home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser 2002 January / STC_CD_01_2002.iso / JAGUAR / JAG_SRC / SOURCE / BOOT.C < prev    next >
C/C++ Source or Header  |  2001-08-18  |  23KB  |  682 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. // Jagulator: Atari Jaguar Console Emulation Project (boot.c)
  3. // -----------------------------------------------------------------------------
  4. // Jagulator is the Copyright (c) RealityMan 1998-2001 and is provided "as is" 
  5. // without any expressed or implied warranty. I have no Trademarks, Legal or 
  6. // otherwise. Atari, Jaguar and the Atari Logo are copyright Hasbro Inc. All 
  7. // other Copyrights and Trademarks are acknowledged. This project is in no way 
  8. // linked to Atari/Hasbro or other associated Atari companies.                
  9. //
  10. // 07-07-2001 GH: New Source, Rewritten for Release 1.5.0
  11. // 00-00-0000 GH: All Previous Source Considered as Development Code Only
  12.  
  13. #include "core.h"
  14.  
  15. ////////////////////////////////////////////////////////////////////////////////
  16. // Globals
  17.  
  18.    // Fetchable Code Areas
  19.    struct STARSCREAM_PROGRAMREGION memFetch[] = {
  20.       { 0x000000, 0x3FFFFF, (unsigned)st.ram   - 0x000000 },
  21.       { 0x800000, 0xDFFFFF, (unsigned)st.game  - 0x800000 },
  22.       { 0xE00000, 0xE1FFFF, (unsigned)st.boot  - 0xE00000 },
  23.       { 0xF00000, 0xF0FFFF, (unsigned)st.tom   - 0xF00000 },
  24.       { 0xF10000, 0xF1FFFF, (unsigned)st.jerry - 0xF10000 },
  25.       { -1,       -1,       (unsigned)NULL                   }
  26.    };
  27.  
  28.    // Read Byte
  29.    struct STARSCREAM_DATAREGION memReadByte[] = {
  30.       { 0x000000, 0x3FFFFF, NULL,          st.ram   },
  31.       { 0x800000, 0xDFFFFF, NULL,          st.game  },
  32.       { 0xE00000, 0xE1FFFF, NULL,          st.boot  },
  33.       { 0xF00000, 0xF0FFFF, NULL,          st.tom   },
  34.       { 0xF10000, 0xF1FFFF, NULL,          st.jerry },
  35.       { -1,       -1,       NULL,          NULL     }
  36.    };
  37.  
  38.    // Read Word
  39.    struct STARSCREAM_DATAREGION memReadWord[] = {
  40.       { 0x000000, 0x3FFFFF, NULL,          st.ram   },
  41.       { 0x800000, 0xDFFFFF, NULL,          st.game  },
  42.       { 0xE00000, 0xE1FFFF, NULL,          st.boot  },
  43.       { 0xF00000, 0xF0FFFF, mem_tomreadw,  st.tom   },
  44.       { 0xF10000, 0xF1FFFF, mem_jryreadw,  st.jerry },
  45.       { -1,       -1,       NULL,          NULL     }
  46.    };
  47.  
  48.    // Write Byte
  49.    struct STARSCREAM_DATAREGION memWriteByte[] = {
  50.       { 0x000000, 0x3FFFFF, NULL,          st.ram   },
  51.       { 0xF00000, 0xF0FFFF, NULL,          st.tom   },
  52.       { 0xF10000, 0xF1FFFF, NULL,          st.jerry },
  53.       { -1,       -1,       NULL,          NULL     }
  54.    };
  55.  
  56.    // Write Word
  57.    struct STARSCREAM_DATAREGION memWriteWord[] = {
  58.       { 0x000000, 0x3FFFFF, NULL,          st.ram   },
  59.       { 0xF00000, 0xF0FFFF, mem_tomwritew, st.tom   },
  60.       { 0xF10000, 0xF1FFFF, mem_jrywritew, st.jerry },
  61.       { -1,       -1,       NULL,          NULL     }
  62.    };
  63.  
  64.    typedef struct {
  65.       dword crc;                       // CRC
  66.       dword title;                     // Description/Title
  67.       dword supp;                      // Supported Y/N
  68.       dword format;                    // 1 = BIN, 2 = JAG
  69.       dword offset;                    // Load Offset
  70.       dword loadaddr;                  // Load Address
  71.       dword hres;                      // Horizontal Resolution
  72.       dword vres;                      // Vertical Resolution
  73.    } ROMTABLE;
  74.  
  75.    // Rom Titles
  76.    char *romt[] = {
  77.       // 0
  78.       "Asteroids by Sinister Developments\0",
  79.       "BadCode0 Demo by BadCoder\0",
  80.       "BadCode1 Demo by BadCoder\0",
  81.       "BadCode2 Demo by BadCoder\0",
  82.       "BadCode3 Demo by BadCoder\0",
  83.       // 5
  84.       "BadCode4 Demo by BadCoder\0",
  85.       "BadCode4c Demo by BadCoder\0",
  86.       "BadCode4 (Metal) Demo by BadCoder\0",
  87.       "Colors (CrY Color Picker) by Matthias Domin\0",
  88.       "Gorf by 3D Stooges Software\0",
  89.       // 10
  90.       "JagMania by Matthias Domin\0",
  91.       "JDC Demo V1 by Lars Hannig\0",
  92.       "JoyPad Tester by Matthias Domin\0",
  93.       "Legion Force Jidai Demo by Force Design\0",
  94.       // Extras
  95.       "Atari Jaguar Object Processor Tester V2 by Lars Hanning\0",
  96.       "\0"
  97.    };
  98.  
  99.    ROMTABLE roms[] = {
  100.       0xDF188AF5,   9, 1, 1, 0x00000000, 0x00004000, 340, 299,
  101.       0xA6B07EFA,   8, 1, 1, 0x00000000, 0x00005000, 380, 286,
  102.       0x17B9C4DD,   8, 1, 2, 0x0000002E, 0x00005000, 380, 286,
  103.       0x3C6E7EFA,  10, 1, 1, 0x00000000, 0x00005000, 448, 338,
  104.       0xF046AD6B,  10, 1, 2, 0x0000002E, 0x00005000, 448, 338,
  105.       0x874650A4,   0, 1, 1, 0x00000000, 0x00020000, 404, 301,
  106.       0x5F141A2A,  13, 1, 1, 0x00000000, 0x00005000, 352, 286,
  107.       0x6B902FD1,  12, 1, 2, 0x0000002E, 0x00005000, 448, 295,
  108.       0xB4FB9F2E,  12, 1, 1, 0x00000000, 0x00005000, 448, 295,
  109.       0xF150D92B,  11, 1, 1, 0x00000000, 0x00004000, 380, 263,
  110.       0xD05AD7EE,   1, 1, 1, 0x00000000, 0x00004000, 380, 280,
  111.       0x6BD289A7,   2, 1, 1, 0x00000000, 0x00004000, 380, 280,
  112.       0x70E19B3F,   3, 1, 1, 0x00000000, 0x00004000, 380, 280,
  113.       0xAAF9123C,   4, 1, 1, 0x00000000, 0x00004000, 380, 280,
  114.       0xFFFFFFFF,   5, 1, 1, 0x00000000, 0x00004000, 380, 280,
  115.       0xFFFFFFFF,   6, 1, 1, 0x00000000, 0x00004000, 380, 280,
  116.       0xEBCED8F5,   7, 1, 1, 0x00000000, 0x00004000, 368, 292,
  117.       0x414F4CD1,   4, 1, 2, 0x0000002E, 0x00004000, 380, 280,
  118.       0xFFFFFFFF,   5, 1, 2, 0x0000002E, 0x00004000, 380, 280,
  119.       0x411D1B4F,   7, 1, 2, 0x0000002E, 0x00004000, 368, 292,
  120.       0x2930F2A3,  14, 1, 1, 0x00000000, 0x00004000, 362, 302,
  121.       0x00000000, 999, 0, 0, 0x00000000, 0x00000000,   0,   0
  122.    };
  123.  
  124. ////////////////////////////////////////////////////////////////////////////////
  125. // CRC Calculation Code
  126. // Usage:
  127. // unsigned long crc = -1L
  128. // crc = crc32(buffer, length, crc)
  129.  
  130.    static unsigned long *CRCTable;    // Table constructed for fast lookup.
  131.  
  132.    #define CRC32_POLYNOMIAL    0xEDB88320L
  133.  
  134.    // Initialize the CRC calculation table
  135.  
  136.    static int BuildCRCTable(void)
  137.    {
  138.        int i, j;
  139.        unsigned long crc;
  140.  
  141.        CRCTable = malloc(256 * sizeof(unsigned long));
  142.        if (CRCTable == NULL)
  143.        {
  144.            fprintf(stderr, "Can't malloc space for CRC table in file %s\n", __FILE__);
  145.            return -1L;
  146.        }
  147.  
  148.        for (i = 0; i <= 255; i++)
  149.        {
  150.            crc = i;
  151.            for (j = 8; j > 0; j--)
  152.                if (crc & 1)
  153.                    crc = (crc >> 1) ^ CRC32_POLYNOMIAL;
  154.                else
  155.                    crc >>= 1;
  156.            CRCTable[i] = crc;
  157.        }
  158.        return 0;
  159.    }
  160.  
  161.    unsigned long crc32(void *buffer, unsigned int count, unsigned long crc)
  162.    {
  163.        unsigned long temp1, temp2;
  164.        static int firsttime = 1;
  165.        unsigned char *p = (unsigned char *)buffer;
  166.    
  167.        if (firsttime)
  168.        {
  169.            if (BuildCRCTable())
  170.                return -1;
  171.            firsttime = 0;
  172.        }
  173.    
  174.        while (count-- != 0)
  175.        {
  176.            temp1 = (crc >> 8) & 0x00FFFFFFL;
  177.            temp2 = CRCTable[((int)crc ^ *p++) & 0xFF];
  178.            crc = temp1 ^ temp2;
  179.        }
  180.        return crc;
  181.    }
  182.  
  183. ////////////////////////////////////////////////////////////////////////////////
  184. // Start Core Jaguar Emulation Here (68000 Command Processor)
  185.  
  186.    void boot_jaguar( dword address )
  187.    {
  188.       // Tie Memory Map into the CPU Context
  189.       s68000context.s_fetch = memFetch;
  190.       s68000context.u_fetch = memFetch;
  191.  
  192.       s68000context.s_readbyte  = memReadByte;
  193.       s68000context.u_readbyte  = memReadByte;
  194.       s68000context.s_readword  = memReadWord;
  195.       s68000context.u_readword  = memReadWord;
  196.       s68000context.s_writebyte = memWriteByte;
  197.       s68000context.u_writebyte = memWriteByte;
  198.       s68000context.s_writeword = memWriteWord;
  199.       s68000context.u_writeword = memWriteWord;
  200.  
  201.       // Initialise and Rest StarScream CPU
  202.       s68000init();
  203.       s68000reset();
  204.  
  205.       // Initialisation
  206.       blt.bltInactive = TRUE;          // Blitter is Inactive
  207.       gst.div16 = FALSE;               // Disable 16.16 Division
  208.  
  209.       #ifdef DEBUG
  210.       print( "%% Initialising System to NTSC\n" );
  211.       #endif
  212.       *(word *)(st.jerry + 0x4002) |= VIDTYPE;
  213.  
  214.       s68000context.areg[7] = address; // Set Stack
  215.       s68000context.pc = address;      // Set Program Counter
  216.  
  217.       wsprintf( sbbuf, "Emulating..." );
  218.       SendMessage( hwndStatus, SB_SETTEXT, 0, (LPARAM)sbbuf );
  219.  
  220.       cpu_exec();
  221.    }
  222.  
  223. ////////////////////////////////////////////////////////////////////////////////
  224. // Entry Point for Rom Loading
  225.  
  226.    dword boot_load( void )
  227.    {
  228.       dword gamesize;                  // Size of Loaded Game Rom
  229.       dword bootsize;                  // Size of Loaded Boot Rom
  230.       byte tmp;                        // Temporary Byte Storage
  231.       static char buf[MAX_PATH];       // Temporary Buffer
  232.       dword crc;                       // CRC Value of Rom
  233.       dword i, j;                      // Iterators
  234.         FILE *hFile;                     // Handle to File
  235.       OPENFILENAME OpenFileName;       // Structure for Open Common Dialog
  236.       TCHAR fname[ MAX_PATH ] = "\0";  // Filename
  237.         LPCTSTR szFilterI = "Jaguar Rom Images (bin,jag,rom,abs)\0"
  238.                               "*.bin;*.jag;*.rom;*.abs\0"
  239.                                "All Files (*.*)\0"
  240.                                 "*.*\0\0";   
  241.       DWORD ofnFlags    = OFN_FILEMUSTEXIST |
  242.                           OFN_HIDEREADONLY  |
  243.                           OFN_PATHMUSTEXIST;
  244.  
  245.       OpenFileName.lpstrFilter = szFilterI;
  246.         OpenFileName.lpstrTitle  = "Load Atari Jaguar Rom";
  247.         OpenFileName.lpstrDefExt = "*.bin";
  248.       OpenFileName.lStructSize       = sizeof( OPENFILENAME );
  249.       OpenFileName.hwndOwner         = hwndMain;
  250.       OpenFileName.hInstance         = hInst;
  251.       OpenFileName.lpstrCustomFilter = (LPTSTR) NULL;
  252.       OpenFileName.nMaxCustFilter    = 0;
  253.       OpenFileName.nFilterIndex      = 1L;
  254.       OpenFileName.lpstrFile         = fname;
  255.       OpenFileName.nMaxFile          = sizeof( fname );
  256.       OpenFileName.lpstrFileTitle    = NULL;
  257.       OpenFileName.nMaxFileTitle     = 0;
  258.       OpenFileName.lpstrInitialDir   = cfg.rompath;
  259.       OpenFileName.nFileOffset       = 0;
  260.       OpenFileName.nFileExtension    = 0;
  261.       OpenFileName.Flags             = ofnFlags;
  262.       OpenFileName.lCustData         = 0;
  263.       OpenFileName.lpfnHook          = NULL;
  264.       OpenFileName.lpTemplateName    = NULL;
  265.  
  266.       if( GetOpenFileName( &OpenFileName ) )
  267.       {
  268.          v_deinit();
  269.          memset( &st,  0, sizeof( STATE    ) );
  270.          memset( &gst, 0, sizeof( GPUSTATE ) );
  271.          memset( &dst, 0, sizeof( DSPSTATE ) );
  272.          memset( &blt, 0, sizeof( BLTSTATE ) );
  273.          wsprintf( sbbuf, "%s", COPYRIGHT );
  274.          SendMessage( hwndStatus, SB_SETTEXT, 0, (LPARAM)sbbuf );
  275.  
  276.          // File Selected
  277.          hFile = fopen( fname, "rb" );
  278.          if( hFile == NULL )
  279.          {
  280.             wsprintf( sbbuf, "Could not open \'%s\'...", fname );
  281.             SendMessage( hwndStatus, SB_SETTEXT, 0, (LPARAM)sbbuf );
  282.             error( "Could not open \'%s\'", fname );
  283.             st.readytogo = 0;
  284.             flushdisplay();
  285.             return( FALSE );
  286.          }
  287.          fseek( hFile, 0L, SEEK_SET );
  288.          fread( buf, 1, MAX_PATH, hFile );
  289.          fclose( hFile );
  290.  
  291.          // Check if Rom is Supported
  292.          crc = crc32( buf, MAX_PATH, -1 );
  293.          for( i = 0; ; i++ )
  294.          {
  295.             if( roms[i].crc == crc ) break;
  296.             if( !roms[i].crc )         // Unsupported Jaguar Rom
  297.             {
  298.                wsprintf( sbbuf, "ERROR: Rom is either not supported or not a valid Atari Jaguar rom image..." );
  299.                SendMessage( hwndStatus, SB_SETTEXT, 0, (LPARAM)sbbuf );
  300.                print( YEL"Error: This rom is not supported by Jagulator "
  301.                           "or is not a recognised\n"
  302.                       YEL"       Atari Jaguar rom image.\n" );
  303.                flushdisplay();
  304.                st.readytogo = 0;
  305.                return( FALSE );
  306.             }
  307.          }
  308.  
  309.          // Load Boot Rom
  310.          strcpy( buf, cfg.bootpath );
  311.          strcat( buf, "jagboot.rom" );
  312.          print( "%% Loading Boot Rom Image \'%s\'\n", buf );
  313.          wsprintf( sbbuf, "Loading Boot Rom Image \'%s\'...", buf );
  314.          SendMessage( hwndStatus, SB_SETTEXT, 0, (LPARAM)sbbuf );
  315.          flushdisplay();
  316.          hFile = fopen( buf, "rb" );
  317.          if( hFile == NULL )
  318.          {
  319.             wsprintf( sbbuf, "Could Not Load Boot Rom...." );
  320.             SendMessage( hwndStatus, SB_SETTEXT, 0, (LPARAM)sbbuf );
  321.             error( "Could Not Open Boot Rom." );
  322.             print( "This file must be named 'jagboot.rom' and be located"
  323.                    " in the 'Boot Path'\n" );
  324.             st.readytogo = 0;
  325.             flushdisplay();
  326.             return( FALSE );
  327.          }
  328.          else
  329.          {
  330.             fseek( hFile, 0L, SEEK_END );
  331.             bootsize = ftell( hFile );
  332.             if( bootsize != 131072 ) 
  333.             {
  334.                fclose( hFile );
  335.                wsprintf( sbbuf, "Invalid Boot Rom File Size..." );
  336.                SendMessage( hwndStatus, SB_SETTEXT, 0, (LPARAM)sbbuf );
  337.                error( "Invalid Boot Rom File Size." );
  338.                st.readytogo = 0;
  339.                flushdisplay();
  340.                return( FALSE );
  341.             }
  342.             fseek( hFile, 0L, SEEK_SET );
  343.             fread( st.boot, 1, bootsize, hFile );
  344.             fclose( hFile );
  345.          }
  346.  
  347.          // Byte Swap Boot Rom 
  348.          for( j = 0; j < bootsize; j+=2 )
  349.          {
  350.             tmp = st.boot[j];
  351.             st.boot[j] = st.boot[j+1];
  352.             st.boot[j+1] = tmp;
  353.          }
  354.  
  355.          // Load Game Rom
  356.          wsprintf( sbbuf, "Loading Rom Image from '%s' to 0x%06X\n", fname, roms[i].loadaddr );
  357.          SendMessage( hwndStatus, SB_SETTEXT, 0, (LPARAM)sbbuf );
  358.          print( "%% Loading Rom Image from '%s' to 0x%06X\n", fname, roms[i].loadaddr );
  359.          flushdisplay();
  360.          hFile = fopen( fname, "rb" );
  361.          if( hFile == NULL )
  362.          {
  363.             error( "Could not open \'%s\'.", fname );
  364.             wsprintf( sbbuf, "Could not open \'%s\'...", fname );
  365.             SendMessage( hwndStatus, SB_SETTEXT, 0, (LPARAM)sbbuf );
  366.             st.readytogo = 0;
  367.             flushdisplay();
  368.             return( FALSE );
  369.          }
  370.          else
  371.          {
  372.             fseek( hFile, 0L, SEEK_END );
  373.             gamesize = ftell( hFile );
  374.             gamesize -= roms[i].offset;
  375.             fseek( hFile, roms[i].offset, SEEK_SET );
  376.             fread( st.ram + roms[i].loadaddr, 1, gamesize, hFile );
  377.             fclose( hFile );
  378.          }
  379.  
  380.          // Byte Swap Game Rom 
  381.          for( j = 0; j < gamesize; j+=2 )
  382.          {
  383.             tmp = st.ram[j+roms[i].loadaddr];
  384.             st.ram[j+roms[i].loadaddr] = st.ram[j+roms[i].loadaddr+1];
  385.             st.ram[j+roms[i].loadaddr+1] = tmp;
  386.          }
  387.       }
  388.       else 
  389.          return( FALSE );
  390.  
  391.       cfg.hres = roms[i].hres;
  392.       cfg.vres = roms[i].vres;
  393.  
  394.       st.readytogo = 1;
  395.       boot_jaguar( roms[i].loadaddr );
  396.       return( TRUE );
  397.    }
  398.  
  399.  
  400.  
  401. ////////////////////////////////////////////////////////////////////////////////
  402. // Entry Point for Standard Cartridge Loading
  403.  
  404.    void boot( char *cartname )
  405.    {
  406.       static char buf[MAX_PATH];       // Temporary Buffer
  407.         FILE *hFile;                     // Handle to File
  408.       dword gamesize;                  // Size of Loaded Game Rom
  409.       dword i;                         // Iterator
  410.       dword bootsize;                  // Size of Loaded Boot Rom
  411.       byte tmp;                        // Temporary Byte Storage
  412.  
  413.       // Load Game Rom
  414.       strcpy( buf, cfg.rompath );
  415.       strcat( buf, cartname );
  416.       #ifdef DEBUG
  417.       print( "%% Loading Rom Image from '%s'\n", buf );
  418.       #endif
  419.       hFile = fopen( buf, "rb" );
  420.       if( hFile == NULL )
  421.       {
  422.          #ifdef DEBUG
  423.          error( "Could not open \'%s\'", buf );
  424.          #endif
  425.          st.readytogo = 0;
  426.          return;
  427.       }
  428.       else
  429.       {
  430.          fseek( hFile, 0L, SEEK_END );
  431.          gamesize = ftell( hFile );
  432.          fseek( hFile, 0L, SEEK_SET );
  433.          fread( st.game, 1, gamesize, hFile );
  434.          fclose( hFile );
  435.       }
  436.  
  437.       // Byte Swap Game Rom 
  438.       for( i = 0; i < gamesize; i+=2 )
  439.       {
  440.          tmp = st.game[i];
  441.          st.game[i] = st.game[i+1];
  442.          st.game[i+1] = tmp;
  443.       }
  444.  
  445.       // Load Boot Rom
  446.       strcpy( buf, cfg.bootpath );
  447.       strcat( buf, "jagboot.rom" );
  448.       #ifdef DEBUG
  449.       print( "%% Loading Boot Rom Image \'%s\'\n", buf );
  450.       #endif
  451.       hFile = fopen( buf, "rb" );
  452.       if( hFile == NULL )
  453.       {
  454.          #ifdef DEBUG
  455.          error( "Could Not Open Boot Rom" );
  456.          print( "This file must be named 'jagboot.rom' and be located"
  457.                 " in the 'Boot Path'\n" );
  458.          #endif
  459.          st.readytogo = 0;
  460.          return;
  461.       }
  462.       else
  463.       {
  464.          fseek( hFile, 0L, SEEK_END );
  465.          bootsize = ftell( hFile );
  466.          if( bootsize != 131072 ) 
  467.          {
  468.             fclose( hFile );
  469.             #ifdef DEBUG
  470.             error( "Invalid Boot Rom File Size" );
  471.             #endif
  472.             st.readytogo = 0;
  473.             return;
  474.          }
  475.          fseek( hFile, 0L, SEEK_SET );
  476.          fread( st.boot, 1, bootsize, hFile );
  477.          fclose( hFile );
  478.       }
  479.  
  480.       // Byte Swap Boot Rom 
  481.       for( i = 0; i < bootsize; i+=2 )
  482.       {
  483.          tmp = st.boot[i];
  484.          st.boot[i] = st.boot[i+1];
  485.          st.boot[i+1] = tmp;
  486.       }
  487.  
  488.       // Copy Interrupt Stack Pointer and Initial PC to 0x000000
  489.       memcpy( st.ram, st.boot, 8 );    // Start of Boot Code
  490.       
  491.       st.ram[5] = 0x00;
  492.       st.ram[4] = 0x80;                // Start of Program Code 
  493.       st.ram[7] = 0x20;
  494.       st.ram[6] = 0x00;
  495.   
  496.  
  497.       st.readytogo = 1;
  498.       boot_jaguar( 802000 );
  499.    }
  500.  
  501. ////////////////////////////////////////////////////////////////////////////////
  502. // Entry Point for Image Loading at RAM Memory Address (Demo Support)
  503.  
  504.    void bootaddr( char *cartname, int address )
  505.    {
  506.       static char buf[MAX_PATH];       // Temporary Buffer
  507.         FILE *hFile;                     // Handle to File
  508.       dword bootsize;                  // Size of Loaded Boot Rom
  509.       dword gamesize;                  // Size of Loaded Game Rom
  510.       dword i;                         // Iterator
  511.       byte tmp;                        // Temporary Byte Storage
  512.  
  513.       // Load Game Rom
  514.       strcpy( buf, cfg.rompath );
  515.       strcat( buf, cartname );
  516.       #ifdef DEBUG
  517.       print( "%% Loading Rom Image from '%s' to 0x%06X\n", buf, address );
  518.       #endif
  519.       hFile = fopen( buf, "rb" );
  520.       if( hFile == NULL )
  521.       {
  522.          #ifdef DEBUG
  523.          error( "Could not open \'%s\'", buf );
  524.          #endif
  525.          st.readytogo = 0;
  526.          return;
  527.       }
  528.       else
  529.       {
  530.          fseek( hFile, 0L, SEEK_END );
  531.          gamesize = ftell( hFile );
  532.          fseek( hFile, 0L, SEEK_SET );
  533.          fread( st.ram + address, 1, gamesize, hFile );
  534.          fclose( hFile );
  535.       }
  536.  
  537.       // Byte Swap Game Rom 
  538.       for( i = 0; i < gamesize; i+=2 )
  539.       {
  540.          tmp = st.ram[i+address];
  541.          st.ram[i+address] = st.ram[i+address+1];
  542.          st.ram[i+address+1] = tmp;
  543.       }
  544.  
  545.       // Load Boot Rom
  546.       strcpy( buf, cfg.bootpath );
  547.       strcat( buf, "jagboot.rom" );
  548.       #ifdef DEBUG
  549.       print( "%% Loading Boot Rom Image \'%s\'\n", buf );
  550.       #endif
  551.       hFile = fopen( buf, "rb" );
  552.       if( hFile == NULL )
  553.       {
  554.          #ifdef DEBUG
  555.          error( "Could Not Open Boot Rom" );
  556.          print( "This file must be named 'jagboot.rom' and be located"
  557.                 " in the 'Boot Path'\n" );
  558.          #endif
  559.          st.readytogo = 0;
  560.          return;
  561.       }
  562.       else
  563.       {
  564.          fseek( hFile, 0L, SEEK_END );
  565.          bootsize = ftell( hFile );
  566.          if( bootsize != 131072 ) 
  567.          {
  568.             fclose( hFile );
  569.             #ifdef DEBUG
  570.             error( "Invalid Boot Rom File Size" );
  571.             #endif
  572.             st.readytogo = 0;
  573.             return;
  574.          }
  575.          fseek( hFile, 0L, SEEK_SET );
  576.          fread( st.boot, 1, bootsize, hFile );
  577.          fclose( hFile );
  578.       }
  579.  
  580.       // Byte Swap Boot Rom 
  581.       for( i = 0; i < bootsize; i+=2 )
  582.       {
  583.          tmp = st.boot[i];
  584.          st.boot[i] = st.boot[i+1];
  585.          st.boot[i+1] = tmp;
  586.       }
  587.  
  588.       st.readytogo = 1;
  589.       boot_jaguar( address );
  590.    }
  591.  
  592. ////////////////////////////////////////////////////////////////////////////////
  593. // Entry Point for CDROM Emulation
  594.  
  595.    void bootcd( void )
  596.    {/*
  597.       static char buf[MAX_PATH];       // Temporary Buffer
  598.         FILE *hFile;                     // Handle to File
  599.       dword bootsize;                  // Size of Loaded Boot Rom
  600.       dword cdrsize;                   // Size of Loaded CD Boot Rom
  601.       dword i;                         // Iterator
  602.       byte tmp;                        // Temporary Byte Storage
  603.  
  604.       // Load CD BIOS
  605.       strcpy( buf, cfg.bootpath );
  606.       strcat( buf, "jagcd.rom" );
  607.       #ifdef DEBUG
  608.       print( "%% Loading CD Boot Rom Image from '%s' to 0x%06X\n", buf, 0x00800000 );
  609.       #endif
  610.       hFile = fopen( buf, "rb" );
  611.       if( hFile == NULL )
  612.       {
  613.          #ifdef DEBUG
  614.          error( "Could not open \'%s\'", buf );
  615.          #endif
  616.          st.readytogo = 0;
  617.          return;
  618.       }
  619.       else
  620.       {
  621.          fseek( hFile, 0L, SEEK_END );
  622.          cdrsize = ftell( hFile );
  623.          fseek( hFile, 0L, SEEK_SET );
  624.          fread( st.game, 1, cdrsize, hFile );
  625.          fclose( hFile );
  626.       }
  627.  
  628.       // Byte Swap Game Rom 
  629.       for( i = 0; i < cdrsize; i+=2 )
  630.       {
  631.          tmp = st.game[i];
  632.          st.game[i] = st.game[i+1];
  633.          st.game[i+1] = tmp;
  634.       }
  635.  
  636.       // Load Boot Rom
  637.       strcpy( buf, cfg.bootpath );
  638.       strcat( buf, "jagboot.rom" );
  639.       #ifdef DEBUG
  640.       print( "%% Loading Boot Rom Image \'%s\'\n", buf );
  641.       #endif
  642.       hFile = fopen( buf, "rb" );
  643.       if( hFile == NULL )
  644.       {
  645.          #ifdef DEBUG
  646.          error( "Could Not Open Boot Rom" );
  647.          print( "This file must be named 'jagboot.rom' and be located"
  648.                 " in the 'Boot Path'\n" );
  649.          #endif
  650.          st.readytogo = 0;
  651.          return;
  652.       }
  653.       else
  654.       {
  655.          fseek( hFile, 0L, SEEK_END );
  656.          bootsize = ftell( hFile );
  657.          if( bootsize != 131072 ) 
  658.          {
  659.             fclose( hFile );
  660.             #ifdef DEBUG
  661.             error( "Invalid Boot Rom File Size" );
  662.             #endif
  663.             st.readytogo = 0;
  664.             return;
  665.          }
  666.          fseek( hFile, 0L, SEEK_SET );
  667.          fread( st.boot, 1, bootsize, hFile );
  668.          fclose( hFile );
  669.       }
  670.  
  671.       // Byte Swap Boot Rom 
  672.       for( i = 0; i < bootsize; i+=2 )
  673.       {
  674.          tmp = st.boot[i];
  675.          st.boot[i] = st.boot[i+1];
  676.          st.boot[i+1] = tmp;
  677.       }
  678.  
  679.       st.readytogo = 1;
  680.       boot_jaguar();*/
  681.    }
  682.