Skip to content

Commit

Permalink
Merge pull request #19 from sdslabs/rendering
Browse files Browse the repository at this point in the history
Complete Rendering
  • Loading branch information
r41k0u authored Sep 6, 2023
2 parents f15c365 + 563c78d commit 1a480e9
Show file tree
Hide file tree
Showing 13 changed files with 889 additions and 504 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: install_dependencies
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse"
sudo apt-get update -y -qq
sudo apt-get install libsdl2-dev
fi
- name: build
run: |
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Dependencies
## SDL
### MacOS
`brew install sdl2`
### Linux
`sudo apt install libsdl2-dev`

### Windows
Download the development pack `SDL2-devel-2.0.5-VC.zip` from [here](https://github.com/libsdl-org/SDL/releases/tag/release-2.26.2)

Or use winget or choco

# Build
## Release
```
Expand Down
10 changes: 9 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ set(SOURCES
cpu.cpp
gameBoy.cpp
mmap.cpp

graphics.cpp
# -------
# Header Files
cpu.h
gameBoy.h
mmap.h
types.h
graphics.h
)

target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})

if (MSVC)
set_target_properties(
${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/")
endif ()

target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})

set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include")
22 changes: 0 additions & 22 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ CPU::CPU()
// Set isHalted to false
isHalted = false;

// The debug logging file
outfile = fopen("logfile.txt", "w");

// TODO: check the initial state of IME
IMEFlag = -1;

Expand Down Expand Up @@ -3971,20 +3968,6 @@ int CPU::executeInstruction(Byte opcode)

int CPU::executeNextInstruction()
{
// Check if boot execution is complete
// If yes, we can do logging in debug log outfile
if (mMap->readMemory(0xFF50) == 0x01)
{
dumpState();
}

// Turn off logging
// If reached infinite loop
if (reg_PC.dat == 0xCC62)
{
fclose(outfile);
}

// Get the opcode
Byte opcode = (*mMap)[reg_PC.dat];
return (this->*method_pointer[opcode])();
Expand Down Expand Up @@ -7789,11 +7772,6 @@ int CPU::SET_7_A()
return 4;
}

void CPU::dumpState()
{
//fprintf(outfile, "A:%02X F:%02X B:%02X C:%02X D:%02X E:%02X H:%02X L:%02X SP:%04X PC:%04X PCMEM:%02X,%02X,%02X,%02X\n", reg_AF.hi, reg_AF.lo, reg_BC.hi, reg_BC.lo, reg_DE.hi, reg_DE.lo, reg_HL.hi, reg_HL.lo, reg_SP.dat, reg_PC.dat, (*mMap)[reg_PC.dat], (*mMap)[reg_PC.dat + 1], (*mMap)[reg_PC.dat + 2], (*mMap)[reg_PC.dat + 3]);
}

// Checks for interrupts and services them if needed
// Behaviour source: https://gbdev.io/pandocs/Interrupts.html
int CPU::performInterrupt()
Expand Down
12 changes: 6 additions & 6 deletions src/cpu.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "types.h"
#include "mmap.h"
#include "graphics.h"

// CPU Register
// Pulled from https://gbdev.io/pandocs/CPU_Registers_and_Flags.html
Expand Down Expand Up @@ -104,6 +105,8 @@ class CPU
// Memory Map
MemoryMap* mMap;

PPU* ppu;

// ISA
// Pulled from https://izik1.github.io/gbops/index.html
typedef int (CPU::*method_function)();
Expand Down Expand Up @@ -1129,12 +1132,6 @@ class CPU
int SET_7_HLp();
int SET_7_A();

// Dump CPU state in logfile
// Useful for debugging
void dumpState();

FILE* outfile;

public:
const int clockSpeed = 4194304; // 4.194304 MHz CPU
const int clockSpeedPerFrame = 70224; // 4194304 / 59.73fps
Expand All @@ -1144,6 +1141,9 @@ class CPU
// set the memory map
void setMemory(MemoryMap* memory) { mMap = memory; }

// set the PPU
void setPPU(PPU* ppu_arg) { ppu = ppu_arg; }

// set the Accumulator
void set_reg_A(Byte value) { reg_AF.hi = value; }

Expand Down
Loading

0 comments on commit 1a480e9

Please sign in to comment.