More Assembly/Spectrum confusion for me :D

The place for codemasters or beginners to talk about programming any language for the Spectrum.
+3code
Dizzy
Posts: 96
Joined: Fri Dec 06, 2019 11:43 pm
Location: Valencia, Spain

Re: More Assembly/Spectrum confusion for me :D

Post by +3code »

If you need the 128k ROM, they are too in the net:

http://www.fruitcake.plus.com/Sinclair/ ... sembly.htm
1 x

AndyC
Manic Miner
Posts: 293
Joined: Mon Nov 13, 2017 5:12 am

Re: More Assembly/Spectrum confusion for me :D

Post by AndyC »

chilledgamer wrote:
Thu Jun 25, 2020 4:28 pm
R-Tape wrote:
Thu Jun 25, 2020 4:22 pm
chilledgamer wrote:
Thu Jun 25, 2020 3:50 pm
Seems insane that after around 40 years there is not a table of detailed description, in order of all functions that exist in memory
There are quite a few ROM disassemblies out there. Here's one (I put it on my own webspace. I think it's by Geoff Wearmouth, but I couldn't find his link. Am I allowed to do this?) If you search this text file for "0DAF" (3503 in hexadecimal), you'll see the CLS routine (or you can look at the memory address in your emulator debugger).

RST 16 is the same, it's listed under "0010" (16 in hex). 'RST' is basically a CALL, but faster because it has special wiring (that phrasing will drive the hardware nuts wild :mrgreen: ). So CALL 16 will do exactly the same as RST 16, but ever so slightly slower (there will be no noticeable difference though).

My advice at this is it: DO NOT TRY TO UNRAVEL THESE ROM ROUTINES YET! They are a nightmare and if you're anything like me, you'll get tangled in confused, hateful knots in no time.

I'd just use them for now, understand that CLS clears the screen & sets paper colours, and RST 16 prints stuff. Even though the ROM code is a mile long, you can write your own CLS, PAPERFILL and PRINT routines in tens of bytes. We can post some if you like.

Though IMO, starting off just using the ROM routines without worrying too much about their contents is a good way to get into coding.

This is really helpful to me thanks!!!! Could I ask about RST 16 again. In the example (im sure your aware of it) he uses RST 16 to print, i get that no problem. But later he 'sets' the xy position of the character for player. After each set of accumulator, he does RST 16 with comment "set the player x coord". Nothing is printed with this action i assume?

code snippet:

Code: Select all

basexy 
	ld a,22 ; AT code.
	rst 16
	ld a,(plx) ; player vertical coord.
	rst 16 ; set vertical position of player.
	ld a,(ply) ; player's horizontal position.
	rst 16 ; set the horizontal coord.
	ret
; Show player at current print position.
splayr 
	ld a,69 ; cyan ink (5) on black paper (0),
; bright (64).
	ld (23695),a ; set our temporary screen colours.
	ld a,144 ; ASCII code for User Defined Graphic 'A'.
	rst 16 ; draw player.
	ret
The BASIC Print command accepts a number of control codes that can be embedded within a string to do things like move the cursor position, change the current INK or PAPER etc. These control codes are documented in the manual.

Internally, this is handled by the RST 16 routine, so passing appropriate control code sequences to that will have the same effect as in BASIC. This is one of the reasons that the code behind it is incredibly complex and also not terribly quick.
1 x

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

Re: More Assembly/Spectrum confusion for me :D

Post by R-Tape »

chilledgamer wrote:
Thu Jun 25, 2020 4:28 pm
This is really helpful to me thanks!!!! Could I ask about RST 16 again. In the example (im sure your aware of it) he uses RST 16 to print, i get that no problem. But later he 'sets' the xy position of the character for player. After each set of accumulator, he does RST 16 with comment "set the player x coord". Nothing is printed with this action i assume?
Yep not every CALL/RST 16 prints a character.

If you LD A with numbers 32 - 127, RST 16 prints the corresponding ASCII), 128 - 165 is the blocks & then UDGS. So this code will print all the ASCII set and UDGS:

Code: Select all

org 32768
	ld a,2
	call 5633
	ld a,32
loop:	push af
	rst 16
	pop af
	inc a
	cp 165
	jr c,loop
	ret
Numbers outside of this range do different things, and some don't do anything. So in your example, RST 22 is the 'PRINT AT' code that tells it that the following two bytes will be the Y & X coords to print at.

Some other useful ones are:

LD A,16 ;INK colour
RST 16 ;it expects to next byte to be a viable colour 0-7
LD A,2 ;red = 2
RST 16 ;anything printed from now will be red

