A92: Re: Prgm and Func format
[Prev][Next][Index][Thread]
A92: Re: Prgm and Func format
>
>Can anyone please explain me what is the difference in the format
>between FUNC and PRGM variables ?
>
I'll assume you are referring to the ACTUAL binary data format...
(All information about files comes directly from FILES.TXT included
with the Fargo II distribution.)
There is VERY little difference between the two formats. Here is
the format for a "file" on the ti-92:
$00.W length of file in bytes
$02 contents of file
$??.B terminating byte (e.g 2D for string)
NOTE: ?? is at the end of the file... ?? = ($00.W) + 1
The terminating byte (and sometimes the precedeing byte) are used
to determine the file type. All programs and libraries (both TI-
BASIC and Fargo) have the terminating byte as $DC. Let's just
stick to the TI-BASIC FUNC and PRGM variables. (Since Fargo
libraries are still .92p files)
Here is the format for a program/function:
$00.B #$DC
$01.B flags- 08 = untokenized, 40/50 = tokenized
$02.W something wierd (always #0)
$04.W parameters of program ending with ) = $E5
$??.W first token #$19E4 for program otherwise function
$?? if untokenized: offset of cursor in editor
#0.W followed by program
if untokenized: rest of program
Now this looks pretty easy doesn't it... Well you're in for a
treat! The TI-OS stores it's programs and functions (when
tokenized) BACKWARDS! You see in the format, the addresses
are relative to the END of the program/function. $00.B is
actually $??.B in the "file format". $01, $02, and higher
are actually approaching the START of the file. The following
examples show TI-BASIC program/function with its actual binary
data on the calc. When I say, "next," or, "after," keep in
mind I'm referring to TOKENS and to assume NEXT means closer
to the START of the file.
Here is a TI-BASIC program in text and in binary*:
:justpaws()
:Prgm
:Pause
:EndPrgm
00 02 04 06 08 0A 0C 0E 0123456789ABCDEF
.....................................
00000000: 0011E912 E400E8E5 51E400E8 19E4E500 ....Q...
00000010: 0050DC .P
* Binary data formatted by HexConv (c) 1998 Aaron Hill
Following the file formats, let's break apart the program. We
need to look for $00.W in the program for the file size. We
find #$0011. Remember that $??.B was found by ($00.W + 1). So
we should find the terminating byte at $12, which we do. Now
that's it for the file format. Essentially we have determined
that the file IS a file. Referring to the PRGM/FUNC format,
after the $DC we have flags. And in this case, the program is
tokenized and we have a #$50. I've only seen #$40 used for
FARGO programs. Next we should have the "SOMETHING WIERD." I
have no clue what it is, but it always seems to be #0. But you
can see that after the flags there is a WORD of 0. The next
item in the format is the parameter list. We should have NO
parameters and so the ')' or #$E5 should be after the #0. The
next item in the format is where we say PRGM or FUNC. The file
format says that #$19E4 is a program. And that's right, except
you really need to break it down more. Tokens for the OS are
really complex. Remember that we are "HEBREW" and read right-
to-left. $E4 means that the next BYTE is a "Program Token."
Now the FILES.TXT has a list of all tokens... if we look through
it we'll find $19... and it is, CAN YOU GUESS? Prgm. Now the
next BYTE we find is $E8. The doc says that this "marks end of
line in tibasic". We can see that after "Prgm" in the program
there is a newline. The $E8 has no special parameters but still
has a BYTE tied to it, so we can ignore the next $00. We then
come to #$51E4. We know what $E4 is, Program Token. $51, when
looked up, is... Pause. Pause is classified as "Variable Number
of Parameters". So following this token we should have a param
list terminated by ')' or $E5. Since the original BASIC had no
parameters (I was aware that PAUSE took parameters... :) ), the
next BYTE is $E5. Next we have the "end of line" token again,
#$00E8. Next there is #$12E4... Program token... EndPrgm. The
last BYTE is a $E9, which the documentation says is "end of
tibasic program". And that's all folks. Programs don't get any
easier! :)
Here is a TI-BASIC function in text and in binary*:
:doesmath(a,b)
:Func
:Return ((a+b-a*b)/a)^b
:EndFunc
00 02 04 06 08 0A 0C 0E 0123456789ABCDEF
.....................................
00000000: 001EE90F E400E8E5 0C0B0C8B 0B0C8F8D .........
00000010: 0B919352 E400E817 E4E50C0B 000050DC .R......P
* Binary data formatted by HexConv (c) 1998 Aaron Hill
This gets a little more exciting as we have variables passed in
and get to work with a complicated expression. But the file
breaks down exactly the same as the program. File size: $001E.
Puts the term. byte at $001E + 1 = $001F. Term Byte: $DC. File
is program/function. Flags: $50 -> tokenized. Wierd something
that is always zero: $0000. List of parameters terminated by
a ')' = $E5: 0B and 0C. This is new to us. The doc says that
0B is 'a' and 0C is 'b'. Looks oddly familiar to me! Start of
program tokens... #$17E4 = Func. (End of line... #$00E8) Next
token... #$52E4 = Return. (Also classified as a Variable Number
of Parameters) The next stuff is the expression that is getting
returned:
93 91 0B 8D 8F 0C 0B 8B 0C 0B 0C 35
^ / a - * b a + b a b )
For all of you who can understand that, you are welcome to try
to explain! :) For our purposes, I don't think we need to get
into it. (I believe it's based on RPN) (That's Reverse-Polish-
Notation not Registered-Param-Number)
Continuing on... (End of line, #$00E8) Next token: #$E40F,
EndFunc. Next token: #$E9, End of program.
There, I've left some space for you to SCREAM and then catch
your breath. I've probably explained SO MUCH more than what
you wanted. But I couldn't simply assume that you would know
that I was talking about if I answer simply, "The difference
is #$19E4 for Pgrm and #$17E4 for Func." But now that should
make sense.
Also, to all who have been wondering about files and where to
get the information... FILES.TXT is the BEST resource. I do
not see how or why a WEBSITE dedicated to FILES would beat
looking at a file that is already on your harddrive! ;|
====
Aaron Hill (Redmond, WA)
E-Mail: SeracOhw24@msn.com
IRC-Nick: SeracOhw (EF-Net)