Subversion Repositories Kolibri OS

Rev

Rev 9942 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9942 Rev 9958
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
6
;;                                                              ;;
7
;;  BOOTCODE.INC                                                ;;
7
;;  BOOTCODE.INC                                                ;;
8
;;                                                              ;;
8
;;                                                              ;;
9
;;  KolibriOS 16-bit loader,                                    ;;
9
;;  KolibriOS 16-bit loader,                                    ;;
10
;;                        based on bootcode for MenuetOS        ;;
10
;;                        based on bootcode for MenuetOS        ;;
11
;;                                                              ;;
11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
13
 
14
$Revision: 9942 $
14
$Revision: 9958 $
15
 
15
 
16
 
16
 
17
;==========================================================================
17
;==========================================================================
18
;
18
;
19
;                           16 BIT FUNCTIONS
19
;                           16 BIT FUNCTIONS
20
;
20
;
21
;==========================================================================
21
;==========================================================================
22
 
22
 
23
 
23
 
24
putchar:
24
putchar:
25
; in: al=character
25
; in: al=character
26
        mov     ah, 0Eh
26
        mov     ah, 0Eh
27
        mov     bh, 0
27
        mov     bh, 0
28
        int     10h
28
        int     10h
29
        ret
29
        ret
30
 
30
 
31
print:
31
print:
32
; in: si->string
32
; in: si->string
33
        mov     al, 186
33
        mov     al, 186
34
        call    putchar
34
        call    putchar
35
        mov     al, ' '
35
        mov     al, ' '
36
        call    putchar
36
        call    putchar
37
 
37
 
38
printplain:
38
printplain:
39
; in: si->string
39
; in: si->string
40
        pusha
40
        pusha
41
        lodsb
41
        lodsb
42
@@:
42
@@:
43
        call    putchar
43
        call    putchar
44
        lodsb
44
        lodsb
45
        test    al, al
45
        test    al, al
46
        jnz     @b
46
        jnz     @b
47
        popa
47
        popa
48
        ret
48
        ret
49
 
49
 
50
getkey:                         ; Use BIOS INT 16h to read a key from the keyboard
50
getkey:                         ; Use BIOS INT 16h to read a key from the keyboard
51
; get number in range [bl,bh] (bl,bh in ['0'..'9'])
51
; get number in range [bl,bh] (bl,bh in ['0'..'9'])
52
; in: bx=range
52
; in: bx=range
53
; out: ax=digit (1..9, 10 for 0)
53
; out: ax=digit (1..9, 10 for 0)
54
        mov     ah, 0       ; If 'int 16h' is called with 'ah' equal to zero, the BIOS will not return control to the caller
54
        mov     ah, 0       ; If 'int 16h' is called with 'ah' equal to zero, the BIOS will not return control to the caller
55
        int     16h         ; until a key is available in the system type ahead buffer. On return, 'al' contains the ASCII
55
        int     16h         ; until a key is available in the system type ahead buffer. On return, 'al' contains the ASCII
56
        cmp     al, 27      ; code for the key read from the buffer and 'ah' contains the keyboard scan code. (27=>ESC)
56
        cmp     al, 27      ; code for the key read from the buffer and 'ah' contains the keyboard scan code. (27=>ESC)
