ZXSpin Assembler

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
Ast A. Moore
Dizzy
Posts: 78
Joined: Mon Nov 13, 2017 3:16 pm

Re: ZXSpin Assembler

Post by Ast A. Moore » Tue Dec 05, 2017 9:22 am

R-Tape wrote:
Mon Dec 04, 2017 10:21 pm
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.
Not for calculating character cell addresses. It’s pretty trivial, as your column is just a range of values 0–31, and your row is just n lots of 0–31. The advantage is that your printout routine doesn’t have to deal with screen thirds.

If I remember correctly, my simplest printout routine was only 19 bytes long (using the bitmap address). Making it accept an attribute address instead will only add seven more bytes. (It’s beneficial if you want to add color and wish for the text to automatically move down one line.)

It’s the smoothest (and most practical) introduction to the actual screen layout I can think of. You are essentially doing sprites. Simple, 8x8, character–cell-aligned sprites, but sprites, nevertheless. Much more exciting than the mysterious incantation of “RST $10.”
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

Ralf
Microbot
Posts: 135
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: ZXSpin Assembler

Post by Ralf » Tue Dec 05, 2017 9:56 am

The problem is this line:

ld hl,21+15*256

It loads HL with 9216 = 0,36 which is an impossible coord.
Yes, now I remember old post at WOS about it.

Spin doesn't follow standard math order of calculations. You know - multiplication first, addition later.

Instead it goes just from left to right:

21+15=36
36*256=9216

So remember about it and use brackets every time. They seem to work correctly :)
0 x

User avatar
R-Tape
Site Admin
Posts: 275
Joined: Thu Nov 09, 2017 11:46 am

Re: ZXSpin Assembler

Post by R-Tape » Tue Dec 05, 2017 10:54 am

Ast A. Moore wrote:
Tue Dec 05, 2017 9:22 am
Not for calculating character cell addresses. It’s pretty trivial, as your column is just a range of values 0–31, and your row is just n lots of 0–31. The advantage is that your printout routine doesn’t have to deal with screen thirds.

If I remember correctly, my simplest printout routine was only 19 bytes long (using the bitmap address). Making it accept an attribute address instead will only add seven more bytes. (It’s beneficial if you want to add color and wish for the text to automatically move down one line.)

It’s the smoothest (and most practical) introduction to the actual screen layout I can think of. You are essentially doing sprites. Simple, 8x8, character–cell-aligned sprites, but sprites, nevertheless. Much more exciting than the mysterious incantation of “RST $10.”
This sounds a good way in, but I would still say that for the complete beginner trying to get your head around moving within the DF at all is a bit much - so I would include the bit interpretations and screen2attr as things to 'call but don't worry about yet'.
0 x

User avatar
R-Tape
Site Admin
Posts: 275
Joined: Thu Nov 09, 2017 11:46 am

Re: ZXSpin Assembler

Post by R-Tape » Tue Dec 05, 2017 11:05 am

Ast A. Moore wrote:
Tue Dec 05, 2017 9:22 am
Much more exciting than the mysterious incantation of “RST $10.”
When I started learning asm I used to think RST 16 was superfast instruction as it was hardwired. Little did I realise that in practise they're the same - RST 16 and CALL 16 both can only manage 42 chars per frame.
0 x

User avatar
Ast A. Moore
Dizzy
Posts: 78
Joined: Mon Nov 13, 2017 3:16 pm

Re: ZXSpin Assembler

Post by Ast A. Moore » Tue Dec 05, 2017 12:08 pm

R-Tape wrote:
Tue Dec 05, 2017 10:54 am
I would still say that for the complete beginner trying to get your head around moving within the DF at all is a bit much - so I would include the bit interpretations and screen2attr as things to 'call but don't worry about yet'.
Indeed. Might work for some, with the caveat of inadvertently encouraging the “it’s just the way it is, don’t think too much about it” behavior, though.
R-Tape wrote:
Tue Dec 05, 2017 11:05 am
When I started learning asm I used to think RST 16 was superfast instruction as it was hardwired. Little did I realise that in practise they're the same - RST 16 and CALL 16 both can only manage 42 chars per frame.
Heh. Yet CALL is three times larger and six T states slower. :D

