Subversion Repositories Kolibri OS

Rev

Rev 925 | Rev 1018 | 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: 946 $
  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 6 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.         cmp     byte [di+preboot_vrrm-preboot_device], 1
  432.         adc     byte [di+preboot_vrrm-preboot_device], 0
  433. ; notify user
  434.         _setcursor 5,2
  435.  
  436.         mov     si, linef
  437.         call    printplain
  438.         mov     si, start_msg
  439.         call    print
  440.         mov     si, time_msg
  441.         call    print
  442. ; get start time
  443.         call    .gettime
  444.         mov     [.starttime], eax
  445.         mov     word [.timer], .newtimer
  446.         mov     word [.timer+2], cs
  447. .printcfg:
  448.  
  449.         _setcursor 9,0
  450.         mov     si, current_cfg_msg
  451.         call    print
  452.         mov     si, curvideo_msg
  453.         call    print
  454.  
  455.             call    draw_current_vmode
  456.  
  457.         mov     si, usebd_msg
  458.         cmp     [preboot_biosdisk], 1
  459.         call    .say_on_off
  460.         mov     si, vrrm_msg
  461.         cmp     [preboot_vrrm], 1
  462.         call    .say_on_off
  463.         mov     si, preboot_device_msg
  464.         call    print
  465.         mov     al, [preboot_device]
  466.         and     eax, 7
  467.         mov     si, [preboot_device_msgs+eax*2]
  468.         call    printplain
  469. .show_remarks:
  470. ; show remarks in gray color
  471.         mov     di, ((21-num_remarks)*80 + 2)*2
  472.         push    0xB800
  473.         pop     es
  474.         mov     cx, num_remarks
  475.         mov     si, remarks
  476. .write_remarks:
  477.         lodsw
  478.         push    si
  479.         xchg    ax, si
  480.         mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
  481.         push    di
  482. .write_remark:
  483.         lodsb
  484.         test    al, al
  485.         jz      @f
  486.         stosw
  487.         jmp     .write_remark
  488. @@:
  489.         pop     di
  490.         pop     si
  491.         add     di, 80*2
  492.         loop    .write_remarks
  493. .wait:
  494.         _setcursor 25,0         ; out of screen
  495. ; set timer interrupt handler
  496.         cli
  497.         push    0
  498.         pop     es
  499.         push    dword [es:8*4]
  500.         pop     dword [.oldtimer]
  501.         push    dword [.timer]
  502.         pop     dword [es:8*4]    
  503. ;        mov     eax, [es:8*4]
  504. ;        mov     [.oldtimer], eax
  505. ;        mov     eax, [.timer]
  506. ;        mov     [es:8*4], eax
  507.         sti
  508. ; wait for keypressed
  509.         xor     ax,ax
  510.         int     16h
  511.         push    ax
  512. ; restore timer interrupt
  513. ;        push    0
  514. ;        pop     es
  515.         mov     eax, [.oldtimer]
  516.         mov     [es:8*4], eax
  517.         mov     [.timer], eax
  518.  
  519.         _setcursor 7,0
  520.         mov     si, space_msg
  521.         call    printplain
  522. ; clear remarks and restore normal attributes
  523.         push    es
  524.         mov     di, ((21-num_remarks)*80 + 2)*2
  525.         push    0xB800
  526.         pop     es
  527.         mov     cx, num_remarks
  528.         mov     ax, ' ' + (1*16 + 15)*100h
  529. @@:
  530.         push    cx
  531.         mov     cx, 76
  532.         rep     stosw
  533.         pop     cx
  534.         add     di, 4*2
  535.         loop    @b
  536.         pop     es
  537.         pop     ax
  538. ; switch on key
  539.         cmp     al, 13
  540.         jz      .continue
  541.         or      al, 20h
  542.         cmp     al, 'a'
  543.         jz      .change_a
  544.         cmp     al, 'b'
  545.         jz      .change_b
  546.         cmp     al, 'c'
  547.         jz      .change_c
  548.         cmp     al, 'd'
  549.         jnz     .show_remarks
  550.         _setcursor 15,0
  551.         mov     si, bdev
  552.         call    print
  553.         mov     bx, '14'
  554.         call    getkey
  555.         mov     [preboot_device], al
  556.         _setcursor 13,0
  557. .d:
  558.         mov     [.bSettingsChanged], 1
  559.         call    clear_vmodes_table             ;clear vmodes_table
  560.         jmp    .printcfg
  561. .change_a:
  562. .loops:
  563.         call    draw_vmodes_table
  564.         _setcursor 25,0         ; out of screen
  565.         xor     ax,ax
  566.         int     0x16
  567. ;        call    clear_table_cursor             ;clear current position of cursor
  568.  
  569.         mov     si,word [cursor_pos]
  570.  
  571.         cmp     ah,0x48;x,0x48E0               ; up
  572.         jne     .down
  573.         cmp     si,modes_table
  574.         jbe     .loops
  575.         sub     word [cursor_pos],size_of_step
  576.         jmp     .loops
  577.  
  578. .down:  cmp     ah,0x50;x,0x50E0               ; down
  579.         jne     .pgup
  580.         cmp     word[es:si+10],-1
  581.         je      .loops        
  582.         add     word [cursor_pos],size_of_step
  583.         jmp     .loops
  584.  
  585. .pgup:  cmp     ah,0x49                 ; page up
  586.         jne     .pgdn
  587.         sub     si, size_of_step*long_v_table
  588.         cmp     si, modes_table
  589.         jae     @f
  590.         mov     si, modes_table
  591. @@:
  592.         mov     word [cursor_pos], si
  593.         mov     si, word [home_cursor]
  594.         sub     si, size_of_step*long_v_table
  595.         cmp     si, modes_table
  596.         jae     @f
  597.         mov     si, modes_table
  598. @@:
  599.         mov     word [home_cursor], si
  600.         jmp     .loops
  601.  
  602. .pgdn:  cmp     ah,0x51                 ; page down
  603.         jne     .enter
  604.         mov     ax, [end_cursor]
  605.         add     si, size_of_step*long_v_table
  606.         cmp     si, ax
  607.         jb      @f
  608.         mov     si, ax
  609.         sub     si, size_of_step
  610. @@:
  611.         mov     word [cursor_pos], si
  612.         mov     si, word [home_cursor]
  613.         sub     ax, size_of_step*long_v_table
  614.         add     si, size_of_step*long_v_table
  615.         cmp     si, ax
  616.         jb      @f
  617.         mov     si, ax
  618. @@:
  619.         mov     word [home_cursor], si
  620.         jmp     .loops
  621.  
  622. .enter: cmp     al,0x0D;x,0x1C0D               ; enter
  623.         jne     .loops
  624.         push    word [cursor_pos]
  625.         pop     bp
  626.         push    word [es:bp]
  627.         pop     word [x_save]
  628.         push    word [es:bp+2]
  629.         pop     word [y_save]
  630.         push    word [es:bp+6]
  631.         pop     word [number_vm]
  632.         mov     word [preboot_graph],bp           ;save choose
  633.        
  634.         jmp    .d
  635.  
  636. .change_b:
  637.         _setcursor 15,0
  638. ;        mov     si, ask_dma
  639. ;        call    print
  640. ;        mov     bx, '13'
  641. ;        call    getkey
  642. ;        mov     [preboot_dma], al
  643.         mov     si, ask_bd
  644.         call    print
  645.         mov     bx, '12'
  646.         call    getkey
  647.         mov     [preboot_biosdisk], al
  648.         _setcursor 11,0
  649.         jmp     .d
  650. .change_c:
  651.         _setcursor 15,0
  652.         mov     si, vrrmprint
  653.         call    print
  654.         mov     bx, '12'
  655.         call    getkey
  656.         mov     [preboot_vrrm], al
  657.         _setcursor 12,0
  658.         jmp     .d
  659. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  660. .say_on_off:
  661.         pushf
  662.         call    print
  663.         mov     si, on_msg
  664.         popf
  665.         jz      @f
  666.         mov     si, off_msg
  667. @@:     jmp     printplain
  668. ; novesa and vervesa strings are not used at the moment of executing this code
  669. virtual at novesa
  670. .oldtimer dd ?
  671. .starttime dd ?
  672. .bSettingsChanged db ?
  673. .timer dd ?
  674. end virtual
  675. .loader_block dd -1
  676. .gettime:
  677.         mov     ah, 0
  678.         int     1Ah
  679.         xchg    ax, cx
  680.         shl     eax, 10h
  681.         xchg    ax, dx
  682.         ret
  683. .newtimer:
  684.         push    ds
  685.         push    cs
  686.         pop     ds
  687.         pushf
  688.         call    [.oldtimer]
  689.         pushad
  690.         call    .gettime
  691.         sub     eax, [.starttime]
  692.         sub     ax, 18*5
  693.         jae     .timergo
  694.         neg     ax
  695.         add     ax, 18-1
  696.         mov     bx, 18
  697.         xor     dx, dx
  698.         div     bx
  699. if lang eq ru
  700. ; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
  701.         cmp     al, 5
  702.         mov     cl, ' '
  703.         jae     @f
  704.         cmp     al, 1
  705.         mov     cl, 'ã'
  706.         jz      @f
  707.         mov     cl, 'ë'
  708. @@:     mov     [time_str+9], cl
  709. else if lang eq et
  710.         cmp     al, 1
  711.         ja      @f
  712.         mov     [time_str+9], ' '
  713.         mov     [time_str+10],' '
  714. @@:
  715. else
  716. ; wait 5/4/3/2 seconds, 1 second
  717.         cmp     al, 1
  718.         mov     cl, 's'
  719.         ja      @f
  720.         mov     cl, ' '
  721. @@:     mov     [time_str+9], cl
  722. end if
  723.         add     al, '0'
  724.         mov     [time_str+1], al
  725.         mov     si, time_msg
  726.         _setcursor 7,0
  727.         call    print
  728.         _setcursor 25,0
  729.         popad
  730.         pop     ds
  731.         iret
  732. .timergo:
  733.         push    0
  734.         pop     es
  735.         mov     eax, [.oldtimer]
  736.         mov     [es:8*4], eax
  737.         mov     sp, 0EC00h
  738. .continue:
  739.         sti
  740.         _setcursor 6,0
  741.         mov     si, space_msg
  742.         call    printplain
  743.         call    printplain
  744.         _setcursor 6,0
  745.         mov     si, loading_msg
  746.         call    print
  747.         _setcursor 15,0
  748.         cmp     [.bSettingsChanged], 0
  749.         jz      .load
  750.         cmp     [.loader_block], -1
  751.         jz      .load
  752.         les     bx, [.loader_block]
  753.         mov     eax, [es:bx+3]
  754.         push    ds
  755.         pop     es
  756.         test    eax, eax
  757.         jz      .load
  758.         push    eax
  759.         mov     si, save_quest
  760.         call    print
  761. .waityn:
  762.         mov     ah, 0
  763.         int     16h
  764.         or      al, 20h
  765.         cmp     al, 'n'
  766.         jz      .loadc
  767.         cmp     al, 'y'
  768.         jnz     .waityn
  769.         call    putchar
  770.         mov     byte [space_msg+80], 186
  771.  
  772.         pop     eax
  773.         push    cs
  774.         push    .cont
  775.         push    eax
  776.         retf                          ;call back
  777. .loadc:
  778.         pop     eax
  779. .cont:
  780.         push    cs
  781.         pop     ds
  782.         mov     si, space_msg
  783.         mov     byte [si+80], 0
  784.         _setcursor 15,0
  785.         call    printplain
  786.         _setcursor 15,0
  787. .load:
  788. ; \end{diamond}[02.12.2005]
  789.  
  790. ; ASK GRAPHICS MODE
  791.  
  792.         call    set_vmode
  793.  
  794. ; GRAPHICS ACCELERATION
  795. ; force yes
  796.         mov     [es:0x901C], byte 1
  797.  
  798. ; DMA ACCESS TO HD
  799.  
  800.         mov     al, [preboot_dma]
  801.         mov     [es:0x901F], al
  802.  
  803. ; VRR_M USE
  804.  
  805.         mov     al,[preboot_vrrm]
  806.         mov     [es:0x9030], al
  807.         mov     [es:0x901E], byte 1
  808.  
  809. ; BOOT DEVICE
  810.  
  811.         mov     al, [preboot_device]
  812.         dec     al
  813.         mov     [boot_dev], al
  814.  
  815. ; READ DISKETTE TO MEMORY
  816.  
  817. ;        cmp     [boot_dev],0
  818.         jne     no_sys_on_floppy
  819.         mov     si,diskload
  820.         call    print
  821.         xor     ax, ax            ; reset drive
  822.         xor     dx, dx
  823.         int     0x13
  824. ; do we boot from CD-ROM?
  825.         mov     ah, 41h
  826.         mov     bx, 55AAh
  827.         xor     dx, dx
  828.         int     0x13
  829.         jc      .nocd
  830.         cmp     bx, 0AA55h
  831.         jnz     .nocd
  832.         mov     ah, 48h
  833.         push    ds
  834.         push    es
  835.         pop     ds
  836.         mov     si, 0xa000
  837.         mov     word [si], 30
  838.         int     0x13
  839.         pop     ds
  840.         jc      .nocd
  841.         push    ds
  842.         lds     si, [es:si+26]
  843.         test    byte [ds:si+10], 40h
  844.         pop     ds
  845.         jz      .nocd
  846. ; yes - read all floppy by 18 sectors
  847.  
  848. ; TODO: !!!! read only first sector and set variables !!!!!
  849. ; ...
  850. ; TODO: !!! then read flippy image track by track
  851.        
  852.         mov     cx, 0x0001      ; startcyl,startsector
  853. .a1:
  854.         push    cx dx
  855.         mov     al, 18
  856.         mov     bx, 0xa000
  857.         call    boot_read_floppy
  858.         mov     si, movedesc
  859.         push    es
  860.         push    ds
  861.         pop     es
  862.         mov     cx, 256*18
  863.         mov     ah, 0x87
  864.         int     0x15
  865.         pop     es
  866.         pop     dx cx
  867.         test    ah, ah
  868.         jnz     sayerr_floppy
  869.         add     dword [si+8*3+2], 512*18
  870.         inc     dh
  871.         cmp     dh, 2
  872.         jnz     .a1
  873.         mov     dh, 0
  874.         inc     ch
  875.         cmp     ch, 80
  876.         jae     ok_sys_on_floppy
  877.         pusha
  878.         mov     al, ch
  879.         shr     ch, 2
  880.         add     al, ch
  881.         aam
  882.         xchg    al, ah
  883.         add     ax, '00'
  884.         mov     si, pros
  885.         mov     [si], ax
  886.         call    printplain
  887.         popa
  888.         jmp     .a1
  889. .nocd:
  890. ; no - read only used sectors from floppy
  891. ; now load floppy image to memory
  892. ; at first load boot sector and first FAT table
  893.  
  894. ; read only first sector and fill variables
  895.         mov     cx, 0x0001      ; first logical sector
  896.         xor     dx, dx          ; head = 0, drive = 0 (a:)
  897.         mov     al, 1           ; read one sector
  898.         mov     bx, 0xB000      ; es:bx -> data area
  899.         call    boot_read_floppy
  900. ; fill the necessary parameters to work with a floppy
  901.         mov     ax, word [es:bx+24]
  902.         mov     word [BPB_SecPerTrk], ax
  903.         mov     ax, word [es:bx+26]
  904.         mov     word [BPB_NumHeads], ax
  905.         mov     ax, word [es:bx+17]
  906.         mov     word [BPB_RootEntCnt], ax
  907.         mov     ax, word [es:bx+14]
  908.         mov     word [BPB_RsvdSecCnt], ax
  909.         mov     ax, word [es:bx+19]
  910.         mov     word [BPB_TotSec16], ax
  911.         mov     al, byte [es:bx+13]
  912.         mov     byte [BPB_SecPerClus], al
  913.         mov     al, byte [es:bx+16]
  914.         mov     byte [BPB_NumFATs], al
  915. ;<Lrz> 18.11.2008
  916.         mov     ax, word [es:bx+22]
  917.         mov     word [BPB_FATSz16], ax
  918.         mov     cx, word [es:bx+11]
  919.         mov     word [BPB_BytsPerSec], cx
  920.  
  921. ; count of clusters in FAT12 ((size_of_FAT*2)/3)
  922. ;        mov     ax, word [BPB_FATSz16]
  923. ;        mov     cx, word [BPB_BytsPerSec]
  924. ;end <Lrz> 18.11.2008
  925.         xor     dx, dx
  926.         mul     cx
  927.         shl     ax, 1
  928.         mov     cx, 3
  929.         div     cx              ; now ax - number of clusters in FAT12
  930.         mov     word [end_of_FAT], ax
  931.  
  932. ; load first FAT table
  933.         mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
  934.         xor     dx, dx          ; starthead,drive
  935.         mov     al, byte [BPB_FATSz16]     ; no of sectors to read
  936.         add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
  937.         call    boot_read_floppy
  938.         mov     bx, 0xB000
  939.  
  940. ; and copy them to extended memory
  941.         mov     si, movedesc
  942.         mov     [si+8*2+3], bh          ; from
  943.        
  944.         mov     ax, word [BPB_BytsPerSec]
  945.         shr     ax, 1                   ; words per sector
  946.         mov     cx, word [BPB_RsvdSecCnt]
  947.         add     cx, word [BPB_FATSz16]
  948.         mul     cx
  949.         push    ax                      ; save to stack count of words in boot+FAT
  950.         xchg    ax, cx
  951.        
  952.         push    es
  953.         push    ds
  954.         pop     es
  955.         mov     ah, 0x87
  956.         int     0x15
  957.         pop     es
  958.         test    ah, ah
  959.         jz      @f
  960. sayerr_floppy:
  961.         mov     dx, 0x3f2
  962.         mov     al, 0
  963.         out     dx, al
  964.         mov     si, memmovefailed
  965.         jmp     sayerr_plain
  966. @@:
  967.         pop     ax                      ; restore from stack count of words in boot+FAT
  968.         shl     ax, 1                   ; make bytes count from count of words
  969.         and     eax, 0ffffh
  970.         add     dword [si+8*3+2], eax
  971.  
  972. ; copy first FAT to second copy
  973. ; TODO: BPB_NumFATs !!!!!
  974.         add     bx, word [BPB_BytsPerSec]       ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
  975.         mov     byte [si+8*2+3], bh     ; bx - begin of FAT
  976.        
  977.         mov     ax, word [BPB_BytsPerSec]
  978.         shr     ax, 1                   ; words per sector
  979.         mov     cx, word [BPB_FATSz16]
  980.         mul     cx
  981.         mov     cx, ax                  ; cx - count of words in FAT
  982.  
  983.         push    es
  984.         push    ds
  985.         pop     es
  986.         mov     ah, 0x87
  987.         int     0x15
  988.         pop     es
  989.         test    ah, ah
  990.         jnz     sayerr_floppy
  991.        
  992.         mov     ax, cx
  993.         shl     ax, 1
  994.         and     eax, 0ffffh             ; ax - count of bytes in FAT
  995.         add     dword [si+8*3+2], eax
  996.        
  997. ; reading RootDir
  998. ; TODO: BPB_NumFATs
  999.         add     bx, ax
  1000.         add     bx, 100h
  1001.         and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
  1002.         push    bx
  1003.  
  1004.         mov     bx, word [BPB_BytsPerSec]
  1005.         shr     bx, 5                           ; divide bx by 32
  1006.         mov     ax, word [BPB_RootEntCnt]
  1007.         xor     dx, dx
  1008.         div     bx
  1009.         push    ax                              ; ax - count of RootDir sectors
  1010.  
  1011.         mov     ax, word [BPB_FATSz16]
  1012.         xor     cx, cx
  1013.         mov     cl, byte [BPB_NumFATs]
  1014.         mul     cx
  1015.         add     ax, word [BPB_RsvdSecCnt]       ; ax - first sector of RootDir
  1016.  
  1017.         mov     word [FirstDataSector], ax
  1018.         pop     bx
  1019.         push    bx
  1020.         add     word [FirstDataSector], bx      ; Begin of data region of floppy
  1021.        
  1022. ; read RootDir
  1023.         call    conv_abs_to_THS
  1024.         pop     ax
  1025.         pop     bx                              ; place in buffer to write
  1026.         push    ax
  1027.         call    boot_read_floppy                ; read RootDir into buffer
  1028. ; copy RootDir
  1029.         mov     byte [si+8*2+3], bh             ; from buffer
  1030.         pop     ax                              ; ax = count of RootDir sectors
  1031.         mov     cx, word [BPB_BytsPerSec]
  1032.         mul     cx
  1033.         shr     ax, 1
  1034.         mov     cx, ax                          ; count of words to copy
  1035.         push    es
  1036.         push    ds
  1037.         pop     es
  1038.         mov     ah, 0x87
  1039.         int     0x15
  1040.         pop     es
  1041.  
  1042.         mov     ax, cx
  1043.         shl     ax, 1
  1044.         and     eax, 0ffffh             ; ax - count of bytes in RootDir
  1045.         add     dword [si+8*3+2], eax   ; add count of bytes copied
  1046.  
  1047. ; Reading data clusters from floppy
  1048.         mov     byte [si+8*2+3], bh
  1049.         push    bx
  1050.  
  1051.         mov     di, 2                   ; First data cluster
  1052. .read_loop:
  1053.         mov     bx, di
  1054.         shr     bx, 1                   ; bx+di = di*1.5
  1055.         jnc     .even
  1056.         test    word [es:bx+di+0xB200], 0xFFF0  ; TODO: may not be 0xB200 !!!
  1057.         jmp     @f
  1058. .even:
  1059.         test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
  1060.  
  1061. @@:
  1062.         jz      .skip
  1063. ; read cluster di
  1064. ;.read:
  1065.         ;conv cluster di to abs. sector ax
  1066.         ; ax = (N-2) * BPB_SecPerClus + FirstDataSector
  1067.         mov     ax, di
  1068.         sub     ax, 2
  1069.         xor     bx, bx
  1070.         mov     bl, byte [BPB_SecPerClus]
  1071.         mul     bx
  1072.         add     ax, word [FirstDataSector]
  1073.         call    conv_abs_to_THS
  1074.         pop     bx
  1075.         push    bx
  1076.         mov     al, byte [BPB_SecPerClus]       ; number of sectors in cluster
  1077.         call    boot_read_floppy
  1078.         push    es
  1079.         push    ds
  1080.         pop     es
  1081.         pusha
  1082. ;
  1083.         mov     ax, word [BPB_BytsPerSec]
  1084.         xor     cx, cx
  1085.         mov     cl, byte [BPB_SecPerClus]
  1086.         mul     cx
  1087.         shr     ax, 1                           ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
  1088.         mov     cx, ax                          ; number of words to copy (count words in cluster)
  1089. ;
  1090.         mov     ah, 0x87
  1091.         int     0x15                            ; copy data
  1092.         test    ah, ah
  1093.         popa
  1094.         pop     es
  1095.         jnz     sayerr_floppy
  1096. ; skip cluster di
  1097. .skip:
  1098.         mov     ax, word [BPB_BytsPerSec]
  1099.         xor     cx, cx
  1100.         mov     cl, byte [BPB_SecPerClus]
  1101.         mul     cx
  1102.         and     eax, 0ffffh             ; ax - count of bytes in cluster
  1103.         add     dword [si+8*3+2], eax
  1104.  
  1105.         mov     ax, word [end_of_FAT]   ; max cluster number
  1106.         pusha
  1107. ; draw percentage
  1108. ; total clusters: ax
  1109. ; read clusters: di
  1110.         xchg    ax, di
  1111.         mov     cx, 100
  1112.         mul     cx
  1113.         div     di
  1114.         aam
  1115.         xchg    al, ah
  1116.         add     ax, '00'
  1117.         mov     si, pros
  1118.         cmp     [si], ax
  1119.         jz      @f
  1120.         mov     [si], ax
  1121.         call    printplain
  1122. @@:
  1123.         popa
  1124.         inc     di
  1125.         cmp     di, word [end_of_FAT]   ; max number of cluster
  1126.         jnz     .read_loop
  1127.         pop     bx                      ; clear stack
  1128.  
  1129. ok_sys_on_floppy:
  1130.         mov     si, backspace2
  1131.         call    printplain
  1132.         mov     si, okt
  1133.         call    printplain
  1134. no_sys_on_floppy:
  1135.         xor     ax, ax          ; reset drive
  1136.         xor     dx, dx
  1137.         int     0x13
  1138.         mov     dx, 0x3f2       ; floppy motor off
  1139.         mov     al, 0
  1140.         out     dx, al
  1141.  
  1142.  
  1143. ; SET GRAPHICS
  1144.  
  1145.         xor     ax, ax
  1146.         mov     es, ax
  1147.  
  1148.         mov     ax, [es:0x9008]         ; vga & 320x200
  1149.         mov     bx, ax
  1150.         cmp     ax, 0x13
  1151.         je      setgr
  1152.         cmp     ax, 0x12
  1153.         je      setgr
  1154.         mov     ax, 0x4f02              ; Vesa
  1155. setgr:
  1156.         int     0x10
  1157.         test    ah, ah
  1158.         mov     si, fatalsel
  1159.         jnz     v_mode_error
  1160. ; set mode 0x12 graphics registers:
  1161.         cmp     bx, 0x12
  1162.         jne     gmok2
  1163.  
  1164.         mov     al, 0x05
  1165.         mov     dx, 0x03ce
  1166.         push    dx
  1167.         out     dx, al      ; select GDC mode register
  1168.         mov     al, 0x02
  1169.         inc     dx
  1170.         out     dx, al      ; set write mode 2
  1171.  
  1172.         mov     al, 0x02
  1173.         mov     dx, 0x03c4
  1174.         out     dx, al      ; select VGA sequencer map mask register
  1175.         mov     al, 0x0f
  1176.         inc     dx
  1177.         out     dx, al      ; set mask for all planes 0-3
  1178.  
  1179.         mov     al, 0x08
  1180.         pop     dx
  1181.         out     dx, al      ; select GDC bit mask register
  1182.                            ; for writes to 0x03cf
  1183. gmok2:
  1184.         push    ds
  1185.         pop     es
  1186.