A programming newb wants to start

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

User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: UMK

Post by nicklausw »

tepples wrote:Was it called Unofficial MagicKit?
Yup, thanks.
User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: A programming newb wants to start

Post by nicklausw »

Update: I decided to take a look at programming the nes in C (as mentioned before,) and it's very weird to look at.

Code: Select all

*((unsigned char*)0x2005) = 0x00;
is used to do

Code: Select all

lda #$00
and

Code: Select all

sta $2005
in C. Jeez, there really isn't a good way to work at a high level with the nes, is there?
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: A programming newb wants to start

Post by thefox »

nicklausw wrote:Jeez, there really isn't a good way to work at a high level with the nes, is there?
Yes, there is. You either make a #define macro that wraps away the ugliness, or use #define macros to define the hardware registers you want to access.

For example:

Code: Select all

// Helper for memory accesses:
#define _M(a)       ( *( unsigned char* )(a) )

_M(0x2015) = 0;
You can also do something like this:

Code: Select all

struct _PPU {
    byte ctrl;
    byte mask;
    byte const status;
    byte oam_addr;
    byte oam_data;
    byte scroll;
    byte addr;
    byte data;
};
#define    PPU         ( *( struct _PPU volatile * )0x2000 )

PPU.scroll = 0;
Obviously that type of stuff would go into some common header.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: A programming newb wants to start

Post by rainwarrior »

In general, anything that writes to registers, and especially PPU interaction like your NMI handler should be written in assembly and buried in a library. This is essentially the same as how you'd do it in C on another platform. Critical hardware stuff is part of libraries, and you write high level code only, for the most part.

Code: Select all

// in a header
extern uint8 ppu_ctrl;
extern uint8 ppu_scroll_x;
extern uint8 ppu_scroll_y;
#pragma zpsym("ppu_ctrl")
#pragma zpsym("ppu_scroll_x")
#pragma zpsym("ppu_scroll_y")

; in the NMI handler of the assembly library
; ...
bit $2002
lda _ppu_scroll_x
sta $2005
lda _ppu_scroll_y
sta $2005
lda _ppu_ctrl
ora #%10000000 ; set NMI bit
sta $2000
; ...

// used in high level C code
// ...
unsigned short int scroll = 0;
// ...
++scroll;
ppu_ctrl = (ppu_ctrl & ~0x01) | ((scroll >> 8) & 0x01);
ppu_scroll_x = scroll & 0xFF;
ppu_scroll_y = 0;
// ...
If you want a specific assembly, you should write that part of the code in assembly. Write in C the parts of the program where the details of how it gets done don't matter. That's what C is for, to relieve you of those details. You can use both assembly and C in the same program, and it's somewhat counterproductive to jump through hoops to force one to do the other's job.
User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: A programming newb wants to start

Post by nicklausw »

I guess now you all know how much I can work with C. :lol:
mikaelmoizt
Posts: 120
Joined: Sat Apr 12, 2014 12:11 pm
Location: Gothenburg, Sweden

Re: A programming newb wants to start

Post by mikaelmoizt »

nicklausw wrote: Someone really does need to just go through that tutorial and modify everything to be asm6-compatible. I know, someone (you?) converted the actual files to its syntax, but the tutorials themselves...
Do you mean this? viewtopic.php?f=10&t=12097
Its a step in the right direction atleast.
I´ve got %01100011 problems but the BITs aint one.
User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: A programming newb wants to start

Post by nicklausw »

mikaelmoizt wrote:
nicklausw wrote: Someone really does need to just go through that tutorial and modify everything to be asm6-compatible. I know, someone (you?) converted the actual files to its syntax, but the tutorials themselves...
Do you mean this? viewtopic.php?f=10&t=12097
Its a step in the right direction atleast.
Yup. Sorry, couldn't remember for the life of me who did the conversion.
mikaelmoizt
Posts: 120
Joined: Sat Apr 12, 2014 12:11 pm
Location: Gothenburg, Sweden

Re: A programming newb wants to start

Post by mikaelmoizt »

nicklausw wrote: Yup. Sorry, couldn't remember for the life of me who did the conversion.
No problem. :wink:
I tried for many hours to combine those stupid .bank directives with .org into something useful before I decided I've had enough. Maybe I am just stupid or something, but why should you ever split banks into 8k slots like that (unless you work with something like mmc3)?

Edit: Come to think of it, I actually now remember this assembler was a modified <something> to work with nes, hence the weird way to split banks like that.
I´ve got %01100011 problems but the BITs aint one.
User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: A programming newb wants to start

Post by nicklausw »

mikaelmoizt wrote:
nicklausw wrote: Yup. Sorry, couldn't remember for the life of me who did the conversion.
No problem. :wink:
I tried for many hours to combine those stupid .bank directives with .org into something useful before I decided I've had enough. Maybe I am just stupid or something, but why should you ever split banks into 8k slots like that (unless you work with something like mmc3)?

Edit: Come to think of it, I actually now remember this assembler was a modified <something> to work with nes, hence the weird way to split banks like that.
It's based off a PC Engine assembler. The 8k banks are pretty much useless.
Post Reply