57
        jz      @f          ; If ESC is pressed, return (user doesn't want to change any value).
57
        jz      @f          ; If ESC is pressed, return (user doesn't want to change any value).
58
        cmp     al, bl      ; Compare 'al' (ASCII code of key pressed) with 'bl' (lowest accepted char from the range).
58
        cmp     al, bl      ; Compare 'al' (ASCII code of key pressed) with 'bl' (lowest accepted char from the range).
59
        jb      getkey      ; ASCII code is below lowest accepted value => continue waiting for another key.
59
        jb      getkey      ; ASCII code is below lowest accepted value => continue waiting for another key.
60
        cmp     al, bh      ; Compare 'al' (ASCII code of key pressed) with 'bh' (highest accepted char from the range).
60
        cmp     al, bh      ; Compare 'al' (ASCII code of key pressed) with 'bh' (highest accepted char from the range).
61
        ja      getkey      ; ASCII code is above highest accepted value => continue waiting for another key.
61
        ja      getkey      ; ASCII code is above highest accepted value => continue waiting for another key.
62
        push    ax          ; If the pressed key is in the accepted range, save it on the stack and echo to screen.
62
        push    ax          ; If the pressed key is in the accepted range, save it on the stack and echo to screen.
63
        call    putchar
63
        call    putchar
64
        pop     ax
64
        pop     ax
65
        and     ax, 0Fh     ; Convert ASCII code to number: '1'->1, '2'->2, etc. 0Fh=1111b.
65
        and     ax, 0Fh     ; Convert ASCII code to number: '1'->1, '2'->2, etc. 0Fh=1111b.
66
        jnz     @f          ; ASCII code for '0' is 48 (110000b). (110000b AND 1111b) = 0
66
        jnz     @f          ; ASCII code for '0' is 48 (110000b). (110000b AND 1111b) = 0
67
        mov     al, 10      ; So if key '0' was entered, return 10 in 'ax'
67
        mov     al, 10      ; So if key '0' was entered, return 10 in 'ax'
68
@@:
68
@@:
69
        ret
69
        ret
70
 
70
 
71
setcursor:
71
setcursor:
72
; in: dl=column, dh=row
72
; in: dl=column, dh=row
73
        mov     ah, 2
73
        mov     ah, 2
74
        mov     bh, 0
74
        mov     bh, 0
75
        int     10h
75
        int     10h
76
        ret
76
        ret
77
 
77
 
78
macro _setcursor row,column
78
macro _setcursor row,column
79
{
79
{
80
        mov     dx, row*256 + column
80
        mov     dx, row*256 + column
81
        call    setcursor
81
        call    setcursor
82
}
82
}
83
 
83
 
84
macro _ask_question question,range,variable_to_set
84
macro _ask_question question,range,variable_to_set
85
{
85
{
86
        _setcursor 16,0
86
        _setcursor 16,0
87
        mov     si, question    ; Print the question
87
        mov     si, question    ; Print the question
88
        call    print
88
        call    print
89
        mov     bx, range       ; range accepted for answer
89
        mov     bx, range       ; range accepted for answer
90
        call    getkey
90
        call    getkey
91
        cmp     al, 27          ; If ESC was pressed, do not change the value
91
        cmp     al, 27          ; If ESC was pressed, do not change the value
92
        jz      .esc_pressed
92
        jz      .esc_pressed
93
        mov     [variable_to_set], al
93
        mov     [variable_to_set], al
94
}
94
}
95
 
95
 
96
clear_status_field:
96
clear_status_field:
97
        mov     si, space_msg
97
        mov     si, space_msg
98
        mov     byte [si+80], 0
98
        mov     byte [si+80], 0
99
        _setcursor 16,0
99
        _setcursor 16,0
100
        call    printplain
100
        call    printplain
101
        _setcursor 16,0
101
        _setcursor 16,0
102
        ret
102
        ret
103
 
103
 
104
boot_read_floppy:
104
boot_read_floppy:
105
        push    si
105
        push    si
106
        xor     si, si
106
        xor     si, si
107
        mov     ah, 2   ; read
107
        mov     ah, 2   ; read
108
@@:
108
@@:
109
        push    ax
109
        push    ax
110
        int     0x13
110
        int     0x13
111
        pop     ax
111
        pop     ax
112
        jnc     @f
112
        jnc     @f
113
        inc     si
113
        inc     si
114
        cmp     si, 10
114
        cmp     si, 10
115
        jb      @b
115
        jb      @b
116
sayerr_badsect:
116
sayerr_badsect:
117
        mov     si, badsect
117
        mov     si, badsect
118
sayerr_plain:
118
sayerr_plain:
119
        call    printplain
119
        call    printplain
120
        jmp     $
120
        jmp     $
121
@@:
121
@@:
122
        pop     si
122
        pop     si
123
        ret
123
        ret
124
 
124
 
125
; convert abs. sector number (AX) to BIOS T:H:S
125
; convert abs. sector number (AX) to BIOS T:H:S
126
; sector number = (abs.sector%BPB_SecPerTrk)+1
126
; sector number = (abs.sector%BPB_SecPerTrk)+1
127
; pre.track number = (abs.sector/BPB_SecPerTrk)
127
; pre.track number = (abs.sector/BPB_SecPerTrk)
128
; head number = pre.track number%BPB_NumHeads
128
; head number = pre.track number%BPB_NumHeads
129
; track number = pre.track number/BPB_NumHeads
129
; track number = pre.track number/BPB_NumHeads
130
; Return: cl - sector number
130
; Return: cl - sector number
131
;         ch - track number
131
;         ch - track number
132
;         dl - drive number (0 = a:)
132
;         dl - drive number (0 = a:)
133
;         dh - head number
133
;         dh - head number
134
conv_abs_to_THS:
134
conv_abs_to_THS:
135
        push    bx
135
        push    bx
136
        mov     bx, word [BPB_SecPerTrk]
136
        mov     bx, word [BPB_SecPerTrk]
137
        xor     dx, dx
137
        xor     dx, dx
138
        div     bx
138
        div     bx
139
        inc     dx
139
        inc     dx
140
        mov     cl, dl                          ; cl = sector number
140
        mov     cl, dl                          ; cl = sector number
141
        mov     bx, word [BPB_NumHeads]
141
        mov     bx, word [BPB_NumHeads]
142
        xor     dx, dx
142
        xor     dx, dx
143
        div     bx
143
        div     bx
144
        ; !!!!!!! ax = track number, dx = head number
144
        ; !!!!!!! ax = track number, dx = head number
145
        mov     ch, al                          ; ch=track number
145
        mov     ch, al                          ; ch=track number
146
        xchg    dh, dl                          ; dh=head number
146
        xchg    dh, dl                          ; dh=head number
147
        mov     dl, 0                           ; dl=0 (drive 0 (a:))
147
        mov     dl, 0                           ; dl=0 (drive 0 (a:))
148
        pop     bx
148
        pop     bx
149
        retn
149
        retn
150
; needed variables
150
; needed variables
151
BPB_SecPerTrk   dw      0                       ; sectors per track
151
BPB_SecPerTrk   dw      0                       ; sectors per track
152
BPB_NumHeads    dw      0                       ; number of heads
152
BPB_NumHeads    dw      0                       ; number of heads
153
BPB_FATSz16     dw      0                       ; size of FAT
153
BPB_FATSz16     dw      0                       ; size of FAT
154
BPB_RootEntCnt  dw      0                       ; count of root dir. entries
154
BPB_RootEntCnt  dw      0                       ; count of root dir. entries
155
BPB_BytsPerSec  dw      0                       ; bytes per sector
155
BPB_BytsPerSec  dw      0                       ; bytes per sector
156
BPB_RsvdSecCnt  dw      0                       ; number of reserved sectors
156
BPB_RsvdSecCnt  dw      0                       ; number of reserved sectors
157
BPB_TotSec16    dw      0                       ; count of the sectors on the volume
157
BPB_TotSec16    dw      0                       ; count of the sectors on the volume
158
BPB_SecPerClus  db      0                       ; number of sectors per cluster
158
BPB_SecPerClus  db      0                       ; number of sectors per cluster
159
BPB_NumFATs     db      0                       ; number of FAT tables
159
BPB_NumFATs     db      0                       ; number of FAT tables
160
abs_sector_adj  dw      0                       ; adjustment to make abs. sector number
160
abs_sector_adj  dw      0                       ; adjustment to make abs. sector number
161
end_of_FAT      dw      0                       ; end of FAT table
161
end_of_FAT      dw      0                       ; end of FAT table
162
FirstDataSector dw      0                       ; begin of data
162
FirstDataSector dw      0                       ; begin of data
163
 
163
 
164
;=========================================================================
164
;=========================================================================
165
;
165
;
166
;                           16 BIT CODE
166
;                           16 BIT CODE
167
;
167
;
168
;=========================================================================
168
;=========================================================================
169
 
169
 
170
include 'bootvesa.inc'                 ;Include source for boot vesa
170
include 'bootvesa.inc'                 ;Include source for boot vesa
171
if defined extended_primary_loader
171
if defined extended_primary_loader
172
include 'parsers.inc'
172
include 'parsers.inc'
173
end if
173
end if
174
 
174
 
175
start_of_code:
175
start_of_code:
176
 
176
 
177
if defined extended_primary_loader
177
if defined extended_primary_loader
178
; save data from primary loader
178
; save data from primary loader
179
        mov     word [cs:bootcallback], si
179
        mov     word [cs:bootcallback], si
180
        mov     word [cs:bootcallback+2], ds
180
        mov     word [cs:bootcallback+2], ds
181
        push    cs
181
        push    cs
182
        pop     ds
182
        pop     ds
183
        mov     [bootdevice], ax
183
        mov     [bootdevice], ax
184
        mov     [bootfs], bx
184
        mov     [bootfs], bx
185
 
185
 
186
; set up stack
186
; set up stack
187
        mov     ax, (TMP_STACK_TOP and 0xF0000) shr 4
187
        mov     ax, (TMP_STACK_TOP and 0xF0000) shr 4
188
        mov     ss, ax
188
        mov     ss, ax
189
        mov     sp, TMP_STACK_TOP and 0xFFFF
189
        mov     sp, TMP_STACK_TOP and 0xFFFF
190
 
190
 
191
; try to load configuration file
191
; try to load configuration file
192
        mov     ax, 1
192
        mov     ax, 1
193
        mov     di, config_file_struct
193
        mov     di, config_file_struct
194
        call    [bootcallback]
194
        call    [bootcallback]
195
        cld
195
        cld
196
        push    cs
196
        push    cs
197
        pop     es
197
        pop     es
198
; bx=0 - ok, bx=1 - part of file loaded, assume this is ok
198
; bx=0 - ok, bx=1 - part of file loaded, assume this is ok
199
        cmp     bx, 1
199
        cmp     bx, 1
200
        ja      .config_bad
200
        ja      .config_bad
201
; configuration file was loaded, parse
201
; configuration file was loaded, parse
202
; if length is too big, use first 0FFFFh bytes
202
; if length is too big, use first 0FFFFh bytes
203
        test    dx, dx
203
        test    dx, dx
204
        jz      @f
204
        jz      @f
205
        mov     ax, 0FFFFh
205
        mov     ax, 0FFFFh
206
@@:
206
@@:
207
; ds:si will be pointer to current data, dx = limit
207
; ds:si will be pointer to current data, dx = limit
208
        xchg    ax, dx
208
        xchg    ax, dx
209
        push    4000h
209
        push    4000h
210
        pop     ds
210
        pop     ds
211
        xor     si, si
211
        xor     si, si
212
.parse_loop:
212
.parse_loop:
213
; skip spaces
213
; skip spaces
214
        cmp     si, dx
214
        cmp     si, dx
215
        jae     .parse_done
215
        jae     .parse_done
216
        lodsb
216
        lodsb
217
        cmp     al, ' '
217
        cmp     al, ' '
218
        jbe     .parse_loop
218
        jbe     .parse_loop
219
        dec     si
219
        dec     si
220
; loop over all possible configuration values
220
; loop over all possible configuration values
221
        mov     bx, config_file_variables
221
        mov     bx, config_file_variables
222
.find_variant:
222
.find_variant:
223
; get length
223
; get length
224
        mov     cx, [es:bx]
224
        mov     cx, [es:bx]
225
; zero length = end of list
225
; zero length = end of list
226
        jecxz   .find_newline
226
        jecxz   .find_newline
227
; skip over length
227
; skip over length
228
        inc     bx
228
        inc     bx
229
        inc     bx
229
        inc     bx
230
        mov     di, bx
230
        mov     di, bx
231
; skip over string
231
; skip over string
232
        add     bx, cx
232
        add     bx, cx
233
; test whether we have at least cx symbols left
233
; test whether we have at least cx symbols left
234
        mov     ax, cx
234
        mov     ax, cx
235
        add     ax, si
235
        add     ax, si
236
        jc      .next_variant1
236
        jc      .next_variant1
237
        cmp     ax, dx
237
        cmp     ax, dx
238
        jae     .next_variant1
238
        jae     .next_variant1
239
; save current position
239
; save current position
240
        push    si
240
        push    si
241
; compare strings
241
; compare strings
242
        repz cmpsb
242
        repz cmpsb
243
        jnz     .next_variant2
243
        jnz     .next_variant2
244
; strings are equal; look for "=" with possible spaces before and after
244
; strings are equal; look for "=" with possible spaces before and after
245
@@:
245
@@:
246
        cmp     si, dx
246
        cmp     si, dx
247
        jae     .next_variant2
247
        jae     .next_variant2
248
        lodsb
248
        lodsb
249
        cmp     al, ' '
249
        cmp     al, ' '
250
        jbe     @b
250
        jbe     @b
251
        cmp     al, '='
251
        cmp     al, '='
252
        jnz     .next_variant2
252
        jnz     .next_variant2
253
; ok, we found the true variant
253
; ok, we found the true variant
254
; ignore saved position on the stack
254
; ignore saved position on the stack
255
        pop     ax
255
        pop     ax
256
; call the parser
256
; call the parser
257
        call    word [es:bx]
257
        call    word [es:bx]
258
; line parsed, find next
258
; line parsed, find next
259
.find_newline:
259
.find_newline:
260
        cmp     si, dx
260
        cmp     si, dx
261
        jae     .parse_done
261
        jae     .parse_done
262
        lodsb
262
        lodsb
263
        cmp     al, 13
263
        cmp     al, 13
264
        jz      .parse_loop
264
        jz      .parse_loop
265
        cmp     al, 10
265
        cmp     al, 10
266
        jz      .parse_loop
266
        jz      .parse_loop
267
        jmp     .find_newline
267
        jmp     .find_newline
268
.next_variant2:
268
.next_variant2:
269
; continue to the next variant, restoring current position
269
; continue to the next variant, restoring current position
270
        pop     si
270
        pop     si
271
.next_variant1:
271
.next_variant1:
272
; continue to the next variant
272
; continue to the next variant
273
; skip over the parser
273
; skip over the parser
274
        inc     bx
274
        inc     bx
275
        inc     bx
275
        inc     bx
276
        jmp     .find_variant
276
        jmp     .find_variant
277
.parse_done:
277
.parse_done:
278
.config_bad:
278
.config_bad:
279
 
279
 
280
; set up segment registers
280
; set up segment registers
281
        push    cs
281
        push    cs
282
        pop     ds
282
        pop     ds
283
else
283
else
284
        cld
284
        cld
285
        push    0
285
        push    0
286
        pop     es
286
        pop     es
287
; if bootloader sets ax = 'KL', then ds:si points to loader block
287
; if bootloader sets ax = 'KL', then ds:si points to loader block
288
        cmp     ax, 'KL'
288
        cmp     ax, 'KL'
289
        jnz     @f
289
        jnz     @f
290
        mov     word [cs:cfgmanager.loader_block], si
290
        mov     word [cs:cfgmanager.loader_block], si
291
        mov     word [cs:cfgmanager.loader_block+2], ds
291
        mov     word [cs:cfgmanager.loader_block+2], ds
292
        mov     word [es:BOOT_LO.kernel_restart], kernel_restart_bootblock
292
        mov     word [es:BOOT_LO.kernel_restart], kernel_restart_bootblock
293
@@:
293
@@:
294
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source disk
294
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source disk
295
; (see comment to BOOT_LO.sys_disk and loader_doc.txt)
295
; (see comment to BOOT_LO.sys_disk and loader_doc.txt)
296
        mov     word [es:BOOT_LO.sys_disk], 'r1'  ; default value: /rd/1
296
        mov     word [es:BOOT_LO.sys_disk], 'r1'  ; default value: /rd/1
297
        cmp     cx, 'HA'
297
        cmp     cx, 'HA'
298
        jnz     no_hd_load
298
        jnz     no_hd_load
299
        cmp     dx, 'RD'
299
        cmp     dx, 'RD'
300
        jnz     no_hd_load
300
        jnz     no_hd_load
301
        mov     [es:BOOT_LO.sys_disk], bx
301
        mov     [es:BOOT_LO.sys_disk], bx
302
no_hd_load:
302
no_hd_load:
303
 
303
 
304
; set up stack
304
; set up stack
305
        mov     ax, (TMP_STACK_TOP and 0xF0000) shr 4
305
        mov     ax, (TMP_STACK_TOP and 0xF0000) shr 4
306
        mov     ss, ax
306
        mov     ss, ax
307
        mov     sp, TMP_STACK_TOP and 0xFFFF
307
        mov     sp, TMP_STACK_TOP and 0xFFFF
308
; set up segment registers
308
; set up segment registers
309
        push    cs
309
        push    cs
310
        pop     ds
310
        pop     ds
311
        push    cs
311
        push    cs
312
        pop     es
312
        pop     es
313
end if
313
end if
314
 
314
 
315
; set videomode
315
; set videomode
316
        mov     ax, 3
316
        mov     ax, 3
317
        int     0x10
317
        int     0x10
318
 
318
 
319
if lang eq ru
319
if lang eq ru
320
 ; Load & set russian VGA font (RU.INC)
320
 ; Load & set russian VGA font (RU.INC)
321
        mov     bp, RU_FNT1             ; RU_FNT1 - First part
321
        mov     bp, RU_FNT1             ; RU_FNT1 - First part
322
        mov     bx, 1000h               ; 768 bytes
322
        mov     bx, 1000h               ; 768 bytes
323
        mov     cx, 30h                 ; 48 symbols
323
        mov     cx, 30h                 ; 48 symbols
324
        mov     dx, 80h                 ; 128 - position of first symbol
324
        mov     dx, 80h                 ; 128 - position of first symbol
325
        mov     ax, 1100h
325
        mov     ax, 1100h
326
        int     10h
326
        int     10h
327
 
327
 
328
        mov     bp, RU_FNT2             ; RU_FNT2 -Second part
328
        mov     bp, RU_FNT2             ; RU_FNT2 -Second part
329
        mov     bx, 1000h               ; 512 bytes
329
        mov     bx, 1000h               ; 512 bytes
330
        mov     cx, 20h                 ; 32 symbols
330
        mov     cx, 20h                 ; 32 symbols
331
        mov     dx, 0E0h                ; 224 - position of first symbol
331
        mov     dx, 0E0h                ; 224 - position of first symbol
332
        mov     ax, 1100h
332
        mov     ax, 1100h
333
        int     10h
333
        int     10h
334
 ; End set VGA russian font
334
 ; End set VGA russian font
335
else if lang eq et
335
else if lang eq et
336
        mov     bp, ET_FNT              ; ET_FNT1
336
        mov     bp, ET_FNT              ; ET_FNT1
337
        mov     bx, 1000h               ;
337
        mov     bx, 1000h               ;
338
        mov     cx, 255                 ; 256 symbols
338
        mov     cx, 255                 ; 256 symbols
339
        xor     dx, dx                  ; 0 - position of first symbol
339
        xor     dx, dx                  ; 0 - position of first symbol
340
        mov     ax, 1100h
340
        mov     ax, 1100h
341
        int     10h
341
        int     10h
342
end if
342
end if
343
 
343
 
344
; draw frames
344
; draw frames
345
        push    0xb800
345
        push    0xb800
346
        pop     es
346
        pop     es
347
        xor     di, di
347
        xor     di, di
348
        mov     ah, 1*16+15
348
        mov     ah, 1*16+15
349
 
349
 
350
; draw top
350
; draw top
351
        mov     si, d80x25_top
351
        mov     si, d80x25_top
352
        mov     cx, d80x25_top_num * 80
352
        mov     cx, d80x25_top_num * 80
353
@@:
353
@@:
354
        lodsb
354
        lodsb
355
        stosw
355
        stosw
356
        loop    @b
356
        loop    @b
357
; draw spaces
357
; draw spaces
358
        mov     si, space_msg
358
        mov     si, space_msg
359
        mov     dx, 25 - d80x25_top_num - d80x25_bottom_num
359
        mov     dx, 25 - d80x25_top_num - d80x25_bottom_num
360
dfl1:
360
dfl1:
361
        push    si
361
        push    si
362
        mov     cx, 80
362
        mov     cx, 80
363
@@:
363
@@:
364
        lodsb
364
        lodsb
365
        stosw
365
        stosw
366
        loop    @b
366
        loop    @b
367
        pop     si
367
        pop     si
368
        dec     dx
368
        dec     dx
369
        jnz     dfl1
369
        jnz     dfl1
370
; draw bottom
370
; draw bottom
371
        mov     si, d80x25_bottom
371
        mov     si, d80x25_bottom
372
        mov     cx, d80x25_bottom_num * 80
372
        mov     cx, d80x25_bottom_num * 80
373
@@:
373
@@:
374
        lodsb
374
        lodsb
375
        stosw
375
        stosw
376
        loop    @b
376
        loop    @b
377
 
377
 
378
        mov     byte [space_msg+80], 0    ; now space_msg is null terminated
378
        mov     byte [space_msg+80], 0    ; now space_msg is null terminated
379
 
379
 
380
        _setcursor d80x25_top_num,0
380
        _setcursor d80x25_top_num,0
381
 
381
 
382
 
382
 
383
; TEST FOR 386+
383
; TEST FOR 386+
384
 
384
 
385
        mov     bx, 0x4000
385
        mov     bx, 0x4000
386
        pushf
386
        pushf
387
        pop     ax
387
        pop     ax
388
        mov     dx, ax
388
        mov     dx, ax
389
        xor     ax, bx
389
        xor     ax, bx
390
        push    ax
390
        push    ax
391
        popf
391
        popf
392
        pushf
392
        pushf
393
        pop     ax
393
        pop     ax
394
        and     ax, bx
394
        and     ax, bx
395
        and     dx, bx
395
        and     dx, bx
396
        cmp     ax, dx
396
        cmp     ax, dx
397
        jnz     cpugood
397
        jnz     cpugood
398
        mov     si, not386
398
        mov     si, not386
399
sayerr:
399
sayerr:
400
        call    print
400
        call    print
401
        jmp     $
401
        jmp     $
402
     cpugood:
402
     cpugood:
403
 
403
 
404
        push    0
404
        push    0
405
        popf
405
        popf
406
 
406
 
407
; set up esp
407
; set up esp
408
        movzx   esp, sp
408
        movzx   esp, sp
409
 
409
 
410
        push    0
410
        push    0
411
        pop     es
411
        pop     es
412
 
412
 
413
        xor     cx, cx
413
        xor     cx, cx
414
@@:
414
@@:
415
        in      al, 64h
415
        in      al, 64h
416
        test    al, 2
416
        test    al, 2
417
        loopnz  @b
417
        loopnz  @b
418
 
418
 
419
        mov     al, 0xf6        ; Сброс клавиатуры, разрешить сканирование
419
        mov     al, 0xf6        ; Сброс клавиатуры, разрешить сканирование
420
        out     0x60, al
420
        out     0x60, al
421
        xor     cx, cx
421
        xor     cx, cx
422
@@:
422
@@:
423
        in      al, 64h
423
        in      al, 64h
424
        test    al, 1
424
        test    al, 1
425
        loopz   @b
425
        loopz   @b
426
        in      al, 0x60
426
        in      al, 0x60
427
 
427
 
428
; set keyboard typematic rate & delay
428
; set keyboard typematic rate & delay
429
        mov     al, 0xf3
429
        mov     al, 0xf3
430
        out     0x60, al
430
        out     0x60, al
431
        xor     cx, cx
431
        xor     cx, cx
432
@@:
432
@@:
433
        in      al, 64h
433
        in      al, 64h
434
        test    al, 1
434
        test    al, 1
435
        loopz   @b
435
        loopz   @b
436
        in      al, 0x60
436
        in      al, 0x60
437
        mov     al, 0
437
        mov     al, 0
438
        out     0x60, al
438
        out     0x60, al
439
        xor     cx, cx
439
        xor     cx, cx
440
@@:
440
@@:
441
        in      al, 64h
441
        in      al, 64h
442
        test    al, 1
442
        test    al, 1
443
        loopz   @b
443
        loopz   @b
444
        in      al, 0x60
444
        in      al, 0x60
445
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
445
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
446
        sti
446
        sti
447
; --------------- APM ---------------------
447
; --------------- APM ---------------------
448
        and     word [es:BOOT_LO.apm_version], 0     ; ver = 0.0 (APM not found)
448
        and     word [es:BOOT_LO.apm_version], 0     ; ver = 0.0 (APM not found)
449
        mov     ax, 0x5300
449
        mov     ax, 0x5300
450
        xor     bx, bx
450
        xor     bx, bx
451
        int     0x15
451
        int     0x15
452
        jc      apm_end                 ; APM not found
452
        jc      apm_end                 ; APM not found
453
        test    cx, 2
453
        test    cx, 2
454
        jz      apm_end                 ; APM 32-bit protected-mode interface not supported
454
        jz      apm_end                 ; APM 32-bit protected-mode interface not supported
455
        mov     [es:BOOT_LO.apm_version], ax         ; Save APM Version
455
        mov     [es:BOOT_LO.apm_version], ax         ; Save APM Version
456
        mov     [es:BOOT_LO.apm_flags], cx           ; Save APM flags
456
        mov     [es:BOOT_LO.apm_flags], cx           ; Save APM flags
457
 
457
 
458
        ; Write APM ver ----
458
        ; Write APM ver ----
459
        and     ax, 0xf0f
459
        and     ax, 0xf0f
460
        add     ax, '00'
460
        add     ax, '00'
461
        mov     si, msg_apm
461
        mov     si, msg_apm
462
        mov     [si + 5], ah
462
        mov     [si + 5], ah
463
        mov     [si + 7], al
463
        mov     [si + 7], al
464
        _setcursor 0, 3
464
        _setcursor 0, 3
465
        call    printplain
465
        call    printplain
466
        ; ------------------
466
        ; ------------------
467
 
467
 
468
        mov     ax, 0x5304              ; Disconnect interface
468
        mov     ax, 0x5304              ; Disconnect interface
469
        xor     bx, bx
469
        xor     bx, bx
470
        int     0x15
470
        int     0x15
471
        mov     ax, 0x5303              ; Connect 32 bit mode interface
471
        mov     ax, 0x5303              ; Connect 32 bit mode interface
472
        xor     bx, bx
472
        xor     bx, bx
473
        int     0x15
473
        int     0x15
474
 
474
 
475
        mov     [es:BOOT_LO.apm_entry], ebx
475
        mov     [es:BOOT_LO.apm_entry], ebx
476
        mov     [es:BOOT_LO.apm_code_32], ax
476
        mov     [es:BOOT_LO.apm_code_32], ax
477
        mov     [es:BOOT_LO.apm_code_16], cx
477
        mov     [es:BOOT_LO.apm_code_16], cx
478
        mov     [es:BOOT_LO.apm_data_16], dx
478
        mov     [es:BOOT_LO.apm_data_16], dx
479
 
479
 
480
apm_end:
480
apm_end:
481
        _setcursor d80x25_top_num, 0
481
        _setcursor d80x25_top_num, 0
-
 
482
 
-
 
483
; --------------- ACPI ---------------------
-
 
484
ACPI_LO_RSDP_WINDOW_END    = 0x000A0000
-
 
485
ACPI_HI_RSDP_WINDOW_START  = 0x000E0000
-
 
486
 
-
 
487
acpi:
-
 
488
        xor     eax, eax
-
 
489
        mov     [es:BOOT_LO.devicesdat_data], eax
-
 
490
        mov     [es:BOOT_LO.devicesdat_size], eax
-
 
491
        mov     [es:BOOT_LO.acpi_rsdp], eax
-
 
492
        push    ds
-
 
493
        mov     ds, ax
-
 
494
        mov     ax, word [40Eh]
-
 
495
        add     ax, 64
-
 
496
.check:
-
 
497
        mov     ds, ax
-
 
498
        cmp     [ds:0], dword 'RSD '
-
 
499
        jne     .next
-
 
500
        cmp     [ds:4], dword 'PTR '
-
 
501
        jne     .next
-
 
502
        shl     eax, 4
-
 
503
        mov     [es:BOOT_LO.acpi_rsdp], eax
-
 
504
        jmp     .end
-
 
505
.next:
-
 
506
        inc     ax
-
 
507
        ; skip VRAM and ROM area A0000h to E0000h
-
 
508
        cmp     ax, (ACPI_LO_RSDP_WINDOW_END shr 4)
-
 
509
        jne     @f
-
 
510
        add     ax, ((ACPI_HI_RSDP_WINDOW_START - ACPI_LO_RSDP_WINDOW_END) shr 4)
-
 
511
@@:     ; end of 1Mb?
-
 
512
        or      ax, ax
-
 
513
        jnz     .check
-
 
514
.end:
-
 
515
        pop     ds
482
 
516
 
483
if ~ defined extended_primary_loader
517
if ~ defined extended_primary_loader
484
;CHECK current of code
518
;CHECK current of code
485
        cmp     [cfgmanager.loader_block], -1
519
        cmp     [cfgmanager.loader_block], -1
486
        jz      noloaderblock
520
        jz      noloaderblock
487
        les     bx, [cfgmanager.loader_block]
521
        les     bx, [cfgmanager.loader_block]
488
        cmp     byte [es:bx], 1
522
        cmp     byte [es:bx], 1
489
        mov     si, loader_block_error
523
        mov     si, loader_block_error
490
        jnz     sayerr
524
        jnz     sayerr
491
        push    0
525
        push    0
492
        pop     es
526
        pop     es
493
end if
527
end if
494
 
528
 
495
noloaderblock:
529
noloaderblock:
496
; DISPLAY VESA INFORMATION
530
; DISPLAY VESA INFORMATION
497
        call    print_vesa_info
531
        call    print_vesa_info
498
        call    calc_vmodes_table
532
        call    calc_vmodes_table
499
        call    check_first_parm   ;check and enable cursor_pos
533
        call    check_first_parm   ;check and enable cursor_pos
500
 
534
 
501
cfgmanager:
535
cfgmanager:
502
; settings:
536
; settings:
503
; a) preboot_graph = graphical mode
537
; a) preboot_graph = graphical mode
504
;    preboot_gprobe = probe this mode?
538
;    preboot_gprobe = probe this mode?
505
; b) preboot_biosdisk  = use BIOS disks through V86 emulation? // (earlier was: preboot_dma  = use DMA access?)
539
; b) preboot_biosdisk  = use BIOS disks through V86 emulation? // (earlier was: preboot_dma  = use DMA access?)
506
; c) preboot_debug = duplicates kernel debug output to the screen
540
; c) preboot_debug = duplicates kernel debug output to the screen
507
; d) preboot_launcher = start the first app (right now it's LAUNCHER) after kernel is loaded?
541
; d) preboot_launcher = start the first app (right now it's LAUNCHER) after kernel is loaded?
508
; e) preboot_device = from where to boot?
542
; e) preboot_device = from where to boot?
509
 
