asmsrc += cspr/dbgfont.asm cspr/confont.asm
bindata = data/loading.img
-inc = -I/usr/local/include -Isrc -Isrc/scr -Isrc/sdl -Ilibs -Ilibs/imago/src -Ilibs/mikmod/include
+inc = -I/usr/local/include -Isrc -Isrc/3dgfx -Isrc/scr -Isrc/sdl -Ilibs -Ilibs/imago/src -Ilibs/mikmod/include
warn = -pedantic -Wall -Wno-unused-variable -Wno-unused-function
CFLAGS = $(arch) $(warn) -g $(inc) `sdl-config --cflags`
!ifdef __UNIX__
dosobj = src/dos/audos.obj src/dos/djdpmi.obj src/dos/gfx.obj src/dos/keyb.obj &
src/dos/logger.obj src/dos/main.obj src/dos/sball.obj src/dos/timer.obj &
- src/dos/vbe.obj src/dos/vga.obj src/dos/watdpmi.obj
+ src/dos/vbe.obj src/dos/vga.obj src/dos/watdpmi.obj src/dos/mouse.obj
3dobj = src/3dgfx/3dgfx.obj src/3dgfx/mesh.obj src/3dgfx/meshload.obj &
src/3dgfx/polyclip.obj src/3dgfx/polyfill.obj
-srcobj = src/bsptree.obj src/cfgopt.obj src/console.obj &
- src/demo.obj src/dynarr.obj src/gfxutil.obj &
- src/metasurf.obj src/noise.obj &
+srcobj = src/bsptree.obj src/cfgopt.obj src/console.obj src/demo.obj &
+ src/dynarr.obj src/gfxutil.obj src/metasurf.obj src/noise.obj &
src/rbtree.obj src/screen.obj src/tinyfps.obj src/treestor.obj &
- src/ts_text.obj src/util.obj
+ src/ts_text.obj src/util.obj src/data.obj
scrobj = src/scr/bump.obj src/scr/fract.obj src/scr/greets.obj &
src/scr/grise.obj src/scr/hairball.obj src/scr/infcubes.obj &
src/scr/metaball.obj src/scr/plasma.obj src/scr/polytest.obj &
src/scr/smoketxt.obj src/scr/thunder.obj src/scr/tilemaze.obj &
src/scr/tunnel.obj
+csprobj = cspr/dbgfont.obj cspr/confont.obj
incpath = -Isrc -Isrc/dos -Isrc/3dgfx -Ilibs -Ilibs/imago/src -Ilibs/anim/src &
-Ilibs/midas
dosobj = src\dos\audos.obj src\dos\djdpmi.obj src\dos\gfx.obj src\dos\keyb.obj &
src\dos\logger.obj src\dos\main.obj src\dos\sball.obj src\dos\timer.obj &
- src\dos\vbe.obj src\dos\vga.obj src\dos\watdpmi.obj
+ src\dos\vbe.obj src\dos\vga.obj src\dos\watdpmi.obj src\dos\mouse.obj
3dobj = src\3dgfx\3dgfx.obj src\3dgfx\mesh.obj src\3dgfx\meshload.obj &
src\3dgfx\polyclip.obj src\3dgfx\polyfill.obj
-srcobj = src\3dgfx.obj src\bsptree.obj src\cfgopt.obj src\console.obj &
- src\demo.obj src\dynarr.obj src\gfxutil.obj src\mesh.obj src\meshload.obj &
- src\metasurf.obj src\noise.obj src\polyclip.obj src\polyfill.obj &
+srcobj = src\bsptree.obj src\cfgopt.obj src\console.obj src\demo.obj &
+ src\dynarr.obj src\gfxutil.obj src\metasurf.obj src\noise.obj &
src\rbtree.obj src\screen.obj src\tinyfps.obj src\treestor.obj &
- src\ts_text.obj src\util.obj
+ src\ts_text.obj src\util.obj src\data.obj
scrobj = src\scr\bump.obj src\scr\fract.obj src\scr\greets.obj &
src\scr\grise.obj src\scr\hairball.obj src\scr\infcubes.obj &
src\scr\metaball.obj src\scr\plasma.obj src\scr\polytest.obj &
src\scr\smoketxt.obj src\scr\thunder.obj src\scr\tilemaze.obj &
src\scr\tunnel.obj
+csprobj = cspr\dbgfont.obj cspr\confont.obj
incpath = -Isrc -Isrc\dos -Isrc\3dgfx -Ilibs -Ilibs\imago\src -Ilibs\anim\src &
-Ilibs\midas
libpath = libpath libs\imago libpath libs\anim libpath libs\midas
!endif
-obj = $(dosobj) $(3dobj) $(scrobj) $(srcobj)
+obj = $(dosobj) $(3dobj) $(scrobj) $(srcobj) $(csprobj)
bin = demo.exe
opt = -otexan
%write ldflags.lnk $(LDFLAGS)
$(LD) debug all name $@ system dos4g file { @objects } @ldflags
-.c: src;src/dos;src/3dgfx;src/scr
-.asm: src;src/dos;src/3dgfx;src/scr
+.c: src;src/dos;src/3dgfx;src/scr;cspr
+.asm: src;src/dos;src/3dgfx;src/scr;cspr
cflags.occ: Makefile
%write $@ $(CFLAGS)
alib = anim.lib
def = -dM_PI=3.141592653589793
-opt = -5 -fp5 -otexan -I.. -I../../src $(def)
+opt = -5 -fp5 -otexan
dbg = -d1
!ifdef __UNIX__
+inc = -I.. -I../../src
RM = rm -f
!else
+inc = -I.. -I..\..\src
RM = del
!endif
CC = wcc386
-CFLAGS = $(dbg) $(opt) $(def) -zq -bt=dos
+CFLAGS = $(dbg) $(opt) $(inc) $(def) -zq -bt=dos
$(alib): $(obj)
wlib -b -n $@ $(obj)
void anm_set_rotation_axis(struct anm_node *node, float angle, float x, float y, float z, anm_time_t tm)
{
cgm_quat q;
- cgm_vec3 axis;
-
- cgm_vcons(&axis, x, y, z);
- cgm_qrotation(&q, &axis, angle);
+ cgm_qrotation(&q, angle, x, y, z);
anm_set_rotation(node, (float*)&q, tm);
}
- section .data
+ section .data USE32
global loading_pixels
global _loading_pixels
#include <ctype.h>
#include "audio.h"
#include "midasdll.h"
+#include "util.h"
#define SET_MUS_VOL(vol) \
do { \
{
return ticks * tick_interval;
}
+
+void sleep_msec(unsigned long msec)
+{
+ unsigned long wakeup_time = ticks + msec / tick_interval;
+ while(ticks < wakeup_time) {
+#ifdef USE_HLT
+ halt();
+#endif
+ }
+}
}
}
- if(init(argc, argv) == -1) {
+ if(demo_init(argc, argv) == -1) {
status = -1;
goto break_evloop;
}
for(;;) {
int key;
while((key = kb_getkey()) != -1) {
- demo_key(key, 1);
+ demo_keyboard(key, 1);
if(quit) goto break_evloop;
}
}
time_msec = get_msec();
- draw();
+ demo_draw();
}
break_evloop:
- cleanup();
+ demo_cleanup();
set_text_mode();
cleanup_video();
kb_shutdown();
#include <string.h>
-#include "gfxutil.h"
#include "demo.h"
+#include "gfxutil.h"
enum {
IN = 0,
#define BLUR(w, h, pstep, sstep) \
for(i=0; i<h; i++) { \
- int sum = sptr[0] * (rad + 1); \
+ int r, g, b; \
+ int rsum = UNPACK_R16(sptr[0]) * (rad + 1); \
+ int gsum = UNPACK_G16(sptr[0]) * (rad + 1); \
+ int bsum = UNPACK_B16(sptr[0]) * (rad + 1); \
int count = (rad * 2 + 1) << 8; \
int midsize = w - rad * 2; \
- int firstpix = sptr[0]; \
- int lastpix = sptr[pstep * (w - 1)]; \
+ int rfirstpix = UNPACK_R16(sptr[0]); \
+ int rlastpix = UNPACK_R16(sptr[pstep * (w - 1)]); \
+ int gfirstpix = UNPACK_G16(sptr[0]); \
+ int glastpix = UNPACK_G16(sptr[pstep * (w - 1)]); \
+ int bfirstpix = UNPACK_B16(sptr[0]); \
+ int blastpix = UNPACK_B16(sptr[pstep * (w - 1)]); \
/* add up the contributions for the -1 pixel */ \
for(j=0; j<rad; j++) { \
- sum += sptr[pstep * j]; \
+ rsum += UNPACK_R16(sptr[pstep * j]); \
+ gsum += UNPACK_G16(sptr[pstep * j]); \
+ bsum += UNPACK_B16(sptr[pstep * j]); \
} \
/* first part adding sptr[rad] and subtracting sptr[0] */ \
for(j=0; j<=rad; j++) { \
- sum += (int)sptr[pstep * rad] - firstpix; \
+ rsum += UNPACK_R16((int)sptr[pstep * rad]) - rfirstpix; \
+ gsum += UNPACK_G16((int)sptr[pstep * rad]) - gfirstpix; \
+ bsum += UNPACK_B16((int)sptr[pstep * rad]) - bfirstpix; \
sptr += pstep; \
- *dptr = scale * sum / count; \
+ r = scale * rsum / count; \
+ g = scale * gsum / count; \
+ b = scale * bsum / count; \
+ *dptr = PACK_RGB16(r, g, b); \
dptr += pstep; \
} \
/* middle part adding sptr[rad] and subtracting sptr[-(rad+1)] */ \
for(j=1; j<midsize; j++) { \
- sum += (int)sptr[pstep * rad] - (int)sptr[-(rad + 1) * pstep]; \
+ rsum += UNPACK_R16((int)sptr[pstep * rad]) - UNPACK_R16((int)sptr[-(rad + 1) * pstep]); \
+ gsum += UNPACK_G16((int)sptr[pstep * rad]) - UNPACK_G16((int)sptr[-(rad + 1) * pstep]); \
+ bsum += UNPACK_B16((int)sptr[pstep * rad]) - UNPACK_B16((int)sptr[-(rad + 1) * pstep]); \
sptr += pstep; \
- *dptr = scale * sum / count; \
+ r = scale * rsum / count; \
+ g = scale * gsum / count; \
+ b = scale * bsum / count; \
+ *dptr = PACK_RGB16(r, g, b); \
dptr += pstep; \
} \
/* last part adding lastpix and subtracting sptr[-(rad+1)] */ \
for(j=0; j<rad; j++) { \
- sum += lastpix - (int)sptr[-(rad + 1) * pstep]; \
+ rsum += rlastpix - UNPACK_R16((int)sptr[-(rad + 1) * pstep]); \
+ gsum += glastpix - UNPACK_G16((int)sptr[-(rad + 1) * pstep]); \
+ bsum += blastpix - UNPACK_B16((int)sptr[-(rad + 1) * pstep]); \
sptr += pstep; \
- *dptr = scale * sum / count; \
+ r = scale * rsum / count; \
+ g = scale * gsum / count; \
+ b = scale * bsum / count; \
+ *dptr = PACK_RGB16(r, g, b); \
dptr += pstep; \
} \
sptr += sstep; \
/* TODO bound blur rad to image size to avoid inner loop conditionals */
/* TODO make version with pow2 (rad*2+1) to avoid div with count everywhere */
-void blur_grey_horiz(uint16_t *dest, uint16_t *src, int xsz, int ysz, int rad, int scale)
+void blur_horiz(uint16_t *dest, uint16_t *src, int xsz, int ysz, int rad, int scale)
{
int i, j;
- unsigned char *dptr = (unsigned char*)dest;
- unsigned char *sptr = (unsigned char*)src;
+ uint16_t *dptr = dest;
+ uint16_t *sptr = src;
- BLUR(xsz, ysz, 2, 0);
+ BLUR(xsz, ysz, 1, 0);
}
-void blur_grey_vert(uint16_t *dest, uint16_t *src, int xsz, int ysz, int rad, int scale)
+void blur_vert(uint16_t *dest, uint16_t *src, int xsz, int ysz, int rad, int scale)
{
int i, j;
- unsigned char *dptr = (unsigned char*)dest;
- unsigned char *sptr = (unsigned char*)src;
- int pixel_step = xsz * 2;
- int scanline_step = 2 - ysz * pixel_step;
+ uint16_t *dptr = dest;
+ uint16_t *sptr = src;
+ int pixel_step = xsz;
+ int scanline_step = 1 - ysz * pixel_step;
BLUR(ysz, xsz, pixel_step, scanline_step);
}
{
int i;
for(i=0; i<height; i++) {
- memcpy(dest, src, width * 2);
+ memcpy(dest, src, width << 1);
dest += 320;
+ }
+}
+
+void blit(uint16_t *dest, int destwidth, uint16_t *src, int width, int height, int pitch_pix)
+{
+ int i, spansz = width << 1;
+ for(i=0; i<height; i++) {
+ memcpy(dest, src, spansz);
+ dest += destwidth;
src += pitch_pix;
}
}
-void blitfb_key(uint16_t *dest, uint16_t *src, int width, int height, int pitch_pix, uint16_t key)
+void blit_key(uint16_t *dest, int destwidth, uint16_t *src, int width, int height, int pitch_pix, uint16_t key)
{
- int i, j, dadv = 320 - width;
+ int i, j;
+ int dadv = destwidth - width;
+ int sadv = pitch_pix - width;
for(i=0; i<height; i++) {
for(j=0; j<width; j++) {
dest++;
}
dest += dadv;
+ src += sadv;
}
}
#include "inttypes.h"
+
#define PACK_RGB16(r, g, b) \
((((uint16_t)(r) << 8) & 0xf800) | \
(((uint16_t)(g) << 3) & 0x7e0) | \
#define UNPACK_G16(c) (((c) >> 3) & 0xfc)
#define UNPACK_B16(c) (((c) << 3) & 0xf8)
+
+#ifdef BUILD_BIGENDIAN
+
+#define PACK_RGB32(r, g, b) \
+ ((((r) & 0xff) << 8) | (((g) & 0xff) << 16) | (((b) & 0xff) << 24) | 0xff)
+
+#define UNPACK_R32(c) (((c) >> 8) & 0xff)
+#define UNPACK_G32(c) (((c) >> 16) & 0xff)
+#define UNPACK_B32(c) (((c) >> 24) & 0xff)
+
+#else /* LITTLE_ENDIAN */
+
#define PACK_RGB32(r, g, b) \
- ((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff))
+ ((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff) | 0xff000000)
#define UNPACK_R32(c) (((c) >> 16) & 0xff)
#define UNPACK_G32(c) (((c) >> 8) & 0xff)
#define UNPACK_B32(c) ((c) & 0xff)
+#endif
int clip_line(int *x0, int *y0, int *x1, int *y1, int xmin, int ymin, int xmax, int ymax);
void draw_line(int x0, int y0, int x1, int y1, unsigned short color);
/* scale in 24.8 fixed point */
-void blur_grey_horiz(uint16_t *dest, uint16_t *src, int xsz, int ysz, int radius, int scale);
-void blur_grey_vert(uint16_t *dest, uint16_t *src, int xsz, int ysz, int radius, int scale);
+void blur_horiz(uint16_t *dest, uint16_t *src, int xsz, int ysz, int radius, int scale);
+void blur_vert(uint16_t *dest, uint16_t *src, int xsz, int ysz, int radius, int scale);
void convimg_rgb24_rgb16(uint16_t *dest, unsigned char *src, int xsz, int ysz);
-void blitfb(uint16_t *dest, uint16_t *src, int xsz, int ysz, int pitch_pix);
-void blitfb_key(uint16_t *dest, uint16_t *src, int xsz, int ysz, int pitch_pix, uint16_t key);
+void blitfb(uint16_t *dest, uint16_t *src, int width, int height, int pitch_pix);
+void blit(uint16_t *dest, int destwidth, uint16_t *src, int xsz, int ysz, int pitch_pix);
+void blit_key(uint16_t *dest, int destwidth, uint16_t *src, int xsz, int ysz, int pitch_pix, uint16_t key);
#endif /* GFXUTIL_H_ */
draw_smktxt(stx);
g3d_framebuffer(FB_WIDTH, FB_HEIGHT, fb_pixels);
- dest = fb_pixels;
- src = cur_smokebuf;
- for(i=0; i<FB_HEIGHT; i++) {
- for(j=0; j<FB_WIDTH; j++) {
- unsigned int alpha = *src++;
- *dest++ = PACK_RGB16(alpha, alpha, alpha);
- }
- }
+ memcpy(fb_pixels, cur_smokebuf, smokebuf_size);
/*perf_start();*/
- blur_grey_horiz(prev_smokebuf, cur_smokebuf, FB_WIDTH, FB_HEIGHT, BLUR_RAD, 240);
+ blur_horiz(prev_smokebuf, cur_smokebuf, FB_WIDTH, FB_HEIGHT, BLUR_RAD, 240);
/*
perf_end();
printf("blur perf: %lu\n", (unsigned long)perf_interval_count);
*/
- blur_grey_vert(cur_smokebuf, prev_smokebuf, FB_WIDTH, FB_HEIGHT, BLUR_RAD, 240);
+ blur_vert(cur_smokebuf, prev_smokebuf, FB_WIDTH, FB_HEIGHT, BLUR_RAD, 240);
swap_smoke_buffers();
msec = get_msec();
void end_loadscr(void)
{
blitfb(loading_pixels + SPLAT_Y * 320 + SPLAT_X, loading_pixels + 320 * 240, 32, 72, 32);
- blitfb_key(loading_pixels + FING_Y * 320 + FING_LAST_X, loading_pixels + 247 * 320 + 64,
+ blit_key(loading_pixels + FING_Y * 320 + FING_LAST_X, 320, loading_pixels + 247 * 320 + 64,
FING_W, FING_H, FING_W, 0);
swap_buffers(loading_pixels);
sleep_msec(300);
dptr = loading_pixels + FING_Y * 320 + FING_X + prev_xoffs;
while(prev_xoffs < xoffs) {
- blitfb_key(dptr, sptr, FING_W, FING_H, FING_W, 0);
+ blit_key(dptr, 320, sptr, FING_W, FING_H, FING_W, 0);
dptr++;
prev_xoffs++;
}
#define PACKED
#endif
+#define BSWAP16(x) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
+#define BSWAP32(x) \
+ ((((x) >> 24) & 0xff) | \
+ (((x) >> 8) & 0xff00) | \
+ (((x) << 8) & 0xff0000) | \
+ ((x) << 24))
+
+#if defined(__i386__) || defined(__x86_64__) || defined(__386__) || defined(MSDOS)
/* fast conversion of double -> 32bit int
* for details see:
* - http://chrishecker.com/images/f/fb/Gdmfp.pdf
val += 6755399441055744.0;
return *(int32_t*)&val;
}
+#else
+#define cround64(x) ((int32_t)(x))
+#endif
+
+static INLINE float rsqrt(float x)
+{
+ float xhalf = x * 0.5f;
+ int32_t i = *(int32_t*)&x;
+ i = 0x5f3759df - (i >> 1);
+ x = *(float*)&i;
+ x = x * (1.5f - xhalf * x * x);
+ return x;
+}
extern uint32_t perf_start_count, perf_interval_count;
#ifdef __WATCOMC__
+void memset16(void *dest, uint16_t val, int count);
+#pragma aux memset16 = \
+ "cld" \
+ "test ecx, 1" \
+ "jz memset16_dwords" \
+ "rep stosw" \
+ "jmp memset16_done" \
+ "memset16_dwords:" \
+ "shr ecx, 1" \
+ "push ax" \
+ "shl eax, 16" \
+ "pop ax" \
+ "rep stosd" \
+ "memset16_done:" \
+ parm[edi][ax][ecx];
+
+#ifdef USE_MMX
+void memcpy64(void *dest, void *src, int count);
+#pragma aux memcpy64 = \
+ "cploop:" \
+ "movq mm0, [edx]" \
+ "movq [ebx], mm0" \
+ "add edx, 8" \
+ "add ebx, 8" \
+ "dec ecx" \
+ "jnz cploop" \
+ "emms" \
+ parm[ebx][edx][ecx] \
+ modify[8087];
+#else
+#define memcpy64(dest, src, count) memcpy(dest, src, (count) << 3)
+#endif
+
void perf_start(void);
#pragma aux perf_start = \
"xor eax, eax" \
void halt(void);
#pragma aux halt = "hlt";
-
-void memset16(void *ptr, int val, int count);
-#pragma aux memset16 = \
- "rep stosw" \
- parm[edi][eax][ecx];
#endif
#ifdef __GNUC__
+#if defined(__i386__) || defined(__x86_64__)
+#define memset16(dest, val, count) asm volatile ( \
+ "cld\n\t" \
+ "test $1, %2\n\t" \
+ "jz 0f\n\t" \
+ "rep stosw\n\t" \
+ "jmp 1f\n\t" \
+ "0:\n\t" \
+ "shr $1, %2\n\t" \
+ "push %%ax\n\t" \
+ "shl $16, %%eax\n\t" \
+ "pop %%ax\n\t" \
+ "rep stosl\n\t" \
+ "1:\n\t"\
+ :: "D"(dest), "a"((uint16_t)(val)), "c"(count) \
+ : "memory")
+#else
+static void INLINE memset16(void *dest, uint16_t val, int count)
+{
+ uint16_t *ptr = dest;
+ while(count--) *ptr++ = val;
+}
+#endif
+
+#ifdef USE_MMX
+#define memcpy64(dest, src, count) asm volatile ( \
+ "0:\n\t" \
+ "movq (%1), %%mm0\n\t" \
+ "movq %%mm0, (%0)\n\t" \
+ "add $8, %1\n\t" \
+ "add $8, %0\n\t" \
+ "dec %2\n\t" \
+ "jnz 0b\n\t" \
+ "emms\n\t" \
+ :: "r"(dest), "r"(src), "r"(count) \
+ : "%mm0")
+#else
+#define memcpy64(dest, src, count) memcpy(dest, src, (count) << 3)
+#endif
+
#define perf_start() asm volatile ( \
"xor %%eax, %%eax\n" \
"cpuid\n" \
#define halt() \
asm volatile("hlt")
-
-#define memset16(ptr, val, count) asm volatile ( \
- "rep stosw\n\t" \
- :: "D"(ptr), "a"(val), "c"(count))
#endif
#ifdef _MSC_VER
+void __inline memset16(void *dest, uint16_t val, int count)
+{
+ __asm {
+ cld
+ mov ax, val
+ mov edi, dest
+ mov ecx, count
+ test ecx, 1
+ jz memset16_dwords
+ rep stosw
+ jmp memset16_done
+ memset16_dwords:
+ shr ecx, 1
+ push ax
+ shl eax, 16
+ pop ax
+ rep stosd
+ memset16_done:
+ }
+}
+
#define perf_start() \
do { \
__asm { \
do { \
__asm { int 3 } \
} while(0)
-
-#define memset16(ptr, val, count) \
- do { \
- __asm { \
- mov edi, ptr \
- mov ecx, count \
- mov eax, val \
- rep stosw \
- } \
- } while(0)
#endif
#endif /* UTIL_H_ */
"\tsection .text\n"
"\tglobal %s\n"
"\tglobal _%s\n"
+ "\tglobal %s_\n"
"%s:\n"
"_%s:\n"
"\tmov eax, [esp + 12]\n"
"\tmov edx, eax\n"
"\tmov eax, [esp + 16]\n"
"\tjmp [titletab + eax * 4]\n\n"
+ "%s_:\n"
+ "\tpush eax\n"
+ "\tmov eax, ebx\n"
+ "\tshl eax, 9\n"
+ "\tshl ebx, 7\n"
+ "\tadd eax, ebx\n"
+ "\tshl edx, 1\n"
+ "\tadd eax, edx\n"
+ "\tpop edx\n"
+ "\tadd edx, eax\n"
+ "\tjmp [titletab + ecx * 4]\n\n"
"titletab:\n"
};
ysz = tile_ysz;
}
- printf(prefixfmt[asyntax], name, name, name, name, fbpitch);
+ printf(prefixfmt[asyntax], name, name, name, name, name, fbpitch, name);
for(i=0; i<num_ytiles*num_xtiles; i++) {
if(asyntax == AS_GNU) {
printf("\t.long tile%d\n", i);