68000 Assembly programming for the Atari ST

The Atari ST completely passed me by in the 80's... While it has the same CPU as the Amiga, it has inferior graphics and sound , with no hardware graphics layers, and only AY sound...

These days the ST has one major advantage... it's much easier to emulate! Often getting Amiga games working requires messing with different configurations, whereas the Atari ST version will run instantly and while usually has inferior sound, will otherwise typically be identical to the Amiga version!

Specs:
Cpu 8mhz
Ram 512k
Resolution 320x200 @ 16 colorr
Palette 16 colors onscreen from 512 colors
Sound chip AY



Memory Map

Address Purpose
000000 512k ram
07FFFF
FA0000 128K Rom
FC0000 System Rom
FEFFF
FF8000 Io Area
FF8200 Io Area
FF8400 Io Area
FF8600 Io Area
FF8800 Io Area SOUND AY-3-8910
FFFA00 Io Area MFP 68901
FFFC00 Io Area 2 ACIA:s 6580

Registers

Address Mode Bits Purpose
FF8004 RW ----xxxx Memory Config
FF8201 RW HHHHHHHH Video Base H
FF8202 EW LLLLLLLL Video Base L
FF8205 R HHHHHHHH Video Counter H
FF8207 R MMMMMMMM Video Counter M
FF8209 R LLLLLLLL Video Counter L
FF820A RW ------SR Sync Mode
FF8240 RW -----RRR -GGG-BBB Palette Color 0
FF8242 RW -----RRR -GGG-BBB Palette Color 1
FF8244 RW -----RRR -GGG-BBB Palette Color 2
FF8246 RW -----RRR -GGG-BBB Palette Color 3
FF8248 RW -----RRR -GGG-BBB Palette Color 4
FF824A RW -----RRR -GGG-BBB Palette Color 5
FF824C RW -----RRR -GGG-BBB Palette Color 6
FF824E RW -----RRR -GGG-BBB Palette Color 7
FF8250 RW -----RRR -GGG-BBB Palette Color 8
FF8252 RW -----RRR -GGG-BBB Palette Color 9
FF8254 RW -----RRR -GGG-BBB Palette Color 10
FF8256 RW -----RRR -GGG-BBB Palette Color 11
FF8258 RW -----RRR -GGG-BBB Palette Color 12
FF825A RW -----RRR -GGG-BBB Palette Color 13
FF825C RW -----RRR -GGG-BBB Palette Color 14
FF825E RW -----RRR -GGG-BBB Palette Color 15
FF8260 RW ------SS Screen Mode (00=320x240x4bpp)
FF8400

Reserved
FF8600

Reserved
FF8602

Reserved
FF8604
-------- XXXXXXXX Disk controler data access
FF8606 R -------- -----DSE DMA Status Mode control
FF8606 W -------W FD0RGAB DMA Mode Control
FF8609 RW HHHHHHHH Dna Base & Counter H
FF860B RW MMMMMMMM Dna Base & Counter M
FF860D RW LLLLLLLL Dna Base & Counter L
FF8800 R DDDDDDDD IO Port B Data
FF8800 W RRRRRRRR PSG Register Select
FF8802 W RGCDRFGH PSG Write Data – IO Port A
FF8802 RW DDDDDDDD IO Port B Data
FFFA01
M-IW---P MFP GP IO
FFFA03
DDDDDDDD MFP Active Edge
FFFA05
DDDDDDDD MFP Data Direction
FFFA07
DDDDDDDD MFP Interrupt Enable A
FFFA09
DDDDDDDD MFP Interrupt Enable B
FFFA0B
DDDDDDDD MFP Interrupt Pending A
FFFA0D
DDDDDDDD MFP Interrupt Pending B
FFFA0F
DDDDDDDD MFP Interrupt Interrupt In Service A
FFFA11
DDDDDDDD MFP Interrupt Interrupt In Service B
FFFA13
DDDDDDDD MFP Interrupt Mask A
FFFA15
DDDDDDDD MFP Interrupt Mask B
FFFA17
DDDDDDDD MFP Vector Base
FFFA19
DDDDDDDD MFP Timer A Control
FFFA1B
DDDDDDDD MFP Timer B Control
FFFA1D
DDDDDDDD MFP Timers C & D Control
FFFA1F
DDDDDDDD MFP Timer A data
FFFA21
DDDDDDDD MFP Timer B data
FFFA23
DDDDDDDD MFP Timer C data
FFFA25
DDDDDDDD MFP Timer D data
FFFA27
DDDDDDDD MFP Sync Character
FFFA29
DDDDDDDD MFP USART control reg
FFFA2B
DDDDDDDD MFP receiver status
FFFA2D
DDDDDDDD MFP Transmitter status
FFFA2F
DDDDDDDD MFP USART Data
FFFC00
DDDDDDDD Keyboard ACIA Control
FFFC02
DDDDDDDD Keyboard Data
FFFC04
DDDDDDDD Midi ACIA Control
FFFC06
DDDDDDDD Midi Data


