Some opti
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#define NRJWORD unsigned short
|
#define NRJWORD unsigned short
|
||||||
#endif
|
#endif
|
||||||
#define NRJSIZE (1 << NRJBITS)
|
#define NRJSIZE (1 << NRJBITS)
|
||||||
|
#define MAXADDR ((NRJWORD) (NRJSIZE - 1))
|
||||||
#define NRJWSIZE sizeof(NRJWORD)
|
#define NRJWSIZE sizeof(NRJWORD)
|
||||||
|
|
||||||
int kbhit() {
|
int kbhit() {
|
||||||
@@ -50,13 +51,13 @@ void nrj_out(NRJWORD *ctxid, NRJWORD *val) {
|
|||||||
putchar((unsigned char) *val);
|
putchar((unsigned char) *val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nrj_load(NRJWORD* m, NRJWORD offset, char *fname) {
|
void nrj_load(NRJWORD* m, char *fname) {
|
||||||
FILE *prog = fopen(fname, "rb");
|
FILE *prog = fopen(fname, "rb");
|
||||||
if(prog) {
|
if(prog) {
|
||||||
fseek(prog, 0, SEEK_END);
|
fseek(prog, 0, SEEK_END);
|
||||||
int flen = ftell(prog);
|
int flen = ftell(prog);
|
||||||
fseek(prog, 0, SEEK_SET);
|
fseek(prog, 0, SEEK_SET);
|
||||||
fread(m+offset, NRJWSIZE, flen/NRJWSIZE, prog);
|
fread(m, NRJWSIZE, (flen/NRJWSIZE) & MAXADDR, prog);
|
||||||
fclose(prog);
|
fclose(prog);
|
||||||
cfmakeraw(&tty_opts_raw);
|
cfmakeraw(&tty_opts_raw);
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw);
|
tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw);
|
||||||
@@ -68,13 +69,11 @@ void nrj_load(NRJWORD* m, NRJWORD offset, char *fname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void nrj_run(char *program) {
|
void nrj_run(char *program) {
|
||||||
NRJWORD maxaddr = (NRJWORD) (NRJSIZE - 1), mem[NRJSIZE], pc;
|
NRJWORD mem[NRJSIZE], pc = (NRJWORD) 3; /* 0 - input, 1 - output, 2 - I/O context, 3 - program start */
|
||||||
mem[0] = mem[1] = mem[2] = (NRJWORD) 0;
|
nrj_load(mem, program);
|
||||||
pc = (NRJWORD) 3;
|
while(pc != MAXADDR) {
|
||||||
nrj_load(mem, pc, program);
|
|
||||||
while(pc != maxaddr) {
|
|
||||||
if(mem[0]) nrj_in(&mem[2], &mem[mem[0]]);
|
if(mem[0]) nrj_in(&mem[2], &mem[mem[0]]);
|
||||||
mem[mem[pc]] = (~(mem[mem[pc]] | mem[mem[pc+1]])) & maxaddr;
|
mem[mem[pc]] = (~(mem[mem[pc]] | mem[mem[pc+1]])) & MAXADDR;
|
||||||
pc = mem[mem[pc+2]];
|
pc = mem[mem[pc+2]];
|
||||||
mem[0] = (NRJWORD) 0;
|
mem[0] = (NRJWORD) 0;
|
||||||
if(mem[1]) {
|
if(mem[1]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user