543
 
510
; determine default settings
544
; determine default settings
511
if ~ defined extended_primary_loader
545
if ~ defined extended_primary_loader
512
        mov     [.bSettingsChanged], 0
546
        mov     [.bSettingsChanged], 0
513
end if
547
end if
514
 
548
 
515
;.preboot_gr_end:
549
;.preboot_gr_end:
516
        mov     di, preboot_device
550
        mov     di, preboot_device
517
; if image in memory is present and [preboot_device] is uninitialized,
551
; if image in memory is present and [preboot_device] is uninitialized,
518
; set it to use this preloaded image
552
; set it to use this preloaded image
519
        cmp     byte [di], 0
553
        cmp     byte [di], 0
520
        jnz     .preboot_device_inited
554
        jnz     .preboot_device_inited
521
if defined extended_primary_loader
555
if defined extended_primary_loader
522
        inc     byte [di]
556
        inc     byte [di]
523
        cmp     byte [bootdevice], 'f' ; floppy?
557
        cmp     byte [bootdevice], 'f' ; floppy?
524
        jz      .preboot_device_inited
558
        jz      .preboot_device_inited
525
        inc     byte [di]
559
        inc     byte [di]
526
else
560
else
527
        cmp     [.loader_block], -1
561
        cmp     [.loader_block], -1
528
        jz      @f
562
        jz      @f
529
        les     bx, [.loader_block]
563
        les     bx, [.loader_block]
530
        test    byte [es:bx+1], 1
564
        test    byte [es:bx+1], 1
531
        jz      @f
565
        jz      @f
532
        mov     byte [di], 3
566
        mov     byte [di], 3
