commit a320538
Devine Lu Linvega
·
2025-06-27 19:28:22 +0000 UTC
parent b76066e
Fixed off by one error in system/expansion
2 files changed,
+37,
-17
+18,
-8
1@@ -186,21 +186,31 @@ system_expansion(const Uint16 addr)
2 Uint8 *aptr = ram + addr;
3 Uint16 length = PEEK2(aptr + 1);
4 if(ram[addr] == 0x0) {
5- unsigned int a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5);
6+ unsigned int src_bank = PEEK2(aptr + 3);
7+ unsigned int src_addr = PEEK2(aptr + 5);
8+ unsigned int src_value = ram[addr + 7];
9+ unsigned int a = src_bank * 0x10000 + src_addr;
10 unsigned int b = a + length;
11- unsigned int value = ram[addr + 7];
12- for(b = b < BANKS_CAP ? b : BANKS_CAP; a < b; ram[a++] = value);
13+ for(b = b < BANKS_CAP ? b : BANKS_CAP; a < b; ram[a++] = src_value);
14 } else if(ram[addr] == 0x1) {
15- unsigned int a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5);
16+ unsigned int src_bank = PEEK2(aptr + 3);
17+ unsigned int src_addr = PEEK2(aptr + 5);
18+ unsigned int dst_bank = PEEK2(aptr + 7);
19+ unsigned int dst_addr = PEEK2(aptr + 9);
20+ unsigned int a = src_bank * 0x10000 + src_addr;
21 unsigned int b = a + length;
22- unsigned int c = PEEK2(aptr + 7) * 0x10000 + PEEK2(aptr + 9);
23+ unsigned int c = dst_bank * 0x10000 + dst_addr;
24 for(b = b < BANKS_CAP ? b : BANKS_CAP; a < b; ram[c++] = ram[a++]);
25 } else if(ram[addr] == 0x2) {
26- unsigned int a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5);
27+ unsigned int src_bank = PEEK2(aptr + 3);
28+ unsigned int src_addr = PEEK2(aptr + 5);
29+ unsigned int dst_bank = PEEK2(aptr + 7);
30+ unsigned int dst_addr = PEEK2(aptr + 9);
31+ unsigned int a = src_bank * 0x10000 + src_addr;
32 unsigned int b = a + length;
33- unsigned int c = PEEK2(aptr + 7) * 0x10000 + PEEK2(aptr + 9);
34+ unsigned int c = dst_bank * 0x10000 + dst_addr;
35 unsigned int d = c + length;
36- for(; b >= a; ram[--d] = ram[--b]);
37+ for(; b > a; ram[--d] = ram[--b]);
38 } else
39 fprintf(stderr, "Unknown command: %s\n", &ram[addr]);
40 }
+19,
-9
1@@ -158,26 +158,36 @@ system_boot(char *rom_path, unsigned int has_args)
2 }
3
4 static void
5-system_expansion(Uint16 addr)
6+system_expansion(const Uint16 addr)
7 {
8 Uint8 *aptr = ram + addr;
9 Uint16 length = PEEK2(aptr + 1);
10 if(ram[addr] == 0x0) {
11- unsigned int a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5);
12+ unsigned int src_bank = PEEK2(aptr + 3);
13+ unsigned int src_addr = PEEK2(aptr + 5);
14+ unsigned int src_value = ram[addr + 7];
15+ unsigned int a = src_bank * 0x10000 + src_addr;
16 unsigned int b = a + length;
17- unsigned int value = ram[addr + 7];
18- for(b = b < BANKS_CAP ? b : BANKS_CAP; a < b; ram[a++] = value);
19+ for(b = b < BANKS_CAP ? b : BANKS_CAP; a < b; ram[a++] = src_value);
20 } else if(ram[addr] == 0x1) {
21- unsigned int a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5);
22+ unsigned int src_bank = PEEK2(aptr + 3);
23+ unsigned int src_addr = PEEK2(aptr + 5);
24+ unsigned int dst_bank = PEEK2(aptr + 7);
25+ unsigned int dst_addr = PEEK2(aptr + 9);
26+ unsigned int a = src_bank * 0x10000 + src_addr;
27 unsigned int b = a + length;
28- unsigned int c = PEEK2(aptr + 7) * 0x10000 + PEEK2(aptr + 9);
29+ unsigned int c = dst_bank * 0x10000 + dst_addr;
30 for(b = b < BANKS_CAP ? b : BANKS_CAP; a < b; ram[c++] = ram[a++]);
31 } else if(ram[addr] == 0x2) {
32- unsigned int a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5);
33+ unsigned int src_bank = PEEK2(aptr + 3);
34+ unsigned int src_addr = PEEK2(aptr + 5);
35+ unsigned int dst_bank = PEEK2(aptr + 7);
36+ unsigned int dst_addr = PEEK2(aptr + 9);
37+ unsigned int a = src_bank * 0x10000 + src_addr;
38 unsigned int b = a + length;
39- unsigned int c = PEEK2(aptr + 7) * 0x10000 + PEEK2(aptr + 9);
40+ unsigned int c = dst_bank * 0x10000 + dst_addr;
41 unsigned int d = c + length;
42- for(; b >= a; ram[--d] = ram[--b]);
43+ for(; b > a; ram[--d] = ram[--b]);
44 } else
45 fprintf(stderr, "Unknown command: %s\n", &ram[addr]);
46 }