home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / Geneve / 9640news / CAT36 / EMULSRC.ZIP / BOOT.C < prev    next >
Text File  |  1993-04-28  |  2KB  |  98 lines

  1. /* Boot section of the TI-99/4A emulator */
  2.  
  3. void load_roms(char configname[])
  4. {
  5. FILE *infile;
  6. char line[80],filename[15],memtype;
  7. word base,skip,length;
  8.  
  9. paging=FALSE;
  10.  
  11. if ((infile=fopen(configname,"r"))==NULL)
  12. {
  13.     printf("Could not open '%s', ",configname);
  14.     printf("configuring standard TI-99/4A\n");
  15.     load_byte_memory_from_file(grom,0x0000,"grom0.bin",0,0x1800);
  16.     load_byte_memory_from_file(grom,0x2000,"grom1.bin",0,0x1800);
  17.     load_byte_memory_from_file(grom,0x4000,"grom2.bin",0,0x1800);
  18.     load_word_memory_from_file(mem,0x0000,"rom.bin",0,0x2000);
  19.     load_word_memory_from_file(mem,0x4000,"diskrom.bin",0,0x100);
  20.  
  21. }
  22. else
  23. {
  24.     printf("Parsing %s:\n",configname);
  25.     while(!feof(infile))
  26.     {
  27.         if(fgets(line,80,infile)!=NULL)
  28.         if ((line[0]!='*')&&(line[0]!=' ')&&(strlen(line)>8))
  29.         {
  30.             if(sscanf(line,"%s %c %x %x %x",filename,
  31.             &memtype,&base,&skip,&length)!=5)
  32.             printf("\n\nSYNTAX ERROR in '%s'\n>>> %s <<<\n",
  33.             configname,line);
  34.             else
  35.             {
  36. if (memtype=='G') load_byte_memory_from_file(grom,base,filename,skip,length);
  37. if (memtype=='C') load_word_memory_from_file(mem,base,filename,skip,length);
  38. if (memtype=='S') {
  39.           word i;
  40.           load_word_memory_from_file(mem,base,filename,skip,length);
  41.           printf(" (Swapping bytes)");
  42.           for(i=0;i<length/2;i++)
  43.           *(mem+base/2+i)=(*(mem+base/2+i)<<8)|(*(mem+base/2+i)>>8);
  44.           }
  45.             }
  46.         }
  47.     }
  48. }
  49. }
  50.  
  51. void load_byte_memory_from_file(
  52. byte *memtype,
  53. word base,
  54. char filename[],
  55. word skip,
  56. word length)
  57. {
  58.     int i;
  59.     FILE *infile;
  60.     infile=fopen(filename,BINARY_READ_MODE);
  61.     if (infile==NULL)
  62.     {
  63.         printf("\nUnable to load '%s', aborting.\n",filename);
  64.         exit(0);
  65.     }
  66.     else printf("\nLoading '%s'",filename,base);
  67.     if (skip) for(i=0;i<skip;i++) fgetc(infile);
  68.     fread(memtype+base,1,length,infile);
  69.     fclose(infile);
  70. }
  71.  
  72. void load_word_memory_from_file(
  73. word *memtype,
  74. word base,
  75. char filename[],
  76. word skip,
  77. word length)
  78. {
  79.     int i;
  80.     FILE *infile;
  81.     infile=fopen(filename,BINARY_READ_MODE);
  82.     if (infile==NULL)
  83.     {
  84.         printf("\nUnable to load '%s', aborting.\n",filename);
  85.         exit(0);
  86.     }
  87.     else printf("\nLoading '%s'",filename);
  88.     if (skip) for(i=0;i<skip;i++) fgetc(infile);
  89.  
  90.     fread(memtype+(base/2),2,length/2,infile);
  91.     fclose(infile);
  92.     if (base==0x9000)
  93.     {
  94.         paging=TRUE;
  95.         printf("\n>7000->7FFF paging enabled.");
  96.     }
  97. }
  98.