Commit 0e25b737 authored by Steven Fuller's avatar Steven Fuller

fmopl.c, fmopl.h: Removed unused stuff

misc.c: DisplayTextSplash: minor fixes, output should be better now

sd_oss.c: SoundThread: Now init WSE=1 (OPL2).  I overlooked this in the
original sources, now many songs/sounds are a lot better!  Also tried to fix
the panning; I think it's okay now.

wl_draw.c: DeCompileSprite: simplified
parent 37c94c71
......@@ -50,4 +50,4 @@ distclean: clean
rm -rf *~ DEADJOE
forced: distclean all
# rm -rf *.o
rm -rf *.o
......@@ -19,6 +19,7 @@ SD_StartMusic((MusicGroup *)audiosegs[STARTMUSIC + chunk]);
=>
SD_StartMusic(chunk);
* move DeModeXize so it does not have to be in every vi_ file
* clean up vi_xlib.c: fix vid mode changing, fix dga for non8bit modes and
the nonpalette setting stuff... lots of if statements
also, it should be able to compile without extensions
......@@ -77,7 +78,7 @@ PlayDemoFromFile specifically
on the border
same with the spear of destiny animation part of ending
* move all references to gfxbuf to vi_* only (gl will need this anyway,
since it would replace id_vh, (parts of) wl_draw, wl_scale)
since it would replace id_vh, (parts of) wl_draw)
by putting in code from id_vh (either by using Plot or just copying it in)
we can mostly stop the large conversion before each UpdateScreen
* the higher depths are a hack since a palette lookup has to be done
......
......@@ -6,6 +6,7 @@
**
** Version 0.37
**
** Modified for Wolf 3D by Steven Fuller
*/
#include <stdio.h>
......@@ -16,18 +17,14 @@
#include "fmopl.h"
#define INLINE inline
void logerror(const char *text, ...);
#ifndef PI
#define PI 3.14159265358979323846
#endif
#ifndef INLINE
#define INLINE inline
#endif
void logerror(const char *text, ...)
{
}
/* -------------------- for debug --------------------- */
/* #define OPL_OUTPUT_LOG */
#ifdef OPL_OUTPUT_LOG
......@@ -37,7 +34,7 @@ static int opl_dbg_maxchip,opl_dbg_chip;
#endif
/* -------------------- preliminary define section --------------------- */
/* attack/decay rate time rate */
/* attack/decay rate */
#define OPL_ARRATE 141280 /* RATE 4 = 2826.24ms @ 3.6MHz */
#define OPL_DRRATE 1956000 /* RATE 4 = 39280.64ms @ 3.6MHz */
......@@ -231,47 +228,6 @@ INLINE int Limit( int val, int max, int min ) {
return val;
}
/* status set and IRQ handling */
INLINE void OPL_STATUS_SET(FM_OPL *OPL,int flag)
{
/* set status flag */
OPL->status |= flag;
if(!(OPL->status & 0x80))
{
if(OPL->status & OPL->statusmask)
{ /* IRQ on */
OPL->status |= 0x80;
/* callback user interrupt handler (IRQ is OFF to ON) */
if(OPL->IRQHandler) (OPL->IRQHandler)(OPL->IRQParam,1);
}
}
}
/* status reset and IRQ handling */
INLINE void OPL_STATUS_RESET(FM_OPL *OPL,int flag)
{
/* reset status flag */
OPL->status &=~flag;
if((OPL->status & 0x80))
{
if (!(OPL->status & OPL->statusmask) )
{
OPL->status &= 0x7f;
/* callback user interrupt handler (IRQ is ON to OFF) */
if(OPL->IRQHandler) (OPL->IRQHandler)(OPL->IRQParam,0);
}
}
}
/* IRQ mask set */
INLINE void OPL_STATUSMASK_SET(FM_OPL *OPL,int flag)
{
OPL->statusmask = flag;
/* IRQ handling check */
OPL_STATUS_SET(OPL,0);
OPL_STATUS_RESET(OPL,0);
}
/* ----- key on ----- */
INLINE void OPL_KEYON(OPL_SLOT *SLOT)
{
......@@ -291,18 +247,17 @@ INLINE void OPL_KEYOFF(OPL_SLOT *SLOT)
/* set envelope counter from envleope output */
SLOT->evm = ENV_MOD_RR;
if( !(SLOT->evc&EG_DST) )
/*TODO*/ SLOT->evc = (ENV_CURVE[SLOT->evc>>ENV_BITS]<<ENV_BITS) + EG_DST;
//SLOT->evc = EG_DST;
SLOT->evc = (ENV_CURVE[SLOT->evc>>ENV_BITS]<<ENV_BITS) + EG_DST;
SLOT->eve = EG_DED;
SLOT->evs = SLOT->evsr;
}
}
/* ---------- calcrate Envelope Generator & Phase Generator ---------- */
/* ---------- Envelope Generator & Phase Generator ---------- */
/* return : envelope output */
INLINE UINT32 OPL_CALC_SLOT( OPL_SLOT *SLOT )
{
/* calcrate envelope generator */
/* calculate envelope generator */
if( (SLOT->evc+=SLOT->evs) >= SLOT->eve )
{
switch( SLOT->evm ){
......@@ -333,7 +288,7 @@ INLINE UINT32 OPL_CALC_SLOT( OPL_SLOT *SLOT )
break;
}
}
/* calcrate envelope */
/* calculate envelope */
return SLOT->TLL+ENV_CURVE[SLOT->evc>>ENV_BITS]+(SLOT->ams ? ams : 0);
}
......@@ -357,7 +312,7 @@ INLINE void CALC_FCSLOT(OPL_CH *CH,OPL_SLOT *SLOT)
if( SLOT->ksr != ksr )
{
SLOT->ksr = ksr;
/* attack , decay rate recalcration */
/* attack , decay rate recalculation */
SLOT->evsa = SLOT->AR[ksr];
SLOT->evsd = SLOT->DR[ksr];
SLOT->evsr = SLOT->RR[ksr];
......@@ -429,7 +384,7 @@ INLINE void set_sl_rr(FM_OPL *OPL,int slot,int v)
/* operator output calculator */
#define OP_OUT(slot,env,con) slot->wavetable[((slot->Cnt+con)/(0x1000000/SIN_ENT))&(SIN_ENT-1)][env]
/* ---------- calcrate one of channel ---------- */
/* ---------- calculate channel ---------- */
INLINE void OPL_CALC_CH( OPL_CH *CH )
{
UINT32 env_out;
......@@ -468,12 +423,12 @@ INLINE void OPL_CALC_CH( OPL_CH *CH )
/* PG */
if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE);
else SLOT->Cnt += SLOT->Incr;
/* connectoion */
/* connection */
outd[0] += OP_OUT(SLOT,env_out, feedback2);
}
}
/* ---------- calcrate rythm block ---------- */
/* ---------- calculate rythm block ---------- */
#define WHITE_NOISE_db 6.0
INLINE void OPL_CALC_RH( OPL_CH *CH )
{
......@@ -682,7 +637,7 @@ static int OPLOpenTable( void )
}
static void OPLCloseTable( void )
static void OPLCloseTable()
{
free(TL_TABLE);
free(SIN_TABLE);
......@@ -727,8 +682,8 @@ static void OPL_initalize(FM_OPL *OPL)
OPL->vibIncr = OPL->rate ? (double)VIB_ENT*(1<<VIB_SHIFT) / OPL->rate * 6.4 * ((double)OPL->clock/3600000) : 0;
}
/* ---------- write a OPL registers ---------- */
static void OPLWriteReg(FM_OPL *OPL, int r, int v)
/* ---------- write to OPL registers ---------- */
void OPLWrite(FM_OPL *OPL, int r, int v)
{
OPL_CH *CH;
int slot;
......@@ -741,18 +696,15 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v)
{
case 0x01:
/* wave selector enable */
if(OPL->type&OPL_TYPE_WAVESEL)
OPL->wavesel = v&0x20;
if(!OPL->wavesel)
{
OPL->wavesel = v&0x20;
if(!OPL->wavesel)
/* preset compatible mode */
int c;
for(c=0;c<OPL->max_ch;c++)
{
/* preset compatible mode */
int c;
for(c=0;c<OPL->max_ch;c++)
{
OPL->P_CH[c].SLOT[SLOT1].wavetable = &SIN_TABLE[0];
OPL->P_CH[c].SLOT[SLOT2].wavetable = &SIN_TABLE[0];
}
OPL->P_CH[c].SLOT[SLOT1].wavetable = &SIN_TABLE[0];
OPL->P_CH[c].SLOT[SLOT2].wavetable = &SIN_TABLE[0];
}
}
return;
......@@ -763,7 +715,6 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v)
case 0x04: /* IRQ clear / mask and Timer enable */
return;
case 0x08: /* MODE,DELTA-T : CSM,NOTESEL,x,x,smpl,da/ad,64k,rom */
if (v & 0x80) printf("CSM?\n");
OPL->mode = v;
return;
}
......@@ -935,7 +886,7 @@ static void OPL_UnLockTable(void)
OPLCloseTable();
}
/* ---------- update one of chip ----------- */
/* ---------- update chip ----------- */
void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length)
{
int i;
......@@ -994,7 +945,7 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length)
#endif
}
/* ---------- reset one of chip ---------- */
/* ---------- reset chip ---------- */
void OPLResetChip(FM_OPL *OPL)
{
int c,s;
......@@ -1002,13 +953,12 @@ void OPLResetChip(FM_OPL *OPL)
/* reset chip */
OPL->mode = 0; /* normal mode */
OPL_STATUS_RESET(OPL,0x7f);
/* reset with register write */
OPLWriteReg(OPL,0x01,0); /* wavesel disable */
OPLWriteReg(OPL,0x02,0); /* Timer1 */
OPLWriteReg(OPL,0x03,0); /* Timer2 */
OPLWriteReg(OPL,0x04,0); /* IRQ mask clear */
for(i = 0xff ; i >= 0x20 ; i-- ) OPLWriteReg(OPL,i,0);
OPLWrite(OPL,0x01,0); /* wavesel disable */
OPLWrite(OPL,0x02,0); /* Timer1 */
OPLWrite(OPL,0x03,0); /* Timer2 */
OPLWrite(OPL,0x04,0); /* IRQ mask clear */
for(i = 0xff ; i >= 0x20 ; i-- ) OPLWrite(OPL,i,0);
/* reset OPerator paramater */
for( c = 0 ; c < OPL->max_ch ; c++ )
{
......@@ -1026,8 +976,7 @@ void OPLResetChip(FM_OPL *OPL)
}
}
/* ---------- Create one of vietual YM3812 ---------- */
/* 'rate' is sampling rate and 'bufsiz' is the size of the */
/* ---------- Create a virtual YM3812 ---------- */
FM_OPL *OPLCreate(int type, int clock, int rate)
{
char *ptr;
......@@ -1092,42 +1041,3 @@ void OPLDestroy(FM_OPL *OPL)
OPL_UnLockTable();
free(OPL);
}
/* ---------- YM3812 I/O interface ---------- */
int OPLWrite(FM_OPL *OPL,int a,int v)
{
#ifdef OPL_OUTPUT_LOG
if(opl_dbg_fp)
{
for(opl_dbg_chip=0;opl_dbg_chip<opl_dbg_maxchip;opl_dbg_chip++)
if( opl_dbg_opl[opl_dbg_chip] == OPL) break;
fprintf(opl_dbg_fp,"%c%c%c",0x10+opl_dbg_chip,OPL->address,v);
}
#endif
OPLWriteReg(OPL, a, v);
return OPL->status>>7;
}
int OPLTimerOver(FM_OPL *OPL,int c)
{
if( c )
{ /* Timer B */
OPL_STATUS_SET(OPL,0x20);
}
else
{ /* Timer A */
OPL_STATUS_SET(OPL,0x40);
/* CSM mode key,TL controll */
if( OPL->mode & 0x80 )
{ /* CSM mode total level latch and auto key on */
int ch;
if(OPL->UpdateHandler) OPL->UpdateHandler(OPL->UpdateParam,0);
for(ch=0;ch<9;ch++)
CSMKeyControll( &OPL->P_CH[ch] );
}
}
/* reload timer */
return OPL->status>>7;
}
......@@ -19,17 +19,6 @@ typedef INT16 OPLSAMPLE;
typedef unsigned char OPLSAMPLE;
#endif
typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec);
typedef void (*OPL_IRQHANDLER)(int param,int irq);
typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us);
/* !!!!! here is private section , do not access there member direct !!!!! */
#define OPL_TYPE_WAVESEL 0x01 /* waveform select */
#define OPL_TYPE_ADPCM 0x02 /* DELTA-T ADPCM unit */
#define OPL_TYPE_KEYBOARD 0x04 /* keyboard interface */
#define OPL_TYPE_IO 0x08 /* I/O port */
/* ---------- OPL one of slot ---------- */
typedef struct fm_opl_slot {
INT32 TL; /* total level :TL << 8 */
......@@ -82,14 +71,8 @@ typedef struct fm_opl_f {
int clock; /* master clock (Hz) */
int rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */
double TimerBase; /* Timer base time (==sampling time) */
UINT8 address; /* address register */
UINT8 status; /* status flag */
UINT8 statusmask; /* status mask */
UINT32 mode; /* Reg.08 : CSM , notesel,etc. */
/* Timer */
int T[2]; /* timer counter */
UINT8 st[2]; /* timer enable */
/* FM channel slots */
OPL_CH *P_CH; /* pointer of CH */
int max_ch; /* maximum channel */
......@@ -109,29 +92,18 @@ typedef struct fm_opl_f {
/* wave selector enable flag */
UINT8 wavesel;
/* external event callback handler */
OPL_TIMERHANDLER TimerHandler; /* TIMER handler */
int TimerParam; /* TIMER parameter */
OPL_IRQHANDLER IRQHandler; /* IRQ handler */
int IRQParam; /* IRQ parameter */
OPL_UPDATEHANDLER UpdateHandler; /* stream update handler */
int UpdateParam; /* stream update parameter */
} FM_OPL;
/* ---------- Generic interface section ---------- */
#define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
#define OPL_TYPE_YM3812 0
FM_OPL *OPLCreate(int type, int clock, int rate);
void OPLDestroy(FM_OPL *OPL);
void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset);
void OPLSetIRQHandler(FM_OPL *OPL,OPL_IRQHANDLER IRQHandler,int param);
void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,int param);
void OPLResetChip(FM_OPL *OPL);
int OPLWrite(FM_OPL *OPL,int a,int v);
void OPLWrite(FM_OPL *OPL,int a,int v);
unsigned char OPLRead(FM_OPL *OPL,int a);
int OPLTimerOver(FM_OPL *OPL,int c);
/* YM3626/YM3812 local section */
void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length);
#endif
......@@ -179,20 +179,24 @@ static void put_dos2ansi(byte attrib)
printf ("%c[%d;25;%dm%c[%dm", 27, intens, fore, 27, back);
}
void DisplayTextSplash(byte *text)
void DisplayTextSplash(byte *text, int l)
{
int i;
int i, x;
//printf("%02X %02X %02X %02X\n", text[0], text[1], text[2], text[3]);
text += 4;
//printf("%02X %02X %02X %02X\n", text[0], text[1], text[2], text[3]);
text += 2;
for (i = 0; i < 7*160; i += 2) {
put_dos2ansi(text[i+0]);
if (text[i+1])
printf("%c", text[i+1]);
else
printf(" ");
for (x = 0; x < l; x++) {
for (i = 0; i < 160; i += 2) {
put_dos2ansi(text[160*x+i+2]);
if (text[160*x+i+1] && text[160*x+i+1] != 160)
printf("%c", text[160*x+i+1]);
else
printf(" ");
}
printf("%c[m", 27);
printf("\n");
}
printf("%c[m", 27);
printf("\n");
}
#include "wl_def.h"
#include <math.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
......@@ -56,6 +57,7 @@ short int musbuf[256];
void *SoundThread(void *data)
{
int i, snd;
short int samp;
int MusicLength;
int MusicCount;
word *MusicData;
......@@ -73,6 +75,11 @@ void *SoundThread(void *data)
AdlibBlock = 0;
AdlibData = NULL;
AdlibLength = -1;
OPLWrite(OPL, 0x01, 0x20); /* Set WSE=1 */
OPLWrite(OPL, 0x08, 0x00); /* Set CSM=0 & SEL=0 */
/* Yeah, one day I'll rewrite this... */
while (SD_Started) {
if (audiofd != -1) {
......@@ -170,13 +177,17 @@ void *SoundThread(void *data)
for (i = 0; i < (sizeof(sndbuf)/sizeof(sndbuf[0])); i += 2) {
if (SoundPlaying != -1) {
if (SoundPositioned) {
snd = ((((signed short)((SoundData[(SoundPlayPos >> 16)] << 8)^0x8000))>>1)/(L+1))+musbuf[i/2];
samp = (SoundData[(SoundPlayPos >> 16)] << 8)^0x8000;
snd = samp*(16-L)/32+musbuf[i/2];
//snd = (((signed short)((SoundData[(SoundPlayPos >> 16)] << 8)^0x8000))*(16-L)>>5)+musbuf[i/2];
if (snd > 32767)
snd = 32767;
if (snd < -32768)
snd = -32768;
sndbuf[i+0] = snd;
snd = ((((signed short)((SoundData[(SoundPlayPos >> 16)] << 8)^0x8000))>>1)/(R+1))+musbuf[i/2];
samp = (SoundData[(SoundPlayPos >> 16)] << 8)^0x8000;
snd = samp*(16-R)/32+musbuf[i/2];
//snd = (((signed short)((SoundData[(SoundPlayPos >> 16)] << 8)^0x8000))*(16-R)>>5)+musbuf[i/2];
if (snd > 32767)
snd = 32767;
if (snd < -32768)
......
/* id_vl.c */
#include "wl_def.h"
#include <vga.h>
......
......@@ -55,26 +55,29 @@ int main(int argc, char *argv[])
==========================
*/
void DisplayTextSplash(byte *text);
void DisplayTextSplash(byte *text, int l);
void Quit(char *error)
{
memptr screen = NULL;
int l = 0;
if (!error || !*error) {
CA_CacheGrChunk(ORDERSCREEN);
screen = grsegs[ORDERSCREEN];
l = 24;
WriteConfig();
} else if (error) {
CA_CacheGrChunk(ERRORSCREEN);
screen = grsegs[ERRORSCREEN];
l = 7;
}
ShutdownId();
if (screen) {
//printf("TODO: spiffy ansi screen goes here..\n");
DisplayTextSplash(screen);
DisplayTextSplash(screen, l);
}
if (error && *error) {
......
......@@ -681,13 +681,6 @@ void ThreeDRefresh()
/* ======================================================================== */
typedef struct
{
word leftpix, rightpix;
word dataofs[64];
/* table data after dataofs[rightpix-leftpix+1] */
} PACKED t_compshape;
/* TODO: this accesses gfxbuf directly! */
static void ScaledDraw(byte *gfx, int scale, byte *vid, unsigned long tfrac, unsigned long tint, unsigned long delta)
{
......@@ -786,6 +779,13 @@ static void ScaleLineTrans(unsigned int height, byte *source, int x)
static unsigned char *spritegfx[SPR_TOTAL];
typedef struct
{
word leftpix, rightpix;
word dataofs[64];
/* table data after dataofs[rightpix-leftpix+1] */
} PACKED t_compshape;
static void DeCompileSprite(int shapenum)
{
t_compshape *ptr;
......@@ -802,34 +802,8 @@ static void DeCompileSprite(int shapenum)
ptr = PM_GetSpritePage(shapenum);
cmdptr = &ptr->dataofs[31 - ptr->leftpix];
for (srcx = 31; srcx >= ptr->leftpix; srcx--) {
linecmds = (short *)((unsigned char *)ptr + *cmdptr--);
while (linecmds[0]) {
y0 = linecmds[2] / 2;
y1 = linecmds[0] / 2;
pixels = (unsigned char *)ptr + y0 + linecmds[1];
for (y = y0; y < y1; y++) {
//*(buf + slinex + (y*64)) = *pixels;
*(buf + (srcx*64) + y) = *pixels;
pixels++;
}
linecmds += 3;
}
}
if (ptr->leftpix < 31) {
srcx = 32;
cmdptr = &ptr->dataofs[32 - ptr->leftpix];
} else {
srcx = ptr->leftpix;
cmdptr = &ptr->dataofs[0];
}
for (; srcx <= ptr->rightpix; srcx++) {
cmdptr = &ptr->dataofs[0];
for (srcx = ptr->leftpix; srcx <= ptr->rightpix; srcx++) {
linecmds = (short *)((unsigned char *)ptr + *cmdptr++);
while (linecmds[0]) {
......@@ -845,7 +819,6 @@ static void DeCompileSprite(int shapenum)
linecmds += 3;
}
}
spritegfx[shapenum] = buf;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment