forked from thefossilrecord/beebem-rs97
-
Notifications
You must be signed in to change notification settings - Fork 5
/
via.cc
166 lines (151 loc) · 7.05 KB
/
via.cc
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/****************************************************************************/
/* Beebem - (c) David Alan Gilbert 1994 */
/* ------------------------------------ */
/* This program may be distributed freely within the following restrictions:*/
/* */
/* 1) You may not charge for this program or for any part of it. */
/* 2) This copyright message must be distributed with all copies. */
/* 3) This program must be distributed complete with source code. Binary */
/* only distribution is not permitted. */
/* 4) The author offers no warrenties, or guarentees etc. - you use it at */
/* your own risk. If it messes something up or destroys your computer */
/* thats YOUR problem. */
/* 5) You may use small sections of code from this program in your own */
/* applications - but you must acknowledge its use. If you plan to use */
/* large sections then please ask the author. */
/* */
/* If you do not agree with any of the above then please do not use this */
/* program. */
/* Please report any problems to the author at [email protected] */
/****************************************************************************/
/* Support file for 6522 via - 30/10/94 - David Alan Gilbert */
#include <iostream>
#include "via.h"
#include "uefstate.h"
//>++ UserVia and SysVia states:
extern VIAState UserVIAState;
extern VIAState SysVIAState;
extern unsigned char IC32State;
extern unsigned char WTDelay1,WTDelay2;
//++<
void VIAReset(VIAState *ToReset) {
ToReset->ora=ToReset->orb=0xff; /* ??? */
ToReset->ira=ToReset->irb=0xff; /* ??? */
ToReset->ddra=ToReset->ddrb=0; /* All inputs */
ToReset->acr=0; /* Timed ints on t1, t2, no pb7 hacking, no latching, no shifting */
ToReset->pcr=0; /* Neg edge inputs for cb2,ca2 and CA1 and CB1 */
ToReset->ifr=0; /* No interrupts presently interrupting */
ToReset->ier=0x80; /* No interrupts enabled */
ToReset->timer1l=ToReset->timer2l=0xffff;/*0xffff; */
ToReset->timer1c=ToReset->timer2c=0xffff;/*0x1ffff; */
ToReset->timer1hasshot=0;
ToReset->timer2hasshot=0;
} /* VIAReset */
/*-------------------------------------------------------------------------*/
//==void SaveVIAState(VIAState *VIAData, unsigned char *StateData) {
//== StateData[0] = VIAData->orb;
//== StateData[1] = VIAData->irb;
//== StateData[2] = VIAData->ora;
//== StateData[3] = VIAData->ira;
//== StateData[4] = VIAData->ddrb;
//== StateData[5] = VIAData->ddra;
//== StateData[6] = (VIAData->timer1c / 2) & 255; /* Timers stored in 2MHz */
//== StateData[7] = (VIAData->timer1c / 2) >> 8; /* units for speed */
//== StateData[8] = VIAData->timer1l & 255;
//== StateData[9] = VIAData->timer1l >> 8;
//== StateData[10] = (VIAData->timer2c / 2) & 255;
//== StateData[11] = (VIAData->timer2c / 2) >> 8;
//== StateData[12] = VIAData->timer2l & 255;
//== StateData[13] = VIAData->timer2l >> 8;
//== StateData[14] = 0; /* Shift register - not currently used */
//== StateData[15] = VIAData->acr;
//== StateData[16] = VIAData->pcr;
//== StateData[17] = VIAData->ifr;
//== StateData[18] = VIAData->ier;
//==}
void SaveVIAUEF(FILE *SUEF) {
VIAState *VIAPtr;
for (int n=0;n<2;n++) {
if (!n) VIAPtr=&SysVIAState; else VIAPtr=&UserVIAState;
fput16(0x0467,SUEF);
fput32(22,SUEF);
fputc(n,SUEF);
fputc(VIAPtr->orb,SUEF);
fputc(VIAPtr->irb,SUEF);
fputc(VIAPtr->ora,SUEF);
fputc(VIAPtr->ira,SUEF);
fputc(VIAPtr->ddrb,SUEF);
fputc(VIAPtr->ddra,SUEF);
fput16(VIAPtr->timer1c / 2,SUEF);
fput16(VIAPtr->timer1l,SUEF);
fput16(VIAPtr->timer2c / 2,SUEF);
fput16(VIAPtr->timer2l,SUEF);
fputc(VIAPtr->acr,SUEF);
fputc(VIAPtr->pcr,SUEF);
fputc(VIAPtr->ifr,SUEF);
fputc(VIAPtr->ier,SUEF);
fputc(VIAPtr->timer1hasshot,SUEF);
fputc(VIAPtr->timer2hasshot,SUEF);
if (!n) fputc(IC32State,SUEF); else fputc(0,SUEF);
}
}
/*-------------------------------------------------------------------------*/
//==void RestoreVIAState(VIAState *VIAData, unsigned char *StateData) {
//== VIAData->orb = StateData[0];
//== VIAData->irb = StateData[1];
//== VIAData->ora = StateData[2];
//== VIAData->ira = StateData[3];
//== VIAData->ddrb = StateData[4];
//== VIAData->ddra = StateData[5];
//== VIAData->timer1c = (StateData[6] + (StateData[7] << 8)) * 2;
//== VIAData->timer1l = StateData[8] + (StateData[9] << 8);
//== VIAData->timer2c = (StateData[10] + (StateData[11] << 8)) * 2;
//== VIAData->timer2l = StateData[12] + (StateData[13] << 8);
//== VIAData->acr = StateData[15];
//== VIAData->pcr = StateData[16];
//== VIAData->ifr = StateData[17];
//== VIAData->ier = StateData[18];
//== VIAData->timer1hasshot = 0;
//== VIAData->timer2hasshot = 0;
//==}
void LoadViaUEF(FILE *SUEF) {
VIAState *VIAPtr;
int VIAType;
VIAType=fgetc(SUEF); if (VIAType) VIAPtr=&UserVIAState; else VIAPtr=&SysVIAState;
VIAPtr->orb=fgetc(SUEF);
VIAPtr->irb=fgetc(SUEF);
VIAPtr->ora=fgetc(SUEF);
VIAPtr->ira=fgetc(SUEF);
VIAPtr->ddrb=fgetc(SUEF);
VIAPtr->ddra=fgetc(SUEF);
VIAPtr->timer1c=fget16(SUEF) * 2;
VIAPtr->timer1l=fget16(SUEF);
VIAPtr->timer2c=fget16(SUEF) * 2;
VIAPtr->timer2l=fget16(SUEF);
VIAPtr->acr=fgetc(SUEF);
VIAPtr->pcr=fgetc(SUEF);
VIAPtr->ifr=fgetc(SUEF);
VIAPtr->ier=fgetc(SUEF);
VIAPtr->timer1hasshot=fgetc(SUEF);
VIAPtr->timer2hasshot=fgetc(SUEF);
if (!VIAType) IC32State=fgetc(SUEF);
}
/*-------------------------------------------------------------------------*/
void via_dumpstate(VIAState *ToDump) {
std::cerr << " ora=" << int(ToDump->ora) << "\n";
std::cerr << " orb=" << int(ToDump->orb) << "\n";
std::cerr << " ira=" << int(ToDump->ira) << "\n";
std::cerr << " irb=" << int(ToDump->irb) << "\n";
std::cerr << " ddra=" << int(ToDump->ddra) << "\n";
std::cerr << " ddrb=" << int(ToDump->ddrb) << "\n";
std::cerr << " acr=" << int(ToDump->acr) << "\n";
std::cerr << " pcr=" << int(ToDump->pcr) << "\n";
std::cerr << " ifr=" << int(ToDump->ifr) << "\n";
std::cerr << " ier=" << int(ToDump->ier) << "\n";
std::cerr << " timer1c=" << ToDump->timer1c << "\n";
std::cerr << " timer2c=" << ToDump->timer2c << "\n";
std::cerr << " timer1l=" << ToDump->timer1l << "\n";
std::cerr << " timer2l=" << ToDump->timer2l << "\n";
std::cerr << " timer1hasshot=" << ToDump->timer1hasshot << "\n";
std::cerr << " timer2hasshot=" << ToDump->timer2hasshot << "\n";
}; /* via_dumpstate */