ADFS DD Partioner

By Richard Dimond

Originally published in EUG #27

As promised in my earlier description of the BASIC version, I now submit a m/code version. This is not only quicker in operation, it is far easier to use (as it is run with a *command). Also, being coded, it can be used with the AUTOROM program, or could be written for storing in Sideways RAM.

In doing the coding, I have made some small improvements. I have turned the flashing cursor off as this is not needed and when quitting the program, the Elk is returned to Mode 6.

The code is assembled at Q% with addresses for P% at &2000. This is done using OPTs 4 - 6 as in my MR MINER program, but the DIM Q% 1000 (Line 90) reserves the space for the code above TOP. This allows the code to set up whether PAGE is at &E00 or &1D00.

The addresses for the variables are set in lines 140-180. Some addresses are used for two variables but this doesn't matter as these are not used at the same time.

I will just describe in detail the parts which have not been covered before and explain these in the order they occur, referring to the lines which create the code.

Lines 220-270 create the opening screen as described in my tutorial series. Lines 270,290 stop the program until RETURN is pressed. Line 280 allows you to exit the program by pressing ESCAPE as this sets the carry flag and then the code returns to BASIC.

The routine 'readdisc", lines 600-630, first gives the command *MOUNT. This uses the OS routine OSCLI (&FFF7) with X and Y registers pointing to the address of the command data at line 2810. OSWORD with A register=&72 is used with parameter block (line 2800) set as in the BASIC version. This reads the two sectors of the FS map to the address W%. I have set this to an address just below the screen memory area. This can be altered if it is not convenient simply by altering the value of W% and re-assembling the code.

Line 300 sets COLUUR 2 to Blue and turns off the cursor.

The routine 'vars' (lines 1100-1260) is next called. This first finds the value in address W%+&1FE (X%+Y) and stores this in 'size'. This is the number of used sections of the disk. The two bytes at W%+&FE are found and stored in the two bytes of 'sectors'. They are also stored in 'tracks' and then the bits manipulated (lines 1160-1190) to divide the value by 16 to give the number of tracks.

The BASIC program then divided by 80 to give the number of sides. This is not so easy to do in m/code and also, having a disk that would only format completely as a 40 Track disk, I found this then gave sides as 0!! I then thought that tracks can only have the values 160, 80 or 40. So I have compared tracks with 160 and if equal 2 is printed, and, if not equal, to print 1 (Lines 1200-1220) - much simpler!!

The value of sectors is also stored at discsize+1 and +2. This gives the value of discsize as sectors*256, i.e. the number of bytes on the disk.

Line 1250 sets up the character number 224 using VDU23. A comparison is made of the value of sides and, if equal to 1, the character bytes are 224, and 192 if not. This gives a narrower character for a double-sided disk.

The routine 'grid' (Lines 1300-1690) is rather complex but consists of several sections. Line 1310 uses the data 'd4' (Line 2840), first to set the background colour to red and setting the graphics window. After the window is cleared, the screen is returned normal. The foreground colour is then set to write and the background to black.

The two sections lines 1320-1400 and 1410-1490, print the grid using the routine 'plotpt' to set the plot points.

The first draws the vertical lines. The number of lines to be drawn are loaded into 'count' and the four co-ordinate bytes of the variable 'plot' are set to zero (Line 1420). The loop 'vlp' then draws the lines. The two calls to the routine 'plotpt' change the Y co-ords to draw a line on the X co-ord (initially zero). The X co-ord is increased by adding 16 each time round the loop and 'count' decreased until this is zero and then the second section draws the horizontal lines in the same way.

The third section (Lines 1500-1690) prints the track numbers and short vertical lines underneath. Line 1510 sets count to 8, the X co-ord, hex and trkno to zero.

The number of sides is then checked; if this is two, the variable 'diff' is equal to 20 otherwise it equals 10. The loop 'vlp2' first draws the short line using 'plotpt' then the value in trkno is compared and if equal to zero, a zero is printed (Lines 1570-1590). The value of 'diff' is added and 192 added to the X co-ord before looping back to 'vlp2'. Since trkno is not zero, the track numbers are now printed using the routine 'decprt' (Lines 650-1090). This routine for printing a decimal number was a routine given in The Micro User, September 1990. This is used complete as I do not know of another routine to do this. The comparison in line 1640 stops the printing of the final track number and ends the routine.

The routine 'info' prints the tracks heading and the remaining printing as before using data lines 2850 and 2860 and the 'decprt' routine for printing the values.

The routine 'key' prints the key to the colours. For each of the four colours, the co-ords X and Y and the two colour numbers C1 and C2 are set before the routine 'sqr' is called. This sets the colour C1 for key and draws a solid square by using PLOT code 85 twice. The colour is changed to C2 and the outline drawn. The program returns to 'info' for the printing.

The routine 'sfreesecs' is rather complex for calculating the values of T and S for the co-ords X and Y in order to print the character number 224. Line 220 gives the command VDU5 to join the cursors. Next the disk space (dsp) is added to the disk address (dad) and stored in 'dsp' to give the end address.

The disk address is stored in T, the bits then shifted right four times to divide by 16. The four low bits of T are rotated into S. These are then shifted four times to the right so that S has the value of T MOD 16.

The bits in T are then shifted left three or four times to multiply by 8 or 16 depending on the value of sides to give the X co-ord. The value of S is multiplied by 32 by shifting left five times and then this value is subtracted from 768 (&300) to give the value of the Y co-ord. The routine 'plotpt' is then used to set the print position for the character 224 and then it is printed.

The disk address is then increased and compared with the end address and if not equal the program returns to calculate for the next sector. When the end address has been reached and comparison is equal, the cursors are returned to normal by the command VDU4 and the routine ends.

The FS map is shown by the next routine (Lines 2450-2500) by loading 'dad' with zero and 'dsp' with two and changing the colour to white.

The root directory is shown in a similar way with routine 'cat'.

The routine 'fdfsecs' (Lines 2570-2710) first sets the colour with VDU 18,3,1 and sets the index Y to zero and stores this in 'count'.

In the loop 'sflp' the index value in 'count' is loaded into Y register so that the disk address info is read from W%,Y and the disk space info from X%,Y. Each time that this is done, the routine to print the free sectors is called and when the value of count equals that of size, the routine ends.

The program then returns to print the final cue at line 380 and pauses at line 390. If the key R is pressed (the AND#&DF gives the same value if the lower case r is used), the program goes to 'st'; this gives the command *FX21 to clear the buffers before a jump is made to 'start'.

If any other key is pressed, Mode 6 is selected and the program returns to BASIC.

Richard Dimond, EUG #27