[SOLVED] Famitone2 - MMC3 banked songs

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.
User avatar
wonder
Posts: 46
Joined: Sat Aug 31, 2019 2:12 pm

Re: [SOLVED] Famitone2 - MMC3 banked songs

Post by wonder » Sat Jul 11, 2020 12:41 am

Good morning! :D

Thank you so much for your suggestions, guys!! :beer:
DRW wrote:
Fri Jul 10, 2020 9:11 pm
By the way:
ZP And ZP_RESERVED overlap each other, so it might happen that two variables use the same memory location and overwrite each other.
Why don't you simply use another segment in ZP for your debug variables?
ZP_RESERVED was a workaround I came-up with for having extern variables on the zeropage, until I finally decided to pay more attention to the CC65 documentation. I don't need it anymore and I use it only for debug purposes. I'll be getting rid of it soon.
What you see on the project shared on GitHub is just a fraction (maybe 3%), of what I'm currently developing... :mrgreen:
DRW wrote:
Fri Jul 10, 2020 9:11 pm
And why does your RAM have such a strange size?
I think I calculated the RAM size by subtracting the other sections, but I will have another look. Thanks for pointing it out!
DRW wrote:
Fri Jul 10, 2020 8:51 pm
If you want my suggestion: Ditch neslib and that crt0 file.

...

But that neslib, as far as I know, simply encapsulates the basic NES functions, like controller reading, waiting for NMI etc. And I think those are things that every NES programmer should know about and understand in its entirety and he should be able to write it himself.
Well, if it wasn't for C and the 8bitworkshop IDE I'd probably haven't gotten into NES development. Being a Python developer is what pays the bills, but on my free time I love messing with C and sometimes C++. My programming path, which started in the 90's when like this:
TurboBASIC --> Visual Basic --> C (in school) --> [10 years without programming at all] --> QBASIC --> Basic4Android --> JNI (Java Interfaced C for Android) --> Python 3 --> C (x86/mainframes) --> C++ --> C (NES) --> ASM (NES) :lol:

So while I replace some of the neslib functions with my own ASM every now and then, I don't see myself yet replacing the entire thing (yet).
Nevertheless, I always look at the listings and try to understand how everything works and how I can make improvements.

On the low-level part of my NES project I have someone collaborating with me every now and then, so we might join forces again to improve on the assembly side.
aa-dav wrote:
Fri Jul 10, 2020 5:23 pm
I would make minimal architecture changes.
For example to contain all chages in neslib.s, not commenting call to FamiToneUpdate, but placing bank switch there.
Yes, I agree. I was thinking about writing some kind of MMC3 wrapper/header for the famitone lib, which would be completely independent from the other modules.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

I admit that I need to improve my low-level knowledge of the NES and it's really embarrassing when I get stuck just because something is not working on the assembly side. Thank you so much for your patience to teach n00bs like me!!! :beer: :beer: :beer:
Image

User avatar
wonder
Posts: 46
Joined: Sat Aug 31, 2019 2:12 pm

Re: [SOLVED] Famitone2 - MMC3 banked songs

Post by wonder » Sat Jul 11, 2020 12:47 am

By the way, this is what's cooking in the oven:
https://www.youtube.com/watch?v=jhX_V3weWi0

Image
Image

User avatar
DRW
Posts: 1976
Joined: Sat Sep 07, 2013 2:59 pm

Re: [SOLVED] Famitone2 - MMC3 banked songs

Post by DRW » Sat Jul 11, 2020 4:50 am

wonder wrote:
Sat Jul 11, 2020 12:41 am
ZP_RESERVED was a workaround I came-up with for having extern variables on the zeropage, until I finally decided to pay more attention to the CC65 documentation. I don't need it anymore and I use it only for debug purposes. I'll be getting rid of it soon.
Debug purposes or not: It still overlaps. If you want to use memory that starts at address $FA, you need to reduce the size of ZP accordingly.

wonder wrote:
Sat Jul 11, 2020 12:41 am
I think I calculated the RAM size by subtracting the other sections, but I will have another look. Thanks for pointing it out!
What other sections do you mean?

The RAM is 2KB, i.e. $800 bytes.

$0000..$00FF --> Zeropage
$0100..$01FF --> Hardware stack
$0200..$02FF --> Sprites
$0300..$07FF --> Regular RAM

Since you're working with C, you need to create a software stack, so you also need to subtract the software stack size from the RAM size accordingly.

