Subversion Repositories Kolibri OS

Rev

Rev 388 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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