Imagen

FM77AV - learning how to program it (english thread)

Avatar de Usuario
pser1
Mensajes: 4893
Registrado: 08 Dic 2012 18:34

Re: FM77AV - learning how to program it (english thread)

Mensaje por pser1 »

@malikto999
let me add a few more questions to the list shown in my previous post ...

8) What does this code do?

Código: Seleccionar todo

Z7FB4   LDA     MFD1B      ; get a byte from FDC
        COMA               ; complement value (255-value)
        STA     MFD1B      ; send to FDC
9) In the Subsystem code, there are some unknown (to me) addresses like
$D410, $D412, $D41B, $D41D all of them used in MD566 and MD5E6
Seem related to tile painting. I said the very first time I played that game that the screens were made of tiles ...

10) MD566 cleans Blue plane both pages, whilst MD5E6 does it only on page 0
Is it possible that enabling Tile Painting, the subsystem will copy for free the values we send to the Blue plane to the other two planes (R-G)?
Apparently it doesn't make sense to clean only plane B ...
Is there any doc with info about the logic funtions that may be called using register $D410? Specially the Tile Painting ...
cheers
pere
Avatar de Usuario
pser1
Mensajes: 4893
Registrado: 08 Dic 2012 18:34

Re: FM77AV - learning how to program it (english thread)

Mensaje por pser1 »

Hello,
after adding the clock cycles to the parts that I have been verifying and were just creating delays, I am updating here
the source code (v2.1 due to changes done) so that any of you could have a peek and/or work on it and update then the doc back here
to share our works ...
It would be good to add a kind of tag or label to identify the changes you make to the source code
For instance *** PSR20231108 or any other coding that allows us to tell who has changed the code and when it was done ...
thanks beforehand
pere
Code03-v2.1.zip
(233.86 KiB) Descargado 32 veces
Avatar de Usuario
jimbobaby
Mensajes: 552
Registrado: 13 Ago 2023 21:17

Re: FM77AV - learning how to program it (english thread)

Mensaje por jimbobaby »

pser1 escribió: 2) What is this code useful for?

Código: Seleccionar todo

; -------------------------------------------------------------------
; BLK 51 - Interrupt Service Routine, set in BLK 01	ZZZZZ
; asociated to $FFF6/7 addresses
; -------------------------------------------------------------------
M776D   ANDCC   #$EF                   ; disable IRQ			
        PSHS    A                      ; save register value		
Z7771   LDA     SUBIF                  ; get SUB interface ($FD04)		
        BITA    #$02                   ; check bit 1 (BRK)		
        BEQ     Z7771                  ; if zero (enabled) loopback
Z7778   LDA     SUBIF                  ; get SUB interface ($FD04)		
        BITA    #$02                   ; check bit 1 (BRK)		
        BNE     Z7778                  ; if disabled, loopback		
Z777F   LDA     SUBIF                  ; get SUB interface ($FD04)		
        BITA    #$02                   ; check bit 1 (BRK)		
        BEQ     Z777F                  ; if zero (enabled) loopback
        PULS    A                      ; restore register		
        RTI                            ; return			
; -------------------------------------------------------------------
AFAIK Its the BREAK key signal, generated by the keyboard microcontroller. I suppose that the signal is send to both, SUB and Main, and it must be some way to sync with SUB to not generate duplicated calls. BTW, don't quote me on that -grin
pser1 escribió: 3) Addresses $FDEA and $FDEB, what are these ones (maybe YM2203)? Both are used in code for the Subsystem
For SUB space, it's whatever routine is in rom (and it seems to change it for another subsystem rom). On main cpu space, it would be MIDI port... non sense.
pser1 escribió: 4) $FD15 and $FD16 (maybe FM related)
Yes, it's the sound generator (PSG, AY-3-8913 compatible). I use $FD0D/$FD0E for sound. for testing, i have changed "mine" for "yours", and it seems to sound the same -shock . Apparently mine are "shared", but i don't know with who... (SUB can't use any of those, AFAIK)
pser1 escribió: 5) $FD37 related to Multipage ...
Yes. In multipage you could then pick which "color plane" (RGB) is visible, and which is "read only" - not writable-. But it's not easy... as VRAM is divided by individual bitplanes, on two "pages" for full 96kb usage, then on mode B, the R, G or B are for groups of bitplanes. So, in mode B, you can hide 4 bitplanes (of 8kb each) at once, but not individually.

