diff --git a/GP2X/fmopl.cpp b/GP2X/fmopl.cpp deleted file mode 100644 index 497bbc5..0000000 --- a/GP2X/fmopl.cpp +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include - -#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<= 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>= 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; i0.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>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<freqbase); - - /* Vibrato: 8 output levels (triangle waveform); 1 level takes 1024 samples */ - OPLs->lfo_pm_inc = (UINT32)((1.0 / 1024.0) * (1<freqbase); - - /* Noise generator: a step takes 1 sample */ - OPLs->noise_f = (UINT32)((1.0 / 1.0) * (1<freqbase); - - OPLs->eg_timer_add = (UINT32)((1<freqbase); - OPLs->eg_timer_overflow = ( 1 ) * (1<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 MAXOUT ) temp = MAXOUT; - if( temp < MINOUT ) temp = MINOUT; - - return (INT16)temp; -} - -#endif /* BUILD_YM3812 */ diff --git a/GP2X/fmopl.h b/GP2X/fmopl.h deleted file mode 100644 index f5e654d..0000000 --- a/GP2X/fmopl.h +++ /dev/null @@ -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 diff --git a/GP2X/fmopl_940/Makefile b/GP2X/fmopl_940/Makefile deleted file mode 100644 index 377aec1..0000000 --- a/GP2X/fmopl_940/Makefile +++ /dev/null @@ -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 diff --git a/GP2X/fmopl_940/fmopl_core.c b/GP2X/fmopl_940/fmopl_core.c deleted file mode 100644 index 6a91a74..0000000 --- a/GP2X/fmopl_940/fmopl_core.c +++ /dev/null @@ -1,1532 +0,0 @@ -#include "fmopl_core.h" -#include "fmopl_shared.h" - -#define INLINE static -#define NOINLINE - -/* 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<>4) - -/* LFO Amplitude Modulation table (verified on real YM3812) - 27 output levels (triangle waveform); 1 level takes one of: 192, 256 or 448 samples - - Length: 210 elements. - - Each of the elements has to be repeated - exactly 64 times (on 64 consecutive samples). - The whole table takes: 64 * 210 = 13440 samples. - - When AM = 1 data is used directly - When AM = 0 data is divided by 4 before being used (loosing precision is important) -*/ - -#define LFO_AM_TAB_ELEMENTS 210 - -static const UINT8 lfo_am_table[LFO_AM_TAB_ELEMENTS] = { -0,0,0,0,0,0,0, -1,1,1,1, -2,2,2,2, -3,3,3,3, -4,4,4,4, -5,5,5,5, -6,6,6,6, -7,7,7,7, -8,8,8,8, -9,9,9,9, -10,10,10,10, -11,11,11,11, -12,12,12,12, -13,13,13,13, -14,14,14,14, -15,15,15,15, -16,16,16,16, -17,17,17,17, -18,18,18,18, -19,19,19,19, -20,20,20,20, -21,21,21,21, -22,22,22,22, -23,23,23,23, -24,24,24,24, -25,25,25,25, -26,26,26, -25,25,25,25, -24,24,24,24, -23,23,23,23, -22,22,22,22, -21,21,21,21, -20,20,20,20, -19,19,19,19, -18,18,18,18, -17,17,17,17, -16,16,16,16, -15,15,15,15, -14,14,14,14, -13,13,13,13, -12,12,12,12, -11,11,11,11, -10,10,10,10, -9,9,9,9, -8,8,8,8, -7,7,7,7, -6,6,6,6, -5,5,5,5, -4,4,4,4, -3,3,3,3, -2,2,2,2, -1,1,1,1 -}; - -/* LFO Phase Modulation table (verified on real YM3812) */ -static const INT8 lfo_pm_table[8*8*2] = { - -/* FNUM2/FNUM = 00 0xxxxxxx (0x0000) */ -0, 0, 0, 0, 0, 0, 0, 0, /*LFO PM depth = 0*/ -0, 0, 0, 0, 0, 0, 0, 0, /*LFO PM depth = 1*/ - -/* FNUM2/FNUM = 00 1xxxxxxx (0x0080) */ -0, 0, 0, 0, 0, 0, 0, 0, /*LFO PM depth = 0*/ -1, 0, 0, 0,-1, 0, 0, 0, /*LFO PM depth = 1*/ - -/* FNUM2/FNUM = 01 0xxxxxxx (0x0100) */ -1, 0, 0, 0,-1, 0, 0, 0, /*LFO PM depth = 0*/ -2, 1, 0,-1,-2,-1, 0, 1, /*LFO PM depth = 1*/ - -/* FNUM2/FNUM = 01 1xxxxxxx (0x0180) */ -1, 0, 0, 0,-1, 0, 0, 0, /*LFO PM depth = 0*/ -3, 1, 0,-1,-3,-1, 0, 1, /*LFO PM depth = 1*/ - -/* FNUM2/FNUM = 10 0xxxxxxx (0x0200) */ -2, 1, 0,-1,-2,-1, 0, 1, /*LFO PM depth = 0*/ -4, 2, 0,-2,-4,-2, 0, 2, /*LFO PM depth = 1*/ - -/* FNUM2/FNUM = 10 1xxxxxxx (0x0280) */ -2, 1, 0,-1,-2,-1, 0, 1, /*LFO PM depth = 0*/ -5, 2, 0,-2,-5,-2, 0, 2, /*LFO PM depth = 1*/ - -/* FNUM2/FNUM = 11 0xxxxxxx (0x0300) */ -3, 1, 0,-1,-3,-1, 0, 1, /*LFO PM depth = 0*/ -6, 3, 0,-3,-6,-3, 0, 3, /*LFO PM depth = 1*/ - -/* FNUM2/FNUM = 11 1xxxxxxx (0x0380) */ -3, 1, 0,-1,-3,-1, 0, 1, /*LFO PM depth = 0*/ -7, 3, 0,-3,-7,-3, 0, 3 /*LFO PM depth = 1*/ -}; - -static int cur_chip = -1; /* current chip pointer */ -static OPL_SLOT *SLOT7_1, *SLOT7_2, *SLOT8_1, *SLOT8_2; - -static signed int phase_modulation[1]; /* phase modulation input (SLOT 2) */ -static signed int output[1]; - -static UINT32 LFO_AM; -static INT32 LFO_PM; - -INLINE int limit( int val, int max, int min ) { - if ( val > max ) - val = max; - else if ( val < min ) - val = 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) */ - } - } -} - -/* 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) */ - } - } -} - -/* 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); -} - -/* advance LFO to next sample */ -INLINE void advance_lfo(FM_OPL *OPL) -{ - UINT8 tmp; - - /* LFO */ - OPL->lfo_am_cnt += OPL->lfo_am_inc; - if( (int) OPL->lfo_am_cnt >= (LFO_AM_TAB_ELEMENTS<lfo_am_cnt -= (LFO_AM_TAB_ELEMENTS<lfo_am_cnt >> LFO_SH ]; - - if (OPL->lfo_am_depth) - LFO_AM = tmp; - else - LFO_AM = tmp>>2; - - OPL->lfo_pm_cnt += OPL->lfo_pm_inc; - LFO_PM = ((OPL->lfo_pm_cnt>>LFO_SH) & 7) | OPL->lfo_pm_depth_range; -} - -/* advance to next sample */ -INLINE void advance(FM_OPL *OPL) -{ - OPL_CH *CH; - OPL_SLOT *op; - int i; - - OPL->eg_timer += OPL->eg_timer_add; - - while (OPL->eg_timer >= OPL->eg_timer_overflow) - { - OPL->eg_timer -= OPL->eg_timer_overflow; - - OPL->eg_cnt++; - - for (i=0; i<9*2; i++) - { - CH = &OPL->P_CH[i/2]; - op = &CH->SLOT[i&1]; - - /* Envelope Generator */ - switch(op->state) - { - case EG_ATT: /* attack phase */ - if ( !(OPL->eg_cnt & ((1<eg_sh_ar)-1) ) ) - { - op->volume += (~op->volume * - (eg_inc[op->eg_sel_ar + ((OPL->eg_cnt>>op->eg_sh_ar)&7)]) - ) >>3; - - if (op->volume <= MIN_ATT_INDEX) - { - op->volume = MIN_ATT_INDEX; - op->state = EG_DEC; - } - - } - break; - - case EG_DEC: /* decay phase */ - if ( !(OPL->eg_cnt & ((1<eg_sh_dr)-1) ) ) - { - op->volume += eg_inc[op->eg_sel_dr + ((OPL->eg_cnt>>op->eg_sh_dr)&7)]; - - if ( (UINT32) op->volume >= op->sl ) - op->state = EG_SUS; - - } - break; - - case EG_SUS: /* sustain phase */ - - /* this is important behaviour: - one can change percusive/non-percussive modes on the fly and - the chip will remain in sustain phase - verified on real YM3812 */ - - if(op->eg_type) /* non-percussive mode */ - { - /* do nothing */ - } - else /* percussive mode */ - { - /* during sustain phase chip adds Release Rate (in percussive mode) */ - if ( !(OPL->eg_cnt & ((1<eg_sh_rr)-1) ) ) - { - op->volume += eg_inc[op->eg_sel_rr + ((OPL->eg_cnt>>op->eg_sh_rr)&7)]; - - if ( op->volume >= MAX_ATT_INDEX ) - op->volume = MAX_ATT_INDEX; - } - /* else do nothing in sustain phase */ - } - break; - - case EG_REL: /* release phase */ - if ( !(OPL->eg_cnt & ((1<eg_sh_rr)-1) ) ) - { - op->volume += eg_inc[op->eg_sel_rr + ((OPL->eg_cnt>>op->eg_sh_rr)&7)]; - - if ( op->volume >= MAX_ATT_INDEX ) - { - op->volume = MAX_ATT_INDEX; - op->state = EG_OFF; - } - - } - break; - - default: - break; - } - } - } - - for (i=0; i<9*2; i++) - { - CH = &OPL->P_CH[i/2]; - op = &CH->SLOT[i&1]; - - /* Phase Generator */ - if(op->vib) - { - UINT8 block; - unsigned int block_fnum = CH->block_fnum; - - unsigned int fnum_lfo = (block_fnum&0x0380) >> 7; - - signed int lfo_fn_table_index_offset = lfo_pm_table[LFO_PM + 16*fnum_lfo ]; - - if (lfo_fn_table_index_offset) /* LFO phase modulation active */ - { - block_fnum += lfo_fn_table_index_offset; - block = (block_fnum&0x1c00) >> 10; - op->Cnt += (OPL->fn_tab[block_fnum&0x03ff] >> (7-block)) * op->mul; - } - else /* LFO phase modulation = zero */ - { - op->Cnt += op->Incr; - } - } - else /* LFO phase modulation disabled for this operator */ - { - op->Cnt += op->Incr; - } - } - - /* The Noise Generator of the YM3812 is 23-bit shift register. - * Period is equal to 2^23-2 samples. - * Register works at sampling frequency of the chip, so output - * can change on every sample. - * - * Output of the register and input to the bit 22 is: - * bit0 XOR bit14 XOR bit15 XOR bit22 - * - * Simply use bit 22 as the noise output. - */ - - OPL->noise_p += OPL->noise_f; - i = OPL->noise_p >> FREQ_SH; /* number of events (shifts of the shift register) */ - OPL->noise_p &= FREQ_MASK; - while (i) - { - /* - UINT32 j; - j = ( (OPL->noise_rng) ^ (OPL->noise_rng>>14) ^ (OPL->noise_rng>>15) ^ (OPL->noise_rng>>22) ) & 1; - OPL->noise_rng = (j<<22) | (OPL->noise_rng>>1); - */ - - /* - Instead of doing all the logic operations above, we - use a trick here (and use bit 0 as the noise output). - The difference is only that the noise bit changes one - step ahead. This doesn't matter since we don't know - what is real state of the noise_rng after the reset. - */ - - if (OPL->noise_rng & 1) OPL->noise_rng ^= 0x800302; - OPL->noise_rng >>= 1; - - i--; - } -} - - -INLINE signed int op_calc(UINT32 phase, unsigned int env, signed int pm, unsigned int wave_tab) -{ - UINT32 p; - - p = (env<<4) + sin_tab[wave_tab + ((((signed int)((phase & ~FREQ_MASK) + (pm<<16))) >> FREQ_SH ) & SIN_MASK) ]; - - if (p >= TL_TAB_LEN) - return 0; - return tl_tab[p]; -} - -INLINE signed int op_calc1(UINT32 phase, unsigned int env, signed int pm, unsigned int wave_tab) -{ - UINT32 p; - - p = (env<<4) + sin_tab[wave_tab + ((((signed int)((phase & ~FREQ_MASK) + pm )) >> FREQ_SH ) & SIN_MASK) ]; - - if (p >= TL_TAB_LEN) - return 0; - return tl_tab[p]; -} - - -#define volume_calc(OP) ((OP)->TLL + ((UINT32)(OP)->volume) + (LFO_AM & (OP)->AMmask)) - -/* calculate output */ -INLINE void OPL_CALC_CH( OPL_CH *CH ) -{ - OPL_SLOT *SLOT; - unsigned int env; - signed int out; - - phase_modulation[0] = 0; - - /* SLOT 1 */ - SLOT = &CH->SLOT[SLOT1]; - env = volume_calc(SLOT); - out = SLOT->op1_out[0] + SLOT->op1_out[1]; - SLOT->op1_out[0] = SLOT->op1_out[1]; - *SLOT->connect1 += SLOT->op1_out[0]; - SLOT->op1_out[1] = 0; - if( env < ENV_QUIET ) - { - if (!SLOT->FB) - out = 0; - SLOT->op1_out[1] = op_calc1(SLOT->Cnt, env, (out<FB), SLOT->wavetable ); - } - - /* SLOT 2 */ - SLOT++; - env = volume_calc(SLOT); - if( env < ENV_QUIET ) - output[0] += op_calc(SLOT->Cnt, env, phase_modulation[0], SLOT->wavetable); -} - -/* - operators used in the rhythm sounds generation process: - - Envelope Generator: - -channel operator register number Bass High Snare Tom Top -/ slot number TL ARDR SLRR Wave Drum Hat Drum Tom Cymbal - 6 / 0 12 50 70 90 f0 + - 6 / 1 15 53 73 93 f3 + - 7 / 0 13 51 71 91 f1 + - 7 / 1 16 54 74 94 f4 + - 8 / 0 14 52 72 92 f2 + - 8 / 1 17 55 75 95 f5 + - - Phase Generator: - -channel operator register number Bass High Snare Tom Top -/ slot number MULTIPLE Drum Hat Drum Tom Cymbal - 6 / 0 12 30 + - 6 / 1 15 33 + - 7 / 0 13 31 + + + - 7 / 1 16 34 ----- n o t u s e d ----- - 8 / 0 14 32 + - 8 / 1 17 35 + + - -channel operator register number Bass High Snare Tom Top -number number BLK/FNUM2 FNUM Drum Hat Drum Tom Cymbal - 6 12,15 B6 A6 + - - 7 13,16 B7 A7 + + + - - 8 14,17 B8 A8 + + + - -*/ - -/* calculate rhythm */ - -INLINE void OPL_CALC_RH( OPL_CH *CH, unsigned int noise ) -{ - OPL_SLOT *SLOT; - signed int out; - unsigned int env; - - - /* Bass Drum (verified on real YM3812): - - depends on the channel 6 'connect' register: - when connect = 0 it works the same as in normal (non-rhythm) mode (op1->op2->out) - when connect = 1 _only_ operator 2 is present on output (op2->out), operator 1 is ignored - - output sample always is multiplied by 2 - */ - - phase_modulation[0] = 0; - /* SLOT 1 */ - SLOT = &CH[6].SLOT[SLOT1]; - env = volume_calc(SLOT); - - out = SLOT->op1_out[0] + SLOT->op1_out[1]; - SLOT->op1_out[0] = SLOT->op1_out[1]; - - if (!SLOT->CON) - phase_modulation[0] = SLOT->op1_out[0]; - /* else ignore output of operator 1 */ - - SLOT->op1_out[1] = 0; - if( env < ENV_QUIET ) - { - if (!SLOT->FB) - out = 0; - SLOT->op1_out[1] = op_calc1(SLOT->Cnt, env, (out<FB), SLOT->wavetable ); - } - - /* SLOT 2 */ - SLOT++; - env = volume_calc(SLOT); - if( env < ENV_QUIET ) - output[0] += op_calc(SLOT->Cnt, env, phase_modulation[0], SLOT->wavetable) * 2; - - - /* Phase generation is based on: */ - /* HH (13) channel 7->slot 1 combined with channel 8->slot 2 (same combination as TOP CYMBAL but different output phases) */ - /* SD (16) channel 7->slot 1 */ - /* TOM (14) channel 8->slot 1 */ - /* TOP (17) channel 7->slot 1 combined with channel 8->slot 2 (same combination as HIGH HAT but different output phases) */ - - /* Envelope generation based on: */ - /* HH channel 7->slot1 */ - /* SD channel 7->slot2 */ - /* TOM channel 8->slot1 */ - /* TOP channel 8->slot2 */ - - - /* The following formulas can be well optimized. - I leave them in direct form for now (in case I've missed something). - */ - - /* High Hat (verified on real YM3812) */ - env = volume_calc(SLOT7_1); - if( env < ENV_QUIET ) - { - - /* high hat phase generation: - phase = d0 or 234 (based on frequency only) - phase = 34 or 2d0 (based on noise) - */ - - /* base frequency derived from operator 1 in channel 7 */ - unsigned char bit7 = ((SLOT7_1->Cnt>>FREQ_SH)>>7)&1; - unsigned char bit3 = ((SLOT7_1->Cnt>>FREQ_SH)>>3)&1; - unsigned char bit2 = ((SLOT7_1->Cnt>>FREQ_SH)>>2)&1; - - unsigned char res1 = (bit2 ^ bit7) | bit3; - - /* when res1 = 0 phase = 0x000 | 0xd0; */ - /* when res1 = 1 phase = 0x200 | (0xd0>>2); */ - UINT32 phase = res1 ? (0x200|(0xd0>>2)) : 0xd0; - - /* enable gate based on frequency of operator 2 in channel 8 */ - unsigned char bit5e= ((SLOT8_2->Cnt>>FREQ_SH)>>5)&1; - unsigned char bit3e= ((SLOT8_2->Cnt>>FREQ_SH)>>3)&1; - - unsigned char res2 = (bit3e ^ bit5e); - - /* when res2 = 0 pass the phase from calculation above (res1); */ - /* when res2 = 1 phase = 0x200 | (0xd0>>2); */ - if (res2) - phase = (0x200|(0xd0>>2)); - - - /* when phase & 0x200 is set and noise=1 then phase = 0x200|0xd0 */ - /* when phase & 0x200 is set and noise=0 then phase = 0x200|(0xd0>>2), ie no change */ - if (phase&0x200) - { - if (noise) - phase = 0x200|0xd0; - } - else - /* when phase & 0x200 is clear and noise=1 then phase = 0xd0>>2 */ - /* when phase & 0x200 is clear and noise=0 then phase = 0xd0, ie no change */ - { - if (noise) - phase = 0xd0>>2; - } - - output[0] += op_calc(phase<wavetable) * 2; - } - - /* Snare Drum (verified on real YM3812) */ - env = volume_calc(SLOT7_2); - if( env < ENV_QUIET ) - { - /* base frequency derived from operator 1 in channel 7 */ - unsigned char bit8 = ((SLOT7_1->Cnt>>FREQ_SH)>>8)&1; - - /* when bit8 = 0 phase = 0x100; */ - /* when bit8 = 1 phase = 0x200; */ - UINT32 phase = bit8 ? 0x200 : 0x100; - - /* Noise bit XOR'es phase by 0x100 */ - /* when noisebit = 0 pass the phase from calculation above */ - /* when noisebit = 1 phase ^= 0x100; */ - /* in other words: phase ^= (noisebit<<8); */ - if (noise) - phase ^= 0x100; - - output[0] += op_calc(phase<wavetable) * 2; - } - - /* Tom Tom (verified on real YM3812) */ - env = volume_calc(SLOT8_1); - if( env < ENV_QUIET ) - output[0] += op_calc(SLOT8_1->Cnt, env, 0, SLOT8_1->wavetable) * 2; - - /* Top Cymbal (verified on real YM3812) */ - env = volume_calc(SLOT8_2); - if( env < ENV_QUIET ) - { - /* base frequency derived from operator 1 in channel 7 */ - unsigned char bit7 = ((SLOT7_1->Cnt>>FREQ_SH)>>7)&1; - unsigned char bit3 = ((SLOT7_1->Cnt>>FREQ_SH)>>3)&1; - unsigned char bit2 = ((SLOT7_1->Cnt>>FREQ_SH)>>2)&1; - - unsigned char res1 = (bit2 ^ bit7) | bit3; - - /* when res1 = 0 phase = 0x000 | 0x100; */ - /* when res1 = 1 phase = 0x200 | 0x100; */ - UINT32 phase = res1 ? 0x300 : 0x100; - - /* enable gate based on frequency of operator 2 in channel 8 */ - unsigned char bit5e= ((SLOT8_2->Cnt>>FREQ_SH)>>5)&1; - unsigned char bit3e= ((SLOT8_2->Cnt>>FREQ_SH)>>3)&1; - - unsigned char res2 = (bit3e ^ bit5e); - /* when res2 = 0 pass the phase from calculation above (res1); */ - /* when res2 = 1 phase = 0x200 | 0x100; */ - if (res2) - phase = 0x300; - - output[0] += op_calc(phase<wavetable) * 2; - } - -} - -INLINE void FM_KEYON(OPL_SLOT *SLOT, UINT32 key_set) -{ - if( !SLOT->key ) - { - /* restart Phase Generator */ - SLOT->Cnt = 0; - /* phase -> Attack */ - SLOT->state = EG_ATT; - } - SLOT->key |= key_set; -} - -INLINE void FM_KEYOFF(OPL_SLOT *SLOT, UINT32 key_clr) -{ - if( SLOT->key ) - { - SLOT->key &= key_clr; - - if( !SLOT->key ) - { - /* phase -> Release */ - if (SLOT->state>EG_REL) - SLOT->state = EG_REL; - } - } -} - -/* update phase increment counter of operator (also update the EG rates if necessary) */ -INLINE void CALC_FCSLOT(OPL_CH *CH,OPL_SLOT *SLOT) -{ - int ksr; - - /* (frequency) phase increment counter */ - SLOT->Incr = CH->fc * SLOT->mul; - ksr = CH->kcode >> SLOT->KSR; - - if( SLOT->ksr != ksr ) - { - SLOT->ksr = ksr; - - /* calculate envelope generator rates */ - if ((SLOT->ar + SLOT->ksr) < 16+62) - { - SLOT->eg_sh_ar = eg_rate_shift [SLOT->ar + SLOT->ksr ]; - SLOT->eg_sel_ar = eg_rate_select[SLOT->ar + SLOT->ksr ]; - } - else - { - SLOT->eg_sh_ar = 0; - SLOT->eg_sel_ar = 13*RATE_STEPS; - } - SLOT->eg_sh_dr = eg_rate_shift [SLOT->dr + SLOT->ksr ]; - SLOT->eg_sel_dr = eg_rate_select[SLOT->dr + SLOT->ksr ]; - SLOT->eg_sh_rr = eg_rate_shift [SLOT->rr + SLOT->ksr ]; - SLOT->eg_sel_rr = eg_rate_select[SLOT->rr + SLOT->ksr ]; - } -} - -/* set multi,am,vib,EG-TYP,KSR,mul */ -INLINE void set_mul(FM_OPL *OPL,int slot,int v) -{ - OPL_CH *CH = &OPL->P_CH[slot/2]; - OPL_SLOT *SLOT = &CH->SLOT[slot&1]; - - SLOT->mul = mul_tab[v&0x0f]; - SLOT->KSR = (v&0x10) ? 0 : 2; - SLOT->eg_type = (v&0x20); - SLOT->vib = (v&0x40); - SLOT->AMmask = (v&0x80) ? ~0 : 0; - CALC_FCSLOT(CH,SLOT); -} - -/* set ksl & tl */ -INLINE void set_ksl_tl(FM_OPL *OPL,int slot,int v) -{ - OPL_CH *CH = &OPL->P_CH[slot/2]; - OPL_SLOT *SLOT = &CH->SLOT[slot&1]; - int ksl = v>>6; /* 0 / 1.5 / 3.0 / 6.0 dB/OCT */ - - SLOT->ksl = ksl ? 3-ksl : 31; - SLOT->TL = (v&0x3f)<<(ENV_BITS-1-7); /* 7 bits TL (bit 6 = always 0) */ - - SLOT->TLL = SLOT->TL + (CH->ksl_base>>SLOT->ksl); -} - -/* set attack rate & decay rate */ -INLINE void set_ar_dr(FM_OPL *OPL,int slot,int v) -{ - OPL_CH *CH = &OPL->P_CH[slot/2]; - OPL_SLOT *SLOT = &CH->SLOT[slot&1]; - - SLOT->ar = (v>>4) ? 16 + ((v>>4) <<2) : 0; - - if ((SLOT->ar + SLOT->ksr) < 16+62) - { - SLOT->eg_sh_ar = eg_rate_shift [SLOT->ar + SLOT->ksr ]; - SLOT->eg_sel_ar = eg_rate_select[SLOT->ar + SLOT->ksr ]; - } - else - { - SLOT->eg_sh_ar = 0; - SLOT->eg_sel_ar = 13*RATE_STEPS; - } - - SLOT->dr = (v&0x0f)? 16 + ((v&0x0f)<<2) : 0; - SLOT->eg_sh_dr = eg_rate_shift [SLOT->dr + SLOT->ksr ]; - SLOT->eg_sel_dr = eg_rate_select[SLOT->dr + SLOT->ksr ]; -} - -/* set sustain level & release rate */ -INLINE void set_sl_rr(FM_OPL *OPL,int slot,int v) -{ - OPL_CH *CH = &OPL->P_CH[slot/2]; - OPL_SLOT *SLOT = &CH->SLOT[slot&1]; - - SLOT->sl = sl_tab[ v>>4 ]; - - SLOT->rr = (v&0x0f)? 16 + ((v&0x0f)<<2) : 0; - SLOT->eg_sh_rr = eg_rate_shift [SLOT->rr + SLOT->ksr ]; - SLOT->eg_sel_rr = eg_rate_select[SLOT->rr + SLOT->ksr ]; -} - - -/* write a value v to register r on OPL chip */ -static void OPLWriteReg(FM_OPL *OPL, int r, int v) -{ - OPL_CH *CH; - int slot; - int block_fnum; - - /* 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 */ - if(OPL->type&OPL_TYPE_WAVESEL) - { - OPL->wavesel = v&0x20; - /* do not change the waveform previously selected */ - } - 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); - - OPL_STATUS_RESET(OPL,0x7f-0x08); /* don't reset BFRDY flag or we will have to call deltat module to set the flag */ - } - else - { /* set IRQ mask ,timer enable*/ -#if 0 - 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; - } - /* timer 2 */ - if(OPL->st[1]) - { - OPL->TC[1]=OPL->T[1]*20; - } -#endif - /* set IRQ mask ,timer enable*/ - UINT8 st1 = v&1; - UINT8 st2 = (v>>1)&1; - - /* IRQRST,T1MSK,t2MSK,EOSMSK,BRMSK,x,ST2,ST1 */ - OPL_STATUS_RESET(OPL, v & (0x78-0x08) ); - OPL_STATUSMASK_SET(OPL, (~v) & 0x78 ); - - /* timer 2 */ - if(OPL->st[1] != st2) - { - OPL->st[1] = st2; - } - /* timer 1 */ - if(OPL->st[0] != st1) - { - OPL->st[0] = st1; - } - } - break; - case 0x08: /* MODE,DELTA-T control 2 : CSM,NOTESEL,x,x,smpl,da/ad,64k,rom */ - OPL->mode = v; - break; - - default: - break; - } - break; - case 0x20: /* am ON, vib ON, ksr, eg_type, mul */ - slot = slot_array[r&0x1f]; - if(slot < 0) return; - set_mul(OPL,slot,v); - break; - case 0x40: - slot = slot_array[r&0x1f]; - if(slot < 0) return; - set_ksl_tl(OPL,slot,v); - break; - case 0x60: - slot = slot_array[r&0x1f]; - if(slot < 0) return; - set_ar_dr(OPL,slot,v); - break; - case 0x80: - slot = slot_array[r&0x1f]; - if(slot < 0) return; - set_sl_rr(OPL,slot,v); - break; - case 0xa0: - if (r == 0xbd) /* am depth, vibrato depth, r,bd,sd,tom,tc,hh */ - { - OPL->lfo_am_depth = v & 0x80; - OPL->lfo_pm_depth_range = (v&0x40) ? 8 : 0; - - OPL->rhythm = v&0x3f; - - if(OPL->rhythm&0x20) - { - /* BD key on/off */ - if(v&0x10) - { - FM_KEYON (&OPL->P_CH[6].SLOT[SLOT1], 2); - FM_KEYON (&OPL->P_CH[6].SLOT[SLOT2], 2); - } - else - { - FM_KEYOFF(&OPL->P_CH[6].SLOT[SLOT1],~2); - FM_KEYOFF(&OPL->P_CH[6].SLOT[SLOT2],~2); - } - /* HH key on/off */ - if(v&0x01) FM_KEYON (&OPL->P_CH[7].SLOT[SLOT1], 2); - else FM_KEYOFF(&OPL->P_CH[7].SLOT[SLOT1],~2); - /* SD key on/off */ - if(v&0x08) FM_KEYON (&OPL->P_CH[7].SLOT[SLOT2], 2); - else FM_KEYOFF(&OPL->P_CH[7].SLOT[SLOT2],~2); - /* TOM key on/off */ - if(v&0x04) FM_KEYON (&OPL->P_CH[8].SLOT[SLOT1], 2); - else FM_KEYOFF(&OPL->P_CH[8].SLOT[SLOT1],~2); - /* TOP-CY key on/off */ - if(v&0x02) FM_KEYON (&OPL->P_CH[8].SLOT[SLOT2], 2); - else FM_KEYOFF(&OPL->P_CH[8].SLOT[SLOT2],~2); - } - else - { - /* BD key off */ - FM_KEYOFF(&OPL->P_CH[6].SLOT[SLOT1],~2); - FM_KEYOFF(&OPL->P_CH[6].SLOT[SLOT2],~2); - /* HH key off */ - FM_KEYOFF(&OPL->P_CH[7].SLOT[SLOT1],~2); - /* SD key off */ - FM_KEYOFF(&OPL->P_CH[7].SLOT[SLOT2],~2); - /* TOM key off */ - FM_KEYOFF(&OPL->P_CH[8].SLOT[SLOT1],~2); - /* TOP-CY off */ - FM_KEYOFF(&OPL->P_CH[8].SLOT[SLOT2],~2); - } - return; - } - /* keyon,block,fnum */ - if( (r&0x0f) > 8) return; - CH = &OPL->P_CH[r&0x0f]; - if(!(r&0x10)) - { /* a0-a8 */ - block_fnum = (CH->block_fnum&0x1f00) | v; - } - else - { /* b0-b8 */ - block_fnum = ((v&0x1f)<<8) | (CH->block_fnum&0xff); - - if(v&0x20) - { - FM_KEYON (&CH->SLOT[SLOT1], 1); - FM_KEYON (&CH->SLOT[SLOT2], 1); - } - else - { - FM_KEYOFF(&CH->SLOT[SLOT1],~1); - FM_KEYOFF(&CH->SLOT[SLOT2],~1); - } - } - /* update */ - if(CH->block_fnum != (UINT32) block_fnum) - { - UINT8 block = block_fnum >> 10; - - CH->block_fnum = block_fnum; - - CH->ksl_base = ksl_tab[block_fnum>>6]; - CH->fc = OPL->fn_tab[block_fnum&0x03ff] >> (7-block); - - /* BLK 2,1,0 bits -> bits 3,2,1 of kcode */ - CH->kcode = (CH->block_fnum&0x1c00)>>9; - - /* the info below is actually opposite to what is stated in the Manuals (verifed on real YM3812) */ - /* if notesel == 0 -> lsb of kcode is bit 10 (MSB) of fnum */ - /* if notesel == 1 -> lsb of kcode is bit 9 (MSB-1) of fnum */ - if (OPL->mode&0x40) - CH->kcode |= (CH->block_fnum&0x100)>>8; /* notesel == 1 */ - else - CH->kcode |= (CH->block_fnum&0x200)>>9; /* notesel == 0 */ - - /* refresh Total Level in both SLOTs of this channel */ - CH->SLOT[SLOT1].TLL = CH->SLOT[SLOT1].TL + (CH->ksl_base>>CH->SLOT[SLOT1].ksl); - CH->SLOT[SLOT2].TLL = CH->SLOT[SLOT2].TL + (CH->ksl_base>>CH->SLOT[SLOT2].ksl); - - /* refresh frequency counter in both SLOTs of this channel */ - CALC_FCSLOT(CH,&CH->SLOT[SLOT1]); - CALC_FCSLOT(CH,&CH->SLOT[SLOT2]); - } - break; - case 0xc0: - /* FB,C */ - if( (r&0x0f) > 8) return; - CH = &OPL->P_CH[r&0x0f]; - CH->SLOT[SLOT1].FB = (v>>1)&7 ? ((v>>1)&7) + 7 : 0; - CH->SLOT[SLOT1].CON = v&1; - CH->SLOT[SLOT1].connect1 = CH->SLOT[SLOT1].CON ? &output[0]: &phase_modulation[0]; - break; - case 0xe0: /* waveform select */ - /* simply ignore write to the waveform select register if selecting not enabled in test register */ - if(OPL->wavesel) - { - slot = slot_array[r&0x1f]; - if(slot < 0) return; - CH = &OPL->P_CH[slot/2]; - - CH->SLOT[slot&1].wavetable = (v&0x03)*SIN_LEN; - } - break; - } -} - -static void OPLResetChip(FM_OPL *OPL) -{ - int c,s; - int i; - - OPL->eg_timer = 0; - OPL->eg_cnt = 0; - - OPL->noise_rng = 1; /* noise shift register */ - 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); - - /* reset operator parameters */ - for( c = 0 ; c < 9 ; c++ ) - { - OPL_CH *CH = &OPL->P_CH[c]; - for(s = 0 ; s < 2 ; s++ ) - { - /* wave table */ - CH->SLOT[s].wavetable = 0; - CH->SLOT[s].state = EG_OFF; - CH->SLOT[s].volume = MAX_ATT_INDEX; - } - } -} - -/* Create one of virtual YM3812/YM3526/Y8950 */ -/* 'clock' is chip clock in Hz */ -/* 'rate' is sampling rate */ -static void OPLCreate(int type, int clock, int rate, FM_OPL *OPL) -{ - OPL->type = type; - OPL->clock = clock; - OPL->rate = rate; - return; -} - -static int OPLWrite(FM_OPL *OPL,int a,int v) -{ - if( !(a&1) ) - { /* address port */ - OPL->address = v & 0xff; - } - else - { /* data port */ - OPLWriteReg(OPL,OPL->address,v); - } - return OPL->status>>7; -} - -static unsigned char OPLRead(FM_OPL *OPL,int a) -{ - if( !(a&1) ) - { - 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; -} - -/* CSM Key Controll */ -INLINE void CSMKeyControll(OPL_CH *CH) -{ - FM_KEYON (&CH->SLOT[SLOT1], 4); - FM_KEYON (&CH->SLOT[SLOT2], 4); - - /* The key off should happen exactly one sample later - not implemented correctly yet */ - - FM_KEYOFF(&CH->SLOT[SLOT1], ~4); - FM_KEYOFF(&CH->SLOT[SLOT2], ~4); -} - - -static 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; - for(ch=0; ch<9; ch++) - CSMKeyControll( &OPL->P_CH[ch] ); - } - } - return OPL->status>>7; -} - - - -#if (BUILD_YM3812) - -static int Active=1; - -static void YM3812ResetChip(int which) -{ - OPLResetChip(OPL_YM3812[which]); -} - -extern "C" void fmopl_Init(void) -{ - char *ptr; - - SharedBuff_ptr = (char *) BUFF_BASE_ADDRESS; - - ptr=(SharedBuff_ptr + NSUB_OFFSET); - NSubmittedMessages=(int *) ptr; - - ptr=(SharedBuff_ptr + NEX_OFFSET); - NExecutedMessages=(int *) ptr; - - ptr=(SharedBuff_ptr + MSG_BUF_OFFSET); - MessageBuffer=(CoreMessage *) ptr; -} - -int YM3812Init(int num, int clock, int rate) -{ - char *ptr; - int i; - - SharedData_ptr=(char *) DATA_BASE_ADDRESS; - - ptr=(SharedData_ptr + NUMCHIP_OFFSET); - YM3812NumChips=(int *) ptr; - - ptr=(SharedBuff_ptr + TL_TAB_OFFSET); - tl_tab=(signed int *) ptr; - ptr=(SharedBuff_ptr + SIN_TAB_OFFSET); - sin_tab=(unsigned int *) ptr; - - for (i = 0;i < *YM3812NumChips; i++) - { - ptr=(SharedBuff_ptr + BUFPOS_OFFSET + i*sizeof(int)); - BufWritePos[i]=(int *) ptr; - - ptr=(SharedBuff_ptr + READPOS_OFFSET + i*sizeof(int)); - BufReadPos[i]=(int *) ptr; - - 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=(SharedBuff_ptr + FNTAB_OFFSET+i*1024*sizeof(UINT32)); - OPL_YM3812[i]->fn_tab=(UINT32 *) ptr; - - OPLCreate(OPL_TYPE_YM3812,clock,rate,OPL_YM3812[i]); - - YM3812ResetChip(i); - } - - return 0; - -} - -void YM3812Shutdown(void) -{ - int i; - - for (i = 0;i < *YM3812NumChips; i++) - { - OPL_YM3812[i] = 0; - } -} - -static int YM3812Write(int which, int a, int v) -{ - return OPLWrite(OPL_YM3812[which], a, v); -} - -static unsigned char YM3812Read(int which, int a) -{ - /* YM3812 always returns bit2 and bit1 in HIGH state */ - return OPLRead(OPL_YM3812[which], a) | 0x06 ; -} -static int YM3812TimerOver(int which, int c) -{ - return OPLTimerOver(OPL_YM3812[which], c); -} - -/* -** Generate samples for one of the YM3812's -** -** 'which' is the virtual YM3812 number -** '*buffer' is the output buffer pointer -** 'length' is the number of samples that should be generated -*/ -static void YM3812UpdateOne_core(int which, INT16 *buffer, int length) -{ - FM_OPL *OPL = OPL_YM3812[which]; - UINT8 rhythm = OPL->rhythm&0x20; - OPLSAMPLE *buf = buffer; - int i; - - if( which != cur_chip ){ - cur_chip = which; - /* rhythm slots */ - SLOT7_1 = &OPL->P_CH[7].SLOT[SLOT1]; - SLOT7_2 = &OPL->P_CH[7].SLOT[SLOT2]; - SLOT8_1 = &OPL->P_CH[8].SLOT[SLOT1]; - SLOT8_2 = &OPL->P_CH[8].SLOT[SLOT2]; - } - for( i=0; i < length ; i++ ) - { - int lt; - - output[0] = 0; - - advance_lfo(OPL); - - /* FM part */ - OPL_CALC_CH(&OPL->P_CH[0]); - OPL_CALC_CH(&OPL->P_CH[1]); - OPL_CALC_CH(&OPL->P_CH[2]); - OPL_CALC_CH(&OPL->P_CH[3]); - OPL_CALC_CH(&OPL->P_CH[4]); - OPL_CALC_CH(&OPL->P_CH[5]); - - if(!rhythm) - { - OPL_CALC_CH(&OPL->P_CH[6]); - OPL_CALC_CH(&OPL->P_CH[7]); - OPL_CALC_CH(&OPL->P_CH[8]); - } - else /* Rhythm part */ - { - OPL_CALC_RH(&OPL->P_CH[0], (OPL->noise_rng>>0)&1 ); - } - - lt = output[0]; - - lt >>= FINAL_SH; - - /* limit check */ - lt = limit( lt , MAXOUT, MINOUT ); - - /* store to sound buffer */ - buf[i] = lt; - - advance(OPL); - } - -} - -static INT16 buff[SHARED_BUF_SIZE]; - -static void YM3812UpdateOne(int which, int length) -{ - int i,nfree; - if(length==0) return; - YM3812UpdateOne_core(which,buff,length); - nfree=SHARED_BUF_SIZE - *BufWritePos[which]; - if(length < nfree) - { - for(i=0;i=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< 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 diff --git a/GP2X/gp2x.h b/GP2X/gp2x.h deleted file mode 100644 index 6a2258a..0000000 --- a/GP2X/gp2x.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef GP2X_H -#define GP2X_H - -#include -#include -#include -#include -#include - -#include "../wl_def.h" -#if defined(GP2X_940) -#include "fmopl.h" -#include -#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 diff --git a/README-GP2X.txt b/README-GP2X.txt deleted file mode 100644 index ee82716..0000000 --- a/README-GP2X.txt +++ /dev/null @@ -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. diff --git a/README-dc.txt b/README-dc.txt deleted file mode 100644 index 50a7bed..0000000 --- a/README-dc.txt +++ /dev/null @@ -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 ---res (default 320x200) ---resf ---bits (default 8) ---dblbuf ---extravbls ---samplerate (default 11025) ---audiobuffer (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 diff --git a/README-devcpp.txt b/README-devcpp.txt deleted file mode 100644 index 96f5904..0000000 --- a/README-devcpp.txt +++ /dev/null @@ -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... diff --git a/Wolf4SDL-DC.cbp b/Wolf4SDL-DC.cbp deleted file mode 100644 index 972ade8..0000000 --- a/Wolf4SDL-DC.cbp +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - diff --git a/Wolf4SDL-GP2X.cbp b/Wolf4SDL-GP2X.cbp deleted file mode 100644 index 09663e8..0000000 --- a/Wolf4SDL-GP2X.cbp +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - diff --git a/Wolf4SDL.cbp b/Wolf4SDL.cbp deleted file mode 100644 index 1113734..0000000 --- a/Wolf4SDL.cbp +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - diff --git a/dc/dc_cd.cpp b/dc/dc_cd.cpp deleted file mode 100644 index 10b2f7e..0000000 --- a/dc/dc_cd.cpp +++ /dev/null @@ -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 diff --git a/dc/dc_main.cpp b/dc/dc_main.cpp deleted file mode 100644 index 92f5eaf..0000000 --- a/dc/dc_main.cpp +++ /dev/null @@ -1,377 +0,0 @@ -//Wolf4SDL\DC -//dc_main.cpp -//2009 - Cyle Terry - -#if defined(_arch_dreamcast) - -//TODO: Use Port A Only - -#include -#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 diff --git a/dc/dc_main.h b/dc/dc_main.h deleted file mode 100644 index b0b0a21..0000000 --- a/dc/dc_main.h +++ /dev/null @@ -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 diff --git a/dc/dc_maple.cpp b/dc/dc_maple.cpp deleted file mode 100644 index 49efc5a..0000000 --- a/dc/dc_maple.cpp +++ /dev/null @@ -1,60 +0,0 @@ -//Wolf4SDL\DC -//dc_maple.cpp -//2009 - Cyle Terry - -#if defined(_arch_dreamcast) - -#include -#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 diff --git a/dc/dc_video.cpp b/dc/dc_video.cpp deleted file mode 100644 index 015c975..0000000 --- a/dc/dc_video.cpp +++ /dev/null @@ -1,37 +0,0 @@ -//Wolf4SDL\DC -//dc_video.cpp -//2009 - Cyle Terry - -#if defined(_arch_dreamcast) - -#include -#include -#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 diff --git a/dc/dc_vmu.cpp b/dc/dc_vmu.cpp deleted file mode 100644 index 548b9ec..0000000 --- a/dc/dc_vmu.cpp +++ /dev/null @@ -1,181 +0,0 @@ -//Wolf4SDL\DC -//dc_vmu.cpp -//2009 - Cyle Terry - -#if defined(_arch_dreamcast) - -#include -#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 diff --git a/dc/dc_vmu.h b/dc/dc_vmu.h deleted file mode 100644 index 031c7aa..0000000 --- a/dc/dc_vmu.h +++ /dev/null @@ -1,1168 +0,0 @@ -//Wolf4SDL\DC -//dc_vmu.h -//2009 - Cyle Terry -// -// BJ LCD images made by Antioch - - -#define LCD_HEIGHT 32 -#define LCD_WIDTH 48 - -const unsigned char vmu_bios_save_icon[544] ={ - 0x00,0xf0,0x0d,0xf0,0x0f,0xf0,0x00,0x0f, - 0x44,0xf4,0x62,0xfb,0x96,0xff,0xca,0xff, - 0xff,0xff,0x00,0xf0,0x00,0xf0,0x00,0xf0, - 0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0xf0, - 0x33,0x33,0x33,0x33,0x33,0x55,0x55,0x55, - 0x55,0x55,0x53,0x33,0x33,0x33,0x33,0x33, - 0x33,0x33,0x33,0x05,0x55,0x55,0x55,0x55, - 0x56,0x56,0x55,0x53,0x33,0x33,0x33,0x33, - 0x33,0x33,0x30,0x55,0x55,0x55,0x55,0x55, - 0x55,0x55,0x55,0x55,0x53,0x33,0x33,0x33, - 0x33,0x33,0x34,0x55,0x55,0x55,0x55,0x55, - 0x55,0x55,0x66,0x55,0x53,0x33,0x33,0x33, - 0x33,0x33,0x45,0x55,0x55,0x44,0x45,0x55, - 0x45,0x45,0x56,0x55,0x55,0x33,0x33,0x33, - 0x33,0x33,0x04,0x55,0x54,0x44,0x45,0x45, - 0x44,0x55,0x55,0x55,0x55,0x33,0x33,0x33, - 0x33,0x33,0x45,0x54,0x45,0x66,0x55,0x54, - 0x44,0x44,0x55,0x54,0x45,0x33,0x33,0x33, - 0x33,0x33,0x34,0x45,0x56,0x67,0x76,0x66, - 0x55,0x55,0x56,0x65,0x54,0x33,0x33,0x33, - 0x33,0x33,0x34,0x56,0x67,0x77,0x77,0x77, - 0x56,0x56,0x56,0x75,0x54,0x33,0x33,0x33, - 0x33,0x33,0x34,0x57,0x76,0x76,0x77,0x77, - 0x76,0x66,0x77,0x76,0x64,0x33,0x33,0x33, - 0x33,0x33,0x34,0x56,0x66,0x78,0x87,0x77, - 0x75,0x57,0x78,0x66,0x64,0x33,0x33,0x33, - 0x33,0x33,0x44,0x57,0x74,0x45,0x57,0x77, - 0x76,0x65,0x44,0x76,0x60,0x43,0x33,0x33, - 0x33,0x33,0x60,0x64,0x44,0x10,0x00,0x55, - 0x50,0x04,0x41,0x46,0x64,0x63,0x33,0x33, - 0x33,0x33,0x60,0x66,0x67,0x12,0x75,0x56, - 0x55,0x71,0x28,0x65,0x54,0x63,0x33,0x33, - 0x33,0x33,0x55,0x67,0x76,0x66,0x67,0x67, - 0x77,0x76,0x66,0x76,0x64,0x53,0x33,0x33, - 0x33,0x33,0x66,0x77,0x78,0x78,0x77,0x68, - 0x77,0x77,0x88,0x76,0x67,0x63,0x33,0x33, - 0x33,0x33,0x66,0x77,0x78,0x78,0x77,0x68, - 0x77,0x77,0x88,0x76,0x67,0x63,0x33,0x33, - 0x33,0x33,0x66,0x67,0x77,0x87,0x76,0x77, - 0x76,0x77,0x78,0x76,0x66,0x63,0x33,0x33, - 0x33,0x33,0x54,0x57,0x77,0x77,0x65,0x54, - 0x55,0x67,0x77,0x65,0x54,0x53,0x33,0x33, - 0x33,0x33,0x35,0x66,0x66,0x77,0x66,0x65, - 0x77,0x67,0x77,0x66,0x65,0x33,0x33,0x33, - 0x33,0x33,0x33,0x66,0x67,0x76,0x77,0x76, - 0x77,0x77,0x76,0x66,0x63,0x33,0x33,0x33, - 0x33,0x33,0x33,0x76,0x67,0x76,0x55,0x66, - 0x65,0x56,0x77,0x67,0x73,0x33,0x33,0x33, - 0x33,0x33,0x33,0x67,0x76,0x76,0x67,0x77, - 0x77,0x66,0x76,0x77,0x73,0x33,0x33,0x33, - 0x33,0x33,0x33,0x66,0x67,0x77,0x76,0x66, - 0x67,0x77,0x77,0x67,0x73,0x33,0x33,0x33, - 0x33,0x33,0x33,0x56,0x67,0x77,0x87,0x77, - 0x77,0x78,0x77,0x67,0x73,0x33,0x33,0x33, - 0x33,0x33,0x33,0x45,0x56,0x67,0x77,0x76, - 0x67,0x77,0x76,0x67,0x73,0x33,0x33,0x33, - 0x33,0x33,0x33,0x55,0x55,0x55,0x66,0x55, - 0x66,0x57,0x55,0x77,0x73,0x33,0x33,0x33, - 0x33,0x33,0x33,0x44,0x44,0x44,0x44,0x44, - 0x44,0x54,0x56,0x77,0x73,0x33,0x33,0x33, - 0x33,0x33,0x33,0x55,0x54,0x54,0x45,0x54, - 0x55,0x55,0x77,0x57,0x73,0x33,0x33,0x33, - 0x33,0x33,0x33,0x44,0x45,0x45,0x56,0x56, - 0x56,0x57,0x77,0x75,0x53,0x33,0x33,0x33, - 0x33,0x33,0x33,0x54,0x44,0x55,0x66,0x67, - 0x76,0x56,0x76,0x75,0x53,0x33,0x33,0x33, - 0x33,0x33,0x33,0x45,0x55,0x55,0x67,0x66, - 0x77,0x66,0x76,0x55,0x53,0x33,0x33,0x33 -}; - -static const char FACE1ALCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. .. .. .. \ - .. ..... ..... .. \ - ..... ........... ..... \ - ... . .. . . . .. . ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . . . \ - . . . . \ - . ......... . \ - . . \ - . ..... . \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE1BLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. ... .. \ - ... . .. .. \ - ........ ..... .. \ - ...... ........ ..... \ - ... .. . . ... . ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ...... . . \ - . . . . . . \ - . . . \ - . ......... . \ - . . \ - . .... . \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE1CLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. ...... \ - .. .. . .. \ - .. ..... ..... .. \ - ..... ......... ...... \ - ... . ... . . .. ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . . \ - . . . \ - . ........ . \ - . . \ - . ..... . \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE2ALCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. .. .. .. \ - .. ..... ..... .. \ - ..... ........... ..... \ - ... . .. . . . .. . ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . . . \ - . . . . \ - . ......... . \ - . . . \ - . .... . . \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE2BLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. ... .. \ - ... . .. .. \ - ........ ..... .. \ - ...... ........ ..... \ - ... .. . . ... . ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ...... . . \ - . . . . . . \ - . . . \ - . ......... . \ - . . . \ - . .... . . \ - .. . .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE2CLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. ...... \ - .. .. . .. \ - .. ..... ..... .. \ - ..... ......... ...... \ - ... . ... . . .. ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . . \ - . . . \ - . ........ . \ - . . . \ - . ..... . \ - .. . .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE3ALCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. .. .. .. \ - .. ..... ..... .. \ - ..... ........... ..... \ - ... . .. . . . .. . ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . . . . \ - . . . . . \ - . ......... . \ - . .. . \ - . .... . . \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE3BLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. ... .. \ - ... . .. .. \ - ........ ..... .. \ - ...... ........ ..... \ - ... .. . . ... . ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ...... . . \ - . . . . . . . \ - . .. . . \ - . ......... . \ - . .. . \ - . .... . . \ - .. . .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE3CLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. ...... \ - .. .. . .. \ - .. ..... ..... .. \ - ..... ......... ...... \ - ... . ... . ... .. ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . . . \ - . . .. . \ - . ........ . \ - . .. . \ - . ..... . \ - .. . .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE4ALCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. .. .. .. \ - .. ..... ..... .. \ - ..... ........... ..... \ - ... . .. . . ...... ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . . . . . \ - . . . . . . \ - . ......... . \ - . ...... . \ - . .... . . \ - .. . .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE4BLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. ... .. \ - ... . .. .. \ - ........ ..... .. \ - ...... ........ ..... \ - ... .. . ..... . ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ...... . . \ - . . . . . . . . \ - . . .. . . \ - . ......... . \ - . ..... . \ - . .... . . \ - .. . .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE4CLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. ...... \ - .. .. . .. \ - .. ..... ..... .. \ - ..... ......... ...... \ - ... . ... . ... .. ... \ - ... . . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . .. . . . \ - . . ... . \ - . ........ . \ - . ... . \ - . ..... . \ - .. . .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE5ALCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. .. .. .. \ - .. ..... ..... .. \ - ..... ......... . ..... \ - ... . .. . . ...... ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . . . . . \ - . . . . . . \ - . ......... . \ - . . ...... . \ - . .......... . \ - .. . . .. \ - ... . . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE5BLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. ... .. \ - ... . .. .. \ - ........ ..... .. \ - ...... ............... \ - ... .. . .. .. .. ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . . ...... . . \ - . . .. . . . . \ - . . .. . . \ - . ......... . \ - . . ..... . \ - . . .... . . \ - .. . . .. \ - ... . . . . \ - .... . . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE5CLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. ...... \ - .. .. ... .. \ - .. ..... ..... .. \ - ..... ................ \ - ... . ... . ... .. ... \ - ... . . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . .. . . . \ - . . . ... . \ - . ........ . \ - . .. ... . \ - . . .... . . \ - .. . .. \ - ... . . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE6ALCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . . \ - .. . . \ - . . . ... ... \ - .. . .... . . . . \ - . . . . . . . \ - ... . . . . .. \ - .. . ... .. \ - .. . .. \ - .. .... .... .. \ - ..... .... .......... \ - ... . .. .......... ... \ - ... . .... ... \ - .. .. \ - .. .. \ - .. . . .. \ - . . .. .. . . \ - . . . ... . . . \ - . . . . \ - . ....... . \ - . .. ...... . \ - .. .. . .. \ - ... . . . . \ - .... . . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE6BLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . . \ - .. . . \ - . . . ... ... \ - .. . .... . . . . \ - . . . . . . . \ - ... . . . . .. \ - .. . ... .. \ - .. ... . .. \ - ... .. .... .. \ - ... .. ... .......... \ - ... .. ........... ... \ - ... . .... ... \ - .. .. \ - .. .. \ - .. . . .. \ - . . .. .. . . \ - . . . ... . . . \ - . . . . \ - . ....... . \ - . .. ...... . \ - .. .. . .. \ - ... . . . . \ - .... . . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE6CLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . . \ - .. . . \ - . . . ... ... \ - .. . .... . . . . \ - . . . . . . . \ - ... . . . . .. \ - .. . ... .. \ - .. ..... .. \ - .. .... . . ... \ - ..... ... .......... \ - ... . ............ ... \ - ... . .... ... \ - .. .. \ - .. .. \ - .. . . .. \ - . . .. .. . . \ - . . . ... . . . \ - . . . . \ - . ....... . \ - . .. ..... . \ - .. .. . .. \ - ... . . . . \ - .... . . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE7ALCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . . \ - .. . . \ - . . . . \ - .. . . . . \ - . . .. . . .. ... \ - .... . .. . . . .. \ - ... .. . . . .. \ - .. . . . .. \ - ... .. ... \ - ... .... ...... ... \ - ..... .... .......... \ - ... .. ... ..... ... \ - .. . ...... .. \ - . .. . \ - . . \ - .. . . .. \ - . . .. .. ... \ - . . . ... . ... \ - . . . . \ - . ......... . \ - .. .. ...... .. \ - ... .. . . . \ - .... . . . . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE7BLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . . \ - .. . . \ - . . . . \ - .. . . . . \ - . . .. . . .. ... \ - .... . .. . . . .. \ - ... .. . . . .. \ - .. . . .. \ - ... . .. ... \ - ... . .. .... ... \ - ...... .. .......... \ - ... ... .... ..... ... \ - .. . ...... .. \ - . .. . \ - . . . \ - . . .. \ - . .. .. ... \ - .. ... . ... \ - .. . . . \ - .. ........ . \ - ... .. ...... .. \ - .... .. . . . \ - ..... . . . . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE7CLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . . \ - .. . . \ - . . . . \ - .. . . . . \ - . . .. . . .. ... \ - .... . .. . . . .. \ - ... .. . . . .. \ - .. . . . .. \ - ... ... ... \ - ... .... ...... ... \ - ..... ... .......... \ - ... .. .. ... ..... ... \ - .. . ....... .. \ - . .. . . \ - . . \ - .. . . .. \ - . . .. .. ... \ - . . . ... . ... \ - . . . . \ - . .......... . \ - .. ... ..... .. \ - ... .. . . . \ - .... .. . .. . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char FACE8ALCD[] = -"\ - \ - \ - \ - .............. \ - . . . \ - . . .. \ - . . . .. \ - .. . . \ - . . . . \ - .. . . \ - ... . \ - .. . . \ - ... . . . \ - .. . . . . \ - .... .... .... \ - ... ... . . . .. \ - ... . . . .. . .. \ - .... . . . . . ... \ - ... ... ... . ... \ - .. ..... ...... . \ - . ............. ... \ - . .... . ...... .. \ - . .. . . . .. \ - . . . . . . \ - . . . . . . \ - ... ... . .. \ - ... ....... . . \ - ... ......... . . \ - ... ... .. . . \ - ................ . \ - .... . . \ - ..... .. . "; - -static const char GOTGATLINGLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. .. .. \ - .. . . .. \ - .. ..... ..... .. \ - .. . .. .. .. .. . .. \ - ... .. . . . . .. ... \ - ... . . ... \ - ... ... \ - .. .. \ - ..... . . ..... \ - . . ....... . . \ - . . .. . .. . . \ - . . ......... . . \ - . . . . \ - .. . . .. \ - .. ........ .. \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char MUTANTBJLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. . . . . .. \ - .. . . . . .. \ - .. .. . . .. .. \ - ..... .. . . . .. ..... \ - ... . . .. . .. . . ... \ - ... .... . .... ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . . . \ - . . . . \ - . . ....... . . \ - . . . . \ - . ..... . \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -#ifdef SPEAR -static const char GODMODEFACE1LCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. .. \ - .. ..... ..... .. \ - ..... ....... ..... \ - ... . . . . . ... \ - ... . . . . . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . \ - . . \ - . ......... . \ - . . \ - . ..... . \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char GODMODEFACE2LCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. .... .. \ - .. . .. ..... .. \ - ..... ......... ..... \ - ... . . . . . ... \ - ... . . . . . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . \ - . . \ - . ......... . \ - . . \ - . ..... . \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char GODMODEFACE3LCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. .... .. \ - .. .... .. .... \ - ..... ........ . ... \ - ... . . . . . ... \ - ... . . . . . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . \ - . . \ - . ......... . \ - . . \ - . ..... . \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char BJWAITING1LCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. .. .. .. \ - .. ..... ..... .. \ - ..... ......... ..... \ - ... . ... . ... . ... \ - ... . ... \ - .. .. \ - ... . . ... \ - . .. ....... .. . \ - . . . . . . . \ - . . . . \ - . . ..... . . \ - . . \ - . . \ - .. .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char BJWAITING2LCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. .. .. .. \ - .. ..... ..... .. \ - ..... ........... ..... \ - ... . .. . . . .. . ... \ - ... . ... \ - .. .. \ - .... . . .... \ - . . ....... . . \ - . . . . . . . \ - . . . . \ - . ..... . \ - . .. . .. . \ - . . . . . \ - .. . . .. \ - ... ... . . \ - .... . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; - -static const char BJOUCHLCD[] = -"\ - \ - ............... \ - . . \ - . . . \ - . . . ... ... \ - .. . .... . . . .. \ - . . . . . .. . \ - .. . . . . \ - . . . . \ - ... .. \ - .. .. \ - .. ...... ...... .. \ - ..... . . ..... \ - ... . .. . . .. . ... \ - ... . .. .. .. .. . ... \ - ... . . . . ... \ - .. .. \ - ... . . ... \ - . . ....... . . \ - . . . . . . . \ - . . \ - . ....... . \ - . ......... . \ - . . \ - .. ... .. \ - ... . . . \ - .... . . . \ - ............... . \ - ..... . .. \ - .... . . \ - ..... . . \ - ..... . . "; -#endif //SPEAR - -static const char *e_BJFaces[] = { - FACE1ALCD, - FACE1BLCD, - FACE1CLCD, - FACE2ALCD, - FACE2BLCD, - FACE2CLCD, - FACE3ALCD, - FACE3BLCD, - FACE3CLCD, - FACE4ALCD, - FACE4BLCD, - FACE4CLCD, - FACE5ALCD, - FACE5BLCD, - FACE5CLCD, - FACE6ALCD, - FACE6BLCD, - FACE6CLCD, - FACE7ALCD, - FACE7BLCD, - FACE7CLCD, - FACE8ALCD, - GOTGATLINGLCD, -#ifndef SPEAR - MUTANTBJLCD -#else - MUTANTBJLCD, - GODMODEFACE1LCD, - GODMODEFACE2LCD, - GODMODEFACE3LCD, - BJWAITING1LCD, - BJOUCHLCD -#endif -}; diff --git a/id_vh.cpp b/id_vh.cpp index ca29571..5022634 100644 --- a/id_vh.cpp +++ b/id_vh.cpp @@ -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; } diff --git a/id_vl.cpp b/id_vl.cpp index f9d99ee..562d81f 100644 --- a/id_vl.cpp +++ b/id_vl.cpp @@ -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); } } diff --git a/wl_agent.cpp b/wl_agent.cpp index 676f49c..2222f35 100644 --- a/wl_agent.cpp +++ b/wl_agent.cpp @@ -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; diff --git a/wl_draw.cpp b/wl_draw.cpp index adedd4c..6accffc 100644 --- a/wl_draw.cpp +++ b/wl_draw.cpp @@ -1589,6 +1589,7 @@ void ThreeDRefresh (void) US_Print(" fps"); } #endif + SDL_BlitSurface(screenBuffer, NULL, screen, NULL); SDL_Flip(screen); }