From: Shamus Hammons Date: Thu, 28 Aug 2003 05:11:51 +0000 (+0000) Subject: Removed last of the __PORT__ stuff X-Git-Tag: 1.0.5~9 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c366a13aeb0ebb8c18a28616732e058466191af;p=virtualjaguar Removed last of the __PORT__ stuff --- diff --git a/src/cdi.cpp b/src/cdi.cpp index 61e1c4f..e283562 100644 --- a/src/cdi.cpp +++ b/src/cdi.cpp @@ -35,175 +35,222 @@ uint32 cdi_tracks_count; int cdi_open(char * path) { - fprintf(log_get(), "CDI: Opening %s\n", path); + WriteLog("CDI: Opening %s\n", path); return open(path, O_BINARY | O_RDONLY); } void cdi_close(int fp) { - fprintf(log_get(), "CDI: Closing\n"); + WriteLog("CDI: Closing\n"); close(fp); } -#ifdef __PORT__ -long tell(int fd) + +/*long tell(int fd) { return lseek(fd, 0LL, SEEK_CUR); -} -#endif +}*/ -s_cdi_descriptor *cdi_get_descriptor(int fp, FILE *stdfp) + +s_cdi_descriptor * cdi_get_descriptor(int fp, FILE * stdfp) { - s_cdi_descriptor *descriptor; - - uint32 previous_position=0; + s_cdi_descriptor * descriptor; + uint32 previous_position = 0; - if (fp==-1) - return(0); + if (fp == -1) + return 0; - descriptor=(s_cdi_descriptor *)malloc(sizeof(s_cdi_descriptor)); - if (descriptor==0) - return(0); + descriptor = (s_cdi_descriptor *)malloc(sizeof(s_cdi_descriptor)); - lseek(fp,0,SEEK_END); - descriptor->length=tell(fp); - if (descriptor->length<8) + if (descriptor == NULL) + return 0; + + lseek(fp, 0, SEEK_END); +//Why??? descriptor->length=tell(fp); + descriptor->length = lseek(fp, 0LL, SEEK_CUR); + + if (descriptor->length < 8) { - if (stdfp) fprintf(stdfp,"cdi: image is too short (%i bytes)\n",descriptor->length); + if (stdfp) + fprintf(stdfp, "CDI: Image is too short (%i bytes)\n", (int)descriptor->length); free(descriptor); - return(0); + return 0; } - lseek(fp,descriptor->length-8,SEEK_SET); - read(fp,&descriptor->version,4); - read(fp,&descriptor->header_offset,4); - lseek(fp,descriptor->header_offset,SEEK_SET); - read(fp,&descriptor->nb_of_sessions,2); - - descriptor->sessions=(s_cdi_session *)malloc(descriptor->nb_of_sessions*sizeof(s_cdi_session)); - if (descriptor->sessions==0) + + lseek(fp, descriptor->length - 8, SEEK_SET); + read(fp, &descriptor->version, 4); + read(fp, &descriptor->header_offset, 4); + lseek(fp, descriptor->header_offset, SEEK_SET); + read(fp, &descriptor->nb_of_sessions, 2); + + descriptor->sessions=(s_cdi_session *)malloc(descriptor->nb_of_sessions * sizeof(s_cdi_session)); + + if (descriptor->sessions == NULL) { free(descriptor); - return(0); + return 0; } - if (stdfp) fprintf(stdfp,"cdi: %i sessions\n",descriptor->nb_of_sessions); - uint32 track_position=0; - for (uint16 session=0;sessionnb_of_sessions;session++) + + if (stdfp) + fprintf(stdfp, "CDI: %i sessions\n", descriptor->nb_of_sessions); + + uint32 track_position = 0; + for(uint16 session=0; sessionnb_of_sessions; session++) { - read(fp,&descriptor->sessions[session].nb_of_tracks,2); - descriptor->sessions[session].tracks=(s_cdi_track*)malloc(descriptor->sessions[session].nb_of_tracks*sizeof(s_cdi_track)); + read(fp, &descriptor->sessions[session].nb_of_tracks, 2); + descriptor->sessions[session].tracks = (s_cdi_track *)malloc(descriptor->sessions[session].nb_of_tracks * sizeof(s_cdi_track)); - if (stdfp) fprintf(stdfp,"cdi:\ncdi: reading session %i (%i tracks)\n",session,descriptor->sessions[session].nb_of_tracks); + if (stdfp) + fprintf(stdfp, "CDI:\nCDI: Reading session %i (%i tracks)\n", session, descriptor->sessions[session].nb_of_tracks); - for (uint16 track=0;tracksessions[session].nb_of_tracks;track++) + for (uint16 track=0; tracksessions[session].nb_of_tracks; track++) { static char current_start_mark[10]; - s_cdi_track *current_track=&descriptor->sessions[session].tracks[track]; - if (stdfp) fprintf(stdfp,"cdi:\ncdi: \t\treading track %i\n",track); + s_cdi_track * current_track=&descriptor->sessions[session].tracks[track]; + if (stdfp) + fprintf(stdfp, "CDI:\nCDI: \t\tReading track %i\n",track); uint32 temp_value; - read(fp,&temp_value, 4); + read(fp, &temp_value, 4); + if (temp_value != 0) lseek(fp, 8, SEEK_CUR); // extra data (DJ 3.00.780 and up) - read(fp,current_start_mark, 10); + read(fp, current_start_mark, 10); + if (memcmp(cdi_track_start_mark, current_start_mark, 10)) { - if (stdfp) fprintf(stdfp,"cdi: could not find the track start mark"); - return(0); + if (stdfp) + fprintf(stdfp, "CDI: Could not find the track start mark\n"); + return 0; } - read(fp,current_start_mark, 10); + + read(fp, current_start_mark, 10); + if (memcmp(cdi_track_start_mark, current_start_mark, 10)) { - if (stdfp) fprintf(stdfp,"cdi: could not find the track start mark"); - return(0); + if (stdfp) + fprintf(stdfp, "CDI: Could not find the track start mark\n"); + return 0; } lseek(fp, 4, SEEK_CUR); - read(fp,¤t_track->filename_length, 1); + read(fp, ¤t_track->filename_length, 1); lseek(fp, current_track->filename_length, SEEK_CUR); lseek(fp, 11, SEEK_CUR); lseek(fp, 4, SEEK_CUR); lseek(fp, 4, SEEK_CUR); - read(fp,&temp_value, 4); + read(fp, &temp_value, 4); + if (temp_value == 0x80000000) lseek(fp, 8, SEEK_CUR); // DJ4 + lseek(fp, 2, SEEK_CUR); read(fp, ¤t_track->pregap_length, 4); - if (current_track->pregap_length!=150) - { - fprintf(log_get(),"cdi: warning: pregap different than 150\n"); - } + + if (current_track->pregap_length != 150) + WriteLog("CDI: Warning: Pregap different than 150\n"); + read(fp, ¤t_track->length, 4); - if (stdfp) fprintf(stdfp,"cdi: \t\t\tpregap length : %i\n", current_track->pregap_length); - if (stdfp) fprintf(stdfp,"cdi: \t\t\tlength : %i\n", current_track->length); + + if (stdfp) + fprintf(stdfp, "CDI: \t\t\tPregap length: %i\n", (int)current_track->pregap_length); + if (stdfp) + fprintf(stdfp, "CDI: \t\t\tLength: %i\n", (int)current_track->length); lseek(fp, 6, SEEK_CUR); read(fp, ¤t_track->mode, 4); - if (stdfp) fprintf(stdfp,"cdi: \t\t\tmode : %i\n", current_track->mode); + + if (stdfp) + fprintf(stdfp, "CDI: \t\t\tMode: %i\n", (int)current_track->mode); lseek(fp, 12, SEEK_CUR); read(fp, ¤t_track->start_lba, 4); - if (stdfp) fprintf(stdfp,"cdi: \t\t\tstart lba : %i\n", current_track->start_lba); + + if (stdfp) + fprintf(stdfp, "CDI: \t\t\tStart LBA: %i\n", (int)current_track->start_lba); + read(fp, ¤t_track->total_length, 4); - if (stdfp) fprintf(stdfp,"cdi: \t\t\ttotal length : %i\n", current_track->total_length); + + if (stdfp) + fprintf(stdfp, "CDI: \t\t\tTotal length: %i\n", (int)current_track->total_length); + lseek(fp, 16, SEEK_CUR); read(fp, ¤t_track->sector_size_value, 4); - if (stdfp) fprintf(stdfp,"cdi: \t\t\tsector size : %i\n", current_track->sector_size_value); + + if (stdfp) + fprintf(stdfp, "CDI: \t\t\tSector size: %i\n", (int)current_track->sector_size_value); switch(current_track->sector_size_value) { - case 0 : current_track->sector_size = 2048; break; - case 1 : current_track->sector_size = 2336; break; - case 2 : current_track->sector_size = 2352; break; - default: { - if (stdfp) fprintf(stdfp,"cdi: \t\t\tunsupported %i bytes sector",current_track->sector_size_value); - return(0); - } + case 0: current_track->sector_size = 2048; break; + case 1: current_track->sector_size = 2336; break; + case 2: current_track->sector_size = 2352; break; + default: + { + if (stdfp) + fprintf(stdfp, "CDI: \t\t\tUnsupported %i bytes sector\n", (int)current_track->sector_size_value); + return 0; + } } - if (current_track->mode > 2) - if (stdfp) fprintf(stdfp,"cdi: \t\t\ttrack mode %i not supported",current_track->mode); + if (current_track->mode > 2) + if (stdfp) + fprintf(stdfp, "CDI: \t\t\tTrack mode %i not supported\n", (int)current_track->mode); lseek(fp, 29, SEEK_CUR); + if (descriptor->version != CDI_V2) { lseek(fp, 5, SEEK_CUR); - read(fp,&temp_value, 4); - if (temp_value == 0xffffffff) + read(fp, &temp_value, 4); + + if (temp_value == 0xFFFFFFFF) lseek(fp, 78, SEEK_CUR); // extra data (DJ 3.00.780 and up) } - current_track->position=track_position; - track_position+=(current_track->pregap_length+current_track->length)*current_track->sector_size; - previous_position=track_position; + + current_track->position = track_position; + track_position += (current_track->pregap_length+current_track->length) * current_track->sector_size; + previous_position = track_position; } + lseek(fp, 4, SEEK_CUR); lseek(fp, 8, SEEK_CUR); + if (descriptor->version != CDI_V2) lseek(fp, 1, SEEK_CUR); } + if (descriptor->header_offset == 0) - return(0); + return 0; - return(descriptor); + return descriptor; } -void cdi_dump_descriptor(FILE *fp,s_cdi_descriptor *cdi_descriptor) +void cdi_dump_descriptor(FILE * fp, s_cdi_descriptor * cdi_descriptor) { - fprintf(fp,"cdi: %i Mb\n",cdi_descriptor->length>>20); - fprintf(fp,"cdi: format version "); + fprintf(fp, "CDI: %i Mb\n", (int)(cdi_descriptor->length >> 20)); + fprintf(fp, "CDI: Format version "); switch(cdi_descriptor->version) { - case CDI_V2: fprintf(fp,"2\n"); break; - case CDI_V3: fprintf(fp,"3\n"); break; - case CDI_V35: fprintf(fp,"3.5\n"); break; - default: fprintf(fp,"unknown\n"); break; + case CDI_V2: + fprintf(fp, "2\n"); + break; + case CDI_V3: + fprintf(fp, "3\n"); + break; + case CDI_V35: + fprintf(fp, "3.5\n"); + break; + default: + fprintf(fp, "unknown\n"); } - fprintf(fp,"cdi: %i sessions\n",cdi_descriptor->nb_of_sessions); + fprintf(fp, "CDI: %i sessions\n", cdi_descriptor->nb_of_sessions); } uint8 * cdi_extract_boot_code(int fp, s_cdi_descriptor * cdi_descriptor) @@ -225,10 +272,12 @@ uint8 * cdi_extract_boot_code(int fp, s_cdi_descriptor * cdi_descriptor) } if (offset == (boot_track_size >> 2)) { - fprintf(log_get(), "CDI: Cannot find the boot code\n"); + WriteLog("CDI: Cannot find the boot code\n"); return NULL; } +//This is likely wrong, but won't get a chance to fix it until I can get a CD image +//to work with... offset = (offset << 2) + 4; uint16 * data16 = (uint16 *)&boot_track_data[offset]; cdi_load_address = *data16++; @@ -237,10 +286,10 @@ uint8 * cdi_extract_boot_code(int fp, s_cdi_descriptor * cdi_descriptor) cdi_code_length = *data16++; cdi_code_length <<= 16; cdi_code_length |= *data16++; - fprintf(log_get(), "CDI: Load address: %08X\n", cdi_load_address); - fprintf(log_get(), "CDI: Length: %08X\n", cdi_code_length); + WriteLog("CDI: Load address: %08X\n", cdi_load_address); + WriteLog("CDI: Length: %08X\n", cdi_code_length); //No need for byte swapping any more... -/* fprintf(log_get(), "cdi: byte swapping boot code\n"); +/* WriteLog("cdi: byte swapping boot code\n"); for(uint32 i=0; i<(cdi_code_length >> 1); i++) { diff --git a/src/include/cdi.h b/src/include/cdi.h index f63f228..f77ac6e 100644 --- a/src/include/cdi.h +++ b/src/include/cdi.h @@ -1,3 +1,7 @@ +// +// CDI.H: Header file +// + #ifndef __CDI_H__ #define __CDI_H__ @@ -5,9 +9,6 @@ #include "types.h" #include #include -#ifndef __PORT__ -#include -#endif #include struct s_cdi_track @@ -38,18 +39,22 @@ struct s_cdi_descriptor s_cdi_session *sessions; }; -extern int cdi_fp; -extern uint32 cdi_load_address; -extern uint32 cdi_code_length; -extern s_cdi_descriptor *cdi_descriptor; -extern s_cdi_track **cdi_tracks; -extern uint32 cdi_tracks_count; +// Exported variables + +extern int cdi_fp; +extern uint32 cdi_load_address; +extern uint32 cdi_code_length; +extern s_cdi_descriptor * cdi_descriptor; +extern s_cdi_track ** cdi_tracks; +extern uint32 cdi_tracks_count; + +// Exported functions -int cdi_open(char *path); +int cdi_open(char * path); void cdi_close(int fp); -s_cdi_descriptor *cdi_get_descriptor(int fp, FILE *stdfp); -void cdi_dump_descriptor(FILE *fp,s_cdi_descriptor *cdi_descriptor); -uint8 *cdi_extract_boot_code(int fp, s_cdi_descriptor *cdi_descriptor); -void cdi_load_sector(uint32 sector, uint8 *buffer); +s_cdi_descriptor * cdi_get_descriptor(int fp, FILE * stdfp); +void cdi_dump_descriptor(FILE * fp,s_cdi_descriptor * cdi_descriptor); +uint8 * cdi_extract_boot_code(int fp, s_cdi_descriptor * cdi_descriptor); +void cdi_load_sector(uint32 sector, uint8 * buffer); -#endif +#endif // __CDI_H__