Subversion Repositories Kolibri OS

Rev

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