
	#undef longint
	type longint as long

	#lang "fb"

	#Include Once ".\KSDK\Support\Constants.bi"	
	dim shared as string Value

	const PBX8088FONT=0

	type sheetType
		as fb.image ptr sheet
		as string file
	end type

	redim shared as sheetType font(any)
	redim font(0 to 0)

	/'
	type pixel
		union
			type
				 as ubyte B,G,R,x
			end type
			u as ulong
		end union
	end type
	'/
	
	#Include Once ".\KSDK\Support\File Support.bi"

	#Include Once ".\KSDK\Support\String Support.bi"
	
	#Include Once ".\KSDK\Support\VGA Lookup.bi"

	#Include Once ".\KSDK\Support\Simple Input.bi"
				
	#Include Once ".\KSDK\Support\Memory Management.bi"
	
	#Include Once ".\KSDK\Support\Text Box.bi"
	
	#Include Once "fbgfx.bi"
	#Include Once "fbimage.bi"
	#Include Once "vbcompat.bi"
	#Include Once "crt.bi"
	#Include Once "z.bi"
	
	'#include once "inc\fbpng.bi"
	'#include once "inc\png_image.bi"

	#Include Once ".\KSDK\Support\Property Core.bi"

	#include once ".\KSDK\Support\Property Shorthand.bi"
	
	#include once ".\KSDK\Support\Random.bas"
	
	declare sub charOffset(fontIndex as longint = PBX8088FONT,index as longint = 0,byref x as longint = 0,byref y as longint = 0,byref w as longint = 0,byref h as longint = 0,byref xs as longint = 0,byref ys as longint = 0,byref xo as longint = 0,byref yo as longint = 0,xc as longint = 8,yc as longint = 8)
	
	declare sub dispText(fontIndex as longint = PBX8088FONT,v as string = EMPTY)
	
	declare sub main()

	/'
	redim shared as Property_DB_Type ParamDB(any)
	redim shared as Property_DB_Type BoardDB(any)
	redim shared as Property_DB_Type TextureDB(any)

	declare sub __SortAll()
	'/

	'#include once ".\Keal's LabDemo2 Macros (No1).bi"
	
	using fb
	
	'dim shared as string Property_Echo
	'Property_Echo = EMPTY

screenres 320,240,32,16
screenset 1,0

color rgba(255,255,255,255)
cls

dim r as string
r = EMPTY

dim shared as string SpritePath
SpritePath="./sprites-8-private/Bitmaps/"

font(PBX8088FONT).file = "Packard Bell PBX-8088 Super Font 2024"

font(PBX8088FONT).sheet = bload(SpritePath & "fonts/" & font(PBX8088FONT).file & ".bmp")

type fileType
	as longint mode=0
	as string file=EMPTY
end type

redim shared as fileType file(any)
redim file(0 to 0)

const CHARNUM=0

file(CHARNUM).mode=freefile
file(CHARNUM).file="chartest.txt"

main()
end

sub main()
	
	dim as longint x=0,y=0,w=0,h=0,xs=0,ys=0,xo=0,yo=0,xc=8,yc=8,xp=0,yp=0
	dim as string r=EMPTY,v=EMPTY
	
	if open(file(CHARNUM).file for input as file(CHARNUM).mode) NEQ 0 then
		close #file(CHARNUM).mode
	end if
	
	color rgba(255,255,255,255)
	cls
	locate 1,1
	
	do while not eof(file(CHARNUM).mode)
	
		dim as longint offset=0,index=0
		dim as string v=EMPTY
		
		line input #file(CHARNUM).mode, r
		
		r = trim(r,QUOT)
	
		v = QUOT & r & QUOT & " is Ascii Seq:" 
		
		for offset = 1 to len(r) step 1
			if offset GTR 1 then
				v &= COMMA
			end if
			v &= asc(mid(r,offset,1))
		next offset
		
		dispText(PBX8088FONT,v)
	
		screencopy 1,0
		
	loop
	
	close #file(CHARNUM).mode
	
	do while inkey EQU EMPTY:loop
	
	return
	
end sub
	
	
sub charOffset(fontIndex as longint = PBX8088FONT,index as longint = 0,byref x as longint = 0,byref y as longint = 0,byref w as longint = 0,byref h as longint = 0,byref xs as longint = 0,byref ys as longint = 0,byref xo as longint = 0,byref yo as longint = 0,xc as longint = 8,yc as longint = 8)
	
	'capture sheet size
	w = font(fontIndex).sheet->width
	h = font(fontIndex).sheet->height
	
	'capture cell size
	xs=int(w/16)
	ys=int(h/16)

	'capture cell input offset
	x=(index and 16)*xs
	y=((index mod 16) and 15)*xs

	'capture cell output offset
	xo=xc-xs
	yo=yc-ys
	
end sub

sub dispText(fontIndex as longint = PBX8088FONT,v as string = EMPTY)
	
	dim as longint x=0,y=0,w=0,h=0,xs=0,ys=0,xo=0,yo=0,xc=8,yc=8,xp=0,yp=0
	dim as longint offset=0

	for offset=1 to len(v) step 1
		
		charOffset(fontIndex,asc(mid(v,offset,1)),x,y,w,h,xs,ys,xo,yo,xc,yc)	

		xp=(pos-1)*xs
		yp=(csrlin-1)*ys
	
		put (xp-xc,yp-yc),font(fontIndex).sheet,(x,y)-step(xs-1,ys-1),alpha
		
		print SP;
		
	next offset
	
end sub