;
; Sega 32X MC68000-visible register definitions and helper macros
;

.DEFINE REG_32X_ADAPTER_CTRL    $A15100
.DEFINE REG_32X_SH2_INT         $A15102
.DEFINE REG_32X_BANK_SET        $A15104
.DEFINE REG_32X_DREQ_CTRL       $A15106
.DEFINE REG_32X_DREQ_STATUS     $A15107
.DEFINE REG_32X_DMA_SRC         $A15108
.DEFINE REG_32X_DMA_DST         $A1510C
.DEFINE REG_32X_DMA_LEN         $A15110
.DEFINE REG_32X_DMA_FIFO        $A15112

.DEFINE REG_32X_COMM0           $A15120
.DEFINE REG_32X_COMM2           $A15122
.DEFINE REG_32X_COMM4           $A15124
.DEFINE REG_32X_COMM6           $A15126
.DEFINE REG_32X_COMM8           $A15128
.DEFINE REG_32X_COMM10          $A1512A
.DEFINE REG_32X_COMM12          $A1512C
.DEFINE REG_32X_COMM14          $A1512E

.DEFINE REG_32X_PWM_CTRL        $A15130
.DEFINE REG_32X_PWM_CYCLE       $A15132
.DEFINE REG_32X_PWM_LEFT        $A15134
.DEFINE REG_32X_PWM_RIGHT       $A15136
.DEFINE REG_32X_PWM_MONO        $A15138

.DEFINE REG_32X_VDP_MODE        $A15180
.DEFINE REG_32X_VDP_FILL_LEN    $A15184
.DEFINE REG_32X_VDP_FILL_START  $A15186
.DEFINE REG_32X_VDP_FILL_DATA   $A15188
.DEFINE REG_32X_VDP_FB_CTRL     $A1518A
.DEFINE REG_32X_PALETTE         $A15200
.DEFINE REG_32X_FRAMEBUFFER     $840000
.DEFINE REG_32X_OVERWRITE_IMG   $860000

.DEFINE MARS_ADAPTER_ENABLE       $0001
.DEFINE MARS_SH2_RESET_RELEASE    $0002
.DEFINE MARS_FM_ACCESS            $8000

.DEFINE MARS_CMD_INT_MASTER       $0001
.DEFINE MARS_CMD_INT_SLAVE        $0002
.DEFINE MARS_CMD_INT_BOTH         $0003

.DEFINE MARS_DREQ_RV              $01
.DEFINE MARS_DREQ_68S             $04

.DEFINE MARS_PWM_CTRL_MONO        $0100
.DEFINE MARS_PWM_CTRL_LEFT        $0200
.DEFINE MARS_PWM_CTRL_RIGHT       $0400
.DEFINE MARS_PWM_CTRL_ENABLE      $0001
.DEFINE MARS_PWM_LCH_LEFT         $0001
.DEFINE MARS_PWM_LCH_RIGHT        $0002
.DEFINE MARS_PWM_RCH_RIGHT        $0004
.DEFINE MARS_PWM_RCH_LEFT         $0008
.DEFINE MARS_PWM_TIMER_1          $0100
.DEFINE MARS_PWM_CTRL_STEREO      (MARS_PWM_TIMER_1 | MARS_PWM_LCH_LEFT | MARS_PWM_RCH_RIGHT)

.DEFINE MARS_VDP_MODE_OFF         $0000
.DEFINE MARS_VDP_MODE_256         $0001
.DEFINE MARS_VDP_MODE_32K         $0002
.DEFINE MARS_VDP_MODE_RLE         $0003
.DEFINE MARS_VDP_PRIO_32X         $0080
.DEFINE MARS_VDP_PRIO_68K         $0000

.MACRO MARS_68K_ENABLE_ADAPTER
  move.w #(MARS_ADAPTER_ENABLE | MARS_SH2_RESET_RELEASE), REG_32X_ADAPTER_CTRL
.ENDM

.MACRO MARS_68K_BOOT_TO_HOTSTART ARGS HOT_ADDRESS
  move.w #$2700, sr
  move.l #HOT_ADDRESS, a0
  move.w #(MARS_ADAPTER_ENABLE | MARS_SH2_RESET_RELEASE), REG_32X_ADAPTER_CTRL
  nop
  nop
  jmp (a0)
.ENDM

.MACRO MARS_68K_SET_FM
  move.w REG_32X_ADAPTER_CTRL, d0
  ori.w #MARS_FM_ACCESS, d0
  move.w d0, REG_32X_ADAPTER_CTRL
.ENDM

.MACRO MARS_68K_CLEAR_FM
  move.w REG_32X_ADAPTER_CTRL, d0
  andi.w #$7FFF, d0
  move.w d0, REG_32X_ADAPTER_CTRL
.ENDM

.MACRO MARS_68K_CMD_INT_BOTH
  move.w #MARS_CMD_INT_BOTH, REG_32X_SH2_INT
.ENDM

.MACRO MARS_68K_SET_RV
  bset #0, REG_32X_DREQ_STATUS
.ENDM

.MACRO MARS_68K_CLEAR_RV
  bclr #0, REG_32X_DREQ_STATUS
.ENDM