;os_byte_113
;-----------
;Write display hardware screen bank
;forces VSyncs if required
;
;Exit:
; R2 - corrupt

.os_byte_113
 #if compile_GPU == 0
   LDR     R14, force_vsync		;are we forcing VSyncs?
   TEQ     R14, #0
   BEQ     vector_handler_forward	;NO, pass to OS
 #endif

 #if compile_GPU == 1
   BL      pre_SWI_veneer		;call SWI that follows
   SWI     XOS_Byte
   BL      post_SWI_veneer
   MOV     R11, R1			;preserve R1

   LDR     R0, force_vsync
   TEQ     R0, #0			;are we forcing VSyncs?
   BEQ     _P1				;NO, exit

   LDR     R0, os_byte_19_happened
   TEQ     R0, #0			;do we need to frame pace?
   MOVEQ   R0, #19			;YES, force a VSync to add delay
   SWIEQ   XOS_Byte
 #endif
 #if compile_GPU == 0
   MOV     R11, R1			;preserve R1
   LDR     R2, os_byte_19_happened	;do we need to force a Vsync?
   TEQ     R2, #0
   BEQ     _delay_frame_change		;YES, don't change frame until end

					;we've seen a VSync, so change frame
					;immediately
   BL      pre_SWI_veneer		;call SWI that follows
   SWI     XOS_Byte
   BL      post_SWI_veneer
   MOV     R11, R1			;preserve R1
   B       _P1

   ._delay_frame_change			;not seen a VSync since the last
   MOV     R0, #19			;force a VSync
   BL      hv_pre_SWI_veneer		;call SWI that follows
   SWI     XOS_Byte			;wait for next VSync

   MOV     R0, #113			;change frames
   MOV     R1, R11			;preserve R1
   BL      pass_SWI_on
   SWI     XOS_Byte			;do the frame change
   BL      post_SWI_veneer
   MOV     R11, R1			;preserve R1
 #endif
 ._P1
 #if compile_IOMD == 1
   BL      get_screen_start
   #if compile_IOMD == 1 AND JIT_debug == 1
     TEMP    R0
     STR     R14, report_JIT_IOMD_occurred
     LOCK    R0
     BL      report_JIT
   #endif
 #endif

 MOV     R0, #0
 STR     R0, os_byte_19_happened	;look for a vsync
 MOV     R1, R11			;preserve R1
 MOV     R0, #113			;preserve R0
B       exit_SWI_veneer
