Subversion Repositories Kolibri OS

Rev

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

Rev 488 Rev 509
1
$Revision: 488 $
1
$Revision: 509 $
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                              ;;
3
;;                                                              ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
6
;; Distributed under terms of the GNU General Public License    ;;
6
;; Distributed under terms of the GNU General Public License    ;;
7
;;                                                              ;;
7
;;                                                              ;;
8
;;  BOOTCODE.INC                                                ;;
8
;;  BOOTCODE.INC                                                ;;
9
;;                                                              ;;
9
;;                                                              ;;
10
;;  KolibriOS 16-bit loader,                                    ;;
10
;;  KolibriOS 16-bit loader,                                    ;;
11
;;                        based on bootcode for MenuetOS        ;;
11
;;                        based on bootcode for MenuetOS        ;;
12
;;                                                              ;;
12
;;                                                              ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
 
14
 
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
    cmp    al, 0
45
    cmp    al, 0
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
        mov     si, badsect
94
        mov     si, badsect
95
sayerr_plain:
95
sayerr_plain:
96
        call    printplain
96
        call    printplain
97
        jmp     $
97
        jmp     $
98
@@:
98
@@:
99
        pop     si
99
        pop     si
100
        ret
100
        ret
101
 
101
 
102
;=========================================================================
102
;=========================================================================
103
;
103
;
104
;                           16 BIT CODE
104
;                           16 BIT CODE
105
;
105
;
106
;=========================================================================
106
;=========================================================================
107
 
107
 
108
 
108
 
109
start_of_code:
109
start_of_code:
110
    cld
110
    cld
111
; \begin{diamond}[02.12.2005]
111
; \begin{diamond}[02.12.2005]
112
    cmp    ax, 'KL'
112
    cmp    ax, 'KL'
113
    jnz    @f
113
    jnz    @f
114
    mov    word [cs:cfgmanager.loader_block], si
114
    mov    word [cs:cfgmanager.loader_block], si
115
    mov    word [cs:cfgmanager.loader_block+2], ds
115
    mov    word [cs:cfgmanager.loader_block+2], ds
116
@@:
116
@@:
117
; \end{diamond}[02.12.2005]
117
; \end{diamond}[02.12.2005]
118
 
118
 
119
    cmp    cx,'HA'						; ïî ðåãèñòðàì îïðåäåëÿåòñÿ çàãðóçêà ñ âèíòà
119
    cmp    cx,'HA'						; ïî ðåãèñòðàì îïðåäåëÿåòñÿ çàãðóçêà ñ âèíòà
120
    jnz    no_hd_load
120
    jnz    no_hd_load
121
    cmp    dx,'RD'
121
    cmp    dx,'RD'
122
    jnz    no_hd_load
122
    jnz    no_hd_load
123
    mov    word [bx_from_load], bx		; {SPraid}[13.03.2007]
123
    mov    word [cs:bx_from_load], bx		; {SPraid}[13.03.2007]
124
    jmp    load_next
-
 
125
no_hd_load:
124
no_hd_load:
126
    mov    word [bx_from_load], 'r1'	; if work with floppy
-
 
127
load_next:
-
 
128
 
125
 
129
; set up stack
126
; set up stack
130
    mov    ax, 3000h
127
    mov    ax, 3000h
131
    mov    ss, ax
128
    mov    ss, ax
132
    mov    sp, 0EC00h
129
    mov    sp, 0EC00h
133
; set up segment registers
130
; set up segment registers
134
    push    cs
131
    push    cs
135
    pop    ds
132
    pop    ds
136
    push    cs
133
    push    cs
137
    pop    es
134
    pop    es
138
 
135
 
139
; set videomode
136
; set videomode
140
    mov    ax, 3
137
    mov    ax, 3
141
        int  0x10
138
        int  0x10
142
 
139
 
143
if lang eq ru
140
if lang eq ru
144
 ; Load & set russian VGA font (RU.INC)
141
 ; Load & set russian VGA font (RU.INC)
145
        mov  bp, RU_FNT1         ; RU_FNT1 - First part
142
        mov  bp, RU_FNT1         ; RU_FNT1 - First part
146
          mov  bx,1000h            ; 768 bytes
143
          mov  bx,1000h            ; 768 bytes
147
          mov  cx,30h              ; 48 symbols
144
          mov  cx,30h              ; 48 symbols
148
          mov  dx,80h              ; 128 - position of first symbol
145
          mov  dx,80h              ; 128 - position of first symbol
149
        mov  ax,1100h
146
        mov  ax,1100h
150
          int  10h
147
          int  10h
151
 
148
 
152
        mov  bp,RU_FNT2          ; RU_FNT2 -Second part
149
        mov  bp,RU_FNT2          ; RU_FNT2 -Second part
153
        mov  bx,1000h            ; 512 bytes
150
        mov  bx,1000h            ; 512 bytes
154
        mov  cx,20h              ; 32 symbols
151
        mov  cx,20h              ; 32 symbols
155
        mov  dx,0E0h             ; 224 - position of first symbol
152
        mov  dx,0E0h             ; 224 - position of first symbol
156
        mov  ax,1100h
153
        mov  ax,1100h
157
          int  10h
154
          int  10h
158
 ; End set VGA russian font
155
 ; End set VGA russian font
159
else if lang eq et
156
else if lang eq et
160
        mov  bp,ET_FNT          ; ET_FNT1
157
        mov  bp,ET_FNT          ; ET_FNT1
161
        mov  bx,1000h           ;
158
        mov  bx,1000h           ;
162
        mov  cx,255             ; 256 symbols
159
        mov  cx,255             ; 256 symbols
163
        mov  dx,0h              ; 0 - position of first symbol
160
        mov  dx,0h              ; 0 - position of first symbol
164
        mov  ax,1100h
161
        mov  ax,1100h
165
        int  10h
162
        int  10h
166
end if
163
end if
167
 
164
 
168
; draw frames
165
; draw frames
169
    push    0xb800
166
    push    0xb800
170
    pop    es
167
    pop    es
171
    xor    di, di
168
    xor    di, di
172
    mov    ah, 1*16+15
169
    mov    ah, 1*16+15
173
 
170
 
174
; draw top
171
; draw top
175
    mov    si, d80x25_top
172
    mov    si, d80x25_top
176
    mov    cx, d80x25_top_num * 80
173
    mov    cx, d80x25_top_num * 80
177
@@:
174
@@:
178
    lodsb
175
    lodsb
179
    stosw
176
    stosw
180
    loop    @b
177
    loop    @b
181
; draw spaces
178
; draw spaces
182
    mov    si, space_msg
179
    mov    si, space_msg
183
    mov    cx, 25 - d80x25_top_num - d80x25_bottom_num
180
    mov    cx, 25 - d80x25_top_num - d80x25_bottom_num
184
dfl1:
181
dfl1:
185
    push    cx
182
    push    cx
186
    push    si
183
    push    si
187
    mov    cx, 80
184
    mov    cx, 80
188
@@:
185
@@:
189
    lodsb
186
    lodsb
190
    stosw
187
    stosw
191
    loop    @b
188
    loop    @b
192
    pop    si
189
    pop    si
193
    pop    cx
190
    pop    cx
194
    loop    dfl1
191
    loop    dfl1
195
; draw bottom
192
; draw bottom
196
    mov    si, d80x25_bottom
193
    mov    si, d80x25_bottom
197
    mov    cx, d80x25_bottom_num * 80
194
    mov    cx, d80x25_bottom_num * 80
198
@@:
195
@@:
199
    lodsb
196
    lodsb
200
    stosw
197
    stosw
201
    loop    @b
198
    loop    @b
202
 
199
 
