#ifndef __MISC_H
#define __MISC_H


#include "types.h"

#define vb_text_out vbTextOut
void vbTextOut(u16 bgmap, u16 col, u16 row, char *t_string)
// The font must reside in Character segment 3
{
	u16 i = 0,
		pos = row * 64 + col;

	while(t_string[i])
	{
		BGMM[(0x1000 * bgmap) + pos + i] = (u16)t_string[i] - 32 + 0x600;
		i++;
	}
}

#define vb_print vbPrint
void vbPrint(u8 bgmap, u16 x, u16 y, char *t_string, u16 bplt) {
// Font consists of the last 256 chars in CAM (1792-2047)
	u16 i=0,pos=0,col=x;

	while(t_string[i]) {
		pos = (y << 6) + x;

		switch(t_string[i++]) {
		case 7:
			// Bell (!)
			break;
		case 9:
			// Horizontal Tab
			x = (x << 2 + 1) >> 2;
			break;
		case 10:
			// Line Feed
			y++;
// Take this part out if...
			break;
		case 13:
// ...you're a cry-baby UNIX dweeb.  Otherwise, leave it in and have more control over text placement.
			// Carriage Return
			x = col;
			break;
		default:
			BGMM[(0x1000 * bgmap) + pos] = ((u16)t_string[i] + 0x700) | (bplt << 14);
			if (x++ > 63) {
				x = col;
				y++;
			}
			break;
		}
	}
}


#endif
