Subversion Repositories Kolibri OS

Rev

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

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