Subversion Repositories Kolibri OS

Rev

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