Assembly Help

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
PeterJ
Site Admin
Posts: 6855
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Assembly Help

Post by PeterJ »

Hi,

I'm coming back to working on my game, and because I have left it so long I seem to have forgotten so much!

I'm using this routine from 'Advanced Spectrum Machine Code - Melbourne House'

Image

Code: Select all

org $6000
ld b,10
ld c,10
ld a,b
and $F8
add a,$40
ld h,a
ld a,b
and 7
rrca
rrca
rrca
add a,c
ld l,a
ld (5c84H),HL
ld a,36
rst $10
ret
I'm loading B & C with the line and column, then after the routine lading the DF-CC system variable with the contents of HL which should be the memory location for that screen position. I'm then loading a '$' then trying to print it to the screen at the position set in B & C.

It dosent error in Pasmo and the code runs, but RANDOMIZE USR 24576 produces nothing. What am I doing wrong? Thanks
User avatar
R-Tape
Site Admin
Posts: 6353
Joined: Thu Nov 09, 2017 11:46 am

Re: Assembly Help

Post by R-Tape »

PeterJ wrote: Mon Dec 03, 2018 1:25 pm I'm coming back to working on my game
Excellent!

Your code works fine, but it's trying to print in the #1 bottom part of the screen. Add this at the very start of the code:

LD A,2
CALL 5633

This changes to the upper screen (LD A,1 CALL 5633 changes back to the lower)
User avatar
PeterJ
Site Admin
Posts: 6855
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Assembly Help

Post by PeterJ »

Thank you [mention]R-Tape[/mention]

I had forgotten I had to do that first.
User avatar
PeterJ
Site Admin
Posts: 6855
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Assembly Help

Post by PeterJ »

With thanks to Dave, I now get my '$' in the top corner (0,0) but not at 10,10 as expected

Code: Select all

org $6000
LD A,2
CALL 5633
ld b,10
ld c,10
ld a,b
and $0F8
add a,$40
ld h,a
ld a,b
and 7
rrca
rrca
rrca
add a,c
ld l,a
ld ($5c84),HL
ld a,36
rst $10
ret
Bizzley
Microbot
Posts: 124
Joined: Thu Nov 16, 2017 10:47 am

Re: Assembly Help

Post by Bizzley »

Is there a specific reason you are using the ROM to put your text on the screen? If all you want to do is print some non-attribute text at a specific location then you will have a lot more control (and understanding of what you're doing) if you do the printing yourself. I can post a tiny no-frills routine if you want to see what I mean that takes the address supplied to you by the 'Advanced Spectrum Machine Code' routine and just pulls the correct character data out of the Spectrum ROM font and onto the screen.
"He made eloquent speeches to an audience consisting of a few depressed daffodil roots, and sometimes the cat from next door."
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Assembly Help

Post by Ast A. Moore »

If you’re trying to use ROM calls, then you’ll be better off with the good old RST $10. However, it’s much, much faster to do it yourself. Here’s arguably the quickest and smallest printer routine I could think of. It’s only 19 bytes (26, if you’re using the attribute address for coordinates):

Code: Select all

		ld de,$484a		;AT 10,10 (screen bitmap)
;		ld de,$594a		;AT 10,10 (screen attributes)

		ld a,"$"		;(some assemblers won’t convert characters to ASCII codes, though)
	
		call printer

		ret

printer					;19/26 bytes (bitmap/attr addr)
		ld h,0			;make sure H=0
		add a,a			;   			\
		ld l,a			;load L with chr code
		add hl,hl		; 			  multiply HL by 8
		add hl,hl		;			/
		ld bc,$3c00		;add $3c00 to get the base address of character
		add hl,bc		;bitmap in ROM (chr code*8+$3c00), load it into HL

;		ld a,d
;		rla			;
;		rla			;convert attr addr to bitmap addr
;		rla			;
;		and 88
;		ld d,a

		ld b,8			;eight lines to draw
char_pr		ld a,(hl)		;bitmap into A
		ld (de),a		;put on screen
		inc l			;next bitmap
		inc d			;one line down
		djnz char_pr

		ret

Uncomment the lines marked "convert attr addr to bitmap addr,” and the second line (“AT 10,10 (screen attributes)”), if you wish to use the attribute address for you character coordinates. The latter is a tad easier to use, as the formula is $5800 + x-coord × 32 + y-coord:

Code: Select all

		ld b,10			;x coord
		ld c,10			;y coord

		ld de,$5800

		ld h,e			;zero into H
		ld l,b			;x coord into L
		add hl,hl		;\
		add hl,hl		; \
		add hl,hl		;  multiply by 32
		add hl,hl		; /
		add hl,hl		;/
		add hl,de		;add $5800
		ld d,e			;zero into D
		ld e,c			;y coord into E
		add hl,de		;add y coord
Last edited by Ast A. Moore on Mon Dec 03, 2018 7:03 pm, edited 1 time in total.
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.
Bizzley
Microbot
Posts: 124
Joined: Thu Nov 16, 2017 10:47 am

Re: Assembly Help

Post by Bizzley »

And here's a 17 byte print routine....any more for any less? :D

Code: Select all

		ld de,$484a
		ld a,"$"
		call printer
		ret
;
printer		or 128
 		ld h,7
 		ld l,a
 		add hl,hl
 		add hl,hl
 		add hl,hl
 		ld b,8
printer1	ld a,(hl)
 		ld (de),a
 		inc d
 		inc l
 		djnz printer1
 		ret
"He made eloquent speeches to an audience consisting of a few depressed daffodil roots, and sometimes the cat from next door."
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Assembly Help

Post by Ast A. Moore »

Bizzley wrote: Mon Dec 03, 2018 7:01 pm And here's a 17 byte print routine....any more for any less? :D
Hah! Neat. A bit tough to use with custom fonts, though, which was what I initially wrote mine for. ;)
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.
Bizzley
Microbot
Posts: 124
Joined: Thu Nov 16, 2017 10:47 am

