Family BASIC sprites in assembly?

Started by zmaster18, March 31, 2016, 10:13:26 am

Previous topic - Next topic

zmaster18

Does anyone know how to control sprites with assembly in BASIC? I need to define up to 16 8x8 sprites, but BASIC only lets you define up to 8 with DEF SPRITE.

UglyJoe

You would do it the same way you control sprites outside of BASIC.

I suspect that the BASIC interpreter code would mess with your sprites, though.

P

March 31, 2016, 01:15:12 pm #2 Last Edit: April 03, 2016, 03:28:55 am by P
Usually you reserve a place in RAM as an OAM buffer (OAM = Object Attribute Memory, PPU register where the sprite attributes on screen are stored) and then use $4014 to fire off a DMA which copies all the sprites for you to the PPU/TV. Most games uses RAM address $0200 as an OAM buffer.

You could also copy all the sprite attribute data manually, using PPU port $2004, but it's much slower (I never tried it though).

Sprite attribute data (or object attribute data as Nintendo calls it in their dev manuals) means all the sprite data like x-position, y-position, CHR address and which palette it's using etc.

zmaster18

Quote from: P on March 31, 2016, 01:15:12 pm
Usually you use reserve a place in RAM as an OAM buffer (OAM = Object Attribute Memory, PPU register where the sprite attributes on screen are stored) and then use PPU port $4014 to fire off a DMA which copies all the sprites for you to the PPU/TV. Most games uses RAM address $0200 as an OAM buffer.

You could also copy all the sprite attribute data manually, using PPU port $2004, but it's much slower (I never tried it though).

Sprite attribute data (or object attribute data as Nintendo calls it in their dev manuals) means all the sprite data like x-position, y-position, CHR address and which palette it's using etc.

So I make all my sprite data and store it in an OAM buffer at $0200 and then POKE the sprites I want to display at $4014? Can you show me how this is done? :) I really wish there was a good resource to learn how to POKE assembly in BASIC and do advanced tricks!

UglyJoe

Quote from: zmaster18 on March 31, 2016, 01:21:43 pm
I really wish there was a good resource to learn how to POKE assembly in BASIC and do advanced tricks!


When I've used it, I created a tiny homebrew ROM first to test out my assembly code.  Once it was working, I grabbed the hex for the code and converted it to POKE calls.

P

Using inline assembly isn't really advanced tricks in BASIC, it's just using assembly. I showed before how to poke in an easy assembly program. I also coded a tiny homebrew ROM on my computer and tested it over and over until it worked, before I started poking it in Family BASIC.

If you are going to use any assembly at all, there's no way around learning the basics of Famicom assembly. Nerdy Nights is the best guide for beginners I know of, just be persistent and ask about things you don't understand.

Advanced poking tricks (like how to use greyscale mode which doesn't have a BASIC command) is just using knowledge of how to use the various CPU registers, something you'll learn when you learn to use assembly.

UglyJoe

Quote from: P on March 31, 2016, 01:54:22 pmNerdy Nights is the best guide for beginners I know of


+1.  I never finished it, but it was a good tutorial.  It got me far enough to get my ROB control code written.

zmaster18

Then I'm going to do Nerdy Nights and practice in BASIC :)

P

That's the spirit!

Testing in Family BASIC will take a lot of time though, but you could try poking in your code as a subroutine once in while once you got it working in a ROM.

zmaster18

Quote from: P on April 01, 2016, 05:52:51 am
That's the spirit!

Testing in Family BASIC will take a lot of time though, but you could try poking in your code as a subroutine once in while once you got it working in a ROM.

I have read Nerdy Nights part 4 and I think I know what to do! I will post my findings for others to see :)

P

Sprite updates (either using OAM DMA or manually) must be done in vblank like all other graphic updates. Not sure how you could do that in a subroutine that you call in Family BASIC. ???