Added FreeBSD makefiles and related changes.
authorFlorian Schulze <crow@icculus.org>
Sun, 22 Sep 2002 19:03:26 +0000 (19:03 +0000)
committerFlorian Schulze <crow@icculus.org>
Sun, 22 Sep 2002 19:03:26 +0000 (19:03 +0000)
17 files changed:
AUTHORS
ChangeLog
Makefile
VisualC6/jumpnbump.dsp
data/Makefile
dj.h
globals.pre [moved from globals.h with 97% similarity]
jnbmenu.pre [moved from jnbmenu.tcl with 97% similarity, mode: 0644]
main.c
menu.c
modify/Makefile [new file with mode: 0644]
modify/gobpack.c
sdl/Makefile [new file with mode: 0644]
sdl/gfx.c
sdl/input.c
sdl/interrpt.c
sdl/sound.c

diff --git a/AUTHORS b/AUTHORS
index 713aa44..5bebec6 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -46,3 +46,9 @@ David Garc
 
 Ryan C. Gordon <icculus@clutteredmind.org>
   Made networking possible again.
+
+Martin Willemoes Hansen <mwh@sysrq.dk>
+  The python frontend.
+
+Alessandro Gatti <a.gatti@tiscali.it>
+  FreeBSD fixes.
index c32722a..06b3cdd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
-Sep 2002 - 1.
+Sep 2002 - 1.40
+  - new frontend (thanks mwh/name/email/url)
+  - manpage update
+  - joystick support added
+  - freebsd ports (thanks rigel from #demoscene)
   - a while back network code using kaillera was send to me by Gil Megidish,
     it's not enabled, because it doesn't seem to work good enough.
 
index 1041398..b965c6a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,41 +1,59 @@
-OBJS = sdl/gfx.o sdl/interrpt.o sdl/sound.o sdl/input.o fireworks.o main.o menu.o
+SDL_CFLAGS = `sdl-config --cflags`
+SDL_LIBS = `sdl-config --libs`
+CFLAGS = -Wall -O2 -ffast-math -funroll-loops -Dstricmp=strcasecmp \
+       -Dstrnicmp=strncasecmp -DUSE_SDL -DNDEBUG -I. $(SDL_CFLAGS) -DUSE_NET
+LIBS = -lm $(SDL_LIBS) -lSDL_mixer -lSDL_net
+SDL_TARGET = sdl.a
+MODIFY_TARGET = gobpack jnbpack jnbunpack
+OBJS = fireworks.o main.o menu.o
 TARGET = jumpnbump
-
-CC = gcc
-CFLAGS = -Wall -O2 -ffast-math -funroll-loops -Dstricmp=strcasecmp -Dstrnicmp=strncasecmp -DUSE_SDL -DNDEBUG -I. $(shell sdl-config --cflags) -DUSE_NET
-LIBS = -lm $(shell sdl-config --libs) -lSDL_mixer -lSDL_net
+BINARIES = $(TARGET) jumpnbump.svgalib jumpnbump.fbcon $(MODIFY_TARGET) \
+       jnbmenu.tcl
+PREFIX ?= /usr/local
 
 .PHONY: data
 
-all: $(TARGET) jnbpack jnbunpack gobpack data
+all: $(BINARIES)
+
+$(SDL_TARGET): globals.h
+       cd sdl && make
+
+$(MODIFY_TARGET): globals.h
+       cd modify && make
 
-$(TARGET): $(OBJS)
-       $(CC) $(LFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
+$(TARGET): $(OBJS) $(SDL_TARGET) data globals.h
+       $(CC) -o $(TARGET) $(OBJS) $(LIBS) $(SDL_TARGET)
 
-jnbpack: modify/jnbpack.o
-       $(CC) $(LFLAGS) -o jnbpack modify/jnbpack.o $(LIBS)
+$(OBJS): globals.h
 
-jnbunpack: modify/jnbunpack.o
-       $(CC) $(LFLAGS) -o jnbunpack modify/jnbunpack.o $(LIBS)
+globals.h: globals.pre
+       sed -e "s#%%PREFIX%%#$(PREFIX)#g" < globals.pre > globals.h
 
-gobpack: modify/gobpack.o
-       $(CC) $(LFLAGS) -o gobpack modify/gobpack.o $(LIBS)
+jnbmenu.tcl: jnbmenu.pre
+       sed -e "s#%%PREFIX%%#$(PREFIX)#g" < jnbmenu.pre > jnbmenu.tcl
 
 data: jnbpack
-       $(MAKE) -C data
+       cd data && make
 
 clean:
-       rm -f $(TARGET) jnbpack jnbunpack *.o sdl/*.o *~ log modify/*.o
-       $(MAKE) -C data clean
+       cd sdl && make clean
+       cd modify && make clean
+       cd data && make clean
+       rm -f $(TARGET) *.o globals.h jnbmenu.tcl
 
 install:
-       mkdir -p $(DESTDIR)/usr/games/
-       mkdir -p $(DESTDIR)/usr/share/jumpnbump/
-       install -o root -g games -m 755 $(TARGET) jumpnbump.svgalib jumpnbump.fbcon gobpack jnbpack jnbunpack jnbmenu.tcl $(DESTDIR)/usr/games/
-       install -o root -g games -m 644 data/jumpbump.dat $(DESTDIR)/usr/share/jumpnbump/jumpbump.dat
+       mkdir -p $(PREFIX)/games/
+       mkdir -p $(PREFIX)/share/jumpnbump/
+       mkdir -p $(PREFIX)/share/man/man6/
+       install -o root -g games -m 755 $(BINARIES) $(PREFIX)/games/
+       install -o root -g games -m 644 data/jumpbump.dat \
+       $(PREFIX)/share/jumpnbump/jumpbump.dat
+       install -o root -g root -m 644 jumpnbump.6 $(PREFIX)/share/man/man6/
 
 uninstall:
-       rm /usr/games/jnbpack /usr/games/jnbunpack /usr/games/jumpnbump /usr/games/jnbmenu.tcl /usr/games/jumpnbump.fbcon /usr/games/jumpnbump.svgalib /usr/games/gobpack
+       cd $(PREFIX)/games && rm -f $(BINARIES)
+       rm -rf $(PREFIX)/share/jumpnbump
+       rm -f $(PREFIX)/share/man/man6/jumpnbump.6
 
 doc:
        rman jumpnbump.6 -f HTML >jumpnbump.html
index 10dc598..cbb3aaf 100644 (file)
@@ -61,7 +61,8 @@ InputPath=.\Release\jumpnbump.exe
 SOURCE="$(InputPath)"
 
 BuildCmds= \
-       call "$(ProjDir)\..\data\pack.bat" "$(ProjDir)\..\data" "..\VisualC6\gobpack\Release\gobpack.exe" "..\VisualC6\pack\Release\jnbpack.exe"
+       call "$(ProjDir)\..\data\pack.bat" "$(ProjDir)\..\data" "..\VisualC6\gobpack\Release\gobpack.exe" "..\VisualC6\pack\Release\jnbpack.exe" \
+       
 
 "$(ProjDir)\..\data\font.gob" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
    $(BuildCmds)
@@ -110,7 +111,8 @@ InputPath=.\Debug\jumpnbump.exe
 SOURCE="$(InputPath)"
 
 BuildCmds= \
-       call "$(ProjDir)\..\data\pack.bat" "$(ProjDir)\..\data" "..\VisualC6\gobpack\Debug\gobpack.exe" "..\VisualC6\pack\Debug\jnbpack.exe"
+       call "$(ProjDir)\..\data\pack.bat" "$(ProjDir)\..\data" "..\VisualC6\gobpack\Debug\gobpack.exe" "..\VisualC6\pack\Debug\jnbpack.exe" \
+       
 
 "$(ProjDir)\..\data\font.gob" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
    $(BuildCmds)
@@ -179,7 +181,32 @@ SOURCE=..\dj.h
 # End Source File
 # Begin Source File
 
-SOURCE=..\globals.h
+SOURCE=..\globals.pre
+
+!IF  "$(CFG)" == "jumpnbump - Win32 Release"
+
+# Begin Custom Build
+ProjDir=.
+InputPath=..\globals.pre
+
+"$(ProjDir)\..\globals.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+       copy "$(ProjDir)\..\globals.pre" "$(ProjDir)\..\globals.h"
+
+# End Custom Build
+
+!ELSEIF  "$(CFG)" == "jumpnbump - Win32 Debug"
+
+# Begin Custom Build
+ProjDir=.
+InputPath=..\globals.pre
+
+"$(ProjDir)\..\globals.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+       copy "$(ProjDir)\..\globals.pre" "$(ProjDir)\..\globals.h"
+
+# End Custom Build
+
+!ENDIF 
+
 # End Source File
 # Begin Source File
 
index c7645d3..de362fe 100644 (file)
@@ -1,3 +1,8 @@
+GOBS = numbers.gob objects.gob rabbit.gob
+DATAFILES = bump.mod calib.dat death.smp fly.smp font.gob jump.mod \
+       jump.smp levelmap.txt level.pcx mask.pcx menu.pcx \
+       menumask.pcx $(GOBS) scores.mod splash.smp spring.smp
+
 all: jumpbump.dat
 
 font.gob:
@@ -12,8 +17,11 @@ numbers.gob:
 objects.gob:
        ../gobpack objects
 
-jumpbump.dat: bump.mod calib.dat death.smp fly.smp font.gob jump.mod jump.smp levelmap.txt level.pcx mask.pcx menu.pcx menumask.pcx numbers.gob objects.gob rabbit.gob scores.mod splash.smp spring.smp
-       ../jnbpack -o jumpbump.dat bump.mod calib.dat death.smp fly.smp font.gob jump.mod jump.smp levelmap.txt level.pcx mask.pcx menu.pcx menumask.pcx numbers.gob objects.gob rabbit.gob scores.mod splash.smp spring.smp
+jumpbump.dat: $(DATAFILES) ../jnbpack
+       ../jnbpack -o jumpbump.dat $(DATAFILES)
+
+../jnbpack:
+       cd ../modify && make
 
 clean:
-       rm -f jumpbump.dat font.gob rabbit.gob numbers.gob objects.gob
+       rm -f jumpbump.dat $(GOBS)
diff --git a/dj.h b/dj.h
index 4c45dc8..66a786e 100644 (file)
--- a/dj.h
+++ b/dj.h
@@ -27,7 +27,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-//#include <conio.h>
 
 #ifdef DOS
 #include <pc.h>
similarity index 97%
rename from globals.h
rename to globals.pre
index bb59031..81a138e 100644 (file)
--- a/globals.h
@@ -59,16 +59,16 @@ extern "C" {
 # include <windows.h>
 # include <sys/stat.h>
 # include <io.h>
-# include <SDL.h>
+# include "SDL.h"
 # if USE_SDL_MIXER
-#  include <SDL_mixer.h>
+#  include "SDL_mixer.h"
 # endif
 #else
 # ifdef USE_SDL
 #  include <sys/stat.h>
-#  include <SDL/SDL.h>
+#  include "SDL.h"
 #  if USE_SDL_MIXER
-#   include <SDL/SDL_mixer.h>
+#   include "SDL_mixer.h"
 #  endif
 # endif
 #endif
@@ -83,7 +83,7 @@ void tellServerPlayerMoved(int playerid, int movement_type, int newval);
 #define MOVEMENT_RIGHT 2
 #define MOVEMENT_UP    3
 
-#define JNB_VERSION "1.39"
+#define JNB_VERSION "1.40"
 
 #define JNB_WIDTH 400
 #define JNB_HEIGHT 256
@@ -171,7 +171,7 @@ extern int bytes_per_pixel;
 #elif _WIN32
 #define        DATA_PATH "data/jumpbump.dat"
 #else
-#define        DATA_PATH "/usr/share/jumpnbump/jumpbump.dat"
+#define        DATA_PATH "%%PREFIX%%/share/jumpnbump/jumpbump.dat"
 #endif
 #endif
 
@@ -345,7 +345,7 @@ void register_mask(void *pixels);
 /* gfx.c */
 
 #ifdef USE_SDL
-//long filelength(int handle);
+/* long filelength(int handle); */
 void fs_toggle();
 int intr_sysupdate();
 #endif
old mode 100755 (executable)
new mode 100644 (file)
similarity index 97%
rename from jnbmenu.tcl
rename to jnbmenu.pre
index c0a77b9..8302560
@@ -49,14 +49,14 @@ global fullscreen
 
        set file ""
        if { [ .top17.lis26 curselection ] != "" } then {
-               set file "/usr/share/games/jumpnbump/[ .top17.lis26 get [.top17.lis26 curselection] ].dat"
+               set file "%%PREFIX%%/games/jumpnbump/[ .top17.lis26 get [.top17.lis26 curselection] ].dat"
        }
        
        exec jumpnbump $str_fullscreen $str_nosound $str_scaleup $str_mirror $str_nogore $str_fireworks -dat $file &
 }
 
 proc {fill_list_box} {} {
-if [ catch { exec ls /usr/share/games/jumpnbump/ } data ] {
+if [ catch { exec ls %%PREFIX%%/share/jumpnbump/ } data ] {
                puts stderr "Error"
        }
 
diff --git a/main.c b/main.c
index f2e73b9..dd9930c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -31,8 +31,8 @@
 #include <fcntl.h>
 
 #ifdef USE_NET
-#include <SDL_net.h>
-#endif // USE_NET
+#include "SDL_net.h"
+#endif /* USE_NET */
 
 #ifndef M_PI
 #define M_PI           3.14159265358979323846
@@ -370,7 +370,7 @@ int grabPacket(TCPsocket s, SDLNet_SocketSet ss, NetPacket *pkt)
                rc = SDLNet_TCP_Recv(s, &buf[buf_count], NETPKTBUFSIZE - buf_count);
                if (rc <= 0) {  /* closed connection? */
                        retval = -1;
-               } else if (rc != NETPKTBUFSIZE) { // !!! FIXME: buffer these?
+               } else if (rc != NETPKTBUFSIZE) {
                        buf_count = rc;
                } else {
                        buf_count = 0;
@@ -465,7 +465,7 @@ void tellServerGoodbye(void)
                sendPacketToSock(sock, &pkt);
        }
 }
-#endif // USE_NET
+#endif /* USE_NET */
 
 
 void processMovePacket(NetPacket *pkt)
@@ -526,7 +526,7 @@ void tellServerNewPosition(void)
                sendPacketToSock(sock, &pkt);
        }
 }
