-#define buopen(mcd) { \
- strcpy(FDesc[1 + mcd].name, Ra0+5); \
- FDesc[1 + mcd].offset = 0; \
- FDesc[1 + mcd].mode = a1; \
- \
- for (i=1; i<16; i++) { \
- ptr = Mcd##mcd##Data + 128 * i; \
- if ((*ptr & 0xF0) != 0x50) continue; \
- if (strcmp(FDesc[1 + mcd].name, ptr+0xa)) continue; \
- FDesc[1 + mcd].mcfile = i; \
- SysPrintf("open %s\n", ptr+0xa); \
- v0 = 1 + mcd; \
- break; \
- } \
- if (a1 & 0x200 && v0 == -1) { /* FCREAT */ \
- for (i=1; i<16; i++) { \
- int j, xor = 0; \
- \
- ptr = Mcd##mcd##Data + 128 * i; \
- if ((*ptr & 0xF0) == 0x50) continue; \
- ptr[0] = 0x50 | (u8)(a1 >> 16); \
- ptr[4] = 0x00; \
- ptr[5] = 0x20; \
- ptr[6] = 0x00; \
- ptr[7] = 0x00; \
- ptr[8] = 'B'; \
- ptr[9] = 'I'; \
- strcpy(ptr+0xa, FDesc[1 + mcd].name); \
- for (j=0; j<127; j++) xor^= ptr[j]; \
- ptr[127] = xor; \
- FDesc[1 + mcd].mcfile = i; \
- SysPrintf("openC %s\n", ptr); \
- v0 = 1 + mcd; \
- SaveMcd(Config.Mcd##mcd, Mcd##mcd##Data, 128 * i, 128); \
- break; \
- } \
- } \
+char ffile[64], *pfile;
+int nfile;
+static void buopen(int mcd, u8 *ptr, u8 *cfg)
+{
+ int i;
+ u8 *fptr = ptr;
+
+ strcpy(FDesc[1 + mcd].name, Ra0+5);
+ FDesc[1 + mcd].offset = 0;
+ FDesc[1 + mcd].mode = a1;
+
+ for (i=1; i<16; i++) {
+ fptr += 128;
+ if ((*fptr & 0xF0) != 0x50) continue;
+ if (strcmp(FDesc[1 + mcd].name, fptr+0xa)) continue;
+ FDesc[1 + mcd].mcfile = i;
+ SysPrintf("open %s\n", fptr+0xa);
+ v0 = 1 + mcd;
+ break;
+ }
+ if (a1 & 0x200 && v0 == -1) { /* FCREAT */
+ fptr = ptr;
+ for (i=1; i<16; i++) {
+ int j, xor, nblk = a1 >> 16;
+ u8 *pptr, *fptr2;
+
+ fptr += 128;
+ if ((*fptr & 0xF0) != 0xa0) continue;
+
+ FDesc[1 + mcd].mcfile = i;
+ fptr[0] = 0x51;
+ fptr[4] = 0x00;
+ fptr[5] = 0x20 * nblk;
+ fptr[6] = 0x00;
+ fptr[7] = 0x00;
+ strcpy(fptr+0xa, FDesc[1 + mcd].name);
+ pptr = fptr2 = fptr;
+ for(j=2; j<=nblk; j++) {
+ int k;
+ for(i++; i<16; i++) {
+ fptr2 += 128;
+
+ memset(fptr2, 0, 128);
+ fptr2[0] = j < nblk ? 0x52 : 0x53;
+ pptr[8] = i - 1;
+ pptr[9] = 0;
+ for (k=0, xor=0; k<127; k++) xor^= pptr[k];
+ pptr[127] = xor;
+ pptr = fptr2;
+ break;
+ }
+ /* shouldn't this return ENOSPC if i == 16? */
+ }
+ pptr[8] = pptr[9] = 0xff;
+ for (j=0, xor=0; j<127; j++) xor^= pptr[j];
+ pptr[127] = xor;
+ SysPrintf("openC %s %d\n", ptr, nblk);
+ v0 = 1 + mcd;
+ /* just go ahead and resave them all */
+ SaveMcd(cfg, ptr, 128, 128 * 15);
+ break;
+ }
+ /* shouldn't this return ENOSPC if i == 16? */
+ }