a11de39fc400b978a1acfe6f8da45063b8b6974d
[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 "logger.h"
28 #include "options.h"
29 #include "cpuid.h"
30
31 static uint32_t *vmem;
32 static int quit, disp_pending;
33
34 int main(int argc, char **argv)
35 {
36         int i;
37         int vmidx;
38         int mx, my, bnstate, bndiff;
39         static int prev_mx, prev_my, prev_bnstate;
40
41 #ifdef __DJGPP__
42         __djgpp_nearptr_enable();
43 #endif
44
45         init_logger();
46
47         if(read_cpuid(&cpuid) == 0) {
48                 print_cpuid(&cpuid);
49         }
50
51         kb_init(32);
52
53         if(!have_mouse()) {
54                 fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n");
55                 return 1;
56         }
57         set_mouse_limits(0, 0, 639, 479);
58         set_mouse(320, 240);
59
60         add_log_file("retroray.log");
61
62         if(init_video() == -1) {
63                 return 1;
64         }
65
66         if((vmidx = match_video_mode(640, 480, 32)) == -1) {
67                 return 1;
68         }
69         if(!(vmem = set_video_mode(vmidx, 1))) {
70                 return 1;
71         }
72
73         win_width = 640;
74         win_height = 480;
75         win_aspect = (float)win_width / (float)win_height;
76
77         if(app_init() == -1) {
78                 goto break_evloop;
79         }
80         disp_pending = 1;
81
82         app_reshape(win_width, win_height);
83
84         for(;;) {
85                 int key;
86                 while((key = kb_getkey()) != -1) {
87                         app_keyboard(key, 1);
88                         if(quit) goto break_evloop;
89                 }
90
91                 bnstate = read_mouse(&mx, &my);
92                 bndiff = bnstate ^ prev_bnstate;
93
94                 if(bndiff & 1) app_mouse(0, bnstate & 1, mx, my);
95                 if(bndiff & 2) app_mouse(1, bnstate & 2, mx, my);
96                 if(bndiff & 4) app_mouse(3, bnstate & 4, mx, my);
97
98                 if(disp_pending) {
99                         disp_pending = 0;
100                         app_display();
101                 }
102         }
103
104 break_evloop:
105         app_shutdown();
106         set_text_mode();
107         cleanup_video();
108         kb_shutdown();
109         return 0;
110 }
111
112 long app_getmsec(void)
113 {
114         return time(0) * 1000;  /* TODO */
115 }
116
117 void app_redisplay(void)
118 {
119         disp_pending = 1;
120 }
121
122 void app_swap_buffers(void)
123 {
124         blit_frame(framebuf, opt.vsync);
125 }
126
127 void app_quit(void)
128 {
129         quit = 1;
130 }
131
132 void app_resize(int x, int y)
133 {
134 }
135
136 void app_fullscreen(int fs)
137 {
138 }
139
140 void app_vsync(int vsync)
141 {
142 }