From 290797e785f663b395c3790ffaf820e57dd15f6d Mon Sep 17 00:00:00 2001 From: neauoire Date: Wed, 14 Dec 2022 12:27:43 -0800 Subject: [PATCH] Added day 2 --- ttc/day1.tal | 21 +++++----- ttc/day2.tal | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 10 deletions(-) create mode 100644 ttc/day2.tal diff --git a/ttc/day1.tal b/ttc/day1.tal index 9b940ad..0e12dac 100644 --- a/ttc/day1.tal +++ b/ttc/day1.tal @@ -1,5 +1,4 @@ |00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2 -|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 |0100 @@ -7,7 +6,7 @@ #23ef .System/r DEO2 #3b7f .System/g DEO2 #665f .System/b DEO2 - ;draw-tree JSR2 + ,draw-tree JSR BRK @@ -15,30 +14,32 @@ BRK #0060 .Screen/y DEO2 ( star ) - #0103 ;draw-line JSR2 - #0203 ;draw-line JSR2 - #0103 ;draw-line JSR2 + #0103 + DUP2 ,draw-line JSR + #0203 ,draw-line JSR + ,draw-line JSR ( tree ) #8000 &tree DUP #02 SFT #3f AND DUP ADD STH - DUP #0f AND STHr ADD #01 ;draw-line JSR2 + DUP #0f AND STHr ADD #01 ,draw-line JSR INC GTHk ,&tree JCN POP2 ( bark ) #1000 &bark - #0802 ;draw-line JSR2 + #0802 ,draw-line JSR INC GTHk ,&bark JCN POP2 ( ground ) - #ff01 + #ff03 @draw-line ( width color -- ) ,&c STR - #00 OVR .Screen/width DEI2 #01 SFT2 SWP2 SUB2 ,&o STR2 - #00 SWP DUP2 ADD2 INC2 #0000 + #00 SWP + DUP2 .Screen/width DEI2 #01 SFT2 SWP2 SUB2 ,&o STR2 + DUP2 ADD2 INC2 #0000 &l DUP2 [ LIT2 &o $2 ] ADD2 .Screen/x DEO2 [ LIT &c $1 ] .Screen/pixel DEO diff --git a/ttc/day2.tal b/ttc/day2.tal new file mode 100644 index 0000000..0e6554f --- /dev/null +++ b/ttc/day2.tal @@ -0,0 +1,112 @@ +|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 +|c0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 + +|0100 + + #23ef .System/r DEO2 + #3b7f .System/g DEO2 + #665f .System/b DEO2 + ,draw-tree JSR + ;prng-init JSR2 + ( prepare particles ) + .Screen/width DEI2 #0000 + &l + ( addr ) DUP2 #20 SFT2 ;snow ADD2 STH2 + ( x ) DUP2 STH2kr STA2 + ( y ) INC2r INC2r ;prng JSR2 #0100 ( mod2 ) DIV2k MUL2 SUB2 STH2r STA2 + INC2 GTH2k ,&l JCN + POP2 POP2 + ( animate ) + ;on-frame .Screen/vector DEO2 + +BRK + +@draw-tree ( -- ) + + #0060 .Screen/y DEO2 + ( star ) + #0103 + DUP2 ,draw-line JSR + #0203 ,draw-line JSR + ,draw-line JSR + ( tree ) + #8000 + &tree + DUP #02 SFT #3f AND DUP ADD STH + DUP #0f AND STHr ADD #01 ,draw-line JSR + INC GTHk ,&tree JCN + POP2 + ( bark ) + #1000 + &bark + #0802 ,draw-line JSR + INC GTHk ,&bark JCN + POP2 + ( ground ) + #ff03 + +@draw-line ( width color -- ) + + ,&c STR + #00 SWP + DUP2 .Screen/width DEI2 #01 SFT2 SWP2 SUB2 ,&o STR2 + DUP2 ADD2 INC2 #0000 + &l + DUP2 [ LIT2 &o $2 ] ADD2 .Screen/x DEO2 + [ LIT &c $1 ] .Screen/pixel DEO + INC2 GTH2k ,&l JCN + POP2 POP2 + .Screen/y DEI2k INC2 ROT DEO2 + +JMP2r + +@on-frame ( -> ) + + .Screen/width DEI2 #0000 + &l + ;prng JSR2 NIP #07 AND ,&skip JCN + DUP2 #20 SFT2 ;snow ADD2 + ( clear ) DUP2 #40 ,draw-snowflake JSR + ( y ) INC2k INC2 LDA2k INC2 #00f0 DIV2k MUL2 SUB2 SWP2 STA2 + ( draw ) #43 ,draw-snowflake JSR + &skip + INC2 GTH2k ,&l JCN + POP2 POP2 + +BRK + +@draw-snowflake ( addr* color -- ) + + ROT ROT LDA2k .Screen/x DEO2 + INC2 INC2 LDA2 .Screen/y DEO2 + .Screen/pixel DEO + +JMP2r + +@prng-init ( -- ) + + ( seed ) + #00 .DateTime/second DEI + #00 .DateTime/minute DEI #60 SFT2 EOR2 + #00 .DateTime/hour DEI #c0 SFT2 EOR2 ,prng/x STR2 + #00 .DateTime/hour DEI #04 SFT2 + #00 .DateTime/day DEI #10 SFT2 EOR2 + #00 .DateTime/month DEI #60 SFT2 EOR2 + .DateTime/year DEI2 #a0 SFT2 EOR2 ,prng/y STR2 + +JMP2r + +@prng ( -- number* ) + + LIT2 &x $2 + DUP2 #50 SFT2 EOR2 + DUP2 #03 SFT2 EOR2 + LIT2 &y $2 DUP2 ,&x STR2 + DUP2 #01 SFT2 EOR2 EOR2 + ,&y STR2k POP + +JMP2r + +@snow +