Subversion Repositories Kolibri OS

Rev

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

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