Page 1 of 3

ZXSpin Assembler

Posted: Mon Dec 04, 2017 8:00 pm
by PeterJ
Evening,

I'm working my way through 'How to Write ZX Spectrum Games' by Jonathan Cauldwell, and I have tried this snippet of code in Spin 0.7S and 0.7Q with the same results. The code assembles fine, then when I try and run with a Randomize USR 24576 it I get a BASIC error 'Integer Out of Range'. It assembles fine with Pasmo, and I can run the .tap file created by Pasmo without problem.

Even though its very old in the tooth now, I like the integrated nature of Spin (and I'm secretly hoping @ZXDunny might update it one day) I'm using Windows 10.

Code: Select all

org $6000
	ld a,71
	ld (23693),a
	xor a	
	call 8859

	ld hl,blocks
	ld (23675),hl

	call 3503

	ld hl,21+15*256
	ld (plx),hl
	

	call basexy
	
	call splayr
	ret

basexy	ld a,22
	rst 16
	ld a,(plx)
	rst 16
	ld a,(ply)
	rst 16
	ret

splayr	ld a,69
	ld (23695),a
	ld a,144
	rst 16
	ret

plx defb 0
ply defb 0
blocks defb 16,16,56,56,124,124,254,254

Re: ZXSpin Assembler

Posted: Mon Dec 04, 2017 8:37 pm
by Ralf
I can't help you with this one but I would have an general advice. Remember that Spin is unfortunately a bit buggy :( It's really a pity as it without bugs it would be really, really great and now it's just good ;)

Re: ZXSpin Assembler

Posted: Mon Dec 04, 2017 8:38 pm
by Stefan
Compare the contents of memory at 24576 ($6000) with the contents of the Pasmo compiled source?

This post however seems to indicate that the ZX Spin assembler is just broken.

Re: ZXSpin Assembler

Posted: Mon Dec 04, 2017 8:44 pm
by R-Tape
I use 0.666 and have never had any problems, but then I don't use assembly to its full potential.

The problem is this line:

ld hl,21+15*256

It loads HL with 9216 = 0,36 which is an impossible coord.

ld hl,21+(15*256) works.

Re: ZXSpin Assembler

Posted: Mon Dec 04, 2017 9:04 pm
by namco
@R-Tape Beaten me to it, I was just about to mention that line (but not the solution).

However, comparing this code to mine (from a earlier game):

Code: Select all

ld a,(plx)
rst 16
ld a,(ply)
rst 16
Are the x and y values the wrong way around?

Re: ZXSpin Assembler

Posted: Mon Dec 04, 2017 9:09 pm
by PeterJ
R-Tape wrote:
Mon Dec 04, 2017 8:44 pm
I use 0.666 and have never had any problems, but then I don't use assembly to its full potential.

The problem is this line:

ld hl,21+15*256

It loads HL with 9216 = 0,36 which is an impossible coord.

ld hl,21+(15*256) works.
Interesting, so Pasmo is doing 15*256 = 3840 + 21 (3,861) which is correct and follows BODMAS (and Sinclair BASIC), whilst Spin is doing (21+15)*256 which is 9,216 as you say Dave.

Replacing that line with LD HL,3,861 works fine in Spin. I suppose its just a matter of getting used to each assemblers oddities.

I did try the Zeus assembler but can't make head nor tale of that.

Thanks everyone

Image

Re: ZXSpin Assembler

Posted: Mon Dec 04, 2017 9:14 pm
by R-Tape
namco wrote:
Mon Dec 04, 2017 9:04 pm
Are the x and y values the wrong way around?
How do you mean the wrong way round?

This is where I get confused because Jonathan's documentation (and AGD) say X when they mean Y (the vertical axis) and Y when they mean X (the horizontal axis). Both ways work as long as the vertical axis is RSTd first followed the horizontal axis. I think that's why Jonathan uses them that was round, because we say X,Y and the ROM print uses the vertical cord first.

So as long as you mean Y when you say X, and X when you say Y, or whichever way you want X to be, Y can be X or X can be Y.

Do that make sense?

No, where am I? :mrgreen:

Re: ZXSpin Assembler

Posted: Mon Dec 04, 2017 9:28 pm
by Ast A. Moore
I don’t think it’s the most logical approach in the long run, though. Restart at $10 is just a special case, and I don’t think it’s beneficial for a novice to think of the print coordinates as X and Y. Ideally, you should reserve these to refer to actual pixel coordinates, and stick to thinking “column, row” for anything print-related.

In my simplest (and fastest) printout routines, I don’t even bother with columns and rows—just use the attribute area of the display file directly. (Although, converting back and forth is trivial.)

And yes, each assembler has its own set of quirks. Some are quirkier than others. ;)

Re: ZXSpin Assembler

Posted: Mon Dec 04, 2017 9:48 pm
by namco
Both ways work as long as the vertical axis is RSTd first followed the horizontal axis. I think that's why Jonathan uses them that was round, because we say X,Y and the ROM print uses the vertical cord first.
That's fine! :)

Oh and it's probably best to use brackets when seeing things like this:
ld hl,21+15*256

That way no assembler gets confused!

Re: ZXSpin Assembler

Posted: Mon Dec 04, 2017 10:21 pm
by R-Tape
Ast A. Moore wrote:
Mon Dec 04, 2017 9:28 pm
I don’t think it’s the most logical approach in the long run, though. Restart at $10 is just a special case
I've often wondered* how feasible it would be for a complete beginner's guide to asm to not use ROM routines at all. It's easy enough to draw a char, but moving it around becomes tricky as you'd need a yx2cell routine that brings forth the intimidating display file layout far too early. Perhaps it could just be included with a note 'just CALL this routine to do this, don't worry about understanding it yet'. Then you could move onto sprites more fluidly. In fact I would have understood that more than I did the magic RST 16 at the time! (Not saying this applies to you Peter).

*But never done anything about.