diff options
Diffstat (limited to 'sux.c')
-rw-r--r-- | sux.c | 221 |
1 files changed, 132 insertions, 89 deletions
@@ -3,11 +3,7 @@ #include <ctype.h> #include <string.h> #include <pthread.h> -#define bench 0 -#define debug 0 -#define IO 1 -#define getclk 0 -#define keypoll 0 + #if bench #include <sys/time.h> #else @@ -31,8 +27,19 @@ uint64_t tclk; /* Total Clock cycles. */ #endif const uint16_t tv = 0xFF50; /* Starting address of the Thread Vectors. */ + +#if !IO uint64_t inst[THREADS]; +#endif + +#if debug +uint8_t subdbg = 0; +#endif + +#if bench uint64_t inss; +#endif + uint8_t threads_done = 0; uint8_t kbd_rdy = 0; uint8_t step = 0; @@ -41,6 +48,7 @@ uint8_t step = 0; #if !bench WINDOW *scr; #endif + pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t main_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; @@ -69,7 +77,9 @@ void *run(void *args) { #if getclk uint64_t iclk = 0; #endif + #if !IO uint64_t ins = 0; + #endif uint8_t sign = 0; uint8_t tmp; uint8_t tmp2; @@ -84,11 +94,12 @@ void *run(void *args) { gettimeofday(&str[thread], 0); #endif #if debug && !bench - uint8_t scr_row = 0xFF, scr_col = 0xFF; - uint8_t updt = 0; uint64_t tmpaddr = 0; - addr[STEP_ADDR] = 1; - step = 1; + uint16_t scr_col = 0; + if (!subdbg) { + addr[STEP_ADDR] = 1; + step = 1; + } #if keypoll pthread_mutex_lock(&mutex); #endif @@ -350,61 +361,77 @@ void *run(void *args) { break; } - if (updt) { - mvwprintw(scr, 27, 0, "TX_ADDR: $%02X, RX_ADDR: $%02X\r", addr[TX_ADDR], addr[RX_ADDR]); - mvwprintw(scr, 28, 0, "scr_ptr3: $%04X", (addr[0x5C] << 8) | addr[0x5B]); - mvwprintw(scr, 29, 0, "address: $%04"PRIX64", scr_row: %02u, scr_col: %02u, scr_str: %02u, scr_end: %02u\r", address, addr[0], addr[1], addr[0x28], addr[0x29]); - mvwprintw(scr, 32, 0, "bitabl: %02X %02X %02X %02X %02X %02X %02X %02X " - "%02x %02x %02x %02x %02x %02x %02x %02x\r" - , addr[0x18], addr[0x19], addr[0x1A], addr[0x1B], addr[0x1C], addr[0x1D], addr[0x1E], addr[0x1F] - , addr[0x20], addr[0x21], addr[0x22], addr[0x23], addr[0x24], addr[0x25], addr[0x26], addr[0x27]); + if (address == TX_ADDR || address == RX_ADDR) { + wmove(scr, 27, 0); + wprintw(scr, "TX_ADDR: $%02X, RX_ADDR: $%02X", addr[TX_ADDR], addr[RX_ADDR]); } - uint8_t ln = 33; - uint16_t line_idx = 0; - uint16_t tmpad = 0x2000; - int row, col; - uint8_t iscursor = 0; - mvwprintw(scr, ln++, 0, "buffer:\r"); - if (updt) { - scr_row = addr[0]; - scr_col = addr[1]; - wmove(scr, ln++, 0); - for (uint8_t i = 0; i < 10; i++) { - line_idx = (i << 6) + (i << 4); - for (uint8_t j = 0; j < 0x50; j++) { - wprintw(scr, "%02X", addr[tmpad+j+line_idx]); - if ((addr[0]+addr[0x28]) == i && addr[1] == j) { - iscursor=1; - getyx(scr,row, col); - wmove(scr, ln++, 0); - wclrtoeol(scr); - wmove(scr, row+1, col-2); - wprintw(scr, "/\\\r"); - wmove(scr, row, col); - } - } - wprintw(scr, ", i: %02X\r", i); - if (!iscursor) { - wmove(scr, ln, 0); - wclrtoeol(scr); - } - iscursor = 0; + if (subdbg) { + uint8_t ln = 33; + uint16_t line_idx = 0; + uint16_t tmpad = 0x2000; + int row, col; + uint8_t iscursor = 0; + uint64_t ptr; + uint8_t adr; + wmove(scr, 30, 0); + adr = 0x1F; + ptr = (uint64_t)addr[adr+0] << 0x00 | (uint64_t)addr[adr+1] << 0x08 | (uint64_t)addr[adr+2] << 0x10 | (uint64_t)addr[adr+3] << 0x18 | + (uint64_t)addr[adr+4] << 0x20 | (uint64_t)addr[adr+5] << 0x28 | (uint64_t)addr[adr+6] << 0x30 | (uint64_t)addr[adr+7] << 0x38; + wprintw(scr, "ptr1: $%04"PRIX64, ptr); + adr = 0x27; + ptr = (uint64_t)addr[adr+0] << 0x00 | (uint64_t)addr[adr+1] << 0x08 | (uint64_t)addr[adr+2] << 0x10 | (uint64_t)addr[adr+3] << 0x18 | + (uint64_t)addr[adr+4] << 0x20 | (uint64_t)addr[adr+5] << 0x28 | (uint64_t)addr[adr+6] << 0x30 | (uint64_t)addr[adr+7] << 0x38; + wprintw(scr, ", ptr2: $%04"PRIX64, ptr); + adr = 0x2F; + ptr = (uint64_t)addr[adr+0] << 0x00 | (uint64_t)addr[adr+1] << 0x08 | (uint64_t)addr[adr+2] << 0x10 | (uint64_t)addr[adr+3] << 0x18 | + (uint64_t)addr[adr+4] << 0x20 | (uint64_t)addr[adr+5] << 0x28 | (uint64_t)addr[adr+6] << 0x30 | (uint64_t)addr[adr+7] << 0x38; + wprintw(scr, ", ptr3: $%04"PRIX64, ptr); + if (address == CTRL_ADDR || addr[STEP_ADDR]) { + mvwprintw(scr, 29, 0, "address: $%04"PRIX64", scr_row: %02u, scr_col: %02u, scr_str: %02u, scr_end: %02u\r", address, addr[0], addr[1], addr[0x1C], addr[0x1D]); + mvwprintw(scr, 32, 0, "bitabl: %02X%02X%02X%02X%02X%02X%02X%02X" + "%02X%02X%02X%02X%02X%02X%02X%02X" + , addr[0x1000], addr[0x1001], addr[0x1002], addr[0x1003], addr[0x1004], addr[0x1005], addr[0x1006], addr[0x1007] + , addr[0x1008], addr[0x1009], addr[0x100A], addr[0x100B], addr[0x100C], addr[0x100D], addr[0x100E], addr[0x100F]); + mvwprintw(scr, ln++, 0, "buffer:\r"); wmove(scr, ln++, 0); + for (uint8_t i = 0; i < 10; i++) { + line_idx = (i << 6) + (i << 4); + for (uint8_t j = 0; j < 0x50; j++) { + wprintw(scr, "%02X", addr[tmpad+j+line_idx]); + if ((addr[0]+addr[0x1C]) == i && addr[1] == j) { + iscursor=1; + getyx(scr,row, col); + wmove(scr, ln++, 0); + wclrtoeol(scr); + wmove(scr, row+1, col-2); + wprintw(scr, "/\\\r"); + wmove(scr, row, col); + } + } + wprintw(scr, ", i: %02X", i); + if (!iscursor) { + wmove(scr, ln, 0); + wclrtoeol(scr); + } + iscursor = 0; + wmove(scr, ln++, 0); + } } - updt = 0; + /*if (address == 0x4000 || tmpaddr == 0x4000 || addr[STEP_ADDR]) { + ln = 46; + tmpad = 0x4000; + line_idx = 0; + mvwprintw(scr, ln++, 0, "cmd_buf:"); + for (uint8_t i = 0; i < 5; i++) { + wmove(scr, ln++, 0); + line_idx = (i << 4)+(i << 6); + for (uint8_t j = 0; j < 0x50; j++) { + wprintw(scr, "%02X", addr[tmpad+j+line_idx]); + } + wprintw(scr, ", i: %02X", i); + } + }*/ } - /*ln = 45; - tmpad = 0x4000; - line_idx = 0; - mvwprintw(scr, ln++, 0, "cmd_buf:\r"); - for (uint8_t i = 0; i < 5; i++) { - wmove(scr, ln++, 0); - line_idx = (i << 4)+(i << 6); - for (uint8_t j = 0; j < 0x50; j++) { - wprintw(scr, "%02X", addr[tmpad+j+line_idx]); - } - wprintw(scr, ", i: %02X\r", i); - }*/ #if keypoll pthread_mutex_unlock(&mutex); #endif @@ -668,8 +695,19 @@ void *run(void *args) { #if keypoll pthread_mutex_lock(&mutex); #endif + #if debug + if (!subdbg) { + scr_col = (addr[TX_ADDR] != 0x0C && addr[TX_ADDR] != '\n' && scr_col < 160) ? (addr[1] << 1)-2 : 0; + wmove(scr, 28, scr_col); + } + #endif if (esc) { - switch(addr[TX_ADDR]) { + #if debug + if (!subdbg && addr[RX_ADDR] == '\n') { + wclrtoeol(scr); + } + #endif + switch (addr[TX_ADDR]) { case 'A': if (y > 0) y--; @@ -716,9 +754,8 @@ void *run(void *args) { #if !debug wmove(scr, y, x); #else - updt = 1; mvwprintw(scr, 30, 0, "x: %i, y: %i ", x, y); - mvwprintw(scr, 31, 0, "bcd[3-2]: {%u, %u}, bcd[1-0]: {%u, %u}", bcd[3], bcd[2], bcd[1], bcd[0]); + /*mvwprintw(scr, 31, 0, "bcd[3-2]: {%u, %u}, bcd[1-0]: {%u, %u}", bcd[3], bcd[2], bcd[1], bcd[0]);*/ #endif idx = 3; bcd[0] = 0; @@ -731,7 +768,6 @@ void *run(void *args) { #if !debug wscrl(scr, -1); #else - updt = (!addr[0x16]); #endif esc = 0; break; @@ -739,7 +775,6 @@ void *run(void *args) { #if !debug wscrl(scr, 1); #else - updt = (!addr[0x16]); #endif esc = 0; break; @@ -779,7 +814,13 @@ void *run(void *args) { #if !debug wdelch(scr); #else - updt = 1; + if (!subdbg) { + scr_col++; + wmove(scr, 28, scr_col--); + wdelch(scr); + wmove(scr, 28, scr_col); + wdelch(scr); + } #endif break; case '\033': @@ -789,8 +830,6 @@ void *run(void *args) { #if !debug wmove(scr, y, x); waddch(scr, addr[address]); - #else - updt = (!addr[0x16]); #endif x = 0; y+=1; @@ -800,7 +839,13 @@ void *run(void *args) { wmove(scr, y, x); waddch(scr, addr[address]); #else - updt = (!addr[0x16]); + if (!subdbg && scr_col < 160) { + if (addr[address] != ' ') { + wprintw(scr, "%02X", addr[address]); + } else { + wprintw(scr, " "); + } + } #endif x+=1; break; @@ -1218,11 +1263,10 @@ void *run(void *args) { default: break; } + #if !IO ins++; - #if !bench - #if debug - updt = (!addr[0x16]); #endif + #if !bench if (step) { pthread_mutex_lock(&main_mutex); pthread_cond_signal(&main_cond); @@ -1244,7 +1288,7 @@ void *run(void *args) { #if getclk wprintw(scr, ", Clock cycles: %"PRIu64, iclk); #endif - if (!step) { + if (!step && !subdbg) { wrefresh(scr); } #if keypoll @@ -1272,9 +1316,13 @@ int main(int argc, char **argv) { struct suxthr thr[THREADS]; char *tmp = malloc(2048); addr = malloc(0x04000000); + #if bench inss = 0; + #endif int v = 0; - + #if debug + subdbg = !strcmp(argv[1], "programs/subeditor.s"); + #endif if (argc != 2) { if (asmmon("stdin") == 2) { return 0; @@ -1328,7 +1376,9 @@ int main(int argc, char **argv) { | (uint64_t)addr[vec+7+offset] << 56; thr[i].th = i; + #if !IO inst[i] = 0; + #endif result = pthread_create(&therads[i], NULL, run, &thr[i]); assert(!result); } @@ -1342,6 +1392,11 @@ int main(int argc, char **argv) { int x, y; if ((step_key && step && !kbd_rdy) || !step || kbd_rdy) { if ((c != EOF && c !=-1)) { + #if !keypoll + pthread_mutex_lock(&mutex); + pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); + #endif pthread_mutex_lock(&main_mutex); curs_set(0); pthread_cond_wait(&main_cond, &main_mutex); @@ -1350,9 +1405,7 @@ int main(int argc, char **argv) { c = 0; step_key = 0; addr[CTRL_ADDR] = 0; - #if !debug wrefresh(scr); - #endif } } #if keypoll @@ -1361,10 +1414,10 @@ int main(int argc, char **argv) { getyx(scr, y, x); c = wgetch(scr); if (c == 19) { - step = 1; if (kbd_rdy) { c = wgetch(scr); } + step = 1; } if (kbd_rdy) { switch (c) { @@ -1377,27 +1430,17 @@ int main(int argc, char **argv) { addr[CTRL_ADDR] = 1; #if debug && !bench wmove(scr, getmaxy(scr)-1, 0); - wprintw(scr, "c: %i, x: %i, y: %i", c, x, y); + wclrtoeol(scr); + wprintw(scr, "c: %i", c); wmove(scr, y, x); - wrefresh(scr); #endif } - #if !keypoll - pthread_mutex_lock(&mutex); - pthread_cond_signal(&cond); - pthread_mutex_unlock(&mutex); - #endif break; } } else { if (step) { step = !(c == 18); step_key = (c == 19); - #if !keypoll - pthread_mutex_lock(&mutex); - pthread_cond_signal(&cond); - pthread_mutex_unlock(&mutex); - #endif } } addr[STEP_ADDR] = step; |