mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-25 20:16:53 +01:00
July 24, 2008 update by theinternetftw
This commit is contained in:
parent
5a65f55992
commit
9644c251ef
270
src/Globals.cpp
270
src/Globals.cpp
@ -1,135 +1,135 @@
|
|||||||
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
|
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
|
||||||
// Copyright (C) 1999-2003 Forgotten
|
// Copyright (C) 1999-2003 Forgotten
|
||||||
// Copyright (C) 2004 Forgotten and the VBA development team
|
// Copyright (C) 2004 Forgotten and the VBA development team
|
||||||
|
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This program is free software; you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
// the Free Software Foundation; either version 2, or(at your option)
|
// the Free Software Foundation; either version 2, or(at your option)
|
||||||
// any later version.
|
// any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program; if not, write to the Free Software Foundation,
|
// along with this program; if not, write to the Free Software Foundation,
|
||||||
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "GBA.h"
|
#include "GBA.h"
|
||||||
|
|
||||||
reg_pair reg[45];
|
reg_pair reg[45];
|
||||||
memoryMap map[256];
|
memoryMap map[256];
|
||||||
bool ioReadable[0x400];
|
bool ioReadable[0x400];
|
||||||
bool N_FLAG = 0;
|
bool N_FLAG = 0;
|
||||||
bool C_FLAG = 0;
|
bool C_FLAG = 0;
|
||||||
bool Z_FLAG = 0;
|
bool Z_FLAG = 0;
|
||||||
bool V_FLAG = 0;
|
bool V_FLAG = 0;
|
||||||
bool armState = true;
|
bool armState = true;
|
||||||
bool armIrqEnable = true;
|
bool armIrqEnable = true;
|
||||||
u32 armNextPC = 0x00000000;
|
u32 armNextPC = 0x00000000;
|
||||||
int armMode = 0x1f;
|
int armMode = 0x1f;
|
||||||
u32 stop = 0x08000568;
|
u32 stop = 0x08000568;
|
||||||
int saveType = 0;
|
int saveType = 0;
|
||||||
bool useBios = false;
|
bool useBios = false;
|
||||||
bool skipBios = false;
|
bool skipBios = false;
|
||||||
int frameSkip = 1;
|
int frameSkip = 1;
|
||||||
bool speedup = false;
|
bool speedup = false;
|
||||||
bool synchronize = true;
|
bool synchronize = true;
|
||||||
bool cpuDisableSfx = false;
|
bool cpuDisableSfx = false;
|
||||||
bool cpuIsMultiBoot = false;
|
bool cpuIsMultiBoot = false;
|
||||||
bool parseDebug = true;
|
bool parseDebug = false;
|
||||||
int layerSettings = 0xff00;
|
int layerSettings = 0xff00;
|
||||||
int layerEnable = 0xff00;
|
int layerEnable = 0xff00;
|
||||||
bool speedHack = false;
|
bool speedHack = false;
|
||||||
int cpuSaveType = 0;
|
int cpuSaveType = 0;
|
||||||
bool cpuEnhancedDetection = true;
|
bool cpuEnhancedDetection = true;
|
||||||
bool cheatsEnabled = true;
|
bool cheatsEnabled = false;
|
||||||
|
|
||||||
u8 *bios = NULL;
|
u8 *bios = NULL;
|
||||||
u8 *rom = NULL;
|
u8 *rom = NULL;
|
||||||
u8 *internalRAM = NULL;
|
u8 *internalRAM = NULL;
|
||||||
u8 *workRAM = NULL;
|
u8 *workRAM = NULL;
|
||||||
u8 *paletteRAM = NULL;
|
u8 *paletteRAM = NULL;
|
||||||
u8 *vram = NULL;
|
u8 *vram = NULL;
|
||||||
u8 *pix = NULL;
|
u8 *pix = NULL;
|
||||||
u8 *oam = NULL;
|
u8 *oam = NULL;
|
||||||
u8 *ioMem = NULL;
|
u8 *ioMem = NULL;
|
||||||
|
|
||||||
u16 DISPCNT = 0x0080;
|
u16 DISPCNT = 0x0080;
|
||||||
u16 DISPSTAT = 0x0000;
|
u16 DISPSTAT = 0x0000;
|
||||||
u16 VCOUNT = 0x0000;
|
u16 VCOUNT = 0x0000;
|
||||||
u16 BG0CNT = 0x0000;
|
u16 BG0CNT = 0x0000;
|
||||||
u16 BG1CNT = 0x0000;
|
u16 BG1CNT = 0x0000;
|
||||||
u16 BG2CNT = 0x0000;
|
u16 BG2CNT = 0x0000;
|
||||||
u16 BG3CNT = 0x0000;
|
u16 BG3CNT = 0x0000;
|
||||||
u16 BG0HOFS = 0x0000;
|
u16 BG0HOFS = 0x0000;
|
||||||
u16 BG0VOFS = 0x0000;
|
u16 BG0VOFS = 0x0000;
|
||||||
u16 BG1HOFS = 0x0000;
|
u16 BG1HOFS = 0x0000;
|
||||||
u16 BG1VOFS = 0x0000;
|
u16 BG1VOFS = 0x0000;
|
||||||
u16 BG2HOFS = 0x0000;
|
u16 BG2HOFS = 0x0000;
|
||||||
u16 BG2VOFS = 0x0000;
|
u16 BG2VOFS = 0x0000;
|
||||||
u16 BG3HOFS = 0x0000;
|
u16 BG3HOFS = 0x0000;
|
||||||
u16 BG3VOFS = 0x0000;
|
u16 BG3VOFS = 0x0000;
|
||||||
u16 BG2PA = 0x0100;
|
u16 BG2PA = 0x0100;
|
||||||
u16 BG2PB = 0x0000;
|
u16 BG2PB = 0x0000;
|
||||||
u16 BG2PC = 0x0000;
|
u16 BG2PC = 0x0000;
|
||||||
u16 BG2PD = 0x0100;
|
u16 BG2PD = 0x0100;
|
||||||
u16 BG2X_L = 0x0000;
|
u16 BG2X_L = 0x0000;
|
||||||
u16 BG2X_H = 0x0000;
|
u16 BG2X_H = 0x0000;
|
||||||
u16 BG2Y_L = 0x0000;
|
u16 BG2Y_L = 0x0000;
|
||||||
u16 BG2Y_H = 0x0000;
|
u16 BG2Y_H = 0x0000;
|
||||||
u16 BG3PA = 0x0100;
|
u16 BG3PA = 0x0100;
|
||||||
u16 BG3PB = 0x0000;
|
u16 BG3PB = 0x0000;
|
||||||
u16 BG3PC = 0x0000;
|
u16 BG3PC = 0x0000;
|
||||||
u16 BG3PD = 0x0100;
|
u16 BG3PD = 0x0100;
|
||||||
u16 BG3X_L = 0x0000;
|
u16 BG3X_L = 0x0000;
|
||||||
u16 BG3X_H = 0x0000;
|
u16 BG3X_H = 0x0000;
|
||||||
u16 BG3Y_L = 0x0000;
|
u16 BG3Y_L = 0x0000;
|
||||||
u16 BG3Y_H = 0x0000;
|
u16 BG3Y_H = 0x0000;
|
||||||
u16 WIN0H = 0x0000;
|
u16 WIN0H = 0x0000;
|
||||||
u16 WIN1H = 0x0000;
|
u16 WIN1H = 0x0000;
|
||||||
u16 WIN0V = 0x0000;
|
u16 WIN0V = 0x0000;
|
||||||
u16 WIN1V = 0x0000;
|
u16 WIN1V = 0x0000;
|
||||||
u16 WININ = 0x0000;
|
u16 WININ = 0x0000;
|
||||||
u16 WINOUT = 0x0000;
|
u16 WINOUT = 0x0000;
|
||||||
u16 MOSAIC = 0x0000;
|
u16 MOSAIC = 0x0000;
|
||||||
u16 BLDMOD = 0x0000;
|
u16 BLDMOD = 0x0000;
|
||||||
u16 COLEV = 0x0000;
|
u16 COLEV = 0x0000;
|
||||||
u16 COLY = 0x0000;
|
u16 COLY = 0x0000;
|
||||||
u16 DM0SAD_L = 0x0000;
|
u16 DM0SAD_L = 0x0000;
|
||||||
u16 DM0SAD_H = 0x0000;
|
u16 DM0SAD_H = 0x0000;
|
||||||
u16 DM0DAD_L = 0x0000;
|
u16 DM0DAD_L = 0x0000;
|
||||||
u16 DM0DAD_H = 0x0000;
|
u16 DM0DAD_H = 0x0000;
|
||||||
u16 DM0CNT_L = 0x0000;
|
u16 DM0CNT_L = 0x0000;
|
||||||
u16 DM0CNT_H = 0x0000;
|
u16 DM0CNT_H = 0x0000;
|
||||||
u16 DM1SAD_L = 0x0000;
|
u16 DM1SAD_L = 0x0000;
|
||||||
u16 DM1SAD_H = 0x0000;
|
u16 DM1SAD_H = 0x0000;
|
||||||
u16 DM1DAD_L = 0x0000;
|
u16 DM1DAD_L = 0x0000;
|
||||||
u16 DM1DAD_H = 0x0000;
|
u16 DM1DAD_H = 0x0000;
|
||||||
u16 DM1CNT_L = 0x0000;
|
u16 DM1CNT_L = 0x0000;
|
||||||
u16 DM1CNT_H = 0x0000;
|
u16 DM1CNT_H = 0x0000;
|
||||||
u16 DM2SAD_L = 0x0000;
|
u16 DM2SAD_L = 0x0000;
|
||||||
u16 DM2SAD_H = 0x0000;
|
u16 DM2SAD_H = 0x0000;
|
||||||
u16 DM2DAD_L = 0x0000;
|
u16 DM2DAD_L = 0x0000;
|
||||||
u16 DM2DAD_H = 0x0000;
|
u16 DM2DAD_H = 0x0000;
|
||||||
u16 DM2CNT_L = 0x0000;
|
u16 DM2CNT_L = 0x0000;
|
||||||
u16 DM2CNT_H = 0x0000;
|
u16 DM2CNT_H = 0x0000;
|
||||||
u16 DM3SAD_L = 0x0000;
|
u16 DM3SAD_L = 0x0000;
|
||||||
u16 DM3SAD_H = 0x0000;
|
u16 DM3SAD_H = 0x0000;
|
||||||
u16 DM3DAD_L = 0x0000;
|
u16 DM3DAD_L = 0x0000;
|
||||||
u16 DM3DAD_H = 0x0000;
|
u16 DM3DAD_H = 0x0000;
|
||||||
u16 DM3CNT_L = 0x0000;
|
u16 DM3CNT_L = 0x0000;
|
||||||
u16 DM3CNT_H = 0x0000;
|
u16 DM3CNT_H = 0x0000;
|
||||||
u16 TM0D = 0x0000;
|
u16 TM0D = 0x0000;
|
||||||
u16 TM0CNT = 0x0000;
|
u16 TM0CNT = 0x0000;
|
||||||
u16 TM1D = 0x0000;
|
u16 TM1D = 0x0000;
|
||||||
u16 TM1CNT = 0x0000;
|
u16 TM1CNT = 0x0000;
|
||||||
u16 TM2D = 0x0000;
|
u16 TM2D = 0x0000;
|
||||||
u16 TM2CNT = 0x0000;
|
u16 TM2CNT = 0x0000;
|
||||||
u16 TM3D = 0x0000;
|
u16 TM3D = 0x0000;
|
||||||
u16 TM3CNT = 0x0000;
|
u16 TM3CNT = 0x0000;
|
||||||
u16 P1 = 0xFFFF;
|
u16 P1 = 0xFFFF;
|
||||||
u16 IE = 0x0000;
|
u16 IE = 0x0000;
|
||||||
u16 IF = 0x0000;
|
u16 IF = 0x0000;
|
||||||
u16 IME = 0x0000;
|
u16 IME = 0x0000;
|
||||||
|
@ -103,7 +103,6 @@ NGCPad()
|
|||||||
{
|
{
|
||||||
float mag,ang;
|
float mag,ang;
|
||||||
int b = wpad->exp.classic.btns;
|
int b = wpad->exp.classic.btns;
|
||||||
/* Stolen Shamelessly out of Falco's unofficial SNES9x update */
|
|
||||||
ang = wpad->exp.classic.ljs.ang;
|
ang = wpad->exp.classic.ljs.ang;
|
||||||
mag = wpad->exp.classic.ljs.mag;
|
mag = wpad->exp.classic.ljs.mag;
|
||||||
|
|
||||||
@ -116,7 +115,7 @@ NGCPad()
|
|||||||
res |= VBA_DOWN;
|
res |= VBA_DOWN;
|
||||||
if (ang > 203.5 & ang <= 337.5)
|
if (ang > 203.5 & ang <= 337.5)
|
||||||
res |= VBA_LEFT;
|
res |= VBA_LEFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x_s = 0; //getStickValue(&wpad.exp.classic.ljs, STICK_X, 127);
|
int x_s = 0; //getStickValue(&wpad.exp.classic.ljs, STICK_X, 127);
|
||||||
int y_s = 0; //getStickValue(&wpad.exp.classic.ljs, STICK_Y, 127);
|
int y_s = 0; //getStickValue(&wpad.exp.classic.ljs, STICK_Y, 127);
|
||||||
@ -151,25 +150,24 @@ NGCPad()
|
|||||||
res |= VBA_BUTTON_R;
|
res |= VBA_BUTTON_R;
|
||||||
|
|
||||||
if (b & CLASSIC_CTRL_BUTTON_HOME)
|
if (b & CLASSIC_CTRL_BUTTON_HOME)
|
||||||
menuCalled = 1;
|
menuCalled = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
//user needs a GC remote
|
//user needs a GC remote
|
||||||
else
|
PAD_ScanPads();
|
||||||
{
|
p = PAD_ButtonsHeld(0);
|
||||||
p = PAD_ButtonsHeld(0);
|
|
||||||
x = PAD_StickX(0);
|
x = PAD_StickX(0);
|
||||||
y = PAD_StickY(0);
|
y = PAD_StickY(0);
|
||||||
if (x * x + y * y > padcal * padcal)
|
if (x * x + y * y > padcal * padcal)
|
||||||
{
|
{
|
||||||
if (x > 0 && y == 0)
|
if (x > 0 && y == 0)
|
||||||
res |= VBA_RIGHT;
|
res |= VBA_RIGHT;
|
||||||
if (x < 0 && y == 0)
|
if (x < 0 && y == 0)
|
||||||
res |= VBA_LEFT;
|
res |= VBA_LEFT;
|
||||||
if (x == 0 && y > 0)
|
if (x == 0 && y > 0)
|
||||||
res |= VBA_UP;
|
res |= VBA_UP;
|
||||||
if (x == 0 && y < 0)
|
if (x == 0 && y < 0)
|
||||||
res |= VBA_DOWN;
|
res |= VBA_DOWN;
|
||||||
|
|
||||||
/*** Recalc left / right ***/
|
/*** Recalc left / right ***/
|
||||||
t = (float) y / x;
|
t = (float) y / x;
|
||||||
@ -222,9 +220,9 @@ NGCPad()
|
|||||||
res |= VBA_BUTTON_R;
|
res |= VBA_BUTTON_R;
|
||||||
|
|
||||||
if((p & PAD_BUTTON_X) && (p & PAD_BUTTON_Y))
|
if((p & PAD_BUTTON_X) && (p & PAD_BUTTON_Y))
|
||||||
menuCalled = 1;
|
menuCalled = 1;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GC_BUILD
|
#ifdef GC_BUILD
|
||||||
p = PAD_ButtonsHeld(0);
|
p = PAD_ButtonsHeld(0);
|
||||||
|
@ -1,264 +1,264 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Generic GX Support for Emulators
|
* Generic GX Support for Emulators
|
||||||
* softdev 2007
|
* softdev 2007
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*
|
*
|
||||||
* NGC GX Video Functions
|
* NGC GX Video Functions
|
||||||
*
|
*
|
||||||
* These are pretty standard functions to setup and use GX scaling.
|
* These are pretty standard functions to setup and use GX scaling.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include <gccore.h>
|
#include <gccore.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
/*** External 2D Video ***/
|
/*** External 2D Video ***/
|
||||||
extern u32 whichfb;
|
extern u32 whichfb;
|
||||||
extern u32 *xfb[2];
|
extern u32 *xfb[2];
|
||||||
extern GXRModeObj *vmode;
|
extern GXRModeObj *vmode;
|
||||||
|
|
||||||
/*** 3D GX ***/
|
/*** 3D GX ***/
|
||||||
#define DEFAULT_FIFO_SIZE ( 256 * 1024 )
|
#define DEFAULT_FIFO_SIZE ( 256 * 1024 )
|
||||||
static u8 gp_fifo[DEFAULT_FIFO_SIZE] ATTRIBUTE_ALIGN(32);
|
static u8 gp_fifo[DEFAULT_FIFO_SIZE] ATTRIBUTE_ALIGN(32);
|
||||||
|
|
||||||
/*** Texture memory ***/
|
/*** Texture memory ***/
|
||||||
static u8 *texturemem;
|
static u8 *texturemem;
|
||||||
static int texturesize;
|
static int texturesize;
|
||||||
|
|
||||||
GXTexObj texobj;
|
GXTexObj texobj;
|
||||||
static Mtx view;
|
static Mtx view;
|
||||||
static int vwidth, vheight, oldvwidth, oldvheight;
|
static int vwidth, vheight, oldvwidth, oldvheight;
|
||||||
|
|
||||||
#define HASPECT 80
|
#define HASPECT 80
|
||||||
#define VASPECT 60
|
#define VASPECT 45
|
||||||
|
|
||||||
/* New texture based scaler */
|
/* New texture based scaler */
|
||||||
typedef struct tagcamera
|
typedef struct tagcamera
|
||||||
{
|
{
|
||||||
Vector pos;
|
Vector pos;
|
||||||
Vector up;
|
Vector up;
|
||||||
Vector view;
|
Vector view;
|
||||||
}
|
}
|
||||||
camera;
|
camera;
|
||||||
|
|
||||||
/*** Square Matrix
|
/*** Square Matrix
|
||||||
This structure controls the size of the image on the screen.
|
This structure controls the size of the image on the screen.
|
||||||
Think of the output as a -80 x 80 by -60 x 60 graph.
|
Think of the output as a -80 x 80 by -60 x 60 graph.
|
||||||
***/
|
***/
|
||||||
static s16 square[] ATTRIBUTE_ALIGN(32) = {
|
static s16 square[] ATTRIBUTE_ALIGN(32) = {
|
||||||
/*
|
/*
|
||||||
* X, Y, Z
|
* X, Y, Z
|
||||||
* Values set are for roughly 4:3 aspect
|
* Values set are for roughly 4:3 aspect
|
||||||
*/
|
*/
|
||||||
-HASPECT, VASPECT, 0, // 0
|
-HASPECT, VASPECT, 0, // 0
|
||||||
HASPECT, VASPECT, 0, // 1
|
HASPECT, VASPECT, 0, // 1
|
||||||
HASPECT, -VASPECT, 0, // 2
|
HASPECT, -VASPECT, 0, // 2
|
||||||
-HASPECT, -VASPECT, 0, // 3
|
-HASPECT, -VASPECT, 0, // 3
|
||||||
};
|
};
|
||||||
|
|
||||||
static camera cam = { {0.0F, 0.0F, 0.0F},
|
static camera cam = { {0.0F, 0.0F, 0.0F},
|
||||||
{0.0F, 0.5F, 0.0F},
|
{0.0F, 0.5F, 0.0F},
|
||||||
{0.0F, 0.0F, -0.5F}
|
{0.0F, 0.0F, -0.5F}
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Scaler Support Functions
|
* Scaler Support Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void draw_init(void)
|
static void draw_init(void)
|
||||||
{
|
{
|
||||||
GX_ClearVtxDesc();
|
GX_ClearVtxDesc();
|
||||||
GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
|
GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
|
||||||
GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8);
|
GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8);
|
||||||
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
||||||
|
|
||||||
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
|
||||||
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
|
||||||
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
||||||
|
|
||||||
GX_SetArray(GX_VA_POS, square, 3 * sizeof(s16));
|
GX_SetArray(GX_VA_POS, square, 3 * sizeof(s16));
|
||||||
|
|
||||||
GX_SetNumTexGens(1);
|
GX_SetNumTexGens(1);
|
||||||
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
|
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
|
||||||
|
|
||||||
GX_InvalidateTexAll();
|
GX_InvalidateTexAll();
|
||||||
|
|
||||||
GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565,
|
GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565,
|
||||||
GX_CLAMP, GX_CLAMP, GX_FALSE);
|
GX_CLAMP, GX_CLAMP, GX_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_vert(u8 pos, u8 c, f32 s, f32 t)
|
static void draw_vert(u8 pos, u8 c, f32 s, f32 t)
|
||||||
{
|
{
|
||||||
GX_Position1x8(pos);
|
GX_Position1x8(pos);
|
||||||
GX_Color1x8(c);
|
GX_Color1x8(c);
|
||||||
GX_TexCoord2f32(s, t);
|
GX_TexCoord2f32(s, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_square(Mtx v)
|
static void draw_square(Mtx v)
|
||||||
{
|
{
|
||||||
Mtx m; // model matrix.
|
Mtx m; // model matrix.
|
||||||
Mtx mv; // modelview matrix.
|
Mtx mv; // modelview matrix.
|
||||||
|
|
||||||
guMtxIdentity(m);
|
guMtxIdentity(m);
|
||||||
guMtxTransApply(m, m, 0, 0, -100);
|
guMtxTransApply(m, m, 0, 0, -100);
|
||||||
guMtxConcat(v, m, mv);
|
guMtxConcat(v, m, mv);
|
||||||
|
|
||||||
GX_LoadPosMtxImm(mv, GX_PNMTX0);
|
GX_LoadPosMtxImm(mv, GX_PNMTX0);
|
||||||
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
|
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
|
||||||
draw_vert(0, 0, 0.0, 0.0);
|
draw_vert(0, 0, 0.0, 0.0);
|
||||||
draw_vert(1, 0, 1.0, 0.0);
|
draw_vert(1, 0, 1.0, 0.0);
|
||||||
draw_vert(2, 0, 1.0, 1.0);
|
draw_vert(2, 0, 1.0, 1.0);
|
||||||
draw_vert(3, 0, 0.0, 1.0);
|
draw_vert(3, 0, 0.0, 1.0);
|
||||||
GX_End();
|
GX_End();
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* StartGX
|
* StartGX
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
void GX_Start(int width, int height, int haspect, int vaspect)
|
void GX_Start(int width, int height, int haspect, int vaspect)
|
||||||
{
|
{
|
||||||
Mtx p;
|
Mtx p;
|
||||||
|
|
||||||
/*** Set new aspect ***/
|
/*** Set new aspect (now with crap AR hack!) ***/
|
||||||
square[0] = square[9] = -haspect;
|
square[0] = square[9] = (-haspect - 7);
|
||||||
square[3] = square[6] = haspect;
|
square[3] = square[6] = (haspect + 7);
|
||||||
square[1] = square[4] = vaspect;
|
square[1] = square[4] = (vaspect + 7);
|
||||||
square[7] = square[10] = -vaspect;
|
square[7] = square[10] = (-vaspect - 7);
|
||||||
|
|
||||||
/*** Allocate 32byte aligned texture memory ***/
|
/*** Allocate 32byte aligned texture memory ***/
|
||||||
texturesize = (width * height) * 2;
|
texturesize = (width * height) * 2;
|
||||||
texturemem = (u8 *) memalign(32, texturesize);
|
texturemem = (u8 *) memalign(32, texturesize);
|
||||||
|
|
||||||
GXColor gxbackground = { 0, 0, 0, 0xff };
|
GXColor gxbackground = { 0, 0, 0, 0xff };
|
||||||
|
|
||||||
/*** Clear out FIFO area ***/
|
/*** Clear out FIFO area ***/
|
||||||
memset(&gp_fifo, 0, DEFAULT_FIFO_SIZE);
|
memset(&gp_fifo, 0, DEFAULT_FIFO_SIZE);
|
||||||
|
|
||||||
/*** Initialise GX ***/
|
/*** Initialise GX ***/
|
||||||
GX_Init(&gp_fifo, DEFAULT_FIFO_SIZE);
|
GX_Init(&gp_fifo, DEFAULT_FIFO_SIZE);
|
||||||
GX_SetCopyClear(gxbackground, 0x00ffffff);
|
GX_SetCopyClear(gxbackground, 0x00ffffff);
|
||||||
|
|
||||||
GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1);
|
GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1);
|
||||||
GX_SetDispCopyYScale((f32) vmode->xfbHeight / (f32) vmode->efbHeight);
|
GX_SetDispCopyYScale((f32) vmode->xfbHeight / (f32) vmode->efbHeight);
|
||||||
GX_SetScissor(0, 0, vmode->fbWidth, vmode->efbHeight);
|
GX_SetScissor(0, 0, vmode->fbWidth, vmode->efbHeight);
|
||||||
GX_SetDispCopySrc(0, 0, vmode->fbWidth, vmode->efbHeight);
|
GX_SetDispCopySrc(0, 0, vmode->fbWidth, vmode->efbHeight);
|
||||||
GX_SetDispCopyDst(vmode->fbWidth, vmode->xfbHeight);
|
GX_SetDispCopyDst(vmode->fbWidth, vmode->xfbHeight);
|
||||||
GX_SetCopyFilter(vmode->aa, vmode->sample_pattern, GX_TRUE,
|
GX_SetCopyFilter(vmode->aa, vmode->sample_pattern, GX_TRUE,
|
||||||
vmode->vfilter);
|
vmode->vfilter);
|
||||||
GX_SetFieldMode(vmode->field_rendering,
|
GX_SetFieldMode(vmode->field_rendering,
|
||||||
((vmode->viHeight ==
|
((vmode->viHeight ==
|
||||||
2 * vmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
|
2 * vmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
|
||||||
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
|
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
|
||||||
GX_SetCullMode(GX_CULL_NONE);
|
GX_SetCullMode(GX_CULL_NONE);
|
||||||
GX_CopyDisp(xfb[whichfb ^ 1], GX_TRUE);
|
GX_CopyDisp(xfb[whichfb ^ 1], GX_TRUE);
|
||||||
GX_SetDispCopyGamma(GX_GM_1_0);
|
GX_SetDispCopyGamma(GX_GM_1_0);
|
||||||
|
|
||||||
guPerspective(p, 60, 1.33F, 10.0F, 1000.0F);
|
guPerspective(p, 60, 1.33F, 10.0F, 1000.0F);
|
||||||
GX_LoadProjectionMtx(p, GX_PERSPECTIVE);
|
GX_LoadProjectionMtx(p, GX_PERSPECTIVE);
|
||||||
memset(texturemem, 0, texturesize);
|
memset(texturemem, 0, texturesize);
|
||||||
|
|
||||||
/*** Setup for first call to scaler ***/
|
/*** Setup for first call to scaler ***/
|
||||||
vwidth = vheight = -1;
|
vwidth = vheight = -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* GX_Render
|
* GX_Render
|
||||||
*
|
*
|
||||||
* Pass in a buffer, width and height to update as a tiled RGB565 texture
|
* Pass in a buffer, width and height to update as a tiled RGB565 texture
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
void GX_Render(int width, int height, u8 * buffer, int pitch)
|
void GX_Render(int width, int height, u8 * buffer, int pitch)
|
||||||
{
|
{
|
||||||
int h, w;
|
int h, w;
|
||||||
long long int *dst = (long long int *) texturemem;
|
long long int *dst = (long long int *) texturemem;
|
||||||
long long int *src1 = (long long int *) buffer;
|
long long int *src1 = (long long int *) buffer;
|
||||||
long long int *src2 = (long long int *) (buffer + pitch);
|
long long int *src2 = (long long int *) (buffer + pitch);
|
||||||
long long int *src3 = (long long int *) (buffer + (pitch * 2));
|
long long int *src3 = (long long int *) (buffer + (pitch * 2));
|
||||||
long long int *src4 = (long long int *) (buffer + (pitch * 3));
|
long long int *src4 = (long long int *) (buffer + (pitch * 3));
|
||||||
int rowpitch = (pitch >> 3) * 3;
|
int rowpitch = (pitch >> 3) * 3;
|
||||||
int rowadjust = ( pitch % 8 ) * 4;
|
int rowadjust = ( pitch % 8 ) * 4;
|
||||||
char *ra = NULL;
|
char *ra = NULL;
|
||||||
|
|
||||||
vwidth = width;
|
vwidth = width;
|
||||||
vheight = height;
|
vheight = height;
|
||||||
|
|
||||||
whichfb ^= 1;
|
whichfb ^= 1;
|
||||||
|
|
||||||
if ((oldvheight != vheight) || (oldvwidth != vwidth))
|
if ((oldvheight != vheight) || (oldvwidth != vwidth))
|
||||||
{
|
{
|
||||||
/** Update scaling **/
|
/** Update scaling **/
|
||||||
oldvwidth = vwidth;
|
oldvwidth = vwidth;
|
||||||
oldvheight = vheight;
|
oldvheight = vheight;
|
||||||
draw_init();
|
draw_init();
|
||||||
memset(&view, 0, sizeof(Mtx));
|
memset(&view, 0, sizeof(Mtx));
|
||||||
guLookAt(view, &cam.pos, &cam.up, &cam.view);
|
guLookAt(view, &cam.pos, &cam.up, &cam.view);
|
||||||
GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1);
|
GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GX_InvVtxCache();
|
GX_InvVtxCache();
|
||||||
GX_InvalidateTexAll();
|
GX_InvalidateTexAll();
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL);
|
||||||
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
|
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
|
||||||
|
|
||||||
for (h = 0; h < vheight; h += 4)
|
for (h = 0; h < vheight; h += 4)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (w = 0; w < (vwidth >> 2); w++)
|
for (w = 0; w < (vwidth >> 2); w++)
|
||||||
{
|
{
|
||||||
*dst++ = *src1++;
|
*dst++ = *src1++;
|
||||||
*dst++ = *src2++;
|
*dst++ = *src2++;
|
||||||
*dst++ = *src3++;
|
*dst++ = *src3++;
|
||||||
*dst++ = *src4++;
|
*dst++ = *src4++;
|
||||||
}
|
}
|
||||||
|
|
||||||
src1 += rowpitch;
|
src1 += rowpitch;
|
||||||
src2 += rowpitch;
|
src2 += rowpitch;
|
||||||
src3 += rowpitch;
|
src3 += rowpitch;
|
||||||
src4 += rowpitch;
|
src4 += rowpitch;
|
||||||
|
|
||||||
if ( rowadjust )
|
if ( rowadjust )
|
||||||
{
|
{
|
||||||
ra = (char *)src1;
|
ra = (char *)src1;
|
||||||
src1 = (long long int *)(ra + rowadjust);
|
src1 = (long long int *)(ra + rowadjust);
|
||||||
ra = (char *)src2;
|
ra = (char *)src2;
|
||||||
src2 = (long long int *)(ra + rowadjust);
|
src2 = (long long int *)(ra + rowadjust);
|
||||||
ra = (char *)src3;
|
ra = (char *)src3;
|
||||||
src3 = (long long int *)(ra + rowadjust);
|
src3 = (long long int *)(ra + rowadjust);
|
||||||
ra = (char *)src4;
|
ra = (char *)src4;
|
||||||
src4 = (long long int *)(ra + rowadjust);
|
src4 = (long long int *)(ra + rowadjust);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DCFlushRange(texturemem, texturesize);
|
DCFlushRange(texturemem, texturesize);
|
||||||
|
|
||||||
GX_SetNumChans(1);
|
GX_SetNumChans(1);
|
||||||
GX_LoadTexObj(&texobj, GX_TEXMAP0);
|
GX_LoadTexObj(&texobj, GX_TEXMAP0);
|
||||||
|
|
||||||
draw_square(view);
|
draw_square(view);
|
||||||
|
|
||||||
GX_DrawDone();
|
GX_DrawDone();
|
||||||
|
|
||||||
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
|
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
|
||||||
GX_SetColorUpdate(GX_TRUE);
|
GX_SetColorUpdate(GX_TRUE);
|
||||||
GX_CopyDisp(xfb[whichfb], GX_TRUE);
|
GX_CopyDisp(xfb[whichfb], GX_TRUE);
|
||||||
GX_Flush();
|
GX_Flush();
|
||||||
|
|
||||||
VIDEO_SetNextFramebuffer(xfb[whichfb]);
|
VIDEO_SetNextFramebuffer(xfb[whichfb]);
|
||||||
VIDEO_Flush();
|
VIDEO_Flush();
|
||||||
//VIDEO_WaitVSync();
|
//VIDEO_WaitVSync();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ extern int isWiimoteAvailable;
|
|||||||
|
|
||||||
void setup_controllers()
|
void setup_controllers()
|
||||||
{ /* Doesn't work, either always returns
|
{ /* Doesn't work, either always returns
|
||||||
WiimoteAvailable or switches REALLY fast
|
WiimoteAvailable only or apparently switches
|
||||||
between the two. WTF.
|
REALLY fast between the two. WTF.
|
||||||
|
|
||||||
WPAD_ScanPads();
|
WPAD_ScanPads();
|
||||||
WPADData pad;
|
WPADData pad;
|
||||||
@ -69,6 +69,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#include "gx_supp.h"
|
#include "gx_supp.h"
|
||||||
#include "tbtime.h"
|
#include "tbtime.h"
|
||||||
|
#include "sdfileio.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
/** VBA **/
|
/** VBA **/
|
||||||
@ -110,10 +111,13 @@ int srcHeight = 0;
|
|||||||
int destWidth = 0;
|
int destWidth = 0;
|
||||||
int destHeight = 0;
|
int destHeight = 0;
|
||||||
int srcPitch = 0;
|
int srcPitch = 0;
|
||||||
|
int saveExists = 0;
|
||||||
extern int menuCalled;
|
extern int menuCalled;
|
||||||
#define WITHGX 1
|
#define WITHGX 1
|
||||||
#define DEBUGON 0
|
#define DEBUGON 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if DEBUGON
|
#if DEBUGON
|
||||||
const char *dbg_local_ip = "192.168.1.32";
|
const char *dbg_local_ip = "192.168.1.32";
|
||||||
const char *dbg_netmask = "255.255.255.0";
|
const char *dbg_netmask = "255.255.255.0";
|
||||||
@ -133,12 +137,7 @@ void (*dbgOutput)(char *, u32) = debuggerOutput;
|
|||||||
/**
|
/**
|
||||||
* Locals
|
* Locals
|
||||||
*/
|
*/
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
void SDInit( void );
|
|
||||||
int gen_getdir( char *whichdir );
|
|
||||||
};
|
|
||||||
extern char *direntries[1000];
|
|
||||||
extern char *MENU_GetLoadFile( char *whichdir );
|
extern char *MENU_GetLoadFile( char *whichdir );
|
||||||
extern void MENU_DrawString( int x, int y, char *msg, int style );
|
extern void MENU_DrawString( int x, int y, char *msg, int style );
|
||||||
|
|
||||||
@ -170,6 +169,13 @@ void doScan(u32 blah)
|
|||||||
PAD_ScanPads();
|
PAD_ScanPads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int throttle = 100;
|
||||||
|
u32 throttleLastTime = 0;
|
||||||
|
|
||||||
|
char filename[1024]; //rom file name
|
||||||
|
char batfilename[1024]; //battery save file name
|
||||||
|
char statename[1024]; //savestate file name
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Initialise Video
|
* Initialise Video
|
||||||
*
|
*
|
||||||
@ -192,6 +198,7 @@ Initialise (void)
|
|||||||
#ifdef WII_BUILD
|
#ifdef WII_BUILD
|
||||||
CONF_Init();
|
CONF_Init();
|
||||||
WPAD_Init();
|
WPAD_Init();
|
||||||
|
setup_controllers();
|
||||||
#endif
|
#endif
|
||||||
vmode = VIDEO_GetPreferredMode(NULL);
|
vmode = VIDEO_GetPreferredMode(NULL);
|
||||||
|
|
||||||
@ -223,11 +230,11 @@ Initialise (void)
|
|||||||
/*** Get the PAD status updated by libogc ***/
|
/*** Get the PAD status updated by libogc ***/
|
||||||
VIDEO_SetPreRetraceCallback (doScan);
|
VIDEO_SetPreRetraceCallback (doScan);
|
||||||
VIDEO_SetBlack (0);
|
VIDEO_SetBlack (0);
|
||||||
|
/*
|
||||||
int i;
|
int i;
|
||||||
u32 *vreg = (u32 *)0xCC002000;
|
u32 *vreg = (u32 *)0xCC002000;
|
||||||
for ( i = 0; i < 64; i++ )
|
for ( i = 0; i < 64; i++ )
|
||||||
vreg[i] = vpal60[i];
|
vreg[i] = vpal60[i]; */
|
||||||
|
|
||||||
/*** Update the video for next vblank ***/
|
/*** Update the video for next vblank ***/
|
||||||
VIDEO_Flush ();
|
VIDEO_Flush ();
|
||||||
@ -240,8 +247,18 @@ Initialise (void)
|
|||||||
|
|
||||||
void systemMessage(int num, const char *msg, ...)
|
void systemMessage(int num, const char *msg, ...)
|
||||||
{
|
{
|
||||||
/*** For now ... do nothing ***/
|
/*** For now ... do nothing ***/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GC_Sleep(u32 dwMiliseconds)
|
||||||
|
{
|
||||||
|
int nVBlanks = (dwMiliseconds / 16);
|
||||||
|
while (nVBlanks-- > 0)
|
||||||
|
{
|
||||||
|
VIDEO_WaitVSync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void systemFrame()
|
void systemFrame()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -252,20 +269,26 @@ void systemShowSpeed(int speed)
|
|||||||
{}
|
{}
|
||||||
static u32 autoFrameSkipLastTime = 0;
|
static u32 autoFrameSkipLastTime = 0;
|
||||||
static int frameskipadjust = 0;
|
static int frameskipadjust = 0;
|
||||||
void system1Frame(int rate)
|
|
||||||
|
void write_save()
|
||||||
{
|
{
|
||||||
/* if ( cartridgeType == 1 )
|
emulator.emuWriteBattery(batfilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void system10Frames(int rate)
|
||||||
|
{
|
||||||
|
if ( cartridgeType == 1 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
u32 time = systemGetClock();
|
u32 time = systemGetClock();
|
||||||
u32 diff = time - autoFrameSkipLastTime;
|
u32 diff = time - autoFrameSkipLastTime;
|
||||||
int speed = 100;
|
int speed = 100;
|
||||||
|
|
||||||
if(diff)
|
if(diff)
|
||||||
speed = (1000000/rate)/diff;
|
speed = (1000000/rate)/diff;
|
||||||
char temp[512];
|
/* char temp[512];
|
||||||
sprintf(temp,"Speed: %i",speed);
|
sprintf(temp,"Speed: %i",speed);
|
||||||
MENU_DrawString( -1, 450,temp , 1 );
|
MENU_DrawString( -1, 450,temp , 1 ); */
|
||||||
|
|
||||||
if(speed >= 98)
|
if(speed >= 98)
|
||||||
{
|
{
|
||||||
@ -291,55 +314,31 @@ void system1Frame(int rate)
|
|||||||
if(systemFrameSkip < 9)
|
if(systemFrameSkip < 9)
|
||||||
systemFrameSkip++;
|
systemFrameSkip++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
autoFrameSkipLastTime = time;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void system10Frames(int rate)
|
if ( cartridgeType == 1 )
|
||||||
{
|
|
||||||
if ( cartridgeType == 1 )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
u32 time = systemGetClock();
|
|
||||||
u32 diff = time - autoFrameSkipLastTime;
|
|
||||||
int speed = 100;
|
|
||||||
|
|
||||||
if(diff)
|
|
||||||
speed = (1000000/rate)/diff;
|
|
||||||
/* char temp[512];
|
|
||||||
sprintf(temp,"Speed: %i",speed);
|
|
||||||
MENU_DrawString( -1, 450,temp , 1 );
|
|
||||||
*/
|
|
||||||
if(speed >= 98)
|
|
||||||
{
|
|
||||||
frameskipadjust++;
|
|
||||||
|
|
||||||
if(frameskipadjust >= 3)
|
|
||||||
{
|
|
||||||
frameskipadjust=0;
|
|
||||||
if(systemFrameSkip > 0)
|
|
||||||
systemFrameSkip--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(speed < 80)
|
|
||||||
frameskipadjust -= (90 - speed)/5;
|
|
||||||
else if(systemFrameSkip < 9)
|
|
||||||
frameskipadjust--;
|
|
||||||
|
|
||||||
if(frameskipadjust <= -2)
|
|
||||||
{
|
|
||||||
frameskipadjust += 2;
|
|
||||||
if(systemFrameSkip < 9)
|
|
||||||
systemFrameSkip++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
autoFrameSkipLastTime = time;
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(systemSaveUpdateCounter) {
|
||||||
|
char temp[512];
|
||||||
|
sprintf(temp,"Writing Save To Disk");
|
||||||
|
MENU_DrawString( -1, 450,temp , 1 );
|
||||||
|
} */
|
||||||
|
|
||||||
|
if(systemSaveUpdateCounter) {
|
||||||
|
if(--systemSaveUpdateCounter <= SYSTEM_SAVE_NOT_UPDATED) {
|
||||||
|
write_save();
|
||||||
|
systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
autoFrameSkipLastTime = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void systemUpdateMotionSensor()
|
void systemUpdateMotionSensor()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -445,7 +444,9 @@ void systemDrawScreen()
|
|||||||
GX_Render( srcWidth, srcHeight, pix, srcPitch );
|
GX_Render( srcWidth, srcHeight, pix, srcPitch );
|
||||||
#endif
|
#endif
|
||||||
#ifdef WII_BUILD
|
#ifdef WII_BUILD
|
||||||
|
|
||||||
VIDEO_WaitVSync ();
|
VIDEO_WaitVSync ();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef GC_BUILD
|
#ifdef GC_BUILD
|
||||||
if ( cartridgeType == 1 )
|
if ( cartridgeType == 1 )
|
||||||
@ -470,10 +471,6 @@ int ShowDir( char *whichdir )
|
|||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char filename[1024]; //rom file name
|
|
||||||
char batfilename[1024]; //battery save file name
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Asks user to select a ROM
|
Asks user to select a ROM
|
||||||
*/
|
*/
|
||||||
@ -490,11 +487,10 @@ void chooseRom() {
|
|||||||
strncat(batfilename,fname,strlen(fname)-4);
|
strncat(batfilename,fname,strlen(fname)-4);
|
||||||
strcat(batfilename,".SAV");
|
strcat(batfilename,".SAV");
|
||||||
|
|
||||||
}
|
// construct savestate name
|
||||||
|
strcpy(statename, "/VBA/SAVES/");
|
||||||
void askSound() {
|
strncat(statename,fname,strlen(fname)-4);
|
||||||
soundOffFlag = false;
|
strcat(statename,".SGM");
|
||||||
soundLowPass = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -502,33 +498,63 @@ void askSound() {
|
|||||||
If it does, it prompts the user to load it or not
|
If it does, it prompts the user to load it or not
|
||||||
*/
|
*/
|
||||||
void checkSave() {
|
void checkSave() {
|
||||||
|
FILE* f = gen_fopen(statename, "rb");
|
||||||
}
|
if (f != NULL) {
|
||||||
void GC_Sleep(u32 dwMiliseconds)
|
gen_fclose(f);
|
||||||
{
|
|
||||||
int nVBlanks = (dwMiliseconds / 16);
|
|
||||||
while (nVBlanks-- > 0)
|
|
||||||
{
|
|
||||||
VIDEO_WaitVSync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void write_save()
|
|
||||||
{
|
|
||||||
VIDEO_ClearFrameBuffer (vmode, xfb[whichfb], COLOR_BLACK);
|
|
||||||
MENU_DrawString( -1, 250,"Attempting to Save data ..." , 1 );
|
|
||||||
whichfb^=1;
|
whichfb^=1;
|
||||||
VIDEO_ClearFrameBuffer (vmode, xfb[whichfb], COLOR_BLACK);
|
VIDEO_ClearFrameBuffer (vmode, xfb[whichfb], COLOR_BLACK);
|
||||||
if(emulator.emuWriteBattery(batfilename) == true)
|
MENU_DrawString( 140, 50,"Quick Save State Exists" , 1 );
|
||||||
MENU_DrawString( -1, 250,"Save OK!" , 1 );
|
MENU_DrawString( 140, 80,"Do you wish to load it?" , 1 );
|
||||||
else
|
MENU_DrawString( -1, 170,"(L) or (+) YES" , 1 );
|
||||||
MENU_DrawString( -1, 250,"Either no data to save yet or error!" , 1 );
|
MENU_DrawString( -1, 200,"(R) or (-) NO" , 1 );
|
||||||
VIDEO_WaitVSync ();
|
VIDEO_WaitVSync ();
|
||||||
VIDEO_SetNextFramebuffer(xfb[whichfb]);
|
VIDEO_SetNextFramebuffer(xfb[whichfb]);
|
||||||
VIDEO_Flush();
|
VIDEO_Flush();
|
||||||
GC_Sleep(2000);
|
VIDEO_WaitVSync();
|
||||||
|
while(1) {
|
||||||
|
WPADData *wpad;
|
||||||
|
WPAD_ScanPads();
|
||||||
|
wpad = WPAD_Data(0);
|
||||||
|
if (isWiimoteAvailable) {
|
||||||
|
unsigned short b = wpad->btns_h;
|
||||||
|
if(b & WPAD_BUTTON_PLUS) {
|
||||||
|
saveExists = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(b & WPAD_BUTTON_MINUS) break;
|
||||||
|
}
|
||||||
|
if (isClassicAvailable) {
|
||||||
|
unsigned short b = wpad->exp.classic.btns;
|
||||||
|
if(b & CLASSIC_CTRL_BUTTON_PLUS) {
|
||||||
|
saveExists = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(b & CLASSIC_CTRL_BUTTON_MINUS) break;
|
||||||
|
}
|
||||||
|
u16 buttons = PAD_ButtonsHeld(0);
|
||||||
|
if(buttons & PAD_TRIGGER_R){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(buttons & PAD_TRIGGER_L){
|
||||||
|
saveExists = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VIDEO_ClearFrameBuffer (vmode, xfb[whichfb], COLOR_BLACK);
|
||||||
|
VIDEO_WaitVSync ();
|
||||||
|
VIDEO_SetNextFramebuffer(xfb[whichfb]);
|
||||||
|
VIDEO_Flush();
|
||||||
|
VIDEO_WaitVSync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void askSound() {
|
||||||
|
soundOffFlag = false;
|
||||||
|
soundLowPass = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int ingameMenu() {
|
int ingameMenu() {
|
||||||
tb_t start,end;
|
tb_t start,end;
|
||||||
mftb(&start);
|
mftb(&start);
|
||||||
@ -542,16 +568,16 @@ int ingameMenu() {
|
|||||||
#ifdef GC_BUILD
|
#ifdef GC_BUILD
|
||||||
MENU_DrawString( 140, 80,"Nintendo Gamecube Port" , 1 );
|
MENU_DrawString( 140, 80,"Nintendo Gamecube Port" , 1 );
|
||||||
MENU_DrawString( -1, 170,"(B) - Resume play" , 1 );
|
MENU_DrawString( -1, 170,"(B) - Resume play" , 1 );
|
||||||
MENU_DrawString( -1, 200,"(L) - Write save" , 1 );
|
MENU_DrawString( -1, 200,"(L) - Write Quicksave" , 1 );
|
||||||
MENU_DrawString( -1, 230,"(R) - Reset game" , 1 );
|
MENU_DrawString( -1, 230,"(R) - Reset game" , 1 );
|
||||||
MENU_DrawString( -1, 320,"(Z) - Return to loader" , 1 );
|
MENU_DrawString( -1, 320,"(Z) - Return to loader" , 1 );
|
||||||
#endif
|
#endif
|
||||||
#ifdef WII_BUILD
|
#ifdef WII_BUILD
|
||||||
MENU_DrawString( 140, 80,"Nintendo Wii Port" , 1 );
|
MENU_DrawString( 140, 80,"Nintendo Wii Port" , 1 );
|
||||||
MENU_DrawString( -1, 170,"(B) or (Home) - Resume play" , 1 );
|
MENU_DrawString( -1, 170,"(B) or (Home) - Resume play" , 1 );
|
||||||
MENU_DrawString( -1, 200,"(L) or (+) - Write save" , 1 );
|
MENU_DrawString( -1, 200,"(L) or (+) - Write Quicksave" , 1 );
|
||||||
MENU_DrawString( -1, 230,"(R) or (-) - Reset game" , 1 );
|
MENU_DrawString( -1, 230,"(R) or (-) - Reset game" , 1 );
|
||||||
MENU_DrawString( -1, 320,"(Z) or (A+B) - Return to loader" , 1 );
|
MENU_DrawString( -1, 320,"(Z) or (A+B) - Return to loader" , 1 );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sprintf(temp,"Frameskip: Auto (Currently %i)",systemFrameSkip);
|
sprintf(temp,"Frameskip: Auto (Currently %i)",systemFrameSkip);
|
||||||
@ -559,95 +585,103 @@ int ingameMenu() {
|
|||||||
|
|
||||||
VIDEO_WaitVSync ();
|
VIDEO_WaitVSync ();
|
||||||
VIDEO_SetNextFramebuffer(xfb[whichfb]);
|
VIDEO_SetNextFramebuffer(xfb[whichfb]);
|
||||||
VIDEO_Flush();
|
VIDEO_Flush();
|
||||||
VIDEO_WaitVSync();
|
VIDEO_WaitVSync();
|
||||||
|
|
||||||
//wait for user to let go of menu calling button
|
//wait for user to let go of menu calling button
|
||||||
do{buttons = PAD_ButtonsHeld(0);}while((buttons & PAD_BUTTON_A)||(buttons & PAD_BUTTON_B));
|
do{buttons = PAD_ButtonsHeld(0);}
|
||||||
|
while((buttons & PAD_BUTTON_A)||(buttons & PAD_BUTTON_B));
|
||||||
//wait for user to let go of home button
|
//wait for user to let go of home button
|
||||||
#ifdef WII_BUILD
|
#ifdef WII_BUILD
|
||||||
WPADData *wpad;
|
WPADData *wpad;
|
||||||
int btn;
|
int btn;
|
||||||
if(isWiimoteAvailable)
|
if(isWiimoteAvailable)
|
||||||
do{WPAD_ScanPads(); wpad = WPAD_Data(0); btn = wpad->btns_h;}while(btn & WPAD_BUTTON_HOME);
|
do{WPAD_ScanPads(); wpad = WPAD_Data(0); btn = wpad->btns_h;}
|
||||||
|
while(btn & WPAD_BUTTON_HOME);
|
||||||
if(isClassicAvailable)
|
if(isClassicAvailable)
|
||||||
do{WPAD_ScanPads(); wpad = WPAD_Data(0); btn = wpad->exp.classic.btns;}while(btn & CLASSIC_CTRL_BUTTON_HOME);
|
do{WPAD_ScanPads(); wpad = WPAD_Data(0); btn = wpad->exp.classic.btns;}
|
||||||
|
while(btn & CLASSIC_CTRL_BUTTON_HOME);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
|
|
||||||
#ifdef WII_BUILD
|
#ifdef WII_BUILD
|
||||||
WPADData *wpad;
|
WPADData *wpad;
|
||||||
WPAD_ScanPads();
|
WPAD_ScanPads();
|
||||||
wpad = WPAD_Data(0);
|
wpad = WPAD_Data(0);
|
||||||
if (isWiimoteAvailable)
|
if (isWiimoteAvailable)
|
||||||
{
|
{
|
||||||
unsigned short b = wpad->btns_h;
|
unsigned short b = wpad->btns_h;
|
||||||
if(b & WPAD_BUTTON_MINUS){ //Reset game
|
if(b & WPAD_BUTTON_MINUS){ //Reset game
|
||||||
emulator.emuReset();
|
emulator.emuReset();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(b & WPAD_BUTTON_PLUS) { //Write save
|
if(b & WPAD_BUTTON_PLUS) { //Write save
|
||||||
write_save();
|
emulator.emuWriteState(statename);
|
||||||
break;
|
GC_Sleep(1500);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
if((b & WPAD_BUTTON_A) && (b & WPAD_BUTTON_B)) { //Return to loader
|
if((b & WPAD_BUTTON_A) && (b & WPAD_BUTTON_B)) { //Return to loader
|
||||||
void (*reload)() = (void(*)())0x80001800;
|
void (*reload)() = (void(*)())0x80001800;
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
if(b & WPAD_BUTTON_HOME) { //Resume play
|
if(b & WPAD_BUTTON_HOME) { //Resume play
|
||||||
do{WPAD_ScanPads(); wpad = WPAD_Data(0); b = wpad->btns_h;}while(b & WPAD_BUTTON_HOME); //wait for home
|
do{WPAD_ScanPads(); wpad = WPAD_Data(0); b = wpad->btns_h;}
|
||||||
break;
|
while(b & WPAD_BUTTON_HOME); //wait for home
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
if (isClassicAvailable)
|
/* if(b & WPAD_BUTTON_2) { //back to menu
|
||||||
{
|
INSERT BACK-TO-MENU HERE
|
||||||
int b = wpad->exp.classic.btns;
|
} */
|
||||||
if(b & CLASSIC_CTRL_BUTTON_MINUS){ //Reset game
|
}
|
||||||
emulator.emuReset();
|
if (isClassicAvailable)
|
||||||
break;
|
{
|
||||||
}
|
int b = wpad->exp.classic.btns;
|
||||||
if(b & CLASSIC_CTRL_BUTTON_PLUS) { //Write save
|
if(b & CLASSIC_CTRL_BUTTON_MINUS){ //Reset game
|
||||||
write_save();
|
emulator.emuReset();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if(b & CLASSIC_CTRL_BUTTON_PLUS) { //Write save
|
||||||
|
emulator.emuWriteState(statename);
|
||||||
|
break;
|
||||||
|
}
|
||||||
if((b & CLASSIC_CTRL_BUTTON_A) && (b & CLASSIC_CTRL_BUTTON_B)) { //Return to loader
|
if((b & CLASSIC_CTRL_BUTTON_A) && (b & CLASSIC_CTRL_BUTTON_B)) { //Return to loader
|
||||||
void (*reload)() = (void(*)())0x80001800;
|
void (*reload)() = (void(*)())0x80001800;
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
if(b & CLASSIC_CTRL_BUTTON_HOME) { //Resume play
|
if(b & CLASSIC_CTRL_BUTTON_HOME) { //Resume play
|
||||||
do{WPAD_ScanPads(); wpad = WPAD_Data(0); b = wpad->exp.classic.btns;}
|
do{WPAD_ScanPads(); wpad = WPAD_Data(0); b = wpad->exp.classic.btns;}
|
||||||
while(b & CLASSIC_CTRL_BUTTON_HOME); //wait for home button
|
while(b & CLASSIC_CTRL_BUTTON_HOME); //wait for home button
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
u16 buttons = PAD_ButtonsHeld(0); //grab pad buttons
|
u16 buttons = PAD_ButtonsHeld(0); //grab pad buttons
|
||||||
|
|
||||||
if(buttons & PAD_TRIGGER_R){ //Reset game
|
if(buttons & PAD_TRIGGER_R){ //Reset game
|
||||||
emulator.emuReset();
|
emulator.emuReset();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(buttons & PAD_TRIGGER_L) { //Write save
|
if(buttons & PAD_TRIGGER_L) { //Write save
|
||||||
write_save();
|
emulator.emuWriteState(statename);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(buttons & PAD_TRIGGER_Z) { //Return to loader
|
if(buttons & PAD_TRIGGER_Z) { //Return to loader
|
||||||
void (*reload)() = (void(*)())0x80001800;
|
void (*reload)() = (void(*)())0x80001800;
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
if(buttons & PAD_BUTTON_B) { //Resume play
|
if(buttons & PAD_BUTTON_B) { //Resume play
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AudioPlayer();
|
AudioPlayer();
|
||||||
mftb(&end);
|
mftb(&end);
|
||||||
loadtimeradjust += tb_diff_msec(&end, &start);
|
loadtimeradjust += tb_diff_msec(&end, &start);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* main
|
* main
|
||||||
*
|
*
|
||||||
@ -666,7 +700,8 @@ int main()
|
|||||||
|
|
||||||
|
|
||||||
/** Kick off SD Lib **/
|
/** Kick off SD Lib **/
|
||||||
SDInit();
|
SDInit();
|
||||||
|
|
||||||
|
|
||||||
/** Build GBPalette **/
|
/** Build GBPalette **/
|
||||||
for( i = 0; i < 24; )
|
for( i = 0; i < 24; )
|
||||||
@ -688,9 +723,6 @@ int main()
|
|||||||
(((i & 0x7c00) >> 10) << systemBlueShift);
|
(((i & 0x7c00) >> 10) << systemBlueShift);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WII_BUILD
|
|
||||||
setup_controllers();
|
|
||||||
#endif
|
|
||||||
//Main loop
|
//Main loop
|
||||||
while(1) {
|
while(1) {
|
||||||
cartridgeType = 0;
|
cartridgeType = 0;
|
||||||
@ -701,14 +733,14 @@ int main()
|
|||||||
srcPitch = 0;
|
srcPitch = 0;
|
||||||
|
|
||||||
chooseRom();
|
chooseRom();
|
||||||
//checkSave();
|
checkSave();
|
||||||
|
|
||||||
IMAGE_TYPE type = utilFindType(filename);
|
IMAGE_TYPE type = utilFindType(filename);
|
||||||
|
|
||||||
switch( type )
|
switch( type )
|
||||||
{
|
{
|
||||||
case IMAGE_GBA:
|
case IMAGE_GBA:
|
||||||
// printf("GameBoy Advance Image\n");
|
printf("GameBoy Advance Image\n");
|
||||||
cartridgeType = 2;
|
cartridgeType = 2;
|
||||||
emulator = GBASystem;
|
emulator = GBASystem;
|
||||||
srcWidth = 240;
|
srcWidth = 240;
|
||||||
@ -724,7 +756,7 @@ int main()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case IMAGE_GB:
|
case IMAGE_GB:
|
||||||
// printf("GameBoy Image\n");
|
printf("GameBoy Image\n");
|
||||||
cartridgeType = 1;
|
cartridgeType = 1;
|
||||||
emulator = GBSystem;
|
emulator = GBSystem;
|
||||||
srcWidth = 160;
|
srcWidth = 160;
|
||||||
@ -739,7 +771,7 @@ int main()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// printf("Unknown Image\n");
|
printf("Unknown Image\n");
|
||||||
while(1);
|
while(1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -755,7 +787,9 @@ int main()
|
|||||||
/** Set GX **/
|
/** Set GX **/
|
||||||
GX_Start( srcWidth, srcHeight, hAspect, vAspect );
|
GX_Start( srcWidth, srcHeight, hAspect, vAspect );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( cartridgeType == 1 )
|
if ( cartridgeType == 1 )
|
||||||
{
|
{
|
||||||
gbSoundReset();
|
gbSoundReset();
|
||||||
@ -768,6 +802,12 @@ int main()
|
|||||||
CPUReset();
|
CPUReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emulator.emuReadBattery(batfilename);
|
||||||
|
if (saveExists){
|
||||||
|
emulator.emuReadState(statename);
|
||||||
|
saveExists = 0;
|
||||||
|
}
|
||||||
|
|
||||||
soundVolume = 0;
|
soundVolume = 0;
|
||||||
systemSoundOn = true;
|
systemSoundOn = true;
|
||||||
|
|
||||||
@ -778,17 +818,15 @@ int main()
|
|||||||
/** Start system clock **/
|
/** Start system clock **/
|
||||||
mftb(&start);
|
mftb(&start);
|
||||||
|
|
||||||
emulator.emuReadBattery(batfilename);
|
|
||||||
while ( emulating )
|
while ( emulating )
|
||||||
{
|
{
|
||||||
emulator.emuMain(emulator.emuCount);
|
emulator.emuMain(emulator.emuCount);
|
||||||
if(menuCalled) {
|
if(menuCalled) {
|
||||||
if(ingameMenu())
|
if(ingameMenu())
|
||||||
break;
|
break;
|
||||||
menuCalled = 0;
|
menuCalled = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Never **/
|
/** Never **/
|
||||||
|
220
src/zutil.h
Normal file
220
src/zutil.h
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
/* zutil.h -- internal interface and configuration of the compression library
|
||||||
|
* Copyright (C) 1995-1998 Jean-loup Gailly.
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* WARNING: this file should *not* be used by applications. It is
|
||||||
|
part of the implementation of the compression library and is
|
||||||
|
subject to change. Applications should only use zlib.h.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* @(#) $Id: zutil.h,v 1.2 2004/01/17 23:07:32 kxu Exp $ */
|
||||||
|
|
||||||
|
#ifndef _Z_UTIL_H
|
||||||
|
#define _Z_UTIL_H
|
||||||
|
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
|
#ifdef STDC
|
||||||
|
# include <stddef.h>
|
||||||
|
# include <string.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#ifdef NO_ERRNO_H
|
||||||
|
extern int errno;
|
||||||
|
#else
|
||||||
|
# include <errno.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef local
|
||||||
|
# define local static
|
||||||
|
#endif
|
||||||
|
/* compile with -Dlocal if your debugger can't find static symbols */
|
||||||
|
|
||||||
|
typedef unsigned char uch;
|
||||||
|
typedef uch FAR uchf;
|
||||||
|
typedef unsigned short ush;
|
||||||
|
typedef ush FAR ushf;
|
||||||
|
typedef unsigned long ulg;
|
||||||
|
|
||||||
|
extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
|
/* (size given to avoid silly warnings with Visual C++) */
|
||||||
|
|
||||||
|
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
|
||||||
|
|
||||||
|
#define ERR_RETURN(strm,err) \
|
||||||
|
return (strm->msg = (char*)ERR_MSG(err), (err))
|
||||||
|
/* To be used only when the state is known to be valid */
|
||||||
|
|
||||||
|
/* common constants */
|
||||||
|
|
||||||
|
#ifndef DEF_WBITS
|
||||||
|
# define DEF_WBITS MAX_WBITS
|
||||||
|
#endif
|
||||||
|
/* default windowBits for decompression. MAX_WBITS is for compression only */
|
||||||
|
|
||||||
|
#if MAX_MEM_LEVEL >= 8
|
||||||
|
# define DEF_MEM_LEVEL 8
|
||||||
|
#else
|
||||||
|
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||||
|
#endif
|
||||||
|
/* default memLevel */
|
||||||
|
|
||||||
|
#define STORED_BLOCK 0
|
||||||
|
#define STATIC_TREES 1
|
||||||
|
#define DYN_TREES 2
|
||||||
|
/* The three kinds of block type */
|
||||||
|
|
||||||
|
#define MIN_MATCH 3
|
||||||
|
#define MAX_MATCH 258
|
||||||
|
/* The minimum and maximum match lengths */
|
||||||
|
|
||||||
|
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
|
||||||
|
|
||||||
|
/* target dependencies */
|
||||||
|
|
||||||
|
#ifdef MSDOS
|
||||||
|
# define OS_CODE 0x00
|
||||||
|
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||||
|
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||||
|
/* Allow compilation with ANSI keywords only enabled */
|
||||||
|
void _Cdecl farfree( void *block );
|
||||||
|
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||||
|
# else
|
||||||
|
# include <alloc.h>
|
||||||
|
# endif
|
||||||
|
# else /* MSC or DJGPP */
|
||||||
|
# include <malloc.h>
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef OS2
|
||||||
|
# define OS_CODE 0x06
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32 /* Window 95 & Windows NT */
|
||||||
|
# define OS_CODE 0x0b
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(VAXC) || defined(VMS)
|
||||||
|
# define OS_CODE 0x02
|
||||||
|
# define F_OPEN(name, mode) \
|
||||||
|
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef AMIGA
|
||||||
|
# define OS_CODE 0x01
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ATARI) || defined(atarist)
|
||||||
|
# define OS_CODE 0x05
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
||||||
|
# define OS_CODE 0x07
|
||||||
|
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
||||||
|
# include <unix.h> /* for fdopen */
|
||||||
|
# else
|
||||||
|
# ifndef fdopen
|
||||||
|
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __50SERIES /* Prime/PRIMOS */
|
||||||
|
# define OS_CODE 0x0F
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TOPS20
|
||||||
|
# define OS_CODE 0x0a
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_BEOS_) || defined(RISCOS)
|
||||||
|
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(_MSC_VER) && (_MSC_VER > 600))
|
||||||
|
# define fdopen(fd,type) _fdopen(fd,type)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Common defaults */
|
||||||
|
|
||||||
|
#ifndef OS_CODE
|
||||||
|
# define OS_CODE 0x03 /* assume Unix */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef F_OPEN
|
||||||
|
# define F_OPEN(name, mode) fopen((name), (mode))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
|
||||||
|
#ifdef HAVE_STRERROR
|
||||||
|
extern char *strerror OF((int));
|
||||||
|
# define zstrerror(errnum) strerror(errnum)
|
||||||
|
#else
|
||||||
|
# define zstrerror(errnum) ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(pyr)
|
||||||
|
# define NO_MEMCPY
|
||||||
|
#endif
|
||||||
|
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
||||||
|
/* Use our own functions for small and medium model with MSC <= 5.0.
|
||||||
|
* You may have to use the same strategy for Borland C (untested).
|
||||||
|
* The __SC__ check is for Symantec.
|
||||||
|
*/
|
||||||
|
# define NO_MEMCPY
|
||||||
|
#endif
|
||||||
|
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
|
||||||
|
# define HAVE_MEMCPY
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_MEMCPY
|
||||||
|
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
|
||||||
|
# define zmemcpy _fmemcpy
|
||||||
|
# define zmemcmp _fmemcmp
|
||||||
|
# define zmemzero(dest, len) _fmemset(dest, 0, len)
|
||||||
|
# else
|
||||||
|
# define zmemcpy memcpy
|
||||||
|
# define zmemcmp memcmp
|
||||||
|
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
|
||||||
|
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
||||||
|
extern void zmemzero OF((Bytef* dest, uInt len));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Diagnostic functions */
|
||||||
|
#ifdef DEBUG
|
||||||
|
# include <stdio.h>
|
||||||
|
extern int z_verbose;
|
||||||
|
extern void z_error OF((char *m));
|
||||||
|
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
||||||
|
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
||||||
|
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
||||||
|
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
|
||||||
|
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
|
||||||
|
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
|
||||||
|
#else
|
||||||
|
# define Assert(cond,msg)
|
||||||
|
# define Trace(x)
|
||||||
|
# define Tracev(x)
|
||||||
|
# define Tracevv(x)
|
||||||
|
# define Tracec(c,x)
|
||||||
|
# define Tracecv(c,x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
|
||||||
|
uInt len));
|
||||||
|
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
|
||||||
|
void zcfree OF((voidpf opaque, voidpf ptr));
|
||||||
|
|
||||||
|
#define ZALLOC(strm, items, size) \
|
||||||
|
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||||
|
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||||
|
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||||
|
|
||||||
|
#endif /* _Z_UTIL_H */
|
Loading…
Reference in New Issue
Block a user