home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / RiscPc / jeux / biohazard.arc / s / VSyncEvent < prev    next >
Text File  |  1994-06-05  |  5KB  |  215 lines

  1. ; Use the GET directive to include register definitions as if typed here
  2.  
  3.       KEEP
  4.           GET     h.WolfReg
  5.  
  6. ; Use the GET directive to include a list of SWI names as if typed here
  7.  
  8.           GET     h.SWInames
  9.  
  10. ; Area name C$$code advisable as wanted to link with C output
  11.  
  12.           AREA    |C$$code|, CODE, READONLY
  13.  
  14. ; Export global symbols
  15.  
  16.           IMPORT  |x$stack_overflow|
  17.        EXPORT  |InitiateScreenEvent|
  18.       EXPORT  |RelinquishScreenEvent|
  19.           EXPORT  |VerifyBufferClear|
  20.       EXPORT  |SetFlagBufferUsed|
  21.       EXPORT  |ScreenEvent|
  22.  
  23. InitScEvX DCB     "InitiateScreenEvent", 0
  24.           ALIGN
  25. InitScEvY DCD     &ff000000 + InitScEvY - InitScEvX
  26.  
  27. ; *************************************************************************
  28.   ; Initialise the vsyncing screen re-drawing routine.
  29.   ; Claims event, and issues a FX 14,4 to begin vsyncing
  30.   ; On entry:
  31.   ;         null
  32.   ;
  33.   ; Returns:
  34.   ;         null
  35.   ; *************************************************************************
  36.  
  37. |InitiateScreenEvent|
  38.       STMFD   r13!,{r0-r12,link}
  39.  
  40.           ;Claim screen event for ScreenEvent
  41.           MOV   r0,#16
  42.           ADR   r1,|ScreenEvent|
  43.           MOV   r2,#1
  44.           SWI   OS_Claim
  45.  
  46.           ;FX 14,4 - initialise vsyncing event
  47.           MOV   r0,#14
  48.           MOV   r1,#4
  49.           SWI   OS_Byte
  50.  
  51. EndInitSEnt
  52.           LDMFD   r13!,{r0-r12,pc}
  53.  
  54. Activate_SEvent
  55.       DCD    0
  56.  
  57.   ; *************************************************************************
  58.   ; Relinquish the vsyncing screen re-drawing routine.
  59.   ; Issues a FX 13,4 to end vsyncing and then relinquishes event
  60.   ; On entry:
  61.   ;         null
  62.   ;
  63.   ; Returns:
  64.   ;         null
  65.   ; *************************************************************************
  66.  
  67. ReliSEntX DCB     "RelinquishScreenEvent", 0
  68.           ALIGN
  69. ReliSEntY DCD     &ff000000 + ReliSEntY - ReliSEntX
  70.  
  71. |RelinquishScreenEvent|
  72.       STMFD   r13!,{r0-r12,link}
  73.  
  74.       ;FX 13,4 - stop vsyncing
  75.           MOV   r0,#13
  76.           MOV   r1,#4
  77.           SWI   OS_Byte
  78.  
  79.       ;Relinquish event
  80.           MOV   r0,#16
  81.           ADR   r1,|ScreenEvent|
  82.           MOV   r2,#1
  83.           SWI   OS_Release
  84.  
  85. EndReliSEnt
  86.           LDMFD   r13!,{r0-r12,pc}
  87.  
  88. CurrentBuffer
  89.           DCD 3
  90.  
  91. ; Flag codes are...
  92. ;
  93. ;    0 = buffer clear and ready to use
  94. ;    1 = buffer full and ready to be displayed
  95. ;    2 = buffer being used to display picture on screen
  96.  
  97. Flags
  98.           DCD 0
  99.           DCD 0
  100.           DCD 2
  101.  
  102.        DCD 0
  103.       DCD 0
  104.       DCD 0
  105.  
  106. |ScreenEvent|
  107.           CMP    r0,#4                      ;check for vsync
  108.           MOVNES pc,r14
  109.  
  110.       STMFD   r13!,{r0-r12,r14}
  111.  
  112.       ;load up flags
  113.       ADR    r3,CurrentBuffer
  114.           ADR    r4,Flags
  115.       MOV    r7,r4
  116.           LDR    r2,[r3]
  117.  
  118.           ;modify base of flags to point to the next buffer to be shown
  119.           MOV    r5,#1
  120.           CMP    r2,#1
  121.           ADDEQ  r4,r4,#4   ;point to buffer 2
  122.           MOVEQ  r5,#2
  123.       CMP    r2,#2
  124.           ADDEQ  r4,r4,#8   ;point to buffer 3
  125.           MOVEQ  r5,#3      ;if buffer is 3, next buffer is 1.
  126.  
  127.           CMP    r2,#2
  128.           ADDEQ  r7,r7,#4
  129.           CMP    r2,#3
  130.           ADDEQ  r7,r7,#8
  131.  
  132.           LDR    r6,[r4]
  133.           CMP    r6,#1
  134.           BNE    EndScreenEvent ;next buffer is empty & not ready for use
  135.  
  136.       ;flip screen banks to show next screen
  137.           MOV   r0,#113
  138.           MOV   r1,r5
  139.           SWI   OS_Byte
  140.  
  141.           ;update current buffer
  142.           STR   r5,[r3]
  143.  
  144.       ;clear the flags.
  145.           MOV   r6,#0
  146.           STR   r6,[r7]
  147.           MOV   r6,#2
  148.           STR   r6,[r4]
  149.  
  150. EndScreenEvent
  151.           LDMFD   r13!,{r0-r12,pc}
  152.  
  153.   ; *************************************************************************
  154.   ; Busy waits until a particular buffer is clear.
  155.   ; On entry:
  156.   ;         r0 = buffer to check
  157.   ;
  158.   ; Returns:
  159.   ;         null
  160.   ; *************************************************************************
  161.  
  162. |VerifyBufferClear|
  163.  
  164.       STMFD   r13!,{r0-r12,r14}
  165.  
  166.       ;get address of flags base & current buffer
  167.       ADR     r1,Flags
  168.  
  169.       ;modify to point to correct flag
  170.           CMP     r0,#2
  171.           ADDEQ   r1,r1,#4
  172.           CMP     r0,#3
  173.           ADDEQ   r1,r1,#8
  174.  
  175. WaitLoop
  176.           ;check if buffer is clear
  177.           LDR     r2,[r1]
  178.           CMP     r2,#0
  179.           BNE     WaitLoop
  180.  
  181. EndVBufClear
  182.           LDMFD   r13!,{r0-r12,pc}
  183.  
  184.   ; *************************************************************************
  185.   ; Sets the flag for a particular buffer as used
  186.   ; On entry:
  187.   ;         r0 = buffer to set
  188.   ;
  189.   ; Returns:
  190.   ;         null
  191.   ; *************************************************************************
  192.  
  193. |SetFlagBufferUsed|
  194.  
  195.       STMFD   r13!,{r0-r12,r14}
  196.  
  197.       ;get address of flags base & current buffer
  198.       ADR     r1,Flags
  199.  
  200.       ;modify to point to correct flag
  201.           CMP     r0,#2
  202.           ADDEQ   r1,r1,#4
  203.           CMP     r0,#3
  204.           ADDEQ   r1,r1,#8
  205.  
  206.           ;set the flag
  207.           MOV     r2,#1
  208.           STR     r2,[r1]
  209.  
  210. EndSetFBufUsed
  211.           LDMFD   r13!,{r0-r12,pc}
  212.  
  213.  
  214.       END
  215.