Speaking of which... i was of the asumption that on mode B there is only one "display" page, that has 12 8k bitplanes (320x200 monocrome each), 6 on each active page. So, in reality, you don't have more than 2 full scanlines off screen, as all 12 bitplanes are visible at once.

But in this game, the scrolling intro is using the scroll register (on both active pages at the same time), to show a bitmap as if bitplanes where 16kb (320x400). As logic says, it stops on 8k offset (after 200 lines of witdth 320).

That's possible to do it on mode A or C if you "downgrade" it to 320, but then you only have 8 colors (3 bitplanes). You could do all palette remap tricks you want, but "in hardware" i was of the assumption that either 8 colors (3 bitplanes mode A/C) or 4096 (12 bitplanes mode B).

So it seems the game is using 96kb in 6 bitplanes of 16kb each, and i don't know how is that possible -banghead (baring XM7 issues, but i doubt it). The secret is obviously on the code, so it's a matter of time -grin
pser1 escribió: 6) $FD00 related to Key Clock, what does it return when read?
Bit 0 should indicate 1.2Mhz (0, compatibility with FM-8) or 2Mhz (1). It's only for reading the current dipswitch setting of the machine.
pser1 escribió: 7) the area $FFE0-$FFE5 seems FDC values, but the game uses $FFE8 too as last drive used. Is that correct?
On main space? That's "pointers to ISR" zone, i think. FDC should be $FD18-$FD1F, i think. On sub it's rom.
-sp3zy PC 386 -coam1 -m3s3x
Avatar de Usuario
jimbobaby
Mensajes: 552
Registrado: 13 Ago 2023 21:17

Re: FM77AV - learning how to program it (english thread)

Mensaje por jimbobaby »

pser1 escribió: 9) In the Subsystem code, there are some unknown (to me) addresses like
$D410, $D412, $D41B, $D41D all of them used in MD566 and MD5E6
Seem related to tile painting. I said the very first time I played that game that the screens were made of tiles ...
We have the docs that Malikto999 has send to us here http://retrowiki.es/viewtopic.php?f=33& ... p200175823

At least for a little start.
-sp3zy PC 386 -coam1 -m3s3x
Avatar de Usuario
pser1
Mensajes: 4893
Registrado: 08 Dic 2012 18:34

Re: FM77AV - learning how to program it (english thread)

Mensaje por pser1 »

jimbobaby escribió:
pser1 escribió: 9) In the Subsystem code, there are some unknown (to me) addresses like
$D410, $D412, $D41B, $D41D all of them used in MD566 and MD5E6
Seem related to tile painting. I said the very first time I played that game that the screens were made of tiles ...
We have the docs that Malikto999 has send to us here http://retrowiki.es/viewtopic.php?f=33& ... p200175823
At least for a little start.
you are right! I had forgotten about that info :-(
Anyway, even reading the translated text I cannot spot how the system would behave ...
The special function "Tile Painting" needs some extra explanation to understand what these two Code Blocks actually do.
The number of affected planes is uncertain to me and same about what would be painted in planes R-G when we send bytes ($00 value)
to plane Blue ... -banghead
cheers!
pere
malikto999
Mensajes: 162
Registrado: 09 Jun 2017 11:20

Re: FM77AV - learning how to program it (english thread)

Mensaje por malikto999 »

For now, I will only answer questions that are immediately obvious.
pser1 escribió: 1) What interrupts have a 'hook' at $FFFx ? $FFF6 and $FFF8 are being used in the game
The FM-7 interrupt vector address is as follows.
$FFF0-$FFF1:UNUSED
$FFF2-$FFF3:SWI3
$FFF4-$FFF5:SWI2
$FFF6-$FFF7:FIRQ
$FFF8-$FFF9:IRQ
$FFFA-$FFFB:SWI
$FFFC-$FFFD:NMI
$FFFE-$FFFF:RESET
pser1 escribió: 2) What is this code useful for?
Is this the code for the FIRQ interrupt?
In-game, press the BREAK key to PAUSE. (It will loop until you release the BREAK key and press it again.)
pser1 escribió: 3) Addresses $FDEA and $FDEB, what are these ones (maybe YM2203)? Both are used in code for the Subsystem
As jimbobaby said, this is MIDI port I/O. I've heard that this game supports various options as a hidden feature, so it probably supports MIDI.
It also seems to be compatible with an optional speech synthesis card. This I/O is $FD35.
pser1 escribió: 7) the area $FFE0-$FFE5 seems FDC values, but the game uses $FFE8 too as last drive used. Is that correct?
Yes, that's right.
Avatar de Usuario
pser1
Mensajes: 4893
Registrado: 08 Dic 2012 18:34

