Created
May 9, 2025 20:42
-
-
Save JettMonstersGoBoom/985a75461f09ebfa7b64b609cb1a3d4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
// make bin\mini.xex with mini.raw at $400 and spritedata at $10000 ( bank 1 ) | |
// xex -o bin\mini.xex -a 400 bin\mini.raw -a 10000 resources\prince.spr | |
// -o output.xex | |
// -a address ( in hex ) filename | |
void fputw(uint16_t word, FILE *file) | |
{ | |
fputc(word & 0xFF, file); | |
fputc(word >> 8, file); | |
} | |
void fput_header(uint16_t offset, uint16_t size, FILE *file) | |
{ | |
fputw(offset, file); // from | |
fputw(offset + size - 1, file); // to | |
} | |
void main(int argc,char *argv[]) | |
{ | |
uint32_t address=0; | |
FILE *fout = NULL; | |
for (int q=1;q<argc;q++) | |
{ | |
if (argv[q][0]=='-') | |
{ | |
switch(argv[q][1]) | |
{ | |
case 'a': | |
{ | |
address = strtoul(argv[q+1],NULL,16); | |
q+=1; | |
break; | |
} | |
case 'o': | |
{ | |
fout = fopen(argv[q+1],"wb"); | |
fputw(0xffff,fout); | |
q+=1; | |
break; | |
} | |
default: | |
{ | |
} | |
} | |
} | |
else | |
{ | |
if (fout==NULL) | |
{ | |
printf("Err: no outputfile specified\n"); | |
return; | |
} | |
printf("file %s\t",argv[q]); | |
// read the file into a buffer | |
char *data; | |
int length; | |
FILE *fin = fopen(argv[q],"rb"); | |
fseek(fin,0,SEEK_END); | |
length = ftell(fin); | |
fseek(fin,0,SEEK_SET); | |
data = calloc(length+1,1); | |
fread(data,1,length,fin); | |
fclose(fin); | |
// output bank info | |
uint8_t bank = address>>16; | |
printf("addr $%04X bank $%02X length $%x\n",address&0xffff,bank,length); | |
// output current bank | |
fput_header(0xfffe,1,fout); | |
fputc(bank,fout); | |
// output destination address | |
fput_header(address&0xffff,length,fout); | |
// output data itself | |
fwrite(data,1,length,fout); | |
// free this data block | |
free(data); | |
// we normally override address, this moves address to the end of last loaded file | |
address += length; | |
} | |
} | |
if (fout!=NULL) | |
fclose(fout); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment