]> git.lizzy.rs Git - loadnothing.git/blob - boot.asm
Pad boot.bin to 446 bytes
[loadnothing.git] / boot.asm
1 [bits 16]
2 [org 0x7c00]
3
4 call boot
5
6 ; Print al register
7 print_al:
8         mov ah, 0x0e ; TTY output
9         mov bh, 0x00 ; Page 0
10         mov bl, 0x07 ; Color: Light grey on black background
11         int 0x10
12
13         ret
14
15 ; Call print_al on all characters in si
16 ; si must be null terminated
17 print_bytes_si:
18         mov cl, 0 ; Start with iteration 0 - equivalent of int i = 0
19 print_bytes_si_loop:
20         lodsb                  ; Load next characet of si into al
21         call print_al
22
23         inc cl
24
25         cmp cl, ch
26         jb print_bytes_si_loop
27
28         ret
29
30 ; APM is not supported
31 apm_error:
32         mov ch, 9           ; Our string is 9 characters long
33         mov si, apm_err
34         call print_bytes_si
35
36         jmp $               ; Infinite loop
37
38 ; Check APM support
39 apm_chk:
40         mov ah, 0x53     ; This is an APM command
41         mov al, 0x00     ; APM: Installation Check
42         mov bx, 0x0000   ; Device ID (0 is APM BIOS)
43         int 0x15         ; Call
44
45         jc apm_error ; Carry flag is set if there was an error
46
47         cmp ah, 1        ; APM major version must be at least one
48         jb apm_error
49
50         cmp al, 1        ; APM minor version must be at least one
51         jb apm_error
52
53         ret
54
55
56 ; Disconnect from any APM interface
57 apm_disco:
58         mov ah, 0x53           ; This is an APM command
59         mov al, 0x04           ; APM: Disconnect
60         mov bx, 0x0000         ; Device ID (0 is APM BIOS)
61         int 0x15               ; Call
62
63         jc .apm_disco_error    ; Carry flag is set if there was an error
64         jmp .apm_disco_success
65
66 ; Disconnecting any APM interface failed
67 .apm_disco_error:
68         cmp ah, 0x03  ; Error code for no interface connected
69         jne apm_error
70
71 ; No interface are connected now
72 .apm_disco_success:
73         ret
74
75 ; Connect to an APM interface
76 apm_connect:
77         mov ah, 0x53   ; This is an APM command
78         mov bx, 0x0000 ; Device ID (0 is APM BIOS)
79         int 0x15       ; Call
80
81         jc apm_error ; Carry flag is set if there was an error
82         ret
83
84 ; Set the APM Driver Version to 1.1
85 apm_drv_init:
86         mov ah, 0x53   ; This is an APM command
87         mov al, 0x0e   ; APM: Set Driver Supported Version
88         mov bx, 0x0000 ; Device ID (0 is APM BIOS)
89         mov ch, 1      ; APM Driver Major Version Number
90         mov cl, 1      ; APM Driver Minor Version Number
91         int 0x15       ; Call
92
93         jc apm_error ; Carry flag is set if there was an error
94         ret
95
96 ; Enable APM Power Management
97 apm_mgmt_on:
98         mov ah, 0x53   ; This is an APM command
99         mov al, 0x08   ; APM: Change power management state
100         mov bx, 0x0001 ; on all devices
101         mov cx, 0x0001 ; to on
102         int 0x15       ; Call
103
104         jc apm_error   ; Carry flag is set if there was an error
105         ret
106
107 ; Power down the system
108 apm_power_off:
109         mov ah, 0x53   ; This is an APM command
110         mov al, 0x07   ; APM: Set power state
111         mov bx, 0x0001 ; on all devices
112         mov cx, 0x0003 ; to off
113         int 0x15       ; Call
114
115         jc apm_error   ; Carry flag is set if there was an error
116         ret
117
118 ; Main
119 boot:
120         call apm_chk        ; Is APM supported?
121         call apm_disco      ; Disconnect from any APM interface
122
123         mov al, 0x01        ; Interface to connect to: Real Mode
124         call apm_connect    ; Connect to APM interface
125
126         call apm_drv_init   ; Set the APM Driver Version to 1.1
127         call apm_mgmt_on    ; Enable Power Management
128
129         ; Clear the screen
130         mov ah, 0x06
131         mov al, 0x00
132         mov bh, 0x07
133         mov ch, 0x00
134         mov cl, 0x00
135         mov dh, 0xff
136         mov dl, 0xff
137         int 0x10
138
139         ; Move cursor to 0, 0 on page 0
140         mov ah, 0x02
141         mov bh, 0           ; Page
142         mov dh, 0           ; Row
143         mov dl, 0           ; Column
144         int 0x10
145
146         mov ch, 5           ; Our string is 5 characters long
147         mov si, hello
148         call print_bytes_si
149
150         mov ch, 29          ; Our string is 29 characters long
151         mov si, paktc       ; paktc: Press any key to continue
152         call print_bytes_si
153
154         mov ah, 0x00        ; Keyboard: Read key press
155         int 0x16            ; Call
156
157         call apm_power_off
158         jmp $               ; Infinite loop
159
160 hello db 'foo', 13, 10                   ; \r\n
161 apm_err db 'APM Error'
162 paktc db 'Press any key to continue... '
163
164 times (446 - ($ - $$)) db 0x00