uxn

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

commit 527d6508e28ae3d6b259257aa4110cfd537f8b09
parent b014a73bcdd93f0dfbd457c191b528f155a36fb0
Author: neauoire <aliceffekt@gmail.com>
Date:   Fri, 26 Feb 2021 16:53:09 -0800

Implemented devctrl

Diffstat:
Memulator.c | 9+++++----
Mexamples/blank.usm | 10++++++----
Aexamples/dev.ctrl.usm | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mexamples/dev.mouse.usm | 6+++---
Dexamples/devctrl.usm | 64----------------------------------------------------------------
Dexamples/devices.usm | 20--------------------
6 files changed, 81 insertions(+), 95 deletions(-)

diff --git a/emulator.c b/emulator.c @@ -297,9 +297,10 @@ dotext(SDL_Event *event) } void -doctrl(SDL_Event *event, int z) +doctrl(Uxn *u, SDL_Event *event, int z) { Uint8 flag = 0x00; + Uint16 addr = 0xff30; /* TODO: get dynamically */ if(z && event->key.keysym.sym == SDLK_h) GUIDES = !GUIDES; if(SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL) @@ -320,7 +321,7 @@ doctrl(SDL_Event *event, int z) case SDLK_LEFT: flag = 0x40; break; case SDLK_RIGHT: flag = 0x80; break; } - setflag(&devcontroller->mem[0], flag, z); + setflag(&u->ram.dat[addr], flag, z); } #pragma mark - Devices @@ -439,8 +440,8 @@ start(Uxn *u) case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEMOTION: domouse(u, &event); break; case SDL_TEXTINPUT: dotext(&event); break; - case SDL_KEYDOWN: doctrl(&event, 1); break; - case SDL_KEYUP: doctrl(&event, 0); break; + case SDL_KEYDOWN: doctrl(u, &event, 1); break; + case SDL_KEYUP: doctrl(u, &event, 0); break; case SDL_WINDOWEVENT: if(event.window.event == SDL_WINDOWEVENT_EXPOSED) redraw(pixels, u); diff --git a/examples/blank.usm b/examples/blank.usm @@ -1,9 +1,10 @@ ( blank ) -&Console { pad 8 stdio 1 } -&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 } -&Sprite { pad 8 y 2 x 2 addr 2 color 1 } -&Mouse { x 2 y 2 state 1 chord 1 } +&Console { pad 8 stdio 1 } +&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 } +&Sprite { pad 8 y 2 x 2 addr 2 color 1 } +&Controller { buttons 1 } +&Mouse { x 2 y 2 state 1 chord 1 } |0100 @RESET BRK |c000 @FRAME BRK @@ -12,6 +13,7 @@ |FF00 ;dev/console Console |FF10 ;dev/screen Screen |FF20 ;dev/sprite Sprite +|FF30 ;dev/ctrl Controller |FF50 ;dev/mouse Mouse |FFF0 [ f2ac 35bb 2b53 ] ( palette ) diff --git a/examples/dev.ctrl.usm b/examples/dev.ctrl.usm @@ -0,0 +1,67 @@ +( controller ) + +&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 } +&Sprite { pad 8 x 2 y 2 addr 2 color 1 } +&Controller { buttons 1 } + +&Point2d { x 2 y 2 } + +;pos Point2d +;sprite 2 + +|0100 @RESET + + ( set origin ) + ~dev/screen.width #0002 DIV2 =pos.x + ~dev/screen.height #0002 DIV2 =pos.y + + #12 ,up_icn ~pos.y ~pos.x ,draw-sprite JSR + +BRK + +|c000 @FRAME + + ,default_icn =sprite + + ~dev/ctrl.buttons #10 NEQ ,next1 ROT JMP? POP2 + ,up_icn =sprite + ~pos.y #0001 SUB2 =pos.y + @next1 + ~dev/ctrl.buttons #20 NEQ ,next2 ROT JMP? POP2 + ,down_icn =sprite + ~pos.y #0001 ADD2 =pos.y + @next2 + ~dev/ctrl.buttons #40 NEQ ,next3 ROT JMP? POP2 + ,left_icn =sprite + ~pos.x #0001 SUB2 =pos.x + @next3 + ~dev/ctrl.buttons #80 NEQ ,end ROT JMP? POP2 + ,right_icn =sprite + ~pos.x #0001 ADD2 =pos.x + @end + ( redraw ) + #13 ~sprite ~pos.y ~pos.x ,draw-sprite JSR + +BRK + +@default_icn [ 3c7e ffdb ffe7 7e3c ] +@up_icn [ 2466 e7db ffff 7e3c ] +@down_icn [ 3c7e ffff dbe7 6624 ] +@left_icn [ 3c7e ef1f 1fef 7e3c ] +@right_icn [ 3c7e f7f8 f8f7 7e3c ] + +@draw-sprite + =dev/sprite.x + =dev/sprite.y + =dev/sprite.addr + =dev/sprite.color + RTS + +|d000 @ERROR BRK + +|FF10 ;dev/screen Screen +|FF20 ;dev/sprite Sprite +|FF30 ;dev/ctrl Controller + +|FFF0 [ 02ac 05bb 0b53 ] ( palette ) +|FFFA .RESET .FRAME .ERROR diff --git a/examples/dev.mouse.usm b/examples/dev.mouse.usm @@ -1,7 +1,7 @@ ( mouse ) &Screen { width 2 height 2 pad 4 y 2 x 2 color 1 } -&Sprite { pad 8 y 2 x 2 addr 2 color 1 } +&Sprite { pad 8 x 2 y 2 addr 2 color 1 } &Mouse { x 2 y 2 state 1 chord 1 } &Point2d { x 2 y 2 } @@ -91,15 +91,15 @@ RTS RTS @draw-sprite - =dev/sprite.x =dev/sprite.y + =dev/sprite.x =dev/sprite.addr =dev/sprite.color RTS @draw-sprite-chr - =dev/sprite.x =dev/sprite.y + =dev/sprite.x =dev/sprite.addr #20 =dev/sprite.color RTS diff --git a/examples/devctrl.usm b/examples/devctrl.usm @@ -1,64 +0,0 @@ -( controller ) - -:dev/r fff8 ( const read port ) -:dev/w fff9 ( const write port ) - -&Point2d { x 2 y 2 } - -;pos Point2d -;sprite 2 - -|0100 @RESET - - #03 =dev/r ( set dev/read to controller ) - #02 =dev/w ( set dev/write to sprite ) - #0080 =pos.x #0040 =pos.y ( origin ) - - #12 ,up_icn ~pos.x ~pos.y ,draw-sprite JSR - -BRK - -|c000 @FRAME - - #03 =dev/r ( set dev/read to controller ) - - ,default_icn =sprite - - #00 IOR #10 NEQ ,next1 ROT JMP? POP2 - ,up_icn =sprite - ~pos.y #0001 SUB2 =pos.y - @next1 - #00 IOR #20 NEQ ,next2 ROT JMP? POP2 - ,down_icn =sprite - ~pos.y #0001 ADD2 =pos.y - @next2 - #00 IOR #40 NEQ ,next3 ROT JMP? POP2 - ,left_icn =sprite - ~pos.x #0001 SUB2 =pos.x - @next3 - #00 IOR #80 NEQ ,end ROT JMP? POP2 - ,right_icn =sprite - ~pos.x #0001 ADD2 =pos.x - @end - ( redraw ) - #13 ~sprite ~pos.x ~pos.y ,draw-sprite JSR - -BRK - -@default_icn [ 3c7e ffdb ffe7 7e3c ] -@up_icn [ 2466 e7db ffff 7e3c ] -@down_icn [ 3c7e ffff dbe7 6624 ] -@left_icn [ 3c7e ef1f 1fef 7e3c ] -@right_icn [ 3c7e f7f8 f8f7 7e3c ] - -@draw-sprite - IOW2 ( y byte ) - IOW2 ( x byte ) - IOW2 ( sprite address ) - IOW ( layer-color ) - RTS - -|d000 @ERROR BRK - -|FFF0 [ 02ac 05bb 0b53 ] ( palette ) -|FFFA .RESET .FRAME .ERROR diff --git a/examples/devices.usm b/examples/devices.usm @@ -1,20 +0,0 @@ -( blank ) - -:dev/r fff8 ( std read port ) -:dev/w fff9 ( std write port ) - -&Console { stdout 1 } - -|0100 @RESET - - -BRK - -|c000 @FRAME BRK -|d000 @ERROR BRK - -|FF00 ;dev/console Console -|FF08 ;device2 Device - -|FFF0 [ f2ac 35bb 2b53 ] ( palette ) -|FFFA .RESET .FRAME .ERROR