I'm having problems using gettext() and puttext(). I'm trying to use them
to save the screen and restore the screen. Sometimes when I'm running
the program, it locks up after I call gettext() and sometimes after I
call puttext(). I was thinking maybe the function is getting confused by
other included files. Here's how I am using it in my program..
void * screen;
//save screen
gettext(1,1,80,25,screen);
//here I am changing the screen, for example in one instance if they press
//F1 it shows a help screen with all the commands available.
//then after they exit the help screen...
//restore screen
puttext(1,1,80,25,screen);
If I remove all the gettext()'s and puttext()'s from my program then it
works great. Any ideas how to fix it? Or alternative methods to save
& restore the screen state?
Lance
: I'm having problems using gettext() and puttext(). I'm trying to use them
: to save the screen and restore the screen. Sometimes when I'm running
: the program, it locks up after I call gettext() and sometimes after I
: call puttext(). I was thinking maybe the function is getting confused by
: other included files. Here's how I am using it in my program..
<snip!>
: If I remove all the gettext()'s and puttext()'s from my program then it
: works great. Any ideas how to fix it? Or alternative methods to save
: & restore the screen state?
: Lance
I am assuming that you are programming in the DOS world, so if not just
ignore this completely. An alternative would be the use of the display
pages. Normally you work in video mode 3 and on display page 0. But
there are another 7 pages available, for a total of 8 in all. I am not
sure what or if there is a C/C++ function to flip the pages, I am sure
there is somewhere. However, if you can't find such information you can
always try to stick some in-line assembly into your program as follows:
asm
{
mov ah, 0x05; // Set active display page. //
mov al, 0; // Set page 0 active. //
int 0x10; // Request BIOS service. //
}
The other thing you may need to know is which display page is showing.
unsigned char page;
asm
{
mov ah, 0x0F; // Get current video mode. //
int 0x10; // Request BIOS service. //
mov page, bh; // Store active display page. //
}
Hope this helps,
Theodore Bisson
bis...@usfca.edu
LMR>I'm having problems using gettext() and puttext().
LMR>void * screen;
LMR>//save screen
LMR>gettext(1,1,80,25,screen);
Assuming that this is your actual code, you need to define the proper
amount of storage space for your screen (80x25 bytes):
char screen[4000];
2000 bytes for the characters being displayed, and 2000 bytes for the
attribute byte for each displayed character.
___
X OLX 1.53 X What was the best thing BEFORE sliced bread?
Did you try allocating some memory for that screen pointer? If you
aren't, then the function may conceivably be overwriting your
executable code or some other important area of memory when you call
gettext and puttext.
Try something like this:
void * screen = (void *)malloc(<number of bytes you need>);
Oh, you'll also need:
#include <malloc.h>, or
#include <alloc.h>
Tell me how it comes out.
-=G2=-
"This content in no way reflects the opinions, standards, or policy of
the United States Air Force Academy or the United States government."
+------------------------------------------------------------+
-=Gumbytwo=- Gumb...@cs25-125.usafa.af.mil
"Kill a man, you're a murderer; Kill many, you're a conqueror;
Kill them all, you're a God." -- MEGADETH Commodore 64!
>Did you try allocating some memory for that screen pointer? If you
>aren't, then the function may conceivably be overwriting your
>executable code or some other important area of memory when you call
>gettext and puttext.
>Try something like this:
>void * screen = (void *)malloc(<number of bytes you need>);
>
>Oh, you'll also need:
>#include <malloc.h>, or
>#include <alloc.h>
Also, it's always good to check if the malloc succeeds in allocating the
memory for you. I'd do it this way:
char *buffer;
if((buffer=(char *)malloc(2*(bottom-top+1)*(right-left+1)))==NULL) {
printf("Memory allocation failure!\n");
exit(EXIT_FAILURE);
}
You have to allocate two bytes for every screen position. That's because
every position also has one byte for it's attributes (blink,color).
Don't forget to include stdlib.h for definition of EXIT_FAILURE
Cheers,
--
--Toni Tiainen tit...@tukki.jyu.fi
' The light at the end of the tunnel is an ongoing train '
- Terry Pratchett
Lance,
Your problem is easy to fix. YOU have to allocate the memory you pass
to gettext. It will use it to store the display info. (The lockups
are due to a memory violation.) The memory space needed for the array
can be calculated the following way:
bytes = number_of_rows * number_of_columns * 2
where number_of_rows = bottom - top + 1
and number_of_collums = right - left + 1
In your example the following lines would do it:
#include <conio.h>
// allocate 80*25*2 = 4000 bytes
void screen[4000];
// save screen
gettext(1,1,80,25,screen);
// your stuff
// ...
//
// restore screen
puttext(1,1,80,25,screen);
I hope that helps.
Wugs
Thanks. I got it to work using "new" as someone suggested. I have a
question now. What is the difference in the memory used by ordinary
variables defined (ie char * screen) and variables defined with "new",
"malloc" or "alloc"?
Lance