> 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:o0(P%,6);" ";:A$=dis(P%) 7 A%=0 N%-1 2:o0(mem%!(P%+A%)&FFFF,6);" ";: A(21-3.5*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 7A%=A$,";"):rpc%=hex(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 : =ݤ_DEBUG(A$):A$="":"1=Register Dump"'"3=Single Step":=0  7debug%=0:trace0%=0:trace1%=&FFFF: uc(A$)="OFF":=0 ,debug%=(A$):(debug%1): <9: : >8  9A%=A$," "): A%:trace0%=hex(A$,A%+1)):A$=A$,A%+1) *,A%=A$," "): A%:trace1%=hex(A$,A%+1)) 4=0 >: HSetType(A$,A%): os%>8: R"SetType "+A$+" "+~A% \ f: p ݤhex(A$) zCuc(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$+" "," ") Wstart%=hex(A$,num%-1)):load%=start%:exec%=load%:A$=s(A$,num%)):num%=1: A$="": 5 A$,1)="+":size%=0:A$=s(A$,2)) size%=start% Wnum%=A$+" "," "):size%=hex(A$,num%-1))-size%:A$=s(A$,num%+1)):num%=2: A$="": Qnum%=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 . 8: BSRegDump:"A=&"h0(ra%,2)" X=&"h0(rx%,2)" Y=&"h0(ry%,2)" P=&"h0(rp%,2);" "; LJ A%=7 0 -1:"-CZIDB5VN",(((rp%(2^A%))<>0)(A%+1))+1,1);::" " V& "XY=&";:DumpLine(rx%+256*ry%): ` " S=&";:DumpLine(rs%): j "PC=&";:DumpLine(rpc%) t4A%=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)" ";:  : 8ݤdis(A%):N%=Dis_Code(65,A%,mem%+(A%mm%)):=$(X%+4) : 3ݤc(A%):A%=A%255: A%<32 A%>126:="." = A% : "EscInit:esch%=esch%:esch%: ( os%=32 2C P% 36, L% -1:[OPT 8:.escyes:mov byte [edi-1],0:mov eax,-1:ret <8.esch%:mov ecx,256:mov edi,[@vdu%-148]:mov al,27:cld F>repnz scasb:jz escyes:xor eax,eax:ret:.escb%:dw 0:dw 0:]: P Z= esch% 31: P=0 1:P%=esch%:[OPT P*2:MOV R11,R11,LSL #1 dSLDR R12,escb%:STRB R11,[R12]:MOV PC,R14:.escb%:EQUD mem%+escflg%:]::escho%=0: n$EscOff:escho%=escho%:escho%: xLos%<>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": : > 6502 : (Go:abort%=:halt%=0:run%=:EscOff (b:(debug%1): rpc%>=trace0% rpc%<=trace1%:x%=:y%=:30:RegDump:31,x%,y%:(debug%2): 2|B%=mem%?rpc%:rpc%=rpc%+1: ("FNm"+~(B%&1C)+"+FN_"+~(B%(((B%1)<>1)&E3))):EscOn:run%=: quiet% abort%:RegDump < F: P: Z!ݤbr(A%):rpc%=rpc%+1:A%=0:=0 d9mem%?(rpc%-1)<128:rpc%=(rpc%+mem%?(rpc%-1))&FFFF:=0 n*rpc%=(rpc%+mem%?(rpc%-1)-256)&FFFF:=0 x: : @ݤm0 :A%=(mem%!((mem%?rpc%+rx%)&FF))&FFFF:=0 : (zp,X) @ݤm4 :A%=mem%?rpc%:=0 : zp @ݤm8 :A%=rpc%:=0 : #n ?ݤmC :A%=(mem%!rpc%)&FFFF:rpc%=rpc%+1:=0 : abs Bݤm10:A%=(mem%!(mem%?rpc%)+ry%)&FFFF:=0 : (zp),Y @ݤm12:A%=(mem%!(mem%?rpc%))&FFFF:=0 : (zp) @ݤm14:A%=(mem%?rpc%+rx%)&FF:=0 : zp,X ?ݤm18:A%=(mem%!rpc%+ry%)&FFFF:rpc%=rpc%+(B%1):=0 : abs,Y Aݤm1C:A%=(mem%!rpc%+rx%)&FFFF:rpc%=rpc%+1:=0 : abs,X : : Sݤ_1 :ra%=ra%mem%?A%:rp%=(rp%&7D)(ra%128)((ra%=0)2):rpc%=rpc%+1:=0 : ORA Rݤ_21:ra%=ra%mem%?A%:rp%=(rp%&7D)(ra%128)((ra%=0)2):rpc%=rpc%+1:=0: AND Rݤ_41:ra%=ra%mem%?A%:rp%=(rp%&7D)(ra%128)((ra%=0)2):rpc%=rpc%+1:=0: EOR ݤ_61:ra%=ra%+mem%?A%+(rp%1):rp%=(rp%254)+(ra%256):ra%=ra%255:rp%=(rp%&3D)(ra%128)(((ra%128)2)(ra%64))((ra%=0)2):rpc%=rpc%+1:=0 : ADC "Tݤ_81:B%=&8A:=_8A io_wr(A%,ra%):rpc%=rpc%+1:=0 : STA ,Sݤ_A1:ra%=io_rd(A%):rp%=(rp%&7D)(ra%128)((ra%=0)2):rpc%=rpc%+1:=0 : LDA 6ݤ_C1:A%=ra%-mem%?A%:rp%=(rp%254)+(((A%256)256)256):A%=A%255:rp%=(rp%&3D)(A%128)((A%=0)2):rpc%=rpc%+1:=0 : CMP @ݤ_E1:ra%=ra%-mem%?A%-(1-(rp%1)):rp%=(rp%254)+(((ra%256)256)256):ra%=ra%255:rp%=(rp%&3D)(ra%128)(((ra%128)2)(ra%64))((ra%=0)2):rpc%=rpc%+1:=0 : SBC J: T@ݤ_12:=m12+_1 : ORA (zp) ^@ݤ_32:=m12+_21 : AND (zp) h@ݤ_52:=m12+_41 : EOR (zp) r@ݤ_72:=m12+_61 : ADC (zp) |@ݤ_92:=m12+_81 : STA (zp) @ݤ_B2:=m12+_A1 : LDA (zp) @ݤ_D2:=m12+_C1 : CMP (zp) @ݤ_F2:=m12+_E1 : SBC (zp) : : Vݤ_8 :mem%?rs%=rp%:rs%=rs%-1:=0 : PHP Vݤ_28:rs%=rs%+1:rp%=mem%?rs%:=0 : PLP Vݤ_48:mem%?rs%=ra%:rs%=rs%-1:=0 : PHA Vݤ_5A:mem%?rs%=ry%:rs%=rs%-1:=0 : PHY Nݤ_68:rs%=rs%+1:ra%=mem%?rs%:rp%=(rp%&7D)(ra%128)((ra%=0)2):=0 : PLA Nݤ_7A:rs%=rs%+1:ry%=mem%?rs%:rp%=(rp%&7D)(ry%128)((ry%=0)2):=0 : PLY Vݤ_DA:mem%?rs%=rx%:rs%=rs%-1:=0 : PHX Nݤ_FA:rs%=rs%+1:rx%=mem%?rs%:rp%=(rp%&7D)(rx%128)((rx%=0)2):=0 : PLX : : 8ݤ_10:=br((rp%128)128) : BPL &:ݤ_30:=br(rp%128) : BMI 08ݤ_50:=br((rp%64)64) : BVC ::ݤ_70:=br(rp%64) : BVS D<ݤ_80:=br(1) : BRA N8ݤ_90:=br((rp%1)1) : BCC X:ݤ_B0:=br(rp%1) : BCS b8ݤ_D0:=br((rp%2)2) : BNE l:ݤ_F0:=br(rp%2) : BEQ v: : ;ݤ_18:rp%=rp%&FE:=0 : CLC <ݤ_38:rp%=rp%1:=0 : SEC ;ݤ_58:rp%=rp%&FB:=0 : CLI <ݤ_78:rp%=rp%4:=0 : SEI ;ݤ_B8:rp%=rp%&BF:=0 : CLV ;ݤ_D8:rp%=rp%&F7:=0 : CLD 8ݤ_F8:rp%=rp%8:"**BCD not supported***":=0 : SED : : ݤ_0:rpc%=rpc%+1:rs%=rs%-3:mem%?(rs%+1)=rp%&10:mem%?(rs%+2)=rpc%:mem%?(rs%+3)=rpc%256:rpc%=(mem%!&FFFE)&FFFF:rp%=rp%4:=0 : BRK eݤ_20:a%=mem%!rpc%:rpc%=rpc%+1:rs%=rs%-2:mem%?(rs%+1)=rpc%:mem%?(rs%+2)=rpc%256:rpc%=a%&FFFF:=0  : JSR Tݤ_40:rp%=mem%?(rs%+1):rpc%=(mem%!(rs%+2))&FFFF:rs%=rs%+3:rpc%=rpc%+1:=0 : RTI  Iݤ_4C:rpc%=A%:=0 : JMP abs Cݤ_60:rpc%=(mem%!(rs%+1))&FFFF:rs%=rs%+2:rpc%=rpc%+1:=0 : RTS  Iݤ_6C:rpc%=(mem%!A%)&FFFF:=0 : JMP (abs) *Kݤ_7C:rpc%=(mem%!A%)&FFFF:=0 : JMP (abs,X) 4Eݤ_EA:=0 : NOP >: H: RKݤ_8A:ra%=rx%:rp%=(rp%&7D)(ra%128)((ra%=0)2):=0 : TXA \Kݤ_98:ra%=ry%:rp%=(rp%&7D)(ra%128)((ra%=0)2):=0 : TYA fSݤ_9A:rs%=rx%+&100:=0 : TXS pKݤ_A8:ry%=ra%:rp%=(rp%&7D)(ry%128)((ry%=0)2):=0 : TAY zKݤ_AA:rx%=ra%:rp%=(rp%&7D)(rx%128)((rx%=0)2):=0 : TAX Iݤ_BA:rx%=rs%&FF:rp%=(rp%&7D)(rx%128)((rx%=0)2):=0 : TSX : : Iݤ_1A:ra%=(ra%+1)&FF:rp%=(rp%&7D)(ra%128)((ra%=0)2):=0 : INC A Iݤ_3A:ra%=(ra%-1)&FF:rp%=(rp%&7D)(ra%128)((ra%=0)2):=0 : DEC A Gݤ_88:ry%=(ry%-1)&FF:rp%=(rp%&7D)(ry%128)((ry%=0)2):=0 : DEY Gݤ_C8:ry%=(ry%+1)&FF:rp%=(rp%&7D)(ry%128)((ry%=0)2):=0 : INY Gݤ_CA:rx%=(rx%-1)&FF:rp%=(rp%&7D)(rx%128)((rx%=0)2):=0 : DEX Gݤ_E8:rx%=(rx%+1)&FF:rp%=(rp%&7D)(rx%128)((rx%=0)2):=0 : INX : ݤ_C6: : DEC zp ݤ_CE: : DEC abs ݤ_D6: : DEC zp,X ݤ_DE: : DEC abs,X Xmem%?A%=(mem%?A%-1)&FF:rp%=(rp%&7D)((mem%?A%)128)((mem%?A%=0)2):rpc%=rpc%+1:=0 : $ݤ_E6: : INC zp .ݤ_EE: : INC abs 8ݤ_F6: : INC zp,X Bݤ_FE: : INC abs,X LXmem%?A%=(mem%?A%+1)&FF:rp%=(rp%&7D)((mem%?A%)128)((mem%?A%=0)2):rpc%=rpc%+1:=0 V: `: jݤ_A2:A%=rpc% : LDX #n tݤ_A6: : LDX zp ~ݤ_AE: : LDX abs 3ݤ_B6:A%=(mem%?rpc%+ry%)&FF : zp,X 4ݤ_BE:A%=(A%-rx%+ry%)&FFFF:rpc%=rpc%+1 : abs,Y Brx%=mem%?A%:rp%=(rp%&7D)(rx%128)((rx%=0)2):rpc%=rpc%+1:=0 : ݤ_A0:A%=rpc% : LDY #n ݤ_A4: : LDY zp ݤ_AC: : LDY abs ݤ_B4: : LDY zp,X ݤ_BC: : LDY abs,X Bry%=mem%?A%:rp%=(rp%&7D)(ry%128)((ry%=0)2):rpc%=rpc%+1:=0 : : ݤ_86: : STX zp  ݤ_8E: : STX abs +ݤ_96:A%=(A%-rx%+ry%)&FFFF : STX zp,Y mem%?A%=rx%:rpc%=rpc%+1:=0 (: 2ݤ_84: : STY zp <ݤ_8C: : STY abs Fݤ_94: : STY zp,X Pmem%?A%=ry%:rpc%=rpc%+1:=0 Z: d: n'ݤ_64: : CLR zp x)ݤ_74: : CLR zp,X &ݤ_9C:A%=(A%-rx%)&FFFF : CLR abs *ݤ_9E: : CLR abs,X mem%?A%=0:rpc%=rpc%+1:=0 : : zݤ_A :ra%=ra%*2:rp%=(rp%&FE)+ra%256:ra%=ra%&FF:rp%=(rp%&7D)(ra%128)((ra%=0)2):=0: : ASL A ݤ_6 : : ASL zp ݤ_E : : ASL abs ݤ_16: : ASL zp,X ݤ_1E: : ASL abs,X ka%=mem%?A%*2:rp%=(rp%&FE)+a%256:mem%?A%=a%:rp%=(rp%&7D)(mem%?A%128)((mem%?A%=0)2):rpc%=rpc%+1:=0 : xݤ_2A:ra%=ra%*2+(rp%1):rp%=(rp%&FE)+ra%256:ra%=ra%&FF:rp%=(rp%&7D)(ra%128)((ra%=0)2):=0 : ROL A ݤ_26: : ROL zp ݤ_2E: : ROL abs ݤ_36: : ROL zp,X "ݤ_3E: : ROL abs,X ,sa%=mem%?A%*2+(rp%1):rp%=(rp%&FE)+a%256:mem%?A%=a%:rp%=(rp%&7D)(mem%?A%128)((mem%?A%=0)2):rpc%=rpc%+1:=0 6: @sݤ_4A:rp%=(rp%&FE)(ra%1):ra%=ra%2:rp%=(rp%&7D)(ra%128)((ra%=0)2):=0 : LSR A Jݤ_46: : LSR zp Tݤ_4E: : LSR abs ^ݤ_56: : LSR zp,X hݤ_5E: : LSR abs,X rjrp%=(rp%&FE)(mem%?A%1):mem%?A%=mem%?A%2:rp%=(rp%&7D)(mem%?A%128)((mem%?A%=0)2):rpc%=rpc%+1:=0 |: xݤ_6A:ra%=ra%+256*(rp%1):rp%=(rp%&FE)+(ra%1):ra%=ra%2:rp%=(rp%&7D)(ra%128)((ra%=0)2):=0 : ROR A ݤ_66: : ROR zp ݤ_6E: : ROR abs ݤ_76: : ROR zp,X ݤ_7E: : ROR abs,X wa%=mem%?A%+256*(rp%1):rp%=(rp%&FE)+(a%1):mem%?A%=a%2:rp%=(rp%&7D)(mem%?A%128)((mem%?A%=0)2):rpc%=rpc%+1:=0 : : ݤ_89:A%=rpc% : BIT #n ݤ_24: : BIT zp ݤ_2C: : BIT abs ݤ_34: : BIT zp,X ݤ_3C: : BIT abs,X Drp%=(rp%&3D)(mem%?A%&C0)(((mem%?A%ra%)=0)2):rpc%=rpc%+1:=0 : : &ݤ_C0:A%=rpc% : CPY #n 0ݤ_C4: : CPY zp :ݤ_CC: : CPY abs DpA%=ry%-mem%?A%:rp%=(rp%254)+(((A%256)256)256):A%=A%255:rp%=(rp%&3D)(A%128)((A%=0)2):rpc%=rpc%+1:=0 N: Xݤ_E0:A%=rpc% : CPX #n bݤ_E4: : CPX zp lݤ_EC: : CPX abs vpA%=rx%-mem%?A%:rp%=(rp%254)+(((A%256)256)256):A%=A%255:rp%=(rp%&3D)(A%128)((A%=0)2):rpc%=rpc%+1:=0 : ݤ_4 :Z%=m4 : TSB zp ݤ_C :Z%=mC : TSB abs Nrp%=(rp%253)+(((mem%?A% ra%)=0)2):mem%?A%=mem%?A% ra%:rpc%=rpc%+1:=0 : ݤ_14:Z%=m4 : TRB zp ݤ_1C:Z%=mC : TRB abs Prp%=(rp%253)+(((mem%?A% ra%)=0)2):mem%?A%=mem%?A% ra%:rpc%=rpc%+1:=0 : :  MOS Interface #ݤ_3 : : OSCLI /OSBYTE #ݤ_23: : OSWORD/OSWRCH #ݤ_43: : OSRDCH/OSFILE  #ݤ_63: : OSARGS/OSBGET #ݤ_83: : OSBPUT/OSGBPB  #ݤ_A3: : OSFIND/OSQUIT * ݤ_C3: : OSLANG/ - 4 ݤ_E3: : - / - >=mos(mem%?(rpc%-1)) H: R: \ݤ_2 : : --- fݤ_22: : --- pݤ_42: : --- zݤ_44: : --- ݤ_54: : --- ݤ_5C: : --- ݤ_62: : --- ݤ_82: : --- ݤ_C2: : --- ݤ_D4: : --- ݤ_DC: : --- ݤ_E2: : --- ݤ_F4: : --- ݤ_FC: : --- =0 > IO : 6 Access absolute memory, checking for I/O devices (6 ------------------------------------------------ 2io_reset: <: F#ݤio_rd(A%): ports%=0:=mem%?A% P$ C%:C%=io_type: C%<0:=mem%?A% Z%(A%&FFFC)<>port%(C%,0):=mem%?A% dA%=A%15:=("FNio_rd"+C%) n: x*io_wr(A%,B%): ports%=0:mem%?A%=B%: ( C%:C%=io_type: C%<0:mem%?A%=B%: )(A%&FFF0)<>port%(C%,0):mem%?A%=B%: "A%=A%15:A%=("FNio_wr"+C%): : ݤio_type:C%=A%&FFFC  C%=port%(0,0):=0  C%=port%(1,0):=1  IF C%=port%(2,0):=2  IF C%=port%(3,0):=2 =-1 : 6850 J base+0 | b7: Enable receive ints | b7: Interupt Request | J | b6: RTS low/high | b6: Receive Parity Error | J | b5: Enable transmit ints | b5: Receive Data Overrun | J | b4: 7bit/8bit data | b4: Framing Error | "J | b3: 2/1 stop bits | b3: Clear To Send not present| ,J | b2: even/odd parity | b2: DCD not present | 6J | b1-0: Clock divide 1/16/64 | b1: Transmit Register Empty | @J | or reset | b0: Receive Register Full | JJ base+1 | Write Data | Read Data | T ݤio_rd0 ^@A%=1:= : 6850 RxData h4A%=0: -256="W":=((-1)<>&FF)1 : 6850 RxRDY rA%=0:=((-1)<>&00)1 |=&7F  ݤio_wr0 A%=1: B%:: 6580 TxData  A%=0: : 6580 TxCtrl  :  6551  base+0 | Data | Data , base+1 | Reset | b7: Interupt Request % | | b6: DSR level % | | b5: DCD level . | | b4: Transmit Reg Empty 1 | | b3: Receive Register Full 0 | | b2: Receive data overrun ) | | b1: Framing Error 0 | | b0: Receive Parity error  base+2 | b7-5: parity & | b4: echo 0 | b3-2: TxControl :" | b1: TxIRQ disable D! | b0: RxIRQ enable N base+3 | b7: stop bits X | b6-5: word length b | b4: clock lI | b3-b0: baud rate: | v ݤio_rd1 @A%=0:= : 6551 RxData 4A%=1: -256="W":=((-1)<>&FF)8 : 6551 RxRDY A%=1:=((-1)<>&00)8 =&7F  ݤio_wr1 A%=0: B%:: 6551 TxData A%=1: : 6551 TxRDY  > MOS ݤmos(m%): X%,Y% -A%=ra%:X%=rx%+256*ry%:Y%=ry%:C%=rp%:rp%=0 ( Ȏ m% 2 &13,&FFF4:=mos_byte < &33,&FFEE: A%:=0 F &FFEC: 13:=0 P &FFE7: &FFE7:=0 Z &FFE3: &FFE3:=0 d' &43,&FFE0:ra%=:rp%=(ra%=27)1:=0 n &73,&FFD7:=mos_bget x &83,&FFD4:=mos_bput  &A3,&FFCE:=mos_find  &63,&FFDA:=mos_args  &B3:=mos_quit  &C3:=mos_lang  X%=X%+mem%:Y%=X%256 Ȏ m%  &03,&FFF7:=mos_cli  &23,&FFF1:=mos_word  &53,&FFDD:=mos_file  &93,&FFD1:=mos_gbpb  =0 : ݤmos_cli:cmd($X%,):=0 : "ݤmos_byte , A%=&82:rx%=0:ry%=&00:=0 6 A%=&83:rx%=0:ry%=&08:=0 @+ A%=&84:rx%=prog%255:ry%=prog%256:=0 JL A%>123:A%<127:mem%?escflg%=128*(A%1):"FX15" : Clear/Set/Ack Escape Ti os%<>32:X%=X%255:A%=&FFF4:rx%=(A%&FF00)256:ry%=(A%&FF0000)65536:rp%=(A%&1000000)&1000000:=0 ^@ A%=128:rx%=7:ȗ rx%,A%,A%:ry%=(rx%>>8)255:rx%=rx%255:=0 h@ A%=128:rx%=8:ȗ A%,rx%,A%:ry%=(rx%>>8)255:rx%=rx%255:=0 r Ȏ A% | 0:rx%=32:=0  127:rx%=#rx%:=0 0 128:A%=(rx%+256*ry%):rx%=A%:ry%=A%256:=0 > 129:A%=(rx%+256*ry%):rx%=A%:ry%=A%256:carry(A%=-1):=0  134:rx%=:ry%=:=0  135:rx%=(,):ry%=:=0  160: Pry%=rx%+1:ry%=(@vdu%!(((ry%-4)+"0312",(ry%3)+1,1)-2)*4))(8*(1+(ry%1))) Irx%=(@vdu%!(((rx%-4)+"0312",(rx%3)+1,1)-2)*4))(8*(1+(rx%1))):=0  =0 : ݤmos_word `A%=0:A%=!X%&FFFF:mem%?255=0:osw0%=:EscOn:""A$:EscOff:$(mem%+A%)=A$:osw0%=:ry%=A$:=0 os%<>32 A%=10: &FFF1:=0  Ȏ A%  1:!X%=:=0  2:=!X%:=0  7: !X%,X%!2,X%!4,X%!6:=0 &U 8: ?X%,X%?1,X%?2,X%?3,X%?4,X%?5,X%?6,X%?7,X%?8,X%?9,X%?10,X%?11,X%?12,X%?13:=0 0 14:$X%=$:=0 : 15:$=$X%:=0 D N=0 X: bݤmos_file l7A%=254:X%?5 =&FF:X%?5=0 A%=254:X%!2=X%!2+mem% v7A%=255:X%?5 =&FF:X%?5=0 A%=255:X%!2=X%!2+mem% QA%=0 :X%?13=&FF:X%?13=0:X%?17=0 A%=0:X%!10=X%!10+mem%:X%!14=X%!14+mem% fn%=mem%+(!X% &FFFF) h os%<32:ș "OS_File",A%,fn%,X%!2,X%!6,X%!10,X%!14 ra%,,X%!2,X%!6,X%!10,X%!14 ra%=file($fn%,A%) _ SYS "OS_File",A%,mem%+(!X% AND &FFFF),X%!2,X%!6,X%!10,X%!14 TO ra%,,X%!2,X%!6,X%!10,X%!14 =0 5 DEFPROCaddr(A%):IFX%!A%<&10000:X%!A%=mem%+A%!X%  ENDPROC : 6ݤmos_bget:ra%=(&FFD7):rp%=ra%256:ra%=ra%255:=0 : ݤmos_bput: &FFD7:=0 : ݤmos_find:A%=0:#Y%:=0 - (A%&C0)=&40:ra%=openin($(mem%+X%)):=0  . (A%&C0)=&80:ra%=openout($(mem%+X%)):=0 - (A%&C0)=&C0:ra%=openup($(mem%+X%)):=0  : *ݤmos_gbpb 42ra%=X%?5 :ra%=&FF:X%?5=0 X%!1=X%!1+mem% >0A%=&FFD1:ra%=&FF:X%?5=&FF X%!1=X%!1-mem% Hra%=A%255:rp%=A%256:=0 R: \ݤmos_args fY%=0:A%=0:ra%=fs:=0 p*Y%=0:mem%!X%=args(ra%,Y%,mem%!X%):=0 zA%=0:mem%!X%=#Y%:ra%=0:=0 A%=1:#Y%=mem%!X%:ra%=0:=0 A%=2:mem%!X%=#Y%:ra%=0:=0 A%=3:#Y%=mem%!X%:ra%=0:=0 A%=4:mem%!X%=#Y%:ra%=0:=0  mem%!X%=args(A%,Y%,mem%!X%) =0 : ݤmos_quit:= ݤmos_lang:=0 > Dis65 ݤDis_Name(cpu%)="65x02" 6ݤDis_Code(cpu%,Ptr%,Data%):op%,ins%,md%,b0%,num% op%=&89:="BIT "+mde(2) H$b0%=1:=alu(ins%)+" "+mde(md%) R)(op%31)=&12:=alu(ins%)+" "+mde(8) \$(op%&EF)=&64:="STZ "+mde(md%) f((op%&FD)=&9C:="STZ "+mde(b0%*2+3) p3(op%&D7)=&96:=rot(ins%)+" "+mde(md%3)+",Y" z((op%7)=6:=rot(ins%)+" "+mde(md%) N(op%&1F)=16:num%=2:="B"+"PLMIVCVSCCCSNEEQ",1+2*ins%,2)+" "+jr(Data%?1) <(op%&8F)=10:=rot((ins%+(md%4)*1.5)((md%>4)1))+" A" 9(op%&E7)=4:="T"+"SR",1+(md%4),1)+"B "+mde(md%3) 6(op%&D3)=&C0:=bxy(ins%)+" "+mde(((md%3)-1)3) $(op%&E7)=&24:="BIT "+mde(md%) ,(op%&C7)=&84:=bxy(ins%)+" "+mde(md%) ;(op%&FD)=&A0:="LD"+"YX",1+((op%2)2),1)+" "+mde(2) R(op%&CF)=&4C:op%<>&5C:X%?2=64:="JMP "+"(",op%>&5F)+mde(md%)+")",op%>&5F) 0op%=&80:num%=2:X%?2=64:="BRA "+jr(Data%?1) !X%?2=128:="EQUB &"+h0(op%,2) 3ݤalu(A%)="ORAANDEORADCSTALDACMPSBC",A%*3+1,3) 3ݤrot(A%)="ASLROLLSRRORSTXLDXDECINC",A%*3+1,3) 3ݤbxy(A%)="***BIT***STZSTYLDYCPYCPX",A%*3+1,3) /ݤmde(A%):num%=2:A%=2:="#&"+h0(Data%?1,2) >(A%2):num%=3:="&"+h0(Data%!1,4)+",X",A%=7)+",Y",A%=6) +(A%1):="&"+h0(Data%?1,2)+",X",A%=5) $4="(&"+h0(Data%!1,2)+",X",A%=0)+")"+",Y",A%=4) .Dݤjr(A%):A%<128:="&"+h0(Ptr%+A%+2,4)="&"+h0(Ptr%+A%+2-256,4) ! > BLib.Close 1.00 09Aug1998 :  Close Handling ( ~~~~~~~~~~~~~~ 2: <Close_All F"in%=in%:in%:A%=in%:in%=0:#A% P'out%=out%:out%:A%=out%:out%=0:#A% Z " > BLib.String 1.00 09Aug1998 : # String Manipulation Functions (# ============================= 2: <7 FNs() - strip spaces from start and end of string F7 ------------------------------------------------- P/ݤs(A$):A$,1)=" ":A$=A$,2):A$,1)<>" " Z+A$,1)=" ":A$=A$,A$-1):A$,1)<>" " d=A$ n: x+ FNuc() - convert string to upper case + ------------------------------------- ݤuc(A$): B$:A$="":="" 5B$=B$+(A$((A$<"@")&DF)):A$=A$,2):A$="":=B$ : + FNlc() - convert string to lower case + ------------------------------------- ݤlc(A$): B$:A$="":="" 5B$=B$+(A$((A$<"_")&20)):A$=A$,2):A$="":=B$ : " > BLib.Number 1.01 09Aug1988 ( v1.00 09Aug1988 JGH: First version 1 v1.01 12Feb1992 JGH: Added Octal and Binary (? v1.02 15Sep2009 JGH: Octal and Binary works for &8xxxxxxx 2: < Number Output Routines F ~~~~~~~~~~~~~~~~~~~~~~ P: Z# Hexadecimal padded with zeros d$ݤh0(A%,N%):="0000000"+~A%,N%) n: x$ Hexadecimal padded with spaces #ݤh(A%,N%):=" "+~A%,N%) :  Decimal padded with zeros $ݤd0(A%,N%):="00000000"+A%,N%) : Decimal padded with spaces $ݤd(A%,N%):=" "+A%,N%) :  Octal padded with zeros 5ݤo0(A%,N%): A$,B%,L%:A%<0:B%=2:A%=A%&7FFFFFFF ;A$=(A%7)+A$:A%=A%8:L%=L%+3:L%>27:=(A%+B%)+A$,N%) :  Octal padded with spaces %ݤo(A%,N%): A$:A%<0:=o0(A%,N%) 2A$=(A%7)+A$:A%=A%8:A%=0:=N%," ")+A$,N%) : " Binary padded with zeros ,>ݤb0(A%,N%): A$,B$,L%:B$="0":A%<0:B$="1":A%=A%&7FFFFFFF 65A$=(A%1)+A$:A%=A%2:L%=L%+1:L%>30:=B$+A$,N%) @: J Binary padded with spaces T%ݤb(A%,N%): A$:A%<0:=b0(A%,N%) ^2A$=(A%1)+A$:A%=A%2:A%=0:=N%," ")+A$,N%) h: r) Drive character for supplied number | ݤdrv(A%):=(48+A%-7*(A%>9)) : ) Drive number for supplied character #ݤDrv(A$):=A$-48+7*(A$>"9")31 : # > BLib.ProgEnv 1.06 20Apr2020 : # Program Environment Functions (# ============================= 2: 31:>&FFFFF:X%256:ș"GetModuleFileName",0,X%,255:run$=$$X%:=@cmd$ nCA%=&600-&7B00*(>&8000)-&3F00*(>&C000):!(-&100)=@%:A%=-&300 x;?(P-3)=0:A%=&100:<&FFFF:A%=-&300:!(+512)=@%:A%= cA$=$A%:=&8F00:run$=A$:ș16A$,,A%:ș72,"",A%:A$=A$,1+A$+" "," ",1+A$," "))):A$=0:A$=run$ UY%=-10:A$=" "+A$:A$=A$,2):A$<>32:A$=34:A%=A$,"""",2)+1 A%=A$+" "," ") 9Y%:run$=A$,1-(A$=34),A%-1+2*(A$=34)):A$=A$,A%+1) :=A$ : . Run a program, passing it a command line = If program is *Command, called with OSCLI, else CHAINed = ------------------------------------------------------- #os(A$):A$=42:A$ A$:A$  : ( Exit program, setting return value ( ---------------------------------- Fexit(A%):"FX1,"+(A%255):quit$=quit$:A$=quit$:quit$="":os(A$) >&FFFFF:Ș A%  ": * > BLib.Generic.FileIO 1.05 22Mar2008 0 v1.05 22Mar2009 Optimised CDIR in FNfile() , v1.04 22Mar2008 FNf_scan strips spaces (7 v1.03 15Feb2008 Add veneer functions in f_ domain 2K v1.02 28Apr2007 Added functions to FNfile on DOS, PROCcdir, FNopenout <7 v1.01 07Sep2006 FNargs avoid zero page on RISC OS F% v1.00 09Aug1988 Initial version P: Z% General File Interface Routines d% =============================== n: x8 FNfile(), PROCgbpb(), FNfs are callable on Windows 8 -------------------------------------------------- : , Returns file type, file info in X%!... , -------------------------------------- Rݤfile(A$,A%):A%-8:<&FFFFF:$name%=A$:?X%=name%:X%?1=name%256:=(&FFDD)&FF TA$=f_name(A$):A%=255 A%=5:X%!14=(A$):X%!14:X%!10=#X%!14:#X%!14:X%!14=&33 1A%=255:X%?6=0:"LOAD """+A$+""" "+~X%!2:=1 A%=5:X%!14:=1 A%=5:=0 FA%=0:"SAVE """+A$+""" "+~X%!10+" "+~X%!14:X%!10=X%!14-X%!10:=1 BA%=7:"SAVE """+A$+""" "+~+"+"+~X%!10:X%!10=X%!14-X%!10:=1 A%-8:=0 -(os%-24):A$="mkdir "+A$ A$="cdir "+A$ >&FFFF: : :=0  A$:=2 :  General OSGBPB call " ------------------- ,%f_gbpb(A%,chn%,addr%,num%,ptr%) 6>?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:<&FFFFF:&FFD1: @A%=1A%=3:#?X%=X%!9 J5:A%=1A%=2:#?X%,?X%!1 A%=3A%=4:?X%!1=#?X% T5X%!1=X%!1+1:X%!5=X%!5-1:(#?X% A%>2) X%!5<1: ^: h#gbpb(A%,chn%,addr%,num%,ptr%) r>?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:<&FFFFF:&FFD1: |A%=1A%=3:#?X%=X%!9 5:A%=1A%=2:#?X%,?X%!1 A%=3A%=4:?X%!1=#?X% 5X%!1=X%!1+1:X%!5=X%!5-1:(#?X% A%>2) X%!5<1: : @ Return current disk (5), directory (6) or library (7) name @ ---------------------------------------------------------- ݤgbpb(A%):>&FFFFF:="" NX%!1=name%:&FFD1:A%=name%+((1+?name%)((A%-2)=6)):A%?(1+?A%)=13:=$(A%+1) : B Returns entry in current directory, or null string if at end B ------------------------------------------------------------  ݤf_scan(ptr%):>&FFFFF:="" 7X%!1=name%:X%!5=1:X%!9=ptr%:A%=8:&FFD1:X%!5=1:="" 7A%=name%+1:A%!(A%?-1)=&D20:A%?($A%," ")-1)=13:=$A% : ݤgbpb8(ptr%):>&FFFFF:="" 7X%!1=name%:X%!5=1:X%!9=ptr%:A%=8:&FFD1:X%!5=1:="" &7A%=name%+1:A%!(A%?-1)=&D20:A%?($A%," ")-1)=13:=$A% 0: :7 OSARGS call with data. Returns any returned data D7 ------------------------------------------------- N6ݤf_args(A%,Y%,ptr%): X%,E%:?(P-3)=0:E%=Y%:Y%=0 X b& !&70:X%=&70:!X%=ptr%:&FFDA:=!X% l v#ș"OS_Args",A%,Y%,ptr% ,,ptr%  :=ptr% : 4ݤargs(A%,Y%,ptr%): X%,E%:?(P-3)=0:E%=Y%:Y%=0  & !&70:X%=&70:!X%=ptr%:&FFDA:=!X%  #ș"OS_Args",A%,Y%,ptr% ,,ptr%  :=ptr% : ' OSARGS call ignoring X, returns A ' --------------------------------- ݤf_argsA(A%): ( X%,Y%,E%,!&70:X%=&70:=(&FFDA)&FF   ș"OS_Args",A% A%  :=A%  : *ݤargsA(A%): 4( X%,Y%,E%,!&70:X%=&70:=(&FFDA)&FF > Hș"OS_Args",A% A% R :=A% \: f& Get current filing system number p& -------------------------------- z.ݤfs:(os%-32)=0: A%,Y%,E%:=(&FFDA)&FF =29 :  Delete an object  ----------------