mirror of
https://github.com/liuk7071/ChonkyStation.git
synced 2024-05-10 08:34:00 -04:00
Add SDL
This commit is contained in:
parent
befa482c23
commit
d328d60b40
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +1,6 @@
|
|||
[submodule "external/fmt"]
|
||||
path = external/fmt
|
||||
url = https://github.com/fmtlib/fmt.git
|
||||
[submodule "external/SDL"]
|
||||
path = external/SDL
|
||||
url = https://github.com/libsdl-org/SDL.git
|
||||
|
|
|
@ -18,5 +18,8 @@ include_directories(external/Panda3DS)
|
|||
source_group("Header Files/External/Dolphin" FILES ${DOLPHIN_HEADER_FILES})
|
||||
source_group("Header Files/External/Panda3DS" FILES ${PANDA3DS_HEADER_FILES})
|
||||
|
||||
add_compile_definitions(SDL_MAIN_HANDLED)
|
||||
|
||||
add_executable(ChonkyStation ${SOURCE_FILES} ${HEADER_FILES} ${DOLPHIN_HEADER_FILES} ${PANDA3DS_HEADER_FILES})
|
||||
target_link_libraries(ChonkyStation PRIVATE fmt)
|
||||
target_include_directories(ChonkyStation PRIVATE ${SDL2_INCLUDE_DIR})
|
||||
target_link_libraries(ChonkyStation PRIVATE fmt SDL2-static)
|
6
external/CMakeLists.txt
vendored
6
external/CMakeLists.txt
vendored
|
@ -7,4 +7,8 @@ set(PANDA3DS_HEADER_FILES
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/Panda3DS/logger.hpp"
|
||||
PARENT_SCOPE)
|
||||
|
||||
add_subdirectory(fmt)
|
||||
add_subdirectory(fmt)
|
||||
|
||||
set(SDL_STATIC ON CACHE BOOL "" FORCE)
|
||||
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
|
||||
add_subdirectory(SDL)
|
1
external/SDL
vendored
Submodule
1
external/SDL
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 379d4780559690a9836444aeb5637f60953947be
|
|
@ -10,5 +10,5 @@ public:
|
|||
u8* getVRAM() override;
|
||||
|
||||
private:
|
||||
u8* vram = new u8[1024 * 512];
|
||||
u8* vram = new u8[1024 * 512 * 2]; // We multiply by 2 because each pixel is 2 bytes (ABGR1555)
|
||||
};
|
|
@ -3,13 +3,19 @@
|
|||
#include <helpers.hpp>
|
||||
#include <BitField.hpp>
|
||||
#include <logger.hpp>
|
||||
#include <backends/software/gpu_software.hpp>
|
||||
#include <backends/base.hpp>
|
||||
|
||||
|
||||
class GPU {
|
||||
public:
|
||||
GPU() {
|
||||
backend = &software;
|
||||
}
|
||||
std::vector<u32> fifo;
|
||||
u32 getStat();
|
||||
u32 gpuRead();
|
||||
u8* getVRAM() { return backend->getVRAM(); };
|
||||
|
||||
// Command processing
|
||||
void writeGp0(u32 data);
|
||||
|
@ -40,6 +46,9 @@ public:
|
|||
private:
|
||||
u32 stat = 0x14802000;
|
||||
|
||||
GPUBackend* backend;
|
||||
GPUSoftware software;
|
||||
|
||||
bool hasCommand = false;
|
||||
u32 paramsLeft = 0; // Parameters needed for command
|
||||
void startCommand(u32 rawCommand);
|
||||
|
|
25
src/main.cpp
25
src/main.cpp
|
@ -1,4 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include "playstation.hpp"
|
||||
|
||||
|
||||
|
@ -11,12 +12,34 @@ int main(int argc, char** argv) {
|
|||
|
||||
PlayStation playstation = PlayStation(argv[1]);
|
||||
|
||||
// SDL Window
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
SDL_Window* window = SDL_CreateWindow("ChonkyStation", 100, 100, 1024, 512, 0);
|
||||
auto renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
auto texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR1555, SDL_TEXTUREACCESS_STREAMING, 1024, 512);
|
||||
|
||||
u64 cycles = 0;
|
||||
while (true) {
|
||||
bool running = true;
|
||||
while (running) {
|
||||
cycles = 0;
|
||||
while (cycles++ < CLOCK_SPEED)
|
||||
playstation.step();
|
||||
|
||||
// Handle SDL window events
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
u8* vram = playstation.getVRAM();
|
||||
// Update window
|
||||
SDL_UpdateTexture(texture, nullptr, vram, 1024 * 2);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture, nullptr, nullptr);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
//printf("pc: 0x%08x\n", playstation.getPC());
|
||||
//Helpers::dump("ramdump.bin", playstation.getRAM(), 2_MB);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ public:
|
|||
|
||||
u32 getPC() { return cpu.core.pc; }
|
||||
u8* getRAM() { return mem.ram; }
|
||||
u8* getVRAM() { return gpu.getVRAM(); }
|
||||
|
||||
private:
|
||||
Cpu cpu;
|
||||
|
|
Loading…
Reference in a new issue