KNES library for CC65 (aka Programming the NES in C)

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

Moderator: Moderators

3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

thefox wrote:
65024U wrote:wouldn't a BASIC-type OS that also could translate to 6502 ASM on the same system work a bit better then C?
Work better in what sense? :) I think it's bit of an apples and oranges situation...

Well....compile better. Because basic would need more commands, but each one would translate into less instuructions and allow for more editable code to be written, not running whole functions and such....but what do I know. I just know TRS-80 basic isn't too bad! :P



I'm going to have to get into this some time....and the hit detection would be nasty to write in BASIC I guess....maybe this would be alot better? Anyway this is really cool.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Then perhaps we need a scripting language with specialized data types for games. These might include points and rectangles, where operator AND performs intersection: rect AND point returns true iff point is within rect, and rect AND rect returns their intersection. Then hit detection would be a matter of computing two objects' hitboxes and ANDing them together.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Well, not need...but like that.....more lightweight functions. The C program can do it though so maybe this'll get easier like basic as it goes, who knows? :P
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

Another issue with C is debugging. If you have a bug in your C code, it will be harder to find in FCEU's debugger than if you did an error in your assembly code.
Useless, lumbering half-wits don't scare us.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Bregalad wrote:Another issue with C is debugging. If you have a bug in your C code, it will be harder to find in FCEU's debugger than if you did an error in your assembly code.
Great point. I have a hard time understanding my assembly. I'd hate to run through a compilers! :shock:
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Post by thefox »

Bregalad wrote:Another issue with C is debugging. If you have a bug in your C code, it will be harder to find in FCEU's debugger than if you did an error in your assembly code.
http://nesdev.com/bbs/viewtopic.php?t=6773

Works fine with C sources too. I'm not sure about the version posted there but I have it working here...
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Any debugger that allows importing a file with labels and comments can in theory be used for source-level debugging.
Chainclaw
Posts: 4
Joined: Wed Jan 26, 2011 10:30 pm

Post by Chainclaw »

Hey, this demo is awesome, and really got me moving on getting some NES development started. I'm learning a lot, and having a completed demo like this with player movement, scrolling, and collision is fantastic. I'll probably make a thread in the new users forum soon with specific questions about getting things to happen in this demo, things like how do I generate new levels for this, or how do I fully implement left scrolling.
dirtyHippy
Posts: 2
Joined: Fri Mar 04, 2011 4:22 pm

Post by dirtyHippy »

Greetings, I am having trouble getting knes working - I'm sure it's something simple that I'm overlooking. My process so far has been:
* Install cc65 from the latest snapshot, set up w/ env variables etc
* Copy nes.lib from cc65 into knes/original, make knes
* Copy knes.lib and knes.h, nes-nrom.cfg into appropriate folders
* Edit nes-nrom.cfg as per this post
* Copy header.h and header.c to my project directory
* Attempt to compile my project:

Code: Select all

//HAI2.c

#include "conio.h"
#include "knes.h"

int main(void) {
	clrscr();
	cprintf("OHI");
	while(1) {}
	return 0;
}

Code: Select all

cl65 -t none -C nes-nrom.cfg -o HAI2.nes HAI2.c header.c knes.lib 
Unresolved external `_clrscr' referenced in:
  HAI2.s(14)
Unresolved external `_cputc' referenced in:
  vcprintf.s(9)
Any ideas as to what I'm missing?
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Post by thefox »

dirtyHippy wrote:

Code: Select all

//HAI2.c

#include "conio.h"
#include "knes.h"

int main(void) {
	clrscr();
	cprintf("OHI");
	while(1) {}
	return 0;
}
KNES doesn't support conio.h routines, sorry. :) If you want to print something you have to write directly to PPU via PPU_ADDR() and PPU.data.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
dirtyHippy
Posts: 2
Joined: Fri Mar 04, 2011 4:22 pm

Post by dirtyHippy »

thefox wrote:KNES doesn't support conio.h routines, sorry. :) If you want to print something you have to write directly to PPU via PPU_ADDR() and PPU.data.
I knew it was something simple :). Thanks for the quick reply
User avatar
Petruza
Posts: 311
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Post by Petruza »

Hey it's great to see someone picked up the idea!
Keep it up!
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

cool.. too bad my c is so rusty
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Post by thefox »

Posted version 0.1.1 in the website (see first post) to fix problems which were discussed in this thread. In other words it now works with the latest dev version of CC65...
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

Looked at the game demo and its sources, it is really cool. Haven't expected scrolled map engine in C with fullspeed. Especially was impressed with music engine also written in C.
Post Reply