- z80 Custom Sprite-Drawing Routine
- 26 Mar 2019 11:36:37 am
- Last edited by Bruce_The_Shark42 on 27 Mar 2019 11:23:07 am; edited 1 time in total
Hey there! Recently I have downloaded Mimas 0.4 onto my TI-84+SE because of reasons that aren't important for what I'm about to ask of you. So just to test myself, I wrote some basic "Hello world" programs and they worked perfectly, but obviously, you can't stay there forever, you have to move somewhere. That's when I started to look and see what other people had created to get an idea of what to do myself and I came across this: https://www.youtube.com/watch?v=31mWIY6NGJw. It's over an hour long, so you don't have to watch the entire thing if you don't want to, but some of the important routines for this post are the ones in the graphics section.
Their names along with inputs, outputs, and other stats are as follows:
Name: gPrint
Inputs: B = x position (0-95), C = y position (0-63)
Outputs: pixel on the screen at (x, y) (origin top left of screen)
Destroyed: AF, BC, DE, HL
Status: Complete
Name: gLine
Inputs: H = x0, L = y0, D = x1, E = y1
Outputs: draws a line from (x0, y0) to (x1, y1)
Destroyed: AF, BC, DE, HL
Status: vertical and horizontal lines work, just need to implement Bresenham's line algorithm for any other line
Name: gSprite
Inputs: HL = address of sprite, B = x position, C = y position, D = sprite width, E = sprite height
Outputs: draws a sprite on the screen at position (x, y) with a given width and height
Destroyed: AF, BC, DE, HL
Status: so far, it draws pixels at the correct place with the correct width and height, but it doesn't get the right data from the sprite (probably me not knowing how exactly the data is stored/how to access it properly)
My question, or rather I'm asking what to do to complete/fix gSprite. I'm not an efficient z80 programmer as I do not yet know all the different things it offers so go easy on me. I know there's better ways to do the things I'm doing, I just don't know what they are yet. Anyways, here's the code:
Code:
EDIT: I don't know why the
Code:
thing didn't work
Their names along with inputs, outputs, and other stats are as follows:
Name: gPrint
Inputs: B = x position (0-95), C = y position (0-63)
Outputs: pixel on the screen at (x, y) (origin top left of screen)
Destroyed: AF, BC, DE, HL
Status: Complete
Name: gLine
Inputs: H = x0, L = y0, D = x1, E = y1
Outputs: draws a line from (x0, y0) to (x1, y1)
Destroyed: AF, BC, DE, HL
Status: vertical and horizontal lines work, just need to implement Bresenham's line algorithm for any other line
Name: gSprite
Inputs: HL = address of sprite, B = x position, C = y position, D = sprite width, E = sprite height
Outputs: draws a sprite on the screen at position (x, y) with a given width and height
Destroyed: AF, BC, DE, HL
Status: so far, it draws pixels at the correct place with the correct width and height, but it doesn't get the right data from the sprite (probably me not knowing how exactly the data is stored/how to access it properly)
My question, or rather I'm asking what to do to complete/fix gSprite. I'm not an efficient z80 programmer as I do not yet know all the different things it offers so go easy on me. I know there's better ways to do the things I'm doing, I just don't know what they are yet. Anyways, here's the code:
Code:
gSprite:
ld a,b
ld (gSpriteSX),a
ld a,c
ld (gSpriteSY),a
ld (gSpriteY),a
ld a,d
ld (gSpriteW),a
ld a,e
ld (gSpriteH),a
push hl
gSpriteLoopY:
ld a,(gSpriteSX)
ld (gSpriteX),a
gSpriteLoopX:
;--------The section I think is wrong---------
pop hl
ld a,(hl)
inc hl
push hl
and %00000001
call z,gSpritePrint
;------------------------------------------------
;gSpriteLoopX check
ld a,(gSpriteW)
ld b,a
ld a,(gSpriteSX)
add a,b
ld b,a
ld a,(gSpriteX)
inc a
ld (gSpriteX),a
sub b
jp nz,gSpriteLoopX
;gSpriteLoopY check
ld a,(gSpriteH)
ld b,a
ld a,(gSpriteSY)
add a,b
ld b,a
ld a,(gSpriteY)
inc a
ld (gSpriteY),a
sub b
jp nz,gSpriteLoopY
pop hl
ret
gSpritePrint:
ld a,(gSpriteX)
ld b,a
ld a,(gSpriteY)
ld c,a
call gPrint
ret
gSpriteX:
dw appBackUpScreen
gSpriteY:
dw gSpriteX+2
gSpriteW:
dw gSpriteY+2
gSpriteH:
dw gSpriteW+2
gSpriteSX:
dw gSpriteH+2
gSpriteSY:
dw gSpriteSX+2
EDIT: I don't know why the
Code: