Obsolete platforms: GP2X and Dreamcast.

This commit is contained in:
fabien sanglard 2014-07-19 22:25:00 -07:00
parent f109352ff6
commit bad6faa85a
27 changed files with 17 additions and 5436 deletions

View File

@ -1,818 +0,0 @@
/*
** based on:
**
** File: fmopl.c - software implementation of FM sound generator
** types OPL and OPL2
**
** Copyright (C) 2002,2003 Jarek Burczynski (bujar at mame dot net)
** Copyright (C) 1999,2000 Tatsuyuki Satoh , MultiArcadeMachineEmulator development
**
** Version 0.70
**
** from the dosbox 0.72 source
*/
#define LOG_MSG printf
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include "fmopl.h"
#include "fmopl_940/fmopl_shared.h"
#ifndef PI
#define PI 3.14159265358979323846
#endif
/* output final shift */
#if (OPL_SAMPLE_BITS==16)
#define FINAL_SH (0)
#define MAXOUT (+32767)
#define MINOUT (-32768)
#else
#define FINAL_SH (8)
#define MAXOUT (+127)
#define MINOUT (-128)
#endif
#define FREQ_SH 16 /* 16.16 fixed point (frequency calculations) */
#define EG_SH 16 /* 16.16 fixed point (EG timing) */
#define LFO_SH 24 /* 8.24 fixed point (LFO calculations) */
#define TIMER_SH 16 /* 16.16 fixed point (timers calculations) */
#define FREQ_MASK ((1<<FREQ_SH)-1)
/* envelope output entries */
#define ENV_BITS 10
#define ENV_LEN (1<<ENV_BITS)
#define ENV_STEP (128.0/ENV_LEN)
#define MAX_ATT_INDEX ((1<<(ENV_BITS-1))-1) /*511*/
#define MIN_ATT_INDEX (0)
/* register number to channel number , slot offset */
#define SLOT1 0
#define SLOT2 1
/* Envelope Generator phases */
#define EG_ATT 4
#define EG_DEC 3
#define EG_SUS 2
#define EG_REL 1
#define EG_OFF 0
#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 */
/* ---------- Generic interface section ---------- */
#define OPL_TYPE_YM3526 (0)
#define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
#define OPL_TYPE_Y8950 (OPL_TYPE_ADPCM|OPL_TYPE_KEYBOARD|OPL_TYPE_IO)
#define WAIT_IF_MSG_BUF_FULL while( *NSubmittedMessages - *NExecutedMessages>= MSG_BUF_SIZE){};
#define WAIT_FOR_SYNC \
while( (*NSubmittedMessages - *NExecutedMessages) % (int) MSG_BUF_SIZE !=0 ){};
#define ADD_MESSAGE(mtype, i,j,k) \
{ \
int n = ((*NSubmittedMessages)+1) % ((int) MSG_BUF_SIZE); \
MessageBuffer[n].type=mtype; \
MessageBuffer[n].data1=i; \
MessageBuffer[n].data2=j; \
MessageBuffer[n].data3=k; \
(*NSubmittedMessages)++; \
}
//if((*NSubmittedMessages) % (int) 500 ==0)
// LOG_MSG("OPL2: %d %d %d\n",*NSubmittedMessages,*NExecutedMessages,*NSubmittedMessages-*NExecutedMessages);
typedef struct fm_opl_lite {
int T[2]; /* timer counters */
int TC[2];
UINT8 st[2]; /* timer enable */
UINT32 *fn_tab;
/* external event callback handlers */
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 */
UINT8 type; /* chip type */
UINT8 address; /* address register */
UINT8 status; /* status flag */
UINT8 statusmask; /* status mask */
UINT8 mode; /* Reg.08 : CSM,notesel,etc. */
int clock; /* master clock (Hz) */
int rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */
double TimerBase; /* Timer base time (==sampling time)*/
} FM_OPLlite;
/* status set and IRQ handling */
inline void OPL_STATUS_SET(FM_OPLlite *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_OPLlite *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_OPLlite *OPL,int flag)
{
OPL->statusmask = flag;
/* IRQ handling check */
OPL_STATUS_SET(OPL,0);
OPL_STATUS_RESET(OPL,0);
}
/* generic table initialize */
static int init_tables(void)
{
signed int i,x;
signed int n;
double o,m;
for (x=0; x<TL_RES_LEN; x++)
{
m = (1<<16) / pow(2.0, (x+1) * (ENV_STEP/4.0) / 8.0);
m = floor(m);
/* we never reach (1<<16) here due to the (x+1) */
/* result fits within 16 bits at maximum */
n = (int)m; /* 16 bits here */
n >>= 4; /* 12 bits here */
if (n&1) /* round to nearest */
n = (n>>1)+1;
else
n = n>>1;
/* 11 bits here (rounded) */
n <<= 1; /* 12 bits here (as in real chip) */
tl_tab[ x*2 + 0 ] = n;
tl_tab[ x*2 + 1 ] = -tl_tab[ x*2 + 0 ];
for (i=1; i<12; i++)
{
tl_tab[ x*2+0 + i*2*TL_RES_LEN ] = tl_tab[ x*2+0 ]>>i;
tl_tab[ x*2+1 + i*2*TL_RES_LEN ] = -tl_tab[ x*2+0 + i*2*TL_RES_LEN ];
}
}
for (i=0; i<SIN_LEN; i++)
{
/* non-standard sinus */
m = sin( ((i*2)+1) * PI / SIN_LEN ); /* checked against the real chip */
/* we never reach zero here due to ((i*2)+1) */
if (m>0.0)
o = 8*log(1.0/m)/log(2.0); /* convert to 'decibels' */
else
o = 8*log(-1.0/m)/log(2.0); /* convert to 'decibels' */
o = o / (ENV_STEP/4);
n = (int)(2.0*o);
if (n&1) /* round to nearest */
n = (n>>1)+1;
else
n = n>>1;
sin_tab[ i ] = n*2 + (m>=0.0? 0: 1 );
}
for (i=0; i<SIN_LEN; i++)
{
/* waveform 1: __ __ */
/* / \____/ \____*/
/* output only first half of the sinus waveform (positive one) */
if (i & (1<<(SIN_BITS-1)) )
sin_tab[1*SIN_LEN+i] = TL_TAB_LEN;
else
sin_tab[1*SIN_LEN+i] = sin_tab[i];
/* waveform 2: __ __ __ __ */
/* / \/ \/ \/ \*/
/* abs(sin) */
sin_tab[2*SIN_LEN+i] = sin_tab[i & (SIN_MASK>>1) ];
/* waveform 3: _ _ _ _ */
/* / |_/ |_/ |_/ |_*/
/* abs(output only first quarter of the sinus waveform) */
if (i & (1<<(SIN_BITS-2)) )
sin_tab[3*SIN_LEN+i] = TL_TAB_LEN;
else
sin_tab[3*SIN_LEN+i] = sin_tab[i & (SIN_MASK>>2)];
}
return 1;
}
static void OPL_initalize(FM_OPLlite *OPL, FM_OPL *OPLs)
{
int i;
/* frequency base */
OPL->freqbase = (OPL->rate) ? ((double)OPL->clock / 72.0) / OPL->rate : 0;
/* Timer base time */
OPL->TimerBase = 1.0 / ((double)OPL->clock / 72.0 );
/* make fnumber -> increment counter table */
for( i=0 ; i < 1024 ; i++ )
{
/* opn phase increment counter = 20bit */
OPL->fn_tab[i] = (UINT32)( (double)i * 64 * OPL->freqbase * (1<<(FREQ_SH-10)) );
/* -10 because chip works with 10.10 fixed point, while we use 16.16 */
}
/* Amplitude modulation: 27 output levels (triangle waveform); 1 level takes one of: 192, 256 or 448 samples */
/* One entry from LFO_AM_TABLE lasts for 64 samples */
OPLs->lfo_am_inc = (UINT32)((1.0 / 64.0 ) * (1<<LFO_SH) * OPL->freqbase);
/* Vibrato: 8 output levels (triangle waveform); 1 level takes 1024 samples */
OPLs->lfo_pm_inc = (UINT32)((1.0 / 1024.0) * (1<<LFO_SH) * OPL->freqbase);
/* Noise generator: a step takes 1 sample */
OPLs->noise_f = (UINT32)((1.0 / 1.0) * (1<<FREQ_SH) * OPL->freqbase);
OPLs->eg_timer_add = (UINT32)((1<<EG_SH) * OPL->freqbase);
OPLs->eg_timer_overflow = ( 1 ) * (1<<EG_SH);
}
/* write a value v to register r on OPL chip */
static void OPLWriteReg(FM_OPLlite *OPL, int r, int v)
{
/* adjust bus to 8 bits */
r &= 0xff;
v &= 0xff;
switch(r&0xe0)
{
case 0x00: /* 00-1f:control */
switch(r&0x1f)
{
case 0x01: /* waveform select enable */
break;
case 0x02: /* Timer 1 */
OPL->T[0] = (256-v)*4;
break;
case 0x03: /* Timer 2 */
OPL->T[1] = (256-v)*16;
break;
case 0x04: /* IRQ clear / mask and Timer enable */
if(v&0x80)
{ /* IRQ flag clear */
OPL_STATUS_RESET(OPL,0x7f);
}
else
{ /* set IRQ mask ,timer enable*/
OPL->st[0] = v&1;
OPL->st[1] = (v>>1)&1;
/* IRQRST,T1MSK,t2MSK,EOSMSK,BRMSK,x,ST2,ST1 */
OPL_STATUS_RESET(OPL, v & 0x78 );
OPL_STATUSMASK_SET(OPL, (~v) & 0x78 );
/* timer 1 */
if(OPL->st[0])
{
OPL->TC[0]=OPL->T[0]*20;
double interval = (double)OPL->T[0]*OPL->TimerBase;
if (OPL->TimerHandler) (OPL->TimerHandler)(OPL->TimerParam+0,interval);
}
/* timer 2 */
if(OPL->st[1])
{
OPL->TC[1]=OPL->T[1]*20;
double interval =(double)OPL->T[1]*OPL->TimerBase;
if (OPL->TimerHandler) (OPL->TimerHandler)(OPL->TimerParam+1,interval);
}
}
break;
case 0x08: /* MODE,DELTA-T control 2 : CSM,NOTESEL,x,x,smpl,da/ad,64k,rom */
OPL->mode = v;
break;
default:
//logerror("FMOPL.C: write to unknown register: %02x\n",r);
break;
}
break;
case 0x20: /* am ON, vib ON, ksr, eg_type, mul */
break;
case 0x40:
break;
case 0x60:
break;
case 0x80:
break;
case 0xa0:
break;
case 0xc0:
break;
case 0xe0: /* waveform select */
break;
}
}
static void OPLResetChip(FM_OPLlite *OPL)
{
int c,s;
int i;
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);
}
/* Create one of virtual YM3812/YM3526/Y8950 */
/* 'clock' is chip clock in Hz */
/* 'rate' is sampling rate */
void OPLCreate(int type, int clock, int rate, FM_OPLlite* OPL, FM_OPL* OPLs)
{
OPL->type = type;
OPL->clock = clock;
OPL->rate = rate;
/* init global tables */
OPL_initalize(OPL,OPLs);
}
/* Destroy one of virtual YM3812 */
static void OPLDestroy(FM_OPLlite *OPL)
{
free(OPL);
}
/* Optional handlers */
static void OPLSetTimerHandler(FM_OPLlite *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset)
{
OPL->TimerHandler = TimerHandler;
OPL->TimerParam = channelOffset;
}
static void OPLSetIRQHandler(FM_OPLlite *OPL,OPL_IRQHANDLER IRQHandler,int param)
{
OPL->IRQHandler = IRQHandler;
OPL->IRQParam = param;
}
static void OPLSetUpdateHandler(FM_OPLlite *OPL,OPL_UPDATEHANDLER UpdateHandler,int param)
{
OPL->UpdateHandler = UpdateHandler;
OPL->UpdateParam = param;
}
static int OPLWrite(FM_OPLlite *OPL,int a,int v)
{
if( !(a&1) )
{ /* address port */
OPL->address = v & 0xff;
}
else
{ /* data port */
if(OPL->UpdateHandler) OPL->UpdateHandler(OPL->UpdateParam,0);
OPLWriteReg(OPL,OPL->address,v);
}
return OPL->status>>7;
}
static unsigned char OPLRead(FM_OPLlite *OPL,int a)
{
if( !(a&1) )
{
/* status port */
if (OPL->st[0]) {
if (OPL->TC[0]) OPL->TC[0]--;
else {
OPL->TC[0]=OPL->T[0]*20;
OPL_STATUS_SET(OPL,0x40);
}
}
if (OPL->st[1]) {
if (OPL->TC[1]) OPL->TC[1]--;
else {
OPL->TC[1]=OPL->T[1]*20;
OPL_STATUS_SET(OPL,0x40);
}
}
return OPL->status & (OPL->statusmask|0x80);
}
return 0xff;
}
static int OPLTimerOver(FM_OPLlite *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);
}
}
return OPL->status>>7;
}
#define MAX_OPL_CHIPS 2
#if (BUILD_YM3812)
static FM_OPLlite *OPLlite_YM3812[MAX_OPL_CHIPS];
extern "C" {
static int Status940=0;
static int g_hMemory=0;
static volatile unsigned short *g_pusRegs;
static unsigned char *g_pSharedMemory = 0;
void UpdateThreadEntry(void);
void Pause940(int n);
void Reset940(int yes);
void Startup940();
void Shutdown940();
void CleanUp(void);
void InitSharedMemory();
}
void Pause940(int n)
{
if(n)
g_pusRegs[0x0904>>1] &= 0xFFFE;
else
g_pusRegs[0x0904>>1] |= 1;
}
void Reset940(int yes)
{
g_pusRegs[0x3B48>>1] = ((yes&1) << 7) | (0x03);
}
void Startup940()
{
int nLen, nRead;
FILE *fp;
unsigned char ucData[1000];
Reset940(1);
Pause940(1);
g_pusRegs[0x3B40>>1] = 0;
g_pusRegs[0x3B42>>1] = 0;
g_pusRegs[0x3B44>>1] = 0xffff;
g_pusRegs[0x3B46>>1] = 0xffff;
// load code940.bin
nLen = 0;
fp = fopen("code940.bin", "r");
if(!fp) {
LOG_MSG("no 940 core found\n");
return;
} else
{
LOG_MSG("940 core found\n");
}
while(1)
{
nRead = fread(ucData, 1, 1000, fp);
if(nRead <= 0)
break;
memcpy(g_pSharedMemory + nLen, ucData, nRead);
nLen += nRead;
}
fclose(fp);
Reset940(0);
Pause940(0);
usleep(10000);
}
void Shutdown940()
{
Reset940(1);
Pause940(1);
}
void CleanUp(void)
{
Status940--;
//if(Status940>0) return;
//if(g_pSharedMemory)
// munmap(g_pSharedMemory, 0xF80000);
g_pSharedMemory = 0;
Shutdown940();
close(g_hMemory);
printf("Core shutdown\n");
}
void InitSharedMemory()
{
if(g_hMemory) return;
LOG_MSG("Once?\n");
g_hMemory = open("/dev/mem", O_RDWR);
g_pusRegs = (unsigned short *) mmap(0, 0x10000,
PROT_READ|PROT_WRITE, MAP_SHARED, g_hMemory, 0xc0000000);
g_pSharedMemory = (unsigned char *) mmap(0, 0xF80000,
PROT_READ|PROT_WRITE, MAP_SHARED, g_hMemory, 0x3000000);
memset(g_pSharedMemory,0,0x400000);
}
void UpdateThreadEntry(void)
{
Status940++;
if(Status940==1) Startup940();
}
static void InitMemory()
{
SharedBuff_ptr = (char *) (g_pSharedMemory + BUFF_BASE_ADDRESS);
SharedData_ptr = (char *) (g_pSharedMemory + DATA_BASE_ADDRESS);
memset(SharedBuff_ptr,0, END_OFFSET);
memset(SharedData_ptr,0, END_OFFSET2);
}
int YM3812Init(int num, int clock, int rate)
{
int i;
char *ptr;
if (YM3812NumChips)
return -1; /* duplicate init. */
if(END_OFFSET>OPL2_MSG_SIZE ||
END_OFFSET2>OPL2_DAT_SIZE) {
LOG_MSG("OPL2 memory data error\n");
return -1;
}
InitSharedMemory();
InitMemory();
LOG_MSG("OPL2 reports\n");
LOG_MSG("OPL2 mem: %d %d %d %d\n", sizeof(OPL_SLOT),
sizeof(OPL_CH),sizeof(FM_OPL),OPL_SIZE);
ptr=(SharedData_ptr + NUMCHIP_OFFSET);
YM3812NumChips=(int *) ptr;
*YM3812NumChips = num;
ptr=(SharedBuff_ptr + NSUB_OFFSET);
NSubmittedMessages=(int *) ptr;
*NSubmittedMessages=-1;
ptr=(SharedBuff_ptr + NEX_OFFSET);
NExecutedMessages=(int *) ptr;
*NExecutedMessages=-1;
ptr=(SharedBuff_ptr + MSG_BUF_OFFSET);
MessageBuffer=(CoreMessage *) ptr;
ptr=(SharedBuff_ptr + TL_TAB_OFFSET);
tl_tab=(signed int *) ptr;
ptr=(SharedBuff_ptr + SIN_TAB_OFFSET);
sin_tab=(unsigned int *) ptr;
init_tables();
for (i = 0;i < *YM3812NumChips; i++)
{
ptr=(SharedBuff_ptr + BUFPOS_OFFSET+ i*sizeof(int));
BufWritePos[i]=(int *) ptr;
*BufWritePos[i]=0;
ptr=(SharedBuff_ptr + READPOS_OFFSET +i*sizeof(int));
BufReadPos[i]=(int *) ptr;
*BufReadPos[i]=0;
ptr=(SharedBuff_ptr + DATA_OFFSET + i * SHARED_BUF_SIZE * sizeof(INT16));
SharedBuffer[i]=(INT16 *) ptr;
ptr=(SharedData_ptr + OPL_OFFSET + i*OPL_SIZE);
OPL_YM3812[i] = (FM_OPL*) ptr;
ptr = (char *) malloc(sizeof(FM_OPLlite));
memset(ptr , 0, sizeof(FM_OPLlite));
OPLlite_YM3812[i] = (FM_OPLlite *) ptr;
ptr=(SharedBuff_ptr + FNTAB_OFFSET+i*1024*sizeof(UINT32));
OPLlite_YM3812[i]->fn_tab=(UINT32 *) ptr;
OPLCreate(OPL_TYPE_YM3812,clock,rate,OPLlite_YM3812[i],OPL_YM3812[i]);
}
UpdateThreadEntry();
ADD_MESSAGE(INIT ,num ,clock ,rate );
for (i = 0;i < *YM3812NumChips; i++)
{
YM3812ResetChip(i);
}
return 0;
}
void YM3812Shutdown(void)
{
int i;
LOG_MSG("OPL2 ...\n");
ADD_MESSAGE(SHUTDOWN,0,0,0);
WAIT_FOR_SYNC;
LOG_MSG("OPL2 end\n");
for (i = 0;i < *YM3812NumChips; i++)
{
/* emulator shutdown */
OPLDestroy(OPLlite_YM3812[i]);
OPL_YM3812[i] = NULL;
OPLlite_YM3812[i] = NULL;
}
*YM3812NumChips = 0;
CleanUp();
}
void YM3812ResetChip(int which)
{
ADD_MESSAGE(RESET,which,0,0);
OPLResetChip(OPLlite_YM3812[which]);
}
int YM3812Write(int which, int a, int v)
{
ADD_MESSAGE(WRITE,which,0,a);
ADD_MESSAGE(WRITE,which,1,v);
OPLWriteReg(OPLlite_YM3812[which], a, v);
return (OPLlite_YM3812[which]->status>>7);
}
unsigned char YM3812Read(int which, int a)
{
ADD_MESSAGE(READ,which,a,0);
/* YM3812 always returns bit2 and bit1 in HIGH state */
return OPLRead(OPLlite_YM3812[which], a) | 0x06 ;
}
int YM3812TimerOver(int which, int c)
{
ADD_MESSAGE(TIMEROVER,which,c,0);
return OPLTimerOver(OPLlite_YM3812[which], c);
}
void YM3812SetTimerHandler(int which, OPL_TIMERHANDLER TimerHandler, int channelOffset)
{
OPLSetTimerHandler(OPLlite_YM3812[which], TimerHandler, channelOffset);
}
void YM3812SetIRQHandler(int which,OPL_IRQHANDLER IRQHandler,int param)
{
OPLSetIRQHandler(OPLlite_YM3812[which], IRQHandler, param);
}
void YM3812SetUpdateHandler(int which,OPL_UPDATEHANDLER UpdateHandler,int param)
{
OPLSetUpdateHandler(OPLlite_YM3812[which], UpdateHandler, param);
}
void YM3812UpdateOne(int which, INT16 *buffer, int length)
{
int i,ncopy,nfree,nbuff,d,bufpos;
INT16 lt;
static int warn=1;
d=*NSubmittedMessages-*NExecutedMessages;
if(warn && d>MSG_BUF_SIZE)
{
LOG_MSG("OPL2: buffer running full");
warn=0;
}
else
{
if(d<MSG_BUF_SIZE) warn=1;
}
bufpos=*BufReadPos[which];
d=*BufWritePos[which]- bufpos;
nbuff=WRAPPED(d,SHARED_BUF_SIZE);
ncopy=MIN(length, nbuff);
nfree=SHARED_BUF_SIZE - bufpos;
if(ncopy < nfree)
{
for(i=0;i<ncopy;i++)
{
lt=Amp( SharedBuffer[which][ bufpos+i ] );
buffer[2*i]=lt;
buffer[2*i+1]=lt; //for stereo
}
(*BufReadPos[which])+=ncopy;
}
else
{
for(i=0;i<nfree;i++)
{
lt=Amp( SharedBuffer[which][ bufpos+i ] );
buffer[2*i]=lt;
buffer[2*i+1]=lt;
}
for(i=0;i<ncopy-nfree;i++)
{
lt=Amp( SharedBuffer[which][i] );
buffer[2*i+2*nfree]=lt;
buffer[2*i+2*nfree+1]=lt;
}
*BufReadPos[which]=ncopy-nfree;
}
if(ncopy < length)
{
bufpos=*BufReadPos[which];
lt=Amp( SharedBuffer[which][WRAPPED(bufpos-1,SHARED_BUF_SIZE)] );
for(i=ncopy;i<length;i++)
{
buffer[2*i]=lt;
buffer[2*i+1]=lt;
}
}
ADD_MESSAGE(UPDATE, which, length, 0);
}
INT16 Amp( INT16 value )
{
INT32 temp;
int offset = 2;
temp = value;
temp <<= offset;
if( temp > MAXOUT ) temp = MAXOUT;
if( temp < MINOUT ) temp = MINOUT;
return (INT16)temp;
}
#endif /* BUILD_YM3812 */

