1 '
2 ' Copyright 1996 Paul Hsieh. All rights reserved.
3 '
4 ' This program is public domain, subject to the conditions that any use made
5 ' of it that results in a derivative work or product must credit the author,
6 ' Paul Hsieh and that this source never be distributed without these comments
7 ' appearing intact at the top of the program.
8 '
10 DIM AR[16]:KEY OFF:H$="0123456789ABCDEF"
20 A$="00 00":OPEN "INST.OUT" FOR OUTPUT AS #2
30 OPEN "oc.src" FOR OUTPUT AS #1
40 PRINT#1,"a"
50 PRINT#1,"db "+A$+" 00 00 00 00 "
60 PRINT#1,""
70 PRINT#1,"u100 10f"
80 PRINT#1,"q"
90 CLOSE #1
100 SHELL "debug < oc.src > oc.out"
110 OPEN "oc.out" FOR INPUT AS #1
120 FOR I=1 TO 9:LINE INPUT #1,A$:NEXT
130 CLOSE #1
140 B$=MID$(A$,25,255)
150 C$=MID$(A$,11,14):E$=C$:IF C$="" THEN C=2:GOTO 190
160 C=0:WHILE ASC(C$)<>ASC(" ")
170 AR[C]=VAL("&h"+LEFT$(C$,2)):C$=MID$(C$,3,255):C=C+1
180 WEND:GOSUB 250:PRINT#2,E$;":";B$
190 FOR T=C TO 16:AR[T]=&H0:NEXT
200 C=C1:AR[C]=AR[C]+1:IF AR[C]>&HFF AND C>0 THEN AR[C]=&H0:GOTO 200
210 IF C<=0 AND AR[C]>&HFF THEN CLOSE #2:END
220 IF C=0 THEN PRINT AR[C]
230 A$="":FOR I=0 TO 15:A$=A$+HEX$(AR[I])+" ":NEXT I
240 GOTO 30
250 OP=0:X=INSTR(B$,","):IF X=0 OR MID$(B$,X+1,1)="[" THEN GOTO 290
260 D$=MID$(B$,X+1,255)+" ":IF INSTR(H$,MID$(D$,2,1))=0 THEN 290
270 OP=1:IF INSTR(H$,MID$(D$,4,1)) THEN B$=LEFT$(B$,X)+"imm16":OP=OP+1:GOTO 290
280 B$=LEFT$(B$,X)+"imm8"
290 X=1
300 X=INSTR(X,B$,"]"):IF X=0 THEN GOTO 340
310 IF INSTR(H$,MID$(B$,X1,1))=0 THEN GOTO 340
320 OP=OP+1:IF INSTR(H$,MID$(B$,X3,1))=0 THEN B$=LEFT$(B$,X3)+"ofs8"+MID$(B$,X,255):GOTO 340
330 OP=OP+1:B$=LEFT$(B$,X5)+"ofs16"+MID$(B$,X,255)
340 REM
350 IF X>0 THEN X=INSTR(X+1,B$,"["):IF X>0 THEN GOTO 300
360 X=INSTR(B$,":"):IF X<6 THEN GOTO 380
370 IF OP=0 AND INSTR(H$,MID$(B$,X1,1)) AND INSTR(H$,MID$(B$,X+1,1)) THEN B$=LEFT$(B$,X5)+" abs16:16":OP=OP+4
380 IF OP=0 AND LEFT$(B$,3)="RET" AND INSTR(H$,MID$(E$,5,1)) THEN OP=OP+2:B$=LEFT$(B$,4)+" imm16"
390 IF OP<>0 OR LEFT$(B$,1)<>"J" THEN GOTO 420
400 IF INSTR(H$,MID$(E$,5,1)) THEN OP=OP+2:B$=LEFT$(B$,3)+" reladdr16":GOTO 420
410 IF VAL("&H"+LEFT$(E$,2))<&HFE THEN OP=OP+1:B$=LEFT$(B$,3)+" reladdr8"
420 IF OP=0 AND LEFT$(B$,4)="CALL" THEN IF INSTR(H$,MID$(E$,5,1)) THEN OP=OP+2:B$=LEFT$(B$,4)+" reladdr16"
430 IF OP=0 AND LEFT$(B$,3)="INT" AND INSTR(H$,MID$(E$,3,1)) THEN OP=OP+1:B$=LEFT$(B$,4)+" imm8"
440 IF OP=0 AND LEFT$(B$,2)="AA" AND INSTR(H$,MID$(E$,3,1)) THEN OP=OP+1:B$=LEFT$(B$,4)+" imm8"
450 IF OP=0 AND LEFT$(B$,4)="LOOP" AND INSTR(H$,MID$(E$,3,1)) THEN OP=OP+1:B$=LEFT$(B$,6+(MID$(B$,5,1)=CHR$(9)))+" reladdr8"
460 IF OP=0 AND LEFT$(B$,3)="OUT" AND INSTR(H$,MID$(E$,3,1)) THEN OP=OP+1:B$=LEFT$(B$,3)+" imm8,AL"
470 REM
480 C=COP:RETURN
