Well you need to find out if the device will allow you to directly access its video memory. Then you need to find out the format of the video memory.
If the video display is mono - no colors, then video memory should be byte for byte in that one byte is one character cell on the display. If it contains colors - foreground and background, normally this is in two bytes or one 16-bit unsigned integer. Sometimes the high byte is the color ((foreground *16)+background) and the low byte is the actual ASCII code of the text character.
So a 80x25 or depending on just how old this thing is, a 40x25 screen with 1 color would be
1000 bytes. Depending on the CPU in the thing this might work for you. Most low video modes and text modes on IBM compatibles and running x86 CPUs have the video memory starting at B800:0000. For video modes it starts at A000:0000 and for protected mode linear frame buffers the address must be retrieved from the hardware.
So this is assuming you start at B800:0000 and the screen is 1000 bytes.
Two simple solutions: Pick your poison. 16-bit code here. FAR denoting the segment pointer is pointing outside of your segment.
Code:
#include <mem.h> //might be memory.h in MS C
#include <dos.h>
unsigned char far *Screen;
void InitVideo(void);
void ClearScreen(void);
void ClearScreenAsm8(void);
void ClearScreenAsm16(void);
void CopyScreenToBuf16(void);
void InitVideo(void)
{
//Set screen mode to desired text mode - I don't know the code here
//Check Ralph Brown's list under interrupt 10h
//Init pointer to video memory
(unsigned char far *)Screen=(unsigned char far *)MK_FP(0xB800,0);
}
void ClearScreen(void)
{
memset(Screen,0,1000);
}
void ClearScreenAsm8(void)
{
asm {
les di,[Screen];
mov cx,1000d
mov ax,0
rep stosb
}
}
void ClearScreenAsm16(void)
{
asm {
les di,[Screen]
mov cx,1000d
shr cx,1
mov ax,0
rep stosw
}
}
void CopyScreenToBuf16(unsigned char far *Source,unsigned char far *Dest,unsigned int Size16)
{
asm {
push ds
lds si,[Source]
les di,[Dest]
mov cx,[Size16]
rep movsw
pop ds
}
}
This is assuming a lot about the environment of the device so don't quote me on all this as it pertains to your little toy.
Just the start to a small video library that you can use to gain more control over the screen, without having to rely on it's BIOS. Invoking interrupts is slow, and probably very slow, on your device. Don't invoke interrupt 10h for every little function you need.
The formula to find the offset in memory for the current row and column to print at is this:
row*width+column
So:
Code:
#define RCTOMEM(row,col,width) (unsigned int)( ( (row) * (width) )+ col)
void Print(int row,int col,unsigned char ch)
{
Screen[RCTOMEM(row,col,40)]=ch;
}
Remember video memory layout, starting address, pitch, etc., is key. Not all video memory is alike.