Where do I go now?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
laketri
Posts: 1
Joined: Sun Jun 29, 2014 1:14 am
Location: Pennsylvania

Where do I go now?

Post by laketri »

So I followed and coded the stuff in http://www.dreamincode.net/forums/topic ... ng-part-1/ and got the program to run. Apparently the series was discontinued, so I really don't have much of an understanding of what everything is doing here. I keep looking for a tutorial that runs along with this one, but I can't seem to find one.

I modified it what little I could, and managed to produce this:
Image By doing

Code: Select all

int y = 0;
void write_string(char *str){
	int z;
	y++;
	z = y*41;
	*((unsigned char*)0x2006) = 0x20;
	*((unsigned char*)0x2006) = z;
	while(*str){
		*((unsigned char*)0x2007) = *str;
		str++;
	}
}
But really, I was just trying to figure out how to get it to a new line.

Are there any tutorials that can pick up where this left of? Or can someone explain to me what all of these *((unsigned char*)0x2006) ='s mean?
lazigamer
Posts: 23
Joined: Mon Oct 10, 2011 9:05 am

Re: Where do I go now?

Post by lazigamer »

Unfortunately there doesn't seem to be much in the way of a comprehensive tutorial for cc65. If you already have a good knowledge of C, then you just have to learn the compiler's specific syntax which can be found at the cc65 website. As far as the NES specific stuff, there are plenty of tutorials (albeit in assembly) that go over how to do graphics, sound, and input which should work in cc65.

The *((unsigned char*)0x2006) means that a value is being written to the memory address 0x2006 on the NES. Writing to this specific address is what is setting the starting point of the text you are printing. Two writes sets the location in video RAM where you will be writing data. Then the writes to 0x2007 are placing the data into video RAM. In order to do a new line, you will have to write to 0x2006 twice again to set a new location and then feed more data through 0x2007.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Where do I go now?

Post by tepples »

I don't know where you got the 41 from (it's really 32 cells per row), but lazigamer is right.

I know C, and I know console programming in C (on Game Boy Advance), and I know NES programming, but I lack any cc65-specific experience. The following are untested but should probably work for you:

Code: Select all

#define PPUADDR (*(volatile unsigned char *)0x2006)
#define PPUDATA (*(volatile unsigned char *)0x2007)

inline void ppu_gotoxy(unsigned char x, unsigned char y) {
   PPUADDR = 0x20 | (y >> 3);
   PPUADDR = x | (y << 5);
}

void ppu_puts(char *str) {
   while(*str){
      PPUDATA = *str;
      str++;
   }
}
Before you write each string, call ppu_gotoxy(2, y).
Only y values from 2 to 27 will be visible on a lot of TVs unless you're in Europe.
Post Reply