CPCWiki forum

General Category => Programming => Topic started by: Kitsune Mifune on 10:07, 19 April 19

Title: Display simple sprite on screen
Post by: Kitsune Mifune on 10:07, 19 April 19
I'm taking tiny baby steps to try and get myself acquainted with the Z80 assembler language and all I want to do right now is just put a simple piece of graphics on the screen. Nothing more. I'm reasonably familiar with labelling, and common commands like "ld", and things like "jr" or "jp" to end a loop, and I'm sort of ok with the CPC memory map, although I'm really not sure what it all means.

I've been reading documentation on Z80 heaven on simple sprites (http://z80-heaven.wikidot.com/sprites (http://z80-heaven.wikidot.com/sprites)) and I get the theory but there doesn't seem to be much context for what to actually do with the ball data to get it displayed on the screen.

Correct me if I'm wrong (and I probably am) but I know you have to specify an origin to call and I think it's usually &4000 or &8000 (not quite sure why one or the other is preferable) and then label the sprite data (or have it in a separate asm file that is 'read' in the main code) which is then loaded into a register and then displayed on the screen by somehow referencing the screen memory at &C000.

I've been reverse engineering very small pieces of code that do visual things on the screen and it's helped a lot, but this is the next step and I'd be very grateful for a few tips/corrections.
Title: Re: Display simple sprite on screen
Post by: AMSDOS on 12:29, 19 April 19
This is one of the routines I have from Sean McManus' Easi-Sprite Driver Advance which uses more of a Graphical Coordinate system which the Firmware is used here to convert to a Screen Address.
The information it uses for the "Sprite label" points to 2 initial values which relate to the Height and Width of the Sprite before the Sprite Data. The Height number is the same as the number of Lines, but Width number may vary. For example 8x8 sprite in MODE 0 has a Width of 4 (8/2), MODE 1 has a Width of 2 (8/4) and MODE 2 has a Width of 1 (8/8), so just remember to Divide by 2, 4 or 8 for the Width.


Code: [Select]



org &8000


ld hl,<ypos> ;; Onscreen Coordinates
ld de,<xpos>
call &bc1d ;; Convert Coordinates to Screen Address
push hl ;; Preserve Screen Address
ld de,<sprite> ;; Sprite address in memory
ex de,hl
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ex de,hl
pop hl
.loop1
push bc
push hl
.loop2
ld a,(de)
ld (hl),a
inc hl
inc de
djnz loop2
pop hl
ld bc,&0800
add hl,bc
jr nc,end
ld bc,&c050
add hl,bc
.end
pop bc
dec c
jr nz,loop1
ret


.sprite <height>,<width>,<sprite data>
Title: Re: Display simple sprite on screen
Post by: Kitsune Mifune on 11:56, 20 April 19
Brilliant, I'm off to chew on that piece of code right now! Thanks for all the help!  ;D