uxneria/sketches/nibble.tal

225 lines
5.3 KiB
Tal

( a blank file )
%+ { ADD } %- { SUB } %* { MUL } %/ { DIV }
%< { LTH } %> { GTH } %= { EQU } %! { NEQ }
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
%DEBUG { ;print-hex JSR2 #0a .Console/write DEO }
%DEBUG2 { SWP ;print-hex JSR2 ;print-hex JSR2 #0a .Console/write DEO }
%RTN { JMP2r }
( devices )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 ]
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|40 @Audio1 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|50 @Audio2 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|60 @Audio3 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|70 @Midi [ &vector $2 &channel $1 &note $1 &velocity $1 ]
|80 @Controller [ &vector $2 &button $1 &key $1 ]
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ]
|a0 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ]
|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
( constants )
%die-color { #53 }
%die-color-tl { #53 } ( top left )
%die-color-tr { #53 } ( top left )
( variables )
|0000
@frame-count $1
( program )
|0100 ( -> )
( theme )
#1fe6 .System/r DEO2
#1ec4 .System/g DEO2
#1e24 .System/b DEO2
#00 .frame-count STZ
#0020 #0020 #01
;draw-nibble-die JSR2
#0030 #0020 #02
;draw-nibble-die JSR2
#0040 #0020 #03
;draw-nibble-die JSR2
#0010 #0030 #04
;draw-nibble-die JSR2
#0020 #0030 #05
;draw-nibble-die JSR2
#0030 #0030 #06
;draw-nibble-die JSR2
#0040 #0030 #07
;draw-nibble-die JSR2
#0010 #0040 #08
;draw-nibble-die JSR2
#0020 #0040 #09
;draw-nibble-die JSR2
#0030 #0040 #0a
;draw-nibble-die JSR2
#0040 #0040 #0b
;draw-nibble-die JSR2
#0010 #0050 #0c
;draw-nibble-die JSR2
#0020 #0050 #0d
;draw-nibble-die JSR2
#0030 #0050 #0e
;draw-nibble-die JSR2
#0040 #0050 #0f
;draw-nibble-die JSR2
#0010 #0060 #ff
;draw-byte JSR2
;on-frame .Screen/vector DEO2
BRK
@on-frame
#0010 #0020
.frame-count LDZ
#01 ADD DUP
.frame-count STZ
#f0 AND #04 SFT
;draw-nibble-die JSR2
( #00 SWP #0008 MUL2 ;nibble-dice0 ADD2 .Screen/addr DEO2 )
( #37 .Screen/color DEO )
BRK
@draw-byte ( x2 y2 byte -- )
STH ( stash byte )
OVR2 OVR2 ( duplicate coordinates )
STHr DUP STH ( restore, duplicate, stash byte )
#04 SFT #0f AND ( get high nibble )
;draw-nibble-die JSR2 ( draw high nibble )
SWP2 #0010 ADD2 SWP2 ( increment x )
STHr ( restore byte )
#0f AND ( get low nibble )
;draw-nibble-die JSR2 ( draw low nibble )
RTN
@draw-nibble-die ( x2 y2 num -- )
( bit 3 )
STH
.Screen/y DEO2
.Screen/x DEO2
STHr DUP STH
#03 SFT #01 AND ,&bit-3-on JCN
&bit-3-off
;nibble-dice-empty .Screen/addr DEO2
,&bit-3-draw JMP
&bit-3-on
;nibble-dice-dot .Screen/addr DEO2
&bit-3-draw
die-color .Screen/color DEO
( bit 2 )
STHr DUP STH
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 ( increment x )
#02 SFT #01 AND ,&bit-2-on JCN
&bit-2-off
;nibble-dice-empty #0010 ADD2 .Screen/addr DEO2
,&bit-2-draw JMP
&bit-2-on
;nibble-dice-dot #0010 ADD2 .Screen/addr DEO2
&bit-2-draw
die-color .Screen/color DEO
( bit 0 )
STHr DUP STH
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 ( increment y )
#01 AND ,&bit-0-on JCN
&bit-0-off
;nibble-dice-empty #0030 ADD2 .Screen/addr DEO2
,&bit-0-draw JMP
&bit-0-on
;nibble-dice-dot #0030 ADD2 .Screen/addr DEO2
&bit-0-draw
die-color .Screen/color DEO
( bit 1 )
STHr
.Screen/x DEI2 #0008 SUB2 .Screen/x DEO2 ( decrement x )
#01 SFT #01 AND ,&bit-1-on JCN
&bit-1-off
;nibble-dice-empty #0020 ADD2 .Screen/addr DEO2
,&bit-1-draw JMP
&bit-1-on
;nibble-dice-dot #0020 ADD2 .Screen/addr DEO2
&bit-1-draw
die-color .Screen/color DEO
RTN
@draw-nibble-die-1bpp ( x2 y2 num -- )
#0f AND #00 SWP #0008 MUL2 ;nibble-dice0 ADD2 .Screen/addr DEO2
.Screen/y DEO2
.Screen/x DEO2
#37 .Screen/color DEO
RTN
@nibble-dice0
0000 0000 0000 0000
0000 0000 0006 0600
0000 0000 0060 6000
0000 0000 0066 6600
0006 0600 0000 0000
0006 0600 0006 0600
0006 0600 0060 6000
0006 0600 0066 6600
0060 6000 0000 0000
0060 6000 0006 0600
0060 6000 0060 6000
0060 6000 0066 6600
0066 6600 0000 0000
0066 6600 0006 0600
0066 6600 0060 6000
0066 6600 0066 6600
@nibble-dice-empty ( top left, top right, bottom left, bottom right )
00 1f 3f 7f 7f 7f 7f 7f 00 1f 3f 7f 7f 7f 7f 7f
00 f8 fc fe fe fe fe fe 00 f8 fc fe fe fe fe fe
7f 7f 7f 7f 7f 3f 1f 00 7f 7f 7f 7f 7f 3f 1f 00
fe fe fe fe fe fc f8 00 fe fe fe fe fe fc f8 00
@nibble-dice-dot ( top left, top right, bottom left, bottom right )
00 1f 3f 7f 7f 7f 7f 7f 00 1f 3f 73 61 61 73 7f
00 f8 fc fe fe fe fe fe 00 f8 fc ce 86 86 ce fe
7f 7f 7f 7f 7f 3f 1f 00 7f 73 61 61 73 3f 1f 00
fe fe fe fe fe fc f8 00 fe ce 86 86 ce fc f8 00