Browse code

Added beginnings of neralie.

Andrew Alderwick authored on 27/03/2021 11:23:20
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,160 @@
1
+( Prints Neralie time to console.
2
+
3
+  Formatting isn't great, but it demonstrates that
4
+  the conversion works correctly. It's a little jittery
5
+  at the beginning because the FPS calculation isn't
6
+  accurate, so in the finished program delay showing
7
+  pulses for up to the first two seconds.
8
+
9
+  When compiled to bin/boot.rom, the faketime package
10
+  allows easy testing of midnight roll-over:
11
+
12
+  faketime '23:59:42' bin/emulator bin/boot.rom
13
+)
14
+
15
+;fps { current 1 next 1 second 1 }
16
+;number { started 1 count 1 }
17
+;linee { var 2 }
18
+;neralie { n6543 2 n21 1 }
19
+
20
+|0100 ;Console { pad 8 char 1 byte 1 short 2 }
21
+|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
22
+|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
23
+|0190 ;Time { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 pad 4 get 1 }
24
+|01F0 .RESET .FRAME .ERROR ( vectors )
25
+|01F8 [ 13fd 1ef3 1bf2 ] ( palette )
26
+
27
+|0200 @RESET
28
+	#3c =fps.current
29
+	@ERROR BRK
30
+
31
+@FRAME
32
+	,update-fps JSR2
33
+	,neralie-calc JSR2
34
+	BRK
35
+
36
+	,font #00 ~number.count #08 MUL ADD2 =Sprite.addr
37
+	#02 =Sprite.color
38
+	#0000 #00 ~number.count DUP2 ,h JSR2
39
+	~number.count #01 ADD =number.count
40
+
41
+@neralie-calc
42
+	( add up fractions of a pulse )
43
+	#0120 #00 ~Time.hour MUL2
44
+	#00c0 #00 ~Time.minute MUL2 ADD2
45
+	#00f8 #00 ~Time.second MUL2 ADD2
46
+	#0271 #00 ~fps.next MUL2 #00 ~fps.current DIV2 #0008 MUL2 ADD2
47
+	#01b0 DIV2
48
+
49
+	( add up units and tens of pulses )
50
+	#0042 #00 ~Time.hour MUL2 ADD2
51
+	#005e #00 ~Time.minute MUL2 ADD2
52
+	#000b #00 ~Time.second MUL2 ADD2
53
+	DUP2 #0064 DIV2 DUP2 STH2 #0064 MUL2 SUB2 =neralie.n21 POP
54
+
55
+	( add up hundreds of pulses + 10 x beats )
56
+	STH2r
57
+	#01a0 #00 ~Time.hour MUL2 ADD2
58
+	#0006 #00 ~Time.minute MUL2 ADD2 =neralie.n6543
59
+
60
+	~neralie.n6543 ,print-short-decimal JSR2
61
+	#20 =Console.char
62
+	~neralie.n21 ,print-byte-decimal JSR2
63
+	#0a =Console.char
64
+	JMP2r
65
+
66
+@h ( x1₂ x2₂ y₂ -- )
67
+	=Screen.y
68
+	,Screen.x =linee.var
69
+	^line JMP
70
+
71
+@v ( y1₂ y2₂ x₂ -- )
72
+	=Screen.x
73
+	,Screen.y =linee.var
74
+	( ^line JMP is redundant )
75
+
76
+@line ( v1₂ v2₂ -- )
77
+	OVR2 OVR2 LTH2 #01 JNZ SWP2
78
+	STH2
79
+
80
+	$loop
81
+	DUP2 DUP2r STH2r GTH2 ^$end JNZ
82
+	DUP2 ~linee.var STR2
83
+	#03 =Screen.color
84
+	#0001 ADD2
85
+	^$loop JMP
86
+
87
+	$end
88
+	POP2 POP2r
89
+	JMP2r
90
+
91
+@update-fps
92
+	#00 =Time.get
93
+	~fps.next #01 ADD =fps.next
94
+	~Time.second ~fps.second NEQ JMP JMP2r
95
+	~Time.second =fps.second
96
+	~fps.next =fps.current
97
+
98
+	~fps.next ^print-byte-decimal JSR
99
+	,strings-fps ^print-string JSR
100
+
101
+	#00 =fps.next
102
+	JMP2r
103
+
104
+@print-byte-decimal ( byte₁ -- )
105
+	#00 =number.started
106
+	DUP #64 DIV DUP ^$digit JSR #64 MUL SUB
107
+	DUP #0a DIV DUP ^$digit JSR #0a MUL SUB
108
+	^$digit JSR
109
+	~number.started ^$end JNZ
110
+	#30 =Console.char
111
+	$end JMP2r
112
+
113
+	$digit
114
+	OVR ~number.started ORA #02 JNZ
115
+	POP JMP2r
116
+	#30 ADD =Console.char
117
+	#01 =number.started
118
+	JMP2r
119
+
120
+@print-string ( string₂ -- )
121
+	DUP2 PEK2 DUP ^$not-end JNZ
122
+
123
+	$end
124
+	POP POP2 JMP2r
125
+
126
+	$not-end
127
+	=Console.char
128
+	#0001 ADD2 ^print-string JMP
129
+
130
+@print-short-decimal ( short₂ -- )
131
+	#00 =number.started
132
+	DUP2 #2710 DIV2 DUP2 ^$digit JSR #2710 MUL2 SUB2
133
+	DUP2 #03e8 DIV2 DUP2 ^$digit JSR #03e8 MUL2 SUB2
134
+	DUP2 #0064 DIV2 DUP2 ^$digit JSR #0064 MUL2 SUB2
135
+	DUP2 #000a DIV2 DUP2 ^$digit JSR #000a MUL2 SUB2
136
+	^$digit JSR
137
+	~number.started ^$end JNZ
138
+	#30 =Console.char
139
+	$end JMP2r
140
+
141
+	$digit
142
+	SWP POP
143
+	OVR ~number.started ORA #02 JNZ
144
+	POP JMP2r
145
+	#30 ADD =Console.char
146
+	#01 =number.started
147
+	JMP2r
148
+
149
+@strings
150
+	$fps [ 20 fps 0a 00 ]
151
+
152
+@font
153
+[
154
+	003c 464a 5262 3c00 0018 0808 0808 1c00
155
+	003c 4202 3c40 7e00 003c 421c 0242 3c00
156
+	000c 1424 447e 0400 007e 407c 0242 3c00
157
+	003c 407c 4242 3c00 007e 0204 0810 1000
158
+	003c 423c 4242 3c00 003c 4242 3e02 3c00
159
+]
160
+