home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Heaven Sunny 2 / APPARE2.BIN / oh_towns / his / omake / vsynci.asm < prev    next >
Assembly Source File  |  1995-06-20  |  5KB  |  219 lines

  1. ;*****************************************************
  2. ;*                                                   *
  3. ;*             垂直同期割り込みサンプル              *
  4. ;*                                                   *
  5. ;*    1995.1.17                    by ちょもらんま   *
  6. ;*                                                   *
  7. ;*****************************************************
  8.  
  9. ;*****************  セグメント関係  ******************
  10. VRAM2        equ    0104h
  11. TBIOS        equ    0110h
  12.  
  13. ;************** 割り込みハードウェア関係 *************
  14. VSYNCclear    equ    05cah
  15. IMR_S        equ    0012h
  16. OCW1_S        equ    0012h
  17. OCW2_M        equ    0000h
  18. OCW2_S        equ    0010h
  19. EOIcommand    equ    00100000b
  20. WaitRegister    equ    006ch
  21.  
  22. ;*****************   BIOS関係   ******************
  23. EGB_workSize    equ    1536
  24. EGB        equ    20h
  25. EGB_init    equ    00h
  26. EndProcess    equ    4ch
  27. GetNativeVector    equ    2502h
  28. GetRealVector    equ    2503h
  29. SetNativeAlways    equ    2506h
  30. SetBothVector    equ    2507h
  31. VsyncNumber    equ    4bh
  32.  
  33. ;********************** その他 ***********************
  34. Ylines        equ    480
  35. PaintColor    equ    0ffffffffh
  36. HByte        equ    1024/2
  37. MaxBar        equ    640/8
  38. VsyncNotOccured    equ    0
  39. VsyncOccured    equ    -1
  40.  
  41.         .386p
  42.         assume    cs:flat,ds:flat,ss:stack
  43.  
  44. ;****************** ワークエリア *********************
  45.  
  46. flat        segment
  47.  
  48. EGB_work    db    EGB_workSize dup( ? )
  49.  
  50. realVector    dd    ?
  51. nativeVectorOff    dd    ?
  52. nativeVectorSeg    dw    ?
  53. saveIMR_S    db    ?
  54. saveIMR_M    db    ?
  55.  
  56. originalDS    dw    ?
  57. vsyncflag    dd    ?
  58.  
  59. ;********************** 初期化 ***********************
  60.  
  61. main        proc    near
  62.         push    ds
  63.         pop    gs
  64.         push    dword ptr TBIOS
  65.         pop    fs
  66. ; EGB初期化
  67.         mov    ah,EGB_init
  68.         mov    edi,offset EGB_work
  69.         mov    ecx,EGB_workSize
  70.         call    pword ptr fs:[EGB]
  71. ; フラグ初期化
  72.         mov    vsyncflag,VsyncNotOccured
  73.  
  74. ;------------ PICアクセス待ちウェイト -------------
  75. PicWait        macro
  76.         out    WaitRegister,al ; 1μ秒ウェイト
  77.         cmc
  78.         cmc
  79.         endm
  80.  
  81. ;************** VSYNC割り込み設定 ***************
  82.  
  83. ;------------------ 割り込み禁止 ---------------------
  84.         cli
  85.  
  86. ;------------- 旧割り込みベクタの保存 ----------------
  87.         mov    cl,VsyncNumber
  88. ; リアル側
  89.         mov    ax,GetRealVector
  90.         int    21h
  91.         mov    realVector,ebx
  92. ; ネイティブ側
  93.         mov    ax,GetNativeVector
  94.         int    21h
  95.         mov    nativeVectorOff,ebx
  96.         mov    ax,es
  97.         mov    nativeVectorSeg,ax
  98.  
  99. ;--------------- 割り込みベクタの設定 ----------------
  100.         push    ds
  101.         mov    edx,offset VsyncHandler
  102.         mov    ax,cs
  103.         mov    ds,ax
  104.         mov    ax,SetNativeAlways
  105.         int    21h
  106.         pop    ds
  107.  
  108. ;---------------- DSレジスタの保存 -----------------
  109.         mov    originalDS,ds
  110.  
  111. ;----------- 割り込みマスクレジスタの設定 -----------
  112.         in    al,IMR_S
  113.         PicWait
  114.         mov    saveIMR_S,al
  115.         and    al,11110111b ; VSYNC割り込み許可
  116.         out    OCW1_S,al
  117.  
  118. ;------------------ 割り込み許可 ---------------------
  119.         sti
  120.  
  121. ;*************** デモンストレーション ****************
  122.  
  123. ; レジスタ表
  124. ;   EAX:色   EBX:描画回数   ECX:縦ライン数  EDX:VRAMアドレス
  125. ;   ESI,EDI,EBP:未使用
  126.  
  127. ; 描画準備
  128.         mov    eax,PaintColor
  129.         push    dword ptr VRAM2
  130.         pop    es
  131.         xor    ebx,ebx
  132. #waiting_loop:
  133.         cmp    vsyncflag,VsyncOccured
  134.         jne    short #waiting_loop
  135. ; VRAMアドレス計算
  136.         lea    edx,[ebx*4] ; edx <= ebx*4
  137.         mov    ecx,Ylines
  138. ; 描画
  139. #drawing_loop:
  140.         mov    es:[edx],eax
  141.         add    edx,HByte
  142.         loop    #drawing_loop
  143.  
  144.         mov    vsyncflag,VsyncNotOccured
  145.         inc    ebx
  146.         cmp    ebx,MaxBar
  147.         jb    short #waiting_loop
  148.  
  149. ;************** VSYNC割り込み終了 ***************
  150.  
  151. ;------------------ 割り込み禁止 ---------------------
  152.         cli
  153.  
  154. ;------------ 割り込みマスクレジスタ復元 ------------
  155.         mov    al,saveIMR_S
  156.         out    OCW1_S,al
  157.  
  158. ;--------------- 割り込みベクタ復元 ------------------
  159. ; リアル側
  160.         mov    ebx,realVector
  161. ; ネイティブ側
  162.         mov    edx,nativeVectorOff
  163.         mov    ax,nativeVectorSeg
  164.         mov    ds,ax
  165.  
  166.         mov    cl,VsyncNumber
  167.         mov    ax,SetBothVector
  168.         int    21h
  169.  
  170. ;------------------ 割り込み許可 ---------------------
  171.         sti
  172.  
  173. ;***************** プログラム終了 ********************
  174.         mov    ah,EndProcess
  175.         xor    al,al
  176.         int    21h
  177. main        endp
  178.  
  179. ;***************** 割り込みハンドラ ******************
  180.  
  181. VsyncHandler    proc    near
  182.         cli
  183.         push    ds
  184.         push    eax
  185.         push    edx
  186.  
  187. ;-- VSYNC割り込み原因クリアレジスタへの書き込み --
  188.         mov    dx,VSYNCclear
  189.         out    dx,al
  190.  
  191. ;---------------- DSレジスタの復元 -----------------
  192.         mov    ds,cs:originalDS
  193.  
  194. ;-------------- 割り込みハンドラの処理 ---------------
  195. ; フラグを立てる
  196.         mov    vsyncflag,VsyncOccured
  197.  
  198. ;-------------------- EOI発行 ---------------------
  199. ; スレーブ側
  200.         mov    al,EOIcommand
  201.         out    OCW2_S,al
  202.         PicWait
  203. ; マスタ側
  204.         out    OCW2_M,al
  205.  
  206.         pop    edx
  207.         pop    eax
  208.         pop    ds
  209.         iretd
  210. VsyncHandler    endp
  211.  
  212. flat        ends
  213.  
  214. ;******************* スタック設定 ********************
  215.  
  216. stack        segment stack
  217.         db    2000 dup( ? )
  218. stack        ends
  219.         end    main