Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's General Open Topic subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Open Topic & United-TI Talk => General Open Topic
Author Message
bxsciencer


Newbie


Joined: 13 Mar 2009
Posts: 11

Posted: 21 Aug 2010 12:01:31 am    Post subject:

Does anyone have a correct description of the .8xp file format? im trying to get 2 particular parts: what are bytes 0x44-0x45 (first byte is position 0) and how do you get them. ive read instructions saying just use \x00\x00, but that doesnt work. pretending they are part of the comments section doesnt work either

and how/where do you get the size of the program on the calc?

i cannot for the life of me get these two strings to work when i parse txt files i created (from existing programs that i dumped with the same program).
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 21 Aug 2010 01:54:44 am    Post subject:

0x00--0x32: Header and comment
0x33--0x34: Length of data section
0x35--0x43: Variable header
0x44--0x45: Variable length
0x46--0x47: Variable length
0x48: Program data
Don't forget to add the checksum at the end.

The length field is needed three times. The first, it specifies the length of the data section. The second time, it specifies the length of the variable. The third time, it is part of the program variable. You specify the same length each time, though.

The following is some code I quickly threw together for a project.

Code:
[code]
        /// <summary>
        /// Exports the font into the 8xv format.
        /// </summary>
        /// <param name="path">The file to write the font to.</param>
        public void Export(string path)
        {
            byte[] header = new byte[]
            {
                // TI File format header
                (byte)'*', (byte)'*', (byte)'T', (byte)'I', // 03
                (byte)'8', (byte)'3', (byte)'F', (byte)'*', // 07
                // More header and comment
                26, 10, 0, (byte)'F', (byte)'i', (byte)'l', // 0B
                (byte)'e', (byte)' ', (byte)'g', (byte)'e', // 0F
                (byte)'n', (byte)'e', (byte)'r', (byte)'a', // 13
                (byte)'t', (byte)'e', (byte)'d', (byte)' ', // 17
                (byte)'b', (byte)'y', (byte)' ', (byte)'P', // 1B
                (byte)'A', (byte)'T', (byte)' ', (byte)'F', // 1F
                (byte)'o', (byte)'n', (byte)'t', (byte)' ', // 23
                (byte)'E', (byte)'d', (byte)'i', (byte)'t', // 27
                (byte)'o', (byte)'r', (byte)'.', (byte)' ', // 2B
                (byte)' ', (byte)' ', (byte)' ', (byte)' ', // 2F
                (byte)' ', (byte)' ', (byte)' ', // 32
                // Space for length field
                0, 0, // 34
                // Variable header
                13, 0, // type // 36
                0, 0, // length word // 38
                21, // type // 39
                0, 0, 0, 0, 0, 0, 0, 0, // prgm name // 41
                0, 128, // flags // 43
                0, 0, // length
                0, 0, // length for the third time
                // Font file header
                0xBB, 0x6D, 0xC9, // compiled prgm token and ret instruction
                (byte)'f', (byte)'o', (byte)'n', (byte)'t', // magic word
                0, 0, // version
            }; //16192
            byte[] data = new byte[32768]; // If you make a font this large, you've got problems.
            for (int i = 0; i < header.Length; i++)
                data[i] = header[i];
            // Write program name
            int bytes = 0x3C;
            for (int i = 0; i < calcName.Length; i++)
                data[bytes++] = (byte)calcName[i];
            // THIS SECTION GENERATES THE PROGRAM DATA
            // Write metadata
            bytes = 0x55;
            for (int i = 0; i < FontName.Length; i++)
                data[bytes++] = (byte)FontName[i];
            bytes++;
            for (int i = 0; i < FontDescription.Length; i++)
                data[bytes++] = (byte)FontDescription[i];
            bytes++;
            for (int i = 0; i < 8; i++)
                data[bytes++] = (byte)fontEncoding[i];
            // Update metadata length word
            int length = bytes - 0x55;
            data[0x53] = (byte)(length & 0xFF);
            data[0x54] = (byte)(length >> 8);
            // Height
            data[bytes++] = (byte)height;
            // Write widths
            for (int chr = 0; chr < 256; chr++)
                data[bytes++] = (byte)this[chr].Width;
            // Write bitmaps
            for (int row = 0; row < height; row++)
                for (int chr = 0; chr < 256; chr++)
                    data[bytes++] = this[chr].rawReadLine(row);
            // END PROGRAM DATA
            // Update length fields
            length = (bytes - 0x4A);
            byte lenHigh = (byte)(length >> 8);
            byte lenLow = (byte)(length & 0xFF);
            data[0x39] = lenLow;
            data[0x3A] = lenHigh;
            data[0x46] = lenLow;
            data[0x47] = lenHigh;
            data[0x48] = lenLow;
            data[0x49] = lenHigh;
            length = (bytes - 0x37);
            lenHigh = (byte)(length >> 8);
            lenLow = (byte)(length & 0xFF);
            data[0x35] = lenLow;
            data[0x36] = lenHigh;
            // Calculate checksum
            int checksum = 0;
            for (int i = 0x37; i < bytes; i++)
                checksum = (checksum + data[i]) % 65536;
            data[bytes++] = (byte)(checksum & 0xFF);
            data[bytes++] = (byte)(checksum >> 8);
            // Copy data and write
            byte[] finalData = new byte[bytes];
            for (int i = 0; i < bytes; i++)
                finalData[i] = data[i];
            // Write out file
            System.IO.File.WriteAllBytes(path, finalData);
        }
[/code]
Back to top
bxsciencer


