The DesTerm RamDisk This document explains how DesTerm uses the Commodore REU as a Ramdisk. A starting point ---------------- Anybody that is familiar with Commodore disk drives will be right at home with the DesTerm Ramdisk. The layout of the `disk' has been borrowed from this well-defined standard. Tracks and Sectors ------------------ As with physical disks, the Ramdisk is broken up into a series of sectors and tracks. The layout of the disk allows REUs of up to 2048K to be used as Ramdisk (larger units can be used, but only the first 2048K will be used by the ramdisk). Sectors contian 256 bytes of data. Unlike real disks, each track has exactly the same number of sectors (128). The number of tracks depends on how large the REU is: REU Size Ramdisk Tracks Total Blocks Banks reu_size (*) 128 4 512 2 0 256 8 1024 4 1 384 12 1536 6 2 512 16 2048 8 3 640 20 2560 10 4 768 24 3072 12 5 896 28 3584 14 6 1024 32 4096 16 7 1152 36 4608 18 8 1280 40 5120 20 9 1408 44 5632 22 10 1536 48 6144 24 11 1664 52 6656 26 12 1792 56 7168 28 13 1920 60 7680 30 14 2048 64 8192 32 15 Notes: The reu_size is used in byte 3 of the Header Block. As may seem logical, each sector uses 256 bytes of memory in the REU. To follow-on from the Commodore standard, tracks are numbered starting from 1 (1-64 for a 2048K REU), sectors are numbered starting from 0 (0-127). The mapping from track§or to memory is quite simple. Memory in the REU is address using a Bank (1 for each 64K) plus an offset (in the range 0- 65535). Since we access the data in 256 byte blocks (pages), we can ignore the lower 8 bits - and just calculate the page. reu_bank = (track - 1) / 2 (resulting in 0-31) reu_page = ((track - 1) & 1) * 128 + sector (resulting in 0-255) Anybody with assembler experience will notice that the calculation of bank and page can be reduced to a few shifts and logical-and operations. Throughout the rest of this document I'll write REU memory addresses in the following format: (bank:address) -> ($01:8000) is bank 1, address 32768. Like regular disks, DesTerm ramdisks contain a header block (sector), a BAM area and a directory area. The Header Block is track 1, sector 0 ($00:0000 - $00:00FF) The Bam (4 blocks) is at track 1, sectors 1-4 ($00:0100-$04FF) The Directory is at track 1, sector 4 ($00:0500 - $00:05FF) Regular disks allocate several directory sectors. The DesTerm Ramdisk only allocates directory sectors as they're needed. The location of the next directory sector can be found by following the track and sector identifiers found in the first two bytes. The Header Block BYTE VALUE DESCRIPTION 0 1 Track pointer to first directory sector 1 5 Sector pointer to first directory sector 2 77 ASCII `M' for format type 3 0 to 15 reu_size (number of 128K blocks) this value may also have the high bit set (+128) 4-143 0 unused 144-159 Disk name padded with shifted spaces 160 160 Shifted space 161-162 77 ASCII `M' for DOS version 162 68 ASCII `D for format type 163 160 Shifted space 164-255 0 unused The Bam The Ramdisk BAM is very similar to that of regular disks. Each bit in the BAM represents a sector. If a bit is `1', the corresponding sector is allocated, if its `0', then the sector is free. (If memory serves, this is backwards from the way normal disks use it). Since each track has 128 sectors, it takes 16 bytes to represent the BAM for a tracks worth of sectors. BYTE DESCRIPTION 0 Block Availability for sectors 0-7 1 Block Availability for sectors sectors 8-15 2 Block Availability for sectors sectors 16-23 3 Block Availability for sectors sectors 24-31 4 Block Availability for sectors sectors 32-39 5 Block Availability for sectors sectors 40-47 6 Block Availability for sectors sectors 48-55 7 Block Availability for sectors sectors 56-63 8 Block Availability for sectors sectors 64-71 9 Block Availability for sectors sectors 72-79 10 Block Availability for sectors sectors 80-87 11 Block Availability for sectors sectors 88-95 12 Block Availability for sectors sectors 96-103 13 Block Availability for sectors sectors 104-111 14 Block Availability for sectors sectors 112-119 15 Block Availability for sectors sectors 120-127 Notes: The lowest bit (LSB) in each byte indicates the status of the lowest sector covered by that byte. A binary value of 0 indicates that the sector is available, while a value of 1 indicates that the sector is allocated. Track 1, Sector 1 (BAM for tracks 1-16) $00-$0F track 1 $10-$1F track 2 $20-$2F track 3 $30-$3F track 4 $40-$4F track 5 $50-$5F track 6 $60-$6F track 7 $70-$7F track 8 $80-$8F track 9 $90-$9F track 10 $A0-$AF track 11 $B0-$BF track 12 $C0-$CF track 13 $D0-$DF track 14 $E0-$EF track 15 $F0-$FF track 16 Track 1, Sector 2 (BAM for tracks 17-32) $00-$0F track 17 $10-$1F track 18 $20-$2F track 19 $30-$3F track 20 $40-$4F track 21 $50-$5F track 22 $60-$6F track 23 $70-$7F track 24 $80-$8F track 25 $90-$9F track 26 $A0-$AF track 27 $B0-$BF track 28 $C0-$CF track 29 $D0-$DF track 30 $E0-$EF track 31 $F0-$FF track 32 Track 1, Sector 3 (BAM for tracks 33-48) $00-$0F track 33 $10-$1F track 34 $20-$2F track 35 $30-$3F track 36 $40-$4F track 37 $50-$5F track 38 $60-$6F track 39 $70-$7F track 40 $80-$8F track 41 $90-$9F track 42 $A0-$AF track 43 $B0-$BF track 44 $C0-$CF track 45 $D0-$DF track 46 $E0-$EF track 47 $F0-$FF track 48 Track 1, Sector 4 (BAM for tracks 49-64) $00-$0F track 49 $10-$1F track 50 $20-$2F track 51 $30-$3F track 52 $40-$4F track 53 $50-$5F track 54 $60-$6F track 55 $70-$7F track 56 $80-$8F track 57 $90-$9F track 58 $A0-$AF track 59 $B0-$BF track 60 $C0-$CF track 61 $D0-$DF track 62 $E0-$EF track 63 $F0-$FF track 64 Directory Block --------------- BYTE DESCRIPTION 0 Track pointer to next directory block (0 indicates last block) 1 Sector pointer to next directory block (255 indicates last block) 2-31 File Entry 1 (See Directory File Entry) 32-33 Two zeros 34-63 File Entry 2 (See Directory File Entry) 64-65 Two zeros 66-95 File Entry 3 (See Directory File Entry) 96-97 Two zeros 98-127 File Entry 4 (See Directory File Entry) 128-129 Two zeros 130-159 File Entry 5 (See Directory File Entry) 160-161 Two zeros 162-191 File Entry 6 (See Directory File Entry) 192-193 Two zeros 194-223 File Entry 7 (See Directory File Entry) 224-225 Two zeros 226-255 File Entry 8 (See Directory File Entry) Directory File Entry -------------------- BYTE VALUE DESCRIPTION 0 File type: 0 DEL (Deleted) 1 SEQ (Sequential) 2 PRG (Program) 3 USR (User) Note: Filetypes will be OR'ed with $80 when the file has been properly closed 1 Track pointer to first data block 2 Sector pointer to first data block 3-18 Filename padded with shifted spaces ($A0) 19-27 0 Unused 28 Number of blocks used by file (low byte) 29 Number of blocks used by file (high byte) Limitations ----------- The DesTerm ramdisk does not currently support REL files, Subpartitions or CMD style directories. Regular disks allow files to be `locked' the ramdisk does not. The rest -------- Pretty much the rest of the story is the same as that for real disks. The first two bytes of each data sector are pointers to the track and sector of the next block. If the track (byte 0) is 0, then this is the last block and the number in byte 1 is the number of bytes used in that block.