various updates i've left uncommitted for many months
- rename standard integer types to a more familiar (u)int(8/16/32) - many function/struct renames. i don't _really_ know if what i've done for this is better, but it "feels" better to me. many draw/blit function names are shorter which is nice, at least. kinda important to me because i develop this on a real DOS machine in 80x50 text mode. - add 'extern "C"' blocks to headers for C++ compiler usage - draw/pixel color value arguments for functions should all have been changed to be uint8 instead of a full 32-bit int. feels right, but maybe should've left alone... - small fix to keyboard handler. noticed a problem on one thinkpad laptop. was a result of what i think was a typo in a constant value used during the part of the interrupt handler that tells the keyboard controller the key event was processed - fix uncommon potential crash function return in draw_filled_rect - renamed low-level "direct" assembly functions to "lowlevel_xxx" to be a little bit more explicit about what they are - add some convenience event helper functions for determining event types - add fixed point atan2 - fixed some tabs/spaces inconsistences (should all be spaces now?) - maybe some other minor things i've forgotten
This commit is contained in:
parent
7816a7887b
commit
62af8575c6
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
14
DGL.C
Normal file → Executable file
14
DGL.C
Normal file → Executable file
|
@ -2,7 +2,7 @@
|
||||||
#include "dglkbrd.h"
|
#include "dglkbrd.h"
|
||||||
#include "dglmouse.h"
|
#include "dglmouse.h"
|
||||||
#include "dglgfx.h"
|
#include "dglgfx.h"
|
||||||
#include "dglutil.h"
|
#include "dglevent.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static DGL_ERROR _last_error = DGL_NONE;
|
static DGL_ERROR _last_error = DGL_NONE;
|
||||||
|
@ -60,14 +60,14 @@ void dgl_set_error(DGL_ERROR error) {
|
||||||
_last_error = error;
|
_last_error = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _dgl_atexit(void) {
|
void dgl_init(void) {
|
||||||
|
atexit(dgl_close);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dgl_close(void) {
|
||||||
events_shutdown();
|
events_shutdown();
|
||||||
mouse_shutdown();
|
mouse_shutdown();
|
||||||
keyboard_shutdown();
|
keyboard_shutdown();
|
||||||
video_shutdown();
|
gfx_shutdown();
|
||||||
}
|
|
||||||
|
|
||||||
void dgl_init(void) {
|
|
||||||
atexit(_dgl_atexit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
55
DGL.H
Normal file → Executable file
55
DGL.H
Normal file → Executable file
|
@ -1,26 +1,41 @@
|
||||||
#ifndef DGL_DGL_H_INCLUDED
|
#ifndef LIBDGL_DGL_H
|
||||||
#define DGL_DGL_H_INCLUDED
|
#define LIBDGL_DGL_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#ifdef __cplusplus
|
||||||
#include "dglerror.h"
|
extern "C" {
|
||||||
|
#endif
|
||||||
#include "dglkbrd.h"
|
|
||||||
#include "dglmouse.h"
|
|
||||||
#include "dglgfx.h"
|
|
||||||
#include "dglpal.h"
|
|
||||||
#include "dglclip.h"
|
|
||||||
#include "dgldraw.h"
|
|
||||||
#include "dglblit.h"
|
|
||||||
#include "dglmath.h"
|
|
||||||
#include "dglfixp.h"
|
|
||||||
#include "dglrect.h"
|
|
||||||
#include "dglvec2.h"
|
|
||||||
#include "dglmtx33.h"
|
|
||||||
#include "dglutil.h"
|
|
||||||
#include "dglpcx.h"
|
|
||||||
#include "dglevent.h"
|
|
||||||
|
|
||||||
void dgl_init(void);
|
void dgl_init(void);
|
||||||
|
void dgl_close(void);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
DGL_NONE = 0,
|
||||||
|
DGL_ALREADY_INIT,
|
||||||
|
DGL_NEARPTR_ENABLE_FAILURE,
|
||||||
|
DGL_VIDEO_ALREADY_INITIALIZED,
|
||||||
|
DGL_VIDEO_MODE_13H_INIT_FAILURE,
|
||||||
|
DGL_VIDEO_TEXT_MODE_INIT_FAILURE,
|
||||||
|
DGL_KEYBOARD_ALREADY_INITIALIZED,
|
||||||
|
DGL_KEYBOARD_IRQ_INSTALL_FAILURE,
|
||||||
|
DGL_KEYBOARD_IRQ_RESTORE_FAILURE,
|
||||||
|
DGL_KEYBOARD_UPDATE_LED_FAILURE,
|
||||||
|
DGL_MOUSE_ALREADY_INITIALIZED,
|
||||||
|
DGL_MOUSE_ALLOCATE_CALLBACK_FAILURE,
|
||||||
|
DGL_MOUSE_FREE_CALLBACK_FAILURE,
|
||||||
|
DGL_MOUSE_INT_CALLBACK_SET_FAILURE,
|
||||||
|
DGL_MOUSE_INT_CALLBACK_RESTORE_FAILURE,
|
||||||
|
DGL_EVENTS_ALREADY_INITIALIZED,
|
||||||
|
DGL_IO_ERROR,
|
||||||
|
DGL_PCX_BAD_FORMAT
|
||||||
|
} DGL_ERROR;
|
||||||
|
|
||||||
|
DGL_ERROR dgl_last_error(void);
|
||||||
|
const char* dgl_last_error_message(void);
|
||||||
|
void dgl_set_error(DGL_ERROR error);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
152
DGLBLIT.C
Normal file → Executable file
152
DGLBLIT.C
Normal file → Executable file
|
@ -1,10 +1,14 @@
|
||||||
|
#include "dglcmn.h"
|
||||||
|
#include "dglrect.h"
|
||||||
#include "dglblit.h"
|
#include "dglblit.h"
|
||||||
#include "dglclip.h"
|
#include "dglclip.h"
|
||||||
|
|
||||||
static boolean clip_blit(const RECT *dest_clip_region,
|
static bool clip_blit(
|
||||||
RECT *src_blit_region,
|
const RECT *dest_clip_region,
|
||||||
int *dest_x,
|
RECT *src_blit_region,
|
||||||
int *dest_y) {
|
int *dest_x,
|
||||||
|
int *dest_y
|
||||||
|
) {
|
||||||
int dest_clip_right = rect_right(dest_clip_region);
|
int dest_clip_right = rect_right(dest_clip_region);
|
||||||
int dest_clip_bottom = rect_bottom(dest_clip_region);
|
int dest_clip_bottom = rect_bottom(dest_clip_region);
|
||||||
int offset;
|
int offset;
|
||||||
|
@ -13,7 +17,7 @@ static boolean clip_blit(const RECT *dest_clip_region,
|
||||||
if (*dest_x < dest_clip_region->x) {
|
if (*dest_x < dest_clip_region->x) {
|
||||||
// completely off the left edge?
|
// completely off the left edge?
|
||||||
if ((*dest_x + src_blit_region->width - 1) < dest_clip_region->x)
|
if ((*dest_x + src_blit_region->width - 1) < dest_clip_region->x)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
offset = src_blit_region->x - *dest_x;
|
offset = src_blit_region->x - *dest_x;
|
||||||
src_blit_region->x += offset;
|
src_blit_region->x += offset;
|
||||||
|
@ -25,7 +29,7 @@ static boolean clip_blit(const RECT *dest_clip_region,
|
||||||
if (*dest_x > (dest_clip_region->width - src_blit_region->width)) {
|
if (*dest_x > (dest_clip_region->width - src_blit_region->width)) {
|
||||||
// completely off the right edge?
|
// completely off the right edge?
|
||||||
if (*dest_x > dest_clip_right)
|
if (*dest_x > dest_clip_right)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
offset = *dest_x + src_blit_region->width - dest_clip_region->width;
|
offset = *dest_x + src_blit_region->width - dest_clip_region->width;
|
||||||
src_blit_region->width -= offset;
|
src_blit_region->width -= offset;
|
||||||
|
@ -35,7 +39,7 @@ static boolean clip_blit(const RECT *dest_clip_region,
|
||||||
if (*dest_y < dest_clip_region->y) {
|
if (*dest_y < dest_clip_region->y) {
|
||||||
// completely off the top edge?
|
// completely off the top edge?
|
||||||
if ((*dest_y + src_blit_region->height - 1) < dest_clip_region->y)
|
if ((*dest_y + src_blit_region->height - 1) < dest_clip_region->y)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
offset = dest_clip_region->y - *dest_y;
|
offset = dest_clip_region->y - *dest_y;
|
||||||
src_blit_region->y += offset;
|
src_blit_region->y += offset;
|
||||||
|
@ -47,52 +51,58 @@ static boolean clip_blit(const RECT *dest_clip_region,
|
||||||
if (*dest_y > (dest_clip_region->height - src_blit_region->height)) {
|
if (*dest_y > (dest_clip_region->height - src_blit_region->height)) {
|
||||||
// completely off the bottom edge?
|
// completely off the bottom edge?
|
||||||
if (*dest_y > dest_clip_bottom)
|
if (*dest_y > dest_clip_bottom)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
offset = *dest_y + src_blit_region->height - dest_clip_region->height;
|
offset = *dest_y + src_blit_region->height - dest_clip_region->height;
|
||||||
src_blit_region->height -= offset;
|
src_blit_region->height -= offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_blit_region(const SURFACE *src,
|
void blit_region(
|
||||||
SURFACE *dest,
|
const SURFACE *src,
|
||||||
int src_x,
|
SURFACE *dest,
|
||||||
int src_y,
|
int src_x,
|
||||||
int src_width,
|
int src_y,
|
||||||
int src_height,
|
int src_width,
|
||||||
int dest_x,
|
int src_height,
|
||||||
int dest_y) {
|
int dest_x,
|
||||||
|
int dest_y
|
||||||
|
) {
|
||||||
RECT src_region = rect(src_x, src_y, src_width, src_height);
|
RECT src_region = rect(src_x, src_y, src_width, src_height);
|
||||||
boolean on_screen = clip_blit(&dest->clip_region, &src_region, &dest_x, &dest_y);
|
bool on_screen = clip_blit(&dest->clip_region, &src_region, &dest_x, &dest_y);
|
||||||
|
|
||||||
if (!on_screen)
|
if (!on_screen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
surface_blit_region_f(src, dest,
|
blit_region_f(
|
||||||
src_region.x, src_region.y,
|
src, dest,
|
||||||
src_region.width, src_region.height,
|
src_region.x, src_region.y,
|
||||||
dest_x, dest_y);
|
src_region.width, src_region.height,
|
||||||
|
dest_x, dest_y
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_blit_region_f(const SURFACE *src,
|
void blit_region_f(
|
||||||
SURFACE *dest,
|
const SURFACE *src,
|
||||||
int src_x,
|
SURFACE *dest,
|
||||||
int src_y,
|
int src_x,
|
||||||
int src_width,
|
int src_y,
|
||||||
int src_height,
|
int src_width,
|
||||||
int dest_x,
|
int src_height,
|
||||||
int dest_y) {
|
int dest_x,
|
||||||
const byte *psrc;
|
int dest_y
|
||||||
byte *pdest;
|
) {
|
||||||
|
const uint8 *psrc;
|
||||||
|
uint8 *pdest;
|
||||||
int lines;
|
int lines;
|
||||||
int src_y_inc = src->width - src_width;
|
int src_y_inc = src->width - src_width;
|
||||||
int dest_y_inc = dest->width - src_width;
|
int dest_y_inc = dest->width - src_width;
|
||||||
int width_4, width_remainder;
|
int width_4, width_remainder;
|
||||||
|
|
||||||
psrc = (const byte*)surface_pointer(src, src_x, src_y);
|
psrc = (const uint8*)surface_pointer(src, src_x, src_y);
|
||||||
pdest = (byte*)surface_pointer(dest, dest_x, dest_y);
|
pdest = (uint8*)surface_pointer(dest, dest_x, dest_y);
|
||||||
lines = src_height;
|
lines = src_height;
|
||||||
|
|
||||||
width_4 = src_width / 4;
|
width_4 = src_width / 4;
|
||||||
|
@ -100,57 +110,63 @@ void surface_blit_region_f(const SURFACE *src,
|
||||||
|
|
||||||
if (width_4 && !width_remainder) {
|
if (width_4 && !width_remainder) {
|
||||||
// width is a multiple of 4 (no remainder)
|
// width is a multiple of 4 (no remainder)
|
||||||
direct_blit_4(width_4, lines, pdest, psrc, dest_y_inc, src_y_inc);
|
lowlevel_blit_4(width_4, lines, pdest, psrc, dest_y_inc, src_y_inc);
|
||||||
|
|
||||||
} else if (width_4 && width_remainder) {
|
} else if (width_4 && width_remainder) {
|
||||||
// width is >= 4 and there is a remainder ( <= 3 )
|
// width is >= 4 and there is a remainder ( <= 3 )
|
||||||
direct_blit_4r(width_4, lines, width_remainder, pdest, psrc, dest_y_inc, src_y_inc);
|
lowlevel_blit_4r(width_4, lines, width_remainder, pdest, psrc, dest_y_inc, src_y_inc);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// width is <= 3
|
// width is <= 3
|
||||||
direct_blit_r(width_remainder, lines, pdest, psrc, dest_y_inc, src_y_inc);
|
lowlevel_blit_r(width_remainder, lines, pdest, psrc, dest_y_inc, src_y_inc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_blit_sprite_region(const SURFACE *src,
|
void blit_sprite_region(
|
||||||
SURFACE *dest,
|
const SURFACE *src,
|
||||||
int src_x,
|
SURFACE *dest,
|
||||||
int src_y,
|
int src_x,
|
||||||
int src_width,
|
int src_y,
|
||||||
int src_height,
|
int src_width,
|
||||||
int dest_x,
|
int src_height,
|
||||||
int dest_y) {
|
int dest_x,
|
||||||
|
int dest_y
|
||||||
|
) {
|
||||||
RECT src_region = rect(src_x, src_y, src_width, src_height);
|
RECT src_region = rect(src_x, src_y, src_width, src_height);
|
||||||
boolean on_screen = clip_blit(&dest->clip_region, &src_region, &dest_x, &dest_y);
|
bool on_screen = clip_blit(&dest->clip_region, &src_region, &dest_x, &dest_y);
|
||||||
|
|
||||||
if (!on_screen)
|
if (!on_screen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
surface_blit_sprite_region_f(src, dest,
|
blit_sprite_region_f(
|
||||||
src_region.x, src_region.y,
|
src, dest,
|
||||||
src_region.width, src_region.height,
|
src_region.x, src_region.y,
|
||||||
dest_x, dest_y);
|
src_region.width, src_region.height,
|
||||||
|
dest_x, dest_y
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_blit_sprite_region_f(const SURFACE *src,
|
void blit_sprite_region_f(
|
||||||
SURFACE *dest,
|
const SURFACE *src,
|
||||||
int src_x,
|
SURFACE *dest,
|
||||||
int src_y,
|
int src_x,
|
||||||
int src_width,
|
int src_y,
|
||||||
int src_height,
|
int src_width,
|
||||||
int dest_x,
|
int src_height,
|
||||||
int dest_y) {
|
int dest_x,
|
||||||
const byte *psrc;
|
int dest_y
|
||||||
byte *pdest;
|
) {
|
||||||
byte pixel;
|
const uint8 *psrc;
|
||||||
|
uint8 *pdest;
|
||||||
|
uint8 pixel;
|
||||||
int src_y_inc, dest_y_inc;
|
int src_y_inc, dest_y_inc;
|
||||||
int width, width_4, width_8, width_remainder;
|
int width, width_4, width_8, width_remainder;
|
||||||
int lines_left;
|
int lines_left;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
psrc = (const byte*)surface_pointer(src, src_x, src_y);
|
psrc = (const uint8*)surface_pointer(src, src_x, src_y);
|
||||||
src_y_inc = src->width;
|
src_y_inc = src->width;
|
||||||
pdest = (byte*)surface_pointer(dest, dest_x, dest_y);
|
pdest = (uint8*)surface_pointer(dest, dest_x, dest_y);
|
||||||
dest_y_inc = dest->width;
|
dest_y_inc = dest->width;
|
||||||
width = src_width;
|
width = src_width;
|
||||||
lines_left = src_height;
|
lines_left = src_height;
|
||||||
|
@ -164,25 +180,25 @@ void surface_blit_sprite_region_f(const SURFACE *src,
|
||||||
if (width_4 && !width_remainder) {
|
if (width_4 && !width_remainder) {
|
||||||
if ((width_4 & 1) == 0) {
|
if ((width_4 & 1) == 0) {
|
||||||
// width is actually an even multiple of 8!
|
// width is actually an even multiple of 8!
|
||||||
direct_blit_sprite_8(width_4 / 2, lines_left, pdest, psrc, dest_y_inc, src_y_inc);
|
lowlevel_blit_sprite_8(width_4 / 2, lines_left, pdest, psrc, dest_y_inc, src_y_inc);
|
||||||
} else {
|
} else {
|
||||||
// width is a multiple of 4 (no remainder)
|
// width is a multiple of 4 (no remainder)
|
||||||
direct_blit_sprite_4(width_4, lines_left, pdest, psrc, dest_y_inc, src_y_inc);
|
lowlevel_blit_sprite_4(width_4, lines_left, pdest, psrc, dest_y_inc, src_y_inc);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (width_4 && width_remainder) {
|
} else if (width_4 && width_remainder) {
|
||||||
if ((width_4 & 1) == 0) {
|
if ((width_4 & 1) == 0) {
|
||||||
// width is _mostly_ made up of an even multiple of 8,
|
// width is _mostly_ made up of an even multiple of 8,
|
||||||
// plus a small remainder
|
// plus a small remainder
|
||||||
direct_blit_sprite_8r(width_4 / 2, lines_left, pdest, psrc, width_remainder, dest_y_inc, src_y_inc);
|
lowlevel_blit_sprite_8r(width_4 / 2, lines_left, pdest, psrc, width_remainder, dest_y_inc, src_y_inc);
|
||||||
} else {
|
} else {
|
||||||
// width is >= 4 and there is a remainder
|
// width is >= 4 and there is a remainder
|
||||||
direct_blit_sprite_4r(width_4, lines_left, pdest, psrc, width_remainder, dest_y_inc, src_y_inc);
|
lowlevel_blit_sprite_4r(width_4, lines_left, pdest, psrc, width_remainder, dest_y_inc, src_y_inc);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// width is <= 3
|
// width is <= 3
|
||||||
direct_blit_sprite_r(width_remainder, lines_left, pdest, psrc, dest_y_inc, src_y_inc);
|
lowlevel_blit_sprite_r(width_remainder, lines_left, pdest, psrc, dest_y_inc, src_y_inc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
202
DGLBLIT.H
Normal file → Executable file
202
DGLBLIT.H
Normal file → Executable file
|
@ -1,79 +1,163 @@
|
||||||
#ifndef DGL_DGLBLIT_H_INCLUDED
|
#ifndef LIBDGL_DGLBLIT_H
|
||||||
#define DGL_DGLBLIT_H_INCLUDED
|
#define LIBDGL_DGLBLIT_H
|
||||||
|
|
||||||
#include "dglgfx.h"
|
#include "dglgfx.h"
|
||||||
#include "dglutil.h"
|
|
||||||
|
|
||||||
void surface_blit_region(const SURFACE *src,
|
#ifdef __cplusplus
|
||||||
SURFACE *dest,
|
extern "C" {
|
||||||
int src_x,
|
#endif
|
||||||
int src_y,
|
|
||||||
int src_width,
|
|
||||||
int src_height,
|
|
||||||
int dest_x,
|
|
||||||
int dest_y);
|
|
||||||
|
|
||||||
void surface_blit_region_f(const SURFACE *src,
|
void blit_region(
|
||||||
SURFACE *dest,
|
const SURFACE *src,
|
||||||
int src_x,
|
SURFACE *dest,
|
||||||
int src_y,
|
int src_x,
|
||||||
int src_width,
|
int src_y,
|
||||||
int src_height,
|
int src_width,
|
||||||
int dest_x,
|
int src_height,
|
||||||
int dest_y);
|
int dest_x,
|
||||||
|
int dest_y
|
||||||
|
);
|
||||||
|
|
||||||
static void surface_blit(const SURFACE *src, SURFACE *dest, int x, int y);
|
void blit_region_f(
|
||||||
|
const SURFACE *src,
|
||||||
|
SURFACE *dest,
|
||||||
|
int src_x,
|
||||||
|
int src_y,
|
||||||
|
int src_width,
|
||||||
|
int src_height,
|
||||||
|
int dest_x,
|
||||||
|
int dest_y
|
||||||
|
);
|
||||||
|
|
||||||
static void surface_blit_f(const SURFACE *src, SURFACE *dest, int x, int y);
|
void blit_sprite_region(
|
||||||
|
const SURFACE *src,
|
||||||
|
SURFACE *dest,
|
||||||
|
int src_x,
|
||||||
|
int src_y,
|
||||||
|
int src_width,
|
||||||
|
int src_height,
|
||||||
|
int dest_x,
|
||||||
|
int dest_y
|
||||||
|
);
|
||||||
|
|
||||||
void surface_blit_sprite_region(const SURFACE *src,
|
void blit_sprite_region_f(
|
||||||
SURFACE *dest,
|
const SURFACE *src,
|
||||||
int src_x,
|
SURFACE *dest,
|
||||||
int src_y,
|
int src_x,
|
||||||
int src_width,
|
int src_y,
|
||||||
int src_height,
|
int src_width,
|
||||||
int dest_x,
|
int src_height,
|
||||||
int dest_y);
|
int dest_x,
|
||||||
|
int dest_y
|
||||||
void surface_blit_sprite_region_f(const SURFACE *src,
|
);
|
||||||
SURFACE *dest,
|
|
||||||
int src_x,
|
|
||||||
int src_y,
|
|
||||||
int src_width,
|
|
||||||
int src_height,
|
|
||||||
int dest_x,
|
|
||||||
int dest_y);
|
|
||||||
|
|
||||||
void direct_blit_4(int width4, int lines, byte *dest, const byte *src, int dest_y_inc, int src_y_inc);
|
|
||||||
void direct_blit_4r(int width4, int lines, int remainder, byte *dest, const byte *src, int dest_y_inc, int src_y_inc);
|
|
||||||
void direct_blit_r(int width, int lines, byte *dest, const byte *src, int dest_y_inc, int src_y_inc);
|
|
||||||
void direct_blit_sprite_4(int width4, int lines, byte *dest, const byte *src, int dest_y_inc, int src_y_inc);
|
|
||||||
void direct_blit_sprite_4r(int width4, int lines, byte *dest, const byte *src, int remainder, int dest_y_inc, int src_y_inc);
|
|
||||||
void direct_blit_sprite_r(int width, int lines, byte *dest, const byte *src, int dest_y_inc, int src_y_inc);
|
|
||||||
void direct_blit_sprite_8(int width8, int lines, byte *dest, const byte *src, int dest_y_inc, int src_y_inc);
|
|
||||||
void direct_blit_sprite_8r(int width8, int lines, byte *dest, const byte *src, int remainder, int dest_y_inc, int src_y_inc);
|
|
||||||
|
|
||||||
static void surface_blit_sprite(const SURFACE *src, SURFACE *dest, int x, int y);
|
|
||||||
static void surface_blit_sprite_f(const SURFACE *src, SURFACE *dest, int x, int y);
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
static void surface_blit(const SURFACE *src, SURFACE *dest, int x, int y) {
|
void lowlevel_blit_4(
|
||||||
surface_blit_region(src, dest, 0, 0, src->width, src->height, x, y);
|
int width4,
|
||||||
}
|
int lines,
|
||||||
|
uint8 *dest,
|
||||||
|
const uint8 *src,
|
||||||
|
int dest_y_inc,
|
||||||
|
int src_y_inc
|
||||||
|
);
|
||||||
|
|
||||||
|
void lowlevel_blit_4r(
|
||||||
|
int width4,
|
||||||
|
int lines,
|
||||||
|
int remainder,
|
||||||
|
uint8 *dest,
|
||||||
|
const uint8 *src,
|
||||||
|
int dest_y_inc,
|
||||||
|
int src_y_inc
|
||||||
|
);
|
||||||
|
|
||||||
|
void lowlevel_blit_r(
|
||||||
|
int width,
|
||||||
|
int lines,
|
||||||
|
uint8 *dest,
|
||||||
|
const uint8 *src,
|
||||||
|
int dest_y_inc,
|
||||||
|
int src_y_inc
|
||||||
|
);
|
||||||
|
|
||||||
|
void lowlevel_blit_sprite_4(
|
||||||
|
int width4,
|
||||||
|
int lines,
|
||||||
|
uint8 *dest,
|
||||||
|
const uint8 *src,
|
||||||
|
int dest_y_inc,
|
||||||
|
int src_y_inc
|
||||||
|
);
|
||||||
|
|
||||||
|
void lowlevel_blit_sprite_4r(
|
||||||
|
int width4,
|
||||||
|
int lines,
|
||||||
|
uint8 *dest,
|
||||||
|
const uint8 *src,
|
||||||
|
int remainder,
|
||||||
|
int dest_y_inc,
|
||||||
|
int src_y_inc
|
||||||
|
);
|
||||||
|
|
||||||
|
void lowlevel_blit_sprite_r(
|
||||||
|
int width,
|
||||||
|
int lines,
|
||||||
|
uint8 *dest,
|
||||||
|
const uint8 *src,
|
||||||
|
int dest_y_inc,
|
||||||
|
int src_y_inc
|
||||||
|
);
|
||||||
|
|
||||||
|
void lowlevel_blit_sprite_8(
|
||||||
|
int width8,
|
||||||
|
int lines,
|
||||||
|
uint8 *dest,
|
||||||
|
const uint8 *src,
|
||||||
|
int dest_y_inc,
|
||||||
|
int src_y_inc
|
||||||
|
);
|
||||||
|
|
||||||
|
void lowlevel_blit_sprite_8r(
|
||||||
|
int width8,
|
||||||
|
int lines,
|
||||||
|
uint8 *dest,
|
||||||
|
const uint8 *src,
|
||||||
|
int remainder,
|
||||||
|
int dest_y_inc,
|
||||||
|
int src_y_inc
|
||||||
|
);
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
static void surface_blit_f(const SURFACE *src, SURFACE *dest, int x, int y) {
|
static void blit(const SURFACE *src, SURFACE *dest, int x, int y);
|
||||||
surface_blit_region_f(src, dest, 0, 0, src->width, src->height, x, y);
|
static void blit_f(const SURFACE *src, SURFACE *dest, int x, int y);
|
||||||
|
static void blit_sprite(const SURFACE *src, SURFACE *dest, int x, int y);
|
||||||
|
static void blit_sprite_f(const SURFACE *src, SURFACE *dest, int x, int y);
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static void blit(const SURFACE *src, SURFACE *dest, int x, int y) {
|
||||||
|
blit_region(src, dest, 0, 0, src->width, src->height, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void surface_blit_sprite(const SURFACE *src, SURFACE *dest, int x, int y) {
|
static void blit_f(const SURFACE *src, SURFACE *dest, int x, int y) {
|
||||||
surface_blit_sprite_region(src, dest, 0, 0, src->width, src->height, x, y);
|
blit_region_f(src, dest, 0, 0, src->width, src->height, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void surface_blit_sprite_f(const SURFACE *src, SURFACE *dest, int x, int y) {
|
static void blit_sprite(const SURFACE *src, SURFACE *dest, int x, int y) {
|
||||||
surface_blit_sprite_region_f(src, dest, 0, 0, src->width, src->height, x, y);
|
blit_sprite_region(src, dest, 0, 0, src->width, src->height, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void blit_sprite_f(const SURFACE *src, SURFACE *dest, int x, int y) {
|
||||||
|
blit_sprite_region_f(src, dest, 0, 0, src->width, src->height, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
48
DGLBLITA.ASM
Normal file → Executable file
48
DGLBLITA.ASM
Normal file → Executable file
|
@ -7,23 +7,23 @@ codeseg
|
||||||
|
|
||||||
locals
|
locals
|
||||||
|
|
||||||
public direct_blit_4_
|
public lowlevel_blit_4_
|
||||||
public direct_blit_4r_
|
public lowlevel_blit_4r_
|
||||||
public direct_blit_r_
|
public lowlevel_blit_r_
|
||||||
public direct_blit_sprite_4_
|
public lowlevel_blit_sprite_4_
|
||||||
public direct_blit_sprite_4r_
|
public lowlevel_blit_sprite_4r_
|
||||||
public direct_blit_sprite_r_
|
public lowlevel_blit_sprite_r_
|
||||||
public direct_blit_sprite_8_
|
public lowlevel_blit_sprite_8_
|
||||||
public direct_blit_sprite_8r_
|
public lowlevel_blit_sprite_8r_
|
||||||
|
|
||||||
; direct_blit_4_
|
; lowlevel_blit_4_
|
||||||
; eax = width4
|
; eax = width4
|
||||||
; edx = lines
|
; edx = lines
|
||||||
; ebx = dest
|
; ebx = dest
|
||||||
; ecx = src
|
; ecx = src
|
||||||
; ebp+8 = dest_y_inc
|
; ebp+8 = dest_y_inc
|
||||||
; ebp+12 = src_y_inc
|
; ebp+12 = src_y_inc
|
||||||
proc direct_blit_4_ near
|
proc lowlevel_blit_4_ near
|
||||||
arg @@dest_y_inc:dword, @@src_y_inc:dword
|
arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
push ebp
|
push ebp
|
||||||
|
@ -62,7 +62,7 @@ arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
; direct_blit_4r_
|
; lowlevel_blit_4r_
|
||||||
; eax = width4
|
; eax = width4
|
||||||
; edx = lines
|
; edx = lines
|
||||||
; ebx = remainder
|
; ebx = remainder
|
||||||
|
@ -70,7 +70,7 @@ arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
; ebp+8 = src
|
; ebp+8 = src
|
||||||
; ebp+12 = dest_y_inc
|
; ebp+12 = dest_y_inc
|
||||||
; ebp+16 = src_y_inc
|
; ebp+16 = src_y_inc
|
||||||
proc direct_blit_4r_ near
|
proc lowlevel_blit_4r_ near
|
||||||
arg @@src:dword, @@dest_y_inc:dword, @@src_y_inc:dword
|
arg @@src:dword, @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
push ebp
|
push ebp
|
||||||
|
@ -107,14 +107,14 @@ arg @@src:dword, @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
; direct_blit_r_
|
; lowlevel_blit_r_
|
||||||
; eax = width
|
; eax = width
|
||||||
; edx = lines
|
; edx = lines
|
||||||
; ebx = dest
|
; ebx = dest
|
||||||
; ecx = src
|
; ecx = src
|
||||||
; ebp+8 = dest_y_inc
|
; ebp+8 = dest_y_inc
|
||||||
; ebp+12 = src_y_inc
|
; ebp+12 = src_y_inc
|
||||||
proc direct_blit_r_ near
|
proc lowlevel_blit_r_ near
|
||||||
arg @@dest_y_inc:dword, @@src_y_inc:dword
|
arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
push ebp
|
push ebp
|
||||||
|
@ -148,14 +148,14 @@ arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
; direct_blit_sprite_4_
|
; lowlevel_blit_sprite_4_
|
||||||
; eax = width4
|
; eax = width4
|
||||||
; edx = lines
|
; edx = lines
|
||||||
; ebx = dest
|
; ebx = dest
|
||||||
; ecx = src
|
; ecx = src
|
||||||
; ebp+8 = dest_y_inc
|
; ebp+8 = dest_y_inc
|
||||||
; ebp+12 = src_y_inc
|
; ebp+12 = src_y_inc
|
||||||
proc direct_blit_sprite_4_ near
|
proc lowlevel_blit_sprite_4_ near
|
||||||
arg @@dest_y_inc:dword, @@src_y_inc:dword
|
arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
push ebp
|
push ebp
|
||||||
|
@ -214,7 +214,7 @@ arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
; direct_blit_sprite_4r_
|
; lowlevel_blit_sprite_4r_
|
||||||
; eax = width4
|
; eax = width4
|
||||||
; edx = lines
|
; edx = lines
|
||||||
; ebx = dest
|
; ebx = dest
|
||||||
|
@ -222,7 +222,7 @@ arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
; ebp+8 = remainder
|
; ebp+8 = remainder
|
||||||
; ebp+12 = dest_y_inc
|
; ebp+12 = dest_y_inc
|
||||||
; ebp+16 = src_y_inc
|
; ebp+16 = src_y_inc
|
||||||
proc direct_blit_sprite_4r_ near
|
proc lowlevel_blit_sprite_4r_ near
|
||||||
arg @@remainder:dword, @@dest_y_inc:dword, @@src_y_inc:dword
|
arg @@remainder:dword, @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
push ebp
|
push ebp
|
||||||
|
@ -295,14 +295,14 @@ arg @@remainder:dword, @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
; direct_blit_sprite_r_
|
; lowlevel_blit_sprite_r_
|
||||||
; eax = width
|
; eax = width
|
||||||
; edx = lines
|
; edx = lines
|
||||||
; ebx = dest
|
; ebx = dest
|
||||||
; ecx = src
|
; ecx = src
|
||||||
; ebp+8 = dest_y_inc
|
; ebp+8 = dest_y_inc
|
||||||
; ebp+12 = src_y_inc
|
; ebp+12 = src_y_inc
|
||||||
proc direct_blit_sprite_r_ near
|
proc lowlevel_blit_sprite_r_ near
|
||||||
arg @@dest_y_inc:dword, @@src_y_inc:dword
|
arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
push ebp
|
push ebp
|
||||||
|
@ -347,14 +347,14 @@ arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
; direct_blit_sprite_8_
|
; lowlevel_blit_sprite_8_
|
||||||
; eax = width8
|
; eax = width8
|
||||||
; edx = lines
|
; edx = lines
|
||||||
; ebx = dest
|
; ebx = dest
|
||||||
; ecx = src
|
; ecx = src
|
||||||
; ebp+8 = dest_y_inc
|
; ebp+8 = dest_y_inc
|
||||||
; ebp+12 = src_y_inc
|
; ebp+12 = src_y_inc
|
||||||
proc direct_blit_sprite_8_ near
|
proc lowlevel_blit_sprite_8_ near
|
||||||
arg @@dest_y_inc:dword, @@src_y_inc:dword
|
arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
push ebp
|
push ebp
|
||||||
|
@ -429,7 +429,7 @@ arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
; direct_blit_sprite_8r_
|
; lowlevel_blit_sprite_8r_
|
||||||
; eax = width8
|
; eax = width8
|
||||||
; edx = lines
|
; edx = lines
|
||||||
; ebx = dest
|
; ebx = dest
|
||||||
|
@ -437,7 +437,7 @@ arg @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
; ebp+8 = remainder
|
; ebp+8 = remainder
|
||||||
; ebp+12 = dest_y_inc
|
; ebp+12 = dest_y_inc
|
||||||
; ebp+16 = src_y_inc
|
; ebp+16 = src_y_inc
|
||||||
proc direct_blit_sprite_8r_ near
|
proc lowlevel_blit_sprite_8r_ near
|
||||||
arg @@remainder:dword, @@dest_y_inc:dword, @@src_y_inc:dword
|
arg @@remainder:dword, @@dest_y_inc:dword, @@src_y_inc:dword
|
||||||
|
|
||||||
push ebp
|
push ebp
|
||||||
|
|
73
DGLCLIP.C
Normal file → Executable file
73
DGLCLIP.C
Normal file → Executable file
|
@ -2,27 +2,47 @@
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
#include "dglmath.h"
|
#include "dglmath.h"
|
||||||
|
|
||||||
static boolean is_in_bounds(int clip_x,
|
bool is_in_bounds(
|
||||||
int clip_y,
|
int clip_x,
|
||||||
int clip_right,
|
int clip_y,
|
||||||
int clip_bottom,
|
int clip_right,
|
||||||
int x1,
|
int clip_bottom,
|
||||||
int y1,
|
int x1,
|
||||||
int x2,
|
int y1,
|
||||||
int y2) {
|
int x2,
|
||||||
if (y1 < clip_y && y2 < clip_y)
|
int y2
|
||||||
return FALSE;
|
) {
|
||||||
|
if (y1 < clip_y && y2 < clip_y)
|
||||||
|
return false;
|
||||||
if (y1 > clip_bottom && y2 > clip_bottom)
|
if (y1 > clip_bottom && y2 > clip_bottom)
|
||||||
return FALSE;
|
return false;
|
||||||
if (x1 < clip_x && x2 < clip_x)
|
if (x1 < clip_x && x2 < clip_x)
|
||||||
return FALSE;
|
return false;
|
||||||
if (x1 > clip_right && x2 > clip_right)
|
if (x1 > clip_right && x2 > clip_right)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean is_point_in_bounds(const RECT *clip_region, int x, int y) {
|
bool is_rect_in_bounds(const RECT *clip_region, const RECT *r) {
|
||||||
|
int clip_right = rect_right(clip_region);
|
||||||
|
int clip_bottom = rect_bottom(clip_region);
|
||||||
|
int x2 = rect_right(r);
|
||||||
|
int y2 = rect_bottom(r);
|
||||||
|
|
||||||
|
if (r->y < clip_region->y && y2 < clip_region->y)
|
||||||
|
return false;
|
||||||
|
if (r->y > clip_bottom && y2 > clip_bottom)
|
||||||
|
return false;
|
||||||
|
if (r->x < clip_region->x && x2 < clip_region->x)
|
||||||
|
return false;
|
||||||
|
if (r->x > clip_right && x2 > clip_right)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_point_in_bounds(const RECT *clip_region, int x, int y) {
|
||||||
return (
|
return (
|
||||||
x >= clip_region->x &&
|
x >= clip_region->x &&
|
||||||
y >= clip_region->y &&
|
y >= clip_region->y &&
|
||||||
|
@ -31,18 +51,14 @@ boolean is_point_in_bounds(const RECT *clip_region, int x, int y) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean clamp_to_region(const RECT *clip_region,
|
bool clamp_to_region(const RECT *clip_region, int *x1, int *y1, int *x2, int *y2) {
|
||||||
int *x1,
|
|
||||||
int *y1,
|
|
||||||
int *x2,
|
|
||||||
int *y2) {
|
|
||||||
int clip_x = clip_region->x;
|
int clip_x = clip_region->x;
|
||||||
int clip_y = clip_region->y;
|
int clip_y = clip_region->y;
|
||||||
int clip_right = rect_right(clip_region);
|
int clip_right = rect_right(clip_region);
|
||||||
int clip_bottom = rect_bottom(clip_region);
|
int clip_bottom = rect_bottom(clip_region);
|
||||||
|
|
||||||
if (!is_in_bounds(clip_x, clip_y, clip_right, clip_bottom, *x1, *y1, *x2, *y2))
|
if (!is_in_bounds(clip_x, clip_y, clip_right, clip_bottom, *x1, *y1, *x2, *y2))
|
||||||
return FALSE;
|
return true;
|
||||||
|
|
||||||
// at least partially within bounds
|
// at least partially within bounds
|
||||||
|
|
||||||
|
@ -55,10 +71,10 @@ boolean clamp_to_region(const RECT *clip_region,
|
||||||
if (*x2 < clip_x) *x2 = clip_x;
|
if (*x2 < clip_x) *x2 = clip_x;
|
||||||
if (*x2 > clip_right) *x2 = clip_right;
|
if (*x2 > clip_right) *x2 = clip_right;
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean clip_to_region(const RECT *clip_region, RECT *r) {
|
bool clip_to_region(const RECT *clip_region, RECT *r) {
|
||||||
int clip_right = rect_right(clip_region);
|
int clip_right = rect_right(clip_region);
|
||||||
int clip_bottom = rect_bottom(clip_region);
|
int clip_bottom = rect_bottom(clip_region);
|
||||||
int offset;
|
int offset;
|
||||||
|
@ -67,7 +83,7 @@ boolean clip_to_region(const RECT *clip_region, RECT *r) {
|
||||||
if (r->x < clip_region->x) {
|
if (r->x < clip_region->x) {
|
||||||
// completely off the left edge?
|
// completely off the left edge?
|
||||||
if (rect_right(r) < clip_region->x)
|
if (rect_right(r) < clip_region->x)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
offset = clip_region->x - r->x;
|
offset = clip_region->x - r->x;
|
||||||
r->x += offset;
|
r->x += offset;
|
||||||
|
@ -78,7 +94,7 @@ boolean clip_to_region(const RECT *clip_region, RECT *r) {
|
||||||
if (r->x > (clip_region->width - r->width)) {
|
if (r->x > (clip_region->width - r->width)) {
|
||||||
// completely off the right edge?
|
// completely off the right edge?
|
||||||
if (r->x > clip_right)
|
if (r->x > clip_right)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
offset = r->x + r->width - clip_region->width;
|
offset = r->x + r->width - clip_region->width;
|
||||||
r->width -= offset;
|
r->width -= offset;
|
||||||
|
@ -88,7 +104,7 @@ boolean clip_to_region(const RECT *clip_region, RECT *r) {
|
||||||
if (r->y < clip_region->y) {
|
if (r->y < clip_region->y) {
|
||||||
// completely off the top edge?
|
// completely off the top edge?
|
||||||
if (rect_bottom(r) < clip_region->y)
|
if (rect_bottom(r) < clip_region->y)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
offset = clip_region->y - r->y;
|
offset = clip_region->y - r->y;
|
||||||
r->y += offset;
|
r->y += offset;
|
||||||
|
@ -99,13 +115,12 @@ boolean clip_to_region(const RECT *clip_region, RECT *r) {
|
||||||
if (r->y > (clip_region->height - r->height)) {
|
if (r->y > (clip_region->height - r->height)) {
|
||||||
// completely off the bottom edge?
|
// completely off the bottom edge?
|
||||||
if (r->y > clip_bottom)
|
if (r->y > clip_bottom)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
offset = r->y + r->height - clip_region->height;
|
offset = r->y + r->height - clip_region->height;
|
||||||
r->height -= offset;
|
r->height -= offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
53
DGLCLIP.H
Normal file → Executable file
53
DGLCLIP.H
Normal file → Executable file
|
@ -1,39 +1,32 @@
|
||||||
#ifndef DGL_DGLCLIP_H_INCLUDED
|
#ifndef LIBDGL_DGLCLIP_H
|
||||||
#define DGL_DGLCLIP_H_INCLUDED
|
#define LIBDGL_DGLCLIP_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
#include "dglrect.h"
|
#include "dglrect.h"
|
||||||
|
|
||||||
/*
|
#ifdef __cplusplus
|
||||||
* Determines if the given point lies within the clipping region.
|
extern "C" {
|
||||||
* @param clip_region the clipping region to check against
|
#endif
|
||||||
* @param x x coordinate of the point
|
|
||||||
* @param y y coordinate of the point
|
|
||||||
* @return TRUE if the point lies inside the clipping region
|
|
||||||
*/
|
|
||||||
boolean is_point_in_bounds(const RECT *clip_region, int x, int y);
|
|
||||||
|
|
||||||
/*
|
bool is_in_bounds(
|
||||||
* Clamps the coordinates given to the clipping region, assuming that the
|
int clip_x,
|
||||||
* region defined by the coordinates lies at least partially within the
|
int clip_y,
|
||||||
* clipping region.
|
int clip_right,
|
||||||
* @param clip_region the clipping region to check against and clamp to
|
int clip_bottom,
|
||||||
* @param x1 x coordinate of the top-left point of the region to clamp
|
int x1,
|
||||||
* @param y1 y coordinate of the top-left point of the region to clamp
|
int y1,
|
||||||
* @param x2 x coordinate of the bottom-right point of the region to clamp
|
int x2,
|
||||||
* @param y2 y coordinate of the bottom-right point of the region to clamp
|
int y2
|
||||||
* @return TRUE if the given region was clamped and was at least partially
|
);
|
||||||
* within the clipping region to begin with. If the region was
|
|
||||||
* totally outside of the clipping region, returns FALSE and the
|
|
||||||
* coordinates will not be modified.
|
|
||||||
*/
|
|
||||||
boolean clamp_to_region(const RECT *clip_region,
|
|
||||||
int *x1,
|
|
||||||
int *y1,
|
|
||||||
int *x2,
|
|
||||||
int *y2);
|
|
||||||
|
|
||||||
boolean clip_to_region(const RECT *clip_region, RECT *r);
|
bool is_rect_in_bounds(const RECT *clip_region, const RECT *r);
|
||||||
|
bool is_point_in_bounds(const RECT *clip_region, int x, int y);
|
||||||
|
bool clamp_to_region(const RECT *clip_region, int *x1, int *y1, int *x2, int *y2);
|
||||||
|
bool clip_to_region(const RECT *clip_region, RECT *r);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
64
DGLCMN.H
Normal file → Executable file
64
DGLCMN.H
Normal file → Executable file
|
@ -1,36 +1,48 @@
|
||||||
#ifndef DGL_DGLCMN_H_INCLUDED
|
#ifndef LIBDGL_DGLCMN_H
|
||||||
#define DGL_DGLCMN_H_INCLUDED
|
#define LIBDGL_DGLCMN_H
|
||||||
|
|
||||||
typedef int boolean;
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef char byte;
|
typedef char int8;
|
||||||
typedef short word;
|
typedef short int16;
|
||||||
typedef int dword;
|
typedef int int32;
|
||||||
|
|
||||||
typedef unsigned char ubyte;
|
typedef unsigned char uint8;
|
||||||
typedef unsigned short uword;
|
typedef unsigned short uint16;
|
||||||
typedef unsigned int udword;
|
typedef unsigned int uint32;
|
||||||
|
|
||||||
typedef unsigned char uchar;
|
#ifndef bool
|
||||||
typedef unsigned short ushort;
|
typedef int bool;
|
||||||
typedef unsigned int uint;
|
#define true 1
|
||||||
|
#define false 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TRUE 1
|
#define BIT_0 0x1
|
||||||
#define FALSE 0
|
#define BIT_1 0x2
|
||||||
|
#define BIT_2 0x4
|
||||||
|
#define BIT_3 0x8
|
||||||
|
#define BIT_4 0x10
|
||||||
|
#define BIT_5 0x20
|
||||||
|
#define BIT_6 0x40
|
||||||
|
#define BIT_7 0x80
|
||||||
|
|
||||||
#define BIT_0 0x1
|
#define BIT_ISSET(bit, x) ((x) & (bit))
|
||||||
#define BIT_1 0x2
|
#define BIT_SET(bit, x) ((x) |= (bit))
|
||||||
#define BIT_2 0x4
|
#define BIT_CLEAR(bit, x) ((x) &= ~(bit))
|
||||||
#define BIT_3 0x8
|
#define BIT_TOGGLE(bit, x) ((x) ^= (bit))
|
||||||
#define BIT_4 0x10
|
|
||||||
#define BIT_5 0x20
|
|
||||||
#define BIT_6 0x40
|
|
||||||
#define BIT_7 0x80
|
|
||||||
|
|
||||||
#define BIT_ISSET(bit, x) ((x) & (bit))
|
#ifndef MAX
|
||||||
#define BIT_SET(bit, x) ((x) |= (bit))
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
#define BIT_CLEAR(bit, x) ((x) &= ~(bit))
|
#endif
|
||||||
#define BIT_TOGGLE(bit, x) ((x) ^= (bit))
|
#ifndef MIN
|
||||||
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
265
DGLDRAW.C
Normal file → Executable file
265
DGLDRAW.C
Normal file → Executable file
|
@ -1,6 +1,6 @@
|
||||||
#include "dgldraw.h"
|
#include "dgldraw.h"
|
||||||
#include "dglgfx.h"
|
#include "dglgfx.h"
|
||||||
#include "dglmath.h"
|
#include "dglrect.h"
|
||||||
#include "dglutil.h"
|
#include "dglutil.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -9,36 +9,37 @@
|
||||||
|
|
||||||
static char printf_buffer[1024];
|
static char printf_buffer[1024];
|
||||||
|
|
||||||
void surface_hline_f(SURFACE *surface, int x1, int x2, int y, int color) {
|
void draw_hline_f(SURFACE *surface, int x1, int x2, int y, uint8 color) {
|
||||||
byte *p = surface_pointer(surface, x1, y);
|
uint8 *p = surface_pointer(surface, x1, y);
|
||||||
mem_fill(p, color, (x2 - x1 + 1));
|
mem_fill(p, color, (x2 - x1 + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_vline_f(SURFACE *surface, int x, int y1, int y2, int color) {
|
extern void _draw_vline(uint8 *dest, uint8 color, int line_inc, int lines_left);
|
||||||
byte *p = surface_pointer(surface, x, y1);
|
#pragma aux _draw_vline = \
|
||||||
|
" test ecx, ecx" \
|
||||||
|
" jz done" \
|
||||||
|
"draw:" \
|
||||||
|
" mov [edx], al" \
|
||||||
|
" add edx, ebx" \
|
||||||
|
" dec ecx" \
|
||||||
|
" jnz draw" \
|
||||||
|
"done:" \
|
||||||
|
parm [edx] [al] [ebx] [ecx];
|
||||||
|
|
||||||
|
void draw_vline_f(SURFACE *surface, int x, int y1, int y2, uint8 color) {
|
||||||
|
uint8 *p = surface_pointer(surface, x, y1);
|
||||||
int line_inc = surface->width;
|
int line_inc = surface->width;
|
||||||
int lines_left = y2 - y1 + 1;
|
int lines_left = y2 - y1 + 1;
|
||||||
|
|
||||||
extern void draw_line(byte *dest, int color, int line_inc, int lines_left);
|
_draw_vline(p, color, line_inc, lines_left);
|
||||||
#pragma aux draw_line = \
|
|
||||||
" test ecx, ecx" \
|
|
||||||
" jz done" \
|
|
||||||
"draw:" \
|
|
||||||
" mov [edx], al" \
|
|
||||||
" add edx, ebx" \
|
|
||||||
" dec ecx" \
|
|
||||||
" jnz draw" \
|
|
||||||
"done:" \
|
|
||||||
parm [edx] [eax] [ebx] [ecx];
|
|
||||||
draw_line(p, color, line_inc, lines_left);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_line(SURFACE *surface, int x1, int y1, int x2, int y2, int color) {
|
void draw_line(SURFACE *surface, int x1, int y1, int x2, int y2, uint8 color) {
|
||||||
int delta_x, delta_y;
|
int delta_x, delta_y;
|
||||||
int delta_x_abs, delta_y_abs;
|
int delta_x_abs, delta_y_abs;
|
||||||
int delta_x_sign, delta_y_sign;
|
int delta_x_sign, delta_y_sign;
|
||||||
int x, y;
|
int x, y;
|
||||||
byte *p;
|
uint8 *p;
|
||||||
int p_x_inc;
|
int p_x_inc;
|
||||||
int p_y_inc;
|
int p_y_inc;
|
||||||
int i;
|
int i;
|
||||||
|
@ -66,7 +67,7 @@ void surface_line(SURFACE *surface, int x1, int y1, int x2, int y2, int color) {
|
||||||
dy >= clip_y1 &&
|
dy >= clip_y1 &&
|
||||||
dx <= clip_x2 &&
|
dx <= clip_x2 &&
|
||||||
dy <= clip_y2)
|
dy <= clip_y2)
|
||||||
*p = (byte)color;
|
*p = color;
|
||||||
|
|
||||||
if (delta_x_abs >= delta_y_abs) {
|
if (delta_x_abs >= delta_y_abs) {
|
||||||
for (i = 0; i < delta_x_abs; ++i) {
|
for (i = 0; i < delta_x_abs; ++i) {
|
||||||
|
@ -85,7 +86,7 @@ void surface_line(SURFACE *surface, int x1, int y1, int x2, int y2, int color) {
|
||||||
dy >= clip_y1 &&
|
dy >= clip_y1 &&
|
||||||
dx <= clip_x2 &&
|
dx <= clip_x2 &&
|
||||||
dy <= clip_y2)
|
dy <= clip_y2)
|
||||||
*p = (byte)color;
|
*p = color;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < delta_y_abs; ++i) {
|
for (i = 0; i < delta_y_abs; ++i) {
|
||||||
|
@ -104,17 +105,17 @@ void surface_line(SURFACE *surface, int x1, int y1, int x2, int y2, int color) {
|
||||||
dy >= clip_y1 &&
|
dy >= clip_y1 &&
|
||||||
dx <= clip_x2 &&
|
dx <= clip_x2 &&
|
||||||
dy <= clip_y2)
|
dy <= clip_y2)
|
||||||
*p = (byte)color;
|
*p = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_line_f(SURFACE *surface, int x1, int y1, int x2, int y2, int color) {
|
void draw_line_f(SURFACE *surface, int x1, int y1, int x2, int y2, uint8 color) {
|
||||||
int delta_x, delta_y;
|
int delta_x, delta_y;
|
||||||
int delta_x_abs, delta_y_abs;
|
int delta_x_abs, delta_y_abs;
|
||||||
int delta_x_sign, delta_y_sign;
|
int delta_x_sign, delta_y_sign;
|
||||||
int x, y;
|
int x, y;
|
||||||
byte *p;
|
uint8 *p;
|
||||||
int p_x_inc;
|
int p_x_inc;
|
||||||
int p_y_inc;
|
int p_y_inc;
|
||||||
int i;
|
int i;
|
||||||
|
@ -132,7 +133,7 @@ void surface_line_f(SURFACE *surface, int x1, int y1, int x2, int y2, int color)
|
||||||
p_x_inc = delta_x_sign;
|
p_x_inc = delta_x_sign;
|
||||||
p_y_inc = delta_y_sign * surface->width;
|
p_y_inc = delta_y_sign * surface->width;
|
||||||
|
|
||||||
*p = (byte)color;
|
*p = color;
|
||||||
|
|
||||||
if (delta_x_abs >= delta_y_abs) {
|
if (delta_x_abs >= delta_y_abs) {
|
||||||
for (i = 0; i < delta_x_abs; ++i) {
|
for (i = 0; i < delta_x_abs; ++i) {
|
||||||
|
@ -144,7 +145,7 @@ void surface_line_f(SURFACE *surface, int x1, int y1, int x2, int y2, int color)
|
||||||
}
|
}
|
||||||
|
|
||||||
p += p_x_inc;
|
p += p_x_inc;
|
||||||
*p = (byte)color;
|
*p = color;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < delta_y_abs; ++i) {
|
for (i = 0; i < delta_y_abs; ++i) {
|
||||||
|
@ -156,36 +157,47 @@ void surface_line_f(SURFACE *surface, int x1, int y1, int x2, int y2, int color)
|
||||||
}
|
}
|
||||||
|
|
||||||
p += p_y_inc;
|
p += p_y_inc;
|
||||||
*p = (byte)color;
|
*p = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void draw_both_vert_lines(byte *left, byte *right, int color, int y_inc, int height);
|
extern void _draw_both_vert_lines(
|
||||||
#pragma aux draw_both_vert_lines = \
|
uint8 *left,
|
||||||
" inc ecx" \
|
uint8 *right,
|
||||||
"draw:" \
|
uint8 color,
|
||||||
" mov [edi], al" \
|
int y_inc,
|
||||||
" mov [esi], al" \
|
int height
|
||||||
" add edi, edx" \
|
);
|
||||||
" add esi, edx" \
|
#pragma aux _draw_both_vert_lines = \
|
||||||
" dec ecx" \
|
" inc ecx" \
|
||||||
" jnz draw" \
|
"draw:" \
|
||||||
"done:" \
|
" mov [edi], al" \
|
||||||
parm [edi] [esi] [eax] [edx] [ecx];
|
" mov [esi], al" \
|
||||||
|
" add edi, edx" \
|
||||||
|
" add esi, edx" \
|
||||||
|
" dec ecx" \
|
||||||
|
" jnz draw" \
|
||||||
|
"done:" \
|
||||||
|
parm [edi] [esi] [al] [edx] [ecx];
|
||||||
|
|
||||||
extern void draw_vert_line(byte *dest, int color, int y_inc, int height);
|
extern void _draw_vert_line(
|
||||||
#pragma aux draw_vert_line = \
|
uint8 *dest,
|
||||||
" inc ecx" \
|
uint8 color,
|
||||||
"draw:" \
|
int y_inc,
|
||||||
" mov [edi], al" \
|
int height
|
||||||
" add edi, edx" \
|
);
|
||||||
" dec ecx" \
|
#pragma aux _draw_vert_line = \
|
||||||
" jnz draw" \
|
" inc ecx" \
|
||||||
"done:" \
|
"draw:" \
|
||||||
parm [edi] [eax] [edx] [ecx];
|
" mov [edi], al" \
|
||||||
|
" add edi, edx" \
|
||||||
|
" dec ecx" \
|
||||||
|
" jnz draw" \
|
||||||
|
"done:" \
|
||||||
|
parm [edi] [al] [edx] [ecx];
|
||||||
|
|
||||||
void surface_rect(SURFACE *surface, int x1, int y1, int x2, int y2, int color) {
|
void draw_rect(SURFACE *surface, int x1, int y1, int x2, int y2, uint8 color) {
|
||||||
RECT clipped;
|
RECT clipped;
|
||||||
int clipped_x2, clipped_y2;
|
int clipped_x2, clipped_y2;
|
||||||
|
|
||||||
|
@ -204,42 +216,41 @@ void surface_rect(SURFACE *surface, int x1, int y1, int x2, int y2, int color) {
|
||||||
|
|
||||||
clipped_x2 = clipped.x + clipped.width - 1;
|
clipped_x2 = clipped.x + clipped.width - 1;
|
||||||
clipped_y2 = clipped.y + clipped.height - 1;
|
clipped_y2 = clipped.y + clipped.height - 1;
|
||||||
color = fill32(color);
|
|
||||||
|
|
||||||
// top line, only if y1 was within bounds
|
// top line, only if y1 was within bounds
|
||||||
if (y1 == clipped.y) {
|
if (y1 == clipped.y) {
|
||||||
byte *p = surface_pointer(surface, clipped.x, clipped.y);
|
uint8 *p = surface_pointer(surface, clipped.x, clipped.y);
|
||||||
mem_fill32(p, color, clipped.width);
|
mem_fill(p, color, clipped.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bottom line, only if y2 was within bounds
|
// bottom line, only if y2 was within bounds
|
||||||
if (y2 == clipped_y2) {
|
if (y2 == clipped_y2) {
|
||||||
byte *p = surface_pointer(surface, clipped.x, clipped_y2);
|
uint8 *p = surface_pointer(surface, clipped.x, clipped_y2);
|
||||||
mem_fill32(p, color, clipped.width);
|
mem_fill(p, color, clipped.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw both left and right lines if neither x1 nor x2 were clipped
|
// draw both left and right lines if neither x1 nor x2 were clipped
|
||||||
if (x1 == clipped.x && x2 == clipped_x2) {
|
if (x1 == clipped.x && x2 == clipped_x2) {
|
||||||
byte *p1 = surface_pointer(surface, clipped.x, clipped.y);
|
uint8 *p1 = surface_pointer(surface, clipped.x, clipped.y);
|
||||||
byte *p2 = surface_pointer(surface, clipped_x2, clipped.y);
|
uint8 *p2 = surface_pointer(surface, clipped_x2, clipped.y);
|
||||||
draw_both_vert_lines(p1, p2, color, surface->width, clipped.height - 1);
|
_draw_both_vert_lines(p1, p2, color, surface->width, clipped.height - 1);
|
||||||
|
|
||||||
// draw left line if x1 was not clipped
|
// draw left line if x1 was not clipped
|
||||||
} else if (x1 == clipped.x) {
|
} else if (x1 == clipped.x) {
|
||||||
byte *p = surface_pointer(surface, clipped.x, clipped.y);
|
uint8 *p = surface_pointer(surface, clipped.x, clipped.y);
|
||||||
draw_vert_line(p, color, surface->width, clipped.height - 1);
|
_draw_vert_line(p, color, surface->width, clipped.height - 1);
|
||||||
|
|
||||||
// draw right line if x2 was not clipped
|
// draw right line if x2 was not clipped
|
||||||
} else if (x2 == clipped_x2) {
|
} else if (x2 == clipped_x2) {
|
||||||
byte *p = surface_pointer(surface, clipped_x2, clipped.y);
|
uint8 *p = surface_pointer(surface, clipped_x2, clipped.y);
|
||||||
draw_vert_line(p, color, surface->width, clipped.height - 1);
|
_draw_vert_line(p, color, surface->width, clipped.height - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_rect_f(SURFACE *surface, int x1, int y1, int x2, int y2, int color) {
|
void draw_rect_f(SURFACE *surface, int x1, int y1, int x2, int y2, uint8 color) {
|
||||||
byte *p;
|
uint8 *p;
|
||||||
byte *p1;
|
uint8 *p1;
|
||||||
byte *p2;
|
uint8 *p2;
|
||||||
int width = x2 - x1 + 1;
|
int width = x2 - x1 + 1;
|
||||||
int lines_left = y2 - y1;
|
int lines_left = y2 - y1;
|
||||||
int y_inc = surface->width;
|
int y_inc = surface->width;
|
||||||
|
@ -249,15 +260,17 @@ void surface_rect_f(SURFACE *surface, int x1, int y1, int x2, int y2, int color)
|
||||||
p1 = p;
|
p1 = p;
|
||||||
p2 = p + width - 1;
|
p2 = p + width - 1;
|
||||||
|
|
||||||
direct_rect_f(color, width, y_inc, lines_left, p1, p2);
|
lowlevel_rect_f(color, width, y_inc, lines_left, p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_filled_rect(SURFACE *surface,
|
void draw_filled_rect(
|
||||||
int x1,
|
SURFACE *surface,
|
||||||
int y1,
|
int x1,
|
||||||
int x2,
|
int y1,
|
||||||
int y2,
|
int x2,
|
||||||
int color) {
|
int y2,
|
||||||
|
uint8 color
|
||||||
|
) {
|
||||||
if (!clamp_to_region(&surface->clip_region, &x1, &y1, &x2, &y2))
|
if (!clamp_to_region(&surface->clip_region, &x1, &y1, &x2, &y2))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -266,48 +279,54 @@ void surface_filled_rect(SURFACE *surface,
|
||||||
if (y2 < y1)
|
if (y2 < y1)
|
||||||
SWAP(int, y1, y2);
|
SWAP(int, y1, y2);
|
||||||
|
|
||||||
surface_filled_rect_f(surface, x1, y1, x2, y2, color);
|
draw_filled_rect_f(surface, x1, y1, x2, y2, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_filled_rect_f(SURFACE *surface,
|
void draw_filled_rect_f(
|
||||||
int x1,
|
SURFACE *surface,
|
||||||
int y1,
|
int x1,
|
||||||
int x2,
|
int y1,
|
||||||
int y2,
|
int x2,
|
||||||
int color) {
|
int y2,
|
||||||
byte *p;
|
uint8 color
|
||||||
|
) {
|
||||||
|
uint8 *p;
|
||||||
int width = x2 - x1 + 1;
|
int width = x2 - x1 + 1;
|
||||||
int y_inc = surface->width;
|
int y_inc = surface->width;
|
||||||
int lines_left = y2 - y1 + 1;
|
int lines_left = y2 - y1 + 1;
|
||||||
|
|
||||||
p = surface_pointer(surface, x1, y1);
|
p = surface_pointer(surface, x1, y1);
|
||||||
|
|
||||||
direct_filled_rect_f(color, y_inc, width, lines_left, p);
|
lowlevel_filled_rect_f(color, y_inc, width, lines_left, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHAR_WIDTH 8
|
#define CHAR_WIDTH 8
|
||||||
#define CHAR_HEIGHT 8
|
#define CHAR_HEIGHT 8
|
||||||
#define CHAR_LINE_BITMASK(x) (1 << ((CHAR_WIDTH - 1) - (x)))
|
#define CHAR_LINE_BITMASK(x) (1 << ((CHAR_WIDTH - 1) - (x)))
|
||||||
#define IS_CHAR_PIXEL(x, line) ((line) & CHAR_LINE_BITMASK(x))
|
#define IS_CHAR_PIXEL(x, line) ((line) & CHAR_LINE_BITMASK(x))
|
||||||
|
#define BIOS_FONT_ADDR 0xffa6e
|
||||||
|
|
||||||
// dest_x, dest_y - original unclipped render x,y coords
|
// dest_x, dest_y - original unclipped render x,y coords
|
||||||
// dest_clipped - clipped destination render region
|
// dest_clipped - clipped destination render region
|
||||||
static void print_char(SURFACE *surface,
|
// TODO: rewrite this. this function is kinda sloppy...
|
||||||
int dest_x,
|
static void print_char(
|
||||||
int dest_y,
|
SURFACE *surface,
|
||||||
const RECT *dest_clipped,
|
int dest_x,
|
||||||
int color,
|
int dest_y,
|
||||||
char c) {
|
const RECT *dest_clipped,
|
||||||
byte *p;
|
uint8 color,
|
||||||
byte *rom_char;
|
char c
|
||||||
char char_line_bits;
|
) {
|
||||||
|
uint8 *p;
|
||||||
|
uint8 *rom_char;
|
||||||
|
uint8 char_line_bits;
|
||||||
int cx, cy;
|
int cx, cy;
|
||||||
int offset_x, offset_y;
|
int offset_x, offset_y;
|
||||||
int width, height;
|
int width, height;
|
||||||
int y_inc = surface->width;
|
int y_inc = surface->width;
|
||||||
|
|
||||||
p = surface_pointer(surface, dest_clipped->x, dest_clipped->y);
|
p = surface_pointer(surface, dest_clipped->x, dest_clipped->y);
|
||||||
rom_char = ((byte*)0xffa6e) + (c * CHAR_HEIGHT);
|
rom_char = ((uint8*)BIOS_FONT_ADDR) + (c * CHAR_HEIGHT);
|
||||||
|
|
||||||
// get offset x,y to start rendering char from (will be in range 0-7)
|
// get offset x,y to start rendering char from (will be in range 0-7)
|
||||||
offset_x = dest_clipped->x - dest_x;
|
offset_x = dest_clipped->x - dest_x;
|
||||||
|
@ -321,19 +340,21 @@ static void print_char(SURFACE *surface,
|
||||||
|
|
||||||
for (cx = offset_x; cx < width; ++cx) {
|
for (cx = offset_x; cx < width; ++cx) {
|
||||||
if (IS_CHAR_PIXEL(cx, char_line_bits))
|
if (IS_CHAR_PIXEL(cx, char_line_bits))
|
||||||
p[cx - offset_x] = (byte)color;
|
p[cx - offset_x] = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
p += y_inc;
|
p += y_inc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_text(SURFACE *surface,
|
static void print_text(
|
||||||
int x,
|
SURFACE *surface,
|
||||||
int y,
|
int x,
|
||||||
int color,
|
int y,
|
||||||
boolean clip,
|
uint8 color,
|
||||||
const char *text) {
|
bool clip,
|
||||||
|
const char *text
|
||||||
|
) {
|
||||||
const char *c;
|
const char *c;
|
||||||
RECT r;
|
RECT r;
|
||||||
RECT draw_r;
|
RECT draw_r;
|
||||||
|
@ -364,37 +385,43 @@ static void print_text(SURFACE *surface,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_text(SURFACE *surface, int x, int y, int color, const char *text) {
|
void draw_text(SURFACE *surface, int x, int y, uint8 color, const char *text) {
|
||||||
print_text(surface, x, y, color, TRUE, text);
|
print_text(surface, x, y, color, true, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_text_f(SURFACE *surface, int x, int y, int color, const char *text) {
|
void draw_text_f(SURFACE *surface, int x, int y, uint8 color, const char *text) {
|
||||||
print_text(surface, x, y, color, FALSE, text);
|
print_text(surface, x, y, color, false, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_printf(SURFACE *surface,
|
void draw_printf(
|
||||||
int x,
|
SURFACE *surface,
|
||||||
int y,
|
int x,
|
||||||
int color,
|
int y,
|
||||||
const char *format, ...) {
|
uint8 color,
|
||||||
|
const char *format,
|
||||||
|
...
|
||||||
|
) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vsprintf(printf_buffer, format, args);
|
vsprintf(printf_buffer, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
print_text(surface, x, y, color, TRUE, printf_buffer);
|
print_text(surface, x, y, color, true, printf_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_printf_f(SURFACE *surface,
|
void draw_printf_f(
|
||||||
int x,
|
SURFACE *surface,
|
||||||
int y,
|
int x,
|
||||||
int color,
|
int y,
|
||||||
const char *format, ...) {
|
uint8 color,
|
||||||
|
const char *format,
|
||||||
|
...
|
||||||
|
) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vsprintf(printf_buffer, format, args);
|
vsprintf(printf_buffer, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
print_text(surface, x, y, color, FALSE, printf_buffer);
|
print_text(surface, x, y, color, false, printf_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
90
DGLDRAW.H
Normal file → Executable file
90
DGLDRAW.H
Normal file → Executable file
|
@ -1,72 +1,94 @@
|
||||||
#ifndef DGL_DGLDRAW_H_INCLUDED
|
#ifndef LIBDGL_DGLDRAW_H
|
||||||
#define DGL_DGLDRAW_H_INCLUDED
|
#define LIBDGL_DGLDRAW_H
|
||||||
|
|
||||||
#include "dglgfx.h"
|
#include "dglgfx.h"
|
||||||
#include "dglclip.h"
|
#include "dglclip.h"
|
||||||
#include "dglutil.h"
|
#include "dglutil.h"
|
||||||
|
|
||||||
static void surface_pset(SURFACE *surface, int x, int y, int color);
|
#ifdef __cplusplus
|
||||||
static void surface_pset_f(SURFACE *surface, int x, int y, int color);
|
extern "C" {
|
||||||
static int surface_point(const SURFACE *surface, int x, int y);
|
#endif
|
||||||
static int surface_point_f(const SURFACE *surface, int x, int y);
|
|
||||||
|
|
||||||
static void surface_hline(SURFACE *surface, int x1, int x2, int y, int color);
|
static void pset(SURFACE *surface, int x, int y, uint8 color);
|
||||||
void surface_hline_f(SURFACE *surface, int x1, int x2, int y, int color);
|
static void pset_f(SURFACE *surface, int x, int y, uint8 color);
|
||||||
static void surface_vline(SURFACE *surface, int x, int y1, int y2, int color);
|
static uint8 pget(const SURFACE *surface, int x, int y);
|
||||||
void surface_vline_f(SURFACE *surface, int x, int y1, int y2, int color);
|
static uint8 pget_f(const SURFACE *surface, int x, int y);
|
||||||
void surface_line(SURFACE *surface, int x1, int y1, int x2, int y2, int color);
|
|
||||||
void surface_line_f(SURFACE *surface, int x1, int y1, int x2, int y2, int color);
|
|
||||||
|
|
||||||
void surface_rect(SURFACE *surface, int x1, int y1, int x2, int y2, int color);
|
static void draw_hline(SURFACE *surface, int x1, int x2, int y, uint8 color);
|
||||||
void surface_rect_f(SURFACE *surface, int x1, int y1, int x2, int y2, int color);
|
void draw_hline_f(SURFACE *surface, int x1, int x2, int y, uint8 color);
|
||||||
void surface_filled_rect(SURFACE *surface, int x1, int y1, int x2, int y2, int color);
|
static void draw_vline(SURFACE *surface, int x, int y1, int y2, uint8 color);
|
||||||
void surface_filled_rect_f(SURFACE *surface, int x1, int y1, int x2, int y2, int color);
|
void draw_vline_f(SURFACE *surface, int x, int y1, int y2, uint8 color);
|
||||||
|
void draw_line(SURFACE *surface, int x1, int y1, int x2, int y2, uint8 color);
|
||||||
|
void draw_line_f(SURFACE *surface, int x1, int y1, int x2, int y2, uint8 color);
|
||||||
|
|
||||||
void surface_text(SURFACE *surface, int x, int y, int color, const char *text);
|
void draw_rect(SURFACE *surface, int x1, int y1, int x2, int y2, uint8 color);
|
||||||
void surface_text_f(SURFACE *surface, int x, int y, int color, const char *text);
|
void draw_rect_f(SURFACE *surface, int x1, int y1, int x2, int y2, uint8 color);
|
||||||
void surface_printf(SURFACE *surface, int x, int y, int color, const char *format, ...);
|
void draw_filled_rect(SURFACE *surface, int x1, int y1, int x2, int y2, uint8 color);
|
||||||
void surface_printf_f(SURFACE *surface, int x, int y, int color, const char *format, ...);
|
void draw_filled_rect_f(SURFACE *surface, int x1, int y1, int x2, int y2, uint8 color);
|
||||||
|
|
||||||
void direct_rect_f(int color, int width, int y_inc, int lines, byte *p1, byte *p2);
|
void draw_text(SURFACE *surface, int x, int y, uint8 color, const char *text);
|
||||||
void direct_filled_rect_f(int color, int y_inc, int width, int lines, byte *dest);
|
void draw_text_f(SURFACE *surface, int x, int y, uint8 color, const char *text);
|
||||||
|
void draw_printf(SURFACE *surface, int x, int y, uint8 color, const char *format, ...);
|
||||||
|
void draw_printf_f(SURFACE *surface, int x, int y, uint8 color, const char *format, ...);
|
||||||
|
|
||||||
|
void lowlevel_rect_f(
|
||||||
|
uint8 color,
|
||||||
|
int width,
|
||||||
|
int y_inc,
|
||||||
|
int lines,
|
||||||
|
uint8 *p1,
|
||||||
|
uint8 *p2
|
||||||
|
);
|
||||||
|
|
||||||
|
void lowlevel_filled_rect_f(
|
||||||
|
uint8 color,
|
||||||
|
int y_inc,
|
||||||
|
int width,
|
||||||
|
int lines,
|
||||||
|
uint8 *dest
|
||||||
|
);
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
static void surface_pset(SURFACE *surface, int x, int y, int color) {
|
static void pset(SURFACE *surface, int x, int y, uint8 color) {
|
||||||
if (is_point_in_bounds(&surface->clip_region, x, y))
|
if (is_point_in_bounds(&surface->clip_region, x, y))
|
||||||
surface_pset_f(surface, x, y, color);
|
pset_f(surface, x, y, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void surface_pset_f(SURFACE *surface, int x, int y, int color) {
|
static void pset_f(SURFACE *surface, int x, int y, uint8 color) {
|
||||||
int offset = surface_offset(surface, x, y);
|
uint32 offset = surface_offset(surface, x, y);
|
||||||
surface->pixels[offset] = color;
|
surface->pixels[offset] = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int surface_point(const SURFACE *surface, int x, int y) {
|
static uint8 pget(const SURFACE *surface, int x, int y) {
|
||||||
if (is_point_in_bounds(&surface->clip_region, x, y))
|
if (is_point_in_bounds(&surface->clip_region, x, y))
|
||||||
return surface_point_f(surface, x, y);
|
return pget_f(surface, x, y);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int surface_point_f(const SURFACE *surface, int x, int y) {
|
static uint8 pget_f(const SURFACE *surface, int x, int y) {
|
||||||
int offset = surface_offset(surface, x, y);
|
uint32 offset = surface_offset(surface, x, y);
|
||||||
return surface->pixels[offset];
|
return surface->pixels[offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void surface_hline(SURFACE *surface, int x1, int x2, int y, int color) {
|
static void draw_hline(SURFACE *surface, int x1, int x2, int y, uint8 color) {
|
||||||
if (x2 < x1)
|
if (x2 < x1)
|
||||||
SWAP(int, x1, x2);
|
SWAP(int, x1, x2);
|
||||||
if (clamp_to_region(&surface->clip_region, &x1, &y, &x2, &y))
|
if (clamp_to_region(&surface->clip_region, &x1, &y, &x2, &y))
|
||||||
surface_hline_f(surface, x1, x2, y, color);
|
draw_hline_f(surface, x1, x2, y, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void surface_vline(SURFACE *surface, int x, int y1, int y2, int color) {
|
static void draw_vline(SURFACE *surface, int x, int y1, int y2, uint8 color) {
|
||||||
if (y2 < y1)
|
if (y2 < y1)
|
||||||
SWAP(int, y1, y2);
|
SWAP(int, y1, y2);
|
||||||
if (clamp_to_region(&surface->clip_region, &x, &y1, &x, &y2))
|
if (clamp_to_region(&surface->clip_region, &x, &y1, &x, &y2))
|
||||||
surface_vline_f(surface, x, y1, y2, color);
|
draw_vline_f(surface, x, y1, y2, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
15
DGLDRAWA.ASM
Normal file → Executable file
15
DGLDRAWA.ASM
Normal file → Executable file
|
@ -7,18 +7,18 @@ codeseg
|
||||||
|
|
||||||
locals
|
locals
|
||||||
|
|
||||||
public direct_rect_f_
|
public lowlevel_rect_f_
|
||||||
public direct_filled_rect_f_
|
public lowlevel_filled_rect_f_
|
||||||
|
|
||||||
|
|
||||||
; direct_rect_f_
|
; lowlevel_rect_f_
|
||||||
; eax = color
|
; eax = color
|
||||||
; edx = width
|
; edx = width
|
||||||
; ebx = y_inc
|
; ebx = y_inc
|
||||||
; ecx = lines
|
; ecx = lines
|
||||||
; ebp+8 = p1
|
; ebp+8 = p1
|
||||||
; ebp+12 = p2
|
; ebp+12 = p2
|
||||||
proc direct_rect_f_ near
|
proc lowlevel_rect_f_ near
|
||||||
arg @@p1:dword, @@p2:dword
|
arg @@p1:dword, @@p2:dword
|
||||||
|
|
||||||
push ebp
|
push ebp
|
||||||
|
@ -82,13 +82,13 @@ arg @@p1:dword, @@p2:dword
|
||||||
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
; direct_filled_rect_f_
|
; lowlevel_filled_rect_f_
|
||||||
; eax = color
|
; eax = color
|
||||||
; edx = y_inc
|
; edx = y_inc
|
||||||
; ebx = width
|
; ebx = width
|
||||||
; ecx = lines
|
; ecx = lines
|
||||||
; ebp+8 = dest
|
; ebp+8 = dest
|
||||||
proc direct_filled_rect_f_ near
|
proc lowlevel_filled_rect_f_ near
|
||||||
arg @@dest:dword
|
arg @@dest:dword
|
||||||
|
|
||||||
push ebp
|
push ebp
|
||||||
|
@ -98,7 +98,7 @@ arg @@dest:dword
|
||||||
|
|
||||||
mov esi, ecx ; get number of lines to be drawn
|
mov esi, ecx ; get number of lines to be drawn
|
||||||
test esi, esi ; if there are no lines to draw, then return
|
test esi, esi ; if there are no lines to draw, then return
|
||||||
jz @@done
|
jz @@early_done
|
||||||
|
|
||||||
mov ah, al ; spread color byte out over all 32-bits
|
mov ah, al ; spread color byte out over all 32-bits
|
||||||
shl eax, 8 ; so 4 pixels can be written horizontally
|
shl eax, 8 ; so 4 pixels can be written horizontally
|
||||||
|
@ -148,6 +148,7 @@ arg @@dest:dword
|
||||||
|
|
||||||
@@done:
|
@@done:
|
||||||
pop ebp
|
pop ebp
|
||||||
|
@@early_done:
|
||||||
pop esi
|
pop esi
|
||||||
pop edi
|
pop edi
|
||||||
pop ebp
|
pop ebp
|
||||||
|
|
32
DGLERROR.H
32
DGLERROR.H
|
@ -1,32 +0,0 @@
|
||||||
#ifndef DGL_DGLERROR_H_INCLUDED
|
|
||||||
#define DGL_DGLERROR_H_INCLUDED
|
|
||||||
|
|
||||||
#include "dglcmn.h"
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
DGL_NONE = 0,
|
|
||||||
DGL_ALREADY_INIT,
|
|
||||||
DGL_NEARPTR_ENABLE_FAILURE,
|
|
||||||
DGL_VIDEO_ALREADY_INITIALIZED,
|
|
||||||
DGL_VIDEO_MODE_13H_INIT_FAILURE,
|
|
||||||
DGL_VIDEO_TEXT_MODE_INIT_FAILURE,
|
|
||||||
DGL_KEYBOARD_ALREADY_INITIALIZED,
|
|
||||||
DGL_KEYBOARD_IRQ_INSTALL_FAILURE,
|
|
||||||
DGL_KEYBOARD_IRQ_RESTORE_FAILURE,
|
|
||||||
DGL_KEYBOARD_UPDATE_LED_FAILURE,
|
|
||||||
DGL_MOUSE_ALREADY_INITIALIZED,
|
|
||||||
DGL_MOUSE_ALLOCATE_CALLBACK_FAILURE,
|
|
||||||
DGL_MOUSE_FREE_CALLBACK_FAILURE,
|
|
||||||
DGL_MOUSE_INT_CALLBACK_SET_FAILURE,
|
|
||||||
DGL_MOUSE_INT_CALLBACK_RESTORE_FAILURE,
|
|
||||||
DGL_EVENTS_ALREADY_INITIALIZED,
|
|
||||||
DGL_IO_ERROR,
|
|
||||||
DGL_PCX_BAD_FORMAT
|
|
||||||
} DGL_ERROR;
|
|
||||||
|
|
||||||
DGL_ERROR dgl_last_error(void);
|
|
||||||
const char* dgl_last_error_message(void);
|
|
||||||
void dgl_set_error(DGL_ERROR error);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
38
DGLEVENT.C
Normal file → Executable file
38
DGLEVENT.C
Normal file → Executable file
|
@ -1,39 +1,39 @@
|
||||||
#include "dglevent.h"
|
#include "dglevent.h"
|
||||||
#include "dglerror.h"
|
#include "dgl.h"
|
||||||
#include "dglutil.h"
|
#include "dglutil.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
volatile boolean _events_enabled;
|
volatile bool _events_enabled = false;
|
||||||
|
|
||||||
volatile INPUTEVENT _events_buffer[EVENTS_BUFFER_SIZE];
|
volatile INPUTEVENT _events_buffer[EVENTS_BUFFER_SIZE];
|
||||||
volatile int _events_buffer_start = 0;
|
volatile int _events_buffer_start = 0;
|
||||||
volatile int _events_buffer_end = 0;
|
volatile int _events_buffer_end = 0;
|
||||||
|
|
||||||
boolean events_init(void) {
|
bool events_init(void) {
|
||||||
if (_events_enabled) {
|
if (_events_enabled) {
|
||||||
dgl_set_error(DGL_EVENTS_ALREADY_INITIALIZED);
|
dgl_set_error(DGL_EVENTS_ALREADY_INITIALIZED);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
events_clear();
|
events_clear();
|
||||||
_events_enabled = TRUE;
|
_events_enabled = true;
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean events_shutdown(void) {
|
bool events_shutdown(void) {
|
||||||
if (!_events_enabled)
|
if (!_events_enabled)
|
||||||
return TRUE; // don't care
|
return true; // don't care
|
||||||
|
|
||||||
_events_enabled = FALSE;
|
_events_enabled = false;
|
||||||
events_clear();
|
events_clear();
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean events_poll(INPUTEVENT **event) {
|
bool events_poll(volatile INPUTEVENT **event) {
|
||||||
if (events_is_empty())
|
if (events_is_empty())
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
int_disable();
|
int_disable();
|
||||||
|
|
||||||
|
@ -45,22 +45,26 @@ boolean events_poll(INPUTEVENT **event) {
|
||||||
|
|
||||||
int_enable();
|
int_enable();
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean events_peek(INPUTEVENT **event) {
|
bool events_peek(volatile INPUTEVENT **event) {
|
||||||
if (events_is_empty())
|
if (events_is_empty())
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
|
int_disable();
|
||||||
|
|
||||||
*event = &_events_buffer[_events_buffer_start];
|
*event = &_events_buffer[_events_buffer_start];
|
||||||
|
|
||||||
return TRUE;
|
int_enable();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void events_clear(void) {
|
void events_clear(void) {
|
||||||
int_disable();
|
int_disable();
|
||||||
|
|
||||||
memset(_events_buffer, 0, sizeof(_events_buffer));
|
memset((void*)_events_buffer, 0, sizeof(_events_buffer));
|
||||||
_events_buffer_start = 0;
|
_events_buffer_start = 0;
|
||||||
_events_buffer_end = 0;
|
_events_buffer_end = 0;
|
||||||
|
|
||||||
|
|
97
DGLEVENT.H
Normal file → Executable file
97
DGLEVENT.H
Normal file → Executable file
|
@ -1,39 +1,43 @@
|
||||||
#ifndef DGL_DGLEVENT_H_INCLUDED
|
#ifndef LIBDGL_DGLEVENT_H
|
||||||
#define DGL_DGLEVENT_H_INCLUDED
|
#define LIBDGL_DGLEVENT_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
#include "dglkbrd.h"
|
#include "dglkbrd.h"
|
||||||
#include "dglmouse.h"
|
#include "dglmouse.h"
|
||||||
|
|
||||||
typedef byte EVENT_TYPE;
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef uint8 EVENT_TYPE;
|
||||||
|
|
||||||
#define EVENT_TYPE_KEYBOARD 1
|
#define EVENT_TYPE_KEYBOARD 1
|
||||||
#define EVENT_TYPE_MOUSE_MOTION 2
|
#define EVENT_TYPE_MOUSE_MOTION 2
|
||||||
#define EVENT_TYPE_MOUSE_BUTTON 3
|
#define EVENT_TYPE_MOUSE_BUTTON 3
|
||||||
|
|
||||||
typedef byte EVENT_ACTION;
|
typedef uint8 EVENT_ACTION;
|
||||||
|
|
||||||
#define EVENT_ACTION_PRESSED 1
|
#define EVENT_ACTION_PRESSED 1
|
||||||
#define EVENT_ACTION_RELEASED 2
|
#define EVENT_ACTION_RELEASED 2
|
||||||
#define EVENT_ACTION_HELD 3
|
#define EVENT_ACTION_HELD 3
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
KEY key;
|
KEY key;
|
||||||
EVENT_ACTION action;
|
EVENT_ACTION action;
|
||||||
uword mod;
|
uint16 mod;
|
||||||
} INPUTEVENT_KEYBOARD;
|
} INPUTEVENT_KEYBOARD;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int x_delta;
|
int x_delta;
|
||||||
int y_delta;
|
int y_delta;
|
||||||
MOUSE_BUTTON buttons;
|
MOUSE_BUTTON buttons;
|
||||||
} INPUTEVENT_MOUSE_MOTION;
|
} INPUTEVENT_MOUSE_MOTION;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
MOUSE_BUTTON button;
|
MOUSE_BUTTON button;
|
||||||
EVENT_ACTION action;
|
EVENT_ACTION action;
|
||||||
} INPUTEVENT_MOUSE_BUTTON;
|
} INPUTEVENT_MOUSE_BUTTON;
|
||||||
|
@ -41,13 +45,13 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
EVENT_TYPE type;
|
EVENT_TYPE type;
|
||||||
union {
|
union {
|
||||||
INPUTEVENT_KEYBOARD keyboard;
|
INPUTEVENT_KEYBOARD keyboard;
|
||||||
INPUTEVENT_MOUSE_MOTION mouse_motion;
|
INPUTEVENT_MOUSE_MOTION mouse_motion;
|
||||||
INPUTEVENT_MOUSE_BUTTON mouse_button;
|
INPUTEVENT_MOUSE_BUTTON mouse_button;
|
||||||
};
|
};
|
||||||
} INPUTEVENT;
|
} INPUTEVENT;
|
||||||
|
|
||||||
extern volatile boolean _events_enabled;
|
extern volatile bool _events_enabled;
|
||||||
|
|
||||||
#define EVENTS_BUFFER_SIZE 32
|
#define EVENTS_BUFFER_SIZE 32
|
||||||
|
|
||||||
|
@ -55,33 +59,76 @@ extern volatile INPUTEVENT _events_buffer[EVENTS_BUFFER_SIZE];
|
||||||
extern volatile int _events_buffer_start;
|
extern volatile int _events_buffer_start;
|
||||||
extern volatile int _events_buffer_end;
|
extern volatile int _events_buffer_end;
|
||||||
|
|
||||||
boolean events_init(void);
|
bool events_init(void);
|
||||||
boolean events_shutdown(void);
|
bool events_shutdown(void);
|
||||||
static boolean events_is_initialized(void);
|
static bool events_is_initialized(void);
|
||||||
|
|
||||||
static boolean events_is_empty(void);
|
static bool events_is_empty(void);
|
||||||
|
|
||||||
boolean events_poll(INPUTEVENT **event);
|
bool events_poll(volatile INPUTEVENT **event);
|
||||||
boolean events_peek(INPUTEVENT **event);
|
bool events_peek(volatile INPUTEVENT **event);
|
||||||
|
|
||||||
void events_clear(void);
|
void events_clear(void);
|
||||||
|
|
||||||
|
static bool events_key_pressed(INPUTEVENT *event, KEY key);
|
||||||
|
static bool events_key_released(INPUTEVENT *event, KEY key);
|
||||||
|
static bool events_key_held(INPUTEVENT *event, KEY key);
|
||||||
|
static bool events_mouse_pressed(INPUTEVENT *event, MOUSE_BUTTON button);
|
||||||
|
static bool events_mouse_released(INPUTEVENT *event, MOUSE_BUTTON button);
|
||||||
|
static bool events_mouse_held(INPUTEVENT *event, MOUSE_BUTTON button);
|
||||||
|
|
||||||
static void _events_push(INPUTEVENT **out_event);
|
static void _events_push(INPUTEVENT **out_event);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
static boolean events_is_initialized(void) {
|
static bool events_is_initialized(void) {
|
||||||
return _events_enabled;
|
return _events_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean events_is_empty(void) {
|
static bool events_is_empty(void) {
|
||||||
return (_events_buffer_start == _events_buffer_end);
|
return (_events_buffer_start == _events_buffer_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool events_key_pressed(INPUTEVENT *event, KEY key) {
|
||||||
|
return event->type == EVENT_TYPE_KEYBOARD &&
|
||||||
|
event->keyboard.action == EVENT_ACTION_PRESSED &&
|
||||||
|
event->keyboard.key == key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool events_key_released(INPUTEVENT *event, KEY key) {
|
||||||
|
return event->type == EVENT_TYPE_KEYBOARD &&
|
||||||
|
event->keyboard.action == EVENT_ACTION_RELEASED &&
|
||||||
|
event->keyboard.key == key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool events_key_held(INPUTEVENT *event, KEY key) {
|
||||||
|
return event->type == EVENT_TYPE_KEYBOARD &&
|
||||||
|
event->keyboard.action == EVENT_ACTION_HELD &&
|
||||||
|
event->keyboard.key == key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool events_mouse_pressed(INPUTEVENT *event, MOUSE_BUTTON button) {
|
||||||
|
return event->type == EVENT_TYPE_MOUSE_BUTTON &&
|
||||||
|
event->mouse_button.action == EVENT_ACTION_PRESSED &&
|
||||||
|
event->mouse_button.button == button;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool events_mouse_released(INPUTEVENT *event, MOUSE_BUTTON button) {
|
||||||
|
return event->type == EVENT_TYPE_MOUSE_BUTTON &&
|
||||||
|
event->mouse_button.action == EVENT_ACTION_RELEASED &&
|
||||||
|
event->mouse_button.button == button;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool events_mouse_held(INPUTEVENT *event, MOUSE_BUTTON button) {
|
||||||
|
return event->type == EVENT_TYPE_MOUSE_BUTTON &&
|
||||||
|
event->mouse_button.action == EVENT_ACTION_HELD &&
|
||||||
|
event->mouse_button.button == button;
|
||||||
|
}
|
||||||
|
|
||||||
// only intended to be called from input device interrupt handler (the
|
// only intended to be called from input device interrupt handler (the
|
||||||
// usage is a little weird as a result)
|
// usage is a little weird as a result)
|
||||||
static void _events_push(INPUTEVENT **out_event) {
|
static void _events_push(INPUTEVENT **out_event) {
|
||||||
*out_event = &_events_buffer[_events_buffer_end];
|
*out_event = (INPUTEVENT*)&_events_buffer[_events_buffer_end];
|
||||||
|
|
||||||
++_events_buffer_end;
|
++_events_buffer_end;
|
||||||
|
|
||||||
|
@ -99,5 +146,9 @@ static void _events_push(INPUTEVENT **out_event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
19
DGLFIXP.C
Normal file → Executable file
19
DGLFIXP.C
Normal file → Executable file
|
@ -1,7 +1,7 @@
|
||||||
#include "dglfixp.h"
|
#include "dglfixp.h"
|
||||||
|
|
||||||
fixed fix_sqrt(fixed x) {
|
fixed fix_sqrt(fixed x) {
|
||||||
int t, q, b, r;
|
int32 t, q, b, r;
|
||||||
r = x;
|
r = x;
|
||||||
b = 0x40000000;
|
b = 0x40000000;
|
||||||
q = 0;
|
q = 0;
|
||||||
|
@ -18,3 +18,20 @@ fixed fix_sqrt(fixed x) {
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fixed fix_atan2(fixed y, fixed x) {
|
||||||
|
fixed absY, mask, angle, r, r3;
|
||||||
|
|
||||||
|
mask = (y >> (sizeof(fixed)*8-1));
|
||||||
|
absY = (y + mask) ^ mask;
|
||||||
|
|
||||||
|
if (x >= 0) {
|
||||||
|
r = fix_div(x - absY, x + absY);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
r = fix_div(x + absY, absY - x);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
17
DGLFIXP.H
Normal file → Executable file
17
DGLFIXP.H
Normal file → Executable file
|
@ -1,10 +1,14 @@
|
||||||
#ifndef DGL_DGLFIXP_H_INCLUDED
|
#ifndef LIBDGL_DGLFIXP_H
|
||||||
#define DGL_DGLFIXP_H_INCLUDED
|
#define LIBDGL_DGLFIXP_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
typedef int fixed;
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int32 fixed;
|
||||||
|
|
||||||
#define FP_INT_SHIFT 16
|
#define FP_INT_SHIFT 16
|
||||||
#define FP_FLOAT_SHIFT 65536.0f
|
#define FP_FLOAT_SHIFT 65536.0f
|
||||||
|
@ -14,6 +18,7 @@ static fixed fix_cos(fixed x);
|
||||||
static fixed fix_tan(fixed x);
|
static fixed fix_tan(fixed x);
|
||||||
|
|
||||||
fixed fix_sqrt(fixed x);
|
fixed fix_sqrt(fixed x);
|
||||||
|
fixed fix_atan2(fixed y, fixed x);
|
||||||
|
|
||||||
fixed fix_mul(fixed a, fixed b);
|
fixed fix_mul(fixed a, fixed b);
|
||||||
#pragma aux fix_mul = \
|
#pragma aux fix_mul = \
|
||||||
|
@ -34,7 +39,7 @@ fixed fix_div(fixed a, fixed b);
|
||||||
#define FTOFIX(f) ((fixed)((f) * FP_FLOAT_SHIFT))
|
#define FTOFIX(f) ((fixed)((f) * FP_FLOAT_SHIFT))
|
||||||
#define ITOFIX(i) ((fixed)((i) << FP_INT_SHIFT))
|
#define ITOFIX(i) ((fixed)((i) << FP_INT_SHIFT))
|
||||||
#define FIXTOF(x) ((float)((x) / FP_FLOAT_SHIFT))
|
#define FIXTOF(x) ((float)((x) / FP_FLOAT_SHIFT))
|
||||||
#define FIXTOI(x) ((int)(((x) + 0x8000) >> FP_INT_SHIFT))
|
#define FIXTOI(x) ((int32)(((x) + 0x8000) >> FP_INT_SHIFT))
|
||||||
|
|
||||||
#define FP_1 ITOFIX(1)
|
#define FP_1 ITOFIX(1)
|
||||||
#define FP_2 ITOFIX(2)
|
#define FP_2 ITOFIX(2)
|
||||||
|
@ -85,5 +90,9 @@ static fixed fix_tan(fixed x) {
|
||||||
return FTOFIX(tan(FIXTOF(x)));
|
return FTOFIX(tan(FIXTOF(x)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
50
DGLGFX.C
Normal file → Executable file
50
DGLGFX.C
Normal file → Executable file
|
@ -1,20 +1,21 @@
|
||||||
|
#include "dgl.h"
|
||||||
#include "dglgfx.h"
|
#include "dglgfx.h"
|
||||||
#include "dglblit.h"
|
#include "dglblit.h"
|
||||||
#include "dglutil.h"
|
#include "dglutil.h"
|
||||||
#include "dglerror.h"
|
#include <conio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
extern void _video_mode(int mode);
|
extern void set_video_mode(int mode);
|
||||||
#pragma aux _video_mode = \
|
#pragma aux set_video_mode = \
|
||||||
"int 0x10" \
|
"int 0x10" \
|
||||||
parm [eax];
|
parm [eax];
|
||||||
|
|
||||||
static boolean _initialized = FALSE;
|
static bool _initialized = false;
|
||||||
|
|
||||||
SURFACE *screen = NULL;
|
SURFACE *screen = NULL;
|
||||||
|
|
||||||
static SURFACE* surface_create_internal(int width, int height, byte *pixels) {
|
static SURFACE* surface_create_internal(int width, int height, uint8 *pixels) {
|
||||||
SURFACE *surface = (SURFACE*)malloc(sizeof(SURFACE));
|
SURFACE *surface = (SURFACE*)malloc(sizeof(SURFACE));
|
||||||
|
|
||||||
surface->width = width;
|
surface->width = width;
|
||||||
|
@ -27,49 +28,47 @@ static SURFACE* surface_create_internal(int width, int height, byte *pixels) {
|
||||||
surface->pixels = pixels;
|
surface->pixels = pixels;
|
||||||
} else {
|
} else {
|
||||||
int size = width * height;
|
int size = width * height;
|
||||||
surface->pixels = (byte*)malloc(size);
|
surface->pixels = (uint8*)malloc(size);
|
||||||
mem_fill(surface->pixels, 0, size);
|
mem_fill(surface->pixels, 0, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean video_init(void) {
|
bool gfx_init(void) {
|
||||||
byte *framebuffer;
|
|
||||||
|
|
||||||
if (_initialized) {
|
if (_initialized) {
|
||||||
dgl_set_error(DGL_VIDEO_ALREADY_INITIALIZED);
|
dgl_set_error(DGL_VIDEO_ALREADY_INITIALIZED);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_video_mode(0x13);
|
set_video_mode(0x13);
|
||||||
|
|
||||||
framebuffer = (byte*)0xa0000;
|
screen = surface_create_internal(320, 200, (uint8*)0xa0000);
|
||||||
screen = surface_create_internal(320, 200, framebuffer);
|
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
_initialized = TRUE;
|
_initialized = true;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean video_shutdown(void) {
|
bool gfx_shutdown(void) {
|
||||||
if (!_initialized)
|
if (!_initialized)
|
||||||
return TRUE; // don't care
|
return true; // don't care
|
||||||
|
|
||||||
_video_mode(0x03);
|
set_video_mode(0x03);
|
||||||
|
|
||||||
surface_free(screen);
|
surface_free(screen);
|
||||||
screen = NULL;
|
screen = NULL;
|
||||||
|
|
||||||
_initialized = FALSE;
|
_initialized = false;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean video_is_initialized(void) {
|
bool gfx_is_initialized(void) {
|
||||||
return _initialized;
|
return _initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
void video_wait_vsync(void) {
|
void wait_vsync(void) {
|
||||||
do {} while (inp(0x3da) & 0x8);
|
do {} while (inp(0x3da) & 0x8);
|
||||||
do {} while (!(inp(0x3da) & 0x8));
|
do {} while (!(inp(0x3da) & 0x8));
|
||||||
}
|
}
|
||||||
|
@ -84,12 +83,13 @@ void surface_free(SURFACE *surface) {
|
||||||
|
|
||||||
if (!BIT_ISSET(SURFACE_FLAGS_ALIASED, surface->flags))
|
if (!BIT_ISSET(SURFACE_FLAGS_ALIASED, surface->flags))
|
||||||
free(surface->pixels);
|
free(surface->pixels);
|
||||||
|
|
||||||
free(surface);
|
free(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_clear(SURFACE *surface, int color) {
|
void surface_clear(SURFACE *surface, uint8 color) {
|
||||||
int length = surface->width * surface->height;
|
int length = surface->width * surface->height;
|
||||||
mem_fill(surface->pixels, (byte)color, length);
|
mem_fill(surface->pixels, color, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void surface_copy(const SURFACE *src, SURFACE *dest) {
|
void surface_copy(const SURFACE *src, SURFACE *dest) {
|
||||||
|
@ -97,7 +97,7 @@ void surface_copy(const SURFACE *src, SURFACE *dest) {
|
||||||
int length = src->width * src->height;
|
int length = src->width * src->height;
|
||||||
mem_copy(dest->pixels, src->pixels, length);
|
mem_copy(dest->pixels, src->pixels, length);
|
||||||
} else {
|
} else {
|
||||||
surface_blit(src, dest, 0, 0);
|
blit(src, dest, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
40
DGLGFX.H
Normal file → Executable file
40
DGLGFX.H
Normal file → Executable file
|
@ -1,44 +1,52 @@
|
||||||
#ifndef DGL_DGLGFX_H_INCLUDED
|
#ifndef LIBDGL_DGLGFX_H
|
||||||
#define DGL_DGLGFX_H_INCLUDED
|
#define LIBDGL_DGLGFX_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
#include "dglrect.h"
|
#include "dglrect.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
byte *pixels;
|
uint8 *pixels;
|
||||||
RECT clip_region;
|
RECT clip_region;
|
||||||
unsigned int flags;
|
uint32 flags;
|
||||||
} SURFACE;
|
} SURFACE;
|
||||||
|
|
||||||
#define SURFACE_FLAGS_ALIASED BIT_0
|
#define SURFACE_FLAGS_ALIASED BIT_0
|
||||||
|
|
||||||
extern SURFACE *screen;
|
extern SURFACE *screen;
|
||||||
|
|
||||||
boolean video_init(void);
|
bool gfx_init(void);
|
||||||
boolean video_shutdown(void);
|
bool gfx_shutdown(void);
|
||||||
boolean video_is_initialized(void);
|
bool gfx_is_initialized(void);
|
||||||
|
|
||||||
void video_wait_vsync(void);
|
void wait_vsync(void);
|
||||||
|
|
||||||
SURFACE* surface_create(int width, int height);
|
SURFACE* surface_create(int width, int height);
|
||||||
void surface_free(SURFACE *surface);
|
void surface_free(SURFACE *surface);
|
||||||
void surface_clear(SURFACE *surface, int color);
|
void surface_clear(SURFACE *surface, uint8 color);
|
||||||
void surface_copy(const SURFACE *src, SURFACE *dest);
|
void surface_copy(const SURFACE *src, SURFACE *dest);
|
||||||
|
|
||||||
static int surface_offset(const SURFACE *surface, int x, int y);
|
static int32 surface_offset(const SURFACE *surface, int x, int y);
|
||||||
static byte* surface_pointer(const SURFACE *surface, int x, int y);
|
static uint8* surface_pointer(const SURFACE *surface, int x, int y);
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
static int surface_offset(const SURFACE *surface, int x, int y) {
|
static int32 surface_offset(const SURFACE *surface, int x, int y) {
|
||||||
return (surface->width * y) + x;
|
return (surface->width * y) + x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte* surface_pointer(const SURFACE *surface, int x, int y) {
|
static uint8* surface_pointer(const SURFACE *surface, int x, int y) {
|
||||||
return surface->pixels + surface_offset(surface, x, y);
|
return surface->pixels + surface_offset(surface, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
65
DGLKBRD.C
Normal file → Executable file
65
DGLKBRD.C
Normal file → Executable file
|
@ -1,10 +1,11 @@
|
||||||
#include "dglkbrd.h"
|
#include "dglkbrd.h"
|
||||||
|
#include "dgl.h"
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
#include "dglevent.h"
|
#include "dglevent.h"
|
||||||
#include "dglutil.h"
|
#include "dglutil.h"
|
||||||
#include "dglerror.h"
|
#include <conio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <dos.h>
|
#include <dos.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define PIC_CTRL_PORT 0x20
|
#define PIC_CTRL_PORT 0x20
|
||||||
#define KEYBRD_DATA_PORT 0x60
|
#define KEYBRD_DATA_PORT 0x60
|
||||||
|
@ -21,15 +22,15 @@
|
||||||
|
|
||||||
#define KEY_EXTENDED ((KEY)0xe0)
|
#define KEY_EXTENDED ((KEY)0xe0)
|
||||||
|
|
||||||
static boolean _installed = FALSE;
|
static bool _installed = false;
|
||||||
static INPUTEVENT *keyboard_event;
|
static INPUTEVENT *keyboard_event;
|
||||||
|
|
||||||
volatile ubyte keys[128];
|
volatile uint8 keys[128];
|
||||||
|
|
||||||
volatile KEY _key_last_scan;
|
volatile KEY _key_last_scan;
|
||||||
volatile KEY _key_scan;
|
volatile KEY _key_scan;
|
||||||
volatile uword key_flags;
|
volatile uint16 key_flags;
|
||||||
volatile uword key_mod;
|
volatile uint16 key_mod;
|
||||||
|
|
||||||
static char lookup_key_to_char[128] = {
|
static char lookup_key_to_char[128] = {
|
||||||
0, 0, '1', '2', '3', '4', '5', '6', // 00 - 07
|
0, 0, '1', '2', '3', '4', '5', '6', // 00 - 07
|
||||||
|
@ -189,9 +190,9 @@ static void wait_kb_data_write() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// sends data to the keyboard data port. checks for success
|
// sends data to the keyboard data port. checks for success
|
||||||
// and returns TRUE if the data write succeeded
|
// and returns true if the data write succeeded
|
||||||
static boolean send_kb_data(ubyte data) {
|
static bool send_kb_data(uint8 data) {
|
||||||
ubyte result;
|
uint8 result;
|
||||||
|
|
||||||
wait_kb_data_write();
|
wait_kb_data_write();
|
||||||
outp(KEYBRD_DATA_PORT, data);
|
outp(KEYBRD_DATA_PORT, data);
|
||||||
|
@ -201,28 +202,28 @@ static boolean send_kb_data(ubyte data) {
|
||||||
return (result == 0xFA);
|
return (result == 0xFA);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uword get_kb_flags(void) {
|
static uint16 get_kb_flags(void) {
|
||||||
return *((uword*)KEYBRD_FLAGS_ADDR);
|
return *((uint16*)KEYBRD_FLAGS_ADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_kb_flags(uword flags) {
|
static void set_kb_flags(uint16 flags) {
|
||||||
*((uword*)KEYBRD_FLAGS_ADDR) = flags;
|
*((uint16*)KEYBRD_FLAGS_ADDR) = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
// updates the keyboard indicator LEDs from the num/caps/scroll lock flags
|
// updates the keyboard indicator LEDs from the num/caps/scroll lock flags
|
||||||
// set in the passed keyboard flags. returns FALSE if the LEDs could not
|
// set in the passed keyboard flags. returns FALSE if the LEDs could not
|
||||||
// be updated (if keyboard data write did not succeed)
|
// be updated (if keyboard data write did not succeed)
|
||||||
static boolean update_kb_led(byte flags) {
|
static bool update_kb_led(uint8 flags) {
|
||||||
if (!send_kb_data(KEYBRD_CMD_SET_LED)) {
|
if (!send_kb_data(KEYBRD_CMD_SET_LED)) {
|
||||||
dgl_set_error(DGL_KEYBOARD_UPDATE_LED_FAILURE);
|
dgl_set_error(DGL_KEYBOARD_UPDATE_LED_FAILURE);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
if (!send_kb_data((flags >> 4) & 3)) {
|
if (!send_kb_data((flags >> 4) & 3)) {
|
||||||
dgl_set_error(DGL_KEYBOARD_UPDATE_LED_FAILURE);
|
dgl_set_error(DGL_KEYBOARD_UPDATE_LED_FAILURE);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void push_keyboard_event(KEY key, EVENT_ACTION action) {
|
static void push_keyboard_event(KEY key, EVENT_ACTION action) {
|
||||||
|
@ -235,16 +236,16 @@ static void push_keyboard_event(KEY key, EVENT_ACTION action) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns TRUE if the key interrupt event should not be handled (at least
|
// returns true if the key interrupt event should not be handled (at least
|
||||||
// as far as updating key state is concerned)
|
// as far as updating key state is concerned)
|
||||||
static boolean handler_filter_keys(void) {
|
static bool handler_filter_keys(void) {
|
||||||
if (BIT_ISSET(KEYBRD_MOD_EXTENDED, key_mod)) {
|
if (BIT_ISSET(KEYBRD_MOD_EXTENDED, key_mod)) {
|
||||||
// extended key + leftshift comes with cursor key presses when
|
// extended key + leftshift comes with cursor key presses when
|
||||||
// numlock is enabled
|
// numlock is enabled
|
||||||
if ((_key_scan & 0x7f) == KEY_LEFTSHIFT)
|
if ((_key_scan & 0x7f) == KEY_LEFTSHIFT)
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// maintains BIOS keyboard flags/led toggle states (caps/num/scroll lock)
|
// maintains BIOS keyboard flags/led toggle states (caps/num/scroll lock)
|
||||||
|
@ -336,16 +337,16 @@ void interrupt far kb_int_handler(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// indicate key event was processed to keyboard controller
|
// indicate key event was processed to keyboard controller
|
||||||
_key_scan = inp(KEYBRD_CTRL_PORT) | 0x82;
|
_key_scan = inp(KEYBRD_CTRL_PORT) | 0x80;
|
||||||
outp(KEYBRD_CTRL_PORT, _key_scan);
|
outp(KEYBRD_CTRL_PORT, _key_scan);
|
||||||
outp(KEYBRD_CTRL_PORT, _key_scan & 0x7f);
|
outp(KEYBRD_CTRL_PORT, _key_scan & 0x7f);
|
||||||
outp(PIC_CTRL_PORT, 0x20);
|
outp(PIC_CTRL_PORT, 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean keyboard_init(void) {
|
bool keyboard_init(void) {
|
||||||
if (_installed) {
|
if (_installed) {
|
||||||
dgl_set_error(DGL_KEYBOARD_ALREADY_INITIALIZED);
|
dgl_set_error(DGL_KEYBOARD_ALREADY_INITIALIZED);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_key_states();
|
reset_key_states();
|
||||||
|
@ -356,23 +357,23 @@ boolean keyboard_init(void) {
|
||||||
_old_handler = _dos_getvect(9);
|
_old_handler = _dos_getvect(9);
|
||||||
_dos_setvect(9, kb_int_handler);
|
_dos_setvect(9, kb_int_handler);
|
||||||
|
|
||||||
_installed = TRUE;
|
_installed = true;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean keyboard_shutdown(void) {
|
bool keyboard_shutdown(void) {
|
||||||
if (!_installed)
|
if (!_installed)
|
||||||
return TRUE; // don't care
|
return true; // don't care
|
||||||
|
|
||||||
_dos_setvect(9, _old_handler);
|
_dos_setvect(9, _old_handler);
|
||||||
|
|
||||||
reset_key_states();
|
reset_key_states();
|
||||||
|
|
||||||
_installed = FALSE;
|
_installed = false;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean keyboard_is_initialized(void) {
|
bool keyboard_is_initialized(void) {
|
||||||
return _installed;
|
return _installed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +390,7 @@ void keyboard_wait_for_key(KEY key) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char key_to_char(KEY key, uword modifiers) {
|
char key_to_char(KEY key, uint16 modifiers) {
|
||||||
// this is really just here because of the stupid slash key on the numpad
|
// this is really just here because of the stupid slash key on the numpad
|
||||||
// (but maybe it will be useful for other types of keyboards later...)
|
// (but maybe it will be useful for other types of keyboards later...)
|
||||||
if (BIT_ISSET(KEYBRD_MOD_EXTENDED, modifiers)) {
|
if (BIT_ISSET(KEYBRD_MOD_EXTENDED, modifiers)) {
|
||||||
|
|
52
DGLKBRD.H
Normal file → Executable file
52
DGLKBRD.H
Normal file → Executable file
|
@ -1,10 +1,14 @@
|
||||||
#ifndef DGL_DGLKYBRD_H_INCLUDED
|
#ifndef LIBDGL_DGLKYBRD_H
|
||||||
#define DGL_DGLKYBRD_H_INCLUDED
|
#define LIBDGL_DGLKYBRD_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
#include "dglkeys.h"
|
#include "dglkeys.h"
|
||||||
|
|
||||||
typedef byte KEY;
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef uint8 KEY;
|
||||||
|
|
||||||
#define KEYBRD_FLAGS_SCROLLOCK 0x10
|
#define KEYBRD_FLAGS_SCROLLOCK 0x10
|
||||||
#define KEYBRD_FLAGS_NUMLOCK 0x20
|
#define KEYBRD_FLAGS_NUMLOCK 0x20
|
||||||
|
@ -15,43 +19,23 @@ typedef byte KEY;
|
||||||
#define KEYBRD_MOD_NUMLOCK 0x4
|
#define KEYBRD_MOD_NUMLOCK 0x4
|
||||||
#define KEYBRD_MOD_CAPSLOCK 0x8
|
#define KEYBRD_MOD_CAPSLOCK 0x8
|
||||||
|
|
||||||
/*
|
extern volatile uint8 keys[128];
|
||||||
* Current state of the keyboard.
|
|
||||||
*/
|
|
||||||
extern volatile ubyte keys[128];
|
|
||||||
|
|
||||||
extern volatile uword key_flags;
|
extern volatile uint16 key_flags;
|
||||||
extern volatile uword key_mod;
|
extern volatile uint16 key_mod;
|
||||||
|
|
||||||
/*
|
bool keyboard_init(void);
|
||||||
* Installs a custom keyboard interrupt handler.
|
bool keyboard_shutdown(void);
|
||||||
* @return TRUE on success
|
bool keyboard_is_initialized(void);
|
||||||
*/
|
|
||||||
boolean keyboard_init(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Removes a previously installed keyboard interrupt handler.
|
|
||||||
* @return TRUE on success
|
|
||||||
*/
|
|
||||||
boolean keyboard_shutdown(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @return TRUE if the custom keyboard interrupt handler is installed.
|
|
||||||
*/
|
|
||||||
boolean keyboard_is_initialized(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Waits indefinitely until any key is pressed.
|
|
||||||
* @return The key that was pressed.
|
|
||||||
*/
|
|
||||||
KEY keyboard_read_key(void);
|
KEY keyboard_read_key(void);
|
||||||
|
|
||||||
/*
|
|
||||||
* Waits indefinitely until the specified key is pressed.
|
|
||||||
*/
|
|
||||||
void keyboard_wait_for_key(KEY key);
|
void keyboard_wait_for_key(KEY key);
|
||||||
|
|
||||||
char key_to_char(KEY key, uword modifiers);
|
char key_to_char(KEY key, uint16 modifiers);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
31
DGLMATH.H
Normal file → Executable file
31
DGLMATH.H
Normal file → Executable file
|
@ -1,10 +1,14 @@
|
||||||
#ifndef DGL_DGLMATH_H_INCLUDED
|
#ifndef LIBDGL_DGLMATH_H
|
||||||
#define DGL_DGLMATH_H_INCLUDED
|
#define LIBDGL_DGLMATH_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
#include "dglvec2.h"
|
#include "dglvec2.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TOLERANCE 0.00001f
|
#define TOLERANCE 0.00001f
|
||||||
|
|
||||||
#define PI 3.1415927f
|
#define PI 3.1415927f
|
||||||
|
@ -34,18 +38,21 @@ float angle_between_f(float x1, float y1, float x2, float y2);
|
||||||
int next_power_of_2(int n);
|
int next_power_of_2(int n);
|
||||||
void point_on_circle(float radius, float radians, float *x, float *y);
|
void point_on_circle(float radius, float radians, float *x, float *y);
|
||||||
|
|
||||||
static VECTOR2F direction_from_angle(float radians);
|
static VEC2 direction_from_angle(float radians);
|
||||||
static float round(float value);
|
static float round(float value);
|
||||||
static float symmetrical_round(float value);
|
static float symmetrical_round(float value);
|
||||||
static boolean close_enough(float a, float b, float tolerance);
|
static bool close_enough(float a, float b, float tolerance);
|
||||||
static boolean power_of_2(int n);
|
static bool power_of_2(int n);
|
||||||
static float smooth_step(float low, float high, float t);
|
static float smooth_step(float low, float high, float t);
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
static VECTOR2F direction_from_angle(float radians) {
|
static VEC2 direction_from_angle(float radians) {
|
||||||
VECTOR2F direction;
|
VEC2 direction;
|
||||||
point_on_circle(1.0f, radians, &direction.x, &direction.y);
|
float x, y;
|
||||||
|
point_on_circle(1.0f, radians, &x, &y);
|
||||||
|
direction.x = FTOFIX(x);
|
||||||
|
direction.y = FTOFIX(y);
|
||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,13 +67,13 @@ static float symmetrical_round(float value) {
|
||||||
return ceil(value - 0.5f);
|
return ceil(value - 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean close_enough(float a, float b, float tolerance) {
|
static bool close_enough(float a, float b, float tolerance) {
|
||||||
//return fabs((a - b) / ((b == 0.0f) ? 1.0f : b)) < tolerance;
|
//return fabs((a - b) / ((b == 0.0f) ? 1.0f : b)) < tolerance;
|
||||||
// TODO: this is not the best way
|
// TODO: this is not the best way
|
||||||
return fabs(a - b) <= tolerance;
|
return fabs(a - b) <= tolerance;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean power_of_2(int n) {
|
static bool power_of_2(int n) {
|
||||||
return (n != 0) && !(n & (n - 1));
|
return (n != 0) && !(n & (n - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,4 +82,8 @@ static float smooth_step(float low, float high, float t) {
|
||||||
return LERP(low, high, (n * n) * (3.0f - (2.0f * n)));
|
return LERP(low, high, (n * n) * (3.0f - (2.0f * n)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
36
DGLMOUSE.C
Normal file → Executable file
36
DGLMOUSE.C
Normal file → Executable file
|
@ -1,11 +1,11 @@
|
||||||
#include "dglmouse.h"
|
#include "dglmouse.h"
|
||||||
|
#include "dgl.h"
|
||||||
#include "dglevent.h"
|
#include "dglevent.h"
|
||||||
#include "dglerror.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <dos.h>
|
#include <dos.h>
|
||||||
|
|
||||||
static boolean _installed = FALSE;
|
static bool _installed = false;
|
||||||
static boolean _has_mouse = FALSE;
|
static bool _has_mouse = false;
|
||||||
|
|
||||||
static INPUTEVENT *mouse_event;
|
static INPUTEVENT *mouse_event;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ static void reset_mouse_state(void) {
|
||||||
mouse_prev_buttons = 0;
|
mouse_prev_buttons = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean init_mouse_driver(void) {
|
static bool init_mouse_driver(void) {
|
||||||
union REGS regs;
|
union REGS regs;
|
||||||
|
|
||||||
memset(®s, 0, sizeof(regs));
|
memset(®s, 0, sizeof(regs));
|
||||||
|
@ -112,21 +112,21 @@ void __loadds far mouse_int_handler(int eax, int ebx, int ecx, int edx) {
|
||||||
}
|
}
|
||||||
#pragma on (check_stack)
|
#pragma on (check_stack)
|
||||||
|
|
||||||
boolean mouse_init(void) {
|
bool mouse_init(void) {
|
||||||
union REGS regs;
|
union REGS regs;
|
||||||
struct SREGS sregs;
|
struct SREGS sregs;
|
||||||
|
|
||||||
if (_installed) {
|
if (_installed) {
|
||||||
dgl_set_error(DGL_MOUSE_ALREADY_INITIALIZED);
|
dgl_set_error(DGL_MOUSE_ALREADY_INITIALIZED);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_mouse_state();
|
reset_mouse_state();
|
||||||
|
|
||||||
_has_mouse = init_mouse_driver();
|
_has_mouse = init_mouse_driver();
|
||||||
if (!_has_mouse) {
|
if (!_has_mouse) {
|
||||||
_installed = TRUE;
|
_installed = true;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_mouse_state();
|
update_mouse_state();
|
||||||
|
@ -139,19 +139,19 @@ boolean mouse_init(void) {
|
||||||
sregs.es = FP_SEG(mouse_int_handler);
|
sregs.es = FP_SEG(mouse_int_handler);
|
||||||
int386x(0x33, ®s, ®s, &sregs);
|
int386x(0x33, ®s, ®s, &sregs);
|
||||||
|
|
||||||
_installed = TRUE;
|
_installed = true;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean mouse_shutdown(void) {
|
bool mouse_shutdown(void) {
|
||||||
union REGS regs;
|
union REGS regs;
|
||||||
|
|
||||||
if (!_installed)
|
if (!_installed)
|
||||||
return TRUE; // don't care
|
return true; // don't care
|
||||||
|
|
||||||
if (!_has_mouse) {
|
if (!_has_mouse) {
|
||||||
_installed = FALSE;
|
_installed = false;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(®s, 0, sizeof(regs));
|
memset(®s, 0, sizeof(regs));
|
||||||
|
@ -162,15 +162,15 @@ boolean mouse_shutdown(void) {
|
||||||
reset_mouse_state();
|
reset_mouse_state();
|
||||||
init_mouse_driver();
|
init_mouse_driver();
|
||||||
|
|
||||||
_installed = FALSE;
|
_installed = false;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean mouse_is_initialized(void) {
|
bool mouse_is_initialized(void) {
|
||||||
return _installed;
|
return _installed;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean mouse_is_present(void) {
|
bool mouse_is_present(void) {
|
||||||
return _has_mouse;
|
return _has_mouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
85
DGLMOUSE.H
Normal file → Executable file
85
DGLMOUSE.H
Normal file → Executable file
|
@ -1,94 +1,43 @@
|
||||||
#ifndef DGL_DGLMOUSE_H_INCLUDED
|
#ifndef LIBDGL_DGLMOUSE_H
|
||||||
#define DGL_DGLMOUSE_H_INCLUDED
|
#define LIBDGL_DGLMOUSE_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
|
|
||||||
typedef byte MOUSE_BUTTON;
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef uint8 MOUSE_BUTTON;
|
||||||
|
|
||||||
#define MOUSE_LEFTBUTTON 0x01
|
#define MOUSE_LEFTBUTTON 0x01
|
||||||
#define MOUSE_RIGHTBUTTON 0x02
|
#define MOUSE_RIGHTBUTTON 0x02
|
||||||
#define MOUSE_CENTERBUTTON 0x04
|
#define MOUSE_CENTERBUTTON 0x04
|
||||||
|
|
||||||
/*
|
|
||||||
* Current mouse cursor X position.
|
|
||||||
*/
|
|
||||||
extern volatile int mouse_x;
|
extern volatile int mouse_x;
|
||||||
|
|
||||||
/*
|
|
||||||
* Current mouse cursor Y position.
|
|
||||||
*/
|
|
||||||
extern volatile int mouse_y;
|
extern volatile int mouse_y;
|
||||||
|
|
||||||
/*
|
|
||||||
* Current state of mouse buttons.
|
|
||||||
*/
|
|
||||||
extern volatile int mouse_buttons;
|
extern volatile int mouse_buttons;
|
||||||
|
|
||||||
/*
|
|
||||||
* Amount the cursor moved along the X-axis since the last update.
|
|
||||||
*/
|
|
||||||
extern volatile int mouse_delta_x;
|
extern volatile int mouse_delta_x;
|
||||||
|
|
||||||
/*
|
|
||||||
* Amount the cursor moved along the Y-axis since the last update.
|
|
||||||
*/
|
|
||||||
extern volatile int mouse_delta_y;
|
extern volatile int mouse_delta_y;
|
||||||
|
|
||||||
/*
|
bool mouse_init(void);
|
||||||
* Installs a custom mouse handler.
|
bool mouse_shutdown(void);
|
||||||
* @return TRUE on success
|
bool mouse_is_initialized(void);
|
||||||
*/
|
bool mouse_is_present(void);
|
||||||
boolean mouse_init(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Removes a previously installed mouse handler.
|
|
||||||
* @return TRUE on success
|
|
||||||
*/
|
|
||||||
boolean mouse_shutdown(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @return TRUE if the custom mouse handler is installed.
|
|
||||||
*/
|
|
||||||
boolean mouse_is_initialized(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @return TRUE if the user's computer has a (recognized) mouse connected.
|
|
||||||
*/
|
|
||||||
boolean mouse_is_present(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Shows the mouse cursor. If the mouse cursor is currently shown, this does
|
|
||||||
* nothing.
|
|
||||||
*/
|
|
||||||
void mouse_show(void);
|
void mouse_show(void);
|
||||||
|
|
||||||
/*
|
|
||||||
* Hides the mouse cursor. If the mouse cursor is not currently shown, this
|
|
||||||
* does nothing.
|
|
||||||
*/
|
|
||||||
void mouse_hide(void);
|
void mouse_hide(void);
|
||||||
|
|
||||||
/*
|
|
||||||
* Sets the pixel boundaries for the mouse cursor.
|
|
||||||
* @param min_x left coordinate
|
|
||||||
* @param max_x right coordinate
|
|
||||||
* @param min_y top coordinate
|
|
||||||
* @param max_y bottom coordinate
|
|
||||||
*/
|
|
||||||
void mouse_set_bounds(int min_x, int min_y, int max_x, int max_y);
|
void mouse_set_bounds(int min_x, int min_y, int max_x, int max_y);
|
||||||
|
|
||||||
/*
|
static bool mouse_button(int button);
|
||||||
* Returns the current status of the specified button.
|
|
||||||
* @param button The button to check the status of.
|
|
||||||
* @return TRUE if the button is pressed.
|
|
||||||
*/
|
|
||||||
static boolean mouse_button(int button);
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
static boolean mouse_button(int button) {
|
static bool mouse_button(int button) {
|
||||||
return (mouse_buttons & button) != 0;
|
return (mouse_buttons & button) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
329
DGLMTX33.H
Normal file → Executable file
329
DGLMTX33.H
Normal file → Executable file
|
@ -1,10 +1,14 @@
|
||||||
#ifndef DGL_DGLMAT33_H_INCLUDED
|
#ifndef LIBDGL_DGLMTX33_H
|
||||||
#define DGL_DGLMAT33_H_INCLUDED
|
#define LIBDGL_DGLMTX33_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
|
||||||
#include "dglmath.h"
|
|
||||||
#include "dglvec2.h"
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include "dglcmn.h"
|
||||||
|
#include "dglfixp.h"
|
||||||
|
#include "dglvec2.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define _M33_11 0
|
#define _M33_11 0
|
||||||
#define _M33_12 3
|
#define _M33_12 3
|
||||||
|
@ -17,47 +21,54 @@
|
||||||
#define _M33_33 8
|
#define _M33_33 8
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float m[9];
|
fixed m[9];
|
||||||
} MATRIX33;
|
} MTX33;
|
||||||
|
|
||||||
static MATRIX33 matrix33(float m11, float m12, float m13,
|
static MTX33 mtx33(
|
||||||
float m21, float m22, float m23,
|
fixed m11, fixed m12, fixed m13,
|
||||||
float m31, float m32, float m33);
|
fixed m21, fixed m22, fixed m23,
|
||||||
static void matrix33_set(MATRIX33 *m,
|
fixed m31, fixed m32, fixed m33
|
||||||
float m11, float m12, float m13,
|
);
|
||||||
float m21, float m22, float m23,
|
|
||||||
float m31, float m32, float m33);
|
|
||||||
|
|
||||||
static MATRIX33 matrix33_from_euler_angles(float x, float y, float z);
|
static void mtx33_set(
|
||||||
static MATRIX33 matrix33_rotation_x(float radians);
|
MTX33 *m,
|
||||||
static MATRIX33 matrix33_rotation_y(float radians);
|
fixed m11, fixed m12, fixed m13,
|
||||||
static MATRIX33 matrix33_rotation_z(float radians);
|
fixed m21, fixed m22, fixed m23,
|
||||||
|
fixed m31, fixed m32, fixed m33
|
||||||
|
);
|
||||||
|
|
||||||
static MATRIX33 matrix33_add(MATRIX33 a, MATRIX33 b);
|
static MTX33 mtx33_from_angles(float x, float y, float z);
|
||||||
static MATRIX33 matrix33_sub(MATRIX33 a, MATRIX33 b);
|
static MTX33 mtx33_rotation_x(float radians);
|
||||||
static MATRIX33 matrix33_mul(MATRIX33 a, MATRIX33 b);
|
static MTX33 mtx33_rotation_y(float radians);
|
||||||
static MATRIX33 matrix33_scale(MATRIX33 m, float scale);
|
static MTX33 mtx33_rotation_z(float radians);
|
||||||
|
|
||||||
static float matrix33_determinant(MATRIX33 m);
|
static MTX33 mtx33_add(MTX33 a, MTX33 b);
|
||||||
static MATRIX33 matrix33_inverse(MATRIX33 m);
|
static MTX33 mtx33_sub(MTX33 a, MTX33 b);
|
||||||
static MATRIX33 matrix33_transpose(MATRIX33 m);
|
static MTX33 mtx33_mul(MTX33 a, MTX33 b);
|
||||||
static VECTOR2F matrix33_transform(MATRIX33 m, VECTOR2F v);
|
static MTX33 mtx33_scale(MTX33 m, fixed scale);
|
||||||
|
|
||||||
static MATRIX33 matrix33_translation_2d(float x, float y);
|
static fixed mtx33_determinant(MTX33 m);
|
||||||
static MATRIX33 matrix33_scaling_2d(float x, float y);
|
static MTX33 mtx33_inverse(MTX33 m);
|
||||||
static MATRIX33 matrix33_rotation_2d(float radians);
|
static MTX33 mtx33_transpose(MTX33 m);
|
||||||
static VECTOR2F matrix33_transform_2d(MATRIX33 m, VECTOR2F v);
|
static VEC2 mtx33_transform(MTX33 m, VEC2 v);
|
||||||
|
|
||||||
#define IDENTITY_MATRIX33 matrix33(1.0f, 0.0f, 0.0f, \
|
static MTX33 mtx33_translation_2d(fixed x, fixed y);
|
||||||
0.0f, 1.0f, 0.0f, \
|
static MTX33 mtx33_scaling_2d(fixed x, fixed y);
|
||||||
0.0f, 0.0f, 1.0f)
|
static MTX33 mtx33_rotation_2d(float radians);
|
||||||
|
static VEC2 mtx33_transform_2d(MTX33 m, VEC2 v);
|
||||||
|
|
||||||
|
#define IDENTITY_MTX33 mtx33(1.0f, 0.0f, 0.0f, \
|
||||||
|
0.0f, 1.0f, 0.0f, \
|
||||||
|
0.0f, 0.0f, 1.0f)
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
static MATRIX33 matrix33(float m11, float m12, float m13,
|
static MTX33 mtx33(
|
||||||
float m21, float m22, float m23,
|
fixed m11, fixed m12, fixed m13,
|
||||||
float m31, float m32, float m33) {
|
fixed m21, fixed m22, fixed m23,
|
||||||
MATRIX33 result;
|
fixed m31, fixed m32, fixed m33
|
||||||
|
) {
|
||||||
|
MTX33 result;
|
||||||
result.m[_M33_11] = m11;
|
result.m[_M33_11] = m11;
|
||||||
result.m[_M33_12] = m12;
|
result.m[_M33_12] = m12;
|
||||||
result.m[_M33_13] = m13;
|
result.m[_M33_13] = m13;
|
||||||
|
@ -70,10 +81,12 @@ static MATRIX33 matrix33(float m11, float m12, float m13,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void matrix33_set(MATRIX33 *m,
|
static void mtx33_set(
|
||||||
float m11, float m12, float m13,
|
MTX33 *m,
|
||||||
float m21, float m22, float m23,
|
fixed m11, fixed m12, fixed m13,
|
||||||
float m31, float m32, float m33) {
|
fixed m21, fixed m22, fixed m23,
|
||||||
|
fixed m31, fixed m32, fixed m33
|
||||||
|
) {
|
||||||
m->m[_M33_11] = m11;
|
m->m[_M33_11] = m11;
|
||||||
m->m[_M33_12] = m12;
|
m->m[_M33_12] = m12;
|
||||||
m->m[_M33_13] = m13;
|
m->m[_M33_13] = m13;
|
||||||
|
@ -85,82 +98,82 @@ static void matrix33_set(MATRIX33 *m,
|
||||||
m->m[_M33_33] = m33;
|
m->m[_M33_33] = m33;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_from_euler_angles(float x, float y, float z) {
|
static MTX33 mtx33_from_angles(float x, float y, float z) {
|
||||||
MATRIX33 rx, ry, rz;
|
MTX33 rx, ry, rz;
|
||||||
rx = matrix33_rotation_x(x);
|
rx = mtx33_rotation_x(x);
|
||||||
ry = matrix33_rotation_y(y);
|
ry = mtx33_rotation_y(y);
|
||||||
rz = matrix33_rotation_z(z);
|
rz = mtx33_rotation_z(z);
|
||||||
return matrix33_mul(matrix33_mul(rz, ry), rx);
|
return mtx33_mul(mtx33_mul(rz, ry), rx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_rotation_x(float radians) {
|
static MTX33 mtx33_rotation_x(fixed radians) {
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
float s, c;
|
fixed s, c;
|
||||||
|
|
||||||
s = sin(radians);
|
s = FTOFIX(sin(radians));
|
||||||
c = cos(radians);
|
c = FTOFIX(cos(radians));
|
||||||
|
|
||||||
result.m[_M33_11] = 1.0f;
|
result.m[_M33_11] = FP_1;
|
||||||
result.m[_M33_12] = 0.0f;
|
result.m[_M33_12] = 0;
|
||||||
result.m[_M33_13] = 0.0f;
|
result.m[_M33_13] = 0;
|
||||||
|
|
||||||
result.m[_M33_21] = 0.0f;
|
result.m[_M33_21] = 0;
|
||||||
result.m[_M33_22] = c;
|
result.m[_M33_22] = c;
|
||||||
result.m[_M33_23] = -s;
|
result.m[_M33_23] = -s;
|
||||||
|
|
||||||
result.m[_M33_31] = 0.0f;
|
result.m[_M33_31] = 0;
|
||||||
result.m[_M33_32] = s;
|
result.m[_M33_32] = s;
|
||||||
result.m[_M33_33] = c;
|
result.m[_M33_33] = c;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_rotation_y(float radians) {
|
static MTX33 mtx33_rotation_y(float radians) {
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
float s, c;
|
fixed s, c;
|
||||||
|
|
||||||
s = sin(radians);
|
s = FTOFIX(sin(radians));
|
||||||
c = cos(radians);
|
c = FTOFIX(cos(radians));
|
||||||
|
|
||||||
result.m[_M33_11] = c;
|
result.m[_M33_11] = c;
|
||||||
result.m[_M33_12] = 0.0f;
|
result.m[_M33_12] = 0;
|
||||||
result.m[_M33_13] = s;
|
result.m[_M33_13] = s;
|
||||||
|
|
||||||
result.m[_M33_21] = 0.0f;
|
result.m[_M33_21] = 0;
|
||||||
result.m[_M33_22] = 1.0f;
|
result.m[_M33_22] = FP_1;
|
||||||
result.m[_M33_23] = 0.0f;
|
result.m[_M33_23] = 0;
|
||||||
|
|
||||||
result.m[_M33_31] = -s;
|
result.m[_M33_31] = -s;
|
||||||
result.m[_M33_32] = 0.0f;
|
result.m[_M33_32] = 0;
|
||||||
result.m[_M33_33] = c;
|
result.m[_M33_33] = c;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_rotation_z(float radians) {
|
static MTX33 mtx33_rotation_z(float radians) {
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
float s, c;
|
fixed s, c;
|
||||||
|
|
||||||
s = sin(radians);
|
s = FTOFIX(sin(radians));
|
||||||
c = cos(radians);
|
c = FTOFIX(cos(radians));
|
||||||
|
|
||||||
result.m[_M33_11] = c;
|
result.m[_M33_11] = c;
|
||||||
result.m[_M33_12] = -s;
|
result.m[_M33_12] = -s;
|
||||||
result.m[_M33_13] = 0.0f;
|
result.m[_M33_13] = 0;
|
||||||
|
|
||||||
result.m[_M33_21] = s;
|
result.m[_M33_21] = s;
|
||||||
result.m[_M33_22] = c;
|
result.m[_M33_22] = c;
|
||||||
result.m[_M33_23] = 0.0f;
|
result.m[_M33_23] = 0;
|
||||||
|
|
||||||
result.m[_M33_31] = 0.0f;
|
result.m[_M33_31] = 0;
|
||||||
result.m[_M33_32] = 0.0f;
|
result.m[_M33_32] = 0;
|
||||||
result.m[_M33_33] = 1.0f;
|
result.m[_M33_33] = FP_1;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_add(MATRIX33 a, MATRIX33 b) {
|
static MTX33 mtx33_add(MTX33 a, MTX33 b) {
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
|
|
||||||
result.m[_M33_11] = a.m[_M33_11] + b.m[_M33_11];
|
result.m[_M33_11] = a.m[_M33_11] + b.m[_M33_11];
|
||||||
result.m[_M33_12] = a.m[_M33_12] + b.m[_M33_12];
|
result.m[_M33_12] = a.m[_M33_12] + b.m[_M33_12];
|
||||||
|
@ -175,8 +188,8 @@ static MATRIX33 matrix33_add(MATRIX33 a, MATRIX33 b) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_sub(MATRIX33 a, MATRIX33 b) {
|
static MTX33 mtx33_sub(MTX33 a, MTX33 b) {
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
|
|
||||||
result.m[_M33_11] = a.m[_M33_11] - b.m[_M33_11];
|
result.m[_M33_11] = a.m[_M33_11] - b.m[_M33_11];
|
||||||
result.m[_M33_12] = a.m[_M33_12] - b.m[_M33_12];
|
result.m[_M33_12] = a.m[_M33_12] - b.m[_M33_12];
|
||||||
|
@ -191,75 +204,75 @@ static MATRIX33 matrix33_sub(MATRIX33 a, MATRIX33 b) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_mul(MATRIX33 a, MATRIX33 b) {
|
static MTX33 mtx33_mul(MTX33 a, MTX33 b) {
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
|
|
||||||
result.m[_M33_11] = a.m[_M33_11] * b.m[_M33_11] + a.m[_M33_12] * b.m[_M33_21] + a.m[_M33_13] * b.m[_M33_31];
|
result.m[_M33_11] = fix_mul(a.m[_M33_11], b.m[_M33_11]) + fix_mul(a.m[_M33_12], b.m[_M33_21]) + fix_mul(a.m[_M33_13], b.m[_M33_31]);
|
||||||
result.m[_M33_12] = a.m[_M33_11] * b.m[_M33_12] + a.m[_M33_12] * b.m[_M33_22] + a.m[_M33_13] * b.m[_M33_32];
|
result.m[_M33_12] = fix_mul(a.m[_M33_11], b.m[_M33_12]) + fix_mul(a.m[_M33_12], b.m[_M33_22]) + fix_mul(a.m[_M33_13], b.m[_M33_32]);
|
||||||
result.m[_M33_13] = a.m[_M33_11] * b.m[_M33_13] + a.m[_M33_12] * b.m[_M33_23] + a.m[_M33_13] * b.m[_M33_33];
|
result.m[_M33_13] = fix_mul(a.m[_M33_11], b.m[_M33_13]) + fix_mul(a.m[_M33_12], b.m[_M33_23]) + fix_mul(a.m[_M33_13], b.m[_M33_33]);
|
||||||
|
|
||||||
result.m[_M33_21] = a.m[_M33_21] * b.m[_M33_11] + a.m[_M33_22] * b.m[_M33_21] + a.m[_M33_23] * b.m[_M33_31];
|
result.m[_M33_21] = fix_mul(a.m[_M33_21], b.m[_M33_11]) + fix_mul(a.m[_M33_22], b.m[_M33_21]) + fix_mul(a.m[_M33_23], b.m[_M33_31]);
|
||||||
result.m[_M33_22] = a.m[_M33_21] * b.m[_M33_12] + a.m[_M33_22] * b.m[_M33_22] + a.m[_M33_23] * b.m[_M33_32];
|
result.m[_M33_22] = fix_mul(a.m[_M33_21], b.m[_M33_12]) + fix_mul(a.m[_M33_22], b.m[_M33_22]) + fix_mul(a.m[_M33_23], b.m[_M33_32]);
|
||||||
result.m[_M33_23] = a.m[_M33_21] * b.m[_M33_13] + a.m[_M33_22] * b.m[_M33_23] + a.m[_M33_23] * b.m[_M33_33];
|
result.m[_M33_23] = fix_mul(a.m[_M33_21], b.m[_M33_13]) + fix_mul(a.m[_M33_22], b.m[_M33_23]) + fix_mul(a.m[_M33_23], b.m[_M33_33]);
|
||||||
|
|
||||||
result.m[_M33_31] = a.m[_M33_31] * b.m[_M33_11] + a.m[_M33_32] * b.m[_M33_21] + a.m[_M33_33] * b.m[_M33_31];
|
result.m[_M33_31] = fix_mul(a.m[_M33_31], b.m[_M33_11]) + fix_mul(a.m[_M33_32], b.m[_M33_21]) + fix_mul(a.m[_M33_33], b.m[_M33_31]);
|
||||||
result.m[_M33_32] = a.m[_M33_31] * b.m[_M33_12] + a.m[_M33_32] * b.m[_M33_22] + a.m[_M33_33] * b.m[_M33_32];
|
result.m[_M33_32] = fix_mul(a.m[_M33_31], b.m[_M33_12]) + fix_mul(a.m[_M33_32], b.m[_M33_22]) + fix_mul(a.m[_M33_33], b.m[_M33_32]);
|
||||||
result.m[_M33_33] = a.m[_M33_31] * b.m[_M33_13] + a.m[_M33_32] * b.m[_M33_23] + a.m[_M33_33] * b.m[_M33_33];
|
result.m[_M33_33] = fix_mul(a.m[_M33_31], b.m[_M33_13]) + fix_mul(a.m[_M33_32], b.m[_M33_23]) + fix_mul(a.m[_M33_33], b.m[_M33_33]);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_scale(MATRIX33 m, float scale) {
|
static MTX33 mtx33_scale(MTX33 m, fixed scale) {
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
|
|
||||||
result.m[_M33_11] = m.m[_M33_11] * scale;
|
result.m[_M33_11] = fix_mul(m.m[_M33_11], scale);
|
||||||
result.m[_M33_12] = m.m[_M33_12] * scale;
|
result.m[_M33_12] = fix_mul(m.m[_M33_12], scale);
|
||||||
result.m[_M33_13] = m.m[_M33_13] * scale;
|
result.m[_M33_13] = fix_mul(m.m[_M33_13], scale);
|
||||||
result.m[_M33_21] = m.m[_M33_21] * scale;
|
result.m[_M33_21] = fix_mul(m.m[_M33_21], scale);
|
||||||
result.m[_M33_22] = m.m[_M33_22] * scale;
|
result.m[_M33_22] = fix_mul(m.m[_M33_22], scale);
|
||||||
result.m[_M33_23] = m.m[_M33_23] * scale;
|
result.m[_M33_23] = fix_mul(m.m[_M33_23], scale);
|
||||||
result.m[_M33_31] = m.m[_M33_31] * scale;
|
result.m[_M33_31] = fix_mul(m.m[_M33_31], scale);
|
||||||
result.m[_M33_32] = m.m[_M33_32] * scale;
|
result.m[_M33_32] = fix_mul(m.m[_M33_32], scale);
|
||||||
result.m[_M33_33] = m.m[_M33_33] * scale;
|
result.m[_M33_33] = fix_mul(m.m[_M33_33], scale);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float matrix33_determinant(MATRIX33 m) {
|
static fixed mtx33_determinant(MTX33 m) {
|
||||||
return
|
return
|
||||||
m.m[_M33_11] * m.m[_M33_22] * m.m[_M33_33] +
|
fix_mul(m.m[_M33_11], fix_mul(m.m[_M33_22], m.m[_M33_33])) +
|
||||||
m.m[_M33_12] * m.m[_M33_23] * m.m[_M33_31] +
|
fix_mul(m.m[_M33_12], fix_mul(m.m[_M33_23], m.m[_M33_31])) +
|
||||||
m.m[_M33_13] * m.m[_M33_21] * m.m[_M33_32] -
|
fix_mul(m.m[_M33_13], fix_mul(m.m[_M33_21], m.m[_M33_32])) -
|
||||||
m.m[_M33_11] * m.m[_M33_23] * m.m[_M33_32] -
|
fix_mul(m.m[_M33_11], fix_mul(m.m[_M33_23], m.m[_M33_32])) -
|
||||||
m.m[_M33_12] * m.m[_M33_21] * m.m[_M33_33] -
|
fix_mul(m.m[_M33_12], fix_mul(m.m[_M33_21], m.m[_M33_33])) -
|
||||||
m.m[_M33_13] * m.m[_M33_22] * m.m[_M33_31];
|
fix_mul(m.m[_M33_13], fix_mul(m.m[_M33_22], m.m[_M33_31]));
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_inverse(MATRIX33 m) {
|
static MTX33 mtx33_inverse(MTX33 m) {
|
||||||
float d;
|
fixed d;
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
d = matrix33_determinant(m);
|
d = mtx33_determinant(m);
|
||||||
if (close_enough(d, 0.0f, TOLERANCE))
|
if (d == 0)
|
||||||
return IDENTITY_MATRIX33;
|
return IDENTITY_MTX33;
|
||||||
else {
|
else {
|
||||||
d = 1.0f / d;
|
d = fix_div(FP_1, d);
|
||||||
|
|
||||||
result.m[_M33_11] = d * (m.m[_M33_22] * m.m[_M33_33] - m.m[_M33_32] * m.m[_M33_23]);
|
result.m[_M33_11] = fix_mul(d, (fix_mul(m.m[_M33_22], m.m[_M33_33]) - fix_mul(m.m[_M33_32], m.m[_M33_23])));
|
||||||
result.m[_M33_21] = d * (m.m[_M33_31] * m.m[_M33_23] - m.m[_M33_21] * m.m[_M33_33]);
|
result.m[_M33_21] = fix_mul(d, (fix_mul(m.m[_M33_31], m.m[_M33_23]) - fix_mul(m.m[_M33_21], m.m[_M33_33])));
|
||||||
result.m[_M33_31] = d * (m.m[_M33_21] * m.m[_M33_32] - m.m[_M33_31] * m.m[_M33_22]);
|
result.m[_M33_31] = fix_mul(d, (fix_mul(m.m[_M33_21], m.m[_M33_32]) - fix_mul(m.m[_M33_31], m.m[_M33_22])));
|
||||||
result.m[_M33_21] = d * (m.m[_M33_32] * m.m[_M33_13] - m.m[_M33_12] * m.m[_M33_33]);
|
result.m[_M33_21] = fix_mul(d, (fix_mul(m.m[_M33_32], m.m[_M33_13]) - fix_mul(m.m[_M33_12], m.m[_M33_33])));
|
||||||
result.m[_M33_22] = d * (m.m[_M33_11] * m.m[_M33_33] - m.m[_M33_31] * m.m[_M33_13]);
|
result.m[_M33_22] = fix_mul(d, (fix_mul(m.m[_M33_11], m.m[_M33_33]) - fix_mul(m.m[_M33_31], m.m[_M33_13])));
|
||||||
result.m[_M33_23] = d * (m.m[_M33_31] * m.m[_M33_12] - m.m[_M33_11] * m.m[_M33_32]);
|
result.m[_M33_23] = fix_mul(d, (fix_mul(m.m[_M33_31], m.m[_M33_12]) - fix_mul(m.m[_M33_11], m.m[_M33_32])));
|
||||||
result.m[_M33_31] = d * (m.m[_M33_12] * m.m[_M33_23] - m.m[_M33_22] * m.m[_M33_13]);
|
result.m[_M33_31] = fix_mul(d, (fix_mul(m.m[_M33_12], m.m[_M33_23]) - fix_mul(m.m[_M33_22], m.m[_M33_13])));
|
||||||
result.m[_M33_32] = d * (m.m[_M33_21] * m.m[_M33_13] - m.m[_M33_11] * m.m[_M33_23]);
|
result.m[_M33_32] = fix_mul(d, (fix_mul(m.m[_M33_21], m.m[_M33_13]) - fix_mul(m.m[_M33_11], m.m[_M33_23])));
|
||||||
result.m[_M33_33] = d * (m.m[_M33_11] * m.m[_M33_22] - m.m[_M33_21] * m.m[_M33_12]);
|
result.m[_M33_33] = fix_mul(d, (fix_mul(m.m[_M33_11], m.m[_M33_22]) - fix_mul(m.m[_M33_21], m.m[_M33_12])));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_transpose(MATRIX33 m) {
|
static MTX33 mtx33_transpose(MTX33 m) {
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
|
|
||||||
result.m[_M33_11] = m.m[_M33_11];
|
result.m[_M33_11] = m.m[_M33_11];
|
||||||
result.m[_M33_12] = m.m[_M33_21];
|
result.m[_M33_12] = m.m[_M33_21];
|
||||||
|
@ -276,65 +289,69 @@ static MATRIX33 matrix33_transpose(MATRIX33 m) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F matrix33_transform(MATRIX33 m, VECTOR2F v) {
|
static VEC2 mtx33_transform(MTX33 m, VEC2 v) {
|
||||||
VECTOR2F result;
|
VEC2 result;
|
||||||
|
|
||||||
result.x = v.x * m.m[_M33_11] + v.y * m.m[_M33_12] + m.m[_M33_13];
|
result.x = fix_mul(v.x, m.m[_M33_11]) + fix_mul(v.y, m.m[_M33_12]) + m.m[_M33_13];
|
||||||
result.y = v.x * m.m[_M33_21] + v.y * m.m[_M33_22] + m.m[_M33_23];
|
result.y = fix_mul(v.x, m.m[_M33_21]) + fix_mul(v.y, m.m[_M33_22]) + m.m[_M33_23];
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_translation_2d(float x, float y) {
|
static MTX33 mtx33_translation_2d(fixed x, fixed y) {
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
|
|
||||||
result.m[_M33_11] = 1.0f;
|
result.m[_M33_11] = FP_1;
|
||||||
result.m[_M33_12] = 0.0f;
|
result.m[_M33_12] = 0;
|
||||||
result.m[_M33_13] = 0.0f;
|
result.m[_M33_13] = 0;
|
||||||
|
|
||||||
result.m[_M33_21] = 0.0f;
|
result.m[_M33_21] = 0;
|
||||||
result.m[_M33_22] = 1.0f;
|
result.m[_M33_22] = FP_1;
|
||||||
result.m[_M33_23] = 0.0f;
|
result.m[_M33_23] = 0;
|
||||||
|
|
||||||
result.m[_M33_31] = x;
|
result.m[_M33_31] = x;
|
||||||
result.m[_M33_32] = y;
|
result.m[_M33_32] = y;
|
||||||
result.m[_M33_33] = 1.0f;
|
result.m[_M33_33] = FP_1;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_scaling_2d(float x, float y) {
|
static MTX33 mtx33_scaling_2d(fixed x, fixed y) {
|
||||||
MATRIX33 result;
|
MTX33 result;
|
||||||
|
|
||||||
result.m[_M33_11] = x;
|
result.m[_M33_11] = x;
|
||||||
result.m[_M33_12] = 0.0f;
|
result.m[_M33_12] = 0;
|
||||||
result.m[_M33_13] = 0.0f;
|
result.m[_M33_13] = 0;
|
||||||
|
|
||||||
result.m[_M33_21] = 0.0f;
|
result.m[_M33_21] = 0;
|
||||||
result.m[_M33_22] = y;
|
result.m[_M33_22] = y;
|
||||||
result.m[_M33_23] = 0.0f;
|
result.m[_M33_23] = 0;
|
||||||
|
|
||||||
result.m[_M33_31] = 0.0f;
|
result.m[_M33_31] = 0;
|
||||||
result.m[_M33_32] = 0.0f;
|
result.m[_M33_32] = 0;
|
||||||
result.m[_M33_33] = 1.0f;
|
result.m[_M33_33] = FP_1;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MATRIX33 matrix33_rotation_2d(float radians) {
|
static MTX33 mtx33_rotation_2d(float radians) {
|
||||||
return matrix33_rotation_z(radians);
|
return mtx33_rotation_z(radians);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F matrix33_transform_2d(MATRIX33 m, VECTOR2F v) {
|
static VEC2 mtx33_transform_2d(MTX33 m, VEC2 v) {
|
||||||
VECTOR2F result;
|
VEC2 result;
|
||||||
|
|
||||||
result.x = v.x * m.m[_M33_11] + v.y * m.m[_M33_12] + m.m[_M33_13];
|
result.x = fix_mul(v.x, m.m[_M33_11]) + fix_mul(v.y, m.m[_M33_12]) + m.m[_M33_13];
|
||||||
result.y = v.x * m.m[_M33_21] + v.y * m.m[_M33_22] + m.m[_M33_23];
|
result.y = fix_mul(v.x, m.m[_M33_21]) + fix_mul(v.y, m.m[_M33_22]) + m.m[_M33_23];
|
||||||
result.x += m.m[_M33_31];
|
result.x += m.m[_M33_31];
|
||||||
result.y += m.m[_M33_32];
|
result.y += m.m[_M33_32];
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
69
DGLPAL.C
Normal file → Executable file
69
DGLPAL.C
Normal file → Executable file
|
@ -1,9 +1,10 @@
|
||||||
#include "dglpal.h"
|
#include "dglpal.h"
|
||||||
#include "dglgfx.h"
|
#include "dglgfx.h"
|
||||||
#include <stdlib.h>
|
#include <conio.h>
|
||||||
#include <dos.h>
|
#include <dos.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
void pal_set_color(byte color, byte r, byte g, byte b) {
|
void pal_set_color(uint8 color, uint8 r, uint8 g, uint8 b) {
|
||||||
outp(0x3c6, 0xff);
|
outp(0x3c6, 0xff);
|
||||||
outp(0x3c8, color);
|
outp(0x3c8, color);
|
||||||
outp(0x3c9, r);
|
outp(0x3c9, r);
|
||||||
|
@ -11,7 +12,7 @@ void pal_set_color(byte color, byte r, byte g, byte b) {
|
||||||
outp(0x3c9, b);
|
outp(0x3c9, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pal_get_color(byte color, byte *r, byte *g, byte *b) {
|
void pal_get_color(uint8 color, uint8 *r, uint8 *g, uint8 *b) {
|
||||||
outp(0x3c6, 0xff);
|
outp(0x3c6, 0xff);
|
||||||
outp(0x3c7, color);
|
outp(0x3c7, color);
|
||||||
*r = inp(0x3c9);
|
*r = inp(0x3c9);
|
||||||
|
@ -19,7 +20,7 @@ void pal_get_color(byte color, byte *r, byte *g, byte *b) {
|
||||||
*b = inp(0x3c9);
|
*b = inp(0x3c9);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pal_set(const byte *palette) {
|
void pal_set(const uint8 *palette) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < 256; ++i) {
|
for (i = 0; i < 256; ++i) {
|
||||||
pal_set_color(i, palette[0], palette[1], palette[2]);
|
pal_set_color(i, palette[0], palette[1], palette[2]);
|
||||||
|
@ -27,7 +28,7 @@ void pal_set(const byte *palette) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pal_get(byte *palette) {
|
void pal_get(uint8 *palette) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < 256; ++i) {
|
for (i = 0; i < 256; ++i) {
|
||||||
pal_get_color(i, palette, palette + 1, palette + 2);
|
pal_get_color(i, palette, palette + 1, palette + 2);
|
||||||
|
@ -35,38 +36,38 @@ void pal_get(byte *palette) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean fade_color(int color, byte r, byte g, byte b, int step) {
|
static bool fade_color(uint8 color, uint8 r, uint8 g, uint8 b, int step) {
|
||||||
byte red, green, blue;
|
uint8 red, green, blue;
|
||||||
byte diff_r, diff_g, diff_b;
|
uint8 diff_r, diff_g, diff_b;
|
||||||
boolean color_diff = FALSE;
|
bool color_diff = false;
|
||||||
|
|
||||||
pal_get_color(color, &red, &green, &blue);
|
pal_get_color(color, &red, &green, &blue);
|
||||||
|
|
||||||
if (red != r) {
|
if (red != r) {
|
||||||
color_diff = TRUE;
|
color_diff = true;
|
||||||
diff_r = abs(red - r);
|
diff_r = abs(red - r);
|
||||||
if (red > r)
|
if (red > r)
|
||||||
red -= min(step, diff_r);
|
red -= MIN(step, diff_r);
|
||||||
else
|
else
|
||||||
red += min(step, diff_r);
|
red += MIN(step, diff_r);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (green != g) {
|
if (green != g) {
|
||||||
color_diff = TRUE;
|
color_diff = true;
|
||||||
diff_g = abs(green - g);
|
diff_g = abs(green - g);
|
||||||
if (green > g)
|
if (green > g)
|
||||||
green -= min(step, diff_g);
|
green -= MIN(step, diff_g);
|
||||||
else
|
else
|
||||||
green += min(step, diff_g);
|
green += MIN(step, diff_g);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blue != b) {
|
if (blue != b) {
|
||||||
color_diff = TRUE;
|
color_diff = true;
|
||||||
diff_b = abs(blue - b);
|
diff_b = abs(blue - b);
|
||||||
if (blue > b)
|
if (blue > b)
|
||||||
blue -= min(step, diff_b);
|
blue -= MIN(step, diff_b);
|
||||||
else
|
else
|
||||||
blue += min(step, diff_b);
|
blue += MIN(step, diff_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (color_diff)
|
if (color_diff)
|
||||||
|
@ -75,34 +76,46 @@ static boolean fade_color(int color, byte r, byte g, byte b, int step) {
|
||||||
return (red == r && green == g && blue == b);
|
return (red == r && green == g && blue == b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pal_fade_range_to_color(int start, int end, byte r, byte g, byte b, int step) {
|
void pal_fade_range_to_color(
|
||||||
|
uint8 start,
|
||||||
|
uint8 end,
|
||||||
|
uint8 r,
|
||||||
|
uint8 g,
|
||||||
|
uint8 b,
|
||||||
|
int step
|
||||||
|
) {
|
||||||
int i;
|
int i;
|
||||||
boolean done = FALSE;
|
bool done = false;
|
||||||
|
|
||||||
step = abs(step);
|
step = abs(step);
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
done = TRUE;
|
done = true;
|
||||||
video_wait_vsync();
|
wait_vsync();
|
||||||
for (i = start; i <= end; ++i) {
|
for (i = start; i <= end; ++i) {
|
||||||
if (!fade_color(i, r, g, b, step))
|
if (!fade_color(i, r, g, b, step))
|
||||||
done = FALSE;
|
done = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pal_fade_range_to_palette(int start, int end, const byte *palette, int step) {
|
void pal_fade_range_to_palette(
|
||||||
|
uint8 start,
|
||||||
|
uint8 end,
|
||||||
|
const uint8 *palette,
|
||||||
|
int step
|
||||||
|
) {
|
||||||
int color, i;
|
int color, i;
|
||||||
boolean done = FALSE;
|
bool done = false;
|
||||||
|
|
||||||
step = abs(step);
|
step = abs(step);
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
done = TRUE;
|
done = true;
|
||||||
video_wait_vsync();
|
wait_vsync();
|
||||||
for (i = (start * 3), color = start; color <= end; ++color, i += 3) {
|
for (i = (start * 3), color = start; color <= end; ++color, i += 3) {
|
||||||
if (!fade_color(color, palette[i], palette[i + 1], palette[i + 2], step))
|
if (!fade_color(color, palette[i], palette[i + 1], palette[i + 2], step))
|
||||||
done = FALSE;
|
done = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
46
DGLPAL.H
Normal file → Executable file
46
DGLPAL.H
Normal file → Executable file
|
@ -1,27 +1,49 @@
|
||||||
#ifndef DGL_DGLPAL_H_INCLUDED
|
#ifndef LIBDGL_DGLPAL_H
|
||||||
#define DGL_DGLPAL_H_INCLUDED
|
#define LIBDGL_DGLPAL_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
|
|
||||||
void pal_set_color(byte color, byte r, byte g, byte b);
|
#ifdef __cplusplus
|
||||||
void pal_get_color(byte color, byte *r, byte *g, byte *b);
|
extern "C" {
|
||||||
void pal_set(const byte *palette);
|
#endif
|
||||||
void pal_get(byte *palette);
|
|
||||||
|
|
||||||
void pal_fade_range_to_color(int start, int end, byte r, byte g, byte b, int step);
|
void pal_set_color(uint8 color, uint8 r, uint8 g, uint8 b);
|
||||||
void pal_fade_range_to_palette(int start, int end, const byte *palette, int step);
|
void pal_get_color(uint8 color, uint8 *r, uint8 *g, uint8 *b);
|
||||||
static void pal_fade_to_color(byte r, byte g, byte b, int step);
|
void pal_set(const uint8 *palette);
|
||||||
static void pal_fade_to_palette(const byte *palette, int step);
|
void pal_get(uint8 *palette);
|
||||||
|
|
||||||
|
void pal_fade_range_to_color(
|
||||||
|
uint8 start,
|
||||||
|
uint8 end,
|
||||||
|
uint8 r,
|
||||||
|
uint8 g,
|
||||||
|
uint8 b,
|
||||||
|
int step
|
||||||
|
);
|
||||||
|
|
||||||
|
void pal_fade_range_to_palette(
|
||||||
|
uint8 start,
|
||||||
|
uint8 end,
|
||||||
|
const uint8 *palette,
|
||||||
|
int step
|
||||||
|
);
|
||||||
|
|
||||||
|
static void pal_fade_to_color(uint8 r, uint8 g, uint8 b, int step);
|
||||||
|
static void pal_fade_to_palette(const uint8 *palette, int step);
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
static void pal_fade_to_color(byte r, byte g, byte b, int step) {
|
static void pal_fade_to_color(uint8 r, uint8 g, uint8 b, int step) {
|
||||||
pal_fade_range_to_color(0, 255, r, g, b, step);
|
pal_fade_range_to_color(0, 255, r, g, b, step);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pal_fade_to_palette(const byte *palette, int step) {
|
static void pal_fade_to_palette(const uint8 *palette, int step) {
|
||||||
pal_fade_range_to_palette(0, 255, palette, step);
|
pal_fade_range_to_palette(0, 255, palette, step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
107
DGLPCX.C
Normal file → Executable file
107
DGLPCX.C
Normal file → Executable file
|
@ -1,38 +1,37 @@
|
||||||
|
#include "dgl.h"
|
||||||
#include "dglpcx.h"
|
#include "dglpcx.h"
|
||||||
#include "dglgfx.h"
|
#include "dglgfx.h"
|
||||||
#include "dglpal.h"
|
#include "dglpal.h"
|
||||||
#include "dgldraw.h"
|
|
||||||
#include "dglerror.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
byte manufacturer;
|
uint8 manufacturer;
|
||||||
byte version;
|
uint8 version;
|
||||||
byte encoding;
|
uint8 encoding;
|
||||||
byte bpp;
|
uint8 bpp;
|
||||||
word x;
|
uint16 x;
|
||||||
word y;
|
uint16 y;
|
||||||
word width;
|
uint16 width;
|
||||||
word height;
|
uint16 height;
|
||||||
word horizontal_dpi;
|
uint16 horizontal_dpi;
|
||||||
word vertical_dpi;
|
uint16 vertical_dpi;
|
||||||
byte ega_palette[48];
|
uint8 ega_palette[48];
|
||||||
byte reserved;
|
uint8 reserved;
|
||||||
byte num_color_planes;
|
uint8 num_color_planes;
|
||||||
word bytes_per_line;
|
uint16 bytes_per_line;
|
||||||
word palette_type;
|
uint16 palette_type;
|
||||||
word horizontal_size;
|
uint16 horizontal_size;
|
||||||
word vertical_size;
|
uint16 vertical_size;
|
||||||
byte padding[54];
|
uint8 padding[54];
|
||||||
} PCX_HEADER;
|
} PCX_HEADER;
|
||||||
|
|
||||||
SURFACE* pcx_load(const char *filename, byte *pcx_palette) {
|
SURFACE* pcx_load(const char *filename, uint8 *pcx_palette) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
PCX_HEADER header;
|
PCX_HEADER header;
|
||||||
int i, n, count, x, y;
|
int i, n, count, x, y;
|
||||||
SURFACE *pcx;
|
SURFACE *pcx;
|
||||||
ubyte data;
|
uint8 data;
|
||||||
|
|
||||||
fp = fopen(filename, "rb");
|
fp = fopen(filename, "rb");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
|
@ -58,32 +57,32 @@ SURFACE* pcx_load(const char *filename, byte *pcx_palette) {
|
||||||
|
|
||||||
pcx = surface_create(header.width + 1, header.height + 1);
|
pcx = surface_create(header.width + 1, header.height + 1);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (y = 0; y < (header.height + 1); ++y) {
|
for (y = 0; y < (header.height + 1); ++y) {
|
||||||
// write pixels out per-scanline (technically this is what the pcx
|
// write pixels out per-scanline (technically this is what the pcx
|
||||||
// standard specifies, though a lot of pcx loaders don't do this).
|
// standard specifies, though a lot of pcx loaders don't do this).
|
||||||
x = 0;
|
x = 0;
|
||||||
while (x < header.bytes_per_line) {
|
while (x < header.bytes_per_line) {
|
||||||
// read pixel (or RLE count...)
|
// read pixel (or RLE count...)
|
||||||
data = fgetc(fp);
|
data = fgetc(fp);
|
||||||
if ((data & 0xc0) == 0xc0) {
|
if ((data & 0xc0) == 0xc0) {
|
||||||
// was an RLE count, pixel is next byte
|
// was an RLE count, pixel is next byte
|
||||||
count = data & 0x3f;
|
count = data & 0x3f;
|
||||||
data = fgetc(fp);
|
data = fgetc(fp);
|
||||||
} else {
|
} else {
|
||||||
count = 1;
|
count = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// store this pixel colour the specified number of times
|
// store this pixel colour the specified number of times
|
||||||
while (count--) {
|
while (count--) {
|
||||||
if (x < pcx->width) {
|
if (x < pcx->width) {
|
||||||
pcx->pixels[i] = data;
|
pcx->pixels[i] = data;
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
++x;
|
++x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// read palette (only if needed)
|
// read palette (only if needed)
|
||||||
if (pcx_palette) {
|
if (pcx_palette) {
|
||||||
|
@ -107,34 +106,34 @@ pcx_load_error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean write_pcx_data(FILE *fp, int run_count, byte pixel) {
|
static bool write_pcx_data(FILE *fp, int run_count, uint8 pixel) {
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if ((run_count > 1) || ((pixel & 0xc0) == 0xc0)) {
|
if ((run_count > 1) || ((pixel & 0xc0) == 0xc0)) {
|
||||||
n = fputc(0xc0 | run_count, fp);
|
n = fputc(0xc0 | run_count, fp);
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
n = fputc(pixel, fp);
|
n = fputc(pixel, fp);
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean pcx_save(const char *filename, const SURFACE *src, const byte *palette) {
|
bool pcx_save(const char *filename, const SURFACE *src, const uint8 *palette) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int i, n, x, y;
|
int i, n, x, y;
|
||||||
int run_count;
|
int run_count;
|
||||||
byte pixel, run_pixel;
|
uint8 pixel, run_pixel;
|
||||||
byte r, g, b;
|
uint8 r, g, b;
|
||||||
boolean result;
|
bool result;
|
||||||
PCX_HEADER header;
|
PCX_HEADER header;
|
||||||
|
|
||||||
fp = fopen(filename, "wb");
|
fp = fopen(filename, "wb");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
dgl_set_error(DGL_IO_ERROR);
|
dgl_set_error(DGL_IO_ERROR);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&header, 0, sizeof(PCX_HEADER));
|
memset(&header, 0, sizeof(PCX_HEADER));
|
||||||
|
@ -220,11 +219,11 @@ boolean pcx_save(const char *filename, const SURFACE *src, const byte *palette)
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
pcx_save_error:
|
pcx_save_error:
|
||||||
dgl_set_error(DGL_IO_ERROR);
|
dgl_set_error(DGL_IO_ERROR);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
DGLPCX.H
Normal file → Executable file
16
DGLPCX.H
Normal file → Executable file
|
@ -1,11 +1,19 @@
|
||||||
#ifndef DGL_DGLPCX_H_INCLUDED
|
#ifndef LIBDGL_DGLPCX_H
|
||||||
#define DGL_DGLPCX_H_INCLUDED
|
#define LIBDGL_DGLPCX_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
#include "dglgfx.h"
|
#include "dglgfx.h"
|
||||||
|
|
||||||
SURFACE* pcx_load(const char *filename, byte *pcx_palette);
|
#ifdef __cplusplus
|
||||||
boolean pcx_save(const char *filename, const SURFACE *src, const byte *palette);
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SURFACE* pcx_load(const char *filename, uint8 *pcx_palette);
|
||||||
|
bool pcx_save(const char *filename, const SURFACE *src, const uint8 *palette);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
12
DGLRECT.H
Normal file → Executable file
12
DGLRECT.H
Normal file → Executable file
|
@ -1,5 +1,9 @@
|
||||||
#ifndef DGL_DGLRECT_H_INCLUDED
|
#ifndef LIBDGL_DGLRECT_H
|
||||||
#define DGL_DGLRECT_H_INCLUDED
|
#define LIBDGL_DGLRECT_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x;
|
int x;
|
||||||
|
@ -37,5 +41,9 @@ static int rect_bottom(const RECT *r) {
|
||||||
return r->y;
|
return r->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
6
DGLUTIL.C
Normal file → Executable file
6
DGLUTIL.C
Normal file → Executable file
|
@ -4,11 +4,11 @@
|
||||||
#define SYS_CLOCKS_PER_SEC (1000.0f / 55.0f)
|
#define SYS_CLOCKS_PER_SEC (1000.0f / 55.0f)
|
||||||
|
|
||||||
|
|
||||||
int sys_clock() {
|
uint32 sys_clock() {
|
||||||
return *((int*)0x046c);
|
return *((uint32*)0x046c);
|
||||||
}
|
}
|
||||||
|
|
||||||
float clock_ticks_to_seconds(int clocks) {
|
float clock_ticks_to_seconds(uint32 clocks) {
|
||||||
return clocks / (float)SYS_CLOCKS_PER_SEC;
|
return clocks / (float)SYS_CLOCKS_PER_SEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
43
DGLUTIL.H
Normal file → Executable file
43
DGLUTIL.H
Normal file → Executable file
|
@ -1,8 +1,12 @@
|
||||||
#ifndef DGL_DGLUTIL_H_INCLUDED
|
#ifndef LIBDGL_DGLUTIL_H
|
||||||
#define DGL_DGLUTIL_H_INCLUDED
|
#define LIBDGL_DGLUTIL_H
|
||||||
|
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SWAP(type, a, b) \
|
#define SWAP(type, a, b) \
|
||||||
do { \
|
do { \
|
||||||
type __tmp = a; \
|
type __tmp = a; \
|
||||||
|
@ -12,8 +16,8 @@
|
||||||
|
|
||||||
#define SIGN(x) (((x) < 0) ? -1 : (((x) > 0) ? 1 : 0))
|
#define SIGN(x) (((x) < 0) ? -1 : (((x) > 0) ? 1 : 0))
|
||||||
|
|
||||||
int sys_clock();
|
uint32 sys_clock();
|
||||||
float clock_ticks_to_seconds(int clocks);
|
float clock_ticks_to_seconds(uint32 clocks);
|
||||||
|
|
||||||
int rnd_int(int low, int high);
|
int rnd_int(int low, int high);
|
||||||
float rnd_float(float low, float high);
|
float rnd_float(float low, float high);
|
||||||
|
@ -24,57 +28,56 @@ void int_enable(void);
|
||||||
void int_disable(void);
|
void int_disable(void);
|
||||||
#pragma aux int_disable = "cli"
|
#pragma aux int_disable = "cli"
|
||||||
|
|
||||||
int fill32(byte value);
|
int32 fill32(uint8 value);
|
||||||
#pragma aux fill32 = \
|
#pragma aux fill32 = \
|
||||||
"mov ah, al" \
|
"mov ah, al" \
|
||||||
"shl eax, 8" \
|
"shl eax, 8" \
|
||||||
"mov al, ah" \
|
"mov al, ah" \
|
||||||
"shl eax, 8" \
|
"shl eax, 8" \
|
||||||
"mov al, ah" \
|
"mov al, ah" \
|
||||||
parm [eax] \
|
parm [al] \
|
||||||
value [eax];
|
value [eax];
|
||||||
|
|
||||||
void REP_MOVSD(const void *src, void *dest, int num_dwords);
|
void REP_MOVSD(const void *src, void *dest, uint32 num_dwords);
|
||||||
#pragma aux REP_MOVSD = \
|
#pragma aux REP_MOVSD = \
|
||||||
"cld" \
|
"cld" \
|
||||||
"rep movsd" \
|
"rep movsd" \
|
||||||
parm [esi] [edi] [ecx];
|
parm [esi] [edi] [ecx];
|
||||||
|
|
||||||
void REP_MOVSB(const void *src, void *dest, int num_bytes);
|
void REP_MOVSB(const void *src, void *dest, uint32 num_bytes);
|
||||||
#pragma aux REP_MOVSB = \
|
#pragma aux REP_MOVSB = \
|
||||||
"cld" \
|
"cld" \
|
||||||
"rep movsb" \
|
"rep movsb" \
|
||||||
parm [esi] [edi] [ecx];
|
parm [esi] [edi] [ecx];
|
||||||
|
|
||||||
void REP_STOSD(int value, void *dest, int num_dwords);
|
void REP_STOSD(uint32 value, void *dest, uint32 num_dwords);
|
||||||
#pragma aux REP_STOSD = \
|
#pragma aux REP_STOSD = \
|
||||||
"cld" \
|
"cld" \
|
||||||
"rep stosd" \
|
"rep stosd" \
|
||||||
parm [eax] [edi] [ecx];
|
parm [eax] [edi] [ecx];
|
||||||
|
|
||||||
void REP_STOSB(int value, void *dest, int num_bytes);
|
void REP_STOSB(uint32 value, void *dest, uint32 num_bytes);
|
||||||
#pragma aux REP_STOSB = \
|
#pragma aux REP_STOSB = \
|
||||||
"cld" \
|
"cld" \
|
||||||
"rep stosb" \
|
"rep stosb" \
|
||||||
parm [eax] [edi] [ecx];
|
parm [eax] [edi] [ecx];
|
||||||
|
|
||||||
void mem_fill(void *dest, byte value, int num_bytes);
|
void mem_fill(void *dest, uint8 value, uint32 num_bytes);
|
||||||
#pragma aux mem_fill = \
|
#pragma aux mem_fill = \
|
||||||
"mov ah, al" \
|
"mov ah, al" \
|
||||||
"shl eax, 8" \
|
"mov bx, ax" \
|
||||||
"mov al, ah" \
|
"shl eax, 16" \
|
||||||
"shl eax, 8" \
|
"mov ax, bx" \
|
||||||
"mov al, ah" \
|
|
||||||
"mov ebx, ecx" \
|
"mov ebx, ecx" \
|
||||||
"shr ecx, 2" \
|
"shr ecx, 2" \
|
||||||
"and ebx, 3" \
|
"and ebx, 3" \
|
||||||
"rep stosd" \
|
"rep stosd" \
|
||||||
"mov ecx, ebx" \
|
"mov ecx, ebx" \
|
||||||
"rep stosb" \
|
"rep stosb" \
|
||||||
parm [edi] [eax] [ecx] \
|
parm [edi] [al] [ecx] \
|
||||||
modify [eax ebx ecx edi];
|
modify [eax ebx ecx edi];
|
||||||
|
|
||||||
void mem_fill32(void *dest, int value, int num_bytes);
|
void mem_fill32(void *dest, uint32 value, uint32 num_bytes);
|
||||||
#pragma aux mem_fill32 = \
|
#pragma aux mem_fill32 = \
|
||||||
"mov ebx, ecx" \
|
"mov ebx, ecx" \
|
||||||
"shr ecx, 2" \
|
"shr ecx, 2" \
|
||||||
|
@ -85,7 +88,7 @@ void mem_fill32(void *dest, int value, int num_bytes);
|
||||||
parm [edi] [eax] [ecx] \
|
parm [edi] [eax] [ecx] \
|
||||||
modify [eax ebx ecx edi];
|
modify [eax ebx ecx edi];
|
||||||
|
|
||||||
void mem_copy(void *dest, const void *src, int num_bytes);
|
void mem_copy(void *dest, const void *src, uint32 num_bytes);
|
||||||
#pragma aux mem_copy = \
|
#pragma aux mem_copy = \
|
||||||
"mov ebx, ecx" \
|
"mov ebx, ecx" \
|
||||||
"shr ecx, 2" \
|
"shr ecx, 2" \
|
||||||
|
@ -96,5 +99,9 @@ void mem_copy(void *dest, const void *src, int num_bytes);
|
||||||
parm [edi] [esi] [ecx] \
|
parm [edi] [esi] [ecx] \
|
||||||
modify [eax ebx ecx];
|
modify [eax ebx ecx];
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
360
DGLVEC2.H
Normal file → Executable file
360
DGLVEC2.H
Normal file → Executable file
|
@ -1,436 +1,294 @@
|
||||||
#ifndef DGL_DGLVEC2_H_INCLUDED
|
#ifndef LIBDGL_DGLVEC2_H
|
||||||
#define DGL_DGLVEC2_H_INCLUDED
|
#define LIBDGL_DGLVEC2_H
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "dglcmn.h"
|
#include "dglcmn.h"
|
||||||
#include "dglfixp.h"
|
#include "dglfixp.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
} VECTOR2I;
|
} VEC2I;
|
||||||
|
|
||||||
static VECTOR2I vector2i(int x, int y);
|
static VEC2I vec2i(int x, int y);
|
||||||
static void vector2i_set(VECTOR2I *v, int x, int y);
|
static void vec2i_set(VEC2I *v, int x, int y);
|
||||||
static boolean vector2i_equals(VECTOR2I a, VECTOR2I b);
|
static bool vec2i_equals(VEC2I a, VEC2I b);
|
||||||
static VECTOR2I vector2i_add(VECTOR2I a, VECTOR2I b);
|
static VEC2I vec2i_add(VEC2I a, VEC2I b);
|
||||||
static VECTOR2I vector2i_sub(VECTOR2I a, VECTOR2I b);
|
static VEC2I vec2i_sub(VEC2I a, VEC2I b);
|
||||||
static VECTOR2I vector2i_mul(VECTOR2I a, VECTOR2I b);
|
static VEC2I vec2i_mul(VEC2I a, VEC2I b);
|
||||||
static VECTOR2I vector2i_muls(VECTOR2I v, int n);
|
static VEC2I vec2i_muls(VEC2I v, int n);
|
||||||
static VECTOR2I vector2i_div(VECTOR2I a, VECTOR2I b);
|
static VEC2I vec2i_div(VEC2I a, VEC2I b);
|
||||||
static VECTOR2I vector2i_divs(VECTOR2I v, int n);
|
static VEC2I vec2i_divs(VEC2I v, int n);
|
||||||
static int vector2i_distance(VECTOR2I a, VECTOR2I b);
|
static int vec2i_distance(VEC2I a, VEC2I b);
|
||||||
static int vector2i_distancesq(VECTOR2I a, VECTOR2I b);
|
static int vec2i_distancesq(VEC2I a, VEC2I b);
|
||||||
static int vector2i_dot(VECTOR2I a, VECTOR2I b);
|
static int vec2i_dot(VEC2I a, VEC2I b);
|
||||||
static int vector2i_length(VECTOR2I v);
|
static int vec2i_length(VEC2I v);
|
||||||
static int vector2i_lengthsq(VECTOR2I v);
|
static int vec2i_lengthsq(VEC2I v);
|
||||||
static VECTOR2I vector2i_lerp(VECTOR2I a, VECTOR2I b, float lerp);
|
static VEC2I vec2i_lerp(VEC2I a, VEC2I b, float lerp);
|
||||||
|
|
||||||
#define ZERO_VECTOR2I vector2i(0, 0)
|
#define VEC2I_ZERO vec2i(0, 0)
|
||||||
#define UP_VECTOR2I vector2i(0, -1);
|
#define VEC2I_UP vec2i(0, -1);
|
||||||
#define DOWN_VECTOR2I vector2i(0, 1);
|
#define VEC2I_DOWN vec2i(0, 1);
|
||||||
#define LEFT_VECTOR2I vector2i(-1, 0);
|
#define VEC2I_LEFT vec2i(-1, 0);
|
||||||
#define RIGHT_VECTOR2I vector2i(1, 0);
|
#define VEC2I_RIGHT vec2i(1, 0);
|
||||||
#define UNIT_X_VECTOR2I vector2i(1, 0);
|
#define VEC2I_UNIT_X vec2i(1, 0);
|
||||||
#define UNIT_Y_VECTOR2I vector2i(0, 1);
|
#define VEC2I_UNIT_Y vec2i(0, 1);
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
} VECTOR2F;
|
|
||||||
|
|
||||||
static VECTOR2F vector2f(float x, float y);
|
|
||||||
static void vector2f_set(VECTOR2F *v, float x, float y);
|
|
||||||
static boolean vector2f_equals(VECTOR2F a, VECTOR2F b);
|
|
||||||
static VECTOR2F vector2f_add(VECTOR2F a, VECTOR2F b);
|
|
||||||
static VECTOR2F vector2f_sub(VECTOR2F a, VECTOR2F b);
|
|
||||||
static VECTOR2F vector2f_mul(VECTOR2F a, VECTOR2F b);
|
|
||||||
static VECTOR2F vector2f_muls(VECTOR2F v, float n);
|
|
||||||
static VECTOR2F vector2f_div(VECTOR2F a, VECTOR2F b);
|
|
||||||
static VECTOR2F vector2f_divs(VECTOR2F v, float n);
|
|
||||||
static float vector2f_distance(VECTOR2F a, VECTOR2F b);
|
|
||||||
static float vector2f_distancesq(VECTOR2F a, VECTOR2F b);
|
|
||||||
static float vector2f_dot(VECTOR2F a, VECTOR2F b);
|
|
||||||
static float vector2f_length(VECTOR2F v);
|
|
||||||
static float vector2f_lengthsq(VECTOR2F v);
|
|
||||||
static VECTOR2F vector2f_normalize(VECTOR2F v);
|
|
||||||
static VECTOR2F vector2f_set_length(VECTOR2F v, float length);
|
|
||||||
static VECTOR2F vector2f_lerp(VECTOR2F a, VECTOR2F b, float lerp);
|
|
||||||
|
|
||||||
#define ZERO_VECTOR2F vector2f(0.0f, 0.0f)
|
|
||||||
#define UP_VECTOR2F vector2f(0.0f, -1.0f);
|
|
||||||
#define DOWN_VECTOR2F vector2f(0.0f, 1.0f);
|
|
||||||
#define LEFT_VECTOR2F vector2f(-1.0f, 0.0f);
|
|
||||||
#define RIGHT_VECTOR2F vector2f(1.0f, 0.0f);
|
|
||||||
#define UNIT_X_VECTOR2F vector2f(1.0f, 0.0f);
|
|
||||||
#define UNIT_Y_VECTOR2F vector2f(0.0f, 1.0f);
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
fixed x;
|
fixed x;
|
||||||
fixed y;
|
fixed y;
|
||||||
} VECTOR2FP;
|
} VEC2;
|
||||||
|
|
||||||
static VECTOR2FP vector2fp(fixed x, fixed y);
|
static VEC2 vec2(fixed x, fixed y);
|
||||||
static void vector2fp_set(VECTOR2FP *v, fixed x, fixed y);
|
static void vec2_set(VEC2 *v, fixed x, fixed y);
|
||||||
static boolean vector2fp_equals(VECTOR2FP a, VECTOR2FP b);
|
static bool vec2_equals(VEC2 a, VEC2 b);
|
||||||
static VECTOR2FP vector2fp_add(VECTOR2FP a, VECTOR2FP b);
|
static VEC2 vec2_add(VEC2 a, VEC2 b);
|
||||||
static VECTOR2FP vector2fp_sub(VECTOR2FP a, VECTOR2FP b);
|
static VEC2 vec2_sub(VEC2 a, VEC2 b);
|
||||||
static VECTOR2FP vector2fp_mul(VECTOR2FP a, VECTOR2FP b);
|
static VEC2 vec2_mul(VEC2 a, VEC2 b);
|
||||||
static VECTOR2FP vector2fp_muls(VECTOR2FP v, fixed n);
|
static VEC2 vec2_muls(VEC2 v, fixed n);
|
||||||
static VECTOR2FP vector2fp_div(VECTOR2FP a, VECTOR2FP b);
|
static VEC2 vec2_div(VEC2 a, VEC2 b);
|
||||||
static VECTOR2FP vector2fp_divs(VECTOR2FP v, fixed n);
|
static VEC2 vec2_divs(VEC2 v, fixed n);
|
||||||
static fixed vector2fp_distance(VECTOR2FP a, VECTOR2FP b);
|
static fixed vec2_distance(VEC2 a, VEC2 b);
|
||||||
static fixed vector2fp_distancesq(VECTOR2FP a, VECTOR2FP b);
|
static fixed vec2_distancesq(VEC2 a, VEC2 b);
|
||||||
static fixed vector2fp_dot(VECTOR2FP a, VECTOR2FP b);
|
static fixed vec2_dot(VEC2 a, VEC2 b);
|
||||||
static fixed vector2fp_length(VECTOR2FP v);
|
static fixed vec2_length(VEC2 v);
|
||||||
static fixed vector2fp_lengthsq(VECTOR2FP v);
|
static fixed vec2_lengthsq(VEC2 v);
|
||||||
static VECTOR2FP vector2fp_normalize(VECTOR2FP v);
|
static VEC2 vec2_normalize(VEC2 v);
|
||||||
static VECTOR2FP vector2fp_set_length(VECTOR2FP v, fixed length);
|
static VEC2 vec2_set_length(VEC2 v, fixed length);
|
||||||
static VECTOR2FP vector2fp_lerp(VECTOR2FP a, VECTOR2FP b, fixed lerp);
|
static VEC2 vec2_lerp(VEC2 a, VEC2 b, fixed lerp);
|
||||||
|
|
||||||
#define ZERO_VECTOR2FP vector2fp(0, 0)
|
#define VEC2_ZERO vec2(0, 0)
|
||||||
#define UP_VECTOR2FP vector2fp(0, (-1 << 16));
|
#define VEC2_UP vec2(0, ITOFIX(-1));
|
||||||
#define DOWN_VECTOR2FP vector2fp(0, (1 << 16));
|
#define VEC2_DOWN vec2(0, ITOFIX(1));
|
||||||
#define LEFT_VECTOR2FP vector2fp((-1 << 16), 0);
|
#define VEC2_LEFT vec2(ITOFIX(-1), 0);
|
||||||
#define RIGHT_VECTOR2FP vector2fp((1 << 16), 0);
|
#define VEC2_RIGHT vec2(ITOFIX(1), 0);
|
||||||
#define UNIT_X_VECTOR2FP vector2fp((1 << 16), 0);
|
#define VEC2_UNIT_X vec2(ITOFIX(1), 0);
|
||||||
#define UNIT_Y_VECTOR2FP vector2fp(0, (1 << 16));
|
#define VEC2_UNIT_Y vec2(0, ITOFIX(1));
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
static VECTOR2I vector2i(int x, int y) {
|
static VEC2I vec2i(int x, int y) {
|
||||||
VECTOR2I v;
|
VEC2I v;
|
||||||
v.x = x;
|
v.x = x;
|
||||||
v.y = y;
|
v.y = y;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F vector2f(float x, float y) {
|
static VEC2 vec2(fixed x, fixed y) {
|
||||||
VECTOR2F v;
|
VEC2 v;
|
||||||
v.x = x;
|
v.x = x;
|
||||||
v.y = y;
|
v.y = y;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2FP vector2fp(fixed x, fixed y) {
|
static void vec2i_set(VEC2I *v, int x, int y) {
|
||||||
VECTOR2FP v;
|
|
||||||
v.x = x;
|
|
||||||
v.y = y;
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void vector2i_set(VECTOR2I *v, int x, int y) {
|
|
||||||
v->x = x;
|
v->x = x;
|
||||||
v->y = y;
|
v->y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vector2f_set(VECTOR2F *v, float x, float y) {
|
static void vec2_set(VEC2 *v, fixed x, fixed y) {
|
||||||
v->x = x;
|
v->x = x;
|
||||||
v->y = y;
|
v->y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vector2fp_set(VECTOR2FP *v, fixed x, fixed y) {
|
static bool vec2i_equals(VEC2I a, VEC2I b) {
|
||||||
v->x = x;
|
|
||||||
v->y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean vector2i_equals(VECTOR2I a, VECTOR2I b) {
|
|
||||||
return (a.x == b.x && a.y == b.y);
|
return (a.x == b.x && a.y == b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean vector2f_equals(VECTOR2F a, VECTOR2F b) {
|
static bool vec2_equals(VEC2 a, VEC2 b) {
|
||||||
return (a.x == b.x && a.y == b.y);
|
return (a.x == b.x && a.y == b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean vector2fp_equals(VECTOR2FP a, VECTOR2FP b) {
|
static VEC2I vec2i_add(VEC2I a, VEC2I b) {
|
||||||
return (a.x == b.x && a.y == b.y);
|
VEC2I result;
|
||||||
}
|
|
||||||
|
|
||||||
static VECTOR2I vector2i_add(VECTOR2I a, VECTOR2I b) {
|
|
||||||
VECTOR2I result;
|
|
||||||
result.x = a.x + b.x;
|
result.x = a.x + b.x;
|
||||||
result.y = a.y + b.y;
|
result.y = a.y + b.y;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F vector2f_add(VECTOR2F a, VECTOR2F b) {
|
static VEC2 vec2_add(VEC2 a, VEC2 b) {
|
||||||
VECTOR2F result;
|
VEC2 result;
|
||||||
result.x = a.x + b.x;
|
result.x = a.x + b.x;
|
||||||
result.y = a.y + b.y;
|
result.y = a.y + b.y;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2FP vector2fp_add(VECTOR2FP a, VECTOR2FP b) {
|
static VEC2I vec2i_sub(VEC2I a, VEC2I b) {
|
||||||
VECTOR2FP result;
|
VEC2I result;
|
||||||
result.x = a.x + b.x;
|
|
||||||
result.y = a.y + b.y;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VECTOR2I vector2i_sub(VECTOR2I a, VECTOR2I b) {
|
|
||||||
VECTOR2I result;
|
|
||||||
result.x = a.x - b.x;
|
result.x = a.x - b.x;
|
||||||
result.y = a.y - b.y;
|
result.y = a.y - b.y;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F vector2f_sub(VECTOR2F a, VECTOR2F b) {
|
static VEC2 vec2_sub(VEC2 a, VEC2 b) {
|
||||||
VECTOR2F result;
|
VEC2 result;
|
||||||
result.x = a.x - b.x;
|
result.x = a.x - b.x;
|
||||||
result.y = a.y - b.y;
|
result.y = a.y - b.y;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2FP vector2fp_sub(VECTOR2FP a, VECTOR2FP b) {
|
static VEC2I vec2i_mul(VEC2I a, VEC2I b) {
|
||||||
VECTOR2FP result;
|
VEC2I result;
|
||||||
result.x = a.x - b.x;
|
|
||||||
result.y = a.y - b.y;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VECTOR2I vector2i_mul(VECTOR2I a, VECTOR2I b) {
|
|
||||||
VECTOR2I result;
|
|
||||||
result.x = a.x * b.x;
|
result.x = a.x * b.x;
|
||||||
result.y = a.y * b.y;
|
result.y = a.y * b.y;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F vector2f_mul(VECTOR2F a, VECTOR2F b) {
|
static VEC2 vec2_mul(VEC2 a, VEC2 b) {
|
||||||
VECTOR2F result;
|
VEC2 result;
|
||||||
result.x = a.x * b.x;
|
|
||||||
result.y = a.y * b.y;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VECTOR2FP vector2fp_mul(VECTOR2FP a, VECTOR2FP b) {
|
|
||||||
VECTOR2FP result;
|
|
||||||
result.x = fix_mul(a.x, b.x);
|
result.x = fix_mul(a.x, b.x);
|
||||||
result.y = fix_mul(a.y, b.y);
|
result.y = fix_mul(a.y, b.y);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2I vector2i_muls(VECTOR2I v, int n) {
|
static VEC2I vec2i_muls(VEC2I v, int n) {
|
||||||
VECTOR2I result;
|
VEC2I result;
|
||||||
result.x = v.x * n;
|
result.x = v.x * n;
|
||||||
result.y = v.y * n;
|
result.y = v.y * n;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F vector2f_muls(VECTOR2F v, float n) {
|
static VEC2 vec2_muls(VEC2 v, fixed n) {
|
||||||
VECTOR2F result;
|
VEC2 result;
|
||||||
result.x = v.x * n;
|
|
||||||
result.y = v.y * n;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VECTOR2FP vector2fp_muls(VECTOR2FP v, fixed n) {
|
|
||||||
VECTOR2FP result;
|
|
||||||
result.x = fix_mul(v.x, n);
|
result.x = fix_mul(v.x, n);
|
||||||
result.y = fix_mul(v.y, n);
|
result.y = fix_mul(v.y, n);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2I vector2i_div(VECTOR2I a, VECTOR2I b) {
|
static VEC2I vec2i_div(VEC2I a, VEC2I b) {
|
||||||
VECTOR2I result;
|
VEC2I result;
|
||||||
result.x = a.x / b.x;
|
result.x = a.x / b.x;
|
||||||
result.y = a.y / b.y;
|
result.y = a.y / b.y;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F vector2f_div(VECTOR2F a, VECTOR2F b) {
|
static VEC2 vec2_div(VEC2 a, VEC2 b) {
|
||||||
VECTOR2F result;
|
VEC2 result;
|
||||||
result.x = a.x / b.x;
|
|
||||||
result.y = a.y / b.y;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VECTOR2FP vector2fp_div(VECTOR2FP a, VECTOR2FP b) {
|
|
||||||
VECTOR2FP result;
|
|
||||||
result.x = fix_div(a.x, b.x);
|
result.x = fix_div(a.x, b.x);
|
||||||
result.y = fix_div(a.y, b.y);
|
result.y = fix_div(a.y, b.y);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2I vector2i_divs(VECTOR2I v, int n) {
|
static VEC2I vec2i_divs(VEC2I v, int n) {
|
||||||
VECTOR2I result;
|
VEC2I result;
|
||||||
result.x = v.x / n;
|
result.x = v.x / n;
|
||||||
result.y = v.y / n;
|
result.y = v.y / n;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F vector2f_divs(VECTOR2F v, float n) {
|
static VEC2 vec2_divs(VEC2 v, fixed n) {
|
||||||
VECTOR2F result;
|
VEC2 result;
|
||||||
result.x = v.x / n;
|
|
||||||
result.y = v.y / n;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VECTOR2FP vector2fp_divs(VECTOR2FP v, fixed n) {
|
|
||||||
VECTOR2FP result;
|
|
||||||
result.x = fix_div(v.x, n);
|
result.x = fix_div(v.x, n);
|
||||||
result.y = fix_div(v.y, n);
|
result.y = fix_div(v.y, n);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vector2i_distance(VECTOR2I a, VECTOR2I b) {
|
static int vec2i_distance(VEC2I a, VEC2I b) {
|
||||||
return (int)sqrt(
|
return (int)sqrt(
|
||||||
((b.x - a.x) * (b.x - a.x)) +
|
((b.x - a.x) * (b.x - a.x)) +
|
||||||
((b.y - a.y) * (b.y - a.y))
|
((b.y - a.y) * (b.y - a.y))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float vector2f_distance(VECTOR2F a, VECTOR2F b) {
|
static fixed vec2_distance(VEC2 a, VEC2 b) {
|
||||||
return (float)sqrt(
|
|
||||||
((b.x - a.x) * (b.x - a.x)) +
|
|
||||||
((b.y - a.y) * (b.y - a.y))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static fixed vector2fp_distance(VECTOR2FP a, VECTOR2FP b) {
|
|
||||||
return fix_sqrt(
|
return fix_sqrt(
|
||||||
fix_mul((b.x - a.x), (b.x - a.x)) +
|
fix_mul((b.x - a.x), (b.x - a.x)) +
|
||||||
fix_mul((b.y - a.y), (b.y - a.y))
|
fix_mul((b.y - a.y), (b.y - a.y))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vector2i_distancesq(VECTOR2I a, VECTOR2I b) {
|
static int vec2i_distancesq(VEC2I a, VEC2I b) {
|
||||||
return
|
return
|
||||||
((b.x - a.x) * (b.x - a.x)) +
|
((b.x - a.x) * (b.x - a.x)) +
|
||||||
((b.y - a.y) * (b.y - a.y));
|
((b.y - a.y) * (b.y - a.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
static float vector2f_distancesq(VECTOR2F a, VECTOR2F b) {
|
static fixed vec2_distancesq(VEC2 a, VEC2 b) {
|
||||||
return
|
|
||||||
((b.x - a.x) * (b.x - a.x)) +
|
|
||||||
((b.y - a.y) * (b.y - a.y));
|
|
||||||
}
|
|
||||||
|
|
||||||
static fixed vector2fp_distancesq(VECTOR2FP a, VECTOR2FP b) {
|
|
||||||
return
|
return
|
||||||
fix_mul((b.x - a.x), (b.x - a.x)) +
|
fix_mul((b.x - a.x), (b.x - a.x)) +
|
||||||
fix_mul((b.y - a.y), (b.y - a.y));
|
fix_mul((b.y - a.y), (b.y - a.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vector2i_dot(VECTOR2I a, VECTOR2I b) {
|
static int vec2i_dot(VEC2I a, VEC2I b) {
|
||||||
return
|
return
|
||||||
(a.x * b.x) +
|
(a.x * b.x) +
|
||||||
(a.y * b.y);
|
(a.y * b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float vector2f_dot(VECTOR2F a, VECTOR2F b) {
|
static fixed vec2_dot(VEC2 a, VEC2 b) {
|
||||||
return
|
|
||||||
(a.x * b.x) +
|
|
||||||
(a.y * b.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
static fixed vector2fp_dot(VECTOR2FP a, VECTOR2FP b) {
|
|
||||||
return
|
return
|
||||||
fix_mul(a.x, b.x) +
|
fix_mul(a.x, b.x) +
|
||||||
fix_mul(a.y, b.y);
|
fix_mul(a.y, b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vector2i_length(VECTOR2I v) {
|
static int vec2i_length(VEC2I v) {
|
||||||
return sqrt(
|
return sqrt(
|
||||||
(v.x * v.x) +
|
(v.x * v.x) +
|
||||||
(v.y * v.y)
|
(v.y * v.y)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float vector2f_length(VECTOR2F v) {
|
static fixed vec2_length(VEC2 v) {
|
||||||
return (float)sqrt(
|
|
||||||
(v.x * v.x) +
|
|
||||||
(v.y * v.y)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static fixed vector2fp_length(VECTOR2FP v) {
|
|
||||||
return fix_sqrt(
|
return fix_sqrt(
|
||||||
fix_mul(v.x, v.x) +
|
fix_mul(v.x, v.x) +
|
||||||
fix_mul(v.y, v.y)
|
fix_mul(v.y, v.y)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vector2i_lengthsq(VECTOR2I v) {
|
static int vec2i_lengthsq(VEC2I v) {
|
||||||
return
|
return
|
||||||
(v.x * v.x) +
|
(v.x * v.x) +
|
||||||
(v.y * v.y);
|
(v.y * v.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float vector2f_lengthsq(VECTOR2F v) {
|
static fixed vec2_lengthsq(VEC2 v) {
|
||||||
return
|
|
||||||
(v.x * v.x) +
|
|
||||||
(v.y * v.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
static fixed vector2fp_lengthsq(VECTOR2FP v) {
|
|
||||||
return
|
return
|
||||||
fix_mul(v.x, v.x) +
|
fix_mul(v.x, v.x) +
|
||||||
fix_mul(v.y, v.y);
|
fix_mul(v.y, v.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F vector2f_normalize(VECTOR2F v) {
|
static VEC2 vec2_normalize(VEC2 v) {
|
||||||
float inverse_length;
|
|
||||||
VECTOR2F result;
|
|
||||||
|
|
||||||
inverse_length = 1.0f / vector2f_length(v);
|
|
||||||
result.x = v.x * inverse_length;
|
|
||||||
result.y = v.y * inverse_length;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VECTOR2FP vector2fp_normalize(VECTOR2FP v) {
|
|
||||||
fixed inverse_length;
|
fixed inverse_length;
|
||||||
VECTOR2FP result;
|
VEC2 result;
|
||||||
|
|
||||||
inverse_length = fix_div(FP_1, vector2fp_length(v));
|
inverse_length = fix_div(FP_1, vec2_length(v));
|
||||||
result.x = fix_mul(v.x, inverse_length);
|
result.x = fix_mul(v.x, inverse_length);
|
||||||
result.y = fix_mul(v.y, inverse_length);
|
result.y = fix_mul(v.y, inverse_length);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F vector2f_set_length(VECTOR2F v, float length) {
|
static VEC2 vec2_set_length(VEC2 v, fixed length) {
|
||||||
float scale_factor;
|
|
||||||
VECTOR2F result;
|
|
||||||
|
|
||||||
scale_factor = length / vector2f_length(v);
|
|
||||||
result.x = v.x * scale_factor;
|
|
||||||
result.y = v.y * scale_factor;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VECTOR2FP vector2fp_set_length(VECTOR2FP v, fixed length) {
|
|
||||||
fixed scale_factor;
|
fixed scale_factor;
|
||||||
VECTOR2FP result;
|
VEC2 result;
|
||||||
|
|
||||||
scale_factor = fix_div(length, vector2fp_length(v));
|
scale_factor = fix_div(length, vec2_length(v));
|
||||||
result.x = fix_mul(v.x, scale_factor);
|
result.x = fix_mul(v.x, scale_factor);
|
||||||
result.y = fix_mul(v.y, scale_factor);
|
result.y = fix_mul(v.y, scale_factor);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2I vector2i_lerp(VECTOR2I a, VECTOR2I b, float lerp) {
|
static VEC2I vec2i_lerp(VEC2I a, VEC2I b, float lerp) {
|
||||||
VECTOR2I result;
|
VEC2I result;
|
||||||
result.x = a.x + (b.x - a.x) * lerp;
|
result.x = a.x + (b.x - a.x) * lerp;
|
||||||
result.y = a.y + (b.y - a.y) * lerp;
|
result.y = a.y + (b.y - a.y) * lerp;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2F vector2f_lerp(VECTOR2F a, VECTOR2F b, float lerp) {
|
static VEC2 vec2_lerp(VEC2 a, VEC2 b, fixed lerp) {
|
||||||
VECTOR2F result;
|
VEC2 result;
|
||||||
result.x = a.x + (b.x - a.x) * lerp;
|
|
||||||
result.y = a.y + (b.y - a.y) * lerp;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VECTOR2FP vector2fp_lerp(VECTOR2FP a, VECTOR2FP b, fixed lerp) {
|
|
||||||
VECTOR2FP result;
|
|
||||||
result.x = a.x + fix_mul((b.x - a.x), lerp);
|
result.x = a.x + fix_mul((b.x - a.x), lerp);
|
||||||
result.y = a.y + fix_mul((b.y - a.y), lerp);
|
result.y = a.y + fix_mul((b.y - a.y), lerp);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
209
TEST/BLIT.C
Normal file → Executable file
209
TEST/BLIT.C
Normal file → Executable file
|
@ -1,9 +1,10 @@
|
||||||
#include "blit.h"
|
#include "blit.h"
|
||||||
#include "dgl.h"
|
#include "dglblit.h"
|
||||||
|
#include "dgldraw.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
SURFACE* get_sprite(int width, int height) {
|
SURFACE* create_sprite(int width, int height) {
|
||||||
int x_third, y_third;
|
int x_third, y_third;
|
||||||
SURFACE *sprite = surface_create(width, height);
|
SURFACE *sprite = surface_create(width, height);
|
||||||
ASSERT(sprite != NULL);
|
ASSERT(sprite != NULL);
|
||||||
|
@ -13,28 +14,28 @@ SURFACE* get_sprite(int width, int height) {
|
||||||
x_third = width / 3;
|
x_third = width / 3;
|
||||||
y_third = height / 3;
|
y_third = height / 3;
|
||||||
|
|
||||||
surface_filled_rect(sprite, 0, 0, x_third, y_third, 1);
|
draw_filled_rect(sprite, 0, 0, x_third, y_third, 1);
|
||||||
surface_filled_rect(sprite, x_third * 2, y_third * 2, width - 1, height - 1, 2);
|
draw_filled_rect(sprite, x_third * 2, y_third * 2, width - 1, height - 1, 2);
|
||||||
surface_filled_rect(sprite, 0, (y_third * 2), x_third, height - 1, 3);
|
draw_filled_rect(sprite, 0, (y_third * 2), x_third, height - 1, 3);
|
||||||
surface_filled_rect(sprite, x_third * 2, 0, width - 1, y_third, 4);
|
draw_filled_rect(sprite, x_third * 2, 0, width - 1, y_third, 4);
|
||||||
surface_filled_rect(sprite, x_third, y_third, x_third * 2, y_third * 2, 5);
|
draw_filled_rect(sprite, x_third, y_third, x_third * 2, y_third * 2, 5);
|
||||||
surface_rect(sprite, 0, 0, width - 1, height - 1, 6);
|
draw_rect(sprite, 0, 0, width - 1, height - 1, 6);
|
||||||
|
|
||||||
return sprite;
|
return sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
SURFACE* get_image(int width, int height) {
|
SURFACE* create_image(int width, int height) {
|
||||||
int x, y;
|
int x, y;
|
||||||
SURFACE *image = surface_create(width, height);
|
SURFACE *image = surface_create(width, height);
|
||||||
ASSERT(image != NULL);
|
ASSERT(image != NULL);
|
||||||
ASSERT(image->width == width);
|
ASSERT(image->width == width);
|
||||||
ASSERT(image->height == height);
|
ASSERT(image->height == height);
|
||||||
|
|
||||||
surface_filled_rect(image, 0, 0, width / 2, height / 2, 1);
|
draw_filled_rect(image, 0, 0, width / 2, height / 2, 1);
|
||||||
surface_filled_rect(image, width / 2, 0, width - 1, height / 2, 2);
|
draw_filled_rect(image, width / 2, 0, width - 1, height / 2, 2);
|
||||||
surface_filled_rect(image, 0, height / 2, width / 2, height - 1, 3);
|
draw_filled_rect(image, 0, height / 2, width / 2, height - 1, 3);
|
||||||
surface_filled_rect(image, width / 2, height / 2, width - 1, height - 1, 4);
|
draw_filled_rect(image, width / 2, height / 2, width - 1, height - 1, 4);
|
||||||
surface_rect(image, 0, 0, width - 1, height - 1, 5);
|
draw_rect(image, 0, 0, width - 1, height - 1, 5);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
@ -47,32 +48,32 @@ SURFACE* get_image(int width, int height) {
|
||||||
void test_blit(void) {
|
void test_blit(void) {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
SURFACE *bmp16 = get_image(16, 16);
|
SURFACE *bmp16 = create_image(16, 16);
|
||||||
SURFACE *bmp12 = get_image(12, 12);
|
SURFACE *bmp12 = create_image(12, 12);
|
||||||
SURFACE *bmp21 = get_image(21, 21);
|
SURFACE *bmp21 = create_image(21, 21);
|
||||||
SURFACE *bmp3 = get_image(3, 3);
|
SURFACE *bmp3 = create_image(3, 3);
|
||||||
|
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
x = 0; y = 0;
|
x = 0; y = 0;
|
||||||
|
|
||||||
surface_blit_region(bmp16, screen, 0, 0, 16, 16, x + 16, y + 16);
|
blit_region(bmp16, screen, 0, 0, 16, 16, x + 16, y + 16);
|
||||||
surface_blit_region(bmp16, screen, 8, 8, 8, 8, x + 48, y + 16);
|
blit_region(bmp16, screen, 8, 8, 8, 8, x + 48, y + 16);
|
||||||
|
|
||||||
surface_blit(bmp16, screen, x + 16, y + 48);
|
blit(bmp16, screen, x + 16, y + 48);
|
||||||
surface_blit(bmp12, screen, x + 48, y + 48);
|
blit(bmp12, screen, x + 48, y + 48);
|
||||||
surface_blit(bmp21, screen, x + 80, y + 48);
|
blit(bmp21, screen, x + 80, y + 48);
|
||||||
surface_blit(bmp3, screen, x + 112, y + 48);
|
blit(bmp3, screen, x + 112, y + 48);
|
||||||
|
|
||||||
x = 160; y = 0;
|
x = 160; y = 0;
|
||||||
|
|
||||||
surface_blit_region_f(bmp16, screen, 0, 0, 16, 16, x + 16, y + 16);
|
blit_region_f(bmp16, screen, 0, 0, 16, 16, x + 16, y + 16);
|
||||||
surface_blit_region_f(bmp16, screen, 8, 8, 8, 8, x + 48, y + 16);
|
blit_region_f(bmp16, screen, 8, 8, 8, 8, x + 48, y + 16);
|
||||||
|
|
||||||
surface_blit_f(bmp16, screen, x + 16, y + 48);
|
blit_f(bmp16, screen, x + 16, y + 48);
|
||||||
surface_blit_f(bmp12, screen, x + 48, y + 48);
|
blit_f(bmp12, screen, x + 48, y + 48);
|
||||||
surface_blit_f(bmp21, screen, x + 80, y + 48);
|
blit_f(bmp21, screen, x + 80, y + 48);
|
||||||
surface_blit_f(bmp3, screen, x + 112, y + 48);
|
blit_f(bmp3, screen, x + 112, y + 48);
|
||||||
|
|
||||||
surface_free(bmp16);
|
surface_free(bmp16);
|
||||||
surface_free(bmp12);
|
surface_free(bmp12);
|
||||||
|
@ -85,41 +86,41 @@ void test_blit(void) {
|
||||||
// varying amounts. the 7th blit on each edge is completely out of bounds and
|
// varying amounts. the 7th blit on each edge is completely out of bounds and
|
||||||
// should not be visible at all.
|
// should not be visible at all.
|
||||||
void test_blit_clipping(void) {
|
void test_blit_clipping(void) {
|
||||||
SURFACE *bmp = get_image(16, 16);
|
SURFACE *bmp = create_image(16, 16);
|
||||||
|
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
surface_blit(bmp, screen, -3, 16);
|
blit(bmp, screen, -3, 16);
|
||||||
surface_blit(bmp, screen, -4, 36);
|
blit(bmp, screen, -4, 36);
|
||||||
surface_blit(bmp, screen, -8, 56);
|
blit(bmp, screen, -8, 56);
|
||||||
surface_blit(bmp, screen, -12, 76);
|
blit(bmp, screen, -12, 76);
|
||||||
surface_blit(bmp, screen, -13, 96);
|
blit(bmp, screen, -13, 96);
|
||||||
surface_blit(bmp, screen, -14, 116);
|
blit(bmp, screen, -14, 116);
|
||||||
surface_blit(bmp, screen, -16, 136);
|
blit(bmp, screen, -16, 136);
|
||||||
|
|
||||||
surface_blit(bmp, screen, 16, -3);
|
blit(bmp, screen, 16, -3);
|
||||||
surface_blit(bmp, screen, 36, -4);
|
blit(bmp, screen, 36, -4);
|
||||||
surface_blit(bmp, screen, 56, -8);
|
blit(bmp, screen, 56, -8);
|
||||||
surface_blit(bmp, screen, 76, -12);
|
blit(bmp, screen, 76, -12);
|
||||||
surface_blit(bmp, screen, 96, -13);
|
blit(bmp, screen, 96, -13);
|
||||||
surface_blit(bmp, screen, 116, -14);
|
blit(bmp, screen, 116, -14);
|
||||||
surface_blit(bmp, screen, 136, -16);
|
blit(bmp, screen, 136, -16);
|
||||||
|
|
||||||
surface_blit(bmp, screen, 307, 16);
|
blit(bmp, screen, 307, 16);
|
||||||
surface_blit(bmp, screen, 308, 36);
|
blit(bmp, screen, 308, 36);
|
||||||
surface_blit(bmp, screen, 312, 56);
|
blit(bmp, screen, 312, 56);
|
||||||
surface_blit(bmp, screen, 316, 76);
|
blit(bmp, screen, 316, 76);
|
||||||
surface_blit(bmp, screen, 317, 96);
|
blit(bmp, screen, 317, 96);
|
||||||
surface_blit(bmp, screen, 318, 116);
|
blit(bmp, screen, 318, 116);
|
||||||
surface_blit(bmp, screen, 320, 136);
|
blit(bmp, screen, 320, 136);
|
||||||
|
|
||||||
surface_blit(bmp, screen, 16, 187);
|
blit(bmp, screen, 16, 187);
|
||||||
surface_blit(bmp, screen, 36, 188);
|
blit(bmp, screen, 36, 188);
|
||||||
surface_blit(bmp, screen, 56, 192);
|
blit(bmp, screen, 56, 192);
|
||||||
surface_blit(bmp, screen, 76, 196);
|
blit(bmp, screen, 76, 196);
|
||||||
surface_blit(bmp, screen, 96, 197);
|
blit(bmp, screen, 96, 197);
|
||||||
surface_blit(bmp, screen, 116, 198);
|
blit(bmp, screen, 116, 198);
|
||||||
surface_blit(bmp, screen, 136, 200);
|
blit(bmp, screen, 136, 200);
|
||||||
|
|
||||||
surface_free(bmp);
|
surface_free(bmp);
|
||||||
getch();
|
getch();
|
||||||
|
@ -130,32 +131,32 @@ void test_blit_clipping(void) {
|
||||||
// black as that colour is not used anywhere in the test sprite.
|
// black as that colour is not used anywhere in the test sprite.
|
||||||
void test_sprite(void) {
|
void test_sprite(void) {
|
||||||
int x, y;
|
int x, y;
|
||||||
SURFACE *bmp16 = get_sprite(16, 16);
|
SURFACE *bmp16 = create_sprite(16, 16);
|
||||||
SURFACE *bmp12 = get_sprite(12, 12);
|
SURFACE *bmp12 = create_sprite(12, 12);
|
||||||
SURFACE *bmp21 = get_sprite(21, 21);
|
SURFACE *bmp21 = create_sprite(21, 21);
|
||||||
SURFACE *bmp3 = get_sprite(3, 3);
|
SURFACE *bmp3 = create_sprite(3, 3);
|
||||||
|
|
||||||
surface_clear(screen, 8);
|
surface_clear(screen, 8);
|
||||||
|
|
||||||
x = 0; y = 0;
|
x = 0; y = 0;
|
||||||
|
|
||||||
surface_blit_sprite_region(bmp16, screen, 0, 0, 16, 16, x + 16, y + 16);
|
blit_sprite_region(bmp16, screen, 0, 0, 16, 16, x + 16, y + 16);
|
||||||
surface_blit_sprite_region(bmp16, screen, 8, 8, 8, 8, x + 48, y + 16);
|
blit_sprite_region(bmp16, screen, 8, 8, 8, 8, x + 48, y + 16);
|
||||||
|
|
||||||
surface_blit_sprite(bmp16, screen, x + 16, y + 48);
|
blit_sprite(bmp16, screen, x + 16, y + 48);
|
||||||
surface_blit_sprite(bmp12, screen, x + 48, y + 48);
|
blit_sprite(bmp12, screen, x + 48, y + 48);
|
||||||
surface_blit_sprite(bmp21, screen, x + 80, y + 48);
|
blit_sprite(bmp21, screen, x + 80, y + 48);
|
||||||
surface_blit_sprite(bmp3, screen, x + 112, y + 48);
|
blit_sprite(bmp3, screen, x + 112, y + 48);
|
||||||
|
|
||||||
x = 160; y = 0;
|
x = 160; y = 0;
|
||||||
|
|
||||||
surface_blit_sprite_region_f(bmp16, screen, 0, 0, 16, 16, x + 16, y + 16);
|
blit_sprite_region_f(bmp16, screen, 0, 0, 16, 16, x + 16, y + 16);
|
||||||
surface_blit_sprite_region_f(bmp16, screen, 8, 8, 8, 8, x + 48, y + 16);
|
blit_sprite_region_f(bmp16, screen, 8, 8, 8, 8, x + 48, y + 16);
|
||||||
|
|
||||||
surface_blit_sprite_f(bmp16, screen, x + 16, y + 48);
|
blit_sprite_f(bmp16, screen, x + 16, y + 48);
|
||||||
surface_blit_sprite_f(bmp12, screen, x + 48, y + 48);
|
blit_sprite_f(bmp12, screen, x + 48, y + 48);
|
||||||
surface_blit_sprite_f(bmp21, screen, x + 80, y + 48);
|
blit_sprite_f(bmp21, screen, x + 80, y + 48);
|
||||||
surface_blit_sprite_f(bmp3, screen, x + 112, y + 48);
|
blit_sprite_f(bmp3, screen, x + 112, y + 48);
|
||||||
|
|
||||||
surface_free(bmp16);
|
surface_free(bmp16);
|
||||||
surface_free(bmp12);
|
surface_free(bmp12);
|
||||||
|
@ -168,41 +169,41 @@ void test_sprite(void) {
|
||||||
// blitting instead and uses a grey background. no part of the screen buffer
|
// blitting instead and uses a grey background. no part of the screen buffer
|
||||||
// should be black as that colour is not used anywhere in the test sprite.
|
// should be black as that colour is not used anywhere in the test sprite.
|
||||||
void test_sprite_clipping(void) {
|
void test_sprite_clipping(void) {
|
||||||
SURFACE *bmp = get_sprite(16, 16);
|
SURFACE *bmp = create_sprite(16, 16);
|
||||||
|
|
||||||
surface_clear(screen, 8);
|
surface_clear(screen, 8);
|
||||||
|
|
||||||
surface_blit_sprite(bmp, screen, -3, 16);
|
blit_sprite(bmp, screen, -3, 16);
|
||||||
surface_blit_sprite(bmp, screen, -4, 36);
|
blit_sprite(bmp, screen, -4, 36);
|
||||||
surface_blit_sprite(bmp, screen, -8, 56);
|
blit_sprite(bmp, screen, -8, 56);
|
||||||
surface_blit_sprite(bmp, screen, -12, 76);
|
blit_sprite(bmp, screen, -12, 76);
|
||||||
surface_blit_sprite(bmp, screen, -13, 96);
|
blit_sprite(bmp, screen, -13, 96);
|
||||||
surface_blit_sprite(bmp, screen, -14, 116);
|
blit_sprite(bmp, screen, -14, 116);
|
||||||
surface_blit_sprite(bmp, screen, -16, 136);
|
blit_sprite(bmp, screen, -16, 136);
|
||||||
|
|
||||||
surface_blit_sprite(bmp, screen, 16, -3);
|
blit_sprite(bmp, screen, 16, -3);
|
||||||
surface_blit_sprite(bmp, screen, 36, -4);
|
blit_sprite(bmp, screen, 36, -4);
|
||||||
surface_blit_sprite(bmp, screen, 56, -8);
|
blit_sprite(bmp, screen, 56, -8);
|
||||||
surface_blit_sprite(bmp, screen, 76, -12);
|
blit_sprite(bmp, screen, 76, -12);
|
||||||
surface_blit_sprite(bmp, screen, 96, -13);
|
blit_sprite(bmp, screen, 96, -13);
|
||||||
surface_blit_sprite(bmp, screen, 116, -14);
|
blit_sprite(bmp, screen, 116, -14);
|
||||||
surface_blit_sprite(bmp, screen, 136, -16);
|
blit_sprite(bmp, screen, 136, -16);
|
||||||
|
|
||||||
surface_blit_sprite(bmp, screen, 307, 16);
|
blit_sprite(bmp, screen, 307, 16);
|
||||||
surface_blit_sprite(bmp, screen, 308, 36);
|
blit_sprite(bmp, screen, 308, 36);
|
||||||
surface_blit_sprite(bmp, screen, 312, 56);
|
blit_sprite(bmp, screen, 312, 56);
|
||||||
surface_blit_sprite(bmp, screen, 316, 76);
|
blit_sprite(bmp, screen, 316, 76);
|
||||||
surface_blit_sprite(bmp, screen, 317, 96);
|
blit_sprite(bmp, screen, 317, 96);
|
||||||
surface_blit_sprite(bmp, screen, 318, 116);
|
blit_sprite(bmp, screen, 318, 116);
|
||||||
surface_blit_sprite(bmp, screen, 320, 136);
|
blit_sprite(bmp, screen, 320, 136);
|
||||||
|
|
||||||
surface_blit_sprite(bmp, screen, 16, 187);
|
blit_sprite(bmp, screen, 16, 187);
|
||||||
surface_blit_sprite(bmp, screen, 36, 188);
|
blit_sprite(bmp, screen, 36, 188);
|
||||||
surface_blit_sprite(bmp, screen, 56, 192);
|
blit_sprite(bmp, screen, 56, 192);
|
||||||
surface_blit_sprite(bmp, screen, 76, 196);
|
blit_sprite(bmp, screen, 76, 196);
|
||||||
surface_blit_sprite(bmp, screen, 96, 197);
|
blit_sprite(bmp, screen, 96, 197);
|
||||||
surface_blit_sprite(bmp, screen, 116, 198);
|
blit_sprite(bmp, screen, 116, 198);
|
||||||
surface_blit_sprite(bmp, screen, 136, 200);
|
blit_sprite(bmp, screen, 136, 200);
|
||||||
|
|
||||||
surface_free(bmp);
|
surface_free(bmp);
|
||||||
getch();
|
getch();
|
||||||
|
|
0
TEST/BLIT.H
Normal file → Executable file
0
TEST/BLIT.H
Normal file → Executable file
24
TEST/EVENTS.C
Normal file → Executable file
24
TEST/EVENTS.C
Normal file → Executable file
|
@ -1,10 +1,12 @@
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "dgl.h"
|
#include "dglkbrd.h"
|
||||||
|
#include "dglmouse.h"
|
||||||
|
#include "dglevent.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
void test_events(void) {
|
void test_events(void) {
|
||||||
boolean result;
|
bool result;
|
||||||
INPUTEVENT *event;
|
INPUTEVENT *event;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
|
@ -12,15 +14,15 @@ void test_events(void) {
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
result = keyboard_init();
|
result = keyboard_init();
|
||||||
ASSERT(result == TRUE);
|
ASSERT(result == true);
|
||||||
result = mouse_init();
|
result = mouse_init();
|
||||||
ASSERT(result == TRUE);
|
ASSERT(result == true);
|
||||||
|
|
||||||
ASSERT(events_is_initialized() == FALSE);
|
ASSERT(events_is_initialized() == false);
|
||||||
|
|
||||||
result = events_init();
|
result = events_init();
|
||||||
ASSERT(result == TRUE);
|
ASSERT(result == true);
|
||||||
ASSERT(events_is_initialized() == TRUE);
|
ASSERT(events_is_initialized() == true);
|
||||||
|
|
||||||
printf("Displaying events:\n\n");
|
printf("Displaying events:\n\n");
|
||||||
|
|
||||||
|
@ -63,13 +65,13 @@ void test_events(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
result = events_shutdown();
|
result = events_shutdown();
|
||||||
ASSERT(result == TRUE);
|
ASSERT(result == true);
|
||||||
ASSERT(events_is_initialized() == FALSE);
|
ASSERT(events_is_initialized() == false);
|
||||||
|
|
||||||
result = mouse_shutdown();
|
result = mouse_shutdown();
|
||||||
ASSERT(result == TRUE);
|
ASSERT(result == true);
|
||||||
result = keyboard_shutdown();
|
result = keyboard_shutdown();
|
||||||
ASSERT(result == TRUE);
|
ASSERT(result == true);
|
||||||
|
|
||||||
printf("\nPress a key to continue...\n");
|
printf("\nPress a key to continue...\n");
|
||||||
|
|
||||||
|
|
2
TEST/EVENTS.H
Normal file → Executable file
2
TEST/EVENTS.H
Normal file → Executable file
|
@ -1,5 +1,7 @@
|
||||||
#ifndef DGL_TEST_EVENTS_H_INCLUDED
|
#ifndef DGL_TEST_EVENTS_H_INCLUDED
|
||||||
#define DGL_TEST_EVENTS_H_INCLUDED
|
#define DGL_TEST_EVENTS_H_INCLUDED
|
||||||
|
|
||||||
|
void test_events(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
3
TEST/FIXED.C
Normal file → Executable file
3
TEST/FIXED.C
Normal file → Executable file
|
@ -1,5 +1,6 @@
|
||||||
#include "fixed.h"
|
#include "fixed.h"
|
||||||
#include "dgl.h"
|
#include "dglfixp.h"
|
||||||
|
#include "dglmath.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
|
|
0
TEST/FIXED.H
Normal file → Executable file
0
TEST/FIXED.H
Normal file → Executable file
1
TEST/HELPERS.C
Normal file → Executable file
1
TEST/HELPERS.C
Normal file → Executable file
|
@ -1,5 +1,4 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "dgl.h"
|
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
#include <dos.h>
|
#include <dos.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
2
TEST/HELPERS.H
Normal file → Executable file
2
TEST/HELPERS.H
Normal file → Executable file
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "dgl.h"
|
#include "dglmath.h"
|
||||||
|
|
||||||
#define F_EQU(a, b) (close_enough((a), (b), TOLERANCE))
|
#define F_EQU(a, b) (close_enough((a), (b), TOLERANCE))
|
||||||
#define FFIX_EQU(a, b) (close_enough((a), (b), 0.05f)) // wow !
|
#define FFIX_EQU(a, b) (close_enough((a), (b), 0.05f)) // wow !
|
||||||
|
|
14
TEST/KBRD.C
Normal file → Executable file
14
TEST/KBRD.C
Normal file → Executable file
|
@ -1,5 +1,5 @@
|
||||||
#include "kbrd.h"
|
#include "kbrd.h"
|
||||||
#include "dgl.h"
|
#include "dglkbrd.h"
|
||||||
#include <dos.h>
|
#include <dos.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
@ -19,16 +19,16 @@ void display_key_states(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_keyboard(void) {
|
void test_keyboard(void) {
|
||||||
boolean result;
|
bool result;
|
||||||
KEY k;
|
KEY k;
|
||||||
|
|
||||||
clrscr(0);
|
clrscr(0);
|
||||||
|
|
||||||
ASSERT(keyboard_is_initialized() == FALSE);
|
ASSERT(keyboard_is_initialized() == false);
|
||||||
|
|
||||||
result = keyboard_init();
|
result = keyboard_init();
|
||||||
ASSERT(result == TRUE);
|
ASSERT(result == true);
|
||||||
ASSERT(keyboard_is_initialized() == TRUE);
|
ASSERT(keyboard_is_initialized() == true);
|
||||||
|
|
||||||
printf("Keyboard state\n");
|
printf("Keyboard state\n");
|
||||||
display_key_states();
|
display_key_states();
|
||||||
|
@ -52,8 +52,8 @@ void test_keyboard(void) {
|
||||||
keyboard_wait_for_key(k);
|
keyboard_wait_for_key(k);
|
||||||
|
|
||||||
result = keyboard_shutdown();
|
result = keyboard_shutdown();
|
||||||
ASSERT(result == TRUE);
|
ASSERT(result == true);
|
||||||
ASSERT(keyboard_is_initialized() == FALSE);
|
ASSERT(keyboard_is_initialized() == false);
|
||||||
|
|
||||||
gotoxy(0, 23);
|
gotoxy(0, 23);
|
||||||
printf("Press a key to continue...\n");
|
printf("Press a key to continue...\n");
|
||||||
|
|
0
TEST/KBRD.H
Normal file → Executable file
0
TEST/KBRD.H
Normal file → Executable file
159
TEST/LINE.C
Normal file → Executable file
159
TEST/LINE.C
Normal file → Executable file
|
@ -1,5 +1,6 @@
|
||||||
#include "line.h"
|
#include "line.h"
|
||||||
#include "dgl.h"
|
#include "dgldraw.h"
|
||||||
|
#include "dglmath.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
// draws two horizontal lines, with red pixels marking the extents of the
|
// draws two horizontal lines, with red pixels marking the extents of the
|
||||||
|
@ -11,21 +12,21 @@ void test_hline(void) {
|
||||||
|
|
||||||
x1 = 10; x2 = 100; y = 20;
|
x1 = 10; x2 = 100; y = 20;
|
||||||
|
|
||||||
surface_pset(screen, x1 - 1, y, 4);
|
pset(screen, x1 - 1, y, 4);
|
||||||
surface_pset(screen, x2 + 1, y, 4);
|
pset(screen, x2 + 1, y, 4);
|
||||||
surface_hline(screen, x1, x2, y, 1);
|
draw_hline(screen, x1, x2, y, 1);
|
||||||
|
|
||||||
y = 30;
|
y = 30;
|
||||||
|
|
||||||
surface_pset(screen, x1 - 1, y, 4);
|
pset(screen, x1 - 1, y, 4);
|
||||||
surface_pset(screen, x2 + 1, y, 4);
|
pset(screen, x2 + 1, y, 4);
|
||||||
surface_hline(screen, x2, x1, y, 2);
|
draw_hline(screen, x2, x1, y, 2);
|
||||||
|
|
||||||
x1 = 200; x2 = 300; y = 20;
|
x1 = 200; x2 = 300; y = 20;
|
||||||
|
|
||||||
surface_pset(screen, x1 - 1, y, 4);
|
pset(screen, x1 - 1, y, 4);
|
||||||
surface_pset(screen, x2 + 1, y, 4);
|
pset(screen, x2 + 1, y, 4);
|
||||||
surface_hline_f(screen, x1, x2, y, 1);
|
draw_hline_f(screen, x1, x2, y, 1);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
@ -40,15 +41,15 @@ void test_hline_clipping(void) {
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
x1 = -50; x2 = 50; y = 6;
|
x1 = -50; x2 = 50; y = 6;
|
||||||
surface_pset(screen, x2 + 1, y, 4);
|
pset(screen, x2 + 1, y, 4);
|
||||||
surface_hline(screen, x1, x2, y, 1);
|
draw_hline(screen, x1, x2, y, 1);
|
||||||
|
|
||||||
x1 = 300; x2 = 340; y = 130;
|
x1 = 300; x2 = 340; y = 130;
|
||||||
surface_pset(screen, x1 - 1, y, 4);
|
pset(screen, x1 - 1, y, 4);
|
||||||
surface_hline(screen, x1, x2, y, 2);
|
draw_hline(screen, x1, x2, y, 2);
|
||||||
|
|
||||||
surface_hline(screen, 100, 200, -10, 3);
|
draw_hline(screen, 100, 200, -10, 3);
|
||||||
surface_hline(screen, 20, 80, 250, 5);
|
draw_hline(screen, 20, 80, 250, 5);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
@ -62,21 +63,21 @@ void test_vline(void) {
|
||||||
|
|
||||||
x = 50; y1 = 10; y2 = 100;
|
x = 50; y1 = 10; y2 = 100;
|
||||||
|
|
||||||
surface_pset(screen, x, y1 - 1, 4);
|
pset(screen, x, y1 - 1, 4);
|
||||||
surface_pset(screen, x, y2 + 1, 4);
|
pset(screen, x, y2 + 1, 4);
|
||||||
surface_vline(screen, x, y1, y2, 1);
|
draw_vline(screen, x, y1, y2, 1);
|
||||||
|
|
||||||
x = 60;
|
x = 60;
|
||||||
|
|
||||||
surface_pset(screen, x, y1 - 1, 4);
|
pset(screen, x, y1 - 1, 4);
|
||||||
surface_pset(screen, x, y2 + 1, 4);
|
pset(screen, x, y2 + 1, 4);
|
||||||
surface_vline(screen, x, y2, y1, 2);
|
draw_vline(screen, x, y2, y1, 2);
|
||||||
|
|
||||||
x = 150; y1 = 10; y2 = 100;
|
x = 150; y1 = 10; y2 = 100;
|
||||||
|
|
||||||
surface_pset(screen, x, y1 - 1, 4);
|
pset(screen, x, y1 - 1, 4);
|
||||||
surface_pset(screen, x, y2 + 1, 4);
|
pset(screen, x, y2 + 1, 4);
|
||||||
surface_vline_f(screen, x, y1, y2, 1);
|
draw_vline_f(screen, x, y1, y2, 1);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
@ -91,15 +92,15 @@ void test_vline_clipping(void) {
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
x = 20; y1 = -32; y2 = 32;
|
x = 20; y1 = -32; y2 = 32;
|
||||||
surface_pset(screen, x, y2 + 1, 4);
|
pset(screen, x, y2 + 1, 4);
|
||||||
surface_vline(screen, x, y1, y2, 1);
|
draw_vline(screen, x, y1, y2, 1);
|
||||||
|
|
||||||
x = 270; y1 = 245; y2 = 165;
|
x = 270; y1 = 245; y2 = 165;
|
||||||
surface_pset(screen, x, y2 - 1, 4);
|
pset(screen, x, y2 - 1, 4);
|
||||||
surface_vline(screen, x, y1, y2, 2);
|
draw_vline(screen, x, y1, y2, 2);
|
||||||
|
|
||||||
surface_vline(screen, -17, 10, 20, 3);
|
draw_vline(screen, -17, 10, 20, 3);
|
||||||
surface_vline(screen, 400, 100, 300, 5);
|
draw_vline(screen, 400, 100, 300, 5);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
@ -114,70 +115,70 @@ void test_line(void) {
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
x1 = 10; y1 = 10; x2 = 20; y2 = 20;
|
x1 = 10; y1 = 10; x2 = 20; y2 = 20;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_line(screen, x1, y1, x2, y2, 1);
|
draw_line(screen, x1, y1, x2, y2, 1);
|
||||||
|
|
||||||
x1 = 10; y1 = 100; x2 = 20; y2 = 150;
|
x1 = 10; y1 = 100; x2 = 20; y2 = 150;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_line(screen, x1, y1, x2, y2, 2);
|
draw_line(screen, x1, y1, x2, y2, 2);
|
||||||
|
|
||||||
x1 = 60; y1 = 150; x2 = 50; y2 = 100;
|
x1 = 60; y1 = 150; x2 = 50; y2 = 100;
|
||||||
surface_pset(screen, x1 + 1, y1, 4);
|
pset(screen, x1 + 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 + 1, 4);
|
pset(screen, x1, y1 + 1, 4);
|
||||||
surface_pset(screen, x2 - 1, y2, 4);
|
pset(screen, x2 - 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 - 1, 4);
|
pset(screen, x2, y2 - 1, 4);
|
||||||
surface_line(screen, x1, y1, x2, y2, 3);
|
draw_line(screen, x1, y1, x2, y2, 3);
|
||||||
|
|
||||||
x1 = 50; y1 = 10; x2 = 100; y2 = 10;
|
x1 = 50; y1 = 10; x2 = 100; y2 = 10;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x2 + 1, y1, 4);
|
pset(screen, x2 + 1, y1, 4);
|
||||||
surface_line(screen, x1, y1, x2, y2, 5);
|
draw_line(screen, x1, y1, x2, y2, 5);
|
||||||
|
|
||||||
x1 = 100; y1 = 50; x2 = 20; y2 = 50;
|
x1 = 100; y1 = 50; x2 = 20; y2 = 50;
|
||||||
surface_pset(screen, x1 + 1, y1, 4);
|
pset(screen, x1 + 1, y1, 4);
|
||||||
surface_pset(screen, x2 - 1, y1, 4);
|
pset(screen, x2 - 1, y1, 4);
|
||||||
surface_line(screen, x1, y1, x2, y2, 6);
|
draw_line(screen, x1, y1, x2, y2, 6);
|
||||||
|
|
||||||
x1 = 290; y1 = 10; x2 = 290; y2 = 100;
|
x1 = 290; y1 = 10; x2 = 290; y2 = 100;
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_line(screen, x1, y1, x2, y2, 7);
|
draw_line(screen, x1, y1, x2, y2, 7);
|
||||||
|
|
||||||
x1 = 310; y1 = 100; x2 = 310; y2 = 10;
|
x1 = 310; y1 = 100; x2 = 310; y2 = 10;
|
||||||
surface_pset(screen, x1, y1 + 1, 4);
|
pset(screen, x1, y1 + 1, 4);
|
||||||
surface_pset(screen, x2, y2 - 1, 4);
|
pset(screen, x2, y2 - 1, 4);
|
||||||
surface_line(screen, x1, y1, x2, y2, 8);
|
draw_line(screen, x1, y1, x2, y2, 8);
|
||||||
|
|
||||||
|
|
||||||
x1 = 30; y1 = 10; x2 = 40; y2 = 20;
|
x1 = 30; y1 = 10; x2 = 40; y2 = 20;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_line_f(screen, x1, y1, x2, y2, 1);
|
draw_line_f(screen, x1, y1, x2, y2, 1);
|
||||||
|
|
||||||
x1 = 30; y1 = 100; x2 = 40; y2 = 150;
|
x1 = 30; y1 = 100; x2 = 40; y2 = 150;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_line_f(screen, x1, y1, x2, y2, 2);
|
draw_line_f(screen, x1, y1, x2, y2, 2);
|
||||||
|
|
||||||
x1 = 50; y1 = 20; x2 = 100; y2 = 20;
|
x1 = 50; y1 = 20; x2 = 100; y2 = 20;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x2 + 1, y1, 4);
|
pset(screen, x2 + 1, y1, 4);
|
||||||
surface_line_f(screen, x1, y1, x2, y2, 5);
|
draw_line_f(screen, x1, y1, x2, y2, 5);
|
||||||
|
|
||||||
x1 = 300; y1 = 10; x2 = 300; y2 = 100;
|
x1 = 300; y1 = 10; x2 = 300; y2 = 100;
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_line_f(screen, x1, y1, x2, y2, 7);
|
draw_line_f(screen, x1, y1, x2, y2, 7);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
@ -193,14 +194,14 @@ void test_line_clipping(void) {
|
||||||
|
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
surface_line(screen, 10, -30, 100, -30, 1);
|
draw_line(screen, 10, -30, 100, -30, 1);
|
||||||
surface_line(screen, 70, 250, 170, 250, 2);
|
draw_line(screen, 70, 250, 170, 250, 2);
|
||||||
surface_line(screen, -100, 120, -100, 199, 3);
|
draw_line(screen, -100, 120, -100, 199, 3);
|
||||||
surface_line(screen, 320, 99, 320, 199, 5);
|
draw_line(screen, 320, 99, 320, 199, 5);
|
||||||
|
|
||||||
for (angle = 0, color = 32; angle <= 360; angle += 10, ++color) {
|
for (angle = 0, color = 32; angle <= 360; angle += 10, ++color) {
|
||||||
point_on_circle(400, DEG_TO_RAD(angle), &x, &y);
|
point_on_circle(400, DEG_TO_RAD(angle), &x, &y);
|
||||||
surface_line(screen, 160, 100, (int)x + 160, (int)y + 100, color);
|
draw_line(screen, 160, 100, (int)x + 160, (int)y + 100, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
|
|
0
TEST/LINE.H
Normal file → Executable file
0
TEST/LINE.H
Normal file → Executable file
0
TEST/MAKEFILE
Normal file → Executable file
0
TEST/MAKEFILE
Normal file → Executable file
14
TEST/MOUSE.C
Normal file → Executable file
14
TEST/MOUSE.C
Normal file → Executable file
|
@ -1,19 +1,19 @@
|
||||||
#include "mouse.h"
|
#include "mouse.h"
|
||||||
#include "dgl.h"
|
#include "dglmouse.h"
|
||||||
#include <dos.h>
|
#include <dos.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
void test_mouse(void) {
|
void test_mouse(void) {
|
||||||
boolean result;
|
bool result;
|
||||||
|
|
||||||
clrscr(0);
|
clrscr(0);
|
||||||
|
|
||||||
ASSERT(mouse_is_initialized() == FALSE);
|
ASSERT(mouse_is_initialized() == false);
|
||||||
|
|
||||||
result = mouse_init();
|
result = mouse_init();
|
||||||
ASSERT(result == TRUE);
|
ASSERT(result == true);
|
||||||
ASSERT(mouse_is_initialized() == TRUE);
|
ASSERT(mouse_is_initialized() == true);
|
||||||
|
|
||||||
// this may seem a little weird to check for a mouse AFTER init, but
|
// this may seem a little weird to check for a mouse AFTER init, but
|
||||||
// it's the init call that determines if a mouse is present :)
|
// it's the init call that determines if a mouse is present :)
|
||||||
|
@ -37,8 +37,8 @@ void test_mouse(void) {
|
||||||
|
|
||||||
// need to close down the mouse subsystem even if one is not present
|
// need to close down the mouse subsystem even if one is not present
|
||||||
result = mouse_shutdown();
|
result = mouse_shutdown();
|
||||||
ASSERT(result == TRUE);
|
ASSERT(result == true);
|
||||||
ASSERT(mouse_is_initialized() == FALSE);
|
ASSERT(mouse_is_initialized() == false);
|
||||||
|
|
||||||
gotoxy(0, 23);
|
gotoxy(0, 23);
|
||||||
printf("Press a key to continue...\n");
|
printf("Press a key to continue...\n");
|
||||||
|
|
0
TEST/MOUSE.H
Normal file → Executable file
0
TEST/MOUSE.H
Normal file → Executable file
12
TEST/PAL.C
Normal file → Executable file
12
TEST/PAL.C
Normal file → Executable file
|
@ -1,5 +1,7 @@
|
||||||
#include "pal.h"
|
#include "pal.h"
|
||||||
#include "dgl.h"
|
#include "dglgfx.h"
|
||||||
|
#include "dgldraw.h"
|
||||||
|
#include "dglpal.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
|
@ -7,14 +9,14 @@
|
||||||
// color 15's RGB values.
|
// color 15's RGB values.
|
||||||
void test_palette(void) {
|
void test_palette(void) {
|
||||||
int i, x, y;
|
int i, x, y;
|
||||||
byte r, g, b;
|
uint8 r, g, b;
|
||||||
|
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (y = 0; y < 16; ++y) {
|
for (y = 0; y < 16; ++y) {
|
||||||
for (x = 0; x < 16; ++x) {
|
for (x = 0; x < 16; ++x) {
|
||||||
surface_filled_rect(screen, x * 8, y * 8, x * 8 + 7, y * 8 + 7, i);
|
draw_filled_rect(screen, x * 8, y * 8, x * 8 + 7, y * 8 + 7, i);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,13 +33,13 @@ void test_palette(void) {
|
||||||
|
|
||||||
void test_palette_fading(void) {
|
void test_palette_fading(void) {
|
||||||
int i, x, y;
|
int i, x, y;
|
||||||
byte palette[768];
|
uint8 palette[768];
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (y = 0; y < 16; ++y) {
|
for (y = 0; y < 16; ++y) {
|
||||||
for (x = 0; x < 16; ++x) {
|
for (x = 0; x < 16; ++x) {
|
||||||
surface_filled_rect(screen, x * 8, y * 8, x * 8 + 7, y * 8 + 7, i);
|
draw_filled_rect(screen, x * 8, y * 8, x * 8 + 7, y * 8 + 7, i);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
0
TEST/PAL.H
Normal file → Executable file
0
TEST/PAL.H
Normal file → Executable file
11
TEST/PCX.C
Normal file → Executable file
11
TEST/PCX.C
Normal file → Executable file
|
@ -1,13 +1,16 @@
|
||||||
#include "pcx.h"
|
#include "pcx.h"
|
||||||
#include "dgl.h"
|
#include "dgl.h"
|
||||||
|
#include "dglgfx.h"
|
||||||
|
#include "dglblit.h"
|
||||||
|
#include "dglpcx.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
void test_pcx(void) {
|
void test_pcx(void) {
|
||||||
SURFACE *pcx;
|
SURFACE *pcx;
|
||||||
DGL_ERROR err;
|
DGL_ERROR err;
|
||||||
byte pcx_palette[768];
|
uint8 pcx_palette[768];
|
||||||
byte original_palette[768];
|
uint8 original_palette[768];
|
||||||
|
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
pal_get(original_palette);
|
pal_get(original_palette);
|
||||||
|
@ -20,7 +23,7 @@ void test_pcx(void) {
|
||||||
pcx = pcx_load("test.pcx", NULL);
|
pcx = pcx_load("test.pcx", NULL);
|
||||||
ASSERT(pcx != NULL);
|
ASSERT(pcx != NULL);
|
||||||
|
|
||||||
surface_blit(pcx, screen, 0, 0);
|
blit(pcx, screen, 0, 0);
|
||||||
getch();
|
getch();
|
||||||
|
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
@ -29,7 +32,7 @@ void test_pcx(void) {
|
||||||
ASSERT(pcx != NULL);
|
ASSERT(pcx != NULL);
|
||||||
|
|
||||||
pal_set(pcx_palette);
|
pal_set(pcx_palette);
|
||||||
surface_blit(pcx, screen, 0, 0);
|
blit(pcx, screen, 0, 0);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
pal_set(original_palette);
|
pal_set(original_palette);
|
||||||
|
|
0
TEST/PCX.H
Normal file → Executable file
0
TEST/PCX.H
Normal file → Executable file
72
TEST/PSET.C
Normal file → Executable file
72
TEST/PSET.C
Normal file → Executable file
|
@ -1,5 +1,5 @@
|
||||||
#include "pset.h"
|
#include "pset.h"
|
||||||
#include "dgl.h"
|
#include "dgldraw.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
// starting at (10,10), draw 256 colour palette in a 16x16 pixel box.
|
// starting at (10,10), draw 256 colour palette in a 16x16 pixel box.
|
||||||
// draw white "guide" lines from (0,0) to (10,10)
|
// draw white "guide" lines from (0,0) to (10,10)
|
||||||
void test_pixels_1(void) {
|
void test_pixels_1(void) {
|
||||||
byte *p;
|
uint8 *p;
|
||||||
int i, x, y;
|
int i, x, y;
|
||||||
|
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
@ -19,7 +19,7 @@ void test_pixels_1(void) {
|
||||||
i = 0;
|
i = 0;
|
||||||
for (y = 0; y < 16; ++y) {
|
for (y = 0; y < 16; ++y) {
|
||||||
for (x = 0; x < 16; ++x) {
|
for (x = 0; x < 16; ++x) {
|
||||||
*p = (byte)i;
|
*p = (uint8)i;
|
||||||
++p;
|
++p;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
@ -49,41 +49,41 @@ void test_pixels_1(void) {
|
||||||
// draws two blue, green, cyan, red pixels each in each screen corner.
|
// draws two blue, green, cyan, red pixels each in each screen corner.
|
||||||
// the second pixel colour is drawn by sampling the first.
|
// the second pixel colour is drawn by sampling the first.
|
||||||
void test_pixels_2(void) {
|
void test_pixels_2(void) {
|
||||||
byte c1, c2, c3, c4;
|
uint8 c1, c2, c3, c4;
|
||||||
|
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
surface_pset(screen, 0, 0, 1);
|
pset(screen, 0, 0, 1);
|
||||||
surface_pset(screen, 319, 0, 2);
|
pset(screen, 319, 0, 2);
|
||||||
surface_pset(screen, 0, 199, 3);
|
pset(screen, 0, 199, 3);
|
||||||
surface_pset(screen, 319, 199, 4);
|
pset(screen, 319, 199, 4);
|
||||||
|
|
||||||
surface_pset_f(screen, 10, 0, 1);
|
pset_f(screen, 10, 0, 1);
|
||||||
surface_pset_f(screen, 309, 0, 2);
|
pset_f(screen, 309, 0, 2);
|
||||||
surface_pset_f(screen, 10, 199, 3);
|
pset_f(screen, 10, 199, 3);
|
||||||
surface_pset_f(screen, 309, 199, 4);
|
pset_f(screen, 309, 199, 4);
|
||||||
|
|
||||||
c1 = surface_point(screen, 0, 0);
|
c1 = pget(screen, 0, 0);
|
||||||
c2 = surface_point(screen, 319, 0);
|
c2 = pget(screen, 319, 0);
|
||||||
c3 = surface_point(screen, 0, 199);
|
c3 = pget(screen, 0, 199);
|
||||||
c4 = surface_point(screen, 319, 199);
|
c4 = pget(screen, 319, 199);
|
||||||
ASSERT(c1 == 1 && c2 == 2 && c3 == 3 && c4 == 4);
|
ASSERT(c1 == 1 && c2 == 2 && c3 == 3 && c4 == 4);
|
||||||
|
|
||||||
surface_pset(screen, 1, 1, c1);
|
pset(screen, 1, 1, c1);
|
||||||
surface_pset(screen, 318, 1, c2);
|
pset(screen, 318, 1, c2);
|
||||||
surface_pset(screen, 1, 198, c3);
|
pset(screen, 1, 198, c3);
|
||||||
surface_pset(screen, 318, 198, c4);
|
pset(screen, 318, 198, c4);
|
||||||
|
|
||||||
c1 = surface_point_f(screen, 10, 0);
|
c1 = pget_f(screen, 10, 0);
|
||||||
c2 = surface_point_f(screen, 309, 0);
|
c2 = pget_f(screen, 309, 0);
|
||||||
c3 = surface_point_f(screen, 10, 199);
|
c3 = pget_f(screen, 10, 199);
|
||||||
c4 = surface_point_f(screen, 309, 199);
|
c4 = pget_f(screen, 309, 199);
|
||||||
ASSERT(c1 == 1 && c2 == 2 && c3 == 3 && c4 == 4);
|
ASSERT(c1 == 1 && c2 == 2 && c3 == 3 && c4 == 4);
|
||||||
|
|
||||||
surface_pset_f(screen, 11, 1, c1);
|
pset_f(screen, 11, 1, c1);
|
||||||
surface_pset_f(screen, 308, 1, c2);
|
pset_f(screen, 308, 1, c2);
|
||||||
surface_pset_f(screen, 11, 198, c3);
|
pset_f(screen, 11, 198, c3);
|
||||||
surface_pset_f(screen, 308, 198, c4);
|
pset_f(screen, 308, 198, c4);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
@ -97,16 +97,16 @@ void test_pixels_clipping(void) {
|
||||||
|
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
surface_pset(screen, 5, 100, 4);
|
pset(screen, 5, 100, 4);
|
||||||
surface_pset(screen, 314, 100, 4);
|
pset(screen, 314, 100, 4);
|
||||||
surface_pset(screen, 160, 5, 4);
|
pset(screen, 160, 5, 4);
|
||||||
surface_pset(screen, 160, 194, 4);
|
pset(screen, 160, 194, 4);
|
||||||
|
|
||||||
for (i = 0; i < 10; ++i) {
|
for (i = 0; i < 10; ++i) {
|
||||||
surface_pset(screen, i - 5, 100, 15);
|
pset(screen, i - 5, 100, 15);
|
||||||
surface_pset(screen, 315 + i, 100, 15);
|
pset(screen, 315 + i, 100, 15);
|
||||||
surface_pset(screen, 160, i - 5, 15);
|
pset(screen, 160, i - 5, 15);
|
||||||
surface_pset(screen, 160, 195 + i, 15);
|
pset(screen, 160, 195 + i, 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
|
|
0
TEST/PSET.H
Normal file → Executable file
0
TEST/PSET.H
Normal file → Executable file
231
TEST/RECT.C
Normal file → Executable file
231
TEST/RECT.C
Normal file → Executable file
|
@ -1,5 +1,6 @@
|
||||||
#include "rect.h"
|
#include "rect.h"
|
||||||
#include "dgl.h"
|
#include "dgldraw.h"
|
||||||
|
#include "dglrect.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
// draws two rectangles. red pixels mark the extents of the rects. a
|
// draws two rectangles. red pixels mark the extents of the rects. a
|
||||||
|
@ -10,37 +11,37 @@ void test_rect(void) {
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
x1 = 10; y1 = 10; x2 = 90; y2 = 90;
|
x1 = 10; y1 = 10; x2 = 90; y2 = 90;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y1, 4);
|
pset(screen, x2 + 1, y1, 4);
|
||||||
surface_pset(screen, x2, y1 - 1, 4);
|
pset(screen, x2, y1 - 1, 4);
|
||||||
surface_pset(screen, x1 - 1, y2, 4);
|
pset(screen, x1 - 1, y2, 4);
|
||||||
surface_pset(screen, x1, y2 + 1, 4);
|
pset(screen, x1, y2 + 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_rect(screen, x1, y1, x2, y2, 1);
|
draw_rect(screen, x1, y1, x2, y2, 1);
|
||||||
|
|
||||||
x1 = 10; y1 = 110; x2 = 90; y2 = 190;
|
x1 = 10; y1 = 110; x2 = 90; y2 = 190;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y1, 4);
|
pset(screen, x2 + 1, y1, 4);
|
||||||
surface_pset(screen, x2, y1 - 1, 4);
|
pset(screen, x2, y1 - 1, 4);
|
||||||
surface_pset(screen, x1 - 1, y2, 4);
|
pset(screen, x1 - 1, y2, 4);
|
||||||
surface_pset(screen, x1, y2 + 1, 4);
|
pset(screen, x1, y2 + 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_rect_f(screen, x1, y1, x2, y2, 1);
|
draw_rect_f(screen, x1, y1, x2, y2, 1);
|
||||||
|
|
||||||
x1 = 190; y1 = 90; x2 = 110; y2 = 10;
|
x1 = 190; y1 = 90; x2 = 110; y2 = 10;
|
||||||
surface_pset(screen, x2 - 1, y2, 4);
|
pset(screen, x2 - 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 - 1, 4);
|
pset(screen, x2, y2 - 1, 4);
|
||||||
surface_pset(screen, x1 + 1, y2, 4);
|
pset(screen, x1 + 1, y2, 4);
|
||||||
surface_pset(screen, x1, y2 - 1, 4);
|
pset(screen, x1, y2 - 1, 4);
|
||||||
surface_pset(screen, x2 - 1, y1, 4);
|
pset(screen, x2 - 1, y1, 4);
|
||||||
surface_pset(screen, x2, y1 + 1, 4);
|
pset(screen, x2, y1 + 1, 4);
|
||||||
surface_pset(screen, x1 + 1, y1, 4);
|
pset(screen, x1 + 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 + 1, 4);
|
pset(screen, x1, y1 + 1, 4);
|
||||||
surface_rect(screen, x1, y1, x2, y2, 2);
|
draw_rect(screen, x1, y1, x2, y2, 2);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
@ -56,50 +57,50 @@ void test_rect_clipping(void) {
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
x1 = -8; y1 = 10; x2 = 7; y2 = 25;
|
x1 = -8; y1 = 10; x2 = 7; y2 = 25;
|
||||||
surface_pset(screen, x2, y1 - 1, 4);
|
pset(screen, x2, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y1, 4);
|
pset(screen, x2 + 1, y1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_rect(screen, x1, y1, x2, y2, 1);
|
draw_rect(screen, x1, y1, x2, y2, 1);
|
||||||
|
|
||||||
surface_rect(screen, -16, 30, -1, 46, 10);
|
draw_rect(screen, -16, 30, -1, 46, 10);
|
||||||
|
|
||||||
x1 = 20; y1 = -8; x2 = 35; y2 = 7;
|
x1 = 20; y1 = -8; x2 = 35; y2 = 7;
|
||||||
surface_pset(screen, x1 - 1, y2, 4);
|
pset(screen, x1 - 1, y2, 4);
|
||||||
surface_pset(screen, x1, y2 + 1, 4);
|
pset(screen, x1, y2 + 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_rect(screen, x1, y1, x2, y2, 2);
|
draw_rect(screen, x1, y1, x2, y2, 2);
|
||||||
|
|
||||||
surface_rect(screen, 40, -16, 55, -1, 11);
|
draw_rect(screen, 40, -16, 55, -1, 11);
|
||||||
|
|
||||||
x1 = 313; y1 = 170; x2 = 328; y2 = 185;
|
x1 = 313; y1 = 170; x2 = 328; y2 = 185;
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1 - 1, y2, 4);
|
pset(screen, x1 - 1, y2, 4);
|
||||||
surface_pset(screen, x1, y2 + 1, 4);
|
pset(screen, x1, y2 + 1, 4);
|
||||||
surface_rect(screen, x1, y1, x2, y2, 3);
|
draw_rect(screen, x1, y1, x2, y2, 3);
|
||||||
|
|
||||||
surface_rect(screen, 320, 150, 335, 165, 12);
|
draw_rect(screen, 320, 150, 335, 165, 12);
|
||||||
|
|
||||||
x1 = 285; y1 = 193; x2 = 300; y2 = 208;
|
x1 = 285; y1 = 193; x2 = 300; y2 = 208;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y1, 4);
|
pset(screen, x2 + 1, y1, 4);
|
||||||
surface_pset(screen, x2, y1 - 1, 4);
|
pset(screen, x2, y1 - 1, 4);
|
||||||
surface_rect(screen, x1, y1, x2, y2, 5);
|
draw_rect(screen, x1, y1, x2, y2, 5);
|
||||||
|
|
||||||
surface_rect(screen, 265, 200, 280, 215, 13);
|
draw_rect(screen, 265, 200, 280, 215, 13);
|
||||||
|
|
||||||
x1 = 150; y1 = -10; x2 = 170; y2 = 210;
|
x1 = 150; y1 = -10; x2 = 170; y2 = 210;
|
||||||
surface_pset(screen, x1 - 1, 10, 4);
|
pset(screen, x1 - 1, 10, 4);
|
||||||
surface_pset(screen, x2 + 1, 10, 4);
|
pset(screen, x2 + 1, 10, 4);
|
||||||
surface_rect(screen, x1, y1, x2, y2, 7);
|
draw_rect(screen, x1, y1, x2, y2, 7);
|
||||||
|
|
||||||
x1 = -10; y1 = 90; x2 = 330; y2 = 110;
|
x1 = -10; y1 = 90; x2 = 330; y2 = 110;
|
||||||
surface_pset(screen, 10, y1 - 1, 4);
|
pset(screen, 10, y1 - 1, 4);
|
||||||
surface_pset(screen, 10, y2 + 1, 4);
|
pset(screen, 10, y2 + 1, 4);
|
||||||
surface_rect(screen, x1, y1, x2, y2, 8);
|
draw_rect(screen, x1, y1, x2, y2, 8);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
@ -112,37 +113,37 @@ void test_filled_rect(void) {
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
x1 = 10; y1 = 10; x2 = 90; y2 = 90;
|
x1 = 10; y1 = 10; x2 = 90; y2 = 90;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y1, 4);
|
pset(screen, x2 + 1, y1, 4);
|
||||||
surface_pset(screen, x2, y1 - 1, 4);
|
pset(screen, x2, y1 - 1, 4);
|
||||||
surface_pset(screen, x1 - 1, y2, 4);
|
pset(screen, x1 - 1, y2, 4);
|
||||||
surface_pset(screen, x1, y2 + 1, 4);
|
pset(screen, x1, y2 + 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_filled_rect(screen, x1, y1, x2, y2, 1);
|
draw_filled_rect(screen, x1, y1, x2, y2, 1);
|
||||||
|
|
||||||
x1 = 10; y1 = 110; x2 = 90; y2 = 190;
|
x1 = 10; y1 = 110; x2 = 90; y2 = 190;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y1, 4);
|
pset(screen, x2 + 1, y1, 4);
|
||||||
surface_pset(screen, x2, y1 - 1, 4);
|
pset(screen, x2, y1 - 1, 4);
|
||||||
surface_pset(screen, x1 - 1, y2, 4);
|
pset(screen, x1 - 1, y2, 4);
|
||||||
surface_pset(screen, x1, y2 + 1, 4);
|
pset(screen, x1, y2 + 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_filled_rect_f(screen, x1, y1, x2, y2, 1);
|
draw_filled_rect_f(screen, x1, y1, x2, y2, 1);
|
||||||
|
|
||||||
x1 = 190; y1 = 90; x2 = 110; y2 = 10;
|
x1 = 190; y1 = 90; x2 = 110; y2 = 10;
|
||||||
surface_pset(screen, x2 - 1, y2, 4);
|
pset(screen, x2 - 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 - 1, 4);
|
pset(screen, x2, y2 - 1, 4);
|
||||||
surface_pset(screen, x1 + 1, y2, 4);
|
pset(screen, x1 + 1, y2, 4);
|
||||||
surface_pset(screen, x1, y2 - 1, 4);
|
pset(screen, x1, y2 - 1, 4);
|
||||||
surface_pset(screen, x2 - 1, y1, 4);
|
pset(screen, x2 - 1, y1, 4);
|
||||||
surface_pset(screen, x2, y1 + 1, 4);
|
pset(screen, x2, y1 + 1, 4);
|
||||||
surface_pset(screen, x1 + 1, y1, 4);
|
pset(screen, x1 + 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 + 1, 4);
|
pset(screen, x1, y1 + 1, 4);
|
||||||
surface_filled_rect(screen, x1, y1, x2, y2, 2);
|
draw_filled_rect(screen, x1, y1, x2, y2, 2);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
@ -158,50 +159,50 @@ void test_filled_rect_clipping(void) {
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
x1 = -8; y1 = 10; x2 = 7; y2 = 25;
|
x1 = -8; y1 = 10; x2 = 7; y2 = 25;
|
||||||
surface_pset(screen, x2, y1 - 1, 4);
|
pset(screen, x2, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y1, 4);
|
pset(screen, x2 + 1, y1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_filled_rect(screen, x1, y1, x2, y2, 1);
|
draw_filled_rect(screen, x1, y1, x2, y2, 1);
|
||||||
|
|
||||||
surface_filled_rect(screen, -16, 30, -1, 46, 10);
|
draw_filled_rect(screen, -16, 30, -1, 46, 10);
|
||||||
|
|
||||||
x1 = 20; y1 = -8; x2 = 35; y2 = 7;
|
x1 = 20; y1 = -8; x2 = 35; y2 = 7;
|
||||||
surface_pset(screen, x1 - 1, y2, 4);
|
pset(screen, x1 - 1, y2, 4);
|
||||||
surface_pset(screen, x1, y2 + 1, 4);
|
pset(screen, x1, y2 + 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y2, 4);
|
pset(screen, x2 + 1, y2, 4);
|
||||||
surface_pset(screen, x2, y2 + 1, 4);
|
pset(screen, x2, y2 + 1, 4);
|
||||||
surface_filled_rect(screen, x1, y1, x2, y2, 2);
|
draw_filled_rect(screen, x1, y1, x2, y2, 2);
|
||||||
|
|
||||||
surface_filled_rect(screen, 40, -16, 55, -1, 11);
|
draw_filled_rect(screen, 40, -16, 55, -1, 11);
|
||||||
|
|
||||||
x1 = 313; y1 = 170; x2 = 328; y2 = 185;
|
x1 = 313; y1 = 170; x2 = 328; y2 = 185;
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1 - 1, y2, 4);
|
pset(screen, x1 - 1, y2, 4);
|
||||||
surface_pset(screen, x1, y2 + 1, 4);
|
pset(screen, x1, y2 + 1, 4);
|
||||||
surface_filled_rect(screen, x1, y1, x2, y2, 3);
|
draw_filled_rect(screen, x1, y1, x2, y2, 3);
|
||||||
|
|
||||||
surface_filled_rect(screen, 320, 150, 335, 165, 12);
|
draw_filled_rect(screen, 320, 150, 335, 165, 12);
|
||||||
|
|
||||||
x1 = 285; y1 = 193; x2 = 300; y2 = 208;
|
x1 = 285; y1 = 193; x2 = 300; y2 = 208;
|
||||||
surface_pset(screen, x1 - 1, y1, 4);
|
pset(screen, x1 - 1, y1, 4);
|
||||||
surface_pset(screen, x1, y1 - 1, 4);
|
pset(screen, x1, y1 - 1, 4);
|
||||||
surface_pset(screen, x2 + 1, y1, 4);
|
pset(screen, x2 + 1, y1, 4);
|
||||||
surface_pset(screen, x2, y1 - 1, 4);
|
pset(screen, x2, y1 - 1, 4);
|
||||||
surface_filled_rect(screen, x1, y1, x2, y2, 5);
|
draw_filled_rect(screen, x1, y1, x2, y2, 5);
|
||||||
|
|
||||||
surface_filled_rect(screen, 265, 200, 280, 215, 13);
|
draw_filled_rect(screen, 265, 200, 280, 215, 13);
|
||||||
|
|
||||||
x1 = 150; y1 = -10; x2 = 170; y2 = 210;
|
x1 = 150; y1 = -10; x2 = 170; y2 = 210;
|
||||||
surface_pset(screen, x1 - 1, 10, 4);
|
pset(screen, x1 - 1, 10, 4);
|
||||||
surface_pset(screen, x2 + 1, 10, 4);
|
pset(screen, x2 + 1, 10, 4);
|
||||||
surface_filled_rect(screen, x1, y1, x2, y2, 7);
|
draw_filled_rect(screen, x1, y1, x2, y2, 7);
|
||||||
|
|
||||||
x1 = -10; y1 = 90; x2 = 330; y2 = 110;
|
x1 = -10; y1 = 90; x2 = 330; y2 = 110;
|
||||||
surface_pset(screen, 10, y1 - 1, 4);
|
pset(screen, 10, y1 - 1, 4);
|
||||||
surface_pset(screen, 10, y2 + 1, 4);
|
pset(screen, 10, y2 + 1, 4);
|
||||||
surface_filled_rect(screen, x1, y1, x2, y2, 8);
|
draw_filled_rect(screen, x1, y1, x2, y2, 8);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
|
0
TEST/RECT.H
Normal file → Executable file
0
TEST/RECT.H
Normal file → Executable file
2
TEST/SURFACE.C
Normal file → Executable file
2
TEST/SURFACE.C
Normal file → Executable file
|
@ -1,5 +1,5 @@
|
||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
#include "dgl.h"
|
#include "dglgfx.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
extern SURFACE *backbuffer;
|
extern SURFACE *backbuffer;
|
||||||
|
|
0
TEST/SURFACE.H
Normal file → Executable file
0
TEST/SURFACE.H
Normal file → Executable file
7
TEST/TEST.C
Normal file → Executable file
7
TEST/TEST.C
Normal file → Executable file
|
@ -1,6 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include "dgl.h"
|
#include "dgl.h"
|
||||||
|
#include "dglgfx.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
#include "blit.h"
|
#include "blit.h"
|
||||||
|
@ -30,7 +31,7 @@ int main(void) {
|
||||||
|
|
||||||
ASSERT(screen == NULL);
|
ASSERT(screen == NULL);
|
||||||
|
|
||||||
if (!video_init()) {
|
if (!gfx_init()) {
|
||||||
printf("Error initializing video: %s\n", dgl_last_error_message());
|
printf("Error initializing video: %s\n", dgl_last_error_message());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -46,8 +47,8 @@ int main(void) {
|
||||||
test_mouse();
|
test_mouse();
|
||||||
test_events();
|
test_events();
|
||||||
test_fixed();
|
test_fixed();
|
||||||
test_vector2i();
|
test_vec2i();
|
||||||
test_vector2f();
|
test_vec2();
|
||||||
test_surface_clear();
|
test_surface_clear();
|
||||||
test_surface_copy();
|
test_surface_copy();
|
||||||
test_pixels_1();
|
test_pixels_1();
|
||||||
|
|
0
TEST/TEST.PCX
Normal file → Executable file
0
TEST/TEST.PCX
Normal file → Executable file
60
TEST/TEXT.C
Normal file → Executable file
60
TEST/TEXT.C
Normal file → Executable file
|
@ -1,5 +1,7 @@
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "dgl.h"
|
#include "dglgfx.h"
|
||||||
|
#include "dgldraw.h"
|
||||||
|
#include "dglmath.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -14,19 +16,19 @@ void test_text(void) {
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
memset(string, 0, 255);
|
memset(string, 0, 255);
|
||||||
|
|
||||||
surface_text(screen, 10, 10, 15, "Hello, world!");
|
draw_text(screen, 10, 10, 15, "Hello, world!");
|
||||||
surface_text_f(screen, 170, 10, 15, "Hello, world!");
|
draw_text_f(screen, 170, 10, 15, "Hello, world!");
|
||||||
|
|
||||||
surface_filled_rect(screen, 8, 28, 114, 40, 7);
|
draw_filled_rect(screen, 8, 28, 114, 40, 7);
|
||||||
surface_text(screen, 10, 30, 15, "transparency!");
|
draw_text(screen, 10, 30, 15, "transparency!");
|
||||||
surface_filled_rect_f(screen, 168, 28, 274, 40, 7);
|
draw_filled_rect_f(screen, 168, 28, 274, 40, 7);
|
||||||
surface_text_f(screen, 170, 30, 15, "transparency!");
|
draw_text_f(screen, 170, 30, 15, "transparency!");
|
||||||
|
|
||||||
surface_text(screen, 10, 50, 15, "line 1\nline 2");
|
draw_text(screen, 10, 50, 15, "line 1\nline 2");
|
||||||
surface_text_f(screen, 170, 50, 15, "line 1\nline 2");
|
draw_text_f(screen, 170, 50, 15, "line 1\nline 2");
|
||||||
|
|
||||||
surface_printf(screen, 10, 70, 15, "printf pi %.5f", PI);
|
draw_printf(screen, 10, 70, 15, "printf pi %.5f", PI);
|
||||||
surface_printf_f(screen, 170, 70, 15, "printf pi %.5f", PI);
|
draw_printf_f(screen, 170, 70, 15, "printf pi %.5f", PI);
|
||||||
|
|
||||||
p = &string[0];
|
p = &string[0];
|
||||||
for (i = 1; i <= 127; ++i, ++p) {
|
for (i = 1; i <= 127; ++i, ++p) {
|
||||||
|
@ -40,8 +42,8 @@ void test_text(void) {
|
||||||
*p = (char)i;
|
*p = (char)i;
|
||||||
}
|
}
|
||||||
|
|
||||||
surface_text(screen, 10, 100, 15, string);
|
draw_text(screen, 10, 100, 15, string);
|
||||||
surface_text_f(screen, 170, 100, 15, string);
|
draw_text_f(screen, 170, 100, 15, string);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
@ -59,36 +61,36 @@ void test_text_clipping(void) {
|
||||||
surface_clear(screen, 0);
|
surface_clear(screen, 0);
|
||||||
|
|
||||||
x = -32; y = 10;
|
x = -32; y = 10;
|
||||||
surface_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
||||||
surface_text(screen, x, y, 9, message);
|
draw_text(screen, x, y, 9, message);
|
||||||
|
|
||||||
x = 80; y = -4;
|
x = 80; y = -4;
|
||||||
surface_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
||||||
surface_text(screen, x, y, 10, message);
|
draw_text(screen, x, y, 10, message);
|
||||||
|
|
||||||
x = 288; y = 120;
|
x = 288; y = 120;
|
||||||
surface_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
||||||
surface_text(screen, x, y, 11, message);
|
draw_text(screen, x, y, 11, message);
|
||||||
|
|
||||||
x = 200; y = 196;
|
x = 200; y = 196;
|
||||||
surface_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
||||||
surface_text(screen, x, y, 12, message);
|
draw_text(screen, x, y, 12, message);
|
||||||
|
|
||||||
x = -232; y = 10;
|
x = -232; y = 10;
|
||||||
surface_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
||||||
surface_text(screen, x, y, 5, message);
|
draw_text(screen, x, y, 5, message);
|
||||||
|
|
||||||
x = 80; y = -24;
|
x = 80; y = -24;
|
||||||
surface_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
||||||
surface_text(screen, x, y, 6, message);
|
draw_text(screen, x, y, 6, message);
|
||||||
|
|
||||||
x = 360; y = 120;
|
x = 360; y = 120;
|
||||||
surface_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
||||||
surface_text(screen, x, y, 7, message);
|
draw_text(screen, x, y, 7, message);
|
||||||
|
|
||||||
x = 200; y = 240;
|
x = 200; y = 240;
|
||||||
surface_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
||||||
surface_text(screen, x, y, 8, message);
|
draw_text(screen, x, y, 8, message);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
|
0
TEST/TEXT.H
Normal file → Executable file
0
TEST/TEXT.H
Normal file → Executable file
156
TEST/VECTOR2.C
Normal file → Executable file
156
TEST/VECTOR2.C
Normal file → Executable file
|
@ -1,134 +1,134 @@
|
||||||
#include "vector2.h"
|
#include "vector2.h"
|
||||||
#include "dgl.h"
|
#include "dglvec2.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
void test_vector2i(void) {
|
void test_vec2i(void) {
|
||||||
VECTOR2I a, b, c;
|
VEC2I a, b, c;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
c = vector2i(3, 7);
|
c = vec2i(3, 7);
|
||||||
ASSERT(c.x == 3 && c.y == 7);
|
ASSERT(c.x == 3 && c.y == 7);
|
||||||
|
|
||||||
vector2i_set(&c, 1, 2);
|
vec2i_set(&c, 1, 2);
|
||||||
ASSERT(c.x == 1 && c.y == 2);
|
ASSERT(c.x == 1 && c.y == 2);
|
||||||
|
|
||||||
a = vector2i(1, 2);
|
a = vec2i(1, 2);
|
||||||
b = vector2i(1, 2);
|
b = vec2i(1, 2);
|
||||||
ASSERT(vector2i_equals(a, b));
|
ASSERT(vec2i_equals(a, b));
|
||||||
|
|
||||||
a = vector2i(3, 4);
|
a = vec2i(3, 4);
|
||||||
b = vector2i(1, 2);
|
b = vec2i(1, 2);
|
||||||
|
|
||||||
c = vector2i_add(a, b);
|
c = vec2i_add(a, b);
|
||||||
ASSERT(c.x == 4 && c.y == 6);
|
ASSERT(c.x == 4 && c.y == 6);
|
||||||
|
|
||||||
c = vector2i_sub(a, b);
|
c = vec2i_sub(a, b);
|
||||||
ASSERT(c.x == 2 && c.y == 2);
|
ASSERT(c.x == 2 && c.y == 2);
|
||||||
|
|
||||||
c = vector2i_mul(a, b);
|
c = vec2i_mul(a, b);
|
||||||
ASSERT(c.x == 3 && c.y == 8);
|
ASSERT(c.x == 3 && c.y == 8);
|
||||||
|
|
||||||
c = vector2i_muls(a, 2);
|
c = vec2i_muls(a, 2);
|
||||||
ASSERT(c.x == 6 && c.y == 8);
|
ASSERT(c.x == 6 && c.y == 8);
|
||||||
|
|
||||||
c = vector2i_div(a, b);
|
c = vec2i_div(a, b);
|
||||||
ASSERT(c.x == 3 && c.y == 2);
|
ASSERT(c.x == 3 && c.y == 2);
|
||||||
|
|
||||||
c = vector2i_divs(a, 2);
|
c = vec2i_divs(a, 2);
|
||||||
ASSERT(c.x == 1 && c.y == 2);
|
ASSERT(c.x == 1 && c.y == 2);
|
||||||
|
|
||||||
a = vector2i(1, 1);
|
a = vec2i(1, 1);
|
||||||
b = vector2i(1, 3);
|
b = vec2i(1, 3);
|
||||||
i = vector2i_distance(a, b);
|
i = vec2i_distance(a, b);
|
||||||
ASSERT(i == 2);
|
ASSERT(i == 2);
|
||||||
|
|
||||||
i = vector2i_distancesq(a, b);
|
i = vec2i_distancesq(a, b);
|
||||||
ASSERT(i == 4);
|
ASSERT(i == 4);
|
||||||
|
|
||||||
a = vector2i(-12, 16);
|
a = vec2i(-12, 16);
|
||||||
b = vector2i(12, 9);
|
b = vec2i(12, 9);
|
||||||
i = vector2i_dot(a, b);
|
i = vec2i_dot(a, b);
|
||||||
ASSERT(i == 0);
|
ASSERT(i == 0);
|
||||||
|
|
||||||
a = vector2i(-3, 0);
|
a = vec2i(-3, 0);
|
||||||
i = vector2i_length(a);
|
i = vec2i_length(a);
|
||||||
ASSERT(i == 3);
|
ASSERT(i == 3);
|
||||||
|
|
||||||
i = vector2i_lengthsq(a);
|
i = vec2i_lengthsq(a);
|
||||||
ASSERT(i == 9);
|
ASSERT(i == 9);
|
||||||
|
|
||||||
a = vector2i(5, 0);
|
a = vec2i(5, 0);
|
||||||
b = vector2i(10, 0);
|
b = vec2i(10, 0);
|
||||||
c = vector2i_lerp(a, b, 0.5f);
|
c = vec2i_lerp(a, b, 0.5f);
|
||||||
ASSERT(c.x == 7 && c.y == 0);
|
ASSERT(c.x == 7 && c.y == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_vector2f(void) {
|
void test_vec2(void) {
|
||||||
VECTOR2F a, b, c;
|
VEC2 a, b, c;
|
||||||
float f;
|
fixed f;
|
||||||
|
|
||||||
c = vector2f(3.0f, 7.0f);
|
c = vec2(FTOFIX(3.0f), FTOFIX(7.0f));
|
||||||
ASSERT(F_EQU(c.x, 3.0f) && F_EQU(c.y, 7.0f));
|
ASSERT(c.x == FTOFIX(3.0f) && c.y == FTOFIX(7.0f));
|
||||||
|
|
||||||
vector2f_set(&c, 1.0f, 2.0f);
|
vec2_set(&c, FTOFIX(1.0f), FTOFIX(2.0f));
|
||||||
ASSERT(F_EQU(c.x, 1.0f) && F_EQU(c.y, 2.0f));
|
ASSERT(c.x == FTOFIX(1.0f) && c.y == FTOFIX(2.0f));
|
||||||
|
|
||||||
a = vector2f(1.0f, 2.0f);
|
a = vec2(FTOFIX(1.0f), FTOFIX(2.0f));
|
||||||
b = vector2f(1.0f, 2.0f);
|
b = vec2(FTOFIX(1.0f), FTOFIX(2.0f));
|
||||||
ASSERT(vector2f_equals(a, b));
|
ASSERT(vec2_equals(a, b));
|
||||||
|
|
||||||
a = vector2f(3.0f, 4.0f);
|
a = vec2(FTOFIX(3.0f), FTOFIX(4.0f));
|
||||||
b = vector2f(1.0f, 2.0f);
|
b = vec2(FTOFIX(1.0f), FTOFIX(2.0f));
|
||||||
|
|
||||||
c = vector2f_add(a, b);
|
c = vec2_add(a, b);
|
||||||
ASSERT(F_EQU(c.x, 4.0f) && F_EQU(c.y, 6.0f));
|
ASSERT(c.x == FTOFIX(4.0f) && c.y == FTOFIX(6.0f));
|
||||||
|
|
||||||
c = vector2f_sub(a, b);
|
c = vec2_sub(a, b);
|
||||||
ASSERT(F_EQU(c.x, 2.0f) && F_EQU(c.y, 2.0f));
|
ASSERT(c.x == FTOFIX(2.0f) && c.y == FTOFIX(2.0f));
|
||||||
|
|
||||||
c = vector2f_mul(a, b);
|
c = vec2_mul(a, b);
|
||||||
ASSERT(F_EQU(c.x, 3.0f) && F_EQU(c.y, 8.0f));
|
ASSERT(c.x == FTOFIX(3.0f) && c.y == FTOFIX(8.0f));
|
||||||
|
|
||||||
c = vector2f_muls(a, 0.5f);
|
c = vec2_muls(a, FTOFIX(0.5f));
|
||||||
ASSERT(F_EQU(c.x, 1.5f) && F_EQU(c.y, 2.0f));
|
ASSERT(c.x == FTOFIX(1.5f) && c.y == FTOFIX(2.0f));
|
||||||
|
|
||||||
c = vector2f_div(a, b);
|
c = vec2_div(a, b);
|
||||||
ASSERT(F_EQU(c.x, 3.0f) && F_EQU(c.y, 2.0f));
|
ASSERT(c.x == FTOFIX(3.0f) && c.y == FTOFIX(2.0f));
|
||||||
|
|
||||||
c = vector2f_divs(a, 0.5f);
|
c = vec2_divs(a, FTOFIX(0.5f));
|
||||||
ASSERT(F_EQU(c.x, 6.0f) && F_EQU(c.y, 8.0f));
|
ASSERT(c.x == FTOFIX(6.0f) && c.y == FTOFIX(8.0f));
|
||||||
|
|
||||||
a = vector2f(1.0f, 1.0f);
|
a = vec2(FTOFIX(1.0f), FTOFIX(1.0f));
|
||||||
b = vector2f(1.0f, 3.0f);
|
b = vec2(FTOFIX(1.0f), FTOFIX(3.0f));
|
||||||
f = vector2f_distance(a, b);
|
f = vec2_distance(a, b);
|
||||||
ASSERT(F_EQU(f, 2.0f));
|
ASSERT(f == FTOFIX(2.0f));
|
||||||
|
|
||||||
f = vector2f_distancesq(a, b);
|
f = vec2_distancesq(a, b);
|
||||||
ASSERT(F_EQU(f, 4.0f));
|
ASSERT(f == FTOFIX(4.0f));
|
||||||
|
|
||||||
a = vector2f(-12.0f, 16.0f);
|
a = vec2(FTOFIX(-12.0f), FTOFIX(16.0f));
|
||||||
b = vector2f(12.0f, 9.0f);
|
b = vec2(FTOFIX(12.0f), FTOFIX(9.0f));
|
||||||
f = vector2f_dot(a, b);
|
f = vec2_dot(a, b);
|
||||||
ASSERT(F_EQU(f, 0.0f));
|
ASSERT(f == 0);
|
||||||
|
|
||||||
a = vector2f(-3.0f, 0.0f);
|
a = vec2(FTOFIX(-3.0f), FTOFIX(0.0f));
|
||||||
f = vector2f_length(a);
|
f = vec2_length(a);
|
||||||
ASSERT(F_EQU(f, 3.0f));
|
ASSERT(f == FTOFIX(3.0f));
|
||||||
|
|
||||||
f = vector2f_lengthsq(a);
|
f = vec2_lengthsq(a);
|
||||||
ASSERT(F_EQU(f, 9.0f));
|
ASSERT(f == FTOFIX(9.0f));
|
||||||
|
|
||||||
a = vector2f(7.0f, 7.0f);
|
a = vec2(FTOFIX(7.0f), FTOFIX(7.0f));
|
||||||
c = vector2f_normalize(a);
|
c = vec2_normalize(a);
|
||||||
ASSERT(F_EQU(c.x, 0.70710f) && F_EQU(c.y, 0.70710f));
|
ASSERT(c.x == FTOFIX(0.70710f) && c.y == FTOFIX(0.70710f));
|
||||||
|
|
||||||
a = vector2f(10.0f, 0.0f);
|
a = vec2(FTOFIX(10.0f), FTOFIX(0.0f));
|
||||||
c = vector2f_set_length(a, 2.0f);
|
c = vec2_set_length(a, FTOFIX(2.0f));
|
||||||
ASSERT(F_EQU(c.x, 2.0f) && F_EQU(c.y, 0.0f));
|
ASSERT(c.x == FTOFIX(2.0f) && c.y == FTOFIX(0.0f));
|
||||||
|
|
||||||
a = vector2f(5.0f, 0.0f);
|
a = vec2(FTOFIX(5.0f), FTOFIX(0.0f));
|
||||||
b = vector2f(10.0f, 0.0f);
|
b = vec2(FTOFIX(10.0f), FTOFIX(0.0f));
|
||||||
c = vector2f_lerp(a, b, 0.5f);
|
c = vec2_lerp(a, b, FTOFIX(0.5f));
|
||||||
ASSERT(F_EQU(c.x, 7.5f) && F_EQU(c.y, 0.0f));
|
ASSERT(c.x == FTOFIX(7.5f) && c.y == FTOFIX(0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
TEST/VECTOR2.H
Normal file → Executable file
4
TEST/VECTOR2.H
Normal file → Executable file
|
@ -1,8 +1,8 @@
|
||||||
#ifndef DGL_TEST_VECTOR2_H_INCLUDED
|
#ifndef DGL_TEST_VECTOR2_H_INCLUDED
|
||||||
#define DGL_TEST_VECTOR2_H_INCLUDED
|
#define DGL_TEST_VECTOR2_H_INCLUDED
|
||||||
|
|
||||||
void test_vector2i(void);
|
void test_vec2i(void);
|
||||||
void test_vector2f(void);
|
void test_vec2(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue