Subversion Repositories Kolibri OS

Rev

Rev 40 | Rev 82 | 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.     or    al, 7
  144. @@:
  145.     stosd
  146.     add    eax, 1000h
  147.     loop    @b
  148.     ret
  149.  
  150. ; 16-bit data
  151. ; videomodes table
  152. gr_table:
  153.     dw      0x112+0100000000000000b ,  640 ,  480        ; 1
  154.     dw      0x115+0100000000000000b ,  800 ,  600        ; 2
  155.     dw      0x118+0100000000000000b , 1024 ,  768        ; 3
  156.     dw      0x11B+0100000000000000b , 1280 , 1024        ; 4
  157.     dw      0x112 ,  640 , 480                ; 5
  158.     dw      0x115 ,  800 , 600                ; 6
  159.     dw      0x118 , 1024 , 768                ; 7
  160.     dw      0x11B , 1280 ,1024                ; 8
  161.     dw    0x13, 320, 200                    ; 9
  162.     dw    0x12, 640, 480                    ; 0
  163.  
  164. ; table for move to extended memory (int 15h, ah=87h)
  165.        movedesc:
  166.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  167.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  168.  
  169.         db      0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0
  170.         db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
  171.  
  172.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  173.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  174.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  175.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  176.  
  177. ;=========================================================================
  178. ;
  179. ;                           16 BIT CODE
  180. ;
  181. ;=========================================================================
  182.  
  183.  
  184. start_of_code:
  185.     cld
  186. ; \begin{diamond}[02.12.2005]
  187.     cmp    ax, 'KL'
  188.     jnz    @f
  189.     mov    word [cs:cfgmanager.loader_block-0x10000], si
  190.     mov    word [cs:cfgmanager.loader_block+2-0x10000], ds
  191. @@:
  192. ; \end{diamond}[02.12.2005]
  193.  
  194. ; set up stack
  195.     mov    ax, 3000h
  196.     mov    ss, ax
  197.     mov    sp, 0EC00h
  198. ; set up segment registers
  199.     push    cs
  200.     pop    ds
  201.     push    cs
  202.     pop    es
  203.  
  204. ; set videomode
  205.     mov    ax, 3
  206.         int  0x10
  207.  
  208.  ; Load & set russian VGA font (RU.INC)
  209.         mov  bp,RU_FNT1-10000h   ; RU_FNT1 - First part
  210.           mov  bx,1000h            ; 768 bytes
  211.           mov  cx,30h              ; 48 symbols
  212.           mov  dx,80h              ; 128 - position of first symbol
  213.         mov  ax,1100h
  214.           int  10h
  215.  
  216.         mov  bp,RU_FNT2-10000h   ; RU_FNT2 -Second part
  217.         mov  bx,1000h            ; 512 bytes
  218.         mov  cx,20h              ; 32 symbols
  219.         mov  dx,0E0h             ; 224 - position of first symbol
  220.         mov  ax,1100h
  221.           int  10h
  222.  ; End set VGA russian font
  223.  
  224. ; draw frames
  225.     push    0xb800
  226.     pop    es
  227.     xor    di, di
  228. ;        mov  si,d80x25-0x10000
  229. ;        mov  cx,80*25
  230. ;        mov  ah,1*16+15
  231. ;       dfl1:
  232. ;        lodsb
  233. ;        stosw
  234. ;        loop dfl1
  235.     mov    ah, 1*16+15
  236. ; draw top
  237.     mov    si, d80x25_top - 0x10000
  238.     mov    cx, d80x25_top_num * 80
  239. @@:
  240.     lodsb
  241.     stosw
  242.     loop    @b
  243. ; draw spaces
  244.     mov    si, space_msg - 0x10000
  245.     mov    cx, 25 - d80x25_top_num - d80x25_bottom_num
  246. dfl1:
  247.     push    cx
  248.     push    si
  249.     mov    cx, 80
  250. @@:
  251.     lodsb
  252.     stosw
  253.     loop    @b
  254.     pop    si
  255.     pop    cx
  256.     loop    dfl1
  257. ; draw bottom
  258.     mov    si, d80x25_bottom - 0x10000
  259.     mov    cx, d80x25_bottom_num * 80
  260. @@:
  261.     lodsb
  262.     stosw
  263.     loop    @b
  264.  
  265.     mov    byte [space_msg-0x10000+80], 0    ; now space_msg is null terminated
  266.  
  267.     _setcursor d80x25_top_num,0
  268.  
  269.  
  270. ; TEST FOR 386+
  271.  
  272.     mov    bx, 0x4000
  273.         pushf
  274.         pop     ax
  275.         mov     dx,ax
  276.         xor     ax,bx
  277.         push    ax
  278.         popf
  279.         pushf
  280.         pop     ax
  281.         and     ax,bx
  282.         and     dx,bx
  283.         cmp     ax,dx
  284.         jnz     cpugood
  285.         mov     si,not386-0x10000
  286. sayerr:
  287.         call    print
  288.         jmp     $
  289.      cpugood:
  290.  
  291. ; set up esp
  292.     movzx    esp, sp
  293.  
  294. ; FLUSH 8042 KEYBOARD CONTROLLER
  295.  
  296. ;// mike.dld [
  297.  ;       mov     al,0xED
  298.  ;       out     0x60,al
  299.  ;       or      cx,-1
  300.  ;     @@:
  301.  ;       in      al,0x64
  302.  ;       test    al,2
  303.  ;       jz      @f
  304.  ;       loop    @b
  305.  ;     @@:
  306.  ;       mov     al,0
  307.  ;       out     0x60,al
  308.  ;       or      cx,-1
  309.  ;     @@:
  310.  ;       in      al,0x64
  311.  ;       test    al,2
  312.  ;       jz      @f
  313.  ;       loop    @b
  314.  ;     @@:
  315. ;// mike.dld ]
  316.  
  317. ;       mov     ecx,10000
  318. ;      fl1:
  319. ;       in      al,0x64
  320. ;       loop    fl1
  321. ;       test    al,1
  322. ;       jz      fl2
  323. ;       in      al,0x60
  324. ;       jmp     fl1
  325. ;      fl2:
  326.  
  327. ;****************************************************************
  328. ; The function is modified Mario79
  329. ;*****************************************************************
  330. ; wait_kbd:        ; variant 1
  331. ;       mov      cx,2500h  ;çàäåðæêà ïîðÿäêà 10 ìñåê
  332. ; test_kbd:
  333. ;       in       al,64h    ;÷èòàåì ñîñòîÿíèå êëàâèàòóðû
  334. ;       test     al,2      ;ïðîâåðêà áèòà ãîòîâíîñòè
  335. ;       loopnz   test_kbd
  336.  
  337.     mov   al,0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
  338.     out   0x60,al
  339.     xor   cx,cx
  340. wait_loop:       ; variant 2
  341. ; reading state of port of 8042 controller
  342.         in      al,64h
  343.         and     al,00000010b  ; ready flag
  344. ; wait until 8042 controller is ready
  345.         loopnz  wait_loop
  346.  
  347. ; --------------- APM ---------------------
  348.     push    0
  349.     pop    es
  350.     mov    word [es : 0x9044], 0        ; ver = 0.0 (APM not found)
  351.     mov    ax, 0x5300
  352.     xor    bx, bx
  353.     int    0x15
  354.     jc    apm_end                ; APM not found
  355.     test    cx, 2
  356.     jz    apm_end                ; APM 32-bit protected-mode interface not supported
  357.     mov    [es : 0x9044], ax        ; Save APM Version
  358.     mov    [es : 0x9046], cx        ; Save APM flags
  359.    
  360.     ; Write APM ver ----
  361.     jmp    @f
  362. msg_apm:db    ' APM x.x ', 0
  363. @@:    and    ax, 0xf0f
  364.     add    ax, '00'
  365.     mov    [msg_apm - 0x10000 + 5], ah
  366.     mov    [msg_apm - 0x10000 + 7], al
  367.     _setcursor 0, 3
  368.     mov    si, msg_apm - 0x10000
  369.     call    printplain
  370.     _setcursor d80x25_top_num,0
  371.     ; ------------------
  372.    
  373.     mov    ax, 0x5304            ; Disconnect interface
  374.     xor    bx, bx
  375.     int    0x15
  376.     mov    ax, 0x5303            ; Connect 32 bit mode interface
  377.     xor    bx, bx
  378.     int    0x15
  379.     ; init selectors
  380.     movzx    eax, ax ; real-mode segment base address of protected-mode 32-bit code segment
  381.     shl    eax, 4
  382.     mov    [apm_code_32 - 0x10000 + 2], ax
  383.     shr    eax, 16
  384.     mov    [apm_code_32 - 0x10000 + 4], al
  385.     movzx    ecx, cx ; real-mode segment base address of protected-mode 16-bit code segment
  386.     shl    ecx, 4
  387.     mov    [apm_code_16 - 0x10000 + 2], cx
  388.     shr    ecx, 16
  389.     mov    [apm_code_16 - 0x10000 + 4], cl
  390.     movzx    edx, dx ; real-mode segment base address of protected-mode 16-bit data segment
  391.     shl    edx, 4
  392.     mov    [apm_data_16 - 0x10000 + 2], dx
  393.     shr    edx, 16
  394.     mov    [apm_data_16 - 0x10000 + 4], dl
  395.     mov    [es : 0x9040], ebx              ; offset of APM entry point
  396. apm_end:
  397. ; -----------------------------------------        
  398.  
  399. ; DISPLAY VESA INFORMATION
  400.  
  401.     push    0
  402.     pop    es
  403.         mov     ax,0x4f00
  404.         mov     di,0xa000
  405.         int     0x10
  406.         cmp     ax,0x004f
  407.         mov    si, novesa-0x10000
  408.         jnz    @f
  409.         mov     ax,[es:di+4]
  410.         add     ax,'0'*256+'0'
  411.         mov    si,vervesa-0x10000
  412.         mov     [si+vervesa_off], ah
  413.         mov     [si+vervesa_off+2], al
  414. @@:     call    print
  415.  
  416. ; \begin{diamond}[30.11.2005]
  417. cfgmanager:
  418. ; settings:
  419. ; a) preboot_graph = graphical mode
  420. ;    preboot_gprobe = probe this mode?
  421. ; b) preboot_mtrr = use hardware acceleration?
  422. ; c) preboot_vrrm = use VRR?
  423. ; d) preboot_device = from what boot?
  424.     mov    di, preboot_graph-0x10000
  425. ; check bootloader block
  426.     cmp    [.loader_block-0x10000], 0
  427.     jz    .noloaderblock
  428.     les    bx, [.loader_block-0x10000]
  429.     cmp    byte [es:bx], 1
  430.     mov    si, loader_block_error-0x10000
  431.     jnz    sayerr
  432.     test    byte [es:bx+1], 1
  433.     jz    @f
  434. ; image in memory present
  435.     cmp    [di+preboot_device-preboot_graph], 0
  436.     jnz    @f
  437.     mov    [di+preboot_device-preboot_graph], 3
  438. @@:
  439. .noloaderblock:
  440. ; determine default settings
  441.     mov    [.bSettingsChanged-0x10000], 0
  442.     cmp    byte [di], 0
  443.     jnz    .preboot_gr_end
  444.     mov    [di+preboot_gprobe-preboot_graph], 0
  445.     mov    al, [vervesa+vervesa_off-0x10000]
  446.     cmp    al, 'x'
  447.     jz    .novesa
  448.     cmp    al, '1'
  449.     jz    .vesa12
  450.     mov    [di+preboot_gprobe-preboot_graph], 2
  451.     mov    al, 3
  452.     jmp    @f
  453. .vesa12:
  454.     mov    al, 7
  455.     jmp    @f
  456. .novesa:
  457.     mov    al, 10
  458. @@:
  459.     mov    [di], al
  460. .preboot_gr_end:
  461.     cmp    [di+preboot_mtrr-preboot_graph], 1
  462.     adc    [di+preboot_mtrr-preboot_graph], 0
  463.     cmp    [di+preboot_vrrm-preboot_graph], 1
  464.     adc    [di+preboot_vrrm-preboot_graph], 0
  465.     cmp    [di+preboot_device-preboot_graph], 1
  466.     adc    [di+preboot_device-preboot_graph], 0
  467. ; notify user
  468.     mov    si, linef-0x10000
  469.     call    print
  470.     mov    si, start_msg-0x10000
  471.     call    print
  472.     mov    si, time_msg-0x10000
  473.     call    print
  474. ; get start time
  475.     call    .gettime
  476.     mov    [.starttime-0x10000], eax
  477.     mov    word [.timer-0x10000], .newtimer-0x10000
  478.     mov    word [.timer-0x10000+2], cs
  479. .printcfg:
  480.     _setcursor 9,0
  481.     mov    si, current_cfg_msg-0x10000
  482.     call    print
  483.     mov    si, curvideo_msg-0x10000
  484.     call    print
  485.     mov    al, [preboot_graph-0x10000]
  486.     cmp    al, 8
  487.     ja    .pnovesa
  488.     mov    dl, al
  489.     and    eax, 3
  490.     mov    si, [modes_msg-0x10000+eax*2]
  491.     call    printplain
  492.     mov    si, modevesa20-0x10000
  493.     cmp    dl, 4
  494.     jbe    @f
  495.     mov    si, modevesa12-0x10000
  496. @@:
  497.     call    printplain
  498.     cmp    dl, 4
  499.     ja    .x
  500.     mov    si, probeno_msg-0x10000
  501.     cmp    [preboot_gprobe-0x10000], 2
  502.     jnz    @f
  503.     mov    si, probeok_msg-0x10000
  504. @@:
  505.     call    printplain
  506. .x:
  507.     jmp    .c
  508. .pnovesa:
  509.     cmp    al, 9
  510.     mov    si, mode9-0x10000
  511.     jz    @b
  512.     mov    si, mode10-0x10000
  513.     jmp    @b
  514. .c:
  515.     mov    si, linef-0x10000
  516.     call    printplain
  517.     mov    si, mtrr_msg-0x10000
  518.     cmp    [preboot_mtrr-0x10000], 1
  519.     call    .say_on_off
  520.     mov    si, vrrm_msg-0x10000
  521.     cmp    [preboot_vrrm-0x10000], 1
  522.     call    .say_on_off
  523.     mov    si, preboot_device_msg-0x10000
  524.     call    print
  525.     mov    al, [preboot_device-0x10000]
  526.     and    eax, 3
  527.     mov    si, [preboot_device_msgs-0x10000+eax*2]
  528.     call    printplain
  529. .wait:
  530.     _setcursor 25,0        ; out of screen
  531. ; set timer interrupt handler
  532.     cli
  533.     push    0
  534.     pop    es
  535.     mov    eax, [es:8*4]
  536.     mov    [.oldtimer-0x10000], eax
  537.     mov    eax, [.timer-0x10000]
  538.     mov    [es:8*4], eax
  539.     sti
  540. ; wait for keypressed
  541.     mov    ah, 0
  542.     int    16h
  543.     push    ax
  544. ; restore timer interrupt
  545.     push    0
  546.     pop    es
  547.     mov    eax, [.oldtimer-0x10000]
  548.     mov    [es:8*4], eax
  549.     mov    [.timer-0x10000], eax
  550.     _setcursor 7,0
  551.     mov    si, space_msg-0x10000
  552.     call    printplain
  553.     pop    ax
  554. ; switch on key
  555.     cmp    al, 13
  556.     jz    .continue
  557.     or    al, 20h
  558.     cmp    al, 'a'
  559.     jz    .change_a
  560.     cmp    al, 'b'
  561.     jz    .change_b
  562.     cmp    al, 'c'
  563.     jz    .change_c
  564.     cmp    al, 'd'
  565.     jnz    .wait
  566.     _setcursor 15,0
  567.     mov     si,bdev-0x10000
  568.     call    print
  569.     mov     bx,'13'
  570.     call    getkey
  571.     mov    [preboot_device-0x10000], al
  572.     _setcursor 13,0
  573. .d:
  574.     mov    [.bSettingsChanged-0x10000], 1
  575.     mov    si, space_msg-0x10000
  576.     call    printplain
  577.     _setcursor 15,0
  578.     mov    cx, 6
  579. @@:
  580.     call    printplain
  581.     loop    @b
  582.     jmp    .printcfg
  583. .change_a:
  584.     _setcursor 15,0
  585.     mov    si, gr_mode-0x10000
  586.     call    printplain
  587.     mov     bx, '09'
  588.     call    getkey
  589.     mov    [preboot_graph-0x10000], al
  590.     cmp    al, 4
  591.     ja    @f
  592.     mov    si, probetext-0x10000
  593.     call    printplain
  594.     mov    bx, '12'
  595.     call    getkey
  596.     mov    [preboot_gprobe-0x10000], al
  597. @@:
  598.     _setcursor 10,0
  599.     jmp    .d
  600. .change_b:
  601.     _setcursor 15,0
  602.     mov    si, gr_acc-0x10000
  603.     call    print
  604.     mov    bx, '12'
  605.     call    getkey
  606.     mov    [preboot_mtrr-0x10000], al
  607.     _setcursor 11,0
  608.     jmp    .d
  609. .change_c:
  610.     _setcursor 15,0
  611.     mov    si, vrrmprint-0x10000
  612.     call    print
  613.     mov    bx, '12'
  614.     call    getkey
  615.     mov    [preboot_vrrm-0x10000], al
  616.     _setcursor 12,0
  617.     jmp    .d
  618. .say_on_off:
  619.     pushf
  620.     call    print
  621.     mov    si, on_msg-0x10000
  622.     popf
  623.     jz    @f
  624.     mov    si, off_msg-0x10000
  625. @@:    call    printplain
  626.     ret
  627. ; novesa and vervesa strings are not used at the moment of executing this code
  628. virtual at novesa
  629. .oldtimer dd ?
  630. .starttime dd ?
  631. .bSettingsChanged db ?
  632. .timer dd ?
  633. end virtual
  634. .loader_block dd 0
  635. .gettime:
  636.     mov    ah, 0
  637.     int    1Ah
  638.     xchg    ax, cx
  639.     shl    eax, 10h
  640.     xchg    ax, dx
  641.     ret
  642. .newtimer:
  643.     push    ds
  644.     push    cs
  645.     pop    ds
  646.     pushf
  647.     call    [.oldtimer-0x10000]
  648.     pushad
  649.     call    .gettime
  650.     sub    eax, [.starttime-0x10000]
  651.     sub    ax, 18*5
  652.     jae    .timergo
  653.     neg    ax
  654.     add    ax, 18-1
  655.     mov    bx, 18
  656.     xor    dx, dx
  657.     div    bx
  658. if lang eq ru
  659. ; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
  660.     cmp    al, 5
  661.     mov    cl, ' '
  662.     jae    @f
  663.     cmp    al, 1
  664.     mov    cl, 'ã'
  665.     jz    @f
  666.     mov    cl, 'ë'
  667. @@:    mov    [time_str+9-0x10000], cl
  668. else
  669. ; wait 5/4/3/2 seconds, 1 second
  670.     cmp    al, 1
  671.     mov    cl, 's'
  672.     ja    @f
  673.     mov    cl, ' '
  674. @@:    mov    [time_str+9-0x10000], cl
  675. end if
  676.     add    al, '0'
  677.     mov    [time_str+1-0x10000], al
  678.     mov    si, time_msg-0x10000
  679.     _setcursor 7,0
  680.     call    print
  681.     _setcursor 25,0
  682.     popad
  683.     pop    ds
  684.     iret
  685. .timergo:
  686.     push    0
  687.     pop    es
  688.     mov    eax, [.oldtimer-0x10000]
  689.     mov    [es:8*4], eax
  690.     mov    sp, 0EC00h
  691. .continue:
  692.     sti
  693.     _setcursor 6,0
  694.     mov    si, space_msg-0x10000
  695.     call    printplain
  696.     call    printplain
  697.     _setcursor 6,0
  698.     mov    si, loading_msg-0x10000
  699.     call    print
  700.     _setcursor 15,0
  701.     cmp    [.bSettingsChanged-0x10000], 0
  702.     jz    .load
  703.     cmp    [.loader_block-0x10000], 0
  704.     jz    .load
  705.     les    bx, [.loader_block-0x10000]
  706.     mov    eax, [es:bx+3]
  707.     push    ds
  708.     pop    es
  709.     test    eax, eax
  710.     jz    .load
  711.     push    eax
  712.     mov    si, save_quest-0x10000
  713.     call    print
  714. .waityn:
  715.     mov    ah, 0
  716.     int    16h
  717.     or    al, 20h
  718.     cmp    al, 'n'
  719.     jz    .loadc
  720.     cmp    al, 'y'
  721.     jnz    .waityn
  722.     call    putchar
  723.     mov    byte [space_msg-0x10000+80], 186
  724.     pop    eax
  725.     push    cs
  726.     push    .cont-0x10000
  727.     push    eax
  728.     retf
  729. .loadc:
  730.     pop    eax
  731. .cont:
  732.     push    cs
  733.     pop    ds
  734.     mov    si, space_msg-0x10000
  735.     mov    byte [si+80], 0
  736.     _setcursor 15,0
  737.     call    printplain
  738.     _setcursor 15,0
  739. .load:
  740. ; \end{diamond}[02.12.2005]
  741.  
  742. ; ASK GRAPHICS MODE
  743.  
  744.     movzx    ax, [preboot_graph-0x10000]
  745.     push    0
  746.     pop    es
  747. ; address is gr_table+6*(ax-1)-0x10000
  748.         add    ax, ax
  749.         lea    si, [gr_table-0x10000 + eax + eax*2 - 6]
  750.         mov     bx,[si+0]
  751.         mov     cx,[si+2]
  752.         mov     dx,[si+4]
  753.         cmp    al, 9*2
  754.         mov    al, 32    ; BPP
  755.         jb    @f
  756.         mov    [es:0x9000], al
  757.         mov    dword [es:0x9018], 0x800000
  758.        @@:
  759.         mov     [es:0x9008],bx
  760.         mov     [es:0x900A],cx
  761.         mov     [es:0x900C],dx
  762.         test    bh, bh
  763.         jz    nov
  764.  
  765. ; USE DEFAULTS OR PROBE
  766.  
  767. ; bx - mode : cx - x size : dx - y size
  768.     cmp    [preboot_gprobe-0x10000], 1
  769.     jz    noprobe
  770.  
  771.         mov     bx,0x100
  772.      newprobe:
  773.         inc     bx
  774.         cmp     bx,0x17f
  775.         mov    si,prnotfnd-0x10000
  776.         jz    sayerr
  777.  
  778.      probemore:
  779.          push    cx
  780.         mov     ax,0x4f01
  781.         mov     cx,bx
  782.         and     cx,0xfff
  783.         mov     di,0xa000
  784.         int     0x10
  785.         pop    cx
  786.  
  787.     test    byte [es:di], 80h    ; lfb?
  788.     jz    newprobe
  789.     cmp    [es:di+0x12], cx    ; x size?
  790.     jnz    newprobe
  791.     cmp    [es:di+0x14], dx    ; y size?
  792.     jnz    newprobe
  793.     cmp    byte [es:di+0x19], 32 ;24
  794.     jb    newprobe
  795.  
  796. ;       add     bx,0100000000000000b
  797.     or    bh, 40h
  798.         mov     [es:0x9008],bx
  799.  
  800.      noprobe:
  801.  
  802.  
  803. ; FIND VESA 2.0 LFB & BPP
  804.  
  805.         mov     ax,0x4f01
  806.         mov     cx,bx
  807.         and     cx,0xfff
  808.         mov     di,0xa000
  809.         int     0x10
  810.         ; LFB
  811.         mov     eax,[es:di+0x28]
  812.         mov     [es:0x9018],eax
  813.         ; ---- vbe voodoo
  814.         BytesPerScanLine equ 0x10
  815.         mov ax, [es:di+BytesPerScanLine]
  816.         mov [es:0x9001],ax
  817.         ; BPP
  818.         mov     al,byte [es:di+0x19]
  819.         mov     [es:0x9000],al
  820.        nov:
  821.         cmp     al,24
  822.         mov    si,bt24-0x10000
  823.         jz    bppl
  824.         cmp     al,32
  825.         mov     si,bt32-0x10000
  826.         jz     bppl
  827.         mov     si,btns-0x10000
  828.         jmp    sayerr
  829.        bppl:
  830.         call    print
  831.  
  832.  
  833. ; FIND VESA 1.2 PM BANK SWITCH ADDRESS
  834.  
  835.     push    es
  836.         mov     ax,0x4f0A
  837.         xor    bx, bx
  838.         int     0x10
  839.         xor     eax,eax
  840.         mov     ax,es
  841.         shl     eax,4
  842.         movzx   ebx,di
  843.         add     eax,ebx
  844.         mov     bx,[es:di]
  845.         add     eax,ebx
  846.         pop     es
  847.         mov     [es:0x9014],eax
  848.  
  849.  
  850. ; GRAPHICS ACCELERATION
  851.  
  852.         mov     al, [preboot_mtrr-0x10000]
  853.         mov     [es:0x901C],al
  854.  
  855. ; VRR_M USE
  856.  
  857.         mov     al,[preboot_vrrm-0x10000]
  858.         mov     [es:0x9030],al
  859.  
  860.  
  861. ; MEMORY MODEL
  862.  
  863. ;        movzx   eax,byte [es:preboot_memory-0x10000]
  864. ;        cmp     eax,0
  865. ;        jne     pre_mem
  866. ;;;;;;;;;;;;;;;;;;;;;;;;;
  867. ; mario79 - memory size ;
  868. ;;;;;;;;;;;;;;;;;;;;;;;;;
  869. ;           mov ax,0E801h
  870. ;;;           xor bx,bx    ; thanks to Alexei for bugfix [18.07.2004]
  871. ;           xor cx, cx
  872. ;           xor dx, dx
  873. ;           int 0x15
  874. ;           movzx ebx, dx ;bx
  875. ;           movzx eax, cx ;ax
  876. ;           shl   ebx,6   ; ïåðåâîä â êèëîáàéòû (x64)
  877. ;           add   eax,ebx
  878. ;           add eax, 1000h ;440h
  879. ;           cmp eax,40000h ; 256?
  880. ;           jge mem_256_z
  881. ;           cmp eax,20000h ; 128?
  882. ;           jge mem_128_z
  883. ;           cmp eax,10000h ; 64?
  884. ;           jge mem_64_z
  885. ;           cmp eax,8000h ; 32?
  886. ;           jge mem_32_z
  887. ;           jmp mem_16_z
  888. ;
  889. ;mem_256_z: mov     si,memokz256-0x10000
  890. ;           call    printplain
  891. ;           mov eax,5
  892. ;           jmp pre_mem
  893. ;mem_128_z: mov     si,memokz128-0x10000
  894. ;           call    printplain
  895. ;           mov eax,4
  896. ;           jmp pre_mem
  897. ;mem_64_z:  mov     si,memokz64-0x10000
  898. ;           call    printplain
  899. ;           mov eax,3
  900. ;           jmp pre_mem
  901. ;mem_32_z:  mov     si,memokz32-0x10000
  902. ;           call    printplain
  903. ;           mov eax,2
  904. ;           jmp pre_mem
  905. ;mem_16_z:  mov     si,memokz16-0x10000
  906. ;           call    printplain
  907. ;           mov eax,1
  908. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  909. ;      pre_mem:
  910. ;        push    word 0x0000
  911. ;        pop     es
  912. ;        mov     [es:0x9030],al
  913. ;        push    word 0x1000
  914. ;        pop     es
  915. ;        mov     si,linef-0x10000
  916. ;        call    printplain
  917.  
  918.  
  919.  
  920.  
  921. ; DIRECT WRITE TO LFB, PAGING DISABLED
  922.  
  923. ;        movzx   eax,byte [es:preboot_lfb-0x10000]
  924. ;        mov     eax,1                             ; paging disabled
  925. ;        cmp     eax,0
  926. ;        jne     pre_lfb
  927. ;        mov     si,gr_direct-0x10000
  928. ;        call    printplain
  929. ;        mov     ebx,'12'
  930. ;        call    getkey
  931. ;      pre_lfb:
  932. ;        push    word 0x0000
  933. ;        pop     es
  934. ;        mov     [es:0x901E],al
  935. ;        mov     ax,0x1000
  936. ;        mov     es,ax
  937. ;        mov     si,linef-0x10000
  938. ;        call    printplain
  939.         mov     [es:0x901E],byte 1
  940.  
  941.  
  942.  
  943. ; BOOT DEVICE
  944.  
  945.     mov    al, [preboot_device-0x10000]
  946.         dec     al
  947.         mov     [boot_dev-0x10000],al
  948.  
  949. ; READ DISKETTE TO MEMORY
  950.  
  951. ;        cmp     [boot_dev-0x10000],0
  952.         jne     no_sys_on_floppy
  953.         mov     si,diskload-0x10000
  954.         call    print
  955.         xor    ax, ax            ; reset drive
  956.         xor    dx, dx
  957.         int     0x13
  958.         mov     cx,0x0001               ; startcyl,startsector
  959.         xor    dx, dx            ; starthead,drive
  960.         push    word 80*2               ; read no of sect
  961.        reads:
  962.         pusha
  963.         xor     si,si
  964.        newread:
  965.         mov     bx,0xa000               ; es:bx -> data area
  966.         mov     ax,0x0200+18            ; read, no of sectors to read
  967.         int     0x13
  968.         test    ah, ah
  969.         jz      goodread
  970.         inc    si
  971.         cmp     si,10
  972.         jnz     newread
  973.         mov     si,badsect-0x10000
  974. sayerr_plain:
  975.         call    printplain
  976.         jmp     $
  977.        goodread:
  978.         ; move -> 1mb
  979.         mov     si,movedesc-0x10000
  980.         push    es
  981.         push    ds
  982.         pop     es
  983.         mov     cx,256*18
  984.         mov     ah,0x87
  985.         int     0x15
  986.         pop    es
  987.  
  988.         test    ah,ah                  ; was the move successfull ?
  989.         je      goodmove
  990.         mov     dx,0x3f2              ; floppy motor off
  991.         mov     al,0
  992.         out     dx,al
  993.         mov     si,memmovefailed-0x10000
  994.         jmp    sayerr_plain
  995.       goodmove:
  996.  
  997.     add    dword [movedesc-0x10000+0x18+2], 512*18
  998.         popa
  999.         inc     dh
  1000.         cmp     dh,2
  1001.         jnz     bb2
  1002.         mov     dh,0
  1003.         inc     ch
  1004.         pusha                        ; print prosentage
  1005.         mov     si,pros-0x10000
  1006.     shr    ch, 2
  1007.     mov    al, '5'
  1008.     test    ch, 1
  1009.     jnz    @f
  1010.     mov    al, '0'
  1011. @@:
  1012.     mov    [si+1], al
  1013.     shr    ch, 1
  1014.     add    ch, '0'
  1015.     mov    [si], ch
  1016.         call    printplain
  1017.         popa
  1018.        bb2:
  1019.         pop     ax
  1020.         dec     ax
  1021.         push    ax
  1022.         jnz     reads
  1023.        readdone:
  1024.         pop     ax
  1025.         mov     si,backspace2-0x10000
  1026.         call    printplain
  1027.         mov     si,okt-0x10000
  1028.         call    printplain
  1029.        no_sys_on_floppy:
  1030.         xor    ax, ax        ; reset drive
  1031.         xor    dx, dx
  1032.         int     0x13
  1033.        mov dx,0x3f2 ; floppy motor off
  1034.        mov al,0
  1035.        out dx,al
  1036.  
  1037.     push    es
  1038. ; PAGE TABLE
  1039.  
  1040.     push    dword [es:0x9018]
  1041.  
  1042.         map_mem equ 64                ; amount of memory to map
  1043.  
  1044.         push    0x6000
  1045.         pop    es                    ; es:di = 6000:0
  1046.         xor     di,di
  1047.         mov     cx,256*map_mem         ; Map (mapmem) M
  1048. ;        mov     eax,7
  1049. ;       pt2:
  1050. ;        cmp     cx,256*(map_mem-8)     ; 8 M map to LFB
  1051. ;        jnz     pt3
  1052. ;        pop     eax
  1053. ;        add     eax,7
  1054. ;       pt3:
  1055. ;        cmp     cx,256*(map_mem-12)    ; 12 M back to linear = physical
  1056. ;        jnz     pt4
  1057. ;        mov     eax,12*0x100000 + 7
  1058. ;       pt4:
  1059. ;        stosd
  1060. ;        add     eax,4096
  1061. ;        loop    pt2
  1062. ; initialize as identity mapping
  1063.     xor    eax, eax
  1064.     call    pagetable_set
  1065. ; 8M..12M map to LFB
  1066.     pop    eax
  1067. ;    mov    cx, 256*4
  1068.     mov    ch, 4
  1069.     mov    di, 2000h
  1070.     call    pagetable_set
  1071.  
  1072.     push    0x7100
  1073.     pop    es
  1074.         xor     di,di
  1075.         mov     eax,8*0x100000
  1076.         mov     cx,256*4
  1077.         call    pagetable_set
  1078.        
  1079. ; 4 KB PAGE DIRECTORY
  1080.  
  1081.     push    0x7F00
  1082.     pop    es                ; es:di = 7F00:0
  1083.         xor     di, di
  1084.         mov     cx, 64 / 4
  1085.         mov     eax, 0x60007            ; for 0 M
  1086.         call    pagetable_set
  1087.         mov     dword [es:0x800],0x71007   ;map region 0x80000000-0x803FFFFF to 0x800000-0xCFFFFF
  1088.         xor     si,si
  1089.         mov     di,second_base_address shr 20
  1090.         mov     cx,64/2
  1091.         rep     movs word [es:di], [es:si]
  1092.        
  1093.         mov     eax, 0x7F000 +8+16      ; Page directory and enable caches
  1094.         mov     cr3, eax
  1095.  
  1096. ; SET GRAPHICS
  1097.  
  1098.     pop    es
  1099.         mov     ax,[es:0x9008]        ; vga & 320x200
  1100.         mov    bx, ax
  1101.         cmp     ax,0x13
  1102.         je      setgr
  1103.         cmp     ax,0x12
  1104.         je      setgr
  1105.         mov     ax,0x4f02            ; Vesa
  1106.        setgr:
  1107.         int     0x10
  1108.         test    ah,ah
  1109.         mov    si, fatalsel-0x10000
  1110.         jnz    sayerr
  1111. ; set mode 0x12 graphics registers:
  1112.         cmp     bx,0x12
  1113.         jne     gmok2
  1114.  
  1115.         mov     al,0x05
  1116.         mov     dx,0x03ce
  1117.         push    dx
  1118.         out     dx,al      ; select GDC mode register
  1119.         mov     al,0x02
  1120.         inc    dx
  1121.         out     dx,al      ; set write mode 2
  1122.  
  1123.         mov     al,0x02
  1124.         mov     dx,0x03c4
  1125.         out     dx,al      ; select VGA sequencer map mask register
  1126.         mov     al,0x0f
  1127.         inc    dx
  1128.         out     dx,al      ; set mask for all planes 0-3
  1129.  
  1130.         mov     al,0x08
  1131.         pop    dx
  1132.         out     dx,al      ; select GDC bit mask register
  1133.                            ; for writes to 0x03cf
  1134.  
  1135.        gmok2:
  1136.         push    ds
  1137.         pop    es
  1138.