/examples/scanline/main.c
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <alloc.h>
#include <mem.h>

#include "i89.h"

extern i89_task_block tb_setup, tb_frobline;

struct frob_channel_parameter_block {
	i89_task_block far * tbp;
	unsigned int far * src;
	unsigned int far * dest;
	unsigned int count;
};

struct i89_channel far * ccb;
struct frob_channel_parameter_block frob_pb = { 0 };
unsigned int charptrs[2];

unsigned long int st_to_ticks(const struct time *t) {
	return t->ti_hour * 360000 + t->ti_min * 6000 + t->ti_sec * 100 + t->ti_hund;
}

char control(char dev, char com, char dat) {
	struct REGPACK regs = { 0 };
	regs.r_bx = dev;
	regs.r_cx = com;
	regs.r_dx = dat;
	intr(0xFC, &regs);
	return regs.r_ax;
}

void setup_chars() {
	/* Set up two characters, one full white, one full black */
	unsigned int * char_mem = MK_FP(0, 0x2800);
	int i;
	for (i = 0; i < 16; i++) {
		char_mem[i] = 0xFFFF;
	}
	for (i = 0; i < 16; i++) {
		char_mem[i + 16] = 0x0000;
	}
}

void frob_setup() {
	ccb[1].ccw = 0x03;
	ccb[1].ppb = (i89_channel_parameter_block_t far *) &frob_pb;
	frob_pb.tbp = &tb_setup;
	frob_pb.src = &charptrs;
	frob_pb.dest = MK_FP(0xF000, 0);
	outportb(0x72, 0);
	while (ccb[1].busy) {}
	frob_pb.tbp = &tb_frobline;
}

void frob() {
	ccb[1].ccw = 0x03;
	outportb(0x72, 0);
}

void frob86(unsigned int * screenmem) {
	int i;
	for (i = 0; i < 50; i++) {
		screenmem[i] = charptrs[0];
	}
	for (i = 0; i < 50; i++) {
		screenmem[i] = charptrs[1];
	}
}

void main() {
	unsigned int far * screen_mem = MK_FP(0xF000, 0);
	int x, y;

	ccb = MK_FP(0, 0x500);
	setup_chars();
	control('1', 1, 1); /* set graphics mode */
	for (y = 0; y < 25; y++) {
		for (x = 0; x < 50; x++) {
			screen_mem[y*50+x] = (0x2800 >> 5) + (y & 1);
		}
	}
	charptrs[0] = (0x2800 >> 5);
	charptrs[1] = (0x2820 >> 5);

	frob_setup();
	while(1) {
		frob();
		if (kbhit()) break;
	}
	getch();

	control('1', 1, 0); /* reset text mode */
}