read ebook on nes ?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg » Mon Mar 06, 2006 11:36 pm

I've only skimmed this thread, but had an idea that might help with handling proportional font rendering. If this is being used on a handheld device, you could display everything rotated 90 degrees, so that you view the screen in a vertical orientation like a page. This would make each byte of tile data a vertical strip rather than horizontal, eliminating all the bit shifting when rendering a proportional font. Maybe this has already been discussed.

francois
Posts: 17
Joined: Wed Mar 01, 2006 3:27 pm
Contact:

Post by francois » Tue Mar 07, 2006 3:13 pm

Very intersting discussion. I didn't think it was so complicated to developpe a simple text reader in NES. I thought that the NES language was a kind of Basic, like on the old TV-computer of the 80's (I had a Thomson Mo5...).
I think a vertical orientation could be a good solution too.

User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg » Tue Mar 07, 2006 3:56 pm

A simple BASIC-style reader with a fixed-width font (i.e. 8x8 pixels per character) is easy. One with proportional fonts pushes the NES hardware since it requires so much bitmap storage. If I can figure something out, I'm going to try a quick implementation.

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Tue Mar 07, 2006 8:27 pm

blargg: You might not want to duplicate the work I've already done. This is what I have so far.

User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg » Tue Mar 07, 2006 9:25 pm

I got an almost full-screen bitmap display technique working on my NES using an MMC1 (to provide a second nametable). I ran into a snag near the end of implementation that reduced the active area by 8 pixels, due to not being able to scroll to X=256. I didn't have any 8-pixel-high TrueType fonts for my Mac, so I threw together some random images to use as a test:

Image

That's how it would look on an emulator that didn't do any aspect ratio correction or pixel expansion, which I'm assuming will be the case for a handheld device.

nes_bitmap.nes

The timing is fairly loose, the above is just a general demo that the idea would work.

The pixels are stored in VRAM in a nearly unbroken fashion. The image is rotated 90 degrees clockwise, so you must turn the screen 90 degrees counter-clockwise. If it's a handheld, this puts the joypad at the bottom where you can use it to change pages. Using this orientation, the source image is mapped to VRAM as follows, with VRAM locations specifies as addr.bit:

Code: Select all

   col 0    ...     127    128  ...   239
row ----------------------------------------
 0    0.0   1.0 ... 127.0 4096.0 ... 4207.0
 1    0.1   1.1 ... 127.1 4096.1 ... 4207.1
 2    0.2   1.2 ... 127.2 4096.2 ... 4207.2
 3    0.3   1.3 ... 127.3 4096.3 ... 4207.3
 4    0.4   1.4 ... 127.4 4096.4 ... 4207.4
 5    0.5   1.5 ... 127.5 4096.5 ... 4207.5
 6    0.6   1.6 ... 127.6 4096.6 ... 4207.6
 7    0.7   1.7 ... 127.7 4096.7 ... 4207.7
 8  128.0 129.0 ... 255.0 4224.0 ... 4335.0
 9  128.1 129.1 ... 255.1 4224.1 ... 4335.1
10  128.2 129.2 ... 255.2 4224.2 ... 4335.2
11  128.3 129.3 ... 255.3 4224.3 ... 4335.3
12  128.4 129.4 ... 255.4 4224.4 ... 4335.4
13  128.5 129.5 ... 255.5 4224.5 ... 4335.5
14  128.6 129.6 ... 255.6 4224.6 ... 4335.6
15  128.7 129.7 ... 255.7 4224.7 ... 4335.7
...
255 3968.7    ... 4095.7  8064.7 ... 8176.7
My main aim was to make the VRAM format easy to render an 8-pixel high proportional font to. With the above layout, the only special case is when a character crosses the boundary near the middle of the screen (columns 127 and 128). When building the bitmap, the VRAM address only needs to be reloaded twice per line.

The first 8 palette entries are set as follows: black, white, black, white, black, black, white, white. This allows the attribute bits to select which of the two 8x8 images to use in a character. I filled the nametables with the following tile indicies (now using the normal NES screen orientation), where x was a junk value:

Code: Select all

248 240 ...  8 0 - 240 232 ...  8 0 x
248 240 ...  8 0 - 240 232 ...  8 0 x
249 241 ...  9 1 - 241 233 ...  9 1 x
249 241 ...  9 1 - 241 233 ...  9 1 x
...
255 247 ... 15 7 - 247 239 ... 15 7 x
255 247 ... 15 7 - 247 239 ... 15 7 x
248 240 ...  8 0 - 240 232 ...  8 0 x
248 240 ...  8 0 - 240 232 ...  8 0 x
...
253 245 ... 13 5 - 245 237 ... 13 5 x
253 245 ... 13 5 - 245 237 ... 13 5 x
I enabled vertical mirroring and filled the left screen's attribute table with $00 and the right with $55. In the NMI handler, I toggle the horizontal scroll every 8 rows between 0 and 248. This causes odd rows to use palette #0 and even rows to use palette #1. Just before scanline 128, I switch the background pattern table address to $1000 by writing to PPU $2000. Then the above process repeats as before, using the second pattern table.

The code could be simplified to just change the pattern table address in the middle of the screen and use an attribute table that alternated between palettes #0 and #1 each pair of rows, but this would complicate the VRAM layout. If the original was 01234567, where each number represents 8 bytes of data, this scrambled layout would be 01324576. It would complicate rendering fonts. I haven't written any font rendering yet, so the complication might be simple to deal with. This would solve the problem with horizontal scrolling and eliminate the need a special mapper beyond having CHR RAM. If the font data could be rendered to a temporary 256-byte buffer, then copied to VRAM, this would work fine, but would that slow it down too much? I need to see how slow font rendering is.

