Also, your note about when to read the registers, you're talking about $2000 and $2001? I think I'm reading it when the emulator is paused, the same moment any memview file prompt popup is launched. So far with my tests it seems to be working ok, but it could be that it's loading at some random moment and I'm lucky. I'm just using default memview behavior, it seems to be fine.
Moving on:
I'm having a really hard time understanding the code. I've only found two instances of the string "2005" on ppu.cpp.
Code: Select all
ARead[x + 5] = A200x;
BWrite[x + 5] = B2005;
Also, when programming a game in ca65 I've learned horizontal scroll has two important values: the selected nametable, as defined by the two least significant bits of PPUCTRL register, and a value of 0-255 to be written to $2005 that defines the pixel position of the scroll relative to the selected nametable. Is that equivalent to what I'm looking for in the source code? I ask this because the wiki talks about fine and coarse scroll values, which is confusing me. Source: http://wiki.nesdev.com/w/index.php/PPU_scrolling
Code: Select all
PPU internal registers
v
Current VRAM address (15 bits)
t
Temporary VRAM address (15 bits); can also be thought of as the address of the top left onscreen tile.
x
Fine X scroll (3 bits)
The 15 bit registers t and v are composed this way during rendering:
yyy NN YYYYY XXXXX
||| || ||||| +++++-- coarse X scroll
||| || +++++-------- coarse Y scroll
||| ++-------------- nametable select
+++----------------- fine Y scroll
ppu.cpp has this function, but I don't understand how it's used
Code: Select all
void ppu_getScroll(int &xpos, int &ypos) {
if (newppu) {
ypos = ppur._vt * 8 + ppur._fv + ppur._v * 256;
xpos = ppur._ht * 8 + ppur.fh + ppur._h * 256;
} else {
xpos = ((RefreshAddr & 0x400) >> 2) | ((RefreshAddr & 0x1F) << 3) | XOffset;
ypos = ((RefreshAddr & 0x3E0) >> 2) | ((RefreshAddr & 0x7000) >> 12);
if (RefreshAddr & 0x800) ypos += 240;
}
}