ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/Display_svga.h
Revision: 1.6
Committed: 2009-01-11T11:32:38Z (14 years ago) by cebix
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -2 lines
Log Message:
const correctness

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * Display_svga.h - C64 graphics display, emulator window handling,
3     * SVGAlib specific stuff
4     *
5 cebix 1.6 * Frodo (C) 1994-1997,2002-2009 Christian Bauer
6 cebix 1.1 *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20     */
21    
22     #include <vga.h>
23     #include <vgamouse.h>
24     #include <vgakeyboard.h>
25    
26     #include "C64.h"
27    
28    
29     #define SCODE_CURSORBLOCKUP 103 /* Cursor key block. */
30     #define SCODE_CURSORBLOCKLEFT 105
31     #define SCODE_CURSORBLOCKRIGHT 106
32     #define SCODE_CURSORBLOCKDOWN 108
33    
34     #define SCODE_INSERT 110
35     #define SCODE_HOME 102
36     #define SCODE_PGUP 104
37     #define SCODE_DELETE 111
38     #define SCODE_END 107
39     #define SCODE_PGDN 109
40    
41     #define SCODE_NUMLOCK 69
42    
43     #define SCODE_KEYPAD0 82
44     #define SCODE_KEYPAD1 79
45     #define SCODE_KEYPAD2 80
46     #define SCODE_KEYPAD3 81
47     #define SCODE_KEYPAD4 75
48     #define SCODE_KEYPAD5 76
49     #define SCODE_KEYPAD6 77
50     #define SCODE_KEYPAD7 71
51     #define SCODE_KEYPAD8 72
52     #define SCODE_KEYPAD9 73
53     #define SCODE_KEYPADENTER 96
54     #define SCODE_KEYPADPLUS 78
55     #define SCODE_KEYPADMINUS 74
56     #define SCODE_KEYPADMULTIPLY 55
57     #define SCODE_KEYPADDIVIDE 98
58    
59     #define SCODE_Q 16
60     #define SCODE_W 17
61     #define SCODE_E 18
62     #define SCODE_R 19
63     #define SCODE_T 20
64     #define SCODE_Y 21
65     #define SCODE_U 22
66     #define SCODE_I 23
67     #define SCODE_O 24
68     #define SCODE_P 25
69    
70     #define SCODE_A 30
71     #define SCODE_S 31
72     #define SCODE_D 32
73     #define SCODE_F 33
74     #define SCODE_G 34
75     #define SCODE_H 35
76     #define SCODE_J 36
77     #define SCODE_K 37
78     #define SCODE_L 38
79    
80     #define SCODE_Z 44
81     #define SCODE_X 45
82     #define SCODE_C 46
83     #define SCODE_V 47
84     #define SCODE_B 48
85     #define SCODE_N 49
86     #define SCODE_M 50
87    
88     #define SCODE_ESCAPE 1
89     #define SCODE_ENTER 28
90     #define SCODE_RIGHTCONTROL 97
91     #define SCODE_CONTROL 97
92     #define SCODE_RIGHTALT 100
93     #define SCODE_LEFTCONTROL 29
94     #define SCODE_LEFTALT 56
95     #define SCODE_SPACE 57
96    
97     #define SCODE_F1 59
98     #define SCODE_F2 60
99     #define SCODE_F3 61
100     #define SCODE_F4 62
101     #define SCODE_F5 63
102     #define SCODE_F6 64
103     #define SCODE_F7 65
104     #define SCODE_F8 66
105     #define SCODE_F9 67
106     #define SCODE_F10 68
107    
108     #define SCODE_0 11
109     #define SCODE_1 2
110     #define SCODE_2 3
111     #define SCODE_3 4
112     #define SCODE_4 5
113     #define SCODE_5 6
114     #define SCODE_6 7
115     #define SCODE_7 8
116     #define SCODE_8 9
117     #define SCODE_9 10
118    
119     #define SCODE_LEFTSHIFT 42
120     #define SCODE_RIGHTSHIFT 54
121     #define SCODE_TAB 15
122    
123     #define SCODE_F11 87
124     #define SCODE_F12 88
125     #define SCODE_NEXT 81
126     #define SCODE_PRIOR 73
127     #define SCODE_BS 14
128    
129     #define SCODE_asciicircum 41
130     #define SCODE_bracketleft 26
131     #define SCODE_bracketright 27
132     #define SCODE_comma 51
133     #define SCODE_period 52
134     #define SCODE_slash 53
135     #define SCODE_semicolon 39
136     #define SCODE_grave 40
137     #define SCODE_minus 12
138     #define SCODE_equal 13
139     #define SCODE_numbersign 43
140     #define SCODE_ltgt 86
141     #define SCODE_scrolllock 70
142    
143     static int bitdepth;
144     static char *bufmem;
145     static int hsize;
146     static vga_modeinfo modeinfo;
147     static char *linear_mem;
148    
149     static int keystate[256];
150     static int f11pressed = 0, f12pressed = 0, quit = 0;
151     static int joystate = 0xFF;
152     static int numlock = 0;
153 cebix 1.3 static uint8 rev_matrix[8], key_matrix[8];
154 cebix 1.1
155     /*
156     C64 keyboard matrix:
157    
158     Bit 7 6 5 4 3 2 1 0
159     0 CUD F5 F3 F1 F7 CLR RET DEL
160     1 SHL E S Z 4 A W 3
161     2 X T F C 6 D R 5
162     3 V U H B 8 G Y 7
163     4 N O K M 0 J I 9
164     5 , @ : . - L P +
165     6 / ^ = SHR HOM ; *
166     7 R/S Q C= SPC 2 CTL <- 1
167     */
168     #define MATRIX(a,b) (((a) << 3) | (b))
169     #define KEY_F10 512
170     #define KEY_F11 513
171     #define KEY_F12 514
172    
173     #define KEY_FIRE 515
174     #define KEY_JUP 516
175     #define KEY_JDN 517
176     #define KEY_JLF 518
177     #define KEY_JRT 519
178    
179     #define KEY_NUMLOCK 520
180    
181     #define KEY_KPPLUS 521
182     #define KEY_KPMINUS 522
183     #define KEY_KPMULT 523
184     #define KEY_KPDIV 524
185    
186     static int scode2c64(int scancode)
187     {
188     switch (scancode) {
189     case SCODE_asciicircum: return MATRIX(7,1);
190     case SCODE_KEYPAD0: return KEY_FIRE;
191     case SCODE_KEYPAD1: return -1;
192     case SCODE_KEYPAD2: return KEY_JDN;
193     case SCODE_KEYPAD3: return -1;
194     case SCODE_KEYPAD4: return KEY_JLF;
195     case SCODE_KEYPAD5: return -1;
196     case SCODE_KEYPAD6: return KEY_JRT;
197     case SCODE_KEYPAD7: return -1;
198     case SCODE_KEYPAD8: return KEY_JUP;
199     case SCODE_KEYPAD9: return -1;
200    
201     case SCODE_NUMLOCK: return KEY_NUMLOCK;
202     case SCODE_KEYPADMULTIPLY: return KEY_KPMULT;
203     case SCODE_KEYPADDIVIDE: return KEY_KPDIV;
204     case SCODE_KEYPADMINUS: return KEY_KPMINUS;
205     case SCODE_KEYPADPLUS: return KEY_KPPLUS;
206     case SCODE_KEYPADENTER: return MATRIX(0,1);
207    
208     case SCODE_F10: return KEY_F10;
209     case SCODE_F11: return KEY_F11;
210     case SCODE_F12: return KEY_F12;
211    
212     case SCODE_comma: return MATRIX(5,7);
213     case SCODE_period: return MATRIX(5,4);
214    
215     case SCODE_A: return MATRIX(1,2);
216     case SCODE_B: return MATRIX(3,4);
217     case SCODE_C: return MATRIX(2,4);
218     case SCODE_D: return MATRIX(2,2);
219     case SCODE_E: return MATRIX(1,6);
220     case SCODE_F: return MATRIX(2,5);
221     case SCODE_G: return MATRIX(3,2);
222     case SCODE_H: return MATRIX(3,5);
223     case SCODE_I: return MATRIX(4,1);
224     case SCODE_J: return MATRIX(4,2);
225     case SCODE_K: return MATRIX(4,5);
226     case SCODE_L: return MATRIX(5,2);
227     case SCODE_M: return MATRIX(4,4);
228     case SCODE_N: return MATRIX(4,7);
229     case SCODE_O: return MATRIX(4,6);
230     case SCODE_P: return MATRIX(5,1);
231     case SCODE_Q: return MATRIX(7,6);
232     case SCODE_R: return MATRIX(2,1);
233     case SCODE_S: return MATRIX(1,5);
234     case SCODE_T: return MATRIX(2,6);
235     case SCODE_U: return MATRIX(3,6);
236     case SCODE_V: return MATRIX(3,7);
237     case SCODE_W: return MATRIX(1,1);
238     case SCODE_X: return MATRIX(2,7);
239     case SCODE_Y: return MATRIX(3,1);
240     case SCODE_Z: return MATRIX(1,4);
241    
242     case SCODE_BS: return MATRIX(0,0);
243     case SCODE_DELETE: return MATRIX(0,0);
244     case SCODE_LEFTCONTROL: return MATRIX(7,2);
245     case SCODE_TAB: return MATRIX(7,1);
246     case SCODE_ENTER: return MATRIX(0,1);
247     case SCODE_SPACE: return MATRIX(7,4);
248     case SCODE_LEFTSHIFT: return MATRIX(1,7);
249     case SCODE_RIGHTSHIFT: return MATRIX(6,4);
250     case SCODE_ESCAPE: return MATRIX(7,7);
251     case SCODE_RIGHTCONTROL:
252     case SCODE_LEFTALT:
253     case SCODE_RIGHTALT: return MATRIX(7,5);
254    
255     case SCODE_INSERT: return MATRIX(0,0) | 0x80;
256     case SCODE_HOME: return MATRIX(6,3);
257     case SCODE_END: return MATRIX(6,0);
258     case SCODE_PGUP: return MATRIX(6,6);
259     case SCODE_PGDN: return MATRIX(6,5);
260    
261     case SCODE_CURSORBLOCKUP: return MATRIX(0,7)| 0x80;
262     case SCODE_CURSORBLOCKDOWN: return MATRIX(0,7);
263     case SCODE_CURSORBLOCKLEFT: return MATRIX(0,2) | 0x80;
264     case SCODE_CURSORBLOCKRIGHT: return MATRIX(0,2);
265    
266     case SCODE_F1: return MATRIX(0,4);
267     case SCODE_F2: return MATRIX(0,4) | 0x80;
268     case SCODE_F3: return MATRIX(0,5);
269     case SCODE_F4: return MATRIX(0,5) | 0x80;
270     case SCODE_F5: return MATRIX(0,6);
271     case SCODE_F6: return MATRIX(0,6) | 0x80;
272     case SCODE_F7: return MATRIX(0,3);
273     case SCODE_F8: return MATRIX(0,3) | 0x80;
274    
275     case SCODE_0: return MATRIX(4,3);
276     case SCODE_1: return MATRIX(7,0);
277     case SCODE_2: return MATRIX(7,3);
278     case SCODE_3: return MATRIX(1,0);
279     case SCODE_4: return MATRIX(1,3);
280     case SCODE_5: return MATRIX(2,0);
281     case SCODE_6: return MATRIX(2,3);
282     case SCODE_7: return MATRIX(3,0);
283     case SCODE_8: return MATRIX(3,3);
284     case SCODE_9: return MATRIX(4,0);
285    
286     case SCODE_bracketleft: return MATRIX(5,6);
287     case SCODE_bracketright: return MATRIX(6,1);
288     case SCODE_slash: return MATRIX(6,7);
289     case SCODE_semicolon: return MATRIX(5,5);
290     case SCODE_grave: return MATRIX(6,2);
291     case SCODE_numbersign: return MATRIX(6,5);
292     case SCODE_ltgt: return MATRIX(6,6);
293     case SCODE_minus: return MATRIX(5,0);
294     case SCODE_equal: return MATRIX(5,3);
295     }
296     }
297    
298     static void my_kbd_handler(int scancode, int newstate)
299     {
300     int kc = scode2c64(scancode);
301     #if 0
302     if (kc == -1) {
303     printf("%d\n",kc);
304     return;
305     }
306     #endif
307     if (newstate == KEY_EVENTPRESS) {
308     switch (kc) {
309     case KEY_KPPLUS:
310     if (ThePrefs.SkipFrames < 10)
311     ThePrefs.SkipFrames++;
312     break;
313    
314     case KEY_KPMINUS:
315     if (ThePrefs.SkipFrames > 1)
316     ThePrefs.SkipFrames--;
317     break;
318    
319     case KEY_KPMULT:
320     ThePrefs.LimitSpeed = !ThePrefs.LimitSpeed;
321     break;
322    
323     case KEY_KPDIV:
324     ThePrefs.JoystickSwap = !ThePrefs.JoystickSwap;
325     break;
326    
327     case KEY_NUMLOCK:
328     numlock = !numlock;
329     break;
330    
331     case KEY_F10:
332     quit = 1;
333     break;
334    
335     case KEY_F11:
336     f11pressed = 1;
337     break;
338    
339     case KEY_F12:
340     f12pressed = 1;
341     break;
342    
343     case KEY_FIRE:
344     joystate &= ~0x10;
345     break;
346    
347     case KEY_JDN:
348     joystate &= ~0x2;
349     break;
350    
351     case KEY_JUP:
352     joystate &= ~0x1;
353     break;
354    
355     case KEY_JLF:
356     joystate &= ~0x4;
357     break;
358    
359     case KEY_JRT:
360     joystate &= ~0x8;
361     break;
362    
363     default:
364     if (keystate[kc])
365     break;
366     keystate[kc] = 1;
367     int c64_byte, c64_bit, shifted;
368     c64_byte = kc >> 3;
369     c64_bit = kc & 7;
370     shifted = kc & 128;
371     c64_byte &= 7;
372     if (shifted) {
373     key_matrix[6] &= 0xef;
374     rev_matrix[4] &= 0xbf;
375     }
376     key_matrix[c64_byte] &= ~(1 << c64_bit);
377     rev_matrix[c64_bit] &= ~(1 << c64_byte);
378     break;
379     }
380     } else {
381     switch (kc) {
382     case KEY_FIRE:
383     joystate |= 0x10;
384     break;
385    
386     case KEY_JDN:
387     joystate |= 0x2;
388     break;
389    
390     case KEY_JUP:
391     joystate |= 0x1;
392     break;
393    
394     case KEY_JLF:
395     joystate |= 0x4;
396     break;
397    
398     case KEY_JRT:
399     joystate |= 0x8;
400     break;
401    
402     default:
403     if (!keystate[kc])
404     break;
405     keystate[kc] = 0;
406     int c64_byte, c64_bit, shifted;
407     c64_byte = kc >> 3;
408     c64_bit = kc & 7;
409     shifted = kc & 128;
410     c64_byte &= 7;
411     if (shifted) {
412     key_matrix[6] |= 0x10;
413     rev_matrix[4] |= 0x40;
414     }
415     key_matrix[c64_byte] |= (1 << c64_bit);
416     rev_matrix[c64_bit] |= (1 << c64_byte);
417     break;
418     }
419    
420     }
421     }
422    
423    
424     C64Display::C64Display(C64 *the_c64) : TheC64(the_c64)
425     {
426     quit_requested = false;
427     }
428    
429    
430     C64Display::~C64Display()
431     {
432     sleep(1);
433     vga_setmode(TEXT);
434     }
435    
436    
437     /*
438     * Prefs may have changed
439     */
440    
441     void C64Display::NewPrefs(Prefs *prefs)
442     {
443     }
444    
445    
446     void C64Display::Speedometer(int speed)
447     {
448     }
449    
450    
451     int init_graphics(void)
452     {
453     int vgamode = G640x480x256;
454     modeinfo = *vga_getmodeinfo (vgamode);
455    
456     if (vga_setmode(vgamode) < 0) {
457     sleep(1);
458     vga_setmode(TEXT);
459     fprintf(stderr, "SVGAlib doesn't like my video mode. Giving up.\n");
460     return 0;
461     }
462    
463     hsize = modeinfo.linewidth;
464     if (hsize < DISPLAY_X)
465     hsize = DISPLAY_X;
466    
467     bufmem = NULL;
468     if ((modeinfo.flags & CAPABLE_LINEAR) && modeinfo.linewidth >= DISPLAY_X) {
469     if (vga_setlinearaddressing() != -1) {
470     linear_mem = (char *)vga_getgraphmem();
471     printf("Using linear addressing: %p.\n", linear_mem);
472     bufmem = linear_mem;
473     }
474     }
475     if (bufmem == NULL)
476     bufmem = (char *)malloc(hsize * DISPLAY_Y);
477    
478     if (keyboard_init() != 0)
479     abort();
480     keyboard_seteventhandler(my_kbd_handler);
481     /* keyboard_translatekeys(DONT_CATCH_CTRLC);*/
482    
483     memset(keystate, 0, sizeof(keystate));
484     memset(key_matrix, 0xFF, 8);
485     memset(rev_matrix, 0xFF, 8);
486     return 1;
487     }
488    
489    
490     void C64Display::Update(void)
491     {
492     int y;
493    
494     if (linear_mem)
495     return;
496    
497     for (y = 0; y < DISPLAY_Y; y++) {
498 cebix 1.3 vga_drawscanline(y, (uint8 *)bufmem + hsize * y);
499 cebix 1.1 }
500     }
501    
502    
503 cebix 1.3 uint8 *C64Display::BitmapBase(void)
504 cebix 1.1 {
505 cebix 1.3 return (uint8 *)bufmem;
506 cebix 1.1 }
507    
508    
509     int C64Display::BitmapXMod(void)
510     {
511     return hsize;
512     }
513    
514    
515 cebix 1.3 void C64Display::PollKeyboard(uint8 *CIA_key_matrix, uint8 *CIA_rev_matrix, uint8 *joystick)
516 cebix 1.1 {
517     keyboard_update();
518     *joystick = joystate;
519     memcpy(CIA_key_matrix, key_matrix, 8);
520     memcpy(CIA_rev_matrix, rev_matrix, 8);
521     if (f11pressed)
522     TheC64->NMI();
523     if (f12pressed)
524     TheC64->Reset();
525     if (quit)
526     quit_requested = true;
527     f11pressed = f12pressed = 0;
528     }
529    
530    
531     /*
532     * Check if NumLock is down (for switching the joystick keyboard emulation)
533     */
534    
535     bool C64Display::NumLock(void)
536     {
537     return numlock;
538     }
539    
540    
541     /*
542     * Allocate C64 colors
543     */
544    
545     static int colorval(int v)
546     {
547     return ((v & 255)*0x01010101) >> 26;
548     }
549    
550 cebix 1.3 void C64Display::InitColors(uint8 *colors)
551 cebix 1.1 {
552     int i;
553    
554     for (i=0; i< 256; i++) {
555     vga_setpalette(i, colorval(palette_red[i & 0x0f]), colorval(palette_green[i & 0x0f]), colorval(palette_blue[i & 0x0f]));
556     colors[i] = i;
557     }
558     }
559    
560    
561     /*
562     * Show a requester (error message)
563     */
564    
565 cebix 1.6 long int ShowRequester(const char *a, const char *b, const char *)
566 cebix 1.1 {
567     printf("%s: %s\n", a, b);
568     return 1;
569     }