Made poke functions return void.

This commit is contained in:
Andrew Alderwick 2021-04-24 09:10:24 +01:00
parent 43a0ad26c8
commit fa2d290351
4 changed files with 22 additions and 29 deletions

View File

@ -37,7 +37,7 @@ printstack(Stack *s)
#pragma mark - Devices
Uint8
void
console_poke(Device *d, Uint8 b0, Uint8 b1)
{
switch(b0) {
@ -48,10 +48,9 @@ console_poke(Device *d, Uint8 b0, Uint8 b1)
fflush(stdout);
(void)d;
(void)b0;
return b1;
}
Uint8
void
file_poke(Device *d, Uint8 b0, Uint8 b1)
{
Uint8 read = b0 == 0xd;
@ -59,7 +58,7 @@ file_poke(Device *d, Uint8 b0, Uint8 b1)
char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)];
Uint16 result = 0, length = mempeek16(d->dat, 0xa);
Uint16 offset = mempeek16(d->dat, 0x4);
Uint16 addr = (d->dat[b0 - 1] << 8) | b1;
Uint16 addr = mempeek16(d->dat, b0 - 1);
FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w"));
if(f) {
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)
}
mempoke16(d->dat, 0x2, result);
}
return b1;
(void)b1;
}
Uint8
void
ppnil(Device *d, Uint8 b0, Uint8 b1)
{
(void)d;
(void)b0;
return b1;
(void)b1;
}
#pragma mark - Generics

View File

@ -181,17 +181,16 @@ doctrl(Uxn *u, SDL_Event *event, int z)
#pragma mark - Devices
Uint8
void
system_poke(Device *d, Uint8 b0, Uint8 b1)
{
putcolors(&ppu, &d->dat[0x8]);
reqdraw = 1;
(void)d;
(void)b0;
return b1;
(void)b1;
}
Uint8
void
console_poke(Device *d, Uint8 b0, Uint8 b1)
{
switch(b0) {
@ -201,10 +200,9 @@ console_poke(Device *d, Uint8 b0, Uint8 b1)
case 0xd: printf("%s\n", &d->mem[(d->dat[0xc] << 8) + b1]); break;
}
fflush(stdout);
return b1;
}
Uint8
void
screen_poke(Device *d, Uint8 b0, Uint8 b1)
{
if(b0 == 0xe) {
@ -219,10 +217,9 @@ screen_poke(Device *d, Uint8 b0, Uint8 b1)
}
reqdraw = 1;
}
return b1;
}
Uint8
void
file_poke(Device *d, Uint8 b0, Uint8 b1)
{
Uint8 read = b0 == 0xd;
@ -230,7 +227,7 @@ file_poke(Device *d, Uint8 b0, Uint8 b1)
char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)];
Uint16 result = 0, length = mempeek16(d->dat, 0xa);
Uint16 offset = mempeek16(d->dat, 0x4);
Uint16 addr = (d->dat[b0 - 1] << 8) | b1;
Uint16 addr = mempeek16(d->dat, b0 - 1);
FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w"));
if(f) {
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)
}
mempoke16(d->dat, 0x2, result);
}
return b1;
(void)b1;
}
static Uint8
static void
audio_poke(Device *d, Uint8 b0, Uint8 b1)
{
if(b0 == 0xa) {
@ -258,14 +255,12 @@ audio_poke(Device *d, Uint8 b0, Uint8 b1)
apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xb) >> 1;
else
apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xb) + 0x8000;
apu.queue->dat[apu.queue->n++] = (d->dat[0xd] << 8) + b1;
apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xd);
} else if(b0 == 0xf && apu.queue != NULL)
apu.queue->finishes = 1;
(void)d;
return b1;
}
Uint8
void
datetime_poke(Device *d, Uint8 b0, Uint8 b1)
{
time_t seconds = time(NULL);
@ -280,17 +275,16 @@ datetime_poke(Device *d, Uint8 b0, Uint8 b1)
d->dat[0x7] = t->tm_wday;
mempoke16(d->dat, 0x08, t->tm_yday);
d->dat[0xa] = t->tm_isdst;
(void)d;
(void)b0;
return b1;
(void)b1;
}
Uint8
void
ppnil(Device *d, Uint8 b0, Uint8 b1)
{
(void)d;
(void)b0;
return b1;
(void)b1;
}
#pragma mark - Generics

View File

@ -179,7 +179,7 @@ loaduxn(Uxn *u, char *filepath)
}
Device *
portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Device *d, Uint8 b0, Uint8 b1))
portuxn(Uxn *u, Uint8 id, char *name, void (*pofn)(Device *d, Uint8 b0, Uint8 b1))
{
Device *d = &u->dev[id];
d->addr = id * 0x10;

View File

@ -32,7 +32,7 @@ struct Uxn;
typedef struct Device {
Uint8 addr, dat[16], *mem;
Uint8 (*poke)(struct Device *d, Uint8, Uint8);
void (*poke)(struct Device *d, Uint8, Uint8);
} Device;
typedef struct Uxn {
@ -47,4 +47,4 @@ int evaluxn(Uxn *u, Uint16 vec);
void mempoke16(Uint8 *m, Uint16 a, Uint16 b);
Uint16 mempeek16(Uint8 *m, Uint16 a);
Device *portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Device *, Uint8, Uint8));
Device *portuxn(Uxn *u, Uint8 id, char *name, void (*pofn)(Device *, Uint8, Uint8));