Page 1 of 3

Sprite Isn't Showing Up

Posted: Sat Aug 08, 2015 4:11 am
by SegaDev
Hi guys,

Still working on my guitar hero like game for the genny. Unfortinately i am having problems getting a single sprite to show even when following the tutorial. There doesn't seem to be any errors so my guess it's an addressing error of some sort.

I am uploading the latest version of my source code for reference.

Sincerely,

SegaDev

Posted: Sat Aug 08, 2015 11:34 am
by ComradeOj
It's there, but it's off screen.

The Y position of the sprite was at $30. Anything less than $80 is off-screen. The X position was also going all over the place, so it would randomly show up, if I altered the Y position to also be on screen.

Posted: Mon Aug 10, 2015 11:32 pm
by SegaDev
ComradeOj wrote:It's there, but it's off screen.

The Y position of the sprite was at $30. Anything less than $80 is off-screen. The X position was also going all over the place, so it would randomly show up, if I altered the Y position to also be on screen.
I altered the x and y position so they both were F0(240) and its still not showing up. I figured out how to check the ram in Genny and managed to see the positions staying constant, so it looks likes i fixed that problem i hope. :cry: I am linking to the latest source code for reference. Any assistance would be greatly appreciated.

Sincerely,

SegaDev

Posted: Tue Aug 11, 2015 11:08 am
by KanedaFr
If I load rom.bin on KMod, I see

1 8x8 sprite at (0, 265), using tile 1792, priority , using pal 1, linked to 0
a brown square

so it's still not visible ;)

Posted: Tue Aug 11, 2015 11:44 pm
by SegaDev
KanedaFr wrote:If I load rom.bin on KMod, I see

1 8x8 sprite at (0, 265), using tile 1792, priority , using pal 1, linked to 0
a brown square

so it's still not visible ;)
Not sure how thats possible so I'll break it down piece by piece:
1 8x8 sprite at (0, 265)
First part is correct, the last part isn't

Code: Select all

globals.asm

; center screen position
centerscreen_position_x:  equ 0x00F0
centerscreen_position_y:  equ 0x00F0

memorymap.asm

; ************************************
; Game globals
; ************************************
cursor_position_x   equ (audio_clock+SizeWord)
cursor_position_y   equ (cursor_position_x+SizeWord)

source.asm
; ************************************
      ; set the cursor position to the center of the screen
      ; ************************************
      move.w #centerscreen_position_x, (cursor_position_x)                     ; Set cursor's x position
      move.w #centerscreen_position_y, (cursor_position_y)                     ; Set cursor's y position
      
      ; ******************************************************************
      ; Main game loop
      ; ******************************************************************
GameLoop:

      jsr WaitVBlankStart                                                      ; Wait for start of vblank

      ; Set cursor's position
      move.w #cursor_id, d0                                                    ; cursor sprite id
      move.w (cursor_position_x), d1                                           ; cursor's x position
      jsr SetSpritePosX                                                        ; Set cursor's x position
      move.w (cursor_position_y), d1                                           ; cursor's y position
      jsr SetSpritePosY                                                        ; Set cursor's y position

      jsr WaitVBlankEnd                                                        ; Wait for end of vblank

      jmp GameLoop        
using tile 1792
That can't be right, I don't even think there's even enough space for that many tiles anyways:

Code: Select all

spritedescriptiors.asm

; Sprite IDs
cursor_id equ 0x0
number_of_sprites equ 0x1

    ; Sprite descriptor structs
sprite_descriptor_table:
cursor_sprite:
      dc.w offscreen_position_y                                                ; Y coord (+ 128)
      dc.b CursorDimensions                                                    ; Width (bits 0-1) and height (bits 2-3) in tiles
      dc.b 0x00                                                                ; Index of next sprite (linked list)
      dc.b 0x00                                                                ; H/V flipping (bits 3/4), palette index (bits 5-6), priority (bit 7)
      dc.b CursorTileID                                                        ; Index of first tile
      dc.w offscreen_position_x                                                ; X coord (+ 128)    
using pal 1, linked to 0 a brown square
Um shouldn't it be palette 0 color 0, and no it's not supposed to be a brown squire it's supposed to be a cursor?

Code: Select all

assets/sprites/cursor.asm

