Subversion Repositories Kolibri OS

Rev

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

Rev 7121 Rev 7129
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
6
;;                                                              ;;
7
;;  BOOTCODE.INC                                                ;;
7
;;  BOOTCODE.INC                                                ;;
8
;;                                                              ;;
8
;;                                                              ;;
9
;;  KolibriOS 16-bit loader,                                    ;;
9
;;  KolibriOS 16-bit loader,                                    ;;
10
;;                        based on bootcode for MenuetOS        ;;
10
;;                        based on bootcode for MenuetOS        ;;
11
;;                                                              ;;
11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
13
 
14
$Revision: 7121 $
14
$Revision: 7129 $
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, (TMP_STACK_TOP and 0xF0000) shr 4
179
        mov     ax, (TMP_STACK_TOP and 0xF0000) shr 4
180
        mov     ss, ax
180
        mov     ss, ax
181
        mov     sp, TMP_STACK_TOP and 0xFFFF
181
        mov     sp, TMP_STACK_TOP and 0xFFFF
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
        push    0
-
 
278
        pop     es
277
; \begin{diamond}[02.12.2005]
279
; \begin{diamond}[02.12.2005]
278
; if bootloader sets ax = 'KL', then ds:si points to loader block
280
; if bootloader sets ax = 'KL', then ds:si points to loader block
279
        cmp     ax, 'KL'
281
        cmp     ax, 'KL'
280
        jnz     @f
282
        jnz     @f
281
        mov     word [cs:cfgmanager.loader_block], si
283
        mov     word [cs:cfgmanager.loader_block], si
282
        mov     word [cs:cfgmanager.loader_block+2], ds
284
        mov     word [cs:cfgmanager.loader_block+2], ds
-
 
285
        mov     word [es:BOOT_KERNEL_RESTART], kernel_restart_bootblock
283
@@:
286
@@:
284
; \end{diamond}[02.12.2005]
287
; \end{diamond}[02.12.2005]
285
 
288
 
286
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source hard disk
289
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source disk
-
 
290
; (see comment to BOOT_BX_FROM_LOAD and loader_doc.txt)
287
; (see comment to bx_from_load)
291
        mov     word [es:BOOT_BX_FROM_LOAD], 'r1'  ; default value: /rd/1
288
        cmp     cx, 'HA'
292
        cmp     cx, 'HA'
289
        jnz     no_hd_load
293
        jnz     no_hd_load
290
        cmp     dx, 'RD'
294
        cmp     dx, 'RD'
291
        jnz     no_hd_load
295
        jnz     no_hd_load
292
        mov     word [cs:bx_from_load], bx              ; {SPraid}[13.03.2007]
296
        mov     [es:BOOT_BX_FROM_LOAD], bx
293
no_hd_load:
297
no_hd_load:
294
 
298
 
295
; set up stack
299
; set up stack
296
        mov     ax, (TMP_STACK_TOP and 0xF0000) shr 4
300
        mov     ax, (TMP_STACK_TOP and 0xF0000) shr 4
297
        mov     ss, ax
301
        mov     ss, ax
298
        mov     sp, TMP_STACK_TOP and 0xFFFF
302
        mov     sp, TMP_STACK_TOP and 0xFFFF
299
; set up segment registers
303
; set up segment registers
300
        push    cs
304
        push    cs
301
        pop     ds
305
        pop     ds
302
        push    cs
306
        push    cs
303
        pop     es
307
        pop     es
304
end if
308
end if
305
 
309
 
306
; set videomode
310
; set videomode
307
        mov     ax, 3
311
        mov     ax, 3
308
        int     0x10
312
        int     0x10
309
 
313
 
310
if lang eq ru
314
if lang eq ru
311
 ; Load & set russian VGA font (RU.INC)
315
 ; Load & set russian VGA font (RU.INC)
312
        mov     bp, RU_FNT1             ; RU_FNT1 - First part
316
        mov     bp, RU_FNT1             ; RU_FNT1 - First part
313
        mov     bx, 1000h               ; 768 bytes
317
        mov     bx, 1000h               ; 768 bytes
314
        mov     cx, 30h                 ; 48 symbols
318
        mov     cx, 30h                 ; 48 symbols
315
        mov     dx, 80h                 ; 128 - position of first symbol
319
        mov     dx, 80h                 ; 128 - position of first symbol
316
        mov     ax, 1100h
320
        mov     ax, 1100h
317
        int     10h
321
        int     10h
318
 
322
 
319
        mov     bp, RU_FNT2             ; RU_FNT2 -Second part
323
        mov     bp, RU_FNT2             ; RU_FNT2 -Second part
320
        mov     bx, 1000h               ; 512 bytes
324
        mov     bx, 1000h               ; 512 bytes
321
        mov     cx, 20h                 ; 32 symbols
325
        mov     cx, 20h                 ; 32 symbols
322
        mov     dx, 0E0h                ; 224 - position of first symbol
326
        mov     dx, 0E0h                ; 224 - position of first symbol
323
        mov     ax, 1100h
327
        mov     ax, 1100h
324
        int     10h
328
        int     10h
325
 ; End set VGA russian font
329
 ; End set VGA russian font
326
else if lang eq et
330
else if lang eq et
327
        mov     bp, ET_FNT              ; ET_FNT1
331
        mov     bp, ET_FNT              ; ET_FNT1
328
        mov     bx, 1000h               ;
332
        mov     bx, 1000h               ;
329
        mov     cx, 255                 ; 256 symbols
333
        mov     cx, 255                 ; 256 symbols
330
        xor     dx, dx                  ; 0 - position of first symbol
334
        xor     dx, dx                  ; 0 - position of first symbol
331
        mov     ax, 1100h
335
        mov     ax, 1100h
332
        int     10h
336
        int     10h
333
end if
337
end if
334
 
338
 
335
; draw frames
339
; draw frames
336
        push    0xb800
340
        push    0xb800
337
        pop     es
341
        pop     es
338
        xor     di, di
342
        xor     di, di
339
        mov     ah, 1*16+15
343
        mov     ah, 1*16+15
340
 
344
 
341
; draw top
345
; draw top
342
        mov     si, d80x25_top
346
        mov     si, d80x25_top
343
        mov     cx, d80x25_top_num * 80
347
        mov     cx, d80x25_top_num * 80
344
@@:
348
@@:
345
        lodsb
349
        lodsb
346
        stosw
350
        stosw
347
        loop    @b
351
        loop    @b
348
; draw spaces
352
; draw spaces
349
        mov     si, space_msg
353
        mov     si, space_msg
350
        mov     dx, 25 - d80x25_top_num - d80x25_bottom_num
354
        mov     dx, 25 - d80x25_top_num - d80x25_bottom_num
351
dfl1:
355
dfl1:
352
        push    si
356
        push    si
353
        mov     cx, 80
357
        mov     cx, 80
354
@@:
358
@@:
355
        lodsb
359
        lodsb
356
        stosw
360
        stosw
357
        loop    @b
361
        loop    @b
358
        pop     si
362
        pop     si
359
        dec     dx
363
        dec     dx
360
        jnz     dfl1
364
        jnz     dfl1
361
; draw bottom
365
; draw bottom
362
        mov     si, d80x25_bottom
366
        mov     si, d80x25_bottom
363
        mov     cx, d80x25_bottom_num * 80
367
        mov     cx, d80x25_bottom_num * 80
364
@@:
368
@@:
365
        lodsb
369
        lodsb
366
        stosw
370
        stosw
367
        loop    @b
371
        loop    @b
368
 
372
 
369
        mov     byte [space_msg+80], 0    ; now space_msg is null terminated
373
        mov     byte [space_msg+80], 0    ; now space_msg is null terminated
370
 
374
 
371
        _setcursor d80x25_top_num,0
375
        _setcursor d80x25_top_num,0
372
 
376
 
373
 
377
 
374
; TEST FOR 386+
378
; TEST FOR 386+
375
 
379
 
376
        mov     bx, 0x4000
380
        mov     bx, 0x4000
377
        pushf
381
        pushf
378
        pop     ax
382
        pop     ax
379
        mov     dx, ax
383
        mov     dx, ax
380
        xor     ax, bx
384
        xor     ax, bx
381
        push    ax
385
        push    ax
382
        popf
386
        popf
383
        pushf
387
        pushf
384
        pop     ax
388
        pop     ax
385
        and     ax, bx
389
        and     ax, bx
386
        and     dx, bx
390
        and     dx, bx
387
        cmp     ax, dx
391
        cmp     ax, dx
388
        jnz     cpugood
392
        jnz     cpugood
389
        mov     si, not386
393
        mov     si, not386
390
sayerr:
394
sayerr:
391
        call    print
395
        call    print
392
        jmp     $
396
        jmp     $
393
     cpugood:
397
     cpugood:
394
 
398
 
395
        push    0
399
        push    0
396
        popf
400
        popf
397
 
401
 
398
; set up esp
402
; set up esp
399
        movzx   esp, sp
403
        movzx   esp, sp
400
 
404
 
401
        push    0
405
        push    0
402
        pop     es
406
        pop     es
403
 
407
 
404
        xor     cx, cx
408
        xor     cx, cx
405
@@:
409
@@:
406
        in      al, 64h
410
        in      al, 64h
407
        test    al, 2
411
        test    al, 2
408
        loopnz  @b
412
        loopnz  @b
409
 
413
 
410
        mov     al, 0xf6        ; Сброс клавиатуры, разрешить сканирование
414
        mov     al, 0xf6        ; Сброс клавиатуры, разрешить сканирование
