uxn/projects/examples/dev.screen-old.usm

401 lines
12 KiB
Plaintext

( Dev/Screen )
%RTN { JMP2r }
%++ { #0001 ADD2 }
%2/ { #0001 SFT2 }
%8+ { #0008 ADD2 }
%STEP8 { #0033 SFT2 }
%S2B { SWP POP }
;center { x 2 y 2 }
;color { byte 1 }
;pointer { x 2 y 2 sprite 2 }
;rect { x1 2 y1 2 x2 2 y2 2 }
;window { x1 2 y1 2 x2 2 y2 2 w 2 h 2 }
;label { x 2 y 2 addr 2 }
;slider { x1 2 y 2 x2 2 pos 2 }
;selection { byte 1 }
;addr { short 2 }
;theme {
r1 1 r2 1 r3 1 r4 1
g1 1 g2 1 g3 1 g4 1
b1 1 b2 1 b3 1 b4 1
}
|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 }
|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 }
( program )
|0200
( theme ) #127f =System.r #34e7 =System.g #56c4 =System.b
( vectors ) ,on-mouse =Mouse.vector
#00b0 =window.w
#0050 =window.h
( center window )
~Screen.width #0002 DIV2 ~window.w #0002 DIV2 SUB2 =window.x1
~Screen.height #0002 DIV2 ~window.h #0002 DIV2 SUB2 =window.y1
#01 =theme.r1 #02 =theme.g1 #03 =theme.b1
#04 =theme.r2 #06 =theme.g2 #07 =theme.b2
#0a =theme.r3 #09 =theme.g3 #08 =theme.b3
#0c =theme.r4 #0b =theme.g4 #0d =theme.b4
( find screen center )
~Screen.width #0002 DIV2 =center.x
~Screen.height #0002 DIV2 =center.y
,update-theme JSR2
,draw-background JSR2
,draw-window JSR2
BRK
@on-mouse
,draw-cursor JSR2
~Mouse.state #00 NEQ ,$no-skip JNZ2 BRK $no-skip
~Mouse.y ~window.y1 SUB2 STEP8
DUP2 #0010 NEQ2 ^$no-touch-red JNZ
~Mouse.x ~window.x1 #0060 ADD2 LTH2 ^$no-touch-red JNZ
~Mouse.x ~window.x1 #009c ADD2 GTH2 ^$no-touch-red JNZ
( get new value ) ~Mouse.x ~window.x1 SUB2 #0060 SUB2 #0004 DIV2 S2B ,theme.r1 #00 ~selection ADD2 POK2
$no-touch-red
DUP2 #0020 NEQ2 ^$no-touch-green JNZ
~Mouse.x ~window.x1 #0060 ADD2 LTH2 ^$no-touch-green JNZ
~Mouse.x ~window.x1 #009c ADD2 GTH2 ^$no-touch-green JNZ
( get new value ) ~Mouse.x ~window.x1 SUB2 #0060 SUB2 #0004 DIV2 S2B ,theme.g1 #00 ~selection ADD2 POK2
$no-touch-green
DUP2 #0030 NEQ2 ^$no-touch-blue JNZ
~Mouse.x ~window.x1 #0060 ADD2 LTH2 ^$no-touch-blue JNZ
~Mouse.x ~window.x1 #009c ADD2 GTH2 ^$no-touch-blue JNZ
( get new value ) ~Mouse.x ~window.x1 SUB2 #0060 SUB2 #0004 DIV2 S2B ,theme.b1 #00 ~selection ADD2 POK2
$no-touch-blue
DUP2 #0040 NEQ2 ^$no-touch-radio JNZ
~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-radio JNZ
~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-radio JNZ
~Mouse.x ~window.x1 SUB2 #0050 SUB2 STEP8 2/ #0008 DIV2 S2B =selection
$no-touch-radio
POP2
,update-theme JSR2
,draw-window JSR2
BRK
@update-theme
#0108 PEK2 #0f AND ~theme.r1 #40 SFT ADD #0108 POK2
#010a PEK2 #0f AND ~theme.g1 #40 SFT ADD #010a POK2
#010c PEK2 #0f AND ~theme.b1 #40 SFT ADD #010c POK2
#0108 PEK2 #f0 AND ~theme.r2 ADD #0108 POK2
#010a PEK2 #f0 AND ~theme.g2 ADD #010a POK2
#010c PEK2 #f0 AND ~theme.b2 ADD #010c POK2
#0109 PEK2 #0f AND ~theme.r3 #40 SFT ADD #0109 POK2
#010b PEK2 #0f AND ~theme.g3 #40 SFT ADD #010b POK2
#010d PEK2 #0f AND ~theme.b3 #40 SFT ADD #010d POK2
#0109 PEK2 #f0 AND ~theme.r4 ADD #0109 POK2
#010b PEK2 #f0 AND ~theme.g4 ADD #010b POK2
#010d PEK2 #f0 AND ~theme.b4 ADD #010d POK2
RTN
@draw-background
( draw hor line )
#0000 =Screen.x ~center.y =Screen.y
#0000 ~Screen.width ( from/to )
$draw-hor
( draw ) #01 =Screen.color
( incr ) SWP2 #0002 ADD2 DUP2 =Screen.x SWP2
OVR2 OVR2 LTH2 ^$draw-hor JNZ
POP2 POP2
( draw ver line )
~center.x =Screen.x #0000 =Screen.y
#0000 ~Screen.height ( from/to )
$draw-ver
( draw ) #02 =Screen.color
( incr ) SWP2 #0002 ADD2 DUP2 =Screen.y SWP2
OVR2 OVR2 LTH2 ^$draw-ver JNZ
POP2 POP2
( draw blending modes )
,preview_icn =Screen.addr
#0010 =Screen.y
#00 #08
$draw-pixel1
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-pixel1 JNZ
POP POP
#0018 =Screen.y
#00 #08
$draw-pixel2
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR #08 ADD =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-pixel2 JNZ
POP POP
#0020 =Screen.y
#00 #08
$draw-icn1
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR #20 ADD =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-icn1 JNZ
POP POP
#0028 =Screen.y
#00 #08
$draw-icn2
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR #28 ADD =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-icn2 JNZ
POP POP
#0030 =Screen.y
#00 #08
$draw-chr1
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR #40 ADD =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-chr1 JNZ
POP POP
#0038 =Screen.y
#00 #08
$draw-chr2
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR #48 ADD =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-chr2 JNZ
POP POP
RTN
@draw-window
~window.x1 ~window.w ADD2 =window.x2
~window.y1 ~window.h ADD2 =window.y2
~window.x1 ~window.y1 ~window.x2 ~window.y2 #02 ,fill-rect JSR2
~window.x1 ~window.y1 ~window.x2 ~window.y2 #01 ,line-rect JSR2
~window.x1 #0002 SUB2 ~window.y1 #0002 SUB2 ~window.x2 #0002 ADD2 ~window.y2 #0002 ADD2 #01 ,line-rect JSR2
~window.x1 #0008 ADD2 ~window.y1 #0010 ADD2 #25 ,red_txt ,draw-label JSR2
~window.x1 #0038 ADD2 ~window.y1 #0010 ADD2 #28 ,System.r ,draw-byte JSR2
~window.x1 #0048 ADD2 ~window.y1 #0010 ADD2 #28 ,System.r #0001 ADD2 ,draw-byte JSR2
~window.x1 #0008 ADD2 ~window.y1 #0020 ADD2 #25 ,green_txt ,draw-label JSR2
~window.x1 #0038 ADD2 ~window.y1 #0020 ADD2 #28 ,System.g ,draw-byte JSR2
~window.x1 #0048 ADD2 ~window.y1 #0020 ADD2 #28 ,System.g #0001 ADD2 ,draw-byte JSR2
~window.x1 #0008 ADD2 ~window.y1 #0030 ADD2 #25 ,blue_txt ,draw-label JSR2
~window.x1 #0038 ADD2 ~window.y1 #0030 ADD2 #28 ,System.b ,draw-byte JSR2
~window.x1 #0048 ADD2 ~window.y1 #0030 ADD2 #28 ,System.b #0001 ADD2 ,draw-byte JSR2
~window.x1 #0060 ADD2 ~window.y1 #0010 ADD2 ~window.x1 #0090 ADD2 #00 ,theme.r1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
~window.x1 #0060 ADD2 ~window.y1 #0020 ADD2 ~window.x1 #0090 ADD2 #00 ,theme.g1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
~window.x1 #0060 ADD2 ~window.y1 #0030 ADD2 ~window.x1 #0090 ADD2 #00 ,theme.b1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
~window.x1 #0050 ADD2 =Screen.x
~window.y1 #0040 ADD2 =Screen.y
,radio_icns #00 ~selection #00 EQU #0008 MUL2 ADD2 =Screen.addr
#25 =Screen.color
~window.x1 #0060 ADD2 =Screen.x
~window.y1 #0040 ADD2 =Screen.y
,radio_icns #00 ~selection #01 EQU #0008 MUL2 ADD2 =Screen.addr
#25 =Screen.color
~window.x1 #0070 ADD2 =Screen.x
~window.y1 #0040 ADD2 =Screen.y
,radio_icns #00 ~selection #02 EQU #0008 MUL2 ADD2 =Screen.addr
#25 =Screen.color
~window.x1 #0080 ADD2 =Screen.x
~window.y1 #0040 ADD2 =Screen.y
,radio_icns #00 ~selection #03 EQU #0008 MUL2 ADD2 =Screen.addr
#25 =Screen.color
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 )
,pointer_icn =Screen.addr
~pointer.x =Screen.x
~pointer.y =Screen.y
#33 ~Mouse.state #00 NEQ #02 MUL SUB =Screen.color
RTN
@draw-slider ( x1 y x2 pos color -- )
( load ) =color =slider.pos =slider.x2 =slider.y =slider.x1
~slider.x1 =Screen.x
~slider.y =Screen.y
,halftone_icn =Screen.addr
,slidera_icn =Screen.addr
( draw ) #25 =Screen.color
,sliderb_icn =Screen.addr
$loop
( incr ) ~Screen.x 8+ =Screen.x
( draw ) #25 =Screen.color
~Screen.x ~slider.x2 #0008 ADD2 LTH2 ^$loop JNZ
( incr ) ~Screen.x #0004 ADD2 =Screen.x
,sliderc_icn =Screen.addr
( draw ) #25 =Screen.color
~slider.x1 ~slider.pos ADD2 =Screen.x
,sliderd_icn =Screen.addr
( draw ) #2a =Screen.color
RTN
@fill-rect ( x1 y1 x2 y2 color )
=color
( x1 x2 y1 y2 ) ROT2 SWP2
$ver
( save ) OVR2 =Screen.y
STH2 STH2 OVR2 OVR2
$hor
( save ) OVR2 =Screen.x
( draw ) ~color =Screen.color
( incr ) SWP2 #0001 ADD2 SWP2
OVR2 OVR2 LTH2 ^$hor JNZ
POP2 POP2 STH2r STH2r
( incr ) SWP2 #0001 ADD2 SWP2
OVR2 OVR2 LTH2 ^$ver JNZ
POP2 POP2 POP2 POP2
RTN
@line-rect ( x1 y1 x2 y2 color -- )
( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1
$hor
( incr ) ~Screen.x ++ =Screen.x
( draw ) ~rect.y1 =Screen.y ~color =Screen.color
( draw ) ~rect.y2 =Screen.y ~color =Screen.color
~Screen.x ~rect.x2 LTH2 ^$hor JNZ
~rect.y1 =Screen.y
$ver
( draw ) ~rect.x1 =Screen.x ~color =Screen.color
( draw ) ~rect.x2 =Screen.x ~color =Screen.color
( incr ) ~Screen.y ++ =Screen.y
~Screen.y ~rect.y2 ++ LTH2 ^$ver JNZ
RTN
@draw-label ( x y color addr -- )
( load ) =label.addr =color =Screen.y =Screen.x ~label.addr
$loop
( draw ) DUP2 PEK2 #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr ~color =Screen.color
( incr ) ++
( incr ) ~Screen.x 8+ =Screen.x
DUP2 PEK2 #00 NEQ ^$loop JNZ
POP2
RTN
@draw-byte ( x y color addr -- )
=addr STH
=Screen.y
=Screen.x
,font_hex #00 ~addr PEK2 #04 SFT #0008 MUL2 ADD2 =Screen.addr
STHr DUP STH =Screen.color
,font_hex #00 ~addr PEK2 #0f AND #0008 MUL2 ADD2 =Screen.addr
~Screen.x 8+ =Screen.x
STHr =Screen.color
RTN
@clear_icn [ 0000 0000 0000 0000 ]
@pointer_icn [ 80c0 e0f0 f8e0 1000 ]
@halftone_icn [ aa55 aa55 aa55 aa55 ]
@slidera_icn [ 3f7f ffff ffff 7f3f ]
@sliderb_icn [ ffff ffff ffff ffff ]
@sliderc_icn [ fcfe ffff ffff fefc ]
@sliderd_icn [ 003c 7e7e 7e7e 3c00 ]
@preview_icn [ 183c 66db db66 3c18 0000 183c 3c18 0000 ]
@radio_icns
[ 3c42 8181 8181 423c ]
[ 3c42 99bd bd99 423c ]
@red_txt [ Red 00 ]
@green_txt [ Green 00 ]
@blue_txt [ Blue 00 ]
@font_hex ( 0-F TODO: should pull from @font instead.. )
[
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
003c 4242 7e42 4200 007c 427c 4242 7c00
003c 4240 4042 3c00 007c 4242 4242 7c00
007e 4078 4040 7e00 007e 4078 4040 4000
]
@font ( spectrum-zx font )
[
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
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
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
0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000
0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000
0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400
0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000
0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800
0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000
003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00
0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000
003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810
0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800
003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00
0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00
0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200
0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00
007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00
00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200
0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00
0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00
0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00
0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c
0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400
0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800
0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800
0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800
0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00
0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
]