3 #include "doomdef.h" // printf
5 #include "v_video.h" // screens[]
6 #include "d_main.h" // D_PostEvent
13 static int mouseactive;
15 static Rectangle grabout;
18 static void kbdproc(void*);
19 static void mouseproc(void*);
21 static uchar cmap[3*256];
23 void I_InitGraphics(void)
25 if(initdraw(nil, nil, "doom") < 0)
26 I_Error("I_InitGraphics failed");
28 draw(screen, screen->r, display->black, nil, ZP);
30 center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
31 grabout = insetrect(screen->r, Dx(screen->r)/8);
33 proccreate(kbdproc, nil, 8*1024);
34 proccreate(mouseproc, nil, 8*1024);
36 screens[0] = (unsigned char*) malloc(SCREENWIDTH * SCREENHEIGHT);
39 void I_ShutdownGraphics(void)
43 void I_SetPalette(byte *palette)
45 memcpy(cmap, palette, 3*256);
48 void I_UpdateNoBlit(void)
53 void I_FinishUpdate(void)
59 uchar buf[SCREENWIDTH*3*4];
63 if(getwindow(display, Refnone) < 0)
64 sysfatal("getwindow failed: %r");
66 /* make black background */
67 draw(screen, screen->r, display->black, nil, ZP);
69 center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
70 grabout = insetrect(screen->r, Dx(screen->r)/8);
73 scale = Dx(screen->r)/SCREENWIDTH;
79 /* where to draw the scaled row */
80 r = rectsubpt(rectaddpt(Rect(0, 0, scale*SCREENWIDTH, scale), center),
81 Pt(scale*SCREENWIDTH/2, scale*SCREENHEIGHT/2));
83 /* the row image, y-axis gets scaled with repl flag */
84 rowimg = allocimage(display, Rect(0, 0, scale*SCREENWIDTH, 1), RGB24, 1, DNofill);
87 for(y = 0; y < SCREENHEIGHT; y++){
111 loadimage(rowimg, rowimg->r, buf, d - buf);
112 draw(screen, r, rowimg, nil, ZP);
118 flushimage(display, 1);
121 void I_MouseEnable(int on)
123 static char nocurs[2*4+2*2*16];
126 if(mouseactive == on)
128 if(mouseactive = on){
129 if((fd = open("/dev/cursor", ORDWR|OCEXEC)) < 0)
131 write(fd, nocurs, sizeof(nocurs));
138 void I_ReadScreen(byte *scr)
140 memcpy (scr, screens[0], SCREENWIDTH*SCREENHEIGHT);
143 void I_BeginRead(void)
145 I_Error("PORTME i_video.c I_BeginRead");
150 I_Error("PORTME i_video.c I_EndRead");
153 void I_StartTic(void)
167 return KEY_LEFTARROW;
169 return KEY_RIGHTARROW;
173 return KEY_DOWNARROW;
204 return KEY_F1+(r-(KF|1));
215 char buf[128], buf2[128], *s;
220 threadsetname("kbdproc");
222 if((kfd = open("/dev/kbd", OREAD)) < 0)
223 sysfatal("can't open kbd: %r");
226 while((n = read(kfd, buf, sizeof(buf))) > 0){
231 s += chartorune(&r, s);
232 if(utfrune(buf2, r) == nil){
234 if(e.data1 = runetokey(r))
240 s += chartorune(&r, s);
241 if(utfrune(buf, r) == nil){
243 if(e.data1 = runetokey(r))
260 threadsetname("mouseproc");
262 if((fd = open("/dev/mouse", ORDWR)) < 0)
263 sysfatal("can't open mouse: %r");
265 memset(&m, 0, sizeof m);
266 memset(&om, 0, sizeof om);
269 n = read(fd, buf, sizeof buf);
271 yield(); /* if error is due to exiting, we'll exit here */
272 fprint(2, "mouse: bad count %d not 49: %r\n", n);
286 m.xy.x = atoi(buf+1+0*12);
287 m.xy.y = atoi(buf+1+1*12);
288 m.buttons = atoi(buf+1+2*12);
289 m.msec = atoi(buf+1+3*12);
291 if(!ptinrect(m.xy, grabout)){
292 fprint(fd, "m%d %d", center.x, center.y);
300 e.data2 = 10*(m.xy.x - om.xy.x);
301 e.data3 = 10*(om.xy.y - m.xy.y);