0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-23 22:35:11 +00:00

Removed extra param in poke functions

This commit is contained in:
neauoire 2021-04-20 21:29:18 -07:00
parent 02993229ee
commit 526650f079
4 changed files with 36 additions and 37 deletions

View file

@ -38,12 +38,12 @@ printstack(Stack *s)
#pragma mark - Devices
Uint8
console_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
console_poke(Device *d, Uint8 b0, Uint8 b1)
{
switch(b0) {
case 0x08: printf("%c", b1); break;
case 0x09: printf("0x%02x\n", b1); break;
case 0x0b: printf("0x%04x\n", (m[0x0a] << 8) + b1); break;
case 0x0b: printf("0x%04x\n", (d->dat[0x0a] << 8) + b1); break;
}
fflush(stdout);
(void)d;
@ -52,8 +52,9 @@ console_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
}
Uint8
file_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
file_poke(Device *d, Uint8 b0, Uint8 b1)
{
/*
Uint8 read = b0 == 0xd;
if(read || b0 == 0xf) {
char *name = (char *)&d->mem[mempeek16(m, 0x8)];
@ -68,14 +69,14 @@ file_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
}
mempoke16(m, 0x2, result);
}
*/
return b1;
}
Uint8
ppnil(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
ppnil(Device *d, Uint8 b0, Uint8 b1)
{
(void)d;
(void)m;
(void)b0;
return b1;
}

View file

@ -182,9 +182,9 @@ doctrl(Uxn *u, SDL_Event *event, int z)
#pragma mark - Devices
Uint8
system_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
system_poke(Device *d, Uint8 b0, Uint8 b1)
{
putcolors(&ppu, &m[0x8]);
putcolors(&ppu, &d->dat[0x8]);
reqdraw = 1;
(void)d;
(void)b0;
@ -192,25 +192,25 @@ system_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
}
Uint8
console_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
console_poke(Device *d, Uint8 b0, Uint8 b1)
{
switch(b0) {
case 0x8: printf("%c", b1); break;
case 0x9: printf("0x%02x\n", b1); break;
case 0xb: printf("0x%04x\n", (m[0xa] << 8) + b1); break;
case 0xd: printf("%s\n", &d->mem[(m[0xc] << 8) + b1]); break;
case 0xb: printf("0x%04x\n", (d->dat[0xa] << 8) + b1); break;
case 0xd: printf("%s\n", &d->mem[(d->dat[0xc] << 8) + b1]); break;
}
fflush(stdout);
return b1;
}
Uint8
screen_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
screen_poke(Device *d, Uint8 b0, Uint8 b1)
{
if(b0 == 0xe) {
Uint16 x = mempeek16(m, 0x8);
Uint16 y = mempeek16(m, 0xa);
Uint8 *addr = &d->mem[mempeek16(m, 0xc)];
Uint16 x = mempeek16(d->dat, 0x8);
Uint16 y = mempeek16(d->dat, 0xa);
Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)];
Uint8 *layer = b1 >> 4 & 0x1 ? ppu.fg : ppu.bg;
switch(b1 >> 5) {
case 0: putpixel(&ppu, layer, x, y, b1 & 0x3); break;
@ -223,7 +223,7 @@ screen_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
}
Uint8
file_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
file_poke(Device *d, Uint8 b0, Uint8 b1)
{
/* TODO: Figure out why fwrite doesn't work with d->mem
Uint8 read = b0 == 0xd;
@ -242,28 +242,27 @@ file_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
}
*/
(void)d;
(void)m;
(void)b0;
return b1;
}
static Uint8
audio_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
audio_poke(Device *d, Uint8 b0, Uint8 b1)
{
if(b0 == 0xa) {
if(b1 >= apu.n_notes) apu.notes = SDL_realloc(apu.notes, (b1 + 1) * sizeof(Note));
while(b1 >= apu.n_notes) SDL_zero(apu.notes[apu.n_notes++]);
apu_play_note(&apu.notes[b1], mempeek16(m, 0x0), mempeek16(m, 0x2), m[0x8], m[0x9] & 0x7f, m[0x9] > 0x7f);
apu_play_note(&apu.notes[b1], mempeek16(d->dat, 0x0), mempeek16(d->dat, 0x2), d->dat[0x8], d->dat[0x9] & 0x7f, d->dat[0x9] > 0x7f);
} else if(b0 == 0xe && apu.queue != NULL) {
if(apu.queue->n == apu.queue->sz) {
apu.queue->sz = apu.queue->sz < 4 ? 4 : apu.queue->sz * 2;
apu.queue->dat = SDL_realloc(apu.queue->dat, apu.queue->sz * sizeof(*apu.queue->dat));
}
if(apu.queue->is_envelope)
apu.queue->dat[apu.queue->n++] = mempeek16(m, 0xb) >> 1;
apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xb) >> 1;
else
apu.queue->dat[apu.queue->n++] = mempeek16(m, 0xb) + 0x8000;
apu.queue->dat[apu.queue->n++] = (m[0xd] << 8) + b1;
apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xb) + 0x8000;
apu.queue->dat[apu.queue->n++] = (d->dat[0xd] << 8) + b1;
} else if(b0 == 0xf && apu.queue != NULL)
apu.queue->finishes = 1;
(void)d;
@ -271,30 +270,29 @@ audio_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
}
Uint8
datetime_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
datetime_poke(Device *d, Uint8 b0, Uint8 b1)
{
time_t seconds = time(NULL);
struct tm *t = localtime(&seconds);
t->tm_year += 1900;
mempoke16(m, 0x0, t->tm_year);
m[0x2] = t->tm_mon;
m[0x3] = t->tm_mday;
m[0x4] = t->tm_hour;
m[0x5] = t->tm_min;
m[0x6] = t->tm_sec;
m[0x7] = t->tm_wday;
mempoke16(m, 0x08, t->tm_yday);
m[0xa] = t->tm_isdst;
mempoke16(d->dat, 0x0, t->tm_year);
d->dat[0x2] = t->tm_mon;
d->dat[0x3] = t->tm_mday;
d->dat[0x4] = t->tm_hour;
d->dat[0x5] = t->tm_min;
d->dat[0x6] = t->tm_sec;
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;
}
Uint8
ppnil(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
ppnil(Device *d, Uint8 b0, Uint8 b1)
{
(void)d;
(void)m;
(void)b0;
return b1;
}

View file

@ -21,7 +21,7 @@ Uint8 pop8(Stack *s) { if (s->ptr == 0) { s->error = 1; return 0; } return s->d
Uint8 peek8(Stack *s, Uint8 a) { if (s->ptr < a + 1) s->error = 1; return s->dat[s->ptr - a - 1]; }
void mempoke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; }
Uint8 mempeek8(Uint8 *m, Uint16 a) { return m[a]; }
void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->poke(d, d->dat, a & 0x0f, b); }
void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->poke(d, a & 0x0f, b); }
Uint8 devpeek8(Device *d, Uint8 a) { return d->dat[a & 0xf]; }
void push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
Uint16 pop16(Stack *s) { return pop8(s) + (pop8(s) << 8); }
@ -179,7 +179,7 @@ loaduxn(Uxn *u, char *filepath)
}
Device *
portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Device *d, Uint8 *devmem, Uint8 b0, Uint8 b1))
portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*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 *devmem, Uint8, Uint8);
Uint8 (*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, Uint8));
Device *portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Device *, Uint8, Uint8));