533
        jmp     .preboot_device_inited
567
        jmp     .preboot_device_inited
534
@@:
568
@@:
535
; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
569
; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
536
        mov     byte [di], 1
570
        mov     byte [di], 1
537
end if
571
end if
538
.preboot_device_inited:
572
.preboot_device_inited:
539
; following 4 lines set variables to 1 if its current value is 0
573
; following 4 lines set variables to 1 if its current value is 0
540
        cmp     byte [di+preboot_dma-preboot_device], 1
574
        cmp     byte [di+preboot_dma-preboot_device], 1
541
        adc     byte [di+preboot_dma-preboot_device], 0
575
        adc     byte [di+preboot_dma-preboot_device], 0
542
        cmp     byte [di+preboot_launcher-preboot_device], 1        ; Start LAUNCHER by default
576
        cmp     byte [di+preboot_launcher-preboot_device], 1        ; Start LAUNCHER by default
543
        adc     byte [di+preboot_launcher-preboot_device], 0
577
        adc     byte [di+preboot_launcher-preboot_device], 0
544
        _setcursor 5,2
578
        _setcursor 5,2
545
 
579
 
546
        mov     si, linef
580
        mov     si, linef
547
        call    printplain
581
        call    printplain
548
        mov     si, start_msg
582
        mov     si, start_msg
549
        call    print
583
        call    print
550
        mov     si, time_msg
584
        mov     si, time_msg
551
        call    print
585
        call    print
552
; get start time
586
; get start time
553
        call    .gettime
587
        call    .gettime
554
        mov     [.starttime], eax
588
        mov     [.starttime], eax
555
        mov     word [.timer], .newtimer
589
        mov     word [.timer], .newtimer
556
        mov     word [.timer+2], cs
590
        mov     word [.timer+2], cs
557
.printcfg:
591
.printcfg:
558
 
592
 
559
        _setcursor 9,0
593
        _setcursor 9,0
560
        mov     si, current_cfg_msg
594
        mov     si, current_cfg_msg
561
        call    print
595
        call    print
562
        mov     si, curvideo_msg
596
        mov     si, curvideo_msg
563
        call    print
597
        call    print
564
 
598
 
565
        call    draw_current_vmode
599
        call    draw_current_vmode
566
 
600
 
567
        mov     si, usebd_msg
601
        mov     si, usebd_msg
568
        cmp     [preboot_biosdisk], 1
602
        cmp     [preboot_biosdisk], 1
569
        call    .say_on_off
603
        call    .say_on_off
570
        mov     si, debug_mode_msg
604
        mov     si, debug_mode_msg
571
        cmp     [preboot_debug], 1
605
        cmp     [preboot_debug], 1
572
        call    .say_on_off
606
        call    .say_on_off
573
        mov     si, launcher_msg
607
        mov     si, launcher_msg
574
        cmp     [preboot_launcher], 1
608
        cmp     [preboot_launcher], 1
575
        call    .say_on_off
609
        call    .say_on_off
576
        mov     si, preboot_device_msg
610
        mov     si, preboot_device_msg
577
        call    print
611
        call    print
578
        mov     al, [preboot_device]
612
        mov     al, [preboot_device]
579
if defined extended_primary_loader
613
if defined extended_primary_loader
580
        and     eax, 3
614
        and     eax, 3
581
else
615
else
582
        and     eax, 7
616
        and     eax, 7
583
end if
617
end if
584
        mov     si, [preboot_device_msgs+eax*2]
618
        mov     si, [preboot_device_msgs+eax*2]
585
        call    printplain
619
        call    printplain
586
.show_remarks:
620
.show_remarks:
587
; show remarks in gray color
621
; show remarks in gray color
588
        mov     di, ((21-num_remarks)*80 + 2)*2
622
        mov     di, ((21-num_remarks)*80 + 2)*2
589
        push    0xB800
623
        push    0xB800
590
        pop     es
624
        pop     es
591
        mov     cx, num_remarks
625
        mov     cx, num_remarks
592
        mov     si, remarks
626
        mov     si, remarks
593
.write_remarks:
627
.write_remarks:
594
        lodsw
628
        lodsw
595
        push    si
629
        push    si
596
        xchg    ax, si
630
        xchg    ax, si
597
        mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
631
        mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
598
        push    di
632
        push    di
599
.write_remark:
633
.write_remark:
600
        lodsb
634
        lodsb
601
        test    al, al
635
        test    al, al
602
        jz      @f
636
        jz      @f
603
        stosw
637
        stosw
604
        jmp     .write_remark
638
        jmp     .write_remark
605
@@:
639
@@:
606
        pop     di
640
        pop     di
607
        pop     si
641
        pop     si
608
        add     di, 80*2
642
        add     di, 80*2
609
        loop    .write_remarks
643
        loop    .write_remarks
610
.wait:
644
.wait:
611
        _setcursor 25,0         ; out of screen
645
        _setcursor 25,0         ; out of screen
612
; set timer interrupt handler
646
; set timer interrupt handler
613
        cli
647
        cli
614
        push    0
648
        push    0
615
        pop     es
649
        pop     es
616
        push    dword [es:8*4]
650
        push    dword [es:8*4]
617
        pop     dword [.oldtimer]
651
        pop     dword [.oldtimer]
618
        push    dword [.timer]
652
        push    dword [.timer]
619
        pop     dword [es:8*4]
653
        pop     dword [es:8*4]
620
;        mov     eax, [es:8*4]
654
;        mov     eax, [es:8*4]
621
;        mov     [.oldtimer], eax
655
;        mov     [.oldtimer], eax
622
;        mov     eax, [.timer]
656
;        mov     eax, [.timer]
623
;        mov     [es:8*4], eax
657
;        mov     [es:8*4], eax
624
        sti
658
        sti
625
; wait for keypressed
659
; wait for keypressed
626
        xor     ax, ax
660
        xor     ax, ax
627
        int     16h
661
        int     16h
628
        push    ax
662
        push    ax
629
; restore timer interrupt
663
; restore timer interrupt
630
;        push    0
664
;        push    0
631
;        pop     es
665
;        pop     es
632
        mov     eax, [.oldtimer]
666
        mov     eax, [.oldtimer]
633
        mov     [es:8*4], eax
667
        mov     [es:8*4], eax
634
        mov     [.timer], eax
668
        mov     [.timer], eax
635
 
669
 
636
        _setcursor 7,0
670
        _setcursor 7,0
637
        mov     si, space_msg
671
        mov     si, space_msg
638
        call    printplain
672
        call    printplain
639
; clear remarks and restore normal attributes
673
; clear remarks and restore normal attributes
640
        push    es
674
        push    es
641
        mov     di, ((21-num_remarks)*80 + 2)*2
675
        mov     di, ((21-num_remarks)*80 + 2)*2
642
        push    0xB800
676
        push    0xB800
643
        pop     es
677
        pop     es
644
        mov     cx, num_remarks
678
        mov     cx, num_remarks
645
        mov     ax, ' ' + (1*16 + 15)*100h
679
        mov     ax, ' ' + (1*16 + 15)*100h
646
@@:
680
@@:
647
        push    cx
681
        push    cx
648
        mov     cx, 76
682
        mov     cx, 76
649
        rep stosw
683
        rep stosw
650
        pop     cx
684
        pop     cx
651
        add     di, 4*2
685
        add     di, 4*2
652
        loop    @b
686
        loop    @b
653
        pop     es
687
        pop     es
654
        pop     ax
688
        pop     ax
655
; switch on key
689
; switch on key
656
        cmp     al, 13
690
        cmp     al, 13
657
        jz      .continue
691
        jz      .continue
658
        or      al, 20h
692
        or      al, 20h
659
        cmp     al, 'a'         ; select graphical mode
693
        cmp     al, 'a'         ; select graphical mode
660
        jz      .change_a
694
        jz      .change_a
661
        cmp     al, 'q'         ; Trick to make 'A' key on azerty keyboard work
695
        cmp     al, 'q'         ; Trick to make 'A' key on azerty keyboard work
662
        je      .change_a
696
        je      .change_a
663
        cmp     al, 'b'         ; use BIOS disks? // (selecting YES will make BIOS disks visible as /bd)
697
        cmp     al, 'b'         ; use BIOS disks? // (selecting YES will make BIOS disks visible as /bd)
664
        jz      .change_b
698
        jz      .change_b
665
        cmp     al, 'c'         ; load kernel in debug mode?
699
        cmp     al, 'c'         ; load kernel in debug mode?
666
        jz      .change_c
700
        jz      .change_c
667
        cmp     al, 'd'         ; start launcher after kernel is loaded?
701
        cmp     al, 'd'         ; start launcher after kernel is loaded?
668
        jz      .change_d
702
        jz      .change_d
669
        cmp     al, 'e'         ; select boot origin
703
        cmp     al, 'e'         ; select boot origin
670
        jnz     .show_remarks
704
        jnz     .show_remarks
671
; e) preboot_device = from where to boot?
705
; e) preboot_device = from where to boot?
672
if defined extended_primary_loader
706
if defined extended_primary_loader
673
        _ask_question bdev,'13',preboot_device  ; range accepted for answer: 1-3
707
        _ask_question bdev,'13',preboot_device  ; range accepted for answer: 1-3
674
else
708
else
675
        _ask_question bdev,'14',preboot_device              ; range accepted for answer: 1-4
709
        _ask_question bdev,'14',preboot_device              ; range accepted for answer: 1-4
676
end if
710
end if
677
        _setcursor 14,0
711
        _setcursor 14,0
678
 
712
 
679
.d:
713
.d:
680
if ~ defined extended_primary_loader
714
if ~ defined extended_primary_loader
681
        mov     [.bSettingsChanged], 1
715
        mov     [.bSettingsChanged], 1
682
end if
716
end if
683
.esc_pressed:
717
.esc_pressed:
684
        call    clear_vmodes_table             ;clear vmodes_table
718
        call    clear_vmodes_table             ;clear vmodes_table
685
        jmp     .printcfg
719
        jmp     .printcfg
686
 
720
 
687
.change_a:
721
.change_a:
688
        call    clear_vmodes_table             ;clear vmodes_table
722
        call    clear_vmodes_table             ;clear vmodes_table
689
 
723
 
690
        mov     si, word [cursor_pos]
724
        mov     si, word [cursor_pos]
691
        mov     word [cursor_pos_old], si
725
        mov     word [cursor_pos_old], si
692
.loops:
726
.loops:
693
        call    draw_vmodes_table
727
        call    draw_vmodes_table
694
        _setcursor 25,0         ; out of screen
728
        _setcursor 25,0         ; out of screen
695
        xor     ax, ax
729
        xor     ax, ax
696
        int     0x16
730
        int     0x16
697
;        call    clear_table_cursor             ;clear current position of cursor
731
;        call    clear_table_cursor             ;clear current position of cursor
698
 
732
 
699
        mov     si, word [cursor_pos]
733
        mov     si, word [cursor_pos]
700
 
734
 
701
        cmp     al, 27              ; If ESC was pressed, do not change the value
735
        cmp     al, 27              ; If ESC was pressed, do not change the value
702
        jnz     @f                   ; Just exit the resolution selection box
736
        jnz     @f                   ; Just exit the resolution selection box
703
 
737
 
704
        mov     si, word [cursor_pos_old]
738
        mov     si, word [cursor_pos_old]
705
        mov     word [cursor_pos], si
739
        mov     word [cursor_pos], si
706
        jmp     .esc_pressed
740
        jmp     .esc_pressed
707
@@:
741
@@:
708
        cmp     ah, 0x48;x,0x48E0               ; up
742
        cmp     ah, 0x48;x,0x48E0               ; up
709
        jne     .down
743
        jne     .down
710
        cmp     si, modes_table
744
        cmp     si, modes_table
711
        jbe     .loops
745
        jbe     .loops
712
        sub     word [cursor_pos], size_of_step
746
        sub     word [cursor_pos], size_of_step
713
        jmp     .loops
747
        jmp     .loops
714
 
748
 
715
.down:
749
.down:
716
        cmp     ah, 0x50;x,0x50E0               ; down
750
        cmp     ah, 0x50;x,0x50E0               ; down
717
        jne     .pgup
751
        jne     .pgup
718
        cmp     word[es:si+10], -1
752
        cmp     word[es:si+10], -1
719
        je      .loops
