more dos port
[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         for(;;) {
83                 int key;
84                 while((key = kb_getkey()) != -1) {
85                         app_keyboard(key, 1);
86                         if(quit) goto break_evloop;
87                 }
88
89                 bnstate = read_mouse(&mx, &my);
90                 bndiff = bnstate ^ prev_bnstate;
91
92                 if(bndiff & 1) app_mouse(0, bnstate & 1, mx, my);
93                 if(bndiff & 2) app_mouse(1, bnstate & 2, mx, my);
94                 if(bndiff & 4) app_mouse(3, bnstate & 4, mx, my);
95
96                 if(disp_pending) {
97                         disp_pending = 0;
98                         app_display();
99                 }
100         }
101
102 break_evloop:
103         app_shutdown();
104         set_text_mode();
105         cleanup_video();
106         kb_shutdown();
107         return 0;
108 }
109
110 long app_getmsec(void)
111 {
112         return time(0) * 1000;  /* TODO */
113 }
114
115 void app_redisplay(void)
116 {
117         disp_pending = 1;
118 }
119
120 void app_swap_buffers(void)
121 {
122         blit_frame(framebuf, opt.vsync);
123 }
124
125 void app_quit(void)
126 {
127         quit = 1;
128 }
129
130 void app_resize(int x, int y)
131 {
132 }
133
134 void app_fullscreen(int fs)
135 {
136 }
137
138 void app_vsync(int vsync)
139 {
140 }