OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 11:33 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Function triple faults PC
PostPosted: Fri Aug 10, 2001 11:00 pm 
For some reason I can't figure out, this function resets my
computer when called:

// Displays 'string' at (col, row) in the current attribute.
// Does not modify cursor position.
// Returns nothing.
void Put_String_At(unsigned short int col, unsigned short int row, unsigned char *string)
{
unsigned char ch;
unsigned short int cursor = ((row - 1) * 80 + (col - 1)) * 2;

while(ch = *string++)
{
switch(ch)
{
// Newline.
case '\n':
// Put our cursor at the first character on next line.
// But for now, just print '\n'.
VIDEO[cursor] = '\\';
cursor = cursor + 1;
VIDEO[cursor] = Get_Text_Color();
cursor = cursor + 1;
VIDEO[cursor] = 'n';
cursor = cursor + 1;
VIDEO[cursor] = Get_Text_Color();
cursor = cursor + 1;
break;

// Normal character.
default:
VIDEO[cursor] = ch;
cursor = cursor + 1;
VIDEO[cursor] = Get_Text_Color();
cursor = cursor + 1;
break;
}
}
}

I've looked at it a million times and can't figure out what is wrong.
Can someone please help me. BTW, VIDEO is a pointer to the video memory
(0xb8000) and I'm using DJGPP.


Top
  
 
 Post subject: Another thing...
PostPosted: Fri Aug 10, 2001 11:00 pm 
Also, (1, 1) would be the upper left of the screen, not (0, 0).


Top
  
 
 Post subject: RE:Function triple faults PC
PostPosted: Fri Aug 10, 2001 11:00 pm 
> unsigned short int cursor = ((row - 1) * 80 + (col - 1)) * 2;

this shouldn't cause a triple fault, but the above
line should actually be:

cursor = (row - 1) * 160 + (col - 1) * 2;
Remember, there's 160 bytes to a line, not 80.

> while(ch = *string++)

Is there a possibility the string isn't \0 terminated?

> VIDEO[cursor] = Get_Text_Color();

If Get_Text_Color(); does something more than
a "return colour;" then the triple fault may
actually be caused by that function... although,
I doubt it.

>I've looked at it a million times and can't figure out what is wrong.
>Can someone please help me. BTW, VIDEO is a pointer to the video memory
>(0xb8000) and I'm using DJGPP.

Positive? Have you enabled paging? Perhaps the
video buffer isn't in your page table?

Or, perhaps, you haven't entered pmode correctly...
is this the very first thing you do after entering
pmode? 'cuz I've often tried to do something
directly after entering pmode which has failed, and
I've blamed the function, when in actuality it was
my pmode code... the processor wasn't properly
put into pmode.

Just a couple suggestions... I really can't
see anything wrong with your code, except the first
line (but then, I'm really tired, so I may
have missed something).

j.weeks


Top
  
 
 Post subject: RE:Function triple faults PC
PostPosted: Fri Aug 10, 2001 11:00 pm 
> unsigned short int cursor = ((row - 1) * 80 + (col - 1)) * 2;

this shouldn't cause a triple fault, but the above
line should actually be:

cursor = (row - 1) * 160 + (col - 1) * 2;
Remember, there's 160 bytes to a line, not 80.

> while(ch = *string++)

Is there a possibility the string isn't \0 terminated?

> VIDEO[cursor] = Get_Text_Color();

If Get_Text_Color(); does something more than
a "return colour;" then the triple fault may
actually be caused by that function... although,
I doubt it.

>I've looked at it a million times and can't figure out what is wrong.
>Can someone please help me. BTW, VIDEO is a pointer to the video memory
>(0xb8000) and I'm using DJGPP.

Positive? Have you enabled paging? Perhaps the
video buffer isn't in your page table?

Or, perhaps, you haven't entered pmode correctly...
is this the very first thing you do after entering
pmode? 'cuz I've often tried to do something
directly after entering pmode which has failed, and
I've blamed the function, when in actuality it was
my pmode code... the processor wasn't properly
put into pmode.

