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 - I'm looking for a simple, very basic sprite demo

Reply to topic
Author Message
  • Joined: 21 Aug 2021
  • Posts: 41
Reply with quote
I'm looking for a simple, very basic sprite demo
Post Posted: Mon Apr 18, 2022 12:26 pm
Hi everyone,

I'm working on a mini game, making progress, but I'm having problems with the sprites.

I'm using 16 by 16 pixel sprites, organized as groups of 4 sprite tiles.

My code works on the "Miracle SMS Emulator", but when I put it on EverDrive for SMS, the sprites behave in a very weird way.
They flicker, and as I move the sprite around, it replaces the bit patterns with random pixels.

The best I get is three of the tiles are displayed correctly (out of 4), while not moving it around.

I believe there's something wrong in my code, but I don't understand why it works on the emulator.

I wonder if you guys could share a link to some simple, very simple project where I can lear how to properly position - and how to properly select the tiles for - a sprite

I know about chibiakumas tutorials, but his examples use multiple source files, and I am working on an Android tablet, so the only Z80 assembler I have is the asm80 website, which only accepts single file projects.

Thanks,

Rui
  View user's profile Send private message
  • Joined: 17 Jun 2017
  • Posts: 19
Reply with quote
Post Posted: Mon Apr 18, 2022 2:02 pm
I don't know of any good examples, but graphical corruption is usually a sign you're running into VDP constraints. Emulators are often more forgiving than the actual hardware and let you get away with more. On real hardware you should usually ensure you're only writing data (like sprites) to VRAM when the display isn't actively being drawn, either when the display is off or during the small window of time known as VBlank when one frame has just finished rendering and the next one hasn't started yet. If you don't, you get odd results like you describe. It's often a good idea to keep a sprite buffer table in RAM which you can write to without restriction, and copy that to VRAM during VBlank.

By the sounds of it you've got sprites moving around which implies you have an update loop set up. If so, have you set up interrupts to achieve this?

A basic lifecycle I use is:

On init:
Ensure display is off
Load assets (patterns, palette, tilemap)
Switch display on
Jump to update loop

Update loop:
Wait for VBlank to finish (poll VDP status)
Update game logic (input, positions)
Update sprites in a buffer in RAM
Restart update loop

On VBlank:
Copy sprite data from RAM buffer to VDP
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3761
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Apr 19, 2022 7:10 am
I would check what appears on Emulicious, with VDP constraints turned on, and see how it differs from what you see on hardware.
Also, the SMS can only display up to 8 sprites on a single scanline so if you see some disappearing when having more of them horizontally aside, that's completely expected...
  View user's profile Send private message Visit poster's website
  • Joined: 21 Aug 2021
  • Posts: 41
Reply with quote
Post Posted: Sat Apr 23, 2022 12:54 pm
Thanks, guys!

I have installed emulicious and done a lot of debugging.
Watching the VRAM 0x3F00-0x3FFF I noticed that the writes to the SAT would skip some values, most of the time.

Then I have added NOP's to my writes to the VDP_Data port, until it worked.

In the end, I am using PUSH AF, followed by POP AF after the writes to the data port - it works like a charm.

Thanks a lot.

Cheers!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3761
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Apr 25, 2022 7:47 am
note that you shouldn't need to add any delay if you're copying data to SAT during the vblank phase, as the VDP has plenty of time to fulfill your writes when it's not busy drawing much on screen...
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!