;********************** Build specific Variables **********************
#if compile_RO > 311
 .MEMC_mask			DCD 0	;previous MEMC field mask
 .environment_handlers		DCD 0	;space to track handlers
#endif

#if Managed_ChannelHandler == 1
 .our_sound_DA_number		DCD 0
 .os_sound_configure		DBD 5	;Sound_Configure previous values
 .hypervised_sound_configure	DBB sound_config_struct.size
				;^^^^^^^^Sound_Configure values game uses
 .our_channel_handler		DBD 4	;PRM4-10 our Channel Handler
 .our_scheduler			DCD 0	;PRM4-12 our Scheduler
#endif

#if compile_RO > 400
 .page_zero_module_cmdline	DCD 0	;commandline 26bit Module was
					;entered with, used for Aborts
#endif

#if compile_RO > 311
 .Error_handler_buffer		DCD 0	;pointer to error handler buffer
 .domainID			DCD &FF8	;RO3.5+ address of DomainID
 .JIT_task_ID			DCD 0, 0	;current task domain ID and Wimp ID
 .Module_being_inserted		DCD 0	;=Stub Module base during 26bit Module init
 .readVDUstart				;used to get the screen start address
  DCD 149				;PRM1-731 display start
  DCD 150				;size of screen
  DCD -1
  DCD 0
  DCD 0
					;table of cache ops to action on JIT exit

 ;-------------- CACHE OPS -------------
				DCD 0	;cache_ops_size
				DCD 0	;cache_ops_index
 .pending_cache_ops		DBB max_cache_ops_index
 ;--------- END OF CACHE OPS -----------

 .emulate_RISCOS		DCD -1	;default to current RISCOS behaviour
 .JIT_fixups			DCD 0	;address of fixup table
 .JIT_module_fixups		DCD 0	;address of module fixup table
 #if compile_RO == 400
   .IRQ_vector			DCD 0	;copy of &18
 #endif

 .hypervised_vectors
   DCD 0
   .hypervised_Undefined	DCD 0
   DCD 0
   DCD 0
   DCD 0
   DCD 0
   .hypervised_IRQ		DCD 0

; STRUCT hardware_vectors
; {
;   .reset		DCD 0
;   .undefined		DCD 0
;   .swi		DCD 0
;   .prefetch		DCD 0
;   .data_abort		DCD 0
;   .address_exception	DCD 0
;   .irq		DCD 0
; }

 .hypervised_IRQ1V		DCD 0	;IRQ1V entry
 .page_zero_EnvString		DCD 0	;RO address of EnvString
 .page_zero_EnvTime		DCD 0	;RO address of EnvTime
#if High_Vectors == 1
  .page_zero_UpCall		DCD 0	;RO address of UpCall discname
#endif

 #if JIT_predictive_branching == 1
 ;-------------- BRANCH PREDICTION ------------
				DCD 0	;current pointer in the circular BPT
 .JIT_branch_prediction_table	DBD JIT_branch_prediction_max
 ;--------- END OF BRANCH PREDICTION ----------
 #endif
 .VProtect_Module		DCD 0	;address of VProtect Module
				DCD 0	;size of VProtect
 .JIT_ARM4			DCD 0	;JIT mode - bits 0..7 0=ARMv3 1=ARMv4
					;   cache   bit 31    0=on    1=off
 .JIT_event11_active		DCD 0	;track event 11, as we've enabled it
 .JIT_started_at		DCD 0	;the start address of the current code
					;the JIT is interpreting
 .JIT_processed_counter		DCD 0	;counts how many instructions handled
 .codelet_cache_flush		DBD 2	;pending codelet cache flush
 .jit_managed_ldr_pc_r13_2	DCD 0	;address of general use LDR PC,[R13],#4
 .jit_managed_ldr_pc_r13	DCD 0	;address of general use LDR PC,[R13],#4
 .jit_managed_os_exit		DCD 0	;SWI OS_Exit
 .jit_managed_swi		DCD 0	;SWI 0

 .jit_task_count		DCD 0	;number of JIT tasks running
 .jit_code			DCD 0	;translated code address
					;this is a static value once setup
 .first_codelet			DCD 0	;first codelet address
					;this is a static value once setup

 .existing_Branch_thru_zero	DCD 0	;RISCOS Branch Thru Zero handler
 .page_zero_L2PT		DCD 0	;copy of page zero L2PT entry

 .jit_claimed_vectors		DCD 0	;address of claimed vector table
 .Vector_Claim_Handlers		DCD 0	;address of vector entry points
 .DeviceVectors			DBB (last_device_to_track + 1) * device_table.size
 ALIGN

