Skip to content

Commit

Permalink
Merge pull request #9 from ogamespec/master
Browse files Browse the repository at this point in the history
apu refactoring
  • Loading branch information
ogamespec authored Jul 14, 2024
2 parents bddb242 + ca25c6b commit 0e518aa
Show file tree
Hide file tree
Showing 11 changed files with 397 additions and 418 deletions.
455 changes: 60 additions & 395 deletions apu.cpp

Large diffs are not rendered by default.

41 changes: 33 additions & 8 deletions apu.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
#pragma once

//extern unsigned long so_clk; - same as gb_clk now
extern unsigned long so_clk_inner[2];
extern unsigned long so_clk_nextchange;
#define SO_FREQ (1<<20)

#define RI_NR10 0x10
#define RI_NR11 0x11
#define RI_NR12 0x12
#define RI_NR13 0x13
#define RI_NR14 0x14
#define RI_NR21 0x16
#define RI_NR22 0x17
#define RI_NR23 0x18
#define RI_NR24 0x19
#define RI_NR30 0x1A
#define RI_NR31 0x1B
#define RI_NR32 0x1C
#define RI_NR33 0x1D
#define RI_NR34 0x1E
#define RI_NR41 0x20
#define RI_NR42 0x21
#define RI_NR43 0x22
#define RI_NR44 0x23
#define RI_NR50 0x24
#define RI_NR51 0x25
#define RI_NR52 0x26

//extern unsigned long apu_clk; - same as gb_clk now
extern unsigned long apu_clk_inner[2];
extern unsigned long apu_clk_nextchange;
// ALL internal clock variables are exported (to be wrapped in gb.c)


uint8_t so_read(uint8_t);
void so_write(uint8_t, uint8_t);
uint8_t apu_read(uint8_t);
void apu_write(uint8_t, uint8_t);

void so_init(unsigned long);
void so_shutdown();
void so_mix();
void apu_init(unsigned long);
void apu_shutdown();
void apu_mix();
void apu_reset();
2 changes: 2 additions & 0 deletions dmgemu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
</ClCompile>
<ClCompile Include="perftimer.cpp" />
<ClCompile Include="apu.cpp" />
<ClCompile Include="sound.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="gb.h" />
Expand All @@ -196,6 +197,7 @@
<ClInclude Include="pad.h" />
<ClInclude Include="perftimer.h" />
<ClInclude Include="apu.h" />
<ClInclude Include="sound.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="thirdparty\SDL2\VisualC\SDL\SDL.vcxproj">
Expand Down
6 changes: 6 additions & 0 deletions dmgemu.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<ClCompile Include="apu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="sound.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="gb.h">
Expand Down Expand Up @@ -76,5 +79,8 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="sound.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
16 changes: 8 additions & 8 deletions gb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ void gb_init()
gbz80_init();
pad_init();
lcd_init();
so_init(44100);
__log("init OK.");
apu_init(44100);
__log("init OK.");
}

/* run on emu shutdown */
void gb_shutdown()
{
mem_shutdown();
mem_shutdown();
pad_shutdown();
//so_shutdown();
apu_shutdown();
lcd_shutdown();
log_shutdown();
log_shutdown();
}

// **********************************************************************
Expand Down Expand Up @@ -136,10 +136,10 @@ void start()
if(gb_eventclk > (4<<28)) { // wrap _ALL_ counters
gb_clk -=(3<<28);
gb_eventclk -=(3<<28);
so_clk_inner[1] -=(3<<28);
so_clk_nextchange-=(3<<28);
apu_clk_inner[1] -=(3<<28);
apu_clk_nextchange-=(3<<28);
if(gb_timerclk<MAXULONG) gb_timerclk-=(3<<28);
}
so_mix();
apu_mix();
}
}
2 changes: 0 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ void plat_init()
}
}

// **********************************************************************

/* platform Entry-point */
PLAT int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
Expand Down
4 changes: 2 additions & 2 deletions mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ uint8_t mem_r8_IO(unsigned addr) {
__log("HRD %.4X [PC=%.4X]", addr, R_PC);
if(addr >= 0xff00) {
if(RANGE(addr, 0xff10, 0xff3f))
return so_read((uint8_t)(addr & 0xff));
return apu_read((uint8_t)(addr & 0xff));
switch(addr & 0xff) {
case 0x00 :
{
Expand Down Expand Up @@ -354,7 +354,7 @@ void mem_w8_IO(unsigned addr, uint8_t data) {

if(addr>=0xFF00) { // OAM or hram?
if(RANGE(addr, 0xff10, 0xff3f)) {
so_write((uint8_t)(addr & 0xff), data);
apu_write((uint8_t)(addr & 0xff), data);
return;
}
switch(addr & 0xff) {
Expand Down
1 change: 1 addition & 0 deletions pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "sm83.h"
#include "ppu.h"
#include "apu.h"
#include "sound.h"
#include "pad.h"
#include "gb.h"
#include "introm.h"
Expand Down
6 changes: 3 additions & 3 deletions ppu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RGBQUAD dib_pal[] = {

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static int so_enabled = 1;
static int sound_enabled = 1;

switch(msg)
{
Expand All @@ -85,8 +85,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
case VK_ESCAPE: DestroyWindow(hwnd); break;
case VK_F12 :
(so_enabled) ? so_shutdown() : so_init(44100);
so_enabled ^= 1;
(sound_enabled) ? apu_shutdown() : apu_init(44100);
sound_enabled ^= 1;
break;
case VK_F8:
lcd_fpslimit^=1;
Expand Down
Loading

0 comments on commit 0e518aa

Please sign in to comment.