diff options
Diffstat (limited to 'sux.c')
-rw-r--r-- | sux.c | 84 |
1 files changed, 57 insertions, 27 deletions
@@ -44,7 +44,7 @@ void *run(void *args) { struct suxthr *thr = (void *)args; struct sux *cpu = &thr->sx; uint8_t thread = thr->th; - uint64_t address; + uint64_t address = 0; uint8_t prefix = 0; uint8_t opcode = 0; uint8_t end = 0; @@ -57,10 +57,12 @@ void *run(void *args) { uint8_t lines = (6*thread)+2; uint16_t tv = 0xFF50; /* Starting address of the Thread Vectors. */ int x = 0, y = 0; + uint8_t esc = 0; #if bench gettimeofday(&str[thread], 0); #endif while (!end) { + address = 0; if (wai) { for (int8_t i = 56; i >= 0; i-=8) { if (i) @@ -91,7 +93,7 @@ void *run(void *args) { prefix = 0; opcode = addr[cpu->pc[thread]]; - #if debug && !bench && keypoll + #if debug && !bench #if keypoll pthread_mutex_lock(&mutex); #endif @@ -762,22 +764,53 @@ void *run(void *args) { #if keypoll pthread_mutex_lock(&mutex); #endif - if (addr[address] == CURSES_BACKSPACE || addr[address] == '\b') { - if (x > 0) { - x--; - wmove(scr, y, x); + if (esc) { + switch(addr[address]) { + case 'A': + if (y > 0) + y--; + wmove(scr, y, x); + esc = 0; + break; + case 'B': + if (y < getmaxy(scr)) + y++; + wmove(scr, y, x); + esc = 0; + break; + case 'C': + if (x < getmaxx(scr)) + x++; + wmove(scr, y, x); + esc = 0; + break; + case 'D': + if (x > 0) + x--; + wmove(scr, y, x); + esc = 0; + break; } - wdelch(scr); - wrefresh(scr); } else { - wmove(scr, y, x); - waddch(scr, addr[address]); - wrefresh(scr); - if (addr[address] == '\n') { - x = 0; - y+=1; + if (addr[address] == CURSES_BACKSPACE || addr[address] == '\b') { + if (x > 0) { + x--; + wmove(scr, y, x); + } + wdelch(scr); + wrefresh(scr); + } else if (addr[address] == '\033') { + esc = 1; } else { - x+=1; + wmove(scr, y, x); + waddch(scr, addr[address]); + wrefresh(scr); + if (addr[address] == '\n') { + x = 0; + y+=1; + } else { + x+=1; + } } } #if keypoll @@ -1296,6 +1329,8 @@ void *run(void *args) { cpu->a[thread]+=1; cpu->z[thread] = (cpu->a[thread] == 0); cpu->n[thread] = (cpu->a[thread] >> 63); + (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); + (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); } if (opcode == INY || opcode == IAY) { cpu->y[thread]+=1; @@ -1307,8 +1342,6 @@ void *run(void *args) { cpu->z[thread] = (cpu->x[thread] == 0); cpu->n[thread] = (cpu->x[thread] >> 63); } - (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); - (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); break; case 0xD0: /* JMP Zero Matrix. */ address = (uint32_t)addr[cpu->pc[thread]] @@ -1329,6 +1362,8 @@ void *run(void *args) { cpu->a[thread]-=1; cpu->z[thread] = (cpu->a[thread] == 0); cpu->n[thread] = (cpu->a[thread] >> 63); + (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); + (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); } if (opcode == DEY || opcode == DAY) { cpu->y[thread]-=1; @@ -1340,8 +1375,6 @@ void *run(void *args) { cpu->z[thread] = (cpu->x[thread] == 0); cpu->n[thread] = (cpu->x[thread] >> 63); } - (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); - (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); break; case JSL: /* Jump to Subroutine Long. */ address = (uint64_t)addr[cpu->pc[thread]] @@ -1457,10 +1490,11 @@ void *run(void *args) { break; } ins++; - #if debug && !bench && keypoll + #if debug && !bench #if keypoll pthread_mutex_lock(&mutex); #endif + mvwprintw(scr, getmaxy(scr)-lines, 0, "Operand: $%llx", address); mvwprintw(scr, (24*thread)+1, 0, "Instructions executed: %llu, Clock cycles: %llu\r", ins, iclk); wrefresh(scr); #if keypoll @@ -1507,7 +1541,7 @@ int main(int argc, char **argv) { crmode(); noecho(); nl(); - curs_set(0); + curs_set(1); werase(scr); scrollok(scr, 1); wrefresh(scr); @@ -1562,8 +1596,10 @@ int main(int argc, char **argv) { #if !bench if ((c != EOF && c !=-1)) { pthread_mutex_lock(&main_mutex); + curs_set(0); pthread_cond_wait(&main_cond, &main_mutex); pthread_mutex_unlock(&main_mutex); + curs_set(1); c = 0; addr[CTRL_ADDR] = 0; } @@ -1571,12 +1607,6 @@ int main(int argc, char **argv) { pthread_mutex_lock(&mutex); #endif getyx(scr, y, x); - attroff(A_REVERSE); - attron(A_BLINK); - wprintw(scr, "_"); - attroff(A_BLINK); - wmove(scr, y, x); - wrefresh(scr); c = wgetch(scr); switch (c) { case ERR: |