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:
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;
}