Subversion Repositories Kolibri OS

Rev

Rev 419 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                        ;;
  3. ;;  BOOTCODE.INC                                          ;;
  4. ;;                                                        ;;
  5. ;;  KolibriOS 16-bit loader,                              ;;
  6. ;;                        based on bootcode for MenuetOS  ;;
  7. ;;                                                        ;;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9.  
  10. ;==========================================================================
  11. ;
  12. ;                           16 BIT FUNCTIONS
  13. ;
  14. ;==========================================================================
  15.  
  16.  
  17. putchar:
  18. ; in: al=character
  19.     mov    ah, 0Eh
  20.     mov    bh, 0
  21.     int    10h
  22.     ret
  23.  
  24. print:
  25. ; in: si->string
  26.     mov    al, 186
  27.     call    putchar
  28.     mov    al, ' '
  29.     call    putchar
  30.  
  31. printplain:
  32. ; in: si->string
  33.     pusha
  34.     lodsb
  35. @@:
  36.     call    putchar
  37.     lodsb
  38.     cmp    al, 0
  39.     jnz    @b
  40.     popa
  41.     ret
  42.  
  43. getkey:
  44. ; get number in range [bl,bh] (bl,bh in ['0'..'9'])
  45. ; in: bx=range
  46. ; out: ax=digit (1..9, 10 for 0)
  47.     mov    ah, 0
  48.     int    16h
  49.     cmp    al, bl
  50.     jb    getkey
  51.     cmp    al, bh
  52.     ja    getkey
  53.     push    ax
  54.     call    putchar
  55.     pop    ax
  56.     and    ax, 0Fh
  57.     jnz    @f
  58.     mov    al, 10
  59. @@:
  60.     ret
  61.  
  62. setcursor:
  63. ; in: dl=column, dh=row
  64.     mov    ah, 2
  65.     mov    bh, 0
  66.     int    10h
  67.     ret
  68.  
  69. macro _setcursor row,column
  70. {
  71.     mov    dx, row*256 + column
  72.     call    setcursor
  73. }
  74.  
  75. boot_read_floppy:
  76.         push    si
  77.         xor     si, si
  78.         mov     ah, 2   ; read
  79. @@:
  80.         push    ax
  81.         int     0x13
  82.         pop     ax
  83.         jnc     @f
  84.         inc     si
  85.         cmp     si, 10
  86.         jb      @b
  87.         mov     si, badsect
  88. sayerr_plain:
  89.         call    printplain
  90.         jmp     $
  91. @@:
  92.         pop     si
  93.         ret
  94.  
  95. ;=========================================================================
  96. ;
  97. ;                           16 BIT CODE
  98. ;
  99. ;=========================================================================
  100.  
  101.  
  102. start_of_code:
  103.     cld
  104. ; \begin{diamond}[02.12.2005]
  105.     cmp    ax, 'KL'
  106.     jnz    @f
  107.     mov    word [cs:cfgmanager.loader_block], si
  108.     mov    word [cs:cfgmanager.loader_block+2], ds
  109. @@:
  110. ; \end{diamond}[02.12.2005]
  111.  
  112. ; set up stack
  113.     mov    ax, 3000h
  114.     mov    ss, ax
  115.     mov    sp, 0EC00h
  116. ; set up segment registers
  117.     push    cs
  118.     pop    ds
  119.     push    cs
  120.     pop    es
  121.  
  122. ; set videomode
  123.     mov    ax, 3
  124.         int  0x10
  125.  
  126. if lang eq ru
  127.  ; Load & set russian VGA font (RU.INC)
  128.         mov  bp, RU_FNT1         ; RU_FNT1 - First part
  129.         mov  bx,1000h            ; 768 bytes
  130.         mov  cx,30h              ; 48 symbols
  131.         mov  dx,80h              ; 128 - position of first symbol
  132.         mov  ax,1100h
  133.         int  10h
  134.  
  135.         mov  bp,RU_FNT2          ; RU_FNT2 -Second part
  136.         mov  bx,1000h            ; 512 bytes
  137.         mov  cx,20h              ; 32 symbols
  138.         mov  dx,0E0h             ; 224 - position of first symbol
  139.         mov  ax,1100h
  140.           int  10h
  141.  ; End set VGA russian font
  142. else if lang eq et
  143.         mov  bp,ET_FNT          ; ET_FNT1
  144.         mov  bx,1000h           ;
  145.         mov  cx,255             ; 256 symbols
  146.         mov  dx,0h              ; 0 - position of first symbol
  147.         mov  ax,1100h
  148.         int  10h
  149. end if
  150.  
  151. ; draw frames
  152.     push    0xb800
  153.     pop    es
  154.     xor    di, di
  155.     mov    ah, 1*16+15
  156.  
  157. ; draw top
  158.     mov    si, d80x25_top
  159.     mov    cx, d80x25_top_num * 80
  160. @@:
  161.     lodsb
  162.     stosw
  163.     loop    @b
  164. ; draw spaces
  165.     mov    si, space_msg
  166.     mov    cx, 25 - d80x25_top_num - d80x25_bottom_num
  167. dfl1:
  168.     push    cx
  169.     push    si
  170.     mov    cx, 80
  171. @@:
  172.     lodsb
  173.     stosw
  174.     loop    @b
  175.     pop    si
  176.     pop    cx
  177.     loop    dfl1
  178. ; draw bottom
  179.     mov    si, d80x25_bottom
  180.     mov    cx, d80x25_bottom_num * 80
  181. @@:
  182.     lodsb
  183.     stosw
  184.     loop    @b
  185.  
  186.     mov    byte [space_msg+80], 0    ; now space_msg is null terminated
  187.  
  188.     _setcursor d80x25_top_num,0
  189.  
  190.  
  191. ; TEST FOR 386+
  192.  
  193.     mov    bx, 0x4000
  194.         pushf
  195.         pop     ax
  196.         mov     dx,ax
  197.         xor     ax,bx
  198.         push    ax
  199.         popf
  200.         pushf
  201.         pop     ax
  202.         and     ax,bx
  203.         and     dx,bx
  204.         cmp     ax,dx
  205.         jnz     cpugood
  206.         mov     si,not386
  207. sayerr:
  208.         call    print
  209.         jmp     $
  210.      cpugood:
  211.  
  212.         push 0
  213.         popf
  214.         sti
  215.  
  216. ; set up esp
  217.     movzx    esp, sp
  218.  
  219.         push    0
  220.         pop     es
  221.         and     word [es:0x9031], 0
  222. ; \begin{Mario79}
  223. ; find HDD IDE DMA PCI device
  224. ; check for PCI BIOS
  225.         mov     ax, 0xB101
  226.         int     0x1A
  227.         jc      .nopci
  228.         cmp     edx, 'PCI '
  229.         jnz     .nopci
  230. ; find PCI class code
  231. ; class 1 = mass storage
  232. ; subclass 1 = IDE controller
  233. ; a) class 1, subclass 1, programming interface 0x80
  234.         mov     ax, 0xB103
  235.         mov     ecx, 1*10000h + 1*100h + 0x80
  236.         mov     si, 0   ; device index = 0
  237.         int     0x1A
  238.         jnc     .found
  239. ; b) class 1, subclass 1, programming interface 0x8A
  240.         mov     ax, 0xB103
  241.         mov     ecx, 1*10000h + 1*100h + 0x8A
  242.         mov     si, 0   ; device index = 0
  243.         int     0x1A
  244.         jnc     .found
  245. ; c) class 1, subclass 1, programming interface 0x85
  246.         mov     ax, 0xB103
  247.         mov     ecx, 1*10000h + 1*100h + 0x85
  248.         mov     si, 0
  249.         int     0x1A
  250.         jc      .nopci
  251. .found:
  252. ; get memory base
  253.         mov     ax, 0xB10A
  254.         mov     di, 0x20        ; memory base is config register at 0x20
  255.         int     0x1A
  256.         jc      .nopci
  257.         and     cx, 0xFFF0      ; clear address decode type
  258.         mov     [es:0x9031], cx
  259. .nopci:
  260. ; \end{Mario79}
  261.  
  262.     mov   al,0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
  263.     out   0x60,al
  264.     xor   cx,cx
  265. wait_loop:       ; variant 2
  266. ; reading state of port of 8042 controller
  267.         in      al,64h
  268.         and     al,00000010b  ; ready flag
  269. ; wait until 8042 controller is ready
  270.         loopnz  wait_loop
  271.  
  272. ; --------------- APM ---------------------
  273.     push    0
  274.     pop    es
  275.     mov    word [es : 0x9044], 0        ; ver = 0.0 (APM not found)
  276.     mov    ax, 0x5300
  277.     xor    bx, bx
  278.     int    0x15
  279.     jc    apm_end                ; APM not found
  280.     test    cx, 2
  281.     jz    apm_end                ; APM 32-bit protected-mode interface not supported
  282.     mov    [es : 0x9044], ax        ; Save APM Version
  283.     mov    [es : 0x9046], cx        ; Save APM flags
  284.  
  285.     ; Write APM ver ----
  286.     and    ax, 0xf0f
  287.     add    ax, '00'
  288.     mov    si, msg_apm
  289.     mov    [si + 5], ah
  290.     mov    [si + 7], al
  291.     _setcursor 0, 3
  292.  
  293.     call    printplain
  294.     _setcursor d80x25_top_num,0
  295.     ; ------------------
  296.  
  297.     mov    ax, 0x5304            ; Disconnect interface
  298.     xor    bx, bx
  299.     int    0x15
  300.     mov    ax, 0x5303            ; Connect 32 bit mode interface
  301.     xor    bx, bx
  302.     int    0x15
  303.  
  304.     push 0
  305.     pop es
  306.  
  307.     mov [es:0x9040], ebx
  308.     mov [es:0x9050], ax
  309.     mov [es:0x9052], cx
  310.     mov [es:0x9054], dx
  311.  
  312. apm_end:
  313.  
  314. ; DISPLAY VESA INFORMATION
  315.         push 0
  316.         pop es
  317.  
  318.         mov     ax,0x4f00
  319.         mov     di,0xa000
  320.         int     0x10
  321.         cmp     ax,0x004f
  322.         mov    si, novesa
  323.         jnz    @f
  324.         mov bx, word [es:di+0x12]
  325.         shl ebx,16
  326.         mov [es:0x9050], ebx
  327.         mov     ax,[es:di+4]
  328.         add     ax,'0'*256+'0'
  329.         mov    si,vervesa
  330.         mov     [si+vervesa_off], ah
  331.         mov     [si+vervesa_off+2], al
  332. @@:     call    print
  333.  
  334. ; \begin{diamond}[30.11.2005]
  335. cfgmanager:
  336. ; settings:
  337. ; a) preboot_graph = graphical mode
  338. ;    preboot_gprobe = probe this mode?
  339. ; b) preboot_dma_write  = use DMA write?
  340. ; c) preboot_vrrm = use VRR?
  341. ; d) preboot_device = from what boot?
  342.     mov    di, preboot_graph
  343. ; check bootloader block
  344.     cmp    [.loader_block], -1
  345.     jz    .noloaderblock
  346.     les    bx, [.loader_block]
  347.     cmp    byte [es:bx], 1
  348.     mov    si, loader_block_error
  349.     jnz    sayerr
  350.     test    byte [es:bx+1], 1
  351.     jz    @f
  352. ; image in memory present
  353.     cmp    [di+preboot_device-preboot_graph], 0
  354.     jnz    @f
  355.     mov    [di+preboot_device-preboot_graph], 3
  356. @@:
  357. .noloaderblock:
  358. ; determine default settings
  359.     mov    [.bSettingsChanged], 0
  360.     cmp    byte [di], 0
  361.     jnz    .preboot_gr_end
  362.     mov    [di+preboot_gprobe-preboot_graph], 0
  363.     mov    al, [vervesa+vervesa_off]
  364.     cmp    al, 'x'
  365.     jz    .novesa
  366.     cmp    al, '1'
  367.     jz    .vesa12
  368.     mov    [di+preboot_gprobe-preboot_graph], 2
  369.     mov    al, 3
  370.     jmp    @f
  371. .vesa12:
  372.     mov    al, 7
  373.     jmp    @f
  374. .novesa:
  375.     mov    al, 10
  376. @@:
  377.     mov    [di], al
  378. .preboot_gr_end:
  379.     cmp    [di+preboot_dma_write-preboot_graph], 1
  380.     adc    [di+preboot_dma_write-preboot_graph], 0
  381.     cmp    [di+preboot_vrrm-preboot_graph], 1
  382.     adc    [di+preboot_vrrm-preboot_graph], 0
  383.     cmp    [di+preboot_device-preboot_graph], 1
  384.     adc    [di+preboot_device-preboot_graph], 0
  385. ; notify user
  386.     mov    si, linef
  387.     call    print
  388.     mov    si, start_msg
  389.     call    print
  390.     mov    si, time_msg
  391.     call    print
  392. ; get start time
  393.     call    .gettime
  394.     mov    [.starttime], eax
  395.     mov    word [.timer], .newtimer
  396.     mov    word [.timer+2], cs
  397. .printcfg:
  398.     _setcursor 9,0
  399.     mov    si, current_cfg_msg
  400.     call    print
  401.     mov    si, curvideo_msg
  402.     call    print
  403.     mov    al, [preboot_graph]
  404.     cmp    al, 8
  405.     ja    .pnovesa
  406.     mov    dl, al
  407.     and    eax, 3
  408.     mov    si, [modes_msg+eax*2]
  409.     call    printplain
  410.     mov    si, modevesa20
  411.     cmp    dl, 4
  412.     jbe    @f
  413.     mov    si, modevesa12
  414. @@:
  415.     call    printplain
  416.     cmp    dl, 4
  417.     ja    .x
  418.     mov    si, probeno_msg
  419.     cmp    [preboot_gprobe], 2
  420.     jnz    @f
  421.     mov    si, probeok_msg
  422. @@:
  423.     call    printplain
  424. .x:
  425.     jmp    .c
  426. .pnovesa:
  427.     cmp    al, 9
  428.     mov    si, mode9
  429.     jz    @b
  430.     mov    si, mode10
  431.     jmp    @b
  432. .c:
  433.     mov    si, linef
  434.     call    printplain
  435.     mov    si, dma_msg
  436.     cmp    [preboot_dma_write], 1
  437.     call    .say_on_off
  438.     mov    si, vrrm_msg
  439.     cmp    [preboot_vrrm], 1
  440.     call    .say_on_off
  441.     mov    si, preboot_device_msg
  442.     call    print
  443.     mov    al, [preboot_device]
  444.     and    eax, 3
  445.     mov    si, [preboot_device_msgs+eax*2]
  446.     call    printplain
  447. .wait:
  448.     _setcursor 25,0        ; out of screen
  449. ; set timer interrupt handler
  450.     cli
  451.     push    0
  452.     pop    es
  453.     mov    eax, [es:8*4]
  454.     mov    [.oldtimer], eax
  455.     mov    eax, [.timer]
  456.     mov    [es:8*4], eax
  457.     sti
  458. ; wait for keypressed
  459.     mov    ah, 0
  460.     int    16h
  461.     push    ax
  462. ; restore timer interrupt
  463.     push    0
  464.     pop    es
  465.     mov    eax, [.oldtimer]
  466.     mov    [es:8*4], eax
  467.     mov    [.timer], eax
  468.     _setcursor 7,0
  469.     mov    si, space_msg
  470.     call    printplain
  471.     pop    ax
  472. ; switch on key
  473.     cmp    al, 13
  474.     jz    .continue
  475.     or    al, 20h
  476.     cmp    al, 'a'
  477.     jz    .change_a
  478.     cmp    al, 'b'
  479.     jz    .change_b
  480.     cmp    al, 'c'
  481.     jz    .change_c
  482.     cmp    al, 'd'
  483.     jnz    .wait
  484.     _setcursor 15,0
  485.     mov     si,bdev
  486.     call    print
  487.     mov     bx,'13'
  488.     call    getkey
  489.     mov    [preboot_device], al
  490.     _setcursor 13,0
  491. .d:
  492.     mov    [.bSettingsChanged], 1
  493.     mov    si, space_msg
  494.     call    printplain
  495.     _setcursor 15,0
  496.     mov    cx, 6
  497. @@:
  498.     call    printplain
  499.     loop    @b
  500.     jmp    .printcfg
  501. .change_a:
  502.     _setcursor 15,0
  503.     mov    si, gr_mode
  504.     call    printplain
  505.     mov     bx, '09'
  506.     call    getkey
  507.     mov    [preboot_graph], al
  508.     cmp    al, 4
  509.     ja    @f
  510.     mov    si, probetext
  511.     call    printplain
  512.     mov    bx, '12'
  513.     call    getkey
  514.     mov    [preboot_gprobe], al
  515. @@:
  516.     _setcursor 10,0
  517.     jmp    .d
  518. .change_b:
  519.     _setcursor 15,0
  520.     mov    si, ask_dma
  521.     call    print
  522.     mov    bx, '12'
  523.     call    getkey
  524.     mov    [preboot_dma_write], al
  525.     _setcursor 11,0
  526.     jmp    .d
  527. .change_c:
  528.     _setcursor 15,0
  529.     mov    si, vrrmprint
  530.     call    print
  531.     mov    bx, '12'
  532.     call    getkey
  533.     mov    [preboot_vrrm], al
  534.     _setcursor 12,0
  535.     jmp    .d
  536. .say_on_off:
  537.     pushf
  538.     call    print
  539.     mov    si, on_msg
  540.     popf
  541.     jz    @f
  542.     mov    si, off_msg
  543. @@:    call    printplain
  544.     ret
  545. ; novesa and vervesa strings are not used at the moment of executing this code
  546. virtual at novesa
  547. .oldtimer dd ?
  548. .starttime dd ?
  549. .bSettingsChanged db ?
  550. .timer dd ?
  551. end virtual
  552. .loader_block dd -1
  553. .gettime:
  554.  
  555.     mov    ah, 0
  556.     int    1Ah
  557.     xchg    ax, cx
  558.     shl    eax, 10h
  559.     xchg    ax, dx
  560.     ret
  561. .newtimer:
  562.     push    ds
  563.     push    cs
  564.     pop    ds
  565.     pushf
  566.     call    [.oldtimer]
  567.     pushad
  568.     call    .gettime
  569.     sub    eax, [.starttime]
  570.     sub    ax, 18*5
  571.     jae    .timergo
  572.     neg    ax
  573.     add    ax, 18-1
  574.     mov    bx, 18
  575.     xor    dx, dx
  576.     div    bx
  577. if lang eq ru
  578. ; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
  579.     cmp    al, 5
  580.     mov    cl, ' '
  581.     jae    @f
  582.     cmp    al, 1
  583.     mov    cl, 'ã'
  584.     jz    @f
  585.     mov    cl, 'ë'
  586. @@:    mov    [time_str+9], cl
  587. else if lang eq et
  588.     cmp    al, 1
  589.     ja     @f
  590.     mov    [time_str+9], ' '
  591.     mov    [time_str+10],' '
  592. @@:
  593. else
  594. ; wait 5/4/3/2 seconds, 1 second
  595.     cmp    al, 1
  596.     mov    cl, 's'
  597.     ja    @f
  598.     mov    cl, ' '
  599. @@:    mov    [time_str+9], cl
  600. end if
  601.     add    al, '0'
  602.     mov    [time_str+1], al
  603.     mov    si, time_msg
  604.     _setcursor 7,0
  605.     call    print
  606.     _setcursor 25,0
  607.     popad
  608.     pop    ds
  609.     iret
  610. .timergo:
  611.     push    0
  612.     pop    es
  613.     mov    eax, [.oldtimer]
  614.     mov    [es:8*4], eax
  615.     mov    sp, 0EC00h
  616. .continue:
  617.     sti
  618.     _setcursor 6,0
  619.     mov    si, space_msg
  620.     call    printplain
  621.     call    printplain
  622.     _setcursor 6,0
  623.     mov    si, loading_msg
  624.     call    print
  625.     _setcursor 15,0
  626.     cmp    [.bSettingsChanged], 0
  627.     jz    .load
  628.     cmp    [.loader_block], -1
  629.     jz    .load
  630.     les    bx, [.loader_block]
  631.     mov    eax, [es:bx+3]
  632.     push    ds
  633.     pop    es
  634.     test    eax, eax
  635.     jz    .load
  636.     push    eax
  637.     mov    si, save_quest
  638.     call    print
  639. .waityn:
  640.     mov    ah, 0
  641.     int    16h
  642.     or    al, 20h
  643.     cmp    al, 'n'
  644.     jz    .loadc
  645.     cmp    al, 'y'
  646.     jnz    .waityn
  647.     call    putchar
  648.     mov    byte [space_msg+80], 186
  649.     pop    eax
  650.     push    cs
  651.     push    .cont
  652.     push    eax
  653.     retf
  654. .loadc:
  655.     pop    eax
  656. .cont:
  657.     push    cs
  658.     pop    ds
  659.     mov    si, space_msg
  660.     mov    byte [si+80], 0
  661.     _setcursor 15,0
  662.     call    printplain
  663.     _setcursor 15,0
  664. .load:
  665. ; \end{diamond}[02.12.2005]
  666.  
  667. ; ASK GRAPHICS MODE
  668.  
  669.     movzx    ax, [preboot_graph]
  670.     push    0
  671.     pop    es
  672. ; address is gr_table+6*(ax-1)
  673.         add    ax, ax
  674.         lea    si, [gr_table + eax + eax*2 - 6]
  675.         mov     bx,[si+0]
  676.         mov     cx,[si+2]
  677.         mov     dx,[si+4]
  678.         cmp    al, 9*2
  679.         mov    al, 32    ; BPP
  680.         jb    @f
  681.         mov    [es:0x9000], al
  682.         mov    dword [es:0x9018], 0xFFFFFFFF; 0x800000
  683.        @@:
  684.         mov     [es:0x9008],bx
  685.         mov     [es:0x900A],cx
  686.         mov     [es:0x900C],dx
  687.         test    bh, bh
  688.         jz    nov
  689.  
  690. ; USE DEFAULTS OR PROBE
  691.  
  692. ; bx - mode : cx - x size : dx - y size
  693.     cmp    [preboot_gprobe], 1
  694.     jz    noprobe
  695.  
  696.         mov     bx,0x100
  697.      newprobe:
  698.         inc     bx
  699.         cmp     bx,0x17f
  700.         mov    si,prnotfnd
  701.         jz    sayerr
  702.  
  703.      probemore:
  704.          push    cx
  705.         mov     ax,0x4f01
  706.         mov     cx,bx
  707.         and     cx,0xfff
  708.         mov     di,0xa000
  709.         int     0x10
  710.         pop    cx
  711.  
  712.     test    byte [es:di], 80h    ; lfb?
  713.     jz    newprobe
  714.     cmp    [es:di+0x12], cx    ; x size?
  715.     jnz    newprobe
  716.     cmp    [es:di+0x14], dx    ; y size?
  717.     jnz    newprobe
  718.     cmp    byte [es:di+0x19], 32 ;24
  719.     jb    newprobe
  720.  
  721. ;       add     bx,0100000000000000b
  722.     or    bh, 40h
  723.         mov     [es:0x9008],bx
  724.  
  725.      noprobe:
  726.  
  727.  
  728. ; FIND VESA 2.0 LFB & BPP
  729.  
  730.         mov     ax,0x4f01
  731.         mov     cx,bx
  732.         and     cx,0xfff
  733.         mov     di,0xa000
  734.         int     0x10
  735.         ; LFB
  736.         mov     eax,[es:di+0x28]
  737.         mov     [es:0x9018],eax
  738.         ; ---- vbe voodoo
  739.         BytesPerLine equ 0x10
  740.         mov ax, [es:di+BytesPerLine]
  741.         mov [es:0x9001],ax
  742.         ; BPP
  743.         mov     al,byte [es:di+0x19]
  744.         mov     [es:0x9000],al
  745.        nov:
  746.         cmp     al,24
  747.         mov    si,bt24
  748.         jz    bppl
  749.         cmp     al,32
  750.         mov     si,bt32
  751.         jz     bppl
  752.         mov     si,btns
  753.         jmp    sayerr
  754.        bppl:
  755.         call    print
  756.  
  757.  
  758. ; FIND VESA 1.2 PM BANK SWITCH ADDRESS
  759.  
  760.     push    es
  761.         mov     ax,0x4f0A
  762.         xor    bx, bx
  763.         int     0x10
  764.         xor     eax,eax
  765.         mov     ax,es
  766.         shl     eax,4
  767.         movzx   ebx,di
  768.         add     eax,ebx
  769.         mov     bx,[es:di]
  770.         add     eax,ebx
  771.         pop     es
  772.         mov     [es:0x9014],eax
  773.  
  774.  
  775. ; GRAPHICS ACCELERATION
  776. ; force yes
  777.         mov     [es:0x901C], byte 1
  778.  
  779. ; DMA WRITE
  780.  
  781.         mov     al, [preboot_dma_write]
  782.         mov     [es:0x901F],al
  783.  
  784. ; VRR_M USE
  785.  
  786.         mov     al,[preboot_vrrm]
  787.         mov     [es:0x9030],al
  788.         mov     [es:0x901E],byte 1
  789.  
  790. ; BOOT DEVICE
  791.  
  792.     mov    al, [preboot_device]
  793.         dec     al
  794.         mov     [boot_dev],al
  795.  
  796. ; READ DISKETTE TO MEMORY
  797.  
  798. ;        cmp     [boot_dev],0
  799.         jne     no_sys_on_floppy
  800.         mov     si,diskload
  801.         call    print
  802.         xor    ax, ax            ; reset drive
  803.         xor    dx, dx
  804.         int     0x13
  805. ; now load floppy image to memory
  806. ; at first load boot sector and first FAT table
  807.         mov     cx, 0x0001      ; startcyl,startsector
  808.         xor     dx, dx          ; starthead,drive
  809.         mov     al, 1+9         ; no of sectors to read
  810.         mov     bx, 0xB000      ; es:bx -> data area
  811.         call    boot_read_floppy
  812. ; and copy them to extended memory
  813.         mov     si, movedesc
  814.         mov     [si+8*2+3], bh
  815.         push    es
  816.         push    ds
  817.         pop     es
  818.         mov     cx, 256*10
  819.         mov     ah, 0x87
  820.         int     0x15
  821.         test    ah, ah
  822.         jz      @f
  823. sayerr_floppy:
  824.         mov     dx, 0x3f2
  825.         mov     al, 0
  826.         out     dx, al
  827.         mov     si, memmovefailed
  828.         jmp     sayerr_plain
  829. @@:
  830.         add     dword [si+8*3+2], 512*10
  831. ; copy FAT to second copy
  832.         mov     byte [si+8*2+3], 0xB2
  833.         mov     cx, 256*9
  834.         mov     ah, 0x87
  835.         int     0x15
  836.         pop     es
  837.         test    ah, ah
  838.         jnz     sayerr_floppy
  839.         add     dword [si+8*3+2], 512*9
  840. ; calculate total number of sectors to read
  841.         mov     ax, 1+9+14      ; boot+FAT+root
  842.         mov     di, 0xB203
  843. .calc_loop:
  844.         test    word [es:di], 0xFFF
  845.         jz      @f
  846.         inc     ax
  847. @@:
  848.         test    word [es:di+1], 0xFFF0
  849.         jz      @f
  850.         inc     ax
  851. @@:
  852.         add     di, 3
  853.         cmp     di, 0xB200+1440*3
  854.         jb      .calc_loop
  855.         push    ax
  856.         mov     bp, 1+9         ; already read sectors
  857. ; now read rest
  858.         mov     byte [si+8*2+3], 0xA0
  859.         mov     di, 2-14        ; absolute sector-31
  860.         mov     cx, 0x0002      ; cylinder=0, sector=2
  861.         mov     dx, 0x0100      ; head=1, disk=0
  862. .read_loop:
  863. ; determine whether sector must be read
  864.         cmp     di, 2
  865.         jl      .read
  866.         mov     bx, di
  867.         shr     bx, 1
  868.         jnc     .even
  869.         test    word [es:bx+di+0xB200], 0xFFF0
  870.         jmp     @f
  871. .even:
  872.         test    word [es:bx+di+0xB200], 0xFFF
  873. @@:
  874.         jz      .skip
  875. .read:
  876.         mov     bx, 0xA000
  877.         mov     al, 1           ; 1 sector
  878.         call    boot_read_floppy
  879.         inc     bp
  880.         push    es
  881.         push    ds
  882.         pop     es
  883.         pusha
  884.         mov     cx, 256
  885.         mov     ah, 0x87
  886.         int     0x15
  887.         test    ah, ah
  888.         popa
  889.         pop     es
  890.         jnz     sayerr_floppy
  891. .skip:
  892.         add     dword [si+8*3+2], 512
  893.         inc     cx
  894.         cmp     cl, 19
  895.         jnz     @f
  896.         mov     cl, 1
  897.         inc     dh
  898.         cmp     dh, 2
  899.         jnz     @f
  900.         mov     dh, 0
  901.         inc     ch
  902. @@:
  903.         pop     ax
  904.         push    ax
  905.         pusha
  906. ; draw percentage
  907. ; total sectors: ax
  908. ; read sectors: bp
  909.         xchg    ax, bp
  910.         mov     cx, 100
  911.         mul     cx
  912.         div     bp
  913.         aam
  914.         xchg    al, ah
  915.         add     ax, '00'
  916.         mov     si, pros
  917.         cmp     [si], ax
  918.         jz      @f
  919.         mov     [si], ax
  920.         call    printplain
  921. @@:
  922.         popa
  923.         inc     di
  924.         cmp     di, 2880-31
  925.         jnz     .read_loop
  926.  
  927. ;        mov     cx, 0x0001      ; startcyl,startsector
  928. ;        xor     dx, dx          ; starthead,drive
  929. ;        push    word 80*2               ; read no of sect
  930. ;       reads:
  931. ;        pusha
  932. ;        xor     si,si
  933. ;       newread:
  934. ;        mov     bx,0xa000               ; es:bx -> data area
  935. ;        mov     ax,0x0200+18            ; read, no of sectors to read
  936. ;        int     0x13
  937. ;        test    ah, ah
  938. ;        jz      goodread
  939. ;        inc    si
  940. ;        cmp     si,10
  941. ;        jnz     newread
  942. ;        mov     si,badsect-0x10000
  943. ;sayerr_plain:
  944. ;        call    printplain
  945. ;        jmp     $
  946. ;       goodread:
  947. ;        ; move -> 1mb
  948. ;        mov     si,movedesc-0x10000
  949. ;        push    es
  950. ;        push    ds
  951. ;        pop     es
  952. ;        mov     cx,256*18
  953. ;        mov     ah,0x87
  954. ;        int     0x15
  955. ;        pop    es
  956. ;
  957. ;        test    ah,ah                  ; was the move successfull ?
  958. ;        je      goodmove
  959. ;        mov     dx,0x3f2              ; floppy motor off
  960. ;        mov     al,0
  961. ;        out     dx,al
  962. ;        mov     si,memmovefailed-0x10000
  963. ;        jmp    sayerr_plain
  964. ;      goodmove:
  965. ;
  966. ;    add    dword [movedesc-0x10000+0x18+2], 512*18
  967. ;        popa
  968. ;        inc     dh
  969. ;        cmp     dh,2
  970. ;        jnz     bb2
  971. ;        mov     dh,0
  972. ;        inc     ch
  973. ;        pusha                        ; print prosentage
  974. ;        mov     si,pros-0x10000
  975. ;    shr    ch, 2
  976. ;    mov    al, '5'
  977. ;    test    ch, 1
  978. ;    jnz    @f
  979. ;    mov    al, '0'
  980. ;@@:
  981. ;    mov    [si+1], al
  982. ;    shr    ch, 1
  983. ;    add    ch, '0'
  984. ;    mov    [si], ch
  985. ;        call    printplain
  986. ;        popa
  987. ;       bb2:
  988. ;        pop     ax
  989. ;        dec     ax
  990. ;        push    ax
  991. ;        jnz     reads
  992. ;       readdone:
  993. ;        pop     ax
  994.  
  995.         mov     si,backspace2
  996.         call    printplain
  997.         mov     si,okt
  998.         call    printplain
  999.  
  1000. no_sys_on_floppy:
  1001.         xor    ax, ax        ; reset drive
  1002.         xor    dx, dx
  1003.         int     0x13
  1004.         mov dx,0x3f2 ; floppy motor off
  1005.         mov al,0
  1006.         out dx,al
  1007.  
  1008.  
  1009. ; SET GRAPHICS
  1010.  
  1011.         xor ax, ax
  1012.         mov es, ax
  1013.  
  1014.         mov   ax,[es:0x9008]        ; vga & 320x200
  1015.         mov    bx, ax
  1016.         cmp     ax,0x13
  1017.         je      setgr
  1018.         cmp     ax,0x12
  1019.         je      setgr
  1020.         mov     ax,0x4f02            ; Vesa
  1021. setgr:
  1022.         int     0x10
  1023.         test    ah,ah
  1024.         mov    si, fatalsel
  1025.         jnz    sayerr
  1026.  
  1027. ; set mode 0x12 graphics registers:
  1028.         cmp     bx,0x12
  1029.         jne     gmok2
  1030.  
  1031.         mov     al,0x05
  1032.         mov     dx,0x03ce
  1033.         push    dx
  1034.         out     dx,al      ; select GDC mode register
  1035.         mov     al,0x02
  1036.         inc    dx
  1037.         out     dx,al      ; set write mode 2
  1038.  
  1039.         mov     al,0x02
  1040.         mov     dx,0x03c4
  1041.         out     dx,al      ; select VGA sequencer map mask register
  1042.         mov     al,0x0f
  1043.         inc    dx
  1044.         out     dx,al      ; set mask for all planes 0-3
  1045.  
  1046.         mov     al,0x08
  1047.         pop    dx
  1048.         out     dx,al      ; select GDC bit mask register
  1049.                            ; for writes to 0x03cf
  1050. gmok2:
  1051.         push    ds
  1052.         pop    es
  1053.