#include #include #include #include #include "psxdev/bs.h" #include "fileutils.h" #include "generic.h" #include "cdutils.h" /* From the SONY documentation: 32 bytes header: StSTATUS : 2 bytes 0 StTYPE : 2 bytes 2 StSECTOR_OFFSET: 2 bytes 4 StSECTOR_SIZE : 2 bytes 6 StFRAME_NO : 4 bytes 10 StFRAME_SIZE : 4 bytes 14 StMOVIE_WIDTH : 2 bytes 16 StMOVIE_HEIGHT : 2 bytes 18 StMOVIE_HEADM : 4 bytes 22 StMOVIE_HEADV : 4 bytes 26 Channels : 2 bytes 30 */ struct STR_Header { Uint16 StSTATUS; Uint16 StTYPE; Uint16 StSECTOR_OFFSET; Uint16 StSECTOR_SIZE; Uint32 StFRAME_NO; Uint32 StFRAME_SIZE; Uint16 StMOVIE_WIDTH; Uint16 StMOVIE_HEIGHT; Uint32 StMOVIE_HEADM; Uint32 StMOVIE_HEADV; Uint16 Channels; } __attribute__((packed)); 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) || (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); printm(M_BARE, "Sector Offset: %i\n", h->StSECTOR_OFFSET); printm(M_BARE, "Sector Size : %i\n", h->StSECTOR_SIZE); printm(M_BARE, "Frame Number : %i\n", h->StFRAME_NO); printm(M_BARE, "Frame Size : %i\n", h->StFRAME_SIZE); printm(M_BARE, "Movie Width : %i\n", h->StMOVIE_WIDTH); printm(M_BARE, "Movie Height : %i\n", h->StMOVIE_HEIGHT); printm(M_BARE, "Movie HeadM : %08x\n", h->StMOVIE_HEADM); printm(M_BARE, "Movie HeadV : %08x\n", h->StMOVIE_HEADV); 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); if (h->StSECTOR_SIZE == (h->StSECTOR_OFFSET + 1)) { // 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(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(); }