Teaser: map routines for sdcc_msx w.i.p.

Page 1/3
| 2 | 3

By salutte

Master (138)

salutte's picture

26-12-2019, 19:38

Hi all!

My son came with an idea for a game, and this game needed a map routine, so I'm working on one using sdcc_msx.
I just got it working stable enough for a short demo:


It is based on MSX1 using interlaced colors in mode2. Supports map sizes of 64x128 tiles of 16x16 pixels each.
It supports up to 256 different 16x16 tiles, and up to 512 different 8x8 tiles (256 for even columns, and 256 for odd columns). And currently 4 animated tiles.

Current tiles are inspired on game boy versions of zelda and pokemon. Tiled is used to create the map. The engine supports an interlaced color palette where black is always the background color, enabling enough variety of colors, up to 4 colors per 8x1 line, and black profiled graphics.

Several tricks are implemented to minimize flicker, albeit it is still very visible in some computers/tvs.

Current version is implemented almost entirely in C and not very optimized (hence the visible corruption during scroll), but capabilities and data structures just got frozen, and asm optimization is in progress.

I'm worried about flicker due to interlacing, I tested on a Philips MSX1 and MSX2, a couple emulators, and in a couple TVs, and flicker ranges from almost not noticeable to very distracting...

Login or register to post comments


Enlighted (6694)

ARTRAG's picture

26-12-2019, 21:26

Eager to see more!

By thegeps

Paladin (949)

thegeps's picture

27-12-2019, 09:21

Interesting. Wanna know more Smile

By salutte

Master (138)

salutte's picture

29-12-2019, 11:22

I solved most of the tearing, but still it's mostly C and there is a lot of optimization to be done (specially when scrolling vertically).

There is a ROM if anyone wants to test it:


By santiontanon

Paragon (1569)

santiontanon's picture

30-12-2019, 00:48

Very very cool!!! I've been wanting to do something with interlaced colors for a long time, but haven't gotten around it yet!! In case it helps, I created a quick ROM a few months ago with all possible colors you can get by mixing 2 colors of the original MSX1 palette with a mesh pattern using interlaced colors. If the two colors you mix are similar, flickering is barely even noticeable! ( https://www.dropbox.com/s/w8u15a13su5ujly/interlaced.rom?dl=0 )

Very curious to see how your engine unfolds once you start adding assembler optimization! Again, very cool!

By Manuel

Ascended (18393)

Manuel's picture

30-12-2019, 21:33

Santi: the amount of flickering is surprisingly low indeed Smile At least on openMSX (without using the deflicker option).

By santiontanon

Paragon (1569)

santiontanon's picture

30-12-2019, 23:01

I know! I was shocked! So, as soon as I finish a couple of projects I am currently working on, I want to explore this some more. So, I am very interested to see what can salutte achieve Smile

By Grauw

Ascended (10313)

Grauw's picture

30-12-2019, 23:16

Those are some nice NES-like colours for MSX1!

By salutte

Master (138)

salutte's picture

30-12-2019, 23:45

Thanks for the support!

santi: thanks for the rom! It's very practical to see how different MSXs and screens react to interlacing!

Interlaced colors are very tricky, and the msx palette is terrible for this purpose because most colors are very bright. Furthermore, most models (i.e. openmsx) do not consider gamma correction when simulating deflicker. I.e., when interlacing 255 and 0, using the sRGB standardone must expect a 187!

image from:

the problem is that: if we limit ourselves to mix similar colors, our resulting image will have very low contrast.
Hence I decided to go bold and use black always as a background color, thus increasing the contrast.
I prepared this palette for gimp:

I calculated it considering sRGB, and a CRT screen. It is a subset of all possible MSX1 interlaced options, but has the property that black is always the background color. I plan to use it in the future to draw black silouettes around sprites without using sprites. When drawing the graphics, each 8x1 line can choose between black (top left corner, one primary color (left column), another primary color (top row), and its combination (its intersection).

To minimize flicker I use two techniques. If a 8x1 tile uses 2 different primary colors, I swap the color maps at each line. If the 8x1 tile uses only one primary color (i.e., water), I can use a pixel-wise pattern. However, at the moment I only optimize for flickering on static tiles, and this results on ugly artifacts when scrolling.

I was slow on updates due to the flu... I couldn't think straight, but I could program! I migrated the key parts to assembler, and pipelined better the different stages. As far as I know, the tearing is all gone, and the scrolling speed has increased by a factor of 2x.



By santiontanon

Paragon (1569)

santiontanon's picture

31-12-2019, 11:02

Nice update! I would say that the level of flicker is acceptable everywhere, except in those red paths that connect the houses in the bottom-right part of the map. So, maybe a different solution will have to be found for that. But the rest looks really good! It's hard to believe it's an MSX1!

By Juan Luis

Master (138)

Juan Luis's picture

31-12-2019, 11:39

I'm also eager to see more. Wink

Page 1/3
| 2 | 3