- SEPTiC DEMO'S COLLEGE -- 

                                  Lesson 9 
                                  ????????? 
                         Written by Vicious / Septic 

                                  Oct 21 93 



                                  Introduction 
                                  ????????? 
After a short break we go now started with a few assembler - 
lessons. This time I thought, to raise a fairly well-known thing 
usually occur in all demos with a little style, namely track charge! 


                                    Theory 
                                    ????? 
When you save a file in, for example, Deluxe Paint, you do not think much of 
what is actually happening. The file just saved on the disk so that you can download 
it again when you need it. What is happening is that AmigaDos 
see if there is one vacancy on the disk and then saving the file 
sector by sector on the disk, plus the update a file list so that the 
can find the file the next time we will load it. 
   This is done so to speak, invisible to us by AmigaDos, and we need 
does not really bother us so much about it. 
   As a coder may, however, think AmigaDos is pretty tough. We must 
CODA very system-friendly if you're going to be able to use AmigaDos in his demo, 
and download section by section from a floppy disk, and that CODA-friendly system should we 
:-) to avoid it so much tougher ... 
   Using AmigaDos file system is also the disadvantage that everyone can look 
on the files you have on the disk. On a track loaded floppy disk, this is very 
more difficult, especially for hackers who can not trackloading. 
   So can skip AmigaDos file system and simply save their files 
for instance, and also charge them by hand. 
   In a separate track loader save their files on the disk directly on 
sectors, and then must keep track of where you saved the file so that 
you can download it again. 
   Maybe I should mention it to a floppy disk is made up of 80 cylinders. 
Each cylinder has a track on the top and one on the bottom, then 160 
tracks total. Each track is composed of 11 sectors and each sector is 
512 bytes. A floppy disk has space for 160 tracks multiplied by 11 
sectors multiplied with 512 bytes (160 * 11 * 512) = 901120 bytes! 
   The first two sectors always include a boot block. Boot block is the 
to boot disk (if it is bootable, of course) and therefore we must 
also take a look at how the construction of a loader in the boot block. 

There are two types of track charge. DOS and Hardware. DOS is the simple 
method. HARDWARE is the difficult, but most used today because the 
deemed to be cooler. I was going to go through both methods because the two 
has advantages and disadvantages. 


                                  Register 
                                  ???????? 