Newbie


Joined: 13 Mar 2009
Posts: 11

Posted: 21 Aug 2010 09:20:55 am    Post subject:

im sorry but that doesnt seem to make sense. from what ive been able to tell, there are only 4 possibilities for the bytes: 00 or 01 for the first byte and 00 or 80 for the second byte, but i have no idea how to chose between them. changing a 01 00 to a 01 80 causes errors

Last edited by Guest on 21 Aug 2010 09:27:19 am; edited 1 time in total
Back to top
calcdude84se


Member


Joined: 09 Aug 2009
Posts: 207

Posted: 21 Aug 2010 11:35:46 am    Post subject:

Hopefully I won't repeat too much of what Dr. D'nar said.
The two bytes you are talking about are the version byte and the byte used to indicate archived status. The version is normally 0, and the second byte is \x00 if in RAM, \x80 otherwise. The only thing that might be causing errors is an incorrect checksum, which is the sum of all the bytes in the data section (Right after the first length field) mod 2^16.
If you need some C, I can write some up Smile
Back to top
bxsciencer


Newbie


Joined: 13 Mar 2009
Posts: 11

Posted: 21 Aug 2010 12:29:26 pm    Post subject:

thanks, but im almost done with my python program. for some reason, i cant understand c. also, strangely, i am never able to run c code, ever, even with c/c++ developer or whatever the program is called

Last edited by Guest on 21 Aug 2010 12:30:12 pm; edited 1 time in total
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 21 Aug 2010 03:23:32 pm    Post subject:

Python, you say?


Code:
[code]#!/usr/bin/python
# This program converts an 8xi to an 8xv.  It is very much written more in the
# style of Assembly language than Python.  You have been warned.
import sys
from struct import *

###### Constants ###############################################################
errArgs = 1
errName = 2
errFile = 3

###### #########################################################################
print """8xp to 8xv Converter
November 1, 2008
Dr. D'nar"""

###### Process Arguments #######################################################
if len(sys.argv) != 4:
   print "Usage: pictoappvar 8xp 8xv newPrgmName"
   sys.exit(errArgs)

newName = sys.argv[3]

if len(newName) > 8:
    print "Error: Name too long."
    sys.exit(errName)

print """
Processing file. . ."""
infile = open(sys.argv[1], 'rb')
outfile = open(sys.argv[2], 'wb')

###### Process First Header ####################################################
header1 = unpack("8s3s42s",infile.read(53)) #>: Big endian
magicword1, magicword2, filecomment = header1
if magicword1 != "**TI83F*":
    print "Error: Infile does not appear to be a TI-83 variable at all."
    sys.exit(errFile)
if magicword2 != "\x1A\x0A\x00":
    print "Error: Infile does not appear to be a TI-83 variable at all."
    sys.exit(errFile)
print "File comment:", filecomment
datalength = unpack("<H", infile.read(2)) #short should be 16-bit, change if not
datalength, = datalength
header2 = unpack("<HHc8sccH",infile.read(17))
if 1==1:
    print "Second header data:"
    print "Unknown:", hex(header2[0])
    print "Length:", header2[1]
    print "ID:", hex(ord(header2[2])) #"ID: %1X" % (ord(header2[2a]))
    print "Name:", header2[3]
    print "Version:", hex(ord(header2[4]))
    print "Flag:", hex(ord(header2[5]))
    print "Length:", header2[6]
if header2[1] != header2[6]:
    print "Error: Format (Lengths do not match.)"
    sys.exit(errFile)
if header2[2] != '\x07':
    print "Error: Not a picture!"
    sys.exit(errFile)
filedata = infile.read(header2[1])

###### Generate new header #####################################################
#header = '\x0D'+hex(header2[1])
#print hex(header2[1])#''.join([hex(ord(x))[2:] for x in header])

outfile.write(pack("8s3s42s", magicword1, magicword2, filecomment))
outdata = pack("<HHc8sccH", 0x0D, header2[1], chr(0x15), newName, chr(0), chr(0x80), header2[1])
outdata = outdata + filedata
outfile.write(pack("<H", len(outdata)))

###### Calculate checksum ######################################################
checksum = 0
for char in outdata:
    checksum = ord(char) + checksum

###### Finish writing file #####################################################

outfile.write(outdata)
outfile.write(pack("<H", checksum))

###### Done ####################################################################
print """
Done."""
infile.close()
outfile.close()[/code]
Back to top
bxsciencer


Newbie


Joined: 13 Mar 2009
Posts: 11

Posted: 21 Aug 2010 04:07:00 pm    Post subject:

why is it that i never understand how other people's programs work? where does the output file go? i cant seem to find it
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 21 Aug 2010 04:30:10 pm    Post subject:

bxsciencer wrote:
where does the output file go?
It should go in the current directory, unless you specified a different directory in the argument.


bxsciencer wrote:
why is it that i never understand how other people's programs work?
I don't know. The program reads in the input file, process the header and makes sure it's valid, generates a new header, copies the data portion out of the first file and into the second, and then calculates the checksum.
Back to top
bxsciencer


Newbie


Joined: 13 Mar 2009
Posts: 11

Posted: 21 Aug 2010 08:57:53 pm    Post subject:

How's this (http://calccrypto.wikidot.com/local--files/files/8xptxt.zip)? i would just show the code here, but the tokens and related stuff take up 50kb. the rest of it is 6kb or so
where do attached files get placed here? i cant seem to find it


Last edited by Guest on 21 Aug 2010 09:01:00 pm; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 

Advertisement