Vendor raptor source files (was embedded gitlink)

Tree vendored at upstream 0019c5dd; origin + license recorded in
raptor/VENDOR.txt. Windows SDL dev packages excluded via .gitignore.
This commit is contained in:
raptorreplica committed 2026-08-25 22:08:42 +10:00
1 parent bd3ea30d55
commit f7c9b7a02d
809 files changed
+337824 -1

No files matched your search

+470
View File
@@ -0,0 +1,470 @@
#include <string.h>
#include "common.h"
#include "anims.h"
#include "gfxapi.h"
#include "glbapi.h"
#include "enemy.h"
#include "rap.h"
#include "tile.h"
#include "fileids.h"
#include "entypes.h"
#define MAX_ANIMLIB 25
#define MAX_ANIMS 100
ANIMS first_anims, last_anims, anims[MAX_ANIMS];
ANIMS *free_anims;
ANIMLIB animlib[MAX_ANIMLIB];
int curlib;
int adir[3] = {
0, -1, 1
};
/***************************************************************************
ANIMS_Clear () - Clears out All ANIM Objects
***************************************************************************/
void
ANIMS_Clear(
void
)
{
int loop;
first_anims.prev = NULL;
first_anims.next = &last_anims;
last_anims.prev = &first_anims;
last_anims.next = NULL;
free_anims = anims;
memset(anims, 0, sizeof(anims));
for (loop = 0; loop < MAX_ANIMS - 1; loop++)
anims[loop].next = &anims[loop + 1];
}
/*-------------------------------------------------------------------------*
ANIMS_Get () - Gets A Free ANIM from Link List
*-------------------------------------------------------------------------*/
ANIMS
*ANIMS_Get(
void
)
{
ANIMS *newa;
if (!free_anims)
return NULL;
newa = free_anims;
free_anims = free_anims->next;
memset(newa, 0, sizeof(ANIMS));
newa->next = &last_anims;
newa->prev = last_anims.prev;
last_anims.prev = newa;
newa->prev->next = newa;
return newa;
}
/*-------------------------------------------------------------------------*
ANIMS_Remove () Removes ANIM from Link List
*-------------------------------------------------------------------------*/
ANIMS
*ANIMS_Remove(
ANIMS *anim
)
{
ANIMS *next;
next = anim->prev;
anim->next->prev = anim->prev;
anim->prev->next = anim->next;
memset(anim, 0, sizeof(ANIMS));
anim->next = free_anims;
free_anims = anim;
return next;
}
/***************************************************************************
ANIMS_Register () - Register a ANIM for USE with this stuff
***************************************************************************/
int
ANIMS_Register(
int item, // INPUT : lumpnum of first frame
int numframes, // INPUT : number of frames
int groundflag, // INPUT : on the ground = TRUE
int playerflag, // INPUT : follow player movements
int transparent, // INPUT : Transparent ( LIGHT )
int adir // INPUT : Anim Direction
)
{
ANIMLIB*cur;
GFX_PIC *h;
int handle;
handle = curlib;
if (curlib >= MAX_ANIMLIB)
EXIT_Error("ANIMS_Register() - Max LIBs");
cur = &animlib[curlib];
curlib++;
cur->item = item;
cur->numframes = numframes;
cur->groundflag = groundflag;
cur->playerflag = playerflag;
cur->transparent = transparent;
cur->adir = adir;
h = (GFX_PIC*)GLB_LockItem(item);
cur->xoff = LE_LONG(h->width) >> 1;
cur->yoff = LE_LONG(h->height) >> 1;
GLB_FreeItem(item);
return handle;
}
/***************************************************************************
ANIMS_Init () Initializes ANIM Stuff
***************************************************************************/
void
ANIMS_Init(
void
)
{
ANIMS_Clear();
memset(animlib, 0, sizeof(animlib));
curlib = 0;
// GROUND EXPLOSIONS
ANIMS_Register(FILE164_GEXPLO_BLK, 0x2a, GROUND, 0, 0, A_NORM);
ANIMS_Register(FILE17d_BOOM_PIC, 0x23, GROUND, 0, 0, A_NORM);
ANIMS_Register(FILE1f5_SPLAT_BLK, 7, GROUND, 0, 0, A_NORM);
ANIMS_Register(FILE113_BIGSPLAT_BLK, 10, GROUND, 0, 0, A_NORM);
// AIR EXPLOSIONS
ANIMS_Register(FILE1e5_LGFLAK_BLK, 0xc, HIGH_AIR, 0, 0, A_NORM);
ANIMS_Register(FILE1d8_EXPLO2_BLK, 0xd, GROUND, 0, 0, A_NORM);
ANIMS_Register(FILE1fc_SMFLAK_BLK, 0xe, HIGH_AIR, 0, 0, A_NORM);
ANIMS_Register(FILE1a0_AIRBOOM_PIC, 0x10, HIGH_AIR, 0, 0, A_NORM);
ANIMS_Register(FILE1ae_NRGBANG_BLK, 0xc, HIGH_AIR, 0, 0, A_NORM);
ANIMS_Register(FILE129_LRBLST_BLK, 4, HIGH_AIR, 0, 0, A_NORM);
// MISC ANIMS
ANIMS_Register(FILE10a_SSMOKE_BLK, 9, MID_AIR, 0, 0, A_NORM);
ANIMS_Register(FILE10e_SSMOKE_BLK, 5, MID_AIR, 0, 1, A_MOVEDOWN);
ANIMS_Register(FILE12d_SMOKTRAL_BLK, 4, MID_AIR, 0, 1, A_MOVEUP);
ANIMS_Register(FILE18e_LGHTIN_BLK, 0xe, MID_AIR, 0, 0, A_NORM);
ANIMS_Register(FILE19c_BSPARK_BLK, 9, MID_AIR, 0, 0, A_NORM);
ANIMS_Register(FILE1a5_OSPARK_BLK, 9, MID_AIR, 0, 0, A_NORM);
ANIMS_Register(FILE1c7_GUNSTR_BLK, 4, MID_AIR, 1, 0, A_NORM);
// GROUND EXPLOSION OVERLAYS
ANIMS_Register(FILE152_FLARE_PIC, 0x1a, GROUND, 0, 0, A_NORM);
ANIMS_Register(FILE16c_SPARKLE_PIC, 0x11, GROUND, 0, 0, A_NORM);
// ENERGY GRAB
ANIMS_Register(FILE18e_LGHTIN_BLK, 0xe, HIGH_AIR, 0, 0, A_NORM);
// SUPER SHIELD
ANIMS_Register(FILE149_SHIPGLOW_BLK, 4, HIGH_AIR, 1, 1, A_NORM);
}
/***************************************************************************
ANIMS_CachePics() - Cache registered anim pics
***************************************************************************/
void
ANIMS_CachePics(
void
)
{
int loop;
unsigned int frames;
ANIMLIB *cur;
cur = animlib;
for (loop = 0; loop < curlib; loop++, cur++)
{
for (frames = 0; frames < (unsigned int)cur->numframes; frames++)
{
GLB_CacheItem(cur->item + frames);
}
}
}
/***************************************************************************
ANIMS_FreePics() - Free Up Anims Used
***************************************************************************/
void
ANIMS_FreePics(
void
)
{
int loop;
unsigned int frames;
ANIMLIB *cur;
cur = animlib;
for (loop = 0; loop < curlib; loop++, cur++)
{
for (frames = 0; frames < (unsigned int)cur->numframes; frames++)
{
GLB_FreeItem(cur->item + frames);
}
}
}
/***************************************************************************
ANIMS_StartAnim () - Start An ANIM Playing
***************************************************************************/
void
ANIMS_StartAnim(
int handle, // INPUT : ANIM handle
int x, // INPUT : x position
int y // INPUT : y position
)
{
ANIMLIB *lib;
ANIMS *cur;
lib = &animlib[handle];
cur = ANIMS_Get();
if (!cur)
return;
cur->lib = lib;
cur->x = x - lib->xoff;
cur->y = y - lib->yoff;
cur->groundflag = lib->groundflag;
}
/***************************************************************************
ANIMS_StartGAnim () - Start An ANIM Playing with groundflag == GROUND
***************************************************************************/
void
ANIMS_StartGAnim(
int handle, // INPUT : ANIM handle
int x, // INPUT : x position
int y // INPUT : y position
)
{
ANIMS *cur;
cur = ANIMS_Get();
if (!cur)
return;
cur->lib = &animlib[handle];
cur->x = x;
cur->y = y;
cur->groundflag = 0;
}
/***************************************************************************
ANIMS_StartEAnim () - Start An ANIM Playing locked onto ENEMY
***************************************************************************/
void
ANIMS_StartEAnim(
SPRITE_SHIP *en, // INPUT : pointer to ENEMY
int handle, // INPUT : ANIM handle
int x, // INPUT : x position
int y // INPUT : y position
)
{
ANIMLIB *lib;
ANIMS *cur;
lib = &animlib[handle];
cur = ANIMS_Get();
if (!cur)
return;
cur->en = en;
cur->lib = &animlib[handle];
cur->x = x - lib->xoff;
cur->y = y - lib->yoff;
cur->groundflag = HIGH_AIR;
}
/***************************************************************************
ANIMS_StartAAnim () - Start An ANIM Playing with groundflag == HIGH_AIR
***************************************************************************/
void
ANIMS_StartAAnim(
int handle, // INPUT : ANIM handle
int x, // INPUT : x position
int y // INPUT : y position
)
{
ANIMLIB *lib;
ANIMS *cur;
lib = &animlib[handle];
cur = ANIMS_Get();
if (!cur)
return;
cur->lib = &animlib[handle];
cur->x = x - lib->xoff;
cur->y = y - lib->yoff;
cur->groundflag = HIGH_AIR;
}
/***************************************************************************
ANIMS_Think () - Does all thinking for ANIMS
***************************************************************************/
void
ANIMS_Think(
void
)
{
ANIMS *cur;
ANIMLIB *lib;
for (cur = first_anims.next; &last_anims != cur; cur = cur->next)
{
lib = cur->lib;
if (cur->curframe >= lib->numframes)
{
cur = ANIMS_Remove(cur);
continue;
}
cur->item = lib->item + cur->curframe;
if (lib->playerflag)
{
cur->dx = player_cx + cur->x;
cur->dy = player_cy + cur->y;
}
else if (cur->en)
{
if (cur->en->item == -1)
cur->edone = 1;
if (!cur->edone)
{
cur->dx = cur->en->move.x + cur->x;
cur->dy = cur->en->move.y + cur->y;
}
}
else
{
cur->dx = cur->x;
cur->dy = cur->y;
}
switch (lib->adir)
{
case 0:
break;
case 2:
cur->y++;
break;
case 1:
cur->y--;
break;
}
cur->y += adir[lib->adir];
if ((lib->groundflag == GROUND) && (scroll_flag))
cur->y++;
cur->curframe++;
}
}
/***************************************************************************
ANIMS_DisplayGround () - Displays All Active ANIMS on the Ground
***************************************************************************/
void
ANIMS_DisplayGround(
void
)
{
ANIMS *cur;
char *pic;
for (cur = first_anims.next; &last_anims != cur; cur = cur->next)
{
if (cur->groundflag)
continue;
pic = (char*)GLB_GetItem(cur->item);
if (cur->lib->transparent)
GFX_ShadeShape(LIGHT, pic, cur->dx, cur->dy);
else
GFX_PutSprite(pic, cur->dx, cur->dy);
}
}
/***************************************************************************
ANIMS_DisplaySky () - Displays All Active ANIMS in SKY
***************************************************************************/
void
ANIMS_DisplaySky(
void
)
{
ANIMS *cur;
char *pic;
for (cur = first_anims.next; &last_anims != cur; cur = cur->next)
{
if (cur->groundflag != MID_AIR)
continue;
pic = (char*)GLB_GetItem(cur->item);
if (cur->lib->transparent)
GFX_ShadeShape(LIGHT, pic, cur->dx, cur->dy);
else
GFX_PutSprite(pic, cur->dx, cur->dy);
}
}
/***************************************************************************
ANIMS_DisplayHigh () - Displays All Active ANIMS in ABOVE PLAYER
***************************************************************************/
void
ANIMS_DisplayHigh(
void
)
{
ANIMS *cur;
char *pic;
for (cur = first_anims.next; &last_anims != cur; cur = cur->next)
{
if (cur->groundflag != HIGH_AIR)
continue;
pic = (char*)GLB_GetItem(cur->item);
if (cur->lib->transparent)
GFX_ShadeShape(LIGHT, pic, cur->dx, cur->dy);
else
GFX_PutSprite(pic, cur->dx, cur->dy);
}
}
+83
View File
@@ -0,0 +1,83 @@
#pragma once
#include "enemy.h"
typedef enum
{
A_NORM,
A_MOVEUP,
A_MOVEDOWN
}ANIM_DIR;
typedef enum
{
GROUND,
MID_AIR,
HIGH_AIR
}GFLAG;
typedef struct ANIMLIB_S
{
int item;
int numframes;
int groundflag;
int playerflag;
int transparent;
int adir;
int xoff;
int yoff;
}ANIMLIB;
typedef struct ANIMS_S
{
struct ANIMS_S *prev;
struct ANIMS_S *next;
int item;
int dx;
int dy;
int x;
int y;
int curframe;
ANIMLIB *lib;
int groundflag;
SPRITE_SHIP *en;
int edone;
}ANIMS;
#define A_LARGE_GROUND_EXPLO1 0
#define A_SMALL_GROUND_EXPLO 1
#define A_PERSON 2
#define A_PLATOON 3
#define A_LARGE_AIR_EXPLO 4
#define A_MED_AIR_EXPLO 5
#define A_SMALL_AIR_EXPLO 6
#define A_MED_AIR_EXPLO2 7
#define A_ENERGY_AIR_EXPLO 8
#define A_LASER_BLAST 9
#define A_SMALL_SMOKE 10
#define A_SMALL_SMOKE_DOWN 11
#define A_SMALL_SMOKE_UP 12
#define A_ENERGY_GRAB_HIT 13
#define A_BLUE_SPARK 14
#define A_ORANGE_SPARK 15
#define A_PLAYER_SHOOT 16
#define A_GROUND_FLARE 17
#define A_GROUND_SPARKLE 18
#define A_ENERGY_GRAB 19
#define A_SUPER_SHIELD 20
void ANIMS_Clear(void);
ANIMS *ANIMS_Remove(ANIMS *anim);
void ANIMS_Init(void);
void ANIMS_CachePics(void);
void ANIMS_FreePics(void);
void ANIMS_StartAnim(int handle, int x, int y);
void ANIMS_StartGAnim(int handle, int x, int y);
void ANIMS_StartEAnim(SPRITE_SHIP *en, int handle, int x, int y);
void ANIMS_StartAAnim(int handle, int x, int y);
void ANIMS_Think(void);
void ANIMS_DisplayGround(void);
void ANIMS_DisplaySky(void);
void ANIMS_DisplayHigh(void);
+279
View File
@@ -0,0 +1,279 @@
#include <string.h>
#include <stdlib.h>
#include "bonus.h"
#include "rap.h"
#include "gfxapi.h"
#include "glbapi.h"
#include "objects.h"
#include "fx.h"
#include "fileids.h"
#include "entypes.h"
BONUS bons[MAX_BONUS];
BONUS first_bonus, last_bonus;
BONUS *free_bonus;
static int energy_count;
static int glow[4];
static int glow_lx, glow_ly;
static int xpos[16] = {
-1, 0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2
};
static int ypos[16] = {
-3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2
};
/***************************************************************************
BONUS_Clear () - Clears out All bonuses
***************************************************************************/
void
BONUS_Clear(
void
)
{
int loop;
energy_count = 0;
first_bonus.prev = NULL;
first_bonus.next = &last_bonus;
last_bonus.prev = &first_bonus;
last_bonus.next = NULL;
free_bonus = bons;
memset(bons, 0, sizeof(bons));
for (loop = 0; loop < MAX_BONUS - 1; loop++)
bons[loop].next = &bons[loop + 1];
}
/*-------------------------------------------------------------------------*
BONUS_Get () - Gets A Free BONUS from Link List
*-------------------------------------------------------------------------*/
BONUS
*BONUS_Get(
void
)
{
BONUS *newb;
if (!free_bonus)
return NULL;
newb = free_bonus;
free_bonus = free_bonus->next;
memset(newb, 0, sizeof(BONUS));
newb->next = &last_bonus;
newb->prev = last_bonus.prev;
last_bonus.prev = newb;
newb->prev->next = newb;
return newb;
}
/*-------------------------------------------------------------------------*
BONUS_Remove () Removes BONUS from Link List
*-------------------------------------------------------------------------*/
BONUS
*BONUS_Remove(
BONUS *sh
)
{
BONUS *next;
if (sh->type == S_ITEMBUY6)
energy_count--;
next = sh->prev;
sh->next->prev = sh->prev;
sh->prev->next = sh->next;
memset(sh, 0, sizeof(BONUS));
sh->next = free_bonus;
free_bonus = sh;
return next;
}
/***************************************************************************
BONUS_Init () - Sets up Bonus stuff
***************************************************************************/
void
BONUS_Init(
void
)
{
int loop;
GFX_PIC *h;
for (loop = 0; loop < 4; loop++)
{
glow[loop] = FILE125_ICNGLW_BLK + loop;
}
h = (GFX_PIC*)GLB_CacheItem(FILE125_ICNGLW_BLK);
glow_lx = LE_LONG(h->width);
glow_ly = LE_LONG(h->height);
GLB_CacheItem(FILE126_ICNGLW_BLK);
GLB_CacheItem(FILE127_ICNGLW_BLK);
GLB_CacheItem(FILE128_ICNGLW_BLK);
BONUS_Clear();
}
/***************************************************************************
BONUS_Add () - Adds A BONUS to Game so player can Try to pick it up
***************************************************************************/
void
BONUS_Add(
int type, // INPUT : OBJECT TYPE
int x, // INPUT : X POSITION
int y // INPUT : Y POSITION
)
{
BONUS *cur;
if (type >= S_LAST_OBJECT)
return;
if (type == S_ITEMBUY6 && energy_count > MAX_MONEY)
return;
cur = BONUS_Get();
if (!cur)
return;
if (type == S_ITEMBUY6)
energy_count++;
cur->type = type;
cur->lib = OBJS_GetLib(type);
cur->curframe = 0;
cur->x = MAP_LEFT + x;
cur->y = y;
cur->pos = wrand() % 16;
}
/***************************************************************************
BONUS_Think () - Does all BONUS Thinking
***************************************************************************/
void
BONUS_Think(
void
)
{
int x, y, x2, y2;
BONUS *cur;
static int gcnt;
x = playerx;
y = playery;
x2 = playerx + PLAYERWIDTH;
y2 = playery + PLAYERHEIGHT;
for (cur = first_bonus.next; &last_bonus != cur; cur = cur->next)
{
cur->item = cur->lib->item + cur->curframe;
cur->bx = cur->x - (BONUS_WIDTH / 2) + xpos[cur->pos];
cur->by = cur->y - (BONUS_HEIGHT / 2) + ypos[cur->pos];
cur->gx = cur->x - (glow_lx>>1) + xpos[cur->pos];
cur->gy = cur->y - (glow_ly>>1) + ypos[cur->pos];
cur->y++;
if (gcnt & 1)
{
cur->pos++;
if (cur->pos >= 16)
cur->pos = 0;
cur->curframe++;
if (cur->curframe >= cur->lib->numframes)
cur->curframe = 0;
}
cur->curglow++;
if (cur->curglow >= 4)
cur->curglow = 0;
if (cur->x > x && cur->x < x2 && cur->y > y && cur->y < y2)
{
if (!cur->dflag && OBJS_GetAmt(S_ENERGY) > 0)
{
SND_Patch(FX_BONUS, 127);
if (cur->type == S_ENERGY)
OBJS_AddEnergy(MAX_SHIELD / 4);
else
OBJS_Add(cur->type);
if (cur->lib->moneyflag)
{
cur->dflag = 1;
cur->countdown = 50;
}
else
{
cur = BONUS_Remove(cur);
continue;
}
}
}
if (cur->dflag)
{
cur->countdown--;
if (cur->countdown <= 0)
{
cur = BONUS_Remove(cur);
continue;
}
}
if (cur->gy > 200)
{
cur = BONUS_Remove(cur);
continue;
}
}
gcnt++;
}
/***************************************************************************
BONUS_Display () - Displays Active Bonuses in game
***************************************************************************/
void
BONUS_Display(
void
)
{
BONUS *cur;
for (cur = first_bonus.next; &last_bonus != cur; cur = cur->next)
{
if (!cur->dflag)
{
GFX_PutSprite((char*)GLB_GetItem(cur->item), cur->bx, cur->by);
GFX_ShadeShape(LIGHT, (char*)GLB_GetItem(glow[cur->curglow]), cur->gx, cur->gy);
}
else
GFX_PutSprite((char*)GLB_GetItem(FILE10f_N$_PIC), cur->bx, cur->by);
}
}
+35
View File
@@ -0,0 +1,35 @@
#pragma once
#include "objects.h"
#define MAX_BONUS 12
#define BONUS_WIDTH 16
#define BONUS_HEIGHT 16
#define MAX_MONEY ( MAX_BONUS - 3 )
typedef struct BONUS_S
{
struct BONUS_S *prev; // LINK LIST PREV
struct BONUS_S *next; // LINK LIST NEXT
int item; // GLB item
int curframe; // CURRENT ANIM FRAME
int curglow; // CURRENT GLOW FRAME
int x; // X POSITION
int y; // Y POSITION
int bx; // BONUS X POSITION
int by; // BONUS Y POSITION
int gx; // GLOW X POSITION
int gy; // GLOW Y POSITION
int pos; // POS IN CIRCLE
int dflag; // DONEFLAG
int countdown; // COUNTDOWN TO REMOVE
int type; // OBJECT TYPE
OBJ_LIB *lib; // POINTER TO OBJECT LIBRARY
}BONUS;
void BONUS_Clear(void);
void BONUS_Think(void);
void BONUS_Display(void);
void BONUS_Init(void);
void BONUS_Add(int type, int x, int y);
+16
View File
@@ -0,0 +1,16 @@
#pragma once
typedef enum
{
M_NONE = 0,// 0
M_PC, // 1
M_ADLIB, // 2
M_GUS, // 3
M_PAS, // 4
M_SB, // 5
M_WAVE, // 6
M_CANVAS, // 7
M_GMIDI, // 8
M_AWE, // 9
M_LAST // 10
}SCARD;
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include <stdlib.h>
static inline void EXIT_Error(const char *a1, ...)
{
exit(0);
}
static inline void EXIT_Clean(void)
{
exit(0);
}
static inline void EXIT_Install(void (*a1)(int a1))
{
}
+333
View File
@@ -0,0 +1,333 @@
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "common.h"
#include "demo.h"
#include "rap.h"
#include "loadsave.h"
#include "objects.h"
#include "gfxapi.h"
#include "glbapi.h"
#include "fx.h"
#include "windows.h"
#include "intro.h"
#include "input.h"
#include "fileids.h"
#include "entypes.h"
#ifdef _MSC_VER
#include <windows.h>
#define PATH_MAX MAX_PATH
#endif
char demo_name[PATH_MAX];
int cur_play;
RECORD playback[MAX_DEMO + 1];
int max_play;
int demo_game;
int demo_wave;
/***************************************************************************
DEMO_MakePlayer() -
***************************************************************************/
void
DEMO_MakePlayer(
int game
)
{
memset(&plr, 0, sizeof(plr));
plr.sweapon = -1;
plr.diff[0] = DIFF_3;
plr.diff[1] = DIFF_3;
plr.diff[2] = DIFF_3;
plr.id_pic = 0;
RAP_SetPlayerDiff();
OBJS_Add(S_FORWARD_GUNS);
OBJS_Add(S_ENERGY);
OBJS_Add(S_ENERGY);
OBJS_Add(S_ENERGY);
OBJS_Add(S_ENERGY);
OBJS_Add(S_DETECT);
plr.score = 10000;
switch (game)
{
default:
case 0:
OBJS_Add(S_MICRO_MISSLE);
OBJS_Add(S_MEGA_BOMB);
OBJS_Add(S_MINI_GUN);
OBJS_Add(S_AIR_MISSLE);
OBJS_Add(S_TURRET);
OBJS_Add(S_DEATH_RAY);
break;
case 1:
OBJS_Add(S_MEGA_BOMB);
OBJS_Add(S_MEGA_BOMB);
OBJS_Add(S_MEGA_BOMB);
OBJS_Add(S_MEGA_BOMB);
OBJS_Add(S_SUPER_SHIELD);
OBJS_Add(S_PLASMA_GUNS);
OBJS_Add(S_MICRO_MISSLE);
OBJS_Add(S_TURRET);
OBJS_Add(S_GRD_MISSLE);
plr.score += 0x50003;
break;
case 2:
OBJS_Add(S_MEGA_BOMB);
OBJS_Add(S_MEGA_BOMB);
OBJS_Add(S_MEGA_BOMB);
OBJS_Add(S_MEGA_BOMB);
OBJS_Add(S_SUPER_SHIELD);
OBJS_Add(S_PLASMA_GUNS);
OBJS_Add(S_MICRO_MISSLE);
OBJS_Add(S_FORWARD_LASER);
OBJS_Add(S_GRD_MISSLE);
plr.score += 0xd5fff;
break;
}
OBJS_GetNext();
}
/***************************************************************************
DEMO_DisplayStats (
***************************************************************************/
void
DEMO_DisplayStats(
void
)
{
char temp[81];
if (demo_mode != DEMO_RECORD)
return;
sprintf(temp, "REC %d", MAX_DEMO - cur_play);
GFX_Print(MAP_LEFT + 5, 20, temp, (FONT*)GLB_GetItem(FILE104_FONT2_FNT), 84);
}
/***************************************************************************
DEMO_StartRec (
***************************************************************************/
void
DEMO_StartRec(
void
)
{
SND_Patch(FX_BONUS, 127);
memset(playback, 0, sizeof(playback));
demo_mode = DEMO_RECORD;
cur_play = 1;
}
/***************************************************************************
DEMO_StartPlayback (
***************************************************************************/
void
DEMO_StartPlayback(
void
)
{
demo_mode = DEMO_PLAYBACK;
cur_play = 1;
}
/***************************************************************************
DEMO_SetFileName ()
***************************************************************************/
void
DEMO_SetFileName(
const char *in_name
)
{
strcpy(demo_name, in_name);
}
/***************************************************************************
DEMO_GLBFile (
***************************************************************************/
void
DEMO_GLBFile(
int item
)
{
char *mem = GLB_GetItem(item);
int size = GLB_ItemSize(item);
if (!mem)
return;
memcpy(playback, mem, size);
cur_play = 1;
max_play = LE_SHORT(playback[0].playerpic);
demo_game = LE_SHORT(playback[0].px);
demo_wave = LE_SHORT(playback[0].py);
GLB_FreeItem(item);
}
/***************************************************************************
DEMO_LoadFile()
***************************************************************************/
void
DEMO_LoadFile(
void
)
{
int filesize;
filesize = GLB_ReadFile(demo_name, 0);
GLB_ReadFile(demo_name, (char*)playback);
cur_play = 1;
max_play = LE_SHORT(playback[0].playerpic);
demo_game = LE_SHORT(playback[0].px);
demo_wave = LE_SHORT(playback[0].py);
}
/***************************************************************************
DEMO_SaveFile (
***************************************************************************/
void
DEMO_SaveFile(
void
)
{
if (cur_play < 2)
return;
playback[0].px = LE_SHORT(cur_game);
playback[0].py = LE_SHORT(game_wave[cur_game]);
playback[0].playerpic = LE_SHORT(cur_play);
GLB_SaveFile(demo_name, (char*)playback, cur_play * sizeof(RECORD));
}
/***************************************************************************
DEMO_Play() - Demo playback routine
***************************************************************************/
int // TRUE=Aborted, FALSE = timeout
DEMO_Play(
void
)
{
int rval;
rval = 0;
DEMO_StartPlayback();
cur_game = demo_game;
game_wave[cur_game] = demo_wave;
DEMO_MakePlayer(demo_game);
switch (cur_game)
{
case 0:
default:
SND_PlaySong(songsg1[demo_wave], 1, 1);
break;
case 1:
SND_PlaySong(songsg2[demo_wave], 1, 1);
break;
case 2:
SND_PlaySong(songsg3[demo_wave], 1, 1);
break;
}
WIN_LoadComp();
RAP_LoadMap();
retraceflag = 0;
rval = Do_Game();
retraceflag = 1;
if (!rval)
{
if (OBJS_GetAmt(S_ENERGY) <= 0)
{
SND_PlaySong(FILE05d_RAP5_MUS, 1, 1);
INTRO_Death();
}
else
INTRO_Landing();
}
RAP_ClearPlayer();
demo_mode = DEMO_OFF;
return rval;
}
/***************************************************************************
DEMO_Think (
***************************************************************************/
int
DEMO_Think(
void
)
{
int rval;
rval = 0;
switch (demo_mode)
{
default:
case 0:
rval = 0;
break;
case DEMO_PLAYBACK:
buttons[0] = playback[cur_play].b1;
buttons[1] = playback[cur_play].b2;
buttons[2] = playback[cur_play].b3;
buttons[3] = playback[cur_play].b4;
playerx = LE_SHORT(playback[cur_play].px);
playery = LE_SHORT(playback[cur_play].py);
player_cx = playerx + 16;
player_cy = playery + 16;
playerpic = LE_SHORT(playback[cur_play].playerpic);
cur_play++;
if (cur_play > max_play)
{
demo_mode = DEMO_OFF;
rval = 1;
}
break;
case DEMO_RECORD:
playback[cur_play].b1 = buttons[0];
playback[cur_play].b2 = buttons[1];
playback[cur_play].b3 = buttons[2];
playback[cur_play].b4 = buttons[3];
playback[cur_play].px = LE_SHORT(playerx);
playback[cur_play].py = LE_SHORT(playery);
playback[cur_play].playerpic = LE_SHORT(playerpic);
cur_play++;
if (cur_play == MAX_DEMO)
{
SND_Patch(FX_BONUS, 127);
demo_mode = 0;
rval = 1;
}
break;
}
return rval;
}
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#pragma pack(push, 1)
#define DEMO_OFF 0
#define DEMO_RECORD 1
#define DEMO_PLAYBACK 2
#define MAX_DEMO 2800
typedef struct
{
char b1;
char b2;
char b3;
char b4;
short px;
short py;
short playerpic;
short fil;
}RECORD;
#pragma pack(pop)
void DEMO_MakePlayer(int game);
void DEMO_GLBFile(int item);
int DEMO_Play(void);
void DEMO_StartRec(void);
int DEMO_Think(void);
void DEMO_SaveFile(void);
void DEMO_SetFileName(const char *in_name);
void DEMO_LoadFile(void);
void DEMO_DisplayStats(void);
+415
View File
@@ -0,0 +1,415 @@
#include <stdint.h>
#include "common.h"
#include "dspapi.h"
#include "fx.h"
#include "entypes.h"
int dsp_init;
int dsp_freq;
int dsp_channelnum;
int dsp_cnt;
int dsp_rsmp;
int dsp_samp[2];
uint16_t pitchtable[256] = {
0x0040, 0x0040, 0x0041, 0x0042, 0x0042, 0x0043,
0x0044, 0x0045, 0x0045, 0x0046, 0x0047, 0x0048,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004C,
0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052,
0x0053, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D,
0x005E, 0x005F, 0x0060, 0x0061, 0x0062, 0x0063,
0x0064, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A,
0x006B, 0x006C, 0x006E, 0x006F, 0x0070, 0x0071,
0x0072, 0x0074, 0x0075, 0x0076, 0x0077, 0x0079,
0x007A, 0x007B, 0x007D, 0x007E, 0x0080, 0x0081,
0x0082, 0x0084, 0x0085, 0x0087, 0x0088, 0x008A,
0x008B, 0x008D, 0x008E, 0x0090, 0x0091, 0x0093,
0x0095, 0x0096, 0x0098, 0x0099, 0x009B, 0x009D,
0x009F, 0x00A0, 0x00A2, 0x00A4, 0x00A6, 0x00A7,
0x00A9, 0x00AB, 0x00AD, 0x00AF, 0x00B1, 0x00B3,
0x00B5, 0x00B7, 0x00B9, 0x00BB, 0x00BD, 0x00BF,
0x00C1, 0x00C3, 0x00C5, 0x00C7, 0x00C9, 0x00CB,
0x00CE, 0x00D0, 0x00D2, 0x00D5, 0x00D7, 0x00D9,
0x00DC, 0x00DE, 0x00E0, 0x00E3, 0x00E5, 0x00E8,
0x00EA, 0x00ED, 0x00EF, 0x00F2, 0x00F5, 0x00F7,
0x00FA, 0x00FD, 0x0100, 0x0102, 0x0105, 0x0108,
0x010B, 0x010E, 0x0111, 0x0114, 0x0117, 0x011A,
0x011D, 0x0120, 0x0123, 0x0126, 0x0129, 0x012D,
0x0130, 0x0133, 0x0137, 0x013A, 0x013D, 0x0141,
0x0144, 0x0148, 0x014C, 0x014F, 0x0153, 0x0157,
0x015A, 0x015E, 0x0162, 0x0166, 0x016A, 0x016E,
0x0172, 0x0176, 0x017A, 0x017E, 0x0182, 0x0186,
0x018A, 0x018F, 0x0193, 0x0197, 0x019C, 0x01A0,
0x01A5, 0x01A9, 0x01AE, 0x01B3, 0x01B8, 0x01BC,
0x01C1, 0x01C6, 0x01CB, 0x01D0, 0x01D5, 0x01DA,
0x01DF, 0x01E5, 0x01EA, 0x01EF, 0x01F5, 0x01FA,
0x0200, 0x0205, 0x020B, 0x0210, 0x0216, 0x021C,
0x0222, 0x0228, 0x022E, 0x0234, 0x023A, 0x0240,
0x0247, 0x024D, 0x0253, 0x025A, 0x0260, 0x0267,
0x026E, 0x0275, 0x027B, 0x0282, 0x0289, 0x0290,
0x0298, 0x029F, 0x02A6, 0x02AD, 0x02B5, 0x02BC,
0x02C4, 0x02CC, 0x02D4, 0x02DC, 0x02E3, 0x02EC,
0x02F4, 0x02FC, 0x0304, 0x030D, 0x0315, 0x031E,
0x0326, 0x032F, 0x0338, 0x0341, 0x034A, 0x0353,
0x035D, 0x0366, 0x036F, 0x0379, 0x0383, 0x038D,
0x0396, 0x03A0, 0x03AB, 0x03B5, 0x03BF, 0x03CA,
0x03D4, 0x03DF, 0x03EA, 0x03F5
};
uint8_t pantable[256] = {
0x0E, 0x13, 0x19, 0x1D, 0x22, 0x26, 0x2A, 0x2F, 0x33, 0x37, 0x3B, 0x3F,
0x41, 0x45, 0x49, 0x4C, 0x50, 0x53, 0x55, 0x59, 0x5C, 0x5E, 0x61, 0x65,
0x67, 0x6A, 0x6C, 0x6F, 0x71, 0x74, 0x75, 0x78, 0x7A, 0x7D, 0x7F, 0x80,
0x83, 0x85, 0x86, 0x89, 0x8B, 0x8C, 0x8E, 0x90, 0x92, 0x93, 0x95, 0x96,
0x99, 0x9A, 0x9C, 0x9D, 0x9E, 0xA0, 0xA2, 0xA3, 0xA5, 0xA6, 0xA7, 0xA9,
0xAA, 0xAB, 0xAC, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB5, 0xB6, 0xB7,
0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 0xC2, 0xC3,
0xC4, 0xC5, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCD,
0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD2, 0xD3, 0xD3, 0xD4, 0xD5, 0xD6,
0xD6, 0xD6, 0xD7, 0xD8, 0xD9, 0xD9, 0xD9, 0xDA, 0xDB, 0xDC, 0xDC, 0xDC,
0xDD, 0xDE, 0xDE, 0xDF, 0xDF, 0xE0, 0xE0, 0xE1, 0xE1, 0xE1, 0xE2, 0xE3,
0xE4, 0xE4, 0xE4, 0xE5, 0xE5, 0xE6, 0xE6, 0xE6, 0xE7, 0xE7, 0xE7, 0xE8,
0xE9, 0xE9, 0xE9, 0xE9, 0xEA, 0xEB, 0xEB, 0xEB, 0xEC, 0xEC, 0xEC, 0xEC,
0xED, 0xED, 0xED, 0xEE, 0xEE, 0xEF, 0xEF, 0xEF, 0xF0, 0xF0, 0xF0, 0xF0,
0xF1, 0xF1, 0xF1, 0xF2, 0xF2, 0xF2, 0xF2, 0xF3, 0xF3, 0xF3, 0xF3, 0xF4,
0xF4, 0xF4, 0xF5, 0xF5, 0xF5, 0xF5, 0xF6, 0xF6, 0xF6, 0xF6, 0xF7, 0xF7,
0xF7, 0xF7, 0xF7, 0xF7, 0xF8, 0xF8, 0xF8, 0xF8, 0xF9, 0xF9, 0xF9, 0xF9,
0xF9, 0xF9, 0xF9, 0xFA, 0xFA, 0xFA, 0xFA, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB,
0xFB, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFD, 0xFD, 0xFD, 0xFD,
0xFD, 0xFD, 0xFD, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
};
struct channel_t {
dsp_t *dsp;
char *data;
int handle;
int priority;
int samples;
// int phase;
int phase_inc;
int phase_sub;
int phase_sub_inc;
int voltable1[256];
int voltable2[256];
};
channel_t dsp_channels[8];
/***************************************************************************
DSP_Init() -
***************************************************************************/
void
DSP_Init(
int channels,
int freq
)
{
int i;
if (dsp_init)
return;
if (channels < 1)
channels = 1;
if (channels > 8)
channels = 0;
dsp_channelnum = channels;
dsp_freq = freq;
for (i = 0; i < dsp_channelnum; i++)
{
auto chan = &dsp_channels[i];
chan->samples = 0;
}
dsp_samp[0] = 0;
dsp_samp[1] = 0;
dsp_rsmp = 0;
dsp_init = 1;
}
/***************************************************************************
DSP_DeInit() -
***************************************************************************/
void
DSP_DeInit(
void
)
{
if (!dsp_init)
return;
dsp_init = 0;
}
/***************************************************************************
DSP_Mix() -
***************************************************************************/
void
DSP_Mix(
int16_t *buffer,
int len
)
{
channel_t *chan;
int i, l, r, j;
if (!dsp_init)
return;
for (i = 0; i < len; i++)
{
dsp_rsmp += dsp_freq;
while (dsp_rsmp >= fx_freq)
{
dsp_rsmp -= fx_freq;
l = 0;
r = 0;
for (j = 0; j < dsp_channelnum; j++)
{
chan = &dsp_channels[j];
if (chan->samples)
{
l += chan->voltable1[(uint8_t)*chan->data];
r += chan->voltable2[(uint8_t)*chan->data];
chan->phase_sub += chan->phase_sub_inc;
if (chan->phase_sub >= 256)
{
chan->phase_sub &= 255;
chan->data++;
}
chan->data += chan->phase_inc;
chan->samples--;
}
}
if (l < -128)
l = -128;
else if (l > 127)
l = 127;
if (r < -128)
r = -128;
else if (r > 127)
r = 127;
dsp_samp[0] = l * 128;
dsp_samp[1] = r * 128;
}
l = buffer[0] + dsp_samp[0];
r = buffer[1] + dsp_samp[1];
if (l < INT16_MIN)
l = INT16_MIN;
else if (l > INT16_MAX)
l = INT16_MAX;
if (r < INT16_MIN)
r = INT16_MIN;
else if (r > INT16_MAX)
r = INT16_MAX;
buffer[0] = l;
buffer[1] = r;
buffer += 2;
}
}
/***************************************************************************
DSP_PatchIsPlaying() -
***************************************************************************/
int
DSP_PatchIsPlaying(
int handle
)
{
int i, stat;
handle &= FXHAND_MASK;
stat = 0;
SND_Lock();
for (i = 0; i < dsp_channelnum; i++)
{
if (dsp_channels[i].samples && dsp_channels[i].handle == handle)
{
stat = 1;
break;
}
}
SND_Unlock();
return stat;
}
/***************************************************************************
DSP_VolTable() -
***************************************************************************/
void
DSP_VolTable(
int *table,
int vol
)
{
int val;
int step;
int sub_step;
int accm;
int i;
val = - (vol / 2);
step = vol >> 8;
sub_step = vol & 255;
accm = sub_step >> 1;
for (i = 0; i < 256; i++)
{
table[i] = val;
val += step;
accm += sub_step;
while (accm >= 256)
{
val++;
accm -= 256;
}
}
}
/***************************************************************************
DSP_StartPatch() -
***************************************************************************/
int
DSP_StartPatch(
dsp_t *dsp,
int sep,
int pitch,
int volume,
int priority
)
{
channel_t *chan = NULL;
int i, lowpriority, samples, best, step, lvol, rvol;
int handle = (dsp_cnt++) & FXHAND_MASK;
if (LE_SHORT(dsp->format) != 3 || LE_LONG(dsp->length) <= 32)
return -1;
SND_Lock();
for (i = 0; i < dsp_channelnum; i++)
{
if (!dsp_channels[i].samples)
{
chan = &dsp_channels[i];
break;
}
}
if (!chan) // No free channels
{
lowpriority = 0;
samples = INT32_MAX;
best = 0;
for (i = 0; i < dsp_channelnum; i++)
{
if (dsp_channels[i].priority > lowpriority)
{
lowpriority = dsp_channels[i].priority;
best = i;
}
else if (dsp_channels[i].priority == lowpriority
&& dsp_channels[i].samples < samples)
{
samples = dsp_channels[i].samples;
best = i;
}
}
if (lowpriority < priority || lowpriority == 0)
{
SND_Unlock();
return -1;
}
if (lowpriority == priority && dsp_channels[best].dsp != dsp)
{
for (i = 0; i < dsp_channelnum; i++)
{
if (dsp_channels[i].dsp == dsp)
{
best = i;
break;
}
}
}
chan = &dsp_channels[best];
}
samples = LE_LONG(dsp->length) - 32;
step = (pitchtable[pitch] * LE_SHORT(dsp->freq) + dsp_freq / 2) / dsp_freq; // .8
lvol = (pantable[255 - sep] * volume) / 127;
rvol = (pantable[sep] * volume) / 127;
DSP_VolTable(chan->voltable1, lvol);
DSP_VolTable(chan->voltable2, rvol);
chan->dsp = dsp;
chan->data = dsp->data + 16;
chan->phase_sub_inc = step & 255;
chan->phase_sub = chan->phase_sub_inc >> 1;
chan->phase_inc = step >> 8;
chan->priority = priority;
chan->handle = handle;
chan->samples = (samples << 8) / step;
SND_Unlock();
return handle | FXHAND_DSP;
}
/***************************************************************************
DSP_StopPatch() -
***************************************************************************/
void
DSP_StopPatch(
int handle
)
{
int i;
handle &= FXHAND_MASK;
SND_Lock();
for (i = 0; i < dsp_channelnum; i++)
{
if (dsp_channels[i].samples && dsp_channels[i].handle == handle)
{
dsp_channels[i].samples = 0;
break;
}
}
SND_Unlock();
}
+14
View File
@@ -0,0 +1,14 @@
#pragma once
struct dsp_t {
int16_t format;
int16_t freq;
int32_t length;
char data[1];
};
void DSP_Init(int channels, int freq);
void DSP_Mix(int16_t *buffer, int len);
int DSP_PatchIsPlaying(int handle);
int DSP_StartPatch(dsp_t* dsp, int sep, int pitch, int volume, int priority);
void DSP_StopPatch(int handle);
+1247
View File
File diff suppressed because it is too large. Load diff
+141
View File
@@ -0,0 +1,141 @@
#pragma once
#include "rap.h"
typedef enum
{
E_FORWARD,
E_BACKWARD
}EDIR;
typedef enum
{
KAMI_FLY,
KAMI_CHASE,
KAMI_END
}KAMI;
typedef enum
{
GANIM_DONE,
GANIM_OFF,
GANIM_ON
}GANIM;
typedef enum
{
MULTI_OFF,
MULTI_START,
MULTI_END
}MULTI;
typedef struct
{
char iname[16]; // ITEM NAME
int item; // * GLB ITEM #
int bonus; // BONUS # ( -1 == NONE )
int exptype; // EXPLOSION TYPE
int shootspace; // SLOWDOWN SPEED
int ground; //NOT USED IS ON GROUND
int suck; // CAN SUCK WEAPON AFFECT
int frame_rate; // FRAME RATE
int num_frames; // NUM FRAMES
int countdown; // COUNT DOWN TO START ANIM
int rewind; // FRAMES TO REWIND
int animtype; // FREE SPACE FOR LATER USE
int shadow; // USE SHADOW ( TRUE/FALSE )
int bossflag; // SHOULD THIS BE CONSIDERED A BOSS
int hits; // HIT POINTS
int money; // $$ AMOUNT WHEN KILLED
int shootstart; // SHOOT START OFFSET
int shootcnt; // HOW MANY TO SHOOT
int shootframe; // FRAME RATE TO SHOOT
int movespeed; // MOVEMENT SPEED
int numflight; // NUMBER OF FLIGHT POSITIONS
int repos; // REPEAT TO POSITION
int flighttype; // FLIGHT TYPE
int numguns; // NUMBER OF GUNS
int numengs; // NUMBER OF ENGINES
int sfx; //NOT USED SFX # TO PLAY
int song; // SONG # TO PLAY
short shoot_type[MAX_GUNS]; // ENEMY SHOOT TYPE
short engx[MAX_GUNS]; // X POS ENGINE FLAME
short engy[MAX_GUNS]; // Y POS ENGINE FLAME
short englx[MAX_GUNS]; // WIDTH OF ENGINE FLAME
short shootx[MAX_GUNS]; // X POS SHOOT FROM
short shooty[MAX_GUNS]; // Y POS SHOOT FROM
short flightx[MAX_FLIGHT]; // FLIGHT X POS
short flighty[MAX_FLIGHT]; // FLIGHT Y POS
}SPRITE;
typedef struct SPRITE_SHIP_S
{
struct SPRITE_SHIP_S *prev;
struct SPRITE_SHIP_S *next;
int item; // GLB item of current frame
SPRITE *lib; // SPRITE LIB POS
int sx; // START X
int sy; // START Y
int x; // CENTER X POS;
int y; // Y POS
int x2; // WIDTH
int y2; // HEIGHT
int width; // WIDTH
int height; // HEIGHT
int hlx; // WIDTH/2
int hly; // HEIGHT/2
int movepos; // CUR POSITION IN FLIGHT (X/Y)
int shootagain; // * COUNT DOWN TO SHOOT
int shootcount; // * COUNT TO SHOOT
int shootflag; // * COUNTER TO SPACE SHOTS
int hits; // *
int groundflag; // *
int doneflag;
MOVEOBJ move;
int countdown;
int curframe;
int eframe;
int num_frames;
int anim_on;
int edir;
int kami;
int frame_rate;
int shoot_on;
int shoot_disable;
int multi;
int speed;
int suckagain;
}SPRITE_SHIP;
#define E_NUM_DIFF 4
#define E_SECRET_1 0
#define E_SECRET_2 1
#define E_SECRET_3 2
#define E_EASY_LEVEL 3
#define E_MED_LEVEL 4
#define E_HARD_LEVEL 5
#define E_TRAIN_LEVEL 6
#define EB_SECRET_1 1
#define EB_SECRET_2 2
#define EB_SECRET_3 4
#define EB_EASY_LEVEL 8
#define EB_MED_LEVEL 16
#define EB_HARD_LEVEL 32
#define EB_NOT_USED 64
extern SPRITE_SHIP first_enemy, last_enemy;
void ENEMY_Clear(void);
void ENEMY_LoadLib(void);
void ENEMY_LoadSprites(void);
void ENEMY_FreeSprites(void);
SPRITE_SHIP *ENEMY_GetRandom(void);
SPRITE_SHIP *ENEMY_GetRandomAir(void);
SPRITE_SHIP *ENEMY_DamageEnergy(int x, int y, int damage);
int ENEMY_DamageAll(int x, int y, int damage);
int ENEMY_DamageGround(int x, int y, int damage);
int ENEMY_DamageAir(int x, int y, int damage);
int ENEMY_GetBaseDamage(void);
void ENEMY_Think(void);
void ENEMY_DisplayGround(void);
void ENEMY_DisplaySky(void);
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include "SDL_endian.h"
#define LE_USHORT(x) SDL_SwapLE16(x)
#define LE_SHORT(x) (signed short) SDL_SwapLE16(x)
#define LE_ULONG(x) SDL_SwapLE32(x)
#define LE_LONG(x) (signed int) SDL_SwapLE32(x)
+539
View File
@@ -0,0 +1,539 @@
#include <string.h>
#include "common.h"
#include "eshot.h"
#include "rap.h"
#include "gfxapi.h"
#include "glbapi.h"
#include "enemy.h"
#include "fx.h"
#include "shots.h"
#include "objects.h"
#include "anims.h"
#include "joyapi.h"
#include "input.h"
#include "fileids.h"
#include "entypes.h"
#define MAX_ESHOT 80
enum LIB_PIC
{
LIB_NORMAL,
LIB_ATPLAY,
LIB_MISSLE,
LIB_LASER,
LIB_MINES,
LIB_PLASMA,
LIB_COCO,
LIB_LASTPIC
};
int eshotnum, eshothigh;
ESHOT first_eshot, last_eshot;
ESHOT eshots[MAX_ESHOT];
ESHOT *free_eshot;
char *elaspow[4];
ESHOT_LIB plib[LIB_LASTPIC];
static int xpos[16] = {
-1, 0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2
};
static int ypos[16] = {
-3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2
};
static int monkeys[6] = {
FX_MON1, FX_MON2, FX_MON3, FX_MON4, FX_MON5, FX_MON6
};
/***************************************************************************
ESHOT_Clear () - Clears out ESHOT Linklist
***************************************************************************/
void
ESHOT_Clear(
void
)
{
int loop;
eshotnum = 0;
first_eshot.prev = NULL;
first_eshot.next = &last_eshot;
last_eshot.prev = &first_eshot;
last_eshot.next = NULL;
free_eshot = &eshots[0];
memset(eshots, 0, sizeof(eshots));
for (loop = 0; loop < MAX_ESHOT - 1; loop++)
eshots[loop].next = &eshots[loop + 1];
}
/*-------------------------------------------------------------------------*
ESHOT_Get () - gets a Free ESHOT OBJECT from linklist
*-------------------------------------------------------------------------*/
ESHOT
*ESHOT_Get(
void
)
{
ESHOT *newes;
if (!free_eshot)
return NULL;
eshotnum++;
if (eshothigh < eshotnum)
eshothigh = eshotnum;
newes = free_eshot;
free_eshot = free_eshot->next;
memset(newes, 0, sizeof(ESHOT));
newes->next = &last_eshot;
newes->prev = last_eshot.prev;
last_eshot.prev = newes;
newes->prev->next = newes;
return newes;
}
/*-------------------------------------------------------------------------*
ESHOT_Remove () - Removes SHOT OBJECT from linklist
*-------------------------------------------------------------------------*/
ESHOT
*ESHOT_Remove(
ESHOT *sh
)
{
ESHOT *next;
eshotnum--;
next = sh->prev;
sh->next->prev = sh->prev;
sh->prev->next = sh->next;
memset(sh, 0, sizeof(ESHOT));
sh->next = free_eshot;
free_eshot = sh;
return next;
}
/***************************************************************************
ESHOT_Init () - Inits ESHOT system and clears link list
***************************************************************************/
void
ESHOT_Init(
void
)
{
ESHOT_LIB *cur;
GFX_PIC *h;
int loop;
for (loop = 0; loop < 4; loop++)
elaspow[loop] = (char*)GLB_LockItem(FILE145_ELASEPOW_BLK + loop);
ESHOT_Clear();
memset(plib, 0, sizeof(plib));
cur = &plib[LIB_NORMAL];
cur->hits = 2;
cur->item = FILE1d6_ESHOT_BLK;
cur->num_frames = 2;
cur->smokeflag = 0;
cur->speed = 6;
for (loop = 0; loop < cur->num_frames; loop++)
cur->pic[loop] = (char*)GLB_LockItem(cur->item + loop);
h = (GFX_PIC*)cur->pic[0];
cur->xoff = LE_LONG(h->width) >> 1;
cur->yoff = LE_LONG(h->height) >> 1;
cur = &plib[LIB_ATPLAY];
cur->hits = 1;
cur->item = FILE1d6_ESHOT_BLK;
cur->num_frames = 2;
cur->smokeflag = 0;
cur->speed = 6;
for (loop = 0; loop < cur->num_frames; loop++)
cur->pic[loop] = (char*)GLB_LockItem(cur->item + loop);
h = (GFX_PIC*)cur->pic[0];
cur->xoff = LE_LONG(h->width) >> 1;
cur->yoff = LE_LONG(h->height) >> 1;
cur = &plib[LIB_MISSLE];
cur->hits = 4;
cur->item = FILE1d4_EMISLE_BLK;
cur->num_frames = 2;
cur->smokeflag = 1;
cur->speed = 10;
for (loop = 0; loop < cur->num_frames; loop++)
cur->pic[loop] = (char*)GLB_LockItem(cur->item + loop);
h = (GFX_PIC*) cur->pic[0];
cur->xoff = LE_LONG(h->width) >> 1;
cur->yoff = LE_LONG(h->height) >> 1;
cur = &plib[LIB_MINES];
cur->hits = 0x10;
cur->item = FILE1d1_MINE_BLK;
cur->num_frames = 2;
cur->smokeflag = 0;
cur->speed = 0;
for (loop = 0; loop < cur->num_frames; loop++)
cur->pic[loop] = (char*)GLB_LockItem(cur->item + loop);
h = (GFX_PIC*)cur->pic[0];
cur->xoff = LE_LONG(h->width) >> 1;
cur->yoff = LE_LONG(h->height) >> 1;
cur = &plib[LIB_LASER];
cur->hits = 0xc;
cur->item = FILE141_ELASER_BLK;
cur->num_frames = 4;
cur->smokeflag = 0;
cur->speed = 6;
for (loop = 0; loop < cur->num_frames; loop++)
cur->pic[loop] = (char*)GLB_LockItem(cur->item + loop);
h = (GFX_PIC*)cur->pic[0];
cur->xoff = LE_LONG(h->width) >> 1;
cur->yoff = LE_LONG(h->height) >> 1;
cur = &plib[LIB_PLASMA];
cur->hits = 0xf;
cur->item = FILE151_EPLASMA_PIC;
cur->num_frames = 1;
cur->smokeflag = 0;
cur->speed = 10;
for (loop = 0; loop < cur->num_frames; loop++)
cur->pic[loop] = (char*)GLB_LockItem(cur->item + loop);
h = (GFX_PIC*)cur->pic[0];
cur->xoff = LE_LONG(h->width) >> 1;
cur->yoff = LE_LONG(h->height) >> 1;
cur = &plib[LIB_COCO];
cur->hits = 1;
cur->item = FILE14d_COCONUT_PIC;
cur->num_frames = 4;
cur->smokeflag = 0;
cur->speed = 6;
for (loop = 0; loop < cur->num_frames; loop++)
cur->pic[loop] = (char*)GLB_LockItem(cur->item + loop);
h = (GFX_PIC*)cur->pic[0];
cur->xoff = LE_LONG(h->width) >> 1;
cur->yoff = LE_LONG(h->height) >> 1;
}
/***************************************************************************
ESHOT_Shoot() - Shoots ENEMY GUNS
***************************************************************************/
void
ESHOT_Shoot(
SPRITE_SHIP *enemy, // INPUT : pointer to Enemy stuff
int gun_num // INPUT : gun number to shoot
)
{
int x;
int y;
int g_shoot_type;
ESHOT *cur;
x = enemy->x + LE_SHORT(enemy->lib->shootx[gun_num]);
y = enemy->y + LE_SHORT(enemy->lib->shooty[gun_num]);
if (((x >= 0) && (x < 320)) && ((y >= 0) && (y < 200)))
{
cur = ESHOT_Get();
if (!cur)
return;
cur->move.x = x;
cur->move.y = y;
cur->en = enemy;
cur->gun_num = gun_num;
g_shoot_type = LE_SHORT(enemy->lib->shoot_type[gun_num]);
switch (g_shoot_type)
{
default:
EXIT_Error("ESHOT_Shoot() - Invalid EShot type");
break;
case ES_ATPLAYER:
SND_3DPatch(FX_ENEMYSHOT, x, y);
cur->lib = &plib[LIB_ATPLAY];
cur->move.x -= cur->lib->xoff;
cur->move.y -= cur->lib->yoff;
cur->move.x2 = player_cx;
cur->move.y2 = player_cy;
cur->speed = 1;
cur->type = ES_ATPLAYER;
break;
case ES_ATDOWN:
SND_3DPatch(FX_ENEMYSHOT, x, y);
cur->lib = &plib[LIB_NORMAL];
cur->move.x -= cur->lib->xoff;
cur->move.y -= cur->lib->yoff;
cur->move.x2 = cur->move.x;
cur->move.y2 = 200;
cur->speed = cur->lib->speed >> 1;
cur->type = ES_ATDOWN;
break;
case ES_ANGLELEFT:
SND_3DPatch(FX_ENEMYSHOT, x, y);
cur->lib = &plib[LIB_NORMAL];
cur->move.x -= cur->lib->xoff;
cur->move.y -= cur->lib->yoff;
cur->move.x2 = cur->move.x - 32;
cur->move.y2 = cur->move.y + 32;
cur->speed = cur->lib->speed >> 1;
cur->type = ES_ANGLELEFT;
break;
case ES_ANGLERIGHT:
SND_3DPatch(FX_ENEMYSHOT, x, y);
cur->lib = &plib[LIB_NORMAL];
cur->move.x -= cur->lib->xoff;
cur->move.y -= cur->lib->yoff;
cur->move.x2 = cur->move.x + 32;
cur->move.y2 = cur->move.y + 32;
cur->speed = cur->lib->speed >> 1;
cur->type = ES_ANGLERIGHT;
break;
case ES_MISSLE:
SND_3DPatch(FX_ENEMYMISSLE, x, y);
cur->lib = &plib[LIB_MISSLE];
cur->move.x -= cur->lib->xoff;
cur->move.x2 = cur->move.x;
cur->move.y2 = 200;
cur->speed = enemy->speed + 1;
cur->type = ES_MISSLE;
break;
case ES_LASER:
SND_3DPatch(FX_ENEMYLASER, x, y);
cur->lib = &plib[LIB_LASER];
cur->move.x -= cur->lib->xoff;
cur->move.x2 = cur->move.x;
cur->move.y2 = 200;
cur->speed = enemy->speed;
cur->type = ES_LASER;
break;
case ES_MINES:
SND_3DPatch(FX_ENEMYSHOT, x, y);
cur->lib = &plib[LIB_MINES];
cur->x = cur->move.x;
cur->y = cur->move.y;
cur->move.x2 = 320;
cur->move.y2 = 200;
cur->speed = 150;
cur->pos = wrand() % 16;
cur->type = ES_MINES;
break;
case ES_PLASMA:
SND_3DPatch(FX_ENEMYPLASMA, x, y);
cur->lib = &plib[LIB_PLASMA];
cur->move.x -= cur->lib->xoff;
cur->move.x2 = cur->move.x;
cur->move.y2 = 200;
cur->speed = 8;
cur->type = ES_PLASMA;
break;
case ES_COCONUTS:
SND_3DPatch(monkeys[wrand() % 6], x, y);
cur->lib = &plib[LIB_COCO];
cur->move.x -= cur->lib->xoff;
cur->move.y -= cur->lib->yoff;
cur->move.x2 = player_cx;
cur->move.y2 = player_cy;
cur->speed = 1;
cur->type = ES_COCONUTS;
break;
}
InitMobj(&cur->move);
MoveSobj(&cur->move, 1);
if (cur->move.x < 0 || cur->move.x >= 320)
cur->move.done = 1;
if (cur->move.y < 0 || cur->move.y >= 200)
cur->move.done = 1;
if (cur->move.done)
ESHOT_Remove(cur);
}
}
/***************************************************************************
ESHOT_Think () - Does All Thinking for shot system
***************************************************************************/
void
ESHOT_Think(
void
)
{
ESHOT *shot;
ESHOT_LIB *lib;
int dx, dy;
for (shot = first_eshot.next; shot!=&last_eshot; shot = shot->next)
{
lib = shot->lib;
shot->pic = lib->pic[shot->curframe];
shot->curframe++;
switch (shot->type)
{
case ES_LASER:
if (shot->en && shot->en->lib && shot->curframe < lib->num_frames)
{
shot->x = shot->en->x + LE_SHORT(shot->en->lib->shootx[shot->gun_num]) - 4;
shot->y = shot->en->y + LE_SHORT(shot->en->lib->shooty[shot->gun_num]);
shot->move.y2 = 200;
dx = abs(shot->x - player_cx);
if (dx < (PLAYERWIDTH / 2) && shot->y < player_cy)
{
shot->move.y2 = player_cy + (wrand() % 4) - 2;
OBJS_SubEnergy(lib->hits);
if ((haptic) && (control == 2))
{
IPT_CalJoyRumbleLow(); //Rumble when Laser eshot is hit
}
}
}
else
{
shot->doneflag = 1;
}
break;
default:
if (shot->curframe >= lib->num_frames)
shot->curframe = 0;
if (lib->speed)
{
shot->x = shot->move.x;
shot->y = shot->move.y;
MoveSobj(&shot->move, shot->speed);
if (shot->speed < lib->speed)
shot->speed++;
}
else
{
shot->speed--;
if (shot->speed)
{
shot->x = shot->move.x + xpos[shot->pos];
shot->y = shot->move.y + ypos[shot->pos];
shot->move.y++;
shot->pos++;
if (shot->pos >= 16)
shot->pos = 0;
}
else
{
shot->doneflag = 1;
ANIMS_StartAnim(A_SMALL_AIR_EXPLO, shot->x + 4, shot->y + 4);
}
}
if (shot->y >= 200 || shot->y < 0)
shot->doneflag = 1;
if (shot->x >= 320 || shot->x < 0)
shot->doneflag = 1;
dx = abs(shot->x - player_cx);
dy = abs(shot->y - player_cy);
if (dx < (PLAYERWIDTH / 2) && dy < (PLAYERWIDTH / 2))
{
ANIMS_StartAnim(A_SMALL_AIR_EXPLO, shot->x, shot->y);
shot->doneflag = 1;
OBJS_SubEnergy(lib->hits);
if ((haptic) && (control == 2))
{
IPT_CalJoyRumbleLow(); //Rumble when eshot is hit
}
}
break;
}
if (shot->doneflag)
{
shot = ESHOT_Remove(shot);
continue;
}
shot->cnt++;
if (lib->smokeflag && (shot->cnt & 1) != 0)
{
ANIMS_StartAAnim(A_SMALL_SMOKE_UP, shot->x + lib->xoff, shot->y);
}
}
}
/***************************************************************************
ESHOT_Display () - Displays All active Shots
***************************************************************************/
void
ESHOT_Display(
void
)
{
ESHOT *shot;
int loop, y;
GFX_PIC *h;
for (shot = first_eshot.next; shot !=&last_eshot; shot = shot->next)
{
if (shot->type == ES_LASER)
{
for (loop = shot->y; loop < shot->move.y2; loop += 3)
GFX_PutSprite(shot->pic, shot->x, loop);
GFX_PutSprite(elaspow[shot->curframe - 1], shot->x, shot->y);
h = (GFX_PIC*)lashit[shot->curframe - 1];
y = shot->move.y2 - 8;
if (y > 0 && y < 200)
{
GFX_PutSprite((char*)h, shot->x - (LE_LONG(h->width) >> 2), y);
}
}
else
GFX_PutSprite(shot->pic, shot->x, shot->y);
}
}
+54
View File
@@ -0,0 +1,54 @@
#pragma once
#include "rap.h"
#include "enemy.h"
#include "gfxapi.h"
typedef enum
{
ES_ATPLAYER, // 0
ES_ATDOWN, // 1
ES_ANGLELEFT, // 2
ES_ANGLERIGHT, // 3
ES_MISSLE, // 4
ES_LASER, // 5
ES_MINES, // 6
ES_PLASMA, // 7
ES_COCONUTS // 8
}ESHOT_TYPE;
typedef struct
{
int item; // BASE ITEM NUMBER
char *pic[10]; // POINTER TO PICS
int num_frames; // NUMBER OF FRAMES
int smokeflag; // TRUE = SMOKETRAIL
int speed; // SPEED OF SHOT
int xoff; // X CENTER OFFSET
int yoff; // Y CENTER OFFSET
int hits; // HIT POINT DAMAGE TO PLAYER
}ESHOT_LIB;
typedef struct ESHOT_S
{
struct ESHOT_S *prev; // LINK LIST PREV
struct ESHOT_S *next; // LINK LIST NEXT
char *pic; // POINTER TO CUR FRAME PIC
int curframe; // CURRENT ANIM FRAME
int x; // CUR SHOT CENTER X
int y; // CUR SHOT CENTER Y
MOVEOBJ move; // MOVE STUFF
int doneflag; // SHOT DONE = TRUE
ESHOT_LIB *lib; // POINTER TO LIB
int cnt;
int speed;
int pos;
int type;
SPRITE_SHIP *en;
int gun_num;
}ESHOT;
void ESHOT_Shoot(SPRITE_SHIP *enemy, int gun_num);
void ESHOT_Clear(void);
void ESHOT_Think(void);
void ESHOT_Display(void);
void ESHOT_Init(void);
+1733
View File
File diff suppressed because it is too large. Load diff
+141
View File
@@ -0,0 +1,141 @@
#include <stdint.h>
#include "common.h"
#include "flame.h"
#include "rap.h"
#include "gfxapi.h"
#include "windows.h"
#define MAX_SHADES 8
char stmem[MAX_SHADES * 512];
static char *_stable[MAX_SHADES];
/***************************************************************************
FLAME_Init () - Inits Flame Tables and stuff
***************************************************************************/
void
FLAME_Init(
void
)
{
int loop;
for (loop = 0; loop < MAX_SHADES; loop++)
{
_stable[loop] = &stmem[loop * 512];
_stable[loop] = (char*)(((intptr_t)_stable[loop] + 255) & ~255);
GFX_MakeLightTable(palette, _stable[loop], (MAX_SHADES - loop) * 2);
}
}
/***************************************************************************
FLAME_InitShades () - Inits shading stuff
***************************************************************************/
void
FLAME_InitShades(
void
)
{
int loop;
for (loop = 0; loop < MAX_SHADES; loop++)
{
GFX_MakeLightTable(palette, _stable[loop], (MAX_SHADES - loop) * 2);
}
}
/***************************************************************************
FLAME_Up () - Shows Flame shooting upward
***************************************************************************/
void
FLAME_Up(
int ix, // INPUT : x position
int iy, // INPUT : y position
int width, // INPUT : width of shade
int frame // INPUT : frame
)
{
char *outbuf;
int y, addx, loop, num;
unsigned int curs;
int height[2] = {
5, 10
};
if (opt_detail < 1)
return;
frame = frame % 2;
iy -= height[frame] - 1;
if (!GFX_ClipLines(0, &ix, &iy, &width, &height[frame]))
return;
y = iy;
addx = (MAX_SHADES << 16) / height[frame];
curs = addx * (height[frame] - 1);
for (loop = 0; loop < height[frame]; loop++)
{
outbuf = displaybuffer + ix + ylookup[y];
y++;
num = curs >> 16;
if (num >= 8)
EXIT_Error("flame > 8 %u", curs >> 16);
if (num < 0)
EXIT_Error("flame < 0");
GFX_Shade(outbuf, width, _stable[num]);
curs -= addx;
}
}
/***************************************************************************
FLAME_Down () - Shows Flame shooting downward
***************************************************************************/
void
FLAME_Down(
int ix, // INPUT : x position
int iy, // INPUT : y position
int width, // INPUT : width of shade
int frame // INPUT : frame
)
{
char *outbuf;
int y, loop, addx;
unsigned int curs;
int height[2] = {
8, 12
};
frame = frame % 2;
if (!GFX_ClipLines(0, &ix, &iy, &width, &height[frame]))
return;
y = iy;
curs = 0;
addx = (MAX_SHADES << 16) / height[frame];
for (loop = 0; loop < height[frame]; loop++)
{
outbuf = displaybuffer + ix + ylookup[y];
y++;
GFX_Shade(outbuf, width, _stable[curs >> 16]);
curs += addx;
}
}
+6
View File
@@ -0,0 +1,6 @@
#pragma once
void FLAME_Init(void);
void FLAME_InitShades(void);
void FLAME_Up(int ix, int iy, int width, int frame);
void FLAME_Down(int ix, int iy, int width, int frame);
+1127
View File
File diff suppressed because it is too large. Load diff
+89
View File
@@ -0,0 +1,89 @@
#pragma once
#define SND_CLOSE 40
#define SND_FAR 500
enum
{
FXHAND_PCS = 0x0000,
FXHAND_GSS1 = 0x4000,
// FXHAND_GSS2 = 0x8000,
FXHAND_DSP = 0xc000,
FXHAND_MASK = 0x3fff,
FXHAND_TMASK = 0xc000,
};
typedef enum
{
SND_NONE,
SND_PC,
SND_MIDI,
SND_CANVAS,
SND_DIGITAL
}SND_TYPE;
typedef enum
{
FX_THEME,
FX_MON1,
FX_MON2,
FX_MON3,
FX_MON4,
FX_MON5,
FX_MON6,
FX_DAVE,
FX_AIREXPLO,
FX_AIREXPLO2,
FX_BONUS,
FX_CRASH,
FX_DOOR,
FX_FLYBY,
FX_EGRAB,
FX_GEXPLO,
FX_GUN,
FX_JETSND,
FX_LASER,
FX_MISSLE,
FX_SWEP,
FX_TURRET,
FX_WARNING,
FX_BOSS1,
FX_IJETSND,
FX_EJETSND,
FX_INTROHIT,
FX_INTROGUN,
FX_ENEMYSHOT,
FX_ENEMYLASER,
FX_ENEMYMISSLE,
FX_ENEMYPLASMA,
FX_SHIT,
FX_HIT,
FX_NOSHOOT,
FX_PULSE,
FX_LAST_SND
}DEFX;
extern int music_volume;
extern int fx_volume;
extern int dig_flag;
extern int fx_freq;
extern int fx_gus;
extern int sys_midi, winmm_mpu_device, core_dls_synth, core_midi_port, alsaclient, alsaport;
int SND_InitSound(void);
void SND_DeInit(void);
void SND_Setup(void);
void SND_PlaySong(int item, int chainflag, int fadeflag);
int SND_IsSongPlaying(void);
void SND_Lock(void);
void SND_Unlock(void);
void SND_FadeOutSong(void);
void SND_FreeFX(void);
void SND_CacheFX(void);
void SND_CacheGFX(void);
void SND_CacheIFX(void);
void SND_3DPatch(int type, int x, int y);
void SND_Patch(int type, int xpos);
int SND_IsPatchPlaying(int type);
void SND_StopPatch(int type);
void SND_StopPatches(void);
File diff suppressed because it is too large. Load diff
+125
View File
@@ -0,0 +1,125 @@
#pragma once
#define G3D_DIST 200
#define GFX_DARK 0
#define GFX_LITE 1
#define SCREENWIDTH 320
#define SCREENHEIGHT 200
typedef enum
{
UPPER_LEFT,
UPPER_RIGHT,
LOWER_LEFT,
LOWER_RIGHT
}CORNER;
typedef enum
{
DARK,
LIGHT,
GREY
}SHADE;
typedef enum
{
GSPRITE,
GPIC
}GFX_TYPE;
#define CLIP_XRIGHT 2
#define CLIP_XLEFT 4
#define CLIP_YTOP 8
#define CLIP_YBOTTOM 16
typedef struct
{
GFX_TYPE type; // type of picture
int opt1; // option 1
int opt2; // option 2
int width; // width of pic
int height; // heigth of pic
}GFX_PIC;
typedef struct
{
int x; // X POS OF SEG
int y; // Y POS OF SEG
int offset; // OFFSET FROM X, Y
int length; // LENGTH OF LINE
}GFX_SPRITE;
typedef struct
{
int height;
short charofs[256];
char width[256];
}FONT;
extern char *displaybuffer;
extern char *displayscreen;
extern int ud_x, ud_y, ud_lx, ud_ly;
extern int o_ud_x, o_ud_y, o_ud_lx, o_ud_ly;
extern int update_start;
extern char *gfx_inmem;
extern int gfx_xp, gfx_yp;
extern int gfx_lx, gfx_ly;
extern int gfx_imga;
extern int framecount;
extern int tablelen;
extern int stable[324];
extern char *ltable, *dtable, *gtable;
extern int ylookup[200];
extern int retraceflag;
extern int G3D_viewx, G3D_viewy, G3D_viewz;
extern int G3D_x, G3D_y, G3D_z, G3D_screenx, G3D_screeny;
void GFX_UpdateTimer(void);
void GFX_InitSystem(void);
void GFX_InitVideo(char *curpal);
int GFX_GetFrameCount(void);
int GFX_ClipLines(char **image, int *x, int *y, int *lx, int *ly);
void GFX_SetPalette(char *curpal, int startpal);
void GFX_FadeOut(int red, int green, int blue, int speed);
void GFX_FadeIn(char *palette, int steps);
void GFX_FadeStart(void);
void GFX_FadeFrame(char *palette, int cur_step, int steps);
void GFX_SetPalRange(int start, int end);
void GFX_MakeLightTable(char *palette, char *ltable, int level);
void GFX_MakeGreyTable(char *palette, char *ltable);
void GFX_GetScreen(char *outmem, int x, int y, int lx, int ly);
void GFX_PutTexture(char *intxt, int x, int y, int lx, int ly);
void GFX_ShadeArea(int opt, int x, int y, int lx, int ly);
void GFX_ShadeShape(int opt, char* mask, int x, int y);
void GFX_VShadeLine(int opt, int x, int y, int ly);
void GFX_HShadeLine(int opt, int x, int y, int lx);
void GFX_LightBox(int opt, int x, int y, int lx, int ly);
void GFX_ColorBox(int x, int y, int lx, int ly, int color);
void GFX_HLine(int x, int y, int lx, int color);
void GFX_VLine(int x, int y, int ly, int color);
void GFX_Line(int x, int y, int x2, int y2, int color);
void GFX_ScalePic(char *buffin, int x, int y, int new_lx, int new_ly, int see_thru);
void GFX_DisplayUpdate(void);
void GFX_PutImage(char *image, int x, int y, int see_thru);
void GFX_PutSprite(char *inmem, int x, int y);
void GFX_MarkUpdate(int x, int y, int lx, int ly);
void GFX_ForceUpdate(int x, int y, int lx, int ly);
void GFX_SetFrameHook(void (*func)(void (*)(void)));
void GFX_WaitUpdate(int count);
void GFX_DisplayScreen(void);
void GFX_DrawSprite(char *dest, char *inmem);
void GFX_DrawChar(char *dest, char *inmem, int width, int height, int addx, int color);
void GFX_Shade(char *outmem, int maxlen, char *dtable);
void GFX_PutPic(void);
void GFX_PutMaskPic(void);
int GFX_StrPixelLen(FONT* infont, char *instr, int maxloop);
int GFX_Print(int printx, int printy, char *str, FONT* infont, int basecolor);
void GFX_ShadeSprite(char *dest, char *inmem, char *dtable);
void GFX_ScaleLine(char *outmem, char *inmem);
void GFX_CScaleLine(char *outmem, char *inmem);
void GFX_3D_SetView(int x, int y, int z);
void GFX_3DPoint(void);
+216
View File
@@ -0,0 +1,216 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "common.h"
#include "gfxapi.h"
#include "entypes.h"
/*==========================================================================
GFX_ScaleLine() - Does the scale from scale table ( _stable )
==========================================================================*/
void
GFX_ScaleLine(
char *outmem,
char *inmem
)
{
int loop;
for (loop = tablelen - 1; loop >= 0; loop--)
{
*outmem = *(inmem + stable[loop]);
outmem++;
}
}
/*==========================================================================
GFX_CScaleLine() - scale from scale table (_stable) color 0 transparent
==========================================================================*/
void
GFX_CScaleLine(
char *outmem,
char *inmem
)
{
int loop;
for (loop = tablelen - 1; loop >= 0; loop--)
{
char px = *(inmem + stable[loop]);
if (px)
*outmem = px;
outmem++;
}
}
/*==========================================================================
GFX_DisplayScreen() - Puts Display Buffer into Video memory
==========================================================================*/
void
GFX_DisplayScreen(
void
)
{
int loop;
char *src = &displaybuffer[ud_y * SCREENWIDTH + ud_x];
char *dest = &displayscreen[ud_y * SCREENWIDTH + ud_x];
if (ud_lx == SCREENWIDTH)
{
memcpy(dest, src, SCREENWIDTH * ud_ly);
}
else
{
for (loop = 0; loop < ud_ly; loop++)
{
memcpy(dest, src, ud_lx);
dest += SCREENWIDTH;
src += SCREENWIDTH;
}
}
update_start = 0;
}
/*==========================================================================
GFX_ShadeSprite() -
==========================================================================*/
void
GFX_ShadeSprite(
char *dest,
char *inmem,
char *dtable
)
{
GFX_PIC* h = (GFX_PIC*)inmem;
GFX_SPRITE* ah = (GFX_SPRITE*)inmem;
while ((int16_t)LE_LONG(ah->offset) != -1)
{
char* d = dest + (uint16_t)LE_LONG(ah->offset);
for (int loop = 0; loop < (uint16_t)LE_LONG(h->width); loop++, d++)
*d = dtable[(uint8_t)*d];
h = (GFX_PIC*)((char*)&h->height + (uint16_t)LE_LONG(h->width));
ah = (GFX_SPRITE*)h;
}
}
/*==========================================================================
GFX_DrawSprite() -
==========================================================================*/
void
GFX_DrawSprite(
char *dest,
char *inmem
)
{
GFX_PIC* h = (GFX_PIC*)inmem;
GFX_SPRITE* ah = (GFX_SPRITE*)inmem;
while ((int16_t)LE_LONG(ah->offset) != -1)
{
memcpy(dest + (uint16_t)LE_LONG(ah->offset), (char*)&h->height, (uint16_t)LE_LONG(h->width));
h = (GFX_PIC*)((char*)&h->height + (uint16_t)LE_LONG(h->width));
ah = (GFX_SPRITE*)h;
}
}
/*==========================================================================
GFX_DrawChar() -
==========================================================================*/
void
GFX_DrawChar(
char *dest,
char *inmem,
int width,
int height,
int addx,
int color
)
{
do
{
for (int loop = 0; loop < width; loop++)
{
if (*inmem)
*dest = color + *inmem;
dest++;
inmem++;
}
inmem += addx;
dest += SCREENWIDTH - width;
} while (--height);
}
/*==========================================================================
GFX_Shade() - Remaps Bytes according to shade table
==========================================================================*/
void
GFX_Shade(
char *outmem,
int maxlen,
char *dtable
)
{
for (int loop = 0; loop < maxlen; loop++)
{
outmem[loop] = dtable[(uint8_t)outmem[loop]];
}
}
/*==========================================================================
GFX_PutPic() - Puts Picture into buffer
==========================================================================*/
void
GFX_PutPic(
void
)
{
char *p = &displaybuffer[gfx_xp + gfx_yp * SCREENWIDTH];
char *src = gfx_inmem;
for (int loop = 0; loop < gfx_ly; loop++)
{
memcpy(p, src, gfx_lx);
p += SCREENWIDTH;
src += gfx_lx + gfx_imga;
}
}
/*==========================================================================
GFX_PutMaskPic() - Puts Picture into buffer with color 0 see thru
==========================================================================*/
void
GFX_PutMaskPic(
void
)
{
char *p = &displaybuffer[gfx_xp + gfx_yp * SCREENWIDTH];
char *src = gfx_inmem;
for (int loop = 0; loop < gfx_ly; loop++)
{
for (int i = 0; i < gfx_lx; i++)
{
if (src[i] != 0)
p[i] = src[i];
}
p += SCREENWIDTH;
src += gfx_lx + gfx_imga;
}
}
+921
View File
@@ -0,0 +1,921 @@
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "common.h"
#include "glbapi.h"
#include "vmemapi.h"
#include "entypes.h"
#ifdef _WIN32
#include <io.h>
#endif // _WIN32
#ifdef __GNUC__
#include <unistd.h>
char* strupr(char* s)
{
char* tmp = s;
for (; *tmp; ++tmp) {
*tmp = toupper((unsigned char)*tmp);
}
return s;
}
#endif // __GNUC__
#ifdef _MSC_VER
#include <windows.h>
#define PATH_MAX MAX_PATH
#endif // _MSC_VER
#define _SCOTTGAME
static const char* serial = "32768GLB";
static char exePath[PATH_MAX];
static int num_glbs;
static KEYFILE g_key;
static char prefix[5] = "FILE";
static bool fVmem = 0;
/*
* define file descriptor used to access file.
*/
typedef struct
{
char name[16];
VM_OWNER vm_mem;
uint32_t size;
uint32_t offset;
uint32_t flags;
uint32_t lock_cnt;
}ITEMINFO;
typedef struct
{
char filepath[PATH_MAX];
ITEMINFO* item;
int items;
FILE *handle;
const char *permissions;
}FILEDESC;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
typedef struct
{
uint16_t filenum;
uint16_t itemnum;
}ITEM_ID;
#else
typedef struct
{
uint16_t itemnum;
uint16_t filenum;
}ITEM_ID;
#endif
typedef union
{
ITEM_ID id;
uint32_t handle;
}ITEM_H;
static FILEDESC filedesc[MAX_GLB_FILES];
#define ITF_LOCKED 0x80000000L
#define ITF_ENCODED 0x40000000L
typedef enum
{
FI_CACHE,
FI_DISCARD,
FI_LOCK
}FI_MODE;
/***************************************************************************
GLB_EnCrypt - Encrypt Data
***************************************************************************/
void
GLB_EnCrypt(
const char* key, // INPUT : Key that will allow Decryption
void* buf, // INPUT : Buffer to Encrypt
int length // INPUT : Length of Buffer
)
{
char* buffer = (char*)buf;
int klen = strlen(key);
int prev_byte;
int kidx;
kidx = SEED % klen;
prev_byte = key[kidx];
while (length--)
{
prev_byte = (*buffer + key[kidx] + prev_byte) % 256;
*buffer++ = prev_byte;
if (++kidx >= klen)
kidx = 0;
}
}
/***************************************************************************
GLB_DeCrypt - Decrypt Data
***************************************************************************/
void
GLB_DeCrypt(
const char* key, // INPUT : Key that will allow Decryption
void* buf, // INPUT : Buffer to Encrypt
int length // INPUT : Length of Buffer
)
{
char* buffer = (char*)buf;
int klen = strlen(key);
int prev_byte;
int kidx;
char dchr;
kidx = SEED % klen;
prev_byte = key[kidx];
while (length--)
{
dchr = (*buffer - key[kidx] - prev_byte) % 256;
prev_byte = *buffer;
*buffer++ = dchr;
if (++kidx >= klen)
kidx = 0;
}
}
/*------------------------------------------------------------------------
GLB_FindFile() - Finds a file, opens it, and stores it's path
------------------------------------------------------------------------*/
static FILE*
GLB_FindFile(
int return_on_failure, // INPUT : Don't bomb if file not open
int filenum, // INPUT : file number
const char *permissions // INPUT : file access permissions
)
{
const char* routine = "GLB_FindFile";
char filename[PATH_MAX];
char filenamelc[PATH_MAX];
FILE *handle;
FILEDESC* fd;
/*
* Scott, the ASSERT function is a macro that will be compiled-out when
* not debugging ( DEBUG not defined ), otherwise it calls EXIT_Assert
* if the expression is false ( which bails out of your program and displays
* the expression, file & line number of the assertion ). This is a standard
* way of checking variables for correct boundries during development, and
* makes it easy to remove extra logic for doing so by recompiling without
* DEBUG defined.
*/
ASSERT(filenum >= 0 && filenum < MAX_GLB_FILES);
/*
* create a file name and attempt to open it local first, then if it
* fails use the exe path and try again.
*/
sprintf(filenamelc, "%s%04u.glb", "file", filenum);
if (!access(filenamelc, 0))
strcpy(filename, filenamelc);
else
sprintf(filename, "%s%04u.GLB", prefix, filenum);
if ((handle = fopen(filename, permissions)) == NULL)
{
sprintf(filenamelc, "%s%s%04u.glb", exePath, "file", filenum);
if (!access(filenamelc, 0))
strcpy(filename, filenamelc);
else
sprintf(filename, "%s%s%04u.GLB", exePath, prefix, filenum);
if ((handle = fopen(filename, permissions)) == NULL)
{
if (return_on_failure)
return NULL;
sprintf(filename, "%s%04u.GLB", prefix, filenum);
EXIT_Error("GLB_FindFile: %s, Error #%d,%s",
filename, errno, strerror(errno));
}
}
/*
* Keep file handle
*/
fd = &filedesc[filenum];
strcpy(fd->filepath, filename);
fd->permissions = permissions;
fd->handle = handle;
return handle;
}
/*------------------------------------------------------------------------
GLB_OpenFile() - Opens & Caches file handle
------------------------------------------------------------------------*/
static FILE*
GLB_OpenFile(
int return_on_failure, // INPUT : Don't bomb if file not open
int filenum, // INPUT : file number
const char *permissions // INPUT : file access permissions
)
{
FILEDESC* fd;
ASSERT(filenum >= 0 && filenum < MAX_GLB_FILES);
fd = &filedesc[filenum];
if (fd->handle == 0)
return GLB_FindFile(return_on_failure, filenum, permissions);
else if (fd->permissions != permissions)
{
fclose(fd->handle);
if ((fd->handle = fopen(fd->filepath, permissions)) == NULL)
{
if (return_on_failure)
return NULL;
EXIT_Error("GLB_OpenFile: %s, Error #%d,%s",
fd->filepath, errno, strerror(errno));
}
}
else
{
fseek(fd->handle, 0L, SEEK_SET);
}
return fd->handle;
}
/*------------------------------------------------------------------------
GLB_CloseFiles() - Closes all cached files.
------------------------------------------------------------------------*/
static void
GLB_CloseFiles(
void
)
{
int j;
for (j = 0; j < MAX_GLB_FILES; j++)
{
if (filedesc[j].handle)
{
fclose(filedesc[j].handle);
filedesc[j].handle = 0;
}
}
}
/*------------------------------------------------------------------------
GLB_NumItems() - Returns number of items in a .GLB file
------------------------------------------------------------------------*/
static int
GLB_NumItems(
int filenum
)
{
KEYFILE key;
FILE *handle;
ASSERT(filenum >= 0 && filenum < num_glbs);
handle = GLB_OpenFile(1, filenum, "rb");
if (handle == NULL)
return 0;
fseek(handle, 0L, SEEK_SET);
if (!fread(&key, sizeof(KEYFILE), 1, handle))
{
EXIT_Error("GLB_NumItems: Read failed!");
}
#ifdef _SCOTTGAME
GLB_DeCrypt(serial, (uint8_t*)&key, sizeof(KEYFILE));
#endif
return ((int)LE_ULONG(key.offset));
}
/*--------------------------------------------------------------------------
GLB_LoadIDT() Loads a item descriptor table from a GLB file.
--------------------------------------------------------------------------*/
static void
GLB_LoadIDT(
FILEDESC* fd // INPUT: file to load
)
{
FILE *handle;
int j;
int k;
int n;
KEYFILE key[10];
ITEMINFO* ii;
handle = fd->handle;
ii = fd->item;
fseek(handle, sizeof(KEYFILE), SEEK_SET);
for (j = 0; j < fd->items; )
{
k = fd->items - j;
if (k > ASIZE(key))
k = ASIZE(key);
fread(key, sizeof(KEYFILE), k, handle);
for (n = 0; n < k; n++)
{
#ifdef _SCOTTGAME
GLB_DeCrypt(serial, (void*)&key[n], sizeof(KEYFILE));
#endif
if (LE_ULONG(key[n].opt) == GLB_ENCODED)
ii->flags |= ITF_ENCODED;
ii->size = LE_ULONG(key[n].filesize);
ii->offset = LE_ULONG(key[n].offset);
memcpy(ii->name, key[n].name, sizeof(ii->name));
ii++;
}
j += k;
}
}
/*************************************************************************
GLB_UseVM - Use virtual memory functions for heap managment.
*************************************************************************/
void
GLB_UseVM(
void
)
{
fVmem = 1;
}
/*************************************************************************
GLB_InitSystem() - Starts up .GLB file system
*************************************************************************/
int // Returns number of GLB resources opened.
GLB_InitSystem(
const char* exepath, // INPUT: Where program was run from
int innum, // INPUT: MAX .GLB FILES TO LOOK FOR
const char* iprefix // INPUT: FILENAME PREFIX ( NULL for "FILE" )
)
{
int opened;
int filenum;
int num;
char* p;
FILEDESC* fd;
/*
* Extract path from program source of execution.
*/
memset(exePath, 0, sizeof(exePath));
strcpy(exePath, exepath);
if ((p = strrchr(exePath, '\\')) != NULL)
*(p + 1) = '\0';
num_glbs = innum;
ASSERT(num_glbs >= 1 && num_glbs <= MAX_GLB_FILES);
if (iprefix)
{
ASSERT(strlen(iprefix) < sizeof(prefix) - 1);
strcpy(prefix, iprefix);
strupr(prefix);
}
memset(filedesc, 0, sizeof(filedesc));
/*
* Next, read in header of each file and allocate cache
*/
opened = 0;
for (filenum = 0; filenum < num_glbs; filenum++)
{
fd = &filedesc[filenum];
if ((num = GLB_NumItems(filenum)) != 0)
{
fd->items = num;
/*
* Note: calloc zeros out all memory that it allocates
*/
fd->item = (ITEMINFO*)calloc(num, sizeof(ITEMINFO));
if (fd->item == NULL)
EXIT_Error("GLB_NumItems: memory ( init )");
/*
* Load Item Descriptor Table for file
*/
GLB_LoadIDT(fd);
opened++;
}
}
return (opened);
}
/*************************************************************************
GLB_Load() Loads a file to a pointer from a .GLB file
*************************************************************************/
int // RETURN : size of item read
GLB_Load(
char* inmem, // INPUT: memory pointer or NULL
int filenum, // INPUT: file number
int itemnum // INPUT: item in file number
)
{
FILE *handle;
ITEMINFO* ii;
ASSERT(filenum >= 0 && filenum < num_glbs);
handle = filedesc[filenum].handle;
if (handle == 0)
return 0;
ASSERT(itemnum < (WORD)filedesc[filenum].items);
ii = filedesc[filenum].item;
ii += itemnum;
if (inmem != NULL)
{
if (ii->vm_mem.obj != NULL && inmem != ii->vm_mem.obj)
memcpy(inmem, ii->vm_mem.obj, ii->size);
else
{
fseek(handle, ii->offset, SEEK_SET);
fread(inmem, ii->size, 1, handle);
#ifdef _SCOTTGAME
if (ii->flags & ITF_ENCODED)
{
GLB_DeCrypt(serial, inmem, ii->size);
}
#endif
}
}
return ii->size;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
GLB_FetchItem() - Loads item into memory only if free core exists.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
static char*
GLB_FetchItem(
uint32_t handle,
FI_MODE mode
)
{
char* obj;
ITEM_H itm;
ITEMINFO* ii;
if (handle == ~0)
{
EXIT_Error("GLB_FetchItem: empty handle.");
return NULL;
}
itm.handle = handle;
ASSERT(itm.id.filenum < (WORD)num_glbs);
ASSERT(itm.id.itemnum < (WORD)filedesc[itm.id.filenum].items);
ii = filedesc[itm.id.filenum].item;
ii += itm.id.itemnum;
if (mode == FI_LOCK)
ii->flags |= ITF_LOCKED;
if ((obj = ii->vm_mem.obj) == NULL)
{
ii->lock_cnt = 0;
if (ii->size == 0)
ii->vm_mem.obj = NULL;
else
{
if (fVmem)
{
obj = (char*)VM_Malloc(ii->size,
(ii->flags & ITF_LOCKED) ? NULL : &ii->vm_mem,
(mode == FI_CACHE) ? 0 : 1);
}
else
{
obj = (char*)calloc(ii->size, sizeof(uint8_t));
}
if (mode == FI_LOCK)
ii->lock_cnt = 1;
ii->vm_mem.obj = obj;
if (obj != NULL)
{
GLB_Load(obj, itm.id.filenum, itm.id.itemnum);
}
}
}
else if (mode == FI_LOCK && fVmem)
{
ii->lock_cnt++;
VM_Lock(obj);
}
if (ii->vm_mem.obj == NULL && mode != FI_CACHE)
{
EXIT_Error("GLB_FetchItem: failed on %d bytes, mode=%d.", ii->size, mode);
}
if (mode == FI_DISCARD && fVmem)
VM_Touch(&ii->vm_mem);
return ii->vm_mem.obj;
}
/***************************************************************************
GLB_CacheItem() - Loads item into memory only if free core exists.
***************************************************************************/
char*
GLB_CacheItem(
int handle
)
{
return GLB_FetchItem(handle, FI_CACHE);
}
/***************************************************************************
GLB_GetItem() - Loads and allocates memory for a .GLB item
***************************************************************************/
char*
GLB_GetItem(
int handle // INPUT : handle of item
)
{
return GLB_FetchItem(handle, FI_DISCARD);
}
/***************************************************************************
GLB_LockItem () - Keeps Item From being discarded.
***************************************************************************/
char*
GLB_LockItem(
int handle
)
{
return GLB_FetchItem(handle, FI_LOCK);
}
/***************************************************************************
GLB_UnlockItem () - Allows item to be discarded from memory.
***************************************************************************/
void
GLB_UnlockItem(
int handle
)
{
ITEM_H itm;
ITEMINFO* ii;
if (handle == ~0)
return;
itm.handle = handle;
ASSERT(itm.id.filenum < (WORD)num_glbs);
ASSERT(itm.id.itemnum < (WORD)filedesc[itm.id.filenum].items);
ii = filedesc[itm.id.filenum].item;
ii += itm.id.itemnum;
if (ii->vm_mem.obj != NULL && fVmem)
{
if (ii->lock_cnt)
{
ii->lock_cnt--;
if (ii->lock_cnt)
return;
}
ii->flags &= ~ITF_LOCKED;
VM_Unlock(ii->vm_mem.obj, &ii->vm_mem);
}
else
{
ii->flags &= ~ITF_LOCKED;
}
}
/***************************************************************************
GLB_IsLabel () - tests to see if ID is a label or an Item
***************************************************************************/
int // RETURN: TRUE = Label
GLB_IsLabel(
int handle // INPUT : handle of item
)
{
ITEM_H itm;
ITEMINFO* ii;
if (handle == ~0)
return 0;
itm.handle = handle;
ASSERT(itm.id.filenum < (WORD)num_glbs);
ASSERT(itm.id.itemnum < (WORD)filedesc[itm.id.filenum].items);
ii = filedesc[itm.id.filenum].item;
ii += itm.id.itemnum;
return (ii->size == 0 ? 1 : 0);
}
/***************************************************************************
GLB_ReadItem() - Loads Item into user memory for a .GLB item
***************************************************************************/
void
GLB_ReadItem(
int handle, // INPUT : handle of item
char* mem // INPUT : pointer to memory
)
{
ITEM_H itm;
ITEMINFO* ii;
if (handle == ~0)
return;
ASSERT(mem != NULL);
itm.handle = handle;
ASSERT(itm.id.filenum < (WORD)num_glbs);
ASSERT(itm.id.itemnum < (WORD)filedesc[itm.id.filenum].items);
ii = filedesc[itm.id.filenum].item;
ii += itm.id.itemnum;
if (mem != NULL)
{
GLB_Load(mem, itm.id.filenum, itm.id.itemnum);
}
}
/***************************************************************************
GLB_GetItemID () - Gets Item ID from the text name
***************************************************************************/
int // RETURN: Handle
GLB_GetItemID(
const char* in_name // INPUT : pointer to text name
)
{
ITEMINFO* ii;
ITEM_H itm;
int filenum;
int itemnum;
int maxloop;
ASSERT(in_name != NULL);
itm.handle = ~0;
if (*in_name != ' ' && *in_name != '\0')
{
for (filenum = 0; filenum < num_glbs; filenum++)
{
maxloop = filedesc[filenum].items;
ii = filedesc[filenum].item;
for (itemnum = 0; itemnum < maxloop; itemnum++)
{
if (strcmp(ii->name, in_name) == 0)
{
itm.id.filenum = filenum;
itm.id.itemnum = itemnum;
return itm.handle;
}
ii++;
}
}
}
return itm.handle;
}
#if 0
/***************************************************************************
GLB_GetPtr() - Returns a pointer to item ( handle )
***************************************************************************/
char* // RETURN: pointer to item
GLB_GetPtr(
int handle // INPUT : handle of item
)
{
ITEM_H itm;
ITEMINFO* ii;
if (handle == ~0)
return NULL;
itm.handle = handle;
ASSERT(itm.id.filenum < (uint16_t)num_glbs);
ASSERT(itm.id.itemnum < (uint16_t)filedesc[itm.id.filenum].items);
ii = filedesc[itm.id.filenum].item;
ii += itm.id.itemnum;
return ii->memory;
}
#endif
/***************************************************************************
GLB_FreeItem() - Frees memory for items and places items < MAX SIZE
***************************************************************************/
void
GLB_FreeItem(
int handle // INPUT : handle of item
)
{
ITEM_H itm;
ITEMINFO* ii;
if (handle == ~0)
return;
itm.handle = handle;
ASSERT(itm.id.filenum < (uint16_t)num_glbs);
if (itm.id.itemnum >= (uint16_t)filedesc[itm.id.filenum].items)
{
EXIT_Error("GLB_FreeItem - item out of range: %d > %d file %d.\n",
itm.id.itemnum, filedesc[itm.id.filenum].items, itm.id.filenum);
}
// ASSERT( itm.id.itemnum < ( WORD ) filedesc[ itm.id.filenum ].items );
ii = filedesc[itm.id.filenum].item;
ii += itm.id.itemnum;
if (ii->vm_mem.obj != NULL)
{
ii->flags &= ~ITF_LOCKED;
if (fVmem)
VM_Free(ii->vm_mem.obj);
else
free(ii->vm_mem.obj);
ii->vm_mem.obj = NULL;
}
}
/***************************************************************************
GLB_FreeAll() - Frees All memory used by GLB items
***************************************************************************/
void
GLB_FreeAll(
void
)
{
int filenum;
int itemnum;
ITEMINFO* ii;
for (filenum = 0; filenum < num_glbs; filenum++)
{
ii = filedesc[filenum].item;
for (itemnum = 0; itemnum < filedesc[filenum].items; itemnum++)
{
if (ii->vm_mem.obj && (ii->flags & ITF_LOCKED) == 0)
{
if (fVmem)
VM_Free(ii->vm_mem.obj);
else
free(ii->vm_mem.obj);
ii->vm_mem.obj = NULL;
}
ii++;
}
}
}
/***************************************************************************
GLB_ItemSize() - Returns Size of Item
***************************************************************************/
int // RETURN: sizeof ITEM
GLB_ItemSize(
int handle // INPUT : handle of item
)
{
ITEM_H itm;
ITEMINFO* ii;
if (handle == ~0)
return 0;
itm.handle = handle;
ASSERT(itm.id.filenum < (WORD)num_glbs);
ASSERT(itm.id.itemnum < (WORD)filedesc[itm.id.filenum].items);
ii = filedesc[itm.id.filenum].item;
ii += itm.id.itemnum;
return ii->size;
}
/***************************************************************************
GLB_ReadFile () reads in a normal file
***************************************************************************/
int // RETURN: size of record
GLB_ReadFile(
const char* name, // INPUT : filename
char* buffer // OUTPUT: pointer to buffer or NULL
)
{
char fqp[PATH_MAX];
FILE *handle;
uint32_t sizerec;
if (access(name, 0) == -1)
{
strcpy(fqp, exePath);
strcat(fqp, name);
name = fqp;
}
if ((handle = fopen(name, "rb")) == NULL)
EXIT_Error("LoadFile: Open failed!");
fseek(handle, 0, SEEK_END);
sizerec = ftell(handle);
rewind(handle);
if (buffer && sizerec)
{
if (!fread(buffer, sizerec, 1, handle))
{
fclose(handle);
EXIT_Error("GLB_LoadFile: Load failed!");
}
}
fclose(handle);
return (sizerec);
}
/***************************************************************************
GLB_SaveFile () saves buffer to a normal file ( filename )
***************************************************************************/
void
GLB_SaveFile(
char* name, // INPUT : filename
char* buffer, // INPUT : pointer to buffer
int length // INPUT : length of buffer
)
{
FILE *handle;
if ((handle = fopen(name, "wb")) == NULL)
EXIT_Error("SaveFile: Open failed!");
if (length)
{
if (!fwrite(buffer, length, 1, handle))
{
fclose(handle);
EXIT_Error("GLB_SaveFile: Write failed!");
}
}
fclose(handle);
}
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#include <stdint.h>
typedef struct
{
uint32_t opt; // option (encode on/off)
uint32_t offset; // offset into file
uint32_t filesize; // filesize
char name[16]; // text name ( end with null )
}KEYFILE;
typedef struct
{
uint16_t itemnum;
uint16_t filenum;
}ITEMS;
#define MAX_GLB_FILES 0x000F
#define SEED 0x0019
#define GLB_NORMAL 0
#define GLB_ENCODED 1
void GLB_UseVM(void);
int GLB_InitSystem(const char *exepath, int innum, const char *iprefix);
char *GLB_LockItem(int handle);
void GLB_UnlockItem(int handle);
char *GLB_GetItem(int handle);
char *GLB_CacheItem(int handle);
void GLB_FreeItem(int handle);
void GLB_FreeAll(void);
int GLB_GetItemID(const char *in_name);
int GLB_ItemSize(int handle);
void GLB_EnCrypt(const char *key, void *buf, int length);
void GLB_DeCrypt(const char *key, void *buf, int length);
int GLB_ReadFile(const char *name, char *buffer);
void GLB_SaveFile(char *name, char *buffer, int length);
int GLB_Load(char *inmem, int filenum, int itemnum);
int GLB_IsLabel(int handle);
void GLB_ReadItem(int handle, char *mem);
//char *GLB_GetPtr(int handle);
//void GLB_SetItemPointer(int a1, char* a2);
//void GLB_SetItemSize(int a1, int a2);
+356
View File
@@ -0,0 +1,356 @@
#include "SDL.h"
#include "common.h"
#include "gssapi.h"
#include "musapi.h"
#include "cards.h"
#include "fx.h"
#include "entypes.h"
musdevice_t *gss_device;
int gss_init;
int gssrate = 140;
int gsshack;
int gss_timer;
int gss_cnt;
void *gss_ptr;
int gss_currentptr;
int gss_priority;
int gss_handcnt;
int gss_handle;
int gss_sep;
int gss_volume;
int gss_type;
int gss_lastnote, gss_lastsmp;
/***************************************************************************
GSS_Init () -
***************************************************************************/
void
GSS_Init(
int device,
int option
)
{
if (gss_init)
return;
switch (device)
{
case M_NONE:
gss_device = NULL;
break;
case M_ADLIB:
case M_PAS:
case M_SB:
gss_device = &mus_device_opl;
break;
case M_WAVE:
case M_CANVAS:
case M_GMIDI:
default:
#ifdef _WIN32
gss_device = &mus_device_winmm;
#endif // _WIN32
break;
}
if (gss_device && gss_device->Init)
gss_device->Init(option);
gsshack = 0;
if (music_device && music_device == gss_device)
gsshack = 1;
gss_cnt = 0;
gss_timer = SDL_GetTicks();
gss_init = 1;
}
/***************************************************************************
GSS_DeInit () -
***************************************************************************/
void
GSS_DeInit(
void
)
{
if (!gss_init)
return;
if (gss_device && gss_device->DeInit)
gss_device->DeInit();
gsshack = 0;
gss_device = NULL;
gss_init = 0;
}
/***************************************************************************
GSS_Service () -
***************************************************************************/
void
GSS_Service(
void
)
{
if (!gss_init)
return;
switch (gss_type)
{
case 1:
{
gss1_t *gss = (gss1_t*)gss_ptr;
int smp, note, bend;
if (gss_currentptr == 0)
{
// setup playback
if (gss_lastnote)
{
if (gss_device && gss_device->KeyOffEvent)
gss_device->KeyOffEvent(14, gss_lastnote);
gss_lastnote = 0;
}
if (gss_device && gss_device->ControllerEvent)
{
gss_device->ControllerEvent(14, 4, gss_sep >> 1);
gss_device->ControllerEvent(14, 1, LE_SHORT(gss->bank));
gss_device->ControllerEvent(14, 0, LE_SHORT(gss->patch));
}
if (gss_device && gss_device->PitchBendEvent)
gss_device->PitchBendEvent(14, 127);
}
else if (gss_currentptr >= LE_SHORT(gss->len))
{
if (gss_lastnote)
{
if (gss_device && gss_device->KeyOffEvent)
gss_device->KeyOffEvent(14, gss_lastnote);
gss_lastnote = 0;
}
gss_type = 0;
gss_ptr = NULL;
break;
}
smp = gss->data[gss_currentptr++];
if (gss_lastsmp != smp)
{
if (smp == 0 && gss_lastnote)
{
if (gss_device && gss_device->KeyOffEvent)
gss_device->KeyOffEvent(14, gss_lastnote);
gss_lastnote = 0;
}
else
{
note = 29 + ((smp - 1) >> 1);
bend = (smp & 1) ? 127 : 159;
if (note != gss_lastnote)
{
if (gss_device && gss_device->KeyOffEvent)
gss_device->KeyOffEvent(14, gss_lastnote);
if (gss_device && gss_device->PitchBendEvent)
gss_device->PitchBendEvent(14, bend);
if (gss_device && gss_device->KeyOnEvent)
gss_device->KeyOnEvent(14, note, gss_volume);
gss_lastnote = note;
}
else
{
if (gss_device && gss_device->PitchBendEvent)
gss_device->PitchBendEvent(14, bend);
}
}
gss_lastsmp = smp;
}
break;
}
}
}
/***************************************************************************
GSS_Mix () -
***************************************************************************/
void
GSS_Mix(
int16_t *stream,
int len
)
{
int i;
if (!gss_init)
return;
if (!gss_init || !gss_device || !gss_device->Mix || gsshack)
return;
for (i = 0; i < len; i++)
{
gss_device->Mix(stream, 1);
gss_cnt += gssrate;
while (gss_cnt >= fx_freq)
{
gss_cnt -= fx_freq;
GSS_Service();
}
stream += 2;
}
}
/***************************************************************************
GSS_Poll () -
***************************************************************************/
void
GSS_Poll(
void
)
{
if (!gss_init || !gss_device || gss_device->Mix)
return;
int now = SDL_GetTicks();
while (gss_timer < now)
{
gss_cnt += gssrate;
if (gss_cnt >= 1000)
{
gss_cnt -= 1000;
GSS_Service();
}
gss_timer++;
}
}
/***************************************************************************
GSS_PlayPatch () -
***************************************************************************/
int
GSS_PlayPatch(
void *gss,
int sep,
int pitch,
int volume,
int priority
)
{
int format = LE_SHORT(*(int16_t*)gss);
int handle = (gss_handcnt++) & FXHAND_MASK;
if (format != 1 && format != 2)
return -1;
SND_Lock();
if (gss_type != 0 && priority < gss_priority)
{
SND_Unlock();
return -1;
}
if (gss_type == 0)
gss_lastnote = 0;
gss_type = 0;
gss_ptr = 0;
gss_priority = priority;
gss_sep = sep;
gss_volume = volume;
switch (format)
{
case 1:
{
gss_currentptr = 0;
gss_lastsmp = 0;
gss_ptr = gss;
gss_type = 1;
break;
}
case 2:
gss_currentptr = 0;
gss_ptr = gss;
gss_type = 2;
break;
}
gss_handle = handle;
SND_Unlock();
return handle | FXHAND_GSS1;
}
/***************************************************************************
GSS_StopPatch () -
***************************************************************************/
void
GSS_StopPatch(
int handle
)
{
if (!gss_init)
return;
handle &= FXHAND_MASK;
SND_Lock();
if (handle == gss_handle)
{
switch (gss_type)
{
case 1:
{
gss1_t *gss = (gss1_t*)gss_ptr;
gss_currentptr = LE_SHORT(gss->len);
}
}
}
SND_Unlock();
}
/***************************************************************************
GSS_PatchIsPlaying () -
***************************************************************************/
int
GSS_PatchIsPlaying(
int handle
)
{
int stat = 0;
if (!gss_init)
return 0;
handle &= FXHAND_MASK;
SND_Lock();
if (handle == gss_handle && gss_type != 0)
stat = 1;
SND_Unlock();
return stat;
}
+30
View File
@@ -0,0 +1,30 @@
#pragma once
#include <stdint.h>
struct gss1_t {
int16_t format;
int16_t len;
int16_t bank;
int16_t patch;
uint8_t data[1];
};
struct gss2_t {
int16_t format;
int16_t bank;
int16_t patch;
int16_t note;
int16_t len;
};
extern int gsshack;
extern int gssrate;
void GSS_Service(void);
void GSS_Init(int device, int option);
void GSS_DeInit(void);
void GSS_Mix(int16_t *stream, int len);
void GSS_Poll(void);
int GSS_PlayPatch(void *gss, int sep, int pitch, int volume, int priority);
void GSS_StopPatch(int handle);
int GSS_PatchIsPlaying(int handle);
+154
View File
@@ -0,0 +1,154 @@
#include <stdio.h>
#include "common.h"
#include "glbapi.h"
#include "rap.h"
#include "kbdapi.h"
#include "swdapi.h"
#include "gfxapi.h"
#include "fx.h"
#include "i_video.h"
#include "windows.h"
#include "joyapi.h"
#include "input.h"
#include "fileids.h"
#include "winids.h"
static int startitem;
static int curpage;
static int maxpages;
/***************************************************************************
HELP_Init() - inits the help stuff
***************************************************************************/
void
HELP_Init(
void
)
{
int enditem;
startitem = GLB_GetItemID("STARTHELP");
enditem = GLB_GetItemID("ENDHELP");
if (!reg_flag)
startitem += 2;
maxpages = enditem - startitem - 1;
startitem++;
curpage = 0;
}
/***************************************************************************
HELP_Win() - Displays the help window at the specified page
***************************************************************************/
void
HELP_Win(
const char *strpage // INPUT : GLB string item
)
{
SWD_DLG dlg;
char temp[20];
int update, item, window;
update = 1;
item = GLB_GetItemID(strpage);
if (item == -1)
EXIT_Error("HELP() - Invalid Page");
curpage = item - startitem;
KBD_Clear();
window = SWD_InitWindow(FILE138_HELP_SWD);
SND_Patch(FX_DOOR, 127);
while (1)
{
if (update)
{
update = 0;
if (curpage >= 0)
curpage = curpage % maxpages;
else
curpage += maxpages;
SWD_SetFieldItem(window, HELP_TEXT, startitem + curpage);
sprintf(temp, "PAGE : %02u", curpage + 1);
SWD_SetFieldText(window, HELP_HEADER, temp);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
}
SWD_Dialog(&dlg);
I_GetNeedResize(false);
switch (dlg.keypress)
{
case SC_HOME:
update = 1;
curpage = 0;
break;
case SC_F1:
update = 1;
curpage = 1;
break;
case SC_END:
update = 1;
curpage = maxpages - 1;
break;
case SC_DOWN:
case SC_RIGHT:
case SC_PAGEDN:
update = 1;
curpage++;
break;
case SC_UP:
case SC_LEFT:
case SC_PAGEUP:
update = 1;
curpage--;
break;
}
if ((KBD_IsKey(SC_ESC)) || (JOY_IsKeyMenu(Back) && joy_ipt_MenuNew) || (JOY_IsKeyMenu(BButton) && joy_ipt_MenuNew))
break;
if (KBD_Key(SC_X) && KBD_Key(SC_ALT))
WIN_AskExit();
if (dlg.cur_act == S_FLD_COMMAND && dlg.cur_cmd == F_SELECT)
{
switch (dlg.field)
{
case HELP_DONE:
goto func_exit;
case HELP_DOWN:
update = 1;
curpage++;
break;
case HELP_UP:
update = 1;
curpage--;
break;
}
}
}
func_exit:
SWD_DestroyWindow(window);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
}
+4
View File
@@ -0,0 +1,4 @@
#pragma once
void HELP_Init(void);
void HELP_Win(const char *strpage);
+86
View File
@@ -0,0 +1,86 @@
//
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// DESCRIPTION:
// Exit text-mode ENDOOM screen.
//
#include <stdio.h>
#include <string.h>
#include "rap.h"
#include "i_lastscr.h"
#include "textscreen.h"
#include "i_video.h"
#include "joyapi.h"
#include "kbdapi.h"
#include "ptrapi.h"
#include "imsapi.h"
#define LASTSCR_W 80
#define LASTSCR_H 25
//
// Displays the text mode ending screen after the game quits
//
void I_LASTSCR(char* mem)
{
unsigned char* screendata;
int y;
int indent;
TXT_Fullscreen(txt_fullscreen);
// Set up text mode screen
TXT_Init();
TXT_SetWindowTitle("Raptor");
// SDL2-TODO I_InitWindowTitle();
// SDL2-TODO I_InitWindowIcon();
// Write the data to the screen memory
screendata = TXT_GetScreenData();
indent = (LASTSCR_W - TXT_SCREEN_W) / 2;
for (y = 0; y < TXT_SCREEN_H; ++y)
{
memcpy(screendata + (y * TXT_SCREEN_W * 2),
mem + (y * LASTSCR_W + indent) * 2,
TXT_SCREEN_W * 2);
}
// Wait for a keypress
IMS_StartAck();
I_Settextmode(true);
while (true)
{
TXT_UpdateScreen();
I_GetEvent();
if (joy_ack || kbd_ack || mouse_b1_ack || mouse_b2_ack || mouse_b3_ack)
break;
TXT_Sleep(0);
}
// Shut down text mode screen
TXT_Shutdown();
}
+3
View File
@@ -0,0 +1,3 @@
#pragma once
void I_LASTSCR(char* mem);
File diff suppressed because it is too large. Load diff
+34
View File
@@ -0,0 +1,34 @@
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// DESCRIPTION:
// The not so system specific sound interface.
//
#pragma once
// DMX version to emulate for OPL emulation:
typedef enum {
opl_doom1_1_666, // Doom 1 v1.666
opl_doom2_1_666, // Doom 2 v1.666, Hexen, Heretic
opl_rap12 // Doom v1.9, Strife
} opl_driver_ver_t;
void LoadInstrumentTable(char *genmidi);
void I_OPL_PlaySong(void);
void I_OPL_PauseSong(void);
void I_OPL_ResumeSong(void);
void I_OPL_StopSong(void);
void I_OPL_ShutdownMusic(void);
int I_OPL_InitMusic(int dummy);
void I_SetOPLDriverVer(opl_driver_ver_t ver);
void I_OPL_SetMusicVolume(int volume);
File diff suppressed because it is too large. Load diff
+55
View File
@@ -0,0 +1,55 @@
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// DESCRIPTION:
// System specific interface stuff.
//
#pragma once
#include <stdint.h>
// Screen width and height.
#define SCREENWIDTH 320
#define SCREENHEIGHT 200
// Screen height used when aspect_ratio_correct=true.
#define SCREENHEIGHT_4_3 240
typedef uint8_t pixel_t;
typedef bool (*grabmouse_callback_t)(void);
// Screen width and height, from configuration file.
extern int window_width;
extern int window_height;
extern int fullscreen;
extern int txt_fullscreen;
extern pixel_t *I_VideoBuffer;
void I_InitGraphics(uint8_t *pal);
void I_ShutdownGraphics(void);
void I_FinishUpdate (void);
void I_GetEvent(void);
void I_SetPalette(uint8_t *doompalette, int start = 0);
void I_GetPalette(uint8_t *pal);
void I_GetMousePos(int *x, int *y);
void I_SetMousePos(int x, int y);
void I_SetGrabMouseCallback(grabmouse_callback_t func);
void VIDEO_LoadPrefs(void);
void closewindow(void);
bool I_GetNeedResize(bool setonlypos);
void I_Settextmode(bool flag);
+124
View File
@@ -0,0 +1,124 @@
#include <stdio.h>
#include "i_video.h"
#include "common.h"
#include "ptrapi.h"
#include "imsapi.h"
#include "kbdapi.h"
#include "joyapi.h"
/***************************************************************************
IMS_StartAck () - Starts up checking for a happening
***************************************************************************/
void
IMS_StartAck(
void
)
{
KBD_Clear();
mouse_b1_ack = 0;
mouse_b2_ack = 0;
mouse_b3_ack = 0;
kbd_ack = 0;
joy_ack = 0;
}
/***************************************************************************
IMS_CheckAck () - Tells if something has happend since last IMS_StartAck
***************************************************************************/
int
IMS_CheckAck(
void
)
{
I_GetEvent();
int rval;
rval = 0;
if (mouse_b1_ack)
rval = 1;
if (mouse_b2_ack)
rval = 1;
if (kbd_ack)
rval = 1;
if (joy_ack)
rval = 1;
return rval;
}
/***************************************************************************
IMS_IsAck() - Returns TRUE if ptr button or key pressed
***************************************************************************/
int
IMS_IsAck(
void
)
{
I_GetEvent();
if (Up || Down || Left || Right || Start || Back || LeftShoulder || RightShoulder || AButton || BButton || XButton || YButton)
{
return 1;
}
if (lastscan)
{
lastscan = 0;
return 1;
}
if (mouseb1 || mouseb2 || mouseb3)
return 1;
return 0;
}
/***************************************************************************
IMS_WaitTimed() - Wait for aprox secs
***************************************************************************/
int // RETURN: keypress (lastscan)
IMS_WaitTimed(
int secs // INPUT : seconds to wait
)
{
int loop, hold, rval;
rval = 0;
lastscan = 0;
IMS_StartAck();
while (secs > 0)
{
for (loop = 0; loop < 55; loop++)
{
hold = GFX_GetFrameCount();
while (GFX_GetFrameCount() == hold)
{
I_GetNeedResize(false);
}
if (IMS_CheckAck())
{
rval = 1;
goto end_func;
}
}
I_GetNeedResize(false);
secs--;
}
end_func:
loop = 100;
while (IMS_IsAck())
{
loop--;
}
IMS_StartAck();
return rval;
}
+5
View File
@@ -0,0 +1,5 @@
#pragma once
int IMS_IsAck(void);
void IMS_StartAck(void);
int IMS_CheckAck(void);
int IMS_WaitTimed(int secs);
+561
View File
@@ -0,0 +1,561 @@
#include "SDL.h"
#include "stdio.h"
#include "common.h"
#include "prefapi.h"
#include "windows.h"
#include "kbdapi.h"
#include "ptrapi.h"
#include "rap.h"
#include "demo.h"
#include "input.h"
#include "i_video.h"
#include "joyapi.h"
#define MAX_ADDX 10
#define MAX_ADDY 8
int control = 1;
int haptic;
int joy_ipt_MenuNew;
int k_Up;
int k_Down;
int k_Left;
int k_Right;
int k_Fire;
int k_FireSp;
int k_ChangeSp;
int k_Mega;
int m_lookup[3];
int j_lookup[4];
int buttons[4];
int xm, ym;
int g_addx, g_addy;
int ipt_start;
int control_pause;
/*------------------------------------------------------------------------
IPT_GetButtons () - Reads in Joystick and Keyboard game buttons
------------------------------------------------------------------------*/
void
IPT_GetButtons(
void
)
{
static int lasttick;
int now = SDL_GetTicks();
if (now - lasttick < 1000 / 26)
return;
lasttick += 1000 / 26;
if (!ipt_start)
return;
#if 0
int num;
if (control == I_JOYSTICK)
{
num = inp(0x2);
num >>= 4;
if ((num & 1) == 0)
buttons[j_lookup[0]] = 1;
if ((num & 2) == 0)
buttons[j_lookup[1]] = 1;
if ((num & 4) == 0)
buttons[j_lookup[2]] = 1;
if ((num & 8) == 0)
buttons[j_lookup[3]] = 1;
}
#endif
if (KBD_Key(k_Fire))
buttons[0] = 1;
if (KBD_Key(k_FireSp))
buttons[1] = 1;
if (KBD_Key(k_ChangeSp))
buttons[2] = 1;
if (KBD_Key(k_Mega))
buttons[3] = 1;
}
/*------------------------------------------------------------------------
IPT_GetJoyStick()
------------------------------------------------------------------------*/
void
IPT_GetJoyStick(
void
)
{
//Get Button
if (AButton)
{
if (AButtonconvert == j_lookup[0]) //Fire
buttons[0] = 1;
if (AButtonconvert == j_lookup[1]) //Fire Special
buttons[1] = 1;
if (AButtonconvert == j_lookup[2]) //Change Special
buttons[2] = 1;
if (AButtonconvert == j_lookup[3]) //Mega
buttons[3] = 1;
}
if (BButton)
{
if (BButtonconvert == j_lookup[0]) //Fire
buttons[0] = 1;
if (BButtonconvert == j_lookup[1]) //Fire Special
buttons[1] = 1;
if (BButtonconvert == j_lookup[2]) //Change Special
buttons[2] = 1;
if (BButtonconvert == j_lookup[3]) //Mega
buttons[3] = 1;
}
if (XButton)
{
if (XButtonconvert == j_lookup[0]) //Fire
buttons[0] = 1;
if (XButtonconvert == j_lookup[1]) //Fire Special
buttons[1] = 1;
if (XButtonconvert == j_lookup[2]) //Change Special
buttons[2] = 1;
if (XButtonconvert == j_lookup[3]) //Mega
buttons[3] = 1;
}
if (YButton)
{
if (YButtonconvert == j_lookup[0]) //Fire
buttons[0] = 1;
if (YButtonconvert == j_lookup[1]) //Fire Special
buttons[1] = 1;
if (YButtonconvert == j_lookup[2]) //Change Special
buttons[2] = 1;
if (YButtonconvert == j_lookup[3]) //Mega
buttons[3] = 1;
}
if (TriggerRight > 0) //Fire
buttons[0] = 1;
if (TriggerLeft > 0) //Fire Special
buttons[1] = 1;
if (LeftShoulder) //Change Special
buttons[2] = 1;
if (RightShoulder) //Mega
buttons[3] = 1;
//Move Player DPad
if (Left)
{
if (g_addx >= 0)
g_addx = -1;
g_addx--;
if (-g_addx > MAX_ADDX)
g_addx = -MAX_ADDX;
}
else if (Right)
{
if (g_addx <= 0)
g_addx = 1;
g_addx++;
if (g_addx > MAX_ADDX)
g_addx = MAX_ADDX;
}
else
{
if (g_addx)
g_addx /= 2;
}
if (Up)
{
if (g_addy >= 0)
g_addy = -1;
g_addy--;
if (-g_addy > MAX_ADDY)
g_addy = -MAX_ADDY;
}
else if (Down)
{
if (g_addy <= 0)
g_addy = 1;
g_addy++;
if (g_addy > MAX_ADDY)
g_addy = MAX_ADDY;
}
else
{
if (g_addy)
g_addy /= 2;
}
//Move Player Analog Stick
if (StickX != 0)
{
if (StickX > 0)
StickX *= 2;
if (StickX > MAX_ADDX)
StickX = MAX_ADDX;
if (StickX < 0)
StickX *= 2;
if (StickX < -MAX_ADDX)
StickX = -MAX_ADDX;
g_addx = StickX;
}
if (StickY != 0)
{
if (StickY > 0)
StickY *= 2;
if (StickY > MAX_ADDY)
StickY = MAX_ADDY;
if (StickY < 0)
StickY *= 2;
if (StickY < -MAX_ADDY)
StickY = -MAX_ADDY;
g_addy = StickY;
}
}
/*------------------------------------------------------------------------
IPT_GetKeyBoard (
------------------------------------------------------------------------*/
void
IPT_GetKeyBoard(
void
)
{
if (KBD_Key(k_Left) || KBD_Key(k_Right))
{
if (KBD_Key(k_Left))
{
if (g_addx >= 0)
g_addx = -1;
g_addx--;
if (-g_addx > MAX_ADDX)
g_addx = -MAX_ADDX;
}
else if (KBD_Key(k_Right))
{
if (g_addx <= 0)
g_addx = 1;
g_addx++;
if (g_addx > MAX_ADDX)
g_addx = MAX_ADDX;
}
}
else
{
if (g_addx)
g_addx /= 2;
}
if (KBD_Key(k_Up) || KBD_Key(k_Down))
{
if (KBD_Key(k_Up))
{
if (g_addy >= 0)
g_addy = -1;
g_addy--;
if (-g_addy > MAX_ADDY)
g_addy = -MAX_ADDY;
}
else if (KBD_Key(k_Down))
{
if (g_addy <= 0)
g_addy = 1;
g_addy++;
if (g_addy > MAX_ADDY)
g_addy = MAX_ADDY;
}
}
else
{
if (g_addy)
g_addy /= 2;
}
}
/*------------------------------------------------------------------------
IPT_GetMouse (
------------------------------------------------------------------------*/
void
IPT_GetMouse(
void
)
{
int plx, ply, ptrx, ptry;
plx = playerx + (PLAYERWIDTH / 2);
ply = playery + (PLAYERHEIGHT / 2);
ptrx = cur_mx;
ptry = cur_my;
xm = ptrx - plx;
ym = ptry - ply;
if (xm)
{
xm >>= 3;
if (!xm)
xm = 1;
else if (xm > 10)
xm = 10;
else if (xm < -10)
xm = -10;
}
if (ym)
{
ym >>= 3;
if (!ym)
ym = 1;
else if (ym > 10)
ym = 10;
else if (ym < -10)
ym = -10;
}
g_addx = xm;
g_addy = ym;
if (mouseb1)
buttons[m_lookup[0]] = 1;
if (mouseb2)
buttons[m_lookup[1]] = 1;
if (mouseb3)
buttons[m_lookup[2]] = 1;
}
/*------------------------------------------------------------------------
IPT_MouseGrab (
------------------------------------------------------------------------*/
bool
IPT_MouseGrab(
void
)
{
return ipt_start;
}
/***************************************************************************
IPT_Init () - Initializes INPUT system
***************************************************************************/
void
IPT_Init(
void
)
{
I_SetGrabMouseCallback(IPT_MouseGrab);
// ipt_tsm = TSM_NewService(IPT_GetButtons, 26, 254, 1);
IPT_CalJoy();
}
/***************************************************************************
IPT_DeInit() - Freeze up resources used by INPUT system
***************************************************************************/
void
IPT_DeInit(
void
)
{
// TSM_DelService(ipt_tsm);
}
/***************************************************************************
IPT_Start() - Tranfers control from PTRAPI stuff to IPT stuff
***************************************************************************/
void
IPT_Start(
void
)
{
PTR_DrawCursor(0);
PTR_Pause(1);
ipt_start = 1;
// TSM_ResumeService(ipt_tsm);
}
/***************************************************************************
IPT_End() - Tranfers control from IPT stuff to PTR stuff
***************************************************************************/
void
IPT_End(
void
)
{
ipt_start = 0;
// TSM_PauseService(ipt_tsm);
PTR_Pause(0);
PTR_DrawCursor(0);
}
/***************************************************************************
IPT_MovePlayer() - Perform player movement for current input device
***************************************************************************/
void
IPT_MovePlayer(
void
)
{
static int oldx = PLAYERINITX;
int delta;
if (demo_mode == DEMO_PLAYBACK)
return;
if (!control_pause)
{
switch (control)
{
case I_KEYBOARD:
default:
IPT_GetKeyBoard();
break;
case I_JOYSTICK:
IPT_GetJoyStick();
break;
case I_MOUSE:
IPT_GetMouse();
break;
}
}
playerx += g_addx;
playery += g_addy;
if (startendwave == -1)
{
if (playery < MINPLAYERY)
{
playery = MINPLAYERY;
g_addy = 0;
}
else if (playery > MAXPLAYERY)
{
playery = MAXPLAYERY;
g_addy = 0;
}
if (playerx < PLAYERMINX)
{
playerx = PLAYERMINX;
g_addx = 0;
}
else if (playerx + PLAYERWIDTH > PLAYERMAXX)
{
playerx = PLAYERMAXX - PLAYERWIDTH;
g_addx = 0;
}
}
delta = abs(playerx - oldx);
delta >>= 2;
if (delta > 3)
delta = 3;
if (playerx < oldx)
{
if (playerbasepic + delta > playerpic)
playerpic++;
}
else if (playerx > oldx)
{
if (playerbasepic - delta < playerpic)
playerpic--;
}
else
{
if (playerpic > playerbasepic)
playerpic--;
else if (playerpic < playerbasepic)
playerpic++;
}
oldx = playerx;
player_cx = playerx + (PLAYERWIDTH / 2);
player_cy = playery + (PLAYERHEIGHT / 2);
}
/***************************************************************************
IPT_PauseControl() - Lets routines run without letting user control anyting
***************************************************************************/
void
IPT_PauseControl(
int flag
)
{
control_pause = flag;
}
/***************************************************************************
IPT_FMovePlayer() - Forces player to move addx/addy
***************************************************************************/
void
IPT_FMovePlayer(
int addx, // INPUT : add to x pos
int addy // INPUT : add to y pos
)
{
g_addx = addx;
g_addy = addy;
IPT_MovePlayer();
}
/***************************************************************************
IPT_LoadPrefs() - Load Input Prefs from setup.ini
***************************************************************************/
void
IPT_LoadPrefs(
void
)
{
opt_detail = INI_GetPreferenceLong("Setup", "Detail", 1);
control = INI_GetPreferenceLong("Setup", "Control", 0);
haptic = INI_GetPreferenceLong("Setup", "Haptic", 1);
joy_ipt_MenuNew = INI_GetPreferenceLong("Setup", "joy_ipt_MenuNew", 0);
k_Up = INI_GetPreferenceLong("Keyboard", "MoveUp", SC_UP);
k_Down = INI_GetPreferenceLong("Keyboard", "MoveDn", SC_DOWN);
k_Left = INI_GetPreferenceLong("Keyboard", "MoveLeft", SC_LEFT);
k_Right = INI_GetPreferenceLong("Keyboard", "MoveRight", SC_RIGHT);
k_Fire = INI_GetPreferenceLong("Keyboard", "Fire", SC_CTRL);
k_FireSp = INI_GetPreferenceLong("Keyboard", "FireSp", SC_ALT);
k_ChangeSp = INI_GetPreferenceLong("Keyboard", "ChangeSp", SC_SPACE);
k_Mega = INI_GetPreferenceLong("Keyboard", "MegaFire", SC_RIGHT_SHIFT);
m_lookup[0] = INI_GetPreferenceLong("Mouse", "Fire", 0);
m_lookup[1] = INI_GetPreferenceLong("Mouse", "FireSp", 1);
m_lookup[2] = INI_GetPreferenceLong("Mouse", "ChangeSp", 2);
j_lookup[0] = INI_GetPreferenceLong("JoyStick", "Fire", 0);
j_lookup[1] = INI_GetPreferenceLong("JoyStick", "FireSp", 1);
j_lookup[2] = INI_GetPreferenceLong("JoyStick", "ChangeSp", 2);
j_lookup[3] = INI_GetPreferenceLong("JoyStick", "MegaFire", 3);
}
+28
View File
@@ -0,0 +1,28 @@
#pragma once
typedef enum
{
I_KEYBOARD,
I_MOUSE,
I_JOYSTICK,
I_FORCE
}ITYPE;
#define BUT_1 ( buttons[0] )
#define BUT_2 ( buttons[1] )
#define BUT_3 ( buttons[2] )
#define BUT_4 ( buttons[3] )
extern int buttons[4];
extern int control;
extern int haptic;
extern int joy_ipt_MenuNew;
void IPT_LoadPrefs(void);
void IPT_GetButtons(void);
void IPT_Start(void);
void IPT_PauseControl(int flag);
void IPT_FMovePlayer(int addx, int addy);
void IPT_MovePlayer(void);
void IPT_End(void);
void IPT_Init(void);
+933
View File
@@ -0,0 +1,933 @@
#include <string.h>
#include "common.h"
#include "rap.h"
#include "i_video.h"
#include "gfxapi.h"
#include "glbapi.h"
#include "fx.h"
#include "imsapi.h"
#include "movie.h"
#include "kbdapi.h"
#include "windows.h"
#include "fileids.h"
FRAME frm[90];
/***************************************************************************
INTRO_City () - Shows City with planes flying into it
***************************************************************************/
int
INTRO_City(
void
)
{
int loop;
int maxframes = 30;
int framecnt = maxframes - 1;
FRAME *cur = frm;
for (loop = 0; loop < maxframes; loop++, cur++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 8;
cur->numframes = framecnt--;
cur->item = FILE141_CHASE_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
cur->fx_vol = 0;
cur->fx_xpos = 127;
if (loop == 4)
{
cur->soundfx = FX_FLYBY;
cur->fx_xpos = 210;
}
if (loop == 9)
{
cur->soundfx = FX_FLYBY;
cur->fx_xpos = 100;
}
}
cur = frm;
cur->startf = M_FADEIN;
cur->startsteps = 128;
if (MOVIE_Play(frm, 1, palette) == K_SKIPALL)
return 1;
SND_StopPatches();
return 0;
}
/***************************************************************************
INTRO_Side1 () - Show Side OF Player ship going thru city
***************************************************************************/
int
INTRO_Side1(
void
)
{
int loop;
int maxframes = 20;
int framecnt = maxframes - 1;
FRAME *cur = frm;
MOVIE_BPatch(FX_JETSND);
for (loop = 0; loop < maxframes; loop++, cur++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 18;
cur->numframes = framecnt--;
cur->item = FILE15f_SHIPSD1_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->fx_vol = 127;
cur->fx_xpos = 127;
cur->soundfx = -1;
}
if (MOVIE_Play(frm, 2, palette) == K_SKIPALL)
return 1;
return 0;
}
/***************************************************************************
INTRO_Pilot () - Shows Pilots Face with lights moving thru
***************************************************************************/
int
INTRO_Pilot(
void
)
{
int loop;
int maxframes = 21;
int framecnt = maxframes - 1;
FRAME *cur = frm;
MOVIE_BPatch(FX_IJETSND);
for (loop = 0; loop < maxframes; loop++, cur++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 10;
cur->numframes = framecnt--;
cur->item = FILE173_PILOT_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
cur->fx_vol = 127;
cur->fx_xpos = 127;
}
if (MOVIE_Play(frm, 1, palette) == K_SKIPALL)
return 1;
return 0;
}
/***************************************************************************
INTRO_Explosion () - Bad Guy Blowing UP
***************************************************************************/
int
INTRO_Explosion(
void
)
{
int loop;
int maxframes = 22;
int framecnt = maxframes - 1;
FRAME *cur = frm;
MOVIE_BPatch(FX_EJETSND);
for (loop = 0; loop < maxframes; loop++, cur++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 12;
cur->numframes = framecnt--;
cur->item = FILE19c_EXPLO_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
cur->fx_vol = 127;
cur->fx_xpos = 127;
if (loop >= 2 && loop < 10)
{
cur->soundfx = FX_INTROHIT;
cur->fx_xpos = 0x6e + (wrand() % 40);
}
if (loop >= 8)
{
if (loop & 1)
{
cur->soundfx = FX_AIREXPLO;
}
}
}
cur--;
cur->soundfx = FX_AIREXPLO;
cur->endf = M_FADEOUT;
cur->red = 63;
cur->green = 28;
cur->blue = 3;
cur->endsteps = 60;
cur++;
if (MOVIE_Play(frm, 1, palette) == K_SKIPALL)
return 1;
return 0;
}
/***************************************************************************
INTRO_Side2 () - Player Side flying thru city Shooting
***************************************************************************/
int
INTRO_Side2(
void
)
{
int loop, opt;
int maxframes = 20;
int framecnt = maxframes - 1;
FRAME *cur = frm;
MOVIE_BPatch(FX_JETSND);
for (loop = 0; loop < maxframes; loop++, cur++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 18;
cur->numframes = framecnt--;
cur->item = FILE15f_SHIPSD1_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
cur->fx_vol = 50;
cur->fx_xpos = 127;
cur->soundfx = -1;
}
opt = MOVIE_Play(frm, 1, palette);
if (opt == K_SKIPALL)
return 1;
if (opt == K_NEXTFRAME)
return 0;
framecnt = maxframes - 1;
cur = frm;
for (loop = 0; loop < maxframes; loop++, cur++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 18;
cur->numframes = framecnt--;
cur->item = FILE188_SHIPSD2_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
cur->fx_xpos = 127;
if (loop > 1)
cur->soundfx = FX_INTROGUN;
}
if (MOVIE_Play(frm, 1, palette) == K_SKIPALL)
return 1;
SND_StopPatches();
return 0;
}
/***************************************************************************
INTRO_Base() - Base Landing at sunset
***************************************************************************/
int
INTRO_Base(
void
)
{
int loop, maxframes, framecnt;
FRAME *cur;
maxframes = 30;
framecnt = maxframes - 1;
cur = frm;
if (!GAME2)
return 1;
for (loop = 0; loop < maxframes; loop++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 10;
cur->numframes = framecnt--;
cur->item = FILE20e_BASE_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
cur++;
}
cur = frm;
cur->startf = M_FADEIN;
cur->startsteps = 128;
if (MOVIE_Play(frm, 1, palette) == K_SKIPALL)
return 1;
return 0;
}
/***************************************************************************
INTRO_Landing () - Ship Landing on Base
***************************************************************************/
int
INTRO_Landing(
void
)
{
int loop, maxframes, framecnt;
FRAME *cur;
maxframes = 33;
framecnt = maxframes - 1;
cur = frm;
for (loop = 0; loop < maxframes; loop++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 10;
cur->numframes = framecnt--;
cur->item = FILE1bd_LANDING_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
cur++;
}
cur--;
cur->startf = M_FADEOUT;
cur->startsteps = 64;
cur->endf = M_PALETTE;
cur->endsteps = 64;
if (MOVIE_Play(frm, 1, palette) == K_SKIPALL)
return 1;
return 0;
}
/***************************************************************************
INTRO_Death2 () - Ground Death Scene
***************************************************************************/
int
INTRO_Death2(
void
)
{
int loop, maxframes, framecnt;
FRAME *cur;
maxframes = 6;
framecnt = maxframes - 1;
cur = frm;
for (loop = 0; loop < maxframes; loop++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 3;
cur->numframes = framecnt--;
cur->item = FILE1b2_SDEATH_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
cur++;
}
if (MOVIE_Play(frm, 8, palette) == K_SKIPALL)
return 1;
GFX_FadeOut(0, 0, 0, 100);
memset(displaybuffer, 0, 64000);
GFX_MarkUpdate(0, 0, 320, 200);
GFX_DisplayUpdate();
return 0;
}
/***************************************************************************
INTRO_Death1 () - Air Death Scene
***************************************************************************/
int
INTRO_Death1(
void
)
{
int loop, maxframes, framecnt;
FRAME *cur;
maxframes = 30;
framecnt = maxframes - 1;
cur = frm;
for (loop = 0; loop < maxframes; loop++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 11;
cur->numframes = framecnt--;
cur->item = FILE1de_DOWN_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
cur++;
}
if (MOVIE_Play(frm, 1, palette) == K_SKIPALL)
return 1;
return 0;
}
/***************************************************************************
INTRO_Death () - Death Scene
***************************************************************************/
int
INTRO_Death(
void
)
{
if (INTRO_Death1())
return 1;
if (INTRO_Death2())
return 1;
return 0;
}
/***************************************************************************
INTRO_Game1End () - Game 1 Victory
***************************************************************************/
int
INTRO_Game1End(
void
)
{
int loop, maxframes, framecnt;
FRAME *cur;
maxframes = 5;
framecnt = maxframes - 1;
cur = frm;
for (loop = 0; loop < maxframes; loop++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 4;
cur->numframes = framecnt--;
cur->item = FILE1b8_GAME1END_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
cur++;
}
if (MOVIE_Play(frm, 8, palette) == K_SKIPALL)
return 1;
GFX_FadeOut(0, 0, 0, 120);
memset(displaybuffer, 0, 64000);
GFX_MarkUpdate(0, 0, 320, 200);
GFX_DisplayUpdate();
GFX_SetPalette(palette, 0);
return 0;
}
/***************************************************************************
INTRO_Game2End () - Game 2 Victory
***************************************************************************/
int
INTRO_Game2End(
void
)
{
int loop, maxframes, framecnt;
FRAME *cur;
maxframes = 25;
framecnt = maxframes - 1;
cur = frm;
for (loop = 0; loop < maxframes; loop++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 4;
cur->numframes = framecnt--;
cur->item = FILE22c_GAME2END_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
if (loop == 22)
{
cur->soundfx = FX_AIREXPLO;
cur->fx_xpos = 127;
}
if (loop == 24)
{
cur->soundfx = FX_AIREXPLO;
cur->fx_xpos = 127;
}
cur++;
}
if (MOVIE_Play(frm, 1, palette) == K_SKIPALL)
return 1;
GFX_FadeOut(0, 0, 0, 120);
memset(displaybuffer, 0, 64000);
GFX_MarkUpdate(0, 0, 320, 200);
GFX_DisplayUpdate();
GFX_SetPalette(palette, 0);
return 0;
}
/***************************************************************************
INTRO_Game3End () - Game 3 Victory
***************************************************************************/
int
INTRO_Game3End(
void
)
{
int loop, maxframes, framecnt;
FRAME *cur;
maxframes = 39;
framecnt = maxframes - 1;
cur = frm;
MOVIE_BPatch(FX_JETSND);
for (loop = 0; loop < maxframes; loop++)
{
cur->holdframe = 0;
cur->opt = M_ANIM;
cur->framerate = 8;
cur->numframes = framecnt--;
cur->item = FILE3c5_GAME3END_AGX + loop;
cur->startf = M_NORM;
cur->startsteps = 0;
cur->endf = M_NORM;
cur->endsteps = 0;
cur->red = 0;
cur->green = 0;
cur->blue = 0;
cur->songid = -1;
cur->songopt = S_PLAY;
cur->songstep = 0;
cur->soundfx = -1;
if (loop == 30)
{
cur->soundfx = FX_AIREXPLO;
cur->fx_xpos = 100;
}
if (loop == 32)
{
cur->soundfx = FX_AIREXPLO;
cur->fx_xpos = 100;
}
cur++;
}
if (MOVIE_Play(frm, 1, palette) == K_SKIPALL)
return 1;
GFX_FadeOut(0, 0, 0, 120);
memset(displaybuffer, 0, 64000);
GFX_MarkUpdate(0, 0, 320, 200);
GFX_DisplayUpdate();
GFX_SetPalette(palette, 0);
return 0;
}
/***************************************************************************
INTRO_EndGame() - Ends the current game anims
***************************************************************************/
void
INTRO_EndGame(
int game
)
{
IMS_StartAck();
if (!gameflag[game])
return;
if (game > 2)
game = 2;
while (IMS_IsAck())
{
}
IMS_StartAck();
switch (game)
{
default:
case 0:
INTRO_Game1End();
break;
case 1:
INTRO_Game2End();
break;
case 2:
INTRO_Game3End();
break;
}
while (IMS_IsAck())
{
}
IMS_StartAck();
INTRO_Base();
while (IMS_IsAck())
{
}
IMS_StartAck();
INTRO_Landing();
while (IMS_IsAck())
{
}
IMS_StartAck();
WIN_WinGame(game);
if (game < 1)
WIN_Order();
}
/***************************************************************************
INTRO_Taiwan (
***************************************************************************/
void
INTRO_Taiwan(
void
)
{
int local_cnt, loop;
char *pic1;
char *pal1;
local_cnt = GFX_GetFrameCount();
framecount = 0;
pic1 = (char*)GLB_GetItem(FILE12f_TAIWARN_PIC);
pal1 = GLB_GetItem(FILE130_TAIPAL_DAT);
GFX_FadeOut(0, 0, 0, 5);
GFX_PutImage(pic1, 0, 0, 0);
GFX_DisplayUpdate();
GFX_FadeIn(pal1, 64);
for (loop = 0; loop < 0x2d; loop++)
{
local_cnt = GFX_GetFrameCount();
if (IMS_IsAck())
break;
while (GFX_GetFrameCount() - local_cnt < 4)
{
}
I_GetNeedResize(false);
}
GFX_FadeOut(0, 0, 0, 63);
GLB_FreeItem(FILE130_TAIPAL_DAT);
GLB_FreeItem(FILE12f_TAIWARN_PIC);
}
/***************************************************************************
INTRO_Credits() - Credits Screen
***************************************************************************/
int
INTRO_Credits(
void
)
{
char *pic1, *pic2;
char *pal1, *pal2;
int local_cnt, loop;
local_cnt = GFX_GetFrameCount();
framecount = 0;
pic1 = (char*)GLB_GetItem(FILE12b_APOGEE_PIC);
pal1 = GLB_GetItem(FILE12c_POGPAL_DAT);
GFX_FadeOut(0, 0, 0, 5);
GFX_PutImage(pic1, 0, 0, 0);
GFX_DisplayUpdate();
GFX_FadeIn(pal1, 64);
if (bday_num != -1 && dig_flag)
SND_Patch(FX_THEME, 127);
else
SND_PlaySong(FILE061_APOGEE_MUS, 0, 0);
for (loop = 0; loop < 30; loop++)
{
local_cnt = GFX_GetFrameCount();
if (IMS_IsAck())
break;
while (GFX_GetFrameCount() - local_cnt < 4)
{
}
I_GetNeedResize(false);
}
if (bday_num != -1 && dig_flag)
{
while (SND_IsPatchPlaying(FX_THEME)) {
I_GetEvent();
I_GetNeedResize(false);
}
}
else
{
while (SND_IsSongPlaying() && !IMS_IsAck()) {
I_GetEvent();
I_GetNeedResize(false);
}
}
GFX_FadeOut(0, 0, 0, 63);
GLB_FreeItem(FILE12c_POGPAL_DAT);
GLB_FreeItem(FILE12b_APOGEE_PIC);
SND_PlaySong(-1, 0, 1);
memset(displayscreen, 0, 64000);
memset(displaybuffer, 0, 64000);
pic2 = (char*)GLB_GetItem(FILE12d_CYGNUS_PIC);
pal2 = GLB_GetItem(FILE12e_CYGPAL_DAT);
GFX_PutImage(pic2, 0, 0, 0);
GFX_DisplayUpdate();
GFX_FadeIn(pal2, 64);
GLB_CacheItem(FILE056_RINTRO_MUS);
for (loop = 0; loop < 65; loop++)
{
if (IMS_IsAck() && loop > 0)
break;
if (loop == 1 || loop == 40)
SND_Patch(FX_BOSS1, 127);
if (loop == 45)
SND_PlaySong(FILE056_RINTRO_MUS, 1, 1);
if (KBD_Key(SC_ESC))
break;
local_cnt = GFX_GetFrameCount();
while (GFX_GetFrameCount() - local_cnt < 3)
{
}
I_GetNeedResize(false);
}
GFX_FadeOut(0, 0, 0, 63);
memset(displaybuffer, 0, 64000);
GFX_MarkUpdate(0, 0, 320, 200);
GFX_DisplayUpdate();
GFX_SetPalette(palette, 0);
GLB_FreeItem(FILE12e_CYGPAL_DAT);
GLB_FreeItem(FILE12d_CYGNUS_PIC);
IMS_StartAck();
return 0;
}
/***************************************************************************
INTRO_BaseLanding() - BaseLanding PLays all needed MOVES
***************************************************************************/
void
INTRO_BaseLanding(
void
)
{
if (!GAME2)
return;
if (INTRO_Base())
return;
if (INTRO_Landing())
return;
}
/***************************************************************************
INTRO_PlayMain() - Plays Main Intro
***************************************************************************/
int
INTRO_PlayMain(
void
)
{
if (INTRO_City())
return 1;
if (INTRO_Side1())
return 1;
if (INTRO_Pilot())
return 1;
if (INTRO_Side2())
return 1;
if (INTRO_Explosion())
return 1;
return 0;
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
int INTRO_Credits(void);
int INTRO_PlayMain(void);
int INTRO_Landing(void);
int INTRO_Death(void);
void INTRO_EndGame(int game);
+328
View File
@@ -0,0 +1,328 @@
#include "SDL.h"
#include "i_video.h"
#include "joyapi.h"
int joy_ack;
bool Up, Down, Left, Right;
bool Start, Back, LeftShoulder, RightShoulder;
bool AButton, BButton, XButton, YButton;
int16_t StickX, StickY, TriggerLeft, TriggerRight;
SDL_GameController* ControllerHandles[MAX_CONTROLLERS];
SDL_Haptic* RumbleHandles[MAX_CONTROLLERS] ;
int MaxJoysticks;
int ControllerIndex;
int JoystickIndex;
int AButtonconvert, BButtonconvert, XButtonconvert, YButtonconvert;
static unsigned int lastTime = 0;
/***************************************************************************
IPT_CalJoy() - Open Gamecontroller
***************************************************************************/
void
IPT_CalJoy(
void
)
{
SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC);
MaxJoysticks = SDL_NumJoysticks();
ControllerIndex = 0;
AButtonconvert = 0;
BButtonconvert = 0;
XButtonconvert = 0;
YButtonconvert = 0;
for (JoystickIndex = 0; JoystickIndex < MaxJoysticks; ++JoystickIndex)
{
if (!SDL_IsGameController(JoystickIndex))
{
continue;
}
if (ControllerIndex >= MAX_CONTROLLERS)
{
break;
}
ControllerHandles[ControllerIndex] = SDL_GameControllerOpen(JoystickIndex);
RumbleHandles[ControllerIndex] = SDL_HapticOpen(JoystickIndex);
if (SDL_HapticRumbleInit(RumbleHandles[ControllerIndex]) != 0)
{
SDL_HapticClose(RumbleHandles[ControllerIndex]);
RumbleHandles[ControllerIndex] = 0;
}
ControllerIndex++;
GetJoyButtonMapping();
}
}
/***************************************************************************
IPT_CloJoy() - Close Gamecontroller
***************************************************************************/
void
IPT_CloJoy(
void
)
{
for (ControllerIndex = 0; ControllerIndex < MAX_CONTROLLERS; ++ControllerIndex)
{
if (ControllerHandles[ControllerIndex])
{
if (RumbleHandles[ControllerIndex])
SDL_HapticClose(RumbleHandles[ControllerIndex]);
SDL_GameControllerClose(ControllerHandles[ControllerIndex]);
}
}
}
/***************************************************************************
I_HandleJoystickEvent() - Get current button or axis status
***************************************************************************/
void
I_HandleJoystickEvent(
SDL_Event *sdlevent
)
{
for (ControllerIndex = 0;
ControllerIndex < MAX_CONTROLLERS;
++ControllerIndex)
{
if (ControllerHandles[ControllerIndex] != 0 && SDL_GameControllerGetAttached(ControllerHandles[ControllerIndex]))
{
Up = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_UP);
Down = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_DOWN);
Left = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_LEFT);
Right = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
Start = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_START);
Back = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_BACK);
LeftShoulder = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
RightShoulder = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
AButton = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_A);
BButton = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_B);
XButton = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_X);
YButton = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_Y);
StickX = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTX) / 8000;
StickY = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTY) / 8000;
TriggerLeft = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_TRIGGERLEFT) / 8000;
TriggerRight = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_TRIGGERRIGHT) / 8000;
}
if (sdlevent->type == SDL_CONTROLLERBUTTONUP)
joy_ack = 0;
if (sdlevent->type == SDL_CONTROLLERBUTTONDOWN)
joy_ack = 1;
}
}
/***************************************************************************
GetJoyButtonMapping() - Detect connected Gamecontroller and map buttons for it
***************************************************************************/
void
GetJoyButtonMapping(
void
)
{
for (ControllerIndex = 0;
ControllerIndex < MAX_CONTROLLERS;
++ControllerIndex)
{
switch (SDL_GameControllerTypeForIndex(ControllerIndex))
{
case SDL_CONTROLLER_TYPE_PS3:
case SDL_CONTROLLER_TYPE_PS4:
case SDL_CONTROLLER_TYPE_PS5:
AButtonconvert = 0;
BButtonconvert = 1;
XButtonconvert = 3;
YButtonconvert = 2;
break;
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
case SDL_CONTROLLER_TYPE_XBOX360:
case SDL_CONTROLLER_TYPE_XBOXONE:
AButtonconvert = 0;
BButtonconvert = 1;
XButtonconvert = 2;
YButtonconvert = 3;
break;
default:
if ((AButtonconvert == 0) && (BButtonconvert == 0) && (XButtonconvert == 0) && (YButtonconvert == 0))
{
AButtonconvert = 0;
BButtonconvert = 1;
XButtonconvert = 2;
YButtonconvert = 3;
}
break;
}
}
}
/***************************************************************************
IPT_CalJoyRumbleLow() - Gamecontroller rumbles low
***************************************************************************/
void
IPT_CalJoyRumbleLow(
void
)
{
for (ControllerIndex = 0;
ControllerIndex < MAX_CONTROLLERS;
++ControllerIndex)
{
if (ControllerHandles[ControllerIndex])
SDL_GameControllerRumble(ControllerHandles[ControllerIndex], 0x3fff, 0x3fff, 1000);
}
}
/***************************************************************************
IPT_CalJoyRumbleMedium() - Gamecontroller rumbles medium
***************************************************************************/
void
IPT_CalJoyRumbleMedium(
void
)
{
for (ControllerIndex = 0;
ControllerIndex < MAX_CONTROLLERS;
++ControllerIndex)
{
if (ControllerHandles[ControllerIndex])
SDL_GameControllerRumble(ControllerHandles[ControllerIndex], 0x7ffe, 0x7ffe, 1000);
}
}
/***************************************************************************
IPT_CalJoyRumbleHigh() - Gamecontroller rumbles high
***************************************************************************/
void
IPT_CalJoyRumbleHigh(
void
)
{
for (ControllerIndex = 0;
ControllerIndex < MAX_CONTROLLERS;
++ControllerIndex)
{
if (ControllerHandles[ControllerIndex])
SDL_GameControllerRumble(ControllerHandles[ControllerIndex], 0xbffd, 0xbffd, 1000);
}
}
/***************************************************************************
JOY_Wait() - Waits for button to be released
***************************************************************************/
void
JOY_Wait(
int button
)
{
while (StickX || StickY || Up || Down || Left || Right || Start || Back || LeftShoulder || RightShoulder || AButton || BButton || XButton || YButton)
{
I_GetEvent();
}
}
/***************************************************************************
JOY_IsKey() - Tests to see if button is down if so waits for release
***************************************************************************/
int
JOY_IsKey(
int button
)
{
if (StickX || StickY || Up || Down || Left || Right || Start || Back || LeftShoulder || RightShoulder || AButton || BButton || XButton || YButton)
{
JOY_Wait(button);
return 1;
}
return 0;
}
/***************************************************************************
JOY_IsKeyInGameStart() - Tests to see if button is down if so waits for release
***************************************************************************/
int
JOY_IsKeyInGameStart(
int button
)
{
if (Start)
{
JOY_Wait(button);
return 1;
}
return 0;
}
/***************************************************************************
JOY_IsKeyInGameBack() - Tests to see if button is down if so waits for release
***************************************************************************/
int
JOY_IsKeyInGameBack(
int button
)
{
if (Back)
{
JOY_Wait(button);
return 1;
}
return 0;
}
/***************************************************************************
JOY_IsKeyMenu() - Tests to see if button is down if so waits for release
***************************************************************************/
int
JOY_IsKeyMenu(
int button
)
{
if (RightShoulder || Back || BButton)
{
JOY_Wait(button);
return 1;
}
return 0;
}
/***************************************************************************
JOY_IsScroll() - Scroll cursor in menu
***************************************************************************/
int
JOY_IsScroll(
int scrollflag
)
{
unsigned int currentTime;
currentTime = SDL_GetTicks();
if (currentTime > lastTime + 200)
{
lastTime = currentTime;
return 1;
}
return 0;
}
+30
View File
@@ -0,0 +1,30 @@
#include "SDL.h"
#define MAX_CONTROLLERS 4
extern SDL_GameController* ControllerHandles[MAX_CONTROLLERS];
extern SDL_Haptic* RumbleHandles[MAX_CONTROLLERS];
extern int joy_ack;
extern bool Up, Down, Left, Right;
extern bool Start, Back, LeftShoulder, RightShoulder;
extern bool AButton, BButton, XButton, YButton;
extern int16_t StickX, StickY, TriggerLeft, TriggerRight;
extern int AButtonconvert, BButtonconvert, XButtonconvert, YButtonconvert;
void IPT_CalJoy(void);
void IPT_CloJoy(void);
void IPT_CalJoyRumbleLow(void);
void IPT_CalJoyRumbleMedium(void);
void IPT_CalJoyRumbleHigh(void);
int JOY_IsKey(int button);
void JOY_Wait(int button);
int JOY_IsKeyInGameStart(int button);
int JOY_IsKeyInGameBack(int button);
int JOY_IsKeyMenu(int button);
void GetJoyButtonMapping(void);
int JOY_IsScroll(int scrollflag);
+313
View File
@@ -0,0 +1,313 @@
#include <string.h>
#include <ctype.h>
#include "SDL.h"
#include "common.h"
#include "kbdapi.h"
#include "i_video.h"
int kbd_ack;
int capslock;
int lastscan, lastascii;
int keyboard[256];
void (*kbdhook)(void);
int ASCIINames[] = {
0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x08, 0x09,
0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, 0x6F, 0x70, 0x5B, 0x5D, 0x0D, 0x00, 0x61, 0x73,
0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B, 0x27, 0x60, 0x00, 0x5C, 0x7A, 0x78, 0x63, 0x76,
0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x00, 0x2A, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0x38, 0x39, 0x2D, 0x34, 0x35, 0x36, 0x2B, 0x31,
0x32, 0x33, 0x30, 0x7F, 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, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x08, 0x09,
0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49, 0x4F, 0x50, 0x7B, 0x7D, 0x0D, 0x00, 0x41, 0x53,
0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A, 0x22, 0x7E, 0x00, 0x7C, 0x5A, 0x58, 0x43, 0x56,
0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x00, 0x2A, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0x38, 0x39, 0x2D, 0x34, 0x35, 0x36, 0x2B, 0x31,
0x32, 0x33, 0x30, 0x7F, 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,
};
int ScanCodeMap[] = {
0,
0,
0,
0,
0x1e,
0x30,
0x2e,
0x20,
0x12,
0x21,
0x22,
0x23,
0x17,
0x24,
0x25,
0x26,
0x32,
0x31,
0x18,
0x19,
0x10,
0x13,
0x1f,
0x14,
0x16,
0x2f,
0x11,
0x2d,
0x15,
0x2c,
0x02,
0x03,
0x04,
0x05,
0x06,
0x07,
0x08,
0x09,
0x0a,
0x0b,
0x1c,
0x01,
0x0e,
0x0f,
0x39,
0x0c,
0x0d,
0x1a,
0x1b,
0x2b,
0,
0x27,
0x28,
0x29,
0x33,
0x34,
0x35,
0x3a,
0x3b,
0x3c,
0x3d,
0x3e,
0x3f,
0x40,
0x41,
0x42,
0x43,
0x44,
0x56,
0x58,
0xe0,
0x46,
0xe0,
0x52,
0x47,
0x49,
0x53,
0x4f,
0x51,
0x4d,
0x4b,
0x50,
0x48,
0x45,
0xe0,
0x37,
0x4a,
0x4e,
0x1c,
0x4f,
0x50,
0x51,
0x4b,
0x4c,
0x4d,
0x47,
0x48,
0x49,
0x52,
0x53,
};
/***************************************************************************
I_HandleKeyboardEvent() - Get current key status
***************************************************************************/
void
I_HandleKeyboardEvent(
SDL_Event *sdlevent
)
{
int key = 0;
if (sdlevent->type != SDL_KEYDOWN && sdlevent->type != SDL_KEYUP)
return;
switch (sdlevent->key.keysym.scancode)
{
case SDL_SCANCODE_LCTRL:
case SDL_SCANCODE_RCTRL:
key = 0x1d;
break;
case SDL_SCANCODE_LSHIFT:
key = 0x2a;
break;
case SDL_SCANCODE_RSHIFT:
key = 0x36;
break;
case SDL_SCANCODE_LALT:
case SDL_SCANCODE_RALT:
key = 0x38;
break;
#ifdef __ANDROID__
case SDL_SCANCODE_AC_BACK:
key = 0x01;
break;
#endif //__ANDROID__
default:
if (sdlevent->key.keysym.scancode >= 0 && sdlevent->key.keysym.scancode < 100)
key = ScanCodeMap[sdlevent->key.keysym.scancode];
break;
}
if (!key)
return;
if (sdlevent->type == SDL_KEYUP)
{
kbd_ack = 0;
keyboard[key] = 0;
if (key == SC_CAPS_LOCK)
capslock = 0;
}
else
{
kbd_ack = 1;
lastscan = key;
keyboard[key] = 1;
if (key && KBD_ISCAPS != 0)
lastascii = ASCIINames[128 + key];
else
lastascii = ASCIINames[key];
if (key == SC_CAPS_LOCK)
capslock = 1;
}
}
/***************************************************************************
KBD_Clear() - Resets all flags
***************************************************************************/
void
KBD_Clear(
void
)
{
lastscan = SC_NONE;
memset(keyboard, 0, sizeof(keyboard));
}
/***************************************************************************
KBD_SetKeyboardHook() - Sets User function to call from keyboard handler
***************************************************************************/
void // RETURN: none
KBD_SetKeyboardHook(
void (*hook)(void) // INPUT : pointer to function
)
{
kbdhook = hook;
}
/***************************************************************************
KBD_Ascii2Scan () - converts most ASCII chars to keyboard scan code
***************************************************************************/
int // RETURN: scan code
KBD_Ascii2Scan(
int ascii // INPUT : ASCII character
)
{
int loop;
ascii = tolower(ascii);
for (loop = 0; loop < 100; loop++)
{
if (ASCIINames[loop] == ascii)
return loop;
}
return 0;
}
/***************************************************************************
KBD_Wait() - Waits for Key to be released
***************************************************************************/
void
KBD_Wait(
int scancode // SCANCODE see kbdapi.h
)
{
while (KBD_Key(scancode))
{
I_GetEvent();
}
lastscan = SC_NONE;
lastascii = SC_NONE;
}
/***************************************************************************
KBD_IsKey() - Tests to see if key is down if so waits for release
***************************************************************************/
int
KBD_IsKey(
int scancode // SCANCODE see kbdapi.h
)
{
if (KBD_Key(scancode))
{
KBD_Wait(scancode);
return 1;
}
return 0;
}
/***************************************************************************
KBD_Install() - Sets up keyboard system
***************************************************************************/
void
KBD_Install(
void
)
{
memset(keyboard, 0, sizeof(keyboard));
}
/***************************************************************************
KBD_End() - Shuts down KBD system
***************************************************************************/
void
KBD_End(
void
)
{
}
+109
View File
@@ -0,0 +1,109 @@
#pragma once
// SCAN CODES
#define SC_NONE 0x0000
#define SC_BAD 0x00ff
#define SC_ESC 0x0001
#define SC_F1 0x003b
#define SC_F2 0x003c
#define SC_F3 0x003d
#define SC_F4 0x003e
#define SC_F5 0x003f
#define SC_F6 0x0040
#define SC_F7 0x0041
#define SC_F8 0x0042
#define SC_F9 0x0043
#define SC_F10 0x0044
#define SC_F11 0x0057
#define SC_F12 0x0058
#define SC_TAB 0x000f
#define SC_SLASH 0x002b
#define SC_CAPS_LOCK 0x003a
#define SC_LEFT_SHIFT 0x002a
#define SC_CTRL 0x001d
#define SC_ALT 0x0038
#define SC_SCROLL_LOCK 0x0046
#define SC_BACKSPACE 0x000e
#define SC_ENTER 0x001c
#define SC_RIGHT_SHIFT 0x0036
#define SC_RIGHT_ALT 0xe038
#define SC_RIGHT_CTRL 0xe010
#define SC_EXT_INSERT 0xe052
#define SC_EXT_DELETE 0xe053
#define SC_EXT_HOME 0xe047
#define SC_EXT_END 0xe04f
#define SC_EXT_PAGEUP 0xe049
#define SC_EXT_PAGEDN 0xe051
#define SC_EXT_UP 0xe048
#define SC_EXT_DN 0xe050
#define SC_EXT_LEFT 0xe04b
#define SC_EXT_RIGHT 0xe04d
#define SC_EXT_ENTER 0xe01c
#define SC_NUMLOCK 0x0045
#define SC_INSERT 0x0052
#define SC_DELETE 0x0053
#define SC_HOME 0x0047
#define SC_END 0x004f
#define SC_PAGEUP 0x0049
#define SC_PAGEDN 0x0051
#define SC_UP 0x0048
#define SC_DOWN 0x0050
#define SC_LEFT 0x004b
#define SC_RIGHT 0x004d
#define SC_1 0x0002
#define SC_2 0x0003
#define SC_3 0x0004
#define SC_4 0x0005
#define SC_5 0x0006
#define SC_6 0x0007
#define SC_7 0x0008
#define SC_8 0x0009
#define SC_9 0x000a
#define SC_0 0x000b
#define SC_Q 0x0010
#define SC_W 0x0011
#define SC_E 0x0012
#define SC_R 0x0013
#define SC_T 0x0014
#define SC_Y 0x0015
#define SC_U 0x0016
#define SC_I 0x0017
#define SC_O 0x0018
#define SC_P 0x0019
#define SC_A 0x001e
#define SC_S 0x001f
#define SC_D 0x0020
#define SC_F 0x0021
#define SC_G 0x0022
#define SC_H 0x0023
#define SC_J 0x0024
#define SC_K 0x0025
#define SC_L 0x0026
#define SC_Z 0x002c
#define SC_X 0x002d
#define SC_C 0x002e
#define SC_V 0x002f
#define SC_B 0x0030
#define SC_N 0x0031
#define SC_M 0x0032
#define SC_SPACE 0x0039
#define SC_RELEASE 0x0080
#define SC_MINUS 12
extern int keyboard[256];
extern int lastscan;
extern int lastascii;
extern int kbd_ack;
extern int capslock;
#define KBD_Key(c) keyboard[c]
#define KBD_ISCAPS (capslock+keyboard[SC_LEFT_SHIFT]+keyboard[SC_RIGHT_SHIFT])
#define KBD_LASTSCAN lastscan
#define KBD_LASTASCII lastascii
void KBD_Clear(void);
void KBD_Install(void);
void KBD_End(void);
int KBD_IsKey(int scancode);
void KBD_Wait(int scancode);
File diff suppressed because it is too large. Load diff
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include "rap.h"
typedef struct
{
int link;
int slib;
int x;
int y;
int game;
int level;
}CSPRITE;
typedef struct
{
short flats;
short fgame;
}MAZEDATA;
typedef struct
{
int sizerec;
int spriteoff;
int numsprites;
MAZEDATA map[MAP_SIZE];
}MAZELEVEL;
extern int curplr_diff;
extern MAZELEVEL *mapmem;
extern CSPRITE *csprite;
const char* RAP_InitLoadSave(void);
const char* RAP_SetupFilename(void);
void RAP_WriteDefaultSetup(void);
const char* RAP_GetPath(void);
int RAP_CheckFileInPath(const char* filename);
void RAP_ClearPlayer(void);
int RAP_IsSaveFile(PLAYEROBJ *in_plr);
int RAP_FFSaveFile(void);
void RAP_SetPlayerDiff(void);
int RAP_SavePlayer(void);
+156
View File
@@ -0,0 +1,156 @@
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 1993-2008 Raven Software
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// DESCRIPTION:
// Miscellaneous.
//
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "common.h"
// Safe string copy function that works like OpenBSD's strlcpy().
// Returns true if the string was not truncated.
bool M_StringCopy(char *dest, const char *src, size_t dest_size)
{
size_t len;
if (dest_size >= 1)
{
dest[dest_size - 1] = '\0';
strncpy(dest, src, dest_size - 1);
}
else
{
return false;
}
len = strlen(dest);
return src[len] == '\0';
}
// Safe string concat function that works like OpenBSD's strlcat().
// Returns true if string not truncated.
bool M_StringConcat(char *dest, const char *src, size_t dest_size)
{
size_t offset;
offset = strlen(dest);
if (offset > dest_size)
{
offset = dest_size;
}
return M_StringCopy(dest + offset, src, dest_size - offset);
}
// Return a newly-malloced string with all the strings given as arguments
// concatenated together.
char *M_StringJoin(const char *s, ...)
{
char *result;
const char *v;
va_list args;
size_t result_len;
result_len = strlen(s) + 1;
va_start(args, s);
for (;;)
{
v = va_arg(args, const char *);
if (v == NULL)
{
break;
}
result_len += strlen(v);
}
va_end(args);
result = (char*)malloc(result_len);
if (result == NULL)
{
EXIT_Error("M_StringJoin: Failed to allocate new string.");
return NULL;
}
M_StringCopy(result, s, result_len);
va_start(args, s);
for (;;)
{
v = va_arg(args, const char *);
if (v == NULL)
{
break;
}
M_StringConcat(result, v, result_len);
}
va_end(args);
return result;
}
// On Windows, vsnprintf() is _vsnprintf().
#ifdef _WIN32
#if _MSC_VER < 1400 /* not needed for Visual Studio 2008 */
#define vsnprintf _vsnprintf
#endif
#endif
// Safe, portable vsnprintf().
int M_vsnprintf(char *buf, size_t buf_len, const char *s, va_list args)
{
unsigned int result;
if (buf_len < 1)
{
return 0;
}
// Windows (and other OSes?) has a vsnprintf() that doesn't always
// append a trailing \0. So we must do it, and write into a buffer
// that is one byte shorter; otherwise this function is unsafe.
result = vsnprintf(buf, buf_len, s, args);
// If truncated, change the final char in the buffer to a \0.
// A negative result indicates a truncated buffer on Windows.
if (result < 0 || result >= buf_len)
{
buf[buf_len - 1] = '\0';
result = buf_len - 1;
}
return result;
}
// Safe, portable snprintf().
int M_snprintf(char *buf, size_t buf_len, const char *s, ...)
{
va_list args;
int result;
va_start(args, s);
result = M_vsnprintf(buf, buf_len, s, args);
va_end(args);
return result;
}
+5
View File
@@ -0,0 +1,5 @@
#pragma once
bool M_StringCopy(char *dest, const char *src, size_t dest_size);
bool M_StringConcat(char *dest, const char *src, size_t dest_size);
char *M_StringJoin(const char *s, ...);
int M_snprintf(char *buf, size_t buf_len, const char *s, ...);
+197
View File
@@ -0,0 +1,197 @@
#include <string.h>
#include "common.h"
#include "rap.h"
#include "movie.h"
#include "fx.h"
#include "gfxapi.h"
#include "imsapi.h"
#include "glbapi.h"
#include "i_video.h"
#include "kbdapi.h"
int back_patch = -1;
/*************************************************************************
MOVIE_BPatch() Plays Sound FX in background for one anim
*************************************************************************/
void
MOVIE_BPatch(
int soundfx
)
{
back_patch = soundfx;
SND_Patch(back_patch, 127);
}
/*************************************************************************
MOVIE_ShowFrame () - Shows an animation frame
*************************************************************************/
void
MOVIE_ShowFrame(
ANIMLINE *inpic // INPUT : pointer to animpic
)
{
if (inpic)
{
ANIM_Render(inpic);
GFX_MarkUpdate(0, 0, 320, 200);
}
}
/*************************************************************************
MOVIE_Play () - Playes an Animation
*************************************************************************/
int
MOVIE_Play(
FRAME *frame, // INPUT : pointer to array of frame defs
int numplay, // INPUT : number of times to play
char *palette // INPUT : pointer to palette
)
{
int loop, hold;
int flag = 1;
int opt = K_OK;
char fill;
char *pic;
FRAME *curfld;
memset(displaybuffer, 0, 64000);
curfld = frame;
IMS_StartAck();
while (1)
{
I_GetEvent();
pic = (char *)GLB_GetItem(curfld->item);
if (flag)
{
fill = pic[0];
memset(displaybuffer, fill, 64000);
pic++;
}
switch (curfld->startf)
{
case M_NORM:
default:
MOVIE_ShowFrame((ANIMLINE*)pic);
GFX_WaitUpdate(curfld->framerate);
break;
case M_FADEOUT:
GFX_FadeOut(curfld->red, curfld->green, curfld->blue, curfld->startsteps);
[[fallthrough]];
case M_ERASE:
memset(displaybuffer, 0, 64000);
GFX_MarkUpdate(0, 0, 320, 200);
GFX_DisplayUpdate();
break;
case M_FADEIN:
if (flag)
{
GFX_FadeOut(0, 0, 0, 2);
flag = 0;
}
MOVIE_ShowFrame((ANIMLINE*)pic);
GFX_WaitUpdate(curfld->framerate);
GFX_FadeIn(palette, curfld->startsteps);
break;
}
if (curfld->holdframe)
{
for (loop = 0; loop < curfld->holdframe; loop++)
{
hold = GFX_GetFrameCount();
while (GFX_GetFrameCount() == hold)
{
if (!SND_IsPatchPlaying(back_patch))
SND_Patch(back_patch, 127);
}
}
}
else
{
if (back_patch != -1)
{
if (!SND_IsPatchPlaying(back_patch))
SND_Patch(back_patch, 127);
}
}
if (curfld->soundfx != -1)
{
SND_Patch(curfld->soundfx, curfld->fx_xpos);
}
switch (curfld->endf)
{
case M_ERASE:
memset(displaybuffer, 0, 64000);
GFX_MarkUpdate(0, 0, 320, 200);
GFX_DisplayUpdate();
break;
case M_FADEOUT:
GFX_FadeOut(curfld->red, curfld->green, curfld->blue, curfld->endsteps);
break;
case M_FADEIN:
GFX_FadeIn(palette, curfld->startsteps);
break;
case M_PALETTE:
GFX_SetPalette(palette, 0);
break;
}
GLB_FreeItem(curfld->item);
if (!curfld->numframes)
{
if (--numplay)
{
memset(displaybuffer, 0, 64000);
curfld = frame;
flag = 1;
}
else
break;
}
else
{
if (IMS_CheckAck())
{
IMS_StartAck();
opt = K_SKIPALL;
break;
}
flag = 0;
curfld++;
}
}
if (opt)
{
KBD_Clear();
GFX_FadeOut(0, 0, 0, 16);
memset(displaybuffer, 0, 64000);
GFX_MarkUpdate(0, 0, 320, 200);
GFX_DisplayUpdate();
GFX_SetPalette(palette, 0);
}
if (back_patch != -1)
{
SND_StopPatch(back_patch);
back_patch = -1;
}
return opt;
}
+59
View File
@@ -0,0 +1,59 @@
#pragma once
typedef enum
{
M_ANIM,
M_PIC,
M_SEE_THRU
}FRAMETYPE;
typedef enum
{
M_NORM,
M_FADEIN,
M_FADEOUT,
M_PALETTE,
M_ERASE
}FRAMEOPT;
typedef enum
{
S_PLAY,
S_FADEIN,
S_FADEOUT,
S_STOP
}SONGOPTS;
typedef struct
{
unsigned short opt;
unsigned short fill;
unsigned short offset;
unsigned short length;
}ANIMLINE;
typedef struct
{
int opt; // TYPE OF DRAWING REQUIRED
int framerate; // FRAME RATE OF UPDATE
int numframes; // NUMBER OF FRAMES LEFT
int item; // ITEM # OF PICTURE
int startf; // START FRAME OPTS
int startsteps; // # OF STEPS IF FADEIN
int endf; // END FRAME OPTS
int endsteps; // # OF STEPS IN FADEOUT
int red; // RED VAL FOR FADEOUT
int green; // GREEN VAL FOR FADEOUT
int blue; // BLUE VAL FOR FADEOUT
int holdframe; // NUMBER OF TICS TO HOLD FRAME
int songid; // SONG ID TO PLAY
int songopt; // SONG OPTS
int songstep; // SONG STEPS FOR FADES
int soundfx; // SOUND FX START
int fx_vol; // SOUND FX VOLUME
int fx_xpos; // SOUND FX XPOS
}FRAME;
void ANIM_Render(ANIMLINE *inmem);
void MOVIE_BPatch(int soundfx);
int MOVIE_Play(FRAME *frame, int numplay, char *palette);
+26
View File
@@ -0,0 +1,26 @@
#include <string.h>
#include "common.h"
#include "movie.h"
#include "gfxapi.h"
#include "entypes.h"
/*************************************************************************
ANIM_Render () - Renders an ANIM FRAME
*************************************************************************/
void
ANIM_Render(
ANIMLINE *inmem
)
{
while (LE_USHORT(inmem->opt))
{
int l = LE_USHORT(inmem->length);
int p = LE_USHORT(inmem->offset);
inmem++;
memcpy(&displaybuffer[p], inmem, l);
inmem = (ANIMLINE*)((char*)inmem + l);
}
}
+262
View File
@@ -0,0 +1,262 @@
#ifndef __ANDROID__
#ifdef __linux__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <alsa/asoundlib.h>
#include "SDL.h"
#include "common.h"
#include "musapi.h"
#include "fx.h"
static snd_seq_t* seq;
static int client;
static snd_seq_event_t ev;
/***************************************************************************
fatal() - Prints an error message to stderr, and dies
***************************************************************************/
static void
fatal(
const char* msg,
...
)
{
va_list ap;
va_start(ap, msg);
vfprintf(stderr, msg, ap);
va_end(ap);
fputc('\n', stderr);
exit(EXIT_FAILURE);
}
/***************************************************************************
check_snd() - Error handling for ALSA functions
***************************************************************************/
static void
check_snd(
const char* operation,
int err
)
{
if (err < 0)
fatal("Cannot %s - %s", operation, snd_strerror(err));
}
/***************************************************************************
ALSA_Init() -
***************************************************************************/
int
ALSA_Init(
int option
)
{
int err;
// ALSA seq
err = snd_seq_open(&seq, "default", SND_SEQ_OPEN_OUTPUT, 0);
if (err)
{
printf("Error opening ALSA seq: %s\n", snd_strerror(err));
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Raptor", "Error opening ALSA seq", NULL);
exit(err);
}
err = snd_seq_set_client_name(seq, "Raptor");
check_snd("set client name", err);
client = snd_seq_client_id(seq);
check_snd("get client id", client);
int port = snd_seq_create_simple_port(seq, "Raptor",
SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ | SND_SEQ_PORT_CAP_SYNC_READ,
SND_SEQ_PORT_TYPE_APPLICATION | SND_SEQ_PORT_TYPE_MIDI_GENERIC);
if (port < 0)
{
printf("Error opening ALSA port: %s\n", snd_strerror(port));
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Raptor", "Error opening ALSA port", NULL);
snd_seq_close(seq);
exit(port);
}
err = snd_seq_connect_to(seq, port, alsaclient, alsaport);
if (err)
{
printf("Couldn't connect to synth: %s\n", snd_strerror(err));
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Raptor", "Couldn't connect to synth", NULL);
snd_seq_close(seq);
exit(err);
}
err = snd_seq_set_output_buffer_size(seq, 512);
if (err)
{
printf("Couldn't set buffer size: %s\n", snd_strerror(err));
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Raptor", "Couldn't set buffer size", NULL);
snd_seq_close(seq);
exit(err);
}
printf("%d:%d connected to %u:%u\n", client, 0, alsaclient, alsaport);
snd_seq_ev_clear(&ev);
snd_seq_ev_set_source(&ev, 0);
snd_seq_ev_set_subs(&ev);
snd_seq_ev_set_direct(&ev);
return 1;
}
/***************************************************************************
ALSA_DeInit() -
***************************************************************************/
void
ALSA_DeInit(
void
)
{
snd_seq_close(seq);
}
/***************************************************************************
MPU_MapChannel() -
***************************************************************************/
static unsigned int
MPU_MapChannel(
unsigned chan
)
{
if (chan < 9)
return chan;
if (chan == 15)
return 9;
return chan + 1;
}
/***************************************************************************
KeyOffEvent() -
***************************************************************************/
static void
KeyOffEvent(
unsigned int chan,
unsigned int key
)
{
int err;
snd_seq_ev_set_noteoff(&ev, MPU_MapChannel(chan), key, 0);
err = snd_seq_event_output_direct(seq, &ev);
check_snd("KeyOffEvent", err);
}
/***************************************************************************
KeyOnEvent() -
***************************************************************************/
static void
KeyOnEvent(
int chan,
unsigned int key,
unsigned int volume
)
{
int err;
snd_seq_ev_set_noteon(&ev, MPU_MapChannel(chan), key, volume);
err = snd_seq_event_output_direct(seq, &ev);
check_snd("KeyOnEvent", err);
}
/***************************************************************************
ProgramEvent() -
***************************************************************************/
static void
ProgramEvent(
unsigned int chan,
unsigned int param
)
{
int err;
snd_seq_ev_set_pgmchange(&ev, MPU_MapChannel(chan), param);
err = snd_seq_event_output_direct(seq, &ev);
check_snd("ProgramEvent", err);
}
/***************************************************************************
PitchBendEvent() -
***************************************************************************/
static void
PitchBendEvent(
unsigned int chan,
int bend
)
{
int err;
snd_seq_ev_set_pitchbend(&ev, MPU_MapChannel(chan), bend);
err = snd_seq_event_output_direct(seq, &ev);
check_snd("PitchBendEvent", err);
}
/***************************************************************************
AllNotesOffEvent() -
***************************************************************************/
static void
AllNotesOffEvent(
unsigned int chan,
unsigned int param
)
{
int err;
snd_seq_ev_set_pgmchange(&ev, chan, param);
err = snd_seq_event_output_direct(seq, &ev);
check_snd("AllNotesOffEvent", err);
}
/***************************************************************************
ControllerEvent() -
***************************************************************************/
static void
ControllerEvent(
unsigned int chan,
unsigned int controller,
unsigned int param
)
{
static int event_map[] = {
0, 0, 1, 7, 10, 11, 91, 93, 64, 67, 120, 123, -1, -1, 121, -1
};
int err;
snd_seq_ev_set_controller(&ev, MPU_MapChannel(chan), event_map[controller], param);
err = snd_seq_event_output_direct(seq, &ev);
check_snd("ControllerEvent", err);
}
musdevice_t mus_device_alsa = {
ALSA_Init,
ALSA_DeInit,
NULL,
KeyOffEvent,
KeyOnEvent,
ControllerEvent,
PitchBendEvent,
ProgramEvent,
AllNotesOffEvent,
};
#endif //__linux__
#endif //__ANDROID__
+549
View File
@@ -0,0 +1,549 @@
#ifdef __APPLE__
#include <AudioUnit/AudioUnit.h>
#include <AudioToolbox/AudioToolbox.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <pthread.h>
#include "musapi.h"
enum {
CAErr_Warning = -2,
CAErr_Error = -1,
CAErr_Ok = 0,
CAErr_Uninitialised,
CAErr_AssembleAUGraph,
CAErr_InitialiseAUGraph,
CAErr_SetPCMFormat,
CAErr_Mutex,
CAErr_SetSoundBank
};
enum {
CASystem_none = 0,
CASystem_pcm = 1,
CASystem_midi = 2
};
static int ErrorCode = CAErr_Ok;
static int Initialised = CASystem_none;
static pthread_mutex_t pcmmutex, midimutex;
static AUGraph graph = 0;
static AudioUnit mixerunit, pcmunit, synthunit;
static unsigned int MidiFrameOffset = 0;
static unsigned int MidiTick = 0;
static unsigned int MidiFramesPerTick = 0;
static char *MixBuffer = 0;
static int MixBufferSize = 0;
static int MixBufferCount = 0;
static int MixBufferCurrent = 0;
static int MixBufferUsed = 0;
static void ( *MixCallBack )( void ) = 0;
static void ( *MidiCallBack)(void) = 0;
static char soundBankName[PATH_MAX+1] = "";
/***************************************************************************
_ASS_MessageOutputString() -
***************************************************************************/
static void
_ASS_MessageOutputString(
const char *str
)
{
fputs(str, stderr);
}
void (*ASS_MessageOutputString)(const char *) = _ASS_MessageOutputString;
/***************************************************************************
ASS_Message() -
***************************************************************************/
void
ASS_Message(
const char *fmt,
...
)
{
char text[256];
va_list va;
va_start(va, fmt);
vsnprintf(text, sizeof(text), fmt, va);
va_end(va);
ASS_MessageOutputString(text);
}
#define check_result(fcall, errval) \
if ((result = (fcall)) != noErr) {\
ASS_Message("CoreAudioDrv: error %d at line %d:" #fcall "\n", (int)result, __LINE__);\
ErrorCode = errval;\
return CAErr_Error;\
}
/***************************************************************************
CoreAudioDrv_PCM_Unlock() -
***************************************************************************/
void
CoreAudioDrv_PCM_Unlock(
void
)
{
if (!(Initialised & CASystem_pcm)) {
return;
}
pthread_mutex_unlock(&pcmmutex);
}
/***************************************************************************
CoreAudioDrv_PCM_Lock() -
***************************************************************************/
void
CoreAudioDrv_PCM_Lock(
void
)
{
if (!(Initialised & CASystem_pcm)) {
return;
}
pthread_mutex_lock(&pcmmutex);
}
/***************************************************************************
CoreAudioDrv_MIDI_Lock() -
***************************************************************************/
void
CoreAudioDrv_MIDI_Lock(
void
)
{
if (!(Initialised & CASystem_midi)) {
return;
}
pthread_mutex_lock(&midimutex);
}
/***************************************************************************
CoreAudioDrv_MIDI_Unlock() -
***************************************************************************/
void
CoreAudioDrv_MIDI_Unlock(
void
)
{
if (!(Initialised & CASystem_midi)) {
return;
}
pthread_mutex_unlock(&midimutex);
}
/***************************************************************************
pcmService() -
***************************************************************************/
static
OSStatus pcmService(
void *inRefCon,
AudioUnitRenderActionFlags *inActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData
)
{
UInt32 remaining, len, bufn;
char *ptr, *sptr;
(void)inRefCon; (void)inActionFlags; (void)inTimeStamp; (void)inBusNumber; (void)inNumberFrames;
if (MixCallBack == 0) return noErr;
CoreAudioDrv_PCM_Lock();
for (bufn = 0; bufn < ioData->mNumberBuffers; bufn++) {
remaining = ioData->mBuffers[bufn].mDataByteSize;
ptr = (char*) ioData->mBuffers[bufn].mData;
while (remaining > 0) {
if (MixBufferUsed == MixBufferSize) {
MixCallBack();
MixBufferUsed = 0;
MixBufferCurrent++;
if (MixBufferCurrent >= MixBufferCount) {
MixBufferCurrent -= MixBufferCount;
}
}
while (remaining > 0 && MixBufferUsed < MixBufferSize) {
sptr = MixBuffer + (MixBufferCurrent * MixBufferSize) + MixBufferUsed;
len = MixBufferSize - MixBufferUsed;
if (remaining < len) {
len = remaining;
}
memcpy(ptr, sptr, len);
ptr += len;
MixBufferUsed += len;
remaining -= len;
}
}
}
CoreAudioDrv_PCM_Unlock();
return noErr;
}
/***************************************************************************
midiService() -
***************************************************************************/
static
OSStatus midiService(
void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData
)
{
int secondsThisCall = (inNumberFrames << 16) / 44100;
(void)inRefCon; (void)inTimeStamp; (void)inBusNumber; (void)ioData;
if (MidiCallBack == 0) return noErr;
if (!(*ioActionFlags & kAudioUnitRenderAction_PreRender)) return noErr;
CoreAudioDrv_MIDI_Lock();
while (MidiFrameOffset < inNumberFrames) {
MidiCallBack();
MidiTick++;
MidiFrameOffset += MidiFramesPerTick;
}
MidiFrameOffset -= inNumberFrames;
CoreAudioDrv_MIDI_Unlock();
return noErr;
}
/***************************************************************************
CORE_Init() -
***************************************************************************/
int
CORE_Init(
int subsystem
)
{
OSStatus result;
AudioComponentDescription desc;
AURenderCallbackStruct callback;
AudioStreamBasicDescription pcmDesc;
AUNode outputnode, mixernode, pcmnode, synthnode;
memset(&pcmDesc, 0, sizeof(pcmDesc));
if (Initialised) {
Initialised |= subsystem;
return CAErr_Ok;
}
if (pthread_mutex_init(&pcmmutex, 0) < 0) {
ErrorCode = CAErr_Mutex;
return CAErr_Error;
}
if (pthread_mutex_init(&midimutex, 0) < 0) {
ErrorCode = CAErr_Mutex;
return CAErr_Error;
}
// create the graph
check_result(NewAUGraph(&graph), CAErr_AssembleAUGraph);
// add the output node to the graph
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
check_result(AUGraphAddNode(graph, &desc, &outputnode), CAErr_AssembleAUGraph);
// add the mixer node to the graph
desc.componentType = kAudioUnitType_Mixer;
desc.componentSubType = kAudioUnitSubType_StereoMixer;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
check_result(AUGraphAddNode(graph, &desc, &mixernode), CAErr_AssembleAUGraph);
// add a node for PCM audio
desc.componentType = kAudioUnitType_FormatConverter;
desc.componentSubType = kAudioUnitSubType_AUConverter;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
check_result(AUGraphAddNode(graph, &desc, &pcmnode), CAErr_AssembleAUGraph);
// add a node for a MIDI synth
desc.componentType = kAudioUnitType_MusicDevice;
desc.componentSubType = kAudioUnitSubType_DLSSynth;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
check_result(AUGraphAddNode(graph, &desc, &synthnode), CAErr_AssembleAUGraph);
// connect the nodes together
check_result(AUGraphConnectNodeInput(graph, pcmnode, 0, mixernode, 0), CAErr_AssembleAUGraph);
check_result(AUGraphConnectNodeInput(graph, synthnode, 0, mixernode, 1), CAErr_AssembleAUGraph);
check_result(AUGraphConnectNodeInput(graph, mixernode, 0, outputnode, 0), CAErr_AssembleAUGraph);
// open the nodes
check_result(AUGraphOpen(graph), CAErr_AssembleAUGraph);
// get the units
check_result(AUGraphNodeInfo(graph, pcmnode, NULL, &pcmunit), CAErr_AssembleAUGraph);
check_result(AUGraphNodeInfo(graph, synthnode, NULL, &synthunit), CAErr_AssembleAUGraph);
check_result(AUGraphNodeInfo(graph, mixernode, NULL, &mixerunit), CAErr_AssembleAUGraph);
// set the mixer bus count
UInt32 buscount = 2;
check_result(AudioUnitSetProperty(mixerunit,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0,
&buscount,
sizeof(buscount)), CAErr_InitialiseAUGraph);
// set the pcm audio callback
callback.inputProc = pcmService;
callback.inputProcRefCon = 0;
check_result(AUGraphSetNodeInputCallback(graph, pcmnode, 0, &callback), CAErr_InitialiseAUGraph);
// set a default pcm audio format
pcmDesc.mFormatID = kAudioFormatLinearPCM;
pcmDesc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
pcmDesc.mChannelsPerFrame = 2;
pcmDesc.mSampleRate = 44100;
pcmDesc.mBitsPerChannel = 16;
pcmDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
#ifdef __POWERPC__
pcmDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
#endif
pcmDesc.mFramesPerPacket = 1;
pcmDesc.mBytesPerFrame = pcmDesc.mBitsPerChannel * pcmDesc.mChannelsPerFrame / 8;
pcmDesc.mBytesPerPacket = pcmDesc.mBytesPerFrame * pcmDesc.mFramesPerPacket;
check_result(AudioUnitSetProperty(pcmunit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&pcmDesc,
sizeof(pcmDesc)), CAErr_SetPCMFormat);
// Set a sound bank for the DLS synth
if (soundBankName[0]) {
CFURLRef url = CFURLCreateFromFileSystemRepresentation(NULL,
(const UInt8 *)soundBankName, strlen(soundBankName), FALSE);
if (url) {
check_result(AudioUnitSetProperty(synthunit,
kMusicDeviceProperty_SoundBankURL,
kAudioUnitScope_Global,
0,
&url,
sizeof(url)), CAErr_SetSoundBank);
CFRelease(url);
}
}
// set the synth notify callback
check_result(AudioUnitAddRenderNotify(synthunit, midiService, NULL), CAErr_InitialiseAUGraph);
// initialise the graph
check_result(AUGraphInitialize(graph), CAErr_InitialiseAUGraph);
// start the graph
check_result(AUGraphStart(graph), CAErr_InitialiseAUGraph);
//CAShow(graph);
Initialised |= subsystem;
return CAErr_Ok;
}
/***************************************************************************
CORE_DeInit() -
***************************************************************************/
void
CORE_DeInit(
void
)
{
OSStatus result;
CoreAudioDrv_PCM_Lock();
CoreAudioDrv_MIDI_Lock();
// clean up the graph
AUGraphStop(graph);
DisposeAUGraph(graph);
graph = 0;
CoreAudioDrv_MIDI_Unlock();
CoreAudioDrv_PCM_Unlock();
pthread_mutex_destroy(&pcmmutex);
pthread_mutex_destroy(&midimutex);
}
/***************************************************************************
MPU_MapChannel() -
***************************************************************************/
static unsigned int
MPU_MapChannel(
unsigned chan
)
{
if (chan < 9)
return chan;
if (chan == 15)
return 9;
return chan +1;
}
/***************************************************************************
KeyOffEvent() -
***************************************************************************/
static void
KeyOffEvent(
unsigned int chan,
unsigned int key
)
{
MusicDeviceMIDIEvent(synthunit,
0x80 | MPU_MapChannel(chan),
key,
0,
MidiFrameOffset);
}
/***************************************************************************
KeyOnEvent() -
***************************************************************************/
static void
KeyOnEvent(
int chan,
unsigned int key,
unsigned int volume
)
{
MusicDeviceMIDIEvent(synthunit,
0x90 | MPU_MapChannel(chan),
key,
volume,
MidiFrameOffset);
}
/***************************************************************************
ProgramEvent() -
***************************************************************************/
static void
ProgramEvent(
unsigned int chan,
unsigned int param
)
{
MusicDeviceMIDIEvent(synthunit,
0xC0 | MPU_MapChannel(chan),
param,
0,
MidiFrameOffset);
}
/***************************************************************************
PitchBendEvent() -
***************************************************************************/
static void
PitchBendEvent(
unsigned int chan,
int bend
)
{
int lsb;
int msb;
bend <<= 6;
lsb = bend;
msb = bend;
lsb &= 0x7F;
msb >>= 7;
MusicDeviceMIDIEvent(synthunit,
0xE0 | MPU_MapChannel(chan),
lsb,
msb,
MidiFrameOffset);
}
/***************************************************************************
AllNotesOffEvent() -
***************************************************************************/
static void
AllNotesOffEvent(
unsigned int chan,
unsigned int param
)
{
MusicDeviceMIDIEvent(synthunit,
0x7B | chan,
param,
0,
MidiFrameOffset);
}
/***************************************************************************
ControllerEvent() -
***************************************************************************/
static void
ControllerEvent(
unsigned int chan,
unsigned int controller,
unsigned int param
)
{
static int event_map[] = {
0, 0, 1, 7, 10, 11, 91, 93, 64, 67, 120, 123, -1, -1, 121, -1
};
MusicDeviceMIDIEvent(synthunit,
0xB0 | MPU_MapChannel(chan),
event_map[controller],
param,
MidiFrameOffset);
}
musdevice_t mus_device_corea = {
CORE_Init,
CORE_DeInit,
NULL,
KeyOffEvent,
KeyOnEvent,
ControllerEvent,
PitchBendEvent,
ProgramEvent,
AllNotesOffEvent
};
#endif
+271
View File
@@ -0,0 +1,271 @@
#ifdef __APPLE__
#include <CoreMIDI/MIDIServices.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <pthread.h>
#include "musapi.h"
#include "fx.h"
MIDIPortRef m_port;
MIDIClientRef m_client;
MIDIEndpointRef m_endpoint;
MIDIPacket *m_pCurPacket;
int
COREM_Init(
int subsystem
)
{
// Get the MIDIEndPoint
m_endpoint = 0;
ItemCount numDests = MIDIGetNumberOfDestinations();
ItemCount destId = numDests;
m_endpoint = MIDIGetDestination(core_midi_port);
// Create a MIDI client and port
MIDIClientCreate(CFSTR("MyClient"), nullptr, nullptr, &m_client);
if (!m_client)
{
printf("MIDI:COREMIDI: No client created.");
return false;
}
MIDIOutputPortCreate(m_client, CFSTR("MyOutPort"), &m_port);
if (!m_port)
{
printf("MIDI:COREMIDI: No port created.");
return false;
}
return true;
}
void
COREM_DeInit(
void
)
{
// Dispose the port
MIDIPortDispose(m_port);
// Dispose the client
MIDIClientDispose(m_client);
}
static unsigned int
MPU_MapChannel(
unsigned chan
)
{
if (chan < 9)
return chan;
if (chan == 15)
return 9;
return chan +1;
}
static void
KeyOffEvent(
unsigned int chan,
unsigned int key
)
{
// Acquire a MIDIPacketList
Byte packetBuf[128];
MIDIPacketList* packetList = (MIDIPacketList*)packetBuf;
m_pCurPacket = MIDIPacketListInit(packetList);
Byte chanin = 0x80 | MPU_MapChannel(chan);
Byte keyin = key;
Byte noteoff[3] = {chanin, keyin, 0};
// Add msg to the MIDIPacketList
MIDIPacketListAdd(packetList,
(ByteCount)sizeof(packetBuf),
m_pCurPacket,
(MIDITimeStamp)0,
3,
noteoff);
// Send the MIDIPacketList
MIDISend(m_port, m_endpoint, packetList);
}
static void
KeyOnEvent(
int chan,
unsigned int key,
unsigned int volume
)
{
// Acquire a MIDIPacketList
Byte packetBuf[128];
MIDIPacketList* packetList = (MIDIPacketList*)packetBuf;
m_pCurPacket = MIDIPacketListInit(packetList);
Byte chanin = 0x90 | MPU_MapChannel(chan);
Byte keyin = key;
Byte volumein = volume;
Byte noteon[3] = {chanin, keyin, volumein};
// Add msg to the MIDIPacketList
MIDIPacketListAdd(packetList,
(ByteCount)sizeof(packetBuf),
m_pCurPacket,
(MIDITimeStamp)1,
3,
noteon);
// Send the MIDIPacketList
MIDISend(m_port, m_endpoint, packetList);
}
static void
ControllerEvent(
unsigned int chan,
unsigned int controller,
unsigned int param
)
{
static int event_map[] = {
0, 0, 1, 7, 10, 11, 91, 93, 64, 67, 120, 123, -1, -1, 121, -1
};
if (event_map[controller] == -1)
return;
// Acquire a MIDIPacketList
Byte packetBuf[128];
MIDIPacketList* packetList = (MIDIPacketList*)packetBuf;
m_pCurPacket = MIDIPacketListInit(packetList);
Byte chanin = 0xB0 | MPU_MapChannel(chan);
Byte controllerin = event_map[controller];
Byte paramin = param;
Byte controlev[3] = {chanin, controllerin, paramin};
// Add msg to the MIDIPacketList
MIDIPacketListAdd(packetList,
(ByteCount)sizeof(packetBuf),
m_pCurPacket,
(MIDITimeStamp)1,
3,
controlev);
// Send the MIDIPacketList
MIDISend(m_port, m_endpoint, packetList);
}
static void
PitchBendEvent(
unsigned int chan,
int bend
)
{
int lsb;
int msb;
bend <<= 6;
lsb = bend;
msb = bend;
lsb &= 0x7F;
msb >>= 7;
// Acquire a MIDIPacketList
Byte packetBuf[128];
MIDIPacketList* packetList = (MIDIPacketList*)packetBuf;
m_pCurPacket = MIDIPacketListInit(packetList);
Byte chanin = 0xE0 | MPU_MapChannel(chan);
Byte lsbin = lsb;
Byte msbin = msb;
Byte pitchbend[3] = {chanin, lsbin, msbin};
// Add msg to the MIDIPacketList
MIDIPacketListAdd(packetList,
(ByteCount)sizeof(packetBuf),
m_pCurPacket,
(MIDITimeStamp)0,
3,
pitchbend);
// Send the MIDIPacketList
MIDISend(m_port, m_endpoint, packetList);
}
static void
ProgramEvent(
unsigned int chan,
unsigned int param
)
{
// Acquire a MIDIPacketList
Byte packetBuf[128];
MIDIPacketList* packetList = (MIDIPacketList*)packetBuf;
m_pCurPacket = MIDIPacketListInit(packetList);
Byte chanin = 0xC0 | MPU_MapChannel(chan);
Byte paramin = param;
Byte progev[3] = {chanin, paramin, 0};
// Add msg to the MIDIPacketList
MIDIPacketListAdd(packetList,
(ByteCount)sizeof(packetBuf),
m_pCurPacket,
(MIDITimeStamp)0,
3,
progev);
// Send the MIDIPacketList
MIDISend(m_port, m_endpoint, packetList);
}
static void
AllNotesOffEvent(
unsigned int chan,
unsigned int param
)
{
// Acquire a MIDIPacketList
Byte packetBuf[128];
MIDIPacketList* packetList = (MIDIPacketList*)packetBuf;
m_pCurPacket = MIDIPacketListInit(packetList);
Byte chanin = 0x7B | chan;
Byte paramin = param;
Byte allnotesoff[3] = {chanin, paramin, 0};
// Add msg to the MIDIPacketList
MIDIPacketListAdd(packetList,
(ByteCount)sizeof(packetBuf),
m_pCurPacket,
(MIDITimeStamp)0,
3,
allnotesoff);
// Send the MIDIPacketList
MIDISend(m_port, m_endpoint, packetList);
}
musdevice_t mus_device_corem = {
COREM_Init,
COREM_DeInit,
NULL,
KeyOffEvent,
KeyOnEvent,
ControllerEvent,
PitchBendEvent,
ProgramEvent,
AllNotesOffEvent
};
#endif
+229
View File
@@ -0,0 +1,229 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "SDL.h"
#define TSF_IMPLEMENTATION
#include "tsf.h"
#include "musapi.h"
#include "prefapi.h"
static tsf* g_TinySoundFont;
/***************************************************************************
AudioCallback() -
***************************************************************************/
void
AudioCallback(
void* data,
uint8_t* stream,
int len
)
{
int SampleCount = (len / (2 * sizeof(short))); //2 output channels
tsf_render_short(g_TinySoundFont, (short*)stream, SampleCount, 0);
}
/***************************************************************************
TSF_Init() -
***************************************************************************/
int
TSF_Init(
int option
)
{
SDL_AudioSpec OutputAudioSpec;
OutputAudioSpec.freq = 44100;
OutputAudioSpec.format = AUDIO_S16SYS;
OutputAudioSpec.channels = 2;
OutputAudioSpec.samples = 512;
OutputAudioSpec.callback = AudioCallback;
char fn[128];
INI_GetPreference("Setup", "SoundFont", fn, 127, "SoundFont.sf2");
// Load the SoundFont from a file
g_TinySoundFont = tsf_load_filename(fn);
if (!g_TinySoundFont)
{
char errmsg[255];
fprintf(stderr, "Could not load %s\n", fn);
sprintf(errmsg,"Could not load %s\n", fn);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Raptor", errmsg, NULL);
EXIT_Error("Could not load SoundFont.");
return 0;
}
// Set the SoundFont rendering output mode
tsf_set_output(g_TinySoundFont, TSF_STEREO_INTERLEAVED, OutputAudioSpec.freq, 0.0f);
// Request the desired audio output format
if (SDL_OpenAudio(&OutputAudioSpec, NULL) < 0)
{
fprintf(stderr, "Could not open the audio hardware or the desired audio output format\n");
EXIT_Error("Could not open the audio hardware or the desired audio output format.");
return 0;
}
return 1;
}
/***************************************************************************
TSF_DeInit() -
***************************************************************************/
void
TSF_DeInit(
void
)
{
tsf_close(g_TinySoundFont);
}
/***************************************************************************
MPU_MapChannel() -
***************************************************************************/
static unsigned int
MPU_MapChannel(
unsigned chan
)
{
if (chan < 9)
return chan;
if (chan == 15)
return 9;
return chan +1;
}
/***************************************************************************
KeyOffEvent() -
***************************************************************************/
static void
KeyOffEvent(
unsigned int chan,
unsigned int key
)
{
tsf_channel_note_off(g_TinySoundFont, MPU_MapChannel(chan), key);
}
/***************************************************************************
KeyOnEvent() -
***************************************************************************/
static void
KeyOnEvent(
int chan,
unsigned int key,
unsigned int volume
)
{
float velocity = (float)volume;
velocity /= 127;
tsf_channel_note_on(g_TinySoundFont, MPU_MapChannel(chan), key, velocity);
}
/***************************************************************************
PitchBendEvent() -
***************************************************************************/
static void
PitchBendEvent(
unsigned int chan,
int bend
)
{
tsf_channel_set_pitchwheel(g_TinySoundFont, MPU_MapChannel(chan), bend);
}
/***************************************************************************
ProgramEvent() -
***************************************************************************/
static void
ProgramEvent(
unsigned int chan,
unsigned int param
)
{
tsf_channel_set_presetnumber(g_TinySoundFont, MPU_MapChannel(chan), param, MPU_MapChannel(chan) == 9);
}
/***************************************************************************
AllNotesOffEvent() -
***************************************************************************/
static void
AllNotesOffEvent(
unsigned int chan,
unsigned int param
)
{
tsf_note_off_all(g_TinySoundFont);
}
/***************************************************************************
SetChannelVolume() -
***************************************************************************/
static void
SetChannelVolume(
unsigned int chan,
unsigned int param
)
{
float volume = (float)param;
volume /= 127;
tsf_channel_set_volume(g_TinySoundFont, MPU_MapChannel(chan), volume);
}
/***************************************************************************
SetChannelPan() -
***************************************************************************/
static void
SetChannelPan(
unsigned int chan,
unsigned int param
)
{
float pan = (float)param;
pan /= 127;
tsf_channel_set_pan(g_TinySoundFont, MPU_MapChannel(chan), pan);
}
/***************************************************************************
ControllerEvent() -
***************************************************************************/
static void
ControllerEvent(
unsigned int chan,
unsigned int controller,
unsigned int param
)
{
static int event_map[] = {
0, 0, 1, 7, 10, 11, 91, 93, 64, 67, 120, 123, -1, -1, 121, -1
};
tsf_channel_midi_control(g_TinySoundFont, MPU_MapChannel(chan), event_map[controller], param);
SDL_PauseAudio(0);
}
musdevice_t mus_device_tsf = {
TSF_Init,
TSF_DeInit,
NULL,
KeyOffEvent,
KeyOnEvent,
ControllerEvent,
PitchBendEvent,
ProgramEvent,
AllNotesOffEvent,
};
+228
View File
@@ -0,0 +1,228 @@
#ifdef _WIN32
#include <windows.h>
#include <mmsystem.h>
#include "SDL.h"
#include "common.h"
#include "musapi.h"
#include "fx.h"
HMIDISTRM mpu_stream;
UINT mpu_device;
int mpu_init;
int mpu_initcnt;
int mpu_timer;
/***************************************************************************
MPU_Init() -
***************************************************************************/
int
MPU_Init(
int device
)
{
MIDIOUTCAPS caps;
if (mpu_initcnt++ != 0)
return 1;
mpu_device = winmm_mpu_device;
if (mpu_device > midiOutGetNumDevs() || midiOutGetDevCaps(mpu_device, &caps, sizeof(caps)))
mpu_device = MIDI_MAPPER;
if (midiStreamOpen(&mpu_stream, &mpu_device, 1, 0, 0, 0))
{
return 0;
}
mpu_timer = SDL_GetTicks();
mpu_init = 1;
return 1;
}
/***************************************************************************
MPU_DeInit() -
***************************************************************************/
void
MPU_DeInit(
void
)
{
if (--mpu_initcnt != 0)
return;
if (!mpu_init)
return;
midiStreamClose(mpu_stream);
mpu_stream = NULL;
mpu_init = 0;
}
/***************************************************************************
MPU_MapChannel() -
***************************************************************************/
static unsigned int
MPU_MapChannel(
unsigned chan
)
{
if (chan < 9)
return chan;
if (chan == 15)
return 9;
return chan + 1;
}
/***************************************************************************
KeyOffEvent() -
***************************************************************************/
static void
KeyOffEvent(
unsigned int chan,
unsigned int key
)
{
if (!mpu_init)
return;
uint32_t data = 0;
data = 0x80 | MPU_MapChannel(chan);
data |= key << 8;
data |= 64 << 16;
midiOutShortMsg((HMIDIOUT)mpu_stream, data);
}
/***************************************************************************
KeyOnEvent() -
***************************************************************************/
static void
KeyOnEvent(
int chan,
unsigned int key,
unsigned int volume
)
{
if (!mpu_init)
return;
uint32_t data = 0;
data = 0x90 | MPU_MapChannel(chan);
data |= key << 8;
data |= volume << 16;
midiOutShortMsg((HMIDIOUT)mpu_stream, data);
}
/***************************************************************************
ControllerEvent() -
***************************************************************************/
static void
ControllerEvent(
unsigned int chan,
unsigned int controller,
unsigned int param
)
{
if (!mpu_init)
return;
static int event_map[] = {
0, 0, 1, 7, 10, 11, 91, 93, 64, 67, 120, 123, -1, -1, 121, -1
};
uint32_t data = 0;
if (event_map[controller] == -1)
return;
data = 0xb0 | MPU_MapChannel(chan);
data |= event_map[controller] << 8;
data |= param << 16;
midiOutShortMsg((HMIDIOUT)mpu_stream, data);
}
/***************************************************************************
PitchBendEvent() -
***************************************************************************/
static void
PitchBendEvent(
unsigned int chan,
int bend
)
{
if (!mpu_init)
return;
uint32_t data = 0;
bend <<= 6;
data = 0xe0 | MPU_MapChannel(chan);
data |= (bend & 127) << 8;
data |= ((bend>>7)&127) << 16;
midiOutShortMsg((HMIDIOUT)mpu_stream, data);
}
/***************************************************************************
ProgramEvent() -
***************************************************************************/
void
ProgramEvent(
unsigned int chan,
unsigned int param
)
{
if (!mpu_init)
return;
uint32_t data = 0;
data = 0xc0 | MPU_MapChannel(chan);
data |= (param & 127) << 8;
midiOutShortMsg((HMIDIOUT)mpu_stream, data);
}
/***************************************************************************
AllNotesOffEvent() -
***************************************************************************/
void
AllNotesOffEvent(
unsigned int chan,
unsigned int param
)
{
if (!mpu_init)
return;
uint32_t data = 0;
data = 0xB0 | MPU_MapChannel(chan);
data |= 0x7B;
midiOutShortMsg((HMIDIOUT)mpu_stream, data);
}
musdevice_t mus_device_winmm = {
MPU_Init,
MPU_DeInit,
NULL,
KeyOffEvent,
KeyOnEvent,
ControllerEvent,
PitchBendEvent,
ProgramEvent,
AllNotesOffEvent,
};
#endif // _WIN32
+681
View File
@@ -0,0 +1,681 @@
#include "SDL.h"
#include <stdint.h>
#include "common.h"
#include "musapi.h"
#include "fx.h"
#include "cards.h"
#include "gssapi.h"
#include "entypes.h"
static int musrate = 70;
static int musfaderate = 50;
int music_init;
int music_startoffset;
int music_len;
int music_cmdptr;
int music_active;
int music_loop;
int music_delay;
int music_timer;
int music_vol;
int music_voltarget;
int music_currentvol = 127;
int music_lastvol;
int music_fading;
int music_channels;
int music_faderaccum;
int music_faderadd1;
int music_faderadd2;
int music_fadersteps;
int music_cnt, music_cnt2, music_cnt3;
char *music_ptr = NULL;
musdevice_t *music_device;
int music_chanvel[16];
int music_chanvol[16];
int music_chanvol2[16];
#pragma pack(push, 1)
struct mushead_t {
char id[4];
uint16_t len;
uint16_t offset;
uint16_t channels;
};
#pragma pack(pop)
/***************************************************************************
MUS_SetupFader() -
***************************************************************************/
int
MUS_SetupFader(
int s
)
{
int start, end;
if (s) // starting song
{
start = 0;
end = 127;
}
else
{
start = music_currentvol;
end = 0;
}
int steps = abs(end - start);
const int count = 51; // ~1000ms
if (steps == 0)
{
return 0;
}
music_fading = 1;
music_faderadd1 = steps / count;
music_faderadd2 = steps % count;
music_fadersteps = steps;
music_faderaccum = -(music_faderadd2 >> 1);
music_vol = start;
music_voltarget = end;
return 1;
}
/***************************************************************************
MUS_UpdateVolume() -
***************************************************************************/
void
MUS_UpdateVolume(
void
)
{
int i, vol;
for (i = 0; i < 16; i++)
{
if (i == music_channels)
i = 15;
vol = music_currentvol;
if (music_fading && vol > music_vol)
vol = music_vol;
if (i != 15 && vol > music_chanvol2[i])
vol = music_chanvol2[i];
if (vol != music_chanvol[i])
{
music_chanvol[i] = vol;
if (music_device && music_device->ControllerEvent)
music_device->ControllerEvent(i, 3, vol);
}
}
}
/***************************************************************************
MUS_Fader() -
***************************************************************************/
void
MUS_Fader(
void
)
{
int update = 0;
if (music_lastvol != music_currentvol)
{
music_lastvol = music_currentvol;
update = 1;
}
if (music_fading)
{
update = 1;
if (music_vol < music_currentvol || music_voltarget < music_currentvol)
{
int cnt = music_faderadd1;
music_faderaccum += music_faderadd2;
if (music_faderaccum >= music_fadersteps)
{
music_faderaccum -= music_fadersteps;
cnt++;
}
if (cnt)
{
if (music_voltarget < music_vol) // fade out
{
music_vol -= cnt;
if (music_vol <= 0)
{
music_vol = 0;
// stop song
music_active = 0;
for (int i = 0; i < 16; i++)
{
if (music_device && music_device->ControllerEvent)
{
music_device->ControllerEvent(i, 10, 0);
music_device->ControllerEvent(i, 11, 0);
}
}
music_ptr = NULL;
return;
}
if (music_vol == music_voltarget)
music_fading = 0;
}
else // fade in
{
music_vol += cnt;
if (music_vol >= music_voltarget)
{
music_vol = music_voltarget;
music_fading = 0;
}
if (music_vol >= music_currentvol)
{
music_vol = music_currentvol;
music_fading = 0;
}
}
}
}
}
if (update)
MUS_UpdateVolume();
}
/***************************************************************************
MUS_Reset() -
***************************************************************************/
void
MUS_Reset(
void
)
{
music_cmdptr = 0;
if (music_vol > music_currentvol)
music_vol = music_currentvol;
if (!music_fading)
music_vol = music_currentvol;
for (int i = 0; i < 16; i++)
{
music_chanvol[i] = 100;
music_chanvol2[i] = 100;
if (i < music_channels || i == 15)
if (music_device && music_device->ControllerEvent)
{
int newvol = 100;
music_device->ControllerEvent(i, 14, 0); // reset
if (newvol > music_vol)
newvol = music_vol;
if (newvol > music_currentvol)
newvol = music_currentvol;
music_device->ControllerEvent(i, 3, newvol);
}
if (music_device && music_device->AllNotesOffEvent)
music_device->AllNotesOffEvent(i,0);
}
}
/***************************************************************************
MUS_Service() -
***************************************************************************/
void
MUS_Service(
void
)
{
if (music_active)
{
if (music_delay)
music_delay--;
while (!music_delay)
{
uint8_t cmd = music_ptr[music_cmdptr + music_startoffset];
music_cmdptr++;
int chan = cmd & 15;
switch ((cmd >> 4) & 7)
{
case 0:
{
uint8_t key = music_ptr[music_cmdptr + music_startoffset] & 127;
music_cmdptr++;
if (music_device && music_device->KeyOffEvent)
music_device->KeyOffEvent(chan, key);
break;
}
case 1:
{
uint8_t key = music_ptr[music_cmdptr + music_startoffset];
music_cmdptr++;
uint8_t vol = music_chanvel[chan];
if (key & 128)
{
vol = music_ptr[music_cmdptr + music_startoffset];
music_cmdptr++;
music_chanvel[chan] = vol;
key &= ~128;
}
if (music_device && music_device->KeyOnEvent)
music_device->KeyOnEvent(chan, key, vol);
break;
}
case 2:
{
uint8_t bend = music_ptr[music_cmdptr + music_startoffset];
music_cmdptr++;
if (music_device && music_device->PitchBendEvent)
music_device->PitchBendEvent(chan, bend);
break;
}
case 3:
{
uint8_t cmd = music_ptr[music_cmdptr + music_startoffset];
music_cmdptr++;
if (music_device && music_device->ControllerEvent)
music_device->ControllerEvent(chan, cmd, 0);
break;
}
case 4:
{
uint8_t cmd = music_ptr[music_cmdptr + music_startoffset];
music_cmdptr++;
uint8_t param = music_ptr[music_cmdptr + music_startoffset];
music_cmdptr++;
switch (cmd)
{
case 0: // Program Channel
if(music_device && music_device->ProgramEvent)
music_device->ProgramEvent(chan, param);
break;
case 3: // Volume
music_chanvol2[chan] = param;
if (param > music_currentvol)
param = music_currentvol;
if (param > music_vol)
param = music_vol;
music_chanvol[chan] = param;
if (music_device && music_device->ControllerEvent)
music_device->ControllerEvent(chan, cmd, param);
break;
case 4: //SetChannelPan
if (music_device && music_device->ControllerEvent)
music_device->ControllerEvent(chan, cmd, param);
break;
case 10:
case 11:
if (music_device && music_device->AllNotesOffEvent)
music_device->AllNotesOffEvent(chan, param);
break;
case 12:
case 13:
// TODO: mono/poly mode
break;
case 14: // Restore volume setting
if (music_device && music_device->AllNotesOffEvent)
music_device->AllNotesOffEvent(chan, param);
param = music_chanvel[chan];
if (param > music_currentvol)
param = music_currentvol;
if (param > music_vol)
param = music_vol;
if (music_device && music_device->ControllerEvent)
music_device->ControllerEvent(chan, 3, param);
break;
default:
break;
}
break;
}
case 6:
{
if (music_loop)
{
MUS_Reset();
}
else
{
music_active = 0;
return;
}
break;
}
}
if (cmd & 128)
{
music_delay = 0;
do
{
uint8_t val = music_ptr[music_cmdptr + music_startoffset];
music_cmdptr++;
music_delay = (music_delay << 7) + (val & 127);
if (!(val & 128))
break;
} while (1);
}
}
}
}
/***************************************************************************
MUS_Init() -
***************************************************************************/
int
MUS_Init(
int card,
int option
)
{
if (music_init)
return 0;
music_cnt2 = music_cnt = 0;
music_active = 0;
music_ptr = NULL;
switch (card)
{
case M_NONE:
music_device = NULL;
break;
case M_ADLIB:
case M_PAS:
case M_SB:
music_device = &mus_device_opl;
break;
case M_WAVE:
case M_CANVAS:
case M_GMIDI:
default:
if (sys_midi)
{
#ifdef _WIN32
music_device = &mus_device_winmm;
#endif // _WIN32
#ifndef __ANDROID__
#ifdef __linux__
music_device = &mus_device_alsa;
#endif // __linux__
#endif //__ANDROID__
#ifdef __APPLE__
if (core_dls_synth)
music_device = &mus_device_corea;
else
music_device = &mus_device_corem;
#endif // __APPLE__
}
else
music_device = &mus_device_tsf;
break;
}
if (music_device && music_device->Init)
music_device->Init(option);
if (music_device && music_device->AllNotesOffEvent)
music_device->AllNotesOffEvent(0,0);
music_timer = SDL_GetTicks();
music_init = 1;
return 1;
}
/***************************************************************************
MUS_DeInit() -
***************************************************************************/
void
MUS_DeInit(
void
)
{
if (!music_init)
return;
for (int i = 0; i < 16; i++)
{
if (music_device && music_device->AllNotesOffEvent)
music_device->AllNotesOffEvent(i,0);
}
music_init = 0;
music_active = 0;
music_ptr = NULL;
if (music_device && music_device->DeInit)
music_device->DeInit();
music_device = NULL;
}
/***************************************************************************
MUS_PlaySong() -
***************************************************************************/
void
MUS_PlaySong(
void *ptr,
int loop,
int fadein
)
{
mushead_t *head;
head = (mushead_t*)ptr;
if (!music_init)
return;
if (!ptr)
return;
SND_Lock();
if (music_active)
MUS_StopSong(0);
music_ptr = (char*)ptr;
music_len = LE_USHORT(head->len);
music_startoffset = LE_USHORT(head->offset);
music_cmdptr = 0;
music_loop = loop;
music_active = 1;
music_delay = 0;
music_vol = 127;
music_fading = 0;
music_channels = LE_USHORT(head->channels);
MUS_Reset();
if (fadein)
MUS_SetupFader(1);
SND_Unlock();
}
/***************************************************************************
MUS_StopSong() -
***************************************************************************/
void
MUS_StopSong(
int fadeout
)
{
if (!music_init)
return;
SND_Lock();
if (fadeout && MUS_SetupFader(0))
{
SND_Unlock();
return;
}
music_active = 0;
for (int i = 0; i < 16; i++)
{
if (music_device && music_device->ControllerEvent)
{
music_device->ControllerEvent(i, 10, 0);
music_device->ControllerEvent(i, 11, 0);
}
if (music_device && music_device->AllNotesOffEvent)
music_device->AllNotesOffEvent(i,0);
}
music_ptr = NULL;
SND_Unlock();
}
/***************************************************************************
MUS_SongPlaying() -
***************************************************************************/
int
MUS_SongPlaying(
void
)
{
if (!music_init)
return 0;
return music_active;
}
/***************************************************************************
MUS_Mix() -
***************************************************************************/
void
MUS_Mix(
int16_t *stream,
int len
)
{
int i;
if (!music_init || !music_device || !music_device->Mix)
return;
for (i = 0; i < len; i++)
{
music_device->Mix(stream, 1);
music_cnt += musrate;
while (music_cnt >= fx_freq)
{
music_cnt -= fx_freq;
MUS_Service();
}
music_cnt2 += musfaderate;
while (music_cnt2 >= fx_freq)
{
music_cnt2 -= fx_freq;
MUS_Fader();
}
if (gsshack)
{
music_cnt3 += gssrate;
while (music_cnt3 >= fx_freq)
{
music_cnt3 -= fx_freq;
GSS_Service();
}
}
stream += 2;
}
}
/***************************************************************************
MUS_SetVolume() -
***************************************************************************/
void
MUS_SetVolume(
int volume
)
{
if (music_currentvol == volume)
return;
music_currentvol = volume;
}
/***************************************************************************
MUS_Poll() -
***************************************************************************/
void
MUS_Poll(
void
)
{
GSS_Poll();
if (!music_init || !music_device || music_device->Mix != NULL)
return;
int now = SDL_GetTicks();
while (music_timer < now)
{
music_cnt += musrate;
if (music_cnt >= 1000)
{
music_cnt -= 1000;
MUS_Service();
}
music_cnt2 += musfaderate;
while (music_cnt2 >= 1000)
{
music_cnt2 -= 1000;
MUS_Fader();
}
music_timer++;
}
}
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#include <stdint.h>
#include "common.h"
struct musdevice_t {
int (*Init)(int option);
void (*DeInit)(void);
void (*Mix)(int16_t *stream, int len);
void (*KeyOffEvent)(unsigned int chan, unsigned int key);
void (*KeyOnEvent)(int chan, unsigned int key, unsigned int volume);
void (*ControllerEvent)(unsigned int chan, unsigned int controller, unsigned int param);
void (*PitchBendEvent)(unsigned int chan, int bend);
void (*ProgramEvent)(unsigned int chan, unsigned int param);
void (*AllNotesOffEvent)(unsigned int chan, unsigned int param);
};
extern musdevice_t mus_device_opl, mus_device_winmm, mus_device_tsf, mus_device_alsa, mus_device_corea, mus_device_corem;
extern musdevice_t *music_device;
int MUS_Init(int card, int option);
void MUS_DeInit(void);
void MUS_PlaySong(void *ptr, int loop, int fadein);
void MUS_StopSong(int fadeout);
int MUS_SongPlaying(void);
void MUS_Mix(int16_t *stream, int len);
void MUS_Poll(void);
void MUS_SetVolume(int volume);
File diff suppressed because it is too large. Load diff
+100
View File
@@ -0,0 +1,100 @@
#pragma once
#define MAX_OBJS 20
typedef enum
{
OBJ_GOTIT,
OBJ_NOMONEY,
OBJ_SHIPFULL,
OBJ_ERROR
}BUYSTUFF;
typedef enum
{
S_FORWARD_GUNS, // 00 * DUAL MACHINE GUNS
S_PLASMA_GUNS, // 01 * PLASMA GUNS
S_MICRO_MISSLE, // 02 * SMALL WING MISSLES
S_DUMB_MISSLE, // 03 DUMB FIRE MISSLE // 1
S_MINI_GUN, // 04 AUTO TRACK MINI GUN // 2
S_TURRET, // 05 AUTO TRACK LASER TURRET // 3
S_MISSLE_PODS, // 06 MULTIPLE MISSLE SHOTS // 4
S_AIR_MISSLE, // 07 AIR TO AIR MISSLE // 5
S_GRD_MISSLE, // 08 AIR TO GROUND // 6
S_BOMB, // 09 GROUND BOMB // 7
S_ENERGY_GRAB, // 10 ENERGY GRAB // 8
S_MEGA_BOMB, // 11 MEGA BOMB KILLS ALL AIR //
S_PULSE_CANNON, // 12 WAVE WEAPON // 9
S_FORWARD_LASER, // 13 ALTERNATING LASER // MINUS
S_DEATH_RAY, // 14 DEATH RAY // 0
S_SUPER_SHIELD, // 15 SUPER SHIELD //
S_ENERGY, // 16 NORMAL SHIELD ENERGY //
S_DETECT, // 18 DAMAGE DETECTOR //
S_ITEMBUY1, // 19
S_ITEMBUY2, // 20
S_ITEMBUY3, // 21
S_ITEMBUY4, // 22
S_ITEMBUY5, // 23
S_ITEMBUY6, // 24
S_LAST_OBJECT // 25 LAST OBJECT ( NOT USED )
}OBJ_TYPE;
#define LAST_WEAPON ( S_DEATH_RAY )
#define FIRST_SPECIAL ( S_DUMB_MISSLE )
typedef struct
{
int item; // LUMPNUM OF PIC
int numframes; // NUMBER OF FRAMES
int cost; // COST OF OBJECT
int start_cnt; // START AMOUNT OF ITEMS
int max_cnt; // MAX COUNT OF UNITS/ITEMS
int (*actf)(int); // FUNCTION PTR FOR ACTION
int fxtype; // SOUND FX TYPE
int forever; // LAST FOREVER
int onlyflag; // UNIQUE FLAG ( ENERGY )
int loseit; // LOSE OBJECT
int specialw; // SPECIAL WEAPON
int moneyflag; // ADDS MONEY TO PLAYER WHEN PICKED UP
int game1flag; // TRUE=AVALABLE IN ALL GAMES
int shieldflag; // SHOW SHIELD WHEN BONUS
}OBJ_LIB;
typedef struct OBJ_S
{
struct OBJ_S *prev; // LINK LIST PREV
struct OBJ_S *next; // LINK LIST NEXT
int num; // NUMBER OF ITEM(S)
int type; // OBJECT TYPE
OBJ_LIB *lib; // POINTER TO LIB
int inuse; // CURRENTLY EQUIPED
}OBJ;
extern OBJ first_objs, last_objs;
void OBJS_Init(void);
int OBJS_Add(int type);
void OBJS_GetNext(void);
int OBJS_GetAmt(int type);
OBJ_LIB *OBJS_GetLib(int type);
int OBJS_CanBuy(int type);
int OBJS_GetCost(int type);
int OBJS_CanSell(int type);
int OBJS_GetNum(void);
int OBJS_IsOnly(int type);
int OBJS_GetTotal(int type);
int OBJS_GetResale(int type);
int OBJS_Buy(unsigned int type);
int OBJS_Sell(int type);
void OBJS_Clear(void);
int OBJS_Load(OBJ *inobj);
int OBJS_IsEquip(int type);
int OBJS_LoseObj(void);
void OBJS_DisplayStats(void);
int OBJS_MakeSpecial(int type);
void OBJS_Use(int type);
void OBJS_Think(void);
int OBJS_SubEnergy(int amt);
int OBJS_AddEnergy(int amt);
void OBJS_CachePics(void);
void OBJS_FreePics(void);
+1382
View File
File diff suppressed because it is too large. Load diff
+151
View File
@@ -0,0 +1,151 @@
/* Nuked OPL3
* Copyright (C) 2013-2020 Nuke.YKT
*
* This file is part of Nuked OPL3.
*
* Nuked OPL3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1
* of the License, or (at your option) any later version.
*
* Nuked OPL3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Nuked OPL3. If not, see <https://www.gnu.org/licenses/>.
* Nuked OPL3 emulator.
* Thanks:
* MAME Development Team(Jarek Burczynski, Tatsuyuki Satoh):
* Feedback and Rhythm part calculation information.
* forums.submarine.org.uk(carbon14, opl3):
* Tremolo and phase generator calculation information.
* OPLx decapsulated(Matthew Gambrell, Olli Niemitalo):
* OPL2 ROMs.
* siliconpr0n.org(John McMaster, digshadow):
* YMF262 and VRC VII decaps and die shots.
*
* version: 1.8
*/
#pragma once
#include <inttypes.h>
#define OPL_WRITEBUF_SIZE 1024
#define OPL_WRITEBUF_DELAY 2
typedef uintptr_t Bitu;
typedef intptr_t Bits;
typedef uint64_t Bit64u;
typedef int64_t Bit64s;
typedef uint32_t Bit32u;
typedef int32_t Bit32s;
typedef uint16_t Bit16u;
typedef int16_t Bit16s;
typedef uint8_t Bit8u;
typedef int8_t Bit8s;
typedef struct _opl3_slot opl3_slot;
typedef struct _opl3_channel opl3_channel;
typedef struct _opl3_chip opl3_chip;
struct _opl3_slot {
opl3_channel *channel;
opl3_chip *chip;
Bit16s out;
Bit16s fbmod;
Bit16s *mod;
Bit16s prout;
Bit16s eg_rout;
Bit16s eg_out;
Bit8u eg_inc;
Bit8u eg_gen;
Bit8u eg_rate;
Bit8u eg_ksl;
Bit8u *trem;
Bit8u reg_vib;
Bit8u reg_type;
Bit8u reg_ksr;
Bit8u reg_mult;
Bit8u reg_ksl;
Bit8u reg_tl;
Bit8u reg_ar;
Bit8u reg_dr;
Bit8u reg_sl;
Bit8u reg_rr;
Bit8u reg_wf;
Bit8u key;
Bit32u pg_reset;
Bit32u pg_phase;
Bit16u pg_phase_out;
Bit8u slot_num;
};
struct _opl3_channel {
opl3_slot *slots[2];
opl3_channel *pair;
opl3_chip *chip;
Bit16s *out[4];
Bit8u chtype;
Bit16u f_num;
Bit8u block;
Bit8u fb;
Bit8u con;
Bit8u alg;
Bit8u ksv;
Bit16u cha, chb;
Bit8u ch_num;
};
typedef struct _opl3_writebuf {
Bit64u time;
Bit16u reg;
Bit8u data;
} opl3_writebuf;
struct _opl3_chip {
opl3_channel channel[18];
opl3_slot slot[36];
Bit16u timer;
Bit64u eg_timer;
Bit8u eg_timerrem;
Bit8u eg_state;
Bit8u eg_add;
Bit8u newm;
Bit8u nts;
Bit8u rhy;
Bit8u vibpos;
Bit8u vibshift;
Bit8u tremolo;
Bit8u tremolopos;
Bit8u tremoloshift;
Bit32u noise;
Bit16s zeromod;
Bit32s mixbuff[2];
Bit8u rm_hh_bit2;
Bit8u rm_hh_bit3;
Bit8u rm_hh_bit7;
Bit8u rm_hh_bit8;
Bit8u rm_tc_bit3;
Bit8u rm_tc_bit5;
//OPL3L
Bit32s rateratio;
Bit32s samplecnt;
Bit16s oldsamples[2];
Bit16s samples[2];
Bit64u writebuf_samplecnt;
Bit32u writebuf_cur;
Bit32u writebuf_last;
Bit64u writebuf_lasttime;
opl3_writebuf writebuf[OPL_WRITEBUF_SIZE];
};
void OPL3_Generate(opl3_chip *chip, Bit16s *buf);
void OPL3_GenerateResampled(opl3_chip *chip, Bit16s *buf);
void OPL3_Reset(opl3_chip *chip, Bit32u samplerate);
void OPL3_WriteReg(opl3_chip *chip, Bit16u reg, Bit8u v);
void OPL3_WriteRegBuffered(opl3_chip *chip, Bit16u reg, Bit8u v);
void OPL3_GenerateStream(opl3_chip *chip, Bit16s *sndptr, Bit32u numsamples);
+500
View File
@@ -0,0 +1,500 @@
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "prefapi.h"
#ifdef _WIN32
#include <io.h>
#endif // _WIN32
#ifdef __GNUC__
#include <unistd.h>
char* ltoa(long i, char* s, int dummy_radix) {
sprintf(s, "%ld", i);
return s;
}
#endif // __GNUC__
static char ProfilePath[260];
/***************************************************************************
GetPrivateProfileString() -
***************************************************************************/
static int // RETURN: 1 Found, 0 Not Found
GetPrivateProfileString(
const char* section, // INPUT : Name of section
const char* option, // INPUT : Name of preference option
const char* def, // INPUT : Default value for preference
char* buf, // OUTPUT: buffer to place preference
int buflen, // INPUT : Maximum size of buffer
const char* file // INPUT : File to retrieve data from
)
{
char buffer[128];
char* token;
FILE* fptr;
short found = 0;
short len;
if ((fptr = fopen(file, "r")) != NULL)
{
len = strlen(section);
while (!found && fgets(buffer, sizeof(buffer), fptr))
{
if (buffer[0] == '[')
{
for (len = 0; buffer[len] != '\0' && buffer[len] != ']'; ++len)
;
if (buffer[len] != ']')
continue;
buffer[len] = '\0';
if (strcmp(buffer + 1, section) == 0)
found = 1;
}
}
while (found && fgets(buffer, sizeof(buffer), fptr))
{
if (buffer[0] == '[')
found = 0;
else if ((token = strtok(buffer, "=\r\n")) != NULL)
{
if (strcmp(token, option) == 0)
{
fclose(fptr);
token = strtok(NULL, "\r\n");
if (token)
{
strncpy(buf, token, buflen);
buf[buflen - 1] = '\0';
}
else
buf[0] = '\0';
return 1;
}
}
}
fclose(fptr);
}
if (def)
strncpy(buf, def, buflen);
else
buf[0] = '\0';
return 0;
}
/***************************************************************************
WritePrivateProfileString() -
***************************************************************************/
static int // RETURN: 1 Success, 0 Failure
WritePrivateProfileString(
const char* section, // INPUT : Name of section
const char* option, // INPUT : Name of preference option
const char* buf, // OUTPUT: preference to write
const char* file // INPUT : File to retrieve data from
)
{
char buffer[128];
char* token;
FILE* fptr;
short found = 0;
short len;
int pos1, pos2, pos3;
int exist_len, new_len, delta;
int size;
int cnt;
if (section == NULL || *section == '\0')
return 0;
if ((fptr = fopen(file, "rb+")) == NULL)
{
if ((fptr = fopen(file, "wb+")) == NULL)
return 0;
fseek(fptr, 0, SEEK_SET);
}
// Search for section
pos3 = 0;
while (!found && fgets(buffer, sizeof(buffer), fptr))
{
if (buffer[0] == '\r' || buffer[0] == '\n')
continue;
if (buffer[0] == '[')
{
for (len = 0; buffer[len] != '\0' && buffer[len] != ']'; ++len)
;
if (buffer[len] != ']')
continue;
buffer[len] = '\0';
if (strcmp(buffer + 1, section) == 0)
{
found = 1;
break;
}
}
pos3 = ftell(fptr);
}
// POS3 = Beginning of section
if (!found) // Create the new section
{
fseek(fptr, 0, SEEK_END);
if (option && *option != '\0')
fprintf(fptr, "\r\n[%s]\r\n", section);
else
{
fclose(fptr);
return 1; // Delete section that doesn't exist
}
found = 0;
pos1 = pos2 = ftell(fptr);
}
else
{ // Search section for option
pos1 = ftell(fptr);
while (fgets(buffer, sizeof(buffer), fptr))
{
pos2 = ftell(fptr);
if (buffer[0] == '[') // Option not found
{
found = 0;
break;
}
else if ((token = strtok(buffer, "=\r\n")) != NULL)
{
if (strcmp(token, option) == 0) // Option found
{
if (strcmp(buf, strtok(NULL, "=\r\n")) == 0)
{
fclose(fptr);
return 1; // Option value is the same
}
found = 1;
break;
}
pos1 = pos2;
}
}
}
// POS3 = Beginning of section
// POS2 = Current Position after last line read
// POS1 = Point before current line, the existing option if found
if (!found) // Option doesn't exist
{
if (pos1 == pos2) // At end of file, append and exit
{
if (option && *option != '\0' && buf && *buf != '\0')
{
fseek(fptr, 0, SEEK_END);
fprintf(fptr, "%s=%s\r\n", option, buf);
}
fclose(fptr);
return 1;
}
if (option && *option != '\0')
exist_len = 0;
else
{ // Deleting the section
exist_len = pos1 - pos3;
pos2 = pos1; // Last line read was next section, don't delete
}
}
else
exist_len = pos2 - pos1;
if (option && *option != '\0' && buf && *buf != '\0')
{
sprintf(buffer, "%s=%s\r\n", option, buf);
new_len = strlen(buffer);
}
else
new_len = 0;
delta = new_len - exist_len;
if (option && *option != '\0')
pos3 = pos1; // Remember where the new line goes
// POS3 = Beginning of text to remove
// POS2 = Current Position after text to remove
// POS1 = Point before current line, the existing option if found
if (delta < 0) // Shrink file
{
while (1)
{
fseek(fptr, pos2, SEEK_SET);
if ((cnt = fread(buffer, sizeof(char), sizeof(buffer), fptr)) == 0)
break;
pos1 = ftell(fptr);
fseek(fptr, pos2 + delta, SEEK_SET);
fwrite(buffer, sizeof(char), cnt, fptr);
pos2 = pos1;
}
fseek(fptr, delta, SEEK_END);
pos1 = ftell(fptr);
#ifdef _MSC_VER
chsize(fileno(fptr), pos1);
#endif
#ifdef __GNUC__
ftruncate(fileno(fptr), pos1);
#endif
}
else if (delta > 0) // Expand file, starting at the end
{ // ...working backwards
size = sizeof(buffer);
fseek(fptr, 0, SEEK_END);
pos2 = pos1 = ftell(fptr);
while (1)
{
pos2 = pos2 - size;
if (pos2 < pos3) // Moved to left of line that changed
{
size = pos1 - pos3; // Calculate what is left
if (size <= 0)
break;
pos2 = pos3;
}
fseek(fptr, pos2, SEEK_SET);
pos1 = pos2;
if ((cnt = fread(buffer, sizeof(char), (size_t)size, fptr)) == 0)
break;
fseek(fptr, pos2 + delta, SEEK_SET);
fwrite(buffer, sizeof(char), cnt, fptr);
}
}
if (option && *option != '\0' && buf && *buf != '\0')
{
fseek(fptr, pos3, SEEK_SET);
fprintf(fptr, "%s=%s\r\n", option, buf);
}
fclose(fptr);
return 1;
}
/***************************************************************************
INI_InitPreference() - Specify the preference program file
***************************************************************************/
int // RETURN: 1 File found, 0 File not found
INI_InitPreference(
const char* profile // INPUT : Profile buffer
)
{
if (profile)
strcpy(ProfilePath, profile);
if (access(ProfilePath, 04) == 0)
return 1;
return 0;
}
/***************************************************************************
INI_GetPreferenceLong() - Retrieve a long integer value from the program file
***************************************************************************/
int // RETURN: Value retrieved
INI_GetPreferenceLong(
const char* section, // INPUT : Name of section
const char* option, // INPUT : Name of preference option
int def // INPUT : Default value for preference
)
{
char buffer[20];
char Def[20];
ltoa(def, Def, 10);
INI_GetPreference(section, option, buffer, sizeof(buffer), Def);
return(atol(buffer));
}
/***************************************************************************
INI_GetPreferenceHex() - Retrieve a Hex value from the program file
***************************************************************************/
int // RETURN: Value retrieved
INI_GetPreferenceHex(
const char* section, // INPUT : Name of section
const char* option, // INPUT : Name of preference option
int def // INPUT : Default value for preference
)
{
char buffer[32];
char Def[32];
ltoa(def, Def, 10);
INI_GetPreference(section, option, buffer, sizeof(buffer), Def);
sscanf(buffer, "%x", &def);
return (def);
}
/***************************************************************************
INI_GetPreferenceBool() - Retrieve a boolean value from the program file
***************************************************************************/
int // RETURN: 1 for 1, 0 for 0
INI_GetPreferenceBool(
const char* section, // INPUT : Name of section
const char* option, // INPUT : Name of preference option
short def // INPUT : Default value for preference
)
{
char buffer[10];
if (def)
INI_GetPreference(section, option, buffer, sizeof(buffer), "TRUE");
else
INI_GetPreference(section, option, buffer, sizeof(buffer), "FALSE");
if (buffer[0] == '1' || strcmp(buffer, "TRUE") == 0)
return 1;
if (buffer[0] == '0' || strcmp(buffer, "FALSE") == 0)
return 0;
return(atoi(buffer));
}
/***************************************************************************
INI_GetPreference() - Retrieve a character string from the program file
***************************************************************************/
char* // RETURN: Pointer to character buffer
INI_GetPreference(
const char* section, // INPUT : Name of section
const char* option, // INPUT : Name of preference option
char* buf, // OUTPUT: buffer to place preference
int buflen, // INPUT : Maximum size of buffer
const char* def // INPUT : Default value for preference
)
{
if (section == NULL || option == NULL || buf == NULL)
{
buf[0] = '\0';
return NULL;
}
GetPrivateProfileString(section, option, def, buf, buflen, ProfilePath);
return buf;
}
/***************************************************************************
INI_PutPreferenceLong() - Write a long integer value to the program file
***************************************************************************/
int // RETURN: SUCCESS 1, FAIL 0
INI_PutPreferenceLong(
const char* section, // INPUT : Name of section
const char* option, // INPUT : Name of preference option
int val // INPUT : Value to write
)
{
char buffer[32];
if (val == -1)
{
INI_DeletePreference(section, option);
return(0);
}
ltoa(val, buffer, 10);
return(INI_PutPreference(section, option, buffer));
}
/***************************************************************************
INI_PutPreferenceHex() - Write a Hex value to the program file
***************************************************************************/
int // RETURN: SUCCESS 1, FAIL 0
INI_PutPreferenceHex(
const char* section, // INPUT : Name of section
const char* option, // INPUT : Name of preference option
int val // INPUT : Value to write
)
{
char buffer[32];
if (val == -1)
{
INI_DeletePreference(section, option);
return(0);
}
sprintf(buffer, "%x", val);
return(INI_PutPreference(section, option, buffer));
}
/***************************************************************************
INI_PutPreferenceBool() - Write a Boolean value to the program file
***************************************************************************/
int // RETURN: SUCCESS 1, FAIL 0
INI_PutPreferenceBool(
const char* section, // INPUT : Name of section
const char* option, // INPUT : Name of preference option
short val // INPUT : Value to write
)
{
return(INI_PutPreference(section, option, (val) ? "TRUE" : "FALSE"));
}
/***************************************************************************
INI_PutPreference() - Write a string value to the program file
***************************************************************************/
int // RETURN: SUCCESS 1, FAIL 0
INI_PutPreference(
const char* section, // INPUT : Name of section
const char* option, // INPUT : Name of preference option
const char* val // INPUT : Value to write
)
{
if (section == NULL || option == NULL || val == NULL)
return 0;
return(WritePrivateProfileString(section, option, val, ProfilePath));
}
/***************************************************************************
INI_DeletePreference() - Delete a preference from the program file
***************************************************************************/
int // RETURN: SUCCESS 1, FAIL 0
INI_DeletePreference(
const char* section, // INPUT : Name of section
const char* option // INPUT : Name of preference option
)
{
if (section == NULL) // If option is NULL, entire section deleted */
return 0;
return(WritePrivateProfileString(section, option, NULL, ProfilePath));
}
+11
View File
@@ -0,0 +1,11 @@
#pragma once
int INI_InitPreference(const char *profile);
int INI_GetPreferenceLong(const char *section, const char *option, int def);
int INI_GetPreferenceHex(const char *section, const char *option, int def);
int INI_GetPreferenceBool(const char *section, const char *option, short def);
char* INI_GetPreference(const char *section, const char *option, char *buf, int buflen, const char *def);
int INI_PutPreferenceLong(const char *section, const char *option, int val);
int INI_PutPreferenceHex(const char *section, const char *option, int val);
int INI_PutPreferenceBool(const char *section, const char *option, short val);
int INI_PutPreference(const char *section, const char *option, const char *val);
int INI_DeletePreference(const char *section, const char *option);
+690
View File
@@ -0,0 +1,690 @@
#include "SDL.h"
#include "common.h"
#include "i_video.h"
#include "ptrapi.h"
#include "gfxapi.h"
#include "joyapi.h"
#include "input.h"
#define CURSORHEIGHT 16
#define CURSORWIDTH 16
#define CURSORSIZE (CURSORHEIGHT*CURSORWIDTH)
#define HOTSPOTCOLOR 255
int g_drawcursor;
static int mousepresent;
static int joyactive;
static int joy_mx, joy_my;
static int ptrupdate = 1;
static int ptr_pause;
static int joypresent;
static void (*ptrcursorhook)(void);
static void (*ptrboundshook)(void);
static int cursoroffsetx, cursoroffsety;
static int ptrerase;
static int ptrclip;
static int cursorxnew, cursorynew;
int ptractive;
int cursorloopx, cursorloopy;
int cursorx, cursory;
char *cursorsave, *cursorpic;
char *displaypic;
char *cursorstart;
int mouseb1, mouseb2, mouseb3;
int mouse_b1_ack, mouse_b2_ack, mouse_b3_ack;
int touchmouseb1off = 0;
int do_game = 0;
int cur_mx, cur_my;
int old_joy_x, old_joy_y;
/*------------------------------------------------------------------------
PTR_JoyHandler() - Joystick Handler Function
------------------------------------------------------------------------*/
void
PTR_JoyHandler(
void
)
{
static int lasttick;
int now = SDL_GetTicks();
if (now - lasttick < 1000 / 60)
return;
lasttick += 1000 / 60;
cur_mx = StickX + old_joy_x;
cur_my = StickY + old_joy_y;
if (cur_mx < 0)
cur_mx = 0;
else if (cur_mx >= SCREENWIDTH)
cur_mx = SCREENWIDTH - 1;
if (cur_my < 0)
cur_my = 0;
else if (cur_my >= SCREENHEIGHT)
cur_my = SCREENHEIGHT - 1;
if (old_joy_x != cur_mx || old_joy_y != cur_my)
{
old_joy_x = cur_mx;
old_joy_y = cur_my;
ptrupdate = 1;
}
}
/*------------------------------------------------------------------------
PTR_MouseHandler() - Mouse Handler Function
------------------------------------------------------------------------*/
void
PTR_MouseHandler(
void
)
{
static int old_x = -1;
static int old_y;
I_GetMousePos(&cur_mx, &cur_my);
if (cur_mx < 0)
cur_mx = 0;
else if (cur_mx >= SCREENWIDTH)
{
cur_mx = SCREENWIDTH - 1;
if (!g_drawcursor || fullscreen)
I_SetMousePos(cur_mx, cur_my);
}
if (cur_my < 0)
cur_my = 0;
else if (cur_my >= SCREENHEIGHT)
{
cur_my = SCREENHEIGHT - 1;
if (!g_drawcursor || fullscreen)
I_SetMousePos(cur_mx, cur_my);
}
if (old_x != cur_mx || old_y != cur_my)
{
old_x = cur_mx;
old_y = cur_my;
ptrupdate = 1;
}
}
/*------------------------------------------------------------------------
I_HandleMouseEvent() - Get current mouse status
------------------------------------------------------------------------*/
void
I_HandleMouseEvent(
SDL_Event *sdlevent
)
{
switch (sdlevent->type)
{
case SDL_MOUSEBUTTONDOWN:
switch (sdlevent->button.button)
{
case SDL_BUTTON_LEFT:
mouseb1 = 1;
mouse_b1_ack = 1;
break;
case SDL_BUTTON_RIGHT:
mouseb2 = 2;
mouse_b2_ack = 1;
break;
case SDL_BUTTON_MIDDLE:
mouseb3 = 4;
mouse_b3_ack = 1;
break;
}
break;
case SDL_MOUSEBUTTONUP:
switch (sdlevent->button.button)
{
case SDL_BUTTON_LEFT:
mouseb1 = 0;
break;
case SDL_BUTTON_RIGHT:
mouseb2 = 0;
break;
case SDL_BUTTON_MIDDLE:
mouseb3 = 0;
break;
}
break;
}
}
/*------------------------------------------------------------------------
I_HandleTouchEvent() - Get current touch status
------------------------------------------------------------------------*/
void
I_HandleTouchEvent(
SDL_Event *sdlevent
)
{
switch (sdlevent->type)
{
case SDL_FINGERDOWN:
if (SDL_GetNumTouchFingers(sdlevent->tfinger.touchId) == 3)
{
mouseb3 = 4;
mouse_b3_ack = 1;
}
if (SDL_GetNumTouchFingers(sdlevent->tfinger.touchId) == 2)
{
static int lasttick;
int now = SDL_GetTicks();
if(now - lasttick < 500)
{
mouseb2 = 2;
mouse_b2_ack = 1;
}
lasttick = now;
}
else if (!g_drawcursor && do_game)
{
static int lasttick;
int now = SDL_GetTicks();
if(now - lasttick < 500)
{
if(!touchmouseb1off)
touchmouseb1off = 1;
else
touchmouseb1off = 0;
}
if (!touchmouseb1off)
{
mouseb1 = 1;
mouse_b1_ack = 1;
}
else if(touchmouseb1off == 1)
{
mouseb1 = 0;
}
lasttick = now;
}
else
{
mouseb1 = 1;
mouse_b1_ack = 1;
}
break;
case SDL_FINGERUP:
mouseb2 = 0;
mouseb3 = 0;
break;
}
}
/*------------------------------------------------------------------------
PTR_ResetJoystick() - Reset joystick x and y
------------------------------------------------------------------------*/
void
PTR_ResetJoyStick(
void
)
{
if (joyactive)
{
joy_mx = 0;
joy_my = 0;
}
}
/*------------------------------------------------------------------------
PTR_ClipCursor () Clips cursor from screen
------------------------------------------------------------------------*/
void
PTR_ClipCursor(
void
)
{
displaypic = cursorpic;
ptrclip = 0;
if (cursorxnew + CURSORWIDTH > SCREENWIDTH)
{
cursorloopx = SCREENWIDTH - cursorxnew;
ptrclip = 1;
}
else if (cursorxnew < 0)
{
cursorloopx = cursorxnew + CURSORWIDTH;
displaypic -= cursorxnew;
cursorxnew = 0;
ptrclip = 1;
}
else
cursorloopx = CURSORWIDTH;
if (cursorynew + CURSORHEIGHT > SCREENHEIGHT)
{
cursorloopy = SCREENHEIGHT - cursorynew;
ptrclip = 1;
}
else if (cursorynew < 0)
{
cursorloopy = cursorynew + CURSORHEIGHT;
displaypic += (-cursorynew) * CURSORWIDTH;
cursorynew = 0;
ptrclip = 1;
}
else
cursorloopy = CURSORHEIGHT;
}
/*========================================================================
PTR_UpdateCursor() - Updates Cursor
========================================================================*/
void
PTR_UpdateCursor(
void
)
{
static int lasttick;
int now = SDL_GetTicks();
if (now - lasttick < 1000 / 15)
return;
lasttick += 1000 / 15;
if (ptr_pause)
return;
if ((joyactive) && (!joy_ipt_MenuNew))
PTR_JoyHandler();
if (ptrupdate)
{
ptrupdate = 0;
if (ptrerase)
{
if (ptrclip)
PTR_ClipErase();
else
PTR_Erase();
ptrerase = 0;
}
if (ptrboundshook)
ptrboundshook();
cursorxnew = cur_mx - cursoroffsetx;
cursorynew = cur_my - cursoroffsety;
if (g_drawcursor)
{
PTR_ClipCursor();
cursorstart = displayscreen + ylookup[cursorynew] + cursorxnew;
if (cursorloopy < 16)
PTR_ClipSave();
else
PTR_Save();
PTR_Draw();
ptrerase = 1;
}
if (ptrcursorhook)
ptrcursorhook();
cursorx = cursorxnew;
cursory = cursorynew;
I_FinishUpdate();
}
}
/*==========================================================================
PTR_FrameHook() - Framehook Function
==========================================================================*/
void
PTR_FrameHook(
void (*update)(void) // INPUT : pointer to function
)
{
int ck_x2, ck_y2, ck_x1, ck_y1;
if (!g_drawcursor)
{
update();
return;
}
if (ptrboundshook)
ptrboundshook();
cursorxnew = cur_mx - cursoroffsetx;
cursorynew = cur_my - cursoroffsety;
ck_x2 = ud_x + ud_lx;
ck_y2 = ud_y + ud_ly;
ck_x1 = ud_x - CURSORWIDTH;
ck_y1 = ud_y - CURSORHEIGHT;
if (ck_x1 <= cursorxnew && ck_x2 >= cursorxnew && ck_y1 <= cursorynew && ck_y2 >= cursorynew)
{
if (ptrerase)
{
if (ck_x1 <= cursorx && ck_x2 >= cursorx && ck_y1 <= cursory && ck_y2 >= cursory)
{
GFX_MarkUpdate(cursorx, cursory, cursorloopx, cursorloopy);
}
else
{
if (ptrclip)
PTR_ClipErase();
else
PTR_Erase();
ptrerase = 0;
}
}
PTR_ClipCursor();
GFX_MarkUpdate(cursorxnew, cursorynew, cursorloopx, cursorloopy);
cursorstart = displaybuffer + ylookup[cursorynew] + cursorxnew;
if (cursorloopy < 16)
PTR_ClipSave();
else
PTR_Save();
PTR_Draw();
update();
if (ptrclip)
PTR_ClipErase();
else
PTR_Erase();
cursorstart = displayscreen + ylookup[cursorynew] + cursorxnew;
ptrerase = 1;
}
else
{
if (ptrupdate)
{
if (ptrerase)
{
if (ptrclip)
PTR_ClipErase();
else
PTR_Erase();
ptrerase = 0;
}
PTR_ClipCursor();
cursorstart = displayscreen + ylookup[cursorynew] + cursorxnew;
PTR_Save();
PTR_Draw();
ptrerase = 1;
}
update();
}
if (ptrcursorhook)
ptrcursorhook();
cursorx = cursorxnew;
cursory = cursorynew;
}
/***************************************************************************
PTR_DrawCursor () - Turns Cursor Drawing to ON/OFF ( TRUE/FALSE )
***************************************************************************/
void
PTR_DrawCursor(
int flag // INPUT: TRUE/FALSE
)
{
if (ptractive)
{
if (!flag && ptrerase == 1)
{
if (ptrclip)
PTR_ClipErase();
else
PTR_Erase();
ptrerase = 0;
}
if (flag == 1)
ptrupdate = 1;
g_drawcursor = flag;
}
else
g_drawcursor = 0;
}
/***************************************************************************
PTR_SetPic () - Sets up a new cursor picture with hotspot
***************************************************************************/
void
PTR_SetPic(
char *newp // INPUT : pointer to new Cursor picture
)
{
char* pic;
int loop;
cursoroffsetx = 0;
cursoroffsety = 0;
if (ptractive)
{
newp += sizeof(GFX_PIC);
pic = (char*)cursorpic;
for (loop = 0; loop < CURSORSIZE; loop++, newp++, pic++)
{
*pic = *newp;
if (*newp == (char)HOTSPOTCOLOR)
{
cursoroffsetx = loop % CURSORWIDTH;
cursoroffsety = loop / CURSORWIDTH;
*pic = *(newp + 1);
}
}
if (cursoroffsetx > 16)
cursoroffsetx = 0;
if (cursoroffsety > 16)
cursoroffsety = 0;
ptrupdate = 1;
}
}
/***************************************************************************
PTR_SetBoundsHook() - Sets User function to OK or change x,y values
***************************************************************************/
void // RETURN: none
PTR_SetBoundsHook(
void (*func)(void) // INPUT : pointer to function
)
{
ptrboundshook = func;
ptrupdate = 1;
}
/***************************************************************************
PTR_SetCursorHook() - Sets User function to call from mouse or joy handler
***************************************************************************/
void // RETURN: none
PTR_SetCursorHook(
void (*hook)(void) // INPUT : pointer to function
)
{
ptrcursorhook = hook;
ptrupdate = 1;
}
/***************************************************************************
PTR_SetUpdateFlag () - Sets cursor to be update next cycle
***************************************************************************/
void
PTR_SetUpdateFlag(
void
)
{
ptrupdate = 1;
}
/***************************************************************************
PTR_SetPos() - Sets Cursor Position
***************************************************************************/
void // RETURN: none
PTR_SetPos(
int x, // INPUT : x position
int y // INPUT : y position
)
{
if (mousepresent)
I_SetMousePos(x, y);
cur_mx = x;
cur_my = y;
old_joy_x = x;
old_joy_y = y;
if (ptractive)
ptrupdate = 1;
}
/***************************************************************************
PTR_Pause() - Pauses/ Starts PTR routines after already initing
***************************************************************************/
void
PTR_Pause(
int flag // INPUT : TRUE / FALSE
)
{
if (ptractive && flag != ptr_pause)
{
if (flag)
{
PTR_DrawCursor(0);
// TSM_PauseService(ptr_tsm);
}
else
{
g_drawcursor = 0;
// TSM_ResumeService(ptr_tsm);
PTR_SetPos(160, 100);
PTR_DrawCursor(0);
}
ptr_pause = flag;
}
}
/***************************************************************************
PTR_Init() - Inits control type
***************************************************************************/
int // RETURN true = Installed, false = No mouse
PTR_Init(
int type // INPUT : Pointer Type to Use
)
{
g_drawcursor = 0;
cursorsave = (char*)malloc(256);
if (!cursorsave)
EXIT_Error("PTR_Init() - malloc");
cursorpic = (char*)malloc(256);
if (!cursorpic)
EXIT_Error("PTR_Init() - malloc");
joyactive = 0;
mousepresent = 0;
joypresent = 0;
if (type == P_JOYSTICK)
joypresent = 1;
if (type == P_AUTO || type == P_MOUSE || type == P_JOYSTICK)
mousepresent = 1;
if (type == P_JOYSTICK && joypresent)
joyactive = 1;
if (mousepresent || joyactive)
{
ptractive = 1;
// ptr_tsm = TSM_NewService(PTR_UpdateCursor, 15, 254, 0);
GFX_SetFrameHook(PTR_FrameHook);
}
// else
// ptr_tsm = -1;
// if (joypresent)
// PTR_CalJoy();
PTR_SetPos(100, 160);
if (mousepresent || joyactive)
return 1;
return 0;
}
/***************************************************************************
PTR_End() - End Cursor system
***************************************************************************/
void
PTR_End(
void
)
{
// if (ptr_tsm != -1)
// TSM_DelService(ptr_tsm);
}
/***************************************************************************
PTR_Settouchmouseb1off() - Set mouseb1off on/off for touch input
***************************************************************************/
void
PTR_Settouchmouseb1off(
int flag // INPUT : TRUE / FALSE
)
{
touchmouseb1off = flag;
}
/***************************************************************************
PTR_SetGameFlag() - Set do_game on/off for touch input
***************************************************************************/
void
PTR_SetGameFlag(
int flag // INPUT : TRUE / FALSE
)
{
do_game = flag;
}
+34
View File
@@ -0,0 +1,34 @@
#pragma once
#include "common.h"
#include "gfxapi.h"
typedef enum
{
P_AUTO,
P_MOUSE,
P_JOYSTICK
}PTRTYPE;
extern int mouseb1, mouseb2, mouseb3;
extern int cur_mx, cur_my;
extern int ptractive;
extern int mouse_b1_ack, mouse_b2_ack, mouse_b3_ack;
extern int g_drawcursor;
void PTR_JoyHandler(void);
void PTR_MouseHandler(void);
void PTR_ResetJoyStick(void);
void PTR_SetPos(int x, int y);
void PTR_Pause(int flag);
void PTR_DrawCursor(int flag);
void PTR_SetPic(char *newp);
int PTR_Init(int type);
void PTR_Erase(void);
void PTR_ClipErase(void);
void PTR_Save(void);
void PTR_ClipSave(void);
void PTR_Draw(void);
void PTR_UpdateCursor(void);
void PTR_Settouchmouseb1off(int flag);
void PTR_SetGameFlag(int flag);
+95
View File
@@ -0,0 +1,95 @@
#include <string.h>
#include "common.h"
#include "ptrapi.h"
#define CURSORHEIGHT 16
#define CURSORWIDTH 16
extern char *cursorsave;
extern char *displaypic;
extern char *cursorstart;
extern int cursorloopx, cursorloopy;
/*------------------------------------------------------------------------
PTR_Save() - Saves screen before a cursor draw
------------------------------------------------------------------------*/
void
PTR_Save(
void
)
{
int loop;
for (loop = 0; loop < CURSORHEIGHT; loop++)
{
memcpy(&cursorsave[loop * CURSORWIDTH], &cursorstart[loop * SCREENWIDTH], CURSORWIDTH);
}
}
/*------------------------------------------------------------------------
PTR_ClipSave() - Saves screen before a cursor draw
------------------------------------------------------------------------*/
void
PTR_ClipSave(
void
)
{
int loop;
for (loop = 0; loop < cursorloopy; loop++)
{
memcpy(&cursorsave[loop * CURSORWIDTH], &cursorstart[loop * SCREENWIDTH], CURSORWIDTH);
}
}
/*------------------------------------------------------------------------
PTR_Erase() - Erases cursor with stuff from PTR_Save()
------------------------------------------------------------------------*/
void
PTR_Erase(
void
)
{
int loop;
for (loop = 0; loop < CURSORHEIGHT; loop++)
{
memcpy(&cursorstart[loop * SCREENWIDTH], &cursorsave[loop * CURSORWIDTH], CURSORWIDTH);
}
}
/*------------------------------------------------------------------------
PTR_ClipErase() - Erases cursor and clips edges of screen
------------------------------------------------------------------------*/
void
PTR_ClipErase(
void
)
{
int loop;
for (loop = 0; loop < cursorloopy; loop++)
{
memcpy(&cursorstart[loop * SCREENWIDTH], &cursorsave[loop * CURSORWIDTH], cursorloopx);
}
}
/*------------------------------------------------------------------------
PTR_Draw() - Draws Cursor
------------------------------------------------------------------------*/
void
PTR_Draw(
void
)
{
int loop, i;
for (loop = 0; loop < cursorloopy; loop++)
{
for (i = cursorloopx - 1; i >= 0; i--)
{
if (displaypic[loop * CURSORWIDTH + i])
cursorstart[loop * SCREENWIDTH + i] = displaypic[loop * CURSORWIDTH + i];
}
}
}
+1574
View File
File diff suppressed because it is too large. Load diff
+175
View File
@@ -0,0 +1,175 @@
#pragma once
#define MAX_SHIELD 100
#define MAX_SUPER 100
#define MAX_FLIGHT 30
#define MAP_ROWS 150
#define MAP_ONSCREEN 8
#define MAP_COLS 9
#define MAP_BLOCKSIZE 32
#define MAP_BOTTOM 200 - 18
#define MAP_TOP 2
#define MAP_LEFT 16
#define MAP_RIGHT ( 320 - 16 )
#define MAP_SIZE ( MAP_ROWS * MAP_COLS )
#define MAX_TILES 2048
#define MAX_GUNS 24
#define ENGINE_COLOR 254
#define SHOT_COLOR 255
extern int reg_flag;
extern int bday_num;
extern int demo_mode;
extern int demo_flag;
extern char *palette;
extern int ingameflag;
extern int gameflag[4];
extern int godmode;
extern int cur_game;
extern int game_wave[4];
extern int cur_diff;
extern int bday_flag;
extern int g_mapleft;
extern int g_flash;
extern int o_gun1[8];
extern int o_gun2[8];
extern int o_gun3[8];
extern int playerpic;
extern int player_cx, player_cy;
extern int startfadeflag;
extern int startendwave;
extern int gl_cnt;
extern int g_oldsuper, g_oldshield;
extern int playerx, playery;
extern char gdmodestr[];
extern int playerbasepic;
typedef struct
{
char name[20];
char callsign[12];
int id_pic;
unsigned int score; // MONEY/POINTS
int sweapon; // CURENT SPECIAL WEAPON
int cur_game; // CURRENT GAME
int game_wave[3]; // CURRENT WAVE
int numobjs; // NUMBER OF OBJECTS TO FOLLOW
int diff[4]; // DIFFICULTY LEVEL
int trainflag;
int fintrain;
}PLAYEROBJ;
#define END_DURATION ( 20 * 3 )
#define END_EXPLODE ( 24 )
#define END_FLYOFF ( 20 * 2 )
#define DIFF_0 0 // TRAINING MODE
#define DIFF_1 1 // EASY MODE
#define DIFF_2 2 // NORMAL MODE
#define DIFF_3 3 // HARD MODE
#define GAME1 ( gameflag[0] )
#define GAME2 ( gameflag[1] )
#define GAME3 ( gameflag[2] + gameflag[3] )
#define SHIELD_COLOR_RUN 9
#define SHIELD_LOW 10
#define PLAYERWIDTH 32
#define PLAYERHEIGHT 32
#define PLAYERMINX 5
#define PLAYERMAXX 314
#define PLAYERINITX 160-(PLAYERWIDTH/2)
#define PLAYERINITY 160
#define MINPLAYERY 0
#define MAXPLAYERY 160
#define GREEN 100
#define RED 34
#define YELLOW 50
#define MAP_ABORT -1
#define MAP_NEXT -2
#define MAX_ONSCREEN 30
typedef struct
{
int x;
int y;
int x2;
int y2;
int delx;
int dely;
int addx;
int addy;
int maxloop;
int err;
int done;
}MOVEOBJ;
typedef enum
{
F_REPEAT,
F_LINEAR,
F_KAMI,
F_GROUND,
F_GROUNDLEFT,
F_GROUNDRIGHT,
}FLIGHT_TYPE;
typedef enum
{
GANIM_NORM,
GANIM_SHOOT,
GANIM_MULTI
}ANIMTYPE;
typedef enum
{
EXP_AIRSMALL1, // 0
EXP_AIRMED, // 1 NORMAL AIR ( norm )
EXP_AIRLARGE, // 2 bigger that 32 by 32
EXP_GRDSMALL, // 3 smaller than 32 by 32
EXP_GRDMED, // 4 NORMAL GROUND ( norm )
EXP_GRDLARGE, // 5 bigger than 32 by 32
EXP_BOSS, // 6 BIG BOSS SHIP ( AIR )
EXP_PERSON, // 7 ONE LITTLE PERSON BLWING UP
EXP_ENERGY, // 8 ENERGY SHIP BLOWING UP
EXP_PLATOON, // 9 ONE LITTLE PERSON BLWING UP
EXP_AIRSMALL2 // 10
}EXP_TYPE;
typedef enum
{
K_OK,
K_NEXTFRAME,
K_SKIPALL,
K_EXITDOS
}KEYOPTS;
typedef struct
{
int linkflat;
short bonus;
short bounty;
}FLATS;
extern FLATS *flatlib[4];
extern PLAYEROBJ plr;
int wrand(void);
void InitMobj(MOVEOBJ *cur);
void MoveMobj(MOVEOBJ *cur);
int MoveSobj(MOVEOBJ *cur, int speed);
void RAP_FreeMap(void);
void RAP_LoadMap(void);
int Do_Game(void);
int RAP_LoadWin(void);
void ShutDown(int errcode);
+499
View File
@@ -0,0 +1,499 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "textscreen.h"
#include "main.h"
#include "input.h"
extern "C" {
#include "txt_keyinput.h"
#include "txt_mouseinput.h"
#include "txt_joyinput.h"
}
int ControllerType;
int key_up = KEY_UPARROW;
int key_down = KEY_DOWNARROW;
int key_left = KEY_LEFTARROW;
int key_right = KEY_RIGHTARROW;
int key_fire = KEY_RCTRL;
int key_special = KEY_LALT;
int key_mega = ' ';
int convertflagkey;
int writeflagkey;
int key_up_convert, key_down_convert, key_left_convert, key_right_convert, key_fire_convert, key_special_convert, key_mega_convert;
static int* controls[] = { &key_up, &key_down, &key_left, &key_right, &key_fire, &key_special, &key_mega, NULL };
static const int scantokey[128] =
{
0 , 27, '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '-', '=', KEY_BACKSPACE, 9,
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '[', ']', 13, KEY_RCTRL, 'a', 's',
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
'\'', '`', KEY_RSHIFT,'\\', 'z', 'x', 'c', 'v',
'b', 'n', 'm', ',', '.', '/', KEY_RSHIFT,KEYP_MULTIPLY,
KEY_RALT, ' ', KEY_CAPSLOCK,KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, /*KEY_NUMLOCK?*/KEY_PAUSE,KEY_SCRLCK,KEY_HOME,
KEY_UPARROW,KEY_PGUP,KEY_MINUS,KEY_LEFTARROW,KEYP_5,KEY_RIGHTARROW,KEYP_PLUS,KEY_END,
KEY_DOWNARROW,KEY_PGDN,KEY_INS,KEY_DEL,0, 0, 0, KEY_F11,
KEY_F12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, KEY_PRTSCR, 0
};
int mousebfire, mousebchweapon, mousebmega;
int mousebfireout, mousebchweaponout, mousebmegaout;
int writeflagmouse;
static int* all_mouse_buttons[] = {
&mousebfire,
&mousebchweapon,
&mousebmega,
};
int joybfire, joybchweapon, joybmega, joybspeed;
int joybfireout, joybchweaponout, joybmegaout;
int writeflagjoy, writeflagjoybfire, writeflagjoybchweapon, writeflagjoybmega;
txt_window_t* getcontrolkeyboardwindow;
txt_window_t* getcontrolmousewindow;
txt_window_t* getcontroljoystickwindow;
void GetControl(TXT_UNCAST_ARG(widget), void* user_data)
{
if (strcmp((char*)user_data, "Keyboard") == 0)
{
ControllerType = 1000;
textbox_control = (char*)"Keyboard ";
}
if (strcmp((char*)user_data, "Mouse") == 0)
{
ControllerType = 1;
textbox_control = (char*)"Mouse ";
}
if (strcmp((char*)user_data, "Joystick") == 0)
{
ControllerType = 2;
textbox_control = (char*)"Joystick ";
}
TXT_ClearTable(infotable);
infotable = TXT_NewTable(2);
TXT_AddWidgets(infotable,
TXT_NewLabel("Control Type : "),
TXT_NewLabel(textbox_control),
TXT_NewLabel("Music Card : "),
TXT_NewLabel(textbox_musiccard),
TXT_NewLabel("Sound FX Card : "),
TXT_NewLabel(textbox_soundfx),
NULL);
TXT_AddWidget(infowindow, infotable);
}
////////////////////////////////////////////////Select ControlButtonConfigKeyboard///////////////////////////////////////////////////
static int VarInGroup(int* variable, int** group)
{
unsigned int i;
for (i = 0; group[i] != NULL; ++i)
{
if (group[i] == variable)
{
return 1;
}
}
return 0;
}
static void CheckKeyGroup(int* variable, int** group)
{
unsigned int i;
// Don't check unless the variable is in this group.
if (!VarInGroup(variable, group))
{
return;
}
// If another variable has the same value as the new value, reset it.
for (i = 0; group[i] != NULL; ++i)
{
if (*variable == *group[i] && group[i] != variable)
{
// A different key has the same value. Clear the existing
// value. This ensures that no two keys can have the same
// value.
*group[i] = 0;
}
}
}
static void KeySetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable))
{
TXT_CAST_ARG(int, variable);
CheckKeyGroup(variable, controls);
}
void ConvertKey(TXT_UNCAST_ARG(widget), void* user_data)
{
int s;
writeflagkey = 1;
for (s = 0; s < 128; ++s)
{
if (scantokey[s] == key_up)
{
key_up_convert = s;
break;
}
}
for (s = 0; s < 128; ++s)
{
if (scantokey[s] == key_down)
{
key_down_convert = s;
break;
}
}
for (s = 0; s < 128; ++s)
{
if (scantokey[s] == key_left)
{
key_left_convert = s;
break;
}
}
for (s = 0; s < 128; ++s)
{
if (scantokey[s] == key_right)
{
key_right_convert = s;
break;
}
}
for (s = 0; s < 128; ++s)
{
if (scantokey[s] == key_fire)
{
key_fire_convert = s;
break;
}
}
for (s = 0; s < 128; ++s)
{
if (scantokey[s] == key_special)
{
key_special_convert = s;
break;
}
}
for (s = 0; s < 128; ++s)
{
if (scantokey[s] == key_mega)
{
key_mega_convert = s;
break;
}
}
}
static void AddKeyControl(TXT_UNCAST_ARG(table), const char* name, int* var)
{
TXT_CAST_ARG(txt_table_t, table);
txt_key_input_t* key_input;
TXT_AddWidget(table, TXT_NewSpecialLabel(name));
key_input = TXT_NewKeyInput(var);
TXT_AddWidget(table, key_input);
TXT_SignalConnect(key_input, "set", KeySetCallback, var);
if (strcmp(name, " Up ") == 0)
TXT_SetHelpLabel(key_input, "Move ship forward");
if (strcmp(name, " Down ") == 0)
TXT_SetHelpLabel(key_input, "Move ship backwards");
if (strcmp(name, " Left ") == 0)
TXT_SetHelpLabel(key_input, "Move ship to the left");
if (strcmp(name, " Right ") == 0)
TXT_SetHelpLabel(key_input, "Move ship to the right");
if (strcmp(name, " Fire ") == 0)
TXT_SetHelpLabel(key_input, "Fire main weapons");
if (strcmp(name, " Change Special ") == 0)
TXT_SetHelpLabel(key_input, "Fire special weapons the you pickup/buy");
if (strcmp(name, " Mega Bomb ") == 0)
TXT_SetHelpLabel(key_input, "Change to next available special weapon");
}
void GetControlKeyboard(TXT_UNCAST_ARG(widget), void* user_data)
{
txt_window_action_t* close_button;
txt_window_action_t* accept_button;
txt_window_action_t* select_button;
if (!convertflagkey)
{
key_up = scantokey[keymoveup];
key_down = scantokey[keymovedown];
key_left = scantokey[keymoveleft];
key_right = scantokey[keymoveright];
key_fire = scantokey[keyfire];
key_special = scantokey[keyspecial];
key_mega = scantokey[keymega];
convertflagkey = 1;
}
getcontrolkeyboardwindow = TXT_NewWindow("Keyboard Configuration ");
TXT_SetWindowPosition(getcontrolkeyboardwindow, TXT_HORIZ_CENTER, TXT_VERT_TOP, 39, 3);
TXT_AddWidget(getcontrolkeyboardwindow, TXT_TABLE_EMPTY);
TXT_SetTableColumns(getcontrolkeyboardwindow, 2);
TXT_SetColumnWidths(getcontrolkeyboardwindow, 4, 3);
TXT_AddWidget(getcontrolkeyboardwindow, TXT_NewSpecialSeparator(" Movement ", 6, 6, TXT_COLOR_BRIGHT_BLUE));
AddKeyControl(getcontrolkeyboardwindow, " Up ", &key_up);
AddKeyControl(getcontrolkeyboardwindow, " Down ", &key_down);
AddKeyControl(getcontrolkeyboardwindow, " Left ", &key_left);
AddKeyControl(getcontrolkeyboardwindow, " Right ", &key_right);
TXT_AddWidget(getcontrolkeyboardwindow, TXT_NewStrut(0, 2));
TXT_AddWidget(getcontrolkeyboardwindow, TXT_NewSpecialSeparator(" Action ", 6, 5, TXT_COLOR_BRIGHT_BLUE));
AddKeyControl(getcontrolkeyboardwindow, " Fire ", &key_fire);
AddKeyControl(getcontrolkeyboardwindow, " Change Special ", &key_special);
AddKeyControl(getcontrolkeyboardwindow, " Mega Bomb ", &key_mega);
TXT_AddWidget(getcontrolkeyboardwindow, TXT_NewStrut(0, 1));
accept_button = TXT_NewWindowAction(KEY_F10, "Accept");
select_button = TXT_NewWindowAction(KEY_ENTER, "Select");
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
TXT_SetHelpLabel(accept_button, " Press F10 to Accept");
TXT_SetHelpLabel(select_button, " Press ENTER to Select");
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, getcontrolkeyboardwindow);
TXT_SignalConnect(select_button, "pressed", WindowSelect, getcontrolkeyboardwindow);
TXT_SignalConnect(accept_button, "pressed", ClosePwnBox, getcontrolkeyboardwindow);
TXT_SignalConnect(accept_button, "pressed", ConvertKey, NULL);
TXT_SetWindowAction(getcontrolkeyboardwindow, TXT_HORIZ_LEFT, close_button);
TXT_SetWindowAction(getcontrolkeyboardwindow, TXT_HORIZ_CENTER, select_button);
TXT_SetWindowAction(getcontrolkeyboardwindow, TXT_HORIZ_RIGHT, accept_button);
}
////////////////////////////////////////////////Select ControlButtonConfigMouse///////////////////////////////////////////////////
static void MouseSetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable))
{
TXT_CAST_ARG(int, variable);
unsigned int i;
// Check if the same mouse button is used for a different action
// If so, set the other action(s) to -1 (unset)
for (i = 0; i < arrlen(all_mouse_buttons); ++i)
{
if (*all_mouse_buttons[i] == *variable
&& all_mouse_buttons[i] != variable)
{
*all_mouse_buttons[i] = -1;
}
}
}
static void AddMouseControl(TXT_UNCAST_ARG(table), const char* label, int* var)
{
TXT_CAST_ARG(txt_table_t, table);
txt_mouse_input_t* mouse_input;
TXT_AddWidget(table, TXT_NewLabel(label));
mouse_input = TXT_NewMouseInput(var);
TXT_AddWidget(table, mouse_input);
TXT_SignalConnect(mouse_input, "set", MouseSetCallback, var);
if (strcmp(label, " Fire ") == 0)
TXT_SetHelpLabel(mouse_input, "Fire main weapons");
if (strcmp(label, " Change Weapon ") == 0)
TXT_SetHelpLabel(mouse_input, "Change to next available special weapon");
if (strcmp(label, " Mega Bomb ") == 0)
TXT_SetHelpLabel(mouse_input, "Launch a Mega Bomb");
}
void SaveMouseConfig(TXT_UNCAST_ARG(widget), void* user_data)
{
txt_window_t* window;
txt_window_action_t* close_button;
if ((mousebfire > 2) || (mousebchweapon > 2) || (mousebmega > 2))
{
window = TXT_CustomMessageBox("Error", ("Only LEFT BUTTON, RIGHT BUTTON and MID BUTTON are supported!\n"
"Please reconfigure mouse buttons before save!"), TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_RED, TXT_COLOR_RED, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE);
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
writeflagmouse = 0;
return;
}
writeflagmouse = 1;
}
void GetControlMouse(TXT_UNCAST_ARG(widget), void* user_data)
{
txt_window_action_t* close_button;
txt_window_action_t* accept_button;
txt_window_action_t* select_button;
getcontrolmousewindow = TXT_NewWindow("Mouse Configuration ");
TXT_SetWindowPosition(getcontrolmousewindow, TXT_HORIZ_CENTER, TXT_VERT_TOP, 40, 5);
TXT_AddWidget(getcontrolmousewindow, TXT_NewStrut(0, 1));
TXT_SetTableColumns(getcontrolmousewindow, 2);
AddMouseControl(getcontrolmousewindow, " Fire ", &mousebfire);
AddMouseControl(getcontrolmousewindow, " Change Weapon ", &mousebchweapon);
AddMouseControl(getcontrolmousewindow, " Mega Bomb ", &mousebmega);
TXT_AddWidget(getcontrolmousewindow, TXT_NewStrut(0, 1));
accept_button = TXT_NewWindowAction(KEY_F10, "Accept");
select_button = TXT_NewWindowAction(KEY_ENTER, "Select");
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
TXT_SetHelpLabel(accept_button, " Press F10 to Accept");
TXT_SetHelpLabel(select_button, " Press ENTER to Select");
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, getcontrolmousewindow);
TXT_SignalConnect(select_button, "pressed", WindowSelect, getcontrolmousewindow);
TXT_SignalConnect(accept_button, "pressed", ClosePwnBox, getcontrolmousewindow);
TXT_SignalConnect(accept_button, "pressed", SaveMouseConfig, NULL);
TXT_SetWindowAction(getcontrolmousewindow, TXT_HORIZ_LEFT, close_button);
TXT_SetWindowAction(getcontrolmousewindow, TXT_HORIZ_CENTER, select_button);
TXT_SetWindowAction(getcontrolmousewindow, TXT_HORIZ_RIGHT, accept_button);
}
////////////////////////////////////////////////Select ControlButtonConfigJoystick////////////////////////////////////////////////
static void AddJoystickControl(TXT_UNCAST_ARG(table), const char* label, int* var)
{
TXT_CAST_ARG(txt_table_t, table);
txt_joystick_input_t* joy_input;
TXT_AddWidget(table, TXT_NewLabel(label));
joy_input = TXT_NewJoystickInput(var);
TXT_AddWidget(table, joy_input);
if (strcmp(label, " Fire ") == 0)
TXT_SetHelpLabel(joy_input, "Fire main weapons");
if (strcmp(label, " Change Special ") == 0)
TXT_SetHelpLabel(joy_input, "Change to the next available special weapon");
if (strcmp(label, " Mega ") == 0)
TXT_SetHelpLabel(joy_input, "Fires a Mega Bomb");
}
void SaveJoyConfig(TXT_UNCAST_ARG(widget), void* user_data)
{
txt_window_t* window;
txt_window_action_t* close_button;
if ((joybfireout > 3) || (joybchweaponout > 3) || (joybmegaout > 3))
{
window = TXT_CustomMessageBox("Error", ("Only BUTTON 1, BUTTON 2, BUTTON 3 and BUTTON 4 are supported!\n"
"Please reconfigure joystick/gamepad buttons before save!"), TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_RED, TXT_COLOR_RED, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE);
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
writeflagjoy = 0;
return;
}
writeflagjoy = 1;
}
void GetControlJoystick(TXT_UNCAST_ARG(widget), void* user_data)
{
txt_window_action_t* close_button;
txt_window_action_t* accept_button;
txt_window_action_t* select_button;
if (!joybfireout)
joybfireout = joybfire;
if (!joybchweaponout)
joybchweaponout = joybchweapon;
if (!joybmegaout)
joybmegaout = joybmega;
getcontroljoystickwindow = TXT_NewWindow("Joystick/Gamepad Config ");
TXT_SetWindowPosition(getcontroljoystickwindow, TXT_HORIZ_CENTER, TXT_VERT_TOP, 39, 7);
TXT_AddWidget(getcontroljoystickwindow, TXT_NewStrut(0, 1));
TXT_SetTableColumns(getcontroljoystickwindow, 2);
AddJoystickControl(getcontroljoystickwindow, " Fire ", &joybfire);
AddJoystickControl(getcontroljoystickwindow, " Change Special ", &joybchweapon);
AddJoystickControl(getcontroljoystickwindow, " Mega ", &joybmega);
TXT_AddWidget(getcontroljoystickwindow, TXT_NewStrut(0, 1));
accept_button = TXT_NewWindowAction(KEY_F10, "Accept");
select_button = TXT_NewWindowAction(KEY_ENTER, "Select");
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
TXT_SetHelpLabel(accept_button, " Press F10 to Accept");
TXT_SetHelpLabel(select_button, " Press ENTER to Select");
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, getcontroljoystickwindow);
TXT_SignalConnect(select_button, "pressed", WindowSelect, getcontroljoystickwindow);
TXT_SignalConnect(accept_button, "pressed", ClosePwnBox, getcontroljoystickwindow);
TXT_SignalConnect(accept_button, "pressed", SaveJoyConfig, NULL);
TXT_SetWindowAction(getcontroljoystickwindow, TXT_HORIZ_LEFT, close_button);
TXT_SetWindowAction(getcontroljoystickwindow, TXT_HORIZ_CENTER, select_button);
TXT_SetWindowAction(getcontroljoystickwindow, TXT_HORIZ_RIGHT, accept_button);
}
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include "textscreen.h"
#define arrlen(s) (sizeof(s)/sizeof(*s))
extern txt_window_t* getcontrolkeyboardwindow;
extern txt_window_t* getcontrolmousewindow;
extern txt_window_t* getcontroljoystickwindow;
extern int ControllerType;
extern int key_up_convert, key_down_convert, key_left_convert, key_right_convert, key_fire_convert, key_special_convert, key_mega_convert;
extern int writeflagkey;
extern int mousebfire, mousebchweapon, mousebmega;
extern int mousebfireout, mousebchweaponout, mousebmegaout;
extern int writeflagmouse;
extern int joybfire, joybchweapon, joybmega, joybspeed;
extern int joybfireout, joybchweaponout, joybmegaout;
extern int writeflagjoy, writeflagjoybfire, writeflagjoybchweapon, writeflagjoybmega;
void GetControl(TXT_UNCAST_ARG(widget), void* user_data);
void GetControlKeyboard(TXT_UNCAST_ARG(widget), void* user_data);
void GetControlMouse(TXT_UNCAST_ARG(widget), void* user_data);
void GetControlJoystick(TXT_UNCAST_ARG(widget), void* user_data);
File diff suppressed because it is too large. Load diff
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#include "textscreen.h"
extern txt_window_t* infowindow;
extern txt_table_t* infotable;
extern char* textbox_control;
extern char* textbox_musiccard;
extern char* textbox_soundfx;
extern int keymoveup, keymovedown, keymoveleft, keymoveright, keyfire, keyspecial, keymega;
void MusicCard(TXT_UNCAST_ARG(widget), void* user_data);
void MainMenu(TXT_UNCAST_ARG(widget), void* user_data);
void FXCard(TXT_UNCAST_ARG(widget), void* user_data);
void ControlButtonConfig(TXT_UNCAST_ARG(widget), void* user_data);
void SaveSettings(TXT_UNCAST_ARG(widget), void* user_data);
void WindowSelect(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(window));
void ClosePwnBox(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(window));
+122
View File
@@ -0,0 +1,122 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "textscreen.h"
#include "main.h"
int MidiPort;
int CardType;
int BasePort;
void GetMusiccard(TXT_UNCAST_ARG(widget), void* user_data)
{
if (strcmp((char*)user_data, "General Midi") == 0)
{
CardType = 8;
textbox_musiccard = (char*)"General Midi ";
}
if (strcmp((char*)user_data, "Roland Sound Canvas") == 0)
{
CardType = 7;
textbox_musiccard = (char*)"Roland Sound Canvas ";
}
if (strcmp((char*)user_data, "WaveBlaster") == 0)
{
CardType = 6;
textbox_musiccard = (char*)"WaveBlaster ";
}
if (strcmp((char*)user_data, "Sound Blaster AWE 32") == 0)
{
CardType = 9;
textbox_musiccard = (char*)"Sound Blaster AWE 32 ";
}
if (strcmp((char*)user_data, "Sound Blaster") == 0)
{
CardType = 5;
textbox_musiccard = (char*)"Sound Blaster ";
}
if (strcmp((char*)user_data, "Pro Audio Spectrum") == 0)
{
CardType = 4;
textbox_musiccard = (char*)"Pro Audio Spectrum ";
}
if (strcmp((char*)user_data, "UltraSound") == 0)
{
CardType = 3;
textbox_musiccard = (char*)"Gravis Ultra Sound ";
}
if (strcmp((char*)user_data, "Adlib") == 0)
{
CardType = 2;
textbox_musiccard = (char*)"Adlib ";
}
if (strcmp((char*)user_data, "NONE") == 0)
{
CardType = 1000;
textbox_musiccard = (char*)"None ";
}
TXT_ClearTable(infotable);
infotable = TXT_NewTable(2);
TXT_AddWidgets(infotable,
TXT_NewLabel("Control Type : "),
TXT_NewLabel(textbox_control),
TXT_NewLabel("Music Card : "),
TXT_NewLabel(textbox_musiccard),
TXT_NewLabel("Sound FX Card : "),
TXT_NewLabel(textbox_soundfx),
NULL);
TXT_AddWidget(infowindow, infotable);
}
void GetMusicGMPort(TXT_UNCAST_ARG(widget), void* user_data)
{
BasePort = 0;
if (strcmp((char*)user_data, "220") == 0)
MidiPort = 220;
if (strcmp((char*)user_data, "230") == 0)
MidiPort = 230;
if (strcmp((char*)user_data, "240") == 0)
MidiPort = 240;
if (strcmp((char*)user_data, "250") == 0)
MidiPort = 250;
if (strcmp((char*)user_data, "300") == 0)
MidiPort = 300;
if (strcmp((char*)user_data, "320") == 0)
MidiPort = 320;
if (strcmp((char*)user_data, "330") == 0)
MidiPort = 330;
if (strcmp((char*)user_data, "332") == 0)
MidiPort = 332;
if (strcmp((char*)user_data, "334") == 0)
MidiPort = 334;
if (strcmp((char*)user_data, "336") == 0)
MidiPort = 336;
if (strcmp((char*)user_data, "340") == 0)
MidiPort = 340;
if (strcmp((char*)user_data, "360") == 0)
MidiPort = 360;
}
void GetMusicBasePort(TXT_UNCAST_ARG(widget), void* user_data)
{
MidiPort = 0;
if (strcmp((char*)user_data, "210") == 0)
BasePort = 210;
if (strcmp((char*)user_data, "220") == 0)
BasePort = 220;
if (strcmp((char*)user_data, "230") == 0)
BasePort = 230;
if (strcmp((char*)user_data, "240") == 0)
BasePort = 240;
if (strcmp((char*)user_data, "250") == 0)
BasePort = 250;
if (strcmp((char*)user_data, "260") == 0)
BasePort = 260;
if (strcmp((char*)user_data, "280") == 0)
BasePort = 280;
}
+9
View File
@@ -0,0 +1,9 @@
#pragma once
extern int MidiPort;
extern int CardType;
extern int BasePort;
void GetMusicBasePort(TXT_UNCAST_ARG(widget), void* user_data);
void GetMusiccard(TXT_UNCAST_ARG(widget), void* user_data);
void GetMusicGMPort(TXT_UNCAST_ARG(widget), void* user_data);
+443
View File
@@ -0,0 +1,443 @@
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "../common.h"
#include "prefapi.h"
#include "main.h"
#ifdef _WIN32
#include <io.h>
#endif // _WIN32
#ifdef __GNUC__
#include <unistd.h>
char* ltoa(long i, char* s, int dummy_radix) {
sprintf(s, "%ld", i);
return s;
}
#endif // __GNUC__
#ifdef _MSC_VER
#include <windows.h>
#define PATH_MAX MAX_PATH
#define access _access
#define ltoa _ltoa
#endif // _MSC_VER
static int INI_OpenFile(const char *section, const char *key, const char *defaultValue, char *value, int length, const char *filename)
{
char *va;
char v9c[128];
short v10, i;
FILE *vs;
v10 = 0;
vs = fopen(filename, "r");
if (vs)
{
while (!v10 && fgets(v9c, 128, vs) != 0)
{
if (v9c[0] == '[')
{
for (i = 0; v9c[i] != 0 && v9c[i] != ']'; i++) {
}
if (v9c[i] == ']')
{
v9c[i] = '\0';
if (!strcmp(v9c + 1, section))
v10 = 1;
}
}
}
while (v10 && fgets(v9c, 128, vs) != 0)
{
if (v9c[0] == '[')
{
v10 = 0;
continue;
}
va = strtok(v9c, "=\r\n");
if (va)
{
if (!strcmp(va, key))
{
fclose(vs);
va = strtok(NULL, "\r\n");
if (va)
{
strncpy(value, va, length);
value[length-1] = '\0';
}
else
value[0] = '\0';
return 1;
}
}
}
fclose(vs);
}
if (defaultValue)
strncpy(value, defaultValue, length);
else
value[0] = '\0';
return 0;
}
static int INI_SaveFile(const char *section, const char *key, const char *value, const char *filename)
{
char *va;
char va8[128];
FILE *vs;
short vc, i;
int v28, vbp, vd, v10, l, v1c, v18, vdi, v20;
int empty;
empty = 0;
vc = 0;
if (!section || !*section)
return 0;
vs = fopen(filename, "rb+");
if (!vs)
{
vs = fopen(filename, "wb+");
if (!vs)
return 0;
fseek(vs, 0, SEEK_SET);
}
v10 = 0;
while (!vc && fgets(va8, 128, vs) != 0)
{
if (va8[0] == '\r' || va8[0] == '\n')
continue;
if (va8[0] == '[')
{
for (i = 0; va8[i] != 0 && va8[i] != ']'; i++) {
}
if (va8[i] == ']')
{
va8[i] = '\0';
if (!strcmp(va8 + 1, section))
{
vc = 1;
break;
}
}
else
continue;
}
v10 = ftell(vs);
}
if (!vc)
{
fseek(vs, 0, SEEK_END);
if (!key || !*key)
{
fclose(vs);
return 1;
}
fprintf(vs, "\r\n[%s]\r\n", section);
v28 = vbp = ftell(vs);
}
else
{
v28 = ftell(vs);
while (fgets(va8, 128, vs) != 0)
{
vbp = ftell(vs);
if (va8[0] == '[')
{
vc = 0;
break;
}
va = strtok(va8, "=\r\n");
if (va)
{
if (!strcmp(va, key))
{
va = strtok(NULL, "=\r\n");
if (!va) //Delete line when after string=empty
{
value = "";
va = (char*)"delete";
empty = 1;
}
if (!strcmp(value, va))
{
fclose(vs);
return 1;
}
vc = 1;
break;
}
else
v28 = vbp;
}
}
}
if (!vc)
{
if (vbp == v28)
{
if (!key || !*key || !value || !*value)
{
fclose(vs);
return 1;
}
fseek(vs, 0, SEEK_END);
fprintf(vs, "%s=%s\r\n", key, value);
fclose(vs);
return 1;
}
else
{
if (key && *key)
vd = 0;
else
{
vd = v28 - v10;
vbp = v28;
}
}
}
else
{
vd = vbp - v28;
}
if (key && *key && value && *value)
{
sprintf(va8, "%s=%s\r\n", key, value);
l = strlen(va8);
}
else
l = 0;
v1c = l - vd;
if (key && *key)
v10 = v28;
if (v1c < 0)
{
while (1)
{
fseek(vs, vbp, SEEK_SET);
vdi = fread(va8, 1, 128, vs);
if (!vdi)
break;
v18 = ftell(vs);
fseek(vs, v1c + vbp, SEEK_SET);
vbp = v18;
fwrite(va8, 1, vdi, vs);
}
fseek(vs, v1c, SEEK_END);
#ifdef _MSC_VER
_chsize(_fileno(vs), ftell(vs));
#endif
#ifdef __GNUC__
ftruncate(fileno(vs), ftell(vs));
#endif
}
else if (v1c > 0)
{
fseek(vs, 0, SEEK_END);
v20 = ftell(vs);
vbp = 128;
while (1)
{
int vd1;
vd1 = v20 - vbp;
if (vd1 < v10)
{
vbp = v20 - v10;
if (vbp <= 0)
break;
vd1 = v10;
}
v20 = vd1;
fseek(vs, v20, SEEK_SET);
vdi = fread(va8, 1, vbp, vs);
if (!vdi)
break;
fseek(vs, v1c + v20, SEEK_SET);
fwrite(va8, 1, vdi, vs);
fflush(vs);
}
}
if (key && *key && value && *value)
{
fseek(vs, v10, SEEK_SET);
fprintf(vs, "%s=%s\r\n", key, value);
}
fclose(vs);
if (empty) //Save Settings again when after string=empty
SaveSettings(0, 0);
return 1;
}
static char preference[PATH_MAX];
int INI_InitPreference(const char *section)
{
if (section)
strcpy(preference, section);
return !access(preference, 4);
}
int INI_GetPreferenceLong(const char *section, const char *key, int defValue)
{
char s1[20], s2[20];
ltoa(defValue, s1, 10);
INI_GetPreference(section, key, s2, 20, s1);
return atol(s2);
}
int INI_GetPreferenceHex(const char* section, const char* key, int defValue)
{
char s1[32], s2[32];
unsigned int t;
ltoa(defValue, s1, 10);
INI_GetPreference(section, key, s2, 32, s1);
sscanf(s2, "%x", &t);
return t & 0xFF;
}
/*int INI_GetPreferenceHex(const char *a1, const char *a2, int a3)
{
char s1[32], s2[32], t;
ltoa(a3, s1, 10);
INI_GetPreference(a1, a2, s2, 32, s1);
sscanf(s2, "%x", &t);
return t;
}*/
int INI_GetPreferenceBool(const char *section, const char *key, short defValue)
{
char s2[10];
if (defValue)
INI_GetPreference(section, key, s2, 10, "TRUE");
else
INI_GetPreference(section, key, s2, 10, "FALSE");
if (s2[0] == '1' || !strcmp(s2, "TRUE"))
return 1;
if (s2[0] == '0' || !strcmp(s2, "FALSE"))
return 0;
return atoi(s2);
}
char *INI_GetPreference(const char *section, const char *key, char *retValue, int length, const char *defValue)
{
if (!section || !key || !retValue)
{
if (retValue)
*retValue = 0;
return NULL;
}
INI_OpenFile(section, key, defValue, retValue, length, preference);
return retValue;
}
int INI_PutPreferenceLong(const char *section, const char *key, int value)
{
char s1[32];
if (value == -1)
{
INI_DeletePreference(section, key);
return 0;
}
ltoa(value, s1, 10);
return INI_PutPreference(section, key, s1);
}
int INI_PutPreferenceHex(const char *section, const char *key, int value)
{
char s1[36];
if (value == -1)
{
INI_DeletePreference(section, key);
return 0;
}
sprintf(s1, "%x", value);
return INI_PutPreference(section, key, s1);
}
int INI_PutPreferenceBool(const char *section, const char *key, short value)
{
if (value)
return INI_PutPreference(section, key, "TRUE");
return INI_PutPreference(section, key, "FALSE");
}
int INI_PutPreference(const char *section, const char *key, const char *value)
{
if (!section || !key || !value)
return 0;
return INI_SaveFile(section, key, value, preference);
}
int INI_DeletePreference(const char *section, const char *key)
{
if (!section)
return 0;
//return FUN_0002f3b4(a1, a2, NULL, preference);
return INI_SaveFile(section, key, "", preference);
}
// Safe, portable vsnprintf().
int M_vsnprintf(char* buf, size_t buf_len, const char* s, va_list args)
{
unsigned int result;
if (buf_len < 1)
{
return 0;
}
// Windows (and other OSes?) has a vsnprintf() that doesn't always
// append a trailing \0. So we must do it, and write into a buffer
// that is one byte shorter; otherwise this function is unsafe.
result = vsnprintf(buf, buf_len, s, args);
// If truncated, change the final char in the buffer to a \0.
// A negative result indicates a truncated buffer on Windows.
if (result < 0 || result >= buf_len)
{
buf[buf_len - 1] = '\0';
result = buf_len - 1;
}
return result;
}
// Safe, portable snprintf().
int M_snprintf(char* buf, size_t buf_len, const char* s, ...)
{
va_list args;
int result;
va_start(args, s);
result = M_vsnprintf(buf, buf_len, s, args);
va_end(args);
return result;
}
// Safe string copy function that works like OpenBSD's strlcpy().
// Returns true if the string was not truncated.
int M_StringCopy(char* dest, const char* src, size_t dest_size)
{
size_t len;
if (dest_size >= 1)
{
dest[dest_size - 1] = '\0';
strncpy(dest, src, dest_size - 1);
}
else
{
return 0;
}
len = strlen(dest);
return src[len] == '\0';
}
+16
View File
@@ -0,0 +1,16 @@
#pragma once
int INI_InitPreference(const char *section);
int INI_GetPreferenceLong(const char* section, const char* key, int defValue);
int INI_GetPreferenceHex(const char* section, const char* key, int defValue);
int INI_GetPreferenceBool(const char* section, const char* key, short defValue);
char* INI_GetPreference(const char* section, const char* key, char* retValue, int length, const char* defValue);
int INI_PutPreferenceLong(const char* section, const char* key, int value);
int INI_PutPreferenceHex(const char* section, const char* key, int value);
int INI_PutPreferenceBool(const char* section, const char* key, short value);
int INI_PutPreference(const char* section, const char* key, const char* value);
int INI_DeletePreference(const char* section, const char* key);
int M_snprintf(char* buf, size_t buf_len, const char* s, ...);
int M_StringCopy(char* dest, const char* src, size_t dest_size);
+163
View File
@@ -0,0 +1,163 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "textscreen.h"
#include "main.h"
int SoundCardType;
int SoundMidiPort;
int SoundBasePort;
int SoundIrq;
int SoundDma;
int SoundChannels;
void GetSoundcard(TXT_UNCAST_ARG(widget), void* user_data)
{
if (strcmp((char*)user_data, "General Midi") == 0)
{
SoundCardType = 8;
textbox_soundfx = (char*)"General Midi ";
}
if (strcmp((char*)user_data, "Sound Canvas") == 0)
{
SoundCardType = 7;
textbox_soundfx = (char*)"Roland Sound Canvas ";
}
if (strcmp((char*)user_data, "Sound Blaster") == 0)
{
SoundCardType = 5;
textbox_soundfx = (char*)"Sound Blaster ";
}
if (strcmp((char*)user_data, "Pro Audio Spectrum") == 0)
{
SoundCardType = 4;
textbox_soundfx = (char*)"Pro Audio Spectrum ";
}
if (strcmp((char*)user_data, "UltraSound") == 0)
{
SoundCardType = 3;
textbox_soundfx = (char*)"Gravis Ultra Sound ";
}
if (strcmp((char*)user_data, "Adlib") == 0)
{
SoundCardType = 2;
textbox_soundfx = (char*)"Adlib ";
}
if (strcmp((char*)user_data, "PC Speaker") == 0)
{
SoundCardType = 1;
textbox_soundfx = (char*)"PC Speaker ";
}
if (strcmp((char*)user_data, "NONE") == 0)
{
SoundCardType = 1000;
textbox_soundfx = (char*)"None ";
}
TXT_ClearTable(infotable);
infotable = TXT_NewTable(2);
TXT_AddWidgets(infotable,
TXT_NewLabel("Control Type : "),
TXT_NewLabel(textbox_control),
TXT_NewLabel("Music Card : "),
TXT_NewLabel(textbox_musiccard),
TXT_NewLabel("Sound FX Card : "),
TXT_NewLabel(textbox_soundfx),
NULL);
TXT_AddWidget(infowindow, infotable);
}
void GetSoundChannels(TXT_UNCAST_ARG(widget), void* user_data)
{
if (strcmp((char*)user_data, "One") == 0)
SoundChannels = 1;
if (strcmp((char*)user_data, "Two") == 0)
SoundChannels = 2;
if (strcmp((char*)user_data, "Three") == 0)
SoundChannels = 3;
if (strcmp((char*)user_data, "Four") == 0)
SoundChannels = 4;
if (strcmp((char*)user_data, "Five") == 0)
SoundChannels = 5;
if (strcmp((char*)user_data, "Six") == 0)
SoundChannels = 6;
if (strcmp((char*)user_data, "Seven") == 0)
SoundChannels = 7;
if (strcmp((char*)user_data, "Eight") == 0)
SoundChannels = 8;
}
void GetSoundDma(TXT_UNCAST_ARG(widget), void* user_data)
{
if (strcmp((char*)user_data, "0") == 0)
SoundDma = 1000;
if (strcmp((char*)user_data, "1") == 0)
SoundDma = 1;
if (strcmp((char*)user_data, "3") == 0)
SoundDma = 3;
if (strcmp((char*)user_data, "5") == 0)
SoundDma = 5;
if (strcmp((char*)user_data, "6") == 0)
SoundDma = 6;
if (strcmp((char*)user_data, "7") == 0)
SoundDma = 7;
}
void GetSoundIrq(TXT_UNCAST_ARG(widget), void* user_data)
{
if (strcmp((char*)user_data, "2") == 0)
SoundIrq = 2;
if (strcmp((char*)user_data, "5") == 0)
SoundIrq = 5;
if (strcmp((char*)user_data, "7") == 0)
SoundIrq = 7;
if (strcmp((char*)user_data, "10") == 0)
SoundIrq = 10;
}
void GetSoundBasePort(TXT_UNCAST_ARG(widget), void* user_data)
{
if (strcmp((char*)user_data, "210") == 0)
SoundBasePort = 210;
if (strcmp((char*)user_data, "220") == 0)
SoundBasePort = 220;
if (strcmp((char*)user_data, "230") == 0)
SoundBasePort = 230;
if (strcmp((char*)user_data, "240") == 0)
SoundBasePort = 240;
if (strcmp((char*)user_data, "250") == 0)
SoundBasePort = 250;
if (strcmp((char*)user_data, "260") == 0)
SoundBasePort = 260;
if (strcmp((char*)user_data, "280") == 0)
SoundBasePort = 280;
}
void GetSoundGMPort(TXT_UNCAST_ARG(widget), void* user_data)
{
if (strcmp((char*)user_data, "220") == 0)
SoundMidiPort = 220;
if (strcmp((char*)user_data, "230") == 0)
SoundMidiPort = 230;
if (strcmp((char*)user_data, "240") == 0)
SoundMidiPort = 240;
if (strcmp((char*)user_data, "250") == 0)
SoundMidiPort = 250;
if (strcmp((char*)user_data, "300") == 0)
SoundMidiPort = 300;
if (strcmp((char*)user_data, "320") == 0)
SoundMidiPort = 320;
if (strcmp((char*)user_data, "330") == 0)
SoundMidiPort = 330;
if (strcmp((char*)user_data, "332") == 0)
SoundMidiPort = 332;
if (strcmp((char*)user_data, "334") == 0)
SoundMidiPort = 334;
if (strcmp((char*)user_data, "336") == 0)
SoundMidiPort = 336;
if (strcmp((char*)user_data, "340") == 0)
SoundMidiPort = 340;
if (strcmp((char*)user_data, "360") == 0)
SoundMidiPort = 360;
}
+15
View File
@@ -0,0 +1,15 @@
#pragma once
extern int SoundCardType;
extern int SoundMidiPort;
extern int SoundBasePort;
extern int SoundIrq;
extern int SoundDma;
extern int SoundChannels;
void GetSoundChannels(TXT_UNCAST_ARG(widget), void* user_data);
void GetSoundDma(TXT_UNCAST_ARG(widget), void* user_data);
void GetSoundIrq(TXT_UNCAST_ARG(widget), void* user_data);
void GetSoundBasePort(TXT_UNCAST_ARG(widget), void* user_data);
void GetSoundcard(TXT_UNCAST_ARG(widget), void* user_data);
void GetSoundGMPort(TXT_UNCAST_ARG(widget), void* user_data);
+371
View File
@@ -0,0 +1,371 @@
//
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_joystick.h"
#include "doomkeys.h"
#include "input.h"
#include "prefapi.h"
#include "main.h"
extern "C" {
#include "txt_joyinput.h"
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_label.h"
#include "txt_sdl.h"
#include "txt_utf8.h"
#include "txt_window.h"
}
#define JOYSTICK_INPUT_WIDTH 10
int joystick_index;
int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = {
0, 1, 2, 3
};
// Joystick button variables.
// The ordering of this array is important. We will always try to map
// each variable to the virtual button with the same array index. For
// example: joybfire should always be 0, and then we change
// joystick_physical_buttons[0] to point to the physical joystick
// button that the user wants to use for firing. We do this so that
// the menus work (the game code is hard coded to interpret
// button #0 = select menu item, button #1 = go back to previous menu).
static int* all_joystick_buttons[NUM_VIRTUAL_BUTTONS] =
{
&joybfire,
&joybchweapon,
&joybmega,
&joybspeed,
};
static int PhysicalForVirtualButton(int vbutton)
{
if (vbutton < NUM_VIRTUAL_BUTTONS)
{
return joystick_physical_buttons[vbutton];
}
else
{
return vbutton;
}
}
// Get the virtual button number for the given variable, ie. the
// variable's index in all_joystick_buttons[NUM_VIRTUAL_BUTTONS].
static int VirtualButtonForVariable(int* variable)
{
int i;
for (i = 0; i < arrlen(all_joystick_buttons); ++i)
{
if (variable == all_joystick_buttons[i])
{
return i;
}
}
//I_Error("Couldn't find virtual button");
return -1;
}
// Rearrange joystick button configuration to be in "canonical" form:
// each joyb* variable should have a value equal to its index in
// all_joystick_buttons[NUM_VIRTUAL_BUTTONS] above.
static void CanonicalizeButtons(void)
{
int new_mapping[NUM_VIRTUAL_BUTTONS];
int vbutton;
int i;
for (i = 0; i < arrlen(all_joystick_buttons); ++i)
{
vbutton = *all_joystick_buttons[i];
// Don't remap the speed key if it's bound to "always run".
// Also preserve "unbound" variables.
if ((all_joystick_buttons[i] == &joybspeed && vbutton >= 20)
|| vbutton < 0)
{
new_mapping[i] = i;
}
else
{
new_mapping[i] = PhysicalForVirtualButton(vbutton);
*all_joystick_buttons[i] = i;
}
}
for (i = 0; i < NUM_VIRTUAL_BUTTONS; ++i)
{
joystick_physical_buttons[i] = new_mapping[i];
}
}
// Check all existing buttons and clear any using the specified physical
// button.
static void ClearVariablesUsingButton(int physbutton)
{
int vbutton;
int i;
for (i = 0; i < arrlen(all_joystick_buttons); ++i)
{
vbutton = *all_joystick_buttons[i];
if (vbutton >= 0 && physbutton == PhysicalForVirtualButton(vbutton))
{
*all_joystick_buttons[i] = -1;
}
}
}
// Called in response to SDL events when the prompt window is open:
static int EventCallback(SDL_Event* event, TXT_UNCAST_ARG(joystick_input))
{
TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
// Got the joystick button press?
if (event->type == SDL_JOYBUTTONDOWN)
{
int vbutton, physbutton;
// Before changing anything, remap button configuration into
// canonical form, to avoid conflicts.
CanonicalizeButtons();
vbutton = VirtualButtonForVariable(joystick_input->variable);
physbutton = event->jbutton.button;
if (joystick_input->check_conflicts)
{
ClearVariablesUsingButton(physbutton);
}
// Set mapping.
*joystick_input->variable = vbutton;
joystick_physical_buttons[vbutton] = physbutton;
if (vbutton == 0)
{
joybfireout = physbutton;
writeflagjoybfire = 1;
}
if (vbutton == 1)
{
joybchweaponout = physbutton;
writeflagjoybchweapon = 1;
}
if (vbutton == 2)
{
joybmegaout = physbutton;
writeflagjoybmega = 1;
}
TXT_CloseWindow(joystick_input->prompt_window);
return 1;
}
return 0;
}
// When the prompt window is closed, disable the event callback function;
// we are no longer interested in receiving notification of events.
static void PromptWindowClosed(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(joystick))
{
TXT_CAST_ARG(SDL_Joystick, joystick);
SDL_JoystickClose(joystick);
TXT_SDL_SetEventCallback(NULL, NULL);
SDL_JoystickEventState(SDL_DISABLE);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
}
static void OpenErrorWindow(void)
{
txt_window_t* window;
txt_window_action_t* close_button;
window = TXT_CustomMessageBox(NULL, "Please connect a controller first!", TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_RED, TXT_COLOR_RED, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE, TXT_COLOR_BRIGHT_WHITE);
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
TXT_SetWidgetFocus(getcontroljoystickwindow, 1);
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
}
static void OpenPromptWindow(txt_joystick_input_t* joystick_input)
{
txt_window_t* window;
txt_window_action_t* close_button;
SDL_Joystick* joystick;
// Silently update when the shift button is held down.
joystick_input->check_conflicts = !TXT_GetModifierState(TXT_MOD_SHIFT);
if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
{
return;
}
// Check the current joystick is valid
joystick = SDL_JoystickOpen(joystick_index);
if (joystick == NULL)
{
OpenErrorWindow();
return;
}
// Open the prompt window
window = TXT_MessageBox(NULL, " Click the new Button ");
TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_TOP, 39, 10);
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
TXT_SDL_SetEventCallback(EventCallback, joystick_input);
TXT_SignalConnect(window, "closed", PromptWindowClosed, joystick);
joystick_input->prompt_window = window;
SDL_JoystickEventState(SDL_ENABLE);
TXT_SetWidgetFocus(getcontroljoystickwindow, 1);
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
}
static void TXT_JoystickInputSizeCalc(TXT_UNCAST_ARG(joystick_input))
{
TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
// All joystickinputs are the same size.
joystick_input->widget.w = JOYSTICK_INPUT_WIDTH;
joystick_input->widget.h = 1;
}
static void GetJoystickButtonDescription(int vbutton, char* buf,
size_t buf_len)
{
M_snprintf(buf, buf_len, "BUTTON %i",
PhysicalForVirtualButton(vbutton) + 1);
}
static void TXT_JoystickInputDrawer(TXT_UNCAST_ARG(joystick_input))
{
TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
char buf[20];
int i;
if (*joystick_input->variable < 0)
{
M_StringCopy(buf, "(none)", sizeof(buf));
}
else
{
GetJoystickButtonDescription(*joystick_input->variable,
buf, sizeof(buf));
}
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_SetWidgetBG(joystick_input);
TXT_DrawString(buf);
for (i = TXT_UTF8_Strlen(buf); i < JOYSTICK_INPUT_WIDTH; ++i)
{
TXT_DrawString(" ");
}
}
static void TXT_JoystickInputDestructor(TXT_UNCAST_ARG(joystick_input))
{
}
static int TXT_JoystickInputKeyPress(TXT_UNCAST_ARG(joystick_input), int key)
{
TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
if (key == KEY_ENTER)
{
// Open a window to prompt for the new joystick press
OpenPromptWindow(joystick_input);
return 1;
}
if (key == KEY_BACKSPACE || key == KEY_DEL)
{
*joystick_input->variable = -1;
}
return 0;
}
static void TXT_JoystickInputMousePress(TXT_UNCAST_ARG(widget),
int x, int y, int b)
{
TXT_CAST_ARG(txt_joystick_input_t, widget);
// Clicking is like pressing enter
if (b == TXT_MOUSE_LEFT)
{
TXT_JoystickInputKeyPress(widget, KEY_ENTER);
}
}
txt_widget_class_t txt_joystick_input_class =
{
TXT_AlwaysSelectable,
TXT_JoystickInputSizeCalc,
TXT_JoystickInputDrawer,
TXT_JoystickInputKeyPress,
TXT_JoystickInputDestructor,
TXT_JoystickInputMousePress,
NULL,
};
txt_joystick_input_t* TXT_NewJoystickInput(int* variable)
{
txt_joystick_input_t* joystick_input;
joystick_input = (txt_joystick_input_t * )malloc(sizeof(txt_joystick_input_t));
TXT_InitWidget(joystick_input, &txt_joystick_input_class);
joystick_input->variable = variable;
return joystick_input;
}
+41
View File
@@ -0,0 +1,41 @@
//
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
#ifndef TXT_JOYB_INPUT_H
#define TXT_JOYB_INPUT_H
#define NUM_VIRTUAL_BUTTONS 4
typedef struct txt_joystick_input_s txt_joystick_input_t;
#include "txt_widget.h"
#include "txt_window.h"
//
// A joystick input is like an input box. When selected, a box pops up
// allowing a joystick button to be pressed to select it.
//
struct txt_joystick_input_s
{
txt_widget_t widget;
int* variable;
txt_window_t* prompt_window;
int check_conflicts;
};
txt_joystick_input_t* TXT_NewJoystickInput(int* variable);
extern int joystick_index;
#endif /* #ifndef TXT_JOYB_INPUT_H */
+200
View File
@@ -0,0 +1,200 @@
//
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
#include <stdlib.h>
#include <string.h>
#include "doomkeys.h"
#include "prefapi.h"
#include "input.h"
#include "main.h"
extern "C" {
#include "txt_keyinput.h"
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_label.h"
#include "txt_utf8.h"
#include "txt_window.h"
}
#define KEY_INPUT_WIDTH 8
static int KeyPressCallback(txt_window_t* window, int key,
TXT_UNCAST_ARG(key_input))
{
TXT_CAST_ARG(txt_key_input_t, key_input);
if (key != KEY_ESCAPE)
{
// Got the key press. Save to the variable and close the window.
*key_input->variable = key;
if (key_input->check_conflicts)
{
TXT_EmitSignal(key_input, "set");
}
TXT_CloseWindow(window);
// Return to normal input mode now that we have the key.
TXT_SetInputMode(TXT_INPUT_NORMAL);
return 1;
}
else
{
return 0;
}
}
static void ReleaseGrab(TXT_UNCAST_ARG(window), TXT_UNCAST_ARG(unused))
{
// SDL2-TODO: Needed?
// SDL_WM_GrabInput(SDL_GRAB_OFF);
}
static void OpenPromptWindow(txt_key_input_t* key_input)
{
txt_window_t* window;
txt_window_action_t* close_button;
// Silently update when the shift button is held down.
key_input->check_conflicts = !TXT_GetModifierState(TXT_MOD_SHIFT);
window = TXT_CustomMessageBox(NULL, " Press New Key ", TXT_COLOR_BLUE, TXT_COLOR_GREY, TXT_COLOR_GREY, TXT_COLOR_BLUE, TXT_COLOR_BLUE, TXT_COLOR_BLUE, TXT_COLOR_BLUE);
TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_TOP, 40, 11);
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
TXT_SetKeyListener(window, KeyPressCallback, key_input);
// Switch to raw input mode while we're grabbing the key.
TXT_SetInputMode(TXT_INPUT_RAW);
// Grab input while reading the key. On Windows Mobile
// handheld devices, the hardware keypresses are only
// detected when input is grabbed.
// SDL2-TODO: Needed?
//SDL_WM_GrabInput(SDL_GRAB_ON);
TXT_SignalConnect(window, "closed", ReleaseGrab, NULL);
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
TXT_SetWidgetFocus(window, 0);
TXT_SetWidgetFocus(getcontrolkeyboardwindow, 1);
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
}
static void TXT_KeyInputSizeCalc(TXT_UNCAST_ARG(key_input))
{
TXT_CAST_ARG(txt_key_input_t, key_input);
// All keyinputs are the same size.
key_input->widget.w = KEY_INPUT_WIDTH;
key_input->widget.h = 1;
}
static void TXT_KeyInputDrawer(TXT_UNCAST_ARG(key_input))
{
TXT_CAST_ARG(txt_key_input_t, key_input);
char buf[20];
int i;
if (*key_input->variable == 0)
{
M_StringCopy(buf, "(none)", sizeof(buf));
}
else
{
TXT_GetKeyDescription(*key_input->variable, buf, sizeof(buf));
}
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_SetWidgetBG(key_input);
TXT_DrawString(buf);
for (i = TXT_UTF8_Strlen(buf); i < KEY_INPUT_WIDTH; ++i)
{
TXT_DrawString(" ");
}
}
static void TXT_KeyInputDestructor(TXT_UNCAST_ARG(key_input))
{
}
static int TXT_KeyInputKeyPress(TXT_UNCAST_ARG(key_input), int key)
{
TXT_CAST_ARG(txt_key_input_t, key_input);
if (key == KEY_ENTER)
{
// Open a window to prompt for the new key press
OpenPromptWindow(key_input);
return 1;
}
if (key == KEY_BACKSPACE || key == KEY_DEL)
{
*key_input->variable = 0;
}
return 0;
}
static void TXT_KeyInputMousePress(TXT_UNCAST_ARG(widget), int x, int y, int b)
{
TXT_CAST_ARG(txt_key_input_t, widget);
// Clicking is like pressing enter
if (b == TXT_MOUSE_LEFT)
{
TXT_KeyInputKeyPress(widget, KEY_ENTER);
}
}
txt_widget_class_t txt_key_input_class =
{
TXT_AlwaysSelectable,
TXT_KeyInputSizeCalc,
TXT_KeyInputDrawer,
TXT_KeyInputKeyPress,
TXT_KeyInputDestructor,
TXT_KeyInputMousePress,
NULL,
};
txt_key_input_t* TXT_NewKeyInput(int* variable)
{
txt_key_input_t* key_input;
key_input = (txt_key_input_t * )malloc(sizeof(txt_key_input_t));
TXT_InitWidget(key_input, &txt_key_input_class);
key_input->variable = variable;
return key_input;
}
+37
View File
@@ -0,0 +1,37 @@
//
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
#ifndef TXT_KEY_INPUT_H
#define TXT_KEY_INPUT_H
typedef struct txt_key_input_s txt_key_input_t;
#include "txt_widget.h"
//
// A key input is like an input box. When selected, a box pops up
// allowing a key to be selected.
//
struct txt_key_input_s
{
txt_widget_t widget;
int* variable;
int check_conflicts;
};
txt_key_input_t* TXT_NewKeyInput(int* variable);
#endif /* #ifndef TXT_KEY_INPUT_H */
+193
View File
@@ -0,0 +1,193 @@
//
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "doomkeys.h"
#include "prefapi.h"
#include "input.h"
#include "main.h"
extern "C" {
#include "txt_mouseinput.h"
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_label.h"
#include "txt_utf8.h"
#include "txt_window.h"
}
// eg. "BUTTON #10"
#define MOUSE_INPUT_WIDTH 10
static int MousePressCallback(txt_window_t* window,
int x, int y, int b,
TXT_UNCAST_ARG(mouse_input))
{
TXT_CAST_ARG(txt_mouse_input_t, mouse_input);
// Got the mouse press. Save to the variable and close the window.
*mouse_input->variable = b - TXT_MOUSE_BASE;
if (mouse_input->check_conflicts)
{
TXT_EmitSignal(mouse_input, "set");
}
TXT_CloseWindow(window);
return 1;
}
static void OpenPromptWindow(txt_mouse_input_t* mouse_input)
{
txt_window_t* window;
txt_window_action_t* close_button;
// Silently update when the shift key is held down.
mouse_input->check_conflicts = !TXT_GetModifierState(TXT_MOD_SHIFT);
window = TXT_MessageBox(NULL, " Click the new Button ");
TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_TOP, 39, 10);
close_button = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
TXT_SetMouseListener(window, MousePressCallback, mouse_input);
TXT_SetHelpLabel(close_button, " Press ESC to Abort");
TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
TXT_SetWidgetFocus(getcontrolmousewindow, 1);
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, close_button);
}
static void TXT_MouseInputSizeCalc(TXT_UNCAST_ARG(mouse_input))
{
TXT_CAST_ARG(txt_mouse_input_t, mouse_input);
// All mouseinputs are the same size.
mouse_input->widget.w = MOUSE_INPUT_WIDTH;
mouse_input->widget.h = 1;
}
static void GetMouseButtonDescription(int button, char* buf, size_t buf_len)
{
switch (button)
{
case 0:
M_StringCopy(buf, "LEFT BUTTON", buf_len);
break;
case 1:
M_StringCopy(buf, "RIGHT BUTTON", buf_len);
break;
case 2:
M_StringCopy(buf, "MID BUTTON", buf_len);
break;
default:
M_snprintf(buf, buf_len, "BUTTON %i", button + 1);
break;
}
}
static void TXT_MouseInputDrawer(TXT_UNCAST_ARG(mouse_input))
{
TXT_CAST_ARG(txt_mouse_input_t, mouse_input);
char buf[20];
int i;
if (*mouse_input->variable < 0)
{
M_StringCopy(buf, "(none)", sizeof(buf));
}
else
{
GetMouseButtonDescription(*mouse_input->variable, buf, sizeof(buf));
}
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_SetWidgetBG(mouse_input);
TXT_DrawString(buf);
for (i = TXT_UTF8_Strlen(buf); i < MOUSE_INPUT_WIDTH; ++i)
{
TXT_DrawString(" ");
}
}
static void TXT_MouseInputDestructor(TXT_UNCAST_ARG(mouse_input))
{
}
static int TXT_MouseInputKeyPress(TXT_UNCAST_ARG(mouse_input), int key)
{
TXT_CAST_ARG(txt_mouse_input_t, mouse_input);
if (key == KEY_ENTER)
{
// Open a window to prompt for the new mouse press
OpenPromptWindow(mouse_input);
return 1;
}
if (key == KEY_BACKSPACE || key == KEY_DEL)
{
*mouse_input->variable = -1;
}
return 0;
}
static void TXT_MouseInputMousePress(TXT_UNCAST_ARG(widget), int x, int y, int b)
{
TXT_CAST_ARG(txt_mouse_input_t, widget);
// Clicking is like pressing enter
if (b == TXT_MOUSE_LEFT)
{
TXT_MouseInputKeyPress(widget, KEY_ENTER);
}
}
txt_widget_class_t txt_mouse_input_class =
{
TXT_AlwaysSelectable,
TXT_MouseInputSizeCalc,
TXT_MouseInputDrawer,
TXT_MouseInputKeyPress,
TXT_MouseInputDestructor,
TXT_MouseInputMousePress,
NULL,
};
txt_mouse_input_t* TXT_NewMouseInput(int* variable)
{
txt_mouse_input_t* mouse_input;
mouse_input = (txt_mouse_input_t *) malloc(sizeof(txt_mouse_input_t));
TXT_InitWidget(mouse_input, &txt_mouse_input_class);
mouse_input->variable = variable;
return mouse_input;
}
+38
View File
@@ -0,0 +1,38 @@
//
// Copyright(C) 2005-2014 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
#ifndef TXT_MOUSE_INPUT_H
#define TXT_MOUSE_INPUT_H
typedef struct txt_mouse_input_s txt_mouse_input_t;
#include "txt_widget.h"
//
// A mouse input is like an input box. When selected, a box pops up
// allowing a mouse to be selected.
//
struct txt_mouse_input_s
{
txt_widget_t widget;
int* variable;
int check_conflicts;
};
txt_mouse_input_t* TXT_NewMouseInput(int* variable);
#endif /* #ifndef TXT_MOUSE_INPUT_H */
+236
View File
@@ -0,0 +1,236 @@
#include <stdint.h>
#include "common.h"
#include "gfxapi.h"
#include "rap.h"
#include "windows.h"
#include "glbapi.h"
#include "entypes.h"
char sdtablemem[516];
char *sdtable;
typedef struct
{
int item;
int x;
int y;
}SHADOW;
#define MAX_SHADOWS 50
#define MAX_GSHADOWS 25
SHADOW shads[MAX_SHADOWS];
SHADOW gshads[MAX_GSHADOWS];
int num_shadows, num_gshadows;
#define MAXZ 1280;
/***************************************************************************
SHADOW_Draw () - Draws AIR shadows in 3D perspective
***************************************************************************/
void
SHADOW_Draw(
char *pic, // INPUT : pointer to sprite data
int x, // INPUT : x position of sprite
int y // INPUT : y position of sprite
)
{
GFX_PIC *h = (GFX_PIC*)pic;
GFX_SPRITE *ah;
int lx, ly, oldsy, sx, sy, ox, oy, x2, y2, oldy, drawflag;
x -= 10;
y += 20;
oldy = oldsy = -1;
G3D_x = x;
G3D_y = y;
G3D_z = MAXZ;
GFX_3DPoint();
ox = G3D_screenx;
oy = G3D_screeny;
G3D_x = ox + LE_LONG(h->width) - 1;
G3D_y = oy + LE_LONG(h->height) - 1;
G3D_z = MAXZ;
GFX_3DPoint();
lx = G3D_screenx - ox + 1;
ly = G3D_screenx - oy + 1;
if (!GFX_ClipLines(0, &ox, &oy, &lx, &ly))
return;
pic += sizeof(GFX_PIC);
ah = (GFX_SPRITE*)pic;
while (LE_LONG(ah->offset) != -1)
{
pic += sizeof(GFX_SPRITE);
ox = LE_LONG(ah->x) + x;
oy = LE_LONG(ah->y) + y;
x2 = ox + LE_LONG(ah->length) - 1;
y2 = oy + 1;
G3D_x = ox;
G3D_y = oy;
G3D_z = MAXZ;
GFX_3DPoint();
sx = G3D_screenx;
sy = G3D_screeny;
G3D_x = x2;
G3D_y = y2;
G3D_z = MAXZ;
GFX_3DPoint();
lx = G3D_screenx - sx + 1;
if (sy > SCREENHEIGHT)
return;
drawflag = 1;
if (LE_LONG(ah->y) != oldy && oldsy == sy)
drawflag = 0;
if (drawflag)
{
ly = 1;
if (GFX_ClipLines(0, &sx, &sy, &lx, &ly))
GFX_Shade(displaybuffer + sx + ylookup[sy], lx, sdtable);
oldy = LE_LONG(ah->y);
}
oldsy = sy;
pic += LE_LONG(ah->length);
ah = (GFX_SPRITE*)pic;
}
}
/***************************************************************************
SHADOW_Init() - Allocate memory and set 3D view
***************************************************************************/
void
SHADOW_Init(
void
)
{
sdtable = sdtablemem;
sdtable = (char*)(((intptr_t)sdtable + 255) & ~255);
GFX_3D_SetView(160, 100, 1000);
}
/***************************************************************************
SHADOW_MakeShades() - Make shade tables
***************************************************************************/
void
SHADOW_MakeShades(
void
)
{
GFX_MakeLightTable(palette, sdtable, -6);
}
/***************************************************************************
SHADOW_Add() - Add a Air ship shadow
***************************************************************************/
void
SHADOW_Add(
int item, // INPUT : GLB item
int x, // INPUT : x position
int y // INPUT : y position
)
{
SHADOW *cur;
cur = &shads[num_shadows];
if (num_shadows < MAX_SHADOWS)
{
cur->item = item;
cur->x = x;
cur->y = y;
num_shadows++;
}
}
/***************************************************************************
SHADOW_GAdd() - Adds Ground shadow
***************************************************************************/
void
SHADOW_GAdd(
int item, // INPUT : GLB item
int x, // INPUT : x position
int y // INPUT : y position
)
{
SHADOW *cur;
cur = &gshads[num_gshadows];
if (num_gshadows < MAX_GSHADOWS)
{
cur->item = item;
cur->x = x - 3;
cur->y = y + 4;
num_gshadows++;
}
}
/***************************************************************************
SHADOW_DisplaySky () - Display Sky Shadows
***************************************************************************/
void
SHADOW_DisplaySky(
void
)
{
char *pic;
SHADOW *cur;
cur = shads;
if (opt_detail < 1)
return;
while (--num_shadows != -1)
{
pic = GLB_GetItem(cur->item);
SHADOW_Draw(pic, cur->x, cur->y);
cur++;
}
num_shadows = 0;
}
/***************************************************************************
SHADOW_DisplayGround() - Display Ground Shadows
***************************************************************************/
void
SHADOW_DisplayGround(
void
)
{
char *pic;
SHADOW *cur;
cur = gshads;
if (opt_detail < 1)
return;
while (--num_gshadows != -1)
{
pic = GLB_GetItem(cur->item);
GFX_ShadeShape(DARK, (char*)pic, cur->x, cur->y);
cur++;
}
num_gshadows = 0;
}
+11
View File
@@ -0,0 +1,11 @@
#pragma once
extern int num_gshadows;
extern int num_shadows;
void SHADOW_Init(void);
void SHADOW_MakeShades(void);
void SHADOW_GAdd(int item, int x, int y);
void SHADOW_Add(int item, int x, int y);
void SHADOW_DisplayGround();
void SHADOW_DisplaySky();
+1307
View File
File diff suppressed because it is too large. Load diff
+76
View File
@@ -0,0 +1,76 @@
#pragma once
#include "rap.h"
#include "gfxapi.h"
#define MAX_SHOTS 70
typedef enum
{
S_ALL,
S_AIR,
S_GROUND,
S_GRALL,
S_GTILE,
S_SUCK
}HIT_TYPE;
typedef enum
{
S_SHOOT,
S_LINE,
S_BEAM
}BEAM_TYPE;
typedef struct
{
int lumpnum; // LUMPNUM OF PIC(S)
char *pic[10]; // POINTER TO PIC
int shadow; // SHADOW ON/OFF
int type; // SHOT TYPE
int hits; // DAMAGE SHOT WILL DO
int speed; // START SPEED
int maxspeed; // MAXIMUM SPEED
int startframe; // START ANIM ON FRAME
int numframes; // NUMBER OF FRAMES OF ANIM
int shoot_rate; // SHOOT EVERY (N) FRAMES
int cur_shoot; // HOLDS FRAME COUNT DOWN
int delayflag; // DEALAYED ANIM START
int smoke; // SMOKE TRAIL
int use_plot; // TRUE = PLOT X,Y ( SLOWER )
int move_flag; // DOES SHOT NEED MOVEMENT
int ht; // SHOT HIT TYPE ( AIR/GROUND )
int fplrx; // FOLLOW PLAYER X POS
int fplry; // FOLLOW PLAYER Y POS
int meffect; // TRACK MOVE TO FIND HIT ?
int beam; // BEAM WEAPON TYPE
GFX_PIC *h;
int hlx;
int hly;
}SHOT_LIB;
typedef struct SHOTS_S
{
struct SHOTS_S *prev; // Link List Prev
struct SHOTS_S *next; // Link List Next
char *pic; // pointer to cur frame pic
int x; // cur shot center x
int y; // cur shot center y
MOVEOBJ move; // MOVE stuff
int speed; // cur speed
int curframe; // current anim frame
int doneflag; // shot done = TRUE
int delayflag; // DEALAYED ANIM START
int startx; // PLAYER X OFFSET;
int starty; // PLAYER Y OFFSET;
SHOT_LIB *lib;
int cnt;
}SHOTS;
extern char *lashit[4];
int SHOTS_PlayerShoot(int type);
void SHOTS_Clear(void);
void SHOTS_Think(void);
void SHOTS_Display(void);
void SHOTS_Init(void);
+693
View File
@@ -0,0 +1,693 @@
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "gfxapi.h"
#include "glbapi.h"
#include "swdapi.h"
#include "rap.h"
#include "store.h"
#include "windows.h"
#include "objects.h"
#include "kbdapi.h"
#include "imsapi.h"
#include "ptrapi.h"
#include "help.h"
#include "fx.h"
#include "joyapi.h"
#include "input.h"
#include "fileids.h"
#include "winids.h"
#include "i_video.h"
#define BUY_MODE 0
#define SELL_MODE 1
static int window;
int buy_count, sell_count;
int b_items[S_LAST_OBJECT], s_items[S_LAST_OBJECT];
int id_pics[4] = {
FILE111_WMALE_PIC, FILE114_BMALE_PIC, FILE112_WFEMALE_PIC, FILE113_BFEMALE_PIC
};
int mainbut[2] = {
FILE134_BUYITEM_PIC, FILE135_SELLITEM_PIC
};
int buybut[2] = {
FILE130_BUYLGT_PIC, FILE131_BUYDRK_PIC
};
int sellbut[2] = {
FILE132_SELLGT_PIC, FILE133_SELLDRK_PIC
};
char saying[2][9] = {
"COST",
"RESALE"
};
int items[S_LAST_OBJECT] = {
FILE03a_ITEM00_TXT,
FILE03b_ITEM01_TXT,
FILE03c_ITEM02_TXT,
FILE03d_ITEM03_TXT,
FILE03e_ITEM04_TXT,
FILE03f_ITEM05_TXT,
FILE040_ITEM06_TXT,
FILE041_ITEM07_TXT,
FILE042_ITEM08_TXT,
FILE043_ITEM09_TXT,
FILE044_ITEM10_TXT,
FILE045_ITEM11_TXT,
FILE046_ITEM12_TXT,
FILE047_ITEM13_TXT,
FILE048_ITEM14_TXT,
FILE049_ITEM15_TXT,
FILE04a_ITEM16_TXT,
FILE04b_ITEM17_TXT,
-1,
-1,
-1,
-1,
-1,
0
};
char storetext[8][20] = {
" EXIT", //0
"ACTIVATE SELL MODE", //1
"ACTIVATE BUY MODE", //2
" NEXT ITEM", //3
" PREVIOUS ITEM", //4
" BUY AN ITEM", //5
" SELL AN ITEM", //6
" HDE MAIN DISPLAY" //7
};
char yh_hold[16];
static int cur_item, mode;
/*-------------------------------------------------------------------------*
MakeBuyItems () - Makes items you can Buy
*-------------------------------------------------------------------------*/
int
MakeBuyItems(
void
)
{
int loop, flag, cost1, cost2, num;
buy_count = 0;
memset(b_items, 0, sizeof(b_items));
for (loop = 0; loop < S_ITEMBUY1; loop++)
{
if (OBJS_CanBuy(loop))
{
b_items[buy_count] = loop;
buy_count++;
}
}
// SORT BY $ AMOUNT ============================
if (buy_count > 1)
{
do
{
flag = 0;
for (loop = 0; loop < buy_count - 1; loop++)
{
cost1 = OBJS_GetCost(b_items[loop]);
cost2 = OBJS_GetCost(b_items[loop+1]);
if (cost1 > cost2)
{
flag = 1;
num = b_items[loop];
b_items[loop] = b_items[loop + 1];
b_items[loop + 1] = num;
}
}
} while (flag);
}
return buy_count;
}
/*-------------------------------------------------------------------------*
MakeSellItems() - Makes the items that you can sell
*-------------------------------------------------------------------------*/
int
MakeSellItems(
void
)
{
int loop, flag, cost1, cost2, num;
memset(s_items, 0, sizeof(s_items));
sell_count = 0;
for (loop = 0; loop < S_LAST_OBJECT; loop++)
{
if (OBJS_CanSell(loop))
{
s_items[sell_count] = loop;
sell_count++;
}
}
// SORT BY $ AMOUNT ============================
if (sell_count > 1)
{
do
{
flag = 0;
for (loop = 0; loop < sell_count - 1; loop++)
{
cost1 = OBJS_GetCost(s_items[loop]);
cost2 = OBJS_GetCost(s_items[loop+1]);
if (cost1 > cost2)
{
flag = 1;
num = s_items[loop];
s_items[loop] = s_items[loop + 1];
s_items[loop + 1] = num;
}
}
} while (flag);
}
return sell_count;
}
/*-------------------------------------------------------------------------*
Harrold() - Lets Harrold do Some Talking
*-------------------------------------------------------------------------*/
void
Harrold(
int item // INPUT : GLB item of harrold text
)
{
int prev, next, buy, buyit, sell;
prev = SWD_GetFieldItem(window, STOR_PREV);
next = SWD_GetFieldItem(window, STOR_NEXT);
buy = SWD_GetFieldItem(window, STOR_BUY);
buyit = SWD_GetFieldItem(window, STOR_BUYIT);
sell = SWD_GetFieldItem(window, STOR_SELL);
SWD_SetFieldItem(window, STOR_PREV, -1);
SWD_SetFieldItem(window, STOR_NEXT, -1);
SWD_SetFieldItem(window, STOR_BUY, -1);
SWD_SetFieldItem(window, STOR_BUYIT, -1);
SWD_SetFieldItem(window, STOR_SELL, -1);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
KBD_Clear();
SWD_SetFieldText(window, STOR_STATS, 0);
SWD_SetFieldText(window, STOR_TEXTCOST, 0);
SWD_SetFieldText(window, STOR_NUM, 0);
SWD_SetFieldText(window, STOR_COST, 0);
SWD_SetFieldItem(window, STOR_COMP, item);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
IMS_WaitTimed(10);
SWD_SetFieldItem(window, STOR_COMP, -1);
SWD_SetFieldItem(window, STOR_PREV, prev);
SWD_SetFieldItem(window, STOR_NEXT, next);
SWD_SetFieldItem(window, STOR_BUY, buy);
SWD_SetFieldItem(window, STOR_BUYIT, buyit);
SWD_SetFieldItem(window, STOR_SELL, sell);
}
/***************************************************************************
STORE_Enter () - Lets User go in store and buy and sell things
***************************************************************************/
void
STORE_Enter(
void
)
{
int update, opt, oldopt, max_items, pos, cost, loop, num;
SWD_DLG dlg;
char youhave[50], coststr[50];
update = 0;
opt = -1;
oldopt = -1;
max_items = 0;
PTR_DrawCursor(0);
KBD_Clear();
GFX_FadeOut(0, 0, 0, 5);
g_button_flag = 0;
window = SWD_InitMasterWindow(FILE131_STORE_SWD);
SWD_SetFieldItem(window, STOR_ID, id_pics[plr.id_pic]);
SWD_SetFieldItem(window, STOR_BUYIT, mainbut[mode]);
SWD_GetFieldText(window, STOR_STATS, yh_hold);
SWD_SetFieldText(window, STOR_STATS, NULL);
SWD_SetFieldText(window, STOR_CALLSIGN, plr.callsign);
sprintf(youhave, "%07d", plr.score);
SWD_SetFieldText(window, STOR_SCORE, youhave);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
GFX_FadeIn(palette, 16);
SWD_SetFieldPtr(window, STOR_VEXIT);
PTR_DrawCursor(1);
OBJS_GetNum();
Harrold(FILE04c_HAR1_TXT);
cur_item = 0;
mode = BUY_MODE;
if (mode == BUY_MODE)
{
SWD_SetFieldItem(window, STOR_BUY, buybut[0]);
SWD_SetFieldItem(window, STOR_SELL, sellbut[1]);
}
else
{
SWD_SetFieldItem(window, STOR_BUY, buybut[1]);
SWD_SetFieldItem(window, STOR_SELL, sellbut[0]);
}
SWD_ShowAllWindows();
GFX_DisplayUpdate();
update = 1;
while (1)
{
MakeSellItems();
MakeBuyItems();
if (mode == BUY_MODE)
max_items = buy_count;
else
max_items = sell_count;
if (max_items < 1)
{
update = 1;
if (mode == 0)
EXIT_Error("STORE Error ( BUY_MODE )");
else
{
Harrold(FILE050_HAR5_TXT);
mode = BUY_MODE;
max_items = MakeBuyItems();
if (max_items < 1)
EXIT_Error("STORE THING 2");
}
}
if (update)
{
update = 0;
if (cur_item < 0)
cur_item = max_items - 1;
if (cur_item >= max_items)
cur_item = 0;
if (mode == BUY_MODE)
{
pos = b_items[cur_item];
SWD_SetFieldItem(window, STOR_BUY, buybut[0]);
SWD_SetFieldItem(window, STOR_SELL, sellbut[1]);
cost = OBJS_GetCost(pos);
if (OBJS_IsOnly(pos))
num = OBJS_GetAmt(pos);
else
num = OBJS_GetTotal(pos);
sprintf(youhave, "%02d", num);
sprintf(coststr, "%02d", cost);
}
else
{
pos = s_items[cur_item];
SWD_SetFieldItem(window, STOR_BUY, buybut[1]);
SWD_SetFieldItem(window, STOR_SELL, sellbut[0]);
cost = OBJS_GetResale(pos);
if (OBJS_IsOnly(pos))
num = OBJS_GetAmt(pos);
else
num = OBJS_GetTotal(pos);
sprintf(youhave, "%02d", num);
sprintf(coststr, "%02d", cost);
}
SWD_SetFieldText(window, STOR_STATS, yh_hold);
SWD_SetFieldText(window, STOR_TEXTCOST, saying[mode]);
SWD_SetFieldText(window, STOR_NUM, youhave);
SWD_SetFieldText(window, STOR_COST, coststr);
sprintf(youhave, "%07d", plr.score);
SWD_SetFieldText(window, STOR_SCORE, youhave);
SWD_SetFieldItem(window, STOR_BUYIT, mainbut[mode]);
if (pos < S_LAST_OBJECT)
SWD_SetFieldItem(window, STOR_COMP, items[pos]);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
}
SWD_Dialog(&dlg);
I_GetNeedResize(false);
if (KBD_Key(SC_X) && KBD_Key(SC_ALT))
WIN_AskExit();
if (dlg.viewactive)
{
switch (dlg.sfield)
{
case STOR_VEXIT:
opt = dlg.sfield;
if ((mouseb1) || (AButton && !joy_ipt_MenuNew))
goto store_exit;
if (opt != oldopt)
{
SWD_SetFieldText(window, STOR_TEXT, storetext[0]);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
oldopt = opt;
}
break;
case STOR_VBUY:
opt = dlg.sfield;
if (opt != oldopt)
{
SWD_SetFieldText(window, STOR_TEXT, storetext[2]);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
oldopt = opt;
}
break;
case STOR_VSELL:
opt = dlg.sfield;
if (opt != oldopt)
{
SWD_SetFieldText(window, STOR_TEXT, storetext[1]);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
oldopt = opt;
}
break;
case STOR_VNEXT:
opt = dlg.sfield;
if (opt != oldopt)
{
SWD_SetFieldText(window, STOR_TEXT, storetext[3]);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
oldopt = opt;
}
break;
case STOR_VPREV:
opt = dlg.sfield;
if (opt != oldopt)
{
SWD_SetFieldText(window, STOR_TEXT, storetext[4]);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
oldopt = opt;
}
break;
case STOR_VACCEPT:
opt = dlg.sfield;
if (opt != oldopt)
{
if (mode == BUY_MODE)
SWD_SetFieldText(window, STOR_TEXT, storetext[5]);
else
SWD_SetFieldText(window, STOR_TEXT, storetext[6]);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
oldopt = opt;
}
break;
case STOR_VSCREEN:
opt = dlg.sfield;
if (opt != oldopt)
{
SWD_SetFieldText(window, STOR_TEXT, storetext[7]);
SWD_ShowAllWindows();
GFX_DisplayUpdate();
oldopt = opt;
}
break;
}
}
else
{
opt = -1;
if (opt != oldopt)
{
SWD_SetFieldText(window, STOR_TEXT, " ");
SWD_ShowAllWindows();
GFX_DisplayUpdate();
oldopt = opt;
}
}
if (joy_ipt_MenuNew)
{
if (StickY > 0)
{
JOY_IsKey(StickY);
dlg.keypress = SC_DOWN;
}
if (StickY < 0)
{
JOY_IsKey(StickY);
dlg.keypress = SC_UP;
}
if (StickX > 0)
{
JOY_IsKey(StickX);
dlg.keypress = SC_RIGHT;
}
if (StickX < 0)
{
JOY_IsKey(StickX);
dlg.keypress = SC_LEFT;
}
if (Down)
{
JOY_IsKey(Down);
dlg.keypress = SC_DOWN;
}
if (Up)
{
JOY_IsKey(Up);
dlg.keypress = SC_UP;
}
if (Left)
{
JOY_IsKey(Left);
dlg.keypress = SC_LEFT;
}
if (Right)
{
JOY_IsKey(Right);
dlg.keypress = SC_RIGHT;
}
if (AButton)
{
JOY_IsKey(AButton);
dlg.keypress = SC_ENTER;
}
if (Back)
{
JOY_IsKey(Back);
dlg.keypress = SC_ESC;
}
if (BButton)
{
JOY_IsKey(BButton);
dlg.keypress = SC_ESC;
}
if (LeftShoulder)
{
JOY_IsKey(LeftShoulder);
dlg.keypress = SC_SPACE;
}
if (RightShoulder)
{
JOY_IsKey(RightShoulder);
dlg.keypress = SC_F1;
}
}
switch (dlg.keypress)
{
case SC_ESC:
goto store_exit;
case SC_F1:
HELP_Win("STORHLP1_TXT");
break;
case SC_SPACE:
KBD_Wait(dlg.keypress);
mode ^= SELL_MODE;
if (mode == BUY_MODE)
{
dlg.cur_act = S_FLD_COMMAND;
dlg.cur_cmd = F_SELECT;
dlg.field = STOR_BUY;
}
else
{
dlg.cur_act = S_FLD_COMMAND;
dlg.cur_cmd = F_SELECT;
dlg.field = STOR_SELL;
}
break;
case SC_ENTER:
KBD_Wait(dlg.keypress);
dlg.cur_act = S_FLD_COMMAND;
dlg.cur_cmd = F_SELECT;
dlg.field = STOR_BUYIT;
break;
case SC_UP:
case SC_PAGEUP:
case SC_RIGHT:
KBD_Wait(dlg.keypress);
dlg.cur_act = S_FLD_COMMAND;
dlg.cur_cmd = F_SELECT;
dlg.field = STOR_NEXT;
break;
case SC_LEFT:
case SC_DOWN:
case SC_PAGEDN:
KBD_Wait(dlg.keypress);
dlg.cur_act = S_FLD_COMMAND;
dlg.cur_cmd = F_SELECT;
dlg.field = STOR_PREV;
break;
}
if (dlg.cur_act == S_FLD_COMMAND && dlg.cur_cmd == F_SELECT)
{
update = 1;
switch (dlg.field)
{
case STOR_NEXT:
SND_Patch(FX_SWEP, 127);
if (max_items)
cur_item++;
break;
case STOR_PREV:
SND_Patch(FX_SWEP, 127);
if (max_items)
cur_item--;
break;
case STOR_BUY:
SND_Patch(FX_SWEP, 127);
mode = BUY_MODE;
max_items = MakeBuyItems();
cur_item = 0;
break;
case STOR_SELL:
SND_Patch(FX_SWEP, 127);
mode = SELL_MODE;
max_items = MakeSellItems();
cur_item = 0;
break;
case STOR_BUYIT:
if (mode == BUY_MODE)
{
pos = b_items[cur_item];
switch (OBJS_Buy(pos))
{
case OBJ_GOTIT:
SND_Patch(FX_SWEP, 127);
break;
case OBJ_NOMONEY:
SND_Patch(FX_WARNING, 127);
Harrold(FILE04f_HAR4_TXT);
break;
case OBJ_SHIPFULL:
SND_Patch(FX_WARNING, 127);
Harrold(FILE051_HAR7_TXT);
break;
case OBJ_ERROR:
SND_Patch(FX_WARNING, 127);
break;
}
MakeBuyItems();
for (loop = 0; loop < buy_count; loop++)
{
if (b_items[loop] == pos)
cur_item = loop;
break;
}
}
else
{
pos = s_items[cur_item];
OBJS_Sell(pos);
MakeSellItems();
SND_Patch(FX_SWEP, 127);
for (loop = 0; loop < sell_count; loop++)
{
if (s_items[loop] == pos)
cur_item = loop;
break;
}
}
break;
}
}
}
store_exit:
SND_Patch(FX_DOOR, 127);
while (IMS_IsAck())
{
}
g_button_flag = 1;
GFX_FadeOut(0, 0, 0, 16);
PTR_DrawCursor(0);
SWD_DestroyWindow(window);
memset(displaybuffer, 0, 64000);
GFX_DisplayUpdate();
GFX_SetPalette(palette, 0);
}
+5
View File
@@ -0,0 +1,5 @@
#pragma once
extern int id_pics[4];
void STORE_Enter(void);
File diff suppressed because it is too large. Load diff
+237
View File
@@ -0,0 +1,237 @@
#pragma once
#include "gfxapi.h"
typedef enum
{
C_IDLE,
F_DOWN,
F_UP,
F_NEXT,
F_PREV,
F_RIGHT,
F_LEFT,
F_TOP,
F_BOTTOM,
F_FIRST,
F_SELECT,
F_OBJ_AREA,
F_VIEW_AREA,
W_NEW,
W_NEXT,
W_MOVE,
W_CLOSE,
W_CLOSE_ALL
}CMD;
typedef enum
{
S_IDLE,
S_FLD_COMMAND,
S_WIN_COMMAND,
S_FIRSTCALL,
S_REDRAW,
S_UPDATE,
S_END
}ACT;
typedef enum
{
R_IDLE,
R_CLOSED,
R_CLOSE_ALL,
R_END_DIALOG
}FCMD;
typedef enum
{
FILL,
TEXTURE,
PICTURE,
SEE_THRU,
INVISABLE
}DSTYLE;
typedef enum
{
NORMAL,
UP,
DOWN
}BUTTON;
typedef enum
{
I_NORM,
I_TOUPPER,
I_NUMERIC
}INPUTOPT;
#define FLD_OFF 0 // 0
#define FLD_TEXT 1 // 1
#define FLD_BUTTON 2 // 2 *
#define FLD_INPUT 3 // 3 *
#define FLD_MARK 4 // 5 *
#define FLD_CLOSE 5 // 6
#define FLD_DRAGBAR 6 // 7 *
#define FLD_BUMPIN 7 // 8
#define FLD_BUMPOUT 8 // 9
#define FLD_ICON 9 // 4
#define FLD_OBJAREA 10 // 10
#define FLD_VIEWAREA 11 // 11
#define SWD_FILENUM 1
// basic format of a window data object
//
// SWIN structure
// SFIELDS..
// TEXT AREA for window
//
#define MAX_WINDOWS 12
#define MAX_FONTS 2
typedef struct
{
int version; // VERSION NUMBER ( not used )
int swdsize; // SIZE OF WIN/FIELD AND TEXT ( not used )
int arrowflag; // Use Arrow Keys ( TRUE/FALSE )
int display; // DISPLAY FLAG
int opt3; // OPTION 3 ( not used )
int opt4; // OPTION 4 ( not used )
int id; // WINDOW ID NUMBER
int type; // WINDOW TYPE NUMBER
char name[16]; // TEXT NAME OF WINDOW ( NOT DISPLAYED )
char item_name[16]; // TEXT NAME OF ITEM
int item; // ITEM ID NUMBER
int picflag; // FILL/TEXTURE/PICTURE
int lock; // TRUE = cannot goto other windows
int fldofs; // OFFSET IN BYTES TO FIRST FIELD
int txtofs; // OFFSET IN BYTES TO TEXT AREA ( not used )
int firstfld; // FIELD TO GOTO FIRST
int opt; // WINDOW TYPE
int color; // COLOR OF WINDOW
int numflds; // NUMBER OF FIELDS
int x; // X POSITON ON SCREEN
int y; // Y POSITION ON SCREEN
int lx; // WIDTH IN PIXELS
int ly; // HEIGHT IN PIXELS
int shadow; // SHADOW TRUE/FALSE
}SWIN;
typedef struct
{
int opt; // FIELD TYPE
int id; // FIELD ID
int hotkey; // SCAN CODE OF HOT KEY
int kbflag; // TRUE if field should be KBACTIVE
int opt3; // not used
int opt4; // not used
int input_opt; // OPTIONS used in INPUT FIELDS
int bstatus; // BUTTON STATUS NORMAL/UP/DOWN
char name[16]; // TEXT NAME OF FIELD ( NOT DISPLAYED )
char item_name[16]; // TEXT NAME OF ITEM #
int item; // ITEM ID NUMBER
char font_name[16]; // FONT .GLB NAME
int fontid; // FONT NUMBER
int fontbasecolor; // FONT BASE COLOR
int maxchars; // MAXCHARS IN FIELD TEXT
int picflag; // PICTURE TRUE/FALSE
int color; // COLOR OF FIELD
int lite; // HIGHLIGHT COLOR
int mark; // FIELD MARK ( TRUE/FLASE )
int saveflag; // MEM TO SAVE PIC UNDER FIELD ( Y/N )
int shadow; // SHADOW ON/OFF
int selectable; // SELECTABLE ON/OFF
int x; // X POSITION ON SCREEN
int y; // Y POSITION ON SCREEN
int lx; // WIDTH IN PIXELS
int ly; // HEIGHT IN PIXELS
int txtoff; // OFFSET TO TEXT DATA ( BYTES )
char *sptr; // SEG POINTER TO SAVE INFO
}SFIELD;
typedef struct
{
int opt; // FIELD TYPE
int id; // FIELD ID
int hotkey; // SCAN CODE OF HOT KEY
int kbflag; // TRUE if field should be KBACTIVE
int opt3; // not used
int opt4; // not used
int input_opt; // OPTIONS used in INPUT FIELDS
int bstatus; // BUTTON STATUS NORMAL/UP/DOWN
char name[16]; // TEXT NAME OF FIELD ( NOT DISPLAYED )
char item_name[16]; // TEXT NAME OF ITEM #
int item; // ITEM ID NUMBER
char font_name[16]; // FONT .GLB NAME
int fontid; // FONT NUMBER
int fontbasecolor; // FONT BASE COLOR
int maxchars; // MAXCHARS IN FIELD TEXT
int picflag; // PICTURE TRUE/FALSE
int color; // COLOR OF FIELD
int lite; // HIGHLIGHT COLOR
int mark; // FIELD MARK ( TRUE/FLASE )
int saveflag; // MEM TO SAVE PIC UNDER FIELD ( Y/N )
int shadow; // SHADOW ON/OFF
int selectable; // SELECTABLE ON/OFF
int x; // X POSITION ON SCREEN
int y; // Y POSITION ON SCREEN
int lx; // WIDTH IN PIXELS
int ly; // HEIGHT IN PIXELS
int txtoff; // OFFSET TO TEXT DATA ( BYTES )
int PlaceHolder; // PLACEHOLDER TO KEEP SIZE
}SFIELD32;
typedef struct
{
int window;
int field;
int cur_act;
int cur_cmd;
int keypress;
int id;
int type;
int x;
int y;
int height;
int width;
int objactive;
int viewactive;
int sfield;
int sx;
int sy;
}SWD_DLG;
typedef struct
{
int gitem; // GLB ITEM ID
int flag; // TRUE = in use ,FALSE = not in use
int viewflag; // TRUE = has viewarea(s) FALSE = none
SWIN *win; // POINTER TO WINDOW
}SWD_WIN;
extern int usekb_flag;
extern int g_button_flag;
extern unsigned int fi_joy_count;
extern bool fi_sec_field;
void SWD_Install(int moveflag);
void SWD_End(void);
void SWD_Dialog(SWD_DLG *swd_dlg);
SWIN* SWD_ReformatFieldData(SWIN *header, int handle);
int SWD_InitMasterWindow(int handle);
int SWD_ShowAllWindows(void);
void SWD_SetWindowPtr(int handle);
void SWD_SetFieldSelect(int handle, int field_id, int opt);
void SWD_SetFieldItem(int handle, int field_id, int item);
int SWD_SetFieldText(int handle, int field_id, const char *in_text);
void SWD_DestroyWindow(int handle);
int SWD_InitWindow(int handle);
void SWD_SetActiveField(int handle, int field_id);
int SWD_GetFieldXYL(int handle, int field_id, int* x, int* y, int* lx, int* ly);
void SWD_SetWinDrawFunc(int handle, void (*infunc)(SWD_DLG*));
void SWD_SetFieldPtr(int handle, int field);
int SWD_GetFieldText(int handle, int field_id, char *out_text);
int SWD_GetFieldItem(int handle, int field_id);
void SWD_SetClearFlag(int inflag);
+573
View File
@@ -0,0 +1,573 @@
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "tile.h"
#include "gfxapi.h"
#include "rap.h"
#include "glbapi.h"
#include "loadsave.h"
#include "fx.h"
#include "anims.h"
#include "entypes.h"
#define MAX_STILES ( MAP_ONSCREEN * MAP_COLS )
#define MAX_TILEDELAY ( ( MAP_ONSCREEN + 1 ) * MAP_COLS )
int eitems[MAP_SIZE];
int titems[MAP_SIZE];
short hits[MAP_SIZE];
short tdead[MAP_SIZE];
short money[MAP_SIZE];
TILEDELAY tdel[MAX_TILEDELAY];
TILEDELAY first_delay;
TILEDELAY last_delay;
TILEDELAY *free_delay;
int tileloopy;
char *tilepic;
char game_start[4][17] = {
"STARTG1TILES",
"STARTG2TILES",
"STARTG3TILES",
"STARTG4TILES"
};
int scroll_flag;
int last_tile;
char *tilestart;
int startflat[4];
int tilepos;
int tileyoff;
TILESPOT tspots[MAX_STILES];
TILESPOT *lastspot;
int spark_delay;
int flare_delay;
/*-------------------------------------------------------------------------*
TClear () - Clears TILE Delay Link List
*-------------------------------------------------------------------------*/
void
TClear(
void
)
{
int loop;
first_delay.prev = NULL;
first_delay.next = &last_delay;
last_delay.prev = &first_delay;
last_delay.next = NULL;
free_delay = &tdel[0];
memset(tdel, 0, sizeof(tdel));
for (loop = 0; loop < MAX_TILEDELAY - 1; loop++)
{
tdel[loop].next = &tdel[loop + 1];
}
}
/*-------------------------------------------------------------------------*
TGet () - Get a TDELAY object
*-------------------------------------------------------------------------*/
TILEDELAY
*TGet(
void
)
{
TILEDELAY *newtd;
if (!free_delay)
EXIT_Error("TILEDELAY_Get() - Max ");
newtd = free_delay;
free_delay = free_delay->next;
memset(newtd, 0, sizeof(TILEDELAY));
newtd->next = &last_delay;
newtd->prev = last_delay.prev;
last_delay.prev = newtd;
newtd->prev->next = newtd;
return newtd;
}
/*-------------------------------------------------------------------------*
TRemove () - Remove a TDELAY Object from link list
*-------------------------------------------------------------------------*/
TILEDELAY
*TRemove(
TILEDELAY *sh
)
{
TILEDELAY *next;
next = sh->prev;
sh->next->prev = sh->prev;
sh->prev->next = sh->next;
memset(sh, 0, sizeof(TILEDELAY));
sh->next = free_delay;
free_delay = sh;
return next;
}
/*--------------------------------------------------------------------------
TILE_DoDamage
--------------------------------------------------------------------------*/
void
TILE_DoDamage(
int mapspot,
int damage
)
{
static int mlookup[3] = {
-1, -MAP_COLS, 1
};
static int xlookup[3] = {
-1, 0, 1
};
int loop, ix, spot, x;
ix = mapspot % MAP_COLS;
for (loop = 0; loop < 3; loop++)
{
spot = mapspot + mlookup[loop];
if (spot < 0 || spot >= MAP_SIZE)
continue;
if (eitems[spot] != titems[spot])
{
x = ix + xlookup[loop];
if (x < 0 || x >= MAP_COLS)
continue;
hits[spot] -= damage;
}
}
}
/***************************************************************************
TILE_Put () - Draws 32 by 32 TILE Clips on y only
***************************************************************************/
void
TILE_Put(
char *inpic, // INPUT : pointer to GFX_PIC ( norm )
int x, // INPUT : x position
int y // INPUT : y position
)
{
int flag;
flag = 0;
if (y + 32 <= 0 || y >= SCREENHEIGHT)
return;
tileloopy = 32;
tilepic = inpic;
if (y < 0)
{
tilepic += y * -32;
tileloopy += y;
y = 0;
flag = 1;
}
if (y + tileloopy > SCREENHEIGHT)
{
tileloopy = SCREENHEIGHT - y;
flag = 1;
}
tilestart = displaybuffer + ylookup[y] + x;
if (flag)
TILE_ClipDraw();
else
TILE_Draw();
}
/***************************************************************************
TILE_Init () - Sets Up A level for Displaying
***************************************************************************/
void
TILE_Init(
void
)
{
TClear();
g_mapleft = MAP_LEFT;
scroll_flag = 1;
last_tile = 0;
// FIND START OF GAME TILES ========
startflat[0] = GLB_GetItemID(game_start[0]);
startflat[0]++;
startflat[1] = GLB_GetItemID(game_start[1]);
startflat[1]++;
startflat[2] = GLB_GetItemID(game_start[2]);
startflat[2]++;
startflat[3] = GLB_GetItemID(game_start[3]);
startflat[3]++;
}
/***************************************************************************
TILE_CacheLevel () - Cache tiles in current level
***************************************************************************/
void
TILE_CacheLevel(
void
)
{
int loop, game, item;
FLATS *lib;
TClear();
g_mapleft = MAP_LEFT;
// SET UP START POS ON MAP =========
tilepos = (MAP_ROWS - MAP_ONSCREEN) * MAP_COLS;
tileyoff = 200 - (MAP_ONSCREEN * MAP_BLOCKSIZE);
lastspot = &tspots[MAX_STILES - 1];
scroll_flag = 1;
last_tile = 0;
memset(titems, 0, sizeof(titems));
memset(eitems, 0, sizeof(eitems));
memset(hits, 0, sizeof(hits));
memset(tdead, 0, sizeof(tdead));
// == CACHE TILES =========================
for (loop = 0; loop < MAP_SIZE; loop++)
{
game = LE_SHORT(mapmem->map[loop].fgame);
lib = flatlib[game];
money[loop] = LE_SHORT(lib[LE_SHORT(mapmem->map[loop].flats)].bounty);
item = startflat[game];
item += LE_SHORT(mapmem->map[loop].flats);
titems[loop] = item;
GLB_CacheItem(item);
item = startflat[game];
item += LE_LONG(lib[LE_SHORT(mapmem->map[loop].flats)].linkflat);
eitems[loop] = item;
if (eitems[loop] != titems[loop])
GLB_CacheItem(item);
if (eitems[loop] != titems[loop])
hits[loop] = LE_SHORT(lib[LE_SHORT(mapmem->map[loop].flats)].bonus);
else
hits[loop] = 1;
}
}
/***************************************************************************
TILE_FreeLevel () - Free tile level
***************************************************************************/
void
TILE_FreeLevel(
void
)
{
int loop;
for (loop = 0; loop < MAP_SIZE; loop++)
{
GLB_FreeItem(titems[loop]);
if (eitems[loop] != titems[loop])
GLB_FreeItem(eitems[loop]);
}
}
/***************************************************************************
TILE_DamageAll () - Damages All tiles on screen
***************************************************************************/
void
TILE_DamageAll(
void
)
{
TILESPOT *ts;
ts = tspots;
do
{
if (eitems[ts->mapspot] != titems[ts->mapspot])
hits[ts->mapspot] -= 20;
if (ts == lastspot)
break;
ts++;
} while (1);
}
/***************************************************************************
TILE_Think () - Does Position Calculations for tiles
***************************************************************************/
void
TILE_Think(
void
)
{
int ty, tx, y, x, mapspot, loopy, loopx;
TILESPOT *ts;
TILEDELAY *td;
y = tileyoff;
mapspot = tilepos;
ts = tspots;
for (loopy = 0; loopy < MAP_ONSCREEN; loopy++, y += 32)
{
x = MAP_LEFT;
for (loopx = 0; loopx < MAP_COLS; loopx++, x += 32, mapspot++, ts++)
{
ts->mapspot = mapspot;
ts->x = x;
ts->y = y;
ts->item = titems[mapspot];
if (hits[mapspot] < 0 && !tdead[mapspot])
{
SND_3DPatch(FX_GEXPLO, x + 16, y + 16);
TILE_DoDamage(ts->mapspot, 5);
plr.score += money[mapspot];
TILE_Explode(ts, 10);
ANIMS_StartAnim(A_LARGE_GROUND_EXPLO1, x + 16, y + 16);
tdead[mapspot] = 1;
}
}
}
for (td = first_delay.next; &last_delay != td; td = td->next)
{
if (td->mapspot - tilepos > (MAP_ONSCREEN * MAP_COLS))
{
td = TRemove(td);
continue;
}
if (td->frames < 0)
{
tx = td->ts->x + 8 + (wrand() % 8);
ty = td->ts->y + 26;
TILE_DoDamage(td->mapspot, 20);
spark_delay++;
flare_delay++;
if (spark_delay > 2)
{
ANIMS_StartAnim(A_GROUND_SPARKLE, tx, ty);
spark_delay = 0;
}
if (flare_delay > 4)
{
ANIMS_StartAnim(A_GROUND_FLARE, tx, ty);
flare_delay = 0;
}
ts = &tspots[td->mapspot - tilepos];
titems[ts->mapspot] = td->item;
eitems[ts->mapspot] = td->item;
td = TRemove(td);
}
else
td->frames--;
}
}
/***************************************************************************
TILE_Display () - Displays Tiles
***************************************************************************/
void
TILE_Display(
void
)
{
char *pic;
TILESPOT *ts;
ts = tspots;
do
{
pic = GLB_GetItem(ts->item);
pic += 20;
TILE_Put(pic, ts->x, ts->y);
if (ts == lastspot)
break;
ts++;
} while (1);
tileyoff++;
if (tileyoff > 0)
{
if (last_tile && tileyoff >= 0)
{
tileyoff = 0;
scroll_flag = 0;
}
else
{
tileyoff -= MAP_BLOCKSIZE;
tilepos -= MAP_COLS;
}
if (tilepos <= 0)
{
tilepos = 0;
last_tile = 1;
}
}
}
/***************************************************************************
TILE_IsHit () - Checks to see if a shot hits an explodable tile
***************************************************************************/
int // RETURNS : TRUE = Tile Hit
TILE_IsHit(
int damage, // INPUT : damage to tile
int x, // INOUT : x screen pos, out tile x
int y // INOUT : y screen pos, out tile y
)
{
TILESPOT *ts = tspots;
while (ts != lastspot)
{
if (x >= ts->x && ts->x + 32 > x && y >= ts->y && ts->y + 32 > y)
{
if (eitems[ts->mapspot] != titems[ts->mapspot])
{
hits[ts->mapspot] -= damage;
switch (wrand() % 2)
{
case 0:
ANIMS_StartGAnim(A_BLUE_SPARK, x, y);
break;
case 1:
ANIMS_StartGAnim(A_ORANGE_SPARK, x, y);
break;
}
return 1;
}
}
ts++;
}
return 0;
}
/***************************************************************************
TILE_Bomb () - Checks to see if a BOMB hits an explodable tile
***************************************************************************/
int // RETURNS : TRUE = Tile Hit
TILE_Bomb(
int damage, // INPUT : damage to tile
int x, // INOUT : x screen pos, out tile x
int y // INOUT : y screen pos, out tile y
)
{
TILESPOT *ts = tspots;
while (ts != lastspot)
{
if (x >= ts->x && ts->x + 32 > x && y >= ts->y && ts->y + 32 > y)
{
if (eitems[ts->mapspot] != titems[ts->mapspot])
{
hits[ts->mapspot] -= damage;
TILE_DoDamage(ts->mapspot, damage);
if (ts->mapspot > MAP_COLS)
TILE_DoDamage(ts->mapspot - MAP_COLS, damage >> 1);
return 1;
}
}
ts++;
}
return 0;
}
/***************************************************************************
TILE_Explode () - Sets the Tile to show explosion tile
***************************************************************************/
void
TILE_Explode(
TILESPOT *ts, // INPUT : tilespot of explosion
int delay // INPUT : frames to delay
)
{
TILEDELAY *td;
if (ts->mapspot != -1 && ts->mapspot >= tilepos)
{
if (delay)
{
td = TGet();
if (td)
{
td->ts = ts;
td->mapspot = ts->mapspot;
td->frames = delay;
td->item = eitems[ts->mapspot];
}
eitems[ts->mapspot] = titems[ts->mapspot];
}
else
{
ts->item = eitems[ts->mapspot];
titems[ts->mapspot] = eitems[ts->mapspot];
}
}
}
+42
View File
@@ -0,0 +1,42 @@
#pragma once
extern char *tilepic;
extern char *tilestart;
extern int tileloopy;
extern int tileyoff;
extern int tilepos;
extern int scroll_flag;
typedef struct
{
int item;
int x;
int y;
int mapspot;
}TILESPOT;
typedef struct TDELAY_S
{
struct TDELAY_S *prev;
struct TDELAY_S *next;
int frames;
int mapspot;
int item;
TILESPOT *ts;
}TILEDELAY;
void TILE_Init(void);
void TILE_Think(void);
void TILE_Display(void);
int TILE_IsHit(int damage, int x, int y);
int TILE_Bomb(int damage, int x, int y);
void TILE_Explode(TILESPOT *ts, int delay);
void TILE_DamageAll(void);
void TILE_CacheLevel(void);
void TILE_FreeLevel(void);
void TILE_Draw(void);
void TILE_ClipDraw(void);
void TILE_ShakeScreen(void);
void TILE_DisplayScreen(void);
+85
View File
@@ -0,0 +1,85 @@
#include <string.h>
#include "common.h"
#include "tile.h"
#include "rap.h"
#include "gfxapi.h"
#include "i_video.h"
#define TILEWIDTH 32
#define TILEHEIGHT 32
/***************************************************************************
TILE_Draw() - 32 by 32 Tile draw
***************************************************************************/
void
TILE_Draw(
void
)
{
int loop;
for (loop = 0; loop < TILEHEIGHT; loop++)
{
memcpy(&tilestart[loop * SCREENWIDTH], &tilepic[loop * TILEWIDTH], TILEWIDTH);
}
}
/***************************************************************************
TILE_ClipDraw() -
***************************************************************************/
void
TILE_ClipDraw(
void
)
{
int loop;
for (loop = 0; loop < tileloopy; loop++)
{
memcpy(&tilestart[loop * SCREENWIDTH], &tilepic[loop * TILEWIDTH], TILEWIDTH);
}
}
/***************************************************************************
TILE_ShakeScreen() -
***************************************************************************/
void
TILE_ShakeScreen(
void
)
{
int loop;
char *src = displaybuffer + 12;
char *dst = displayscreen + g_mapleft - 4;
for (loop = 0; loop < SCREENHEIGHT; loop++)
{
memcpy(dst, src, 296);
dst += SCREENWIDTH;
src += SCREENWIDTH;
}
I_FinishUpdate();
}
/***************************************************************************
TILE_DisplayScreen() -
***************************************************************************/
void
TILE_DisplayScreen(
void
)
{
int loop;
char *src = displaybuffer + MAP_LEFT;
char *dst = displayscreen + MAP_LEFT;
for (loop = 0; loop < SCREENHEIGHT; loop++)
{
memcpy(dst, src, 288);
dst += SCREENWIDTH;
src += SCREENWIDTH;
}
I_FinishUpdate();
}
+444
View File
@@ -0,0 +1,444 @@
#include <stdio.h>
#include <stdint.h>
#include "common.h"
#include "vmemapi.h"
#define MAX_BLOCKS 63
typedef struct
{
uint32_t size;
VM_OWNER* owner;
}MCBL;
typedef struct
{
uint8_t* blk[MAX_BLOCKS];
MCBL* last_mcb[MAX_BLOCKS];
uint32_t blocks;
MCBL* rover;
uint32_t discarded;
uint32_t age;
}POOL;
#define BLK_FREE 0x80000000L
#define BLK_SIZE 0x00FFFFFFL
#define BLK_ID 0x7F000000L
static POOL pool;
/*************************************************************************
VM_InitMemory - Assign memory block to be used as virtual memory.
- Can be called multiple times to add additional memory.
*************************************************************************/
void
VM_InitMemory(
char* memory, // INPUT : Memory to be added to the pool
int size // INPUT : Size of memory
)
{
MCBL* mcb;
ASSERT(pool.blocks < MAX_BLOCKS);
ASSERT(size > 1024);
pool.blk[pool.blocks] = (uint8_t*)memory;
/*
* Create 1st Memory Block, the size of the block does include
* the MCB header.
*/
mcb = (MCBL*)memory;
mcb->size = size - sizeof(MCBL);
mcb->size |= BLK_FREE;
mcb->size |= pool.blocks << 24;
mcb->owner = NULL;
if (pool.rover == NULL)
pool.rover = mcb;
/*
* Create Last Memory Block
*/
mcb = (MCBL*)((uint8_t*)mcb + (mcb->size & BLK_SIZE));
mcb->size = 0;
mcb->owner = NULL;
pool.last_mcb[pool.blocks] = mcb;
/*
* Chain previous last MCB to this block
*/
if (pool.blocks > 0)
{
mcb = pool.last_mcb[pool.blocks - 1];
mcb->size = pool.blocks << 24;
}
pool.blocks++;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vm_ColaceMem - Colace small fragments of memory into larger blocks.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
uint32_t
vm_ColaceMem(
MCBL* mcb
)
{
MCBL* next_mcb;
uint32_t mcb_size;
mcb_size = (uint32_t)(mcb->size & BLK_SIZE);
/*
* Merge all free contiguous blocks.
*/
next_mcb = (MCBL*)((uint8_t*)mcb + mcb_size);
while (next_mcb->size & BLK_FREE)
{
mcb_size += (uint32_t)(next_mcb->size & BLK_SIZE);
next_mcb = (MCBL*)((uint8_t*)mcb + mcb_size);
}
mcb->size = (uint32_t)(BLK_FREE | (mcb->size & ~BLK_SIZE) | mcb_size);
return mcb_size;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vm_DiscardMem - Disacard infrequently used memory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
MCBL*
vm_DiscardMem(
uint32_t size
)
{
MCBL* mcb;
MCBL* free_mcb;
VM_OWNER* owner;
uint32_t mcb_size;
bool mem_freed;
uint32_t lowcnt;
uint32_t lowsize;
uint32_t oldage;
MCBL* low_mcb;
do
{
oldage = lowsize = lowcnt = (uint32_t)~0;
low_mcb = NULL;
mcb = (MCBL*)(pool.blk[0]);
mem_freed = 0;
pool.age--;
for (;; )
{
mcb_size = mcb->size & BLK_SIZE;
if (mcb_size == 0)
{
/*
* At end of block, use the block # encoded in the size to
* advance (or wrap) to the next block of memory.
*/
mcb_size = mcb->size >> 24;
mcb = (MCBL*)(pool.blk[mcb_size]);
if (mcb_size == 0)
{
if (low_mcb != NULL)
{
pool.discarded++;
low_mcb->owner->obj = NULL;
vm_ColaceMem(low_mcb);
return low_mcb;
}
break;
}
continue;
}
if (!(mcb->size & BLK_FREE))
{
if ((owner = mcb->owner) != NULL)
{
/*
* Keep track of the least recently used memory block that is
* large enough to use as we are searching for a free block.
*/
if (owner->age)
owner->age--;
if (mcb_size >= size &&
(owner->age < lowcnt ||
(owner->age == lowcnt && lowsize > mcb_size)
)
)
{
lowsize = mcb_size;
lowcnt = owner->age;
low_mcb = mcb;
}
else if (owner->age < oldage)
{
oldage = owner->age;
}
}
}
mcb = (MCBL*)((uint8_t*)mcb + mcb_size);
}
/*
* Now go through and colace the heap
*/
pool.rover = mcb = (MCBL*)(pool.blk[0]);
free_mcb = NULL;
oldage += 2;
for (;; )
{
mcb_size = (mcb->size & BLK_SIZE);
if (mcb->size & BLK_FREE)
{
free_mcb = mcb;
mcb_size = vm_ColaceMem(mcb);
if (mcb_size >= size)
return mcb;
mcb = (MCBL*)((uint8_t*)mcb + mcb_size);
continue;
}
else if (mcb_size)
{
if (mcb->owner != NULL && mcb->owner->age <= oldage)
{
pool.discarded++;
mcb->size |= BLK_FREE;
mcb->owner->obj = NULL;
mcb->owner = NULL;
mem_freed = 1;
if (free_mcb)
{
mcb = free_mcb;
continue;
}
free_mcb = mcb;
}
else
{
free_mcb = NULL;
}
mcb = (MCBL*)((uint8_t*)mcb + (mcb_size & BLK_SIZE));
}
else
{
/*
* At end of block, use the block # encoded in the size to
* advance (or wrap) to the next block of memory.
*/
free_mcb = NULL;
mcb_size = mcb->size >> 24;
mcb = (MCBL*)(pool.blk[mcb_size]);
if (mcb_size == 0)
{
break;
}
}
}
} while (mem_freed == 1);
return NULL;
}
/*************************************************************************
VM_Malloc - Allocates a block of memory - swapping out other blocks if
needed.
*************************************************************************/
void*
VM_Malloc(
uint32_t size, // INPUT : Size of object
VM_OWNER* owner, // INPUT : Owner Structure, NULL=Locked
bool discard // INPUT : Discard memory to satisfy request.
)
{
MCBL* mcb;
MCBL* next_mcb;
uint32_t mcb_size;
bool all_locked;
ASSERT(pool.blocks > 0);
/*
* Round block up to next DWORD in size, and add in overhead of MCB
*/
size = ((size + 3) & ~3) + sizeof(MCBL);
/*
* Search for free memory block across all pools...
*/
all_locked = 1;
mcb = pool.rover;
do
{
while (!(mcb->size & BLK_FREE))
{
mcb_size = (uint32_t)(mcb->size & BLK_SIZE);
if (all_locked == 1 && mcb->owner != NULL && discard)
all_locked = 0;
if (mcb_size > 0)
mcb = (MCBL*)((uint8_t*)mcb + mcb_size);
else
{
/*
* At end of block, use the block # encoded in the size to
* advance (or wrap) to the next block of memory.
*/
mcb = (MCBL*)(pool.blk[mcb->size >> 24]);
}
if (mcb == pool.rover)
{
if (all_locked == 1)
return NULL;
/*
* Walked all of memory with no luck, start discarding least recently
* used memory.
*/
if ((mcb = vm_DiscardMem(size)) == NULL)
return NULL;
mcb_size = mcb->size & BLK_SIZE;
goto FOUND_MCB;
}
}
mcb_size = vm_ColaceMem(mcb);
if (mcb_size < size)
{
/*
* Block is not big enough to satisfy request, goto next block
*/
mcb = (MCBL*)((uint8_t*)mcb + mcb_size);
}
} while (mcb_size < size && mcb != pool.rover);
if (mcb_size < size)
return NULL;
FOUND_MCB:
if (mcb_size - size < (sizeof(MCBL) + 4))
{
size = mcb_size;
next_mcb = (MCBL*)((uint8_t*)mcb + size);
}
else
{
next_mcb = (MCBL*)((uint8_t*)mcb + size);
next_mcb->size = (uint32_t)(BLK_FREE | (mcb->size & BLK_ID) | (mcb_size - size));
next_mcb->owner = NULL;
}
pool.rover = next_mcb;
mcb->size = (uint32_t)((mcb->size & BLK_ID) | size);
mcb->owner = owner;
if (owner != NULL)
{
owner->obj = (char*)mcb + sizeof(MCBL);
owner->age = ++pool.age;
}
return (void*)((uint8_t*)mcb + sizeof(MCBL));
}
/*************************************************************************
VM_Touch - touch a peice of memory to keep track of most recently used.
*************************************************************************/
void
VM_Touch(
VM_OWNER* owner // INPUT : Owner of memory to touch.
)
{
if (owner)
{
owner->age = ++pool.age;
}
}
/*************************************************************************
VM_Free - frees a block of memory allocated by VM_Malloc
*************************************************************************/
void
VM_Free(
char* mem // INPUT : Memory Object to Free
)
{
MCBL* mcb;
if (mem != NULL)
{
mcb = (MCBL*)((uint8_t*)mem - sizeof(MCBL));
if (!(mcb->size & BLK_FREE))
{
if (mcb->owner != NULL)
mcb->owner->obj = NULL;
mcb->owner = NULL;
vm_ColaceMem(mcb);
pool.rover = mcb;
}
}
}
/*************************************************************************
VM_Lock - Locks a block of memory from being swapped out.
*************************************************************************/
void
VM_Lock(
char* mem // INPUT : Memory Object to Free
)
{
MCBL* mcb;
ASSERT(mem != NULL);
mcb = (MCBL*)((uint8_t*)mem - sizeof(MCBL));
if (!(mcb->size & BLK_FREE))
{
mcb->owner = NULL;
}
}
/*************************************************************************
VM_Unlock - Unlocks a block of memory allowing it to be swapped out.
*************************************************************************/
void
VM_Unlock(
char* mem, // INPUT : Memory Object to Free
VM_OWNER* owner // INPUT : Owner Structure, NULL=Locked
)
{
MCBL* mcb;
if (mem != NULL)
{
mcb = (MCBL*)((uint8_t*)mem - sizeof(MCBL));
if (!(mcb->size & BLK_FREE))
{
mcb->owner = owner;
if (owner != NULL)
{
owner->obj = (char*)mcb + sizeof(MCBL);
owner->age = pool.age;
}
}
}
}
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#define ASSERT(exp) ((void)0)
#define ASIZE(a) (sizeof(a)/sizeof((a)[0]))
typedef struct
{
char* obj;
uint32_t age;
}VM_OWNER;
void VM_InitMemory(char *memory, int size);
void *VM_Malloc(uint32_t size, VM_OWNER *owner, bool discard);
void VM_Free(char *mem);
void VM_Lock(char *mem);
void VM_Unlock(char *mem, VM_OWNER *owner);
void VM_Touch(VM_OWNER *owner);
File diff suppressed because it is too large. Load diff
Loaded 100 of 809 files, more files were not shown because too many files have changed in this diff. Show more