Coleco SmartBASIC V1.0

A Coleco ADAM Blog

Disk Interleaving


Data is stored on a tape in 256 blocks of 1024 (1kb) bytes each. There are 2 different ways the data is placed on the tape. For game tapes blocks 0 – 127 are stored on the front track, blocks 128 – 255 are stored on the back track. So to load a game tape the ADAM rewinds all the way to the beginning and then loads starting at block 0. Data tapes are arranged differently, blocks 64 – 127 then 0 – 63 are stored on the front track, then 128 – 255 is stored on the back track. This layout means that the ADAM will move to the middle of the tape to load block 0, the boot block, and that the directory starting at block 1 will always be at most 1/2 a tape away from current position you are on the tape versus on a game tape where the directory (if it has one) can be almost a full tape away from the current position. This is for EOS style tapes – CP/M (and TDOS) are a little different.

On a disk the data is stored differently. Each disk can hold 160kb of data (160 blocks) but is not stored linearly like a tape but broken down into 640, 256 byte sectors, numbered 0 – 639, that are then interleaved into 4kb chunks. This may sound confusing but it is not that hard to understand. Here is some SmartBASIC code that will show you how to interleave something:

100 REM Sector number 0 – 639
110 SECTOR = 52
120 REM Get which 4kb chunk
130 THIS4K = INT(SECTOR / 16)
140 REM Get the offset into the 4kb chunk
150 RAW = SECTOR – THIS4K * 16
160 REM Get the interleave for this sector
170 IF RAW = 0 THEN INTERLEAVE = 0
180 IF RAW = 1 THEN INTERLEAVE = 1
190 IF RAW = 2 THEN INTERLEAVE = 10
200 IF RAW = 3 THEN INTERLEAVE = 11
210 IF RAW = 4 THEN INTERLEAVE = 4
220 IF RAW = 5 THEN INTERLEAVE = 5
230 IF RAW = 6 THEN INTERLEAVE = 14
240 IF RAW = 7 THEN INTERLEAVE = 15
250 IF RAW = 8 THEN INTERLEAVE = 8
260 IF RAW = 9 THEN INTERLEAVE = 9
270 IF RAW = 10 THEN INTERLEAVE = 2
280 IF RAW = 11 THEN INTERLEAVE = 3
290 IF RAW = 12 THEN INTERLEAVE = 12
300 IF RAW = 13 THEN INTERLEAVE = 13
310 IF RAW = 14 THEN INTERLEAVE = 6
320 IF RAW = 15 THEN INTERLEAVE = 7
330 REM Now get the actual physical sector on the disk
400 ACTUAL = (THIS4K * 16) + INTERLEAVE

You will not need to use this since the disk drive will take care of this for you, if you want to load block 0 it will know to load in the sectors 0, 1, 10 and 11. For block 1 it will load in sectors 4,5,14,15 etc. But if you want to work with disk images then you will need to know how to work with the sector interleaving.

 


Categorized as: Hardware



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


© William "Milli" Hicks