Others:
17 (does PAPER 0 -7)
18 (FLASH 0 or 1)
19 BRIGHT (0 or 1)

Have you got the BASIC manual? This info is listed on p183, "The character set"
1 x

User avatar
chilledgamer
Berk
Posts: 46
Joined: Wed Jun 24, 2020 1:22 am
Location: Torquay
Contact:

Re: More Assembly/Spectrum confusion for me :D

Post by chilledgamer »

Thank you all. I wangled the night off work haha :D I understand much better now about RST , which has helped me somewhat understand the whole thing a little better also.
1 x

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

Re: More Assembly/Spectrum confusion for me :D

Post by R-Tape »

chilledgamer wrote:
Thu Jun 25, 2020 5:52 pm
Thank you all. I wangled the night off work haha :D I understand much better now about RST , which has helped me somewhat understand the whole thing a little better also.
You have a very understanding boss!

Mr Pargeter? I'm afraid I can't come to work tonight; I need to unravel the convoluted wonders of the RST 16 instruction on the ZX Spectrum.
2 x

User avatar
chilledgamer
Berk
Posts: 46
Joined: Wed Jun 24, 2020 1:22 am
Location: Torquay
Contact:

Re: More Assembly/Spectrum confusion for me :D

Post by chilledgamer »

R-Tape wrote:
Thu Jun 25, 2020 8:51 pm
chilledgamer wrote:
Thu Jun 25, 2020 5:52 pm
Thank you all. I wangled the night off work haha :D I understand much better now about RST , which has helped me somewhat understand the whole thing a little better also.
You have a very understanding boss!

Mr Pargeter? I'm afraid I can't come to work tonight; I need to unravel the convoluted wonders of the RST 16 instruction on the ZX Spectrum.

haha no he isn't understanding at all lol. But luckily for me (as I really didn't fancy working tonight) he had booked too many staff and needed one of us to go home (if we didn't mind lol).

By the way, I think I might have found a mistake on Skoolkid site https://skoolkid.github.io/rom/maps/all.html , here he lists "2294 The Border Command Routine" but in my example tutorial and all of my testing I have to use 229B. Anyone see if this is the website that is wrong, or yet again me being dumb lol?
0 x

User avatar
lister_of_smeg
Dizzy
Posts: 53
Joined: Thu Nov 16, 2017 1:44 pm

Re: More Assembly/Spectrum confusion for me :D

Post by lister_of_smeg »

chilledgamer wrote:
Thu Jun 25, 2020 11:00 pm
By the way, I think I might have found a mistake on Skoolkid site https://skoolkid.github.io/rom/maps/all.html , here he lists "2294 The Border Command Routine" but in my example tutorial and all of my testing I have to use 229B. Anyone see if this is the website that is wrong, or yet again me being dumb lol?
$2294 - $229a deal with handling the parameter passed from the BORDER command in BASIC. So if calling from machine code with your border value already in A you instead jump in after those instructions.
1 x

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

Re: More Assembly/Spectrum confusion for me :D

Post by R-Tape »

chilledgamer wrote:
Thu Jun 25, 2020 11:00 pm
By the way, I think I might have found a mistake on Skoolkid site https://skoolkid.github.io/rom/maps/all.html , here he lists "2294 The Border Command Routine" but in my example tutorial and all of my testing I have to use 229B. Anyone see if this is the website that is wrong, or yet again me being dumb lol?
No they're both correct for their purpose. The border control routine does start at hex 2294.

At 2294, it checks that your are trying to set a viable border colour: 0 - 7, and if not, print the BASIC "K: Invalid colour":

Code: Select all

L2294:  CALL    L1E94           ; routine FIND-INT1
        CP      $08             ; must be in range 0 (black) to 7 (white)
        JR      NC,L2244        ; back to REPORT-K if not
Jonathan knows his onions, and has chosen to skip this, so that the chance of an error is avoided:

Code: Select all

229B       OUT     ($FE),A         ; outputting to port effects an immediate
                                ; change.
It skips some unecessary stuff, and also avoids a stoppage (the worst case scenario is a wonky border colour)
0 x

User avatar
chilledgamer
Berk
Posts: 46
Joined: Wed Jun 24, 2020 1:22 am
Location: Torquay
Contact:

Re: More Assembly/Spectrum confusion for me :D

Post by chilledgamer »

Ah i see. That makes more sense. A little challenge for me now then to change the border starting with call &2294
0 x

Profmyster
Berk
Posts: 11
Joined: Wed Apr 10, 2019 8:46 am

Re: More Assembly/Spectrum confusion for me :D

Post by Profmyster »

0 x

Post Reply