Any example code for the games master cart?

This area for discussing Assembly language.

Any example code for the games master cart?

Postby William Schaub » Sat Oct 21, 2017 10:48 pm

I would like to play with the games_master support in MAME but so far I've not been able to find anything that produces sound.

I'm using it in multipack slot 1 with the floppy controller in the normal slot and active.

This is my non-working code to try and make it produce a tone but so far nothing I've tried works.
Do I need to select the card in the multipack before writing to the sound chip address? (not sure what address to poke to make that happen)
Code: Select all
    ORG $0E00
START   CLRA
        LDA #$3F
        STA $FF23
        LDA #$3D    ;set cart sound input
        STA $FF03
R       LEAX REGS,PCR
!       LDA ,X+
        CMPA #$00
        BEQ R
        STA $FF41
        NOP
        NOP
        NOP
        NOP
        BRA <
REGS    FCB $84,$27,$90,$91,$92,$93,$00
        END START
William Schaub
 
Posts: 8
Joined: Mon Oct 16, 2017 9:08 pm

Re: Any example code for the games master cart?

Postby Invisible » Sun Oct 22, 2017 4:21 am

YES, here you are...

I wrote this pattern based player for Johns cart earlier in the year.

/Simon :ugeek:
Attachments
snplayer.zip
(276.63 KiB) Downloaded 106 times
Invisible
 
Posts: 12
Joined: Tue Oct 17, 2017 1:50 pm

Re: Any example code for the games master cart?

Postby nowhereman999 » Sun Oct 22, 2017 5:04 pm

Hi William,

Just last week I started playing with John Linville's Game Master Cartridge to use with my MIDI to CoCo converter. It's working OK, but it's not user friendly just yet. I'll post the code once the player code is complete. Below is part of the top part of my source code, it should help you to get going with the GMC.

Code: Select all
**************************************
* Test program for the Texas Instruments SN76489 sound chip
* Used inside John Lynville's Game Master Cartridge for the Tandy Color Computer
*
* The SN76489 has 3 music channels selected as 00, 01, and 10 and one noise channel which is channel 11
*
* To send a note you need two bytes the first is called the latch and bit 7 must be set to signify it is a latch byte
*    7654 3210
*   %1cct dddd
*     ||| ````-- Data, For Tone Data these are the least significant bits
*     ||`------ Type 0 = tone data, 1=volume level
*     ``------- Channel
*
* for tone data a second byte is required and is a data byte where bit 7 must be low
*       987654
*    %0xdddddd These are the most significant bits of the register that represnets the frequency of the tone
*
* The 10 bit value (0-9) that represents the Frequency of the tone to play
*
* Example to send a note
*
*                       Input clock (Hz) (4000000)
*   Frequency (Hz) = ----------------------------------
*                     2 x register value x divider (16)
*
* Example values for an NTSC-clocked chip are given and are generally assumed throughout. Thus, for example, 0x0fe gives 440.4Hz.
*
*                              4000000                             125000
*     Register Value =      ------------      also equals       ------------ 
*                        2 x Freq (Hz) x 16                       Freq (Hz)
*
*   Volume control is set when bit 4 is high, the volume level is a value between 0 to 15 (value of the right nibble) with 15 being silence and 0 being the loudest, backwards to normal
*    7654 3210
*   %1011 1111      Latch, channel 1, volume control, data 1111   Set channel 1 volume to 0xf (silent)
*     ||| ````- Data  - Volume level 0000 = loudest - 1111 silence
*     ||`------ Type  - Volume setting
*     ``------- Channel
*  Good info here:
*  http://www.smspower.org/uploads/Development/SN76489-20030421.txt
*
**************************************


Values for the Frequency can be calculated from the above info. Here are the DATA statements for my MIDI converter, it might help to just look up the values you need. The two hex values per line will have to be sent to the SN chip with the right value first and the left value next, adding your latching and channel info. B2 is the lowest value you can use with the GMC as $3F is the highest value you can send as the 2nd byte for the frequency value's 2nd byte. As per info above.

