(examples/devices) Revamped a lot of the device examples
This commit is contained in:
parent
0c587b9e0e
commit
45c31327ec
|
@ -1,23 +0,0 @@
|
|||
( dev/console )
|
||||
|
||||
(
|
||||
Copies data from stdin to both stdout and stderr.
|
||||
)
|
||||
|
||||
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
|
||||
|
||||
( init )
|
||||
|
||||
|0100 ( -> )
|
||||
|
||||
;on-stdin .Console/vector DEO2
|
||||
|
||||
BRK
|
||||
|
||||
@on-stdin ( -> )
|
||||
|
||||
.Console/read DEI
|
||||
DUP .Console/write DEO
|
||||
.Console/error DEO
|
||||
|
||||
BRK
|
|
@ -1,94 +0,0 @@
|
|||
( dev/console )
|
||||
|
||||
%RTN { JMP2r }
|
||||
%PRINT { ;print JSR2 }
|
||||
%BR { #0a .Console/write DEO }
|
||||
|
||||
( devices )
|
||||
|
||||
|10 @Console [ &pad $8 &write $1 ]
|
||||
|
||||
( variables )
|
||||
|
||||
|0000
|
||||
|
||||
@number [ &started $1 ]
|
||||
|
||||
( init )
|
||||
|
||||
|0100 ( -> )
|
||||
|
||||
;char-txt PRINT #42 .Console/write DEO BR
|
||||
;byte-txt PRINT #ab ;print-byte JSR2 BR
|
||||
;short-txt PRINT #cdef ;print-short JSR2 BR
|
||||
;string-txt PRINT ;hello-word ;print JSR2 BR
|
||||
|
||||
;hello-word ;print JSR2
|
||||
#ffff ;print-short JSR2
|
||||
;is-word ;print JSR2
|
||||
#ffff ;print-short-decimal JSR2
|
||||
|
||||
BRK
|
||||
|
||||
@print ( addr* -- )
|
||||
|
||||
&loop
|
||||
( send ) LDAk .Console/write DEO
|
||||
( incr ) INC2
|
||||
( loop ) LDAk ,&loop JCN
|
||||
POP2
|
||||
|
||||
RTN
|
||||
|
||||
@print-short ( short* -- )
|
||||
LIT '0 .Console/write DEO
|
||||
LIT 'x .Console/write DEO
|
||||
OVR #04 SFT ,&hex JSR
|
||||
SWP #0f AND ,&hex JSR
|
||||
DUP #04 SFT ,&hex JSR
|
||||
#0f AND ,&hex JMP
|
||||
|
||||
&hex
|
||||
#30 ADD DUP #3a LTH ,¬-alpha JCN
|
||||
#27 ADD
|
||||
¬-alpha
|
||||
.Console/write DEO
|
||||
RTN
|
||||
|
||||
@print-byte ( byte -- )
|
||||
LIT '0 .Console/write DEO
|
||||
LIT 'x .Console/write DEO
|
||||
DUP #04 SFT ,&hex JSR
|
||||
#0f AND ,&hex JMP
|
||||
|
||||
&hex
|
||||
#30 ADD DUP #39 GTH #27 MUL ADD .Console/write DEO
|
||||
RTN
|
||||
|
||||
@print-short-decimal ( short -- )
|
||||
#00 .number/started STZ
|
||||
DUP2 #2710 DIV2 DUP2 ,&digit JSR #2710 MUL2 SUB2
|
||||
DUP2 #03e8 DIV2 DUP2 ,&digit JSR #03e8 MUL2 SUB2
|
||||
DUP2 #0064 DIV2 DUP2 ,&digit JSR #0064 MUL2 SUB2
|
||||
DUP2 #000a DIV2 DUP2 ,&digit JSR #000a MUL2 SUB2
|
||||
,&digit JSR
|
||||
.number/started LDZ ,&end JCN
|
||||
LIT '0 .Console/write DEO
|
||||
&end
|
||||
RTN
|
||||
|
||||
&digit
|
||||
NIP
|
||||
DUP .number/started LDZ ORA #02 JCN
|
||||
POP JMP2r
|
||||
LIT '0 ADD .Console/write DEO
|
||||
#01 .number/started STZ
|
||||
RTN
|
||||
|
||||
@char-txt "char: 20 $1
|
||||
@byte-txt "byte: 20 $1
|
||||
@short-txt "short: 20 $1
|
||||
@string-txt "string: 20 $1
|
||||
|
||||
@hello-word "hello 20 "World! 0a 00
|
||||
@is-word 20 "is 20 00
|
|
@ -1,19 +1,37 @@
|
|||
( dev/console )
|
||||
( Console:
|
||||
Prints Hello Uxn!, and listens for incoming stdin events on enter. )
|
||||
|
||||
%HALT { #010f DEO }
|
||||
%EMIT { #18 DEO }
|
||||
|
||||
( init )
|
||||
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
|
||||
|
||||
|0100 ( -> )
|
||||
|
||||
;hello-word
|
||||
( set vector )
|
||||
;on-console .Console/vector DEO2
|
||||
( print hello )
|
||||
;hello-txt
|
||||
&while
|
||||
( send ) LDAk EMIT
|
||||
LDAk .Console/write DEO
|
||||
INC2 LDAk ,&while JCN
|
||||
POP2
|
||||
( stop ) HALT
|
||||
|
||||
BRK
|
||||
|
||||
@hello-word "Hello 20 "Uxn! $1
|
||||
@on-console ( -> )
|
||||
|
||||
;yousaid-txt ,print-str JSR
|
||||
.Console/read DEI .Console/write DEO
|
||||
#0a .Console/write DEO
|
||||
|
||||
BRK
|
||||
|
||||
@print-str ( str* -- )
|
||||
|
||||
&while
|
||||
LDAk #18 DEO
|
||||
INC2 LDAk ,&while JCN
|
||||
POP2
|
||||
|
||||
JMP2r
|
||||
|
||||
@hello-txt "Hello 20 "Uxn! $1
|
||||
@yousaid-txt "You 20 "said: 20 $1
|
||||
|
|
|
@ -1,35 +1,16 @@
|
|||
( dev/controller/keys )
|
||||
( Controller:
|
||||
Buttons should highlight on press and display the button and key bytes. )
|
||||
|
||||
%+ { ADD } %- { SUB } %/ { DIV }
|
||||
%< { LTH } %> { GTH } %= { EQU } %! { NEQ }
|
||||
%++ { ADD2 } %-- { SUB2 } %// { DIV2 }
|
||||
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
|
||||
|
||||
%RTN { JMP2r }
|
||||
%TOS { #00 SWP }
|
||||
%LTS2 { #8000 ++ SWP2 #8000 ++ >> }
|
||||
%AUTO-NONE { #00 .Screen/auto DEO }
|
||||
%AUTO-X { #01 .Screen/auto DEO }
|
||||
|
||||
( devices )
|
||||
|
||||
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|
||||
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
||||
|80 @Controller [ &vector $2 &button $1 &key $1 ]
|
||||
|
||||
( variables )
|
||||
|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
|
||||
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
||||
|80 @Controller &vector $2 &button $1 &key $1
|
||||
|
||||
|0000
|
||||
|
||||
@center
|
||||
&x $2
|
||||
&y $2
|
||||
&x $2 &y $2
|
||||
@frame
|
||||
&w $2 &h $2
|
||||
&x0 $2 &y0 $2
|
||||
&x1 $2 &y1 $2
|
||||
|
||||
( init )
|
||||
&w $2 &h $2 &x0 $2 &y0 $2 &x1 $2 &y1 $2
|
||||
|
||||
|0100 ( -> )
|
||||
|
||||
|
@ -37,22 +18,18 @@
|
|||
#0ff7 .System/r DEO2
|
||||
#0f07 .System/g DEO2
|
||||
#0f07 .System/b DEO2
|
||||
|
||||
( find center )
|
||||
.Screen/width DEI2 #01 SFT2 .center/x STZ2
|
||||
.Screen/height DEI2 #01 SFT2 .center/y STZ2
|
||||
|
||||
( place controller )
|
||||
#0068 .frame/w STZ2
|
||||
#0030 .frame/h STZ2
|
||||
.center/x LDZ2 .frame/w LDZ2 #0002 // -- .frame/x0 STZ2
|
||||
.center/y LDZ2 .frame/h LDZ2 #0002 // -- .frame/y0 STZ2
|
||||
.frame/x0 LDZ2 .frame/w LDZ2 ++ .frame/x1 STZ2
|
||||
.frame/y0 LDZ2 .frame/h LDZ2 ++ .frame/y1 STZ2
|
||||
|
||||
.center/x LDZ2 .frame/w LDZ2 #01 SFT2 SUB2 .frame/x0 STZ2
|
||||
.center/y LDZ2 .frame/h LDZ2 #01 SFT2 SUB2 .frame/y0 STZ2
|
||||
.frame/x0 LDZ2 .frame/w LDZ2 ADD2 .frame/x1 STZ2
|
||||
.frame/y0 LDZ2 .frame/h LDZ2 ADD2 .frame/y1 STZ2
|
||||
( vectors )
|
||||
;on-button .Controller/vector DEO2
|
||||
|
||||
( frame )
|
||||
.frame/x0 LDZ2 .frame/y0 LDZ2
|
||||
.frame/x1 LDZ2 .frame/y1 LDZ2
|
||||
|
@ -67,7 +44,7 @@ BRK
|
|||
,draw-controller JSR
|
||||
|
||||
( print stack on start button )
|
||||
.Controller/button DEI #08 = JMP BRK #010e DEO
|
||||
.Controller/button DEI #08 EQU JMP BRK #010e DEO
|
||||
|
||||
BRK
|
||||
|
||||
|
@ -76,74 +53,74 @@ BRK
|
|||
.Controller/button DEI STH
|
||||
|
||||
( d-pad )
|
||||
.frame/x0 LDZ2 #0010 ++ .Screen/x DEO2
|
||||
.frame/y0 LDZ2 #0010 ++ .Screen/y DEO2
|
||||
.frame/x0 LDZ2 #0010 ADD2 .Screen/x DEO2
|
||||
.frame/y0 LDZ2 #0010 ADD2 .Screen/y DEO2
|
||||
;controller-icn/dpad-up .Screen/addr DEO2
|
||||
#03 [ STHkr #04 SFT #01 AND DUP + - ] .Screen/sprite DEO
|
||||
.Screen/y DEI2 #0010 ++ .Screen/y DEO2
|
||||
#03 [ STHkr #04 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO
|
||||
.Screen/y DEI2 #0010 ADD2 .Screen/y DEO2
|
||||
;controller-icn/dpad-down .Screen/addr DEO2
|
||||
#03 [ STHkr #05 SFT #01 AND DUP + - ] .Screen/sprite DEO
|
||||
.Screen/y DEI2 #0008 -- .Screen/y DEO2
|
||||
.Screen/x DEI2 #0008 -- .Screen/x DEO2
|
||||
#03 [ STHkr #05 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO
|
||||
.Screen/y DEI2 #0008 SUB2 .Screen/y DEO2
|
||||
.Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
|
||||
;controller-icn/dpad-left .Screen/addr DEO2
|
||||
#03 [ STHkr #06 SFT #01 AND DUP + - ] .Screen/sprite DEO
|
||||
.Screen/x DEI2 #0010 ++ .Screen/x DEO2
|
||||
#03 [ STHkr #06 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO
|
||||
.Screen/x DEI2 #0010 ADD2 .Screen/x DEO2
|
||||
;controller-icn/dpad-right .Screen/addr DEO2
|
||||
#03 [ STHkr #07 SFT #01 AND DUP + - ] .Screen/sprite DEO
|
||||
.Screen/x DEI2 #0008 -- .Screen/x DEO2
|
||||
#03 [ STHkr #07 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO
|
||||
.Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
|
||||
;controller-icn/dpad .Screen/addr DEO2
|
||||
#03 .Screen/sprite DEO
|
||||
|
||||
( options )
|
||||
.center/y LDZ2 #0009 ++ .Screen/y DEO2
|
||||
.center/x LDZ2 #0009 -- .Screen/x DEO2
|
||||
.center/y LDZ2 #0009 ADD2 .Screen/y DEO2
|
||||
.center/x LDZ2 #0009 SUB2 .Screen/x DEO2
|
||||
;controller-icn/option .Screen/addr DEO2
|
||||
#03 [ STHkr #02 SFT #01 AND DUP + - ] .Screen/sprite DEO
|
||||
.center/x LDZ2 #0004 ++ .Screen/x DEO2
|
||||
#03 [ STHkr #02 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO
|
||||
.center/x LDZ2 #0004 ADD2 .Screen/x DEO2
|
||||
;controller-icn/option .Screen/addr DEO2
|
||||
#03 [ STHkr #03 SFT #01 AND DUP + - ] .Screen/sprite DEO
|
||||
#03 [ STHkr #03 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO
|
||||
|
||||
( buttons )
|
||||
.center/y LDZ2 #0000 ++ .Screen/y DEO2
|
||||
.center/x LDZ2 #0018 ++ .Screen/x DEO2
|
||||
.center/y LDZ2 #0000 ADD2 .Screen/y DEO2
|
||||
.center/x LDZ2 #0018 ADD2 .Screen/x DEO2
|
||||
;controller-icn/button .Screen/addr DEO2
|
||||
#03 [ STHkr #01 SFT #01 AND - ] .Screen/sprite DEO
|
||||
.Screen/y DEI2 #000a ++ .Screen/y DEO2
|
||||
;font-hex #000b #30 SFT2 ++ .Screen/addr DEO2
|
||||
#03 [ STHkr #01 SFT #01 AND SUB ] .Screen/sprite DEO
|
||||
.Screen/y DEI2 #000a ADD2 .Screen/y DEO2
|
||||
;font-hex #000b #30 SFT2 ADD2 .Screen/addr DEO2
|
||||
#03 .Screen/sprite DEO
|
||||
|
||||
.center/y LDZ2 #0000 ++ .Screen/y DEO2
|
||||
.center/x LDZ2 #0024 ++ .Screen/x DEO2
|
||||
.center/y LDZ2 #0000 ADD2 .Screen/y DEO2
|
||||
.center/x LDZ2 #0024 ADD2 .Screen/x DEO2
|
||||
;controller-icn/button .Screen/addr DEO2
|
||||
#03 [ STHr #01 AND - ] .Screen/sprite DEO
|
||||
.Screen/y DEI2 #000a ++ .Screen/y DEO2
|
||||
;font-hex #000a #30 SFT2 ++ .Screen/addr DEO2
|
||||
#03 [ STHr #01 AND SUB ] .Screen/sprite DEO
|
||||
.Screen/y DEI2 #000a ADD2 .Screen/y DEO2
|
||||
;font-hex #000a #30 SFT2 ADD2 .Screen/addr DEO2
|
||||
#03 .Screen/sprite DEO
|
||||
|
||||
.center/x LDZ2 #0010 -- .Screen/x DEO2
|
||||
.center/y LDZ2 #0010 -- .Screen/y DEO2
|
||||
AUTO-X
|
||||
.Controller/button DEI2 #03 ;draw-short JSR2
|
||||
AUTO-NONE
|
||||
.center/x LDZ2 #0010 SUB2 .Screen/x DEO2
|
||||
.center/y LDZ2 #0010 SUB2 .Screen/y DEO2
|
||||
#01 .Screen/auto DEO
|
||||
.Controller/button DEI2 ,draw-short JSR
|
||||
#00 .Screen/auto DEO
|
||||
|
||||
RTN
|
||||
JMP2r
|
||||
|
||||
( generics )
|
||||
|
||||
@draw-short ( short* color -- )
|
||||
@draw-short ( short* -- )
|
||||
|
||||
STH SWP STHkr ,draw-byte JSR STHr
|
||||
SWP ,draw-byte JSR
|
||||
|
||||
@draw-byte ( byte color -- )
|
||||
@draw-byte ( byte -- )
|
||||
|
||||
STH DUP #04 SFT STHkr ,draw-hex JSR STHr
|
||||
DUP #04 SFT ,draw-hex JSR
|
||||
|
||||
@draw-hex ( char color -- )
|
||||
@draw-hex ( char -- )
|
||||
|
||||
#00 ROT #0f AND #30 SFT2 ;font-hex ++ .Screen/addr DEO2
|
||||
.Screen/sprite DEO
|
||||
#00 SWP #0f AND #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
|
||||
#03 .Screen/sprite DEO
|
||||
|
||||
RTN
|
||||
JMP2r
|
||||
|
||||
@line-rect ( x1* y1* x2* y2* color -- )
|
||||
|
||||
|
@ -170,7 +147,7 @@ RTN
|
|||
POP2 POP2
|
||||
POPr
|
||||
|
||||
RTN
|
||||
JMP2r
|
||||
|
||||
@controller-icn
|
||||
&dpad ffff ffff ffff ffff
|
||||
|
@ -182,11 +159,11 @@ RTN
|
|||
&button 3c7e ffff ffff 7e3c
|
||||
|
||||
@font-hex
|
||||
003c 4242 4242 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
|
||||
007c 8282 8282 827c 0030 1010 1010 1010
|
||||
007c 8202 7c80 80fe 007c 8202 1c02 827c
|
||||
000c 1424 4484 fe04 00fe 8080 7c02 827c
|
||||
007c 8280 fc82 827c 00fe 0202 0408 1010
|
||||
007c 8282 7c82 827c 007c 8282 7e02 827c
|
||||
007c 8202 7e82 827e 00fc 8282 fc82 82fc
|
||||
007c 8280 8080 827c 00fc 8282 8282 82fc
|
||||
00fe 8080 fe80 80fe 00fe 8080 f080 8080
|
||||
|
|
|
@ -1,133 +0,0 @@
|
|||
( simple Dev/File reading example )
|
||||
|
||||
( devices )
|
||||
|
||||
|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 &pixel $1 &sprite $1 ]
|
||||
|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ]
|
||||
|
||||
( variables )
|
||||
|
||||
|0000
|
||||
|
||||
( program )
|
||||
|
||||
|0100 ( -> )
|
||||
;try-load JSR2
|
||||
BRK
|
||||
|
||||
@try-load ( -- )
|
||||
( load contents from file )
|
||||
#1000 .File/length DEO2
|
||||
;filename .File/name DEO2
|
||||
;contents .File/read DEO2
|
||||
|
||||
.File/success DEI2 ORA ,&success JCN
|
||||
( failed to read: bright yellow background )
|
||||
#f0f7 .System/r DEO2
|
||||
#f0f7 .System/g DEO2
|
||||
#00f7 .System/b DEO2
|
||||
JMP2r
|
||||
|
||||
&success
|
||||
( read successful: dark blue background, show contents )
|
||||
#00f7 .System/r DEO2
|
||||
#00f7 .System/g DEO2
|
||||
#40f7 .System/b DEO2
|
||||
;contents DUP2 .File/success DEI2 ADD2 SWP2 ;draw JSR2
|
||||
JMP2r
|
||||
|
||||
@draw ( end-ptr* ptr* -- )
|
||||
EQU2k ,&end JCN
|
||||
LDAk
|
||||
DUP #0a EQU ,&linefeed JCN
|
||||
#0005 SFT2 ;font ADD2
|
||||
.Screen/addr DEO2
|
||||
#09 .Screen/sprite DEO
|
||||
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
|
||||
&next
|
||||
INC2
|
||||
,draw JMP
|
||||
|
||||
&linefeed
|
||||
POP
|
||||
#0000 .Screen/x DEO2
|
||||
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
|
||||
,&next JMP
|
||||
|
||||
&end
|
||||
POP2 POP2
|
||||
JMP2r
|
||||
|
||||
@get-x-advance ( font-char-addr* -- advance* )
|
||||
( Save two 00 bytes for later use )
|
||||
#0000 SWP2
|
||||
( First, load the eight bytes that make up the character )
|
||||
LDA2k SWP2 #0002 ADD2
|
||||
LDA2k SWP2 #0002 ADD2
|
||||
LDA2k SWP2 #0002 ADD2
|
||||
LDA2
|
||||
( OR all the bytes together, so we know which columns contain filled pixels )
|
||||
ORA2 ORA2 ORA2 ORA
|
||||
( Find the lowest set bit (using one of the 00 bytes at the top, but not consuming it) )
|
||||
SUBk AND
|
||||
( Convert the nine possible values (00-80) into an offset into the magic table (00-08). )
|
||||
( They get jumbled up with these two operations, but each possible value remains unique )
|
||||
#a3 MUL #16 DIV
|
||||
( Load the byte from the magic table, return a short (consuming/returning the 00 bytes at the top) )
|
||||
;&magic ADD2 LDA
|
||||
JMP2r
|
||||
( The magic table performs the last bit of arithmetic we want:
|
||||
* the advance in x should be one more than the number of columns with filled pixels,
|
||||
* with a maximum of 8, and
|
||||
* a minimum of 3. )
|
||||
&magic
|
||||
03 ( lowest set bit is 00, 0 columns wide )
|
||||
06 ( lowest set bit is 08, 5 columns wide )
|
||||
05 ( lowest set bit is 10, 4 columns wide )
|
||||
08 ( lowest set bit is 02, 7 columns wide )
|
||||
04 ( lowest set bit is 20, 3 columns wide )
|
||||
03 ( lowest set bit is 80, 1 column wide )
|
||||
07 ( lowest set bit is 04, 6 columns wide )
|
||||
08 ( lowest set bit is 01, 8 columns wide )
|
||||
03 ( lowest set bit is 40, 2 columns wide )
|
||||
|
||||
@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
|
||||
]
|
||||
|
||||
@filename "hello.txt 00
|
||||
@contents
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
( simple Dev/File writing example )
|
||||
|
||||
( devices )
|
||||
|
||||
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|
||||
|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ]
|
||||
|
||||
( variables )
|
||||
|
||||
|0000
|
||||
|
||||
( init )
|
||||
|
||||
|0100 ( -> )
|
||||
;try-save JSR2
|
||||
BRK
|
||||
|
||||
@try-save ( -- )
|
||||
( save contents to file )
|
||||
;contents/end ;contents SUB2 .File/length DEO2
|
||||
;filename .File/name DEO2
|
||||
;contents .File/write DEO2
|
||||
|
||||
.File/success DEI2 ORA ,&success JCN
|
||||
( failed to write: bright yellow background )
|
||||
#f0f7 .System/r DEO2
|
||||
#f0f7 .System/g DEO2
|
||||
#00f7 .System/b DEO2
|
||||
JMP2r
|
||||
|
||||
&success
|
||||
( write successful: dark blue background )
|
||||
#00f7 .System/r DEO2
|
||||
#00f7 .System/g DEO2
|
||||
#40f7 .System/b DEO2
|
||||
JMP2r
|
||||
|
||||
@filename "hello.txt 00
|
||||
@contents "Hello 20 "world, 0a "how 20 "are 20 "you? 0a
|
||||
&end
|
||||
|
|
@ -1,78 +1,92 @@
|
|||
( Dev/File )
|
||||
( File:
|
||||
Creates a temporary file called file-output.txt,
|
||||
then read it back in console, print length and delete it. )
|
||||
|
||||
%8+ { #0008 ADD2 }
|
||||
%MEMORY { #1000 }
|
||||
|
||||
( devices )
|
||||
|
||||
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|
||||
|10 @Console [ &pad $8 &write $1 ]
|
||||
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|
||||
|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ]
|
||||
|
||||
( variables )
|
||||
|
||||
|0000
|
||||
|
||||
( init )
|
||||
|a0 @File0 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|
||||
|b0 @File1 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|
||||
|
||||
|0100 ( -> )
|
||||
|
||||
( theme )
|
||||
#0efc .System/r DEO2
|
||||
#03cc .System/g DEO2
|
||||
#03ac .System/b DEO2
|
||||
|
||||
( load file )
|
||||
#1000 .File/length DEO2
|
||||
;srcpath .File/name DEO2
|
||||
MEMORY .File/read DEO2
|
||||
|
||||
.File/success DEI2 ORA ;on-success JCN2
|
||||
|
||||
;failedtxt ;print-string JSR2
|
||||
( write a file with file0 )
|
||||
;filepath-txt .File0/name DEO2
|
||||
;part1 ,append JSR
|
||||
;part2 ,append JSR
|
||||
( read a file with file1 )
|
||||
;filepath-txt .File1/name DEO2
|
||||
,stream JSR
|
||||
( delete file with file0 )
|
||||
;filepath-txt .File0/delete DEO2
|
||||
|
||||
BRK
|
||||
|
||||
@on-success ( -> )
|
||||
@append ( part* -- )
|
||||
|
||||
;successtxt ;print-string JSR2
|
||||
DUP2 ;print-str JSR2
|
||||
DUP2 ;slen JSR2 STH2k .File0/length DEO2
|
||||
.File0/write DEO2
|
||||
( print result )
|
||||
;saved-txt ;print-str JSR2
|
||||
STH2r ;print JSR2 #2018 DEO
|
||||
;bytes-txt ;print-str JSR2 #0a18 DEO
|
||||
|
||||
( draw image )
|
||||
MEMORY .Screen/addr DEO2
|
||||
#0000 #0080
|
||||
&ver
|
||||
( save ) OVR2 .Screen/y DEO2
|
||||
#0000 #0080
|
||||
&hor
|
||||
( save ) OVR2 .Screen/x DEO2
|
||||
( draw ) #81 .Screen/sprite DEO
|
||||
( incr ) .Screen/addr DEI2 #0010 ADD2 .Screen/addr DEO2
|
||||
( incr ) SWP2 8+ SWP2
|
||||
LTH2k ,&hor JCN
|
||||
POP2 POP2
|
||||
( incr ) SWP2 8+ SWP2
|
||||
LTH2k ,&ver JCN
|
||||
POP2 POP2
|
||||
JMP2r
|
||||
|
||||
( save file )
|
||||
#1000 .File/length DEO2
|
||||
;dstpath .File/name DEO2
|
||||
MEMORY .File/write DEO2
|
||||
@stream ( -- )
|
||||
|
||||
BRK
|
||||
#0001 .File1/length DEO2
|
||||
LIT2r 0000
|
||||
&stream
|
||||
;&buf DUP2 .File1/read DEO2 LDA #18 DEO INC2r
|
||||
.File1/success DEI2 #0000 NEQ2 ,&stream JCN
|
||||
( print result )
|
||||
;loaded-txt ;print-str JSR2
|
||||
STH2r ;print JSR2 #2018 DEO
|
||||
;bytes-txt ;print-str JSR2 #0a18 DEO
|
||||
|
||||
@print-string ( ptr* -- )
|
||||
LDAk DUP ,&keep-going JCN
|
||||
POP POP2 JMP2r
|
||||
JMP2r
|
||||
&buf $1
|
||||
|
||||
&keep-going
|
||||
.Console/write DEO
|
||||
INC2
|
||||
,print-string JMP
|
||||
@slen ( str* -- len* )
|
||||
|
||||
@successtxt "Success! 09 $1
|
||||
@failedtxt "Failed. 09 $1
|
||||
DUP2 ,scap JSR SWP2 SUB2
|
||||
|
||||
@srcpath "projects/pictures/ako10x10.chr $1
|
||||
@dstpath "bin/image-copy.chr $1
|
||||
JMP2r
|
||||
|
||||
@scap ( str* -- end* )
|
||||
|
||||
LDAk #00 NEQ JMP JMP2r
|
||||
&while INC2 LDAk ,&while JCN
|
||||
|
||||
JMP2r
|
||||
|
||||
@print ( short* -- )
|
||||
|
||||
&short ( short* -- ) SWP ,&byte JSR
|
||||
&byte ( byte -- ) DUP #04 SFT ,&char JSR
|
||||
&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
|
||||
|
||||
JMP2r
|
||||
|
||||
@print-str ( str* -- )
|
||||
|
||||
&while
|
||||
LDAk #18 DEO
|
||||
INC2 LDAk ,&while JCN
|
||||
POP2
|
||||
|
||||
JMP2r
|
||||
|
||||
@saved-txt "Saved 20 $1
|
||||
@loaded-txt "Loaded 20 $1
|
||||
@bytes-txt "bytes. $1
|
||||
@filepath-txt "file-output.txt $1
|
||||
|
||||
@part1
|
||||
476f 6420 6865 6c70 2074 6865 2064 7265
|
||||
616d 6572 2077 686f 7365 206d 6164 2076
|
||||
6973 696f 6e73 2073 6865 770a 00
|
||||
|
||||
@part2
|
||||
5468 6f73 6520 6465 6164 2065 7965 7320
|
||||
7365 7420 696e 2063 7279 7374 616c 2067
|
||||
756c 6673 2062 656c 6f77 210a 00
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
( Mouse )
|
||||
( Mouse:
|
||||
Paint with 3 colors with each mouse button. )
|
||||
|
||||
|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
|
||||
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
( Screen )
|
||||
( Screen:
|
||||
Draws a table of all possible sprite arrangements. )
|
||||
|
||||
|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
|
||||
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
||||
|
|
Loading…
Reference in New Issue