DJGPP and SDL2 backends working!

This commit is contained in:
Scott Duensing 2022-06-07 19:02:56 -05:00
parent 7d2908b365
commit 7d32a1df31
10 changed files with 149 additions and 505 deletions

View file

@ -4,8 +4,8 @@ CONFIG -= qt
CONFIG += console
CONFIG += c99
CONFIG += BACKEND_SDL2
#CONFIG += BACKEND_DJGPP
#CONFIG += BACKEND_SDL2
CONFIG += BACKEND_DJGPP
SHARED = $$PWD/../shared
@ -30,9 +30,7 @@ HEADERS += \
src/gui/surface.h \
src/gui/wmwindow.h \
src/os.h \
src/platform/djgpp.h \
src/platform/platform.h \
src/platform/sdl2.h \
src/thirdparty/stb_image.h
SOURCES += \

View file

@ -57,6 +57,9 @@ void guiRegister(WidgetRegisterT widgetRegister) {
void guiShutdown(void) {
free(__guiBaseColors);
while (hmlen(_widgetCatalog) > 0) {
if (_widgetCatalog[0].value->unregister) _widgetCatalog[0].value->unregister(NULL);
hmdel(_widgetCatalog, _widgetCatalog[0].key);
@ -75,9 +78,33 @@ void guiShutdown(void) {
uint8_t guiStartup(int16_t width, int16_t height, int16_t depth) {
uint8_t i;
uint8_t EGA[16][3] = {
{ 0, 0, 0 }, /* black */
{ 0, 0, 170 }, /* blue */
{ 0, 170, 0 }, /* green */
{ 0, 170, 170 }, /* cyan */
{ 170, 0, 0 }, /* red */
{ 170, 0, 170 }, /* magenta */
{ 170, 85, 0 }, /* brown */
{ 170, 170, 170 }, /* light gray */
{ 85, 85, 85 }, /* dark gray */
{ 85, 85, 255 }, /* light blue */
{ 85, 255, 85 }, /* light green */
{ 85, 255, 255 }, /* light cyan */
{ 255, 85, 85 }, /* light red */
{ 255, 85, 255 }, /* light magenta */
{ 255, 255, 85 }, /* yellow */
{ 255, 255, 255 } /* white */
};
if (platformStartup(width, height, depth) == FAIL) return FAIL;
__guiBaseColors = (ColorT *)malloc(sizeof(ColorT) * 16);
for (i=0; i<16; i++) {
__guiBaseColors[i] = surfaceColorMake(EGA[i][0], EGA[i][1], EGA[i][2]);
}
__guiBackBuffer = surfaceCreate(videoDisplayWidthGet(), videoDisplayHeightGet());
surfaceSet(__guiBackBuffer);

View file

@ -7,6 +7,19 @@ uint8_t __surfaceBytesPerPixel = 0;
SurfaceFormatT __surfaceFormat = { 0 };
ColorT (*surfacePixelGet)(SurfaceT *surface, int16_t x, int16_t y);
void (*surfacePixelSet)(uint16_t x, uint16_t y, ColorT color);
static ColorT surfacePixelGet8(SurfaceT *surface, int16_t x, int16_t y);
static ColorT surfacePixelGet16(SurfaceT *surface, int16_t x, int16_t y);
static ColorT surfacePixelGet32(SurfaceT *surface, int16_t x, int16_t y);
static void surfacePixelSet8(uint16_t x, uint16_t y, ColorT color);
static void surfacePixelSet16(uint16_t x, uint16_t y, ColorT color);
static void surfacePixelSet32(uint16_t x, uint16_t y, ColorT color);
void surfaceBlit(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source) {
uint16_t y1;
size_t offsetTarget;
@ -195,35 +208,33 @@ void surfaceLineV(int16_t x, int16_t y1, int16_t y2, ColorT c) {
}
ColorT surfacePixelGet(SurfaceT *surface, int16_t x, int16_t y) {
switch (__surfaceBitsPerPixel) {
case 8:
static ColorT surfacePixelGet8(SurfaceT *surface, int16_t x, int16_t y) {
return surface->buffer.bits8[y * surface->width + x];
}
case 16:
static ColorT surfacePixelGet16(SurfaceT *surface, int16_t x, int16_t y) {
return surface->buffer.bits16[y * surface->width + x];
}
default:
static ColorT surfacePixelGet32(SurfaceT *surface, int16_t x, int16_t y) {
return surface->buffer.bits32[y * surface->width + x];
}
static void surfacePixelSet8(uint16_t x, uint16_t y, ColorT color) {
__surfaceActive->buffer.bits8[y * __surfaceActive->width + x] = (uint8_t)color;
}
void surfacePixelSet(int16_t x, int16_t y, ColorT c) {
switch (__surfaceBitsPerPixel) {
case 8:
__surfaceActive->buffer.bits8[y * __surfaceActive->width + x] = (uint8_t)c;
break;
case 16:
__surfaceActive->buffer.bits16[y * __surfaceActive->width + x] = (uint8_t)c;
break;
default:
__surfaceActive->buffer.bits32[y * __surfaceActive->width + x] = (uint8_t)c;
break;
static void surfacePixelSet16(uint16_t x, uint16_t y, ColorT color) {
__surfaceActive->buffer.bits16[y * __surfaceActive->width + x] = (uint16_t)color;
}
static void surfacePixelSet32(uint16_t x, uint16_t y, ColorT color) {
__surfaceActive->buffer.bits32[y * __surfaceActive->width + x] = color;
}
@ -253,6 +264,8 @@ void surfaceStartup(uint8_t bits) {
redMaskSize = 3;
greenMaskSize = 3;
blueMaskSize = 2;
surfacePixelSet = surfacePixelSet8;
surfacePixelGet = surfacePixelGet8;
break;
case 16:
@ -261,6 +274,8 @@ void surfaceStartup(uint8_t bits) {
redMaskSize = 5;
greenMaskSize = 6;
blueMaskSize = 5;
surfacePixelSet = surfacePixelSet16;
surfacePixelGet = surfacePixelGet16;
break;
default:
@ -269,6 +284,8 @@ void surfaceStartup(uint8_t bits) {
redMaskSize = 8;
greenMaskSize = 8;
blueMaskSize = 8;
surfacePixelSet = surfacePixelSet32;
surfacePixelGet = surfacePixelGet32;
break;
}
@ -287,10 +304,12 @@ void surfaceStartup(uint8_t bits) {
__surfaceFormat.bLoss = 8 - blueMaskSize;
__surfaceFormat.aLoss = 8 - alphaMaskSize;
printf("Red Mask %u Shift %u Loss %u\n", __surfaceFormat.rMask, __surfaceFormat.rShift, __surfaceFormat.rLoss);
printf("Green Mask %u Shift %u Loss %u\n", __surfaceFormat.gMask, __surfaceFormat.gShift, __surfaceFormat.gLoss);
printf("Blue Mask %u Shift %u Loss %u\n", __surfaceFormat.bMask, __surfaceFormat.bShift, __surfaceFormat.bLoss);
printf("Alpha Mask %u Shift %u Loss %u\n\n", __surfaceFormat.aMask, __surfaceFormat.aShift, __surfaceFormat.aLoss);
/*
logWrite("Surface Red Mask %u Shift %u Loss %u\n", __surfaceFormat.rMask, __surfaceFormat.rShift, __surfaceFormat.rLoss);
logWrite("Surface Green Mask %u Shift %u Loss %u\n", __surfaceFormat.gMask, __surfaceFormat.gShift, __surfaceFormat.gLoss);
logWrite("Surface Blue Mask %u Shift %u Loss %u\n", __surfaceFormat.bMask, __surfaceFormat.bShift, __surfaceFormat.bLoss);
logWrite("Surface Alpha Mask %u Shift %u Loss %u\n\n", __surfaceFormat.aMask, __surfaceFormat.aShift, __surfaceFormat.aLoss);
*/
}

View file

@ -41,6 +41,10 @@ extern uint8_t __surfaceBytesPerPixel;
extern SurfaceFormatT __surfaceFormat;
extern ColorT (*surfacePixelGet)(SurfaceT *surface, int16_t x, int16_t y);
extern void (*surfacePixelSet)(uint16_t x, uint16_t y, ColorT color);
void surfaceBlit(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source);
void surfaceBlitWithTransparency(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source, ColorT transparent);
void surfaceClear(ColorT color);
@ -53,8 +57,6 @@ SurfaceT *surfaceGet(void);
int16_t surfaceHeightGet(SurfaceT *surface);
void surfaceLineH(int16_t x1, int16_t x2, int16_t y, ColorT c);
void surfaceLineV(int16_t x, int16_t y1, int16_t y2, ColorT c);
ColorT surfacePixelGet(SurfaceT *surface, int16_t x, int16_t y);
void surfacePixelSet(int16_t x, int16_t y, ColorT c);
void surfaceSet(SurfaceT *surface);
void surfaceShutdown(void);
void surfaceStartup(uint8_t bits);

View file

@ -11,7 +11,7 @@ int main(int argc, char *argv[]) {
memoryStartup(argv[0]);
logOpenByHandle(memoryLogHandleGet());
if (guiStartup(800, 600, 16) == SUCCESS) {
if (guiStartup(800, 600, 32) == SUCCESS) {
for (i=1; i<4; i++) {
sprintf(title, "Testing %d", i);
windowCreate(i * 50, i * 50, 300, 200, title, WIN_CLOSE | WIN_MAXIMIZE | WIN_MINIMIZE | WIN_RESIZE);

View file

@ -11,7 +11,7 @@
#include <sys/farptr.h>
#include <sys/nearptr.h>
#include "djgpp.h"
#include "platform.h"
// These are all we support
@ -156,15 +156,11 @@ typedef struct VBESurfaceS {
} VBESurfaceT;
extern ColorT *__guiBaseColors;
static VBESurfaceT _vbeSurface;
static VBEInfoT _vbeInfo;
static VBEModeInfoT _vbeModeInfo;
static PModeInterfaceT *_pmodeInterfacePtr;
static uint32_t *_yTable;
/* static */ SurfaceT *_activeSurface = NULL;
static void vbeCreatePalette(void);
@ -176,23 +172,9 @@ static uint16_t vbeSelectModeNumber(uint16_t xRes, uint16_t yRes, uint8_t b
static VBESurfaceT *vbeSetMode(uint16_t vbeModeNumber);
static uint16_t vbeSetScanlineLength(uint16_t pixelLength);
/*
static ColorT videoSurfacePixelGet8(SurfaceT *surface, int16_t x, int16_t y);
static ColorT videoSurfacePixelGet16(SurfaceT *surface, int16_t x, int16_t y);
static ColorT videoSurfacePixelGet32(SurfaceT *surface, int16_t x, int16_t y);
static void videoSurfacePixelSet8(uint16_t x, uint16_t y, ColorT color);
static void videoSurfacePixelSet16(uint16_t x, uint16_t y, ColorT color);
static void videoSurfacePixelSet32(uint16_t x, uint16_t y, ColorT color);
*/
static void (*pmVBESetDisplayStart)(void);
/*
ColorT (*videoSurfacePixelGet)(SurfaceT *surface, int16_t x, int16_t y);
void (*videoSurfacePixelSet)(uint16_t x, uint16_t y, ColorT color);
*/
void platformEventGet(EventT *event) {
int32_t x;
@ -294,7 +276,7 @@ void platformShutdown(void) {
__dpmi_regs r;
__dpmi_meminfo m;
free(__guiBaseColors);
surfaceShutdown();
if (_vbeSurface.vbeInitBoolean == 0) {
r.x.ax = 0x03; // make sure we're in 3h
@ -334,25 +316,6 @@ void platformShutdown(void) {
uint8_t platformStartup(int16_t width, int16_t height, int16_t depth) {
uint16_t vbeModeNumber;
uint8_t i;
uint8_t EGA[16][3] = {
{ 0, 0, 0 }, /* black */
{ 0, 0, 170 }, /* blue */
{ 0, 170, 0 }, /* green */
{ 0, 170, 170 }, /* cyan */
{ 170, 0, 0 }, /* red */
{ 170, 0, 170 }, /* magenta */
{ 170, 85, 0 }, /* brown */
{ 170, 170, 170 }, /* light gray */
{ 85, 85, 85 }, /* dark gray */
{ 85, 85, 255 }, /* light blue */
{ 85, 255, 85 }, /* light green */
{ 85, 255, 255 }, /* light cyan */
{ 255, 85, 85 }, /* light red */
{ 255, 85, 255 }, /* light magenta */
{ 255, 255, 85 }, /* yellow */
{ 255, 255, 255 } /* white */
};
if (vbeGetInfo() == NULL) {
logWrite("No VESA BIOS Extensions found.\n");
@ -379,17 +342,7 @@ uint8_t platformStartup(int16_t width, int16_t height, int16_t depth) {
return FAIL;
}
/*
if (_vbeSurface.bitsPerPixel == 8) { videoSurfacePixelSet = videoSurfacePixelSet8; videoSurfacePixelGet = videoSurfacePixelGet8; }
if (_vbeSurface.bitsPerPixel == 16) { videoSurfacePixelSet = videoSurfacePixelSet16; videoSurfacePixelGet = videoSurfacePixelGet16; }
if (_vbeSurface.bitsPerPixel == 15) { videoSurfacePixelSet = videoSurfacePixelSet16; videoSurfacePixelGet = videoSurfacePixelGet16; }
if (_vbeSurface.bitsPerPixel == 32) { videoSurfacePixelSet = videoSurfacePixelSet32; videoSurfacePixelGet = videoSurfacePixelGet32; }
*/
__guiBaseColors = (ColorT *)malloc(sizeof(ColorT) * 16);
for (i=0; i<16; i++) {
__guiBaseColors[i] = videoColorMake(EGA[i][0], EGA[i][1], EGA[i][2]);
}
surfaceStartup(_vbeSurface.bitsPerPixel);
return SUCCESS;
}
@ -582,7 +535,7 @@ static uint8_t vbeIsDesiredMode(void) {
// Packed or Direct Color mode.
if (_vbeModeInfo.memoryModel == VBE_MM_PACKED || _vbeModeInfo.memoryModel == VBE_MM_DCOLOR) {
// We only handle these bit depths.
if ((_vbeModeInfo.bitsPerPixel == 8) || (_vbeModeInfo.bitsPerPixel == 15) || (_vbeModeInfo.bitsPerPixel == 16) || (_vbeModeInfo.bitsPerPixel == 32)) {
if ((_vbeModeInfo.bitsPerPixel == 8) || (_vbeModeInfo.bitsPerPixel == 16) || (_vbeModeInfo.bitsPerPixel == 32)) {
// Resolution minimum of 640x480.
if (_vbeModeInfo.xResolution >= 640 && _vbeModeInfo.yResolution >= 480) {
// Multiple of 8
@ -674,7 +627,7 @@ static VBESurfaceT *vbeSetMode(uint16_t vbeModeNumber) {
_vbeModeInfo.redFieldPosition = 5;
_vbeModeInfo.greenFieldPosition = 2;
_vbeModeInfo.blueFieldPosition = 0;
_vbeModeInfo.rsvdFieldPosition = 7;
_vbeModeInfo.rsvdFieldPosition = 8;
_vbeModeInfo.redMaskSize = 3;
_vbeModeInfo.greenMaskSize = 3;
@ -697,6 +650,13 @@ static VBESurfaceT *vbeSetMode(uint16_t vbeModeNumber) {
_vbeSurface.bPos = _vbeModeInfo.blueFieldPosition;
_vbeSurface.aPos = _vbeModeInfo.rsvdFieldPosition;
/*
logWrite("VESA Red Mask %u Shift %u Loss %u\n", _vbeSurface.rMask, _vbeSurface.rPos, _vbeSurface.rShift);
logWrite("VESA Green Mask %u Shift %u Loss %u\n", _vbeSurface.gMask, _vbeSurface.gPos, _vbeSurface.gShift);
logWrite("VESA Blue Mask %u Shift %u Loss %u\n", _vbeSurface.bMask, _vbeSurface.bPos, _vbeSurface.bShift);
logWrite("VESA Alpha Mask %u Shift %u Loss %u\n\n", _vbeSurface.aMask, _vbeSurface.aPos, _vbeSurface.aShift);
*/
return(&_vbeSurface);
}
@ -719,11 +679,13 @@ static uint16_t vbeSetScanlineLength(uint16_t pixelLength) {
}
ColorT videoColorMake(uint8_t red, uint8_t green, uint8_t blue) {
return
(((red >> _vbeSurface.rShift) << _vbeSurface.rPos) & _vbeSurface.rMask) |
(((green >> _vbeSurface.gShift) << _vbeSurface.gPos) & _vbeSurface.gMask) |
(((blue >> _vbeSurface.bShift) << _vbeSurface.bPos) & _vbeSurface.bMask);
void videoBlit(int16_t targetX, int16_t targetY, SurfaceT *source) {
//***TODO*** Does not handle partial blits at this time.
(void)targetX;
(void)targetY;
_movedatal(_my_ds(), (int32_t)source->buffer.bits32, _vbeSurface.lfbSelector, 0x0, _vbeSurface.screenDWords);
}
@ -796,236 +758,4 @@ void videoModesShow(void) {
}
void videoSurfaceBlit(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source) {
uint16_t y1;
size_t offsetTarget;
size_t offsetSource;
// HACK! Are we copying to the screen? This assumes a full screen update.
if (!target) {
_movedatal(_my_ds(), (int32_t)source->buffer.bits32, _vbeSurface.lfbSelector, 0x0, _vbeSurface.screenDWords);
return;
}
if (targetX == 0 && targetY == 0 && target->width == source->width && target->height == source->height) {
// Direct blit of entire surface.
memcpy(target->buffer.bits8, source->buffer.bits8, source->bytes);
} else {
// Blit into larger surface.
offsetTarget = targetY * _activeSurface->scanline + targetX * _vbeSurface.bytesPerPixel;
offsetSource = 0;
for (y1=targetY; y1<targetY+source->height; y1++) {
memcpy(&target->buffer.bits8[offsetTarget], &source->buffer.bits8[offsetSource], source->scanline);
offsetTarget += target->scanline;
offsetSource += source->scanline;
}
}
}
void videoSurfaceBlitWithTransparency(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source, ColorT transparent) {
uint16_t x1;
uint16_t y1;
uint16_t x2 = source->width;
uint16_t y2 = source->height;
ColorT pixel;
SurfaceT *t = videoSurfaceGet();
videoSurfaceSet(target);
// Clip on right and bottom
if (targetX + x2 > target->width) x2 -= targetX + x2 - target->width;
if (targetY + y2 > target->height) y2 -= targetY + y2 - target->height;
for (y1=0; y1<y2; y1++) {
for (x1=0; x1<x2; x1++) {
pixel = videoSurfacePixelGet(source, x1, y1);
if (transparent != pixel) {
videoSurfacePixelSet(targetX + x1, targetY + y1, pixel);
}
}
}
videoSurfaceSet(t);
}
void videoSurfaceClear(ColorT color) {
uint16_t x;
size_t offsetTarget;
// Draw the top line.
for (x=0; x<_activeSurface->width; x++) {
videoSurfacePixelSet(x, 0, color);
}
// Copy it to the other lines.
offsetTarget = _activeSurface->scanline;
for (x=1; x<_activeSurface->height; x++) {
memcpy(&_activeSurface->buffer.bits8[offsetTarget], &_activeSurface->buffer.bits8[0], _activeSurface->scanline);
offsetTarget += _activeSurface->scanline;
}
}
SurfaceT *videoSurfaceCreate(int16_t width, int16_t height) {
SurfaceT *surface = (SurfaceT *)malloc(sizeof(SurfaceT));
if (!surface) return NULL;
surface->width = width;
surface->height = height;
surface->scanline = width * _vbeSurface.bytesPerPixel;
surface->bytes = surface->scanline * height;
surface->buffer.bits8 = malloc(surface->bytes);
if (!surface->buffer.bits8) {
free(surface);
return NULL;
}
memset(surface->buffer.bits8, 0, surface->bytes);
return surface;
}
void videoSurfaceBox(int16_t x1, int16_t y1, int16_t x2, int16_t y2, ColorT c) {
videoSurfaceLineH(x1, x2, y1, c);
videoSurfaceLineH(x1, x2, y2, c);
videoSurfaceLineV(x1, y1, y2, c);
videoSurfaceLineV(x2, y1, y2, c);
}
void videoSurfaceBoxFilled(int16_t x1, int16_t y1, int16_t x2, int16_t y2, ColorT c) {
int16_t i;
size_t offsetTarget;
size_t offsetSource;
uint16_t width;
if (x1 > x2) {
i = x1;
x1 = x2;
x2 = i;
}
if (y1 > y2) {
i = y1;
y1 = y2;
y2 = i;
}
width = (x2 - x1 + 1) * _vbeSurface.bytesPerPixel;
// Draw the top line.
for (i=x1; i<=x2; i++) {
videoSurfacePixelSet(i, y1, c);
}
// Copy it to the other lines.
offsetTarget = _activeSurface->scanline * (y1 + 1) + (x1 * _vbeSurface.bytesPerPixel);
offsetSource = _activeSurface->scanline * y1 + (x1 * _vbeSurface.bytesPerPixel);
for (i=y1 + 1; i<=y2; i++) {
memcpy(&_activeSurface->buffer.bits8[offsetTarget], &_activeSurface->buffer.bits8[offsetSource], width);
offsetTarget += _activeSurface->scanline;
}
}
void videoSurfaceDestroy(SurfaceT *surface) {
free(surface->buffer.bits8);
free(surface);
}
SurfaceT *videoSurfaceGet(void) {
return _activeSurface;
}
int16_t videoSurfaceHeightGet(SurfaceT *surface) {
return surface->height;
}
void videoSurfaceLineH(int16_t x1, int16_t x2, int16_t y, ColorT c) {
int16_t i;
int16_t t;
if (x1 > x2) {
t = x2;
x2 = x1;
x1 = t;
}
for (i=x1; i<=x2; i++) {
videoSurfacePixelSet(i, y, c);
}
}
void videoSurfaceLineV(int16_t x, int16_t y1, int16_t y2, ColorT c) {
int16_t i;
int16_t t;
if (y1 > y2) {
t = y2;
y2 = y1;
y1 = t;
}
for (i=y1; i<=y2; i++) {
videoSurfacePixelSet(x, i, c);
}
}
/*
static ColorT videoSurfacePixelGet8(SurfaceT *surface, int16_t x, int16_t y) {
return surface->buffer.bits8[y * surface->width + x];
}
static ColorT videoSurfacePixelGet16(SurfaceT *surface, int16_t x, int16_t y) {
return surface->buffer.bits16[y * surface->width + x];
}
static ColorT videoSurfacePixelGet32(SurfaceT *surface, int16_t x, int16_t y) {
return surface->buffer.bits32[y * surface->width + x];
}
static void videoSurfacePixelSet8(uint16_t x, uint16_t y, ColorT color) {
_activeSurface->buffer.bits8[y * _activeSurface->width + x] = (uint8_t)color;
}
static void videoSurfacePixelSet16(uint16_t x, uint16_t y, ColorT color) {
_activeSurface->buffer.bits16[y * _activeSurface->width + x] = (uint16_t)color;
}
static void videoSurfacePixelSet32(uint16_t x, uint16_t y, ColorT color) {
_activeSurface->buffer.bits32[y * _activeSurface->width + x] = color;
}
*/
void videoSurfaceSet(SurfaceT *surface) {
_activeSurface = surface;
}
SurfaceT *videoSurfaceScreenGet(void) {
return NULL;
}
int16_t videoSurfaceWidthGet(SurfaceT *surface) {
return surface->width;
}
#endif // BACKEND_DJGPP

View file

@ -1,83 +0,0 @@
#ifndef DJGPP_H
#define DJGPP_H
#include <stdint.h>
#include <stdlib.h>
typedef uint32_t ColorT;
typedef struct SurfaceS {
uint16_t width;
uint16_t height;
size_t scanline;
size_t bytes;
union {
uint8_t *bits8;
uint16_t *bits16;
uint32_t *bits32;
} buffer;
} SurfaceT;
typedef struct EventS {
int32_t flags;
int32_t x;
int32_t y;
int32_t buttons;
int32_t key;
int32_t kbstat;
int32_t dtime;
} EventT;
#define EVENT_FLAG_KEYPRESS 1
#define EVENT_FLAG_LEFT_DOWN 2
#define EVENT_FLAG_LEFT_UP 4
#define EVENT_FLAG_RIGHT_DOWN 8
#define EVENT_FLAG_RIGHT_UP 16
#define BUTTON_LEFT 1
#define BUTTON_RIGHT 2
#define META_ALT 1
#define META_CTRL 2
#define META_SHIFT 4
#define KEY_ESC 27
extern SurfaceT *_activeSurface;
#define videoSurfacePixelGet(s,x,y) ((s)->buffer.bits16[(y) * (s)->width + (x)])
#define videoSurfacePixelSet(x,y,c) _activeSurface->buffer.bits16[(y) * _activeSurface->width + (x)] = (uint16_t)(c)
/*
extern ColorT (*videoSurfacePixelGet)(SurfaceT *surface, int16_t x, int16_t y);
extern void (*videoSurfacePixelSet)(uint16_t x, uint16_t y, ColorT color);
*/
void platformEventGet(EventT *event);
ColorT videoColorMake(uint8_t red, uint8_t green, uint8_t blue);
uint16_t videoDisplayHeightGet(void);
uint16_t videoDisplayWidthGet(void);
void surfaceBlit(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source);
void surfaceBlitWithTransparency(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source, ColorT transparent);
void surfaceClear(ColorT color);
SurfaceT *surfaceCreate(int16_t width, int16_t height);
void surfaceBox(int16_t x1, int16_t y1, int16_t x2, int16_t y2, ColorT c);
void surfaceBoxFilled(int16_t x1, int16_t y1, int16_t x2, int16_t y2, ColorT c);
void surfaceDestroy(SurfaceT *surface);
SurfaceT *surfaceGet(void);
int16_t surfaceHeightGet(SurfaceT *surface);
void surfaceLineH(int16_t x1, int16_t y1, int16_t x, ColorT c);
void surfaceLineV(int16_t x, int16_t x2, int16_t y2, ColorT c);
void surfaceSet(SurfaceT *surface);
SurfaceT *videoDisplayGet(void);
int16_t surfaceWidthGet(SurfaceT *surface);
#endif // DJGPP_H

View file

@ -2,21 +2,46 @@
#define PLATFORM_H
#include "stdint.h"
#include <stdint.h>
#include <stdlib.h>
#include "../gui/surface.h"
#ifdef BACKEND_SDL2
#include "sdl2.h"
#endif
#define EVENT_FLAG_KEYPRESS 1
#define EVENT_FLAG_LEFT_DOWN 2
#define EVENT_FLAG_LEFT_UP 4
#define EVENT_FLAG_RIGHT_DOWN 8
#define EVENT_FLAG_RIGHT_UP 16
#ifdef BACKEND_DJGPP
#include "djgpp.h"
#endif
#define BUTTON_LEFT 1
#define BUTTON_RIGHT 2
#define META_ALT 1
#define META_CTRL 2
#define META_SHIFT 4
#define KEY_ESC 27
typedef struct EventS {
int32_t flags;
int32_t x;
int32_t y;
int32_t buttons;
int32_t key;
int32_t kbstat;
int32_t dtime;
} EventT;
void platformEventGet(EventT *event);
void platformShutdown(void);
uint8_t platformStartup(int16_t width, int16_t height, int16_t depth);
void videoBlit(int16_t targetX, int16_t targetY, SurfaceT *source);
uint16_t videoDisplayHeightGet(void);
uint16_t videoDisplayWidthGet(void);
void videoModesShow(void);

View file

@ -2,7 +2,7 @@
#include "sdl2.h"
#include "../gui/surface.h"
#include "platform.h"
static SDL_Window *_window = NULL;
@ -13,9 +13,6 @@ static uint16_t _height = 0;
static uint8_t _windowScale = 1;
extern ColorT *__guiBaseColors;
void platformEventGet(EventT *event) {
SDL_Event e;
static uint8_t ASCII = 0;
@ -88,8 +85,6 @@ void platformShutdown(void) {
surfaceShutdown();
free(__guiBaseColors);
if (_texture) {
SDL_DestroyTexture(_texture);
_texture = NULL;
@ -110,49 +105,30 @@ void platformShutdown(void) {
void platformStartup(int16_t width, int16_t height, int16_t depth) {
uint8_t i;
uint8_t EGA[16][3] = {
{ 0, 0, 0 }, /* black */
{ 0, 0, 170 }, /* blue */
{ 0, 170, 0 }, /* green */
{ 0, 170, 170 }, /* cyan */
{ 170, 0, 0 }, /* red */
{ 170, 0, 170 }, /* magenta */
{ 170, 85, 0 }, /* brown */
{ 170, 170, 170 }, /* light gray */
{ 85, 85, 85 }, /* dark gray */
{ 85, 85, 255 }, /* light blue */
{ 85, 255, 85 }, /* light green */
{ 85, 255, 255 }, /* light cyan */
{ 255, 85, 85 }, /* light red */
{ 255, 85, 255 }, /* light magenta */
{ 255, 255, 85 }, /* yellow */
{ 255, 255, 255 } /* white */
};
SDL_PixelFormatEnum pixelFormat;
(void)depth;
/*
SDL_Surface *bits8 = SDL_CreateRGBSurfaceWithFormat(0, 320, 200, 8, SDL_PIXELFORMAT_RGB332);
SDL_Surface *bits16 = SDL_CreateRGBSurfaceWithFormat(0, 320, 200, 8, SDL_PIXELFORMAT_RGB565);
SDL_Surface *bits32 = SDL_CreateRGBSurfaceWithFormat(0, 320, 200, 8, SDL_PIXELFORMAT_ARGB8888);
printf("8 Red Mask %u Shift %u Loss %u\n", bits8->format->Rmask, bits8->format->Rshift, bits8->format->Rloss);
printf("8 Green Mask %u Shift %u Loss %u\n", bits8->format->Gmask, bits8->format->Gshift, bits8->format->Gloss);
printf("8 Blue Mask %u Shift %u Loss %u\n", bits8->format->Bmask, bits8->format->Bshift, bits8->format->Bloss);
printf("8 Alpha Mask %u Shift %u Loss %u\n\n", bits8->format->Amask, bits8->format->Ashift, bits8->format->Aloss);
logWrite("8 Red Mask %u Shift %u Loss %u\n", bits8->format->Rmask, bits8->format->Rshift, bits8->format->Rloss);
logWrite("8 Green Mask %u Shift %u Loss %u\n", bits8->format->Gmask, bits8->format->Gshift, bits8->format->Gloss);
logWrite("8 Blue Mask %u Shift %u Loss %u\n", bits8->format->Bmask, bits8->format->Bshift, bits8->format->Bloss);
logWrite("8 Alpha Mask %u Shift %u Loss %u\n\n", bits8->format->Amask, bits8->format->Ashift, bits8->format->Aloss);
printf("16 Red Mask %u Shift %u Loss %u\n", bits16->format->Rmask, bits16->format->Rshift, bits16->format->Rloss);
printf("16 Green Mask %u Shift %u Loss %u\n", bits16->format->Gmask, bits16->format->Gshift, bits16->format->Gloss);
printf("16 Blue Mask %u Shift %u Loss %u\n", bits16->format->Bmask, bits16->format->Bshift, bits16->format->Bloss);
printf("16 Alpha Mask %u Shift %u Loss %u\n\n", bits16->format->Amask, bits16->format->Ashift, bits16->format->Aloss);
logWrite("16 Red Mask %u Shift %u Loss %u\n", bits16->format->Rmask, bits16->format->Rshift, bits16->format->Rloss);
logWrite("16 Green Mask %u Shift %u Loss %u\n", bits16->format->Gmask, bits16->format->Gshift, bits16->format->Gloss);
logWrite("16 Blue Mask %u Shift %u Loss %u\n", bits16->format->Bmask, bits16->format->Bshift, bits16->format->Bloss);
logWrite("16 Alpha Mask %u Shift %u Loss %u\n\n", bits16->format->Amask, bits16->format->Ashift, bits16->format->Aloss);
printf("32 Red Mask %u Shift %u Loss %u\n", bits32->format->Rmask, bits32->format->Rshift, bits32->format->Rloss);
printf("32 Green Mask %u Shift %u Loss %u\n", bits32->format->Gmask, bits32->format->Gshift, bits32->format->Gloss);
printf("32 Blue Mask %u Shift %u Loss %u\n", bits32->format->Bmask, bits32->format->Bshift, bits32->format->Bloss);
printf("32 Alpha Mask %u Shift %u Loss %u\n\n", bits32->format->Amask, bits32->format->Ashift, bits32->format->Aloss);
logWrite("32 Red Mask %u Shift %u Loss %u\n", bits32->format->Rmask, bits32->format->Rshift, bits32->format->Rloss);
logWrite("32 Green Mask %u Shift %u Loss %u\n", bits32->format->Gmask, bits32->format->Gshift, bits32->format->Gloss);
logWrite("32 Blue Mask %u Shift %u Loss %u\n", bits32->format->Bmask, bits32->format->Bshift, bits32->format->Bloss);
logWrite("32 Alpha Mask %u Shift %u Loss %u\n\n", bits32->format->Amask, bits32->format->Ashift, bits32->format->Aloss);
*/
switch (depth) {
case 8:
@ -183,12 +159,6 @@ void platformStartup(int16_t width, int16_t height, int16_t depth) {
_height = height;
surfaceStartup(depth);
// ***TODO*** This needs to be in GUI.
__guiBaseColors = (ColorT *)malloc(sizeof(ColorT) * 16);
for (i=0; i<16; i++) {
__guiBaseColors[i] = surfaceColorMake(EGA[i][0], EGA[i][1], EGA[i][2]);
}
}

View file

@ -1,44 +0,0 @@
#ifndef SDL2_H
#define SDL2_H
#include <stdint.h>
#include <SDL2/SDL.h>
#include "../gui/surface.h"
typedef struct EventS {
int32_t flags;
int32_t x;
int32_t y;
int32_t buttons;
int32_t key;
int32_t kbstat;
int32_t dtime;
} EventT;
#define EVENT_FLAG_KEYPRESS 1
#define EVENT_FLAG_LEFT_DOWN 2
#define EVENT_FLAG_LEFT_UP 4
#define EVENT_FLAG_RIGHT_DOWN 8
#define EVENT_FLAG_RIGHT_UP 16
#define BUTTON_LEFT 1
#define BUTTON_RIGHT 2
#define META_ALT 1
#define META_CTRL 2
#define META_SHIFT 4
#define KEY_ESC 27
void platformEventGet(EventT *event);
void videoBlit(int16_t targetX, int16_t targetY, SurfaceT *source);
uint16_t videoDisplayHeightGet(void);
uint16_t videoDisplayWidthGet(void);
#endif // SDL2_H