Code: Select all
'Game Master Cartridge Frequency values Can't play notes below C1 so C0 to B0 = C1 value
'                   Frequency
DATA EE,F: 'C-0            0
DATA EE,F: 'C#-0/Db-0
DATA EE,F: 'D-0
DATA EE,F: 'D#-0/Eb-0
DATA EE,F: 'E-0
DATA EE,F: 'F-0
DATA EE,F: 'F#-0/Gb-0
DATA EE,F: 'G-0
DATA EE,F: 'G#-0/Ab-0
DATA EE,F: 'A-0
DATA EE,F: 'A#-0/Bb-0
DATA EE,F: 'B-0
DATA EE,F: 'C-1            12
DATA EE,F: 'C#-1/Db-1
DATA EE,F: 'D-1
DATA EE,F: 'D#-1/Eb-1
DATA EE,F: 'E-1
DATA EE,F: 'F-1
DATA EE,F: 'F#-1/Gb-1
DATA EE,F: 'G-1
DATA EE,F: 'G#-1/Ab-1
DATA EE,F: 'A-1
DATA EE,F: 'A#-1/Bb-1
DATA EE,F: 'B-1
DATA EE,F: 'C0      16.35   24
DATA EE,F: 'C#0/Db0 17.32
DATA EE,F: 'D0      18.35
DATA EE,F: 'D#0/Eb0 19.45
DATA EE,F: 'E0      20.6
DATA EE,F: 'F0      21.83
DATA EE,F: 'F#0/Gb0 23.12
DATA EE,F: 'G0      24.5
DATA EE,F: 'G#0/Ab0 25.96
DATA EE,F: 'A0      27.5
DATA EE,F: 'A#0/Bb0 29.14
DATA EE,F: 'B0      30.87
DATA EE,F: 'C1      32.7    36
DATA E1,8: 'C#1/Db1 34.65
DATA D4,D: 'D1      36.71
DATA C8,E: 'D#1/Eb1 38.89
DATA BD,A: 'E1      41.2
DATA B3,0: 'F1      43.65
DATA A8,F: 'F#1/Gb1 46.25
DATA 9F,7: 'G1      49
DATA 96,8: 'G#1/Ab1 51.91
DATA 8E,1: 'A1      55
DATA 86,1: 'A#1/Bb1 58.27
DATA 7E,9: 'B1      61.74
DATA 77,7: 'C2      65.41   48
DATA 70,C: 'C#2/Db2 69.3
DATA 6A,7: 'D2      73.42
DATA 64,7: 'D#2/Eb2 77.78
DATA 5E,D: 'E2      82.41
DATA 59,8: 'F2      87.31
DATA 54,7: 'F#2/Gb2 92.5
DATA 4F,C: 'G2      98
DATA 4B,4: 'G#2/Ab2 103.83
DATA 47,0: 'A2      110
DATA 43,1: 'A#2/Bb2 116.54
DATA 3F,4: 'B2      123.47    Lowest Note GMC can play
DATA 3B,C: 'C3      130.81  60
DATA 38,6: 'C#3/Db3 138.59
DATA 35,3: 'D3      146.83
DATA 32,4: 'D#3/Eb3 155.56
DATA 2F,6: 'E3      164.81
DATA 2C,C: 'F3      174.61
DATA 2A,4: 'F#3/Gb3 185
DATA 27,E: 'G3      196
DATA 25,A: 'G#3/Ab3 207.65
DATA 23,8: 'A3      220
DATA 21,8: 'A#3/Bb3 233.08
DATA 1F,A: 'B3      246.94
DATA 1D,E: 'C4      261.63  72  - Newer MIDI programs use C4=72
DATA 1C,3: 'C#4/Db4 277.18
DATA 1A,A: 'D4      293.66
DATA 19,2: 'D#4/Eb4 311.13
DATA 17,B: 'E4      329.63
DATA 16,6: 'F4      349.23
DATA 15,2: 'F#4/Gb4 369.99
DATA 13,F: 'G4      392
DATA 12,D: 'G#4/Ab4 415.3
DATA 11,C: 'A4      440
DATA 10,C: 'A#4/Bb4 466.16
DATA F,D: 'B4       493.88
DATA E,F: 'C5       523.25  84
DATA E,1: 'C#5/Db5  554.37
DATA D,5: 'D5       587.33
DATA C,9: 'D#5/Eb5  622.25
DATA B,E: 'E5       659.25
DATA B,3: 'F5       698.46
DATA A,9: 'F#5/Gb5  739.99
DATA 9,F: 'G5       783.99
DATA 9,6: 'G#5/Ab5  830.61
DATA 8,E: 'A5       880
DATA 8,6: 'A#5/Bb5  932.33
DATA 7,F: 'B5       987.77
DATA 7,7: 'C6       1046.5  96
DATA 7,1: 'C#6/Db6  1108.73
DATA 6,A: 'D6       1174.66
DATA 6,4: 'D#6/Eb6  1244.51
DATA 5,F: 'E6       1318.51
DATA 5,9: 'F6       1396.91
DATA 5,4: 'F#6/Gb6  1479.98
DATA 5,0: 'G6       1567.98
DATA 4,B: 'G#6/Ab6  1661.22
DATA 4,7: 'A6       1760
DATA 4,3: 'A#6/Bb6  1864.66
DATA 3,F: 'B6       1975.53
DATA 3,C: 'C7       2093     108
DATA 3,8: 'C#7/Db7  2217.46
DATA 3,5: 'D7       2349.32
DATA 3,2: 'D#7/Eb7  2489.02
DATA 2,F: 'E7       2637.02
DATA 2,D: 'F7       2793.83
DATA 2,A: 'F#7/Gb7  2959.96
DATA 2,8: 'G7       3135.96
DATA 2,6: 'G#7/Ab7  3322.44
DATA 2,4: 'A7       3520
DATA 2,2: 'A#7/Bb7  3729.31
DATA 2,0: 'B7       3951.07
DATA 1,E: 'C8       4186.01  120
DATA 1,C: 'C#8/Db8  4434.92
DATA 1,B: 'D8       4698.63
DATA 1,9: 'D#8/Eb8  4978.03
DATA 1,8: 'E8       5274.04
DATA 1,6: 'F8       5587.65
DATA 1,5: 'F#8/Gb8  5919.91
DATA 1,4: 'G8       6271.93
DATA 1,3: 'G#8/Ab8  6644.88