203
    mov    byte [space_msg+80], 0    ; now space_msg is null terminated
200
    mov    byte [space_msg+80], 0    ; now space_msg is null terminated
204
 
201
 
205
    _setcursor d80x25_top_num,0
202
    _setcursor d80x25_top_num,0
206
 
203
 
207
 
204
 
208
; TEST FOR 386+
205
; TEST FOR 386+
209
 
206
 
210
    mov    bx, 0x4000
207
    mov    bx, 0x4000
211
        pushf
208
        pushf
212
        pop     ax
209
        pop     ax
213
        mov     dx,ax
210
        mov     dx,ax
214
        xor     ax,bx
211
        xor     ax,bx
215
        push    ax
212
        push    ax
216
        popf
213
        popf
217
        pushf
214
        pushf
218
        pop     ax
215
        pop     ax
219
        and     ax,bx
216
        and     ax,bx
220
        and     dx,bx
217
        and     dx,bx
221
        cmp     ax,dx
218
        cmp     ax,dx
222
        jnz     cpugood
219
        jnz     cpugood
223
        mov     si,not386
220
        mov     si,not386
224
sayerr:
221
sayerr:
225
        call    print
222
        call    print
226
        jmp     $
223
        jmp     $
227
     cpugood:
224
     cpugood:
228
 
225
 
229
        push 0
226
        push 0
230
        popf
227
        popf
231
        sti
228
        sti
232
 
229
 
233
; set up esp
230
; set up esp
234
    movzx    esp, sp
231
    movzx    esp, sp
235
 
232
 
236
        push    0
233
        push    0
237
        pop     es
234
        pop     es
238
        and     word [es:0x9031], 0
235
        and     word [es:0x9031], 0
239
; \begin{Mario79}
236
; \begin{Mario79}
240
; find HDD IDE DMA PCI device
237
; find HDD IDE DMA PCI device
241
; check for PCI BIOS
238
; check for PCI BIOS
242
        mov     ax, 0xB101
239
        mov     ax, 0xB101
243
        int     0x1A
240
        int     0x1A
244
        jc      .nopci
241
        jc      .nopci
245
        cmp     edx, 'PCI '
242
        cmp     edx, 'PCI '
246
        jnz     .nopci
243
        jnz     .nopci
247
; find PCI class code
244
; find PCI class code
248
; class 1 = mass storage
245
; class 1 = mass storage
249
; subclass 1 = IDE controller
246
; subclass 1 = IDE controller
250
; a) class 1, subclass 1, programming interface 0x80
247
; a) class 1, subclass 1, programming interface 0x80
251
        mov     ax, 0xB103
248
        mov     ax, 0xB103
252
        mov     ecx, 1*10000h + 1*100h + 0x80
249
        mov     ecx, 1*10000h + 1*100h + 0x80
253
        mov     si, 0   ; device index = 0
250
        mov     si, 0   ; device index = 0
254
        int     0x1A
251
        int     0x1A
255
        jnc     .found
252
        jnc     .found
256
; b) class 1, subclass 1, programming interface 0x8A
253
; b) class 1, subclass 1, programming interface 0x8A
257
        mov     ax, 0xB103
254
        mov     ax, 0xB103
258
        mov     ecx, 1*10000h + 1*100h + 0x8A
255
        mov     ecx, 1*10000h + 1*100h + 0x8A
259
        mov     si, 0   ; device index = 0
256
        mov     si, 0   ; device index = 0
260
        int     0x1A
257
        int     0x1A
261
        jnc     .found
258
        jnc     .found
262
; c) class 1, subclass 1, programming interface 0x85
259
; c) class 1, subclass 1, programming interface 0x85
263
        mov     ax, 0xB103
260
        mov     ax, 0xB103
264
        mov     ecx, 1*10000h + 1*100h + 0x85
261
        mov     ecx, 1*10000h + 1*100h + 0x85
265
        mov     si, 0
262
        mov     si, 0
266
        int     0x1A
263
        int     0x1A
267
        jc      .nopci
264
        jc      .nopci
268
.found:
265
.found:
269
; get memory base
266
; get memory base
270
        mov     ax, 0xB10A
267
        mov     ax, 0xB10A
271
        mov     di, 0x20        ; memory base is config register at 0x20
268
        mov     di, 0x20        ; memory base is config register at 0x20
272
        int     0x1A
269
        int     0x1A
273
        jc      .nopci
270
        jc      .nopci
274
        and     cx, 0xFFF0      ; clear address decode type
271
        and     cx, 0xFFF0      ; clear address decode type
275
        mov     [es:0x9031], cx
272
        mov     [es:0x9031], cx
276
.nopci:
273
.nopci:
277
; \end{Mario79}
274
; \end{Mario79}
278
 
275
 
279
    mov   al,0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
276
    mov   al,0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
280
    out   0x60,al
277
    out   0x60,al
281
    xor   cx,cx
278
    xor   cx,cx
282
wait_loop:       ; variant 2
279
wait_loop:       ; variant 2
283
; reading state of port of 8042 controller
280
; reading state of port of 8042 controller
284
        in      al,64h
281
        in      al,64h
285
        and     al,00000010b  ; ready flag
282
        and     al,00000010b  ; ready flag
286
; wait until 8042 controller is ready
283
; wait until 8042 controller is ready
287
        loopnz  wait_loop
284
        loopnz  wait_loop
288
 
285
 
289
; --------------- APM ---------------------
286
; --------------- APM ---------------------
290
    push    0
287
    push    0
291
    pop    es
288
    pop    es
292
    mov    word [es : 0x9044], 0        ; ver = 0.0 (APM not found)
289
    mov    word [es : 0x9044], 0        ; ver = 0.0 (APM not found)
293
    mov    ax, 0x5300
290
    mov    ax, 0x5300
294
    xor    bx, bx
291
    xor    bx, bx
295
    int    0x15
292
    int    0x15
296
    jc    apm_end                ; APM not found
293
    jc    apm_end                ; APM not found
297
    test    cx, 2
294
    test    cx, 2
298
    jz    apm_end                ; APM 32-bit protected-mode interface not supported
295
    jz    apm_end                ; APM 32-bit protected-mode interface not supported
299
    mov    [es : 0x9044], ax        ; Save APM Version
296
    mov    [es : 0x9044], ax        ; Save APM Version
300
    mov    [es : 0x9046], cx        ; Save APM flags
297
    mov    [es : 0x9046], cx        ; Save APM flags
301
 
298
 
302
    ; Write APM ver ----
299
    ; Write APM ver ----
303
    and    ax, 0xf0f
300
    and    ax, 0xf0f
304
    add    ax, '00'
301
    add    ax, '00'
305
    mov    si, msg_apm
302
    mov    si, msg_apm
306
    mov    [si + 5], ah
303
    mov    [si + 5], ah
307
    mov    [si + 7], al
304
    mov    [si + 7], al
308
    _setcursor 0, 3
305
    _setcursor 0, 3
309
    call    printplain
306
    call    printplain
310
    ; ------------------
307
    ; ------------------
311
 
308
 
312
    mov    ax, 0x5304            ; Disconnect interface
309
    mov    ax, 0x5304            ; Disconnect interface
313
    xor    bx, bx
310
    xor    bx, bx
314
    int    0x15
311
    int    0x15
315
    mov    ax, 0x5303            ; Connect 32 bit mode interface
312
    mov    ax, 0x5303            ; Connect 32 bit mode interface
316
    xor    bx, bx
313
    xor    bx, bx
317
    int    0x15
314
    int    0x15
318
 
315
 
319
    push 0
316
    push 0
320
    pop es
317
    pop es
321
 
318
 
