Musical memory mapper - byte to SN76489AN

Página 1/2
| 2

Por NYYRIKKI

Enlighted (6091)

Imagen del NYYRIKKI

01-04-2023, 21:00

Can someone please help me and show me a working routine that writes a byte to SN76489AN in Musical Memory Mapper ???

I've been playing with openMSX for hours and hours and I just can't do it... I've tried to write all kinds of combinations to I/O ports #3C and #3F as well as memory address #403C in MMM slot, but only way I can write the registers is to open debugger and manipulate the registers from there... from MSX side I can't get access.

The MMM manual does not explain what way each of the bits work, but I'm starting to think there must be something else I'm missing here... This problem just seems too difficult for me to solve on my own. :(

Login sesión o register para postear comentarios

Por NYYRIKKI

Enlighted (6091)

Imagen del NYYRIKKI

01-04-2023, 23:08

Ok, I'm starting to think this is openMSX problem... If I ie. write #80 to I/O port #3C my Mapper RAM gets corrupted from addresses like #80FC-#80FF and #803C & #813C... Seems that I/O writes and memory writes are somehow messed up and I highly doubt this happens if I get to try on real MSX.

Shit... I feel, I used way, way too many hours trying to solve a problem that most likely does not even exists!
Evil

Por Grauw

Ascended (10820)

Imagen del Grauw

01-04-2023, 23:42

It works fine with VGMPlay. Here’s the enable function that I do before accessing the I/O. Iirc:

1. Disable interrupts to prevent access to the mapper temporarily (e.g. interrupts).
2. Write 80H to I/O port 3CH. Memory-mapped I/O (R/W) is now enabled.
3. Write C0H to memory mapped I/O 803CH. SN76489AN is now enabled on I/O 3FH.
4. Write 00H to I/O port 3CH. Memory-mapped I/O is now disabled.
5. Enable interrupts.

And when it’s done playing I do the same but write 80H to 803CH to disable the SN76489AN port.

You can only access the SN76489AN through the 3FH I/O port btw. Writing to 803FH doesn’t work, supposedly because the memory-mapped I/O timing is too tight for the DCSG.

Por Manuel

Ascended (19678)

Imagen del Manuel

01-04-2023, 23:37

NYYRIKKI - for reference, which openMSX version are you using?

Por gdx

Enlighted (6429)

Imagen del gdx

02-04-2023, 00:42

I use the MMM detection routine from the manual for ROM2MMM. It works fine.

	ld	H,080h
	call	MMM_Srch	; MMM detection
	.
	.
	.
; Musical Memory Mapper detection

MMM_Srch:
	ld	l,0FFh
	ld	b,16

MMM_Srch_Loop:
	push	hl

	ld	a,b
	dec	a
	and	3

	ld	hl,EXPTBL
	add	a,l
	ld	l,a

	ld	a,b
	dec	a
	or	(hl)

	pop    hl

	jp	m,Sec_SLT	; Jump if secondary Slot

	and	%00001111
	cp	4
	jr	nc,NextMMM_Srch ; Jump if 3-3 Slot

Sec_SLT:
	ld	c,a

	push	bc
	push	hl
	call	ENASLT		; Slot to search
	pop	hl
	pop	bc

	di

	ld	a,080h
	out	(03Ch),a	; Enable acces to registers by memory address mode

	ld	a,(hl)
	and	%00011111
	inc	a

	out	(0FFh),a

	or	%11000000
	cp	(hl)		; Same value?

	ld	a,0
	out	(03Ch),a
	out	(0FFh),a	; Restore initial mapper page on bank 0C000H~0FFFFH 

	ei

	ld	a,c		; A = Found Slot Number (F000SSPP)
	jr	z,MMM_Found

NextMMM_Srch:
	djnz	MMM_Srch_Loop	; Jump if MMM is not found

	ld	a,0FFh		; MMM not found value
	ret

MMM_Found:
	dec	b
	ret

Por NYYRIKKI

Enlighted (6091)

Imagen del NYYRIKKI

02-04-2023, 00:58

Thanks Grauw! I thought that I tested this but the RAM corruption might have messed up my routine. I think that I just understood a bit wrong how the I/O port #3C works.

Manuel wrote:

NYYRIKKI - for reference, which openMSX version are you using?

I'm runnning 18.0 ATM.

Por NYYRIKKI

Enlighted (6091)

Imagen del NYYRIKKI

02-04-2023, 01:24

Yes, that was my problem...

First I checked that SN76489AN is on I/O #3F -> Does not work
Then I checked from wiki that I need to enable #3F by using I/O #3C -> Does not work
Then I read that I need to write memory config register to enable #3C & #3F -> Does not work
... I did not read the memory mapper detection carefully as I was not interested about detecting memory mapper but enabling SN76489AN... So practically I just did everything in wrong order from the start... It is very hard to get it right way on the head when you get fixed to the wrong idea.
Have to try the right way tomorrow, thanks all!

Por NYYRIKKI

Enlighted (6091)

Imagen del NYYRIKKI

02-04-2023, 12:38

Yes, now all is ok...

I wanted to play in BASIC, so I came up with this:

1 D$="013C1026FC0578E603C6C16F7EE680B0FE0C382D21FD40C5CD2400C1F33E80ED797EE61F3CD3FDF6C0BE20156936C03E9FD33F3EBFD33F3EDFD33F3EFFD33F0600AFFBD33C0410BB3E02D3FD3AC1FCC32400"
2 FOR I=1TO82:A$=A$+CHR$(VAL("&H"+MID$(D$,I*2-1,2))):NEXTI
3 A=VARPTR(A$):POKE&HF39A,PEEK(A+1):POKE &HF39B,PEEK(A+2):A=USR(0)

(same code as BIN-file)

         OUTPUT "SNINIT.BIN"

         DB #FE
         DW BEGIN,END,BEGIN

         ORG #C000
BEGIN

         LD BC,#103C

.SLOTLOOP
	 LD H,#FC
         DEC B
	 LD A,B
	 AND 3
	 ADD A,#C1
	 LD L,A
	 LD A,(HL)
	 AND 128
	 OR B
	 CP 12
	 JR C,.NEXTSLOT

         LD HL,#40FD
         PUSH BC
         CALL #24
         POP BC

         DI
         LD A,#80
         OUT (C),A
         LD A,(HL)
         AND 31
         INC A
         OUT (#FD),A
         OR #C0
         CP (HL)

	 JR NZ,.NEXTSLOT
         LD L,C
         LD (HL),#C0 ; Enable SN76489AN

         ; Mute all channels

         LD A,#9F
         OUT (#3F),A ; channel 1
         LD A,#BF
         OUT (#3F),A ; channel 2
         LD A,#DF
         OUT (#3F),A ; channel 3
         LD A,#FF
         OUT (#3F),A ; channel 4

	 LD B,0

.NEXTSLOT
         XOR A
         EI
         OUT (#3C),A
         INC B
         DJNZ .SLOTLOOP
	 LD A,2
	 OUT (#FD),A
         LD A,(#FCC1)
         JP #24

END:

Por NYYRIKKI

Enlighted (6091)

Imagen del NYYRIKKI

03-04-2023, 02:01

Oh well... I thought I got it right as it worked fine on openMSX, but failed miserably on real hardware... It seems I still did not quite understand, how the Page 1/2 switching works... I now found that it is explained in manual, but the explanation mostly makes my head just spin. The thing is that if I want to use the registers from Page 1, I first need to write control byte to Page 2 in order to move the control to page 1, but I still did not quite get all the fine print details sorted out in my head as this seems to be quite a puzzle with bits flipping together and bits with double meaning that can switch between things A and B in some case if the bit is 0 or 1... or maybe if is 1 or 0, who knows. This must be the most complex sound hardware out there to get initialized at least if I count how many times I've already managed to get it wrong. Smile

I'll update the routines soon, but I got yet another reminder of this old wisdom: Always test on real hardware.

Por gdx

Enlighted (6429)

Imagen del gdx

03-04-2023, 03:12

You only have to understand that bit 7 of the port #3Ch enables the 803Ch address to access the MMM register.
When 803Ch is enabled you can enable the SN76489AN and control the MMM mapper regardless of the standard Memory Mapper via this address. You can even write protect mapper pages each independently. It's simple once you understand the principle.

Por NYYRIKKI

Enlighted (6091)

Imagen del NYYRIKKI

03-04-2023, 11:41

gdx wrote:

You only have to understand that bit 7 of the port #3Ch enables the 803Ch address to access the MMM register.
When 803Ch is enabled you can enable the SN76489AN and control the MMM mapper regardless of the standard Memory Mapper via this address. You can even write protect mapper pages each independently. It's simple once you understand the principle.

Yes, that part I now understand and that is enough for my case, but rest of the stuff I really don't quite get... I think there could be quite a bit better explanation of how the bits actually work and affect things as then it could be emulated better as well.

Página 1/2
| 2