SD_SETPA failes on SMSQ with Invalid Parameter

Anything QL Software or Programming Related.
User avatar
NormanDunbar
Forum Moderator
Posts: 2249
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

SD_SETPA failes on SMSQ with Invalid Parameter

Post by NormanDunbar »

Morning All,

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
So, the SCR_ channel opens, and returns $2A6CA8 as the channel Id in A0. At least, it did in the last test. QMON2 told me so.
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.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
tofro
Font of All Knowledge
Posts: 2679
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: SD_SETPA failes on SMSQ with Invalid Parameter

Post by tofro »

Norman,

I suppose it doesn't help if I'll tell you "this should work"....

What could upset the QL, however, is your "new way of formatting source code".

I would suppose there's something ending up on an odd address. Note

Code: Select all

byte: dc.b 42
word: dc.w 4711
and

Code: Select all

byte: dc.b 42
word:
	dc.w 4711
generate two binaries different in a subtile way: The first example has "word" pointing to 4711, while the second has it point 1 byte before it. While dc.w adjusts * to an even address, it doesn't adjust the label one line above. (At least that is what the GST assembler does - I would be surprised if George's assembler would do something differently).

I haven't gone through all of your code but that is what I suspect is the problem after a short glance (this problem affects your label "block", for example). Inject some "ds.w 0" in strategic places.

Tobias
Last edited by tofro on Sun Feb 18, 2018 9:55 am, edited 2 times in total.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: SD_SETPA failes on SMSQ with Invalid Parameter

Post by mk79 »

You always call "do_trap1" instead of "do_trap3". No idea how you get any channel this way (should be trap#2)?

Cheers, Marcel


User avatar
pjw
QL Wafer Drive
Posts: 1280
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: SD_SETPA failes on SMSQ with Invalid Parameter

Post by pjw »

NormanDunbar wrote:

Code: Select all

Langton
	   lea	   scr_def,a1	       ; Screen channel
	   moveq   #io_open,d0
	   moveq   #-1,d1
	   moveq   #0,d3
	   bsr.s   doTrap1
You just created a nice little job there, Norm, not a screen ;)


Per
dont be happy. worry
- ?
User avatar
NormanDunbar
Forum Moderator
Posts: 2249
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: SD_SETPA failes on SMSQ with Invalid Parameter

Post by NormanDunbar »

mk79 wrote:You always call "do_trap1" instead of "do_trap3". No idea how you get any channel this way (should be trap#2)?
Oh for f*ck sake!!!! :shock: :shock: :shock: :roll: :? :? 8-)

WTF was I doing? Thanks very much Marcel, I looked and looked and checked Pennell and Dickens and still didn't see it. Now, what the hell did I actually do?

Checks Pennell...

Hmm, as Per points out somewhere below, MT_CJOB.

Thank you, I am, as they say, a dickhed. :(


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
NormanDunbar
Forum Moderator
Posts: 2249
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: SD_SETPA failes on SMSQ with Invalid Parameter

Post by NormanDunbar »

pjw wrote:You just created a nice little job there, Norm, not a screen ;)
MT_CJOB, thanks Per. It's funny how you can never spot these things until someone else sees it as so bloody obvious!".

I am, much appreciative - thanks.


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
NormanDunbar
Forum Moderator
Posts: 2249
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: SD_SETPA failes on SMSQ with Invalid Parameter

Post by NormanDunbar »

Hi Tobias,
tofro wrote:I suppose it doesn't help if I'll tell you "this should work"....
By "should" do you mean "should work if and when you put the pointer to the scrdef in A0 and not in A1 and call trap #2 to open it rather than trap #1? :D
tofro wrote:What could upset the QL, however, is your "new way of formatting source code".
No, that's fine. Geroge's assemblers do the right thing and the DC.W is aligned on an even address regardless of whether the current address is odd. I've been told off in the past - read issue 4, Wolfgang's comments, about my use of DS.W 0 to make sure words were even aligned. I did some tests with GWASL and GWASS60, and both put the word at an even address.
tofro wrote:I haven't gone through all of your code but that is what I suspect is the problem after a short glance (this problem affects your label "block", for example). Inject some "ds.w 0" in strategic places.
The label "block" is indeed perfecly even in its address, at least when I'm stepping through it.


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
pjw
QL Wafer Drive
Posts: 1280
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: SD_SETPA failes on SMSQ with Invalid Parameter

Post by pjw »

NormanDunbar wrote:
pjw wrote:You just created a nice little job there, Norm, not a screen ;)
MT_CJOB, thanks Per. It's funny how you can never spot these things until someone else sees it as so bloody obvious!".
I dont know, but it seems to be a fact of life. Also, a lot of this stuff we studied deeply like 20-30 years ago, so it does start to fade or play us tricks. The time to start worrying is when you find youve put the cat in the washing machine and taken the lawnmower to the super market..


Per
dont be happy. worry
- ?
User avatar
NormanDunbar
Forum Moderator
Posts: 2249
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: SD_SETPA failes on SMSQ with Invalid Parameter

Post by NormanDunbar »

Well, after a few hours hard work, i finally debugged the whole thing.

I had one nasty where it ran for ages then just stopped. Same place each time. I couldn't find out why, and tracing it would have taken until the end of time! In the end, I resorted to a utility I wrote years ago for Quanta's "Easy Pointer Tutorial" series - the jobinfo program.

With that dumping out the job's details from the header, I could see A7 getting smaller and smaller all the time - a clue. Sure enough, I was stacking a word but not unstacking it. Sigh.

Still, at least I've got a potential new utility to write up, in assembler! :D

Cheers,
Norm.

PS. The assembly version is way too fast, I had to suspend the job for 1 frame each time around the loop. That caused it to be slower than SuperBASIC!


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
janbredenbeek
Super Gold Card
Posts: 628
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: SD_SETPA failes on SMSQ with Invalid Parameter

Post by janbredenbeek »

NormanDunbar wrote: So, the SCR_ channel opens, and returns $2A6CA8 as the channel Id in A0. At least, it did in the last test. QMON2 told me so.
This should have rung a bell, as channel IDs should never have such a high value in the lower word. The lower word is an index value in the channel table which never exceeds 360 (the maximum under QDOS, don't know about SMSQ) and in most cases is much lower. The higher word is a tag value which increases with each channel opened and can go as high as 32767 (SuperBASIC gets into trouble with negative tags as it treats the channel ID as invalid or closed, while in fact it could be perfectly valid, but that's a different story).

regards, Jan.


Post Reply