home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ENTERPRS
/
CPM
/
UTILS
/
S
/
SGTOOL11.ARC
/
CHARFLIP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-25
|
3KB
|
117 lines
/*
SG C Tools 1.1
(C) 1993 Steve Goldsmith
All Rights Reserved
Example of xfering VDC memory to and from a dynamic buffer.
Compiled with HI-TECH C 3.09 (CP/M-80).
To compile with HI-TECH C and SG C Tools source on same disk use:
C FLIPCHAR.C -LC128
*/
#include <stdlib.h>
#include <hitech.h>
#include <conio.h>
#include <vdc.h>
#define appClrScrCh 32
void drawcharset(uchar X1, uchar Y1, uchar Attr);
void println(char * TextStr);
void flipcharset(void);
extern ushort vdcCharMem;
extern ushort vdcCharMemSize;
extern uchar vdcCharBytes;
uchar appTextY = 10;
main()
{
savevdc(); /* save vdc regs and set global vars */
clrscrvdc(appClrScrCh); /* clear screen */
clrattrvdc(vdcAltChrSet); /* clear attributes */
setcursorvdc(0,0,vdcCurNone); /* turn cursor off */
outvdc(vdcFgBgColor,vdcBlack); /* set new screen color */
flipcharset(); /* flips both character sets */
while (getch() != 0x0D); /* wait for return press */
restorevdc(); /* restore registers saved by savevdc() */
putchar(0x1A); /* adm-3a clear-home cursor */
}
/* draws character set in a 64 X 4 grid given x and y offsets */
void drawcharset(uchar X1, uchar Y1, uchar Attr)
{
uchar X, Y;
for (Y = 0; Y < 4; Y++)
{
fillattrvdc(X1,Y+Y1,64,Attr);
for (X = 0; X < 64; X++)
filldspvdc(X+X1,Y+Y1,1,Y*64+X);
}
}
/* prints string and sets y position for next string */
void println(char * TextStr)
{
printstrvdc(0,appTextY++,vdcAltChrSet+vdcLightGreen,TextStr);
}
/* flip both 8x8 char sets */
void flipcharset(void)
{
uchar CurByte, CharSave;
ushort CurChar, CharOfs;
uchar *BufPtr;
drawcharset(7,0,vdcDarkCyan); /* draw char sets */
drawcharset(7,5,vdcAltChrSet+vdcLightBlue);
println("coping vdc character set to buffer...");
BufPtr = memtobufvdc(vdcCharMem,vdcCharMemSize); /* copy char sets to buf */
if (BufPtr != NULL)
{
println("flipping patterns in buffer...");
for(CurChar = 0; CurChar < 512; CurChar++) /* flip char sets in buf */
{
CharOfs = CurChar*vdcCharBytes;
for(CurByte = 0; CurByte < 4; CurByte++)
{
CharSave = BufPtr[CharOfs+CurByte];
BufPtr[CharOfs+CurByte] = BufPtr[CharOfs+(7-CurByte)];
BufPtr[CharOfs+(7-CurByte)] = CharSave;
}
}
println("coping buffer to vdc character set...");
buftomemvdc(BufPtr,vdcCharMem,vdcCharMemSize);
println("Press [RETURN].");
while (getch() != 0x0D);
println("flipping patterns in buffer..."); /* flip em back */
for(CurChar = 0; CurChar < 512; CurChar++)
{
CharOfs = CurChar*vdcCharBytes;
for(CurByte = 0; CurByte < 4; CurByte++)
{
CharSave = BufPtr[CharOfs+CurByte];
BufPtr[CharOfs+CurByte] = BufPtr[CharOfs+(7-CurByte)];
BufPtr[CharOfs+(7-CurByte)] = CharSave;
}
}
println("coping buffer to vdc character set...");
buftomemvdc(BufPtr,vdcCharMem,vdcCharMemSize);
println("Done. Press [RETURN].");
free(BufPtr); /* dealloc buf */
}
}