322
    mov [es:0x9040], ebx
319
    mov [es:0x9040], ebx
323
    mov [es:0x9050], ax
320
    mov [es:0x9050], ax
324
    mov [es:0x9052], cx
321
    mov [es:0x9052], cx
325
    mov [es:0x9054], dx
322
    mov [es:0x9054], dx
326
 
323
 
327
apm_end:
324
apm_end:
328
        _setcursor d80x25_top_num, 0
325
        _setcursor d80x25_top_num, 0
329
 
326
 
330
; DISPLAY VESA INFORMATION
327
; DISPLAY VESA INFORMATION
331
 
328
 
332
    push    0
329
    push    0
333
    pop    es
330
    pop    es
334
        mov     ax,0x4f00
331
        mov     ax,0x4f00
335
        mov     di,0xa000
332
        mov     di,0xa000
336
        int     0x10
333
        int     0x10
337
        cmp     ax,0x004f
334
        cmp     ax,0x004f
338
        mov    si, novesa
335
        mov    si, novesa
339
        jnz    @f
336
        jnz    @f
340
        mov bx, word [es:di+0x12]
337
        mov bx, word [es:di+0x12]
341
        shl ebx,16
338
        shl ebx,16
342
        mov [es:0x9050], ebx
339
        mov [es:0x9050], ebx
343
        mov     ax,[es:di+4]
340
        mov     ax,[es:di+4]
344
        add     ax,'0'*256+'0'
341
        add     ax,'0'*256+'0'
345
        mov    si,vervesa
342
        mov    si,vervesa
346
        mov     [si+vervesa_off], ah
343
        mov     [si+vervesa_off], ah
347
        mov     [si+vervesa_off+2], al
344
        mov     [si+vervesa_off+2], al
348
@@:     call    print
345
@@:     call    print
349
 
346
 
350
; \begin{diamond}[30.11.2005]
347
; \begin{diamond}[30.11.2005]
351
cfgmanager:
348
cfgmanager:
352
; settings:
349
; settings:
353
; a) preboot_graph = graphical mode
350
; a) preboot_graph = graphical mode
354
;    preboot_gprobe = probe this mode?
351
;    preboot_gprobe = probe this mode?
355
; b) preboot_dma_write  = use DMA write?
352
; b) preboot_dma_write  = use DMA write?
356
; c) preboot_vrrm = use VRR?
353
; c) preboot_vrrm = use VRR?
357
; d) preboot_device = from what boot?
354
; d) preboot_device = from what boot?
358
    mov    di, preboot_graph
355
    mov    di, preboot_graph
359
; check bootloader block
356
; check bootloader block
360
    cmp    [.loader_block], -1
357
    cmp    [.loader_block], -1
361
    jz    .noloaderblock
358
    jz    .noloaderblock
362
    les    bx, [.loader_block]
359
    les    bx, [.loader_block]
363
    cmp    byte [es:bx], 1
360
    cmp    byte [es:bx], 1
364
    mov    si, loader_block_error
361
    mov    si, loader_block_error
365
    jnz    sayerr
362
    jnz    sayerr
366
    test    byte [es:bx+1], 1
363
    test    byte [es:bx+1], 1
367
    jz    @f
364
    jz    @f
368
; image in memory present
365
; image in memory present
369
    cmp    [di+preboot_device-preboot_graph], 0
366
    cmp    [di+preboot_device-preboot_graph], 0
370
    jnz    @f
367
    jnz    @f
371
    mov    [di+preboot_device-preboot_graph], 3
368
    mov    [di+preboot_device-preboot_graph], 3
372
@@:
369
@@:
373
.noloaderblock:
370
.noloaderblock:
374
; determine default settings
371
; determine default settings
375
    mov    [.bSettingsChanged], 0
372
    mov    [.bSettingsChanged], 0
376
    cmp    byte [di], 0
373
    cmp    byte [di], 0
377
    jnz    .preboot_gr_end
374
    jnz    .preboot_gr_end
378
    mov    [di+preboot_gprobe-preboot_graph], 0
375
    mov    [di+preboot_gprobe-preboot_graph], 0
379
    mov    al, [vervesa+vervesa_off]
376
    mov    al, [vervesa+vervesa_off]
380
    cmp    al, 'x'
377
    cmp    al, 'x'
381
    jz    .novesa
378
    jz    .novesa
382
    cmp    al, '1'
379
    cmp    al, '1'
383
    jz    .vesa12
380
    jz    .vesa12
384
    mov    [di+preboot_gprobe-preboot_graph], 2
381
    mov    [di+preboot_gprobe-preboot_graph], 2
385
    mov    al, 3
382
    mov    al, 3
386
    jmp    @f
383
    jmp    @f
387
.vesa12:
384
.vesa12:
388
    mov    al, 7
385
    mov    al, 7
389
    jmp    @f
386
    jmp    @f
390
.novesa:
387
.novesa:
391
    mov    al, 10
388
    mov    al, 10
392
@@:
389
@@:
393
    mov    [di], al
390
    mov    [di], al
394
.preboot_gr_end:
391
.preboot_gr_end:
395
    cmp    [di+preboot_dma_write-preboot_graph], 1
392
    cmp    [di+preboot_dma_write-preboot_graph], 1
396
    adc    [di+preboot_dma_write-preboot_graph], 0
393
    adc    [di+preboot_dma_write-preboot_graph], 0
397
    cmp    [di+preboot_vrrm-preboot_graph], 1
394
    cmp    [di+preboot_vrrm-preboot_graph], 1
398
    adc    [di+preboot_vrrm-preboot_graph], 0
395
    adc    [di+preboot_vrrm-preboot_graph], 0
399
    cmp    [di+preboot_device-preboot_graph], 1
396
    cmp    [di+preboot_device-preboot_graph], 1
400
    adc    [di+preboot_device-preboot_graph], 0
397
    adc    [di+preboot_device-preboot_graph], 0
401
; notify user
398
; notify user
402
    mov    si, linef
399
    mov    si, linef
403
    call    print
400
    call    print
404
    mov    si, start_msg
401
    mov    si, start_msg
405
    call    print
402
    call    print
406
    mov    si, time_msg
403
    mov    si, time_msg
407
    call    print
404
    call    print
408
; get start time
405
; get start time
409
    call    .gettime
406
    call    .gettime
410
    mov    [.starttime], eax
407
    mov    [.starttime], eax
411
    mov    word [.timer], .newtimer
408
    mov    word [.timer], .newtimer
412
    mov    word [.timer+2], cs
409
    mov    word [.timer+2], cs
413
.printcfg:
410
.printcfg:
414
    _setcursor 9,0
411
    _setcursor 9,0
415
    mov    si, current_cfg_msg
412
    mov    si, current_cfg_msg
416
    call    print
413
    call    print
417
    mov    si, curvideo_msg
414
    mov    si, curvideo_msg
418
    call    print
415
    call    print
419
    mov    al, [preboot_graph]
416
    mov    al, [preboot_graph]
420
    cmp    al, 8
417
    cmp    al, 8
421
    ja    .pnovesa
418
    ja    .pnovesa
422
    mov    dl, al
419
    mov    dl, al
423
    and    eax, 3
420
    and    eax, 3
424
    mov    si, [modes_msg+eax*2]
421
    mov    si, [modes_msg+eax*2]
425
    call    printplain
422
    call    printplain
426
    mov    si, modevesa20
423
    mov    si, modevesa20
427
    cmp    dl, 4
424
    cmp    dl, 4
428
    jbe    @f
425
    jbe    @f
429
    mov    si, modevesa12
426
    mov    si, modevesa12
430
@@:
427
@@:
431
    call    printplain
428
    call    printplain
