A treatise by Nathan Clark Sanders, known to some as ZackMan, who, being a most excellent expert on thingy32, is qualified to give divers addresses on the subject of

Reading Data Through a Table

in the form of letter to his young friend interested in creating a Final Fantasy V save state editor.

Outline

I. Load Data and Table Values

A. Data format.
B. Table format.

II. Compare Data with Table Values

III. Extra Functions

A. Double and triple values
B. End line and section break codes.

Note: All code presented is Visual Basic code. Even if you don't know BASIC, you won't have to much trouble. For reference and examples of the ideas in this letter, see the thingy32 source code.

Ganoran,

The first thing you need to do when reading data through a table is to load your data in an array of strings or a single string. Load the data as hex(ex: Space becomes "20" in ASCII data). Thingy32 loads only one screenful of data at one time into memory, treating it as an array and parsing using the Mid$ function(useful if you are using C because that's the way its strings are). However, if you load the whole 260K file into memory, an array of strings might work better.
Once you've got your data loaded, you need to have two parallel arrays of strings. The first one contains the actual text of the different table values, and the second array contains the hex values in string form. In thingy32, these are wisely named combo and comhex respectively. For now I will call them TableText and TableHex instead(example: TableHex(1)="AA" TableText(1)="Wa"). Please note that it is also possible to create your own data type that combines these two:

Type TableVal
	Hex as String * 2
	Text as String
End Type
Dim Table(1 To 300) as TableVal

This is better structure but is not completely necessary.
Thingy32 obtains the table values by parsing .tbl files, which is outside the scope of this letter.(I don't understand it very well myself o_o) In your program, it may well be easier to just type these in by hand as constants since you're only using one set of table equivalencies. When assigning table values, the array index must match the value of the hex. That way the hex values are very easy to match with the data when comparing them. Please note that thingy32 starts its arrays at 1 and thus must add 1 to the hex value in case the hex is 00. To avoid this, just start your arrays at 0. My example code will assume your arrays start at 0 for simplicity.

Once you have the data and the table values in the correct format, it is relatively simple to compare the two and obtain the correct text from the table. Here is some example code that demonstrates this(simplified from DisplayData of thingy32):

	For x = 1 To 16	'loop through a single line finding the table value from the data hex
	'note that strData is one screenful of data, stored as a single string.(char[] in C)
		strDataHex = Mid$(strData, x + 16 * (y - 1), 1)	'parse the data string array to isolate 1(one) character
		char = Hex$(Asc(strDataHex))		'convert the character to standard hex format(e.g. "1F")
		If Len(char) = 1 Then char = "0" & char	'make sure single digit hex are prefixed with "0"
		AscVal = Asc(strDataHex)	'get the ASCII number of the character(like treating a char like an int in C)
		If TableHex(AscVal) <> "" Then	'check to see if that index has been assigned a table value.
			strTableOutput = strTableOutput & TableText(AscVal)	'if it has, add it to the string
		End If
	Next x
	lstItems.Add strTableOutput	'this may not be the right function--I can't remember.

That's it for basic table value reading! The problem comes when you want to add fancy features like reading of double and triple hex combinations, end line codes(a necessity for script dumping), or section break codes. I will attempt to describe how to implement these. As always, see thingy32's code for a working example of this. Keep in mind thingy's code is very ugly, though. The examples here will look beautiful compared to it.
That said, the first thing for double or triple implementation is another set of parallel arrays(if you declared the TableVal structure you can use that for the new array). Fill these just like the normal table values, except they don't have to be in any order because we'll search the values with a For loop instead. Come to think of it, if you wanted to create an ordered array 65536 long, you could. But not in QBasic which is why thingy doesn't do that. Anyway, take the above example code and add

	strDataHex2 = Mid$(strData, (x + 1) + 16 * (y - 1), 1)	'get another char and format it
	char2 = Hex$(Asc(strDataHex2))
	If Len(char2) = 1 then char = "0" & char
	AscVal2 = Asc(strDataHex2)
	For i = 1 To MaxDoubles	'MaxDoubles is how many doubles there are
		If TableHexDbl(i) = char & char2 Then
			strTableOutput = strTableOutput & TableTextDbl(i)
			Exit For
		End If
	Next i

If you want to add triples just extend this process(but you will probably be unable to declare an ordered array 16M long :). Now, adding line breaks and section breaks is pretty easy; just create EndLineText and EndLineHex variables and test char against EndLineHex to do line breaks. Do the same for section breaks. Now, something you may be wondering about is letting the user edit the table text. This is completely different and much more complicated. Also, cursor positioning on table values in fairly difficult. Thus, these topics are beyond the scope of this letter. Sorry.

I hope this helps to understand how to add code to your program that reads data through table values.

Sincerely,

ZackMan

Typed this 2nd of March of the year 2000 AD by ZackMan, the undersigned who can't sign because of stupid browser technology limitations.