vga-logic-processor-examples/main.c

104 lines
2.3 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;
}
}
}
int main(void) {
// 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);
while (keyboardPressed == 0);
_dos_setvect(9, int9Save);
enableTextMode();
return 0;
}