Each device now has its own vector

This commit is contained in:
neauoire 2021-04-05 11:39:08 -07:00
parent c7c237895a
commit 3d8ddc143a
8 changed files with 75 additions and 68 deletions

View File

@ -28,7 +28,7 @@ else
fi
echo "Assembling.."
./bin/assembler projects/software/nasu.usm bin/boot.rom
./bin/assembler projects/software/left.usm bin/boot.rom
echo "Running.."
if [ "${2}" = '--cli' ];

View File

@ -42,24 +42,21 @@
( devices )
|0100 ;Console { pad 8 char 1 byte 1 short 2 }
|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|0130 ;Controller { buttons 1 }
|0140 ;Keys { key 1 }
|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
|01F0 ;System { pad 8 r 2 g 2 b 2 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|0110 ;Console { pad 8 char 1 byte 1 short 2 }
|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 }
|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|0140 ;Controller { buttons 1 }
|0150 ;Keys { key 1 }
|0160 ;Mouse { x 2 y 2 state 1 chord 1 }
|0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
( program )
@RESET
|0200 @RESET
( theme ) #e0fa =System.r #30fa =System.g #30fa =System.b
( vectors ) ,FRAME =Screen.vector
( load file )
,filepath ,load-file JSR2

View File

@ -31,24 +31,23 @@
( devices )
|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|0130 ;Controller { buttons 1 }
|0140 ;Keys { key 1 }
|0150 ;Mouse { x 2 y 2 state 1 chord 1 change 1 }
|0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
|01F0 ;System { pad 8 r 2 g 2 b 2 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|0110 ;Console { pad 8 char 1 byte 1 short 2 }
|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 }
|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|0140 ;Controller { buttons 1 }
|0150 ;Keys { key 1 }
|0160 ;Mouse { x 2 y 2 state 1 chord 1 change 1 }
|0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
( program )
@RESET
|0200 @RESET
( theme ) #e0fc =System.r #30cc =System.g #30ac =System.b
,FRAME =Screen.vector
~Screen.width 2/ #008a SUB2 =bankview.x
~Screen.height 2/ #003f SUB2 =bankview.y
,bank =bankview.addr

View File

@ -11,18 +11,18 @@
;neralie { n0123 2 n4 1 n5 1 n6 1 n7 1 n8 1 n9 1 color 1 x 2 y 2 w 2 h 2 }
;mul { ahi 1 alo 1 bhi 1 blo 1 }
|0100 ;Console { pad 8 char 1 byte 1 short 2 }
|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|0190 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 pad 4 get 1 }
|01F0 ;System { pad 8 r 2 g 2 b 2 }
|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|0110 ;Console { pad 8 char 1 byte 1 short 2 }
|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 }
|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|01a0 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 pad 4 get 1 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
( program )
|0200 @RESET
@RESET
( theme ) #03fd =System.r #0ef3 =System.g #0bf2 =System.b
( vectors ) ,FRAME =Screen.vector
#01 =fps.current
#000c

View File

@ -51,25 +51,23 @@
( devices )
|0100 ;Console { pad 8 char 1 byte 1 short 2 string 2 }
|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|0130 ;Controller { p1 1 }
|0140 ;Keys { key 1 }
|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
|01F0 ;System { pad 8 r 2 g 2 b 2 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|0110 ;Console { pad 8 char 1 byte 1 short 2 }
|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 }
|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|0140 ;Controller { p1 1 }
|0150 ;Keys { key 1 }
|0160 ;Mouse { x 2 y 2 state 1 chord 1 }
|0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
( program )
@RESET ( -- )
|0200 @RESET
( theme )
#e0fa =theme.r0 #30fa =theme.g0 #30fa =theme.b0 ( normal mode )
#00fe =theme.r1 #00f3 =theme.g1 #00f3 =theme.b1 ( presentation mode )
( vectors ) ,FRAME =Screen.vector
~theme.r0 =System.r ~theme.g0 =System.g ~theme.b0 =System.b

View File

