Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
When I call a function I've written ( con_put(char c); ).. this function should copy a character to a buffer and then it copies the buffer to the videomemory (don't ask why :p I have my reasons for it :p).. but this isn't the case unfortunately. Here is some code:
#define MAX_CONSOLES 10 // should be OK ;)
typedef struct __console_t
{
char* buffer; // pointer to memory
unsigned short pos; // pointer to current position
int u; // used to chek wheter a console is used
} console_t;
// used to let the manager now which console shoulde be written to.
unsigned int active_con = 0; // std use the kernel console ;)
console_t consoles[MAX_CONSOLES];
char kernel_buffer[4000]; // 80 * 25 * 2 ;)
// following is the init-func.. is called before con_put(char c); func
void con_init()
{
// zero console headers
memset((void*)&consoles, 0, sizeof(console_t) * MAX_CONSOLES);
// create the primary kernel console:
consoles[0].buffer = (char*)&kernel_buffer; // assign buffer
consoles[0].pos = 0; // set our position
consoles[0].u = 1; // used :p
}
void con_put(char c)
{
consoles[active_con].buffer[consoles[active_con].pos] = c; // copy character to buffer
consoles[active_con].pos += 2; // skip over attribute
memcpy((void*)0xb8000, (void*)&consoles[active_con].buffer, 4000); // refresh screen
}
But I get something else instead :S The problem is that I get a kinda green color on my screen, only one character. (color: windows98 backgroud color :@) I hope someone can help.
Thanks in advance,
Matthias
Last edited by matthias on Thu Aug 25, 2005 11:00 pm, edited 4 times in total.
when i face such problem with a code that i am sure it is well written .. i think of stupid causes
try to isolate the various possible causes and test each one separately:
* the mode has not been initialized properly:
try to write directly to the video memory .. no buffers, consoles or such things .. if it works then the mode has been initialized well
* a bug in the memcpy fucntion:
try to use memcpy to write directly into video memory .. if it works then no bugs are there
* a bug in the consoles:
use a single console, don't use a buffer
* a bug that is cannot be determined !!
use an emulator with debugger .. check the video memory to see what is there. BOCHs is good .. there is also VMware Workstation, it doesn't offer a debugger but u can dump the contents of the memory using a simple hack
consoles[active_con].buffer[consoles[active_con].pos] = c; // copy character to buffer
consoles[active_con].pos += 2; // skip over attribute
This will set the character, but since the consoles->buffer is assigned an char buffer with no initial value, it'll be tossed into the BSS section. If your loader is doing the right thing, this BSS section will be zerod out, and therefore your attribute byte will be 0; the characters will not show, in this case.
consoles[active_con].buffer[consoles[active_con].pos] = c; // copy character to buffer
consoles[active_con].pos += 2; // skip over attribute
This will set the character, but since the consoles->buffer is assigned an char buffer with no initial value, it'll be tossed into the BSS section. If your loader is doing the right thing, this BSS section will be zerod out, and therefore your attribute byte will be 0; the characters will not show, in this case.
--Jeff
--> Problem solved thanks I was planning to do the attribute-stuff later on. But now I see that wasn't such a good idea :p
Last edited by matthias on Fri Aug 26, 2005 11:00 pm, edited 2 times in total.