Subversion Repositories Kolibri OS

Rev

Rev 3711 | Rev 3760 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2011. 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: 3712 $
  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.         test    al, al
  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. sayerr_badsect:
  95.         mov     si, badsect
  96. sayerr_plain:
  97.         call    printplain
  98.         jmp     $
  99. @@:
  100.         pop     si
  101.         ret
  102.  
  103. ; convert abs. sector number (AX) to BIOS T:H:S
  104. ; sector number = (abs.sector%BPB_SecPerTrk)+1
  105. ; pre.track number = (abs.sector/BPB_SecPerTrk)
  106. ; head number = pre.track number%BPB_NumHeads
  107. ; track number = pre.track number/BPB_NumHeads
  108. ; Return: cl - sector number
  109. ;         ch - track number
  110. ;         dl - drive number (0 = a:)
  111. ;         dh - head number
  112. conv_abs_to_THS:
  113.         push    bx
  114.         mov     bx, word [BPB_SecPerTrk]
  115.         xor     dx, dx
  116.         div     bx
  117.         inc     dx
  118.         mov     cl, dl                          ; cl = sector number
  119.         mov     bx, word [BPB_NumHeads]
  120.         xor     dx, dx
  121.         div     bx
  122.         ; !!!!!!! ax = track number, dx = head number
  123.         mov     ch, al                          ; ch=track number
  124.         xchg    dh, dl                          ; dh=head number
  125.         mov     dl, 0                           ; dl=0 (drive 0 (a:))
  126.         pop     bx
  127.         retn
  128. ; needed variables
  129. BPB_SecPerTrk   dw      0                       ; sectors per track
  130. BPB_NumHeads    dw      0                       ; number of heads
  131. BPB_FATSz16     dw      0                       ; size of FAT
  132. BPB_RootEntCnt  dw      0                       ; count of root dir. entries
  133. BPB_BytsPerSec  dw      0                       ; bytes per sector
  134. BPB_RsvdSecCnt  dw      0                       ; number of reserved sectors
  135. BPB_TotSec16    dw      0                       ; count of the sectors on the volume
  136. BPB_SecPerClus  db      0                       ; number of sectors per cluster
  137. BPB_NumFATs     db      0                       ; number of FAT tables
  138. abs_sector_adj  dw      0                       ; adjustment to make abs. sector number
  139. end_of_FAT      dw      0                       ; end of FAT table
  140. FirstDataSector dw      0                       ; begin of data
  141.  
  142. ;=========================================================================
  143. ;
  144. ;                           16 BIT CODE
  145. ;
  146. ;=========================================================================
  147.  
  148. include 'bootvesa.inc'                 ;Include source for boot vesa
  149. if defined extended_primary_loader
  150. include 'parsers.inc'
  151. end if
  152.  
  153. start_of_code:
  154.  
  155. if defined extended_primary_loader
  156. ; save data from primary loader
  157.         mov     word [cs:bootcallback], si
  158.         mov     word [cs:bootcallback+2], ds
  159.         push    cs
  160.         pop     ds
  161.         mov     [bootdevice], ax
  162.         mov     [bootfs], bx
  163.  
  164. ; set up stack
  165.         mov     ax, 3000h
  166.         mov     ss, ax
  167.         mov     sp, 0EC00h
  168.  
  169. ; try to load configuration file
  170.         mov     ax, 1
  171.         mov     di, config_file_struct
  172.         call    [bootcallback]
  173.         cld
  174.         push    cs
  175.         pop     es
  176. ; bx=0 - ok, bx=1 - part of file loaded, assume this is ok
  177.         cmp     bx, 1
  178.         ja      .config_bad
  179. ; configuration file was loaded, parse
  180. ; if length is too big, use first 0FFFFh bytes
  181.         test    dx, dx
  182.         jz      @f
  183.         mov     ax, 0FFFFh
  184. @@:
  185. ; ds:si will be pointer to current data, dx = limit
  186.         xchg    ax, dx
  187.         push    4000h
  188.         pop     ds
  189.         xor     si, si
  190. .parse_loop:
  191. ; skip spaces
  192.         cmp     si, dx
  193.         jae     .parse_done
  194.         lodsb
  195.         cmp     al, ' '
  196.         jbe     .parse_loop
  197.         dec     si
  198. ; loop over all possible configuration values
  199.         mov     bx, config_file_variables
  200. .find_variant:
  201. ; get length
  202.         mov     cx, [es:bx]
  203. ; zero length = end of list
  204.         jecxz   .find_newline
  205. ; skip over length
  206.         inc     bx
  207.         inc     bx
  208.         mov     di, bx
  209. ; skip over string
  210.         add     bx, cx
  211. ; test whether we have at least cx symbols left
  212.         mov     ax, cx
  213.         add     ax, si
  214.         jc      .next_variant1
  215.         cmp     ax, dx
  216.         jae     .next_variant1
  217. ; save current position
  218.         push    si
  219. ; compare strings
  220.         repz cmpsb
  221.         jnz     .next_variant2
  222. ; strings are equal; look for "=" with possible spaces before and after
  223. @@:
  224.         cmp     si, dx
  225.         jae     .next_variant2
  226.         lodsb
  227.         cmp     al, ' '
  228.         jbe     @b
  229.         cmp     al, '='
  230.         jnz     .next_variant2
  231. ; ok, we found the true variant
  232. ; ignore saved position on the stack
  233.         pop     ax
  234. ; call the parser
  235.         call    word [es:bx]
  236. ; line parsed, find next
  237. .find_newline:
  238.         cmp     si, dx
  239.         jae     .parse_done
  240.         lodsb
  241.         cmp     al, 13
  242.         jz      .parse_loop
  243.         cmp     al, 10
  244.         jz      .parse_loop
  245.         jmp     .find_newline
  246. .next_variant2:
  247. ; continue to the next variant, restoring current position
  248.         pop     si
  249. .next_variant1:
  250. ; continue to the next variant
  251. ; skip over the parser
  252.         inc     bx
  253.         inc     bx
  254.         jmp     .find_variant
  255. .parse_done:
  256. .config_bad:
  257.  
  258. ; set up segment registers
  259.         push    cs
  260.         pop     ds
  261. else
  262.         cld
  263. ; \begin{diamond}[02.12.2005]
  264. ; if bootloader sets ax = 'KL', then ds:si points to loader block
  265.         cmp     ax, 'KL'
  266.         jnz     @f
  267.         mov     word [cs:cfgmanager.loader_block], si
  268.         mov     word [cs:cfgmanager.loader_block+2], ds
  269. @@:
  270. ; \end{diamond}[02.12.2005]
  271.  
  272. ; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source hard disk
  273. ; (see comment to bx_from_load)
  274.         cmp     cx, 'HA'
  275.         jnz     no_hd_load
  276.         cmp     dx, 'RD'
  277.         jnz     no_hd_load
  278.         mov     word [cs:bx_from_load], bx              ; {SPraid}[13.03.2007]
  279. no_hd_load:
  280.  
  281. ; set up stack
  282.         mov     ax, 3000h
  283.         mov     ss, ax
  284.         mov     sp, 0EC00h
  285. ; set up segment registers
  286.         push    cs
  287.         pop     ds
  288.         push    cs
  289.         pop     es
  290. end if
  291.  
  292. ; set videomode
  293.         mov     ax, 3
  294.         int     0x10
  295.  
  296. if lang eq ru
  297.  ; Load & set russian VGA font (RU.INC)
  298.         mov     bp, RU_FNT1             ; RU_FNT1 - First part
  299.         mov     bx, 1000h               ; 768 bytes
  300.         mov     cx, 30h                 ; 48 symbols
  301.         mov     dx, 80h                 ; 128 - position of first symbol
  302.         mov     ax, 1100h
  303.         int     10h
  304.  
  305.         mov     bp, RU_FNT2             ; RU_FNT2 -Second part
  306.         mov     bx, 1000h               ; 512 bytes
  307.         mov     cx, 20h                 ; 32 symbols
  308.         mov     dx, 0E0h                ; 224 - position of first symbol
  309.         mov     ax, 1100h
  310.         int     10h
  311.  ; End set VGA russian font
  312. else if lang eq et
  313.         mov     bp, ET_FNT              ; ET_FNT1
  314.         mov     bx, 1000h               ;
  315.         mov     cx, 255                 ; 256 symbols
  316.         xor     dx, dx                  ; 0 - position of first symbol
  317.         mov     ax, 1100h
  318.         int     10h
  319. end if
  320.  
  321. ; draw frames
  322.         push    0xb800
  323.         pop     es
  324.         xor     di, di
  325.         mov     ah, 1*16+15
  326.  
  327. ; draw top
  328.         mov     si, d80x25_top
  329.         mov     cx, d80x25_top_num * 80
  330. @@:
  331.         lodsb
  332.         stosw
  333.         loop    @b
  334. ; draw spaces
  335.         mov     si, space_msg
  336.         mov     dx, 25 - d80x25_top_num - d80x25_bottom_num
  337. dfl1:
  338.         push    si
  339.         mov     cx, 80
  340. @@:
  341.         lodsb
  342.         stosw
  343.         loop    @b
  344.         pop     si
  345.         dec     dx
  346.         jnz     dfl1
  347. ; draw bottom
  348.         mov     si, d80x25_bottom
  349.         mov     cx, d80x25_bottom_num * 80
  350. @@:
  351.         lodsb
  352.         stosw
  353.         loop    @b
  354.  
  355.         mov     byte [space_msg+80], 0    ; now space_msg is null terminated
  356.  
  357.         _setcursor d80x25_top_num,0
  358.  
  359.  
  360. ; TEST FOR 386+
  361.  
  362.         mov     bx, 0x4000
  363.         pushf
  364.         pop     ax
  365.         mov     dx, ax
  366.         xor     ax, bx
  367.         push    ax
  368.         popf
  369.         pushf
  370.         pop     ax
  371.         and     ax, bx
  372.         and     dx, bx
  373.         cmp     ax, dx
  374.         jnz     cpugood
  375.         mov     si, not386
  376. sayerr:
  377.         call    print
  378.         jmp     $
  379.      cpugood:
  380.  
  381.         push    0
  382.         popf
  383.         sti
  384.  
  385. ; set up esp
  386.         movzx   esp, sp
  387.  
  388.         push    0
  389.         pop     es
  390.         xor     ax, ax
  391.         and     word [es:BOOT_IDE_BASE_ADDR], ax        ;0
  392.         and     word [es:BOOT_IDE_BAR0_16], ax  ;0
  393.         and     word [es:BOOT_IDE_BAR1_16], ax  ;0
  394.         and     word [es:BOOT_IDE_BAR2_16], ax  ;0
  395.         and     word [es:BOOT_IDE_BAR3_16], ax  ;0
  396. ; \begin{Mario79}
  397. ; find HDD IDE DMA PCI device
  398. ; check for PCI BIOS
  399.         mov     ax, 0xB101
  400.         int     0x1A
  401.         jc      .nopci
  402.         cmp     edx, 'PCI '
  403.         jnz     .nopci
  404. ; find PCI class code
  405. ; class 1 = mass storage
  406. ; subclass 1 = IDE controller
  407. ; a) class 1, subclass 1, programming interface 0x80
  408. ; This is a Parallel IDE Controller which uses IRQs 14 and 15.
  409.         mov     ax, 0xB103
  410.         mov     ecx, 1*10000h + 1*100h + 0x80
  411.         mov     [es:BOOT_IDE_PI_16], cx
  412.         xor     si, si  ; device index = 0
  413.         int     0x1A
  414.         jnc     .found_1 ; Parallel IDE Controller
  415. ; b) class 1, subclass 1, programming interface 0x8f
  416.         mov     ax, 0xB103
  417.         mov     ecx, 1*10000h + 1*100h + 0x8f
  418.         mov     [es:BOOT_IDE_PI_16], cx
  419.         xor     si, si  ; device index = 0
  420.         int     0x1A
  421.         jnc     .found
  422. ; c) class 1, subclass 1, programming interface 0x85
  423.         mov     ax, 0xB103
  424.         mov     ecx, 1*10000h + 1*100h + 0x85
  425.         mov     [es:BOOT_IDE_PI_16], cx
  426.         xor     si, si  ; device index = 0
  427.         int     0x1A
  428.         jnc     .found
  429. ; d) class 1, subclass 1, programming interface 0x8A
  430. ; This is a Parallel IDE Controller which uses IRQs 14 and 15.
  431.         mov     ax, 0xB103
  432.         mov     ecx, 1*10000h + 1*100h + 0x8A
  433.         mov     [es:BOOT_IDE_PI_16], cx
  434.         xor     si, si  ; device index = 0
  435.         int     0x1A
  436.         jnc     .found_1 ; Parallel IDE Controller
  437.  
  438.         jmp     .nopci
  439. .found_1:
  440. ; get memory base BAR4
  441.         mov     ax, 0xB10A
  442.         mov     di, 0x20        ; memory base is config register at 0x20
  443.         push    cx
  444.         int     0x1A
  445.         jc      .no_BAR4        ;.nopci
  446.         and     cx, 0xFFF0      ; clear address decode type
  447.         mov     [es:BOOT_IDE_BASE_ADDR], cx
  448. .no_BAR4:
  449.         pop     cx
  450. .found:
  451. ; get memory base BAR0
  452.         mov     ax, 0xB10A
  453.         mov     di, 0x10        ; memory base is config register at 0x10
  454.         push    cx
  455.         int     0x1A
  456.         jc      .no_BAR0        ;.nopci
  457.         mov     [es:BOOT_IDE_BAR0_16], cx
  458. .no_BAR0:
  459.         pop     cx
  460. ; get memory base BAR1
  461.         mov     ax, 0xB10A
  462.         mov     di, 0x14        ; memory base is config register at 0x14
  463.         push    cx
  464.         int     0x1A
  465.         jc      .no_BAR1        ;.nopci
  466.         mov     [es:BOOT_IDE_BAR1_16], cx
  467. .no_BAR1:
  468.         pop     cx
  469. ; get memory base BAR2
  470.         mov     ax, 0xB10A
  471.         mov     di, 0x18        ; memory base is config register at 0x18
  472.         push    cx
  473.         int     0x1A
  474.         jc      .no_BAR2        ;.nopci
  475.         mov     [es:BOOT_IDE_BAR2_16], cx
  476. .no_BAR2:
  477.         pop     cx
  478. ; get memory base BAR3
  479.         mov     ax, 0xB10A
  480.         mov     di, 0x1C        ; memory base is config register at 0x1c
  481.         push    cx
  482.         int     0x1A
  483.         jc      .no_BAR3        ;.nopci
  484.         mov     [es:BOOT_IDE_BAR3_16], cx
  485. .no_BAR3:
  486.         pop     cx
  487. .nopci:
  488. ; \end{Mario79}
  489.  
  490.         mov     al, 0xf6        ; Сброс клавиатуры, разрешить сканирование
  491.         out     0x60, al
  492.         xor     cx, cx
  493. wait_loop:       ; variant 2
  494. ; reading state of port of 8042 controller
  495.         in      al, 64h
  496.         and     al, 00000010b  ; ready flag
  497. ; wait until 8042 controller is ready
  498.         loopnz  wait_loop
  499.  
  500. ;;;/diamond today   5.02.2008
  501. ; set keyboard typematic rate & delay
  502.         mov     al, 0xf3
  503.         out     0x60, al
  504.         xor     cx, cx
  505. @@:
  506.         in      al, 64h
  507.         test    al, 2
  508.         loopnz  @b
  509.         mov     al, 0
  510.         out     0x60, al
  511.         xor     cx, cx
  512. @@:
  513.         in      al, 64h
  514.         test    al, 2
  515.         loopnz  @b
  516. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  517. ; --------------- APM ---------------------
  518.         and     word [es:BOOT_APM_VERSION], 0     ; ver = 0.0 (APM not found)
  519.         mov     ax, 0x5300
  520.         xor     bx, bx
  521.         int     0x15
  522.         jc      apm_end                 ; APM not found
  523.         test    cx, 2
  524.         jz      apm_end                 ; APM 32-bit protected-mode interface not supported
  525.         mov     [es:BOOT_APM_VERSION], ax         ; Save APM Version
  526.         mov     [es:BOOT_APM_FLAGS], cx           ; Save APM flags
  527.  
  528.         ; Write APM ver ----
  529.         and     ax, 0xf0f
  530.         add     ax, '00'
  531.         mov     si, msg_apm
  532.         mov     [si + 5], ah
  533.         mov     [si + 7], al
  534.         _setcursor 0, 3
  535.         call    printplain
  536.         ; ------------------
  537.  
  538.         mov     ax, 0x5304              ; Disconnect interface
  539.         xor     bx, bx
  540.         int     0x15
  541.         mov     ax, 0x5303              ; Connect 32 bit mode interface
  542.         xor     bx, bx
  543.         int     0x15
  544.  
  545.         mov     [es:BOOT_APM_ENTRY], ebx
  546.         mov     [es:BOOT_APM_CODE_32], ax
  547.         mov     [es:BOOT_APM_CODE_16], cx
  548.         mov     [es:BOOT_APM_DATA_16], dx
  549.  
  550. apm_end:
  551.         _setcursor d80x25_top_num, 0
  552.  
  553. if ~ defined extended_primary_loader
  554. ;CHECK current of code
  555.         cmp     [cfgmanager.loader_block], -1
  556.         jz      noloaderblock
  557.         les     bx, [cfgmanager.loader_block]
  558.         cmp     byte [es:bx], 1
  559.         mov     si, loader_block_error
  560.         jnz     sayerr
  561.         push    0
  562.         pop     es
  563. end if
  564.  
  565. noloaderblock:
  566. ; DISPLAY VESA INFORMATION
  567.         call    print_vesa_info
  568.         call    calc_vmodes_table
  569.         call    check_first_parm   ;check and enable cursor_pos
  570.  
  571. ; \begin{diamond}[30.11.2005]
  572. cfgmanager:
  573. ; settings:
  574. ; a) preboot_graph = graphical mode
  575. ;    preboot_gprobe = probe this mode?
  576. ; b) preboot_dma  = use DMA access?
  577. ; c) preboot_vrrm = use VRR?
  578. ; d) preboot_device = from what boot?
  579.  
  580. ; determine default settings
  581. if ~ defined extended_primary_loader
  582.         mov     [.bSettingsChanged], 0
  583. end if
  584.  
  585. ;.preboot_gr_end:
  586.         mov     di, preboot_device
  587. ; if image in memory is present and [preboot_device] is uninitialized,
  588. ; set it to use this preloaded image
  589.         cmp     byte [di], 0
  590.         jnz     .preboot_device_inited
  591. if defined extended_primary_loader
  592.         inc     byte [di]
  593.         cmp     byte [bootdevice], 'f' ; floppy?
  594.         jz      .preboot_device_inited
  595.         inc     byte [di]
  596. else
  597.         cmp     [.loader_block], -1
  598.         jz      @f
  599.         les     bx, [.loader_block]
  600.         test    byte [es:bx+1], 1
  601.         jz      @f
  602.         mov     byte [di], 3
  603.         jmp     .preboot_device_inited
  604. @@:
  605. ; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
  606.         mov     byte [di], 1
  607. end if
  608. .preboot_device_inited:
  609. ; following 4 lines set variables to 1 if its current value is 0
  610.         cmp     byte [di+preboot_dma-preboot_device], 1
  611.         adc     byte [di+preboot_dma-preboot_device], 0
  612. ;        cmp     byte [di+preboot_biosdisk-preboot_device], 1
  613. ;        adc     byte [di+preboot_biosdisk-preboot_device], 0
  614. ;; default value for VRR is OFF
  615. ;        cmp     byte [di+preboot_vrrm-preboot_device], 0
  616. ;        jnz    @f
  617. ;        mov    byte [di+preboot_vrrm-preboot_device], 2
  618. ;@@:
  619. ; notify user
  620.         _setcursor 5,2
  621.  
  622.         mov     si, linef
  623.         call    printplain
  624.         mov     si, start_msg
  625.         call    print
  626.         mov     si, time_msg
  627.         call    print
  628. ; get start time
  629.         call    .gettime
  630.         mov     [.starttime], eax
  631.         mov     word [.timer], .newtimer
  632.         mov     word [.timer+2], cs
  633. .printcfg:
  634.  
  635.         _setcursor 9,0
  636.         mov     si, current_cfg_msg
  637.         call    print
  638.         mov     si, curvideo_msg
  639.         call    print
  640.  
  641.         call    draw_current_vmode
  642.  
  643.         mov     si, usebd_msg
  644.         cmp     [preboot_biosdisk], 1
  645.         call    .say_on_off
  646. ;        mov     si, vrrm_msg
  647. ;        cmp     [preboot_vrrm], 1
  648. ;        call    .say_on_off
  649.         mov     si, preboot_device_msg
  650.         call    print
  651.         mov     al, [preboot_device]
  652. if defined extended_primary_loader
  653.         and     eax, 3
  654. else
  655.         and     eax, 7
  656. end if
  657.         mov     si, [preboot_device_msgs+eax*2]
  658.         call    printplain
  659. .show_remarks:
  660. ; show remarks in gray color
  661.         mov     di, ((21-num_remarks)*80 + 2)*2
  662.         push    0xB800
  663.         pop     es
  664.         mov     cx, num_remarks
  665.         mov     si, remarks
  666. .write_remarks:
  667.         lodsw
  668.         push    si
  669.         xchg    ax, si
  670.         mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
  671.         push    di
  672. .write_remark:
  673.         lodsb
  674.         test    al, al
  675.         jz      @f
  676.         stosw
  677.         jmp     .write_remark
  678. @@:
  679.         pop     di
  680.         pop     si
  681.         add     di, 80*2
  682.         loop    .write_remarks
  683. .wait:
  684.         _setcursor 25,0         ; out of screen
  685. ; set timer interrupt handler
  686.         cli
  687.         push    0
  688.         pop     es
  689.         push    dword [es:8*4]
  690.         pop     dword [.oldtimer]
  691.         push    dword [.timer]
  692.         pop     dword [es:8*4]
  693. ;        mov     eax, [es:8*4]
  694. ;        mov     [.oldtimer], eax
  695. ;        mov     eax, [.timer]
  696. ;        mov     [es:8*4], eax
  697.         sti
  698. ; wait for keypressed
  699.         xor     ax, ax
  700.         int     16h
  701.         push    ax
  702. ; restore timer interrupt
  703. ;        push    0
  704. ;        pop     es
  705.         mov     eax, [.oldtimer]
  706.         mov     [es:8*4], eax
  707.         mov     [.timer], eax
  708.  
  709.         _setcursor 7,0
  710.         mov     si, space_msg
  711.         call    printplain
  712. ; clear remarks and restore normal attributes
  713.         push    es
  714.         mov     di, ((21-num_remarks)*80 + 2)*2
  715.         push    0xB800
  716.         pop     es
  717.         mov     cx, num_remarks
  718.         mov     ax, ' ' + (1*16 + 15)*100h
  719. @@:
  720.         push    cx
  721.         mov     cx, 76
  722.         rep stosw
  723.         pop     cx
  724.         add     di, 4*2
  725.         loop    @b
  726.         pop     es
  727.         pop     ax
  728. ; switch on key
  729.         cmp     al, 13
  730.         jz      .continue
  731.         or      al, 20h
  732.         cmp     al, 'a'
  733.         jz      .change_a
  734.         cmp     al, 'b'
  735.         jz      .change_b
  736. ;        cmp     al, 'c'
  737. ;        jz      .change_c
  738.         cmp     al, 'c'         ; 'd'
  739.         jnz     .show_remarks
  740.         _setcursor 15,0
  741.         mov     si, bdev
  742.         call    print
  743. if defined extended_primary_loader
  744.         mov     bx, '12'
  745. else
  746.         mov     bx, '14'
  747. end if
  748.         call    getkey
  749.         mov     [preboot_device], al
  750.         _setcursor 13,0
  751. .d:
  752. if ~ defined extended_primary_loader
  753.         mov     [.bSettingsChanged], 1
  754. end if
  755.         call    clear_vmodes_table             ;clear vmodes_table
  756.         jmp     .printcfg
  757. .change_a:
  758. .loops:
  759.         call    draw_vmodes_table
  760.         _setcursor 25,0         ; out of screen
  761.         xor     ax, ax
  762.         int     0x16
  763. ;        call    clear_table_cursor             ;clear current position of cursor
  764.  
  765.         mov     si, word [cursor_pos]
  766.  
  767.         cmp     ah, 0x48;x,0x48E0               ; up
  768.         jne     .down
  769.         cmp     si, modes_table
  770.         jbe     .loops
  771.         sub     word [cursor_pos], size_of_step
  772.         jmp     .loops
  773.  
  774. .down:
  775.         cmp     ah, 0x50;x,0x50E0               ; down
  776.         jne     .pgup
  777.         cmp     word[es:si+10], -1
  778.         je      .loops
  779.         add     word [cursor_pos], size_of_step
  780.         jmp     .loops
  781.  
  782. .pgup:
  783.         cmp     ah, 0x49                ; page up
  784.         jne     .pgdn
  785.         sub     si, size_of_step*long_v_table
  786.         cmp     si, modes_table
  787.         jae     @f
  788.         mov     si, modes_table
  789. @@:
  790.         mov     word [cursor_pos], si
  791.         mov     si, word [home_cursor]
  792.         sub     si, size_of_step*long_v_table
  793.         cmp     si, modes_table
  794.         jae     @f
  795.         mov     si, modes_table
  796. @@:
  797.         mov     word [home_cursor], si
  798.         jmp     .loops
  799.  
  800. .pgdn:
  801.         cmp     ah, 0x51                ; page down
  802.         jne     .enter
  803.         mov     ax, [end_cursor]
  804.         add     si, size_of_step*long_v_table
  805.         cmp     si, ax
  806.         jb      @f
  807.         mov     si, ax
  808.         sub     si, size_of_step
  809. @@:
  810.         mov     word [cursor_pos], si
  811.         mov     si, word [home_cursor]
  812.         sub     ax, size_of_step*long_v_table
  813.         add     si, size_of_step*long_v_table
  814.         cmp     si, ax
  815.         jb      @f
  816.         mov     si, ax
  817. @@:
  818.         mov     word [home_cursor], si
  819.         jmp     .loops
  820.  
  821. .enter:
  822.         cmp     al, 0x0D;x,0x1C0D               ; enter
  823.         jne     .loops
  824.         push    word [cursor_pos]
  825.         pop     bp
  826.         push    word [es:bp]
  827.         pop     word [x_save]
  828.         push    word [es:bp+2]
  829.         pop     word [y_save]
  830.         push    word [es:bp+6]
  831.         pop     word [number_vm]
  832.         mov     word [preboot_graph], bp          ;save choose
  833.        
  834.         jmp     .d
  835.  
  836. .change_b:
  837.         _setcursor 15,0
  838. ;        mov     si, ask_dma
  839. ;        call    print
  840. ;        mov     bx, '13'
  841. ;        call    getkey
  842. ;        mov     [preboot_dma], al
  843.         mov     si, ask_bd
  844.         call    print
  845.         mov     bx, '12'
  846.         call    getkey
  847.         mov     [preboot_biosdisk], al
  848.         _setcursor 11,0
  849.         jmp     .d
  850. ;.change_c:
  851. ;        _setcursor 15,0
  852. ;        mov     si, vrrmprint
  853. ;        call    print
  854. ;        mov     bx, '12'
  855. ;        call    getkey
  856. ;        mov     [preboot_vrrm], al
  857. ;        _setcursor 12,0
  858. ;        jmp     .d
  859. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  860. .say_on_off:
  861.         pushf
  862.         call    print
  863.         mov     si, on_msg
  864.         popf
  865.         jz      @f
  866.         mov     si, off_msg
  867. @@:
  868.         jmp     printplain
  869. ; novesa and vervesa strings are not used at the moment of executing this code
  870. virtual at novesa
  871. .oldtimer dd ?
  872. .starttime dd ?
  873. if ~ defined extended_primary_loader
  874. .bSettingsChanged db ?
  875. end if
  876. .timer dd ?
  877. end virtual
  878. if ~ defined extended_primary_loader
  879. .loader_block dd -1
  880. end if
  881. .gettime:
  882.         mov     ah, 0
  883.         int     1Ah
  884.         xchg    ax, cx
  885.         shl     eax, 10h
  886.         xchg    ax, dx
  887.         ret
  888. .newtimer:
  889.         push    ds
  890.         push    cs
  891.         pop     ds
  892.         pushf
  893.         call    [.oldtimer]
  894.         pushad
  895.         call    .gettime
  896.         sub     eax, [.starttime]
  897. if defined extended_primary_loader
  898.         sub     ax, [preboot_timeout]
  899. else
  900.         sub     ax, 18*5
  901. end if
  902.         jae     .timergo
  903.         neg     ax
  904.         add     ax, 18-1
  905.         mov     bx, 18
  906.         xor     dx, dx
  907.         div     bx
  908. if lang eq ru
  909. ; подождите 5 секунд, 4/3/2 секунды, 1 секунду
  910.         cmp     al, 5
  911.         mov     cl, ' '
  912.         jae     @f
  913.         cmp     al, 1
  914.         mov     cl, 0xE3 ; 'у' in cp866
  915.         jz      @f
  916.         mov     cl, 0xEB ; 'ы' in cp866
  917. @@:
  918.         mov     [time_str+9], cl
  919. else if lang eq et
  920.         cmp     al, 1
  921.         ja      @f
  922.         mov     byte [time_str+9], ' '
  923.         mov     byte [time_str+10], ' '
  924. @@:
  925. else if lang eq sp
  926. ; esperar 5/4/3/2 segundos, 1 segundo
  927.         cmp     al, 1
  928.         mov     cl, 's'
  929.         ja      @f
  930.         mov     cl, ' '
  931. @@:
  932.         mov     [time_str+10], cl
  933. else
  934. ; wait 5/4/3/2 seconds, 1 second
  935.         cmp     al, 1
  936.         mov     cl, 's'
  937.         ja      @f
  938.         mov     cl, ' '
  939. @@:
  940.         mov     [time_str+9], cl
  941. end if
  942.         add     al, '0'
  943.         mov     [time_str+1], al
  944.         mov     si, time_msg
  945.         _setcursor 7,0
  946.         call    print
  947.         _setcursor 25,0
  948.         popad
  949.         pop     ds
  950.         iret
  951. .timergo:
  952.         push    0
  953.         pop     es
  954.         mov     eax, [.oldtimer]
  955.         mov     [es:8*4], eax
  956.         mov     sp, 0EC00h
  957. .continue:
  958.         sti
  959.         _setcursor 6,0
  960.         mov     si, space_msg
  961.         call    printplain
  962.         call    printplain
  963.         _setcursor 6,0
  964.         mov     si, loading_msg
  965.         call    print
  966.         _setcursor 15,0
  967. if ~ defined extended_primary_loader
  968.         cmp     [.bSettingsChanged], 0
  969.         jz      .load
  970.         cmp     [.loader_block], -1
  971.         jz      .load
  972.         les     bx, [.loader_block]
  973.         mov     eax, [es:bx+3]
  974.         push    ds
  975.         pop     es
  976.         test    eax, eax
  977.         jz      .load
  978.         push    eax
  979.         mov     si, save_quest
  980.         call    print
  981. .waityn:
  982.         mov     ah, 0
  983.         int     16h
  984.         or      al, 20h
  985.         cmp     al, 'n'
  986.         jz      .loadc
  987.         if lang eq sp
  988.         cmp     al, 's'
  989.         else
  990.         cmp     al, 'y'
  991.         end if
  992.         jnz     .waityn
  993.         call    putchar
  994.         mov     byte [space_msg+80], 186
  995.  
  996.         pop     eax
  997.         push    cs
  998.         push    .cont
  999.         push    eax
  1000.         retf                          ;call back
  1001. .loadc:
  1002.         pop     eax
  1003. .cont:
  1004.         push    cs
  1005.         pop     ds
  1006.         mov     si, space_msg
  1007.         mov     byte [si+80], 0
  1008.         _setcursor 15,0
  1009.         call    printplain
  1010.         _setcursor 15,0
  1011. .load:
  1012. end if
  1013. ; \end{diamond}[02.12.2005]
  1014.  
  1015. ; ASK GRAPHICS MODE
  1016.  
  1017.         call    set_vmode
  1018.  
  1019. ; GRAPHICS ACCELERATION
  1020. ; force yes
  1021.         mov     [es:BOOT_MTRR], byte 1
  1022.  
  1023. ; DMA ACCESS TO HD
  1024.  
  1025.         mov     al, [preboot_dma]
  1026.         mov     [es:BOOT_DMA], al
  1027.  
  1028. ;; VRR_M USE
  1029. ;
  1030. ;        mov     al,[preboot_vrrm]
  1031. ;        mov     [es:0x9030], al
  1032.  
  1033. ; BOOT DEVICE
  1034.  
  1035.         mov     al, [preboot_device]
  1036.         dec     al
  1037.         mov     [boot_dev], al
  1038.  
  1039. ; GET MEMORY MAP
  1040. include '../detect/biosmem.inc'
  1041.  
  1042. ; READ DISKETTE TO MEMORY
  1043.  
  1044.         cmp     [boot_dev], 0
  1045.         jne     no_sys_on_floppy
  1046.         mov     si, diskload
  1047.         call    print
  1048.         xor     ax, ax            ; reset drive
  1049.         xor     dx, dx
  1050.         int     0x13
  1051. ; do we boot from CD-ROM?
  1052.         mov     ah, 41h
  1053.         mov     bx, 55AAh
  1054.         xor     dx, dx
  1055.         int     0x13
  1056.         jc      .nocd
  1057.         cmp     bx, 0AA55h
  1058.         jnz     .nocd
  1059.         mov     ah, 48h
  1060.         push    ds
  1061.         push    es
  1062.         pop     ds
  1063.         mov     si, 0xa000
  1064.         mov     word [si], 30
  1065.         int     0x13
  1066.         pop     ds
  1067.         jc      .nocd
  1068.         push    ds
  1069.         lds     si, [es:si+26]
  1070.         test    byte [ds:si+10], 40h
  1071.         pop     ds
  1072.         jz      .nocd
  1073. ; yes - read all floppy by 18 sectors
  1074.  
  1075. ; TODO: !!!! read only first sector and set variables !!!!!
  1076. ; ...
  1077. ; TODO: !!! then read flippy image track by track
  1078.        
  1079.         mov     cx, 0x0001      ; startcyl,startsector
  1080. .a1:
  1081.         push    cx dx
  1082.         mov     al, 18
  1083.         mov     bx, 0xa000
  1084.         call    boot_read_floppy
  1085.         mov     si, movedesc
  1086.         push    es
  1087.         push    ds
  1088.         pop     es
  1089.         mov     cx, 256*18
  1090.         mov     ah, 0x87
  1091.         int     0x15
  1092.         pop     es
  1093.         pop     dx cx
  1094.         test    ah, ah
  1095.         jnz     sayerr_floppy
  1096.         add     dword [si+8*3+2], 512*18
  1097.         inc     dh
  1098.         cmp     dh, 2
  1099.         jnz     .a1
  1100.         mov     dh, 0
  1101.         inc     ch
  1102.         cmp     ch, 80
  1103.         jae     ok_sys_on_floppy
  1104.         pusha
  1105.         mov     al, ch
  1106.         shr     ch, 2
  1107.         add     al, ch
  1108.         aam
  1109.         xchg    al, ah
  1110.         add     ax, '00'
  1111.         mov     si, pros
  1112.         mov     [si], ax
  1113.         call    printplain
  1114.         popa
  1115.         jmp     .a1
  1116. .nocd:
  1117. ; no - read only used sectors from floppy
  1118. ; now load floppy image to memory
  1119. ; at first load boot sector and first FAT table
  1120.  
  1121. ; read only first sector and fill variables
  1122.         mov     cx, 0x0001      ; first logical sector
  1123.         xor     dx, dx          ; head = 0, drive = 0 (a:)
  1124.         mov     al, 1           ; read one sector
  1125.         mov     bx, 0xB000      ; es:bx -> data area
  1126.         call    boot_read_floppy
  1127. ; fill the necessary parameters to work with a floppy
  1128.         mov     ax, word [es:bx+24]
  1129.         mov     word [BPB_SecPerTrk], ax
  1130.         mov     ax, word [es:bx+26]
  1131.         mov     word [BPB_NumHeads], ax
  1132.         mov     ax, word [es:bx+17]
  1133.         mov     word [BPB_RootEntCnt], ax
  1134.         mov     ax, word [es:bx+14]
  1135.         mov     word [BPB_RsvdSecCnt], ax
  1136.         mov     ax, word [es:bx+19]
  1137.         mov     word [BPB_TotSec16], ax
  1138.         mov     al, byte [es:bx+13]
  1139.         mov     byte [BPB_SecPerClus], al
  1140.         mov     al, byte [es:bx+16]
  1141.         mov     byte [BPB_NumFATs], al
  1142. ;<Lrz> 18.11.2008
  1143.         mov     ax, word [es:bx+22]
  1144.         mov     word [BPB_FATSz16], ax
  1145.         mov     cx, word [es:bx+11]
  1146.         mov     word [BPB_BytsPerSec], cx
  1147.  
  1148. ; count of clusters in FAT12 ((size_of_FAT*2)/3)
  1149. ;        mov     ax, word [BPB_FATSz16]
  1150. ;        mov     cx, word [BPB_BytsPerSec]
  1151. ;end <Lrz> 18.11.2008
  1152.         xor     dx, dx
  1153.         mul     cx
  1154.         shl     ax, 1
  1155.         mov     cx, 3
  1156.         div     cx              ; now ax - number of clusters in FAT12
  1157.         mov     word [end_of_FAT], ax
  1158.  
  1159. ; load first FAT table
  1160.         mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
  1161.         xor     dx, dx          ; starthead,drive
  1162.         mov     al, byte [BPB_FATSz16]     ; no of sectors to read
  1163.         add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
  1164.         call    boot_read_floppy
  1165.         mov     bx, 0xB000
  1166.  
  1167. ; and copy them to extended memory
  1168.         mov     si, movedesc
  1169.         mov     [si+8*2+3], bh          ; from
  1170.        
  1171.         mov     ax, word [BPB_BytsPerSec]
  1172.         shr     ax, 1                   ; words per sector
  1173.         mov     cx, word [BPB_RsvdSecCnt]
  1174.         add     cx, word [BPB_FATSz16]
  1175.         mul     cx
  1176.         push    ax                      ; save to stack count of words in boot+FAT
  1177.         xchg    ax, cx
  1178.        
  1179.         push    es
  1180.         push    ds
  1181.         pop     es
  1182.         mov     ah, 0x87
  1183.         int     0x15
  1184.         pop     es
  1185.         test    ah, ah
  1186.         jz      @f
  1187. sayerr_floppy:
  1188.         mov     dx, 0x3f2
  1189.         mov     al, 0
  1190.         out     dx, al
  1191. sayerr_memmove:
  1192.         mov     si, memmovefailed
  1193.         jmp     sayerr_plain
  1194. @@:
  1195.         pop     ax                      ; restore from stack count of words in boot+FAT
  1196.         shl     ax, 1                   ; make bytes count from count of words
  1197.         and     eax, 0ffffh
  1198.         add     dword [si+8*3+2], eax
  1199.  
  1200. ; copy first FAT to second copy
  1201. ; TODO: BPB_NumFATs !!!!!
  1202.         add     bx, word [BPB_BytsPerSec]       ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
  1203.         mov     byte [si+8*2+3], bh     ; bx - begin of FAT
  1204.        
  1205.         mov     ax, word [BPB_BytsPerSec]
  1206.         shr     ax, 1                   ; words per sector
  1207.         mov     cx, word [BPB_FATSz16]
  1208.         mul     cx
  1209.         mov     cx, ax                  ; cx - count of words in FAT
  1210.  
  1211.         push    es
  1212.         push    ds
  1213.         pop     es
  1214.         mov     ah, 0x87
  1215.         int     0x15
  1216.         pop     es
  1217.         test    ah, ah
  1218.         jnz     sayerr_floppy
  1219.        
  1220.         mov     ax, cx
  1221.         shl     ax, 1
  1222.         and     eax, 0ffffh             ; ax - count of bytes in FAT
  1223.         add     dword [si+8*3+2], eax
  1224.        
  1225. ; reading RootDir
  1226. ; TODO: BPB_NumFATs
  1227.         add     bx, ax
  1228.         add     bx, 100h
  1229.         and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
  1230.         push    bx
  1231.  
  1232.         mov     bx, word [BPB_BytsPerSec]
  1233.         shr     bx, 5                           ; divide bx by 32
  1234.         mov     ax, word [BPB_RootEntCnt]
  1235.         xor     dx, dx
  1236.         div     bx
  1237.         push    ax                              ; ax - count of RootDir sectors
  1238.  
  1239.         mov     ax, word [BPB_FATSz16]
  1240.         xor     cx, cx
  1241.         mov     cl, byte [BPB_NumFATs]
  1242.         mul     cx
  1243.         add     ax, word [BPB_RsvdSecCnt]       ; ax - first sector of RootDir
  1244.  
  1245.         mov     word [FirstDataSector], ax
  1246.         pop     bx
  1247.         push    bx
  1248.         add     word [FirstDataSector], bx      ; Begin of data region of floppy
  1249.        
  1250. ; read RootDir
  1251.         call    conv_abs_to_THS
  1252.         pop     ax
  1253.         pop     bx                              ; place in buffer to write
  1254.         push    ax
  1255.         call    boot_read_floppy                ; read RootDir into buffer
  1256. ; copy RootDir
  1257.         mov     byte [si+8*2+3], bh             ; from buffer
  1258.         pop     ax                              ; ax = count of RootDir sectors
  1259.         mov     cx, word [BPB_BytsPerSec]
  1260.         mul     cx
  1261.         shr     ax, 1
  1262.         mov     cx, ax                          ; count of words to copy
  1263.         push    es
  1264.         push    ds
  1265.         pop     es
  1266.         mov     ah, 0x87
  1267.         int     0x15
  1268.         pop     es
  1269.  
  1270.         mov     ax, cx
  1271.         shl     ax, 1
  1272.         and     eax, 0ffffh             ; ax - count of bytes in RootDir
  1273.         add     dword [si+8*3+2], eax   ; add count of bytes copied
  1274.  
  1275. ; Reading data clusters from floppy
  1276.         mov     byte [si+8*2+3], bh
  1277.         push    bx
  1278.  
  1279.         mov     di, 2                   ; First data cluster
  1280. .read_loop:
  1281.         mov     bx, di
  1282.         shr     bx, 1                   ; bx+di = di*1.5
  1283.         jnc     .even
  1284.         test    word [es:bx+di+0xB200], 0xFFF0  ; TODO: may not be 0xB200 !!!
  1285.         jmp     @f
  1286. .even:
  1287.         test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
  1288.  
  1289. @@:
  1290.         jz      .skip
  1291. ; read cluster di
  1292. ;.read:
  1293.         ;conv cluster di to abs. sector ax
  1294.         ; ax = (N-2) * BPB_SecPerClus + FirstDataSector
  1295.         mov     ax, di
  1296.         sub     ax, 2
  1297.         xor     bx, bx
  1298.         mov     bl, byte [BPB_SecPerClus]
  1299.         mul     bx
  1300.         add     ax, word [FirstDataSector]
  1301.         call    conv_abs_to_THS
  1302.         pop     bx
  1303.         push    bx
  1304.         mov     al, byte [BPB_SecPerClus]       ; number of sectors in cluster
  1305.         call    boot_read_floppy
  1306.         push    es
  1307.         push    ds
  1308.         pop     es
  1309.         pusha
  1310. ;
  1311.         mov     ax, word [BPB_BytsPerSec]
  1312.         xor     cx, cx
  1313.         mov     cl, byte [BPB_SecPerClus]
  1314.         mul     cx
  1315.         shr     ax, 1                           ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
  1316.         mov     cx, ax                          ; number of words to copy (count words in cluster)
  1317. ;
  1318.         mov     ah, 0x87
  1319.         int     0x15                            ; copy data
  1320.         test    ah, ah
  1321.         popa
  1322.         pop     es
  1323.         jnz     sayerr_floppy
  1324. ; skip cluster di
  1325. .skip:
  1326.         mov     ax, word [BPB_BytsPerSec]
  1327.         xor     cx, cx
  1328.         mov     cl, byte [BPB_SecPerClus]
  1329.         mul     cx
  1330.         and     eax, 0ffffh             ; ax - count of bytes in cluster
  1331.         add     dword [si+8*3+2], eax
  1332.  
  1333.         mov     ax, word [end_of_FAT]   ; max cluster number
  1334.         pusha
  1335. ; draw percentage
  1336. ; total clusters: ax
  1337. ; read clusters: di
  1338.         xchg    ax, di
  1339.         mov     cx, 100
  1340.         mul     cx
  1341.         div     di
  1342.         aam
  1343.         xchg    al, ah
  1344.         add     ax, '00'
  1345.         mov     si, pros
  1346.         cmp     [si], ax
  1347.         jz      @f
  1348.         mov     [si], ax
  1349.         call    printplain
  1350. @@:
  1351.         popa
  1352.         inc     di
  1353.         cmp     di, word [end_of_FAT]   ; max number of cluster
  1354.         jnz     .read_loop
  1355.         pop     bx                      ; clear stack
  1356.  
  1357. ok_sys_on_floppy:
  1358.         mov     si, backspace2
  1359.         call    printplain
  1360.         mov     si, okt
  1361.         call    printplain
  1362. no_sys_on_floppy:
  1363.         xor     ax, ax          ; reset drive
  1364.         xor     dx, dx
  1365.         int     0x13
  1366.         mov     dx, 0x3f2       ; floppy motor off
  1367.         mov     al, 0
  1368.         out     dx, al
  1369.  
  1370. if defined extended_primary_loader
  1371.         cmp     [boot_dev], 1
  1372.         jne     no_sys_from_primary
  1373. ; load kolibri.img using callback from primary loader
  1374.         and     word [movedesc + 24 + 2], 0
  1375.         mov     byte [movedesc + 24 + 4], 10h
  1376. ; read in blocks of 64K until file is fully loaded
  1377.         mov     ax, 1
  1378. .repeat:
  1379.         mov     di, image_file_struct
  1380.         call    [bootcallback]
  1381.         push    cs
  1382.         pop     ds
  1383.         push    cs
  1384.         pop     es
  1385.         cmp     bx, 1
  1386.         ja      sayerr_badsect
  1387.         push    bx
  1388.         mov     si, movedesc
  1389.         and     word [si + 16 + 2], 0
  1390.         mov     byte [si + 16 + 4], 4
  1391.         mov     ah, 87h
  1392.         mov     cx, 8000h
  1393.         int     15h
  1394.         pop     bx
  1395.         test    ah, ah
  1396.         jnz     sayerr_memmove
  1397.         inc     byte [si + 24 + 4]
  1398.         test    bx, bx
  1399.         jz      no_sys_from_primary
  1400.         mov     ax, 2
  1401.         jmp     .repeat
  1402. no_sys_from_primary:
  1403. end if
  1404.  
  1405. ; SET GRAPHICS
  1406.  
  1407.         xor     ax, ax
  1408.         mov     es, ax
  1409.  
  1410.         mov     ax, [es:BOOT_VESA_MODE]         ; vga & 320x200
  1411.         mov     bx, ax
  1412.         cmp     ax, 0x13
  1413.         je      setgr
  1414.         cmp     ax, 0x12
  1415.         je      setgr
  1416.         mov     ax, 0x4f02              ; Vesa
  1417. setgr:
  1418.         int     0x10
  1419.         test    ah, ah
  1420.         mov     si, fatalsel
  1421.         jnz     v_mode_error
  1422. ; set mode 0x12 graphics registers:
  1423.         cmp     bx, 0x12
  1424.         jne     gmok2
  1425.  
  1426.         mov     al, 0x05
  1427.         mov     dx, 0x03ce
  1428.         push    dx
  1429.         out     dx, al      ; select GDC mode register
  1430.         mov     al, 0x02
  1431.         inc     dx
  1432.         out     dx, al      ; set write mode 2
  1433.  
  1434.         mov     al, 0x02
  1435.         mov     dx, 0x03c4
  1436.         out     dx, al      ; select VGA sequencer map mask register
  1437.         mov     al, 0x0f
  1438.         inc     dx
  1439.         out     dx, al      ; set mask for all planes 0-3
  1440.  
  1441.         mov     al, 0x08
  1442.         pop     dx
  1443.         out     dx, al      ; select GDC bit mask register
  1444.                            ; for writes to 0x03cf
  1445. gmok2:
  1446.         push    ds
  1447.         pop     es
  1448.