
Sub VGA_Load ( VGA_Table ( Any ) As String, Filename As String = "./Assets/Property/VGA Table.Property" )	
	
	Erase VGA_Table
	ReDim VGA_Table ( -1 To -1 )
	
	Dim As String ReserveBuffer, OutBuffer

	If Is_File ( Filename ) = 0 Then
		Exit Sub
	End If

	Dim As Long Filemode = FreeFile

	If Filemode = 0 Then
		Close #Filemode
		Exit Sub
	End If
	
	IF Open ( Filename For Binary As #Filemode ) Then
		Close #Filemode
		Filemode = 0
		Exit Sub
	End If

	ReserveBuffer = Space ( Lof ( Filemode ) )
	Get #Filemode, 1, ReserveBuffer
	Close #Filemode
	
	Do While Len ( ReserveBuffer ) > 0
		
		OutBuffer = Prefix ( CRLF, ReserveBuffer )
		ReserveBuffer = Suffix ( CRLF, ReserveBuffer )
		ReDim Preserve VGA_Table ( 0 To UBound ( VGA_Table, 1 ) + 1 )
		VGA_Table ( UBound ( VGA_Table, 1 ) ) = Trim ( OutBuffer, QUOT )
	
	Loop
	
	Exit Sub
	
End Sub

Function VGA_Lookup ( Index As Long = 0 ) As uLongInt
	
	ReDim As String VGA_Table ( Any )
	
	Return VGA_Lookup2 ( VGA_Table ( ), Index )
	 
End Function

Function VGA_Lookup2 ( VGA_Table ( Any ) As String, Index As Long = 0, Filename As String = "./Assets/Property/VGA Table.Property" ) As uLongInt

	If UBound ( VGA_Table, 1 ) = -1 Then
		
		VGA_Load ( VGA_Table (  ), Filename )
	
	End If

	Select Case Index

	Case 0 To 255
		
		If Index < LBound ( VGA_Table, 1 ) Or Index > UBound ( VGA_Table, 1 ) Then
			VGA_Lookup2 = Index
			Exit Function
		End If
		
		VGA_Lookup2 = ValULng ( VGA_Table ( Index ) )
		Exit Function
		
	Case Else

		VGA_Lookup2 = Index
		Exit Function

	End Select

End Function


Function VGA_Test ( VGA_Table ( Any ) As String ) As FB.Image Ptr
	
	Dim As Fb.Image Ptr Img
	Img = ImageCreate ( 256, 256, RGBA ( 0, 0, 0, 0 ), 32 )
	
	Dim As ULongInt crgb = RGBA ( 0, 0, 0, 0 )
	
	For Index As Long = 0 To 255 Step 1
		crgb = VGA_Lookup2 ( VGA_Table ( ), Index )
		crgb = RGBA ( rgbaR ( crgb ), rgbaG ( crgb ), rgbaB ( crgb ), 0 )
		For Alpha As Long = 0 To 255 Step 1
			PSet Img, ( Index, Alpha ), crgb or RGBA ( 0, 0, 0, Alpha xor 255 )
		Next Alpha
	Next Index
	
	Return Img
	
End Function