432
    cmp    dl, 4
429
    cmp    dl, 4
433
    ja    .x
430
    ja    .x
434
    mov    si, probeno_msg
431
    mov    si, probeno_msg
435
    cmp    [preboot_gprobe], 2
432
    cmp    [preboot_gprobe], 2
436
    jnz    @f
433
    jnz    @f
437
    mov    si, probeok_msg
434
    mov    si, probeok_msg
438
@@:
435
@@:
439
    call    printplain
436
    call    printplain
440
.x:
437
.x:
441
    jmp    .c
438
    jmp    .c
442
.pnovesa:
439
.pnovesa:
443
    cmp    al, 9
440
    cmp    al, 9
444
    mov    si, mode9
441
    mov    si, mode9
445
    jz    @b
442
    jz    @b
446
    mov    si, mode10
443
    mov    si, mode10
447
    jmp    @b
444
    jmp    @b
448
.c:
445
.c:
449
    mov    si, linef
446
    mov    si, linef
450
    call    printplain
447
    call    printplain
451
    mov    si, dma_msg
448
    mov    si, dma_msg
452
    cmp    [preboot_dma_write], 1
449
    cmp    [preboot_dma_write], 1
453
    call    .say_on_off
450
    call    .say_on_off
454
    mov    si, vrrm_msg
451
    mov    si, vrrm_msg
455
    cmp    [preboot_vrrm], 1
452
    cmp    [preboot_vrrm], 1
456
    call    .say_on_off
453
    call    .say_on_off
457
    mov    si, preboot_device_msg
454
    mov    si, preboot_device_msg
458
    call    print
455
    call    print
459
    mov    al, [preboot_device]
456
    mov    al, [preboot_device]
460
    and    eax, 3
457
    and    eax, 3
461
    mov    si, [preboot_device_msgs+eax*2]
458
    mov    si, [preboot_device_msgs+eax*2]
462
    call    printplain
459
    call    printplain
463
.wait:
460
.wait:
464
    _setcursor 25,0        ; out of screen
461
    _setcursor 25,0        ; out of screen
465
; set timer interrupt handler
462
; set timer interrupt handler
466
    cli
463
    cli
467
    push    0
464
    push    0
468
    pop    es
465
    pop    es
469
    mov    eax, [es:8*4]
466
    mov    eax, [es:8*4]
470
    mov    [.oldtimer], eax
467
    mov    [.oldtimer], eax
471
    mov    eax, [.timer]
468
    mov    eax, [.timer]
472
    mov    [es:8*4], eax
469
    mov    [es:8*4], eax
473
    sti
470
    sti
474
; wait for keypressed
471
; wait for keypressed
475
    mov    ah, 0
472
    mov    ah, 0
476
    int    16h
473
    int    16h
477
    push    ax
474
    push    ax
478
; restore timer interrupt
475
; restore timer interrupt
479
    push    0
476
    push    0
480
    pop    es
477
    pop    es
481
    mov    eax, [.oldtimer]
478
    mov    eax, [.oldtimer]
482
    mov    [es:8*4], eax
479
    mov    [es:8*4], eax
483
    mov    [.timer], eax
480
    mov    [.timer], eax
484
    _setcursor 7,0
481
    _setcursor 7,0
485
    mov    si, space_msg
482
    mov    si, space_msg
486
    call    printplain
483
    call    printplain
487
    pop    ax
484
    pop    ax
488
; switch on key
485
; switch on key
489
    cmp    al, 13
486
    cmp    al, 13
490
    jz    .continue
487
    jz    .continue
491
    or    al, 20h
488
    or    al, 20h
492
    cmp    al, 'a'
489
    cmp    al, 'a'
493
    jz    .change_a
490
    jz    .change_a
494
    cmp    al, 'b'
491
    cmp    al, 'b'
495
    jz    .change_b
492
    jz    .change_b
496
    cmp    al, 'c'
493
    cmp    al, 'c'
497
    jz    .change_c
494
    jz    .change_c
498
    cmp    al, 'd'
495
    cmp    al, 'd'
499
    jnz    .wait
496
    jnz    .wait
500
    _setcursor 15,0
497
    _setcursor 15,0
501
    mov     si,bdev
498
    mov     si,bdev
502
    call    print
499
    call    print
503
    mov     bx,'13'
500
    mov     bx,'13'
504
    call    getkey
501
    call    getkey
505
    mov    [preboot_device], al
502
    mov    [preboot_device], al
506
    _setcursor 13,0
503
    _setcursor 13,0
507
.d:
504
.d:
508
    mov    [.bSettingsChanged], 1
505
    mov    [.bSettingsChanged], 1
509
    mov    si, space_msg
506
    mov    si, space_msg
510
    call    printplain
507
    call    printplain
511
    _setcursor 15,0
508
    _setcursor 15,0
512
    mov    cx, 6
509
    mov    cx, 6
513
@@:
510
@@:
514
    call    printplain
511
    call    printplain
515
    loop    @b
512
    loop    @b
516
    jmp    .printcfg
513
    jmp    .printcfg
517
.change_a:
514
.change_a:
518
    _setcursor 15,0
515
    _setcursor 15,0
519
    mov    si, gr_mode
516
    mov    si, gr_mode
520
    call    printplain
517
    call    printplain
521
    mov     bx, '09'
518
    mov     bx, '09'
522
    call    getkey
519
    call    getkey
523
    mov    [preboot_graph], al
520
    mov    [preboot_graph], al
524
    cmp    al, 4
521
    cmp    al, 4
525
    ja    @f
522
    ja    @f
526
    mov    si, probetext
523
    mov    si, probetext
527
    call    printplain
524
    call    printplain
528
    mov    bx, '12'
525
    mov    bx, '12'
529
    call    getkey
526
    call    getkey
530
    mov    [preboot_gprobe], al
527
    mov    [preboot_gprobe], al
531
@@:
528
@@:
532
    _setcursor 10,0
529
    _setcursor 10,0
533
    jmp    .d
530
    jmp    .d
534
.change_b:
531
.change_b:
535
    _setcursor 15,0
532
    _setcursor 15,0
536
    mov    si, ask_dma
533
    mov    si, ask_dma
537
    call    print
534
    call    print
538
    mov    bx, '12'
535
    mov    bx, '12'
539
    call    getkey
536
    call    getkey
540
    mov    [preboot_dma_write], al
537
    mov    [preboot_dma_write], al
541
    _setcursor 11,0
538
    _setcursor 11,0
542
    jmp    .d
539
    jmp    .d
543
.change_c:
540
.change_c:
544
    _setcursor 15,0
541
    _setcursor 15,0
545
    mov    si, vrrmprint
542
    mov    si, vrrmprint
546
    call    print
543
    call    print
547
    mov    bx, '12'
544
    mov    bx, '12'
548
    call    getkey
545
    call    getkey
549
    mov    [preboot_vrrm], al
546
    mov    [preboot_vrrm], al
550
    _setcursor 12,0
547
    _setcursor 12,0
551
    jmp    .d
548
    jmp    .d
552
.say_on_off:
549
.say_on_off:
553
    pushf
550
    pushf
554
    call    print
551
    call    print
555
    mov    si, on_msg
552
    mov    si, on_msg
556
    popf
553
    popf
557
    jz    @f
554
    jz    @f
558
    mov    si, off_msg
555
    mov    si, off_msg
559
@@:    call    printplain
556
@@:    call    printplain
560
    ret
557
    ret
