Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch Mockingboard speech titles to use SAM software speech #272

Open
roughana opened this issue Jun 24, 2020 · 29 comments
Open

Patch Mockingboard speech titles to use SAM software speech #272

roughana opened this issue Jun 24, 2020 · 29 comments
Labels
enhancement New feature or request mockingboard Mockingboard-related issues

Comments

@roughana
Copy link
Contributor

Can we patch TR titles that have Mockingboard speech to use SAM software speech instead?
Memory may preclude this on standard system but perhaps it could be a IIgs only patch.

@peterferrie
Copy link
Collaborator

peterferrie commented Jun 24, 2020 via email

@tomcw
Copy link
Contributor

tomcw commented Jun 26, 2020

Slightly off topic: I mentioned a similar idea on the Slack #totalreplay channel: Crime Wave (and Spy Strikes Back) both use the older Mockingboard w/Votrax SC-01 speech chip only.

You could patch the games to use the newer SSI263 speech chip instead. In fact this is how AppleWin supports this SC-01 speech chip (by just translating the SC-01 to SSI263 phonemes on the fly). You'd also need to patch the setup & IRQ support. So it's a fair amount of effort just for 2 games.

Taken further you could go the other way, and support older SC-01 based chips, by patching in the reverse direction! (Requires patching 3 games: Bejeweled, Berzap, Rescue Raiders). But does anyone even have one of these older Mockingboards?

...and then a step further would be to add speech support for games that never had it! IMO this goes beyond what TR is about, but for completeness I thought I'd mentioned it :-)

@roughana
Copy link
Contributor Author

A port of SAM engine into C and some modern resources including a wiki for the phonemes: https://github.com/s-macke/SAM
Software only version of SAM:
https://archive.org/details/3d0g_373b_Sam_Talks
While this works, the 66 sector binary is full of junk and appears to be a pirate rip. Therefore not recommended as a starting point unless there is no other option. I remember having a disk which was more like an SDK. I'll keep looking.

@roughana
Copy link
Contributor Author

roughana commented Jul 17, 2020

Apple II disassembly of SAM and RECITER programs from the SAM hardware SDK.
https://github.com/robjustice/Apple3SAM/tree/master/A2SAMdisassembly

Discussion about the usage of the SAM software SDK
https://groups.google.com/d/topic/comp.sys.apple2/WpWA9qPUGpw/discussion

Documentation for SAM (Hat tip to Antoine Vignau)
http://mirrors.apple2.org.za/Apple%20II%20Documentation%20Project/Interface%20Cards/Speech/Don%27t%20Ask%20Software%20Automated%20Mouth/

@roughana
Copy link
Contributor Author

In theory, if the games are using phonemes then only the SAM program would be necessary.
Some tweaking of the phonemes may be necessary to obtain similar output.
If the gameplay continues during Mockingboard speech then the SAM output would provide a different experience because the software output will require dedicated CPU while the output is happening.

@roughana
Copy link
Contributor Author

roughana commented Jul 17, 2020

Speech usage observed during a brief investigation using AppleWin:
Berzap uses speech during the gameplay (various). The end of life "Ha Ha Ha" and end of game sequence (??) would not interfere with gameplay.
Crimewave uses speech during the gameplay ("Danger"). The beginning and end of play sequences ("Crime wave 1", "Game Over", "Enter your initials") would not interfere with gameplay.
Bejeweled - The beginning and end of play sequences ("Ready", "Go", "Game Over") would not interfere with gameplay. There is speech during gameplay ("Good", "Excellent", "Incredible"), but it sounded broken up as the jewels moved. Perhaps a better experience to play the whole word before the screen redraws?
Rescue Raiders uses speech at the beginning of the game - would not interfere with gameplay.

@tomcw
Copy link
Contributor

tomcw commented Jul 17, 2020

Bejeweled - crash to monitor in TR4a1 during load

