Port80.cpp

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : 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 
00068 #include "StdAfx.h"
00069 #include "Port80.h"
00070 #include "System.h"
00071 
00075 CPort80::CPort80(CConfigurator* cfg, CSystem* c) : CSystemComponent(cfg, c)
00076 {
00077   c->RegisterMemory(this, 0, U64(0x00000801fc000080), 1);
00078   state.p80 = 0;
00079 }
00080 
00084 CPort80::~CPort80()
00085 { }
00086 
00091 u64 CPort80::ReadMem(int index, u64 address, int dsize)
00092 {
00093   return state.p80;
00094 }
00095 
00099 void CPort80::WriteMem(int index, u64 address, int dsize, u64 data)
00100 {
00101   state.p80 = (u8) data;
00102 }
00103 
00104 static u32  p80_magic1 = 0x80FFAA80;
00105 static u32  p80_magic2 = 0xAA8080FF;
00106 
00110 int CPort80::SaveState(FILE* f)
00111 {
00112   long  ss = sizeof(state);
00113 
00114   fwrite(&p80_magic1, sizeof(u32), 1, f);
00115   fwrite(&ss, sizeof(long), 1, f);
00116   fwrite(&state, sizeof(state), 1, f);
00117   fwrite(&p80_magic2, sizeof(u32), 1, f);
00118   printf("%s: %d bytes saved.\n", devid_string, ss);
00119   return 0;
00120 }
00121 
00125 int CPort80::RestoreState(FILE* f)
00126 {
00127   long    ss;
00128   u32     m1;
00129   u32     m2;
00130   size_t  r;
00131 
00132   r = fread(&m1, sizeof(u32), 1, f);
00133   if(r != 1)
00134   {
00135     printf("%s: unexpected end of file!\n", devid_string);
00136     return -1;
00137   }
00138 
00139   if(m1 != p80_magic1)
00140   {
00141     printf("%s: MAGIC 1 does not match!\n", devid_string);
00142     return -1;
00143   }
00144 
00145   fread(&ss, sizeof(long), 1, f);
00146   if(r != 1)
00147   {
00148     printf("%s: unexpected end of file!\n", devid_string);
00149     return -1;
00150   }
00151 
00152   if(ss != sizeof(state))
00153   {
00154     printf("%s: STRUCT SIZE does not match!\n", devid_string);
00155     return -1;
00156   }
00157 
00158   fread(&state, sizeof(state), 1, f);
00159   if(r != 1)
00160   {
00161     printf("%s: unexpected end of file!\n", devid_string);
00162     return -1;
00163   }
00164 
00165   r = fread(&m2, sizeof(u32), 1, f);
00166   if(r != 1)
00167   {
00168     printf("%s: unexpected end of file!\n", devid_string);
00169     return -1;
00170   }
00171 
00172   if(m2 != p80_magic2)
00173   {
00174     printf("%s: MAGIC 1 does not match!\n", devid_string);
00175     return -1;
00176   }
00177 
00178   printf("%s: %d bytes restored.\n", devid_string, ss);
00179   return 0;
00180 }

SourceForge.net Logo
Project space on SourceForge.net