561
; novesa and vervesa strings are not used at the moment of executing this code
558
; novesa and vervesa strings are not used at the moment of executing this code
562
virtual at novesa
559
virtual at novesa
563
.oldtimer dd ?
560
.oldtimer dd ?
564
.starttime dd ?
561
.starttime dd ?
565
.bSettingsChanged db ?
562
.bSettingsChanged db ?
566
.timer dd ?
563
.timer dd ?
567
end virtual
564
end virtual
568
.loader_block dd -1
565
.loader_block dd -1
569
.gettime:
566
.gettime:
570
    mov    ah, 0
567
    mov    ah, 0
571
    int    1Ah
568
    int    1Ah
572
    xchg    ax, cx
569
    xchg    ax, cx
573
    shl    eax, 10h
570
    shl    eax, 10h
574
    xchg    ax, dx
571
    xchg    ax, dx
575
    ret
572
    ret
576
.newtimer:
573
.newtimer:
577
    push    ds
574
    push    ds
578
    push    cs
575
    push    cs
579
    pop    ds
576
    pop    ds
580
    pushf
577
    pushf
581
    call    [.oldtimer]
578
    call    [.oldtimer]
582
    pushad
579
    pushad
583
    call    .gettime
580
    call    .gettime
584
    sub    eax, [.starttime]
581
    sub    eax, [.starttime]
585
    sub    ax, 18*5
582
    sub    ax, 18*5
586
    jae    .timergo
583
    jae    .timergo
587
    neg    ax
584
    neg    ax
588
    add    ax, 18-1
585
    add    ax, 18-1
589
    mov    bx, 18
586
    mov    bx, 18
590
    xor    dx, dx
587
    xor    dx, dx
591
    div    bx
588
    div    bx
592
if lang eq ru
589
if lang eq ru
593
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
590
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
594
    cmp    al, 5
591
    cmp    al, 5
595
    mov    cl, ' '
592
    mov    cl, ' '
596
    jae    @f
593
    jae    @f
597
    cmp    al, 1
594
    cmp    al, 1
598
    mov    cl, 'ã'
595
    mov    cl, 'ã'
599
    jz    @f
596
    jz    @f
600
    mov    cl, 'ë'
597
    mov    cl, 'ë'
601
@@:    mov    [time_str+9], cl
598
@@:    mov    [time_str+9], cl
602
else if lang eq et
599
else if lang eq et
603
    cmp    al, 1
600
    cmp    al, 1
604
    ja     @f
601
    ja     @f
605
    mov    [time_str+9], ' '
602
    mov    [time_str+9], ' '
606
    mov    [time_str+10],' '
603
    mov    [time_str+10],' '
607
@@:
604
@@:
608
else
605
else
609
; wait 5/4/3/2 seconds, 1 second
606
; wait 5/4/3/2 seconds, 1 second
610
    cmp    al, 1
607
    cmp    al, 1
611
    mov    cl, 's'
608
    mov    cl, 's'
612
    ja    @f
609
    ja    @f
613
    mov    cl, ' '
610
    mov    cl, ' '
614
@@:    mov    [time_str+9], cl
611
@@:    mov    [time_str+9], cl
615
end if
612
end if
616
    add    al, '0'
613
    add    al, '0'
617
    mov    [time_str+1], al
614
    mov    [time_str+1], al
618
    mov    si, time_msg
615
    mov    si, time_msg
619
    _setcursor 7,0
616
    _setcursor 7,0
620
    call    print
617
    call    print
621
    _setcursor 25,0
618
    _setcursor 25,0
622
    popad
619
    popad
623
    pop    ds
620
    pop    ds
624
    iret
621
    iret
625
.timergo:
622
.timergo:
626
    push    0
623
    push    0
627
    pop    es
624
    pop    es
628
    mov    eax, [.oldtimer]
625
    mov    eax, [.oldtimer]
629
    mov    [es:8*4], eax
626
    mov    [es:8*4], eax
630
    mov    sp, 0EC00h
627
    mov    sp, 0EC00h
631
.continue:
628
.continue:
632
    sti
629
    sti
633
    _setcursor 6,0
630
    _setcursor 6,0
634
    mov    si, space_msg
631
    mov    si, space_msg
635
    call    printplain
632
    call    printplain
636
    call    printplain
633
    call    printplain
637
    _setcursor 6,0
634
    _setcursor 6,0
638
    mov    si, loading_msg
635
    mov    si, loading_msg
639
    call    print
636
    call    print
640
    _setcursor 15,0
637
    _setcursor 15,0
641
    cmp    [.bSettingsChanged], 0
638
    cmp    [.bSettingsChanged], 0
642
    jz    .load
639
    jz    .load
643
    cmp    [.loader_block], -1
640
    cmp    [.loader_block], -1
644
    jz    .load
641
    jz    .load
645
    les    bx, [.loader_block]
642
    les    bx, [.loader_block]
646
    mov    eax, [es:bx+3]
643
    mov    eax, [es:bx+3]
647
    push    ds
644
    push    ds
648
    pop    es
645
    pop    es
649
    test    eax, eax
646
    test    eax, eax
650
    jz    .load
647
    jz    .load
651
    push    eax
648
    push    eax
652
    mov    si, save_quest
649
    mov    si, save_quest
653
    call    print
650
    call    print
654
.waityn:
651
.waityn:
655
    mov    ah, 0
652
    mov    ah, 0
656
    int    16h
653
    int    16h
657
    or    al, 20h
654
    or    al, 20h
658
    cmp    al, 'n'
655
    cmp    al, 'n'
659
    jz    .loadc
656
    jz    .loadc
660
    cmp    al, 'y'
657
    cmp    al, 'y'
661
    jnz    .waityn
658
    jnz    .waityn
662
    call    putchar
659
    call    putchar
663
    mov    byte [space_msg+80], 186
660
    mov    byte [space_msg+80], 186
664
    pop    eax
661
    pop    eax
665
    push    cs
662
    push    cs
666
    push    .cont
663
    push    .cont
667
    push    eax
664
    push    eax
668
    retf
665
    retf
669
.loadc:
666
.loadc:
670
    pop    eax
667
    pop    eax
671
.cont:
668
.cont:
672
    push    cs
669
    push    cs
673
    pop    ds
670
    pop    ds
674
    mov    si, space_msg
671
    mov    si, space_msg
675
    mov    byte [si+80], 0
672
    mov    byte [si+80], 0
676
    _setcursor 15,0
673
    _setcursor 15,0
677
    call    printplain
674
    call    printplain
678
    _setcursor 15,0
675
    _setcursor 15,0
679
.load:
676
.load:
680
; \end{diamond}[02.12.2005]
677
; \end{diamond}[02.12.2005]
681
 
678
 
682
; ASK GRAPHICS MODE
679
; ASK GRAPHICS MODE
683
 
680
 
684
    movzx    ax, [preboot_graph]
681
    movzx    ax, [preboot_graph]
685
    push    0
682
    push    0
686
    pop    es
683
    pop    es
687
; address is gr_table+6*(ax-1)
684
; address is gr_table+6*(ax-1)
688
        add    ax, ax
685
        add    ax, ax
689
        lea    si, [gr_table + eax + eax*2 - 6]
686
        lea    si, [gr_table + eax + eax*2 - 6]
690
        mov     bx,[si+0]
687
        mov     bx,[si+0]
691
        mov     cx,[si+2]
688
        mov     cx,[si+2]
692
        mov     dx,[si+4]
689
        mov     dx,[si+4]
693
        cmp    al, 9*2
690
        cmp    al, 9*2
694
        mov    al, 32    ; BPP
691
        mov    al, 32    ; BPP
695
        jb    @f
692
        jb    @f
696
        mov    [es:0x9000], al
693
        mov    [es:0x9000], al
697
        mov    dword [es:0x9018], 0xFFFFFFFF; 0x800000