As for your code see my comments:
Code: Select all
    ORG $0E00           * Must be run as a cartridge so you must ORG   $C000 
START   CLRA           * Why CLRA then LDA next line?
        LDA #$3F
        STA $FF23
        LDA #$3D    ;set cart sound input
        STA $FF03

* From John Linville's demo code he does the this at the beginning of his player code which I haven't bothered to figure out yet, but it works for me...
        LDA     $FF01
        ANDA    #$FC
        STA     $FF01
        TST     $FF00
        LDA     $FF03
        ORA     #$01
        STA     $FF03
        TST     $FF02


R       LEAX REGS,PCR
!       LDA ,X+
        CMPA #$00       * FYI  after a LD instruction the Z flag will be set if the value loaded is a zero, so you never have to use a CMPx   #$00  leave it out if you are going to BEQ on a $00 value
        BEQ R
        STA $FF41
        NOP
        NOP
        NOP
        NOP
        BRA <
REGS    FCB $84,$27,$90,$91,$92,$93,$00
        END START


So your code will first send $84 and $27 which is close to a G3 note on channel 0, then it sets the Volume of Channel 0 to full with $90, then a little lower volume with $91, and lower with $92 and lower again with $93. Then it repeats sending the notes and volume over and over. Those volume changes are super fast and you probably wont hear the changes. You might want to be some delay's in between the volume changes so you can notice them.

Your code should work if you run it as a ROM cartridge (ORG $C000) using LWASM and MAME as (if your source code is called GMC_play.asm):
lwasm -9rl -p cd -otest.rom GMC_play.asm > listing.txt
mame coco2b -ext games_master -cart test.rom -skip_gameinfo -window -ui_active

Keep in mind you don't need to keep sending the data to the chip, the SN chip will play the note you send it until you send it another note or set the volume level to off $9F for channel 0 in your example.

Cheers,
Glen
nowhereman999
 
Posts: 33
Joined: Mon Sep 18, 2017 11:43 pm

Re: Any example code for the games master cart?

Postby William Schaub » Sun Oct 22, 2017 5:34 pm

Thanks simon, as usual you are awesome! However It looks like I'm having problems witn MAME I was hoping to play with the games master emulation in it but after running your code on mame with no sound I'm assuming either there's a problem with MAME or I'm doing something wrong in mame. has anyone gotten the games master emulation to play in MAME?
William Schaub
 
Posts: 8
Joined: Mon Oct 16, 2017 9:08 pm

Re: Any example code for the games master cart?

Postby William Schaub » Sun Oct 22, 2017 5:41 pm

nowhereman999 wrote:Hi William,

Just last week I started playing with John Linville's Game Master Cartridge to use with my MIDI to CoCo converter. It's working OK, but it's not user friendly just yet. I'll post the code once the player code is complete. Below is part of the top part of my source code, it should help you to get going with the GMC.

