add code to replace bmps in an Image.img file and and an update script

This commit is contained in:
Martin Johnson 2016-12-30 17:39:45 +13:00
parent 32994209ca
commit 2233751243
11 changed files with 381 additions and 1 deletions

View File

@ -1,3 +1,7 @@
all: decode recode
all: decode recode recode110 extractbmp makever fixbmpheader
decode:
recode:
recode110:
extractbmp:
makever:
fixbmpheader:

104
extractbmp.c Normal file
View File

@ -0,0 +1,104 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
FILE *fin,*fout,*iout,*fin1;
typedef struct idx_st {
int start;
int size;
int uncompressed_size;
} idx_type;
typedef struct header_st {
int magic;
int count;
int header_size;
int zero1;
int index_start;
int index_size;
int img_start;
int img_size;
int string_start;
int string_size;
} header_type;
if(argc>2) {
puts("usage: extractbmp [encode]");
exit(1);
}
int encode=0;
if(argc==2 && !strcmp(argv[1],"encode"))
encode=1;
fin=fopen("Image.img","rb");
header_type header;
fread(&header,4,10,fin);
idx_type index[header.count];
char fname[256];
fread(index, sizeof(idx_type), header.count, fin);
printf("%d bitmaps\n", header.count);
int outpos=0;
if(encode) {
iout=fopen("Image1.img","wb");
fwrite(&header,4,10,iout);
fwrite(index, sizeof(idx_type), header.count, iout);
outpos=sizeof(idx_type)*header.count+sizeof(header_type);
}
for(int i=0;i<header.count;i++) {
printf("bmp %d at %d, len %d\n",i, index[i].start, index[i].size);
sprintf(fname,"bmp/b%d.bmp.gz",i);
fout=fopen(fname,"wb");
fseek(fin,index[i].start, SEEK_SET);
for(int j=0;j<index[i].size;j++)
fputc(fgetc(fin),fout);
fclose(fout);
if(encode) {
sprintf(fname,"bmp1/b%d.bmp.gz",i);
fin1=fopen(fname,"rb");
if(!fin1) {
printf("%s not found\n",fname);
exit(1);
}
int l=0;
index[i].start=outpos;
while(!feof(fin1)) {
char c=fgetc(fin1);
if(!feof(fin1)) {
fputc(c,iout);
l++;
}
}
fclose(fin1);
index[i].size=l;
outpos+=l;
sprintf(fname,"bmp1/b%d.bmp",i);
fin1=fopen(fname,"rb");
if(fin1) {
fseek(fin1, 0L, SEEK_END);
index[i].uncompressed_size = ftell(fin1);
fclose(fin1);
}
}
// sprintf(fname,"gzip -d bmp/b%d.bmp.gz",i);
// system(fname);
}
char strings[header.string_size];
fseek(fin,header.string_start,SEEK_SET);
fout=fopen("bmp_names","wb");
fread(strings,1,header.string_size,fin);
fwrite(strings,1,header.string_size,fout);
fclose(fout);
if(encode) {
fwrite(strings,1,header.string_size,iout);
fseek(iout, 0, SEEK_SET);
header.img_size=outpos-index[0].start;
header.string_start=outpos;
fwrite(&header,4,10,iout);
fwrite(index, sizeof(idx_type), header.count, iout);
}
}

54
fixbmpheader.c Normal file
View File

@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
FILE *fin,*fout;
typedef struct __attribute__((__packed__)) bmp_st {
short sig;
int size;
int reserved;
int offset;
int dib_size;
int width;
int height;
short planes;
short bpp;
int compression;
int img_size;
int xppm;
int yppm;
int cols;
int ccnt;
} bmp_h_type;
if(argc!=3) {
puts("error");
exit(1);
}
fin=fopen(argv[1],"rb");
fout=fopen(argv[2],"wb");
bmp_h_type header;
fread(&header,1,sizeof(header),fin);
char z[16];
fread(z,1,16,fin);
header.size-=16;
header.offset-=16;
header.dib_size-=16;
header.compression=0;
header.xppm=0;
header.yppm=0;
header.cols=0;
header.ccnt=0;
fwrite(&header,1,sizeof(header),fout);
while(!feof(fin)) {
char c=fgetc(fin);
if(!feof(fin))
fputc(c,fout);
}
}

BIN
imageupdate/Image.img Normal file

Binary file not shown.

BIN
imageupdate/PF090JPJPN.LNG Normal file

Binary file not shown.

BIN
imageupdate/PF110JPJPN.LNG Normal file

Binary file not shown.

View File

@ -0,0 +1,24 @@
COLOR 48
ECHO
ECHO Language Installer for MRZ99 by Dzo
ECHO
SLEEP 3000
ERROR OFF
ECHO ON
COPY -c USB\Image.img USER\PRG1\APL\MENU\Image.img
COPY -c USB\Image.img USER\PRG0\APL\MENU\Image.img
COPY -c USB\PF090JPJPN.LNG USER\PRG1\APL\LANGDATA\PF090JPJPN.LNG
COPY -c USB\PF090JPJPN.LNG USER\PRG0\APL\LANGDATA\PF090JPJPN.LNG
COPY -c USB\PF110JPJPN.LNG USER\PRG1\APL\LANGDATA\PF110JPJPN.LNG
COPY -c USB\PF110JPJPN.LNG USER\PRG0\APL\LANGDATA\PF110JPJPN.LNG
COLOR 21
ECHO
ECHO
ECHO Done
ECHO
ECHO
ECHO
SLEEP 5000
RESET
ECHO RESET
RESET 1

