-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_ram.c
254 lines (210 loc) · 6.29 KB
/
edit_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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*************************************************************************/
/* */
/* Ram editor source file */
/* */
/* A few functions to edit/view RAM as asked by Dave Shadoff ;) */
/* Note that cheating functions can also be helpful */
/* */
/*************************************************************************/
#include "edit_ram.h"
#define NB_BYTE_LINE 8
// Number of byte displayed on each line
#define NB_LINE 20
// Number of displayed lines
/*
static char out;
// To know whether we got to quit
static int frame_up, frame_down;
// The currently displayed "frame" in RAM
static unsigned short selected_byte;
// The current offset
*/
/*****************************************************************************
Function: change_value
Description: change the value at selected_byte
Parameters: none, use global selected_byte
Return:nothing, but may modify the RAM
*****************************************************************************
void change_value()
{
unsigned X=(((selected_byte&0x04)/4)*2+6+3*(selected_byte&0x07))*8+blit_x,Y=(selected_byte-frame_up)/NB_BYTE_LINE*10+blit_y-1;
char out=0,index=0;
char value[3]="\0\0";
int ch;
do {
rectfill(screen,X,Y,X+16,Y+9,-15);
textout(screen,font,value,X,Y+1,-1);
ch=osd_readkey();
// first switch by scancode
switch (ch>>8)
{
case KEY_ESC:
out=1;
break;
case KEY_ENTER:
RAM[selected_byte]=cvtnum(value);
out=1;
break;
case KEY_BACKSPACE:
if (index)
value[--index]=0;
break;
}
// Now by ascii code
switch (ch&0xff)
{
case '0' ... '9':
case 'a' ... 'f':
case 'A' ... 'F':
if (index<2)
value[index++]=toupper(ch&0xff);
break;
}
} while (!out);
return ;
}
*/
/*****************************************************************************
Function: ram_key
Description: handle the keyboard in edit_ram
Parameters: none
Return: nothing
*****************************************************************************/
void
ram_key ()
{
/* TODO: deallegroize here too */
#ifdef ALLEGRO
int ch = osd_readkey ();
switch (ch >> 8)
{
// The two first are a bit special
case KEY_HOME:
selected_byte = 0;
frame_up = 0;
frame_down = NB_BYTE_LINE * NB_LINE;
return;
case KEY_END:
selected_byte = 0x7FFF;
frame_down = 0x8000;
frame_up = frame_down - NB_BYTE_LINE * NB_LINE;
return;
case KEY_PGUP:
if (selected_byte >= NB_BYTE_LINE * NB_LINE)
selected_byte -= NB_BYTE_LINE * NB_LINE;
break;
case KEY_PGDN:
if (selected_byte <= 0x7FFF - NB_BYTE_LINE * NB_LINE);
selected_byte += NB_BYTE_LINE * NB_LINE;
break;
case KEY_UP:
if (selected_byte >= NB_BYTE_LINE)
selected_byte -= NB_BYTE_LINE;
break;
case KEY_DOWN:
if (selected_byte <= 0x7FFF - NB_BYTE_LINE)
selected_byte += NB_BYTE_LINE;
break;
case KEY_RIGHT:
if (selected_byte < 0x7FFF)
selected_byte++;
break;
case KEY_LEFT:
if (selected_byte)
selected_byte--;
break;
case KEY_SPACE:
{
UInt32 dummy = RAM[selected_byte];
change_value (
(((selected_byte & 0x04) / 4) * 2 + 6 +
3 * (selected_byte & 0x07)) * 8 + blit_x,
(selected_byte - frame_up) / NB_BYTE_LINE * 10 +
blit_y - 1, 2, &dummy);
RAM[selected_byte] = (UChar) dummy;
}
break;
case KEY_F12:
case KEY_ESC:
out = 1;
break;
}
// Now ajust the frame
if ((selected_byte < 3 * NB_BYTE_LINE) ||
(selected_byte > 0x7FFF - 3 * NB_BYTE_LINE))
return;
if (selected_byte >= frame_down - 3 * NB_BYTE_LINE)
{
frame_down = min (0x8000, (selected_byte + 3 * NB_BYTE_LINE) & 0x7FF8);
frame_up = frame_down - NB_BYTE_LINE * NB_LINE;
}
if (selected_byte < frame_up + 3 * NB_BYTE_LINE)
{
frame_up = max (0, (int) ((selected_byte - 3 * NB_BYTE_LINE) & 0x7FF8));
frame_down = frame_up + NB_BYTE_LINE * NB_LINE;
}
return;
#endif
}
/*****************************************************************************
Function: edit_ram
Description: view or edit the RAM
Parameters: none
Return: nothing
*****************************************************************************/
void
edit_ram ()
{
#ifdef ALLEGRO
BITMAP *bg;
unsigned char line, col;
char *tmp_buf = (char *) alloca (100);
unsigned short dum;
bg = create_bitmap (vheight, vwidth);
blit (screen, bg, 0, 0, 0, 0, vheight, vwidth);
selected_byte = 0;
out = 0;
frame_up = 0;
frame_down = frame_up + NB_LINE * NB_BYTE_LINE;
while (!out)
{
clear (screen);
for (line = 0; line < NB_LINE; line++)
{
sprintf (tmp_buf, "%04X", frame_up + line * NB_BYTE_LINE);
textoutshadow (screen, font, tmp_buf, blit_x, blit_y + 10 * line,
-15, 2, 1, 1);
for (col = 0; col < NB_BYTE_LINE / 2; col++)
{
if ((dum = frame_up + line * NB_BYTE_LINE + col) ==
selected_byte)
rectfill (screen, blit_x + (6 + col * 3) * 8,
blit_y + 10 * line - 1, blit_x + (8 + col * 3) * 8,
blit_y + 10 * (line + 1) - 2, -15);
sprintf (tmp_buf, "%02X", RAM[dum]);
textoutshadow (screen, font, tmp_buf,
blit_x + (6 + col * 3) * 8, blit_y + 10 * line,
-1, 2, 1, 1);
}
for (; col < NB_BYTE_LINE; col++)
{
if ((dum = frame_up + line * NB_BYTE_LINE + col) ==
selected_byte)
rectfill (screen, blit_x + (8 + col * 3) * 8,
blit_y + 10 * line - 1, blit_x + (10 + col * 3) * 8,
blit_y + 10 * (line + 1) - 2, -15);
sprintf (tmp_buf, "%02X",
RAM[frame_up + line * NB_BYTE_LINE + col]);
textoutshadow (screen, font, tmp_buf,
blit_x + (8 + col * 3) * 8, blit_y + 10 * line,
-1, 2, 1, 1);
}
}
ram_key ();
vsync ();
}
blit (bg, screen, 0, 0, 0, 0, vheight, vwidth);
destroy_bitmap (bg);
return;
#endif
}