Subversion Repositories Kolibri OS

Rev

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

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