commit de13ad7
Devie Lu Linvega
·
2025-12-23 18:42:21 +0000 UTC
parent f19b456
Cleanup
2 files changed,
+17,
-18
+8,
-5
1@@ -36,10 +36,9 @@ static Window window;
2 #define WIDTH (64 * 8)
3 #define HEIGHT (40 * 8)
4
5-#define PEEK2(d) (*(d) << 8 | (d)[1])
6 #define CLAMP(v, a, b) { if(v < a) v = a; else if(v >= b) v = b; }
7 #define TWOS(v) (v & 0x8000 ? (int)v - 0x10000 : (int)v)
8-
9+#define PEEK2(d) (*(d) << 8 | (d)[1])
10 #define NEXT if(--cycles) goto step; else return 0;
11
12 #define OPC(opc, A, B) {\
13@@ -183,9 +182,13 @@ system_expansion(const Uint16 exp)
14 Uint16 length = PEEK2(aptr + 1), limit;
15 unsigned int bank = PEEK2(aptr + 3) * 0x10000;
16 unsigned int addr = PEEK2(aptr + 5);
17- if(ram[exp] == 0x0)
18- memset(ram + addr, ram[exp + 7], length);
19- else if(ram[exp] == 0x1) {
20+ if(ram[exp] == 0x0) {
21+ unsigned int dst_value = ram[exp + 7];
22+ unsigned short a = addr;
23+ if(bank < BANKS_CAP)
24+ for(limit = a + length; a != limit; a++)
25+ ram[bank + a] = dst_value;
26+ } else if(ram[exp] == 0x1) {
27 unsigned int dst_bank = PEEK2(aptr + 7) * 0x10000;
28 unsigned int dst_addr = PEEK2(aptr + 9);
29 Uint16 a = addr, c = dst_addr;
+9,
-13
1@@ -19,19 +19,12 @@ cc -DNDEBUG -O2 -g0 -s src/uxncli.c -lutil -o bin/uxncli
2 typedef unsigned char Uint8;
3 typedef unsigned short Uint16;
4
5-static Uint8 *ram, dev[0x100], ptr[2], stk[2][0x100];
6-
7-Uint8 emu_dei(const Uint8 port);
8-void emu_deo(const Uint8 port, const Uint8 value);
9-
10 /* clang-format off */
11
12 #define BANKS 0x10
13 #define BANKS_CAP BANKS * 0x10000
14
15 #define PEEK2(d) (*(d) << 8 | (d)[1])
16-#define POKE2(d, v) { *(d) = (v) >> 8; (d)[1] = (v); }
17-
18 #define NEXT if(--cycles) goto step; else return 0;
19
20 #define OPC(opc, A, B) {\
21@@ -63,7 +56,10 @@ void emu_deo(const Uint8 port, const Uint8 value);
22 #define DEI(i,r) r[0] = emu_dei(i); if(_2) r[1] = emu_dei(i + 1); PUT(r)
23 #define PEK(i,r,m) r[0] = ram[i]; if(_2) r[1] = ram[(i + 1) & m]; PUT(r)
24
25-static unsigned int
26+Uint8 *ram, dev[0x100], ptr[2], stk[2][0x100], emu_dei(const Uint8 port);
27+void emu_deo(const Uint8 port, const Uint8 value);
28+
29+unsigned int
30 uxn_eval(unsigned short pc)
31 {
32 unsigned int a, b, c, x[2], y[2], z[2], cycles = 0x80000000;
33@@ -130,7 +126,7 @@ system_print(char *name, int r)
34 }
35
36 static unsigned int
37-system_load(char *rom_path)
38+system_load(const char *rom_path)
39 {
40 FILE *f = fopen(rom_path, "rb");
41 if(f) {
42@@ -143,12 +139,12 @@ system_load(char *rom_path)
43 }
44
45 static unsigned int
46-system_boot(char *rom_path, unsigned int has_args)
47+system_boot(char *rom_path, const unsigned int has_args)
48 {
49 ram = (Uint8 *)calloc(BANKS_CAP, sizeof(Uint8));
50 system_boot_path = rom_path;
51 dev[0x17] = has_args;
52- return system_load(rom_path);
53+ return ram && system_load(rom_path);
54 }
55
56 static void
57@@ -599,7 +595,7 @@ file_delete(unsigned int id)
58 static void
59 file_success(unsigned int port, unsigned int value)
60 {
61- POKE2(&dev[port], value);
62+ dev[port] = value >> 8, dev[port + 1] = value;
63 }
64
65 /* file registers */
66@@ -691,7 +687,7 @@ main(int argc, char **argv)
67 {
68 int i = 1;
69 if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
70- return !fprintf(stdout, "Uxn11 - Varvara Emulator(cli), 18 Oct 2025.\n");
71+ return !fprintf(stdout, "Uxn11 - Varvara Emulator(cli), 23 Dec 2025.\n");
72 else if(argc == 1)
73 return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
74 else if(!system_boot(argv[i++], argc > 2))