From d63c1d544648b03482bc34054306c6aefc1afd0c Mon Sep 17 00:00:00 2001 From: Jorge Gorbe Moya Date: Tue, 24 Jun 2008 13:30:16 +0200 Subject: [PATCH] Video, first steps --- GBRom.cc | 1 + GBVideo.cc | 34 ++++++++++++++++++++++++++++++++++ GBVideo.h | 17 ++++++++++++++++- Makefile | 8 ++++---- gbcore.cc | 3 ++- gbcore.h | 6 ++++++ 6 files changed, 63 insertions(+), 6 deletions(-) diff --git a/GBRom.cc b/GBRom.cc index 4cccf7f..8d0ddb8 100644 --- a/GBRom.cc +++ b/GBRom.cc @@ -86,5 +86,6 @@ int main(int argc, char *argv[]) std::exit(EXIT_FAILURE); } GBRom *rom=read_gbrom(argv[1]); + printf("rom=%p\n", rom); } #endif diff --git a/GBVideo.cc b/GBVideo.cc index 96aa2b7..2789af8 100644 --- a/GBVideo.cc +++ b/GBVideo.cc @@ -1,4 +1,22 @@ #include "GBVideo.h" + +GBVideo::GBVideo(GameBoy *core): + display(0), + core(core) +{ + SDL_Init(SDL_INIT_VIDEO); + display=SDL_SetVideoMode(160,144,32,SDL_SWSURFACE); + + colors[0] = SDL_MapRGB(display->format, 0xFF, 0xFF, 0xFF); + colors[1] = SDL_MapRGB(display->format, 0xAA, 0xAA, 0xAA); + colors[2] = SDL_MapRGB(display->format, 0x55, 0x55, 0x55); + colors[3] = SDL_MapRGB(display->format, 0x00, 0x00, 0x00); +} + +GBVideo::~GBVideo() +{ + SDL_Quit(); +} u8 GBVideo::read_VRAM (int addr) const { @@ -20,4 +38,20 @@ void GBVideo::write_OAM (int addr, u8 value) OAM[addr-OAM_BASE] = value; } +void GBVideo::update() +{ + //Mode 0 is present between 201-207 clks, 2 about 77-83 clks, and 3 + //about 169-175 clks. A complete cycle through these states takes 456 + //clks. VBlank lasts 4560 clks. A complete screen refresh occurs every + //70224 clks.) + // + // sequence: + // 2: 80 clocks \ + // 3: 172 clocks |-> for each one of the 144 lines + // 0: 204 clocks (HBlank) / + // 1: 4560 clocks -> VBlank + + int t = core->cycle_count % 70224; + +} diff --git a/GBVideo.h b/GBVideo.h index 660ef94..8e35bed 100644 --- a/GBVideo.h +++ b/GBVideo.h @@ -1,23 +1,38 @@ #include "GBMemory.h" +#include "SDL.h" class GBVideo { + SDL_Surface *display; GameBoy *core; u8 VRAM[8192]; u8 OAM[160]; + u32 colors[4]; + public: static const u16 VRAM_BASE = 0x8000; static const u16 OAM_BASE = 0xFE00; - GBVideo(GameBoy *core):core(core) {} + GBVideo(GameBoy *core); + ~GBVideo(); + // VRAM/OAM access u8 read_VRAM (int addr) const; u8 read_OAM (int addr) const; void write_VRAM(int addr, u8 value); void write_OAM (int addr, u8 value); + + // drawing control + void update(); + + // prevent object copying + private: + GBVideo(const GBVideo&); + GBVideo operator=(const GBVideo&); + }; diff --git a/Makefile b/Makefile index 2512b13..dabd46a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CXXFLAGS=-g -Wall -Weffc++ -Wstrict-null-sentinel -Wold-style-cast \ - -Woverloaded-virtual -LDFLAGS=-g + -Woverloaded-virtual $(shell sdl-config --cflags) +LDFLAGS=-g $(shell sdl-config --libs) all: tests @@ -20,10 +20,10 @@ gbcore.o: gbcore.cc gbcore.h opcodes.h disasm.h \ g++ $(CXXFLAGS) -c -o $@ $< tests/test_gbrom: GBRom.cc GBRom.h - g++ -DTEST_GBROM -o $@ GBRom.cc + g++ $(CXXFLAGS) $(LDFLAGS) -DTEST_GBROM -o $@ GBRom.cc tests/test_core: tests/test_core.cc gbcore.o MBC.o GBMemory.o GBRom.o GBVideo.o - g++ -o $@ $^ + g++ $(CXXFLAGS) $(LDFLAGS) -o $@ $^ clean: rm -f *.o tests/test_gbrom diff --git a/gbcore.cc b/gbcore.cc index 5ca3b51..c5a7859 100644 --- a/gbcore.cc +++ b/gbcore.cc @@ -78,6 +78,8 @@ void GameBoy::reset() GameBoy::run_status GameBoy::run_cycle() { + video.update(); + // Check for interrupts before opcode fetching u8 IE; if (IME && (IE=memory.read(0xFFFF))) @@ -1280,7 +1282,6 @@ void GameBoy::disassemble_opcode(u16 addr, std::string &instruction, int &length errmsg << "Unknown opcode 0x"; errmsg << std::hex << std::setw(2) << std::setfill('0') << opcode; errmsg << " at 0x" << std::hex << std::setw(4) << PC-1; - errmsg << " (cycle count = " << std::dec << cycle_count << ")"; logger.trace(errmsg.str()); break; diff --git a/gbcore.h b/gbcore.h index c5a6fcc..658dcad 100644 --- a/gbcore.h +++ b/gbcore.h @@ -90,8 +90,10 @@ class GameBoy TRACEPOINT = 3, }; + // Constructors GameBoy(std::string rom_name, GameBoyType type=GAMEBOY); + void irq(InterruptRequest i) { memory.write(0xFFFF, memory.read(0xFFFF) | i); } void reset(); run_status run_cycle(); @@ -102,6 +104,10 @@ class GameBoy std::string status_string() const; std::string get_port_name(int port) const; + // prevent object copying + private: + GameBoy(const GameBoy&); + GameBoy operator=(const GameBoy&); }; #endif -- 2.34.1