|
|
1.1 root 1: /* Generator is (c) James Ponder, 1997-2001 http://www.squish.net/generator/ */
2:
3: /* user interface for svgalib (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 <stdio.h>
9: #include <unistd.h>
10:
11: #include "generator.h"
12: #include <vga.h>
13: #include <vgakeyboard.h>
1.1.1.2 root 14: #include <vgajoystick.h>
1.1 root 15:
16: #include "uip.h"
17: #include "ui.h"
18: #include "ui-console.h"
19: #include "vdp.h"
1.1.1.2 root 20: #include "cpu68k.h"
1.1 root 21: #include "mem68k.h"
22:
23: #define BANKSIZE 640*480*2
24:
25: /*** forward reference declarations ***/
26:
27: /*** static variables ***/
28:
1.1.1.2 root 29: static uint8 uip_vga = 0; /* flag for whether in VGA mode */
30: static uint8 uip_key[256]; /* keyboard state */
31: static uint8 uip_displaybanknum = 0; /* view this one, write to other one */
32: static t_uipinfo *uip_uipinfo = NULL; /* uipinfo */
33: static int uip_forceredshift = -1; /* if set, forces red shift pos */
34: static int uip_forcegreenshift = -1; /* if set, forces green shift pos */
35: static int uip_forceblueshift = -1; /* if set, forces blue shift pos */
1.1 root 36:
37: /*** Code ***/
38:
1.1.1.2 root 39: static void uip_keyboardhandler(int scancode, int press)
40: {
1.1 root 41: if (scancode >= 256)
42: return;
43: if (uip_key[scancode] == press)
44: return;
45: uip_key[scancode] = press;
46: if (press) {
47: if (scancode == SCANCODE_F1) {
1.1.1.2 root 48: ui_fkeys |= 1 << 1;
1.1 root 49: } else if (scancode == SCANCODE_F2) {
1.1.1.2 root 50: ui_fkeys |= 1 << 2;
1.1 root 51: } else if (scancode == SCANCODE_F3) {
1.1.1.2 root 52: ui_fkeys |= 1 << 3;
1.1 root 53: } else if (scancode == SCANCODE_F4) {
1.1.1.2 root 54: ui_fkeys |= 1 << 4;
1.1 root 55: } else if (scancode == SCANCODE_F5) {
1.1.1.2 root 56: ui_fkeys |= 1 << 5;
1.1 root 57: } else if (scancode == SCANCODE_F6) {
1.1.1.2 root 58: ui_fkeys |= 1 << 6;
1.1 root 59: } else if (scancode == SCANCODE_F7) {
1.1.1.2 root 60: ui_fkeys |= 1 << 7;
1.1 root 61: } else if (scancode == SCANCODE_F8) {
1.1.1.2 root 62: ui_fkeys |= 1 << 8;
1.1 root 63: } else if (scancode == SCANCODE_F9) {
1.1.1.2 root 64: ui_fkeys |= 1 << 9;
1.1 root 65: } else if (scancode == SCANCODE_F10) {
1.1.1.2 root 66: ui_fkeys |= 1 << 10;
1.1 root 67: } else if (scancode == SCANCODE_F11) {
1.1.1.2 root 68: ui_fkeys |= 1 << 11;
1.1 root 69: } else if (scancode == SCANCODE_F12) {
1.1.1.2 root 70: ui_fkeys |= 1 << 12;
1.1 root 71: }
72: }
73: }
74:
1.1.1.2 root 75: int uip_init(t_uipinfo * uipinfo)
1.1 root 76: {
77: uip_uipinfo = uipinfo;
1.1.1.2 root 78: LOG_REQUEST(("Initialising svgalib..."));
1.1 root 79: sleep(1);
80: if (vga_init()) {
81: LOG_CRITICAL(("Failed to initialise SVGALib"));
82: return 1;
83: }
84: return 0;
85: }
86:
1.1.1.2 root 87: int uip_initjoysticks(void)
88: {
89: LOG_REQUEST(("Checking for svgalib joysticks..."));
90: if (joystick_init(0, JOY_CALIB_STDOUT) < 0) {
91: LOG_VERBOSE(("Joystick 0 not found"));
92: return 0;
93: }
94: LOG_NORMAL(("Joystick 0 initialised"));
95: if (joystick_init(1, JOY_CALIB_STDOUT) < 0) {
96: LOG_VERBOSE(("Joystick 1 not found"));
97: return 1;
98: }
99: LOG_NORMAL(("Joystick 1 initialised"));
100: return 2;
101: }
102:
1.1 root 103: int uip_vgamode(void)
104: {
105: vga_modeinfo *modeinfo;
106:
107: uip_vga = 1;
108: if (vga_setmode(G640x480x32K) == -1) {
109: LOG_CRITICAL(("640x480 @ 32K colours not supported by hardware"));
110: LOG_CRITICAL(("Trying 640x480 @ 64K colours..."));
111: if (vga_setmode(G640x480x64K) == -1) {
112: LOG_CRITICAL(("640x480 @ 64K colours not supported by hardware"));
113: uip_textmode();
114: LOG_CRITICAL(("Unable to change SVGA mode, mode not supported by "
1.1.1.2 root 115: "hardware?"));
1.1 root 116: LOG_CRITICAL(("Check /etc/vga/libvga.config to ensure your card "
1.1.1.2 root 117: "is not commented out"));
1.1 root 118: return 1;
119: }
120: }
1.1.1.2 root 121: if (vga_claimvideomemory(2 * BANKSIZE) == -1) {
1.1 root 122: uip_textmode();
123: LOG_CRITICAL(("Unable to allocated video memory - 2MB video card "
1.1.1.2 root 124: "required."));
1.1 root 125: return 1;
126: }
127: if ((modeinfo = vga_getmodeinfo(vga_getcurrentmode())) == NULL) {
128: uip_textmode();
129: LOG_CRITICAL(("Unable to get current mode information"));
130: return 1;
131: }
132: LOG_VERBOSE(("Resolution %dx%d bytesperpixel %d linewidth %d",
1.1.1.2 root 133: modeinfo->width, modeinfo->height, modeinfo->bytesperpixel,
134: modeinfo->linewidth));
1.1 root 135: if (modeinfo->width != 640 || modeinfo->height != 480 ||
1.1.1.2 root 136: modeinfo->bytesperpixel != 2 || modeinfo->linewidth * 480 > BANKSIZE ||
1.1 root 137: (modeinfo->startaddressrange & BANKSIZE) != BANKSIZE) {
138: uip_textmode();
139: LOG_CRITICAL(("Unexpected mode settings"));
140: return 1;
141: }
142: uip_uipinfo->linewidth = modeinfo->linewidth;
143: if (vga_setlinearaddressing() == -1) {
144: uip_textmode();
145: LOG_CRITICAL(("Linear addressing mode not supported by hardware"));
146: return 1;
147: }
148: if ((uip_uipinfo->screenmem0 = vga_getgraphmem()) == NULL) {
149: uip_textmode();
150: LOG_CRITICAL(("Failed to find start of screen memory"));
151: return 1;
152: }
1.1.1.2 root 153: uip_uipinfo->screenmem1 = uip_uipinfo->screenmem0 + BANKSIZE;
1.1 root 154: if (uip_forceredshift != -1 && uip_forcegreenshift != -1 &&
155: uip_forceblueshift != -1) {
156: uip_uipinfo->redshift = uip_forceredshift;
157: uip_uipinfo->greenshift = uip_forcegreenshift;
158: uip_uipinfo->blueshift = uip_forceblueshift;
159: } else {
160: switch (modeinfo->colors) {
161: case 32768:
162: LOG_VERBOSE(("Assuming colour bit positions 10,5,0 for 32k colour mode"));
163: uip_uipinfo->blueshift = 0;
164: uip_uipinfo->greenshift = 5;
165: uip_uipinfo->redshift = 10;
166: break;
167: case 65536:
168: LOG_VERBOSE(("Assuming colour bit positions 11,6,0 for 64k colour mode"));
169: uip_uipinfo->blueshift = 0;
170: uip_uipinfo->greenshift = 6;
171: uip_uipinfo->redshift = 11;
172: break;
173: default:
174: LOG_CRITICAL(("Unknown mode - %d colours?? use -c", modeinfo->colors));
175: return 1;
176: }
177: }
1.1.1.2 root 178: uip_displaybank(0); /* set current to 0th bank */
179: uip_clearscreen(); /* clear bank */
180: ui_setupscreen(); /* setup bank */
181: uip_displaybank(-1); /* toggle bank */
182: uip_clearscreen(); /* clear bank */
183: ui_setupscreen(); /* setup bank */
1.1 root 184: if (keyboard_init() == -1) {
185: uip_textmode();
186: LOG_CRITICAL(("Unable to initialise keyboard"));
187: return 1;
188: }
189: memset(uip_key, 0, sizeof(uip_key));
190: keyboard_seteventhandler(uip_keyboardhandler);
191: return 0;
192: }
193:
194: int uip_setcolourbits(int red, int green, int blue)
195: {
196: uip_forceredshift = red;
197: uip_forcegreenshift = green;
198: uip_forceblueshift = blue;
199: return 0;
200: }
201:
1.1.1.2 root 202: void uip_displaybank(int bank)
203: {
1.1 root 204: if (bank == -1)
205: bank = uip_displaybanknum ^ 1;
206: vga_setdisplaystart(bank ? BANKSIZE : 0);
207: uip_uipinfo->screenmem_w = bank ? uip_uipinfo->screenmem0 :
208: uip_uipinfo->screenmem1;
209: uip_displaybanknum = bank;
210: }
211:
1.1.1.2 root 212: void uip_clearscreen(void)
213: {
1.1 root 214: memset(uip_uipinfo->screenmem_w, 0, BANKSIZE);
215: }
216:
1.1.1.2 root 217: void uip_clearmiddle(void)
218: {
1.1 root 219: int i;
220:
221: for (i = 0; i < 240; i++) {
1.1.1.2 root 222: memset(uip_uipinfo->screenmem_w +
223: (uip_uipinfo->linewidth) * (120 + i) + 160 * 2, 0, 2 * 320);
1.1 root 224: }
225: }
226:
227: /* uip_singlebank sets write address to the current display screen */
228:
1.1.1.2 root 229: void uip_singlebank(void)
230: {
1.1 root 231: uip_uipinfo->screenmem_w = uip_displaybanknum ? uip_uipinfo->screenmem1 :
232: uip_uipinfo->screenmem0;
233: }
234:
235: /* uip_doublebank sets write address to hidden display screen */
236:
1.1.1.2 root 237: void uip_doublebank(void)
238: {
1.1 root 239: uip_uipinfo->screenmem_w = uip_displaybanknum ? uip_uipinfo->screenmem0 :
240: uip_uipinfo->screenmem1;
241: }
242:
243: void uip_textmode(void)
244: {
245: if (uip_vga) {
246: keyboard_setdefaulteventhandler();
247: vga_setmode(0);
248: }
249: uip_vga = 0;
250: }
251:
252: int uip_checkkeyboard(void)
253: {
1.1.1.2 root 254: int x, y;
255: int pad;
256: int joystick;
257:
258: joystick_update();
1.1 root 259: keyboard_update();
1.1.1.2 root 260: for (pad = 0; pad < 2; pad++) {
261: if ((joystick = ui_bindings[pad].joystick) >= 0) {
262: x = joystick_getaxis(joystick, 0);
263: y = joystick_getaxis(joystick, 1);
264: mem68k_cont[pad].a = joystick_getbutton(joystick, 0);
265: mem68k_cont[pad].b = joystick_getbutton(joystick, 1);
266: mem68k_cont[pad].c = joystick_getbutton(joystick, 2);
267: mem68k_cont[pad].start = joystick_getbutton(joystick, 3);
268: mem68k_cont[pad].left = x < -64 ? 1 : 0;
269: mem68k_cont[pad].right = x > 64 ? 1 : 0;
270: mem68k_cont[pad].up = y < -64 ? 1 : 0;
271: mem68k_cont[pad].down = y > 64 ? 1 : 0;
272: } else {
273: switch (ui_bindings[pad].keyboard) {
274: case 0: /* main keys */
275: mem68k_cont[pad].a = uip_key[SCANCODE_A] ? 1 : 0;
276: mem68k_cont[pad].b = (uip_key[SCANCODE_B] ||
277: uip_key[SCANCODE_S]) ? 1 : 0;
278: mem68k_cont[pad].c = (uip_key[SCANCODE_C] ||
279: uip_key[SCANCODE_D]) ? 1 : 0;
280: mem68k_cont[pad].left = uip_key[SCANCODE_CURSORBLOCKLEFT] ? 1 : 0;
281: mem68k_cont[pad].up = uip_key[SCANCODE_CURSORBLOCKUP] ? 1 : 0;
282: mem68k_cont[pad].right = uip_key[SCANCODE_CURSORBLOCKRIGHT] ? 1 : 0;
283: mem68k_cont[pad].down = uip_key[SCANCODE_CURSORBLOCKDOWN] ? 1 : 0;
284: mem68k_cont[pad].start = uip_key[SCANCODE_ENTER] ? 1 : 0;
285: break;
286: case 1: /* left side of keyboard */
287: mem68k_cont[pad].a = uip_key[SCANCODE_Z] ? 1 : 0;
288: mem68k_cont[pad].b = uip_key[SCANCODE_X] ? 1 : 0;
289: mem68k_cont[pad].c = uip_key[SCANCODE_C] ? 1 : 0;
290: mem68k_cont[pad].left = uip_key[SCANCODE_D] ? 1 : 0;
291: mem68k_cont[pad].up = uip_key[SCANCODE_R] ? 1 : 0;
292: mem68k_cont[pad].right = uip_key[SCANCODE_G] ? 1 : 0;
293: mem68k_cont[pad].down = uip_key[SCANCODE_F] ? 1 : 0;
294: mem68k_cont[pad].start = uip_key[SCANCODE_V] ? 1 : 0;
295: break;
296: case 2: /* right side of keyboard */
297: mem68k_cont[pad].a = uip_key[SCANCODE_COMMA] ? 1 : 0;
298: mem68k_cont[pad].b = uip_key[SCANCODE_PERIOD] ? 1 : 0;
299: mem68k_cont[pad].c = uip_key[SCANCODE_SLASH] ? 1 : 0;
300: mem68k_cont[pad].left = uip_key[SCANCODE_CURSORBLOCKLEFT] ? 1 : 0;
301: mem68k_cont[pad].up = uip_key[SCANCODE_CURSORBLOCKUP] ? 1 : 0;
302: mem68k_cont[pad].right = uip_key[SCANCODE_CURSORBLOCKRIGHT] ? 1 : 0;
303: mem68k_cont[pad].down = uip_key[SCANCODE_CURSORBLOCKDOWN] ? 1 : 0;
304: mem68k_cont[pad].start = uip_key[SCANCODE_ENTER] ? 1 : 0;
305: break;
306: }
307: }
308: }
1.1 root 309: return (uip_key[SCANCODE_ESCAPE] ? 1 : 0);
310: }
311:
312: void uip_vsync(void)
313: {
314: vga_waitretrace();
315: }
316:
317: unsigned int uip_whichbank(void)
318: {
319: /* returns 0 or 1 - the bank being VIEWED */
320: return uip_displaybanknum;
321: }
322:
323: uint8 uip_getchar(void)
324: {
325: char c;
326:
327: keyboard_setdefaulteventhandler();
328: keyboard_close();
329: c = getchar();
330: keyboard_init();
331: memset(uip_key, 0, sizeof(uip_key));
332: keyboard_seteventhandler(uip_keyboardhandler);
333: return c;
334: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.