Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mwillsey/NES
Browse files Browse the repository at this point in the history
  • Loading branch information
mwillsey committed Feb 12, 2014
2 parents eac552e + 80ae2d6 commit 6fa9d11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion nes.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ struct cpu_s {
struct ppu_s {
memory *mem;
/* registers */
byte latch;
byte ctrl;
byte mask;
byte status;
byte oam_addr;
byte oam_data;
addr scroll;
byte scrollx;
byte scrolly;
addr addr;
byte data;
};
Expand Down
15 changes: 11 additions & 4 deletions ppu.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ void oam_data_cb (nes* n, byte b) {
n->p->oam_data = b;
}
void scroll_cb (nes* n, byte b) {
/* addr is written byte by byte, lo then hi */
n->p->scroll = (n->p->scroll << 8) | b;
if (n->p->latch)
n->p->scrolly = b;
else
n->p->scrollx = b;

}
void addr_cb (nes* n, byte b) {
/* addr is written byte by byte, lo then hi */
n->p->addr = (n->p->addr << 8) | b;
/* clear then write to spot indicated by latch */
if (n->p->latch)
n->p->addr = (n->p->addr & 0xff00) | b;
else
n->p->addr = (n->p->addr & 0x00ff) | (b << 8);
}
void data_cb (nes* n, byte b) {
n->p->data = b;
Expand All @@ -41,6 +47,7 @@ void ppu_init (nes *n) {
ppu *p = n->p;
p->mem = malloc(sizeof(memory));
mem_init(p->mem, 0x4000, n);
p->latch = 0;

/* install callbacks in CPU address space */
n->c->mem->write_cbs[0x2000] = &ctrl_cb;
Expand Down

0 comments on commit 6fa9d11

Please sign in to comment.