|
@@ -34,28 +34,6 @@
|
|
|
snes_romprops_t romprops;
|
|
|
|
|
|
uint32_t hdr_addr[6] = {0xffb0, 0x101b0, 0x7fb0, 0x81b0, 0x40ffb0, 0x4101b0};
|
|
|
-uint8_t countAllASCII(uint8_t* data, int size) {
|
|
|
- uint8_t res = 0;
|
|
|
- do {
|
|
|
- size--;
|
|
|
- if(data[size] >= 0x20 && data[size] <= 0x7e) {
|
|
|
- res++;
|
|
|
- }
|
|
|
- } while (size);
|
|
|
- return res;
|
|
|
-}
|
|
|
-
|
|
|
-uint8_t countAllJISX0201(uint8_t* data, int size) {
|
|
|
- uint8_t res = 0;
|
|
|
- do {
|
|
|
- size--;
|
|
|
- if((data[size] >= 0x20 && data[size] <= 0x7e)
|
|
|
- ||(data[size] >= 0xa1 && data[size] <= 0xdf)) {
|
|
|
- res++;
|
|
|
- }
|
|
|
- } while (size);
|
|
|
- return res;
|
|
|
-}
|
|
|
|
|
|
uint8_t isFixed(uint8_t* data, int size, uint8_t value) {
|
|
|
uint8_t res = 1;
|
|
@@ -72,7 +50,7 @@ uint8_t checkChksum(uint16_t cchk, uint16_t chk) {
|
|
|
uint32_t sum = cchk + chk;
|
|
|
uint8_t res = 0;
|
|
|
if(sum==0x0000ffff) {
|
|
|
- res = 0x10;
|
|
|
+ res = 1;
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
@@ -87,32 +65,13 @@ void smc_id(snes_romprops_t* props) {
|
|
|
props->fpga_features = 0;
|
|
|
props->fpga_conf = NULL;
|
|
|
for(uint8_t num = 0; num < 6; num++) {
|
|
|
- if(!file_readblock(header, hdr_addr[num], sizeof(snes_header_t))
|
|
|
- || file_res) {
|
|
|
- score = 0;
|
|
|
- } else {
|
|
|
- score = smc_headerscore(header)/(1+(num&1));
|
|
|
- if((file_handle.fsize & 0x2ff) == 0x200) {
|
|
|
- if(num&1) {
|
|
|
- score+=20;
|
|
|
- } else {
|
|
|
- score=0;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if(!(num&1)) {
|
|
|
- score+=20;
|
|
|
- } else {
|
|
|
- score=0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-//printf("%d: offset = %lX; score = %d\n", num, hdr_addr[num], score); // */
|
|
|
+ score = smc_headerscore(hdr_addr[num], header);
|
|
|
+ printf("%d: offset = %lX; score = %d\n", num, hdr_addr[num], score); // */
|
|
|
if(score>=maxscore) {
|
|
|
score_idx=num;
|
|
|
maxscore=score;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if(score_idx & 1) {
|
|
|
props->offset = 0x200;
|
|
|
} else {
|
|
@@ -163,7 +122,7 @@ void smc_id(snes_romprops_t* props) {
|
|
|
(header->map == 0x30 && header->carttype == 0x05 && header->licensee != 0xb2)) {
|
|
|
props->has_dspx = 1;
|
|
|
props->fpga_features |= FEAT_DSPX;
|
|
|
- // Pilotwings uses DSP1 instead of DSP1B
|
|
|
+ /* Pilotwings uses DSP1 instead of DSP1B */
|
|
|
if(!memcmp(header->name, "PILOTWINGS", 10)) {
|
|
|
props->dsp_fw = DSPFW_1;
|
|
|
} else {
|
|
@@ -236,17 +195,86 @@ void smc_id(snes_romprops_t* props) {
|
|
|
if(props->ramsize_bytes > 32768 || props->ramsize_bytes < 2048) {
|
|
|
props->ramsize_bytes = 0;
|
|
|
}
|
|
|
+ props->region = (header->destcode <= 1 || header->destcode >= 13) ? 0 : 1;
|
|
|
+
|
|
|
/*dprintf("ramsize_bytes: %ld\n", props->ramsize_bytes); */
|
|
|
}
|
|
|
|
|
|
-uint8_t smc_headerscore(snes_header_t* header) {
|
|
|
- uint8_t score=0;
|
|
|
- score += countAllASCII(header->maker, sizeof(header->maker));
|
|
|
- score += countAllASCII(header->gamecode, sizeof(header->gamecode));
|
|
|
- score += isFixed(header->fixed_00, sizeof(header->fixed_00), 0x00);
|
|
|
- score += countAllJISX0201(header->name, sizeof(header->name));
|
|
|
- score += 3*isFixed(&header->licensee, sizeof(header->licensee), 0x33);
|
|
|
- score += checkChksum(header->cchk, header->chk);
|
|
|
+uint8_t smc_headerscore(uint32_t addr, snes_header_t* header) {
|
|
|
+ int score=0;
|
|
|
+ uint8_t reset_inst;
|
|
|
+ uint16_t header_offset;
|
|
|
+ if((addr & 0xfff) == 0x1b0) {
|
|
|
+ header_offset = 0x200;
|
|
|
+ } else {
|
|
|
+ header_offset = 0;
|
|
|
+ }
|
|
|
+ if((file_readblock(header, addr, sizeof(snes_header_t)) < sizeof(snes_header_t))
|
|
|
+ || file_res) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ uint8_t mapper = header->map & ~0x10;
|
|
|
+ uint16_t resetvector = header->vect_reset; /* not endian safe! */
|
|
|
+ uint32_t file_addr = (((addr - header_offset) & ~0x7fff) | (resetvector & 0x7fff)) + header_offset;
|
|
|
+ if(resetvector < 0x8000) return 0;
|
|
|
+
|
|
|
+ score += 2*isFixed(&header->licensee, sizeof(header->licensee), 0x33);
|
|
|
+ score += 4*checkChksum(header->cchk, header->chk);
|
|
|
+ if(header->carttype < 0x08) score++;
|
|
|
+ if(header->romsize < 0x10) score++;
|
|
|
+ if(header->ramsize < 0x08) score++;
|
|
|
+ if(header->destcode < 0x0e) score++;
|
|
|
+
|
|
|
+ if((addr-header_offset) == 0x007fc0 && mapper == 0x20) score += 2;
|
|
|
+ if((addr-header_offset) == 0x00ffc0 && mapper == 0x21) score += 2;
|
|
|
+ if((addr-header_offset) == 0x007fc0 && mapper == 0x22) score += 2;
|
|
|
+ if((addr-header_offset) == 0x40ffc0 && mapper == 0x25) score += 2;
|
|
|
+
|
|
|
+ file_readblock(&reset_inst, file_addr, 1);
|
|
|
+ switch(reset_inst) {
|
|
|
+ case 0x78: /* sei */
|
|
|
+ case 0x18: /* clc */
|
|
|
+ case 0x38: /* sec */
|
|
|
+ case 0x9c: /* stz abs */
|
|
|
+ case 0x4c: /* jmp abs */
|
|
|
+ case 0x5c: /* jml abs */
|
|
|
+ score += 8;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0xc2: /* rep */
|
|
|
+ case 0xe2: /* sep */
|
|
|
+ case 0xad: /* lda abs */
|
|
|
+ case 0xae: /* ldx abs */
|
|
|
+ case 0xac: /* ldy abs */
|
|
|
+ case 0xaf: /* lda abs long */
|
|
|
+ case 0xa9: /* lda imm */
|
|
|
+ case 0xa2: /* ldx imm */
|
|
|
+ case 0xa0: /* ldy imm */
|
|
|
+ case 0x20: /* jsr abs */
|
|
|
+ case 0x22: /* jsl abs */
|
|
|
+ score += 4;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x40: /* rti */
|
|
|
+ case 0x60: /* rts */
|
|
|
+ case 0x6b: /* rtl */
|
|
|
+ case 0xcd: /* cmp abs */
|
|
|
+ case 0xec: /* cpx abs */
|
|
|
+ case 0xcc: /* cpy abs */
|
|
|
+ score -= 4;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x00: /* brk */
|
|
|
+ case 0x02: /* cop */
|
|
|
+ case 0xdb: /* stp */
|
|
|
+ case 0x42: /* wdm */
|
|
|
+ case 0xff: /* sbc abs long indexed */
|
|
|
+ score -= 8;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(score && addr > 0x400000) score += 4;
|
|
|
+ if(score < 0) score = 0;
|
|
|
return score;
|
|
|
}
|
|
|
|