| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,119 +0,0 @@ |
| 1 |
- |
|
| 2 |
-static void |
|
| 3 |
-stack_diff(Stack *old, Stack *new, char *title) |
|
| 4 |
-{
|
|
| 5 |
- size_t i; |
|
| 6 |
- printf("%6s: ", title);
|
|
| 7 |
- for(i = 0;; ++i) {
|
|
| 8 |
- if(i < old->ptr) {
|
|
| 9 |
- if(i < new->ptr) {
|
|
| 10 |
- if(old->dat[i] == new->dat[i]) {
|
|
| 11 |
- printf(" \033[0m%02x", new->dat[i]);
|
|
| 12 |
- } else {
|
|
| 13 |
- printf(" \033[0;31m%02x\033[33;1m%02x", old->dat[i], new->dat[i]);
|
|
| 14 |
- } |
|
| 15 |
- } else { /* only in old stack */
|
|
| 16 |
- printf(" \033[0;31m%02x", old->dat[i]);
|
|
| 17 |
- } |
|
| 18 |
- } else {
|
|
| 19 |
- if(i < new->ptr) { /* only in new stack */
|
|
| 20 |
- printf(" \033[33;1m%02x", new->dat[i]);
|
|
| 21 |
- } else { /* in neither stack, end of loop */
|
|
| 22 |
- break; |
|
| 23 |
- } |
|
| 24 |
- } |
|
| 25 |
- } |
|
| 26 |
- printf("\033[0m\n");
|
|
| 27 |
-} |
|
| 28 |
- |
|
| 29 |
-static void |
|
| 30 |
-memory_diff(Uint8 *old, Uint8 *new, size_t start, size_t end) |
|
| 31 |
-{
|
|
| 32 |
- size_t i, j; |
|
| 33 |
- for(i = start; i < end; i += 0x10) {
|
|
| 34 |
- int changes = 0; |
|
| 35 |
- for(j = i; j < i + 0x10; ++j) {
|
|
| 36 |
- if(old[j] != new[j]) {
|
|
| 37 |
- changes = 1; |
|
| 38 |
- break; |
|
| 39 |
- } |
|
| 40 |
- } |
|
| 41 |
- if(!changes) continue; |
|
| 42 |
- printf("0x%04lx: ", i);
|
|
| 43 |
- for(j = i; j < i + 0x10; ++j) {
|
|
| 44 |
- printf("\033[%sm%02x", old[j] == new[j] ? "0" : "33;1", new[j]);
|
|
| 45 |
- if(j % 2) putchar(' ');
|
|
| 46 |
- } |
|
| 47 |
- printf(" ");
|
|
| 48 |
- for(j = i; j < i + 0x10; ++j) {
|
|
| 49 |
- printf("\033[%sm%c", old[j] == new[j] ? "0" : "33;1", (new[j] < ' ' || new[j] > '~') ? '.' : new[j]);
|
|
| 50 |
- } |
|
| 51 |
- printf("\033[0m\n");
|
|
| 52 |
- } |
|
| 53 |
-} |
|
| 54 |
- |
|
| 55 |
-Uint8 |
|
| 56 |
-debug_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 57 |
-{
|
|
| 58 |
- size_t i; |
|
| 59 |
- (void)ptr; |
|
| 60 |
- switch(b0) {
|
|
| 61 |
- case 0x08: /* stack */ |
|
| 62 |
- printf("pc %04x working stack:", u->ram.ptr);
|
|
| 63 |
- for(i = 0; i < u->wst.ptr; ++i) {
|
|
| 64 |
- printf(" %02x", u->wst.dat[i]);
|
|
| 65 |
- } |
|
| 66 |
- printf(", return stack: ");
|
|
| 67 |
- for(i = 0; i < u->rst.ptr; ++i) {
|
|
| 68 |
- printf(" %02x", u->rst.dat[i]);
|
|
| 69 |
- } |
|
| 70 |
- printf("\n");
|
|
| 71 |
- if(b1 && b1 != u->wst.ptr) {
|
|
| 72 |
- printf("length %d failed to match %d!\n", b1, u->wst.ptr);
|
|
| 73 |
- exit(1); |
|
| 74 |
- } |
|
| 75 |
- break; |
|
| 76 |
- case 0x09: /* snapshot */ |
|
| 77 |
- if(u->snapshot != NULL) {
|
|
| 78 |
- if(!(b1 & 0x01)) {
|
|
| 79 |
- stack_diff(&u->snapshot->wst, &u->wst, "work"); |
|
| 80 |
- } |
|
| 81 |
- if(!(b1 & 0x02)) {
|
|
| 82 |
- stack_diff(&u->snapshot->rst, &u->rst, "return"); |
|
| 83 |
- } |
|
| 84 |
- if(!(b1 & 0x04)) {
|
|
| 85 |
- memory_diff(u->snapshot->ram.dat, u->ram.dat, 0, PAGE_DEVICE); |
|
| 86 |
- memory_diff(u->snapshot->ram.dat, u->ram.dat, PAGE_DEVICE + 0x0100, 0x10000); |
|
| 87 |
- } |
|
| 88 |
- } |
|
| 89 |
- {
|
|
| 90 |
- int want_snapshot = !(b1 & 0x80); |
|
| 91 |
- if(want_snapshot) {
|
|
| 92 |
- if(u->snapshot == NULL) {
|
|
| 93 |
- u->snapshot = malloc(sizeof(*u)); |
|
| 94 |
- } |
|
| 95 |
- for(i = 0; i < sizeof(*u); ++i) {
|
|
| 96 |
- ((char *)u->snapshot)[i] = ((char *)u)[i]; |
|
| 97 |
- } |
|
| 98 |
- } |
|
| 99 |
- printf("pc 0x%04x snapshot%s taken\n", u->counter, want_snapshot ? "" : " not");
|
|
| 100 |
- } |
|
| 101 |
- break; |
|
| 102 |
- case 0x0a: /* exit */ |
|
| 103 |
- printf("Exited after 0x%04x cycles.\n", u->counter);
|
|
| 104 |
- exit(b1); |
|
| 105 |
- break; |
|
| 106 |
- case 0x0f: /* test mode */ |
|
| 107 |
- u->test_mode = b1; |
|
| 108 |
- printf("Test mode is now 0x%02x: ", u->test_mode);
|
|
| 109 |
- if(b1 & 0x01) {
|
|
| 110 |
- printf("BRK resets stacks to zero length");
|
|
| 111 |
- } else {
|
|
| 112 |
- printf("all test mode features disabled");
|
|
| 113 |
- } |
|
| 114 |
- printf("\n");
|
|
| 115 |
- break; |
|
| 116 |
- } |
|
| 117 |
- fflush(stdout); |
|
| 118 |
- return b1; |
|
| 119 |
-} |
|
| 120 | 0 |
\ No newline at end of file |