Just a couple suggestions... I really can't
see anything wrong with your code, except the first
line (but then, I'm really tired, so I may
have missed something).

j.weeks


Top
  
 
 Post subject: RE:Function triple faults PC
PostPosted: Fri Aug 10, 2001 11:00 pm 
>this shouldn't cause a triple fault, but the above
>line should actually be:
>
>cursor = (row - 1) * 160 + (col - 1) * 2;
>Remember, there's 160 bytes to a line, not 80.

I use that same offset algorithm in a Put_Char() function and it works beautifully so it's correct :-)


>Is there a possibility the string isn't \0 terminated?

Well, I always use the function like 'Put_String_At(1, 1, "Hello, World!");' or something similar.


>If Get_Text_Color(); does something more than
>a "return colour;" then the triple fault may
>actually be caused by that function... although,
>I doubt it.

No, it just returns (foreground | background);


>Positive? Have you enabled paging? Perhaps the
>video buffer isn't in your page table?

I have other video output functions and they all work fine. This is the only one that doesn't.

Any other suggestions?


Top
  
 
 Post subject: RE:Function triple faults PC
PostPosted: Fri Aug 10, 2001 11:00 pm 
>On 2001-08-11 17:48:05, Hillbillie wrote:

>Can someone please help me. BTW, VIDEO is a pointer to the video memory
>(0xb8000) and I'm using DJGPP.

#include <sys/nearptr.h>
#include <crt0.h>
void main(void) {
unsigned char *VIDEO = (unsigned char *)
0xB8000 + __djgpp_conventional_base;

if(!(_crt0_startup_flags & _CRT0_FLAG_NEARPTR)) {
if(!__djgpp_nearptr_enable()) {
printf("Could not enable nearptr\n");
return -1;
}
}
*VIDEO = '@';
}


Top
  
 
 Post subject: RE:Function triple faults PC
PostPosted: Sun Aug 12, 2001 11:00 pm 
>#include <sys/nearptr.h>
>#include <crt0.h>
>void main(void) {
>unsigned char *VIDEO = (unsigned char *)
> 0xB8000 + __djgpp_conventional_base;
>
>if(!(_crt0_startup_flags & _CRT0_FLAG_NEARPTR)) {
> if(!__djgpp_nearptr_enable()) {
> printf("Could not enable nearptr\n");
> return -1;
> }
>}
>*VIDEO = '@';
>}

Hmm...how will this help? Doesn't printf() call the operating system?


Top
  
 
 Post subject: Fixed it!
PostPosted: Sat Oct 20, 2001 11:00 pm 
In case someone was having the same trouble, I'll post the updated code and how I fixed it.

// Displays 'string' at (col, row) in the current attribute.
// Does not modify cursor position.
// Returns 0 on success, -1 on error.
signed short int Put_String_At(unsigned short int col, unsigned short int row, unsigned char string[])
{
unsigned short int ch = 0;
unsigned short int offset;

// If coordinates are legit, print that sucker.
if((col < 81) && (col > 0) && (row < 26) && (row > 0))
{
offset = ((row - 1) * 80 + (col - 1)) * 2;

while(string[ch] != 0)
{
// Newline.
if(string[ch] == '\n')
{
// Put our cursor at the first character on next line.
offset = ((offset / 2 / 80) + 1) * 160;

// If we're offscreen, scroll.
if((offset / 2) > 1999)
{
Scroll_Screen(1, 1, 80, (unsigned short int)SCREEN);
offset = 3840;
}
}

// Normal character.
else
{
VIDEO[offset] = string[ch];
offset = offset + 1;
VIDEO[offset] = Get_Text_Color();
offset = offset + 1;
}

ch++;
}

return 0;
}

return -1;
}

Also, when I compiled it, I used the '-fwritable-strings' option.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], rdos and 220 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group