aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-02-03 18:47:40 +0100
committerStapleButter <thetotalworm@gmail.com>2017-02-03 18:47:40 +0100
commit1f691f3795a7480201e8a9384bda4e1b02123456 (patch)
treef991a976081c729ed458d14e85ac5f32b79c17d0
parentf4335b92927ec3ba0eb3675eb1c4a5c80bb0a05d (diff)
* HBlank flag and IRQ.
* VBlank and HBlank DMA.
-rw-r--r--DMA.cpp7
-rw-r--r--GPU.cpp28
-rw-r--r--NDS.cpp2
-rw-r--r--NDS.h2
-rw-r--r--main.cpp11
-rw-r--r--melonDS.depend12
6 files changed, 46 insertions, 16 deletions
diff --git a/DMA.cpp b/DMA.cpp
index 6c47f5c..91cb532 100644
--- a/DMA.cpp
+++ b/DMA.cpp
@@ -89,8 +89,9 @@ void DMA::WriteCnt(u32 val)
Start();
//else
// printf("SPECIAL ARM%d DMA%d START MODE %02X\n", CPU?7:9, Num, StartMode);
- if (StartMode!=0x00 && StartMode!=0x10 && StartMode!=0x05 && StartMode!=0x12)
+ if ((StartMode&7)!=0x00 && (StartMode&7)!=0x1 && StartMode!=2 && StartMode!=0x05 && StartMode!=0x12)
printf("UNIMPLEMENTED ARM%d DMA%d START MODE %02X\n", CPU?7:9, Num, StartMode);
+ //if (StartMode==2)printf("HBLANK DMA %08X -> %08X\n", SrcAddr, DstAddr);
}
}
@@ -106,13 +107,13 @@ void DMA::Start()
if (!RemCount)
RemCount = countmask+1;
- if ((Cnt & 0x00060000) == 0x00060000)
+ if ((Cnt & 0x00600000) == 0x00600000)
CurDstAddr = DstAddr;
// special path for cart DMA. this is a gross hack.
// emulating it properly requires emulating cart transfer delays, so uh... TODO
if (CurSrcAddr==0x04100010 && RemCount==1 && (Cnt & 0x07E00000)==0x07000000 &&
- ((CPU==0 && StartMode==0x05) || (CPU==1 && StartMode==0x12)))
+ StartMode==0x05 || StartMode==0x12)
{
NDSCart::DMA(CurDstAddr);
Cnt &= ~0x80000000;
diff --git a/GPU.cpp b/GPU.cpp
index 9222ce3..5bd269b 100644
--- a/GPU.cpp
+++ b/GPU.cpp
@@ -26,6 +26,7 @@ namespace GPU
{
#define LINE_CYCLES (355*6)
+#define HBLANK_CYCLES (256*6)
#define FRAME_CYCLES (LINE_CYCLES * 263)
u16 VCount;
@@ -756,10 +757,27 @@ void StartFrame()
StartScanline(0);
}
+void StartHBlank(u32 line)
+{
+ DispStat[0] |= (1<<1);
+ DispStat[1] |= (1<<1);
+
+ NDS::CheckDMAs(0, 0x02);
+
+ if (DispStat[0] & (1<<4)) NDS::TriggerIRQ(0, NDS::IRQ_HBlank);
+ if (DispStat[1] & (1<<4)) NDS::TriggerIRQ(1, NDS::IRQ_HBlank);
+
+ if (line < 262)
+ NDS::ScheduleEvent(NDS::Event_LCD, true, (LINE_CYCLES - HBLANK_CYCLES), StartScanline, line+1);
+}
+
void StartScanline(u32 line)
{
VCount = line;
+ DispStat[0] &= ~(1<<1);
+ DispStat[1] &= ~(1<<1);
+
if (line == VMatch[0])
{
DispStat[0] |= (1<<2);
@@ -785,7 +803,6 @@ void StartScanline(u32 line)
GPU2D_B->DrawScanline(line);
//NDS::ScheduleEvent(LINE_CYCLES, StartScanline, line+1);
- NDS::ScheduleEvent(NDS::Event_ScanlineStart, true, LINE_CYCLES, StartScanline, line+1);
}
else if (line == 262)
{
@@ -802,13 +819,18 @@ void StartScanline(u32 line)
DispStat[0] |= (1<<0);
DispStat[1] |= (1<<0);
+ NDS::CheckDMAs(0, 0x01);
+ NDS::CheckDMAs(1, 0x11);
+
if (DispStat[0] & (1<<3)) NDS::TriggerIRQ(0, NDS::IRQ_VBlank);
if (DispStat[1] & (1<<3)) NDS::TriggerIRQ(1, NDS::IRQ_VBlank);
}
//NDS::ScheduleEvent(LINE_CYCLES, StartScanline, line+1);
- NDS::ScheduleEvent(NDS::Event_ScanlineStart, true, LINE_CYCLES, StartScanline, line+1);
+ //NDS::ScheduleEvent(NDS::Event_LCD, true, LINE_CYCLES, StartScanline, line+1);
}
+
+ NDS::ScheduleEvent(NDS::Event_LCD, true, HBLANK_CYCLES, StartHBlank, line);
}
@@ -819,8 +841,6 @@ void SetDispStat(u32 cpu, u16 val)
DispStat[cpu] |= val;
VMatch[cpu] = (val >> 8) | ((val & 0x80) << 1);
-
- if (val & 0x10) printf("!! HBLANK ENABLED\n");
}
}
diff --git a/NDS.cpp b/NDS.cpp
index cd6fd8c..d1d0c4b 100644
--- a/NDS.cpp
+++ b/NDS.cpp
@@ -1679,7 +1679,7 @@ void ARM9IOWrite32(u32 addr, u32 val)
case 0x040001B4: *(u32*)&ROMSeed1[0] = val; return;
case 0x04000208: IME[0] = val & 0x1; return;
- case 0x04000210: IE[0] = val; if (val&~0x000F0F7D)printf("unusual IRQ %08X\n",val);return;
+ case 0x04000210: IE[0] = val; if (val&~0x000F0F7F)printf("unusual IRQ %08X\n",val);return;
case 0x04000214: IF[0] &= ~val; return;
case 0x04000240:
diff --git a/NDS.h b/NDS.h
index 8ca022b..2b84513 100644
--- a/NDS.h
+++ b/NDS.h
@@ -38,7 +38,7 @@ typedef struct _SchedEvent
enum
{
- Event_ScanlineStart = 0,
+ Event_LCD = 0,
Event_Timer9_0,
Event_Timer9_1,
diff --git a/main.cpp b/main.cpp
index 8b29972..31716bc 100644
--- a/main.cpp
+++ b/main.cpp
@@ -40,7 +40,6 @@ LRESULT CALLBACK derpo(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
case WM_CLOSE:
printf("close\n");
{
- // 6006800 6008000
FILE* f = fopen("debug/wram.bin", "wb");
if (f)
{
@@ -51,6 +50,16 @@ LRESULT CALLBACK derpo(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
}
fclose(f);
}
+ f = fopen("debug/arm7vram.bin", "wb");
+ if (f)
+ {
+ for (u32 i = 0x6000000; i < 0x6040000; i+=4)
+ {
+ u32 blarg = NDS::ARM7Read32(i);
+ fwrite(&blarg, 4, 1, f);
+ }
+ fclose(f);
+ }
f = fopen("debug/mainram.bin", "wb");
if (f)
{
diff --git a/melonDS.depend b/melonDS.depend
index 18630d9..00c3856 100644
--- a/melonDS.depend
+++ b/melonDS.depend
@@ -1,16 +1,16 @@
# depslib dependency file v1.0
-1486086940 source:c:\documents\sources\melonds\main.cpp
+1486141269 source:c:\documents\sources\melonds\main.cpp
<stdio.h>
<windows.h>
"NDS.h"
"GPU.h"
-1485981187 c:\documents\sources\melonds\nds.h
+1486142800 c:\documents\sources\melonds\nds.h
"types.h"
1481161027 c:\documents\sources\melonds\types.h
-1486135026 source:c:\documents\sources\melonds\nds.cpp
+1486143063 source:c:\documents\sources\melonds\nds.cpp
<stdio.h>
<string.h>
"NDS.h"
@@ -86,7 +86,7 @@
"NDS.h"
"SPI.h"
-1485994573 source:c:\documents\sources\melonds\gpu2d.cpp
+1486143936 source:c:\documents\sources\melonds\gpu2d.cpp
<stdio.h>
<string.h>
"NDS.h"
@@ -108,7 +108,7 @@
1484612398 c:\documents\sources\melonds\fifo.h
"types.h"
-1486093630 source:c:\documents\sources\melonds\dma.cpp
+1486143294 source:c:\documents\sources\melonds\dma.cpp
<stdio.h>
"NDS.h"
"DMA.h"
@@ -117,7 +117,7 @@
1484698068 c:\documents\sources\melonds\dma.h
"types.h"
-1485990504 source:c:\documents\sources\melonds\gpu.cpp
+1486142983 source:c:\documents\sources\melonds\gpu.cpp
<stdio.h>
<string.h>
"NDS.h"