PCem

view src/allegro-main.c @ 154:d0d530adce12

Initial port to Linux (using Allegro). 64-bit fixes. Some changes to aid portability. A few other tweaks.
author TomW
date Thu Sep 04 21:07:24 2014 +0100
parents
children
line source
1 #include "allegro-main.h"
2 #include "ibm.h"
3 #include "cpu.h"
4 #include "model.h"
5 #include "nvr.h"
6 #include "video.h"
8 #undef printf
10 int mousecapture = 0;
11 int quited = 0;
12 int winsizex = -1, winsizey = -1;
14 int romspresent[ROM_MAX];
15 int gfx_present[GFX_MAX];
17 void updatewindowsize(int x, int y)
18 {
19 if (x < 128)
20 x = 128;
21 if (y < 128)
22 y = 128;
23 if (winsizex != x || winsizey != y)
24 {
25 winsizex = x;
26 winsizey = y;
27 allegro_video_update_size(x, y);
28 }
29 }
31 void startblit()
32 {
33 }
35 void endblit()
36 {
37 }
39 static int ticks = 0;
40 static void timer_rout()
41 {
42 ticks++;
43 }
45 uint64_t timer_freq;
46 uint64_t timer_read()
47 {
48 return 0;
49 }
51 int main()
52 {
53 int frames = 0;
54 int c, d;
55 allegro_init();
56 allegro_video_init();
57 install_timer();
58 install_int_ex(timer_rout, BPS_TO_TIMER(100));
59 install_int_ex(onesec, BPS_TO_TIMER(1));
60 midi_init();
62 initpc();
64 d = romset;
65 for (c = 0; c < ROM_MAX; c++)
66 {
67 romset = c;
68 romspresent[c] = loadbios();
69 pclog("romset %i - %i\n", c, romspresent[c]);
70 }
72 for (c = 0; c < ROM_MAX; c++)
73 {
74 if (romspresent[c])
75 break;
76 }
77 if (c == ROM_MAX)
78 {
79 printf("No ROMs present!\nYou must have at least one romset to use PCem.");
80 return 0;
81 }
83 romset=d;
84 c=loadbios();
86 if (!c)
87 {
88 if (romset != -1)
89 printf("Configured romset not available.\nDefaulting to available romset.");
90 for (c = 0; c < ROM_MAX; c++)
91 {
92 if (romspresent[c])
93 {
94 romset = c;
95 model = model_getmodel(romset);
96 saveconfig();
97 resetpchard();
98 break;
99 }
100 }
101 }
103 for (c = 0; c < GFX_MAX; c++)
104 gfx_present[c] = video_card_available(video_old_to_new(c));
106 if (!video_card_available(video_old_to_new(gfxcard)))
107 {
108 if (gfxcard) printf("Configured video BIOS not available.\nDefaulting to available romset.");
109 for (c = GFX_MAX-1; c >= 0; c--)
110 {
111 if (gfx_present[c])
112 {
113 gfxcard = c;
114 saveconfig();
115 resetpchard();
116 break;
117 }
118 }
119 }
121 ticks = 0;
122 while (!quited)
123 {
124 if (ticks)
125 {
126 ticks--;
127 runpc();
128 frames++;
129 if (frames >= 200 && nvr_dosave)
130 {
131 frames = 0;
132 nvr_dosave = 0;
133 savenvr();
134 }
135 }
136 else
137 rest(1);
139 if (ticks > 10)
140 ticks = 0;
142 if ((mouse_b & 1) && !mousecapture)
143 mousecapture = 1;
145 if (((key[KEY_LCONTROL] || key[KEY_RCONTROL]) && key[KEY_END]) || (mouse_b & 4))
146 mousecapture = 0;
148 if ((key[KEY_LCONTROL] || key[KEY_RCONTROL]) && key[KEY_ALT] && key[KEY_PGDN])
149 {
150 int old_winsizex = winsizex, old_winsizey = winsizey;
151 if (winsizex < 512 || winsizey < 350)
152 updatewindowsize(512, 350);
153 gui_enter();
154 if (old_winsizex < 512 || old_winsizey < 350)
155 updatewindowsize(old_winsizex, old_winsizey);
156 ticks = 0;
157 }
158 }
160 closepc();
162 midi_close();
164 return 0;
165 }
167 END_OF_MAIN();