Skip to content

Commit

Permalink
ColEm 2.6 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xe1f committed Sep 13, 2010
1 parent ad111f0 commit e4411b6
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 74 deletions.
2 changes: 1 addition & 1 deletion ColEm.mak
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
COLEM=ColEm
PSP_APP_NAME=ColEm PSP
PSP_APP_VER=2.5.2
PSP_APP_VER=2.6.1

PSP_FW_VERSION=200

Expand Down
34 changes: 19 additions & 15 deletions ColEm/Coleco.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/** This file contains implementation for the Coleco **/
/** specific hardware. Initialization code is also here. **/
/** **/
/** Copyright (C) Marat Fayzullin 1994-2007 **/
/** Copyright (C) Marat Fayzullin 1994-2010 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
Expand Down Expand Up @@ -318,9 +318,12 @@ int LoadROM(const char *Cartridge)
/* If ROM not recognized, drop out */
if(!P) { fclose(F);return(0); }

/* Read the rest of the ROM */
/* Clear ROM buffer and store the first two bytes */
memset(P,NORAM,0x8000);
P[0]=Buf[0];
P[1]=Buf[1];

/* Read the rest of the ROM */
#ifdef MINIZIP
if(ZF) J=2+unzReadCurrentFile(ZF,P+2,0x7FFE);
else
Expand Down Expand Up @@ -361,7 +364,7 @@ int LoadROM(const char *Cartridge)
/*************************************************************/
int SaveSTA(const char *StateFile)
{
static byte Header[16] = "STF\032\001\0\0\0\0\0\0\0\0\0\0\0";
static byte Header[16] = "STF\032\002\0\0\0\0\0\0\0\0\0\0\0";
unsigned int State[256],J;
FILE *F;

Expand Down Expand Up @@ -449,7 +452,7 @@ int LoadSTA(const char *StateFile)
/* Read and check the header */
if(fread(Header,1,16,F)!=16)
{ fclose(F);return(0); }
if(memcmp(Header,"STF\032\001",5))
if(memcmp(Header,"STF\032\002",5))
{ fclose(F);return(0); }
J=CartCRC();
if(
Expand Down Expand Up @@ -646,29 +649,30 @@ int ResetColeco(int NewMode)

/* Clear memory (important for NetPlay, to */
/* keep states at both sides consistent) */
memset(RAM_MAIN_LO,NORAM,0x8000);
memset(RAM_MAIN_HI,NORAM,0x8000);
memset(RAM_EXP_LO,NORAM,0x8000);
memset(RAM_EXP_HI,NORAM,0x8000);
memset(RAM_OS7,NORAM,0x2000);
/* Clearing to zeros (Heist) */
memset(RAM_MAIN_LO,0x00,0x8000);
memset(RAM_MAIN_HI,0x00,0x8000);
memset(RAM_EXP_LO,0x00,0x8000);
memset(RAM_EXP_HI,0x00,0x8000);
memset(RAM_OS7,0x00,0x2000);

/* Set up memory pages */
SetMemory(Mode&CV_ADAM? 0x00:0x0F,0x00);

/* Set scanline parameters according to video type */
/* (this has to be done before CPU and VDP are reset) */
VDP.MaxSprites = Mode&CV_ALLSPRITE? 255:TMS9918_MAXSPRITES;
VDP.Scanlines = Mode&CV_PAL? TMS9929_LINES:TMS9918_LINES;
CPU.IPeriod = Mode&CV_PAL? TMS9929_LINE:TMS9918_LINE;

/* Reset TMS9918 VDP */
Reset9918(&VDP,ScrBuffer,ScrWidth,ScrHeight);
/* Set sprite limit */
VDP.MaxSprites = Mode&CV_ALLSPRITE? 255:TMS9918_MAXSPRITES;
/* Reset SN76489 PSG */
Reset76489(&PSG,0);
Sync76489(&PSG,SN76489_SYNC);
/* Reset Z80 CPU */
ResetZ80(&CPU);

/* Set scanline parameters according to video type */
VDP.Scanlines = Mode&CV_PAL? TMS9929_LINES:TMS9918_LINES;
CPU.IPeriod = Mode&CV_PAL? TMS9929_LINE:TMS9918_LINE;

/* Set up the palette */
I = Mode&CV_PALETTE;
I = I==CV_PALETTE0? 0:I==CV_PALETTE1? 16:I==CV_PALETTE2? 32:0;
Expand Down
2 changes: 1 addition & 1 deletion ColEm/Coleco.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/** and Coleco emulation itself. See Z80.h for #defines **/
/** related to Z80 emulation. **/
/** **/
/** Copyright (C) Marat Fayzullin 1994-2007 **/
/** Copyright (C) Marat Fayzullin 1994-2010 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
Expand Down
22 changes: 11 additions & 11 deletions EMULib/DRV9918.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/** TMS9918.h for declarations and TMS9918.c for the main **/
/** code. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2008 **/
/** Copyright (C) Marat Fayzullin 1996-2010 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
Expand Down Expand Up @@ -281,10 +281,9 @@ void RefreshLine1(register TMS9918 *VDP,register byte Y)
/*************************************************************/
void RefreshLine2(register TMS9918 *VDP,register byte Y)
{
register byte X,K,Offset;
register byte *T,*PGT,*CLT;
register pixel *P,FC,BC;
register int J;
register byte X,K,*T,*PGT,*CLT;
register int J,I,PGTMask,CLTMask;

P = (pixel *)(VDP->XBuf)
+ VDP->Width*(Y+(VDP->Height-192)/2)
Expand All @@ -297,19 +296,20 @@ void RefreshLine2(register TMS9918 *VDP,register byte Y)
}
else
{
J = (int)(Y&0xC0)<<5;
PGT = VDP->ChrGen+J;
CLT = VDP->ColTab+J;
J = ((int)(Y&0xC0)<<5)+(Y&0x07);
PGT = VDP->ChrGen;
CLT = VDP->ColTab;
PGTMask = VDP->ChrGenM;
CLTMask = VDP->ColTabM;
T = VDP->ChrTab+((int)(Y&0xF8)<<2);
Offset = Y&0x07;

for(X=0;X<32;X++)
{
J = ((int)*T<<3)+Offset;
K = CLT[J];
I = (int)*T<<3;
K = CLT[(J+I)&CLTMask];
FC = VDP->XPal[K>>4];
BC = VDP->XPal[K&0x0F];
K = PGT[J];
K = PGT[(J+I)&PGTMask];
P[0] = K&0x80? FC:BC;
P[1] = K&0x40? FC:BC;
P[2] = K&0x20? FC:BC;
Expand Down
2 changes: 1 addition & 1 deletion EMULib/EMULib.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/** This file contains platform-independent definitions and **/
/** declarations for the emulation library. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2008 **/
/** Copyright (C) Marat Fayzullin 1996-2010 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
Expand Down
2 changes: 1 addition & 1 deletion EMULib/MIDIFreq.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/** into MIDI octave/note numbers. It is included from the **/
/** Sound.c and SndWin.c files. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2008 **/
/** Copyright (C) Marat Fayzullin 1996-2010 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
Expand Down
2 changes: 1 addition & 1 deletion EMULib/SN76489.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/** This file contains emulation for the SN76489 sound chip **/
/** produced by Intel. See SN76489.h for declarations. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2008 **/
/** Copyright (C) Marat Fayzullin 1996-2010 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
Expand Down
2 changes: 1 addition & 1 deletion EMULib/SN76489.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/** This file contains emulation for the SN76489 sound chip **/
/** produced by Intel. See SN76489.c for the code. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2008 **/
/** Copyright (C) Marat Fayzullin 1996-2010 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
Expand Down
70 changes: 49 additions & 21 deletions EMULib/Sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/** and functions needed to log soundtrack into a MIDI **/
/** file. See Sound.h for declarations. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2008 **/
/** Copyright (C) Marat Fayzullin 1996-2010 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
Expand All @@ -16,7 +16,7 @@
#include <stdio.h>
#include <string.h>

#ifdef UNIX
#if defined(UNIX) || defined(MAEMO) || defined(STMP3700) || defined(NXC2600)
#include <unistd.h>
#endif

Expand Down Expand Up @@ -85,13 +85,31 @@ static struct
int Pos; /* Wave current position in Data */

int Count; /* Phase counter */
} WaveCH[SND_CHANNELS];
} WaveCH[SND_CHANNELS] =
{
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 },
{ SND_MELODIC,0,0,0,0,0,0,0 }
};

/** RenderAudio() Variables *******************************************/
static int SndRate = 0; /* Sound rate (1=Adlib, 0=Off) */
static int NoiseGen = 1; /* Noise generator seed */
int MasterSwitch = 0xFFFF; /* Switches to turn channels on/off */
int MasterVolume = 192; /* Master volume */
static int SndRate = 0; /* Sound rate (0=Off) */
static int NoiseGen = 1; /* Noise generator seed */
int MasterSwitch = 0xFFFF; /* Switches to turn channels on/off */
int MasterVolume = 192; /* Master volume */

/** MIDI Logging Variables ********************************************/
static const char *LogName = 0; /* MIDI logging file name */
Expand Down Expand Up @@ -208,7 +226,7 @@ void SetWave(int Channel,const signed char *Data,int Length,int Rate)
WaveCH[Channel].Type = SND_WAVE;
WaveCH[Channel].Length = Length;
WaveCH[Channel].Rate = Rate;
WaveCH[Channel].Pos = 0;
WaveCH[Channel].Pos = Length? WaveCH[Channel].Pos%Length:0;
WaveCH[Channel].Count = 0;
WaveCH[Channel].Data = Data;

Expand Down Expand Up @@ -565,16 +583,14 @@ unsigned int InitSound(unsigned int Rate,unsigned int Latency)
/* Shut down current sound */
TrashSound();

/* Initialize internal variables */
SndRate = 0;
MasterVolume = 0;
MasterSwitch = 0;
NoiseGen = 1;
/* Initialize internal variables (keeping MasterVolume/MasterSwitch!) */
SndRate = 0;
NoiseGen = 1;

/* Reset sound parameters */
for(I=0;I<SND_CHANNELS;I++)
{
WaveCH[I].Type = SND_MELODIC;
/* NOTICE: Preserving Type value! */
WaveCH[I].Count = 0;
WaveCH[I].Volume = 0;
WaveCH[I].Freq = 0;
Expand All @@ -591,7 +607,7 @@ unsigned int InitSound(unsigned int Rate,unsigned int Latency)
if(!Rate) { SndRate=0;return(0); }

/* Done */
SetChannels(192,(1<<SND_CHANNELS)-1);
SetChannels(MasterVolume,MasterSwitch);
return(SndRate=Rate);
}

Expand All @@ -603,13 +619,16 @@ void TrashSound(void)
/* Sound is now off */
SndRate = 0;
/* Shut down platform-dependent audio */
#if !defined(NO_AUDIO_PLAYBACK)
#if defined(WINDOWS)
WinTrashSound();
#else
TrashAudio();
#endif
#endif
}

