Difference between revisions of "Commodore Amiga"

From SizeCoding
Jump to: navigation, search
(6 intermediate revisions by the same user not shown)
Line 14: Line 14:
  
 
=== Amiga executable format ===
 
=== 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.  
Here's an example where deadc0de is the only code data. 0000 03f2 marks the end of the block.  
 
 
<syntaxhighlight lang="">
 
<syntaxhighlight lang="">
 
00000000: 0000 03f3 0000 0000 0000 0001 0000 0000   
 
00000000: 0000 03f3 0000 0000 0000 0001 0000 0000   
Line 21: Line 20:
 
00000020: dead c0de 0000 03f2  
 
00000020: dead c0de 0000 03f2  
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== Memory Map ===
 +
Here is the amiga memory map
 +
<gallery>
 +
Amiga_memorymap.png
 +
</gallery>
  
 
=== Video display ===
 
=== Video display ===
Line 26: Line 31:
  
 
==== Getting something on screen ====
 
==== 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.  
+
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 very slow in execution.
+
However, as can be expected these routines are extremely slow in execution.
  
 
<syntaxhighlight lang="">
 
<syntaxhighlight lang="">
Line 38: Line 43:
 
         move.l  $4.w,a6        ; execbase
 
         move.l  $4.w,a6        ; execbase
 
         move.l  156(a6),a6      ; graphics.library
 
         move.l  156(a6),a6      ; graphics.library
 +
 +
        ; clear screen
 +
        lea sc_RastPort(a5),a1
 +
        jsr _LVOClearScreen(a6)
  
 
frameloop:
 
frameloop:
 
move.w #240-1,d7 ; y
 
move.w #240-1,d7 ; y
 
yLoop:
 
yLoop:
move.w #320-1,d6 ; x
+
move.w #640-1,d6 ; x
 
xLoop:
 
xLoop:
 
+
; Set Pixel/Pen Color
; Putpixel
 
 
move.b d6,d0 ; d0=x
 
move.b d6,d0 ; d0=x
 
eor d7,d0         ; d0=x^y
 
eor d7,d0         ; d0=x^y
lsr.b #2,d0 ; d0>>=4
+
lsr #3,d0 ; d0>>=3
and #42,d0 ; d0&42
+
        jsr _LVOSetAPen(a6)
 
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
+
; Write Pixel
 +
move d6,d0
 +
move d7,d1
 +
jsr _LVOWritePixel(a6)
 +
dbra d6,xLoop
 
     dbra d7,yLoop
 
     dbra d7,yLoop
  
  ; Wait loop
+
   bra frameloop
   bra frameloop ; .s *
 
 
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 74: Line 78:
  
 
==== Setting a palette ====
 
==== Setting a palette ====
The Amiga OCS uses index values into a palette of colours.  
+
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.
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
 
  
 
<syntaxhighlight lang="">
 
<syntaxhighlight lang="">
pea paldata(pc)
+
lea sc_ViewPort(a5),a0
move.w #6,-(sp)
+
lea paldata(pc),a1
trap #14
+
moveq #16,d0
 +
jsr _LVOLoadRGB4(a6)
  
 
; Palette data
 
; Palette data
Line 89: Line 92:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
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).
+
Alternatively you can set individual palette entries either by using a graphics function or using the copperlist for setting initial colors
  
 
=== Sound ===
 
=== Sound ===
Line 106: Line 109:
 
* [http://amigadev.elowar.com/read/ADCD_2.1/Hardware_Manual_guide/node0000.html Hardware Manual Guide]
 
* [http://amigadev.elowar.com/read/ADCD_2.1/Hardware_Manual_guide/node0000.html Hardware Manual Guide]
 
* [https://www.markwrobel.dk/project/amigamachinecode/ Learning Amiga machine code]
 
* [https://www.markwrobel.dk/project/amigamachinecode/ Learning Amiga machine code]
 +
* [http://www.coppershade.org/articles/Code/Articles/ Coppershade articles]
 +
* [http://amiga-dev.wikidot.com/file-format:hunk#toc7 Amiga Header information]

Revision as of 16:34, 28 March 2024

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

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 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

Additional Resources