Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Trying to draw sprites

Reply to topic
Author Message
  • Joined: 03 Dec 2021
  • Posts: 54
Reply with quote
Trying to draw sprites
Post Posted: Tue Aug 23, 2022 9:03 pm
Hello everyone,

I am trying to draw one sprite made up of 3X4 tiles to the screen.

I had a first success in defining the SAT bytes one by one (first YXN bytes, second XYN bytes).

I moved on trying to automate things a bit and the result (of course) got super messy.

I share the sources of my code:
- sprite_demo_v1.asm is the first manual attempt, which resulted in picture output_v1.png (only first 2 out of 12 sprite tiles are drawn for simplicity).
- sprite_demo_v2.asm is my second attempt which resulted in the mess that is picture output_v2.png

Does anyone have any hint to solve the problem?

P.S. I am using VASM assembler to compile.

Thank you in advance!

output_v1.png



output_v2.png


output_v1.png (25.67 KB)
output_v1.png
output_v2.png (29.41 KB)
output_v2.png
sprite_demo.zip (5.57 KB)

  View user's profile Send private message
  • Joined: 06 Mar 2022
  • Posts: 594
  • Location: London, UK
Reply with quote
Post Posted: Wed Aug 24, 2022 9:35 am
Hey umbe, I've had a quick glance at your code although haven't had the chance to install vasm and assemble.

Firstly, are you in a position where you're debugging this stuff? Emulicious has an extremely fully-featured debugger which I think would help get you further down the track.

From a quick code inspection, I'm not sure your `PlayerSprX` or `PlayerSprN` routines do what you want them to. `PlayerSprY` I think is okay, but I'm not 100% convinced.

Looks like `PlayerSprX` is adding 8 to the a register (which is the x coordinate) three times and writing out each byte consecutively to $3f80, but you actually want to be writing three pairs of bytes - three x coordinates and 3 tile indexes. Your incrementing of hl appears to do nothing in this routine, as hl is not involved in any of the other operations, and you overwrite it afterwards.

`PlayerSprN` I'm fairly confused about, it looks like you start off writing to $3f81, which presumably will overwrite the X coordinates you already tried to write with `PlayerSprX`. You also don't appear to be writing any Y coordinates for the "N" sprites. Otherwise, `PlayerSprN` looks like you intended it to be just a block copy from memory to the VDP_Data port, which could almost certainly have been accomplished with an `otir`, although you are for some reason incrementing hl twice each time, effectively copying only every other byte - is this what you intended?

A couple of selected side notes:

- I would encourage use of `otir` and `outi` as much as possible for this kind of stuff; if you can use them, they cut overall byte size, potentially can be faster, and most certainly make for more readable code.

- It's quite conventional to build a copy of your SAT in RAM and block copy it to VRAM every frame. I know it might seem like a hassle, and I know you're currently setting up the SAT with the display off and then turning it on, but for big SATs it means that you can maximise the time in blanking to send data to the VDP because you've already done the hard work of figuring out which bytes go where in the SAT. Block copying is relatively quicker than random access because you don't need to reset the address pointer all the time. Also, and importantly here, I think you'll find that separating the logic of what the SAT needs to look like from the logic of actually sending the bytes to the VDP will clean up your code and make it considerably easier to reason about.
  View user's profile Send private message Visit poster's website
  • Joined: 03 Dec 2021
  • Posts: 54
Reply with quote
Post Posted: Wed Aug 24, 2022 7:16 pm
Last edited by umbe1987 on Thu Aug 25, 2022 5:54 am; edited 1 time in total
Hi @willbritton and thank you so much for always be so supportive and helpful!

I have installed Emulicious and I think it's great! Thanks to its Memory Editor I can see what is wrong in my code by looking at the bytes from $3f00.
I know what I have to do, but it's still hard for me to translate it into actual code. However, with this tool and a bit of more study I am pretty sure I will figure it out.

Thanks also for the suggestion! I am aware that this is not the "right" way of drawing sprites, since thanks to hang-on tutorial I know it's better to keep a SAT buffer, update that and load it into the real SAT during VBlank (I hope this is correct :) ). I am still progressing steb-by-step and after I will draw my sprite "the dirty way" I will do this for sure.

Finally, this is how the final SAT is supposed to look:

3F00 $60 $60 $60 $68 $68 $68 $70 $70 $70 $78 $78 $78 $00 $00 $00 $00
3F10 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3F20 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3F30 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3F40 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3F50 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3F60 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3F70 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3F80 $80 $00 $88 $01 $90 $02 $80 $03 $88 $04 $90 $05 $80 $06 $88 $07
3F90 $90 $08 $80 $09 $88 $0A $90 $0B $00 $00 $00 $00 $00 $00 $00 $00
3FA0 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3FB0 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3FC0 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3FD0 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3FE0 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
3FF0 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
  View user's profile Send private message
  • Joined: 03 Dec 2021
  • Posts: 54
Reply with quote
Post Posted: Wed Aug 24, 2022 10:49 pm
And finally!!!!!



Man that was hard...
Of course what I was doing at the beginning was completely non sense :)

I upload the sources just in case anyone is curious, but please don't use them for studying purposes, I am sure I made lots of mistakes!

I will try to clean the code and integrate @willbritton suggestions for sure (again, thanks!).

Moving on...
sonic.png (14.12 KB)
sonic.png
sprite_demo.zip (3.81 KB)

  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!