OSDN Git Service

- ppu debug dump func updated
[motonesemu/motonesemu.git] / emulator / ppucore / ppucore.c
index 60d695f..5310e78 100644 (file)
@@ -10,9 +10,9 @@
 #include "sprite.h"
 #include "clock.h"
 
-int vscreen_init(void);
+int init_vscreen(void);
 void clean_vscreen(void);
-int palette_init(void);
+int init_palette(void);
 void set_monocolor (int mono);
 void set_nmi_pin(int val);
 void set_bg_pattern_bank(unsigned char bank);
@@ -119,7 +119,7 @@ static int scan_recovery(void) {
      * Sprite reg:
      * Stores the y-coordinate of the top left of the sprite minus 1
      * */
-    if (scan_x == VSCREEN_WIDTH && scan_y < VSCREEN_HEIGHT) {
+    if (scan_x == HSCAN_MAX - 1 && scan_y < VSCREEN_HEIGHT) {
         int next_line = (scan_y == VSCAN_MAX - 1 ? 0 : scan_y + 1);
         sprite_prefetch1(next_line);
         sprite_prefetch2(next_line);
@@ -134,6 +134,7 @@ static int clock_ppu(void) {
     if (scan_x < VSCREEN_WIDTH && scan_y < VSCREEN_HEIGHT) {
         if (scan_x == 0) {
             status_reg.sprite0_hit = 0;
+            status_reg.sprite_overflow = 0;
             if (scan_y == 0) {
                 //start displaying
                 status_reg.vblank = 0;
@@ -147,7 +148,7 @@ static int clock_ppu(void) {
         }
         if (ctrl_reg2.show_bg/**/) {
             //back ground image is pre-loaded. load 1 line ahead of drawline.
-            load_background(scan_x, scan_y);
+            load_background(scan_x + scroll_reg.x, scan_y + scroll_reg.y);
         }
         if (ctrl_reg2.show_sprite) {
             //foreground sprite
@@ -230,6 +231,9 @@ unsigned char ppu_status_get(void) {
     //if read status reg, vram addr register counter is reset
     vram_addr_reg.cnt = 0;
     //dprint("ppu_status:%02x\n", ret);
+
+    //reading status resets the vblank flg.
+    status_reg.vblank = 0;
     return ret;
 }
 
@@ -313,7 +317,12 @@ void sprite0_hit_set(void) {
     status_reg.sprite0_hit = 1;
 }
 
-int ppucore_init(void) {
+void sprite_overflow_set(void) {
+    //dprint("sprite0 set...\n");
+    status_reg.sprite_overflow = 1;
+}
+
+int init_ppucore(void) {
     int ret;
 
     memset(&ctrl_reg1, 0, sizeof(ctrl_reg1));
@@ -335,23 +344,23 @@ int ppucore_init(void) {
     scan_x = 0;
     scan_y = 0;
 
-    ret = vga_xfer_init();
+    ret = init_vga_xfer();
     if (!ret)
         return FALSE;
 
-    ret = sprite_init();
+    ret = init_sprite();
     if (!ret)
         return FALSE;
 
-    ret = vscreen_init();
+    ret = init_vscreen();
     if (!ret)
         return FALSE;
 
-    ret = palette_init();
+    ret = init_palette();
     if (!ret)
         return FALSE;
 
-    ret = vram_init();
+    ret = init_vram();
     if (!ret)
         return FALSE;
     ret = register_clock_hander(clock_ppu, PPU_DEVIDER);
@@ -393,5 +402,16 @@ void dump_ppu_reg(void) {
     printf(" left 8 pix bg:%d\n", ctrl_reg2.show_left_8bg);
     printf(" col mode:%d\n", ctrl_reg2.color_mode);
 
+    printf("\nstatus reg\n");
+    printf(" vram_ignore:%d\n", status_reg.vram_ignore);
+    printf(" sprite_overflow:%d\n", status_reg.sprite_overflow);
+    printf(" sprite0_hit:%d\n", status_reg.sprite0_hit);
+    printf(" vblank:%d\n", status_reg.vblank);
+
+    printf("\nvram_addr_reg:%04x\n", vram_addr_reg.addr.s);
+    printf("vram_data_reg:%02x\n", vram_data_reg);
+    printf("\nscroll_reg:\n");
+    printf(" x:%d\n", scroll_reg.x);
+    printf(" y:%d\n", scroll_reg.y);
 }