Any ideas of working around the scroll problem? Or about what font rendering will entail?

User avatar
Dwedit
Posts: 4236
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit » Tue Mar 07, 2006 10:57 pm

The device's resolution is 640x480 according to this page:
http://www.yaka88.com/Product/PDVD-8088.html
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg » Tue Mar 07, 2006 11:28 pm

I tried the alternate version that only needs to switch pattern tables in the middle of the screen and I think it'll work better. It gives the full 240x256 image and requires only one timed PPU write in the middle of the frame.

nes_bitmap2.nes

It'd be simpler to render the font into a 240-byte temporary buffer than try to write it to VRAM using either way. Copying 32 of these 240-byte buffers to VRAM using a fully unrolled loop would take 240x32x8 clocks per byte = 61440 CPU clocks = ~1/30 second and use only 1.5K of the ROM. So the only advantage of the original layout is that it might shave 1/30 second off changing pages, which is insignificant compared to what the font rendering and decompression time will likely be.

As for font rendering, if there was only one font available, the text could be pre-wrapped by the encoder/compressor program, freeing the reader from handling that. I'm going to try a quick text rendering implementation and see if it's really slow.

UPDATE: Text rendering and wrapping turned out to be plenty fast; it can flip through about 4 pages of text per second. This version lets you read the GNU General Public License by pressing A to go to the next page (13 pages in all). The source text isn't preprocessed in any way, and the reader wraps lines during rendering.

Image

nes_book.nes

This is what it might look like on a device which expanded the NES image to 640x480 using bilinear filtering:

Image

I think I can turn on the left-hand 8 pixel PPU blanking and smoothly scroll text up the screen without any delays (won't know for sure until I try it).

The only requirement of this is CHR RAM (and that seems pretty hard to get around). When the display is enabled, you lose about 50% of the CPU time, but you can otherwise run code that polls the joypad, plays sound, etc. And this has been developed on my NES, even though it'd be pretty impractical to turn your TV on its side. :)

UPDATE 2: Now it smoothly scrolls each page. I think plain switching is fine, but this looks cool (this is just a fun hack, after all). :)

nes_book_scrolling.nes

francois
Posts: 17
Joined: Wed Mar 01, 2006 3:27 pm
Contact:

Post by francois » Wed Mar 08, 2006 5:01 am

I have tested the nes_bitmap2.nes file. On my emulator the picture is like your, but on my PDVD it give me that :


Image

:?:

User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg » Wed Mar 08, 2006 5:35 am

What about nes_book and nes_scrolling_book? Do you know how compatible the NES emulator is in general? As in, name some games that work properly on it.

francois
Posts: 17
Joined: Wed Mar 01, 2006 3:27 pm
Contact:

Post by francois » Wed Mar 08, 2006 7:52 am

I have tested

nes_book : black screen with nothing else
nes_scrolling_book : The PDVD can't launch it at all...

This product is sell with around 300 NES games on a disk. Exemple of games:

1942, 1943, Adventure Island, Bomber man, Super Mario, Tetris, Arkanoid, burger time, Donkey 1 to 3, Exerion, Golf, millipede,othello, pacman, popeye, tennis, iron fighter, majiang 2, china chess, king knight, puzzle, mickey, buggy pop, pyramid, mteal gear, card game, maze, circus, star gate, pacland, baseball, elevator, gunsmoke,route, sasa, lunar ball, gambling, gradius, binary land, arabian, dhexbian.... and more.

I have downloaded some games and demo on internet to test it with my usb key on the PDVD and it's ok.

Game furnished with the PDVD are on a VCD. There is a VCD menu to choose games. On windows, when I open the VCD with explorer I have that :


Image

Games are in this folder :

Image

You can see that game have a .bin extension, I suppose it's for VCD system. I have copied a file on my hard drive, rename the extension with .nes and try to open it with emulator (jnes and nesten) and it doesn't work (can't open).

Informations given by Nesten :

Image

But I can play .nes game and demo downloaded on internet (and nesdev).

User avatar
Dwedit
Posts: 4236
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit » Wed Mar 08, 2006 11:52 am

Does it even run Zelda or Metroid, or other games with no vrom?
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
Quietust
Posts: 1492
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Post by Quietust » Wed Mar 08, 2006 1:46 pm

I suspect the problem may be due to the fact that you aren't disabling rendering on powerup. The demo runs in my emulator on powerup, as well as on a frontloader, but upon performing a soft reset in my emulator (or a top-loader or Famicom) it gets completely garbled.
Last edited by Quietust on Wed Mar 08, 2006 2:14 pm, edited 3 times in total.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Wed Mar 08, 2006 2:06 pm

My reader will not require rotating the screen. Once it is working, it should work on any emulator that can handle mappers similar to UNROM (see list). At least 1943 and Gunsmoke appear to be listed.

MausBoy
Posts: 7
Joined: Thu Jan 05, 2006 8:09 am
Contact:

Post by MausBoy » Wed Mar 08, 2006 2:27 pm

What I'm dying to know here is how you guys plan on setting up your progs to allow for the loading of txt files. From what I'm seeing, the text has to be hardcoded into the .nes file, right? Exactly how useful would that be?

Hey heres a wicked idea for a possible application, a monthly or quarterly nes homebrew news/fanzine published in nes format. I realise the internet is a much more viable and useful publishing medium, but i would happily download and read such a zine for the pure novelty and coolness of it.

Anyone else have any ideas on how this could be used if they release the source?

User avatar
Dwedit
Posts: 4236
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit » Wed Mar 08, 2006 2:31 pm

I'm guessing someone could always make a program that injects one or more text files into a 512k NES ROM image using a PC program.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Post Reply