0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-30 17:53:01 +00:00

Pass Uxn *u to poke routines instead of Uint8 *m.

This commit is contained in:
Andrew Alderwick 2021-03-22 21:22:06 +00:00
parent ecc50fd9f2
commit 52eb7f11af
3 changed files with 19 additions and 12 deletions

View file

@ -339,8 +339,9 @@ doctrl(Uxn *u, SDL_Event *event, int z)
#pragma mark - Devices
Uint8
console_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
console_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
{
Uint8 *m = u->ram.dat;
switch(b0) {
case 0x08: printf("%c", b1); break;
case 0x09: printf("0x%02x\n", b1); break;
@ -354,8 +355,9 @@ console_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
}
Uint8
screen_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
screen_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
{
Uint8 *m = u->ram.dat;
ptr += 8;
if(b0 == 0x0c) {
Uint16 x = (m[ptr] << 8) + m[ptr + 1];
@ -367,8 +369,9 @@ screen_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
}
Uint8
sprite_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
sprite_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
{
Uint8 *m = u->ram.dat;
ptr += 8;
if(b0 == 0x0e) {
Uint16 x = (m[ptr] << 8) + m[ptr + 1];
@ -386,8 +389,9 @@ sprite_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
}
Uint8
file_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
file_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
{
Uint8 *m = u->ram.dat;
char *name = (char *)&m[(m[ptr + 8] << 8) + m[ptr + 8 + 1]];
Uint16 length = (m[ptr + 8 + 2] << 8) + m[ptr + 8 + 3];
if(b0 == 0x0d) {
@ -409,8 +413,9 @@ file_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
}
Uint8
system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
system_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
{
Uint8 *m = u->ram.dat;
loadtheme(&m[PAGE_DEVICE + 0x00f8]);
(void)ptr;
(void)b0;
@ -418,9 +423,9 @@ system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
}
Uint8
ppnil(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
{
(void)m;
(void)u;
(void)ptr;
(void)b0;
return b1;

4
uxn.c
View file

@ -18,7 +18,7 @@ WITH REGARD TO THIS SOFTWARE.
/* clang-format off */
void setflag(Uint8 *a, char flag, int b) { if(b) *a |= flag; else *a &= (~flag); }
int getflag(Uint8 *a, char flag) { return *a & flag; }
Uint8 devpoke8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < u->devices ? u->dev[id].poke(u->ram.dat, PAGE_DEVICE + id * 0x10, b0, b1) : b1; }
Uint8 devpoke8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < u->devices ? u->dev[id].poke(u, PAGE_DEVICE + id * 0x10, b0, b1) : b1; }
void mempoke8(Uxn *u, Uint16 a, Uint8 b) { u->ram.dat[a] = (a & 0xff00) == PAGE_DEVICE ? devpoke8(u, (a & 0xff) >> 4, a & 0xf, b) : b; }
Uint8 mempeek8(Uxn *u, Uint16 a) { return u->ram.dat[a]; }
void mempoke16(Uxn *u, Uint16 a, Uint16 b) { mempoke8(u, a, b >> 8); mempoke8(u, a + 1, b); }
@ -224,7 +224,7 @@ loaduxn(Uxn *u, char *filepath)
}
Device *
portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1))
portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1))
{
Device *d = &u->dev[u->devices++];
d->addr = PAGE_DEVICE + (u->devices - 1) * 0x10;

8
uxn.h
View file

@ -32,12 +32,14 @@ typedef struct {
Uint8 dat[65536];
} Memory;
struct Uxn;
typedef struct Device {
Uint16 addr;
Uint8 (*poke)(Uint8 *, Uint16, Uint8, Uint8);
Uint8 (*poke)(struct Uxn *, Uint16, Uint8, Uint8);
} Device;
typedef struct {
typedef struct Uxn {
Uint8 literal, status, devices;
Uint16 counter, vreset, vframe, verror;
Stack wst, rst, *src, *dst;
@ -50,4 +52,4 @@ int getflag(Uint8 *status, char flag);
int loaduxn(Uxn *c, char *filepath);
int bootuxn(Uxn *c);
int evaluxn(Uxn *u, Uint16 vec);
Device *portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uint8 *, Uint16, Uint8, Uint8));
Device *portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8));