Subversion Repositories Kolibri OS

Rev

Rev 713 | Rev 730 | 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: 726 $
  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.  
  350. noloaderblock:
  351. ; DISPLAY VESA INFORMATION
  352.          call    print_vesa_info
  353.          call    calc_vmodes_table
  354.          call    check_first_parm  ;check and enable cursor_pos
  355.  
  356.  
  357. ; \begin{diamond}[30.11.2005]
  358. cfgmanager:
  359. ; settings:
  360. ; a) preboot_graph = graphical mode
  361. ;    preboot_gprobe = probe this mode?
  362. ; b) preboot_dma  = use DMA access?
  363. ; c) preboot_vrrm = use VRR?
  364. ; d) preboot_device = from what boot?
  365.  
  366. ; determine default settings
  367.         mov     [.bSettingsChanged], 0
  368.  
  369. ;.preboot_gr_end:
  370.         mov     di, preboot_device
  371. ; if image in memory is present and [preboot_device] is uninitialized,
  372. ; set it to use this preloaded image
  373.         cmp     byte [di], 0
  374.         jnz     .preboot_device_inited
  375.         cmp     [.loader_block], -1
  376.         jz      @f
  377.         les     bx, [.loader_block]
  378.         test    byte [es:bx+1], 1
  379.         jz      @f
  380.         mov     byte [di], 3
  381.         jmp     .preboot_device_inited
  382. @@:
  383. ; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
  384.         mov     byte [di], 1
  385. .preboot_device_inited:
  386. ; following 6 lines set variables to 1 if its current value is 0
  387.         cmp     byte [di+preboot_dma-preboot_device], 1
  388.         adc     byte [di+preboot_dma-preboot_device], 0
  389.         cmp     byte [di+preboot_biosdisk-preboot_device], 1
  390.         adc     byte [di+preboot_biosdisk-preboot_device], 0
  391.         cmp     byte [di+preboot_vrrm-preboot_device], 1
  392.         adc     byte [di+preboot_vrrm-preboot_device], 0
  393. ; notify user
  394.         _setcursor 5,2
  395.  
  396.         mov     si, linef
  397.         call    printplain
  398.         mov     si, start_msg
  399.         call    print
  400.         mov     si, time_msg
  401.         call    print
  402. ; get start time
  403.         call    .gettime
  404.         mov     [.starttime], eax
  405.         mov     word [.timer], .newtimer
  406.         mov     word [.timer+2], cs
  407. .printcfg:
  408.         _setcursor 9,0
  409.         mov     si, current_cfg_msg
  410.         call    print
  411.         mov     si, curvideo_msg
  412.         call    print
  413.  
  414.             call    draw_current_vmode
  415.  
  416.         mov     si, usebd_msg
  417.         cmp     [preboot_biosdisk], 1
  418.         call    .say_on_off
  419.         mov     si, vrrm_msg
  420.         cmp     [preboot_vrrm], 1
  421.         call    .say_on_off
  422.         mov     si, preboot_device_msg
  423.         call    print
  424.         mov     al, [preboot_device]
  425.         and     eax, 7
  426.         mov     si, [preboot_device_msgs+eax*2]
  427.         call    printplain
  428. .show_remarks:
  429. ; show remarks in gray color
  430.         mov     di, ((21-num_remarks)*80 + 2)*2
  431.         push    0xB800
  432.         pop     es
  433.         mov     cx, num_remarks
  434.         mov     si, remarks
  435. .write_remarks:
  436.         lodsw
  437.         push    si
  438.         xchg    ax, si
  439.         mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
  440.         push    di
  441. .write_remark:
  442.         lodsb
  443.         test    al, al
  444.         jz      @f
  445.         stosw
  446.         jmp     .write_remark
  447. @@:
  448.         pop     di
  449.         pop     si
  450.         add     di, 80*2
  451.         loop    .write_remarks
  452. .wait:
  453.         _setcursor 25,0         ; out of screen
  454. ; set timer interrupt handler
  455.         cli
  456.         push    0
  457.         pop     es
  458.         push    dword [es:8*4]
  459.         pop     dword [.oldtimer]
  460.         push    dword [.timer]
  461.         pop     dword [es:8*4]    
  462. ;        mov     eax, [es:8*4]
  463. ;        mov     [.oldtimer], eax
  464. ;        mov     eax, [.timer]
  465. ;        mov     [es:8*4], eax
  466.         sti
  467. ; wait for keypressed
  468.         xor     ax,ax
  469.         int     16h
  470.         push    ax
  471. ; restore timer interrupt
  472. ;        push    0
  473. ;        pop     es
  474.         mov     eax, [.oldtimer]
  475.         mov     [es:8*4], eax
  476.         mov     [.timer], eax
  477.         _setcursor 7,0
  478.         mov     si, space_msg
  479.         call    printplain
  480. ; clear remarks and restore normal attributes
  481.         push    es
  482.         mov     di, ((21-num_remarks)*80 + 2)*2
  483.         push    0xB800
  484.         pop     es
  485.         mov     cx, num_remarks
  486.         mov     ax, ' ' + (1*16 + 15)*100h
  487. @@:
  488.         push    cx
  489.         mov     cx, 76
  490.         rep     stosw
  491.         pop     cx
  492.         add     di, 4*2
  493.         loop    @b
  494.         pop     es
  495.         pop     ax
  496. ; switch on key
  497.         cmp     al, 13
  498.         jz      .continue
  499.         or      al, 20h
  500.         cmp     al, 'a'
  501.         jz      .change_a
  502.         cmp     al, 'b'
  503.         jz      .change_b
  504.         cmp     al, 'c'
  505.         jz      .change_c
  506.         cmp     al, 'd'
  507.         jnz     .show_remarks
  508.         _setcursor 15,0
  509.         mov     si, bdev
  510.         call    print
  511.         mov     bx, '14'
  512.         call    getkey
  513.         mov     [preboot_device], al
  514.         _setcursor 13,0
  515. .d:
  516.         mov     [.bSettingsChanged], 1
  517.         call    clear_vmodes_table             ;clear vmodes_table
  518.         jmp    .printcfg
  519. .change_a:
  520. .loops:
  521.         call    draw_vmodes_table
  522.  
  523.         xor     ax,ax
  524.         int     0x16
  525. ;        call    clear_table_cursor             ;clear current position of cursor
  526.  
  527.         mov     si,word [cursor_pos]
  528.  
  529.         cmp     ah,0x48;x,0x48E0               ; up
  530.         jne     .down
  531.         cmp     si,modes_table
  532.         jbe     .loops
  533.         sub     word [cursor_pos],size_of_step
  534.         jmp     .loops
  535.  
  536. .down:  cmp     ah,0x50;x,0x50E0               ; down
  537.         jne     .enter
  538.         cmp     word[es:si+10],-1
  539.         je      .loops        
  540.         add     word [cursor_pos],size_of_step
  541.         jmp     .loops
  542.  
  543. .enter: cmp     al,0x0D;x,0x1C0D               ; enter
  544.         jne     .loops
  545.         push    word [cursor_pos]
  546.         pop     word [preboot_graph]           ;save choose
  547.         jmp    .d
  548.  
  549. .change_b:
  550.         _setcursor 15,0
  551. ;        mov     si, ask_dma
  552. ;        call    print
  553. ;        mov     bx, '13'
  554. ;        call    getkey
  555. ;        mov     [preboot_dma], al
  556.         mov     si, ask_bd
  557.         call    print
  558.         mov     bx, '12'
  559.         call    getkey
  560.         mov     [preboot_biosdisk], al
  561.         _setcursor 11,0
  562.         jmp     .d
  563. .change_c:
  564.         _setcursor 15,0
  565.         mov     si, vrrmprint
  566.         call    print
  567.         mov     bx, '12'
  568.         call    getkey
  569.         mov     [preboot_vrrm], al
  570.         _setcursor 12,0
  571.         jmp     .d
  572. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  573. .say_on_off:
  574.         pushf
  575.         call    print
  576.         mov     si, on_msg
  577.         popf
  578.         jz      @f
  579.         mov     si, off_msg
  580. @@:     jmp     printplain
  581. ; novesa and vervesa strings are not used at the moment of executing this code
  582. virtual at novesa
  583. .oldtimer dd ?
  584. .starttime dd ?
  585. .bSettingsChanged db ?
  586. .timer dd ?
  587. end virtual
  588. .loader_block dd -1
  589. .gettime:
  590.         mov     ah, 0
  591.         int     1Ah
  592.         xchg    ax, cx
  593.         shl     eax, 10h
  594.         xchg    ax, dx
  595.         ret
  596. .newtimer:
  597.         push    ds
  598.         push    cs
  599.         pop     ds
  600.         pushf
  601.         call    [.oldtimer]
  602.         pushad
  603.         call    .gettime
  604.         sub     eax, [.starttime]
  605.         sub     ax, 18*5
  606.         jae     .timergo
  607.         neg     ax
  608.         add     ax, 18-1
  609.         mov     bx, 18
  610.         xor     dx, dx
  611.         div     bx
  612. if lang eq ru
  613. ; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
  614.         cmp     al, 5
  615.         mov     cl, ' '
  616.         jae     @f
  617.         cmp     al, 1
  618.         mov     cl, 'ã'
  619.         jz      @f
  620.         mov     cl, 'ë'
  621. @@:     mov     [time_str+9], cl
  622. else if lang eq et
  623.         cmp     al, 1
  624.         ja      @f
  625.         mov     [time_str+9], ' '
  626.         mov     [time_str+10],' '
  627. @@:
  628. else
  629. ; wait 5/4/3/2 seconds, 1 second
  630.         cmp     al, 1
  631.         mov     cl, 's'
  632.         ja      @f
  633.         mov     cl, ' '
  634. @@:     mov     [time_str+9], cl
  635. end if
  636.         add     al, '0'
  637.         mov     [time_str+1], al
  638.         mov     si, time_msg
  639.         _setcursor 7,0
  640.         call    print
  641.         _setcursor 25,0
  642.         popad
  643.         pop     ds
  644.         iret
  645. .timergo:
  646.         push    0
  647.         pop     es
  648.         mov     eax, [.oldtimer]
  649.         mov     [es:8*4], eax
  650.         mov     sp, 0EC00h
  651. .continue:
  652.         sti
  653.         _setcursor 6,0
  654.         mov     si, space_msg
  655.         call    printplain
  656.         call    printplain
  657.         _setcursor 6,0
  658.         mov     si, loading_msg
  659.         call    print
  660.         _setcursor 15,0
  661.         cmp     [.bSettingsChanged], 0
  662.         jz      .load
  663.         cmp     [.loader_block], -1
  664.         jz      .load
  665.         les     bx, [.loader_block]
  666.         mov     eax, [es:bx+3]
  667.         push    ds
  668.         pop     es
  669.         test    eax, eax
  670.         jz      .load
  671.         push    eax
  672.         mov     si, save_quest
  673.         call    print
  674. .waityn:
  675.         mov     ah, 0
  676.         int     16h
  677.         or      al, 20h
  678.         cmp     al, 'n'
  679.         jz      .loadc
  680.         cmp     al, 'y'
  681.         jnz     .waityn
  682.         call    putchar
  683.         mov     byte [space_msg+80], 186
  684.         pop     eax
  685.         push    cs
  686.         push    .cont
  687.         push    eax
  688.         retf
  689. .loadc:
  690.         pop     eax
  691. .cont:
  692.         push    cs
  693.         pop     ds
  694.         mov     si, space_msg
  695.         mov     byte [si+80], 0
  696.         _setcursor 15,0
  697.         call    printplain
  698.         _setcursor 15,0
  699. .load:
  700. ; \end{diamond}[02.12.2005]
  701.  
  702. ; ASK GRAPHICS MODE
  703.  
  704.         call    set_vmode
  705.  
  706. ; GRAPHICS ACCELERATION
  707. ; force yes
  708.         mov     [es:0x901C], byte 1
  709.  
  710. ; DMA ACCESS TO HD
  711.  
  712.         mov     al, [preboot_dma]
  713.         mov     [es:0x901F], al
  714.  
  715. ; VRR_M USE
  716.  
  717.         mov     al,[preboot_vrrm]
  718.         mov     [es:0x9030], al
  719.         mov     [es:0x901E], byte 1
  720.  
  721. ; BOOT DEVICE
  722.  
  723.         mov     al, [preboot_device]
  724.         dec     al
  725.         mov     [boot_dev], al
  726.  
  727. ; READ DISKETTE TO MEMORY
  728.  
  729. ;        cmp     [boot_dev],0
  730.         jne     no_sys_on_floppy
  731.         mov     si,diskload
  732.         call    print
  733.         xor     ax, ax            ; reset drive
  734.         xor     dx, dx
  735.         int     0x13
  736. ; do we boot from CD-ROM?
  737.         mov     ah, 41h
  738.         mov     bx, 55AAh
  739.         xor     dx, dx
  740.         int     0x13
  741.         jc      .nocd
  742.         cmp     bx, 0AA55h
  743.         jnz     .nocd
  744.         mov     ah, 48h
  745.         push    ds
  746.         push    es
  747.         pop     ds
  748.         mov     si, 0xa000
  749.         mov     word [si], 30
  750.         int     0x13
  751.         pop     ds
  752.         jc      .nocd
  753.         push    ds
  754.         lds     si, [es:si+26]
  755.         test    byte [ds:si+10], 40h
  756.         pop     ds
  757.         jz      .nocd
  758. ; yes - read all floppy by 18 sectors
  759.         mov     cx, 0x0001      ; startcyl,startsector
  760. .a1:
  761.         push    cx dx
  762.         mov     al, 18
  763.         mov     bx, 0xa000
  764.         call    boot_read_floppy
  765.         mov     si, movedesc
  766.         push    es
  767.         push    ds
  768.         pop     es
  769.         mov     cx, 256*18
  770.         mov     ah, 0x87
  771.         int     0x15
  772.         pop     es
  773.         pop     dx cx
  774.         test    ah, ah
  775.         jnz     sayerr_floppy
  776.         add     dword [si+8*3+2], 512*18
  777.         inc     dh
  778.         cmp     dh, 2
  779.         jnz     .a1
  780.         mov     dh, 0
  781.         inc     ch
  782.         cmp     ch, 80
  783.         jae     ok_sys_on_floppy
  784.         pusha
  785.         mov     al, ch
  786.         shr     ch, 2
  787.         add     al, ch
  788.         aam
  789.         xchg    al, ah
  790.         add     ax, '00'
  791.         mov     si, pros
  792.         mov     [si], ax
  793.         call    printplain
  794.         popa
  795.         jmp     .a1
  796. .nocd:
  797. ; no - read only used sectors from floppy
  798. ; now load floppy image to memory
  799. ; at first load boot sector and first FAT table
  800.         mov     cx, 0x0001      ; startcyl,startsector
  801.         xor     dx, dx          ; starthead,drive
  802.         mov     al, 1+9         ; no of sectors to read
  803.         mov     bx, 0xB000      ; es:bx -> data area
  804.         call    boot_read_floppy
  805. ; and copy them to extended memory
  806.         mov     si, movedesc
  807.         mov     [si+8*2+3], bh
  808.         push    es
  809.         push    ds
  810.         pop     es
  811.         mov     cx, 256*10
  812.         mov     ah, 0x87
  813.         int     0x15
  814.         test    ah, ah
  815.         jz      @f
  816. sayerr_floppy:
  817.         mov     dx, 0x3f2
  818.         mov     al, 0
  819.         out     dx, al
  820.         mov     si, memmovefailed
  821.         jmp     sayerr_plain
  822. @@:
  823.         add     dword [si+8*3+2], 512*10
  824. ; copy FAT to second copy
  825.         mov     byte [si+8*2+3], 0xB2
  826.         mov     cx, 256*9
  827.         mov     ah, 0x87
  828.         int     0x15
  829.         pop     es
  830.         test    ah, ah
  831.         jnz     sayerr_floppy
  832.         add     dword [si+8*3+2], 512*9
  833. ; calculate total number of sectors to read
  834.         mov     ax, 1+9+14      ; boot+FAT+root
  835.         mov     di, 0xB203
  836. .calc_loop:
  837.         test    word [es:di], 0xFFF
  838.         jz      @f
  839.         inc     ax
  840. @@:
  841.         test    word [es:di+1], 0xFFF0
  842.         jz      @f
  843.         inc     ax
  844. @@:
  845.         add     di, 3
  846.         cmp     di, 0xB200+1440*3
  847.         jb      .calc_loop
  848.         push    ax
  849.         mov     bp, 1+9         ; already read sectors
  850. ; now read rest
  851.         mov     byte [si+8*2+3], 0xA0
  852.         mov     di, 2-14        ; absolute sector-31
  853.         mov     cx, 0x0002      ; cylinder=0, sector=2
  854.         mov     dx, 0x0100      ; head=1, disk=0
  855. .read_loop:
  856. ; determine whether sector must be read
  857.         cmp     di, 2
  858.         jl      .read
  859.         mov     bx, di
  860.         shr     bx, 1
  861.         jnc     .even
  862.         test    word [es:bx+di+0xB200], 0xFFF0
  863.         jmp     @f
  864. .even:
  865.         test    word [es:bx+di+0xB200], 0xFFF
  866. @@:
  867.         jz      .skip
  868. .read:
  869.         mov     bx, 0xA000
  870.         mov     al, 1           ; 1 sector
  871.         call    boot_read_floppy
  872.         inc     bp
  873.         push    es
  874.         push    ds
  875.         pop     es
  876.         pusha
  877.         mov     cx, 256
  878.         mov     ah, 0x87
  879.         int     0x15
  880.         test    ah, ah
  881.         popa
  882.         pop     es
  883.         jnz     sayerr_floppy
  884. .skip:
  885.         add     dword [si+8*3+2], 512
  886.         inc     cx
  887.         cmp     cl, 19
  888.         jnz     @f
  889.         mov     cl, 1
  890.         inc     dh
  891.         cmp     dh, 2
  892.         jnz     @f
  893.         mov     dh, 0
  894.         inc     ch
  895. @@:
  896.         pop     ax
  897.         push    ax
  898.         pusha
  899. ; draw percentage
  900. ; total sectors: ax
  901. ; read sectors: bp
  902.         xchg    ax, bp
  903.         mov     cx, 100
  904.         mul     cx
  905.         div     bp
  906.         aam
  907.         xchg    al, ah
  908.         add     ax, '00'
  909.         mov     si, pros
  910.         cmp     [si], ax
  911.         jz      @f
  912.         mov     [si], ax
  913.         call    printplain
  914. @@:
  915.         popa
  916.         inc     di
  917.         cmp     di, 2880-31
  918.         jnz     .read_loop
  919.  
  920. ;        mov     cx, 0x0001      ; startcyl,startsector
  921. ;        xor     dx, dx          ; starthead,drive
  922. ;        push    word 80*2               ; read no of sect
  923. ;       reads:
  924. ;        pusha
  925. ;        xor     si,si
  926. ;       newread:
  927. ;        mov     bx,0xa000               ; es:bx -> data area
  928. ;        mov     ax,0x0200+18            ; read, no of sectors to read
  929. ;        int     0x13
  930. ;        test    ah, ah
  931. ;        jz      goodread
  932. ;        inc    si
  933. ;        cmp     si,10
  934. ;        jnz     newread
  935. ;        mov     si,badsect-0x10000
  936. ;sayerr_plain:
  937. ;        call    printplain
  938. ;        jmp     $
  939. ;       goodread:
  940. ;        ; move -> 1mb
  941. ;        mov     si,movedesc-0x10000
  942. ;        push    es
  943. ;        push    ds
  944. ;        pop     es
  945. ;        mov     cx,256*18
  946. ;        mov     ah,0x87
  947. ;        int     0x15
  948. ;        pop    es
  949. ;
  950. ;        test    ah,ah                  ; was the move successfull ?
  951. ;        je      goodmove
  952. ;        mov     dx,0x3f2              ; floppy motor off
  953. ;        mov     al,0
  954. ;        out     dx,al
  955. ;        mov     si,memmovefailed-0x10000
  956. ;        jmp    sayerr_plain
  957. ;      goodmove:
  958. ;
  959. ;    add    dword [movedesc-0x10000+0x18+2], 512*18
  960. ;        popa
  961. ;        inc     dh
  962. ;        cmp     dh,2
  963. ;        jnz     bb2
  964. ;        mov     dh,0
  965. ;        inc     ch
  966. ;        pusha                        ; print prosentage
  967. ;        mov     si,pros-0x10000
  968. ;    shr    ch, 2
  969. ;    mov    al, '5'
  970. ;    test    ch, 1
  971. ;    jnz    @f
  972. ;    mov    al, '0'
  973. ;@@:
  974. ;    mov    [si+1], al
  975. ;    shr    ch, 1
  976. ;    add    ch, '0'
  977. ;    mov    [si], ch
  978. ;        call    printplain
  979. ;        popa
  980. ;       bb2:
  981. ;        pop     ax
  982. ;        dec     ax
  983. ;        push    ax
  984. ;        jnz     reads
  985. ;       readdone:
  986. ;        pop     ax
  987.  
  988. ok_sys_on_floppy:
  989.         mov     si, backspace2
  990.         call    printplain
  991.         mov     si, okt
  992.         call    printplain
  993. no_sys_on_floppy:
  994.         xor     ax, ax          ; reset drive
  995.         xor     dx, dx
  996.         int     0x13
  997.         mov     dx, 0x3f2       ; floppy motor off
  998.         mov     al, 0
  999.         out     dx, al
  1000.  
  1001.  
  1002. ; SET GRAPHICS
  1003.  
  1004.         xor     ax, ax
  1005.         mov     es, ax
  1006.  
  1007.         mov     ax, [es:0x9008]         ; vga & 320x200
  1008.         mov     bx, ax
  1009.         cmp     ax, 0x13
  1010.         je      setgr
  1011.         cmp     ax, 0x12
  1012.         je      setgr
  1013.         mov     ax, 0x4f02              ; Vesa
  1014. setgr:
  1015.         int     0x10
  1016.         test    ah, ah
  1017.         mov     si, fatalsel
  1018.         jnz     v_mode_error
  1019. ; set mode 0x12 graphics registers:
  1020.         cmp     bx, 0x12
  1021.         jne     gmok2
  1022.  
  1023.         mov     al, 0x05
  1024.         mov     dx, 0x03ce
  1025.         push    dx
  1026.         out     dx, al      ; select GDC mode register
  1027.         mov     al, 0x02
  1028.         inc     dx
  1029.         out     dx, al      ; set write mode 2
  1030.  
  1031.         mov     al, 0x02
  1032.         mov     dx, 0x03c4
  1033.         out     dx, al      ; select VGA sequencer map mask register
  1034.         mov     al, 0x0f
  1035.         inc     dx
  1036.         out     dx, al      ; set mask for all planes 0-3
  1037.  
  1038.         mov     al, 0x08
  1039.         pop     dx
  1040.         out     dx, al      ; select GDC bit mask register
  1041.                            ; for writes to 0x03cf
  1042. gmok2:
  1043.         push    ds
  1044.         pop     es
  1045.