From fefc260ec4d7e7839483129a62ecdc73a3734c5a Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Thu, 18 Dec 2008 17:13:47 +0000 Subject: [PATCH] sound rendering test, updated DOS/Win32 ports --- source/ngc/ngc.c | 4 +- source/ngc/ogc_audio.c | 34 +- source/ngc/ogc_audio.h | 1 + source/system.c | 5 - source/unused/CHANGELOG | 41 +- source/unused/dos/Makefile | 17 +- source/unused/dos/SEALINTF.C | 428 +++++------ source/unused/dos/dos.c | 766 ++++++++++---------- source/unused/dos/dos.h | 1 - source/unused/dos/error.c | 10 +- source/unused/dos/unzip.c | 1294 ++++++++++++++++++++++++++++++++++ source/unused/dos/unzip.h | 273 +++++++ source/unused/win/Makefile | 1 - source/unused/win/config.c | 4 +- source/unused/win/error.c | 12 +- source/unused/win/main.c | 179 ++--- source/unused/win/unzip.c | 1294 ++++++++++++++++++++++++++++++++++ source/unused/win/unzip.h | 273 +++++++ 18 files changed, 3906 insertions(+), 731 deletions(-) create mode 100644 source/unused/dos/unzip.c create mode 100644 source/unused/dos/unzip.h create mode 100644 source/unused/win/unzip.c create mode 100644 source/unused/win/unzip.h diff --git a/source/ngc/ngc.c b/source/ngc/ngc.c index cf0d41f..bf936a0 100644 --- a/source/ngc/ngc.c +++ b/source/ngc/ngc.c @@ -196,6 +196,8 @@ int main (int argc, char *argv[]) /* Emulation Loop */ while (1) { + ogc_audio__start(); + /* Frame synchronization */ if (gc_pal != vdp_pal) { @@ -242,8 +244,8 @@ int main (int argc, char *argv[]) } /* update video & audio */ - ogc_video__update(); ogc_audio__update(); + ogc_video__update(); /* Check rendered frames (FPS) */ FrameCount++; diff --git a/source/ngc/ogc_audio.c b/source/ngc/ogc_audio.c index e0aedd8..84be0e8 100644 --- a/source/ngc/ogc_audio.c +++ b/source/ngc/ogc_audio.c @@ -51,11 +51,14 @@ void ogc_audio__init(void) { AUDIO_Init (NULL); AUDIO_SetDSPSampleRate (AI_SAMPLERATE_48KHZ); - AUDIO_RegisterDMACallback (AudioSwitchBuffers); + // AUDIO_RegisterDMACallback (AudioSwitchBuffers); } void ogc_audio__reset(void) { + IsPlaying = 0; + mixbuffer = 0; + playbuffer = 0; memset(soundbuffer, 0, 16 * 3840); } @@ -63,12 +66,27 @@ void ogc_audio__update(void) { /* flush data from CPU cache */ DCFlushRange(soundbuffer[mixbuffer], dma_len); + AUDIO_InitDMA((u32) soundbuffer[mixbuffer], dma_len); +} +void ogc_audio__stop(void) +{ + /* stop audio DMA */ + AUDIO_StopDMA (); + AUDIO_InitDMA((u32) soundbuffer[0], dma_len); + IsPlaying = 0; + mixbuffer = 0; + playbuffer = 0; +} + +void ogc_audio__start(void) +{ if (!IsPlaying) { - dma_len = (vdp_pal) ? 3840 : 3200; + /* buffer size */ + dma_len = vdp_pal ? 3840 : 3200; - /* set audio DMA parameters */ + /* set default DMA parameters */ AUDIO_InitDMA((u32) soundbuffer[0], dma_len); /* start audio DMA */ @@ -77,13 +95,3 @@ void ogc_audio__update(void) IsPlaying = 1; } } - -void ogc_audio__stop(void) -{ - /* stop audio DMA */ - AUDIO_StopDMA (); - IsPlaying = 0; - mixbuffer = 0; - playbuffer = 0; -} - diff --git a/source/ngc/ogc_audio.h b/source/ngc/ogc_audio.h index 174df7c..d75e421 100644 --- a/source/ngc/ogc_audio.h +++ b/source/ngc/ogc_audio.h @@ -30,6 +30,7 @@ extern int mixbuffer; extern void ogc_audio__init(void); extern void ogc_audio__reset(void); extern void ogc_audio__stop(void); +extern void ogc_audio__start(void); extern void ogc_audio__update(void); #endif diff --git a/source/system.c b/source/system.c index b3e19e6..e6ee51e 100644 --- a/source/system.c +++ b/source/system.c @@ -396,9 +396,4 @@ static inline void audio_update (void) *sb++ = l; #endif } - -#ifndef DOS - mixbuffer++; - mixbuffer &= 0xf; -#endif } diff --git a/source/unused/CHANGELOG b/source/unused/CHANGELOG index 108fd38..89fadc7 100644 --- a/source/unused/CHANGELOG +++ b/source/unused/CHANGELOG @@ -1,9 +1,28 @@ Genesis Plus History -------------------- -Note: All recent changes directly come from the Gamecube/Wii port, coded by Eke-Eke. +Note: All recent changes directly come from the GX (Gamecube/Wii) port, code by Eke-Eke. + + + [14/12/08] (Eke-Eke) version 1.3.0 +------------------- +- YM2612 bugfixes (MAME core): + .fixed EG Decay->Substain transition when SL & DR are minimals: fix tracks #3 and #9 in "Mega Turrican" + .fixed a bug in SSG-EG emulation code: fix Level 1 music in "Alisia Dragoon" + .modified SSG-EG Decay End Level: fix some sound effects (ChainSaw, Zap...) in "Beavis & Butthead" + .improved Detune overflow accuracy: fix very high frequency sounds in many games + .fixed registers 0x20-0x26 Reset state: fix intro music in "B.O.B" + .reverted incorrect fix with KEY ON: fix "Flamethrower" sound effect in "Alien 3" and many others +- adjusted HCounter values: fixes line flickering in "Sonic 3D" bonus stage +- adjusted VINT timing: fixes hang-up in "V.R Troopers" +- improved HBLANK flag accuracy: fixes line flickering in "Gouketsuji Ichizoku" +- fixed broken Z80 access to WRAM: fixes hang-up in "Mamono Hunter Youko" +- modified JCART emulation: fixes corrupted tracks logo in "Micro Machines 2" +- added Blargg's NTSC Filters support (NTSC video artifacts emulation) +- optimized VDP rendering core, rewrote 68k interface (memory handlers, cycle execution, interrupts): greatly improved emulation speed [08/26/08] (Eke-Eke) +------------------- - YM2612(MAME): fixed LFO phase update for CH3 special mode: fix sound effects in Warlock & Aladdin (thanks to AamirM) - YM2612(MAME): fixed EG attenuation level on "KEY ON": fix Ecco 2's splash sound - YM2612(MAME): fixed SSG-EG emulation: fix Bubba'n Stix (Track 5) and many others @@ -19,6 +38,7 @@ Note: All recent changes directly come from the Gamecube/Wii port, coded by Eke- - added Sega Mouse emulation (Populous 2, Body Count, Shangai 2, Fun'n Games, ...) [07/16/08] (Eke-Eke) +------------------- - adjusted (again) HINT timings: fix Double Dragon 2 (game freezed), hopefully does not break anything else - fixed broken EEPROM support for Codemaster games - modified input update timings: fix Dungeons & Dragons - Warriors of the Eternal Sun (thanks to Notaz) @@ -33,22 +53,26 @@ Note: All recent changes directly come from the Gamecube/Wii port, coded by Eke- .implemented sample interpolation in MAME core to emulate the chip at original frequency (HQ YM2612 mode, from gens) [06/01/08] (Eke-Eke) +------------------- - improved HCounter accuracy: fix graphic glitches in "Striker (Europe)" - improved HINT timing accuracy: fix flickering in "Zero The Kamikaze Squirrel (USA)" - improved rendering accuracy when backdrop color is modified during HBLANK (Road Rash I/II/III) - fixed broken Game Genie support [04/19/08] (Eke-Eke) +------------------- - modified VINT timings a little bit: fix lockup during Desert Strike's intro - corrected 68k interrupts handling: fix graphic glitches in Darius II/Sagaia [04/06/08] (Eke-Eke) +------------------- - updated SVP core: fix some perspective issues in Virtua Racing (thanks to Notaz) - added internal SAT update during VRAM Fill: fix unmasked sprites during Battletech's intro - fixed m68k core issues with gcc 4.2.3: fix Xperts, Lemmings 2, M1 Abrams Battle Tank - forced YM2612 Enveloppe update: fix intro music in Batman&Robin (thanks to Aamir) [03/01/08] (Eke-Eke) +------------------- - added SVP emulation: Virtua Racing is now emulated (big thanks to Notaz and TascoDeluxe) - fixed VDP registers behaviour when VDP Mode 4 is enabled: fix Bass Masters Classic Pro, Captain Planet & The Planeeters - corrected a bug in DMA Fill operation: fix James Pond 3, Rockman World/Megaman Willy Wars (corrupted VRAM) @@ -59,6 +83,7 @@ Note: All recent changes directly come from the Gamecube/Wii port, coded by Eke- - reduced Savestate size [01/07/08] (Eke-Eke) +------------------- - fixed interleaved rom detection: roms with .smd extension should now work fine - fixed a recently introduced bug in VDP registers writes: fixes bad colors in Toy Story (intro) - updated list of games using EEPROM: added Sports Talk Baseball (internal memory check fixed) and Brian Lara Cricket @@ -69,6 +94,7 @@ Note: All recent changes directly come from the Gamecube/Wii port, coded by Eke- - added support for custom ROM/RAM mapping used by Game no Kanzume Otokuyou [12/28/07] (Eke-Eke) +------------------- - many sourcecode cleanup and optimization - completely rewrote EEPROM emulation: now support all known EEPROM types (24C01-24C65) and mappers (Sega, Acclaim, EA, Codemasters) used in a few games (now use internal game database) as external RAM. This should at least fix save support in the following games: @@ -99,6 +125,7 @@ used in a few games (now use internal game database) as external RAM. This shoul - added full overscan emulation (vertical & horizontal borders) for "pixel perfect" aspect ratio (tested against a real genesis) [07/20/07] (Eke-Eke) +------------------- - corrected TeamPlayer support: fix multiplayer in Gauntlet 4 (Sept. version), Pengo and a lot of others - added J-Cart support: enable multiplayer in Codemasters games (Pete Sampras, Micromachines games, Super Skidmarks) - added serial EEPROM autodetection: fix games with bad SRAM informations in header (NBA Jam TE) @@ -109,10 +136,12 @@ used in a few games (now use internal game database) as external RAM. This shoul in some games to enable special features or even complete the game (ex: X-Men). [06/21/07] (Eke-Eke) +------------------- - added Multitap support (EA 4-Way Play and Sega Teamplayer): allowed up to four players in games supporting those peripherals - added partial Sega Menacer lightgun support (use Analog Stick): automatically set when detecting the 6-in-1 Menacer game [05/18/07] (Eke-Eke) +------------------- - you can now switch between FM cores without reseting the game. FM registers value are automatically restored when switching. - removed the previous VINT timings modification because it brokes some games (Rocket Knight, Thunderforce III,...) - added automatic Timing configuration (VDP latency, VINT timing & alternate Line Timing) at game loading, based upon specific romname detection. @@ -124,6 +153,7 @@ For information, games that are actually detected and need special timings to ru .Chaos Engine/Soldiers of Fortune (graphic glitches on scrolling) [05/08/07] (Eke-Eke) +------------------- - VINT timings are now a little more accurate: fixes Sesame's Street Counting Cafe - SN76496 MAX_OUTPUT back to normal - modified FB_WNOISE value in SN76496 core according to John Kortink's last informations @@ -135,13 +165,16 @@ For information, games that are actually detected and need special timings to ru - added some other configurable sound options (boost overall volume, FM improvment for Gens YM2612) [04/11/07] (Eke-Eke) +------------------- - corrected MAX_OUTPUT value in SN76496 core: fix PSG sound (SFX) volume [03/17/07] (Eke-Eke) +------------------- - added an option to enable alternate line rendering timing (fix single line error in Road Rash series and Legend of Galahad's Intro) - Color RAM update now always reset color 0 to border color (fix color glitches in Mortal Kombat,...) (thanks to Noop's for the idea) [03/09/07] (Eke-Eke) +------------------- - modified HV counter tables (fix graphic glitches in Skitchin's sky, Lotus 2 Recs, Panorama Cotton, Dashin Desperados & maybe more) - completely rewrote DMA timings emulation so that it works for all games (no more cpu freezing) - added all DMA tranfer rates handling for each three DMA modes and added dma busy flag emulation @@ -154,6 +187,7 @@ For information, games that are actually detected and need special timings to ru - modified sound mixing a bit according to Generator sourcecode (FM and PSG ratios seems more correct) [02/07/07] (Eke-Eke) +------------------- - fixed fm timers (fix missing music in Castle of Illusion, Quackshot, Undead Line, Wonderboy in Monster Lair, Cal 50, Turbo Outrun, Thundeforce 4 and maybe more) - added complete EEPROM emulation (save support now works fine in Wonderboy5, Megaman Willy Wars, NBA Jam...) (credits to Notaz, adapted from Picodrive code) - added preliminar dma timing emulation (fix bottom screen in Legend of Galahad) (credits to Notaz, adapted from Picodrive code) @@ -165,12 +199,15 @@ For information, games that are actually detected and need special timings to ru - modified dma fill operation for big endian platform (fix Contra Hardcorps gfx garbage) [05/25/03] +------------------- - Fixed a typo that made Z80 banked access to the VDP registers always fail. [05/17/03] +------------------- - Modified the rendering code to handle unaligned longword access to memory. [04/20/03] +------------------- - Modified 68000 emulator to prevent 'tas.b $mem' from writing data back after a read (fixes Gargoyles). - Fixed bug in 68000 emulator to swap order of words written for address @@ -181,6 +218,7 @@ For information, games that are actually detected and need special timings to ru - Optimized sprite rendering inner loop. [04/13/03] +------------------- - Finished up memory map for VDP DMA V-bus reads. - Fixed handling of 68000 writes to I/O chip at even addresses. - Fixed bit 7 handling of control register in I/O chip. @@ -189,5 +227,6 @@ For information, games that are actually detected and need special timings to ru - Removed some faulty code from the 68000 memory map handlers. [03/22/03] +------------------- - Completed implementation of Z80 banked memory handlers. diff --git a/source/unused/dos/Makefile b/source/unused/dos/Makefile index 3ac7d7f..1b0a0b8 100644 --- a/source/unused/dos/Makefile +++ b/source/unused/dos/Makefile @@ -13,19 +13,19 @@ CC = gcc AS = nasm -f coff LDFLAGS = FLAGS = -I. -I.. -I../z80 -I../m68k -I../dos -I../sound -I../sound/SRC -I../cart_hw -I../cart_hw/svp \ - -Wall -g \ - -O6 -march=i686 -fomit-frame-pointer \ - -DLSB_FIRST -DX86_ASM -DDOS + -Wall -g \ + -O6 -march=i686 -fomit-frame-pointer \ + -DLSB_FIRST -DX86_ASM -DDOS LIBS = -lalleg -laudio -lz -lm -OBJ = obj/z80.o +OBJ = obj/z80.o -OBJ += obj/m68kcpu.o \ +OBJ += obj/m68kcpu.o \ obj/m68kops.o -OBJ += obj/genesis.o \ +OBJ += obj/genesis.o \ obj/vdp.o \ obj/render.o \ obj/system.o \ @@ -34,10 +34,9 @@ OBJ += obj/genesis.o \ obj/mem68k.o \ obj/memz80.o \ obj/membnk.o \ - obj/memvdp.o \ obj/state.o -OBJ += obj/sound.o \ +OBJ += obj/sound.o \ obj/fm.o \ obj/sn76489.o \ obj/ym2612.o @@ -48,7 +47,7 @@ OBJ += obj/samplerate.o \ obj/src_sinc.o \ obj/src_zoh.o \ -OBJ += obj/sram.o \ +OBJ += obj/sram.o \ obj/eeprom.o \ obj/svp.o \ obj/ssp16.o \ diff --git a/source/unused/dos/SEALINTF.C b/source/unused/dos/SEALINTF.C index fa28dcc..f7c9eac 100644 --- a/source/unused/dos/SEALINTF.C +++ b/source/unused/dos/SEALINTF.C @@ -16,273 +16,273 @@ static int master_volume = 256; void osd_update_audio(void) { - if (seal_sample_rate == 0) return; - AUpdateAudio(); + if (seal_sample_rate == 0) return; + AUpdateAudio(); } /* attenuation in dB */ void osd_set_mastervolume(int _attenuation) { - float volume; + float volume; - attenuation = _attenuation; + attenuation = _attenuation; - volume = 256.0; /* range is 0-256 */ - while (_attenuation++ < 0) - volume /= 1.122018454; /* = (10 ^ (1/20)) = 1dB */ + volume = 256.0; /* range is 0-256 */ + while (_attenuation++ < 0) + volume /= 1.122018454; /* = (10 ^ (1/20)) = 1dB */ - master_volume = volume; + master_volume = volume; - ASetAudioMixerValue(AUDIO_MIXER_MASTER_VOLUME,master_volume); + ASetAudioMixerValue(AUDIO_MIXER_MASTER_VOLUME,master_volume); } int msdos_init_sound(int *rate, int card) { - int i; + int i; - seal_sample_rate = *rate; - seal_sound_card = card; + seal_sample_rate = *rate; + seal_sound_card = card; - if (AInitialize() != AUDIO_ERROR_NONE) - return 1; + if (AInitialize() != AUDIO_ERROR_NONE) + return 1; - /* Ask the user if no sound card was chosen */ - if (seal_sound_card == -1) + /* Ask the user if no sound card was chosen */ + if (seal_sound_card == -1) + { + unsigned int k; + + printf("\n SELECT YOUR AUDIO DEVICE :\n\n" + " AWE32/64 playback requires onboard DRAM,\n" + " Sound Blaster playback is the most compatible & better for emulation\n\n"); + + for (k = 0;k < AGetAudioNumDevs();k++) { - unsigned int k; - - printf("\n SELECT YOUR AUDIO DEVICE :\n\n" - " AWE32/64 playback requires onboard DRAM,\n" - " Sound Blaster playback is the most compatible & better for emulation\n\n"); - - for (k = 0;k < AGetAudioNumDevs();k++) - { - if (AGetAudioDevCaps(k,&caps) == AUDIO_ERROR_NONE) - printf(" %2d. %s\n",k,caps.szProductName); - } - printf("\n"); - - if (k < 10) - { - i = getch(); - seal_sound_card = i - '0'; - } - else - scanf("%d",&seal_sound_card); + if (AGetAudioDevCaps(k,&caps) == AUDIO_ERROR_NONE) + printf(" %2d. %s\n",k,caps.szProductName); } + printf("\n"); - /* initialize SEAL audio library */ - if (seal_sound_card == 0) /* silence */ + if (k < 10) { - /* update the Machine structure to show that sound is disabled */ - seal_sample_rate = 0; - exit(0); - return 0; + i = getch(); + seal_sound_card = i - '0'; } + else + scanf("%d",&seal_sound_card); + } - /* open audio device */ - /* info.nDeviceId = AUDIO_DEVICE_MAPPER;*/ - info.nDeviceId = seal_sound_card; - /* always use 16 bit mixing if possible - better quality and same speed of 8 bit */ - info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO | AUDIO_FORMAT_RAW_SAMPLE; - - info.nSampleRate = seal_sample_rate; - if (AOpenAudio(&info) != AUDIO_ERROR_NONE) - { - return (1); - } - - AGetAudioDevCaps(info.nDeviceId,&caps); - printf("Using `%s' at %d-bit %s %u Hz\n", - caps.szProductName, - info.wFormat & AUDIO_FORMAT_16BITS ? 16 : 8, - info.wFormat & AUDIO_FORMAT_STEREO ? "stereo" : "mono", - info.nSampleRate); - - /* open and allocate voices, allocate waveforms */ - if (AOpenVoices(NUMVOICES) != AUDIO_ERROR_NONE) - { - printf("voices initialization failed\n"); - return 1; - } - - for (i = 0; i < NUMVOICES; i++) - { - if (ACreateAudioVoice(&hVoice[i]) != AUDIO_ERROR_NONE) - { - printf("voice #%d creation failed\n",i); - return 1; - } - - ASetVoicePanning(hVoice[i],128); - - lpWave[i] = 0; - } - - /* update the Machine structure to reflect the actual sample rate */ - *rate = seal_sample_rate = info.nSampleRate; - - { - uclock_t a,b; - LONG start,end; - - - if ((lpWave[0] = (LPAUDIOWAVE)malloc(sizeof(AUDIOWAVE))) == 0) - return 1; - - lpWave[0]->wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO; - lpWave[0]->nSampleRate = seal_sample_rate; - lpWave[0]->dwLength = 3*seal_sample_rate; - lpWave[0]->dwLoopStart = 0; - lpWave[0]->dwLoopEnd = 3*seal_sample_rate; - if (ACreateAudioData(lpWave[0]) != AUDIO_ERROR_NONE) - { - free(lpWave[0]); - lpWave[0] = 0; - - return 1; - } - - memset(lpWave[0]->lpData,0,3*seal_sample_rate); - /* upload the data to the audio DRAM local memory */ - AWriteAudioData(lpWave[0],0,3*seal_sample_rate); - APrimeVoice(hVoice[0],lpWave[0]); - ASetVoiceFrequency(hVoice[0],seal_sample_rate); - ASetVoiceVolume(hVoice[0],0); - AStartVoice(hVoice[0]); - - a = uclock(); - /* wait some time to let everything stabilize */ - do - { - osd_update_audio(); - b = uclock(); - } while (b-a < UCLOCKS_PER_SEC/10); - - a = uclock(); - AGetVoicePosition(hVoice[0],&start); - do - { - osd_update_audio(); - b = uclock(); - } while (b-a < UCLOCKS_PER_SEC); - AGetVoicePosition(hVoice[0],&end); - - nominal_sample_rate = seal_sample_rate; - seal_sample_rate = end - start; - - AStopVoice(hVoice[0]); - ADestroyAudioData(lpWave[0]); - free(lpWave[0]); - lpWave[0] = 0; - } - - osd_set_mastervolume(0); /* start at maximum volume */ - + /* initialize SEAL audio library */ + if (seal_sound_card == 0) /* silence */ + { + /* update the Machine structure to show that sound is disabled */ + seal_sample_rate = 0; + exit(0); return 0; + } + + /* open audio device */ + /* info.nDeviceId = AUDIO_DEVICE_MAPPER;*/ + info.nDeviceId = seal_sound_card; + /* always use 16 bit mixing if possible - better quality and same speed of 8 bit */ + info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO | AUDIO_FORMAT_RAW_SAMPLE; + + info.nSampleRate = seal_sample_rate; + if (AOpenAudio(&info) != AUDIO_ERROR_NONE) + { + return (1); + } + + AGetAudioDevCaps(info.nDeviceId,&caps); + printf("Using `%s' at %d-bit %s %u Hz\n", + caps.szProductName, + info.wFormat & AUDIO_FORMAT_16BITS ? 16 : 8, + info.wFormat & AUDIO_FORMAT_STEREO ? "stereo" : "mono", + info.nSampleRate); + + /* open and allocate voices, allocate waveforms */ + if (AOpenVoices(NUMVOICES) != AUDIO_ERROR_NONE) + { + printf("voices initialization failed\n"); + return 1; + } + + for (i = 0; i < NUMVOICES; i++) + { + if (ACreateAudioVoice(&hVoice[i]) != AUDIO_ERROR_NONE) + { + printf("voice #%d creation failed\n",i); + return 1; + } + + ASetVoicePanning(hVoice[i],128); + + lpWave[i] = 0; + } + + /* update the Machine structure to reflect the actual sample rate */ + *rate = seal_sample_rate = info.nSampleRate; + + { + uclock_t a,b; + LONG start,end; + + + if ((lpWave[0] = (LPAUDIOWAVE)malloc(sizeof(AUDIOWAVE))) == 0) + return 1; + + lpWave[0]->wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO; + lpWave[0]->nSampleRate = seal_sample_rate; + lpWave[0]->dwLength = 3*seal_sample_rate; + lpWave[0]->dwLoopStart = 0; + lpWave[0]->dwLoopEnd = 3*seal_sample_rate; + if (ACreateAudioData(lpWave[0]) != AUDIO_ERROR_NONE) + { + free(lpWave[0]); + lpWave[0] = 0; + + return 1; + } + + memset(lpWave[0]->lpData,0,3*seal_sample_rate); + /* upload the data to the audio DRAM local memory */ + AWriteAudioData(lpWave[0],0,3*seal_sample_rate); + APrimeVoice(hVoice[0],lpWave[0]); + ASetVoiceFrequency(hVoice[0],seal_sample_rate); + ASetVoiceVolume(hVoice[0],0); + AStartVoice(hVoice[0]); + + a = uclock(); + /* wait some time to let everything stabilize */ + do + { + osd_update_audio(); + b = uclock(); + } while (b-a < UCLOCKS_PER_SEC/10); + + a = uclock(); + AGetVoicePosition(hVoice[0],&start); + do + { + osd_update_audio(); + b = uclock(); + } while (b-a < UCLOCKS_PER_SEC); + AGetVoicePosition(hVoice[0],&end); + + nominal_sample_rate = seal_sample_rate; + seal_sample_rate = end - start; + + AStopVoice(hVoice[0]); + ADestroyAudioData(lpWave[0]); + free(lpWave[0]); + lpWave[0] = 0; + } + + osd_set_mastervolume(0); /* start at maximum volume */ + + return 0; } void msdos_shutdown_sound(void) { - if (seal_sample_rate != 0) - { - int n; + if (seal_sample_rate != 0) + { + int n; - /* stop and release voices */ - for (n = 0; n < NUMVOICES; n++) - { - AStopVoice(hVoice[n]); - ADestroyAudioVoice(hVoice[n]); - if (lpWave[n]) - { - ADestroyAudioData(lpWave[n]); - free(lpWave[n]); - lpWave[n] = 0; - } - } - ACloseVoices(); - ACloseAudio(); + /* stop and release voices */ + for (n = 0; n < NUMVOICES; n++) + { + AStopVoice(hVoice[n]); + ADestroyAudioVoice(hVoice[n]); + if (lpWave[n]) + { + ADestroyAudioData(lpWave[n]); + free(lpWave[n]); + lpWave[n] = 0; + } } + ACloseVoices(); + ACloseAudio(); + } } void playstreamedsample(int channel,signed char *data,int len,int freq,int volume,int pan,int bits) { - static int playing[NUMVOICES]; - static int c[NUMVOICES]; + static int playing[NUMVOICES]; + static int c[NUMVOICES]; - /* backwards compatibility with old 0-255 volume range */ - if (volume > 100) volume = volume * 25 / 255; + /* backwards compatibility with old 0-255 volume range */ + if (volume > 100) volume = volume * 25 / 255; - if (seal_sample_rate == 0 || channel >= NUMVOICES) return; + if (seal_sample_rate == 0 || channel >= NUMVOICES) return; - if (!playing[channel]) + if (!playing[channel]) + { + if (lpWave[channel]) { - if (lpWave[channel]) - { - AStopVoice(hVoice[channel]); - ADestroyAudioData(lpWave[channel]); - free(lpWave[channel]); - lpWave[channel] = 0; - } + AStopVoice(hVoice[channel]); + ADestroyAudioData(lpWave[channel]); + free(lpWave[channel]); + lpWave[channel] = 0; + } - if ((lpWave[channel] = (LPAUDIOWAVE)malloc(sizeof(AUDIOWAVE))) == 0) - return; + if ((lpWave[channel] = (LPAUDIOWAVE)malloc(sizeof(AUDIOWAVE))) == 0) + return; - lpWave[channel]->wFormat = (bits == 8 ? AUDIO_FORMAT_8BITS : AUDIO_FORMAT_16BITS) - | AUDIO_FORMAT_MONO | AUDIO_FORMAT_LOOP; - lpWave[channel]->nSampleRate = nominal_sample_rate; - lpWave[channel]->dwLength = 3*len; - lpWave[channel]->dwLoopStart = 0; - lpWave[channel]->dwLoopEnd = 3*len; - if (ACreateAudioData(lpWave[channel]) != AUDIO_ERROR_NONE) - { - free(lpWave[channel]); - lpWave[channel] = 0; + lpWave[channel]->wFormat = (bits == 8 ? AUDIO_FORMAT_8BITS : AUDIO_FORMAT_16BITS) + | AUDIO_FORMAT_MONO | AUDIO_FORMAT_LOOP; + lpWave[channel]->nSampleRate = nominal_sample_rate; + lpWave[channel]->dwLength = 3*len; + lpWave[channel]->dwLoopStart = 0; + lpWave[channel]->dwLoopEnd = 3*len; + if (ACreateAudioData(lpWave[channel]) != AUDIO_ERROR_NONE) + { + free(lpWave[channel]); + lpWave[channel] = 0; + return; + } - return; - } + memset(lpWave[channel]->lpData,0,3*len); + memcpy(lpWave[channel]->lpData,data,len); + + /* upload the data to the audio DRAM local memory */ + AWriteAudioData(lpWave[channel],0,3*len); + APrimeVoice(hVoice[channel],lpWave[channel]); - memset(lpWave[channel]->lpData,0,3*len); - memcpy(lpWave[channel]->lpData,data,len); - /* upload the data to the audio DRAM local memory */ - AWriteAudioData(lpWave[channel],0,3*len); - APrimeVoice(hVoice[channel],lpWave[channel]); /* need to cast to double because freq*nominal_sample_rate can exceed the size of an int */ - ASetVoiceFrequency(hVoice[channel],(double)freq*nominal_sample_rate/seal_sample_rate); - AStartVoice(hVoice[channel]); - playing[channel] = 1; - c[channel] = 1; - } - else + ASetVoiceFrequency(hVoice[channel],(double)freq*nominal_sample_rate/seal_sample_rate); + AStartVoice(hVoice[channel]); + playing[channel] = 1; + c[channel] = 1; + } + else + { + LONG pos; + + for(;;) { - LONG pos; - - for(;;) - { - AGetVoicePosition(hVoice[channel],&pos); - if (c[channel] == 0 && pos >= len) break; - if (c[channel] == 1 && (pos < len || pos >= 2*len)) break; - if (c[channel] == 2 && pos < 2*len) break; - osd_update_audio(); - } - - memcpy(&lpWave[channel]->lpData[len * c[channel]],data,len); - AWriteAudioData(lpWave[channel],len*c[channel],len); - c[channel]++; - if (c[channel] == 3) c[channel] = 0; + AGetVoicePosition(hVoice[channel],&pos); + if (c[channel] == 0 && pos >= len) break; + if (c[channel] == 1 && (pos < len || pos >= 2*len)) break; + if (c[channel] == 2 && pos < 2*len) break; + osd_update_audio(); } + memcpy(&lpWave[channel]->lpData[len * c[channel]],data,len); + AWriteAudioData(lpWave[channel],len*c[channel],len); + c[channel]++; + if (c[channel] == 3) c[channel] = 0; + } - ASetVoiceVolume(hVoice[channel],volume * 64 / 100); - ASetVoicePanning(hVoice[channel],(pan + 100) * 255 / 200); + ASetVoiceVolume(hVoice[channel],volume * 64 / 100); + ASetVoicePanning(hVoice[channel],(pan + 100) * 255 / 200); } void osd_play_streamed_sample_16(int channel,signed short *data,int len,int freq,int volume,int pan) { - playstreamedsample(channel,(signed char *)data,len,freq,volume,pan,16); + playstreamedsample(channel,(signed char *)data,len,freq,volume,pan,16); } diff --git a/source/unused/dos/dos.c b/source/unused/dos/dos.c index 35a1ed0..eeb09ed 100644 --- a/source/unused/dos/dos.c +++ b/source/unused/dos/dos.c @@ -67,34 +67,34 @@ int main (int argc, char *argv[]) error_init(); cart_rom = malloc(0xA00000); - memset(cart_rom, 0, 0xA00000); + memset(cart_rom, 0, 0xA00000); - if(!load_rom(argv[1])) + if(!load_rom(argv[1])) { printf("File `%s' not found.\n", argv[1]); return (0); } - /* load BIOS */ + /* load BIOS */ memset(bios_rom, 0, sizeof(bios_rom)); - FILE *f = fopen("./BIOS.bin", "rb"); - if (f!=NULL) - { - fread(&bios_rom, 0x800,1,f); - fclose(f); - int i; - for(i = 0; i < 0x800; i += 2) - { - uint8 temp = bios_rom[i]; - bios_rom[i] = bios_rom[i+1]; - bios_rom[i+1] = temp; - } - config.bios_enabled |= 2; + FILE *f = fopen("./BIOS.bin", "rb"); + if (f!=NULL) + { + fread(&bios_rom, 0x800,1,f); + fclose(f); + int i; + for(i = 0; i < 0x800; i += 2) + { + uint8 temp = bios_rom[i]; + bios_rom[i] = bios_rom[i+1]; + bios_rom[i+1] = temp; + } + config.bios_enabled |= 2; } - else config.bios_enabled = 0; + else config.bios_enabled = 0; - /* initialize genesis VM */ + /* initialize genesis VM */ init_machine(); /* default config */ @@ -103,44 +103,45 @@ int main (int argc, char *argv[]) input.system[0] = SYSTEM_GAMEPAD; input.system[1] = SYSTEM_GAMEPAD; - /* initialize emulation */ + /* initialize emulation */ system_init(); audio_init(option.sndrate); - f = fopen("./game.srm", "rb"); - if (f!=NULL) - { - fread(&sram.sram,0x10000,1, f); - fclose(f); - } - + f = fopen("./game.srm", "rb"); + if (f!=NULL) + { + fread(&sram.sram,0x10000,1, f); + fclose(f); + } + /* reset emulation */ system_reset(); /* emulation loop */ for(;;) { + dos_update_input(); frame_count += 1; if(quit) break; if(frame_count % frame_skip == 0) { system_frame(0); frames_rendered++; - dos_update_video(); + dos_update_video(); } else { - system_frame(1); + system_frame(1,reset_line); } if(option.sound) dos_update_audio(); - } + } - f = fopen("./game.srm", "wb"); + f = fopen("./game.srm", "wb"); if (f!=NULL) { fwrite(&sram.sram, 0x10000,1,f); fclose(f); - } + } trash_machine(); system_shutdown(); @@ -153,131 +154,130 @@ int main (int argc, char *argv[]) /* Timer handler */ void tick_handler(void) { - tick_count += 1; - if(tick_count % FRAMES_PER_SECOND == 0) - { - frame_rate = frames_rendered; - frames_rendered = 0; - } + tick_count += 1; + if(tick_count % FRAMES_PER_SECOND == 0) + { + frame_rate = frames_rendered; + frames_rendered = 0; + } } END_OF_FUNCTION(tick_handler); int load_file(char *filename, char *buf, int size) { - FILE *fd = fopen(filename, "rb"); - if(!fd) return (0); - fread(buf, size, 1, fd); - fclose(fd); - return (1); + FILE *fd = fopen(filename, "rb"); + if(!fd) return (0); + fread(buf, size, 1, fd); + fclose(fd); + return (1); } int save_file(char *filename, char *buf, int size) { - FILE *fd = NULL; - if(!(fd = fopen(filename, "wb"))) return (0); - fwrite(buf, size, 1, fd); - fclose(fd); - return (1); + FILE *fd = NULL; + if(!(fd = fopen(filename, "wb"))) return (0); + fwrite(buf, size, 1, fd); + fclose(fd); + return (1); } static int joynum = 0; void dos_update_input(void) { - FILE *f; + FILE *f; - if(key[KEY_ESC] || key[KEY_END]) - { - quit = 1; - } + if(key[KEY_ESC] || key[KEY_END]) + { + quit = 1; + } while (input.dev[joynum] == NO_DEVICE) - { - joynum ++; - if (joynum > MAX_DEVICES - 1) joynum = 0; - } - + { + joynum ++; + if (joynum > MAX_DEVICES - 1) joynum = 0; + } + if(check_key(KEY_F11)) - { - - joynum ++; - if (joynum > MAX_DEVICES - 1) joynum = 0; + { + joynum ++; + if (joynum > MAX_DEVICES - 1) joynum = 0; - while (input.dev[joynum] == NO_DEVICE) - { - joynum ++; - if (joynum > MAX_DEVICES - 1) joynum = 0; - } - } - - input.pad[joynum] = 0; - - /* Is the joystick being used ? */ - if(option.joy_driver != JOY_TYPE_NONE) + while (input.dev[joynum] == NO_DEVICE) { - poll_joystick(); - - /* Check player 1 joystick */ - if(joy[0].stick[0].axis[1].d1) input.pad[0] |= INPUT_UP; - else - if(joy[0].stick[0].axis[1].d2) input.pad[0] |= INPUT_DOWN; - - if(joy[0].stick[0].axis[0].d1) input.pad[0] |= INPUT_LEFT; - else - if(joy[0].stick[0].axis[0].d2) input.pad[0] |= INPUT_RIGHT; - - if(joy[0].button[0].b) input.pad[0] |= INPUT_A; - if(joy[0].button[1].b) input.pad[0] |= INPUT_B; - if(joy[0].button[2].b) input.pad[0] |= INPUT_C; - if(joy[0].button[3].b) input.pad[0] |= INPUT_START; - if(joy[0].button[4].b) input.pad[0] |= INPUT_X; - if(joy[0].button[5].b) input.pad[0] |= INPUT_Y; - if(joy[0].button[6].b) input.pad[0] |= INPUT_Z; - if(joy[0].button[7].b) input.pad[0] |= INPUT_MODE; - - /* More than one joystick supported ? */ - if(num_joysticks > 2) - { - /* Check player 2 joystick */ - if(joy[1].stick[0].axis[1].d1) input.pad[1] |= INPUT_UP; - else - if(joy[1].stick[0].axis[1].d2) input.pad[1] |= INPUT_DOWN; - - if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_LEFT; - else - if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_RIGHT; - - if(joy[1].button[0].b) input.pad[1] |= INPUT_A; - if(joy[1].button[1].b) input.pad[1] |= INPUT_B; - if(joy[1].button[2].b) input.pad[1] |= INPUT_C; - if(joy[1].button[3].b) input.pad[1] |= INPUT_START; - if(joy[1].button[4].b) input.pad[1] |= INPUT_X; - if(joy[1].button[5].b) input.pad[1] |= INPUT_Y; - if(joy[1].button[6].b) input.pad[1] |= INPUT_Z; - if(joy[1].button[7].b) input.pad[1] |= INPUT_MODE; - } + joynum ++; + if (joynum > MAX_DEVICES - 1) joynum = 0; } + } - /* keyboard */ - if(key[KEY_UP]) input.pad[joynum] |= INPUT_UP; - else - if(key[KEY_DOWN]) input.pad[joynum] |= INPUT_DOWN; + input.pad[joynum] = 0; - if(key[KEY_LEFT]) input.pad[joynum] |= INPUT_LEFT; - else - if(key[KEY_RIGHT]) input.pad[joynum] |= INPUT_RIGHT; + /* Is the joystick being used ? */ + if(option.joy_driver != JOY_TYPE_NONE) + { + poll_joystick(); - if(key[KEY_A]) input.pad[joynum] |= INPUT_A; - if(key[KEY_S]) input.pad[joynum] |= INPUT_B; - if(key[KEY_D]) input.pad[joynum] |= INPUT_C; + /* Check player 1 joystick */ + if(joy[0].stick[0].axis[1].d1) input.pad[0] |= INPUT_UP; + else + if(joy[0].stick[0].axis[1].d2) input.pad[0] |= INPUT_DOWN; + + if(joy[0].stick[0].axis[0].d1) input.pad[0] |= INPUT_LEFT; + else + if(joy[0].stick[0].axis[0].d2) input.pad[0] |= INPUT_RIGHT; + + if(joy[0].button[0].b) input.pad[0] |= INPUT_A; + if(joy[0].button[1].b) input.pad[0] |= INPUT_B; + if(joy[0].button[2].b) input.pad[0] |= INPUT_C; + if(joy[0].button[3].b) input.pad[0] |= INPUT_START; + if(joy[0].button[4].b) input.pad[0] |= INPUT_X; + if(joy[0].button[5].b) input.pad[0] |= INPUT_Y; + if(joy[0].button[6].b) input.pad[0] |= INPUT_Z; + if(joy[0].button[7].b) input.pad[0] |= INPUT_MODE; + + /* More than one joystick supported ? */ + if(num_joysticks > 2) + { + /* Check player 2 joystick */ + if(joy[1].stick[0].axis[1].d1) input.pad[1] |= INPUT_UP; + else + if(joy[1].stick[0].axis[1].d2) input.pad[1] |= INPUT_DOWN; + + if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_LEFT; + else + if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_RIGHT; + + if(joy[1].button[0].b) input.pad[1] |= INPUT_A; + if(joy[1].button[1].b) input.pad[1] |= INPUT_B; + if(joy[1].button[2].b) input.pad[1] |= INPUT_C; + if(joy[1].button[3].b) input.pad[1] |= INPUT_START; + if(joy[1].button[4].b) input.pad[1] |= INPUT_X; + if(joy[1].button[5].b) input.pad[1] |= INPUT_Y; + if(joy[1].button[6].b) input.pad[1] |= INPUT_Z; + if(joy[1].button[7].b) input.pad[1] |= INPUT_MODE; + } + } + + /* keyboard */ + if(key[KEY_UP]) input.pad[joynum] |= INPUT_UP; + else + if(key[KEY_DOWN]) input.pad[joynum] |= INPUT_DOWN; + + if(key[KEY_LEFT]) input.pad[joynum] |= INPUT_LEFT; + else + if(key[KEY_RIGHT]) input.pad[joynum] |= INPUT_RIGHT; + + if(key[KEY_A]) input.pad[joynum] |= INPUT_A; + if(key[KEY_S]) input.pad[joynum] |= INPUT_B; + if(key[KEY_D]) input.pad[joynum] |= INPUT_C; if(key[KEY_Z]) input.pad[joynum] |= INPUT_X; - if(key[KEY_X]) input.pad[joynum] |= INPUT_Y; - if(key[KEY_C]) input.pad[joynum] |= INPUT_Z; - if(key[KEY_V]) input.pad[joynum] |= INPUT_MODE; + if(key[KEY_X]) input.pad[joynum] |= INPUT_Y; + if(key[KEY_C]) input.pad[joynum] |= INPUT_Z; + if(key[KEY_V]) input.pad[joynum] |= INPUT_MODE; + + if(key[KEY_F]) input.pad[joynum] |= INPUT_START; - if(key[KEY_F]) input.pad[joynum] |= INPUT_START; - extern uint8 pico_current; if (input.dev[joynum] == DEVICE_LIGHTGUN) { @@ -297,81 +297,80 @@ void dos_update_input(void) else if (input.dev[joynum] == DEVICE_MOUSE) { /* Poll mouse if necessary */ - if(mouse_needs_poll() == TRUE) - poll_mouse(); + if(mouse_needs_poll() == TRUE) + poll_mouse(); /* Get X & Y quantity of movement */ - get_mouse_mickeys(&input.analog[2][0], &input.analog[2][1]); + get_mouse_mickeys(&input.analog[2][0], &input.analog[2][1]); /* Sega Mouse range is -256;+256 */ - input.analog[2][0] = (input.analog[2][0] * 256) / SCREEN_W; - input.analog[2][1] = (input.analog[2][1] * 256) / SCREEN_H; + input.analog[2][0] = (input.analog[2][0] * 256) / SCREEN_W; + input.analog[2][1] = (input.analog[2][1] * 256) / SCREEN_H; /* Vertical movement is upsidedown */ if (!config.invert_mouse) input.analog[2][1] = 0 - input.analog[2][1]; - - /* Map mouse buttons to player #1 inputs */ - if(mouse_b & 4) input.pad[joynum] |= INPUT_C; - if(mouse_b & 1) input.pad[joynum] |= INPUT_B; - if(mouse_b & 2) input.pad[joynum] |= INPUT_A; - } + + /* Map mouse buttons to player #1 inputs */ + if(mouse_b & 4) input.pad[joynum] |= INPUT_C; + if(mouse_b & 1) input.pad[joynum] |= INPUT_B; + if(mouse_b & 2) input.pad[joynum] |= INPUT_A; + } else if (system_hw == SYSTEM_PICO) { - /* Poll mouse if necessary */ - if(mouse_needs_poll() == TRUE) - poll_mouse(); + /* Poll mouse if necessary */ + if(mouse_needs_poll() == TRUE) + poll_mouse(); /* Calculate X Y axis values */ input.analog[0][0] = 0x3c + (mouse_x * (0x17c-0x03c+1)) / SCREEN_W; input.analog[0][1] = 0x1fc + (mouse_y * (0x2f7-0x1fc+1)) / SCREEN_H; - /* Map mouse buttons to player #1 inputs */ - if(mouse_b & 2) input.pad[0] |= INPUT_B; - if(mouse_b & 1) input.pad[0] |= INPUT_A; - if(mouse_b & 4) pico_current++; - if (pico_current > 6) pico_current = 0; + /* Map mouse buttons to player #1 inputs */ + if(mouse_b & 2) input.pad[0] |= INPUT_B; + if(mouse_b & 1) input.pad[0] |= INPUT_A; + if(mouse_b & 4) pico_current++; + if (pico_current > 6) pico_current = 0; } - - if(check_key(KEY_F1)) frame_skip = 1; - if(check_key(KEY_F2)) frame_skip = 2; - if(check_key(KEY_F3)) frame_skip = 3; - if(check_key(KEY_F4)) frame_skip = 4; + if(check_key(KEY_F1)) frame_skip = 1; + if(check_key(KEY_F2)) frame_skip = 2; + if(check_key(KEY_F3)) frame_skip = 3; + if(check_key(KEY_F4)) frame_skip = 4; - if(check_key(KEY_F5)) log_error ^= 1; - if(check_key(KEY_F6)) debug_on ^= 1; - - if(check_key(KEY_F7)) - { - f = fopen("game.gpz","r+b"); - if (f) - { - fread(&buf, 0x23000, 1, f); - state_load(buf); - fclose(f); - } - } + if(check_key(KEY_F5)) log_error ^= 1; + if(check_key(KEY_F6)) debug_on ^= 1; - if(check_key(KEY_F8)) - { - f = fopen("game.gpz","w+b"); - if (f) - { - state_save(buf); - fwrite(&buf, 0x23000, 1, f); - fclose(f); - } + if(check_key(KEY_F7)) + { + f = fopen("game.gpz","r+b"); + if (f) + { + fread(&buf, 0x23000, 1, f); + state_load(buf); + fclose(f); + } } - if(check_key(KEY_F9)) + if(check_key(KEY_F8)) + { + f = fopen("game.gpz","w+b"); + if (f) + { + state_save(buf); + fwrite(&buf, 0x23000, 1, f); + fclose(f); + } + } + + if(check_key(KEY_F9)) { vdp_pal ^= 1; /* reinitialize timings */ system_init (); - audio_init(option.sndrate); + audio_init(option.sndrate); fm_restore(); - + /* reinitialize HVC tables */ vctab = (vdp_pal) ? ((reg[1] & 8) ? vc_pal_240 : vc_pal_224) : vc_ntsc_224; hctab = (reg[12] & 1) ? cycle2hc40 : cycle2hc32; @@ -382,268 +381,267 @@ void dos_update_input(void) bitmap.viewport.changed = 1; } - if(check_key(KEY_F10)) set_softreset(); - if(check_key(KEY_TAB)) system_reset(); + if(check_key(KEY_F10)) set_softreset(); + if(check_key(KEY_TAB)) system_reset(); } void dos_update_audio(void) { - osd_play_streamed_sample_16(option.swap ^ 0, snd.buffer[0], snd.buffer_size * 2, option.sndrate, FRAMES_PER_SECOND, -100); - osd_play_streamed_sample_16(option.swap ^ 1, snd.buffer[1], snd.buffer_size * 2, option.sndrate, FRAMES_PER_SECOND, 100); + osd_play_streamed_sample_16(option.swap ^ 0, snd.buffer[0], snd.buffer_size * 2, option.sndrate, FRAMES_PER_SECOND, -100); + osd_play_streamed_sample_16(option.swap ^ 1, snd.buffer[1], snd.buffer_size * 2, option.sndrate, FRAMES_PER_SECOND, 100); } #if 0 void dos_update_palette(void) { - if(is_border_dirty) + if(is_border_dirty) + { + uint16 data = *(uint16 *)&cram[(border << 1)]; + RGB *color; + + is_border_dirty = 0; + + if(reg[12] & 8) { - uint16 data = *(uint16 *)&cram[(border << 1)]; + int j; + for(j = 0; j < 3; j += 1) + { + color = &vdp_palette[j][data]; + set_color((j << 6), color); + } + } + else + { + color = &vdp_palette[1][data]; + set_color(0x00, color); + set_color(0x40, color); + set_color(0x80, color); + } + } + + if(is_color_dirty) + { + int i; + uint16 *p = (uint16 *)&cram[0]; + is_color_dirty = 0; + + for(i = 0; i < 64; i += 1) + { + if((color_dirty[i]) && ((i & 0x0F) != 0x00)) + { RGB *color; - - is_border_dirty = 0; - + color_dirty[i] = 0; if(reg[12] & 8) { - int j; - for(j = 0; j < 3; j += 1) - { - color = &vdp_palette[j][data]; - set_color((j << 6), color); - } + int j; + for(j = 0; j < 3; j += 1) + { + color = &vdp_palette[j][p[i]]; + set_color((j << 6) | i, color); + } } else { - color = &vdp_palette[1][data]; - set_color(0x00, color); - set_color(0x40, color); - set_color(0x80, color); - } - } - - if(is_color_dirty) - { - int i; - uint16 *p = (uint16 *)&cram[0]; - is_color_dirty = 0; - - for(i = 0; i < 64; i += 1) - { - if((color_dirty[i]) && ((i & 0x0F) != 0x00)) - { - RGB *color; - color_dirty[i] = 0; - if(reg[12] & 8) - { - int j; - for(j = 0; j < 3; j += 1) - { - color = &vdp_palette[j][p[i]]; - set_color((j << 6) | i, color); - } - } - else - { - color = &vdp_palette[1][p[i]]; - set_color(0x00 | i, color); - set_color(0x40 | i, color); - set_color(0x80 | i, color); - } - } + color = &vdp_palette[1][p[i]]; + set_color(0x00 | i, color); + set_color(0x40 | i, color); + set_color(0x80 | i, color); } + } } + } } #endif void dos_update_video(void) { - int width = (bitmap.viewport.w + 2 * bitmap.viewport.x); - int height = (bitmap.viewport.h + 2 * bitmap.viewport.y) << (interlaced ? 1:0); - int center_x = (SCREEN_W - width) / 2; - int center_y = (SCREEN_H / (option.scanlines ? 4 : 2)) - (height / 2); + int width = (bitmap.viewport.w + 2 * bitmap.viewport.x); + int height = (bitmap.viewport.h + 2 * bitmap.viewport.y) << (interlaced ? 1:0); + int center_x = (SCREEN_W - width) / 2; + int center_y = (SCREEN_H / (option.scanlines ? 4 : 2)) - (height / 2); - /* Wait for VSync */ - if(option.vsync) vsync(); + /* Wait for VSync */ + if(option.vsync) vsync(); - if(bitmap.viewport.changed) + if(bitmap.viewport.changed) + { + bitmap.viewport.changed = 0; + if(bitmap.remap) { - bitmap.viewport.changed = 0; - if(bitmap.remap) - { - clear(screen); - } - else - { - clear_to_color(screen, 0xFF); - } - } - -#if 0 - if(bitmap.remap == 0) - { - dos_update_palette(); - } -#endif - - msg_print(2, 2, "offset = 0x%x", hc_latch/*frame_rate*/); - - if(option.scanlines) - { - int y; - for(y = 0; y < height; y += 1) - { - blit(gen_bmp, screen, 0x0, y, center_x, (center_y + y) << 1, width, 1); - } + clear(screen); } else { - stretch_blit(gen_bmp, screen, 0, 0, width, height, (SCREEN_W-352)/2, (SCREEN_H-240)/2, 352,240 << (interlaced ? 1:0)); - + clear_to_color(screen, 0xFF); } + } + +#if 0 + if(bitmap.remap == 0) + { + dos_update_palette(); + } +#endif + + msg_print(2, 2, "%d", frame_rate); + + if(option.scanlines) + { + int y; + for(y = 0; y < height; y += 1) + { + blit(gen_bmp, screen, 0x0, y, center_x, (center_y + y) << 1, width, 1); + } + } + else + { + stretch_blit(gen_bmp, screen, 0, 0, width, height, (SCREEN_W-352)/2, (SCREEN_H-240)/2, 352,240 << (interlaced ? 1:0)); + } } void init_machine(void) { - do_config("gen.cfg"); + do_config("gen.cfg"); - if(option.sound) - { - msdos_init_sound(&option.sndrate, option.sndcard); - } + if(option.sound) + { + msdos_init_sound(&option.sndrate, option.sndcard); + } - allegro_init(); - install_mouse(); - install_keyboard(); - install_joystick(option.joy_driver); + allegro_init(); + install_mouse(); + install_keyboard(); + install_joystick(option.joy_driver); - install_timer(); - LOCK_FUNCTION(tick_handler); - LOCK_VARIABLE(tick_count); - LOCK_VARIABLE(frame_rate); - install_int_ex(tick_handler, BPS_TO_TIMER(FRAMES_PER_SECOND)); + install_timer(); + LOCK_FUNCTION(tick_handler); + LOCK_VARIABLE(tick_count); + LOCK_VARIABLE(frame_rate); + install_int_ex(tick_handler, BPS_TO_TIMER(FRAMES_PER_SECOND)); - set_color_depth(option.video_depth); - gen_bmp = create_bitmap(360, 576); - clear(gen_bmp); + set_color_depth(option.video_depth); + gen_bmp = create_bitmap(720, 576); + clear(gen_bmp); - memset(&bitmap, 0, sizeof(bitmap)); - bitmap.data = (uint8 *)&gen_bmp->line[0][0]; - bitmap.width = gen_bmp->w; - bitmap.height = gen_bmp->h; - bitmap.depth = option.video_depth; - switch(option.video_depth) - { - case 8: - bitmap.granularity = 1; - break; - case 15: - bitmap.granularity = 2; - break; - case 16: - bitmap.granularity = 2; - break; - case 32: - bitmap.granularity = 4; - break; - } - bitmap.pitch = (bitmap.width * bitmap.granularity); - bitmap.viewport.w = 256; - bitmap.viewport.h = 224; - bitmap.viewport.x = 0x00; - bitmap.viewport.y = 0x00; - bitmap.remap = 0; - if(option.remap) bitmap.remap = 1; - else - if(bitmap.depth > 8) bitmap.remap = 1; + memset(&bitmap, 0, sizeof(bitmap)); + bitmap.data = (uint8 *)&gen_bmp->line[0][0]; + bitmap.width = gen_bmp->w; + bitmap.height = gen_bmp->h; + bitmap.depth = option.video_depth; + switch(option.video_depth) + { + case 8: + bitmap.granularity = 1; + break; + case 15: + bitmap.granularity = 2; + break; + case 16: + bitmap.granularity = 2; + break; + case 32: + bitmap.granularity = 4; + break; + } + bitmap.pitch = (bitmap.width * bitmap.granularity); + bitmap.viewport.w = 256; + bitmap.viewport.h = 224; + bitmap.viewport.x = 0x00; + bitmap.viewport.y = 0x00; + bitmap.remap = 0; + if(option.remap) bitmap.remap = 1; + else + if(bitmap.depth > 8) bitmap.remap = 1; - make_vdp_palette(); + make_vdp_palette(); - memcpy(gen_pal, black_palette, sizeof(PALETTE)); - gen_pal[0xFE].r = \ - gen_pal[0xFE].g = \ - gen_pal[0xFE].b = 0x3F; + memcpy(gen_pal, black_palette, sizeof(PALETTE)); + gen_pal[0xFE].r = \ + gen_pal[0xFE].g = \ + gen_pal[0xFE].b = 0x3F; - dos_change_mode(); + dos_change_mode(); } void trash_machine(void) { - if(option.sound) - { - msdos_shutdown_sound(); - } - clear(screen); - destroy_bitmap(gen_bmp); - set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); + if(option.sound) + { + msdos_shutdown_sound(); + } + clear(screen); + destroy_bitmap(gen_bmp); + set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); } void make_vdp_palette(void) { - uint8 lut[3][8] = - { - {0x00, 0x04, 0x08, 0x0C, 0x10, 0x14, 0x18, 0x1C}, - {0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38}, - {0x20, 0x24, 0x28, 0x2C, 0x30, 0x34, 0x38, 0x3C}, - }; + uint8 lut[3][8] = + { + {0x00, 0x04, 0x08, 0x0C, 0x10, 0x14, 0x18, 0x1C}, + {0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38}, + {0x20, 0x24, 0x28, 0x2C, 0x30, 0x34, 0x38, 0x3C}, + }; - int j; - for(j = 0; j < 0x600; j += 1) - { + int j; + for(j = 0; j < 0x600; j += 1) + { - int r = (j >> 6) & 7; - int g = (j >> 3) & 7; - int b = (j >> 0) & 7; - int i = (j >> 9) & 3; + int r = (j >> 6) & 7; + int g = (j >> 3) & 7; + int b = (j >> 0) & 7; + int i = (j >> 9) & 3; - vdp_palette[i][j & 0x1FF].r = lut[i][r]; - vdp_palette[i][j & 0x1FF].g = lut[i][g]; - vdp_palette[i][j & 0x1FF].b = lut[i][b]; - } + vdp_palette[i][j & 0x1FF].r = lut[i][r]; + vdp_palette[i][j & 0x1FF].g = lut[i][g]; + vdp_palette[i][j & 0x1FF].b = lut[i][b]; + } } void dos_change_mode(void) { - int ret; - int width = option.video_width; - int height = option.video_height; + int ret; + int width = option.video_width; + int height = option.video_height; - if(option.scanlines) height *= 2; - ret = set_gfx_mode(option.video_driver, width, height, 0, 0); - if(ret != 0) - { - set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); - printf("Error setting graphics mode (%dx%d %dbpp).\nAllegro says: `%s'\n", width, height, option.video_depth, allegro_error); - exit(1); - } + if(option.scanlines) height *= 2; + ret = set_gfx_mode(option.video_driver, width, height, 0, 0); + if(ret != 0) + { + set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); + printf("Error setting graphics mode (%dx%d %dbpp).\nAllegro says: `%s'\n", width, height, option.video_depth, allegro_error); + exit(1); + } - if(bitmap.depth == 8) + if(bitmap.depth == 8) + { + if(bitmap.remap) { - if(bitmap.remap) - { - int i; - for(i = 0; i < 0x100; i += 1) - { - gen_pal[i].r = ((i >> 5) & 7) << 3; - gen_pal[i].g = ((i >> 2) & 7) << 3; - gen_pal[i].b = ((i >> 0) & 3) << 4; - } - set_palette(gen_pal); - } - else - { - clear_to_color(screen, 0xFF); - gen_pal[0xfe].r = 0xff; - gen_pal[0xfe].g = 0xff; - gen_pal[0xfe].b = 0xff; - set_palette(gen_pal); - inp(0x3DA); - outp(0x3C0, 0x31); - outp(0x3C0, 0xFF); - } + int i; + for(i = 0; i < 0x100; i += 1) + { + gen_pal[i].r = ((i >> 5) & 7) << 3; + gen_pal[i].g = ((i >> 2) & 7) << 3; + gen_pal[i].b = ((i >> 0) & 3) << 4; + } + set_palette(gen_pal); } else { - clear(screen); + clear_to_color(screen, 0xFF); + gen_pal[0xfe].r = 0xff; + gen_pal[0xfe].g = 0xff; + gen_pal[0xfe].b = 0xff; + set_palette(gen_pal); + inp(0x3DA); + outp(0x3C0, 0x31); + outp(0x3C0, 0xFF); } + } + else + { + clear(screen); + } } @@ -651,17 +649,17 @@ void dos_change_mode(void) /* Check if a key is pressed */ int check_key(int code) { - static char lastbuf[0x100] = {0}; + static char lastbuf[0x100] = {0}; - if((!key[code]) && (lastbuf[code] == 1)) - lastbuf[code] = 0; + if((!key[code]) && (lastbuf[code] == 1)) + lastbuf[code] = 0; - if((key[code]) && (lastbuf[code] == 0)) - { - lastbuf[code] = 1; - return (1); - } + if((key[code]) && (lastbuf[code] == 0)) + { + lastbuf[code] = 1; + return (1); + } - return (0); + return (0); } diff --git a/source/unused/dos/dos.h b/source/unused/dos/dos.h index 6f0717c..0f2a36b 100644 --- a/source/unused/dos/dos.h +++ b/source/unused/dos/dos.h @@ -17,7 +17,6 @@ void make_vdp_palette(void); void dos_change_mode(void); int check_key(int code); -#define update_input() dos_update_input() #define MAX_INPUTS 8 extern uint8 debug_on; diff --git a/source/unused/dos/error.c b/source/unused/dos/error.c index 8d6ad24..f8cd443 100644 --- a/source/unused/dos/error.c +++ b/source/unused/dos/error.c @@ -4,9 +4,9 @@ FILE *error_log; struct { - int enabled; - int verbose; - FILE *log; + int enabled; + int verbose; + FILE *log; } t_error; void error_init(void) @@ -23,8 +23,8 @@ void error_shutdown(void) void error(char *format, ...) { - if (!log_error) return; - va_list ap; + if (!log_error) return; + va_list ap; va_start(ap, format); if(error_log) vfprintf(error_log, format, ap); va_end(ap); diff --git a/source/unused/dos/unzip.c b/source/unused/dos/unzip.c new file mode 100644 index 0000000..90e8618 --- /dev/null +++ b/source/unused/dos/unzip.c @@ -0,0 +1,1294 @@ +/* unzip.c -- IO on .zip files using zlib + Version 0.15 beta, Mar 19th, 1998, + + Read unzip.h for more info +*/ + + +#include +#include +#include +#include "zlib.h" +#include "unzip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else + #include +#endif + + +#ifndef local + #define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + + + +#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \ + !defined(CASESENSITIVITYDEFAULT_NO) +#define CASESENSITIVITYDEFAULT_NO +#endif + + +#ifndef UNZ_BUFSIZE +#define UNZ_BUFSIZE (16384) +#endif + +#ifndef UNZ_MAXFILENAMEINZIP +#define UNZ_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +const char unz_copyright[] = + " unzip 0.15 Copyright 1998 Gilles Vollant "; + +/* unz_file_info_interntal contain internal info about a file in zipfile*/ +typedef struct unz_file_info_internal_s +{ + uLong offset_curfile;/* relative offset of local header 4 bytes */ +} unz_file_info_internal; + + +/* file_in_zip_read_info_s contain internal information about a file in zipfile, + when reading and decompress it */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + + uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ + uLong stream_initialised; /* flag set if stream structure is initialised*/ + + uLong offset_local_extrafield;/* offset of the local extra field */ + uInt size_local_extrafield;/* size of the local extra field */ + uLong pos_local_extrafield; /* position in the local extra field in read*/ + + uLong crc32; /* crc32 of all data uncompressed */ + uLong crc32_wait; /* crc32 we must obtain after decompress all */ + uLong rest_read_compressed; /* number of byte to be decompressed */ + uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ + FILE* file; /* io structore of the zipfile */ + uLong compression_method; /* compression method (0==store) */ + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ +} file_in_zip_read_info_s; + + +/* unz_s contain internal information about the zipfile +*/ +typedef struct +{ + FILE* file; /* io structore of the zipfile */ + unz_global_info gi; /* public global information */ + uLong byte_before_the_zipfile; /* byte before the zipfile, (>0 for sfx)*/ + uLong num_file; /* number of the current file in the zipfile*/ + uLong pos_in_central_dir; /* pos of the current file in the central dir*/ + uLong current_file_ok; /* flag about the usability of the current file*/ + uLong central_pos; /* position of the beginning of the central dir*/ + + uLong size_central_dir; /* size of the central directory */ + uLong offset_central_dir; /* offset of start of central directory with + respect to the starting disk number */ + + unz_file_info cur_file_info; /* public info about the current file in zip*/ + unz_file_info_internal cur_file_info_internal; /* private info about it*/ + file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current + file if we are decompressing it */ +} unz_s; + + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been sucessfully opened for reading. +*/ + + +local int unzlocal_getByte(fin,pi) + FILE *fin; + int *pi; +{ + unsigned char c; + int err = fread(&c, 1, 1, fin); + if (err==1) + { + *pi = (int)c; + return UNZ_OK; + } + else + { + if (ferror(fin)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int unzlocal_getShort (fin,pX) + FILE* fin; + uLong *pX; +{ + uLong x ; + int i = 0; + int err; + + err = unzlocal_getByte(fin,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<8; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unzlocal_getLong (fin,pX) + FILE* fin; + uLong *pX; +{ + uLong x ; + int i = 0; + int err; + + err = unzlocal_getByte(fin,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<8; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<16; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<24; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + + +/* My own strcmpi / strcasecmp */ +local int strcmpcasenosensitive_internal (fileName1,fileName2) + const char* fileName1; + const char* fileName2; +{ + for (;;) + { + char c1=*(fileName1++); + char c2=*(fileName2++); + if ((c1>='a') && (c1<='z')) + c1 -= 0x20; + if ((c2>='a') && (c2<='z')) + c2 -= 0x20; + if (c1=='\0') + return ((c2=='\0') ? 0 : -1); + if (c2=='\0') + return 1; + if (c1c2) + return 1; + } +} + + +#ifdef CASESENSITIVITYDEFAULT_NO +#define CASESENSITIVITYDEFAULTVALUE 2 +#else +#define CASESENSITIVITYDEFAULTVALUE 1 +#endif + +#ifndef STRCMPCASENOSENTIVEFUNCTION +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal +#endif + +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) + +*/ +extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) + const char* fileName1; + const char* fileName2; + int iCaseSensitivity; +{ + if (iCaseSensitivity==0) + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; + + if (iCaseSensitivity==1) + return strcmp(fileName1,fileName2); + + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); +} + +#define BUFREADCOMMENT (0x400) + +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local uLong unzlocal_SearchCentralDir(fin) + FILE *fin; +{ + unsigned char* buf; + uLong uSizeFile; + uLong uBackRead; + uLong uMaxBack=0xffff; /* maximum size of global comment */ + uLong uPosFound=0; + + if (fseek(fin,0,SEEK_END) != 0) + return 0; + + + uSizeFile = ftell( fin ); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); + if (fseek(fin,uReadPos,SEEK_SET)!=0) + break; + + if (fread(buf,(uInt)uReadSize,1,fin)!=1) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer + "zlib/zlib109.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ +extern unzFile ZEXPORT unzOpen (path) + const char *path; +{ + unz_s us; + unz_s *s; + uLong central_pos,uL; + FILE * fin ; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + uLong number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + + int err=UNZ_OK; + + if (unz_copyright[0]!=' ') + return NULL; + + fin=fopen(path,"rb"); + if (fin==NULL) + return NULL; + + central_pos = unzlocal_SearchCentralDir(fin); + if (central_pos==0) + err=UNZ_ERRNO; + + if (fseek(fin,central_pos,SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unzlocal_getLong(fin,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir on this disk */ + if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir */ + if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* zipfile comment length */ + if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((central_pospfile_in_zip_read!=NULL) + unzCloseCurrentFile(file); + + fclose(s->file); + TRYFREE(s); + return UNZ_OK; +} + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ +extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) + unzFile file; + unz_global_info *pglobal_info; +{ + unz_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + *pglobal_info=s->gi; + return UNZ_OK; +} + + +/* + Translate date/time from Dos format to tm_unz (readable more easilty) +*/ +local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) + uLong ulDosDate; + tm_unz* ptm; +{ + uLong uDate; + uDate = (uLong)(ulDosDate>>16); + ptm->tm_mday = (uInt)(uDate&0x1f) ; + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; + + ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; +} + +/* + Get Info about the current file in the zipfile, with internal only info +*/ +local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, + unz_file_info *pfile_info, + unz_file_info_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +local int unzlocal_GetCurrentFileInfoInternal (file, + pfile_info, + pfile_info_internal, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + unz_file_info_internal *pfile_info_internal; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + unz_s* s; + unz_file_info file_info; + unz_file_info_internal file_info_internal; + int err=UNZ_OK; + uLong uMagic; + long lSeek=0; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0) + err=UNZ_ERRNO; + + + /* we check the magic */ + if (err==UNZ_OK) + { + if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x02014b50) + err=UNZ_BADZIPFILE; + } + + if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK) + err=UNZ_ERRNO; + + unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); + + if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + + lSeek+=file_info.size_filename; + if ((err==UNZ_OK) && (szFileName!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_filename0) && (fileNameBufferSize>0)) + if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek -= uSizeRead; + } + + if ((err==UNZ_OK) && (extraField!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_extrafile,lSeek,SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) + if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek += file_info.size_file_extra - uSizeRead; + } + else + lSeek+=file_info.size_file_extra; + + if ((err==UNZ_OK) && (szComment!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_commentfile,lSeek,SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_comment>0) && (commentBufferSize>0)) + if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek+=file_info.size_file_comment - uSizeRead; + } + else + lSeek+=file_info.size_file_comment; + + if ((err==UNZ_OK) && (pfile_info!=NULL)) + *pfile_info=file_info; + + if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) + *pfile_info_internal=file_info_internal; + + return err; +} + + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. +*/ +extern int ZEXPORT unzGetCurrentFileInfo (file, + pfile_info, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); +} + +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ +extern int ZEXPORT unzGoToFirstFile (file) + unzFile file; +{ + int err=UNZ_OK; + unz_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + s->pos_in_central_dir=s->offset_central_dir; + s->num_file=0; + err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ +extern int ZEXPORT unzGoToNextFile (file) + unzFile file; +{ + unz_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + if (s->num_file+1==s->gi.number_entry) + return UNZ_END_OF_LIST_OF_FILE; + + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; + s->num_file++; + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzipStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ +extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) + unzFile file; + const char *szFileName; + int iCaseSensitivity; +{ + unz_s* s; + int err; + + uLong num_fileSaved; + uLong pos_in_central_dirSaved; + + if (file==NULL) + return UNZ_PARAMERROR; + + if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) + return UNZ_PARAMERROR; + + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + num_fileSaved = s->num_file; + pos_in_central_dirSaved = s->pos_in_central_dir; + + err = unzGoToFirstFile(file); + + while (err == UNZ_OK) + { + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; + unzGetCurrentFileInfo(file,NULL, + szCurrentFileName,sizeof(szCurrentFileName)-1, + NULL,0,NULL,0); + if (unzStringFileNameCompare(szCurrentFileName, + szFileName,iCaseSensitivity)==0) + return UNZ_OK; + err = unzGoToNextFile(file); + } + + s->num_file = num_fileSaved ; + s->pos_in_central_dir = pos_in_central_dirSaved ; + return err; +} + + +/* + Read the local header of the current zipfile + Check the coherency of the local header and info in the end of central + directory about this file + store in *piSizeVar the size of extra info in local header + (filename and size of extra field data) +*/ +local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, + poffset_local_extrafield, + psize_local_extrafield) + unz_s* s; + uInt* piSizeVar; + uLong *poffset_local_extrafield; + uInt *psize_local_extrafield; +{ + uLong uMagic,uData,uFlags; + uLong size_filename; + uLong size_extra_field; + int err=UNZ_OK; + + *piSizeVar = 0; + *poffset_local_extrafield = 0; + *psize_local_extrafield = 0; + + if (fseek(s->file,s->cur_file_info_internal.offset_curfile + + s->byte_before_the_zipfile,SEEK_SET)!=0) + return UNZ_ERRNO; + + + if (err==UNZ_OK) + { + if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x04034b50) + err=UNZ_BADZIPFILE; + } + + if (unzlocal_getShort(s->file,&uData) != UNZ_OK) + err=UNZ_ERRNO; +/* + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) + err=UNZ_BADZIPFILE; +*/ + if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&uData) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) + err=UNZ_BADZIPFILE; + + if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */ + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + + if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) + err=UNZ_BADZIPFILE; + + *piSizeVar += (uInt)size_filename; + + if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK) + err=UNZ_ERRNO; + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + + SIZEZIPLOCALHEADER + size_filename; + *psize_local_extrafield = (uInt)size_extra_field; + + *piSizeVar += (uInt)size_extra_field; + + return err; +} + +/* + Open for reading data the current file in the zipfile. + If there is no error and the file is opened, the return value is UNZ_OK. +*/ +extern int ZEXPORT unzOpenCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + int Store; + uInt iSizeVar; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uLong offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_PARAMERROR; + + if (s->pfile_in_zip_read != NULL) + unzCloseCurrentFile(file); + + if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, + &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) + return UNZ_BADZIPFILE; + + pfile_in_zip_read_info = (file_in_zip_read_info_s*) + ALLOC(sizeof(file_in_zip_read_info_s)); + if (pfile_in_zip_read_info==NULL) + return UNZ_INTERNALERROR; + + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; + pfile_in_zip_read_info->pos_local_extrafield=0; + + if (pfile_in_zip_read_info->read_buffer==NULL) + { + TRYFREE(pfile_in_zip_read_info); + return UNZ_INTERNALERROR; + } + + pfile_in_zip_read_info->stream_initialised=0; + + if ((s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + Store = s->cur_file_info.compression_method==0; + + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; + pfile_in_zip_read_info->crc32=0; + pfile_in_zip_read_info->compression_method = + s->cur_file_info.compression_method; + pfile_in_zip_read_info->file=s->file; + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; + + pfile_in_zip_read_info->stream.total_out = 0; + + if (!Store) + { + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; + pfile_in_zip_read_info->stream.zfree = (free_func)0; + pfile_in_zip_read_info->stream.opaque = (voidpf)0; + + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised=1; + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + * In unzip, i don't wait absolutely Z_STREAM_END because I known the + * size of both compressed and uncompressed data + */ + } + pfile_in_zip_read_info->rest_read_compressed = + s->cur_file_info.compressed_size ; + pfile_in_zip_read_info->rest_read_uncompressed = + s->cur_file_info.uncompressed_size ; + + pfile_in_zip_read_info->pos_in_zipfile = + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + + iSizeVar; + + pfile_in_zip_read_info->stream.avail_in = (uInt)0; + + + s->pfile_in_zip_read = pfile_in_zip_read_info; + return UNZ_OK; +} + + +/* + Read bytes from the current file. + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ +extern int ZEXPORT unzReadCurrentFile (file, buf, len) + unzFile file; + voidp buf; + unsigned len; +{ + int err=UNZ_OK; + uInt iRead = 0; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if ((pfile_in_zip_read_info->read_buffer == NULL)) + return UNZ_END_OF_LIST_OF_FILE; + if (len==0) + return 0; + + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; + + pfile_in_zip_read_info->stream.avail_out = (uInt)len; + + if (len>pfile_in_zip_read_info->rest_read_uncompressed) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; + + while (pfile_in_zip_read_info->stream.avail_out>0) + { + if ((pfile_in_zip_read_info->stream.avail_in==0) && + (pfile_in_zip_read_info->rest_read_compressed>0)) + { + uInt uReadThis = UNZ_BUFSIZE; + if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; + if (uReadThis == 0) + return UNZ_EOF; + if (fseek(pfile_in_zip_read_info->file, + pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) + return UNZ_ERRNO; + if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1, + pfile_in_zip_read_info->file)!=1) + return UNZ_ERRNO; + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; + + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; + + pfile_in_zip_read_info->stream.next_in = + (Bytef*)pfile_in_zip_read_info->read_buffer; + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; + } + + if (pfile_in_zip_read_info->compression_method==0) + { + uInt uDoCopy,i ; + if (pfile_in_zip_read_info->stream.avail_out < + pfile_in_zip_read_info->stream.avail_in) + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; + else + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; + + for (i=0;istream.next_out+i) = + *(pfile_in_zip_read_info->stream.next_in+i); + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, + pfile_in_zip_read_info->stream.next_out, + uDoCopy); + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; + pfile_in_zip_read_info->stream.next_out += uDoCopy; + pfile_in_zip_read_info->stream.next_in += uDoCopy; + pfile_in_zip_read_info->stream.total_out += uDoCopy; + iRead += uDoCopy; + } + else + { + uLong uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + uLong uOutThis; + int flush=Z_SYNC_FLUSH; + + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; + bufBefore = pfile_in_zip_read_info->stream.next_out; + + /* + if ((pfile_in_zip_read_info->rest_read_uncompressed == + pfile_in_zip_read_info->stream.avail_out) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + flush = Z_FINISH; + */ + err=inflate(&pfile_in_zip_read_info->stream,flush); + + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->crc32 = + crc32(pfile_in_zip_read_info->crc32,bufBefore, + (uInt)(uOutThis)); + + pfile_in_zip_read_info->rest_read_uncompressed -= + uOutThis; + + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + if (err==Z_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=Z_OK) + break; + } + } + + if (err==Z_OK) + return iRead; + return err; +} + + +/* + Give the current position in uncompressed data +*/ +extern z_off_t ZEXPORT unztell (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + return (z_off_t)pfile_in_zip_read_info->stream.total_out; +} + + +/* + return 1 if the end of file was reached, 0 elsewhere +*/ +extern int ZEXPORT unzeof (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + return 1; + else + return 0; +} + +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field that can be read + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ +extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) + unzFile file; + voidp buf; + unsigned len; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uInt read_now; + uLong size_to_read; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - + pfile_in_zip_read_info->pos_local_extrafield); + + if (buf==NULL) + return (int)size_to_read; + + if (len>size_to_read) + read_now = (uInt)size_to_read; + else + read_now = (uInt)len ; + + if (read_now==0) + return 0; + + if (fseek(pfile_in_zip_read_info->file, + pfile_in_zip_read_info->offset_local_extrafield + + pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0) + return UNZ_ERRNO; + + if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1) + return UNZ_ERRNO; + + return (int)read_now; +} + +/* + Close the file in zip opened with unzipOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ +extern int ZEXPORT unzCloseCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + { + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) + err=UNZ_CRCERROR; + } + + + TRYFREE(pfile_in_zip_read_info->read_buffer); + pfile_in_zip_read_info->read_buffer = NULL; + if (pfile_in_zip_read_info->stream_initialised) + inflateEnd(&pfile_in_zip_read_info->stream); + + pfile_in_zip_read_info->stream_initialised = 0; + TRYFREE(pfile_in_zip_read_info); + + s->pfile_in_zip_read=NULL; + + return err; +} + + +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ +extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) + unzFile file; + char *szComment; + uLong uSizeBuf; +{ +/* int err=UNZ_OK; */ + unz_s* s; + uLong uReadThis ; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + + uReadThis = uSizeBuf; + if (uReadThis>s->gi.size_comment) + uReadThis = s->gi.size_comment; + + if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0) + return UNZ_ERRNO; + + if (uReadThis>0) + { + *szComment='\0'; + if (fread(szComment,(uInt)uReadThis,1,s->file)!=1) + return UNZ_ERRNO; + } + + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) + *(szComment+s->gi.size_comment)='\0'; + return (int)uReadThis; +} diff --git a/source/unused/dos/unzip.h b/source/unused/dos/unzip.h new file mode 100644 index 0000000..a30f79c --- /dev/null +++ b/source/unused/dos/unzip.h @@ -0,0 +1,273 @@ +/* unzip.h -- IO for uncompress .zip files using zlib + Version 0.15 beta, Mar 19th, 1998, + + Copyright (C) 1998 Gilles Vollant + + This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g + WinZip, InfoZip tools and compatible. + Encryption and multi volume ZipFile (span) are not supported. + Old compressions used by old PKZip 1.x are not supported + + THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE + CAN CHANGE IN FUTURE VERSION !! + I WAIT FEEDBACK at mail info@winimage.com + Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* for more info about .ZIP format, see + ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip + PkWare has also a specification at : + ftp://ftp.pkware.com/probdesc.zip */ + +#ifndef _unz_H +#define _unz_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef voidp unzFile; +#endif + + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + +/* tm_unz contain date/time info */ +typedef struct tm_unz_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_unz; + +/* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ +typedef struct unz_global_info_s +{ + uLong number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info; + + +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_info_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + uLong compressed_size; /* compressed size 4 bytes */ + uLong uncompressed_size; /* uncompressed size 4 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info; + +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, + const char* fileName2, + int iCaseSensitivity)); +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + + +extern unzFile ZEXPORT unzOpen OF((const char *path)); +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer + "zlib/zlib111.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ + +extern int ZEXPORT unzClose OF((unzFile file)); +/* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, + unz_global_info *pglobal_info)); +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, + char *szComment, + uLong uSizeBuf)); +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int ZEXPORT unzLocateFile OF((unzFile file, + const char *szFileName, + int iCaseSensitivity)); +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern z_off_t ZEXPORT unztell OF((unzFile file)); +/* + Give the current position in uncompressed data +*/ + +extern int ZEXPORT unzeof OF((unzFile file)); +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _unz_H */ diff --git a/source/unused/win/Makefile b/source/unused/win/Makefile index f35e16f..d9c2b75 100644 --- a/source/unused/win/Makefile +++ b/source/unused/win/Makefile @@ -31,7 +31,6 @@ OBJECTS += obj/genesis.o \ obj/mem68k.o \ obj/memz80.o \ obj/membnk.o \ - obj/memvdp.o \ obj/state.o OBJECTS += obj/sound.o \ diff --git a/source/unused/win/config.c b/source/unused/win/config.c index afc5bf7..b560b8c 100644 --- a/source/unused/win/config.c +++ b/source/unused/win/config.c @@ -11,8 +11,8 @@ void set_config_defaults(void) config.fm_preamp = 1.0; config.boost = 1; config.filter = 1; - config.hq_fm = 2; - config.fm_core = 0; + config.hq_fm = 1; + config.fm_core = 1; /* system options */ config.region_detect = 0; diff --git a/source/unused/win/error.c b/source/unused/win/error.c index 1819a23..9bedc1a 100644 --- a/source/unused/win/error.c +++ b/source/unused/win/error.c @@ -8,14 +8,14 @@ FILE *error_log; struct { - int enabled; - int verbose; - FILE *log; + int enabled; + int verbose; + FILE *log; } t_error; void error_init(void) { -#ifdef LOG_ERROR +#ifdef LOGERROR error_log = fopen("error.log","w"); #endif } @@ -27,8 +27,8 @@ void error_shutdown(void) void error(char *format, ...) { - if (!log_error) return; - va_list ap; + if (!log_error) return; + va_list ap; va_start(ap, format); if(error_log) vfprintf(error_log, format, ap); va_end(ap); diff --git a/source/unused/win/main.c b/source/unused/win/main.c index 736e257..62219ad 100644 --- a/source/unused/win/main.c +++ b/source/unused/win/main.c @@ -24,9 +24,9 @@ int playbuffer = 0; uint8 log_error = 0; uint8 debug_on = 0; -uint8 turbo_mode = 0; -uint8 use_sound = 1; -uint8 fullscreen = 0; +uint8 turbo_mode = 1; +uint8 use_sound = 0; +uint8 fullscreen = 0; int audio_len; @@ -53,8 +53,8 @@ static int sdl_sound_init() if(SDL_Init(SDL_INIT_AUDIO) < 0) { char caption[256]; - sprintf(caption, "SDL audio can't initialize"); - MessageBox(NULL, caption, "Error", 0); + sprintf(caption, "SDL audio can't initialize"); + MessageBox(NULL, caption, "Error", 0); return 0; } @@ -67,12 +67,12 @@ static int sdl_sound_init() if(SDL_OpenAudio(&audio, NULL) == -1) { char caption[256]; - sprintf(caption, "SDL can't open audio"); - MessageBox(NULL, caption, "Error", 0); + sprintf(caption, "SDL can't open audio"); + MessageBox(NULL, caption, "Error", 0); return 0; } - memset(soundbuffer, 0, 16 * 3840); + memset(soundbuffer, 0, 16 * 3840); mixbuffer = 0; playbuffer = 0; return 1; @@ -86,32 +86,32 @@ static long output_pitch; Uint32 fps_callback(Uint32 interval) { - if(paused) return 1000/vdp_rate; - timer_count++; + if(paused) return 1000/vdp_rate; + timer_count++; frameticker ++; - if(timer_count % vdp_rate == 0) - { - int fps = frame_count + 1; - char caption[100]; + if(timer_count % vdp_rate == 0) + { + int fps = frame_count + 1; + char caption[100]; char region[10]; if (region_code == REGION_USA) sprintf(region,"USA"); else if (region_code == REGION_EUROPE) sprintf(region,"EUR"); else sprintf(region,"JAP"); sprintf(caption, "Genesis Plus/SDL - %s (%s) - %d fps", rominfo.international, region, fps); - SDL_WM_SetCaption(caption, NULL); - frame_count = 0; + SDL_WM_SetCaption(caption, NULL); + frame_count = 0; - } - return 1000/vdp_rate; + } + return 1000/vdp_rate; } void lock_pixels( void ) { - if ( SDL_LockSurface( surface ) < 0 ) - MessageBox(NULL, "Couldn't lock surface", "Error", 0); - SDL_FillRect( surface, 0, 0 ); - output_pitch = surface->pitch; - output_pixels = (unsigned char*) surface->pixels; + if ( SDL_LockSurface( surface ) < 0 ) + MessageBox(NULL, "Couldn't lock surface", "Error", 0); + SDL_FillRect( surface, 0, 0 ); + output_pitch = surface->pitch; + output_pixels = (unsigned char*) surface->pixels; } void display_output( void ) @@ -121,9 +121,9 @@ void display_output( void ) dest.h=rect.h; dest.x=(640-rect.w)/2; dest.y=(480-rect.h)/2; - //SDL_UnlockSurface( surface ); - if ( SDL_BlitSurface( surface, &rect, screen, &dest ) < 0 || SDL_Flip( screen ) < 0 ) - MessageBox(NULL, "SDL blit failed", "Error", 0); + //SDL_UnlockSurface( surface ); + if ( SDL_BlitSurface( surface, &rect, screen, &dest ) < 0 || SDL_Flip( screen ) < 0 ) + MessageBox(NULL, "SDL blit failed", "Error", 0); } md_ntsc_t md_ntsc; @@ -131,7 +131,7 @@ sms_ntsc_t sms_ntsc; int main (int argc, char **argv) { - int running = 1; + int running = 1; int sym; md_ntsc_setup_t md_setup; sms_ntsc_setup_t sms_setup; @@ -141,42 +141,42 @@ int main (int argc, char **argv) error_init(); /* Print help if no game specified */ - if(argc < 2) - { - char caption[256]; + if(argc < 2) + { + char caption[256]; sprintf(caption, "Genesis Plus\\SDL by Charles MacDonald\nWWW: http://cgfm2.emuviews.com\nusage: %s gamename\n", argv[0]); MessageBox(NULL, caption, "Information", 0); - exit(1); - } + exit(1); + } - /* Load game */ + /* Load game */ cart_rom = malloc(0xA00000); - memset(cart_rom, 0, 0xA00000); + memset(cart_rom, 0, 0xA00000); if(!load_rom(argv[1])) - { - char caption[256]; - sprintf(caption, "Error loading file `%s'.", argv[1]); - MessageBox(NULL, caption, "Error", 0); - exit(1); - } + { + char caption[256]; + sprintf(caption, "Error loading file `%s'.", argv[1]); + MessageBox(NULL, caption, "Error", 0); + exit(1); + } /* initialize SDL */ if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { - char caption[256]; - sprintf(caption, "SDL initialization failed"); - MessageBox(NULL, caption, "Error", 0); + char caption[256]; + sprintf(caption, "SDL initialization failed"); + MessageBox(NULL, caption, "Error", 0); exit(1); } SDL_WM_SetCaption("Genesis Plus/SDL", NULL); SDL_ShowCursor(0); - screen = SDL_SetVideoMode(640, 480, 16, fullscreen ? (SDL_SWSURFACE|SDL_FULLSCREEN): (SDL_SWSURFACE)); - surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 720, 576, 16, 0, 0, 0, 0); + screen = SDL_SetVideoMode(640, 480, 16, fullscreen ? (SDL_HWSURFACE|SDL_FULLSCREEN): (SDL_HWSURFACE)); + surface = SDL_CreateRGBSurface(SDL_HWSURFACE, 720, 576, 16, 0, 0, 0, 0); if (!screen || !surface) { - MessageBox(NULL, "Video initialization failed", "Error", 0); - exit(1); + MessageBox(NULL, "Video initialization failed", "Error", 0); + exit(1); } /* initialize Genesis display */ @@ -197,24 +197,24 @@ int main (int argc, char **argv) input.system[0] = SYSTEM_GAMEPAD; input.system[1] = SYSTEM_GAMEPAD; - /* load BIOS */ + /* load BIOS */ memset(bios_rom, 0, sizeof(bios_rom)); - FILE *f = fopen("./BIOS.bin", "rb"); - if (f!=NULL) - { - fread(&bios_rom, 0x800,1,f); - fclose(f); - int i; - for(i = 0; i < 0x800; i += 2) - { - uint8 temp = bios_rom[i]; - bios_rom[i] = bios_rom[i+1]; - bios_rom[i+1] = temp; - } - config.bios_enabled |= 2; + FILE *f = fopen("./BIOS.bin", "rb"); + if (f!=NULL) + { + fread(&bios_rom, 0x800,1,f); + fclose(f); + int i; + for(i = 0; i < 0x800; i += 2) + { + uint8 temp = bios_rom[i]; + bios_rom[i] = bios_rom[i+1]; + bios_rom[i+1] = temp; + } + config.bios_enabled |= 2; } - /* initialize emulation */ + /* initialize emulation */ system_init(); audio_init(SOUND_FREQUENCY); @@ -226,7 +226,7 @@ int main (int argc, char **argv) if (f!=NULL) { fread(sram.sram,0x10000,1, f); - fclose(f); + fclose(f); } /* reset emulation */ @@ -236,23 +236,23 @@ int main (int argc, char **argv) SDL_SetTimer(1000/vdp_rate, fps_callback); if (use_sound) SDL_PauseAudio(0); - while(running) - { - while (SDL_PollEvent(&event)) - { - switch(event.type) - { - case SDL_QUIT: /* Windows was closed */ - running = 0; - break; + while(running) + { + while (SDL_PollEvent(&event)) + { + switch(event.type) + { + case SDL_QUIT: /* Windows was closed */ + running = 0; + break; - case SDL_ACTIVEEVENT: /* Window focus changed or was minimized */ - if(event.active.state & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) - { - paused = !event.active.gain; + case SDL_ACTIVEEVENT: /* Window focus changed or was minimized */ + if(event.active.state & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) + { + paused = !event.active.gain; if (use_sound) SDL_PauseAudio(paused); - } - break; + } + break; case SDL_KEYDOWN: /* user options */ sym = event.key.keysym.sym; @@ -261,7 +261,7 @@ int main (int argc, char **argv) else if (sym == SDLK_RETURN) { fullscreen ^=1; - screen = SDL_SetVideoMode(640, 480, 16, fullscreen ? (SDL_SWSURFACE|SDL_FULLSCREEN): (SDL_SWSURFACE)); + screen = SDL_SetVideoMode(640, 480, 16, fullscreen ? (SDL_HWSURFACE|SDL_FULLSCREEN): (SDL_HWSURFACE)); } else if(sym == SDLK_F3) config.render ^=1; @@ -337,10 +337,11 @@ int main (int argc, char **argv) } break; - default: - break; - } - } + default: + break; + } + } + if(!paused) { @@ -359,14 +360,15 @@ int main (int argc, char **argv) system_frame (0); frame_count++; } + update_input(); frameticker--; if(bitmap.viewport.changed) { - bitmap.viewport.changed = 0; + bitmap.viewport.changed = 0; rect.w = bitmap.viewport.w+2*bitmap.viewport.x; - rect.h = bitmap.viewport.h+2*bitmap.viewport.y; + rect.h = bitmap.viewport.h+2*bitmap.viewport.y; if (config.render && (interlaced || config.ntsc)) rect.h *= 2; if (config.ntsc) rect.w = (reg[12]&1) ? MD_NTSC_OUT_WIDTH(rect.w) : SMS_NTSC_OUT_WIDTH(rect.w); @@ -403,7 +405,7 @@ int main (int argc, char **argv) if (f!=NULL) { fwrite(&sram.sram,0x10000,1, f); - fclose(f); + fclose(f); } SDL_PauseAudio(1); @@ -424,8 +426,8 @@ int update_input(void) while (input.dev[joynum] == NO_DEVICE) { - joynum ++; - if (joynum > MAX_DEVICES - 1) joynum = 0; + joynum ++; + if (joynum > MAX_DEVICES - 1) joynum = 0; } /* reset input */ @@ -448,7 +450,6 @@ int update_input(void) if(keystate[SDLK_c]) input.pad[joynum] |= INPUT_Z; if(keystate[SDLK_v]) input.pad[joynum] |= INPUT_MODE; - extern uint8 pico_current; if (input.dev[joynum] == DEVICE_LIGHTGUN) { /* get mouse (absolute values) */ diff --git a/source/unused/win/unzip.c b/source/unused/win/unzip.c new file mode 100644 index 0000000..90e8618 --- /dev/null +++ b/source/unused/win/unzip.c @@ -0,0 +1,1294 @@ +/* unzip.c -- IO on .zip files using zlib + Version 0.15 beta, Mar 19th, 1998, + + Read unzip.h for more info +*/ + + +#include +#include +#include +#include "zlib.h" +#include "unzip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else + #include +#endif + + +#ifndef local + #define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + + + +#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \ + !defined(CASESENSITIVITYDEFAULT_NO) +#define CASESENSITIVITYDEFAULT_NO +#endif + + +#ifndef UNZ_BUFSIZE +#define UNZ_BUFSIZE (16384) +#endif + +#ifndef UNZ_MAXFILENAMEINZIP +#define UNZ_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +const char unz_copyright[] = + " unzip 0.15 Copyright 1998 Gilles Vollant "; + +/* unz_file_info_interntal contain internal info about a file in zipfile*/ +typedef struct unz_file_info_internal_s +{ + uLong offset_curfile;/* relative offset of local header 4 bytes */ +} unz_file_info_internal; + + +/* file_in_zip_read_info_s contain internal information about a file in zipfile, + when reading and decompress it */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + + uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ + uLong stream_initialised; /* flag set if stream structure is initialised*/ + + uLong offset_local_extrafield;/* offset of the local extra field */ + uInt size_local_extrafield;/* size of the local extra field */ + uLong pos_local_extrafield; /* position in the local extra field in read*/ + + uLong crc32; /* crc32 of all data uncompressed */ + uLong crc32_wait; /* crc32 we must obtain after decompress all */ + uLong rest_read_compressed; /* number of byte to be decompressed */ + uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ + FILE* file; /* io structore of the zipfile */ + uLong compression_method; /* compression method (0==store) */ + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ +} file_in_zip_read_info_s; + + +/* unz_s contain internal information about the zipfile +*/ +typedef struct +{ + FILE* file; /* io structore of the zipfile */ + unz_global_info gi; /* public global information */ + uLong byte_before_the_zipfile; /* byte before the zipfile, (>0 for sfx)*/ + uLong num_file; /* number of the current file in the zipfile*/ + uLong pos_in_central_dir; /* pos of the current file in the central dir*/ + uLong current_file_ok; /* flag about the usability of the current file*/ + uLong central_pos; /* position of the beginning of the central dir*/ + + uLong size_central_dir; /* size of the central directory */ + uLong offset_central_dir; /* offset of start of central directory with + respect to the starting disk number */ + + unz_file_info cur_file_info; /* public info about the current file in zip*/ + unz_file_info_internal cur_file_info_internal; /* private info about it*/ + file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current + file if we are decompressing it */ +} unz_s; + + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been sucessfully opened for reading. +*/ + + +local int unzlocal_getByte(fin,pi) + FILE *fin; + int *pi; +{ + unsigned char c; + int err = fread(&c, 1, 1, fin); + if (err==1) + { + *pi = (int)c; + return UNZ_OK; + } + else + { + if (ferror(fin)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int unzlocal_getShort (fin,pX) + FILE* fin; + uLong *pX; +{ + uLong x ; + int i = 0; + int err; + + err = unzlocal_getByte(fin,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<8; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unzlocal_getLong (fin,pX) + FILE* fin; + uLong *pX; +{ + uLong x ; + int i = 0; + int err; + + err = unzlocal_getByte(fin,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<8; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<16; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<24; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + + +/* My own strcmpi / strcasecmp */ +local int strcmpcasenosensitive_internal (fileName1,fileName2) + const char* fileName1; + const char* fileName2; +{ + for (;;) + { + char c1=*(fileName1++); + char c2=*(fileName2++); + if ((c1>='a') && (c1<='z')) + c1 -= 0x20; + if ((c2>='a') && (c2<='z')) + c2 -= 0x20; + if (c1=='\0') + return ((c2=='\0') ? 0 : -1); + if (c2=='\0') + return 1; + if (c1c2) + return 1; + } +} + + +#ifdef CASESENSITIVITYDEFAULT_NO +#define CASESENSITIVITYDEFAULTVALUE 2 +#else +#define CASESENSITIVITYDEFAULTVALUE 1 +#endif + +#ifndef STRCMPCASENOSENTIVEFUNCTION +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal +#endif + +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) + +*/ +extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) + const char* fileName1; + const char* fileName2; + int iCaseSensitivity; +{ + if (iCaseSensitivity==0) + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; + + if (iCaseSensitivity==1) + return strcmp(fileName1,fileName2); + + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); +} + +#define BUFREADCOMMENT (0x400) + +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local uLong unzlocal_SearchCentralDir(fin) + FILE *fin; +{ + unsigned char* buf; + uLong uSizeFile; + uLong uBackRead; + uLong uMaxBack=0xffff; /* maximum size of global comment */ + uLong uPosFound=0; + + if (fseek(fin,0,SEEK_END) != 0) + return 0; + + + uSizeFile = ftell( fin ); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); + if (fseek(fin,uReadPos,SEEK_SET)!=0) + break; + + if (fread(buf,(uInt)uReadSize,1,fin)!=1) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer + "zlib/zlib109.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ +extern unzFile ZEXPORT unzOpen (path) + const char *path; +{ + unz_s us; + unz_s *s; + uLong central_pos,uL; + FILE * fin ; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + uLong number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + + int err=UNZ_OK; + + if (unz_copyright[0]!=' ') + return NULL; + + fin=fopen(path,"rb"); + if (fin==NULL) + return NULL; + + central_pos = unzlocal_SearchCentralDir(fin); + if (central_pos==0) + err=UNZ_ERRNO; + + if (fseek(fin,central_pos,SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unzlocal_getLong(fin,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir on this disk */ + if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir */ + if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* zipfile comment length */ + if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((central_pospfile_in_zip_read!=NULL) + unzCloseCurrentFile(file); + + fclose(s->file); + TRYFREE(s); + return UNZ_OK; +} + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ +extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) + unzFile file; + unz_global_info *pglobal_info; +{ + unz_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + *pglobal_info=s->gi; + return UNZ_OK; +} + + +/* + Translate date/time from Dos format to tm_unz (readable more easilty) +*/ +local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) + uLong ulDosDate; + tm_unz* ptm; +{ + uLong uDate; + uDate = (uLong)(ulDosDate>>16); + ptm->tm_mday = (uInt)(uDate&0x1f) ; + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; + + ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; +} + +/* + Get Info about the current file in the zipfile, with internal only info +*/ +local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, + unz_file_info *pfile_info, + unz_file_info_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +local int unzlocal_GetCurrentFileInfoInternal (file, + pfile_info, + pfile_info_internal, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + unz_file_info_internal *pfile_info_internal; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + unz_s* s; + unz_file_info file_info; + unz_file_info_internal file_info_internal; + int err=UNZ_OK; + uLong uMagic; + long lSeek=0; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0) + err=UNZ_ERRNO; + + + /* we check the magic */ + if (err==UNZ_OK) + { + if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x02014b50) + err=UNZ_BADZIPFILE; + } + + if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK) + err=UNZ_ERRNO; + + unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); + + if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + + lSeek+=file_info.size_filename; + if ((err==UNZ_OK) && (szFileName!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_filename0) && (fileNameBufferSize>0)) + if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek -= uSizeRead; + } + + if ((err==UNZ_OK) && (extraField!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_extrafile,lSeek,SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) + if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek += file_info.size_file_extra - uSizeRead; + } + else + lSeek+=file_info.size_file_extra; + + if ((err==UNZ_OK) && (szComment!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_commentfile,lSeek,SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_comment>0) && (commentBufferSize>0)) + if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek+=file_info.size_file_comment - uSizeRead; + } + else + lSeek+=file_info.size_file_comment; + + if ((err==UNZ_OK) && (pfile_info!=NULL)) + *pfile_info=file_info; + + if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) + *pfile_info_internal=file_info_internal; + + return err; +} + + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. +*/ +extern int ZEXPORT unzGetCurrentFileInfo (file, + pfile_info, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); +} + +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ +extern int ZEXPORT unzGoToFirstFile (file) + unzFile file; +{ + int err=UNZ_OK; + unz_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + s->pos_in_central_dir=s->offset_central_dir; + s->num_file=0; + err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ +extern int ZEXPORT unzGoToNextFile (file) + unzFile file; +{ + unz_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + if (s->num_file+1==s->gi.number_entry) + return UNZ_END_OF_LIST_OF_FILE; + + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; + s->num_file++; + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzipStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ +extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) + unzFile file; + const char *szFileName; + int iCaseSensitivity; +{ + unz_s* s; + int err; + + uLong num_fileSaved; + uLong pos_in_central_dirSaved; + + if (file==NULL) + return UNZ_PARAMERROR; + + if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) + return UNZ_PARAMERROR; + + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + num_fileSaved = s->num_file; + pos_in_central_dirSaved = s->pos_in_central_dir; + + err = unzGoToFirstFile(file); + + while (err == UNZ_OK) + { + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; + unzGetCurrentFileInfo(file,NULL, + szCurrentFileName,sizeof(szCurrentFileName)-1, + NULL,0,NULL,0); + if (unzStringFileNameCompare(szCurrentFileName, + szFileName,iCaseSensitivity)==0) + return UNZ_OK; + err = unzGoToNextFile(file); + } + + s->num_file = num_fileSaved ; + s->pos_in_central_dir = pos_in_central_dirSaved ; + return err; +} + + +/* + Read the local header of the current zipfile + Check the coherency of the local header and info in the end of central + directory about this file + store in *piSizeVar the size of extra info in local header + (filename and size of extra field data) +*/ +local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, + poffset_local_extrafield, + psize_local_extrafield) + unz_s* s; + uInt* piSizeVar; + uLong *poffset_local_extrafield; + uInt *psize_local_extrafield; +{ + uLong uMagic,uData,uFlags; + uLong size_filename; + uLong size_extra_field; + int err=UNZ_OK; + + *piSizeVar = 0; + *poffset_local_extrafield = 0; + *psize_local_extrafield = 0; + + if (fseek(s->file,s->cur_file_info_internal.offset_curfile + + s->byte_before_the_zipfile,SEEK_SET)!=0) + return UNZ_ERRNO; + + + if (err==UNZ_OK) + { + if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x04034b50) + err=UNZ_BADZIPFILE; + } + + if (unzlocal_getShort(s->file,&uData) != UNZ_OK) + err=UNZ_ERRNO; +/* + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) + err=UNZ_BADZIPFILE; +*/ + if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&uData) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) + err=UNZ_BADZIPFILE; + + if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */ + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + + if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) + err=UNZ_BADZIPFILE; + + *piSizeVar += (uInt)size_filename; + + if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK) + err=UNZ_ERRNO; + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + + SIZEZIPLOCALHEADER + size_filename; + *psize_local_extrafield = (uInt)size_extra_field; + + *piSizeVar += (uInt)size_extra_field; + + return err; +} + +/* + Open for reading data the current file in the zipfile. + If there is no error and the file is opened, the return value is UNZ_OK. +*/ +extern int ZEXPORT unzOpenCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + int Store; + uInt iSizeVar; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uLong offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_PARAMERROR; + + if (s->pfile_in_zip_read != NULL) + unzCloseCurrentFile(file); + + if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, + &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) + return UNZ_BADZIPFILE; + + pfile_in_zip_read_info = (file_in_zip_read_info_s*) + ALLOC(sizeof(file_in_zip_read_info_s)); + if (pfile_in_zip_read_info==NULL) + return UNZ_INTERNALERROR; + + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; + pfile_in_zip_read_info->pos_local_extrafield=0; + + if (pfile_in_zip_read_info->read_buffer==NULL) + { + TRYFREE(pfile_in_zip_read_info); + return UNZ_INTERNALERROR; + } + + pfile_in_zip_read_info->stream_initialised=0; + + if ((s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + Store = s->cur_file_info.compression_method==0; + + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; + pfile_in_zip_read_info->crc32=0; + pfile_in_zip_read_info->compression_method = + s->cur_file_info.compression_method; + pfile_in_zip_read_info->file=s->file; + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; + + pfile_in_zip_read_info->stream.total_out = 0; + + if (!Store) + { + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; + pfile_in_zip_read_info->stream.zfree = (free_func)0; + pfile_in_zip_read_info->stream.opaque = (voidpf)0; + + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised=1; + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + * In unzip, i don't wait absolutely Z_STREAM_END because I known the + * size of both compressed and uncompressed data + */ + } + pfile_in_zip_read_info->rest_read_compressed = + s->cur_file_info.compressed_size ; + pfile_in_zip_read_info->rest_read_uncompressed = + s->cur_file_info.uncompressed_size ; + + pfile_in_zip_read_info->pos_in_zipfile = + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + + iSizeVar; + + pfile_in_zip_read_info->stream.avail_in = (uInt)0; + + + s->pfile_in_zip_read = pfile_in_zip_read_info; + return UNZ_OK; +} + + +/* + Read bytes from the current file. + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ +extern int ZEXPORT unzReadCurrentFile (file, buf, len) + unzFile file; + voidp buf; + unsigned len; +{ + int err=UNZ_OK; + uInt iRead = 0; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if ((pfile_in_zip_read_info->read_buffer == NULL)) + return UNZ_END_OF_LIST_OF_FILE; + if (len==0) + return 0; + + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; + + pfile_in_zip_read_info->stream.avail_out = (uInt)len; + + if (len>pfile_in_zip_read_info->rest_read_uncompressed) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; + + while (pfile_in_zip_read_info->stream.avail_out>0) + { + if ((pfile_in_zip_read_info->stream.avail_in==0) && + (pfile_in_zip_read_info->rest_read_compressed>0)) + { + uInt uReadThis = UNZ_BUFSIZE; + if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; + if (uReadThis == 0) + return UNZ_EOF; + if (fseek(pfile_in_zip_read_info->file, + pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) + return UNZ_ERRNO; + if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1, + pfile_in_zip_read_info->file)!=1) + return UNZ_ERRNO; + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; + + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; + + pfile_in_zip_read_info->stream.next_in = + (Bytef*)pfile_in_zip_read_info->read_buffer; + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; + } + + if (pfile_in_zip_read_info->compression_method==0) + { + uInt uDoCopy,i ; + if (pfile_in_zip_read_info->stream.avail_out < + pfile_in_zip_read_info->stream.avail_in) + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; + else + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; + + for (i=0;istream.next_out+i) = + *(pfile_in_zip_read_info->stream.next_in+i); + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, + pfile_in_zip_read_info->stream.next_out, + uDoCopy); + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; + pfile_in_zip_read_info->stream.next_out += uDoCopy; + pfile_in_zip_read_info->stream.next_in += uDoCopy; + pfile_in_zip_read_info->stream.total_out += uDoCopy; + iRead += uDoCopy; + } + else + { + uLong uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + uLong uOutThis; + int flush=Z_SYNC_FLUSH; + + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; + bufBefore = pfile_in_zip_read_info->stream.next_out; + + /* + if ((pfile_in_zip_read_info->rest_read_uncompressed == + pfile_in_zip_read_info->stream.avail_out) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + flush = Z_FINISH; + */ + err=inflate(&pfile_in_zip_read_info->stream,flush); + + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->crc32 = + crc32(pfile_in_zip_read_info->crc32,bufBefore, + (uInt)(uOutThis)); + + pfile_in_zip_read_info->rest_read_uncompressed -= + uOutThis; + + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + if (err==Z_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=Z_OK) + break; + } + } + + if (err==Z_OK) + return iRead; + return err; +} + + +/* + Give the current position in uncompressed data +*/ +extern z_off_t ZEXPORT unztell (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + return (z_off_t)pfile_in_zip_read_info->stream.total_out; +} + + +/* + return 1 if the end of file was reached, 0 elsewhere +*/ +extern int ZEXPORT unzeof (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + return 1; + else + return 0; +} + +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field that can be read + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ +extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) + unzFile file; + voidp buf; + unsigned len; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uInt read_now; + uLong size_to_read; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - + pfile_in_zip_read_info->pos_local_extrafield); + + if (buf==NULL) + return (int)size_to_read; + + if (len>size_to_read) + read_now = (uInt)size_to_read; + else + read_now = (uInt)len ; + + if (read_now==0) + return 0; + + if (fseek(pfile_in_zip_read_info->file, + pfile_in_zip_read_info->offset_local_extrafield + + pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0) + return UNZ_ERRNO; + + if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1) + return UNZ_ERRNO; + + return (int)read_now; +} + +/* + Close the file in zip opened with unzipOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ +extern int ZEXPORT unzCloseCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + { + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) + err=UNZ_CRCERROR; + } + + + TRYFREE(pfile_in_zip_read_info->read_buffer); + pfile_in_zip_read_info->read_buffer = NULL; + if (pfile_in_zip_read_info->stream_initialised) + inflateEnd(&pfile_in_zip_read_info->stream); + + pfile_in_zip_read_info->stream_initialised = 0; + TRYFREE(pfile_in_zip_read_info); + + s->pfile_in_zip_read=NULL; + + return err; +} + + +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ +extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) + unzFile file; + char *szComment; + uLong uSizeBuf; +{ +/* int err=UNZ_OK; */ + unz_s* s; + uLong uReadThis ; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + + uReadThis = uSizeBuf; + if (uReadThis>s->gi.size_comment) + uReadThis = s->gi.size_comment; + + if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0) + return UNZ_ERRNO; + + if (uReadThis>0) + { + *szComment='\0'; + if (fread(szComment,(uInt)uReadThis,1,s->file)!=1) + return UNZ_ERRNO; + } + + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) + *(szComment+s->gi.size_comment)='\0'; + return (int)uReadThis; +} diff --git a/source/unused/win/unzip.h b/source/unused/win/unzip.h new file mode 100644 index 0000000..a30f79c --- /dev/null +++ b/source/unused/win/unzip.h @@ -0,0 +1,273 @@ +/* unzip.h -- IO for uncompress .zip files using zlib + Version 0.15 beta, Mar 19th, 1998, + + Copyright (C) 1998 Gilles Vollant + + This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g + WinZip, InfoZip tools and compatible. + Encryption and multi volume ZipFile (span) are not supported. + Old compressions used by old PKZip 1.x are not supported + + THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE + CAN CHANGE IN FUTURE VERSION !! + I WAIT FEEDBACK at mail info@winimage.com + Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* for more info about .ZIP format, see + ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip + PkWare has also a specification at : + ftp://ftp.pkware.com/probdesc.zip */ + +#ifndef _unz_H +#define _unz_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef voidp unzFile; +#endif + + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + +/* tm_unz contain date/time info */ +typedef struct tm_unz_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_unz; + +/* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ +typedef struct unz_global_info_s +{ + uLong number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info; + + +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_info_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + uLong compressed_size; /* compressed size 4 bytes */ + uLong uncompressed_size; /* uncompressed size 4 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info; + +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, + const char* fileName2, + int iCaseSensitivity)); +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + + +extern unzFile ZEXPORT unzOpen OF((const char *path)); +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer + "zlib/zlib111.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ + +extern int ZEXPORT unzClose OF((unzFile file)); +/* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, + unz_global_info *pglobal_info)); +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, + char *szComment, + uLong uSizeBuf)); +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int ZEXPORT unzLocateFile OF((unzFile file, + const char *szFileName, + int iCaseSensitivity)); +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern z_off_t ZEXPORT unztell OF((unzFile file)); +/* + Give the current position in uncompressed data +*/ + +extern int ZEXPORT unzeof OF((unzFile file)); +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _unz_H */