NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectRegister name conventions / standards  
Posted byHappy_Dude
Posted on9/11/03 5:27 PM
From IP203.7.134.220  



is there a standard file for the NES that defines the names of registers ? NES.h mabye ?
I don't like using the addresses directly ($2001,$2002,etc..) plus its harder to visualise what your program is doing.
Especialy if your new to NES coding. :)





SubjectRe: Register name conventions / standards new  
Posted byMemblers
Posted on9/11/03 10:31 PM
From IP68.58.99.218  



Maybe someone has made an nes.h, I dunno. Here's some somewhat standard register names lifted from one of SnowBro's dissassemblies.

PPUControl0 EQU $2000
PPUControl1 EQU $2001
PPUStatus EQU $2002
SPRAddress EQU $2003
SPRIOReg EQU $2004
PPUScroll EQU $2005
PPUAddress EQU $2006
PPUIOReg EQU $2007
SPRDMAReg EQU $4014
CPUJoyPad EQU $4016




SubjectRe: Register name conventions / standards new  
Posted by<_Hyde_>
Posted on9/12/03 00:56 AM
From IP204.102.252.147  



Laziness is a wonderful thing :-)

hydesprojects.cjb.net


SubjectRe: Register name conventions / standards new  
Posted byMemblers
Posted on9/12/03 04:17 AM
From IP68.58.99.218  



Also, if we wanted to be more official-sounding (heheh), we might replace SPR with OAM (Object Attribute Memory).




SubjectRe: Register name conventions / standards new  
Posted byHappy_Dude
Posted on9/12/03 10:39 AM
From IP203.7.134.73  



Well I decided to roll my own ;)

Tell me what you think.
Could some of the names be a little clearer ?
and do you have any suggestions ?






; NES.h
; 2003 Cye Freeman
;
; 12/9/03 - Coming from the Stella comunity the VCS.h file was
; a huge help in allowing me and other newbies to understand
; what registers did. I'v recently been trying my hand at NES
; development So I asked about a NES.h file at NESdev.
; There wasn't one, but I got some PPU names (that where pretty
; close to ones I already came up with) there and made up some
; more for the rest of the registers.
;
; Puting this together has taught me a lot about how the NES
; handles addresses and talks to the PPU and SPR-RAM.

; NOTE : I use DASM for everything but this could easily be converted
; to your compiler of choice.



; R E G I S T E R S


; P P U
; Picture Processing Unit

PPUControl0 = $2000 ; PPU Control Register #0
PPUControl1 = $2001 ; PPU Control Register #1
PPUStatus = $2002 ; PPU Status Register
OAMAddress = $2003 ; SPR-RAM Address Register
OAMIOReg = $2004 ; SPR-RAM I/O Register
PPUScroll = $2005 ; VRAM Address Register #0
PPUAddress = $2006 ; VRAM Address Register #1
PPUIO = $2007 ; VRAM I/O Register


; p A P U
; pseuedo-Audio Processing Unit

;P U L S E 0
P0CR = $4000 ; Control Register
P0RC = $4001 ; Ramp Control Register
P0FT = $4002 ; Fine Tune Register
P0CT = $4003 ; Coarse Tune Register
; P U L S E 1
P1CR = $4004 ; Control Register
P1RC = $4005 ; Ramp Control Register
P1FT = $4006 ; Fine Tune Register
P1CT = $4007 ; Coarse Tune Register
; T R I A N G L E
T0CR = $4008 ; Triangle Control Register #0
T1CR = $4009 ; Triangle Control Register #1
T0FRQ = $400A ; Triangle Frequency Register #0
T1FRQ = $400B ; Triangle Frequency Register #1
; N O I S E
NCR0 = $400C ; Noise Control Register #0
;UNUSED = $400D
NFR0 = $400E ; Noise Frequency Register #0
NFR1 = $400F ; Noise Frequency Register #1
; D E L T A M O D U L A T I O N
; The channel of the APU which handles digital data.
; Commonly referred to as the PCM (Pulse Code Modulation) channel.
DMCR = $4010 ; Delta Modulation Control Register (W)
DMDA = $4011 ; Delta Modulation D/A Register (W)
DMAR = $4012 ; Delta Modulation Address Register (W)
DMLENGTH = $4013 ; Delta Modulation Data Length Register (W)
SPRDMA = $4014 ; Sprite DMA Register
ChCtrl = $4015 ; Channel Control (w) Sound/Vertical Clock Signal Register (R)
; J O Y P A D S
PAD0 = $4016
PAD1 = $4017


; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .



; V R A M A D D R E S S E S

PTable0 = $0000 ; Pattern Table 0 (256x2x8, may be VROM)
PTable1 = $1000 ; Pattern Table 1 (256x2x8, may be VROM)
NameTable0 = $2000 ; Name Table 0 (32x25 tiles)
AttribTable0 = $23C0 ; Attribute Table 0
NameTable1 = $2400 ; Name Table 1 (32x25 tiles)
AttribTable1 = $27C0 ; Attribute Table 1
NameTable2 = $2800 ; Name Table 2 (32x25 tiles)
AttribTable2 = $2BC0 ; Attribute Table 2
NameTable3 = $2C00 ; Name Table 3 (32x25 tiles)
AttribTable4 = $2FC0 ; Attribute Table 3
IPalette = $3F00 ; Image Palette
SPalette = $3F10 ; Sprite Palette
Mirror2 = $4000 ; Mirror of $0000-3FFF


; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .









SubjectRe: Register name conventions / standards new  
Posted byquietust
Posted on9/12/03 2:33 PM



