开发者

Replicating Spinrite Animation Effect in C

I would like to replicate the spinner effect that Spinrite displays in the upper-right corner of the screen to indicate that it's still running and hasn't frozen. You can see an example of this here at 2:18 - http://youtu.be/XRmDwVj5CRM

We could debate the efficacy of Spinrite until the cows come home but there's no denying that it has a decent UI considering what it runs on.

I'll be replicating the effect in C on an ARM platform but I'm looking for general advice rather than code, such as how to increment the steps of the animation.

Thanks in a开发者_如何学Cdvance.


That's some old tech there, but it looks like Gibson has updated his UI a little. I remember his spinner being the /\|- characters... But I digress. :)

That is in text mode and most likely done by hooking the timer interrupt in DOS and drawing every other tick of the timer.

A standard DOS timer ticked roughly every 55 milliseconds.

You can draw directly to the screen in DOS on an X86 by writing to the pointer 0xA0000 using the goofy extended DOS character set.

(Note that this is from OLD memory, it's been 15+ years since I've done any of this stuff :) In other words, to draw the letter 'A' at the first row/column of the screen, you'd do the following.

    char *screen = 0xA0000;
    *screen = 'A';

To get a little bit more advanced, (no error or bounds checking.)

#define COLUMNS 80
#define ROWS    25
#define VIDMEM_BASE 0xA0000

// Row and column are 1 based
// Note that in a real implementation you would make sure row/column are within the screen bounds
// and if you were on the last row, you might scroll the screen up etc.
void writeScreen( char theChar, size_t row, size_t column )
{
    char *screenBase = VIDMEM_BASE;

    screenBase += ((row - 1) * COLUMNS) + column - 1;
    *screenBase = theChar;
}

With the above in mind, you'll have to figure out how that stuff works on your ARM system and replicate it. Looking at a port of ncurses or Borlands conio system for the ARM would probably give you a good head start. I know there was a port of Borland's Turbo Vision library to Linux but I'm not sure it was ever ported to ARM. Here's a link to the sourceforge page if you're interested. Turbo Vision was a nice text mode GUI in its day, for what it's worth.

Hope this helps.


I haven't worked on an ARM platform for ages. Used to have an Archimedes .

I don't appear to be able to comment on the question, so I'll ask for clarification here:

What are you using for the graphics for the animation? I mean animated GIF, a set of bitmap files, or drawing from scratch each time, something else?

I believe that on ARM you can set a timer interrupt callback thingamajig. However that would likely get called even if the application itself has frozen, incorrectly leading the user into believing it was working.

I have no idea what UI library or whatever you are using, but most that I have ever worked on have a way to poll() on the event queue. Each time poll() returns, calculate the elapsed time since you last redrew the animation and if it is large enough, do the next frame. If not, decrement the poll() timeout so that you don't block in poll() too long.

Alternatively, sometimes you can get the OS to push timed events onto the event queue. Redraw a frame each time you read one off the event queue. This may be especially useful since if the event is slow processing the events and starts getting a backlog, this will be indicted by the animation slowing down. I.e. the spinner will spin full speed normally, slowly when the application is thrashing and struggling, and stop when the application hangs.

Is that the sort of information you're looking for?

As for incrementing the steps of the animation, I'm sure you're not talking about something like:

int step = 0;

...

step = (step + 1) % max_steps;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