Browse code

Implemented writing to output file

Andrew Alderwick authored on 15/05/2021 20:02:33
Showing 1 changed files
... ...
@@ -10,7 +10,6 @@
10 10
 	BRK
11 11
 
12 12
 	&source-file
13
-		"test.usm 00
14 13
 		"projects/demos/piano.usm 00
15 14
 	&dest-file
16 15
 		"bin/asma-boot.rom 00
... ...
@@ -40,10 +39,12 @@
40 39
 	;asma/dest-filename STA2 ;asma/src-filename STA2
41 40
 
42 41
 	;asma-init-first-pass JSR2
42
+	;asma-flush-ignore ;asma/flush-fn STA2
43 43
 	;asma/src-filename LDA2 ;asma-assemble-file-pass JSR2
44 44
 	asma-IF-ERROR ,&error JCN
45 45
 
46 46
 	;asma-init-next-pass JSR2
47
+	;asma-flush-to-file ;asma/flush-fn STA2
47 48
 	;asma/src-filename LDA2 ;asma-assemble-file-pass JSR2
48 49
 	asma-IF-ERROR ,&error JCN
49 50
 
... ...
@@ -142,19 +143,24 @@
142 143
 
143 144
 @asma-init-first-pass ( -- )
144 145
 	#ff ;asma/pass STA
145
-	#0000 ;asma/error STA2
146
+	#0000 DUP2k
147
+		;asma/error STA2
148
+		;asma-trees/labels STA2
149
+		;asma-trees/macros STA2
146 150
 	;asma-heap ;asma/heap STA2
147
-	#0000 ;asma-trees/labels STA2
148 151
 	;asma-opcodes/_entry ;asma-trees/opcodes STA2
149
-	#0000 ;asma-trees/macros STA2
150 152
 	( fall through )
151 153
 
152 154
 @asma-init-next-pass ( -- )
153 155
 	;asma/pass LDA #01 ADD ;asma/pass STA
154
-	#00 ;asma/state STA
155
-	#0000 ;asma/addr STA2
156
-	#0100 ;asma/written-addr STA2
157
-	#0001 ;asma/line STA2
156
+	;asma-write-buffer ;asma-output/ptr STA2
157
+	#0000 DUP2k
158
+		;asma-output/offset STA2
159
+		;asma/addr STA2
160
+		;asma/state STA
161
+	#01 ( 0001 )
162
+	SWPk ( 0001 0100 ) ;asma/written-addr STA2
163
+	;asma/line STA2
158 164
 	JMP2r
159 165
 
160 166
 (
... ...
@@ -167,8 +173,8 @@
167 173
 	&loop
168 174
 	OVR2 .File/name DEO2
169 175
 	DUP2 .File/offset DEO2
170
-	#0023 STH2k .File/length DEO2
171
-	#f000 DUP2k .File/load DEO2
176
+	;asma-read-buffer/end ;asma-read-buffer SUB2 STH2k .File/length DEO2
177
+	;asma-read-buffer DUP2k .File/load DEO2
172 178
 	.File/success DEI2
173 179
 	DUP2 STH2r SUB2 ORA ,&last-one JCN
174 180
 	,asma-assemble-chunk JSR asma-IF-ERROR ,&error JCN
... ...
@@ -179,6 +185,10 @@
179 185
 	ADD2k #00 ROT ROT STA
180 186
 	#0001 ADD2
181 187
 	,asma-assemble-chunk JSR asma-IF-ERROR ,&error JCN
188
+
189
+	( flush output buffer )
190
+	;asma-output/ptr LDA2 ;asma-write-buffer SUB2 ;asma/flush-fn LDA2 JSR2
191
+
182 192
 	POP2
183 193
 	&error
184 194
 	POP2 POP2 POP2
... ...
@@ -386,6 +396,11 @@
386 396
 	POP2 #01
387 397
 	JMP2r
388 398
 
399
+@asma-write-short ( short -- )
400
+	SWP
401
+	,asma-write-byte JSR
402
+	,asma-write-byte JMP ( tail call )
403
+
389 404
 @asma-write-byte ( byte -- )
390 405
 	;asma/addr LDA2 ;asma/written-addr LDA2
391 406
 	LTH2k ,&rewound JCN
... ...
@@ -395,26 +410,46 @@
395 410
 	#0001 ADD2
396 411
 	,&loop JMP
397 412
 
413
+	&rewound
414
+	;asma-msg-rewound ;asma/error STA2
415
+	POP2 POP2 POP JMP2r
416
+
398 417
 	&ready
399 418
 	POP2 #0001 ADD2
400 419
 	DUP2 ;asma/addr STA2
401 420
 	;asma/written-addr STA2
402 421
 
403 422
 	&write
404
-	#3e .Console/char ;asma/pass LDA asma-DEO
423
+	,asma-output/ptr LDR2
424
+	DUP2 ;asma-write-buffer/end EQU2 ,&flush JCN
425
+	&after-flush
426
+	STH2k STA
427
+	STH2r #0001 ADD2 ,asma-output/ptr STR2
428
+
429
+	( #3e .Console/char ;asma/pass LDA asma-DEO
405 430
 	#20 .Console/char ;asma/pass LDA asma-DEO
406
-	.Console/byte ;asma/pass LDA asma-DEO ( FIXME actually write! )
407
-	#0a .Console/char ;asma/pass LDA asma-DEO
431
+	#00 .Console/byte ;asma/pass LDA asma-DEO
432
+	#0a .Console/char ;asma/pass LDA asma-DEO )
408 433
 	JMP2r
409 434
 
410
-	&rewound
411
-	;asma-msg-rewound ;asma/error STA2
412
-	POP2 POP2 POP JMP2r
435
+	&flush ( ptr* -- start-of-buffer* )
436
+	;asma-write-buffer SUB2k ( ptr* start* len* )
437
+	;asma/flush-fn LDA2 JSR2
438
+	SWP2 POP2 ( start* )
439
+	,&after-flush JMP
413 440
 
414
-@asma-write-short ( short -- )
415
-	SWP
416
-	,asma-write-byte JSR
417
-	,asma-write-byte JMP ( tail call )
441
+@asma-output [ &ptr $2 &offset $2 &filename $2 ]
442
+
443
+@asma-flush-ignore ( len* -- )
444
+	POP2
445
+	JMP2r
446
+
447
+@asma-flush-to-file ( len* -- )
448
+	DUP2 .File/length DEO2
449
+	,asma-output/offset LDR2 DUP2 .File/offset DEO2 ADD2 ,asma-output/offset STR2
450
+	;asma/dest-filename LDA2 .File/name DEO2
451
+	;asma-write-buffer .File/save DEO2
452
+	JMP2r
418 453
 
419 454
 @asma-append-heap-byte ( dummy byte -- dummy )
420 455
 	;asma/heap LDA2