1 #include "u.h" 2 #include "../port/lib.h" 3 #include "mem.h" 4 #include "io.h" 5 #include "dat.h" 6 #include "fns.h" 7 8 #include <draw.h> 9 #include <memdraw.h> 10 #include "screen.h" 11 12 extern Video *vid; 13 extern Memimage gscreen; 14 15 static Vctlr* init(Vctlr* vctlr, int x, int y, int d); 16 static int setcolour(ulong p, ulong r, ulong g, ulong b); 17 static void enable(void); 18 static void disable(void); 19 static void move(int cx, int cy); 20 static void load(Cursor *c); 21 static int isloaded(void); 22 23 extern void* memcpy(void*, void*, int); 24 extern void cursorupdate0(void); 25 26 Vctlr FSV = { 27 "FSV", /* name */ 28 init, /* init */ 29 0, /* page */ 30 setcolour, /* setcolor */ 31 32 enable, /* enable cursor fn */ 33 disable, /* disable cursor fn */ 34 move, /* move cursor fn */ 35 load, /* load cursor fn */ 36 isloaded, /* is cursor loaded? */ 37 0, /* deprecated */ 38 39 1024, /* screen width (x) */ 40 768, /* screen height (y) */ 41 3, /* depth */ 42 43 0, /* hidecount */ 44 0, /* loaded */ 45 }; 46 47 static int lastx=-1; 48 static int lasty=-1; 49 50 static Vctlr* 51 init(Vctlr* vctlr, int x, int y, int d) 52 { 53 USED(vctlr,x,y,d); 54 55 return &FSV; 56 } 57 58 static int 59 setcolour(ulong p, ulong r, ulong g, ulong b) 60 { 61 if(gscreen.ldepth == 0) 62 return 0; /* can't change mono screen colormap */ 63 else{ 64 vid->addr = p << 24; 65 vid->color = r << 24; 66 vid->color = g << 24; 67 vid->color = b << 24; 68 return 1; 69 } 70 } 71 72 static ulong backingstore[64]; 73 static Memdata backingstoredata = { 74 nil, 75 backingstore 76 }; 77 78 static ulong backingnocursor[64]; 79 static Memdata backingnocursordata = { 80 nil, 81 backingnocursor 82 }; 83 84 static ulong backwithcursor[64]; 85 static Memdata backwithcursordata = { 86 nil, 87 backwithcursor 88 }; 89 90 static Memimage backingnocursormem = { 91 {0,0,16,16}, 92 {0,0,16,16}, 93 3, 94 0, 95 &backingnocursordata, 96 0, 97 16/4, 98 0, 99 0, 100 }; 101 static Memimage backingmem = { 102 {0,0,16,16}, 103 {0,0,16,16}, 104 3, 105 0, 106 &backingstoredata, 107 0, 108 16/4, 109 0, 110 0, 111 }; 112 113 static void 114 disable(void) 115 { 116 if(FSV.hidecount++) 117 return; 118 if(lastx < 0 || lasty < 0) 119 return; 120 121 memimagedraw(&gscreen, Rect(lastx,lasty,lastx+16,lasty+16), 122 &backingnocursormem, Pt(0,0), memones, Pt(0,0)); 123 } 124 125 static void 126 enable(void) 127 { 128 uchar *p; 129 uchar mask; 130 uchar *cset; 131 int i; 132 133 if(--FSV.hidecount > 0) 134 return; 135 FSV.hidecount = 0; 136 137 if(lastx < 0 || lasty < 0) 138 return; 139 140 memimagedraw(&backingmem,Rect(0,0,16,16),&gscreen,Pt(lastx,lasty),memones, 141 Pt(0,0)); 142 143 memcpy(backingnocursor,backingstore,256); 144 p = (uchar*)backingmem.data->data; 145 146 cset = FSV.cursor.set; 147 148 for(i=0;i<32;i++) { 149 mask = ~cset[i]; 150 151 if(!(mask&(1<<7))) *p = 0xff; 152 ++p; 153 if(!(mask&(1<<6))) *p = 0xff; 154 ++p; 155 if(!(mask&(1<<5))) *p = 0xff; 156 ++p; 157 if(!(mask&(1<<4))) *p = 0xff; 158 ++p; 159 if(!(mask&(1<<3))) *p = 0xff; 160 ++p; 161 if(!(mask&(1<<2))) *p = 0xff; 162 ++p; 163 if(!(mask&(1<<1))) *p = 0xff; 164 ++p; 165 if(!(mask&(1<<0))) *p = 0xff; 166 ++p; 167 } 168 169 memimagedraw(&gscreen,Rect(lastx,lasty,lastx+16,lasty+16),&backingmem,Pt(0,0), 170 memones,Pt(0,0)); 171 } 172 173 static void 174 move(int cx, int cy) 175 { 176 if(!FSV.loaded) 177 return; 178 179 disable(); 180 cursorupdate0(); 181 lastx = cx; 182 lasty = cy; 183 enable(); 184 } 185 186 187 static void 188 load(Cursor *curs) 189 { 190 FSV.cursor = *curs; 191 FSV.loaded=1; 192 } 193 194 static int 195 isloaded(void) 196 { 197 return FSV.loaded; 198 } 199