-#endif // USE_NET
+#endif /* USE_NET */
 
 
 void processKillPacket(NetPacket *pkt)
@@ -669,7 +669,7 @@ void serverSendAlive(int playerid)
        pkt.arg3 = player[playerid].y;
        sendPacketToAll(&pkt);
 }
-#endif // USE_NET
+#endif /* USE_NET */
 
 
 void serverSendKillPacket(int killer, int victim)
@@ -716,8 +716,10 @@ void update_players_from_clients(void)
                        }
                } else if (pkt.cmd == NETCMD_MOVE) {
                        pkt.arg = playerid;  /* just in case. */
-                       //pkt.arg3 = player[playerid].x;
-                       //pkt.arg4 = player[playerid].y;
+                       /*
+                       pkt.arg3 = player[playerid].x;
+                       pkt.arg4 = player[playerid].y;
+                       */
                        processMovePacket(&pkt);
                        sendPacketToAll(&pkt);
                } else {
@@ -910,7 +912,7 @@ void connect_to_server(char *netarg)
 
        br = SDLNet_TCP_Recv(sock, buf, NETPKTBUFSIZE);
        if (br < 0) {
-               fprintf(stderr, "CLIENT: recv(): %s\n", SDLNet_GetError);
+               fprintf(stderr, "CLIENT: recv(): %s\n", SDLNet_GetError());
                SDLNet_FreeSocketSet(socketset);
                SDLNet_TCP_Close(sock);
                exit(42);
@@ -943,10 +945,10 @@ void connect_to_server(char *netarg)
 
        wait_for_greenlight();
 }
-#endif // USE_NET
+#endif /* USE_NET */
 
 
-static flip_pixels(unsigned char *pixels)
+static void flip_pixels(unsigned char *pixels)
 {
        int x,y;
        unsigned char temp;
@@ -969,7 +971,7 @@ int main(int argc, char *argv[])
        int l1;
        int s1, s2, s3, s4;
        int closest_player = 0, dist, cur_dist = 0;
-       int end_loop_flag = 0, fade_flag;
+       int end_loop_flag = 0, fade_flag = 0;
        int mod_vol, sfx_vol, mod_fade_direction;
        char str1[100];
        char pal[768];
@@ -1002,7 +1004,6 @@ int main(int argc, char *argv[])
                setpalette(0, 256, cur_pal);
 
                recalculate_gob(&rabbit_gobs, pal);
-               //recalculate_gob(&font_gobs, pal);
                recalculate_gob(&object_gobs, pal);
                recalculate_gob(&number_gobs, pal);
 
@@ -1488,7 +1489,6 @@ int main(int argc, char *argv[])
                memset(mask_pic, 0, JNB_WIDTH*JNB_HEIGHT);
                register_mask(mask_pic);
 
-               //recalculate_gob(&font_gobs, pal);
                register_background(NULL, NULL);
 
                draw_begin();
@@ -1529,7 +1529,8 @@ int main(int argc, char *argv[])
                        return 1;
                }
 
-               for (c1 = 0; c1 < 16; c1++) { // fix dark font
+               /* fix dark font */
+               for (c1 = 0; c1 < 16; c1++) {
                        pal[(240 + c1) * 3 + 0] = c1 << 2;
                        pal[(240 + c1) * 3 + 1] = c1 << 2;
                        pal[(240 + c1) * 3 + 2] = c1 << 2;
@@ -2785,7 +2786,6 @@ int init_program(int argc, char *argv[], char *pal)
                                printf("  -v                       print version\n");
                                printf("  -dat level.dat           play a different level\n");
 #ifdef USE_NET
-                               //printf("  -port port               define listen port\n");
                                printf("  -server playercount      start as server waiting for players\n");
                                printf("  -connect host            connect to server\n");
 #endif
@@ -2975,7 +2975,8 @@ int init_program(int argc, char *argv[], char *pal)
        memset(mask_pic, 0, JNB_WIDTH*JNB_HEIGHT);
        register_mask(mask_pic);
 
-       for (c1 = 0; c1 < 16; c1++) { // fix dark font
+       /* fix dark font */
+       for (c1 = 0; c1 < 16; c1++) {
                pal[(240 + c1) * 3 + 0] = c1 << 2;
                pal[(240 + c1) * 3 + 1] = c1 << 2;
                pal[(240 + c1) * 3 + 2] = c1 << 2;
diff --git a/menu.c b/menu.c
index aef5cf4..c310c77 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -44,7 +44,7 @@ char *message[] = {
        "Linux port by Chuck Mason.",
        "New SDL port by Florian Schulze.",
        "http://www.icculus.org/jumpnbump/",
-       //"Ryan C. Gordon made networking possible again!",
+       "Ryan C. Gordon made networking possible again!",
        "Visit our homepage at:",
        "http://www.algonet.se/~mattiasb",
        "Jump 'n Bump is e-mailware.",
@@ -577,7 +577,8 @@ int menu_init(void)
        }
        memset(menu_cur_pal, 0, 768);
 
-       for (c1 = 0; c1 < 16; c1++) { // fix dark font
+       /* fix dark font */
+       for (c1 = 0; c1 < 16; c1++) {
                menu_pal[(240 + c1) * 3 + 0] = c1 << 2;
                menu_pal[(240 + c1) * 3 + 1] = c1 << 2;
                menu_pal[(240 + c1) * 3 + 2] = c1 << 2;
diff --git a/modify/Makefile b/modify/Makefile
new file mode 100644 (file)
index 0000000..2d4822b
--- /dev/null
@@ -0,0 +1,21 @@
+CFLAGS = -Wall -ansi -pedantic -O2 -ffast-math -funroll-loops \
+       -Dstricmp=strcasecmp -Dstrnicmp=strncasecmp -DNDEBUG \
+       -I. -I.. -DUSE_NET
+LIBS = -lm
+SRCS = gobpack.c jnbpack.c jnbunpack.c
+OBJS = gobpack.o jnbpack.o jnbunpack.o
+TARGETS = ../gobpack ../jnbpack ../jnbunpack
+
+all: $(TARGETS)
+
+../gobpack: gobpack.c
+       $(CC) $(CFLAGS) -o ../gobpack $(LIBS) gobpack.c
+
+../jnbpack: jnbpack.c
+       $(CC) $(CFLAGS) -o ../jnbpack $(LIBS) jnbpack.c
+
+../jnbunpack: jnbunpack.c
+       $(CC) $(CFLAGS) -o ../jnbunpack $(LIBS) jnbunpack.c
+
+clean:
+       rm -f $(TARGETS) $(OBJS)
index 1c55d0b..7e524a8 100644 (file)
@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <string.h>
 
 typedef struct {
@@ -43,34 +43,34 @@ static void write_pcx(FILE *pcxfile, unsigned char *data, int width, int height,
 {
        int    i;
 
-       fputc(0x0a, pcxfile); // manufacturer
-       fputc(5, pcxfile); // version
-       fputc(1, pcxfile); // encoding
-       fputc(8, pcxfile); // bits_per_pixel
-       fputc(0, pcxfile); // xmin
+       fputc(0x0a, pcxfile); /* manufacturer */
+       fputc(5, pcxfile); /* version */
+       fputc(1, pcxfile); /* encoding */
+       fputc(8, pcxfile); /* bits_per_pixel */
+       fputc(0, pcxfile); /* xmin */
        fputc(0, pcxfile);
-       fputc(0, pcxfile); // ymin
+       fputc(0, pcxfile); /* ymin */
        fputc(0, pcxfile);
-       fputc((width - 1) & 0xff, pcxfile); // xmax
+       fputc((width - 1) & 0xff, pcxfile); /* xmax */
        fputc(((width - 1) >> 8) & 0xff, pcxfile);
-       fputc((height - 1) & 0xff, pcxfile); // ymax
+       fputc((height - 1) & 0xff, pcxfile); /* ymax */
        fputc(((height - 1) >> 8) & 0xff, pcxfile);
-       fputc(width & 0xff, pcxfile); // hres
+       fputc(width & 0xff, pcxfile); /* hres */
        fputc((width >> 8) & 0xff, pcxfile);
-       fputc(height & 0xff, pcxfile); // vres
+       fputc(height & 0xff, pcxfile); /* vres */
        fputc((height >> 8) & 0xff, pcxfile);
-       for (i = 0; i < 48; i++) // palette
+       for (i = 0; i < 48; i++) /* palette */
                fputc(0, pcxfile);
-       fputc(0, pcxfile); // reserved
-       fputc(1, pcxfile); // color_planes
-       fputc(width & 0xff, pcxfile); // bytes_per_line
+       fputc(0, pcxfile); /* reserved */
+       fputc(1, pcxfile); /* color_planes */
+       fputc(width & 0xff, pcxfile); /* bytes_per_line */
        fputc((width >> 8) & 0xff, pcxfile);
-       fputc(1 & 0xff, pcxfile); // palette_type
+       fputc(1 & 0xff, pcxfile); /* palette_type */
        fputc((1 >> 8) & 0xff, pcxfile);
-       for (i = 0; i < 58; i++) // filler
+       for (i = 0; i < 58; i++) /* filler */
                fputc(0, pcxfile);
 
-       // pack the image
+       /* pack the image */
 
        for (i = 0 ; i < width*height ; i++)
                if ( (*data & 0xc0) != 0xc0)
@@ -81,9 +81,9 @@ static void write_pcx(FILE *pcxfile, unsigned char *data, int width, int height,
                        fputc(*data++, pcxfile);
                }
 
-       // write the palette
+       /* write the palette */
 
-       fputc(0x0c, pcxfile); // palette ID byte
+       fputc(0x0c, pcxfile); /* palette ID byte */
        if (palette)
                for (i = 0 ; i < 768 ; i++)
                        fputc(*palette++, pcxfile);
@@ -318,8 +318,8 @@ int main(int argc, char **argv)
                fclose(f);
        } else {
                unsigned char *data;
-               int i;
-               int x_pos, y_pos;
+               int i = 0;
+               int x_pos = 0, y_pos = 0;
 
                data = malloc(400*256);
                if (!data) {
@@ -359,7 +359,7 @@ int main(int argc, char **argv)
                        char buffer[1024];
                        int value;
 
-                       fscanf(f, "%s %i\n", &buffer, &value);
+                       fscanf(f, "%s %i\n", buffer, &value);
                        if (strcmp(buffer, "num_images:") == 0) {
                                if (gob.num_images != 0) {
                                        printf("Parse error in %s\n", filename);
@@ -418,4 +418,4 @@ int main(int argc, char **argv)
        }
 
        return 0;
-}
\ No newline at end of file
+}
diff --git a/sdl/Makefile b/sdl/Makefile
new file mode 100644 (file)
index 0000000..9a7fc7c
--- /dev/null
@@ -0,0 +1,16 @@
+SDL_CFLAGS = `sdl-config --cflags`
+CFLAGS = -Wall -ansi -pedantic -O2 -ffast-math -funroll-loops \
+       -Dstricmp=strcasecmp -Dstrnicmp=strncasecmp -DNDEBUG \
+       -I. -I.. $(SDL_CFLAGS) -DUSE_SDL -DUSE_NET
+
+OBJS = gfx.o interrpt.o sound.o input.o
+TARGET = ../sdl.a
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+       ar cru $(TARGET) $(OBJS)
+       ranlib $(TARGET)
+
+clean:
+       rm -f $(TARGET) $(OBJS)
index 5f33b2e..6c4e0b0 100644 (file)
--- a/sdl/gfx.c
+++ b/sdl/gfx.c
@@ -28,7 +28,7 @@
  */
 
 #include "globals.h"
-#include <SDL_endian.h>
+#include "SDL_endian.h"
 
 #ifdef _MSC_VER
     #include "jumpnbump32.xpm"
@@ -132,10 +132,10 @@ static SDL_Surface *load_xpm_from_array(char **xpm)
                                SDL_FreeSurface(surface);
                                return NULL;
                        }
-                       r = (pal[*p] >> 16) & 0xff;
-                       b = (pal[*p] & 0xff);
-                       g = (pal[*p] >> 8) & 0xff;
-                       a = (pal[*p] >> 24) & 0xff;
+                       r = (pal[(int)*p] >> 16) & 0xff;
+                       b = (pal[(int)*p] & 0xff);
+                       g = (pal[(int)*p] >> 8) & 0xff;
+                       a = (pal[(int)*p] >> 24) & 0xff;
                        pixels[x] = SDL_MapRGBA(surface->format, r, g, b, a);
                        x++;
                        p++;
@@ -178,11 +178,7 @@ void open_screen(void)
        int bpp;
        int flags;
 
-#ifdef __APPLE__
-       lval = SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO);
-#else
-       lval = SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_AUDIO);
-#endif
+       lval = SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
        if (lval < 0) {
                fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
                exit(EXIT_FAILURE);
@@ -533,11 +529,16 @@ void Super2xSaI (unsigned char *src, unsigned int src_pitch, int src_bytes_per_p
                for (x = 0; x < width; x++) {
                        unsigned long product1a, product1b, product2a, product2b;
 
+/*
+
 //---------------------------------------  B0 B1 B2 B3    0  1  2  3
 //                                         4  5* 6  S2 -> 4  5* 6  7
 //                                         1  2  3  S1    8  9 10 11
 //                                         A0 A1 A2 A3   12 13 14 15
 //--------------------------------------
+
+*/
+
                        if (color[9] == color[6] && color[5] != color[10]) {
                                product2b = color[9];
                                product1b = product2b;
@@ -596,8 +597,6 @@ void Super2xSaI (unsigned char *src, unsigned int src_pitch, int src_bytes_per_p
        
                        if (dst_bytes_per_pixel == 2) {
                                unsigned long tmp;
-                               //*((unsigned long *) (&dst_line[0][x * 4])) = product1a | (product1b << 16);
-                               //*((unsigned long *) (&dst_line[1][x * 4])) = product2a | (product2b << 16);
                                tmp = SDL_SwapLE16(product1a) | SDL_SwapLE16(product1b) << 16;
                                *((unsigned long *) (&dst_line[0][x * 4])) = SDL_SwapLE32(tmp);
                                tmp = SDL_SwapLE16(product2a) | SDL_SwapLE16(product2b) << 16;
@@ -714,7 +713,6 @@ void flippage(int page)
        dest=(unsigned char *)jnb_surface->pixels;
        src=screen_buffer[page];
        for (y=0; y<screen_height; y++) {
-               //memset(&dest[y*jnb_surface->pitch],0,JNB_WIDTH*bytes_per_pixel);
                for (x=0; x<25; x++) {
                        int count;
                        int test_x;
@@ -729,7 +727,6 @@ void flippage(int page)
                                memcpy( &dest[y*jnb_surface->pitch+(x<<dirty_block_shift)*bytes_per_pixel],
                                        &src[y*screen_pitch+((x<<dirty_block_shift)*bytes_per_pixel)],
                                        ((16<<dirty_block_shift)>>4)*bytes_per_pixel*count);
-                               //*((pixel_t *)(&dest[(y>>dirty_block_shift)*jnb_surface->pitch+x*bytes_per_pixel]))=0xe0e0;
                        }
                        x = test_x;
                }
@@ -750,8 +747,6 @@ void draw_begin(void)
                if (background) {
                        put_block(0, 0, 0, JNB_WIDTH, JNB_HEIGHT, background);
                        put_block(1, 0, 0, JNB_WIDTH, JNB_HEIGHT, background);
-                       //put_block(0, 0, 0, rabbit_gobs.width[1], rabbit_gobs.height[1], rabbit_gobs.data[1]);
-                       //put_block(1, 0, 0, rabbit_gobs.width[1], rabbit_gobs.height[1], rabbit_gobs.data[1]);
                } else {
                        clear_page(0, 0);
                        clear_page(1, 0);
@@ -1239,7 +1234,7 @@ void register_background(char *pixels, char pal[768])
                background = malloc(screen_pitch*screen_height);
                assert(background);
                Init_2xSaI(565);
-               Super2xSaI(pixels, JNB_WIDTH, 1, (unsigned char *)background, screen_pitch, bytes_per_pixel, JNB_WIDTH, JNB_HEIGHT, int_pal);
+               Super2xSaI((unsigned char *)pixels, JNB_WIDTH, 1, (unsigned char *)background, screen_pitch, bytes_per_pixel, JNB_WIDTH, JNB_HEIGHT, int_pal);
        } else {
                background = malloc(JNB_WIDTH*JNB_HEIGHT);
                assert(background);
index ab2bce5..62e7f95 100644 (file)
 
 #include "globals.h"
 
+static int num_joys=0;
+static SDL_Joystick *joys[4];
+
+/* assumes joysticks have at least one button, could check numbuttons first? */
+#define JOY_LEFT(num) (num_joys>num && SDL_JoystickGetAxis(joys[num], 0)<-3200)
+#define JOY_RIGHT(num) (num_joys>num && SDL_JoystickGetAxis(joys[num], 0)>3200)
+/* I find using the vertical axis to be annoying -- dnb */
+#define JOY_JUMP(num) (num_joys>num && SDL_JoystickGetButton(joys[num], 0))
+
 int calib_joy(int type)
 {
        return 1;
@@ -39,53 +48,53 @@ void update_player_actions(void)
        int tmp;
 
        if (client_player_num < 0) {
-               tmp = (key_pressed(KEY_PL1_LEFT) == 1);
+               tmp = (key_pressed(KEY_PL1_LEFT) == 1) || JOY_LEFT(3);
                if (tmp != player[0].action_left)
                        tellServerPlayerMoved(0, MOVEMENT_LEFT, tmp);
-               tmp = (key_pressed(KEY_PL1_RIGHT) == 1);
+               tmp = (key_pressed(KEY_PL1_RIGHT) == 1) || JOY_RIGHT(3);
                if (tmp != player[0].action_right)
                        tellServerPlayerMoved(0, MOVEMENT_RIGHT, tmp);
-               tmp = (key_pressed(KEY_PL1_JUMP) == 1);
+               tmp = (key_pressed(KEY_PL1_JUMP) == 1) || JOY_JUMP(3);
                if (tmp != player[0].action_up)
                        tellServerPlayerMoved(0, MOVEMENT_UP, tmp);
 
-               tmp = (key_pressed(KEY_PL2_LEFT) == 1);
+               tmp = (key_pressed(KEY_PL2_LEFT) == 1) || JOY_LEFT(2);
                if (tmp != player[1].action_left)
                        tellServerPlayerMoved(1, MOVEMENT_LEFT, tmp);
-               tmp = (key_pressed(KEY_PL2_RIGHT) == 1);
+               tmp = (key_pressed(KEY_PL2_RIGHT) == 1) || JOY_RIGHT(2);
                if (tmp != player[1].action_right)
                        tellServerPlayerMoved(1, MOVEMENT_RIGHT, tmp);
-               tmp = (key_pressed(KEY_PL2_JUMP) == 1);
+               tmp = (key_pressed(KEY_PL2_JUMP) == 1) || JOY_JUMP(2);
                if (tmp != player[1].action_up)
                        tellServerPlayerMoved(1, MOVEMENT_UP, tmp);
 
-               tmp = (key_pressed(KEY_PL3_LEFT) == 1);
+               tmp = (key_pressed(KEY_PL3_LEFT) == 1) || JOY_LEFT(1);
                if (tmp != player[2].action_left)
                        tellServerPlayerMoved(2, MOVEMENT_LEFT, tmp);
-               tmp = (key_pressed(KEY_PL3_RIGHT) == 1);
+               tmp = (key_pressed(KEY_PL3_RIGHT) == 1) || JOY_RIGHT(1);
                if (tmp != player[2].action_right)
                        tellServerPlayerMoved(2, MOVEMENT_RIGHT, tmp);
-               tmp = (key_pressed(KEY_PL3_JUMP) == 1);
+               tmp = (key_pressed(KEY_PL3_JUMP) == 1) || JOY_JUMP(1);
                if (tmp != player[2].action_up)
                        tellServerPlayerMoved(2, MOVEMENT_UP, tmp);
 
-               tmp = (key_pressed(KEY_PL4_LEFT) == 1);
+               tmp = (key_pressed(KEY_PL4_LEFT) == 1) || JOY_LEFT(0);
                if (tmp != player[3].action_left)
                tellServerPlayerMoved(3, MOVEMENT_LEFT, tmp);
-               tmp = (key_pressed(KEY_PL4_RIGHT) == 1);
+               tmp = (key_pressed(KEY_PL4_RIGHT) == 1) || JOY_RIGHT(0);
                if (tmp != player[3].action_right)
                tellServerPlayerMoved(3, MOVEMENT_RIGHT, tmp);
-               tmp = (key_pressed(KEY_PL4_JUMP) == 1);
+               tmp = (key_pressed(KEY_PL4_JUMP) == 1) || JOY_JUMP(0);
                if (tmp != player[3].action_up)
                tellServerPlayerMoved(3, MOVEMENT_UP, tmp);
        } else {
-               tmp = (key_pressed(KEY_PL1_LEFT) == 1);
+               tmp = (key_pressed(KEY_PL1_LEFT) == 1) || JOY_LEFT(0);
                if (tmp != player[client_player_num].action_left)
                        tellServerPlayerMoved(client_player_num, MOVEMENT_LEFT, tmp);
-               tmp = (key_pressed(KEY_PL1_RIGHT) == 1);
+               tmp = (key_pressed(KEY_PL1_RIGHT) == 1) || JOY_RIGHT(0);
                if (tmp != player[client_player_num].action_right)
                        tellServerPlayerMoved(client_player_num, MOVEMENT_RIGHT, tmp);
-               tmp = (key_pressed(KEY_PL1_JUMP) == 1);
+               tmp = (key_pressed(KEY_PL1_JUMP) == 1) || JOY_JUMP(0);
                if (tmp != player[client_player_num].action_up)
                        tellServerPlayerMoved(client_player_num, MOVEMENT_UP, tmp);
        }
@@ -93,6 +102,12 @@ void update_player_actions(void)
 
 void init_inputs(void)
 {
+       int i;
+
+       num_joys = SDL_NumJoysticks();
+       for(i = 0; i < 4 && i < num_joys; ++i)
+               joys[i] = SDL_JoystickOpen(i);
+
        main_info.mouse_enabled = 0;
        main_info.joy_enabled = 0;
 }
index c021898..547437b 100644 (file)
 #include "globals.h"
 
 #ifdef USE_KAILLERA
-#include <SDL_thread.h>
-#include <SDL_mutex.h>
+#include "SDL_thread.h"
+#include "SDL_mutex.h"
 #include <kailleraclient.h>
 
 char local_keyb[256];
-#endif // USE_KAILLERA
+#endif /* USE_KAILLERA */
 
 char keyb[256];
 char last_keys[50];
@@ -268,7 +268,7 @@ int key_pressed(int key)
        return keyb[(unsigned char) key];
 }
 
-#else // USE_KAILLERA
+#else /* USE_KAILLERA */
 
 int addkey(unsigned int key)
 {
@@ -302,7 +302,7 @@ int key_pressed(int key)
 }
 
 
-#endif // USE_KAILLERA
+#endif /* USE_KAILLERA */
 
 int intr_sysupdate()
 {
@@ -381,7 +381,7 @@ int intr_sysupdate()
                update_kaillera_keys();
                i=1;
        }
-#endif // USE_KAILLERA
+#endif /* USE_KAILLERA */
 
        return i;
 }
index 7025c42..19cd97f 100644 (file)
@@ -44,28 +44,28 @@ static int SAMPLECOUNT = 512;
 #define MAX_CHANNELS   32
 
 typedef struct {
-       // loop flag
+       /* loop flag */
        int loop;
-       // The channel step amount...
+       /* The channel step amount... */
        unsigned int step;
-       // ... and a 0.16 bit remainder of last step.
+       /* ... and a 0.16 bit remainder of last step. */
        unsigned int stepremainder;
        unsigned int samplerate;
-       // The channel data pointers, start and end.
+       /* The channel data pointers, start and end. */
        signed short* data;
        signed short* startdata;
        signed short* enddata;
-       // Hardware left and right channel volume lookup.
+       /* Hardware left and right channel volume lookup. */
        int leftvol;
        int rightvol;
 } channel_info_t;
 
 channel_info_t channelinfo[MAX_CHANNELS];
 
-// Sample rate in samples/second
+/* Sample rate in samples/second */
 int audio_rate = 44100;
 int global_sfx_volume = 0;
-//
+/*
 // This function loops all active (internal) sound
 //  channels, retrieves a given number of samples
 //  from the raw sound data, modifies it according
@@ -75,7 +75,7 @@ int global_sfx_volume = 0;
 //  range.
 //
 // This function currently supports only 16bit.
-//
+*/
 
 static void stopchan(int i)
 {
@@ -85,19 +85,19 @@ static void stopchan(int i)
 }
 
 
-//
+/*
 // This function adds a sound to the
 //  list of currently active sounds,
 //  which is maintained as a given number
 //  (eight, usually) of internal channels.
 // Returns a handle.
-//
+*/
 int addsfx(signed short *data, int len, int loop, int samplerate, int channel)
 {
        stopchan(channel);
 
-       // We will handle the new SFX.
-       // Set pointer to raw data.
+       /* We will handle the new SFX. */
+       /* Set pointer to raw data. */
        channelinfo[channel].data = data;
        channelinfo[channel].startdata = data;
       
@@ -117,17 +117,19 @@ static void updateSoundParams(int slot, int volume)
        int rightvol;
        int leftvol;
 
+       /*
        // Set stepping
        // MWM 2000-12-24: Calculates proportion of channel samplerate
        // to global samplerate for mixing purposes.
        // Patched to shift left *then* divide, to minimize roundoff errors
        // as well as to use SAMPLERATE as defined above, not to assume 11025 Hz
+       */
        channelinfo[slot].step = ((channelinfo[slot].samplerate<<16)/audio_rate);
 
        leftvol = volume;
        rightvol= volume;  
 
-       // Sanity check, clamp volume.
+       /* Sanity check, clamp volume. */
        if (rightvol < 0)
                rightvol = 0;
        if (rightvol > 127)
@@ -145,69 +147,67 @@ static void updateSoundParams(int slot, int volume)
 
 void mix_sound(void *unused, Uint8 *stream, int len)
 {
-       // Mix current sound data.
-       // Data, from raw sound, for right and left.
+       /* Mix current sound data. */
+       /* Data, from raw sound, for right and left. */
        register int sample;
        register int    dl;
        register int    dr;
 
-       // Pointers in audio stream, left, right, end.
+       /* Pointers in audio stream, left, right, end. */
        signed short*   leftout;
        signed short*   rightout;
        signed short*   leftend;
-       // Step in stream, left and right, thus two.
+       /* Step in stream, left and right, thus two. */
        int       step;
 
-       // Mixing channel index.
+       /* Mixing channel index. */
        int       chan;
 
-       // Left and right channel
-       //  are in audio stream, alternating.
+       /* Left and right channel */
+       /*  are in audio stream, alternating. */
        leftout = (signed short *)stream;
        rightout = ((signed short *)stream)+1;
        step = 2;
 
-       // Determine end, for left channel only
-       //  (right channel is implicit).
+       /* Determine end, for left channel only */
+       /*  (right channel is implicit). */
        leftend = leftout + (len/4)*step;
 
-       // Mix sounds into the mixing buffer.
-       // Loop over step*SAMPLECOUNT,
-       //  that is 512 values for two channels.
+       /* Mix sounds into the mixing buffer. */
+       /* Loop over step*SAMPLECOUNT, */
+       /*  that is 512 values for two channels. */
        while (leftout != leftend) {
-               // Reset left/right value. 
-               //dl = 0;
-               //dr = 0;
+               /* Reset left/right value. */
                dl = *leftout * 256;
                dr = *rightout * 256;
 
-               // Love thy L2 chache - made this a loop.
-               // Now more channels could be set at compile time
-               //  as well. Thus loop those  channels.
+               /* Love thy L2 chache - made this a loop. */
+               /* Now more channels could be set at compile time */
+               /*  as well. Thus loop those  channels. */
                for ( chan = 0; chan < MAX_CHANNELS; chan++ ) {
-                       // Check channel, if active.
+                       /* Check channel, if active. */
                        if (channelinfo[chan].data) {
-                               // Get the raw data from the channel.
-                               // no filtering
-                               // sample = *channelinfo[chan].data;
-                               // linear filtering
+                               /* Get the raw data from the channel. */
+                               /* no filtering */
+                               /* sample = *channelinfo[chan].data; */
+                               /* linear filtering */
                                sample = (int)(((int)channelinfo[chan].data[0] * (int)(0x10000 - channelinfo[chan].stepremainder))
                                        + ((int)channelinfo[chan].data[1] * (int)(channelinfo[chan].stepremainder))) >> 16;
 
-                               // Add left and right part
-                               //  for this channel (sound)
-                               //  to the current data.
-                               // Adjust volume accordingly.
+                               /* Add left and right part */
+                               /*  for this channel (sound) */
+                               /*  to the current data. */
+                               /* Adjust volume accordingly. */
                                dl += sample * (channelinfo[chan].leftvol * global_sfx_volume) / 128;
                                dr += sample * (channelinfo[chan].rightvol * global_sfx_volume) / 128;
-                               // Increment index ???
+                               /* Increment index ??? */
                                channelinfo[chan].stepremainder += channelinfo[chan].step;
-                               // MSB is next sample???
+                               /* MSB is next sample??? */
                                channelinfo[chan].data += channelinfo[chan].stepremainder >> 16;
-                               // Limit to LSB???
+                               /* Limit to LSB??? */
                                channelinfo[chan].stepremainder &= 0xffff;
 
-                               // Check whether we are done.
+                               /* Check whether we are done. */
                                if (channelinfo[chan].data >= channelinfo[chan].enddata)
                                        if (channelinfo[chan].loop) {
                                                channelinfo[chan].data = channelinfo[chan].startdata;
@@ -217,11 +217,11 @@ void mix_sound(void *unused, Uint8 *stream, int len)
                        }
                }
   
-               // Clamp to range. Left hardware channel.
-               // Has been char instead of short.
-               // if (dl > 127) *leftout = 127;
-               // else if (dl < -128) *leftout = -128;
-               // else *leftout = dl;
+               /* Clamp to range. Left hardware channel. */
+               /* Has been char instead of short. */
+               /* if (dl > 127) *leftout = 127; */
+               /* else if (dl < -128) *leftout = -128; */
+               /* else *leftout = dl; */
 
                dl = dl / 256;
                dr = dr / 256;
@@ -233,7 +233,7 @@ void mix_sound(void *unused, Uint8 *stream, int len)
                else
                        *leftout = (signed short)dl;
 
-               // Same for right hardware channel.
+               /* Same for right hardware channel. */
                if (dr > SHRT_MAX)
                        *rightout = SHRT_MAX;
                else if (dr < SHRT_MIN)
@@ -241,7 +241,7 @@ void mix_sound(void *unused, Uint8 *stream, int len)
                else
                        *rightout = (signed short)dr;
 
-               // Increment current pointers in stream
+               /* Increment current pointers in stream */
                leftout += step;
                rightout += step;
        }