Atari ST

From SizeCoding
Revision as of 16:06, 19 June 2022 by Superogue (talk | contribs)

Jump to: navigation, search

Atari ST

The Atari ST systems consists of the M68k system with custom hardware for graphics and sound.

Setting up

Setting up your development platform for the Atari ST systems is quite easy, first get the following tools:

  • Assembler: VASM - This assembler is able to assemble directly to a TOS executable
  • Assembler: RMAC - Can assemble to TOS executable as well as a headerless absolute binary
  • Emulator(s): Hatari Make sure to use the original TOS 1.62 Image for best compatibility.

Compiling to a TOS image

Vasm -Ftos source.s -o source.tos
rmac -p -o source.tos source.s

ST executable format, and why you should write relocatable code

To be added

Video display

The Atari ST uses an interleaved planar memory layout to represent its paletted display modes. 320x200 w/ 16 colors is called Lowres and is used most of the time. It is also possible to use either midres mode (640x200 w/ 4 colors) or hires mode (640x400 w/ 2 colors)

Setting a palette

The Atari ST uses index values into a palette of colours. Index 0 is the background colour (that's also used for the border) and a maximum of 16 colours can be defined and indexed.

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

Getting something on screen

One of the shortest ways to get you started with getting anything on screen at all, is to use the built-in Line-A routines. These are relatively easy to setup and allow you to plot pixels, hlines, lines, rects and even polygons. However, as can be expected these routines are very slow in execution.

	; Line-A Initialization
        ; After calling this function, data register D0 and address register A0 point to a table ; with the starting address of the Line A variables. 
        ; Address register A1 points to a table with the starting addresses for the three system ; font headers, 
        ; and address register A2 points to a table that specifies the starting addresses of the; 15 Line A opcodes. There's no parameter required for this function, so all you have
        ; to do is call the word opcode label that you specified for the $A000 (Initialize)
        ; function.
	dc.w	$A000
	movem.l	(a0),a1-a4		; A3=INTIN, A4=PTSIN
	move.w	#200-1,d7		; y
	move.w	#320-1,d6		; x

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


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 4 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 Plabe4 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.


16 pixels worth of data are represented as a full graphicword, meaning all information to display 16 pixels are stored together, followed by the data to represent the next 16 pixels etc. One row worth of display data has 20 graphicwords (20*16 pixels=320 pixels).

16 pixels are stored in 4 words - which contain 4 of the aforementioned planes.

So a 320x200x16 colour display is a contiuous memory buffer containing:

Pixels 0-15, row 0:(Plane1.w Plane2.w Plane3.w Plane4.w)
Pixels 16-31, row 0:(Plane1.w Plane2.w Plane3.w Plane4.w)
Pixels 32-47, row 0:(Plane1.w Plane2.w Plane3.w Plane4.w)
Pixels 304-319, row 199:(Plane1.w Plane2.w Plane3.w Plane4.w)

(To be refined in the future)


The Atari ST systems use the YM2149 chip to generate sound.

For more information check out

Make some noise

The Atari YM sound registers are located at address: $ffff8800

So, here is a bit of sound code that outputs some noise to the YM registers (assuming your ym register values in ymdata)

	lea	$ffff8800.w,a0							; ym reg
	lea	.ymdata(pc),a1							; load data
	move.w	(a1)+,d0							; first val
	movep.w	d0,0(a0)							; write data to ym chip
	move.w	(a1)+,d0							; get next value
	bne.s	.ymloop

Additional Resources

Sizecoding on the Atari ST is not very huge yet, so resources are sparse.

The Atari Compendium Writeup to porting of Mona to the Atari ST

Here are some tiny intros with source code:

Prod name (Pouet link) Source code
128b Palette Starfield by Gaston
Fractal Landscape bootsector by Gaston
BIG scroller by NoCrew
128byte drum machine by gwEm
128byte Theremin by gwEm
128byte virtual 303 by gwEm
88 Bytes by Sedma
Realtime Competition by Mystic Bytes
The Bootshitctor by KÜA software productionsÜA%20software%20productions/boot
BOOT MY PIGGY GAME by Lineout & KÜA software productionsÜA%20software%20productions/piggy
Keeping atari alive by D-Bug
dla by Positivity
quadratic splines by Positivity
TT-Noise by KÜA software productionsÜA%20software%20productions/ttnoise
Random Cell by Positivity
128 byte Choonage by Psycho Hacking Force
ShowMem by Positivity
Benoît by Orb
1 euro by Lineout & KÜA software productions & Psycho Hacking ForceÜA%20software%20productions/BIER/source
Έτη πολλα! by KÜA software productionsÜA%20software%20productions/etipolla
Sync128b by Dyno
128B Mandelbrot Set by Dyno
64B Sierpinski Scroller by Dyno
32B Sierpinski Triangles by Dyno
32B Noise by Dyno
Fractal 128 by Orion_
ImPerfect by Satantronic
tunnelST by atariBDSM
Blues by tr1x
Shades by tr1x
Wobble by Gash
MindBender by Defence Force Force/MindBender

And some for the Atari Falcon

Prod name (pouet link) Source code
NoBrains Mandelbrot Zoomer 128 by NoCrew
128 bytes Plasma demo by NoCrew
128 bytes Pyro demo by NoCrew
128 bytes Sierspinksi by NoCrew
128 TRON[ by T.O.Y.S.]
Strange Things Happends In Sweden by Mind Design
Mixed Dots 128 by NoCrew
Realtime Competition Falcon by Sedma