int eapi_extract(easyflash_cart_t * cart) { if (check_header(&cart->main_flash_data[EAPI_OFFSET]) != 0) { return -1; } memcpy(eapi_data, &cart->main_flash_data[EAPI_OFFSET], EAPI_SIZE); strncpy(eapi_name_buf, petscii_to_ascii((const char *)&cart->main_flash_data[EAPI_NAME_OFFSET]), 16); return 0; }
int eapi_inject(easyflash_cart_t * cart, int custom) { const unsigned char *p; if (custom) { if (check_header(eapi_data) != 0) { return -1; } p = eapi_data; } else { p = &eapi_am29f040_prg[2]; } memcpy(&cart->main_flash_data[EAPI_OFFSET], p, EAPI_SIZE); strncpy(eapi_name_buf, petscii_to_ascii((const char *)&cart->main_flash_data[EAPI_NAME_OFFSET]), 16); return 0; }
void log_hexdump2(const char *p, int len, int petscii, const char *prefix) { int tot = 0; int line = 0; int x = 0; const char *spaceprefix = spaces + strlen(spaces) - strlen(prefix); newline = lastlog_anything; color_log_debug(); if(len) { while(tot < len) { if (tot == 0) { printf(LOG_PREFIX "%s%04X ", prefix, tot); } else { printf(LOG_PREFIX "%s%04X ", spaceprefix , tot); } for(x=0; x<16; x++) { if(line+x < len) { tot++; printf("%02X ", 255&p[line+x]); } else printf(" "); if(x == 7) putchar(' '); } printf(" |"); for(x=0; x<16; x++) { if(line+x < len) { int c = p[line+x]; if (petscii) c = petscii_to_ascii(c); if(isprint(c)) putchar(c); else putchar(' '); } else putchar(' '); } printf("|\n"); line = tot; } } color_default(); }
static int find_file(FILE *fp, Disk_Image_t *di, const char *filename, uint8_t *start_track, uint8_t *start_sector, uint8_t *ss_track, uint8_t *ss_sector, uint8_t *reclen, int *flength) { // directory sector uint8_t dirsect[256]; // default *start_track = 0; *ss_track = 0; // dir chain int dir_track = di->DirTrack; int dir_sector = di->DirSector; // walk along the directory chain while (dir_track != 0) { // each slot starts at 2 bytes into the block due to the link address // but we can do as if it started at each $20 boundary read_sector(fp, di, dir_track, dir_sector, dirsect); // iterate slots in file for (int slot = 0; slot < 8; slot++) { int slotp = slot * 0x20; if (dirsect[slotp+2] != 0x84) { log_debug("t/s %d/%d ignoring slot %d, type is %02x\n", dir_track, dir_sector,slot, dirsect[slotp+2]); continue; } int j = 0; // match file name for (j = 0; j < 16; j++) { // printf("match: %c (%02x) with %c (%2x)\n", filename[j], filename[j], //dirsect[slotp+5+j],dirsect[slotp+5+j]); if (filename[j] == 0 || dirsect[slotp + 5 + j] == 0xa0) { break; } if (filename[j] != petscii_to_ascii(dirsect[slotp + 5 + j])) { // files differ break; } } if (filename[j] == 0 && dirsect[slotp + 5 + j] == 0xa0) { // both ended at same char, then they match *start_track = dirsect[slotp + 3]; *start_sector = dirsect[slotp + 4]; *ss_track = dirsect[slotp + 0x15]; *ss_sector = dirsect[slotp + 0x16]; *reclen = dirsect[slotp + 0x17]; *flength = (dirsect[slotp + 0x1e] & 0xff) + (dirsect[slotp + 0x1f] << 8); return 1; } } dir_track = dirsect[BLK_OFFSET_NEXT_TRACK]; dir_sector = dirsect[BLK_OFFSET_NEXT_SECTOR]; } return 0; }