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/>.
35 static INLINE int clamp(int x, int a, int b)
42 static void draw_cursor(int x, int y);
43 static void draw_rband(rtk_rect *r);
45 static uint32_t *vmem;
46 static int quit, dirty_valid;
47 static rtk_rect dirty;
48 static int mx, my, prev_mx, prev_my;
49 static rtk_rect rband, prev_rband;
52 int main(int argc, char **argv)
56 int mdx, mdy, bnstate, bndiff;
57 static int prev_bnstate;
61 __djgpp_nearptr_enable();
66 if(read_cpuid(&cpuid) == 0) {
74 fprintf(stderr, "No mouse detected. Make sure the mouse driver is installed\n");
78 if((env = getenv("RRLOG"))) {
79 if(tolower(env[0]) == 'c' && tolower(env[1]) == 'o' && tolower(env[2]) == 'm'
87 if(vid_init() == -1) {
91 if((vmidx = vid_findmode(640, 480, 32)) == -1) {
94 if(!(vmem = vid_setmode(vmidx))) {
100 win_aspect = (float)win_width / (float)win_height;
102 if(app_init() == -1) {
105 app_redisplay(0, 0, 0, 0);
107 app_reshape(win_width, win_height);
110 prev_mx = prev_my = -1;
116 if(kb_isdown(KEY_ALT)) {
117 modkeys |= KEY_MOD_ALT;
119 if(kb_isdown(KEY_CTRL)) {
120 modkeys |= KEY_MOD_CTRL;
122 if(kb_isdown(KEY_SHIFT)) {
123 modkeys |= KEY_MOD_SHIFT;
126 while((key = kb_getkey()) != -1) {
127 if(key == 'r' && (modkeys & KEY_MOD_CTRL)) {
128 app_redisplay(0, 0, 0, 0);
130 app_keyboard(key, 1);
132 if(quit) goto break_evloop;
135 bnstate = read_mouse_bn();
136 bndiff = bnstate ^ prev_bnstate;
137 prev_bnstate = bnstate;
139 read_mouse_rel(&mdx, &mdy);
140 mx = clamp(mx + mdx, 0, win_width - 1);
141 my = clamp(my + mdy, 0, win_height - 1);
145 if(bndiff & 1) app_mouse(0, bnstate & 1, mx, my);
146 if(bndiff & 2) app_mouse(1, bnstate & 2, mx, my);
147 if(bndiff & 4) app_mouse(3, bnstate & 4, mx, my);
149 if((mdx | mdy) != 0) {
164 void app_redisplay(int x, int y, int w, int h)
171 r.height = win_height;
180 rtk_rect_union(&dirty, &r);
187 void app_swap_buffers(void)
193 if(dirty.width < win_width || dirty.height < win_height) {
194 uint32_t *src = framebuf + dirty.y * win_width + dirty.x;
195 vid_blit32(dirty.x, dirty.y, dirty.width, dirty.height, src, 0);
197 vid_blitfb32(framebuf, 0);
202 draw_cursor(prev_mx, prev_my);
208 if(prev_rband.width) {
209 draw_rband(&prev_rband);
222 void app_resize(int x, int y)
226 void app_fullscreen(int fs)
230 void app_vsync(int vsync)
234 void app_rband(int x, int y, int w, int h)
246 static void draw_cursor(int x, int y)
249 uint32_t *fbptr = vmem + y * win_width + x;
253 if(y > offs) fbptr[-win_width * offs] ^= 0xffffff;
254 if(y < win_height - offs - 1) fbptr[win_width * offs] ^= 0xffffff;
255 if(x > offs) fbptr[-offs] ^= 0xffffff;
256 if(x < win_width - offs - 1) fbptr[offs] ^= 0xffffff;
260 static void draw_rband(rtk_rect *r)
264 uint32_t *fbptr, *bptr;
269 if(rect.width <= 0 || rect.height <= 0) {
273 fbptr = vmem + rect.y * win_width + rect.x;
274 bptr = fbptr + win_width * (rect.height - 1);
276 for(i=0; i<rect.width; i++) {
277 fbptr[i] ^= 0xffffff;
281 for(i=0; i<rect.height-2; i++) {
282 fbptr[0] ^= 0xffffff;
283 fbptr[rect.width - 1] ^= 0xffffff;