mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-12-17 22:10:14 +00:00
Removed extra param in poke functions
This commit is contained in:
parent
02993229ee
commit
526650f079
4 changed files with 36 additions and 37 deletions
|
@ -38,12 +38,12 @@ printstack(Stack *s)
|
||||||
#pragma mark - Devices
|
#pragma mark - Devices
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
console_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
console_poke(Device *d, Uint8 b0, Uint8 b1)
|
||||||
{
|
{
|
||||||
switch(b0) {
|
switch(b0) {
|
||||||
case 0x08: printf("%c", b1); break;
|
case 0x08: printf("%c", b1); break;
|
||||||
case 0x09: printf("0x%02x\n", 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);
|
fflush(stdout);
|
||||||
(void)d;
|
(void)d;
|
||||||
|
@ -52,8 +52,9 @@ console_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
file_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
file_poke(Device *d, Uint8 b0, Uint8 b1)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
Uint8 read = b0 == 0xd;
|
Uint8 read = b0 == 0xd;
|
||||||
if(read || b0 == 0xf) {
|
if(read || b0 == 0xf) {
|
||||||
char *name = (char *)&d->mem[mempeek16(m, 0x8)];
|
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);
|
mempoke16(m, 0x2, result);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return b1;
|
return b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
ppnil(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
ppnil(Device *d, Uint8 b0, Uint8 b1)
|
||||||
{
|
{
|
||||||
(void)d;
|
(void)d;
|
||||||
(void)m;
|
|
||||||
(void)b0;
|
(void)b0;
|
||||||
return b1;
|
return b1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,9 +182,9 @@ doctrl(Uxn *u, SDL_Event *event, int z)
|
||||||
#pragma mark - Devices
|
#pragma mark - Devices
|
||||||
|
|
||||||
Uint8
|
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;
|
reqdraw = 1;
|
||||||
(void)d;
|
(void)d;
|
||||||
(void)b0;
|
(void)b0;
|
||||||
|
@ -192,25 +192,25 @@ system_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
console_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
console_poke(Device *d, Uint8 b0, Uint8 b1)
|
||||||
{
|
{
|
||||||
switch(b0) {
|
switch(b0) {
|
||||||
case 0x8: printf("%c", b1); break;
|
case 0x8: printf("%c", b1); break;
|
||||||
case 0x9: printf("0x%02x\n", b1); break;
|
case 0x9: printf("0x%02x\n", b1); break;
|
||||||
case 0xb: printf("0x%04x\n", (m[0xa] << 8) + b1); break;
|
case 0xb: printf("0x%04x\n", (d->dat[0xa] << 8) + b1); break;
|
||||||
case 0xd: printf("%s\n", &d->mem[(m[0xc] << 8) + b1]); break;
|
case 0xd: printf("%s\n", &d->mem[(d->dat[0xc] << 8) + b1]); break;
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return b1;
|
return b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
screen_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
screen_poke(Device *d, Uint8 b0, Uint8 b1)
|
||||||
{
|
{
|
||||||
if(b0 == 0xe) {
|
if(b0 == 0xe) {
|
||||||
Uint16 x = mempeek16(m, 0x8);
|
Uint16 x = mempeek16(d->dat, 0x8);
|
||||||
Uint16 y = mempeek16(m, 0xa);
|
Uint16 y = mempeek16(d->dat, 0xa);
|
||||||
Uint8 *addr = &d->mem[mempeek16(m, 0xc)];
|
Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)];
|
||||||
Uint8 *layer = b1 >> 4 & 0x1 ? ppu.fg : ppu.bg;
|
Uint8 *layer = b1 >> 4 & 0x1 ? ppu.fg : ppu.bg;
|
||||||
switch(b1 >> 5) {
|
switch(b1 >> 5) {
|
||||||
case 0: putpixel(&ppu, layer, x, y, b1 & 0x3); break;
|
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
|
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
|
/* TODO: Figure out why fwrite doesn't work with d->mem
|
||||||
Uint8 read = b0 == 0xd;
|
Uint8 read = b0 == 0xd;
|
||||||
|
@ -242,28 +242,27 @@ file_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
(void)d;
|
(void)d;
|
||||||
(void)m;
|
|
||||||
(void)b0;
|
(void)b0;
|
||||||
return b1;
|
return b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8
|
static Uint8
|
||||||
audio_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
audio_poke(Device *d, Uint8 b0, Uint8 b1)
|
||||||
{
|
{
|
||||||
if(b0 == 0xa) {
|
if(b0 == 0xa) {
|
||||||
if(b1 >= apu.n_notes) apu.notes = SDL_realloc(apu.notes, (b1 + 1) * sizeof(Note));
|
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++]);
|
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) {
|
} else if(b0 == 0xe && apu.queue != NULL) {
|
||||||
if(apu.queue->n == apu.queue->sz) {
|
if(apu.queue->n == apu.queue->sz) {
|
||||||
apu.queue->sz = apu.queue->sz < 4 ? 4 : apu.queue->sz * 2;
|
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));
|
apu.queue->dat = SDL_realloc(apu.queue->dat, apu.queue->sz * sizeof(*apu.queue->dat));
|
||||||
}
|
}
|
||||||
if(apu.queue->is_envelope)
|
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
|
else
|
||||||
apu.queue->dat[apu.queue->n++] = mempeek16(m, 0xb) + 0x8000;
|
apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xb) + 0x8000;
|
||||||
apu.queue->dat[apu.queue->n++] = (m[0xd] << 8) + b1;
|
apu.queue->dat[apu.queue->n++] = (d->dat[0xd] << 8) + b1;
|
||||||
} else if(b0 == 0xf && apu.queue != NULL)
|
} else if(b0 == 0xf && apu.queue != NULL)
|
||||||
apu.queue->finishes = 1;
|
apu.queue->finishes = 1;
|
||||||
(void)d;
|
(void)d;
|
||||||
|
@ -271,30 +270,29 @@ audio_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
datetime_poke(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
datetime_poke(Device *d, Uint8 b0, Uint8 b1)
|
||||||
{
|
{
|
||||||
time_t seconds = time(NULL);
|
time_t seconds = time(NULL);
|
||||||
struct tm *t = localtime(&seconds);
|
struct tm *t = localtime(&seconds);
|
||||||
t->tm_year += 1900;
|
t->tm_year += 1900;
|
||||||
mempoke16(m, 0x0, t->tm_year);
|
mempoke16(d->dat, 0x0, t->tm_year);
|
||||||
m[0x2] = t->tm_mon;
|
d->dat[0x2] = t->tm_mon;
|
||||||
m[0x3] = t->tm_mday;
|
d->dat[0x3] = t->tm_mday;
|
||||||
m[0x4] = t->tm_hour;
|
d->dat[0x4] = t->tm_hour;
|
||||||
m[0x5] = t->tm_min;
|
d->dat[0x5] = t->tm_min;
|
||||||
m[0x6] = t->tm_sec;
|
d->dat[0x6] = t->tm_sec;
|
||||||
m[0x7] = t->tm_wday;
|
d->dat[0x7] = t->tm_wday;
|
||||||
mempoke16(m, 0x08, t->tm_yday);
|
mempoke16(d->dat, 0x08, t->tm_yday);
|
||||||
m[0xa] = t->tm_isdst;
|
d->dat[0xa] = t->tm_isdst;
|
||||||
(void)d;
|
(void)d;
|
||||||
(void)b0;
|
(void)b0;
|
||||||
return b1;
|
return b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
ppnil(Device *d, Uint8 *m, Uint8 b0, Uint8 b1)
|
ppnil(Device *d, Uint8 b0, Uint8 b1)
|
||||||
{
|
{
|
||||||
(void)d;
|
(void)d;
|
||||||
(void)m;
|
|
||||||
(void)b0;
|
(void)b0;
|
||||||
return b1;
|
return b1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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]; }
|
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; }
|
void mempoke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; }
|
||||||
Uint8 mempeek8(Uint8 *m, Uint16 a) { return m[a]; }
|
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]; }
|
Uint8 devpeek8(Device *d, Uint8 a) { return d->dat[a & 0xf]; }
|
||||||
void push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
|
void push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
|
||||||
Uint16 pop16(Stack *s) { return pop8(s) + (pop8(s) << 8); }
|
Uint16 pop16(Stack *s) { return pop8(s) + (pop8(s) << 8); }
|
||||||
|
@ -179,7 +179,7 @@ loaduxn(Uxn *u, char *filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *
|
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];
|
Device *d = &u->dev[id];
|
||||||
d->addr = id * 0x10;
|
d->addr = id * 0x10;
|
||||||
|
|
|
@ -32,7 +32,7 @@ struct Uxn;
|
||||||
|
|
||||||
typedef struct Device {
|
typedef struct Device {
|
||||||
Uint8 addr, dat[16], *mem;
|
Uint8 addr, dat[16], *mem;
|
||||||
Uint8 (*poke)(struct Device *d, Uint8 *devmem, Uint8, Uint8);
|
Uint8 (*poke)(struct Device *d, Uint8, Uint8);
|
||||||
} Device;
|
} Device;
|
||||||
|
|
||||||
typedef struct Uxn {
|
typedef struct Uxn {
|
||||||
|
@ -47,4 +47,4 @@ int evaluxn(Uxn *u, Uint16 vec);
|
||||||
void mempoke16(Uint8 *m, Uint16 a, Uint16 b);
|
void mempoke16(Uint8 *m, Uint16 a, Uint16 b);
|
||||||
Uint16 mempeek16(Uint8 *m, Uint16 a);
|
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));
|
Loading…
Reference in a new issue