From 5b46e0aec4fd48e623ec111a4e5dd1060130d28c Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Sun, 12 Jul 2026 10:46:54 +0200 Subject: [PATCH 1/8] Cleanup gfx init --- src/bme/bme_gfx.cpp | 7 ++----- src/bme/bme_gfx.h | 2 +- src/bme/bme_main.h | 4 ---- src/console.cpp | 4 ++-- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/bme/bme_gfx.cpp b/src/bme/bme_gfx.cpp index 189cf0e..6b3913b 100644 --- a/src/bme/bme_gfx.cpp +++ b/src/bme/bme_gfx.cpp @@ -72,7 +72,6 @@ SDL_Renderer *gfx_renderer = nullptr; static bool gfx_initexec = false; static unsigned gfx_last_xsize; static unsigned gfx_last_ysize; -static unsigned gfx_last_framerate; static unsigned gfx_last_flags; static int gfx_cliptop; static int gfx_clipbottom; @@ -85,7 +84,7 @@ static SDL_Color gfx_sdlpalette[MAX_COLORS]; static bool gfx_locked = false; static SDL_Texture *sdlTexture = nullptr; -bool gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags) +bool gfx_init(unsigned xsize, unsigned ysize, unsigned flags) { // Prevent re-entry (by window procedure) if (gfx_initexec) return true; @@ -93,7 +92,6 @@ bool gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags gfx_last_xsize = xsize; gfx_last_ysize = ysize; - gfx_last_framerate = framerate; gfx_last_flags = flags & ~(GFX_FULLSCREEN | GFX_WINDOW); // Store the options contained in the flags @@ -152,8 +150,7 @@ bool gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags int gfx_reinit() { gfx_uninit(); - return gfx_init(gfx_last_xsize, gfx_last_ysize, gfx_last_framerate, - gfx_last_flags); + return gfx_init(gfx_last_xsize, gfx_last_ysize, gfx_last_flags); } void gfx_uninit() diff --git a/src/bme/bme_gfx.h b/src/bme/bme_gfx.h index d3edb98..a262b1d 100644 --- a/src/bme/bme_gfx.h +++ b/src/bme/bme_gfx.h @@ -7,7 +7,7 @@ #define MAX_COLORS 16 // 8bit oldskool mode -bool gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); +bool gfx_init(unsigned xsize, unsigned ysize, unsigned flags); int gfx_reinit(); void gfx_uninit(); bool gfx_lock(); diff --git a/src/bme/bme_main.h b/src/bme/bme_main.h index 392e28d..a675171 100644 --- a/src/bme/bme_main.h +++ b/src/bme/bme_main.h @@ -7,10 +7,6 @@ #define GFX_SCANLINES 1 #define GFX_DOUBLESIZE 2 -#define GFX_USE1PAGE 0 -#define GFX_USE2PAGES 4 -#define GFX_USE3PAGES 8 -#define GFX_WAITVBLANK 16 #define GFX_FULLSCREEN 32 #define GFX_WINDOW 64 diff --git a/src/console.cpp b/src/console.cpp index 174b6c4..d556b56 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -103,10 +103,10 @@ bool initscreen() win_setmousemode(MOUSE_ALWAYS_HIDDEN); initicon(); - if (!gfx_init(MAX_COLUMNS * fontwidth, MAX_ROWS * fontheight, 60, 0)) + if (!gfx_init(MAX_COLUMNS * fontwidth, MAX_ROWS * fontheight, 0)) { win_fullscreen = 0; - if (!gfx_init(MAX_COLUMNS * fontwidth, MAX_ROWS * fontheight, 60, 0)) + if (!gfx_init(MAX_COLUMNS * fontwidth, MAX_ROWS * fontheight, 0)) return false; } From d695e15296ea0716c24233ba44de456d03e083ef Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Sun, 12 Jul 2026 10:55:26 +0200 Subject: [PATCH 2/8] Cleanup --- src/bme/bme_gfx.cpp | 78 ++------------------------------------------- src/bme/bme_gfx.h | 6 ++-- src/bme/bme_main.h | 5 --- src/console.cpp | 4 +-- 4 files changed, 8 insertions(+), 85 deletions(-) diff --git a/src/bme/bme_gfx.cpp b/src/bme/bme_gfx.cpp index 6b3913b..6e0eb52 100644 --- a/src/bme/bme_gfx.cpp +++ b/src/bme/bme_gfx.cpp @@ -57,7 +57,6 @@ void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bot bool gfx_initted = false; bool gfx_redraw = false; -int gfx_scanlinemode = 0; unsigned gfx_virtualxsize; unsigned gfx_virtualysize; unsigned gfx_windowxsize; @@ -72,7 +71,6 @@ SDL_Renderer *gfx_renderer = nullptr; static bool gfx_initexec = false; static unsigned gfx_last_xsize; static unsigned gfx_last_ysize; -static unsigned gfx_last_flags; static int gfx_cliptop; static int gfx_clipbottom; static int gfx_clipleft; @@ -84,7 +82,7 @@ static SDL_Color gfx_sdlpalette[MAX_COLORS]; static bool gfx_locked = false; static SDL_Texture *sdlTexture = nullptr; -bool gfx_init(unsigned xsize, unsigned ysize, unsigned flags) +bool gfx_init(unsigned xsize, unsigned ysize) { // Prevent re-entry (by window procedure) if (gfx_initexec) return true; @@ -92,11 +90,6 @@ bool gfx_init(unsigned xsize, unsigned ysize, unsigned flags) gfx_last_xsize = xsize; gfx_last_ysize = ysize; - gfx_last_flags = flags & ~(GFX_FULLSCREEN | GFX_WINDOW); - - // Store the options contained in the flags - - gfx_scanlinemode = flags & (GFX_SCANLINES | GFX_DOUBLESIZE); SDL_SetWindowFullscreen(win_window, win_fullscreen); @@ -120,11 +113,6 @@ bool gfx_init(unsigned xsize, unsigned ysize, unsigned flags) gfx_windowxsize = gfx_virtualxsize; gfx_windowysize = gfx_virtualysize; - if (gfx_scanlinemode) - { - gfx_windowxsize <<= 1; - gfx_windowysize <<= 1; - } gfx_setclipregion(0, 0, gfx_virtualxsize, gfx_virtualysize); @@ -150,7 +138,7 @@ bool gfx_init(unsigned xsize, unsigned ysize, unsigned flags) int gfx_reinit() { gfx_uninit(); - return gfx_init(gfx_last_xsize, gfx_last_ysize, gfx_last_flags); + return gfx_init(gfx_last_xsize, gfx_last_ysize); } void gfx_uninit() @@ -269,68 +257,9 @@ void gfx_freecursor() } } -void gfx_copyscreen8(Uint8 *destaddress, Uint8 *srcaddress, unsigned pitch) -{ - switch(gfx_scanlinemode) - { - default: - for (unsigned c = 0; c < gfx_virtualysize; c++) - { - std::memcpy(destaddress, srcaddress, gfx_virtualxsize); - destaddress += pitch; - srcaddress += gfx_virtualxsize; - } - break; - - case GFX_SCANLINES: - for (unsigned c = 0; c < gfx_virtualysize; c++) - { - int d = gfx_virtualxsize; - while (d--) - { - *destaddress = *srcaddress; - destaddress++; - *destaddress = *srcaddress; - destaddress++; - srcaddress++; - } - destaddress += pitch*2 - (gfx_virtualxsize << 1); - } - break; - - case GFX_DOUBLESIZE: - for (unsigned c = 0; c < gfx_virtualysize; c++) - { - int d = gfx_virtualxsize; - while (d--) - { - *destaddress = *srcaddress; - destaddress++; - *destaddress = *srcaddress; - destaddress++; - srcaddress++; - } - destaddress += pitch - (gfx_virtualxsize << 1); - srcaddress -= gfx_virtualxsize; - d = gfx_virtualxsize; - while (d--) - { - *destaddress = *srcaddress; - destaddress++; - *destaddress = *srcaddress; - destaddress++; - srcaddress++; - } - destaddress += pitch - (gfx_virtualxsize << 1); - } - break; - } -} - void gfx_drawcursor(int x, int y) { if (!gfx_initted) return; - //if (!gfx_locked) return; if (!gfx_cursor) { @@ -350,6 +279,5 @@ void gfx_drawcursor(int x, int y) SDL_Rect dstrect; dstrect.x = x; dstrect.y = y; - if (!SDL_BlitSurface(gfx_cursor, NULL, gfx_screen, &dstrect)) - printf("Error: %s\n", SDL_GetError()); + SDL_BlitSurface(gfx_cursor, NULL, gfx_screen, &dstrect); } diff --git a/src/bme/bme_gfx.h b/src/bme/bme_gfx.h index a262b1d..5b05740 100644 --- a/src/bme/bme_gfx.h +++ b/src/bme/bme_gfx.h @@ -5,9 +5,9 @@ #include -#define MAX_COLORS 16 // 8bit oldskool mode +#define MAX_COLORS 16 -bool gfx_init(unsigned xsize, unsigned ysize, unsigned flags); +bool gfx_init(unsigned xsize, unsigned ysize); int gfx_reinit(); void gfx_uninit(); bool gfx_lock(); @@ -16,7 +16,7 @@ void gfx_flip(); void gfx_setpalette(); -bool gfx_loadcursor( const char *name); +bool gfx_loadcursor(const char *name); void gfx_drawcursor(int x, int y); void gfx_freecursor(); diff --git a/src/bme/bme_main.h b/src/bme/bme_main.h index a675171..468c573 100644 --- a/src/bme/bme_main.h +++ b/src/bme/bme_main.h @@ -5,11 +5,6 @@ #include -#define GFX_SCANLINES 1 -#define GFX_DOUBLESIZE 2 -#define GFX_FULLSCREEN 32 -#define GFX_WINDOW 64 - #define MOUSE_ALWAYS_VISIBLE 0 #define MOUSE_FULLSCREEN_HIDDEN 1 #define MOUSE_ALWAYS_HIDDEN 2 diff --git a/src/console.cpp b/src/console.cpp index d556b56..d33bcf3 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -103,10 +103,10 @@ bool initscreen() win_setmousemode(MOUSE_ALWAYS_HIDDEN); initicon(); - if (!gfx_init(MAX_COLUMNS * fontwidth, MAX_ROWS * fontheight, 0)) + if (!gfx_init(MAX_COLUMNS * fontwidth, MAX_ROWS * fontheight)) { win_fullscreen = 0; - if (!gfx_init(MAX_COLUMNS * fontwidth, MAX_ROWS * fontheight, 0)) + if (!gfx_init(MAX_COLUMNS * fontwidth, MAX_ROWS * fontheight)) return false; } From 8c3f5d26dd46d638348a5d3c633838c6617baa3f Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Sun, 12 Jul 2026 11:03:50 +0200 Subject: [PATCH 3/8] More cleanup --- src/bme/bme_gfx.cpp | 18 +++++++++--------- src/bme/bme_main.h | 4 ---- src/bme/bme_win.cpp | 30 +----------------------------- src/bme/bme_win.h | 2 -- src/console.cpp | 1 - 5 files changed, 10 insertions(+), 45 deletions(-) diff --git a/src/bme/bme_gfx.cpp b/src/bme/bme_gfx.cpp index 6e0eb52..90f53cc 100644 --- a/src/bme/bme_gfx.cpp +++ b/src/bme/bme_gfx.cpp @@ -118,21 +118,21 @@ bool gfx_init(unsigned xsize, unsigned ysize) gfx_renderer = SDL_CreateRenderer(win_window, nullptr); gfx_screen = SDL_CreateSurface(xsize, ysize, SDL_PIXELFORMAT_INDEX8); + if (!gfx_screen) + return false; + sdlTexture = SDL_CreateTexture(gfx_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, xsize, ysize); + gfx_setpalette(); + SDL_HideCursor(); + gfx_initexec = false; - if (gfx_screen) - { - gfx_initted = true; - gfx_redraw = true; - gfx_setpalette(); - win_setmousemode(win_mousemode); - return true; - } - else return false; + gfx_initted = true; + gfx_redraw = true; + return true; } int gfx_reinit() diff --git a/src/bme/bme_main.h b/src/bme/bme_main.h index 468c573..2ede3e4 100644 --- a/src/bme/bme_main.h +++ b/src/bme/bme_main.h @@ -5,10 +5,6 @@ #include -#define MOUSE_ALWAYS_VISIBLE 0 -#define MOUSE_FULLSCREEN_HIDDEN 1 -#define MOUSE_ALWAYS_HIDDEN 2 - #define MOUSEB_LEFT 1 #define MOUSEB_RIGHT 2 #define MOUSEB_MIDDLE 4 diff --git a/src/bme/bme_win.cpp b/src/bme/bme_win.cpp index 779c2f8..2c2e442 100644 --- a/src/bme/bme_win.cpp +++ b/src/bme/bme_win.cpp @@ -30,7 +30,6 @@ unsigned win_mouseypos = 0; unsigned win_mousexrel = 0; unsigned win_mouseyrel = 0; unsigned win_mousebuttons = 0; -int win_mousemode = MOUSE_FULLSCREEN_HIDDEN; float win_mouseywheel = 0.f; unsigned char win_keystate[SDL_SCANCODE_COUNT] = {0}; @@ -209,33 +208,6 @@ void win_checkmessages() } } -void win_setmousemode(int mode) -{ - win_mousemode = mode; - - switch(mode) - { - case MOUSE_ALWAYS_VISIBLE: - SDL_ShowCursor(); - break; - - case MOUSE_FULLSCREEN_HIDDEN: - if (win_fullscreen) - { - SDL_HideCursor(); - } - else - { - SDL_ShowCursor(); - } - break; - - case MOUSE_ALWAYS_HIDDEN: - SDL_HideCursor(); - break; - } -} - void mou_init() { win_mousebuttons = 0; @@ -255,7 +227,7 @@ void mou_getpos(unsigned *x, unsigned *y) } } -unsigned mou_getbuttons(void) +unsigned mou_getbuttons() { return win_mousebuttons; } diff --git a/src/bme/bme_win.h b/src/bme/bme_win.h index 9dcd413..7f7fc00 100644 --- a/src/bme/bme_win.h +++ b/src/bme/bme_win.h @@ -8,7 +8,6 @@ int win_openwindow(unsigned xsize, unsigned ysize, const char *appname); void win_closewindow(void); int win_getspeed(int framerate); -void win_setmousemode(int mode); void mou_init(); void mou_getpos(unsigned *x, unsigned *y); @@ -19,7 +18,6 @@ extern int win_fullscreen; extern unsigned char win_keytable[SDL_SCANCODE_COUNT]; extern unsigned char win_keystate[SDL_SCANCODE_COUNT]; extern unsigned char win_asciikey; -extern int win_mousemode; extern float win_mouseywheel; extern SDL_Window *win_window; diff --git a/src/console.cpp b/src/console.cpp index d33bcf3..34bab19 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -100,7 +100,6 @@ bool initscreen() unsigned ysize = MAX_ROWS * 16; win_openwindow(xsize, ysize, "LoadTracker"); - win_setmousemode(MOUSE_ALWAYS_HIDDEN); initicon(); if (!gfx_init(MAX_COLUMNS * fontwidth, MAX_ROWS * fontheight)) From 75a62596ce5dd12968317a179057553dbe010f6d Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Sun, 12 Jul 2026 11:04:43 +0200 Subject: [PATCH 4/8] Convert to bool --- src/bme/bme_win.cpp | 4 ++-- src/bme/bme_win.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bme/bme_win.cpp b/src/bme/bme_win.cpp index 2c2e442..6c492a9 100644 --- a/src/bme/bme_win.cpp +++ b/src/bme/bme_win.cpp @@ -22,7 +22,7 @@ void win_checkmessages(); int win_fullscreen = 0; // By default windowed bool win_windowinitted = false; -int win_quitted = 0; +bool win_quitted = false; unsigned char win_keytable[SDL_SCANCODE_COUNT] = {0}; unsigned char win_asciikey = 0; unsigned win_mousexpos = 0; @@ -168,7 +168,7 @@ void win_checkmessages() break; case SDL_EVENT_QUIT: - win_quitted = 1; + win_quitted = true; break; case SDL_EVENT_TEXT_INPUT: diff --git a/src/bme/bme_win.h b/src/bme/bme_win.h index 7f7fc00..497c55b 100644 --- a/src/bme/bme_win.h +++ b/src/bme/bme_win.h @@ -13,7 +13,7 @@ void mou_init(); void mou_getpos(unsigned *x, unsigned *y); unsigned mou_getbuttons(); -extern int win_quitted; +extern bool win_quitted; extern int win_fullscreen; extern unsigned char win_keytable[SDL_SCANCODE_COUNT]; extern unsigned char win_keystate[SDL_SCANCODE_COUNT]; From 422632b854afbe5bd0e3179a0ca3a471c6fb5a34 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Sun, 12 Jul 2026 11:14:20 +0200 Subject: [PATCH 5/8] More cleanup --- src/bme/bme_gfx.cpp | 4 ++-- src/bme/bme_win.cpp | 10 +++++----- src/bme/bme_win.h | 4 ++-- src/console.cpp | 4 +++- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/bme/bme_gfx.cpp b/src/bme/bme_gfx.cpp index 90f53cc..21f8ed0 100644 --- a/src/bme/bme_gfx.cpp +++ b/src/bme/bme_gfx.cpp @@ -116,18 +116,18 @@ bool gfx_init(unsigned xsize, unsigned ysize) gfx_setclipregion(0, 0, gfx_virtualxsize, gfx_virtualysize); - gfx_renderer = SDL_CreateRenderer(win_window, nullptr); gfx_screen = SDL_CreateSurface(xsize, ysize, SDL_PIXELFORMAT_INDEX8); if (!gfx_screen) return false; + gfx_renderer = SDL_CreateRenderer(win_window, nullptr); sdlTexture = SDL_CreateTexture(gfx_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, xsize, ysize); - gfx_setpalette(); SDL_HideCursor(); + gfx_setpalette(); gfx_initexec = false; gfx_initted = true; diff --git a/src/bme/bme_win.cpp b/src/bme/bme_win.cpp index 6c492a9..a11ec5c 100644 --- a/src/bme/bme_win.cpp +++ b/src/bme/bme_win.cpp @@ -42,7 +42,7 @@ static Uint64 win_currenttime = 0; static int win_framecounter = 0; static int win_activateclick = 0; -int win_openwindow(unsigned xsize, unsigned ysize, const char *appname) +bool win_openwindow(unsigned xsize, unsigned ysize, const char *appname) { Uint32 flags = SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_RESIZABLE; if (win_fullscreen) flags |= SDL_WINDOW_FULLSCREEN; @@ -51,7 +51,7 @@ int win_openwindow(unsigned xsize, unsigned ysize, const char *appname) { if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK)) { - return BME_ERROR; + return false; } std::atexit(SDL_Quit); win_windowinitted = true; @@ -62,13 +62,13 @@ int win_openwindow(unsigned xsize, unsigned ysize, const char *appname) win_window = SDL_CreateWindow(appname, xsize, ysize, flags); if (!win_window) { - return BME_ERROR; + return false; } SDL_StartTextInput(win_window); - return BME_OK; + return true; } -void win_closewindow(void) +void win_closewindow() { SDL_StopTextInput(win_window); SDL_DestroyWindow(win_window); diff --git a/src/bme/bme_win.h b/src/bme/bme_win.h index 497c55b..6142300 100644 --- a/src/bme/bme_win.h +++ b/src/bme/bme_win.h @@ -5,8 +5,8 @@ #include -int win_openwindow(unsigned xsize, unsigned ysize, const char *appname); -void win_closewindow(void); +bool win_openwindow(unsigned xsize, unsigned ysize, const char *appname); +void win_closewindow(); int win_getspeed(int framerate); void mou_init(); diff --git a/src/console.cpp b/src/console.cpp index 34bab19..6a05ed0 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -99,7 +99,8 @@ bool initscreen() unsigned xsize = MAX_COLUMNS * 8; unsigned ysize = MAX_ROWS * 16; - win_openwindow(xsize, ysize, "LoadTracker"); + if (!win_openwindow(xsize, ysize, "LoadTracker")) + return false; initicon(); if (!gfx_init(MAX_COLUMNS * fontwidth, MAX_ROWS * fontheight)) @@ -210,6 +211,7 @@ void closescreen() gfx_freecursor(); gfxinitted = false; + win_closewindow(); } void clearscreen() From d35311e48ca926f4eaf4f1ae04f790d2d58e4ec2 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Sun, 12 Jul 2026 11:21:18 +0200 Subject: [PATCH 6/8] Merge files --- CMakeLists.txt | 1 - src/bme/bme_gfx.cpp | 283 -------------------------------------------- src/bme/bme_gfx.h | 32 ----- src/bme/bme_win.cpp | 269 ++++++++++++++++++++++++++++++++++++++++- src/bme/bme_win.h | 17 +++ src/console.cpp | 1 - 6 files changed, 285 insertions(+), 318 deletions(-) delete mode 100644 src/bme/bme_gfx.cpp delete mode 100644 src/bme/bme_gfx.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cf13adf..8ce1dbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,6 @@ set(LOADTRK_SOURCES src/asm/parse.c src/asm/pc.c src/asm/vec.c - src/bme/bme_gfx.cpp src/bme/bme_snd.cpp src/bme/bme_win.cpp src/bme/bme_io.cpp diff --git a/src/bme/bme_gfx.cpp b/src/bme/bme_gfx.cpp deleted file mode 100644 index 21f8ed0..0000000 --- a/src/bme/bme_gfx.cpp +++ /dev/null @@ -1,283 +0,0 @@ -// -// BME (Blasphemous Multimedia Engine) graphics main module -// - -#include "bme_gfx.h" - -#include "bme_main.h" -#include "bme_win.h" -#include "bme_io.h" - -#include - -#include - -#include -#include -#include - -// Colodore palette -unsigned char gfx_palette[MAX_COLORS * 3] = -{ - // Black - 0x00, 0x00, 0x00, - // White - 0xFF, 0xFF, 0xFF, - // Red - 0x96, 0x28, 0x2e, - // Cyan - 0x5b, 0xd6, 0xce, - // Purple - 0x9f, 0x2d, 0xad, - // Green - 0x41, 0xb9, 0x36, - // Blue - 0x27, 0x24, 0xc4, - // Yellow - 0xef, 0xf3, 0x47, - // Orange - 0x9f, 0x48, 0x15, - // Brown - 0x5e, 0x35, 0x00, - // Light Red - 0xda, 0x5f, 0x66, - // Dark Gray - 0x47, 0x47, 0x47, - // Medium Gray - 0x78, 0x78, 0x78, - // Light Green - 0x91, 0xff, 0x84, - // Light Blue - 0x68, 0x64, 0xff, - // Light Gray - 0xae, 0xae, 0xae -}; - -void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom); - -bool gfx_initted = false; -bool gfx_redraw = false; -unsigned gfx_virtualxsize; -unsigned gfx_virtualysize; -unsigned gfx_windowxsize; -unsigned gfx_windowysize; -int spr_xsize = 0; -int spr_ysize = 0; -SDL_Surface *gfx_screen = nullptr; -SDL_Renderer *gfx_renderer = nullptr; - -// Static variables - -static bool gfx_initexec = false; -static unsigned gfx_last_xsize; -static unsigned gfx_last_ysize; -static int gfx_cliptop; -static int gfx_clipbottom; -static int gfx_clipleft; -static int gfx_clipright; - -static SDL_Surface *gfx_cursor = nullptr; - -static SDL_Color gfx_sdlpalette[MAX_COLORS]; -static bool gfx_locked = false; -static SDL_Texture *sdlTexture = nullptr; - -bool gfx_init(unsigned xsize, unsigned ysize) -{ - // Prevent re-entry (by window procedure) - if (gfx_initexec) return true; - gfx_initexec = true; - - gfx_last_xsize = xsize; - gfx_last_ysize = ysize; - - SDL_SetWindowFullscreen(win_window, win_fullscreen); - - // Calculate virtual window size - - gfx_virtualxsize = xsize; - gfx_virtualxsize /= 16; - gfx_virtualxsize *= 16; - gfx_virtualysize = ysize; - - if ((!gfx_virtualxsize) || (!gfx_virtualysize)) - { - gfx_initexec = false; - gfx_uninit(); - bme_error = BME_ILLEGAL_CONFIG; - return false; - } - - // Calculate actual window size (for scanline mode & doublesize mode - // this is double the virtual) - - gfx_windowxsize = gfx_virtualxsize; - gfx_windowysize = gfx_virtualysize; - - gfx_setclipregion(0, 0, gfx_virtualxsize, gfx_virtualysize); - - gfx_screen = SDL_CreateSurface(xsize, ysize, SDL_PIXELFORMAT_INDEX8); - if (!gfx_screen) - return false; - - gfx_renderer = SDL_CreateRenderer(win_window, nullptr); - sdlTexture = SDL_CreateTexture(gfx_renderer, - SDL_PIXELFORMAT_RGBA32, - SDL_TEXTUREACCESS_STREAMING, - xsize, ysize); - - SDL_HideCursor(); - gfx_setpalette(); - - gfx_initexec = false; - gfx_initted = true; - gfx_redraw = true; - return true; -} - -int gfx_reinit() -{ - gfx_uninit(); - return gfx_init(gfx_last_xsize, gfx_last_ysize); -} - -void gfx_uninit() -{ - SDL_DestroyTexture(sdlTexture); - SDL_DestroySurface(gfx_screen); - SDL_DestroyRenderer(gfx_renderer); - gfx_initted = false; - return; -} - -bool gfx_lock() -{ - if (gfx_locked) return true; - if (!gfx_initted) return false; - if (SDL_LockSurface(gfx_screen)) - { - gfx_locked = true; - return true; - } - else return false; -} - -void gfx_unlock() -{ - if (gfx_locked) - { - SDL_UnlockSurface(gfx_screen); - gfx_locked = false; - } -} - -void gfx_flip() -{ - SDL_Surface* surf = SDL_ConvertSurface(gfx_screen, SDL_PIXELFORMAT_RGBA32); - SDL_UpdateTexture(sdlTexture, nullptr, surf->pixels, surf->pitch); - SDL_DestroySurface(surf); - SDL_RenderClear(gfx_renderer); - SDL_RenderTexture(gfx_renderer, sdlTexture, nullptr, nullptr); - SDL_RenderPresent(gfx_renderer); - gfx_redraw = false; -} - -void gfx_calcpalette() -{ - unsigned char *sptr = gfx_palette; - for (int c = 0; c < MAX_COLORS; c++) - { - gfx_sdlpalette[c].r = *sptr; - sptr++; - - gfx_sdlpalette[c].g = *sptr; - sptr++; - - gfx_sdlpalette[c].b = *sptr; - sptr++; - - gfx_sdlpalette[c].a = 255; - } -} - -void gfx_setpalette() -{ - if (!gfx_initted) return; - - gfx_calcpalette(); - SDL_Palette *palette = SDL_CreateSurfacePalette(gfx_screen); - SDL_SetPaletteColors(palette, &gfx_sdlpalette[0], 0, MAX_COLORS); -} - -void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom) -{ - if (left >= right) return; - if (top >= bottom) return; - if (left >= gfx_virtualxsize) return; - if (top >= gfx_virtualysize) return; - if (right > gfx_virtualxsize) return; - if (bottom > gfx_virtualysize) return; - - gfx_clipleft = left; - gfx_clipright = right; - gfx_cliptop = top; - gfx_clipbottom = bottom; -} - -bool gfx_loadcursor(const char *name) -{ - bme_error = BME_OPEN_ERROR; - - gfx_freecursor(); - - int handle = io_open(name); - if (handle == -1) return false; - - int size = io_lseek(handle, 0, SEEK_END); - io_lseek(handle, 0, SEEK_SET); - char *iconbuffer = new (std::nothrow) char[size]; - io_read(handle, iconbuffer, size); - io_close(handle); - - SDL_IOStream *rw = SDL_IOFromMem(iconbuffer, size); - gfx_cursor = SDL_LoadPNG_IO(rw, true); - if (!gfx_cursor) - return false; - - bme_error = BME_OK; - return true; -} - -void gfx_freecursor() -{ - if (gfx_cursor) - { - SDL_DestroySurface(gfx_cursor); - gfx_cursor = nullptr; - } -} - -void gfx_drawcursor(int x, int y) -{ - if (!gfx_initted) return; - - if (!gfx_cursor) - { - spr_xsize = 0; - spr_ysize = 0; - return; - } - - spr_xsize = gfx_cursor->w; - spr_ysize = gfx_cursor->h; - - if (x >= gfx_clipright) return; - if (y >= gfx_clipbottom) return; - if (x + spr_xsize <= gfx_clipleft) return; - if (y + spr_ysize <= gfx_cliptop) return; - - SDL_Rect dstrect; - dstrect.x = x; - dstrect.y = y; - SDL_BlitSurface(gfx_cursor, NULL, gfx_screen, &dstrect); -} diff --git a/src/bme/bme_gfx.h b/src/bme/bme_gfx.h deleted file mode 100644 index 5b05740..0000000 --- a/src/bme/bme_gfx.h +++ /dev/null @@ -1,32 +0,0 @@ -// BME graphics module header file - -#ifndef BME_GFX_H -#define BME_GFX_H - -#include - -#define MAX_COLORS 16 - -bool gfx_init(unsigned xsize, unsigned ysize); -int gfx_reinit(); -void gfx_uninit(); -bool gfx_lock(); -void gfx_unlock(); -void gfx_flip(); - -void gfx_setpalette(); - -bool gfx_loadcursor(const char *name); -void gfx_drawcursor(int x, int y); -void gfx_freecursor(); - -extern bool gfx_initted; -extern bool gfx_redraw; -extern unsigned gfx_windowxsize; -extern unsigned gfx_windowysize; -extern unsigned gfx_virtualxsize; -extern unsigned gfx_virtualysize; -extern unsigned char gfx_palette[]; -extern SDL_Surface *gfx_screen; - -#endif diff --git a/src/bme/bme_win.cpp b/src/bme/bme_win.cpp index a11ec5c..e760970 100644 --- a/src/bme/bme_win.cpp +++ b/src/bme/bme_win.cpp @@ -5,18 +5,60 @@ #include "bme_win.h" #include "bme_main.h" -#include "bme_gfx.h" #include "bme_io.h" #include +#include + #include #include #include +// Colodore palette +unsigned char gfx_palette[MAX_COLORS * 3] = +{ + // Black + 0x00, 0x00, 0x00, + // White + 0xFF, 0xFF, 0xFF, + // Red + 0x96, 0x28, 0x2e, + // Cyan + 0x5b, 0xd6, 0xce, + // Purple + 0x9f, 0x2d, 0xad, + // Green + 0x41, 0xb9, 0x36, + // Blue + 0x27, 0x24, 0xc4, + // Yellow + 0xef, 0xf3, 0x47, + // Orange + 0x9f, 0x48, 0x15, + // Brown + 0x5e, 0x35, 0x00, + // Light Red + 0xda, 0x5f, 0x66, + // Dark Gray + 0x47, 0x47, 0x47, + // Medium Gray + 0x78, 0x78, 0x78, + // Light Green + 0x91, 0xff, 0x84, + // Light Blue + 0x68, 0x64, 0xff, + // Light Gray + 0xae, 0xae, 0xae +}; + SDL_Window *win_window = nullptr; void win_checkmessages(); +void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom); +int gfx_reinit(); +void gfx_uninit(); + // Global variables @@ -33,6 +75,17 @@ unsigned win_mousebuttons = 0; float win_mouseywheel = 0.f; unsigned char win_keystate[SDL_SCANCODE_COUNT] = {0}; +bool gfx_initted = false; +bool gfx_redraw = false; +unsigned gfx_virtualxsize; +unsigned gfx_virtualysize; +unsigned gfx_windowxsize; +unsigned gfx_windowysize; +int spr_xsize = 0; +int spr_ysize = 0; +SDL_Surface *gfx_screen = nullptr; +SDL_Renderer *gfx_renderer = nullptr; + int bme_error = BME_OK; // Static variables @@ -42,6 +95,20 @@ static Uint64 win_currenttime = 0; static int win_framecounter = 0; static int win_activateclick = 0; +static bool gfx_initexec = false; +static unsigned gfx_last_xsize; +static unsigned gfx_last_ysize; +static int gfx_cliptop; +static int gfx_clipbottom; +static int gfx_clipleft; +static int gfx_clipright; + +static SDL_Surface *gfx_cursor = nullptr; + +static SDL_Color gfx_sdlpalette[MAX_COLORS]; +static bool gfx_locked = false; +static SDL_Texture *sdlTexture = nullptr; + bool win_openwindow(unsigned xsize, unsigned ysize, const char *appname) { Uint32 flags = SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_RESIZABLE; @@ -208,6 +275,206 @@ void win_checkmessages() } } +bool gfx_init(unsigned xsize, unsigned ysize) +{ + // Prevent re-entry (by window procedure) + if (gfx_initexec) return true; + gfx_initexec = true; + + gfx_last_xsize = xsize; + gfx_last_ysize = ysize; + + SDL_SetWindowFullscreen(win_window, win_fullscreen); + + // Calculate virtual window size + + gfx_virtualxsize = xsize; + gfx_virtualxsize /= 16; + gfx_virtualxsize *= 16; + gfx_virtualysize = ysize; + + if ((!gfx_virtualxsize) || (!gfx_virtualysize)) + { + gfx_initexec = false; + gfx_uninit(); + bme_error = BME_ILLEGAL_CONFIG; + return false; + } + + // Calculate actual window size (for scanline mode & doublesize mode + // this is double the virtual) + + gfx_windowxsize = gfx_virtualxsize; + gfx_windowysize = gfx_virtualysize; + + gfx_setclipregion(0, 0, gfx_virtualxsize, gfx_virtualysize); + + gfx_screen = SDL_CreateSurface(xsize, ysize, SDL_PIXELFORMAT_INDEX8); + if (!gfx_screen) + return false; + + gfx_renderer = SDL_CreateRenderer(win_window, nullptr); + sdlTexture = SDL_CreateTexture(gfx_renderer, + SDL_PIXELFORMAT_RGBA32, + SDL_TEXTUREACCESS_STREAMING, + xsize, ysize); + + SDL_HideCursor(); + gfx_setpalette(); + + gfx_initexec = false; + gfx_initted = true; + gfx_redraw = true; + return true; +} + +int gfx_reinit() +{ + gfx_uninit(); + return gfx_init(gfx_last_xsize, gfx_last_ysize); +} + +void gfx_uninit() +{ + SDL_DestroyTexture(sdlTexture); + SDL_DestroySurface(gfx_screen); + SDL_DestroyRenderer(gfx_renderer); + gfx_initted = false; + return; +} + +bool gfx_lock() +{ + if (gfx_locked) return true; + if (!gfx_initted) return false; + if (SDL_LockSurface(gfx_screen)) + { + gfx_locked = true; + return true; + } + else return false; +} + +void gfx_unlock() +{ + if (gfx_locked) + { + SDL_UnlockSurface(gfx_screen); + gfx_locked = false; + } +} + +void gfx_flip() +{ + SDL_Surface* surf = SDL_ConvertSurface(gfx_screen, SDL_PIXELFORMAT_RGBA32); + SDL_UpdateTexture(sdlTexture, nullptr, surf->pixels, surf->pitch); + SDL_DestroySurface(surf); + SDL_RenderClear(gfx_renderer); + SDL_RenderTexture(gfx_renderer, sdlTexture, nullptr, nullptr); + SDL_RenderPresent(gfx_renderer); + gfx_redraw = false; +} + +void gfx_calcpalette() +{ + unsigned char *sptr = gfx_palette; + for (int c = 0; c < MAX_COLORS; c++) + { + gfx_sdlpalette[c].r = *sptr; + sptr++; + + gfx_sdlpalette[c].g = *sptr; + sptr++; + + gfx_sdlpalette[c].b = *sptr; + sptr++; + + gfx_sdlpalette[c].a = 255; + } +} + +void gfx_setpalette() +{ + if (!gfx_initted) return; + + gfx_calcpalette(); + SDL_Palette *palette = SDL_CreateSurfacePalette(gfx_screen); + SDL_SetPaletteColors(palette, &gfx_sdlpalette[0], 0, MAX_COLORS); +} + +void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom) +{ + if (left >= right) return; + if (top >= bottom) return; + if (left >= gfx_virtualxsize) return; + if (top >= gfx_virtualysize) return; + if (right > gfx_virtualxsize) return; + if (bottom > gfx_virtualysize) return; + + gfx_clipleft = left; + gfx_clipright = right; + gfx_cliptop = top; + gfx_clipbottom = bottom; +} + +bool gfx_loadcursor(const char *name) +{ + bme_error = BME_OPEN_ERROR; + + gfx_freecursor(); + + int handle = io_open(name); + if (handle == -1) return false; + + int size = io_lseek(handle, 0, SEEK_END); + io_lseek(handle, 0, SEEK_SET); + char *iconbuffer = new (std::nothrow) char[size]; + io_read(handle, iconbuffer, size); + io_close(handle); + + SDL_IOStream *rw = SDL_IOFromMem(iconbuffer, size); + gfx_cursor = SDL_LoadPNG_IO(rw, true); + if (!gfx_cursor) + return false; + + bme_error = BME_OK; + return true; +} + +void gfx_freecursor() +{ + if (gfx_cursor) + { + SDL_DestroySurface(gfx_cursor); + gfx_cursor = nullptr; + } +} + +void gfx_drawcursor(int x, int y) +{ + if (!gfx_initted) return; + + if (!gfx_cursor) + { + spr_xsize = 0; + spr_ysize = 0; + return; + } + + spr_xsize = gfx_cursor->w; + spr_ysize = gfx_cursor->h; + + if (x >= gfx_clipright) return; + if (y >= gfx_clipbottom) return; + if (x + spr_xsize <= gfx_clipleft) return; + if (y + spr_ysize <= gfx_cliptop) return; + + SDL_Rect dstrect; + dstrect.x = x; + dstrect.y = y; + SDL_BlitSurface(gfx_cursor, NULL, gfx_screen, &dstrect); +} + void mou_init() { win_mousebuttons = 0; diff --git a/src/bme/bme_win.h b/src/bme/bme_win.h index 6142300..4a5e6af 100644 --- a/src/bme/bme_win.h +++ b/src/bme/bme_win.h @@ -5,10 +5,23 @@ #include +#define MAX_COLORS 16 + bool win_openwindow(unsigned xsize, unsigned ysize, const char *appname); void win_closewindow(); int win_getspeed(int framerate); +bool gfx_init(unsigned xsize, unsigned ysize); +bool gfx_lock(); +void gfx_unlock(); +void gfx_flip(); + +void gfx_setpalette(); + +bool gfx_loadcursor(const char *name); +void gfx_drawcursor(int x, int y); +void gfx_freecursor(); + void mou_init(); void mou_getpos(unsigned *x, unsigned *y); unsigned mou_getbuttons(); @@ -21,4 +34,8 @@ extern unsigned char win_asciikey; extern float win_mouseywheel; extern SDL_Window *win_window; +extern bool gfx_redraw; +extern unsigned char gfx_palette[]; +extern SDL_Surface *gfx_screen; + #endif diff --git a/src/console.cpp b/src/console.cpp index 6a05ed0..996f565 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -28,7 +28,6 @@ #include "bme_main.h" #include "bme_win.h" -#include "bme_gfx.h" #include "bme_io.h" #include From d4da3fc5e1a300afe970b673a26c6ba1b36266c1 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Sun, 12 Jul 2026 11:32:23 +0200 Subject: [PATCH 7/8] More cleanup --- src/bme/bme_io.cpp | 8 ++++---- src/bme/bme_io.h | 2 +- src/bme/bme_main.h | 42 ++++++++++++++---------------------------- src/bme/bme_snd.cpp | 6 ++++++ src/bme/bme_win.cpp | 11 +++-------- src/bme/bme_win.h | 1 - src/loadtrk.cpp | 14 +++++++------- 7 files changed, 35 insertions(+), 49 deletions(-) diff --git a/src/bme/bme_io.cpp b/src/bme/bme_io.cpp index 36d5797..1621570 100644 --- a/src/bme/bme_io.cpp +++ b/src/bme/bme_io.cpp @@ -46,7 +46,7 @@ static void linkedseek(unsigned pos); static void linkedread(void *buffer, int length); static unsigned linkedreadle32(void); -int io_openlinkeddatafile(unsigned char *ptr) +bool io_openlinkeddatafile(unsigned char *ptr) { if (datafilehandle) std::fclose(datafilehandle); datafilehandle = nullptr; @@ -59,7 +59,7 @@ int io_openlinkeddatafile(unsigned char *ptr) if (std::memcmp(ident, idstring, 4)) { bme_error = BME_WRONG_FORMAT; - return BME_ERROR; + return false; } files = linkedreadle32(); @@ -67,7 +67,7 @@ int io_openlinkeddatafile(unsigned char *ptr) if (!fileheaders) { bme_error = BME_OUT_OF_MEMORY; - return BME_ERROR; + return false; } for (unsigned index = 0; index < files; index++) { @@ -79,7 +79,7 @@ int io_openlinkeddatafile(unsigned char *ptr) for (unsigned index = 0; index < MAX_HANDLES; index++) handle[index].open = false; io_datafileopen = true; bme_error = BME_OK; - return BME_OK; + return true; } void io_closelinkeddatafile() diff --git a/src/bme/bme_io.h b/src/bme/bme_io.h index 27dd47a..7811bc9 100644 --- a/src/bme/bme_io.h +++ b/src/bme/bme_io.h @@ -3,7 +3,7 @@ #ifndef BME_IO_H #define BME_IO_H -int io_openlinkeddatafile(unsigned char *ptr); +bool io_openlinkeddatafile(unsigned char *ptr); void io_closelinkeddatafile(); int io_open(const char *name); void io_close(int handle); diff --git a/src/bme/bme_main.h b/src/bme/bme_main.h index 2ede3e4..d40d2bd 100644 --- a/src/bme/bme_main.h +++ b/src/bme/bme_main.h @@ -9,26 +9,12 @@ #define MOUSEB_RIGHT 2 #define MOUSEB_MIDDLE 4 -#define LEFT 0 -#define MIDDLE 128 -#define RIGHT 255 - -#define B_OFF 0 -#define B_SOLID 1 -#define B_NOTSOLID 2 - #define MONO 0 #define STEREO 1 #define EIGHTBIT 0 #define SIXTEENBIT 2 #define FLOAT32BIT 4 -#define VM_OFF 0 -#define VM_ON 1 -#define VM_ONESHOT 0 -#define VM_LOOP 2 -#define VM_16BIT 4 - #define KEY_BACKSPACE SDL_SCANCODE_BACKSPACE #define KEY_CAPSLOCK SDL_SCANCODE_CAPSLOCK #define KEY_ENTER SDL_SCANCODE_RETURN @@ -162,24 +148,24 @@ typedef struct { - Sint8 *start; - Sint8 *repeat; - Sint8 *end; - unsigned char voicemode; + Sint8 *start; + Sint8 *repeat; + Sint8 *end; + unsigned char voicemode; } SAMPLE; typedef struct { - volatile Sint8 *pos; - Sint8 *repeat; - Sint8 *end; - SAMPLE *smp; - unsigned freq; - volatile unsigned fractpos; - int vol; - int mastervol; - unsigned panning; - volatile unsigned voicemode; + volatile Sint8 *pos; + Sint8 *repeat; + Sint8 *end; + SAMPLE *smp; + unsigned freq; + volatile unsigned fractpos; + int vol; + int mastervol; + unsigned panning; + volatile unsigned voicemode; } CHANNEL; typedef struct diff --git a/src/bme/bme_snd.cpp b/src/bme/bme_snd.cpp index 585f72f..1b617b9 100644 --- a/src/bme/bme_snd.cpp +++ b/src/bme/bme_snd.cpp @@ -23,6 +23,12 @@ #include #include +#define VM_OFF 0 +#define VM_ON 1 +#define VM_ONESHOT 0 +#define VM_LOOP 2 +#define VM_16BIT 4 + #ifdef USE_JACK typedef jack_default_audio_sample_t sample_t; #endif diff --git a/src/bme/bme_win.cpp b/src/bme/bme_win.cpp index e760970..ddcdaa7 100644 --- a/src/bme/bme_win.cpp +++ b/src/bme/bme_win.cpp @@ -56,7 +56,7 @@ SDL_Window *win_window = nullptr; void win_checkmessages(); void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom); -int gfx_reinit(); +bool gfx_reinit(); void gfx_uninit(); @@ -328,7 +328,7 @@ bool gfx_init(unsigned xsize, unsigned ysize) return true; } -int gfx_reinit() +bool gfx_reinit() { gfx_uninit(); return gfx_init(gfx_last_xsize, gfx_last_ysize); @@ -352,7 +352,7 @@ bool gfx_lock() gfx_locked = true; return true; } - else return false; + return false; } void gfx_unlock() @@ -475,11 +475,6 @@ void gfx_drawcursor(int x, int y) SDL_BlitSurface(gfx_cursor, NULL, gfx_screen, &dstrect); } -void mou_init() -{ - win_mousebuttons = 0; -} - void mou_getpos(unsigned *x, unsigned *y) { if (!gfx_initted) diff --git a/src/bme/bme_win.h b/src/bme/bme_win.h index 4a5e6af..93dacb1 100644 --- a/src/bme/bme_win.h +++ b/src/bme/bme_win.h @@ -22,7 +22,6 @@ bool gfx_loadcursor(const char *name); void gfx_drawcursor(int x, int y); void gfx_freecursor(); -void mou_init(); void mou_getpos(unsigned *x, unsigned *y); unsigned mou_getbuttons(); diff --git a/src/loadtrk.cpp b/src/loadtrk.cpp index 459698f..4a1ffa5 100644 --- a/src/loadtrk.cpp +++ b/src/loadtrk.cpp @@ -186,13 +186,11 @@ void findduplicatepatterns(); int main(int argc, char **argv) { - char filename[MAX_PATHNAME]; - FILE *configfile; - - bool dark = false; - // Open datafile - io_openlinkeddatafile(datafile); + if (!io_openlinkeddatafile(datafile)) + return EXIT_FAILURE; + + char filename[MAX_PATHNAME]; // Load configuration #ifdef __WIN32__ @@ -217,7 +215,7 @@ int main(int argc, char **argv) #endif specialnotenames[0] = 0; scalatuningfilepath[0] = 0; - configfile = fopen(filename, "rt"); + FILE *configfile = fopen(filename, "rt"); if (configfile) { unsigned cfg_version; @@ -262,6 +260,8 @@ int main(int argc, char **argv) // Init pathnames initpaths(); + bool dark = false; + // Scan command line for (int c = 1; c < argc; c++) { From 08b4f2125d287f8f5c337142bdf1c983cb25c29c Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Sun, 12 Jul 2026 11:44:35 +0200 Subject: [PATCH 8/8] More cleanup --- src/loadtrk.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/loadtrk.cpp b/src/loadtrk.cpp index 4a1ffa5..77fee18 100644 --- a/src/loadtrk.cpp +++ b/src/loadtrk.cpp @@ -1799,7 +1799,7 @@ void setspecialnotenames() break; if (i < 93) { - char *name = (char*)std::malloc(4); + char *name = (char*)std::malloc(4); // FIXME std::strncpy(name, specialnotenames + j, 2); std::sprintf(octave, "%d", oct); std::strcpy(name + 2, octave); @@ -1813,16 +1813,13 @@ void setspecialnotenames() void readscalatuningfile() { - char *configptr; - char strbuf[64]; - char name[3]; - double numerator; - double denominator; - double centvalue; - FILE *scalatuningfile = fopen(scalatuningfilepath, "rt"); if (scalatuningfile) { + char *configptr; + char strbuf[64]; + char name[3]; + // Tuning name for (;;) { @@ -1870,13 +1867,15 @@ void readscalatuningfile() } else { - strcat(specialnotenames, name); + std::strcat(specialnotenames, name); } } if (!strchr(strbuf, '.')) { + double numerator; + double denominator; std::sscanf(strbuf, "%lf", &numerator); - if (strchr(strbuf, '/')) + if (std::strchr(strbuf, '/')) { std::sscanf(strchr(strbuf, '/') + 1, "%lf", &denominator); tuning[i] = numerator / denominator; @@ -1884,6 +1883,7 @@ void readscalatuningfile() } else { + double centvalue; std::sscanf(configptr, "%lf", ¢value); tuning[i] = std::pow(2.0, centvalue / 1200.0); } @@ -1895,8 +1895,6 @@ void readscalatuningfile() void switchMode() { char nextMode[7]; - char textbuffer[80]; - if (numsids == 1) { std::strcpy(nextMode, "STEREO"); @@ -1906,6 +1904,7 @@ void switchMode() std::strcpy(nextMode, "MONO"); } + char textbuffer[80]; std::sprintf(textbuffer, "Switch to %s Mode (y/n) ?", nextMode); printtextcp( @@ -1931,7 +1930,7 @@ void switchMode() std::memset(songfilename, 0, sizeof songfilename); numsids ^= 3; - clearsong(1, 1, 1, 1, 1); + clearsong(true, true, true, true, true); sound_init( mr,