View File

@ -1,58 +0,0 @@
#ifndef __FMOPL_H_
#define __FMOPL_H_
#define HAS_YM3812 1
/* --- select emulation chips --- */
#define BUILD_YM3812 (HAS_YM3812)
#define BUILD_YM3526 (HAS_YM3526)
#define BUILD_Y8950 (HAS_Y8950)
/* select output bits size of output : 8 or 16 */
#define OPL_SAMPLE_BITS 16
/* compiler dependence */
#ifndef OSD_CPU_H
#define OSD_CPU_H
typedef unsigned char UINT8; /* unsigned 8bit */
typedef unsigned short UINT16; /* unsigned 16bit */
typedef unsigned int UINT32; /* unsigned 32bit */
typedef signed char INT8; /* signed 8bit */
typedef signed short INT16; /* signed 16bit */
typedef signed int INT32; /* signed 32bit */
#endif
#if (OPL_SAMPLE_BITS==16)
typedef INT16 OPLSAMPLE;
#endif
#if (OPL_SAMPLE_BITS==8)
typedef INT8 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);
typedef void (*OPL_PORTHANDLER_W)(int param,unsigned char data);
typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
#if BUILD_YM3812
int YM3812Init(int num, int clock, int rate);
void YM3812Shutdown(void);
void YM3812ResetChip(int which);
int YM3812Write(int which, int a, int v);
unsigned char YM3812Read(int which, int a);
int YM3812TimerOver(int which, int c);
void YM3812UpdateOne(int which, INT16 *buffer, int length);
void YM3812SetTimerHandler(int which, OPL_TIMERHANDLER TimerHandler, int channelOffset);
void YM3812SetIRQHandler(int which, OPL_IRQHANDLER IRQHandler, int param);
void YM3812SetUpdateHandler(int which, OPL_UPDATEHANDLER UpdateHandler, int param);
INT16 Amp( INT16 );
#endif
#endif