But this can all be done cleanly with constants instead of calculating the values by hand:
STACKSIZE = $0100 (increase or reduce accordingly)
RAMSTART = $0300
RAMSIZE = $0800 - RAMSTART - STACKSIZE
STACKSTART = RAMSTART + RAMSIZE

wonder wrote:
Sat Jul 11, 2020 12:41 am
Well, if it wasn't for C and the 8bitworkshop IDE I'd probably haven't gotten into NES development. Being a Python developer is what pays the bills, but on my free time I love messing with C and sometimes C++. My programming path, which started in the 90's when like this:
TurboBASIC --> Visual Basic --> C (in school) --> [10 years without programming at all] --> QBASIC --> Basic4Android --> JNI (Java Interfaced C for Android) --> Python 3 --> C (x86/mainframes) --> C++ --> C (NES) --> ASM (NES) :lol:
It's similar with me as well. I'm mainly a C, C++ and C# developer. And I would never have the patience to write an entire NES game in Assembly.

But when I started with NES development, even though I planned to use cc64, I first learned the basics of 6502 Assembly. (Most of my code is C, but I can read and write Assembly code now and a bunch of general-purpose functions are written in Assembly in my games.)

I want all of the code in the game to be mine and I want to understand the underlying architecture.

The external sound library is an exception and a necessity because a programmer doesn't have to be a music buff. (However, I do know how the APU works. This way, I was able to include a music fadeout by manipulating the volume bits in FamiTone's final APU buffer variables.)


Those workshop examples are good for people with a beginner's level knowledge of programming, to quickly put something on the screen.
But for somebody who is a professional programmer in high level languages, I would suggest: First learn the basics. Before you even touch C for the NES, put some background tiles on the screen and move a single hardware sprite with the D-pad. This way you know how the entirety of the game is working.

In my games, I don't even have a void main(void) function.
I have the reset interrupt that handles global preparations, controller reading, some other stuff and the infinite loop, including waiting for NMI accordingly.

And in the middle of this interrupt, I call ProcessNextFrame which is the first C function. But that function cannot be identified as main because it doesn't read the controller anymore and it has no do { } while(true); loop, but gets called anew every frame.
My game "City Trouble": www.denny-r-walter.de/city.htm

User avatar
aa-dav
Posts: 89
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: [SOLVED] Famitone2 - MMC3 banked songs

Post by aa-dav » Mon Jul 13, 2020 2:44 am

wonder wrote:
Sat Jul 11, 2020 12:47 am
By the way, this is what's cooking in the oven:
It looks very cool!
I like idea of little game characters. Map looks big and many layers of labyrinth are possible.
I want to create something similar.

User avatar
wonder
Posts: 46
Joined: Sat Aug 31, 2019 2:12 pm

Re: [SOLVED] Famitone2 - MMC3 banked songs

Post by wonder » Thu Jul 16, 2020 4:21 am

aa-dav wrote:
Mon Jul 13, 2020 2:44 am
wonder wrote:
Sat Jul 11, 2020 12:47 am
By the way, this is what's cooking in the oven:
It looks very cool!
I like idea of little game characters. Map looks big and many layers of labyrinth are possible.
I want to create something similar.
Thank you so such!! A demo can be found here:
viewtopic.php?f=22&t=20401&p=252251#p252251
DRW wrote:
Sat Jul 11, 2020 4:50 am
Since you're working with C, you need to create a software stack, so you also need to subtract the software stack size from the RAM size accordingly.

But this can all be done cleanly with constants instead of calculating the values by hand:
STACKSIZE = $0100 (increase or reduce accordingly)
RAMSTART = $0300
RAMSIZE = $0800 - RAMSTART - STACKSIZE
STACKSTART = RAMSTART + RAMSIZE
I did this and it works great!!! Thank you so much!! :)
Image

coto
Posts: 46
Joined: Wed Mar 06, 2019 6:00 pm
Location: Chile

Re: [SOLVED] Famitone2 - MMC3 banked songs

Post by coto » Thu Jul 16, 2020 7:08 am

DRW wrote:
Sat Jul 11, 2020 4:50 am
It's similar with me as well. I'm mainly a C, C++ and C# developer. And I would never have the patience to write an entire NES game in Assembly.
May be a bit off topic, but I pretty much agree with your thoughts. I'd rather write some entirely useful piece of software in a higher level language than to lose my mind over software layout (where applicable, because i'd use that software layout design effort in game AI). Besides there are good debugging tools for C > languages, such as GDB, which is very useful if one wants to test programs on real hardware.

Post Reply