Subversion Repositories Kolibri OS

Rev

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