XWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V Yamaha FM-Sound Synthesizer Unit documentation Ver:1.0 Made By : NYYRIKKI V ZWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ General : ========= This document contains short description about programming FM sound Synthesizer (YM2151) of the FM sound synthesizer unit(II), that was made by Yamaha for CX5M MSX computer, but that was also available for other MSX computers trough Yamaha Unit Connector UCN-01. This unit includes also D/A converter (YM3012), so 8 audio tone signals can be obtained at the R and L channels. The YM2151 has 8-note capability and it is also equipped with a noise generator, vibrato oscillator, amplitude modulation circuit, tonal effect generator and timer circuitry. 2 sets of timers are used and when a timer overflows an interrupt request takes place. This unit has also YM2148 chip, that has a MIDI function, keyboard scan function and it supports MODE 2 IRQ for CPU, but this document does not tell, how to use these features. Addresses, that are needed for accessing this chip can be anyway founded from address table. How to found FM-Sound Synthesizer Unit: ======================================= Because Yamaha made a Unit Connector, that can be inserted to any expansion slot, it is not sure, that this Unit is always connected to slot #3. That means, that you have to find this with your own routine. The standard way to do that is to search text "MCHFM0" from address #80 in every slot. Here is a simple routine to do that, activate this slot, run your FM-program part and exit to previous routine. WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW ; First we have to move this program to area #4000-#7FFF, because ; other ways we can't read needed area from FM Synthesizer module. LD HL,BBEGIN LD DE,BEGIN LD BC,END-BEGIN LDIR JP BEGIN BBEGIN ORG #4000 BEGIN DI ; Interrupts must be disabled, other ways we can't ; switch slots in #0000-#3FFF area. LD (TOHL),SP ; We have to be sure, that SP is in area #4000-#BFFF LD HL,0 TOHL EQU $-2 LD SP,#8000 PUSH HL IN A,(#A8) PUSH AF AND %00111100 LD D,A LD B,3 SEARCHM ; Loop to search from main-slots. LD A,B RRCA RRCA OR B OR D OUT (#A8),A PUSH BC LD A,(#FFFF) CPL PUSH AF AND %11111100 LD E,A LD B,3 SEARCHS ; Inner loop for sub slot search. LD A,B OR E LD (#FFFF),A EXX LD B,6 LD HL,IDTXT-1 LD DE,#80-1 SEID INC HL INC DE LD A,(DE) CP (HL) JR NZ,NOMATCH DJNZ SEID ; It was found, so we will call a main program (you have to make that one), ; and after that we will select a slot, that was selected before running ; this part and we will exit with C flag as zero. CALL FM_PROGGRAM POP AF LD (#FFFF),A POP AF POP AF OUT (#A8),A POP HL LD SP,HL XOR A RET IDTXT DEFB "MCHFM0" NOMATCH EXX DJNZ SEARCHS POP AF LD (#FFFF),A POP BC DJNZ SEARCHM ; We didn't found it, and we will set C flag to detect an error. POP AF OUT (#A8),A POP HL LD SP,HL SCF RET WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW ADDRESS TABLE : =============== #3FF0 (R) FM Status register #3FF0 (W) FM Address register #3FF1 (R/W) FM Data register #3FF2 (R/W) Yamaha external keyboard (YK-01 or YK-10) I/O address. #3FF3 (W) MIDI IRQ vector address #3FF4 (W) External IRQ vector address #3FF5 (R/W) MIDI UART Data read and write buffer #3FF6 (R) MIDI UART Status Register #3FF6 (W) MIDI UART Command Register Using this FM-Chip: =================== STATUS REGISTER : (READY FOR WRITE, TIMER OVERFLOWS) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWY V Busy V V V V V VTIMER BVTIMER AV ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWW[ Write able registers : ------------------------------------------------------------------------- REGISTER : #00 (NOT USED) ------------------------------------------------------------------------- REGISTER : #01 (TEST & LFO RESET) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWY V V V V V V V LFO R V V ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWW[ ------------------------------------------------------------------------- REGISTER : #02-#07 (NOT USED) ------------------------------------------------------------------------- REGISTER : #08 (KEY ON) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWY V V MOD1 V CAR1 V MOD2 V CAR2 V CHANNEL NUMBER V ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWW[ KEY ON (1) or OFF (0) for each modulator and carrier on channel 0-7. ------------------------------------------------------------------------- REGISTER : #09-#0E (NOT USED) ------------------------------------------------------------------------- REGISTER : #0F (NOISE ENABBLE, NOISE FREQUENCY) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V NE V V V NOISE FREQUENCY V ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ FREQUENCY (Hz) = 3579545 / (32 * NOISE FREQUENCY) ------------------------------------------------------------------------- REGISTER : #10 (NOT USED) ------------------------------------------------------------------------- REGISTER : #11 (CLOCK A1) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWY V B9 V B8 V B7 V B6 V B5 V B4 V B3 V B2 V ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWW[ ------------------------------------------------------------------------- REGISTER : #12 (CLOCK A2) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWY V V V V V V V B1 V B0 V ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWW[ ------------------------------------------------------------------------- REGISTER : #13 (CLOCK B) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWY V D7 V B6 V B5 V B4 V B3 V B2 V B1 V B0 V ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWW[ ------------------------------------------------------------------------- REGISTER : #14 (CLOCK FUNCTIONS) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWWWWWWWWWRWWWWWWWWWWWWWWWRWWWWWWWWWWWWWWWY V CSM V V F RESET V IRQ EN V LOAD V ZWWWWWWWQWWWWWWWQWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWW[ ------------------------------------------------------------------------- REGISTER : #15-#17 (NOT USED) ------------------------------------------------------------------------- REGISTER : #18 (LOW FREQUENCY) 7 6 5 4 3 2 1 0 XWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V LOW OSCILLATION FREQUENCY V ZWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ ------------------------------------------------------------------------- REGISTER : #19 (PHASE & AMPLITUDE MODULATION) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V F V PHASE OR AMPLITUDE MODULATION DEPHT V ZWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ F = 0 AMPLITUDE MODULATION F = 1 PHASE MODULATION ------------------------------------------------------------------------- REGISTER : #1A (NOT USED) ------------------------------------------------------------------------- REGISTER : #1B (CONTROLL OUTPUT & WAVE FORM SELECT) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWWWWWWWWWY V CT2 V CT1 V V V V V WAVE FORM V ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWWWWWWWWW[ XWWWWWWWWWWWWWWWWWWY V PHASE MODULATION V XWWWWWWWWWWWWWWWRWWWWWWQWWWWWWWWRWWWWWWWWWQWWWWWRWWWWWWWWWWWWWWWY V WAVE FORM : 0 V WAVE FORM : 1 V WAVE FORM : 2 V WAVE FORM : 3 V V V V V V V /V /V V XWWWY XWWWY V /` /` V V V / V / V / V V V V V V / ` / V V V WWUWW/WWVWW/W V UWWWUWWWUWWWU V/WWWW`WWWW/WWW V NOISE V V V / V / V V V V ` / V V V V/ V/ V ZWWW[ V `/ V V ZWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWW[ XWWWWWWWWWWWWWWWWWWWWWWY V AMPLITUDE MODULATION V XWWWWWWWWWWWWWWWRWWWQWWWWWWWWWWWRWWWWWWWWWWQWWWWRWWWWWWWWWWWWWWWY V WAVE FORM : 0 V WAVE FORM : 1 V WAVE FORM : 2 V WAVE FORM : 3 V V V V V V V V` V` V` V XWWWY XWWWY V ` /` V V V V ` V ` V ` V V V V V V ` / ` V V V V ` V ` V V V V V V V ` / ` V NOISE V V V `V `V V V V V V V ` / ` V V V QWWWWQWWWWQWW V QWWWQWWWQWWWQ V WWWWQWWWWWWWW V V ZWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWW[ ------------------------------------------------------------------------- REGISTER : #1C-#1F (NOT USED) ------------------------------------------------------------------------- REGISTER : #20-#27 (CHANNEL CONTROL) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWY V RIGHT V LEFT V FB V CONECT V ZWWWWWWWQWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWW[ REGISTER = #20 + CHANNEL NUMBER (0-7) ------------------------------------------------------------------------- REGISTER : #28-#2F (KEY CODE) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V V OCTAVE V NOTE V ZWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ REGISTER = #28 + CHANNEL NUMBER (0-7) ------------------------------------------------------------------------- REGISTER : #30-#37 (KEY FRACTION) 7 6 5 4 3 2 1 0 XWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWRWWWWWWWRWWWWWWWY V KEY FRACTION V V V ZWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWQWWWWWWWQWWWWWWW[ REGISTER = #30 + CHANNEL NUMBER (0-7) ------------------------------------------------------------------------- REGISTER : #38-#3F (PHASE & AMPLITUDE MODULATION SENSITIVITY) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWWWWWWWWWY V V PMS V V V AMS V ZWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWWWWWWWWW[ REGISTER = #38 + CHANNEL NUMBER (0-7) ------------------------------------------------------------------------- REGISTER : #40-#5F (DETUNE & PHASE MULTIBLY) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V V DETUNE (1) V PHASE MULTIBLY V ZWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ REGISTER = #40 + 8 * DEV(*) + CHANNEL NUMBER (0-7) ------------------------------------------------------------------------- REGISTER : #60-#7F (TOTAL LEVEL) 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V V TOTAL LEVEL V ZWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ REGISTER = #60 + 8 * DEV(*) + CHANNEL NUMBER (0-7) ------------------------------------------------------------------------- REGISTER : #80-#9F 7 6 5 4 3 2 1 0 XWWWWWWWWWWWWWWWRWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V KEY SCALING V V ATACK RATE V ZWWWWWWWWWWWWWWWQWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ REGISTER = #80 + 8 * DEV(*) + CHANNEL NUMBER (0-7) ------------------------------------------------------------------------- REGISTER : #A0-#BF 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V AMSEN V V V FIRST DECAY RATE V ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ REGISTER = #A0 + 8 * DEV(*) + CHANNEL NUMBER (0-7) AMSEN = AMPLITUDE MODULATION SENSITIVITY ENABBLE (1=ENABBLE) ------------------------------------------------------------------------- REGISTER : #C0-#DF 7 6 5 4 3 2 1 0 XWWWWWWWWWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V DETUNE(2) V V V SECOND DECAY RATE V ZWWWWWWWWWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ REGISTER = #C0 + 8 * DEV(*) + CHANNEL NUMBER (0-7) ------------------------------------------------------------------------- REGISTER : #E0-#FF 7 6 5 4 3 2 1 0 XWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWRWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V FIRST DECAY LEVEL V RELEASE RATE V ZWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWQWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ REGISTER = #E0 + 8 * DEV(*) + CHANNEL NUMBER (0-7) ------------------------------------------------------------------------- XWWWWWY V (*) V V ZWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWY V If you change value of MODULATOR 1 then DEV = 0 V V If you change value of MODULATOR 2 then DEV = 1 V V If you change value of CARRIER 1 then DEV = 2 V V If you change value of CARRIER 2 then DEV = 3 V ZWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[ WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW How to handle external Yamaha keyboard : ======================================== Yamaha keyboards are easy to use. They have been divided to 8 separate rows, that each have 6 keys. When you want to read some key, you first have to select a row to read. This is done by sending this row number to #3FF2 in format : 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWY V ROW7 V ROW6 V ROW5 V ROW4 V ROW3 V ROW2 V ROW1 V ROW0 V ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWW[ This means, that you can calculate current row by using formula : [to #3FF2] = 2 ^ [ROW NUMBER 0-7] After this you need to wait a little while. Unfortunately I don't know how little, but something like one microsecond. Then you can read this address, and you will get a value in following format : 7 6 5 4 3 2 1 0 XWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWRWWWWWWWY V V KEY5 V KEY4 V KEY3 V V KEY2 V KEY1 V KEY0 V ZWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWWQWWWWWWW[ "1" = Not pressed "0" = pressed Current key number from bottom to up can be calculated by using formula : KEYNUMBER + ROW * 6 Please note, that YK-01 does not have few bottom keys at all. WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW Rest, that I want to say. ========================= I want to thank "Greg_" about helping me to collect this information, I mean, that this information is not a offical documentation, but I have just collected it from different sources and rest is just generated by testing. Here are the Yamaha part-numbers for the most important chips, that are in FM-Sound Synthesizer Unit: YM2151 (IC101): #IT-21-51-00 (FM-chip) YM3012 (IC102): #IT-30-12-00 (Stereo D/A converter) YM2148 (IC103): #IT-21-46-00 (Midi handling) YM22702 (IC104): #IT-22-70-20 (ROM) Greetings : ,_____. _=_=_=_=!_MSX_!=_=_=_=_=_=_=_=_, ! A1ST ~--- - I ( o o o o o o )i /--------------------------------`, / .::::::::::::::::::::::;::; ::::., / :::.:.:.:::____________:::::!. -=- `, ~====================================== NYYRIKKI