694
        mov    dword [es:0x9018], 0xFFFFFFFF; 0x800000
698
       @@:
695
       @@:
699
        mov     [es:0x9008],bx
696
        mov     [es:0x9008],bx
700
        mov     [es:0x900A],cx
697
        mov     [es:0x900A],cx
701
        mov     [es:0x900C],dx
698
        mov     [es:0x900C],dx
702
        test    bh, bh
699
        test    bh, bh
703
        jz    nov
700
        jz    nov
704
 
701
 
705
; USE DEFAULTS OR PROBE
702
; USE DEFAULTS OR PROBE
706
 
703
 
707
; bx - mode : cx - x size : dx - y size
704
; bx - mode : cx - x size : dx - y size
708
    cmp    [preboot_gprobe], 1
705
    cmp    [preboot_gprobe], 1
709
    jz    noprobe
706
    jz    noprobe
710
 
707
 
711
        mov     bx,0x100
708
        mov     bx,0x100
712
     newprobe:
709
     newprobe:
713
        inc     bx
710
        inc     bx
714
        cmp     bx,0x17f
711
        cmp     bx,0x17f
715
        mov    si,prnotfnd
712
        mov    si,prnotfnd
716
        jz    sayerr
713
        jz    sayerr
717
 
714
 
718
     probemore:
715
     probemore:
719
         push    cx
716
         push    cx
720
        mov     ax,0x4f01
717
        mov     ax,0x4f01
721
        mov     cx,bx
718
        mov     cx,bx
722
        and     cx,0xfff
719
        and     cx,0xfff
723
        mov     di,0xa000
720
        mov     di,0xa000
724
        int     0x10
721
        int     0x10
725
        pop    cx
722
        pop    cx
726
 
723
 
727
    test    byte [es:di], 80h    ; lfb?
724
    test    byte [es:di], 80h    ; lfb?
728
    jz    newprobe
725
    jz    newprobe
729
    cmp    [es:di+0x12], cx    ; x size?
726
    cmp    [es:di+0x12], cx    ; x size?
730
    jnz    newprobe
727
    jnz    newprobe
731
    cmp    [es:di+0x14], dx    ; y size?
728
    cmp    [es:di+0x14], dx    ; y size?
732
    jnz    newprobe
729
    jnz    newprobe
733
    cmp    byte [es:di+0x19], 32 ;24
730
    cmp    byte [es:di+0x19], 32 ;24
734
    jb    newprobe
731
    jb    newprobe
735
 
732
 
736
;       add     bx,0100000000000000b
733
;       add     bx,0100000000000000b
737
    or    bh, 40h
734
    or    bh, 40h
738
        mov     [es:0x9008],bx
735
        mov     [es:0x9008],bx
739
 
736
 
740
     noprobe:
737
     noprobe:
741
 
738
 
742
 
739
 
743
; FIND VESA 2.0 LFB & BPP
740
; FIND VESA 2.0 LFB & BPP
744
 
741
 
745
        mov     ax,0x4f01
742
        mov     ax,0x4f01
746
        mov     cx,bx
743
        mov     cx,bx
747
        and     cx,0xfff
744
        and     cx,0xfff
748
        mov     di,0xa000
745
        mov     di,0xa000
749
        int     0x10
746
        int     0x10
750
        ; LFB
747
        ; LFB
751
        mov     eax,[es:di+0x28]
748
        mov     eax,[es:di+0x28]
752
        mov     [es:0x9018],eax
749
        mov     [es:0x9018],eax
753
        ; ---- vbe voodoo
750
        ; ---- vbe voodoo
754
        BytesPerLine equ 0x10
751
        BytesPerLine equ 0x10
755
        mov ax, [es:di+BytesPerLine]
752
        mov ax, [es:di+BytesPerLine]
756
        mov [es:0x9001],ax
753
        mov [es:0x9001],ax
757
        ; BPP
754
        ; BPP
758
        mov     al,byte [es:di+0x19]
755
        mov     al,byte [es:di+0x19]
759
        mov     [es:0x9000],al
756
        mov     [es:0x9000],al
760
       nov:
757
       nov:
761
        cmp     al,24
758
        cmp     al,24
762
        mov    si,bt24
759
        mov    si,bt24
763
        jz    bppl
760
        jz    bppl
764
        cmp     al,32
761
        cmp     al,32
765
        mov     si,bt32
762
        mov     si,bt32
766
        jz     bppl
763
        jz     bppl
767
        mov     si,btns
764
        mov     si,btns
768
        jmp    sayerr
765
        jmp    sayerr
769
       bppl:
766
       bppl:
770
        call    print
767
        call    print
771
 
768
 
772
 
769
 
773
; FIND VESA 1.2 PM BANK SWITCH ADDRESS
770
; FIND VESA 1.2 PM BANK SWITCH ADDRESS
774
 
771
 
775
    push    es
772
    push    es
776
        mov     ax,0x4f0A
773
        mov     ax,0x4f0A
777
        xor    bx, bx
774
        xor    bx, bx
778
        int     0x10
775
        int     0x10
779
        xor     eax,eax
776
        xor     eax,eax
780
        mov     ax,es
777
        mov     ax,es
781
        shl     eax,4
778
        shl     eax,4
782
        movzx   ebx,di
779
        movzx   ebx,di
783
        add     eax,ebx
780
        add     eax,ebx
784
        mov     bx,[es:di]
781
        mov     bx,[es:di]
785
        add     eax,ebx
782
        add     eax,ebx
786
        pop     es
783
        pop     es
787
        mov     [es:0x9014],eax
784
        mov     [es:0x9014],eax
788
 
785
 
789
 
786
 
790
; GRAPHICS ACCELERATION
787
; GRAPHICS ACCELERATION
791
; force yes
788
; force yes
792
        mov     [es:0x901C], byte 1
789
        mov     [es:0x901C], byte 1
793
 
790
 
794
; DMA WRITE
791
; DMA WRITE
795
 
792
 
796
        mov     al, [preboot_dma_write]
793
        mov     al, [preboot_dma_write]
797
        mov     [es:0x901F],al
794
        mov     [es:0x901F],al
798
 
795
 
799
; VRR_M USE
796
; VRR_M USE
800
 
797
 
801
        mov     al,[preboot_vrrm]
798
        mov     al,[preboot_vrrm]
802
        mov     [es:0x9030],al
799
        mov     [es:0x9030],al
803
        mov     [es:0x901E],byte 1
800
        mov     [es:0x901E],byte 1
804
 
801
 
805
; BOOT DEVICE
802
; BOOT DEVICE
806
 
803
 
807
    mov    al, [preboot_device]
804
    mov    al, [preboot_device]
808
        dec     al
805
        dec     al
809
        mov     [boot_dev],al
806
        mov     [boot_dev],al
810
 
807
 
811
; READ DISKETTE TO MEMORY
808
; READ DISKETTE TO MEMORY
812
 
809
 
813
;        cmp     [boot_dev],0
810
;        cmp     [boot_dev],0
814
        jne     no_sys_on_floppy
811
        jne     no_sys_on_floppy
815
        mov     si,diskload
812
        mov     si,diskload
816
        call    print
813
        call    print
817
        xor    ax, ax            ; reset drive
814
        xor    ax, ax            ; reset drive
818
        xor    dx, dx
815
        xor    dx, dx
819
        int     0x13
816
        int     0x13
820
; now load floppy image to memory
817
; now load floppy image to memory
821
; at first load boot sector and first FAT table
818
; at first load boot sector and first FAT table
822
        mov     cx, 0x0001      ; startcyl,startsector
819
        mov     cx, 0x0001      ; startcyl,startsector
823
        xor     dx, dx          ; starthead,drive