Re: Assembly Help

Post by Bizzley »

Ast A. Moore wrote: Mon Dec 03, 2018 7:12 pm Hah! Neat. A bit tough to use with custom fonts, though, which was what I initially wrote mine for. ;)
Not really. As long as you're careful on what specific page boundary you put the font then it's just a matter of changing the LD H,n command to the appropriate value. While there are some values you can't use there are others where you don't need to apply the OR n command at all and can reduce the routine to 15 bytes. It's a bit like setting up interrupt vector tables, you tend to pick something and code around it...well at least I do :)
"He made eloquent speeches to an audience consisting of a few depressed daffodil roots, and sometimes the cat from next door."
User avatar
Morkin
Bugaboo
Posts: 3251
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Assembly Help

Post by Morkin »

I thought if you were using RST $10 you use the PRINT AT X, Y codes to set the co-ordinates...?

e.g.

Instead of

Code: Select all

ld a,36
rst $10
ret
For PRINT AT 10, 10 you'd do something like:

Code: Select all

ld a,22   ; code for AT
rst $10
ld a,10   ; row 10
rst $10
ld a,10   ; column 10
rst $10
ld a,36  ; "$"
rst $10
ret
[Edit] BTW that looks like a fairly pristine copy of the Melbourne House Advanced Machine Code book - I've got that one and it's practically falling apart..!
Last edited by Morkin on Mon Dec 03, 2018 7:51 pm, edited 1 time in total.
My Speccy site: thirdharmoniser.com
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Assembly Help

Post by Ast A. Moore »

Bizzley wrote: Mon Dec 03, 2018 7:37 pm
Ast A. Moore wrote: Mon Dec 03, 2018 7:12 pm Hah! Neat. A bit tough to use with custom fonts, though, which was what I initially wrote mine for. ;)
Not really. As long as you're careful on what specific page boundary you put the font then it's just a matter of changing the LD H,n command to the appropriate value. While there are some values you can't use there are others where you don't need to apply the OR n command at all and can reduce the routine to 15 bytes. It's a bit like setting up interrupt vector tables, you tend to pick something and code around it...well at least I do :)
True. Although with fonts, I only align them with an 8-byte window boundary (to keep the INC L instruction instead of INC HL for speed). That way I only lose seven bytes at most. Besides, I let the assembler worry about where to stick the font. One less thing to worry about. :P
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
PeterJ
Site Admin
Posts: 6855
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Assembly Help

Post by PeterJ »

Thanks for all the replies guys.
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: Assembly Help

Post by AndyC »

Ast A. Moore wrote: Mon Dec 03, 2018 7:46 pm
Bizzley wrote: Mon Dec 03, 2018 7:37 pm Not really. As long as you're careful on what specific page boundary you put the font then it's just a matter of changing the LD H,n command to the appropriate value. While there are some values you can't use there are others where you don't need to apply the OR n command at all and can reduce the routine to 15 bytes. It's a bit like setting up interrupt vector tables, you tend to pick something and code around it...well at least I do :)
True. Although with fonts, I only align them with an 8-byte window boundary (to keep the INC L instruction instead of INC HL for speed). That way I only lose seven bytes at most. Besides, I let the assembler worry about where to stick the font. One less thing to worry about. :P
I normally find I have enough 256-byte aligned tables that adding another doesn't actually lose any bytes.
User avatar
Ivanzx
Manic Miner
Posts: 736
Joined: Tue Nov 14, 2017 9:51 am

Re: Assembly Help

Post by Ivanzx »

Aaaaaaaaand, what game are you coding? :)
namco
Manic Miner
Posts: 247
Joined: Mon Dec 04, 2017 8:55 pm

Re: Assembly Help

Post by namco »

Here's my RST command for Print At. I'm currently using this on the ZX Spectrum Next to check on the number in my sprite rotation.:

Code: Select all

ld a,22 ; Set A with PRINT AT command
rst 10h ; Call

ld a,10 ; Set A with 7 (Y coord)
rst 10h

ld a,10 ; Set A with 8 (X coord)
rst 10h

ld a,0
ld a,(rightplayer)
ld bc,0
ld c,a
call 6683
User avatar
PeterJ
Site Admin
Posts: 6855
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Assembly Help

Post by PeterJ »

Ivanzx wrote: Mon Dec 03, 2018 8:45 pm Aaaaaaaaand, what game are you coding? :)
Its a simple platform game. Nothing that will shake the world, but I try and get back to developing it when I can.
User avatar
Cosmium
Microbot
Posts: 154
Joined: Tue Dec 04, 2018 10:20 pm
Location: USA

Re: Assembly Help

Post by Cosmium »

PeterJ wrote: Mon Dec 03, 2018 1:25 pm Hi,

I'm coming back to working on my game, and because I have left it so long I seem to have forgotten so much!
Hi Peter - I know the feeling! Six months ago I was in a similar position to you and a bit rusty on the Z80 having not touched it since the early 1990s. But it's funny how quickly it comes back. Really enjoyable to be back on this 8-bit processor.

Good luck completing your game!

Cosmium
Post Reply