KSS Extraction

Page 1/2
| 2

By niek

Expert (112)

niek's picture

02-06-2016, 00:32

Hello all,

I've been learning about the internals of the KSS format lately, and afaik there's no guide on how to get the music extracted. I know now why that is difficult, but finding this out and putting things together took me a while. So I'm on a quest to get Comic Bakery in a KSS file! That probably exists already, but hey, I'm not downloading it. Smile If I know everything, I will write a guide.

Currently I know about all the fields in the KSS header. I've been using z80dasm to disassemble some KSS & ROM files, and what I've learned that's it's doable to just include the whole game rom in the KSS. Magical Tree.kss uses this. However, there's also Pippols.kss, which seems to include half the game with a few less jumps and calls. And Circus Charley is a nice one if you look at it from a programmers view; only 1500 bytes that include everything.

Libkss will only emulate sound related stuff so the 'whole rom' approach is not very elegant but has a chance of working I guess. At least you don't need to know a lot about Z80 programming, which I don't.

I've learned that 0xa0 is a call used in players, as well 0x90, 0x93 etc registers. I've been told it's also common to look at the hooks fd9f and fd9a for players. But all available KSS files have a player address which start something I don't understand. Smile So I've been trying but no clue as of yet.

I will continue to learn a bit about Z80 programming, maybe I can find players. But, first I need the load address, and that's my current issue, how would I know the load address, it differs a lot between all the KSS files. I've been using the debugger from openMSX running Pippols to do a memory dump, and I can find the Pippols code in there, but it's starting on a different address then the working KSS file has. And the Pippols.kss can work with the real game rom, I've tried that using the values in the header with the rom file. How is it possible the memory addresses differ, but the calls in the code go to the same address?

z80dasm kss command (using load address + 1): z80dasm -a -g0x3FF1 pippols.kss.

Some code of the kss dump:
ld a,005h ;4952
call 04039h ;4954
inc de ;4957
djnz $-27 ;4958
ld a,(0e012h) ;495a

The same code from the memory dump:
ld a,005h ;4a41
call 04039h ;4a43
inc de ;4a46
djnz $-27 ;4a47
ld a,(0e012h) ;4a49

Login or register to post comments

By giangiacomo.zaffini

Champion (267)

giangiacomo.zaffini's picture

02-06-2016, 13:08

Hi niek,
I'm sorry I cannot help because You far above me in this topic. I'm stuck trying to make a kss player on linux/Ubuntu.

I guess everything to be learnt about KSS should be in msx_plug for WinAmp Kobaryn player, since I think kss is common format, and MGS BGM OPX MPK MBM formats are transcoded to KSS and then re-played.

Anyways Naruto has built a ROM with its songs and gave instruction to build a kss compilation with it.

Link to Naruto page, click on MSX - FAN special disc to get files.

In the same page there are other examples or pure music ROM (Yoshida and FM-BIOS TEST) and also a converter from MPK MGS to KSS format.

By niek

Expert (112)

niek's picture

02-06-2016, 22:23

Hello,

Thank you for the link, I will look into it!

I'm aware of the msx_plug, it's based on libkss. I've been working on a website using libkss, however it's compiled to Javascript by Emscripten. It started out as just using existing stuff, but since then I changed a lot. Have a look at this forum topic; .

What do you mean with making a kss player on Linux? There's audio overload, that should just work on Linux, haven't tested it. If you want to do it yourself you can compile libkss yourself. However then you have a library that can convert KSS to WAV, you 'just' need to at the audio part. Maybe you can see how they did it with GME, if memory serves me right; in the source is a complete SDL based player included, didn't test that either.

By giangiacomo.zaffini

Champion (267)

giangiacomo.zaffini's picture

03-06-2016, 03:11

Hi niek,
in facts I did just used that libkss implementation that compiles natively on my GNU/Linux/Ubuntu machine.

You can look at up-today porting of samples_win32.c module, which is a command line KSS player on Windows by Brezza himself, if You download here a beta version with sources and all files modified by me (I know it is not cleaned but it works)
Here samples_win32.c had become samples_linux.c.
It can play KSS MGS OPX BGM MPK and MBM, like a plain in_msx/msx_plug plug-in for WinAmp/Kobarin.

By niek

Expert (112)

niek's picture

03-06-2016, 13:30

Sorry,

I didn't see you're the same person posting messages in the Javascript player topic. Do you have a new profile picture? Smile

Nice that you got it working!

By niek

Expert (112)

niek's picture

04-06-2016, 12:41

I'm making a little progress here.

