Konami SCC/SCC+ Programming
This page was last modified 11:07, 31 January 2022 by Gdx. Based on work by NYYRIKKI and Rderooy.

Contents

Links

Sample Programs

SCC Detection

Routine to detect the slot of the SCC in lower slot: (See SlotID)

SCCDETECT:
;----------------------------------------------------
; SCCDETECT (Made by : NYYRIKKI)
; Input: (None)
; Output:
;   Success:
;     CF = NC
;     A  = SlotID
;     B  = Number of untested slots
;     (SCC SLOT on #8000-#BFFF)
;
;   Fail:
;     CF = C
;     B  = 0
;     (Random slot on #8000-#BFFF)
; Changes: All registers
;----------------------------------------------------
 
        LD B,16
 
SCCDETECT_NEXT:
;-----------------------------------------------------
; Call this address if you need to detect another SCC
; Input: B = Value returned by SCCDETECT (must be >0)
;-----------------------------------------------------
 
	LD H,#FC
.SLOTLOOP
        DEC B
	LD A,B
	AND 3
	ADD A,#C1
	LD L,A
	LD A,(HL)
	AND 128
	OR B
	CP 12
	CALL NC,.TESTSLOT
	RET NC
        INC B
        DJNZ .SLOTLOOP
	RET
 
.TESTSLOT:
	 XOR 12
	 LD C,A
         PUSH BC
         PUSH HL
 
         LD H,#80
         CALL #24
 
         LD A,(#9000)
         LD D,A
         LD A,#3F
         LD (#9000),A
         LD HL,#9800
         LD E,(HL)
         XOR A
         LD (HL),A
         OR (HL)
         JR NZ,.NOSCC
         DEC A
         LD (HL),A
         LD A,(HL)
         INC A
         JR NZ,.NOSCC
         LD A,(#9000)
         XOR #3F
         JR NZ,.EXIT
.NOSCC
         LD (HL),E
         LD A,D
         LD (#9000),A
         SCF
.EXIT
         POP HL
         POP BC
	 LD A,C
         RET

Multi SCC Detection

; This routine can be used in any environement (ROM, MSX-DOS, BASIC).
; It make a table containing the slot number of the SCC cartridge inserted
; in the MSX cartridge slots.
; Slot numbers sre in the format F000SSPP.
; The table ends with 0 but it is easy to replace it by FFh.
 
SCCtbl:	equ	0C000h
 
 
SCCSRCH:
	ld	hl,SCCtbl
	call	SCCDetect
	ret
 
;------------------------------------------
; SCC detection routine by gdx
; Input: HL= Table for slots with SCC inserted
; Output: HL= Table of slots with SCC inserted (0 at table end)
; Changes: All registers
;------------------------------------------
 
SCCDetect:
	push	hl
	ld	de,0		; E = Primary slot
SCCDetectLp:
	ld	hl,EXPTBL
	add	hl,de
	ld	a,(hl)
	and	80h
	or	e		; Store primary slot number
	pop	hl
	call	ChkCurrentSlt	; Check the current primary slot (or secondary 0-0)
	push	hl
	bit	7,a
	jr	z,NoSecSlt	; Jump if primary slot
	ld	a,84h
	or	e
	pop	hl
	call	ChkCurrentSlt	; Check the current secondary slot 1
	push	hl
	ld	a,88h
	or	e
	pop	hl
	call	ChkCurrentSlt	; Check the current secondary slot 2
	push	hl
	ld	a,8Ch
	or	e
	pop	hl
	call	ChkCurrentSlt	; Check the current secondary slot 3
	push	hl
NoSecSlt:
	inc	e
	ld	a,4
	cp	e
	jp	nz,SCCDetectLp
 
	pop	hl
	ret
 
; Search the SCC on specified slot
; Input: A = Slot number, HL= Table
; Output: A = Slot number, Carry = 0 if not found
 
ChkCurrentSlt:
	push	hl
	push	de
	push	bc
	push	af
 
; Test if RAM at 08000h
 
	ld	hl,08000h
	call	RDSLT
	cpl			; Test with inverted bits
	ld	e,a
	ex	af,af'		; Store readed byte to A'
	pop	af		; A = current slot number
	push	af
	call	WRSLT		; 	
	pop	af		; A = current slot number
	push	af
	call	RDSLT
	cpl
	ld	e,a
	pop	af		; A = current slot number
	push	af
	call	WRSLT		; 	
	ex	af,af'		; Restore A
	cpl
	cp	e
	jr	z,SCCNotFnd	; Jump if RAM
 
	pop	af		; A = current slot number
	push	af
	ld	e,0h
	ld	hl,0BFFEh
	call	WRSLT		; Set ROM mode for all pages & SCC mode on the Sound Cartridge
 
	pop	af		; A = current slot number
	push	af
	ld	e,03Fh
	ld	hl,09000h
	call	WRSLT		; Enable the SCC registers
 
; Test if SCC register at 09800h
 
	ld	hl,09800h
 
	pop	af		; A = current slot number
	push	af
	call	RDSLT
	cpl			; Test with inverted bits
	ld	e,a
	ex	af,af'		; Store A
	pop	af		; A = current slot number
	push	af
	call	WRSLT
	pop	af		; A = current slot number
	push	af
	call	RDSLT
	ld	e,a
	ex	af,af'		; Restore A
	cp	e
	jr	nz,SCCNotFnd	; Jump if the read value is not the same
	cpl			; Test again with not inverted bits
	ld	e,a
	ex	af,af'		; Store A
	pop	af		; A = current slot number
	push	af
	call	WRSLT
	pop	af		; A = current slot number
	push	af
	call	RDSLT
	ld	e,a
	ex	af,af'		; Restore A
	cp	e
	jr	nz,SCCNotFnd	; Jump if the read value is not the same
 
; When the SCC is found
 
	pop	af
	pop	bc
	pop	de
	pop	hl
	ld	(hl),a		; Store the slot number in the table
	inc	hl
	push	af
	xor	a
	ld	(hl),a		; Write 0 to indicate the end of the table
	pop	af
	scf			; Carry = 1
	ret
 
; When the SCC is not found
 
SCCNotFnd:
	pop	af
	ex	af,af'
	pop	bc
	pop	de
	pop	hl
	xor	a
	ld	(hl),a		; Write 0 to indicate the end of the table
	ex	af,af'
	or	a		; Carry = 0
	ret

SCC+ Detection

Routine to detect SCC+ slot:

;------------------------------------------
; SCC+ detection routine by gdx
; Input: None
; Output: A = SCC Slot ID if found else 0
;	  F = Carry is 0 if SCC found else 1
;	  Page 8000h-BFFFh = First SCC+ found slot or random slot if SCC not found
; Changes: All registers
;------------------------------------------
 
SCCDetect:
	call	Slt_Num_conv
	ld	c,a		; C = Current slot number
	jr	nz,SltPrim	; Jump if not primary slot
	ld	a,3
	ld	(Sec_SLT),a	; Sec_SLT =3 if primary slot to skip secondary slots
SltPrim:
	ld	a,c
	call	CHK_SLT
	ld	a,c		; A = Current slot number
	ret	nc		; Back if SCC+ found
 
	ld	a,(Sec_SLT)
	inc	a
	and	3		; Sec_SLT = 0~3 only
	ld	(Sec_SLT),a
	jr	nz,SCCDetect	; Jump if Sec_SLT <> 0
 
	ld	a,(Prim_SLT)
	inc	a
	cp	4
	ld	(Prim_SLT),a
	jr	nz,SCCDetect	; Jump if all primary slots are not scanned
 
	xor	a
	scf
	ret
 
CHK_SLT:
	push	bc
 
	ld	h,080h
	call	ENASLT
 
	ld	a,020h
	ld	(0BFFEh),a	; Set ROM mode for all page & SCC+ mode
 
	ld	hl,0AFFFh
	ld	d,(hl)
	ld	a,d		; Store the value
	ld	(hl),a
	cp	d
	jr	nz,SCCpNotFnd	; Jump if the read value is not the same
	cpl
	ld	(hl),a
	ld	a,(hl)
	cp	d
	jr	nz,SCCpNotFnd	; Jump if the read value remains the same
 
	ld	hl,0B800h
	ld	e,(hl)
	ld	a,e		; Store the value
	cpl
	ld	(hl),a
	ld	a,(hl)
	jr	nz,SCCpNotFnd	; Jump if the read value remains the same
 
	ld	a,080h
	ld	(0B000h),a	; Enable the SCC+ registers
 
	ld	a,255
	ld	(hl),a
	ld	a,(hl)
	cp	255
	jr	nz,SCCpNotFnd	; Jump if the read value is not 255
	inc	a
	ld	(hl),a
	ld	a,(hl)
	or	a	
	jr	nz,SCCpNotFnd	; Jump if the read value is not 0
 
	xor	a
	jr	SCRCH_End
 
SCCpNotFnd:
	ld	a,d
	ld	(0AFFFh),a
	ld	(hl),e
	scf
SCRCH_End:
	pop	bc
	ret
 
; Convert Prim_SLT and Sec_SLT values to slot number format
; Entry: Prim_SLT, Sec_SLT
; Output: A = Slot number (FxxxPPSS)
; Modify: A, BC, HL
 
Slt_Num_conv:
	ld	a,(Prim_SLT)
	ld	c,a
	ld	b,0
	ld	hl,EXPTBL
	add	hl,bc
	ld	a,(hl)
	and	80h
	ld	a,c
	ret	z		; Back if primary slot
 
	ld	a,(Sec_SLT)
	rlca
	rlca
	or	c
	or	080h
	ret
 
Prim_SLT:
	db	0	; Current primary slot number
Sec_SLT:
	db	1	; Current secondary slot number

Note: Routine not optimized.