#if compile_IOMD == 1
  .hwd_framestore		DCD 0
#endif
#if compile_IOMD == 1 OR compile_GPU == 1
   .VIDC20_width		DCD 0	;VIDC20 screen width
   .VIDC20_height		DCD 0	;VIDC20 screen height
   .VIDC20_aspect_ratio		DCD 0	;VIDC20 screen ratio: 0=5:4 1=2:3 2=10:4
 #endif
 #if compile_GPU == 1
   .Cursor_state		DCD 0	;0=pointer off, 1..4=pointer on
   .blit_in_progress		DCD -1	;<>0 if a blit is in progress
   .old_VIDC20_HCR		DCD 0	;overall screen width
   .old_VIDC20_VCR		DCD 0	;overall screen height
   .our_GraphicsV_ID		DCD 0	;<>0 if GraphicsV claimed
 #endif
 #if compile_GPU == 1 AND use_overlay == 0
   .overlay_clip		DBD 4
 #endif
 #if use_overlay == 1
   .current_overlay_bank	DCD 0	;bank to display in the overlay
   .overlay_clip		DCD 0,0	;width ration, height ratio
   .overlay_transform		DBD 7	;transform settings for overlay
   .overlay_id			DCD -1
				DBB overlay_info.size-4

   .overlay_mode	;Mode Selector Block
    DCD	1	;flags
    DCD	0,0	;x,y
    DCD	5	;log2bpp
    DCD	-1	;hz (-1 use any frame rate)
		;Mode Variable Numbers
    DCD	0	;0=ModeFlags
    DCD	0	;framebuffer format - 32bpp TBGR
    DCD	3	;3=NColour
    DCD	-1	;ncolour
    DCD	13	;13=MinScreenBanks
    DCD	screen_banks
    DCD	-1

   .overlay_pos			DCD 0	;head
				DCD 0,0	;x,y
 #endif

 .os_memory_block	DCD 0, 0, 0	;block for OS_Memory actions
 #if compile_IOMD == 1 AND JIT_debug == 1
   .current_screen_mode	DCD 0		;current screen mode VIDC parameter ptr
   .blitter_FPS		DCD 0		;refresh rate of the blitter
 #endif
 .closest_screen_mode	DCD -1		;the actual MODE no.

 .IOMD_FSIZE_value	DCD 0		;track IOMD FSIZE value

					;track VIDC20 registers
 .vidc20_regs		DBD (VIDC20_VCER - VIDC20_HCR) + 1

 .vram_available	DCD 0		;amount of VRAM
 .IOMD_addr		DCD IOC_addr	;base address of IOMD
					;default to IOC address for 32bit

					;speed of VIDC20 clock
					;RPC   - 24000
					;A7000 - 32000
 .VIDC20_clock		DCD RPC_reference_clock
					;space for claimed devices
#endif

#if compile_GPU == 1 OR compile_IOMD == 1
 .IOC_registers			DBB &80 >> 2	;1 byte per IOC register
#endif

 .SVC_stack_init		DCD 0		;top of SVC stack
#if compile_RO == 400
 .DA2_delta			DCD 0		;RO4/6 SA DA2 size delta
#endif
#if compile_RO > 311
 .IRQ_stack_init		DCD 0		;top of IRQ stack
 .transient_stack_DA_number	DCD 0
 .transient_stacks		DCD 0		;address of transient stacks
 .transient_stacks_used		DCD 0		;bitmap of used stacks
 .pre_JIT_wimp_slot_size	DCD 0		;size of WimpSlot to return
 #if compile_RO == 400
   .abort_stack_DA_number	DCD 0
   .und_stack			DCD 0		;32bit Abort stack on IOMD
   .undefined_stack_DA_number	DCD 0
 #endif
 #if MMUControl2_support == 0
  .cacheops_DA_number		DCD 0
  .cacheops_DA_address		DCD 0
  .DCache_CleanBaseAddress	DCD 0, 0
 #endif
 #if compile_IOMD == 1
  .VIDC20_addr		DCD VIDC20_base_addr	;base address of VIDC20
 #endif

  .MEMC_CinitOS	DCD 0			;pointer address as passed by the OS
