Game Link II sample code

 

From jdpotter@xxxxxxxxxxxxxx.net Mon Sep 29 18:32:15 1997
Date: Mon, 29 Sep 1997 21:30:16 -0400
From: Jeff Potter
Newsgroups: comp.sys.atari.8bit
Subject: Game Link II sample code

Okay. It took a while to remember some of the little tricks in writing
SIO bus interrupt handlers (like remember your interrupt routine is
called *after* a PHA instruction has been performed). Here is actual
Action source code for a really simple application. It reads the
joystick and sends out a word which affects the color of the other’s
screen. As a check, it shows the color it sent as the background color
on its own screen. If two Ataris aren’t connected, the program loops
slowly, and speeds up when a connection occurs (using the already
mentioned GameLink II hardware available from your local authorized AGDA
distributor :^)

BTW: if you wait too long after you’ve launched the program, attract
mode sets in. Even though you are resetting the color registers,
attract mode XORs your values with other ones. Press any key to stop
this annoying behavior (actual fix is left to the student as an
exercise).

This source will compile to binary executable directly (no need to
include the Action library routines, I didn’t use any). So after
compiling, the program will run without the Action cartridge. You must
press RESET after running this program to restore the default interrupt
vectors.

Warning: this program only does what I set out to do, so modifications
you make are likely to cause you a lot of grief. I can be of some help.

Jeff Potter

=====================================================================
;
; GameLink II demo program
; coded to *not* use Action library routines
; created 9/21/97 J.D.Potter
; modified 9/29/97 J.D.Potter
;
BYTE stick0=$0278, ;joystick 0
color0=$02C4, ;playfield 0
color2=$02C6, ;background color
color4=$02C8, ;border color
sskctl=$0232, ;skctl shadow
audf3=$D204, ;Channel 3 frequency
audf4=$D206, ;Channel 4 frequency
audctl=$D208, ;pokey control
skres=$D20A, ;serial port reset
serin=$D20D, ;serial port input
serout=$D20D, ;serial port output
irqen=$D20E, ;irq interrupt enable
skctl=$D20F ;serial port control

BYTE pokmsk=$0010, ;pokey irq mask
rtclok=$0014, ;jiffy clock LSB
status=$0030, ;sio status
recvdn=$0039, ;sio receive done
xmtdon=$003A ;sio xmit done

CARD vserin=$020A, ;receive int vector
vseror=$020C, ;xmit ready int vector
vseroc=$020E ;xmit complete int vector

DEFINE PHA=“$48″
DEFINE TXA=“$8A“
DEFINE TYA=“$98″
DEFINE PLA=“$68″
DEFINE TAX=“$AA“
DEFINE TAY=“$A8″
DEFINE RTI=“$40″
DEFINE SEI=“$78″
DEFINE CLI=“$58″
DEFINE pushregs=“[$8A $48 $98 $48]“
DEFINE pullrti=“[$68 $A8 $68 $AA $68 $40]“

;
; setup receive interrupt
;
PROC rxen()
skres=$CF
sskctl=(sskctl&$07)%$13
skctl=sskctl
pokmsk=(pokmsk&$C7)%$20
irqen=pokmsk
RETURN

;
; setup transmit interrupt
;
PROC txen()
skres=$CF
sskctl=(sskctl&$07)%$23
skctl=sskctl
pokmsk=(pokmsk&$C7)%$10
irqen=pokmsk
RETURN

;
; setup output complete interrupt
;
PROC ocen()
skres=$CF
skctl=sskctl
pokmsk=(pokmsk&$C7)%$08
irqen=pokmsk
RETURN

;
; setup null interrupt
;
PROC nxen()
skres=$FF
sskctl=(sskctl&$07)%$23
skctl=sskctl
pokmsk=(pokmsk&$C7)
irqen=pokmsk
RETURN

;
; Output complete handler; setup to receive
;
PROC ocr()
pushregs
rxen()
xmtdon=1
recvdn=0
status=1
pullrti
RETURN

;
; Receive complete handler (one byte)
;
PROC rxr()
BYTE i
pushregs
i = skctl ;read status
skres=$FF ;clear

IF i&$80 THEN
status = $8C ;input frame error
ELSEIF i&$20 THEN
status = $8E ;overrun error
ELSE status = 1
FI

color2 = serin ;set color

recvdn = 1
pullrti
RETURN

;
; Transmit ready handler (one byte)
; replace with real routines to handle things like
; multi-byte count-down, etc.
;
PROC txr()
pushregs
ocen()
pullrti
RETURN

;
; sets up serial bus speed, interrupt vectors
; (press RESET to undo this)
;
PROC setup()
audf4 = $00 ;19kbps
audf3 = $28
audctl = $28
recvdn = 0
xmtdon = 0
[SEI]
vserin = rxr ;point the 3 int vectors
vseror = txr ;to the right routines
vseroc = ocr
[CLI]
RETURN

;
; Main Program
;
PROC main()
BYTE i, x, colorx

setup()
colorx = 0
DO
recvdn = 0

; wait for a jiffy
i = rtclok
DO
x = stick0 ;read joystick
UNTIL i # rtclok
OD

; update internal colorx variable
IF (x & $01)=0 THEN
colorx ==+$10
ELSEIF (x & $02)=0 THEN
colorx ==-$10
FI

IF (x & $04)=0 THEN
colorx ==-$01
ELSEIF (x & $08)=0 THEN
colorx ==+$01
FI

; send colorx to other node
txen() ;enable transmit Int
serout = colorx ;send color
color4 = colorx ;set own border color

; wait for xmit done
DO UNTIL xmtdon OD
xmtdon = 0

; receiving is automatic
; (controlled by interrupt routine)
; other colorx gets written to us

rtclok = $F0
DO
UNTIL (recvdn=1) OR (rtclok=0)
OD
OD

RETURN