uxncli.c (1757B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #include "uxn.h" 5 #include "devices/system.h" 6 #include "devices/console.h" 7 #include "devices/file.h" 8 #include "devices/datetime.h" 9 10 /* 11 Copyright (c) 2021-2025 Devine Lu Linvega, Andrew Alderwick 12 13 Permission to use, copy, modify, and distribute this software for any 14 purpose with or without fee is hereby granted, provided that the above 15 copyright notice and this permission notice appear in all copies. 16 17 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 18 WITH REGARD TO THIS SOFTWARE. 19 */ 20 21 Uxn uxn; 22 23 Uint8 24 emu_dei(Uint8 addr) 25 { 26 switch(addr & 0xf0) { 27 case 0x00: return system_dei(addr); 28 case 0xc0: return datetime_dei(addr); 29 } 30 return uxn.dev[addr]; 31 } 32 33 void 34 emu_deo(Uint8 addr, Uint8 value) 35 { 36 uxn.dev[addr] = value; 37 switch(addr & 0xf0) { 38 case 0x00: system_deo(addr); break; 39 case 0x10: console_deo(addr); break; 40 case 0xa0: file_deo(addr); break; 41 case 0xb0: file_deo(addr); break; 42 } 43 } 44 45 int 46 main(int argc, char **argv) 47 { 48 int i = 1; 49 if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v') 50 return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 19 Jan 2025.\n"); 51 else if(argc == 1) 52 return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]); 53 else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) 54 return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]); 55 uxn.dev[0x17] = argc > 2; 56 if(uxn_eval(PAGE_PROGRAM) && uxn.dev[0x10]) { 57 /* arguments input */ 58 for(; i < argc; i++) { 59 char *p = argv[i]; 60 while(*p) console_input(*p++, CONSOLE_ARG); 61 console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA); 62 } 63 /* console input */ 64 while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1)); 65 } 66 return uxn.dev[0x0f] & 0x7f; 67 }