-
Notifications
You must be signed in to change notification settings - Fork 0
/
mc6809e.asm
1327 lines (1232 loc) · 53.2 KB
/
mc6809e.asm
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
;*******************************************************************************
; Program: MC6809E
; Version: 1.20
; Written: July 15, 1990
; Updated: Friday, August 12, 1994 7:52 pm
; Author : Tony G. Papadimitriou
; Purpose: This is an enhanced version of the MC6809E emulator program
; originally written in Turbo Pascal. Because it is completely
; written in Assembly language there should be a dramatic speed
; improvement over the Pascal version.
; Note : This program requires DOS 3.x or later to run properly.
; The program will abort if a lower version is found.
; Include: This file requires the following INCLUDE files to assemble
; properly: DOS.INC BIOS.INC KBD.INC (originally supplied by Borland)
; LOADER.ASM OPCODES1.ASM OPCODES2.ASM OS9.ASM (supplied by
; Tony G. Papadimitriou)
; History: 940811 - Started 386 code optimization for speed
; The following optimizations were initiated:
; 386 intructions that are shorter and run faster
; Consecutive ClearFlag macros optimized to single ANDs
; Consecutive SetFlag macros optimized to single ORs
; Where possible, operations performed directly on 6809 memory
;*******************************************************************************
IDEAL
%TITLE "MC6809E Emulator ver. 1.20 (80386 Assembly Language)"
MODEL COMPACT
STACK 4096
P386
include "dos.inc"
include "bios.inc"
include "kbd.inc"
CarryMask = 01h
OverflowMask = 02h
ZeroMask = 04h
NegativeMask = 08h
IRQMask = 10h
HalfCarryMask = 20h
FIRQMask = 40h
EntireFlagMask = 80h
;*******************************************************************************
; Macro : GetByte
; Purpose: Get a byte in AL from the 6809 memory pointed by ES:SI
macro GetByte
mov al,[es:si]
endm GetByte
;*******************************************************************************
; Macro : GetWord
; Purpose: Get a word in AX from the 6809 memory pointed by ES:SI
macro GetWord
mov ax,[es:si]
xchg ah,al
endm GetWord
;*******************************************************************************
; Macro : PutByte
; Purpose: Put a byte in AL to the 6809 memory pointed by ES:SI
macro PutByte
mov [es:si],al
endm PutByte
;*******************************************************************************
; Macro : PutWord
; Purpose: Put a word in AX to the 6809 memory pointed by ES:SI
macro PutWord
xchg ah,al
mov [es:si],ax
endm PutWord
;*******************************************************************************
; Macro : CCarry
; Purpose: Clear Carry Flag
macro CCarry
pushf
and [CC],11111110b
popf
endm CCarry
;*******************************************************************************
; Macro : COverflow
; Purpose: Clear Overflow Flag
macro COverflow
pushf
and [CC],11111101b
popf
endm COverflow
;*******************************************************************************
; Macro : CZero
; Purpose: Clear Zero Flag
macro CZero
pushf
and [CC],11111011b
popf
endm CZero
;*******************************************************************************
; Macro : CNegative
; Purpose: Clear Negative Flag
macro CNegative
pushf
and [CC],11110111b
popf
endm CNegative
;*******************************************************************************
; Macro : CIRQ
; Purpose: Clear IRQ Flag
macro CIRQ
pushf
and [CC],11101111b
popf
endm CIRQ
;*******************************************************************************
; Macro : CHalfCarry
; Purpose: Clear Half Carry Flag
macro CHalfCarry
pushf
and [CC],11011111b
popf
endm CHalfCarry
;*******************************************************************************
; Macro : CFIRQ
; Purpose: Clear Fast IRQ Flag
macro CFIRQ
pushf
and [CC],10111111b
popf
endm CFIRQ
;*******************************************************************************
; Macro : CEntireFlag
; Purpose: Clear Entire Flag Flag
macro CEntireFlag
pushf
and [CC],01111111b
popf
endm CEntireFlag
;*******************************************************************************
; Macro : SCarry
; Purpose: Set Carry Flag
macro SCarry
pushf
or [CC],00000001b
popf
endm SCarry
;*******************************************************************************
; Macro : SOverflow
; Purpose: Set Overflow Flag
macro SOverflow
pushf
or [CC],00000010b
popf
endm SOverflow
;*******************************************************************************
; Macro : SZero
; Purpose: Set Zero Flag
macro SZero
pushf
or [CC],00000100b
popf
endm SZero
;*******************************************************************************
; Macro : SNegative
; Purpose: Set Negative Flag
macro SNegative
pushf
or [CC],00001000b
popf
endm SNegative
;*******************************************************************************
; Macro : SIRQ
; Purpose: Set IRQ Flag
macro SIRQ
pushf
or [CC],00010000b
popf
endm SIRQ
;*******************************************************************************
; Macro : SHalfCarry
; Purpose: Set Half Carry Flag
macro SHalfCarry
pushf
or [CC],00100000b
popf
endm SHalfCarry
;*******************************************************************************
; Macro : SFIRQ
; Purpose: Set Fast IRQ Flag
macro SFIRQ
pushf
or [CC],01000000b
popf
endm SFIRQ
;*******************************************************************************
; Macro : SEntireFlag
; Purpose: Set Entire Flag Flag
macro SEntireFlag
pushf
or [CC],10000000b
popf
endm SEntireFlag
FARDATA ; 64K of emulator's main memory
Memory equ 0
db 0FF00h dup(?)
Ports equ 0FF00h
db 00100h dup(?)
;*******************************************************************************
; The following table is used to determine the entry point of each routine
;*******************************************************************************
DATASEG
OpCodeAll dw mcNEG ; 00 -- NEGate
dw mcERROR ; 01 -- none
dw mcERROR ; 02 -- none
dw mcCOM ; 03 -- COMplement
dw mcLSR ; 04 -- Logical Shift Right
dw mcERROR ; 05 -- none
dw mcROR ; 06 -- ROtate Right
dw mcASR ; 07 -- Arithmetic Shift Right
dw mcASL ; 08 -- Arithmetic Shift Left (LSL)
dw mcROL ; 09 -- ROtate Left
dw mcDEC ; 0A -- DECrement
dw mcERROR ; 0B -- none
dw mcINC ; 0C -- INCrement
dw mcTST ; 0D -- TeST
dw mcJMP ; 0E -- JuMP
dw mcCLR ; 0F -- CLeaR
dw mcCASE10 ; 10 -- special case
dw mcCASE11 ; 11 -- special case
dw mcNOP ; 12 -- No OPeration
dw mcSYNC ; 13 -- SYNChronize
dw mcERROR ; 14 -- none
dw mcERROR ; 15 -- none
dw mcBRA ; 16 -- Long BRanch Always
dw mcBSR ; 17 -- Long Branch to SubRoutine
dw mcERROR ; 18 -- none
dw mcDAA ; 19 -- Decimal Addition Adjust
dw mcORCC ; 1A -- OR Condition Codes
dw mcERROR ; 1B -- none
dw mcANDCC ; 1C -- AND Condition Codes
dw mcSEX ; 1D -- Sign EXtend
dw mcEXG ; 1E -- EXGhange
dw mcTFR ; 1F -- TransFeR
dw mcBRA ; 20 -- BRanch Always
dw mcBRN ; 21 -- BRanch Never
dw mcBHI ; 22 -- BRanch if HIgher
dw mcBLS ; 23 -- BRanch if Less or Same
dw mcBHS ; 24 -- BRanch if Higher or Same
dw mcBLO ; 25 -- BRanch if LOwer
dw mcBNE ; 26 -- BRanch if Not Equal
dw mcBEQ ; 27 -- BRanch if EQual
dw mcBVC ; 28 -- BRanch if oVerflow bit Clear
dw mcBVS ; 29 -- BRanch if oVerflow bit Set
dw mcBPL ; 2A -- BRanch on PLus sign
dw mcBMI ; 2B -- BRanch on MInus sign
dw mcBGE ; 2C -- BRanch if Greater than or Equal
dw mcBLT ; 2D -- BRanch if Less Than
dw mcBGT ; 2E -- BRanch if Greater Than
dw mcBLE ; 2F -- BRanch if Less than or Equal
dw mcLEAX ; 30 -- Load Effective Address into X
dw mcLEAY ; 31 -- Load Effective Address into Y
dw mcLEAS ; 32 -- Load Effective Address into S
dw mcLEAU ; 33 -- Load Effective Address into U
dw mcPSHS ; 34 -- PuSH onto System stack
dw mcPULS ; 35 -- PULl from System stack
dw mcPSHU ; 36 -- PuSH onto User stack
dw mcPULU ; 37 -- PULl from User stack
dw mcERROR ; 38 -- none
dw mcRTS ; 39 -- ReTurn from Subroutine
dw mcABX ; 3A -- Add B to X
dw mcRTI ; 3B -- ReTurn from Interrupt
dw mcCWAI ; 3C -- Clear flags and WAit for Interrupt
dw mcMUL ; 3D -- MULtiply
dw mcERROR ; 3E -- none
dw mcSWI ; 3F -- SoftWare Interrupt
dw mcNEG ; 40 -- NEGate
dw mcERROR ; 41 -- none
dw mcERROR ; 42 -- none
dw mcCOM ; 43 -- COMplement
dw mcLSR ; 44 -- Logical Shift Right
dw mcERROR ; 45 -- none
dw mcROR ; 46 -- ROtate Right
dw mcASR ; 47 -- Arithmetic Shift Right
dw mcASL ; 48 -- Arithmetic Shift Left (LSL)
dw mcROL ; 49 -- ROtate Left
dw mcDEC ; 4A -- DECrement
dw mcERROR ; 4B -- none
dw mcINC ; 4C -- INCrement
dw mcTST ; 4D -- TeST
dw mcERROR ; 4E -- none
dw mcCLR ; 4F -- CLeaR
dw mcNEG ; 50 -- NEGate
dw mcERROR ; 51 -- none
dw mcERROR ; 52 -- none
dw mcCOM ; 53 -- COMplement
dw mcLSR ; 54 -- Logical Shift Right
dw mcERROR ; 55 -- none
dw mcROR ; 56 -- ROtate Right
dw mcASR ; 57 -- Arithmetic Shift Right
dw mcASL ; 58 -- Arithmetic Shift Left (LSL)
dw mcROL ; 59 -- ROtate Left
dw mcDEC ; 5A -- DECrement
dw mcERROR ; 5B -- none
dw mcINC ; 5C -- INCrement
dw mcTST ; 5D -- TeST
dw mcERROR ; 5E -- none
dw mcCLR ; 5F -- CLeaR
dw mcNEG ; 60 -- NEGate
dw mcERROR ; 61 -- none
dw mcERROR ; 62 -- none
dw mcCOM ; 63 -- COMplement
dw mcLSR ; 64 -- Logical Shift Right
dw mcERROR ; 65 -- none
dw mcROR ; 66 -- ROtate Right
dw mcASR ; 67 -- Arithmetic Shift Right
dw mcASL ; 68 -- Arithmetic Shift Left (LSL)
dw mcROL ; 69 -- ROtate Left
dw mcDEC ; 6A -- DECrement
dw mcERROR ; 6B -- none
dw mcINC ; 6C -- INCrement
dw mcTST ; 6D -- TeST
dw mcJMP ; 6E -- JuMP
dw mcCLR ; 6F -- CLeaR
dw mcNEG ; 70 -- NEGate
dw mcERROR ; 71 -- none
dw mcERROR ; 72 -- none
dw mcCOM ; 73 -- COMplement
dw mcLSR ; 74 -- Logical Shift Right
dw mcERROR ; 75 -- none
dw mcROR ; 76 -- ROtate Right
dw mcASR ; 77 -- Arithmetic Shift Right
dw mcASL ; 78 -- Arithmetic Shift Left (LSL)
dw mcROL ; 79 -- ROtate Left
dw mcDEC ; 7A -- DECrement
dw mcERROR ; 7B -- none
dw mcINC ; 7C -- INCrement
dw mcTST ; 7D -- TeST
dw mcJMP ; 7E -- JuMP
dw mcCLR ; 7F -- CLeaR
dw mcSUBA ; 80 -- SUBtract A
dw mcCMPA ; 81 -- CoMPare with A
dw mcSBCA ; 82 -- SuBtract with Carry from A
dw mcSUBD ; 83 -- SUBtract from D
dw mcANDA ; 84 -- AND A
dw mcBITA ; 85 -- BIT test A
dw mcLDA ; 86 -- LoaD A
dw mcERROR ; 87 -- none
dw mcEORA ; 88 -- Exclusive OR A
dw mcADCA ; 89 -- ADd with Carry to A
dw mcORA ; 8A -- OR A
dw mcADDA ; 8B -- ADD to A
dw mcCMPX ; 8C -- CoMPare with X
dw mcBSR ; 8D -- Branch to SubRoutine
dw mcLDX ; 8E -- LoaD X
dw mcERROR ; 8F -- none
dw mcSUBA ; 90 -- SUBtract A
dw mcCMPA ; 91 -- CoMPare with A
dw mcSBCA ; 92 -- SuBtract with Carry from A
dw mcSUBD ; 93 -- SUBtract from D
dw mcANDA ; 94 -- AND A
dw mcBITA ; 95 -- BIT test A
dw mcLDA ; 96 -- LoaD A
dw mcSTA ; 97 -- STore A
dw mcEORA ; 98 -- Exclusive OR A
dw mcADCA ; 99 -- ADd with Carry to A
dw mcORA ; 9A -- OR A
dw mcADDA ; 9B -- ADD to A
dw mcCMPX ; 9C -- CoMPare with X
dw mcJSR ; 9D -- Jump to SubRoutine
dw mcLDX ; 9E -- LoaD X
dw mcSTX ; 9F -- STore X
dw mcSUBA ; A0 -- SUBtract A
dw mcCMPA ; A1 -- CoMPare with A
dw mcSBCA ; A2 -- SuBtract with Carry from A
dw mcSUBD ; A3 -- SUBtract from D
dw mcANDA ; A4 -- AND A
dw mcBITA ; A5 -- BIT test A
dw mcLDA ; A6 -- LoaD A
dw mcSTA ; A7 -- STore A
dw mcEORA ; A8 -- Exclusive OR A
dw mcADCA ; A9 -- ADd with Carry to A
dw mcORA ; AA -- OR A
dw mcADDA ; AB -- ADD to A
dw mcCMPX ; AC -- CoMPare with X
dw mcJSR ; AD -- Jump to SubRoutine
dw mcLDX ; AE -- LoaD X
dw mcSTX ; AF -- STore X
dw mcSUBA ; B0 -- SUBtract A
dw mcCMPA ; B1 -- CoMPare with A
dw mcSBCA ; B2 -- SuBtract with Carry from A
dw mcSUBD ; B3 -- SUBtract from D
dw mcANDA ; B4 -- AND A
dw mcBITA ; B5 -- BIT test A
dw mcLDA ; B6 -- LoaD A
dw mcSTA ; B7 -- STore A
dw mcEORA ; B8 -- Exclusive OR A
dw mcADCA ; B9 -- ADd with Carry to A
dw mcORA ; BA -- OR A
dw mcADDA ; BB -- ADD to A
dw mcCMPX ; BC -- CoMPare with X
dw mcJSR ; BD -- Jump to SubRoutine
dw mcLDX ; BE -- LoaD X
dw mcSTX ; BF -- STore X
dw mcSUBB ; C0 -- SUBtract B
dw mcCMPB ; C1 -- CoMPare with B
dw mcSBCB ; C2 -- SuBtract with Carry from B
dw mcADDD ; C3 -- ADD to D
dw mcANDB ; C4 -- AND B
dw mcBITB ; C5 -- BIT test B
dw mcLDB ; C6 -- LoaD B
dw mcERROR ; C7 -- none
dw mcEORB ; C8 -- Exclusive OR B
dw mcADCB ; C9 -- ADd with Carry to B
dw mcORB ; CA -- OR B
dw mcADDB ; CB -- ADD to B
dw mcLDD ; CC -- LoaD D
dw mcERROR ; CD -- none
dw mcLDU ; CE -- LoaD U
dw mcERROR ; CF -- none
dw mcSUBB ; D0 -- SUBtract B
dw mcCMPB ; D1 -- CoMPare with B
dw mcSBCB ; D2 -- SuBtract with Carry from B
dw mcADDD ; D3 -- ADD to D
dw mcANDB ; D4 -- AND B
dw mcBITB ; D5 -- BIT test B
dw mcLDB ; D6 -- LoaD B
dw mcSTB ; D7 -- STore B
dw mcEORB ; D8 -- Exclusive OR B
dw mcADCB ; D9 -- ADd with Carry to B
dw mcORB ; DA -- OR B
dw mcADDB ; DB -- ADD to B
dw mcLDD ; DC -- LoaD D
dw mcSTD ; DD -- STore D
dw mcLDU ; DE -- LoaD U
dw mcSTU ; DF -- STore U
dw mcSUBB ; E0 -- SUBtract B
dw mcCMPB ; E1 -- CoMPare with B
dw mcSBCB ; E2 -- SuBtract with Carry from B
dw mcADDD ; E3 -- ADD to D
dw mcANDB ; E4 -- AND B
dw mcBITB ; E5 -- BIT test B
dw mcLDB ; E6 -- LoaD B
dw mcSTB ; E7 -- STore B
dw mcEORB ; E8 -- Exclusive OR B
dw mcADCB ; E9 -- ADd with Carry to B
dw mcORB ; EA -- OR B
dw mcADDB ; EB -- ADD to B
dw mcLDD ; EC -- LoaD D
dw mcSTD ; ED -- STore D
dw mcLDU ; EE -- LoaD U
dw mcSTU ; EF -- STore U
dw mcSUBB ; F0 -- SUBtract B
dw mcCMPB ; F1 -- CoMPare with B
dw mcSBCB ; F2 -- SuBtract with Carry from B
dw mcADDD ; F3 -- ADD to D
dw mcANDB ; F4 -- AND B
dw mcBITB ; F5 -- BIT test B
dw mcLDB ; F6 -- LoaD B
dw mcSTB ; F7 -- STore B
dw mcEORB ; F8 -- Exclusive OR B
dw mcADCB ; F9 -- ADd with Carry to B
dw mcORB ; FA -- OR B
dw mcADDB ; FB -- ADD to B
dw mcLDD ; FC -- LoaD D
dw mcSTD ; FD -- STore D
dw mcLDU ; FE -- LoaD U
dw mcSTU ; FF -- STore U
OpCode10 dw 33 dup(mcERROR) ; 00 -> 20 -- none
dw mcBRN ; 21 -- Long BRaNch
dw mcBHI ; 22 -- Long BRanch if HIgher
dw mcBLS ; 23 -- Long BRanch if Less or Same
dw mcBHS ; 24 -- Long BRanch if Higher or Same
dw mcBLO ; 25 -- Long BRanch if LOwer
dw mcBNE ; 26 -- Long BRanch if Not Equal
dw mcBEQ ; 27 -- Long BRanch if EQual
dw mcBVC ; 28 -- Long BRanch if oVerflow bit Clear
dw mcBVS ; 29 -- Long BRanch if oVerflow bit Set
dw mcBPL ; 2A -- Long BRanch on PLus sign
dw mcBMI ; 2B -- Long BRanch on MInus sign
dw mcBGE ; 2C -- Long BRanch if Greater than or Equal
dw mcBLT ; 2D -- Long BRanch if Less Than
dw mcBGT ; 2E -- Long BRanch if Greater Than
dw mcBLE ; 2F -- Long BRanch if Less than or Equal
dw 15 dup(mcERROR) ; 30 -> 3E -- none
dw mcSWI2 ; 3F -- SoftWare Interrupt 2
dw 67 dup(mcERROR) ; 40 -> 82 -- none
dw mcCMPD ; 83 -- CoMPare with D
dw 8 dup(mcERROR) ; 84 -> 8B -- none
dw mcCMPY ; 8C -- CoMPare with Y
dw mcERROR ; 8D -- none
dw mcLDY ; 8E -- LoaD Y
dw mcERROR ; 8F -- none
dw 3 dup(mcERROR) ; 90 -> 92 none
dw mcCMPD ; 93 -- CoMPare with D
dw 8 dup(mcERROR) ; 94 -> 9B -- none
dw mcCMPY ; 9C -- CoMPare with Y
dw mcERROR ; 9D -- none
dw mcLDY ; 9E -- LoaD Y
dw mcSTY ; 9F -- STore Y
dw 3 dup(mcERROR) ; A0 -> A2 none
dw mcCMPD ; A3 -- CoMPare with D
dw 8 dup(mcERROR) ; A4 -> AB -- none
dw mcCMPY ; AC -- CoMPare with Y
dw mcERROR ; AD -- none
dw mcLDY ; AE -- LoaD Y
dw mcSTY ; AF -- STore Y
dw 3 dup(mcERROR) ; B0 -> B2 none
dw mcCMPD ; B3 -- CoMPare with D
dw 8 dup(mcERROR) ; B4 -> BB -- none
dw mcCMPY ; BC -- CoMPare with Y
dw mcERROR ; BD -- none
dw mcLDY ; BE -- LoaD Y
dw mcSTY ; BF -- STore Y
dw 14 dup(mcERROR) ; C0 -> CD -- none
dw mcLDS ; CE -- LoaD S
dw mcERROR ; CF -- none
dw 14 dup(mcERROR) ; D0 -> DD -- none
dw mcLDS ; DE -- LoaD S
dw mcSTS ; DF -- STore S
dw 14 dup(mcERROR) ; E0 -> ED -- none
dw mcLDS ; EE -- LoaD S
dw mcSTS ; EF -- STore S
dw 14 dup(mcERROR) ; F0 -> FD -- none
dw mcLDS ; FE -- LoaD S
dw mcSTS ; FF -- STore S
OpCode11 dw 131 dup(mcERROR) ; 00 -> 82 -- none
dw mcCMPU ; 83 -- CoMPare with U
dw 8 dup(mcERROR) ; 84 -> 8B -- none
dw mcCMPS ; 8C -- CoMPare with S
dw 6 dup(mcERROR) ; 8D -> 92 -- none
dw mcCMPU ; 93 -- CoMPare with U
dw 8 dup(mcERROR) ; 94 -> 9B -- none
dw mcCMPS ; 9C -- CoMPare with S
dw 6 dup(mcERROR) ; 9D -> A2 -- none
dw mcCMPU ; A3 -- CoMPare with U
dw 8 dup(mcERROR) ; A4 -> AB -- none
dw mcCMPS ; AC -- CoMPare with S
dw 6 dup(mcERROR) ; AD -> B2 -- none
dw mcCMPU ; B3 -- CoMPare U
dw 8 dup(mcERROR) ; B4 -> BB -- none
dw mcCMPS ; BC -- CoMPare with S
dw 67 dup(mcERROR) ; BD -> FF -- none
;*******************************************************************************
; Messages used by the Emulator
;*******************************************************************************
Copyright db "Motorola 6809E Emulator ver. 1.20 "
db "(Limited OS-9 Level One Ver. 2.00 Emulator)",RETURN,LINEFEED
db "Copyright (c) 1990-2022 by Tony G. Papadimitriou. "
db "All Rights Reserved.",RETURN,LINEFEED
db "(Assembled on: ",??date,")",RETURN,LINEFEED
db RETURN,LINEFEED
CprghtLen = $ - Copyright
LMsg db "Loading file",RETURN,LINEFEED
LMsgLen = $ - LMsg
EMsgG db "ERROR: "
EMsgGLen = $ - EMsgG
EMsg db "Unknown error code was returned by MS-DOS",RETURN,LINEFEED
EMsgLen = $ - EMsg
EMsg0 db "Usage: MC6809E progname.s19",RETURN,LINEFEED
EMsg0Len = $ - EMsg0
EMsg1 db "Invalid Motorola S19 file format",RETURN,LINEFEED
EMsg1Len = $ - EMsg1
EMsg2 db "File not found",RETURN,LINEFEED
EMsg2Len = $ - EMsg2
EMsg3 db "Path not found",RETURN,LINEFEED
EMsg3Len = $ - EMsg3
EMsg4 db "MS-DOS reported an invalid DOS function",RETURN,LINEFEED
EMsg4Len = $ - EMsg4
EMsg5 db "Can't open file, no file handles available",RETURN,LINEFEED
EMsg5Len = $ - EMsg5
EMsg6 db "Access to file was denied",RETURN,LINEFEED
EMsg6Len = $ - EMsg6
EMsg7 db "Internal error. Please contact tonyp@ars.ath.forthnet.gr",RETURN,LINEFEED
EMsg7Len = $ - EMsg7
EMsg8 db "Bad CRC while loading file, cannot run program",RETURN,LINEFEED
EMsg8Len = $ - EMsg8
EMsg9 db "*** Invalid opcode encountered ***",RETURN,LINEFEED
EMsg9Len = $ - EMsg9
EMsg10 db "Incorrect DOS version. Must use DOS 3.x or greater",RETURN,LINEFEED
EMsg10Len = $ - EMsg10
;*******************************************************************************
; General Variables
;*******************************************************************************
PSP dw ? ; holds Program Segment Prefix
OS9_On db 1 ; flag to indicate OS9 emulation
;*******************************************************************************
; Variables used by the Emulator
;*******************************************************************************
;
; Global variables (other than the 6809 registers)
;
OpCode db ? ; Last OpCode fetched
Paged db ? ; Paged OpCode $10, or $11
PostCode db ? ; post-opcode for indexed etc.
Register db ? ; Register used as indexed (X,Y,U,S)
RegCont dw ? ; Contents of register
EffAdd dw ? ; Last calculated effective address
Timer dw ? ; Allows breakpoint setting
;
; Define the 6809 registers
;
DPR db ? ; Direct Page Register
CC db ? ; Condition Codes (flags)
label XYUS word
X dw ? ; primary index register
Y dw ? ; secondary index register
U dw ? ; User stack register
S dw ? ; System stack register
PC dw ? ; Program Counter
label D word ; 16-bit accumulator (pair A,B)
B db ? ; secondary 8-bit Accumulator (low D)
A db ? ; primary 8-bit Accumulator (high D)
CODESEG
;*******************************************************************************
; Routine: Init6809
; Purpose: Call the various functions of the program
; Input : None
; Output : None
proc Init6809
mov ax,@data ; initialize DS
mov ds,ax
mov ah,DOS_GET_PSP ; get Program Segment Prefix
int DOS_FUNCTION
mov [PSP],bx ; save PSP for later
call ClrScr
call ShwCprght
call CheckVersion
cmp ax,0 ; wrong version?
jne @@errors ; yes, report the problem
call ClearMemory
call Restart
call LoadProgram ; load programs passed as parameters
jc @@errors ; on carry set, we got errors
cmp ax,0
jne @@errors ; or if AX <> 0, we got errors
call ClrScr
mov ax,[ExecAddr] ; get the execution address
mov [PC],ax ; into the PC register
mov [Timer],0 ; if Timer<>0 break in Timer cycles
call Emulator ; else call the emulator
cmp ax,0 ; did we have errors?
jne @@errors ; yes, take care of them
mov al,0 ; no errors
jmp short @@exit ; and then exit program
@@errors: call Errors ; display error message (AX=error code)
@@exit: mov ah,DOS_TERMINATE_EXE
int DOS_FUNCTION
endp Init6809
;*******************************************************************************
; Routine: ClrScr
; Purpose: Clear the display and home the cursor
; Input : None
; Output : None
proc ClrScr
push ax ; save registers
push bx
push cx
push dx
push bp
mov ah,INT10_SCROLL_UP
mov al,0 ; entire window/screen
mov cx,0 ; start of screen
mov dx,0FFFFh ; end of screen (maximum possible)
mov bh,7 ; character attribute normal
int VIDEO_SERVICE
mov ah,2 ; BIOS set cursor location function
mov dx,0 ; cursor coordinates (top left)
mov bh,0 ; current video page
int VIDEO_SERVICE
pop bp ; restore registers
pop dx
pop cx
pop bx
pop ax
ret
endp ClrScr
;*******************************************************************************
; Routine: ShwCprght
; Purpose: Display the program copyright message
; Input : DS must point to the segment where the copyright is located
; Output : None
proc ShwCprght
mov dx,offset Copyright
mov cx,CprghtLen
call Write
ret
endp ShwCprght
;*******************************************************************************
; Routine: CheckVersion
; Purpose: Check the DOS version
; Input : None
; Output : If DOS version is < 3.x then AX = 131 (error code) else AX = 0
proc CheckVersion
push bx
push cx
mov ah,DOS_GET_DOS_VERSION
int DOS_FUNCTION
cmp al,3 ; major = 3 ?
jl @@error ; if less, get error code
cmp ah,0 ; minor = 0 ?
jl @@error ; if less, get error code
mov ax,0 ; no error code
jmp short @@exit
@@error: mov ax,131 ; Invalid DOS version error code
@@exit: pop cx
pop bx
ret
endp CheckVersion
;*******************************************************************************
; Routine: ClearMemory
; Purpose: Fill 6809 segment with zeros
; Input : None
; Output : None
proc ClearMemory
push es ; save registers
mov ax,@fardata
mov es,ax
mov di,0
mov cx,0FFFFh ; 65535 bytes
mov ax,0 ; initialization value
rep stosb
stosb ; one more for the last byte
pop es
ret
endp ClearMemory
;*******************************************************************************
; Routine: Restart
; Purpose: Initialize the 6809 registers
; Input : None
; Output : None
proc Restart
push ax ; save registers
push bx
mov ax,@fardata
mov es,ax
mov ax,0
mov [D],ax
mov [X],ax
mov [Y],ax
mov [U],ax
mov [S],ax
mov [U],ax
mov [CC],01010000b
mov [DPR],al
mov bx,0FFFEh
mov ax,[word es:Memory+bx]
xchg ah,al
mov [PC],ax
pop bx
pop ax
ret
endp Restart
;*******************************************************************************
include "loader.asm"
;*******************************************************************************
;*******************************************************************************
; Routine: Errors
; Purpose: Display an error message based on the code in AX
; Input : AX holds the error code
; Output : None
proc Errors
cmp ax,0 ; do we have an error?
jne @@skip ; error, go on and print it
mov dx,offset EMsg0 ; usage message
mov cx,EMsg0Len
call Write
jmp @@exit
@@skip: ;call Beep ; beep on error
mov dx,offset EMsgG
mov cx,EMsgGLen
call Write
cmp ax,128 ; Invalid S format?
jne @@2
mov dx,offset EMsg1
mov cx,EMsg1Len
call Write
jmp @@exit
@@2: cmp ax,2 ; File not found?
jne @@3
mov dx,offset EMsg2
mov cx,EMsg2Len
call Write
jmp @@exit
@@3: cmp ax,3 ; Path not found?
jne @@4
mov dx,offset EMsg3
mov cx,EMsg3Len
call Write
jmp @@exit
@@4: cmp ax,1 ; Invalid DOS function?
jne @@5
mov dx,offset EMsg4
mov cx,EMsg4Len
call Write
jmp short @@exit
@@5: cmp ax,4 ; No handles available?
jne @@6
mov dx,offset EMsg5
mov cx,EMsg5Len
call Write
jmp short @@exit
@@6: cmp ax,5 ; Access denied?
jne @@7
mov dx,offset EMsg6
mov dx,EMsg6Len
call Write
jmp short @@exit
@@7: cmp ax,0Ch ; Invalid access code, internal
jne @@8
mov dx,offset EMsg7
mov cx,EMsg7Len
call Write
jmp short @@exit
@@8: cmp ax,129 ; Bad CRC while loading
jne @@9
mov dx,offset EMsg8
mov cx,EMsg8Len
call Write
jmp short @@exit
@@9: cmp ax,130 ; Invalid opcode
jne @@10
mov dx,offset EMsg9
mov cx,EMsg9Len
call Write
jmp short @@exit
@@10: cmp ax,131 ; Invalid DOS version
jne @@11
mov dx,offset EMsg10
mov cx,EMsg10Len
call Write
jmp short @@exit
@@11: ; ************* add more errors here if needed ***********
@@unknown: mov dx,offset EMsg ; unknown error
mov cx,EMsgLen
call Write
@@exit: mov ax,0 ; reset error code
ret
endp Errors
;*******************************************************************************
; Routine: DirMode
; Purpose: Calculate the effective address assuming direct mode
; Input : None
; Output : SI holds the effective address in the ES segment (6809)
proc DirMode
push ax
mov ah,[DPR]
mov si,[PC]
GetByte
inc [PC]
mov si,ax
pop ax
ret
endp DirMode
;*******************************************************************************
; Routine: RelMode
; Purpose: Calculate the effective address assuming relative mode
; Input : None
; Output : SI holds the effective address in the ES segment (6809)
proc RelMode
mov si,[PC]
ret
endp RelMode
;*******************************************************************************
; Routine: IndMode
; Purpose: Calculate the effective address assuming indexed mode
; Input : None
; Output : SI holds the effective address in the ES segment (6809)
proc IndMode
push ax
push bx
push cx
mov si,[PC] ; get post-opcode
GetByte
inc [PC]
mov ah,al ; get a copy in AH
cmp al,10011111b ; special case (extended indirect)
je @@ExtIndH
and al,10011111b ; remove the register info from AL
mov [PostCode],al ; and save it for later
and ah,01100000b ; and figure out the register from AH
mov cl,5
shr ah,cl ; a number from 0 to 3 (X,Y,U,S)
mov [Register],ah ; save it for later
shl ah,1 ; multiply by two (size of XYUS)
xchg ah,al
cbw
mov bx,offset XYUS ; point to XYUS registers
add bx,ax
mov bx,[bx] ; get contents of register
mov [RegCont],bx ; and save for later
mov al,[PostCode] ; get postbyte
and al,11101111b ; turn off indirect bit for now
cmp al,10000100b ; is it no offset?
je @@noffset
test al,80h ; is it 5-bit offset?
jz @@5bit
cmp al,10001000b ; is it 8-bit offset?
je @@8bit
cmp al,10001001b ; is it 16-bit offset?
je @@16bit
cmp al,10000110b ; is it accumulator A offset?
je @@AoffH
cmp al,10000101b ; is it accumulator B offset?
je @@BoffH
cmp al,10001011b ; is it accumulator D offset?
je @@DoffH
cmp al,10000000b ; is it auto increment by 1?
je @@Inc1H
cmp al,10000001b ; is it auto increment by 2?
je @@Inc2H
cmp al,10000010b ; is it auto decrement by 1?
je @@Dec1H
cmp al,10000011b ; is it auto decrement by 2?
je @@Dec2H
cmp al,10001100b ; is it 8-bit PCR?
je @@8PCRH
cmp al,10001101b ; is it 16-bit PCR?
je @@16PCRH
mov al,[PostCode]
jmp @@Invalid ; post byte is invalid
@@ExtIndH: jmp @@ExtInd
@@AoffH: jmp @@Aoffset
@@BoffH: jmp @@Boffset
@@DoffH: jmp @@Doffset
@@Inc1H: jmp @@Inc1
@@Inc2H: jmp @@Inc2
@@Dec1H: jmp @@Dec1
@@Dec2H: jmp @@Dec2
@@8PCRH: jmp @@8PCR
@@16PCRH: jmp @@16PCR
@@noffset: mov si,[RegCont]
jmp @@Indirec
@@5bit: mov si,[RegCont]
mov al,[PostCode]