Subversion Repositories Kolibri OS

Rev

Rev 641 | Rev 713 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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