Commodore Amiga
Contents
Commodore Amiga
The Commodore Amiga system consists of the M68k system with custom hardware for graphics and sound.
Setting up
- Assembler: VASM
- Emulator(s): Linux: fs-uae, Windows: WinUAE
Compile source to Amiga Kickstart1.x executable:
vasm -kick1hunks -Fhunkexe -o example -nosym
Amiga executable format
Commodore Amiga executables consist of a 32 byte header, as well as a 4 byte footer. Here's an example where deadc0de is the only code data. 0000 03f2 marks the end of the block.
00000000: 0000 03f3 0000 0000 0000 0001 0000 0000
00000010: 0000 0000 0000 0001 0000 03e9 0000 0001
00000020: dead c0de 0000 03f2
Memory Map
Here is the amiga memory map
Video display
The Amiga OCS uses an interleaved planar memory layout to represent its various paletted display modes.
Getting something on screen
One of the shortest ways to get you started with getting anything on screen at all, is to initialize and use the intuition graphics library routines. These are relatively easy to setup and allow you to plot pixels, circles, rects and even polygons. However, as can be expected these routines are extremely slow in execution.
incdir "include"
include "graphics/graphics_lib.i"
include "intuition/screens.i"
move.l $170(a2),a6 ; intuitionbase from globvec
move.l ib_ActiveScreen(a6),a5 ; a5 = activeScreen (640x240 on most systems)
move.l $4.w,a6 ; execbase
move.l 156(a6),a6 ; graphics.library
; clear screen
lea sc_RastPort(a5),a1
jsr _LVOClearScreen(a6)
frameloop:
move.w #240-1,d7 ; y
yLoop:
move.w #640-1,d6 ; x
xLoop:
; Set Pixel/Pen Color
move.b d6,d0 ; d0=x
eor d7,d0 ; d0=x^y
lsr #3,d0 ; d0>>=3
jsr _LVOSetAPen(a6)
; Write Pixel
move d6,d0
move d7,d1
jsr _LVOWritePixel(a6)
dbra d6,xLoop
dbra d7,yLoop
bra frameloop
Copperlist
Another way to start drawing things on screen is to setup a (minimal) copperlist with commands for one or more planes, which can be manipulated indiviually
Copper list format:
To be added
As it happens, you can also insert color definition into the copperlist.
Planes
Every plane contains one bit of a pixel's colour index value. The bits of the binary representation of a colour index like %1010 (% Bit3,Bit2,Bit1,Bit0) will end up in 6 different planes (bits most significant to least significant aka left to right): Plane4 Plane3 Plane2 Plane1.
So basicly Plane1 contains all of the Bit0s of all pixels, Plane2 all Bit1s, Plane3 all Bit2s and Plane4 all Bit3s.
The first pixel on a plane is described by the leftmost (aka most significant) bit in a word, the second one by the second-leftmost etc. - just like this %0123456789abcdef with 0-f=pixels 1-16. %1000000000000000=$8000=pixel 1 in a plane word set. The 16th pixel will use the leftmost bit of the next word in this plane. etc.
Drawing pixels
Here are some examples for drawing pixels in 1 or more bitplanes:
1-bpp pixel plot
To be added
2-bpp pixel plot
To be added
Setting a palette
The Amiga OCS uses index values into a palette of colours. Palette format is a word per index with 3 nibbles for 4-bit RGB (e.g. $00f for blue). Here is some code that will help you setup an entire palette at once using the intuition graphics routine.
lea sc_ViewPort(a5),a0
lea paldata(pc),a1
moveq #16,d0
jsr _LVOLoadRGB4(a6)
; Palette data
paldata:
dc.w $000,$100,$200,$311,$422,$533,$644,$755
dc.w $575,$464,$353,$242,$131,$020,$010,$000
Alternatively you can set individual palette entries either by using a graphics function or using the copperlist for setting initial colors
Sound
To be added
Make some noise
So, here is a bit of sound code that outputs some sounds to the PCM output
To be added