View File

@ -1,27 +0,0 @@
CROSS_COMPILE = /mythtv/media/devel/toolchains/open2x/gcc-4.1.1-glibc-2.3.6/bin/arm-open2x-linux-
LDFLAGS = -static
CXX = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)g++
LD = $(CROSS_COMPILE)ld
STRIP = $(CROSS_COMPILE)strip
CXXFLAGS = -I/opt/open2x/gcc-4.1.1-glibc-2.3.6/include -Wall -Werror -Os -fomit-frame-pointer
LIBS = -L/opt/open2x/gcc-4.1.1-glibc-2.3.6/lib
CODE940_TARGET = code940.gpe
CODE940_OBJS = main.o fmopl_core.o
all : $(CODE940_TARGET)
$(CODE940_TARGET) : $(CODE940_OBJS)
$(LD) -marmelf -e code940 -Ttext 0x0 $(CODE940_OBJS) -o $(CODE940_TARGET)
$(CROSS_COMPILE)objcopy -O binary code940.gpe code940.bin
ls -l code940.bin
main.o: main.c
$(CXX) $(CXXFLAGS) -O0 -c main.c
fmopl_core.o: fmopl_core.c fmopl_core.h fmopl_shared.h memory_layout.h
$(CPP) $(CXXFLAGS) -Os -c fmopl_core.c

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +0,0 @@
#ifndef __FMOPL_H_
#define __FMOPL_H_
#define HAS_YM3812 1
/* --- select emulation chips --- */
#define BUILD_YM3812 (HAS_YM3812)
#define BUILD_YM3526 (HAS_YM3526)
#define BUILD_Y8950 (HAS_Y8950)
/* select output bits size of output : 8 or 16 */
#define OPL_SAMPLE_BITS 16
/* compiler dependence */
#ifndef OSD_CPU_H
#define OSD_CPU_H
typedef unsigned char UINT8; /* unsigned 8bit */
typedef unsigned short UINT16; /* unsigned 16bit */
typedef unsigned int UINT32; /* unsigned 32bit */
typedef signed char INT8; /* signed 8bit */
typedef signed short INT16; /* signed 16bit */
typedef signed int INT32; /* signed 32bit */
#endif
#if (OPL_SAMPLE_BITS==16)
typedef INT16 OPLSAMPLE;
#endif
#if (OPL_SAMPLE_BITS==8)
typedef INT8 OPLSAMPLE;
#endif
#endif

View File

@ -1,175 +0,0 @@
#include "memory_layout.h"
#define WRAPPED(x,y) ((x)>=0?(x):(x)+(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
typedef struct{
UINT32 ar; /* attack rate: AR<<2 */
UINT32 dr; /* decay rate: DR<<2 */
UINT32 rr; /* release rate:RR<<2 */
UINT8 KSR; /* key scale rate */
UINT8 ksl; /* keyscale level */
UINT8 ksr; /* key scale rate: kcode>>KSR */
UINT8 mul; /* multiple: mul_tab[ML] */
/* Phase Generator */
UINT32 Cnt; /* frequency counter */
UINT32 Incr; /* frequency counter step */
UINT8 FB; /* feedback shift value */
INT32 *connect1; /* slot1 output pointer */
INT32 op1_out[2]; /* slot1 output for feedback */
UINT8 CON; /* connection (algorithm) type */
/* Envelope Generator */
UINT8 eg_type; /* percussive/non-percussive mode */
UINT8 state; /* phase type */
UINT32 TL; /* total level: TL << 2 */
INT32 TLL; /* adjusted now TL */
INT32 volume; /* envelope counter */
UINT32 sl; /* sustain level: sl_tab[SL] */
UINT8 eg_sh_ar; /* (attack state) */
UINT8 eg_sel_ar; /* (attack state) */
UINT8 eg_sh_dr; /* (decay state) */
UINT8 eg_sel_dr; /* (decay state) */
UINT8 eg_sh_rr; /* (release state) */
UINT8 eg_sel_rr; /* (release state) */
UINT32 key; /* 0 = KEY OFF, >0 = KEY ON */
/* LFO */
UINT32 AMmask; /* LFO Amplitude Modulation enable mask */
UINT8 vib; /* LFO Phase Modulation enable flag (active high)*/
/* waveform select */
unsigned int wavetable;
} OPL_SLOT;
typedef struct{
OPL_SLOT SLOT[2];
/* phase generator state */
UINT32 block_fnum; /* block+fnum */
UINT32 fc; /* Freq. Increment base */
UINT32 ksl_base; /* KeyScaleLevel Base step */
UINT8 kcode; /* key code (for key scaling) */
} OPL_CH;
/* OPL state */
typedef struct fm_opl_f {
/* FM channel slots */
OPL_CH P_CH[9]; /* OPL/OPL2 chips have 9 channels*/
UINT32 eg_cnt; /* global envelope generator counter */
UINT32 eg_timer; /* global envelope generator counter works at frequency = chipclock/72 */
UINT32 eg_timer_add; /* step of eg_timer */
UINT32 eg_timer_overflow; /* envelope generator timer overlfows every 1 sample (on real chip) */
UINT8 rhythm; /* Rhythm mode */
UINT32 *fn_tab; /* fnumber->increment counter */
/* LFO */
UINT8 lfo_am_depth;
UINT8 lfo_pm_depth_range;
UINT32 lfo_am_cnt;
UINT32 lfo_am_inc;
UINT32 lfo_pm_cnt;
UINT32 lfo_pm_inc;
UINT32 noise_rng; /* 23 bit noise shift register */
UINT32 noise_p; /* current noise 'phase' */
UINT32 noise_f; /* current noise period */
UINT8 wavesel; /* waveform select enable flag */
int T[2]; /* timer counters */
int TC[2];
UINT8 st[2]; /* timer enable */
/* external event callback handlers */
UINT8 type; /* chip type */
UINT8 address; /* address register */
UINT8 status; /* status flag */
UINT8 statusmask; /* status mask */
UINT8 mode; /* Reg.08 : CSM,notesel,etc. */
int clock; /* master clock (Hz) */
int rate; /* sampling rate (Hz) */
} FM_OPL;
#define OPL_SIZE 2048
/* TL_TAB_LEN is calculated as:
* 12 - sinus amplitude bits (Y axis)
* 2 - sinus sign bit (Y axis)
* TL_RES_LEN - sinus resolution (X axis)
*/
#define TL_RES_LEN (256) /* 8 bits addressing (real chip) */
#define TL_TAB_LEN (12*2*TL_RES_LEN)
static signed int *tl_tab;
#define SIN_BITS 10
#define SIN_LEN (1<<SIN_BITS)
#define SIN_MASK (SIN_LEN-1)
/* sin waveform table in 'decibel' scale */
/* four waveforms on OPL2 type chips */
/* sinwave entries */
static unsigned int *sin_tab;
enum CMESSAGE {
INIT,
READ,
WRITE,
UPDATE,
TIMEROVER,
RESET,
SHUTDOWN
};
typedef struct {
int type;
// int no;
int data1;
int data2;
int data3;
} CoreMessage;
#define MAX_OPL_CHIPS 2
#define MSG_BUF_SIZE 4*1024
volatile static CoreMessage* MessageBuffer;
volatile static int* NSubmittedMessages;
volatile static int* NExecutedMessages;
#define SHARED_BUF_SIZE 256
volatile static INT16* SharedBuffer[MAX_OPL_CHIPS];
volatile static int* BufWritePos[MAX_OPL_CHIPS];
volatile static int* BufReadPos[MAX_OPL_CHIPS];
#if (BUILD_YM3812)
static FM_OPL *OPL_YM3812[MAX_OPL_CHIPS]; /* array of pointers to the YM3812's */
static int *YM3812NumChips=0; /* number of chips */
#endif
#define BUFF_BASE_ADDRESS OPL2_MSG_BASE
#define NSUB_OFFSET 0
#define NEX_OFFSET (NSUB_OFFSET+sizeof(int))
#define MSG_BUF_OFFSET (NEX_OFFSET+sizeof(int))
#define BUFPOS_OFFSET (MSG_BUF_OFFSET+MSG_BUF_SIZE*sizeof(CoreMessage))
#define READPOS_OFFSET (BUFPOS_OFFSET+MAX_OPL_CHIPS*sizeof(int))
#define DATA_OFFSET (READPOS_OFFSET+MAX_OPL_CHIPS*sizeof(int))
#define TL_TAB_OFFSET (DATA_OFFSET+MAX_OPL_CHIPS*SHARED_BUF_SIZE*sizeof(INT16))
#define SIN_TAB_OFFSET (TL_TAB_OFFSET+TL_TAB_LEN*sizeof(signed int))
#define FNTAB_OFFSET (SIN_TAB_OFFSET+4*SIN_LEN*sizeof(unsigned int))
#define END_OFFSET (FNTAB_OFFSET+1024*MAX_OPL_CHIPS*sizeof(UINT32))
#define DATA_BASE_ADDRESS OPL2_DAT_BASE
#define NUMCHIP_OFFSET 0
#define OPL_OFFSET (NUMCHIP_OFFSET+sizeof(int))
#define END_OFFSET2 (OPL_OFFSET+OPL_SIZE*MAX_OPL_CHIPS)
static char* SharedData_ptr;
static char* SharedBuff_ptr;

