Subversion Repositories Kolibri OS

Rev

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

  1. $Revision: 545 $
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;                                                              ;;
  4. ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
  5. ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
  6. ;; Distributed under terms of the GNU General Public License    ;;
  7. ;;                                                              ;;
  8. ;;  BOOTCODE.INC                                                ;;
  9. ;;                                                              ;;
  10. ;;  KolibriOS 16-bit loader,                                    ;;
  11. ;;                        based on bootcode for MenuetOS        ;;
  12. ;;                                                              ;;
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14.  
  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_dma  = use DMA access?
  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.         cmp     [di+preboot_dma-preboot_graph], 0
  385.         jnz     @f
  386.         mov     [di+preboot_dma-preboot_graph], 3 ; DMA: defaults to none
  387. @@:
  388. ; following 4 lines set variables to 1 if its current value is 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, vrrm_msg
  454.         cmp     [preboot_vrrm], 1
  455.         call    .say_on_off
  456.         mov     si, preboot_device_msg
  457.         call    print
  458.         mov     al, [preboot_device]
  459.         and     eax, 7
  460.         mov     si, [preboot_device_msgs+eax*2]
  461.         call    printplain
  462. .wait:
  463.         _setcursor 25,0         ; out of screen
  464. ; set timer interrupt handler
  465.         cli
  466.         push    0
  467.         pop     es
  468.         mov     eax, [es:8*4]
  469.         mov     [.oldtimer], eax
  470.         mov     eax, [.timer]
  471.         mov     [es:8*4], eax
  472.         sti
  473. ; wait for keypressed
  474.         mov     ah, 0
  475.         int     16h
  476.         push    ax
  477. ; restore timer interrupt
  478.         push    0
  479.         pop     es
  480.         mov     eax, [.oldtimer]
  481.         mov     [es:8*4], eax
  482.         mov     [.timer], eax
  483.         _setcursor 7,0
  484.         mov     si, space_msg
  485.         call    printplain
  486.         pop     ax
  487. ; switch on key
  488.         cmp     al, 13
  489.         jz      .continue
  490.         or      al, 20h
  491.         cmp     al, 'a'
  492.         jz      .change_a
  493.         cmp     al, 'b'
  494.         jz      .change_b
  495.         cmp     al, 'c'
  496.         jz      .change_c
  497.         cmp     al, 'd'
  498.         jnz     .wait
  499.         _setcursor 15,0
  500.         mov     si, bdev
  501.         call    print
  502.         mov     bx, '14'
  503.         call    getkey
  504.         mov     [preboot_device], al
  505.         _setcursor 13,0
  506. .d:
  507.         mov     [.bSettingsChanged], 1
  508.         mov     si, space_msg
  509.         call    printplain
  510.         _setcursor 15,0
  511.         mov     cx, 6
  512. @@:
  513.         call    printplain
  514.         loop    @b
  515.         jmp    .printcfg
  516. .change_a:
  517.         _setcursor 15,0
  518.         mov     si, gr_mode
  519.         call    printplain
  520.         mov     bx, '09'
  521.         call    getkey
  522.         mov     [preboot_graph], al
  523.         cmp     al, 4
  524.         ja      @f
  525.         mov     si, probetext
  526.         call    printplain
  527.         mov     bx, '12'
  528.         call    getkey
  529.         mov     [preboot_gprobe], al
  530. @@:
  531.         _setcursor 10,0
  532.         jmp    .d
  533. .change_b:
  534.         _setcursor 15,0
  535.         mov     si, ask_dma
  536.         call    print
  537.         mov     bx, '13'
  538.         call    getkey
  539.         mov     [preboot_dma], al
  540.         _setcursor 11,0
  541.         jmp     .d
  542. .change_c:
  543.         _setcursor 15,0
  544.         mov     si, vrrmprint
  545.         call    print
  546.         mov     bx, '12'
  547.         call    getkey
  548.         mov     [preboot_vrrm], al
  549.         _setcursor 12,0
  550.         jmp     .d
  551. .say_on_off:
  552.         pushf
  553.         call    print
  554.         mov     si, on_msg
  555.         popf
  556.         jz      @f
  557.         mov     si, off_msg
  558. @@:     jmp     printplain
  559. ; novesa and vervesa strings are not used at the moment of executing this code
  560. virtual at novesa
  561. .oldtimer dd ?
  562. .starttime dd ?
  563. .bSettingsChanged db ?
  564. .timer dd ?
  565. end virtual
  566. .loader_block dd -1
  567. .gettime:
  568.         mov     ah, 0
  569.         int     1Ah
  570.         xchg    ax, cx
  571.         shl     eax, 10h
  572.         xchg    ax, dx
  573.         ret
  574. .newtimer:
  575.         push    ds
  576.         push    cs
  577.         pop     ds
  578.         pushf
  579.         call    [.oldtimer]
  580.         pushad
  581.         call    .gettime
  582.         sub     eax, [.starttime]
  583.         sub     ax, 18*5
  584.         jae     .timergo
  585.         neg     ax
  586.         add     ax, 18-1
  587.         mov     bx, 18
  588.         xor     dx, dx
  589.         div     bx
  590. if lang eq ru
  591. ; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
  592.         cmp     al, 5
  593.         mov     cl, ' '
  594.         jae     @f
  595.         cmp     al, 1
  596.         mov     cl, 'ã'
  597.         jz      @f
  598.         mov     cl, 'ë'
  599. @@:     mov     [time_str+9], cl
  600. else if lang eq et
  601.         cmp     al, 1
  602.         ja      @f
  603.         mov     [time_str+9], ' '
  604.         mov     [time_str+10],' '
  605. @@:
  606. else
  607. ; wait 5/4/3/2 seconds, 1 second
  608.         cmp     al, 1
  609.         mov     cl, 's'
  610.         ja      @f
  611.         mov     cl, ' '
  612. @@:     mov     [time_str+9], cl
  613. end if
  614.         add     al, '0'
  615.         mov     [time_str+1], al
  616.         mov     si, time_msg
  617.         _setcursor 7,0
  618.         call    print
  619.         _setcursor 25,0
  620.         popad
  621.         pop     ds
  622.         iret
  623. .timergo:
  624.         push    0
  625.         pop     es
  626.         mov     eax, [.oldtimer]
  627.         mov     [es:8*4], eax
  628.         mov     sp, 0EC00h
  629. .continue:
  630.         sti
  631.         _setcursor 6,0
  632.         mov     si, space_msg
  633.         call    printplain
  634.         call    printplain
  635.         _setcursor 6,0
  636.         mov     si, loading_msg
  637.         call    print
  638.         _setcursor 15,0
  639.         cmp     [.bSettingsChanged], 0
  640.         jz      .load
  641.         cmp     [.loader_block], -1
  642.         jz      .load
  643.         les     bx, [.loader_block]
  644.         mov     eax, [es:bx+3]
  645.         push    ds
  646.         pop     es
  647.         test    eax, eax
  648.         jz      .load
  649.         push    eax
  650.         mov     si, save_quest
  651.         call    print
  652. .waityn:
  653.         mov     ah, 0
  654.         int     16h
  655.         or      al, 20h
  656.         cmp     al, 'n'
  657.         jz      .loadc
  658.         cmp     al, 'y'
  659.         jnz     .waityn
  660.         call    putchar
  661.         mov     byte [space_msg+80], 186
  662.         pop     eax
  663.         push    cs
  664.         push    .cont
  665.         push    eax
  666.         retf
  667. .loadc:
  668.         pop     eax
  669. .cont:
  670.         push    cs
  671.         pop     ds
  672.         mov     si, space_msg
  673.         mov     byte [si+80], 0
  674.         _setcursor 15,0
  675.         call    printplain
  676.         _setcursor 15,0
  677. .load:
  678. ; \end{diamond}[02.12.2005]
  679.  
  680. ; ASK GRAPHICS MODE
  681.  
  682.         movzx   ax, [preboot_graph]
  683.         push    0
  684.         pop     es
  685. ; address is gr_table+6*(ax-1)
  686.         add     ax, ax
  687.         lea     si, [gr_table + eax + eax*2 - 6]
  688.         mov     bx, [si+0]
  689.         mov     cx, [si+2]
  690.         mov     dx, [si+4]
  691.         cmp     al, 9*2
  692.         mov     al, 32    ; BPP
  693.         jb      @f
  694.         mov     [es:0x9000], al
  695.         or      dword [es:0x9018], 0xFFFFFFFF; 0x800000
  696. @@:
  697.         mov     [es:0x9008], bx
  698.         mov     [es:0x900A], cx
  699.         mov     [es:0x900C], dx
  700.         test    bh, bh
  701.         jz      nov
  702.  
  703. ; USE DEFAULTS OR PROBE
  704.  
  705. ; bx - mode : cx - x size : dx - y size
  706.         cmp     [preboot_gprobe], 1
  707.         jz      noprobe
  708.  
  709.         mov     bx, 0x100
  710.      newprobe:
  711.         inc     bx
  712.         cmp     bx, 0x17f
  713.         mov     si, prnotfnd
  714.         jz      invalid_video_mode
  715.  
  716.      probemore:
  717.         push    cx
  718.         mov     ax, 0x4f01
  719.         mov     cx, bx
  720.         mov     di, 0xa000
  721.         int     0x10
  722.         pop     cx
  723.  
  724.         test    byte [es:di], 80h    ; lfb?
  725.         jz      newprobe
  726.         cmp     [es:di+0x12], cx    ; x size?
  727.         jnz     newprobe
  728.         cmp     [es:di+0x14], dx    ; y size?
  729.         jnz     newprobe
  730.         cmp     byte [es:di+0x19], 32 ;24
  731.         jb      newprobe
  732.  
  733. ;       add     bx, 0100000000000000b
  734.         or      bh, 40h
  735.         mov     [es:0x9008], bx
  736.  
  737.      noprobe:
  738.  
  739.  
  740. ; FIND VESA 2.0 LFB & BPP
  741.  
  742.         mov     ax, 0x4f01
  743.         mov     cx, bx
  744.         and     cx, 0xfff
  745.         mov     di, 0xa000
  746.         int     0x10
  747.         ; LFB
  748.         mov     eax, [es:di+0x28]
  749.         mov     [es:0x9018], eax
  750.         ; ---- vbe voodoo
  751.         BytesPerLine equ 0x10
  752.         mov     ax, [es:di+BytesPerLine]
  753.         mov     [es:0x9001], ax
  754.         ; BPP
  755.         mov     al, byte [es:di+0x19]
  756.         mov     [es:0x9000], al
  757. nov:
  758.         cmp     al, 24
  759.         mov     si, bt24
  760.         jz      bppl
  761.         cmp     al, 32
  762.         mov     si, bt32
  763.         jz      bppl
  764.         mov     si, btns
  765. invalid_video_mode:
  766.         call    print
  767.         _setcursor (d80x25_top_num+2), 0
  768.         mov     si, start_msg
  769.         call    print
  770.         jmp     cfgmanager.printcfg
  771. bppl:
  772.         call    print
  773.  
  774.  
  775. ; FIND VESA 1.2 PM BANK SWITCH ADDRESS
  776.  
  777.         push    es
  778.         mov     ax, 0x4f0A
  779.         xor     bx, bx
  780.         int     0x10
  781.         xor     eax, eax
  782.         mov     ax, es
  783.         shl     eax, 4
  784.         movzx   ebx, di
  785.         add     eax, ebx
  786.         mov     bx, [es:di]
  787.         add     eax, ebx
  788.         pop     es
  789.         mov     [es:0x9014], eax
  790.  
  791.  
  792. ; GRAPHICS ACCELERATION
  793. ; force yes
  794.         mov     [es:0x901C], byte 1
  795.  
  796. ; DMA ACCESS TO HD
  797.  
  798.         mov     al, [preboot_dma]
  799.         mov     [es:0x901F], al
  800.  
  801. ; VRR_M USE
  802.  
  803.         mov     al,[preboot_vrrm]
  804.         mov     [es:0x9030], al
  805.         mov     [es:0x901E], byte 1
  806.  
  807. ; BOOT DEVICE
  808.  
  809.         mov     al, [preboot_device]
  810.         dec     al
  811.         mov     [boot_dev], al
  812.  
  813. ; READ DISKETTE TO MEMORY
  814.  
  815. ;        cmp     [boot_dev],0
  816.         jne     no_sys_on_floppy
  817.         mov     si,diskload
  818.         call    print
  819.         xor     ax, ax            ; reset drive
  820.         xor     dx, dx
  821.         int     0x13
  822. ; now load floppy image to memory
  823. ; at first load boot sector and first FAT table
  824.         mov     cx, 0x0001      ; startcyl,startsector
  825.         xor     dx, dx          ; starthead,drive
  826.         mov     al, 1+9         ; no of sectors to read
  827.         mov     bx, 0xB000      ; es:bx -> data area
  828.         call    boot_read_floppy
  829. ; and copy them to extended memory
  830.         mov     si, movedesc
  831.         mov     [si+8*2+3], bh
  832.         push    es
  833.         push    ds
  834.         pop     es
  835.         mov     cx, 256*10
  836.         mov     ah, 0x87
  837.         int     0x15
  838.         test    ah, ah
  839.         jz      @f
  840. sayerr_floppy:
  841.         mov     dx, 0x3f2
  842.         mov     al, 0
  843.         out     dx, al
  844.         mov     si, memmovefailed
  845.         jmp     sayerr_plain
  846. @@:
  847.         add     dword [si+8*3+2], 512*10
  848. ; copy FAT to second copy
  849.         mov     byte [si+8*2+3], 0xB2
  850.         mov     cx, 256*9
  851.         mov     ah, 0x87
  852.         int     0x15
  853.         pop     es
  854.         test    ah, ah
  855.         jnz     sayerr_floppy
  856.         add     dword [si+8*3+2], 512*9
  857. ; calculate total number of sectors to read
  858.         mov     ax, 1+9+14      ; boot+FAT+root
  859.         mov     di, 0xB203
  860. .calc_loop:
  861.         test    word [es:di], 0xFFF
  862.         jz      @f
  863.         inc     ax
  864. @@:
  865.         test    word [es:di+1], 0xFFF0
  866.         jz      @f
  867.         inc     ax
  868. @@:
  869.         add     di, 3
  870.         cmp     di, 0xB200+1440*3
  871.         jb      .calc_loop
  872.         push    ax
  873.         mov     bp, 1+9         ; already read sectors
  874. ; now read rest
  875.         mov     byte [si+8*2+3], 0xA0
  876.         mov     di, 2-14        ; absolute sector-31
  877.         mov     cx, 0x0002      ; cylinder=0, sector=2
  878.         mov     dx, 0x0100      ; head=1, disk=0
  879. .read_loop:
  880. ; determine whether sector must be read
  881.         cmp     di, 2
  882.         jl      .read
  883.         mov     bx, di
  884.         shr     bx, 1
  885.         jnc     .even
  886.         test    word [es:bx+di+0xB200], 0xFFF0
  887.         jmp     @f
  888. .even:
  889.         test    word [es:bx+di+0xB200], 0xFFF
  890. @@:
  891.         jz      .skip
  892. .read:
  893.         mov     bx, 0xA000
  894.         mov     al, 1           ; 1 sector
  895.         call    boot_read_floppy
  896.         inc     bp
  897.         push    es
  898.         push    ds
  899.         pop     es
  900.         pusha
  901.         mov     cx, 256
  902.         mov     ah, 0x87
  903.         int     0x15
  904.         test    ah, ah
  905.         popa
  906.         pop     es
  907.         jnz     sayerr_floppy
  908. .skip:
  909.         add     dword [si+8*3+2], 512
  910.         inc     cx
  911.         cmp     cl, 19
  912.         jnz     @f
  913.         mov     cl, 1
  914.         inc     dh
  915.         cmp     dh, 2
  916.         jnz     @f
  917.         mov     dh, 0
  918.         inc     ch
  919. @@:
  920.         pop     ax
  921.         push    ax
  922.         pusha
  923. ; draw percentage
  924. ; total sectors: ax
  925. ; read sectors: bp
  926.         xchg    ax, bp
  927.         mov     cx, 100
  928.         mul     cx
  929.         div     bp
  930.         aam
  931.         xchg    al, ah
  932.         add     ax, '00'
  933.         mov     si, pros
  934.         cmp     [si], ax
  935.         jz      @f
  936.         mov     [si], ax
  937.         call    printplain
  938. @@:
  939.         popa
  940.         inc     di
  941.         cmp     di, 2880-31
  942.         jnz     .read_loop
  943.  
  944. ;        mov     cx, 0x0001      ; startcyl,startsector
  945. ;        xor     dx, dx          ; starthead,drive
  946. ;        push    word 80*2               ; read no of sect
  947. ;       reads:
  948. ;        pusha
  949. ;        xor     si,si
  950. ;       newread:
  951. ;        mov     bx,0xa000               ; es:bx -> data area
  952. ;        mov     ax,0x0200+18            ; read, no of sectors to read
  953. ;        int     0x13
  954. ;        test    ah, ah
  955. ;        jz      goodread
  956. ;        inc    si
  957. ;        cmp     si,10
  958. ;        jnz     newread
  959. ;        mov     si,badsect-0x10000
  960. ;sayerr_plain:
  961. ;        call    printplain
  962. ;        jmp     $
  963. ;       goodread:
  964. ;        ; move -> 1mb
  965. ;        mov     si,movedesc-0x10000
  966. ;        push    es
  967. ;        push    ds
  968. ;        pop     es
  969. ;        mov     cx,256*18
  970. ;        mov     ah,0x87
  971. ;        int     0x15
  972. ;        pop    es
  973. ;
  974. ;        test    ah,ah                  ; was the move successfull ?
  975. ;        je      goodmove
  976. ;        mov     dx,0x3f2              ; floppy motor off
  977. ;        mov     al,0
  978. ;        out     dx,al
  979. ;        mov     si,memmovefailed-0x10000
  980. ;        jmp    sayerr_plain
  981. ;      goodmove:
  982. ;
  983. ;    add    dword [movedesc-0x10000+0x18+2], 512*18
  984. ;        popa
  985. ;        inc     dh
  986. ;        cmp     dh,2
  987. ;        jnz     bb2
  988. ;        mov     dh,0
  989. ;        inc     ch
  990. ;        pusha                        ; print prosentage
  991. ;        mov     si,pros-0x10000
  992. ;    shr    ch, 2
  993. ;    mov    al, '5'
  994. ;    test    ch, 1
  995. ;    jnz    @f
  996. ;    mov    al, '0'
  997. ;@@:
  998. ;    mov    [si+1], al
  999. ;    shr    ch, 1
  1000. ;    add    ch, '0'
  1001. ;    mov    [si], ch
  1002. ;        call    printplain
  1003. ;        popa
  1004. ;       bb2:
  1005. ;        pop     ax
  1006. ;        dec     ax
  1007. ;        push    ax
  1008. ;        jnz     reads
  1009. ;       readdone:
  1010. ;        pop     ax
  1011.  
  1012.         mov     si, backspace2
  1013.         call    printplain
  1014.         mov     si, okt
  1015.         call    printplain
  1016. no_sys_on_floppy:
  1017.         xor     ax, ax          ; reset drive
  1018.         xor     dx, dx
  1019.         int     0x13
  1020.         mov     dx, 0x3f2       ; floppy motor off
  1021.         mov     al, 0
  1022.         out     dx, al
  1023.  
  1024.  
  1025. ; SET GRAPHICS
  1026.  
  1027.         xor     ax, ax
  1028.         mov     es, ax
  1029.  
  1030.         mov     ax, [es:0x9008]         ; vga & 320x200
  1031.         mov     bx, ax
  1032.         cmp     ax, 0x13
  1033.         je      setgr
  1034.         cmp     ax, 0x12
  1035.         je      setgr
  1036.         mov     ax, 0x4f02              ; Vesa
  1037. setgr:
  1038.         int     0x10
  1039.         test    ah, ah
  1040.         mov     si, fatalsel
  1041.         jnz     sayerr
  1042. ; set mode 0x12 graphics registers:
  1043.         cmp     bx, 0x12
  1044.         jne     gmok2
  1045.  
  1046.         mov     al, 0x05
  1047.         mov     dx, 0x03ce
  1048.         push    dx
  1049.         out     dx, al      ; select GDC mode register
  1050.         mov     al, 0x02
  1051.         inc     dx
  1052.         out     dx, al      ; set write mode 2
  1053.  
  1054.         mov     al, 0x02
  1055.         mov     dx, 0x03c4
  1056.         out     dx, al      ; select VGA sequencer map mask register
  1057.         mov     al, 0x0f
  1058.         inc     dx
  1059.         out     dx, al      ; set mask for all planes 0-3
  1060.  
  1061.         mov     al, 0x08
  1062.         pop     dx
  1063.         out     dx, al      ; select GDC bit mask register
  1064.                            ; for writes to 0x03cf
  1065. gmok2:
  1066.         push    ds
  1067.         pop     es
  1068.