Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBC 3 #22

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f42a2bb
Render Background
r41k0u Mar 21, 2023
95fe9f7
Add explanation for rendering
r41k0u Mar 22, 2023
6d9a99e
Enable scrolling of window
r41k0u Apr 6, 2023
d5465de
Add PPU execution barebones
r41k0u Apr 10, 2023
97a7be0
Add SDL2 to cpp.yml
r41k0u Apr 10, 2023
a402217
Fix rendering algo to scroll Nintendo logo
r41k0u Apr 11, 2023
021b6fe
Merge branch 'rendering' of github.com:sdslabs/gbemu into rendering
r41k0u Apr 11, 2023
b443316
Add VBLANK interrupt, boot Tetris till demo
r41k0u Apr 11, 2023
f27c58d
Replace frame based rendering with scanline based rendering
r41k0u Apr 13, 2023
c09dbb6
Add STAT interrupts
r41k0u Apr 13, 2023
a59bd89
Add WY, WX registers
r41k0u Apr 13, 2023
e8dc51a
Remove PPU::load()
r41k0u Apr 13, 2023
715a6b8
Complete Background rendering
r41k0u Apr 13, 2023
3679dba
Add Window rendering, but WY misbehaves
r41k0u Apr 13, 2023
75e8eeb
Finish window internal line counter and window rendering
r41k0u Apr 17, 2023
0719607
Implement DMA Transfer
r41k0u Apr 18, 2023
d50f21e
Get sprites working, passes half of dmg-acid2's sprite tests
r41k0u Apr 18, 2023
6ed7da5
Finish DMG-Acid2 test with one sprite artifact, run Dr. Mario
r41k0u Apr 18, 2023
a1d1da5
Game playable now
r41k0u Apr 25, 2023
1503dd0
Remove VBLANK stub
r41k0u May 1, 2023
61ec724
Remove sprite overscan artifact
r41k0u May 1, 2023
00ce12f
Fix OBJ priority, run tetris
r41k0u May 2, 2023
8be6c0b
Cleanup gameboy.cpp
r41k0u May 2, 2023
3366ccd
Remove CPU Debug framework
r41k0u May 2, 2023
3f9cbed
Move ROM load logic to MemoryMap
r41k0u May 2, 2023
e09a146
Init MBC
r41k0u May 2, 2023
741db22
Create Banks, Registers and Masks for MBC1
Parth-Nebula Jun 4, 2023
84f8e5d
Read ROM banks from the game rom file
Parth-Nebula Jun 4, 2023
95a3c04
Add banking functions
NehaGujar1 Jun 4, 2023
7253d91
Make read changes in ROM Bank 0 and ROM Bank 1
NehaGujar1 Jun 4, 2023
74de4f2
Cycle count issue
NehaGujar1 Jun 11, 2023
ec8d6cd
Minor modification in updateRTCReg
NehaGujar1 Jun 11, 2023
703e4e6
Add SDL2 to CMakeLists.txt
r41k0u Jun 14, 2023
563c78d
Update cpp.yml - Add OS Check
r41k0u Jun 14, 2023
99cc8e3
Update RTC write functions
NehaGujar1 Jun 17, 2023
6a33b9e
Merge remote-tracking branch 'origin/rendering' into MBC-3
NehaGujar1 Aug 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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