Subversion Repositories Kolibri OS

Rev

Rev 3989 | Rev 4291 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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