BeebMaster - BeebHelp - Formatting a Disc on a BBC Model B
BeebMaster

Formatting a disc
on a
BBC Model B

OK. You've just bought a BeebMaster Disc Upgrade Kit, you've put it in the Beeb and put your lovely Beeb back together. All appears well and you've tried out a few discs of games and now you want to format your first disc.

You type *FORM80 0 and all you get is "Disk fault 18 at 00/00". Disaster!

Don't worry - this is quite normal! The reason is that the format utility was not built into the original 8271 DFS software. You will need a special formatting utility and if you can't find one, just type in the programme below and all your problems will be solved!

10REM Format
20REM 8271 Disc Formatter
30REM (C) Ian Wolstenholme 2003
40REM Version 1.2 12/vii/2003
50DIM osblock 20,sector 50,seek 20,track0 512
60PRINT"Disc Formatter"
70REPEAT
80PRINT"Which drive? ";:INPUT""D%
90UNTILD%=0ORD%=1ORD%=2ORD%=3
100REPEAT
110PRINT"Start track (0-79)? ";:INPUT""V%
120UNTILV%>-1ANDV%<80
130IFV%=79W%=79:GOTO170
140REPEAT
150PRINT"End track (";V%;"-79)? ";:INPUT""W%
160UNTILW%>=V%AND W%<80
170FORT%=V%TOW%
180PROCsector
190PROCseek
200A%=&7F
210X%=osblock MOD256
220Y%=osblock DIV256
230?osblock=D%
240osblock?1=sector MOD256
250osblock?2=sector DIV256
260osblock?3=&FF:osblock?4=&FF
270osblock?5=5:REM 5 params
280osblock?6=&63:REM Format
290osblock?7=T%:REM track
300osblock?8=16:REM gap3
310osblock?9=32+10:REM 256 bps; 10 spt
320osblock?10=0:REM gap5
330osblock?11=16:REM gap1
340osblock?12=0
350CALL&FFF1
360IFosblock?12<>0 STOP
370PRINT" ";STRING$(3-LENSTR$T%," ");T%;
380NEXT
390IFV%<>0ANDW%<>39ANDW%<>79 END
400PROCcat
410END
420DEFPROCsector
430?sector=T%
440sector?1=0:sector?2=0
450sector?3=1:sector?4=T%
460sector?5=0:sector?6=1
470sector?7=1:sector?8=T%
480sector?9=0:sector?10=2
490sector?11=1:sector?12=T%
500sector?13=0:sector?14=3
510sector?15=1:sector?16=T%
520sector?17=0:sector?18=4
530sector?19=1:sector?20=T%
540sector?21=0:sector?22=5
550sector?23=1:sector?24=T%
560sector?25=0:sector?26=6
570sector?27=1:sector?28=T%
580sector?29=0:sector?30=7
590sector?31=1:sector?32=T%
600sector?33=0:sector?34=8
610sector?35=1:sector?36=T%
620sector?37=0:sector?38=9
630sector?39=1:sector?40=T%
640sector?41=0:sector?42=0
650ENDPROC
660DEFPROCseek
670A%=&7F
680X%=seek MOD256
690Y%=seek DIV256
700?seek=D%
710seek?1=0:seek?2=0:seek?3=0:seek?4=0
720seek?5=1:seek?6=&69
730seek?7=T%
740seek?8=0
750CALL&FFF1
760IFseek?8<>0STOP
770ENDPROC
780DEFPROCcat
790T%=0:PROCseek
800FORB%=0TO512STEP4
810track0!B%=0
820NEXT
830IFW%=79 track0?262=3 ELSEtrack0?262=1
840IFW%=79 track0?263=32 ELSEtrack0?263=144:REM Sectors on disc
850X%=osblock MOD256
860Y%=osblock DIV256
870?osblock=D%
880osblock?1=track0 MOD256
890osblock?2=track0 DIV256
900osblock?3=0:osblock?4=0
910osblock?5=3:osblock?6=&4B
920osblock?7=0:osblock?8=0
930osblock?9=34
940osblock?10=0
950CALL&FFF1
960ENDPROC

