Re: MS-DOS Porting trouble

Search this archive.

From: Lionel Pinkhard (lionelp@worldonline.co.za)
Date: Fri 11 Aug 2000 - 23:37:30 IDT


Hi,

Thanks for the help! I seem to have one more problem with the time:

My game expects the time to be returned in the system timer's format, how
would I be able to convert tv.tv_usec to this format? The way the game is
programmed, makes it VERY hard to rewrite the game's timing routines,
without rewriting the entire game, but the game uses a procedure which
returns the system timer, so just converting the number in this
procedure would be the easiest. :-)

Ciao,

Lionel

On Sat, 12 Aug 2000, Bart Oldeman wrote:

> On Fri, 11 Aug 2000, Lionel Pinkhard wrote:
> 
> > I'm having a little trouble with the keyboard, I tried your piece of code
> > (thanks a lot, BTW!), and I include <ncurses.h> as well, and got this
> > output:
> > 
> > /tmp/cca020801.o: In function `gameloop':
> > /tmp/cca020801.o(.text+0x2f2): undefined reference to `noecho'
> > /tmp/cca020801.o(.text+0x2f7): undefined reference to `cbreak'
> 
> That's a linking problem. Solved by putting -lncurses on the gcc command
> line. My loop was a bit wrong anyway, if you want to test for non-blocking
> input.
> 
> Better is (with #include <curses.h>):
> noecho();
> cbreak(); /* set cbreak mode (don't wait for return key) */
> nodelay(stdscr,TRUE);
> while ((keypressed=getch())!=ERR) {
> 
> You see in non-blocking mode, kbhit() is equivalent to getch()!=ERR. But
> getch also gives you the resulting key so you don't want to loose it.
> 
> With svgalib instead of ncurses it's easier:
> 
> while ((keypressed=vga_getkey()) {
> /*vga_getkey returns zero if no key has been hit*/
> 
> Check out raw keyboard mode in svgalib if you need special keys not in the
> ascii table or ncurses.
> 
> > Also, I checked out the man page for gettimeofday, I'm just having a
> > little trouble understanding it, what type of variable should I set up to
> > store it in? Can you give me an example of how I can get the time from it?
> > Sorry, the man page is talking about struct's, and I don't have that much
> > experience with it (well, I've never returned a struct, but I have used
> > them before).
> 
> struct timeval           tv;
> struct timezone		 tz;
> gettimeofday(&tv, &tz);
> 
> Simple ;-)
> 
> BUT if you just want to use your timing for a delay you're better of
> and it's easier using sleep or usleep. (see man 3 sleep or usleep)
> usleep suspends the execution for the given interval of microseconds.
> 
> Bart
> 
> 


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST