10
20 ONERRORREPORT:PRINTERL:PROCend:END
30 os%=FNfx(0,1):MODE(FNfx(135,0)DIV256)OR((HIMEM<&FFFF)AND&80):IFHIMEM<&FFFF:HIMEM=FNfx(132,0)
40 io%=(FNfx(130,0)=&FFFF)AND(os%<6):ad$="ddress":dd$="isassembl":*FX219,9
50 DIMctrl%39,data%15,zp%3,A%-1:bln%=HIMEM-A%-1500*(1-2*(HIMEM>&FFFF)):buf%=HIMEM-bln%:PROCcpu:ONERRORIFFNerr:PROCend:END
60 X%=ctrl%:Y%=X%DIV256:IFP%<PAGEORP%>HIMEM:P%=PAGE
70 REPEAT:PROChlp:UNTILFNmenu:PROCend:END
80 DEFFNerr:IFERR<0:P%=P%DIV2:O%=O%DIV2:=INKEY-1
90 REPORT:IFERR<>17:IFGET
100 IFINKEY-1:PRINT" at line ";ERLELSECLS
110 =INKEY-1
120 DEFPROCend:OSCLI"FX3":ONERROREND
130 PROCbot:*QUIT
140 ENDPROC
150 DEFFNmenu:PRINT'CHR$30"Memory: &"FNho(P%-O%,W%)TAB(19)"Origin: &"FNho(O%,W%)'"Buffer: &";~buf%TAB(18)"Buffer size: &";~bln%'
160 addr%=FNline(P%):num%=addr%-P%:REPEAT:addr%=FNline(addr%):UNTILVPOS>=ht%
170 REPEATQ$=GET$:IFQ$>"`"ANDQ$<"{":Q$=CHR$(ASCQ$-32)
180 UNTILINSTR(CHR$8+CHR$9+CHR$13+CHR$127+"*+-;= ",Q$)ORQ$>="0"
190 IFQ$=CHR$13:P%=P%+1:=0
200 IFQ$=CHR$127ORQ$=CHR$8:P%=P%-1:=0
210 IFQ$=" ":P%=P%+num%:=0
220 IF(Q$>"/"ANDQ$<":")OR(Q$>"@"ANDQ$<"G"):PROChex:=0
230 IFQ$="L":PROClst:=0
240 IFQ$="T"ORQ$="Y":PRINTMID$("MessageText",1-7*(Q$="T"),7);:INPUT": "A$:A%=P%?LENA$:$P%=A$:P%?LENA$=A%:P%?(LENA$-1)=P%?(LENA$-1)OR((Q$="Y")AND&80):P%=P%+LENA$:=0
250 IFQ$=CHR$9:Z%=Z%EOR64:=0
260 IFQ$="M":PROCm:=0
270 IFQ$="O":PROCo:=0
280 IFQ$="+"ORQ$=";":P%=P%+8:=0
290 IFQ$="-"ORQ$="=":P%=P%-8:=0
300 IFQ$="*":PROCosc:IFQ$="":=0
310 IFQ$="H":Z%=Z%EOR32:PROCcol:=0
320 IFQ$="G":INPUTLINE"Load file: "A$:IFA$<>"":OSCLI"LOAD """+A$+""" "+STR$~buf%+LEFT$("+"+STR$~bln%,os%=32):=0
330 IFQ$="P":INPUTLINE"Save file: "A$:IFA$<>"":INPUT"Length: &"Q$:OSCLI"SAVE """+A$+""" "+STR$~buf%+"+"+Q$:=0
340 IFQ$="J":Z%=(Z%AND-4)+((Z%AND3)+1)MOD3:PROCcol:=0
350 IFQ$="W":W%=VALMID$("44456784",W%,1):=0
360 IFQ$="S":PROCmde:=0
370 IFQ$="Z":IFFNDis_Name(0)="":M%=FNDis_CPU:PROCcpu:=0
380 IFQ$="R":IFio%:PROCrom:=0
390 IFQ$="Q"ORQ$="X":INPUT"Quit? "Q$:A%=(ASCQ$AND&DF)=89:Q$="":IFA%:Q$="Q"
400 =Q$="Q"
410 DEFFNline(addr%):PRINTFNho(addr%-O%,W%);" ";
420 IFio%:IFaddr%<0:FORN%=0TO7:data%?N%=FNrm(addr%+N%):NEXTELSEFORN%=0TO15STEP4:data%!N%=addr%!N%:NEXT
430 IFZ%AND64:A%=11-Z%DIV16:FORN%=0TOA%:PRINTFNho(data%?N%,2)" ";:NEXT:FORN%=0TOA%:PRINTFNc(data%?N%);:NEXT:PRINT:=addr%+A%+1
440 N%=FNDis_Code(M%,addr%-O%,data%)-1:A%=Z%AND3
450 FORB%=0TON%STEP2^A%:PRINTFNho(data%!B%,2*(2^A%));" ";:NEXT
460 PRINTTAB(W%+U%);:FORB%=0TON%:PRINTFNc(data%?B%);:NEXT
470 PRINTTAB(W%+V%);:PRINT$(X%+4)CHR$8:IF(X%?2AND64):IFVPOS<ht%:PRINT
480 =addr%+N%+1
490 DEFPROCm:PRINT"A"ad$;:INPUT": &"A$:A$=FNuc(A$):IFA$="":P%=buf%:O%=P%:ENDPROC
500 A%=EVAL("&"+A$):IFio%:IFA%<&10000:P%=(P%AND&FFFF0000)+A%+O%ELSEP%=A%+O%
510 ENDPROC
520 DEFPROCo:PRINT"A"ad$;" for code a"ad$;:INPUT" 0000: &"A$:A$=FNuc(A$):IFA$="":A$=STR$~buf%
530 IFLEFT$(A$,1)="=":O%=P%-EVAL("&"+MID$(A$,2)):ENDPROC
540 A%=P%-O%:O%=EVAL("&"+A$):P%=O%+A%:ENDPROC
550 DEFPROClst:PROCbot
560 PRINT"Start a"ad$;:INPUT": &"A$:A$=FNuc(A$):IFA$="":addr%=P%ELSEaddr%=EVAL("&"+A$)+O%
570 PRINT"End a"ad$;:INPUT": &"A$:A$=FNuc(A$):IFA$="":end%=addr%+&8000ELSEend%=EVAL("&"+A$)+O%
580 PRINT"A"ad$" for code a"ad$;:INPUT" 0000: &"A$:A$=FNuc(A$):IFA$<>"":O%=EVAL("&"+A$)
590 OSCLI"FX3":REPEATaddr%=FNline(addr%):UNTILaddr%>end%:ENDPROC
600 DEFPROChex:PRINT"Bytes: &";Q$;:REPEAT:A%=GET:IFA%>96:A%=A%AND&DF
610 IF(A%=95ORA%=8)ANDQ$<>"":VDU127:Q$=LEFT$(Q$,LENQ$-1)
620 IF((A%>47ANDA%<58)OR(A%>64ANDA%<71))ANDLENQ$<30:VDUA%:Q$=Q$+CHR$A%
630 UNTILA%=13:IFQ$<>"":REPEAT:?P%=EVAL("&"+LEFT$(Q$,2)):P%=P%+1:Q$=MID$(Q$,3):UNTILLENQ$<2:ENDPROC
640 DEFPROCosc:PROCbot:REPEAT:INPUTLINE"*"A$:OSCLIA$:VDU58:REPEATQ$=CHR$(GETAND&DF):UNTILINSTR(CHR$10+CHR$13+"GP",Q$):VDU127:UNTILASCQ$<>10:ENDPROC
650 DEFPROCrom:INPUT"ROM: &"A$:A$=FNuc(A$):IFA$="":P%=P%AND&FFFFFF:ENDPROC
660 P%=(P%AND&FFFF)OR&FF000000OR65536*EVAL("&F"+A$):ENDPROC
670 DEFPROCmde:INPUT"Mode: "A$:IFA$="":ENDPROC
680 Q%=EVAL(A$)OR&80:IFio%:IFFNfx(133,Q%)<HIMEM:ENDPROC
690 VDU22,Q%:ENDPROC
700 DEFPROCcpu:X%=ctrl%:Y%=X%DIV256:!X%=0:M$=FNDis_Name(M%)+" D"+dd$+"er":W%=(X%?3AND3)*2+4:Z%=(X%?3/4)AND31:PROCcol:ENDPROC
710 DEFPROCcol:A%=Z%DIV4:U%=A%*3+13:V%=U%+A%+6:IFA%<8:ENDPROC
720 U%=17:V%=U%+7:ENDPROC
730 DEFPROCbot:PRINTCHR$26TAB(0,ht%-8*(wd%<40)-1):ENDPROC
740 DEFPROChlp:OSCLI"FX3,16":VDU26,12:wd%=FNfx(160,10):ht%=FNfx(160,9)AND&FF
750 IFwd%>50:VDU28,wd%-29,ht%,wd%,0:PRINTSPC(14-LENM$/2);M$''"RETURN forward 1 + forward 8"'"DELETE back 1"SPC5"- back 8"'"SPACE move past code"''" M: Set memory a"ad$'" O: Set code origin"
760 IFwd%>50:PRINT" W: A"ad$" width"'" J: Data width"'" H: Hex/Oct toggle"'"TAB: Dump/list"''"0-9 A-F: Enter bytes"'" T: Enter text"'" Y: Enter message"
770 IFwd%>50:PRINT" L: List d"dd$"y"'" G: Load file"'" P: Save file"'" Z: Select CPU"'" S: Screen mode"'" R: ROM number"'" Q: Quit":VDU28,0,ht%,wd%-31,0:ENDPROC
780 PRINTSPC((wd%+1-LENM$)/2);M$:VDU28,0,ht%,wd%,ht%-5:B$=" ":C$=" ":IFFNfx(135,0)DIV256=7:B$=CHR$132:C$=CHR$135
790 PRINTB$"RETURN"C$"forward 1"SPC5;B$"+"C$"forward 8"'B$"DELETE"C$"backward 1"SPC4;B$"-"C$"backward 8"'B$"TAB"C$"DUMP/LIST"SPC8;B$"H"C$"HEX/ASCII"
800 PRINTB$"M"C$"Set memory a"ad$" "B$"O"C$"Set code offset"CHR$8'B$"T"C$"Enter text"SPC9;B$"Y"C$"Enter message"'B$"L"C$"List d"dd$"y "B$"SPC"C$"Move past code";:VDU28,0,ht%-6,wd%,1:ht%=ht%-7:ENDPROC
810 DEFFNho(A%,N%):IFZ%AND32:=FNo0(A%,N%*3/2)ELSE=FNh0(A%,N%)
820 DEFFNc(A%):A%=A%AND127:IFA%=127ORA%<32:="."ELSE=CHR$A%
830 DEFFNuc(A$):LOCALB$:IFA$="":=""
840 REPEATB$=B$+CHR$(ASCA$AND((A$<"@")OR&DF)):A$=MID$(A$,2):UNTILA$="":=B$
850 DEFFNh0(A%,N%)=RIGHT$("0000000"+STR$~A%,N%)
860 DEFFNo0(A%,N%):LOCALA$,B%,L%:IFA%<0:B%=2:A%=A%AND&7FFFFFFF
870 REPEATA$=STR$(A%AND7)+A$:A%=A%DIV8:L%=L%+3:UNTILL%>27:=RIGHT$(STR$(A%+B%)+A$,N%)
880 DEFFNfx(A%,X%):LOCALY%:Y%=X%DIV256:IFPAGE<&FFFFF:=((USR&FFF4)AND&FFFF00)DIV256
890 IFA%=135:X%=MODE:IFX%>-1:=X%*256ELSEIFA%=135:=&A00
900 IFA%=160:IFX%=10:=@vdu%!28DIV@vdu%!216-1
910 IFA%=160:IFX%=9:=@vdu%!36DIV@vdu%!220-1
920 =((USR&FFF4)AND&FFFF00)DIV256
930 DEFFNrm(!&F6):LOCALY%:Y%=?&F8+&40:IFY%AND&40:IF?&F7>&BF:?&F9=0
940 IF!&F6<0:IF?&F7>&7FORY%=&3E:=(USR&FFB9)AND&FFELSE=?!&F6
950 DEFFNDis_Name(A%):X%?3=&94:="PDP11"
960 DEFFNDis_Code(A%,Ptr%,Data%):LOCALs%,d%,c%:!X%=0:num%=2
970 c%=!Data%:s%=(c%AND&FC0)DIV64:d%=c%AND63:c%=(c%AND&F000)DIV&1000
980 $(X%+4)=FNpdp:X%?3=num%:=num%
990 DEFFNpdp
1000 IF(c%AND7)=0:IFs%>39:IFs%<52:=MID$("CLRCOMINCDECNEGADCSBCTSTRORROLASRASL",3*(s%-40)+1,3)+MID$(" B",c%DIV8+1,1)+" "+FNmr(d%)
1010 IF((c%-1)AND7)<5:=MID$("MOVCMPBITBICBIS",(c%AND7)*3-2,3)+MID$(" B",c%DIV8+1,1)+" "+FNmr(s%)+","+FNmr(d%)ELSE=EVAL("FNpdp_"+STR$~c%)
1020 DEFFNpdp_F:="FLOP "+FNmr(s%)+","+FNmr(d%)
1030 DEFFNpdp_E:="SUB "+FNmr(s%)+","+FNmr(d%)
1040 DEFFNpdp_8:IFs%<32:=MID$("BPLBMIBHIBLSBVCBVSBCCBCS",3*((s%DIV4))+1,3)+FNjr(?Data%)
1050 IFs%<40:=MID$("EMT TRAP",(s%AND&FC)-31,4)+" &"+FNh0(?Data%,2)
1060 IF(s%AND&FC)=52:=MID$("MTPSMFPDMTPDMFPS",4*s%-207,4)+" "+FNmr(d%)
1070 X%?2=128:="EQUW &"+FNh0(!Data%,4)
1080 DEFFNpdp_7
1090 IFs%<32:=MID$("MUL DIV ASH ASHC",4*(s%DIV8)+1,4)+" "+FNmr(d%)+","+FNr(s%)
1100 IFs%<40:="XOR "+FNr(s%)+","+FNmr(d%)
1110 IFs%=40:IFd%<32:=MID$("FADDFSUBFMULFDIV",4*(d%DIV8)+1,4)+" "+FNr(d%)
1120 IF(s%AND56)=56:="SOB "+FNr(s%)+","+MID$(FNjr(d%-192*(d%>31)),3)
1130 X%?2=128:="EQUW &"+FNh0(!Data%,4)
1140 DEFFNpdp_6:="ADD "+FNmr(s%)+","+FNmr(d%)
1150 DEFFNpdp_0:IFs%<32:IFs%>3:X%?2=(s%<8)AND64:=MID$("BR BNEBEQBGEBLTBGTBLE",3*(s%DIV4)-2,3)+FNjr(?Data%)
1160 IFs%=0:IFd%<7:=MID$("HALTWAITRTIBPTIOTRESETRTT",d%*4+1+(d%>2)+(d%>3)+(d%=5),4+(d%>1)-2*(d%>4))
1170 IFs%=1:X%?2=64:="JMP "+FNmr(d%)
1180 IFs%=2:IFd%<8:X%?2=64:="RTS "+FNr(d%)
1190 IFs%=2:IF(d%AND56)=24:="SPL "+STR$(d%AND7)
1200 IFs%=2:IF(d%AND48)=32:="CCC &"+FNh0(d%AND&F,2)
1210 IFs%=2:IF(d%AND48)=48:="SCC &"+FNh0(d%AND&F,2)
1220 IFs%=3:="SWAB "+FNmr(d%)
1230 IF(s%AND56)=32:="JSR "+FNr(s%AND7)+","+FNmr(d%)
1240 IFs%=52:="MARK &"+FNh0(d%,2)
1250 IF(s%AND&FC)=52:=MID$("MFPIMTPISXT ",4*s%-211,4)+" "+FNmr(d%)
1260 X%?2=128:="EQUW &"+FNh0(!Data%,4)
1270 DEFFNr(A%):A%=A%AND7:IFA%=7:="PC"ELSEIFA%=6:="SP"ELSE="R"+STR$A%
1280 DEFFNmr(A%):LOCALm%:m%=(A%AND56)DIV8:IF(A%AND7)=7:=FNpc
1290 IFm%<2:=MID$("("+FNr(A%)+")",2-m%,2*m%+2)
1300 IFm%<6:=LEFT$("@",m%AND1)+LEFT$("-",m%DIV4)+"("+FNr(A%)+")"+LEFT$("+",m%<4)
1310 num%=num%+2:=LEFT$("@",m%=7)+"&"+FNh0(Data%!(num%-2),4)+"("+FNr(A%)+")"
1320 DEFFNpc
1330 IFm%<2:=MID$("(PC)",2-m%,2*m%+2)
1340 IFm%<5:num%=num%+2:=LEFT$("@",m%=3)+"#&"+FNh0(Data%!(num%-2),4)
1350 IFm%<6:=MID$("@-(PC)",6-m%)
1360 num%=num%+2:=LEFT$("@",m%=7)+"&"+FNh0(Ptr%+num%+Data%!(num%-2),4)
1370 DEFFNjr(A%):=" &"+FNh0(Ptr%+A%*2+2+512*(A%>127),4)