@ -80,7 +80,7 @@ static SDL_Renderer *gRenderer;
static SDL_Texture *gTexture;
static SDL_AudioDeviceID audio_id;
static Screen screen;
static Device *devscreen, *devmouse, *devkey, *devctrl, *devaudio;
static Device *devsystem, *devscreen, *devmouse, *devkey, *devctrl, *devaudio;
#pragma mark - Helpers
@ -582,7 +582,7 @@ ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
int
start(Uxn *u)
{
evaluxn(u, PAGE_VECTORS);
inituxn(u, 0x0200);
redraw(pixels, u);
while(1) {
SDL_Event event;
@ -602,12 +602,13 @@ start(Uxn *u)
break;
}
}
evaluxn(u, PAGE_VECTORS + 0x08);
evaluxn(u, devscreen->vector);
if(screen.reqdraw)
redraw(pixels, u);
elapsed = (SDL_GetPerformanceCounter() - start) / (double)SDL_GetPerformanceFrequency() * 1000.0f;
SDL_Delay(clamp(16.666f - elapsed, 0, 1000));
}
return 1;
}
int
@ -624,28 +625,28 @@ main(int argc, char **argv)
if(!init())
return error("Init", "Failed");
portuxn(&u, 0x00, "console", console_poke);
devscreen = portuxn(&u, 0x01, "screen", screen_poke);
portuxn(&u, 0x02, "sprite", sprite_poke);
devctrl = portuxn(&u, 0x03, "controller", ppnil);
devkey = portuxn(&u, 0x04, "key", ppnil);
devmouse = portuxn(&u, 0x05, "mouse", ppnil);
portuxn(&u, 0x06, "file", file_poke);
devaudio = portuxn(&u, 0x07, "audio", audio_poke);
portuxn(&u, 0x08, "midi", ppnil);
portuxn(&u, 0x09, "datetime", datetime_poke);
portuxn(&u, 0x0a, "---", ppnil);
devsystem = portuxn(&u, 0x00, "system", system_poke);
portuxn(&u, 0x01, "console", console_poke);
devscreen = portuxn(&u, 0x02, "screen", screen_poke);
portuxn(&u, 0x03, "sprite", sprite_poke);
devctrl = portuxn(&u, 0x04, "controller", ppnil);
devkey = portuxn(&u, 0x05, "key", ppnil);
devmouse = portuxn(&u, 0x06, "mouse", ppnil);
portuxn(&u, 0x07, "file", file_poke);
devaudio = portuxn(&u, 0x08, "audio", audio_poke);
portuxn(&u, 0x09, "midi", ppnil);
portuxn(&u, 0x0a, "datetime", datetime_poke);
portuxn(&u, 0x0b, "---", ppnil);
portuxn(&u, 0x0c, "---", ppnil);
portuxn(&u, 0x0d, "---", ppnil);
portuxn(&u, 0x0e, "---", ppnil);
portuxn(&u, 0x0f, "system", system_poke);
portuxn(&u, 0x0f, "---", ppnil);
/* Write screen size to dev/screen */
u.ram.dat[devscreen->addr + 0] = (HOR * 8 >> 8) & 0xff;
u.ram.dat[devscreen->addr + 1] = HOR * 8 & 0xff;
u.ram.dat[devscreen->addr + 2] = (VER * 8 >> 8) & 0xff;
u.ram.dat[devscreen->addr + 3] = VER * 8 & 0xff;
u.ram.dat[devscreen->addr + 2] = (HOR * 8 >> 8) & 0xff;
u.ram.dat[devscreen->addr + 3] = HOR * 8 & 0xff;
u.ram.dat[devscreen->addr + 4] = (VER * 8 >> 8) & 0xff;
u.ram.dat[devscreen->addr + 5] = VER * 8 & 0xff;
start(&u);
quit();

View File

@ -151,6 +151,17 @@ evaluxn(Uxn *u, Uint16 vec)
return 1;
}
int
inituxn(Uxn *u, Uint16 vec)
{
Uint8 i = 0;
if(!evaluxn(u, vec))
return 0;
for(i = 0; i < 0x10; ++i)
u->dev[i].vector = mempeek16(u, u->dev[i].addr);
return 1;
}
int
bootuxn(Uxn *u)
{
@ -178,6 +189,6 @@ portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0
Device *d = &u->dev[id];
d->addr = PAGE_DEVICE + id * 0x10;
d->poke = pofn;
printf("Device #%d: %s, at 0x%04x \n", id, name, d->addr);
printf("Device added #%d: %s, at 0x%04x \n", id, name, d->addr);
return d;
}

View File

@ -32,7 +32,7 @@ typedef struct {
struct Uxn;
typedef struct Device {
Uint16 addr;
Uint16 addr, vector;
Uint8 (*poke)(struct Uxn *, Uint16, Uint8, Uint8);
} Device;
@ -44,5 +44,6 @@ typedef struct Uxn {
int loaduxn(Uxn *c, char *filepath);
int bootuxn(Uxn *c);
int inituxn(Uxn *u, Uint16 vec);
int evaluxn(Uxn *u, Uint16 vec);
Device *portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8));