Past few days been working on an 8xk disassembler. So far i only have one that will take an 8xk and turn it into the bin files of its pages , for example it turns Axe.8xk into page1.bin and page2.bin. Now to work on parsing the app header ( I really dont want to do this and its a miracle I got this far, pls someone else write this ).

An exe and source is available here but not approved yet.

Edit : I realized i don't actually know how long it'll take for the file to get approved so I am posting the current source code here for now.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <inttypes.h>

#define ASCFX 'A'-'0'-0xA

#define xkHeader 0x5F

typedef struct {
   char hex[2];
} hexString;

uint8_t charToHex(hexString string) {
   string.hex[0] -= '0';
   string.hex[1] -= '0';
   
   if (string.hex[0] > 9) {
      string.hex[0] -= ASCFX;
   }
   
   if (string.hex[1] > 9) {
      string.hex[1] -= ASCFX;
   }
   
   return (string.hex[0] << 4) + string.hex[1];
}

uint8_t* stringToHexArray(char* hexLine) {
   hexString currByte;
   uint8_t* hexArray = malloc(strlen(hexLine)*sizeof(uint8_t)/2);
   
   for (int i=0; i<strlen(hexLine); i +=2 ) {
      strncpy(currByte.hex,hexLine+i,2);
      hexArray[i/2] = charToHex(currByte);
   }
   
   return hexArray;
}
int main(int argc, char* argv[]) {
   FILE *xkFile, *binFile;
   
   if (argc != 2) {
      puts("\nUsage: 8xkToAsm 8xkFile\n");
      return 1;
   }
   
   xkFile = fopen(argv[1],"r");
   if (xkFile == NULL) {
      puts("\nFailed to open 8xk File\n");
      return 1;
   }
   
   fseek(xkFile,0,SEEK_END);
   
   size_t xkSize = ftell(xkFile);
   if (xkSize < 0x5F) {
      puts("\nNo data to be disassembled\n");
      return 1;
   }
   
   fseek(xkFile,xkHeader,SEEK_SET);
   
   int pageIndex = 0;
   int writePage = 0;
   
   char line[1024];
   char page[16384];
   char pageName[10];
   
   memset(page,0xff,sizeof(page));
   
   while (fgets(line, sizeof(line), xkFile)) {
       size_t len = strlen(line);
       while (len > 0 && (line[len-1] == '\n' || line[len-1] == '\r')) {
           line[--len] = '\0';
       }
      char *hexPart = line + 1;
       if (line[0] != ':') {
         puts("\nCannot handel this hex file\n");
         return 1;
      }
      uint8_t *currLine = stringToHexArray(hexPart);
      int length = currLine[0];
      int type = currLine[3];
      int address = (currLine[1] << 8) | currLine[2];
      
      if ( ! ( address < 0x8000 ) && ( address > 0x3fff) ) {
         free(currLine);
         continue;
      }
      if (type == 0) {
         if ( address == 0x4000 ) {
            if ( pageIndex > 0 ) {
               sprintf(pageName,"page%d.bin",pageIndex);
               binFile = fopen(pageName,"wb");
               fwrite(page,1,16384,binFile);
               fclose(binFile);
            }
            memset(page,0xff,sizeof(page));
            pageIndex++;
         }
         for (int i=0; i<length; i++) {
            page[address + i - 0x4000 ] = currLine[4+i];
         }
      } else if ( type == 1 ) {
         writePage = 1;
         free(currLine);
         break;
      }
      free(currLine);
      // rest of parsing and filing code
   }
   if (writePage) {
         sprintf(pageName,"page%d.bin",pageIndex);
         binFile = fopen(pageName,"wb");
         fwrite(page,1,16384,binFile);
         fclose(binFile);
   }
   fclose(xkFile);
   return 0;   
}
The file has been approved 🙂

