OSDN Git Service

apu & dma work started.
authorastoria-d <astoria-d@mail.goo.ne.jp>
Wed, 27 Mar 2013 02:25:38 +0000 (11:25 +0900)
committerastoria-d <astoria-d@mail.goo.ne.jp>
Wed, 27 Mar 2013 02:25:38 +0000 (11:25 +0900)
emulator/Makefile
emulator/apu.h [new file with mode: 0644]
emulator/bus.c
emulator/dma.c [new file with mode: 0644]
emulator/emu-main.c
emulator/ioapu.c [new file with mode: 0644]
emulator/ppucore/vscreen.c

index c0b360f..decb1a4 100644 (file)
@@ -3,7 +3,7 @@ BIN=motonesemu
 
 OBJS=emu-main.o clock.o bus.o cpu.o \
         rom.o cartridge.o 6502core.o debug.o ram.o \
-        ppu.o
+        ppu.o dma.o ioapu.o
         
 #       kbhit.o
 
diff --git a/emulator/apu.h b/emulator/apu.h
new file mode 100644 (file)
index 0000000..5b013b1
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __apu_h__
+#define __apu_h__
+
+void set_apu_addr(unsigned short addr);
+unsigned char get_apu_data(void);
+void set_apu_data(unsigned char data);
+
+void set_apu_start(int ce);
+
+#endif /*__apu_h__*/
+
index 2c23b8c..0f8b7f8 100644 (file)
@@ -5,6 +5,7 @@
 #include "rom.h"
 #include "ram.h"
 #include "ppu.h"
+#include "apu.h"
 
 unsigned char dbg_rom_get_byte(unsigned short offset);
 unsigned short dbg_rom_get_short(unsigned short offset);
@@ -35,7 +36,7 @@ static struct cpu_pin pin_status;
  * */
 
 #define IO_PPU_BIT  0x2000
-#define IO_APU_BIT  0x6000
+#define IO_APU_BIT  0x4000
 #define ROM_BIT     0x8000
 
 #define RAM_MASK    0x07FF
