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/>.
33 static INLINE int clamp(int x, int a, int b)
40 static void draw_cursor(int x, int y);
42 static uint32_t *vmem;
43 static int quit, disp_pending;
45 int main(int argc, char **argv)
49 int mx, my, mdx, mdy, prev_mx, prev_my, bnstate, bndiff;
50 static int prev_bnstate;
54 __djgpp_nearptr_enable();
59 if(read_cpuid(&cpuid) == 0) {
66 fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n");
70 if((env = getenv("RRLOG"))) {
71 if(tolower(env[0]) == 'c' && tolower(env[1]) == 'o' && tolower(env[2]) == 'm'
79 if(vid_init() == -1) {
83 if((vmidx = vid_findmode(640, 480, 32)) == -1) {
86 if(!(vmem = vid_setmode(vmidx))) {
92 win_aspect = (float)win_width / (float)win_height;
94 if(app_init() == -1) {
99 app_reshape(win_width, win_height);
107 if(kb_isdown(KEY_ALT)) {
108 modkeys |= KEY_MOD_ALT;
110 if(kb_isdown(KEY_CTRL)) {
111 modkeys |= KEY_MOD_CTRL;
113 if(kb_isdown(KEY_SHIFT)) {
114 modkeys |= KEY_MOD_SHIFT;
117 while((key = kb_getkey()) != -1) {
118 app_keyboard(key, 1);
119 if(quit) goto break_evloop;
122 bnstate = read_mouse_bn();
123 bndiff = bnstate ^ prev_bnstate;
124 prev_bnstate = bnstate;
126 read_mouse_rel(&mdx, &mdy);
129 mx = clamp(mx + mdx, 0, win_width - 1);
130 my = clamp(my + mdy, 0, win_height - 1);
134 if(bndiff & 1) app_mouse(0, bnstate & 1, mx, my);
135 if(bndiff & 2) app_mouse(1, bnstate & 2, mx, my);
136 if(bndiff & 4) app_mouse(3, bnstate & 4, mx, my);
138 if((mdx | mdy) != 0) {
147 draw_cursor(prev_mx, prev_my);
160 long app_getmsec(void)
162 return time(0) * 1000; /* TODO */
165 void app_redisplay(void)
170 void app_swap_buffers(void)
175 vid_blitfb32(framebuf, 0);
183 void app_resize(int x, int y)
187 void app_fullscreen(int fs)
191 void app_vsync(int vsync)
195 static void draw_cursor(int x, int y)
198 uint32_t *fbptr = framebuf + y * win_width + x;
202 if(y > offs) fbptr[-win_width * offs] ^= 0xffffff;
203 if(y < win_height - offs - 1) fbptr[win_width * offs] ^= 0xffffff;
204 if(x > offs) fbptr[-offs] ^= 0xffffff;
205 if(x < win_width - offs - 1) fbptr[offs] ^= 0xffffff;