Added key example

This commit is contained in:
neauoire 2021-03-01 20:57:08 -08:00
parent f42a307f1f
commit 39faf4c2b7
1 changed files with 104 additions and 31 deletions

View File

@ -3,62 +3,76 @@
&Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } &Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
&Sprite { pad 8 x 2 y 2 addr 2 color 1 } &Sprite { pad 8 x 2 y 2 addr 2 color 1 }
&Keyboard { key 1 } &Keyboard { key 1 }
&Mouse { x 2 y 2 state 1 chord 1 }
&Textarea2d { x1 2 y1 2 x2 2 y2 2 color 1 addr 2 cursor 1 } &Textarea2d { x1 2 y1 2 x2 2 y2 2 color 1 addr 2 cursor 1 }
&Point2d { x 2 y 2 }
&Rect2d { x1 2 y1 2 x2 2 y2 2 } &Rect2d { x1 2 y1 2 x2 2 y2 2 }
&Point2d { x 2 y 2 }
;mouse Point2d
;textarea Textarea2d ;textarea Textarea2d
;rect Rect2d ;rect Rect2d
;color 1 ;color 1
;blink 1
;timer 1
|0100 @RESET |0100 @RESET
#0010 =textarea.x1 #0040 =textarea.y1 #00c0 =textarea.x2 #0090 =textarea.y2 ,body =textarea.addr #0080 =textarea.x1 #0060 =textarea.y1 #00c0 =textarea.x2 #0090 =textarea.y2 ,body =textarea.addr
,redraw JSR ,redraw JSR
,redraw-window JSR
BRK BRK
|0200 @FRAME |0200 @FRAME
~dev/key #00 EQU BRK? ( skip on no-key ) ,do-cursor JSR
,do-textarea JSR
( backspace )
,on-erase ~dev/key #08 EQU JMP? POP2
( otherwise )
~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR
( incr ) ~textarea.cursor #01 ADD =textarea.cursor
@input-end
#00 =dev/key ( release key )
,redraw JSR
BRK BRK
@redraw @redraw-window
~textarea.x1 ~textarea.y1 ~textarea.x2 ~textarea.y2 #01 ,fill-rect JSR #0000 #0000 ~dev/screen.width ~dev/screen.height #01 ,pattern ,tile-rect JSR
~textarea.x1 ~textarea.y1 #0f ~textarea.addr ,draw-textarea JSR ( dropshadow )
~textarea.x2 #0001 ADD2 ~textarea.y1 ~textarea.x2 #0004 ADD2 ~textarea.y2 #0004 ADD2 #01 ,fill-rect JSR
~textarea.x1 ~textarea.y2 #0001 ADD2 ~textarea.x2 #0001 ADD2 ~textarea.y2 #0004 ADD2 #01 ,fill-rect JSR
~textarea.x1 #0001 SUB2 ~textarea.y1 #0001 SUB2 ~textarea.x2 ~textarea.y2 #00 ,line-rect JSR
~textarea.x1 #0002 SUB2 ~textarea.y1 #0002 SUB2 ~textarea.x2 #0001 ADD2 ~textarea.y2 #0001 ADD2 #01 ,line-rect JSR ~textarea.x1 #0002 SUB2 ~textarea.y1 #0002 SUB2 ~textarea.x2 #0001 ADD2 ~textarea.y2 #0001 ADD2 #01 ,line-rect JSR
RTS RTS
@on-erase @redraw
( skip if cursor is at 0 ) ~textarea.x1 ~textarea.y1 ~textarea.x2 ~textarea.y2 #01 ,fill-rect JSR
,input-end ~textarea.cursor #01 LTH JMP? POP2 ~textarea.x1 ~textarea.y1 #04 ~textarea.addr ,draw-textarea JSR
#00 ~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR RTS
( decr ) ~textarea.cursor #01 SUB =textarea.cursor @blink-cursor
BRK ,skip ~timer #10 LTH JMP? POP2
#00 =timer
~blink #00 EQU =blink
,cursor =dev/sprite.addr
#05 ~blink ADD =dev/sprite.color
@skip
~timer #01 ADD =timer
RTS
@tile-rect ( x1 y1 x2 y2 color addr )
=dev/sprite.addr =color =rect.y2 =rect.x2 DUP2 =dev/sprite.y =rect.y1 DUP2 =dev/sprite.x =rect.x1
@tile-rect-ver
~rect.x1 =dev/sprite.x
@tile-rect-hor
( draw ) ~color =dev/sprite.color
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
,tile-rect-hor ~dev/sprite.x ~rect.x2 LTH2 JMP? POP2
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
,tile-rect-ver ~dev/sprite.y ~rect.y2 LTH2 JMP? POP2
RTS RTS
@ -115,12 +129,66 @@ RTS
RTS RTS
@do-textarea
( ,blink-cursor JSR )
,do-textarea-end ~dev/key #00 EQU JMP? POP2 ( skip on no key )
( backspace )
,any-key ~dev/key #08 NEQ JMP? POP2
,input-end ~textarea.cursor #00 EQU JMP? POP2
( decr ) ~textarea.cursor #01 SUB =textarea.cursor
#00 ~textarea.addr #00 ~textarea.cursor ADD2 STR
,input-end JMP
@any-key
~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR
( incr ) ~textarea.cursor #01 ADD =textarea.cursor
@input-end
#00 =dev/key ( release key )
,redraw JSR
( add cursor )
,cursor =dev/sprite.addr
#06 =dev/sprite.color
@do-textarea-end
RTS
@do-cursor
,skip-drag ~dev/mouse.state #01 NEQ JMP? POP2
~mouse.x =textarea.x1 ~mouse.y =textarea.y1
,redraw-window JSR
,redraw JSR
@skip-drag
~mouse.x ~dev/mouse.x NEQU2
~mouse.y ~dev/mouse.y NEQU2
#0000 EQU2 RTS? ( Return if unchanged )
( clear last cursor )
#10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR
( record mouse positions )
~dev/mouse.x =mouse.x ~dev/mouse.y =mouse.y
#12 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR
RTS
@draw-sprite
=dev/sprite.y
=dev/sprite.x
=dev/sprite.addr
=dev/sprite.color
RTS
@font ( spectrum-zx font ) @font ( spectrum-zx font )
[ [
0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000
007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000
0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800 0038 446c 107c 1000 0000 0000 0000 0000 003e 2222 2266 6600 0000 0822 0022 0800
0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800
003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038
0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000
@ -151,13 +219,18 @@ RTS
0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
] ]
@body [ ] @clear_icn [ 0000 0000 0000 0000 ]
@cursor_icn [ 80c0 e0f0 f8e0 1000 ]
@pattern [ aa55 aa55 aa55 aa55 ]
@cursor [ 7e7e 7e7e 7e7e 7e7e ]
@body [ ]
|d000 @ERROR BRK |d000 @ERROR BRK
|FF10 ;dev/screen Screen |FF10 ;dev/screen Screen
|FF20 ;dev/sprite Sprite |FF20 ;dev/sprite Sprite
|FF40 ;dev/key Keyboard |FF40 ;dev/key Keyboard
|FF50 ;dev/mouse Mouse
|FFF0 .RESET .FRAME .ERROR ( vectors ) |FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ f0ff f00f f00f ] ( palette ) |FFF8 [ f0ff f000 f00f ] ( palette )