411
        out     0x60, al
415
        out     0x60, al
412
        xor     cx, cx
416
        xor     cx, cx
413
@@:
417
@@:
414
        in      al, 64h
418
        in      al, 64h
415
        test    al, 1
419
        test    al, 1
416
        loopz   @b
420
        loopz   @b
417
        in      al, 0x60
421
        in      al, 0x60
418
 
422
 
419
;;;/diamond today   5.02.2008
423
;;;/diamond today   5.02.2008
420
; set keyboard typematic rate & delay
424
; set keyboard typematic rate & delay
421
        mov     al, 0xf3
425
        mov     al, 0xf3
422
        out     0x60, al
426
        out     0x60, al
423
        xor     cx, cx
427
        xor     cx, cx
424
@@:
428
@@:
425
        in      al, 64h
429
        in      al, 64h
426
        test    al, 1
430
        test    al, 1
427
        loopz   @b
431
        loopz   @b
428
        in      al, 0x60
432
        in      al, 0x60
429
        mov     al, 0
433
        mov     al, 0
430
        out     0x60, al
434
        out     0x60, al
431
        xor     cx, cx
435
        xor     cx, cx
432
@@:
436
@@:
433
        in      al, 64h
437
        in      al, 64h
434
        test    al, 1
438
        test    al, 1
435
        loopz   @b
439
        loopz   @b
436
        in      al, 0x60
440
        in      al, 0x60
437
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
441
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
438
        sti
442
        sti
439
; --------------- APM ---------------------
443
; --------------- APM ---------------------
440
        and     word [es:BOOT_APM_VERSION], 0     ; ver = 0.0 (APM not found)
444
        and     word [es:BOOT_APM_VERSION], 0     ; ver = 0.0 (APM not found)
441
        mov     ax, 0x5300
445
        mov     ax, 0x5300
442
        xor     bx, bx
446
        xor     bx, bx
443
        int     0x15
447
        int     0x15
444
        jc      apm_end                 ; APM not found
448
        jc      apm_end                 ; APM not found
445
        test    cx, 2
449
        test    cx, 2
446
        jz      apm_end                 ; APM 32-bit protected-mode interface not supported
450
        jz      apm_end                 ; APM 32-bit protected-mode interface not supported
447
        mov     [es:BOOT_APM_VERSION], ax         ; Save APM Version
451
        mov     [es:BOOT_APM_VERSION], ax         ; Save APM Version
448
        mov     [es:BOOT_APM_FLAGS], cx           ; Save APM flags
452
        mov     [es:BOOT_APM_FLAGS], cx           ; Save APM flags
449
 
453
 
450
        ; Write APM ver ----
454
        ; Write APM ver ----
451
        and     ax, 0xf0f
455
        and     ax, 0xf0f
452
        add     ax, '00'
456
        add     ax, '00'
453
        mov     si, msg_apm
457
        mov     si, msg_apm
454
        mov     [si + 5], ah
458
        mov     [si + 5], ah
455
        mov     [si + 7], al
459
        mov     [si + 7], al
456
        _setcursor 0, 3
460
        _setcursor 0, 3
457
        call    printplain
461
        call    printplain
458
        ; ------------------
462
        ; ------------------
459
 
463
 
460
        mov     ax, 0x5304              ; Disconnect interface
464
        mov     ax, 0x5304              ; Disconnect interface
461
        xor     bx, bx
465
        xor     bx, bx
462
        int     0x15
466
        int     0x15
463
        mov     ax, 0x5303              ; Connect 32 bit mode interface
467
        mov     ax, 0x5303              ; Connect 32 bit mode interface
464
        xor     bx, bx
468
        xor     bx, bx
465
        int     0x15
469
        int     0x15
466
 
470
 
467
        mov     [es:BOOT_APM_ENTRY], ebx
471
        mov     [es:BOOT_APM_ENTRY], ebx
468
        mov     [es:BOOT_APM_CODE_32], ax
472
        mov     [es:BOOT_APM_CODE_32], ax
469
        mov     [es:BOOT_APM_CODE_16], cx
473
        mov     [es:BOOT_APM_CODE_16], cx
470
        mov     [es:BOOT_APM_DATA_16], dx
474
        mov     [es:BOOT_APM_DATA_16], dx
471
 
475
 
472
apm_end:
476
apm_end:
473
        _setcursor d80x25_top_num, 0
477
        _setcursor d80x25_top_num, 0
474
 
478
 
475
if ~ defined extended_primary_loader
479
if ~ defined extended_primary_loader
476
;CHECK current of code
480
;CHECK current of code
477
        cmp     [cfgmanager.loader_block], -1
481
        cmp     [cfgmanager.loader_block], -1
478
        jz      noloaderblock
482
        jz      noloaderblock
479
        les     bx, [cfgmanager.loader_block]
483
        les     bx, [cfgmanager.loader_block]
480
        cmp     byte [es:bx], 1
484
        cmp     byte [es:bx], 1
481
        mov     si, loader_block_error
485
        mov     si, loader_block_error
482
        jnz     sayerr
486
        jnz     sayerr
483
        push    0
487
        push    0
484
        pop     es
488
        pop     es
485
end if
489
end if
486
 
490
 
487
noloaderblock:
491
noloaderblock:
488
; DISPLAY VESA INFORMATION
492
; DISPLAY VESA INFORMATION
489
        call    print_vesa_info
493
        call    print_vesa_info
490
        call    calc_vmodes_table
494
        call    calc_vmodes_table
491
        call    check_first_parm   ;check and enable cursor_pos
495
        call    check_first_parm   ;check and enable cursor_pos
492
 
496
 
493
; \begin{diamond}[30.11.2005]
497
; \begin{diamond}[30.11.2005]
494
cfgmanager:
498
cfgmanager:
495
; settings:
499
; settings:
496
; a) preboot_graph = graphical mode
500
; a) preboot_graph = graphical mode
497
;    preboot_gprobe = probe this mode?
501
;    preboot_gprobe = probe this mode?
498
; b) preboot_biosdisk  = use BIOS disks through V86 emulation? // (earlier was: preboot_dma  = use DMA access?)
502
; b) preboot_biosdisk  = use BIOS disks through V86 emulation? // (earlier was: preboot_dma  = use DMA access?)
499
; c) preboot_debug = duplicates kernel debug output to the screen
503
; c) preboot_debug = duplicates kernel debug output to the screen
500
; d) preboot_launcher = start the first app (right now it's LAUNCHER) after kernel is loaded?
504
; d) preboot_launcher = start the first app (right now it's LAUNCHER) after kernel is loaded?
501
; e) preboot_device = from where to boot?
505
; e) preboot_device = from where to boot?
502
 
506
 
503
; determine default settings
507
; determine default settings
504
if ~ defined extended_primary_loader
508
if ~ defined extended_primary_loader
505
        mov     [.bSettingsChanged], 0
509
        mov     [.bSettingsChanged], 0
506
end if
510
end if
507
 
511
 
508
;.preboot_gr_end:
512
;.preboot_gr_end:
509
        mov     di, preboot_device
513
        mov     di, preboot_device
510
; if image in memory is present and [preboot_device] is uninitialized,
514
; if image in memory is present and [preboot_device] is uninitialized,
511
; set it to use this preloaded image
515
; set it to use this preloaded image
512
        cmp     byte [di], 0
516
        cmp     byte [di], 0
513
        jnz     .preboot_device_inited
517
        jnz     .preboot_device_inited
514
if defined extended_primary_loader
518
if defined extended_primary_loader
515
        inc     byte [di]
519
        inc     byte [di]
516
        cmp     byte [bootdevice], 'f' ; floppy?
520
        cmp     byte [bootdevice], 'f' ; floppy?
517
        jz      .preboot_device_inited
521
        jz      .preboot_device_inited
518
        inc     byte [di]
522
        inc     byte [di]
519
else
523
else
520
        cmp     [.loader_block], -1
524
        cmp     [.loader_block], -1
521
        jz      @f
525
        jz      @f
522
        les     bx, [.loader_block]
526
        les     bx, [.loader_block]
523
        test    byte [es:bx+1], 1
527
        test    byte [es:bx+1], 1
524
        jz      @f
528
        jz      @f
525
        mov     byte [di], 3
529
        mov     byte [di], 3
526
        jmp     .preboot_device_inited
530
        jmp     .preboot_device_inited
527
@@:
531
@@:
528
; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
532
; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
529
        mov     byte [di], 1
533
        mov     byte [di], 1
530
end if
534
end if
531
.preboot_device_inited:
535
.preboot_device_inited:
532
; following 4 lines set variables to 1 if its current value is 0
536
; following 4 lines set variables to 1 if its current value is 0
533
        cmp     byte [di+preboot_dma-preboot_device], 1
537
        cmp     byte [di+preboot_dma-preboot_device], 1
534
        adc     byte [di+preboot_dma-preboot_device], 0
538
        adc     byte [di+preboot_dma-preboot_device], 0
535
        cmp     byte [di+preboot_launcher-preboot_device], 1        ; Start LAUNCHER by default
539
        cmp     byte [di+preboot_launcher-preboot_device], 1        ; Start LAUNCHER by default
536
        adc     byte [di+preboot_launcher-preboot_device], 0
540
        adc     byte [di+preboot_launcher-preboot_device], 0
537
        _setcursor 5,2
541
        _setcursor 5,2
538
 
542
 
539
        mov     si, linef
543
        mov     si, linef
540
        call    printplain
544
        call    printplain
541
        mov     si, start_msg
