CC65, NES, joystick
Moderator: Moderators
CC65, NES, joystick
Hi,
Could anyone put an example code in CC65 how to get joystick to work in NES ? I haven't found good (or any) examples, all my attempts so far haven't worked.
Thanks for advance !
-jp
Could anyone put an example code in CC65 how to get joystick to work in NES ? I haven't found good (or any) examples, all my attempts so far haven't worked.
Thanks for advance !
-jp
Yes, of course, sorry, I was too busy.
I'm using C, not asm, compiling using cl65 (-t nes -o XXX.nes XXX.c).
An example, which doesn't work, probably as the joystick driver is not installed or something:
I make sound programming only, nothing else, so all .... means poking to sound registers directly as in example above. With joy_read() it stops there, seems to wait forever (something), without it, the sounds are generated and audible as usually.
Thanks !
-jp
I'm using C, not asm, compiling using cl65 (-t nes -o XXX.nes XXX.c).
An example, which doesn't work, probably as the joystick driver is not installed or something:
Code: Select all
#include <nes.h>
#include <joystick.h>
int joy;
void main() {
POKE(0x4015,0xFF);
while(1) {
joy = joy_read(JOY_1);
......
......
}
}
Thanks !
-jp
Ah, in that case I have no idea what the problem is. I know the default CC65 NES libraries aren't that great but I'd expect joypad routines to work at least.
I wrote an alternative library some time ago, you might want to give it a go: http://kkfos.aspekt.fi/projects/nes/kne ... -for-cc65/ There's also a read_joy() function in there. The code you pasted would be something like this with my library:
EDIT: Hmph, I guess I should've included an empty template in the KNES package... I doubt very many want to dig through the makefile and stuff in the demo "game"...
I wrote an alternative library some time ago, you might want to give it a go: http://kkfos.aspekt.fi/projects/nes/kne ... -for-cc65/ There's also a read_joy() function in there. The code you pasted would be something like this with my library:
Code: Select all
#include "knes.h"
byte joy;
int main(void)
{
_M(0x4015) = 0xFF;
while(1) {
joy = read_joy(0);
// ...
}
}
Thanks, I knew about your knes library replacement, I was actually going to try it next. I had (and still have:) the current official version, I downloaded snapshot version and installed it (before that mv cc65 cc65.org, working on Linux), before snapshot I downloaded your knes and compiled it without problems, after installing the snapshot version it doesn't compile, instead got this message:
I also got this message
These both with snapshot version cc65-snapshot-2.13.9.20110212, but not in official version cc65-2.13.2.
Any thoughts ?
And thanks !
-jp
ps. Do I need any other files than knes.h and knes.lib for compiling with cl65 ?
Code: Select all
ar65: Error: Wrong data version in `knes.lib'
make: *** [knes.lib] Error 1
Code: Select all
Fatal error: The meaning of `-l' has changed. It does now expect a file name as argument.
Any thoughts ?
And thanks !
-jp
ps. Do I need any other files than knes.h and knes.lib for compiling with cl65 ?
Hmm I can't even remember why I wrote it would only work with the snapshot version... maybe I compiled knes.lib with some older snapshot version (which is kind of stupid if I did). Anyway the object/library version number was probably bumped up so you'll need to replace nes.lib in the directory "knes/original" with the one in the snapshot version (in cc65-snapshot-nes-*.zip) and then recompile knes.lib.jp48 wrote:Thanks, I knew about your knes library replacement, I was actually going to try it next. I had (and still have:) the current official version, I downloaded snapshot version and installed it (before that mv cc65 cc65.org, working on Linux), before snapshot I downloaded your knes and compiled it without problems, after installing the snapshot version it doesn't compile, instead got this message:
Code: Select all
ar65: Error: Wrong data version in `knes.lib' make: *** [knes.lib] Error 1
Yeah that's a pretty recent change in CC65, you can remove the -l argument from the makefile though, it only generates the listing files.I also got this message
Code: Select all
Fatal error: The meaning of `-l' has changed. It does now expect a file name as argument.
If it works with the official version, by all means use that. You can also recompile knes.lib for that if it doesn't otherwise work. Actually now that I think of it it's probably the best thing to do since there have been quite a few changes to the CC65 dev version after I released KNES v0.1... build breaking changes.These both with snapshot version cc65-snapshot-2.13.9.20110212, but not in official version cc65-2.13.2.
Yeah only those are needed.ps. Do I need any other files than knes.h and knes.lib for compiling with cl65 ?
Okay, let's move on:
I sticked to snapshot version, got the nes.lib and recompiled, removed -l options, compiled without errors. Using same code example we've worked , I get this error:
However I removed #include <peekpoke.h> and instead use your _M, it works perfectly, just the joystick external, there's something (same happened with official CC65 version).
Thanks again !
-jp
I sticked to snapshot version, got the nes.lib and recompiled, removed -l options, compiled without errors. Using same code example we've worked , I get this error:
Code: Select all
Unresolved external `_read_joy' referenced in:
snd1.s(16)
ld65: Error: 1 unresolved external(s) found - cannot create output file
Thanks again !
-jp
Seems like knes.c wasn't compiled and archived into knes.lib for some reason, did you use the supplied makefile? Try deleting the .lib and all .o files and recompiling knes.lib once more.jp48 wrote:Okay, let's move on:
I sticked to snapshot version, got the nes.lib and recompiled, removed -l options, compiled without errors. Using same code example we've worked , I get this error:
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
I actually removed whole knes directory, unzipped from the original, replaced the nes.lib from snapshot, compiles without errors (after removing -l flags), I copied knes.lib to /opt/lib/cc65/lib and knes.h to /opt/lib/cc65/include. I tried to copy both to same directory where my sources reside, withthefox wrote: Seems like knes.c wasn't compiled and archived into knes.lib for some reason, did you use the supplied makefile? Try deleting the .lib and all .o files and recompiling knes.lib once more.
Code: Select all
#include <knes.h>
and
#include "knes.h"
Code: Select all
cl65 -v -g -t none -c crt0.s
cl65 -t none -g -T -Cl -Oirs -c knes.c
cl65 -v -g -t none -c _read_joy.s
cp original/nes.lib knes.lib
ar65 d knes.lib _scrsize.o cclear.o chline.o clock.o clrscr.o color.o cputc.o crt0.o cvline.o get_tv.o gotox.o gotoxy.o gotoy.o mainargs.o ppu.o ppubuf.o randomize.o revers.o setcursor.o sysuname.o waitvblank.o wherex.o wherey.o
ar65 a knes.lib crt0.o knes.o _read_joy.o
Thanks very much of your efforts to help with this !
-jp
Aah damn I forgot, you also need a separate linker config file, can't use the default one, sorry about that. There's one for NROM in the "demo" directory: nes-nrom.cfg. Also you probably forgot to link with knes.lib, so add it to the command line when linking. And specify the config file with "-C nes-nrom.cfg". You can look in demo/Makefile for an example.jp48 wrote:I actually removed whole knes directory, unzipped from the original, replaced the nes.lib from snapshot, compiles without errors (after removing -l flags), I copied knes.lib to /opt/lib/cc65/lib and knes.h to /opt/lib/cc65/include. I tried to copy both to same directory where my sources reside, withthefox wrote: Seems like knes.c wasn't compiled and archived into knes.lib for some reason, did you use the supplied makefile? Try deleting the .lib and all .o files and recompiling knes.lib once more.
Linker config format has changed in snapshot so you'll need to remove this from it:
Code: Select all
symbols {
__STACKSIZE__ = $0200;
}
No problem, thanks for ideas on how to improve the usability of the library. I should add a blank template and make sure it works without all of this hassle. It was supposed to make things EASIER, after all.Thanks very much of your efforts to help with this !
Well, still problems, the program compiles with two warnings, below:
It still produces ROM file but neither FCEU nor mednafen do open it.
I used nes-nrom.cfg, removed the three lines you mentioned and ensured that I link knes.lib:
(and few combinations of other flags for cl65).
The template would be wonderful, don't be too "ankara" for yourself, this is version 0.1, at some point it makes things easier.
(and by "ankara" I don't mean any cities, just a Finnish word from Kitee to Tampere).
-jp
Code: Select all
ld65: Warning: nes-nrom.cfg(45): Segment `HEADER' does not exist
ld65: Warning: nes-nrom.cfg(45): Segment `DPCM' does not exist
I used nes-nrom.cfg, removed the three lines you mentioned and ensured that I link knes.lib:
Code: Select all
cl65 -t nes -C nes-nrom.cfg -o snd1.nes snd1.c knes.lib
The template would be wonderful, don't be too "ankara" for yourself, this is version 0.1, at some point it makes things easier.
(and by "ankara" I don't mean any cities, just a Finnish word from Kitee to Tampere).
-jp
DPCM you can ignore. (It should have been made optional in the link script.) But if the header don exits, then of course nothing will open it.
Yes, I already ignored DPCM simply by commenting it out. But header, where it should be, I mean, if I simply comment out the joy_read(), everything works, it is obvious there's some problem with the header, I just need to know how to solve it.tepples wrote:DPCM you can ignore. (It should have been made optional in the link script.) But if the header don exits, then of course nothing will open it.
Thanks !
-jp
Bleh, I'm completely out of touch with this stuff. I forgot how non-generic that config file was.jp48 wrote:Well, still problems, the program compiles with two warnings, below:
It still produces ROM file but neither FCEU nor mednafen do open it.Code: Select all
ld65: Warning: nes-nrom.cfg(45): Segment `HEADER' does not exist ld65: Warning: nes-nrom.cfg(45): Segment `DPCM' does not exist
I used nes-nrom.cfg, removed the three lines you mentioned and ensured that I link knes.lib:
(and few combinations of other flags for cl65).Code: Select all
cl65 -t nes -C nes-nrom.cfg -o snd1.nes snd1.c knes.lib
The template would be wonderful, don't be too "ankara" for yourself, this is version 0.1, at some point it makes things easier.
So here's the command line that should work after that:
Code: Select all
cl65 -t none -C nes-nrom.cfg -o snd1.nes snd1.c header.c knes.lib
Heh heh... I don't think I am, I'm just surprised how much I've forgotten about this already.(and by "ankara" I don't mean any cities, just a Finnish word from Kitee to Tampere).![]()
Btw, here's the correct replacement for the symbols line in the config:
Code: Select all
symbols {
__STACKSIZE__: type = weak, value = $0200;
}
OK, let's continue:
I added 'optional = yes' to DPCM line, copied both kernel.c and kernel.h, commented out #include <nes.h>, I need VBLANK so I use one from knes.h. No errors in compiling, still stucks to reading joystick ie.
If I comment out those two lines, sounds come out normally, except now wait_blank(); stucks to first sound (I tried disable_interrupts(); and enable_interrupts(); but it doesn't help).
I'm not sure if this all have something to do that I'm working only with sound, no display, just blank screen. However without joystick CC65 nes.h works exactly as it should work, waitvblank() works correctly etc.
Thanks !
-jp
I added 'optional = yes' to DPCM line, copied both kernel.c and kernel.h, commented out #include <nes.h>, I need VBLANK so I use one from knes.h. No errors in compiling, still stucks to reading joystick ie.
Code: Select all
joy=read_joy(0);
if(joy & JOY_UP) par1=40;
I'm not sure if this all have something to do that I'm working only with sound, no display, just blank screen. However without joystick CC65 nes.h works exactly as it should work, waitvblank() works correctly etc.
Thanks !
-jp