820
        xor     dx, dx          ; starthead,drive
824
        mov     al, 1+9         ; no of sectors to read
821
        mov     al, 1+9         ; no of sectors to read
825
        mov     bx, 0xB000      ; es:bx -> data area
822
        mov     bx, 0xB000      ; es:bx -> data area
826
        call    boot_read_floppy
823
        call    boot_read_floppy
827
; and copy them to extended memory
824
; and copy them to extended memory
828
        mov     si, movedesc
825
        mov     si, movedesc
829
        mov     [si+8*2+3], bh
826
        mov     [si+8*2+3], bh
830
        push    es
827
        push    es
831
        push    ds
828
        push    ds
832
        pop     es
829
        pop     es
833
        mov     cx, 256*10
830
        mov     cx, 256*10
834
        mov     ah, 0x87
831
        mov     ah, 0x87
835
        int     0x15
832
        int     0x15
836
        test    ah, ah
833
        test    ah, ah
837
        jz      @f
834
        jz      @f
838
sayerr_floppy:
835
sayerr_floppy:
839
        mov     dx, 0x3f2
836
        mov     dx, 0x3f2
840
        mov     al, 0
837
        mov     al, 0
841
        out     dx, al
838
        out     dx, al
842
        mov     si, memmovefailed
839
        mov     si, memmovefailed
843
        jmp     sayerr_plain
840
        jmp     sayerr_plain
844
@@:
841
@@:
845
        add     dword [si+8*3+2], 512*10
842
        add     dword [si+8*3+2], 512*10
846
; copy FAT to second copy
843
; copy FAT to second copy
847
        mov     byte [si+8*2+3], 0xB2
844
        mov     byte [si+8*2+3], 0xB2
848
        mov     cx, 256*9
845
        mov     cx, 256*9
849
        mov     ah, 0x87
846
        mov     ah, 0x87
850
        int     0x15
847
        int     0x15
851
        pop     es
848
        pop     es
852
        test    ah, ah
849
        test    ah, ah
853
        jnz     sayerr_floppy
850
        jnz     sayerr_floppy
854
        add     dword [si+8*3+2], 512*9
851
        add     dword [si+8*3+2], 512*9
855
; calculate total number of sectors to read
852
; calculate total number of sectors to read
856
        mov     ax, 1+9+14      ; boot+FAT+root
853
        mov     ax, 1+9+14      ; boot+FAT+root
857
        mov     di, 0xB203
854
        mov     di, 0xB203
858
.calc_loop:
855
.calc_loop:
859
        test    word [es:di], 0xFFF
856
        test    word [es:di], 0xFFF
860
        jz      @f
857
        jz      @f
861
        inc     ax
858
        inc     ax
862
@@:
859
@@:
863
        test    word [es:di+1], 0xFFF0
860
        test    word [es:di+1], 0xFFF0
864
        jz      @f
861
        jz      @f
865
        inc     ax
862
        inc     ax
866
@@:
863
@@:
867
        add     di, 3
864
        add     di, 3
868
        cmp     di, 0xB200+1440*3
865
        cmp     di, 0xB200+1440*3
869
        jb      .calc_loop
866
        jb      .calc_loop
870
        push    ax
867
        push    ax
871
        mov     bp, 1+9         ; already read sectors
868
        mov     bp, 1+9         ; already read sectors
872
; now read rest
869
; now read rest
873
        mov     byte [si+8*2+3], 0xA0
870
        mov     byte [si+8*2+3], 0xA0
874
        mov     di, 2-14        ; absolute sector-31
871
        mov     di, 2-14        ; absolute sector-31
875
        mov     cx, 0x0002      ; cylinder=0, sector=2
872
        mov     cx, 0x0002      ; cylinder=0, sector=2
876
        mov     dx, 0x0100      ; head=1, disk=0
873
        mov     dx, 0x0100      ; head=1, disk=0
877
.read_loop:
874
.read_loop:
878
; determine whether sector must be read
875
; determine whether sector must be read
879
        cmp     di, 2
876
        cmp     di, 2
880
        jl      .read
877
        jl      .read
881
        mov     bx, di
878
        mov     bx, di
882
        shr     bx, 1
879
        shr     bx, 1
883
        jnc     .even
880
        jnc     .even
884
        test    word [es:bx+di+0xB200], 0xFFF0
881
        test    word [es:bx+di+0xB200], 0xFFF0
885
        jmp     @f
882
        jmp     @f
886
.even:
883
.even:
887
        test    word [es:bx+di+0xB200], 0xFFF
884
        test    word [es:bx+di+0xB200], 0xFFF
888
@@:
885
@@:
889
        jz      .skip
886
        jz      .skip
890
.read:
887
.read:
891
        mov     bx, 0xA000
888
        mov     bx, 0xA000
892
        mov     al, 1           ; 1 sector
889
        mov     al, 1           ; 1 sector
893
        call    boot_read_floppy
890
        call    boot_read_floppy
894
        inc     bp
891
        inc     bp
895
        push    es
892
        push    es
896
        push    ds
893
        push    ds
897
        pop     es
894
        pop     es
898
        pusha
895
        pusha
899
        mov     cx, 256
896
        mov     cx, 256
900
        mov     ah, 0x87
897
        mov     ah, 0x87
901
        int     0x15
898
        int     0x15
902
        test    ah, ah
899
        test    ah, ah
903
        popa
900
        popa
904
        pop     es
901
        pop     es
905
        jnz     sayerr_floppy
902
        jnz     sayerr_floppy
906
.skip:
903
.skip:
907
        add     dword [si+8*3+2], 512
904
        add     dword [si+8*3+2], 512
908
        inc     cx
905
        inc     cx
909
        cmp     cl, 19
906
        cmp     cl, 19
910
        jnz     @f
907
        jnz     @f
911
        mov     cl, 1
908
        mov     cl, 1
912
        inc     dh
909
        inc     dh
913
        cmp     dh, 2
910
        cmp     dh, 2
914
        jnz     @f
911
        jnz     @f
915
        mov     dh, 0
912
        mov     dh, 0
916
        inc     ch
913
        inc     ch
917
@@:
914
@@:
918
        pop     ax
915
        pop     ax
919
        push    ax
916
        push    ax
920
        pusha
917
        pusha
921
; draw percentage
918
; draw percentage
922
; total sectors: ax
919
; total sectors: ax
923
; read sectors: bp
920
; read sectors: bp
924
        xchg    ax, bp
921
        xchg    ax, bp
925
        mov     cx, 100
922
        mov     cx, 100
926
        mul     cx
923
        mul     cx
927
        div     bp
924
        div     bp
928
        aam
925
        aam
929
        xchg    al, ah
926
        xchg    al, ah
930
        add     ax, '00'
927
        add     ax, '00'
931
        mov     si, pros
928
        mov     si, pros
932
        cmp     [si], ax
929
        cmp     [si], ax
933
        jz      @f
930
        jz      @f
934
        mov     [si], ax
931
        mov     [si], ax
935
        call    printplain
932
        call    printplain
936
@@:
933
@@:
937
        popa
934
        popa
938
        inc     di
935
        inc     di
939
        cmp     di, 2880-31
936
        cmp     di, 2880-31
940
        jnz     .read_loop
937
        jnz     .read_loop
941
 
938
 
