-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.c
197 lines (153 loc) · 4.39 KB
/
system.c
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
Copyright (C) 1998-2004 Charles MacDonald
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "shared.h"
bitmap_t bitmap;
cart_t cart;
input_t input;
/* Run the virtual console emulation for one frame */
void system_frame(int skip_render)
{
static int iline_table[] = {0xC0, 0xE0, 0xF0};
int lpf = (sms.display == DISPLAY_NTSC) ? 262 : 313;
int iline;
/* Debounce pause key */
if(input.system & INPUT_PAUSE)
{
if(!sms.paused)
{
sms.paused = 1;
z80_set_irq_line(IRQ_LINE_NMI, ASSERT_LINE);
z80_set_irq_line(IRQ_LINE_NMI, CLEAR_LINE);
}
}
else
{
sms.paused = 0;
}
text_counter = 0;
/* End of frame, parse sprites for line 0 on line 261 (VCount=$FF) */
if(vdp.mode <= 7)
parse_line(0);
for(vdp.line = 0; vdp.line < lpf;)
{
z80_execute(227);
iline = iline_table[vdp.extended];
if(!skip_render)
{
render_line(vdp.line);
}
if(vdp.line <= iline)
{
vdp.left -= 1;
if(vdp.left == -1)
{
vdp.left = vdp.reg[0x0A];
vdp.hint_pending = 1;
z80_execute(16);
if(vdp.reg[0x00] & 0x10)
{
z80_set_irq_line(0, ASSERT_LINE);
}
}
}
else
{
vdp.left = vdp.reg[0x0A];
}
if(vdp.line == iline)
{
vdp.status |= 0x80;
vdp.vint_pending = 1;
z80_execute(16);
if(vdp.reg[0x01] & 0x20)
{
z80_set_irq_line(0, ASSERT_LINE);
}
}
sound_update(vdp.line);
++vdp.line;
if(vdp.mode <= 7)
parse_line(vdp.line);
}
}
void system_reinit(void)
{
/* AK: This is needed to fix a palette corruption problem */
/* when switching between GG and SMS */
sms_shutdown();
pio_shutdown();
vdp_shutdown();
render_shutdown();
sms_init();
pio_init();
vdp_init();
render_init();
sms.save = 0;
}
void system_init(void)
{
error_init();
sms_init();
pio_init();
vdp_init();
render_init();
sound_init();
sms.save = 0;
}
void system_shutdown(void)
{
#ifdef DEBUG
int i;
error("PC:%04X\tSP:%04X\n", z80_get_reg(Z80_PC), z80_get_reg(Z80_SP));
error("AF:%04X\tAF:%04X\n", z80_get_reg(Z80_AF), z80_get_reg(Z80_AF2));
error("BC:%04X\tBC:%04X\n", z80_get_reg(Z80_BC), z80_get_reg(Z80_BC2));
error("DE:%04X\tDE:%04X\n", z80_get_reg(Z80_DE), z80_get_reg(Z80_DE2));
error("HL:%04X\tHL:%04X\n", z80_get_reg(Z80_HL), z80_get_reg(Z80_HL2));
error("IX:%04X\tIY:%04X\n", z80_get_reg(Z80_IX), z80_get_reg(Z80_IY));
for(i = 0; i <= 0x0A; i++)
error("%02X ", vdp.reg[i]);
error("\n");
error("MODE:%02X\n", vdp.mode & 7);
error("PN:%04X\n", vdp.pn);
error("CT:%04X\n", vdp.ct);
error("PG:%04X\n", vdp.pg);
error("SA:%04X\n", vdp.sa);
error("SG:%04X\n", vdp.sg);
error("\n");
#endif
sms_shutdown();
pio_shutdown();
vdp_shutdown();
render_shutdown();
sound_shutdown();
error_shutdown();
}
void system_reset(void)
{
sms_reset();
pio_reset();
vdp_reset();
render_reset();
sound_reset();
system_manage_sram(cart.sram, SLOT_CART, SRAM_LOAD);
}
void system_poweron(void)
{
system_reset();
}
void system_poweroff(void)
{
system_manage_sram(cart.sram, SLOT_CART, SRAM_SAVE);
}