Help: How to play PSG music in assembly

Page 1/2
| 2

Par turbor

Champion (416)

Portrait de turbor

11-01-2019, 20:16

After decades I'm finally programming something that should work on any MSX1, with no MSX2 or higher extra's.
The only problem is... I have never ever done something with PSG sounds (except the usual PLAY commands in Basic).
I found in the BIOS routine (http://map.grauw.nl/resources/msxbios.php#msx1bios) the routine STRTMS on address #0099, but no further explanation on how to use it...
Does anybody have any pointers on how to "translate" those PLAY basic commands to something that I can do in ML?

!login ou Inscrivez-vous pour poster

Par wolf_

Ambassador_ (9734)

Portrait de wolf_

11-01-2019, 20:30

Isn't it just a matter of using a timer (50/60 Hz) combined with changing PSG registers? You could even do it in BASIC with INTERVAL, if it weren't so slow. Wink

Par turbor

Champion (416)

Portrait de turbor

11-01-2019, 20:48

Yes, but then I would be writing my own music player. And I know nothing of music, so I still would need help to translate PLAY"CDEF" to the corresponding frequencies and all. So my idea was to make a simple tune by taking some sheetmusic that I could then translate to PLAY commands...

Par wolf_

Ambassador_ (9734)

Portrait de wolf_

11-01-2019, 21:08

How would that not be a music player? I'm sure you could write an MML'ish parser in ASM, but even that would have to be called a music player, no?

Corresponding freqs are actually quite easy, just play all notes in BASIC MML, in ascending order on each octave, while exporting the PSG-registers in openMSX, then you should have a table of the byte-pairs representing the frequencies.

Par turbor

Champion (416)

Portrait de turbor

11-01-2019, 21:52

I was actually hoping that the STRTMS would be the player and that you just needed to feed it the MML string

Quote:

STRTMS
Address : #0099
Function : Tests whether the PLAY statement is being executed as a background
task. If not, begins to execute the PLAY statement
Registers: All

So I was hoping that someone could simply tell me where to write the parameters for said PLAY statement... (simply expecting it to be the "CDEF" string Smile )

Par wimpie3

Master (237)

Portrait de wimpie3

11-01-2019, 22:47

This is something I was expecting to find as well, but it doesn't exist.

Par santiontanon

Paladin (767)

Portrait de santiontanon

12-01-2019, 02:51

Indeed, I do not think that exists. In all my games, I wrote my own music player. You can easily calculate the frequencies corresponding to each note knowing that the "LA" in the center of a piano keyboard has a frequency of 440Hz, and then each semitone up multiplies the frequency by 2^(1/12). Then, to know the value you have to set in the PSG registers, you just divide "111861" (the "master frequency") by the frequency you want to achieve for the note you have to play. The resulting number is what you put in the registers.

What is usually done is to precalculate this with some script (Java/Python/whatever), and put it into a table in your assembler program, so that playing notes is as easy as accessing the corresponding values on that table, and sending it to the PSG. Happy to provide such table already precalculated if you want.

Par wimpie3

Master (237)

Portrait de wimpie3

12-01-2019, 08:20

I think the table can be found in the wiki on this site.

Par ARTRAG

Enlighted (6150)

Portrait de ARTRAG

12-01-2019, 09:31

Use an off the shelf player that comes with a nice tracker to import and edit music
This seems very good, but the msx player needs to be in ram
https://www.msx.org/forum/msx-talk/software/arkos-tracker-2
or use this other
https://bulba.untergrund.net/vortex_e.htm
whose msx player is here
https://www.msx.org/downloads/music/players/pt3-player
or here (integrated with a nice sfx player)
http://www.z80st.es/downloads/code/
You have plenty of choice, look here:
http://www.msxblog.es/wp-content/uploads/2017/10/PLAYERS-MUS...

No need to reinvent the wheel
LOL!

Par Randam

Paladin (901)

Portrait de Randam

12-01-2019, 17:41

ATRAG already named a ton of options, but perhaps MuSICA and Synth Saurus also provide some options for you.

Par santiontanon

Paladin (767)

Portrait de santiontanon

12-01-2019, 20:44

Those are all very good options!!!

I have never used them since I am always very tight on space on my games hahaha. Existing trackers are fairly large (2-3KB), while custom code can be very compact (the music player I did for XSpelunker was about 700 bytes if I remember right), but of course the player was very limited, and totally customized for the songs in that game!

And about the Arkos Tracker needing to be in RAM, Keith just published this tutorial where he modifies it to run from ROM: https://www.youtube.com/watch?v=yDFoi6tO858&feature=youtu.be&a (haven't seen it yet though)

Page 1/2
| 2
My MSX profile