b353f3336b8512c765c7bc53bc523da8847ea2f2
[retroray] / src / dos / main.c
1 /*
2 RetroRay - integrated standalone vintage modeller/renderer
3 Copyright (C) 2023  John Tsiombikas <nuclear@mutantstargoat.com>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <time.h>
22 #include "app.h"
23 #include "keyb.h"
24 #include "gfx.h"
25 #include "cdpmi.h"
26 #include "mouse.h"
27 #include "options.h"
28
29 static uint32_t *vmem;
30 static int quit, disp_pending;
31
32 int main(int argc, char **argv)
33 {
34         int i;
35         int vmidx;
36         int mx, my, bnstate, bndiff;
37         static int prev_mx, prev_my, prev_bnstate;
38
39 #ifdef __DJGPP__
40         __djgpp_nearptr_enable();
41 #endif
42
43         kb_init(32);
44
45         if(!have_mouse()) {
46                 fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n");
47                 return 1;
48         }
49         set_mouse_limits(0, 0, 639, 479);
50         set_mouse(320, 240);
51
52         if(init_video() == -1) {
53                 return 1;
54         }
55
56         if((vmidx = match_video_mode(640, 480, 32)) == -1) {
57                 return 1;
58         }
59         if(!(vmem = set_video_mode(vmidx, 1))) {
60                 return 1;
61         }
62
63         win_width = 640;
64         win_height = 480;
65         win_aspect = (float)win_width / (float)win_height;
66
67         if(app_init() == -1) {
68                 goto break_evloop;
69         }
70         disp_pending = 1;
71
72         for(;;) {
73                 int key;
74                 while((key = kb_getkey()) != -1) {
75                         app_keyboard(key, 1);
76                         if(quit) goto break_evloop;
77                 }
78
79                 bnstate = read_mouse(&mx, &my);
80                 bndiff = bnstate ^ prev_bnstate;
81
82                 if(bndiff & 1) app_mouse(0, bnstate & 1, mx, my);
83                 if(bndiff & 2) app_mouse(1, bnstate & 2, mx, my);
84                 if(bndiff & 4) app_mouse(3, bnstate & 4, mx, my);
85
86                 if(disp_pending) {
87                         disp_pending = 0;
88                         app_display();
89                 }
90         }
91
92 break_evloop:
93         app_shutdown();
94         set_text_mode();
95         cleanup_video();
96         kb_shutdown();
97         return 0;
98 }
99
100 long app_getmsec(void)
101 {
102         return time(0) * 1000;  /* TODO */
103 }
104
105 void app_redisplay(void)
106 {
107         disp_pending = 1;
108 }
109
110 void app_swap_buffers(void)
111 {
112         blit_frame(framebuf, opt.vsync);
113 }
114
115 void app_quit(void)
116 {
117         quit = 1;
118 }
119
120 void app_resize(int x, int y)
121 {
122 }
123
124 void app_fullscreen(int fs)
125 {
126 }
127
128 void app_vsync(int vsync)
129 {
130 }