; File: Stella.i
; Author: Neil Cafferkey
; ======================
; These are replacements for instructions that access the Stella television
; interface adapter. They call the appropriate function in
; atari2600.library.
;
; $VER: Stella.i 2.1 (6.9.99)
;

	ifnd	stella_i
stella_i	set	1

	include	"asm_support.i"



; Macro: _ZPI_STELLA
; ==================
;

	macro	_ZPI_STELLA

	addq.l	#4,CLOCK

	move.l	#\1,d1
	add.b	\2,d1

	btst.b	#7,d1
	bne	\@ram$

	mulu.w	#LIB_VECTSIZE,d1

	movea.l	a6,a0
	adda.l	#LIB_USERDEF,a0
	suba.l	d1,a0

	move.l	\3,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1

	jsr	(a0)

	bra	\@skip_ram$

\@ram$:

	move.b	\3,(DATA,d1)

\@skip_ram$:

	endm


; Macro: _ABI_STELLA
; ==================
;

	macro	_ABI_STELLA

	addq.l	#5,CLOCK

	_ABI	\1,\2

	move.l	d1,d0
	andi.l	#$ffffff80,d0

	eor.l	#$80,d0
	beq.s	\@ram$

;	bne	\@ram$

	mulu.w	#LIB_VECTSIZE,d1

	movea.l	a6,a0
	adda.l	#LIB_USERDEF,a0
	suba.l	d1,a0

	move.l	\3,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1

	jsr	(a0)

	bra	\@skip_ram$

\@ram$:

	move.b	\3,(DATA,d1)

\@skip_ram$:

	endm


; Macro: STA_ZPI_STELLA
; =====================
;

	macro	STA_ZPI_STELLA

	_ZPI_STELLA	\1,\2,A

	endm


; Macro: STA_ABI_STELLA
; =====================
;

	macro	STA_ABI_STELLA

	_ABI_STELLA	\1,\2,A

	endm


; Macro: STX_ZPI_STELLA
; =====================
;

	macro	STX_ZPI_STELLA

	_ZPI_STELLA	\1,\2,X

	endm


; Macro: STY_ZPI_STELLA
; =====================
;

	macro	STY_ZPI_STELLA

	_ZPI_STELLA	\1,\2,Y

	endm


; Write addresses

; Macro: VSYNC
; ============
;

	macro	VSYNC

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	movea.l	ENV,a1
	move.b	\1,d0
	move.l	CLOCK,d1
	CALLSYS	A2600_VSync

	endm


; Macro: VBLANK
; =============
;

	macro	VBLANK

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	movea.l	ENV,a1
	move.b	\1,d0
	move.l	CLOCK,d1
	CALLSYS	A2600_VBlank

	endm


; Macro: WSYNC
; ============
;

	macro	WSYNC

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_WSync

	endm


; Macro: RSYNC
; ============
;

;	macro	RSYNC
;	endm


; Macro: NUSIZ0
; =============
;

	macro	NUSIZ0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_NuSiz0

	endm


; Macro: NUSIZ1
; =============
;

	macro	NUSIZ1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_NuSiz1

	endm


; Macro: COLUP0
; =============
;

	macro	COLUP0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_CoLuP0

	endm


; Macro: COLUP1
; =============
;

	macro	COLUP1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_CoLuP1

	endm


; Macro: COLUPF
; =============
;

	macro	COLUPF

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_CoLuPF

	endm


; Macro: COLUBK
; =============
;

	macro	COLUBK

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_CoLuBk

	endm


; Macro: CTRLPF
; =============
;

	macro	CTRLPF

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_CtrlPF

	endm


; Macro: REFP0
; ============
;

	macro	REFP0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_RefP0

	endm


; Macro: REFP1
; ============
;

	macro	REFP1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_RefP1

	endm


; Macro: PF0
; ==========
;

	macro	PF0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_PF0

	endm


; Macro: PF1
; ==========
;

	macro	PF1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_PF1

	endm


; Macro: PF2
; ==========
;

	macro	PF2

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_PF2

	endm


; Macro: RESP0
; ============
;

	macro	RESP0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_ResP0

	endm


; Macro: RESP1
; ============
;

	macro	RESP1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_ResP1

	endm


; Macro: RESM0
; ============
;

	macro	RESM0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_ResM0

	endm


; Macro: RESM1
; ============
;

	macro	RESM1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_ResM1

	endm


; Macro: RESBL
; ============
;

	macro	RESBL

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_ResBl

	endm


; Macro: AUDC0
; ============
;

	macro	AUDC0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_AudC0

	endm


; Macro: AUDC1
; ============
;

	macro	AUDC1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_AudC1

	endm


; Macro: AUDF0
; ============
;

	macro	AUDF0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_AudF0

	endm


; Macro: AUDF1
; ============
;

	macro	AUDF1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_AudF1

	endm


; Macro: AUDV0
; ============
;

	macro	AUDV0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_AudV0

	endm


; Macro: AUDV1
; ============
;

	macro	AUDV1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_AudV1

	endm


; Macro: GRP0
; ===========
;

	macro	GRP0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_GrP0

	endm


; Macro: GRP1
; ===========
;

	macro	GRP1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_GrP1

	endm


; Macro: ENAM0
; ============
;

	macro	ENAM0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_EnaM0

	endm


; Macro: ENAM1
; ============
;

	macro	ENAM1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_EnaM1

	endm


; Macro: ENABL
; ============
;

	macro	ENABL

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_EnaBl

	endm


; Macro: HMP0
; ===========
;

	macro	HMP0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	movea.l	ENV,a1
	CALLSYS	A2600_HMP0

	endm


; Macro: HMP1
; ===========
;

	macro	HMP1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	movea.l	ENV,a1
	CALLSYS	A2600_HMP1

	endm


; Macro: HMM0
; ===========
;

	macro	HMM0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	movea.l	ENV,a1
	CALLSYS	A2600_HMM0

	endm


; Macro: HMM1
; ===========
;

	macro	HMM1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	movea.l	ENV,a1
	CALLSYS	A2600_HMM1

	endm


; Macro: HMBL
; ===========
;

	macro	HMBL

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	movea.l	ENV,a1
	CALLSYS	A2600_HMBl

	endm


; Macro: VDELP0
; =============
;

	macro	VDELP0

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_VDelP0

	endm


; Macro: VDELP1
; =============
;

	macro	VDELP1

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_VDelP1

	endm


; Macro: VDELBL
; =============
;

	macro	VDELBL

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_VDelBl

	endm


; Macro: RESMP0
; =============
;

	macro	RESMP0

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_ResMP0

	endm


; Macro: RESMP1
; =============
;

	macro	RESMP1

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	\1,d0
	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_ResMP1

	endm


; Macro: HMOVE
; ============
;

	macro	HMOVE

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	move.l	CLOCK,d1
	movea.l	ENV,a1
	CALLSYS	A2600_HMove

	endm


; Macro: HMCLR
; ============
;

	macro	HMCLR

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	movea.l	ENV,a1
	CALLSYS	A2600_HMClr

	endm


; Macro: CXCLR
; ============
;

	macro	CXCLR

	; Update clock cycle counter

	addq.l	#\2,CLOCK

	; Call library function corresponding to this macro

	movea.l	ENV,a1
	CALLSYS	A2600_CxClr

	endm


	endc

