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
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
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, ellipses, rects and even polygons. However, as can be expected these routines are very 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
frameloop:
move.w #240-1,d7 ; y
yLoop:
move.w #320-1,d6 ; x
xLoop:
; Putpixel
move.b d6,d0 ; d0=x
eor d7,d0 ; d0=x^y
lsr.b #2,d0 ; d0>>=4
and #42,d0 ; d0&42
move.w d0,(a3) ; a3=color(d0)
movem.w d6/d7,(a4) ; a4=x,y`
dc.w $A001 ; put pixel command
dbra d6,xLoop ; decrease and branch
dbra d7,yLoop
; Wait loop
bra frameloop ; .s *
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.
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 trap #14function
pea paldata(pc)
move.w #6,-(sp)
trap #14
; 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 trap function or writing to the palette color address directly (starting at address $ffff8240).
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