Skip to content

Commit

Permalink
APU init
Browse files Browse the repository at this point in the history
  • Loading branch information
0xn4utilus committed Sep 8, 2023
1 parent c337cd5 commit 6b60850
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.vs/
.vscode/
build/
*.DS_Store
cmake-build-debug/
.idea/
src/.vscode/
CMakeSettings.json
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON")

find_package(SDL2 REQUIRED)

if (DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG")
endif()

add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} SDL2::SDL2 SDL2::SDL2main)
add_subdirectory(src)
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(SOURCES
gameBoy.cpp
mmap.cpp
graphics.cpp
sound.cpp

# -------
# Header Files
Expand All @@ -13,6 +14,7 @@ set(SOURCES
mmap.h
types.h
graphics.h
sound.h
)

target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
Expand Down
14 changes: 11 additions & 3 deletions src/gameBoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ GBE::GBE()
// Initialize the Graphics
gbe_graphics = new PPU();

// Initialize the APU
gbe_sound = new APU();


// Unify the CPU and MemoryMap
gbe_cpu->setMemory(gbe_mMap);

Expand All @@ -24,14 +28,19 @@ GBE::GBE()
// Unify the PPU and MmeoryMap
gbe_graphics->setMemoryMap(gbe_mMap);

// Unify the CPU and MemoryMap
gbe_sound->setMemoryMap(gbe_mMap);

gbe_sound->test();

gbe_graphics->init();

// Open the Boot ROM
if ((bootROM = fopen("../src/dmg_boot.gb", "rb")) == NULL)
if ((bootROM = fopen("../../../src/dmg_boot.gb", "rb")) == NULL)
printf("boot rom file not opened");

// Open the Game ROM
if ((gameROM = fopen("../tests/pkmnred.gb", "rb")) == NULL)
if ((gameROM = fopen("../../../tests/pacman.gb", "rb")) == NULL)
printf("game rom file not opened");

// Set the Boot ROM
Expand Down Expand Up @@ -98,7 +107,6 @@ GBE::GBE()
gbe_mMap->debugWriteMemory(0x133, 0x3E);

executeBootROM();

update();
}

Expand Down
4 changes: 4 additions & 0 deletions src/gameBoy.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "cpu.h"
#include "mmap.h"
#include "graphics.h"
#include "sound.h"

// GBE stands for GameBoyEmulator

Expand All @@ -28,6 +29,9 @@ class GBE
// Pointer to the Graphics
PPU* gbe_graphics;

// Pointer to the Sound
APU* gbe_sound;

// File pointer for Boot ROM
FILE* bootROM;

Expand Down
2 changes: 1 addition & 1 deletion src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PPU::PPU()
bool PPU::init()
{
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0)
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
{
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void MemoryMap::mapRom()

// Set the RAM Existence Mask
// Tells if External RAM is available in the Cartridge
if ((mbcMode == 2 or mbcMode == 3) and ramBanks > 0)
if ((mbcMode == 2 || mbcMode == 3) && ramBanks > 0)
{
ramExistenceMask = 1;
}
Expand Down
17 changes: 17 additions & 0 deletions src/sound.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "sound.h"
#include "types.h"

APU::APU()
{
mMap = nullptr;

}

void APU::test()
{
for (int i = 0; i < 0x20; i++)
{
printf("------------------------ at register FF%d: %d\n\n", i, mMap->readMemory(0xff10 + i) );
}

}
74 changes: 74 additions & 0 deletions src/sound.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once
#include "types.h"
#include "mmap.h"
#include <stdio.h>
#include <SDL.h>


class MasterController
{

};

class PulseChannel
{
private:
// https://gbdev.io/pandocs/Audio_Registers.html

// NRx0
Byte sweepPace;
Byte sweepChange;
Byte sweepSlope;

// NRx1
Byte waveDuty;
Byte lengthTimer;

// NRx2
Byte envelopeVolume;
Byte envelopeDirection;
Byte envelopeSweepPace;

// Nrx3
// needs 11 bits - 3 bits from NRX4 + 8 bits from NRx3
Word periodValue;

// NRx4
bool trigger;
bool soundLengthEnable;



};

class WaveChannel
{
private:

};

class NoiseChannel
{
private:

};


class APU
{
private:
// memory map
MemoryMap* mMap;

PulseChannel* channel1;
PulseChannel* channel2;

// WaveChannel* channel3;

// NoiseChannel* channel4;

public:
APU();
void setMemoryMap(MemoryMap* m){ mMap = m; }
void test();
};
Binary file added tests/pacman.gb
Binary file not shown.
Binary file added tests/pkmnred.gb
Binary file not shown.
Binary file added tests/tetris.gb
Binary file not shown.

0 comments on commit 6b60850

Please sign in to comment.