Mercurial > sdl-ios-xcode
comparison src/video/riscos/SDL_wimpvideo.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | d910939febfa |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
41 | 41 |
42 #include "kernel.h" | 42 #include "kernel.h" |
43 #include "swis.h" | 43 #include "swis.h" |
44 | 44 |
45 /* Initialization/Query functions */ | 45 /* Initialization/Query functions */ |
46 SDL_Rect **WIMP_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | 46 SDL_Rect **WIMP_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags); |
47 SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | 47 SDL_Surface *WIMP_SetVideoMode (_THIS, SDL_Surface * current, int width, |
48 int WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | 48 int height, int bpp, Uint32 flags); |
49 void WIMP_SetWMCaption(_THIS, const char *title, const char *icon); | 49 int WIMP_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors); |
50 | 50 void WIMP_SetWMCaption (_THIS, const char *title, const char *icon); |
51 | 51 |
52 extern unsigned char *WIMP_CreateBuffer(int width, int height, int bpp); | 52 |
53 extern void WIMP_PumpEvents(_THIS); | 53 extern unsigned char *WIMP_CreateBuffer (int width, int height, int bpp); |
54 extern void WIMP_PlotSprite(_THIS, int x, int y); | 54 extern void WIMP_PumpEvents (_THIS); |
55 extern void WIMP_SetupPlotInfo(_THIS); | 55 extern void WIMP_PlotSprite (_THIS, int x, int y); |
56 extern void WIMP_SetFocus(int win); | 56 extern void WIMP_SetupPlotInfo (_THIS); |
57 extern void WIMP_SetFocus (int win); | |
57 | 58 |
58 /* etc. */ | 59 /* etc. */ |
59 static void WIMP_UpdateRects(_THIS, int numrects, SDL_Rect *rects); | 60 static void WIMP_UpdateRects (_THIS, int numrects, SDL_Rect * rects); |
60 | 61 |
61 /* RISC OS Wimp handling helpers */ | 62 /* RISC OS Wimp handling helpers */ |
62 void WIMP_ReadModeInfo(_THIS); | 63 void WIMP_ReadModeInfo (_THIS); |
63 unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface); | 64 unsigned int WIMP_SetupWindow (_THIS, SDL_Surface * surface); |
64 void WIMP_SetDeviceMode(_THIS); | 65 void WIMP_SetDeviceMode (_THIS); |
65 void WIMP_DeleteWindow(_THIS); | 66 void WIMP_DeleteWindow (_THIS); |
66 | 67 |
67 /* FULLSCREEN function required for wimp/fullscreen toggling */ | 68 /* FULLSCREEN function required for wimp/fullscreen toggling */ |
68 extern int FULLSCREEN_SetMode(int width, int height, int bpp); | 69 extern int FULLSCREEN_SetMode (int width, int height, int bpp); |
69 | 70 |
70 /* Currently need to set this up here as it only works if you | 71 /* Currently need to set this up here as it only works if you |
71 start up in a Wimp mode */ | 72 start up in a Wimp mode */ |
72 extern int RISCOS_ToggleFullScreen(_THIS, int fullscreen); | 73 extern int RISCOS_ToggleFullScreen (_THIS, int fullscreen); |
73 | 74 |
74 extern int riscos_backbuffer; | 75 extern int riscos_backbuffer; |
75 extern int mouseInWindow; | 76 extern int mouseInWindow; |
76 extern int riscos_closeaction; | 77 extern int riscos_closeaction; |
77 | 78 |
78 /* Following needed to ensure window is shown immediately */ | 79 /* Following needed to ensure window is shown immediately */ |
79 extern int hasFocus; | 80 extern int hasFocus; |
80 extern void WIMP_Poll(_THIS, int waitTime); | 81 extern void WIMP_Poll (_THIS, int waitTime); |
81 | 82 |
82 SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, | 83 SDL_Surface * |
83 int width, int height, int bpp, Uint32 flags) | 84 WIMP_SetVideoMode (_THIS, SDL_Surface * current, |
84 { | 85 int width, int height, int bpp, Uint32 flags) |
85 Uint32 Rmask = 0; | 86 { |
86 Uint32 Gmask = 0; | 87 Uint32 Rmask = 0; |
87 Uint32 Bmask = 0; | 88 Uint32 Gmask = 0; |
88 char *buffer = NULL; | 89 Uint32 Bmask = 0; |
89 int bytesPerPixel = 1; | 90 char *buffer = NULL; |
90 | 91 int bytesPerPixel = 1; |
91 /* Don't support double buffering in Wimp mode */ | 92 |
92 flags &= ~SDL_DOUBLEBUF; | 93 /* Don't support double buffering in Wimp mode */ |
93 flags &= ~SDL_HWSURFACE; | 94 flags &= ~SDL_DOUBLEBUF; |
94 | 95 flags &= ~SDL_HWSURFACE; |
95 switch(bpp) | 96 |
96 { | 97 switch (bpp) { |
97 case 8: | 98 case 8: |
98 /* Emulated palette using ColourTrans */ | 99 /* Emulated palette using ColourTrans */ |
99 flags |= SDL_HWPALETTE; | 100 flags |= SDL_HWPALETTE; |
100 break; | 101 break; |
101 | 102 |
102 case 15: | 103 case 15: |
103 case 16: | 104 case 16: |
104 Bmask = 0x00007c00; | 105 Bmask = 0x00007c00; |
105 Gmask = 0x000003e0; | 106 Gmask = 0x000003e0; |
106 Rmask = 0x0000001f; | 107 Rmask = 0x0000001f; |
107 bytesPerPixel = 2; | 108 bytesPerPixel = 2; |
108 break; | 109 break; |
109 | 110 |
110 case 32: | 111 case 32: |
111 Bmask = 0x00ff0000; | 112 Bmask = 0x00ff0000; |
112 Gmask = 0x0000ff00; | 113 Gmask = 0x0000ff00; |
113 Rmask = 0x000000ff; | 114 Rmask = 0x000000ff; |
114 bytesPerPixel = 4; | 115 bytesPerPixel = 4; |
115 break; | 116 break; |
116 | 117 |
117 default: | 118 default: |
118 SDL_SetError("Pixel depth not supported"); | 119 SDL_SetError ("Pixel depth not supported"); |
119 return NULL; | 120 return NULL; |
120 break; | 121 break; |
121 } | 122 } |
122 | 123 |
123 /* printf("Setting mode %dx%d\n", width, height);*/ | 124 /* printf("Setting mode %dx%d\n", width, height);*/ |
124 | 125 |
125 /* Allocate the new pixel format for the screen */ | 126 /* Allocate the new pixel format for the screen */ |
126 if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { | 127 if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, 0)) { |
127 SDL_SetError("Couldn't allocate new pixel format for requested mode"); | 128 SDL_SetError |
128 return(NULL); | 129 ("Couldn't allocate new pixel format for requested mode"); |
129 } | 130 return (NULL); |
130 | 131 } |
131 /* Set up the new mode framebuffer */ | 132 |
132 current->w = width; | 133 /* Set up the new mode framebuffer */ |
133 this->hidden->height = current->h = height; | 134 current->w = width; |
134 | 135 this->hidden->height = current->h = height; |
135 if (bpp == 15) bpp = 16; | 136 |
136 buffer = WIMP_CreateBuffer(width, height, bpp); | 137 if (bpp == 15) |
137 if (buffer == NULL) | 138 bpp = 16; |
138 { | 139 buffer = WIMP_CreateBuffer (width, height, bpp); |
139 SDL_SetError("Couldn't create sprite for video memory"); | 140 if (buffer == NULL) { |
140 return (NULL); | 141 SDL_SetError ("Couldn't create sprite for video memory"); |
141 } | 142 return (NULL); |
142 | 143 } |
143 this->hidden->bank[0] = buffer + 60; /* Start of sprite data */ | 144 |
144 if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ | 145 this->hidden->bank[0] = buffer + 60; /* Start of sprite data */ |
145 | 146 if (bpp == 8) |
146 this->hidden->bank[1] = buffer; /* Start of buffer */ | 147 this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ |
147 | 148 |
148 /* Remember sprite buffer so it can be freed later */ | 149 this->hidden->bank[1] = buffer; /* Start of buffer */ |
149 if (this->hidden->alloc_bank) SDL_free(this->hidden->alloc_bank); | 150 |
150 this->hidden->alloc_bank = buffer; | 151 /* Remember sprite buffer so it can be freed later */ |
151 | 152 if (this->hidden->alloc_bank) |
152 current->pitch = width * bytesPerPixel; | 153 SDL_free (this->hidden->alloc_bank); |
153 if ((current->pitch & 3)) | 154 this->hidden->alloc_bank = buffer; |
154 { | 155 |
155 /* Sprites are 32bit word aligned */ | 156 current->pitch = width * bytesPerPixel; |
156 current->pitch += (4 - (current->pitch & 3)); | 157 if ((current->pitch & 3)) { |
157 } | 158 /* Sprites are 32bit word aligned */ |
158 | 159 current->pitch += (4 - (current->pitch & 3)); |
159 current->flags = flags | SDL_PREALLOC; | 160 } |
160 | 161 |
161 WIMP_ReadModeInfo(this); | 162 current->flags = flags | SDL_PREALLOC; |
162 | 163 |
163 SDL_memset(this->hidden->bank[0], 0, height * current->pitch); | 164 WIMP_ReadModeInfo (this); |
164 | 165 |
165 this->hidden->current_bank = 0; | 166 SDL_memset (this->hidden->bank[0], 0, height * current->pitch); |
166 current->pixels = this->hidden->bank[0]; | 167 |
167 | 168 this->hidden->current_bank = 0; |
168 | 169 current->pixels = this->hidden->bank[0]; |
169 if (WIMP_SetupWindow(this, current) == 0) | 170 |
170 { | 171 |
171 SDL_SetError("Unable to create window to display surface"); | 172 if (WIMP_SetupWindow (this, current) == 0) { |
172 return NULL; | 173 SDL_SetError ("Unable to create window to display surface"); |
173 } | 174 return NULL; |
174 | 175 } |
175 /* Reset device functions for the wimp */ | 176 |
176 WIMP_SetDeviceMode(this); | 177 /* Reset device functions for the wimp */ |
177 | 178 WIMP_SetDeviceMode (this); |
178 /* Needs to set up plot info after window has been created */ | 179 |
179 /* Not sure why, but plots don't work if I do it earlier */ | 180 /* Needs to set up plot info after window has been created */ |
180 WIMP_SetupPlotInfo(this); | 181 /* Not sure why, but plots don't work if I do it earlier */ |
181 | 182 WIMP_SetupPlotInfo (this); |
182 /* Poll until window is shown */ | 183 |
183 { | 184 /* Poll until window is shown */ |
184 /* We wait until it gets the focus, but give up after 5 seconds | 185 { |
185 in case the focus is prevented in any way. | 186 /* We wait until it gets the focus, but give up after 5 seconds |
186 */ | 187 in case the focus is prevented in any way. |
187 Uint32 now = SDL_GetTicks(); | 188 */ |
188 while (!hasFocus && SDL_GetTicks() - now < 5000) | 189 Uint32 now = SDL_GetTicks (); |
189 { | 190 while (!hasFocus && SDL_GetTicks () - now < 5000) { |
190 WIMP_Poll(this, 0); | 191 WIMP_Poll (this, 0); |
191 } | 192 } |
192 } | 193 } |
193 | 194 |
194 /* We're done */ | 195 /* We're done */ |
195 return(current); | 196 return (current); |
196 } | 197 } |
197 | 198 |
198 | 199 |
199 void WIMP_ReadModeInfo(_THIS) | 200 void |
200 { | 201 WIMP_ReadModeInfo (_THIS) |
201 _kernel_swi_regs regs; | 202 { |
202 int vars[6]; | 203 _kernel_swi_regs regs; |
203 int vals[5]; | 204 int vars[6]; |
204 | 205 int vals[5]; |
205 vars[0] = 4; /* XEig */ | 206 |
206 vars[1] = 5; /* YEig */ | 207 vars[0] = 4; /* XEig */ |
207 vars[2] = 9; /* Log base 2 bpp */ | 208 vars[1] = 5; /* YEig */ |
208 vars[3] = 11; /* Screen Width - 1 */ | 209 vars[2] = 9; /* Log base 2 bpp */ |
209 vars[4] = 12; /* Screen Depth - 1 */ | 210 vars[3] = 11; /* Screen Width - 1 */ |
210 vars[5] = -1; /* Terminate list */ | 211 vars[4] = 12; /* Screen Depth - 1 */ |
211 | 212 vars[5] = -1; /* Terminate list */ |
212 regs.r[0] = (int)vars; | 213 |
213 regs.r[1] = (int)vals; | 214 regs.r[0] = (int) vars; |
214 _kernel_swi(OS_ReadVduVariables, ®s, ®s); | 215 regs.r[1] = (int) vals; |
215 this->hidden->xeig = vals[0]; | 216 _kernel_swi (OS_ReadVduVariables, ®s, ®s); |
216 this->hidden->yeig = vals[1]; | 217 this->hidden->xeig = vals[0]; |
217 this->hidden->screen_bpp = 1 << vals[2]; | 218 this->hidden->yeig = vals[1]; |
218 this->hidden->screen_width = vals[3] + 1; | 219 this->hidden->screen_bpp = 1 << vals[2]; |
219 this->hidden->screen_height = vals[4] + 1; | 220 this->hidden->screen_width = vals[3] + 1; |
221 this->hidden->screen_height = vals[4] + 1; | |
220 } | 222 } |
221 | 223 |
222 /* Set device function to call the correct versions for running | 224 /* Set device function to call the correct versions for running |
223 in a wimp window */ | 225 in a wimp window */ |
224 | 226 |
225 void WIMP_SetDeviceMode(_THIS) | 227 void |
226 { | 228 WIMP_SetDeviceMode (_THIS) |
227 if (this->UpdateRects == WIMP_UpdateRects) return; /* Already set up */ | 229 { |
228 | 230 if (this->UpdateRects == WIMP_UpdateRects) |
229 this->SetColors = WIMP_SetColors; | 231 return; /* Already set up */ |
230 this->UpdateRects = WIMP_UpdateRects; | 232 |
231 | 233 this->SetColors = WIMP_SetColors; |
232 this->FlipHWSurface = NULL; | 234 this->UpdateRects = WIMP_UpdateRects; |
233 | 235 |
234 this->SetCaption = WIMP_SetWMCaption; | 236 this->FlipHWSurface = NULL; |
235 this->SetIcon = NULL; | 237 |
236 this->IconifyWindow = NULL; | 238 this->SetCaption = WIMP_SetWMCaption; |
237 | 239 this->SetIcon = NULL; |
238 this->ShowWMCursor = WIMP_ShowWMCursor; | 240 this->IconifyWindow = NULL; |
239 this->WarpWMCursor = WIMP_WarpWMCursor; | 241 |
240 | 242 this->ShowWMCursor = WIMP_ShowWMCursor; |
241 this->ToggleFullScreen = RISCOS_ToggleFullScreen; | 243 this->WarpWMCursor = WIMP_WarpWMCursor; |
242 | 244 |
243 this->PumpEvents = WIMP_PumpEvents; | 245 this->ToggleFullScreen = RISCOS_ToggleFullScreen; |
246 | |
247 this->PumpEvents = WIMP_PumpEvents; | |
244 } | 248 } |
245 | 249 |
246 /* Setup the Window to display the surface */ | 250 /* Setup the Window to display the surface */ |
247 unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface) | 251 unsigned int |
248 { | 252 WIMP_SetupWindow (_THIS, SDL_Surface * surface) |
249 _kernel_swi_regs regs; | 253 { |
250 int window_data[23]; | 254 _kernel_swi_regs regs; |
251 int *window_block = window_data+1; | 255 int window_data[23]; |
252 int x = (this->hidden->screen_width - surface->w) / 2; | 256 int *window_block = window_data + 1; |
253 int y = (this->hidden->screen_height - surface->h) / 2; | 257 int x = (this->hidden->screen_width - surface->w) / 2; |
254 int xeig = this->hidden->xeig; | 258 int y = (this->hidden->screen_height - surface->h) / 2; |
255 int yeig = this->hidden->yeig; | 259 int xeig = this->hidden->xeig; |
260 int yeig = this->hidden->yeig; | |
256 | 261 |
257 mouseInWindow = 0; | 262 mouseInWindow = 0; |
258 | 263 |
259 /* Always delete the window and recreate on a change */ | 264 /* Always delete the window and recreate on a change */ |
260 if (this->hidden->window_handle) WIMP_DeleteWindow(this); | 265 if (this->hidden->window_handle) |
261 | 266 WIMP_DeleteWindow (this); |
262 /* Setup window co-ordinates */ | 267 |
263 window_block[0] = x << xeig; | 268 /* Setup window co-ordinates */ |
264 window_block[1] = y << yeig; | 269 window_block[0] = x << xeig; |
265 window_block[2] = window_block[0] + (surface->w << xeig); | 270 window_block[1] = y << yeig; |
266 window_block[3] = window_block[1] + (surface->h << yeig); | 271 window_block[2] = window_block[0] + (surface->w << xeig); |
267 | 272 window_block[3] = window_block[1] + (surface->h << yeig); |
268 | 273 |
269 window_block[4] = 0; /* Scroll offsets */ | 274 |
270 window_block[5] = 0; | 275 window_block[4] = 0; /* Scroll offsets */ |
271 window_block[6] = -1; /* Open on top of window stack */ | 276 window_block[5] = 0; |
272 | 277 window_block[6] = -1; /* Open on top of window stack */ |
273 window_block[7] = 0x85040042; /* Window flags */ | 278 |
274 if (riscos_closeaction != 0) window_block[7] |= 0x2000000; | 279 window_block[7] = 0x85040042; /* Window flags */ |
275 | 280 if (riscos_closeaction != 0) |
276 /* TODO: Take into account surface->flags */ | 281 window_block[7] |= 0x2000000; |
277 | 282 |
278 window_block[8] = 0xff070207; /* Window colours */ | 283 /* TODO: Take into account surface->flags */ |
279 window_block[9] = 0x000c0103; | 284 |
280 window_block[10] = 0; /* Work area minimum */ | 285 window_block[8] = 0xff070207; /* Window colours */ |
281 window_block[11] = -surface->h << yeig; | 286 window_block[9] = 0x000c0103; |
282 window_block[12] = surface->w << xeig; /* Work area maximum */ | 287 window_block[10] = 0; /* Work area minimum */ |
283 window_block[13] = 0; | 288 window_block[11] = -surface->h << yeig; |
284 window_block[14] = 0x2700013d; /* Title icon flags */ | 289 window_block[12] = surface->w << xeig; /* Work area maximum */ |
285 window_block[15] = 0x00003000; /* Work area flags - Mouse click down reported */ | 290 window_block[13] = 0; |
286 window_block[16] = 1; /* Sprite area control block pointer */ | 291 window_block[14] = 0x2700013d; /* Title icon flags */ |
287 window_block[17] = 0x00100010; /* Minimum window size (width & height) (16x16)*/ | 292 window_block[15] = 0x00003000; /* Work area flags - Mouse click down reported */ |
288 window_block[18] = (int)this->hidden->title; /* Title data */ | 293 window_block[16] = 1; /* Sprite area control block pointer */ |
289 window_block[19] = -1; | 294 window_block[17] = 0x00100010; /* Minimum window size (width & height) (16x16) */ |
290 window_block[20] = 256; | 295 window_block[18] = (int) this->hidden->title; /* Title data */ |
291 window_block[21] = 0; /* Number of icons */ | 296 window_block[19] = -1; |
292 | 297 window_block[20] = 256; |
293 regs.r[1] = (unsigned int)(window_block); | 298 window_block[21] = 0; /* Number of icons */ |
294 | 299 |
295 /* Create the window */ | 300 regs.r[1] = (unsigned int) (window_block); |
296 if (_kernel_swi(Wimp_CreateWindow, ®s, ®s) == NULL) | 301 |
297 { | 302 /* Create the window */ |
298 this->hidden->window_handle = window_data[0] = regs.r[0]; | 303 if (_kernel_swi (Wimp_CreateWindow, ®s, ®s) == NULL) { |
299 | 304 this->hidden->window_handle = window_data[0] = regs.r[0]; |
300 /* Show the window on the screen */ | 305 |
301 regs.r[1] = (unsigned int)window_data; | 306 /* Show the window on the screen */ |
302 if (_kernel_swi(Wimp_OpenWindow, ®s, ®s) == NULL) | 307 regs.r[1] = (unsigned int) window_data; |
303 { | 308 if (_kernel_swi (Wimp_OpenWindow, ®s, ®s) == NULL) { |
304 WIMP_SetFocus(this->hidden->window_handle); | 309 WIMP_SetFocus (this->hidden->window_handle); |
305 } else | 310 } else { |
306 { | 311 WIMP_DeleteWindow (this); |
307 WIMP_DeleteWindow(this); | 312 } |
308 } | 313 } |
309 } | 314 |
310 | 315 return this->hidden->window_handle; |
311 return this->hidden->window_handle; | |
312 } | 316 } |
313 | 317 |
314 /* Destroy the Window */ | 318 /* Destroy the Window */ |
315 | 319 |
316 void WIMP_DeleteWindow(_THIS) | 320 void |
317 { | 321 WIMP_DeleteWindow (_THIS) |
318 _kernel_swi_regs regs; | 322 { |
319 regs.r[1] = (unsigned int)&(this->hidden->window_handle); | 323 _kernel_swi_regs regs; |
320 _kernel_swi(Wimp_DeleteWindow, ®s, ®s); | 324 regs.r[1] = (unsigned int) &(this->hidden->window_handle); |
321 this->hidden->window_handle = 0; | 325 _kernel_swi (Wimp_DeleteWindow, ®s, ®s); |
322 } | 326 this->hidden->window_handle = 0; |
323 | 327 } |
324 | 328 |
325 void WIMP_UpdateRects(_THIS, int numrects, SDL_Rect *rects) | 329 |
326 { | 330 void |
327 _kernel_swi_regs regs; | 331 WIMP_UpdateRects (_THIS, int numrects, SDL_Rect * rects) |
328 int update_block[12]; | 332 { |
329 int xeig = this->hidden->xeig; | 333 _kernel_swi_regs regs; |
330 int yeig = this->hidden->yeig; | 334 int update_block[12]; |
331 int j; | 335 int xeig = this->hidden->xeig; |
332 update_block[0] = this->hidden->window_handle; | 336 int yeig = this->hidden->yeig; |
333 | 337 int j; |
334 for (j = 0; j < numrects; j++) | 338 update_block[0] = this->hidden->window_handle; |
335 { | 339 |
336 update_block[1] = rects[j].x << xeig; /* Min X */ | 340 for (j = 0; j < numrects; j++) { |
337 update_block[4] = -(rects[j].y << yeig); | 341 update_block[1] = rects[j].x << xeig; /* Min X */ |
338 update_block[3] = update_block[1] + (rects[j].w << xeig); | 342 update_block[4] = -(rects[j].y << yeig); |
339 update_block[2] = update_block[4] - (rects[j].h << yeig); | 343 update_block[3] = update_block[1] + (rects[j].w << xeig); |
340 | 344 update_block[2] = update_block[4] - (rects[j].h << yeig); |
341 regs.r[1] = (int)update_block; | 345 |
342 /* Update window can fail if called before first poll */ | 346 regs.r[1] = (int) update_block; |
343 if (_kernel_swi(Wimp_UpdateWindow, ®s, ®s) == 0) | 347 /* Update window can fail if called before first poll */ |
344 { | 348 if (_kernel_swi (Wimp_UpdateWindow, ®s, ®s) == 0) { |
345 while (regs.r[0]) | 349 while (regs.r[0]) { |
346 { | 350 WIMP_PlotSprite (this, update_block[1], update_block[2]); |
347 WIMP_PlotSprite(this, update_block[1], update_block[2]); | 351 _kernel_swi (Wimp_GetRectangle, ®s, ®s); |
348 _kernel_swi(Wimp_GetRectangle, ®s, ®s); | 352 } |
349 } | 353 } |
350 } | 354 } |
351 } | 355 } |
352 } | 356 |
353 | 357 |
354 | 358 int |
355 int WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | 359 WIMP_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) |
356 { | 360 { |
357 unsigned int *pal = (unsigned int *)(this->hidden->bank[1]+60); | 361 unsigned int *pal = (unsigned int *) (this->hidden->bank[1] + 60); |
358 int j; | 362 int j; |
359 SDL_Rect update; | 363 SDL_Rect update; |
360 | 364 |
361 pal += firstcolor*2; | 365 pal += firstcolor * 2; |
362 for (j = 0; j < ncolors; j++) | 366 for (j = 0; j < ncolors; j++) { |
363 { | 367 *pal = (((unsigned int) colors->r) << 8) |
364 *pal = (((unsigned int)colors->r) << 8) | 368 + (((unsigned int) colors->g) << 16) |
365 + (((unsigned int)colors->g) << 16) | 369 + (((unsigned int) colors->b) << 24); |
366 + (((unsigned int)colors->b) << 24); | 370 pal[1] = *pal; |
367 pal[1] = *pal; | 371 pal += 2; |
368 pal += 2; | 372 colors++; |
369 colors++; | 373 } |
370 } | 374 |
371 | 375 WIMP_SetupPlotInfo (this); |
372 WIMP_SetupPlotInfo(this); | 376 |
373 | 377 /* Need to refresh the window */ |
374 /* Need to refresh the window */ | 378 update.x = 0; |
375 update.x = 0; | 379 update.y = 0; |
376 update.y = 0; | 380 update.w = SDL_VideoSurface->w; |
377 update.w = SDL_VideoSurface->w; | 381 update.h = SDL_VideoSurface->h; |
378 update.h = SDL_VideoSurface->h; | 382 WIMP_UpdateRects (this, 1, &update); |
379 WIMP_UpdateRects(this, 1, &update); | 383 |
380 | 384 return 1; |
381 return 1; | 385 } |
382 } | 386 |
383 | 387 void |
384 void WIMP_SetWMCaption(_THIS, const char *title, const char *icon) | 388 WIMP_SetWMCaption (_THIS, const char *title, const char *icon) |
385 { | 389 { |
386 _kernel_swi_regs regs; | 390 _kernel_swi_regs regs; |
387 | 391 |
388 SDL_strlcpy(this->hidden->title, title, SDL_arraysize(this->hidden->title)); | 392 SDL_strlcpy (this->hidden->title, title, |
389 | 393 SDL_arraysize (this->hidden->title)); |
390 if (RISCOS_GetWimpVersion() < 380) | 394 |
391 { | 395 if (RISCOS_GetWimpVersion () < 380) { |
392 int block[6]; | 396 int block[6]; |
393 | 397 |
394 regs.r[1] = (int)block; | 398 regs.r[1] = (int) block; |
395 _kernel_swi(Wimp_GetCaretPosition, ®s, ®s); | 399 _kernel_swi (Wimp_GetCaretPosition, ®s, ®s); |
396 if (block[0] == (int)this->hidden->window_handle) | 400 if (block[0] == (int) this->hidden->window_handle) { |
397 { | 401 regs.r[0] = -1; |
398 regs.r[0] = -1; | 402 _kernel_swi (Wimp_SetCaretPosition, ®s, ®s); |
399 _kernel_swi(Wimp_SetCaretPosition, ®s,®s); | 403 } else { |
400 } else | 404 regs.r[0] = this->hidden->window_handle; |
401 { | 405 regs.r[1] = -1; |
402 regs.r[0] = this->hidden->window_handle; | 406 regs.r[2] = -1; |
403 regs.r[1] = -1; | 407 regs.r[3] = -1; |
404 regs.r[2] = -1; | 408 _kernel_swi (Wimp_SetCaretPosition, ®s, ®s); |
405 regs.r[3] = -1; | 409 } |
406 _kernel_swi(Wimp_SetCaretPosition, ®s,®s); | 410 regs.r[0] = block[0]; |
407 } | 411 regs.r[1] = block[1]; |
408 regs.r[0] = block[0]; | 412 regs.r[2] = block[2]; |
409 regs.r[1] = block[1]; | 413 regs.r[3] = block[3]; |
410 regs.r[2] = block[2]; | 414 regs.r[4] = block[4]; |
411 regs.r[3] = block[3]; | 415 regs.r[5] = block[5]; |
412 regs.r[4] = block[4]; | 416 _kernel_swi (Wimp_SetCaretPosition, ®s, ®s); |
413 regs.r[5] = block[5]; | 417 } else { |
414 _kernel_swi(Wimp_SetCaretPosition, ®s,®s); | 418 regs.r[0] = this->hidden->window_handle; |
415 } else | 419 regs.r[1] = 0x4b534154; /* "TASK" */ |
416 { | 420 regs.r[2] = 3; /* Redraw title */ |
417 regs.r[0] = this->hidden->window_handle; | 421 _kernel_swi (Wimp_ForceRedraw, ®s, ®s); |
418 regs.r[1] = 0x4b534154; /* "TASK" */ | 422 } |
419 regs.r[2] = 3; /* Redraw title */ | 423 } |
420 _kernel_swi(Wimp_ForceRedraw, ®s, ®s); | 424 |
421 } | 425 void |
422 } | 426 WIMP_RefreshDesktop (_THIS) |
423 | 427 { |
424 void WIMP_RefreshDesktop(_THIS) | 428 int width = this->hidden->screen_width << this->hidden->xeig; |
425 { | 429 int height = this->hidden->screen_height << this->hidden->yeig; |
426 int width = this->hidden->screen_width << this->hidden->xeig; | 430 _kernel_swi_regs regs; |
427 int height = this->hidden->screen_height << this->hidden->yeig; | 431 regs.r[0] = -1; /* Whole screen */ |
428 _kernel_swi_regs regs; | 432 regs.r[1] = 0; |
429 regs.r[0] = -1; /* Whole screen */ | 433 regs.r[2] = 0; |
430 regs.r[1] = 0; | 434 regs.r[3] = width; |
431 regs.r[2] = 0; | 435 regs.r[4] = height; |
432 regs.r[3] = width; | 436 _kernel_swi (Wimp_ForceRedraw, ®s, ®s); |
433 regs.r[4] = height; | |
434 _kernel_swi(Wimp_ForceRedraw, ®s, ®s); | |
435 } | 437 } |
436 | 438 |
437 /* Toggle to window from full screen */ | 439 /* Toggle to window from full screen */ |
438 int WIMP_ToggleFromFullScreen(_THIS) | 440 int |
439 { | 441 WIMP_ToggleFromFullScreen (_THIS) |
440 int width = this->screen->w; | 442 { |
441 int height = this->screen->h; | 443 int width = this->screen->w; |
442 int bpp = this->screen->format->BitsPerPixel; | 444 int height = this->screen->h; |
443 char *buffer = NULL; | 445 int bpp = this->screen->format->BitsPerPixel; |
444 char *old_bank[2]; | 446 char *buffer = NULL; |
445 char *old_alloc_bank; | 447 char *old_bank[2]; |
446 | 448 char *old_alloc_bank; |
447 /* Ensure flags are OK */ | 449 |
448 this->screen->flags &= ~(SDL_DOUBLEBUF|SDL_HWSURFACE); | 450 /* Ensure flags are OK */ |
449 | 451 this->screen->flags &= ~(SDL_DOUBLEBUF | SDL_HWSURFACE); |
450 if (this->hidden->bank[0] == this->hidden->alloc_bank || riscos_backbuffer == 0) | 452 |
451 { | 453 if (this->hidden->bank[0] == this->hidden->alloc_bank |
452 /* Need to create a sprite for the screen and copy the data to it */ | 454 || riscos_backbuffer == 0) { |
453 char *data; | 455 /* Need to create a sprite for the screen and copy the data to it */ |
454 buffer = WIMP_CreateBuffer(width, height, bpp); | 456 char *data; |
455 data = buffer + 60; /* Start of sprite data */ | 457 buffer = WIMP_CreateBuffer (width, height, bpp); |
456 if (bpp == 8) data += 2048; /* 8bpp sprite have palette first */ | 458 data = buffer + 60; /* Start of sprite data */ |
457 | 459 if (bpp == 8) |
458 if (buffer == NULL) return 0; | 460 data += 2048; /* 8bpp sprite have palette first */ |
459 SDL_memcpy(data, this->hidden->bank[0], width * height * this->screen->format->BytesPerPixel); | 461 |
460 } | 462 if (buffer == NULL) |
461 /* else We've switch to full screen before so we already have a sprite */ | 463 return 0; |
462 | 464 SDL_memcpy (data, this->hidden->bank[0], |
463 old_bank[0] = this->hidden->bank[0]; | 465 width * height * this->screen->format->BytesPerPixel); |
464 old_bank[1] = this->hidden->bank[1]; | 466 } |
465 old_alloc_bank = this->hidden->alloc_bank; | 467 /* else We've switch to full screen before so we already have a sprite */ |
466 | 468 |
467 if (buffer != NULL) this->hidden->alloc_bank = buffer; | 469 old_bank[0] = this->hidden->bank[0]; |
468 | 470 old_bank[1] = this->hidden->bank[1]; |
469 this->hidden->bank[1] = this->hidden->alloc_bank; | 471 old_alloc_bank = this->hidden->alloc_bank; |
470 this->hidden->bank[0] = this->hidden->bank[1] + 60; /* Start of sprite data */ | 472 |
471 if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ | 473 if (buffer != NULL) |
472 | 474 this->hidden->alloc_bank = buffer; |
473 this->hidden->current_bank = 0; | 475 |
474 this->screen->pixels = this->hidden->bank[0]; | 476 this->hidden->bank[1] = this->hidden->alloc_bank; |
475 | 477 this->hidden->bank[0] = this->hidden->bank[1] + 60; /* Start of sprite data */ |
476 RISCOS_RestoreWimpMode(); | 478 if (bpp == 8) |
477 WIMP_ReadModeInfo(this); | 479 this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ |
478 if (WIMP_SetupWindow(this, this->screen)) | 480 |
479 { | 481 this->hidden->current_bank = 0; |
480 WIMP_SetDeviceMode(this); | 482 this->screen->pixels = this->hidden->bank[0]; |
481 WIMP_SetupPlotInfo(this); | 483 |
482 | 484 RISCOS_RestoreWimpMode (); |
483 if (riscos_backbuffer == 0) riscos_backbuffer = 1; | 485 WIMP_ReadModeInfo (this); |
484 | 486 if (WIMP_SetupWindow (this, this->screen)) { |
485 if (buffer && old_alloc_bank) SDL_free(old_alloc_bank); | 487 WIMP_SetDeviceMode (this); |
486 | 488 WIMP_SetupPlotInfo (this); |
487 return 1; | 489 |
488 } else | 490 if (riscos_backbuffer == 0) |
489 { | 491 riscos_backbuffer = 1; |
490 /* Drop back to full screen mode on failure */ | 492 |
491 this->hidden->bank[0] = old_bank[0]; | 493 if (buffer && old_alloc_bank) |
492 this->hidden->bank[1] = old_bank[1]; | 494 SDL_free (old_alloc_bank); |
493 this->hidden->alloc_bank = old_alloc_bank; | 495 |
494 if (buffer) SDL_free(buffer); | 496 return 1; |
495 | 497 } else { |
496 RISCOS_StoreWimpMode(); | 498 /* Drop back to full screen mode on failure */ |
497 FULLSCREEN_SetMode(width, height, bpp); | 499 this->hidden->bank[0] = old_bank[0]; |
498 } | 500 this->hidden->bank[1] = old_bank[1]; |
499 | 501 this->hidden->alloc_bank = old_alloc_bank; |
500 return 0; | 502 if (buffer) |
501 } | 503 SDL_free (buffer); |
504 | |
505 RISCOS_StoreWimpMode (); | |
506 FULLSCREEN_SetMode (width, height, bpp); | |
507 } | |
508 | |
509 return 0; | |
510 } | |
511 | |
512 /* vi: set ts=4 sw=4 expandtab: */ |