Page 1 of 1

Mega Drive text reader

Posted: Tue Jun 30, 2009 8:18 pm
by Brunni
Hello!
I don't know if this was already done before (probably :P), but here is a small text reader that I did for the Mega Drive. The goal was to experiment software writes to the VDP with a simple app.

Image

It has smooth scrolling, and you can modify the text color and font using format codes.
There is a small "filesystem" which allows you to add your own files to the ROM image.
I'm curious to discuss about performance for this type of application. For now it's coded in C but I don't think I could earn much in assembly as the main (slow) drawing loop is already very clean.
Here is the download link (src + bin + sample): http://brunni.dev-fr.org/dl/smd/text-reader.7z

Posted: Tue Jun 30, 2009 8:44 pm
by Huge
Nice choice for fonts. I almost thought it was HTML before I read your post.

Posted: Wed Jul 01, 2009 3:53 am
by HardWareMan
TrueType font on Megadrive? You used graphic-based printing instead of tile-based (wich more simple and monospaced)? Awesome!

Posted: Wed Jul 01, 2009 10:09 am
by Brunni
Yep thank you ^^
It's a virtual bitmap (like used in 3D games) done by mapping every cell on the map to a unique tile in VRAM. Then when writing a letter I find the right tile to write to.
In fact here is more precisely how it works. The map (38x32) is defined like this:
0 32 64
1 33 65
2 34 66
3 35 67
..........
31 63 95
So for writing, if it's aligned (x mod 8 == 0) and the letter is long enough (at least 8 pixels) it's very easy: you can just write the letter 'h' times (where h is the letter height) because it's vertically contiguous. By using 32 bit arithmetic you can write 8 pixels at once, so work directly with whole lines in a given tile.
If the letter is not aligned you will need to first read what's there and OR it with the letter shifted right, and report the rest of the letter to the following tile. You can avoid rereading from the VRAM by using a buffer that you keep from letter to letter: when you know you are writing to the last tile of a letter (horizontally), you store a copy of what you write to the buffer.
From my calculation 32-bit arithmetic is a good tradeoff compared to the -a lot more- complicated 16-bit arithmetic that would be needed to achieve the same results.
Letters in ROM are thus stored as such: [line 0, pixels 0-7] [line 1, pixels 0-7] ... [line n, pixels 0-7], [line 0, pixels 8-15] , [line 1, pixels 8-15]...
For the color, every letter line, when fetched from ROM, is applied a 32-bit mask which can be for example 0x55555555 to make it use the color n° 5. You can give an effect to the letters like in the title screen by using masks like 0x12344321 (a horizontal gradient).

Posted: Thu Jul 02, 2009 4:07 pm
by TmEE co.(TM)
hehe, this is nice, really great work Brunni :D

Posted: Fri Jul 03, 2009 10:07 pm
by tomaitheous
Nice VWF routine demo :)

Re: Mega Drive text reader

Posted: Sat Jul 04, 2009 12:53 am
by Christuserloeser
This is great! - How about implementing VGM playback into your text reader to allow us to listen to music while reading ?

viewtopic.php?t=442

:D

Posted: Sun Jul 05, 2009 7:02 pm
by Brunni
Thanks ^^ but what is a VWF routine? :oops:
Christuserloeser> No I'm not interested sorry ^^ althrough this project is impressive :D

Posted: Sun Jul 05, 2009 7:07 pm
by Shiru
Variable-Width Font

Posted: Mon Jul 06, 2009 3:41 am
by tomaitheous
Shiru wrote:Variable-Width Font
yup :) As opposed to a FWF (fixed width font) routine. Anyway, looks nice.