32 static const Uint8 init_ula_palette_rgb[16 * 3] = {
50 static Uint32 ula_palette[16];
51 static Uint32 ulaplus_palette[256];
54 static int contended_memory_t_states;
58 static Uint8 *pix_mem_p[192];
59 static Uint8 *atr_mem_p[192];
60 static unsigned int frame_counter;
61 static int frame_done;
62 static int flash_state;
63 static Uint32 paper_colours[256], ink_colours[256], border_colour;
64 static Uint32 ulaplus_colours[64];
65 static Uint8 ulaplus_ink_index[256], ulaplus_paper_index[256];
71 static void init_ula_tables (
void )
76 for (a = 0; a < 192; a++) {
77 pix_mem_p[a] =
memory + 0x4000 + (((((a >> 3) & 0x18) | (a & 7)) << 8) | (((a >> 3) & 7) << 5));
78 atr_mem_p[a] =
memory + 0x5800 + ((a >> 3) << 5);
83 for (a = 0; a < 128; a++ ) {
84 paper_colours[a] = ink_colours [a + 128] = ula_palette[(a & 120) >> 3];
85 ink_colours [a] = paper_colours[a + 128] = ula_palette[(a & 7) | ((a & 64) >> 3)];
91 for (a = 0; a < 256; a++) {
92 int red = (a >> 2) & 7;
93 int green = (a >> 5) & 7;
94 int blue = ((a & 3) << 1) | ((a & 3) ? 1 : 0);
95 ulaplus_palette[a] = SDL_MapRGBA(
97 (red << 5) | (red << 2) | (red >> 1),
98 (green << 5) | (green << 2) | (green >> 1),
99 (blue << 5) | (blue << 2) | (blue >> 1),
102 ulaplus_ink_index[a] = ((a & 0xC0) >> 2) + (a & 7);
103 ulaplus_paper_index[a] = ((a & 0xC0) >> 2) + ((a >> 3) & 7) + 8;
104 ulaplus_colours[a & 63] = ulaplus_palette[0];
116 if (tstate_x < 128) {
120 Uint32 fg = ink_colours[ad & flash_state];
121 Uint32 bg = paper_colours[ad & flash_state];
122 switch (tstate_x & 3) {
124 *pix++ = pd & 0x80 ? fg : bg;
125 *pix++ = pd & 0x40 ? fg : bg;
128 *pix++ = pd & 0x20 ? fg : bg;
129 *pix++ = pd & 0x10 ? fg : bg;
132 *pix++ = pd & 0x08 ? fg : bg;
133 *pix++ = pd & 0x04 ? fg : bg;
136 *pix++ = pd & 0x02 ? fg : bg;
137 *pix++ = pd & 0x01 ? fg : bg;
141 *pix++ = border_colour;
142 *pix++ = border_colour;
144 }
else if (tstate_x < 128 + 24) {
145 *pix++ = border_colour;
146 *pix++ = border_colour;
147 }
else if (tstate_x < 128 + 24 + 48) {
149 *pix++ = border_colour;
150 *pix++ = border_colour;
158 flash_state = (frame_counter & 16) ? 0xFF : 0x7F;
171 if (contended_memory_t_states & ((
addr & 0xC000) == 0x4000))
185 if (contended_memory_t_states)
215 border_colour = ula_palette[
value & 7];
231 #define VIRTUAL_SHIFT_POS 0x00
246 { SDL_SCANCODE_LSHIFT, 0x00 }, { SDL_SCANCODE_RSHIFT, 0x00},
247 { SDL_SCANCODE_Z, 0x01 },
248 { SDL_SCANCODE_X, 0x02 },
249 { SDL_SCANCODE_C, 0x03 },
250 { SDL_SCANCODE_V, 0x04 },
251 { SDL_SCANCODE_A, 0x10 },
252 { SDL_SCANCODE_S, 0x11 },
253 { SDL_SCANCODE_D, 0x12 },
254 { SDL_SCANCODE_F, 0x13 },
255 { SDL_SCANCODE_G, 0x14 },
256 { SDL_SCANCODE_Q, 0x20 },
257 { SDL_SCANCODE_W, 0x21 },
258 { SDL_SCANCODE_E, 0x22 },
259 { SDL_SCANCODE_R, 0x23 },
260 { SDL_SCANCODE_T, 0x24 },
261 { SDL_SCANCODE_1, 0x30 },
262 { SDL_SCANCODE_2, 0x31 },
263 { SDL_SCANCODE_3, 0x32 },
264 { SDL_SCANCODE_4, 0x33 },
265 { SDL_SCANCODE_5, 0x34 },
266 { SDL_SCANCODE_0, 0x40 },
267 { SDL_SCANCODE_9, 0x41 },
268 { SDL_SCANCODE_8, 0x42 },
269 { SDL_SCANCODE_7, 0x43 },
270 { SDL_SCANCODE_6, 0x44 },
271 { SDL_SCANCODE_P, 0x50 },
272 { SDL_SCANCODE_O, 0x51 },
273 { SDL_SCANCODE_I, 0x52 },
274 { SDL_SCANCODE_U, 0x53 },
275 { SDL_SCANCODE_Y, 0x54 },
276 { SDL_SCANCODE_RETURN, 0x60 },
277 { SDL_SCANCODE_L, 0x61 },
278 { SDL_SCANCODE_K, 0x62 },
279 { SDL_SCANCODE_J, 0x63 },
280 { SDL_SCANCODE_H, 0x64 },
281 { SDL_SCANCODE_SPACE, 0x70 },
282 { SDL_SCANCODE_LCTRL, 0x71 },
283 { SDL_SCANCODE_M, 0x72 },
284 { SDL_SCANCODE_N, 0x73 },
285 { SDL_SCANCODE_B, 0x74 },
308 static void open_new_frame (
void )
314 FATAL(
"FATAL: Xemu texture tail is not zero, but %d", tail);
326 int main (
int argc,
char **argv )
344 init_ula_palette_rgb,
359 if (
xemu_load_file(
configdb.
rom,
memory, 0x4000, 0x4000,
"Selected ROM image cannot be loaded. Without it, Xemu won't work.\nPlease install it, or use the CLI switch -rom to specify one.") < 0)
365 contended_memory_t_states = 0;
384 if (frame_counter & 1)