Coranac

tonc 1.4 preview

2008-05-26 – 22:54 | .

I'm close to releasing the latest (and probably last; this really has gone on long enough) version of Tonc. As a preview, I'm releasing the PDF a little early in the hope that someone may take a look and offer some feedback before the official release (aw, c'mon, it's only 400 pages).

The changes mostly relate to the new Tonc Text Engine, a text system for all occasions. There's a new chapter describing how TTE works, how to write general character printers for (almost) for arbitrary sized fonts and every type of graphics, and a few other things. It's fairly long and could use sanity checking from someone else.

Also, many of the older demos now use TTE for their text as well. As a result they look cleaner and prettier, but it's possible there are some left-overs from older versions. So have at it.

Surface drawing routines.

2008-05-14 – 18:19 | .

I've been building a basic interface for dealing with graphic surfaces lately. I already had most of the routines for 16bpp and 8bpp bitmaps in older Toncs, but but their use was still somewhat awkward because you had to provide some details of the destination manually; most notably a base pointer and the pitch. This got more than a little annoying, especially when trying to make blitters as well. So I made some changes.


typedef struct TSurface
{
    u8  *data;      //!< Surface data pointer.
    u32 pitch;      //!< Scanline pitch in bytes (PONDER: alignment?).
    u16 width;      //!< Image width in pixels. 
    u16 height;     //!< Image width in pixels.
    u8  bpp;        //!< Bits per pixel.
    u8  type;       //!< Surface type (not used that much).
    u16 palSize;    //!< Number of colors.
    u16 *palData;   //!< Pointer to palette.
} TSurface;

I've rebuilt the routines around a surface description struct called TSurface (see above). This way, I can just initialize the surface somewhere and just pass the pointer to that surface around. There are a number of different kinds of surfaces. The most important ones are these three:

  • bmp16. 16bpp bitmap surfaces.
  • bmp8. 8bpp bitmap surfaces.
  • chr4c. 4bpp tiled surfaces, in column-major order (i.e., tile 1 is under tile 0 instead of to the right). Column-major order may seem strange, but it actually simplifies the code considerably. There is also a chr4r mode for normal, row-major tiling, but that's unfinished and will probably remain so.
surface.gba movie
Demonstrating surface routines for 4bpp tiles.

For each of these three, I have the most important rendering functions: plotting pixels, lines, rectangles and blits. Yes, blits too. Even for chr4c-mode. There are routines for frames (empty rectangles) and floodfill as well. The functions have a uniform interface with respect to surface-type, so switching between them should be easy were it necessary. There are also tables with function pointers to these routines, so by using those you need not really care about the details of the surface after its creation. I'll probably add a pointer to such a table in TSurface in the future.


Linkies


The image on the right is the result of the following routine. Turret pic semi-knowingly provided by Kawa.

void test_surface_procs(const TSurface *src, TSurface *dst,
    const TSurfaceProcTab *procs, u16 colors[])
{
    // Init object text
    tte_init_obj(&oam_mem[127], ATTR0_TALL, ATTR1_SIZE_8, 512,
        CLR_YELLOW, 0, &vwf_default, NULL);
    tte_init_con();
    tte_set_margins(8, 140, 160, 152);

    // And go!
    tte_printf("#{es;P}%s surface primitives#{w:60}", procs->name);

    tte_printf("#{es;P}Rect#{w:20}");
    procs->rect(dst, 20, 20, 100, 100, colors[0]);

    tte_printf("#{w:30;es;P}Frame#{w:20}");
    procs->frame(dst, 21, 21, 99, 99, colors[1]);

    tte_printf("#{w:30;es;P}Hlines#{w:20}");

    procs->hline(dst, 23, 23, 96, colors[2]);
    procs->hline(dst, 23, 96, 96, colors[2]);

    tte_printf("#{w:30;es;P}Vlines#{w:20}");
    procs->vline(dst, 23, 25, 94, colors[3]);
    procs->vline(dst, 96, 25, 94, colors[3]);

    tte_printf("#{w:30;es;P}Lines#{w:20}");
    procs->line(dst, 25, 25, 94, 40, colors[4]);
    procs->line(dst, 94, 25, 79, 94, colors[4]);
    procs->line(dst, 94, 94, 25, 79, colors[4]);
    procs->line(dst, 25, 94, 40, 25, colors[4]);

    tte_printf("#{w:30;es;P}Full blit#{w:20}");
    procs->blit(dst, 120, 16, src->width, src->height, src, 0, 0);

    tte_printf("#{w:30;es;P}Partial blit#{w:20}");
    procs->blit(dst, 40, 40, 40, 40, src, 12, 8);

    tte_printf("#{w:30;es;P}Floodfill#{w:20}");
    procs->flood(dst, 40, 32, colors[5]);
    tte_printf("#{w:30;es;P}Again !#{w:20}");
    procs->flood(dst, 40, 32, colors[6]);

    tte_printf("#{w:30;es;P;w:30}Ta-dah!!!#{w:20}");

    key_wait_till_hit(KEY_ANY);
}

