0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-24 06:45:11 +00:00

Removed poke16

This commit is contained in:
neauoire 2022-01-03 13:23:57 -08:00
parent c4746c2601
commit 0ee477615b
7 changed files with 69 additions and 33 deletions

View file

@ -144,12 +144,35 @@ file_delete(void)
void void
file_deo(Device *d, Uint8 port) file_deo(Device *d, Uint8 port)
{ {
Uint16 a, b, res;
switch(port) { switch(port) {
case 0x1: d->vector = peek16(d->dat, 0x0); break; case 0x1: d->vector = peek16(d->dat, 0x0); break;
case 0x9: poke16(d->dat, 0x2, file_init(&d->mem[peek16(d->dat, 0x8)])); break; case 0x9:
case 0xd: poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa))); break; DEVPEEK16(a, 0x8);
case 0xf: poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7])); break; res = file_init(&d->mem[a]);
case 0x5: poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa))); break; DEVPOKE16(0x2, res);
case 0x6: poke16(d->dat, 0x2, file_delete()); break; break;
case 0xd:
DEVPEEK16(a, 0xc);
DEVPEEK16(b, 0xa);
res = file_read(&d->mem[a], b);
DEVPOKE16(0x2, res);
break;
case 0xf:
DEVPEEK16(a, 0xe);
DEVPEEK16(b, 0xa);
res = file_write(&d->mem[a], b, d->dat[0x7]);
DEVPOKE16(0x2, res);
break;
case 0x5:
DEVPEEK16(a, 0x4);
DEVPEEK16(b, 0xa);
res = file_stat(&d->mem[a], b);
DEVPOKE16(0x2, res);
break;
case 0x6:
res = file_delete();
DEVPOKE16(0x2, res);
break;
} }
} }

View file

@ -30,17 +30,17 @@ mouse_up(Device *d, Uint8 mask)
void void
mouse_pos(Device *d, Uint16 x, Uint16 y) mouse_pos(Device *d, Uint16 x, Uint16 y)
{ {
poke16(d->dat, 0x2, x); DEVPOKE16(0x2, x);
poke16(d->dat, 0x4, y); DEVPOKE16(0x4, y);
uxn_eval(d->u, d->vector); uxn_eval(d->u, d->vector);
} }
void void
mouse_scroll(Device *d, Uint16 x, Uint16 y) mouse_scroll(Device *d, Uint16 x, Uint16 y)
{ {
poke16(d->dat, 0xa, x); DEVPOKE16(0xa, x);
poke16(d->dat, 0xc, -y); DEVPOKE16(0xc, -y);
uxn_eval(d->u, d->vector); uxn_eval(d->u, d->vector);
poke16(d->dat, 0xa, 0); DEVPOKE16(0xa, 0);
poke16(d->dat, 0xc, 0); DEVPOKE16(0xc, 0);
} }

View file