View File

@ -1,54 +0,0 @@
extern void fmopl_Init();
extern int fmopl_core_control();
void Main940();
void code940(void) __attribute__((naked))
{
asm ("b .DzzBegin"); // reset, interrupt table
asm ("b .DzzBegin");
asm ("b .DzzBegin");
asm ("b .DzzBegin");
asm ("b .DzzBegin");
asm ("b .DzzBegin");
asm ("b .DzzBegin");
asm ("b .DzzBegin");
asm (".DzzBegin:");
asm ("mov sp, #0x100000"); // set the stack top (1M)
asm ("sub sp, sp, #4"); // minus 4
// set up memory region 0 -- the whole 4GB address space
asm ("mov r0, #63"); // region data
asm ("mcr p15, 0, r0, c6, c0, 0");
asm ("mcr p15, 0, r0, c6, c0, 1");
// set up region 1 which is the first 2 megabytes.
asm ("mov r0, #0x00000029"); // region data
asm ("mcr p15, 0, r0, c6, c1, 0");
asm ("mcr p15, 0, r0, c6, c1, 1");
// set region 1 to be cacheable (so the first 2M will be cacheable)
asm ("mov r0, #2");
asm ("mcr p15, 0, r0, c2, c0, 0");
asm ("mcr p15, 0, r0, c2, c0, 1");
// set region 1 to be bufferable too (only data)
asm ("mcr p15, 0, r0, c3, c0, 0");
// set protection on for all regions
asm ("mov r0, #15");
asm ("mcr p15, 0, r0, c5, c0, 0");
asm ("mcr p15, 0, r0, c5, c0, 1");
asm ("mrc p15, 0, r0, c1, c0, 0"); // fetch current control reg
asm ("orr r0, r0, #1"); // 0x00000001: enable protection unit
asm ("orr r0, r0, #4"); // 0x00000004: enable D cache
asm ("orr r0, r0, #0x1000"); // 0x00001000: enable I cache
asm ("orr r0, r0, #0xC0000000"); // 0xC0000000: async+fastbus
asm ("mcr p15, 0, r0, c1, c0, 0"); // set control reg
Main940();
}
void Main940(void)
{
fmopl_Init();
while(fmopl_core_control()) {};
}

View File

@ -1,34 +0,0 @@
/*
memory layout for OPL2+OPL3
*/
#define OPL2_MSG_BASE 0x200000
#define OPL2_MSG_SIZE 0x100000
#define OPL2_DAT_BASE 0x14C000
#define OPL2_DAT_SIZE 0x14000
#define OPL3_MSG_BASE 0x300000
#define OPL3_MSG_SIZE 0x100000
#define OPL3_DAT_BASE 0x160000
#define OPL3_DAT_SIZE 0x40000
#undef BUFF_BASE_ADDRESS
#undef NSUB_OFFSET
#undef NEX_OFFSET
#undef MSG_BUF_OFFSET
#undef BUFPOS_OFFSET
#undef READPOS_OFFSET
#undef DATA_OFFSET
#undef FNTAB_OFFSET
#undef END_OFFSET
#undef DATA_BASE_ADDRESS
#undef NUMCHIP_OFFSET
#undef TL_TAB_OFFSET
#undef SIN_TAB_OFFSET
#undef OPL_OFFSET
#undef END_OFFSET2
#undef MSG_BUF_SIZE
#undef SHARED_BUF_SIZE
#undef OPL_SIZE

View File

@ -1,327 +0,0 @@
//
// GP2X specific code
//
// by Pickle
//
#if defined(GP2X)
#include "gp2x.h"
static bool volume_init = false;
static unsigned int screenshot_count = 0;
#if defined(GP2X_940)
static int volume = 70;
#else
static int volume = 10;
#endif
static int intUp = 0;
static int intDown = 0;
static int intLeft = 0;
static int intRight = 0;
static int intUpRight = 0;
static int intUpLeft = 0;
static int intDownRight = 0;
static int intDownLeft = 0;
static int intButtonR = 0;
static int intButtonL = 0;
static int intButtonA = 0;
static int intButtonB = 0;
static int intButtonX = 0;
static int intButtonY = 0;
static int intButtonSel = 0;
static int intButtonSrt = 0;
static int intButtonStick = 0;
#if defined(GP2X_940)
void GP2X_Shutdown(void)
{
YM3812Shutdown();
}
void GP2X_MemoryInit( void )
{
SDL_GP2X_AllowGfxMemory(NULL,0);
}
#endif
void GP2X_AdjustVolume( int direction )
{
if( volume <= 10 )
{
if( direction == VOLUME_UP ) volume += VOLUME_CHANGE_RATE/2;
if( direction == VOLUME_DOWN ) volume -= VOLUME_CHANGE_RATE/2;
}
else
{
if( direction == VOLUME_UP ) volume += VOLUME_CHANGE_RATE;
if( direction == VOLUME_DOWN ) volume -= VOLUME_CHANGE_RATE;
}
if( volume < VOLUME_MIN ) volume = VOLUME_MIN;
if( volume > VOLUME_MAX ) volume = VOLUME_MAX;
printf( "Volume Change: %i\n", volume );
unsigned long soundDev = open("/dev/mixer", O_RDWR);
if(soundDev)
{
int vol = ((volume << 8) | volume);
ioctl(soundDev, SOUND_MIXER_WRITE_PCM, &vol);
close(soundDev);
}
}
void GP2X_ButtonDown( int button )
{
if( !volume_init )
{
GP2X_AdjustVolume(VOLUME_NOCHG);
volume_init = 1;
}
switch( button )
{
case GP2X_BUTTON_UP: intUp = 1; break;
case GP2X_BUTTON_DOWN: intDown = 1; break;
case GP2X_BUTTON_RIGHT: intRight = 1; break;
case GP2X_BUTTON_LEFT: intLeft = 1; break;
case GP2X_BUTTON_UPRIGHT: intUpRight = 1; break;
case GP2X_BUTTON_UPLEFT: intUpLeft = 1; break;
case GP2X_BUTTON_DOWNRIGHT: intDownRight = 1; break;
case GP2X_BUTTON_DOWNLEFT: intDownLeft = 1; break;
case GP2X_BUTTON_SELECT: intButtonSel = 1; break;
case GP2X_BUTTON_START: intButtonSrt = 1; break;
case GP2X_BUTTON_X: intButtonX = 1; LastASCII = 'x'; break;
case GP2X_BUTTON_Y: intButtonY = 1; LastASCII = 'y'; break;
case GP2X_BUTTON_A: intButtonA = 1; LastASCII = 'a'; break;
case GP2X_BUTTON_B: intButtonB = 1; LastASCII = 'b'; break;
case GP2X_BUTTON_R: intButtonR = 1; break;
case GP2X_BUTTON_L: intButtonL = 1; break;
case GP2X_BUTTON_VOLUP: GP2X_AdjustVolume( VOLUME_UP ); break;
case GP2X_BUTTON_VOLDOWN: GP2X_AdjustVolume( VOLUME_DOWN ); break;
case GP2X_BUTTON_CLICK: intButtonStick = 1; break;
}
if( intButtonL & intButtonR )
{
// Status Bar
SetKeyboard( SDLK_TAB, KEY_DOWN );
// Music Player (doesnt work, it appears the event's arnt happening soon enough)
SetKeyboard( sc_M, KEY_DOWN );
SetKeyboard( SDLK_LALT, KEY_UP );
SetKeyboard( SDLK_LEFT, KEY_UP );
SetKeyboard( SDLK_RIGHT, KEY_UP );
}
else if( intButtonL & !intButtonR )
{
// Strafe Left
SetKeyboard( SDLK_LALT, KEY_DOWN );
SetKeyboard( SDLK_LEFT, KEY_DOWN );
}
else if( intButtonR & !intButtonL )
{
// Strafe Right
SetKeyboard( SDLK_LALT, KEY_DOWN );
SetKeyboard( SDLK_RIGHT, KEY_DOWN );
}
// Left Direction
if( intLeft | intDownLeft | intUpLeft )
{
// UNstrafe
SetKeyboard( SDLK_LALT, KEY_UP );
SetKeyboard( SDLK_RIGHT, KEY_UP );
// Turn
SetKeyboard( SDLK_LEFT, KEY_DOWN );
}
// Right Direction
if( intRight | intDownRight | intUpRight )
{
// UNstrafe
SetKeyboard( SDLK_LALT, KEY_UP );
SetKeyboard( SDLK_LEFT, KEY_UP );
// Turn
SetKeyboard( SDLK_RIGHT, KEY_DOWN );
}
// Up Direction
if( intUp | intUpRight | intUpLeft ) {
SetKeyboard( SDLK_UP, KEY_DOWN );
}
// Down Direction
if( intDown | intDownRight | intDownLeft ) {
SetKeyboard( SDLK_DOWN, KEY_DOWN );
}
if( intButtonSel & intButtonSrt ) {
// Pause
SetKeyboard( SDLK_PAUSE, KEY_DOWN );
}
else if( intButtonL & intButtonSel ) {
fpscounter ^= 1; // Turn On FPS Counter
}
else if( intButtonL & intButtonSrt ) {
Screenshot();
}
else if( intButtonSel & !intButtonSrt ) {
// Escape
SetKeyboard( SDLK_ESCAPE, KEY_DOWN );
}
else if( !intButtonSel & intButtonSrt ) {
// Enter
SetKeyboard( SDLK_RETURN, KEY_DOWN );
}
if( intButtonX ) {
// Shoot
SetKeyboard( SDLK_LCTRL, KEY_DOWN );
}
if( intButtonY ) {
// Yes
SetKeyboard( SDLK_y, KEY_DOWN );
if( gamestate.chosenweapon == gamestate.bestweapon )
{
SetKeyboard( SDLK_1, KEY_DOWN );
}
else
{
SetKeyboard( SDLK_1 + gamestate.chosenweapon + 1, KEY_DOWN );
}
}
if( intButtonA ) {
// Open
SetKeyboard( SDLK_SPACE, KEY_DOWN );
}
if( intButtonB ) {
// No
SetKeyboard( SDLK_n, KEY_DOWN );
// Run
SetKeyboard( SDLK_LSHIFT, KEY_DOWN );
}
}
void GP2X_ButtonUp( int button )
{
switch( button )
{
case GP2X_BUTTON_UP: intUp = 0; break;
case GP2X_BUTTON_DOWN: intDown = 0; break;
case GP2X_BUTTON_RIGHT: intRight = 0; break;
case GP2X_BUTTON_LEFT: intLeft = 0; break;
case GP2X_BUTTON_UPRIGHT: intUpRight = 0; break;
case GP2X_BUTTON_UPLEFT: intUpLeft = 0; break;
case GP2X_BUTTON_DOWNRIGHT: intDownRight = 0; break;
case GP2X_BUTTON_DOWNLEFT: intDownLeft = 0; break;
case GP2X_BUTTON_SELECT: intButtonSel = 0; break;
case GP2X_BUTTON_START: intButtonSrt = 0; break;
case GP2X_BUTTON_X: intButtonX = 0; break;
case GP2X_BUTTON_Y: intButtonY = 0; break;
case GP2X_BUTTON_A: intButtonA = 0; break;
case GP2X_BUTTON_B: intButtonB = 0; break;
case GP2X_BUTTON_R: intButtonR = 0; break;
case GP2X_BUTTON_L: intButtonL = 0; break;
case GP2X_BUTTON_CLICK: intButtonStick = 0; break;
}
if( !intButtonL | !intButtonR )
{
SetKeyboard( SDLK_TAB, KEY_UP );
SetKeyboard( sc_M, KEY_UP );
SetKeyboard( SDLK_LALT, KEY_UP );
}
if( !intLeft & !intDownLeft & !intUpLeft )
{
if( !intButtonL )
{
SetKeyboard( SDLK_LALT, KEY_UP );
SetKeyboard( SDLK_LEFT, KEY_UP );
}
if( intButtonR )
{
SetKeyboard( SDLK_LALT, KEY_DOWN );
SetKeyboard( SDLK_RIGHT, KEY_DOWN );
}
}
if( !intRight & !intDownRight & !intUpRight )
{
if( !intButtonR )
{
SetKeyboard( SDLK_LALT, KEY_UP );
SetKeyboard( SDLK_RIGHT, KEY_UP );
}
if( intButtonL )
{
SetKeyboard( SDLK_LALT, KEY_DOWN );
SetKeyboard( SDLK_LEFT, KEY_DOWN );
}
}
if( !intUp & !intUpRight & !intUpLeft ) {
SetKeyboard( SDLK_UP, KEY_UP );
}
if( !intDown & !intDownRight & !intDownLeft ) {
SetKeyboard( SDLK_DOWN, KEY_UP );
}
if( !intButtonSel & !intButtonSrt ) {
SetKeyboard( SDLK_PAUSE, KEY_UP );
}
if( !intButtonSel ) {
SetKeyboard( SDLK_ESCAPE, KEY_UP );
}
if( !intButtonSrt ) {
SetKeyboard( SDLK_RETURN, KEY_UP );
}
if( !intButtonX ) {
SetKeyboard( SDLK_LCTRL, KEY_UP );
}
if( !intButtonY ) {
SetKeyboard( SDLK_y, KEY_UP );
SetKeyboard( SDLK_1, KEY_UP );
SetKeyboard( SDLK_2, KEY_UP );
SetKeyboard( SDLK_3, KEY_UP );
SetKeyboard( SDLK_4, KEY_UP );
}
if( !intButtonA ) {
SetKeyboard( SDLK_SPACE, KEY_UP );
}
if( !intButtonB ) {
SetKeyboard( SDLK_n, KEY_UP );
SetKeyboard( SDLK_LSHIFT, KEY_UP );
}
}
void Screenshot( void )
{
char filename[32];
snprintf( filename, sizeof(filename), "Screenshot_%i.bmp", screenshot_count );
SDL_SaveBMP(screen, filename );
screenshot_count++;
}
void SetKeyboard( unsigned int key, int press )
{
// press = 1 = down, press = 0 = up
if( press )
{
LastScan = key;
Keyboard[key] = 1;
}
else
{
Keyboard[key] = 0;
}
}
#endif // GP2X

