;os_byte_113
;-----------
;Write display hardware screen bank
;forces VSyncs if required
;
;Entry:
; R11 - pointer to VARS
;Exit:
; R2 - corrupt

.os_byte_113
 #if compile_IOMD == 1
   BL      flush_screen			;flush the screen cache
 #endif

 #if compile_GPU == 0
   LDRB    R14, [R11, #force_vsync - VARS]	;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

   LDRB    R0, [R11, #force_vsync - VARS]
   TEQ     R0, #0			;are we forcing VSyncs?
   BEQ     _P1				;NO, exit

   LDRB    R0, [R11, #os_byte_19_happened - VARS]
   MOV     R14, #0
   TEQ     R0, #0			;do we need to frame pace?
   STRB    R14, [R11, #os_byte_19_happened - VARS]
   MOV     R11, R1
   MOVEQ   R0, #19			;YES, force a VSync to add delay
   SWIEQ   XOS_Byte
   MOV     R1, R11
 #endif
 #if compile_GPU == 0
   LDRB    R2, [R11, #os_byte_19_happened - VARS]	;do we need to force a Vsync?
   MOV     R14, #0
   STRB    R14, [R11, #os_byte_19_happened - VARS]
   MOV     R11, R1			;preserve R1
   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
   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, note stack must "SWI_stack" on 3.11 build
   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
 #endif
 ._P1
 #if compile_IOMD == 1
   BL      get_screen_start		;corrupts R0
;ZZZ
;   #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, #113			;preserve R0
B       exit_SWI_veneer
