gxx problem
gxx problem
When i compile my code with gxx(C:\djgpp\bin\gxx -c C:\os\kernel.cpp -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o C:\os\kernel.o) it compiles without a flaw, but, then it doesn't give output
"Real corn makes it special!" -The Grim Adventures of Billy and Mandy
MMM...Caffeine
Intel Inside, Idiot Outside
MMM...Caffeine
Intel Inside, Idiot Outside
it's all from a tutorial but,
Code: Select all
//Video.h
#ifndef VIDEO_H
#define VIDEO_H //so we don't get multiple definitions of Video
class Video
{
public:
Video() ;
~Video() ;
void clear() ;
void write(char *cp) ;
void put(char c) ;
private:
unsigned short *videomem ; //pointer to video memory
unsigned int off ; //offset, used like a y cord
unsigned int pos ; //position, used like x cord
}; //don't forget the semicolon!
#endif
Code: Select all
//Video.cpp
#include "Video.h"
Video::Video()
{
pos=0 ; off=0 ;
videomem = (unsigned short*) 0xb8000 ;
}
Video::~Video() {}
void Video::clear()
{
unsigned int i;
for(i=0; i<(80*25); i++)
{
videomem[i] = (unsigned char) ' ' | 0x0700 ;
}
pos=0 ; off=0 ;
}
void Video::write(char *cp)
{
char *str = cp, *ch;
for (ch = str; *ch; ch++)
{
put(*ch) ;
}
}
void Video::put(char c)
{
if(pos>=80)
{
pos=0 ;
off += 80 ;
}
if(off>=(80*25))
{
clear() ; //should scroll the screen, but for now, just clear
}
videomem[off + pos] = (unsigned char) c | 0x0700 ;
pos++ ;
}
Code: Select all
//Kernel.cpp
#include "Video.h"
int main(void)
{
Video vid ; //local, (global variables need some Run-Time support code)
vid.write("Hello, world!") ;
}
"Real corn makes it special!" -The Grim Adventures of Billy and Mandy
MMM...Caffeine
Intel Inside, Idiot Outside
MMM...Caffeine
Intel Inside, Idiot Outside
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
How are you running this? Linking to an .exe and running?
You're assuming video memory is at 0xb8000. I don't believe this is the case when you use DJGPP in conjunction with CWSDPMI (the default DPMI "agent"). You will have to use some of the DJGPP specific functions in order to get a far pointer to video memory.
For example, you could create your own selector:
short video_selector;
video_selector = __dpmi_allocate_ldt_descriptors(1);
__dpmi_set_segment_base_address( video_selector, linear_address);
__dpmi_set_segment_limit( video_selector, 2000000L); /* 2 Megs */
And then write to video memory using:
_farpokeb(video_selector, offset, value);
The other method is to "enable near pointers" and reference the base of conventional memory:
__djgpp_nearptr_enable();
char *video = (char *)0xb8000;
video[offset + __djgpp_conventional_base] = value;
__djgpp_nearptr_disable();
--Jeff
You're assuming video memory is at 0xb8000. I don't believe this is the case when you use DJGPP in conjunction with CWSDPMI (the default DPMI "agent"). You will have to use some of the DJGPP specific functions in order to get a far pointer to video memory.
For example, you could create your own selector:
short video_selector;
video_selector = __dpmi_allocate_ldt_descriptors(1);
__dpmi_set_segment_base_address( video_selector, linear_address);
__dpmi_set_segment_limit( video_selector, 2000000L); /* 2 Megs */
And then write to video memory using:
_farpokeb(video_selector, offset, value);
The other method is to "enable near pointers" and reference the base of conventional memory:
__djgpp_nearptr_enable();
char *video = (char *)0xb8000;
video[offset + __djgpp_conventional_base] = value;
__djgpp_nearptr_disable();
--Jeff
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
I see... this is what I thought you meant, then I second guessing my interpretation of "output"
Do you get an object file when you try to compile without the specified compile options? ie: a strict gcc -c file.cpp -o file.o?
If you put in an explicit #error clause, does the compiler report a proper failure code?
Lastly, what platform are you using? djgpp was originally meant to run in Dos. From what I've heard, it's not overly well suited for windows operation... and, personally, I prefer the overall cygwin environment. You might want to check that out.
Cheers,
Jeff
Do you get an object file when you try to compile without the specified compile options? ie: a strict gcc -c file.cpp -o file.o?
If you put in an explicit #error clause, does the compiler report a proper failure code?
Lastly, what platform are you using? djgpp was originally meant to run in Dos. From what I've heard, it's not overly well suited for windows operation... and, personally, I prefer the overall cygwin environment. You might want to check that out.
Cheers,
Jeff