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