Subversion Repositories Kolibri OS

Rev

Rev 161 | Rev 183 | Go to most recent revision | Blame | Compare with Previous | 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. ;==========================================================================
  13. ;
  14. ;                           16 BIT FUNCTIONS
  15. ;
  16. ;==========================================================================
  17.  
  18. putchar:
  19. ; in: al=character
  20.     mov    ah, 0Eh
  21.     mov    bh, 0
  22.     int    10h
  23.     ret
  24.  
  25. print:
  26. ; in: si->string
  27.     mov    al, 186
  28.     call    putchar
  29.     mov    al, ' '
  30.     call    putchar
  31.  
  32. printplain:
  33. ; in: si->string
  34.     pusha
  35.     lodsb
  36. @@:
  37.     call    putchar
  38.     lodsb
  39.     cmp    al, 0
  40.     jnz    @b
  41.     popa
  42.     ret
  43.  
  44. ; Now int 16 is used for keyboard support.
  45. ; This is shorter, simpler and more reliable.
  46. if 0
  47. getkey:      push  ecx
  48.              push  edx
  49.              add   ebx,0x0101
  50.              xor   eax,eax
  51.  
  52.            gk1:
  53.              in    al,0x60
  54.              mov   cl,al
  55.            gk0:
  56.              in    al,0x60
  57.              cmp   al,cl
  58.              je    gk0
  59.              cmp   ax,11
  60.              jg    gk0
  61.              gk0_1:
  62.              mov   cl,al
  63.  
  64. ;             add   al,47
  65. ;             mov   [ds:keyinbs-0x10000],al
  66. ;             mov   si,keyinbs-0x10000
  67. ;             call  printplain
  68.  
  69.            gk12:
  70.              in    al,0x60
  71.              cmp   al,cl
  72.              je    gk12
  73.              cmp   ax,240
  74.              jne   gk13
  75.              mov   al,cl
  76.              jmp   gk14
  77.            gk13:
  78.              add   cl,128
  79.              cmp   al,cl
  80.              jne   gk1
  81.              sub   al,128
  82.            gk14:
  83.  
  84.              movzx edx,bl
  85.              cmp   eax,edx
  86.              jb    gk1
  87.              movzx edx,bh
  88.              cmp   eax,edx
  89.              jg    gk1
  90.              test  ebx,0x010000
  91.              jnz   gk3
  92.              mov   cx,0x1000
  93.              mov   dx,cx
  94.              add   eax,47
  95.              mov   cx,ax
  96.              cmp   cx,58
  97.              jb    gk_nozero
  98.              sub   cx,10
  99.            gk_nozero:
  100.              mov   [ds:keyin-0x10000],cl
  101.              mov   si,keyin-0x10000
  102.              call  printplain
  103.            gk3:
  104.              sub   eax,48
  105.              pop   edx
  106.              pop   ecx
  107.              ret
  108. end if
  109.  
  110. getkey:
  111. ; get number in range [bl,bh] (bl,bh in ['0'..'9'])
  112. ; in: bx=range
  113. ; out: ax=digit (1..9, 10 for 0)
  114.     mov    ah, 0
  115.     int    16h
  116.     cmp    al, bl
  117.     jb    getkey
  118.     cmp    al, bh
  119.     ja    getkey
  120.     push    ax
  121.     call    putchar
  122.     pop    ax
  123.     and    ax, 0Fh
  124.     jnz    @f
  125.     mov    al, 10
  126. @@:
  127.     ret
  128.  
  129. setcursor:
  130. ; in: dl=column, dh=row
  131.     mov    ah, 2
  132.     mov    bh, 0
  133.     int    10h
  134.     ret
  135.  
  136. macro _setcursor row,column
  137. {
  138.     mov    dx, row*256 + column
  139.     call    setcursor
  140. }
  141.  
  142. pagetable_set:
  143. ;eax - physical address
  144. ;es:di - page table
  145. ;ecx - number of pages to map
  146.     or    al, 7
  147. @@:
  148.     stosd
  149.     add    eax, 1000h
  150.     loop    @b
  151.     ret
  152.  
  153. boot_read_floppy:
  154.         push    si
  155.         xor     si, si
  156.         mov     ah, 2   ; read
  157. @@:
  158.         push    ax
  159.         int     0x13
  160.         pop     ax
  161.         jnc     @f
  162.         inc     si
  163.         cmp     si, 10
  164.         jb      @b
  165.         mov     si, badsect-0x10000
  166. sayerr_plain:
  167.         call    printplain
  168.         jmp     $
  169. @@:
  170.         pop     si
  171.         ret
  172.  
  173. ; 16-bit data
  174. ; videomodes table
  175.                 org $+0x10000
  176. gr_table:
  177.     dw      0x112+0100000000000000b ,  640 ,  480        ; 1
  178.     dw      0x115+0100000000000000b ,  800 ,  600        ; 2
  179.     dw      0x118+0100000000000000b , 1024 ,  768        ; 3
  180.     dw      0x11B+0100000000000000b , 1280 , 1024        ; 4
  181.     dw      0x112 ,  640 , 480                ; 5
  182.     dw      0x115 ,  800 , 600                ; 6
  183.     dw      0x118 , 1024 , 768                ; 7
  184.     dw      0x11B , 1280 ,1024                ; 8
  185.     dw    0x13, 640, 480                    ; 9
  186.     dw    0x12, 640, 480                    ; 0
  187.  
  188. ; table for move to extended memory (int 15h, ah=87h)
  189.        movedesc:
  190.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  191.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  192.  
  193.         db      0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0
  194.         db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
  195.  
  196.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  197.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  198.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  199.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  200.                 org $-0x10000
  201.  
  202. ;=========================================================================
  203. ;
  204. ;                           16 BIT CODE
  205. ;
  206. ;=========================================================================
  207.  
  208.  
  209. start_of_code:
  210.     cld
  211. ; \begin{diamond}[02.12.2005]
  212.     cmp    ax, 'KL'
  213.     jnz    @f
  214.     mov    word [cs:cfgmanager.loader_block-0x10000], si
  215.     mov    word [cs:cfgmanager.loader_block+2-0x10000], ds
  216. @@:
  217. ; \end{diamond}[02.12.2005]
  218.  
  219. ; set up stack
  220.     mov    ax, 3000h
  221.     mov    ss, ax
  222.     mov    sp, 0EC00h
  223. ; set up segment registers
  224.     push    cs
  225.     pop    ds
  226.     push    cs
  227.     pop    es
  228.  
  229. ; set videomode
  230.     mov    ax, 3
  231.         int  0x10
  232.  
  233. if lang eq ru
  234.  ; Load & set russian VGA font (RU.INC)
  235.         mov  bp,RU_FNT1-10000h   ; RU_FNT1 - First part
  236.           mov  bx,1000h            ; 768 bytes
  237.           mov  cx,30h              ; 48 symbols
  238.           mov  dx,80h              ; 128 - position of first symbol
  239.         mov  ax,1100h
  240.           int  10h
  241.  
  242.         mov  bp,RU_FNT2-10000h   ; RU_FNT2 -Second part
  243.         mov  bx,1000h            ; 512 bytes
  244.         mov  cx,20h              ; 32 symbols
  245.         mov  dx,0E0h             ; 224 - position of first symbol
  246.         mov  ax,1100h
  247.           int  10h
  248.  ; End set VGA russian font
  249. end if
  250.  
  251. ; draw frames
  252.     push    0xb800
  253.     pop    es
  254.     xor    di, di
  255. ;        mov  si,d80x25-0x10000
  256. ;        mov  cx,80*25
  257. ;        mov  ah,1*16+15
  258. ;       dfl1:
  259. ;        lodsb
  260. ;        stosw
  261. ;        loop dfl1
  262.     mov    ah, 1*16+15
  263. ; draw top
  264.     mov    si, d80x25_top - 0x10000
  265.     mov    cx, d80x25_top_num * 80
  266. @@:
  267.     lodsb
  268.     stosw
  269.     loop    @b
  270. ; draw spaces
  271.     mov    si, space_msg - 0x10000
  272.     mov    cx, 25 - d80x25_top_num - d80x25_bottom_num
  273. dfl1:
  274.     push    cx
  275.     push    si
  276.     mov    cx, 80
  277. @@:
  278.     lodsb
  279.     stosw
  280.     loop    @b
  281.     pop    si
  282.     pop    cx
  283.     loop    dfl1
  284. ; draw bottom
  285.     mov    si, d80x25_bottom - 0x10000
  286.     mov    cx, d80x25_bottom_num * 80
  287. @@:
  288.     lodsb
  289.     stosw
  290.     loop    @b
  291.  
  292.     mov    byte [space_msg-0x10000+80], 0    ; now space_msg is null terminated
  293.  
  294.     _setcursor d80x25_top_num,0
  295.  
  296.  
  297. ; TEST FOR 386+
  298.  
  299.     mov    bx, 0x4000
  300.         pushf
  301.         pop     ax
  302.         mov     dx,ax
  303.         xor     ax,bx
  304.         push    ax
  305.         popf
  306.         pushf
  307.         pop     ax
  308.         and     ax,bx
  309.         and     dx,bx
  310.         cmp     ax,dx
  311.         jnz     cpugood
  312.         mov     si,not386-0x10000
  313. sayerr:
  314.         call    print
  315.         jmp     $
  316.      cpugood:
  317.  
  318. ; set up esp
  319.     movzx    esp, sp
  320.  
  321. ; FLUSH 8042 KEYBOARD CONTROLLER
  322.  
  323. ;// mike.dld [
  324.  ;       mov     al,0xED
  325.  ;       out     0x60,al
  326.  ;       or      cx,-1
  327.  ;     @@:
  328.  ;       in      al,0x64
  329.  ;       test    al,2
  330.  ;       jz      @f
  331.  ;       loop    @b
  332.  ;     @@:
  333.  ;       mov     al,0
  334.  ;       out     0x60,al
  335.  ;       or      cx,-1
  336.  ;     @@:
  337.  ;       in      al,0x64
  338.  ;       test    al,2
  339.  ;       jz      @f
  340.  ;       loop    @b
  341.  ;     @@:
  342. ;// mike.dld ]
  343.  
  344. ;       mov     ecx,10000
  345. ;      fl1:
  346. ;       in      al,0x64
  347. ;       loop    fl1
  348. ;       test    al,1
  349. ;       jz      fl2
  350. ;       in      al,0x60
  351. ;       jmp     fl1
  352. ;      fl2:
  353.  
  354. ;****************************************************************
  355. ; The function is modified Mario79
  356. ;*****************************************************************
  357. ; wait_kbd:        ; variant 1
  358. ;       mov      cx,2500h  ;çàäåðæêà ïîðÿäêà 10 ìñåê
  359. ; test_kbd:
  360. ;       in       al,64h    ;÷èòàåì ñîñòîÿíèå êëàâèàòóðû
  361. ;       test     al,2      ;ïðîâåðêà áèòà ãîòîâíîñòè
  362. ;       loopnz   test_kbd
  363.  
  364.         push    0
  365.         pop     es
  366.         and     word [es:0x9031], 0
  367. ; \begin{Mario79}
  368. ; find HDD IDE DMA PCI device
  369. ; check for PCI BIOS
  370.         mov     ax, 0xB101
  371.         int     0x1A
  372.         jc      .nopci
  373.         cmp     edx, 'PCI '
  374.         jnz     .nopci
  375. ; find PCI class code
  376. ; class 1 = mass storage
  377. ; subclass 1 = IDE controller
  378. ; a) class 1, subclass 1, programming interface 0x80
  379.         mov     ax, 0xB103
  380.         mov     ecx, 1*10000h + 1*100h + 0x80
  381.         mov     si, 0   ; device index = 0
  382.         int     0x1A
  383.         jnc     .found
  384. ; b) class 1, subclass 1, programming interface 0x85
  385.         mov     ax, 0xB103
  386.         mov     ecx, 1*10000h + 1*100h + 0x85
  387.         mov     si, 0   ; device index = 0
  388.         int     0x1A
  389.         jnc     .found
  390. ; c) class 1, subclass 1, programming interface 0x8A
  391.         mov     ax, 0xB103
  392.         mov     ecx, 1*10000h + 1*100h + 0x8A
  393.         mov     si, 0
  394.         int     0x1A
  395.         jc      .nopci
  396. .found:
  397. ; get memory base
  398.         mov     ax, 0xB10A
  399.         mov     di, 0x20        ; memory base is config register at 0x20
  400.         int     0x1A
  401.         jc      .nopci
  402.         and     cx, 0xFFF0      ; clear address decode type
  403.         mov     [es:0x9031], cx
  404. .nopci:
  405. ; \end{Mario79}
  406.  
  407.     mov   al,0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
  408.     out   0x60,al
  409.     xor   cx,cx
  410. wait_loop:       ; variant 2
  411. ; reading state of port of 8042 controller
  412.         in      al,64h
  413.         and     al,00000010b  ; ready flag
  414. ; wait until 8042 controller is ready
  415.         loopnz  wait_loop
  416.  
  417. ; --------------- APM ---------------------
  418.     push    0
  419.     pop    es
  420.     mov    word [es : 0x9044], 0        ; ver = 0.0 (APM not found)
  421.     mov    ax, 0x5300
  422.     xor    bx, bx
  423.     int    0x15
  424.     jc    apm_end                ; APM not found
  425.     test    cx, 2
  426.     jz    apm_end                ; APM 32-bit protected-mode interface not supported
  427.     mov    [es : 0x9044], ax        ; Save APM Version
  428.     mov    [es : 0x9046], cx        ; Save APM flags
  429.  
  430.     ; Write APM ver ----
  431.     and    ax, 0xf0f
  432.     add    ax, '00'
  433.     mov    si, msg_apm - 0x10000
  434.     mov    [si + 5], ah
  435.     mov    [si + 7], al
  436.     _setcursor 0, 3
  437.     call    printplain
  438.     _setcursor d80x25_top_num,0
  439.     ; ------------------
  440.  
  441.     mov    ax, 0x5304            ; Disconnect interface
  442.     xor    bx, bx
  443.     int    0x15
  444.     mov    ax, 0x5303            ; Connect 32 bit mode interface
  445.     xor    bx, bx
  446.     int    0x15
  447.     ; init selectors
  448.     movzx    eax, ax ; real-mode segment base address of protected-mode 32-bit code segment
  449.     shl    eax, 4
  450.     mov    [apm_code_32 - 0x10000 + 2], ax
  451.     shr    eax, 16
  452.     mov    [apm_code_32 - 0x10000 + 4], al
  453.     movzx    ecx, cx ; real-mode segment base address of protected-mode 16-bit code segment
  454.     shl    ecx, 4
  455.     mov    [apm_code_16 - 0x10000 + 2], cx
  456.     shr    ecx, 16
  457.     mov    [apm_code_16 - 0x10000 + 4], cl
  458.     movzx    edx, dx ; real-mode segment base address of protected-mode 16-bit data segment
  459.     shl    edx, 4
  460.     mov    [apm_data_16 - 0x10000 + 2], dx
  461.     shr    edx, 16
  462.     mov    [apm_data_16 - 0x10000 + 4], dl
  463.     mov    [es : 0x9040], ebx              ; offset of APM entry point
  464. apm_end:
  465. ; -----------------------------------------
  466.  
  467. ; DISPLAY VESA INFORMATION
  468.  
  469.     push    0
  470.     pop    es
  471.         mov     ax,0x4f00
  472.         mov     di,0xa000
  473.         int     0x10
  474.         cmp     ax,0x004f
  475.         mov    si, novesa-0x10000
  476.         jnz    @f
  477.         mov bx, word [es:di+0x12]
  478.         shl ebx,16
  479.         mov [es:0x9050], ebx
  480.         mov     ax,[es:di+4]
  481.         add     ax,'0'*256+'0'
  482.         mov    si,vervesa-0x10000
  483.         mov     [si+vervesa_off], ah
  484.         mov     [si+vervesa_off+2], al
  485. @@:     call    print
  486.  
  487. ; \begin{diamond}[30.11.2005]
  488. cfgmanager:
  489. ; settings:
  490. ; a) preboot_graph = graphical mode
  491. ;    preboot_gprobe = probe this mode?
  492. ; b) preboot_mtrr = use hardware acceleration?
  493. ; c) preboot_vrrm = use VRR?
  494. ; d) preboot_device = from what boot?
  495.     mov    di, preboot_graph-0x10000
  496. ; check bootloader block
  497.     cmp    [.loader_block-0x10000], -1
  498.     jz    .noloaderblock
  499.     les    bx, [.loader_block-0x10000]
  500.     cmp    byte [es:bx], 1
  501.     mov    si, loader_block_error-0x10000
  502.     jnz    sayerr
  503.     test    byte [es:bx+1], 1
  504.     jz    @f
  505. ; image in memory present
  506.     cmp    [di+preboot_device-preboot_graph], 0
  507.     jnz    @f
  508.     mov    [di+preboot_device-preboot_graph], 3
  509. @@:
  510. .noloaderblock:
  511. ; determine default settings
  512.     mov    [.bSettingsChanged-0x10000], 0
  513.     cmp    byte [di], 0
  514.     jnz    .preboot_gr_end
  515.     mov    [di+preboot_gprobe-preboot_graph], 0
  516.     mov    al, [vervesa+vervesa_off-0x10000]
  517.     cmp    al, 'x'
  518.     jz    .novesa
  519.     cmp    al, '1'
  520.     jz    .vesa12
  521.     mov    [di+preboot_gprobe-preboot_graph], 2
  522.     mov    al, 3
  523.     jmp    @f
  524. .vesa12:
  525.     mov    al, 7
  526.     jmp    @f
  527. .novesa:
  528.     mov    al, 10
  529. @@:
  530.     mov    [di], al
  531. .preboot_gr_end:
  532.     cmp    [di+preboot_mtrr-preboot_graph], 1
  533.     adc    [di+preboot_mtrr-preboot_graph], 0
  534.     cmp    [di+preboot_vrrm-preboot_graph], 1
  535.     adc    [di+preboot_vrrm-preboot_graph], 0
  536.     cmp    [di+preboot_device-preboot_graph], 1
  537.     adc    [di+preboot_device-preboot_graph], 0
  538. ; notify user
  539.     mov    si, linef-0x10000
  540.     call    print
  541.     mov    si, start_msg-0x10000
  542.     call    print
  543.     mov    si, time_msg-0x10000
  544.     call    print
  545. ; get start time
  546.     call    .gettime
  547.     mov    [.starttime-0x10000], eax
  548.     mov    word [.timer-0x10000], .newtimer
  549.     mov    word [.timer-0x10000+2], cs
  550. .printcfg:
  551.     _setcursor 9,0
  552.     mov    si, current_cfg_msg-0x10000
  553.     call    print
  554.     mov    si, curvideo_msg-0x10000
  555.     call    print
  556.     mov    al, [preboot_graph-0x10000]
  557.     cmp    al, 8
  558.     ja    .pnovesa
  559.     mov    dl, al
  560.     and    eax, 3
  561.     mov    si, [modes_msg-0x10000+eax*2]
  562.     call    printplain
  563.     mov    si, modevesa20-0x10000
  564.     cmp    dl, 4
  565.     jbe    @f
  566.     mov    si, modevesa12-0x10000
  567. @@:
  568.     call    printplain
  569.     cmp    dl, 4
  570.     ja    .x
  571.     mov    si, probeno_msg-0x10000
  572.     cmp    [preboot_gprobe-0x10000], 2
  573.     jnz    @f
  574.     mov    si, probeok_msg-0x10000
  575. @@:
  576.     call    printplain
  577. .x:
  578.     jmp    .c
  579. .pnovesa:
  580.     cmp    al, 9
  581.     mov    si, mode9-0x10000
  582.     jz    @b
  583.     mov    si, mode10-0x10000
  584.     jmp    @b
  585. .c:
  586.     mov    si, linef-0x10000
  587.     call    printplain
  588.     mov    si, mtrr_msg-0x10000
  589.     cmp    [preboot_mtrr-0x10000], 1
  590.     call    .say_on_off
  591.     mov    si, vrrm_msg-0x10000
  592.     cmp    [preboot_vrrm-0x10000], 1
  593.     call    .say_on_off
  594.     mov    si, preboot_device_msg-0x10000
  595.     call    print
  596.     mov    al, [preboot_device-0x10000]
  597.     and    eax, 3
  598.     mov    si, [preboot_device_msgs-0x10000+eax*2]
  599.     call    printplain
  600. .wait:
  601.     _setcursor 25,0        ; out of screen
  602. ; set timer interrupt handler
  603.     cli
  604.     push    0
  605.     pop    es
  606.     mov    eax, [es:8*4]
  607.     mov    [.oldtimer-0x10000], eax
  608.     mov    eax, [.timer-0x10000]
  609.     mov    [es:8*4], eax
  610.     sti
  611. ; wait for keypressed
  612.     mov    ah, 0
  613.     int    16h
  614.     push    ax
  615. ; restore timer interrupt
  616.     push    0
  617.     pop    es
  618.     mov    eax, [.oldtimer-0x10000]
  619.     mov    [es:8*4], eax
  620.     mov    [.timer-0x10000], eax
  621.     _setcursor 7,0
  622.     mov    si, space_msg-0x10000
  623.     call    printplain
  624.     pop    ax
  625. ; switch on key
  626.     cmp    al, 13
  627.     jz    .continue
  628.     or    al, 20h
  629.     cmp    al, 'a'
  630.     jz    .change_a
  631.     cmp    al, 'b'
  632.     jz    .change_b
  633.     cmp    al, 'c'
  634.     jz    .change_c
  635.     cmp    al, 'd'
  636.     jnz    .wait
  637.     _setcursor 15,0
  638.     mov     si,bdev-0x10000
  639.     call    print
  640.     mov     bx,'13'
  641.     call    getkey
  642.     mov    [preboot_device-0x10000], al
  643.     _setcursor 13,0
  644. .d:
  645.     mov    [.bSettingsChanged-0x10000], 1
  646.     mov    si, space_msg-0x10000
  647.     call    printplain
  648.     _setcursor 15,0
  649.     mov    cx, 6
  650. @@:
  651.     call    printplain
  652.     loop    @b
  653.     jmp    .printcfg
  654. .change_a:
  655.     _setcursor 15,0
  656.     mov    si, gr_mode-0x10000
  657.     call    printplain
  658.     mov     bx, '09'
  659.     call    getkey
  660.     mov    [preboot_graph-0x10000], al
  661.     cmp    al, 4
  662.     ja    @f
  663.     mov    si, probetext-0x10000
  664.     call    printplain
  665.     mov    bx, '12'
  666.     call    getkey
  667.     mov    [preboot_gprobe-0x10000], al
  668. @@:
  669.     _setcursor 10,0
  670.     jmp    .d
  671. .change_b:
  672.     _setcursor 15,0
  673.     mov    si, gr_acc-0x10000
  674.     call    print
  675.     mov    bx, '12'
  676.     call    getkey
  677.     mov    [preboot_mtrr-0x10000], al
  678.     _setcursor 11,0
  679.     jmp    .d
  680. .change_c:
  681.     _setcursor 15,0
  682.     mov    si, vrrmprint-0x10000
  683.     call    print
  684.     mov    bx, '12'
  685.     call    getkey
  686.     mov    [preboot_vrrm-0x10000], al
  687.     _setcursor 12,0
  688.     jmp    .d
  689. .say_on_off:
  690.     pushf
  691.     call    print
  692.     mov    si, on_msg-0x10000
  693.     popf
  694.     jz    @f
  695.     mov    si, off_msg-0x10000
  696. @@:    call    printplain
  697.     ret
  698. ; novesa and vervesa strings are not used at the moment of executing this code
  699. virtual at novesa
  700. .oldtimer dd ?
  701. .starttime dd ?
  702. .bSettingsChanged db ?
  703. .timer dd ?
  704. end virtual
  705.         org $+0x10000
  706. .loader_block dd -1
  707.         org $-0x10000
  708. .gettime:
  709.     mov    ah, 0
  710.     int    1Ah
  711.     xchg    ax, cx
  712.     shl    eax, 10h
  713.     xchg    ax, dx
  714.     ret
  715. .newtimer:
  716.     push    ds
  717.     push    cs
  718.     pop    ds
  719.     pushf
  720.     call    [.oldtimer-0x10000]
  721.     pushad
  722.     call    .gettime
  723.     sub    eax, [.starttime-0x10000]
  724.     sub    ax, 18*5
  725.     jae    .timergo
  726.     neg    ax
  727.     add    ax, 18-1
  728.     mov    bx, 18
  729.     xor    dx, dx
  730.     div    bx
  731. if lang eq ru
  732. ; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
  733.     cmp    al, 5
  734.     mov    cl, ' '
  735.     jae    @f
  736.     cmp    al, 1
  737.     mov    cl, 'ã'
  738.     jz    @f
  739.     mov    cl, 'ë'
  740. @@:    mov    [time_str+9-0x10000], cl
  741. else
  742. ; wait 5/4/3/2 seconds, 1 second
  743.     cmp    al, 1
  744.     mov    cl, 's'
  745.     ja    @f
  746.     mov    cl, ' '
  747. @@:    mov    [time_str+9-0x10000], cl
  748. end if
  749.     add    al, '0'
  750.     mov    [time_str+1-0x10000], al
  751.     mov    si, time_msg-0x10000
  752.     _setcursor 7,0
  753.     call    print
  754.     _setcursor 25,0
  755.     popad
  756.     pop    ds
  757.     iret
  758. .timergo:
  759.     push    0
  760.     pop    es
  761.     mov    eax, [.oldtimer-0x10000]
  762.     mov    [es:8*4], eax
  763.     mov    sp, 0EC00h
  764. .continue:
  765.     sti
  766.     _setcursor 6,0
  767.     mov    si, space_msg-0x10000
  768.     call    printplain
  769.     call    printplain
  770.     _setcursor 6,0
  771.     mov    si, loading_msg-0x10000
  772.     call    print
  773.     _setcursor 15,0
  774.     cmp    [.bSettingsChanged-0x10000], 0
  775.     jz    .load
  776.     cmp    [.loader_block-0x10000], -1
  777.     jz    .load
  778.     les    bx, [.loader_block-0x10000]
  779.     mov    eax, [es:bx+3]
  780.     push    ds
  781.     pop    es
  782.     test    eax, eax
  783.     jz    .load
  784.     push    eax
  785.     mov    si, save_quest-0x10000
  786.     call    print
  787. .waityn:
  788.     mov    ah, 0
  789.     int    16h
  790.     or    al, 20h
  791.     cmp    al, 'n'
  792.     jz    .loadc
  793.     cmp    al, 'y'
  794.     jnz    .waityn
  795.     call    putchar
  796.     mov    byte [space_msg-0x10000+80], 186
  797.     pop    eax
  798.     push    cs
  799.     push    .cont
  800.     push    eax
  801.     retf
  802. .loadc:
  803.     pop    eax
  804. .cont:
  805.     push    cs
  806.     pop    ds
  807.     mov    si, space_msg-0x10000
  808.     mov    byte [si+80], 0
  809.     _setcursor 15,0
  810.     call    printplain
  811.     _setcursor 15,0
  812. .load:
  813. ; \end{diamond}[02.12.2005]
  814.  
  815. ; ASK GRAPHICS MODE
  816.  
  817.     movzx    ax, [preboot_graph-0x10000]
  818.     push    0
  819.     pop    es
  820. ; address is gr_table+6*(ax-1)-0x10000
  821.         add    ax, ax
  822.         lea    si, [gr_table-0x10000 + eax + eax*2 - 6]
  823.         mov     bx,[si+0]
  824.         mov     cx,[si+2]
  825.         mov     dx,[si+4]
  826.         cmp    al, 9*2
  827.         mov    al, 32    ; BPP
  828.         jb    @f
  829.         mov    [es:0x9000], al
  830.         mov    dword [es:0x9018], 0xFFFFFFFF; 0x800000
  831.        @@:
  832.         mov     [es:0x9008],bx
  833.         mov     [es:0x900A],cx
  834.         mov     [es:0x900C],dx
  835.         test    bh, bh
  836.         jz    nov
  837.  
  838. ; USE DEFAULTS OR PROBE
  839.  
  840. ; bx - mode : cx - x size : dx - y size
  841.     cmp    [preboot_gprobe-0x10000], 1
  842.     jz    noprobe
  843.  
  844.         mov     bx,0x100
  845.      newprobe:
  846.         inc     bx
  847.         cmp     bx,0x17f
  848.         mov    si,prnotfnd-0x10000
  849.         jz    sayerr
  850.  
  851.      probemore:
  852.          push    cx
  853.         mov     ax,0x4f01
  854.         mov     cx,bx
  855.         and     cx,0xfff
  856.         mov     di,0xa000
  857.         int     0x10
  858.         pop    cx
  859.  
  860.     test    byte [es:di], 80h    ; lfb?
  861.     jz    newprobe
  862.     cmp    [es:di+0x12], cx    ; x size?
  863.     jnz    newprobe
  864.     cmp    [es:di+0x14], dx    ; y size?
  865.     jnz    newprobe
  866.     cmp    byte [es:di+0x19], 32 ;24
  867.     jb    newprobe
  868.  
  869. ;       add     bx,0100000000000000b
  870.     or    bh, 40h
  871.         mov     [es:0x9008],bx
  872.  
  873.      noprobe:
  874.  
  875.  
  876. ; FIND VESA 2.0 LFB & BPP
  877.  
  878.         mov     ax,0x4f01
  879.         mov     cx,bx
  880.         and     cx,0xfff
  881.         mov     di,0xa000
  882.         int     0x10
  883.         ; LFB
  884.         mov     eax,[es:di+0x28]
  885.         mov     [es:0x9018],eax
  886.         ; ---- vbe voodoo
  887.         BytesPerScanLine equ 0x10
  888.         mov ax, [es:di+BytesPerScanLine]
  889.         mov [es:0x9001],ax
  890.         ; BPP
  891.         mov     al,byte [es:di+0x19]
  892.         mov     [es:0x9000],al
  893.        nov:
  894.         cmp     al,24
  895.         mov    si,bt24-0x10000
  896.         jz    bppl
  897.         cmp     al,32
  898.         mov     si,bt32-0x10000
  899.         jz     bppl
  900.         mov     si,btns-0x10000
  901.         jmp    sayerr
  902.        bppl:
  903.         call    print
  904.  
  905.  
  906. ; FIND VESA 1.2 PM BANK SWITCH ADDRESS
  907.  
  908.     push    es
  909.         mov     ax,0x4f0A
  910.         xor    bx, bx
  911.         int     0x10
  912.         xor     eax,eax
  913.         mov     ax,es
  914.         shl     eax,4
  915.         movzx   ebx,di
  916.         add     eax,ebx
  917.         mov     bx,[es:di]
  918.         add     eax,ebx
  919.         pop     es
  920.         mov     [es:0x9014],eax
  921.  
  922.  
  923. ; GRAPHICS ACCELERATION
  924.  
  925.         mov     al, [preboot_mtrr-0x10000]
  926.         mov     [es:0x901C],al
  927.  
  928. ; VRR_M USE
  929.  
  930.         mov     al,[preboot_vrrm-0x10000]
  931.         mov     [es:0x9030],al
  932.  
  933.  
  934. ; MEMORY MODEL
  935.  
  936. ;        movzx   eax,byte [es:preboot_memory-0x10000]
  937. ;        cmp     eax,0
  938. ;        jne     pre_mem
  939. ;;;;;;;;;;;;;;;;;;;;;;;;;
  940. ; mario79 - memory size ;
  941. ;;;;;;;;;;;;;;;;;;;;;;;;;
  942. ;           mov ax,0E801h
  943. ;;;           xor bx,bx    ; thanks to Alexei for bugfix [18.07.2004]
  944. ;           xor cx, cx
  945. ;           xor dx, dx
  946. ;           int 0x15
  947. ;           movzx ebx, dx ;bx
  948. ;           movzx eax, cx ;ax
  949. ;           shl   ebx,6   ; ïåðåâîä â êèëîáàéòû (x64)
  950. ;           add   eax,ebx
  951. ;           add eax, 1000h ;440h
  952. ;           cmp eax,40000h ; 256?
  953. ;           jge mem_256_z
  954. ;           cmp eax,20000h ; 128?
  955. ;           jge mem_128_z
  956. ;           cmp eax,10000h ; 64?
  957. ;           jge mem_64_z
  958. ;           cmp eax,8000h ; 32?
  959. ;           jge mem_32_z
  960. ;           jmp mem_16_z
  961. ;
  962. ;mem_256_z: mov     si,memokz256-0x10000
  963. ;           call    printplain
  964. ;           mov eax,5
  965. ;           jmp pre_mem
  966. ;mem_128_z: mov     si,memokz128-0x10000
  967. ;           call    printplain
  968. ;           mov eax,4
  969. ;           jmp pre_mem
  970. ;mem_64_z:  mov     si,memokz64-0x10000
  971. ;           call    printplain
  972. ;           mov eax,3
  973. ;           jmp pre_mem
  974. ;mem_32_z:  mov     si,memokz32-0x10000
  975. ;           call    printplain
  976. ;           mov eax,2
  977. ;           jmp pre_mem
  978. ;mem_16_z:  mov     si,memokz16-0x10000
  979. ;           call    printplain
  980. ;           mov eax,1
  981. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  982. ;      pre_mem:
  983. ;        push    word 0x0000
  984. ;        pop     es
  985. ;        mov     [es:0x9030],al
  986. ;        push    word 0x1000
  987. ;        pop     es
  988. ;        mov     si,linef-0x10000
  989. ;        call    printplain
  990.  
  991.  
  992.  
  993.  
  994. ; DIRECT WRITE TO LFB, PAGING DISABLED
  995.  
  996. ;        movzx   eax,byte [es:preboot_lfb-0x10000]
  997. ;        mov     eax,1                             ; paging disabled
  998. ;        cmp     eax,0
  999. ;        jne     pre_lfb
  1000. ;        mov     si,gr_direct-0x10000
  1001. ;        call    printplain
  1002. ;        mov     ebx,'12'
  1003. ;        call    getkey
  1004. ;      pre_lfb:
  1005. ;        push    word 0x0000
  1006. ;        pop     es
  1007. ;        mov     [es:0x901E],al
  1008. ;        mov     ax,0x1000
  1009. ;        mov     es,ax
  1010. ;        mov     si,linef-0x10000
  1011. ;        call    printplain
  1012.         mov     [es:0x901E],byte 1
  1013.  
  1014.  
  1015.  
  1016. ; BOOT DEVICE
  1017.  
  1018.     mov    al, [preboot_device-0x10000]
  1019.         dec     al
  1020.         mov     [boot_dev-0x10000],al
  1021.  
  1022. ; READ DISKETTE TO MEMORY
  1023.  
  1024. ;        cmp     [boot_dev-0x10000],0
  1025.         jne     no_sys_on_floppy
  1026.         mov     si,diskload-0x10000
  1027.         call    print
  1028.         xor    ax, ax            ; reset drive
  1029.         xor    dx, dx
  1030.         int     0x13
  1031. ; now load floppy image to memory
  1032. ; at first load boot sector and first FAT table
  1033.         mov     cx, 0x0001      ; startcyl,startsector
  1034.         xor     dx, dx          ; starthead,drive
  1035.         mov     al, 1+9         ; no of sectors to read
  1036.         mov     bx, 0xB000      ; es:bx -> data area
  1037.         call    boot_read_floppy
  1038. ; and copy them to extended memory
  1039.         mov     si, movedesc-0x10000
  1040.         mov     [si+8*2+3], bh
  1041.         push    es
  1042.         push    ds
  1043.         pop     es
  1044.         mov     cx, 256*10
  1045.         mov     ah, 0x87
  1046.         int     0x15
  1047.         test    ah, ah
  1048.         jz      @f
  1049. sayerr_floppy:
  1050.         mov     dx, 0x3f2
  1051.         mov     al, 0
  1052.         out     dx, al
  1053.         mov     si, memmovefailed-0x10000
  1054.         jmp     sayerr_plain
  1055. @@:
  1056.         add     dword [si+8*3+2], 512*10
  1057. ; copy FAT to second copy
  1058.         mov     byte [si+8*2+3], 0xB2
  1059.         mov     cx, 256*9
  1060.         mov     ah, 0x87
  1061.         int     0x15
  1062.         pop     es
  1063.         test    ah, ah
  1064.         jnz     sayerr_floppy
  1065.         add     dword [si+8*3+2], 512*9
  1066. ; calculate total number of sectors to read
  1067.         mov     ax, 1+9+14      ; boot+FAT+root
  1068.         mov     di, 0xB203
  1069. .calc_loop:
  1070.         test    word [es:di], 0xFFF
  1071.         jz      @f
  1072.         inc     ax
  1073. @@:
  1074.         test    word [es:di+1], 0xFFF0
  1075.         jz      @f
  1076.         inc     ax
  1077. @@:
  1078.         add     di, 3
  1079.         cmp     di, 0xB200+1440*3
  1080.         jb      .calc_loop
  1081.         push    ax
  1082.         mov     bp, 1+9         ; already read sectors
  1083. ; now read rest
  1084.         mov     byte [si+8*2+3], 0xA0
  1085.         mov     di, 2-14        ; absolute sector-31
  1086.         mov     cx, 0x0002      ; cylinder=0, sector=2
  1087.         mov     dx, 0x0100      ; head=1, disk=0
  1088. .read_loop:
  1089. ; determine whether sector must be read
  1090.         cmp     di, 2
  1091.         jl      .read
  1092.         mov     bx, di
  1093.         shr     bx, 1
  1094.         jnc     .even
  1095.         test    word [es:bx+di+0xB200], 0xFFF0
  1096.         jmp     @f
  1097. .even:
  1098.         test    word [es:bx+di+0xB200], 0xFFF
  1099. @@:
  1100.         jz      .skip
  1101. .read:
  1102.         mov     bx, 0xA000
  1103.         mov     al, 1           ; 1 sector
  1104.         call    boot_read_floppy
  1105.         inc     bp
  1106.         push    es
  1107.         push    ds
  1108.         pop     es
  1109.         pusha
  1110.         mov     cx, 256
  1111.         mov     ah, 0x87
  1112.         int     0x15
  1113.         test    ah, ah
  1114.         popa
  1115.         pop     es
  1116.         jnz     sayerr_floppy
  1117. .skip:
  1118.         add     dword [si+8*3+2], 512
  1119.         inc     cx
  1120.         cmp     cl, 19
  1121.         jnz     @f
  1122.         mov     cl, 1
  1123.         inc     dh
  1124.         cmp     dh, 2
  1125.         jnz     @f
  1126.         mov     dh, 0
  1127.         inc     ch
  1128. @@:
  1129.         pop     ax
  1130.         push    ax
  1131.         pusha
  1132. ; draw percentage
  1133. ; total sectors: ax
  1134. ; read sectors: bp
  1135.         xchg    ax, bp
  1136.         mov     cx, 100
  1137.         mul     cx
  1138.         div     bp
  1139.         aam
  1140.         xchg    al, ah
  1141.         add     ax, '00'
  1142.         mov     si, pros-0x10000
  1143.         cmp     [si], ax
  1144.         jz      @f
  1145.         mov     [si], ax
  1146.         call    printplain
  1147. @@:
  1148.         popa
  1149.         inc     di
  1150.         cmp     di, 2880-31
  1151.         jnz     .read_loop
  1152.  
  1153. ;        mov     cx, 0x0001      ; startcyl,startsector
  1154. ;        xor     dx, dx          ; starthead,drive
  1155. ;        push    word 80*2               ; read no of sect
  1156. ;       reads:
  1157. ;        pusha
  1158. ;        xor     si,si
  1159. ;       newread:
  1160. ;        mov     bx,0xa000               ; es:bx -> data area
  1161. ;        mov     ax,0x0200+18            ; read, no of sectors to read
  1162. ;        int     0x13
  1163. ;        test    ah, ah
  1164. ;        jz      goodread
  1165. ;        inc    si
  1166. ;        cmp     si,10
  1167. ;        jnz     newread
  1168. ;        mov     si,badsect-0x10000
  1169. ;sayerr_plain:
  1170. ;        call    printplain
  1171. ;        jmp     $
  1172. ;       goodread:
  1173. ;        ; move -> 1mb
  1174. ;        mov     si,movedesc-0x10000
  1175. ;        push    es
  1176. ;        push    ds
  1177. ;        pop     es
  1178. ;        mov     cx,256*18
  1179. ;        mov     ah,0x87
  1180. ;        int     0x15
  1181. ;        pop    es
  1182. ;
  1183. ;        test    ah,ah                  ; was the move successfull ?
  1184. ;        je      goodmove
  1185. ;        mov     dx,0x3f2              ; floppy motor off
  1186. ;        mov     al,0
  1187. ;        out     dx,al
  1188. ;        mov     si,memmovefailed-0x10000
  1189. ;        jmp    sayerr_plain
  1190. ;      goodmove:
  1191. ;
  1192. ;    add    dword [movedesc-0x10000+0x18+2], 512*18
  1193. ;        popa
  1194. ;        inc     dh
  1195. ;        cmp     dh,2
  1196. ;        jnz     bb2
  1197. ;        mov     dh,0
  1198. ;        inc     ch
  1199. ;        pusha                        ; print prosentage
  1200. ;        mov     si,pros-0x10000
  1201. ;    shr    ch, 2
  1202. ;    mov    al, '5'
  1203. ;    test    ch, 1
  1204. ;    jnz    @f
  1205. ;    mov    al, '0'
  1206. ;@@:
  1207. ;    mov    [si+1], al
  1208. ;    shr    ch, 1
  1209. ;    add    ch, '0'
  1210. ;    mov    [si], ch
  1211. ;        call    printplain
  1212. ;        popa
  1213. ;       bb2:
  1214. ;        pop     ax
  1215. ;        dec     ax
  1216. ;        push    ax
  1217. ;        jnz     reads
  1218. ;       readdone:
  1219. ;        pop     ax
  1220.         mov     si,backspace2-0x10000
  1221.         call    printplain
  1222.         mov     si,okt-0x10000
  1223.         call    printplain
  1224.        no_sys_on_floppy:
  1225.         xor    ax, ax        ; reset drive
  1226.         xor    dx, dx
  1227.         int     0x13
  1228.        mov dx,0x3f2 ; floppy motor off
  1229.        mov al,0
  1230.        out dx,al
  1231.  
  1232.     push    es
  1233. ; PAGE TABLE
  1234.  
  1235.     push    dword [es:0x9018]
  1236. ;
  1237. ;        mmap_mem equ 64                ; amount of memory to map
  1238. ;
  1239.         push    0x6000
  1240.         pop    es                    ; es:di = 6000:0
  1241. ;        xor     di,di
  1242. ;        mov     cx,256*mmap_mem         ; Map (mapmem) M
  1243. ;; initialize as identity mapping
  1244. ;        xor    eax, eax
  1245. ;        call    pagetable_set
  1246. ;
  1247. ;
  1248. ; 4 KB PAGE DIRECTORY
  1249. ;
  1250.        push    0x7F00
  1251.        pop    es                ; es:di = 7F00:0
  1252. ;        xor     di, di
  1253. ;        mov     cx, 64 / 4
  1254. ;        mov     eax, 0x60007            ; for 0 M
  1255. ;        call    pagetable_set
  1256. ;        xor     si,si
  1257. ;        mov     di,second_base_address shr 20
  1258. ;        mov     cx,64/2
  1259. ;        rep     movs word [es:di], [es:si]
  1260.  
  1261. ;        mov     eax, 0x7F000 +8+16      ; Page directory and enable caches
  1262. ;        mov     cr3, eax
  1263.  
  1264. ; SET GRAPHICS
  1265.  
  1266.     pop    es
  1267.  
  1268.         xor ax, ax
  1269.         mov es, ax
  1270.  
  1271.         mov   ax,[es:0x9008]        ; vga & 320x200
  1272.         mov    bx, ax
  1273.         cmp     ax,0x13
  1274.         je      setgr
  1275.         cmp     ax,0x12
  1276.         je      setgr
  1277.         mov     ax,0x4f02            ; Vesa
  1278.        setgr:
  1279.         int     0x10
  1280.         test    ah,ah
  1281.         mov    si, fatalsel-0x10000
  1282.         jnz    sayerr
  1283. ; set mode 0x12 graphics registers:
  1284.         cmp     bx,0x12
  1285.         jne     gmok2
  1286.  
  1287.         mov     al,0x05
  1288.         mov     dx,0x03ce
  1289.         push    dx
  1290.         out     dx,al      ; select GDC mode register
  1291.         mov     al,0x02
  1292.         inc    dx
  1293.         out     dx,al      ; set write mode 2
  1294.  
  1295.         mov     al,0x02
  1296.         mov     dx,0x03c4
  1297.         out     dx,al      ; select VGA sequencer map mask register
  1298.         mov     al,0x0f
  1299.         inc    dx
  1300.         out     dx,al      ; set mask for all planes 0-3
  1301.  
  1302.         mov     al,0x08
  1303.         pop    dx
  1304.         out     dx,al      ; select GDC bit mask register
  1305.                            ; for writes to 0x03cf
  1306.  
  1307.        gmok2:
  1308.         push    ds
  1309.         pop    es
  1310.