// Test 4bpp tiled, column-major surfaces
void test_chr4c_procs()
{
    TSurface turret, dst;

    // Init turret for blitting.
    srf_init(&turret, SRF_CHR4C, turretChr4cTiles, 128, 128, 4, NULL);

    // Init destination surface
    srf_init(&dst, SRF_CHR4C, tile_mem[0], 240, 160, 4, pal_bg_mem);
    schr4c_prep_map(&dst, se_mem[31], 0);
    GRIT_CPY(pal_bg_mem, turretChr4cPal);

    // Set video stuff
    REG_DISPCNT= DCNT_MODE0 | DCNT_BG2 | DCNT_OBJ | DCNT_OBJ_1D;
    REG_BG2CNT= BG_CBB(0)|BG_SBB(31);

    u16 colors[8]= { 6, 13, 1, 14, 15, 0, 14, 0 };

    // Run internal tester
    test_surface_procs(&turret, &dst, &chr4c_tab, colors);
}

Expelled recap

2008-05-13 – 16:19 | .

So this Expelled movie has been out for a couple of weeks now. To my surprise, it's been doing rather well. It's running in about 400 theaters right now, which I guess is a lot (but then I'm from a puny little country so I could be wrong). It's also got an amazing rating of 9 on rotten tomatoes.

Oh, wait. That's not 9 out of 10; that's 9 out of 100. Wow. That's … that's just … wow.

So yeah, this thing is going down so hard it could go straight through the planet. A score of 9%. That should qualify as “Epic Fail” in anyone's book Anyone sane, anyway. As for the theater count, the guys at Panda's Thumb have been tracking the numbers; it started with just over 1000 on April 18th and is now down to 400. It'll probably disappear completely in a week or two.

Away from the silver screen, the producers and Ben Stein have been doing interviews left and right and apparently making complete asses of themselves. I've seen some videos of Stein that are just two-hands facepalmingly stupid. One of the things he's keen on mentioning is how Darwinism doesn't explain the origins of life or gravity or where the universe came from. The theory of evolution is not and will never be about those things, so why this counts as a mark against the theory I don't know. It's like to arguing that metallurgy doesn't explain last week's weather, therefore it's bogus. Simply using this line of reasoning hows that he really doesn't know what he's talking about. That, or he's deliberately misleading everyone, which is also a real possibility.

The real moment of inanity, however, comes from an interview at TBN where he made this immortal statement (emphasis mine):

Love of God and compassion and empathy leads you to a very glorious place, and science leads you to killing people.

O_O. Lolwut ?!?

Yes, he actually said that, and in all earnest too, apparently. You can see it (and a response to it) in Thunderfoot's latest Why do people laugh at creationists video. The original interview can be found here as well. This is what as also earned him the dubious virtue of second place for MSNBC's Worst Person in the World.

Right now, I am this close to believing this is actually all part of a massive hoax. With the ever-growing list of stupidities, I find it harder and harder to believe they're serious.


And now for something completely related: the infamous Beware the believers video. This *wonderful* clip was released anonymously in the end of March and has been a favorite in sciency circles since. There has been a lively debate about its origins. Because it clearly is caricaturing the atheists depicted in the clip (“if I was dyslexic, I’d even hate dog too”. Hehehehe), one group believed the Expelled group were behind it. On the other hand, it was well done and extremely funny. Since the creationists have a long track record of shoddy craftsmanship and witlessness (the Expelled movie itself is a good example of this), many others felt it could not come from them.

About a month later, the answer came: it was done by Michael Edmondson, as a contract job for the producers of Expelled. So yes, it did come from their camp after all. That said, Edmonson isn't affiliated with them that much. I've read that the producers' intent was for it to be viral advertising for the movie. I don't think that worked out too well, though, what with it being embraced by the atheist side as one of the pieces of Internet Win of this year.

Read the thread on pharyngula for extra details. Edmonson himself also makes an appearance in the comments, so you get it straight from the horse's mouth. Simon Owens also has an interview with him at bloggasm.com, so check that out as well for even more details.

Lastly, to Michael Edmonson and Matt Chandler (who did the lyrics): thank you for the hilarious video. We will watch your career with great interest.

Grit 0.8.1

2008-05-12 – 16:37 | .

Grit 0.8.1 is out now. I've made three somewhat small changes here. First, there was some trouble with shared palettes/tiles if there was no -O or -S option. “Trouble”, as in segmentation fault. This should now be fixed.

I've also reformatted the include guards from __FOO__ to GRIT_FOO_H. GCC uses that format for internal #defines and it is very territorial about such matters. So, say, when you have elf.png, GCC gets cranky because that would hide its own __ELF__, and guess who wins out there? Again, thanks for pointing these things out, Quirky.

The last item is the addition of column-major tiling. This can be useful for horizontal scrolling games, since the data or the columns are all adjacent instead of a whole scanline apart. A second benefit of this mode is that rendering to tiles is made considerably easier (and a little bit faster too).

In case you hadn't noticed yet, I've also put the manual on-line. This shows the basic options for grit and wingrit, and now there's a description of how to use it in makefiles as well. This includes how the building the grit-demo project works. This one's quite interesting, so please check it out.


Project link.

Artsy fartsy

2008-04-10 – 23:20 | .

I've been working on a few functions for rendering onto tiles recently. Yesterday was the turn of a rectangle filler. The traditional routine of double-looping over a pixel-plotter would be slow in every case, but for tiled surfaces it's positively evil, so I made something that divides the rectangle in 5 areas and fills them using by words or better. Yes, this is a little tricky but I figured the speed increase of up to 300 would be worth it.

For testing purposes, I filled each region with a different color so that ifwhen something went wrong, I could easily identify the problem. When playing around with the test app, I more or less accidentally came up with this:

accidental mondriaan

Hmmm ... Mondriaany.

Anyway, it seems that this thing went alright. So now tonclib also has plot, hline, vline, line, rect and frame functions for 4bpp tiled modes. No, there's no blitting yet. In anyone wants that, I'm going to insist on some mental hazard pay.

grit 0.8

2008-04-04 – 18:51 | .

It's time for another Grit release. There are three important changes compared to previous versions.

First, palette merging is in (and there was much rejoicing). If you use the -pS option, a shared palette will be created and used in the graphics. Note that I still think palette merging should be performed on the images themselves and not in the output phase. If anyone's interested, I do have a small app that can do just this.

Another big change is that handling of shared data is now done correctly. The previous version required two runs for this: one for the non-shared stuff, and then another for the tileset itself. You also had to take care to disable the shared item for the individual runs, otherwise the (useless) intermediates would be exported as well. Grit 0.8 fixes all this. You can provide multiple images and request a shared tileset and/or palette (with -pS, -gS, or -fx) and it should work right. Grit will export the individual parts first and save exporting the shared data for the end. For example, if you have 5 files to be converted to maps with a shared tileset, you'll get 5 maps, and one tileset and palette (instead of 5 of each like 0.7 did). You can tune the shared output names with -S and -O (uppercase s and o) if necessary.

Thirdly, there is a new binary file-type available. I'm calling it GRF, for Grit RIFF File. This places the graphics, maps and palette in RIFF chunks. The idea behind this was to have related data in a single file instead of three different binaries. The chunked data-format also allows easier extension and it's easy to make a generic loader for it too. For details (including such a loader), see the the manual. The -ftr option creates a GRF file, and you can also create GRF-formatted C/asm arrays using -fr.

I've also added something I like to call ‘fake’ compression, -Z0 (Z zero). This adds a header word to the data similar to the ones that the compressed data have. This consistency of data-formats is essential for the generic data-loader.


As I mentioned before, there is also a proper demo project to show how you can use grit and its various options. Take note of how it uses a separate makefile to prepare the graphics. This way you can keep the main makefile pretty clean and it makes it easier to insert customized conversion rules. Note: to build the demo project, make sure GRIT points to the updated binary.


Linkies

Expelled : No intelligence allowed! Give them a hearty round of scorn and ridicule, folks.


OK, perhaps a bit of backstory is in order here.

There's this strange thing going on in the USA known as the Creation-evolution controversy. In a nutshell, on one side you have the Theory of Evolution, accepted by all but a fraction of the scientists and supported by evidence from multiple fields; and on the other you have groups (usually motivated by their religion or ignorance and frequently both) screaming “nuh-uh!”, backed up by arguments ranging from utterly insane, to fabrications, misunderstandings, red herrings, and “I dunno, Magic Man dun it”. No, I'm not embellishing here: there are long lists of creationists claims that often make no sense at all, but are still used even after being debunked decades ago. As an example how silly these can be, consider the Banana argument. And no, this is not a parody; they're absolutely serious.

After the scientists got so fed up by the constant misrepresentations that they won't even debate anymore and several defeats in courts, the creationists came up with a new strategy: Intelligent Design (ID). They've been quite clever with this, actually. For one, they're leaving the Bible out of it and claiming that life's complexity can only come about through an intelligent, yet unnamed (wink, wink), designer. They also claim that all they want is a fair hearing; that the scientists are being mean with their insistence on evidence and refusal to accept bogus reasoning.


Enter Expelled. You'd have to read the wikipedia page for details, but the idea behind the movie is to highlight this repression by scientists; that the evolutionists are actively ‘expelling’ people critical of evolution. It so happens that they've interviewed a number of evolutionary biologists (under false pretenses) for their views on the subject. This is now widely regarded as a bad move.

You see, one of them happened to be PZ Myers, a vocal critic of creationism and other irrationality on his blog pharyngula. You can see how hostile he is in this video (I'd point to the Expelled trailers with the interview, but they pulled it). Ever since the interview, he and other science-bloggers have been keeping an eye on the movie, pointing out flaws in the producers' arguments whenever they went public with anything.

And now it gets interesting. About two weeks ago, there was a screening of the movie in Minneapolis. He reserved a place via their website, went to the theatre … but was barred from entering. To spell it out: here's a movie accusing evolutionists of expelling their critics, expelling their critics. And then lying about it afterwards! Repeatedly! Seriously, you just can't make this stuff up.

Naturally, this is now all over the blogosphere. The original account has well over 1600 comments. Many other science bloggers have commented on it as well. Greg Laden's blog has a list of over 100 links, including to stories from the NY Times and Salon. Another interesting detail is that Myers was accompanied by Richard Dawkins (yes, that Richard Dawkins), who did get in. The two had a nice little discussion afterwards, which can be seen here.


Other interesting links


Testing latex

2008-02-22 – 19:00 | .

No, not the rubber stuff; the math stuff. According to the WP codex, it should be as simple as this:

$latex i\hbar\frac{\partial}{\partial t}\left|\Psi(t)\right>=H\left|\Psi(t)\right>$

OK, so that doesn't work :\. Ah right, that's just for when you have the blog under the wordpress.org itself. Right … mimetex then.

* finds wp-latexrender.zip here.

* looks for install procedure.

* looks for clear install procedure.

* tries the install anyway.

* reads the mimetex.php in full because while everyone says to update the path directories, it's unclear what to set them to especially as they seem to be double.

* sighs and rewrites the whole function because the variables and how they are used are … silly.


Right. How about this then: "[tex]x^2+y^2[/tex]"?

x^2+y^2

Yaaay! :D. And now for some more interesting forms:

E = mc^2 \label{clever}

OK, so apparently I can't put the labels into mimetex. Let's see what else will and will not work ...

\lim_{n \to \infty}\sum_{k=1}^n \frac{1}{k^2} = \frac{\pi^2}{6}

Okay ... so the default version doesn't like newlines either. So let's tweak the formula so that all whitespace (and repeated white) it replaced by a single space ... '/\s+/ /g' should do the trick.

\LARGE\tilde y=\left\{ {\ddot x\text{ if $\vec x$ odd}\atop\hat{\,\bar x+1}\text{ if even}}\right.
\small\hspace{10}\unitlength{.75} \picture(120,220){~(60,200){\circle(120,40)}~(0,20){\line(0,180)} (5,189;0,-30){\pict(110,20){(c20,10;70;2){ \pict(40,20){(20,10){\circle(40,20)}(c10,10)+(c30,10)-}}~}~} (119,20){\line(0,180)}~(60,20){\circle(120,40;34)}}
\bold C( \theta, \phi) = \bold R_y(\phi) \cdot \bold R_x(\theta) = \begin{bmatrix} \cos (\phi) &amp; \sin(\phi) \sin(\theta) &amp; -\sin(\phi) \cos(\theta)\\ 0 &amp; \cos(\theta) &amp; \sin(\theta) \\ \sin(\phi) &amp; -\cos(\phi)\sin(\theta) &amp; \cos(\phi)\sin(\theta) \end{bmatrix}

And to try some inline stuff: m \vec{a} = -k \vec{x} . Or maybe m \vec{a} = -k \vec{x} for something a little smaller. Yay, that works as well.

Anyway, for anyone who also wants math on their site, you can get mimetex from from http://www.forkosh.com/mimetex.html. Although the site starts with the source, there are precompiled binaries in the back somewhere. I would recommend rewriting mimetex.php, though: I found it somewhat tricky to get it working. It relies on 4 paths, but it doesn't exactly say what they were supposed to represent or what they should be set to; when I tried it locally the only way to get them to work was to do stuff that had little relation to the fill-in-the-blanks parts of the paths.

It doesn't like whitespace either in or around the formula, so removing that can be useful; so is feeding the through rawurlencode() if you want to put it into the url: HTMLTidy really doesn't like all the backslashes and stuff in the url. Adding options to the [tex] tag is also a good idea (like size; see above). And what's especially useful is a preview mode that doesn't render to a file. That way you won't be left with hundreds of little temporary bitmaps for all the failed variants. (I suppose I could give you mine, but it's not finished yet.)

Lastly, if you're new to TeX, consider using this site as an editor. There is a larger manual on the mimetex maintainer's site, but this little tool is very useful.

Via coding horror, I stumbled upon a simply wonderful talk by Herb Sutter about various performance issues like how much operations cost. It also discusses how memory, latency and machine architecture can affect that cost how this has changed over the years. You can find the slides and a video of the presentation at http://nwcpp.org/Meetings/2007/09.html.

Be prepared for a total geek-out. This is highly technical (and awesome, but that's bordering on a tautology) stuff and probably not for the faint of heart. Slides 6 and 7, for example, around the 23m mark) show the value of cache compared to getting something from RAM, and just how bad retrieval from disk is. Later (slides 13 and on; around 55m in the video), when it comes to threads and how a compiler or even hardware may screw you over not do what you want to do, or even what you tell it to do, people how still have them are allowed to run to their moms for safety. By Patina, that is just nasty.

Near the end Sutter discusses the differences between using vectors, lists and sets and what the penalties for the latter are for something as simple add adding all the values in them. This starts at around slide 22, or 1h40m. Even if the rest is gobblyjook, this part is easy to understand. Basically, low footprint and sequential accesses are Good Things, even if you have cache and stuff. Especially when you have cache and stuff.

Tonc:setup update

2008-02-17 – 12:04 | .

Finally got round to updating Tonc's dev setup page. It finally mentions devkitPro's template makefiles and the basics of how to use them. I've also added a list of potential problems you may encounter when installing/upgrading devkitARM or just building projects. I have not updated the downloadables yet because there's still a few unfinished edits there. I just wanted to get this one out of the way because it's so very, very overdue.

« Previous PageNext Page »

Powered by WordPress