Tcl script to make MSX-viewable screenshots

Page 1/2
| 2

By Louthrax

Paragon (1514)

Louthrax's picture

25-08-2016, 14:45

I've started playing a bit with openMSX and Tcl to have a quick way to capture MSX screenshots for games (so not .PNG format, but an MSX specific format).

I've found how to acces the VDP registers (vdpreg) and dump the VRAM (vramdump), that's almost all I need, but I still have some questions:

  • How to get the full path of the inserted ROM, disk or cassette? Ideally, I'd like to have my snapshot file generated in the same directory and with the same base name as the inserted game (for example, "C:\games\msx1\Knightmare (1986)(Konami).rom" and "C:\games\msx1\Knightmare (1986)(Konami).mig").
  • Is it possible to bind a key to an external .tcl script (something like msxsnap.tcl that I could easily edit externally)?
  • Is there an easier way to get the VRAM content (directly in a Tcl variable / array)?
  • Any other recommendations on this?
Login or register to post comments

By Louthrax

Paragon (1514)

Louthrax's picture

25-08-2016, 14:53

Louthrax wrote:

[*]Is it possible to bind a key to an external .tcl script (something like msxsnap.tcl that I could easily edit externally)?
[/list]

Answering to myself: looks like the Tcl "source" command should to the job.

By Louthrax

Paragon (1514)

Louthrax's picture

25-08-2016, 16:26

Louthrax wrote:
  • How to get the full path of the inserted ROM, disk or cassette? Ideally, I'd like to have my snapshot file generated in the same directory and with the same base name as the inserted game (for example, "C:\games\msx1\Knightmare (1986)(Konami).rom" and "C:\games\msx1\Knightmare (1986)(Konami).mig").

Just discovered the guess_title, guess_cassette_title, guess_disk_title and guess_rom_title commands. That's quite close from what I need, just that I'd rather have the "original" (non-guessed) file name (also with the full-path).

EDIT: "diska" and "cassetteplayer" commands are returning full path to the disk and cassette images, just missing something for the ROM files now.

By wouter_

Champion (384)

wouter_'s picture

25-08-2016, 19:24

Louthrax wrote:

...

  • Is there an easier way to get the VRAM content (directly in a Tcl variable / array)?
  • Any other recommendations on this?

To get the content of VRAM into a Tcl variable use 'debug read_block'. See how the 'save_debuggable' proc is implemented (in share/scripts/_save_debuggable.tcl in your openMSX installation directory).

It's relatively easy in Tcl to call other tools (using the 'exec' command). So if you're more familiar with some other scripting language you can implement your stuff in your favourite language and call that from Tcl.

By NYYRIKKI

Enlighted (4614)

NYYRIKKI's picture

25-08-2016, 19:46

Louthrax wrote:

I've started playing a bit with openMSX and Tcl to have a quick way to capture MSX screenshots for games (so not .PNG format, but an MSX specific format).

I don't want to spoil your fun, but I already did it... and it is included in OpenMSX default package...

https://github.com/openMSX/openMSX/blob/master/share/scripts...

By Louthrax

Paragon (1514)

Louthrax's picture

25-08-2016, 20:11

Thanks Wouter & Nyyrikki. Can't say I had too much fun getting into Tcl, the syntax and kind of "abstract" nature (don't know how to explain that...) of the language are weird at first contact... So glad to have something ready-made to start with Smile

I've also found some Tcl sources for LZSS compression (which is not so different from what BitBuster uses).

The only thing I'm missing now is how to get the full-path to the loaded ROM(s).

By Manuel

Ascended (13296)

Manuel's picture

25-08-2016, 22:41

Similar to the other commands: carta/cartb/cartc/etc.

