> Startup & PDP11 Emulator with disassembler  v0.12 2004 Some more work (+ v0.13 2005 *Commands, RTS, EMT, TRAP 2[ v0.14 01-Sep-2005 More EMTs and TRAPs, mode 7(pc) seems to work, works on PC/Windows > K v0.29a 29-Apr-2020 Tweeks to FNload() and FNrun(), V fixed on CMP/SUB P v0.30 11-Mar-2021 Added *SAVE, start/len/exec/load address general parser ] v0.30a 21-Apr-2021 OSCLI catches DOS errors, quiet exit from running from PDP11> prompt 4 v0.31 01-Nov-2023 Tweeks to work on SDL BASIC "J v0.31a 01-Nov-2024 EscapeOn enables events to turn on touch keyboard ,: 61slowfix%=: Don't use Client on slow systems @"bugfix%=: Error in OS_GetEnv J) pr::Close_All:" at line ";: T< >&7FFFFFFF:"Can't access 64-bit memory":A%=(500):Ș ^d(-256&DF)=83:A$="":run$="":cd$=@dir$:os%=32 A$=OS_GetEnv:cd$="": Workaround for SDL BASIC h3ver$="0.31b":debug%=0:Init:A%=_DEBUG(debug%) rSbugfix%:>&FFFFF:ș "GetCommandLine" name%:$$name%,"bbcwin.exe")=0:A$="-" |j A$="":os%=32 (-256&DF)=83:in%=(@dir$+"basic.rom"):in%:#in%:in%=0:A$=""""+@dir$+"basic.rom"""  A$="-":A$="" quiet%=A$<>"" > A$="":"PDP11 Emulator v"ver$" (C)2001-2023 J.G.Harston" ^ A$="":"Memory start: &"h0(mem%,8)" MemSz: &"h0(mz%,6): " MemMsk: &"FNh0(mm%,6) P A$="":"base: &"h0(base%,4)" prog: &"h0(prog%,4)" err: &"h0(err%,4) = IF A$="":PRINT" sys: &";FNh0(sys%,4)" io: &"FNh0(io%,4) ^ A$="":"Program space: &"h0(membot%,4)"-&"h0(memtop%,4)" ";(memtop%-membot%);" bytes"  Error:A$=""  A$<>"":A%=_RUN(A$)  run%:Go  quiet%:A%=_QUIT("")  Error:A$="" +quiet%=: "PDP11> "A$:cmd(A$,):0  :  Init &7::IF(INKEY-256AND&DF)=83:IF(@platform%AND15):os%=8 0d$=".":s$="/":fsnum%=0:os%40:d$="/":s$=".":fsnum%=24:os%32:d$="\":fsnum%=29:(-256&DF)=83:(@platform%15):d$="/":fsnum%=24 :%bugfix%:>&FFFFF:run$=@dir$+"*" DHrunpath$=run$: runpath$,1)="""":runpath$=runpath$,2, runpath$-2) N? runpath$=runpath$): d$+":",runpath$,1)) runpath$="" XRos%=32:mx%=@vdu%!208:my%=@vdu%!212:mw%=@vdu%!216:mh%=@vdu%!220:mc%=@vdu%?73+1 bEmz%=memsize:mm%=mz%-1:memmax%=mz%:run%=:trace0%=0:trace1%=&FFFF lT ctrl% 31,name% 255,r%(7),mem% mz%:zp%=name%:hdr%=zp%:psw%=0:X%=ctrl%:Y%=X%256 v IF(INKEY-256AND&DF)<>83:DIM A% mz%+32+256 ELSE PRINT"%%":DIM A%% mz%+32+256:PRINT~A%%:!^A%=!^A%%:PRINT~A%:IF !(4+^A%%):PRINT"Can't access 64-bit memory":A%=INKEY(500):PROCexit(127) b ctrl%=A%:name%=A%+32:mem%=A%+256+32:DIM r%(7):zp%=name%:hdr%=zp%:psw%=0:X%=ctrl%:Y%=X%DIV256 _basic$="": os%>31 (-256&DF)=83:basic$=@dir$+"basic.rom" os%=6:basic$="" Pclient: client$<>"": "Load """+client$+""" "+~(mem%+&F800):memmax%=&F600 Ybase%=mem(&100):base%=mem(0):prog%=base% : Allocate low memory [err%=mem(-&100):err0%=err%:mem%?err%=13:escflg%=err%+255 : Allocate high memory Ymemtop%=memmax%:membot%=base%:reset%=0:trapvec%=0:errvec%=0:emt%=0:ind%=0:r7%=0:pc%=0 EscInit: : >ݤmemsize:A%=2^((--1024)/2): A%<&10000:=A% =&10000 Qݤmem(A%): A%<0:memmax%=memmax%+A%:=memmax% membot%=membot%+A%:=membot%-A% client:client$="":pc%=0: 6client$="Tube ClientSerial",pc%*6+1,6+2*(pc%=0)) m os%>31:client$=f_name(runpath$+client$+"11.pdp") slowfix%:client$=f_name(runpath$+client$+"11*") -in%=(client$):pc%=pc%+1: pc%=3 in%<>0  " in%:#in%:in%=0 client$=""   : *+Error:X%=ctrl%:Y%=X%256: -1:run%= 4K run%:pr::Close_All:" at line "+Þ,<128 <>17): -1:RegDump >c =25:run%: os%=32:run%=: 23,22,mx%;my%;mw%,mh%,mc%,128:run%=:r%(7)=r7%+(r%(7)(r7%=0)): HS IF ERR=17:mem%?escflg%=255:psw%=psw%OR(osw0%AND1):IFosw0%:osw0%=FALSE:ENDPROC R IF run%:mem%!err%=ERR:mem%!(err%+4)=&880F:mem%?(err%+6)=ERR:$(mem%+err%+7)=LEFT$("PDPEm: ",ERR<128 AND ERR<>17)+REPORT$+CHR$0:PROCpsw(0,0,TRUE,TRUE,ERR=17,ERR=17):r%(0)=err%+6:IFERR=17:mem%?escflg%=&FF \ run%:mem%!err%=:mem%!(err%+4)=&880F:mem%?(err%+6)=:A%=<128 <>17:$(mem%+err%+7)="PDPEm: ",A%)+$+" at line "+Þ,A%(>0))+0:psw%=psw%3:r%(0)=err%+6:=17:mem%?escflg%=&FF f r7%:r%(7)=r7% p ind%:r%(7)=ind% z errvec%:r%(7)=errvec%  pr:?(P-3): : : 5cmd(A$,link%)::A$=s(A$):A$,1)="*":A$=A$,2) ( A$,1)<>"*" A$,1)<>" ":reset%=0  A$=""A$,1)="|":  A$+" ",3)="ls ":A$="." 1 IF LEFT$(A$,1)="*":OSCLI MID$(A$,2):ENDPROC : A$,1)=".": "."+A$,2)+"\",A$>2)+"*.*",os%=32): ! A$,1)="/":A$="RUN "+A$,2) 7 uc(A$,2))="FX": A$,3) (A$,3,1)="0"):A$: 2A%=A$+" "," "):C$=uc(A$,A%-1)):T$=A$,A%+1) ZA%=" BASIC CORE DEBUG GO HELP LOAD MDUMP MDIS MEDIT QUIT RUN RESET SAVE "," "+C$+" ")  A%:A%=("FN_"+C$+"(T$)"): A%=_run(C$+" "+T$,link%): : $>ݤ_HELP(A$):'"PDP11 Emulator ";ver$: uc(A$)<>"PDP11":=0 .h" BASIC"'" CORE "'" DEBUG ( ( ))";8'" GO ()"'" HELP" 8k" LOAD "'" MDUMP "'" MDIS "'" QUIT"'" RESET ()"'" RUN " B>" SAVE |+ ( ())" L=0 V: `ݤ_MDIS(A$): N%,P%,C% j-addrs:P%=start%:N%=16: num%<2:size%=256 t(: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  : ݤ_SAVE(A$) fname:addrs ( num%<2: 252,"Bad address" 2( start%>=0:start%=mem%+(start%mm%) "":=_RUN(basic$+" "+A$) =_RUN("basic "+A$) : ݤ_RESET(A$)::A%=-1 ^ uc(A$)="TUBE": client$<>"":"Load """+client$+""" "+~(mem%+&F800):memmax%=&F500:A$=""  memmax%<&F800 )'$(mem%+&F805):A%=mem%!&F5FC &FFFF  7'"PDP11 Tube Emulator": A$<>"":A%=_load(A$,-1,)  * uc(A$)="NOTUBE":memmax%=&FF00:A$="" "%'"Econet Station 128"': A%<0:=0 ,Ihdr%=mem%+A%: hdr%!(hdr%?7)=&29432800:B%=hdr%+9:?B%:B%=B%+1:?B%=0 6 hdr%-mem%=0:11,11 @:':F$="":psw%=0:=_go: Needs to ensure no stack frame J: Tݤ_load( F$,A%,F%) ^in%=0:size%=0: A%=-1 hCin%=f_openin(F$): in%=0: F%:F$=F$+s$+"pdp":in%=f_openin(F$) r in% |'size%=#in%:gbpb(4,in%,hdr%,256,0) Nmagic%=!hdr% &FFFF: magic%<&105 magic%>&111:A%=-1 A%=0: No address ! This is duplicated in FNrun 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" &0 A%=-1 (A%+size%>mm%): 252,"Bad address" 01 F%:"Load """+f_name(F$)+""" "+~(mem%+A%) :=A% D: N%syscmd(cli$): os%<>32: cli$: X% ch%,err$,tmp$:tmp$=@tmp$+Ñ+"." b- : : : =214: cli$: ,$: l+ cli$+" 2>"+tmp$:ch%=(tmp$): ch%=0: v@err$=#ch%:#ch%:"Delete "+tmp$: err$,1)=",":err$,1)="."  254,err$: : ݤ_RUN(A$) Y <&FFFFF:ș"XOS_File",5,A$ ,,A%:A%=A%&FFF00: A%=&FFB00 A%=&1C700:=_BASIC(A$) =_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" psw%=1:=_go  ݤ_go * A% = entry address as PDP11 address / hdr%=>Acorn ROM header in mem%+A% address ! in% =open file being loaded 7 F$ =file being loaded or "" if already in memory  /membot%=base%:err%=memmax%:escflg%=err%+255  memtop%<&F800 A%>&FF  , Client present and entry address known *A F$<>"":#in%:in%=0:"Load """+f_name(F$)+""" "+~(mem%+A%) 4:prog%=A%: prog%<&8000:memtop%=memmax% memtop%=prog% >sB%=A%:hdr%=mem%+A%: hdr%!(hdr%?7)=&29432800: (hdr%?6 32)<>0:B%=hdr%?7:B%=B%+1:hdr%?B%=0:B%=A%+hdr%!(B%+5) H&111 memtop%=memmax% RFmem%!&F5F0=err%:$(mem%+err%)=A$ : LPTR=command tail \Amem%!&F5F4=membot% : MEMBOT=&0100 fAmem%!&F5F6=memtop% : MEMTOP=&F500 pGmem%!&F5F8=A%:r%(1)=A%:prog%=A% : ADDR=dest, R1=dest zEA%=&F800::A%=A%+2:mem%!A%=&9F700A1 : Look for CLC:JSR CLI_WAIT @r%(7)=A%+(mem%!(A%+4)&FFFF)+10 : R7=CLI_WAIT+4 Br%(0)=&80:psw%=psw%8 : R0=&80, PSW=MI  Go:=0   B%=A% " This is duplicated in FNload  hdr%!(hdr%?7)=&29432800  Acorn ROM header < (hdr%?6 64)=0 :#in%:in%=0: 249,"Not a language":=0 < (hdr%?6 15)<>7:#in%:in%=0: 249,"Not PDP11 code":=0 F (hdr%?6 32)<>0:B%=hdr%?7:B%=B%+1:hdr%?B%=0:B%=A%+hdr%!(B%+5)  :prog%=A%: prog%<&8000:memtop%=memmax% memtop%=prog% 3r%(6)=(memtop%-2)-2:(debug%16)=0:r%(5)=&0BBC f F$="":r%(0)=1:r%(7)=A%:mem%?r%(6)=0:mem%?(r%(6)+1)=0:Go:=0 : No Client, code already in memory 8load%=A%:exec%=B%: A%<>B%:gbpb(3,in%,zp%,16,B%-A%) $jmagic%=!zp% &FFFF: magic%<&105 magic%>&111:magic%=0 magic%=16:exec%=exec%-load%:load%=0:prog%=0 .. magic%=0:gbpb(3,in%,mem%+load%,#in%,0) 8T magic% :gbpb(3,in%,mem%+load%,#in%-(exec%-load%-magic%),exec%-load%+magic%) BI#in%:in%=0:r%(7)=exec%: prog%<&8000:memtop%=memmax% memtop%=prog% L} magic%:frame r%(6)=(r%(6)-C$-3)-2:$(mem%+r%(6)+2)=C$:r%(1)=r%(6)+2:mem%?0=0:mem%?1=0:mem%?r%(6)=0:mem%?(r%(6)+1)=0 V Go:=0 `: j$ When running code within Unix: t/ r0-r5=0, r6=top of memory, r7=entry point ~# (sp)=>argn, argv[], envv[], 0 C Code expects text segment at header+16 to be at address &0000  Code entered at header!10 % Not relocatable if header!14<>0 % Cannot RTS to system, must exit 9 If no header, &0000 pushed onto stack, [&0000]=halt :  Set up entry from header 0 Create stack frame with command parameters o sp=>argn, ->arg[0], ->arg[1], .., 0, ->env[0], ->env[1], .., 0, arg[0], arg[1], .., env[0], env[1], .., 0 7 eg 2, ->cat, ->file, 0, 0, "cat"+0, "file"+0, 0  Need to: ) scan for file >>file options frame  Clear data area: ]A%=(zp%!6)&FFFF: A%:B%=(zp%!2 &FFFF)+(zp%!4 &FFFF): mem%?B%=0:B%=B%+1:A%=A%-1: A%=0 , Set membot to end of code+idata+udata: (Kmembot%=((zp%!2)&FFFF)+((zp%!4)&FFFF)+((zp%!6)&FFFF)+((zp%!8)&FFFF) 2:r%(7)=zp%!10 &FFFF : Set PC to entry point "":A$=A$+" " Z. Convert spaces to nulls, and count them: dLC%=1::A%=A$," "): A%:A$=A$,A%-1)+0+0,(A%1)<>0)+A$,A%+1):C%=C%+1 n A%=0 x% Put arguments at top of memory: A%=(memtop%-A$-3)-2 B%=(A%-F$-1)-2 $(mem%+B%)=F$+0+0 $(mem%+A%)=A$+0+0 MA%=B%-C%*2-6:r%(6)=A% : Drop SP to make space for stack frame: 6mem%?A%=C%:mem%?(A%+1)=C%256 : Put argn on stack A%=A%+2  Point to strings on stack  )mem%?A%=B%:mem%?(A%+1)=B%256:A%=A%+2 5:B%=B%+1:mem%?B%=0 B%>=memtop%-2:B%=(B%+2)-2  B%>=memtop%-2 Smem%!(A%-2)=0 : End of arg[] list and null env[] list: Qmem%?(memtop%-2)=0:mem%?(memtop%-1)=0 : terminating null at top of arguments " P.~r%(6):A%=FN_MDUMP("FE00")  ": ,ݤ_GO(A$): A$="":=0 68A%=A$,";"):r%(7)=hex(A$): A%:A$=A$,A%+1) A$="" @,F$="":A%=r%(7):hdr%=mem%+A%:psw%=1:=_go J: Tݤ_CORE(A$): Dump core ^8A$=f_name(s(A$,A$+" "," ")-1))):A$="":A$="core" h("Save "+cd$+A$+" "+~mem%+"+"+~mz% rSetType(A$,&FFD) |=0 : ݤ_DEBUG(A$):A$="":" 1=Register Dump"'" 3=Single Step"'" 4=EMT/TRAP calls"'" 8=ignore odd word accesses"'"16=r5<>&BBC on startup":=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)) =0 : 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% 0: : fname DRA$,1)="""":A%=A$+"""","""",2):F$=A$,2,A%-2) A%=A$+" "," "):F$=A$,A%-1) NA$=s(A$,A%+1)): X: b addrs l+num%=0:start%=0:size%=0:load%=0:exec%=0 vA$=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$="": Qnum%=A$+" "," "):load%=hex(A$,num%-1)):A$=s(A$,num%+1)):num%=4: A$="": num%=5: : RegDump: N%: : O A%=07:"R";A%;"= "o0(r%(A%)&FFFF,6)": ";c(r%(A%)256);c(r%(A%));" "; - B%=r%(A%)r%(A%)+7: c(mem%?B%);::32 > B%=r%(A%)r%(A%)+7 2: o0(mem%!(B%mm%)&FFFF,6)" ";: $::"PSW="o0(psw%,6);":";(5); 3 ;(psw%&E0)32;":";"T-",((psw%16)<>0)+2,1); 8 "M-",((psw%8)<>0)+2,1);"Z-",((psw%4)<>0)+2,1); J "V-",((psw%2)<>0)+2,1);"C-",((psw%1)<>0)+2,1);1;dis(r%(7));12  *: 4Pݤdis(A%):N%=Dis_Code(11,A%,mem%+(A%mm%)):A$=$(X%+4):A%=A$,"&"):A%=0:=A$ >=B%=A%:B%=B%+1:"0123456789ABCDEF",A$,B%,1))=0 B%>A$ H@A$=A$,A%)+"o"+o0((A$,A%,B%-A%+1)),(B%-A%-1)*3/2)+A$,B%) R=A$ \: f3ݤc(A%):A%=A%255: A%<32 A%>126:="." = A% p: z"EscInit:esch%=esch%:esch%:  >&FFFFF (-256&DF)=83 D!(^KbdQ$+4)=256: @platform% &40:(KbdQ$)=]428 (KbdQ$)=!428   B 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 >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%: N <&FFFFF:ș "OS_ChangeEnvironment",9,esch%,0,0 ,escho%,escRo%,escbo%: "ESC OFF":escho%=  -256=87 & esch%:mem%?escflg%=&FF: $ . 8(-256&DF)=83 B> KbdQ$,&1B):KbdQ$=ĩKbdQ$,0):mem%?escflg%=&FF: L."SYS 2": ȗ @msg%=&700:"OSK ON": V ` j% -113:mem%?escflg%=&FF: t ~1EscOn: >&FFFFF: :escho%=0:"ESC ON": ?ș "OS_ChangeEnvironment",9,escho%,escRo%,escbo%:escho%=0:  DEF FN_was_escape_pressed  LOCAL I%, kbdq%% < IF @platform% AND &40 kbdq%% = ]428 ELSE kbdq%% = !428 @ FOR I%=0 TO 255 : IF kbdq%%?I% = &1B THEN = TRUE ELSE NEXT  = FALSE  > PDP11 $ 08-Nov-2007: ops 1-7, SPL done > 12-Aug-2008: SXT, ASHC, SOB, ops 1-7, SPL, M[F|T]PS done 0 17-Jun-2010: Entering code resets handlers - 17-Jul-2018: MUL sets Cy=(result>&FFFF) @ 27-Jul-2018: Rewrote MUL, shifts and rotates use << and >> 4 05-Aug-2018: PROCpsw(xxAND&FFFF/&FF in ADD/SUB  8 MOVB is only op that sets b8-b15 of dest. register K MUL treats arguments as signed, &FFFF x 100 = -100, fixed V on ASH(C) @ 31-Oct-2024: DIV doesn't change regs if Overflow (optable) (: 25Go:abort%=:halt%=0:run%=:r7%=0:ind%=0:EscOff <5 err%=err0%:escflg%=err%+255:escvec%=0:errvec%=0 Fd:(debug%1): r%(7)>=trace0% r%(7)<=trace1%:x%=:y%=:30:RegDump:31,x%,y%:(debug%2): P8op%=mem%!(r%(7)mm%):pc%=r%(7):r%(7)=(r%(7)+2)&FFFE Z@dd%=op%63:ss%=(op%&FC0)64:op%=(op%&F000)&1000:by%=op%8 d@A%=("FN_"+~(op%7)):halt%:EscOn:run%=:abort%:r%(7)=pc% n quiet%: r%(0):abort%= x quiet% abort%:RegDump  :  Opcodes are: & 00xxxx various 10xxxx various ) 01xxxx MOV ss,dd 11xxxx MOVB ss,dd ) 02xxxx CMP ss,dd 12xxxx CMPB ss,dd ) 03xxxx BIT ss,dd 13xxxx BITB ss,dd ) 04xxxx BIC ss,dd 14xxxx BICB ss,dd ) 05xxxx BIS ss,dd 15xxxx BISB ss,dd ) 06xxxx ADD ss,dd 16xxxx SUB ss,dd & 07xxxx various 17xxxx various : Dݤsrc(ss%,b%): Fetch source value, sets D% to address of source ( m%,r%,a%:D%=0:a%=&FFFF: b%:a%=&FF Bm%=ss%8:r%=ss%7:b%=2-b%: r%>5: m%<6:b%=2: sp&pc always +2 N m%=0:D%=0:=r%(r%)a% : Rn "R m%=1:D%=r%(r%) : (Rn) ,S m%=2:D%=r%(r%):r%(r%)=r%(r%)+b% : (Rn)+ 6P m%=3:D%=mem%!(r%(r%)mm%)&FFFF:r%(r%)=r%(r%)+2 : @(Rn)+ @S m%=4:r%(r%)=r%(r%)-b%:D%=r%(r%) : -(Rn) JP m%=5:r%(r%)=r%(r%)-2:D%=mem%!(r%(r%)mm%)&FFFF : @-(Rn) T] m%=6:D%=mem%!(r%(7)mm%)&FFFF:r%(7)=r%(7)+2:D%=(r%(r%)+D%)&FFFF : X(Rn) ^\ m%=7:D%=mem%!(r%(7)mm%)&FFFF:r%(7)=r%(7)+2:D%=mem%!((r%(r%)+D%)mm%)&FFFF : @X(Rn) hj b%=2:(D%1):(debug%8)=0:"Bus error: word read from odd address (";m%;"/";r%;")":halt%=:abort%= r=mem%!(D%mm%)a% |: Xpre(dd%,b%): Do pre-access register adjustment, sets D% to address of destination O m%,r%:D%=0:m%=dd%8:r%=dd%7:b%=2-b%: r%>5: m%<6:b%=2: sp&pc always +2 E Pre always called, dst sometimes not, so D% must be set up here ? m%=4:r%(r%)=r%(r%)-b% : -(Rn) @ m%=5:r%(r%)=r%(r%)-2 : @-(Rn) J m%=1 m%=2 m%=4:D%=r%(r%) : (Rn), (Rn)+, -(Rn) E m%=3 m%=5:D%=mem%!(r%(r%)mm%) : @(Rn)+, @-(Rn) = m%=6:D%=mem%!(r%(7)mm%):r%(7)=r%(7)+2 : X(Rn) > m%=7:D%=mem%!(r%(7)mm%):r%(7)=r%(7)+2 : @X(Rn)  : +ݤdst(dd%,b%): Fetch destination value 5 m%,r%,a%:m%=dd%8:r%=dd%7:a%=&FFFF: b%:a%=&FF : m%=0:=r%(r%)a% : Rn ; m%=6:=mem%!((r%(r%)+D%)mm%)a% : X(Rn) =mem%!(D%mm%)a% &: 01dst2(dd%,v%,b%): Store dest value from MOV :P b%=1: dd%<8:r%(dd%)=(v%&FF) (&FF00 (v%128)<>0): : MOVB ,Rn DBdst(dd%,v%,b%): Store dest value and post-access reg adjust N0 Storing to mode 7 needs to double indirect XD m%,r%:m%=dd%8:r%=dd%7:v%=v%&FFFF:b%=2-b%: r%>5: m%<6:b%=2 b| IF b%=2:IF(D%AND1):IF(debug%AND8)=0:PRINT"Bus error: word write to odd address (";m%;"/";r%;")":halt%=TRUE:abort%=TRUE lY IF m%=0:IF b%=1:r%(r%)=(v%AND&FF) OR (&FF00 AND (v%AND128)<>0):ENDPROC :REM Rn vL m%=0: b%=1:r%(r%)=(v%&FF) (&FF00 r%(r%)): : Rn R m%=0:r%(r%)=v%: : Rn e m%<6:mem%?(D%mm%)=v%:b%=2:mem%?((D%+1)mm%)=v%256 : (Rn) [@]-(Rn) [@](Rn)+ U m%=2:r%(r%)=r%(r%)+b%: : (Rn)+ V m%=3:r%(r%)=r%(r%)+2: : @(Rn)+ T m%=6:mem%?((r%(r%)+D%)mm%)=v%: b%=2:mem%?((r%(r%)+D%+1)mm%)=v%256 : X(Rn) a m%=7:mem%?(mem%!((r%(r%)+D%)mm%)mm%)=v%: b%=2:mem%?(mem%!((r%(r%)+D%)mm%+1)mm%)=v%256  : Opsw(v%,b%,cv%,nv%,cc%,nc%): value, byte?, changeV?, newV, changeC?, newC ( v%=0:psw%=psw%4 psw%=psw%&FFFB 0 b%=0:psw%=(psw%&FFF7)(((v%&8000)<>0)8) , b%:psw%=(psw%&FFF7)(((v%&80)<>0)8) ( cv%:psw%=(psw%&FFFD)((nv%<>0)2) ( cc%:psw%=(psw%&FFFE)((nc%<>0)1)   :  /carry(c%):psw%=(psw%&FFFE)((c%<>0)1): *(ݤsxt(A%):=A%((A%>&7FFF)&FFFF0000) 4: > b1xxxx - MOV/MOVB: HQݤ_1:V%=src(ss%,by%):pre(dd%,by%):dst2(dd%,V%,by%):psw(V%,by%,1,0,0,0):=0 R: \ b2xxxx - CMP/CMPB: f3ݤ_2:V%=src(ss%,by%):W%=src(dd%,by%):R%=V%-W% pW by%:V%=((V%&80)<>(W%&80))((R%&80)=(W%&80)):psw(R%,0,1,V%,1,R%&FFFFFF00):=0 zYV%=((V%&8000)<>(W%&8000))((R%&8000)=(W%&8000)):psw(R%,0,1,V%,1,R%&FFFF0000):=0 :  b3xxxx - BIT/BITB: Eݤ_3:V%=src(ss%,by%):W%=src(dd%,by%):psw(V%W%,by%,1,0,0,0):=0 :  b4xxxx - BIC/BICB: 8ݤ_4:V%=src(ss%,by%):pre(dd%,by%):W%=dst(dd%,by%) 6V%=V%W%:dst(dd%,V%,by%):psw(V%,by%,1,0,0,0):=0 :  b5xxxx - BIS/BISB: 8ݤ_5:V%=src(ss%,by%):pre(dd%,by%):W%=dst(dd%,by%) 5V%=V%W%:dst(dd%,V%,by%):psw(V%,by%,1,0,0,0):=0 :  b6xxxx - ADD/SUB: Lݤ_6:V%=src(ss%,0):pre(dd%,0):W%=dst(dd%,0): by%:R%=W%-V% R%=W%+V% (W%&8000))((R%&8000)=(V%&8000)) >by%=0:V%=((V%&8000)=(W%&8000))((R%&8000)<>(V%&8000)) $:dst(dd%,R%,0):psw(R%&FFFF,0,1,V%,1,R%&FFFF0000):=0 .: 8/ b7xxxx - MUL/DIV/ASH/ASHC/XOR/Fop/???/SOB B(ݤ_7: by%:=0 =("FN_7"+~(ss%8)) L: V2 b0xxxx - HALT/etc/Bxx/JSR/CLRetc/RORetc/und: `,ݤ_0:(ss%&20)=0: ss%>3 by%:=branch jH ss%8=7:=0 : x07xxx - CSM/.../TSET/WLCK/.../.../.../... t9 ss%8=4:=_04 : x04rdd - JSR Rn,dst/EMT/TRAP ~#=("FN_0"+o0(ss%,2)) : x0xxdd : Nݤbranch:dist%=dd%+(ss%3)*64:op%=ss%4+op%: IFINKEY-113:mem%?escflg%=&FF < op%=1 :=rel() : BR D op%=2 :=rel((psw%4)=0) : BNE - Z=0 D op%=3 :=rel((psw%4)<>0) : BEQ - Z=1 G op%=4 :=rel(((psw%8)<>0)((psw%2)<>0)=0) : BGE - N XOR V =0 G op%=5 :=rel(((psw%8)<>0)((psw%2)<>0)<>0) : BLT - N XOR V =1 W op%=6 :=rel(((psw%4)<>0((psw%8)<>0(psw%2)<>0))=0) : BGT - Z OR (N XOR V)=0 W op%=7 :=rel(((psw%4)<>0((psw%8)<>0(psw%2)<>0))<>0): BLE - Z OR (N XOR V)=1 D op%=8 :=rel((psw%8)=0) : BPL - N=0 D op%=9 :=rel((psw%8)<>0) : BMI - N=1 G op%=10:=rel(((psw%1)<>0)((psw%4)<>0)=0) : BHI - C OR Z =0 G op%=11:=rel(((psw%1)<>0)((psw%4)<>0)<>0) : BLOS- C OR V =1  D op%=12:=rel((psw%2)=0) : BVC - V=0 D op%=13:=rel((psw%2)<>0) : BVS - V=1 D op%=14:=rel((psw%1)=0) : BCC - C=0 (D op%=15:=rel((psw%1)<>0) : BCS - C=1 2=0 <: Fݤrel(A%): A%:=0 P? dist%>127:r%(7)=r%(7)-(256-dist%)*2 r%(7)=r%(7)+dist%*2 Z=0 d: n3 0000dd - HALT/WAIT/RTI/BPT/IOT/RESET/RTT/MFPT x ݤ_000 & dd%=0:halt%=:abort%=:=0: HALT  dd%=1:=0 : WAIT h dd%=2:r%(7)=mem%!(r%(6)mm%)&FFFF:psw%=mem%!((r%(6)+2)mm%)&FFFF:r%(6)=(r%(6)+4)&FFFF:=0 : RTI  dd%=3:=0 : BPT  dd%=4:=0 : IOT ! dd%=5:=0 : RESET h dd%=6:r%(7)=mem%!(r%(6)mm%)&FFFF:psw%=mem%!((r%(6)+2)mm%)&FFFF:r%(6)=(r%(6)+4)&FFFF:=0 : RTT  dd%=7:=0 : MFPT =0 :  0001dd - JMP: Pݤ_001:(dd%&38)=0 dd%=&17:(debug%8)=0:"JMP fault":halt%=:abort%=:=0 ]A%=src(dd%,0):(D%1):(debug%8)=0:"Bus error: JMP to odd address":halt%=:abort%=:=0 r%(7)=D%&FFFF:=0 : 0 0002xx - RTS/-/-/SPL/Clear flags/Set flags " ݤ_002 ,/ dd%>47:psw%=psw%(dd%15):=0 : Sxx 6, dd%>23:psw%=psw%(dd%15):=0 : Cxx @2(dd%8)=3:=0 : SPL n J.(dd%8)=2:=0 : - T.(dd%8)=1:=0 : - ^;r%=dd%7:r%(7)=r%(r%):W%=mem%?(r%(6)mm%):r%(6)=r%(6)+1 hLW%=mem%?(r%(6)mm%)*256+W%:r%(6)=r%(6)+1:r%(r%)=W%:=0 : RTS r r: | 0003dd - SWAB: Jݤ_003:pre(dd%,0):V%=dst(dd%,0):!zp%=V%:zp%!2=V%:R%=zp%!1: AND&FFFF (dst(dd%,R%,0):psw(V%,0,1,0,1,0):=0 : # 004rdd - JSR Rn,dst/EMT/TRAP: ݤ_04: by%:=_TRAP ;(dd%&38)=0 dd%=&17:"JSR fault":halt%=:abort%=:=0 OA%=src(dd%,0):(D%1):"Bus error: JSR to odd address":halt%=:abort%=:=0  by%:psw((V%+W%)&FF,by%,1,V%=&7F W%,1,V%=&FF W%):=0 >psw((V%+W%)&FFFF,by%,1,V%=&7FFF W%,1,V%=&FFFF W%):=0 :  b056dd - SBC: Gݤ_056:pre(dd%,by%):V%=dst(dd%,by%):W%=psw%1:dst(dd%,V%-W%,by%) A by%:psw((V%-W%)&FF,by%,1,(V%-W%)=&80 W%,1,V%=0 W%):=0 ?psw((V%-W%)&FFFF,by%,1,(V%-W%)=&8000 W%,1,V%=0 W%):=0 :   b057dd - TST: 3ݤ_057:V%=src(dd%,by%):psw(V%,by%,1,0,1,0):=0  : * b060dd - ROR: 43ݤ_060:pre(dd%,by%):V%=dst(dd%,by%):W%=psw%1 >O by%=1:R%=((V%>>1)(W%<<7))&FF:psw(R%,by%,1,(R%>&7F)((V%1)<>0),1,V%1) HL by%=0:R%=(V%>>1)(W%<<15):psw(R%,by%,1,(R%>&7FFF)((V%1)<>0),1,V%1) Rdst(dd%,R%,by%):=0 \: f b061dd - ROL: p3ݤ_061:pre(dd%,by%):V%=dst(dd%,by%):W%=psw%1 zN by%=1:R%=((V%<<1)W%)&FF:psw(R%,by%,1,(R%>&7F)((V%&80)<>0),1,V%&80) V by%=0:R%=((V%<<1)W%)&FFFF:psw(R%,by%,1,(R%>&7FFF)((V%&8000)<>0),1,V%&8000) dst(dd%,R%,by%):=0 :  b062dd - ASR: )ݤ_062:pre(dd%,by%):V%=dst(dd%,by%) P by%=1:R%=((V%>>1)(V%&80))&FF:psw(R%,by%,1,(R%>&7F)((V%1)<>0),1,V%1) N by%=0:R%=(V%>>1)(V%&8000):psw(R%,by%,1,(R%>&7FFF)((V%1)<>0),1,V%1) dst(dd%,R%,by%):=0 :  b063dd - ASL: )ݤ_063:pre(dd%,by%):V%=dst(dd%,by%) I by%=1:R%=(V%<<1)&FE:psw(R%,by%,1,(R%>&7F)((V%&80)<>0),1,V%&80) Q by%=0:R%=(V%<<1)&FFFE:psw(R%,by%,1,(R%>&7FFF)((V%&8000)<>0),1,V%&8000) dst(dd%,R%,by%):=0 :  b064dd - MARK/MTPS: $=ݤ_064:by%:psw%=src(dd%,0):=0 : MTPS .<"#"o0(r%(7)-2,6)":"o0(mem%!(r%(7)-2),6)"#";:=0: MARK 8: BHݤ_065:"#"o0(r%(7)-2,6)":"o0(mem%!(r%(7)-2),6)"#";:=0: MFPI/MFPD LHݤ_066:"#"o0(r%(7)-2,6)":"o0(mem%!(r%(7)-2),6)"#";:=0: MTPI/MTPD V: ` b067dd - SXT/MFPS: j8ݤ_067:by%:pre(dd%,0):dst(dd%,psw%,0):=0 : MFPS tQpre(dd%,0):V%=((psw%8)<>0)&FFFF:dst(dd%,V%,0):psw(V%,0,1,0,0,0):=0: SXT ~:  070rss - MUL: ; R(n)=b16-b31 of result, then R(nOR1)=b0-b15 of result F C set if result>&7FFFFFFF or <&80000000, R(n), R(nOR1) corrupted  V always cleared 7ݤ_70:r%=ss%7:V%=sxt(src(dd%,0)):W%=sxt(r%(r%)) Jr=V%*W%:W%=r:r%(r%)=W%>>>16:r%(r%1)=W%&FFFF:psw(W%,0,1,0,1,W%>>>16) #psw%=(psw%&FFF7)((W%<0)8):=0 :  071rss - DIV: ; If dest reg is odd, Set overflow, registers unchanged 8 If divisor is 0, Set overflow, registers unchanged L If result larger than 15 bits, Set Carry+Overflow, registers unchanged / Otherwise, R(n)=result, R(nOR1)=remainder  Eݤ_71:r%=ss%7:V%=sxt(src(dd%,0)): r%1:psw%=(psw%&FFFD)2:=0 ER%=r%(r%1):W%=r%(r%):!zp%=R%:zp%!2=W%: V%:W%=!zp%V%:R%=!zp%V% 3psw(W%,0,1,V%=0 W%>32767 W%<-32768,1,V%=0) (@(debug%256) (psw%2)=0:r%(r%1)=R%&FFFF:r%(r%)=W%&FFFF 2=0 <: F 072rdd - ASH: P.ݤ_72:r%=ss%7:V%=src(dd%,0)63:W%=r%(r%) ZB V%<32:R%=W%<31:R%=(W%<<16)>>(79-V%):psw(R%>>1,0,1,((R%>>1)W%)&8000,1,R%1):R%=R%>>1 nr%(r%)=R%&FFFF:=0 x:  073rdd - ASHC: Cݤ_73:r%=ss%7:V%=src(dd%,0)63:R%=(r%(r%)<<16)r%(r%1):W%=R% ( V%<32:C%=R%(1<<(32-V%)):R%=R%<31:(r%1)=0:C%=R%(1<<(63-V%)):R%=R%>>(64-V%) M V%>31:(r%1)=1:R%=R%&FFFF:R%=R%(R%<<16):R%=(R%>>>(64-V%))&FFFF:C%=0 Dpsw(R%,0,1,(V%W%)&80000000,1,C%):psw%=(psw%&FFF7)((R%<0)8) 'r%(r%1)=R%>>>16:r%(r%)=R%&FFFF:=0 :  074rdd - XOR: 4ݤ_74:pre(dd%,0):V%=dst(dd%,0):R%=V%r%(ss%7) (dst(dd%,R%,0):psw(R%,0,1,0,0,0):=0 : " 075rdd - FADD/FSUB/FMUL/FDIV ;ݤ_75:"#"o0(r%(7)-2,6)":"o0(mem%!(r%(7)-2),6)"#";:=0 :  076nnn - unused " ݤ_76:=0 ,: 6 077rdd - SOB: @Wݤ_77:dist%=dd%-192*(dd%>31):ss%=ss%7:V%=(r%(ss%)-1)&FFFF:r%(ss%)=V%:=rel(V%<>0) J: T > EMT ^ EMT interface to host h< v0.22 27-Sep-2009 OSBYTE 160 translated to host calls r) v0.25 10-Jan-2014 Added OSWORD 190 |\ v0.28 25-Oct-2015 Added more OSBYTE 160 translations, OSBYTE 135 returns shadow MODEs 5 v0.29a 10-May-2020 OSWORD optimised with X%!... ) v0.30 11-Mar-2021 Windows OSFILE 5 / v0.31 01-Nov-2023 Tweeks for SDL/Android O NB: Keyboard tested for with: kbd%=(os%<8):IF(INKEY-256AND&DB)=&53:kbd%=1 : Mݤ_TRAP:dd%=dd%+(ss%7)*64:(debug%4):DbTrap(dd%): &0xx=EMT, &1xx=TRAP Ÿtrapvec%:dd%>255:r%(6)=(r%(6)-4)&FFFF:mem%!r%(6)=r%(7):mem%?(r%(6)+2)=psw%:mem%?(r%(6)+3)=psw%256:psw%=mem%!&1E &FFFF:r%(7)=mem%!&1C &FFFF:r7%=0:=0 4dd%<16:psw%=psw%-4:A%=r%(0):=("FN_EMT"+~dd%) #dd%<224:=("FN_EMT("+dd%+")") (dd%<256:A%=r%(0):=("FN_EMT"+~dd%) add%=dd%&FF:r7%=r%(7):dd%<&40:psw%=psw%-4:A%=("FN_TRAP"+~dd%) A%=("FN_TRAP("+dd%+")") r%(7)=r7%:r7%=0:=A% : FDbTrap(dd%):(dd%>3 dd%<7) (dd%>&102 dd%<&105 r%(0)<3): dd%<16:"OS";"QUITCLI BYTEWORDWRCHNEWLRDCHFILEARGSBGETBPUTGBPBFINDSYSTCTRLERR ",dd%*4+1,4);" r0=";ho(r%(0),4);" r1=";h0(r%(1),4);" r2=";h0(r%(2),4): 9dd%<256::"EMT ";~dd%;" r0=";~r%(0):: EMT &10-&FF &>A%=r%(7):dd%=&100:A%=mem%!r%(7)&FFFF:dd%=mem%?A%:A%=A%+2 0(dd%&20)=&00: "indir exit fork read write open close wait creat link unlinkexec chdir time mknod chmod chown brk stat lseek getpidmount umountsetuidgetuidstime ptrace[27] fstat pause utime stty ",(dd%31)*6+1,6); :(dd%&20)=&20: "gtty [33] nice ftime sync kill switch[39] [40] dup2 pipe times profiltui setgidgetgidsignal[49] [50] acct phys lock ioctl [55] mpxchn[57] [58] exece umask chroot[62] [63] ",(dd%31)*6+1,6); Db" r0=";o0(r%(0),6);" p1=";h0(mem%!A%,4);" p2=";h0(mem%!(A%+2),4);" p3=";h0(mem%!(A%+4),4) N X: b>ݤ_EMT0:halt%=:=0 : QUIT lDݤ_EMT1:EscOn:cmd($(mem%+r%(0)),):r%(0)=0:EscOff:=0 : OSCLI v=ݤ_EMT2: X%,Y%:psw%=psw%-2 : OSBYTE Q A%=&82:r%(1)=0:r%(2)=0:=0 : high order address M A%=&83:r%(1)=membot%:r%(2)=membot%256:=0 : bottom of memory J A%=&84:r%(1)=memtop%:r%(2)=memtop%256:=0 : top of memory L A%>123:A%<127:mem%?escflg%=128*(A%1):"FX15" : Clear/Set/Ack Escape ` A%=&7F:r%(1)=0 r%(1)=&FFFF:r%(1)=0:=0 : =EOF#0/-1:REM Should check keyboard C A%=&A0:os%=6:vdu:=0 : =VDU(n) . A%=&00:r%(1)=0: 247,"PDPTube "+ver$:=0 8 A%=&00:(-256&DF)=83:(@platform%15):r%(1)=8:=0 ~ os%<32:X%=r%(1):Y%=r%(2):A%=&FFF4:r%(1)=(A%&FFFF00)256:r%(2)=(A%&FF0000)65536:carry(A%&1000000):(A%&FF)<>&87:=0 U os%<32:X%=0:A%=&75:r%(2)=r%(2)(((&FFF4)&1000)32):=0: OSBYTE &87 adjustment  Windows OSBYTE calls: 4 A%=128:r%(1)=7:ȗ r%(1),A%,A%:r%(2)=A%256:=0 4 A%=128:r%(1)=8:ȗ A%,r%(1),A%:r%(2)=A%256:=0 4 A%=128:r%(1)=9:ȗ A%,A%,r%(1):r%(2)=A%256:=0  Ȏ A%  0:r%(1)=os%:=0   127:r%(1)=#r%(1):=0 *n If on Windows, ADVAL-1/-2 need to be 255-ADVAL - but client should do this as OSBYTE 0,1 returns DOS/Win 4V 128:A%=((r%(1)255)+256*r%(2)((r%(2)>&7F)&FFFF0000)):r%(1)=A%:r%(2)=A%256:=0 >~ 129:A%=((r%(1)255)+256*r%(2)((r%(2)>&7F)&FFFF0000)):carry(A%=-1 r%(2)<&80):r%(1)=A%:r%(2)=A%256:carry(A%=-1):=0 H 134:r%(1)=:r%(2)=:=0 R! 135:r%(1)=(,):r%(2)=:=0 \ 160: fȎ r%(1) p4 0,128:ș "GetRgnBox",@vdu%!60,zp%:r%(1)=zp%!0 z4 1 :ș "GetRgnBox",@vdu%!60,zp%:r%(1)=zp%!1 4 2,129:ș "GetRgnBox",@vdu%!60,zp%:r%(1)=zp%!4 4 3 :ș "GetRgnBox",@vdu%!60,zp%:r%(1)=zp%!5 6 4,130:ș "GetRgnBox",@vdu%!60,zp%:r%(1)=zp%!8-1 < 5 :ș "GetRgnBox",@vdu%!60,zp%:r%(1)=(zp%!8-1)256 9 6,131:ș "GetRgnBox",@vdu%!60,zp%:r%(1)=zp%!12/2-1 ? 7 :ș "GetRgnBox",@vdu%!60,zp%:r%(1)=(zp%!12/2-1)256 ' 8,132:r%(1)=@vdu%!24 @vdu%!216 ) 9,133:r%(1)=@vdu%!36 @vdu%!220-1 ) 10,134:r%(1)=@vdu%!28 @vdu%!216-1 ' 11,135:r%(1)=@vdu%!32 @vdu%!220  12,136:r%(1)=2*@vdu%!0 " 13 :r%(1)=2*@vdu%!0 256  14,137:r%(1)=2*@vdu%!4 " 15 :r%(1)=2*@vdu%!4 256  16,138:r%(1)=2*@vdu%!8 " 17 :r%(1)=2*@vdu%!8 256 $D 18,139:ș "GetRgnBox",@vdu%!60,zp%:r%(1)=2*(zp%!12-@vdu%!12-1) .J 19 :ș "GetRgnBox",@vdu%!60,zp%:r%(1)=2*(zp%!12-@vdu%!12-1) 256 8 20,142:r%(1)=@vdu%!16 B! 21 :r%(1)=@vdu%!16 256 LB 22,143:ș "GetRgnBox",@vdu%!60,zp%:r%(1)=(zp%!12-@vdu%!20-1) VH 23 :ș "GetRgnBox",@vdu%!60,zp%:r%(1)=(zp%!12-@vdu%!20-1) 256 ` 24 :r%(1)= j 25 :r%(1)= t 36 :r%(1)=@vdu%!8 ~ 37 :r%(1)=@vdu%!8 256 B 38 :ș "GetRgnBox",@vdu%!60,zp%:r%(1)=(zp%!12-@vdu%!12-1) H 39 :ș "GetRgnBox",@vdu%!60,zp%:r%(1)=(zp%!12-@vdu%!12-1) 256  85 :r%(1)=  87,155:r%(1)=8*@vdu%?70  88,156:r%(1)=8*@vdu%?71  89,153:r%(1)=8*@vdu%?65  90,154:r%(1)=8*@vdu%?67 4 91,151:r%(1)=3-(@vdu%?64-7)2:r%(1)<0:r%(1)=1 4 92,152:r%(1)=3-(@vdu%?66-7)2:r%(1)<0:r%(1)=1  96,3 :r%(1)=@vdu%?73  98 : Left colour mask  99 : Right colour mask  109 :r%(1)=@vdu%?65   110 :r%(1)=@vdu%?67  155 :r%(1)=@vdu%?70  156 :r%(1)=@vdu%?71 ( 153 :r%(1)=@vdu%?65 2 154 :r%(1)=@vdu%?67 < F r%(1)=0 P Zr%(2)=r%(1)256:=0 d ncX%=r%(1):Y%=r%(2):A%=&FFF4:r%(1)=(A%&FFFF00)256:r%(2)=(A%&FF0000)65536:carry(A%&1000000) x =0 ݤvdu: r%(1)<16:=0  ARM and R1>15 Ȏ r%(1)  16,17:A%=138  18,19:A%=139  20,21:A%=142  22,23:A%=143  24 :r%(1)=:=  25 :r%(1)=:=  36,37:A%=144  38,39:A%=145  78 :A%=148  80,81:A%=149  84 :A%=150:r%(1)=85  87 :A%=155:r%(1)=-1 " 88 :A%=156:r%(1)=-1 , 89 :A%=153:r%(1)=-1 6 90 :A%=154:r%(1)=-1 @ 91 :A%=151:r%(1)=0 J 92 :A%=152:r%(1)=0 T 96 :A%=3 ^ 109 :A%=153:r%(1)=0 h 110 :A%=154:r%(1)=0 r |(A%=r%(1): A%<128:r%(1)=0:r%(1)=0:=  n!zp%=A%:zp%!4=-1:ș "OS_ReadVduVariables",zp%,zp%+8: r%(1)=-1:zp%!8=zp%!8*8 r%(1)1:zp%!8=zp%!8 256 r%(1)=zp%!8:r%(2)=r%(1)256 = : +ݤ_EMT3: X%,Y% : OSWORD X%=mem%+r%(1):Y%=X%256 : A%=0:EscOn:input:$(mem%+(!X%&FFFF))=A$:EscOff:=0 < A%=190: X%?2=11: ?X%>8:A%=Dis_Code(11,X%!4,X%!8):=0 7 A%=190: X%?2=11: ?X%<9:$(X%+4)=Dis_Name(11):=0  <&FFFF A%=10: &FFF1:=0  Ȏ A%  1:!X%=:=0  2:=!X%:=0  7: X%!0,X%!2,X%!4,X%!6:=0 V 8: X%?0,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 &* 9:X%?4=!X% &FFFF,X%!2 &FFFF):=0 0 14:?X%=0:$X%=$:=0 :$ 15:X%?(?X%+1)=13:$=$(X%+1):=0 D N=0 X3ݤ_EMT4: A%:=0 : OSWRCH b1ݤ_EMT5::r%(0)=13:=0 : OSNEWL l0ݤ_EMT6:r%(0)=:carry(r%(0)=27):=0: OSRDCH v5ݤ_EMT7 : OSFILE + A%=2 14 4:X%!A%=mem%!(r%(1)+A%):  r%(0)=255:addr(2) # r%(0)=0 :addr(10):addr(14) &FFFFF:A$=s($fn%) = A$=34:A$=A$,2,A$,"""",2)-1) A$=A$,A$+" "," ")-1)  -256=87 r%(0)=5 dir%,sh%:dir%319 =ș"FindFirstFile",f_name(A$),dir%sh%:sh%=-1:r%(0)=0:=0 5ș"FindClose",sh%:X%!10=dir%!32:dir%!28:X%!10=-1 BX%?14=(?dir%1)*8+(&33 ((?dir%16)=0)):r%(0)=(?dir%16)16+1 )ș"FileTimeToSystemTime",dir%+20,dir% LA%=(!dir%&FFFF)-1981:X%?15=dir%?6+(A%&70)*2:X%?16=dir%?2+A%*16:X%?17=0 . A%=2 14 4:mem%!(r%(1)+A%)=X%!A%::=0 ! ! w <&FFFFF:ș "OS_File",r%(0),$fn%,X%!2,X%!6,X%!10,X%!14 r%(0),,X%!2,X%!6,X%!10,X%!14 r%(0)=file(cd$+A$,r%(0)) !@ IF r%(0)=0 OR r%(0)=255:PROCaddr(2):IF r%(0)=0:PROCaddr(6) ! . A%=2 14 4:mem%!(r%(1)+A%)=X%!A%::=0 !*-addr(A%):X%!A%<&10000:X%!A%=mem%+A%!X% !4 !>/ݤ_EMT8 : OSARGS !H- os%>31: A%=0: r%(1)=0:r%(0)=fsnum%:=0 !R/ A%=0: r%(1)=0: Y%:r%(0)=(&FFDA)&FF:=0 !\ r%(1)=0 r%(1)=&FFFF !f Ȏ A% !p8 Add EXT#-1=keyboard buffer, EOF#-1=keyboard buffer !z% 0:mem%!r%(2)=0:=0 : =PTR#0/-1 !% 1:=0 : PTR#0/-1= !% 2:mem%!r%(2)=0:=0 : =EXT#0/-1 !% 3:=0 : EXT#0/-1= !' 4:mem%!r%(2)=0:=0 : =Alloc#0/-1 !% 5:mem%!r%(2)=0:=0 : =EOF#0/-1 !' 6:=0 : Alloc#0/-1= ! ! ! Ȏ A% ! 0:mem%!r%(2)=#r%(1):=0 ! 1:#r%(1)=mem%!r%(2):=0 ! 2:mem%!r%(2)=#r%(1):=0 ! 3:#r%(1)=mem%!r%(2):=0 " 4:mem%!r%(2)=#r%(1):=0 " 5:mem%!r%(2)=#r%(1):=0 " 6:#r%(1)=mem%!r%(2):=0 "$ 255:os%>31:=0 ". "8/mem%!r%(1)=args(r%(0),r%(1),mem%!r%(2)):=0 "B "L=0 "V,ݤ_EMT9: r%(1)=0:r%(0)=:=0 : OSBGET "`1os%=32:r%(0)=#r%(1):carry(#r%(1)&100):=0 "j? Y%:Y%=r%(1):A%=&FFD7:r%(0)=A%&FF:carry(A%&1000000):=0 "t6ݤ_EMTA:r%(1)=0: A%:=0 #r%(1),A%:=0 : OSBPUT "~/ݤ_EMTB : OSGBPB "' A%=0 12:X%?A%=mem%?(r%(1)+A%): "&B%=(X%!1<&10000):addr(1):A%=r%(0) "4 ?X%=0:A%=1A%=2:?(X%!1):X%!5=X%!5-1:X%!5<1 "5 ?X%=0:A%=3A%=4:?(X%!1)=:X%!5=X%!5-1:X%!5<1 ", ?X%:f_gbpb(r%(0),X%?0,X%!1,X%!5,X%!9) " B%:X%!1=X%!1-mem% "' A%=0 12:mem%?(r%(1)+A%)=X%?A%: "=0 "/ݤ_EMTC : OSFIND " A%=0:#r%(1):=0 "8 (A%&C0)=&40:r%(0)=f_openin(cd$+$(mem%+r%(1))):=0 "9 (A%&C0)=&80:r%(0)=f_openout(cd$+$(mem%+r%(1))):=0 #8 (A%&C0)=&C0:r%(0)=f_openup(cd$+$(mem%+r%(1))):=0 # =0 #,ݤ_EMTD : SYS #+A%=0:r%(1):=_BASIC($(mem%+r%(1))):=0 #("A%=0:r%(1)=0:=_BASIC(""):=0 #26A%=1:memtop%<&F800:mem%!&F5FC=mem%!&F5FA &FFFF #< IF(INKEY-256AND&DF)=83:IF (@platform% AND &0F)=3:*OSK ON #A$="":::B%=(100):B%<>-1 #*B%>31:B%<>127:A$<255:A$=A$+B%:B% #(B%=127B%=8:A$:A$=A$,A$-1):127 #"B%=21:A$:ĩA$,127);:A$="" #B%=10B%=13:: #: # > Unix $ PDP11 Unix Trap functions $2 v0.15 04-Mar-2006 Separated out from PDP11Em $> 17-Mar-2006 read/write done, added exit,open,close $"# v0.16 20-May-2006 Added indir $,8 v0.17 20-Feb-2009 Added rudimentary SIGINT capture $6; v0.23 17-Jun-2010 TRAP0 calls TRAPn instead of TRAPnn $@9 v0.24 02-Jul-2010 TRAPB and TRAP3B execute commands $J> v0.25 20-Jan-2012 brk(), pipe() fetch correct parameters $T% v0.26 20-Jun-2012 Added ftime() $^D Note, different parameters for v7/pre-v7 for lseek(), ioctrl() $hO By ioctrl() returning CarryClear (via dispatcher), declares to be Unix V7 $r. v0.31 01-Nov-2023 Tweeks for SDL/Android $|: $Cݤ_TRAP0: indir - entry: (pc+0)=>TRAP instruction, parameters $Qr7%=mem%!r%(7)&FFFF : Address of ind'ed TRAP instruction $Cdd%=mem%!r7%255:r7%=r7%+2:ind%=r%(7)+2 : Get TRAP instruction $? dd%<&40:A%=("FN_TRAP"+~dd%) A%=("FN_TRAP("+dd%+")") $r7%=r%(7)+2:ind%=0:=A% $: $(ݤ_TRAP1: exit - entry: r0=status $ halt%= $=0 $: $ݤ_TRAP2: fork - $3=0 : - exit: r0=new process ID $: %Fݤ_TRAP3: read - entry: r0=filedes, (pc+0)=buffer, (pc+2)=count %/ exit: r0=byte count %>buffer%=mem%!r7%&FFFF:count%=mem%!(r7%+2)&FFFF:r7%=r7%+4 %&Jr%(0)<3:"FX126":A%=0count%-1:mem%?(buffer%+A%)=::r%(0)=count%:=0 %0:gbpb(4,r%(0),mem%+buffer%,count%,0):r%(0)=count%-X%!5 %:=0 %D: %NFݤ_TRAP4: write - entry: r0=filedes, (pc+0)=buffer, (pc+2)=count %X/ exit: r0=byte count %b>buffer%=mem%!r7%&FFFF:count%=mem%!(r7%+2)&FFFF:r7%=r7%+4 %l@r%(0)<3:A%=0count%-1:mem%?(buffer%+A%)::r%(0)=count%:=0 %v:gbpb(2,r%(0),mem%+buffer%,count%,0):r%(0)=count%-X%!5 %=0 %: %8ݤ_TRAP5: open - entry: (pc+0)=>name, (pc+2)=mode %, exit: r0=filedes %Cname%=mem%!r7%&FFFF:mode%=mem%!(r7%+2)&FFFF:r7%=r7%+4:r%(0)=0 %3mode%=0:r%(0)=f_openin(cd$+str0(mem%+name%)) %4mode%=1:r%(0)=f_openout(cd$+str0(mem%+name%)) %3mode%=2:r%(0)=f_openup(cd$+str0(mem%+name%)) %$r%(0)=0:r%(0)=&FFFF:psw%=psw%1 %=0 %: %)ݤ_TRAP6: close - entry: r0=filedes %r%(0)>2:#r%(0) &=0 & : &ݤ_TRAP7: wait - & :=0 exit: r0=process ID, r1=status &*: &48ݤ_TRAP8: creat - entry: (pc+0)=>name, (pc+2)=mode &>, exit: r0=filedes &H;name%=mem%!r7%&FFFF:mode%=mem%!(r7%+2)&FFFF:r7%=r7%+4 &R@r%(0)=f_openout(cd$+str0(mem%+name%)):r%(0)=0:r%(0)=&FFFF &\=0 &f: &p;ݤ_TRAP9: link - entry: (pc+0)=>name1, (pc+2)=>name2 &zr7%=r7%+4:r%(0)=&FFFF:=0 &: &+ݤ_TRAPA: unlink - entry: (pc+0)=>name &*name%=mem%!r7%&FFFF:r7%=r7%+2:r%(0)=0 &@A%=file(7,cd$+f_name(str0(mem%+name%))):A%=0:r%(0)=&FFFF &=0 &: &9ݤ_TRAPB: exec - entry: (pc+0)=>name, (pc+2)=>argv &;name%=mem%!r7%&FFFF:mode%=mem%!(r7%+2)&FFFF:r7%=r7%+4 &^str0(mem%+(mem%!mode%&FFFF))="sh":cmd(str0(mem%+(mem%!(mode%+4)&FFFF)),):r%(0)=0:=0 &=0 &: &.ݤ_TRAPC: chdir - entry: (pc+0)=>dirname &*name%=mem%!r7%&FFFF:r7%=r7%+2:r%(0)=0 'Fos%<7:"DIR "+str0(mem%+name%) "chdir "+cd$+str0(mem%+name%) '=0 ': '$ݤ_TRAPD: time - '.B exit: r0:r1=time since 1970 in seconds '82!zp%= 100:r%(1)=!zp%&FFFF:r%(0)=zp%!2&FFFF 'B=0 'L: 'VEݤ_TRAPE: mknod - entry: (pc+0)=>name, (pc+2)=mode, (pc+4)=addr '`;name%=mem%!r7%&FFFF:mode%=mem%!(r7%+2)&FFFF:r7%=r7%+6 'j=(mode%16384):A%=file(8,cd$+f_name(str0(mem%+name%))) 't=0 '~: 'Fݤ_TRAPF :r7%=r7%+4:=0: chmod - entry: (pc+0)=>name, (pc+2)=mode 'Uݤ_TRAP10:r7%=r7%+6:=0: chown - entry: (pc+0)=>name, (pc+2)=owner, (pc+4)=group ': '+ݤ_TRAP11: brk - entry: (pc+0)=addr '=addr%=mem%!r7%&FFFF:r7%=r7%+2:addr%>memtop%:psw%=psw%1 '=0 ': '9ݤ_TRAP12: stat - entry: (pc+0)=>name, (pc+2)=>buf 'Ename%=mem%!r7%&FFFF:buffer%=mem%!(r7%+2)&FFFF:r7%=r7%+4:r%(0)=0 '@A%=file(5,cd$+f_name(str0(mem%+name%))):A%=0:r%(0)=&FFFF 'mem%!(buffer%+14)=X%!10 '=0 (: ( ]ݤ_TRAP13: lseek - entry: r0=filedes, (pc+0)=>offsethi, (pc+2)=>offsetlo, (pc+4)=whence (]offset%=(mem%!(r7%+2)&FFFF)(mem%!(r7%-2)&FFFF0000):where%=mem%!(r7%+4)&FFFF:r7%=r7%+6 (r%(0)<3:r%(0)=0:r%(1)=0:=0 ((where%=0:#r%(0)=offset% (2%where%=1:#r%(0)=#r%(0)+offset% (<%where%=2:#r%(0)=#r%(0)+offset% (F5r%(1)=#r%(0):r%(0)=r%(1)65536:r%(1)=r%(1)&FFFF (P=0 (Z: (d:ݤ_TRAP14:r7%=r7%+0:=0: getpid - exit: r0=process ID (nYݤ_TRAP15:r7%=r7%+6:=0: mount - entry: (pc+0)=>special, (pc+2)=>name, (pc+4)=rwflag (x<ݤ_TRAP16:r7%=r7%+2:=0: umount - entry: (pc+0)=>special (3ݤ_TRAP17:r7%=r7%+0:=0: setuid - entry: r0=uid (Jݤ_TRAP18:r7%=r7%+0:=0: getuid - exit: r0=real uid, r1=effective uid (Bݤ_TRAP19:r7%=r7%+0:=0: stime - entry: r0:r1=time since 1970 (]ݤ_TRAP1A:r7%=r7%+6:=0: ptrace - entry: r0=data, (pc+0)=pid, (pc+2)=addr, (pc+4)=request (8 exit: r0=value (!ݤ_TRAP1B:r7%=r7%+0:=0: [27] (Eݤ_TRAP1C:r7%=r7%+2:=0: fstat - entry: r0=filedes, (pc+0)=>buff ("ݤ_TRAP1D:r7%=r7%+0:=0: pause (Gݤ_TRAP1E:r7%=r7%+4:=0: utime - entry: (pc+0)=>file, (pc+2)=timep (Dݤ_TRAP1F:r7%=r7%+2:=0: stty - entry: r0=filedes, (pc+0)=argp (Dݤ_TRAP20:r7%=r7%+2:=0: gtty - entry: r0=filedes, (pc+0)=argp (!ݤ_TRAP21:r7%=r7%+0:=0: [33] (8ݤ_TRAP22:r7%=r7%+0:=0: nice - entry: r0=priority ): )Eݤ_TRAP23: ftime - entry: (pc+0)=bufptr, read millisecond count )"addr%=mem%!r7%&FFFF:r7%=r7%+2 )"7!zp%=:mem%!addr%=zp%!4 100 : seconds b16-b31 ),9mem%!(addr%+2)=!zp% 100 : seconds b0-b15 )6Nmem%!(addr%+4)=(mem%!(addr%+4)&FFFF0000) ((!zp%100)*10): milliseconds )@=0 )J: )Tݤ_TRAP24: sync )^A%=&FF:=_EMT8 )h: )r?ݤ_TRAP25:r7%=r7%+2:=0: kill - entry: r0=pid, (pc+0)=sig )|Fݤ_TRAP26:r%(0)=&FFFF:=0: switch - exit: r0=front panel switches )!ݤ_TRAP27:r7%=r7%+0:=0: [39] )@ݤ_TRAP28:r7%=r7%+0:=0: tell - exit: r0:r1=ptr/size/etc. )Eݤ_TRAP29:r7%=r7%+0:=0: dup2 - entry: r0=filedes1, r1=filedes2 )> exit: r0=new filedes )Nݤ_TRAP2A:r7%=r7%+0:=0: pipe - exit: r0=read filedes, r1=write filedes ):ݤ_TRAP2B:r7%=r7%+2:=0: times - entry: (pc+0)=buffer )eݤ_TRAP2C:r7%=r7%+8:=0: profil - entry: (pc+0)=buff, (pc+2)=bufsize, (pc+4)=offset, (pc+6)=scale ),ݤ_TRAP2D:r7%=r7%+0:=0: tui - [null] )3ݤ_TRAP2E:r7%=r7%+0:=0: setgid - entry: r0=gid )Jݤ_TRAP2F:r7%=r7%+0:=0: getgid - exit: r0=real gid, r1=effective gid ): )7ݤ_TRAP30: signal - entry: (pc+0)=sig, (pc+2)=func ). exit: r0=old func *|(mem%!r7%&FFFF)=2:A%=mem%!(r7%+2)&FFFF: A%: mem%!(A%+4)=&FF95F7:escflg%=A%+10+mem%!(A%+8)&FFFF:!escb%=mem%+escflg% *r7%=r7%+4:=0 *: *&!ݤ_TRAP31:r7%=r7%+0:=0: [49] *0!ݤ_TRAP32:r7%=r7%+0:=0: [50] *:8ݤ_TRAP33:r7%=r7%+2:=0: acct - entry: (pc+0)=file *DWݤ_TRAP34:r7%=r7%+6:=0: phys - entry: (pc+0)=segreg, (pc+2)=size, (pc+4)=physadr *N8ݤ_TRAP35:r7%=r7%+2:=0: lock - entry: (pc+0)=flag *XXݤ_TRAP36:r7%=r7%+6:=0: ioctl - entry: (pc+0)=filedes, (pc+2)=request, (pc+4)=argp *b!ݤ_TRAP37:r7%=r7%+0:=0: [55] *lWݤ_TRAP38:r7%=r7%+8:=0: mpxchan- entry: (pc+0)=??, (pc+2)=??, (pc+4)=??, (pc+6)=?? *v!ݤ_TRAP39:r7%=r7%+0:=0: [57] *!ݤ_TRAP3A:r7%=r7%+0:=0: [58] *: *Hݤ_TRAP3B: exece - entry: (pc+0)=>name, (pc+2)=>argv, (pc+4)=>envp *;name%=mem%!r7%&FFFF:mode%=mem%!(r7%+2)&FFFF:r7%=r7%+6 *^str0(mem%+(mem%!mode%&FFFF))="sh":cmd(str0(mem%+(mem%!(mode%+4)&FFFF)),):r%(0)=0:=0 *=0 *: *=ݤ_TRAP3C:r7%=r7%+2:=0: umask - entry: (pc+0)=complmode *<ݤ_TRAP3D:r7%=r7%+2:=0: chroot - entry: (pc+0)=>dirname *!ݤ_TRAP3E:r7%=r7%+0:=0: [62] *!ݤ_TRAP3F:r7%=r7%+0:=0: [63] *ݤ_TRAP(A%):=0 *: +1ݤstr0(A%):A$="": ?A%>31:A$=A$+?A%:A%=A%+1 + ?A%<32 A$>254:=A$ +Aݤstr(A%): B$,B%::B%=!A%&FFFF:B%:B$=B$+" "+str0(mem%+B%) + A%=A%+2:B%=0:=B$ +*: +4 > RT11RSX +>% RT11 and RSX EMT function calls +H v0.01 Initial version +R: +\]ݤ_EMTE0:r%(0)=(0):psw%=(psw%-2)(r%(0)=-1):=0 : &o340 CONIN R0=char, Cy=buffer empty +f_ݤ_EMTE1: A%:psw%=psw%-2:=0 : &o341 CONOUT R0=char, Cy=buffer full +p#ݤ_EMTE2:=0: Get device status +z%ݤ_EMTE3:=0: Load device handler +4ݤ_EMTE4:=0: Command String Interpreter general +Tݤ_EMTE5:=0: Command String Interpreter special GETLIN? Input line of text o345 +"ݤ_EMTE6:=0: Lock USR in core +$ݤ_EMTE7:=0: Unlock USR in core +$ݤ_EMTE8:halt%=:=0: &o350 EXIT +5ݤ_EMTE9: &o351 PRINT Output ASCIZ string at R0 +-:A%=mem%?r%(0):r%(0)=r%(0)+1:A%127:A% +(A%127)=0:A%=0: +psw%=psw%-2:=0 +*ݤ_EMTEA:=0: &o352 Reset all channels +2ݤ_EMTEB:=0: &o353 Increase size of I/O queue +bݤ_EMTEC: &o354 SETTOP Set top of user memory, In: R0=requested MEMTOP, Out: R0=actual MEMTOP +! r%(0)>memtop%:r%(0)=memtop% ,psw%=psw%-2:=0 ,(ݤ_EMTED:=0: Enable terminal output ,ݤ_EMTEE:=0: Unused ,$2ݤ_EMTEF:=0: Terminate I/O and reset channels ,.ݤ_EMTF0:=0 ,8ݤ_EMTF1:=0 ,Bݤ_EMTF2:=0 ,Lݤ_EMTF3:=0 ,Vݤ_EMTF4:=0 ,`ݤ_EMTF5:=0 ,jݤ_EMTF6:=0 ,tݤ_EMTF7:=0 ,~ݤ_EMTF8:=0 ,ݤ_EMTF9:=0 ,ݤ_EMTFA:=0 ,-ݤ_EMTFB:=0: Call address in Kernal mode ,%ݤ_EMTFC:=0: R0=function:channel ,$ݤ_EMTFD:=0: R0=>argument block ,ݤ_EMTFE:=0 ,!ݤ_EMTFF:=0: RSX system call ,: ,0 > DisPDP 1.02 - PDP11 disassembly routines ,: ,$ݤDis_Name(A%):X%?3=&94:="PDP11" ,5ݤDis_Code(A%,Ptr%,Data%): s%,d%,c%:!X%=0:num%=2 -:c%=!Data%:s%=(c%&FC0)64:d%=c%63:c%=(c%&F000)&1000 - $(X%+4)=pdp:X%?3=num%:=num% -: - ݤpdp -(o(c%7)=0:s%>39:s%<52:="CLRCOMINCDECNEGADCSBCTSTRORROLASRASL",3*(s%-40)+1,3)+" B",c%8+1,1)+" "+mr(d%) -2o((c%-1)7)<5:="MOVCMPBITBICBIS",(c%7)*3-2,3)+" B",c%8+1,1)+" "+mr(s%)+","+mr(d%) =("FNpdp_"+~c%) -<: -F(ݤpdp_F:="FLOP "+mr(s%)+","+mr(d%) -P: -Z(ݤpdp_E:="SUB "+mr(s%)+","+mr(d%) -d: -nKݤpdp_8:s%<32:="BPLBMIBHIBLSBVCBVSBCCBCS",3*((s%4))+1,3)+jr(?Data%) -x9s%<40:="EMT TRAP",(s%&FC)-31,4)+" &"+h0(?Data%,2) -=(s%&FC)=52:="MTPSMFPDMTPDMFPS",4*s%-207,4)+" "+mr(d%) -$X%?2=128:="EQUW &"+h0(!Data%,4) -: - ݤpdp_7 -Ds%<32:="MUL DIV ASH ASHC",4*(s%8)+1,4)+" "+mr(d%)+","+r(s%) -&s%<40:="XOR "+r(s%)+","+mr(d%) -?s%=40:d%<32:="FADDFSUBFMULFDIV",4*(d%8)+1,4)+" "+r(d%) -;(s%56)=56:="SOB "+r(s%)+","+jr(d%-192*(d%>31)),3) -$X%?2=128:="EQUW &"+h0(!Data%,4) -: -(ݤpdp_6:="ADD "+mr(s%)+","+mr(d%) -: -[ݤpdp_0:s%<32:s%>3:X%?2=(s%<8)64:="BR BNEBEQBGEBLTBGTBLE",3*(s%4)-2,3)+jr(?Data%) .\s%=0:d%<7:="HALTWAITRTIBPTIOTRESETRTT",d%*4+1+(d%>2)+(d%>3)+(d%=5),4+(d%>1)-2*(d%>4)) ."s%=1:X%?2=64:="JMP "+mr(d%) .'s%=2:d%<8:X%?2=64:="RTS "+r(d%) ."&s%=2:(d%56)=24:="SPL "+(d%7) .,,s%=2:(d%48)=32:="CCC &"+h0(d%&F,2) .6,s%=2:(d%48)=48:="SCC &"+h0(d%&F,2) .@s%=3:="SWAB "+mr(d%) .J-(s%56)=32:="JSR "+r(s%7)+","+mr(d%) .Ts%=52:="MARK &"+h0(d%,2) .^9(s%&FC)=52:="MFPIMTPISXT ",4*s%-211,4)+" "+mr(d%) .h$X%?2=128:="EQUW &"+h0(!Data%,4) .r: .|9ݤr(A%):A%=A%7:A%=7:="PC" A%=6:="SP" ="R"+ A% .-ݤmr(A%): m%:m%=(A%56)8:(A%7)=7:=pc .'m%<2:="("+r(A%)+")",2-m%,2*m%+2) .:m%<6:="@",m%1)+"-",m%4)+"("+r(A%)+")"+"+",m%<4) .Dnum%=num%+2:="@",m%=7)+"&"+h0(Data%!(num%-2),4)+"("+r(A%)+")" .ݤpc .m%<2:="(PC)",2-m%,2*m%+2) .127),4) .: .! > BLib.Close 1.00 09Aug1998 /: / Close Handling / ~~~~~~~~~~~~~~ /&: /0Close_All /:"in%=in%:in%:A%=in%:in%=0:#A% /D'out%=out%:out%:A%=out%:out%=0:#A% /N /X" > BLib.String 1.00 09Aug1998 /b: /l# String Manipulation Functions /v# ============================= /: /7 FNs() - strip spaces from start and end of string /7 ------------------------------------------------- //ݤs(A$):A$,1)=" ":A$=A$,2):A$,1)<>" " /+A$,1)=" ":A$=A$,A$-1):A$,1)<>" " /=A$ /: /+ 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 0+ ------------------------------------- 0 ݤlc(A$): B$:A$="":="" 05B$=B$+(A$((A$<"_")&20)):A$=A$,2):A$="":=B$ 0 : 0*" > BLib.Number 1.01 09Aug1988 04( v1.00 09Aug1988 JGH: First version 0>1 v1.01 12Feb1992 JGH: Added Octal and Binary 0H? v1.02 15Sep2009 JGH: Octal and Binary works for &8xxxxxxx 0R: 0\ Number Output Routines 0f ~~~~~~~~~~~~~~~~~~~~~~ 0p: 0z# Hexadecimal padded with zeros 0$ݤh0(A%,N%):="0000000"+~A%,N%) 0: 0$ Hexadecimal padded with spaces 0#ݤh(A%,N%):=" "+~A%,N%) 0: 0 Decimal padded with zeros 0$ݤd0(A%,N%):="00000000"+A%,N%) 0: 0 Decimal padded with spaces 0$ݤd(A%,N%):=" "+A%,N%) 0: 0 Octal padded with zeros 05ݤo0(A%,N%): A$,B%,L%:A%<0:B%=2:A%=A%&7FFFFFFF 1;A$=(A%7)+A$:A%=A%8:L%=L%+3:L%>27:=(A%+B%)+A$,N%) 1: 1 Octal padded with spaces 1$%ݤo(A%,N%): A$:A%<0:=o0(A%,N%) 1.2A$=(A%7)+A$:A%=A%8:A%=0:=N%," ")+A$,N%) 18: 1B Binary padded with zeros 1L>ݤb0(A%,N%): A$,B$,L%:B$="0":A%<0:B$="1":A%=A%&7FFFFFFF 1V5A$=(A%1)+A$:A%=A%2:L%=L%+1:L%>30:=B$+A$,N%) 1`: 1j Binary padded with spaces 1t%ݤb(A%,N%): A$:A%<0:=b0(A%,N%) 1~2A$=(A%1)+A$:A%=A%2:A%=0:=N%," ")+A$,N%) 1: 1) Drive character for supplied number 1 ݤdrv(A%):=(48+A%-7*(A%>9)) 1: 1) Drive number for supplied character 1#ݤDrv(A$):=A$-48+7*(A$>"9")31 1: 1# > BLib.ProgEnv 1.06 20Apr2020 1: 1# Program Environment Functions 1# ============================= 1: 2? Return command line tail, sets run$ to execution filename 2 Z Works on BBCIO,BBC09,T6502,T6809,TZ80,ZX80,PDP11,ARMEval,ARMCoPro,RISCOS,DOS,Windows 2Z ------------------------------------------------------------------------------------ 2:ݤOS_GetEnv:A$,A%,X%,Y%:X%=1:os%=((&FFF4)&FF00)256 2(Mos%>31:>&FFFFF:X%256:ș"GetModuleFileName",0,X%,255:run$=$$X%:=@cmd$ 22CA%=&600-&7B00*(>&8000)-&3F00*(>&C000):!(-&100)=@%:A%=-&300 2<;?(P-3)=0:A%=&100:<&FFFF:A%=-&300:!(+512)=@%:A%= 2FcA$=$A%:=&8F00:run$=A$:ș16A$,,A%:ș72,"",A%:A$=A$,1+A$+" "," ",1+A$," "))):A$=0:A$=run$ 2PUY%=-10:A$=" "+A$:A$=A$,2):A$<>32:A$=34:A%=A$,"""",2)+1 A%=A$+" "," ") 2Z9Y%:run$=A$,1-(A$=34),A%-1+2*(A$=34)):A$=A$,A%+1) 2d :=A$ 2n: 2x. Run a program, passing it a command line 2= If program is *Command, called with OSCLI, else CHAINed 2= ------------------------------------------------------- 2#os(A$):A$=42:A$ A$:A$ 2 2: 2( Exit program, setting return value 2( ---------------------------------- 2Fexit(A%):"FX1,"+(A%255):quit$=quit$:A$=quit$:quit$="":os(A$) 2>&FFFFF:Ș A% 2 2: 2* > BLib.Generic.FileIO 1.05 22Mar2008 20 v1.05 22Mar2009 Optimised CDIR in FNfile() 3, v1.04 22Mar2008 FNf_scan strips spaces 37 v1.03 15Feb2008 Add veneer functions in f_ domain 3K v1.02 28Apr2007 Added functions to FNfile on DOS, PROCcdir, FNopenout 3"7 v1.01 07Sep2006 FNargs avoid zero page on RISC OS 3,% v1.00 09Aug1988 Initial version 36: 3@% General File Interface Routines 3J% =============================== 3T: 3^8 FNfile(), PROCgbpb(), FNfs are callable on Windows 3h8 -------------------------------------------------- 3r: 3|, Returns file type, file info in X%!... 3, -------------------------------------- 3Rݤfile(A$,A%):A%-8:<&FFFFF:$name%=A$:?X%=name%:X%?1=name%256:=(&FFDD)&FF 3TA$=f_name(A$):A%=255 A%=5:X%!14=(A$):X%!14:X%!10=#X%!14:#X%!14:X%!14=&33 31A%=255:X%?6=0:"LOAD """+A$+""" "+~X%!2:=1 3A%=5:X%!14:=1 A%=5:=0 3FA%=0:"SAVE """+A$+""" "+~X%!10+" "+~X%!14:X%!10=X%!14-X%!10:=1 3BA%=7:"SAVE """+A$+""" "+~+"+"+~X%!10:X%!10=X%!14-X%!10:=1 3 A%-8:=0 3-(os%-24):A$="mkdir "+A$ A$="cdir "+A$ 3>&FFFF: : :=0 3 A$:=2 3: 3 General OSGBPB call 4 ------------------- 4%f_gbpb(A%,chn%,addr%,num%,ptr%) 4>?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:<&FFFFF:&FFD1: 4&A%=1A%=3:#?X%=X%!9 405:A%=1A%=2:#?X%,?X%!1 A%=3A%=4:?X%!1=#?X% 4:5X%!1=X%!1+1:X%!5=X%!5-1:(#?X% A%>2) X%!5<1: 4D: 4N#gbpb(A%,chn%,addr%,num%,ptr%) 4X>?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:<&FFFFF:&FFD1: 4bA%=1A%=3:#?X%=X%!9 4l5:A%=1A%=2:#?X%,?X%!1 A%=3A%=4:?X%!1=#?X% 4v5X%!1=X%!1+1:X%!5=X%!5-1:(#?X% A%>2) X%!5<1: 4: 4@ Return current disk (5), directory (6) or library (7) name 4@ ---------------------------------------------------------- 4ݤgbpb(A%):>&FFFFF:="" 4NX%!1=name%:&FFD1:A%=name%+((1+?name%)((A%-2)=6)):A%?(1+?A%)=13:=$(A%+1) 4: 4B Returns entry in current directory, or null string if at end 4B ------------------------------------------------------------ 4 ݤf_scan(ptr%):>&FFFFF:="" 47X%!1=name%:X%!5=1:X%!9=ptr%:A%=8:&FFD1:X%!5=1:="" 47A%=name%+1:A%!(A%?-1)=&D20:A%?($A%," ")-1)=13:=$A% 4: 4ݤgbpb8(ptr%):>&FFFFF:="" 57X%!1=name%:X%!5=1:X%!9=ptr%:A%=8:&FFD1:X%!5=1:="" 5 7A%=name%+1:A%!(A%?-1)=&D20:A%?($A%," ")-1)=13:=$A% 5: 5 7 OSARGS call with data. Returns any returned data 5*7 ------------------------------------------------- 546ݤf_args(A%,Y%,ptr%): X%,E%:?(P-3)=0:E%=Y%:Y%=0 5> 5H& !&70:X%=&70:!X%=ptr%:&FFDA:=!X% 5R 5\#ș"OS_Args",A%,Y%,ptr% ,,ptr% 5f :=ptr% 5p: 5z4ݤargs(A%,Y%,ptr%): X%,E%:?(P-3)=0:E%=Y%:Y%=0 5 5& !&70:X%=&70:!X%=ptr%:&FFDA:=!X% 5 5#ș"OS_Args",A%,Y%,ptr% ,,ptr% 5 :=ptr% 5: 5' OSARGS call ignoring X, returns A 5' --------------------------------- 5ݤf_argsA(A%): 5( X%,Y%,E%,!&70:X%=&70:=(&FFDA)&FF 5 5ș"OS_Args",A% A% 5 :=A% 6: 6ݤargsA(A%): 6( X%,Y%,E%,!&70:X%=&70:=(&FFDA)&FF 6$ 6.ș"OS_Args",A% A% 68 :=A% 6B: 6L& Get current filing system number 6V& -------------------------------- 6`.ݤfs:(os%-32)=0: A%,Y%,E%:=(&FFDA)&FF 6j=29 6t: 6~ Delete an object 6 ---------------- 6