uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 92e455141fa360b7db13339529ba9ca0b939fcc0
parent 256d72e340e01ecc2a329c81f081620dab08de11
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun, 14 Feb 2021 19:43:33 -0800

Reordered devices

Diffstat:
Memulator.c | 86++++++++++++++-----------------------------------------------------------------
Mexamples/controller.usm | 4++--
Mexamples/draw.usm | 2+-
Mexamples/hello.usm | 1+
Mexamples/line.usm | 2+-
Mexamples/mouse.usm | 2+-
Mexamples/sprite.usm | 2+-
7 files changed, 22 insertions(+), 77 deletions(-)

diff --git a/emulator.c b/emulator.c @@ -37,7 +37,7 @@ SDL_Renderer *gRenderer; SDL_Texture *gTexture; Uint32 *pixels; -Device *devconsole, *devscreen, *devmouse, *devkey, *devsprite, *devctrl; +Device *devconsole, *devscreen, *devmouse, *devkey, *devsprite, *devcontroller; #pragma mark - Helpers @@ -188,12 +188,6 @@ domouse(SDL_Event *event) } void -dokey(SDL_Event *event) -{ - (void)event; -} - -void doctrl(SDL_Event *event, int z) { Uint8 flag = 0x00; @@ -209,18 +203,16 @@ doctrl(SDL_Event *event, int z) case SDLK_LEFT: flag = 0x40; break; case SDLK_RIGHT: flag = 0x80; break; } - setflag(&devctrl->mem[0], flag, z); + setflag(&devcontroller->mem[0], flag, z); } #pragma mark - Devices Uint8 -consoler(Device *d, Memory *m, Uint8 b) +defaultrw(Device *d, Memory *m, Uint8 b) { - (void)b; - (void)d; (void)m; - return 0; + return d->mem[b]; } Uint8 @@ -235,7 +227,7 @@ consolew(Device *d, Memory *m, Uint8 b) } Uint8 -ppur(Device *d, Memory *m, Uint8 b) +screenr(Device *d, Memory *m, Uint8 b) { switch(b) { case 0: return (WIDTH >> 8) & 0xff; @@ -243,11 +235,12 @@ ppur(Device *d, Memory *m, Uint8 b) case 2: return (HEIGHT >> 8) & 0xff; case 3: return HEIGHT & 0xff; } + (void)m; return d->mem[b]; } Uint8 -ppuw(Device *d, Memory *m, Uint8 b) +screenw(Device *d, Memory *m, Uint8 b) { d->mem[d->len++] = b; if(d->len > 5) { @@ -259,17 +252,12 @@ ppuw(Device *d, Memory *m, Uint8 b) redraw(pixels); d->len = 0; } + (void)m; return 0; } Uint8 -ppusr(Device *d, Memory *m, Uint8 b) -{ - return 0; -} - -Uint8 -ppusw(Device *d, Memory *m, Uint8 b) +spritew(Device *d, Memory *m, Uint8 b) { d->mem[d->len++] = b; if(d->len > 6) { @@ -284,50 +272,6 @@ ppusw(Device *d, Memory *m, Uint8 b) return 0; } -Uint8 -mouser(Device *d, Memory *m, Uint8 b) -{ - return d->mem[b]; -} - -Uint8 -mousew(Device *d, Memory *m, Uint8 b) -{ - (void)d; - (void)b; - return 0; -} - -Uint8 -keyr(Device *d, Memory *m, Uint8 b) -{ - (void)d; - (void)b; - return 0; -} - -Uint8 -keyw(Device *d, Memory *m, Uint8 b) -{ - (void)d; - (void)b; - return 0; -} - -Uint8 -ctrlr(Device *d, Memory *m, Uint8 b) -{ - return d->mem[b]; -} - -Uint8 -ctrlw(Device *d, Memory *m, Uint8 b) -{ - (void)d; - (void)b; - return 0; -} - #pragma mark - Generics int @@ -378,12 +322,12 @@ main(int argc, char **argv) if(!init()) return error("Init", "Failed"); - devconsole = portuxn(&u, "console", consoler, consolew); - devscreen = portuxn(&u, "ppu", ppur, ppuw); - devmouse = portuxn(&u, "mouse", mouser, mousew); - devkey = portuxn(&u, "key", keyr, keyw); - devsprite = portuxn(&u, "ppu-sprite", ppusr, ppusw); - devctrl = portuxn(&u, "ctrl", ctrlr, ctrlw); + devconsole = portuxn(&u, "console", defaultrw, consolew); + devscreen = portuxn(&u, "screen", screenr, screenw); + devsprite = portuxn(&u, "sprite", defaultrw, spritew); + devcontroller = portuxn(&u, "controller", defaultrw, defaultrw); + devkey = portuxn(&u, "key", defaultrw, consolew); + devmouse = portuxn(&u, "mouse", defaultrw, defaultrw); start(&u); diff --git a/examples/controller.usm b/examples/controller.usm @@ -7,8 +7,8 @@ |0100 @RESET - #05 =dev/r ( set dev/read to ctrl ) - #04 =dev/w ( set dev/write to ppu-sprite ) + #03 =dev/r ( set dev/read to controller ) + #02 =dev/w ( set dev/write to sprite ) #0080 =x #0040 =y ( origin ) #01 ,cursor_icn ~x ~y ,putsprite JSR ( draw sprite ) diff --git a/examples/draw.usm b/examples/draw.usm @@ -9,7 +9,7 @@ |0100 @RESET ( set dev/write to screen ) - #01 ,dev/w STR + #01 =dev/w ( set dev/write to sprite ) #01 ,color STR ( fill rect x y w h ) diff --git a/examples/hello.usm b/examples/hello.usm @@ -4,6 +4,7 @@ |0100 @RESET + #00 =dev/w ( set dev/write to sprite ) ,string ( add string pointer to stack ) @loop DUP2 LDR IOW ( write pointer value to console ) diff --git a/examples/line.usm b/examples/line.usm @@ -9,7 +9,7 @@ |0100 @RESET ( set dev/write to screen ) - #01 ,dev/w STR + #01 =dev/w ( set dev/write to sprite ) ( positive ) #01 ,color STR diff --git a/examples/mouse.usm b/examples/mouse.usm @@ -5,7 +5,7 @@ |0100 @RESET - #02 =dev/r ( set dev/read mouse#02 ) + #05 =dev/r ( set dev/read mouse#02 ) #01 =dev/w ( set dev/write screen#01 ) BRK diff --git a/examples/sprite.usm b/examples/sprite.usm @@ -5,7 +5,7 @@ |0100 @RESET #01 =dev/w ( set dev/write to screen ) - #04 =dev/w ( set dev/write to ppu-sprite ) + #02 =dev/w ( set dev/write to sprite ) #00 ,star_icn #0041 #0041 ,putsprite JSR #00 ,star_icn #0031 #0021 ,putsprite JSR