Update to my tutorial in C

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
dougeff
Posts: 2617
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Update to my tutorial in C

Post by dougeff » Thu Sep 20, 2018 4:20 pm

Does anyone think I should increase the # of metatiles? Currently my code can use up to 51 (5 bytes each). But with a slight modification, that could be 102.

In my mind (before) you could swap metatile definitions for each type of level. I thought 51 should be enough.

Just wondering what other people think.
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
Banshaku
Posts: 2328
Joined: Tue Jun 24, 2008 8:38 pm
Location: Fukuoka, Japan
Contact:

Re: Update to my tutorial in C

Post by Banshaku » Thu Sep 20, 2018 5:28 pm

Since it's a tutorial for learning about the nes, yes, it should be fine. Once the user know enough to do things on their own, they can update the code and add those extra metatile they are missing. It should be part of the learning process anyway, to extend to make it work the way you want :)

na_th_an
Posts: 543
Joined: Mon May 27, 2013 9:40 am

Re: Update to my tutorial in C

Post by na_th_an » Fri Sep 21, 2018 12:58 am

Most of my games use 16 or 32 as per "section", I think it's more than enough.

User avatar
gauauu
Posts: 660
Joined: Sat Jan 09, 2016 9:21 pm
Location: Central Illinois, USA
Contact:

Re: Update to my tutorial in C

Post by gauauu » Fri Sep 21, 2018 7:08 am

Banshaku wrote:Since it's a tutorial for learning about the nes, yes, it should be fine. Once the user know enough to do things on their own, they can update the code and add those extra metatile they are missing. It should be part of the learning process anyway, to extend to make it work the way you want :)
Agreed. It's a tutorial, not an all-purpose framework. Arbitrary limitations are fine. People following your tutorials are eventually going to have to learn to do things themselves.

User avatar
dougeff
Posts: 2617
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Update to my tutorial in C

Post by dougeff » Fri Sep 21, 2018 10:38 am

True. Just trying to anticipate "how do I expand your code to do X" questions.
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
dougeff
Posts: 2617
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Update to my tutorial in C

Post by dougeff » Tue Dec 11, 2018 6:55 am

I wrote a function for changing song speed manually (a while back).

It occurred to me today, as I was working on music code, that you could have greater flexibility over song speed, AND not interfere with Fxx effects if you instead adjusted the FT_TEMPO_STEP_L and FT_TEMPO_STEP_H.

Bigger for faster.

I might edit my code... later (I'm busy).
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
dougeff
Posts: 2617
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Update to my tutorial in C

Post by dougeff » Tue Sep 17, 2019 11:25 am

Updated the neslib Sprite functions to remove the "sprid" parts. one sprite is 11% faster, metasprite is 5% faster. fewer passed arguments = faster.
nesdoug.com -- blog/tutorial on programming for the NES

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

Re: Update to my tutorial in C

Post by wonder » Wed Sep 18, 2019 12:30 am

Hi! Thanks for the update! :)

I've been trying to "load" it into 8bitworkshop, but without success yet.
No matter what I do, a reference to the "old" neslib is probably hardcoded somewhere in their IDE.
I'll keep trying, nevertheless.

@Doug, is neslib.h and neslib.s independent from nesdoug.h and nesdoug.s?
Image

User avatar
Memblers
Site Admin
Posts: 3770
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Update to my tutorial in C

Post by Memblers » Wed Sep 18, 2019 12:59 am