Using AppleWin, I was able to reproduce this crash too (Enhanced //e) or hang with unenhanced //e.

Bug in TR4a1?
As the a2bejwld 2.6 release .dsk version works fine:
https://github.com/jeremysrand/a2bejwld/releases/tag/2.6

@roughana
Copy link
Contributor Author

roughana commented Jul 17, 2020 via email

@roughana
Copy link
Contributor Author

roughana commented Jul 19, 2020

Potentially, just target the 64k games - in which case the speech code could be added to AUX memory and then the //e users could also benefit from this.

I have disassembled the SAM software engine enough to understand the differences from the hardware version. They are very similar. Potentially, the hardware version could be loaded for those who have the SAM hardware. I believe that the hardware audio output should be easier to understand than the software audio output, but I haven't tested this myself.

Going for lowest common denominator, loading the software version into AUX memory for //e and //gs users would give the most bang for the buck.

@roughana
Copy link
Contributor Author

I need to understand each game's usage of the Mockingboard speech output to be able to patch in the SAM usage instead.

Bejewelled source code is available which makes this a great starting point.
https://github.com/jeremysrand/a2bejwld/blob/master/a2bejwld/sound.c

@roughana
Copy link
Contributor Author

roughana commented Jul 19, 2020

Using the games' own Mockingboard phonemes for SAM output is probably not possible - unless it turns out that they are related.
The SAM phonemes can be obtained by entering the text phrases from the games into the SAM reciter program and then looking at the phoneme buffer that the SAM program used to produce the output. Using phoneme's will make the SAM output stage quicker as it skips the reciter text -> phoneme interpretation steps.

@roughana
Copy link
Contributor Author

Bejewelled's precondition for speech output relies on the presence of a Mockingboard which will have to be changed to be independent. gMockingBoardSpeechEnabled is used to configure the speaker settings for mockingboard sounds.
Lets assume that the patch needs to add speech where none was possible before.
We can reuse the global flag for speech, but any use of that flag by other code should be checked.
The MB speech output checks to ensure there is nothing in progress before starting to speak a new phrase. This is because there is an interrupt routine set to process the output of the phrase as the mainline code keeps going.
For the speaker output, the entire phrase will be output before the routine returns.

SAM Phonemes for Bejewelled:
READY: REHDIY
GO: GOW
GOOD: GUH5D
EXCELLENT: EHKSSEHLEHNT
INCREDIBLE: INKREHDIHBUL
LEVELCOMPLETE: LEHVEHL KAHMPLIY4T
NOMOREMOVES: NOW MAOR MUW4VZ

@roughana
Copy link
Contributor Author

roughana commented Jul 20, 2020

We need an assembled version of SAM software for AUX mem space with an aux -> main return routine.
SAM uses a lot of zero page space. If this can be used in AUX ZP instead of main ZP then the save and restore routines could be avoided which would speed up the output.
We need a method of calling the SAM code in AUX from main mem.
We need a method of putting the SAM phonemes for the phrase to be spoken into the AUX mem buffer from main mem.
We need to patch the Bejewelled speech output routines to move the phoneme into the buffer and call SAM.
We need a loader to retrieve all these pieces from disk and to place them in the correct location.

For investigation: ProRWTS, AUX memory soft switches and control passing from main->AUX and AUX->main.

@roughana
Copy link
Contributor Author

roughana commented Jul 23, 2020

Ciderpress was unable to add SAM to the Bejewelled disk image. I'm off on a tangent to provide a reproducible use case to Andy McFadden.
fadden/ciderpress#32
And bingo! a new release of Ciderpress 4.0.4 - Thanks Andy!

@roughana
Copy link
Contributor Author

roughana commented Jul 23, 2020

After the SAM software speech code is put into auxmem, the games that have Mockingboard speech need to be patched to use SAM instead.
TR Prelaunch can apply patches and ProRWTS can load SAM into auxmem - Refer to Berzap prelaunch (thanks Qkumba).
I don’t think I can expect code loaded into auxmem during Init will still be there after any 128k game is run. Do we always reboot after 128k games?

@roughana
Copy link
Contributor Author

TR ProRWTS https://github.com/a2-4am/4cade/blob/master/src/prorwts2.a
The SAM file that gets loaded into auxmem can be enriched to have all the phrases for all the TR games that will be patched with a jump table to copy the needed phrase into the buffer and then call the output routine and then return to main mem.
The in-game patch can then be a JSR to a routine that determines what phrase is needed and pass control to jump table in aux, and a return from aux routine that RTS back to game.

@a2-4am a2-4am added enhancement New feature or request mockingboard Mockingboard-related issues labels Aug 1, 2020
@tomcw
Copy link
Contributor

tomcw commented Apr 4, 2021

Crime Wave (and Spy Strikes Back) both use the older Mockingboard w/Votrax SC-01 speech chip only.
You could patch the games to use the newer SSI263 speech chip instead.

I was curious to hear how this would sound on real SSI263 h/w.

So I dumped the SC-01 phonemes from 7 phrases from 4 games (The Spy Strikes Back, Crime Wave, Crypt of Medea & Berzap!), and then wrote some code to play them back using the SSI263. I used the same 64-phoneme translation table that's in AppleWin, and just do it on-the-fly in my SSI263 interrupt handler.

The attached zip contains 4 recordings (directly from a real Phasor card w/SSI263) at different phoneme rates, the closest to SC-01 speed is the fastest one, "ssi263-A-to-G-attr-20C85CE9.wav". (Those 4 hex numbers are the 4x SSI263 fixed attribute values I used for each phoneme, where the 3rd nibble, eg. $C in this case, is the rate.)

play-sc01-using-ssi263-v0.1.zip

You can try the same code with MAME's Mockingboard which has an SC-01 (use keys 1-7 to playback each SC-01 phrase):
https://github.com/tomcw/play-sc01-using-ssi263/releases/download/v0.1/play-sc01-using-ssi263.dsk

NB. The code/dsk works with Mockingboards with either SC-01 or SSI263 chips (or with AppleWin which supports both chips... although the speech quality is poor).

IMO the results of the SSI263 just playing back on-the-fly translated phonemes is pretty good, ie. the phrases are about as intelligible as MAME's SC-01 (of which I think the author has done an excellent emulation job!)

Again, it's probably a lot of effort to support this old speech chip (SC-01) in just 2 games in the TR collection, but this demonstrates that it would work and be "understandable" speech.

@tomcw
Copy link
Contributor

tomcw commented Apr 7, 2021

@roughana:

Crimewave uses speech during the gameplay ("Danger"). The beginning and end of play sequences ("Crime wave 1", "Game Over", "Enter your initials") would not interfere with gameplay.

Here are some quick notes on Crime Wave, listing all the speech phrases and their addresses:
Crime-Wave-speech-info.txt

btw, phrases $0b, $0c and $0f were so poor (both AppleWin & MAME), that I had to decode them manually (as you can see) to actually understand what the SC01 was trying to say!


FYI, in AppleWin (config=Phasor in slot-4) then I know that the speech phonemes will be written to the 6522's ORB at $C400. So just set a watchpoint on write to $C400 from the debugger: bpmw c400 and start the game (press J). You'll see it stopped at $A245, where it's kicking the SC01 for the "crime wave one" phrase. This is how I quickly found all the code that's in the attached txt file.

If you now clear that watchpoint (bpc) and set a breakpoint at $A209 (bp a209), then you can just modify the X register to playback different phrases, eg. r x=d then g for "you missed".

You can similarly do this in MAME (if you want to try better SC01 emulation).
EG, start MAME with -debug, then from the debug window:

  • bp a209
  • g
  • do x = d

@roughana
Copy link
Contributor Author

roughana commented Jul 8, 2021

Qkumba has added Teleport to the collection which also uses the Votrax. His notes from
Csa2 announcement post:
Teleport supports the Votrax for speech. Press Ctrl-V to toggle.
Once enabled, pause the game and type "DEDICATION" to hear the dedication.
During play, press Ctrl-^ to enable extra keys, then press
Ctrl-U for the E.T. message;
Ctrl-@ for the hint message;
Ctrl-M for a collection of messages from songs and other games like Berzerk.

@roughana
Copy link
Contributor Author

Bobbi Manners' Applecorn project provides a reference for loading code into aux memory, running it and returning back to main memory.
https://github.com/bobbimanners/Applecorn

@roughana
Copy link
Contributor Author

roughana commented Jul 18, 2021

I have completed coding a test application that loads SAM into AUX memory, loads phonemes into AUX memory, receives a pointer to the phrase to be spoken, passes control to AUX, looks up phrase, speaks phrase with SAM, & returns to main memory with stack intact.
Phrases are loaded for Bejeweled and Crime Wave.

The software SAM and hardware SAM APIs are the same (although different entry points, but this can be aligned), so potentially the user could choose which method (soft; hard & SAM Slot) and TR could load the desired SAM driver to support both.

@roughana
Copy link
Contributor Author

roughana commented Jul 21, 2021

I have determined where in memory Bejeweled is calling speech routines from and have crafted some patches for re-directing to SAM instead.
After applying the patches, I can play a full level with the phrases being spoken.
However, it is not fully working, there is a screen redraw issue when starting the next level.

@roughana
Copy link
Contributor Author

roughana commented Jul 26, 2021

This project was the subject of my Hackfest entry for Kansasfest 2021. See my entry video here
https://youtu.be/1VFAwxnx6qQ
See judging here
https://youtu.be/ZMgTxAJbBsc?t=1240
This was awarded third place.

@roughana
Copy link
Contributor Author

I have fixed a couple of bugs in the Bejeweled patch code and now I can play through a whole game with SAM speech.

@roughana
Copy link
Contributor Author

roughana commented Aug 2, 2021

I have relocated and assembled a version of SAM Software that starts on a page boundary and has the input buffer and SAM speak phoneme entry point in the same locations as SAM Hardware version.
The Hardware version needs Phonemes with high bit set. Software version needs Phonemes with high bit clear. I need to resolve this so the interface is exactly the same.

@roughana
Copy link
Contributor Author

I have completed local integration with the Total Replay build for SAM software (by default if 128k and no mockingboard speech) and SAM hardware (user can press number key 1-7 during load and slot will be set to that number). I will submit a pull request.

roughana added a commit to roughana/4cade that referenced this issue Aug 14, 2021
@roughana
Copy link
Contributor Author

roughana commented Feb 26, 2022

Ape Escape also uses SC01 speech. AppleWin >=1.30.2.0 works.

@roughana
Copy link
Contributor Author

roughana commented Apr 25, 2022

SC-01 titles:
Ape Escape * (Hangs if a Mockingboard without an SC-01 is present)
Berzap *
Bouncing Kamungas * (Ctrl-S to Activate Mockingboard)
Crime Wave *
Crypt of Medea (Ctrl-V to Activate Mockingboard)
Microbe
The Spy Strikes Back *
ThunderBombs * (Ctrl-S to Activate Mockingboard)
Zoo Master *
SC-02 titles:
Battle Cruiser *
Bejewelled *
Berzap * (Yes, it can use either)
Black Belt
Mockingboard Classic Adventure (Sweet Micro Systems)
Rescue Raiders *
Willy Byte in the Digital Dimension *

(*) Present on Total Replay

Rob Justice reports that Teleport does not use MB speech at all but supports the Votrax Type'n'Talk which is an external peripheral connected by serial card. The Scott Adams Adventures also support this peripheral.

@roughana
Copy link
Contributor Author

roughana commented Sep 20, 2023

Thread on external (serial) Cricket device and converting MB to cricket:
https://apple2infinitum.slack.com/archives/C1J89GVL4/p1694995081913409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mockingboard Mockingboard-related issues
Projects
None yet
Development

No branches or pull requests

4 participants