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/>.
32 static INLINE int clamp(int x, int a, int b)
39 static void draw_cursor(int x, int y);
41 static uint32_t *vmem;
42 static int quit, disp_pending;
44 int main(int argc, char **argv)
48 int mx, my, mdx, mdy, prev_mx, prev_my, bnstate, bndiff;
49 static int prev_bnstate;
52 __djgpp_nearptr_enable();
57 if(read_cpuid(&cpuid) == 0) {
64 fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n");
68 /*add_log_file("retroray.log");*/
70 if(vid_init() == -1) {
74 if((vmidx = vid_findmode(640, 480, 32)) == -1) {
77 if(!(vmem = vid_setmode(vmidx))) {
83 win_aspect = (float)win_width / (float)win_height;
85 if(app_init() == -1) {
90 app_reshape(win_width, win_height);
98 if(kb_isdown(KEY_ALT)) {
99 modkeys |= KEY_MOD_ALT;
101 if(kb_isdown(KEY_CTRL)) {
102 modkeys |= KEY_MOD_CTRL;
104 if(kb_isdown(KEY_SHIFT)) {
105 modkeys |= KEY_MOD_SHIFT;
108 while((key = kb_getkey()) != -1) {
109 app_keyboard(key, 1);
110 if(quit) goto break_evloop;
113 bnstate = read_mouse_bn();
114 bndiff = bnstate ^ prev_bnstate;
115 prev_bnstate = bnstate;
117 read_mouse_rel(&mdx, &mdy);
120 mx = clamp(mx + mdx, 0, win_width - 1);
121 my = clamp(my + mdy, 0, win_height - 1);
125 if(bndiff & 1) app_mouse(0, bnstate & 1, mx, my);
126 if(bndiff & 2) app_mouse(1, bnstate & 2, mx, my);
127 if(bndiff & 4) app_mouse(3, bnstate & 4, mx, my);
129 if((mdx | mdy) != 0) {
138 draw_cursor(prev_mx, prev_my);
151 long app_getmsec(void)
153 return time(0) * 1000; /* TODO */
156 void app_redisplay(void)
161 void app_swap_buffers(void)
166 vid_blitfb32(framebuf, 0);
174 void app_resize(int x, int y)
178 void app_fullscreen(int fs)
182 void app_vsync(int vsync)
186 static void draw_cursor(int x, int y)
189 uint32_t *fbptr = framebuf + y * win_width + x;
193 if(y > offs) fbptr[-win_width * offs] ^= 0xffffff;
194 if(y < win_height - offs - 1) fbptr[win_width * offs] ^= 0xffffff;
195 if(x > offs) fbptr[-offs] ^= 0xffffff;
196 if(x < win_width - offs - 1) fbptr[offs] ^= 0xffffff;