View File

@ -1,54 +0,0 @@
#ifndef GP2X_H
#define GP2X_H
#include <SDL/SDL.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <fcntl.h>
#include <unistd.h>
#include "../wl_def.h"
#if defined(GP2X_940)
#include "fmopl.h"
#include <SDL_gp2x.h>
#endif
#define GP2X_BUTTON_UP (0)
#define GP2X_BUTTON_DOWN (4)
#define GP2X_BUTTON_LEFT (2)
#define GP2X_BUTTON_RIGHT (6)
#define GP2X_BUTTON_UPLEFT (1)
#define GP2X_BUTTON_UPRIGHT (7)
#define GP2X_BUTTON_DOWNLEFT (3)
#define GP2X_BUTTON_DOWNRIGHT (5)
#define GP2X_BUTTON_CLICK (18)
#define GP2X_BUTTON_A (12)
#define GP2X_BUTTON_B (13)
#define GP2X_BUTTON_X (14)
#define GP2X_BUTTON_Y (15)
#define GP2X_BUTTON_L (10)
#define GP2X_BUTTON_R (11)
#define GP2X_BUTTON_START (8)
#define GP2X_BUTTON_SELECT (9)
#define GP2X_BUTTON_VOLUP (16)
#define GP2X_BUTTON_VOLDOWN (17)
#define VOLUME_MIN 0
#define VOLUME_MAX 100
#define VOLUME_CHANGE_RATE 2
#define VOLUME_NOCHG 0
#define VOLUME_DOWN 1
#define VOLUME_UP 2
#define KEY_DOWN 1
#define KEY_UP 0
void GP2X_MemoryInit(void);
void GP2X_Shutdown(void);
void GP2X_AdjustVolume( int direction );
void GP2X_ButtonDown( int button );
void GP2X_ButtonUp( int button );
void Screenshot( void );
void SetKeyboard( unsigned int key, int press );
#endif // GP2X_H

View File

