Subversion Repositories Kolibri OS

Rev

Rev 465 | Blame | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;   MenuetOS Driver (vmode.mdr)
  3. ;   Target: Vertical Refresh Rate programming and videomode changing
  4. ;
  5. ;   Author: Trans <<<<<13>>>>>
  6. ;   Date:   20.07.2003
  7. ;
  8. ;   Version: 1.0
  9. ;   OS: MenuetOS
  10. ;   Compiler: FASM
  11. ;
  12.  
  13. OS_BASE equ 0x80000000
  14.  
  15. use32
  16.  
  17. macro align value { rb (value-1) - ($ + value-1) mod value }
  18.  
  19.         org    OS_BASE+0x0428000
  20.  
  21. headerstart=$
  22.  
  23. mdid    db     'MDAZ'              ; 4 byte id
  24. mdhver  dd     0x00                ; header version
  25. mdcode  dd     MDSTART             ; start of code
  26. mdver   dd     0x00000001          ; driver version (subversion*65536+version)
  27. mdname  db     'Trans VideoDriver' ; 32 bytes of full driver name
  28.     times (32-($-mdname)) db ' '   ;
  29.  
  30. headerlen=$-headerstart
  31.     times (256-headerlen) db 0     ; reserved area for future
  32.  
  33. MDSTART:    ; start of driver code ( base_adr+256 bytes)
  34. ; ebx(=ecx in program):
  35. ;   1 - Get DriverInfo and Driver Initial Set
  36. ;   2 - Get Current Video Mode With Vertical Refresh Rate
  37. ;   3 - Change Video Mode
  38. ;   4 - Return at Start System Video Mode
  39. ;   5 - Change vertical and horizontal size of visible screen area
  40. ;   6 - Change Vert/Hor position visible area on screen (not complete yet)
  41. ;
  42. ;   MAXF - ...
  43. MAXF=5
  44.  
  45. ;-------Main Manager-------------
  46.     pushad
  47.     cmp ebx,1
  48.     jb mdvm_00
  49.     cmp ebx,MAXF
  50.     ja mdvm_00
  51.     shl ebx,2
  52.     add ebx,mdvm_func_table
  53.     call dword [ebx]
  54.     mov [esp+28],eax
  55.     mov [esp+24],ecx
  56.     mov [esp+20],edx
  57.     mov [esp+16],ebx
  58.     popad
  59.     retn
  60. mdvm_00:
  61.     popad
  62.     xor eax,eax
  63.     dec eax
  64.     retn
  65.  
  66. ; ------Drivers Functions----------
  67.  
  68. align 4
  69.  
  70. ; EBX=1 (in applications ECX=1)- Get DriverInfo and Driver Initial Set
  71. ;
  72. ; IN: ecx (in app. edx) - pointer to 512-bytes info area in application
  73. ; OUT:
  74. ;
  75. vm_info_init:
  76.       push ecx
  77.       cmp [mdrvm],dword 0
  78.       jnz .vmii_00
  79.       call vm_safe_reg
  80.       call vm_get_initial_videomode
  81.       mov eax,[initvm]
  82.       mov [currvm],eax
  83.       call vm_search_sys_func_table
  84.       call vm_get_cur_vert_rate
  85.       mov [initrr],eax
  86.       call vm_calc_pixelclock
  87.       call vm_calc_refrate
  88.       inc [mdrvm]
  89. .vmii_00:
  90.       pop ecx
  91.       call vm_transfer_drv_info
  92.       mov ebx,dword [refrate]
  93.       mov eax,dword [mdid]      ;dword [systlb]
  94.       retn
  95.  
  96.  
  97. align 4
  98.  
  99. ; EBX=2 (in applications ECX=2)- Get Current Video Mode
  100. ;
  101. ; OUT: eax = X_screen*65536+Y_screen
  102. ;      ebx = current vertical rate
  103. ;      ecx = current video mode (number)
  104. vm_get_cur_mode:
  105.       cmp [mdrvm],dword 0
  106.       jz .vmgcm_00
  107.       call vm_get_cur_vert_rate
  108.       mov eax,[OS_BASE+0FE00h]
  109.       mov ebx,[OS_BASE+0FE04h]
  110.       shl eax,16
  111.       add eax,ebx
  112.       add eax,00010001h
  113.       mov ebx,[refrate]
  114.       mov ecx,[currvm]
  115.       retn
  116. .vmgcm_00:
  117.       xor eax,eax
  118.       dec eax
  119.       retn
  120.  
  121.  
  122. align 4
  123.  
  124. ; EBX=3 (in applications ECX=3)- Change Video Mode
  125. ;
  126. ; IN:  ecx = VertRate*65536+VideoMode
  127. ; OUT: eax = 0 if no error
  128. ;
  129. vm_set_video_mode:
  130.       cmp [mdrvm],dword 0
  131.       jz .vmsvm_00
  132.       call vm_set_selected_mode
  133. ;      xor eax,eax
  134.       retn
  135. .vmsvm_00:
  136.       xor eax,eax
  137.       dec eax
  138.       retn
  139.  
  140.  
  141. align 4
  142.  
  143. ; EBX=4 (in applications ECX=4)- Return at Start System Video Mode
  144. ;
  145. ; IN:
  146. ; OUT: eax = = 0 if no error
  147. ;
  148. vm_restore_init_video_mode:
  149.       cmp [mdrvm],dword 0
  150.       jz .vmrivm_00
  151.       call vm_restore_reg
  152.       xor eax,eax
  153.       retn
  154. .vmrivm_00:
  155.       xor eax,eax
  156.       dec eax
  157.       retn
  158.  
  159.  
  160. align 4
  161.  
  162. ; EBX=5 (in applications ECX=5)- Change vertical and horizontal size
  163. ;                                 of visible screen area
  164. ; IN:  ecx (in app. edx) = 0/1 - -/+ horizontal size on 1 position
  165. ;                        = 2/3 - -/+ vertical size on 1 position (8 pixels)
  166. ;                          ^-^----- not complete yet
  167. ; OUT: eax = = 0 if no error
  168. ;
  169. vm_change_screen_size:
  170.       cmp [mdrvm],dword 0
  171.       jz .vmcss_00
  172.       cmp cl,1
  173.       ja .vmcss_01
  174.       mov eax,ecx
  175.       call vm_inc_dec_width
  176.       xor eax,eax
  177.       retn
  178. .vmcss_01:
  179.       and ecx,01h
  180.       mov eax,ecx
  181. ;     call vm_inc_dec_high   ; not complete yet
  182.       xor eax,eax
  183.       retn
  184. .vmcss_00:
  185.       xor eax,eax
  186.       dec eax
  187.       retn
  188.  
  189.  
  190. align 4
  191.  
  192. ; EBX=6 (in applications ECX=6)- Change Vert/Hor position visible area on screen
  193. ;
  194. ; IN:  ecx (in app. edx) = 0/1 - -/+ horizontal position on 1 point
  195. ;                        = 2/3 - -/+ vertical position on 1 pixel
  196. ;                          ^-^----- not complete yet
  197. ; OUT: eax = 0 if no error
  198. ;
  199. vm_change_position_screen:
  200.       cmp [mdrvm],dword 0
  201.       jz .vmcps_00
  202.   ; ...
  203.       xor eax,eax
  204.       retn
  205. .vmcps_00:
  206.       xor eax,eax
  207.       dec eax
  208.       retn
  209.  
  210.  
  211. ;-----Drivers Subfunctions---------
  212.  
  213. ;
  214. ; Searching i40 system functions pointer table in kernel area location
  215. ;
  216. vm_search_sys_func_table:
  217.       push eax     ; eax - current value
  218.       push ecx     ; ecx - will be counter of equevalent value
  219.       push edx     ; edx - last value
  220.       push esi     ; esi - current address
  221.       xor ecx,ecx
  222.       mov esi,OS_BASE+010000h            ; Start address of kernel location
  223.       lodsd
  224.       mov edx,eax
  225.       cld
  226. .vmssft_00:
  227.       cmp esi,OS_BASE+30000h
  228.       ja .vmssft_03
  229.       inc ecx
  230.       lodsd
  231.       cmp edx,eax
  232.       mov edx,eax
  233.       je .vmssft_00
  234.       cmp ecx,128
  235.       ja .vmssft_02
  236. .vmssft_01:
  237.       xor ecx,ecx
  238.       jmp .vmssft_00
  239. .vmssft_02:
  240.       cmp edx,0
  241.       je .vmssft_01
  242.       sub esi,256*4-1
  243.       mov [systlb],esi
  244.       xor ecx,ecx
  245. .vmssft_03_0:
  246.       inc ecx
  247.       lodsd
  248.       cmp edx,eax
  249.       mov edx,eax
  250.       jne .vmssft_03_0
  251.       mov esi,dword [systlb]
  252.       cmp cx,60
  253.       jae .vmssft_03
  254.       add esi,256*4-4
  255.       lodsb
  256.       mov edx,eax
  257.       jmp .vmssft_01
  258. .vmssft_03:
  259.       mov [systlb],esi
  260.       pop esi
  261.       pop edx
  262.       pop ecx
  263.       pop eax
  264.       retn
  265.  
  266. ; IN:
  267. ; OUT: eax= vertical rate in Hz
  268. vm_get_cur_vert_rate:
  269.       push edx
  270.       push ebx
  271.       xor eax,eax
  272.       mov edx,eax
  273.       mov ebx,eax
  274.       mov dx,03DAh
  275. .vmgcvt_00:
  276.       in al,dx
  277.       test al,8
  278.       jz .vmgcvt_00
  279. .vmgcvt_01:
  280.       in al,dx
  281.       test al,8
  282.       jnz .vmgcvt_01
  283.       mov ebx,edx
  284.       rdtsc
  285.       mov edx,ebx
  286.       mov ebx,eax
  287. .vmgcvt_02:
  288.       in al,dx
  289.       test al,8
  290.       jz .vmgcvt_02
  291. .vmgcvt_03:
  292.       in al,dx
  293.       test al,8
  294.       jnz .vmgcvt_03
  295.       rdtsc
  296.       sub eax,ebx
  297.       mov ebx,eax
  298.       mov eax,[OS_BASE+0F600h]
  299.       xor edx,edx
  300.       div ebx
  301.       inc eax
  302.       mov [refrate],eax
  303.       pop ebx
  304.       pop edx
  305.       retn
  306.  
  307. vm_calc_pixelclock:
  308.         push ebx
  309.         push edx
  310.         xor eax,eax
  311.         mov al,[_00]
  312.         add ax,5
  313.         shl eax,3
  314.         xor ebx,ebx
  315.         mov bl,[_06]
  316.         mov bh,[_07]
  317.         and bh,00100001b
  318.         btr bx,13
  319.         jnc .vmcpc_00
  320.         or bh,2
  321. .vmcpc_00:
  322.         xor edx,edx
  323.         mul ebx
  324.         xor edx,edx
  325.         mul [initrr]
  326.         mov [pclock],eax
  327.         pop edx
  328.         pop ebx
  329.         retn
  330.  
  331. ;
  332. ; Safe of initial CRTC state
  333. ;
  334. vm_safe_reg:
  335.     push edx
  336.     push ebx
  337.     push ecx
  338.     push edi
  339.     cli
  340.     mov dx,3d4h  ; CRTC
  341.     mov al,11h
  342.     out dx,al
  343.     inc dx
  344.     in al,dx
  345.     and al,7fh
  346.     out dx,al    ; Clear protection bit
  347.     dec dx
  348.     xor ecx,ecx
  349.     mov cl,19h
  350.     xor bl,bl
  351.     mov edi,CRTCreg
  352. .vmsr_00:
  353.     mov al,bl
  354.     out dx,al
  355.     inc dx
  356.     in al,dx
  357.     dec dx
  358.     stosb
  359.     inc bl
  360.     loop .vmsr_00
  361.     sti
  362.     pop edi
  363.     pop ecx
  364.     pop ebx
  365.     pop edx
  366.     retn
  367.  
  368. ;
  369. ; Restore of initial CRTC state
  370. ;
  371. vm_restore_reg:
  372.     push eax
  373.     push ebx
  374.     push edx
  375.     push esi
  376.     mov eax,[oldX]
  377.     mov [OS_BASE+0FE00h],eax
  378.     mov eax,[oldY]
  379.     mov [OS_BASE+0FE04h],eax
  380.     mov dx,03dah
  381. .vmrr_00:
  382.     in al,dx
  383.     test al,8
  384.     jnz .vmrr_00
  385. .vmrr_01:
  386.     in al,dx
  387.     test al,8
  388.     jnz .vmrr_01
  389.     cli
  390.     mov dx,03c4h
  391.     mov ax,0101h
  392.     out dx,ax
  393.     mov dx,3d4h  ; CRTC
  394.     mov al,11h
  395.     out dx,al
  396.     inc dx
  397.     in al,dx
  398.     and al,7fh  ; Clear Protection bit
  399.     out dx,al
  400.     dec dx
  401.     xor ecx,ecx
  402.     mov cl,19h
  403.     mov esi,CRTCreg
  404.     xor bl,bl
  405. .vmrr_02:
  406.     lodsb
  407.     mov ah,al
  408.     mov al,bl
  409.     out dx,ax
  410.     inc bl
  411.     loop .vmrr_02
  412.     sti
  413. ;    call ref_screen
  414.     pop esi
  415.     pop edx
  416.     pop ecx
  417.     pop eax
  418.     retn
  419.  
  420. ; Calculate of possible vertical refrash rate
  421. ;  (light version of function)
  422. vm_calc_refrate:
  423.         push ebx
  424.         push ecx
  425.         push edx
  426.         push edi
  427.         push esi
  428.         mov eax,[pclock]
  429.         xor edx,edx
  430.         mov edi,_m1
  431.         mov ebx,eax
  432.         mov ecx,(1696*1065)
  433.         div ecx
  434.         xor edx,edx
  435.         stosw
  436.         add edi,8
  437.         mov eax,ebx
  438.         mov ecx,(1344*804)
  439.         div ecx
  440.         xor edx,edx
  441.         stosw
  442.         add edi,8
  443.         mov eax,ebx
  444.         mov ecx,(1056*636)
  445.         div ecx
  446.         xor edx,edx
  447.         stosw
  448.         add edi,8
  449.         mov eax,ebx
  450.         mov ecx,(800*524)
  451.         div ecx
  452.         xor edx,edx
  453.         stosw
  454.         mov edi,_m1
  455.         mov esi,edi
  456.         mov ecx,5*4
  457. .vmcrr_00:
  458.         lodsw
  459.         cmp ax,55
  460.         jb .vmcrr_01
  461.         stosw
  462.         loop .vmcrr_00
  463.         pop esi
  464.         pop edi
  465.         pop edx
  466.         pop ecx
  467.         pop ebx
  468.         retn
  469. .vmcrr_01:
  470.         xor ax,ax
  471.         stosw
  472.         loop .vmcrr_00
  473.         pop esi
  474.         pop edi
  475.         pop edx
  476.         pop ecx
  477.         pop ebx
  478.         retn
  479.  
  480. vm_get_initial_videomode:
  481.     push eax
  482.     mov eax,dword [OS_BASE+0FE00h]
  483.     mov [oldX],eax
  484.     mov eax,dword [OS_BASE+0FE04h]
  485.     mov [oldY],eax
  486.     mov eax,dword [OS_BASE+0FE0Ch] ; initial video mode
  487.     and ax,01FFh
  488.     mov dword [initvm],eax
  489.     pop eax
  490.     retn
  491.  
  492.  
  493. ; IN: eax = 0/1  -  -/+ 1 position of width
  494. vm_inc_dec_width:
  495.     push ebx
  496.     push edx
  497.     mov ebx,eax
  498.     mov dx,3d4h  ; CRTC
  499.     mov al,11h
  500.     out dx,al
  501.     inc dx
  502.     in al,dx
  503.     and al,7fh  ; Clear Protection bit
  504.     out dx,al
  505.     dec dx
  506.     xor al,al
  507.     out dx,al
  508.     inc dx
  509.     in al,dx
  510.     dec al
  511.     cmp bl,0
  512.     jnz .vmidr_00
  513.     inc al
  514.     inc al
  515. .vmidr_00:
  516.     out dx,al
  517.     pop edx
  518.     pop ebx
  519.     retn
  520.  
  521. ;
  522. ; Copy driver info to application area
  523. ;
  524. ; IN: ecx (in app. edx) - pointer to 512-bytes info area in application
  525. ; OUT:
  526. vm_transfer_drv_info:
  527.         push ecx
  528.         push edi
  529.         push esi
  530.         mov eax,ecx
  531.         xor ecx,ecx
  532.         mov cl,32/4
  533.         mov esi,mdname
  534.         mov edi,drvname
  535.         rep movsd
  536.         mov ecx,eax
  537.         mov eax,[mdver]
  538.         mov [drvver],eax
  539.         mov edi,[OS_BASE+3010h]
  540.         mov edi,[edi+10h]
  541.         add edi,ecx
  542.         mov esi,drvinfo
  543.         xor ecx,ecx
  544.         mov cx,512
  545.         rep movsb
  546.         pop esi
  547.         pop edi
  548.         pop ecx
  549.         retn
  550.  
  551.  
  552. ;
  553. ; Set selected video mode
  554. ; (light version)
  555. ;
  556. ; IN: ecx = VertRate*65536+VideoMode
  557. ;
  558. vm_set_selected_mode:
  559.     push edx
  560.     push ecx
  561.     push esi
  562.     ror ecx,16
  563.     cmp cx,00h
  564.     je .vmssm_03
  565.     rol ecx,16
  566.     mov eax,ecx
  567.     shl eax,16
  568.     shr eax,16
  569.     mov [currvm],eax
  570.     cmp cx,112h
  571.     jne .vmssm_00
  572.     mov esi,mode0
  573.     mov ecx,639
  574.     mov edx,479
  575.     jmp .vmssm_st00
  576. .vmssm_00:
  577.     cmp cx,115h
  578.     jne .vmssm_01
  579.     mov esi,mode1
  580.     mov ecx,799
  581.     mov edx,599
  582.     jmp .vmssm_st00
  583. .vmssm_01:
  584.     cmp cx,118h
  585.     jne .vmssm_02
  586.     mov esi,mode2
  587.     mov ecx,1023
  588.     mov edx,767
  589.     jmp .vmssm_st00
  590. .vmssm_02:
  591.     cmp cx,11Bh
  592.     jne .vmssm_03
  593.     mov esi,mode2
  594.     mov ecx,1279
  595.     mov edx,1023
  596.     jmp .vmssm_st00
  597. .vmssm_03:
  598.     xor eax,eax
  599.     dec eax
  600.     pop esi
  601.     pop ecx
  602.     pop edx
  603.     retn
  604. .vmssm_st00:
  605.     mov [OS_BASE+0FE00h],ecx
  606.     mov [OS_BASE+0FE04h],edx
  607.     cli
  608.     mov dx,03c4h
  609.     lodsw
  610.     out dx,ax
  611.     mov dx,03d4h
  612.     mov al,11h
  613.     out dx,al
  614.     inc dx
  615.     in al,dx
  616.     and al,7fh
  617.     out dx,al
  618.     dec dx
  619.     mov ecx,13
  620. .vmssm_st01:
  621.     lodsw
  622.     out dx,ax
  623.     loop .vmssm_st01
  624.     sti
  625.     xor eax,eax
  626.     pop esi
  627.     pop ecx
  628.     pop edx
  629.     retn
  630.  
  631.  
  632. ;------------DATA AREA---------------
  633. align 4
  634.  
  635. mdvm_func_table:
  636.         dd MDSTART
  637.         dd vm_info_init,          vm_get_cur_mode
  638.         dd vm_set_video_mode,     vm_restore_init_video_mode
  639.         dd vm_change_screen_size, vm_change_position_screen
  640.  
  641.  
  642. CRTCreg:
  643. _00  db ?
  644. _01  db ?
  645. _02  db ?
  646. _03  db ?
  647. _04  db ?
  648. _05  db ?
  649. _06  db ?
  650. _07  db ?
  651. _08  db ?
  652. _09  db ?
  653. _0a  db ?
  654. _0b  db ?
  655. _0c  db ?
  656. _0d  db ?
  657. _0e  db ?
  658. _0f  db ?
  659. _10  db ?
  660. _11  db ?
  661. _12  db ?
  662. _13  db ?
  663. _14  db ?
  664. _15  db ?
  665. _16  db ?
  666. _17  db ?
  667. _18  db ?
  668. _19  db ?
  669.  
  670. align 4
  671.  
  672. oldX       dd ?
  673. oldY       dd ?
  674. initvm     dd ?
  675. currvm     dd 0
  676. refrate    dd 0
  677. initrr     dd 0
  678. systlb     dd 0
  679. pclock     dd ?
  680. mdrvm      dd 0 ; 0 - not drv init yet, 1 - already drv init
  681.  
  682.  
  683. drvinfo:
  684. drvname:   times 32 db ' '
  685. drvver     dd 0
  686.            times (32-($-drvver))/4 dd 0
  687. drvmode    dw 011Bh,0118h,0115h,0112h
  688.            times (64-($-drvmode))/2 dw 00h
  689. _m1        dw 0,0,0,0,0
  690. _m2        dw 0,0,0,0,0
  691. _m3        dw 0,0,0,0,0
  692. _m4        dw 0,0,0,0,0
  693. _m5        dw 0,0,0,0,0
  694.            times (512-($-drvinfo)) db 0
  695. drvinfoend:
  696.  
  697.  
  698. ;1280x1024 - 11Bh
  699. mode3:
  700.       dw 0101h
  701.       dw 0d000h,9f01h,9f02h,9303h,0a904h,1905h,2806h,5a07h
  702.       dw 0110h,8411h,0ff12h,0ff15h,2916h
  703.  
  704. ;1024x768 - 118h
  705. mode2:
  706.       dw 0101h
  707.       dw 0a400h,7f01h,7f02h,8703h,8404h,9505h,2406h,0f507h
  708.       dw 0310h,8911h,0ff12h,0ff15h,2516h
  709.  
  710. ;800x600  - 115h
  711. mode1:
  712.       dw 0101h
  713.       dw 8000h,6301h,6302h,8303h,6a04h,1a05h,7206h,0f007h
  714.       dw 5910h,8d11h,5712h,5715h,7316h
  715.  
  716. ;640x480 - 112h, 12h
  717. mode0:
  718.       dw 0101h
  719.       dw 6000h,4f01h,4f02h,8303h,5304h,9f05h,00b06h,3e07h
  720.       dw 0ea10h,8c11h,0df12h,0df15h,0c16h
  721.  
  722. ; 640x400
  723. ;mymode0:
  724. ; dw 0101h
  725. ;_0_7 dw 5f00h,4f01h,4f02h,8303h,5304h,9f05h,0BF06h,1f07h
  726. ; dw 9c10h,8e11h,8f12h,9615h,0B916h ;,4013h
  727.  
  728. ; 640x800
  729. ;mymode1:
  730. ; dw 0101h
  731. ; dw 5f00h,4f01h,4f02h,8003h,5004h,9f05h,06006h,0FF07h
  732. ; dw 2d10h,8f11h,2012h,2615h,05716h ;,4013h
  733.  
  734.  
  735. DRVM_END:
  736.  
  737.