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/>.
34 static INLINE int clamp(int x, int a, int b)
41 static void draw_cursor(int x, int y);
43 static uint32_t *vmem;
44 static int quit, disp_pending, dirty_valid;
45 static rtk_rect dirty;
48 int main(int argc, char **argv)
52 int mdx, mdy, prev_mx, prev_my, bnstate, bndiff;
53 static int prev_bnstate;
57 __djgpp_nearptr_enable();
62 if(read_cpuid(&cpuid) == 0) {
69 fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n");
73 if((env = getenv("RRLOG"))) {
74 if(tolower(env[0]) == 'c' && tolower(env[1]) == 'o' && tolower(env[2]) == 'm'
82 if(vid_init() == -1) {
86 if((vmidx = vid_findmode(640, 480, 32)) == -1) {
89 if(!(vmem = vid_setmode(vmidx))) {
95 win_aspect = (float)win_width / (float)win_height;
97 if(app_init() == -1) {
100 app_redisplay(0, 0, 0, 0);
102 app_reshape(win_width, win_height);
110 if(kb_isdown(KEY_ALT)) {
111 modkeys |= KEY_MOD_ALT;
113 if(kb_isdown(KEY_CTRL)) {
114 modkeys |= KEY_MOD_CTRL;
116 if(kb_isdown(KEY_SHIFT)) {
117 modkeys |= KEY_MOD_SHIFT;
120 while((key = kb_getkey()) != -1) {
121 if(key == 'r' && (modkeys & KEY_MOD_CTRL)) {
122 app_redisplay(0, 0, 0, 0);
124 app_keyboard(key, 1);
126 if(quit) goto break_evloop;
129 bnstate = read_mouse_bn();
130 bndiff = bnstate ^ prev_bnstate;
131 prev_bnstate = bnstate;
133 read_mouse_rel(&mdx, &mdy);
136 mx = clamp(mx + mdx, 0, win_width - 1);
137 my = clamp(my + mdy, 0, win_height - 1);
141 if(bndiff & 1) app_mouse(0, bnstate & 1, mx, my);
142 if(bndiff & 2) app_mouse(1, bnstate & 2, mx, my);
143 if(bndiff & 4) app_mouse(3, bnstate & 4, mx, my);
145 if((mdx | mdy) != 0) {
156 draw_cursor(prev_mx, prev_my);
167 long app_getmsec(void)
169 return time(0) * 1000; /* TODO */
172 void app_redisplay(int x, int y, int w, int h)
179 r.height = win_height;
188 rtk_rect_union(&dirty, &r);
196 void app_swap_buffers(void)
201 if(!dirty_valid) return;
202 if(dirty.width < win_width || dirty.height < win_height) {
203 uint32_t *src = framebuf + dirty.y * win_width + dirty.x;
204 vid_blit32(dirty.x, dirty.y, dirty.width, dirty.height, src, 0);
206 if(mx >= dirty.x && my >= dirty.y && mx < dirty.x + dirty.width && my < dirty.y + dirty.height) {
210 vid_blitfb32(framebuf, 0);
222 void app_resize(int x, int y)
226 void app_fullscreen(int fs)
230 void app_vsync(int vsync)
234 static void draw_cursor(int x, int y)
237 uint32_t *fbptr = vmem + y * win_width + x;
241 if(y > offs) fbptr[-win_width * offs] ^= 0xffffff;
242 if(y < win_height - offs - 1) fbptr[win_width * offs] ^= 0xffffff;
243 if(x > offs) fbptr[-offs] ^= 0xffffff;
244 if(x < win_width - offs - 1) fbptr[offs] ^= 0xffffff;