Mercurial > hg > Members > kono > nitros9-code
changeset 926:ebd5b6ce665d
Cluster size added by John Collyer
Untested format sector summary should now put out 24 bits
author | boisy |
---|---|
date | Mon, 20 Jan 2003 03:19:21 +0000 |
parents | 93c871621a22 |
children | 207aaa792076 |
files | level1/cmds/format.asm |
diffstat | 1 files changed, 905 insertions(+), 700 deletions(-) [+] |
line wrap: on
line diff
--- a/level1/cmds/format.asm Sun Jan 19 18:54:43 2003 +0000 +++ b/level1/cmds/format.asm Mon Jan 20 03:19:21 2003 +0000 @@ -6,6 +6,15 @@ * Ed. Comments Who YY/MM/DD * ------------------------------------------------------------------ * 22 From Tandy OS-9 Level Two Vr. 2.00.01 +* +* 23 Format incorrect/clusters summary: JC 03/01/06 +* Now, specifying cluster size works. +* +* Fixed bug where format showed an improper +* number of sectors formatted at the summary +* if the number of sectors was a large number. +* This was most notable when formatting large +* disks, such as hard drives. nam Format ttl Disk format program @@ -17,47 +26,51 @@ use rbfdefs endc +DOHELP set 0 + tylg set Prgrm+Objct atrv set ReEnt+rev rev set $01 -edition set $16 +edition set 23 mod eom,name,tylg,atrv,start,size - org 0 -savedu rmb 2 -diskpath rmb 1 -currtrak rmb 2 +******************************************************************** +* begin our data area, starts on direct page +******************************************************************** + +savedu rmb 2 save the u register +diskpath rmb 1 disk path number +currtrak rmb 2 current track on u0005 rmb 2 -currsect rmb 1 -u0008 rmb 1 +currsect rmb 1 current sector on +u0008 rmb 1 counted sectors u0009 rmb 1 u000A rmb 2 u000C rmb 2 u000E rmb 2 -mfm rmb 1 +mfm rmb 1 denisity (double/single) u0011 rmb 1 T4896 rmb 1 u0013 rmb 1 u0014 rmb 1 -ncyls rmb 2 +ncyls rmb 2 total number of cylinders u0017 rmb 1 u0018 rmb 1 -sectors rmb 1 -u001A rmb 1 -sectors0 rmb 1 +sectors rmb 1 total number of sectors +u001A rmb 1 total number of sectors +sectors0 rmb 1 total number of sectors u001C rmb 1 -dtype rmb 1 -u001E rmb 1 -u001F rmb 1 -u0020 rmb 1 -interlv rmb 1 +dtype rmb 1 disk device type (5", 8", hard disk) +ready rmb 1 ready to proceed, skip warning +dresult rmb 2 decimal number in binary +interlv rmb 1 sector interleave value u0022 rmb 2 u0024 rmb 1 u0025 rmb 1 u0026 rmb 1 -u0027 rmb 1 -u0028 rmb 1 +clustsiz rmb 1 cluster size +ClustSz rmb 1 cluster size u0029 rmb 1 u002A rmb 1 u002B rmb 1 @@ -71,7 +84,7 @@ u0033 rmb 1 u0034 rmb 1 u0035 rmb 1 -u0036 rmb 2 +oksects rmb 3 u0038 rmb 2 u003A rmb 2 u003C rmb 1 @@ -80,24 +93,24 @@ u0041 rmb 2 u0043 rmb 1 u0044 rmb 1 -u0045 rmb 1 +dovfy rmb 1 dtentry rmb 2 u0048 rmb 1 stoff rmb 2 u004B rmb 1 u004C rmb 1 u004D rmb 1 -u004E rmb 1 +u004E rmb 1 logical format u004F rmb 1 u0050 rmb 5 u0055 rmb 15 u0064 rmb 7 u006B rmb 4 -u006F rmb 32 +dskname rmb 32 quoted delimited disk name buffer u008F rmb 40 -u00B7 rmb 14 +u00B7 rmb 14 buffer u00C5 rmb 12 -timepkt rmb 5 +timepkt rmb 5 DD.DAT creation date u00D6 rmb 18 u00E8 rmb 14 u00F6 rmb 177 @@ -105,194 +118,149 @@ u01A9 rmb 2 u01AB rmb 12 optbuf rmb 256 -u02B7 rmb 3 -u02BA rmb 9924 +fdtbuf1 rmb 3 +fdtbuf2 rmb 9924 u297E rmb 451 size equ . name fcs /Format/ fcb edition -L0014 fdb $0000 -L0016 fdb $0000 -L0018 fdb $0000 -L001A fdb $80E5 - fdb $80E5 - fdb $0000 -L0020 fdb $0100 - fdb $28FF - fdb $0600 - fdb $01FC - fdb $0CFF - fdb $0000 - fdb $0600 - fdb $01FE - fdb $0400 - fdb $01F7 - fdb $0AFF - fdb $0600 - fdb $01FB - fdb $80E5 - fdb $80E5 - fdb $01F7 - fdb $0AFF - fdb $0000 - fcb $Ff - fdb $0043 - fdb $0128 -L0049 fdb $504E - fdb $0C00 - fdb $03F6 - fdb $01Fc - fdb $204E - fdb $0000 - fdb $0C00 - fdb $03F5 - fdb $01FE - fdb $0400 - fdb $01F7 - fdb $164E - fdb $0C00 - fdb $03F5 - fdb $01FB - fdb $80E5 - fdb $80E5 - fdb $01F7 - fdb $164E - fdb $0000 +val1 fdb $0000 +val2 fdb $0000 +val3 fdb $0000 +hdsdat fdb $80E5,$80E5,$0000 +sgtdat fdb $0100,$28FF,$0600,$01FC,$0CFF,$0000 +sgsdat fdb $0600,$01FE,$0400,$01F7,$0AFF,$0600 + fdb $01FB,$80E5,$80E5,$01F7,$0AFF,$0000 + fcb $FF +sgfidp fdb $0043 +sgsize fdb $0128 +dbtdat fdb $504E,$0C00,$03F6,$01FC,$204E,$0000 +dbsdat fdb $0C00,$03F5,$01FE,$0400,$01F7,$164E + fdb $0C00,$03F5,$01FB,$80E5,$80E5,$01F7 + fdb $164E,$0000 fcb $4E - fcb $00 - fcb $90 - fcb $01 - fcb $52 R -L0076 fcb $20 - fcb $4E N - fcb $00 - fcb $00 - fcb $0C - fcb $00 - fcb $03 - fcb $F5 u - fcb $01 - fcb $FE - fcb $04 - fcb $00 - fcb $01 - fcb $F7 w - fcb $16 - fcb $4E N - fcb $0C - fcb $00 - fcb $03 - fcb $F5 u - fcb $01 - fcb $FB - fcb $80 - fcb $E5 e - fcb $80 - fcb $E5 e - fcb $01 - fcb $F7 w - fcb $18 - fcb $4E N - fcb $00 - fcb $00 - fcb $4E N - fcb $00 - fcb $30 0 - fcb $01 - fcb $54 T +dbfidp fdb $0090 +dbsize fdb $0152 +dctdat fdb $204E,$0000,$0C00,$03F5,$01FE,$0400 + fdb $01F7,$164E,$0C00,$03F5,$01FB,$80E5 + fdb $80E5,$01F7,$184E,$0000 + fcb $4E +dcfidp fdb $0030 +dcsize fdb $0154 -start stu <savedu - bsr ClrWork cleark work area - bsr OpenDev get device name and open it - bsr Default - lbsr GetDTyp - lbsr Format - lbsr InitDisk +******************************************************************** +* format module execution start address +******************************************************************** + +start stu <savedu save our data pointer + bsr ClrWork clear the work area + bsr OpenDev get device name and open it + bsr Default handle all the options + lbsr GetDTyp initialize the device + lbsr Format physically format device + lbsr InitDisk initialize the device lbsr Access lbsr Stamps - lbsr L0843 - ldu <dtentry - os9 I$Detach - clrb -L00BB os9 F$Exit -ClrWork leay diskpath,u - pshs y - leay >u00B7,u -ClrOne clr ,-y - cmpy ,s - bhi ClrOne - puls pc,y + lbsr FDScipt file descriptor + ldu <dtentry device table entry + os9 I$Detach detach the device + clrb flag no error +Exit os9 F$Exit exit module + +******************************************************************** +* clear our working memory area +******************************************************************** + +ClrWork leay diskpath,u point to work area + pshs y save that + leay >u00B7,u get size of area +ClrOne clr ,-y clear it down + cmpy ,s at begin? + bhi ClrOne not yet, + puls pc,y done + +******************************************************************** +* get rbf device name and open it +******************************************************************** -OpenDev lda ,x+ get char at X - cmpa #PDELIM pathlist delimiter? - beq L00DA branch if so -L00D5 ldb #E$BPNam else set bad pathname - lbra L0961 and print error -L00DA os9 F$PrsNam parse pathname - lbcs L0961 branch if illegal (has additional pathlist element) - lda #PDELIM - cmpa ,y - beq L00D5 - sty <u0022 - leay <u004F,u -L00ED sta ,y+ - lda ,x+ - decb - bpl L00ED - leax <u0050,u - lda #C$SPAC - sta ,y - clra - os9 I$Attach - lbcs L0961 - stu <dtentry - ldu <savedu - lda #PENTIR - ldb #C$SPAC - std ,y - lda #WRITE. - leax <u004F,u - os9 I$Open - bcs L00BB - sta <diskpath +OpenDev lda ,x+ get char at X + cmpa #PDELIM pathlist delimiter? + beq PrsPrm branch if so +BadPath ldb #E$BPNam else set bad pathname + lbra PrtError and print error +PrsPrm os9 F$PrsNam parse pathname + lbcs PrtError branch if illegal (has additional pathlist element) + lda #PDELIM get pathlist name separator + cmpa ,y another pathlist separator? + beq BadPath yes, set bad pathname + sty <u0022 no, save end of pathname + leay <u004F,u point to pathname buffer +MovNam sta ,y+ save pathname character + lda ,x+ get next pathname character + decb decrement pathname size + bpl MovNam got full pathname? + leax <u0050,u get pathname for I$Attach + lda #C$SPAC space character + sta ,y delimit pathname + clra get access mode + os9 I$Attach attach the rbf device + lbcs PrtError if error print error and exit + stu <dtentry save device table entry + ldu <savedu get data pointer + lda #PENTIR delimit pathname + ldb #C$SPAC for os9 I$Open + std ,y do it now + lda #WRITE. get access mode + leax <u004F,u get pathname + os9 I$Open open the rbf device + bcs Exit exit if could not open it + sta <diskpath save path number + rts return + +******************************************************************** +* get geometry and options, proceed (Y/N) +******************************************************************** + +Default bsr Geometry + bsr DoOpts + lbsr Proceed rts -Default bsr GetOpts - bsr L0183 - lbsr L025E - rts +******************************************************************** +* get rbf device geometry +******************************************************************** -GetOpts leax >optbuf,u - clrb - os9 I$GetStt - bcs L00BB - ldb PD.SID-PD.OPT,x - stb <u0013 - stb <u0014 - ldb PD.SToff-PD.OPT,x - beq L0143 - tfr b,a - anda #$0F - sta <stoff - lsrb - lsrb - lsrb - lsrb - stb <u004B -L0143 ldb PD.DNS-PD.OPT,x - pshs b - andb #DNS.MFM - stb <mfm - stb <u0011 - ldb ,s - lsrb - pshs b - andb #$01 (PD.DTD) - stb <T4896 - puls b - lsrb +Geometry leax >optbuf,u status packet address + clrb SS.OPT function + os9 I$GetStt get status packet + bcs Exit exit if error + ldb PD.SID-PD.OPT,x number of surfaces + stb <u0013 save it + stb <u0014 save it + ldb PD.SToff-PD.OPT,x foreign disk format? + beq L0143 no, + tfr b,a yes, get copy + anda #$0F foreign low nibble + sta <stoff save it + lsrb + lsrb + lsrb + lsrb foreign high nibble + stb <u004B save it +L0143 ldb PD.DNS-PD.OPT,x density capability + pshs b save it + andb #DNS.MFM check double-density + stb <mfm save double-density (Yes/No) + stb <u0011 save it again + ldb ,s get density capability + lsrb checking + pshs b save it + andb #$01 single track density (96 tpi) or (48 tpi) + stb <T4896 save it (PD.DTD) + puls b get checking + lsrb andb <u0011 stb <u004C puls b @@ -301,42 +269,51 @@ beq L0169 stb <u004B clr <stoff -L0169 ldd PD.CYL-PD.OPT,x - std <ncyls - ldb PD.TYP-PD.OPT,x - stb <dtype - ldd PD.SCT-PD.OPT,x - std <sectors - ldd PD.T0S-PD.OPT,x - std <sectors0 - ldb PD.ILV-PD.OPT,x - stb <interlv - ldb #$01 - stb <u0027 - clrb - rts -L0183 ldx <u0022 -L0185 leay >OptTbl,pcr - bsr L019C - bcs L01A5 - pshs b,a - ldd $02,y - leay d,y - puls b,a - jsr ,y - bcc L0185 - lbra L00BB -L019C lda ,x+ -L019E cmpa ,y - bne L01A6 - ldb $01,y - clra -L01A5 rts -L01A6 leay $04,y - tst ,y - bne L019E - coma - rts +L0169 ldd PD.CYL-PD.OPT,x number of cylinders + std <ncyls save it + ldb PD.TYP-PD.OPT,x disk device type + stb <dtype save it + ldd PD.SCT-PD.OPT,x default sectors/track + std <sectors save it + ldd PD.T0S-PD.OPT,x default sectors/track tr00,s0 + std <sectors0 save it + ldb PD.ILV-PD.OPT,x sector interleave offset + stb <interlv save it + ldb #$01 default cluster size + stb <clustsiz save it + clrb no error + rts return + +******************************************************************** +* find a option and call, until all options are processed +******************************************************************** + +DoOpts ldx <u0022 option buffer +L0185 leay >OptTbl,pcr point to table + bsr L019C check for match? + bcs L01A5 no, match + pshs b,a save d register + ldd $02,y get offset value + leay d,y make function address + puls b,a restore d register + jsr ,y call function + bcc L0185 finished good? + lbra Exit no, exit +L019C lda ,x+ get option character +L019E cmpa ,y is it in the table? + bne L01A6 no, try the next one + ldb $01,y get return value + clra flag good +L01A5 rts return +L01A6 leay $04,y get next table location + tst ,y is it the end of the table? + bne L019E no, try next location + coma yes, flag bad + rts return + +******************************************************************** +* option command table +******************************************************************** OptTbl opt.1 fcc /R/ @@ -345,203 +322,280 @@ opt.2 fcc /r/ fcc /Y/ fdb DoReady-opt.2 -opt.3 fcc /"/ - fcb $00 - fdb DoQuote-opt.3 -opt.4 fcc /:/ +opt.3 fcc /S/ + fcc / / + fdb DoDsity-opt.3 +opt.4 fcc /s/ + fcc / / + fdb DoDsity-opt.4 +opt.5 fcc /D/ + fcc /M/ + fdb DoDsity-opt.5 +opt.6 fcc /d/ + fcc /M/ + fdb DoDsity-opt.6 +opt.7 fcc /"/ fcb $00 - fdb DoColon-opt.4 -opt.5 fcc /1/ - fcb $01 - fdb Do1-opt.5 -opt.6 fcc /2/ - fcb $02 - fdb Do2-opt.6 -opt.7 fcc /'/ - fcb 0 - fdb DoSQuote-opt.7 -opt.8 fcc /L/ + fdb DoQuote-opt.7 +opt.8 fcc /:/ + fcb $00 + fdb DoColon-opt.8 +opt.9 fcc "/" + fcb $00 + fdb DoClust-opt.9 +opt.10 fcc /1/ fcb $01 - fdb DoL-opt.8 -opt.9 fcc /l/ + fdb Do1-opt.10 +opt.11 fcc /2/ + fcb $02 + fdb Do2-opt.11 +opt.12 fcc /'/ + fcb 0 + fdb DoSQuote-opt.12 +opt.13 fcc /L/ + fcb $01 + fdb DoL-opt.13 +opt.14 fcc /l/ fcb 01 - fdb DoL-opt.9 -opt.10 fcc /(/ - fcb $00 - fdb DoLParen-opt.10 -opt.11 fcc /)/ + fdb DoL-opt.14 +opt.15 fcc /(/ fcb $00 - fdb DoRParen-opt.11 -opt.12 fcc /,/ + fdb DoLParen-opt.15 +opt.16 fcc /)/ fcb $00 - fdb DoComa-opt.12 -opt.13 fcb C$SPAC + fdb DoRParen-opt.16 +opt.17 fcc /,/ + fcb $00 + fdb DoComa-opt.17 +opt.18 fcb C$SPAC fcb 00 - fdb DoSpace-opt.13 - + fdb DoSpace-opt.18 fcb $00 - cmpb <u0011 - bgt L01FE +******************************************************************** +* S/D - density; single or double +******************************************************************** + +DoDsity cmpb <u0011 + bgt OptAbort cmpb <u004C - blt L01FE + blt OptAbort stb <mfm clrb +******************************************************************** +* skip white space +******************************************************************** + DoComa DoRParen DoLParen DoSpace rts -DoReady stb <u001E - rts +******************************************************************** +* set ready flag - skip warn messages +******************************************************************** + +DoReady stb <ready set and save ready + rts return + +******************************************************************** +* 1/2 - number of sides +******************************************************************** Do2 Do1 cmpb <u0013 - bgt L01FE + bgt OptAbort stb <u0013 clrb rts -DoL stb <u004E - clrb - rts +******************************************************************** +* only do a logical format on the rbf device +******************************************************************** + +DoL stb <u004E do a logical format + clrb did option + rts return -L01FE leax >AbortOp,pcr - lbra L06F9 +******************************************************************** +* not a option - show abort message and exit +******************************************************************** + +OptAbort leax >AbortOp,pcr Option not allowed message + lbra PExit print message and exit + +******************************************************************** +* double quoted option "disk name" save name in dskname +******************************************************************** -DoQuote leay <u006F,u - ldb #C$SPAC -L020A -koQuote lda ,x+ - cmpa #'" - beq L0221 - sta ,y+ - decb - bne L020A -L0215 ldb ,x+ - cmpb #'" - beq L0227 - cmpb #C$SPAC - bcc L0215 - bra L0227 -L0221 lda #C$SPAC - cmpb #C$SPAC - beq L022B -L0227 leay -$01,y - lda ,y -L022B adda #$80 - sta ,y - clrb - rts +DoQuote leay <dskname,u delimited buffer + ldb #C$SPAC delimited size +koQuote lda ,x+ delimited character + cmpa #'" is end quote? + beq L0221 must be done + sta ,y+ no, save character + decb decrement name size + bne KoQuote get all 32 of them or quote +L0215 ldb ,x+ next delimited character + cmpb #'" find end quote? + beq L0227 yes, back up and mark it + cmpb #C$SPAC skip space character? + bcc L0215 yes, get next one + bra L0227 no, mark it's end +L0221 lda #C$SPAC get space character + cmpb #C$SPAC any delimited characters? + beq L022B no, mark it's end +L0227 leay -$01,y yes, back up + lda ,y get saved character +L022B adda #$80 make it negative + sta ,y mark it's end + clrb did option + rts return -DoSQuote lbsr L092C - ldd <u001F - std <ncyls - rts +******************************************************************** +* single quoted option 'number of cylinders' save number in ncyls +******************************************************************** + +DoSQuote lbsr Decimal procces number of cylinders + ldd <dresult get it + std <ncyls save it + rts return -DoColon lbsr L092C - ldd <u001F - tsta - beq L0243 - ldb #$01 -L0243 stb <interlv - rts - lbsr L092C - ldd <u001F - tsta - beq L0250 - ldb #$01 -L0250 stb <u0027 - negb - decb - andb <u0027 - beq L025C - ldb #$01 - stb <u0027 -L025C clrb -L025D rts -L025E leax >Title,pcr - lbsr L02E2 - leay >optbuf,u - ldx PD.T0S-PD.OPT,y - tst <mfm - beq L0271 - ldx PD.SCT-PD.OPT,y -L0271 stx <sectors - leax >FmtMsg,pcr - ldy #FmtMLen - lbsr L02E6 - leax <u004F,u - tfr x,y -L0283 lda ,y+ - cmpa #PENTIR - bne L0283 - pshs y - lda #C$CR - sta -$01,y - lbsr L02E2 - puls y +******************************************************************** +* colon quoted option :interleave value: save value in interlv +******************************************************************** + +DoColon lbsr Decimal proccess interleave value + ldd <dresult get it + tsta answer out of bounds? + beq L0243 no, save it + ldb #$01 yes, default size +L0243 stb <interlv save it + rts return + +******************************************************************** +* quoted option /cluster size/ save size in clustsiz +* cluster size is in decimal and the number of sectors +* in a cluster must be a power of 2 and fit inside of two bytes +******************************************************************** + +DoClust lbsr Decimal proccess cluster size + ldd <dresult get it + tsta answer out of bounds? + beq L0250 no, save it + ldb #$01 yes, default size +L0250 stb <clustsiz save it + negb one's complement + decb power of 2 + andb <clustsiz in range? + beq L025C yes, skip ahead + ldb #$01 no, default size + stb <clustsiz save it +L025C clrb did option +L025D rts return + +******************************************************************** +* print title, format (Y/N), and get responce +******************************************************************** + +Proceed leax >Title,pcr coco formatter message + lbsr PrintLn print it + leay >optbuf,u point to option buffer + ldx PD.T0S-PD.OPT,y default sectors/track tr00,s0 + tst <mfm double-density? + beq L0271 no, + ldx PD.SCT-PD.OPT,y default sectors/track +L0271 stx <sectors save it + leax >FmtMsg,pcr formatting drive message + ldy #FmtMLen length of message + lbsr Print print it + leax <u004F,u input buffer + tfr x,y put it in y +L0283 lda ,y+ get input + cmpa #PENTIR proceed (y/n)? + bne L0283 no, wait for yes + pshs y save input pointer + lda #C$CR carriage return + sta -$01,y store it over input + lbsr PrintLn print line + puls y get pointer lda #PENTIR sta -$01,y - lda <u001E - bne L02BC - tst <dtype - bpl L02AB - leax >HDFmt,pcr - ldy #$002A - lbsr L02E6 -L02AB leax >Query,pcr - ldy #QueryLen - lbsr L02EC - anda #$DF - cmpa #'Y - bne L02D5 -L02BC tst <dtype - bpl L025D - leax >HDFmt,pcr - ldy #$0038 - lbsr L02EC - anda #$DF - cmpa #'Y - beq L025D - clrb - lbra L00BB -L02D5 clrb - cmpa #'N - lbeq L00BB - bra L02AB -L02DE leax >HelpCR,pcr -L02E2 ldy #80 -L02E6 lda #$01 - os9 I$WritLn - rts -L02EC pshs u,y,x,b,a - bsr L02E6 - leax ,s - ldy #$0001 - clra - os9 I$Read - lbcs L00BB - bsr L02DE - puls u,y,x,b,a - anda #$7F - rts + lda <ready ok to proceed? ready + bne L02BC yes, were ready skip ahead + tst <dtype is this a floppy or hard drive? + bpl L02AB it is a floppy + leax >HDFmt,pcr it is a hard drive + ldy #$002A length of message + lbsr Print print message +L02AB leax >Query,pcr query message + ldy #QueryLen length of message + lbsr Input show it and get responce (Y/N) + anda #$DF make it upper case + cmpa #'Y answered yes? + bne L02D5 no, check for no? +L02BC tst <dtype formatting hard drive? + bpl L025D no, return skip hard disk warn message + leax >HDFmt,pcr show hard disk warn message + ldy #HDFmtLen size of the message + lbsr Input show it and get responce (Y/N) + anda #$DF make it upper case + cmpa #'Y answered yes? + beq L025D yes, return + clrb clear error + lbra Exit exit +L02D5 clrb clear error + cmpa #'N answered no? + lbeq Exit yes, exit + bra L02AB no, get a (Y/N) answer + +******************************************************************** +* print usage message and return +******************************************************************** -GetDTyp leax >L001A,pcr - stx <u000A - ldb <dtype - bitb #TYP.HARD+TYP.NSF - bne L0323 - tst <u004D +LineFD leax >HelpCR,pcr point to line feed +PrintLn ldy #80 size of message +Print lda #$01 standard ouput path + os9 I$WritLn print line + rts return + +******************************************************************** +* print message and get responce +* entry: x holds data address y holds data size +* exit: a holds responce (ascii character) +******************************************************************** + +Input pshs u,y,x,b,a save registers + bsr Print print line + leax ,s get data address + ldy #$0001 data size + clra standard input + os9 I$Read read it + lbcs Exit exit on error + bsr LineFD print line feed + puls u,y,x,b,a restore stack + anda #$7F make it ascii + rts return + +******************************************************************** +* get capability of the rbf device +******************************************************************** + +GetDTyp leax >hdsdat,pcr hard drive data + stx <u000A sector data pointer + ldb <dtype get disk drive type + bitb #TYP.HARD+TYP.NSF hard disk or non-standard type? + bne L0323 no, check track data + tst <u004D beq L031B - leax >L0076,pcr + leax >dctdat,pcr bra L032D -L031B leax >L0020,pcr - tst <mfm - beq L032D +L031B leax >sgtdat,pcr + tst <mfm double-density? + beq L032D no, L0323 stx <u000A - leax >L0049,pcr + leax >dbtdat,pcr tst <u004C beq L032F L032D stx <u000A @@ -551,14 +605,14 @@ tfr d,y clrb ldx <ncyls - bsr L0379 + bsr Mulbxty exg d,x subd #$0001 bcc L0344 leax -$01,x L0344 exg d,x ldy <sectors - bsr L0379 + bsr Mulbxty exg d,x addd <sectors0 std <u0025 @@ -570,46 +624,56 @@ ldx <u0025 ldb <u0024 bsr L03C2 - lda <u0027 - pshs a + lda <clustsiz get cluster size + pshs a save it bsr L03C2 tstb beq L0374 - leax >ClustMsg,pcr - lbsr L02E2 - lbra L05B1 + leax >ClustMsg,pcr cluster size mismatch message + lbsr PrintLn print mismatch message + lbra L05B1 abort message and exit L0374 leas $02,s - stx <u0028 - rts -L0379 lda #$08 -L037B clr ,-s - deca - bne L037B + stx <ClustSz + rts return + +******************************************************************** +* multiply (mlbxty) +******************************************************************** + +Mulbxty lda #$08 make stack space +MulClr clr ,-s clear the space + deca cleared? + bne MulClr no, sty ,s stb $02,s stx $03,s -L0387 ldd ,s - beq L03AA +MulLoop ldd ,s we done? + beq MulZer yes, clean up lsra rorb std ,s - bcc L039D + bcc MulNoC ldd $03,s addd $06,s std $06,s lda $02,s adca $05,s sta $05,s -L039D ldd $03,s +MulNoC ldd $03,s lslb rola std $03,s lda $02,s rola sta $02,s - bra L0387 -L03AA leas $05,s - puls pc,x,b + bra MulLoop continue rest +MulZer leas $05,s clean up space + puls pc,x,b pop results, return + +******************************************************************** +* +******************************************************************** + L03AE pshs x,b lsr ,s ror $01,s @@ -624,27 +688,31 @@ bne L03AE rts -Format tst <u004E - bne L03E4 - tst <dtype +******************************************************************** +* format rbf device +******************************************************************** + +Format tst <u004E doing a logical format? + bne L03E4 yes, don't do this then + tst <dtype bpl L03E5 - leax >Both,pcr - ldy #BothLen - lbsr L02EC - anda #$DF - cmpa #'Y - beq L03E5 - cmpa #'N - bne Format -L03E4 rts -L03E5 lda <diskpath - ldb #SS.Reset - os9 I$SetStt - lbcs L00BB - ldd #$0000 - std <currtrak - inca - sta <currsect + leax >Both,pcr PHYSICAL and LOGICAL? message + ldy #BothLen length of message + lbsr Input print and get input + anda #$DF make it upper case + cmpa #'Y is it yes? + beq L03E5 yes, + cmpa #'N is it no? + bne Format no, +L03E4 rts return +L03E5 lda <diskpath device path number + ldb #SS.Reset reset device + os9 I$SetStt at track zero + lbcs Exit exit if error + ldd #$0000 get current track + std <currtrak save it + inca get current sector + sta <currsect save it L03F8 clr <u0005 L03FA bsr L045C leax >u00B7,u @@ -669,23 +737,28 @@ L0423 lda <u0005 beq L0429 orb #$01 -L0429 tfr d,y - lda <diskpath - ldb #SS.WTrk - os9 I$SetStt - lbcs L00BB - ldu <savedu +L0429 tfr d,y get side/density bits + lda <diskpath rbf device path number + ldb #SS.WTrk format (write) track + os9 I$SetStt do format it + lbcs Exit exit if error + ldu <savedu get u pointer ldb <u0005 incb stb <u0005 cmpb <u0013 bcs L03FA - ldd <currtrak - addd #$0001 - std <currtrak - cmpd <ncyls - bcs L03F8 - rts + ldd <currtrak get current track + addd #$0001 increment it + std <currtrak save it + cmpd <ncyls did all tracks? + bcs L03F8 no, + rts yes, return + +******************************************************************** +* +******************************************************************** + L044E ldy <u000E L0451 ldd ,y++ beq L046B @@ -700,6 +773,11 @@ leax >u00B7,u bsr L0451 L046B rts + +******************************************************************** +* +******************************************************************** + L046C ldy <u000C ldb <u001A tst <currtrak+1 @@ -722,10 +800,10 @@ sty <u000E stx <u003D leay >u297E,u - sty <u001F + sty <dresult tfr a,b L04A6 std ,x++ - cmpx <u001F + cmpx <dresult bcs L04A6 ldy <u000E ldd ,y++ @@ -754,8 +832,18 @@ ldd <u0041 bra L04C3 L04E4 rts -L04E5 leax >AbortSct,pcr - lbra L06F9 + +******************************************************************** +* +******************************************************************** + +L04E5 leax >AbortSct,pcr sector number out of range message + lbra PExit print message and exit + +******************************************************************** +* +******************************************************************** + L04EC pshs y,b tfr b,a ldb <currtrak+1 @@ -765,8 +853,8 @@ leay a,x ldb <interlv bne L0507 -L0500 leax >AbortIlv,pcr - lbra L06F9 +L0500 leax >AbortIlv,pcr Interleave out of range message + lbra PExit print message and exit L0507 cmpb <u0018 bhi L0500 nega @@ -789,7 +877,12 @@ leax $01,x stx $02,s bra L050F -InitDisk lbsr L0898 + +******************************************************************** +* +******************************************************************** + +InitDisk lbsr ClrBuf ldd <u0025 std $01,x ldb <u0024 @@ -797,10 +890,10 @@ ldd <sectors std <$11,x stb $03,x - lda <u0027 - sta $07,x + lda <clustsiz get cluster size + sta $07,x save it clra - ldb <u0028 + ldb <ClustSz tst <u0029 beq L054F addd #$0001 @@ -821,14 +914,14 @@ beq L056F ora #$04 L056F sta <$10,x - ldd <u0028 + ldd <ClustSz std $04,x lda #$FF sta $0D,x leax >timepkt,u os9 F$Time leax >u00D6,u - leay <u006F,u + leay <dskname,u quote delimited disk name buffer tst ,y beq L0594 L058C lda ,y+ @@ -837,7 +930,7 @@ bra L05C7 L0594 leax >DName,pcr ldy #DNameLen - lbsr L02E6 + lbsr Print leax >u00D6,u ldy #$0021 clra @@ -845,8 +938,8 @@ bcc L05B8 cmpa #E$EOF bne L0594 -L05B1 leax >Aborted,pcr - lbra L06F9 +L05B1 leax >Aborted,pcr format aborted message + lbra PExit print message and exit L05B8 tfr y,d leax d,x clr ,-x @@ -864,11 +957,11 @@ bcs L05D3 leas $02,s std >u00C5,u - ldd >L0014,pcr + ldd >val1,pcr std >u01A7,u - ldd >L0016,pcr + ldd >val2,pcr std >u01A9,u - ldd >L0018,pcr + ldd >val3,pcr std >u01AB,u lda <diskpath ldb #SS.Opt @@ -876,48 +969,57 @@ os9 I$GetStt ldb #SS.Reset os9 I$SetStt - lbcs L00BB + lbcs Exit leax >u00B7,u - lbra L08A4 + lbra WritSec + +******************************************************************** +* +******************************************************************** Access lda <diskpath os9 I$Close leax <u004F,u lda #READ. os9 I$Open - lbcs L06F5 + lbcs BadSect sta <diskpath leax >u00B7,u ldy #256 os9 I$Read - lbcs L06F5 + lbcs BadSect lda <diskpath os9 I$Close leax <u004F,u lda #UPDAT. os9 I$Open - lbcs L06F5 + lbcs BadSect sta <diskpath rts -Stamps lda <dtype - clr <u0045 - bita #$80 - beq L0667 +******************************************************************** +* +******************************************************************** + +Stamps lda <dtype get device type in A + clr <dovfy + bita #TYP.HARD hard drive? + beq L0667 branch if not L0650 leax >Verify,pcr ldy #VerifyL - lbsr L02EC + lbsr Input anda #$DF - cmpa #$59 + cmpa #'Y beq L0667 - cmpa #$4E + cmpa #'N bne L0650 - sta <u0045 + sta <dovfy L0667 ldd <sectors0 std <u0017 clra clrb - std <u0036 + sta <oksects + std <oksects+1 std <currtrak std <u0008 std <u0032 @@ -925,23 +1027,23 @@ sta <u003C leax >optbuf,u stx <u0038 - lbsr L089C + lbsr ClrSec leax >$0100,x stx <u003A clra ldb #$01 std <u0034 - lda <u0027 - sta <u002B + lda <clustsiz get cluster size + sta <u002B store in cluster counter clr <u002A clra - ldb <u0028 + ldb <ClustSz tst <u0029 beq L069D addd #$0001 L069D addd #$0009 std <u002D - lda <u0027 + lda <clustsiz get cluster size L06A4 lsra bcs L06B5 lsr <u002D @@ -953,77 +1055,102 @@ bra L06A4 L06B5 ldb <u002E stb <u002F - lda <u0027 + lda <clustsiz get cluster size mul std <u002D subd #$0001 - subb <u0028 + subb <ClustSz sbca #$00 tst <u0029 beq L06CC subd #$0001 L06CC stb <u002C -L06CE tst <u0045 - bne L0700 - lda <diskpath - leax >u00B7,u - ldy #256 - os9 I$Read - bcc L0700 - os9 F$PErr - lbsr L08C8 +L06CE tst <dovfy + bne OutScrn ouput screen display + lda <diskpath get rbf device path + leax >u00B7,u input buffer + ldy #256 buffer size + os9 I$Read read sector? + bcc OutScrn ouput screen display + os9 F$PErr no, print error message + lbsr NextSec next sector lda #$FF sta <u002A tst <u0031 - bne L0700 + bne OutScrn ouput screen display ldx <u0032 cmpx <u002D - bhi L0700 -L06F5 leax >BadSect,pcr -L06F9 lbsr L02E2 - clrb - lbra L00BB -L0700 ldd <u0008 - addd #$0001 - std <u0008 - cmpd <u0017 - bcs L0745 - clr <u0008 - clr <u0009 - tst <u0045 + bhi OutScrn ouput screen display +BadSect leax >BadSectM,pcr bad system sector message +PExit lbsr PrintLn print message + clrb clear error + lbra Exit exit no error + +******************************************************************** +* ouput screen display scrolling track counter +******************************************************************** + +OutScrn ldd <u0008 get counted sectors + addd #$0001 increment it + std <u0008 save counted sectors + cmpd <u0017 > good sector count? + bcs L0745 next segment + clr <u0008 clear counted sectors + clr <u0009 + tst <dovfy bne L073A - lda #$20 + lda #C$SPAC pshs a lda <currtrak+1 - lbsr L07A7 - pshs b,a + lbsr HexDigit + +**************************************************************** +* Patch to "format" to give a 4 digit rolling track count rather +* than the 3 digit scrolling one. Tim Koonce, Oct. 10, 1989 +* L0724 pshs b,a +* lda #C$CR +* nop +* pshs a +* tfr s,x +* ldy #$0006 +* lda #$01 +* os9 I$Write +* nop +* nop +* L0738 ror 4,s +**************************************************************** + +L0724 pshs b,a lda <currtrak - lbsr L07A7 + lbsr HexDigit pshs b tfr s,x ldy #$0004 - lbsr L02E6 + lbsr Print lda $02,s cmpa #$46 bne L0738 - lbsr L02DE + lbsr LineFD L0738 leas $04,s -L073A ldd <currtrak - addd #$0001 - std <currtrak - ldd <sectors - std <u0017 -L0745 dec <u002B +L073A ldd <currtrak get current track + addd #$0001 increment it + std <currtrak save it back + ldd <sectors get number of sectors + std <u0017 save +L0745 dec <u002B decrement cluster counter bne L075B bsr L0784 tst <u002A bne L0755 - ldx <u0036 - leax $01,x - stx <u0036 +* Increment good sectors + ldd <oksects+1 + addd #$0001 + std <oksects+1 + bcc L0755 + inc <oksects L0755 clr <u002A - lda <u0027 - sta <u002B + lda <clustsiz get cluster size + sta <u002B save in cluster counter L075B ldb <u0031 ldx <u0032 leax $01,x @@ -1040,7 +1167,7 @@ sta <u002A leay >optbuf,u L077B cmpy <u0038 - beq L07BF + beq GoodSect number of good sectors summary bsr L0784 bra L077B L0784 ldx <u0038 @@ -1055,157 +1182,212 @@ stx <u0038 cmpx <u003A bne L07A6 - bsr L0803 + bsr WrtSecs leax >optbuf,u stx <u0038 - lbsr L089C -L07A6 rts -L07A7 tfr a,b - lsra - lsra - lsra - lsra - andb #$0F - addd #$3030 - cmpa #$39 - bls L07B8 - adda #$07 -L07B8 cmpb #$39 - bls L07BE - addb #$07 -L07BE rts -L07BF lbsr L02DE - leax >NumGood,pcr - ldy #NumGoodLen - lbsr L02E6 - ldb <u0027 - clra - ldx <u0036 - pshs x,a -L07D4 lsrb - bcs L07DF - lsl $02,s - rol $01,s - rol ,s - bra L07D4 -L07DF puls x,a - ldb #$0D - pshs b - tfr d,y - tfr x,d - tfr b,a - bsr L07A7 - pshs b,a - tfr x,d - bsr L07A7 - pshs b,a - tfr y,d - bsr L07A7 - pshs b,a - tfr s,x - lbsr L02E2 - leas $07,s - rts -L0803 pshs y - clra - ldb #$01 - cmpd <u0034 - bne L081E - leax >optbuf,u - clra - ldb <u002F - tfr d,y - clrb - os9 F$AllBit - lbcs L06F5 -L081E lbsr L08B2 - leax >optbuf,u - lbsr L08A4 - ldd <u0024 - cmpd <u0031 - bcs L083A - bhi L0837 - ldb <u0026 - cmpb <u0033 - bcc L083A -L0837 lbsr L08C8 -L083A ldd <u0034 - addd #$0001 - std <u0034 - puls pc,y -L0843 bsr L08B2 - leax >u02B7,u - bsr L089C - leax >u02BA,u - os9 F$Time - leax >u02B7,u - lda #$BF - sta ,x - lda #$02 - sta $08,x - clra - ldb #$40 - std $0B,x + lbsr ClrSec +L07A6 rts return + +******************************************************************** +* convert byte to ascii hexadecimal and return it in d register +******************************************************************** + +HexDigit tfr a,b get byte again + lsra shift upper digit + lsra + lsra + lsra + andb #$0F mask lower digit + addd #$3030 make it ascii + cmpa #$39 upper digit > 9 + bls L07B8 no, + adda #$07 yes, make hexadecimal +L07B8 cmpb #$39 lower digit > 9 + bls L07BE no, + addb #$07 yes, make hexadecimal +L07BE rts return + +******************************************************************** +* number of good sectors message +******************************************************************** + +GoodSect lbsr LineFD print line feed + leax >NumGood,pcr number of good sectors + ldy #NumGoodLen length of message + lbsr Print print it + ldb <clustsiz get cluster size + lda <oksects get 24 bit counter + ldx <oksects+1 + pshs x,a save 24 bit counter +L07D4 lsrb carry set 0xxx xxxx -> X ? + bcs L07DF yes, + lsl $02,s <u0036 1 X <- nnnn nnnn X <- xxxx xxx0 + rol $01,s <u0036 2 N <- nnnn nnnX N <- xxxx xxx0 + rol ,s <u0036 3 N <- nnnn nnnN + bra L07D4 did all sectors? +L07DF puls x,a get counted sectors + ldb #C$CR + pshs b save enter + tfr d,y get size + tfr x,d get + tfr b,a get convert byte + bsr HexDigit convert it BYTE 1 + pshs b,a save in buffer + tfr x,d get convert byte + bsr HexDigit convert it BYTE 2 + pshs b,a save in buffer + tfr y,d get convert byte + bsr HexDigit convert it BYTE 3 + pshs b,a save it buffer + tfr s,x get output buffer + lbsr PrintLn print it + leas $07,s fix stack + rts return + +******************************************************************** +* get allocation bit map and write sectors +******************************************************************** + +WrtSecs pshs y save register + clra set number + ldb #$01 bits to set + cmpd <u0034 map sector? + bne L081E yes, write sector + leax >optbuf,u allocation bit map + clra get number + ldb <u002F system sectors + tfr d,y into register + clrb first bit to set + os9 F$AllBit set allocation bit map + lbcs BadSect if there a error +L081E lbsr GetSec get sector + leax >optbuf,u allocation bit map + lbsr WritSec write sector + ldd <u0024 get total sectors + cmpd <u0031 lsn sector count? + bcs AdvSec advance to mapped sectors + bhi NxtSec get next sector + ldb <u0026 get LSB total sectors + cmpb <u0033 good sector count? + bcc AdvSec advance to mapped sectors +NxtSec lbsr NextSec skip to next sector +AdvSec ldd <u0034 get mapped sectors + addd #$0001 count from one + std <u0034 save mapped sectors count + puls pc,y restore and return + +******************************************************************** +* file descriptor +******************************************************************** + +FDScipt bsr GetSec get sector + leax >fdtbuf1,u sector buff + bsr ClrSec clear sector + leax >fdtbuf2,u get date last modified + os9 F$Time get system time + leax >fdtbuf1,u get file descriptor + lda #DIR.+PEXEC.+PWRIT.+PREAD.+EXEC.+UPDAT. + sta FD.ATT,x save in FD.ATT + lda #$02 get link count + sta FD.LNK,x save in FD.LNK + clra directory size + ldb #DIR.SZ*2 directory entries (DIR.SZ*2) + std FD.SIZ+2,x save it (FD.SIZ+2) ldb <u002C - decb - stb <$14,x + decb + stb <FD.SEG+FDSL.B+1,x save it (FD.SEG+FDSL.B+1) ldd <u0034 addd #$0001 - std <$11,x - bsr L08A4 - bsr L0898 - ldd #$2EAE - std ,x - stb <$20,x + std <FD.SEG+FDSL.A+1,x save it (FD.SEG+FDSL.A+1) + bsr WritSec + bsr ClrBuf + ldd #$2EAE (#'.*256+'.+128) + std DIR.NM,x (DIR.NM) + stb <DIR.SZ+DIR.NM,x (DIR.NM+DIR.SZ) ldd <u0034 - std <$1E,x - std <$3E,x - bsr L08A4 - bsr L0898 + std <DIR.FD+1,x + std <DIR.SZ+DIR.FD+1,x + bsr WritSec + bsr ClrBuf ldb <u002C - decb -L088C decb - bne L0890 - rts -L0890 pshs b - bsr L08A4 - puls b - bra L088C -L0898 leax >u00B7,u -L089C clra - clrb -L089E sta d,x - decb - bne L089E - rts -L08A4 lda <diskpath - ldy #256 - os9 I$Write - lbcs L00BB - rts -L08B2 clra - ldb <u0034 - tfr d,x + decb make zero offset (0 - 255) +NextCnt decb decrement sector count + bne NextWrt if more to do + rts else return +NextWrt pshs b save sector count + bsr WritSec write the sector + puls b get count back + bra NextCnt do until done + +******************************************************************** +* clear the 256 byte sector buffer +******************************************************************** + +ClrBuf leax >u00B7,u sector buffer +ClrSec clra store mask + clrb sector count +ClrLop sta d,x clear the buffer + decb decrement sector count + bne ClrLop clear sector buffer + rts return when done + +******************************************************************** +* write physical 256 byte sector to the diskette +******************************************************************** + +WritSec lda <diskpath get path number + ldy #256 get sector size + os9 I$Write write the sector + lbcs Exit exit on error + rts return + +******************************************************************** +* get sector file position +******************************************************************** + +GetSec clra + ldb <u0034 get map sectors high word + tfr d,x save it lda <u0035 - clrb - tfr d,u -L08BC lda <diskpath - os9 I$Seek - ldu <savedu - lbcs L00BB - rts -L08C8 ldx <u0031 - lda <u0033 - clrb - addd #$0100 - tfr d,u - bcc L08BC - leax $01,x - bra L08BC + clrb get map sectors low word + tfr d,u save it + +******************************************************************** +* seek to physical sector +******************************************************************** + +SeekSec lda <diskpath get path number + os9 I$Seek seek to sector + ldu <savedu get data pointer + lbcs Exit exit if error + rts return + +******************************************************************** +* skip to the next sector +******************************************************************** + +NextSec ldx <u0031 lsn count + lda <u0033 good sector count + clrb add this + addd #$0100 sector + tfr d,u lsn count + bcc SeekSec seek it? + leax $01,x next sector + bra SeekSec seek it + +******************************************************************** +* the format module never gets to this code? +******************************************************************** + ldd ,y leau >u00B7,u - leax >L0920,pcr + leax >dcnums,pcr decimal number conversion table ldy #$2F20 + +******************************************************************** +* +******************************************************************** + L08E6 leay >$0100,y subd ,x bcc L08E6 @@ -1228,24 +1410,34 @@ ldu <savedu leas $02,s leax >u00B7,u - lbsr L02E2 - rts + lbsr PrintLn + rts -L0920 fdb $2710,$03e8,$0064,$000a,$0001,$0000 +dcnums fdb 10000,1000,100,10,1,0 + +******************************************************************** +* process decimal number input (65535) +******************************************************************** -L092C ldd #$0000 -L092F bsr L093F - bcs L0939 - bne L092F - std <u001F - bne L093E -L0939 ldd #$0001 - std <u001F -L093E rts -L093F pshs y,b,a - ldb ,x+ - subb #$30 - cmpb #$0A +Decimal ldd #$0000 start at zero +L092F bsr DecBin get first digit + bcs L0939 if overflow + bne L092F get next digit + std <dresult save decimal as binary + bne L093E if no error return +L0939 ldd #$0001 flag error + std <dresult save it +L093E rts return + +******************************************************************** +* process decimal number into it's binary representation +* return with binary in the d register +******************************************************************** + +DecBin pshs y,b,a save registers + ldb ,x+ get digit + subb #$30 make it binary + cmpb #$0A bla bla bla! bcc L095D lda #$00 ldy #$000A @@ -1258,23 +1450,36 @@ L095B puls pc,y,b,a L095D orcc #Zero puls pc,y,b,a -L0961 lda #$02 - os9 F$PErr - leax <HelpMsg,pcr - ldy #$0154 - lda #$02 - os9 I$WritLn - clrb - os9 F$Exit + +******************************************************************** +* print error, usage message, and exit +******************************************************************** + +PrtError lda #$02 standard error + os9 F$PErr print error + IFNE DOHELP + leax <HelpMsg,pcr point to usage + ldy #HelpLen usage size + lda #$02 standard error + os9 I$WritLn print usage + ENDC + clrb no error + os9 F$Exit exit module + +******************************************************************** +* messages +******************************************************************** Title fcb C$LF fcc "COLOR COMPUTER FORMATTER" HelpCR fcb C$CR - + IFNE DOHELP HelpMsg fcc "Use: FORMAT /devname <opts>" fcb C$LF fcc " opts: R - Ready" fcb C$LF + fcc " S/D - density; single or double" + fcb C$LF fcc " L - Logical format only" fcb C$LF fcc / "disk name"/ @@ -1284,12 +1489,13 @@ fcc " 'No. of cylinders' (in decimal)" fcb C$LF fcc " :Interleave value: (in decimal)" + fcb C$LF + fcc " /Cluster size/ (in decimal)" fcb C$CR HelpLen equ *-HelpMsg - + ENDC FmtMsg fcc "Formatting drive " FmtMLen equ *-FmtMsg - Query fcc "y (yes) or n (no)" fcb C$LF fcc "Ready? " @@ -1303,8 +1509,8 @@ DName fcc "Disk name: " DNameLen equ *-DName fcc "How many Cylinders (Tracks?) : " -BadSect fcc "Bad system sector, " -Aborted fcc "FORMAT ABORTED" +BadSectM fcc "Bad system sector, " +Aborted fcc "FORMAT ABORTED" fcb C$CR ClustMsg fcc "Cluster size mismatch" fcb C$CR @@ -1322,7 +1528,6 @@ BothLen equ *-Both Verify fcc "Physical Verify desired? " VerifyL equ *-Verify - emod eom equ * end