#if !defined(NO_AUDIO_PLAYBACK)
/** RenderAudio() ********************************************/
/** Render given number of melodic sound samples into an **/
/** integer buffer for mixing. **/
Expand All @@ -633,8 +652,9 @@ void RenderAudio(int *Wave,unsigned int Samples)
/* Waveform data must have correct length! */
if(WaveCH[J].Length<=0) break;
/* Start counting */
K = WaveCH[J].Rate>0? (SndRate<<15)/WaveCH[J].Freq/WaveCH[J].Rate
: (SndRate<<15)/WaveCH[J].Freq/WaveCH[J].Length;
K = WaveCH[J].Rate>0?
(SndRate<<15)/WaveCH[J].Freq/WaveCH[J].Rate
: (SndRate<<15)/WaveCH[J].Freq/WaveCH[J].Length;
L1 = WaveCH[J].Pos%WaveCH[J].Length;
L2 = WaveCH[J].Count;
A1 = WaveCH[J].Data[L1]*V;
Expand Down Expand Up @@ -738,8 +758,12 @@ unsigned int PlayAudio(int *Wave,unsigned int Samples)
{
D = ((*Wave++)*MasterVolume)/255;
D = D>32767? 32767:D<-32768? -32768:D;
#ifdef BPS16
#if defined(BPU16)
Buf[I] = D+32768;
#elif defined(BPS16)
Buf[I] = D;
#elif defined(BPU8)
Buf[I] = (D>>8)+128;
#else
Buf[I] = D>>8;
#endif
Expand All @@ -765,16 +789,20 @@ unsigned int RenderAndPlayAudio(unsigned int Samples)
/* Exit if wave sound not initialized */
if(SndRate<8192) return(0);

J = GetFreeAudio();
Samples = Samples<J? Samples:J;

/* Render and play sound */
for(I=0;(I<Samples)&&(J=GetFreeAudio());I+=J)
for(I=0;I<Samples;I+=J)
{
J = J<Samples? J:Samples;
J = Samples-I;
J = J<sizeof(Buf)/sizeof(Buf[0])? J:sizeof(Buf)/sizeof(Buf[0]);
memset(Buf,0,J*sizeof(Buf[0]));
RenderAudio(Buf,J);
J = PlayAudio(Buf,J);
if(PlayAudio(Buf,J)<J) { I+=J;break; }
}

/* Return number of samples rendered */
return(I);
}
#endif /* !NO_AUDIO_PLAYBACK */
4 changes: 2 additions & 2 deletions EMULib/Sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/** functions needed to log soundtrack into a MIDI file. **/
/** See Sound.c and the sound drivers for the code. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2008 **/
/** Copyright (C) Marat Fayzullin 1996-2010 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
Expand Down Expand Up @@ -141,7 +141,7 @@ int MIDILogging(int Switch);
/*************************************************************/
void MIDITicks(int N);

#if !defined(MSDOS) & !defined(UNIX) & !defined(WINDOWS) & !defined(S60) & !defined(UIQ)
#if !defined(MSDOS) & !defined(UNIX) & !defined(MAEMO) & !defined(WINDOWS) & !defined(S60) & !defined(UIQ)
#define SND_CHANNELS MIDI_CHANNELS /* Default number */
#endif

Expand Down
Loading

0 comments on commit e4411b6

Please sign in to comment.