Joystick reading

I'm not a fan of using the firmware for doing things, but I can't find any other way to read the joysick on the Atari ST

The Atari ST joystick is connected as part of the keyboard... to read it we have to install a Joystick event interrupt handler...

Shown to the right is the simplest joystick handler I have working...
we store the two joystick bytes to a temporary variable called "Joydata"
    move.w    #$14,-(sp)    ;IKBD command $14 - set joystick event reporting
    move.w    #4,-(sp)    ;Device no 4 (keyboard - Joystick is part of keyboard)
    move.w    #3,-(sp)    ;Bconout (send cmd to keyboard)
    trap    #13            ;BIOS Trap
    addq.l     #6,sp        ;Fix the stack

    move.w  #34,-(sp)    ;return IKBD vector table (KBDVBASE)
    trap      #14            ;XBIOS trap
    addq.l  #2,sp         ;Fix the stack
   
    move.l  d0,ikbd_vec     ; store IKBD vectors address for later
    move.l  d0,a0              ; A0 points to IKBD vectors
    move.l  24(a0),old_joy     ; backup old joystick vector so we can restore it
    move.l  #JoystickHandler,24(a0); Set our Joystick Handler
    rts
   
JoystickHandler:
    move.b  (1,a0),joydata          ; store joy 0 data
    move.b  (2,a0),joydata+1     ; store joy 1 data
    rts 

ikbd_vec:    dc.l 0             ; old IKBD vector storage
old_joy:    dc.l 0            ; old joy vector storage
joydata:    ds.b 2            ;Joypad bytes F----RLDU

AY Sound Chip:
Register Meaning Bit Meaning Details
0 Tone Pitch L - Channel A LLLLLLLL Lower value = Higher pitch
1 Tone Pitch H - Channel A ----HHHH Lower value = Higher pitch
2 Tone Pitch L - Channel B LLLLLLLL Lower value = Higher pitch
3 Tone Pitch H - Channel B ----HHHH Lower value = Higher pitch
4 Tone Pitch L - Channel C LLLLLLLL Lower value = Higher pitch
5 Tone Pitch H - Channel C ----HHHH Lower value = Higher pitch
6 Noise Generator ---NNNNN Higer = Faster noise
7 Mixer  --NNNTTT   N=Noise T=Tone (Channel --CBACBA 1=mute 0=normal)
8 Amplitude - Channel A ---EVVVV E=Envelope (1=Enabled) VVVV=Volume
9 Amplitude - Channel B ---EVVVV E=Envelope (1=Enabled) VVVV=Volume
10 Amplitude - Channel C ---EVVVV E=Envelope (1=Enabled) VVVV=Volume
11 Envelope L (Volume over time)  LLLLLLLL Lower=Faster Envelope
12 Envelope H (Volume over time)  HHHHHHHH Lower=Faster Envelope
13 Envelope Selection ----EEEE Envelope number (See PDF)
For more details, please see the AY sound chip PDF



Learn Assembly for the Greatest Classic Processors:  Z80 - 6502 - 68000
Visit www.ChibiAkumas.com to get my games and their source code! | Support me on patreon