// Filename : MEMCARD.C // Coded by : Scott Evans // Created/Modified : 20/7/98 // Description : Memory card library #include // Function : InitMemoryCard() // Coded by : Scott Evans // Created/Modified : 21/7/98 // Description : Test a memory card // Parameters : slot - 0 or 1 to select memory card // Returns : result of test // Notes : Results are as follows // // MC_MISSING - no memory card in the slot // MC_PRESENT - a memory card was found in the slot // MC_NEW - a new memory card was found // MC_ERROR - an error with card // MC_UNINITIALISED - non formatted memory card long InitMemoryCard(u_byte slot) { #ifdef DEBUG_INFO static u_byte *messages[]={"No memory card found","Memory card found","New memory card found","Error","Non formatted memory card found"}; #endif long result; #ifdef YAROZE result=TestCard(slot); #else result=MC_MISSING; #endif // Wait for it.... VSync(4); #ifdef DEBUG_INFO sprintf(fm_string,"Slot %d %s\n",slot+1,messages[result]); PrintFM(fm_string); #endif return(result); } // Function : CreateMemoryCardFilename() // Coded by : Scott Evans // Created/Modified : 21/7/98 // Description : Creates a memory card filename // Parameters : name - name of file // mc_name - memory card filename // slot - slot number to use // Returns : 1 for success, 0 for error // Notes : None void CreateMemoryCardFilename(u_byte *name,u_byte *mc_name,u_byte slot) { // Create filename sprintf(mc_name,"bu%d0:%s %s",slot,MC_STANDARD_FILENAME,name); #ifdef DEBUG_INFO sprintf(fm_string,"%s created\n",mc_name); PrintFM(fm_string); #endif } // Function : CreateFile() // Coded by : Scott Evans // Created/Modified : 21/7/98 // Description : Creates a file on a memory card // Parameters : mc_name - memory card filename // size - size of file in blocks // Returns : 1 for success, 0 for error // Notes : File blocks are 8K, total capcity of card 15 blocks (120K) // One file = One block // Filename format is bu0:BE-NETYAROZE // Filename should be created with CreateMemoryCardFilename() u_byte CreateFile(u_byte *mc_name,word size) { long fh; // Try to create the file if((fh=open(mc_name,O_CREAT|(size<<16)))>0) { #ifdef DEBUG_INFO sprintf(fm_string,"Created file %s size %d bytes %d block(s)\n",mc_name,size*MC_BLOCK_SIZE,size); PrintFM(fm_string); #endif close(fh); return(1); } #ifdef DEBUG_INFO sprintf(fm_string,"Failed (%s)\n",mc_name); PrintFM(fm_string); #endif return(0); } // Function : InitMCFileHeader() // Coded by : Scott Evans // Created/Modified : 21/7/98 // Description : Initialises a memory card file header // Parameters : mch - pointer to header // mci - pointer to informaion on textures to use in animation // n - file size in blocks // s - description string // Returns : 1 for success, 0 for error // Notes : None void InitMCFileHeader(MCFILE_HEADER *mch,MC_IMAGE_INFO *mci,u_byte n,u_byte *s) { // Clear out the structure bzero((u_byte *)mch,sizeof(MCFILE_HEADER)); // Fill out the header mch->magic_no[0]='S'; mch->magic_no[1]='C'; mch->type=mci->type; mch->no_blocks=n; // Put in the description memcpy(&mch->name[0],ConvertAsciiToShiftJIS(s),MC_DESCRIPTION_SIZE); // Pad with spaces memset(&mch->pad[0],' ',MC_PADDING_SIZE); // Copy the CLUT for the animation if(mci->clut) memcpy((u_byte *)&mch->CLUT[0],(u_byte *)mci->clut,MC_CLUT_SIZE<<1); // Copy the first image if(mci->image0) memcpy((u_byte *)&mch->image0[0],(u_byte *)mci->image0,MC_IMAGE_SIZE<<1); // Copy the second image if(mci->image1) memcpy((u_byte *)&mch->image1[0],(u_byte *)mci->image1,MC_IMAGE_SIZE<<1); // Copy the third image if(mci->image2) memcpy((u_byte *)&mch->image2[0],(u_byte *)mci->image2,MC_IMAGE_SIZE<<1); } // Function : WriteBlock() // Coded by : Scott Evans // Created/Modified : 21/7/98 // Description : Writes a block of bytes to memory card // Parameters : mc_name - memory card filename // buffer - pointer to data to write // n - number of bytes to write // Returns : Number of bytes written or -1 for error // Notes : The memory card filename is created by CreateFile() long WriteBlock(u_byte *mc_name,u_byte *buffer,long n) { long fh,no_bytes; word i,nsectors; // Open the file if((fh=open(mc_name,O_WRONLY))>=0) { // Calculate number of sectors to write nsectors=n/MC_SECTOR_SIZE; // Write the data for(no_bytes=i=0;i=0) { // Calculate number of sectors to write nsectors=n/MC_SECTOR_SIZE; // Write the data for(no_bytes=i=0;i=0) { p=_GetSprPblk(h,n0); images.image0=(u_word *)_GetSprImgData(p); // Get CLUT for images images.clut=(u_word *)((u_byte *)_GetCLUT(h)+_4bitCLUTSIZE*p->CLUTid); images.type=MC_ONE_IMAGE; images.header_size=MC_HEADER0_SIZE; } // Second frame if(n1>=0) { p=_GetSprPblk(h,n1); images.image1=(u_word *)_GetSprImgData(p); images.type=MC_TWO_IMAGES; images.header_size=MC_HEADER1_SIZE; } // Third frame if(n2>=0) { p=_GetSprPblk(h,n2); images.image2=(u_word *)_GetSprImgData(p); images.type=MC_THREE_IMAGES; images.header_size=MC_HEADER2_SIZE; } return(&images); } // Function : MapAsciiToShiftJIS() // Coded by : Scott Evans // Created/Modified : 31/7/98 // Description : Maps an ASCII character to a Shift JIS character // Parameters : c - ASCII code to convert // Returns : Shift JIS character code // Notes : None u_word MapAsciiToShiftJIS(u_byte c) { // Convert upper case letters (A-Z) if(c>='A' && c<='Z') return(SJIS_UA+c-'A'); // Convert lower case letters (a-z) if(c>='a' && c<='z') return(SJIS_LA+c-'a'); // Convert numbers (0-9) if(c>='0' && c<='9') return(SJIS_0+c-'0'); // Other characters switch(c) { case ' ': return(SJIS_SPACE); default: #ifdef DEBUG_INFO PrintFM("ASCII code not converted\n"); #endif return(0); } } // Function : ConvertAsciiToShiftJIS() // Coded by : Scott Evans // Created/Modified : 31/7/98 // Description : Converts an ASCII string a Shift JIS string // Parameters : string - ASCII string to convert // Returns : Shift JIS character string // Notes : No check is done on length of string u_byte *ConvertAsciiToShiftJIS(u_byte *string) { static u_byte buffer[MC_DESCRIPTION_SIZE]; u_byte i,j,l; u_word sjis; // Number of characters to convert l=strlen(string); // Convert Ascii string for(i=0,j=0;i>8)&0xff; buffer[j++]=sjis&0xff; } buffer[j++]=0; buffer[j]=0; return(&buffer[0]); }