다마고치 연구소 한국어판 소스 공개
This commit is contained in:
commit
db23855630
661 files changed
+503597
No files matched your search
@@ -0,0 +1,99 @@
|
||||
/* generated by gen/font.py: custom 5x7 font */
|
||||
static const unsigned char g_font[96][7]={
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x04,0x04,0x04,0x04,0x04,0x00,0x04},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x19,0x19,0x02,0x04,0x08,0x13,0x13},
|
||||
{0x0c,0x12,0x14,0x08,0x15,0x12,0x0d},
|
||||
{0x04,0x04,0x08,0x00,0x00,0x00,0x00},
|
||||
{0x02,0x04,0x08,0x08,0x08,0x04,0x02},
|
||||
{0x08,0x04,0x02,0x02,0x02,0x04,0x08},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x04,0x04,0x1f,0x04,0x04,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x0c,0x04,0x08},
|
||||
{0x00,0x00,0x00,0x1f,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x0c,0x0c},
|
||||
{0x01,0x01,0x02,0x04,0x08,0x10,0x10},
|
||||
{0x0e,0x11,0x13,0x15,0x19,0x11,0x0e},
|
||||
{0x04,0x0c,0x04,0x04,0x04,0x04,0x0e},
|
||||
{0x0e,0x11,0x01,0x02,0x04,0x08,0x1f},
|
||||
{0x1e,0x01,0x01,0x0e,0x01,0x01,0x1e},
|
||||
{0x02,0x06,0x0a,0x12,0x1f,0x02,0x02},
|
||||
{0x1f,0x10,0x1e,0x01,0x01,0x11,0x0e},
|
||||
{0x0e,0x10,0x10,0x1e,0x11,0x11,0x0e},
|
||||
{0x1f,0x01,0x02,0x04,0x08,0x08,0x08},
|
||||
{0x0e,0x11,0x11,0x0e,0x11,0x11,0x0e},
|
||||
{0x0e,0x11,0x11,0x0f,0x01,0x01,0x0e},
|
||||
{0x00,0x04,0x04,0x00,0x04,0x04,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x02,0x04,0x08,0x10,0x08,0x04,0x02},
|
||||
{0x00,0x00,0x1f,0x00,0x1f,0x00,0x00},
|
||||
{0x08,0x04,0x02,0x01,0x02,0x04,0x08},
|
||||
{0x0e,0x11,0x01,0x02,0x04,0x00,0x04},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x0e,0x11,0x11,0x1f,0x11,0x11,0x11},
|
||||
{0x1e,0x11,0x11,0x1e,0x11,0x11,0x1e},
|
||||
{0x0e,0x11,0x10,0x10,0x10,0x11,0x0e},
|
||||
{0x1e,0x11,0x11,0x11,0x11,0x11,0x1e},
|
||||
{0x1f,0x10,0x10,0x1e,0x10,0x10,0x1f},
|
||||
{0x1f,0x10,0x10,0x1e,0x10,0x10,0x10},
|
||||
{0x0e,0x11,0x10,0x17,0x11,0x11,0x0f},
|
||||
{0x11,0x11,0x11,0x1f,0x11,0x11,0x11},
|
||||
{0x0e,0x04,0x04,0x04,0x04,0x04,0x0e},
|
||||
{0x07,0x02,0x02,0x02,0x02,0x12,0x0c},
|
||||
{0x11,0x12,0x14,0x18,0x14,0x12,0x11},
|
||||
{0x10,0x10,0x10,0x10,0x10,0x10,0x1f},
|
||||
{0x11,0x1b,0x15,0x15,0x11,0x11,0x11},
|
||||
{0x11,0x19,0x15,0x13,0x11,0x11,0x11},
|
||||
{0x0e,0x11,0x11,0x11,0x11,0x11,0x0e},
|
||||
{0x1e,0x11,0x11,0x1e,0x10,0x10,0x10},
|
||||
{0x0e,0x11,0x11,0x11,0x15,0x12,0x0d},
|
||||
{0x1e,0x11,0x11,0x1e,0x14,0x12,0x11},
|
||||
{0x0f,0x10,0x10,0x0e,0x01,0x01,0x1e},
|
||||
{0x1f,0x04,0x04,0x04,0x04,0x04,0x04},
|
||||
{0x11,0x11,0x11,0x11,0x11,0x11,0x0e},
|
||||
{0x11,0x11,0x11,0x11,0x11,0x0a,0x04},
|
||||
{0x11,0x11,0x11,0x15,0x15,0x15,0x0a},
|
||||
{0x11,0x11,0x0a,0x04,0x0a,0x11,0x11},
|
||||
{0x11,0x11,0x0a,0x04,0x04,0x04,0x04},
|
||||
{0x1f,0x01,0x02,0x04,0x08,0x10,0x1f},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x11,0x0a,0x04,0x0a,0x11},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0x11,0x0e,0x11,0x1f,0x11,0x11,0x11},
|
||||
{0x11,0x0e,0x11,0x11,0x11,0x11,0x0e},
|
||||
{0x11,0x00,0x11,0x11,0x11,0x11,0x0e},
|
||||
};
|
||||
@@ -0,0 +1,205 @@
|
||||
/* Paramix: what the Wolfenstein 3D core (Wolf4SDL) needs from its id_* layers, for a 128 x 128 screen with
|
||||
* three keys and a wheel. Replaces id_pm.h, id_sd.h, id_in.h, id_vl.h, id_vh.h, id_us.h, id_ca.h, wl_menu.h.
|
||||
* Implemented in pmx_*.c. Author: mameise. GPL-2.0-or-later like Wolf4SDL. */
|
||||
#ifndef PMX_H
|
||||
#define PMX_H
|
||||
|
||||
/* ---- SDL bits the core uses ---- */
|
||||
typedef struct { uint8_t r, g, b, a; } SDL_Color;
|
||||
typedef struct { byte *pixels; } SDL_Surface;
|
||||
#define SDL_ALPHA_OPAQUE 255
|
||||
uint32_t SDL_GetTicks (void);
|
||||
void SDL_Delay (uint32_t ms);
|
||||
static inline void SDL_GetRelativeMouseState (int *x, int *y) { *x = 0; *y = 0; }
|
||||
|
||||
/* ---- id_pm ---- */
|
||||
#define PMPageSize (TEXTURESIZE * TEXTURESIZE)
|
||||
#define PM_GetSpritePage(v) PM_GetPage (PMSpriteStart + (v))
|
||||
extern word ChunksInFile, PMSpriteStart, PMSoundStart;
|
||||
void PM_Startup (void);
|
||||
uint32_t PM_GetPageSize (int page);
|
||||
byte *PM_GetPage (int page);
|
||||
|
||||
/* ---- id_ca ---- */
|
||||
#define NUMMAPS 60
|
||||
#define MAPPLANES 2
|
||||
typedef struct
|
||||
{
|
||||
int32_t planestart[3];
|
||||
word planelength[3];
|
||||
word width,height;
|
||||
char name[16];
|
||||
} maptype;
|
||||
extern word *mapsegs[MAPPLANES];
|
||||
extern maptype *mapheaderseg[NUMMAPS];
|
||||
void CA_Startup (void);
|
||||
void CA_CacheMap (int mapnum);
|
||||
#define CA_CacheAudioChunk(c) (0)
|
||||
#define CA_LoadAllSounds()
|
||||
#define UNCACHEAUDIOCHUNK(c)
|
||||
#define UNCACHEGRCHUNK(c)
|
||||
#define CA_CacheGrChunk(c)
|
||||
|
||||
/* ---- id_sd ---- */
|
||||
#define TickBase 70
|
||||
enum SDMode { sdm_Off, sdm_PC, sdm_AdLib };
|
||||
enum SMMode { smm_Off, smm_AdLib };
|
||||
enum SDSMode { sds_Off, sds_PC, sds_SoundBlaster };
|
||||
typedef struct { longword length; word priority; } SoundCommon;
|
||||
typedef struct { int valid; fixed globalsoundx, globalsoundy; } globalsoundpos;
|
||||
extern globalsoundpos channelSoundPos[];
|
||||
extern boolean AdLibPresent, SoundBlasterPresent, SoundPositioned;
|
||||
extern byte SoundMode, DigiMode, MusicMode;
|
||||
#define GetTimeCount() ((SDL_GetTicks()*7)/100)
|
||||
void Delay (int32_t wolfticks);
|
||||
void SD_Startup (void);
|
||||
boolean SD_PlaySound (int sound);
|
||||
void SD_StopSound (void);
|
||||
void SD_WaitSoundDone (void);
|
||||
word SD_SoundPlaying (void);
|
||||
void SD_PositionSound (int leftvol, int rightvol);
|
||||
void SD_SetPosition (int channel, int leftvol, int rightvol);
|
||||
#define SD_StartMusic(c)
|
||||
#define SD_ContinueMusic(c, o)
|
||||
#define SD_MusicOn()
|
||||
#define SD_MusicOff() (0)
|
||||
#define SD_FadeOutMusic()
|
||||
#define SD_MusicPlaying() (false)
|
||||
#define SD_PrepareSound(w)
|
||||
#define SD_GetChannelForDigi(w) (0)
|
||||
|
||||
/* ---- id_in ---- */
|
||||
#define sc_None 0
|
||||
#define sc_Last 64
|
||||
typedef int32_t ScanCode;
|
||||
/* the keys the core asks for (Keyboard[]); set by pmx_in.c from the Paradise's keys */
|
||||
enum { sc_Return = 1, sc_Escape, sc_Space, sc_BackSpace, sc_Tab, sc_Alt, sc_Control, sc_LShift, sc_RShift,
|
||||
sc_UpArrow, sc_DownArrow, sc_LeftArrow, sc_RightArrow, sc_Y, sc_N, sc_Pause,
|
||||
sc_1, sc_2, sc_3, sc_4, sc_5, sc_6, sc_7, sc_8, sc_9, sc_0,
|
||||
sc_F1, sc_F2, sc_F3, sc_F4, sc_F5, sc_F6, sc_F7, sc_F8, sc_F9, sc_F10, sc_F11, sc_F12,
|
||||
sc_A, sc_B, sc_C, sc_D, sc_E, sc_G, sc_H, sc_I, sc_J, sc_K, sc_L, sc_M, sc_O, sc_P, sc_Q, sc_R, sc_S, sc_T,
|
||||
sc_U, sc_V, sc_W, sc_X, sc_Z, sc_Enter2 };
|
||||
#define sc_LAlt sc_Alt
|
||||
#define sc_RAlt sc_Alt
|
||||
#define sc_LControl sc_Control
|
||||
#define sc_RControl sc_Control
|
||||
#define sc_Enter sc_Return
|
||||
#define key_None sc_None
|
||||
enum Direction { dir_North, dir_NorthEast, dir_East, dir_SouthEast, dir_South, dir_SouthWest, dir_West, dir_NorthWest, dir_None };
|
||||
typedef struct
|
||||
{
|
||||
boolean button0,button1,button2,button3;
|
||||
int16_t x,y;
|
||||
int16_t xaxis,yaxis;
|
||||
byte dir;
|
||||
} ControlInfo;
|
||||
extern bool Keyboard[sc_Last];
|
||||
extern boolean MousePresent, Paused;
|
||||
extern ScanCode LastScan;
|
||||
#define IN_ClearKey(code) { Keyboard[code] = false; if (code == LastScan) LastScan = sc_None; }
|
||||
void IN_ClearKeysDown (void);
|
||||
void IN_Ack (void);
|
||||
boolean IN_UserInput (longword delay);
|
||||
void IN_ProcessEvents (void);
|
||||
static inline int IN_MouseButtons (void) { return 0; }
|
||||
static inline int IN_JoyButtons (void) { return 0; }
|
||||
static inline void IN_GetJoyDelta (int *dx, int *dy) { *dx = 0; *dy = 0; }
|
||||
static inline void IN_GetJoyFineDelta (int *dx, int *dy) { *dx = 0; *dy = 0; }
|
||||
static inline void IN_CenterMouse (void) {}
|
||||
void IN_StartAck (void);
|
||||
boolean IN_CheckAck (void);
|
||||
|
||||
/* ---- id_vl / id_vh ---- */
|
||||
extern SDL_Surface *screenBuffer;
|
||||
extern int16_t screenWidth, screenHeight;
|
||||
extern unsigned screenPitch, bufferPitch;
|
||||
extern int scaleFactor;
|
||||
extern boolean screenfaded;
|
||||
extern unsigned bordercolor;
|
||||
extern uint32_t *ylookup;
|
||||
extern SDL_Color gamepal[256];
|
||||
#define WHITE 15
|
||||
#define BLACK 0
|
||||
#define VL_WaitVBL(a) SDL_Delay((a)*8)
|
||||
void VL_SetPalette (SDL_Color *palette, bool forceupdate);
|
||||
void VL_FadeOut (int start, int end, int red, int green, int blue, int steps);
|
||||
void VL_FadeIn (int start, int end, SDL_Color *palette, int steps);
|
||||
byte *VL_LockSurface (SDL_Surface *surface);
|
||||
void VL_UnlockSurface (SDL_Surface *surface);
|
||||
void VL_BarScaledCoord (int scx, int scy, int scwidth, int scheight, int color);
|
||||
void VL_Bar (int x, int y, int width, int height, int color);
|
||||
void VL_ClearScreen (int color);
|
||||
void VWB_Bar (int x, int y, int width, int height, int color);
|
||||
#define VWB_BarScaledCoord VL_BarScaledCoord
|
||||
void VWB_DrawPic (int x, int y, int chunknum);
|
||||
void VWB_DrawPicScaledCoord (int x, int y, int chunknum);
|
||||
void VH_UpdateScreen (SDL_Surface *surface);
|
||||
#define VW_UpdateScreen() VH_UpdateScreen (screenBuffer)
|
||||
#define VW_WaitVBL VL_WaitVBL
|
||||
#define VW_FadeIn() VL_FadeIn(0,255,gamepal,30);
|
||||
#define VW_FadeOut() VL_FadeOut(0,255,0,0,0,30);
|
||||
boolean FizzleFade (SDL_Surface *source, int x1, int y1, unsigned width, unsigned height, unsigned frames, boolean abortable);
|
||||
extern byte fontcolor, backcolor;
|
||||
extern int fontnumber;
|
||||
extern int px, py;
|
||||
#define SETFONTCOLOR(f,b) fontcolor=f;backcolor=b;
|
||||
|
||||
/* ---- id_us ---- */
|
||||
#define MaxX 320
|
||||
#define MaxY 200
|
||||
extern boolean ingame;
|
||||
extern word PrintX, PrintY, WindowX, WindowY, WindowW, WindowH;
|
||||
void US_Print (const char *s);
|
||||
void US_PrintSigned (int32_t n);
|
||||
void US_PrintUnsigned (longword n);
|
||||
void US_CPrint (const char *s);
|
||||
void US_DrawWindow (word x, word y, word w, word h);
|
||||
void US_CenterWindow (word w, word h);
|
||||
void US_InitRndT (int randomize);
|
||||
int US_RndT (void);
|
||||
boolean US_LineInput (int x, int y, char *buf, const char *def, boolean escok, int maxchars, int maxwidth);
|
||||
void US_ControlPanel (ScanCode s);
|
||||
|
||||
/* ---- wl_menu ---- */
|
||||
#define MenuFadeOut() VL_FadeOut(0,255,43,0,0,10)
|
||||
#define MenuFadeIn() VL_FadeIn(0,255,gamepal,10)
|
||||
#define INTROSONG NAZI_NOR_MUS
|
||||
#define VIEWCOLOR 0x7f
|
||||
void Message (const char *string);
|
||||
void CenterWindow (word w, word h);
|
||||
void ClearMemory (void);
|
||||
void ClearSplitVWB (void);
|
||||
|
||||
/* ---- Paramix own (pmx_*.c) ---- */
|
||||
int pmx_iangle (int32_t dy, int32_t dx); /* atan2 in whole degrees 0..359 (as (int)(atan2/(2 pi)*360)) */
|
||||
void pmx_hud_dirty (void); /* the status bar changed */
|
||||
extern unsigned pmx_face; /* face pic (game chunk number) set by DrawFace */
|
||||
void pmx_status (void); /* draw it into the screen buffer */
|
||||
uint32_t pmx_ms (void); /* milliseconds */
|
||||
void pmx_present (void); /* the 8-bit screen to the display */
|
||||
void pmx_poll (void); /* keys */
|
||||
extern uint32_t pmx_keys; /* PMX_K_* held */
|
||||
#define PMX_K_A 1u
|
||||
#define PMX_K_B 2u
|
||||
#define PMX_K_C 4u
|
||||
#define PMX_K_WHEEL 8u
|
||||
void pmx_buttons (void); /* keys to buttonstate[] (PollKeyboardButtons) */
|
||||
void pmx_move (int delta); /* keys and wheel to controlx, controly (PollKeyboardMove) */
|
||||
void pmx_error (const char *s); /* shown, then back to the Paradise */
|
||||
typedef struct { uint32_t fire, fwd, back, use, mod, run_dbl, invert, turn_deg; } PmxKeys;
|
||||
extern PmxKeys pmx_k; /* key layout (from the settings block the Studio writes) */
|
||||
extern int pmx_run, pmx_leave_req, pmx_sound_on;
|
||||
void pmx_leave (void); /* save and back to the Paradise */
|
||||
void pmx_idle (void); /* waiting: sound, leave request */
|
||||
void pmx_sd_service (uint32_t now);
|
||||
byte *pmx_screen (void);
|
||||
const uint16_t *pmx_lut (void);
|
||||
void pmx_vl_init (void);
|
||||
void pmx_palshift (int r, int g, int b, int i, int steps); /* the game's palette shifted i/steps towards r, g, b */
|
||||
void pmx_text (int x, int y, const char *s, int color);
|
||||
void pmx_text_c (int y, const char *s, int color);
|
||||
void pmx_drawpic (int x, int y, int k);
|
||||
void pmx_drawpic_scaled (int x, int y, int k, int dw, int dh);
|
||||
extern int pmx_wheel; /* wheel steps since the last poll (+ one way) */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,150 @@
|
||||
/* Paramix Wolf3D: the data pack (W3DP, built by the Studio from the user's game files): pages, maps, pics, sounds.
|
||||
* Maps are unpacked (Carmack, then RLEW) into RAM when a level starts; everything else is read in place.
|
||||
* Author: mameise. GPL-2.0-or-later (CAL_CarmackExpand and CA_RLEWexpand from Wolf4SDL / id Software). */
|
||||
#include "wl_def.h"
|
||||
#include "pmx_plat.h"
|
||||
#include "pmx_ca.h"
|
||||
|
||||
word ChunksInFile, PMSpriteStart, PMSoundStart;
|
||||
word *mapsegs[MAPPLANES];
|
||||
maptype *mapheaderseg[NUMMAPS];
|
||||
static word g_plane[MAPPLANES][MAPAREA];
|
||||
static maptype g_maphead;
|
||||
static const uint8_t *P, *PF; /* the pack: fast up to g_win, then through PF */
|
||||
static uint32_t g_win;
|
||||
static const uint8_t *at (uint32_t o) { return o < g_win ? P + o : PF + o; }
|
||||
/* a piece that ends behind the fast part is read whole through the slow path */
|
||||
static const uint8_t *atn (uint32_t o, uint32_t n) { return o + n <= g_win ? P + o : PF + o; }
|
||||
static uint32_t n_pages, pages_tab, n_maps, rlew, maps_tab, n_snd, snd_tab, n_pics, pics_tab;
|
||||
int pmx_episodes, pmx_shareware;
|
||||
|
||||
static uint32_t rd32 (uint32_t o) { const uint8_t *b = at (o); return b[0] | b[1] << 8 | b[2] << 16 | (uint32_t)b[3] << 24; }
|
||||
static uint16_t rd16 (uint32_t o) { const uint8_t *b = at (o); return (uint16_t)(b[0] | b[1] << 8); }
|
||||
|
||||
int pmx_pack_open (void)
|
||||
{
|
||||
P = plat_pack (); PF = plat_pack_far (); g_win = plat_pack_win ();
|
||||
if (!P || P[0] != 'W' || P[1] != '3' || P[2] != 'D' || P[3] != 'P') return 0;
|
||||
pmx_shareware = rd32 (8) & 1;
|
||||
#ifdef SPEAR
|
||||
if (!(rd32 (8) & 2)) return 0; /* 1.6.11 test2: the Spear of Destiny program needs a pack of the .SOD files */
|
||||
pmx_episodes = 1;
|
||||
#else
|
||||
if (rd32 (8) & 2) return 0;
|
||||
#endif
|
||||
n_pages = rd32 (16); PMSpriteStart = (word)rd32 (20); pages_tab = rd32 (24);
|
||||
n_maps = rd32 (28); rlew = rd32 (32); maps_tab = rd32 (36);
|
||||
n_snd = rd32 (40); snd_tab = rd32 (44);
|
||||
n_pics = rd32 (48); pics_tab = rd32 (52);
|
||||
#ifndef SPEAR
|
||||
pmx_episodes = (int)rd32 (60);
|
||||
#endif
|
||||
if (pmx_episodes < 1) pmx_episodes = 1;
|
||||
if (pmx_episodes > 6) pmx_episodes = 6;
|
||||
ChunksInFile = PMSoundStart = (word)n_pages;
|
||||
for (int i = 0; i < MAPPLANES; i++) mapsegs[i] = g_plane[i];
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ---- pages (walls 64 x 64 by columns, sprites as t_compshape) ---- */
|
||||
byte *PM_GetPage (int page)
|
||||
{
|
||||
if ((uint32_t)page >= n_pages) Quit ("PM_GetPage: page %d", page);
|
||||
uint32_t o = rd32 (pages_tab + 8u * (uint32_t)page);
|
||||
if (!o) return (byte *)P + 64; /* empty page: something harmless */
|
||||
return (byte *)atn (o, rd32 (pages_tab + 8u * (uint32_t)page + 4));
|
||||
}
|
||||
uint32_t PM_GetPageSize (int page) { return (uint32_t)page < n_pages ? rd32 (pages_tab + 8u * (uint32_t)page + 4) : 0; }
|
||||
void PM_Startup (void) {}
|
||||
|
||||
/* ---- maps ---- */
|
||||
#define NEARTAG 0xa7
|
||||
#define FARTAG 0xa8
|
||||
static void carmack (const byte *src, word *dest, int length)
|
||||
{
|
||||
word ch, chhigh, count, offset;
|
||||
word *copyptr, *outptr = dest;
|
||||
length /= 2;
|
||||
while (length > 0)
|
||||
{
|
||||
ch = (word)(src[0] | src[1] << 8); src += 2;
|
||||
chhigh = ch >> 8;
|
||||
if (chhigh == NEARTAG || chhigh == FARTAG)
|
||||
{
|
||||
count = ch & 0xff;
|
||||
if (!count) { ch |= *src++; *outptr++ = ch; length--; continue; }
|
||||
if (chhigh == NEARTAG) { offset = *src++; copyptr = outptr - offset; }
|
||||
else { offset = (word)(src[0] | src[1] << 8); src += 2; copyptr = dest + offset; }
|
||||
length -= count;
|
||||
if (length < 0) return;
|
||||
while (count--) *outptr++ = *copyptr++;
|
||||
}
|
||||
else { *outptr++ = ch; length--; }
|
||||
}
|
||||
}
|
||||
static void rlewexpand (const word *source, word *dest, int32_t length, word tag)
|
||||
{
|
||||
word *end = dest + length / 2;
|
||||
do
|
||||
{
|
||||
word value = *source++;
|
||||
if (value != tag) *dest++ = value;
|
||||
else { word count = *source++; value = *source++; for (word i = 1; i <= count && dest < end; i++) *dest++ = value; }
|
||||
} while (dest < end);
|
||||
}
|
||||
/* the Carmack-unpacked plane (RLEW packed, at most a little longer than the plane): in the screen buffer, which is
|
||||
* drawn anew after a level was loaded (saves 8 KB of RAM) */
|
||||
#define SCRATCH_LEN (128u * 128u)
|
||||
static word *scratch (void) { return (word *)pmx_screen (); }
|
||||
|
||||
void CA_CacheMap (int mapnum)
|
||||
{
|
||||
if ((uint32_t)mapnum >= n_maps || !rd32 (maps_tab + 4u * (uint32_t)mapnum)) Quit ("no map %d", mapnum);
|
||||
uint32_t h = rd32 (maps_tab + 4u * (uint32_t)mapnum);
|
||||
pmx_read (&g_maphead, h, sizeof g_maphead);
|
||||
mapheaderseg[mapnum] = &g_maphead;
|
||||
for (int plane = 0; plane < MAPPLANES; plane++)
|
||||
{
|
||||
uint32_t pos = (uint32_t)g_maphead.planestart[plane], len = g_maphead.planelength[plane];
|
||||
if (!pos || !len) Quit ("map %d plane %d", mapnum, plane);
|
||||
const byte *src = atn (pos, len); /* read in place (memory mapped flash) */
|
||||
word expanded = (word)(src[0] | src[1] << 8);
|
||||
if (expanded > SCRATCH_LEN) Quit ("map %d too big", mapnum);
|
||||
carmack (src + 2, scratch (), expanded);
|
||||
rlewexpand (scratch () + 1, g_plane[plane], MAPAREA * 2, (word)rlew);
|
||||
}
|
||||
}
|
||||
void CA_Startup (void) {}
|
||||
/* the map unpacking buffer, free while a level runs (the save uses it) */
|
||||
byte *pmx_ca_scratch (uint32_t *len) { *len = SCRATCH_LEN; return (byte *)scratch (); }
|
||||
uint32_t pmx_pack_len (void) { return rd32 (12); }
|
||||
|
||||
/* ---- pics (8-bit, rows from the top; index see pmx_ca.h) ---- */
|
||||
const byte *pmx_pic (int k, int *w, int *h)
|
||||
{
|
||||
if ((uint32_t)k >= n_pics) { *w = *h = 0; return 0; }
|
||||
uint32_t o = rd32 (pics_tab + 8u * (uint32_t)k);
|
||||
*w = rd16 (pics_tab + 8u * (uint32_t)k + 4); *h = rd16 (pics_tab + 8u * (uint32_t)k + 6);
|
||||
if (!o) { *w = *h = 0; return 0; }
|
||||
return atn (o, (uint32_t)*w * (uint32_t)*h);
|
||||
}
|
||||
|
||||
/* ---- PC speaker sounds: u32 length, u16 priority, bytes ---- */
|
||||
const byte *pmx_sound (int k, uint32_t *len, int *prio)
|
||||
{
|
||||
if ((uint32_t)k >= n_snd) return 0;
|
||||
uint32_t o = rd32 (snd_tab + 8u * (uint32_t)k);
|
||||
if (!o) return 0;
|
||||
*len = rd32 (o); *prio = rd16 (o + 4);
|
||||
return atn (o + 6, *len);
|
||||
}
|
||||
|
||||
void pmx_read (void *dst, uint32_t off, uint32_t n)
|
||||
{
|
||||
const uint8_t *s = atn (off, n); uint8_t *d = (uint8_t *)dst;
|
||||
while (n--) *d++ = *s++;
|
||||
}
|
||||
|
||||
/* demos are not played or recorded on the Paradise */
|
||||
void CA_LoadFile (const char *filename, void **ptr) { (void)filename; *ptr = 0; Quit ("no demos"); }
|
||||
void CA_WriteFile (const char *filename, void *ptr, int32_t length) { (void)filename; (void)ptr; (void)length; }
|
||||
@@ -0,0 +1,27 @@
|
||||
/* Paramix Wolf3D: the data pack. Author: mameise. */
|
||||
#ifndef PMX_CA_H
|
||||
#define PMX_CA_H
|
||||
#include <stdint.h>
|
||||
|
||||
/* pics in the pack: the game's range L_COLONPIC .. GETPSYCHEDPIC (same order in every version) */
|
||||
enum {
|
||||
PK_L_COLON = 0, PK_L_NUM0 = 1, PK_L_PERCENT = 11, PK_L_A = 12, /* L_APIC .. L_ZPIC: 26 */
|
||||
PK_L_EXPOINT = 38, PK_L_APOSTROPHE = 39, PK_L_GUY = 40, PK_L_GUY2 = 41,
|
||||
PK_STATUSBAR = 42, PK_TITLE = 43, PK_PG13 = 44, PK_CREDITS = 45, PK_HIGHSCORES = 46,
|
||||
PK_KNIFE = 47, PK_GUN, PK_MACHINEGUN, PK_GATLING, PK_NOKEY, PK_GOLDKEY, PK_SILVERKEY, PK_N_BLANK,
|
||||
PK_N_0 = 55, PK_FACE1A = 65, PK_FACE8A = 86, PK_GOTGATLING = 87, PK_MUTANTBJ = 88, PK_PAUSED = 89, PK_GETPSYCHED = 90,
|
||||
PK_SOD_GOD1 = 91 /* Spear of Destiny: GODMODEFACE1..3, BJWAITING1..2, BJOUCH */
|
||||
};
|
||||
|
||||
extern int pmx_episodes, pmx_shareware;
|
||||
int pmx_pack_open (void);
|
||||
const uint8_t *pmx_pic (int k, int *w, int *h);
|
||||
int chunk_to_pk (int chunk);
|
||||
const uint8_t *pmx_sound (int k, uint32_t *len, int *prio);
|
||||
void pmx_read (void *dst, uint32_t off, uint32_t n);
|
||||
uint32_t pmx_pack_len (void);
|
||||
int pmx_save_game (void);
|
||||
int pmx_load_game (void);
|
||||
int pmx_save_present (void);
|
||||
void pmx_save_forget (void);
|
||||
#endif
|
||||
@@ -0,0 +1,122 @@
|
||||
/* Paramix Wolf3D: the Paradise's keys to the game (same layout as DOOM on the Paradise, set in the Studio):
|
||||
* A fire, B forward, C back, wheel turns, wheel press use (doors, switches), hold C + wheel: weapon,
|
||||
* B twice quickly: run on/off, A+C: menu, wheel held 2 s: save and back to the Paradise.
|
||||
* The hold key (C) only moves back after 120 ms and while the wheel was not turned.
|
||||
* Author: mameise. GPL-2.0-or-later. */
|
||||
#include "wl_def.h"
|
||||
#include "pmx_plat.h"
|
||||
|
||||
bool Keyboard[sc_Last];
|
||||
boolean MousePresent, Paused;
|
||||
ScanCode LastScan;
|
||||
uint32_t pmx_keys;
|
||||
int pmx_wheel;
|
||||
|
||||
PmxKeys pmx_k = { PMX_K_A, PMX_K_B, PMX_K_C, PMX_K_WHEEL, PMX_K_C, 1, 0, 15 };
|
||||
int pmx_run; /* run on (B twice) */
|
||||
static int turn_pending; /* controlx units still to turn (20 per degree) */
|
||||
static int use_left, chg_left, chg_dir;
|
||||
static uint32_t mod_t0, b_last, b_prev, wh_t0;
|
||||
static int det_seen, menu_hold, esc_req;
|
||||
int pmx_leave_req;
|
||||
|
||||
/* once per game tic batch (PollControls): read the keys and the wheel */
|
||||
void pmx_poll (void)
|
||||
{
|
||||
uint32_t now = plat_ms (), b = plat_keys ();
|
||||
int det = plat_wheel ();
|
||||
if (pmx_k.invert) det = -det;
|
||||
pmx_keys = b;
|
||||
/* wheel pressed: short = use, held 2 s = leave */
|
||||
if (b & PMX_K_WHEEL) { if (!wh_t0) wh_t0 = now | 1u; else if (plat_exit (now - wh_t0)) pmx_leave_req = 1; }
|
||||
else { if (wh_t0 && now - wh_t0 < 800u && pmx_k.use == PMX_K_WHEEL) use_left = 2; wh_t0 = 0; }
|
||||
if (det)
|
||||
{
|
||||
if (b & pmx_k.mod) { chg_left = 1; chg_dir = det > 0; det_seen = 1; }
|
||||
else
|
||||
{
|
||||
int add = det * pmx_k.turn_deg * 20;
|
||||
if ((add > 0) != (turn_pending > 0)) turn_pending = 0;
|
||||
turn_pending += add;
|
||||
}
|
||||
}
|
||||
int ac = (b & PMX_K_A) && (b & PMX_K_C);
|
||||
if (ac) { if (++menu_hold == 1) esc_req = 1; } else menu_hold = 0;
|
||||
if (!(b & pmx_k.mod)) { mod_t0 = 0; det_seen = 0; }
|
||||
else if (!mod_t0) mod_t0 = now | 1u;
|
||||
if (pmx_k.run_dbl && (b & pmx_k.fwd) && !(b_last & pmx_k.fwd))
|
||||
{
|
||||
if (b_prev && now - b_prev < 300u) { pmx_run ^= 1; b_prev = 0; pmx_hud_dirty (); } else b_prev = now;
|
||||
}
|
||||
if (pmx_k.use != PMX_K_WHEEL && (b & pmx_k.use) && !(b_last & pmx_k.use)) use_left = 2;
|
||||
b_last = b;
|
||||
}
|
||||
|
||||
static int held (uint32_t key)
|
||||
{
|
||||
uint32_t b = pmx_keys;
|
||||
if ((b & PMX_K_A) && (b & PMX_K_C)) return 0; /* the menu pair */
|
||||
if (!(b & key)) return 0;
|
||||
if (key == pmx_k.mod) return !det_seen && mod_t0 && (int)(plat_ms () - mod_t0) >= 120;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void pmx_buttons (void)
|
||||
{
|
||||
pmx_poll ();
|
||||
if (held (pmx_k.fire)) buttonstate[bt_attack] = true;
|
||||
if (use_left) { use_left--; buttonstate[bt_use] = true; }
|
||||
if (pmx_run) buttonstate[bt_run] = true;
|
||||
if (chg_left) { chg_left--; buttonstate[chg_dir ? bt_nextweapon : bt_prevweapon] = true; }
|
||||
if (esc_req) { esc_req = 0; buttonstate[bt_esc] = true; }
|
||||
}
|
||||
|
||||
void pmx_move (int delta)
|
||||
{
|
||||
if (held (pmx_k.fwd)) controly -= delta;
|
||||
if (held (pmx_k.back)) controly += delta;
|
||||
if (turn_pending)
|
||||
{
|
||||
int max = 100 * (int)tics, t = turn_pending;
|
||||
if (t > max) t = max;
|
||||
if (t < -max) t = -max;
|
||||
controlx += t; turn_pending -= t;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- the id input calls the game still makes ---- */
|
||||
void IN_ClearKeysDown (void) { memset (Keyboard, 0, sizeof Keyboard); LastScan = sc_None; esc_req = 0; }
|
||||
void IN_ProcessEvents (void) { if (pmx_leave_req) pmx_leave (); }
|
||||
|
||||
/* a fresh key press (any of A, B, C, wheel press, or a wheel step) */
|
||||
static uint32_t ack_last;
|
||||
void IN_StartAck (void) { ack_last = plat_keys (); plat_wheel (); }
|
||||
boolean IN_CheckAck (void)
|
||||
{
|
||||
uint32_t b = plat_keys ();
|
||||
int det = plat_wheel ();
|
||||
boolean r = (b & ~ack_last) != 0;
|
||||
ack_last = b;
|
||||
(void)det;
|
||||
pmx_idle ();
|
||||
return r;
|
||||
}
|
||||
void IN_Ack (void) { IN_StartAck (); while (!IN_CheckAck ()) plat_wait (10); }
|
||||
boolean IN_UserInput (longword delay)
|
||||
{
|
||||
uint32_t t0 = plat_ms (), ms = delay * 1000u / 70u;
|
||||
IN_StartAck ();
|
||||
while (plat_ms () - t0 < ms) { if (IN_CheckAck ()) return true; plat_wait (10); }
|
||||
return false;
|
||||
}
|
||||
|
||||
/* the key layout from the settings block (the Studio writes it) */
|
||||
int pmx_english;
|
||||
void pmx_cfg_keys (uint32_t fire, uint32_t fwd, uint32_t back, uint32_t use, uint32_t mod, uint32_t run_dbl, uint32_t invert, uint32_t turn_deg, uint32_t english)
|
||||
{
|
||||
if (fire && fwd && back && fire != fwd && fire != back && fwd != back)
|
||||
{ pmx_k.fire = fire; pmx_k.fwd = fwd; pmx_k.back = back; pmx_k.use = use ? use : PMX_K_WHEEL; pmx_k.mod = mod; }
|
||||
pmx_k.run_dbl = run_dbl; pmx_k.invert = invert;
|
||||
if (turn_deg >= 2 && turn_deg <= 90) pmx_k.turn_deg = turn_deg;
|
||||
pmx_english = (int)english;
|
||||
}
|
||||
@@ -0,0 +1,454 @@
|
||||
/* Paramix Wolf3D: start, menus, interludes and the status bar for the 128 x 128 screen.
|
||||
* BuildTables, CalcProjection, SetupWalls, SetViewSize, NewGame and the level bonus logic come from Wolf4SDL
|
||||
* (wl_main.c, wl_inter.c by id Software); the screens are new.
|
||||
* Author: mameise. GPL-2.0-or-later. */
|
||||
#include "wl_def.h"
|
||||
#include "pmx_plat.h"
|
||||
#include "pmx_ca.h"
|
||||
extern int pmx_english;
|
||||
#define TX(de, en) (pmx_english ? (en) : (de))
|
||||
/* settings kept on the device (4 KB settings page): sound */
|
||||
typedef struct { uint32_t magic; uint8_t sound, r[3]; } PmxSet;
|
||||
#define SET_MAGIC 0x31533357u /* "W3S1" */
|
||||
static void set_load (void) { PmxSet t; plat_settings_read (&t, sizeof t); if (t.magic == SET_MAGIC) pmx_sound_on = t.sound & 1; }
|
||||
static void set_store (void) { PmxSet t = { SET_MAGIC, (uint8_t)pmx_sound_on, {0, 0, 0} }; PmxSet o; plat_settings_read (&o, sizeof o); if (memcmp (&o, &t, sizeof t)) plat_settings_write (&t, sizeof t); }
|
||||
|
||||
/* ---- wl_main.c globals ---- */
|
||||
#define FOCALLENGTH (0x5700l)
|
||||
#define VIEWGLOBAL 0x10000
|
||||
char str[80];
|
||||
int dirangle[9] = {0,ANGLES/8,2*ANGLES/8,3*ANGLES/8,4*ANGLES/8,5*ANGLES/8,6*ANGLES/8,7*ANGLES/8,ANGLES};
|
||||
fixed focallength;
|
||||
unsigned screenofs;
|
||||
int viewscreenx, viewscreeny;
|
||||
int viewwidth;
|
||||
int viewheight;
|
||||
short centerx,centery;
|
||||
int shootdelta;
|
||||
fixed scale;
|
||||
int32_t heightnumerator;
|
||||
boolean startgame;
|
||||
boolean loadedgame;
|
||||
int mouseadjustment;
|
||||
boolean param_debugmode = false;
|
||||
boolean param_nowait = false;
|
||||
int param_difficulty = 1;
|
||||
int param_tedlevel = -1;
|
||||
int param_mission = 0;
|
||||
boolean param_goodtimes = true;
|
||||
LRstruct LevelRatios[LRpack];
|
||||
static short g_pixelangle[128];
|
||||
static int16_t g_wallheight[128];
|
||||
unsigned pmx_face;
|
||||
static int hud_dirty = 1;
|
||||
|
||||
static const byte rndtable_[256] = {
|
||||
#include "rndtable.inc"
|
||||
};
|
||||
static int rndindex;
|
||||
void US_InitRndT (int randomize) { rndindex = randomize ? (int)((plat_ms () >> 4) & 0xff) : 0; }
|
||||
int US_RndT (void) { rndindex = (rndindex + 1) & 0xff; return rndtable_[rndindex]; }
|
||||
|
||||
uint32_t SDL_GetTicks (void) { return plat_ms (); }
|
||||
void SDL_Delay (uint32_t ms)
|
||||
{
|
||||
uint32_t t0 = plat_ms ();
|
||||
pmx_idle ();
|
||||
while (plat_ms () - t0 < ms) { plat_wait (ms - (plat_ms () - t0) > 5 ? 5 : 1); pmx_idle (); }
|
||||
}
|
||||
void pmx_idle (void)
|
||||
{
|
||||
#ifndef PMX_SD_IN_TICK /* on the Paradise the millisecond tick serves the sound */
|
||||
pmx_sd_service (plat_ms ());
|
||||
#endif
|
||||
if (pmx_leave_req) pmx_leave ();
|
||||
}
|
||||
|
||||
/* ---- tables (wl_main.c BuildTables and CalcProjection, computed on the PC for a view 128 wide) ---- */
|
||||
#include "pmx_tables.h"
|
||||
void BuildTables (void) {}
|
||||
void CalcProjection (int32_t focal)
|
||||
{
|
||||
focallength = focal;
|
||||
scale = PMX_T_SCALE;
|
||||
heightnumerator = PMX_T_HEIGHTNUMERATOR;
|
||||
for (int i = 0; i < viewwidth && i < 128; i++) pixelangle[i] = pmx_pixelangle[i];
|
||||
}
|
||||
void SetupWalls (void)
|
||||
{
|
||||
horizwall[0]=0;
|
||||
vertwall[0]=0;
|
||||
for (int i=1;i<MAXWALLTILES;i++)
|
||||
{
|
||||
horizwall[i]=(i-1)*2;
|
||||
vertwall[i]=(i-1)*2+1;
|
||||
}
|
||||
}
|
||||
boolean SetViewSize (unsigned width, unsigned height)
|
||||
{
|
||||
viewwidth = width&~15;
|
||||
viewheight = height&~1;
|
||||
centerx = viewwidth/2-1;
|
||||
centery = viewheight / 2;
|
||||
shootdelta = viewwidth/10;
|
||||
viewscreenx = 0; viewscreeny = 0; screenofs = 0;
|
||||
CalcProjection (FOCALLENGTH);
|
||||
return true;
|
||||
}
|
||||
void NewGame (int difficulty,int episode)
|
||||
{
|
||||
memset (&gamestate,0,sizeof(gamestate));
|
||||
gamestate.difficulty = difficulty;
|
||||
gamestate.weapon = gamestate.bestweapon = gamestate.chosenweapon = wp_pistol;
|
||||
gamestate.health = 100;
|
||||
gamestate.ammo = STARTAMMO;
|
||||
gamestate.lives = 3;
|
||||
gamestate.nextextra = EXTRAPOINTS;
|
||||
gamestate.episode=episode;
|
||||
startgame = true;
|
||||
}
|
||||
void Quit (const char *errorStr, ...)
|
||||
{
|
||||
char b[80];
|
||||
va_list ap; va_start (ap, errorStr); vsnprintf (b, sizeof b, errorStr ? errorStr : "", ap); va_end (ap);
|
||||
pmx_error (b);
|
||||
}
|
||||
|
||||
/* ---- screen out ---- */
|
||||
void pmx_hud_dirty (void) { hud_dirty = 1; }
|
||||
#define HUD_Y 96
|
||||
static int hud_bg = 0x1d;
|
||||
static void num_big (int x, int y, int digits, int32_t v)
|
||||
{
|
||||
char s[12]; snprintf (s, sizeof s, "%ld", (long)v);
|
||||
int n = (int)strlen (s);
|
||||
for (int i = 0; i < digits; i++)
|
||||
{
|
||||
int k = i - (digits - n);
|
||||
pmx_drawpic (x + 8 * i, y, k < 0 ? PK_N_BLANK : PK_N_0 + (s[k] - '0'));
|
||||
}
|
||||
}
|
||||
void pmx_status (void)
|
||||
{
|
||||
byte *s = pmx_screen ();
|
||||
memset (s + HUD_Y * 128, hud_bg, 32 * 128);
|
||||
for (int x = 0; x < 128; x++) s[HUD_Y * 128 + x] = 0x00;
|
||||
if (pmx_face) pmx_drawpic (0, HUD_Y, chunk_to_pk ((int)pmx_face)); /* 24 x 32 */
|
||||
num_big (26, HUD_Y + 2, 3, gamestate.health); /* 8 x 16 digits */
|
||||
pmx_text (50, HUD_Y + 6, "%", 0x0f);
|
||||
num_big (58, HUD_Y + 2, 2, gamestate.ammo > 99 ? 99 : gamestate.ammo);
|
||||
pmx_drawpic (78, HUD_Y + 2, (gamestate.keys & 1) ? PK_GOLDKEY : PK_NOKEY);
|
||||
pmx_drawpic (86, HUD_Y + 2, (gamestate.keys & 2) ? PK_SILVERKEY : PK_NOKEY);
|
||||
if (gamestate.weapon >= 0) pmx_drawpic_scaled (96, HUD_Y + 2, PK_KNIFE + gamestate.weapon, 32, 16);
|
||||
char line[24];
|
||||
#ifdef SPEAR
|
||||
snprintf (line, sizeof line, "%d", gamestate.mapon + 1);
|
||||
#else
|
||||
snprintf (line, sizeof line, "%d-%d", gamestate.episode + 1, gamestate.mapon + 1);
|
||||
#endif
|
||||
pmx_text (26, HUD_Y + 22, line, 0x0f);
|
||||
snprintf (line, sizeof line, "%d", gamestate.lives);
|
||||
pmx_drawpic_scaled (52, HUD_Y + 20, PK_FACE1A, 6, 8);
|
||||
pmx_text (60, HUD_Y + 22, line, 0x0f);
|
||||
snprintf (line, sizeof line, "%07ld", (long)gamestate.score);
|
||||
pmx_text (128 - 6 * 7, HUD_Y + 22, line, 0x0f);
|
||||
if (pmx_run) pmx_text (72, HUD_Y + 22, ">>", 0x0e);
|
||||
hud_dirty = 0;
|
||||
}
|
||||
static int g_hud_on, g_hud_shown;
|
||||
extern int pmx_lut_changed;
|
||||
/* in a level the status bar is drawn and sent only when it changed (or the palette did) */
|
||||
void pmx_present (void)
|
||||
{
|
||||
int full = 1;
|
||||
if (g_hud_on)
|
||||
{
|
||||
full = hud_dirty || !g_hud_shown || pmx_lut_changed;
|
||||
if (hud_dirty || !g_hud_shown) pmx_status ();
|
||||
g_hud_shown = 1;
|
||||
}
|
||||
else g_hud_shown = 0;
|
||||
pmx_lut_changed = 0;
|
||||
pmx_idle ();
|
||||
plat_lcd (pmx_screen (), 0, full ? 128 : 128 - STATUSLINES, pmx_lut ());
|
||||
}
|
||||
|
||||
/* ---- menus ---- */
|
||||
#define C_TEXT 0x0f
|
||||
#define C_HI 0x0e
|
||||
#define C_DIM 0x08
|
||||
#define C_BACK 0x00
|
||||
|
||||
/* keys for menus: a fresh press of A/B (ok), C (back), wheel steps or A+C */
|
||||
enum { MK_NONE, MK_UP, MK_DOWN, MK_OK, MK_BACK };
|
||||
static uint32_t mk_last;
|
||||
static int menu_key (void)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
pmx_idle ();
|
||||
uint32_t b = plat_keys (), n = b & ~mk_last;
|
||||
int det = plat_wheel ();
|
||||
if (pmx_k.invert) det = -det;
|
||||
mk_last = b;
|
||||
if (det > 0) return MK_DOWN;
|
||||
if (det < 0) return MK_UP;
|
||||
if (n & (PMX_K_A | PMX_K_B | PMX_K_WHEEL)) return MK_OK;
|
||||
if (n & PMX_K_C) return MK_BACK;
|
||||
plat_wait (10);
|
||||
}
|
||||
}
|
||||
static int menu (const char *title, const char *const *items, int n, int sel, int top_pic)
|
||||
{
|
||||
mk_last = plat_keys ();
|
||||
for (;;)
|
||||
{
|
||||
VL_ClearScreen (C_BACK);
|
||||
int y = 4;
|
||||
if (top_pic) { pmx_drawpic_scaled (0, 0, PK_TITLE, 128, 80); y = 82; }
|
||||
else { pmx_text_c (y, title, C_HI); y += 12; }
|
||||
int rows = (128 - y) / 10, first = sel - rows + 1; if (first < 0) first = 0;
|
||||
for (int i = first; i < n && i < first + rows; i++)
|
||||
{
|
||||
int yy = y + (i - first) * 10;
|
||||
if (i == sel) VL_Bar (0, yy - 2, 128, 10, 0x29);
|
||||
pmx_text (4, yy, items[i], i == sel ? C_HI : C_TEXT);
|
||||
}
|
||||
pmx_present ();
|
||||
switch (menu_key ())
|
||||
{
|
||||
case MK_UP: sel = (sel + n - 1) % n; break;
|
||||
case MK_DOWN: sel = (sel + 1) % n; break;
|
||||
case MK_OK: return sel;
|
||||
case MK_BACK: return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char *const EPISODES[6] = { "ESCAPE", "EISENFAUST", "DIE FUHRER DIE", "A DARK SECRET", "TRAIL OF MADMAN", "CONFRONTATION" };
|
||||
static const char *const SKILLS[4] = { "CAN I PLAY, DADDY?", "DON'T HURT ME.", "BRING 'EM ON!", "I AM DEATH INCARNATE" };
|
||||
|
||||
static int choose_new_game (void)
|
||||
{
|
||||
int ep = 0;
|
||||
if (pmx_episodes > 1)
|
||||
{
|
||||
const char *items[6]; char buf[6][24];
|
||||
for (int i = 0; i < pmx_episodes; i++) { snprintf (buf[i], sizeof buf[i], "%d %s", i + 1, EPISODES[i]); items[i] = buf[i]; }
|
||||
ep = menu ("EPISODE", items, pmx_episodes, 0, 0);
|
||||
if (ep < 0) return 0;
|
||||
}
|
||||
int sk = menu (TX ("SCHWIERIGKEIT", "DIFFICULTY"), SKILLS, 4, 2, 0);
|
||||
if (sk < 0) return 0;
|
||||
NewGame (sk, ep);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* in game (A+C): returns with startgame set for a new game, playstate ex_abort to the title */
|
||||
void US_ControlPanel (ScanCode s)
|
||||
{
|
||||
(void)s;
|
||||
g_hud_on = 0;
|
||||
for (;;)
|
||||
{
|
||||
const char *items[] = { TX ("WEITER", "CONTINUE"), TX ("NEUES SPIEL", "NEW GAME"), pmx_sound_on ? TX ("TON: AN", "SOUND: ON") : TX ("TON: AUS", "SOUND: OFF"), TX ("ZUM PARADISE", "TO THE PARADISE") };
|
||||
int r = menu ("MENU", items, 4, 0, 0);
|
||||
if (r < 0 || r == 0) break;
|
||||
if (r == 1) { if (choose_new_game ()) break; continue; }
|
||||
if (r == 2) { pmx_sound_on ^= 1; if (!pmx_sound_on) SD_StopSound (); set_store (); continue; }
|
||||
if (r == 3) pmx_leave ();
|
||||
}
|
||||
VL_SetPalette (gamepal, true);
|
||||
g_hud_on = 1; hud_dirty = 1;
|
||||
}
|
||||
|
||||
void Message (const char *string)
|
||||
{
|
||||
VL_Bar (4, 30, 120, 40, 0x7f);
|
||||
PrintX = WindowX = 8; PrintY = 34; fontcolor = 0;
|
||||
US_Print (string);
|
||||
pmx_present ();
|
||||
}
|
||||
void ClearSplitVWB (void) {}
|
||||
void DrawPlayScreen (void) { VL_ClearScreen (0); g_hud_on = 1; hud_dirty = 1; DrawFace (); }
|
||||
void DrawPlayBorder (void) {}
|
||||
void DrawPlayBorderSides (void) {}
|
||||
void DrawStatusBorder (byte color) { (void)color; }
|
||||
void Write (int x, int y, const char *string) { pmx_text (x * 128 / 40, y * 128 / 25, string, C_TEXT); }
|
||||
boolean US_LineInput (int x, int y, char *buf, const char *def, boolean escok, int maxchars, int maxwidth)
|
||||
{ (void)x; (void)y; (void)buf; (void)def; (void)escok; (void)maxchars; (void)maxwidth; return false; }
|
||||
|
||||
void PreloadGraphics (void)
|
||||
{
|
||||
VL_Bar (0, 0, 128, viewheight, VIEWCOLOR);
|
||||
pmx_drawpic_scaled (0, 34, PK_GETPSYCHED, 128, 27);
|
||||
VW_UpdateScreen ();
|
||||
VW_FadeIn ();
|
||||
SDL_Delay (1000);
|
||||
}
|
||||
|
||||
/* ---- end of a floor (bonus as in wl_inter.c LevelCompleted) ---- */
|
||||
static const uint16_t PAR[60] = { /* par times in seconds (wl_inter.c parTimes; 0 = boss or secret floor) */
|
||||
90,120,120,210,180,180,150,150,0,0, 90,210,180,120,240,360,60,180,0,0, 90,90,150,150,210,150,120,360,0,0,
|
||||
120,120,90,60,270,210,120,270,0,0, 150,90,150,150,240,180,270,210,0,0, 390,240,270,360,300,300,330,330,510,0 };
|
||||
#ifdef SPEAR /* 1.6.11 test2: Spear of Destiny, 21 floors (wl_inter.c parTimes; 0 = boss or secret floor) */
|
||||
static const uint16_t PAR_SOD[21] = { 90,210,165,210,0, 270,195,165,285,0, 390,270,165,270,360,0, 360,0, 0,0,0 };
|
||||
static int normal_floor (void) { int m = gamestate.mapon; return m != 4 && m != 9 && m != 15 && m < 17; }
|
||||
#else
|
||||
static int normal_floor (void) { return gamestate.mapon < 8; }
|
||||
#endif
|
||||
static void line2 (int y, const char *a, const char *b) { pmx_text (6, y, a, C_TEXT); pmx_text (128 - 6 * (int)strlen (b) - 4, y, b, C_HI); }
|
||||
void LevelCompleted (void)
|
||||
{
|
||||
char t[24], v[16];
|
||||
g_hud_on = 0;
|
||||
VL_SetPalette (gamepal, true);
|
||||
VL_ClearScreen (VIEWCOLOR);
|
||||
if (normal_floor ())
|
||||
{
|
||||
int sec = gamestate.TimeCount / 70, kr = 0, sr = 0, tr = 0;
|
||||
int32_t timeleft = 0;
|
||||
if (sec > 99 * 60) sec = 99 * 60;
|
||||
#ifdef SPEAR
|
||||
int par = PAR_SOD[gamestate.mapon % 21];
|
||||
#else
|
||||
int par = PAR[(gamestate.episode * 10 + gamestate.mapon) % 60];
|
||||
#endif
|
||||
if (gamestate.TimeCount < par * 70) timeleft = par - sec;
|
||||
if (gamestate.killtotal) kr = (gamestate.killcount * 100) / gamestate.killtotal;
|
||||
if (gamestate.secrettotal) sr = (gamestate.secretcount * 100) / gamestate.secrettotal;
|
||||
if (gamestate.treasuretotal) tr = (gamestate.treasurecount * 100) / gamestate.treasuretotal;
|
||||
int32_t bonus = timeleft * 500 + 10000 * (kr >= 100) + 10000 * (sr >= 100) + 10000 * (tr >= 100);
|
||||
snprintf (t, sizeof t, "FLOOR %d COMPLETED", gamestate.mapon + 1); pmx_text_c (6, t, C_HI);
|
||||
snprintf (v, sizeof v, "%ld", (long)bonus); line2 (24, "BONUS", v);
|
||||
snprintf (v, sizeof v, "%02d:%02d", sec / 60, sec % 60); line2 (36, "TIME", v);
|
||||
snprintf (v, sizeof v, "%02d:%02d", par / 60, par % 60); line2 (46, "PAR", par > 0 ? v : "??:??");
|
||||
snprintf (v, sizeof v, "%d%%", kr); line2 (60, "KILL RATIO", v);
|
||||
snprintf (v, sizeof v, "%d%%", sr); line2 (70, "SECRET RATIO", v);
|
||||
snprintf (v, sizeof v, "%d%%", tr); line2 (80, "TREASURE RATIO", v);
|
||||
GivePoints (bonus);
|
||||
LevelRatios[gamestate.mapon].kill = kr;
|
||||
LevelRatios[gamestate.mapon].secret = sr;
|
||||
LevelRatios[gamestate.mapon].treasure = tr;
|
||||
LevelRatios[gamestate.mapon].time = sec;
|
||||
SD_PlaySound (bonus ? ENDBONUS2SND : NOBONUSSND);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef SPEAR
|
||||
static const char *const BOSS[6] = { "TRANS GROSSE", "BARNACLE WILHELM", "UBERMUTANT", "DEATH KNIGHT", "SECRET TUNNEL AREA", "SECRET CASTLE AREA" };
|
||||
int m = gamestate.mapon, b = m == 4 ? 0 : m == 9 ? 1 : m == 15 ? 2 : m == 17 ? 3 : m == 18 ? 4 : 5;
|
||||
pmx_text_c (30, BOSS[b], C_HI);
|
||||
pmx_text_c (40, b < 4 ? "DEFEATED!" : "COMPLETED!", C_HI);
|
||||
#else
|
||||
pmx_text_c (30, "SECRET FLOOR", C_HI);
|
||||
pmx_text_c (40, "COMPLETED!", C_HI);
|
||||
#endif
|
||||
pmx_text_c (60, "15000 BONUS!", C_TEXT);
|
||||
GivePoints (15000);
|
||||
SD_PlaySound (ENDBONUS2SND);
|
||||
}
|
||||
snprintf (v, sizeof v, "%ld", (long)gamestate.score); line2 (100, "SCORE", v);
|
||||
pmx_text_c (116, TX ("TASTE: WEITER", "KEY: GO ON"), C_DIM);
|
||||
pmx_present ();
|
||||
IN_Ack ();
|
||||
g_hud_on = 1; hud_dirty = 1;
|
||||
}
|
||||
|
||||
void Victory (void)
|
||||
{
|
||||
char v[24];
|
||||
int32_t sec = 0, kr = 0, sr = 0, tr = 0, n = 0;
|
||||
for (int i = 0; i < LRpack && i < 20; i++) { if (!LevelRatios[i].time && !LevelRatios[i].kill && !LevelRatios[i].secret && !LevelRatios[i].treasure) continue; sec += LevelRatios[i].time; kr += LevelRatios[i].kill; sr += LevelRatios[i].secret; tr += LevelRatios[i].treasure; n++; }
|
||||
g_hud_on = 0;
|
||||
VL_SetPalette (gamepal, true);
|
||||
VL_ClearScreen (VIEWCOLOR);
|
||||
pmx_text_c (8, "YOU WIN!", C_HI);
|
||||
snprintf (v, sizeof v, "%02ld:%02ld", (long)(sec / 60) % 100, (long)(sec % 60)); line2 (30, "TOTAL TIME", v);
|
||||
if (!n) n = 1;
|
||||
snprintf (v, sizeof v, "%ld%%", (long)(kr / n)); line2 (44, "KILL", v);
|
||||
snprintf (v, sizeof v, "%ld%%", (long)(sr / n)); line2 (54, "SECRET", v);
|
||||
snprintf (v, sizeof v, "%ld%%", (long)(tr / n)); line2 (64, "TREASURE", v);
|
||||
snprintf (v, sizeof v, "%ld", (long)gamestate.score); line2 (84, "SCORE", v);
|
||||
pmx_text_c (116, TX ("TASTE: WEITER", "KEY: GO ON"), C_DIM);
|
||||
pmx_present ();
|
||||
IN_Ack ();
|
||||
}
|
||||
void CheckHighScore (int32_t score, word other) { (void)score; (void)other; }
|
||||
|
||||
/* ---- start ---- */
|
||||
static void init_game (void)
|
||||
{
|
||||
if (!pmx_pack_open ()) pmx_error (TX ("KEINE WOLF3D-DATEN", "NO WOLF3D DATA"));
|
||||
set_load ();
|
||||
pmx_vl_init ();
|
||||
BuildTables ();
|
||||
SetupWalls ();
|
||||
pixelangle = g_pixelangle;
|
||||
wallheight = g_wallheight;
|
||||
viewsize = 20;
|
||||
SetViewSize (128, 128 - STATUSLINES);
|
||||
InitRedShifts ();
|
||||
US_InitRndT (true);
|
||||
hud_bg = 0x1d;
|
||||
{ int w, h; const byte *sb = pmx_pic (PK_STATUSBAR, &w, &h); if (sb && w > 4 && h > 20) hud_bg = sb[20 * w + 2]; }
|
||||
}
|
||||
|
||||
void pmx_leave (void)
|
||||
{
|
||||
pmx_leave_req = 0;
|
||||
plat_tone (0);
|
||||
if (ingame && !playstate && gamestate.health > 0)
|
||||
{
|
||||
VL_Bar (0, 40, 128, 16, 0);
|
||||
pmx_text_c (45, TX ("SPEICHERE", "SAVING"), C_HI);
|
||||
plat_lcd (pmx_screen (), 40, 56, pmx_lut ());
|
||||
pmx_save_game ();
|
||||
}
|
||||
plat_back ();
|
||||
}
|
||||
|
||||
void pmx_main (void)
|
||||
{
|
||||
init_game ();
|
||||
for (;;)
|
||||
{
|
||||
int cont = pmx_save_present ();
|
||||
const char *items[4]; int n = 0, act[4];
|
||||
if (cont) { items[n] = TX ("WEITER", "CONTINUE"); act[n++] = 0; }
|
||||
items[n] = TX ("NEUES SPIEL", "NEW GAME"); act[n++] = 1;
|
||||
items[n] = pmx_sound_on ? TX ("TON: AN", "SOUND: ON") : TX ("TON: AUS", "SOUND: OFF"); act[n++] = 2;
|
||||
items[n] = TX ("ZUM PARADISE", "TO THE PARADISE"); act[n++] = 3;
|
||||
g_hud_on = 0;
|
||||
VL_SetPalette (gamepal, true);
|
||||
int r = menu ("", items, n, 0, 1);
|
||||
if (r < 0) continue;
|
||||
r = act[r];
|
||||
if (r == 0) { if (!pmx_load_game ()) { pmx_save_forget (); continue; } loadedgame = true; }
|
||||
else if (r == 1) { if (!choose_new_game ()) continue; }
|
||||
else if (r == 2) { pmx_sound_on ^= 1; set_store (); continue; }
|
||||
else pmx_leave ();
|
||||
g_hud_on = 1;
|
||||
GameLoop ();
|
||||
g_hud_on = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* atan2 without floating point: the first quadrant from finetangent (tenths of a degree), then the quadrant */
|
||||
int pmx_iangle (int32_t dy, int32_t dx)
|
||||
{
|
||||
int64_t ay = dy < 0 ? -(int64_t)dy : dy, ax = dx < 0 ? -(int64_t)dx : dx;
|
||||
int a;
|
||||
if (!ax) a = ay ? 900 : 0;
|
||||
else
|
||||
{
|
||||
int64_t r = (ay << 16) / ax;
|
||||
int lo = 0, hi = FINEANGLES / 4; /* first a with tan(a + 0.5 tenth) > r */
|
||||
while (lo < hi) { int m = (lo + hi) / 2; if (finetangent[m] <= r) lo = m + 1; else hi = m; }
|
||||
a = lo; /* tenths of a degree, 0..900 */
|
||||
}
|
||||
if (dx < 0) a = 1800 - a;
|
||||
if (dy < 0) a = 3600 - a;
|
||||
if (a >= 3600) a -= 3600;
|
||||
return a / 10;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/* Paramix Wolf3D: what the platform (PC test runner or the Paradise) gives the game. Author: mameise. */
|
||||
#ifndef PMX_PLAT_H
|
||||
#define PMX_PLAT_H
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t plat_ms (void); /* milliseconds since start */
|
||||
void plat_wait (uint32_t ms); /* sleep (the Paradise: wfi until then) */
|
||||
int plat_exit (uint32_t held); /* 1.7.3 test12: the wheel held this long: go back (the way chosen in the Studio) */
|
||||
uint32_t plat_keys (void); /* PMX_K_* held now */
|
||||
int plat_wheel (void); /* wheel steps since the last call (+ one way, - the other) */
|
||||
void plat_lcd (const uint8_t *fb, int y0, int y1, const uint16_t *lut); /* rows y0..y1-1 of the 128-wide screen */
|
||||
void plat_tone (uint32_t hz); /* buzzer, 0 = off */
|
||||
const uint8_t *plat_pack (void); /* the data pack (W3DP), fast (cached) */
|
||||
const uint8_t *plat_pack_far (void); /* the same pack through a slower path, for offsets >= plat_pack_win() */
|
||||
uint32_t plat_pack_win (void); /* how much of the pack the fast pointer reaches */
|
||||
int plat_settings_read (void *buf, int len);
|
||||
void plat_settings_write (const void *buf, int len);
|
||||
void plat_back (void); /* leave to the Paradise (does not return) */
|
||||
void plat_save_at (uint32_t off, void *dst, int len); /* read the save area (60 KB) */
|
||||
void plat_save_page (uint32_t off, const void *src, int len); /* write one 4 KB page (off 4 KB aligned; rest 0xFF) */
|
||||
#define plat_save_read(buf, len) plat_save_at (0, (buf), (len))
|
||||
void plat_fatal (const char *s);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,173 @@
|
||||
/* Paramix Wolf3D: the game is saved when leaving to the Paradise and can be continued at the next start.
|
||||
* Same contents as SaveTheGame / LoadTheGame in Wolf4SDL's wl_main.c (id Software), streamed in 4 KB pieces into
|
||||
* the save area of the flash instead of a file. A header tells this program's build and the pack apart, so an
|
||||
* old save after an update is not used. Author: mameise. GPL-2.0-or-later. */
|
||||
#include "wl_def.h"
|
||||
#include "pmx_plat.h"
|
||||
#include "pmx_ca.h"
|
||||
|
||||
extern statetype s_grdstand, s_player;
|
||||
#define SAVE_MAGIC 0x56533357u /* "W3SV" */
|
||||
#define SAVE_MAX 0xF000
|
||||
|
||||
typedef struct { uint32_t magic, build, pack_len, len, sum; } SaveHead;
|
||||
|
||||
static uint32_t build_tag (void)
|
||||
{
|
||||
return (uint32_t)(uintptr_t)&s_grdstand ^ ((uint32_t)(uintptr_t)&s_player << 7) ^ (uint32_t)sizeof (objtype) << 20
|
||||
^ (uint32_t)sizeof (statobj_t) << 26 ^ (uint32_t)sizeof (gamestate);
|
||||
}
|
||||
|
||||
/* ---- writing: a 4 KB page at a time ---- */
|
||||
static byte *wbuf; /* borrowed: the map unpacking buffer (pmx_ca.c), free while a level runs */
|
||||
static uint32_t wpos, wsum;
|
||||
static int werr;
|
||||
extern byte *pmx_ca_scratch (uint32_t *len);
|
||||
static void wflush (void)
|
||||
{
|
||||
uint32_t page = (wpos - 1) & ~0xFFFu, n = wpos - page;
|
||||
if (!werr) plat_save_page (page, wbuf, (int)n);
|
||||
}
|
||||
static void wr (const void *p, uint32_t n)
|
||||
{
|
||||
const byte *s = (const byte *)p;
|
||||
while (n--)
|
||||
{
|
||||
if (wpos >= SAVE_MAX) { werr = 1; return; }
|
||||
wsum = wsum * 31u + *s;
|
||||
wbuf[wpos & 0xFFFu] = *s++; wpos++;
|
||||
if (!(wpos & 0xFFFu)) wflush ();
|
||||
}
|
||||
}
|
||||
|
||||
int pmx_save_game (void)
|
||||
{
|
||||
uint32_t cap; wbuf = pmx_ca_scratch (&cap);
|
||||
if (cap < 0x1000u) return 0;
|
||||
wpos = sizeof (SaveHead); wsum = 0; werr = 0;
|
||||
memset (wbuf, 0xFF, sizeof (SaveHead));
|
||||
wr (&gamestate, sizeof gamestate);
|
||||
wr (LevelRatios, sizeof LevelRatios);
|
||||
wr (tilemap, sizeof tilemap);
|
||||
for (int i = 0; i < mapwidth; i++)
|
||||
for (int j = 0; j < mapheight; j++)
|
||||
{
|
||||
objtype *ob = actorat[i][j];
|
||||
word actnum = ISPOINTER (ob) ? (word)(0x8000 | (word)(ob - objlist)) : (word)(uintptr_t)ob;
|
||||
wr (&actnum, sizeof actnum);
|
||||
}
|
||||
wr (areaconnect, sizeof areaconnect);
|
||||
wr (areabyplayer, sizeof areabyplayer);
|
||||
objtype nullobj;
|
||||
for (objtype *ob = player; ob; ob = ob->next)
|
||||
{
|
||||
memcpy (&nullobj, ob, sizeof nullobj);
|
||||
if (ob == player) nullobj.state = (statetype *)((uintptr_t)nullobj.state - (uintptr_t)&s_player);
|
||||
else nullobj.state = (statetype *)((uintptr_t)nullobj.state - (uintptr_t)&s_grdstand);
|
||||
wr (&nullobj, sizeof nullobj);
|
||||
}
|
||||
nullobj.active = ac_badobject;
|
||||
wr (&nullobj, sizeof nullobj);
|
||||
word laststatobjnum = (word)(laststatobj - statobjlist);
|
||||
wr (&laststatobjnum, sizeof laststatobjnum);
|
||||
for (statobj_t *st = &statobjlist[0]; st < laststatobj; st++) wr (st, sizeof *st);
|
||||
for (doorobj_t *door = &doorobjlist[0]; door < lastdoorobj; door++) wr (door, sizeof *door);
|
||||
wr (&pwallstate, sizeof pwallstate); wr (&pwalltile, sizeof pwalltile); wr (&pwallx, sizeof pwallx);
|
||||
wr (&pwally, sizeof pwally); wr (&pwalldir, sizeof pwalldir); wr (&pwallpos, sizeof pwallpos);
|
||||
if (werr) return 0;
|
||||
uint32_t len = wpos;
|
||||
if (wpos & 0xFFFu) wflush ();
|
||||
/* the header last: a save cut short (power gone) stays invalid */
|
||||
SaveHead h = { SAVE_MAGIC, build_tag (), pmx_pack_len (), len, wsum };
|
||||
plat_save_read (wbuf, 0x1000);
|
||||
memcpy (wbuf, &h, sizeof h);
|
||||
plat_save_page (0, wbuf, (int)(len < 0x1000u ? len : 0x1000u));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ---- reading: straight from the flash ---- */
|
||||
static uint32_t rpos, rsum, rlen;
|
||||
static int rd (void *p, uint32_t n)
|
||||
{
|
||||
if (rpos + n > rlen) return 0;
|
||||
byte *d = (byte *)p;
|
||||
plat_save_at (rpos, d, (int)n);
|
||||
for (uint32_t i = 0; i < n; i++) rsum = rsum * 31u + d[i];
|
||||
rpos += n;
|
||||
return 1;
|
||||
}
|
||||
static int head_ok (SaveHead *h)
|
||||
{
|
||||
plat_save_at (0, h, sizeof *h);
|
||||
return h->magic == SAVE_MAGIC && h->build == build_tag () && h->pack_len == pmx_pack_len () && h->len > sizeof *h && h->len <= SAVE_MAX;
|
||||
}
|
||||
int pmx_save_present (void) { SaveHead h; return head_ok (&h); }
|
||||
void pmx_save_forget (void)
|
||||
{
|
||||
uint32_t cap; byte *b = pmx_ca_scratch (&cap);
|
||||
plat_save_read (b, 0x1000);
|
||||
memset (b, 0xFF, sizeof (SaveHead));
|
||||
plat_save_page (0, b, 0x1000);
|
||||
}
|
||||
|
||||
int pmx_load_game (void)
|
||||
{
|
||||
SaveHead h;
|
||||
if (!head_ok (&h)) return 0;
|
||||
/* the checksum over everything first, so a broken save does not leave a half loaded game */
|
||||
{ byte b[64]; rpos = sizeof h; rlen = h.len; rsum = 0;
|
||||
while (rpos < rlen) { uint32_t n = rlen - rpos < sizeof b ? rlen - rpos : sizeof b; rd (b, n); }
|
||||
if (rsum != h.sum) return 0; }
|
||||
rpos = sizeof h; rlen = h.len; rsum = 0;
|
||||
rd (&gamestate, sizeof gamestate);
|
||||
rd (LevelRatios, sizeof LevelRatios);
|
||||
SetupGameLevel ();
|
||||
rd (tilemap, sizeof tilemap);
|
||||
for (int i = 0; i < mapwidth; i++)
|
||||
for (int j = 0; j < mapheight; j++)
|
||||
{
|
||||
word actnum = 0; rd (&actnum, sizeof actnum);
|
||||
actorat[i][j] = (actnum & 0x8000) ? &objlist[actnum & 0x7fff] : (objtype *)(uintptr_t)actnum;
|
||||
}
|
||||
rd (areaconnect, sizeof areaconnect);
|
||||
rd (areabyplayer, sizeof areabyplayer);
|
||||
InitActorList ();
|
||||
objtype nullobj, *newobj;
|
||||
for (;;)
|
||||
{
|
||||
if (!rd (&nullobj, sizeof nullobj)) return 0;
|
||||
if (nullobj.active == ac_badobject) break;
|
||||
if (nullobj.obclass == playerobj) { newobj = player; nullobj.state = (statetype *)((uintptr_t)nullobj.state + (uintptr_t)&s_player); }
|
||||
else { newobj = GetNewActor (); nullobj.state = (statetype *)((uintptr_t)nullobj.state + (uintptr_t)&s_grdstand); }
|
||||
memcpy (newobj, &nullobj, sizeof nullobj - (sizeof nullobj.next + sizeof nullobj.prev));
|
||||
}
|
||||
word laststatobjnum = 0; rd (&laststatobjnum, sizeof laststatobjnum);
|
||||
if (laststatobjnum > MAXSTATS) return 0;
|
||||
laststatobj = &statobjlist[laststatobjnum];
|
||||
for (statobj_t *st = &statobjlist[0]; st < laststatobj; st++) rd (st, sizeof *st);
|
||||
for (doorobj_t *door = &doorobjlist[0]; door < lastdoorobj; door++) rd (door, sizeof *door);
|
||||
rd (&pwallstate, sizeof pwallstate); rd (&pwalltile, sizeof pwalltile); rd (&pwallx, sizeof pwallx);
|
||||
rd (&pwally, sizeof pwally); rd (&pwalldir, sizeof pwalldir); rd (&pwallpos, sizeof pwallpos);
|
||||
if (gamestate.secretcount)
|
||||
{
|
||||
word *map = mapsegs[0], tile;
|
||||
for (int y = 0; y < mapheight; y++)
|
||||
for (int x = 0; x < mapwidth; x++)
|
||||
{
|
||||
tile = *map;
|
||||
if (MAPSPOT (x, y, 1) == PUSHABLETILE && !tilemap[x][y] && !VALIDAREA (tile))
|
||||
{
|
||||
if (VALIDAREA (*(map + 1))) tile = *(map + 1);
|
||||
if (VALIDAREA (*(map - mapwidth))) tile = *(map - mapwidth);
|
||||
if (VALIDAREA (*(map + mapwidth))) tile = *(map + mapwidth);
|
||||
if (VALIDAREA (*(map - 1))) tile = *(map - 1);
|
||||
*map = tile;
|
||||
MAPSPOT (x, y, 1) = 0;
|
||||
}
|
||||
map++;
|
||||
}
|
||||
}
|
||||
Thrust (0, 0);
|
||||
lastgamemusicoffset = 0;
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/* Paramix Wolf3D: sound on the Paradise's buzzer. The game's PC speaker sounds are one tone at a time already:
|
||||
* one byte every 1/140 s, 0 = silence, else the PC timer divisor / 60 (frequency = 1193181 / (byte * 60) Hz).
|
||||
* pmx_sd_service() is called every millisecond (the Paradise's tick) or often (PC test).
|
||||
* Author: mameise. GPL-2.0-or-later. */
|
||||
#include "wl_def.h"
|
||||
#include "pmx_plat.h"
|
||||
#include "pmx_ca.h"
|
||||
|
||||
globalsoundpos channelSoundPos[1];
|
||||
boolean AdLibPresent, SoundBlasterPresent, SoundPositioned;
|
||||
byte SoundMode = sdm_PC, DigiMode = sds_Off, MusicMode = smm_Off;
|
||||
int pmx_sound_on = 1;
|
||||
|
||||
static volatile const byte *s_data;
|
||||
static volatile uint32_t s_len, s_start;
|
||||
static volatile int s_num, s_prio;
|
||||
static volatile uint32_t s_hz;
|
||||
|
||||
void SD_Startup (void) {}
|
||||
|
||||
boolean SD_PlaySound (int sound)
|
||||
{
|
||||
uint32_t len; int prio;
|
||||
if (!pmx_sound_on) return false;
|
||||
const byte *d = pmx_sound (sound, &len, &prio);
|
||||
if (!d || !len) return false;
|
||||
if (s_data && prio < s_prio) return false; /* a more important sound is playing */
|
||||
s_data = 0; /* the tick does not read while we change it */
|
||||
s_len = len; s_prio = prio; s_num = sound; s_start = plat_ms ();
|
||||
s_data = d;
|
||||
return true;
|
||||
}
|
||||
|
||||
void pmx_sd_service (uint32_t now)
|
||||
{
|
||||
const byte *d = (const byte *)s_data;
|
||||
uint32_t hz = 0;
|
||||
if (d)
|
||||
{
|
||||
uint32_t i = (now - s_start) * 140u / 1000u;
|
||||
if (i >= s_len) { s_data = 0; s_num = 0; }
|
||||
else { byte b = d[i]; hz = b ? 1193181u / ((uint32_t)b * 60u) : 0; }
|
||||
}
|
||||
if (hz != s_hz)
|
||||
{
|
||||
/* a new pitch always starts the buzzer anew (as in GBEmu test39: changing the running timer stays silent) */
|
||||
if (hz && s_hz) plat_tone (0);
|
||||
s_hz = hz; plat_tone (hz);
|
||||
}
|
||||
}
|
||||
|
||||
/* before writing the flash: nothing in the millisecond tick reads the flash any more */
|
||||
void pmx_sd_halt (void) { s_data = 0; s_num = 0; s_hz = 0; plat_tone (0); }
|
||||
void SD_StopSound (void)
|
||||
{
|
||||
s_data = 0; s_num = 0;
|
||||
#ifndef PMX_SD_IN_TICK
|
||||
pmx_sd_service (plat_ms ());
|
||||
#endif
|
||||
}
|
||||
word SD_SoundPlaying (void) { return s_data ? (word)s_num : 0; }
|
||||
void SD_WaitSoundDone (void) { uint32_t t0 = plat_ms (); while (s_data && plat_ms () - t0 < 3000u) { pmx_idle (); plat_wait (2); } }
|
||||
void SD_PositionSound (int leftvol, int rightvol) { (void)leftvol; (void)rightvol; }
|
||||
void SD_SetPosition (int channel, int leftvol, int rightvol) { (void)channel; (void)leftvol; (void)rightvol; }
|
||||
void SD_StopDigitized (void) {}
|
||||
|
||||
void Delay (int32_t wolfticks)
|
||||
{
|
||||
if (wolfticks > 0) SDL_Delay ((uint32_t)wolfticks * 100u / 7u);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/* generated by tools/gen_tables.c (BuildTables, CalcProjection of Wolf4SDL for a view 128 wide) */
|
||||
#define PMX_T_SCALE 87
|
||||
#define PMX_T_HEIGHTNUMERATOR 89088
|
||||
const int32_t finetangent[900] = {
|
||||
57,171,285,400,514,629,743,857,972,1086,
|
||||
1201,1315,1430,1544,1658,1773,1887,2002,2116,2231,
|
||||
2345,2460,2574,2689,2804,2918,3033,3147,3262,3377,
|
||||
3491,3606,3721,3836,3950,4065,4180,4295,4410,4525,
|
||||
4640,4755,4870,4985,5100,5215,5330,5445,5560,5676,
|
||||
5791,5906,6021,6137,6252,6368,6483,6599,6714,6830,
|
||||
6945,7061,7177,7293,7408,7524,7640,7756,7872,7988,
|
||||
8104,8221,8337,8453,8569,8686,8802,8919,9035,9152,
|
||||
9268,9385,9502,9619,9735,9852,9969,10086,10204,10321,
|
||||
10438,10555,10673,10790,10908,11025,11143,11261,11378,11496,
|
||||
11614,11732,11850,11968,12087,12205,12323,12442,12560,12679,
|
||||
12798,12917,13035,13154,13273,13393,13512,13631,13750,13870,
|
||||
13989,14109,14229,14349,14468,14588,14709,14829,14949,15069,
|
||||
15190,15311,15431,15552,15673,15794,15915,16036,16157,16279,
|
||||
16400,16522,16644,16765,16887,17009,17131,17254,17376,17499,
|
||||
17621,17744,17867,17990,18113,18236,18359,18483,18606,18730,
|
||||
18854,18977,19102,19226,19350,19474,19599,19724,19848,19973,
|
||||
20098,20224,20349,20474,20600,20726,20852,20978,21104,21230,
|
||||
21357,21483,21610,21737,21864,21991,22118,22246,22374,22501,
|
||||
22629,22757,22886,23014,23143,23271,23400,23529,23659,23788,
|
||||
23917,24047,24177,24307,24437,24568,24698,24829,24960,25091,
|
||||
25222,25353,25485,25617,25749,25881,26013,26146,26278,26411,
|
||||
26544,26678,26811,26945,27078,27212,27347,27481,27616,27750,
|
||||
27885,28021,28156,28292,28427,28563,28700,28836,28973,29110,
|
||||
29247,29384,29521,29659,29797,29935,30073,30212,30351,30490,
|
||||
30629,30769,30908,31048,31188,31329,31469,31610,31751,31893,
|
||||
32034,32176,32318,32461,32603,32746,32889,33032,33176,33320,
|
||||
33464,33608,33753,33898,34043,34188,34334,34480,34626,34772,
|
||||
34919,35066,35213,35361,35509,35657,35805,35954,36103,36252,
|
||||
36401,36551,36701,36852,37003,37154,37305,37456,37608,37761,
|
||||
37913,38066,38219,38372,38526,38680,38835,38989,39144,39300,
|
||||
39455,39611,39768,39924,40081,40239,40396,40554,40713,40871,
|
||||
41031,41190,41350,41510,41670,41831,41992,42154,42316,42478,
|
||||
42640,42803,42967,43131,43295,43459,43624,43789,43955,44121,
|
||||
44287,44454,44621,44789,44957,45125,45294,45463,45633,45803,
|
||||
45974,46144,46316,46487,46660,46832,47005,47179,47353,47527,
|
||||
47702,47877,48052,48229,48405,48582,48760,48938,49116,49295,
|
||||
49474,49654,49834,50015,50196,50378,50560,50743,50926,51110,
|
||||
51294,51479,51664,51850,52036,52223,52410,52598,52786,52975,
|
||||
53164,53354,53545,53736,53927,54119,54312,54505,54699,54893,
|
||||
55088,55284,55480,55676,55874,56072,56270,56469,56669,56869,
|
||||
57070,57271,57473,57676,57879,58083,58287,58493,58698,58905,
|
||||
59112,59320,59528,59737,59947,60157,60369,60580,60793,61006,
|
||||
61220,61434,61650,61866,62082,62300,62518,62737,62956,63176,
|
||||
63397,63619,63842,64065,64289,64514,64740,64966,65193,65421,
|
||||
65650,65880,66110,66341,66573,66806,67040,67274,67509,67746,
|
||||
67983,68221,68459,68699,68939,69181,69423,69666,69910,70155,
|
||||
70401,70648,70896,71145,71394,71645,71896,72149,72403,72657,
|
||||
72912,73169,73426,73685,73944,74205,74466,74729,74993,75257,
|
||||
75523,75790,76058,76327,76597,76868,77140,77414,77688,77964,
|
||||
78241,78519,78798,79078,79360,79643,79926,80212,80498,80785,
|
||||
81074,81364,81656,81948,82242,82537,82834,83132,83431,83731,
|
||||
84033,84336,84640,84946,85254,85562,85872,86184,86497,86811,
|
||||
87127,87444,87763,88083,88405,88728,89053,89379,89707,90037,
|
||||
90368,90700,91035,91371,91708,92047,92388,92731,93075,93421,
|
||||
93769,94118,94469,94822,95177,95533,95892,96252,96614,96978,
|
||||
97344,97711,98081,98453,98826,99202,99579,99959,100340,100724,
|
||||
101109,101497,101887,102279,102673,103069,103467,103868,104271,104676,
|
||||
105083,105493,105905,106319,106735,107154,107576,107999,108426,108854,
|
||||
109286,109719,110156,110594,111036,111480,111927,112376,112828,113283,
|
||||
113740,114201,114664,115130,115599,116070,116545,117022,117503,117987,
|
||||
118473,118963,119456,119952,120451,120953,121459,121968,122480,122996,
|
||||
123515,124037,124563,125092,125625,126162,126702,127246,127793,128344,
|
||||
128899,129458,130021,130587,131158,131732,132311,132893,133480,134071,
|
||||
134666,135266,135870,136478,137091,137708,138329,138956,139587,140222,
|
||||
140863,141508,142158,142813,143473,144138,144809,145484,146165,146851,
|
||||
147542,148239,148941,149649,150363,151082,151808,152539,153276,154019,
|
||||
154768,155523,156285,157053,157828,158609,159396,160191,160992,161800,
|
||||
162615,163437,164267,165103,165948,166799,167658,168525,169400,170282,
|
||||
171173,172072,172979,173894,174818,175751,176692,177643,178602,179570,
|
||||
180548,181536,182532,183539,184555,185582,186619,187666,188723,189792,
|
||||
190871,191961,193062,194175,195299,196435,197584,198744,199916,201101,
|
||||
202299,203510,204734,205971,207222,208487,209766,211060,212368,213691,
|
||||
215029,216383,217752,219137,220538,221956,223391,224843,226313,227800,
|
||||
229306,230830,232373,233935,235516,237118,238740,240383,242047,243732,
|
||||
245440,247170,248923,250699,252499,254324,256173,258048,259949,261876,
|
||||
263831,265813,267823,269862,271931,274030,276160,278321,280515,282741,
|
||||
285002,287297,289627,291994,294397,296839,299320,301840,304401,307005,
|
||||
309651,312341,315076,317858,320687,323564,326492,329471,332503,335589,
|
||||
338731,341930,345188,348506,351886,355330,358841,362418,366066,369785,
|
||||
373579,377448,381397,385426,389539,393738,398026,402406,406880,411453,
|
||||
416128,420906,425794,430793,435909,441144,446504,451993,457616,463378,
|
||||
469284,475339,481549,487921,494460,501174,508070,515155,522436,529924,
|
||||
537626,545551,553710,562114,570773,579699,588905,598404,608212,618342,
|
||||
628811,639637,650838,662434,674447,686899,699816,713223,727149,741625,
|
||||
756684,772363,788701,805739,823525,842108,861544,881893,903221,925600,
|
||||
949110,973839,999886,1027357,1056374,1087071,1119598,1154125,1190842,1229963,
|
||||
1271734,1316434,1364382,1415946,1471551,1531692,1596949,1668002,1745662,1830894,
|
||||
1924864,2028989,2145010,2275089,2421948,2589058,2780919,3003472,3264723,3575729,
|
||||
3952202,4417248,5006295,5776577,6826947,8344131,10728256,15019650,25032852,75098708,
|
||||
};
|
||||
const int32_t sintable[450] = {
|
||||
0,1143,2287,3429,4571,5711,6850,7986,9120,10252,
|
||||
11380,12504,13625,14742,15854,16961,18064,19160,20251,21336,
|
||||
22414,23486,24550,25606,26655,27696,28729,29752,30767,31772,
|
||||
32767,33753,34728,35693,36647,37589,38521,39440,40347,41243,
|
||||
42125,42995,43852,44695,45525,46340,47142,47930,48702,49460,
|
||||
50203,50931,51643,52339,53019,53683,54331,54963,55577,56175,
|
||||
56755,57319,57864,58393,58903,59395,59870,60326,60763,61183,
|
||||
61583,61965,62328,62672,62997,63302,63589,63856,64103,64331,
|
||||
64540,64729,64898,65047,65176,65286,65376,65446,65496,65526,
|
||||
65536,65526,65496,65446,65376,65286,65176,65047,64898,64729,
|
||||
64540,64331,64103,63856,63589,63302,62997,62672,62328,61965,
|
||||
61583,61183,60763,60326,59870,59395,58903,58393,57864,57319,
|
||||
56755,56175,55577,54963,54331,53683,53019,52339,51643,50931,
|
||||
50203,49460,48702,47930,47142,46340,45525,44695,43852,42995,
|
||||
42125,41243,40347,39440,38521,37589,36647,35693,34728,33753,
|
||||
32767,31772,30767,29752,28729,27696,26655,25606,24550,23486,
|
||||
22414,21336,20251,19160,18064,16961,15854,14742,13625,12504,
|
||||
11380,10252,9120,7986,6850,5711,4571,3429,2287,1143,
|
||||
0,-1143,-2287,-3429,-4571,-5711,-6850,-7986,-9120,-10252,
|
||||
-11380,-12504,-13625,-14742,-15854,-16961,-18064,-19160,-20251,-21336,
|
||||
-22414,-23486,-24550,-25606,-26655,-27696,-28729,-29752,-30767,-31772,
|
||||
-32767,-33753,-34728,-35693,-36647,-37589,-38521,-39440,-40347,-41243,
|
||||
-42125,-42995,-43852,-44695,-45525,-46340,-47142,-47930,-48702,-49460,
|
||||
-50203,-50931,-51643,-52339,-53019,-53683,-54331,-54963,-55577,-56175,
|
||||
-56755,-57319,-57864,-58393,-58903,-59395,-59870,-60326,-60763,-61183,
|
||||
-61583,-61965,-62328,-62672,-62997,-63302,-63589,-63856,-64103,-64331,
|
||||
-64540,-64729,-64898,-65047,-65176,-65286,-65376,-65446,-65496,-65526,
|
||||
-65536,-65526,-65496,-65446,-65376,-65286,-65176,-65047,-64898,-64729,
|
||||
-64540,-64331,-64103,-63856,-63589,-63302,-62997,-62672,-62328,-61965,
|
||||
-61583,-61183,-60763,-60326,-59870,-59395,-58903,-58393,-57864,-57319,
|
||||
-56755,-56175,-55577,-54963,-54331,-53683,-53019,-52339,-51643,-50931,
|
||||
-50203,-49460,-48702,-47930,-47142,-46340,-45525,-44695,-43852,-42995,
|
||||
-42125,-41243,-40347,-39440,-38521,-37589,-36647,-35693,-34728,-33753,
|
||||
-32767,-31772,-30767,-29752,-28729,-27696,-26655,-25606,-24550,-23486,
|
||||
-22414,-21336,-20251,-19160,-18064,-16961,-15854,-14742,-13625,-12504,
|
||||
-11380,-10252,-9120,-7986,-6850,-5711,-4571,-3429,-2287,-1143,
|
||||
0,1143,2287,3429,4571,5711,6850,7986,9120,10252,
|
||||
11380,12504,13625,14742,15854,16961,18064,19160,20251,21336,
|
||||
22414,23486,24550,25606,26655,27696,28729,29752,30767,31772,
|
||||
32767,33753,34728,35693,36647,37589,38521,39440,40347,41243,
|
||||
42125,42995,43852,44695,45525,46340,47142,47930,48702,49460,
|
||||
50203,50931,51643,52339,53019,53683,54331,54963,55577,56175,
|
||||
56755,57319,57864,58393,58903,59395,59870,60326,60763,61183,
|
||||
61583,61965,62328,62672,62997,63302,63589,63856,64103,64331,
|
||||
64540,64729,64898,65047,65176,65286,65376,65446,65496,65526,
|
||||
};
|
||||
static const short pmx_pixelangle[128] = {
|
||||
357,353,348,344,339,335,330,326,321,316,312,307,302,297,292,287,
|
||||
282,277,272,266,261,256,251,245,240,234,229,223,218,212,206,200,
|
||||
195,189,183,177,171,165,159,153,147,141,134,128,122,116,109,103,
|
||||
97,90,84,78,71,65,58,52,45,39,32,26,19,13,6,0,
|
||||
0,-6,-13,-19,-26,-32,-39,-45,-52,-58,-65,-71,-78,-84,-90,-97,
|
||||
-103,-109,-116,-122,-128,-134,-141,-147,-153,-159,-165,-171,-177,-183,-189,-195,
|
||||
-200,-206,-212,-218,-223,-229,-234,-240,-245,-251,-256,-261,-266,-272,-277,-282,
|
||||
-287,-292,-297,-302,-307,-312,-316,-321,-326,-330,-335,-339,-344,-348,-353,-357,
|
||||
};
|
||||
@@ -0,0 +1,235 @@
|
||||
/* Paramix Wolf3D: the screen. One 8-bit buffer of 128 x 128 (view 128 x 96 above, status bar 128 x 32 below),
|
||||
* sent to the display through a table of the current palette (RGB565).
|
||||
* Author: mameise. GPL-2.0-or-later. */
|
||||
#include "wl_def.h"
|
||||
#include "pmx_plat.h"
|
||||
#include "pmx_ca.h"
|
||||
#include "font.h"
|
||||
|
||||
#define RGB(r, g, b) {(r)*255/63, (g)*255/63, (b)*255/63, 0}
|
||||
SDL_Color gamepal[] = {
|
||||
#ifdef SPEAR
|
||||
#include "sodpal.inc"
|
||||
#else
|
||||
#include "wolfpal.inc"
|
||||
#endif
|
||||
};
|
||||
#undef RGB
|
||||
|
||||
static byte g_screen[128 * 128] __attribute__((aligned(4)));
|
||||
static SDL_Surface g_surf = { g_screen };
|
||||
SDL_Surface *screenBuffer = &g_surf;
|
||||
int16_t screenWidth = 128, screenHeight = 128;
|
||||
unsigned screenPitch = 128, bufferPitch = 128;
|
||||
int scaleFactor = 1;
|
||||
boolean screenfaded;
|
||||
unsigned bordercolor;
|
||||
static uint32_t g_ylookup[128];
|
||||
uint32_t *ylookup = g_ylookup;
|
||||
byte fontcolor, backcolor;
|
||||
int fontnumber;
|
||||
int px, py;
|
||||
static uint16_t g_lut[256];
|
||||
static SDL_Color g_curpal[256];
|
||||
|
||||
byte *pmx_screen (void) { return g_screen; }
|
||||
const uint16_t *pmx_lut (void) { return g_lut; }
|
||||
|
||||
void pmx_vl_init (void)
|
||||
{
|
||||
for (int i = 0; i < 128; i++) g_ylookup[i] = (uint32_t)i * 128u;
|
||||
VL_SetPalette (gamepal, true);
|
||||
}
|
||||
|
||||
int pmx_lut_changed;
|
||||
void VL_SetPalette (SDL_Color *palette, bool forceupdate)
|
||||
{
|
||||
(void)forceupdate;
|
||||
pmx_lut_changed = 1;
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
g_curpal[i] = palette[i];
|
||||
g_lut[i] = (uint16_t)((palette[i].r >> 3) << 11 | (palette[i].g >> 2) << 5 | (palette[i].b >> 3));
|
||||
}
|
||||
}
|
||||
|
||||
void pmx_palshift (int r, int g, int b, int i, int steps)
|
||||
{
|
||||
for (int j = 0; j < 256; j++)
|
||||
{
|
||||
const SDL_Color *p = &gamepal[j]; SDL_Color *o = &g_curpal[j];
|
||||
o->r = (uint8_t)(p->r + (r - p->r) * i / steps);
|
||||
o->g = (uint8_t)(p->g + (g - p->g) * i / steps);
|
||||
o->b = (uint8_t)(p->b + (b - p->b) * i / steps);
|
||||
g_lut[j] = (uint16_t)((o->r >> 3) << 11 | (o->g >> 2) << 5 | (o->b >> 3));
|
||||
}
|
||||
pmx_lut_changed = 1;
|
||||
}
|
||||
|
||||
/* fades in a few steps (each one a full picture) */
|
||||
#define FADE_STEPS 6
|
||||
void VL_FadeOut (int start, int end, int red, int green, int blue, int steps)
|
||||
{
|
||||
(void)steps;
|
||||
SDL_Color pal[256], from[256];
|
||||
memcpy (from, g_curpal, sizeof from);
|
||||
red = red * 255 / 63; green = green * 255 / 63; blue = blue * 255 / 63;
|
||||
for (int s = 1; s <= FADE_STEPS; s++)
|
||||
{
|
||||
memcpy (pal, from, sizeof pal);
|
||||
for (int i = start; i <= end; i++)
|
||||
{
|
||||
pal[i].r = (uint8_t)(from[i].r + (red - from[i].r) * s / FADE_STEPS);
|
||||
pal[i].g = (uint8_t)(from[i].g + (green - from[i].g) * s / FADE_STEPS);
|
||||
pal[i].b = (uint8_t)(from[i].b + (blue - from[i].b) * s / FADE_STEPS);
|
||||
}
|
||||
VL_SetPalette (pal, true);
|
||||
pmx_present ();
|
||||
SDL_Delay (20);
|
||||
}
|
||||
screenfaded = true;
|
||||
}
|
||||
void VL_FadeIn (int start, int end, SDL_Color *palette, int steps)
|
||||
{
|
||||
(void)steps;
|
||||
SDL_Color pal[256], from[256];
|
||||
memcpy (from, g_curpal, sizeof from);
|
||||
for (int s = 1; s <= FADE_STEPS; s++)
|
||||
{
|
||||
memcpy (pal, from, sizeof pal);
|
||||
for (int i = start; i <= end; i++)
|
||||
{
|
||||
pal[i].r = (uint8_t)(from[i].r + (palette[i].r - from[i].r) * s / FADE_STEPS);
|
||||
pal[i].g = (uint8_t)(from[i].g + (palette[i].g - from[i].g) * s / FADE_STEPS);
|
||||
pal[i].b = (uint8_t)(from[i].b + (palette[i].b - from[i].b) * s / FADE_STEPS);
|
||||
}
|
||||
VL_SetPalette (pal, true);
|
||||
pmx_present ();
|
||||
SDL_Delay (20);
|
||||
}
|
||||
VL_SetPalette (palette, true);
|
||||
screenfaded = false;
|
||||
}
|
||||
|
||||
byte *VL_LockSurface (SDL_Surface *surface) { return surface->pixels; }
|
||||
void VL_UnlockSurface (SDL_Surface *surface) { (void)surface; }
|
||||
|
||||
void VL_Bar (int x, int y, int w, int h, int color)
|
||||
{
|
||||
if (x < 0) { w += x; x = 0; }
|
||||
if (y < 0) { h += y; y = 0; }
|
||||
if (x + w > 128) w = 128 - x;
|
||||
if (y + h > 128) h = 128 - y;
|
||||
for (int j = 0; j < h; j++) memset (g_screen + (y + j) * 128 + x, color, (size_t)(w > 0 ? w : 0));
|
||||
}
|
||||
void VL_BarScaledCoord (int scx, int scy, int scwidth, int scheight, int color) { VL_Bar (scx, scy, scwidth, scheight, color); }
|
||||
void VWB_Bar (int x, int y, int width, int height, int color) { VL_Bar (x, y, width, height, color); }
|
||||
void VL_ClearScreen (int color) { memset (g_screen, color, sizeof g_screen); }
|
||||
|
||||
/* a pic of the pack, cut at the screen's edges; colour 255 is not transparent in Wolf3D pics */
|
||||
void pmx_drawpic (int x, int y, int k)
|
||||
{
|
||||
int w, h; const byte *p = pmx_pic (k, &w, &h);
|
||||
if (!p) return;
|
||||
for (int j = 0; j < h; j++)
|
||||
{
|
||||
int yy = y + j; if (yy < 0 || yy >= 128) continue;
|
||||
for (int i = 0; i < w; i++) { int xx = x + i; if (xx >= 0 && xx < 128) g_screen[yy * 128 + xx] = p[j * w + i]; }
|
||||
}
|
||||
}
|
||||
/* a pic shrunk to dw x dh (nearest dot) */
|
||||
void pmx_drawpic_scaled (int x, int y, int k, int dw, int dh)
|
||||
{
|
||||
int w, h; const byte *p = pmx_pic (k, &w, &h);
|
||||
if (!p || dw <= 0 || dh <= 0) return;
|
||||
for (int j = 0; j < dh; j++)
|
||||
{
|
||||
int yy = y + j; if (yy < 0 || yy >= 128) continue;
|
||||
const byte *row = p + (j * h / dh) * w;
|
||||
for (int i = 0; i < dw; i++) { int xx = x + i; if (xx >= 0 && xx < 128) g_screen[yy * 128 + xx] = row[i * w / dw]; }
|
||||
}
|
||||
}
|
||||
/* the game's chunk numbers (gfxv_wl6.h) to the pack's pics */
|
||||
int chunk_to_pk (int c)
|
||||
{
|
||||
#ifdef SPEAR /* 1.6.11 test2 Spear of Destiny: the pack keeps the order of Wolf3D, the faces of SOD come after */
|
||||
if (c >= L_COLONPIC && c <= L_BJWINSPIC) return c - L_COLONPIC;
|
||||
if (c >= KNIFEPIC && c <= GOTGATLINGPIC) return c - KNIFEPIC + PK_KNIFE;
|
||||
if (c >= GODMODEFACE1PIC && c <= BJOUCHPIC) return PK_SOD_GOD1 + c - GODMODEFACE1PIC;
|
||||
switch (c)
|
||||
{
|
||||
case STATUSBARPIC: return PK_STATUSBAR;
|
||||
case TITLE1PIC: return PK_TITLE;
|
||||
case PG13PIC: return PK_PG13;
|
||||
case CREDITSPIC: return PK_CREDITS;
|
||||
case HIGHSCORESPIC: return PK_HIGHSCORES;
|
||||
case PAUSEDPIC: return PK_PAUSED;
|
||||
case GETPSYCHEDPIC: return PK_GETPSYCHED;
|
||||
}
|
||||
return -1;
|
||||
#else
|
||||
return c - L_COLONPIC;
|
||||
#endif
|
||||
}
|
||||
void VWB_DrawPic (int x, int y, int chunknum) { pmx_drawpic (x * 128 / 320, y * 128 / 320, chunk_to_pk (chunknum)); }
|
||||
void VWB_DrawPicScaledCoord (int x, int y, int chunknum) { pmx_drawpic (x, y, chunk_to_pk (chunknum)); }
|
||||
|
||||
/* ---- text: 5 x 7 dots, 6 per letter ---- */
|
||||
void pmx_text (int x, int y, const char *s, int color)
|
||||
{
|
||||
for (; *s; s++, x += 6)
|
||||
{
|
||||
int c = (unsigned char)*s; if (c >= 'a' && c <= 'z') c -= 32;
|
||||
c = (c < 32 || c > 127) ? 0 : c - 32;
|
||||
for (int r = 0; r < 7; r++)
|
||||
{
|
||||
int yy = y + r; if (yy < 0 || yy >= 128) continue;
|
||||
unsigned bits = g_font[c][r];
|
||||
for (int k = 0; k < 5; k++) if ((bits & (0x10u >> k)) && x + k >= 0 && x + k < 128) g_screen[yy * 128 + x + k] = (byte)color;
|
||||
}
|
||||
}
|
||||
}
|
||||
void pmx_text_c (int y, const char *s, int color) { pmx_text ((128 - 6 * (int)strlen (s)) / 2 + 1, y, s, color); }
|
||||
|
||||
/* ---- the id print routines the game still uses (debug texts, messages) ---- */
|
||||
word PrintX, PrintY, WindowX, WindowY, WindowW, WindowH;
|
||||
void US_Print (const char *s)
|
||||
{
|
||||
char line[24]; int n = 0;
|
||||
for (;; s++)
|
||||
{
|
||||
if (*s == '\n' || !*s || n == 21)
|
||||
{
|
||||
line[n] = 0; pmx_text (PrintX, PrintY, line, fontcolor);
|
||||
if (!*s) { PrintX += 6 * n; break; }
|
||||
PrintY += 8; PrintX = WindowX; n = 0;
|
||||
if (*s != '\n') line[n++] = *s;
|
||||
continue;
|
||||
}
|
||||
line[n++] = *s;
|
||||
}
|
||||
}
|
||||
void US_PrintSigned (int32_t n) { char b[16]; snprintf (b, sizeof b, "%ld", (long)n); US_Print (b); }
|
||||
void US_PrintUnsigned (longword n) { char b[16]; snprintf (b, sizeof b, "%lu", (unsigned long)n); US_Print (b); }
|
||||
void US_CPrint (const char *s) { US_Print (s); }
|
||||
void US_DrawWindow (word x, word y, word w, word h)
|
||||
{
|
||||
WindowX = x; WindowY = y; WindowW = w; WindowH = h; PrintX = x; PrintY = y;
|
||||
VL_Bar (x, y, w, h, 0x7f);
|
||||
}
|
||||
void US_CenterWindow (word w, word h) { US_DrawWindow (4, 20, 120, 60); (void)w; (void)h; }
|
||||
|
||||
void VH_UpdateScreen (SDL_Surface *surface)
|
||||
{
|
||||
(void)surface;
|
||||
pmx_present ();
|
||||
}
|
||||
|
||||
boolean FizzleFade (SDL_Surface *source, int x1, int y1, unsigned width, unsigned height, unsigned frames, boolean abortable)
|
||||
{
|
||||
(void)source; (void)abortable;
|
||||
pmx_present ();
|
||||
SDL_Delay (frames * 1000u / 70u / 3u);
|
||||
(void)x1; (void)y1; (void)width; (void)height;
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
0, 8, 109, 220, 222, 241, 149, 107, 75, 248, 254, 140, 16, 66,
|
||||
74, 21, 211, 47, 80, 242, 154, 27, 205, 128, 161, 89, 77, 36,
|
||||
95, 110, 85, 48, 212, 140, 211, 249, 22, 79, 200, 50, 28, 188,
|
||||
52, 140, 202, 120, 68, 145, 62, 70, 184, 190, 91, 197, 152, 224,
|
||||
149, 104, 25, 178, 252, 182, 202, 182, 141, 197, 4, 81, 181, 242,
|
||||
145, 42, 39, 227, 156, 198, 225, 193, 219, 93, 122, 175, 249, 0,
|
||||
175, 143, 70, 239, 46, 246, 163, 53, 163, 109, 168, 135, 2, 235,
|
||||
25, 92, 20, 145, 138, 77, 69, 166, 78, 176, 173, 212, 166, 113,
|
||||
94, 161, 41, 50, 239, 49, 111, 164, 70, 60, 2, 37, 171, 75,
|
||||
136, 156, 11, 56, 42, 146, 138, 229, 73, 146, 77, 61, 98, 196,
|
||||
135, 106, 63, 197, 195, 86, 96, 203, 113, 101, 170, 247, 181, 113,
|
||||
80, 250, 108, 7, 255, 237, 129, 226, 79, 107, 112, 166, 103, 241,
|
||||
24, 223, 239, 120, 198, 58, 60, 82, 128, 3, 184, 66, 143, 224,
|
||||
145, 224, 81, 206, 163, 45, 63, 90, 168, 114, 59, 33, 159, 95,
|
||||
28, 139, 123, 98, 125, 196, 15, 70, 194, 253, 54, 14, 109, 226,
|
||||
71, 17, 161, 93, 186, 87, 244, 138, 20, 52, 123, 251, 26, 36,
|
||||
17, 46, 52, 231, 232, 76, 31, 221, 84, 37, 216, 165, 212, 106,
|
||||
197, 242, 98, 43, 39, 175, 254, 145, 190, 84, 118, 222, 187, 136,
|
||||
120, 163, 236, 249
|
||||
Reference in new issue
Block a user