Browse Source

Simplified system booting

main
Devine Lu Linvega 1 year ago
parent
commit
5c0a638e29
  1. 5
      src/devices/console.c
  2. 2
      src/devices/console.h
  3. 39
      src/devices/system.c
  4. 4
      src/devices/system.h
  5. 17
      src/uxncli.c
  6. 5
      src/uxnemu.c

5
src/devices/console.c

@ -25,11 +25,12 @@ console_input(int c, int type)
} }
void void
console_listen(int i, int argc, char **argv) console_arguments(int i, int argc, char **argv)
{ {
for(; i < argc; i++) { for(; i < argc; i++) {
char *p = argv[i]; char *p = argv[i];
while(*p) console_input(*p++, CONSOLE_ARG); while(*p)
console_input(*p++, CONSOLE_ARG);
console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA); console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
} }
} }

2
src/devices/console.h

@ -15,6 +15,6 @@ WITH REGARD TO THIS SOFTWARE.
#define CONSOLE_END 0x4 #define CONSOLE_END 0x4
int console_input(int c, int type); int console_input(int c, int type);
void console_listen(int i, int argc, char **argv); void console_arguments(int i, int argc, char **argv);
Uint8 console_dei(Uint8 addr); Uint8 console_dei(Uint8 addr);
void console_deo(Uint8 addr); void console_deo(Uint8 addr);

39
src/devices/system.c

@ -27,13 +27,6 @@ system_print(Stack *s)
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;
}
static int static int
system_load(Uint8 *ram, char *rom_path) system_load(Uint8 *ram, char *rom_path)
{ {
@ -47,22 +40,32 @@ system_load(Uint8 *ram, char *rom_path)
return !!f; return !!f;
} }
void int
system_reboot(int soft) system_error(char *msg, const char *err)
{ {
int i; fprintf(stderr, "%s: %s\n", msg, err), fflush(stderr);
for(i = soft ? 0x100 : 0; i < 0x10000; i++) uxn.ram[i] = 0; return 0;
for(i = 0x0; i < 0x100; i++) uxn.dev[i] = 0;
uxn.wst.ptr = uxn.rst.ptr = 0;
if(system_load(&uxn.ram[PAGE_PROGRAM], boot_path))
uxn_eval(PAGE_PROGRAM);
} }
int int
system_boot(Uint8 *ram, char *rom_path) system_boot(Uint8 *ram, char *rom_path, int has_args)
{ {
uxn.ram = ram, boot_path = rom_path; uxn.ram = ram;
return system_load(uxn.ram + PAGE_PROGRAM, rom_path); boot_path = rom_path;
uxn.dev[0x17] = has_args;
if(ram && system_load(uxn.ram + PAGE_PROGRAM, rom_path))
return uxn_eval(PAGE_PROGRAM);
return 0;
}
int
system_reboot(int soft)
{
int i;
for(i = 0x0; i < 0x100; i++) uxn.dev[i] = 0;
for(i = soft ? 0x100 : 0; i < 0x10000; i++) uxn.ram[i] = 0;
uxn.wst.ptr = uxn.rst.ptr = 0;
return system_boot(uxn.ram, boot_path, 0);
} }
/* IO */ /* IO */

4
src/devices/system.h

@ -11,9 +11,9 @@ WITH REGARD TO THIS SOFTWARE.
#define RAM_PAGES 0x10 #define RAM_PAGES 0x10
void system_reboot(int soft);
int system_error(char *msg, const char *err); int system_error(char *msg, const char *err);
int system_boot(Uint8 *ram, char *rompath); int system_boot(Uint8 *ram, char *rom_path, int has_args);
int system_reboot(int soft);
Uint8 system_dei(Uint8 addr); Uint8 system_dei(Uint8 addr);
void system_deo(Uint8 addr); void system_deo(Uint8 addr);

17
src/uxncli.c

@ -47,21 +47,12 @@ main(int argc, char **argv)
{ {
int i = 1; int i = 1;
if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v') if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 19 Jan 2025.\n"); return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 20 Jan 2025.\n");
else if(argc == 1) else if(argc == 1)
return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]); return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2))
return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]); return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
uxn.dev[0x17] = argc > 2; console_arguments(i, argc, argv);
if(uxn_eval(PAGE_PROGRAM) && uxn.dev[0x10]) { while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1));
/* arguments input */
for(; i < argc; i++) {
char *p = argv[i];
while(*p) console_input(*p++, CONSOLE_ARG);
console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
}
/* console input */
while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1));
}
return uxn.dev[0x0f] & 0x7f; return uxn.dev[0x0f] & 0x7f;
} }

5
src/uxnemu.c

@ -468,14 +468,13 @@ main(int argc, char **argv)
} }
/* start */ /* start */
rom_path = i == argc ? "boot.rom" : argv[i++]; rom_path = i == argc ? "boot.rom" : argv[i++];
if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES + 1, sizeof(Uint8)), rom_path)) if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES + 1, sizeof(Uint8)), rom_path, argc > i))
return system_error("usage:", "uxnemu [-v | -f | -2x | -3x] file.rom [args...]"); return system_error("usage:", "uxnemu [-v | -f | -2x | -3x] file.rom [args...]");
if(!emu_init()) if(!emu_init())
return system_error("Init", "Failed to initialize varvara."); return system_error("Init", "Failed to initialize varvara.");
/* loop */ /* loop */
uxn.dev[0x17] = argc > i;
if(uxn_eval(PAGE_PROGRAM)) { if(uxn_eval(PAGE_PROGRAM)) {
console_listen(i, argc, argv); console_arguments(i, argc, argv);
emu_run(rom_path); emu_run(rom_path);
} }
return emu_end(); return emu_end();

Loading…
Cancel
Save