@ -172,29 +172,36 @@ void
screen_deo(Device *d, Uint8 port) screen_deo(Device *d, Uint8 port)
{ {
switch(port) { switch(port) {
case 0x1: d->vector = peek16(d->dat, 0x0); break; case 0x1: DEVPEEK16(d->vector, 0x0); break;
case 0x5: case 0x5:
if(!FIXED_SIZE) set_size(peek16(d->dat, 0x2), peek16(d->dat, 0x4), 1); if(!FIXED_SIZE) {
Uint16 w, h;
DEVPEEK16(w, 0x2);
DEVPEEK16(h, 0x4);
set_size(w, h, 1);
}
break; break;
case 0xe: { case 0xe: {
Uint16 x = peek16(d->dat, 0x8); Uint16 x, y;
Uint16 y = peek16(d->dat, 0xa);
Uint8 layer = d->dat[0xe] & 0x40; Uint8 layer = d->dat[0xe] & 0x40;
DEVPEEK16(x, 0x8);
DEVPEEK16(y, 0xa);
screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d->dat[0xe] & 0x3); screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d->dat[0xe] & 0x3);
if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */ if(d->dat[0x6] & 0x01) DEVPOKE16(0x8, x + 1); /* auto x+1 */
if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */ if(d->dat[0x6] & 0x02) DEVPOKE16(0xa, y + 1); /* auto y+1 */
break; break;
} }
case 0xf: { case 0xf: {
Uint16 x = peek16(d->dat, 0x8); Uint16 x, y, addr;
Uint16 y = peek16(d->dat, 0xa);
Layer *layer = (d->dat[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
Uint8 *addr = &d->mem[peek16(d->dat, 0xc)];
Uint8 twobpp = !!(d->dat[0xf] & 0x80); Uint8 twobpp = !!(d->dat[0xf] & 0x80);
screen_blit(&uxn_screen, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp); Layer *layer = (d->dat[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp * 8); /* auto addr+8 / auto addr+16 */ DEVPEEK16(x, 0x8);
if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8); /* auto x+8 */ DEVPEEK16(y, 0xa);
if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8); /* auto y+8 */ DEVPEEK16(addr, 0xc);
screen_blit(&uxn_screen, layer, x, y, &d->mem[addr], d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp);
if(d->dat[0x6] & 0x04) DEVPOKE16(0xc, addr + 8 + twobpp * 8); /* auto addr+length */
if(d->dat[0x6] & 0x01) DEVPOKE16(0x8, x + 8); /* auto x+8 */
if(d->dat[0x6] & 0x02) DEVPOKE16(0xa, y + 8); /* auto y+8 */
break; break;
} }
} }

View file

@ -31,7 +31,6 @@ WITH REGARD TO THIS SOFTWARE.
#define DEVW(d, x, y) { dev = (d); if(bs) { DEVW8((x), (y) >> 8); DEVW8((x) + 1, (y)); } else { DEVW8((x), (y)) } } #define DEVW(d, x, y) { dev = (d); if(bs) { DEVW8((x), (y) >> 8); DEVW8((x) + 1, (y)); } else { DEVW8((x), (y)) } }
#define WARP(x) { if(bs) u->ram.ptr = (x); else u->ram.ptr += (Sint8)(x); } #define WARP(x) { if(bs) u->ram.ptr = (x); else u->ram.ptr += (Sint8)(x); }
void poke16(Uint8 *m, Uint16 a, Uint16 b) { m[a] = b >> 8; m[a + 1] = b; }
Uint16 peek16(Uint8 *m, Uint16 a) { Uint16 r = m[a] << 8; return r + m[a + 1]; } Uint16 peek16(Uint8 *m, Uint16 a) { Uint16 r = m[a] << 8; return r + m[a + 1]; }
int int

View file

@ -17,6 +17,13 @@ typedef unsigned int Uint32;
#define PAGE_PROGRAM 0x0100 #define PAGE_PROGRAM 0x0100
/* clang-format off */
#define DEVPEEK16(o, x) { (o) = (d->dat[(x)] << 8) + d->dat[(x) + 1]; }
#define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); }
/* clang-format on */
typedef struct { typedef struct {
Uint8 ptr; Uint8 ptr;
Uint8 dat[256]; Uint8 dat[256];
@ -41,7 +48,6 @@ typedef struct Uxn {
Device dev[16]; Device dev[16];
} Uxn; } Uxn;
void poke16(Uint8 *m, Uint16 a, Uint16 b);
Uint16 peek16(Uint8 *m, Uint16 a); Uint16 peek16(Uint8 *m, Uint16 a);
int uxn_boot(Uxn *c, Uint8 *memory); int uxn_boot(Uxn *c, Uint8 *memory);

View file

@ -72,7 +72,7 @@ static void
console_deo(Device *d, Uint8 port) console_deo(Device *d, Uint8 port)
{ {
if(port == 0x1) if(port == 0x1)
d->vector = peek16(d->dat, 0x0); DEVPEEK16(d->vector, 0x0);
if(port > 0x7) if(port > 0x7)
write(port - 0x7, (char *)&d->dat[port], 1); write(port - 0x7, (char *)&d->dat[port], 1);
} }
@ -110,7 +110,7 @@ nil_dei(Device *d, Uint8 port)
static void static void
nil_deo(Device *d, Uint8 port) nil_deo(Device *d, Uint8 port)
{ {
if(port == 0x1) d->vector = peek16(d->dat, 0x0); if(port == 0x1) DEVPEEK16(d->vector, 0x0);
} }
#pragma mark - Generics #pragma mark - Generics
@ -135,8 +135,9 @@ static void
run(Uxn *u) run(Uxn *u)
{ {
Uint16 vec; Uint16 vec;
Device *d = devconsole;
while((!u->dev[0].dat[0xf]) && (read(0, &devconsole->dat[0x2], 1) > 0)) { while((!u->dev[0].dat[0xf]) && (read(0, &devconsole->dat[0x2], 1) > 0)) {
vec = peek16(devconsole->dat, 0); DEVPEEK16(vec, 0);
if(!vec) vec = u->ram.ptr; /* continue after last BRK */ if(!vec) vec = u->ram.ptr; /* continue after last BRK */
uxn_eval(u, vec); uxn_eval(u, vec);
} }

View file

@ -194,7 +194,7 @@ static void
console_deo(Device *d, Uint8 port) console_deo(Device *d, Uint8 port)
{ {
if(port == 0x1) if(port == 0x1)
d->vector = peek16(d->dat, 0x0); DEVPEEK16(d->vector, 0x0);
if(port > 0x7) if(port > 0x7)
write(port - 0x7, (char *)&d->dat[port], 1); write(port - 0x7, (char *)&d->dat[port], 1);
} }
@ -206,7 +206,7 @@ audio_dei(Device *d, Uint8 port)
if(!audio_id) return d->dat[port]; if(!audio_id) return d->dat[port];
switch(port) { switch(port) {
case 0x4: return audio_get_vu(c); case 0x4: return audio_get_vu(c);
case 0x2: poke16(d->dat, 0x2, c->i); /* fall through */ case 0x2: DEVPOKE16(0x2, c->i); /* fall through */
default: return d->dat[port]; default: return d->dat[port];
} }
} }
@ -262,7 +262,7 @@ nil_dei(Device *d, Uint8 port)
static void static void
nil_deo(Device *d, Uint8 port) nil_deo(Device *d, Uint8 port)
{ {
if(port == 0x1) d->vector = peek16(d->dat, 0x0); if(port == 0x1) DEVPEEK16(d->vector, 0x0);
} }
/* Boot */ /* Boot */