# > HDInit/src 1.16 J.G.Harston  Initialise IDE hard drive $ v1.02 - Drives 0-7 all allowed (; v1.03 - Drive reversably initialised, selects drive 0 24 v1.04 - Allows drive size to be set explicitly <. v1.05 - Displays sizes in M as well as K F2 v1.06 - Wipes full root if 'safe' turned off P& v1.07 - Full drive investigation Z v1.08 - Partitions d v1.09 - New FNsum routine n9 v1.10 - Displays full firmware info and device type x* v1.11 - Allows ADFS/HADFS partitions ? v1.12 - Display full info by default, Randomise made safe E v1.13 - Attempts to use SCSI call before direct hardware access ! v1.14 - 4G HADFS partitions , v1.15 - ADFS partition size selectable 7 v1.16 - Detects ADFS device hardware and revision : K&87:fx(0,1)<6:fx(130,0)=&FFFF "Must run on BBC I/O processor": fs%=fs:ver$="1.16" adfs%=: adfs%= adfs%:fs<>8:*FADFS hadfs%=: hadfs%= hadfs%:fs<>16:*HADFS ,fs%<>8:fs%<>16:fs%=8: IFhadfs%:fs%=16 ok%=: ok%= )ok%:"FX143,18,"+fs%:fs%=8:MOUNT 0 fs%=fs:hd%=(fs%-8)/2:init " err:end: ,&87:menu:end: 6: @ end:: J: Tݤerr:::A%=(100):=-1 ^: h init r1 ctrl%31,mem%511,info%512:X%=ctrl%:Y%=X%256 |'safe%=:full%=:asm:info:*FX219,9  :  info Ebig%=0:hdsz%=0:rv%=0:A%=05114:info%!A%=0::dev$="IDE":hd%>3: "FADFS":Y%=?&DBC:!&F6=&BFFF:rv%=(&FFB9)255:!&F6=&8002:d4%=((&FFB9)128)/64+2:!&F6=&8008:A%=((&FFB9)6)/2:Y%=X%256:A%<>1:scsz%=256 /dev$="SCSIIDE --- MMC ",A%*4+1,4+(A%>0)): :  ݤmenu EA$=" BBC "+dev$+"r"+~rv%,rv%>0)+" Hard Drive Initialiser "+ver$ #:A$'ĩA$+1,"=");8:DriveInfo .'"D: Select drive I: Investigate drive" *"S: Scan for size Z: Set drive size" G"F: Format drive W: Wipe data (";"on",safe%);"off",safe%);")" 6full%:safe%:17; full%:"R: Randomise data"; !full%:" Toggle width" $'6"Press a key or X to exit:"; &\ A$=: 9+"*DdIiFfWwRrSsXxZz",A$):13;32;13;:A$="*" "*"A$: A$: A$="":A$="*" 0A$=( A$&DF) :A$="D":Drive:=0 DA$="F":Format:=0 NA$="I":Invest:=0 XA$="S":Scan:=0 bA$="W":safe%=safe%:=0 lA$="R":safe%:Random:=0 vA$="Z":SetSize:=0  A$=9:符-1:scsz%=768-scsz% A$=9:-1:full%=full%  =A$="X" : DriveInfo *hd%<4:dev%=hd%d4% dev%=hd%8:d4%=4 9" Current drive: ";~hd%;" ("dev$" device ";dev%;")"; 7 IFadfs%:IF(hd%AND6)=4:PRINT" (Floppy ";hd%-4;")"; 8 IFadfs%:IF(hd%AND6)=6:PRINT" (Unknown ";hd%-6;")"; )'" Device width: ";scsz%32;" bits" @full%:" Model: "str(info%+54,20)'11;str(info%+74,20) )full%:" Firmware: "str(info%+46,8) *full%:" Serial: "str(info%+20,20) A'" Total sectors: &";h0(hdsz%,8)" (";(hdsz%/204.8)/10;"M)"  Q" Physical size: C:&";h0(info%!&02,4);" H:";d(info%?&06,2);" S:";info%?&0C Q" Logical size: C:&";h0(info%!&6C,4);" H:";d(info%?&6E,2);" S:";info%?&70  B" 8-bit Size: ";d(hdsz%4,8);"K (";(hdsz%/409.6)/10;"M)" *Lhd%<4:Info(hd%,16-d4%,&200000,"ADFS") Info(hd%,12,&1000000,"HADFS") 434+dev$,"="): >: H"Info(d%,m%,sz%,fs$):d%=d%m% R%" ";fs$;" drives:";:hsz%=hdsz%: \A%=sz%:hsz%"`":A$=(A$-32) ,"0123456789AB",A$):hd%=("&"+A$):info  :  Invest "A%=05114:mem%!A%=0::big%= dev$="SCSI":hd%<4:A%=scsi(&1A,mem%,22,0,hd%):info%?2=mem%?14:info%!3=mem%?13:info%?6=mem%?15:info%?12=33:info%!&6C=info%!2:info%!&6E=info%?6:info%!&70=info%?12:hdsz%=info%!2*info%?6*info%?12:"MOUNT": >dev$="IDE":!addr%=mem%:A%=dev%*16:nm%?1=scsz%256-1: id% AA%=0255:info%?(A%*2)=mem%?A%:info%?(A%*2+1)=mem%?(A%+256): info%?3+info%?109+info%?115=0:info%?109=info%?116:info%?115=info%?108:A%=(256*info%?109+info%?108)*info%?110*info%?112:info%?3=(A%((info%?6)*(info%?12)))256 7info%?&74=0:big%=:info%?&74=info%?&72:info%?&72=0 $info%?&79=0:info%?&79=info%?&6C $Ihdsz%=info%!&78: hdsz%=(256*info%?&6D+info%?&6C)*info%?&6E*info%?&70 . 8: B Scan L*"Scanning drive ";hd%:sec%=&800:info V4 sec%=sec%+sec%: scan(sec%)<>0 sec%>&1FFFFF `step%=sec%2:dir%=-1: j'sec%=sec%+step%*dir%:A%=scan(sec%) t(step%=step%2:A%=0:dir%=1 dir%=-1 ~ step%<1:hdsz%=sec%-1:  : 2ݤscan(sec%):13;"Drive size: ";sec%4;"K "; .adfs%:=scsi(&08,mem%,1,sec%-1,hd%) =-1 :  SetSize F"Enter drive size, use , &, K or M :"A$ "info:big%=0:hdsz%=rdsz(A$): : Format:hdsz%<1:Invest 1size%=hdsz%:max%=&200000:hd%>3:max%=&1000000 ? d4%=2:A%=hd%=1 hd%=3 A%=hd%=1 hd%=2 hd%=3 hd%>5 < A%:A%=hd%:size%=size%-max%:A%=A%-1:(A%3)=0 A%=d4%  size%>max%:size%=max% 7size%<0:"No space for drive ";~hd%;:delay(200): /size%<&1000:"This appears to be a floppy" (B"Format ";"H",hd%>3);"ADFS drive ";~hd%;" to ";sz(size%);8 2QA$="":(hd%(7-d4%))=0:"Leave space for ";"H",hd%<4);"ADFS system? ";:""A$ hdsz%:part%=hdsz% FQpart%:hd%>3:"ADFS space (";sz(part%);"): ";:""A$:A$<>"":part%=rdsz(A$) PR"Format? Enter YES to confirm: "A$:A$<>"YES":"Not formatted";:delay(200): Zhd%<4:InitADFS d(hd%>3:InitHADFS:part%:hdsz%=part% n x: InitHADFS )!X%=1:A%=14:&FFF1: Get today's date 7A%=06:X%?A%=(X%?A%15)+10*(X%?A%16):: BCD->BIN 6?X%<81:?X%=19+?X% ?X%=?X%-81: Offset from 1981 1today%=(?X%16)+8*X%?2+256*X%?1+4096*(?X%15) Tstart%=2:part%:start%=7:size%>&FFFF:start%=part%: Start free space after ADFS -dskID%=(65535):size%=&10000:size%=&FFFF : /clear : Clear sector 1safe%:read(&46,hd%) : Read sector &46 1$mem%="IDEDISK"+~hd%+" ": Disk title .$(mem%+16)=0+"(C)JGH"+0: Disk ID string 4mem%!24=dskID% : Disk ID number 6mem%!26=today% : Disk format date 9mem%!28=size% : Disk size and flags 9size%<&10000:mem%?30=&11:msz%=2 mem%?31=&80:msz%=3 "Lmem%!(32+0*msz%)=&02:mem%!(32+1*msz%)=&44 : Empty free space map ,3mem%!(32+2*msz%)=&4A:mem%!(32+3*msz%)=size%-&4A 6+mem%!(32+4*msz%)=&00:mem%!(32+5*msz%)=0 @opart%:mem%?31=mem%?31&41:mem%!32=start%:mem%!(32+msz%)=size%-start%:mem%!(32+2*msz%)=0:mem%!(32+3*msz%)=0 J3write(&46,hd%) : Write sector &46 T: ^/clear : Clear sector h1safe%:read(&47,hd%) : Read sector &47 r4$mem%="$ " : Directory name |6mem%!10=&47:mem%!14=0 : Parent directory 4mem%!16=dskID%:mem%!20=0 : Disk ID number Esize%>&FFFF:mem%!10=0:mem%!24=0:mem%!28=&47:mem%?12=&80: BigDir 3write(&47,hd%) : Write sector &47 : /clear : Clear sector 0safe%:write(&48,hd%) : Write sector &48 0safe%:write(&49,hd%) : Write sector &49 : <"Drive ";~hd%;" initialised to ";sz(size%):delay(200)  : InitADFS *clear : Clear sector :mem%!0=7 : Start of first free space :part%:mem%!3=&4A : Start of second free space @mem%!252=size% : Total number of sectors on disk &,mem%?255=0:mem%?255=sum : FSM checksum 0,write(0,hd%) : Write sector 0 :: D*clear : Clear sector NEmem%!0=size%-7 : Length of first free space XEpart%:mem%!0=&3F:mem%!3=size%-&4A : Length of second free space b&mem%!251=(65535) : Disk ID l1mem%?253=0 : Disk boot option v6mem%?254=3-3*(part%<>0) : End of free space map ,mem%?255=1:mem%?255=sum : FSM checksum ,write(1,hd%) : Write sector 1 : 8S%=26:clear : Clear sector Esafe%:read(S%,hd%):clrdir(S%*4-3): Read sector, clear entries BS%=2:$mem%=0+"Hugo":mem%?5=0 : Directory identifier AS%=6:$(mem%+204)="$":mem%!214=2 : Dir name, parent @S%=6:$(mem%+217)="$":$(mem%+227)="" : Directory title BS%=6:$(mem%+250)=0+"Hugo":mem%?255=0 : Directory identifier 8write(S%,hd%): : Write sector : /"Drive ";hd%;" initialised to ";sz(size%) F"**WARNING** You *MUST* reset ADFS to"'"prevent disk corruption." delay(200):  : %clear:A%=02554:mem%!A%=0::  ,clrdir(O%):A%=O%25526:mem%?A%=0:: *: 4ݤsum:sum%:sum%=255 >GA%=2540-1:sum%=(sum%+sum%256)255:sum%=sum%+mem%?A%::=sum%255 H: R Random \+"Randomise contents of drive ";hd%;"?" fK"Enter YES to confirm: "A$:A$<>"YES":"Not randomised";:delay(200): p("Press ESCAPE to terminate "; z sec%=0:6,8);h0(sec%,6); /A%=0255:mem%?A%=(255)::write(sec%,hd%) sec%=sec%+1:0: : Hwrite(sec%,drv%):cmd%=wr%:drv%<4:scsi(&0A,mem%,1,sec%,drv%)=0: Gread(sec%,drv%):cmd%=rd%:drv%<4:scsi(&08,mem%,1,sec%,drv%)=0: j!addr%=mem%:!sc%=sec%:A%=sc%?2:sc%?2=sc%?0:sc%?0=A%:?dv%=(d4%*32)128:?nm%=1:nm%?1=0:drv%>3:?dv%=drv% A%=cmd%: : "delay(T%):T%=+T%: >T%: : :ݤscsi(cmd%,addr%,num%,sect%,drv%):sect%>&1EFFFF:=&21 fs%:fs%=fs:fs%<>8:*FADFS DX%?0=0:X%!1=addr%:X%?5=cmd%:X%?6=drv%*32+((sect%&1F0000)65536) 9X%?7=((sect%&FF00)256):X%?8=sect%:X%!9=num%:X%!11=0 2A%=114:&FFF1:A%=?X%:fs%<>8:"FX143,18,"+fs% =A% $: .!ݤfs: A%,Y%,E%:=(&FFDA)&FF 86ݤfx(A%,X%): Y%:Y%=X%256:=((&FFF4)&FFFF00)256 B: L#ݤh0(A%,N%)="0000000"+~A%,N%) V"ݤd(A%,N%)=" "+A%,N%) `ݤstr(A%,N%): A$: j$A%?1>31:A$=A$+A%?1 A$=A$+"." t"?A%>31:A$=A$+?A% A$=A$+"." ~A%=A%+2:N%=N%-2:N%<1:=A$ +ݤsz(A%):=(A%4)+"K ("+(A%4096)+"M)" ݤrdsz(A$):A$,1)="&":=A$ #A$,1)="K" A$,1)="k":=A$*4 &A$,1)="M" A$,1)="m":=A$*4096 =A$256 : asm:mc%=mc%:mc%: >mc%409:addr%=&80:dv%=&84:sc%=&85:nm%=&88:cmd%=&8A:tmp=&8B ?IDEdata=&FC40:IDEerror=&FC41:IDEcount=&FC42:IDEsector=&FC43 DIDEcylinder=&FC44:IDEhead=&FC46:IDEstatus=&FC47:IDEcommand=&FC47 ,scsz%=256:!IDEdata<>IDEdata!8:scsz%=512  &80/&81 = addr  &82/&83 = addr.hi  &84 = drv (0,4-B,&80) ! &85 = drv-sect.hi (0-3)  &86 = sect.mid ( &87 = sect.lo 2 &88 = num < &89 = data width F &8A = cmd P &8B = tmp Z &8E/F =>control block dP=01:P%=mc%:[OPT P*2 n>.id%:TAY:.idlp:LDA &FF:BMI idescape:LDA IDEstatus:BMI idlp xATYA: #16:STA IDEhead:LDA #&EC:STA IDEcommand :\ &EC=Identify block 4LDA #&7F:STA &8E:LDA #0:STA &8F :\ &8E/F=>block PHP:JSR SetGeometry:PLP .CommandLoop CLDX #2:.Twice:JSR SetSector:LDY #0:\ Set sector, count, command .TransferLoop )JSR WaitForData: #&21:BNE TransError "BCC IORead , .IOWrite 64LDA (&80),Y:STA &FC40:LDA nm%+1:BEQ TransferByte @:INC &81:LDA (&80),Y:STA &FC48:DEC &81:JMP TransferByte J .IORead T4LDA &FC40:STA (&80),Y:LDA nm%+1:BEQ TransferByte ^:INC &81:LDA &FC48:STA (&80),Y:DEC &81:JMP TransferByte h.TransferByte r6LDA &FC47: #8:BEQ TransError:INY:BNE TransferLoop |1LDA &FC47: #&21:BNE TransError:DEX:BNE Twice 9INC &87:BNE TransCount:INC &86:BNE TransCount:INC &85 .TransCount *DEC &88:BNE CommandLoop:LDA #0:TAX:RTS .TransError LDA &FC47:LDX &FC41:RTS .SetGeometry FJSR WaitNotBusy:LDA #64:STA &FC42:STA &FC43:\ 64 sectors per track 8LDA dv%:BMI SetGeo8:BNE SetGeo16:LDA sc%:LSR A:LSR A ;.SetGeo8:A #3: #&13:BNE SetGeo:\ 4 heads per cylinder K.SetGeo16:ASL A:ASL A:ASL A:ASL A:A #15: #&1F:\ 16 heads per cylinder ,.SetGeo:STA &FC46:LDA #&91:STA &FC47:RTS : .SetSector DPHP:JSR WaitNotBusy :\ Save CC/CS Read/Write ALDAdv%:BMI SetSector8:BNE SetSector16 :\ Set 16-head sector ?LDAsc%+0:PHA: #&3F:STA &FC45 :\ Set sector b16-b20 &&20 or CC->&30 ESTA &FC47:PLP:RTS :\ Set command &08 or &0A .SetSector8 ALDAsc%+0:STA &FC45 :\ Set sector b16-b20 "LDAsc%+2: #&C0:JMP SetSectorX .SetSector16 -LDAsc%+2:ROL A:ROL A:ROL A: #&03:STA tmp .LDAsc%+1:ASL A:ASL A: #&0C:A tmp:STA tmp JLDAdv%:LSR A:LDA tmp:BCC P%+4:A #&10:STA &FC46 :\ Head = sector b6-b9 LDAsc%+1:LSR A:LSR A:STA tmp TLDAsc%+0:ROR A:ROR A:ROR A: #&C0:A tmp:STA &FC44 :\ Cylinder.lo=sector b10-b17 LDAsc%+0:LSR A:LSR A:STA tmp ALDAdv%:ROR A:ROR A:ROR A:ROR A: #&C0: #&80:A tmp:STA &FC45 JMP SetCommand ]: