Kevin Vance - Displaying textmode on the NDS

Entries | Archive | Friends | Friends' Friends | User Info

01:45 am

Displaying textmode on the NDS

Wednesday, August 22nd, 2007
Previous Entry Share Next Entry
Tags, ,

screenshot 1

screenshot 2

Further pursuing the idea of running MegaZeux on the DS, I wrote a routine to render 8x14 character textmode to one of the screens. I managed to get 52 FPS on my first try, which could be good enough. MegaZeux is low motion enough that probably less than 20 FPS would be acceptable.

The reason why it's not straightforward to scale down a 640x350 textmode screen is that the DS limits the size of an "extended rotation background" (one with per-pixel addressing) to 512x512 pixels. My solution was to plot one pixel horizontally for every two pixels in the current character, squeezing the screen down to 320x350. I can use a simple map from the two-pixel bitmap to the one-pixel result:

BitmapPlot
00Background color
01BG/FG blend
10BG/FG blend
11Foreground color

That just leaves me with the problem of calculating a 50/50 blend for many of the pixels. As luck would have it, the MZX palette is 16 colors but the NDS palette is 256 colors—more than enough to precalculate a blend for every color. And it's EXACTLY enough to do it naïvely: result = 16*color1 + color2.

It turns out that this method runs very well on the hardware. I was expecting 1/10 of the speed that I got. Add in some hardware scaling enhancement tricks, and the result is not bad looking. Characters are squished to about 3x7 pixels, which makes text reading a challenge, but not impossible. For real game playing, I'd probably ape ScummVM and have both a zoomed-out and a zoomed-in screen. The zoomed-in screen could be accomplished using sprites at 1:1.

There are a few caveats to this method. The zoomed screen uses 256K of VRAM, which are both of your 128K main screen banks if you want to use 128K extended rotation and sprite banks on the subscreen. The zoomed screen can't run on the subscreen at all. There are also some "checkerboarding" artifacts visible. If you've ever taken a screenshot of a ZZT or MZX game and scaled it down with a poor quality scaler, you've seen this before. But I'm pretty sure abandoning the hardware scaler completely would destroy the performance.

I am pleased :)

Link )Reply )

Comments
[User Picture]From: myth
2007-08-22 07:03 am (UTC)
How can you post something like this without posting a screenshot?

How.
(Reply) (Thread)
[User Picture]From: kvance
2007-08-22 07:22 am (UTC)
Fair enough. My camera isn't good enough to capture this, and a screenshot is inaccurate because I use flicker. Never the less, I have made a fair approximation using the GIMP, and added it to my post.
(Reply) (Parent) (Thread)
[User Picture]From: myth
2007-08-22 12:32 pm (UTC)
Nice. Now we're talking.
(Reply) (Parent) (Thread)
[User Picture]From: kvance
2007-08-22 07:24 am (UTC)
Trivia: I originally used the Software Visions distribution BBS ANSI, but switched to a larger ANSI when I wanted to test out scrolling.
(Reply) (Parent) (Thread)