Subversion Repositories Kolibri OS

Rev

Rev 737 | Rev 749 | 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: 746 $
  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.         mov     word [preboot_graph],bp           ;save choose
  591.        
  592.         jmp    .d
  593.  
  594. .change_b:
  595.         _setcursor 15,0
  596. ;        mov     si, ask_dma
  597. ;        call    print
  598. ;        mov     bx, '13'
  599. ;        call    getkey
  600. ;        mov     [preboot_dma], al
  601.         mov     si, ask_bd
  602.         call    print
  603.         mov     bx, '12'
  604.         call    getkey
  605.         mov     [preboot_biosdisk], al
  606.         _setcursor 11,0
  607.         jmp     .d
  608. .change_c:
  609.         _setcursor 15,0
  610.         mov     si, vrrmprint
  611.         call    print
  612.         mov     bx, '12'
  613.         call    getkey
  614.         mov     [preboot_vrrm], al
  615.         _setcursor 12,0
  616.         jmp     .d
  617. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  618. .say_on_off:
  619.         pushf
  620.         call    print
  621.         mov     si, on_msg
  622.         popf
  623.         jz      @f
  624.         mov     si, off_msg
  625. @@:     jmp     printplain
  626. ; novesa and vervesa strings are not used at the moment of executing this code
  627. virtual at novesa
  628. .oldtimer dd ?
  629. .starttime dd ?
  630. .bSettingsChanged db ?
  631. .timer dd ?
  632. end virtual
  633. .loader_block dd -1
  634. .gettime:
  635.         mov     ah, 0
  636.         int     1Ah
  637.         xchg    ax, cx
  638.         shl     eax, 10h
  639.         xchg    ax, dx
  640.         ret
  641. .newtimer:
  642.         push    ds
  643.         push    cs
  644.         pop     ds
  645.         pushf
  646.         call    [.oldtimer]
  647.         pushad
  648.         call    .gettime
  649.         sub     eax, [.starttime]
  650.         sub     ax, 18*5
  651.         jae     .timergo
  652.         neg     ax
  653.         add     ax, 18-1
  654.         mov     bx, 18
  655.         xor     dx, dx
  656.         div     bx
  657. if lang eq ru
  658. ; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
  659.         cmp     al, 5
  660.         mov     cl, ' '
  661.         jae     @f
  662.         cmp     al, 1
  663.         mov     cl, 'ã'
  664.         jz      @f
  665.         mov     cl, 'ë'
  666. @@:     mov     [time_str+9], cl
  667. else if lang eq et
  668.         cmp     al, 1
  669.         ja      @f
  670.         mov     [time_str+9], ' '
  671.         mov     [time_str+10],' '
  672. @@:
  673. else
  674. ; wait 5/4/3/2 seconds, 1 second
  675.         cmp     al, 1
  676.         mov     cl, 's'
  677.         ja      @f
  678.         mov     cl, ' '
  679. @@:     mov     [time_str+9], cl
  680. end if
  681.         add     al, '0'
  682.         mov     [time_str+1], al
  683.         mov     si, time_msg
  684.         _setcursor 7,0
  685.         call    print
  686.         _setcursor 25,0
  687.         popad
  688.         pop     ds
  689.         iret
  690. .timergo:
  691.         push    0
  692.         pop     es
  693.         mov     eax, [.oldtimer]
  694.         mov     [es:8*4], eax
  695.         mov     sp, 0EC00h
  696. .continue:
  697.         sti
  698.         _setcursor 6,0
  699.         mov     si, space_msg
  700.         call    printplain
  701.         call    printplain
  702.         _setcursor 6,0
  703.         mov     si, loading_msg
  704.         call    print
  705.         _setcursor 15,0
  706.         cmp     [.bSettingsChanged], 0
  707.         jz      .load
  708.         cmp     [.loader_block], -1
  709.         jz      .load
  710.         les     bx, [.loader_block]
  711.         mov     eax, [es:bx+3]
  712.         push    ds
  713.         pop     es
  714.         test    eax, eax
  715.         jz      .load
  716.         push    eax
  717.         mov     si, save_quest
  718.         call    print
  719. .waityn:
  720.         mov     ah, 0
  721.         int     16h
  722.         or      al, 20h
  723.         cmp     al, 'n'
  724.         jz      .loadc
  725.         cmp     al, 'y'
  726.         jnz     .waityn
  727.         call    putchar
  728.         mov     byte [space_msg+80], 186
  729.         pop     eax
  730.         push    cs
  731.         push    .cont
  732.         push    eax
  733.         retf
  734. .loadc:
  735.         pop     eax
  736. .cont:
  737.         push    cs
  738.         pop     ds
  739.         mov     si, space_msg
  740.         mov     byte [si+80], 0
  741.         _setcursor 15,0
  742.         call    printplain
  743.         _setcursor 15,0
  744. .load:
  745. ; \end{diamond}[02.12.2005]
  746.  
  747. ; ASK GRAPHICS MODE
  748.  
  749.         call    set_vmode
  750.  
  751. ; GRAPHICS ACCELERATION
  752. ; force yes
  753.         mov     [es:0x901C], byte 1
  754.  
  755. ; DMA ACCESS TO HD
  756.  
  757.         mov     al, [preboot_dma]
  758.         mov     [es:0x901F], al
  759.  
  760. ; VRR_M USE
  761.  
  762.         mov     al,[preboot_vrrm]
  763.         mov     [es:0x9030], al
  764.         mov     [es:0x901E], byte 1
  765.  
  766. ; BOOT DEVICE
  767.  
  768.         mov     al, [preboot_device]
  769.         dec     al
  770.         mov     [boot_dev], al
  771.  
  772. ; READ DISKETTE TO MEMORY
  773.  
  774. ;        cmp     [boot_dev],0
  775.         jne     no_sys_on_floppy
  776.         mov     si,diskload
  777.         call    print
  778.         xor     ax, ax            ; reset drive
  779.         xor     dx, dx
  780.         int     0x13
  781. ; do we boot from CD-ROM?
  782.         mov     ah, 41h
  783.         mov     bx, 55AAh
  784.         xor     dx, dx
  785.         int     0x13
  786.         jc      .nocd
  787.         cmp     bx, 0AA55h
  788.         jnz     .nocd
  789.         mov     ah, 48h
  790.         push    ds
  791.         push    es
  792.         pop     ds
  793.         mov     si, 0xa000
  794.         mov     word [si], 30
  795.         int     0x13
  796.         pop     ds
  797.         jc      .nocd
  798.         push    ds
  799.         lds     si, [es:si+26]
  800.         test    byte [ds:si+10], 40h
  801.         pop     ds
  802.         jz      .nocd
  803. ; yes - read all floppy by 18 sectors
  804.         mov     cx, 0x0001      ; startcyl,startsector
  805. .a1:
  806.         push    cx dx
  807.         mov     al, 18
  808.         mov     bx, 0xa000
  809.         call    boot_read_floppy
  810.         mov     si, movedesc
  811.         push    es
  812.         push    ds
  813.         pop     es
  814.         mov     cx, 256*18
  815.         mov     ah, 0x87
  816.         int     0x15
  817.         pop     es
  818.         pop     dx cx
  819.         test    ah, ah
  820.         jnz     sayerr_floppy
  821.         add     dword [si+8*3+2], 512*18
  822.         inc     dh
  823.         cmp     dh, 2
  824.         jnz     .a1
  825.         mov     dh, 0
  826.         inc     ch
  827.         cmp     ch, 80
  828.         jae     ok_sys_on_floppy
  829.         pusha
  830.         mov     al, ch
  831.         shr     ch, 2
  832.         add     al, ch
  833.         aam
  834.         xchg    al, ah
  835.         add     ax, '00'
  836.         mov     si, pros
  837.         mov     [si], ax
  838.         call    printplain
  839.         popa
  840.         jmp     .a1
  841. .nocd:
  842. ; no - read only used sectors from floppy
  843. ; now load floppy image to memory
  844. ; at first load boot sector and first FAT table
  845.         mov     cx, 0x0001      ; startcyl,startsector
  846.         xor     dx, dx          ; starthead,drive
  847.         mov     al, 1+9         ; no of sectors to read
  848.         mov     bx, 0xB000      ; es:bx -> data area
  849.         call    boot_read_floppy
  850. ; and copy them to extended memory
  851.         mov     si, movedesc
  852.         mov     [si+8*2+3], bh
  853.         push    es
  854.         push    ds
  855.         pop     es
  856.         mov     cx, 256*10
  857.         mov     ah, 0x87
  858.         int     0x15
  859.         test    ah, ah
  860.         jz      @f
  861. sayerr_floppy:
  862.         mov     dx, 0x3f2
  863.         mov     al, 0
  864.         out     dx, al
  865.         mov     si, memmovefailed
  866.         jmp     sayerr_plain
  867. @@:
  868.         add     dword [si+8*3+2], 512*10
  869. ; copy FAT to second copy
  870.         mov     byte [si+8*2+3], 0xB2
  871.         mov     cx, 256*9
  872.         mov     ah, 0x87
  873.         int     0x15
  874.         pop     es
  875.         test    ah, ah
  876.         jnz     sayerr_floppy
  877.         add     dword [si+8*3+2], 512*9
  878. ; calculate total number of sectors to read
  879.         mov     ax, 1+9+14      ; boot+FAT+root
  880.         mov     di, 0xB203
  881. .calc_loop:
  882.         test    word [es:di], 0xFFF
  883.         jz      @f
  884.         inc     ax
  885. @@:
  886.         test    word [es:di+1], 0xFFF0
  887.         jz      @f
  888.         inc     ax
  889. @@:
  890.         add     di, 3
  891.         cmp     di, 0xB200+1440*3
  892.         jb      .calc_loop
  893.         push    ax
  894.         mov     bp, 1+9         ; already read sectors
  895. ; now read rest
  896.         mov     byte [si+8*2+3], 0xA0
  897.         mov     di, 2-14        ; absolute sector-31
  898.         mov     cx, 0x0002      ; cylinder=0, sector=2
  899.         mov     dx, 0x0100      ; head=1, disk=0
  900. .read_loop:
  901. ; determine whether sector must be read
  902.         cmp     di, 2
  903.         jl      .read
  904.         mov     bx, di
  905.         shr     bx, 1
  906.         jnc     .even
  907.         test    word [es:bx+di+0xB200], 0xFFF0
  908.         jmp     @f
  909. .even:
  910.         test    word [es:bx+di+0xB200], 0xFFF
  911. @@:
  912.         jz      .skip
  913. .read:
  914.         mov     bx, 0xA000
  915.         mov     al, 1           ; 1 sector
  916.         call    boot_read_floppy
  917.         inc     bp
  918.         push    es
  919.         push    ds
  920.         pop     es
  921.         pusha
  922.         mov     cx, 256
  923.         mov     ah, 0x87
  924.         int     0x15
  925.         test    ah, ah
  926.         popa
  927.         pop     es
  928.         jnz     sayerr_floppy
  929. .skip:
  930.         add     dword [si+8*3+2], 512
  931.         inc     cx
  932.         cmp     cl, 19
  933.         jnz     @f
  934.         mov     cl, 1
  935.         inc     dh
  936.         cmp     dh, 2
  937.         jnz     @f
  938.         mov     dh, 0
  939.         inc     ch
  940. @@:
  941.         pop     ax
  942.         push    ax
  943.         pusha
  944. ; draw percentage
  945. ; total sectors: ax
  946. ; read sectors: bp
  947.         xchg    ax, bp
  948.         mov     cx, 100
  949.         mul     cx
  950.         div     bp
  951.         aam
  952.         xchg    al, ah
  953.         add     ax, '00'
  954.         mov     si, pros
  955.         cmp     [si], ax
  956.         jz      @f
  957.         mov     [si], ax
  958.         call    printplain
  959. @@:
  960.         popa
  961.         inc     di
  962.         cmp     di, 2880-31
  963.         jnz     .read_loop
  964.  
  965. ;        mov     cx, 0x0001      ; startcyl,startsector
  966. ;        xor     dx, dx          ; starthead,drive
  967. ;        push    word 80*2               ; read no of sect
  968. ;       reads:
  969. ;        pusha
  970. ;        xor     si,si
  971. ;       newread:
  972. ;        mov     bx,0xa000               ; es:bx -> data area
  973. ;        mov     ax,0x0200+18            ; read, no of sectors to read
  974. ;        int     0x13
  975. ;        test    ah, ah
  976. ;        jz      goodread
  977. ;        inc    si
  978. ;        cmp     si,10
  979. ;        jnz     newread
  980. ;        mov     si,badsect-0x10000
  981. ;sayerr_plain:
  982. ;        call    printplain
  983. ;        jmp     $
  984. ;       goodread:
  985. ;        ; move -> 1mb
  986. ;        mov     si,movedesc-0x10000
  987. ;        push    es
  988. ;        push    ds
  989. ;        pop     es
  990. ;        mov     cx,256*18
  991. ;        mov     ah,0x87
  992. ;        int     0x15
  993. ;        pop    es
  994. ;
  995. ;        test    ah,ah                  ; was the move successfull ?
  996. ;        je      goodmove
  997. ;        mov     dx,0x3f2              ; floppy motor off
  998. ;        mov     al,0
  999. ;        out     dx,al
  1000. ;        mov     si,memmovefailed-0x10000
  1001. ;        jmp    sayerr_plain
  1002. ;      goodmove:
  1003. ;
  1004. ;    add    dword [movedesc-0x10000+0x18+2], 512*18
  1005. ;        popa
  1006. ;        inc     dh
  1007. ;        cmp     dh,2
  1008. ;        jnz     bb2
  1009. ;        mov     dh,0
  1010. ;        inc     ch
  1011. ;        pusha                        ; print prosentage
  1012. ;        mov     si,pros-0x10000
  1013. ;    shr    ch, 2
  1014. ;    mov    al, '5'
  1015. ;    test    ch, 1
  1016. ;    jnz    @f
  1017. ;    mov    al, '0'
  1018. ;@@:
  1019. ;    mov    [si+1], al
  1020. ;    shr    ch, 1
  1021. ;    add    ch, '0'
  1022. ;    mov    [si], ch
  1023. ;        call    printplain
  1024. ;        popa
  1025. ;       bb2:
  1026. ;        pop     ax
  1027. ;        dec     ax
  1028. ;        push    ax
  1029. ;        jnz     reads
  1030. ;       readdone:
  1031. ;        pop     ax
  1032.  
  1033. ok_sys_on_floppy:
  1034.         mov     si, backspace2
  1035.         call    printplain
  1036.         mov     si, okt
  1037.         call    printplain
  1038. no_sys_on_floppy:
  1039.         xor     ax, ax          ; reset drive
  1040.         xor     dx, dx
  1041.         int     0x13
  1042.         mov     dx, 0x3f2       ; floppy motor off
  1043.         mov     al, 0
  1044.         out     dx, al
  1045.  
  1046.  
  1047. ; SET GRAPHICS
  1048.  
  1049.         xor     ax, ax
  1050.         mov     es, ax
  1051.  
  1052.         mov     ax, [es:0x9008]         ; vga & 320x200
  1053.         mov     bx, ax
  1054.         cmp     ax, 0x13
  1055.         je      setgr
  1056.         cmp     ax, 0x12
  1057.         je      setgr
  1058.         mov     ax, 0x4f02              ; Vesa
  1059. setgr:
  1060.         int     0x10
  1061.         test    ah, ah
  1062.         mov     si, fatalsel
  1063.         jnz     v_mode_error
  1064. ; set mode 0x12 graphics registers:
  1065.         cmp     bx, 0x12
  1066.         jne     gmok2
  1067.  
  1068.         mov     al, 0x05
  1069.         mov     dx, 0x03ce
  1070.         push    dx
  1071.         out     dx, al      ; select GDC mode register
  1072.         mov     al, 0x02
  1073.         inc     dx
  1074.         out     dx, al      ; set write mode 2
  1075.  
  1076.         mov     al, 0x02
  1077.         mov     dx, 0x03c4
  1078.         out     dx, al      ; select VGA sequencer map mask register
  1079.         mov     al, 0x0f
  1080.         inc     dx
  1081.         out     dx, al      ; set mask for all planes 0-3
  1082.  
  1083.         mov     al, 0x08
  1084.         pop     dx
  1085.         out     dx, al      ; select GDC bit mask register
  1086.                            ; for writes to 0x03cf
  1087. gmok2:
  1088.         push    ds
  1089.         pop     es
  1090.