> P0CR = $4000 ; Control Register
> P0RC = $4001 ; Ramp Control Register
> P0FT = $4002 ; Fine Tune Register
> ...

I believe *that* is one of the main reasons why I just use the raw addresses in my own code - it's impossible to remember what the 'names' are! (that, and I know what all of the addresses correspond to).

--
Quietust
P.S. If you don't get this note, let me know and I'll write you another.


SubjectRe: Register name conventions / standards new  
Posted byHappy_Dude
Posted on9/12/03 3:39 PM
From IP203.7.134.104  



>>I believe *that* is one of the main reasons why I just use the raw addresses in my own code - it's impossible to remember what the 'names' are! (that, and I know
>>what all of the addresses correspond to).

PCTRL_0 ??? Mabey :)

I think register names make things easier. especialy if theres some sort of standard. ;)




SubjectRe: Register name conventions / standards new  
Posted bykoitsu
Posted on9/12/03 10:25 PM
From IP64.81.51.192  



The official Famicom docs had static equates for each of the registers. The only one I can remember is PPUSTAT.

-- jdc


SubjectRe: Register name conventions / standards new  
Posted byBig Time
Posted on9/13/03 5:12 PM



You make an interesting point, Quietust. After all, the whole point of assigning text labels to numbers is to help the programmer make addressing these ports easier. But, when only 4 or 5 alphabet letters (representing abbreviations) are used to represent 4 hexadecimal numbers, this scheme quickly loses it's effectiveness. $400F is going to mean as much to a stranger to the NES's architecture, as the words "NFR1" will. My point: if text labels are to be used to assist the programmer

However, this is not to discourage the efforts of Cye Freeman. I just think that some of the labels for those addresses should be a *little* more descriptive. Don't be afraid of using 10 or more characters for to label an absolute address: this is the whole point of using compilers and interpreters. After all, if the coder has a problem with typing so much text just to access a 16-bit memory address, then they're probably going to be using the raw addresses anyway.

However, it seems that with an architecture like the NES, where I/O registers are more or less organized in a structured way (and there is after all, only a very few of them), remembering absolute addresses is pretty easy. I don't know if this would be effective for a (much) more complicated architecture like the SNES, but I suppose that if a programmer used the raw addresses frequently enough, they would sure memorize them. Of course, this still doesn't mean that they have to.

I know that this post isn't so much NES-related, as it is personal opinion, but I thought I'd make a point of bringing it up.




SubjectRe: Register name conventions / standards new  
Posted byMemblers
Posted on9/13/03 7:58 PM
From IP68.58.99.218  



I guess it's because I've been working with the NES's registers so long that I've got them all memorized. I did have an old nestech doc printed up, but I've lost track of it since I rarely refer to it anymore.

A standard nes.h file might be good for those who are just now learning this stuff, though. As long as it's standard, otherwise source codes might be confusing to read. (then again, if someone is going to learn from existing sources they're mostly going to see the actual register addresses)

I think it's OK to use longer register names (but just short enough to still be descriptive). Myself, when programming I spend most of the time planning, and little time doing the actual typing, anyways.

When I messed around on the SNES, I definitely could see how register names would be helpful. I was needing to refer to docs to be able to understand code that I wrote the day before. :P

The SNES must've had at least 20 times more registers than the NES, though.

Happy Dude, I think your NES.h is usable enough, other than the sound register names. Usually there will be only one or two routines in a program that uses those registers, so I think using longer names won't be too much of a burden.

I'd suggest something like this:
(anyone feel free to tear this apart, just kicking around some ideas)

Pulse0Ctrl = $4000
Pulse0Sweep = $4001
Pulse0FreqLo = $4002
Pulse0FreqHi = $4003

Pulse1Ctrl = $4004
Pulse1Sweep = $4005
Pulse1FreqLo = $4006
Pulse1FreqHi = $4007

TriangleTimer = $4008
TriangleFreqLo = $400A
TriangleFreqHi = $400B

NoiseCtrl = $400C
NoiseFreq = $400E
NoiseTimer = $400F

DeltaCtrl = $4010
DC_Offset = $4011 (this is a tough one to name)
DeltaAddr = $4012
DeltaLength = $4013

SoundCtrl = $4015 (another kinda tough one, this is readable and writable for different purposes)

$4003, $4007, $400B, and $400F are kinda multi-purpose, though. So I'm not sure if my naming describes them well enough. FreqLo and FreqHi are just my personal preference (descriptive enough of their primary use, too).

Also, it seems kinda redundant to use the name OAMIOReg, since it's given that it's a register anyways. :P

Wasn't the source code to the NES version of Elite released at one point? I thought it was, but I can't find it anywhere. That might be interesting to see.




SubjectRe: Register name conventions / standards new  
Posted byHappy_Dude
Posted on9/14/03 4:51 PM
From IP203.7.134.79  



>>$4003, $4007, $400B, and $400F are kinda multi-purpose, though

I'm not sure about other assemblers but Dasm can define multiple names for single addresses :)
ie:

Channel_Priority = $4015 ; READ
Channel_Ctrl = $4015 ; WRITE





At the moment my PPU names look like this

PPUCTRL0 = $2000 ; PPU Control Register #0
PPUCTRL1 = $2001 ; PPU Control Register #1
PPUSTAT = $2002 ; PPU Status Register
OAMADDR = $2003 ; SPR-RAM Address Register
OAMIO = $2004 ; SPR-RAM I/O Register
PPUSCROLL = $2005 ; VRAM Address Register #0
PPUADDR = $2006 ; VRAM Address Register #1
PPUIO = $2007 ; VRAM I/O Register

But I don't think PPUSCROLL sounds right ...




Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo