Subversion Repositories Kolibri OS

Rev

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