backport builds
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 13 Jun 2020 10:59:00 +0000 (13:59 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 13 Jun 2020 10:59:00 +0000 (13:59 +0300)
13 files changed:
GNUmakefile
Makefile
libs/anim/Makefile
libs/anim/src/anim.c
src/data.asm
src/dos/audos.c
src/dos/main.c
src/gfxutil.c
src/gfxutil.h
src/scr/greets.c
src/screen.c
src/util.h
tools/csprite/src/main.c

index 6e91ee8..49fb3a1 100644 (file)
@@ -7,7 +7,7 @@ bin = demo
 asmsrc += cspr/dbgfont.asm cspr/confont.asm
 bindata = data/loading.img
 
 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`
 warn = -pedantic -Wall -Wno-unused-variable -Wno-unused-function
 
 CFLAGS = $(arch) $(warn) -g $(inc) `sdl-config --cflags`
index 8a2db49..0b6a460 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,19 @@
 !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 &
 !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
 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/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
 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
 
 incpath = -Isrc -Isrc/dos -Isrc/3dgfx -Ilibs -Ilibs/imago/src -Ilibs/anim/src &
        -Ilibs/midas
@@ -22,26 +22,26 @@ libpath = libpath libs/imago libpath libs/anim libpath libs/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 &
 
 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
 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\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
 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
 
 
 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
 bin = demo.exe
 
 opt = -otexan
@@ -61,8 +61,8 @@ $(bin): cflags.occ $(obj) libs/imago/imago.lib libs/anim/anim.lib
        %write ldflags.lnk $(LDFLAGS)
        $(LD) debug all name $@ system dos4g file { @objects } @ldflags
 
        %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)
 
 cflags.occ: Makefile
        %write $@ $(CFLAGS)
index 657e083..5da7a19 100644 (file)
@@ -2,17 +2,19 @@ obj = anim.obj track.obj
 alib = anim.lib
 
 def = -dM_PI=3.141592653589793
 alib = anim.lib
 
 def = -dM_PI=3.141592653589793
-opt = -5 -fp5 -otexan -I.. -I../../src $(def)
+opt = -5 -fp5 -otexan
 dbg = -d1
 
 !ifdef __UNIX__
 dbg = -d1
 
 !ifdef __UNIX__
+inc =  -I.. -I../../src
 RM = rm -f
 !else
 RM = rm -f
 !else
+inc =  -I.. -I..\..\src
 RM = del
 !endif
 
 CC = wcc386
 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)
 
 $(alib): $(obj)
        wlib -b -n $@ $(obj)
index a2f1944..6468d31 100644 (file)
@@ -617,11 +617,8 @@ void anm_set_rotation4f(struct anm_node *node, float x, float y, float z, float
 void anm_set_rotation_axis(struct anm_node *node, float angle, float x, float y, float z, anm_time_t tm)
 {
        cgm_quat q;
 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);
 }
 
        anm_set_rotation(node, (float*)&q, tm);
 }
 
index 26234fc..e9cd436 100644 (file)
@@ -1,4 +1,4 @@
-       section .data
+       section .data USE32
 
        global loading_pixels
        global _loading_pixels
 
        global loading_pixels
        global _loading_pixels
index 513bf89..6b7709a 100644 (file)
@@ -4,6 +4,7 @@
 #include <ctype.h>
 #include "audio.h"
 #include "midasdll.h"
 #include <ctype.h>
 #include "audio.h"
 #include "midasdll.h"
+#include "util.h"
 
 #define SET_MUS_VOL(vol) \
        do { \
 
 #define SET_MUS_VOL(vol) \
        do { \
@@ -209,3 +210,13 @@ unsigned long get_msec(void)
 {
        return ticks * tick_interval;
 }
 {
        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
+       }
+}
index 0de90ed..b415bb4 100644 (file)
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
                }
        }
 
                }
        }
 
-       if(init(argc, argv) == -1) {
+       if(demo_init(argc, argv) == -1) {
                status = -1;
                goto break_evloop;
        }
                status = -1;
                goto break_evloop;
        }
@@ -83,7 +83,7 @@ int main(int argc, char **argv)
        for(;;) {
                int key;
                while((key = kb_getkey()) != -1) {
        for(;;) {
                int key;
                while((key = kb_getkey()) != -1) {
-                       demo_key(key, 1);
+                       demo_keyboard(key, 1);
                        if(quit) goto break_evloop;
                }
 
                        if(quit) goto break_evloop;
                }
 
@@ -99,11 +99,11 @@ int main(int argc, char **argv)
                }
 
                time_msec = get_msec();
                }
 
                time_msec = get_msec();
-               draw();
+               demo_draw();
        }
 
 break_evloop:
        }
 
 break_evloop:
-       cleanup();
+       demo_cleanup();
        set_text_mode();
        cleanup_video();
        kb_shutdown();
        set_text_mode();
        cleanup_video();
        kb_shutdown();
index 259b56d..d410766 100644 (file)
@@ -1,6 +1,6 @@
 #include <string.h>
 #include <string.h>
-#include "gfxutil.h"
 #include "demo.h"
 #include "demo.h"
+#include "gfxutil.h"
 
 enum {
        IN              = 0,
 
 enum {
        IN              = 0,
@@ -147,34 +147,58 @@ void draw_line(int x0, int y0, int x1, int y1, unsigned short color)
 
 #define BLUR(w, h, pstep, sstep) \
        for(i=0; i<h; i++) { \
 
 #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 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++) { \
                /* 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++) { \
                } \
                /* 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; \
                        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++) { \
                        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; \
                        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++) { \
                        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; \
                        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; \
                        dptr += pstep; \
                } \
                sptr += sstep; \
@@ -183,23 +207,23 @@ void draw_line(int x0, int y0, int x1, int y1, unsigned short color)
 
 /* 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 */
 
 /* 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;
 {
        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;
 {
        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);
 }
 
        BLUR(ysz, xsz, pixel_step, scanline_step);
 }
@@ -221,15 +245,26 @@ void blitfb(uint16_t *dest, uint16_t *src, int width, int height, int pitch_pix)
 {
        int i;
        for(i=0; i<height; i++) {
 {
        int i;
        for(i=0; i<height; i++) {
-               memcpy(dest, src, width * 2);
+               memcpy(dest, src, width << 1);
                dest += 320;
                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;
        }
 }
 
                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++) {
 
        for(i=0; i<height; i++) {
                for(j=0; j<width; j++) {
@@ -238,6 +273,7 @@ void blitfb_key(uint16_t *dest, uint16_t *src, int width, int height, int pitch_
                        dest++;
                }
                dest += dadv;
                        dest++;
                }
                dest += dadv;
+               src += sadv;
        }
 
 }
        }
 
 }
index b46f813..d4f06c6 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "inttypes.h"
 
 
 #include "inttypes.h"
 
+
 #define PACK_RGB16(r, g, b) \
        ((((uint16_t)(r) << 8) & 0xf800) | \
         (((uint16_t)(g) << 3) & 0x7e0) | \
 #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)
 
 #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) \
 #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)
 
 #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 */
 
 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 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_ */
 
 #endif /* GFXUTIL_H_ */
index 49a5b50..9a49527 100644 (file)
@@ -154,22 +154,15 @@ static void draw(void)
        draw_smktxt(stx);
        g3d_framebuffer(FB_WIDTH, FB_HEIGHT, fb_pixels);
 
        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();*/
 
        /*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);
        */
        /*
        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();
        swap_smoke_buffers();
 
        msec = get_msec();
index 5167d96..8069ce8 100644 (file)
@@ -204,7 +204,7 @@ void start_loadscr(void)
 void end_loadscr(void)
 {
        blitfb(loading_pixels + SPLAT_Y * 320 + SPLAT_X, loading_pixels + 320 * 240, 32, 72, 32);
 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);
                        FING_W, FING_H, FING_W, 0);
        swap_buffers(loading_pixels);
        sleep_msec(300);
@@ -220,7 +220,7 @@ void loadscr(int n, int count)
        dptr = loading_pixels + FING_Y * 320 + FING_X + prev_xoffs;
 
        while(prev_xoffs < xoffs) {
        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++;
        }
                dptr++;
                prev_xoffs++;
        }
index b305d78..8a46036 100644 (file)
 #define PACKED
 #endif
 
 #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
 /* fast conversion of double -> 32bit int
  * for details see:
  *  - http://chrishecker.com/images/f/fb/Gdmfp.pdf
@@ -26,10 +34,56 @@ static INLINE int32_t cround64(double val)
        val += 6755399441055744.0;
        return *(int32_t*)&val;
 }
        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__
 
 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 perf_start(void);
 #pragma aux perf_start = \
        "xor eax, eax" \
@@ -52,14 +106,49 @@ void debug_break(void);
 
 void halt(void);
 #pragma aux halt = "hlt";
 
 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__
 #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 perf_start()  asm volatile ( \
        "xor %%eax, %%eax\n" \
        "cpuid\n" \
@@ -83,13 +172,30 @@ void memset16(void *ptr, int val, int count);
 
 #define halt() \
        asm volatile("hlt")
 
 #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
 #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 { \
 #define perf_start() \
        do { \
                __asm { \
@@ -115,16 +221,6 @@ void memset16(void *ptr, int val, int count);
        do { \
                __asm { int 3 } \
        } while(0)
        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_ */
 #endif
 
 #endif /* UTIL_H_ */
index fab302b..039a0eb 100644 (file)
@@ -147,6 +147,7 @@ const char *prefixfmt[] = {
        "\tsection .text\n"
        "\tglobal %s\n"
        "\tglobal _%s\n"
        "\tsection .text\n"
        "\tglobal %s\n"
        "\tglobal _%s\n"
+       "\tglobal %s_\n"
        "%s:\n"
        "_%s:\n"
        "\tmov eax, [esp + 12]\n"
        "%s:\n"
        "_%s:\n"
        "\tmov eax, [esp + 12]\n"
@@ -162,6 +163,17 @@ const char *prefixfmt[] = {
        "\tmov edx, eax\n"
        "\tmov eax, [esp + 16]\n"
        "\tjmp [titletab + eax * 4]\n\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"
 };
 
        "titletab:\n"
 };
 
@@ -217,7 +229,7 @@ int proc_sheet(const char *fname)
                ysz = tile_ysz;
        }
 
                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);
        for(i=0; i<num_ytiles*num_xtiles; i++) {
                if(asyntax == AS_GNU) {
                        printf("\t.long tile%d\n", i);