Re: FM77AV - learning how to program it (english thread)

Mensaje por pser1 »

Hello,
thanks a lot for your answers ...
Anyway, the addresses $FDEA and $FDEB cannot be MIDI because the YM2203 doesn't have any MIDI port.
Looking at the chip dataset, I have found this
YM2203.jpg
YM2203.jpg (27.03 KiB) Visto 951 veces
It seems to accept up to four addresses, but I am not sure how these pins are connected /used in the FM77AV schematics
But as we can see, it is possible to send /write data right to these registers, but there is nothing like a MIDI there ...

Concerning the code related to the Break Key, it is the Interrupt Service for the FIRQ. So I asume that pressing the Break Key
forces the SUB CPU to create a FIRQ to the main CPU ...

jimbobaby says that he uses $FD0D-$FD0E for sound, but the program uses $FD15-$FD16. As the YM2203 can generate three FM outputs
like the AY-3-8913 does, maybe each pair of addresses is connected to one of the chips and while we send the same values to
the same registers, both act the same and make a very similar sound ... just thinking out loud!
cheers!
pere
Avatar de Usuario
pser1
Mensajes: 4893
Registrado: 08 Dic 2012 18:34

Re: FM77AV - learning how to program it (english thread)

Mensaje por pser1 »

concerning the YM2203, it has two parallel ports like the AY-3-8910, maybe they are used via $FDEA and $FDEB (?)
But in any case they are not MIDI. MIDI is a serial port that requires a UART, not a parallel one!!
8BitPorts.jpg
8BitPorts.jpg (5.8 KiB) Visto 949 veces
cheers!
pere
Avatar de Usuario
pser1
Mensajes: 4893
Registrado: 08 Dic 2012 18:34

Re: FM77AV - learning how to program it (english thread)

Mensaje por pser1 »

Hello,
The music player (ChipTunes) I have converted from the CoCo to the Dragon allows working wiht some chips, among them
The AY-3-8910, YM2149 and YM2203
For them all, no exceptions, the program reads two bytes from the VGM source file (Video Games Music) and sends them
the first to a port in order to select the requested register number and then the value we want for that register to the other port.
Much to my surprise the FM77AV seems to have a defined protocol to deal with the AY chip and the YM2203 they name FM
First of all the programmer *must* select the register to work with. That's accomplished doing :
- for the AY-3 chip the register number must be sent to $FD0E and then $03 and $00 must be sent in sequence to $FD0D
Once this step has been done, we can either read the current value or write a new value in it
-- To write we send the new value to $FD0E and then we must send $02 and $00 in sequence to $FD0D
-- To read the current value in the register we must send $01 to $FD0D, then we read the value from $FD0E and finally we send $00 to $FD0D
- for the YM2203 we must do the very same procedure but changing the port numbers:
-- $FD16 must be used instead of $FD0E and $FD15 must be used instead of $FD0D

I asume that the music chips are been managed by the subsystem, so the ROM code that deals with this functions expects these
different sequences for each one