545
        mov     si, start_msg
542
        call    print
546
        call    print
543
        mov     si, time_msg
547
        mov     si, time_msg
544
        call    print
548
        call    print
545
; get start time
549
; get start time
546
        call    .gettime
550
        call    .gettime
547
        mov     [.starttime], eax
551
        mov     [.starttime], eax
548
        mov     word [.timer], .newtimer
552
        mov     word [.timer], .newtimer
549
        mov     word [.timer+2], cs
553
        mov     word [.timer+2], cs
550
.printcfg:
554
.printcfg:
551
 
555
 
552
        _setcursor 9,0
556
        _setcursor 9,0
553
        mov     si, current_cfg_msg
557
        mov     si, current_cfg_msg
554
        call    print
558
        call    print
555
        mov     si, curvideo_msg
559
        mov     si, curvideo_msg
556
        call    print
560
        call    print
557
 
561
 
558
        call    draw_current_vmode
562
        call    draw_current_vmode
559
 
563
 
560
        mov     si, usebd_msg
564
        mov     si, usebd_msg
561
        cmp     [preboot_biosdisk], 1
565
        cmp     [preboot_biosdisk], 1
562
        call    .say_on_off
566
        call    .say_on_off
563
        mov     si, debug_mode_msg
567
        mov     si, debug_mode_msg
564
        cmp     [preboot_debug], 1
568
        cmp     [preboot_debug], 1
565
        call    .say_on_off
569
        call    .say_on_off
566
        mov     si, launcher_msg
570
        mov     si, launcher_msg
567
        cmp     [preboot_launcher], 1
571
        cmp     [preboot_launcher], 1
568
        call    .say_on_off
572
        call    .say_on_off
569
        mov     si, preboot_device_msg
573
        mov     si, preboot_device_msg
570
        call    print
574
        call    print
571
        mov     al, [preboot_device]
575
        mov     al, [preboot_device]
572
if defined extended_primary_loader
576
if defined extended_primary_loader
573
        and     eax, 3
577
        and     eax, 3
574
else
578
else
575
        and     eax, 7
579
        and     eax, 7
576
end if
580
end if
577
        mov     si, [preboot_device_msgs+eax*2]
581
        mov     si, [preboot_device_msgs+eax*2]
578
        call    printplain
582
        call    printplain
579
.show_remarks:
583
.show_remarks:
580
; show remarks in gray color
584
; show remarks in gray color
581
        mov     di, ((21-num_remarks)*80 + 2)*2
585
        mov     di, ((21-num_remarks)*80 + 2)*2
582
        push    0xB800
586
        push    0xB800
583
        pop     es
587
        pop     es
584
        mov     cx, num_remarks
588
        mov     cx, num_remarks
585
        mov     si, remarks
589
        mov     si, remarks
586
.write_remarks:
590
.write_remarks:
587
        lodsw
591
        lodsw
588
        push    si
592
        push    si
589
        xchg    ax, si
593
        xchg    ax, si
590
        mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
594
        mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
591
        push    di
595
        push    di
592
.write_remark:
596
.write_remark:
593
        lodsb
597
        lodsb
594
        test    al, al
598
        test    al, al
595
        jz      @f
599
        jz      @f
596
        stosw
600
        stosw
597
        jmp     .write_remark
601
        jmp     .write_remark
598
@@:
602
@@:
599
        pop     di
603
        pop     di
600
        pop     si
604
        pop     si
601
        add     di, 80*2
605
        add     di, 80*2
602
        loop    .write_remarks
606
        loop    .write_remarks
603
.wait:
607
.wait:
604
        _setcursor 25,0         ; out of screen
608
        _setcursor 25,0         ; out of screen
605
; set timer interrupt handler
609
; set timer interrupt handler
606
        cli
610
        cli
607
        push    0
611
        push    0
608
        pop     es
612
        pop     es
609
        push    dword [es:8*4]
613
        push    dword [es:8*4]
610
        pop     dword [.oldtimer]
614
        pop     dword [.oldtimer]
611
        push    dword [.timer]
615
        push    dword [.timer]
612
        pop     dword [es:8*4]
616
        pop     dword [es:8*4]
613
;        mov     eax, [es:8*4]
617
;        mov     eax, [es:8*4]
614
;        mov     [.oldtimer], eax
618
;        mov     [.oldtimer], eax
615
;        mov     eax, [.timer]
619
;        mov     eax, [.timer]
616
;        mov     [es:8*4], eax
620
;        mov     [es:8*4], eax
617
        sti
621
        sti
618
; wait for keypressed
622
; wait for keypressed
619
        xor     ax, ax
623
        xor     ax, ax
620
        int     16h
624
        int     16h
621
        push    ax
625
        push    ax
622
; restore timer interrupt
626
; restore timer interrupt
623
;        push    0
627
;        push    0
624
;        pop     es
628
;        pop     es
625
        mov     eax, [.oldtimer]
629
        mov     eax, [.oldtimer]
626
        mov     [es:8*4], eax
630
        mov     [es:8*4], eax
627
        mov     [.timer], eax
631
        mov     [.timer], eax
628
 
632
 
629
        _setcursor 7,0
633
        _setcursor 7,0
630
        mov     si, space_msg
634
        mov     si, space_msg
631
        call    printplain
635
        call    printplain
632
; clear remarks and restore normal attributes
636
; clear remarks and restore normal attributes
633
        push    es
637
        push    es
634
        mov     di, ((21-num_remarks)*80 + 2)*2
638
        mov     di, ((21-num_remarks)*80 + 2)*2
635
        push    0xB800
639
        push    0xB800
636
        pop     es
640
        pop     es
637
        mov     cx, num_remarks
641
        mov     cx, num_remarks
638
        mov     ax, ' ' + (1*16 + 15)*100h
642
        mov     ax, ' ' + (1*16 + 15)*100h
639
@@:
643
@@:
640
        push    cx
644
        push    cx
641
        mov     cx, 76
645
        mov     cx, 76
642
        rep stosw
646
        rep stosw
643
        pop     cx
647
        pop     cx
644
        add     di, 4*2
648
        add     di, 4*2
645
        loop    @b
649
        loop    @b
646
        pop     es
650
        pop     es
647
        pop     ax
651
        pop     ax
648
; switch on key
652
; switch on key
649
        cmp     al, 13
653
        cmp     al, 13
650
        jz      .continue
654
        jz      .continue
651
        or      al, 20h
655
        or      al, 20h
652
        cmp     al, 'a'         ; select graphical mode
656
        cmp     al, 'a'         ; select graphical mode
653
        jz      .change_a
657
        jz      .change_a
654
        cmp     al, 'q'         ; Trick to make 'A' key on azerty keyboard work
658
        cmp     al, 'q'         ; Trick to make 'A' key on azerty keyboard work
655
        je      .change_a
659
        je      .change_a
656
        cmp     al, 'b'         ; use BIOS disks? // (selecting YES will make BIOS disks visible as /bd)
660
        cmp     al, 'b'         ; use BIOS disks? // (selecting YES will make BIOS disks visible as /bd)
657
        jz      .change_b
661
        jz      .change_b
658
        cmp     al, 'c'         ; load kernel in debug mode?
662
        cmp     al, 'c'         ; load kernel in debug mode?
659
        jz      .change_c
663
        jz      .change_c
660
        cmp     al, 'd'         ; start launcher after kernel is loaded?
664
        cmp     al, 'd'         ; start launcher after kernel is loaded?
661
        jz      .change_d
665
        jz      .change_d
662
        cmp     al, 'e'         ; select boot origin
666
        cmp     al, 'e'         ; select boot origin
663
        jnz     .show_remarks
667
        jnz     .show_remarks
664
; e) preboot_device = from where to boot?
668
; e) preboot_device = from where to boot?
665
if defined extended_primary_loader
669
if defined extended_primary_loader
666
        _ask_question bdev,'12',preboot_device              ; range accepted for answer: 1-2
670
        _ask_question bdev,'12',preboot_device              ; range accepted for answer: 1-2
667
else
671
else
668
        _ask_question bdev,'14',preboot_device              ; range accepted for answer: 1-4
672
        _ask_question bdev,'14',preboot_device              ; range accepted for answer: 1-4
669
end if
673
end if
670
        _setcursor 14,0
674
        _setcursor 14,0
671
 
675
 
672
.d:
676
.d:
673
if ~ defined extended_primary_loader
677
if ~ defined extended_primary_loader
674
        mov     [.bSettingsChanged], 1
678
        mov     [.bSettingsChanged], 1
675
end if
679
end if
676
.esc_pressed:
680
.esc_pressed:
677
        call    clear_vmodes_table             ;clear vmodes_table
681
        call    clear_vmodes_table             ;clear vmodes_table
678
        jmp     .printcfg
682
        jmp     .printcfg
679
 
683
 
680
.change_a:
684
.change_a:
681
        call    clear_vmodes_table             ;clear vmodes_table
685
        call    clear_vmodes_table             ;clear vmodes_table
682
 
686
 
683
        mov     si, word [cursor_pos]
687
        mov     si, word [cursor_pos]
684
        mov     word [cursor_pos_old], si
688
        mov     word [cursor_pos_old], si
685
.loops:
689
.loops:
686
        call    draw_vmodes_table
690
        call    draw_vmodes_table
687
        _setcursor 25,0         ; out of screen
691
        _setcursor 25,0         ; out of screen
688
        xor     ax, ax
692
        xor     ax, ax
689
        int     0x16
693
        int     0x16