@ -1,70 +0,0 @@
Wolf4SDL by Moritz "Ripper" Kroll (http://www.chaos-software.de.vu)
Original Wolfenstein 3D by id Software (http://www.idsoftware.com)
GP2X support by Pickle
Source and Windows Binary: http://www.stud.uni-karlsruhe.de/~uvaue/chaos/downloads.html
GP2X Binary: http://archive.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,20,2479
SUMMARY:
See main README.txt
GP2X CONTROLS:
Directional: these are mapped to the arrow keys.
A : mapped to space, which opens doors
B : mapped to left shift, which enables running. Also mapped
to key n, for the NO response in the menu.
X : mapped to left control, which enables shooting.
Y : mapped to the number keys, to select weapons. It cycles
through each weapon in order. Also mapped to key y, for
the YES responses in the menu.
** NOTE: In "enter text" mode each button sends its letter,
for example a=a, y=y
Select: mapped to the escape key
Start: mapped to the enter key
Select+Start: mapped to pause
Shoulder Left: this is mapped in a way to strafe left
Shoulder Right: this is mapped in a way to strafe right
** NOTE: If you press both the left and right shoulder buttons the statusbar
will be shown in the fullscreen mode described above.
Volume Buttons: raise and lower the volume.
Either Volume Button + Select: show fps
Either Volume Button + Start: take a screenshot
** NOTE: The directional stick is given precedence over the strafe keys.
For example if you hold the shoulder right to strafe right and you
then move the stick right you will stop strafing and turn. If you
then release the stick you will resume strafing the right.
(I've tested this and it seems to work fairly well)
INSTALL:
Pick your Wolf4SDL binary and copy the files at the root of the zip to any
folder together with the data files of the according game (e.g. *.WL6 for
Wolfenstein 3D or *.SOD for Spear of Destiny).
The binaries do not restart the GP2X menu application.
If you use GMenu2x, select the wrapper option for your icon.
If you use the GPH menu, you will have to create your own script to restart it.
Compiling from source code:
I used the Code::Blocks dev kit. (http://archive.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,14,2295)
You can use the template example. Add all of the source files to the project.
Under build options (pick your GP2X compilier) and under "Compilier Settings"
-> "Defines" add GP2X. Just press the build button.
The Makefile should also work for linux type environments, although I have
not tried it this way. If you use it, the GP2X define should be added to the
Makefile using CFLAGS += -DGP2X.
I also added the compiler flags
"-fmerge-all-constants -ffast-math -funswitch-loops"
which give a good performance increase.
For Code::Blocks put this line in "Compiler Settings" - "Other Options".
PERFORMANCE:
The game runs good at 200 Mhz.

View File

@ -1,85 +0,0 @@
Wolf4SDL\DC 1.7
ported to Dreamcast by dcbasic
A port of Wolf4SDL by Moritz "Ripper" Kroll.
What's new in 1.7:
- See Changes-dc.txt
Instructions:
- Extract the Wolf4SDL\DC archive to it's own folder.
- Put your *.wl6 files inside /cd/data/wolf3d (if you have a commercial CD-ROM
release of Wolfenstein you can skip this step).
- If you want to use the command line, create a text file called 'args.txt'
(without quotes) in the /cd/data/wolf3d folder and add any valid
arguments. Please keep them on one line.
- Download and install BootDreams (http://dchelp.dcemulation.org/?BootDreams).
- Open the folder you extracted Wolf4SDL\DC to in BootDreams.
- Select a task. If you'd like to burn Wolf4SDL\DC directly to a CD-R, select
the CDRecord task and set the disc format to either Audio\Data or Data\Data
(both do essentially the same thing).
- Click Process.
- If you created a CD image, burn it with the appropriate burning program
e.g. Alcohol 120%.
- Pop the CD-R in your Dreamcast and play.
- If you have a commercial CD-ROM, wait until you're asked to swap in your
copy of Wolfenstein 3D, swap your copy in, press start and play.
Valid Arguments:
--goobers (Wolfenstein 3D only)
--debugkeys (Spear of Destiny only)
--goodtimes (Spear of Destiny only)
--nowait
--baby
--easy
--normal
--hard
--tedlevel <level>
--res <width> <height> (default 320x200)
--resf <width> <height>
--bits <screen_bits> (default 8)
--dblbuf
--extravbls <vbls>
--samplerate <rate> (default 11025)
--audiobuffer <size> (default 4096)
Notes:
- The --res argument will also except '640 400' but will slow rendering down
greatly. The width must be a multiple of 320 and the height must be a
multiple of 200 or 240.
- The --resf argument will force the passed screen resolution but may result
in graphic corruption.
- The default samplerate is 11025 to keep the extra SOD missions from running
out of memory. Wolfenstein 3D and the original SOD mission will happily run
with the samplerate set to 22050.
- The --dblbuf argument works but slows speed down by about 10 frames.
Compiling:
This port was developed under Code::Blocks 8.02 with the DC Dev ISO R4
integrated within it. I've also included a Makefile in case you don't use
Code::Blocks. You will need SDL and SDL mixer to compile Wolf4SDL\DC.
DC Dev ISO can be downloaded from here:
http://dcemulation.org/?title=DC_Dev_ISO
It contains everything you need to compile Wolf4SDL. It includes Code::Blocks
8.02 and a tool to integrate Code::Blocks with DC Dev ISO. It uses Cygwin as
the terminal environment and includes the DC compilers and all the SDL
libraries that are needed to compile Wolf4SDL.
To compile Wolf4SDL\DC under Code::Blocks, extract the source to it's own
folder, open 'Wolf4SDL-DC.cbp' and goto 'Build' | 'Build'.
To compile Wolf4SDL\DC using the supplied Makefile, extract the source to it's
own directory in C:\cygwin\usr\local\dc and type 'make -f Makefile.dc' in your
terminal while inside the folder Wolf4SDL\DC was extracted to. By default the
Makefile will create a scrambled 1ST_READ.BIN, unscrambled Wolf4SDL.bin and of
course, Wolf4SDL.elf.
Credits & Thanks:
- OneThiryt8 for which parts of this port was based on his port, sdlWolf
- BlueCrab who wrote parts of the swap disc menu
- BlackAura for which I stole parts of his menu code from nxDoom
- Ripper for such a clean and friendly Wolfenstein 3D engine
- Bero for the Dreamcast port of SDL, which this port uses
- Dan Potter and team for KOS, which this port uses

View File

@ -1,43 +0,0 @@
This file explains how you can compile Wolf4SDL using Bloodshed's Dev-C++.
Keep in mind, that Dev-C++ is a dead project since 2005. The recommended way
to compile Wolf4SDL on Windows is using Visual Studio 2005 C++ or the free
Visual C++ 2005 Express. But for dial-up users Dev-C++ is probably still a
good option.
Needed files:
- "Dev-C++ 5.0 Beta 9.2 (4.9.9.2)" with Mingw/GCC 3.4.2 (about 9 MB)
http://www.bloodshed.net/dev/devcpp.html
- SDL-1.2.13-1chaos.DevPak (544 kB)
http://www.chaos-software.de.vu -> Downloads
- SDL_mixer-1.2.6-2mol.DevPak (347 kB)
http://sourceforge.net/project/showfiles.php?group_id=94270&package_id=151751
Installation:
- Install Dev-C++ to C:\Dev-Cpp
- Open Wolf4SDL.dev
- Go to "Tools" -> "Package Manager"
- Click on the "Install" button in the toolbar
- Select "SDL-1.2.13-1chaos.DevPak" (where ever you saved it)
- Some "Next" buttons and a "Finish" button later...
- Click on the "Install" button in the toolbar
- Select "SDL_mixer-1.2.6-2mol.DevPak" (where ever you saved it)
- Some "Next" buttons and a "Finish" button later...
- Close the Package Manager
Data file setup:
- Copy the data files (e.g. *.WL6) you want to use to the Wolf4SDL
source code folder
- If you want to use the data files of the full Activision version of
Wolfenstein 3D v1.4, you can just skip to the next section
- Otherwise open "version.h" and comment/uncomment the definitions
according to the description given in this file
Compiling Wolf4SDL:
- Compile via "Execute" -> "Compile"
- No errors should be displayed
- Run Wolf4SDL via "Execute" -> "Run"
Troubleshooting:
- If you get an error message "undefined reference to `__cpu_features_init'",
make sure, there is no c:\mingw folder. Otherwise Dev-C++ will mix different
versions of MinGW libraries...

View File

@ -1,86 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Wolf4SDL\DC" />
<Option pch_mode="2" />
<Option compiler="dreamcast_shelf_dependent" />
<Build>
<Target title="default">
<Option output="Wolf4SDL.elf" prefix_auto="0" extension_auto="0" />
<Option type="1" />
<Option compiler="dreamcast_shelf_dependent" />
<Option use_console_runner="0" />
<Compiler>
<Add directory="C:\cygwin\usr\local\dc\kos\kos-ports\include\SDL" />
</Compiler>
<Linker>
<Add option="-lSDL_mixer" />
<Add option="-lSDL" />
<Add option="-lm" />
<Add option="-lz" />
</Linker>
</Target>
</Build>
<Unit filename="audiosod.h" />
<Unit filename="audiowl6.h" />
<Unit filename="dc\dc_cd.cpp" />
<Unit filename="dc\dc_main.cpp" />
<Unit filename="dc\dc_main.h" />
<Unit filename="dc\dc_maple.cpp" />
<Unit filename="dc\dc_video.cpp" />
<Unit filename="dc\dc_vmu.cpp" />
<Unit filename="dc\dc_vmu.h" />
<Unit filename="f_spear.h" />
<Unit filename="fmopl.cpp" />
<Unit filename="fmopl.h" />
<Unit filename="foreign.h" />
<Unit filename="gfxv_apo.h" />
<Unit filename="gfxv_sod.h" />
<Unit filename="gfxv_wl6.h" />
<Unit filename="id_ca.cpp" />
<Unit filename="id_ca.h" />
<Unit filename="id_in.cpp" />
<Unit filename="id_in.h" />
<Unit filename="id_pm.cpp" />
<Unit filename="id_pm.h" />
<Unit filename="id_sd.cpp" />
<Unit filename="id_sd.h" />
<Unit filename="id_us.h" />
<Unit filename="id_us_1.cpp" />
<Unit filename="id_vh.cpp" />
<Unit filename="id_vh.h" />
<Unit filename="id_vl.cpp" />
<Unit filename="id_vl.h" />
<Unit filename="signon.cpp" />
<Unit filename="version.h" />
<Unit filename="wl_act1.cpp" />
<Unit filename="wl_act2.cpp" />
<Unit filename="wl_agent.cpp" />
<Unit filename="wl_atmos.cpp" />
<Unit filename="wl_atmos.h" />
<Unit filename="wl_cloudsky.cpp" />
<Unit filename="wl_cloudsky.h" />
<Unit filename="wl_debug.cpp" />
<Unit filename="wl_def.h" />
<Unit filename="wl_dir3dspr.cpp" />
<Unit filename="wl_draw.cpp" />
<Unit filename="wl_floorceiling.cpp" />
<Unit filename="wl_game.cpp" />
<Unit filename="wl_inter.cpp" />
<Unit filename="wl_main.cpp" />
<Unit filename="wl_menu.cpp" />
<Unit filename="wl_menu.h" />
<Unit filename="wl_parallax.cpp" />
<Unit filename="wl_play.cpp" />
<Unit filename="wl_shade.cpp" />
<Unit filename="wl_shade.h" />
<Unit filename="wl_state.cpp" />
<Unit filename="wl_text.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -1,71 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Wolf4SDL" />
<Option pch_mode="2" />
<Option compiler="devkitgp2x" />
<Build>
<Target title="default">
<Option output="Wolf4SDL" prefix_auto="1" extension_auto="1" />
<Option type="0" />
<Option compiler="devkitgp2x" />
</Target>
</Build>
<Compiler>
<Add option="-DGP2X" />
</Compiler>
<Linker>
<Add library="SDL" />
<Add library="SDL_mixer" />
<Add library="iconv" />
</Linker>
<Unit filename="GP2X/gp2x.cpp" />
<Unit filename="GP2X/gp2x.h" />
<Unit filename="audiosod.h" />
<Unit filename="audiowl6.h" />
<Unit filename="f_spear.h" />
<Unit filename="fmopl.cpp" />
<Unit filename="fmopl.h" />
<Unit filename="foreign.h" />
<Unit filename="gfxv_apo.h" />
<Unit filename="gfxv_sod.h" />
<Unit filename="gfxv_wl6.h" />
<Unit filename="id_ca.cpp" />
<Unit filename="id_ca.h" />
<Unit filename="id_in.cpp" />
<Unit filename="id_in.h" />
<Unit filename="id_pm.cpp" />
<Unit filename="id_sd.cpp" />
<Unit filename="id_sd.h" />
<Unit filename="id_us.h" />
<Unit filename="id_us_1.cpp" />
<Unit filename="id_vh.cpp" />
<Unit filename="id_vh.h" />
<Unit filename="id_vl.cpp" />
<Unit filename="id_vl.h" />
<Unit filename="sdl_winmain.cpp" />
<Unit filename="signon.cpp" />
<Unit filename="version.h" />
<Unit filename="wl_act1.cpp" />
<Unit filename="wl_act2.cpp" />
<Unit filename="wl_agent.cpp" />
<Unit filename="wl_debug.cpp" />
<Unit filename="wl_def.h" />
<Unit filename="wl_draw.cpp" />
<Unit filename="wl_game.cpp" />
<Unit filename="wl_inter.cpp" />
<Unit filename="wl_main.cpp" />
<Unit filename="wl_menu.cpp" />
<Unit filename="wl_menu.h" />
<Unit filename="wl_play.cpp" />
<Unit filename="wl_state.cpp" />
<Unit filename="wl_text.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -1,71 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Wolf4SDL" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="default">
<Option output="Wolf4SDL" prefix_auto="1" extension_auto="1" />
<Option type="0" />
<Option compiler="gcc" />
</Target>
</Build>
<Compiler>
<Add option="-Dmain=SDL_main" />
<Add directory="..\SDL-devel\include\SDL" />
</Compiler>
<Linker>
<Add library="mingw32" />
<Add library="SDL" />
<Add library="SDL_mixer" />
<Add directory="..\SDL-devel\lib" />
</Linker>
<Unit filename="audiosod.h" />
<Unit filename="audiowl6.h" />
<Unit filename="f_spear.h" />
<Unit filename="fmopl.cpp" />
<Unit filename="fmopl.h" />
<Unit filename="foreign.h" />
<Unit filename="gfxv_apo.h" />
<Unit filename="gfxv_sod.h" />
<Unit filename="gfxv_wl6.h" />
<Unit filename="id_ca.cpp" />
<Unit filename="id_ca.h" />
<Unit filename="id_in.cpp" />
<Unit filename="id_in.h" />
<Unit filename="id_pm.cpp" />
<Unit filename="id_sd.cpp" />
<Unit filename="id_sd.h" />
<Unit filename="id_us.h" />
<Unit filename="id_us_1.cpp" />
<Unit filename="id_vh.cpp" />
<Unit filename="id_vh.h" />
<Unit filename="id_vl.cpp" />
<Unit filename="id_vl.h" />
<Unit filename="sdl_winmain.cpp" />
<Unit filename="signon.cpp" />
<Unit filename="version.h" />
<Unit filename="wl_act1.cpp" />
<Unit filename="wl_act2.cpp" />
<Unit filename="wl_agent.cpp" />
<Unit filename="wl_debug.cpp" />
<Unit filename="wl_def.h" />
<Unit filename="wl_draw.cpp" />
<Unit filename="wl_game.cpp" />
<Unit filename="wl_inter.cpp" />
<Unit filename="wl_main.cpp" />
<Unit filename="wl_menu.cpp" />
<Unit filename="wl_menu.h" />
<Unit filename="wl_play.cpp" />
<Unit filename="wl_state.cpp" />
<Unit filename="wl_text.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -1,16 +0,0 @@
//Wolf4SDL\DC
//dc_cd.cpp
//2009 - Cyle Terry
#if defined(_arch_dreamcast)
#include "dc/cdrom.h"
int DC_CheckDrive() {
int disc_status;
int disc_type;
cdrom_get_status(&disc_status, &disc_type);
return disc_status;
}
#endif

View File

@ -1,377 +0,0 @@
//Wolf4SDL\DC
//dc_main.cpp
//2009 - Cyle Terry
#if defined(_arch_dreamcast)
//TODO: Use Port A Only
#include <string.h>
#include "../wl_def.h"
#include "dc/video.h"
#include "kos/dbglog.h"
#include "kos/fs.h"
#include "zlib/zlib.h"
char dcwolf3dpath[1024];
void DC_CheckArguments() {
FILE *fp;
char *buf;
char *result = NULL;
bool sampleRateGiven = false;
bool audioBufferGiven = false;
int length = 0;
fp = fopen("/cd/data/wolf3d/args.txt", "r");
if (!fp)
return;
fseek(fp, 0, SEEK_END);
length = ftell (fp);
fseek(fp, 0, SEEK_SET);
buf = (char *)malloc(length + 2);
fread(buf, 1, length, fp);
buf[length] = 0;
fclose(fp);
result = strtok(buf, " ");
while (result != NULL) {
#ifndef SPEAR
if (!strcmp(result, "--goobers"))
#else
if (!strcmp(result, "--debugmode"))
#endif
param_debugmode = true;
else if (!strcmp(result, "--baby"))
param_difficulty = 0;
else if (!strcmp(result, "--easy"))
param_difficulty = 1;
else if (!strcmp(result, "--normal"))
param_difficulty = 2;
else if (!strcmp(result, "--hard"))
param_difficulty = 3;
else if (!strcmp(result, "--nowait"))
param_nowait = true;
else if (!strcmp(result, "--tedlevel")) {
result = strtok(NULL, " ");
param_tedlevel = atoi(result);
} else if (!strcmp(result, "--res")) {
result = strtok(NULL, " ");
screenWidth = atoi(result);
result = strtok(NULL, " ");
screenHeight = atoi(result);
if ( screenWidth % 320 && screenHeight % 200) {
dbglog(DBG_DEBUG, "Screen height\\width must be a multiple of 320x200\n");
dbglog(DBG_DEBUG, "Defaulting to 320x200\n");
screenWidth = 320;
screenHeight = 200;
}
} else if (!strcmp(result, "--resf")) {
result = strtok(NULL, " ");
screenWidth = atoi(result);
result = strtok(NULL, " ");
screenHeight = atoi(result);
if (screenWidth < 320 && screenHeight < 200) {
dbglog(DBG_DEBUG, "Screen height\\width must be at least 320x200\n");
dbglog(DBG_DEBUG, "Defaulting to 320x200\n");
screenWidth = 320;
screenHeight = 200;
}
} else if (!strcmp(result, "--bits")) {
result = strtok(NULL, " ");
screenBits = atoi(result);
switch (screenBits) {
case 8:
case 16:
case 24:
case 32:
break;
default:
dbglog(DBG_DEBUG, "Screen bits must be either 8, 16, 24 or 32\n");
dbglog(DBG_DEBUG, "Defaulting to 8\n");
screenBits = 8;
break;
}
result = strtok(NULL, " ");
param_samplerate = atoi(result);
sampleRateGiven = true;
} else if (!strcmp(result, "--dblbuf")) { //Was --nodblbuf
usedoublebuffering = true;
} else if (!strcmp(result, "--extravbls")) {
result = strtok(NULL, " ");
extravbls = atoi(result);
if(extravbls < 0) {
dbglog(DBG_DEBUG, "Extravbls must be positive!\n");
dbglog(DBG_DEBUG, "Defaulting to 0\n");
extravbls = 0;
}
} else if (!strcmp(result, "--samplerate")) {
result = strtok(NULL, " ");
param_samplerate = atoi(result);
sampleRateGiven = true;
} else if (!strcmp(result, "--audiobuffer")) {
result = strtok(NULL, " ");
param_audiobuffer = atoi(result);
audioBufferGiven = true;
} else if (!strcmp(result, "--goodtimes"))
param_goodtimes = true;
result = strtok(NULL, " ");
}
free(buf);
if (sampleRateGiven && !audioBufferGiven)
param_audiobuffer = 4096 / (44100 / param_samplerate);
}
int DC_CheckForMaps(char *path) {
file_t dir;
dirent_t *dirent;
char fpath[1024];
int disc_status;
for(;;) {
SDL_Delay(5);
disc_status = DC_CheckDrive();
#ifdef SPEAR
DC_DrawString(4, 1, "Sod4SDL\\DC");
#else
DC_DrawString(4, 1, "Wolf4SDL\\DC");
#endif
switch(disc_status) {
//case CD_STATUS_BUSY:
//case CD_STATUS_OPEN:
// DC_DrawString(4, 6, "Please insert your Wolfenstein 3D CD.");
// break;
default:
dir = fs_open(path, O_DIR);
while(dirent = fs_readdir(dir)) {
#ifdef SPEAR
#ifdef SPEARDEMO
if(!strcmp(dirent->name, "AUDIOHED.SDM")) {
fs_close(dir);
strcpy(dcwolf3dpath, path);
return 0;
}
#else
if(!strcmp(dirent->name, "AUDIOHED.SOD")) {
fs_close(dir);
strcpy(dcwolf3dpath, path);
param_mission = DC_SetMission(path);
return 0;
}
#endif
#else
#ifdef UPLOAD
if(!strcmp(dirent->name, "AUDIOHED.WL1")) {
fs_close(dir);
strcpy(dcwolf3dpath, path);
return 0;
}
#else
if(!strcmp(dirent->name, "AUDIOHED.WL6")) {
fs_close(dir);
strcpy(dcwolf3dpath, path);
return 0;
}
#endif
#endif
strcpy(fpath, path);
sprintf(fpath, "%s/%s", fpath, dirent->name);
DC_CheckForMaps(fpath);
}
fs_close(dir);
return -1;
}
DC_Flip();
}
}
void DC_LoadMaps() {
DC_CheckForMaps("/cd");
DC_CLS();
fs_chdir(dcwolf3dpath);
#ifdef SPEAR
#ifndef SPEARDEMO
fs_copy("audiohed.sod", "/ram/audiohed.sod");
fs_copy("audiot.sod", "/ram/audiot.sod");
fs_copy("vgadict.sod", "/ram/vgadict.sod");
fs_copy("vgagraph.sod", "/ram/vgagraph.sod");
fs_copy("vgahead.sod", "/ram/vgahead.sod");
switch(param_mission) {
case 0:
fs_copy("gamemaps.sod", "/ram/gamemaps.sod");
fs_copy("maphead.sod", "/ram/maphead.sod");
fs_copy("vswap.sod", "/ram/vswap.sod");
break;
case 1:
fs_copy("gamemaps.sd1", "/ram/gamemaps.sd1");
fs_copy("maphead.sd1", "/ram/maphead.sd1");
fs_copy("vswap.sd1", "/ram/vswap.sd1");
break;
case 2:
fs_copy("gamemaps.sd2", "/ram/gamemaps.sd2");
fs_copy("maphead.sd2", "/ram/maphead.sd2");
fs_copy("vswap.sd2", "/ram/vswap.sd2");
break;
case 3:
fs_copy("gamemaps.sd3", "/ram/gamemaps.sd3");
fs_copy("maphead.sd3", "/ram/maphead.sd3");
fs_copy("vswap.sd3", "/ram/vswap.sd3");
break;
}
#else
fs_copy("audiohed.sdm", "/ram/audiohed.sdm");
fs_copy("audiot.sdm", "/ram/audiot.sdm");
fs_copy("vgadict.sdm", "/ram/vgadict.sdm");
fs_copy("vgagraph.sdm", "/ram/vgagraph.sdm");
fs_copy("vgahead.sdm", "/ram/vgahead.sdm");
fs_copy("gamemaps.sdm", "/ram/gamemaps.sdm");
fs_copy("maphead.sdm", "/ram/maphead.sdm");
fs_copy("vswap.sdm", "/ram/vswap.sdm");
#endif
#else
#ifndef UPLOAD
fs_copy("audiohed.wl6", "/ram/audiohed.wl6");
fs_copy("audiot.wl6", "/ram/audiot.wl6");
fs_copy("vgadict.wl6", "/ram/vgadict.wl6");
fs_copy("vgagraph.wl6", "/ram/vgagraph.wl6");
fs_copy("vgahead.wl6", "/ram/vgahead.wl6");
fs_copy("gamemaps.wl6", "/ram/gamemaps.wl6");
fs_copy("maphead.wl6", "/ram/maphead.wl6");
fs_copy("vswap.wl6", "/ram/vswap.wl6");
#else
fs_copy("audiohed.wl1", "/ram/audiohed.wl1");
fs_copy("audiot.wl1", "/ram/audiot.wl1");
fs_copy("vgadict.wl1", "/ram/vgadict.wl1");
fs_copy("vgagraph.wl1", "/ram/vgagraph.wl1");
fs_copy("vgahead.wl1", "/ram/vgahead.wl1");
fs_copy("gamemaps.wl1", "/ram/gamemaps.wl1");
fs_copy("maphead.wl1", "/ram/maphead.wl1");
fs_copy("vswap.wl1", "/ram/vswap.wl1");
#endif
#endif
fs_chdir("/ram");
}
void DC_Init() {
DC_CheckArguments();
DC_VideoInit();
DC_LoadMaps();
DC_CLS();
}
#ifdef SPEAR
#ifndef SPEARDEMO
int DC_SetMission(char *path) {
int mission1 = 0;
int mission2 = 0;
int mission3 = 0;
int missions = 0;
int last_mission = 0;
int current_mission = 0;
int previous_mission = 0;
int font_y = 0;
char fname[1024];
bool finished = false;
FILE *fp;
sprintf(fname, "%s/MAPHEAD.SOD", path);
fp = fopen(fname, "r");
if(fp) {
fclose(fp);
last_mission = 1;
mission1 = 1;
missions++;
}
sprintf(fname, "%s/MAPHEAD.SD2", path);
fp = fopen(fname, "r");
if(fp) {
fclose(fp);
last_mission = 2;
mission2 = 1;
missions++;
}
sprintf(fname, "%s/MAPHEAD.SD3", path);
fp = fopen(fname, "r");
if(fp) {
fclose(fp);
last_mission = 3;
mission3 = 1;
missions++;
}
if(missions > 1) {
while(!finished) {
SDL_Delay(5);
DC_CLS();
DC_DrawString(2, 6 + current_mission, ">");
font_y = 6;
DC_DrawString(4, 1, "Sod4SDL\\DC");
if(mission1 == 1) {
DC_DrawString(4, font_y, "Spear of Destiny (Original Mission)");
font_y++;
}
if(mission2 == 1) {
DC_DrawString(4, font_y, "Mission 2 - Return to Danger");
font_y++;
}
if(mission3 == 1) {
DC_DrawString(4, font_y, "Mission 3 - Ultimate Challenge");
font_y++;
}
if(DC_ButtonPress(CONT_A)) {
finished = true;
break;
} else if(DC_ButtonPress(CONT_DPAD_DOWN)) {
current_mission++;
previous_mission = -1;
if(current_mission > (missions - 1))
current_mission = 0;
DC_WaitButtonRelease(CONT_DPAD_DOWN);
} else if(DC_ButtonPress(CONT_DPAD_UP)) {
current_mission--;
previous_mission = -1;
if(current_mission < 0)
current_mission = missions - 1;
DC_WaitButtonRelease(CONT_DPAD_UP);
}
DC_Flip();
}
/* Return Selected Mission */
// XXX: What does this do? Are the fall throughs intended?!
switch(current_mission) {
case 1:
if(mission1) return 1;
if(mission2 && !mission1) return 2;
case 2:
if(mission2 && mission1) return 2;
if(mission3 && mission1 && !mission2) return 3;
if(mission3 && mission2 && !mission1) return 3;
case 3:
if(mission3 && mission2 && mission1) return 3;
}
}
return last_mission;
}
#endif
#endif
#endif

View File

@ -1,49 +0,0 @@
//Wolf4SDL\DC
//dc_main.h
//2009 - Cyle Terry
#ifndef __DC_MAIN_H_
#define __DC_MAIN_H_
typedef uint8 uint8_t;
typedef uint16 uint16_t;
typedef uint32 uint32_t;
typedef int8 int8_t;
typedef int16 int16_t;
typedef int32 int32_t;
typedef int64 int64_t;
typedef ptr_t uintptr_t;
//dc_cd.cpp
int DC_CheckDrive();
//dc_main.cpp
void DC_Init();
void DC_CheckArguments();
int DC_CheckForMaps(char *path);
#ifdef SPEAR
#ifndef SPEARDEMO
int DC_SetMission(char *path);
#endif
#endif
//dc_maple.cpp
int DC_ButtonPress(int button);
int DC_MousePresent();
void DC_WaitButtonPress(int button);
void DC_WaitButtonRelease(int button);
//dc_video.cpp
void DC_VideoInit();
void DC_DrawString(int x, int y, char *str);
void DC_CLS();
void DC_Flip();
//dc_vmu.cpp
extern void DiskFlopAnim(int x, int y);
void DC_StatusDrawLCD(int index);
void DC_StatusClearLCD();
void DC_SaveToVMU(char *fname, char *str);
int DC_LoadFromVMU(char *fname);
#endif

View File

@ -1,60 +0,0 @@
//Wolf4SDL\DC
//dc_maple.cpp
//2009 - Cyle Terry
#if defined(_arch_dreamcast)
#include <SDL.h>
#include "dc/maple.h"
#include "dc/maple/controller.h"
#include "dc/maple/vmu.h"
int DC_MousePresent() {
return maple_first_mouse() != 0;
}
void DC_WaitButtonPress(int button)
{
int first_controller = 0;
cont_cond_t controller_condition;
first_controller = maple_first_controller();
cont_get_cond(first_controller, &controller_condition);
while((controller_condition.buttons & button)) {
SDL_Delay(5);
cont_get_cond(first_controller, &controller_condition);
}
}
void DC_WaitButtonRelease(int button)
{
int first_controller = 0;
cont_cond_t controller_condition;
first_controller = maple_first_controller();
cont_get_cond(first_controller, &controller_condition);
while(!(controller_condition.buttons & button)) {
SDL_Delay(5);
cont_get_cond(first_controller, &controller_condition);
}
}
int DC_ButtonPress(int button)
{
int first_controller = 0;
cont_cond_t controller_condition;
first_controller = maple_first_controller();
cont_get_cond(first_controller, &controller_condition);
if(!(controller_condition.buttons & button))
return 1;
else
return 0;
}
#endif

View File

@ -1,37 +0,0 @@
//Wolf4SDL\DC
//dc_video.cpp
//2009 - Cyle Terry
#if defined(_arch_dreamcast)
#include <string.h>
#include <malloc.h>
#include "../wl_def.h"
#include "dc/biosfont.h"
#include "dc/video.h"
static uint16 *bbuffer;
void DC_VideoInit() {
bbuffer = (uint16 *)malloc(640 * 480 * 2);
DC_CLS();
}
void DC_DrawString(int x, int y, char *str) {
bfont_draw_str(bbuffer + ((y + 1) * 24 * 640) + (x * 12), 640, 0, str);
}
void DC_Flip() {
memcpy(vram_s, bbuffer, 640 * 480 * 2);
}
void DC_CLS() {
int x, y, ofs;
for(y = 0; y < 480; y++) {
ofs = (640 * y);
for(x = 0; x < 640; x++)
bbuffer[ofs + x] = 0;
}
}
#endif

View File

@ -1,181 +0,0 @@
//Wolf4SDL\DC
//dc_vmu.cpp
//2009 - Cyle Terry
#if defined(_arch_dreamcast)
#include <string.h>
#include "../wl_def.h"
#include "dc/maple.h"
#include "dc/maple/controller.h"
#include "dc/maple/vmu.h"
#include "dc/vmu_pkg.h"
#include "kos/fs.h"
#include "zlib/zlib.h"
#include "dc_vmu.h"
maple_device_t *vmu_lcd_addr[8];
void DC_StatusDrawLCD(int lcd) {
const char *character;
int x, y;
int xi, xb;
int i = 0;
uint8 bitmap[48 * 32 / 8];
maple_device_t *vmu_lcd_addr;
memset(bitmap, 0, sizeof(bitmap));
character = e_BJFaces[lcd - FACE1APIC];
if(character) {
for(y = 0; y < LCD_HEIGHT; y++) {
for(x = 0; x < LCD_WIDTH; x++) {
xi = x / 8;
xb = 0x80 >> (x % 8);
if(character[(31 - y) * 48 + (47 - x)] == '.')
bitmap[y * (48 / 8) + xi] |= xb;
}
}
}
while ((vmu_lcd_addr = maple_enum_type(i++, MAPLE_FUNC_LCD)))
vmu_draw_lcd(vmu_lcd_addr, bitmap);
vmu_shutdown ();
}
void DC_StatusClearLCD() {
int x, y;
int xi;
int i = 0;
uint8 bitmap[48 * 32 / 8];
maple_device_t *vmu_lcd_addr;
memset(bitmap, 0, sizeof(bitmap));
for(y = 0; y < LCD_HEIGHT; y++) {
for(x = 0; x < LCD_WIDTH; x++) {
xi = x / 8;
bitmap[y * (48 / 8) + xi] |= 0;
}
}
while ((vmu_lcd_addr = maple_enum_type(i++, MAPLE_FUNC_LCD)))
vmu_draw_lcd(vmu_lcd_addr, bitmap);
vmu_shutdown ();
}
void DC_SaveToVMU(char *fname, char *str) {
char destination[32];
int filesize = 0;
int vmu_package_size;
unsigned long zipsize = 0;
unsigned char *vmu_package_out;
unsigned char *data;
unsigned char *zipdata;
file_t file;
vmu_pkg_t vmu_package;
DiskFlopAnim(102, 85);
strcpy(destination, "/vmu/a1/");
strcat(destination, fname);
file = fs_open(fname, O_RDONLY);
filesize = fs_total(file);
data = (unsigned char*)malloc(filesize);
fs_read(file, data, filesize);
fs_close(file);
DiskFlopAnim(102, 85);
zipsize = filesize * 2;
zipdata = (unsigned char*)malloc(zipsize);
compress(zipdata, &zipsize, data, filesize);
DiskFlopAnim(102, 85);
#ifdef SPEAR
strcpy(vmu_package.desc_short, "Sod4SDL\\DC");
strcpy(vmu_package.app_id, "Sod4SDL\\DC");
#else
strcpy(vmu_package.desc_short, "Wolf4SDL\\DC");
strcpy(vmu_package.app_id, "Wolf4SDL\\DC");
#endif
if(str == NULL)
strcpy(vmu_package.desc_long, "Configuration");
else {
strcpy(vmu_package.desc_long, "Game Save - ");
strcat(vmu_package.desc_long, str);
}
vmu_package.icon_cnt = 1;
vmu_package.icon_anim_speed = 0;
memcpy(&vmu_package.icon_pal[0], vmu_bios_save_icon, 32);
vmu_package.icon_data = vmu_bios_save_icon + 32;
vmu_package.eyecatch_type = VMUPKG_EC_NONE;
vmu_package.data_len = zipsize;
vmu_package.data = zipdata;
vmu_pkg_build(&vmu_package, &vmu_package_out, &vmu_package_size);
DiskFlopAnim(102, 85);
fs_unlink(destination);
file = fs_open(destination, O_WRONLY);
fs_write(file, vmu_package_out, vmu_package_size);
fs_close(file);
DiskFlopAnim(102, 85);
free(vmu_package_out);
free(data);
free(zipdata);
}
int DC_LoadFromVMU(char *fname) {
char fpath[64];
int file;
int filesize;
unsigned long unzipsize;
unsigned char *data;
unsigned char *unzipdata;
vmu_pkg_t vmu_package;
sprintf(fpath, "/vmu/a1/%s", fname);
file = fs_open(fpath, O_RDONLY);
if(file == 0) return 0;
filesize = fs_total(file);
if(filesize <= 0) return 0;
data = (unsigned char*)malloc(filesize);
fs_read(file, data, filesize);
fs_close(file);
if(!strcmp(fname, configname))
DiskFlopAnim(102, 85);
vmu_pkg_parse(data, &vmu_package);
if(!strcmp(fname, configname))
DiskFlopAnim(102, 85);
unzipdata = (unsigned char*)malloc(65536);
unzipsize = 65536;
uncompress(unzipdata, &unzipsize, (unsigned char*)vmu_package.data, vmu_package.data_len);
if(!strcmp(fname, configname))
DiskFlopAnim(102, 85);
fs_unlink(fname);
file = fs_open(fname, O_WRONLY);
fs_write(file, unzipdata, unzipsize);
fs_close(file);
if(!strcmp(fname, configname))
DiskFlopAnim(102, 85);
free(data);
free(unzipdata);
return 1;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -115,7 +115,7 @@ void VW_MeasurePropString (const char *string, word *width, word *height)
void VH_UpdateScreen()
{
SDL_BlitSurface(screenBuffer, NULL, screen, NULL);
SDL_BlitSurface(screenBuffer, NULL, screen, NULL);
SDL_Flip(screen);
}
@ -356,7 +356,7 @@ boolean FizzleFade (SDL_Surface *source, int x1, int y1,
if(abortable && IN_CheckAck ())
{
VL_UnlockSurface(source);
SDL_BlitSurface(source, NULL, screen, NULL);
SDL_BlitSurface(screenBuffer, NULL, screen, NULL);
SDL_Flip(screen);
return true;
}
@ -429,7 +429,7 @@ boolean FizzleFade (SDL_Surface *source, int x1, int y1,
finished:
VL_UnlockSurface(source);
VL_UnlockSurface(screen);
SDL_BlitSurface(source, NULL, screen, NULL);
SDL_BlitSurface(screenBuffer, NULL, screen, NULL);
SDL_Flip(screen);
return false;
}

View File

@ -20,8 +20,8 @@ boolean fullscreen = true;
boolean usedoublebuffering = true;
unsigned screenWidth = 640;
unsigned screenHeight = 400;
unsigned screenWidth = 320;
unsigned screenHeight = 200;
unsigned screenBits = -1; // use "best" color depth according to libSDL
@ -129,7 +129,8 @@ void VL_SetVGAPlaneMode (void)
scaleFactor = screenWidth/320;
if(screenHeight/200 < scaleFactor) scaleFactor = screenHeight/200;
pixelangle = (short *) malloc(screenWidth * sizeof(short));
CHECKMALLOCRESULT(pixelangle);
wallheight = (int *) malloc(screenWidth * sizeof(int));
@ -207,7 +208,7 @@ void VL_SetColor (int color, int red, int green, int blue)
else
{
SDL_SetPalette(curSurface, SDL_LOGPAL, &col, color, 1);
SDL_BlitSurface(curSurface, NULL, screen, NULL);
SDL_BlitSurface(screenBuffer, NULL, screen, NULL);
SDL_Flip(screen);
}
}
@ -251,7 +252,7 @@ void VL_SetPalette (SDL_Color *palette, bool forceupdate)
SDL_SetPalette(curSurface, SDL_LOGPAL, palette, 0, 256);
if(forceupdate)
{
SDL_BlitSurface(curSurface, NULL, screen, NULL);
SDL_BlitSurface(screenBuffer, NULL, screen, NULL);
SDL_Flip(screen);
}
}

View File

@ -985,9 +985,12 @@ void VictoryTile (void)
static fixed FixedByFracOrig(fixed a, fixed b)
{
int sign = 0;
if(b == 65536) b = 65535;
else if(b == -65536) b = 65535, sign = 1;
else if(b < 0) b = (-b), sign = 1;
if(b == 65536)
b = 65535;
else
if(b == -65536) b = 65535, sign = 1;
else
if(b < 0) b = (-b), sign = 1;
if(a < 0)
{
@ -995,6 +998,7 @@ static fixed FixedByFracOrig(fixed a, fixed b)
sign = !sign;
}
fixed res = (fixed)(((int64_t) a * b) >> 16);
if(sign)
res = -res;
return res;

View File

@ -1589,6 +1589,7 @@ void ThreeDRefresh (void)
US_Print(" fps");
}
#endif
SDL_BlitSurface(screenBuffer, NULL, screen, NULL);
SDL_Flip(screen);
}