TI-H: 8080 asm to z80 asm
[Prev][Next][Index][Thread]
TI-H: 8080 asm to z80 asm
hey, i was searching on info for some c to z80 cross compiler and came
across a site that featured the "Beehive" z80 based computer, or it could
have been CPM. There was a whole crapload of source code and info and
stuff, but its all in z80 computer stuff format. well i dunno what format
its in, but i cant read it. anyways, i did find 1 file that worked, its
some converter for 8080 asm to z80 asm. i hope this helps anyone.
10 PRINT "Conversion from Intel 8080 Mnemonics to Zilog Z80":PRINT
20 INPUT "INPUT file name? ",NI$
30 INPUT "OUTPUT file name? ",NO$
40 INPUT "Does space terminate the operand (Y/N)? ",IN$
50 SPC$=" ":IF LEFT$(IN$+" ",1)="Y" THEN 80
60 IF LEFT$(IN$+" ",1)<>"N" THEN PRINT "Please answer Y)es or N)o":GOTO 40
70 SPC$=""
80 RESET:EF=0:RC=0:OPEN "I",1,NI$:OPEN "O",2,NO$
90 IF EOF(1) THEN CLOSE:STOP
100 LINE INPUT #1,IN$
110 REM
120 REM *** PARSE THE LABEL, OPERATION CODE, OPERAND, AND COMMENT
130 REM
140 IF RIGHT$(IN$,1)=" " THEN IN$=LEFT$(IN$,LEN(IN$)-1):GOTO 140
150 IL=LEN(IN$):IF IL=0 THEN IN$=";"
160 IF IL<2 OR LEFT$(IN$,1)=";" THEN 1430
170 BF=0:QF=0:LB$="":OPC$="":OPD$="":CM$=""
180 IF LEFT$(IN$,1)<>" " AND LEFT$(IN$,1)<>CHR$(9) THEN LC=1 ELSE LC=2
190 FOR IC=1 TO IL
200 CH$=MID$(IN$,IC,1)
210 IF LC<4 THEN 240
220 CM$=CM$+CH$:IF CM$=" " OR CM$=CHR$(9) THEN CM$=""
230 GOTO 360
240 IF CH$=":" AND LC=1 THEN 360
250 IF ASC(CH$)=34 OR ASC(CH$)=39 THEN QF=1-QF
260 IF QF THEN 340
270 IF CH$=";" THEN LC=4:GOTO 360
280 BL$=" ":IF LC=3 THEN BL$=SPC$
290 IF CH$<>BL$ AND CH$<>CHR$(9) THEN BF=1:GOTO 320
300 IF BF=1 THEN LC=LC+1:BF=0
310 GOTO 360
320 IF CH$ >= "a" AND CH$ <= "z" THEN CH$=CHR$(ASC(CH$)-32)
330 IF LC=3 AND CH$=";" THEN LC=4:GOTO 360
340 IF LC=1 THEN LB$=LB$+CH$:GOTO 360
350 IF LC=2 THEN OPC$=OPC$+CH$ ELSE OPD$=OPD$+CH$
360 NEXT IC
370 REM
380 REM *** CONVERT THE OPERATION CODES
390 REM
400 IF OPC$<>"LD" THEN 430
410 GOSUB 1490:IF LEFT$(B$,1)<>"(" THEN B$="("+B$+")"
420 OPD$=A$+","+B$
430 IF OPC$<>"STO" THEN 460
440 GOSUB 1490:IF LEFT$(B$,1)<>"(" THEN B$="("+B$+")"
450 OPD$=B$+","+A$:OPC$="LD"
460 IF OPC$="LHLD" THEN OPC$="LD":OPD$="HL,("+OPD$+")"
470 IF OPC$="LDED" THEN OPC$="LD":OPD$="DE,("+OPD$+")"
480 IF OPC$="LBCD" THEN OPC$="LD":OPD$="BC,("+OPD$+")"
490 IF OPC$="SHLD" THEN OPC$="LD":OPD$="("+OPD$+"),HL"
500 IF OPC$="SDED" THEN OPD$="("+OPD$+"),DE":OPC$="LD"
510 IF OPC$="SBCD" THEN OPD$="("+OPD$+"),BC":OPC$="LD"
520 IF OPC$="LDA" THEN OPC$="LD":OPD$="A,("+OPD$+")"
530 IF OPC$="LDAX" THEN OPC$="LD":GOSUB 1630:OPD$="A,("+OPD$+")"
540 IF OPC$="STA" THEN OPC$="LD":OPD$="("+OPD$+"),A"
550 IF OPC$="STAX" THEN OPC$="LD":GOSUB 1630:OPD$="("+OPD$+"),A"
560 IF (OPC$<>"MOV") AND (OPC$<>"MVI") THEN 600
570 GOSUB 1490:IF A$="M" THEN A$="(HL)"
580 IF B$="M" THEN B$="(HL)"
590 OPC$="LD":OPD$=A$+","+B$
600 IF OPC$="XRI" THEN OPC$="XOR"
610 IF OPC$="CP" THEN OPC$="CALL":OPD$="P,"+OPD$
620 IF OPC$="CZ" THEN OPC$="CALL":OPD$="Z,"+OPD$
630 IF OPC$="CNZ" THEN OPC$="CALL":OPD$="NZ,"+OPD$
640 IF OPC$="CC" THEN OPC$="CALL":OPD$="C,"+OPD$
650 IF OPC$="CNC" THEN OPC$="CALL":OPD$="NC,"+OPD$
660 IF OPC$="CPO" THEN OPC$="CALL":OPD$="PO,"+OPD$
670 IF OPC$="CPE" THEN OPC$="CALL":OPD$="PE,"+OPD$
680 IF OPC$="CM" THEN OPC$="CALL":OPD$="M,"+OPD$
690 IF (OPC$="CPI") OR (OPC$="CMP") THEN OPC$="CP":GOSUB 1580
700 IF OPC$="ADD" THEN GOSUB 1490:GOSUB 1580:IF B$="" THEN OPD$="A,"+OPD$
710 IF OPC$="DAD" THEN OPC$="ADD":GOSUB 1630:OPD$="HL,"+OPD$
720 IF OPC$="ADI" THEN OPC$="ADD":OPD$="A,"+OPD$
730 IF OPC$="DAD" THEN OPC$="ADD":OPD$="HL,"+OPD$
740 IF OPC$="SUI" OR OPC$="SUB" THEN OPC$="SUB":GOSUB 1580
750 IF OPC$="SBB" OR OPC$="SBI" THEN OPC$="SBC":GOSUB 1580:OPD$="A,"+OPD$
760 IF OPC$="ACI" THEN OPC$="ADC"
770 IF OPC$="ADC" THEN OPD$="A,"+OPD$
780 IF OPC$="DCR" THEN OPC$="DEC":GOSUB 1580
790 IF OPC$="DCX" THEN OPC$="DEC":GOSUB 1630
800 IF OPC$="INR" THEN OPC$="INC":GOSUB 1580
810 IF OPC$="INX" THEN OPC$="INC":GOSUB 1630
820 IF OPC$="CBIT" THEN OPC$="RES"
830 IF OPC$="SBIT" THEN OPC$="SET"
840 IF OPC$="ANA" THEN GOSUB 1580:OPC$="AND"
850 IF OPC$="ANI" THEN OPC$="AND"
860 IF (OPC$="ORA") OR (OPC$="ORI") THEN OPC$="OR":GOSUB 1580
870 IF (OPC$="XRA") OR (OPC$="XRI") THEN OPC$="XOR":GOSUB 1580
880 IF OPC$="CMC" THEN OPC$="CCF"
890 IF OPC$="STC" THEN OPC$="SCF"
900 IF OPC$="CMA" THEN OPC$="CPL"
910 IF OPC$="RLC" THEN OPC$="RLCA"
920 IF OPC$="RLC#" THEN OPC$="RLC"
930 IF OPC$="RRC" THEN OPC$="RRCA"
940 IF OPC$="RRC#" THEN OPC$="RRC"
950 IF OPC$="RAL" THEN OPC$="RLA"
960 IF OPC$="RAR" THEN OPC$="RRA"
970 IF OPC$="HLT" THEN OPC$="HALT"
980 IF OPC$="OUT" THEN OPD$="("+OPD$+"),A"
990 IF OPC$="OT,C" THEN OPC$="OUT":OPD$="(C),"+OPD$
1000 IF OPC$="IN" THEN OPD$="A,("+OPD$+")"
1010 IF OPC$="IN,C" THEN OPC$="IN":OPD$=OPD$+",(C)"
1020 IF OPC$="XTHL" THEN OPC$="EX":OPD$="(SP),HL"
1030 IF (OPC$="EX") AND (OPD$="AF") THEN OPD$="AF,AF'"
1040 IF OPC$="XCHG" THEN OPC$="EX":OPD$="DE,HL"
1050 IF (OPC$="PUSH") OR (OPC$="POP") THEN GOSUB 1630
1060 IF OPC$="LXI" THEN GOSUB 1490:OPD$=A$:GOSUB
1630:OPD$=OPD$+","+B$:OPC$="LD"
1070 IF OPC$="LK" THEN OPC$="LD"
1080 IF OPC$="SPHL" THEN OPC$="LD":OPD$="SP,HL"
1090 IF OPC$="RZ" THEN OPD$="Z":OPC$="RET"
1100 IF OPC$="RNZ" THEN OPD$="NZ":OPC$="RET"
1110 IF OPC$="RC" THEN OPD$="C":OPC$="RET"
1120 IF OPC$="RNC" THEN OPD$="NC":OPC$="RET"
1130 IF OPC$="RPE" THEN OPD$="PE":OPC$="RET"
1140 IF OPC$="RPO" THEN OPD$="PO":OPC$="RET"
1150 IF OPC$="RP" THEN OPD$="P":OPC$="RET"
1160 IF OPC$="RM" THEN OPD$="M":OPC$="RET"
1170 IF OPC$="RST" THEN OPD$="8*("+OPD$+")"
1180 IF OPC$="JP" THEN OPD$="P,"+OPD$
1190 IF OPC$="JZ" THEN OPC$="JP":OPD$="Z,"+OPD$
1200 IF OPC$="JNZ" THEN OPC$="JP":OPD$="NZ,"+OPD$
1210 IF OPC$="JC" THEN OPC$="JP":OPD$="C,"+OPD$
1220 IF OPC$="JNC" THEN OPC$="JP":OPD$="NC,"+OPD$
1230 IF OPC$="JPE" THEN OPC$="JP":OPD$="PE,"+OPD$
1240 IF OPC$="JPO" THEN OPC$="JP":OPD$="PO,"+OPD$
1250 IF OPC$="JM" THEN OPC$="JP":OPD$="M,"+OPD$
1260 IF OPC$="JRZ" THEN OPC$="JR":OPD$="Z,"+OPD$
1270 IF OPC$="JRNZ" THEN OPC$="JR":OPD$="NZ,"+OPD$
1280 IF OPC$="JRC" THEN OPC$="JR":OPD$="C,"+OPD$
1290 IF OPC$="JRNC" THEN OPC$="JR":OPD$="NC,"+OPD$
1300 IF OPC$="JMP" THEN OPC$="JP"
1310 IF OPC$="PCHL" THEN OPC$="JP":OPD$="(HL)"
1320 REM
1330 REM *** GENERATE THE OUTPUT RECORD
1340 REM
1350 IN$=LB$
1360 IF IN$<>"" AND OPC$<>"MACRO" AND OPC$<>"EQU" THEN IN$=IN$+":"
1370 IF (LEN(OPC$)>0) OR (LEN(OPD$)>0) OR (LEN(CM$)>0) THEN
IN$=IN$+CHR$(9)+OPC$
1380 IF (LEN(OPD$)>0) OR (LEN(CM$)>0) THEN IN$=IN$+CHR$(9)+OPD$
1390 IF LEN(CM$)=0 THEN 1430
1400 IF LEN(OPD$)<8 THEN IN$=IN$+CHR$(9)
1410 IF LEFT$(CM$,1)<>";" THEN CM$=";"+CM$
1420 IN$=IN$+CHR$(9)+CM$
1430 PRINT IN$
1440 PRINT #2,IN$
1450 GOTO 90
1460 REM
1470 REM *** SPLIT THE OPERANDS
1480 REM
1490 A$="":B$="":IF LEN(OPD$)<1 THEN RETURN
1500 LC=1:QF=-1:FOR IC=1 TO LEN(OPD$)
1505 IF MID$(OPD$,IC,1)="'" THEN QF=-QF-1
1510 IF QF AND MID$(OPD$,IC,1)="," THEN LC=2:GOTO 1530
1520 IF LC=1 THEN A$=A$+MID$(OPD$,IC,1) ELSE B$=B$+MID$(OPD$,IC,1)
1530 NEXT IC
1540 RETURN
1550 REM
1560 REM *** CHANGE MEMORY REGISTER TO (HL)
1570 REM
1580 IF OPD$="M" THEN OPD$="(HL)"
1590 RETURN
1600 REM
1610 REM *** CONVERT REGISTER PAIRS
1620 REM
1630 IF OPD$="B" THEN OPD$="BC"
1640 IF OPD$="H" THEN OPD$="HL"
1650 IF OPD$="D" THEN OPD$="DE"
1660 IF OPD$="PSW" THEN OPD$="AF"
1670 RETURN
FUZZ
David Norelid
Posse in effect, yo
-------------------
listen.to/yankovic
ICQ: 3512251
Follow-Ups: