1 #include <proto/exec.h>
2 #include <proto/graphics.h>
3 #include <proto/intuition.h>
4 #include <devices/keyboard.h>
5 #include <devices/rawkeycodes.h>
6 #include <devices/timer.h>
7 #include <exec/memory.h>
8 #include <graphics/gfxbase.h>
9 #include <libraries/bootmenu.h>
10 #include <aros/symbolsets.h>
12 #include "devs_private.h"
14 #include <aros/debug.h>
16 #include "bootmenu_intern.h"
18 #include LC_LIBDEFS_FILE
23 struct GfxBase
*GfxBase
;
27 static const ULONG coltab
[] = {
28 (16L << 16) + 0, /* 16 colors, loaded at index 0 */
31 0xB3B3B3B3, 0xB3B3B3B3, 0xB3B3B3B3, /* Grey70 */
32 0x00000000, 0x00000000, 0x00000000, /* Black */
33 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, /* White */
34 0x66666666, 0x88888888, 0xBBBBBBBB, /* AMIGA Blue */
36 0x00000000, 0x00000000, 0xFFFFFFFF, /* Blue */
37 0x00000000, 0xFFFFFFFF, 0x00000000, /* Green */
38 0xFFFFFFFF, 0x00000000, 0x00000000, /* Red */
39 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, /* Cyan */
41 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, /* Magenta */
42 0xEEEEEEEE, 0x82828282, 0xEEEEEEEE, /* Violet */
43 0xA5A5A5A5, 0x2A2A2A2A, 0x2A2A2A2A, /* Brown */
44 0xFFFFFFFF, 0xE4E4E4E4, 0xC4C4C4C4, /* Bisque */
46 0xE6E6E6E6, 0xE6E6E6E6, 0xFAFAFAFA, /* Lavender */
47 0x00000000, 0x00000000, 0x80808080, /* Navy */
48 0xF0F0F0F0, 0xE6E6E6E6, 0x8C8C8C8C, /* Khaki */
49 0xA0A0A0A0, 0x52525252, 0x2D2D2D2D, /* Sienna */
53 BOOL
initScreen(STRPTR gfxhiddname
, struct BootMenuBase
*bootmenubase
) {
54 struct TagItem modetags
[] =
57 {BIDTAG_DesiredWidth
, 640},
58 {BIDTAG_DesiredHeight
, 200},
63 GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 37);
66 if (LateGfxInit(gfxhiddname
))
68 modeid
= BestModeIDA(modetags
);
69 if (modeid
!= INVALID_ID
)
73 rp
.BitMap
= AllocScreenBitMap(modeid
);
76 vp
.RasInfo
= AllocMem(sizeof(struct RasInfo
), MEMF_ANY
| MEMF_CLEAR
);
79 vp
.RasInfo
->BitMap
= rp
.BitMap
;
80 vp
.ColorMap
= GetColorMap(4);
81 vp
.ColorMap
->VPModeID
= modeid
;
82 if (AttachPalExtra(vp
.ColorMap
, &vp
) == 0)
84 LoadRGB32(&vp
, (ULONG
*)coltab
);
85 rp
.BitMap
->Flags
|= BMF_AROS_HIDD
;
86 SetFont(&rp
, GfxBase
->DefaultFont
);
87 SetFrontBitMap(rp
.BitMap
, TRUE
);
89 rp
.Font
->tf_Accessors
++;
93 Text(&rp
, "Sucker", 6);
97 FreeMem(vp
.RasInfo
, sizeof(struct RasInfo
));
99 FreeBitMap(rp
.BitMap
);
103 CloseLibrary((struct Library
*)GfxBase
);
105 kprintf("no screen!\n");
114 static BOOL
init_gfx(STRPTR gfxclassname
, struct BootMenuBase
*bootmenubase
)
116 BOOL success
= FALSE
;
117 EnterFunc(bug("init_gfx(hiddbase=%s)\n", gfxclassname
));
119 /* Call private gfx.library call to init the HIDD.
120 Gfx library is responsable for closing the HIDD
121 library (although it will probably not be neccesary).
124 D(bug("calling private gfx LateGfxInit()\n"));
125 if (LateGfxInit(gfxclassname
))
130 if (LateIntuiInit(NULL
))
136 ReturnBool ("init_gfxhidd", success
);
140 static BOOL
init_device( STRPTR hiddclassname
, STRPTR devicename
, struct BootMenuBase
*bootmenubase
)
142 BOOL success
= FALSE
;
145 EnterFunc(bug("init_device(classname=%s)\n", hiddclassname
));
147 mp
= CreateMsgPort();
150 struct IORequest
*io
;
151 io
= CreateIORequest(mp
, sizeof ( struct IOStdReq
));
154 if (0 == OpenDevice(devicename
, 0, io
, 0))
156 #define ioStd(x) ((struct IOStdReq *)x)
157 ioStd(io
)->io_Command
= CMD_HIDDINIT
;
158 ioStd(io
)->io_Data
= hiddclassname
;
159 ioStd(io
)->io_Length
= strlen(hiddclassname
);
161 /* Let the device init the HIDD */
163 if (0 == io
->io_Error
)
173 ReturnBool("init_device", success
);
176 BOOL
initHidds(struct BootConfig
*bootcfg
, struct BootMenuBase
*bootmenubase
) {
178 OpenLibrary(bootcfg
->defaultgfx
.libname
, 0);
179 init_gfx(bootcfg
->defaultgfx
.hiddname
, bootmenubase
);
180 OpenLibrary(bootcfg
->defaultmouse
.libname
, 0);
181 init_device(bootcfg
->defaultmouse
.hiddname
, "gameport.device", bootmenubase
);
185 struct Gadget
*createGadgets(struct BootMenuBase_intern
*bootmenubase
) {
186 struct Gadget
*first
;
187 struct ButtonGadget
*last
;
189 last
= bootmenubase
->maingadgets
.boot
= createButton(16, 190, 280, 14, (struct Gadget
*)&first
, "Boot", BUTTON_BOOT
, bootmenubase
);
192 last
= bootmenubase
->maingadgets
.bootnss
= createButton(344, 190, 280, 14, last
->gadget
, "Boot With No Startup-Sequence", BUTTON_BOOT_WNSS
, bootmenubase
);
195 last
= bootmenubase
->maingadgets
.bootopt
= createButton(180, 63, 280, 14, last
->gadget
, "Boot Options...", BUTTON_BOOT_OPTIONS
, bootmenubase
);
198 last
= bootmenubase
->maingadgets
.displayopt
= createButton(180, 84, 280, 14, last
->gadget
, "Display Options...", BUTTON_DISPLAY_OPTIONS
, bootmenubase
);
201 last
= bootmenubase
->maingadgets
.expboarddiag
= createButton(180, 105, 280, 14, last
->gadget
, "Expansion Board Diagnostic...", BUTTON_EXPBOARDDIAG
, bootmenubase
);
207 void freeGadgets(struct BootMenuBase_intern
*bootmenubase
) {
209 if (bootmenubase
->maingadgets
.boot
!= NULL
)
210 freeButtonGadget(bootmenubase
->maingadgets
.boot
, bootmenubase
);
211 if (bootmenubase
->maingadgets
.bootnss
!= NULL
);
212 freeButtonGadget(bootmenubase
->maingadgets
.bootnss
, bootmenubase
);
213 if (bootmenubase
->maingadgets
.bootopt
!= NULL
)
214 freeButtonGadget(bootmenubase
->maingadgets
.bootopt
, bootmenubase
);
215 if (bootmenubase
->maingadgets
.displayopt
!= NULL
)
216 freeButtonGadget(bootmenubase
->maingadgets
.displayopt
, bootmenubase
);
217 if (bootmenubase
->maingadgets
.expboarddiag
!= NULL
)
218 freeButtonGadget(bootmenubase
->maingadgets
.expboarddiag
, bootmenubase
);
221 void msgLoop(struct BootMenuBase
*bootmenubase
, struct Window
*win
, struct BootConfig
*bcfg
) {
223 struct IntuiMessage
*msg
;
228 WaitPort(win
->UserPort
);
229 while ((msg
=(struct IntuiMessage
*)GetMsg(win
->UserPort
)))
231 if (msg
->Class
== IDCMP_GADGETUP
)
237 bcfg
->startup_sequence
= TRUE
;
240 case BUTTON_BOOT_WNSS
:
241 bcfg
->startup_sequence
= FALSE
;
246 ReplyMsg(&msg
->ExecMessage
);
249 while ((msg
=(struct IntuiMessage
*)GetMsg(win
->UserPort
)))
250 ReplyMsg(&msg
->ExecMessage
);
253 BOOL
initScreen(struct BootMenuBase_intern
*bootmenubase
, struct BootConfig
*bcfg
) {
255 struct TagItem scrtags
[] =
260 {SA_Pens
, (IPTR
)pens
},
263 struct TagItem wintags
[] =
265 {WA_Left
, 0}, /* 0 */
267 {WA_Width
, 640}, /* 2 */
268 {WA_Height
, 256}, /* 3 */
269 {WA_CustomScreen
, 0}, /* 4 */
270 {WA_Gadgets
, NULL
}, /* 5 */
271 {WA_IDCMP
, IDCMP_MOUSEBUTTONS
| IDCMP_MOUSEMOVE
| IDCMP_VANILLAKEY
| IDCMP_GADGETUP
| IDCMP_GADGETDOWN
},
272 {WA_Borderless
, TRUE
},
276 struct Gadget
*first
= NULL
;
278 bootmenubase
->scr
= OpenScreenTagList(NULL
, scrtags
);
279 if (bootmenubase
->scr
!= NULL
)
281 first
= createGadgets(bootmenubase
);
284 wintags
[2].ti_Data
= bootmenubase
->scr
->Width
;
285 wintags
[3].ti_Data
= bootmenubase
->scr
->Height
;
286 wintags
[4].ti_Data
= (IPTR
)bootmenubase
->scr
;
287 wintags
[5].ti_Data
= (IPTR
)first
;
288 bootmenubase
->win
= OpenWindowTagList(NULL
, wintags
);
289 if (bootmenubase
->win
!= NULL
)
291 SetAPen(bootmenubase
->win
->RPort
, 2);
292 Move(bootmenubase
->win
->RPort
, 215, 20);
293 Text(bootmenubase
->win
->RPort
, "AROS Early Startup Control", 26);
294 SetAPen(bootmenubase
->win
->RPort
, 1);
295 Move(bootmenubase
->win
->RPort
, 225, 40);
296 Text(bootmenubase
->win
->RPort
, "(what is PAL and NTSC?)", 23);
297 msgLoop(bootmenubase
, bootmenubase
->win
, bcfg
);
301 Alert(AT_DeadEnd
| AN_OpenWindow
);
302 CloseWindow(bootmenubase
->win
);
303 freeGadgets(bootmenubase
);
306 Alert(AT_DeadEnd
| AN_BadGadget
);
307 CloseScreen(bootmenubase
->scr
);
310 Alert(AT_DeadEnd
| AN_OpenScreen
);
314 void delay(struct BootMenuBase
*bootmenubase
, LONG secs
, LONG micro
) {
317 mp
= CreateMsgPort();
320 struct timerequest
*tr
;
321 tr
= (struct timerequest
*)CreateIORequest(mp
, sizeof(struct timerequest
));
324 if (OpenDevice("timer.device", UNIT_VBLANK
, (struct IORequest
*)tr
, 0) == 0)
326 #define ioStd(x) ((struct IOStdReq *)x)
327 ioStd(tr
)->io_Command
= TR_ADDREQUEST
;
328 tr
->tr_time
.tv_secs
= secs
;
329 tr
->tr_time
.tv_micro
= micro
;
330 DoIO((struct IORequest
*)tr
);
331 CloseDevice((struct IORequest
*)tr
);
333 DeleteIORequest((struct IORequest
*)tr
);
339 BOOL
buttonsPressed(struct BootMenuBase
*bootmenubase
, struct DefaultHidd
*kbd
) {
340 BOOL success
= FALSE
;
344 if (OpenLibrary(kbd
->libname
, 0) != NULL
)
346 if (init_device(kbd
->hiddname
, "keyboard.device", bootmenubase
))
348 delay(bootmenubase
, 1, 0);
349 mp
= CreateMsgPort();
352 struct IORequest
*io
;
353 io
= CreateIORequest(mp
, sizeof ( struct IOStdReq
));
356 if (0 == OpenDevice("keyboard.device", 0, io
, 0))
358 #define ioStd(x) ((struct IOStdReq *)x)
359 ioStd(io
)->io_Command
= KBD_READMATRIX
;
360 ioStd(io
)->io_Data
= matrix
;
361 ioStd(io
)->io_Length
= 16;
363 if (0 == io
->io_Error
)
365 if (matrix
[RAWKEY_SPACE
/8] & (1<<(RAWKEY_SPACE
%8)))
382 static int CheckAndDisplay(LIBBASETYPEPTR LIBBASE
)
384 static struct BootConfig bootcfg
=
387 {"vgah.hidd", "hidd.gfx.vga"},
388 {"kbd.hidd", "hidd.kbd.hw"},
389 {"mouse.hidd", "hidd.bus.mouse"},
394 LIBBASE
->bcfg
= bootcfg
;
396 /* init keyboard + check */
397 if (buttonsPressed(LIBBASE
, &LIBBASE
->bcfg
.defaultkbd
))
399 kprintf("Entering Boot Menu ...\n");
400 /* init mouse + gfx */
401 if (initHidds(&LIBBASE
->bcfg
, LIBBASE
))
403 initScreen(LIBBASE
, &LIBBASE
->bcfg
);
410 ADD2INITLIB(CheckAndDisplay
, 0)