Skip to content

Commit

Permalink
set zero hit status when sprite 0 is hit
Browse files Browse the repository at this point in the history
  • Loading branch information
jauhararifin committed Nov 14, 2023
1 parent 0d54892 commit ae04623
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 0 additions & 20 deletions platform/web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,6 @@ window.onload = async function() {
return text
}

function getCPU() {
const [a,x,y,sp,pc,status, lastOpcode, lastInsOffset, lastAddr, lastData, lastPc] = debugCPU()

const desc = getString(lastInsOffset)

return {
last: desc,
a: [a,a.toString(16)],
x: [x,x.toString(16)],
y: [y,y.toString(16)],
sp: [sp,sp.toString(16)],
pc: [pc,pc.toString(16)],
status: [status,status.toString(2)],
lastOpcode,
lastAddr: [lastAddr, lastAddr.toString(16)],
lastData: [lastData, lastData.toString(16)],
lastPc: [lastPc, lastPc.toString(16)],
}
}

function renderToCanvas(theCanvas, ctx, image) {
const [framebuffer, width, height] = image;
const pixels = new Uint8ClampedArray(memoryBuffer, framebuffer, width*height*4);
Expand Down
20 changes: 20 additions & 0 deletions ppu.mg
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ fn tick(ppu: *PPU, cycles: i64) {
let is_zero_hit = sprite0_y == ppu.scanline.* &&
ppu.cycles.* >= sprite0_x &&
(ppu.reg.mask.* & MASK_FLAG_SPRITE) != 0;
if is_zero_hit {
ppu.reg.status.* = ppu.reg.status.* | STATUS_FLAG_ZERO_HIT;
}
ppu.cycles.* = ppu.cycles.* - 341;
Expand Down Expand Up @@ -686,6 +689,15 @@ fn render_background(ppu: *PPU) {
let name_d: u16 = 3;
let selected_nametable: u8 = (ppu.reg.control.* & CONTROL_FLAG_NAMETABLE_1) | (ppu.reg.control.* & CONTROL_FLAG_NAMETABLE_2);
// fmt::print_str("scroll_x=");
// fmt::print_i32(scroll_x);
// fmt::print_str(",scroll_y=");
// fmt::print_i32(scroll_y);
// fmt::print_str(",selected_nametable=");
// fmt::print_u8(selected_nametable);
// fmt::print_str("\n");
let selected_nametable: u16 = selected_nametable as u16;
name_a = selected_nametable;
Expand Down Expand Up @@ -917,6 +929,14 @@ fn render_objects(ppu: *PPU) {
continue;
}
// fmt::print_str("render object x=");
// fmt::print_i32(x as i32);
// fmt::print_str(" y=");
// fmt::print_i32(y as i32);
// fmt::print_str(" tile_id=");
// fmt::print_u16(tile_id);
// fmt::print_str("\n");
let pattern_addr: u16 = 0;
if (ppu.reg.control.* & CONTROL_FLAG_SPRITE_PATTERN_ADDR) != 0 {
pattern_addr = 0x1000;
Expand Down

0 comments on commit ae04623

Please sign in to comment.