Subversion Repositories Kolibri OS

Rev

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