Subversion Repositories Kolibri OS

Rev

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

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