( Boing ) %G { #0001 } %BALL-HEIGHT { #0008 } %DEBUG { #ab .System/debug DEO } %PRINT2 { .Console/write DEO } %SHORT2BYTE { SWP POP } |00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1 |10 @Console &vector $2 &read $1 &pad $5 &write $1 |20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |0000 @ball &x $2 &y $2 &vx $2 &vy $2 @timer $1 @frame $1 |0100 @reset ( vectors ) ;on-frame .Screen/vector DEO2 ( theme ) #aff0 .System/r DEO2 #af00 .System/g DEO2 #af00 .System/b DEO2 ( screen size ) #0140 .Screen/width DEO2 #0100 .Screen/height DEO2 ( inital position ) #0020 .ball/x STZ2 #0002 .ball/vx STZ2 #0020 .ball/y STZ2 #0000 .ball/vy STZ2 ;draw-background JSR2 BRK @on-frame ( -> ) ( every 4th frame ) .timer LDZ INC .timer STZk POP #03 EQU JMP [ BRK ] ( reset timer ) #00 .timer STZ ( 12 frames animation ) .frame LDZ INC DUP #0c NEQ MUL .frame STZ ;move-ball JSR2 BRK @move-ball ( -- ) ;draw-background JSR2 ( .ball/vy LDZ2 PRINT2 ) ;clear-ball JSR2 .ball/x LDZ2k .ball/vx LDZ2 ADD2 ;check-flip-vx JSR2 ROT STZ2 .ball/vy LDZ2k G ADD2 STH2k ROT STZ2 .ball/y LDZ2k STH2r ADD2 ;check-flip-vy JSR2 ROT STZ2 ;draw-ball JSR2 JMP2r @check-flip-vy ( y -- y ) DUP2 BALL-HEIGHT ADD2 .Screen/height DEI2 BALL-HEIGHT SUB2 GTH2 ,&flip JCN ,&else JMP &flip .ball/vy LDZ2k #ffff EOR2 ( INC2 ) ROT STZ2 &else JMP2r @check-flip-vx ( x -- x ) DUP2 BALL-HEIGHT ADD2 .Screen/width DEI2 BALL-HEIGHT SUB2 GTH2 ,&flip JCN ,&else JMP &flip #fffe .ball/vx STZ2 &else JMP2r @draw-ball ( -- ) .ball/x LDZ2 .Screen/x DEO2 .ball/y LDZ2 .Screen/y DEO2 ;img .Screen/addr DEO2 #4f .Screen/sprite DEO JMP2r @clear-ball ( -- ) .ball/x LDZ2 .Screen/x DEO2 .ball/y LDZ2 .Screen/y DEO2 #40 .Screen/sprite DEO JMP2r @draw-background ( -- ) ( hor lines ) #01 .Screen/auto DEO ;hor-icn .Screen/addr DEO2 .Screen/height DEI2 #04 SFT2 NIP #04 SUB #00 &ver #0020 .Screen/x DEO2 #00 OVR #40 SFT2 #0020 ADD2 .Screen/y DEO2 .Screen/width DEI2 #03 SFT2 NIP #08 SUB #00 &hor #0f .Screen/sprite DEO INC GTHk ,&hor JCN POP2 INC GTHk ,&ver JCN POP2 ( ver lines ) #02 .Screen/auto DEO ;ver-icn .Screen/addr DEO2 .Screen/width DEI2 #04 SFT2 NIP #03 SUB #00 &ver2 #0027 .Screen/y DEO2 #00 OVR #40 SFT2 #0019 ADD2 .Screen/x DEO2 .Screen/height DEI2 #03 SFT2 NIP #0a SUB #00 &hor2 #0f .Screen/sprite DEO INC GTHk ,&hor2 JCN POP2 INC GTHk ,&ver2 JCN POP2 JMP2r @hor-icn 0000 0000 0000 00ff @ver-icn 0101 0101 0101 0101 @img ffff ffff ffff ffff