Browse code

Made poke functions return void.

Andrew Alderwick authored on 24/04/2021 08:10:24
Showing 4 changed files
... ...
@@ -37,7 +37,7 @@ printstack(Stack *s)
37 37
 
38 38
 #pragma mark - Devices
39 39
 
40
-Uint8
40
+void
41 41
 console_poke(Device *d, Uint8 b0, Uint8 b1)
42 42
 {
43 43
 	switch(b0) {
... ...
@@ -48,10 +48,9 @@ console_poke(Device *d, Uint8 b0, Uint8 b1)
48 48
 	fflush(stdout);
49 49
 	(void)d;
50 50
 	(void)b0;
51
-	return b1;
52 51
 }
53 52
 
54
-Uint8
53
+void
55 54
 file_poke(Device *d, Uint8 b0, Uint8 b1)
56 55
 {
57 56
 	Uint8 read = b0 == 0xd;
... ...
@@ -59,7 +58,7 @@ file_poke(Device *d, Uint8 b0, Uint8 b1)
59 58
 		char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)];
60 59
 		Uint16 result = 0, length = mempeek16(d->dat, 0xa);
61 60
 		Uint16 offset = mempeek16(d->dat, 0x4);
62
-		Uint16 addr = (d->dat[b0 - 1] << 8) | b1;
61
+		Uint16 addr = mempeek16(d->dat, b0 - 1);
63 62
 		FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w"));
64 63
 		if(f) {
65 64
 			if(fseek(f, offset, SEEK_SET) != -1 && (result = read ? fread(&d->mem[addr], 1, length, f) : fwrite(&d->mem[addr], 1, length, f)))
... ...
@@ -68,15 +67,15 @@ file_poke(Device *d, Uint8 b0, Uint8 b1)
68 67
 		}
69 68
 		mempoke16(d->dat, 0x2, result);
70 69
 	}
71
-	return b1;
70
+	(void)b1;
72 71
 }
73 72
 
74
-Uint8
73
+void
75 74
 ppnil(Device *d, Uint8 b0, Uint8 b1)
76 75
 {
77 76
 	(void)d;
78 77
 	(void)b0;
79
-	return b1;
78
+	(void)b1;
80 79
 }
81 80
 
82 81
 #pragma mark - Generics
... ...
@@ -181,17 +181,16 @@ doctrl(Uxn *u, SDL_Event *event, int z)
181 181
 
182 182
 #pragma mark - Devices
183 183
 
184
-Uint8
184
+void
185 185
 system_poke(Device *d, Uint8 b0, Uint8 b1)
186 186
 {
187 187
 	putcolors(&ppu, &d->dat[0x8]);
188 188
 	reqdraw = 1;
189
-	(void)d;
190 189
 	(void)b0;
191
-	return b1;
190
+	(void)b1;
192 191
 }
193 192
 
194
-Uint8
193
+void
195 194
 console_poke(Device *d, Uint8 b0, Uint8 b1)
196 195
 {
197 196
 	switch(b0) {
... ...
@@ -201,10 +200,9 @@ console_poke(Device *d, Uint8 b0, Uint8 b1)
201 200
 	case 0xd: printf("%s\n", &d->mem[(d->dat[0xc] << 8) + b1]); break;
202 201
 	}
203 202
 	fflush(stdout);
204
-	return b1;
205 203
 }
206 204
 
207
-Uint8
205
+void
208 206
 screen_poke(Device *d, Uint8 b0, Uint8 b1)
209 207
 {
210 208
 	if(b0 == 0xe) {
... ...
@@ -219,10 +217,9 @@ screen_poke(Device *d, Uint8 b0, Uint8 b1)
219 217
 		}
220 218
 		reqdraw = 1;
221 219
 	}
222
-	return b1;
223 220
 }
224 221
 
225
-Uint8
222
+void
226 223
 file_poke(Device *d, Uint8 b0, Uint8 b1)
227 224
 {
228 225
 	Uint8 read = b0 == 0xd;
... ...
@@ -230,7 +227,7 @@ file_poke(Device *d, Uint8 b0, Uint8 b1)
230 227
 		char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)];