@@ -57,21 +58,20 @@ void release_bus(void) {
  * */
 void start_bus(void) {
     //dprint("start bus %04x, addr&ppu: %x\n", addr_bus, addr_bus & IO_PPU_BIT);
+    pin_status.ready = 0;
     if (addr_bus & ROM_BIT) {
         /*case rom*/
-        pin_status.ready = 0;
         set_rom_ce_pin(TRUE);
     }
-    else if ((addr_bus & IO_APU_BIT) == IO_APU_BIT) {
+    else if (addr_bus & IO_APU_BIT) {
+        set_apu_start(TRUE);
     }
     else if (addr_bus & IO_PPU_BIT) {
         /*case ppu*/
-        pin_status.ready = 0;
         set_ppu_ce_pin(TRUE);
     }
     else {
         /*case ram*/
-        pin_status.ready = 0;
         set_ram_ce_pin(TRUE);
     }
 }
@@ -80,11 +80,13 @@ void end_bus(void) {
     if (!pin_status.ready) {
         fprintf(stderr, "pin not ready!!!!\n");
     }
+
     //dprint("end bus\n");
     if (addr_bus & ROM_BIT) {
         set_rom_ce_pin(FALSE);
     }
-    else if ((addr_bus & IO_APU_BIT) == IO_APU_BIT) {
+    else if (addr_bus & IO_APU_BIT) {
+        set_apu_start(FALSE);
     }
     else if (addr_bus & IO_PPU_BIT) {
         set_ppu_ce_pin(FALSE);
@@ -101,7 +103,9 @@ void set_bus_addr(unsigned short addr) {
     if (addr & ROM_BIT) {
         set_rom_addr(addr & ROM_MASK);
     }
-    else if ((addr & IO_APU_BIT) == IO_APU_BIT) {
+    else if (addr & IO_APU_BIT) {
+        //dprint("bus addr ioapu...\n");
+        set_apu_addr(addr & IO_APU_MASK);
     }
     else if (addr & IO_PPU_BIT) {
         set_ppu_addr(addr & IO_PPU_MASK);
@@ -131,7 +135,8 @@ void set_bus_data(unsigned char data){
         critical_error = TRUE;
         //no write to ROM
     }
-    else if ((addr_bus & IO_APU_BIT) == IO_APU_BIT) {
+    else if (addr_bus & IO_APU_BIT) {
+        set_apu_data(data);
     }
     else if (addr_bus & IO_PPU_BIT) {
         set_ppu_data(data);
@@ -149,7 +154,8 @@ char get_bus_data(void) {
     if (addr_bus & ROM_BIT) {
         data_bus = get_rom_data();
     }
-    else if ((addr_bus & IO_APU_BIT) == IO_APU_BIT) {
+    else if (addr_bus & IO_APU_BIT) {
+        data_bus = get_apu_data();
     }
     else if (addr_bus & IO_PPU_BIT) {
         data_bus = get_ppu_data();
@@ -167,6 +173,10 @@ void set_rw_pin(int rw) {
     pin_status.rw = rw;
 }
 
+int get_rw_pin(void) {
+    return pin_status.rw;
+}
+
 /*nmi interrupt*/
 void set_nmi_pin(int val) {
     pin_status.nmi = val;
@@ -195,7 +205,7 @@ unsigned char dbg_get_byte(unsigned short addr) {
     if (addr & ROM_BIT) {
         return dbg_rom_get_byte(addr & ROM_MASK);
     }
-    else if ((addr & IO_APU_BIT) == IO_APU_BIT) {
+    else if (addr & IO_APU_BIT) {
         return 0;
     }
     else if (addr & IO_PPU_BIT) {
@@ -209,7 +219,7 @@ unsigned short dbg_get_short(unsigned short addr) {
     if (addr & ROM_BIT) {
         return dbg_rom_get_short(addr & ROM_MASK);
     }
-    else if ((addr & IO_APU_BIT) == IO_APU_BIT) {
+    else if (addr & IO_APU_BIT) {
         return 0;
     }
     else if (addr & IO_PPU_BIT) {
diff --git a/emulator/dma.c b/emulator/dma.c
new file mode 100644 (file)
index 0000000..a74fd37
--- /dev/null
@@ -0,0 +1,20 @@
+
+#include "tools.h"
+
+static unsigned char sprite_dma_reg;
+
+void set_dma_data(unsigned char data) {
+    dprint("set_dma_data: %02x\n", data);
+    sprite_dma_reg = data;
+}
+
+int init_dma(void) {
+
+    sprite_dma_reg = 0;
+    return TRUE;
+}
+
+void clean_dma(void) {
+
+}
+
index 665a8ac..bcdfc00 100644 (file)
@@ -12,10 +12,14 @@ int init_cpu(void);
 int init_bus(void);
 int init_debug(void);
 int init_ppu(void);
+int init_apu(void);
+int init_dma(void);
 
 void clean_bus(void);
 void clean_debug(void);
 void clean_ppu(void);
+void clean_apu(void);
+void clean_dma(void);
 
 void reset_cpu(void);
 int load_cartridge(const char* cartridge);
@@ -61,6 +65,18 @@ static int init_datas(void) {
         return FALSE;
     }
 
+    ret = init_apu();
+    if (!ret) {
+        fprintf(stderr, "apu init err.\n");
+        return FALSE;
+    }
+
+    ret = init_dma();
+    if (!ret) {
+        fprintf(stderr, "dma init err.\n");
+        return FALSE;
+    }
+
     ret = init_cpu();
     if (!ret) {
         fprintf(stderr, "cpu init err.\n");
@@ -79,9 +95,11 @@ static int init_datas(void) {
 static void clean_datas(void) {
     dprint("clean data...\n");
     clean_clock();
+    clean_dma();
     clean_rom();
     clean_ram();
     clean_ppu();
+    clean_apu();
     clean_bus();
 
     clean_debug();
diff --git a/emulator/ioapu.c b/emulator/ioapu.c
new file mode 100644 (file)
index 0000000..b15433b
--- /dev/null
@@ -0,0 +1,76 @@
+#include "tools.h"
+#include "apu.h"
+
+static unsigned short apu_addr;
+static unsigned char apu_data;
+
+#define APU_IO_SIZE 0x20
+
+/*
+ * apucore r/w func ptr.
+ * */
+void set_dma_data(unsigned char data);
+void release_bus(void);
+int get_rw_pin(void);
+
+typedef void (apu_write_t)(unsigned char);
+typedef unsigned char (apu_read_t)(void);
+
+static apu_write_t *apu_write_func[APU_IO_SIZE];
+static apu_read_t *apu_read_func[APU_IO_SIZE];
+
+void set_apu_addr(unsigned short addr) {
+    dprint("set_apu_addr: %02x\n", addr);
+    apu_addr = addr;
+}
+
+unsigned char get_apu_data(void) {
+    return apu_data;
+}
+
+void set_apu_data(unsigned char data) {
+    dprint("set_apu_data: %02x\n", data);
+    apu_data = data;
+}
+
+void set_apu_start(int ce) {
+    //let ram i/o on the bus.
+    if (ce) {
+        if (get_rw_pin()) {
+            //write cycle
+            apu_write_func[apu_addr](apu_data);
+        }
+        else {
+            //read cycle
+            apu_data = apu_read_func[apu_addr]();
+        }
+        release_bus();
+    }
+}
+
+
+/*dummy I/O func*/
+static void null_write(unsigned char d){}
+static unsigned char null_read(void){return 0;}
+
+int init_apu(void) {
+    int i;
+    apu_addr = 0;
+    apu_data = 0;
+
+    //fill null function
+    for (i = 0; i < APU_IO_SIZE; i++) {
+        apu_write_func[i] = null_write;
+    }
+    for (i = 0; i < APU_IO_SIZE; i++) {
+        apu_read_func[i] = null_read;
+    }
+    //dma func
+    apu_write_func[0x14] = set_dma_data;
+
+    return TRUE;
+}
+
+void clean_apu(void) {
+}
+
index 58e82c6..d91d482 100644 (file)
@@ -176,16 +176,19 @@ int show_sprite(int foreground) {
     struct sprite_attr sa;
     unsigned char x, y, tile;
 
+    //sprite priority:
+    //draw lowest priority first, 
+    //high priority late. highest priority comes top.
     if (foreground) {
         for (i = 0; i < SPRITE_CNT; i++) {
-            spr_ram_data_get(i, &x, &y, &tile, &sa);
+            spr_ram_data_get(SPRITE_CNT - 1 - i, &x, &y, &tile, &sa);
             if (sa.priority)
                 set_sprite(x, y, tile, sa);
         }
     }
     else {
         for (i = 0; i < SPRITE_CNT; i++) {
-            spr_ram_data_get(i, &x, &y, &tile, &sa);
+            spr_ram_data_get(SPRITE_CNT - 1 - i, &x, &y, &tile, &sa);
             if (!sa.priority)
                 set_sprite(x, y, tile, sa);
         }