Minor optimization in system

This commit is contained in:
Devine Lu Linvega 2024-01-02 09:55:52 -08:00
parent 3f252c0ee3
commit a4f4eb7460
2 changed files with 25 additions and 22 deletions

View File

@ -39,21 +39,16 @@ system_print(Stack *s, char *name)
fprintf(stderr, "%s ", name); fprintf(stderr, "%s ", name);
for(i = 0; i < 9; i++) { for(i = 0; i < 9; i++) {
Uint8 pos = s->ptr - 4 + i; Uint8 pos = s->ptr - 4 + i;
fprintf(stderr, !pos ? "[%02x]" : i == 4 ? "<%02x>" if(!pos)
: " %02x ", fprintf(stderr, "[%02x]", s->dat[pos]);
s->dat[pos]); else if(i == 4)
fprintf(stderr, "<%02x>", s->dat[pos]);
else
fprintf(stderr, " %02x ", s->dat[pos]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
int
system_error(char *msg, const char *err)
{
fprintf(stderr, "%s: %s\n", msg, err);
fflush(stderr);
return 0;
}
void void
system_inspect(Uxn *u) system_inspect(Uxn *u)
{ {
@ -61,6 +56,14 @@ system_inspect(Uxn *u)
system_print(&u->rst, "rst"); system_print(&u->rst, "rst");
} }
int
system_error(char *msg, const char *err)
{
fprintf(stderr, "%s: %s\n", msg, err);
fflush(stderr);
return 0;
}
int int
system_version(char *name, char *date) system_version(char *name, char *date)
{ {
@ -69,21 +72,20 @@ system_version(char *name, char *date)
} }
void void
system_boot(Uxn *u, int soft) system_zero(Uxn *u, int soft)
{ {
int i; int i;
for(i = 0x100 * soft; i < 0x10000; i++) for(i = PAGE_PROGRAM * soft; i < 0x10000; i++)
u->ram[i] = 0; u->ram[i] = 0;
for(i = 0x0; i < 0x100; i++) for(i = 0x0; i < 0x100; i++)
u->dev[i] = 0; u->dev[i] = 0;
u->wst.ptr = 0; u->wst.ptr = u->rst.ptr = 0;
u->rst.ptr = 0;
} }
void void
system_reboot(Uxn *u, char *rom, int soft) system_reboot(Uxn *u, char *rom, int soft)
{ {
system_boot(u, soft); system_zero(u, soft);
if(system_load(u, boot_rom)) if(system_load(u, boot_rom))
if(uxn_eval(u, PAGE_PROGRAM)) if(uxn_eval(u, PAGE_PROGRAM))
boot_rom = rom; boot_rom = rom;
@ -93,7 +95,7 @@ int
system_init(Uxn *u, Uint8 *ram, char *rom) system_init(Uxn *u, Uint8 *ram, char *rom)
{ {
u->ram = ram; u->ram = ram;
system_boot(u, 0); system_zero(u, 0);
if(!system_load(u, rom)) if(!system_load(u, rom))
if(!system_load(u, "boot.rom")) if(!system_load(u, "boot.rom"))
return system_error("Init", "Failed to load rom."); return system_error("Init", "Failed to load rom.");
@ -123,10 +125,11 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port)
ram = u->ram; ram = u->ram;
addr = PEEK2(d + 2); addr = PEEK2(d + 2);
if(ram[addr] == 0x1) { if(ram[addr] == 0x1) {
Uint16 i, length = PEEK2(ram + addr + 1); Uint8 *cmd_addr = ram + addr + 1;
Uint16 a_page = PEEK2(ram + addr + 1 + 2), a_addr = PEEK2(ram + addr + 1 + 4); Uint16 i, length = PEEK2(cmd_addr);
Uint16 b_page = PEEK2(ram + addr + 1 + 6), b_addr = PEEK2(ram + addr + 1 + 8); Uint16 a_page = PEEK2(cmd_addr + 2), a_addr = PEEK2(cmd_addr + 4);
int src = (a_page % RAM_PAGES) * 0x10000, dst = (b_page % RAM_PAGES) * 0x10000; Uint16 b_page = PEEK2(cmd_addr + 6), b_addr = PEEK2(cmd_addr + 8);
int src = (a_page % RAM_PAGES) << 0x10, dst = (b_page % RAM_PAGES) << 0x10;
for(i = 0; i < length; i++) for(i = 0; i < length; i++)
ram[dst + (Uint16)(b_addr + i)] = ram[src + (Uint16)(a_addr + i)]; ram[dst + (Uint16)(b_addr + i)] = ram[src + (Uint16)(a_addr + i)];
} }

View File

@ -498,7 +498,7 @@ main(int argc, char **argv)
/* Read flag. Right now, there can be only one. */ /* Read flag. Right now, there can be only one. */
if(argv[i][0] == '-') { if(argv[i][0] == '-') {
if(argv[i][1] == 'v') if(argv[i][1] == 'v')
return system_version("Uxnemu - Graphical Varvara Emulator", "18 Dec 2023"); return system_version("Uxnemu - Graphical Varvara Emulator", "2 Jan 2024");
if(argv[i][1] == '-') if(argv[i][1] == '-')
i++; i++;
if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0) if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)