I'm working on some code for the next (exciting) issue of the randomly produced Assembly Language eComic and I've come across a bit of a weird thing happening. SD_SETPA is failing to set green paper. Here's the offending code:
Code: Select all
size_x
equ 512 ; Pixels across (width)
size_y
equ 256 ; Pixels down (height)
black
equ 0 ; Black cell colour
red
equ 2 ; It's a red ant!
white
equ 7 ; White cell colour
green
equ 4 ; The world colour
start
bra.s Langton
dc.l 0
dc.w $4afb
name
dc.w nameEnd-name-2
dc.b "Langton's Ant"
nameEnd
equ *
;--------------------------------------------------------------------
; BLOCK command parameter block.
;--------------------------------------------------------------------
Block
dc.w 1,1
xPos
dc.w Size_x/2,Size_y/2
;--------------------------------------------------------------------
; Screen channel name and window definition block.
;--------------------------------------------------------------------
scr_def
dc.w 4
dc.b 'scr_'
winDef
dc.w size_x
dc.w size_y
dc.w (512-size_x)/2
dc.w (256-size_y)/2
;--------------------------------------------------------------------
; Subroutine to do a trap #3, test D0 and die horribly if there was
; an error.
;--------------------------------------------------------------------
doTrap3
trap #3
bra.s testD0
;--------------------------------------------------------------------
; Subroutine to do a similar thing for trap #1.
;--------------------------------------------------------------------
doTrap1
trap #1
testD0
tst.l d0
bne.s suicide
rts
suicide
move.l d0,d3
moveq #mt_frjob,d0
moveq #-1,d1
trap #1
;--------------------------------------------------------------------
; The main starting place. Open a scr_ channel. The channel ID will
; stay protected in A0.L throughout the rest of the code.
;--------------------------------------------------------------------
Langton
lea scr_def,a1 ; Screen channel
moveq #io_open,d0
moveq #-1,d1
moveq #0,d3
bsr.s doTrap1
;--------------------------------------------------------------------
; The screen channel is open, make the window the requested size.
;--------------------------------------------------------------------
Window
moveq #sd_wdef,d0 ; Window definition
moveq #0,d1
moveq #0,d2
moveq #-1,d3
lea winDef,a1
bsr.s doTrap1
;--------------------------------------------------------------------
; Set the paper to green.
;--------------------------------------------------------------------
Paper
moveq #sd_setpa,d0 ; Set paper to green
moveq #green,d1
bsr.s doTrap1
;--------------------------------------------------------------------
; And clear the entire screen.
;--------------------------------------------------------------------
Cls
moveq #sd_clear,d0 ; Cls
bsr.s doTrap1
The SD_WDEF returns ok, and A0 is not changed.
The call to SD_SETPA trips up and returns D0 as $FFFFFFF1 aka -15 aka Invalid Parameter. WTH?
If I skip over the branch to suicide, then the call to SD_CLEAR works fine.
A0 has not changed.
D1 is correctly set to 4 for green paper.
D3 is preserved throughout all the calls and remains at -1.
I'm running QPC v4 and whatever version of SMSQ that came with it.
I thought it might have been because I mistakenly loaded D2 with 2 for the open mode, instead of 0, but that made no difference.
I'm seriously puzzled, given that SD_SETPA takes only three parameters - colour (4) , timeout (-1) and a channel id, and all of those look fine to me.
Any offers of advice, help or strong drugs gratefully received. I've got more bugs to work out in this code but I'm struggling to get past this one, its obviously correct!
Cheers,
Norm.