2020-07-19 19:24:48 -04:00
|
|
|
#include "dgl.h"
|
2018-04-28 11:30:53 -04:00
|
|
|
#include "dglgfx.h"
|
|
|
|
#include "dglblit.h"
|
|
|
|
#include "dglutil.h"
|
2020-07-19 19:24:48 -04:00
|
|
|
#include <conio.h>
|
2018-04-28 11:30:53 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
extern void set_video_mode(int mode);
|
|
|
|
#pragma aux set_video_mode = \
|
|
|
|
"int 0x10" \
|
2018-04-28 11:30:53 -04:00
|
|
|
parm [eax];
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
static bool _initialized = false;
|
2018-04-28 11:30:53 -04:00
|
|
|
|
|
|
|
SURFACE *screen = NULL;
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
static SURFACE* surface_create_internal(int width, int height, uint8 *pixels) {
|
2018-04-28 11:30:53 -04:00
|
|
|
SURFACE *surface = (SURFACE*)malloc(sizeof(SURFACE));
|
|
|
|
|
|
|
|
surface->width = width;
|
|
|
|
surface->height = height;
|
|
|
|
surface->clip_region = rect(0, 0, width, height);
|
|
|
|
surface->flags = 0;
|
|
|
|
|
|
|
|
if (pixels != NULL) {
|
|
|
|
surface->flags |= SURFACE_FLAGS_ALIASED;
|
|
|
|
surface->pixels = pixels;
|
|
|
|
} else {
|
|
|
|
int size = width * height;
|
2020-07-19 19:24:48 -04:00
|
|
|
surface->pixels = (uint8*)malloc(size);
|
2018-04-28 11:30:53 -04:00
|
|
|
mem_fill(surface->pixels, 0, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
bool gfx_init(void) {
|
2018-04-28 11:30:53 -04:00
|
|
|
|
|
|
|
if (_initialized) {
|
|
|
|
dgl_set_error(DGL_VIDEO_ALREADY_INITIALIZED);
|
2020-07-19 19:24:48 -04:00
|
|
|
return false;
|
2018-04-28 11:30:53 -04:00
|
|
|
}
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
set_video_mode(0x13);
|
2018-04-28 11:30:53 -04:00
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
screen = surface_create_internal(320, 200, (uint8*)0xa0000);
|
2018-04-28 11:30:53 -04:00
|
|
|
surface_clear(screen, 0);
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
_initialized = true;
|
|
|
|
return true;
|
2018-04-28 11:30:53 -04:00
|
|
|
}
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
bool gfx_shutdown(void) {
|
2018-04-28 11:30:53 -04:00
|
|
|
if (!_initialized)
|
2020-07-19 19:24:48 -04:00
|
|
|
return true; // don't care
|
2018-04-28 11:30:53 -04:00
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
set_video_mode(0x03);
|
2018-04-28 11:30:53 -04:00
|
|
|
|
|
|
|
surface_free(screen);
|
|
|
|
screen = NULL;
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
_initialized = false;
|
|
|
|
return true;
|
2018-04-28 11:30:53 -04:00
|
|
|
}
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
bool gfx_is_initialized(void) {
|
2018-04-28 11:30:53 -04:00
|
|
|
return _initialized;
|
|
|
|
}
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
void wait_vsync(void) {
|
2018-04-28 11:30:53 -04:00
|
|
|
do {} while (inp(0x3da) & 0x8);
|
|
|
|
do {} while (!(inp(0x3da) & 0x8));
|
|
|
|
}
|
|
|
|
|
|
|
|
SURFACE* surface_create(int width, int height) {
|
|
|
|
return surface_create_internal(width, height, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void surface_free(SURFACE *surface) {
|
|
|
|
if (!surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!BIT_ISSET(SURFACE_FLAGS_ALIASED, surface->flags))
|
|
|
|
free(surface->pixels);
|
2020-07-19 19:24:48 -04:00
|
|
|
|
2018-04-28 11:30:53 -04:00
|
|
|
free(surface);
|
|
|
|
}
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
void surface_clear(SURFACE *surface, uint8 color) {
|
2018-04-28 11:30:53 -04:00
|
|
|
int length = surface->width * surface->height;
|
2020-07-19 19:24:48 -04:00
|
|
|
mem_fill(surface->pixels, color, length);
|
2018-04-28 11:30:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void surface_copy(const SURFACE *src, SURFACE *dest) {
|
|
|
|
if (src->width == dest->width && src->height == dest->height) {
|
|
|
|
int length = src->width * src->height;
|
|
|
|
mem_copy(dest->pixels, src->pixels, length);
|
|
|
|
} else {
|
2020-07-19 19:24:48 -04:00
|
|
|
blit(src, dest, 0, 0);
|
2018-04-28 11:30:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|