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:
parent
ecc50fd9f2
commit
52eb7f11af
3 changed files with 19 additions and 12 deletions
19
emulator.c
19
emulator.c
|
@ -339,8 +339,9 @@ doctrl(Uxn *u, SDL_Event *event, int z)
|
||||||
#pragma mark - Devices
|
#pragma mark - Devices
|
||||||
|
|
||||||
Uint8
|
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) {
|
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;
|
||||||
|
@ -354,8 +355,9 @@ console_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
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;
|
ptr += 8;
|
||||||
if(b0 == 0x0c) {
|
if(b0 == 0x0c) {
|
||||||
Uint16 x = (m[ptr] << 8) + m[ptr + 1];
|
Uint16 x = (m[ptr] << 8) + m[ptr + 1];
|
||||||
|
@ -367,8 +369,9 @@ screen_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
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;
|
ptr += 8;
|
||||||
if(b0 == 0x0e) {
|
if(b0 == 0x0e) {
|
||||||
Uint16 x = (m[ptr] << 8) + m[ptr + 1];
|
Uint16 x = (m[ptr] << 8) + m[ptr + 1];
|
||||||
|
@ -386,8 +389,9 @@ sprite_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
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]];
|
char *name = (char *)&m[(m[ptr + 8] << 8) + m[ptr + 8 + 1]];
|
||||||
Uint16 length = (m[ptr + 8 + 2] << 8) + m[ptr + 8 + 3];
|
Uint16 length = (m[ptr + 8 + 2] << 8) + m[ptr + 8 + 3];
|
||||||
if(b0 == 0x0d) {
|
if(b0 == 0x0d) {
|
||||||
|
@ -409,8 +413,9 @@ file_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
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]);
|
loadtheme(&m[PAGE_DEVICE + 0x00f8]);
|
||||||
(void)ptr;
|
(void)ptr;
|
||||||
(void)b0;
|
(void)b0;
|
||||||
|
@ -418,9 +423,9 @@ system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
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)ptr;
|
||||||
(void)b0;
|
(void)b0;
|
||||||
return b1;
|
return b1;
|
||||||
|
|
4
uxn.c
4
uxn.c
|
@ -18,7 +18,7 @@ WITH REGARD TO THIS SOFTWARE.
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
void setflag(Uint8 *a, char flag, int b) { if(b) *a |= flag; else *a &= (~flag); }
|
void setflag(Uint8 *a, char flag, int b) { if(b) *a |= flag; else *a &= (~flag); }
|
||||||
int getflag(Uint8 *a, char flag) { return *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; }
|
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]; }
|
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); }
|
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 *
|
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++];
|
Device *d = &u->dev[u->devices++];
|
||||||
d->addr = PAGE_DEVICE + (u->devices - 1) * 0x10;
|
d->addr = PAGE_DEVICE + (u->devices - 1) * 0x10;
|
||||||
|
|
8
uxn.h
8
uxn.h
|
@ -32,12 +32,14 @@ typedef struct {
|
||||||
Uint8 dat[65536];
|
Uint8 dat[65536];
|
||||||
} Memory;
|
} Memory;
|
||||||
|
|
||||||
|
struct Uxn;
|
||||||
|
|
||||||
typedef struct Device {
|
typedef struct Device {
|
||||||
Uint16 addr;
|
Uint16 addr;
|
||||||
Uint8 (*poke)(Uint8 *, Uint16, Uint8, Uint8);
|
Uint8 (*poke)(struct Uxn *, Uint16, Uint8, Uint8);
|
||||||
} Device;
|
} Device;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Uxn {
|
||||||
Uint8 literal, status, devices;
|
Uint8 literal, status, devices;
|
||||||
Uint16 counter, vreset, vframe, verror;
|
Uint16 counter, vreset, vframe, verror;
|
||||||
Stack wst, rst, *src, *dst;
|
Stack wst, rst, *src, *dst;
|
||||||
|
@ -50,4 +52,4 @@ int getflag(Uint8 *status, char flag);
|
||||||
int loaduxn(Uxn *c, char *filepath);
|
int loaduxn(Uxn *c, char *filepath);
|
||||||
int bootuxn(Uxn *c);
|
int bootuxn(Uxn *c);
|
||||||
int evaluxn(Uxn *u, Uint16 vec);
|
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));
|
||||||
|
|
Loading…
Reference in a new issue