2 RetroRay - integrated standalone vintage modeller/renderer
3 Copyright (C) 2023 John Tsiombikas <nuclear@mutantstargoat.com>
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.
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.
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/>.
31 static void draw_cursor(int x, int y);
33 static uint32_t *vmem;
34 static int quit, disp_pending;
36 int main(int argc, char **argv)
40 int mx, my, bnstate, bndiff;
41 static int prev_mx = -1, prev_my, prev_bnstate;
44 __djgpp_nearptr_enable();
49 if(read_cpuid(&cpuid) == 0) {
56 fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n");
59 set_mouse_limits(0, 0, 639, 479);
64 add_log_file("retroray.log");
66 if(init_video() == -1) {
70 if((vmidx = match_video_mode(640, 480, 32)) == -1) {
73 if(!(vmem = set_video_mode(vmidx, 1))) {
79 win_aspect = (float)win_width / (float)win_height;
81 if(app_init() == -1) {
86 app_reshape(win_width, win_height);
95 if(kb_isdown(KEY_ALT)) {
96 modkeys |= KEY_MOD_ALT;
98 if(kb_isdown(KEY_CTRL)) {
99 modkeys |= KEY_MOD_CTRL;
101 if(kb_isdown(KEY_SHIFT)) {
102 modkeys |= KEY_MOD_SHIFT;
105 while((key = kb_getkey()) != -1) {
106 app_keyboard(key, 1);
107 if(quit) goto break_evloop;
110 bnstate = read_mouse(&mx, &my);
111 bndiff = bnstate ^ prev_bnstate;
112 prev_bnstate = bnstate;
115 dbgmsg("bndiff: %04x\n", bndiff);
118 if(bndiff & 1) app_mouse(0, bnstate & 1, mx, my);
119 if(bndiff & 2) app_mouse(1, bnstate & 2, mx, my);
120 if(bndiff & 4) app_mouse(3, bnstate & 4, mx, my);
126 draw_cursor(prev_mx, prev_my);
128 if((mx ^ prev_mx) | (my ^ prev_my)) {
151 long app_getmsec(void)
153 return time(0) * 1000; /* TODO */
156 void app_redisplay(void)
161 void app_swap_buffers(void)
163 blit_frame(framebuf, opt.vsync);
171 void app_resize(int x, int y)
175 void app_fullscreen(int fs)
179 void app_vsync(int vsync)
183 static void draw_cursor(int x, int y)
186 uint32_t *fbptr = framebuf + y * win_width + x;
190 if(y > offs) fbptr[-win_width * offs] ^= 0xffffff;
191 if(y < win_height - offs - 1) fbptr[win_width * offs] ^= 0xffffff;
192 if(x > offs) fbptr[-offs] ^= 0xffffff;
193 if(x < win_width - offs - 1) fbptr[offs] ^= 0xffffff;