.MEMC_registers				;MEMC registers
  .MEMC_Vinit	DCD 0
  .MEMC_Vstart	DCD 0
  .MEMC_Vend	DCD 0
  .MEMC_Cinit	DCD RO3xx_Pointer_Buffer
  .MEMC_Sstart  DCD 0
  .MEMC_SendN   DCD 0
  .MEMC_Sptr	DCD 0
		DCD &36E0D0C		;MEMC CR
  		DCD 0			;MEMC SendC
					;current speed for VIDC1 clock
  .VIDC1_clock		DCD VIDC1_reference_clock
  .VIDC1_CR		DCD &E0000800	;current VIDC1 Control Register
  .modeextension_in_progress DCD -1	;are we processing a Mode_Extension
#endif

;********************** Variables across all builds **********************

.Open_Filer_Window      DCB "Filer_OpenDir "
.ADFFS_Current_DiscName DCB "12345678901234567890123456789012.$", 0
                        ALIGN		;^^^ must follow Open_Filer_Window
.Star_Dismount		DCB "adfs:DISMOUNT "
.Star_Dismount_DiscName DCB "78901234567890123456789012", 0
                        ALIGN		;^^^ must follow Star_Dismount

.softwareVectors	DBD (LastVectorToTrack - FirstVectorToTrack + 1) * 2
					;^^^ software vector table
.softwareVectorBitmap	DBD (LastVectorToTrack + 31) DIV 32
					;^^^ bit is set if vector is claimed by us

.FileType_Loaded	DBB 12		;"ADF", "APD", "JFD vx.xx" or "HFEvx"
.Current_File_Mounted	DCD 0		;pointer to filename
.record_filename	DCD 0		;pointer to for recording filename

.JFD_tmp		DBB JFD_Header	;space to load JFD headers
			ALIGN

.reserve_DA	DCD 0			;<>0 prevent the DA from shrinking
#if compile_RO == 311
  .RO31_memmap_entry	DCD 0, 0, 0, -1	;used to remap memory pages
  .WIMP_reentry			DCD 0	;set to acknowledge the WIMP calling us
  .WIMP_OScopy_ChangeDynamic	DCD 0	;address of WIMP's OS_ChangeDynamic
  .DA_mask			DCD 0
  .RO31_Next_DynamicAreaNo	DCD  RO31_First_DynamicAreaNo	;our DA number on RO3.1
  .RO31_DynamicAreaAddress	DCD  &1000000			;..end address
  .RO31_DA_table
  ;1st is always ADFFS
  .DA_address	DCD 0			;ADFFS buffer address
		DCD 0, 0
  ;2nd onward are 3rd party
  DBB RO31_DA.size * (RO31_Last_DynamicAreaNo-RO31_First_DynamicAreaNo)
#else
  .DA_address	DCD 0			;ADFFS buffer address
  .fscontrol_filename	DCD 0		;filename when hypervising FSControl
#endif

.VARS	DCD 0				;pointer to VARS
;********************** flags/byte values **********************
#if compile_RO >= 400			;must come after VARS as the early entries are word aligned
  .Current_Machine_State	DBB Machine_State.Size
#endif
#if Managed_ChannelHandler == 1
 .dont_trap_sound_configure	DCB 0	;<>0 if Sound_Configure needs to be trapped
 .soundDMA_restarting		DCB 0	;<>0 if SoundDMA is restarting
#endif
#if compile_RO > 311
 .remapping_video_memory	DCB 0	;<>0 if we need to remap video memory
 .is_screen_remapped	DCB 0	;<>0 when screen memory is remapped
#endif
#if compile_IOMD == 1
 .TV_offset			DCB 0		;*TV adjustment
 .ignore_next_mode_change	DCB 0
#endif
#if compile_RO == 400
 .riscos6		DCB 1		;=0 if running on RO4/6 SA