- The offset thing was my bad; z80dasm has an automatic offset of 0x100h and I forgot to substract the first 0x10h bytes from the KSS header
- I created a little script that disassembles the kss file with auto labeling, the correct offsets and it adds a remark at the addresses where the init and the player are pointed at in the KSS header.
- Many KSS files from the early Konami roms use a similar technique; in the KSS file add 0x10h bytes after the KSS header and before the entire ROM file. In this part a call is made to the PSG initialisation stuff in the rom with a push af before and pop af after an then a jp.
- However, I tried what happened without the jp, because I figured that the KSS player will ignore everything non-music related, so the whole game initialisation stuff does nothing, that worked with at least at two games.
- The PSG initialisation stuff usually uses a jp or call to 0x93, sometimes a out (0x0ah).
- So that's kinda doable. Smile
- The player is a different story however to me at least. They don't look similar at all, it's possible the player address used in the KSS files is not perfect, maybe it's pointing just somewhere in the game routine and eventually it'll reach the audio stuff?
- I tried changing the address the player routine should be at, based on (very) basic analysis of the code, and that worked sometimes. Wink

To be continued... FMPAC stuff for example. Should be something like out 7C and 7D I guess, or are there more options?

I wonder if it's possible to make for example a memory dump of the active ANMA Relax demo, and then find the player and music in it. Might be possible that some of the code required initialising everything has been overwritten during the process? Don't know if this happens often in code?

By giangiacomo.zaffini

Champion (267)

giangiacomo.zaffini's picture

06-06-2016, 22:53

Hi niek,
I guess KSS can contain different log information formats (suited for MSX, but also for SEGA Master System and SEGA GameGear): for instance KSSX, which I do not like so much because in_msx/libkss player cannot play it, or KSCC, which is far better, so not every KSS is the same. If You compare original ROM and KSS file, take note of which log information format is used.

Then what about PSG: I don't know much but I guess You're right and MAIN BIOS calls are, among others
* GICINI (0090H/MAIN) .................. PSG initialization
Input: ---
Output: ---
Function: initializes PSG registers and does the initial settings of
the work area in which PLAY statement of BASIC is executed.
Each register of PSG is set to the value as shown in
Figure 5.9.
* WRTPSG (0093H/MAIN) ................. writing data in PSG registers
Input: A <-- PSG register number
E <-- data to be written
Output: ---
Function: writes the contents of the E register in the PSG register
whose number is specified by the A register.
* RDPSG (0096H/MAIN) .................. reading PSG register data
Input: A <-- PSG register number
Output: A <-- contents of the specified register
Function: reads the contents of PSG register whose number is specified
by the A register and stores the value in the A register.

Finally about MSX-MUSIC : MSX-MUSIC I/O ports are
7CH write address register
7DH write data register
For the case of Panamusement FM PAC, same resources can also be addressed with memory addresses 7FF4H and 7FF5H.

By nitrofurano

Champion (301)

nitrofurano's picture

07-06-2016, 19:13

converting .kss to .vgm would be really great, if possible

By giangiacomo.zaffini

Champion (267)

giangiacomo.zaffini's picture

08-06-2016, 17:43

@ nitrofurano: such a tool should better exist in some form since quite a number of MSX games soundtracks (mostly Konami's ones) can be found also on .VGM format (and bridge format could have been .KSS).
Otherwise one can use Grauw's TCL script for opemMSX and have brand new .VGMs as something happens on openMSX (for instance one can use a player such as MGSEL od MultiPlayer-X).

Bonus:
KSS (KSCC format) explained link

By niek

Expert (112)

niek's picture

11-06-2016, 21:38

@nitrofurano: conversion is hard, considering the complete different approach of storing and playing the audio files. But, there's a way already I guess, at least for PSG/FMPAC. Since there's a KSS player for MSX, this can run in OpenMSX as well. Then you could use the script from Grauw giangiacomo.zaffini is talking about on OpenMSX. This script supports PSG and FMPAC. Depending on the quality of the m3u file with the KSS file your 'converting' process will be easy or hard. :) Also: a little bit more info about the Grauw tool.

vgmrips.net already has some SCC VGM packs too, don't know how those were created, maybe using MESS? This seems to have a VGM ripper as well.. have to investigate...

By giangiacomo.zaffini

Champion (267)

giangiacomo.zaffini's picture

12-06-2016, 15:21

Hi,
just to inform that I committed on GitHub this command line version of KSS/OPX/MGS/BGM/MBM player that can (after my preliminary tests) run on GNU/Linux/Ubuntu. On Windws side it is not needed but on Linux I don't think such a thing exist yet. It is a fork of official repository.

Then I tried to play KSS files with KSS play by NYYRIKKI on openMSX 0.11.0 configured as MSX turboR + ram4mb, and application starts but it doesn't play anything. Anyway I think that KSS play by NYYRIKKI + tcl script can be a viable KSS -> VGM converter.
It need just a tweak. Wink

Page 1/2
| 2