Famicom World

Family Computer => Famicom / Disk System => Topic started by: zmaster18 on March 31, 2016, 10:13:26 am

Title: Family BASIC sprites in assembly?
Post by: zmaster18 on March 31, 2016, 10:13:26 am
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.
Title: Re: Family BASIC sprites in assembly?
Post by: UglyJoe on March 31, 2016, 10:42:55 am
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.
Title: Re: Family BASIC sprites in assembly?
Post by: P on March 31, 2016, 01:15:12 pm
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 (http://wiki.nesdev.com/w/index.php/PPU_registers#OAMDMA) 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.
Title: Re: Family BASIC sprites in assembly?
Post by: zmaster18 on March 31, 2016, 01:21:43 pm
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 (http://wiki.nesdev.com/w/index.php/PPU_registers#OAMDMA) 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!
Title: Re: Family BASIC sprites in assembly?
Post by: UglyJoe on March 31, 2016, 01:29:41 pm
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.
Title: Re: Family BASIC sprites in assembly?
Post by: P on March 31, 2016, 01:54:22 pm
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.
Title: Re: Family BASIC sprites in assembly?
Post by: UglyJoe on March 31, 2016, 02:03:53 pm
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.
Title: Re: Family BASIC sprites in assembly?
Post by: zmaster18 on March 31, 2016, 05:47:50 pm
Then I'm going to do Nerdy Nights and practice in BASIC :)
Title: Re: Family BASIC sprites in assembly?
Post by: 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.
Title: Re: Family BASIC sprites in assembly?
Post by: zmaster18 on April 01, 2016, 08:54:34 am
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 :)
Title: Re: Family BASIC sprites in assembly?
Post by: P on April 03, 2016, 03:39:47 am
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. ???