
BankSwapper_INIT:
	in a,(&A8)
	ld (SlotRestoreA),a
	ld a,(&FFFF)	
	cpl
	ld (SlotRestoreB),a
	ret


SlotRestoreA: db 0
SlotRestoreB: db 0

BankSwapper_SetCartBank:	;Bank 3 is the first of our program's banks (0-2 are ROM)
	ld (&5000),a
	inc a
	ld (&7000),a
	ret



BankTest:
; H=Page
; L=Slot
; D=subslot
	di
	;Check the slot expansion vars FCC1H-FCC4H - bit 7 is set if expanded
	ld b,&FC
	ld a,&C1
	add l
	ld c,a
	ld a,(bc)
	bit 7,a
	jr z,SlotNotExpanded

	;PageIn the subslot selection register &FFFF 
	ld b,L;3;	Load B with 3
	ld c,3;	Load C with Slot
	call GetSlotMask

	ld a,(SlotRestoreA)
	and B
	or c
	out (&A8),a

	;Set the subslot selection register &FFFF 
	ld b,H;1;	Load B with Page
	ld c,D;2;	Load C with Subslot
	call GetSlotMask
	ld a,(&FFFF)
	cpl
	and B
	or c
;	and %11110011
;	or  %00001100
	ld (&FFFF),a

	;Page in the bank we want
SlotNotExpanded:
	ld a,(SlotRestoreA)
	ld b,H;1;	Load B with Page
	ld c,L;3;	Load C with Slot
	call GetSlotMask
	and B
	or c
;	and %11110011
;	or  %00001100
	out (&A8),a

	ret

GetSlotMask:
	;Set
	;	Load B with Page
	;	Load C with Bank
	;Returns
		;Load B with Mask
		;Load C with Bank
	push af
		ld a,%11111100
		GetSlotMaskB:
		rlc c
		rlca
		rlc c
		rlca
		djnz GetSlotMaskB
		ld b,a
	pop af
	ret
Memtest:
		ld a,(hl)
		ld b,a
		ld (hl),0
		cp (hl)
		ld a,0
		ret z
		ld (hl),b
		inc a
	ret


		