-
Notifications
You must be signed in to change notification settings - Fork 4
/
Listing.lst
4682 lines (4682 loc) · 272 KB
/
Listing.lst
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
00001 ; version 2.10
00002 ; two pass assembler, dissembler and tracer- inspiration with permission from A1 by San Bergmans
00003 ; REGB bits 0-3 are connected to LED's
00004 ; tested in Michael Kowalski 6502 Simulator - using 65C02 Code
00005 ; "Programmed" by Joe DiMeglio
00006 ; https://github.com/jdimeglio/6502-Monitor
00007
00008 .OPT proc65C02,swapbin ;Michal Kowaski Simulator
00009 F8DF .START RESET_VECTOR ;version 1.3.2
00010 .IO_WND 80,25 ;
00011
00012 ;------------------------------------------------------------------------
00013 ; Compiler Options/Directives
00014 ;------------------------------------------------------------------------
00015
00016 0000 BRKAS2 = 0 ;Add a second BRK byte
00017 0000 MYWYM = 0 ;has MYWYM Board settings/Chips
00018 0000 LCD_ROUTINES = 0 ;Compile with LCD 16x2 lines
00019 0000 SYMON = 0 ;used for SYMON to define CIA and VIA
00020
00021 .INCLUDE "constants.65s"
00022 ; LIBRARY FILE
00023 ; version 2.09
00024 ; two pass assembler, dissembler and tracer- inspiration with permission from A1 by San Bergmans
00025 ; REGB bits 0-3 are connected to LED's
00026 ; tested in Michael Kowalski 6502 Simulator - using 65C02 Code
00027 ; "Programmed" by Joe DiMeglio
00028
00029
00030 ;------------------------------------------------------------------------
00031 ; Symbols used in source code
00032 ;------------------------------------------------------------------------
00033
00034 0023 IMV ='#' ;Indicates immediate mode value
00035 0024 HEX ='$' ;Indicates a hex value
00036 0028 OPEN ='(' ;Open bracket for indirect addressing
00037 0029 CLOSE =')' ;Close bracket for indirect addressing
00038 002A PCREL ='*' ;Indicates PC relative addressing
00039 003C LOBYTE ='<' ;Indicates lo-byte of following word
00040 003E HIBYTE ='>' ;Indicates hi-byte of following word
00041 002B PLUS ='+' ;Plus in simple expressions
00042 002D MINUS ='-' ;Minus in simple expressions
00043 002E DOT ='.' ;Indicates a local label
00044 0027 QUOTE =''' ;delimits a string
00045 002C COMMA =','
00046 003B CMNT =';' ;indicates a full line comment
00047 002E PROMPT ='.' ;The assembler prompt character
00048 002D DASH ='-' ;Dash for crued graphics
00049 0000 EOL =$00 ;End of line marker
00050 0000 EOS =$00 ;End of string marker
00051 0001 EOFLD =$01 ;End of field in tokenised source line
00052 0002 BLANK =$02 ;used to mark a blank line
00053 00FE PRGEND =$FE ;used to flag end of program parsing
00054 00FF FAIL =$FF ;used to flag failure in various searches
00055 000D CR =$0D ;CR character
00056 001B ESC =$1B ;ESC character
00057 0007 BELL =$07 ;BELL should be $07 but $20 for testing
00058 0008 BS =$08 ;Back space key
00059 0009 TAB =$09 ;TAB character
00060 000A LF =$0a ;Line feed
00061 0020 SP =$20 ;Space
00062
00063 000C TAB1 =12 ;1st tab stop 8
00064 0010 TAB2 =16 ;2nd tab stop 12
00065 0014 TAB3 =20 ;3rd tab stop 21
00066 001A TAB4 =26 ;4th tab
00067
00068
00069 ;------------------------------------------------------------------------
00070 ; Constants
00071 ;------------------------------------------------------------------------
00072
00073 0004 DEF_LOMEM = $04 ;Default lomem page
00074 03E8 DEF_AUTO = 1000 ;Default Auto line number start
00075 000A DEF_INC = 10 ;Default Auto increment step
00076 1000 DEF_ORG = $1000 ;Default .OR
00077 0200 DEF_OBJLOW = $0200 ;Default lowest object address
00078
00079
00080
00081 ;------------------------------------------------------------------------
00082 ; Zero page memory
00083 ; Input buffer placed in ZP because of the many references to it. Must be
00084 ; completely in ZP because address + index remains only one byte address
00085 ; PASS must remain the first label here! See INIT routine
00086 ;------------------------------------------------------------------------
00087
00088 000019 .ORG $0019 ;Leave 1st part of ZP free
00089 000099 IN .RS 128 ;Input and parse buffer 128 Characters input
00090
00091 .IF LCD_ROUTINES
00092 ;------------------------------------------------------------------------
00093 ; Tracing/debuging varials
00094 ;------------------------------------------------------------------------
00095 0000A8 XQT .RS 15 ;Used for tacing
00096 0000A9 SAVP .RS 1 ;registers save - 5 locations must be contiguous1
00097 0000AA SAVS .RS 1
00098 0000AB SAVY .RS 1
00099 0000AC SAVX .RS 1
00100 0000AD SAVA .RS 1
00101
00102 ;------------------------------------------------------------------------
00103 ; Assembler registers
00104
00105 0000AE PASS .RS 1 ;Assembler pass 0=1, 1=2
00106 0000B0 GLOBAL .RS 2 ;Last defined Global label
00107 0000B2 GLOBAL_VAL .RS 2 ;Last defined Global's value
00108 0000B3 LABEL_FLAG .RS 1 ;Found label's assigned flag (b7)
00109 0000B5 PNTR .RS 2 ;Pointer in source
00110 0000B6 INDEX .RS 1 ;Index mode 0, X or Y
00111 0000B8 PC .RS 2 ;Current program counter
00112 0000BA TA .RS 2 ;Current target address
00113 0000BC TA_BEGIN .RS 2 ;Begin of target address block
00114 0000BE PC_BEG .RS 2 ;Program counter at start of line
00115 0000BF ASM_ERR .RS 1 ;Assemble errors (max 255)
00116 0000C0 UNDEF .RS 1 ;Undefined label if <> 0
00117 0000C1 FORWARD .RS 1 ;Forward referenced label if <> 0
00118 0000C2 LL_NUM .RS 1 ;Local label's number
00119 0000C3 FIRST_CHAR .RS 1 ;First character of a label
00120
00121 0000C4 CURMNE .RS 1 ;Holds the current mne index
00122 0000C5 CURADM .RS 1 ;Holds the current addressing mode
00123
00124 ;------------------------------------------------------------------------
00125 ; Editor's registers
00126
00127 0000C6 CMD_CHR .RS 1 ;First character of command
00128 0000C7 ERROR .RS 1 ;Latest error
00129 0000C8 DUMP .RS 1 ;Dump mode in list command
00130 0000CA PARM1 .RS 2 ;Parameter 1
00131 0000CC PARM2 .RS 2 ;Parameter 2
00132
00133 ;------------------------------------------------------------------------
00134 ; General purpose registers
00135
00136 0000CD NEG_FLAG .RS 1 ;Negative flag (if <> 0)
00137 0000CE COUNT .RS 1 ;GP counter
00138 0000CF DELIM .RS 1 ;String/ASCII delimiter
00139 0000D1 HEXVAL .RS 2 ;16-bit value of expression
00140 0000D2 LEAD0 .RS 1 ;Leading 0 flag
00141 0000D3 CHAR .RS 1 ;Character compilation register
00142 0000D5 MULDIV .RS 2 ;Multiply/divide temp
00143 0000D7 EXP_SAVE .RS 2 ;Expression save value
00144 0000D9 DEC_SAVE .RS 2 ;Decimal convert save value
00145 0000DA SAVE_Y .RS 1 ;Save Y pointer
00146 0000DC LENG .RS 2 ;Length of block move
00147 0000DE SRCE .RS 2 ;Source for block move
00148 0000E0 DEST .RS 2 ;Destination for block move
00149
00150 ;------------------------------------------------------------------------
00151 ; for disassembler
00152
00153 0000E2 PRFLAG .RS 2
00154 0000E3 TEMP1 .RS 1 ;general purpose storage
00155 0000E4 TEMP2 .RS 1
00156
00157 ;------------------------------------------------------------------------
00158 ; Registers which are best NOT to be disturbed by user's program!
00159
00160 0000E5 OLD_SAVE .RS 1 ;OLD possible if <> 0
00161 0000E7 AUTO .RS 2 ;Next Auto line number
00162 0000E8 AUTO_INC .RS 1 ;Auto increment
00163 0000E9 AUTO_FLAG .RS 1 ;Auto mode flag (if <> -)
00164 0000EB SYM_TABLE .RS 2 ;Symbol table (if MSB <> 0)
00165 0000ED USR_OBJLO .RS 2 ;User's safe object begin
00166 0000EF USR_OBJHI .RS 2 ;User's safe object end
00167 0000F1 LOMEM .RS 2 ;Lomem address | Don't
00168 0000F3 HIMEM .RS 2 ;Himem address | change order
00169 0000F5 XEC_LAST .RS 2 ;Last Xec address
00170 0000F7 USERKEYDEF .RS 2 ;User defined @keys
00171 0000F9 USIRQ .RS 2 ;User IRQ vector
00172 0000FB USBRK .RS 2 ;User BRK vector
00173 0000FD USMNI .RS 2 ;User NMI vector
00174 000100 USRRST .RS 3 ;User RESET vector + checksum
00175
00176
00177 ;------------------------------------------------------------------------
00178 ; Hardware mapping
00179 ;------------------------------------------------------------------------
00180 .IF LCD_ROUTINES
00181
00182
00183
00184
00185 ;------------------------------------------------------------------------
00186 ; My board settings
00187 ;------------------------------------------------------------------------
00188 .IF MYWYM
00189
00190
00191 ;------------------------------------------------------------------------
00192 ; Simulator or HARDWARE Mapping 6502 Simulator
00193 ;------------------------------------------------------------------------
00194 8000 VIA = $8000
00195 8800 ACIA = io_area
00196 8800 io_cls = io_area + 0 ;writing to this clears the output window
00197 8801 io_putc = io_area + 1 ;a "glass teletype" output window. BS, CR and LF are actioned
00198 8802 io_putr = io_area + 2 ;raw output, bytes are output as their
00199 ;characters and not actioned.
00200 8803 io_puth = io_area + 3 ;hex output, bytes are output as their hex code
00201 8804 io_getc = io_area + 4 ;SCAN_ESCing character get, will wait for input
00202 8805 io_posx = io_area + 5 ;set cursor x position by writing here
00203 8806 io_posy = io_area + 6 ;set cursor y position by writing here
00204
00205 8804 KBD = io_getc ;Keyboard input register
00206 8804 KBDCR = io_getc ;Keyboard control register
00207
00208
00209 .ENDIF
00210
00211
00212
00213
00214
00215
00216 00E000 *= $e000 ;ROM location
00217
00218 ;------------------------------------------------------------------------
00219 ; Lets get going
00220 ; Cold and Warm program entry points
00221 ;------------------------------------------------------------------------
00222
00223 00E000 20 B2 E5 COLD JSR INIT ;Initialise assembler
00224 00E003 D8 WARM CLD ;You'll probably know why
00225 00E004 20 A2 F6 JSR WRCRLF ;Print CR & LF before we do anything
00226 00E007 64 E8 STZ AUTO_FLAG ;Clear auto flag
00227
00228 ;------------------------------------------------------------------------
00229 ; Get input line (main program loop)
00230 ;------------------------------------------------------------------------
00231
00232 00E009 A2 00 GETLINE LDX #$00 ;reset buffer index
00233 00E00B A9 2E LDA #PROMPT ;Print the assembler prompt
00234 00E00D 20 A9 F6 JSR WRCHAR
00235 00E010 20 46 E8 JSR AUTONUM ;Generate line number if auto=on
00236 00E013 20 E5 F6 .IN JSR RDCHAR ;Was a key pressed?
00237 00E016 C9 1B .found CMP #ESC ;Is it the ESC key?
00238 00E018 F0 23 BEQ .ESC ;Nope!
00239 00E01A C9 08 CMP #BS ;Back space key then?
00240 00E01C F0 26 BEQ .BS
00241 00E01E C9 09 CMP #TAB ;Is it the TAB character?
00242 00E020 F0 2B BEQ .TABS
00243 00E022 C9 0D CMP #CR ;Is it a CR then?
00244 00E024 F0 45 BEQ .CR ;Yes!
00245 00E026 C9 3A CMP #':' ;INTEL Hex loader
00246 00E028 D0 05 BNE .LF ;nope then skip
00247 00E02A 20 16 E1 JSR CMD_INTELHEX
00248 00E02D 80 DA BRA GETLINE
00249
00250 00E02F C9 0A .LF CMP #LF ;Is it a CR then?
00251 00E031 F0 E0 BEQ .IN ;Strip LF useful for pasting code
00252 00E033 95 19 STA IN,X ;Save new character in input buffer
00253 00E035 20 A9 F6 JSR WRCHAR ; and display it
00254 00E038 E8 INX
00255 00E039 10 D8 BPL .IN ;Get next character unless its 128 characters
00256 00E03B 80 02 BRA .CANCEL ;Always taken! Too many chars.
00257
00258 00E03D 64 E8 .ESC STZ AUTO_FLAG ;Clear auto flag and therefore OFF
00259
00260
00261 ; .IF MYWYM
00262 ; .IF SYMON
00263 ; JSR RDCHAR ;get the unwanted arrow keys
00264 ;
00265 ; .ELSE
00266 ; ;JSR RDCHAR
00267 ; ;JSR RDCHAR
00268 ; .ENDIF
00269 ; .ENDIF
00270
00271 00E03F 20 A2 F6 .CANCEL JSR WRCRLF ;Print CRLF
00272 00E042 80 C5 BRA GETLINE ;Always taken! Restart line
00273
00274 00E044 20 A9 F6 .BS JSR WRCHAR ;Process Back SPACE
00275 00E047 CA DEX ;Decrement input pointer
00276 00E048 10 C9 BPL .IN ;Still positive!
00277 00E04A E8 INX ;Don't allow it to go negative
00278 00E04B 80 C6 BRA .IN ;Always taken!
00279
00280 00E04D A0 00 .TABS LDY #0 ;Point to 1st tab stop
00281 00E04F B9 93 E0 .TABS_NEXT LDA TABS,Y ;It X smaller than this one?
00282 00E052 85 CD STA COUNT
00283 00E054 A9 20 LDA #SP ;replace with SPACE probably dont need this
00284 00E056 E4 CD CPX COUNT
00285 00E058 90 05 BCC .DOTAB ;Yes! Tab to this position
00286 00E05A C8 INY
00287 00E05B C0 04 CPY #NUMTABS ;Maximum number of tab stops
00288 00E05D 90 F0 BCC .TABS_NEXT ;Try next!
00289
00290 00E05F 95 19 .DOTAB STA IN,X ;Save this character
00291 00E061 E8 INX
00292 00E062 20 A9 F6 JSR WRCHAR ; and WRCHAR it
00293 00E065 E4 CD CPX COUNT ;At tab stop?
00294 00E067 90 F6 BCC .DOTAB ;Not yet!
00295 00E069 80 A8 BRA .IN ;Always taken!
00296
00297 00E06B 95 19 .CR STA IN,X ;Mark end of line now with CR
00298 00E06D 20 2A F7 JSR UPPERCASE ;convert to upper case
00299 00E070 20 A2 F6 JSR WRCRLF ;CR new line
00300 00E073 20 A4 E5 JSR FIRSTNONSPC ;Find first non space
00301 00E076 F0 91 BEQ GETLINE ;End of line reached!
00302
00303 00E078 C9 30 CMP #'0' ;Is it a line number?
00304 00E07A 90 04 BCC .NOLINE ;No!
00305 00E07C C9 3A CMP #'9'+1
00306 00E07E 90 0D BCC .LINENUM ;It is! Add it to the program
00307 00E080 20 97 E0 .NOLINE JSR KEYDEF ;Parse command, or line number
00308 00E083 A5 C6 .CHK_ERROR LDA ERROR ;Was there an error?
00309 00E085 F0 03 BEQ .GETLINE ;Nope!
00310 00E087 20 6D E4 JSR PRINT_MSGS ;Print error
00311 00E08A 4C 09 E0 .GETLINE JMP GETLINE ;Stay in main program loop
00312
00313 00E08D 20 3C EC .LINENUM JSR ADDLINE ;Add line to program
00314 00E090 4C 83 E0 JMP .CHK_ERROR ;Check if an error occurred
00315
00316 TABS .BYTE TAB1 ;1st tab stop
00317 .BYTE TAB2 ;2nd tab stop
00318 .BYTE TAB3
00319 .BYTE TAB4 ;3rd tab stop
00320 0004 NUMTABS = 4 ;Number of tab stops
00321
00322 ;------------------------------------------------------------------------
00323 ; Parse command or line number
00324 ; A holds the command character
00325 ;------------------------------------------------------------------------
00326
00327 00E097 A0 00 KEYDEF LDY #0 ;Find command in table
00328 00E099 84 C6 STY ERROR ;Clear error
00329 00E09B 85 C5 STA CMD_CHR
00330
00331 00E09D B9 C3 E0 .LOOP LDA .TABLE,Y
00332 00E0A0 F0 1C BEQ .SYNERR ;End of table! Syntax errorv
00333 00E0A2 C5 C5 CMP CMD_CHR ;Is it this command
00334 00E0A4 F0 03 BEQ .FOUND ;Found our command!
00335 00E0A6 C8 INY ;Next command from table
00336 00E0A7 80 F4 BRA .LOOP ;Always taken!
00337
00338 00E0A9 20 32 EC .FOUND JSR IN_BLANK ;Get next and see if it's blank
00339 00E0AC D0 FB BNE .FOUND ;A CR would have been too!
00340 00E0AE 98 TYA ;Point to command handler's
00341 00E0AF 0A ASL ; address in table
00342 00E0B0 A8 TAY
00343 00E0B1 B9 DB E0 LDA FUNCTIONS+1,Y ; Get the address and use it MSB first
00344 00E0B4 48 PHA ; as return address
00345 00E0B5 B9 DA E0 LDA FUNCTIONS,Y
00346 00E0B8 48 PHA
00347 00E0B9 A0 00 LDY #0 ;Some commands may benefit from this
00348 00E0BB 4C A6 E5 JMP NNONSPC ;Find next non space and exec cmd XR points to IN.X
00349
00350 00E0BE A9 08 .SYNERR LDA #ERR_SYN ;Exit with syntax error
00351 00E0C0 85 C6 STA ERROR
00352 00E0C2 60 RTS
00353
00354 ;------------------------------------------------------------------------
00355 ; Table of commands
00356 ;
00357 ;------------------------------------------------------------------------
00358
00359 .TABLE .BYTE 'A' ;Auto line numbering
00360 .BYTE 'B' ;Break command
00361 .BYTE 'C' ;Copy command
00362 .BYTE 'D' ;Dissassembler
00363 .BYTE 'E' ;Erase command
00364 .BYTE 'F' ;Fill Command - future
00365 .BYTE 'G' ;GO command - future
00366 .BYTE 'H' ;Hunt Command - future
00367 .BYTE '?' ;Help command
00368 .BYTE 'I' ;ASCII Dump
00369 .BYTE 'L' ;List command
00370 .BYTE 'M' ;Memory command
00371 .BYTE 'N' ;New command
00372 .BYTE 'O' ;Old command
00373 .BYTE 'R' ;Renumber command
00374 .BYTE 'S' ;Start assembling
00375 .BYTE 'T' ;Trace code
00376 .BYTE 'V' ;Value command
00377 .BYTE "W" ;Display registers
00378 .BYTE 'Y' ;memory configuraion
00379 .BYTE 'Z' ;Clear Screen
00380 .BYTE '@' ;User commands
00381 CMD_BRK .BYTE 0 ;End of table & BRK
00382
00383 ;------------------------------------------------------------------------
00384 ; Table of commands
00385 ; RTS will a +1 to the address
00386 ;------------------------------------------------------------------------
00387
00388 FUNCTIONS .WORD CMD_AUT-1 ;Auto line numbering
00389 .WORD CMD_BRK-1 ;Break command
00390 .WORD CMD_COP-1 ;Copy command
00391 .WORD CMD_DISSASSEMBLER-1 ;Dissassembler
00392 .WORD CMD_ERASE-1 ;Erase command
00393 .WORD CMD_FILL-1 ;Fill memory
00394 .WORD CMD_XEC-1 ;eXecute command
00395 .WORD CMD_HUNT-1 ;hunt command
00396 .WORD CMD_HLP-1 ;Help command
00397 .WORD CMD_ASCIIDUMP-1 ;ASCII DUMP
00398 .WORD CMD_LST-1 ;List command
00399 .WORD CMD_MEMORY_DUMP-1 ;Memory command
00400 .WORD CMD_NEW-1 ;New command
00401 .WORD CMD_OLD-1 ;Old command
00402 .WORD CMD_REN-1 ;Renumber command
00403 .WORD CMD_ASM-1 ;Start assembling
00404 .WORD CMD_TRACE-1 ;Trace Code
00405 .WORD CMD_VAL-1 ;Value command
00406 .WORD CMD_SHOWREG-1 ;Display registers
00407 .WORD CMD_MEM-1 ;Memory command
00408 .WORD CMD_CLS-1 ;Clrscreen command
00409 .WORD CMD_USERKEYS-1 ;Allows users to add more keys after @
00410
00411 ;----------------------------------------------------------------------------------------
00412 ; Allows users to add more keys after @
00413 ;----------------------------------------------------------------------------------------
00414
00415 00E106 6C F5 00 CMD_USERKEYS JMP (USERKEYDEF)
00416
00417 ;----------------------------------------------------------------------------------------
00418 ;Clear the screen
00419 ;----------------------------------------------------------------------------------------
00420
00421 00E109 4C 73 F6 CMD_CLS JMP CLS
00422
00423 ;----------------------------------------------------------------------------------------
00424 00E10C 64 E8 CMD_ESC STZ AUTO_FLAG ;Clear auto flag and therefore OFF
00425 00E10E A9 07 .CANCEL LDA #BELL ;play bell
00426 00E110 20 A9 F6 JSR WRCHAR
00427 00E113 4C A2 F6 JMP WRCRLF ;Print CRLF
00428
00429 ;----------------------------------------------------------------------------------------
00430 ;Intel HEX loader
00431
00432 .INCLUDE "INTELHEX.65s"
00433 ; LIBRARY FILE
00434 ; version 2.09
00435 ; two pass assembler, dissembler and tracer- inspiration with permission from A1 by San Bergmans
00436 ; REGB bits 0-3 are connected to LED's
00437 ; tested in Michael Kowalski 6502 Simulator - using 65C02 Code
00438 ; "Programmed" by Joe DiMeglio
00439
00440
00441 ;----------------------------------------------------------------------------------------
00442 ;Intel HEX loader
00443 ;----------------------------------------------------------------------------------------
00444
00445 00DA CHECKSUM = LENG
00446
00447 00E116 78 CMD_INTELHEX SEI ;stop Interrupts
00448 00E117 D8 CLD ;binary mode additons
00449 00E118 64 D5 STZ EXP_SAVE ;temp
00450 00E11A 64 D7 STZ DEC_SAVE ;Bytes count
00451 00E11C 64 D8 STZ DEC_SAVE+1
00452 00E11E 64 DA STZ CHECKSUM ;checksum
00453 00E120 A9 0D LDA #CR
00454 00E122 8D 00 88 STA ACIA ;dont wait on port status
00455 00E125 A9 0A LDA #LF
00456 00E127 8D 00 88 STA ACIA ;dont wait on port status
00457 00E12A 80 33 BRA CONTINUE
00458
00459 00E12C 20 E5 F6 NEXTRECORD JSR RDCHAR
00460 00E12F C9 0D CMP #CR
00461 00E131 D0 0E BNE PROTOCOLERROR
00462 00E133 20 E5 F6 JSR RDCHAR ;CRLF and end of line (BUG there's a CHECKSUM)
00463 00E136 C9 0A CMP #LF
00464 00E138 D0 07 BNE PROTOCOLERROR
00465 00E13A 20 E5 F6 JSR RDCHAR
00466 00E13D C9 3A CMP #':'
00467 00E13F F0 1E BEQ CONTINUE
00468
00469 00E141 20 A9 F6 PROTOCOLERROR JSR WRCHAR
00470 00E144 20 15 F6 JSR STRING
00471 .ASCII BELL,CR,LF," :PROTOCOL ERROR",CR,LF + $80
00472 00E15C 4C 4A E2 JMP TERMINATE
00473
00474 00E15F 20 4D E2 CONTINUE JSR READ_DATA ;read rcord length with checksum add
00475 00E162 85 CD STA COUNT ;load the amount of bytes to load into memory
00476 00E164 20 4D E2 JSR READ_DATA ;read hgh byte of memory location
00477 00E167 85 DD STA SRCE+1 ;store hgh byte of memory location
00478 00E169 20 4D E2 JSR READ_DATA ;read low byte with checksum add
00479 00E16C 85 DC STA SRCE ;store
00480 00E16E 20 4D E2 JSR READ_DATA ;get record type 01 = end
00481 ;CMP #$00 ;check if 00 if yes then type #00
00482 00E171 F0 27 BEQ .DATARECORD ;get the data frame
00483 00E173 C9 01 CMP #$01 ;is it type #01 ie: end of record
00484 00E175 D0 03 BNE .INVREC ;else invalid
00485 00E177 4C 01 E2 JMP .END_RECORD
00486
00487 00E17A 20 15 F6 .INVREC JSR STRING
00488 .ASCII BELL,CR,LF," :INVALID RECORD TYPE",CR,LF +$80
00489 00E197 4C 4A E2 JMP TERMINATE
00490
00491
00492 .IF MYWYM
00493
00494 00E19A A6 CD .DATARECORD LDX COUNT ;DATASIZE
00495 00E19C A0 00 LDY #$00
00496 00E19E 20 4D E2 .NEXT_BYTE JSR READ_DATA ;read two hex characters
00497 00E1A1 91 DC STA (SRCE),y ;store in RAM
00498 00E1A3 D1 DC CMP (SRCE),y ;did it actually store
00499 00E1A5 D0 0F BNE .WRITEERROR ;no then error - probably no ram there
00500 00E1A7 A9 23 LDA #'#' ;write fast
00501 00E1A9 8D 00 88 STA ACIA ;dont wait on port status
00502 00E1AC C8 INY ;next address
00503 00E1AD CA DEX ;next byte to recieve
00504 ;CPX #$00 ;all bytes recieved?
00505 00E1AE D0 EE BNE .NEXT_BYTE ;no then get next record
00506 00E1B0 20 4D E2 JSR READ_DATA ;get checksum
00507
00508 .IF MYWYM
00509 00E1B3 4C 2C E1 .LEDCNT JMP NEXTRECORD
00510
00511 00E1B6 20 15 F6 .WRITEERROR JSR STRING
00512 .ASCII BELL,CR,LF
00513 .ASCIS " :CANNOT WRITE AT ADDRESS $"
00514
00515 00E1D7 A5 DD LDA SRCE+1
00516 00E1D9 20 BC F6 JSR WR2HEX
00517 00E1DC A5 DC LDA SRCE
00518 00E1DE 20 BC F6 JSR WR2HEX
00519 00E1E1 20 A2 F6 JSR WRCRLF
00520 00E1E4 80 64 BRA TERMINATE
00521
00522 00E1E6 20 15 F6 .CHECKSUMERR JSR STRING
00523 .ASCII BELL,LF,CR," :CHECK SUM ERROR",LF,CR +$80
00524 00E1FF 80 49 BRA TERMINATE
00525
00526 00E201 20 F0 F6 .END_RECORD JSR RD2HEX ;last two byes the CheckSUM
00527 00E204 18 CLC
00528 00E205 65 DA ADC CHECKSUM
00529 00E207 D0 DD BNE .CHECKSUMERR
00530 00E209 20 15 F6 JSR STRING
00531 .ASCII BELL,CR,LF
00532 .ASCIS " :INTEL-HEX SUCCESSFUL"
00533 00E225 20 15 F6 JSR STRING
00534 .ASCII CR,LF
00535 .ASCIS " :TOTAL BYTES WRITTEN "
00536 00E240 A4 D7 LDY DEC_SAVE
00537 00E242 A5 D8 LDA DEC_SAVE+1
00538 00E244 20 AB E7 JSR WRDECI
00539
00540 .IF MYWYM
00541 00E247 58 CLI
00542 00E248 18 CLC
00543 00E249 60 RTS ;return to caller
00544
00545 TERMINATE
00546 .IF MYWYM
00547 00E24A 38 SEC
00548 00E24B 58 CLI
00549 00E24C 60 RTS ;return to caller
00550
00551 ;---------------------------------------------------------------------------------
00552 00E24D 20 F0 F6 READ_DATA JSR RD2HEX ;read two hex characters & checksum
00553 ;bcs ERRS
00554 00E250 48 PHA
00555 00E251 18 CLC
00556 00E252 65 DA ADC CHECKSUM ;add to checksum
00557 00E254 85 DA STA CHECKSUM
00558 00E256 18 CLC
00559 00E257 A5 D7 LDA DEC_SAVE
00560 00E259 69 01 ADC #01
00561 00E25B 85 D7 STA DEC_SAVE
00562 00E25D A5 D8 LDA DEC_SAVE+1 ;add the carry
00563 00E25F 69 00 ADC #00
00564 00E261 85 D8 STA DEC_SAVE+1
00565 00E263 68 PLA
00566 00E264 60 RTS
00567
00568 ;ERRS tsx ;remove the last RTS from stack
00569 ; inx
00570 ; inx
00571 ; txs
00572 ; jsr STRING ;read error from RS232
00573 ; .ASCIS BELL,CR,LF," :READ ERROR FROM ACIA",CR,LF
00574 ; BRA TERMINATE
00575
00576
00577
00578 ;------------------------------------------------------------------------
00579 ;Bump Address by AC
00580 ;------------------------------------------------------------------------
00581
00582 00E265 18 BUMPSRCE CLC
00583 00E266 65 DC ADC SRCE
00584 00E268 85 DC STA SRCE
00585 00E26A 90 02 BCC .BUMPSRCE
00586 00E26C E6 DD INC SRCE+1
00587 00E26E 60 .BUMPSRCE RTS
00588
00589 ;------------------------------------------------------------------------
00590 ;Instruction display - orginal code seems to come from MOS
00591 ;------------------------------------------------------------------------
00592
00593 00E26F A8 INSTDSP TAY ;Save op code
00594 00E270 4A LSR ;* Even/odd test
00595 00E271 90 05 BCC .IEVEN
00596 00E273 6A ROR ;* Test B1
00597 00E274 B0 11 BCS .ERR ;XXXXXX11 instr invalid
00598 ;CMP #$A2
00599 ;BEQ ERR ;10001001 instr invalid
00600 00E276 29 87 AND #$87 ;Mask 3 bits for address mode
00601 ;ORA #$80 ;* add indexing offset
00602 00E278 4A .IEVEN LSR ;* LSB into carry for
00603 00E279 AA TAX ;Left/right test below
00604 00E27A BD FD F3 LDA MODE,X ;Index into address mode table
00605 00E27D 90 04 BCC .RTMODE ;If carry set use LSD for
00606 00E27F 4A LSR ;* print format index
00607 00E280 4A LSR
00608 00E281 4A LSR ;If carry clear use MSD
00609 00E282 4A LSR
00610 00E283 29 0F .RTMODE AND #$0F ;Mask for 4-bit index
00611 00E285 D0 04 BNE .GETFMT ;$0 for invalid opcodes
00612 00E287 A0 FC .ERR LDY #$FC ;Substitute $FC for invalid op,
00613 00E289 A9 00 LDA #$00 ;set print format index to 0
00614 00E28B AA .GETFMT TAX
00615 00E28C BD 41 F4 LDA MODE2,X ;Index into print format table
00616 00E28F 85 D9 STA SAVE_Y ;Save for address field format
00617 00E291 29 03 AND #$03 ;Mask 2-bit length. 0=1-byte
00618 00E293 85 DA STA LENG ;* 1=2-byte, 2=3 byte
00619 00E295 98 TYA ;* op code
00620 00E296 20 B2 F5 JSR GETMNE ;Lookup the mnemonic
00621 00E299 A0 00 LDY #$00
00622 00E29B 48 PHA ;Save mnemonic table index
00623 00E29C B1 DC .PROP LDA (SRCE),Y
00624 00E29E 20 BC F6 JSR WR2HEX
00625 00E2A1 A2 01 LDX #$01
00626 00E2A3 20 31 E3 .PROPBL JSR PRBL2
00627 00E2A6 C4 DA CPY LENG ;Print instr (1 to 3 bytes)
00628 00E2A8 C8 INY ;* in a 12-character field
00629 00E2A9 90 F1 BCC .PROP
00630 00E2AB A2 03 LDX #$03 ;char count for mnemonic print
00631 00E2AD 86 E0 STX PRFLAG ;So EXPMNE prints the mnemonic
00632 00E2AF C0 04 CPY #$04
00633 00E2B1 90 F0 BCC .PROPBL
00634 00E2B3 68 PLA ;Recover mnemonic index
00635 00E2B4 AA TAX
00636 00E2B5 20 08 E3 JSR EXPMNE ;Expand the Memonic
00637 00E2B8 20 2F E3 JSR PRBLNK ;Output 3 blanks
00638 00E2BB A4 DA LDY LENG
00639 00E2BD A2 06 LDX #$06 ;Count for 6 print format bits
00640 00E2BF E0 03 .PPADR1 CPX #$03
00641 00E2C1 F0 1E BEQ .PPADR5 ;If X=3 then print address val
00642 00E2C3 06 D9 .PPADR2 ASL SAVE_Y ;Test next print format bit
00643 00E2C5 90 0E BCC .PPADR3 ;If 0 don't print
00644 00E2C7 BD 54 F4 LDA CHAR1-1,X ; * corresponding chars
00645 00E2CA 20 A9 F6 JSR WRCHAR ;Output 1 or 2 chars
00646 00E2CD BD 4E F4 LDA CHAR2-1,X ;* (If char from char2 is 0,
00647 00E2D0 F0 03 BEQ .PPADR3 ;* don't output it)
00648 00E2D2 20 A9 F6 JSR WRCHAR
00649 ;LDA UNDEF
00650 ;JSR WRDECI
00651 00E2D5 CA .PPADR3 DEX
00652 00E2D6 D0 E7 BNE .PPADR1
00653 00E2D8 86 E0 STX PRFLAG ;reset flag to 0
00654 00E2DA 60 RTS ;Return if done 6 format bits
00655 00E2DB 88 .PPADR4 DEY
00656 00E2DC 30 E5 BMI .PPADR2
00657 00E2DE 20 BC F6 JSR WR2HEX ;Output 1- or 2-byte address
00658 00E2E1 A5 D9 .PPADR5 LDA SAVE_Y
00659 00E2E3 C9 E8 CMP #$E8 ;Handle rel addressing mode
00660 00E2E5 B1 DC LDA (SRCE),Y ;Special print target adr
00661 00E2E7 90 F2 BCC .PPADR4 ;* (not displacement)
00662 00E2E9 20 FC E2 .RELADR JSR PCADJ3 ;PCL,H + DISPL + 1 to A,Y
00663 00E2EC AA TAX
00664 00E2ED E8 INX ;adjust
00665 00E2EE D0 01 BNE PRNTYX ;* +1 to X,Y
00666 00E2F0 C8 INY
00667 00E2F1 98 PRNTYX TYA ;falls through
00668
00669 ;------------------------------------------------------------------------
00670 ;print AX as a HEX word
00671 ;------------------------------------------------------------------------
00672
00673 00E2F2 20 BC F6 PRNTAX JSR WR2HEX ;Print target adr of branch (DUPLICATE FUNCTION to WRWORDAY)
00674 00E2F5 8A PRNTX TXA ; * and return
00675 00E2F6 4C BC F6 JMP WR2HEX
00676
00677
00678 ;------------------------------------------------------------------------------------------
00679 ;PC Adjust
00680 ;------------------------------------------------------------------------------------------
00681
00682 00E2F9 38 PCADJ SEC
00683 00E2FA A5 DA PCADJ2 LDA LENG ;0=1-byte, 1=2-byte, 2=3-byte
00684 00E2FC A4 DD PCADJ3 LDY SRCE+1
00685 00E2FE AA TAX ;* test displ sign (for rel
00686 00E2FF 10 01 BPL .PCADJ4 ;* branch). Extend neg
00687 00E301 88 DEY ;* by decrementing PCH
00688 ;SEC ;* by incrementin PCL
00689 ;CLC
00690 00E302 65 DC .PCADJ4 ADC SRCE
00691 00E304 90 01 BCC .RTS ;PCL+LENGTH (or displ) + 1 to A
00692 00E306 C8 INY ;* carry into Y (PCH)
00693 00E307 60 .RTS RTS
00694
00695 ;------------------------------------------------------------------------
00696 ; Expand Mnemic
00697 ; copy the 2 chars at R/LMNETB,X
00698 ; into LMNE and RMNE, and expand
00699 ; into 3 chars at MNE to MNE+2
00700 ;------------------------------------------------------------------------
00701
00702 00E308 BD 0A F3 EXPMNE LDA LMNETB,X ;Expand Mnemic
00703 00E30B 85 C8 STA PARM1
00704 00E30D BD 4C F3 LDA RMNETB,X
00705 00E310 85 C9 STA PARM1+1
00706 00E312 A2 00 LDX #$00
00707 00E314 A9 00 .NEXT LDA #$00
00708 00E316 A0 05 LDY #$05
00709 00E318 06 C9 .LOOP ASL PARM1+1
00710 00E31A 26 C8 ROL PARM1
00711 00E31C 2A ROL
00712 00E31D 88 DEY
00713 00E31E D0 F8 BNE .LOOP
00714 00E320 69 40 ADC #'A'-1
00715 ;STA MNE,X
00716 00E322 A4 E0 LDY PRFLAG
00717 00E324 F0 03 BEQ .SKIP
00718 00E326 20 A9 F6 JSR WRCHAR ;print the mnemonic as well
00719 00E329 E8 .SKIP INX
00720 00E32A E0 03 CPX #$03
00721 00E32C D0 E6 BNE .NEXT
00722 00E32E 60 RTS
00723
00724 ;------------------------------------------------------------------------
00725 ;Print Blank Lines
00726 ;------------------------------------------------------------------------
00727
00728 00E32F A2 03 PRBLNK LDX #$03 ;Blank count
00729 00E331 20 9E F6 PRBL2 JSR WRSPACE ;Output a blank
00730 00E334 CA DEX
00731 00E335 D0 FA BNE PRBL2 ;Loop until count = 0
00732 00E337 60 RTS
00733
00734 ;------------------------------------------------------------------------
00735 ;Hunt F start end value
00736 ;------------------------------------------------------------------------
00737
00738 00E338 20 DE E5 CMD_HUNT JSR GET_VAL ;Fill Memory
00739 00E33B 84 DC STY SRCE ;Get start address
00740 00E33D 85 DD STA SRCE+1
00741 00E33F E8 INX
00742 00E340 20 DE E5 JSR GET_VAL ;FILL end address
00743 00E343 84 DE STY DEST
00744 00E345 85 DF STA DEST+1
00745 00E347 E8 INX
00746 00E348 20 DE E5 JSR GET_VAL ;FILL value
00747 00E34B 84 D2 STY CHAR
00748
00749 00E34D 38 SEC ;find length add +1
00750 00E34E A5 DE LDA DEST
00751 00E350 E5 DC SBC SRCE
00752 00E352 85 DA STA LENG
00753 00E354 A5 DF LDA DEST+1
00754 00E356 E5 DD SBC SRCE+1
00755 00E358 85 DB STA LENG+1
00756 00E35A 98 TYA ;the value
00757
00758 00E35B A4 DB LDY LENG+1
00759 00E35D F0 12 BEQ .partpg ;compare partpage
00760
00761 00E35F A0 00 LDY #00 ;another way is keep y=0 and increment
00762 00E361 D1 DC .fullpg CMP (SRCE),Y
00763 00E363 D0 03 BNE .skip1 ;probably should be write error
00764 00E365 20 C3 E3 JSR DISPLAY_ADDR
00765 00E368 C8 .skip1 INY
00766 00E369 D0 F6 BNE .fullpg
00767 00E36B E6 DD INC SRCE+1
00768 00E36D C6 DB DEC LENG+1 ;are we done
00769 00E36F D0 F0 BNE .fullpg
00770
00771 00E371 A4 DA .partpg LDY LENG
00772 00E373 D1 DC .loop1 CMP (SRCE),Y
00773 00E375 D0 05 BNE .skip2
00774 ;savey
00775 ;savya
00776 ;add + y to A
00777
00778 ;better of inc source until equals dest ;probably should be write error
00779 00E377 20 C3 E3 JSR DISPLAY_ADDR
00780 00E37A A5 D2 LDA CHAR ;get the value
00781 00E37C 88 .skip2 DEY
00782 00E37D D0 F4 BNE .loop1
00783 ;STA (SRCE),Y ;last byte
00784 00E37F 60 RTS
00785
00786
00787
00788
00789 ;------------------------------------------------------------------------
00790 ;ASCII DUMP
00791 ;------------------------------------------------------------------------
00792
00793 00E380 20 E3 E6 CMD_ASCIIDUMP JSR GET_EXPRES ;Get Source aka get expression
00794 00E383 D0 04 BNE .CONT
00795 00E385 84 DC STY SRCE
00796 00E387 85 DD STA SRCE+1
00797 00E389 A9 42 .CONT LDA #$42
00798 00E38B 85 CD STA COUNT
00799 00E38D A0 14 LDY #$14
00800 00E38F 5A .NEXTLINE PHY
00801 00E390 20 C3 E3 JSR DISPLAY_ADDR ; display address format
00802 00E393 20 A5 E3 JSR ASCII_DUMP
00803 00E396 20 A2 F6 JSR WRCRLF
00804 00E399 A9 2A LDA #42
00805 00E39B 20 65 E2 JSR BUMPSRCE ; Add to SRCE
00806 00E39E 7A PLY
00807 00E39F 88 DEY
00808 00E3A0 D0 ED BNE .NEXTLINE
00809 00E3A2 64 C6 STZ ERROR ; No Error
00810 00E3A4 60 RTS
00811
00812 ;------------------------------------------------------------------------
00813 ;ASCII DUMP one line
00814 ;------------------------------------------------------------------------
00815
00816 00E3A5 A9 2F ASCII_DUMP LDA #'/' ;ASCII DUMP - Dumps ASCII onto the screen
00817 00E3A7 20 A9 F6 JSR WRCHAR
00818 00E3AA A0 00 LDY #$00
00819 00E3AC B1 DC .NEXTCHAR1 LDA (SRCE),y
00820 00E3AE C9 1F CMP #$1f
00821 00E3B0 90 06 BCC .NOTASCII
00822 00E3B2 C9 7F CMP #$7f
00823 00E3B4 B0 02 BCS .NOTASCII
00824 00E3B6 80 02 BRA .WRITE
00825 00E3B8 A9 2E .NOTASCII LDA #'.'
00826 00E3BA 20 A9 F6 .WRITE JSR WRCHAR
00827 00E3BD C8 INY
00828 00E3BE C4 CD CPY COUNT
00829 00E3C0 D0 EA BNE .NEXTCHAR1
00830 00E3C2 60 RTS
00831
00832 ;------------------------------------------------------------------------
00833 ; display address without the $ A=MSD y=LSB
00834 ;------------------------------------------------------------------------
00835
00836 00E3C3 A9 2E DISPLAY_ADDR LDA #'.'
00837 00E3C5 20 A9 F6 JSR WRCHAR
00838 00E3C8 A9 3A LDA #':'
00839 00E3CA 20 A9 F6 JSR WRCHAR
00840 00E3CD A9 20 DISPLAY_ADDR_B LDA #SP ;basic version
00841 00E3CF 20 A9 F6 JSR WRCHAR
00842 00E3D2 A5 DD LDA SRCE+1
00843 00E3D4 A4 DC LDY SRCE
00844 00E3D6 20 D9 F6 JSR WRWORDAY ;print address AY
00845 00E3D9 A9 20 lda #SP ;TABS HERE
00846 00E3DB 20 A9 F6 JSR WRCHAR
00847 00E3DE 4C A9 F6 JMP WRCHAR ;return to caller
00848
00849 ;------------------------------------------------------------------------
00850 ;Memory DUMP one line
00851 ;------------------------------------------------------------------------
00852
00853 00E3E1 20 E3 E6 CMD_MEMORY_DUMP JSR GET_EXPRES ;DUMPS MEMORY TO THE SCREEN
00854 00E3E4 D0 04 BNE .CONT
00855 00E3E6 84 DC STY SRCE
00856 00E3E8 85 DD STA SRCE+1
00857 00E3EA A0 14 .CONT LDY #$14 ;lines to draw
00858 00E3EC A2 04 LDX #04 ;divided by 4
00859 00E3EE 5A .NEWLINE PHY
00860 00E3EF 20 C3 E3 JSR DISPLAY_ADDR
00861 00E3F2 A0 00 LDY #$00
00862 00E3F4 B1 DC .DUMP LDA (SRCE),y
00863 00E3F6 20 BC F6 JSR WR2HEX
00864 00E3F9 A9 20 LDA #SP
00865 00E3FB 20 A9 F6 JSR WRCHAR
00866 00E3FE CA DEX
00867 00E3FF D0 05 BNE .SKIPSP
00868 00E401 A2 04 LDX #04
00869 00E403 20 A9 F6 JSR WRCHAR
00870 00E406 C8 .SKIPSP INY
00871 00E407 C0 10 CPY #$10
00872 00E409 D0 E9 BNE .DUMP
00873 00E40B 20 9E F6 JSR WRSPACE
00874 00E40E 84 CD STY COUNT
00875 00E410 20 A5 E3 JSR ASCII_DUMP
00876 00E413 20 A2 F6 JSR WRCRLF
00877 00E416 A9 10 LDA #$10
00878 00E418 20 65 E2 JSR BUMPSRCE ;Add to SRCE
00879 00E41B 7A PLY
00880 00E41C 88 DEY
00881 00E41D D0 CF BNE .NEWLINE
00882 00E41F 64 C6 STZ ERROR
00883 00E421 60 RTS
00884
00885 ;------------------------------------------------------------------------
00886 ; Move a part of memory down (to delete or shorten source lines)
00887 ;
00888 ; SRCE 2 Address of source data (destroyed)
00889 ; DEST 2 Address of destination data (destroyed)
00890 ; LENG 2 Holds the number of bytes to move
00891 ;------------------------------------------------------------------------
00892
00893 00E422 A0 00 MOV_DOWN LDY #0 ;Clear index in 256 byte blocks
00894 00E424 A6 DB LDX LENG+1 ;Get number of blocks to be moved
00895 00E426 F0 0E BEQ .LAST ;Move last (partial) block
00896
00897 00E428 B1 DC .LOOP1 LDA (SRCE),Y ;Move this byte
00898 00E42A 91 DE STA (DEST),Y
00899 00E42C C8 INY ;Point to next byte in block
00900 00E42D D0 F9 BNE .LOOP1 ;Block not done yet!
00901 00E42F E6 DD INC SRCE+1 ;Point to next block
00902 00E431 E6 DF INC DEST+1
00903 00E433 CA DEX ;Count down blocks
00904 00E434 D0 F2 BNE .LOOP1 ;Not all blocs done yet!
00905
00906 00E436 A6 DA .LAST LDX LENG ;Count remainder of last block
00907 00E438 F0 08 BEQ .EXIT ;Oh, there is no remainder!
00908
00909 00E43A B1 DC .LOOP2 LDA (SRCE),Y ;Move this byte
00910 00E43C 91 DE STA (DEST),Y
00911 00E43E C8 INY ;Point to next byte in last block
00912 00E43F CA DEX ;Count down the bytes
00913 00E440 D0 F8 BNE .LOOP2 ;Last block not done yet!
00914 00E442 60 .EXIT RTS
00915
00916 ;------------------------------------------------------------------------
00917 ; Move a part of memory up (to make room for new or longer source line)
00918 ;
00919 ; SRCE 2 Address of source data
00920 ; DEST 2 Address of destination data
00921 ; LENG 2 Holds number of bytes to move
00922 ;
00923 ;------------------------------------------------------------------------
00924
00925 00E443 A6 DB MOV_UP LDX LENG+1 ;We have started the move at the
00926 00E445 18 CLC ;end otherwise we risk
00927 00E446 8A TXA ;overwriting the source
00928 00E447 65 DD ADC SRCE+1
00929 00E449 85 DD STA SRCE+1 ;So add Length-High to source and
00930 00E44B 18 CLC ;destination address
00931 00E44C 8A TXA
00932 00E44D 65 DF ADC DEST+1
00933 00E44F 85 DF STA DEST+1
00934 00E451 E8 INX ;Allow BNE to signal the end
00935 00E452 A4 DA LDY LENG
00936 00E454 F0 0E BEQ .PAGE ;Only entire pages to be moved!
00937 00E456 88 DEY
00938 00E457 F0 07 BEQ .PART ;Move last, partial, page first!
00939 00E459 B1 DC .LOOP1 LDA (SRCE),Y ;Move one entire page
00940 00E45B 91 DE STA (DEST),Y
00941 00E45D 88 DEY ; backwards
00942 00E45E D0 F9 BNE .LOOP1 ;Page not done yet
00943 00E460 B1 DC .PART LDA (SRCE),Y ;Move first byte of page too
00944 00E462 91 DE STA (DEST),Y
00945 00E464 88 .PAGE DEY
00946 00E465 C6 DD DEC SRCE+1 ;Decrement source and destination
00947 00E467 C6 DF DEC DEST+1
00948 00E469 CA DEX
00949 00E46A D0 ED BNE .LOOP1 ;Move all pages!
00950 00E46C 60 RTS
00951
00952 ;------------------------------------------------------------------------
00953 ; Print error c=1 means its ERROR messages
00954 ;------------------------------------------------------------------------
00955
00956 00E46D A4 C6 PRINT_MSGS LDY ERROR
00957 00E46F D0 0B BNE ERRORMSGS ;normal string
00958 00E471 A0 57 PRINT_ERR LDY #<TEXT1 ;Error texts
00959 00E473 84 DC STY SRCE
00960 00E475 A0 E5 LDY #>TEXT1
00961 00E477 84 DD STY SRCE+1
00962 00E479 A8 TAY ;index to message string
00963 00E47A 80 0F BRA PRINT_SRCE
00964
00965 00E47C A9 98 ERRORMSGS LDA #<TEXT ;noramal texts
00966 00E47E 85 DC STA SRCE
00967 00E480 A9 E4 LDA #>TEXT
00968 00E482 85 DD STA SRCE+1
00969 00E484 20 8B E4 JSR PRINT_SRCE ;Print 3 characters
00970 00E487 A0 00 LDY #0 ;Save A
00971 00E489 84 C6 STY ERROR ;Clear the error now
00972
00973 00E48B B1 DC PRINT_SRCE LDA (SRCE),Y ;Get character (also GLobal Print)
00974 00E48D 48 PHA
00975 00E48E 29 7F AND #%01111111
00976 00E490 20 A9 F6 JSR WRCHAR ; and print it
00977 00E493 C8 INY ;check if it exceed 127
00978 00E494 68 PLA
00979 00E495 10 F4 BPL PRINT_SRCE ; is bit=8 =1
00980 00E497 60 RTS
00981
00982 ;------------------------------------------------------------------------
00983 ; Error Messages - TODO
00984 ;------------------------------------------------------------------------
00985
00986 TEXT .ASCII " ERROR",CR,LF + $80
00987 PNTR_ERR_SYN .ASCIS " :SYNTAX" ;Syntax error
00988 PNTR_ERR_LBL .ASCIS " :LABEL" ;Label error / no global
00989 PNTR_ERR_RNG .ASCIS " :INVALID RANGE" ;Range error
00990 PNTR_ERR_MIS .ASCIS " :MISSING PARAMETER or OPERAND" ;Missing parameter/operand
00991 PNTR_ERR_DIV .ASCIS " :DIVIDE by 0" ;Divide by 0 error
00992 PNTR_ERR_MEM .ASCIS " :MEMORY FULL" ;Memory full / illegal TA
00993 PNTR_ERR_DEF .ASCIS " :UNDEFINED LABEL" ;Undefined label
00994 PNTR_ERR_DIR .ASCIS " :ILLEGAL DIRECTIVE" ;Illegal directive error
00995 PNTR_ERR_OPE .ASCIS " :OPERAND" ;Operand error
00996 PNTR_ERR_MNE .ASCIS " :MNEMONIC " ;Mnemonic error
00997 PNTR_ERR_EXT .ASCIS " :EXTRAT DEFINATION" ;Extra definition error
00998 PNTR_ERR_WRT .ASCIS " :UNABLE TO WRITE/READ" ;Read/Write Error
00999
01000 TEXT1 .ASCIS "--------------------------"