-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathz80_to_6809_09.c
847 lines (827 loc) · 30.5 KB
/
z80_to_6809_09.c
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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
void getparts(char line[], char first[], char second[])
{
int ret,x,pos,pos2;
// Get first part - before comma
ret = 0;
for (x = 30; x < 50; x++) {
if (line[x] == ',') {
ret = 1;
pos = x;
}
}
if (ret == 1) {
strncpy(first, line+30, pos-30);
first[pos-30] = '\0';
}
// get second part - after comma
ret = 0;
for (x = pos; x < 50; x++) {
if (line[x] == ' ') {
ret = 1;
pos2 = x;
x = 50;
}
}
if (ret == 1) {
strncpy(second, line+pos+1, pos2-pos-1);
second[pos2-pos-1] = '\0';
}
}
/* get single value return with value in first and point indicates:
0 - register
1 - points to register mem location [register]
2 - memory location - $1e00
3 - points to memory location [$1e00]
*/
int getsingle(char line[], char first[])
{
int ret,x,pos,test = 0;
char temp[256];
int point = 0;
// Get first part - before comma
ret = 0;
for (x = 30; x < 50; x++) {
if (line[x] == ' ') {
ret = 1;
pos = x;
x = 50;
}
}
if (ret == 1) {
strncpy(first, line+30, pos-30);
first[pos-30] = '\0';
}
if (first[0] == '$') {
point = 2;
test = 1;
}
if (first[0] == '(') {
point = 3;
test = 1;
}
if ((strlen(first) == 1) || (strlen(first) == 2)) {
point = 0;
test = 1;
if (ret == 1) {
strncpy(first, line+30, pos-30);
first[pos-30] = '\0';
}
}
else {
strncpy(temp, first, 2);
temp[2] = '\0';
// Test for (HL)
if ((strncmp(temp, "(H" ,2) == 0)) {
point = 1;
test = 1;
strcpy(first, "HL");
}
}
return point;
}
int comparetor (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
void change(char* var)
{
// printf("compare command is %d\n",strcmp(var,"RL"));
if (strcmp(var, "HL") == 0) {
strcpy(var,"X");
}
if (strcmp(var, "DE") == 0) {
strcpy(var,"Y");
}
if (strcmp(var, "AF") == 0) {
strcpy(var,"A,CC");
}
if (strcmp(var, "BC") == 0) {
strcpy(var,"U");
}
// if (strcmp(var, "H") == 0) {
// strcpy(var,"A");
// }
// if (strcmp(var, "L") == 0) {
// strcpy(var,"B");
// }
}
int main(int argc, char* argv[])
{
FILE *file = NULL;
char line[256];
char newcode[256];
int lnumber, count = 0;
int ret,x,pos,point,found,store = 0;
char address[256];
char first[256];
char second[256];
char temp[256];
char oldcode[256];
char other[256] = "";
char z80[256];
char comment[256] = "";
char m6809[256] = "UNKNOWN";
char in_out[1000][25];
if (argc == 2)
file = fopen(argv[1], "r");
else {
fprintf(stderr, "error: wrong number of arguments\n"
"usage: %s textfile\n", argv[0]);
return 1;
}
lnumber = 1;
while (fgets(line, sizeof(line), file)) {
/* note that fgets don't strip the terminating \n, checking its
presence would allow to handle lines longer that sizeof(line) */
// remove the line feed at the end of 'line'
line[strcspn(line, "\n")] = 0;
strcpy(m6809,"UNKNOWN");
strcpy(other,"");
strcpy(comment,"");
if (strcmp(line, "\n") != 0) {
strcpy(newcode, "");
}
ret = strncmp(line, ";", 1);
if (ret == 0){
// find comment
ret = 0;
for (x = 0; x < strlen(line); x++) {
if (line[x] == ';') {
ret = 1;
pos = x;
}
}
if (ret == 1) {
strncpy(comment, line+pos, strlen(line)-pos);
comment[strlen(line)-pos] = '\0';
}
strcpy(newcode, comment);
}
// line of code
if ((isdigit(line[0]) == 0)) {
strcpy(newcode, line);
}
else
{
// Get oiginal code section
strncpy(oldcode, line+22, 28);
oldcode[28] = '\0';
strncpy(address, line, 4);
address[4] = '\0';
// find comment
ret = 0;
for (x = 0; x < strlen(line); x++) {
if (line[x] == ';') {
ret = 1;
pos = x;
}
}
if (ret == 1) {
strncpy(comment, line+pos+1, strlen(line)-pos);
comment[strlen(line)-pos] = '\0';
}
// Get 9 characters = mnuemonic for z80
strncpy(z80, line+22, 9);
z80[9] = '\0';
strncpy(temp, line+6, 2);
temp[2] = '\0';
//NOP = NOP or 00 data
if ((strncmp(temp, "00" ,2) == 0)) {
strcpy(m6809, "FCB $00");
//NOP = NOP or 00 data
if ((strncmp(z80, "NOP " ,4) == 0)) {
strcpy(m6809, "NOP ");
}
}
//LD = LDx or STx
store = 0;
point = 1;
strncpy(temp, line+30, 20);
temp[20] = '\0';
// check if command is LD
if ((strncmp(z80, "LD " ,4) == 0)) {
// Get first,second values
//get getparts
getparts(line, first, second);
if ((first[0] != '(') && (second[0] != '(') && ((first[0] != '$') && (second[0] != '$'))) {
strcpy(m6809, "TFR");
strcat(m6809," ");
change(first);
change(second);
strcat(m6809,second);
strcat(m6809,",");
strcat(m6809,first);
}
else {
strcpy(m6809, "LD");
if (second[0] == '$') {
strcpy(temp,"#");
strcat(temp,second);
strcpy(second,temp);
point = 0;
}
if (first[0] == '(') {
store = 1;
point = 1;
strncpy(temp, first+1, strlen(first)-2);
temp[strlen(first)-2] = '\0';
//reverse order of first, second
strcpy(first,second);
strcpy(second,temp);
strcpy(m6809, "ST");
}
if (second[0] == '(') {
point = 1;
strncpy(temp, second+1, strlen(second)-2);
temp[strlen(second)-2] = '\0';
strcpy(second, temp);
}
if (point == 1) {
strcpy(temp, "");
if (strlen(second) < 3) {
strcat(temp,",");
}
change(second);
strcat(temp, second);
strcat(temp, "");
strcpy(second, temp);
}
change(first);
strcat(m6809,first);
strcat(m6809," ");
strcat(m6809,second);
if ((strncmp(m6809, "ST#$00 ,X" ,13) == 0)) {
strcpy(m6809, "CLR ,X");
}
if ((strncmp(m6809, "ST#$00 ,Y" ,13) == 0)) {
strcpy(m6809, "CLR ,Y");
}
}
}
//JP = JMP
if ((strncmp(z80, "JP " ,4) == 0)) {
strncpy(temp, line+6, 2);
temp[2] = '\0';
if ((strncmp(temp, "C3" ,2) == 0)) {
strcpy(m6809, "LBRA ");
point = getsingle(line, first);
strcat(m6809,first);
}
else {
//get getparts
getparts(line, first, second);
if (strlen(first) == 2) {
if ((strncmp(first, "NZ" ,2) == 0)) {
strcpy(m6809, "LBNE ");
}
if ((strncmp(first, "NC" ,2) == 0)) {
strcpy(m6809, "LBCC ");
}
}
if ((strncmp(first, "C" ,1) == 0)) {
strcpy(m6809, "LBCS ");
}
if ((strncmp(first, "Z" ,1) == 0)) {
strcpy(m6809, "LBEQ ");
}
if ((strncmp(first, "M" ,1) == 0)) {
strcpy(m6809, "LBMI ");
}
strcat(m6809,second);
}
}
//DEC = DEC
if ((strncmp(z80, "DEC " ,4) == 0)) {
// Get value
point = getsingle(line, first);
// 0 - register
// 2 - memory location - $1e00
// 3 - points to memory location [$1e00]
if ((point == 0) || (point == 2) || (point == 3)) {
strcpy(temp, "DEC ");
if (strlen(first) < 3) {
strcat(temp,"");
}
change(first);
if ((strncmp(first, "A" ,1) == 0) || (strncmp(first, "B" ,1) == 0)) {
strcpy(m6809, "DEC");
strcat(m6809,first);
strcat(m6809," ");
}
else {
strcat(temp, first);
strcpy(m6809, temp);
}
}
// 1 - points to register mem location [register]
if (point == 1) {
strcpy(temp, "DEC ");
if (strlen(first) < 3) {
strcat(temp,",");
}
change(first);
strcat(temp, first);
strcat(temp, " ");
strcpy(m6809, temp);
}
if ((strncmp(m6809, "DEC X" ,9) == 0)) {
strcpy(m6809, "LEAX -1,X");
}
if ((strncmp(m6809, "DEC Y" ,9) == 0)) {
strcpy(m6809, "LEAY -1,Y");
}
}
//INC = INC
if ((strncmp(z80, "INC " ,4) == 0)) {
// Get value
point = getsingle(line, first);
// 0 - register
// 2 - memory location - $1e00
// 3 - points to memory location [$1e00]
if ((point == 0) || (point == 2) || (point == 3)) {
strcpy(temp,"INC ");
if (strlen(first) < 3) {
strcat(temp,"");
}
change(first);
if ((strncmp(first, "A" ,1) == 0) || (strncmp(first, "B" ,1) == 0)) {
strcpy(m6809, "INC");
strcat(m6809,first);
strcat(m6809," ");
}
else {
strcat(temp, first);
strcpy(m6809, temp);
}
}
// 1 - points to register mem location [register]
if (point == 1) {
strcpy(temp, "INC ");
if (strlen(first) < 3) {
strcat(temp,",");
}
change(first);
strcat(temp, first);
strcat(temp, " ");
strcpy(m6809, temp);
}
if ((strncmp(m6809, "INC X" ,9) == 0)) {
strcpy(m6809, "LEAX 1,X");
}
if ((strncmp(m6809, "INC Y" ,9) == 0)) {
strcpy(m6809, "LEAY 1,Y");
}
}
//RAR = Rotate Right, bit 0 is Copied to Carry old Carry bit to bit 7
if ((strncmp(z80, "RRA " ,4) == 0)) {
//get getparts
getparts(line, first, second);
strcpy(m6809,"RORA");
}
//RLA = Rotate Left, bit 7 is Copied to Carry old Carry bit to bit 0
if ((strncmp(z80, "RLA " ,4) == 0)) {
//get getparts
getparts(line, first, second);
strcpy(m6809,"ROLA");
} //ADD = ADD
if ((strncmp(z80, "ADD " ,4) == 0)) {
point = 0;
//get getparts
getparts(line, first, second);
strcpy(m6809,"ADD ");
change(first);
strcat(m6809,first);
strcat(m6809,"=");
strcat(m6809,first);
strcat(m6809,"+");
if (second[0] == '(') {
// point = 1;
strncpy(temp, second+1, strlen(second)-2);
temp[strlen(second)-2] = '\0';
strcpy(second, temp);
}
if (point == 1) {
strcpy(temp, "[");
change(second);
strcat(temp, second);
strcat(temp, "]");
strcpy(second, temp);
}
else {
change(second);
strcat(m6809,second);
}
if ((strncmp(m6809, "ADD A=A+" ,12) == 0)) {
strcpy(m6809, "ADDA ,");
change(second);
strcat(m6809,second);
if (second[0] == '$') {
strcpy(m6809, "ADDA #");
strcat(m6809,second);
}
}
}
//AND = AND
if ((strncmp(z80, "AND " ,4) == 0)) {
// Get value
point = getsingle(line, first);
// 0 - register
// 3 - points to memory location [$1e00]
if ((point == 0) || (point == 3)) {
strcpy(m6809,"ANDA ");
if (strncmp(first, "A", 1) == 0) {
strcpy(m6809,"TSTA");
}
else {
strcat(m6809,first);
}
}
// 2 - value - $A00
if (point == 2) {
strcpy(m6809,"ANDA #");
strcat(m6809,first);
}
// 1 - points to register mem location [register]
if (point == 1) {
strcpy(m6809,"ANDA ,");
change(first);
strcat(m6809,first);
}
}
//CP = subtraction from A but doesn't modify A
//Work out similar function with CMPA - Compare A 6809
if ((strncmp(z80, "CP " ,4) == 0)) {
// Get value
point = getsingle(line, first);
// 0 - register
// 3 - points to memory location [$1e00]
if ((point == 0) || (point == 3)) {
strcpy(m6809,"CMPA ");
strcat(m6809,first);
strcat(m6809,"_Temp");
}
// 2 - value - $A00
if (point == 2) {
strcpy(m6809,"CMPA #");
strcat(m6809,first);
}
// 1 - points to register mem location register
if (point == 1) {
strcpy(m6809,"CMPA ,");
change(first);
strcat(m6809,first);
}
}
//SBI = Subtract with borrow A <- A - byte - Carry
if ((strncmp(z80, "SBI " ,4) == 0)) {
point = 0;
//get getparts
getparts(line, first, second);
strcpy(m6809,"SBCA #");
strcat(m6809,second);
}
//SUI = Subtract Immediate from accumulator
if ((strncmp(z80, "SUI " ,4) == 0)) {
point = 0;
//get getparts
point = getsingle(line, first);
strcpy(m6809,"SUBA #");
strcat(m6809,first);
}
//SUB A = subtract A from A - same as 6809 CLRA
if ((strncmp(z80, "SUB A" ,4) == 0)) {
strcpy(m6809, "CLRA");
}
//SCF = Set Carry Flag
if ((strncmp(z80, "SCF " ,4) == 0)) {
strcpy(m6809,"ORCC #$01");
}
//CPL = Compliment the Accumulator
if ((strncmp(z80, "CPL " ,4) == 0)) {
strcpy(m6809,"COMA ");
}
//XOR = XORS A with A or with Registor or memory
if ((strncmp(z80, "XOR " ,4) == 0)) {
strcpy(m6809, "EORA ");
// Get value
point = getsingle(line, first);
strcat(m6809,first);
if ((strncmp(m6809, "EORA A" ,9) == 0)) {
strcpy(m6809,"CLRA ");
}
}
// Instructions that need more lines of code to work correctly are below...
//IN = Read value from hardware port into A
if ((strncmp(z80, "IN " ,4) == 0)) {
//get getparts
getparts(line, first, second);
strcpy(m6809,"LDA ");
strncpy(z80, line+9, 2);
z80[2] = '\0';
strcat(m6809,"IO_");
strcat(m6809,z80);
strcat(m6809,"_");
if (second[0] == '(') {
strncpy(temp, second+1, strlen(second)-2);
temp[strlen(second)-2] = '\0';
strcpy(second, temp);
}
strcat(m6809,second);
// Let's see if it's new and if so add it to the bottom of the table
found = 0;
strncpy(temp, m6809+8, strlen(m6809)-8);
temp[strlen(m6809)-8] = '\0';
for (x = 0; x < count ; x++) {
if (strcmp(temp,in_out[x]) == 0) {
found = 1;
x = count;
}
}
if (found == 0) {
// printf("Adding-%s\n",temp);
strcpy(in_out[count],temp);
count++;
}
}
//OUT = Store value to hardware port from A
if ((strncmp(z80, "OUT " ,4) == 0)) {
//get getparts
getparts(line, first, second);
strcpy(m6809,"STA ");
strncpy(z80, line+9, 2);
z80[2] = '\0';
strcat(m6809,"IO_");
strcat(m6809,z80);
strcat(m6809,"_");
if (first[0] == '(') {
strncpy(temp, first+1, strlen(first)-2);
temp[strlen(first)-2] = '\0';
strcpy(first, temp);
}
strcat(m6809,first);
// Let's see if it's new and if so add it to the bottom of the table
found = 0;
strncpy(temp, m6809+8, strlen(m6809)-8);
temp[strlen(m6809)-8] = '\0';
for (x = 0; x < count ; x++) {
if (strcmp(temp,in_out[x]) == 0) {
found = 1;
x = count;
}
}
if (found == 0) {
// printf("Adding-%s\n",temp);
strcpy(in_out[count],temp);
count++;
}
}
//DAA = convert the A register into two BCD values 4 bits each
if ((strncmp(z80, "DAA " ,4) == 0)) {
strcpy(m6809, "DAA ");
strncpy(z80, line+30, 2);
z80[2] = '\0';
strcat(m6809,z80);
}
//CALL = LBSR
if ((strncmp(z80, "CALL" ,4) == 0)) {
strncpy(temp, line+6, 2);
temp[2] = '\0';
if ((strncmp(temp, "CD" ,2) == 0)) {
strcpy(m6809, "LBSR ");
point = getsingle(line, first);
strcat(m6809,first);
}
else {
//get getparts
getparts(line, first, second);
if (strlen(first) == 2) {
if ((strncmp(first, "NZ" ,2) == 0)) { // if Z = 0
x = (int)strtol(address, NULL, 16);
x = x + 3;
sprintf(temp, "%04X", x);
strcpy(other, " BEQ $");
strcat(other,temp);
strcat(other," ;");
strcat(other,address);
strcat(other," -");
strcat(other,comment);
strcat(other,"\n");
strcpy(address,"****");
strcpy(comment," Added for 6809 worakaround");
strcpy(m6809, "LBSR ");
}
if ((strncmp(first, "NC" ,2) == 0)) { // if C = 0
x = (int)strtol(address, NULL, 16);
x = x + 3;
sprintf(temp, "%04X", x);
strcpy(other, " BCS $");
strcat(other,temp);
strcat(other," ;");
strcat(other,address);
strcat(other," -");
strcat(other,comment);
strcat(other,"\n");
strcpy(address,"****");
strcpy(comment," Added for 6809 worakaround");
strcpy(m6809, "LBSR ");
}
}
if ((strncmp(first, "C" ,1) == 0)) { // if C = 1
x = (int)strtol(address, NULL, 16);
x = x + 3;
sprintf(temp, "%04X", x);
strcpy(other, " BCC $");
strcat(other,temp);
strcat(other," ;");
strcat(other,address);
strcat(other," -");
strcat(other,comment);
strcat(other,"\n");
strcpy(address,"****");
strcpy(comment," Added for 6809 worakaround");
strcpy(m6809, "LBSR ");
}
if ((strncmp(first, "Z" ,1) == 0)) { // if Z = 1
x = (int)strtol(address, NULL, 16);
x = x + 3;
sprintf(temp, "%04X", x);
strcpy(other, " BNE $");
strcat(other,temp);
strcat(other," ;");
strcat(other,address);
strcat(other," -");
strcat(other,comment);
strcat(other,"\n");
strcpy(address,"****");
strcpy(comment," Added for 6809 worakaround");
strcpy(m6809, "LBSR ");
}
// if ((strncmp(first, "M" ,1) == 0)) { // if M = 1
// strcpy(m6809, "LBSR based on LBMI ");
// }
strcat(m6809,second);
}
}
//PUSH = PSHS
if ((strncmp(z80, "PUSH" ,4) == 0)) {
strcpy(m6809, "PSHS ");
strncpy(z80, line+30, 2);
z80[2] = '\0';
change(z80);
strcat(m6809,z80);
}
//POP = PULS
if ((strncmp(z80, "POP " ,4) == 0)) {
strcpy(m6809, "PULS ");
strncpy(z80, line+30, 2);
z80[2] = '\0';
change(z80);
strcat(m6809,z80);
}
//EI = Enable Interrupts
if ((strncmp(z80, "EI " ,4) == 0)) {
strcpy(m6809, "ANDCC #$AF");
strncpy(z80, line+30, 2);
z80[2] = '\0';
strcat(m6809,z80);
}
//RET = Return from subroutine or Return from Interrupt
if ((strncmp(z80, "RET " ,4) == 0)) {
strncpy(temp, line+6, 2);
temp[2] = '\0';
if ((strncmp(temp, "C9" ,2) == 0)) {
strcpy(m6809, "RTS ");
point = getsingle(line, first);
strcat(m6809,first);
}
else {
// Get value
point = getsingle(line, first);
if (strlen(first) == 2) {
if ((strncmp(first, "PE" ,2) == 0)) {
strcpy(m6809, "RTS - If PE is set ");
}
if ((strncmp(first, "NZ" ,2) == 0)) {
strcpy(m6809, "RTS - If NZ is set BNE to RTS address ");
}
if ((strncmp(first, "NC" ,2) == 0)) {
strcpy(m6809, "RTS - If NC is set BCC to RTS address ");
}
}
if ((strncmp(first, "C" ,1) == 0)) {
strcpy(m6809, "RTS - If C is set BCS to RTS address ");
}
if ((strncmp(first, "M" ,1) == 0)) {
strcpy(m6809, "RTS - If M is set ");
}
if ((strncmp(first, "Z" ,1) == 0)) {
strcpy(m6809, "RTS - If Z is set BEQ to RTS address ");
}
}
}
//EX = Exchange registers or memory pointed to
if ((strncmp(z80, "EX " ,4) == 0)) {
point = 0;
//get getparts
getparts(line, first, second);
strcpy(m6809,"EXG ");
change(first);
strcat(m6809,first);
strcat(m6809,",");
change(second);
strcat(m6809,second);
}
//OR = ORA with operand
if ((strncmp(z80, "OR " ,4) == 0)) {
// Get value
point = getsingle(line, first);
// 0 - register
if (point == 0) {
strcpy(m6809,"ORA Register - need tweaking ");
strcat(m6809,first);
}
// 2 - value - $A00
if (point == 2) {
strcpy(m6809,"ORA #");
strcat(m6809,first);
}
// 1 - points to register mem location [register]
// 3 - points to memory location [$1e00]
if (point == 1) {
strcpy(m6809,"ORA ,");
change(first);
strcat(m6809,first);
}
if (point == 3) {
strcpy(m6809,"ORA ");
strcat(m6809,first);
}
}
//PCHL = Load Program Counter , TFR HL,PC
if ((strncmp(z80, "PCHL" ,4) == 0)) {
//get getparts
getparts(line, first, second);
strcpy(m6809,"TFR HL,PC transfer HL to Program counter - Fix");
strcat(m6809,second);
}
//ADC = ADD two operands plus the carry flag store it back into first operand
if ((strncmp(z80, "ADC " ,4) == 0)) {
point = 0;
//get getparts
getparts(line, first, second);
strcpy(m6809,"ADC ");
strcat(m6809,first);
strcat(m6809,",");
strcat(m6809,second);
strcat(m6809," - Fix");
}
//RRCA = Rotate Right, Copy bit 0 to Carry, Copy bit 0 to bit 1
if ((strncmp(z80, "RRCA" ,4) == 0)) {
//get getparts
getparts(line, first, second);
strcpy(m6809,"RORA");
}
//RLCA = Rotate Left, Copy bit 7 to Carry, Copy bit 7 to bit 0
if ((strncmp(z80, "RLCA" ,4) == 0)) {
//get getparts
getparts(line, first, second);
strcpy(m6809,"ROLA");
}
if ((strncmp(m6809, "UNKNOWN" ,7) == 0)) {
printf("error: unknown instruction -%s-\n"
"address: %s\n"
"line: %s\n", z80, address,line);
exit(-2);
}
strcpy(temp," ");
strcat(temp,m6809);
strcpy(m6809,temp);
strcat(m6809," ");
strncpy(temp, m6809, 50);
temp[50] = '\0';
strcpy(m6809,temp);
strcpy(temp,";");
strcat(m6809,temp);
strcat(other,m6809);
strcpy(m6809,other);
strcat(m6809,address);
strcat(m6809," -");
strcat(m6809,oldcode);
strcat(m6809,comment);
strcat(newcode,m6809);
}
// printf("%s\n%s\n", line, newcode);
printf("%s\n", newcode);
lnumber++;
}
printf("; IN/OUT pointers (amnually have to set):\n");
for (x = 0; x < count ; x++) {
printf("%-20sFCB $00\n",in_out[x]);
}
fclose(file);
return 0;
}