753
        je      .loops
720
        add     word [cursor_pos], size_of_step
754
        add     word [cursor_pos], size_of_step
721
        jmp     .loops
755
        jmp     .loops
722
 
756
 
723
.pgup:
757
.pgup:
724
        cmp     ah, 0x49                ; page up
758
        cmp     ah, 0x49                ; page up
725
        jne     .pgdn
759
        jne     .pgdn
726
        sub     si, size_of_step*long_v_table
760
        sub     si, size_of_step*long_v_table
727
        cmp     si, modes_table
761
        cmp     si, modes_table
728
        jae     @f
762
        jae     @f
729
        mov     si, modes_table
763
        mov     si, modes_table
730
@@:
764
@@:
731
        mov     word [cursor_pos], si
765
        mov     word [cursor_pos], si
732
        mov     si, word [home_cursor]
766
        mov     si, word [home_cursor]
733
        sub     si, size_of_step*long_v_table
767
        sub     si, size_of_step*long_v_table
734
        cmp     si, modes_table
768
        cmp     si, modes_table
735
        jae     @f
769
        jae     @f
736
        mov     si, modes_table
770
        mov     si, modes_table
737
@@:
771
@@:
738
        mov     word [home_cursor], si
772
        mov     word [home_cursor], si
739
        jmp     .loops
773
        jmp     .loops
740
 
774
 
741
.pgdn:
775
.pgdn:
742
        cmp     ah, 0x51                ; page down
776
        cmp     ah, 0x51                ; page down
743
        jne     .enter
777
        jne     .enter
744
        mov     ax, [end_cursor]
778
        mov     ax, [end_cursor]
745
        add     si, size_of_step*long_v_table
779
        add     si, size_of_step*long_v_table
746
        cmp     si, ax
780
        cmp     si, ax
747
        jb      @f
781
        jb      @f
748
        mov     si, ax
782
        mov     si, ax
749
        sub     si, size_of_step
783
        sub     si, size_of_step
750
@@:
784
@@:
751
        mov     word [cursor_pos], si
785
        mov     word [cursor_pos], si
752
        mov     si, word [home_cursor]
786
        mov     si, word [home_cursor]
753
        sub     ax, size_of_step*long_v_table
787
        sub     ax, size_of_step*long_v_table
754
        add     si, size_of_step*long_v_table
788
        add     si, size_of_step*long_v_table
755
        cmp     si, ax
789
        cmp     si, ax
756
        jb      @f
790
        jb      @f
757
        mov     si, ax
791
        mov     si, ax
758
@@:
792
@@:
759
        mov     word [home_cursor], si
793
        mov     word [home_cursor], si
760
        jmp     .loops
794
        jmp     .loops
761
 
795
 
762
.enter:
796
.enter:
763
        cmp     al, 0x0D;x,0x1C0D               ; enter
797
        cmp     al, 0x0D;x,0x1C0D               ; enter
764
        jne     .loops
798
        jne     .loops
765
        push    word [cursor_pos]
799
        push    word [cursor_pos]
766
        pop     bp
800
        pop     bp
767
        push    word [es:bp]
801
        push    word [es:bp]
768
        pop     word [x_save]
802
        pop     word [x_save]
769
        push    word [es:bp+2]
803
        push    word [es:bp+2]
770
        pop     word [y_save]
804
        pop     word [y_save]
771
        push    word [es:bp+6]
805
        push    word [es:bp+6]
772
        pop     word [number_vm]
806
        pop     word [number_vm]
773
        mov     word [preboot_graph], bp          ;save choose
807
        mov     word [preboot_graph], bp          ;save choose
774
        
808
        
775
        jmp     .d
809
        jmp     .d
776
 
810
 
777
.change_b:                      ; b) preboot_biosdisk  = use BIOS disks through V86 emulation?
811
.change_b:                      ; b) preboot_biosdisk  = use BIOS disks through V86 emulation?
778
;        _setcursor 16,0
812
;        _setcursor 16,0
779
;        mov     si, ask_dma    // (earlier was: preboot_dma  = use DMA access?)
813
;        mov     si, ask_dma    // (earlier was: preboot_dma  = use DMA access?)
780
;        call    print
814
;        call    print
781
;        mov     bx, '13'       ; range accepted for answer: 1-3
815
;        mov     bx, '13'       ; range accepted for answer: 1-3
782
;        call    getkey
816
;        call    getkey
783
;        mov     [preboot_dma], al
817
;        mov     [preboot_dma], al
784
        _ask_question ask_bd,'12',preboot_biosdisk              ; range accepted for answer: 1-2
818
        _ask_question ask_bd,'12',preboot_biosdisk              ; range accepted for answer: 1-2
785
        _setcursor 11,0
819
        _setcursor 11,0
786
        jmp     .d
820
        jmp     .d
787
.change_c:                      ; c) preboot_debug = duplicates kernel debug output to the screen
821
.change_c:                      ; c) preboot_debug = duplicates kernel debug output to the screen
788
        _ask_question ask_debug,'12',preboot_debug              ; range accepted for answer: 1-2
822
        _ask_question ask_debug,'12',preboot_debug              ; range accepted for answer: 1-2
789
        _setcursor 12,0
823
        _setcursor 12,0
790
        jmp     .d
824
        jmp     .d