#endif
.force_vsync		DCB 0		;=no. of VSync's to wait at OS_Byte 113
.os_byte_19_happened	DCB 0
.suspend_adding_sectors	DCB 0
.Format_In_Progress	DCB 0		;points to our disc rec during a format
.Floppy_Changed		DCB 0		;>0 disc has changed
.Type_Mounted		DCB 0		;0=unmounted, 1=ADF, 2=APD, 3=JFD, 4=HFE
#set Type_None = 0
#set Type_ADF  = 1
#set Type_APD  = 2
#set Type_JFD  = 3
#set Type_HFE  = 4

.miscop_floppy_HD	DCB 0		;is the floppy HD?
.disk_swap_pending	DCB 0		;<>0 if a disk change is pending
.vectorHandler_swapdisc DCB 0		;<>0 means processing a disc change
.prevent_RMKills	DCB 0		;<>0 prevent essential module kills
.prevent_CMOSchanges	DCB 0		;<>0 CMOS changes are prevented
.prevent_Hourglass	DCB 0		;<>0 don't display hourglass
.current_density	DCB 0		;density (1, 2, 4, 8)
.floppy_content_changed	DCB 0		;<>0 if floppy needs flushing
.flush_in_progress	DCB 0		;<>0 if a save is actually a flush
.BASICTrans_loaded	DCB 0		;<>0 if BASICTrans was loaded
.force_mono		DCB 0		;-127/127 to force audio to left/right
.emulate_1772		DCB 1		;0=710/711, 1=1772
.FDC_Error_Sector_Not_Found	DCB Error_Sector_Not_Found_1772	;errors to return
.FDC_Error_Sector_CRC		DCB Error_Sector_CRC_1772	;..FDC dependent
.FDC_Error_Mark_Not_Found	DCB Error_Mark_Not_Found_1772
.No_Floppy_Support	DCB 0		;if <>0 no MiscOp or DiscOp for floppies should be passed on
.os_byte_176_time	DCB 0
.event_4_enabled	DCB 0		;<>0 if _trigger_event_4 is generating VSync
#if compile_GPU == 1 OR compile_IOMD == 1
 .vsync_unthreaded	DCB 0		;<>0 raise VSync unthreaded
#endif
#if compile_GPU == 1
 .vsync_triggered	DCB 0		;<>0 if VSync occurred
 .display_V_border	DCB 32		;=0 to display the vertical border, =32 to not display borders
#endif
#if compile_RO > 311
 .current_mode_bitdepth DCB 0		;bitdepth of mode in VIDC1 format VIDC1-20
#endif
.BootFloppyRequested	DCB 0		;<>0 if the Filer wants to boot a floppy
ALIGN
;***************************************************************
.crc_ccitt		DCD 0		;CRC table for MFM
.crc32_table		DCD 0		;CRC32 table

.stereo_position	DBD 2		;1 byte per channel for stereo position

.our_Floppy_DA_number	DCD 0		;our Dynamic Area number
.DA_size		DCD 0		;size of Dynamic Area
.JFD_delta_offset	DCD 0		;offset in DA to store next new delta sector
.IRQsema		DCD &108	;pointer to IRQsema

.miscop_sequence_no	DCD 0		;OS uses this to track changes
.current_PageSize	DCD 0		;size of memory pages
 #if compile_RO >= 450
  .current_PageSizeSH	DCD 0		;size of memory pages as a shift (1<<n)
 #endif
.cpu_id			DCD 0		;CPU model no
.obey_file_offset	DCD 0		;offset address of floppy Boot script
.os_version		DCD 0		;BCD of OS version ie 3.11 would be &31100

.MonotonicTime		DCD 0		;time we reset monotonic time PRM1-446

.new_style_error_block	DCD 0, 0, 0	;new style error for newer OS versions



.time_last		DCD 0		;time DiscOp was last called, used
					;to advance the virtual disc head

.File_Size_Limit	DCD O_File_Size_Limit * 1024

.SiS			DCD 0, 0, 0, 0	;nested sector cache
.sector_timing		DCD 0		;bit position * this = time in ms
					;                      from start of track

.ADFS_FileCore_Private		DCD 0	;ADFS' private word
.FileCore_Notify_Background	DCD 0	;address to call after background transfer
.FileCore_Release_FIQ		DCD 0	;address to call to release floppy FIQ

.ADFS_FS_Create_Block
 DCD 0					;Filing system number etc
 DCD ADFS_Module			;Filing system title
 DCD ADFS_boot				;Boot text
 DCD Entry_DiscOp			;DiscOp entry
 DCD Entry_MiscOp			;Misc entry