That said, this only tells us how to use the FM part of the YM2203. That chip has also two parallel ports each 8 bits that can be
input or output upon configuration (I don't know what is their default behaviour ...)
The game we are working on has functions ("Z8BAD", "Z8BB7") that use addresses $FDEA-$FDEB that would write or read respectively
a byte from somewhere (maybe these ports)
More suspicious is that the code block "Z75E1" reads from register $0E, this one according to the chip datasheet is an 8 bit parallel port
so the program would be able to work with some add-on that can be attached to one of these ports. I don't know how difficult it
would be to insert a card there ... if it were possible, of course
cheers!
pere
Avatar de Usuario
jimbobaby
Mensajes: 552
Registrado: 13 Ago 2023 21:17

Re: FM77AV - learning how to program it (english thread)

Mensaje por jimbobaby »

pser1 escribió: Much to my surprise the FM77AV seems to have a defined protocol to deal with the AY chip and the YM2203 they name FM
First of all the programmer *must* select the register to work with. That's accomplished doing :
- for the AY-3 chip the register number must be sent to $FD0E and then $03 and $00 must be sent in sequence to $FD0D
Once this step has been done, we can either read the current value or write a new value in it
-- To write we send the new value to $FD0E and then we must send $02 and $00 in sequence to $FD0D
-- To read the current value in the register we must send $01 to $FD0D, then we read the value from $FD0E and finally we send $00 to $FD0D
- for the YM2203 we must do the very same procedure but changing the port numbers:
-- $FD16 must be used instead of $FD0E and $FD15 must be used instead of $FD0D
Ok, confession time -grin

Over a month ago, reading older posts, i stumbled on this http://retrowiki.es/viewtopic.php?f=33& ... p200086630, a PSG sample of malikto999. It seemed really easy, so i wanted to try it.

As i am a very big fan of the AY sound (being a zx spectrum user myself), i then started to think about a player of those tunes. .AY files were discarted very early, because of the z80 emulation needed, but the .ym file format (by Leonard/Oxygene) seemed an easy target. Each vertical retrace, output one sample. And that's what i do, take a YM song, process it on the PC, and each vsync, output the 14 registers values onto its place. The player (or better said, the "replayer") code is as easy as this:

Código: Seleccionar todo

for (a=0;a<samples;a++)
{
	vsync();  //or a fixed loop simulating a 1/50 delay for accurate PAL timing
	for (b=0;b<16;b++)
	{
		unsigned int ff;		
		ff=ofsy + (a*16) +b;			
		PSG_DATA[0]=b;
		PSG_CTL[0]=3;
		PSG_CTL[0]=0;

		PSG_DATA[0]=buffy[ff];
		PSG_CTL[0]=2;
		PSG_CTL[0]=0;
	}
}
(note, the 16 part instead of 14, it's because the YM was for Atari ST, and this chip has 2 "more things" that not all songs uses, the rest are "standard" AY-3- chip format. PSG_CTL is $FD0D PSG_DATA is $FD0E)

That works, and sounds. As the songs i try (for now) are PAL amstrad tunes (1Mhz), it sounds about right, though at a faster rate if you use vsync because PAL/NTSC timing.
But it works for a few seconds (small RAM buffer), i don't have memory for much more (unpacked YM songs could be 200KB).

I then thought about a YM file player, but it doesn't work that way, i would need to create a lha unpacker, then be prepared to de-interleave 200KB or more of data. Not feasible, directly. But i could convert the format on PC to another one. And i'm still on this step -thumbup, trying to come up with some kind of compression (a YM file format is a dump of a tracked song, so definitively there must be some kind of pattern) and/or make it "streamable" (play on the fly as i decompress, and forget the old data). And i would definitively need also put the "player" code on a timer event (IRQ) of 50hz, to allow for streaming of data (as i can't have all in memory at once).

After that there would be the considerations of "resampling" of files captured with other machines at 2Mhz, etc...but that would be a bonus and could be done on the PC.

Overall, that's a very tall order, but stranger things have happened -507.

Anyway, that player is was what i was referring to when i said i have working sound code.

I replaced as is the $FD0D/$FD0E for $FD15/$FD16 and it sounds the same, but what it's even more disturbing, mixing them ($FD0D/$FD16) works -shock. But keep in mind that i only test on the XM7 emulator!

Reading again the I/O map, $FD0D/$FD0E is the FM7 port for PSG (standard for all the FM7 family), translated by google as "FM sound source shared") ,and 4 commands (high impedance, data read, data write and address register). The $FD15/$FD16 is translated as "FM sound source", its exclussive to AV family and it has the older commands plus two extra ones (status register, read joystick port).

So in theory it could be that new ports are for the added commands, and they (Fujitsu engineers) couln't retrofit the new commands onto old adresses because of compatibility reasons (the FM7 system manual clearly says that only lower 2 bits have sense, but lazy programmers, you know.. -rofl ). I don't know, it's just speculation.
pser1 escribió: I asume that the music chips are been managed by the subsystem, so the ROM code that deals with this functions expects these
different sequences for each one
For what it's worth, on the FM7 system specifications manual, the block diagram says that PSG is connected to main cpu.
pser1 escribió: That said, this only tells us how to use the FM part of the YM2203. That chip has also two parallel ports each 8 bits that can be
input or output upon configuration (I don't know what is their default behaviour ...)
I must confess, again, that i don't know jack about that -shock . I mean, i keep reading about the AY/Yamaha FM chips on wikipedia and it's a "festival" of models and submodels with subtle differences, PSG/SSG/OPL..i lose track easly -rofl

I have read about the extra paralel ports on those chips, but i don't know what they are about... are those digital DACs for sampled data?
Anyway, i don't know how those extra features (if pressent) would be accesible through the I/O map
-sp3zy PC 386 -coam1 -m3s3x
Avatar de Usuario
jimbobaby
Mensajes: 552
Registrado: 13 Ago 2023 21:17

Re: FM77AV - learning how to program it (english thread)

Mensaje por jimbobaby »

pser1 escribió: Anyway, the addresses $FDEA and $FDEB cannot be MIDI because the YM2203 doesn't have any MIDI port.
I don't know, i just saw than on the I/O map it says so (for the FM77AV onwards, not for the FM7), that those ports are for MIDI, for send/receive commands. I don't know about MIDI in general, but i suppose it's not for playing MIDI on itself, "just" for routing and controlling MIDI devices, as an Atari ST for example. On the I/O map also speaks about the 8251A (an intel USART transmitter).

Searching about that, i have stumbled on this. I think that could answer some of our questions (and give some more, probably -507 )

https://www.matrixsynth.com/2020/12/rac ... rsion.html
-sp3zy PC 386 -coam1 -m3s3x
Avatar de Usuario
pser1
Mensajes: 4893
Registrado: 08 Dic 2012 18:34

Re: FM77AV - learning how to program it (english thread)

Mensaje por pser1 »

@jimbobaby
Hello,
Clearly the FMAV77 requires that strange sequence of operations just to send a value to a register, mainly
- Select the register with, let's say, three POKEs
- Write the data with another set of three POKEs

On the SuperSprite-FM+ for the CoCo and Dragon, made and sold by John Whitworth, we can access two chips:
- YM2149 that is pin compatible with the AY-3-8910 with the two parallel ports
- YM2413 an OPL2 chip that allows for 9 simultaneous sounds or 6 melody plus 5 rhythm sounds
Both can be fed the very same way:
- one POKE to send the register number
- one POKE to send the value for that register
And this *MUST* work for the AY-3-8910 for sure, so there must be something special on the FM77AV, maybe hardware
or maybe software, but the sequence of 6 POKEs to send a value seems unnecessary ...
cheers!
pere
Avatar de Usuario
jimbobaby
Mensajes: 552
Registrado: 13 Ago 2023 21:17

Re: FM77AV - learning how to program it (english thread)

Mensaje por jimbobaby »

Ok, after some "wikipeding" -507 , a little recap

FM7 - General Instruments AY-3-8910
FM77 L2 onwards (including of course FM77AV) - Yamaha YM2203

From wikipedia (https://en.wikipedia.org/wiki/Yamaha_YM2203, https://en.wikipedia.org/wiki/General_I ... _AY-3-8910, https://sinclair.wiki.zxnet.co.uk/wiki/AY-3-8912):
The YM2203 has the following features:

Three concurrent FM synthesis channels (voices)
Four operators per channel
Two interval timers
Internal implementation of Yamaha's YM2149F SSG chip

The SSG module implemented the YM2149F's three SSG channels, noise generator and dual GPIO ports. The YM2203 is used with a YM3014 external DAC companion chip.
The YM2149F is effectively a GI AY-3-8910 chip (same pin-out, could be a direct replacement). The only difference with the GI chip seems to be able to half the master clock (not needed for replacing the GI chip).

The ZX Spectrum 128k models have also MIDI, and they have an GI AY-3-8912. The 8912 has only one of the 8bit GPIO, instead of the two of the 8910.
As wikipedia says:
I/O port A of the AY chip of 128K Spectrums is connected to a pair of I/O sockets, One designated RS232/MIDI and the other Keypad or Aux. Each port contains two input pins, two output pins, and 12 volt and ground rails.
So if the spectrum have MIDI with one GPIO channel and FM77AV has two, it should have DOUBLE THE MIDI -507 ('jokin)

So right now, i'm using just old compatible AY-3-8910 mode, and for using the full YM2203 chip, we could use other machines code as info/examples (i.e. some arcade mame games).

That's one thing i like about this machine... i'm learning indirectly a lot about another machines too -thumbup
-sp3zy PC 386 -coam1 -m3s3x
Avatar de Usuario
jimbobaby
Mensajes: 552
Registrado: 13 Ago 2023 21:17

Re: FM77AV - learning how to program it (english thread)

Mensaje por jimbobaby »

pser1 escribió:@jimbobaby
Clearly the FMAV77 requires that strange sequence of operations just to send a value to a register, mainly
- Select the register with, let's say, three POKEs
- Write the data with another set of three POKEs
pser1 escribió:@jimbobaby
but the sequence of 6 POKEs to send a value seems unnecessary ...
That were needed already with the pure FM7, and it was a AY-3-8910 (at least on some models)
-sp3zy PC 386 -coam1 -m3s3x
Avatar de Usuario
jimbobaby
Mensajes: 552
Registrado: 13 Ago 2023 21:17

Re: FM77AV - learning how to program it (english thread)

Mensaje por jimbobaby »

pser1 escribió: Clearly the FMAV77 requires that strange sequence of operations just to send a value to a register, mainly
- Select the register with, let's say, three POKEs
- Write the data with another set of three POKEs
Of course!!! -banghead Silly me.

Those POKE's are the commands. So the PSG control register is not directly mapped to the sound chip, it's a multiplexor of some kind.
Put the data on data register and then
Command 3 = address register
Command 0 = high impedance -> (a "send command", something bus related, i suppose)

And for sending sound data, Command 2 (write data) and Command 0 (high impedance).

Instead of just putting the control register directly as 0-13 register.

I suppose this weird implementation is for bus implementation reasons or an "abstracting hw" approach.
-sp3zy PC 386 -coam1 -m3s3x
Avatar de Usuario
pser1
Mensajes: 4893
Registrado: 08 Dic 2012 18:34

Re: FM77AV - learning how to program it (english thread)

Mensaje por pser1 »

hi,
back to MIDI
I have read in the web that jimbobaby commented about in his last post and well, I need a FM77AV schematic to try to find
how the heck it could be done with the YM2203 ...
According to the MIDI definition:
The MIDI protocol uses 8-bit serial transmission with one start bit and one stop bit. It has a 31.25 kilobits-per-second (Kbps) data rate and is asynchronous.
This implies the presence of an UART inside the FM77AV or at least that the IO port in the rear pannel can be used to attach an external module
or maybe it exists a module that can be connected on the mother board ...
We really need to know where the ports $FDEA and $FDEB are connected in the FM77AV
cheers!
pere
Responder

Volver a “Fujitsu FM7”