Amiga Machine Code Letter IV

Amiga Machine Code - Letter IV

We have reached Letter IV of the Amiga Machine Code course.

This letter was the toughest yet, and I think that it’s due to my obsession with details. The authors writes repeatedly that we have to gloss over the details, as an explaination will be given in later letters.

Btw. these scribblings are my own notes, so don’t expect that I will explain what’s already explained in the letters. But hopefully, I will shine some light on some of the more murky stuff.

The overall gist of this post is how to get graphics displayed on the screen. To do this we need to take a look at color registers, bitplanes and display resolution.

Color registers

The Amiga has 32 color registers, that represents red, green and blue colors using 4 bits for each.

Color register

This enables the Amiga to display (161616) = 4.096 colors. Pixels on the screen represents an index value into the color registers. Just how many color registers are addressable is determined by the number of bitplanes.

The color registers can be found in the custom chips register at $DFF180 - $DFF1BE, where they are named COLOR00 - COLOR31.

Bitplanes

A bitplane is a continues area of memory in chip-mem, where each pixel is represented by a single bit.

Using one bitplane gives us two index values into the color register, or two colors. Adding more bitplanes increases the number of color registers that we can address. E.g. using 4 bitplanes make it possible to address 16 color registers.

We can use up to 6 bitplanes in a display, which enable us to address all 32 color registers.

The index into the color register is determined using bitplane 0 as the least significant bit and bitplane 6 as the most significant bit.

Setting up the bitplanes are done through the bitplane control registers BPLCON1, BPLCON1, BPLCON2, and BPLCON3.

Display data is loaded into the graphics subsystem, by using BPLxPTH / BLPxPTL to give a pointer to the start of the bitplane in chip-mem. We must use two pointers to the high and low part of the memory address, since the custom chip registers are 16 bits, and a memory address is 24 bits.

Display Resolution

The Amiga can handle multiple display resolutions. Here shown for PAL.

Type Resolution Bitplanes Colors
LORES 320 * 256 1 - 6 2 - 64
HIGHRES 640 * 256 1 - 4 2 - 16
LORES-LACE 320 * 512 1 - 6 2 - 64
HIGRES-LACE 640 * 512 1 - 4 2 - 16
HAM 320 * 256 6 4.096
HAM-LACE 640 * 512 6 4.096

Display resolution is set by using the bitplane control registers above. By the way, HAM - Hold and Modify is a bit special. There’s a good video of the concept here.

Display Window Size and Position

The Amiga uses the two control registers DIWSTRT and DIWSTOP to set the upper left corner and lower right corner of the display window.

The start and stop values are given in lores coordinates, even if you choose a highres mode.

Manufactures of monitors and televisions created a delibrate overscan to ensure that the picture filled the screen. This overscan can be used by the Amiga, I guess for purposes like scrolling.

For PAL mode there are 312 lines available and we need to setup the display window to use 256 of these lines. Choosing more lines will make some of them end up in the non-visisble overscan area.

DIWSTRT Vertical postion

Type From To Default Overscan
LORES / HIGHRES $15 (21) $FF (255) $2C (44) $1C (28)

DIWSTRT Horizontal position

Type Default Overscan
LORES $81 (129) $71 (113)
HIGHRES $80 (128) $70 (112)

It’s a litte bit more tricky to set up DIWSTOP since the lower right corner will have values that are higher than what can fit in a byte. So there are some hardware tricks needed for PAL. This is very well explained in Letter IV

DIWSTOP Vertical postion

For PAL we need 256 lines, which gives $2C + $100 = $12C, which does not fit a byte. So a hardware trick is needed. For NTSC there is no problem, since it has 200 lines, so $2C + $C8 = $F4 will fit in a byte.

The PAL trick is to write the following two lines, which must follow each other.

move.w  #$f4c1, $dff090
move.w  #$38c1, $dff090  ; $F4 + $38 = $12C

DIWSTOP Horizontal position

For both PAL and NTSC modes there are in 320 pixels (LORES) on the screen. Since the horizontal position $81 + $140 = $1C1 is too big to fit in a byte, another hardware trick is used. The hardware will simply add $100 to the horizontal input, and thus we can set any value from $100 to $1FF by using only one byte.

Timing is everything

Up until now, we have only seen how to setup colors, bitplanes, display resolution and display window. We still need to consider how the display data is transfered to the graphics subsystem.

The transfer of graphics data, requires some finely tuned timing between the custom chips and the 68K using shared memory. This is also known as DMA time slot allocation, which we briefly looked on in Letter II and which we will revist in the next post.


Amiga Machine Code Course

Previous post: Amiga Machine Code Letter III - Branching

Next post: Amiga Machine Code Letter IV - DMA Revisited.

Mark Wrobel
Mark Wrobel
Team Lead, developer and mortgage expert