(uxnasm) Print assembly result to stdout

This commit is contained in:
Devine Lu Linvega 2024-03-07 21:01:12 -08:00
parent 45fd270e9d
commit 52f9f9d4a7
2 changed files with 13 additions and 26 deletions

View File

@ -29,23 +29,17 @@ mouse_up(Uxn *u, Uint8 *d, Uint8 mask)
void void
mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y) mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{ {
*(d + 2) = x >> 8; *(d + 2) = x >> 8, *(d + 3) = x;
*(d + 3) = x; *(d + 4) = y >> 8, *(d + 5) = y;
*(d + 4) = y >> 8;
*(d + 5) = y;
uxn_eval(u, PEEK2(d)); uxn_eval(u, PEEK2(d));
} }
void void
mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y) mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{ {
*(d + 0xa) = x >> 8; *(d + 0xa) = x >> 8, *(d + 0xb) = x;
*(d + 0xb) = x; *(d + 0xc) = -y >> 8, *(d + 0xd) = -y;
*(d + 0xc) = -y >> 8;
*(d + 0xd) = -y;
uxn_eval(u, PEEK2(d)); uxn_eval(u, PEEK2(d));
*(d + 0xa) = 0; *(d + 0xa) = 0, *(d + 0xb) = 0;
*(d + 0xb) = 0; *(d + 0xc) = 0, *(d + 0xd) = 0;
*(d + 0xc) = 0;
*(d + 0xd) = 0;
} }

View File

@ -83,13 +83,6 @@ error_asm(const char *name, const char *msg)
return 0; return 0;
} }
static int
error_res(const char *name, const char *msg)
{
fprintf(stderr, "%s: %s.\n", name, msg);
return 0;
}
static char * static char *
setlocation(char *name) setlocation(char *name)
{ {
@ -434,7 +427,7 @@ resolve(void)
case '_': case '_':
case ',': case ',':
if(!(l = findlabel(r->name))) if(!(l = findlabel(r->name)))
return error_res("Unknown relative reference", r->name); return error_top("Unknown relative reference", r->name);
p.data[r->addr] = (Sint8)(l->addr - r->addr - 2); p.data[r->addr] = (Sint8)(l->addr - r->addr - 2);
if((Sint8)p.data[r->addr] != (l->addr - r->addr - 2)) if((Sint8)p.data[r->addr] != (l->addr - r->addr - 2))
return error_asm("Relative reference is too far", r->name); return error_asm("Relative reference is too far", r->name);
@ -443,7 +436,7 @@ resolve(void)
case '-': case '-':
case '.': case '.':
if(!(l = findlabel(r->name))) if(!(l = findlabel(r->name)))
return error_res("Unknown zero-page reference", r->name); return error_top("Unknown zero-page reference", r->name);
p.data[r->addr] = l->addr & 0xff; p.data[r->addr] = l->addr & 0xff;
l->refs++; l->refs++;
break; break;
@ -451,7 +444,7 @@ resolve(void)
case '=': case '=':
case ';': case ';':
if(!(l = findlabel(r->name))) if(!(l = findlabel(r->name)))
return error_res("Unknown absolute reference", r->name); return error_top("Unknown absolute reference", r->name);
p.data[r->addr] = l->addr >> 0x8; p.data[r->addr] = l->addr >> 0x8;
p.data[r->addr + 1] = l->addr & 0xff; p.data[r->addr + 1] = l->addr & 0xff;
l->refs++; l->refs++;
@ -460,7 +453,7 @@ resolve(void)
case '!': case '!':
default: default:
if(!(l = findlabel(r->name))) if(!(l = findlabel(r->name)))
return error_res("Unknown absolute reference", r->name); return error_top("Unknown absolute reference", r->name);
a = l->addr - r->addr - 2; a = l->addr - r->addr - 2;
p.data[r->addr] = a >> 0x8; p.data[r->addr] = a >> 0x8;
p.data[r->addr + 1] = a & 0xff; p.data[r->addr + 1] = a & 0xff;
@ -491,8 +484,8 @@ review(char *filename)
if(p.labels[i].name[0] >= 'A' && p.labels[i].name[0] <= 'Z') if(p.labels[i].name[0] >= 'A' && p.labels[i].name[0] <= 'Z')
continue; /* Ignore capitalized labels(devices) */ continue; /* Ignore capitalized labels(devices) */
else if(!p.labels[i].refs) else if(!p.labels[i].refs)
fprintf(stderr, "-- Unused label: %s\n", p.labels[i].name); fprintf(stdout, "-- Unused label: %s\n", p.labels[i].name);
fprintf(stderr, fprintf(stdout,
"Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n", "Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n",
filename, filename,
p.length - TRIM, p.length - TRIM,
@ -528,7 +521,7 @@ main(int argc, char *argv[])
if(argc == 1) if(argc == 1)
return error_top("usage", "uxnasm [-v] input.tal output.rom"); return error_top("usage", "uxnasm [-v] input.tal output.rom");
if(argv[1][0] == '-' && argv[1][1] == 'v') if(argv[1][0] == '-' && argv[1][1] == 'v')
return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 6 Mar 2024.\n"); return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 7 Mar 2024.\n");
if(!(src = fopen(setlocation(argv[1]), "r"))) if(!(src = fopen(setlocation(argv[1]), "r")))
return !error_top("Invalid input", argv[1]); return !error_top("Invalid input", argv[1]);
p.entry = argv[1]; p.entry = argv[1];