wonder wrote: I've been trying to "load" it into 8bitworkshop, but without success yet.
No matter what I do, a reference to the "old" neslib is probably hardcoded somewhere in their IDE.
You could try the LIBARGS special command, put it in the comments like here (but add in crt0, that's for an assembly example):
https://forums.nesdev.com/viewtopic.php ... 15#p242505

It implies that crt0 and neslib are linked by default.

User avatar
dougeff
Posts: 2617
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Update to my tutorial in C

Post by dougeff » Wed Sep 18, 2019 4:13 am

is neslib.h and neslib.s independent from nesdoug.h and nesdoug.s?
Correct. neslib was written by Shiru 6 years. The version in 8bitworkshop is a more recent fork. The version that I use is also an unrelated fork, which I modified yesterday.

nesdoug is code specific to my tutorial, and meant to be a companion library to neslib, which I felt was not complete.

But you can make a complete game without the nesdoug files, you will just not be able to follow my tutorial.
nesdoug.com -- blog/tutorial on programming for the NES

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

Re: Update to my tutorial in C

Post by wonder » Wed Sep 18, 2019 7:15 am

I've started to setup an NES development environment on my Ubuntu VM.

I can compile and run 01_Hello without problems.

Instructions:

Code: Select all

# Install an emulator (eg. Nestopia)
sudo apt install nestopia

# Install CC55
cd $HOME
mkdir -p nes && cd nes
git clone https://github.com/cc65/cc65.git
make

# Add CC65 to your path environment variable
echo '# NesDev' >> $HOME/.bashrc
echo 'export CC65_HOME="$HOME/nes/cc65"' >> $HOME/.bashrc
echo 'export PATH="$PATH:$CC65_HOME/bin"' >> $HOME/.bashrc
Now you can git clone the 01_Hello repository.
The windows file 'compile.bat' won't work here,
so I created a new file named 'compile.sh':

Code: Select all

#!/bin/bash

name="$1"

cc65 -Oirs "$name.c" --add-source
ca65 crt0.s
ca65 "$name.s" -g

ld65 -C nrom_32k_vert.cfg -o "$name.nes" crt0.o "$name.o" nes.lib -Ln labels.txt

rm *.o

mv labels.txt  BUILD/
mv "$name.s"   BUILD/
mv "$name.nes" BUILD/

nestopia "BUILD/$name.nes"
When done, don't forget to

Code: Select all

chmod +x compile.sh
Now it's simple:

Code: Select all

# Assuming 01_Hello exists in 'projects'
cd $HOME/nes/projects
cd 01_Hello
./compile.sh hello
I'll convert the bash script to a Makefile when I have some time. :)
Image

Diskover
Posts: 213
Joined: Thu Nov 24, 2011 7:16 am
Contact:

Re: Update to my tutorial in C

Post by Diskover » Wed Sep 18, 2019 11:15 am

dougeff wrote:Updated the neslib Sprite functions to remove the "sprid" parts. one sprite is 11% faster, metasprite is 5% faster. fewer passed arguments = faster.
Where I download it? I've looked at your github but I don't see it.

User avatar
dougeff
Posts: 2617
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Update to my tutorial in C

Post by dougeff » Wed Sep 18, 2019 1:28 pm

Every tutorial, from 01_Hello to 29_Powerpad.

In main folders, crt0.s changed to include SPRID as an internal variable.

In LIB folders, neslib.h and neslib.s updated. oam_spr() and oam_meta_spr() specifically.
nesdoug.com -- blog/tutorial on programming for the NES

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

Re: Update to my tutorial in C

Post by wonder » Wed Sep 18, 2019 2:43 pm

@Dougeff, in neslib.h you have the following declaration:

Code: Select all

//set sprite in OAM buffer, chrnum is tile, attr is attribute, sprid is offset in OAM in bytes
//returns sprid+4, which is offset for a next sprite
// Note: sprid removed for speed
void __fastcall__ oam_spr(unsigned char x,unsigned char y,unsigned char chrnum,unsigned char attr);
The docstring says it returns something, but the return type is void. I would suggest:

Code: Select all

//set sprite in OAM buffer, chrnum is tile, attr is attribute, sprid is offset in OAM in bytes
//increments the sprid by 4 bytes, which is the offset for the next sprite
// Note: sprid removed for speed
void __fastcall__ oam_spr(unsigned char x,unsigned char y,unsigned char chrnum,unsigned char attr);
Image

User avatar
dougeff
Posts: 2617
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Update to my tutorial in C

Post by dougeff » Wed Sep 18, 2019 4:22 pm

Fixed. Removed old comments about return values.
nesdoug.com -- blog/tutorial on programming for the NES

Post Reply