On a more serious note, I think it’s important to teach beginners that there’s a fundamental difference between universal (read: library-based) and custom approaches to programming for underpowered micros. The former is instrumental for saving space, while the latter is crucial for gaining speed. The RST $10 routine is an excellent case in point. It does too many things—which makes it universal—but at a huge speed expense. A perfect “gateway drug” to writing small and fast custom routines.

Thirty-two characters (with color) in about one-fifth of a frame (the black border represents execution time):
Image
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Morkin
Berk
Posts: 43
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol

Re: ZXSpin Assembler

Post by Morkin » Tue Dec 05, 2017 2:06 pm

I've tended to use Spin 0.666 and its assembler, as it seems a bit more stable than 0.7. Only thing is that the beeper in 0.666 didn't seem to work when it's in 48k mode, but I always found it great apart from that.

I found Jonathan's guide really useful, but I didn't attempt to follow along with creating his game as I didn't really want to play Centipede.. ;)

I used Tapey-boy's method of "borrowing" a routine that converted an XY screen co-ordinate into the correct point on the screen without worrying how it worked, and then printed the sprite on screen. It was then just a series of steps:

(1) work out how print a sprite to the screen
(2) work out how to read the keyboard
(3) create extra graphic sprites for the character in "half character steps" (for 4 pixel rather than 8 pixel moves)

The result was this:

Image

The first time I successfully tried to do (2) I burst out laughing'; the sprite basically just 'teleported' from the middle of the screen to the edge. Having got so used to BASIC back in the day, I'd forgotten that machine code was so quick it was faster than the naked eye.. I had to put a pause in between frames after that.. :lol:

...So ultimately it's proof positive that it's possible for a complete novice to learn without using the RST 16 routine.


[Edit: oh, you can probably see why I recruited Rorthron to do the graphics for Catacombs of Balachor.. :lol: ]
0 x

User avatar
PeterJ
Site Admin
Posts: 115
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: ZXSpin Assembler

Post by PeterJ » Tue Dec 05, 2017 4:01 pm

Hi @Morkin ,

Thanks for this. Any chance of sharing the code for this example?
0 x

User avatar
Morkin
Berk
Posts: 43
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol

Re: ZXSpin Assembler

Post by Morkin » Tue Dec 05, 2017 7:04 pm

Would be happy to but I'd have to dig it out from a mass of files and I'm not even sure if I still have it... Will have a look, but no promises..! :|

If it helps, I used the two routines in chapter one (p6-8) of the Advanced Spectrum Machine Language book:

http://zxinfo.dk/details/2000025

One for the pixels and one for the attributes.

It explains about how the screen works but I couldn't get my head round how the rows/columns etc. worked at the time, despite reading it about 3 times...

Fortunately, you can just use the routines without knowing exactly how they work, you only need to get the general gist of them to start with. (Well, that's what I reckon anyway! :D )

You can LD B (and C) with your X (and Y) screen co-ordinates, CALL the routines and the HL register is pointing at the top pixel line of the square you want to print your graphic at, ready to LD data into.
1 x

User avatar
PeterJ
Site Admin
Posts: 115
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: ZXSpin Assembler

Post by PeterJ » Tue Dec 05, 2017 8:41 pm

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.
I have been letting my brain digest this today, and reading my Spectrum manual again and I agree with you it is odd how the Spectrum BASIC (and ROM routine) works opposite to what you expect.

Normally you would expect X along the bottom and Y up the side:

Image

But the "Print At" and RST routines uses lines then columns which I would have said in Y,X as you say. Then Jonathan refers to them as X,Y. Sorry if I'm rambling! I need to print something out and stick it on the wall!
0 x

User avatar
PeterJ
Site Admin
Posts: 115
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: ZXSpin Assembler

Post by PeterJ » Tue Dec 05, 2017 8:46 pm

Bob's 8-Bit Blog tutorials code everything from scratch rather than using ROM routines.

https://bobs8bb.wordpress.com/
0 x

Post Reply