BIN
imageupdate/TESTMODE.KEY Normal file

Binary file not shown.

96
makever.c Normal file
View File

@ -0,0 +1,96 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct header_st {
int magic; // 0xa55a5aa5
int len; // len of ver file
int version;
int volume; //1
int zero1;
int a2c; //2c
int zeros[5];
int nfiles; //1
int dirdepth; //1
char dirname[64];
int filestoprocess; //1
char filename[56];
int file_length;
int file_crc;
int magic1; // 0xa55a5aa5
int ver_crc; // up to and including magic1
} header_type;
void wscpy(char *d, char *s) {
while (*s) {
*d++=*s++;
d++;
}
}
int crc16a(unsigned char * data_p, int len) {
unsigned char x;
unsigned short crc = 0xFFFF;
while (len--){
x = crc >> 8 ^ *data_p++;
x ^= x>>4;
crc = (crc << 8) ^ ((unsigned short)(x << 12)) ^ ((unsigned short)(x <<5)) ^ ((unsigned short)x);
}
return crc;
}
unsigned short crc16(const unsigned char *data, int len) {
unsigned short crc = 0xFFFF;
int i;
if (len) do {
crc ^= *data++;
for (i=0; i<8; i++) {
if (crc & 1) crc = (crc >> 1) ^ 0x8408;
else crc >>= 1;
}
} while (--len);
return(~crc);
}
int main(int argc, char *argv[]) {
header_type h;
FILE *fin,*fout;
memset(&h, 0, sizeof(h));
char *dir="OPN090";
char *datfile="NA090OPN.DAT";
if(argc>=2)
datfile=argv[1];
if(argc>=3)
dir=argv[2];
h.magic=0xa55a5aa5;
h.len=sizeof(h);
h.version=0x04000000;
h.volume=1;
h.a2c=0x2c;
h.nfiles=1;
h.dirdepth=1;
wscpy(h.dirname,dir);
h.filestoprocess=1;
wscpy(h.filename,datfile);
fin=fopen(datfile,"rb");
fseek(fin, 0L, SEEK_END);
h.file_length = ftell(fin);
unsigned char *p=malloc(h.file_length);
rewind(fin);
fread(p,1,h.file_length,fin);
h.file_crc=crc16(p,h.file_length);
h.magic1=0xa55a5aa5;
h.ver_crc=crc16((unsigned char *)&h, h.len-4);
fout=fopen("NA090OPN.VER","wb");
fwrite(&h,1,h.len,fout);
fclose(fout);
}

98
recode110.c Normal file
View File

@ -0,0 +1,98 @@
#include <stdio.h>
#include <string.h>
void readstring(FILE *f, char *p) {
char c;
c=fgetc(f);
if(c!='\"')
puts("ERRRRRRRR");
while((c=fgetc(f))!='"' && !feof(f))
*p++=c;
*p++=0;
while((c=fgetc(f))!=10 && !feof(f));
}
int main(int argc,char *argv[]) {
char data[200000];
char st[10240];
FILE *f,*g;
int i;
unsigned *id=(unsigned *) data;
id[0]=0xa55a5aa5;
id[1]=0x01000001;
id[2]=0x39304650;
id[3]=0x45504a30;
id[4]=0;
id[5]=0;
id[6]=0;// len
id[7]=0x40;
id[8]=0;//last
id[9]=0xaaaaaa02;
id[10]=0xaaaaaaaa;
id[11]=0xaaaaaaaa;
id[12]=0xaaaaaaaa;
id[13]=0xaaaaaaaa;
id[14]=0xaaaaaaaa;
id[15]=0xaaaaaaaa;
g=fopen("translated_110.txt","rb");
f=fopen("PF110JPJPN.LNG","rb");
int start=0x40;
unsigned short *idx=(unsigned short *)(data+0x40);
fseek(f,0x40,SEEK_SET);
short nstrings;
int offset=0;
int next=0;
short ch;
fread(&nstrings, 2, 1, f);
nstrings=nstrings-3;
unsigned short *strptr=idx+nstrings;
int off=0x40+(nstrings+3)*2;
int ntrans=0;
for(i=0;i<nstrings;i++) {
fseek(f,0x40+i*2,SEEK_SET);
offset=0;
fread(&offset, 2, 1, f);
offset=offset*2+0x40;
next=0;
fread(&next, 2, 1, f);
next=next*2+0x40;
ch=1;
putchar('"');
fseek(f,offset,SEEK_SET);
while(offset<next-2) {
fread(&ch,2,1,f);
offset+=2;
putchar(ch&127);
}
putchar('"');
putchar(10);
readstring(g,st);
puts(st);
idx[i]=(off-0x40)/2;
if((off-0x40)/2>65535)
printf("Error index too large %x\n",(off-0x40)/2);
int j=0;
for(j=0;st[j]!=0;j++) {
data[off++]=st[j];
data[off++]=0;
}
data[off++]=0;
data[off++]=0;
}
idx[i]=(off-0x40)/2;
id[8]=off;
strcpy(data+off,"RG_VOICE_DATA");
off+=strlen("RG_VOICE_DATA");
data[off++]=0xf1; // this looks like a checksum at the end of the file but
data[off++]=0x8d; // it doesn't seem to matter if it's wrong
id[6]=off;
printf("%d strings\n",nstrings);
f=fopen("PF110JPJPN1.LNG","wb");
fwrite(data,off,1,f);
fclose(f);
}

BIN
updatemrz99.zip Normal file

Binary file not shown.