-
Notifications
You must be signed in to change notification settings - Fork 0
/
C65c02.cpp
100 lines (90 loc) · 4.07 KB
/
C65c02.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// Copyright (c) 2004 K. Wilkins
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from
// the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
//////////////////////////////////////////////////////////////////////////////
// Handy - An Atari Lynx Emulator //
// Copyright (c) 1996,1997 //
// K. Wilkins //
//////////////////////////////////////////////////////////////////////////////
// 65C02 Emulation class //
//////////////////////////////////////////////////////////////////////////////
// //
// This class emulates a 65C02 processor. It is interfaced to the rest of //
// the system via the PEEK/POKE macros and a number of global variables //
// //
// K. Wilkins //
// August 1997 //
// //
//////////////////////////////////////////////////////////////////////////////
// Revision History: //
// ----------------- //
// //
// 16Oct2007 AK Moved non-speed-intensive routines to a separate CPP file //
// 01Aug1997 KW Document header added & class documented. //
// //
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "System.h"
#ifdef GZIP_STATE
#include "./zlib-113/zlib.h"
#endif
bool C65C02::ContextSave(FILE *fp)
{
TRACE_CPU0("ContextSave()");
#ifdef GZIP_STATE
#define fwrite(B,L,N,F) gzwrite(F,B,(L)*(N))
#define fprintf(F,S) gzprintf(F,S)
#endif
int mPS;
mPS=PS();
if(!fprintf(fp,"C6502::ContextSave")) return 0;
if(!fwrite(&mA,sizeof(ULONG),1,fp)) return 0;
if(!fwrite(&mX,sizeof(ULONG),1,fp)) return 0;
if(!fwrite(&mY,sizeof(ULONG),1,fp)) return 0;
if(!fwrite(&mSP,sizeof(ULONG),1,fp)) return 0;
if(!fwrite(&mPS,sizeof(ULONG),1,fp)) return 0;
if(!fwrite(&mPC,sizeof(ULONG),1,fp)) return 0;
if(!fwrite(&mIRQActive,sizeof(ULONG),1,fp)) return 0;
#ifdef GZIP_STATE
#undef fwrite
#undef fprintf
#endif
return 1;
}
bool C65C02::ContextLoad(LSS_FILE *fp)
{
TRACE_CPU0("ContextLoad()");
int mPS;
char teststr[100]="XXXXXXXXXXXXXXXXXX";
if(!lss_read(teststr,sizeof(char),18,fp)) return 0;
if(strcmp(teststr,"C6502::ContextSave")!=0) return 0;
if(!lss_read(&mA,sizeof(ULONG),1,fp)) return 0;
if(!lss_read(&mX,sizeof(ULONG),1,fp)) return 0;
if(!lss_read(&mY,sizeof(ULONG),1,fp)) return 0;
if(!lss_read(&mSP,sizeof(ULONG),1,fp)) return 0;
if(!lss_read(&mPS,sizeof(ULONG),1,fp)) return 0;
if(!lss_read(&mPC,sizeof(ULONG),1,fp)) return 0;
if(!lss_read(&mIRQActive,sizeof(ULONG),1,fp)) return 0;
PS(mPS);
return 1;
}