This is Belboz's brief breakdown of his 'Hello World' file along with a reprinting of the source code, jag.c and font.h for any discussion or questions anyone may have.
Quote
Well I wanted the bare minimum to get the jag up, setup a video buffer, and print a message. Since there is no printf routines, I threw together a few simple routines that write the character font to the video buffer.
It is pretty simple to understand the video buffer once you think about it. You have 64000 bytes set aside for the screen memory:
(320X200 pixels = 320 times 200 or 64000)
So the first byte in video memory is the color register to use to draw the top left pixel in. Next byte is the color reg for the next pixel to the right of the previous. Once you go through the first 320 bytes the next value is the color reg for the first pixel on the next line down. I wrote zeros to the video memory. Which means use color register 0 for drawing those pixels. I had previously set color register zero to black.
Think of those color registers from 0 - 255 as 256 seperate paint cans. You can setup each to whatever color you want. Then the video memory just tells the system which of those paint cans to use to draw that pixel on the screen.
Whats nice about this kind of video mode (which is called a color indexed mode) is that you can change the values of those 256 color registers (or paint cans) at anytime. And when you do the pixels on screen that use those registers automatically change to the new color you set. The two lines above the loop that clears the video memory are where I write values to the first two color registers. I set register 0 to black and register 1 to white. So if video memory contains a zero that corresponding pixel uses register 0 which is black. If it contains a 1 it uses register 1 which I set to white. But basically it boils down to the video memory telling the computer what color register to use for a pixel instead of 16bit and higher modes where each pixel value is actually the RGB values for that pixel.
So if your in a 320 X 200 mode in 16bit color mode. You need 320 times 200 time 2 or 128000 bytes for video memory. No color registers are used. Each 16 bits (or two bytes) is the RGB value for a pixel. 24 bit mode is the same way, but it needs 3 bytes for each pixel. So 320 x 200 24bit would be 320 times 200 time 3 or 192000 bytes for video memory.
It is pretty simple to understand the video buffer once you think about it. You have 64000 bytes set aside for the screen memory:
(320X200 pixels = 320 times 200 or 64000)
So the first byte in video memory is the color register to use to draw the top left pixel in. Next byte is the color reg for the next pixel to the right of the previous. Once you go through the first 320 bytes the next value is the color reg for the first pixel on the next line down. I wrote zeros to the video memory. Which means use color register 0 for drawing those pixels. I had previously set color register zero to black.
Think of those color registers from 0 - 255 as 256 seperate paint cans. You can setup each to whatever color you want. Then the video memory just tells the system which of those paint cans to use to draw that pixel on the screen.
Whats nice about this kind of video mode (which is called a color indexed mode) is that you can change the values of those 256 color registers (or paint cans) at anytime. And when you do the pixels on screen that use those registers automatically change to the new color you set. The two lines above the loop that clears the video memory are where I write values to the first two color registers. I set register 0 to black and register 1 to white. So if video memory contains a zero that corresponding pixel uses register 0 which is black. If it contains a 1 it uses register 1 which I set to white. But basically it boils down to the video memory telling the computer what color register to use for a pixel instead of 16bit and higher modes where each pixel value is actually the RGB values for that pixel.
So if your in a 320 X 200 mode in 16bit color mode. You need 320 times 200 time 2 or 128000 bytes for video memory. No color registers are used. Each 16 bits (or two bytes) is the RGB value for a pixel. 24 bit mode is the same way, but it needs 3 bytes for each pixel. So 320 x 200 24bit would be 320 times 200 time 3 or 192000 bytes for video memory.
#include"font.h"
extern void *vidmem;
unsigned char *jagscreen;
void DrawCharLine (int charloc, int screenloc)
{
static unsigned char shift[] = { 7, 6, 5, 4, 3, 2, 1, 0 };
int xcnt;
for (xcnt = 0; xcnt < F_WIDTH; xcnt++)
{
if (((textfont[charloc] >> shift[xcnt]) & 0x1))
jagscreen[screenloc++] = 1;
else
jagscreen[screenloc++] = 0;
}
}
void DrawChar (int x, int y, char ch)
{
int ycnt, charloc, screenloc;
charloc = ch * F_CHARSIZE;
screenloc = (y * T_XREZ) + x;
for (ycnt = 0; ycnt < F_HEIGHT; ycnt++)
{
DrawCharLine (charloc, screenloc);
screenloc += T_XREZ;
charloc++;
}
}
void DrawString (int x, int y, char *str)
{
int cnt;
for (cnt = 0; str[cnt] != 0; cnt++)
{
DrawChar (x, y, str[cnt]);
x += F_WIDTH;
}
}
void __main(void)
{
int w;
jagscreen = (unsigned char *)&vidmem;
*(unsigned short int *) 0xf00400 = 0x0000; /* Color reg 0 = black */
*(unsigned short int *) 0xf00402 = 0xffff; /* Color reg 1 = white */
for(w=0;w<64000;w++) jagscreen[w]=0;
DrawString(1,1,"Hello World");
for(;;); /* Infinite Loop. Alpine users can delete this. */
asm(" illegal");
}
Edited by JagChris, Thu Jul 15, 2010 12:27 PM.













