Subversion Repositories Kolibri OS

Rev

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

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