vga-logic-processor-examples/main.c

150 lines
3.0 KiB
C

#include <stdio.h>
#include <i86.h>
#include <conio.h>
#include <dos.h>
extern void __cdecl enableUnchainedVGAMode();
extern void __cdecl enableTextMode();
extern void __cdecl fillScreen(int);
extern void __cdecl latchCopyCube(
int offset,
int writtenValue,
int writeMode,
int setResetRegister,
int enableSetResetRegister
);
extern void __cdecl writeCube(
int offset,
int writeMode,
int setResetRegister,
int enableSetResetRegister
);
extern void __cdecl drawColorCube(
char offset,
int color
);
extern void far interrupt keyboardHandler();
extern char keyboardPressed;
extern char lastScancode;
char far *VGA = (char*)0xA0000;
#define PLANE_WIDTH (320 / 4)
void far (interrupt *int9Save)();
void populateExampleCube(void) {
int y, x;
outp(0x3c4, 0x02);
for (x = 0; x < 16; ++x) {
outp(0x3c5, 1 << (x % 4));
for (y = 0; y < 16; ++y) {
VGA[y * PLANE_WIDTH + x / 4] = y * 16 + x;
}
}
}
void forceReadVGA(char far *vga);
#pragma aux forceReadVGA = \
"mov bl,BYTE PTR [eax]" \
parm [ eax ] \
modify [ bl ];
int main(void) {
char a;
// activate unchained vga mode
// place some data into video memory to be latch copied
// show off the following
// * latch copies with logical operators
// * plane selection
// * barrel shifting
// * set/reset
int9Save = _dos_getvect(9);
_dos_setvect(9, keyboardHandler);
enableUnchainedVGAMode();
// set a very bright color as the last possible color to make
// set/reset usage more visible
outp(0x3c8, 255);
outp(0x3c9, 63);
outp(0x3c9, 63);
outp(0x3c9, 63);
fillScreen(0);
populateExampleCube();
latchCopyCube(80 * 20, 0, 0x00, 0, 0);
latchCopyCube(80 * 20 + 5, 127, 0x00, 0, 0);
latchCopyCube(80 * 20 + 10, 0, 0x08, 0, 0);
latchCopyCube(80 * 20 + 15, 127, 0x08, 0, 0);
latchCopyCube(80 * 20 + 20, 0, 0x10, 0, 0);
latchCopyCube(80 * 20 + 25, 127, 0x10, 0, 0);
latchCopyCube(80 * 20 + 30, 0, 0x18, 0, 0);
latchCopyCube(80 * 20 + 35, 127, 0x18, 0, 0);
latchCopyCube(80 * 20 + 40, 127, 0x10, 1, 3);
latchCopyCube(80 * 40, 0, 0x18 + 0x04, 0, 0);
latchCopyCube(80 * 40 + 5, 127, 0x18 + 0x04, 0, 0);
latchCopyCube(80 * 40 + 10, 0, 0x10, 3, 3);
latchCopyCube(80 * 40 + 15, 0, 0x10, 1, 3);
latchCopyCube(80 * 40 + 20, 0, 0x10, 0, 3);
writeCube(5, 0x00, 1, 3);
writeCube(10, 0x00, 0, 3);
writeCube(15, 0x00, 3, 0);
outpw(0x3ce, 0x0000);
outpw(0x3ce, 0x0001);
outpw(0x3ce, 0x0002);
outpw(0x3ce, 0x0003);
/*
outpw(0x3ce, 0x0005);
*/
outpw(0x3ce, 0xff08);
outpw(0x3c4, 0x0f02);
/*
outp(0x3ce, 0x08);
outp(0x3cf, 0xff);
*/
VGA[0] = 255;
// read the above. if you're reading the value and doing nothing with it, watcom will optimize it out
forceReadVGA(VGA);
//outp(0x3cf, 0xff);
// all from latches
outpw(0x3ce, 0x0008);
VGA[2] = 127;
// all but the first bit from incoming data
outpw(0x3ce, 0xfe08);
VGA[4] = 2;
a = VGA[4];
/*
outp(0x3cf, 0x00);
VGA[410] = 0;
*/
while (keyboardPressed == 0);
_dos_setvect(9, int9Save);
enableTextMode();
printf("%d\n", a);
return 0;
}