Browse code

Fixed file_poke

Andrew Alderwick authored on 21/04/2021 12:37:41
Showing 2 changed files
... ...
@@ -54,22 +54,20 @@ console_poke(Device *d, Uint8 b0, Uint8 b1)
54 54
 Uint8
55 55
 file_poke(Device *d, Uint8 b0, Uint8 b1)
56 56
 {
57
-	/*
58 57
 	Uint8 read = b0 == 0xd;
59 58
 	if(read || b0 == 0xf) {
60
-		char *name = (char *)&d->mem[mempeek16(m, 0x8)];
61
-		Uint16 result = 0, length = mempeek16(m, 0xa);
62
-		Uint16 offset = mempeek16(m, 0x4);
63
-		Uint16 addr = (m[b0 - 1] << 8) | b1;
59
+		char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)];
60
+		Uint16 result = 0, length = mempeek16(d->dat, 0xa);
61
+		Uint16 offset = mempeek16(d->dat, 0x4);
62
+		Uint16 addr = (d->dat[b0 - 1] << 8) | b1;
64 63
 		FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w"));
65 64
 		if(f) {
66
-			if(fseek(f, offset, SEEK_SET) != -1 && (result = read ? fread(&m[addr], 1, length, f) : fwrite(&m[addr], 1, length, f)))
65
+			if(fseek(f, offset, SEEK_SET) != -1 && (result = read ? fread(&d->mem[addr], 1, length, f) : fwrite(&d->mem[addr], 1, length, f)))
67 66
 				printf("%s %d bytes, at %04x from %s\n", read ? "Loaded" : "Saved", length, addr, name);
68 67
 			fclose(f);
69 68
 		}
70
-		mempoke16(m, 0x2, result);
69
+		mempoke16(d->dat, 0x2, result);
71 70
 	}
72
-	*/
73 71
 	return b1;
74 72
 }
75 73
 
... ...
@@ -225,24 +225,20 @@ screen_poke(Device *d, Uint8 b0, Uint8 b1)
225 225
 Uint8
226 226
 file_poke(Device *d, Uint8 b0, Uint8 b1)
227 227
 {
228
-	/* TODO: Figure out why fwrite doesn't work with d->mem
229 228
 	Uint8 read = b0 == 0xd;
230 229
 	if(read || b0 == 0xf) {
231
-		char *name = (char *)&d->mem[mempeek16(m, 0x8)];
232
-		Uint16 result = 0, length = mempeek16(m, 0xa);
233
-		Uint16 offset = mempeek16(m, 0x4);
234
-		Uint16 addr = (m[b0 - 1] << 8) | b1;
230
+		char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)];
231
+		Uint16 result = 0, length = mempeek16(d->dat, 0xa);
232
+		Uint16 offset = mempeek16(d->dat, 0x4);
233
+		Uint16 addr = (d->dat[b0 - 1] << 8) | b1;
235 234
 		FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w"));
236 235
 		if(f) {
237
-			if(fseek(f, offset, SEEK_SET) != -1 && (result = read ? fread(d->mem[addr], 1, length, f) : fwrite(&d->mem[addr], 1, length, f)))
236
+			if(fseek(f, offset, SEEK_SET) != -1 && (result = read ? fread(&d->mem[addr], 1, length, f) : fwrite(&d->mem[addr], 1, length, f)))
238 237
 				printf("%s %d bytes, at %04x from %s\n", read ? "Loaded" : "Saved", length, addr, name);
239 238
 			fclose(f);
240 239
 		}
241
-		mempoke16(m, 0x2, result);
240
+		mempoke16(d->dat, 0x2, result);
242 241
 	}
243
-	*/
244
-	(void)d;
245
-	(void)b0;
246 242
 	return b1;
247 243
 }
248 244