|
|
1.1 root 1: /*****************************************************************************/
2: /* Generator - Sega Genesis emulation - (c) James Ponder 1997-2000 */
3: /*****************************************************************************/
4: /* */
5: /* uip-svgalib - User interface for svgalib (15 bit) */
6: /* */
7: /*****************************************************************************/
8:
9: #include <stdio.h>
10: #include <unistd.h>
11:
12: #include "generator.h"
13: #include <vga.h>
14: #include <vgakeyboard.h>
15:
16: #include "uip.h"
17: #include "ui.h"
18: #include "ui-console.h"
19: #include "vdp.h"
20: #include "mem68k.h"
21:
22: #define BANKSIZE 640*480*2
23:
24: /*** forward reference declarations ***/
25:
26: /*** static variables ***/
27:
28: static uint8 uip_vga = 0; /* flag for whether in VGA more or not */
29: static uint8 uip_displaybanknum = 0; /* view this one, write to other one */
30: static t_uipinfo *uip_uipinfo = NULL; /* uipinfo */
31: static uint8 uip_key[256]; /* keyboard state */
32:
33: /*** Code ***/
34:
35: static void uip_keyboardhandler(int scancode, int press) {
36: if (scancode >= 256)
37: return;
38: if (uip_key[scancode] == press)
39: return;
40: uip_key[scancode] = press;
41: if (press) {
42: if (scancode == SCANCODE_F5) {
43: ui_info^= 1;
44: ui_clearnext = 2;
45: } else if (scancode == SCANCODE_F6) {
46: vdp_pal^= 1;
47: vdp_setupvideo();
48: ui_clearnext = 2;
49: } else if (scancode == SCANCODE_F7) {
50: vdp_overseas^= 1;
51: ui_clearnext = 2;
52: } else if (scancode == SCANCODE_F8) {
53: ui_vdpsimple^= 1;
54: ui_clearnext = 2;
55: } else if (scancode == SCANCODE_F9) {
56: ui_vsync^= 1;
57: ui_clearnext = 2;
58: } else if (scancode == SCANCODE_1) {
59: vdp_layerB^= 1;
60: ui_clearnext = 2;
61: } else if (scancode == SCANCODE_2) {
62: vdp_layerBp^= 1;
63: ui_clearnext = 2;
64: } else if (scancode == SCANCODE_3) {
65: vdp_layerA^= 1;
66: ui_clearnext = 2;
67: } else if (scancode == SCANCODE_4) {
68: vdp_layerAp^= 1;
69: ui_clearnext = 2;
70: } else if (scancode == SCANCODE_5) {
71: vdp_layerW^= 1;
72: ui_clearnext = 2;
73: } else if (scancode == SCANCODE_6) {
74: vdp_layerWp^= 1;
75: ui_clearnext = 2;
76: } else if (scancode == SCANCODE_7) {
77: vdp_layerH^= 1;
78: ui_clearnext = 2;
79: } else if (scancode == SCANCODE_8) {
80: vdp_layerS^= 1;
81: ui_clearnext = 2;
82: } else if (scancode == SCANCODE_9) {
83: vdp_layerSp^= 1;
84: ui_clearnext = 2;
85: }
86: /*
87: {
88: FILE *moo;
89: int i;
90: moo = fopen("/tmp/screenshot.raw", "w");
91: for (i = 0; i < 640*480; i++) {
92: fputc(((((uint16 *)uip_uipinfo.screenmem)[i]>>10) & 0x1f)<<3, moo);
93: fputc(((((uint16 *)uip_uipinfo.screenmem)[i]>>5) & 0x1f)<<3, moo);
94: fputc(((((uint16 *)uip_uipinfo.screenmem)[i]>>0) & 0x1f)<<3, moo);
95: }
96: fclose(moo);
97: }
98: */
99: }
100: }
101:
102: int uip_init(t_uipinfo *uipinfo)
103: {
104: uip_uipinfo = uipinfo;
105: printf("Initialising svgalib...\n");
106: sleep(1);
107: if (vga_init()) {
108: LOG_CRITICAL(("Failed to initialise SVGALib"));
109: return 1;
110: }
111: return 0;
112: }
113:
114: int uip_vgamode(void)
115: {
116: vga_modeinfo *modeinfo;
117: int cardmemory;
118:
119: uip_vga = 1;
120: if (vga_setmode(G640x480x32K) == -1) {
121: uip_textmode();
122: LOG_CRITICAL(("Unable to change SVGA mode, mode not supported by "
123: "hardware?"));
124: LOG_CRITICAL(("Check /etc/vga/libvga.config to ensure your card "
125: "is not commented out"));
126: return 1;
127: }
128: if (vga_claimvideomemory(2*BANKSIZE) == -1) {
129: uip_textmode();
130: LOG_CRITICAL(("Unable to allocated video memory - 2MB video card "
131: "required."));
132: return 1;
133: }
134: if ((modeinfo = vga_getmodeinfo(vga_getcurrentmode())) == NULL) {
135: uip_textmode();
136: LOG_CRITICAL(("Unable to get current mode information"));
137: return 1;
138: }
139: LOG_VERBOSE(("Resolution %dx%d bytesperpixel %d linewidth %d",
140: modeinfo->width, modeinfo->height, modeinfo->bytesperpixel,
141: modeinfo->linewidth));
142: if (modeinfo->width != 640 || modeinfo->height != 480 ||
143: modeinfo->bytesperpixel != 2 || modeinfo->linewidth*480 > BANKSIZE ||
144: (modeinfo->startaddressrange & BANKSIZE) != BANKSIZE) {
145: uip_textmode();
146: LOG_CRITICAL(("Unexpected mode settings"));
147: return 1;
148: }
149: uip_uipinfo->linewidth = modeinfo->linewidth;
150: uip_uipinfo->redshift = 0;
151: uip_uipinfo->greenshift = 5;
152: uip_uipinfo->redshift = 10;
153: if (vga_setlinearaddressing() == -1) {
154: uip_textmode();
155: LOG_CRITICAL(("Linear addressing mode not supported by hardware"));
156: return 1;
157: }
158: if ((uip_uipinfo->screenmem0 = vga_getgraphmem()) == NULL) {
159: uip_textmode();
160: LOG_CRITICAL(("Failed to find start of screen memory"));
161: return 1;
162: }
163: uip_uipinfo->screenmem1 = uip_uipinfo->screenmem0+BANKSIZE;
164: uip_displaybank(0); /* set current to 0th bank */
165: uip_clearscreen(); /* clear bank */
166: ui_setupscreen(); /* setup bank */
167: uip_displaybank(-1); /* toggle bank */
168: uip_clearscreen(); /* clear bank */
169: ui_setupscreen(); /* setup bank */
170: if (keyboard_init() == -1) {
171: uip_textmode();
172: LOG_CRITICAL(("Unable to initialise keyboard"));
173: return 1;
174: }
175: memset(uip_key, 0, sizeof(uip_key));
176: keyboard_seteventhandler(uip_keyboardhandler);
177: return 0;
178: }
179:
180: void uip_displaybank(int bank) {
181: if (bank == -1)
182: bank = uip_displaybanknum ^ 1;
183: vga_setdisplaystart(bank ? BANKSIZE : 0);
184: uip_uipinfo->screenmem_w = bank ? uip_uipinfo->screenmem0 :
185: uip_uipinfo->screenmem1;
186: uip_displaybanknum = bank;
187: }
188:
189: void uip_clearscreen(void) {
190: memset(uip_uipinfo->screenmem_w, 0, BANKSIZE);
191: }
192:
193: void uip_textmode(void)
194: {
195: if (uip_vga) {
196: keyboard_setdefaulteventhandler();
197: vga_setmode(0);
198: }
199: uip_vga = 0;
200: }
201:
202: int uip_checkkeyboard(void)
203: {
204: keyboard_update();
205: mem68k_cont1_a = uip_key[SCANCODE_A] ? 1 : 0;
206: mem68k_cont1_b = (uip_key[SCANCODE_B] ||
207: uip_key[SCANCODE_S]) ? 1 : 0;
208: mem68k_cont1_c = (uip_key[SCANCODE_C] ||
209: uip_key[SCANCODE_D]) ? 1 : 0;
210: mem68k_cont1_left = uip_key[SCANCODE_CURSORBLOCKLEFT] ? 1 : 0;
211: mem68k_cont1_up = uip_key[SCANCODE_CURSORBLOCKUP] ? 1 : 0;
212: mem68k_cont1_right = uip_key[SCANCODE_CURSORBLOCKRIGHT] ? 1 : 0;
213: mem68k_cont1_down = uip_key[SCANCODE_CURSORBLOCKDOWN] ? 1 : 0;
214: mem68k_cont1_start = uip_key[SCANCODE_ENTER] ? 1 : 0;
215: if (uip_key[SCANCODE_F12])
216: gen_reset();
217: return (uip_key[SCANCODE_ESCAPE] ? 1 : 0);
218: }
219:
220: void uip_vsync(void)
221: {
222: vga_waitretrace();
223: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.