> Startup ) 6502 Tube Emulator written in BASIC , v0.10 Initial program based on PDP11Em (+ v0.11 &x3 opcodes interface with host 2& v0.12 Uses runpath for resources <2 v0.13 Updated with same base code as PDPTube F+ v0.14 Added more updates from PDPTube P- v0.15 Added command: PORT Z: d"bugfix%=: Error in OS_GetEnv n) pr::Close_All:" at line ";: x@A$=OS_GetEnv:ver$="0.15":debug%=0:Init:A%=_DEBUG(debug%) Sbugfix%:>&FFFFF:ș "GetCommandLine" name%:$$name%,"bbcwin.exe")=0:A$="-"  A$="-":A$="" quiet%=A$<>"" k A$="":"6502 Emulator v"ver$" (C)2006 J.G.Harston"'"Memory start: &"h0(mem%,8)" MemSz: &"h0(mz%,6) W A$="":"Program space: &"h0(mbot%,6)"-&"h0(mtop%,6)" ";(mtop%-mbot%);" bytes"'  Error:A$=""  A$<>"":A%=_RUN(A$)  run%:Go  quiet%:A%=_QUIT("")  Error:A$="" *quiet%=: "65Em> "A$:cmd(A$,):0  :  Init 5d$=".":s$="/":os%>6:d$="/":s$=".":os%=32:d$="\" %bugfix%:>&FFFFF:run$=@dir$+"*" "Hrunpath$=run$: runpath$,1)="""":runpath$=runpath$,2, runpath$-2) ,1 runpath$=runpath$): d$+":",runpath$,1)) 6Ros%=32:mx%=@vdu%!208:my%=@vdu%!212:mw%=@vdu%!216:mh%=@vdu%!220:mc%=@vdu%?73+1 @Kmz%=memsize:mm%=mz%-1:mtop%=mz%:mbot%=0:run%=:trace0%=0:trace1%=&FFFF J> ctrl% 31,name% 255,mem% mz%:zp%=name%:X%=ctrl%:Y%=X%256 T+ra%=0:rx%=0:ry%=0:rp%=0:rs%=&1FF:rpc%=0 ^Fosw0%=:err%=&100:escflg%=&FF:prog%=&F800:iobase%=-1:memmax%=&F800 h; port%(7,1),port$(3): A%=0 1: port$(A%)::ports%=0 r 6850,6551 | Initial state: ="Load """+f_name(runpath$+"TOS64")+""" "+~(mem%+&F800) DA%=mem%!&FFB7 &FFFF: B%=0 &35:mem%?(B%+&200)=mem%?(A%+B%): /mem%!&F0=&800:mem%!&F4=&8000:mem%?escflg%=0 EscInit: : >ݤmemsize:A%=2^((--1024)/2): A%<&10000:=A% =&10000 : +Error:X%=ctrl%:Y%=X%256: -1:run%= K run%:pr::Close_All:" at line "+Þ,<128 <>17): -1:RegDump I =25:run%: os%=32:run%=: 23,22,mx%;my%;mw%,mh%,mc%,128:run%=: 3 =17:mem%?255=255:rp%=rp%(osw0%1):osw0%=:  run%:mem%!err%=*256:A%=<128 <>17:$(mem%+err%+7)="PDPEm: ",A%)+$+" at line "+Þ,A%(>0))+0:rpc%=err%:=17:mem%?escflg%=&FF  pr:?(P-3): : : 5cmd(A$,link%)::A$=s(A$):A$,1)="*":A$=A$,2) &( A$,1)<>"*" A$,1)<>" ":reset%=0 0 A$=""A$,1)="|": :1 IF LEFT$(A$,1)="*":OSCLI MID$(A$,2):ENDPROC D: A$,1)=".": "."+A$,2)+"\",A$>2)+"*.*",os%=32): N! A$,1)="/":A$="RUN "+A$,2) X7 uc(A$,2))="FX": A$,3) (A$,3,1)="0"):A$: b2A%=A$+" "," "):C$=uc(A$,A%-1)):T$=A$,A%+1) l_A%=" BASIC CORE DEBUG GO HELP LOAD MDUMP MDIS MEDIT QUIT RUN RESET SAVE PORT "," "+C$+" ") v A%:A%=("FN_"+C$+"(T$)"): A%=_run(C$+" "+T$,link%): : <ݤ_HELP(A$):'"6502 Emulator ";ver$: uc(A$)<>"6502":=0 i" BASIC"'" CORE "'" DEBUG ( ( ))";8'" GO ()"'" HELP" [" LOAD "'" MDUMP "'" MDIS "'" PORT ( )(?)" 1" QUIT"'" RESET ()"'" RUN " >" SAVE |+ ( ())" =0 : ݤ_PORT(A$): B% . A$="?":"Types: "port$(0)", "port$(1):=0  A$="" F A%=0 7:B%=port%(A%,0): B%: h0(B%,4);": ";port$(port%(A%,1)) :=0    ":=0  B%=("&"+uc(A$,A%))) *A$=uc(s(A$,A%+1))) 4*A%=-1: A%=A%+1: A%=7 port%(A%,0)=0 >+ port%(A%,0): 220,"All ports used":=0 Hports%=ports%+1 R1 A$=port$(0):port%(A%,0)=B%:port%(A%,1)=0:=0 \1 A$=port$(1):port%(A%,0)=B%:port%(A%,1)=1:=0 f4 IF A$=port$(2):port%(A%,0)=B%:port%(A%,1)=2:=0 p4 IF A$=port$(3):port%(A%,0)=B%:port%(A%,1)=3:=0 z0ports%=ports%-1: 220,"Unknown port type":=0 : ݤ_MDIS(A$): N%,P%,C% -addrs:P%=start%:N%=16: num%<2:size%=256 (:C%=16:h0(P%,4);" ";:A$=dis(P%) 3 A%=0 N%-1:h0(mem%!(P%+A%)&FFFF,2);" ";: @ (15-3*N%);: A%=0 N%-1:c(mem%?(P%+A%));::(7-N%);A$ RP%=(P%+N%)&FFFF:C%=C%-1:size%=size%-N%: C%=0 size%<0: size%>0:A%= A%=0  A%=27 size%<0:=0 : ݤ_MDUMP(A$): N%,P%,C% -addrs:P%=start%:N%=16: num%<2:size%=256 :C%=16:h0(P%,4);" "; - A%=0 N%-1:h0(mem%?(P%+A%),2);" ";: ( A%=0 N%-1:c(mem%?(P%+A%));:: RP%=(P%+N%)&FFFF:C%=C%-1:size%=size%-N%: C%=0 size%<0: size%>0:A%= A%=0  A%=27 size%<0:=0 $: .ݤ_MEDIT(A$):=0 8: Bݤ_SAVE(A$) Lfname:addrs V num%<2: 252,"Bad address" `( start%>=0:start%=mem%+(start%mm%) jN "SAVE """+f_name(F$)+""" "+~start%+"+"+~size%+" "+~exec%+" "+~load% t=0 ~: ݤ_LOAD(A$) #fname:addrs: num%=0:load%=-1 =_load(F$,load%,) : !ݤ_QUIT(A$): A$:halt%=:=0 =Close_All: IF os%=32:PRINT"Press SPACE to exit";:A%=GET "QUIT":=0 : 0ݤ_BASIC(A$): =FN_RUN("<65Tube$Basic> "+A$) 9"BASIC"':=_RUN(""""+runpath$+f_name("Basic")+"""") : ݤ_RESET(A$)::A%=-1 j IF FNuc(A$)="TUBE":IF client$<>"":OSCLI"Load """+client$+""" "+STR$~(mem%+&F800):memmax%=&F500:A$=""   IF memmax%<&F800 THEN 1 PRINT'$(mem%+&F805):A%=mem%!&F5FC AND &FFFF  ELSE (6'"6502 Tube Emulator": A$<>"":A%=_load(A$,-1,) 2 ENDIF <. IF FNuc(A$)="NOTUBE":memmax%=&FF00:A$="" F%'"Econet Station 128"': A%<0:=0 PIhdr%=mem%+A%: hdr%!(hdr%?7)=&29432800:B%=hdr%+9:?B%:B%=B%+1:?B%=0 Z hdr%-mem%=0:11,11 d':F$="":rp%=0:=_go n: xݤ_load( F$,A%,F%) in%=0:size%=0: A%=-1 =in%=f_openin(F$): in%=0: F%:F$=F$+s$:in%=f_openin(F$)  in% 'size%=#in%:gbpb(4,in%,hdr%,256,0) 2 hdr%!(hdr%?7)=&29432800 (hdr%?6 32)<>0 0A%=hdr%?7:A%=A%+1:hdr%?A%=0:A%=hdr%!(A%+1)  1 A%<0: <&FFFFF:ș"XOS_File",5,F$,-1 ,,A%   A%=-2: Not found   7 IF A%<0:IF F%:IF in%=0:ERROR 214,"File not found" * IF A%<0 OR F%:IF in%:CLOSE#in%:in%=0 + IF A%<0:IF F%:ERROR 252,"Bad address" "" in%: F% A%=-1:#in%:in%=0 ,' A%=-2: F%: 214,"File not found" 60 A%=-1 (A%+size%>mm%): 252,"Bad address" @1 F%:"Load """+f_name(F$)+""" "+~(mem%+A%) J=A% T: ^%syscmd(cli$): os%<>32: cli$: h% ch%,err$,tmp$:tmp$=@tmp$+Ñ+"." r- : : : =214: cli$: ,$: |+ cli$+" 2>"+tmp$:ch%=(tmp$): ch%=0: @err$=#ch%:#ch%:"Delete "+tmp$: err$,1)=",":err$,1)="."  254,err$: : ݤ_RUN(A$) L <&FFFFF:ș"XOS_File",5,A$ ,,A%:A%=A%&FFF00: A%=&FFB00=_BASIC(A$) # <&FFFFF: A%=&BBC00:A%=&8000 =_run(A$,) (ݤ_run(A$,osc%):A$=s(A$): A$="":=0 IC$=A$:fname:hdr%=zp%:A%=_load(F$,-1,): A%<0: osc%:syscmd(C$):=0 " A%=-2: 214,"File not found" rp%=1:=_go  ݤ_go ) A% = entry address as 6502 address / hdr%=>Acorn ROM header in mem%+A% address ! in% =open file being loaded 7 F$ =file being loaded or "" if already in memory &7 membot%=base%:err%=memmax%:escflg%=err%+255:B%=A% 0,membot%=&800:err%=&100:escflg%=&FF:B%=A% : hdr%!(hdr%?7)=&29432800 D Acorn ROM header N< (hdr%?6 64)=0 :#in%:in%=0: 249,"Not a language":=0 X: (hdr%?6 15)>3:#in%:in%=0: 249,"Not 6502 code":=0 bF (hdr%?6 32)<>0:B%=hdr%?7:B%=B%+1:hdr%?B%=0:B%=A%+hdr%!(B%+5) l v:prog%=A%: prog%<&8000:memtop%=memmax% memtop%=prog% %load%=A%:rpc%=A%:in%:#in%:in%=0  Go:=0 : ݤ_GO(A$): A$="":=0 QA%=&FF90:A$<>"":"[(",A$,1)):A%=hex(A$,2)) A$<>"":rpc%=hex(A$):A%=-1 (A%<>-1:rpc%=mem%?A%+256*mem%?(A%+1) )A%=A$,";"): A%:A$=A$,A%+1) A$="" *F$="":A%=rpc%:hdr%=mem%+A%:rp%=1:=_go : ݤ_CORE(A$): Dump core  8A$=f_name(s(A$,A$+" "," ")-1))):A$="":A$="core" $"Save "+A$+" "+~mem%+"+"+~mz%  SetType(A$,&FFD) *=0 4: >=ݤ_DEBUG(A$):A$="":"1=Register Dump"'"3=Single Step":=0 H7debug%=0:trace0%=0:trace1%=&FFFF: uc(A$)="OFF":=0 R,debug%=(A$):(debug%1): <9: : >8 \9A%=A$," "): A%:trace0%=hex(A$,A%+1)):A$=A$,A%+1) f,A%=A$," "): A%:trace1%=hex(A$,A%+1)) p=0 z: SetType(A$,A%): os%>8: "SetType "+A$+" "+~A%  :  ݤhex(A$) Cuc(A$,2))="&O":=("&"+h0(oct(A$,3)),8)) =("&"+uc(A$)) ݤoct(A$): A%: 0 A$>"/" A$<":":A%=A%*8+ A$,1):A$=A$,2)  (A$>"/" A$<":"):=A% :  fname RA$,1)="""":A%=A$+"""","""",2):F$=A$,2,A%-2) A%=A$+" "," "):F$=A$,A%-1) A$=s(A$,A%+1)): :  addrs +num%=0:start%=0:size%=0:load%=0:exec%=0 $A$=s(A$): A$="": .,num%=A$,"+"): num%=0:num%=A$+" "," ") 8Wstart%=hex(A$,num%-1)):load%=start%:exec%=load%:A$=s(A$,num%)):num%=1: A$="": B5 A$,1)="+":size%=0:A$=s(A$,2)) size%=start% LWnum%=A$+" "," "):size%=hex(A$,num%-1))-size%:A$=s(A$,num%+1)):num%=2: A$="": VQnum%=A$+" "," "):exec%=hex(A$,num%-1)):A$=s(A$,num%+1)):num%=3: A$="": `Gnum%=A$+" "," "):load%=hex(A$,num%-1)):A$=s(A$,num%+1)):num%=4 j t: ~SRegDump:"A=&"h0(ra%,2)" X=&"h0(rx%,2)" Y=&"h0(ry%,2)" P=&"h0(rp%,2);" "; J A%=7 0 -1:"-CZIDB5VN",(((rp%(2^A%))<>0)(A%+1))+1,1);::" " & "XY=&";:DumpLine(rx%+256*ry%):  " S=&";:DumpLine(rs%):  "PC=&";:DumpLine(rpc%) 4A%=Dis_Code(65,rpc%,mem%+rpc%):$(X%+4);(56-) 9 PRINT "2A=&";:PROCDumpLine(mem%!&2A AND&FFFF):PRINT 9 PRINT "0B=&";:PROCDumpLine(mem%!&0B AND&FFFF):PRINT 9 PRINT "39=&";:PROCDumpLine(mem%!&39 AND&FFFF):PRINT 9 PRINT "19=&";:PROCDumpLine(mem%!&19 AND&FFFF):PRINT # PRINT "15=&";FNh0(mem%?&15,2)  : "DumpLine(m%): h0(m%,4)" "; ' B%=m% m%+7: c(mem%?B%);::32 3 B%=m% m%+7: h0(mem%?(B%mm%)&FF,2)" ";:  (: 28ݤdis(A%):N%=Dis_Code(65,A%,mem%+(A%mm%)):=$(X%+4) <: F3ݤc(A%):A%=A%255: A%<32 A%>126:="." = A% P: Z"EscInit:esch%=esch%:esch%: d os%=32 nC P% 36, L% -1:[OPT 8:.escyes:mov byte [edi-1],0:mov eax,-1:ret x8.esch%:mov ecx,256:mov edi,[@vdu%-148]:mov al,27:cld >repnz scasb:jz escyes:xor eax,eax:ret:.escb%:dw 0:dw 0:]:  = esch% 31: P=0 1:P%=esch%:[OPT P*2:MOV R11,R11,LSL #1 SLDR R12,escb%:STRB R11,[R12]:MOV PC,R14:.escb%:EQUD mem%+escflg%:]::escho%=0: $EscOff:escho%=escho%:escho%: Los%<>32:ș "OS_ChangeEnvironment",9,esch%,0,0 ,escho%,escRo%,escbo%: :"ESC OFF":escho%=: esch%:mem%?escflg%=&FF:  %EscOn:escho%=escho%:escho%=0: Hos%<>32:ș "OS_ChangeEnvironment",9,escho%,escRo%,escbo%:escho%=0:  :escho%=0:"ESC ON": :