-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathram.c
180 lines (149 loc) · 4.44 KB
/
ram.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
/*
* ram.c - RAM stuff.
*
* Written by
* Andreas Matthies <andreas.matthies@gmx.net>
*
* This file is part of VICE, the Versatile Commodore Emulator.
* See README for copyright notice.
*
* 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 "vice.h"
#include <stdio.h>
#include <string.h>
#include "cmdline.h"
#include "ram.h"
#include "resources.h"
#include "translate.h"
#include "types.h"
static int start_value;
static int value_invert;
static int pattern_invert;
static int set_start_value(int val, void *param)
{
start_value = val;
if (start_value < 0)
start_value = 0;
if (start_value > 0xff)
start_value = 0xff;
return 0;
}
static int set_value_invert(int val, void *param)
{
value_invert = val;
return 0;
}
static int set_pattern_invert(int val, void *param)
{
pattern_invert = val;
return 0;
}
/* RAM-related resources. */
static const resource_int_t resources_int[] = {
{ "RAMInitStartValue", 0, RES_EVENT_SAME, NULL,
&start_value, set_start_value, NULL },
{ "RAMInitValueInvert", 64, RES_EVENT_SAME, NULL,
&value_invert, set_value_invert, NULL },
{ "RAMInitPatternInvert", 0, RES_EVENT_SAME, NULL,
&pattern_invert, set_pattern_invert, NULL },
{ NULL }
};
int ram_resources_init(void)
{
return resources_register_int(resources_int);
}
static const cmdline_option_t cmdline_options[] = {
{ "-raminitstartvalue", SET_RESOURCE, 1,
NULL, NULL, "RAMInitStartValue", NULL,
USE_PARAM_ID, USE_DESCRIPTION_ID,
IDCLS_P_VALUE, IDCLS_SET_FIRST_RAM_ADDRESS_VALUE,
NULL, NULL },
{ "-raminitvalueinvert" , SET_RESOURCE, 1,
NULL, NULL, "RAMInitValueInvert", NULL,
USE_PARAM_ID, USE_DESCRIPTION_ID,
IDCLS_P_NUM_OF_BYTES, IDCLS_LENGTH_BLOCK_SAME_VALUE,
NULL, NULL },
{ "-raminitpatterninvert", SET_RESOURCE, 1,
NULL, NULL, "RAMInitPatternInvert", NULL,
USE_PARAM_ID, USE_DESCRIPTION_ID,
IDCLS_P_NUM_OF_BYTES, IDCLS_LENGTH_BLOCK_SAME_PATTERN,
NULL, NULL },
{ NULL }
};
int ram_cmdline_options_init(void)
{
return cmdline_register_options(cmdline_options);
}
void ram_init(BYTE *memram, unsigned int ramsize)
{
unsigned int i;
BYTE v = start_value;
for (i = 0; i < ramsize; i++)
{
memram[i] = v;
if (value_invert > 0 && (i + 1) % value_invert == 0)
v ^= 0xff;
if (pattern_invert > 0 && (i + 1) % pattern_invert == 0)
v ^= 0xff;
}
}
const char *ram_init_print_pattern(void)
{
static char s[512], s_tmp[16], pattern_line[64];
BYTE v = start_value;
int i;
int linenum = 0;
int last_line_drawn = 0;
s[0] = 0;
do {
pattern_line[0] = 0;
for (i = 0; i < 8; i++) {
sprintf(s_tmp," %02x", v);
strcat(pattern_line, s_tmp);
if (value_invert > 0
&& (linenum * 8 + i + 1) % value_invert == 0)
{
v ^= 0xff;
}
if (pattern_invert > 0
&& (linenum * 8 + i + 1) % pattern_invert == 0)
{
v ^= 0xff;
}
}
if (linenum * 8 == 0
|| linenum * 8 == value_invert
|| linenum * 8 == pattern_invert
|| linenum * 8 == pattern_invert + value_invert)
{
sprintf(s_tmp, "%04x ", linenum * 8);
strcat(s, s_tmp);
strcat(s, pattern_line);
strcat(s, "\n");
last_line_drawn = 1;
} else {
if (last_line_drawn == 1)
strcat(s, "...\n");
last_line_drawn = 0;
}
linenum++;
} while (linenum * 8 < value_invert * 2 || linenum * 8 < pattern_invert * 2);
if (last_line_drawn == 1)
strcat(s, "...\n");
return s;
}