Пример #1
0
QString QmlApp::readAndAdaptTemplateFile(const QString &filePath, bool &ok) const
{
    const QByteArray originalTemplate = readFile(filePath, ok);
    if (!ok)
        return QString();

    QTextStream tsIn(originalTemplate);
    QByteArray adaptedTemplate;
    QTextStream tsOut(&adaptedTemplate, QIODevice::WriteOnly | QIODevice::Text);
    int lineNr = 1;
    QString line;
    do {
        static const QString markerQtcReplace = QLatin1String("QTC_REPLACE");
        static const QString markerWith = QLatin1String("WITH");

        line = tsIn.readLine();
        const int markerQtcReplaceIndex = line.indexOf(markerQtcReplace);
        if (markerQtcReplaceIndex >= 0) {
            QString replaceXWithYString = line.mid(markerQtcReplaceIndex + markerQtcReplace.length()).trimmed();
            if (filePath.endsWith(QLatin1String(".json")))
                replaceXWithYString.replace(QRegExp(QLatin1String("\",$")), QString());
            else if (filePath.endsWith(QLatin1String(".html")))
                replaceXWithYString.replace(QRegExp(QLatin1String(" -->$")), QString());
            const QStringList replaceXWithY = replaceXWithYString.split(markerWith);
            if (replaceXWithY.count() != 2) {
                qWarning().nospace() << QString::fromLatin1("Error in %1:%2. Invalid %3 options.")
                              .arg(QDir::toNativeSeparators(filePath)).arg(lineNr).arg(markerQtcReplace);
                ok = false;
                return QString();
            }
            const QString replaceWhat = replaceXWithY.at(0).trimmed();
            const QString replaceWith = replaceXWithY.at(1).trimmed();
            if (!m_replacementVariables.contains(replaceWith)) {
                qWarning().nospace() << QString::fromLatin1("Error in %1:%2. Unknown %3 option '%4'.")
                              .arg(QDir::toNativeSeparators(filePath)).arg(lineNr).arg(markerQtcReplace).arg(replaceWith);
                ok = false;
                return QString();
            }
            line = tsIn.readLine(); // Following line which is to be patched.
            lineNr++;
            if (line.indexOf(replaceWhat) < 0) {
                qWarning().nospace() << QString::fromLatin1("Error in %1:%2. Replacement '%3' not found.")
                              .arg(QDir::toNativeSeparators(filePath)).arg(lineNr).arg(replaceWhat);
                ok = false;
                return QString();
            }
            line.replace(replaceWhat, m_replacementVariables.value(replaceWith));
        }
        if (!line.isNull())
            tsOut << line << endl;
        lineNr++;
    } while (!line.isNull());

    ok = true;
    return QString::fromUtf8(adaptedTemplate);
}
Пример #2
0
int loadZ80_f(Computer* comp, FILE* file) {
	int btm;
	int err = ERR_OK;
	unsigned char tmp,tmp2,reg,lst;
	unsigned short adr, twrd;
//	CPU* cpu = comp->cpu;
	char pageBuf[0xc000];
	z80v1Header hd;
	comp->p7FFD = 0x10;
	comp->pEFF7 = 0x00;
	memSetBank(comp->mem,0x00,MEM_ROM,1,MEM_16K,NULL,NULL,NULL);
	memSetBank(comp->mem,0xc0,MEM_RAM,0,MEM_16K,NULL,NULL,NULL);
	comp->vid->curscr = 5;

	fread((char*)&hd, sizeof(z80v1Header), 1, file);
	if (hd.flag12 == 0xff) hd.flag12 = 0x01;	// Because of compatibility, if byte 12 is 255, it has to be regarded as being 1.

	comp->cpu->af = (hd.a << 8) | hd.f;
	comp->cpu->bc = (hd.b << 8) | hd.c;
	comp->cpu->de = (hd.d << 8) | hd.e;
	comp->cpu->hl = (hd.h << 8) | hd.l;
	comp->cpu->af_ = (hd._a << 8) | hd._f;
	comp->cpu->bc_ = (hd._b << 8) | hd._c;
	comp->cpu->de_ = (hd._d << 8) | hd._e;
	comp->cpu->hl_ = (hd._h << 8) | hd._l;
	comp->cpu->pc = (hd.pch << 8) | hd.pcl;
	comp->cpu->sp = (hd.sph << 8) | hd.spl;
	comp->cpu->ix = (hd.ixh << 8) | hd.ixl;
	comp->cpu->iy = (hd.iyh << 8) | hd.iyl;
	comp->cpu->i = hd.i;
	comp->cpu->r7 = (hd.flag12 & 1) ? 0x80 : 0;
	comp->cpu->r = (hd.r7 & 0x7f) | comp->cpu->r7;
	comp->cpu->imode = hd.flag29 & 3;
	comp->cpu->iff1 = hd.iff1;
	comp->cpu->iff2 = hd.iff2;
	comp->cpu->inten = Z80_NMI | (hd.iff1 ? Z80_INT : 0);
	comp->vid->brdcol = (hd.flag12 >> 1) & 7;
	comp->vid->nextbrd = comp->vid->brdcol;
// unsupported things list
	if (hd.flag12 & 0x10) printf("...flag 12.bit 4.Basic SamRom switched in\n");
	if (hd.flag29 & 0x04) printf("...flag 29.bit 2.Issue 2 emulation\n");
	if (hd.flag29 & 0x08) printf("...flag 29.bit 3.Double interrupt frequency\n");
// continued
	if (comp->cpu->pc == 0) {
		adr = fgetw(file);
		twrd = fgetw(file);
		comp->cpu->pc = twrd;
		lst = fgetc(file);			// 34: HW mode
		tmp = fgetc(file);			// 35: 7FFD last out
		comp->hw->out(comp, 0x7ffd, tmp, 0);
		tmp = fgetc(file);			// 36: skip (IF1)
		tmp = fgetc(file);			// 37: skip (flags) TODO
		reg = fgetc(file);			// 38: last out to fffd
		for (tmp2 = 0; tmp2 < 16; tmp2++) {	// AY regs
			tmp = fgetc(file);
			tsOut(comp->ts, 0xfffd, tmp2);
			tsOut(comp->ts, 0xbffd, tmp);
		}
		comp->hw->out(comp, 0xfffd, reg, 0);

		if (adr > 23) {
printf(".z80 version 3\n");
			if (lst < 16) printf("Hardware: %s\n",v3hardware[lst]);
			switch (lst) {
				case 0:
				case 1:
				case 2: lst = 1; break;		// 48K
				case 4:
				case 5:
				case 6:
				case 9: lst = 2; break;		// 128K
				case 10: lst = 3; break;	// 256K
				default: lst = 0; break;	// undef
			}
			fseek(file, adr-23, SEEK_CUR);		// skip all other bytes
		} else {
printf(".z80 version 2\n");
			if (lst < 16) printf("Hardware: %s\n",v2hardware[lst]);
			switch (lst) {
				case 0:
				case 1: lst = 1; break;
				case 3:
				case 4:
				case 9: lst = 2; break;		// 128K
				case 10: lst = 3; break;	// 256K
				default: lst = 0; break;	// undef
			}
		}
		switch (lst) {
			case 1:
				btm = 1;
				do {
					tmp = z80readblock(file,pageBuf);
					switch (tmp) {
						case 4: memPutData(comp->mem,MEM_RAM,2,MEM_16K,pageBuf); break;
						case 5: memPutData(comp->mem,MEM_RAM,0,MEM_16K,pageBuf); break;
						case 8: memPutData(comp->mem,MEM_RAM,5,MEM_16K,pageBuf); break;
						default: btm = 0; break;
					}
				} while (btm && !feof(file));
				break;
			case 2:
				btm = 1;
				do {
					tmp = z80readblock(file,pageBuf);
					if ((tmp > 2) && (tmp < 11)) {
						memPutData(comp->mem,MEM_RAM,tmp-3,MEM_16K,pageBuf);
					} else {
						btm = 0;
					}
				} while (btm && !feof(file));
				break;
			case 3:
				btm = 1;
				do {
					tmp = z80readblock(file,pageBuf);
					if ((tmp > 2) && (tmp < 19)) {
						memPutData(comp->mem,MEM_RAM,tmp-3,MEM_16K,pageBuf);
					} else {
						btm = 0;
					}
				} while (btm && !feof(file));
				break;
			default:
				printf("Hardware mode not supported. reset\n");
				compReset(comp, RES_DEFAULT);
				err = ERR_Z80_HW;
				break;
		}
	} else {			// version 1
printf(".z80 version 1\n");
		if (hd.flag12 & 0x20) {
			printf("data is compressed\n");
			z80uncompress(file,pageBuf,0xc000);
			memPutData(comp->mem,MEM_RAM,5,MEM_16K,pageBuf);
			memPutData(comp->mem,MEM_RAM,2,MEM_16K,pageBuf + MEM_16K);
			memPutData(comp->mem,MEM_RAM,0,MEM_16K,pageBuf + MEM_32K);
		} else {
			printf("data is not compressed\n");
			fread(pageBuf, 0x4000, 1, file);
			memPutData(comp->mem,MEM_RAM,5,MEM_16K,pageBuf);
			fread(pageBuf, 0x4000, 1, file);
			memPutData(comp->mem,MEM_RAM,2,MEM_16K,pageBuf);
			fread(pageBuf, 0x4000, 1, file);
			memPutData(comp->mem,MEM_RAM,0,MEM_16K,pageBuf);
		}
	}
	tsReset(comp->ts);
	return err;
}