2 #define INTUI_V36_NAMES_ONLY 4 #include <exec/types.h> 5 #include <exec/memory.h> 6 #include <exec/execbase.h> 7 #include <pragmas/dos_pragmas.h> 8 #include <intuition/intuition.h> 9 #include <intuition/screens.h> 11 #include <clib/exec_protos.h> 12 #include <clib/graphics_protos.h> 13 #include <clib/intuition_protos.h> 20 extern struct DosLibrary *
DOSBase;
21 extern struct Library *IntuitionBase;
22 extern struct Library *GfxBase;
24 void __inline WaitVBL(buffered_screen *screen)
29 USHORT getLogicalBitmapIndex(buffered_screen *screen)
31 if (screen->double_buffer_enabled)
32 return (USHORT)((screen->physical)^1);
37 USHORT getPhysicalBitmapIndex(buffered_screen *screen)
39 return screen->physical;
42 void flipBuffers(buffered_screen *screen)
44 if (screen->double_buffer_enabled)
47 screen->physical = (USHORT)(screen->physical)^1;
48 screen->screen->RastPort.BitMap = screen->bitmaps[screen->physical];
49 screen->screen->ViewPort.RasInfo->BitMap = screen->bitmaps[screen->physical];
53 printf(
"flipBuffers() : physical screen: %d\n", screen->physical);
54 printf(
"flipBuffers() : logical screen: %d\n", getLogicalBitmapIndex(screen));
58 void presentPalette(buffered_screen *screen)
60 set_palette(&(screen->screen->ViewPort), &(screen->palettes[getPhysicalBitmapIndex(screen)]), 0, 1 << screen->screen->BitMap.Depth);
63 void presentScreen(buffered_screen *screen)
66 MakeScreen(screen->screen);
68 presentPalette(screen);
70 printf(
"presentScreen()\n");
74 void synchronizeBuffers(buffered_screen *screen)
76 if (screen->double_buffer_enabled)
79 for(i = 0; i < (1 << screen->screen->BitMap.Depth); i++)
80 screen->palettes[getLogicalBitmapIndex(screen)][i] = screen->palettes[getPhysicalBitmapIndex(screen)][i];
81 BltBitMap(screen->bitmaps[screen->physical], 0, 0, screen->bitmaps[getLogicalBitmapIndex(screen)], 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0xC0, 0xFF, NULL);
86 UWORD screenGetDepth(
void)
93 buffered_screen *openMainScreen(
void)
96 static buffered_screen bscreen;
97 struct NewScreen new_screen;
98 struct NewWindow new_window;
101 printf(
"openMainScreenCustom(%d, %d, %d, %d), depth = %d\n", SCREEN_WIDTH, SCREEN_HEIGHT, COLORS, DBUFFER_ENABLED, this_screen.depth);
104 bscreen.double_buffer_enabled = DBUFFER_ENABLED;
105 bscreen.physical = 0;
107 for(i = 0; i < (DBUFFER_ENABLED?2:1); i++)
109 bscreen.bitmaps[i] = setupBitMap(SCREEN_DEPTH, SCREEN_WIDTH, SCREEN_HEIGHT);
110 bscreen.palettes[i] = (amiga_color *)calloc(COLORS,
sizeof(amiga_color));
111 memset(bscreen.palettes[i], 0x000, COLORS);
115 printf(
"Allocated %d bitmaps!\n", i);
118 if (bscreen.bitmaps[i-1] != NULL)
120 new_screen.LeftEdge = 0;
121 new_screen.TopEdge = 0;
122 new_screen.Width = SCREEN_WIDTH;
123 new_screen.Height = SCREEN_HEIGHT;
124 new_screen.Depth = SCREEN_DEPTH;
125 new_screen.ViewModes = SPRITES;
126 new_screen.BlockPen = 0;
127 new_screen.DetailPen = 0;
129 if (SCREEN_WIDTH >= 640)
131 new_screen.ViewModes |= HIRES;
133 printf(
"openMainScreenCustom(), HIRES.\n");
137 if (SCREEN_HEIGHT >= 512)
139 new_screen.ViewModes |= LACE;
141 printf(
"openMainScreenCustom(), INTERLACE.\n");
145 new_screen.Type = CUSTOMSCREEN | CUSTOMBITMAP | SCREENQUIET;
146 new_screen.Font = NULL;
147 new_screen.DefaultTitle = NULL;
148 new_screen.Gadgets = NULL;
149 new_screen.CustomBitMap = bscreen.bitmaps[bscreen.physical];
151 bscreen.screen = OpenScreen(&new_screen);
152 if (bscreen.screen != NULL)
154 ShowTitle(bscreen.screen,
FALSE);
157 set_palette_to_grey(&(bscreen.screen->ViewPort), 0, COLORS);
162 new_window.LeftEdge = 0;
163 new_window.TopEdge = 0;
164 new_window.DetailPen = 0;
165 new_window.BlockPen = 0;
166 new_window.Title = NULL;
167 new_window.Width = SCREEN_WIDTH;
168 new_window.Height = SCREEN_HEIGHT;
169 new_window.BlockPen = 0;
170 new_window.DetailPen = 0;
171 new_window.IDCMPFlags = IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_RAWKEY | IDCMP_INTUITICKS;
172 new_window.Flags = WFLG_ACTIVATE | WFLG_OTHER_REFRESH | WFLG_RMBTRAP | WFLG_REPORTMOUSE | WFLG_WINDOWACTIVE | WFLG_GIMMEZEROZERO | WFLG_BORDERLESS | WFLG_NOCAREREFRESH;
173 new_window.Screen = bscreen.screen;
174 new_window.Type = CUSTOMSCREEN;
175 new_window.FirstGadget = NULL;
176 new_window.CheckMark = NULL;
177 new_window.BitMap = NULL;
179 bscreen.window = OpenWindow(&new_window);
180 if (bscreen.window == NULL)
182 printf(
"openMainScreenCustom(), OpenWindow() failed!\n");
183 closeMainScreen(&bscreen);
187 bscreen.screen->FirstWindow = bscreen.window;
190 ScreenToFront(bscreen.screen);
195 for(i = 0; i < (DBUFFER_ENABLED?2:1); i++)
197 freeBitMap(bscreen.bitmaps[i], SCREEN_DEPTH, SCREEN_WIDTH, SCREEN_HEIGHT);
198 free(bscreen.palettes[i]);
200 printf(
"openMainScreenCustom(), OpenScreen() failed!\n");
206 printf(
"openMainScreenCustom(), setupBitMaps() failed!\n");
211 void closeMainScreen(buffered_screen *screen)
214 printf(
"closeMainScreen()\n");
216 if (screen->screen->FirstWindow != NULL)
217 CloseWindow(screen->screen->FirstWindow);
219 if (screen->screen != NULL)
222 struct BitMap *_bmp[2];
223 for(i = 0; i < ((!(screen->double_buffer_enabled))?1:2); i++)
224 _bmp[i] = screen->bitmaps[i];
227 CloseScreen(screen->screen);
229 for(i = 0; i < ((!(screen->double_buffer_enabled))?1:2); i++)
231 freeBitMap(_bmp[i], SCREEN_DEPTH, SCREEN_WIDTH, SCREEN_HEIGHT);
232 free(screen->palettes[i]);
235 for(i = 0; i < ((!(screen->double_buffer_enabled))?1:2); i++)
236 screen->bitmaps[i] = NULL;
237 screen->screen = NULL;
238 screen->window = NULL;
241 printf(
"closeMainScreen(): new_screen is NULL!\n");
247 struct BitMap *setupBitMap(LONG depth, LONG width, LONG height)
249 struct BitMap *main_bitmap = NULL;
251 main_bitmap = (
struct BitMap *)AllocMem((LONG)
sizeof(
struct BitMap), MEMF_CLEAR);
252 if (main_bitmap != NULL)
254 InitBitMap(main_bitmap, depth, width, height);
256 if (setupPlanes(main_bitmap, depth, width, height) != NULL)
257 return (main_bitmap);
259 freePlanes(main_bitmap, depth, width, height);
262 if (main_bitmap != NULL)
264 FreeMem(main_bitmap, (LONG)
sizeof(
struct BitMap));
273 VOID freeBitMap(
struct BitMap *main_bitmaps, LONG depth, LONG width, LONG height)
275 if (main_bitmaps != NULL)
277 freePlanes(main_bitmaps, depth, width, height);
286 LONG setupPlanes(
struct BitMap *bitMap, LONG depth, LONG width, LONG height)
290 for (plane_num = 0; plane_num < depth; plane_num++)
292 bitMap->Planes[plane_num] = (PLANEPTR)AllocRaster(width, height);
294 if (bitMap->Planes[plane_num] != NULL)
295 BltClear(bitMap->Planes[plane_num], (width / 8) * height, 1);
298 freePlanes(bitMap, depth, width, height);
308 VOID freePlanes(
struct BitMap *bitMap, LONG depth, LONG width, LONG height)
312 for (plane_num = 0; plane_num < depth; plane_num++)
314 if (bitMap->Planes[plane_num] != NULL)
315 FreeRaster(bitMap->Planes[plane_num], width, height);
324 VOID add36k(
struct IntuitionBase *ibase)
326 long pl0,pl1,plb,ple;
334 scr = ibase->ActiveScreen;
335 win = ibase->ActiveWindow;
337 origheight=scr->Height;
338 SizeWindow(win,0,-150);
347 pl0=(long)bm->Planes[0];
348 pl1=(
long)bm->Planes[1];
351 ple=pl1+(640*origheight/8);
354 FreeMem((APTR)plb,ple-plb);
struct DosLibrary * DOSBase