791
.change_d:                      ; d) preboot_launcher = start the first app (right now it's LAUNCHER) after kernel is loaded?
825
.change_d:                      ; d) preboot_launcher = start the first app (right now it's LAUNCHER) after kernel is loaded?
792
        _ask_question ask_launcher,'12',preboot_launcher        ; range accepted for answer: 1-2
826
        _ask_question ask_launcher,'12',preboot_launcher        ; range accepted for answer: 1-2
793
        _setcursor 13,0
827
        _setcursor 13,0
794
        jmp     .d
828
        jmp     .d
795
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
829
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
796
.say_on_off:
830
.say_on_off:
797
        pushf
831
        pushf
798
        call    print
832
        call    print
799
        mov     si, on_msg
833
        mov     si, on_msg
800
        popf
834
        popf
801
        jz      @f
835
        jz      @f
802
        mov     si, off_msg
836
        mov     si, off_msg
803
@@:
837
@@:
804
        jmp     printplain
838
        jmp     printplain
805
; novesa and vervesa strings are not used at the moment of executing this code
839
; novesa and vervesa strings are not used at the moment of executing this code
806
virtual at novesa
840
virtual at novesa
807
.oldtimer dd ?
841
.oldtimer dd ?
808
.starttime dd ?
842
.starttime dd ?
809
if ~ defined extended_primary_loader
843
if ~ defined extended_primary_loader
810
.bSettingsChanged db ?
844
.bSettingsChanged db ?
811
end if
845
end if
812
.timer dd ?
846
.timer dd ?
813
end virtual
847
end virtual
814
if ~ defined extended_primary_loader
848
if ~ defined extended_primary_loader
815
.loader_block dd -1
849
.loader_block dd -1
816
end if
850
end if
817
.gettime:
851
.gettime:
818
        mov     ah, 0
852
        mov     ah, 0
819
        int     1Ah
853
        int     1Ah
820
        xchg    ax, cx
854
        xchg    ax, cx
821
        shl     eax, 10h
855
        shl     eax, 10h
822
        xchg    ax, dx
856
        xchg    ax, dx
823
        ret
857
        ret
824
.newtimer:
858
.newtimer:
825
        push    ds
859
        push    ds
826
        push    cs
860
        push    cs
827
        pop     ds
861
        pop     ds
828
        pushf
862
        pushf
829
        call    [.oldtimer]
863
        call    [.oldtimer]
830
        pushad
864
        pushad
831
        call    .gettime
865
        call    .gettime
832
        sub     eax, [.starttime]
866
        sub     eax, [.starttime]
833
if defined extended_primary_loader
867
if defined extended_primary_loader
834
        sub     ax, [preboot_timeout]
868
        sub     ax, [preboot_timeout]
835
else
869
else
836
        ; bios 0x1A timer runs at ~18 ticks per second
870
        ; bios 0x1A timer runs at ~18 ticks per second
837
        sub     ax, 18*PREBOOT_TIMEOUT
871
        sub     ax, 18*PREBOOT_TIMEOUT
838
end if
872
end if
839
        jae     .timergo
873
        jae     .timergo
840
        neg     ax
874
        neg     ax
841
        add     ax, 18-1
875
        add     ax, 18-1
842
        mov     bx, 18
876
        mov     bx, 18
843
        xor     dx, dx
877
        xor     dx, dx
844
        div     bx
878
        div     bx
845
if lang eq ru
879
if lang eq ru
846
; подождите 5 секунд, 4/3/2 секунды, 1 секунду
880
; подождите 5 секунд, 4/3/2 секунды, 1 секунду
847
        cmp     al, 5
881
        cmp     al, 5
848
        mov     cl, ' '
882
        mov     cl, ' '
849
        jae     @f
883
        jae     @f
850
        cmp     al, 1
884
        cmp     al, 1
851
        mov     cl, 0xE3 ; 'у' in cp866
885
        mov     cl, 0xE3 ; 'у' in cp866
852
        jz      @f
886
        jz      @f
853
        mov     cl, 0xEB ; 'ы' in cp866
887
        mov     cl, 0xEB ; 'ы' in cp866
854
@@:
888
@@:
855
        mov     [time_str+9], cl
889
        mov     [time_str+9], cl
856
else if lang eq et
890
else if lang eq et
857
        cmp     al, 1
891
        cmp     al, 1
858
        ja      @f
892
        ja      @f
859
        mov     byte [time_str+9], ' '
893
        mov     byte [time_str+9], ' '
860
        mov     byte [time_str+10], ' '
894
        mov     byte [time_str+10], ' '
861
@@:
895
@@:
862
else if lang eq sp
896
else if lang eq sp
863
; esperar 5/4/3/2 segundos, 1 segundo
897
; esperar 5/4/3/2 segundos, 1 segundo
864
        cmp     al, 1
898
        cmp     al, 1
865
        mov     cl, 's'
899
        mov     cl, 's'
866
        ja      @f
900
        ja      @f
867
        mov     cl, ' '
901
        mov     cl, ' '
868
@@:
902
@@:
869
        mov     [time_str+10], cl
903
        mov     [time_str+10], cl
870
else
904
else
871
; wait 5/4/3/2 seconds, 1 second
905
; wait 5/4/3/2 seconds, 1 second
872
        cmp     al, 1
906
        cmp     al, 1
873
        mov     cl, 's'
907
        mov     cl, 's'
874
        ja      @f
908
        ja      @f
875
        mov     cl, ' '
909
        mov     cl, ' '
876
@@:
910
@@:
877
        mov     [time_str+9], cl
911
        mov     [time_str+9], cl
878
end if
912
end if
879
        add     al, '0'
913
        add     al, '0'
880
        mov     [time_str+1], al
914
        mov     [time_str+1], al
881
        mov     si, time_msg
915
        mov     si, time_msg
882
        _setcursor 7,0
916
        _setcursor 7,0
883
        call    print
917
        call    print
884
        _setcursor 25,0
918
        _setcursor 25,0
885
        popad
919
        popad
886
        pop     ds
920
        pop     ds
887
        iret
921
        iret
888
.timergo:
922
.timergo:
889
        push    0
923
        push    0
890
        pop     es
924
        pop     es
891
        mov     eax, [.oldtimer]
925
        mov     eax, [.oldtimer]
892
        mov     [es:8*4], eax
926
        mov     [es:8*4], eax
893
        mov     sp, 0EC00h
927
        mov     sp, 0EC00h
894
.continue:
928
.continue:
895
        sti
929
        sti
896
        _setcursor 6,0
930
        _setcursor 6,0
897
        mov     si, space_msg
931
        mov     si, space_msg
898
        call    printplain
932
        call    printplain
899
        call    printplain
933
        call    printplain
900
        _setcursor 6,0
934
        _setcursor 6,0
901
        mov     si, loading_msg
935
        mov     si, loading_msg
902
        call    print
936
        call    print
903
        _setcursor 16,0
937
        _setcursor 16,0
904
if ~ defined extended_primary_loader
938
if ~ defined extended_primary_loader
905
        cmp     [.bSettingsChanged], 0
939
        cmp     [.bSettingsChanged], 0
906
        jz      .load
940
        jz      .load
907
        cmp     [.loader_block], -1
941
        cmp     [.loader_block], -1
908
        jz      .load
942
        jz      .load
909
        les     bx, [.loader_block]
943
        les     bx, [.loader_block]
910
        mov     eax, [es:bx+3]
944
        mov     eax, [es:bx+3]
911
        push    ds
945
        push    ds
912
        pop     es
946
        pop     es
913
        test    eax, eax
947
        test    eax, eax
914
        jz      .load
948
        jz      .load
915
        push    eax
949
        push    eax
916
        mov     si, save_quest
950
        mov     si, save_quest
917
        call    print
951
        call    print
918
.waityn:
952
.waityn:
919
        mov     ah, 0
953
        mov     ah, 0
920
        int     16h
954
        int     16h
921
        or      al, 20h
955
        or      al, 20h
922
        cmp     al, 'n'
956
        cmp     al, 'n'
923
        jz      .loadc
957
        jz      .loadc
924
        if lang eq sp
958
        if lang eq sp
925
        cmp     al, 's'
959
        cmp     al, 's'
926
        else
960
        else
927
        cmp     al, 'y'
961
        cmp     al, 'y'
928
        end if
962
        end if
929
        jnz     .waityn
963
        jnz     .waityn
930
        call    putchar
964
        call    putchar
931
        mov     byte [space_msg+80], 186
965
        mov     byte [space_msg+80], 186
932
 
966
 
933
        pop     eax
967
        pop     eax
934
        push    cs
968
        push    cs
935
        push    .cont
969
        push    .cont
936
        push    eax
970
        push    eax
937
        retf                            ;call back
971
        retf                            ;call back
938
.loadc:
972
.loadc:
939
        pop     eax
973
        pop     eax
940
.cont:
974
.cont:
941
        push    cs
975
        push    cs
942
        pop     ds
976
        pop     ds
943
 
977
 
944
        push    es
978
        push    es
945
        les     bx, [.loader_block]
979
        les     bx, [.loader_block]
946
        cmp     byte [es:bx+7], 0      ; get write error flag
980
        cmp     byte [es:bx+7], 0      ; get write error flag
947
        pop     es
981
        pop     es
948
        jz      .load
982
        jz      .load
949
        call    clear_status_field
983
        call    clear_status_field
950
        mov     si, write_err_msg
984
        mov     si, write_err_msg
951
        call    print
985
        call    print
952
.wait_any_key:
986
.wait_any_key:
953
        xor     ax, ax
987
        xor     ax, ax
954
        int     16h
988
        int     16h
955
        test    ax, ax
989
        test    ax, ax
956
        jz      .wait_any_key
990
        jz      .wait_any_key
957
 
991
 
958
.load:
992
.load:
959
        call    clear_status_field
993
        call    clear_status_field
960
end if
994
end if
961
 
995
 
962
; ASK GRAPHICS MODE
996
; ASK GRAPHICS MODE
963
 
997
 
964
        call    set_vmode
998
        call    set_vmode
965
 
999
 
966
; GRAPHICS ACCELERATION
1000
; GRAPHICS ACCELERATION
967
; force yes
1001
; force yes
968
        mov     [es:BOOT_LO.mtrr], byte 1
1002
        mov     [es:BOOT_LO.mtrr], byte 1
969
 
1003
 
970
; DMA ACCESS TO HD
1004
; DMA ACCESS TO HD
971
 
1005
 
972
        mov     al, [preboot_dma]
1006
        mov     al, [preboot_dma]
973
        mov     [es:BOOT_LO.dma], al
1007
        mov     [es:BOOT_LO.dma], al
974
 
1008
 
975
; Set kernel DEBUG mode - if nonzero, duplicates debug output to the screen.
1009
; Set kernel DEBUG mode - if nonzero, duplicates debug output to the screen.
976
        mov     al, [preboot_debug]
1010
        mov     al, [preboot_debug]
977
        mov     [es:BOOT_LO.debug_print], al       ;// 0x901E
1011
        mov     [es:BOOT_LO.debug_print], al       ;// 0x901E
978
 
1012
 
979
; Start the first app (right now it's LAUNCHER) after kernel is loaded?
1013
; Start the first app (right now it's LAUNCHER) after kernel is loaded?
980
        mov     al, [preboot_launcher]
1014
        mov     al, [preboot_launcher]
981
        mov     [es:BOOT_LO.launcher_start], al    ;// 0x901D        
1015
        mov     [es:BOOT_LO.launcher_start], al    ;// 0x901D        
982
 
1016
 
983
; BOOT DEVICE
1017
; BOOT DEVICE
984
 
1018
 
985
        mov     al, [preboot_device]
1019
        mov     al, [preboot_device]
986
if defined extended_primary_loader
1020
if defined extended_primary_loader
987
        cmp     al, RD_LOAD_FROM_MEMORY
1021
        cmp     al, RD_LOAD_FROM_MEMORY
988
        jnz     @f
1022
        jnz     @f
989
        mov     al, RD_LOAD_FROM_NONE
1023
        mov     al, RD_LOAD_FROM_NONE
990
@@:
1024
@@:
991
end if
1025
end if
992
        mov     [es:BOOT_LO.rd_load_from], al
1026
        mov     [es:BOOT_LO.rd_load_from], al
993
 
1027
 
994
; /sys path
1028
; /sys path
995
        mov     eax, dword[preboot_syspath+0]
1029
        mov     eax, dword[preboot_syspath+0]
996
        mov     dword[es:BOOT_LO.syspath+0], eax
1030
        mov     dword[es:BOOT_LO.syspath+0], eax
997
        mov     eax, dword[preboot_syspath+4]
1031
        mov     eax, dword[preboot_syspath+4]
998
        mov     dword[es:BOOT_LO.syspath+4], eax
1032
        mov     dword[es:BOOT_LO.syspath+4], eax
999
        mov     eax, dword[preboot_syspath+8]
1033
        mov     eax, dword[preboot_syspath+8]
1000
        mov     dword[es:BOOT_LO.syspath+8], eax
1034
        mov     dword[es:BOOT_LO.syspath+8], eax
1001
        mov     eax, dword[preboot_syspath+12]
1035
        mov     eax, dword[preboot_syspath+12]
1002
        mov     dword[es:BOOT_LO.syspath+12], eax
1036
        mov     dword[es:BOOT_LO.syspath+12], eax
1003
 
1037
 
1004
 
1038
 
1005
; GET MEMORY MAP
1039
; GET MEMORY MAP
1006
include '../detect/biosmem.inc'
1040
include '../detect/biosmem.inc'
1007
 
1041
 
1008
; READ DISKETTE TO MEMORY
1042
; READ DISKETTE TO MEMORY
1009
 
1043
 
1010
        cmp     byte [es:BOOT_LO.rd_load_from], RD_LOAD_FROM_FLOPPY
1044
        cmp     byte [es:BOOT_LO.rd_load_from], RD_LOAD_FROM_FLOPPY
1011
        jne     no_sys_on_floppy
1045
        jne     no_sys_on_floppy
1012
        mov     si, diskload
1046
        mov     si, diskload
1013
        call    print
1047
        call    print
1014
        xor     ax, ax          ; reset drive
1048
        xor     ax, ax          ; reset drive
1015
        xor     dx, dx          ; 1st floppy disk (0)
1049
        xor     dx, dx          ; 1st floppy disk (0)
1016
        int     0x13
1050
        int     0x13
1017
; do we boot from CD-ROM?
1051
; do we boot from CD-ROM?
1018
        mov     ah, 41h         ; check extended mode
1052
        mov     ah, 41h         ; check extended mode
1019
        mov     bx, 55AAh       ; test 2 bytes to check that this function is supported
1053
        mov     bx, 55AAh       ; test 2 bytes to check that this function is supported
1020
        xor     dx, dx          ; 1st floppy disk (0)
1054
        xor     dx, dx          ; 1st floppy disk (0)
1021
        int     0x13
1055
        int     0x13
1022
        jc      .nocd           ; extended mode not supported
1056
        jc      .nocd           ; extended mode not supported
1023
        cmp     bx, 0AA55h
1057
        cmp     bx, 0AA55h
1024
        jnz     .nocd           ; extended mode not supported
1058
        jnz     .nocd           ; extended mode not supported
1025
        mov     ah, 48h         ; extended read drive parameters
1059
        mov     ah, 48h         ; extended read drive parameters
1026
        push    ds
1060
        push    ds
1027
        push    es
1061
        push    es
1028
        pop     ds
1062
        pop     ds
1029
        mov     si, 0xa000
1063
        mov     si, 0xa000
1030
        mov     word [si], 30   ; size of result buffer
1064
        mov     word [si], 30   ; size of result buffer
1031
        int     0x13
1065
        int     0x13
1032
        pop     ds
1066
        pop     ds
1033
        jc      .nocd           ; error getting parameters
1067
        jc      .nocd           ; error getting parameters
1034
        push    ds
1068
        push    ds
1035
        lds     si, [es:si+26]  ; pointer to Enhanced Disk Drive (EDD) configuration parameters
1069
        lds     si, [es:si+26]  ; pointer to Enhanced Disk Drive (EDD) configuration parameters
1036
        test    byte [ds:si+10], 40h ; check ATAPI device
1070
        test    byte [ds:si+10], 40h ; check ATAPI device
1037
        pop     ds
1071
        pop     ds
1038
        jz      .nocd
1072
        jz      .nocd
1039
 
1073
 
1040
; yes - read all floppy by 18 sectors
1074
; yes - read all floppy by 18 sectors
1041
 
1075
 
1042
; TODO: !!!! read only first sector and set variables !!!!!
1076
; TODO: !!!! read only first sector and set variables !!!!!
1043
; ...
1077
; ...
1044
; TODO: !!! then read flippy image track by track
1078
; TODO: !!! then read flippy image track by track
1045
 
1079
 
1046
        mov     cx, 0x0001      ; startcyl,startsector
1080
        mov     cx, 0x0001      ; startcyl,startsector
1047
.a1:
1081
.a1:
1048
        push    cx dx
1082
        push    cx dx
1049
        mov     al, 18
1083
        mov     al, 18
1050
        mov     bx, 0xa000
1084
        mov     bx, 0xa000
1051
        call    boot_read_floppy
1085
        call    boot_read_floppy
1052
        mov     si, movedesc
1086
        mov     si, movedesc
1053
        push    es
1087
        push    es
1054
        push    ds
1088
        push    ds
1055
        pop     es
1089
        pop     es
1056
        mov     cx, 256*18
1090
        mov     cx, 256*18
1057
        mov     ah, 0x87
1091
        mov     ah, 0x87
1058
        int     0x15
1092
        int     0x15
1059
        pop     es
1093
        pop     es
1060
        pop     dx cx
1094
        pop     dx cx
1061
        test    ah, ah
1095
        test    ah, ah
1062
        jnz     sayerr_floppy
1096
        jnz     sayerr_floppy
1063
        add     dword [si+8*3+2], 512*18
1097
        add     dword [si+8*3+2], 512*18
1064
        inc     dh
1098
        inc     dh
1065
        cmp     dh, 2
1099
        cmp     dh, 2
1066
        jnz     .a1
1100
        jnz     .a1
1067
        mov     dh, 0
1101
        mov     dh, 0
1068
        inc     ch
1102
        inc     ch
1069
        cmp     ch, 80
1103
        cmp     ch, 80
1070
        jae     ok_sys_on_floppy
1104
        jae     ok_sys_on_floppy
1071
        pusha
1105
        pusha
1072
        mov     al, ch
1106
        mov     al, ch
1073
        shr     ch, 2
1107
        shr     ch, 2
1074
        add     al, ch
1108
        add     al, ch
1075
        aam
1109
        aam
1076
        xchg    al, ah
1110
        xchg    al, ah
1077
        add     ax, '00'
1111
        add     ax, '00'
1078
        mov     si, pros
1112
        mov     si, pros
1079
        mov     [si], ax
1113
        mov     [si], ax
1080
        call    printplain
1114
        call    printplain
1081
        popa
1115
        popa
1082
        jmp     .a1
1116
        jmp     .a1
1083
.nocd:
1117
.nocd:
1084
; no - read only used sectors from floppy
1118
; no - read only used sectors from floppy
1085
; now load floppy image to memory
1119
; now load floppy image to memory
1086
; at first load boot sector and first FAT table
1120
; at first load boot sector and first FAT table
1087
 
1121
 
1088
; read only first sector and fill variables
1122
; read only first sector and fill variables
1089
        mov     cx, 0x0001      ; first logical sector
1123
        mov     cx, 0x0001      ; first logical sector
1090
        xor     dx, dx          ; head = 0, drive = 0 (a:)
1124
        xor     dx, dx          ; head = 0, drive = 0 (a:)
1091
        mov     al, 1           ; read one sector
1125
        mov     al, 1           ; read one sector
1092
        mov     bx, 0xB000      ; es:bx -> data area
1126
        mov     bx, 0xB000      ; es:bx -> data area
1093
        call    boot_read_floppy
1127
        call    boot_read_floppy
1094
; fill the necessary parameters to work with a floppy
1128
; fill the necessary parameters to work with a floppy
1095
        mov     ax, word [es:bx+24]
1129
        mov     ax, word [es:bx+24]
1096
        mov     word [BPB_SecPerTrk], ax
1130
        mov     word [BPB_SecPerTrk], ax
1097
        mov     ax, word [es:bx+26]
1131
        mov     ax, word [es:bx+26]
1098
        mov     word [BPB_NumHeads], ax
1132
        mov     word [BPB_NumHeads], ax
1099
        mov     ax, word [es:bx+17]
1133
        mov     ax, word [es:bx+17]
1100
        mov     word [BPB_RootEntCnt], ax
1134
        mov     word [BPB_RootEntCnt], ax
1101
        mov     ax, word [es:bx+14]
1135
        mov     ax, word [es:bx+14]
1102
        mov     word [BPB_RsvdSecCnt], ax
1136
        mov     word [BPB_RsvdSecCnt], ax
1103
        mov     ax, word [es:bx+19]
1137
        mov     ax, word [es:bx+19]
1104
        mov     word [BPB_TotSec16], ax
1138
        mov     word [BPB_TotSec16], ax
1105
        mov     al, byte [es:bx+13]
1139
        mov     al, byte [es:bx+13]
1106
        mov     byte [BPB_SecPerClus], al
1140
        mov     byte [BPB_SecPerClus], al
1107
        mov     al, byte [es:bx+16]
1141
        mov     al, byte [es:bx+16]
1108
        mov     byte [BPB_NumFATs], al
1142
        mov     byte [BPB_NumFATs], al
1109
; 18.11.2008
1143
; 18.11.2008
1110
        mov     ax, word [es:bx+22]
1144
        mov     ax, word [es:bx+22]
1111
        mov     word [BPB_FATSz16], ax
1145
        mov     word [BPB_FATSz16], ax
1112
        mov     cx, word [es:bx+11]
1146
        mov     cx, word [es:bx+11]
1113
        mov     word [BPB_BytsPerSec], cx
1147
        mov     word [BPB_BytsPerSec], cx
1114
 
1148
 
1115
; count of clusters in FAT12 ((size_of_FAT*2)/3)
1149
; count of clusters in FAT12 ((size_of_FAT*2)/3)
1116
;        mov     ax, word [BPB_FATSz16]
1150
;        mov     ax, word [BPB_FATSz16]
1117
;        mov     cx, word [BPB_BytsPerSec]
1151
;        mov     cx, word [BPB_BytsPerSec]
1118
;end  18.11.2008
1152
;end  18.11.2008
1119
        xor     dx, dx
1153
        xor     dx, dx
1120
        mul     cx
1154
        mul     cx
1121
        shl     ax, 1
1155
        shl     ax, 1
1122
        mov     cx, 3
1156
        mov     cx, 3
1123
        div     cx              ; now ax - number of clusters in FAT12
1157
        div     cx              ; now ax - number of clusters in FAT12
1124
        mov     word [end_of_FAT], ax
1158
        mov     word [end_of_FAT], ax
1125
 
1159
 
1126
; load first FAT table
1160
; load first FAT table
1127
        mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
1161
        mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
1128
        xor     dx, dx          ; starthead,drive
1162
        xor     dx, dx          ; starthead,drive
1129
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
1163
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
1130
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
1164
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
1131
        call    boot_read_floppy
1165
        call    boot_read_floppy
1132
        mov     bx, 0xB000
1166
        mov     bx, 0xB000
1133
 
1167
 
1134
; and copy them to extended memory
1168
; and copy them to extended memory
1135
        mov     si, movedesc
1169
        mov     si, movedesc
1136
        mov     [si+8*2+3], bh          ; from
1170
        mov     [si+8*2+3], bh          ; from
1137
        
1171
        
1138
        mov     ax, word [BPB_BytsPerSec]
1172
        mov     ax, word [BPB_BytsPerSec]
1139
        shr     ax, 1                   ; words per sector
1173
        shr     ax, 1                   ; words per sector
1140
        mov     cx, word [BPB_RsvdSecCnt]
1174
        mov     cx, word [BPB_RsvdSecCnt]
1141
        add     cx, word [BPB_FATSz16]
1175
        add     cx, word [BPB_FATSz16]
1142
        mul     cx
1176
        mul     cx
1143
        push    ax                      ; save to stack count of words in boot+FAT
1177
        push    ax                      ; save to stack count of words in boot+FAT
1144
        xchg    ax, cx
1178
        xchg    ax, cx
1145
        
1179
        
1146
        push    es
1180
        push    es
1147
        push    ds
1181
        push    ds
1148
        pop     es
1182
        pop     es
1149
        mov     ah, 0x87
1183
        mov     ah, 0x87
1150
        int     0x15
1184
        int     0x15
1151
        pop     es
1185
        pop     es
1152
        test    ah, ah
1186
        test    ah, ah
1153
        jz      @f
1187
        jz      @f
1154
sayerr_floppy:
1188
sayerr_floppy:
1155
        mov     dx, 0x3f2
1189
        mov     dx, 0x3f2
1156
        mov     al, 0
1190
        mov     al, 0
1157
        out     dx, al
1191
        out     dx, al
1158
sayerr_memmove:
1192
sayerr_memmove:
1159
        mov     si, memmovefailed
1193
        mov     si, memmovefailed
1160
        jmp     sayerr_plain
1194
        jmp     sayerr_plain
1161
@@:
1195
@@:
1162
        pop     ax                      ; restore from stack count of words in boot+FAT
1196
        pop     ax                      ; restore from stack count of words in boot+FAT
1163
        shl     ax, 1                   ; make bytes count from count of words
1197
        shl     ax, 1                   ; make bytes count from count of words
1164
        and     eax, 0ffffh
1198
        and     eax, 0ffffh
1165
        add     dword [si+8*3+2], eax
1199
        add     dword [si+8*3+2], eax
1166
 
1200
 
1167
; copy first FAT to second copy
1201
; copy first FAT to second copy
1168
; TODO: BPB_NumFATs !!!!!
1202
; TODO: BPB_NumFATs !!!!!
1169
        add     bx, word [BPB_BytsPerSec]       ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
1203
        add     bx, word [BPB_BytsPerSec]       ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
1170
        mov     byte [si+8*2+3], bh     ; bx - begin of FAT
1204
        mov     byte [si+8*2+3], bh     ; bx - begin of FAT
1171
        
1205
        
1172
        mov     ax, word [BPB_BytsPerSec]
1206
        mov     ax, word [BPB_BytsPerSec]
1173
        shr     ax, 1                   ; words per sector
1207
        shr     ax, 1                   ; words per sector
1174
        mov     cx, word [BPB_FATSz16]
1208
        mov     cx, word [BPB_FATSz16]
1175
        mul     cx
1209
        mul     cx
1176
        mov     cx, ax                  ; cx - count of words in FAT
1210
        mov     cx, ax                  ; cx - count of words in FAT
1177
 
1211
 
1178
        push    es
1212
        push    es
1179
        push    ds
1213
        push    ds
1180
        pop     es
1214
        pop     es
1181
        mov     ah, 0x87
1215
        mov     ah, 0x87
1182
        int     0x15
1216
        int     0x15
1183
        pop     es
1217
        pop     es
1184
        test    ah, ah
1218
        test    ah, ah
1185
        jnz     sayerr_floppy
1219
        jnz     sayerr_floppy
1186
        
1220
        
1187
        mov     ax, cx
1221
        mov     ax, cx
1188
        shl     ax, 1
1222
        shl     ax, 1
1189
        and     eax, 0ffffh             ; ax - count of bytes in FAT
1223
        and     eax, 0ffffh             ; ax - count of bytes in FAT
1190
        add     dword [si+8*3+2], eax
1224
        add     dword [si+8*3+2], eax
1191
        
1225
        
1192
; reading RootDir
1226
; reading RootDir
1193
; TODO: BPB_NumFATs
1227
; TODO: BPB_NumFATs
1194
        add     bx, ax
1228
        add     bx, ax
1195
        add     bx, 100h
1229
        add     bx, 100h
1196
        and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
1230
        and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
1197
        push    bx
1231
        push    bx
1198
 
1232
 
1199
        mov     bx, word [BPB_BytsPerSec]
1233
        mov     bx, word [BPB_BytsPerSec]
1200
        shr     bx, 5                           ; divide bx by 32
1234
        shr     bx, 5                           ; divide bx by 32
1201
        mov     ax, word [BPB_RootEntCnt]
1235
        mov     ax, word [BPB_RootEntCnt]
1202
        xor     dx, dx
1236
        xor     dx, dx
1203
        div     bx
1237
        div     bx
1204
        push    ax                              ; ax - count of RootDir sectors
1238
        push    ax                              ; ax - count of RootDir sectors
1205
 
1239
 
1206
        mov     ax, word [BPB_FATSz16]
1240
        mov     ax, word [BPB_FATSz16]
1207
        xor     cx, cx
1241
        xor     cx, cx
1208
        mov     cl, byte [BPB_NumFATs]
1242
        mov     cl, byte [BPB_NumFATs]
1209
        mul     cx
1243
        mul     cx
1210
        add     ax, word [BPB_RsvdSecCnt]       ; ax - first sector of RootDir
1244
        add     ax, word [BPB_RsvdSecCnt]       ; ax - first sector of RootDir
1211
 
1245
 
1212
        mov     word [FirstDataSector], ax
1246
        mov     word [FirstDataSector], ax
1213
        pop     bx
1247
        pop     bx
1214
        push    bx
1248
        push    bx
1215
        add     word [FirstDataSector], bx      ; Begin of data region of floppy
1249
        add     word [FirstDataSector], bx      ; Begin of data region of floppy
1216
        
1250
        
1217
; read RootDir
1251
; read RootDir
1218
        call    conv_abs_to_THS
1252
        call    conv_abs_to_THS
1219
        pop     ax
1253
        pop     ax
1220
        pop     bx                              ; place in buffer to write
1254
        pop     bx                              ; place in buffer to write
1221
        push    ax
1255
        push    ax
1222
        call    boot_read_floppy                ; read RootDir into buffer
1256
        call    boot_read_floppy                ; read RootDir into buffer
1223
; copy RootDir
1257
; copy RootDir
1224
        mov     byte [si+8*2+3], bh             ; from buffer
1258
        mov     byte [si+8*2+3], bh             ; from buffer
1225
        pop     ax                              ; ax = count of RootDir sectors
1259
        pop     ax                              ; ax = count of RootDir sectors
1226
        mov     cx, word [BPB_BytsPerSec]
1260
        mov     cx, word [BPB_BytsPerSec]
1227
        mul     cx
1261
        mul     cx
1228
        shr     ax, 1
1262
        shr     ax, 1
1229
        mov     cx, ax                          ; count of words to copy
1263
        mov     cx, ax                          ; count of words to copy
1230
        push    es
1264
        push    es
1231
        push    ds
1265
        push    ds
1232
        pop     es
1266
        pop     es
1233
        mov     ah, 0x87
1267
        mov     ah, 0x87
1234
        int     0x15
1268
        int     0x15
1235
        pop     es
1269
        pop     es
1236
 
1270
 
1237
        mov     ax, cx
1271
        mov     ax, cx
1238
        shl     ax, 1
1272
        shl     ax, 1
1239
        and     eax, 0ffffh             ; ax - count of bytes in RootDir
1273
        and     eax, 0ffffh             ; ax - count of bytes in RootDir
1240
        add     dword [si+8*3+2], eax   ; add count of bytes copied
1274
        add     dword [si+8*3+2], eax   ; add count of bytes copied
1241
 
1275
 
1242
; Reading data clusters from floppy
1276
; Reading data clusters from floppy
1243
        mov     byte [si+8*2+3], bh
1277
        mov     byte [si+8*2+3], bh
1244
        push    bx
1278
        push    bx
1245
 
1279
 
1246
        mov     di, 2                   ; First data cluster
1280
        mov     di, 2                   ; First data cluster
1247
.read_loop:
1281
.read_loop:
1248
        mov     bx, di
1282
        mov     bx, di
1249
        shr     bx, 1                   ; bx+di = di*1.5
1283
        shr     bx, 1                   ; bx+di = di*1.5
1250
        jnc     .even
1284
        jnc     .even
1251
        test    word [es:bx+di+0xB200], 0xFFF0  ; TODO: may not be 0xB200 !!!
1285
        test    word [es:bx+di+0xB200], 0xFFF0  ; TODO: may not be 0xB200 !!!
1252
        jmp     @f
1286
        jmp     @f
1253
.even:
1287
.even:
1254
        test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
1288
        test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
1255
 
1289
 
1256
@@:
1290
@@:
1257
        jz      .skip
1291
        jz      .skip
1258
; read cluster di
1292
; read cluster di
1259
;.read:
1293
;.read:
1260
        ;conv cluster di to abs. sector ax
1294
        ;conv cluster di to abs. sector ax
1261
        ; ax = (N-2) * BPB_SecPerClus + FirstDataSector
1295
        ; ax = (N-2) * BPB_SecPerClus + FirstDataSector
1262
        mov     ax, di
1296
        mov     ax, di
1263
        sub     ax, 2
1297
        sub     ax, 2
1264
        xor     bx, bx
1298
        xor     bx, bx
1265
        mov     bl, byte [BPB_SecPerClus]
1299
        mov     bl, byte [BPB_SecPerClus]
1266
        mul     bx
1300
        mul     bx
1267
        add     ax, word [FirstDataSector]
1301
        add     ax, word [FirstDataSector]
1268
        call    conv_abs_to_THS
1302
        call    conv_abs_to_THS
1269
        pop     bx
1303
        pop     bx
1270
        push    bx
1304
        push    bx
1271
        mov     al, byte [BPB_SecPerClus]       ; number of sectors in cluster
1305
        mov     al, byte [BPB_SecPerClus]       ; number of sectors in cluster
1272
        call    boot_read_floppy
1306
        call    boot_read_floppy
1273
        push    es
1307
        push    es
1274
        push    ds
1308
        push    ds
1275
        pop     es
1309
        pop     es
1276
        pusha
1310
        pusha
1277
;
1311
;
1278
        mov     ax, word [BPB_BytsPerSec]
1312
        mov     ax, word [BPB_BytsPerSec]
1279
        xor     cx, cx
1313
        xor     cx, cx
1280
        mov     cl, byte [BPB_SecPerClus]
1314
        mov     cl, byte [BPB_SecPerClus]
1281
        mul     cx
1315
        mul     cx
1282
        shr     ax, 1                           ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
1316
        shr     ax, 1                           ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
1283
        mov     cx, ax                          ; number of words to copy (count words in cluster)
1317
        mov     cx, ax                          ; number of words to copy (count words in cluster)
1284
;
1318
;
1285
        mov     ah, 0x87
1319
        mov     ah, 0x87
1286
        int     0x15                            ; copy data
1320
        int     0x15                            ; copy data
1287
        test    ah, ah
1321
        test    ah, ah
1288
        popa
1322
        popa
1289
        pop     es
1323
        pop     es
1290
        jnz     sayerr_floppy
1324
        jnz     sayerr_floppy
1291
; skip cluster di
1325
; skip cluster di
1292
.skip:
1326
.skip:
1293
        mov     ax, word [BPB_BytsPerSec]
1327
        mov     ax, word [BPB_BytsPerSec]
1294
        xor     cx, cx
1328
        xor     cx, cx
1295
        mov     cl, byte [BPB_SecPerClus]
1329
        mov     cl, byte [BPB_SecPerClus]
1296
        mul     cx
1330
        mul     cx
1297
        and     eax, 0ffffh             ; ax - count of bytes in cluster
1331
        and     eax, 0ffffh             ; ax - count of bytes in cluster
1298
        add     dword [si+8*3+2], eax
1332
        add     dword [si+8*3+2], eax
1299
 
1333
 
1300
        mov     ax, word [end_of_FAT]   ; max cluster number
1334
        mov     ax, word [end_of_FAT]   ; max cluster number
1301
        pusha
1335
        pusha
1302
; draw percentage
1336
; draw percentage
1303
; total clusters: ax
1337
; total clusters: ax
1304
; read clusters: di
1338
; read clusters: di
1305
        xchg    ax, di
1339
        xchg    ax, di
1306
        mov     cx, 100
1340
        mov     cx, 100
1307
        mul     cx
1341
        mul     cx
1308
        div     di
1342
        div     di
1309
        aam
1343
        aam
1310
        xchg    al, ah
1344
        xchg    al, ah
1311
        add     ax, '00'
1345
        add     ax, '00'
1312
        mov     si, pros
1346
        mov     si, pros
1313
        cmp     [si], ax
1347
        cmp     [si], ax
1314
        jz      @f
1348
        jz      @f
1315
        mov     [si], ax
1349
        mov     [si], ax
1316
        call    printplain
1350
        call    printplain
1317
@@:
1351
@@:
1318
        popa
1352
        popa
1319
        inc     di
1353
        inc     di
1320
        cmp     di, word [end_of_FAT]   ; max number of cluster
1354
        cmp     di, word [end_of_FAT]   ; max number of cluster
1321
        jnz     .read_loop
1355
        jnz     .read_loop
1322
        pop     bx                      ; clear stack
1356
        pop     bx                      ; clear stack
1323
 
1357
 
1324
ok_sys_on_floppy:
1358
ok_sys_on_floppy:
1325
        mov     si, backspace2
1359
        mov     si, backspace2
1326
        call    printplain
1360
        call    printplain
1327
        mov     si, okt
1361
        mov     si, okt
1328
        call    printplain
1362
        call    printplain
1329
no_sys_on_floppy:
1363
no_sys_on_floppy:
1330
        xor     ax, ax          ; reset drive
1364
        xor     ax, ax          ; reset drive
1331
        xor     dx, dx
1365
        xor     dx, dx
1332
        int     0x13
1366
        int     0x13
1333
        mov     dx, 0x3f2       ; floppy motor off
1367
        mov     dx, 0x3f2       ; floppy motor off
1334
        mov     al, 0
1368
        mov     al, 0
1335
        out     dx, al
1369
        out     dx, al
1336
 
1370
 
1337
if defined extended_primary_loader
1371
if defined extended_primary_loader
1338
        cmp     [es:BOOT_LO.rd_load_from], RD_LOAD_FROM_HD
1372
        cmp     [es:BOOT_LO.rd_load_from], RD_LOAD_FROM_HD
1339
        jne     no_sys_from_primary
1373
        jne     no_sys_from_primary
1340
; load kolibri.img using callback from primary loader
1374
; load kolibri.img using callback from primary loader
1341
        and     word [movedesc + 24 + 2], 0
1375
        and     word [movedesc + 24 + 2], 0
1342
        mov     byte [movedesc + 24 + 4], 10h
1376
        mov     byte [movedesc + 24 + 4], 10h
1343
; read in blocks of 64K until file is fully loaded
1377
; read in blocks of 64K until file is fully loaded
1344
        mov     ax, 1
1378
        mov     ax, 1
1345
.repeat:
1379
.repeat:
1346
        mov     di, image_file_struct
1380
        mov     di, image_file_struct
1347
        call    [bootcallback]
1381
        call    [bootcallback]
1348
        push    cs
1382
        push    cs
1349
        pop     ds
1383
        pop     ds
1350
        push    cs
1384
        push    cs
1351
        pop     es
1385
        pop     es
1352
        cmp     bx, 1
1386
        cmp     bx, 1
1353
        ja      sayerr_badsect
1387
        ja      sayerr_badsect
1354
        push    bx
1388
        push    bx
1355
        mov     si, movedesc
1389
        mov     si, movedesc
1356
        and     word [si + 16 + 2], 0
1390
        and     word [si + 16 + 2], 0
1357
        mov     byte [si + 16 + 4], 4
1391
        mov     byte [si + 16 + 4], 4
1358
        mov     ah, 87h
1392
        mov     ah, 87h
1359
        mov     cx, 8000h
1393
        mov     cx, 8000h
1360
        int     15h
1394
        int     15h
1361
        pop     bx
1395
        pop     bx
1362
        test    ah, ah
1396
        test    ah, ah
1363
        jnz     sayerr_memmove
1397
        jnz     sayerr_memmove
1364
        inc     byte [si + 24 + 4]
1398
        inc     byte [si + 24 + 4]
1365
        test    bx, bx
1399
        test    bx, bx
1366
        jz      no_sys_from_primary
1400
        jz      no_sys_from_primary
1367
        mov     ax, 2
1401
        mov     ax, 2
1368
        jmp     .repeat
1402
        jmp     .repeat
1369
no_sys_from_primary:
1403
no_sys_from_primary:
1370
end if
1404
end if
1371
 
1405
 
1372
; SET GRAPHICS
1406
; SET GRAPHICS
1373
 
1407
 
1374
        xor     ax, ax
1408
        xor     ax, ax
1375
        mov     es, ax
1409
        mov     es, ax
1376
 
1410
 
1377
        mov     ax, [es:BOOT_LO.vesa_mode]         ; vga & 320x200
1411
        mov     ax, [es:BOOT_LO.vesa_mode]         ; vga & 320x200
1378
        mov     bx, ax
1412
        mov     bx, ax
1379
        cmp     ax, 0x13
1413
        cmp     ax, 0x13
1380
        je      setgr
1414
        je      setgr
1381
        cmp     ax, 0x12
1415
        cmp     ax, 0x12
1382
        je      setgr
1416
        je      setgr
1383
        mov     ax, 0x4f02              ; Vesa
1417
        mov     ax, 0x4f02              ; Vesa
1384
setgr:
1418
setgr:
1385
        int     0x10
1419
        int     0x10
1386
        test    ah, ah
1420
        test    ah, ah
1387
        mov     si, fatalsel
1421
        mov     si, fatalsel
1388
        jnz     v_mode_error
1422
        jnz     v_mode_error
1389
; set mode 0x12 graphics registers:
1423
; set mode 0x12 graphics registers:
1390
        cmp     bx, 0x12
1424
        cmp     bx, 0x12
1391
        jne     gmok2
1425
        jne     gmok2
1392
 
1426
 
1393
        mov     al, 0x05
1427
        mov     al, 0x05
1394
        mov     dx, 0x03ce
1428
        mov     dx, 0x03ce
1395
        push    dx
1429
        push    dx
1396
        out     dx, al      ; select GDC mode register
1430
        out     dx, al      ; select GDC mode register
1397
        mov     al, 0x02
1431
        mov     al, 0x02
1398
        inc     dx
1432
        inc     dx
1399
        out     dx, al      ; set write mode 2
1433
        out     dx, al      ; set write mode 2
1400
 
1434
 
1401
        mov     al, 0x02
1435
        mov     al, 0x02
1402
        mov     dx, 0x03c4
1436
        mov     dx, 0x03c4
1403
        out     dx, al      ; select VGA sequencer map mask register
1437
        out     dx, al      ; select VGA sequencer map mask register
1404
        mov     al, 0x0f
1438
        mov     al, 0x0f
1405
        inc     dx
1439
        inc     dx
1406
        out     dx, al      ; set mask for all planes 0-3
1440
        out     dx, al      ; set mask for all planes 0-3
1407
 
1441
 
1408
        mov     al, 0x08
1442
        mov     al, 0x08
1409
        pop     dx
1443
        pop     dx
1410
        out     dx, al      ; select GDC bit mask register
1444
        out     dx, al      ; select GDC bit mask register
1411
                           ; for writes to 0x03cf
1445
                           ; for writes to 0x03cf
1412
gmok2:
1446
gmok2:
1413
        push    ds
1447
        push    ds
1414
        pop     es
1448
        pop     es