mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-10 16:25:05 +00:00
Merged ctrl with text
This commit is contained in:
parent
98c32fd95c
commit
ad19620b82
13 changed files with 97 additions and 155 deletions
2
build.sh
2
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' ];
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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 )
|
||||
|
|
|
@ -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
|
||||
|
@ -35,9 +37,9 @@
|
|||
~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
|
||||
RTN
|
||||
|
||||
@draw-label-left ( x y color addr )
|
||||
@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
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
||||
|
|
|
@ -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 )
|
||||
[
|
||||
|
|
|
@ -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,27 +281,36 @@ 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
|
||||
( default )
|
||||
~path.length #1f EQU ^$edit-end JNZ
|
||||
~Controller.key ,path.name #00 ~path.length ADD2 POK2
|
||||
~path.length #01 ADD =path.length
|
||||
~Controller.key =Console.byte
|
||||
$edit-end
|
||||
#00 ,path.name #00 ~path.length ADD2 POK2
|
||||
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
|
||||
|
@ -314,24 +321,9 @@ BRK
|
|||
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
|
||||
|
||||
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
|
||||
~path.length #01 ADD =path.length
|
||||
$edit-end
|
||||
#00 ,path.name #00 ~path.length ADD2 POK2
|
||||
( release ) #00 =Keys.key
|
||||
BRK
|
||||
$no-edit
|
||||
|
||||
~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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue