Highlight selected menu item with > ... <.

Moved global variables on the stack.
Hide cursor while menu is displayed.
Print error message at correct location.
Reboot on error.
Display "Loading <name>".

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25089 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2008-04-20 18:42:59 +00:00
parent 7b51470a32
commit 7ca9a33b59
2 changed files with 255 additions and 135 deletions

View File

@ -2,19 +2,21 @@
// ./make_array kBootLoader bootman.bin
static const uint8 kBootLoader[] = {
0xb8, 0xc0, 0x07, 0x8e, 0xd8, 0x8e, 0xc0, 0x8e, 0xd0, 0xbc, 0xff, 0xff, 0xfc, 0xb4, 0x06, 0x30,
0xc0, 0xb7, 0x0f, 0x31, 0xc9, 0xba, 0x4f, 0x18, 0xcd, 0x10, 0xb7, 0x00, 0xb4, 0x02, 0xba, 0x1f,
0x01, 0xcd, 0x10, 0xbe, 0x83, 0x00, 0xb3, 0x0f, 0xe8, 0x2c, 0x00, 0xb4, 0x02, 0xba, 0x1b, 0x17,
0xb3, 0x07, 0xcd, 0x10, 0xbe, 0x96, 0x00, 0xe8, 0x1d, 0x00, 0xb4, 0x42, 0xb2, 0x80, 0xbe, 0x73,
0x00, 0xcd, 0x13, 0x72, 0x03, 0xe9, 0xb8, 0x01, 0xbe, 0xb1, 0x00, 0xb3, 0x04, 0xe8, 0x07, 0x00,
0xb4, 0x00, 0xcd, 0x16, 0xf4, 0xeb, 0xf9, 0x51, 0xe9, 0x11, 0x00, 0xb9, 0x01, 0x00, 0xb4, 0x09,
0xcd, 0x10, 0xb4, 0x03, 0xcd, 0x10, 0xfe, 0xc2, 0xb4, 0x02, 0xcd, 0x10, 0xac, 0x3c, 0x00, 0x75,
0xea, 0x59, 0xc3, 0x10, 0x00, 0x03, 0x00, 0x00, 0x02, 0xc0, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x48, 0x61, 0x69, 0x6b, 0x75, 0x20, 0x42, 0x6f, 0x6f, 0x74, 0x20, 0x4d, 0x61,
0x6e, 0x61, 0x67, 0x65, 0x72, 0x00, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x20, 0x61, 0x6e, 0x20,
0x4f, 0x53, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6d, 0x65, 0x6e, 0x75,
0x00, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x73,
0x65, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x21, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0xb8, 0xc0, 0x07, 0x8e, 0xd8, 0x8e, 0xc0, 0x8e, 0xd0, 0xbc, 0xf3, 0xff, 0x89, 0xe5, 0xfc, 0xb4,
0x06, 0x30, 0xc0, 0xb7, 0x0f, 0x31, 0xc9, 0xba, 0x4f, 0x18, 0xcd, 0x10, 0xe8, 0x63, 0x00, 0xb7,
0x00, 0xba, 0x1f, 0x01, 0x89, 0x56, 0x08, 0xbe, 0xa9, 0x00, 0xb3, 0x0f, 0xe8, 0x2f, 0x00, 0xba,
0x1b, 0x17, 0x89, 0x56, 0x08, 0xb3, 0x07, 0xbe, 0xbc, 0x00, 0xe8, 0x21, 0x00, 0xb4, 0x42, 0xb2,
0x80, 0xbe, 0x99, 0x00, 0xcd, 0x13, 0x72, 0x03, 0xe9, 0xb5, 0x01, 0xe8, 0x43, 0x00, 0xbe, 0xd7,
0x00, 0xb3, 0x04, 0xe8, 0x08, 0x00, 0xb4, 0x00, 0xcd, 0x16, 0xb2, 0x80, 0xcd, 0x19, 0x50, 0x53,
0x51, 0x52, 0x30, 0xff, 0xe9, 0x11, 0x00, 0x8b, 0x56, 0x08, 0xb4, 0x02, 0xcd, 0x10, 0xfe, 0x46,
0x08, 0xb9, 0x01, 0x00, 0xb4, 0x09, 0xcd, 0x10, 0xac, 0x3c, 0x00, 0x75, 0xea, 0x5a, 0x59, 0x5b,
0x58, 0xc3, 0xb4, 0x03, 0xcd, 0x10, 0x89, 0x4e, 0x0a, 0xb4, 0x01, 0xb9, 0x00, 0x20, 0xcd, 0x10,
0xc3, 0x8b, 0x4e, 0x0a, 0xb4, 0x01, 0xcd, 0x10, 0xc3, 0x10, 0x00, 0x03, 0x00, 0x00, 0x02, 0xc0,
0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x61, 0x69, 0x6b, 0x75, 0x20, 0x42,
0x6f, 0x6f, 0x74, 0x20, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x00, 0x53, 0x65, 0x6c, 0x65,
0x63, 0x74, 0x20, 0x61, 0x6e, 0x20, 0x4f, 0x53, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68,
0x65, 0x20, 0x6d, 0x65, 0x6e, 0x75, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61,
0x64, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x21, 0x00, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
@ -27,37 +29,42 @@ static const uint8 kBootLoader[] = {
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x55, 0xaa,
0xa1, 0x9a, 0x03, 0xa3, 0x47, 0x03, 0xb8, 0x13, 0x00, 0xf7, 0x26, 0x9c, 0x03, 0x89, 0xd3, 0x50,
0xb4, 0x00, 0xcd, 0x1a, 0x58, 0x01, 0xd0, 0x11, 0xcb, 0xa3, 0x4b, 0x03, 0x89, 0x1e, 0x4d, 0x03,
0xa0, 0x98, 0x03, 0xd0, 0xe8, 0xb3, 0x0c, 0x28, 0xc3, 0x88, 0x1e, 0x49, 0x03, 0xe8, 0x65, 0x00,
0x81, 0x3e, 0x9c, 0x03, 0xff, 0xff, 0x74, 0x27, 0xb4, 0x01, 0xcd, 0x16, 0x75, 0x21, 0xe8, 0x05,
0x00, 0x73, 0xf5, 0xe9, 0x9b, 0x00, 0xb4, 0x00, 0xcd, 0x1a, 0x3b, 0x0e, 0x4d, 0x03, 0x72, 0x08,
0x77, 0x08, 0x3b, 0x16, 0x4b, 0x03, 0x77, 0x02, 0xf8, 0xc3, 0xf9, 0xc3, 0xe8, 0x36, 0x00, 0xb4,
0x00, 0xcd, 0x16, 0x80, 0xfc, 0x50, 0x74, 0x0c, 0x80, 0xfc, 0x48, 0x74, 0x18, 0x80, 0xfc, 0x1c,
0x74, 0x6f, 0xeb, 0xeb, 0xa1, 0x47, 0x03, 0x40, 0x3b, 0x06, 0x98, 0x03, 0x75, 0x02, 0x31, 0xc0,
0xa3, 0x47, 0x03, 0xeb, 0xd7, 0xa1, 0x47, 0x03, 0x09, 0xc0, 0x75, 0x03, 0xa1, 0x98, 0x03, 0x48,
0xa3, 0x47, 0x03, 0xeb, 0xc7, 0xa0, 0x49, 0x03, 0xa2, 0x4a, 0x03, 0xbe, 0x9e, 0x03, 0x31, 0xc9,
0xac, 0xfe, 0xc8, 0xd0, 0xe8, 0xb2, 0x28, 0x28, 0xc2, 0x8a, 0x36, 0x4a, 0x03, 0xb4, 0x02, 0xcd,
0x10, 0x89, 0xcf, 0x81, 0xe7, 0x03, 0x00, 0x8a, 0x9d, 0x5f, 0x03, 0x3b, 0x0e, 0x47, 0x03, 0x75,
0x03, 0x80, 0xf3, 0x08, 0xe8, 0x57, 0x00, 0x81, 0xc6, 0x09, 0x00, 0xfe, 0x06, 0x4a, 0x03, 0x41,
0x3b, 0x0e, 0x98, 0x03, 0x75, 0xca, 0xb4, 0x02, 0xba, 0x1a, 0x15, 0xba, 0x1c, 0x18, 0xcd, 0x10,
0xc3, 0xbe, 0x9e, 0x03, 0x8b, 0x0e, 0x47, 0x03, 0x41, 0x30, 0xe4, 0xe9, 0x04, 0x00, 0x81, 0xc6,
0x09, 0x00, 0xac, 0x01, 0xc6, 0xe2, 0xf7, 0xac, 0x88, 0xc2, 0xbf, 0x57, 0x03, 0xb9, 0x04, 0x00,
0xad, 0xab, 0xe2, 0xfc, 0xb4, 0x42, 0xbe, 0x4f, 0x03, 0xcd, 0x13, 0xbe, 0x63, 0x03, 0x72, 0x2a,
0xa1, 0xfe, 0x01, 0x3d, 0x55, 0xaa, 0xbe, 0x79, 0x03, 0x75, 0x1f, 0xe9, 0xe2, 0xfc, 0x51, 0xe9,
0x11, 0x00, 0xb9, 0x01, 0x00, 0xb4, 0x09, 0xcd, 0x10, 0xb4, 0x03, 0xcd, 0x10, 0xfe, 0xc2, 0xb4,
0x02, 0xcd, 0x10, 0xac, 0x3c, 0x00, 0x75, 0xea, 0x59, 0xc3, 0xbb, 0x0f, 0x00, 0xe8, 0xde, 0xff,
0xb4, 0x00, 0xcd, 0x16, 0xf4, 0xeb, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0x00, 0x01, 0x00, 0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x04, 0x03, 0x02, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67,
0x20, 0x73, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x00, 0x4e, 0x6f, 0x74, 0x20, 0x61, 0x20, 0x62,
0x6f, 0x6f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f,
0x6e, 0x00, 0x42, 0x6f, 0x6f, 0x74, 0x21, 0x00
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa,
0xa1, 0x09, 0x04, 0x89, 0x46, 0x00, 0xb8, 0x13, 0x00, 0xf7, 0x26, 0x0b, 0x04, 0x89, 0xd3, 0x50,
0xb4, 0x00, 0xcd, 0x1a, 0x58, 0x01, 0xd0, 0x11, 0xcb, 0x89, 0x46, 0x04, 0x89, 0x5e, 0x06, 0xa0,
0x07, 0x04, 0xd0, 0xe8, 0xb3, 0x0c, 0x28, 0xc3, 0x88, 0x5e, 0x02, 0xe8, 0x64, 0x00, 0x81, 0x3e,
0x0b, 0x04, 0xff, 0xff, 0x74, 0x25, 0xb4, 0x01, 0xcd, 0x16, 0x75, 0x1f, 0xe8, 0x05, 0x00, 0x73,
0xf5, 0xe9, 0xa6, 0x00, 0xb4, 0x00, 0xcd, 0x1a, 0x3b, 0x4e, 0x06, 0x72, 0x07, 0x77, 0x07, 0x3b,
0x56, 0x04, 0x77, 0x02, 0xf8, 0xc3, 0xf9, 0xc3, 0xe8, 0x37, 0x00, 0xb4, 0x00, 0xcd, 0x16, 0x80,
0xfc, 0x50, 0x74, 0x0d, 0x80, 0xfc, 0x48, 0x74, 0x19, 0x80, 0xfc, 0x1c, 0x75, 0xed, 0xe9, 0x79,
0x00, 0x8b, 0x46, 0x00, 0x40, 0x3b, 0x06, 0x07, 0x04, 0x75, 0x02, 0x31, 0xc0, 0x89, 0x46, 0x00,
0xeb, 0xd6, 0x8b, 0x46, 0x00, 0x09, 0xc0, 0x75, 0x03, 0xa1, 0x07, 0x04, 0x48, 0x89, 0x46, 0x00,
0xeb, 0xc6, 0x8a, 0x46, 0x02, 0x88, 0x46, 0x09, 0xbe, 0x0d, 0x04, 0x31, 0xc9, 0xac, 0x04, 0x03,
0xd0, 0xe8, 0xb2, 0x28, 0x28, 0xc2, 0x88, 0x56, 0x08, 0xb0, 0x10, 0xe8, 0x30, 0x00, 0xfe, 0x46,
0x08, 0x89, 0xcf, 0x81, 0xe7, 0x03, 0x00, 0x8a, 0x9d, 0xcc, 0x03, 0x3b, 0x4e, 0x00, 0x75, 0x03,
0x80, 0xf3, 0x08, 0xe8, 0xb6, 0x00, 0x81, 0xc6, 0x09, 0x00, 0x80, 0x46, 0x08, 0x01, 0xb0, 0x11,
0xe8, 0x0b, 0x00, 0xfe, 0x46, 0x09, 0x41, 0x3b, 0x0e, 0x07, 0x04, 0x75, 0xc0, 0xc3, 0x3b, 0x4e,
0x00, 0x74, 0x02, 0xb0, 0x20, 0xb3, 0x0f, 0xe9, 0xb6, 0x00, 0xe8, 0xa4, 0xfd, 0xe8, 0x83, 0x00,
0xac, 0x88, 0xc2, 0xbf, 0xc4, 0x03, 0xb9, 0x04, 0x00, 0xad, 0xab, 0xe2, 0xfc, 0xb4, 0x42, 0xbe,
0xbc, 0x03, 0xcd, 0x13, 0xbe, 0xd0, 0x03, 0x72, 0x40, 0xa1, 0xfe, 0x01, 0x3d, 0x55, 0xaa, 0xbe,
0xe6, 0x03, 0x75, 0x35, 0xb4, 0x06, 0x30, 0xc0, 0xb7, 0x0f, 0x31, 0xc9, 0xba, 0x4f, 0x18, 0xcd,
0x10, 0xc7, 0x46, 0x08, 0x00, 0x00, 0xbe, 0xff, 0x03, 0xb3, 0x07, 0xe8, 0x4e, 0x00, 0xfe, 0x46,
0x08, 0xe8, 0x29, 0x00, 0x46, 0xe8, 0x44, 0x00, 0xba, 0x00, 0x01, 0x30, 0xff, 0xb4, 0x02, 0xcd,
0x10, 0xe8, 0x2f, 0x00, 0x8a, 0x14, 0xe9, 0xb7, 0xfc, 0xba, 0x1a, 0x15, 0x89, 0x56, 0x08, 0xbb,
0x0f, 0x00, 0xe8, 0x27, 0x00, 0xb4, 0x00, 0xcd, 0x16, 0xb2, 0x80, 0xcd, 0x19, 0xbe, 0x0d, 0x04,
0x8b, 0x4e, 0x00, 0x41, 0x30, 0xe4, 0xe9, 0x07, 0x00, 0xac, 0x01, 0xc6, 0x81, 0xc6, 0x09, 0x00,
0xe2, 0xf7, 0xc3, 0xe8, 0xe7, 0xff, 0xac, 0x30, 0xe4, 0x01, 0xc6, 0xc3, 0x50, 0x53, 0x51, 0x52,
0x30, 0xff, 0xe9, 0x11, 0x00, 0x8b, 0x56, 0x08, 0xb4, 0x02, 0xcd, 0x10, 0xfe, 0x46, 0x08, 0xb9,
0x01, 0x00, 0xb4, 0x09, 0xcd, 0x10, 0xac, 0x3c, 0x00, 0x75, 0xea, 0x5a, 0x59, 0x5b, 0x58, 0xc3,
0x50, 0x53, 0x51, 0x52, 0x30, 0xff, 0x8b, 0x56, 0x08, 0xb4, 0x02, 0xcd, 0x10, 0xfe, 0x46, 0x08,
0xb9, 0x01, 0x00, 0xb4, 0x09, 0xcd, 0x10, 0x5a, 0x59, 0x5b, 0x58, 0xc3, 0x10, 0x00, 0x01, 0x00,
0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x02, 0x03,
0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x65,
0x63, 0x74, 0x6f, 0x72, 0x73, 0x00, 0x4e, 0x6f, 0x74, 0x20, 0x61, 0x20, 0x62, 0x6f, 0x6f, 0x74,
0x61, 0x62, 0x6c, 0x65, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x4c,
0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x00
};

View File

@ -22,12 +22,15 @@
%assign BIOS_VIDEO_SERVICES 0x10
%assign BIOS_DISK_SERVICES 0x13
%assign BIOS_KEYBOARD_SERVICES 0x16
%assign BIOS_REBOOT 0x19
%assign BIOS_REBOOT 0x19 ; dl - boot drive number
%assign BIOS_TIME_SERVICES 0x1A
; video services
%assign SET_VIDEO_MODE 0x00 ; al - mode
%assign SET_CURSOR_SHAPE 0x01 ; ch - starting scan line (5 bits)
; cl - ending scan line (5 bits)
%assign SET_CURSOR 0x02 ; dl - column
; dh - row
; bh - page
@ -154,6 +157,18 @@ BITS 16
resb sizeof(%1) * %2
%endmacro
; Variables on stack
struc Locals
selection resw 1
firstLine resb 2 ; low byte used only
timeoutTicks resd 1
cursorX resb 1
cursorY resb 1
cursorShape resw 1
endstruc
cursorPosition equ cursorX
%macro DEBUG_PAUSE 0
push ax
mov ah, READ_CHAR
@ -161,7 +176,7 @@ BITS 16
pop ax
%endmacro
%macro clearScreen 0
%macro CLEAR_SCREEN 0
mov ah, SCROLL_UP
xor al, al
mov bh, WHITE
@ -171,24 +186,33 @@ BITS 16
%endmacro
; Prints a null terminated string
; bl ... color
; si ... offset to string
%macro printString 0
%macro PRINT_STRING 0
push ax
push bx
push cx
push dx
xor bh, bh ; write on page 0
jmp .loop_condition
.loop
mov dx, [bp + cursorPosition]
mov ah, SET_CURSOR
int BIOS_VIDEO_SERVICES
inc byte [bp + cursorX]
mov cx, 1
mov ah, WRITE_CHAR
int BIOS_VIDEO_SERVICES
mov ah, GET_CURSOR
int BIOS_VIDEO_SERVICES
inc dl
mov ah, SET_CURSOR
int BIOS_VIDEO_SERVICES
.loop_condition
lodsb
cmp al, 0
jnz .loop
pop dx
pop cx
pop bx
pop ax
ret
%endmacro
@ -222,29 +246,29 @@ stage1:
mov es, ax
mov ss, ax
mov sp, 0xFFFF ; Make stack empty
mov sp, 0xFFFF - sizeof(Locals) ; Make stack empty
mov bp, sp
cld ; String operations increment index registers
clearScreen
CLEAR_SCREEN
call hideCursor
mov bh, 0 ; Text output on page 0
; Print title centered at row 2
mov ah, SET_CURSOR
mov dx, 1 * 0x100 + (40 - TITLE_LENGTH / 2)
int BIOS_VIDEO_SERVICES
mov [bp + cursorPosition], dx
mov si, kTitle
mov bl, WHITE
call printstr
; Print message centered at second last row
mov ah, SET_CURSOR
mov dx, (TEXT_ROWS-2) * 0x100 + (40 - SELECT_OS_MESSAGE_LENGTH / 2)
mov bl, LIGHT_GRAY
int BIOS_VIDEO_SERVICES
mov [bp + cursorPosition], dx
mov bl, LIGHT_GRAY
mov si, kSelectOSMessage
call printstr
@ -257,18 +281,36 @@ stage1:
jmp stage2 ; Continue in loaded stage 2
.error:
call showCursor
mov si, kError
mov bl, RED
call printstr
.halt
mov ah, READ_CHAR
int BIOS_KEYBOARD_SERVICES
hlt
jmp .halt
mov dl, 0x80
int BIOS_REBOOT
printStringStage1:
printString
PRINT_STRING
hideCursor:
mov ah, GET_CURSOR
int BIOS_VIDEO_SERVICES
mov [bp + cursorShape], cx
mov ah, SET_CURSOR_SHAPE
mov cx, 0x2000
int BIOS_VIDEO_SERVICES
ret
showCursor:
mov cx, [bp + cursorShape]
mov ah, SET_CURSOR_SHAPE
int BIOS_VIDEO_SERVICES
ret
nextStageDAP:
istruc AddressPacket
at AddressPacket.packet_size, db 0x10
@ -284,10 +326,18 @@ kSelectOSMessage:
kError:
db 'Error loading sectors!', 0x00
; Fill the missing space to reach 510 byte
times 510 -($-$$) db 'B'
kStage1UnusedSpace equ 440 - ($-$$)
; Fill the missing space to reach byte 440
times kStage1UnusedSpace db 'B'
signature:
kDiskSignatue:
dw 0, 0
kReserved
dw 0
kPartitionTable
times 64 db 0
kMBRSignature:
; Magic marker "AA55" (to identify a valid boot record)
dw MBR_SIGNATURE
@ -303,7 +353,7 @@ signature:
stage2:
mov ax, [defaultItem] ; Select default item
mov [selection], ax
mov [bp + selection], ax
mov ax, TICKS_PER_SECOND ; Calculate timeout ticks
mul word [timeout]
@ -316,14 +366,14 @@ stage2:
pop ax ; Add current ticks
add ax, dx
adc bx, cx
mov [timeoutTicks], ax
mov [timeoutTicks + 2], bx
mov [bp + timeoutTicks], ax
mov [bp + timeoutTicks + 2], bx
mov al, [listItemCount] ; Calculate start row for menu
shr al, 1
mov bl, TEXT_ROWS / 2
sub bl, al ; y = TEXT_ROWS / 2 - number of items / 2
mov [firstLine], bl
mov [bp + firstLine], bl
call printMenu
@ -341,10 +391,10 @@ timeoutLoop:
isTimeoutReached:
mov ah, READ_CLOCK
int BIOS_TIME_SERVICES
cmp cx, [timeoutTicks + 2]
cmp cx, [bp + timeoutTicks + 2]
jb .returnFalse
ja .returnTrue
cmp dx, [timeoutTicks]
cmp dx, [bp + timeoutTicks]
ja .returnTrue
.returnFalse:
clc
@ -368,96 +418,89 @@ inputLoop:
je selectPreviousPartition
cmp ah, KEY_RETURN
je bootSelectedPartition
jmp inputLoop
jne inputLoop
jmp bootSelectedPartition
selectNextPartition:
mov ax, [selection]
mov ax, [bp + selection]
inc ax
cmp ax, [listItemCount]
jne .done ; At end of list?
xor ax, ax ; Then jump to first entry
.done:
mov [selection], ax
mov [bp + selection], ax
jmp mainLoop
selectPreviousPartition:
mov ax, [selection]
mov ax, [bp + selection]
or ax, ax
jnz .done ; At top of list?
mov ax, [listItemCount] ; Then jump to last entry
.done:
dec ax
mov [selection], ax
mov [bp + selection], ax
jmp mainLoop
; ======================= Print the OS list ============================
printMenu:
mov al, [firstLine]
mov [currentLine], al
mov al, [bp + firstLine]
mov [bp + cursorY], al
mov si, list ; Start at top of list
xor cx, cx ; The index of the current item
.loop:
lodsb ; String length incl. 0-terminator
dec al ; center menu item
add al, 3 ; center menu item
shr al, 1 ; x = TEXT_COLUMNS / 2 - length / 2
mov dl, TEXT_COLUMNS / 2
sub dl, al
mov dh, [currentLine]
mov ah, SET_CURSOR
int BIOS_VIDEO_SERVICES
mov [bp + cursorX], dl
mov al, TRIANGLE_TO_RIGHT
call updateMarker
inc byte [bp + cursorX]
mov di, cx
and di, 3
mov bl, [kColorTable + di] ; Text color
cmp cx, [selection]
cmp cx, [bp + selection]
jne .print ; Selected item reached?
xor bl, BRIGHT_COLOR_MASK ; Highlight it
.print:
call printstr
add si, sizeof(BootLoaderAddress)
inc byte [currentLine]
add byte [bp + cursorX], 1
mov al, TRIANGLE_TO_LEFT
call updateMarker
inc byte [bp + cursorY]
inc cx
cmp cx, [listItemCount]
jne .loop
mov ah, SET_CURSOR ; Set cursor position
mov dx, (TEXT_ROWS-4) * 0x100 + (TEXT_COLUMNS / 3)
mov dx, 0x181C
int BIOS_VIDEO_SERVICES
jne .loop
ret
updateMarker:
cmp cx, [bp + selection]
je .print
mov al, ' ' ; Clear marker
.print
mov bl, WHITE
jmp printChar ; return from subroutine
; ========================== Chainload ==========================
bootSelectedPartition:
mov si, list ; Search address of start sector
; of the selected item.
mov cx, [selection]
inc cx ; Number of required iterations
xor ah, ah ; The high-byte of the string length
; see loop body
jmp .search_loop_entry
.search_loop:
add si, sizeof(BootLoaderAddress)
call showCursor
.search_loop_entry:
lodsb ; Length of menu item name
add si, ax ; Skip name to BootLoaderAddess
loop .search_loop
call getSelectedBootLoaderAddress
lodsb ; Set boot drive
mov dl, al
@ -474,39 +517,107 @@ bootSelectedPartition:
mov si, kReadError
jc printAndHalt ; Failed to read sector
mov ax, [signature]
mov ax, [kMBRSignature]
cmp ax, MBR_SIGNATURE
mov si, kNoBootablePartitionError
jne printAndHalt ; Missing signature
CLEAR_SCREEN
; Print "Loading <name>" at top of screen
mov word [bp + cursorPosition], 0
mov si, kLoadingMessage
mov bl, LIGHT_GRAY
call printstr
inc byte [bp + cursorX]
call getSelectedMenuItem
inc si ; Skip string length byte
call printstr
mov dx, 0x100
xor bh, bh
mov ah, SET_CURSOR
int BIOS_VIDEO_SERVICES
call getSelectedBootLoaderAddress
mov dl, [si] ; drive number in dl
jmp $$ ; Start loaded boot loader
; ====================== THE printMenu function ================
printStringStage2:
printString
printAndHalt:
mov dx, (TEXT_ROWS-4) * 0x100 + (TEXT_COLUMNS / 3)
mov [bp + cursorPosition], dx
mov bx, 0x0F ; Page number and foreground color
call printstr
.halt
mov ah, READ_CHAR
int BIOS_KEYBOARD_SERVICES
hlt
jmp .halt
mov dl, 0x80
int BIOS_REBOOT
; Output:
; si address of selected menu item
; Trashes:
; ax, cx
getSelectedMenuItem:
mov si, list ; Search address of start sector
; of the selected item.
mov cx, [bp + selection]
inc cx ; Number of required iterations
xor ah, ah ; The high-byte of the string length
; see loop body
jmp .entry
.loop:
lodsb ; Length of menu item name
add si, ax ; Skip name to BootLoaderAddess
add si, sizeof(BootLoaderAddress)
.entry:
loop .loop
ret
getSelectedBootLoaderAddress:
call getSelectedMenuItem
lodsb
xor ah, ah
add si, ax ; Skip name
ret
printStringStage2:
PRINT_STRING
; al ... ASCII character
; bl ... color
printChar:
push ax
push bx
push cx
push dx
xor bh, bh ; Write on page 0
mov dx, [bp + cursorPosition]
mov ah, SET_CURSOR
int BIOS_VIDEO_SERVICES
inc byte [bp + cursorX]
mov cx, 1
mov ah, WRITE_CHAR
int BIOS_VIDEO_SERVICES
pop dx
pop cx
pop bx
pop ax
ret
; ================================ DATA ===========================
selection:
dw 0x0000
firstLine:
db 0
currentLine:
db 0
timeoutTicks:
dw 0, 0
bootSectorDAP:
istruc AddressPacket
at AddressPacket.packet_size, db 0x10
@ -515,13 +626,13 @@ bootSectorDAP:
iend
kColorTable:
db BLUE, RED, CYAN, GREEN
db BLUE, RED, GREEN, CYAN
kReadError:
db 'Error loading sectors', 0x00
kNoBootablePartitionError:
db 'Not a bootable partition', 0x00
kBootMessage:
db 'Boot!', 0x00
kLoadingMessage:
db 'Loading', 0x00
listItemCount:
@ -574,5 +685,7 @@ list equ timeout + 2
db 'OpenBSD', 0
db 0x80
dw 0xAAAA, 0, 0, 0
dw kStage1UnusedSpace
%endif