# HG changeset patch # User John Tsiombikas # Date 1379911265 -10800 # Node ID 1870c4ef8b76c30992a34d2f2351f634ce586a19 # Parent c6406e4aa0fb09cf97f29a9e4060306af9b17fca added visual studio project moved the dosemu directory diff -r c6406e4aa0fb -r 1870c4ef8b76 .hgignore --- a/.hgignore Mon Sep 23 05:58:24 2013 +0300 +++ b/.hgignore Mon Sep 23 07:41:05 2013 +0300 @@ -7,3 +7,10 @@ \.exe$ \.EXE$ ^OBJECTS.LNK$ +\.suo$ +\.ncb$ +\.user$ +\.dll$ +Debug/ +Release/ +dosbox/ diff -r c6406e4aa0fb -r 1870c4ef8b76 GNUmakefile --- a/GNUmakefile Mon Sep 23 05:58:24 2013 +0300 +++ b/GNUmakefile Mon Sep 23 07:41:05 2013 +0300 @@ -2,13 +2,18 @@ src/mingl.o src/mglrast.o src/mglclip.o src/mglgen.o \ src/texture.o src/palman.o \ src/scene.o src/cvec.o src/fixedp.o \ - dosemu/dosemu.o + src/dosemu/dosemu.o dep = $(obj:.o=.d) bin = deepstone +dbg = -g +#opt = -O3 -ffast-math + CC = gcc -CFLAGS = -pedantic -Wall -g `pkg-config --cflags sdl` -Isrc -Idosemu $(add_cflags) -DRAST_FLOAT -DDBG_USE_FLOAT +CFLAGS = -pedantic -Wall $(dbg) $(opt) `pkg-config --cflags sdl` -Isrc -Idosemu $(add_cflags) -DRAST_FLOAT -DDBG_USE_FLOAT LDFLAGS = `pkg-config --libs sdl` -lm +#LDFLAGS = -Llib64 -Wl,-rpath=./lib64 -lSDL -lm +#LDFLAGS = -m32 -Llib32 -Wl,-rpath=./lib32 -lSDL-1.2 -lm ifeq ($(shell uname -s), Darwin) add_cflags = -Dmain=SDL_main diff -r c6406e4aa0fb -r 1870c4ef8b76 README --- a/README Mon Sep 23 05:58:24 2013 +0300 +++ b/README Mon Sep 23 07:41:05 2013 +0300 @@ -1,17 +1,62 @@ -A short trip back in time in the days of 16bit graphics programming for MS-DOS -in VGA mode 13h. +Deepstone (unfinished) +---------------------- +This would/will be a dungeon crawler if I ever finish it. -Copyright (C) 2011 John Tsiombikas +Copyright (C) 2013 John Tsiombikas Feel free to use, modify and redistribute this code under the terms of the GNU General Public License version 3 (or at your option any later version published by the free software foundation). See COPYING for details. -interesting source code files: -- mingl.c: quick & dirty 256-color renderer with a vaguely GL-like interface. -- vga.c: denthoresque vga mode 13h driver. -- timer.c: DOS timer and 8254 code. +Usage +----- +Just start it, walk around with WASD and look around by moving the mouse. +Nothing else to do at the moment :) -To compile this you need Borland C, any version should do. Just type make. +Precompiled binaries included in the archive: + * deepston.exe MS-DOS version (32bit, requires included dos4gw.exe) + * deepstone-win32.exe 32bit Windows version + * deepstone-linux32 32bit GNU/Linux version + * deepstone-linux64 64bit GNU/Linux version -Special thanks to the vim project for providing a DOS version of vim, without it -this would be much less enjoyable. +The GNU/Linux binaries require libSDL which depends on a shitload of libraries +on my system, so you probably won't be able to run it without first installing +all the dependencies. It might be easier to just compile it yourself, just type +make and run ./deepstone + +Running with DOSBOX +------------------- +I've included a dosbox.conf which automatically runs the "game", as well as a +copy of dosbox.exe for windows. So just change into the dosbox/ subdirectory and +run dosbox. +NOTE: you might need to click in the dosbox window first before you can use +mouse control. + +Running on actual MS-DOS +------------------------ +Just copy deepston.exe, dos4gw.exe and the data directory to your DOS machine, +and run it. The mouse driver must be installed first! (mouse.com or whatever). + +Build on MS-DOS +--------------- + * You need the Watcom 32bit compiler and assorted utilities. + * Type make + * Profit (run deepston.exe) + +Build on GNU/Linux +------------------ + * Install SDL (libsdl-1.2-dev or whatever). + * Type make + * Profit (run ./deepstone) + +Build on MS-Windows +------------------- + * Install SDL + * Open deepstone.sln with visual studio >= 2008 + * Make sure visual studio knows where to find your copy of SDL (so configure + include and library paths... ugh, windows programming.. icky). + * Press build solution or whatever it's called this way. + * Profit (find the bloody thing and run it, or click the happy little play button). + +Contact +------- +Feel free to tell me how much I rule, by sending email to nuclear@member.fsf.org diff -r c6406e4aa0fb -r 1870c4ef8b76 deepstone.sln --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/deepstone.sln Mon Sep 23 07:41:05 2013 +0300 @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "deepstone", "deepstone.vcproj", "{7CBC96FF-B324-4904-9FD5-A95075F292BB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7CBC96FF-B324-4904-9FD5-A95075F292BB}.Debug|Win32.ActiveCfg = Debug|Win32 + {7CBC96FF-B324-4904-9FD5-A95075F292BB}.Debug|Win32.Build.0 = Debug|Win32 + {7CBC96FF-B324-4904-9FD5-A95075F292BB}.Release|Win32.ActiveCfg = Release|Win32 + {7CBC96FF-B324-4904-9FD5-A95075F292BB}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff -r c6406e4aa0fb -r 1870c4ef8b76 deepstone.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/deepstone.vcproj Mon Sep 23 07:41:05 2013 +0300 @@ -0,0 +1,291 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r c6406e4aa0fb -r 1870c4ef8b76 dosemu/conio.h --- a/dosemu/conio.h Mon Sep 23 05:58:24 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#ifndef CONIO_H_ -#define CONIO_H_ - -int kbhit(void); -int getch(void); - -#endif /* CONIO_H_ */ diff -r c6406e4aa0fb -r 1870c4ef8b76 dosemu/dosemu.c --- a/dosemu/dosemu.c Mon Sep 23 05:58:24 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,336 +0,0 @@ -/* This file implements all calls made to dos-specific code using SDL - * Don't ask why ... - */ - -#include -#include -#include -#include "wvga.h" -#include "conio.h" -#include "mouse.h" -#include "keyb.h" -#include "timer.h" - -static void proc_events(void); - -static void init_sdl() -{ - if(!SDL_WasInit(SDL_INIT_EVERYTHING)) { - SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); - } -} - -/* ----- graphics (wvga.c implementation) ----- */ -static SDL_Surface *fbsurf; -static int scale = 1; - -int set_video_mode(int mode) -{ - int resx = 320, resy = 200; - unsigned int sdl_flags = SDL_HWPALETTE; - char *env; - - if(getenv("DOSEMU_DOUBLESIZE")) { - scale = 2; - } - - if((env = getenv("DOSEMU_SCALE"))) { - int n = atoi(env); - if(n > 0) { - scale = n; - } - } - resx *= scale; - resy *= scale; - - if(getenv("DOSEMU_FULLSCREEN")) { - sdl_flags |= SDL_FULLSCREEN; - } - - init_sdl(); - - switch(mode) { - case 0x13: - if(!(fbsurf = SDL_SetVideoMode(resx, resy, 8, sdl_flags))) { - fprintf(stderr, "failed to set video mode\n"); - abort(); - } - SDL_WM_SetCaption("Deepstone", 0); - /*SDL_ShowCursor(0);*/ - /*SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);*/ - break; - - case 3: - SDL_ShowCursor(1); - SDL_EnableKeyRepeat(0, 0); - SDL_Quit(); - break; - - default: - break; - } - - return 0; -} - -void set_palette(int idx, int *col, int count) -{ - int i; - - for(i=0; i 1) { - int i, j, xsz, ysz; - unsigned char *dest = fbsurf->pixels; - - xsz = 320 * scale; - ysz = 200 * scale; - - for(i=0; ipixels, frame, 64000); - } - - if(SDL_MUSTLOCK(fbsurf)) { - SDL_UnlockSurface(fbsurf); - } - SDL_Flip(fbsurf); - - - /* also print fps every second ... */ - { - static long prev_fps, num_frames; - long msec, dt; - - msec = get_msec(); - dt = msec - prev_fps; - if(dt >= 1000) { - float fps = (float)num_frames / ((float)dt / 1000.0f); - printf("framerate: %.1f \r", fps); - fflush(stdout); - num_frames = 0; - prev_fps = msec; - } else { - num_frames++; - } - } -} - -void wait_vsync(void) -{ -} - -/* ----- event handling (conio.h) ----- */ -static SDL_Event *keybev; -static int mousex, mousey, bnmask; - -static int keystate[256]; -static int num_pressed; - -int kbhit(void) -{ - if(!keybev) { - proc_events(); - } - return keybev != 0; -} - -int getch(void) -{ - int res; - - while(!keybev) { - SDL_Event ev; - SDL_WaitEvent(&ev); - SDL_PushEvent(&ev); - proc_events(); - } - res = keybev->key.keysym.sym; - keybev = 0; - return res; -} - -/* ----- improved event handling (keyb.h) ---- */ - -int kb_init(int bufsz) -{ - init_sdl(); - - return 0; -} - -void kb_shutdown(void) -{ -} - -int kb_getkey(void) -{ - int res = -1; - - proc_events(); - if(keybev) { - res = keybev->key.keysym.sym; - keybev = 0; - } - return res; -} - -int kb_isdown(int key) -{ - if(key == KB_ANY) { - return num_pressed; - } - return keystate[key]; -} - -/* mouse handling (mouse.c implementation) */ -static unsigned long last_mouse_hide_time; - -int have_mouse(void) -{ - return 1; -} - -void set_mouse(int x, int y) -{ - SDL_ShowCursor(0); - last_mouse_hide_time = get_msec(); - - SDL_WarpMouse(x * scale, y * scale); - mousex = x; - mousey = y; -} - -int read_mouse(int *xp, int *yp) -{ - if(xp) *xp = mousex; - if(yp) *yp = mousey; - return bnmask; -} - -static void proc_events(void) -{ - static SDL_Event ev; - - if(last_mouse_hide_time > 0 && get_msec() - last_mouse_hide_time > 3000) { - last_mouse_hide_time = 0; - SDL_ShowCursor(1); - } - - while(SDL_PollEvent(&ev)) { - switch(ev.type) { - case SDL_KEYDOWN: - { - int key = ev.key.keysym.sym; - - if(!keybev) { - keybev = &ev; - } - - if(!keystate[key]) { - keystate[key] = 1; - num_pressed++; - } - } - break; - - case SDL_KEYUP: - { - int key = ev.key.keysym.sym; - - if(keystate[key]) { - keystate[key] = 0; - if(--num_pressed < 0) { - num_pressed = 0; - } - } - } - break; - - case SDL_MOUSEMOTION: - mousex = ev.motion.x / scale; - mousey = ev.motion.y / scale; - break; - - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - { - int mask = 0; - switch(ev.button.button) { - case SDL_BUTTON_LEFT: - mask = MOUSE_LEFT; - break; - case SDL_BUTTON_MIDDLE: - mask = MOUSE_MIDDLE; - break; - case SDL_BUTTON_RIGHT: - mask = MOUSE_RIGHT; - default: - break; - } - if(!mask) { - break; - } - - if(ev.button.state == SDL_PRESSED) { - bnmask |= mask; - } else { - bnmask &= ~mask; - } - } - break; - - default: - break; - } - } -} - -/* ---- timer.c implementation ---- */ -static Uint32 start_time; - -void init_timer(int res_hz) -{ - init_sdl(); - reset_timer(); -} - -void reset_timer(void) -{ - start_time = SDL_GetTicks(); - printf("resetting timer: %u, %lu\n", start_time, get_msec()); -} - -unsigned long get_msec(void) -{ - Uint32 ticks = SDL_GetTicks(); - return (unsigned long)(ticks - start_time); -} diff -r c6406e4aa0fb -r 1870c4ef8b76 src/dosemu/conio.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dosemu/conio.h Mon Sep 23 07:41:05 2013 +0300 @@ -0,0 +1,7 @@ +#ifndef CONIO_H_ +#define CONIO_H_ + +int kbhit(void); +int getch(void); + +#endif /* CONIO_H_ */ diff -r c6406e4aa0fb -r 1870c4ef8b76 src/dosemu/dosemu.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dosemu/dosemu.c Mon Sep 23 07:41:05 2013 +0300 @@ -0,0 +1,342 @@ +/* This file implements all calls made to dos-specific code using SDL + * Don't ask why ... + */ + +#include +#include +#include +#include "wvga.h" +#include "conio.h" +#include "mouse.h" +#include "keyb.h" +#include "timer.h" + +static void proc_events(void); + +static void init_sdl() +{ + const SDL_version *ver; + + if(!SDL_WasInit(SDL_INIT_EVERYTHING)) { + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); + + if((ver = SDL_Linked_Version())) { + printf("SDL %d.%d.%d initialized\n", ver->major, ver->minor, ver->patch); + } + } +} + +/* ----- graphics (wvga.c implementation) ----- */ +static SDL_Surface *fbsurf; +static int scale = 3; + +int set_video_mode(int mode) +{ + int resx = 320, resy = 200; + unsigned int sdl_flags = SDL_HWPALETTE; + char *env; + + if(getenv("DOSEMU_DOUBLESIZE")) { + scale = 2; + } + + if((env = getenv("DOSEMU_SCALE"))) { + int n = atoi(env); + if(n > 0) { + scale = n; + } + } + resx *= scale; + resy *= scale; + + if(getenv("DOSEMU_FULLSCREEN")) { + sdl_flags |= SDL_FULLSCREEN; + } + + init_sdl(); + + switch(mode) { + case 0x13: + if(!(fbsurf = SDL_SetVideoMode(resx, resy, 8, sdl_flags))) { + fprintf(stderr, "failed to set video mode\n"); + abort(); + } + SDL_WM_SetCaption("Deepstone", 0); + /*SDL_ShowCursor(0);*/ + /*SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);*/ + break; + + case 3: + SDL_ShowCursor(1); + SDL_EnableKeyRepeat(0, 0); + SDL_Quit(); + break; + + default: + break; + } + + return 0; +} + +void set_palette(int idx, int *col, int count) +{ + int i; + + for(i=0; i 1) { + int i, j, xsz, ysz; + unsigned char *dest = fbsurf->pixels; + + xsz = 320 * scale; + ysz = 200 * scale; + + for(i=0; ipixels, frame, 64000); + } + + if(SDL_MUSTLOCK(fbsurf)) { + SDL_UnlockSurface(fbsurf); + } + SDL_Flip(fbsurf); + + + /* also print fps every second ... */ + { + static long prev_fps, num_frames; + long msec, dt; + + msec = get_msec(); + dt = msec - prev_fps; + if(dt >= 1000) { + float fps = (float)num_frames / ((float)dt / 1000.0f); + printf("framerate: %.1f \r", fps); + fflush(stdout); + num_frames = 0; + prev_fps = msec; + } else { + num_frames++; + } + } +} + +void wait_vsync(void) +{ +} + +/* ----- event handling (conio.h) ----- */ +static SDL_Event *keybev; +static int mousex, mousey, bnmask; + +static int keystate[256]; +static int num_pressed; + +int kbhit(void) +{ + if(!keybev) { + proc_events(); + } + return keybev != 0; +} + +int getch(void) +{ + int res; + + while(!keybev) { + SDL_Event ev; + SDL_WaitEvent(&ev); + SDL_PushEvent(&ev); + proc_events(); + } + res = keybev->key.keysym.sym; + keybev = 0; + return res; +} + +/* ----- improved event handling (keyb.h) ---- */ + +int kb_init(int bufsz) +{ + init_sdl(); + + return 0; +} + +void kb_shutdown(void) +{ +} + +int kb_getkey(void) +{ + int res = -1; + + proc_events(); + if(keybev) { + res = keybev->key.keysym.sym; + keybev = 0; + } + return res; +} + +int kb_isdown(int key) +{ + if(key == KB_ANY) { + return num_pressed; + } + return keystate[key]; +} + +/* mouse handling (mouse.c implementation) */ +static unsigned long last_mouse_hide_time; + +int have_mouse(void) +{ + return 1; +} + +void set_mouse(int x, int y) +{ + /*SDL_ShowCursor(0); + last_mouse_hide_time = get_msec();*/ + + SDL_WarpMouse(x * scale, y * scale); + mousex = x; + mousey = y; +} + +int read_mouse(int *xp, int *yp) +{ + if(xp) *xp = mousex; + if(yp) *yp = mousey; + return bnmask; +} + +static void proc_events(void) +{ + static SDL_Event ev; + + if(last_mouse_hide_time > 0 && get_msec() - last_mouse_hide_time > 3000) { + last_mouse_hide_time = 0; + SDL_ShowCursor(1); + } + + while(SDL_PollEvent(&ev)) { + switch(ev.type) { + case SDL_KEYDOWN: + { + int key = ev.key.keysym.sym; + + if(!keybev) { + keybev = &ev; + } + + if(!keystate[key]) { + keystate[key] = 1; + num_pressed++; + } + } + break; + + case SDL_KEYUP: + { + int key = ev.key.keysym.sym; + + if(keystate[key]) { + keystate[key] = 0; + if(--num_pressed < 0) { + num_pressed = 0; + } + } + } + break; + + case SDL_MOUSEMOTION: + mousex = ev.motion.x / scale; + mousey = ev.motion.y / scale; + break; + + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + { + int mask = 0; + switch(ev.button.button) { + case SDL_BUTTON_LEFT: + mask = MOUSE_LEFT; + break; + case SDL_BUTTON_MIDDLE: + mask = MOUSE_MIDDLE; + break; + case SDL_BUTTON_RIGHT: + mask = MOUSE_RIGHT; + default: + break; + } + if(!mask) { + break; + } + + if(ev.button.state == SDL_PRESSED) { + bnmask |= mask; + } else { + bnmask &= ~mask; + } + } + break; + + default: + break; + } + } +} + +/* ---- timer.c implementation ---- */ +static Uint32 start_time; + +void init_timer(int res_hz) +{ + init_sdl(); + reset_timer(); +} + +void reset_timer(void) +{ + start_time = SDL_GetTicks(); + printf("resetting timer: %u, %lu\n", start_time, get_msec()); +} + +unsigned long get_msec(void) +{ + Uint32 ticks = SDL_GetTicks(); + return (unsigned long)(ticks - start_time); +} diff -r c6406e4aa0fb -r 1870c4ef8b76 src/inttypes.h --- a/src/inttypes.h Mon Sep 23 05:58:24 2013 +0300 +++ b/src/inttypes.h Mon Sep 23 07:41:05 2013 +0300 @@ -1,7 +1,7 @@ #ifndef INT_TYPES_H_ #define INT_TYPES_H_ -#ifdef __DOS__ +#if defined(__DOS__) || defined(WIN32) typedef char int8_t; typedef short int16_t; typedef long int32_t; diff -r c6406e4aa0fb -r 1870c4ef8b76 src/palman.c --- a/src/palman.c Mon Sep 23 05:58:24 2013 +0300 +++ b/src/palman.c Mon Sep 23 07:41:05 2013 +0300 @@ -48,7 +48,7 @@ { int i; - for(i=0; i