mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-26 15:53:01 +00:00
Ported mouse example
This commit is contained in:
parent
53eacc6039
commit
b01b74bad4
9 changed files with 93 additions and 230 deletions
14
README.md
14
README.md
|
@ -22,11 +22,17 @@ To build the Uxn emulator, you must have [SDL2](https://wiki.libsdl.org/).
|
|||
Read more in the [Uxambly Guide](https://wiki.xxiivv.com/site/uxambly.html).
|
||||
|
||||
```
|
||||
( dev/console )
|
||||
|
||||
%RTN { JMP2r }
|
||||
|
||||
( program )
|
||||
( devices )
|
||||
|
||||
|0100
|
||||
|10 @Console [ &pad $8 &char $1 ]
|
||||
|
||||
( init )
|
||||
|
||||
|0100 ( -> )
|
||||
|
||||
;hello-word ;print JSR2
|
||||
|
||||
|
@ -43,10 +49,6 @@ BRK
|
|||
RTN
|
||||
|
||||
@hello-word [ 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 ]
|
||||
|
||||
( devices )
|
||||
|
||||
|ff10 @Console [ &pad $8 &char $1 ]
|
||||
```
|
||||
|
||||
## TODOs
|
||||
|
|
2
build.sh
2
build.sh
|
@ -32,7 +32,7 @@ else
|
|||
fi
|
||||
|
||||
echo "Assembling.."
|
||||
./bin/assembler projects/examples/dev.controller.keys.usm bin/boot.rom
|
||||
./bin/assembler projects/examples/dev.mouse.usm bin/boot.rom
|
||||
|
||||
echo "Running.."
|
||||
if [ "${2}" = '--cli' ];
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
( a blank file )
|
||||
|
||||
%RTN { JMP2r }
|
||||
|
||||
( devices )
|
||||
|
||||
|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|
||||
|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 button 1 key 1 }
|
||||
|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 }
|
||||
|0170 ;File { vector 2 success 2 offset 2 pad 2 name 2 length 2 load 2 save 2 }
|
||||
|01a0 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dotw 1 doty 2 isdst 1 refresh 1 }
|
||||
|
||||
|0200
|
||||
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|
||||
|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ]
|
||||
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|
||||
|40 @Controller [ &vector $2 &button $1 &key $1 ]
|
||||
|60 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &chord $1 ]
|
||||
|70 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ]
|
||||
|
||||
|1000 ( program )
|
||||
|
|
|
@ -6,13 +6,9 @@
|
|||
|
||||
|10 @Console [ &pad $8 &char $1 ]
|
||||
|
||||
( variables )
|
||||
( init )
|
||||
|
||||
|0000
|
||||
|
||||
( program )
|
||||
|
||||
|0100
|
||||
|0100 ( -> )
|
||||
|
||||
;hello-word ;print JSR2
|
||||
|
||||
|
@ -29,4 +25,3 @@ BRK
|
|||
RTN
|
||||
|
||||
@hello-word [ 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 ]
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|
||||
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|
||||
|40 @Controller [ &vector $2 &button $1 &key $1 ]
|
||||
|40 @Controller [ &vector $2 &button $1 &key $1 ]
|
||||
|
||||
( variables )
|
||||
|
||||
|
@ -18,7 +18,9 @@
|
|||
|
||||
@slime $1
|
||||
|
||||
|0100
|
||||
( init )
|
||||
|
||||
|0100 ( -> )
|
||||
|
||||
( theme )
|
||||
#0daf .System/r IOW2
|
||||
|
@ -38,7 +40,7 @@
|
|||
|
||||
BRK
|
||||
|
||||
@on-frame
|
||||
@on-frame ( -> )
|
||||
|
||||
#2a .slime POK
|
||||
;default_icn =>SC/ADDR
|
||||
|
|
|
@ -10,13 +10,9 @@
|
|||
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|
||||
|40 @Controller [ &vector $2 &button $1 &key $1 ]
|
||||
|
||||
( variables )
|
||||
( init )
|
||||
|
||||
|0000
|
||||
|
||||
@slime $1
|
||||
|
||||
|0100
|
||||
|0100 ( -> )
|
||||
|
||||
( theme )
|
||||
#0f73 .System/r IOW2
|
||||
|
@ -29,7 +25,7 @@
|
|||
|
||||
BRK
|
||||
|
||||
@on-button
|
||||
@on-button ( -> )
|
||||
|
||||
.Controller/key IOR #00 NEQ ,&skip JNZ BRK &skip
|
||||
|
||||
|
@ -49,14 +45,13 @@ BRK
|
|||
|
||||
BRK
|
||||
|
||||
@draw-cursor
|
||||
@draw-cursor ( -- )
|
||||
|
||||
;cursor .Screen/addr IOW2 #22 .Screen/color IOW
|
||||
|
||||
RTN
|
||||
|
||||
@cursor
|
||||
ffff ffff ffff ffff
|
||||
@cursor [ ffff ffff ffff ffff ]
|
||||
|
||||
@font ( spectrum-zx font )
|
||||
0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
|
||||
|
|
|
@ -1,188 +0,0 @@
|
|||
( Dev/File )
|
||||
|
||||
%RTN { JMP2r }
|
||||
%STEP8 { #0033 SFT2 }
|
||||
%++ { #01 ADD }
|
||||
|
||||
%MEMORY { #1000 }
|
||||
|
||||
;loadbtn { x 2 y 2 }
|
||||
;output { x 2 y 2 }
|
||||
;pointer { x 2 y 2 }
|
||||
;label { x 2 y 2 color 1 addr 2 }
|
||||
|
||||
( devices )
|
||||
|
||||
|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|
||||
|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 }
|
||||
|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 }
|
||||
|0170 ;File { vector 2 success 2 offset 2 pad 2 name 2 length 2 load 2 save 2 }
|
||||
|
||||
( program )
|
||||
|
||||
|0200
|
||||
|
||||
( theme ) #804b =System.r #804b =System.g #e0bb =System.b
|
||||
( vectors ) ,on-mouse =Mouse.vector
|
||||
( vectors ) ,on-transfer =File.vector
|
||||
|
||||
#0020 =loadbtn.x
|
||||
#0020 =loadbtn.y
|
||||
#0020 =output.x
|
||||
#0030 =output.y
|
||||
|
||||
~loadbtn.x ~loadbtn.y #26 ,load_txt ,draw-label JSR2
|
||||
|
||||
,draw-file JSR2
|
||||
|
||||
BRK
|
||||
|
||||
@on-transfer ( -> )
|
||||
|
||||
,draw-file JSR2
|
||||
~output.x ~output.y #0088 ADD2 #23 ,done_txt ,draw-label JSR2
|
||||
( release ) #00 =Mouse.state
|
||||
|
||||
BRK
|
||||
|
||||
@on-mouse ( -> )
|
||||
|
||||
~loadbtn.x ~loadbtn.y #26 ,load_txt ,draw-label JSR2
|
||||
~loadbtn.x #0028 ADD2 ~loadbtn.y #23 ,srcpath ,draw-label JSR2
|
||||
|
||||
~Mouse.state #00 EQU ^$touch-end JNZ
|
||||
|
||||
~Mouse.y STEP8 ~loadbtn.y NEQ2 ^$no-touch-load JNZ
|
||||
~loadbtn.x ~loadbtn.y #27 ,load_txt ,draw-label JSR2
|
||||
,srcpath #0100 ,load-file JSR2
|
||||
( release ) #00 =Mouse.state
|
||||
$no-touch-load
|
||||
|
||||
$touch-end
|
||||
|
||||
,draw-cursor JSR2
|
||||
|
||||
BRK
|
||||
|
||||
@draw-file ( -- )
|
||||
|
||||
#00 #10
|
||||
$ver
|
||||
( pos-y ) OVR #00 SWP #0008 MUL2 ~output.y ADD2 =Screen.y
|
||||
#00 #10
|
||||
$hor
|
||||
( pos-x ) OVR #00 SWP #0008 MUL2 ~output.x ADD2 =Screen.x
|
||||
( get x,y ) SWP2 OVR STH SWP2 OVR STHr
|
||||
( get id ) #10 MUL ADD
|
||||
( get data ) #00 SWP MEMORY ADD2 PEK2
|
||||
( get sprite ) #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
|
||||
( draw ) #2d =Screen.color
|
||||
( incr ) SWP ++ SWP
|
||||
DUP2 NEQ ^$hor JNZ
|
||||
POP2
|
||||
( incr ) SWP ++ SWP
|
||||
DUP2 NEQ ^$ver JNZ
|
||||
POP2
|
||||
|
||||
RTN
|
||||
|
||||
@load-file ( path length -- )
|
||||
|
||||
=File.length =File.name MEMORY =File.load
|
||||
|
||||
RTN
|
||||
|
||||
@draw-cursor ( -- )
|
||||
|
||||
( clear last cursor )
|
||||
,clear_icn =Screen.addr
|
||||
~pointer.x =Screen.x
|
||||
~pointer.y =Screen.y
|
||||
#30 =Screen.color
|
||||
|
||||
( record pointer positions )
|
||||
~Mouse.x =pointer.x ~Mouse.y =pointer.y
|
||||
|
||||
( draw new cursor )
|
||||
,cursor_icn =Screen.addr
|
||||
~pointer.x =Screen.x
|
||||
~pointer.y =Screen.y
|
||||
#32 ~Mouse.state #00 NEQ ADD =Screen.color
|
||||
|
||||
RTN
|
||||
|
||||
@draw-label ( x y color addr -- )
|
||||
|
||||
( load ) =label.addr =label.color =Screen.y =Screen.x
|
||||
~label.addr
|
||||
$loop
|
||||
( draw ) DUP2 PEK2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr ~label.color =Screen.color
|
||||
( incr ) #0001 ADD2
|
||||
( incr ) ~Screen.x #0008 ADD2 =Screen.x
|
||||
DUP2 PEK2 #00 NEQ ^$loop JNZ
|
||||
POP2
|
||||
|
||||
RTN
|
||||
|
||||
@clear_icn [ 0000 0000 0000 0000 ]
|
||||
@cursor_icn [ 80c0 e0f0 f8e0 1000 ]
|
||||
|
||||
@done_txt [ LOAD 20 SUCCESS! 00 ]
|
||||
@load_txt [ LOAD 00 ]
|
||||
@save_txt [ SAVE 00 ]
|
||||
|
||||
@srcpath [ README.md 00 ]
|
||||
@dstpath [ bin/export.md 00 ]
|
||||
|
||||
@font ( specter8-frag font )
|
||||
[
|
||||
0000 0000 0000 0000 0008 0808 0800 0800
|
||||
0014 1400 0000 0000 0024 7e24 247e 2400
|
||||
0008 1e28 1c0a 3c08 0000 2204 0810 2200
|
||||
0030 4832 4c44 3a00 0008 1000 0000 0000
|
||||
0004 0808 0808 0400 0020 1010 1010 2000
|
||||
0000 2214 0814 2200 0000 0808 3e08 0800
|
||||
0000 0000 0000 0810 0000 0000 3e00 0000
|
||||
0000 0000 0000 0800 0000 0204 0810 2000
|
||||
003c 464a 5262 3c00 0018 0808 0808 1c00
|
||||
003c 4202 3c40 7e00 003c 421c 0242 3c00
|
||||
000c 1424 447e 0400 007e 407c 0242 3c00
|
||||
003c 407c 4242 3c00 007e 0204 0810 1000
|
||||
003c 423c 4242 3c00 003c 4242 3e02 3c00
|
||||
0000 0010 0000 1000 0000 1000 0010 1020
|
||||
0000 0810 2010 0800 0000 003e 003e 0000
|
||||
0000 1008 0408 1000 003c 420c 1000 1000
|
||||
003c 4232 4a42 3c00 003c 4242 7e42 4200
|
||||
007c 427c 4242 7c00 003c 4240 4042 3c00
|
||||
007c 4242 4242 7c00 007e 4078 4040 7e00
|
||||
007e 4078 4040 4000 003c 4240 4642 3c00
|
||||
0042 427e 4242 4200 001c 0808 0808 1c00
|
||||
007e 0202 0242 3c00 0042 4478 4442 4200
|
||||
0040 4040 4040 7e00 0042 665a 4242 4200
|
||||
0042 6252 4a46 4200 003c 4242 4242 3c00
|
||||
007c 4242 7c40 4000 003c 4242 4244 3a00
|
||||
007c 4242 7c44 4200 003e 403c 0242 3c00
|
||||
007e 0808 0808 1000 0042 4242 4244 3a00
|
||||
0042 4242 4224 1800 0042 4242 5a66 4200
|
||||
0042 423c 4242 4200 0042 423e 0242 3c00
|
||||
007e 020c 3040 7e00 000c 0808 0808 0c00
|
||||
0040 2010 0804 0200 0030 1010 1010 3000
|
||||
0008 1400 0000 0000 0000 0000 0000 7e00
|
||||
0008 0400 0000 0000 0000 3c02 3e42 3a00
|
||||
0040 407c 4242 7c00 0000 3c42 4042 3c00
|
||||
0002 023e 4242 3e00 0000 3c42 7e40 3e00
|
||||
0000 3e40 7840 4000 0000 3c42 3e02 3c00
|
||||
0040 405c 6242 4200 0008 0018 0808 0400
|
||||
0008 0018 0808 4830 0040 4244 7844 4200
|
||||
0010 1010 1010 0c00 0000 6c52 5252 5200
|
||||
0000 5c62 4242 4200 0000 3c42 4242 3c00
|
||||
0000 7c42 427c 4040 0000 3e42 423e 0202
|
||||
0000 5c62 4040 4000 0000 3e40 3c02 7c00
|
||||
0008 7e08 0808 1000 0000 4242 4244 3a00
|
||||
0000 4242 4224 1800 0000 5252 5252 2e00
|
||||
0000 4224 1824 4200 0000 4242 3e02 7c00
|
||||
0000 7e02 3c40 7e00 000c 0810 1008 0c00
|
||||
0008 0808 0808 0800 0030 1008 0810 3000
|
||||
0000 0032 4c00 0000 3c42 99a1 a199 423c
|
||||
]
|
|
@ -34,9 +34,9 @@
|
|||
@pointer [ &x $2 &y $2 ]
|
||||
@label [ &x $2 &y $2 &color $1 &addr $2 ]
|
||||
|
||||
( program )
|
||||
( init )
|
||||
|
||||
|0100
|
||||
|0100 ( -> )
|
||||
|
||||
( theme )
|
||||
#804b .System/r IOW2
|
||||
|
@ -204,4 +204,3 @@ RTN
|
|||
0008 0808 0808 0800 0030 1008 0810 3000
|
||||
0000 0032 4c00 0000 3c42 99a1 a199 423c
|
||||
]
|
||||
|
||||
|
|
63
projects/examples/dev.mouse.usm
Normal file
63
projects/examples/dev.mouse.usm
Normal file
|
@ -0,0 +1,63 @@
|
|||
( dev/mouse )
|
||||
|
||||
%RTN { JMP2r }
|
||||
%8+ { #0008 ADD2 }
|
||||
%++ { #0001 ADD2 }
|
||||
%-- { #0001 SUB2 }
|
||||
|
||||
( devices )
|
||||
|
||||
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|
||||
|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ]
|
||||
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|
||||
|40 @Controller [ &vector $2 &button $1 &key $1 ]
|
||||
|60 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &chord $1 ]
|
||||
|
||||
|0000
|
||||
|
||||
@pointer [ &x $2 &y $2 ]
|
||||
|
||||
( program )
|
||||
|
||||
|0100 ( -> )
|
||||
|
||||
( theme )
|
||||
#03fd .System/r IOW2
|
||||
#0ef3 .System/g IOW2
|
||||
#0bf2 .System/b IOW2
|
||||
|
||||
( vectors ) ;on-mouse .Mouse/vector IOW2
|
||||
|
||||
BRK
|
||||
|
||||
@on-mouse ( -> )
|
||||
|
||||
;draw-cursor JSR2
|
||||
|
||||
BRK
|
||||
|
||||
@draw-cursor ( -- )
|
||||
|
||||
( clear last cursor )
|
||||
;clear .Screen/addr IOW2
|
||||
.pointer/x LDR .Screen/x IOW2
|
||||
.pointer/y LDR .Screen/y IOW2
|
||||
#30 .Screen/color IOW
|
||||
|
||||
( record pointer positions )
|
||||
.Mouse/x IOR2 .pointer/x STR
|
||||
.Mouse/y IOR2 .pointer/y STR
|
||||
|
||||
( draw new cursor )
|
||||
;cursor .Screen/addr IOW2
|
||||
.pointer/x LDR .Screen/x IOW2
|
||||
.pointer/y LDR .Screen/y IOW2
|
||||
|
||||
( colorize on state )
|
||||
.Mouse/state IOR #00 NEQ
|
||||
#31 ADD .Screen/color IOW
|
||||
|
||||
RTN
|
||||
|
||||
@clear [ 0000 0000 0000 0000 ]
|
||||
@cursor [ 80c0 e0f0 f8e0 1000 ]
|
Loading…
Reference in a new issue