690
;        call    clear_table_cursor             ;clear current position of cursor
694
;        call    clear_table_cursor             ;clear current position of cursor
691
 
695
 
692
        mov     si, word [cursor_pos]
696
        mov     si, word [cursor_pos]
693
 
697
 
694
        cmp     al, 27              ; If ESC was pressed, do not change the value
698
        cmp     al, 27              ; If ESC was pressed, do not change the value
695
        jnz     @f                   ; Just exit the resolution selection box
699
        jnz     @f                   ; Just exit the resolution selection box
696
 
700
 
697
        mov     si, word [cursor_pos_old]
701
        mov     si, word [cursor_pos_old]
698
        mov     word [cursor_pos], si
702
        mov     word [cursor_pos], si
699
        jmp     .esc_pressed
703
        jmp     .esc_pressed
700
@@:
704
@@:
701
        cmp     ah, 0x48;x,0x48E0               ; up
705
        cmp     ah, 0x48;x,0x48E0               ; up
702
        jne     .down
706
        jne     .down
703
        cmp     si, modes_table
707
        cmp     si, modes_table
704
        jbe     .loops
708
        jbe     .loops
705
        sub     word [cursor_pos], size_of_step
709
        sub     word [cursor_pos], size_of_step
706
        jmp     .loops
710
        jmp     .loops
707
 
711
 
708
.down:
712
.down:
709
        cmp     ah, 0x50;x,0x50E0               ; down
713
        cmp     ah, 0x50;x,0x50E0               ; down
710
        jne     .pgup
714
        jne     .pgup
711
        cmp     word[es:si+10], -1
715
        cmp     word[es:si+10], -1
712
        je      .loops
716
        je      .loops
713
        add     word [cursor_pos], size_of_step
717
        add     word [cursor_pos], size_of_step
714
        jmp     .loops
718
        jmp     .loops
715
 
719
 
716
.pgup:
720
.pgup:
717
        cmp     ah, 0x49                ; page up
721
        cmp     ah, 0x49                ; page up
718
        jne     .pgdn
722
        jne     .pgdn
719
        sub     si, size_of_step*long_v_table
723
        sub     si, size_of_step*long_v_table
720
        cmp     si, modes_table
724
        cmp     si, modes_table
721
        jae     @f
725
        jae     @f
722
        mov     si, modes_table
726
        mov     si, modes_table
723
@@:
727
@@:
724
        mov     word [cursor_pos], si
728
        mov     word [cursor_pos], si
725
        mov     si, word [home_cursor]
729
        mov     si, word [home_cursor]
726
        sub     si, size_of_step*long_v_table
730
        sub     si, size_of_step*long_v_table
727
        cmp     si, modes_table
731
        cmp     si, modes_table
728
        jae     @f
732
        jae     @f
729
        mov     si, modes_table
733
        mov     si, modes_table
730
@@:
734
@@:
731
        mov     word [home_cursor], si
735
        mov     word [home_cursor], si
732
        jmp     .loops
736
        jmp     .loops
733
 
737
 
734
.pgdn:
738
.pgdn:
735
        cmp     ah, 0x51                ; page down
739
        cmp     ah, 0x51                ; page down
736
        jne     .enter
740
        jne     .enter
737
        mov     ax, [end_cursor]
741
        mov     ax, [end_cursor]
738
        add     si, size_of_step*long_v_table
742
        add     si, size_of_step*long_v_table
739
        cmp     si, ax
743
        cmp     si, ax
740
        jb      @f
744
        jb      @f
741
        mov     si, ax
745
        mov     si, ax
742
        sub     si, size_of_step
746
        sub     si, size_of_step
743
@@:
747
@@:
744
        mov     word [cursor_pos], si
748
        mov     word [cursor_pos], si
745
        mov     si, word [home_cursor]
749
        mov     si, word [home_cursor]
746
        sub     ax, size_of_step*long_v_table
750
        sub     ax, size_of_step*long_v_table
747
        add     si, size_of_step*long_v_table
751
        add     si, size_of_step*long_v_table
748
        cmp     si, ax
752
        cmp     si, ax
749
        jb      @f
753
        jb      @f
750
        mov     si, ax
754
        mov     si, ax
751
@@:
755
@@:
752
        mov     word [home_cursor], si
756
        mov     word [home_cursor], si
753
        jmp     .loops
757
        jmp     .loops
754
 
758
 
755
.enter:
759
.enter:
756
        cmp     al, 0x0D;x,0x1C0D               ; enter
760
        cmp     al, 0x0D;x,0x1C0D               ; enter
757
        jne     .loops
761
        jne     .loops
758
        push    word [cursor_pos]
762
        push    word [cursor_pos]
759
        pop     bp
763
        pop     bp
760
        push    word [es:bp]
764
        push    word [es:bp]
761
        pop     word [x_save]
765
        pop     word [x_save]
762
        push    word [es:bp+2]
766
        push    word [es:bp+2]
763
        pop     word [y_save]
767
        pop     word [y_save]
764
        push    word [es:bp+6]
768
        push    word [es:bp+6]
765
        pop     word [number_vm]
769
        pop     word [number_vm]
766
        mov     word [preboot_graph], bp          ;save choose
770
        mov     word [preboot_graph], bp          ;save choose
767
        
771
        
768
        jmp     .d
772
        jmp     .d
769
 
773
 
770
.change_b:                      ; b) preboot_biosdisk  = use BIOS disks through V86 emulation?
774
.change_b:                      ; b) preboot_biosdisk  = use BIOS disks through V86 emulation?
771
;        _setcursor 16,0
775
;        _setcursor 16,0
772
;        mov     si, ask_dma    // (earlier was: preboot_dma  = use DMA access?)
776
;        mov     si, ask_dma    // (earlier was: preboot_dma  = use DMA access?)
773
;        call    print
777
;        call    print
774
;        mov     bx, '13'       ; range accepted for answer: 1-3
778
;        mov     bx, '13'       ; range accepted for answer: 1-3
775
;        call    getkey
779
;        call    getkey
776
;        mov     [preboot_dma], al
780
;        mov     [preboot_dma], al
777
        _ask_question ask_bd,'12',preboot_biosdisk              ; range accepted for answer: 1-2
781
        _ask_question ask_bd,'12',preboot_biosdisk              ; range accepted for answer: 1-2
778
        _setcursor 11,0
782
        _setcursor 11,0
779
        jmp     .d
783
        jmp     .d
780
.change_c:                      ; c) preboot_debug = duplicates kernel debug output to the screen
784
.change_c:                      ; c) preboot_debug = duplicates kernel debug output to the screen
781
        _ask_question ask_debug,'12',preboot_debug              ; range accepted for answer: 1-2
785
        _ask_question ask_debug,'12',preboot_debug              ; range accepted for answer: 1-2
782
        _setcursor 12,0
786
        _setcursor 12,0
783
        jmp     .d
787
        jmp     .d
