Subversion Repositories Kolibri OS

Rev

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

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