1 /*************************************************************************/
2 /* */
3 /* Zero Page viewer source file */
4 /* */
5 /* A few functions to view Zero page */
6 /* */
7 /*************************************************************************/
8
9 #include "view_zp.h"
10
11 #define NB_BYTE_LINE 8
12 // Number of byte displayed on each line
13
14 #define NB_LINE 20
15 // Number of displayed lines
16
17 #ifdef ALLEGRO
18 static char out;
19 // To know whether we got to quit
20
21 static int frame_up, frame_down;
22 // The currently displayed "frame" in RAM
23
24 static unsigned short selected_byte;
25 // The current offset
26 #endif
27
28
29 /*****************************************************************************
30
31 Function: zp_key
32
33 Description: handle the keyboard in view_zp
34 Parameters: none
35 Return: nothing
36
37 *****************************************************************************/
38 void
zp_key()39 zp_key ()
40 {
41 #ifdef ALLEGRO
42 int ch = osd_readkey ();
43
44 /* TODO: we can easily handle this without allegro defines */
45
46 switch (ch >> 8)
47 {
48 // The two first are a bit special
49 case KEY_HOME:
50 selected_byte = 0;
51 frame_up = 0;
52 frame_down = NB_BYTE_LINE * NB_LINE;
53 return;
54 case KEY_END:
55 selected_byte = 0xFF;
56 frame_down = 0x100;
57 frame_up = frame_down - NB_BYTE_LINE * NB_LINE;
58 return;
59 case KEY_PGUP:
60 if (selected_byte >= NB_BYTE_LINE * NB_LINE)
61 selected_byte -= NB_BYTE_LINE * NB_LINE;
62 break;
63 case KEY_PGDN:
64 if (selected_byte <= 0xFF - NB_BYTE_LINE * NB_LINE);
65 selected_byte += NB_BYTE_LINE * NB_LINE;
66 break;
67 case KEY_UP:
68 if (selected_byte >= NB_BYTE_LINE)
69 selected_byte -= NB_BYTE_LINE;
70 break;
71 case KEY_DOWN:
72 if (selected_byte <= 0xFF - NB_BYTE_LINE)
73 selected_byte += NB_BYTE_LINE;
74 break;
75 case KEY_RIGHT:
76 if (selected_byte < 0xFF)
77 selected_byte++;
78 break;
79 case KEY_LEFT:
80 if (selected_byte)
81 selected_byte--;
82 break;
83 case KEY_F12:
84 case KEY_ESC:
85 out = 1;
86 break;
87 }
88
89 // Now ajust the frame
90 if ((selected_byte < 3 * NB_BYTE_LINE) ||
91 (selected_byte > 0xFF - 3 * NB_BYTE_LINE))
92 return;
93
94 if (selected_byte >= frame_down - 3 * NB_BYTE_LINE)
95 {
96 frame_down = min (0x100, (selected_byte + 3 * NB_BYTE_LINE) & 0xF8);
97 frame_up = frame_down - NB_BYTE_LINE * NB_LINE;
98 }
99
100 if (selected_byte < frame_up + 3 * NB_BYTE_LINE)
101 {
102 frame_up = max (0, (int) ((selected_byte - 3 * NB_BYTE_LINE) & 0xF8));
103 frame_down = frame_up + NB_BYTE_LINE * NB_LINE;
104 }
105
106 return;
107
108 #endif
109
110 }
111
112 /*****************************************************************************
113
114 Function: view_zp
115
116 Description: view the Zero Page
117 Parameters: none
118 Return: nothing
119
120 *****************************************************************************/
121 void
view_zp()122 view_zp ()
123 {
124
125 #ifdef ALLEGRO
126 BITMAP *bg;
127 unsigned char line, col;
128 char *tmp_buf = (char *) alloca (100);
129 unsigned short dum;
130
131 bg = create_bitmap (vheight, vwidth);
132 blit (screen, bg, 0, 0, 0, 0, vheight, vwidth);
133
134 selected_byte = 0;
135 out = 0;
136 frame_up = 0;
137 frame_down = frame_up + NB_LINE * NB_BYTE_LINE;
138
139 while (!out)
140 {
141 clear (screen);
142 for (line = 0; line < NB_LINE; line++)
143 {
144 sprintf (tmp_buf, "%04X", frame_up + line * NB_BYTE_LINE);
145 textoutshadow (screen, font, tmp_buf, blit_x, blit_y + 10 * line,
146 -15, 2, 1, 1);
147 for (col = 0; col < NB_BYTE_LINE / 2; col++)
148 {
149 if ((dum = frame_up + line * NB_BYTE_LINE + col) ==
150 selected_byte)
151 rectfill (screen, blit_x + (6 + col * 3) * 8,
152 blit_y + 10 * line - 1, blit_x + (8 + col * 3) * 8,
153 blit_y + 10 * (line + 1) - 2, -15);
154 sprintf (tmp_buf, "%02X", Op6502 (0x2000 + dum));
155 textoutshadow (screen, font, tmp_buf,
156 blit_x + (6 + col * 3) * 8, blit_y + 10 * line,
157 -1, 2, 1, 1);
158 }
159 for (; col < NB_BYTE_LINE; col++)
160 {
161 if ((dum = frame_up + line * NB_BYTE_LINE + col) ==
162 selected_byte)
163 rectfill (screen, blit_x + (8 + col * 3) * 8,
164 blit_y + 10 * line - 1, blit_x + (10 + col * 3) * 8,
165 blit_y + 10 * (line + 1) - 2, -15);
166 sprintf (tmp_buf, "%02X", Op6502 (0x2000 + dum));
167 textoutshadow (screen, font, tmp_buf,
168 blit_x + (8 + col * 3) * 8, blit_y + 10 * line,
169 -1, 2, 1, 1);
170 }
171
172 }
173
174 zp_key ();
175 vsync ();
176 }
177
178 blit (bg, screen, 0, 0, 0, 0, vheight, vwidth);
179 destroy_bitmap (bg);
180 return;
181 #endif
182
183 }
184