DPR.cpp

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * Website: http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  * 
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  */
00025 
00101 #include "StdAfx.h"
00102 #include "DPR.h"
00103 #include "System.h"
00104 #include "Serial.h"
00105 #include <time.h>
00106 #include "AlphaCPU.h"
00107 
00108 #define ToBCD(x)  (((x) / 10 << 4) | ((x) % 10))
00109 
00110 extern CSerial*   srl[2];
00111 
00115 CDPR::CDPR(CConfigurator* cfg, CSystem* c) : CSystemComponent(cfg, c)
00116 {
00117   if(theDPR)
00118     FAILURE(Configuration, "More than one DPR");
00119   theDPR = this;
00120 
00121   c->RegisterMemory(this, 0, U64(0x0000080110000000), 0x100000);  // 16KB
00122 }
00123 
00127 void CDPR::init()
00128 {
00129   int  i;
00130 
00131   memset(&state, 0, sizeof(state));
00132   RestoreStateF();
00133 
00134   for(i = 0; i < cSystem->get_cpu_num(); i++)
00135   {
00136     state.ram[i * 0x20 + 0x00] = 1; // EV6 BIST
00137     state.ram[i * 0x20 + 0x01] = (i == 0) ? 0x80 : i; // SROM status
00138     state.ram[i * 0x20 + 0x02] = 1;     // STR status
00139     state.ram[i * 0x20 + 0x03] = 1;     // CSC status
00140     state.ram[i * 0x20 + 0x04] = 1;     // Pchip0 status
00141     state.ram[i * 0x20 + 0x05] = 1;     // Pchip1 status
00142     state.ram[i * 0x20 + 0x06] = 1;     // DIMx status
00143     state.ram[i * 0x20 + 0x07] = 1;     // TIG bus status
00144     state.ram[i * 0x20 + 0x08] = 0xdd;  // DPR test started
00145     state.ram[i * 0x20 + 0x09] = 1;     // DPR status
00146     state.ram[i * 0x20 + 0x0a] = 0xff;  // CPU speed status
00147     state.ram[i * 0x20 + 0x0b] = (cSystem->get_cpu(i)->get_speed() / 1000000) % 256;  //speed
00148     state.ram[i * 0x20 + 0x0c] = (cSystem->get_cpu(i)->get_speed() / 1000000) / 256;  //speed
00149 
00150     // powerup time BCD:
00151     time_t      now = time(NULL);
00152     struct tm*  t = localtime(&now);
00153     state.ram[i * 0x20 + 0x10] = ToBCD(t->tm_hour);
00154     state.ram[i * 0x20 + 0x11] = ToBCD(t->tm_min);
00155     state.ram[i * 0x20 + 0x12] = ToBCD(t->tm_sec);
00156     state.ram[i * 0x20 + 0x13] = ToBCD(t->tm_mday);
00157     state.ram[i * 0x20 + 0x14] = ToBCD(t->tm_mon + 1);
00158     state.ram[i * 0x20 + 0x15] = ToBCD(t->tm_year - 100); // tm_year is based on 1900
00159 #if defined(DEBUG_DPR)
00160     printf("%%DPR-I-BOOTDATE: %02x-%02x-%02x, %02x:%02x:%02x\n",
00161            state.ram[i * 0x20 + 21], state.ram[i * 0x20 + 20],
00162            state.ram[i * 0x20 + 19], state.ram[i * 0x20 + 16],
00163            state.ram[i * 0x20 + 17], state.ram[i * 0x20 + 18]);
00164 #endif
00165     state.ram[i * 0x20 + 0x16] = 0;     // no error
00166     state.ram[i * 0x20 + 0x1e] = 0x80;  // CPU SROM sync moet 0x80 zijn; anders --> cpu0 startup failure
00167     state.ram[i * 0x20 + 0x1f] = 8;     // cach size in MB
00168   }
00169 
00170   state.ram[0xda] = 0xaa; // TIG load
00171 
00172   // DIMM config
00173   state.ram[0x80] = 0xf0; // twice-split 8 dimms array 0
00174   state.ram[0x81] = 0x01; // 64 MB
00175 
00176   //    state.ram[0x82] = 0xf1; // twice-split 8 dimms array 1
00177   //    state.ram[0x83] = 0x01; // 64 MB
00178   //    state.ram[0x84] = 0xf2; // twice-split 8 dimms array 2
00179   //    state.ram[0x85] = 0x01; // 64 MB
00180   //    state.ram[0x86] = 0xf3; // twice-split 8 dimms array 3
00181   //    state.ram[0x87] = 0x01; // 64 MB
00182   // powerup failure bits
00183   state.ram[0x88] = 0;    // each bit is one DIMM on MMB0
00184   state.ram[0x89] = 0x00; // MMB1
00185   state.ram[0x8a] = 0x00; // MMB2
00186   state.ram[0x8b] = 0x00; // MMB3
00187 
00188   // misconfigured DIMM bits
00189   state.ram[0x8c] = 0;    // each bit is one DIMM on MMB0
00190   state.ram[0x8d] = 0;    // MMB1
00191   state.ram[0x8e] = 0;    // MMB2
00192   state.ram[0x8f] = 0;    // MMB3
00193   state.ram[0x90] = 0xff; // psu / vterm present
00194   state.ram[0x91] = 0x00; // psu ok bits
00195   state.ram[0x92] = 0x07; // ac inputs valid
00196   state.ram[0x93] = 0x25; // cpu 0 temp in C
00197   state.ram[0x94] = 0x25; // cpu 1 temp in C
00198   state.ram[0x95] = 0x25; // cpu 2 temp in C
00199   state.ram[0x96] = 0x25; // cpu 3 temp in C
00200   state.ram[0x97] = 0x25; // pci 0 temp in C
00201   state.ram[0x98] = 0x25; // pci 1 temp in C
00202   state.ram[0x99] = 0x25; // pci 2 temp in C
00203   state.ram[0x9a] = 0x8b; // fan 0 speed
00204   state.ram[0x9b] = 0x8b; // fan 1 speed
00205   state.ram[0x9c] = 0x8b; // fan 2 speed
00206   state.ram[0x9d] = 0x8b; // fan 3 speed
00207   state.ram[0x9e] = 0x8b; // fan 4 speed
00208   state.ram[0x9f] = 0x8b; // fan 5 speed
00209 
00210   // vector 680 info (various faults)
00211   for(i = 0xa0; i < 0xaa; i++)
00212     state.ram[i] = 0;
00213 
00214   state.ram[0xaa] = 0x00; // fans good
00215 
00216   // RMC read failure DIMM bits
00217   state.ram[0xab] = 0;    // each bit is one DIMM on MMB0
00218   state.ram[0xac] = 0xff; // MMB1
00219   state.ram[0xad] = 0xff; // MMB2
00220   state.ram[0xae] = 0xff; // MMB3
00221   switch(cSystem->get_cpu_num())
00222   {
00223   case 1: state.ram[0xaf] = 0x0e; // all MMB I2C's read + CPU 0
00224     break;
00225   case 2: state.ram[0xaf] = 0x0c; // all MMB I2C's read + CPU 0
00226     break;
00227   case 3: state.ram[0xaf] = 0x08; // all MMB I2C's read + CPU 0
00228     break;
00229   case 4: state.ram[0xaf] = 0x00; // all MMB I2C's read + CPU 0
00230     break;
00231   }
00232 
00233   state.ram[0xb0] = 0x00; // PCI i2c read
00234   state.ram[0xb1] = 0x00; // mainboard i2c read
00235   state.ram[0xb2] = 0x00; // psu's and scsi backplanes i2c read
00236   state.ram[0xba] = 0xba; // i2c finished
00237   state.ram[0xbb] = 0x00; // rmc error
00238   state.ram[0xbc] = 0x00; //rmc flash update error status
00239 
00240   // 680 fatal registers
00241   state.ram[0xbd] = 0x07; // ac inputs valid
00242   state.ram[0xbe] = 0;    // faults
00243   state.ram[0xbf] = 0;    // faults
00244   state.ram[0xda] = 0xaa; // tig load success
00245 
00246   // Power-supplies
00247   state.ram[0xdb] = 0xf4; // PS0 id
00248   state.ram[0xdc] = 0x45; // 3.3v current
00249   state.ram[0xdd] = 0x51; // 5.0v current
00250   state.ram[0xde] = 0x37; // 12v current
00251   state.ram[0xdf] = 0x8b; // fan speed
00252   state.ram[0xe0] = 0xd6; // ac voltage (230v)
00253   state.ram[0xe1] = 0x49; // internal temp. (56 C)
00254   state.ram[0xe2] = 0x4b; // inlet temp. (20 C)
00255   state.ram[0xe4] = 0xf5; // PS1 id
00256   state.ram[0xe5] = 0x45; // 3.3v current
00257   state.ram[0xe6] = 0x51; // 5.0v current
00258   state.ram[0xe7] = 0x37; // 12v current
00259   state.ram[0xe8] = 0x8b; // fan speed
00260   state.ram[0xe9] = 0xd6; // ac voltage (230v)
00261   state.ram[0xea] = 0x49; // internal temp. (56 C)
00262   state.ram[0xeb] = 0x4b; // inlet temp. (20 C)
00263   state.ram[0xed] = 0xf6; // PS2 id
00264   state.ram[0xee] = 0x45; // 3.3v current
00265   state.ram[0xef] = 0x51; // 5.0v current
00266   state.ram[0xf0] = 0x37; // 12v current
00267   state.ram[0xf1] = 0x8b; // fan speed
00268   state.ram[0xf2] = 0xd6; // ac voltage (230v)
00269   state.ram[0xf3] = 0x49; // internal temp. (56 C)
00270   state.ram[0xf4] = 0x4b; // inlet temp. (20 C)
00271 
00272   // EEROMs
00273 
00274   /*
00275      100: MMB0 DIMM 2
00276      200: MMB0 DIMM 3
00277      300: MMB0 DIMM 4
00278      400: MMB0 DIMM 5
00279      500: MMB0 DIMM 6
00280      600: MMB0 DIMM 7
00281      700: MMB0 DIMM 8
00282      800: MMB0 DIMM 1
00283      900: MMB1 DIMM 2
00284      a00: MMB1 DIMM 3
00285      b00: MMB1 DIMM 4
00286      c00: MMB1 DIMM 5
00287      d00: MMB1 DIMM 6
00288      e00: MMB1 DIMM 7
00289      f00: MMB1 DIMM 8
00290      1000: MMB1 DIMM 1
00291      1100: MMB2 DIMM 2
00292      1200: MMB2 DIMM 3
00293      1300: MMB2 DIMM 4
00294      1400: MMB2 DIMM 5
00295      1500: MMB2 DIMM 6
00296      1600: MMB2 DIMM 7
00297      1700: MMB2 DIMM 8
00298      1800: MMB2 DIMM 1
00299      1900: MMB3 DIMM 2
00300      1a00: MMB3 DIMM 3
00301      1b00: MMB3 DIMM 4
00302      1c00: MMB3 DIMM 5
00303      1d00: MMB3 DIMM 6
00304      1e00: MMB3 DIMM 7
00305      1f00: MMB3 DIMM 8
00306      2000: MMB3 DIMM 1
00307      2100: CPU0
00308      2200: CPU1
00309      2300: CPU2
00310      2400: CPU3
00311      2500: MMB0
00312      2600: MMB1
00313      2700: MMB2
00314      2800: MMB3
00315      2900: CPB (PCI backplane)
00316      2a00: CSB (motherboard)
00317      3100: PSU0 cont @ 3d00
00318      3200: PSU1 cont @ 3e00
00319      3300: PSU2 cont @ 3f00
00320      3b00: SCSI0 (backplane)
00321      3c00: SCSI1
00322 
00323      2B00:2BFF  RMC Last EV6 Correctable Error 
00324      ASCII character string that indicates correctable error occurred, type, FRU, and so on.
00325      2C00:2CFF  RMC Last Redundant Failure
00326      ASCII character string that indicates redundant failure occurred, type, FRU, and so on.
00327      2D00:2DFF  RMC Last System Failure
00328      ASCII character string that indicates system failure occurred, type, FRU, and so on.
00329      2E00:2FFF  RMC Uncorrectable machine logout frame (512 bytes)
00330    */
00331 
00332   //    3000:3008       SROM Version (ASCII string)
00333   state.ram[0x3000] = 'V';
00334   state.ram[0x3001] = '2';
00335   state.ram[0x3002] = '.';
00336   state.ram[0x3003] = '2';
00337   state.ram[0x3004] = '2';
00338   state.ram[0x3005] = 'G';
00339   state.ram[0x3006] = 0;
00340   state.ram[0x3007] = 0;
00341   state.ram[0x3008] = 0;
00342 
00343   //    3009:300B       RMC Rev Level of RMC first byte is letter Rev [x/t/v] second 2 bytes are major/minor.
00344   //                            This is the rev level of the RMC on-chip code.
00345   state.ram[0x3009] = 'V';
00346   state.ram[0x300a] = 0x31;
00347   state.ram[0x300b] = 0x30;
00348 
00349   //    300C:300E       RMC Rev Level of RMC first byte is letter Rev [x/t/v] second 2 bytes are major/minor.
00350   //                            This is the rev level of the RMC flash code.
00351   state.ram[0x300c] = 'V';
00352   state.ram[0x300d] = 0x31;
00353   state.ram[0x300e] = 0x30;
00354 
00355   //    300F:3010 300F RMC Revision Field of the DPR Structure
00356   //    3400 SROM Size of Bcache in MB
00357   state.ram[0x3400] = 8;
00358 
00359   //3401 SROM Flash SROM is valid flag; 8 = valid,0 = invalid
00360   state.ram[0x3401] = 1;
00361 
00362   //3402 SROM System's errors determined by SROM
00363   state.ram[0x3402] = 0;
00364 
00365   //3410:3417 SROM/SRM Jump to address for CPU0
00366   //3418 SROM/SRM Waiting to jump to flag for CPU0
00367   //3419 SROM Shadow of value written to EV6 DC_CTL register.
00368   //341A:341E SROM Shadow of most recent writes to EV6 CBOX "Write-many" chain.
00369   //34A0:34A7 SROM Array 0 to DIMM ID translation
00370   //                                                                            Bits<4:0>
00371   //            Bits<7:5>
00372   //            0 = Exists, No Error                    Bits <2:0> =
00373   //            1 = Expected Missing DIMM                       + 1 (1-8)
00374   //            2 = Error - Missing DIMM(s)             Bits <4:3> =
00375   //            4 = Error - Illegal MMB                 (0-3) DIMM(s)
00376   //            6 = Error - Incompatible DIMM(s)
00377   //    34A8:34AF SROM Repeat for Array 1 of Array 0 34A0:34A7
00378   //    34B0:34B7 SROM Repeat for Array 2 of Array 0 34A0:34A7
00379   //    34B8:34CF SROM Repeat for Array 3 of Array 0 34A0:34A7
00380   for(i = 0; i < 0x20; i++)
00381     state.ram[0x34a0 + i] = i;
00382 
00383   //    34C0:34FF       Used as scratch area for SROM
00384   //    3500:35FF       Used as the dedicated buffer in which SRM writes OCP or FRU EEROM data.
00385   //                            Firmware will write this data, RMC will only read this data.
00386   //    3600:36FF 3600 SRM Reserved
00387   //    3700:37FF SRM Reserved
00388   //    3800:3AFF RMC RMC scratch space
00389   printf("%s: $Id: DPR.cpp,v 1.22 2008/04/09 12:59:42 iamcamiel Exp $\n",
00390          devid_string);
00391 }
00392 
00396 CDPR::~CDPR()
00397 { }
00398 u64 CDPR::ReadMem(int index, u64 address, int dsize)
00399 {
00400   u64 data = 0;
00401   int a = (int) (address >> 6);
00402 
00403   data = state.ram[a];
00404 
00405 #if defined(DEBUG_DPR)
00406   printf("%%DPR-I-READ: Dual-Port RAM read @ 0x%08x: 0x%02x\n", a,
00407          (u32) (data & 0xff));
00408 #endif
00409   return data;
00410 }
00411 
00412 void CDPR::WriteMem(int index, u64 address, int dsize, u64 data)
00413 {
00414   int i;
00415   int a = (int) (address >> 6);
00416 #if defined(DEBUG_DPR)
00417   printf("%%DPR-I-WRITE: Dual-Port RAM write 0x%08x 0x%02x:\n", a,
00418          (u32) (data & 0xff));
00419 #endif
00420 
00421   // FOR COMMANDS:
00422   //
00423   // 0xf9:      buffer size
00424   // 0xfb:fa    qualifier / address
00425   // 0xfc:      completion code (0 = ok, 80 = error, 81 = invalid code, 82 = invalid qualifier)
00426   // 0xfd:      rmc command id for response
00427   // 0xfe:      command code
00428   // 0xff:      rmc command id for command
00429   // COMMANDS:
00430   // 01:        update EEPROM
00431   // 02:        update baud rate
00432   // 03:        write to OCP
00433   // F0:        update RMC flash
00434   state.ram[a] = (char) data;
00435   switch(a)
00436   {
00437   case 0xff:
00438 
00439     // command
00440     state.ram[0xfd] = state.ram[0xff];
00441     switch(state.ram[0xfe])
00442     {
00443     case 1:
00444 
00445       /*
00446          100: MMB0 DIMM 2
00447          200: MMB0 DIMM 3
00448          300: MMB0 DIMM 4
00449          400: MMB0 DIMM 5
00450          500: MMB0 DIMM 6
00451          600: MMB0 DIMM 7
00452          700: MMB0 DIMM 8
00453          800: MMB0 DIMM 1
00454          900: MMB1 DIMM 2
00455          a00: MMB1 DIMM 3
00456          b00: MMB1 DIMM 4
00457          c00: MMB1 DIMM 5
00458          d00: MMB1 DIMM 6
00459          e00: MMB1 DIMM 7
00460          f00: MMB1 DIMM 8
00461          1000: MMB1 DIMM 1
00462          1100: MMB2 DIMM 2
00463          1200: MMB2 DIMM 3
00464          1300: MMB2 DIMM 4
00465          1400: MMB2 DIMM 5
00466          1500: MMB2 DIMM 6
00467          1600: MMB2 DIMM 7
00468          1700: MMB2 DIMM 8
00469          1800: MMB2 DIMM 1
00470          1900: MMB3 DIMM 2
00471          1a00: MMB3 DIMM 3
00472          1b00: MMB3 DIMM 4
00473          1c00: MMB3 DIMM 5
00474          1d00: MMB3 DIMM 6
00475          1e00: MMB3 DIMM 7
00476          1f00: MMB3 DIMM 8
00477          2000: MMB3 DIMM 1
00478          2100: CPU0
00479          2200: CPU1
00480          2300: CPU2
00481          2400: CPU3
00482          2500: MMB0
00483          2600: MMB1
00484          2700: MMB2
00485          2800: MMB3
00486          2900: CPB (PCI backplane)
00487          2a00: CSB (motherboard)
00488          3100: PSU0 cont @ 3d00
00489          3200: PSU1 cont @ 3e00
00490          3300: PSU2 cont @ 3f00
00491          3b00: SCSI0 (backplane)
00492          3c00: SCSI1 */
00493 
00494       // FRU-Write
00495       switch(state.ram[0xfb])
00496       {
00497       case 0x21:
00498       case 0x22:
00499       case 0x23:
00500       case 0x24:
00501         if((state.ram[0xfb] - 0x20) > cSystem->get_cpu_num())
00502         {
00503           state.ram[0xfc] = 0x80;
00504           break;
00505         }
00506 
00507       case 1:
00508       case 2:
00509       case 3:
00510       case 4:
00511       case 5:
00512       case 6:
00513       case 7:
00514       case 8:
00515       case 0x25:
00516       case 0x26:
00517       case 0x27:
00518       case 0x28:
00519       case 0x29:
00520       case 0x2a:
00521       case 0x31:
00522       case 0x32:
00523       case 0x33:
00524       case 0x3b:
00525       case 0x3c:
00526       case 0x3d:
00527       case 0x3e:
00528       case 0x3f:
00529         for(i = 0; i < state.ram[0xf9] + 1; i++)
00530         {
00531           state.ram[state.ram[0xfb] * 0x100 + state.ram[0xfa] + i] = state.ram[0x3500 + state.ram[0xfa] + i];
00532 #if defined(DEBUG_DPR)
00533           printf("%%DPR-I-FRU: FRU data %02x @ FRU %02x set to %02x\n",
00534                  state.ram[0xfa] + i, state.ram[0xfb],
00535                  state.ram[0x3500 + state.ram[0xfa] + i]);
00536 #endif
00537         }
00538 
00539         state.ram[0xfc] = 0;
00540         break;
00541 
00542       default:
00543 #if defined(DEBUG_DPR)
00544         printf("%%DPR-I-RMC: RMC Command given: %02x\r\n", state.ram[0xfe]);
00545         printf("%%DPR-I-RMC: f9:%02x fb-fa:%02x%02x\r\n", state.ram[0xf9],
00546                state.ram[0xfb], state.ram[0xfa]);
00547 #endif
00548         state.ram[0xfc] = 0x80;
00549       }
00550       break;
00551 
00552     case 2:
00553       state.ram[0xfc] = 0;
00554       break;
00555 
00556     case 3:
00557 
00558       // OCP-Write
00559 #if defined(DEBUG_DPR)
00560       sprintf(trcbuffer,
00561               "%%%%DPR-I-OCP: OCP Text set to \"0123456789abcdef\"\r\n");
00562       memcpy(trcbuffer + 29, &(state.ram[0x3500]), 16);
00563 
00564       //                    srl[0]->write(trcbuffer);
00565       printf(trcbuffer);
00566 #endif
00567       state.ram[0xfc] = 0;
00568       break;
00569 
00570     case 0xf0:
00571       state.ram[0xfc] = 0;
00572 
00573     default:
00574 #if defined(DEBUG_DPR)
00575       printf("%%DPR-I-RMC: RMC Command given: %02x\r\n", state.ram[0xfe]);
00576       printf("%%DPR-I-RMC: f9:%02x fb-fa:%02x%02x\r\n", state.ram[0xf9],
00577              state.ram[0xfb], state.ram[0xfa]);
00578 #endif
00579       state.ram[0xfc] = 0x81;
00580     }
00581     break;
00582 
00583   case 0xfd:
00584 
00585     // end of command
00586     state.ram[0xff] = state.ram[0xfd];
00587   }
00588 
00589   return;
00590 }
00591 
00595 void CDPR::SaveStateF(char* fn)
00596 {
00597   FILE*   ff;
00598   ff = fopen(fn, "wb");
00599   if(ff)
00600   {
00601     SaveState(ff);
00602     fclose(ff);
00603     printf("%%DPR-I-SAVEST: DPR state saved to %s\n", fn);
00604   }
00605   else
00606   {
00607     printf("%%DPR-F-NOSAVE: DPR could not be saved to %s\n", fn);
00608   }
00609 }
00610 
00614 void CDPR::SaveStateF()
00615 {
00616   SaveStateF(myCfg->get_text_value("rom.dpr", "dpr.rom"));
00617 }
00618 
00622 void CDPR::RestoreStateF(char* fn)
00623 {
00624   FILE*   ff;
00625   ff = fopen(fn, "rb");
00626   if(ff)
00627   {
00628     RestoreState(ff);
00629     fclose(ff);
00630     printf("%%DPR-I-RESTST: DPR state restored from %s\n", fn);
00631   }
00632   else
00633   {
00634     printf("%%DPR-F-NOREST: DPR could not be restored from %s\n", fn);
00635   }
00636 }
00637 
00638 static u32  dpr_magic1 = 0x18A7B92D;
00639 static u32  dpr_magic2 = 0xD29B7A81;
00640 
00644 int CDPR::SaveState(FILE* f)
00645 {
00646   long  ss = sizeof(state);
00647 
00648   fwrite(&dpr_magic1, sizeof(u32), 1, f);
00649   fwrite(&ss, sizeof(long), 1, f);
00650   fwrite(&state, sizeof(state), 1, f);
00651   fwrite(&dpr_magic2, sizeof(u32), 1, f);
00652   printf("%s: %d bytes saved.\n", "dpr", ss);
00653   return 0;
00654 }
00655 
00659 int CDPR::RestoreState(FILE* f)
00660 {
00661   long    ss;
00662   u32     m1;
00663   u32     m2;
00664   size_t  r;
00665 
00666   r = fread(&m1, sizeof(u32), 1, f);
00667   if(r != 1)
00668   {
00669     printf("%s: unexpected end of file!\n", "dpr");
00670     return -1;
00671   }
00672 
00673   if(m1 != dpr_magic1)
00674   {
00675     printf("%s: MAGIC 1 does not match!\n", "dpr");
00676     return -1;
00677   }
00678 
00679   fread(&ss, sizeof(long), 1, f);
00680   if(r != 1)
00681   {
00682     printf("%s: unexpected end of file!\n", "dpr");
00683     return -1;
00684   }
00685 
00686   if(ss != sizeof(state))
00687   {
00688     printf("%s: STRUCT SIZE does not match!\n", "dpr");
00689     return -1;
00690   }
00691 
00692   fread(&state, sizeof(state), 1, f);
00693   if(r != 1)
00694   {
00695     printf("%s: unexpected end of file!\n", "dpr");
00696     return -1;
00697   }
00698 
00699   r = fread(&m2, sizeof(u32), 1, f);
00700   if(r != 1)
00701   {
00702     printf("%s: unexpected end of file!\n", "dpr");
00703     return -1;
00704   }
00705 
00706   if(m2 != dpr_magic2)
00707   {
00708     printf("%s: MAGIC 1 does not match!\n", "dpr");
00709     return -1;
00710   }
00711 
00712   printf("%s: %d bytes restored.\n", "dpr", ss);
00713   return 0;
00714 }
00715 
00719 void CDPR::RestoreStateF()
00720 {
00721   RestoreStateF(myCfg->get_text_value("rom.dpr", "dpr.rom"));
00722 }
00723 
00724 CDPR*   theDPR = 0;

SourceForge.net Logo
Project space on SourceForge.net