I also have a beta that tells where execution starts, now to start writing the decomper. (I cant use an established one as I want a better experience with bcalls (the closest good thing was z80dismblr on github).
This project is done

I rewrote the project with copilot in python and it seems to work.
The github is here and the cemetech archive file is pending.
Bug reports are welcome here and on github. 🙂
I asked from claude to do review and check if there is any bugs etc, here is response:
I'll review this C code that appears to convert TI-83/84 calculator 8xk files to binary format. I found several bugs and areas for improvement:

[size=150]Critical Bugs[/size]

1. Incorrect Address Range Logic

Code:

if ( ! ( address < 0x8000 ) && ( address > 0x3fff) ) {

BUG: This logic is inverted! It currently means "if address >= 0x8000 AND address > 0x3fff, skip". This would skip valid addresses >= 0x8000.

Fix:

Code:

if (address < 0x4000 || address >= 0x8000) {
    free(currLine);
    continue;
}


2. Buffer Overflow Risk

Code:

for (int i=0; i<length; i++) {
   page[address + i - 0x4000 ] = currLine[4+i];
}

BUG: No bounds checking! If [c]address + length > 0x8000[/c], this writes past the 16384-byte page buffer.

Fix:

Code:

if (address + length - 0x4000 > 16384) {
    puts("\nData exceeds page boundary\n");
    free(currLine);
    continue;
}


3. Missing Error Handling for ftell

Code:

size_t xkSize = ftell(xkFile);
if (xkSize < 0x5F) {

BUG: [c]ftell[/c] returns [c]long[/c] and returns [c]-1[/c] on error. Using [c]size_t[/c] (unsigned) makes the error check fail.

Fix:

Code:

long xkSize = ftell(xkFile);
if (xkSize < 0) {
    puts("\nFailed to determine file size\n");
    fclose(xkFile);
    return 1;
}
if (xkSize < 0x5F) {


[size=150]Moderate Issues[/size]

4. No Lowercase Hex Support
[c]charToHex()[/c] only handles uppercase A-F, not a-f.

Fix:

Code:

uint8_t charToHex(hexString string) {
    string.hex[0] -= '0';
    string.hex[1] -= '0';
   
    if (string.hex[0] > 9) {
        string.hex[0] -= (string.hex[0] >= ('A' - '0')) ? ASCFX : ('a' - '0' - 0xA);
    }
    if (string.hex[1] > 9) {
        string.hex[1] -= (string.hex[1] >= ('A' - '0')) ? ASCFX : ('a' - '0' - 0xA);
    }
   
    return (string.hex[0] << 4) + string.hex[1];
}


5. Missing NULL Checks
No checks for [c]malloc()[/c] or [c]fopen()[/c] failures.

Add:

Code:

uint8_t* hexArray = malloc(strlen(hexLine)/2);
if (hexArray == NULL) {
    return NULL;
}

binFile = fopen(pageName,"wb");
if (binFile == NULL) {
    puts("\nFailed to create output file\n");
    continue;
}


6. Inefficient strlen() in Loop

Code:

for (int i=0; i<strlen(hexLine); i +=2 )

Calls [c]strlen()[/c] every iteration.

Fix:

Code:

size_t len = strlen(hexLine);
for (int i=0; i<len; i +=2)


[size=150]Minor Improvements[/size]


  • 7. Typo: "handel" → "handle"
  • 8. Redundant: [c]sizeof(uint8_t)[/c] is always 1
  • 9. Missing: No Intel HEX checksum validation
  • 10. strncpy safety: While it works, consider explicitly setting bounds or using memcpy for the 2-byte copy


[size=150]Performance & Safety Score[/size]

  • Memory safety: 3/10 (multiple buffer overflow risks)
  • Error handling: 4/10 (missing many checks)
  • Correctness: 5/10 (critical logic bug)
This project is no longer in C, if you check the github or the archives then you will see that it is in python.
Okay, for that I could even do some review without AI, some issues might still apply.
  
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
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement