Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 44 additions & 63 deletions src/bme/bme_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,42 @@
#include <cstdio>
#include <cstring>

#define MAX_COLORS 256 // 8bit oldskool mode
// 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);

Expand All @@ -29,7 +64,6 @@ unsigned gfx_windowxsize;
unsigned gfx_windowysize;
int spr_xsize = 0;
int spr_ysize = 0;
Uint8 gfx_palette[MAX_COLORS * 3] = {0};
SDL_Surface *gfx_screen = nullptr;
SDL_Renderer *gfx_renderer = nullptr;

Expand All @@ -44,7 +78,6 @@ static int gfx_cliptop;
static int gfx_clipbottom;
static int gfx_clipleft;
static int gfx_clipright;
static int gfx_maxcolors = MAX_COLORS;

static SDL_Surface *gfx_cursor = nullptr;

Expand Down Expand Up @@ -97,16 +130,6 @@ bool gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags

gfx_setclipregion(0, 0, gfx_virtualxsize, gfx_virtualysize);

// Colors 0 & 255 are always black & white
gfx_sdlpalette[0].r = 0;
gfx_sdlpalette[0].g = 0;
gfx_sdlpalette[0].b = 0;
gfx_sdlpalette[0].a = 255;
gfx_sdlpalette[255].r = 255;
gfx_sdlpalette[255].g = 255;
gfx_sdlpalette[255].b = 255;
gfx_sdlpalette[255].a = 255;

gfx_renderer = SDL_CreateRenderer(win_window, nullptr);
gfx_screen = SDL_CreateSurface(xsize, ysize, SDL_PIXELFORMAT_INDEX8);
sdlTexture = SDL_CreateTexture(gfx_renderer,
Expand Down Expand Up @@ -174,61 +197,18 @@ void gfx_flip()
gfx_redraw = false;
}

bool gfx_loadpalette(const char *name)
void gfx_calcpalette()
{
int handle = io_open(name);
if (handle == -1)
{
bme_error = BME_OPEN_ERROR;
return false;
}
if (io_read(handle, gfx_palette, sizeof gfx_palette) != sizeof gfx_palette)
{
bme_error = BME_READ_ERROR;
io_close(handle);
return false;
}

io_close(handle);
gfx_calcpalette(64, 0, 0, 0);
bme_error = BME_OK;
return true;
}

void gfx_calcpalette(int fade, int radd, int gadd, int badd)
{
if (radd < 0) radd = 0;
if (gadd < 0) gadd = 0;
if (badd < 0) badd = 0;

Uint8 *sptr = &gfx_palette[3];
for (int c = 1; c < 255; c++)
unsigned char *sptr = gfx_palette;
for (int c = 0; c < MAX_COLORS; c++)
{
int cl = *sptr;
cl *= fade;
cl >>= 6;
cl += radd;
if (cl > 63) cl = 63;
if (cl < 0) cl = 0;
gfx_sdlpalette[c].r = (cl << 2) | (cl & 3);
gfx_sdlpalette[c].r = *sptr;
sptr++;

cl = *sptr;
cl *= fade;
cl >>= 6;
cl += gadd;
if (cl > 63) cl = 63;
if (cl < 0) cl = 0;
gfx_sdlpalette[c].g = (cl << 2) | (cl & 3);
gfx_sdlpalette[c].g = *sptr;
sptr++;

cl = *sptr;
cl *= fade;
cl >>= 6;
cl += badd;
if (cl > 63) cl = 63;
if (cl < 0) cl = 0;
gfx_sdlpalette[c].b = (cl << 2) | (cl & 3);
gfx_sdlpalette[c].b = *sptr;
sptr++;

gfx_sdlpalette[c].a = 255;
Expand All @@ -239,8 +219,9 @@ void gfx_setpalette()
{
if (!gfx_initted) return;

gfx_calcpalette();
SDL_Palette *palette = SDL_CreateSurfacePalette(gfx_screen);
SDL_SetPaletteColors(palette, &gfx_sdlpalette[0], 0, gfx_maxcolors);
SDL_SetPaletteColors(palette, &gfx_sdlpalette[0], 0, MAX_COLORS);
}

void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom)
Expand Down
6 changes: 3 additions & 3 deletions src/bme/bme_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

#include <SDL3/SDL.h>

#define MAX_COLORS 16 // 8bit oldskool mode

bool gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags);
int gfx_reinit();
void gfx_uninit();
bool gfx_lock();
void gfx_unlock();
void gfx_flip();

bool gfx_loadpalette(const char *name);
void gfx_calcpalette(int fade, int radd, int gadd, int badd);
void gfx_setpalette();

bool gfx_loadcursor( const char *name);
Expand All @@ -26,7 +26,7 @@ extern unsigned gfx_windowxsize;
extern unsigned gfx_windowysize;
extern unsigned gfx_virtualxsize;
extern unsigned gfx_virtualysize;
extern Uint8 gfx_palette[];
extern unsigned char gfx_palette[];
extern SDL_Surface *gfx_screen;

#endif
16 changes: 6 additions & 10 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ bool initscreen()
io_read(handle, &chardata[0], 4096);
io_close(handle);

if (!gfx_loadpalette("palette.bin"))
return false;
loadexternalpalette();
gfx_setpalette();

Expand Down Expand Up @@ -157,21 +155,19 @@ void loadexternalpalette()
if (std::sscanf(ln, "%d", &colors) == 1 && colors == 256)
{
int p = 0;
while (!feof(ext_f))
while (!std::feof(ext_f))
{
int r, g, b;
if (!std::fgets(ln, sizeof(ln), ext_f)) break;
int r, g, b;
if (std::sscanf(ln, "%d %d %d", &r, &g, &b) == 3)
{
// JASC palette is 8-bit and goat palette is 6-bit
gfx_palette[p++] = r / 4;
gfx_palette[p++] = g / 4;
gfx_palette[p++] = b / 4;
gfx_palette[p++] = r;
gfx_palette[p++] = g;
gfx_palette[p++] = b;
}

if (p >= 768) break;
if (p >= MAX_COLORS*3) break;
}
gfx_calcpalette(64, 0, 0, 0);
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@
#include <cstring>

#define CBLACK 0x0
#define CDBLUE 0x1
#define CDGREEN 0x2
#define CDGREY 0x3
#define CDRED 0x4
#define CDBROWN 0x5
#define CLBROWN 0x6
#define CLGREY 0x7
#define CGREY 0x8
#define CLBLUE 0x9
#define CLGREEN 0xA
#define CCYAN 0xB
#define CLRED 0xC
#define CPURPLE 0xD
#define CYELLOW 0xE
#define CWHITE 0xF
#define CWHITE 0x1
#define CLRED 0x2
#define CCYAN 0x3
#define CPURPLE 0x4
#define CDGREEN 0x5
#define CDBLUE 0x6
#define CYELLOW 0x7
#define CLBROWN 0x8
#define CDBROWN 0x9
#define CDRED 0xA
#define CDGREY 0xB
#define CGREY 0xC
#define CLGREEN 0xD
#define CLBLUE 0xE
#define CLGREY 0xF

const char *notename[] =
{"C-0", "C#0", "D-0", "D#0", "E-0", "F-0", "F#0", "G-0", "G#0", "A-0", "A#0", "B-0",
Expand Down
1 change: 0 additions & 1 deletion src/loadtrk.seq
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ altplayer.s
player_s.s
altplayer_s.s
chargen.bin
palette.bin
cursor.png
loadtrk.bmp
Binary file removed src/palette.bin
Binary file not shown.
Binary file removed src/palette.lbm
Binary file not shown.
Loading