Change colors, try to cross compile
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
|||||||
cmake-build-debug
|
/cmake-build-*
|
@@ -1,25 +1,65 @@
|
|||||||
cmake_minimum_required(VERSION 3.31)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
project(RISCB C)
|
project(RISCB C)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 23)
|
set(CMAKE_C_STANDARD 23)
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
|
# Allow setting the target platform manually
|
||||||
|
if (NOT DEFINED TARGET_PLATFORM)
|
||||||
|
if (WIN32)
|
||||||
|
set(TARGET_PLATFORM windows)
|
||||||
|
elseif (UNIX)
|
||||||
|
set(TARGET_PLATFORM linux)
|
||||||
|
else ()
|
||||||
|
message(FATAL_ERROR "Unsupported platform. Please set TARGET_PLATFORM manually.")
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
message(STATUS "Target platform: ${TARGET_PLATFORM}")
|
||||||
|
|
||||||
|
# Detect build type and configure SDL2 paths accordingly
|
||||||
|
if (TARGET_PLATFORM STREQUAL "windows")
|
||||||
|
include_directories(${SDL2_INCLUDE_DIR})
|
||||||
|
elseif (TARGET_PLATFORM STREQUAL "mingw")
|
||||||
|
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
||||||
|
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||||
|
find_package(SDL2 REQUIRED)
|
||||||
|
find_package(SDL2_ttf REQUIRED)
|
||||||
|
include_directories(${SDL2_INCLUDE_DIRS})
|
||||||
|
link_directories(${SDL2_LIBRARY_DIRS})
|
||||||
|
add_definitions(${SDL2_CFLAGS_OTHER})
|
||||||
|
elseif (TARGET_PLATFORM STREQUAL "linux")
|
||||||
pkg_check_modules(SDL2 REQUIRED sdl2)
|
pkg_check_modules(SDL2 REQUIRED sdl2)
|
||||||
|
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
|
||||||
|
include_directories(${SDL2_INCLUDE_DIRS})
|
||||||
|
add_definitions(${SDL2_CFLAGS_OTHER})
|
||||||
|
else ()
|
||||||
|
message(FATAL_ERROR "Unsupported TARGET_PLATFORM: ${TARGET_PLATFORM}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
add_executable(RISCB main.c
|
# Define source files
|
||||||
util/font.c
|
set(SOURCE_FILES
|
||||||
util/font.h
|
main.c
|
||||||
assembler/assembler.c
|
util/font.c util/font.h
|
||||||
assembler/assembler.h
|
assembler/assembler.c assembler/assembler.h
|
||||||
cpu/memory.c
|
cpu/memory.c cpu/memory.h
|
||||||
cpu/memory.h
|
cpu/core.c cpu/core.h
|
||||||
cpu/core.c
|
util/texteditor.c util/texteditor.h
|
||||||
cpu/core.h
|
util/hexdump.c util/hexdump.h
|
||||||
util/texteditor.c
|
util/cpustatusui.c util/cpustatusui.h
|
||||||
util/texteditor.h
|
)
|
||||||
util/hexdump.c
|
|
||||||
util/hexdump.h
|
|
||||||
util/cpustatusui.c
|
|
||||||
util/cpustatusui.h) # Ensure the target is defined before linking
|
|
||||||
|
|
||||||
|
# Build the target executable
|
||||||
|
add_executable(RISCB ${SOURCE_FILES})
|
||||||
target_link_libraries(RISCB SDL2 SDL2_ttf m)
|
target_link_libraries(RISCB SDL2 SDL2_ttf m)
|
||||||
|
|
||||||
|
# Cross-compile Windows executable on Unix
|
||||||
|
if (UNIX AND TARGET_PLATFORM STREQUAL "mingw")
|
||||||
|
add_executable(RISCB_WIN32 ${SOURCE_FILES})
|
||||||
|
set_target_properties(RISCB_WIN32 PROPERTIES COMPILE_FLAGS "-mwindows")
|
||||||
|
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
||||||
|
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||||
|
add_definitions(-DSDL_MAIN_HANDLED)
|
||||||
|
target_link_libraries(RISCB_WIN32 mingw32 SDL2main SDL2 SDL2_ttf -static-libgcc -static-libstdc++)
|
||||||
|
endif ()
|
||||||
|
22
main.c
22
main.c
@@ -1,6 +1,6 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <threads.h>
|
#include <time.h>
|
||||||
#include "util/font.h"
|
#include "util/font.h"
|
||||||
#include "assembler/assembler.h"
|
#include "assembler/assembler.h"
|
||||||
#include "util/texteditor.h"
|
#include "util/texteditor.h"
|
||||||
@@ -103,7 +103,7 @@ int init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Create window
|
//Create window
|
||||||
window = SDL_CreateWindow("SDLko", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
window = SDL_CreateWindow("RISC-B simulator", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||||
SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
|
SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
|
||||||
if (window == NULL) {
|
if (window == NULL) {
|
||||||
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
|
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
|
||||||
@@ -120,10 +120,10 @@ int init() {
|
|||||||
SDL_RenderSetViewport(renderer, &viewport);
|
SDL_RenderSetViewport(renderer, &viewport);
|
||||||
|
|
||||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||||
biggerFont = prepText(renderer, 16, "../PublicPixel.ttf", 255, 255, 255, 255);
|
biggerFont = prepText(renderer, 16, "PublicPixel.ttf", 255, 255, 255, 255);
|
||||||
smallFont = prepText(renderer, 12, "../PublicPixel.ttf", 255, 255, 255, 255);
|
smallFont = prepText(renderer, 12, "PublicPixel.ttf", 255, 255, 255, 255);
|
||||||
smallerFont = prepText(renderer, 8, "../PublicPixel.ttf", 255, 255, 255, 255);
|
smallerFont = prepText(renderer, 8, "PublicPixel.ttf", 255, 255, 255, 255);
|
||||||
init_editor(&codeEditor, &smallFont, 10, 80, renderer, 54, 1000, 48, false);
|
init_editor(&codeEditor, &smallFont, 10, 80, renderer, 35, 1000, 48, false);
|
||||||
init_editor(&memoryViewer, &smallerFont, 738, 80, renderer, 59, MEM_SIZE / 16 + 2, 70, true);
|
init_editor(&memoryViewer, &smallerFont, 738, 80, renderer, 59, MEM_SIZE / 16 + 2, 70, true);
|
||||||
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
|
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, NULL);
|
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, NULL);
|
||||||
@@ -514,13 +514,13 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char *args[])
|
|||||||
|
|
||||||
puts(SDL_GetError());
|
puts(SDL_GetError());
|
||||||
|
|
||||||
//SDL_DestroyRenderer(renderer);
|
if (cpuStatsTexture) SDL_DestroyTexture(cpuStatsTexture);
|
||||||
|
if (cpuStateTexture) SDL_DestroyTexture(cpuStateTexture);
|
||||||
|
|
||||||
//Destroy window
|
if (renderer) SDL_DestroyRenderer(renderer);
|
||||||
//SDL_DestroyWindow(window);
|
if (window) SDL_DestroyWindow(window);
|
||||||
|
|
||||||
//Quit SDL subsystems
|
SDL_Quit();
|
||||||
//SDL_Quit();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@@ -345,7 +345,7 @@ void editor_render(TextEditor *editor, SDL_Renderer *renderer, CPU *cpu, uint8_t
|
|||||||
SDL_Rect highlightedLineAbs = *editor->highlightedLineRect;
|
SDL_Rect highlightedLineAbs = *editor->highlightedLineRect;
|
||||||
highlightedLineAbs.x += editor->outRect->x;
|
highlightedLineAbs.x += editor->outRect->x;
|
||||||
highlightedLineAbs.y += editor->outRect->y;
|
highlightedLineAbs.y += editor->outRect->y;
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 72, 64, 255);
|
SDL_SetRenderDrawColor(renderer, 0, 64, 128, 255);
|
||||||
if (targetLine >= editor->cursor_line_offset &&
|
if (targetLine >= editor->cursor_line_offset &&
|
||||||
targetLine < editor->cursor_line_offset + editor->displayLineCount) {
|
targetLine < editor->cursor_line_offset + editor->displayLineCount) {
|
||||||
SDL_RenderFillRect(renderer, &highlightedLineAbs);
|
SDL_RenderFillRect(renderer, &highlightedLineAbs);
|
||||||
|
Reference in New Issue
Block a user