Cursor:

	dc.l	0x00055000                                                         ;    XX   
	dc.l	0x00500500                                                         ;   X  X  
	dc.l	0x05000050                                                         ;  X    X 
	dc.l	0x50000005                                                         ; X      X
	dc.l	0x50000005                                                         ; X      X
	dc.l	0x55500555                                                         ; XXX  XXX
	dc.l	0x00500500                                                         ;   X  X  
	dc.l	0x00555500                                                         ;   XXXX  

assets/palette/palettes.asm

Palette:
	dc.w 0x0000								; Colour 0 - Transparent
	dc.w 0x000E								; Colour 1 - Red
	dc.w 0x00E0								; Colour 2 - Green
	dc.w 0x0E00								; Colour 3 - Blue
	dc.w 0x0000								; Colour 4 - Black
	dc.w 0x0EEE								; Colour 5 - White
	dc.w 0x00EE								; Colour 6 - Yellow
	dc.w 0x008E								; Colour 7 - Orange
	dc.w 0x0E0E								; Colour 8 - Pink
	dc.w 0x0808								; Colour 9 - Purple
	dc.w 0x0444								; Colour A - Dark grey
	dc.w 0x0888								; Colour B - Light grey
	dc.w 0x0EE0								; Colour C - Turquoise
	dc.w 0x000A								; Colour D - Maroon
	dc.w 0x0600								; Colour E - Navy blue
	dc.w 0x0060								; Colour F - Dark green