Take a good look at the already installed scripts. There are many many examples! And yes, I also had to get used to Tcl. But mostly to the way the expansion works, so the difference between {, [ and ". That was the most tricky part. Also, on IRC I always get good help (if not from Wouter, then from the people on #tcl on FreeNode.net).

Also keep the Console Command Reference open, it documents what kind of commands (including informational things) are available. Comes with openMSX and is online too, of course.

And don't hesitate to ask Smile

By Louthrax

Paragon (1514)

Louthrax's picture

26-08-2016, 00:30

Manuel wrote:

Similar to the other commands: carta/cartb/cartc/etc.

Take a good look at the already installed scripts. There are many many examples! And yes, I also had to get used to Tcl. But mostly to the way the expansion works, so the difference between {, [ and ". That was the most tricky part. Also, on IRC I always get good help (if not from Wouter, then from the people on #tcl on FreeNode.net).

Also keep the Console Command Reference open, it documents what kind of commands (including informational things) are available. Comes with openMSX and is online too, of course.

And don't hesitate to ask Smile

Daaaaarn, I was trying roma romb romc... Had the Console Command Reference guide opened of course, but just missed that. Thanks Manuel! Have all I need now (just need to resist the temptation to dump eveything in a binary file and have an external C tool called with Tcl's exec as Wouter mentionned.... must... do... everything.. in Tcl... Smile).

By ~mk~

Master (185)

~mk~'s picture

26-08-2016, 01:27

I did something similar using a combination of NYYRIKKI's script in openMSX and some of the awesome features of hap's Meisei emulator to inspect the vram.
Still working on it, one day I'll release it (not here because includes roms).
If anyone wants to beta test, drop me a message Wink

By Vampier

Prophet (2052)

Vampier's picture

27-08-2016, 17:49

I did something similar for MSX translations and created a BMP generator... quite a fun experience.

By Louthrax

Paragon (1514)

Louthrax's picture

29-08-2016, 14:24

I have something working, and can now take MSX viewable screenshots including sprites without artefacts. They are placed in the same directory as the selected ROM, tape or disk file, with extension changed to MIG.

The conversion is done in C for now, and I had to choose between 2 methods depending on the VDP:

  • On MSX 1 (VDP_9918), conversion is done using openMSX VRAM, registers and palette dumps.
  • On MSX 2 (VDP_9938 or VDP_9958), conversion is done using a .PNG screenshot. This allows to support scanline effects, and also make the result file smaller as the sprites are not dumped separately.

I added some extra options to MIF.EXE to crop the openMSX screenshot before conversion (-cropx, -cropy, -cropw, -croph), and also the border color.

MSX2MIG.EXE is a new command line tool that converts openMSX VRAM, registers and palette dumps to a .MIF compressed file.

Below is my screenshot.tcl script:

set romfilename ""
set dskfilename ""
set casfilename ""

regexp {\{(.+)\}} [carta]          -> romfilename
regexp {\{(.+)\}} [diska]          -> dskfilename
regexp {\{(.+)\}} [cassetteplayer] -> casfilename

set romfilename [file rootname $romfilename]
set dskfilename [file rootname $dskfilename]
set casfilename [file rootname $casfilename]

set msxversion [debug read "MSX BIOS with BASIC ROM" 0x2D]
set bordercolor [expr {[vdpreg 7] & 0x0F}]
set tpflag [expr {[vdpreg 8] & 0x20}]

if {$romfilename != ""} {
	set filename $romfilename
} elseif {$dskfilename != "\} \{empty readonly"} {
	set filename $dskfilename
} else {
	set filename $casfilename
}

set migfilename ${filename}.mig
set pngfilename ${filename}.png

save_debuggable "VDP palette" palette

switch [get_screen_mode] {
	"TEXT40" - "TEXT80" - "1" - "2" - "3" {

		save_debuggable "VDP regs" regs
		save_debuggable "VRAM" vram
		
		exec msx2mig $msxversion $migfilename regs vram palette

		file delete regs
		file delete vram
	}
	"4" {
		screenshot -raw $pngfilename
		exec mif $pngfilename -cropx32 -cropy14 -cropw256 -croph212 -sm5 -ct6 -df0 -fm5 -pt1 -cpfpalette -bc$bordercolor -of$migfilename
		file delete $pngfilename
	}
	"5" {
		screenshot -raw $pngfilename
		exec mif $pngfilename -cropx32 -cropy14 -cropw256 -croph212 -sm5 -ct6 -df0 -fm5 -pt1 -cpfpalette -bc$bordercolor -of$migfilename
		file delete $pngfilename
	}
	"6" {
		screenshot -raw $pngfilename -doublesize
		exec mif $pngfilename -cropx64 -cropy28 -cropw512 -croph424 -sm6 -ct6 -df0 -fm5 -pt1 -cpfpalette -bc$bordercolor -of$migfilename
		file delete $pngfilename
	}
	"7" {
		screenshot -raw $pngfilename -doublesize
		exec mif $pngfilename -cropx64 -cropy28 -cropw512 -croph424 -sm7 -ct6 -df0 -fm5 -pt1 -cpfpalette -bc$bordercolor -of$migfilename
		file delete $pngfilename
	}
	"8" {
		screenshot -raw $pngfilename
		exec mif $pngfilename -cropx32 -cropy14 -cropw256 -croph212 -sm8 -ct6 -df0 -fm5 -pt1 -cpfpalette -bc$bordercolor -of$migfilename
		file delete $pngfilename
	}
	"11" {
		screenshot -raw $pngfilename
		exec mif $pngfilename -cropx32 -cropy14 -cropw256 -croph212 -sm10 -ct6 -df0 -fm5 -pt1 -cpfpalette -bc$bordercolor -of$migfilename
		file delete $pngfilename
	}
	"12" {
		screenshot -raw $pngfilename
		exec mif $pngfilename -cropx32 -cropy14 -cropw256 -croph212 -sm12 -ct6 -df0 -fm5 -pt1 -cpfpalette -bc$bordercolor -of$migfilename
		file delete $pngfilename
	}
}

file delete palette
Page 1/2
| 2
My MSX profile