# aoc1-1.tal -rw-r--r-- 1.6 KiB View raw
                                                                                
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
( uxnasm day1.tal day1.rom && uxncli day1.rom )

%+  { ADD } %-   { SUB }              %/   { DIV }  
%<  { LTH } %>   { GTH }  %=  { EQU } %!   { NEQ } 
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } 
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } 

%RTN { JMP2r }
%HALT { #0101 #0e DEO2 }
%DEBUG2 { SWP ;print-hex JSR2 ;print-hex JSR2 }

|00 @System     [ &vector $2 &wst      $1 &rst    $1 &pad   $4 &r      $2 &g      $2 &b    $2 &debug  $1 &halt $1 ]
|a0 @File       [ &vector $2 &success  $2 &stat   $2 &delete $1 &append $1 &name  $2 &length $2 &read $2 &write $2 ]

|0000

@value
	&length $1
	&string $5
@last $2
@count $2

|0100 @on-reset

	;filepath .File/name DEO2
	#0001 .File/length DEO2
	#ffff .last STZ2

	&stream
		;&char .File/read DEO2
		;&char LDA #0a ! ,&no-end JCN
			#00 ,&push JSR
			( eval )
			;value/string ;sdec JSR2 
				( incr ) DUP2 .last LDZ2 GTH2 #00 SWP .count LDZ2 ++ .count STZ2
				( save ) .last STZ2 
			#00 .value/length STZ
			,&continue JMP
			&no-end
		( append ) ;&char LDA ,&push JSR
		( incr ) .value/length LDZk INC SWP STZ
		&continue
		.File/success DEI2 #0000 !! ,&stream JCN
	.count LDZ2 #0001 -- DEBUG2
	HALT

BRK
	&char $1
	&push ( char -- ) .value/length LDZ .value/string + STZ RTN

( decimal string to hex number )

@sdec ( addr* -- hex* )

	( res ) LIT2r 0000
	&while
		LDAk #30 - #00 SWP
		STH2r #000a ** ++ STH2
		INC2 LDAk ,&while JCN
	POP2
	( res ) STH2r

RTN

@print-hex ( value -- )
	
	STHk #04 SFT ,&parse JSR #18 DEO
	STHr #0f AND ,&parse JSR #18 DEO
	RTN
	&parse ( value -- char )
		DUP #09 GTH ,&above JCN #30 ADD RTN &above #09 SUB #60 ADD RTN

RTN

@filepath "day1.txt $1