Page 2 of 2

Re: Update to my tutorial in C

Posted: Thu Sep 20, 2018 4:20 pm
by dougeff
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.

Re: Update to my tutorial in C

Posted: Thu Sep 20, 2018 5:28 pm
by Banshaku
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 :)

Re: Update to my tutorial in C

Posted: Fri Sep 21, 2018 12:58 am
by na_th_an
Most of my games use 16 or 32 as per "section", I think it's more than enough.

Re: Update to my tutorial in C

Posted: Fri Sep 21, 2018 7:08 am
by gauauu
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.

Re: Update to my tutorial in C

Posted: Fri Sep 21, 2018 10:38 am
by dougeff
True. Just trying to anticipate "how do I expand your code to do X" questions.

Re: Update to my tutorial in C

Posted: Tue Dec 11, 2018 6:55 am
by dougeff
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).

Re: Update to my tutorial in C

Posted: Tue Sep 17, 2019 11:25 am
by dougeff
Updated the neslib Sprite functions to remove the "sprid" parts. one sprite is 11% faster, metasprite is 5% faster. fewer passed arguments = faster.

Re: Update to my tutorial in C

Posted: Wed Sep 18, 2019 12:30 am
by wonder
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?

Re: Update to my tutorial in C

Posted: Wed Sep 18, 2019 12:59 am
by Memblers
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.

Re: Update to my tutorial in C

Posted: Wed Sep 18, 2019 4:13 am
by dougeff
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.

Re: Update to my tutorial in C

Posted: Wed Sep 18, 2019 7:15 am
by wonder
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. :)

Re: Update to my tutorial in C

Posted: Wed Sep 18, 2019 11:15 am
by Diskover
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.

Re: Update to my tutorial in C

Posted: Wed Sep 18, 2019 1:28 pm
by dougeff
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.

Re: Update to my tutorial in C

Posted: Wed Sep 18, 2019 2:43 pm
by wonder
@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);

Re: Update to my tutorial in C

Posted: Wed Sep 18, 2019 4:22 pm
by dougeff
Fixed. Removed old comments about return values.