Subversion Repositories Kolibri OS

Rev

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