784
.change_d:                      ; d) preboot_launcher = start the first app (right now it's LAUNCHER) after kernel is loaded?
788
.change_d:                      ; d) preboot_launcher = start the first app (right now it's LAUNCHER) after kernel is loaded?
785
        _ask_question ask_launcher,'12',preboot_launcher        ; range accepted for answer: 1-2
789
        _ask_question ask_launcher,'12',preboot_launcher        ; range accepted for answer: 1-2
786
        _setcursor 13,0
790
        _setcursor 13,0
787
        jmp     .d
791
        jmp     .d
788
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
792
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
789
.say_on_off:
793
.say_on_off:
790
        pushf
794
        pushf
791
        call    print
795
        call    print
792
        mov     si, on_msg
796
        mov     si, on_msg
793
        popf
797
        popf
794
        jz      @f
798
        jz      @f
795
        mov     si, off_msg
799
        mov     si, off_msg
796
@@:
800
@@:
797
        jmp     printplain
801
        jmp     printplain
798
; novesa and vervesa strings are not used at the moment of executing this code
802
; novesa and vervesa strings are not used at the moment of executing this code
799
virtual at novesa
803
virtual at novesa
800
.oldtimer dd ?
804
.oldtimer dd ?
801
.starttime dd ?
805
.starttime dd ?
802
if ~ defined extended_primary_loader
806
if ~ defined extended_primary_loader
803
.bSettingsChanged db ?
807
.bSettingsChanged db ?
804
end if
808
end if
805
.timer dd ?
809
.timer dd ?
806
end virtual
810
end virtual
807
if ~ defined extended_primary_loader
811
if ~ defined extended_primary_loader
808
.loader_block dd -1
812
.loader_block dd -1
809
end if
813
end if
810
.gettime:
814
.gettime:
811
        mov     ah, 0
815
        mov     ah, 0
812
        int     1Ah
816
        int     1Ah
813
        xchg    ax, cx
817
        xchg    ax, cx
814
        shl     eax, 10h
818
        shl     eax, 10h
815
        xchg    ax, dx
819
        xchg    ax, dx
816
        ret
820
        ret
817
.newtimer:
821
.newtimer:
818
        push    ds
822
        push    ds
819
        push    cs
823
        push    cs
820
        pop     ds
824
        pop     ds
821
        pushf
825
        pushf
822
        call    [.oldtimer]
826
        call    [.oldtimer]
823
        pushad
827
        pushad
824
        call    .gettime
828
        call    .gettime
825
        sub     eax, [.starttime]
829
        sub     eax, [.starttime]
826
if defined extended_primary_loader
830
if defined extended_primary_loader
827
        sub     ax, [preboot_timeout]
831
        sub     ax, [preboot_timeout]
828
else
832
else
829
        sub     ax, 18*5
833
        sub     ax, 18*5
830
end if
834
end if
831
        jae     .timergo
835
        jae     .timergo
832
        neg     ax
836
        neg     ax
833
        add     ax, 18-1
837
        add     ax, 18-1
834
        mov     bx, 18
838
        mov     bx, 18
835
        xor     dx, dx
839
        xor     dx, dx
836
        div     bx
840
        div     bx
837
if lang eq ru
841
if lang eq ru
838
; подождите 5 секунд, 4/3/2 секунды, 1 секунду
842
; подождите 5 секунд, 4/3/2 секунды, 1 секунду
839
        cmp     al, 5
843
        cmp     al, 5
840
        mov     cl, ' '
844
        mov     cl, ' '
841
        jae     @f
845
        jae     @f
842
        cmp     al, 1
846
        cmp     al, 1
843
        mov     cl, 0xE3 ; 'у' in cp866
847
        mov     cl, 0xE3 ; 'у' in cp866
844
        jz      @f
848
        jz      @f
845
        mov     cl, 0xEB ; 'ы' in cp866
849
        mov     cl, 0xEB ; 'ы' in cp866
846
@@:
850
@@:
847
        mov     [time_str+9], cl
851
        mov     [time_str+9], cl
848
else if lang eq et
852
else if lang eq et
849
        cmp     al, 1
853
        cmp     al, 1
850
        ja      @f
854
        ja      @f
851
        mov     byte [time_str+9], ' '
855
        mov     byte [time_str+9], ' '
852
        mov     byte [time_str+10], ' '
856
        mov     byte [time_str+10], ' '
853
@@:
857
@@:
854
else if lang eq sp
858
else if lang eq sp
855
; esperar 5/4/3/2 segundos, 1 segundo
859
; esperar 5/4/3/2 segundos, 1 segundo
856
        cmp     al, 1
860
        cmp     al, 1
857
        mov     cl, 's'
861
        mov     cl, 's'
858
        ja      @f
862
        ja      @f
859
        mov     cl, ' '
863
        mov     cl, ' '
860
@@:
864
@@:
861
        mov     [time_str+10], cl
865
        mov     [time_str+10], cl
862
else
866
else
863
; wait 5/4/3/2 seconds, 1 second
867
; wait 5/4/3/2 seconds, 1 second
864
        cmp     al, 1
868
        cmp     al, 1
865
        mov     cl, 's'
869
        mov     cl, 's'
866
        ja      @f
870
        ja      @f
867
        mov     cl, ' '
871
        mov     cl, ' '
868
@@:
872
@@:
869
        mov     [time_str+9], cl
873
        mov     [time_str+9], cl
870
end if
874
end if
871
        add     al, '0'
875
        add     al, '0'
872
        mov     [time_str+1], al
876
        mov     [time_str+1], al
873
        mov     si, time_msg
877
        mov     si, time_msg
874
        _setcursor 7,0
878
        _setcursor 7,0
875
        call    print
879
        call    print
876
        _setcursor 25,0
880
        _setcursor 25,0
877
        popad
881
        popad
878
        pop     ds
882
        pop     ds
879
        iret
883
        iret
880
.timergo:
884
.timergo:
881
        push    0
885
        push    0
882
        pop     es
886
        pop     es
883
        mov     eax, [.oldtimer]
887
        mov     eax, [.oldtimer]
884
        mov     [es:8*4], eax
888
        mov     [es:8*4], eax
885
        mov     sp, 0EC00h
889
        mov     sp, 0EC00h
886
.continue:
890
.continue:
887
        sti
891
        sti
888
        _setcursor 6,0
892
        _setcursor 6,0
889
        mov     si, space_msg
893
        mov     si, space_msg
890
        call    printplain
894
        call    printplain
891
        call    printplain
895
        call    printplain
892
        _setcursor 6,0
896
        _setcursor 6,0
893
        mov     si, loading_msg
897
        mov     si, loading_msg
894
        call    print
898
        call    print
895
        _setcursor 16,0
899
        _setcursor 16,0
896
if ~ defined extended_primary_loader
900
if ~ defined extended_primary_loader
897
        cmp     [.bSettingsChanged], 0
901
        cmp     [.bSettingsChanged], 0
898
        jz      .load
902
        jz      .load
899
        cmp     [.loader_block], -1
903
        cmp     [.loader_block], -1
900
        jz      .load
904
        jz      .load
901
        les     bx, [.loader_block]
905
        les     bx, [.loader_block]
902
        mov     eax, [es:bx+3]
906
        mov     eax, [es:bx+3]
903
        push    ds
907
        push    ds
904
        pop     es
908
        pop     es
905
        test    eax, eax
909
        test    eax, eax
906
        jz      .load
910
        jz      .load
907
        push    eax
911
        push    eax
908
        mov     si, save_quest
912
        mov     si, save_quest
909
        call    print
913
        call    print
910
.waityn:
914
.waityn:
911
        mov     ah, 0
915
        mov     ah, 0
912
        int     16h
916
        int     16h
913
        or      al, 20h
917
        or      al, 20h
914
        cmp     al, 'n'
918
        cmp     al, 'n'
915
        jz      .loadc
919
        jz      .loadc
916
        if lang eq sp
920
        if lang eq sp
917
        cmp     al, 's'
921
        cmp     al, 's'
918
        else
922
        else
919
        cmp     al, 'y'
923
        cmp     al, 'y'
920
        end if
924
        end if
921
        jnz     .waityn
925
        jnz     .waityn
922
        call    putchar
926
        call    putchar
923
        mov     byte [space_msg+80], 186
927
        mov     byte [space_msg+80], 186
924
 
928
 
925
        pop     eax
929
        pop     eax
926
        push    cs
930
        push    cs
927
        push    .cont
931
        push    .cont
928
        push    eax
932
        push    eax
929
        retf                          ;call back
933
        retf                          ;call back
930
.loadc:
934
.loadc:
931
        pop     eax
935
        pop     eax
932
.cont:
936
.cont:
933
        push    cs
937
        push    cs
934
        pop     ds
938
        pop     ds
935
        mov     si, space_msg
939
        mov     si, space_msg
936
        mov     byte [si+80], 0
940
        mov     byte [si+80], 0
937
        _setcursor 16,0
941
        _setcursor 16,0
938
        call    printplain
942
        call    printplain
939
        _setcursor 16,0
943
        _setcursor 16,0
940
.load:
944
.load:
941
end if
945
end if
942
; \end{diamond}[02.12.2005]
946
; \end{diamond}[02.12.2005]
943
 
947
 
944
; ASK GRAPHICS MODE
948
; ASK GRAPHICS MODE
945
 
949
 
946
        call    set_vmode
950
        call    set_vmode
947
 
951
 
948
; GRAPHICS ACCELERATION
952
; GRAPHICS ACCELERATION
949
; force yes
953
; force yes
950
        mov     [es:BOOT_MTRR], byte 1
954
        mov     [es:BOOT_MTRR], byte 1
951
 
955
 
952
; DMA ACCESS TO HD
956
; DMA ACCESS TO HD
953
 
957
 
954
        mov     al, [preboot_dma]
958
        mov     al, [preboot_dma]
955
        mov     [es:BOOT_DMA], al
959
        mov     [es:BOOT_DMA], al
956
 
960
 
957
; Set kernel DEBUG mode - if nonzero, duplicates debug output to the screen.
961
; Set kernel DEBUG mode - if nonzero, duplicates debug output to the screen.
958
        mov     al, [preboot_debug]
962
        mov     al, [preboot_debug]
959
        mov     [es:BOOT_DEBUG_PRINT], al       ;// 0x901E
963
        mov     [es:BOOT_DEBUG_PRINT], al       ;// 0x901E
960
 
964
 
961
; Start the first app (right now it's LAUNCHER) after kernel is loaded?
965
; Start the first app (right now it's LAUNCHER) after kernel is loaded?
962
        mov     al, [preboot_launcher]
966
        mov     al, [preboot_launcher]
963
        mov     [es:BOOT_LAUNCHER_START], al    ;// 0x901D        
967
        mov     [es:BOOT_LAUNCHER_START], al    ;// 0x901D        
964
 
968
 
965
; BOOT DEVICE
969
; BOOT DEVICE
966
 
970
 
967
        mov     al, [preboot_device]
971
        mov     al, [preboot_device]
968
        dec     al
972
        dec     al
969
        mov     [boot_dev], al
973
        mov     [es:BOOT_DEV], al
970
 
974
 
971
; GET MEMORY MAP
975
; GET MEMORY MAP
972
include '../detect/biosmem.inc'
976
include '../detect/biosmem.inc'
973
 
977
 
974
; READ DISKETTE TO MEMORY
978
; READ DISKETTE TO MEMORY
975
 
979
 
976
        cmp     [boot_dev], 0
980
        cmp     byte [es:BOOT_DEV], 0
977
        jne     no_sys_on_floppy
981
        jne     no_sys_on_floppy
978
        mov     si, diskload
982
        mov     si, diskload
979
        call    print
983
        call    print
980
        xor     ax, ax            ; reset drive
984
        xor     ax, ax            ; reset drive
981
        xor     dx, dx
985
        xor     dx, dx
982
        int     0x13
986
        int     0x13
983
; do we boot from CD-ROM?
987
; do we boot from CD-ROM?
984
        mov     ah, 41h
988
        mov     ah, 41h
985
        mov     bx, 55AAh
989
        mov     bx, 55AAh
986
        xor     dx, dx
990
        xor     dx, dx
987
        int     0x13
991
        int     0x13
988
        jc      .nocd
992
        jc      .nocd
989
        cmp     bx, 0AA55h
993
        cmp     bx, 0AA55h
990
        jnz     .nocd
994
        jnz     .nocd
991
        mov     ah, 48h
995
        mov     ah, 48h
992
        push    ds
996
        push    ds
993
        push    es
997
        push    es
994
        pop     ds
998
        pop     ds
995
        mov     si, 0xa000
999
        mov     si, 0xa000
996
        mov     word [si], 30
1000
        mov     word [si], 30
997
        int     0x13
1001
        int     0x13
998
        pop     ds
1002
        pop     ds
999
        jc      .nocd
1003
        jc      .nocd
1000
        push    ds
1004
        push    ds
1001
        lds     si, [es:si+26]
1005
        lds     si, [es:si+26]
1002
        test    byte [ds:si+10], 40h
1006
        test    byte [ds:si+10], 40h
1003
        pop     ds
1007
        pop     ds
1004
        jz      .nocd
1008
        jz      .nocd
1005
; yes - read all floppy by 18 sectors
1009
; yes - read all floppy by 18 sectors
1006
 
1010
 
1007
; TODO: !!!! read only first sector and set variables !!!!!
1011
; TODO: !!!! read only first sector and set variables !!!!!
1008
; ...
1012
; ...
1009
; TODO: !!! then read flippy image track by track
1013
; TODO: !!! then read flippy image track by track
1010
        
1014
        
1011
        mov     cx, 0x0001      ; startcyl,startsector
1015
        mov     cx, 0x0001      ; startcyl,startsector
1012
.a1:
1016
.a1:
1013
        push    cx dx
1017
        push    cx dx
1014
        mov     al, 18
1018
        mov     al, 18
1015
        mov     bx, 0xa000
1019
        mov     bx, 0xa000
1016
        call    boot_read_floppy
1020
        call    boot_read_floppy
1017
        mov     si, movedesc
1021
        mov     si, movedesc
1018
        push    es
1022
        push    es
1019
        push    ds
1023
        push    ds
1020
        pop     es
1024
        pop     es
1021
        mov     cx, 256*18
1025
        mov     cx, 256*18
1022
        mov     ah, 0x87
1026
        mov     ah, 0x87
1023
        int     0x15
1027
        int     0x15
1024
        pop     es
1028
        pop     es
1025
        pop     dx cx
1029
        pop     dx cx
1026
        test    ah, ah
1030
        test    ah, ah
1027
        jnz     sayerr_floppy
1031
        jnz     sayerr_floppy
1028
        add     dword [si+8*3+2], 512*18
1032
        add     dword [si+8*3+2], 512*18
1029
        inc     dh
1033
        inc     dh
1030
        cmp     dh, 2
1034
        cmp     dh, 2
1031
        jnz     .a1
1035
        jnz     .a1
1032
        mov     dh, 0
1036
        mov     dh, 0
1033
        inc     ch
1037
        inc     ch
1034
        cmp     ch, 80
1038
        cmp     ch, 80
1035
        jae     ok_sys_on_floppy
1039
        jae     ok_sys_on_floppy
1036
        pusha
1040
        pusha
1037
        mov     al, ch
1041
        mov     al, ch
1038
        shr     ch, 2
1042
        shr     ch, 2
1039
        add     al, ch
1043
        add     al, ch
1040
        aam
1044
        aam
1041
        xchg    al, ah
1045
        xchg    al, ah
1042
        add     ax, '00'
1046
        add     ax, '00'
1043
        mov     si, pros
1047
        mov     si, pros
1044
        mov     [si], ax
1048
        mov     [si], ax
1045
        call    printplain
1049
        call    printplain
1046
        popa
1050
        popa
1047
        jmp     .a1
1051
        jmp     .a1
1048
.nocd:
1052
.nocd:
1049
; no - read only used sectors from floppy
1053
; no - read only used sectors from floppy
1050
; now load floppy image to memory
1054
; now load floppy image to memory
1051
; at first load boot sector and first FAT table
1055
; at first load boot sector and first FAT table
1052
 
1056
 
1053
; read only first sector and fill variables
1057
; read only first sector and fill variables
1054
        mov     cx, 0x0001      ; first logical sector
1058
        mov     cx, 0x0001      ; first logical sector
1055
        xor     dx, dx          ; head = 0, drive = 0 (a:)
1059
        xor     dx, dx          ; head = 0, drive = 0 (a:)
1056
        mov     al, 1           ; read one sector
1060
        mov     al, 1           ; read one sector
1057
        mov     bx, 0xB000      ; es:bx -> data area
1061
        mov     bx, 0xB000      ; es:bx -> data area
1058
        call    boot_read_floppy
1062
        call    boot_read_floppy
1059
; fill the necessary parameters to work with a floppy
1063
; fill the necessary parameters to work with a floppy
1060
        mov     ax, word [es:bx+24]
1064
        mov     ax, word [es:bx+24]
1061
        mov     word [BPB_SecPerTrk], ax
1065
        mov     word [BPB_SecPerTrk], ax
1062
        mov     ax, word [es:bx+26]
1066
        mov     ax, word [es:bx+26]
1063
        mov     word [BPB_NumHeads], ax
1067
        mov     word [BPB_NumHeads], ax
1064
        mov     ax, word [es:bx+17]
1068
        mov     ax, word [es:bx+17]
1065
        mov     word [BPB_RootEntCnt], ax
1069
        mov     word [BPB_RootEntCnt], ax
1066
        mov     ax, word [es:bx+14]
1070
        mov     ax, word [es:bx+14]
1067
        mov     word [BPB_RsvdSecCnt], ax
1071
        mov     word [BPB_RsvdSecCnt], ax
1068
        mov     ax, word [es:bx+19]
1072
        mov     ax, word [es:bx+19]
1069
        mov     word [BPB_TotSec16], ax
1073
        mov     word [BPB_TotSec16], ax
1070
        mov     al, byte [es:bx+13]
1074
        mov     al, byte [es:bx+13]
1071
        mov     byte [BPB_SecPerClus], al
1075
        mov     byte [BPB_SecPerClus], al
1072
        mov     al, byte [es:bx+16]
1076
        mov     al, byte [es:bx+16]
1073
        mov     byte [BPB_NumFATs], al
1077
        mov     byte [BPB_NumFATs], al
1074
; 18.11.2008
1078
; 18.11.2008
1075
        mov     ax, word [es:bx+22]
1079
        mov     ax, word [es:bx+22]
1076
        mov     word [BPB_FATSz16], ax
1080
        mov     word [BPB_FATSz16], ax
1077
        mov     cx, word [es:bx+11]
1081
        mov     cx, word [es:bx+11]
1078
        mov     word [BPB_BytsPerSec], cx
1082
        mov     word [BPB_BytsPerSec], cx
1079
 
1083
 
1080
; count of clusters in FAT12 ((size_of_FAT*2)/3)
1084
; count of clusters in FAT12 ((size_of_FAT*2)/3)
1081
;        mov     ax, word [BPB_FATSz16]
1085
;        mov     ax, word [BPB_FATSz16]
1082
;        mov     cx, word [BPB_BytsPerSec]
1086
;        mov     cx, word [BPB_BytsPerSec]
1083
;end  18.11.2008
1087
;end  18.11.2008
1084
        xor     dx, dx
1088
        xor     dx, dx
1085
        mul     cx
1089
        mul     cx
1086
        shl     ax, 1
1090
        shl     ax, 1
1087
        mov     cx, 3
1091
        mov     cx, 3
1088
        div     cx              ; now ax - number of clusters in FAT12
1092
        div     cx              ; now ax - number of clusters in FAT12
1089
        mov     word [end_of_FAT], ax
1093
        mov     word [end_of_FAT], ax
1090
 
1094
 
1091
; load first FAT table
1095
; load first FAT table
1092
        mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
1096
        mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
1093
        xor     dx, dx          ; starthead,drive
1097
        xor     dx, dx          ; starthead,drive
1094
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
1098
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
1095
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
1099
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
1096
        call    boot_read_floppy
1100
        call    boot_read_floppy
1097
        mov     bx, 0xB000
1101
        mov     bx, 0xB000
1098
 
1102
 
1099
; and copy them to extended memory
1103
; and copy them to extended memory
1100
        mov     si, movedesc
1104
        mov     si, movedesc
1101
        mov     [si+8*2+3], bh          ; from
1105
        mov     [si+8*2+3], bh          ; from
1102
        
1106
        
1103
        mov     ax, word [BPB_BytsPerSec]
1107
        mov     ax, word [BPB_BytsPerSec]
1104
        shr     ax, 1                   ; words per sector
1108
        shr     ax, 1                   ; words per sector
1105
        mov     cx, word [BPB_RsvdSecCnt]
1109
        mov     cx, word [BPB_RsvdSecCnt]
1106
        add     cx, word [BPB_FATSz16]
1110
        add     cx, word [BPB_FATSz16]
1107
        mul     cx
1111
        mul     cx
1108
        push    ax                      ; save to stack count of words in boot+FAT
1112
        push    ax                      ; save to stack count of words in boot+FAT
1109
        xchg    ax, cx
1113
        xchg    ax, cx
1110
        
1114
        
1111
        push    es
1115
        push    es
1112
        push    ds
1116
        push    ds
1113
        pop     es
1117
        pop     es
1114
        mov     ah, 0x87
1118
        mov     ah, 0x87
1115
        int     0x15
1119
        int     0x15
1116
        pop     es
1120
        pop     es
1117
        test    ah, ah
1121
        test    ah, ah
1118
        jz      @f
1122
        jz      @f
1119
sayerr_floppy:
1123
sayerr_floppy:
1120
        mov     dx, 0x3f2
1124
        mov     dx, 0x3f2
1121
        mov     al, 0
1125
        mov     al, 0
1122
        out     dx, al
1126
        out     dx, al
1123
sayerr_memmove:
1127
sayerr_memmove:
1124
        mov     si, memmovefailed
1128
        mov     si, memmovefailed
1125
        jmp     sayerr_plain
1129
        jmp     sayerr_plain
1126
@@:
1130
@@:
1127
        pop     ax                      ; restore from stack count of words in boot+FAT
1131
        pop     ax                      ; restore from stack count of words in boot+FAT
1128
        shl     ax, 1                   ; make bytes count from count of words
1132
        shl     ax, 1                   ; make bytes count from count of words
1129
        and     eax, 0ffffh
1133
        and     eax, 0ffffh
1130
        add     dword [si+8*3+2], eax
1134
        add     dword [si+8*3+2], eax
1131
 
1135
 
1132
; copy first FAT to second copy
1136
; copy first FAT to second copy
1133
; TODO: BPB_NumFATs !!!!!
1137
; TODO: BPB_NumFATs !!!!!
1134
        add     bx, word [BPB_BytsPerSec]       ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
1138
        add     bx, word [BPB_BytsPerSec]       ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
1135
        mov     byte [si+8*2+3], bh     ; bx - begin of FAT
1139
        mov     byte [si+8*2+3], bh     ; bx - begin of FAT
1136
        
1140
        
1137
        mov     ax, word [BPB_BytsPerSec]
1141
        mov     ax, word [BPB_BytsPerSec]
1138
        shr     ax, 1                   ; words per sector
1142
        shr     ax, 1                   ; words per sector
1139
        mov     cx, word [BPB_FATSz16]
1143
        mov     cx, word [BPB_FATSz16]
1140
        mul     cx
1144
        mul     cx
1141
        mov     cx, ax                  ; cx - count of words in FAT
1145
        mov     cx, ax                  ; cx - count of words in FAT
1142
 
1146
 
1143
        push    es
1147
        push    es
1144
        push    ds
1148
        push    ds
1145
        pop     es
1149
        pop     es
1146
        mov     ah, 0x87
1150
        mov     ah, 0x87
1147
        int     0x15
1151
        int     0x15
1148
        pop     es
1152
        pop     es
1149
        test    ah, ah
1153
        test    ah, ah
1150
        jnz     sayerr_floppy
1154
        jnz     sayerr_floppy
1151
        
1155
        
1152
        mov     ax, cx
1156
        mov     ax, cx
1153
        shl     ax, 1
1157
        shl     ax, 1
1154
        and     eax, 0ffffh             ; ax - count of bytes in FAT
1158
        and     eax, 0ffffh             ; ax - count of bytes in FAT
1155
        add     dword [si+8*3+2], eax
1159
        add     dword [si+8*3+2], eax
1156
        
1160
        
1157
; reading RootDir
1161
; reading RootDir
1158
; TODO: BPB_NumFATs
1162
; TODO: BPB_NumFATs
1159
        add     bx, ax
1163
        add     bx, ax
1160
        add     bx, 100h
1164
        add     bx, 100h
1161
        and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
1165
        and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
1162
        push    bx
1166
        push    bx
1163
 
1167
 
1164
        mov     bx, word [BPB_BytsPerSec]
1168
        mov     bx, word [BPB_BytsPerSec]
1165
        shr     bx, 5                           ; divide bx by 32
1169
        shr     bx, 5                           ; divide bx by 32
1166
        mov     ax, word [BPB_RootEntCnt]
1170
        mov     ax, word [BPB_RootEntCnt]
1167
        xor     dx, dx
1171
        xor     dx, dx
1168
        div     bx
1172
        div     bx
1169
        push    ax                              ; ax - count of RootDir sectors
1173
        push    ax                              ; ax - count of RootDir sectors
1170
 
1174
 
1171
        mov     ax, word [BPB_FATSz16]
1175
        mov     ax, word [BPB_FATSz16]
1172
        xor     cx, cx
1176
        xor     cx, cx
1173
        mov     cl, byte [BPB_NumFATs]
1177
        mov     cl, byte [BPB_NumFATs]
1174
        mul     cx
1178
        mul     cx
1175
        add     ax, word [BPB_RsvdSecCnt]       ; ax - first sector of RootDir
1179
        add     ax, word [BPB_RsvdSecCnt]       ; ax - first sector of RootDir
1176
 
1180
 
1177
        mov     word [FirstDataSector], ax
1181
        mov     word [FirstDataSector], ax
1178
        pop     bx
1182
        pop     bx
1179
        push    bx
1183
        push    bx
1180
        add     word [FirstDataSector], bx      ; Begin of data region of floppy
1184
        add     word [FirstDataSector], bx      ; Begin of data region of floppy
1181
        
1185
        
1182
; read RootDir
1186
; read RootDir
1183
        call    conv_abs_to_THS
1187
        call    conv_abs_to_THS
1184
        pop     ax
1188
        pop     ax
1185
        pop     bx                              ; place in buffer to write
1189
        pop     bx                              ; place in buffer to write
1186
        push    ax
1190
        push    ax
1187
        call    boot_read_floppy                ; read RootDir into buffer
1191
        call    boot_read_floppy                ; read RootDir into buffer
1188
; copy RootDir
1192
; copy RootDir
1189
        mov     byte [si+8*2+3], bh             ; from buffer
1193
        mov     byte [si+8*2+3], bh             ; from buffer
1190
        pop     ax                              ; ax = count of RootDir sectors
1194
        pop     ax                              ; ax = count of RootDir sectors
1191
        mov     cx, word [BPB_BytsPerSec]
1195
        mov     cx, word [BPB_BytsPerSec]
1192
        mul     cx
1196
        mul     cx
1193
        shr     ax, 1
1197
        shr     ax, 1
1194
        mov     cx, ax                          ; count of words to copy
1198
        mov     cx, ax                          ; count of words to copy
1195
        push    es
1199
        push    es
1196
        push    ds
1200
        push    ds
1197
        pop     es
1201
        pop     es
1198
        mov     ah, 0x87
1202
        mov     ah, 0x87
1199
        int     0x15
1203
        int     0x15
1200
        pop     es
1204
        pop     es
1201
 
1205
 
1202
        mov     ax, cx
1206
        mov     ax, cx
1203
        shl     ax, 1
1207
        shl     ax, 1
1204
        and     eax, 0ffffh             ; ax - count of bytes in RootDir
1208
        and     eax, 0ffffh             ; ax - count of bytes in RootDir
1205
        add     dword [si+8*3+2], eax   ; add count of bytes copied
1209
        add     dword [si+8*3+2], eax   ; add count of bytes copied
1206
 
1210
 
1207
; Reading data clusters from floppy
1211
; Reading data clusters from floppy
1208
        mov     byte [si+8*2+3], bh
1212
        mov     byte [si+8*2+3], bh
1209
        push    bx
1213
        push    bx
1210
 
1214
 
1211
        mov     di, 2                   ; First data cluster
1215
        mov     di, 2                   ; First data cluster
1212
.read_loop:
1216
.read_loop:
1213
        mov     bx, di
1217
        mov     bx, di
1214
        shr     bx, 1                   ; bx+di = di*1.5
1218
        shr     bx, 1                   ; bx+di = di*1.5
1215
        jnc     .even
1219
        jnc     .even
1216
        test    word [es:bx+di+0xB200], 0xFFF0  ; TODO: may not be 0xB200 !!!
1220
        test    word [es:bx+di+0xB200], 0xFFF0  ; TODO: may not be 0xB200 !!!
1217
        jmp     @f
1221
        jmp     @f
1218
.even:
1222
.even:
1219
        test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
1223
        test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
1220
 
1224
 
1221
@@:
1225
@@:
1222
        jz      .skip
1226
        jz      .skip
1223
; read cluster di
1227
; read cluster di
1224
;.read:
1228
;.read:
1225
        ;conv cluster di to abs. sector ax
1229
        ;conv cluster di to abs. sector ax
1226
        ; ax = (N-2) * BPB_SecPerClus + FirstDataSector
1230
        ; ax = (N-2) * BPB_SecPerClus + FirstDataSector
1227
        mov     ax, di
1231
        mov     ax, di
1228
        sub     ax, 2
1232
        sub     ax, 2
1229
        xor     bx, bx
1233
        xor     bx, bx
1230
        mov     bl, byte [BPB_SecPerClus]
1234
        mov     bl, byte [BPB_SecPerClus]
1231
        mul     bx
1235
        mul     bx
1232
        add     ax, word [FirstDataSector]
1236
        add     ax, word [FirstDataSector]
1233
        call    conv_abs_to_THS
1237
        call    conv_abs_to_THS
1234
        pop     bx
1238
        pop     bx
1235
        push    bx
1239
        push    bx
1236
        mov     al, byte [BPB_SecPerClus]       ; number of sectors in cluster
1240
        mov     al, byte [BPB_SecPerClus]       ; number of sectors in cluster
1237
        call    boot_read_floppy
1241
        call    boot_read_floppy
1238
        push    es
1242
        push    es
1239
        push    ds
1243
        push    ds
1240
        pop     es
1244
        pop     es
1241
        pusha
1245
        pusha
1242
;
1246
;
1243
        mov     ax, word [BPB_BytsPerSec]
1247
        mov     ax, word [BPB_BytsPerSec]
1244
        xor     cx, cx
1248
        xor     cx, cx
1245
        mov     cl, byte [BPB_SecPerClus]
1249
        mov     cl, byte [BPB_SecPerClus]
1246
        mul     cx
1250
        mul     cx
1247
        shr     ax, 1                           ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
1251
        shr     ax, 1                           ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
1248
        mov     cx, ax                          ; number of words to copy (count words in cluster)
1252
        mov     cx, ax                          ; number of words to copy (count words in cluster)
1249
;
1253
;
1250
        mov     ah, 0x87
1254
        mov     ah, 0x87
1251
        int     0x15                            ; copy data
1255
        int     0x15                            ; copy data
1252
        test    ah, ah
1256
        test    ah, ah
1253
        popa
1257
        popa
1254
        pop     es
1258
        pop     es
1255
        jnz     sayerr_floppy
1259
        jnz     sayerr_floppy
1256
; skip cluster di
1260
; skip cluster di
1257
.skip:
1261
.skip:
1258
        mov     ax, word [BPB_BytsPerSec]
1262
        mov     ax, word [BPB_BytsPerSec]
1259
        xor     cx, cx
1263
        xor     cx, cx
1260
        mov     cl, byte [BPB_SecPerClus]
1264
        mov     cl, byte [BPB_SecPerClus]
1261
        mul     cx
1265
        mul     cx
1262
        and     eax, 0ffffh             ; ax - count of bytes in cluster
1266
        and     eax, 0ffffh             ; ax - count of bytes in cluster
1263
        add     dword [si+8*3+2], eax
1267
        add     dword [si+8*3+2], eax
1264
 
1268
 
1265
        mov     ax, word [end_of_FAT]   ; max cluster number
1269
        mov     ax, word [end_of_FAT]   ; max cluster number
1266
        pusha
1270
        pusha
1267
; draw percentage
1271
; draw percentage
1268
; total clusters: ax
1272
; total clusters: ax
1269
; read clusters: di
1273
; read clusters: di
1270
        xchg    ax, di
1274
        xchg    ax, di
1271
        mov     cx, 100
1275
        mov     cx, 100
1272
        mul     cx
1276
        mul     cx
1273
        div     di
1277
        div     di
1274
        aam
1278
        aam
1275
        xchg    al, ah
1279
        xchg    al, ah
1276
        add     ax, '00'
1280
        add     ax, '00'
1277
        mov     si, pros
1281
        mov     si, pros
1278
        cmp     [si], ax
1282
        cmp     [si], ax
1279
        jz      @f
1283
        jz      @f
1280
        mov     [si], ax
1284
        mov     [si], ax
1281
        call    printplain
1285
        call    printplain
1282
@@:
1286
@@:
1283
        popa
1287
        popa
1284
        inc     di
1288
        inc     di
1285
        cmp     di, word [end_of_FAT]   ; max number of cluster
1289
        cmp     di, word [end_of_FAT]   ; max number of cluster
1286
        jnz     .read_loop
1290
        jnz     .read_loop
1287
        pop     bx                      ; clear stack
1291
        pop     bx                      ; clear stack
1288
 
1292
 
1289
ok_sys_on_floppy:
1293
ok_sys_on_floppy:
1290
        mov     si, backspace2
1294
        mov     si, backspace2
1291
        call    printplain
1295
        call    printplain
1292
        mov     si, okt
1296
        mov     si, okt
1293
        call    printplain
1297
        call    printplain
1294
no_sys_on_floppy:
1298
no_sys_on_floppy:
1295
        xor     ax, ax          ; reset drive
1299
        xor     ax, ax          ; reset drive
1296
        xor     dx, dx
1300
        xor     dx, dx
1297
        int     0x13
1301
        int     0x13
1298
        mov     dx, 0x3f2       ; floppy motor off
1302
        mov     dx, 0x3f2       ; floppy motor off
1299
        mov     al, 0
1303
        mov     al, 0
1300
        out     dx, al
1304
        out     dx, al
1301
 
1305
 
1302
if defined extended_primary_loader
1306
if defined extended_primary_loader
1303
        cmp     [boot_dev], 1
1307
        cmp     [es:BOOT_DEV], 1
1304
        jne     no_sys_from_primary
1308
        jne     no_sys_from_primary
1305
; load kolibri.img using callback from primary loader
1309
; load kolibri.img using callback from primary loader
1306
        and     word [movedesc + 24 + 2], 0
1310
        and     word [movedesc + 24 + 2], 0
1307
        mov     byte [movedesc + 24 + 4], 10h
1311
        mov     byte [movedesc + 24 + 4], 10h
1308
; read in blocks of 64K until file is fully loaded
1312
; read in blocks of 64K until file is fully loaded
1309
        mov     ax, 1
1313
        mov     ax, 1
1310
.repeat:
1314
.repeat:
1311
        mov     di, image_file_struct
1315
        mov     di, image_file_struct
1312
        call    [bootcallback]
1316
        call    [bootcallback]
1313
        push    cs
1317
        push    cs
1314
        pop     ds
1318
        pop     ds
1315
        push    cs
1319
        push    cs
1316
        pop     es
1320
        pop     es
1317
        cmp     bx, 1
1321
        cmp     bx, 1
1318
        ja      sayerr_badsect
1322
        ja      sayerr_badsect
1319
        push    bx
1323
        push    bx
1320
        mov     si, movedesc
1324
        mov     si, movedesc
1321
        and     word [si + 16 + 2], 0
1325
        and     word [si + 16 + 2], 0
1322
        mov     byte [si + 16 + 4], 4
1326
        mov     byte [si + 16 + 4], 4
1323
        mov     ah, 87h
1327
        mov     ah, 87h
1324
        mov     cx, 8000h
1328
        mov     cx, 8000h
1325
        int     15h
1329
        int     15h
1326
        pop     bx
1330
        pop     bx
1327
        test    ah, ah
1331
        test    ah, ah
1328
        jnz     sayerr_memmove
1332
        jnz     sayerr_memmove
1329
        inc     byte [si + 24 + 4]
1333
        inc     byte [si + 24 + 4]
1330
        test    bx, bx
1334
        test    bx, bx
1331
        jz      no_sys_from_primary
1335
        jz      no_sys_from_primary
1332
        mov     ax, 2
1336
        mov     ax, 2
1333
        jmp     .repeat
1337
        jmp     .repeat
1334
no_sys_from_primary:
1338
no_sys_from_primary:
1335
end if
1339
end if
1336
 
1340
 
1337
; SET GRAPHICS
1341
; SET GRAPHICS
1338
 
1342
 
1339
        xor     ax, ax
1343
        xor     ax, ax
1340
        mov     es, ax
1344
        mov     es, ax
1341
 
1345
 
1342
        mov     ax, [es:BOOT_VESA_MODE]         ; vga & 320x200
1346
        mov     ax, [es:BOOT_VESA_MODE]         ; vga & 320x200
1343
        mov     bx, ax
1347
        mov     bx, ax
1344
        cmp     ax, 0x13
1348
        cmp     ax, 0x13
1345
        je      setgr
1349
        je      setgr
1346
        cmp     ax, 0x12
1350
        cmp     ax, 0x12
1347
        je      setgr
1351
        je      setgr
1348
        mov     ax, 0x4f02              ; Vesa
1352
        mov     ax, 0x4f02              ; Vesa
1349
setgr:
1353
setgr:
1350
        int     0x10
1354
        int     0x10
1351
        test    ah, ah
1355
        test    ah, ah
1352
        mov     si, fatalsel
1356
        mov     si, fatalsel
1353
        jnz     v_mode_error
1357
        jnz     v_mode_error
1354
; set mode 0x12 graphics registers:
1358
; set mode 0x12 graphics registers:
1355
        cmp     bx, 0x12
1359
        cmp     bx, 0x12
1356
        jne     gmok2
1360
        jne     gmok2
1357
 
1361
 
1358
        mov     al, 0x05
1362
        mov     al, 0x05
1359
        mov     dx, 0x03ce
1363
        mov     dx, 0x03ce
1360
        push    dx
1364
        push    dx
1361
        out     dx, al      ; select GDC mode register
1365
        out     dx, al      ; select GDC mode register
1362
        mov     al, 0x02
1366
        mov     al, 0x02
1363
        inc     dx
1367
        inc     dx
1364
        out     dx, al      ; set write mode 2
1368
        out     dx, al      ; set write mode 2
1365
 
1369
 
1366
        mov     al, 0x02
1370
        mov     al, 0x02
1367
        mov     dx, 0x03c4
1371
        mov     dx, 0x03c4
1368
        out     dx, al      ; select VGA sequencer map mask register
1372
        out     dx, al      ; select VGA sequencer map mask register
1369
        mov     al, 0x0f
1373
        mov     al, 0x0f
1370
        inc     dx
1374
        inc     dx
1371
        out     dx, al      ; set mask for all planes 0-3
1375
        out     dx, al      ; set mask for all planes 0-3
1372
 
1376
 
1373
        mov     al, 0x08
1377
        mov     al, 0x08
1374
        pop     dx
1378
        pop     dx
1375
        out     dx, al      ; select GDC bit mask register
1379
        out     dx, al      ; select GDC bit mask register
1376
                           ; for writes to 0x03cf
1380
                           ; for writes to 0x03cf
1377
gmok2:
1381
gmok2:
1378
        push    ds
1382
        push    ds
1379
        pop     es
1383
        pop     es