-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday15.tal
96 lines (76 loc) · 1.88 KB
/
day15.tal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
~library/macros.tal
~library/devices.tal
( variables )
|0000
( init )
|0100 @program
;on-arg-char .Console/vector DEO2
BRK !
@on-arg-char
.Console/read DEI ( char )
DUP #0a EQU ,&complete JCN
;argv #00 ,&argptr LDR ADD2 STA
,&argptr LDR INC ,&argptr STR
BRK !
&complete
POP
;arg-received JMP2
&argptr $1
@argv $20
( arg is in @argv )
@arg-received
LIT ': EMIT
;argv ;print JSR2
LF
;open-file JSR2
P< "risk_matrix_size= >P ;risk-matrix/_risks_end ;risk-matrix/_risks SUB2 DBGSHORTDEC POP2
P< "visited_size= >P ;cost-matrix/_visited_end ;cost-matrix/_visited SUB2 DBGSHORTDEC POP2
P< "costs_size= >P ;cost-matrix/_costlist_end ;cost-matrix/_costlist SUB2 DBGSHORTDEC POP2
;read-byte ;risk-matrix/parse JSR2
#0005 [ ;cost-matrix/scale STA2 ]
;cost-matrix/init JSR2
;flood-all JSR2
;cost-matrix/get-end-cost JSR2 DBGSHORTDEC POP2
BRK
[ ]
( -- )
@flood-all
#0000 #0000 #0000 ;cost-matrix/set-at JSR2
#0000 #2000 DO
( DBGSHORTDECn SP ;&count JSR2 DBGSHORTDEC POP2 )
DUP2 ;cost-matrix/flood-matching JSR2
;cost-matrix/is-end-visited JSR2
NOT ,&flood-all/not-done JCN
UNLOOP
;cost-matrix/dump JSR2
RTN
&flood-all/not-done
DUP2 #0100 MOD2 #0000 NEQ2 ,&no-render JCN
;dump-visited JSR2
&no-render
( ;cost-matrix/dump JSR2 )
LOOP
RTN
( -- )
@dump-visited
[ ;cost-matrix/_w LDA2 ] DBGSHORTDECn SP POP2
[ ;cost-matrix/_h LDA2 ] DBGSHORTDEC POP2
#0000 [ ;cost-matrix/_h LDA2 ] DO
#0000 [ ;cost-matrix/_w LDA2 ] DO
DUP4 SWP2 ;cost-matrix/get-visited JSR2
LIT '0 ADD EMIT
LOOP
LF
LOOP
RTN
@open-file
;argv .File/name DEO2
#0001 .File/length DEO2
RTN
( -- next-byte )
@read-byte
#00 ;&byte STA ( clear byte so that EOF reads as zero )
;&byte .File/read DEO2
LIT &byte 00 ( <- this byte is patched by the two previous instructions! )
RTN
~day15_lib.tal