I can't see how it can be that off as I double checked my code and it's nowhere near what being outputted :( Any assistance in this matter would be greatly appreciated.

Sincerely,

SegaDev

Posted: Wed Aug 12, 2015 12:06 am
by Charles MacDonald
The link to the source code doesn't work anymore.

Have you checked the code that writes data (namely the sprite data) to VRAM is working correctly? For example is the increment value in register $8F set to the right value?

Posted: Wed Aug 12, 2015 1:14 am
by SegaDev
Charles MacDonald wrote:The link to the source code doesn't work anymore.

Have you checked the code that writes data (namely the sprite data) to VRAM is working correctly? For example is the increment value in register $8F set to the right value?
Are you Charles MacDonald, the Charles MacDonald who wrote the Bible on Sega Genesis Programming? If you are then i must be blessed to be around so many famous members of the sega scene. :oops: Anyways about the actual system code, I am using a framework written by BigEvilCorporation. You can read about it here as well as a notation that it's not totally complete so that could be the problem as well. The link works for me so not sure what the problem is. :?: Any assistance in this matter would be greatly appreciated.

Sincerely,

SegaDev

Posted: Wed Aug 12, 2015 5:23 am
by Charles MacDonald
Thanks for the kind words! :D You're right, the link works now so I'll take a peek at the source and check out the framework BigEvilCorporation wrote.

Posted: Wed Aug 12, 2015 8:55 pm
by SegaDev
Charles MacDonald wrote:Thanks for the kind words! :D You're right, the link works now so I'll take a peek at the source and check out the framework BigEvilCorporation wrote.
Your welcome, your famous among the community. Anyways thanks for taking the time to look at the source code and try to figure out whats wrong.

Sincerely,

SegaDev

Update: setting the sprite's y position manually doesn't seem to work
Update 2: Neither does setting the tile id manually

Posted: Fri Aug 14, 2015 4:42 am
by gasega68k
I think the problem is here:

Code: Select all

GameLoop:

      jsr WaitVBlankStart                                                      ; Wait for start of vblank

      ; Set cursor's position
      move.w #cursor_id, d0                                                    ; cursor sprite id
      move.w (cursor_position_x), d1                                           ; cursor's x position
      jsr SetSpritePosX                                                        ; Set cursor's x position
      move.w (cursor_position_y), d1                                           ; cursor's y position
      jsr SetSpritePosY                                                        ; Set cursor's y position

      jsr WaitVBlankEnd                                                        ; Wait for end of vblank

      jmp GameLoop 

The "SetSpritePosX" and "SetSpritePosY" routines need several regs:

Code: Select all

SetSpritePosX:
	; Set sprite X position
	; d0 (b)  - Sprite ID
	; d1 (w)  - X coord
	; d2 (bb) - Sprite dimensions (width/height in subsprites)
	; d3 (w)  - Sprite width (pixels)
	; d4 (b)  - X flipped
	; a1 ---- - Subsprite dimensions array
	;......................................


SetSpritePosY:
	; Set sprite Y position
	; d0 (b)  - Sprite ID
	; d1 (w)  - Y coord
	; d2 (bb) - Sprite dimensions (width/height in subsprites)
	; d3 (w)  - Sprite height (pixels)
	; d4 (b)  - Y flipped
	; a1 ---- - Subsprite dimensions array
	;......................................
and you're just using d0 and d1. :wink:

Posted: Fri Aug 14, 2015 12:13 pm
by BigEvilCorporation
Ahh yes, that's a fairly new attempt at making it support multiple sprites and subsprites in any combination, it'll need a bit more info to work out the positions of each sprite.

Here's some example params:

Code: Select all


Sprite_SonicDimensions: equ 0x0202	; 2x2 subsprites
Sprite_SonicSizeS:      equ 4		; Sprite size in 4x4 subsprites

; Subsprite dimensions
Sprite_SonicSSDimensions:
	dc.w 0x0404	; Top-left     (4x4)
	dc.w 0x0401	; Bottom-left  (4x1)
	dc.w 0x0104	; Top-right    (1x4)
	dc.w 0x0101	; Bottom-right (1x1)
	even

; Subsprite dimension bits (for sprite descs)
Sprite_SonicSSDimensionBits:
	dc.b (%00001111)	; Top-left     (4x4)
	dc.b (%00001100)	; Bottom-left  (4x1)
	dc.b (%00000011)	; Top-right    (1x4)
	dc.b (%00000000)	; Bottom-right (1x1)
	even
	
; Num tiles per subsprite (for sprite descs)
Sprite_SonicSSTiles:
	dc.b 0x10	; Top-left
	dc.b 0x4	; Bottom-left
	dc.b 0x4	; Top-right
	dc.b 0x1	; Bottom-right
	even

I've afraid it's not as simple as it used to be, perhaps you could revive the old subroutines (from my blog) and keep them around.

Posted: Sat Aug 15, 2015 6:33 pm
by SegaDev
BigEvilCorporation wrote:Ahh yes, that's a fairly new attempt at making it support multiple sprites and subsprites in any combination, it'll need a bit more info to work out the positions of each sprite.

Here's some example params:

Code: Select all


Sprite_SonicDimensions: equ 0x0202	; 2x2 subsprites
Sprite_SonicSizeS:      equ 4		; Sprite size in 4x4 subsprites

; Subsprite dimensions
Sprite_SonicSSDimensions:
	dc.w 0x0404	; Top-left     (4x4)
	dc.w 0x0401	; Bottom-left  (4x1)
	dc.w 0x0104	; Top-right    (1x4)
	dc.w 0x0101	; Bottom-right (1x1)
	even

; Subsprite dimension bits (for sprite descs)
Sprite_SonicSSDimensionBits:
	dc.b (%00001111)	; Top-left     (4x4)
	dc.b (%00001100)	; Bottom-left  (4x1)
	dc.b (%00000011)	; Top-right    (1x4)
	dc.b (%00000000)	; Bottom-right (1x1)
	even
	
; Num tiles per subsprite (for sprite descs)
Sprite_SonicSSTiles:
	dc.b 0x10	; Top-left
	dc.b 0x4	; Bottom-left
	dc.b 0x4	; Top-right
	dc.b 0x1	; Bottom-right
	even

I've afraid it's not as simple as it used to be, perhaps you could revive the old subroutines (from my blog) and keep them around.
Nope, same thing as before using the new code:

Code: Select all

===============================================
cursor.asm
===============================================
Cursor:

      dc.l	0x00055000                                                         ;    XX   
      dc.l	0x00500500                                                         ;   X  X  
      dc.l	0x05000050                                                         ;  X    X 
      dc.l	0x50000005                                                         ; X      X
      dc.l	0x50000005                                                         ; X      X
      dc.l	0x55500555                                                         ; XXX  XXX
      dc.l	0x00500500                                                         ;   X  X  
      dc.l	0x00555500                                                         ;   XXXX  

CursorEnd                                                                       ; Sprite end address
CursorSizeS: equ 4                                                             ; Sprite size in 4x4 subsprites
CursorSizeB: equ (CursorEnd-Cursor)                                            ; Sprite size in bytes
CursorSizeW: equ (CursorSizeB/2)                                               ; Sprite size in words
CursorSizeL: equ (CursorSizeB/4)                                               ; Sprite size in longs
CursorSizeT: equ (CursorSizeB/32)                                              ; Sprite size in tiles
CursorTileID: equ (CursorVRAM/32)                                              ; ID of first tile
CursorDimensions: equ (%00000000)                                              ; Sprite dimensions (1x1)
CursorWidth: equ 0x08                                                          ; cursor width in pixels
CursorHeight: equ 0x08                                                         ; cursor height in pixels

; Subsprite dimensions
CursorSubSpriteDimensions:
      dc.w 0x0101                                                              ; Top-left     (1x1)
      dc.w 0x0101                                                              ; Bottom-left  (1x1)
      dc.w 0x0101                                                              ; Top-right    (1x1)
      dc.w 0x0101                                                              ; Bottom-right (1x1)

===============================================
spritedescriptors.asm
===============================================
; Sprite IDs
cursor_id equ 0x0
number_of_sprites equ 0x1

    ; Sprite descriptor structs
sprite_descriptor_table:
cursor_sprite:
      dc.w offscreen_position_y                                                ; Y coord (+ 128)
      dc.b CursorDimensions                                                    ; Width (bits 0-1) and height (bits 2-3) in tiles
      dc.b 0x00                                                                ; Index of next sprite (linked list)
      dc.b 0x00                                                                ; H/V flipping (bits 3/4), palette index (bits 5-6), priority (bit 7)
      dc.b CursorTileID                                                        ; Index of first tile
      dc.w offscreen_position_x                                                ; X coord (+ 128)

; Subsprite dimension bits
CursorSubSpriteDimensionBits:
      dc.b (%00000000)   ; Top-left     (1x1)
      dc.b (%00000000)   ; Bottom-left  (1x1)
      dc.b (%00000000)   ; Top-right    (1x1)
      dc.b (%00000000)   ; Bottom-right (1x1)

   
; Num tiles per subsprite
CursorSubSpriteTiles:
      dc.b 0x1                                                                 ; Top-left
      dc.b 0x1                                                                 ; Bottom-left
      dc.b 0x1                                                                 ; Top-right
      dc.b 0x1                                                                 ; Bottom-right 

==============================================
source.asm
==============================================
; Set cursor's position
      move.b #cursor_id, d0                                                    ; cursor sprite id
      move.w (cursor_position_x), d1                                           ; cursor's x position
      move.b CursorDimensions, d2                                              ; cursor's dimensions
      move.w #CursorWidth, d3                                                  ; cursor's width in pixels
      move.b #0x00, d4                                                         ; cursor's x flipped
      lea CursorSubSpriteDimensions, a1                                        ; cursor's subsprite 
      jsr SetSpritePosX                                                        ; Set cursor's x position
      move.w (cursor_position_y), d1                                           ; cursor's y position
      move.w #CursorHeight, d3                                                 ; cursor's width in pixels
      jsr SetSpritePosY                                                        ; Set cursor's y position

      jsr WaitVBlankEnd                                                        ; Wait for end of vblank

      jmp GameLoop   
Any assistance in this matter would be greatly appreciated.

Sincerely,

SegaDev

Posted: Mon Aug 17, 2015 8:44 am
by BigEvilCorporation
Ok, I'll debug it when I get home from work this evening :)

Posted: Mon Aug 17, 2015 10:32 pm
by BigEvilCorporation
Seems fine here after all the suggestions above. ComadeOj was correct, it was just off screen:

Image

Apologies for the not-so-simple SpriteSetPos subroutines, the new ones were to support massive sprites made up of arbitrary sizes subsprites. I should have kept the simpler ones and named these something else :)

Here's the working code: https://www.mediafire.com/?4krszlil86b60s6

(you'll need to restore your build.bat file, I wrote over it sorry!)

Posted: Tue Aug 18, 2015 3:12 am
by SegaDev
BigEvilCorporation wrote:Seems fine here after all the suggestions above. ComadeOj was correct, it was just off screen:

Image

Apologies for the not-so-simple SpriteSetPos subroutines, the new ones were to support massive sprites made up of arbitrary sizes subsprites. I should have kept the simpler ones and named these something else :)

Here's the working code: https://www.mediafire.com/?4krszlil86b60s6

(you'll need to restore your build.bat file, I wrote over it sorry!)
That worked for me so i started modifying my code so it would match yours. Unfortunately it only seemed to work halfway as the x and y positions are correct and fixed but the tile id and priority are still bugged. I used WinMerge to compare my source code to yours and the only differences were the naming conventions used(CursorSubSpriteDimensions vs. CursorSSDimensions). I am attaching a link to the source code in hopes you can figure out how i messed it up :P. Also no problem with the subscrites thing, your heart was in the right place in making it easier for others to create bigger sprites without all the fuss. Any assistance in this matter would be greatly appreciated.

Sincerely,

SegaDev