When RUN, this programme asks you for the drive to format and allows you to specify the range of tracks to be formatted. This is useful for formatting odd tracks on discs which are partially corrupt. To fully format an 80 track disc, select 0 for the start track and 79 for the end track. When you enter the end track number, formatting begins without any further warning so make sure you have the correct disc in the drive!

Here's the science bit...for anyone who's interested:

10-40 Copyright & version messages
50 Reserve some space for the data blocks we will need
60 Print start up message
70 Begin a REPEAT...UNTIL loop
80 Ask for the drive number
90 Keep asking until the user inputs 0, 1, 2 or 3
100 Start a REPEAT...UNTIL loop
110 Ask for start track
120 Keep asking until user inputs a sensible number
130 If start track is 79 then skip the bit to ask end track as it will be the same
140 Start a REPEAT...UNTIL loop
150 Ask for end track
160 Keep asking until user inputs a number less than 80 and at least as big as the start track
170 Set up a for next loop to go from Start Track to End Track
180 Call procedure "Sector"
190 Call procedure "Seek"
200 Set up OSWORD call - set A% to &7F, DFS general read/write call
210-220 Set X% & Y% to point to osblock, our OSWORD parameter block
230 Set up our OSWORD parameter block: first byte is drive number
240 Second byte is low byte of "sector" memory block
250 Third byte is high byte of "sector" memory block
260 Fourth & fifth bytes are 255. These are the two high bytes of the "sector" memory address
270 Sixth byte specifies 5 parameters to follow for this command
280 Seventh byte is first of our five parameters - the command type, Format
290 Eighth byte is second of our five parameters - the track number
300 Ninth byte is third of our five parameters - "Gap3" size set to 16
310 Tenth byte is fourth of our five parameters - sector size (256 bytes) & number of sectors to operate on (10, ie. a whole track)
320 Eleventh byte is fifth of our five parameters - "Gap5" size set to 0
330 Twelfth byte is "Gap1" size - 16 for DFS format
340 Thirteenth byte is zero. Any errors will be reported in this byte
350 Call OSWORD. This will format the current track
360 Check for errors and stop if an error reported
370 Print number of track just formatted
380 Continue until all specified tracks are formatted
390 Check if we're formatting a full disc. If not, end.
400 If we are formatting a full disc, call procedure "Cat" to write the disc catalogue & free space map
410 Finished
420 Define procedure called "Sector"
430 Set up "sector" data block - first byte is track number
440-640 Set up remainder of data block alternating sector number (0-9) and track number. This is required for the format command to work properly
650 End of procedure
660 Define procedure called "Seek"
670 Set up OSWORD call: A%=&7F, DFS general read/write function
680-690 X% & Y% point to "seek" data block
700 Set up "seek" data block - first byte is drive number
710 Four empty bytes because no memory block to point to for this command
720 Next byte specifies one parameter for this command, command number &69 for seek
730 Next byte is track number
740 Clear next byte for error reporting
750 Call OSWORD this will cause the floppy disc controller to move the drive heads to the specified track
760 Check for errors and stop if error
770 End of "seek" routine
780 Define a procedure called "Cat"
790 Move drive heads to track 0
800-820 Clear "track0" memory block of any data
830-840 Write number of sectors on disc - if end track was 79, then it is 800, otherwise assume 400 for 40 track disc
850-860 Set X% & Y% to point to OSWORD parameter block
870 Set up parameter block - first byte is drive number
880-900 Four bytes to point to "track0" memory block
910 3 paramters for this command, first one is &4B for Write
920 Second parameter is track number (0); third parameter is sector number (0)
930 Specify data format, 256 bytes per sector and operate on two sectors
940 Empty byte for errors
950 Call OSWORD - this will write the 512 bytes of data stored at "track0"(i.e. 2 sectors' worth) to track 0 sectors 0, 1. This effectively writes a blank catalogue and puts the right number of sectors in the free space map.
960 End procedure


Click here to go back