Browse code

Finished first draft of neralie.

Andrew Alderwick authored on 28/03/2021 10:51:37
Showing 1 changed files
... ...
@@ -1,23 +1,15 @@
1
-( Prints Neralie time to console.
1
+(
2
+	app/neralie : clock with arvelie date
2 3
 
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
4
+	TODO
5
+		- Implement higher resolution time rather than counting fps
13 6
 )
14 7
 
15
-%HCF { #0000 DIV }
16
-
17 8
 ;fps { current 1 next 1 second 1 }
18 9
 ;number { started 1 count 1 }
19 10
 ;lines { x1 2 x2 2 y1 2 y2 2 addr 2 }
20
-;neralie { n6543 2 n21 1 }
11
+;neralie { n0123 2 n4 1 n5 1 n6 1 n7 1 n8 1 n9 1 color 1 x 2 y 2 w 2 h 2 }
12
+;mul { ahi 1 alo 1 bhi 1 blo 1 }
21 13
 
22 14
 |0100 ;Console { pad 8 char 1 byte 1 short 2 }
23 15
 |0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
... ...
@@ -27,14 +19,15 @@
27 19
 |01F8 [ 13fd 1ef3 1bf2 ] ( palette )
28 20
 
29 21
 |0200 @RESET
30
-	#3c =fps.current
22
+	#01 =fps.current
31 23
 
32
-	#000b
24
+	#000c
33 25
 	DUP2 =lines.x1
34 26
 	DUP2 =lines.y1
35
-	DUP2 ~Screen.width SWP2 SUB2 =lines.x2
27
+	DUP2 ~Screen.width SWP2 SUB2 #0001 SUB2 =lines.x2
36 28
 	     ~Screen.height SWP2 SUB2 =lines.y2
37 29
 
30
+	#02 =neralie.color
38 31
 	~lines.x1 ~lines.x2
39 32
 	OVR2 OVR2 ~lines.y1 ,h JSR2
40 33
 	          ~lines.y2 ,h JSR2
... ...
@@ -46,9 +39,13 @@
46 39
 
47 40
 @FRAME
48 41
 	,update-fps JSR2
42
+	#00 =neralie.color
43
+	,neralie-lines JSR2
49 44
 	,neralie-calc JSR2
45
+	#02 =neralie.color
50 46
 	,arvelie-text JSR2
51 47
 	,neralie-text JSR2
48
+	,neralie-lines JSR2
52 49
 	BRK
53 50
 
54 51
 	#02 =Sprite.color
... ...
@@ -56,23 +53,23 @@
56 53
 	~number.count #01 ADD =number.count
57 54
 
58 55
 @neralie-calc ( -- )
59
-	( add up fractions of a pulse )
56
+	( add up fractions of a pulse, store tenths in n6 )
60 57
 	#0120 #00 ~DateTime.hour MUL2
61 58
 	#00c0 #00 ~DateTime.minute MUL2 ADD2
62 59
 	#00f8 #00 ~DateTime.second MUL2 ADD2
63 60
 	#0271 #00 ~fps.next MUL2 #00 ~fps.current DIV2 #0008 MUL2 ADD2
64
-	#01b0 DIV2
61
+	#01b0 ,modf JSR2 SWP2 #0017 MUL2 #03e8 DIV2 =neralie.n6 POP
65 62
 
66
-	( add up units and tens of pulses )
63
+	( add up units and tens of pulses, store in n5 and n4 )
67 64
 	#0042 #00 ~DateTime.hour MUL2 ADD2
68 65
 	#005e #00 ~DateTime.minute MUL2 ADD2
69 66
 	#000b #00 ~DateTime.second MUL2 ADD2
70
-	DUP2 #0064 DIV2 DUP2 STH2 #0064 MUL2 SUB2 =neralie.n21 POP
67
+	#000a ,modf JSR2 SWP2 =neralie.n5 POP
68
+	#000a ,modf JSR2 SWP2 =neralie.n4 POP
71 69
 
72
-	( add up hundreds of pulses + 10 x beats )
73
-	STH2r
70
+	( add up hundreds of pulses + 10 x beats, store in n0123 )
74 71
 	#01a0 #00 ~DateTime.hour MUL2 ADD2
75
-	#0006 #00 ~DateTime.minute MUL2 ADD2 =neralie.n6543
72
+	#0006 #00 ~DateTime.minute MUL2 ADD2 =neralie.n0123
76 73
 
77 74
 	JMP2r
78 75
 
... ...
@@ -90,15 +87,14 @@
90 87
 
91 88
 @neralie-text ( -- )
92 89
 	~Screen.width #0002 DIV2 #0004 SUB2 =Sprite.x
93
-	~neralie.n6543
90
+	~neralie.n0123
94 91
 	#03e8 ,modf JSR2 ^digit JSR
95 92
 	#0064 ,modf JSR2 ^digit JSR
96 93
 	#000a ,modf JSR2 ^digit JSR
97
-	           #000a ^digit JSR ( the colon )
98
-	                 ^digit JSR
99
-	#00 ~neralie.n21
100
-	#000a ,modf JSR2 ^digit JSR
94
+	           #000b ^digit JSR ( the colon )
101 95
 	                 ^digit JSR
96
+	#00 ~neralie.n4  ^digit JSR
97
+	#00 ~neralie.n5  ^digit JSR
102 98
 	JMP2r
103 99
 
104 100
 @letter ( index* -- )
... ...
@@ -108,33 +104,82 @@
108 104
 @digit ( index* -- )
109 105
 	#0008 MUL2 ,font-numbers ADD2 =Sprite.addr
110 106
 	$middle
111
-	#02 =Sprite.color
107
+	~neralie.color =Sprite.color
112 108
 	~Sprite.x #0008 ADD2 =Sprite.x
113 109
 	JMP2r
114 110
 
111
+@neralie-lines ( -- )
112
+	~lines.x2 ~lines.x1 DUP2 =neralie.x SUB2 =neralie.w
113
+	~lines.y2 ~lines.y1 DUP2 =neralie.y SUB2 =neralie.h
114
+
115
+	,neralie.n4 SWP POP ~neralie.n0123
116
+	DUP2 ,$h JSR2
117
+	,$next JSR2 #0001 =Sprite.x ~neralie.y #0003 SUB2 =Sprite.y ^digit JSR
118
+	DUP2 ,$v JSR2
119
+	#04 ,v-spacing POK2
120
+	~lines.y1 #0003 SUB2 ~neralie.y ~neralie.x ,v JSR2
121
+	#01 ,v-spacing POK2
122
+	^$next JSR #0001 =Sprite.y ~neralie.x #0003 SUB2 =Sprite.x ,digit JSR2
123
+	DUP2 ^$h JSR
124
+	^$next JSR ~Screen.width #0009 SUB2 =Sprite.x ~neralie.y #0003 SUB2 =Sprite.y ,digit JSR2
125
+	DUP2 ^$v JSR
126
+	^$next JSR POP2
127
+	DUP2 ^$h JSR
128
+	^$next JSR POP2
129
+	DUP2 ^$v JSR
130
+	POP2 POP
131
+	JMP2r
132
+
133
+	$next ( digit-addr number* -- next-digit-addr next-number* prev-digit* )
134
+	#03e8 ,modf JSR2 STH2 #000a MUL2
135
+	ROT DUP STH #01 ADD ROT ROT
136
+	#00 STHr PEK ADD2
137
+	STH2r
138
+	JMP2r
139
+
140
+	$h ( number* -- )
141
+	^scale JSR
142
+	~neralie.h ,mul2hi JSR2
143
+	DUP2 #0000 NEQ2 #02 JNZ POP2 JMP2r
144
+	DUP2 ~neralie.y ADD2 =neralie.y
145
+	~neralie.h SWP2 SUB2 =neralie.h
146
+	~neralie.x DUP2 ~neralie.w ADD2 ~neralie.y ^h JMP
147
+
148
+	$v ( number* -- )
149
+	^scale JSR
150
+	~neralie.w ,mul2hi JSR2
151
+	DUP2 #0000 NEQ2 #02 JNZ POP2 JMP2r
152
+	DUP2 ~neralie.x ADD2 =neralie.x
153
+	~neralie.w SWP2 SUB2 =neralie.w
154
+	~neralie.y DUP2 ~neralie.h ADD2 ~neralie.x ^v JMP
155
+
156
+@scale ( 0..10000* -- 0..65535* )
157
+	DUP2 #8db8 ,mul2hi JSR2
158
+	SWP2 #0006 MUL2 ADD2
159
+	JMP2r
115 160
 
116 161
 @h ( x1* x2* y* -- )
117 162
 	=Screen.y
118 163
 	,Screen.x =lines.addr
119
-	^draw-line JMP
164
+	^v-draw-line JMP
120 165
 
121 166
 @v ( y1* y2* x* -- )
122 167
 	=Screen.x
123 168
 	,Screen.y =lines.addr
124 169
 
125
-@draw-line ( v1* v2* -- )
170
+	$draw-line ( v1* v2* -- )
126 171
 	OVR2 OVR2 LTH2 #01 JNZ SWP2
127 172
 	STH2
128 173
 
129 174
 	$loop
130
-	#0001 ADD2
175
+	LIT2 [ 00 ] $spacing [ 01 ] ADD2
131 176
 	DUP2 DUP2r STH2r LTH2 ^$keep-going JNZ
132 177
 	POP2 POP2r
133 178
 	JMP2r
134 179
 
135 180
 	$keep-going
136 181
 	DUP2 ~lines.addr STR2
137
-	#02 =Screen.color
182
+	~neralie.color =Screen.color
138 183
 	^$loop JMP
139 184
 
140 185
 @update-fps ( -- )
... ...
@@ -144,16 +189,14 @@
144 189
 	~DateTime.second =fps.second
145 190
 	~fps.next =fps.current
146 191
 
147
-	~fps.next ^print-byte-decimal JSR
148
-	,strings-fps ^print-string JSR
192
+	( ~fps.next ^print-byte-decimal JSR
193
+	,strings-fps ^print-string JSR )
149 194
 
150 195
 	#00 =fps.next
151 196
 	JMP2r
152 197
 
153 198
 @print-string ( string* -- )
154 199
 	DUP2 PEK2 DUP ^$not-end JNZ
155
-
156
-	$end
157 200
 	POP POP2 JMP2r
158 201
 
159 202
 	$not-end
... ...
@@ -188,6 +231,42 @@
188 231
 @modf ( dividend* divisor* -- remainder* quotient* )
189 232
 	OVR2 OVR2 DIV2 DUP2 STH2 MUL2 SUB2 STH2r JMP2r
190 233
 
234
+@mul2hi ( a* b* -- product-top-16-bits* )
235
+	(
236
+		Multiplying two 16-bit numbers yields a 32-bit number.
237
+		MUL2 returns the lowest 16 bits, we want the highest.
238
+
239
+		We split each short into hi and lo bytes, then sum
240
+		the following multiplications:
241
+
242
+		31..24 23..16 15..08 07..00
243
+		{ ahi * bhi }
244
+		       { alo * bhi }
245
+		       { ahi * blo }
246
+		              { alo * blo }
247
+
248
+		Bits 07..00 can be ignored, but each sum in bits 23..16
249
+		can end up overflowing into bit 24.
250
+	)
251
+	,mul.bhi STR2 ,mul.ahi STR2
252
+	#00
253
+		#00
254
+			#00 ~mul.alo #00 ~mul.blo MUL2
255
+		POP
256
+		#00 ~mul.ahi #00 ~mul.blo MUL2 ^$adc JSR
257
+		#00 ~mul.alo #00 ~mul.bhi MUL2 ^$adc JSR
258
+	POP
259
+	#00 ~mul.ahi #00 ~mul.bhi MUL2 ADD2
260
+	JMP2r
261
+
262
+	$adc ( 31..24 a* b* -- 31..24 sum* )
263
+	OVR2 ADD2 SWP2 OVR2
264
+	GTH2 ^$carry JNZ
265
+	JMP2r
266
+	$carry
267
+	ROT #01 ADD ROT ROT
268
+	JMP2r
269
+
191 270
 @strings
192 271
 	$fps [ 20 fps 0a 00 ]
193 272
 
... ...
@@ -196,7 +275,7 @@
196 275
 	7cc6 ced6 e6c6 7c00 1838 1818 1818 7e00 3c66 063c 6066 7e00
197 276
 	3c66 061c 0666 3c00 1c3c 6ccc fe0c 1e00 7e62 607c 0666 3c00
198 277
 	3c66 607c 6666 3c00 7e66 060c 1818 1800 3c66 663c 6666 3c00
199
-	3c66 663e 0666 3c00 0018 1800 1818 0000
278
+	3c66 663e 0666 3c00 7cc6 ced6 e6c6 7c00 0018 1800 1818 0000
200 279
 ]
201 280
 
202 281
 @font-letters