Browse code

Implemented address changes and rewind detection

Andrew Alderwick authored on 14/05/2021 20:22:55
Showing 1 changed files
... ...
@@ -136,6 +136,7 @@
136 136
 	;asma/pass LDA #01 ADD ;asma/pass STA
137 137
 	#00 ;asma/state STA
138 138
 	#0000 ;asma/addr STA2
139
+	#0100 ;asma/written-addr STA2
139 140
 	#0001 ;asma/line STA2
140 141
 	JMP2r
141 142
 
... ...
@@ -170,7 +171,7 @@
170 171
 	POP POP2 POP2
171 172
 	JMP2r
172 173
 
173
-@asma [ &pass $1 &state $1 &line $2 &token $2 &orig-token $2 &heap $2 &addr $2 &scope-addr $2 &error $2 ]
174
+@asma [ &pass $1 &state $1 &line $2 &token $2 &orig-token $2 &heap $2 &addr $2 &written-addr $2 &scope-addr $2 &error $2 ]
174 175
 @asma-trees [ &labels $2 &macros $2 &opcodes $2 &scope $2 ]
175 176
 
176 177
 @asma-assemble-token ( string-ptr* -- )
... ...
@@ -323,13 +324,30 @@
323 324
 	JMP2r
324 325
 
325 326
 @asma-write-byte ( byte -- )
327
+	;asma/addr LDA2 ;asma/written-addr LDA2
328
+	LTH2k ,&rewound JCN
329
+	&loop
330
+	EQU2k ,&ready JCN
331
+	#00 ,&write JSR
332
+	#0001 ADD2
333
+	,&loop JMP
334
+
335
+	&ready
336
+	POP2 #0001 ADD2
337
+	DUP2 ;asma/addr STA2
338
+	;asma/written-addr STA2
339
+
340
+	&write
326 341
 	#3e .Console/char ;asma/pass LDA asma-DEO
327 342
 	#20 .Console/char ;asma/pass LDA asma-DEO
328 343
 	.Console/byte ;asma/pass LDA asma-DEO ( FIXME actually write! )
329 344
 	#0a .Console/char ;asma/pass LDA asma-DEO
330
-	;asma/addr LDA2 #0001 ADD2 ;asma/addr STA2
331 345
 	JMP2r
332 346
 
347
+	&rewound
348
+	;asma-msg-rewound ;asma/error STA2
349
+	POP2 POP2 POP JMP2r
350
+
333 351
 @asma-write-short ( short -- )
334 352
 	SWP
335 353
 	,asma-write-byte JSR
... ...
@@ -497,7 +515,6 @@
497 515
 	JMP2r
498 516
 
499 517
 	&valid
500
-	( FIXME complain if rewind after writing nonzeroes )
501 518
 	ADD2 ;asma/addr STA2
502 519
 	JMP2r
503 520
 
... ...
@@ -659,6 +676,7 @@
659 676
 @asma-msg-relative  "Address 20 "outside 20 "range 00
660 677
 @asma-msg-label     "Label 20 "not 20 "found 00
661 678
 @asma-msg-macro     "Macro 20 "already 20 "exists 00
679
+@asma-msg-rewound   "Memory 20 "overwrite 00
662 680
 
663 681
 ( trees )
664 682