942
;        mov     cx, 0x0001      ; startcyl,startsector
939
;        mov     cx, 0x0001      ; startcyl,startsector
943
;        xor     dx, dx          ; starthead,drive
940
;        xor     dx, dx          ; starthead,drive
944
;        push    word 80*2               ; read no of sect
941
;        push    word 80*2               ; read no of sect
945
;       reads:
942
;       reads:
946
;        pusha
943
;        pusha
947
;        xor     si,si
944
;        xor     si,si
948
;       newread:
945
;       newread:
949
;        mov     bx,0xa000               ; es:bx -> data area
946
;        mov     bx,0xa000               ; es:bx -> data area
950
;        mov     ax,0x0200+18            ; read, no of sectors to read
947
;        mov     ax,0x0200+18            ; read, no of sectors to read
951
;        int     0x13
948
;        int     0x13
952
;        test    ah, ah
949
;        test    ah, ah
953
;        jz      goodread
950
;        jz      goodread
954
;        inc    si
951
;        inc    si
955
;        cmp     si,10
952
;        cmp     si,10
956
;        jnz     newread
953
;        jnz     newread
957
;        mov     si,badsect-0x10000
954
;        mov     si,badsect-0x10000
958
;sayerr_plain:
955
;sayerr_plain:
959
;        call    printplain
956
;        call    printplain
960
;        jmp     $
957
;        jmp     $
961
;       goodread:
958
;       goodread:
962
;        ; move -> 1mb
959
;        ; move -> 1mb
963
;        mov     si,movedesc-0x10000
960
;        mov     si,movedesc-0x10000
964
;        push    es
961
;        push    es
965
;        push    ds
962
;        push    ds
966
;        pop     es
963
;        pop     es
967
;        mov     cx,256*18
964
;        mov     cx,256*18
968
;        mov     ah,0x87
965
;        mov     ah,0x87
969
;        int     0x15
966
;        int     0x15
970
;        pop    es
967
;        pop    es
971
;
968
;
972
;        test    ah,ah                  ; was the move successfull ?
969
;        test    ah,ah                  ; was the move successfull ?
973
;        je      goodmove
970
;        je      goodmove
974
;        mov     dx,0x3f2              ; floppy motor off
971
;        mov     dx,0x3f2              ; floppy motor off
975
;        mov     al,0
972
;        mov     al,0
976
;        out     dx,al
973
;        out     dx,al
977
;        mov     si,memmovefailed-0x10000
974
;        mov     si,memmovefailed-0x10000
978
;        jmp    sayerr_plain
975
;        jmp    sayerr_plain
979
;      goodmove:
976
;      goodmove:
980
;
977
;
981
;    add    dword [movedesc-0x10000+0x18+2], 512*18
978
;    add    dword [movedesc-0x10000+0x18+2], 512*18
982
;        popa
979
;        popa
983
;        inc     dh
980
;        inc     dh
984
;        cmp     dh,2
981
;        cmp     dh,2
985
;        jnz     bb2
982
;        jnz     bb2
986
;        mov     dh,0
983
;        mov     dh,0
987
;        inc     ch
984
;        inc     ch
988
;        pusha                        ; print prosentage
985
;        pusha                        ; print prosentage
989
;        mov     si,pros-0x10000
986
;        mov     si,pros-0x10000
990
;    shr    ch, 2
987
;    shr    ch, 2
991
;    mov    al, '5'
988
;    mov    al, '5'
992
;    test    ch, 1
989
;    test    ch, 1
993
;    jnz    @f
990
;    jnz    @f
994
;    mov    al, '0'
991
;    mov    al, '0'
995
;@@:
992
;@@:
996
;    mov    [si+1], al
993
;    mov    [si+1], al
997
;    shr    ch, 1
994
;    shr    ch, 1
998
;    add    ch, '0'
995
;    add    ch, '0'
999
;    mov    [si], ch
996
;    mov    [si], ch
1000
;        call    printplain
997
;        call    printplain
1001
;        popa
998
;        popa
1002
;       bb2:
999
;       bb2:
1003
;        pop     ax
1000
;        pop     ax
1004
;        dec     ax
1001
;        dec     ax
1005
;        push    ax
1002
;        push    ax
1006
;        jnz     reads
1003
;        jnz     reads
1007
;       readdone:
1004
;       readdone:
1008
;        pop     ax
1005
;        pop     ax
1009
 
1006
 
1010
        mov     si,backspace2
1007
        mov     si,backspace2
1011
        call    printplain
1008
        call    printplain
1012
        mov     si,okt
1009
        mov     si,okt
1013
        call    printplain
1010
        call    printplain
1014
       no_sys_on_floppy:
1011
       no_sys_on_floppy:
1015
        xor    ax, ax        ; reset drive
1012
        xor    ax, ax        ; reset drive
1016
        xor    dx, dx
1013
        xor    dx, dx
1017
        int     0x13
1014
        int     0x13
1018
       mov dx,0x3f2 ; floppy motor off
1015
       mov dx,0x3f2 ; floppy motor off
1019
       mov al,0
1016
       mov al,0
1020
       out dx,al
1017
       out dx,al
1021
 
1018
 
1022
 
1019
 
1023
; SET GRAPHICS
1020
; SET GRAPHICS
1024
 
1021
 
1025
        xor ax, ax
1022
        xor ax, ax
1026
        mov es, ax
1023
        mov es, ax
1027
 
1024
 
1028
        mov   ax,[es:0x9008]        ; vga & 320x200
1025
        mov   ax,[es:0x9008]        ; vga & 320x200
1029
        mov    bx, ax
1026
        mov    bx, ax
1030
        cmp     ax,0x13
1027
        cmp     ax,0x13
1031
        je      setgr
1028
        je      setgr
1032
        cmp     ax,0x12
1029
        cmp     ax,0x12
1033
        je      setgr
1030
        je      setgr
1034
        mov     ax,0x4f02            ; Vesa
1031
        mov     ax,0x4f02            ; Vesa
1035
setgr:
1032
setgr:
1036
        int     0x10
1033
        int     0x10
1037
        test    ah,ah
1034
        test    ah,ah
1038
        mov    si, fatalsel
1035
        mov    si, fatalsel
1039
        jnz    sayerr
1036
        jnz    sayerr
1040
; set mode 0x12 graphics registers:
1037
; set mode 0x12 graphics registers:
1041
        cmp     bx,0x12
1038
        cmp     bx,0x12
1042
        jne     gmok2
1039
        jne     gmok2
1043
 
1040
 
1044
        mov     al,0x05
1041
        mov     al,0x05
1045
        mov     dx,0x03ce
1042
        mov     dx,0x03ce
1046
        push    dx
1043
        push    dx
1047
        out     dx,al      ; select GDC mode register
1044
        out     dx,al      ; select GDC mode register
1048
        mov     al,0x02
1045
        mov     al,0x02
1049
        inc    dx
1046
        inc    dx
1050
        out     dx,al      ; set write mode 2
1047
        out     dx,al      ; set write mode 2
1051
 
1048
 
1052
        mov     al,0x02
1049
        mov     al,0x02
1053
        mov     dx,0x03c4
1050
        mov     dx,0x03c4
1054
        out     dx,al      ; select VGA sequencer map mask register
1051
        out     dx,al      ; select VGA sequencer map mask register
1055
        mov     al,0x0f
1052
        mov     al,0x0f
1056
        inc    dx
1053
        inc    dx
1057
        out     dx,al      ; set mask for all planes 0-3
1054
        out     dx,al      ; set mask for all planes 0-3
1058
 
1055
 
1059
        mov     al,0x08
1056
        mov     al,0x08
1060
        pop    dx
1057
        pop    dx
1061
        out     dx,al      ; select GDC bit mask register
1058
        out     dx,al      ; select GDC bit mask register
1062
                           ; for writes to 0x03cf
1059
                           ; for writes to 0x03cf
1063
gmok2:
1060
gmok2:
1064
        push    ds
1061
        push    ds
1065
        pop    es
1062
        pop    es