So your code will first send $84 and $27 which is close to a G3 note on channel 0, then it sets the Volume of Channel 0 to full with $90, then a little lower volume with $91, and lower with $92 and lower again with $93. Then it repeats sending the notes and volume over and over. Those volume changes are super fast and you probably wont hear the changes. You might want to be some delay's in between the volume changes so you can notice them.

Your code should work if you run it as a ROM cartridge (ORG $C000) using LWASM and MAME as (if your source code is called GMC_play.asm):
lwasm -9rl -p cd -otest.rom GMC_play.asm > listing.txt
mame coco2b -ext games_master -cart test.rom -skip_gameinfo -window -ui_active

Keep in mind you don't need to keep sending the data to the chip, the SN chip will play the note you send it until you send it another note or set the volume level to off $9F for channel 0 in your example.

Cheers,
Glen


Thanks for the info. I've been trying to load from disk and from tape with the cart configured in MAME with no luck, even with simon's code so far. I will try loading it from the cart and give your code a try. I'm wondering if I'm not having an issue with mame as far as not being able to hear any sound at this point.

I know my example code is rubbish, was just trying to make it produce any sound at all. I'm assuming I can just have the code halt after i give it a note and a volume level then and still have at least a tone.
William Schaub
 
Posts: 8
Joined: Mon Oct 16, 2017 9:08 pm

Re: Any example code for the games master cart?

Postby William Schaub » Sun Oct 22, 2017 9:58 pm

I added the extra bit to my code (the from john linville's demo code bit) and built it up as a rom, even ram MAME as you said and still no sound. I removed the constant loop and just told it to make one tone and halted afterwards (just after it sends $90 to what is supposed to be the chip address ) I also tried it without my trying to setup the audio inputs and just the code you added with no luck. so I guess I'm safe to assume that my version of mame isn't working?
William Schaub
 
Posts: 8
Joined: Mon Oct 16, 2017 9:08 pm

Re: Any example code for the games master cart?

Postby nowhereman999 » Mon Oct 23, 2017 3:03 pm

Hi William,

Did you use the options for mame that I suggested exactly? You can't use the -flop1 option since the Floppy drive controller is also using $FF41. I found that out the hard way last week. You have to make your program look like a ROM cartridge program that is assembled with LWASM using -r and not -b. Then start MAME without the -flop1 or -flop2 option.

I hope this helps...

If not, show us your code, your lwasm command line and mame command and I'll try it on my system and let you know if it works here.

FYI - I'm using MAME 0.190, but I know the Game Master Cartridge code has been in MAME for at least six months now.

Cheers,
Glen
nowhereman999
 
Posts: 33
Joined: Mon Sep 18, 2017 11:43 pm

Re: Any example code for the games master cart?

Postby Invisible » Tue Oct 24, 2017 7:35 am

Hi Glen...

I beg to differ on that you can't have the cart and the disk controller at the same time in mess/mame....

this is the command line i used myself to have both of them:

mess.exe coco2b -ext multi -ext:multi:slot3 games_master -flop1 ssc.dsk -skip_gameinfo -window -ui_active

my code just picks which MPI slot i want to address

/Simon :D
Invisible
 
Posts: 12
Joined: Tue Oct 17, 2017 1:50 pm

Re: Any example code for the games master cart?

Postby nowhereman999 » Tue Oct 24, 2017 8:14 pm

Thanks for the info Simon, you are the man!

I'll take a closer look at your code and see how to play with the multipack options in assembly. That will make it easier to test and I can then have 512k of music to play back. Just when I was starting to look into writing some LZ compression algorithms too. I'll probably still look at compression stuff anyways just for fun... :)

Cheers mate,
Glen
nowhereman999
 
Posts: 33
Joined: Mon Sep 18, 2017 11:43 pm

Re: Any example code for the games master cart?

Postby sixxie » Wed Oct 25, 2017 3:11 am

For compression, a few tools exist already:

Exomizer 2 achieves really good compression, the unpacker is very large and slow (there is a 6809 version in there somewhere).

There's one called either SLZ or SLC which I can't for the life of me find now. The unpacker is moderately sized IIRC, and achieves slightly better compression than dzip on average (sometimes dzip beats it).

And mine, dzip, has a very tight decompressor (39 bytes, depending on how you engineer the loop for your purpose), but doesn't pull any neat tricks, so compression isn't as good as Exomizer 2.

If you come up with one of your own, maybe you can strike a different balance :)
sixxie
 
Posts: 8
Joined: Tue Oct 17, 2017 9:19 am

Next

Return to Assembly

Who is online

Users browsing this forum: No registered users and 1 guest

cron