
	#undef longint
	type longint as long

	#lang "fb"

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

	/'
	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(index as longint = 0,byref x as longint = 0,byref y as longint = 0,w as longint = 0,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)
	
	/'
	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 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 shared as string SpritePath
SpritePath="./sprites-8-private/Bitmaps/"

const PB8088FONT=0

type sheetType
	as fb.image ptr sheet
end type

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

font(PB8088FONT).sheet = bload(SpritePath & "fonts/Packard Bell PBX-8088 Super Font 2024.bmp")

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

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

const CHARNUM=0

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

if open(file(CHARNUM).file for input as file(CHARNUM).mode) NEQ 0 then
	close #file(CHARNUM).mode
	end
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)
	print QUOT & r & QUOT & " is Ascii Seq:" 
	
	color rgba(255,255,255,255)
	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
	
	print v
	
	screencopy 1,0
	
	charOffset(asc("r"),x,y,w,h,xs,ys,xo,yo,xc,yc)	

	xp=(pos-1)*xs
	yp=(csrlin-1)*ys
	
	put (xp-xc,yp-yc),font(PB8088FONT).sheet,(x,y)-step(xs-1,ys-1),alpha

	screencopy 1,0
loop

close #file(CHARNUM).mode

do while inkey EQU EMPTY:loop
end

sub charOffset(index as longint = 0,byref x as longint = 0,byref y as longint = 0,w as longint = 0,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 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