The source compiles with Watcom V11.0


Some quick words about how the program works conceptually.
So far documented is the event loop which is the heart of
the emulator.

Event-loop:
-----------

The file busa.asm contains a loop that executes events.
Each event has a cycle-number which says when the event happens.

The seven events are:

Cpu-instruction
Copper-instruction
End of line
Cia event (forks out to second-level events within Cia)
Blitter finished
Interrupt
End of frame

The event loop first executes one cpu-instruction, then
it executes other events until it is time to execute another
cpu-instruction.


Cpu-event:
----------

Calls the routine which emulates the next instruction and then
updates the cycle-time for the next instruction.
Files used for cpu-emulation are 68000.asm, 68000ini.c 68030..etc.


Copper-instruction:
-------------------

Calls copemu routine which is located in coppera.asm
Copper emulation is quite simple, it executes the next
copper-instruction, updates the state of the copper and then
determines the time for the next copper-instruction.


End of line:
------------

Called with 228 cycle-intervals, at the end of every virtual
raster-line.  A lot of tasks are collected in the end of line handler.
Then the cycle-time for this event is updated so that the routine is 
called again at the end of the next line.

The routine is located in busa.asm

The end of line handler has 4 tasks:

Graphics-output:

Several routines in graphema.asm and drawa.asm is called to determines
what is happening on the screen on the line, calculates what it looks 
like and draws the line in the framebuffer.

Sound-output:

Calls routine in sounda.asm which runs the audio-state machine for
each channel as many times as needed to bring the audio-emulation 
up to date.  If this process produced any samples, a routine is called
in the sound-card driver to copy the samples a output-buffer.

Disk-DMA:

Copy floppy-data into the Amiga memory, usually a couple of
words for each line. Routine called in file floppy.c if disk-dma
is started.

Keyboard:

Determines if it is time to make a scancode available to
the Amiga.  Macro in include\asm\mac\keyboard.mac
Consumes data from a queue filled by the (PC) keyboard 
handler in keyboard.c


Cia:
----

Cia emulation is located in cianew.c
It is a collection of several events, Timer A and B in both Cias,
and Alarm in one (the one that counts eols).
The time for a cia-event is updated whenever the timers are changed,
or after an Cia-event has been executed.


Blitter:
--------

Whenever a blit is started, the time when the blit will be finished
is calculated and the time for the Blitter Finished event will be
updated.  Nothing actually happens to the blitter when the BLTSIZE
register is written.  The emulation goes on until the associated
Blitter Finished event comes up in the event-loop.

Then the finish_blit routine is called in blita.asm and the entire blit
is performed in one go.

 
Interrupt:
----------

Whenever an interrupt is signaled by other emulated units, the
interrupt event will be activated.  Since interrupts spend some
time in never-never land before they actually occur, the actual
cycle-time of the irq is calculated.
Emulation then goes on for a while until the interrupt event comes up
in the event-loop, which causes a routine in 68000.asm to be called.
The routine sets up the cpu-emulation to handle the irq (some stack
saving, switch to supervisor etc.)


End of Frame:
-------------

This event happens at the end of every virtual frame. (71364 cycle
intervals).  Much happens in the end of frame handler:
The routine is in busa.asm

Frame handling:

-Switch buffer and reset emulated graphics to draw a new frame.
-Draw "performance" symbol.
-Perform screen-centering keypresses and BMP-dump from PC-keyboard handler.

(in graphema.asm, draw.asm, inout.c)

Copper:

-Reset copper. (in coppera.asm)

Sound:

-Every 5th frame, call routine in sound-card driver to play samples
 accumulated in the buffer.

Irq:

-Generate a couple of rare interrupts if needed (Index and dsksync.)

Events:

-Subtract cycles for this frame from all active events, so the cycle-times
 refer to the start of the current frame.

Joystick:

-At regular intervals, poll the state of the analog joystick.
 (in joymouse.c)

Keypresses:

-Check if the user pressed F12 to exit, or if the user pressed
 CTRL-AMIGA-AMIGA to reset the emulated Amiga.



Well, that was a quick top-down view of the emulator design.
I'll see if I can make it more detailed later.

 

