|
|
1.1 root 1: /* Generator is (c) James Ponder, 1997-2001 http://www.squish.net/generator/ */
2:
3: /* user interface for allegro (15/16 bit) */
4:
1.1.1.2 root 5: /* this part of generator is 'slaved' from the ui-console.c file - only
6: platform specific code is contained here */
7:
1.1 root 8: #include <sys/nearptr.h>
9: #include <stdio.h>
10:
11: #include "generator.h"
12: #include <allegro.h>
13:
14: #include "uip.h"
15: #include "ui.h"
16: #include "ui-console.h"
17: #include "vdp.h"
1.1.1.2 root 18: #include "cpu68k.h"
1.1 root 19: #include "mem68k.h"
20:
21: /*** forward reference declarations ***/
22:
23: /*** static variables ***/
24:
1.1.1.2 root 25: static uint8 uip_vga = 0; /* flag for whether in VGA more or not */
26: static uint8 uip_displaybanknum = 0; /* view this one, write to other one */
27: static BITMAP *uip_bank0; /* first video bank */
28: static BITMAP *uip_bank1; /* second video bank */
29: static BITMAP *uip_writebank; /* current write bank */
30: static uint8 uip_keypoll = 0; /* flag indicating requires polling */
31: static t_uipinfo *uip_uipinfo = NULL; /* uipinfo */
32: static int uip_forceredshift = -1; /* if set, forces red shift position */
33: static int uip_forcegreenshift = -1; /* if set, forces green shift position */
34: static int uip_forceblueshift = -1; /* if set, forces blue shift position */
1.1 root 35:
36: /*** Code ***/
37:
1.1.1.2 root 38: static void uip_keyboardhandler(int scancode)
39: {
1.1 root 40: int press;
41: press = (scancode & 128) ? 0 : 1;
42: scancode = scancode & 127;
43: if (press) {
44: if (scancode == KEY_F1) {
1.1.1.2 root 45: ui_fkeys |= 1 << 1;
1.1 root 46: } else if (scancode == KEY_F2) {
1.1.1.2 root 47: ui_fkeys |= 1 << 2;
1.1 root 48: } else if (scancode == KEY_F3) {
1.1.1.2 root 49: ui_fkeys |= 1 << 3;
1.1 root 50: } else if (scancode == KEY_F4) {
1.1.1.2 root 51: ui_fkeys |= 1 << 4;
1.1 root 52: } else if (scancode == KEY_F5) {
1.1.1.2 root 53: ui_fkeys |= 1 << 5;
1.1 root 54: } else if (scancode == KEY_F6) {
1.1.1.2 root 55: ui_fkeys |= 1 << 6;
1.1 root 56: } else if (scancode == KEY_F7) {
1.1.1.2 root 57: ui_fkeys |= 1 << 7;
1.1 root 58: } else if (scancode == KEY_F8) {
1.1.1.2 root 59: ui_fkeys |= 1 << 8;
1.1 root 60: } else if (scancode == KEY_F9) {
1.1.1.2 root 61: ui_fkeys |= 1 << 9;
1.1 root 62: } else if (scancode == KEY_F10) {
1.1.1.2 root 63: ui_fkeys |= 1 << 10;
1.1 root 64: } else if (scancode == KEY_F11) {
1.1.1.2 root 65: ui_fkeys |= 1 << 11;
1.1 root 66: } else if (scancode == KEY_F12) {
1.1.1.2 root 67: ui_fkeys |= 1 << 12;
1.1 root 68: }
69: }
70: }
71:
72: END_OF_FUNCTION(uip_keyboardhandler);
73:
1.1.1.2 root 74: int uip_init(t_uipinfo * uipinfo)
1.1 root 75: {
76: uip_uipinfo = uipinfo;
77: check_cpu();
78: printf("Initialising %s - %s (%d:%d:%d:%d:%d)\n", allegro_id, cpu_vendor,
1.1.1.2 root 79: cpu_family, cpu_model, cpu_fpu ? 1 : 0, cpu_mmx ? 1 : 0,
80: cpu_3dnow ? 1 : 0);
1.1 root 81: printf("\nNote: Allegro can take at least 5 seconds to quit!\n");
82: sleep(2);
83: if (allegro_init()) {
84: LOG_CRITICAL(("Failed to initialise allegro"));
85: return 1;
86: }
87: LOCK_VARIABLE(ui_info);
88: LOCK_VARIABLE(vdp_overseas);
89: LOCK_VARIABLE(ui_vdpsimple);
90: LOCK_VARIABLE(ui_vsync);
91: LOCK_VARIABLE(ui_clearnext);
92: LOCK_VARIABLE(ui_fullscreen);
93: LOCK_VARIABLE(ui_fkeys);
94: LOCK_FUNCTION(uip_keyboardhandler);
95: return 0;
96: }
97:
1.1.1.2 root 98: int uip_initjoysticks(void)
99: {
100: /* joysticks not supported - yet */
101: return 0;
102: }
103:
1.1 root 104: int uip_vgamode(void)
105: {
106: int depth, rate;
107: unsigned long screenbase;
108:
1.1.1.2 root 109: for (rate = 60; rate <= 70; rate += 10) {
1.1.1.3 ! root 110: for (depth = 15; depth <= 16; depth++) {
1.1 root 111: LOG_VERBOSE(("Trying mode 640x480 depth %d rate %d", depth, rate));
1.1.1.3 ! root 112: set_color_depth(depth);
1.1 root 113: request_refresh_rate(rate);
1.1.1.2 root 114: if ((set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 480 * 2) < 0)) {
1.1 root 115: LOG_VERBOSE(("Mode not supported"));
116: continue;
117: }
118: if (SCREEN_W != 640 || SCREEN_H != 480) {
1.1.1.2 root 119: LOG_CRITICAL(("Screen not approriate for depth %d rate %d",
120: depth, rate));
1.1 root 121: continue;
122: }
123: goto WHEE;
124: }
125: }
126: LOG_CRITICAL(("Failed to find suitable mode"));
127: return 1;
1.1.1.2 root 128: WHEE:
1.1 root 129: uip_vga = 1;
130: if (uip_forceredshift != -1 && uip_forcegreenshift != -1 &&
131: uip_forceblueshift != -1) {
132: uip_uipinfo->redshift = uip_forceredshift;
133: uip_uipinfo->greenshift = uip_forcegreenshift;
134: uip_uipinfo->blueshift = uip_forceblueshift;
135: } else {
1.1.1.2 root 136: uip_uipinfo->redshift = ui_topbit(makecol(255, 0, 0)) - 4;
137: uip_uipinfo->greenshift = ui_topbit(makecol(0, 255, 0)) - 4;
138: uip_uipinfo->blueshift = ui_topbit(makecol(0, 0, 255)) - 4;
1.1 root 139: }
140: if ((uip_bank0 = create_video_bitmap(640, 480)) == NULL ||
141: (uip_bank1 = create_video_bitmap(640, 480)) == NULL) {
142: uip_textmode();
143: LOG_CRITICAL(("Failed to allocate memory pages"));
144: return 1;
145: }
146: if (is_linear_bitmap(uip_bank0) == 0 ||
147: is_linear_bitmap(uip_bank1) == 0 ||
1.1.1.2 root 148: is_video_bitmap(uip_bank0) == 0 || is_video_bitmap(uip_bank1) == 0) {
1.1 root 149: uip_textmode();
150: LOG_CRITICAL(("Allocated bitmaps not suitable or linear addressing mode "
1.1.1.2 root 151: "not supported by hardware"));
1.1 root 152: return 1;
153: }
154: /* don't you just hate MS platforms? */
155: __djgpp_nearptr_enable();
156: __dpmi_get_segment_base_address(uip_bank0->seg, &screenbase);
157: uip_uipinfo->screenmem0 = (uint8 *)(screenbase + uip_bank0->line[0] -
1.1.1.2 root 158: __djgpp_base_address);
1.1 root 159: __dpmi_get_segment_base_address(uip_bank1->seg, &screenbase);
160: uip_uipinfo->screenmem1 = (uint8 *)(screenbase + uip_bank1->line[0] -
1.1.1.2 root 161: __djgpp_base_address);
162: uip_uipinfo->linewidth = 2 * VIRTUAL_W; /* 16 bit */
163: uip_displaybank(0); /* set current to 0th bank */
164: uip_clearscreen(); /* clear bank */
165: ui_setupscreen(); /* setup bank */
166: uip_displaybank(-1); /* toggle bank */
167: uip_clearscreen(); /* clear bank */
168: ui_setupscreen(); /* setup bank */
1.1 root 169: if (install_keyboard() == -1) {
170: uip_textmode();
171: LOG_CRITICAL(("Unable to initialise keyboard"));
172: return 1;
173: }
174: if (uip_bank0->y_ofs != 0 || uip_bank1->y_ofs != 480) {
175: uip_textmode();
176: LOG_CRITICAL(("sorry, I don't understand this video layout"));
177: return 1;
178: }
179: keyboard_lowlevel_callback = uip_keyboardhandler;
1.1.1.2 root 180: uip_keypoll = keyboard_needs_poll()? 1 : 0;
1.1 root 181: return 0;
182: }
183:
184: int uip_setcolourbits(int red, int green, int blue)
185: {
186: uip_forceredshift = red;
187: uip_forcegreenshift = green;
188: uip_forceblueshift = blue;
189: return 0;
190: }
191:
1.1.1.2 root 192: void uip_displaybank(int bank)
193: {
1.1 root 194: if (bank == -1)
195: bank = uip_displaybanknum ^ 1;
196: uip_writebank = bank ? uip_bank0 : uip_bank1;
197: if (show_video_bitmap(bank ? uip_bank1 : uip_bank0))
198: ui_err("Failed to page flip");
199: uip_uipinfo->screenmem_w = bank ? uip_uipinfo->screenmem0 :
200: uip_uipinfo->screenmem1;
201: uip_displaybanknum = bank;
202: }
203:
1.1.1.2 root 204: void uip_clearscreen(void)
205: {
1.1 root 206: int y;
207:
208: for (y = 0; y < 480; y++) {
1.1.1.2 root 209: memset(uip_uipinfo->screenmem_w + uip_uipinfo->linewidth * y, 0, 640 * 2);
1.1 root 210: }
211: }
212:
1.1.1.2 root 213: void uip_clearmiddle(void)
214: {
1.1 root 215: int i;
216:
217: for (i = 0; i < 240; i++) {
1.1.1.2 root 218: memset(uip_uipinfo->screenmem_w +
219: (uip_uipinfo->linewidth) * (120 + i) + 160 * 2, 0, 2 * 320);
1.1 root 220: }
221: }
222:
223: /* uip_singlebank sets write address to the current display screen */
224:
1.1.1.2 root 225: void uip_singlebank(void)
226: {
1.1 root 227: uip_uipinfo->screenmem_w = uip_displaybanknum ? uip_uipinfo->screenmem1 :
228: uip_uipinfo->screenmem0;
229: }
230:
231: /* uip_doublebank sets write address to hidden display screen */
232:
1.1.1.2 root 233: void uip_doublebank(void)
234: {
1.1 root 235: uip_uipinfo->screenmem_w = uip_displaybanknum ? uip_uipinfo->screenmem0 :
236: uip_uipinfo->screenmem1;
237: }
238:
239: void uip_textmode(void)
240: {
241: if (uip_vga) {
242: remove_keyboard();
243: set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
244: }
245: uip_vga = 0;
246: }
247:
248: int uip_checkkeyboard(void)
249: {
1.1.1.2 root 250: int pad;
251: int joystick;
252:
1.1 root 253: if (uip_keypoll)
254: poll_keyboard();
1.1.1.2 root 255:
256: for (pad = 0; pad < 2; pad++) {
257: if ((joystick = ui_bindings[pad].joystick) >= 0) {
258: /* not supported - yet */
259: } else {
260: switch (ui_bindings[pad].keyboard) {
261: case 0: /* main keys */
262: mem68k_cont[pad].a = key[KEY_A] ? 1 : 0;
263: mem68k_cont[pad].b = (key[KEY_B] ||
264: key[KEY_S]) ? 1 : 0;
265: mem68k_cont[pad].c = (key[KEY_C] ||
266: key[KEY_D]) ? 1 : 0;
267: mem68k_cont[pad].left = key[KEY_LEFT] ? 1 : 0;
268: mem68k_cont[pad].up = key[KEY_UP] ? 1 : 0;
269: mem68k_cont[pad].right = key[KEY_RIGHT] ? 1 : 0;
270: mem68k_cont[pad].down = key[KEY_DOWN] ? 1 : 0;
271: mem68k_cont[pad].start = key[KEY_ENTER] ? 1 : 0;
272: break;
273: case 1: /* left side of keyboard */
274: mem68k_cont[pad].a = key[KEY_Z] ? 1 : 0;
275: mem68k_cont[pad].b = key[KEY_X] ? 1 : 0;
276: mem68k_cont[pad].c = key[KEY_C] ? 1 : 0;
277: mem68k_cont[pad].left = key[KEY_D] ? 1 : 0;
278: mem68k_cont[pad].up = key[KEY_R] ? 1 : 0;
279: mem68k_cont[pad].right = key[KEY_G] ? 1 : 0;
280: mem68k_cont[pad].down = key[KEY_F] ? 1 : 0;
281: mem68k_cont[pad].start = key[KEY_V] ? 1 : 0;
282: break;
283: case 2: /* right side of keyboard */
284: mem68k_cont[pad].a = key[KEY_COMMA] ? 1 : 0;
285: mem68k_cont[pad].b = key[KEY_STOP] ? 1 : 0;
286: mem68k_cont[pad].c = key[KEY_SLASH] ? 1 : 0;
287: mem68k_cont[pad].left = key[KEY_LEFT] ? 1 : 0;
288: mem68k_cont[pad].up = key[KEY_UP] ? 1 : 0;
289: mem68k_cont[pad].right = key[KEY_RIGHT] ? 1 : 0;
290: mem68k_cont[pad].down = key[KEY_DOWN] ? 1 : 0;
291: mem68k_cont[pad].start = key[KEY_ENTER] ? 1 : 0;
292: break;
293: }
294: }
295: }
1.1 root 296: return (key[KEY_ESC] ? 1 : 0);
297: }
298:
299: unsigned int uip_whichbank(void)
300: {
301: /* returns 0 or 1 - the bank being VIEWED */
302: return uip_displaybanknum;
303: }
304:
305: void uip_vsync(void)
306: {
307: vsync();
308: }
309:
310: uint8 uip_getchar(void)
311: {
312: char c;
313:
314: keyboard_lowlevel_callback = NULL;
315: c = readkey() & 0xff;
316: keyboard_lowlevel_callback = uip_keyboardhandler;
317: return c;
318: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.