home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
itcapr91.arj
/
MEMTST.C
< prev
next >
Wrap
Text File
|
1991-09-07
|
2KB
|
69 lines
/****************************************************************
* MEMTST.C -- Demonstrate memset() and memcpy() by clearing *
* video RAM, and copy a string to the screen. (This program *
* assumes you're in 80x25 text mode.) *
* *
* To compile: "tcc -ml MEMTST" *
****************************************************************/
#include <stdio.h> /* puts() */
#include <stdlib.h> /* exit(), EXIT_FAILURE */
#include <string.h> /* memcpy(), memset(), strlen() */
#include <dos.h> /* geninterrupt() */
#include <assert.h> /* assert() */
#define MAXSIZE (80 * 25)
#define GREEN 32 /* Black letters on Green attribute */
#define RED 64 /* Black letters on Red attribute */
#define MAXROWS 10
#define ROW 80
void main(void)
{
char buff[] = "Inside Turbo C";
unsigned message[26];
unsigned dot, i, len, mode, scale;
unsigned far *scrptr, far *base;
/* Ensure that we use the correct memory model (the memset() */
/* function expects NEAR pointers in TINY, SMALL, and MEDIUM */
/* memory models). */
assert(sizeof(void *) == sizeof(void far *));
/* Get the current video mode */
_AX = 0x0f00;
geninterrupt(0x10);
mode = _AX & 0xff;
/* Point to the beginning of the video buffer */
if (mode==7)
base = scrptr = (unsigned far *)MK_FP(0xb000,0);
else if (mode==2 || mode==3)
base = scrptr = (unsigned far *)MK_FP(0xb800,0);
else
{
puts("Invalid display mode");
exit(EXIT_FAILURE);
}
/* Clear the screen */
scale = MAXSIZE * 2; /* (each cell is 2 bytes) */
memset(base, GREEN, scale); /* black on green AND space */
/* Initialize message background */
dot = RED << 8; /* Red background for msg */
len = strlen(buff);
for (i = 0; i < len; i++)
message[i] = dot + buff[i];
/* Write message on screen */
len *= sizeof(unsigned); /* (each cell is 2 bytes) */
scrptr += 3 * ROW + 20; /* Line 3, column 20 */
for (i = 0; i < 10; i++) /* Write msg on lines 3..13 */
{
memcpy(scrptr, message, len); /* Put msg on CRT */
scrptr += ROW; /* Point to next row*/
}
}