diff options
author | Pixel <Pixel> | 2002-06-23 11:19:06 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2002-06-23 11:19:06 +0000 |
commit | 54c77d2cb0f734615febdb3cb33548bf4cd6e953 (patch) | |
tree | c6105e4984b0c29f2db05352234e5fbed6a1d092 /str-util.cpp | |
parent | cdbb43ea328883261c6f71e6e44b16ae39173fa6 (diff) |
Pfiou, huge work...
Diffstat (limited to 'str-util.cpp')
-rw-r--r-- | str-util.cpp | 96 |
1 files changed, 90 insertions, 6 deletions
diff --git a/str-util.cpp b/str-util.cpp index 3588707..67f20b1 100644 --- a/str-util.cpp +++ b/str-util.cpp @@ -1,6 +1,8 @@ #include <stdlib.h> #include <string.h> -//#include "psxdev/bs.h" +#include <SDL/SDL.h> +#include <SDL/SDL_audio.h> +#include "psxdev/bs.h" #include "fileutils.h" #include "generic.h" #include "cdutils.h" @@ -41,19 +43,26 @@ struct STR_Header { Byte * video = 0, * audio = 0; +int width, height; + +SDL_Surface * screen = 0; +Uint8 bpp; + +extern void mixaudio(void *unused, Uint8 *stream, int len); + void process_one_sector(FILE * f) { Byte sector[2336]; STR_Header * h; fread(sector, 2336, 1, f); h = (STR_Header *) ((Byte *) sector + 8); - + printm(M_BARE, "SubHeader FN : %x\n", sector[0]); printm(M_BARE, "SubHeader CN : %x\n", sector[1]); printm(M_BARE, "SubHeader SM : %x\n", sector[2]); printm(M_BARE, "SubHeader CI : %x\n", sector[3]); - - if (sector[2] == 0x48) { + + if ((sector[2] == 0x48) || (sector[2] == 0x42)) { printm(M_BARE, "Video sector\n"); printm(M_BARE, "Status : %04x\n", h->StSTATUS); printm(M_BARE, "Type : %04x\n", h->StTYPE); @@ -68,6 +77,17 @@ void process_one_sector(FILE * f) { printm(M_BARE, "Channels : %04x\n", h->Channels); if (h->StSECTOR_OFFSET == 0) { video = (Byte *) malloc(h->StSECTOR_SIZE * 2016); + if (!screen) { + bs_init(); + width = h->StMOVIE_WIDTH; + height = h->StMOVIE_HEIGHT; + screen = SDL_SetVideoMode(width, height, 24, SDL_HWSURFACE | SDL_DOUBLEBUF); + if (!screen) { + printm(M_ERROR, "Couldn't get framebuffer\n"); + exit(-1); + } + bpp = screen->format->BytesPerPixel; + } } memcpy(video + h->StSECTOR_OFFSET * 2016, sector + 40, 2016); @@ -76,19 +96,83 @@ void process_one_sector(FILE * f) { // Frame finished. printm(M_BARE, "End of Frame.\n"); + Uint8 * buffer = ((Uint8 *) screen->pixels); + + if (SDL_MUSTLOCK(screen)) + if (SDL_LockSurface(screen) < 0) + exit(1); + printm(M_BARE, "Width: %i, Height: %i - bpp: %i\n", width, height, bpp); + bs_decode_rgb24(buffer, (bs_header_t *) video, width, height, 0); + +// fwrite(screen->pixels, 3, width * height, stdout); + + if (SDL_MUSTLOCK(screen)) + SDL_UnlockSurface(screen); + SDL_Flip(screen); + free(video); } - } else if (sector[2] == 0x64) { + SoundSector * buffer = (SoundSector *) sector); printm(M_BARE, "Audio sector\n"); + printm(M_BARE, "Frequency: %i\n", xahalfhz(buffer) ? 18900 : 37800); + printm(M_BARE, "Channels : %s\n", xastereo(buffer) ? "stereo" : "mono"); +// fwrite(sector + 8, 1, 2324, stdout); + if (!audio) { + SDL_AudioSpec fmt; + + /* Un son sereo de 16 bits à 44kHz */ + fmt.freq = xahalfhz(&buffer)?"18900":"37800"; + fmt.format = AUDIO_S16; + fmt.channels = 2; + fmt.samples = 512; /*Une bonne valeur pour les jeux */ + fmt.callback = mixaudio; + fmt.userdata = NULL; + + /* Ouvre le contexte audio et joue le son */ + if ( SDL_OpenAudio(&fmt, NULL) < 0 ) { + fprintf(stderr, "Impossible d'acce'der a` l'audio: %s\n", SDL_GetError()); + exit(1); + } + SDL_PauseAudio(0); + + } else { + free(audio); + } + audio = (Byte *) malloc(2336); } else { printm(M_BARE, "Unknow sector\n"); } printm(M_BARE, "---------------------------------\n\n"); } -int main(void) { +int main(int argc, char ** argv) { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) { + printm(M_ERROR, "Couldn't initialise SDL: %s\n", SDL_GetError()); + exit(-1); + } + atexit(SDL_Quit); + SDL_ShowCursor(SDL_DISABLE); + + + switch (argc) { + case 1: + break; + case 2: + fclose(stdin); + stdin = fopen(argv[1], "r"); + break; + default: + printm(M_ERROR, "Too much arguments.\n"); + exit(-1); + } + while (!feof(stdin)) { process_one_sector(stdin); } + + if (!audio) + SDL_CloseAudio(); + + SDL_Quit(); } |