231 228
 		Uint16 result = 0, length = mempeek16(d->dat, 0xa);
232 229
 		Uint16 offset = mempeek16(d->dat, 0x4);
233
-		Uint16 addr = (d->dat[b0 - 1] << 8) | b1;
230
+		Uint16 addr = mempeek16(d->dat, b0 - 1);
234 231
 		FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w"));
235 232
 		if(f) {
236 233
 			if(fseek(f, offset, SEEK_SET) != -1 && (result = read ? fread(&d->mem[addr], 1, length, f) : fwrite(&d->mem[addr], 1, length, f)))
... ...
@@ -239,10 +236,10 @@ file_poke(Device *d, Uint8 b0, Uint8 b1)
239 236
 		}
240 237
 		mempoke16(d->dat, 0x2, result);
241 238
 	}
242
-	return b1;
239
+	(void)b1;
243 240
 }
244 241
 
245
-static Uint8
242
+static void
246 243
 audio_poke(Device *d, Uint8 b0, Uint8 b1)
247 244
 {
248 245
 	if(b0 == 0xa) {
... ...
@@ -258,14 +255,12 @@ audio_poke(Device *d, Uint8 b0, Uint8 b1)
258 255
 			apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xb) >> 1;
259 256
 		else
260 257
 			apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xb) + 0x8000;
261
-		apu.queue->dat[apu.queue->n++] = (d->dat[0xd] << 8) + b1;
258
+		apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xd);
262 259
 	} else if(b0 == 0xf && apu.queue != NULL)
263 260
 		apu.queue->finishes = 1;
264
-	(void)d;
265
-	return b1;
266 261
 }
267 262
 
268
-Uint8
263
+void
269 264
 datetime_poke(Device *d, Uint8 b0, Uint8 b1)
270 265
 {
271 266
 	time_t seconds = time(NULL);
... ...
@@ -280,17 +275,16 @@ datetime_poke(Device *d, Uint8 b0, Uint8 b1)
280 275
 	d->dat[0x7] = t->tm_wday;
281 276
 	mempoke16(d->dat, 0x08, t->tm_yday);
282 277
 	d->dat[0xa] = t->tm_isdst;
283
-	(void)d;
284 278
 	(void)b0;
285
-	return b1;
279
+	(void)b1;
286 280
 }
287 281
 
288
-Uint8
282
+void
289 283
 ppnil(Device *d, Uint8 b0, Uint8 b1)
290 284
 {
291 285
 	(void)d;
292 286
 	(void)b0;
293
-	return b1;
287
+	(void)b1;
294 288
 }
295 289
 
296 290
 #pragma mark - Generics
... ...
@@ -179,7 +179,7 @@ loaduxn(Uxn *u, char *filepath)
179 179
 }
180 180
 
181 181
 Device *
182
-portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Device *d, Uint8 b0, Uint8 b1))
182
+portuxn(Uxn *u, Uint8 id, char *name, void (*pofn)(Device *d, Uint8 b0, Uint8 b1))
183 183
 {
184 184
 	Device *d = &u->dev[id];
185 185
 	d->addr = id * 0x10;
... ...
@@ -32,7 +32,7 @@ struct Uxn;
32 32
 
33 33
 typedef struct Device {
34 34
 	Uint8 addr, dat[16], *mem;
35
-	Uint8 (*poke)(struct Device *d, Uint8, Uint8);
35
+	void (*poke)(struct Device *d, Uint8, Uint8);
36 36
 } Device;
37 37
 
38 38
 typedef struct Uxn {
... ...
@@ -47,4 +47,4 @@ int evaluxn(Uxn *u, Uint16 vec);
47 47
 void mempoke16(Uint8 *m, Uint16 a, Uint16 b);
48 48
 Uint16 mempeek16(Uint8 *m, Uint16 a);
49 49
 
50
-Device *portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Device *, Uint8, Uint8));
51 50
\ No newline at end of file
51
+Device *portuxn(Uxn *u, Uint8 id, char *name, void (*pofn)(Device *, Uint8, Uint8));
52 52
\ No newline at end of file