For dose-trackloading there is no need to use any records at all (it is 
precisely why it's called denial-of-trackloading) but only a library 
feature that loads from the disk. 
   However, you need to use some new things at HW-trackloading 
(HW = Hardware), which I explain now ... 
   Firstly, we look at Amigans timers. A timer is a counter 
which only has the task of counting from a certain specified numbers down 
to zero. What a BRAIN DEATH task, you might think, but these timers are 
very useful when you have to wait a certain period of less than 
one front, ie 1 / 50 second. Previously we have made use of 
screen beam to wait a certain period of time, namely a frame, but when 
Monday track loads, you need sometimes to wait only a few milliseconds, and then 
a timer in good stead. 
   Now I must also point out - because there's always somebody well as protest 
and says it is too hard to use timers - that will ABSOLUT 
do not wait a certain period of time by using the loop-command DBF! This 
may seem smooth, and works well on your own computer, but so 
philosopher was all coders for two or three years ago and further back. It is 
also why none of their demos work on the A1200 today, for example, for 
their trackloaders waiting with DBF loops that go much faster in 1200: an. 
   Okay, I said there are several timers. When the system is running so 
they are used, inter alia, to shake hands with the keyboard at certain 
dates, exec task switching and Interrupt. 
   When we track loads, however, we have tossed out the system, so when it does not 
Whether we plundered us a timer and use it to our timing 
track loader. 
   A timer can work in slightly different ways. The example can count down to 
zero, generate an interrupt, and then bring their original value again and 
renaissance count down to zero. Or it can count down once and then 
stay, and it is the method we should use. 
   In my track loader, I have chosen to use CIAB Timer A. We should look at 
how easy it is built. 
   First and foremost, we have a check register, CIAB Control Register A 
($ BFDE00). It looks like this: 

BIT NAME FUNCTION 
--- ---- -------- 
  0 START 1 = Start Timer A, 0 = Stop Timer A 
                     (This bit is reset automatically when the timer reached 
                      zero in One-Shot mode) 
  1 PBON 1 = A timer output to PB6, 0 = normal PB6 
  2 OUTMODE 1 = Toggle, 0 = Pulse 
  3 RUNMODE 1 = One-Shot mode, 0 = continuo fashion 
  4 LOAD 1 = Force load (Strobe bit, forcing the timer to start 
                     bill) 
  5 INMODE 1 = A timer counting Positive CNT transitions 
                     0 = A timer counts 02 pulses 
  6 SPMODE 1 = Serial port becomes output, 0 = Serial port are fed 
  7 UNUSED Not used. 

Then, it must also record the value of timer to count down from. The 
for the man in the CIAB Timer A lo byte ($ BFD400) and hi byte ($ BFD500). Then 
it just to test bit 0 in the control register to see when the timer is 
completed. 
   I will not go into detail on how these timers work. It is 
explained in detail in the hardware manual, so get it if you are interested. 

To make a HW-track loader is a really mandomsprov for a coder. Here 
we must manage disk drive at the very lowest level, that move read / write 
head manually, change the disk side depending on which track you read on, read 
data from the disk using any hardware register and then Decode 
data to the format we saved in. 
   To begin with, we have no records to govern lashuvudet and it is 
CIAAPRA ($ BFE001) and CIAAPRB ($ BFD100). CIAAPRA we know among other things again 
to Reading of the mouse button there, but there are some pieces that are 
interesting at HW-trackloading. Here's the interesting bits: 

BIT NAME FUNCTION 
--- ---- -------- 
  2 DSKCHANGE Becomes 0 when a disk is taken from the drive. 
  3 DSKPROT disk is write-protected = 0. 
  4 DSKTRACK0 Is zero when lashuvudet are on track 0. 
  5 DSKREADY Disk ready. Zero when the drive motor rotates with the full 
                     speed and drive is ready to receive commands. 

In CIAAPRB, we only interesting bits! See here: 

BIT NAME FUNCTION 
--- ---- -------- 
  0 DSKSTEP Moves read / write heads of disk drive. The signal must 
                     given as a rapid pulse, 1, then 0 of 3 milliseconds 
                     and then 1 again. (When you change direction, we must wait 
                     in less than 18 milliseconds before continuing.) 
  1 DSKDIREC Specify the direction that drive head must go. A 
                     zero indicates the direction inwards towards the center of the disk, a 
                     one indicating outwards. 
  2 DSKSIDE Determines the page on disk, we should read. A zero 
                     means the top, and a studio is the bottom. All 
                     periodically tracks are on the bottom and the odd-on 
                     top side. (Must be stable for at least 100 microseconds 
                     before you write to the disk.) 
  3 DSKSEL0 Select drive 0. 
  4 DSKSEL1 Drive 1. 
  5 DSKSEL2 Drive 2. 
  6 DSKSEL3 Drive 3. 
  7 DSKMOTOR Disk motor control. Used to turn on the disk engine 
                     on the drive selected. It involves the first 
                     the disk drive, then clears DSKMOTOR bit, waiting 
                     cards and then clear the disk drive-bitten on the drives the 
                     chosen. 

There we have everything we need to steer diskdrivens read and write head. 
It was probably not so bad? 
   Now we can look forward to the hardware registers in charge of literacy and 
Writing from disk. What they really control is DISK DMA, specially made 
to read and write from disk. 
   We can start by checking the registry ADKCON, which stands for Audio Disk 
Control, and which indeed contains bits to check sound 
and disk. We are going to look only at the disk-bits: 

BIT NAME FUNCTION 
--- ---- -------- 
15 SET / CLR Turns or scavenge bits that are contested. (Just in 
                     DMACon, BPLCon etc ...) 
14-13 PRECOMP 0-1 00 No prekompensation 
                     01 140 nano-second prekompensation 
                     10 280 "" "" 
                     11 560 "" "" 
12 MFMPREC 0 = GCR Precompensation (Group CODED Recording) 
                     1 = MFM Precompensation (Normal) 
10 WORDSYNC A studio allows synchronisering with DSKSYNC-Register 
09 MSBSYNC A studio allows synchronisering of the most 
                     significant piece of read data (used most often in the GCR) 
08 SET A one indicates 2 microseconds per bit cell (MFM) 
                     Nobody delivers 4 microseconds (GCR) 

Furthermore, we have a record called DSKLEN ($ DFF024). It gives the disk DMA 
the data length in words. Bit 15 states, however, on Disk DMA and bit 14 indicates if the data 
to read (0) or written (1), so it is the only piece 0-13 showing 
length. The tricky is that you must write TWO times to the present 
address to execute it. 
   In DSKPT ($ DFF020) says in the disk-pointing-destination as a 
long word, therefore, was in memory of the MFM-coded rawdatan to read. Must be 
to CHIP mem. 
   In DSKSYNC ($ DFF07E) we write the disk sync-value, which typically 
Usually century $ 4489! 
   The intensity ($ DFF01C), there is also a bit Interrupt set when an 
disk blocks read. I use it to check for disk DMA: n is complete. 
   That's right, forget about everything in the world not to turn on DISK DMA piece in the 
DMACON too! 
   So far, so good, but now is the snag that all the data we read is encoded into 
in a special way, called MFM encoding. There is every bit two bits 
instead, which is as follows: A 1 is always 01. An 0 is 10 on 
previous also was zero, otherwise it is 00. 

   There, that was all it needed for HW-track charge. 

Now, I go through the dose-track charging a little easy. Since libraries 
is not my strong suit, it might be a little krystat and difficult to explain now, but 
You can read more about these library functions in Rome Kernel Reference 
Manual. 
   We will therefore use us out of a device called Trackdisk.device for 
to load from disk. 
   First we must create an IO Request blocks we should make use out of 
to load. Block should be 20 words long, or 80 bytes. 
   We then use AddPort and create a port that we bring in 
IO request. Then, we open trackdisk.device. 
   After that we can enter a command to the IO request on the 28th 
changes. Here is a list of commands: 

Number Command Performance 
------ -------- -------- 
    2 Read read from the disk 
    3 Write Write to disk 
    4 Update Update written data to disk 
    5 Clear Clear tracks 
    9 Motor Turn on or off the disk engine 
   10 Seek Move write head to a special track 
   11 Format formats tracks 
   13 ChgNum Look how many times the disk had a change of drive 
   14 ChgState Is anybody disk in the drive? 
   15 Prot Prime Check if the disk is write protected 

I thought not go in so closely on the various commands. We just come 
remember that the command READ (# 2) requires the length in bytes 36 of IO-request; 
destination in bytes 40 and ethylene offs in the current 44. The length and offset must 
be even multiples of 512, therefore, we must enter it as SECTOR * 512. 
If you want to read fifteen sectors starting at sector three, it will offs ethylene 
3 * 512 and the length 15 * 512. The destination must be in chipmem. 
   Then you only jumps to the exec function DoIO (-456). 
   When designing the boot block, it is customary to use a 
dose-track loader that loads into the real loader, as HW-trackloaders 
tends to be quite large. The boot block, however, it is quite smooth with 
dose-loaders, because it may be a pointer to a fordefinerad IO-structure in 
A1, which is easy to use. So, you need only type in length, 
offset and destination and then loaded MAIN-load up. 


                               Program examples 
                               ??????????????? 
Today we have many exciting programs to look at. An example of a boot - 
blocks of a dostrackloader, an ordinary dosloader and a HW-track loader. 
   The program is a dostrackloader. It uses out of the system 
load-track procedures, and therefore, the system must be intact when running it. 
Using that kind of routine in a demo can not turn off the system 
and then we can not use the entire memory. 
   The program is not so difficult to understand. It reads simply a given 
number of sectors from a certain position on the disk (measured in sectors) to a 
address in memory. 
   The next program, Lekt9b.s, is basically the same program, though it is redesigned 
to be in a boot block. When you start a program from 
boot block to get a IO-structure ready for use in the register A1. 
Therefore there is no need to allocate one yourself and then of course the program rather 
small and smooth. Since the program was written to serve only 
from the boot block, you can not run the normal way in assembler, but you 
must save it to disk and then boot from the disk. What you should do is 
explained in the beginning. 
   The program makes no real benefit. It reads only a few sectors from 
the disk to demonstrate how to do, and then it goes into a perpetual loop 
which can only be reset by fracturing. 

The last program is a complete hardware track loader. The working alone 
with the tracks, not sectors, therefore, so each reading means 5632 bytes. 
   The program is fairly extensively commented so you can read there how the 
the whole works. 

Now you may wonder how to save their works on a floppy disk so that it 
can use trackloading ago. Yes, it is quite simple, although one would have to 
keep track of some figures that may have to write down on paper. 
First and foremost to boot block always be on sector 0 and 1 so there can be 
we do not save anything. In contrast to the sector 2 onwards are all free. If we now 
To store such as a great track, which is 95,789 bytes large, we must first 
count up how many sectors it raises. Where are we just so that we 
dividing the length of 512, thus 95789/512 and then we 187.09 sectors. 
We can only work with entire sectors and we see that we need a little more than 
187 sectors, so then we save the 188 sectors for the whole file to 
come up with. 
   In ASMONAS can then do the following to save the file. Write a short 
program that looks like this: 

    section data, data_c 
s: incbin 'lat-path/latens-namn' 

Assemblera late this and stop late in the disk you want to save the song on the DF0: 
(disk may not include some important AmigaDOS files! These will then 
cases to be destroyed!) 
   Now, enter the WS Write Sector and indicates that S RAM ptr, because it 
is where our song is in memory. Then we would start to save on the sector 2, 
and therefore, we also 2 on the question of DISK ptr. Then we write the length 
188 and then it was clear. Now save the song on the sector 2 to 190 and it is 
Now we need some paper and pencil to write up those numbers. 
Or maybe it saves the song over the next time you will save another file 
on the disk. 
   Hardware Trackloadern works only with whole tracks, as I said, and would 
we use it in our demo instead, we should do a little different. We take 
out the number of tracks instead of the number of sectors, and it is done by 
to file length alone by 11 * 512 (because there are 11 sectors on each track). 
So 95789/5632 and it becomes 17.01. We need a little more than 17 
tracks, and then there is obviously 18 tracks. 
   Now we use the command WT (Write Tracks) instead of WS, and indicates 
all lengths and ether offs in the tracks. We therefore begin saving on Track 1 
instead of sector 2, and the length will be 18 instead of 188. 
   So, now I hope you can make really cool trackmos after this! 