.Format_Requested	DCD 0		;zero terminated format eg "F", 0
.Floppy_Title		DCD 0, 0, 0	;buffer for floppy title
.date_5byte_format	DCD 0, 0	;buffer for date result

.ADF_Buffer_Address	DCD 0		;address of disc data in memory
.ADF_Buffer_Length	DCD 0		;size of disc image

.tmp_Track		DCD 0		;temp buffer address
.tmp_Track_Length	DCD 0		;temp buffer length
.MFM_Stream_Pos		DCD 0		;current position within track
.File_Handle		DCD 0		;ZLib file handle
.tmp_Header		DCD 0		;buffer for APD header
.tmp_Header_Pos		DCD 0		;current position within APD header

.JFD_Tracks		DCD 0		;address of track info
.JFD_Sectors		DCD 0		;address of sector info
.JFD_TrackSector_size	DCD 0		;size of track and sector tables

.head_position		DCD 0		;pointer to sector head is currently on
.head_track		DCD -1		;current track head is on, reset to -1
					;..when the disc is changed

.MFM_crc		DCD 0		;FM/MFM CRC
.sec_sync_mark		DCD 0		;sector header sync mark
.bit_sync_mark		DCD 0		;bitstream sync mark
.SiS_syncmark		DCD 0		;lower byte of bit_sync_mark converted
						; from MFM / FM
.mfm5554		DCD 0		;xFM ID start
.mfm5545		DCD 0		;xFM normal data start

.recording_ptr		DCD 0		;offset of next entry in record buffer
.recording_addr		DCD 0		;address of recording buffer
.recordStack		DCD 0, 0, 0, 0, 0, -1
					;^^^ ;R1,R2,R4,[R5,#0],[R5,#DR_discsize]

.non_scatter_original	DCD 0, 0, 0	;used to return R2, R3, R4
					;  if a data or ID CRC occurs
.non_scatter_R3_return  DCD 0
			DCD 0, 0
.DiscOp_local_scatter	DCD 0, 0, -8, 0
.DiscOp_return_error	DCD 0
.os_byte_19_time	DCD 0

#if JIT_instruction_trace == 1
.our_IT_DA_number	DCD 0		;instruction trace DA number
.IT_DA_address		DCD 0		;instruction trace DA address
.instruction_trace_ptr	DCD 0		;address of the instruction trace
#endif

.ZIP_workspace		DCD 0		;pointer to RMA allocation

; ******* Joystick variables *********
			DCD 0		;Event_Joystick, must directly preceed Joystick_Keymapping
			;Jn RLDU B1 B2 B3 B4 B5 B6 B7 B8
			;        A  B  X  Y  LB RB Bk St
.Joystick_Keymapping	DBB Max_Joysticks*Joystick_Keys.size, &FF
.Joystick_Buttons	DBD Max_Joysticks
.Econet_Registers	DCD &F8, 0, 0, 0 ;Econet, %FUDLR, %UDLFR000
#if Max_Joysticks>3
  DBD Max_Joysticks-3
#endif
.screen_OS_units_X	DCD 0		;width of screen in OS units
.screen_OS_units_Y	DCD 0		;height of screen in OS units
.Joystick_Mousemapping	DBB Joystick_Mouse.size
.Joystick_DeadZones	DBD Max_Joysticks, Joystick_Percentage*25
.Joystick_DeadZonesSQ	DBD Max_Joysticks, (Joystick_Percentage*25)^2
; ************************************

.DiscOp_CPSR		DCD 0		;DiscOp's CPSR to exit with
.MiscOp_CPSR		DCD 0		;MiscOp's CPSR to exit with
.trap_aborts_in_Finalise	DCD 0	;R12 to restore if an error occurs during Module Finalise

#if compile_RO > 311
.VIDC3	DBB VIDC_Type3.size
	DCD -1			;terminator
#endif

.os_ADFS_MiscOp		DCD 0		;address of ADFS MiscOp entry
.os_ADFS_DiscOp		DCD 0		;address of ADFS DiscOp entry

.pass_to_os_ADFS_MiscOp	LDR     PC, os_ADFS_MiscOp
.pass_to_os_ADFS_DiscOp	LDR     PC, os_ADFS_DiscOp
