diff options
-rw-r--r-- | CMakeLists.txt | 30 | ||||
-rw-r--r-- | emulator.cpp | 2 | ||||
-rw-r--r-- | graphics.cpp | 25 | ||||
-rw-r--r-- | vdp.cpp | 5 | ||||
-rw-r--r-- | vdp.hpp | 4 |
5 files changed, 43 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 994b703..ec342a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,12 +8,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_EXPORT_COMPILE_COMMANDS True) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic") -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -O1") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types -Wall -Wextra -pedantic") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti") # Speed up compilation -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -O1") -set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer") set(emulator_sources bus.cpp @@ -51,6 +45,30 @@ target_include_directories(musashi_m68k PRIVATE find_package(SDL2 REQUIRED) add_executable(emulator ${emulator_sources}) +target_compile_options(emulator PRIVATE + $<$<COMPILE_LANGUAGE:CXX>:-fms-extensions> + $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions> + $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti> + $<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override> + # TODO enable these and fix warnings + #$<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-final-types> + #$<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-final-methods> + #$<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast> + #-Wconversion + #-Wsign-conversion + -fno-omit-frame-pointer + -Wall + -Wextra + -Wcast-align + -Wshadow + -Wlogical-op + -pedantic + -g3 + -O2 + -fsanitize=address,undefined +) + +target_link_options(emulator PRIVATE -fsanitize=address,undefined) target_link_libraries(emulator musashi_m68k) # TODO make SDL2 optional for headless mode target_include_directories(emulator PRIVATE ${SDL2_INCLUDE_DIRS}) diff --git a/emulator.cpp b/emulator.cpp index 70927bd..7ce5f60 100644 --- a/emulator.cpp +++ b/emulator.cpp @@ -484,7 +484,7 @@ int emulator(M68KDebuggingControl& m68k_debug, Graphics& graphics) } if (m68k_debug.IsRunning()) { do { - m68k_execute(1000000); + m68k_execute(10000); } while(!g_vdp.Scanline()); graphics.Render(g_vdp); } diff --git a/graphics.cpp b/graphics.cpp index 2455630..03379c5 100644 --- a/graphics.cpp +++ b/graphics.cpp @@ -18,7 +18,8 @@ Graphics::Graphics() _window = SDL_CreateWindow("Gut (SEGA MD/G emulator)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - VDP().render_width, VDP().render_height, + VDP().render_width, + VDP().render_height, SDL_WINDOW_RESIZABLE); if (!_window) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError()); @@ -49,29 +50,33 @@ Graphics::Graphics() Graphics::~Graphics() { #if HAS_GRAPHICS == 1 - SDL_DestroyTexture(_render_texture); - SDL_DestroyRenderer(_renderer); - SDL_DestroyWindow(_window); + if (_window) { + if (_renderer) { + if (_render_texture) { + SDL_DestroyTexture(_render_texture); + } + SDL_DestroyRenderer(_renderer); + } + SDL_DestroyWindow(_window); + } SDL_Quit(); #endif } void Graphics::Render(const VDP& vdp) { - const uint8_t* buffer = vdp.GetRenderedBuffer(); + const uint32_t* buffer = vdp.GetRenderedBuffer(); #if HAS_GRAPHICS == 1 void* pixels; int pitch; if (SDL_LockTexture(_render_texture, NULL, &pixels, &pitch) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError()); + // TODO probably should return and propagate error abort(); } - for (int row = 0; (size_t)row < VDP().render_height; row++) { + for (size_t row = 0; row < VDP().render_height; row++) { uint32_t *dst = (uint32_t*)((uint8_t*)pixels + row * pitch); - for (int col = 0; (size_t)col < VDP().render_width; col++, buffer += 4) { - const uint32_t color = ((buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]); - *dst++ = color; - } + memcpy(dst, buffer, VDP().render_width * sizeof(*dst)); } SDL_UnlockTexture(_render_texture); SDL_RenderClear(_renderer); @@ -142,10 +142,7 @@ bool VDP::Scanline() return true; } for (size_t i = 0; i < render_width; i++) { - _rendered_buffer[render_width * _lines_counter * 4 + i + 0] = 0xff; // Alpha - _rendered_buffer[render_width * _lines_counter * 4 + i + 1] = 0xff; // Red - _rendered_buffer[render_width * _lines_counter * 4 + i + 2] = 0x7f; // Green - _rendered_buffer[render_width * _lines_counter * 4 + i + 3] = 0x7f; // Blue + _rendered_buffer[render_width * _lines_counter + i] = 0xff00ffff; } _lines_counter++; const uint16_t lines_per_screen = _status.pal_mode ? kLinesPerScreenPAL : kLinesPerScreenNTSC; @@ -15,7 +15,7 @@ class VDP { void Write(uint32_t offset, enum bitness, uint32_t value); bool Scanline(); // Returns true if display disabled or vblank happened void Reset(); - const uint8_t* GetRenderedBuffer() const { return _rendered_buffer; } + const uint32_t* GetRenderedBuffer() const { return _rendered_buffer; } const uint32_t base_address; @@ -112,5 +112,5 @@ class VDP { uint8_t _vram[kVRAMSize]{}; uint8_t _cram[kCRAMSize]{}; uint8_t _vsram[kVSRAMSize]{}; - uint8_t _rendered_buffer[render_buffer_size]{}; + uint32_t _rendered_buffer[kLinesPerScreenNTSC * render_width]{}; }; |