Subversion Repositories Kolibri OS

Rev

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

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