From ad19620b823ae74ae841cebbdf25d986a415c45a Mon Sep 17 00:00:00 2001 From: neauoire Date: Sat, 10 Apr 2021 19:39:32 -0700 Subject: [PATCH] Merged ctrl with text --- build.sh | 2 +- projects/examples/blank.usm | 3 +- projects/examples/dev.audio.usm | 9 ++- ...troller.usm => dev.controller.buttons.usm} | 6 +- .../{dev.keys.usm => dev.controller.keys.usm} | 33 +++++----- projects/examples/gui.hover.usm | 4 -- projects/examples/gui.label.usm | 24 ++++---- projects/examples/gui.picture.usm | 3 - projects/examples/gui.shapes.usm | 4 -- projects/software/nasu.usm | 38 ++++-------- projects/software/noodle.usm | 61 ++++++++----------- projects/software/orca.usm | 22 +++---- src/emulator.c | 43 +++++-------- 13 files changed, 97 insertions(+), 155 deletions(-) rename projects/examples/{dev.controller.usm => dev.controller.buttons.usm} (93%) rename projects/examples/{dev.keys.usm => dev.controller.keys.usm} (90%) diff --git a/build.sh b/build.sh index 572c5a5..ff748ac 100755 --- a/build.sh +++ b/build.sh @@ -32,7 +32,7 @@ else fi echo "Assembling.." -./bin/assembler projects/examples/dev.screen.usm bin/boot.rom +./bin/assembler projects/examples/dev.controller.buttons.usm bin/boot.rom echo "Running.." if [ "${2}" = '--cli' ]; diff --git a/projects/examples/blank.usm b/projects/examples/blank.usm index b9d4b70..8551351 100644 --- a/projects/examples/blank.usm +++ b/projects/examples/blank.usm @@ -8,8 +8,7 @@ |0110 ;Console { vector 2 pad 6 char 1 byte 1 short 2 string 2 } |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 } |0130 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 } -|0140 ;Controller { vector 2 player1 1 player2 1 player3 1 player4 1 } -|0150 ;Keyboard { vector 2 key 1 } +|0140 ;Controller { vector 2 button 1 key 1 } |0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } |0170 ;File { vector 2 pad 6 name 2 length 2 load 3 save 2 } |01a0 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dotw 1 doty 2 isdst 1 refresh 1 } diff --git a/projects/examples/dev.audio.usm b/projects/examples/dev.audio.usm index c10adb5..b31c103 100644 --- a/projects/examples/dev.audio.usm +++ b/projects/examples/dev.audio.usm @@ -30,8 +30,7 @@ |0110 ;Console { pad 8 char 1 byte 1 short 2 } |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 } |0130 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 } -|0140 ;Controller { vector 2 button 1 } -|0150 ;Keys { vector 2 key 1 } +|0140 ;Controller { vector 2 button 1 key 1 } |0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } |0170 ;File { pad 8 name 2 length 2 load 2 save 2 } @@ -42,7 +41,7 @@ ( theme ) #e0fa =System.r #30fa =System.g #30fa =System.b ( vectors ) ,on-screen =Screen.vector ( vectors ) ,on-mouse =Mouse.vector - ( vectors ) ,on-key =Keys.vector + ( vectors ) ,on-button =Controller.vector ~Screen.width #0002 DIV2 DUP2 #0080 SUB2 =trkframe.x1 #0080 ADD2 =trkframe.x2 @@ -96,9 +95,9 @@ BRK BRK -@on-key ( -> ) +@on-button ( -> ) - ~Keys.key + ~Controller.key DUP #61 NEQ ^$no-c JNZ ,notes PEK2 ,play JSR2 $no-c DUP #73 NEQ ^$no-d JNZ diff --git a/projects/examples/dev.controller.usm b/projects/examples/dev.controller.buttons.usm similarity index 93% rename from projects/examples/dev.controller.usm rename to projects/examples/dev.controller.buttons.usm index fca943c..e5bbcae 100644 --- a/projects/examples/dev.controller.usm +++ b/projects/examples/dev.controller.buttons.usm @@ -12,7 +12,7 @@ |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 } -|0140 ;Controller { vector 2 p1 1 } +|0140 ;Controller { vector 2 button 1 key 1 } |0200 @@ -35,7 +35,7 @@ BRK ( hold ctrl key to change slime color ) - ~Controller.p1 #0f AND + ~Controller.button #0f AND DUP #01 NEQ ^$no-ctrl JNZ #25 =slime $no-ctrl DUP #02 NEQ ^$no-alt JNZ #2f =slime $no-alt POP @@ -43,7 +43,7 @@ BRK ( clear ) #30 =Screen.color ( detect movement ) - ~Controller.p1 #f0 AND + ~Controller.button #f0 AND DUP #04 SFT #01 AND #01 NEQ ^$no-up JNZ ( move ) ~Screen.y -- =Screen.y ,up_icn =Screen.addr $no-up DUP #05 SFT #01 AND #01 NEQ ^$no-down JNZ diff --git a/projects/examples/dev.keys.usm b/projects/examples/dev.controller.keys.usm similarity index 90% rename from projects/examples/dev.keys.usm rename to projects/examples/dev.controller.keys.usm index c918e4c..df4940d 100644 --- a/projects/examples/dev.keys.usm +++ b/projects/examples/dev.controller.keys.usm @@ -5,43 +5,40 @@ %8* { #0030 SFT2 } |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } +|0110 ;Console { vector 2 pad 6 char 1 byte 1 short 2 } |0120 ;Screen { vector 2 pad 6 x 2 y 2 addr 2 color 1 } -|0140 ;Controller { vector 2 button 1 } -|0150 ;Keys { vector 2 key 1 } +|0140 ;Controller { vector 2 button 1 key 1 } ( program ) |0200 ( theme ) #0f73 =System.r #0fe3 =System.g #0fc3 =System.b - ( vectors ) ,KEY =Keys.vector - ( vectors ) ,BUTTON =Controller.vector + ( vectors ) ,on-button =Controller.vector ,draw-cursor JSR2 BRK -@KEY +@on-button - ,cursor_icn =Screen.addr - ,font #00 ~Keys.key 8* ADD2 =Screen.addr - ( draw ) #21 =Screen.color - ~Screen.x 8+ =Screen.x - ( release ) #00 =Keys.key - ,draw-cursor JSR2 + ~Controller.key #00 NEQ ^$skip JNZ BRK $skip -BRK - -@BUTTON - - ( enter key ) - ~Controller.button #08 NEQ ^$no-return JNZ + ~Controller.key #0d NEQ ^$no-return JNZ #20 =Screen.color #0000 =Screen.x ( incr ) ~Screen.y 8+ =Screen.y - ( release ) #00 =Controller.button ,draw-cursor JSR2 + BRK $no-return + ~Controller.key =Console.char + + ,cursor_icn =Screen.addr + ,font #00 ~Controller.key 8* ADD2 =Screen.addr + ( draw ) #21 =Screen.color + ~Screen.x 8+ =Screen.x + ,draw-cursor JSR2 + BRK @draw-cursor diff --git a/projects/examples/gui.hover.usm b/projects/examples/gui.hover.usm index 7ef1fbe..29111e1 100644 --- a/projects/examples/gui.hover.usm +++ b/projects/examples/gui.hover.usm @@ -1,7 +1,6 @@ ( GUI Hover ) %RTN { JMP2r } -%RTN? { #00 EQU #02 JNZ STH2r JMP2 } ;color { byte 1 } ;pointer { x 2 y 2 sprite 2 } @@ -11,10 +10,7 @@ ;r3 { x1 2 y1 2 x2 2 y2 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 addr 2 color 1 } -|0140 ;Controller { vector 2 button 1 } -|0150 ;Keys { vector 2 key 1 } |0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } ( program ) diff --git a/projects/examples/gui.label.usm b/projects/examples/gui.label.usm index cd6c765..4c4a255 100644 --- a/projects/examples/gui.label.usm +++ b/projects/examples/gui.label.usm @@ -6,18 +6,20 @@ ;center { x 2 y 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 addr 2 color 1 } -|0140 ;Controller { vector 2 button 1 } -|0150 ;Keys { vector 2 key 1 } -|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } ( program ) -|0200 @RESET +|0200 ( theme ) #0f0f =System.r #0fff =System.g #0ff0 =System.b + ,draw JSR2 + +BRK + +@draw ( -- ) + ( find screen center ) ~Screen.width #0002 DIV2 =center.x ~Screen.height #0002 DIV2 =center.y @@ -34,10 +36,10 @@ ~center.x ~center.y #0010 ADD2 #2c ,text3 ,draw-label-right JSR2 ~center.x ~center.y #0020 ADD2 #2c ,text4 ,draw-label-middle JSR2 ~center.x ~center.y #0030 ADD2 #2c ,text5 ,draw-label-middle JSR2 - -BRK -@draw-label-left ( x y color addr ) +RTN + +@draw-label-left ( x y color addr -- ) ( load ) =label.addr =label.color =Screen.y =Screen.x ~label.addr @@ -50,7 +52,7 @@ BRK RTN -@draw-label-middle ( x y color addr ) +@draw-label-middle ( x y color addr -- ) ( load ) =label.addr =label.color =Screen.y ( align ) ~label.addr ,get-text-length JSR2 #0008 MUL2 #0002 DIV2 SUB2 =Screen.x @@ -64,7 +66,7 @@ RTN RTN -@draw-label-right ( x y color addr ) +@draw-label-right ( x y color addr -- ) ( load ) =label.addr =label.color =Screen.y ( align ) ~label.addr ,get-text-length JSR2 #0008 MUL2 SUB2 #0008 SUB2 =Screen.x @@ -78,7 +80,7 @@ RTN RTN -@get-text-length ( label ) +@get-text-length ( label* -- length ) #0000 ( counter ) $loop diff --git a/projects/examples/gui.picture.usm b/projects/examples/gui.picture.usm index 84dcaa6..dad158c 100644 --- a/projects/examples/gui.picture.usm +++ b/projects/examples/gui.picture.usm @@ -6,10 +6,7 @@ ;pict { x 2 y 2 width 2 height 2 color 1 addr 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 addr 2 color 1 } -|0140 ;Controller { vector 2 button 1 } -|0150 ;Keys { vector 2 key 1 } |0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } |0170 ;File { pad 8 name 2 length 2 load 2 save 2 } diff --git a/projects/examples/gui.shapes.usm b/projects/examples/gui.shapes.usm index 7364063..f71afce 100644 --- a/projects/examples/gui.shapes.usm +++ b/projects/examples/gui.shapes.usm @@ -13,11 +13,7 @@ ;circle { xc 2 yc 2 x 2 y 2 r 2 d 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 addr 2 color 1 } -|0140 ;Controller { vector 2 button 1 } -|0150 ;Keys { vector 2 key 1 } -|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } ( program ) diff --git a/projects/software/nasu.usm b/projects/software/nasu.usm index ee47014..c5a0318 100644 --- a/projects/software/nasu.usm +++ b/projects/software/nasu.usm @@ -34,18 +34,16 @@ |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 addr 2 color 1 } -|0140 ;Controller { vector 2 button 1 } -|0150 ;Keys { vector 2 key 1 } +|0140 ;Controller { vector 2 button 1 key 1 } |0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } |0170 ;File { pad 8 name 2 length 2 load 2 save 2 } ( program ) -|0200 @RESET +|0200 ( theme ) #e0fc =System.r #30cc =System.g #30ac =System.b ( vectors ) ,on-button =Controller.vector - ( vectors ) ,on-key =Keys.vector ( vectors ) ,on-mouse =Mouse.vector ~Screen.width 2/ #008a SUB2 =bankview.x @@ -56,23 +54,13 @@ ~Screen.height 2/ #003f SUB2 =tileview.y ,bank #0448 ADD2 =tileview.addr - ,filepath ,load-file JSR2 + ,filepath1 =File.name #0800 =File.length ,bank =File.load + ,filepath2 =File.name #0800 =File.length ,bank #0800 ADD2 =File.load ,redraw JSR2 BRK -@on-key - - ~Keys.key #31 LTH ^$skip JNZ - ~Keys.key #33 GTH ^$skip JNZ - ( select ) ~Keys.key #31 SUB =bankview.mode - ( release ) #00 =Keys.key - ,redraw JSR2 - $skip - -BRK - @on-button ~Controller.button @@ -86,6 +74,11 @@ BRK ~tileview.addr 8- =tileview.addr $no-ctrl-right POP ~tileview.addr #0800 DIV2 #0800 MUL2 =bankview.addr + + ~Controller.key #31 LTH ^$skip JNZ + ~Controller.key #33 GTH ^$skip JNZ + ( select ) ~Controller.key #31 SUB =bankview.mode + $skip ,redraw JSR2 BRK @@ -105,12 +98,12 @@ BRK ,redraw JSR2 ,$click-end JMP2 $no-brush-click ~Mouse.x ~tileview.x SUB2 8/ #000e NEQ2 ^$no-load-click JNZ - ( load ) ,filepath =File.name #0800 =File.length ~bankview.addr =File.load + ( load ) ,filepath1 =File.name #0800 =File.length ~bankview.addr =File.load ( release ) #00 =Mouse.state ,redraw JSR2 ,$click-end JMP2 $no-load-click ~Mouse.x ~tileview.x SUB2 8/ #000f NEQ2 ^$no-save-click JNZ - ( save ) ,filepath =File.name #0800 =File.length ~bankview.addr =File.save + ( save ) ,filepath1 =File.name #0800 =File.length ~bankview.addr =File.save ( release ) #00 =Mouse.state ,redraw JSR2 ,$click-end JMP2 $no-save-click @@ -206,12 +199,6 @@ BRK BRK -@load-file ( path ) - - =File.name #0800 =File.length ,bank =File.load - -RTN - @op_shiftup ~tileview.addr PEK2 @@ -505,7 +492,8 @@ RTN @save_icn [ fe82 8282 848a f400 ] @moveup_icn [ 0010 387c fe10 1000 ] @movedown_icn [ 0010 1010 fe7c 3810 ] -@filepath [ projects/fonts/specter8.bit 00 ] +@filepath1 [ projects/fonts/specter8.bit 00 ] +@filepath2 [ projects/pictures/cibo.bit 00 ] @font_hex ( 0-F ) [ diff --git a/projects/software/noodle.usm b/projects/software/noodle.usm index bb5d303..56bcc76 100644 --- a/projects/software/noodle.usm +++ b/projects/software/noodle.usm @@ -52,10 +52,9 @@ ( devices ) |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } -|0110 ;Console { pad 8 char 1 byte 1 short 2 } +|0110 ;Console { pad 8 char 1 byte 1 short 2 string 2 } |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 } -|0140 ;Controller { vector 2 button 1 } -|0150 ;Keys { vector 2 key 1 } +|0140 ;Controller { vector 2 button 1 key 1 } |0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } |0170 ;File { pad 8 name 2 length 2 load 2 save 2 } @@ -67,7 +66,6 @@ #e0fa =theme.r0 #30fa =theme.g0 #30fa =theme.b0 ( normal mode ) #00fe =theme.r1 #00f3 =theme.g1 #00f3 =theme.b1 ( presentation mode ) ( vectors ) ,on-screen =Screen.vector - ( vectors ) ,on-key =Keys.vector ( vectors ) ,on-button =Controller.vector ( vectors ) ,on-mouse =Mouse.vector @@ -283,55 +281,49 @@ BRK BRK -@on-button - +@on-button ( -> ) + ( if in renaming mode ) ~document.edit #01 NEQ ,$no-edit JNZ2 + ~Controller.key #00 EQU ,$no-edit JNZ2 ( enter ) - ~Controller.button #08 NEQ ^$no-edit-enter JNZ + ~Controller.key #0d NEQ ^$no-edit-enter JNZ #00 =document.edit ,redraw JSR2 BRK $no-edit-enter ( backspace ) - ~Controller.button #04 NEQ ^$no-edit-backspace JNZ + ~Controller.key #08 NEQ ^$no-edit-backspace JNZ ~path.length #00 EQU ^$edit-end JNZ ~path.length #01 SUB =path.length #00 ,path.name #00 ~path.length ADD2 POK2 BRK $no-edit-backspace - $edit-end - BRK - $no-edit - - ~Controller.button #f0 AND - DUP #04 SFT #01 AND #01 NEQ ^$no-up JNZ - ( move ) ~zoom.y -- =zoom.y $no-up - DUP #05 SFT #01 AND #01 NEQ ^$no-down JNZ - ( move ) ~zoom.y ++ =zoom.y $no-down - DUP #06 SFT #01 AND #01 NEQ ^$no-left JNZ - ( move ) ~zoom.x -- =zoom.x $no-left - DUP #07 SFT #01 AND #01 NEQ ^$no-right JNZ - ( move ) ~zoom.x ++ =zoom.x $no-right - #00 EQU #04 JNZ ,draw-canvas JSR2 - -BRK - -@on-key - - ( if in renaming mode ) - ~document.edit #01 NEQ ,$no-edit JNZ2 ( default ) ~path.length #1f EQU ^$edit-end JNZ - ~Keys.key ,path.name #00 ~path.length ADD2 POK2 + ~Controller.key ,path.name #00 ~path.length ADD2 POK2 ~path.length #01 ADD =path.length - $edit-end + ~Controller.key =Console.byte + $edit-end #00 ,path.name #00 ~path.length ADD2 POK2 - ( release ) #00 =Keys.key BRK $no-edit + + ( control zoom ) + ~zoom.active #00 EQU ^$skip-zoom JNZ + ~Controller.button #f0 AND + DUP #04 SFT #01 AND #01 NEQ ^$no-up JNZ + ( move ) ~zoom.y -- =zoom.y $no-up + DUP #05 SFT #01 AND #01 NEQ ^$no-down JNZ + ( move ) ~zoom.y ++ =zoom.y $no-down + DUP #06 SFT #01 AND #01 NEQ ^$no-left JNZ + ( move ) ~zoom.x -- =zoom.x $no-left + DUP #07 SFT #01 AND #01 NEQ ^$no-right JNZ + ( move ) ~zoom.x ++ =zoom.x $no-right + #00 EQU #04 JNZ ,draw-canvas JSR2 + $skip-zoom - ~Keys.key + ~Controller.key DUP #20 NEQ ^$no-space JNZ ( toggle zoom ) ~zoom.active #00 EQU =zoom.active ,redraw JSR2 $no-space DUP #08 NEQ ^$no-backspace JNZ @@ -348,9 +340,8 @@ BRK ( tool0 ) #04 =brush.tool ,draw-toolpane JSR2 $no-tkey DUP DUP #30 GTH SWP #39 LTH #0101 NEQ2 ^$no-numkey JNZ - ( size ) ~Keys.key #31 SUB =brush.size ,draw-sizepane JSR2 $no-numkey + ( size ) ~Controller.key #31 SUB =brush.size ,draw-sizepane JSR2 $no-numkey POP - ( release ) #00 =Keys.key BRK diff --git a/projects/software/orca.usm b/projects/software/orca.usm index 9f6a4c9..688ed69 100644 --- a/projects/software/orca.usm +++ b/projects/software/orca.usm @@ -45,15 +45,13 @@ |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 addr 2 color 1 } -|0140 ;Controller { vector 2 button 1 } -|0150 ;Keys { vector 2 key 1 } +|0140 ;Controller { vector 2 button 1 key 1 } |0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } |0200 ( theme ) #08f3 =System.r #08fc =System.g #08f9 =System.b ( vectors ) ,on-button =Controller.vector - ( vectors ) ,on-key =Keys.vector ( vectors ) ,on-mouse =Mouse.vector ( vectors ) ,on-frame =Screen.vector @@ -82,20 +80,14 @@ BRK BRK -@on-key - - ( skip ) ~Keys.key #00 NEQ ^$continue JNZ BRK $continue - - ~selection.x1 ~selection.y1 ~Keys.key SET-CELL - - ( release ) #00 =Keys.key - - ,redraw JSR2 - -BRK - @on-button + ~Controller.key #00 EQU ^$no-key JNZ + ~selection.x1 ~selection.y1 ~Controller.key SET-CELL + ~Controller.key =Console.byte + ,redraw JSR2 + $no-key + ( arrows ) ~Controller.button #f0 AND DUP #04 SFT #01 AND #01 NEQ ^$no-up JNZ diff --git a/src/emulator.c b/src/emulator.c index 85a00e7..934bdcc 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -23,7 +23,7 @@ static SDL_Renderer *gRenderer; static SDL_Texture *gTexture; static Ppu ppu; static Apu apu; -static Device *devsystem, *devscreen, *devmouse, *devkey, *devctrl, *devapu; +static Device *devsystem, *devscreen, *devmouse, *devctrl, *devapu; Uint8 zoom = 0, debug = 0, reqdraw = 0; @@ -151,26 +151,10 @@ domouse(Uxn *u, SDL_Event *event) } } -void -dotext(Uxn *u, SDL_Event *event) -{ - int i; - Uint16 addr = devkey->addr + 2; - if(SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL) - return; - for(i = 0; i < SDL_TEXTINPUTEVENT_TEXT_SIZE; ++i) { - char c = event->text.text[i]; - if(c < ' ' || c > '~') - break; - u->ram.dat[addr] = c; - } -} - void doctrl(Uxn *u, SDL_Event *event, int z) { Uint8 flag = 0x00; - Uint16 addr = devctrl->addr + 2; if(z && event->key.keysym.sym == SDLK_h) { if(SDL_GetModState() & KMOD_LCTRL) toggledebug(u); @@ -180,17 +164,19 @@ doctrl(Uxn *u, SDL_Event *event, int z) switch(event->key.keysym.sym) { case SDLK_LCTRL: flag = 0x01; break; case SDLK_LALT: flag = 0x02; break; - case SDLK_BACKSPACE: flag = 0x04; break; - case SDLK_RETURN: flag = 0x08; break; + case SDLK_ESCAPE: flag = 0x04; break; + case SDLK_LSHIFT: flag = 0x08; break; case SDLK_UP: flag = 0x10; break; case SDLK_DOWN: flag = 0x20; break; case SDLK_LEFT: flag = 0x40; break; case SDLK_RIGHT: flag = 0x80; break; } - if(z) - u->ram.dat[addr] |= flag; - else - u->ram.dat[addr] &= (~flag); + if(flag && z) + u->ram.dat[devctrl->addr + 2] |= flag; + else if(flag) + u->ram.dat[devctrl->addr + 2] &= (~flag); + if(z && event->key.keysym.sym < 20) + u->ram.dat[devctrl->addr + 3] = event->key.keysym.sym; } #pragma mark - Devices @@ -338,21 +324,20 @@ start(Uxn *u) case SDL_QUIT: quit(); break; + case SDL_TEXTINPUT: + if(event.text.text[0] >= ' ' || event.text.text[0] <= '~') + u->ram.dat[devctrl->addr + 3] = event.text.text[0]; case SDL_KEYDOWN: case SDL_KEYUP: doctrl(u, &event, event.type == SDL_KEYDOWN); evaluxn(u, devctrl->vector); - break; + u->ram.dat[devctrl->addr + 3] = 0; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEMOTION: domouse(u, &event); evaluxn(u, devmouse->vector); break; - case SDL_TEXTINPUT: - dotext(u, &event); - evaluxn(u, devkey->vector); - break; case SDL_WINDOWEVENT: if(event.window.event == SDL_WINDOWEVENT_EXPOSED) redraw(ppu.output, u); @@ -389,7 +374,7 @@ main(int argc, char **argv) devscreen = portuxn(&u, 0x02, "screen", screen_poke); devapu = portuxn(&u, 0x03, "audio", audio_poke); devctrl = portuxn(&u, 0x04, "controller", ppnil); - devkey = portuxn(&u, 0x05, "key", ppnil); + portuxn(&u, 0x05, "---", ppnil); devmouse = portuxn(&u, 0x06, "mouse", ppnil); portuxn(&u, 0x07, "file", file_poke); portuxn(&u, 0x08, "---", ppnil);