Subversion Repositories Kolibri OS

Rev

Rev 465 | Rev 509 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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