Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;; Synhronization for MenuetOS.                                 ;;
  7. ;; Author: Halyavin Andrey, halyavin@land.ru                    ;;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9.  
  10. $Revision: 6240 $
  11.  
  12. struct FRB
  13.         list            LHEAD
  14.         magic           rd 1
  15.         handle          rd 1
  16.         destroy         rd 1
  17.  
  18.         width           rd 1
  19.         height          rd 1
  20.         pitch           rd 1
  21.         format          rd 1
  22.         private         rd 1
  23.         pde             rd 8
  24. ends
  25.  
  26. align 4
  27. create_framebuffer:
  28.         mov     ecx, sizeof.FRB
  29.         call    create_object
  30.         test    eax, eax
  31.         jz .fail
  32.  
  33.         mov     [eax+FRB.magic], 'FRMB'
  34.         mov     [eax+FRB.destroy], 0
  35. .fail:
  36.         ret
  37.  
  38.  
  39. align 4
  40. init_video:
  41.         mov     ebp, bios_fb
  42.  
  43.         movzx   eax, byte [BOOT_VARS+BOOT_BPP]      ; bpp
  44.         mov     [_display.bits_per_pixel], eax
  45.         mov     [_display.vrefresh], 60
  46.  
  47.         movzx   eax, word [BOOT_VARS+BOOT_X_RES]; X max
  48.         mov     [_display.width], eax
  49.         mov     [ebp+FRB.width], eax
  50.         mov     [display_width_standard], eax
  51.         dec     eax
  52.         mov     [screen_workarea.right], eax
  53.  
  54.         movzx   eax, word [BOOT_VARS+BOOT_Y_RES]; Y max
  55.         mov     [_display.height], eax
  56.         mov     [ebp+FRB.height], eax
  57.         mov     [display_height_standard], eax
  58.         dec     eax
  59.         mov     [screen_workarea.bottom], eax
  60.  
  61.         movzx   eax, word [BOOT_VARS+BOOT_VESA_MODE]    ; screen mode
  62.         mov     dword [SCR_MODE], eax
  63.         mov     eax, 640 *4                             ; Bytes PerScanLine
  64.         cmp     [SCR_MODE], word 0x13                   ; 320x200
  65.         je      @f
  66.         cmp     [SCR_MODE], word 0x12                   ; VGA 640x480
  67.         je      @f
  68.         movzx   eax, word[BOOT_VARS+BOOT_PITCH]         ; for other modes
  69. @@:
  70.         mov     [_display.lfb_pitch], eax
  71.         mov     [ebp+FRB.pitch], eax
  72.  
  73.         mov     eax, [BOOT_VARS+BOOT_LFB]
  74.         mov     [LFBAddress], eax
  75.  
  76.         mov     eax, [_display.width]
  77.         mul     [_display.height]
  78.         mov     [_display.win_map_size], eax
  79.  
  80.         cmp     word [SCR_MODE], 0x0012                 ; VGA (640x480 16 colors)
  81.         je      .vga
  82.         cmp     word [SCR_MODE], 0x0013                 ; MCGA (320*200 256 colors)
  83.         je      .32bpp
  84.         cmp     byte [_display.bits_per_pixel], 32
  85.         je      .32bpp
  86.         cmp     byte [_display.bits_per_pixel], 24
  87.         je      .24bpp
  88.         cmp     byte [_display.bits_per_pixel], 16
  89.         je      .16bpp
  90.  
  91. .vga:
  92.         mov     [PUTPIXEL], VGA_putpixel
  93.         mov     [GETPIXEL], Vesa20_getpixel32           ; Conversion buffer is 32 bpp
  94.         mov     [_display.bytes_per_pixel], 4           ; Conversion buffer is 32 bpp
  95.         jmp     .finish
  96.  
  97. .16bpp:
  98.         mov     [PUTPIXEL], Vesa20_putpixel16
  99.         mov     [GETPIXEL], Vesa20_getpixel16
  100.         mov     [_display.bytes_per_pixel], 2
  101.         jmp     .finish
  102.  
  103. .24bpp:
  104.         mov     [PUTPIXEL], Vesa20_putpixel24
  105.         mov     [GETPIXEL], Vesa20_getpixel24
  106.         mov     [_display.bytes_per_pixel], 3
  107.         jmp     .finish
  108.  
  109. .32bpp:
  110.         mov     [PUTPIXEL], Vesa20_putpixel32
  111.         mov     [GETPIXEL], Vesa20_getpixel32
  112.         mov     [_display.bytes_per_pixel], 4
  113.  
  114. .finish:
  115.         mov     [MOUSE_PICTURE], mousepointer
  116.         mov     [_display.check_mouse], check_mouse_area_for_putpixel
  117.         mov     [_display.check_m_pixel], check_mouse_area_for_getpixel
  118.  
  119.         mov     ax, word [SCR_MODE]
  120.         cmp     ax, 0x0012
  121.         je      .fake
  122.         cmp     ax, 0x0013
  123.         je      .fake
  124.  
  125.         mov     esi, [LFBAddress]
  126.         bt      [cpu_caps], CAPS_PSE
  127.         jnc     .create_page_tables
  128.         mov     edx, 0x00400000
  129.         or      esi, PG_GLOBAL+PDE_LARGE+PAT_WC+PG_UWR
  130.         and     esi, [pte_valid_mask]
  131.         mov     [ebp+FRB.pde], esi
  132.         add     esi, edx
  133.         mov     [ebp+FRB.pde+4], esi
  134.         add     esi, edx
  135.         mov     [ebp+FRB.pde+8], esi
  136.         add     esi, edx
  137.         mov     [ebp+FRB.pde+12], esi
  138.         add     esi, edx
  139. .ok:
  140.         call    calculate_fast_getting_offset_for_WinMapAddress
  141. ; for Qemu or non standart video cards
  142. ; Unfortunately [BytesPerScanLine] does not always
  143. ; equal to [_display.width] * [ScreenBPP] / 8
  144.         call    calculate_fast_getting_offset_for_LFB
  145.         ret
  146.  
  147. .create_page_tables:
  148.  
  149.         add     ebp, FRB.pde
  150.         or      esi, PG_GLOBAL+PAT_WC+PG_UWR
  151.         and     esi, [pte_valid_mask]
  152.  
  153.         stdcall alloc_kernel_space, 0x1000
  154.         mov     edi, eax
  155.         mov     ebx, 4
  156.  
  157. .new_pd:
  158.         call    alloc_page
  159.         lea     edx, [eax+PG_UWR]
  160.         mov     [ebp], edx
  161.  
  162.         stdcall map_page, edi, eax, PG_SWR
  163.  
  164.         mov     eax, esi
  165.         mov     ecx, 1024
  166. @@:
  167.         stosd
  168.         add     eax, 0x1000
  169.         loop    @B
  170.  
  171.         add     esi, 0x400000
  172.         add     ebp, 4
  173.         sub     edi, 4096
  174.         dec     ebx
  175.         jnz     .new_pd
  176.         stdcall free_kernel_space, edi
  177.         jmp     .ok
  178.  
  179. .fake:
  180.         mov     [BOOT_VARS+BOOT_MTRR], byte 2
  181.  
  182.         stdcall alloc_kernel_space, 0x1000
  183.         push    eax                            ;store in stack for subsequent
  184.         mov     edi, eax                       ;free_kernel_space call
  185.  
  186.         call    alloc_page
  187.         lea     edx, [eax+PG_UWR]
  188.         mov     [ebp+FRB.pde], edx
  189.  
  190. ; max VGA=640*480*4=1228800 bytes
  191. ; + 32*640*4=81920 bytes for mouse pointer
  192.         stdcall alloc_pages, ((1228800+81920)/4096)
  193.         or      eax, PG_GLOBAL+PG_UWR
  194.         and     eax, [pte_valid_mask]
  195.         mov     ecx, (1228800+81920)/4096
  196. @@:
  197.         stosd
  198.         add     eax, 0x1000
  199.         loop    @B
  200.  
  201.         call free_kernel_space
  202.         jmp     .ok
  203.  
  204. align 4
  205. set_framebuffer:
  206.         mov     edx, LFB_BASE shr 22
  207.         mov     eax, [ecx+FRB.pde]
  208.         mov     dword [master_tab+edx*4], eax
  209.         mov     eax, [ecx+FRB.pde+4]
  210.         mov     dword [master_tab+edx*4+4], eax
  211.         mov     eax, [ecx+FRB.pde+8]
  212.         mov     dword [master_tab+edx*4+8], eax
  213.         mov     eax, [ecx+FRB.pde+12]
  214.         mov     dword [master_tab+edx*4+12], eax
  215.         ret
  216.  
  217.