From 539e3e81a854a554d86a14fd70316f521339397d Mon Sep 17 00:00:00 2001 From: "fabio.olimpieri" Date: Sun, 29 Jul 2012 08:39:21 +0000 Subject: [PATCH] added 64k NTSC, precision emulation, 320X240 resolution, frame rate setting, screen menu --- src/VirtualKeyboard.c | 6 +- src/cargador.c | 1357 +++++------ src/computer.c | 680 +++++- src/computer.h | 28 +- src/emulator.c | 2416 ++++++++++--------- src/emulator.h | 105 +- src/gui_sdl.c | 2336 +++++++++--------- src/menu_sdl.c | 2027 ++++++++-------- src/menu_sdl.h | 140 +- src/menus.c | 4008 ++++++++++++++++--------------- src/menus.h | 109 +- src/tape.c | 1544 ++++++------ src/z80free/Z80free.c | 1572 ++++++------ src/z80free/Z80free.h | 315 +-- src/z80free/Z80free_codesDDCB.c | 3040 +++++++++++------------ src/z80free/Z80free_codesFDCB.c | 3040 +++++++++++------------ 16 files changed, 11736 insertions(+), 10987 deletions(-) diff --git a/src/VirtualKeyboard.c b/src/VirtualKeyboard.c index 3a15fd3..e71f8e3 100644 --- a/src/VirtualKeyboard.c +++ b/src/VirtualKeyboard.c @@ -67,8 +67,8 @@ void draw() int y,x; int screen_w = VirtualKeyboard.screen->w; int screen_h = VirtualKeyboard.screen->h; - int key_w = 54; - int key_h = 36; + int key_w = 54/RATIO; + int key_h = 36/RATIO; int border_x = (screen_w - (key_w * KEY_COLS)) / 2; int border_y = (screen_h - (key_h * KEY_ROWS)) / 2; SDL_Rect bg_rect = {border_x, border_y, @@ -170,7 +170,7 @@ struct virtkey *get_key_internal() struct virtkey* get_key() { virtkey_t *key; - SDL_Rect rect = {32, 120, FULL_DISPLAY_X-64, FULL_DISPLAY_Y-250}; + SDL_Rect rect = {32/RATIO, 120/RATIO, FULL_DISPLAY_X-64/RATIO, FULL_DISPLAY_Y-250/RATIO}; keys[3 * KEY_COLS + 0 ].is_done = 0; //Caps Shit keys[3 * KEY_COLS + 8 ].is_done = 0; //Sym Shift diff --git a/src/cargador.c b/src/cargador.c index 2e0a4be..46a3604 100644 --- a/src/cargador.c +++ b/src/cargador.c @@ -1,678 +1,679 @@ -/* - * Copyright (C) 2012 Fabio Olimpieri - * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX Wii - * - * FBZX Wii is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * FBZX Wii is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "z80free/Z80free.h" -#include "computer.h" -#include "emulator.h" -#include "cargador.h" -#include -#include - -#ifdef DEBUG -extern FILE *fdebug; -#define printf(...) fprintf(fdebug,__VA_ARGS__) -#else - #ifdef GEKKO - #define printf(...) - #endif -#endif - -void uncompress_z80(FILE *fichero,int length,unsigned char *memo) { - - unsigned char byte_loaded,EDfound,counter; - int position,retval; - - counter=0; - byte_loaded=0; - EDfound=0; - position=0; - - printf("Descomprimo de longitud %d\n",length); - - do { - if(counter) { - memo[position++]=byte_loaded; - counter--; - continue; - } else - retval=fread(&byte_loaded,1,1,fichero); - - if(EDfound==2) { // we have two EDs - counter=byte_loaded; - retval=fread(&byte_loaded,1,1,fichero); - EDfound=0; - continue; - } - - if(byte_loaded==0xED) { - EDfound++; - } else { - if(EDfound==1) { // we found ED xx. We write ED and xx - memo[position++]=0xED; - EDfound=0; - } - if (position>=length) { - break; - } - memo[position++]=byte_loaded; - } - } while(position>8)&0xFF)); // PC - else - fprintf(fichero,"%c%c",0,0); // 128K - - fprintf(fichero,"%c%c",procesador.Rm.br.P,procesador.Rm.br.S); // SP - fprintf(fichero,"%c%c%c",procesador.I,procesador.R,(((procesador.R2>>7)&0x01)|((ordenador.border<<1)&0x0E))); // I, R and border color - - fprintf(fichero,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c",procesador.Rm.br.E,procesador.Rm.br.D,procesador.Ra.br.C,procesador.Ra.br.B,procesador.Ra.br.E,procesador.Ra.br.D,procesador.Ra.br.L,procesador.Ra.br.H,procesador.Ra.br.A,procesador.Ra.br.F,procesador.Rm.br.IYl,procesador.Rm.br.IYh,procesador.Rm.br.IXl,procesador.Rm.br.IXh); - - if (procesador.IFF1) - value=1; - else - value=0; - fprintf(fichero,"%c",value); - if (procesador.IFF2) - value=1; - else - value=0; - fprintf(fichero,"%c",value); - value=procesador.IM; - if(ordenador.issue==2) - value|=4; - switch (ordenador.joystick[0]) { //Only one Joystick in Z80 file - case 1: - value|=64; - break; - case 2: - value|=128; - break; - case 3: - value|=192; - break; - } - fprintf(fichero,"%c",value); - - if(ordenador.mode128k==0) { // 48K - retval=fwrite((ordenador.memoria+147456),16384,1,fichero); // video memory - retval=fwrite((ordenador.memoria+98304),32768,1,fichero); // memory pages 2 & 3 - fclose(fichero); - return 0; - } - - // 128K - - fprintf(fichero,"%c%c",23,0); // Z80 file v2.01 - fprintf(fichero,"%c%c",(byte)(procesador.PC&0x0FF),(byte)((procesador.PC>>8)&0x0FF)); // PC - fprintf(fichero,"%c",3); // hardware mode=3 - fprintf(fichero,"%c",ordenador.mport1); // content of 0x7FFD latch - fprintf(fichero,"%c%c",0,0); // no If1, no emulation of any kind - fprintf(fichero,"%c",ordenador.ay_latch); // last selected AY register - for(bucle=0;bucle<16;bucle++) - fprintf(fichero,"%c",ordenador.ay_registers[bucle]); // AY registers - for(bucle=0;bucle<8;bucle++) { - fprintf(fichero,"%c%c",0xFF,0xFF); // length=0xFFFF (uncompressed) - fprintf(fichero,"%c",bucle+3); // page number - retval=fwrite(ordenador.memoria+(16384*bucle)+65536,16384,1,fichero); // store page - } - fclose(fichero); - return 0; -} - -int load_z80(char *filename) { - - struct z80snapshot *snap; - unsigned char tempo[30],tempo2[56],type,compressed,page,byte_read[3]; - unsigned char *memo; - FILE *fichero; - int longitud=0,longitud2,bucle,retval; - - memo=(unsigned char *)malloc(49152); - snap=(struct z80snapshot *)malloc(sizeof(struct z80snapshot)); - - longitud=strlen(filename); - if ((longitud>4)&&(0==strcasecmp(".sna",filename+(longitud-4)))) { - printf("Read SNA file\n"); - free(memo); - free(snap); - return load_sna(filename); - } - - printf("Read Z80 file\n"); - - for(bucle=0;bucle<16;bucle++) - snap->ay_regs[bucle]=0; - - fichero=fopen(filename,"r"); - if(fichero==NULL) { - free(memo); - free(snap); - return -1; // error - } - - printf("Read header (first 30 bytes)\n"); - retval=fread(tempo,1,30,fichero); - - if((tempo[6]==0)&&(tempo[7]==0)) { // extended Z80 - printf("It's an extended Z80 file\n"); - type=1; // new type - - retval=fread(tempo2,1,2,fichero); // read the length of the extension - - longitud=((int)tempo2[0])+256*((int)tempo2[1]); - if(longitud>54) { - fclose(fichero); - printf("Not suported Z80 file\n"); - free(memo); - free(snap); - return -3; // not a supported Z80 file - } - printf("Length: %d\n",longitud); - retval=fread(tempo2+2,1,longitud,fichero); - - if(longitud==23) // z80 ver 2.01 - switch(tempo2[4]) { - case 0: - case 1: - snap->type=0; // 48K - break; - case 3: - case 4: - snap->type=1; // 128K - break; - default: - fclose(fichero); - printf("Again not suported Z80 file\n"); - free(memo); - free(snap); - return -3; // not a supported Z80 file - break; - } - else // z80 ver 3.0x - switch(tempo2[4]) { - case 0: - case 1: - case 3: - snap->type=0; // 48K - break; - case 4: - case 5: - case 6: - snap->type=1; // 128K - break; - default: - fclose(fichero); - free(memo); - free(snap); - return -3; // not a supported Z80 file - break; - } - } else { - printf("Old type z80\n"); - type=0; // old type - snap->type=0; // 48k - } - - if(tempo[29]&0x04) { - printf("Issue 2\n"); - snap->issue=2; // issue2 - } else { - printf("Issue 3\n"); - snap->issue=3; // issue3 - } - - snap->A=tempo[0]; - snap->F=tempo[1]; - snap->C=tempo[2]; - snap->B=tempo[3]; - snap->L=tempo[4]; - snap->H=tempo[5]; - if(type) { - snap->PC=((word)tempo2[2])+256*((word)tempo2[3]); - for(bucle=0;bucle<16;bucle++) - snap->ay_regs[bucle]=tempo2[9+bucle]; - snap->ay_latch=tempo2[8]; - } else { - snap->PC=((word)tempo[6])+256*((word)tempo[7]); - } - - snap->SP=((word)tempo[8])+256*((word)tempo[9]); - snap->I=tempo[10]; - snap->R=(tempo[11]&0x7F); - - if(tempo[12]==255) { - printf("Byte 12 is 255! doing 1\n"); - tempo[12]=1; - } - - if(tempo[12]&0x01) - snap->R|=0x80; - - snap->border=(tempo[12]>>1)&0x07; - - if(tempo[12]&32) - compressed=1; - else - compressed=0; - - snap->E=tempo[13]; - snap->D=tempo[14]; - snap->CC=tempo[15]; - snap->BB=tempo[16]; - snap->EE=tempo[17]; - snap->DD=tempo[18]; - snap->LL=tempo[19]; - snap->HH=tempo[20]; - snap->AA=tempo[21]; - snap->FF=tempo[22]; - snap->IY=((word)tempo[23])+256*((word)tempo[24]); - snap->IX=((word)tempo[25])+256*((word)tempo[26]); - - if(tempo[27]!=0) - snap->IFF1=1; - else - snap->IFF1=0; - - if(tempo[28]!=0) - snap->IFF2=1; - else - snap->IFF2=0; - - switch(tempo[29]&0x03) { - case 0: - snap->Imode=0; - break; - case 1: - snap->Imode=1; - break; - case 2: - snap->Imode=2; - break; - } - - snap->joystick=((tempo[29]>>6)&0x03); - - if(type) - snap->pager=tempo2[5]; - - if(type) { // extended z80 - if(snap->type==1) { // 128K snapshot - - /* fclose(fichero); - return -3;*/ // z80 file not yet supported - - while(!feof(fichero)) { - retval=fread(byte_read,3,1,fichero); - if(feof(fichero)) - break; - longitud2=((int)byte_read[0])+256*((int)byte_read[1]); - switch(byte_read[2]) { - case 3: - page=0; - break; - case 4: - page=1; - break; - case 5: - page=2; - break; - case 6: - page=3; - break; - case 7: - page=4; - break; - case 8: - page=5; - break; - case 9: - page=6; - break; - case 10: - page=7; - break; - default: - page=11; - break; - } - printf("Loading page %d of length %d\n",page,longitud); - if(longitud2==0xFFFF) // uncompressed raw data - retval=fread(snap->page[page],16384,1,fichero); - else - uncompress_z80(fichero,16384,snap->page[page]); - } - - } else { - while(!feof(fichero)) { - retval=fread(byte_read,3,1,fichero); - if(feof(fichero)) - break; - longitud2=((int)byte_read[0])+256*((int)byte_read[1]); - switch(byte_read[2]) { - case 8: - page=0; - break; - case 4: - page=1; - break; - case 5: - page=2; - break; - default: - page=11; - break; - } - if(longitud2==0xFFFF) // uncompressed raw data - retval=fread(snap->page[page],16384,1,fichero); - else - uncompress_z80(fichero,16384,snap->page[page]); - } - } - } else { - - if(compressed) { - // 48k compressed z80 loader - - // we uncompress first the data - - uncompress_z80(fichero,49152,memo); - - memcpy(snap->page[0],memo,16384); - memcpy(snap->page[1],memo+16384,16384); - memcpy(snap->page[2],memo+32768,16384); - - } else { - // 48k uncompressed z80 loader - - retval=fread(snap->page[0],16384,1,fichero); - retval=fread(snap->page[1],16384,1,fichero); - retval=fread(snap->page[2],16384,1,fichero); - } - - } - - load_snap(snap); - fclose(fichero); - free(memo); - free(snap); - return 0; // all right -} - - -int load_sna(char *filename) { - - unsigned char *tempo; - unsigned char *tempo2; - unsigned char type=0; - FILE *fichero; - struct z80snapshot *snap; - unsigned char v1,v2; - int addr,loop; - - tempo=(unsigned char *)malloc(49179); - tempo2=(unsigned char *)malloc(98308); - snap=(struct z80snapshot *)malloc(sizeof(struct z80snapshot)); - - //Some inits - for(loop=0;loop<16;loop++) - snap->ay_regs[loop]=0; - snap->ay_latch=0; - snap->issue=3; - snap->joystick=1; //kempston - - printf("Loading SNA file\n"); - - fichero=fopen(filename,"r"); - if(fichero==NULL) { - free(tempo); - free(tempo2); - free(snap); - return -1; // error - } - - if (1!=fread(tempo,49179,1,fichero)) { - free(tempo); - free(tempo2); - free(snap); - return -1; - } - - if (0==fread(tempo2,1,98308,fichero)) { - printf("48K SNA\n"); - type=0; - } else { - printf("128K SNA\n"); - type=1; - } - - snap->type=type; - - snap->I=tempo[0]; - snap->LL=tempo[1]; - snap->HH=tempo[2]; - snap->EE=tempo[3]; - snap->DD=tempo[4]; - snap->CC=tempo[5]; - snap->BB=tempo[6]; - snap->FF=tempo[7]; - snap->AA=tempo[8]; - - snap->L=tempo[9]; - snap->H=tempo[10]; - snap->E=tempo[11]; - snap->D=tempo[12]; - snap->C=tempo[13]; - snap->B=tempo[14]; - - snap->IY=((word)tempo[15])+256*((word)tempo[16]); - snap->IX=((word)tempo[17])+256*((word)tempo[18]); - - if (tempo[19]&0x01) { - snap->IFF1=1; - } else { - snap->IFF1=0; - } - - if (tempo[19]&0x02) { - snap->IFF2=1; - } else { - snap->IFF2=0; - } - - snap->R=tempo[20]; - snap->F=tempo[21]; - snap->A=tempo[22]; - snap->SP=((word)tempo[23])+256*((word)tempo[24]); - snap->Imode=tempo[25]; - snap->border=tempo[26]; - - if (type==0) { - - v1=tempo[23]; - v2=tempo[24]; - addr=((int)v1)+256*((int)v2); - if ((addr<16384)||(addr>=65534)) { - free(tempo); - free(tempo2); - free(snap); - printf("Error loading SNA file. Return address in ROM.\n"); - return -1; - } - addr-=16384; - addr+=27; - snap->PC=((word)tempo[addr])+256*((word)tempo[addr+1]); - tempo[addr]=0; - tempo[addr+1]=0; - snap->SP+=2; - snap->IFF1=snap->IFF2; - memcpy(snap->page[0],tempo+27,16384); - memcpy(snap->page[1],tempo+16411,16384); - memcpy(snap->page[2],tempo+32795,16384); - } else { - snap->PC=((word)tempo2[0])+256*((word)tempo2[1]); - memcpy(snap->page[5],tempo+27,16384); - memcpy(snap->page[2],tempo+16411,16384); - v1=tempo[2]; - snap->pager=v1; - v1&=0x07; - memcpy(snap->page[v1],tempo+32795,16384); - addr=4; - for (loop=0;loop<7;loop++) { - if ((loop==2)||(loop==5)||(loop==((int)v1))) { - continue; - } - memcpy(snap->page[loop],tempo2+addr,16384); - addr+=16384; - } - } - - load_snap(snap); - free(tempo); - free(tempo2); - free(snap); - return 0; - -} - - -void load_snap(struct z80snapshot *snap) { - - int bucle; - - printf("Loading SnapShot\n"); - - switch(snap->type) { - case 0: // 48k - printf("Mode 48K\n"); - ordenador.mode128k=0; // 48K mode - ordenador.issue=snap->issue; - ResetComputer(); - break; - case 1: // 128k - printf("Mode 128K\n"); - ordenador.mode128k=1; // 128k mode - ordenador.issue=3; - ResetComputer(); - printf("Pager: %X\n",snap->pager); - Z80free_Out(0x7FFD,snap->pager); - break; - default: - break; - } - - ordenador.joystick[0]=snap->joystick; //Only one Joystick in Z80 file - - procesador.Rm.br.A=snap->A; - procesador.Rm.br.F=snap->F; - procesador.Rm.br.B=snap->B; - procesador.Rm.br.C=snap->C; - procesador.Rm.br.D=snap->D; - procesador.Rm.br.E=snap->E; - procesador.Rm.br.H=snap->H; - procesador.Rm.br.L=snap->L; - printf("A:%x F:%x B:%x C:%x D:%x E:%x H:%x L:%x\n",snap->A,snap->F,snap->B,snap->C,snap->D,snap->E,snap->H,snap->L); - procesador.Ra.br.A=snap->AA; - procesador.Ra.br.F=snap->FF; - procesador.Ra.br.B=snap->BB; - procesador.Ra.br.C=snap->CC; - procesador.Ra.br.D=snap->DD; - procesador.Ra.br.E=snap->EE; - procesador.Ra.br.H=snap->HH; - procesador.Ra.br.L=snap->LL; - printf("A:%x F:%x B:%x C:%x D:%x E:%x H:%x L:%x\n",snap->AA,snap->FF,snap->BB,snap->CC,snap->DD,snap->EE,snap->HH,snap->LL); - procesador.Rm.wr.IX=snap->IX; - procesador.Rm.wr.IY=snap->IY; - procesador.Rm.wr.SP=snap->SP; - procesador.PC=snap->PC; - printf("IX:%x IY:%x SP:%x PC:%x\n",snap->IX,snap->IY,snap->SP,snap->PC); - procesador.I=snap->I; - procesador.R=snap->R; - procesador.R2=snap->R; - printf("I:%x R:%x\n",snap->I,snap->R); - - if(snap->IFF1) { - procesador.IFF1=1; - } else { - procesador.IFF1=0; - } - if(snap->IFF2) { - procesador.IFF2=1; - } else { - procesador.IFF2=0; - } - printf("IFF1:%x IFF2:%x\n",snap->IFF1,snap->IFF1); - procesador.IM=snap->Imode; - printf("IM:%x\n",snap->Imode); - Z80free_Out(0xFFFE,((snap->border&0x07)|0x10)); - - switch(snap->type) { - case 0: // 48K - - for(bucle=0;bucle<16384;bucle++) { - ordenador.memoria[bucle+147456]=snap->page[0][bucle]; - ordenador.memoria[bucle+98304]=snap->page[1][bucle]; - ordenador.memoria[bucle+114688]=snap->page[2][bucle]; - } - - ordenador.ay_emul=0; - break; - case 1: // 128K - - for(bucle=0;bucle<16384;bucle++) { - ordenador.memoria[bucle+65536]=snap->page[0][bucle]; - ordenador.memoria[bucle+81920]=snap->page[1][bucle]; - ordenador.memoria[bucle+98304]=snap->page[2][bucle]; - ordenador.memoria[bucle+114688]=snap->page[3][bucle]; - ordenador.memoria[bucle+131072]=snap->page[4][bucle]; - ordenador.memoria[bucle+147456]=snap->page[5][bucle]; - ordenador.memoria[bucle+163840]=snap->page[6][bucle]; - ordenador.memoria[bucle+180224]=snap->page[7][bucle]; - } - ordenador.ay_emul=1; - for(bucle=0;bucle<16;bucle++) - ordenador.ay_registers[bucle]=snap->ay_regs[bucle]; - ordenador.ay_latch=snap->ay_latch; - break; - default: - break; - } -} +/* + * Copyright (C) 2012 Fabio Olimpieri + * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "z80free/Z80free.h" +#include "computer.h" +#include "emulator.h" +#include "cargador.h" +#include +#include + +#ifdef DEBUG +extern FILE *fdebug; +#define printf(...) fprintf(fdebug,__VA_ARGS__) +#else + #ifdef GEKKO + #define printf(...) + #endif +#endif + +void uncompress_z80(FILE *fichero,int length,unsigned char *memo) { + + unsigned char byte_loaded,EDfound,counter; + int position,retval; + + counter=0; + byte_loaded=0; + EDfound=0; + position=0; + + printf("Descomprimo de longitud %d\n",length); + + do { + if(counter) { + memo[position++]=byte_loaded; + counter--; + continue; + } else + retval=fread(&byte_loaded,1,1,fichero); + + if(EDfound==2) { // we have two EDs + counter=byte_loaded; + retval=fread(&byte_loaded,1,1,fichero); + EDfound=0; + continue; + } + + if(byte_loaded==0xED) { + EDfound++; + } else { + if(EDfound==1) { // we found ED xx. We write ED and xx + memo[position++]=0xED; + EDfound=0; + } + if (position>=length) { + break; + } + memo[position++]=byte_loaded; + } + } while(position>8)&0xFF)); // PC + else + fprintf(fichero,"%c%c",0,0); // 128K + + fprintf(fichero,"%c%c",procesador.Rm.br.P,procesador.Rm.br.S); // SP + fprintf(fichero,"%c%c%c",procesador.I,procesador.R,(((procesador.R2>>7)&0x01)|((ordenador.border<<1)&0x0E))); // I, R and border color + + fprintf(fichero,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c",procesador.Rm.br.E,procesador.Rm.br.D,procesador.Ra.br.C,procesador.Ra.br.B,procesador.Ra.br.E,procesador.Ra.br.D,procesador.Ra.br.L,procesador.Ra.br.H,procesador.Ra.br.A,procesador.Ra.br.F,procesador.Rm.br.IYl,procesador.Rm.br.IYh,procesador.Rm.br.IXl,procesador.Rm.br.IXh); + + if (procesador.IFF1) + value=1; + else + value=0; + fprintf(fichero,"%c",value); + if (procesador.IFF2) + value=1; + else + value=0; + fprintf(fichero,"%c",value); + value=procesador.IM; + if(ordenador.issue==2) + value|=4; + switch (ordenador.joystick[0]) { //Only one Joystick in Z80 file + case 1: + value|=64; + break; + case 2: + value|=128; + break; + case 3: + value|=192; + break; + } + fprintf(fichero,"%c",value); + + if(ordenador.mode128k==0) { // 48K + retval=fwrite((ordenador.memoria+147456),16384,1,fichero); // video memory + retval=fwrite((ordenador.memoria+98304),32768,1,fichero); // memory pages 2 & 3 + fclose(fichero); + return 0; + } + + // 128K + + fprintf(fichero,"%c%c",23,0); // Z80 file v2.01 + fprintf(fichero,"%c%c",(byte)(procesador.PC&0x0FF),(byte)((procesador.PC>>8)&0x0FF)); // PC + fprintf(fichero,"%c",3); // hardware mode=3 + fprintf(fichero,"%c",ordenador.mport1); // content of 0x7FFD latch + fprintf(fichero,"%c%c",0,0); // no If1, no emulation of any kind + fprintf(fichero,"%c",ordenador.ay_latch); // last selected AY register + for(bucle=0;bucle<16;bucle++) + fprintf(fichero,"%c",ordenador.ay_registers[bucle]); // AY registers + for(bucle=0;bucle<8;bucle++) { + fprintf(fichero,"%c%c",0xFF,0xFF); // length=0xFFFF (uncompressed) + fprintf(fichero,"%c",bucle+3); // page number + retval=fwrite(ordenador.memoria+(16384*bucle)+65536,16384,1,fichero); // store page + } + fclose(fichero); + return 0; +} + +int load_z80(char *filename) { + + struct z80snapshot *snap; + unsigned char tempo[30],tempo2[56],type,compressed,page,byte_read[3]; + unsigned char *memo; + FILE *fichero; + int longitud=0,longitud2,bucle,retval; + + memo=(unsigned char *)malloc(49152); + snap=(struct z80snapshot *)malloc(sizeof(struct z80snapshot)); + + longitud=strlen(filename); + if ((longitud>4)&&(0==strcasecmp(".sna",filename+(longitud-4)))) { + printf("Read SNA file\n"); + free(memo); + free(snap); + return load_sna(filename); + } + + printf("Read Z80 file\n"); + + for(bucle=0;bucle<16;bucle++) + snap->ay_regs[bucle]=0; + + fichero=fopen(filename,"r"); + if(fichero==NULL) { + free(memo); + free(snap); + return -1; // error + } + + printf("Read header (first 30 bytes)\n"); + retval=fread(tempo,1,30,fichero); + + if((tempo[6]==0)&&(tempo[7]==0)) { // extended Z80 + printf("It's an extended Z80 file\n"); + type=1; // new type + + retval=fread(tempo2,1,2,fichero); // read the length of the extension + + longitud=((int)tempo2[0])+256*((int)tempo2[1]); + if(longitud>54) { + fclose(fichero); + printf("Not suported Z80 file\n"); + free(memo); + free(snap); + return -3; // not a supported Z80 file + } + printf("Length: %d\n",longitud); + retval=fread(tempo2+2,1,longitud,fichero); + + if(longitud==23) // z80 ver 2.01 + switch(tempo2[4]) { + case 0: + case 1: + snap->type=0; // 48K + break; + case 3: + case 4: + snap->type=1; // 128K + break; + default: + fclose(fichero); + printf("Again not suported Z80 file\n"); + free(memo); + free(snap); + return -3; // not a supported Z80 file + break; + } + else // z80 ver 3.0x + switch(tempo2[4]) { + case 0: + case 1: + case 3: + snap->type=0; // 48K + break; + case 4: + case 5: + case 6: + snap->type=1; // 128K + break; + default: + fclose(fichero); + free(memo); + free(snap); + return -3; // not a supported Z80 file + break; + } + } else { + printf("Old type z80\n"); + type=0; // old type + snap->type=0; // 48k + } + + if(tempo[29]&0x04) { + printf("Issue 2\n"); + snap->issue=2; // issue2 + } else { + printf("Issue 3\n"); + snap->issue=3; // issue3 + } + + snap->A=tempo[0]; + snap->F=tempo[1]; + snap->C=tempo[2]; + snap->B=tempo[3]; + snap->L=tempo[4]; + snap->H=tempo[5]; + if(type) { + snap->PC=((word)tempo2[2])+256*((word)tempo2[3]); + for(bucle=0;bucle<16;bucle++) + snap->ay_regs[bucle]=tempo2[9+bucle]; + snap->ay_latch=tempo2[8]; + } else { + snap->PC=((word)tempo[6])+256*((word)tempo[7]); + } + + snap->SP=((word)tempo[8])+256*((word)tempo[9]); + snap->I=tempo[10]; + snap->R=(tempo[11]&0x7F); + + if(tempo[12]==255) { + printf("Byte 12 is 255! doing 1\n"); + tempo[12]=1; + } + + if(tempo[12]&0x01) + snap->R|=0x80; + + snap->border=(tempo[12]>>1)&0x07; + + if(tempo[12]&32) + compressed=1; + else + compressed=0; + + snap->E=tempo[13]; + snap->D=tempo[14]; + snap->CC=tempo[15]; + snap->BB=tempo[16]; + snap->EE=tempo[17]; + snap->DD=tempo[18]; + snap->LL=tempo[19]; + snap->HH=tempo[20]; + snap->AA=tempo[21]; + snap->FF=tempo[22]; + snap->IY=((word)tempo[23])+256*((word)tempo[24]); + snap->IX=((word)tempo[25])+256*((word)tempo[26]); + + if(tempo[27]!=0) + snap->IFF1=1; + else + snap->IFF1=0; + + if(tempo[28]!=0) + snap->IFF2=1; + else + snap->IFF2=0; + + switch(tempo[29]&0x03) { + case 0: + snap->Imode=0; + break; + case 1: + snap->Imode=1; + break; + case 2: + snap->Imode=2; + break; + } + + snap->joystick=((tempo[29]>>6)&0x03); + + if(type) + snap->pager=tempo2[5]; + + if(type) { // extended z80 + if(snap->type==1) { // 128K snapshot + + /* fclose(fichero); + return -3;*/ // z80 file not yet supported + + while(!feof(fichero)) { + retval=fread(byte_read,3,1,fichero); + if(feof(fichero)) + break; + longitud2=((int)byte_read[0])+256*((int)byte_read[1]); + switch(byte_read[2]) { + case 3: + page=0; + break; + case 4: + page=1; + break; + case 5: + page=2; + break; + case 6: + page=3; + break; + case 7: + page=4; + break; + case 8: + page=5; + break; + case 9: + page=6; + break; + case 10: + page=7; + break; + default: + page=11; + break; + } + printf("Loading page %d of length %d\n",page,longitud); + if(longitud2==0xFFFF) // uncompressed raw data + retval=fread(snap->page[page],16384,1,fichero); + else + uncompress_z80(fichero,16384,snap->page[page]); + } + + } else { + while(!feof(fichero)) { + retval=fread(byte_read,3,1,fichero); + if(feof(fichero)) + break; + longitud2=((int)byte_read[0])+256*((int)byte_read[1]); + switch(byte_read[2]) { + case 8: + page=0; + break; + case 4: + page=1; + break; + case 5: + page=2; + break; + default: + page=11; + break; + } + if(longitud2==0xFFFF) // uncompressed raw data + retval=fread(snap->page[page],16384,1,fichero); + else + uncompress_z80(fichero,16384,snap->page[page]); + } + } + } else { + + if(compressed) { + // 48k compressed z80 loader + + // we uncompress first the data + + uncompress_z80(fichero,49152,memo); + + memcpy(snap->page[0],memo,16384); + memcpy(snap->page[1],memo+16384,16384); + memcpy(snap->page[2],memo+32768,16384); + + } else { + // 48k uncompressed z80 loader + + retval=fread(snap->page[0],16384,1,fichero); + retval=fread(snap->page[1],16384,1,fichero); + retval=fread(snap->page[2],16384,1,fichero); + } + + } + + load_snap(snap); + fclose(fichero); + free(memo); + free(snap); + return 0; // all right +} + + +int load_sna(char *filename) { + + unsigned char *tempo; + unsigned char *tempo2; + unsigned char type=0; + FILE *fichero; + struct z80snapshot *snap; + unsigned char v1,v2; + int addr,loop; + + tempo=(unsigned char *)malloc(49179); + tempo2=(unsigned char *)malloc(98308); + snap=(struct z80snapshot *)malloc(sizeof(struct z80snapshot)); + + //Some inits + for(loop=0;loop<16;loop++) + snap->ay_regs[loop]=0; + snap->ay_latch=0; + snap->issue=3; + snap->joystick=1; //kempston + + printf("Loading SNA file\n"); + + fichero=fopen(filename,"r"); + if(fichero==NULL) { + free(tempo); + free(tempo2); + free(snap); + return -1; // error + } + + if (1!=fread(tempo,49179,1,fichero)) { + free(tempo); + free(tempo2); + free(snap); + return -1; + } + + if (0==fread(tempo2,1,98308,fichero)) { + printf("48K SNA\n"); + type=0; + } else { + printf("128K SNA\n"); + type=1; + } + + snap->type=type; + + snap->I=tempo[0]; + snap->LL=tempo[1]; + snap->HH=tempo[2]; + snap->EE=tempo[3]; + snap->DD=tempo[4]; + snap->CC=tempo[5]; + snap->BB=tempo[6]; + snap->FF=tempo[7]; + snap->AA=tempo[8]; + + snap->L=tempo[9]; + snap->H=tempo[10]; + snap->E=tempo[11]; + snap->D=tempo[12]; + snap->C=tempo[13]; + snap->B=tempo[14]; + + snap->IY=((word)tempo[15])+256*((word)tempo[16]); + snap->IX=((word)tempo[17])+256*((word)tempo[18]); + + if (tempo[19]&0x01) { + snap->IFF1=1; + } else { + snap->IFF1=0; + } + + if (tempo[19]&0x02) { + snap->IFF2=1; + } else { + snap->IFF2=0; + } + + snap->R=tempo[20]; + snap->F=tempo[21]; + snap->A=tempo[22]; + snap->SP=((word)tempo[23])+256*((word)tempo[24]); + snap->Imode=tempo[25]; + snap->border=tempo[26]; + + if (type==0) { + + v1=tempo[23]; + v2=tempo[24]; + addr=((int)v1)+256*((int)v2); + if ((addr<16384)||(addr>=65534)) { + free(tempo); + free(tempo2); + free(snap); + printf("Error loading SNA file. Return address in ROM.\n"); + return -1; + } + addr-=16384; + addr+=27; + snap->PC=((word)tempo[addr])+256*((word)tempo[addr+1]); + tempo[addr]=0; + tempo[addr+1]=0; + snap->SP+=2; + snap->IFF1=snap->IFF2; + memcpy(snap->page[0],tempo+27,16384); + memcpy(snap->page[1],tempo+16411,16384); + memcpy(snap->page[2],tempo+32795,16384); + } else { + snap->PC=((word)tempo2[0])+256*((word)tempo2[1]); + memcpy(snap->page[5],tempo+27,16384); + memcpy(snap->page[2],tempo+16411,16384); + v1=tempo[2]; + snap->pager=v1; + v1&=0x07; + memcpy(snap->page[v1],tempo+32795,16384); + addr=4; + for (loop=0;loop<7;loop++) { + if ((loop==2)||(loop==5)||(loop==((int)v1))) { + continue; + } + memcpy(snap->page[loop],tempo2+addr,16384); + addr+=16384; + } + } + + load_snap(snap); + free(tempo); + free(tempo2); + free(snap); + return 0; + +} + + +void load_snap(struct z80snapshot *snap) { + + int bucle; + + printf("Loading SnapShot\n"); + + switch(snap->type) { + case 0: // 48k + printf("Mode 48K\n"); + ordenador.mode128k=0; // 48K mode + ordenador.issue=snap->issue; + ResetComputer(); + break; + case 1: // 128k + printf("Mode 128K\n"); + ordenador.mode128k=1; // 128k mode + ordenador.issue=3; + ordenador.videosystem=0; + ResetComputer(); + printf("Pager: %X\n",snap->pager); + Z80free_Out_fake(0x7FFD,snap->pager); + break; + default: + break; + } + + ordenador.joystick[0]=snap->joystick; //Only one Joystick in Z80 file + + procesador.Rm.br.A=snap->A; + procesador.Rm.br.F=snap->F; + procesador.Rm.br.B=snap->B; + procesador.Rm.br.C=snap->C; + procesador.Rm.br.D=snap->D; + procesador.Rm.br.E=snap->E; + procesador.Rm.br.H=snap->H; + procesador.Rm.br.L=snap->L; + printf("A:%x F:%x B:%x C:%x D:%x E:%x H:%x L:%x\n",snap->A,snap->F,snap->B,snap->C,snap->D,snap->E,snap->H,snap->L); + procesador.Ra.br.A=snap->AA; + procesador.Ra.br.F=snap->FF; + procesador.Ra.br.B=snap->BB; + procesador.Ra.br.C=snap->CC; + procesador.Ra.br.D=snap->DD; + procesador.Ra.br.E=snap->EE; + procesador.Ra.br.H=snap->HH; + procesador.Ra.br.L=snap->LL; + printf("A:%x F:%x B:%x C:%x D:%x E:%x H:%x L:%x\n",snap->AA,snap->FF,snap->BB,snap->CC,snap->DD,snap->EE,snap->HH,snap->LL); + procesador.Rm.wr.IX=snap->IX; + procesador.Rm.wr.IY=snap->IY; + procesador.Rm.wr.SP=snap->SP; + procesador.PC=snap->PC; + printf("IX:%x IY:%x SP:%x PC:%x\n",snap->IX,snap->IY,snap->SP,snap->PC); + procesador.I=snap->I; + procesador.R=snap->R; + procesador.R2=snap->R; + printf("I:%x R:%x\n",snap->I,snap->R); + + if(snap->IFF1) { + procesador.IFF1=1; + } else { + procesador.IFF1=0; + } + if(snap->IFF2) { + procesador.IFF2=1; + } else { + procesador.IFF2=0; + } + printf("IFF1:%x IFF2:%x\n",snap->IFF1,snap->IFF1); + procesador.IM=snap->Imode; + printf("IM:%x\n",snap->Imode); + Z80free_Out_fake(0xFFFE,((snap->border&0x07)|0x10)); + + switch(snap->type) { + case 0: // 48K + + for(bucle=0;bucle<16384;bucle++) { + ordenador.memoria[bucle+147456]=snap->page[0][bucle]; + ordenador.memoria[bucle+98304]=snap->page[1][bucle]; + ordenador.memoria[bucle+114688]=snap->page[2][bucle]; + } + + ordenador.ay_emul=0; + break; + case 1: // 128K + + for(bucle=0;bucle<16384;bucle++) { + ordenador.memoria[bucle+65536]=snap->page[0][bucle]; + ordenador.memoria[bucle+81920]=snap->page[1][bucle]; + ordenador.memoria[bucle+98304]=snap->page[2][bucle]; + ordenador.memoria[bucle+114688]=snap->page[3][bucle]; + ordenador.memoria[bucle+131072]=snap->page[4][bucle]; + ordenador.memoria[bucle+147456]=snap->page[5][bucle]; + ordenador.memoria[bucle+163840]=snap->page[6][bucle]; + ordenador.memoria[bucle+180224]=snap->page[7][bucle]; + } + ordenador.ay_emul=1; + for(bucle=0;bucle<16;bucle++) + ordenador.ay_registers[bucle]=snap->ay_regs[bucle]; + ordenador.ay_latch=snap->ay_latch; + break; + default: + break; + } +} diff --git a/src/computer.c b/src/computer.c index 5deb42f..2aad834 100644 --- a/src/computer.c +++ b/src/computer.c @@ -33,6 +33,7 @@ #include "microdrive.h" #include "Virtualkeyboard.h" #include "gui_sdl.h" +#include "menu_sdl.h" #if defined(GEKKO) # include # include @@ -47,6 +48,7 @@ extern FILE *fdebug; #endif #endif + /* Returns the bus value when reading a port without a periferial */ inline byte bus_empty () { @@ -60,13 +62,19 @@ inline byte bus_empty () { /* calls all the routines that emulates the computer, runing them for 'tstados' tstates */ -inline void emulate (int tstados) { +inline void emulate_screen (int tstados) { - if((procesador.I>=0x40)&&(procesador.I<=0x7F)) { + if((procesador.I & 0xC0) == 0x40) { // (procesador.I>=0x40)&&(procesador.I<=0x7F) ordenador.screen_snow=1; } else ordenador.screen_snow=0; - show_screen (tstados); + + if (ordenador.precision) show_screen_precision (tstados); + else show_screen(tstados); +} + +inline void emulate (int tstados) { + play_ay (tstados); play_sound (tstados); tape_read (ordenador.tap_file, tstados); @@ -87,10 +95,12 @@ void computer_init () { ordenador.port254 = 0; ordenador.issue = 3; ordenador.mode128k = 0; + ordenador.videosystem = 0; //PAL ordenador.joystick[0] = 1; //Kemposton ordenador.joystick[1] = 0; // Cursor ordenador.rumble[0] = 0; ordenador.rumble[1] = 0; + ordenador.precision = 0; ordenador.tape_readed = 0; ordenador.pause = 1; // tape stop @@ -124,6 +134,10 @@ void computer_init () { ordenador.vol_c = 0; ordenador.tst_ay = 0; ordenador.tst_ay2 = 0; + ordenador.wr = 0; + ordenador.r_fetch = 0; + ordenador.io = 0; + ordenador.contention = 0; ordenador.ayval_a = 0; ordenador.ayval_b = 0; @@ -144,6 +158,8 @@ void computer_init () { strcpy (ordenador.SmbShare, "Share"); strcpy (ordenador.SmbIp, "192.168.0.1"); ordenador.autoconf=0; + + ordenador.cpufreq = 3500000; // values for 48K mode } void computer_set_palete() { @@ -360,6 +376,7 @@ void register_screen (SDL_Surface * pantalla) { ordenador.screen = pantalla; ordenador.border = 0; + ordenador.border_p = 0; ordenador.currline = 0; ordenador.currpix = 0; ordenador.flash = 0; @@ -372,8 +389,6 @@ void register_screen (SDL_Surface * pantalla) { ordenador.init_line = 0; ordenador.next_line = 640; ordenador.next_scanline = 640; - ordenador.first_line = 40; - ordenador.last_line = 280; ordenador.first_pixel = 16; ordenador.last_pixel = 336; ordenador.next_pixel = 1; @@ -383,8 +398,6 @@ void register_screen (SDL_Surface * pantalla) { ordenador.init_line = 65; ordenador.next_line = 160; ordenador.next_scanline = 160; - ordenador.first_line = 40; - ordenador.last_line = 280; ordenador.first_pixel = 0; ordenador.last_pixel = 351; ordenador.next_pixel = 1; @@ -394,8 +407,6 @@ void register_screen (SDL_Surface * pantalla) { ordenador.init_line = 479; ordenador.next_line = -(307202); ordenador.next_scanline = -1; - ordenador.first_line = 40; - ordenador.last_line = 280; ordenador.first_pixel = 16; ordenador.last_pixel = 336; ordenador.next_pixel = 480; @@ -405,8 +416,6 @@ void register_screen (SDL_Surface * pantalla) { ordenador.init_line = 0; ordenador.next_line = 0; ordenador.next_scanline = 0; - ordenador.first_line = 40; - ordenador.last_line = 280; ordenador.first_pixel = 0; ordenador.last_pixel = 319; ordenador.next_pixel = 1; @@ -424,14 +433,15 @@ void register_screen (SDL_Surface * pantalla) { ordenador.pixel = ((unsigned char *) (ordenador.screen->pixels)) + ordenador.init_line; ordenador.interr = 0; - + ordenador.readkeyboard = 0; + ordenador.p_translt = ordenador.translate; ordenador.p_translt2 = ordenador.translate2; ordenador.contador_flash = 0; ordenador.readed = 0; - ordenador.contended_zone=0; + //ordenador.contended_zone=0; ordenador.cicles_counter=0; ordenador.tstados_counter_sound = 0; @@ -439,8 +449,6 @@ void register_screen (SDL_Surface * pantalla) { ordenador.num_buff = 0; // first buffer ordenador.sound_cuantity = 0; ordenador.sound_current_value = 0; - ordenador.pixancho = 447; - ordenador.pixalto = 311; // values for 48K mode } void set_memory_pointers () { @@ -514,38 +522,48 @@ void set_memory_pointers () { /* Paints the spectrum screen during the TSTADOS tstates that the Z80 used to execute last instruction */ + inline void show_screen (int tstados) { - static unsigned char temporal, ink, paper, fflash, tmp2; + static unsigned char temporal, temporal3, ink, paper, fflash, tmp2; + ordenador.tstados_counter += tstados; ordenador.cicles_counter += tstados; if (curr_frames=69888) { - ordenador.tstados_counter-=69888; + if (ordenador.tstados_counter>=ordenador.tstatodos_frame) { + ordenador.tstados_counter-=ordenador.tstatodos_frame; ordenador.interr = 1; + if ((ordenador.turbo == 0) || (curr_frames%7 == 0)) ordenador.readkeyboard = 1; curr_frames++; } return; } fflash = 0; // flash flag + while (ordenador.tstados_counter > 3) { ordenador.tstados_counter -= 4; - + + //test if current pixel is outside visible area + + if ((ordenador.currline >= ordenador.first_line) && (ordenador.currline < ordenador.last_line)&& + (ordenador.currpix > 15) && (ordenador.currpix < 336)) + { + + // test if current pixel is for border or for user area - if ((ordenador.currline < 64) || (ordenador.currline > 255) + if ((ordenador.currline < ordenador.upper_border_line ) || (ordenador.currline >= ordenador.lower_border_line) || (ordenador.currpix < 48) || (ordenador.currpix > 303)) { // is border - ordenador.contended_zone=0; // no contention here if (ordenador.ulaplus) { - paint_pixels (255, ordenador.border+24, 0); // paint 8 pixels with BORDER color + paint_pixels (255, ordenador.border+24, 0, 8); // paint 8 pixels with BORDER color } else { - paint_pixels (255, ordenador.border, 0); // paint 8 pixels with BORDER color + paint_pixels (255, ordenador.border, 0, 8); // paint 8 pixels with BORDER color } ordenador.bus_value = 255; @@ -553,11 +571,10 @@ inline void show_screen (int tstados) { } else { // is user area. We search for ink and paper colours - - ordenador.contended_zone=1; // can have contention temporal = ordenador.memoria[(*ordenador.p_translt2) + ordenador.video_offset]; // attributes ordenador.bus_value = temporal; + ink = temporal & 0x07; // ink colour paper = (temporal >> 3) & 0x07; // paper colour if (ordenador.ulaplus) { @@ -575,18 +592,23 @@ inline void show_screen (int tstados) { // Snow Effect if(ordenador.screen_snow) { - temporal = ordenador.memoria[(((*ordenador.p_translt) + (ordenador.video_offset))&0xFFFFFF00)+(procesador.R)]; // data with snow + temporal3 = ordenador.memoria[(((*ordenador.p_translt) + (ordenador.video_offset))&0xFFFFFF00)+(procesador.R)]; // data with snow ordenador.screen_snow=0; // no more snow for now } else - temporal = ordenador.memoria[(*ordenador.p_translt) + ordenador.video_offset]; // data - + temporal3 = ordenador.memoria[(*ordenador.p_translt) + ordenador.video_offset]; // bitmap // bitmap + ordenador.p_translt++; ordenador.p_translt2++; + if ((fflash) && (ordenador.flash)) - paint_pixels (temporal, paper, ink); // if FLASH, invert PAPER and INK + paint_pixels (temporal3, paper, ink, 8); // if FLASH, invert PAPER and INK else - paint_pixels (temporal, ink, paper); + paint_pixels (temporal3, ink, paper, 8); + } + } + + //Update pixel position ordenador.currpix += 8; if (ordenador.currpix > ordenador.pixancho) { ordenador.currpix = 0; @@ -596,7 +618,9 @@ inline void show_screen (int tstados) { } } - if ((ordenador.currline > ordenador.pixalto)&&(ordenador.currpix>=64)) { + + //End of frame + if ((ordenador.currline > ordenador.pixalto)&&(ordenador.currpix>63)) { ordenador.currpix=64; if (ordenador.osd_time) { ordenador.osd_time--; @@ -626,6 +650,7 @@ inline void show_screen (int tstados) { curr_frames=0; ordenador.currline = 0; ordenador.interr = 1; + ordenador.readkeyboard = 1; ordenador.cicles_counter=0; ordenador.pixel = ((unsigned char *) (ordenador.screen->pixels))+ordenador.init_line; // +ordenador.init_line; ordenador.p_translt = ordenador.translate; @@ -639,21 +664,236 @@ inline void show_screen (int tstados) { } } +//Write the screen from 14339 state -/* PAINT_PIXELS paints one byte with INK color for 1 bits and PAPER color +inline void show_screen_precision (int tstados) { + + static unsigned char temporal, temporal2, temporal_1, temporal2_1,temporal3, ink, paper, fflash, tmp2; + + ordenador.tstados_counter += tstados; + + if (curr_frames=ordenador.tstatodos_frame) { + ordenador.tstados_counter-=ordenador.tstatodos_frame; + ordenador.interr = 1; + ordenador.readkeyboard = 1; + curr_frames++; + } + if (ordenador.tstados_counter > 31) ordenador.interr = 0; + return; + } + + while (ordenador.tstados_counter>0) { + ordenador.tstados_counter--; + + //test if current pixel is outside visible area + + if ((ordenador.currline >= ordenador.first_line) && (ordenador.currline < ordenador.last_line)&& + (ordenador.currpix > 15) && (ordenador.currpix < 336)) + { + + + ordenador.pixels_word = ordenador.currpix%16; + ordenador.pixels_octect = ordenador.currpix%8; + + // test if current pixel is for border or for user area + + if ((ordenador.currline < ordenador.upper_border_line ) || (ordenador.currline >= ordenador.lower_border_line) + || (ordenador.currpix < 48) || (ordenador.currpix > 303)) { + + // is border + + if (ordenador.pixels_octect==0) ordenador.border_p = ordenador.border; + + if (ordenador.ulaplus) { + paint_pixels (255, ordenador.border_p+24, 0, 2); // paint 2 pixels with BORDER color + } else { + paint_pixels (255, ordenador.border_p, 0, 2); // paint 2 pixels with BORDER color + } + + ordenador.bus_value = 255; + + if ((ordenador.currline == ordenador.upper_border_line) && (ordenador.currpix == 46)) + { + + temporal = ordenador.memoria[(*ordenador.p_translt2) + ordenador.video_offset]; // attributes + temporal2 = ordenador.memoria[(*ordenador.p_translt) + ordenador.video_offset]; // bitmap + temporal_1 = ordenador.memoria[(*(ordenador.p_translt2+1)) + ordenador.video_offset]; // attributes + temporal2_1 = ordenador.memoria[((*ordenador.p_translt+1)) + ordenador.video_offset]; // bitmap + + ordenador.p_translt+=2; + ordenador.p_translt2+=2; + ordenador.bus_value = temporal2; + } + + } else { + + // is user area. We search for ink and paper colours + + switch (ordenador.pixels_word) + { + case 0: //start of first byte + + ink = temporal & 0x07; // ink colour + paper = (temporal >> 3) & 0x07; // paper colour + if (ordenador.ulaplus) { + tmp2=0x10+((temporal>>2)&0x30); + ink+=tmp2; + paper+=8+tmp2; + } else { + if (temporal & 0x40) { // bright flag? + ink += 8; + paper += 8; + } + fflash = temporal & 0x80; // flash flag + } + + // Snow Effect + + if(ordenador.screen_snow) { + temporal3 = ordenador.memoria[(((*ordenador.p_translt) + (ordenador.video_offset))&0xFFFFFF00)+(procesador.R)]; // data with snow + ordenador.screen_snow=0; // no more snow for now + } else + temporal3 = temporal2; // bitmap + + break; + + + case 8: //start of second byte + + ink = temporal_1 & 0x07; // ink colour + paper = (temporal_1 >> 3) & 0x07; // paper colour + if (ordenador.ulaplus) { + tmp2=0x10+((temporal_1>>2)&0x30); + ink+=tmp2; + paper+=8+tmp2; + } else { + if (temporal_1 & 0x40) { // bright flag? + ink += 8; + paper += 8; + } + fflash = temporal_1 & 0x80; // flash flag + } + + temporal3 = temporal2_1; // bitmap + break; + + case 14: //sample the memory + + temporal = ordenador.memoria[(*ordenador.p_translt2) + ordenador.video_offset]; // attributes + temporal2 = ordenador.memoria[(*ordenador.p_translt) + ordenador.video_offset]; // bitmap + temporal_1 = ordenador.memoria[(*(ordenador.p_translt2+1)) + ordenador.video_offset]; // attributes + temporal2_1 = ordenador.memoria[((*ordenador.p_translt+1)) + ordenador.video_offset]; // bitmap + + ordenador.p_translt+=2; + ordenador.p_translt2+=2; + + break; + } + + //Floating bus + if (ordenador.currpix < 295) + switch (ordenador.pixels_word) + { + case 14: + // bitmap + ordenador.bus_value = temporal2; + break; + case 0: + // attributes + ordenador.bus_value = temporal; + break; + case 2: + // bitmap + ordenador.bus_value = temporal2_1; + break; + case 4: + // attributes + ordenador.bus_value = temporal_1; + break; + default: + ordenador.bus_value = 255; + break; + } + + if ((fflash) && (ordenador.flash)) + paint_pixels (temporal3, paper, ink, 2); // if FLASH, invert PAPER and INK + else + paint_pixels (temporal3, ink, paper ,2); + + } + } + + //Update pixel position + ordenador.cicles_counter++; + ordenador.currpix += 2; + if (ordenador.currpix > ordenador.pixancho) { + ordenador.currpix = 0; + ordenador.currline++; + if (ordenador.currline > ordenador.first_line) { // ordenador.first_line) + ordenador.pixel += ordenador.next_line; // ordenador.next_line; + } + } + + //End of frame + if ((ordenador.currline > ordenador.pixalto)&&(ordenador.currpix>ordenador.start_screen)){ + if (ordenador.osd_time) { + ordenador.osd_time--; + if (ordenador.osd_time==0) { + ordenador.tab_extended=0; + ordenador.esc_again=0; + } + + if (ordenador.osd_time) + print_string (ordenador.screenbuffer,ordenador.osd_text, -1,450, 12, 0,ordenador.screen_width); + else { + if (ordenador.zaurus_mini==0) + print_string (ordenador.screenbuffer," ",-1, 450, 12, 0,ordenador.screen_width); + else + print_string (ordenador.screenbuffer," ",-1, 450, 12, 0,ordenador.screen_width); + } + } + + if (ordenador.mustlock) { + SDL_UnlockSurface (ordenador.screen); + SDL_Flip (ordenador.screen); + SDL_LockSurface (ordenador.screen); + } else { + SDL_Flip (ordenador.screen); + } + + curr_frames=0; + ordenador.currline = 0; + ordenador.interr = 1; + ordenador.readkeyboard = 1; + ordenador.cicles_counter=0; + ordenador.pixel = ((unsigned char *) (ordenador.screen->pixels))+ordenador.init_line; // +ordenador.init_line; + ordenador.p_translt = ordenador.translate; + ordenador.p_translt2 = ordenador.translate2; + ordenador.contador_flash++; + if (ordenador.contador_flash == 16) { + ordenador.flash = 1 - ordenador.flash; + ordenador.contador_flash = 0; + } + } + + //End of interrupt + if (ordenador.cicles_counter == 32) ordenador.interr = 0; + + } +} + +/* PAINT_PIXELS paints bits with INK color for 1 bits and PAPER color for 0 bits, and increment acordingly the pointer PIXEL */ -inline void paint_pixels (unsigned char octet,unsigned char ink, unsigned char paper) { +inline void paint_pixels (unsigned char octet,unsigned char ink, unsigned char paper, unsigned char bit) { static int bucle,valor,*p; static unsigned char mask; - - if ((ordenador.currpix < 16) || (ordenador.currpix >= 336) - || (ordenador.currline < 40) || (ordenador.currline >= 280)) - return; - - mask = 0x80; - for (bucle = 0; bucle < 8; bucle++) { + + if (ordenador.pixels_octect==0 ||bit == 8) mask = 0x80; + + for (bucle = 0; bucle < bit; bucle++) { valor = (octet & mask) ? (int) ink : (int) paper; p=(colors+valor); @@ -1132,17 +1372,45 @@ void ResetComputer () { ordenador.updown=0; ordenador.leftright=0; + + ordenador.wr=0; + ordenador.r_fetch = 0; + ordenador.io = 0; + ordenador.contention = 0; ordenador.ulaplus=0; ordenador.mport1 = 0; ordenador.mport2 = 0; ordenador.video_offset = 0; // video in page 9 (page 5 in 128K) - switch (ordenador.mode128k) { + switch (ordenador.mode128k) { case 0: // 48K ordenador.pixancho = 447; + ordenador.start_screen=41; + if (ordenador.videosystem==0) + { ordenador.pixalto = 311; - + ordenador.upper_border_line = 64; + ordenador.lower_border_line = 64 + 192; + ordenador.cpufreq = 3500000; + ordenador.tstatodos_frame= 69888; + ordenador.start_contention = 14335; + ordenador.end_contention = 14335+224*192; + ordenador.first_line = 40; + ordenador.last_line = 280; + } + else + { + ordenador.pixalto = 263; + ordenador.upper_border_line = 40; + ordenador.lower_border_line = 40 + 192; + ordenador.cpufreq = 3527500; + ordenador.tstatodos_frame= 59136; + ordenador.start_contention = 8959; + ordenador.end_contention = 8959+224*192; + ordenador.first_line = 16; + ordenador.last_line = 256; + } ordenador.block0 = ordenador.memoria; ordenador.block1 = ordenador.memoria + 131072; // video mem. in page 9 (page 5 in 128K) ordenador.block2 = ordenador.memoria + 65536; // 2nd block in page 6 (page 2 in 128K) @@ -1151,13 +1419,22 @@ void ResetComputer () { break; case 3: // +2A/+3 - Z80free_Out (0x1FFD, 0); + Z80free_Out_fake (0x1FFD, 0); case 1: // 128K case 2: // +2 case 4: // spanish 128K - Z80free_Out (0x7FFD, 0); + Z80free_Out_fake (0x7FFD, 0); ordenador.pixancho = 455; ordenador.pixalto = 310; + ordenador.upper_border_line = 63; + ordenador.lower_border_line = 63 + 192; + ordenador.cpufreq = 3546900; + ordenador.tstatodos_frame= 70908; + ordenador.start_contention = 14361; + ordenador.end_contention = 14361+228*192; + ordenador.first_line = 40; + ordenador.last_line = 280; + ordenador.start_screen=45; break; } @@ -1167,36 +1444,75 @@ void ResetComputer () { // check if there's contention and waits the right number of tstates void do_contention() { - - if (!ordenador.contended_zone) - return; - - if (ordenador.cicles_counter<14335) { - return; - } - int ccicles=(ordenador.cicles_counter-14335)%8; - - if (ccicles>5) { - return; - } + static int ccicles; + + if ((ordenador.currline < ordenador.upper_border_line ) || (ordenador.currline >= ordenador.lower_border_line) + || (ordenador.currpix < 40) || (ordenador.currpix > 295)) return; + + if (ordenador.mode128k==3) //+3 + { + ccicles=((ordenador.currpix-28)/2)%8; //44-16 + if (ccicles>6) return; + ordenador.contention+=7-ccicles; + emulate_screen(7-ccicles); + } + else //64k/128k/+2 + { + ccicles=((ordenador.currpix-40)/2)%8; + if (ccicles>5) return; + ordenador.contention+=6-ccicles; + emulate_screen(6-ccicles); + } - emulate(6-ccicles); - } -void Z80free_Wr (register word Addr, register byte Value) { +void Z80free_Wr (register word Addr, register byte Value) { + + ordenador.wr+=3; switch (Addr & 0xC000) { case 0x0000: // only writes in the first 16K if we are in +3 mode and bit0 of mport2 is 1 - + if (ordenador.precision) emulate_screen(3); if ((ordenador.mode128k == 3) && (1 == (ordenador.mport2 & 0x01))) *(ordenador.block0 + Addr) = (unsigned char) Value; break; case 0x4000: do_contention(); + if (ordenador.precision) emulate_screen(3); + *(ordenador.block1 + Addr) = (unsigned char) Value; + break; + + case 0x8000: + if (ordenador.precision) emulate_screen(3); + *(ordenador.block2 + Addr) = (unsigned char) Value; + break; + + case 0xC000: + if (ordenador.precision) { + if (((ordenador.mode128k==1)||(ordenador.mode128k==2)||(ordenador.mode128k==4))&&(ordenador.mport1 & 0x01)) do_contention(); + emulate_screen(3); + } + *(ordenador.block3 + Addr) = (unsigned char) Value; + break; + } + +} + +void Z80free_Wr_fake (register word Addr, register byte Value) { + + switch (Addr & 0xC000) { + + case 0x0000: + // only writes in the first 16K if we are in +3 mode and bit0 of mport2 is 1 + + if ((ordenador.mode128k == 3) && (1 == (ordenador.mport2 & 0x01))) + *(ordenador.block0 + Addr) = (unsigned char) Value; + break; + + case 0x4000: *(ordenador.block1 + Addr) = (unsigned char) Value; break; @@ -1210,8 +1526,7 @@ void Z80free_Wr (register word Addr, register byte Value) { } } - -byte Z80free_Rd (register word Addr) { +byte Z80free_Rd_fetch (register word Addr) { if((ordenador.mdr_active)&&(ordenador.mdr_paged)&&(Addr<8192)) // Interface I return((byte)ordenador.shadowrom[Addr]); @@ -1223,21 +1538,77 @@ byte Z80free_Rd (register word Addr) { break; default: + ordenador.r_fetch+=4; switch (Addr & 0xC000) { case 0x0000: + if (ordenador.precision) emulate_screen (4); return ((byte) (*(ordenador.block0 + Addr))); break; case 0x4000: do_contention(); + if (ordenador.precision) emulate_screen (4); return ((byte) (*(ordenador.block1 + Addr))); break; case 0x8000: + if (ordenador.precision) emulate_screen (4); return ((byte) (*(ordenador.block2 + Addr))); break; case 0xC000: + if (ordenador.precision) { + if (((ordenador.mode128k==1)||(ordenador.mode128k==2)||(ordenador.mode128k==4))&&(ordenador.mport1 & 0x01)) do_contention(); + emulate_screen (4); + } + return ((byte) (*(ordenador.block3 + Addr))); + break; + + default: + printf ("Memory error\n"); + exit (1); + return 0; + } + + break; + } +} + +byte Z80free_Rd (register word Addr) { + + if((ordenador.mdr_active)&&(ordenador.mdr_paged)&&(Addr<8192)) // Interface I + return((byte)ordenador.shadowrom[Addr]); + + switch (ordenador.other_ret) { + case 1: + ordenador.other_ret = 0; + return (201); // RET instruction + break; + + default: + ordenador.wr+=3; + switch (Addr & 0xC000) { + case 0x0000: + if (ordenador.precision) emulate_screen (3); + return ((byte) (*(ordenador.block0 + Addr))); + break; + + case 0x4000: + do_contention(); + if (ordenador.precision) emulate_screen (3); + return ((byte) (*(ordenador.block1 + Addr))); + break; + + case 0x8000: + if (ordenador.precision) emulate_screen (3); + return ((byte) (*(ordenador.block2 + Addr))); + break; + + case 0xC000: + if (ordenador.precision) { + if (((ordenador.mode128k==1)||(ordenador.mode128k==2)||(ordenador.mode128k==4))&&(ordenador.mport1 & 0x01)) do_contention(); + emulate_screen (3); + } return ((byte) (*(ordenador.block3 + Addr))); break; @@ -1275,22 +1646,47 @@ void set_palete_entry(unsigned char entry, byte Value) { void Z80free_Out (register word Port, register byte Value) { - // Microdrive access - register word maskport; - if (((Port&0x0001)==0)||((Port>=0x4000)&&(Port<0x8000))) { - do_contention(); + //It should out after 3 states + + if (ordenador.precision) + { + switch (ordenador.mode128k) + { + case 0: + if ((Port & 0xC000) == 0x4000) // (Port>=0x4000)&&(Port<0x8000) + {if ((Port&0x0001)==0 ||(Port == 0xBF3B)||(Port == 0xFF3B)) {do_contention();emulate_screen(1);do_contention();ordenador.io+=1;} + else {do_contention();emulate_screen(1);do_contention();emulate_screen(1);do_contention();emulate_screen(1);do_contention();ordenador.io+=3;} + } + else + if ((Port&0x0001)==0 ||(Port == 0xBF3B)||(Port == 0xFF3B)) {emulate_screen(1);do_contention();ordenador.io+=1;} + break; + case 1: + case 2: + case 4: + if (((Port & 0xC000) == 0x4000)||((ordenador.mport1 & 0x01)&&((Port & 0xC000) == 0xC000))) // (Port>=0xc000)&&(Port<=0xffff) + {if ((Port&0x0001)==0 ||(Port == 0xBF3B)||(Port == 0xFF3B)) {do_contention();emulate_screen(1);do_contention();ordenador.io+=1;} + else {do_contention();emulate_screen(1);do_contention();emulate_screen(1);do_contention();emulate_screen(1);do_contention();ordenador.io+=3;} + } + else + if ((Port&0x0001)==0 ||(Port == 0xBF3B)||(Port == 0xFF3B)) {emulate_screen(1);do_contention();ordenador.io+=1;} + break; + case 3: + break; //no io contention in +3 + default: + break; + } } + else if ((Port&0x0001)==0) do_contention(); + // ULAPlus if (Port == 0xBF3B) { - do_contention(); ordenador.ulaplus_reg = Value; return; } if (Port == 0xFF3B) { - do_contention(); if (ordenador.ulaplus_reg==0x40) { // mode ordenador.ulaplus=Value&0x01; return; @@ -1300,6 +1696,8 @@ void Z80free_Out (register word Port, register byte Value) { set_palete_entry(ordenador.ulaplus_reg,Value); } } + + // Microdrive access if(((Port &0x0018)!=0x0018)&&(ordenador.mdr_active)) microdrive_out(Port,Value); @@ -1321,9 +1719,9 @@ void Z80free_Out (register word Port, register byte Value) { // Memory page (7FFD & 1FFD) if (ordenador.mode128k==3) { - maskport=0x0FFD; - } else { maskport=0x3FFD; + } else { + maskport=0x7FFD; } if (((Port|maskport) == 0x7FFD) && (0 == (ordenador.mport1 & 0x20))) { @@ -1331,37 +1729,104 @@ void Z80free_Out (register word Port, register byte Value) { set_memory_pointers (); // set the pointers } - if (((Port|maskport) == 0x1FFD) && (0 == (ordenador.mport1 & 0x20))) { + if (((Port|0x0FFD) == 0x1FFD) && (0 == (ordenador.mport1 & 0x20))) { ordenador.mport2 = (unsigned char) Value; set_memory_pointers (); // set the pointers } // Sound chip (AY-3-8912) - if (((Port|maskport) == 0xFFFD)&&(ordenador.ay_emul)) + if (((Port|0x3FFD) == 0xFFFD)&&(ordenador.ay_emul)) // bit1, 14 ,15 according to the manual ordenador.ay_latch = ((unsigned int) (Value & 0x0F)); - if (((Port|maskport) == 0xBFFD)&&(ordenador.ay_emul)) { + if (((Port|0x3FFD) == 0xBFFD)&&(ordenador.ay_emul)) { //bit1, 14 ,15 according to the manual ordenador.ay_registers[ordenador.ay_latch] = (unsigned char) Value; if (ordenador.ay_latch == 13) //Envelope shape ordenador.ay_envel_way = 2; // start cycle } } +void Z80free_Out_fake (register word Port, register byte Value) { + + register word maskport; + + // ULA port (A0 low) + + if (!(Port & 0x0001)) { + ordenador.port254 = (unsigned char) Value; + ordenador.border = (((unsigned char) Value) & 0x07); + + if (ordenador.pause) { + if (Value & 0x10) + ordenador.sound_bit = 1; + else + ordenador.sound_bit = 0; // assign to SOUND_BIT the value + } + } + + // Memory page (7FFD & 1FFD) + + if (ordenador.mode128k==3) { + maskport=0x3FFD; + } else { + maskport=0x7FFD; + } + + if (((Port|maskport) == 0x7FFD) && (0 == (ordenador.mport1 & 0x20))) { + ordenador.mport1 = (unsigned char) Value; + set_memory_pointers (); // set the pointers + } + + if (((Port|0x0FFD) == 0x1FFD) && (0 == (ordenador.mport1 & 0x20))) { + ordenador.mport2 = (unsigned char) Value; + set_memory_pointers (); // set the pointers + } +} byte Z80free_In (register word Port) { static unsigned int temporal_io; - byte pines; - - if (((Port&0x0001)==0)||((Port>=0x4000)&&(Port<0x8000))) { - do_contention(); + static byte pines; + + + if (ordenador.precision) + { + ordenador.io+=4; + switch (ordenador.mode128k) + { + case 0: + if ((Port & 0xC000) == 0x4000) // (Port>=0x4000)&&(Port<0x8000) + {if ((Port&0x0001)==0 ||(Port == 0xBF3B)||(Port == 0xFF3B)) {do_contention();emulate_screen(1);do_contention();emulate_screen(3);} + else {do_contention();emulate_screen(1);do_contention();emulate_screen(1);do_contention();emulate_screen(1);do_contention();emulate_screen(1);} + } + else + if ((Port&0x0001)==0 ||(Port == 0xBF3B)||(Port == 0xFF3B)) {emulate_screen(1);do_contention();emulate_screen(3);} + else emulate_screen(4); + break; + case 1: + case 2: + case 4: + if (((Port & 0xC000) == 0x4000)||((ordenador.mport1 & 0x01)&&((Port & 0xC000) == 0xC000))) // (Port>=0xc000)&&(Port<=0xffff) + {if ((Port&0x0001)==0 ||(Port == 0xBF3B)||(Port == 0xFF3B)) {do_contention();emulate_screen(1);do_contention();emulate_screen(3);} + else {do_contention();emulate_screen(1);do_contention();emulate_screen(1);do_contention();emulate_screen(1);do_contention();emulate_screen(1);} + } + else + if ((Port&0x0001)==0 ||(Port == 0xBF3B)||(Port == 0xFF3B)) {emulate_screen(1);do_contention();emulate_screen(3);} + else emulate_screen(4); + break; + case 3: + emulate_screen(4);//no io contention in +3 + break; + default: + emulate_screen(4); + break; + } } - + else if ((Port&0x0001)==0) do_contention(); + temporal_io = (unsigned int) Port; - + if (Port == 0xFF3B) { - do_contention(); if (ordenador.ulaplus_reg==0x40) { // mode return(ordenador.ulaplus&0x01); } @@ -1415,7 +1880,10 @@ byte Z80free_In (register word Port) { } } - if ((temporal_io == 0xFFFD)&&(ordenador.ay_emul)) + if ((temporal_io == 0xFFFD)&&(ordenador.ay_emul)) //any mask to apply? + return (ordenador.ay_registers[ordenador.ay_latch]); + + if ((temporal_io == 0xBFFD)&&(ordenador.ay_emul)&&(ordenador.mode128k==3)) //any mask to apply? return (ordenador.ay_registers[ordenador.ay_latch]); // Microdrive access @@ -1424,7 +1892,12 @@ byte Z80free_In (register word Port) { return(microdrive_in(Port)); pines=bus_empty(); - + + if (ordenador.precision && (ordenador.mode128k==1||ordenador.mode128k==2||(ordenador.mode128k==4))) + { if (temporal_io == 0x7FFD) Z80free_Out_fake (0x7FFD,pines); //writeback 0X7ffd + if (temporal_io == 0x3FFD) Z80free_Out_fake (0x3FFD,pines); //writeback 0X3ffd + } + return (pines); } @@ -1475,3 +1948,46 @@ void set_volume (unsigned char volume) { break; } } + +void restart_video() +{ + int dblbuffer=1,hwsurface=1; + char old_border; + +clean_screen(); + +if (ordenador.mustlock) { + SDL_UnlockSurface (ordenador.screen); + SDL_Flip (ordenador.screen); + SDL_LockSurface (ordenador.screen); + } else { + SDL_Flip (ordenador.screen); + } + + +switch(ordenador.zaurus_mini) { + case 0: + init_screen(640,480,0,0,dblbuffer,hwsurface); + break; + case 1: + case 2: + init_screen(480,640,0,0,dblbuffer,hwsurface); + break; + case 3: + init_screen(320,240,0,0,dblbuffer,hwsurface); + break; + } + + old_border = ordenador.border; + register_screen(screen); + ordenador.border = old_border; + + ordenador.screenbuffer=ordenador.screen->pixels; + ordenador.screen_width=ordenador.screen->w; + + //Init SDL Menu + + menu_init(ordenador.screen); + + clean_screen(); +} diff --git a/src/computer.h b/src/computer.h index 9e56afe..34fcb55 100644 --- a/src/computer.h +++ b/src/computer.h @@ -36,6 +36,7 @@ int countdown; struct computer { + unsigned char precision; //If set 1 emulate with more precision unsigned int temporal_io; // screen private global variables @@ -52,7 +53,7 @@ struct computer { unsigned int *p_translt,*p_translt2; unsigned char *pixel; // current address - char border,flash; + char border,flash, border_p; int currline,currpix; int tstados_counter; // counts tstates leaved to the next call @@ -67,8 +68,18 @@ struct computer { int next_pixel; // next pixel int pixancho,pixalto; // maximum pixel value for width and height int jump_pixel; + int upper_border_line; //63 or 62 for 48k or 128k + int lower_border_line; //upper_border_line + 192 + int start_screen; //Pixel at which the interrupt is generated + int cpufreq; //frequency CPU + int tstatodos_frame; //number of tstados per frame + int pixels_octect; //2 bits in the octect + int pixels_word; //2 bits in the word + int start_contention; //start tstados for contention + int end_contention; //end tstados for contention + unsigned char screen_snow; // 0-> no emulate snow; 1-> emulate snow - unsigned char contended_zone; // 0-> no contention; 1-> contention possible + //unsigned char contended_zone; // 0-> no contention; 1-> contention possible int cicles_counter; // counts how many pixel clock cicles passed since las interrupt char ulaplus; // 0 = inactive; 1 = active @@ -121,13 +132,18 @@ struct computer { signed char ay_envel_value; unsigned char ay_envel_way; unsigned char sound_current_value; + unsigned int wr; + unsigned int r_fetch; + unsigned int io; + unsigned int contention; // bus global variables unsigned char bus_counter; unsigned char bus_value; unsigned char issue; // 2= 48K issue 2, 3= 48K issue 3 - unsigned char mode128k; // 0=48K, 1=128K, 2=+2, 3=+3 + unsigned char mode128k; // 0=48K, 1=128K, 2=+2, 3=+3 4=sp + unsigned char videosystem; //0=PAL, 1=NTSC unsigned char joystick[2]; // 0=cursor, 1=kempston, 2=sinclair1, 3=sinclair2 unsigned char port254; @@ -193,6 +209,7 @@ struct computer { unsigned char memoria[196608]; // memory (12 pages of 16K each one). 4 for ROM, and 8 for RAM unsigned char shadowrom[8192]; // space for Interface I's ROMs unsigned char interr; + unsigned char readkeyboard; unsigned char mustlock; unsigned char other_ret; // 0=no change; 1=memory returns RET (201) @@ -219,11 +236,13 @@ struct computer { void computer_init(); void register_screen(SDL_Surface *); inline void show_screen(int); -inline void paint_pixels(unsigned char, unsigned char, unsigned char); +inline void show_screen_precision(int); +inline void paint_pixels(unsigned char, unsigned char, unsigned char, unsigned char); inline void read_keyboard(); void fill_audio(void *udata,Uint8 *,int); void set_volume(unsigned char); inline void play_sound(unsigned int); +inline void emulate_screen(int); inline void emulate(int); void ResetComputer(); inline byte bus_empty(); @@ -232,5 +251,6 @@ inline void play_ay(); inline void paint_one_pixel(unsigned char *colour,unsigned char *address); void computer_set_palete(); void set_palete_entry(unsigned char entry, byte Value); +void restart_video(); #endif diff --git a/src/emulator.c b/src/emulator.c index 5cb5c5e..af5a3e8 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -1,1166 +1,1250 @@ -/* - * Copyright (C) 2012 Fabio Olimpieri - * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX Wii - * - * FBZX Wii is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * FBZX Wii is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "z80free/Z80free.h" -#include "computer.h" -#include "emulator.h" -#include "cargador.h" -#include -#include -#include -#include -#include -#include -#include "characters.h" -#include "menus.h" -#include -#include -#include -#include -#include "sound.h" -#include "tape.h" -#include "microdrive.h" -#include "menu_sdl.h" - -#ifdef GEKKO -#include -#include -#include -#include -#include -#endif - -#ifdef DEBUG -FILE *fdebug; -#define printf(...) fprintf(fdebug,__VA_ARGS__) -#else - #ifdef GEKKO - #define printf(...) - #endif -#endif - -char debug_var=1; - -Z80FREE procesador; -struct computer ordenador; -SDL_Surface *screen; -char salir,sound_aborted; -unsigned char *sound[NUM_SNDBUF]; -char path_snaps[2049]; -char path_taps[2049]; -char path_mdrs[2049]; -char path_scr[2049]; -char path_confs[2049]; -unsigned int colors[80]; -unsigned int jump_frames,curr_frames; -char *filenames[5]; -static SDL_Surface *image; - -bool usbismount = false; -bool networkisinit = false; -bool smbismount = false; - -#if defined(GEKKO) - -/**************************************************************************** - * Mount SMB Share - ****************************************************************************/ - -bool ConnectShare () -{ - - if(smbismount) - return true; - printf("user: %s\n", ordenador.SmbUser); - printf("pass: %s\n", ordenador.SmbPwd); - printf("share: %s\n", ordenador.SmbShare); - printf("ip: %s\n", ordenador.SmbIp); - - int a; - for (a=0;a<3;a++) - if(smbInit(ordenador.SmbUser, ordenador.SmbPwd,ordenador.SmbShare, ordenador.SmbIp)) - {smbismount = true; break;} - - - if(!smbismount) printf("Failed to connect to SMB share\n"); - else { - printf("Established connection to SMB share\n"); - } - - return smbismount; -} - -void CloseShare() -{ - - if(smbismount) { - printf("Disconnected from SMB share\n"); - smbClose("smb"); - } - smbismount = false; -} - -/**************************************************************************** - * init and deinit USB device functions - ****************************************************************************/ - -bool InitUSB() -{ - printf("Initializing USB FAT subsytem ...\n"); - fatUnmount("usb:"); - - // This should wake up the drive - bool isMounted = fatMountSimple("usb", &__io_usbstorage); - - bool isInserted = __io_usbstorage.isInserted(); - if (!isInserted) - { - printf("USB device not found\n"); - return false; - } - - // USB Drive may be "sleeeeping" - // We need to try Mounting a few times to wake it up - int retry = 10; - while (retry && !isMounted) - { - sleep(1); - isMounted = fatMountSimple("usb", &__io_usbstorage); - retry--; - } - if (isMounted) - printf("USB FAT subsytem initialized\n"); - else - printf("Impossible to initialize USB FAT subsytem\n"); - return isMounted; - } - - void DeInitUSB() -{ - fatUnmount("usb:"); - __io_usbstorage.shutdown(); -} - -bool InitNetwork() -{ - char myIP[16]; - - memset(myIP, 0, sizeof(myIP)); - printf("Getting IP address via DHCP...\n"); - - if (if_config(myIP, NULL, NULL, true) < 0) { - printf("No DHCP reply\n"); - return false; - } - printf("Got an address: %s\n",myIP); - return true; -} - -#endif - -int load_zxspectrum_picture() -{ - -image=IMG_Load("/fbzx-wii/fbzx/ZXSpectrum48k.png"); - -if (image == NULL) {printf("Impossible to load image\n"); return 0;} - -SDL_BlitSurface(image, NULL, ordenador.screen, NULL); - -if (ordenador.mustlock) { - SDL_UnlockSurface (ordenador.screen); - SDL_Flip (ordenador.screen); - SDL_LockSurface (ordenador.screen); - } else { - SDL_Flip (ordenador.screen); - } - -return 1; -} - -void SDL_Fullscreen_Switch() -{ - Uint32 flags = screen->flags; - if ( flags & SDL_FULLSCREEN ) - flags &= ~SDL_FULLSCREEN; - else - flags |= SDL_FULLSCREEN; - - screen = SDL_SetVideoMode(screen->w, screen->h, screen->format->BitsPerPixel,flags); -} - -FILE *myfopen(char *filename,char *mode) { - - char tmp[4096]; - FILE *fichero; - - fichero=fopen(filename,mode); - if (fichero!=NULL) { - return (fichero); - } - sprintf(tmp,"/usr/share/%s",filename); - fichero=fopen(tmp,mode); - if (fichero!=NULL) { - return (fichero); - } - sprintf(tmp,"/usr/local/share/%s",filename); - fichero=fopen(tmp,mode); - if (fichero!=NULL) { - return (fichero); - } - #ifdef GEKKO - sprintf(tmp,"/fbzx-wii/%s",filename); - fichero=fopen(tmp,mode); - if (fichero!=NULL) { - return (fichero); - } - #endif - - return (NULL); -} - -char *load_a_rom(char **filenames) { - - char **pointer; - int offset=0; - FILE *fichero; - int size; - - for(pointer=filenames;*pointer!=NULL;pointer++) { - fichero=myfopen(*pointer,"r"); - if(fichero==NULL) { - return (*pointer); - } - size=fread(ordenador.memoria+offset,16384,1,fichero); - offset+=16384; - fclose(fichero); - } - return (NULL); -} - -void load_rom(char type) { - - char *retval; - FILE *fichero; - int size; - - switch(type) { - case 0: - filenames[0]="spectrum-roms/48.rom"; - filenames[1]=NULL; - retval=load_a_rom(filenames); - if (retval) { - printf("Can't load file %s\n",retval); - exit(1); - } - break; - case 1: - filenames[0]="spectrum-roms/128-0.rom"; - filenames[1]="spectrum-roms/128-1.rom"; - filenames[2]=NULL; - retval=load_a_rom(filenames); - if (retval) { - printf("Can't load file %s\n",retval); - exit(1); - } - break; - case 2: - filenames[0]="spectrum-roms/plus2-0.rom"; - filenames[1]="spectrum-roms/plus2-1.rom"; - filenames[2]=NULL; - retval=load_a_rom(filenames); - if (retval) { - printf("Can't load file %s\n",retval); - exit(1); - } - break; - case 3: - // first, try last version of PLUS3 roms - - filenames[0]="spectrum-roms/plus3-41-0.rom"; - filenames[1]="spectrum-roms/plus3-41-1.rom"; - filenames[2]="spectrum-roms/plus3-41-2.rom"; - filenames[3]="spectrum-roms/plus3-41-3.rom"; - filenames[4]=NULL; - retval=load_a_rom(filenames); - if (retval) { - printf("Can't load the Spectrum +3 ROM version 4.1. Trying with version 4.0\n"); - filenames[0]="spectrum-roms/plus3-40-0.rom"; - filenames[1]="spectrum-roms/plus3-40-1.rom"; - filenames[2]="spectrum-roms/plus3-40-2.rom"; - filenames[3]="spectrum-roms/plus3-40-3.rom"; - filenames[4]=NULL; - retval=load_a_rom(filenames); - if (retval) { - printf("Can't load the Spectrum +3 ROM version 4.0. Trying with legacy filenames\n"); - filenames[0]="spectrum-roms/plus3-0.rom"; - filenames[1]="spectrum-roms/plus3-1.rom"; - filenames[2]="spectrum-roms/plus3-2.rom"; - filenames[3]="spectrum-roms/plus3-3.rom"; - filenames[4]=NULL; - retval=load_a_rom(filenames); - if (retval) { - printf("Can't load file %s\n",retval); - exit(1); - } - } - } - break; - case 4: - filenames[0]="spectrum-roms/128-spanish-0.rom"; - filenames[1]="spectrum-roms/128-spanish-1.rom"; - filenames[2]=NULL; - retval=load_a_rom(filenames); - if (retval) { - printf("Can't load file %s\n",retval); - exit(1); - } - break; - } - - fichero=myfopen("spectrum-roms/if1-2.rom","r"); // load Interface1 ROM - if(fichero==NULL) { - // try legacy name - fichero=myfopen("spectrum-roms/if1-v2.rom","r"); - if(fichero==NULL) { - printf("Can't open Interface1 ROM file\n"); - exit(1); - } - } - size=fread(ordenador.shadowrom,8192,1,fichero); - fclose(fichero); -} - -void init_screen(int resx,int resy,int depth,int fullscreen,int dblbuffer,int hwsurface) { - - int retorno,bucle,bucle2,valores,ret2; - - //if (sound_type!=3) - retorno=SDL_Init(SDL_INIT_VIDEO); - /*else - retorno=SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);*/ - if(retorno!=0) { - printf("Can't initialize SDL library. Exiting\n"); - exit(1); - } - - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK)) { - ordenador.use_js=0; - printf("Can't initialize JoyStick subsystem\n"); - } else { - printf("JoyStick subsystem initialized\n"); - ordenador.use_js=1; - if(SDL_NumJoysticks()>0){ - // Open joystick - ordenador.joystick_number = SDL_NumJoysticks(); - if (ordenador.joystick_number>2) ordenador.joystick_number = 2; //Open max 2 joysticks - printf("Try to open %d joysticks \n", ordenador.joystick_number); - for (bucle=0;bucleformat->BytesPerPixel; - printf("Bytes per pixel: %d\n",ordenador.bpp); - - if(SDL_MUSTLOCK(screen)) { - ordenador.mustlock=1; - SDL_LockSurface(screen); - } else - ordenador.mustlock=0; - - printf("Locking screen: %d\n", ordenador.mustlock); - - // sound initialization - - if (sound_type==SOUND_AUTOMATIC) { - ret2=sound_init(1); // check all sound systems - } else { - ret2=sound_init(0); // try with the one specified in command line - } - if(ret2==0) { - sound_aborted=0; - } else { // if fails, run without sound - sound_type=SOUND_NO; - sound_init(0); - sound_aborted=1; - } - printf("Init sound\n"); - if(ordenador.format) - ordenador.increment=2*ordenador.channels; - else - ordenador.increment=ordenador.channels; - - for(bucle2=0;bucle2mode128k,10); - fprintf(fconfig,"issue=%c%c",48+object->issue,10); - fprintf(fconfig,"joystick1=%c%c",48+object->joystick[0],10); - fprintf(fconfig,"joystick2=%c%c",48+object->joystick[1],10); - fprintf(fconfig,"ay_sound=%c%c",48+object->ay_emul,10); - fprintf(fconfig,"interface1=%c%c",48+object->mdr_active,10); - fprintf(fconfig,"doublescan=%c%c",48+object->dblscan,10); - fprintf(fconfig,"volume=%c%c",65+(object->volume),10); - fprintf(fconfig,"bw=%c%c",48+object->bw,10); - fprintf(fconfig,"tap_fast=%c%c",48+object->tape_fast_load,10); - fprintf(fconfig,"joypad1=%c%c",48+object->joypad_as_joystick[0],10); - fprintf(fconfig,"joypad2=%c%c",48+object->joypad_as_joystick[1],10); - fprintf(fconfig,"rumble1=%c%c",48+object->rumble[0],10); - fprintf(fconfig,"rumble2=%c%c",48+object->rumble[1],10); - fprintf(fconfig,"port=%c%c",48+object->port,10); - fprintf(fconfig,"autoconf=%c%c",48+object->autoconf,10); - - - for (joy_n=0; joy_n<2; joy_n++) - for (key=0; key<22; key++) - fprintf(fconfig,"joybutton_%c_%c=%.3d%c",joy_n+48,key+97, object->joybuttonkey[joy_n][key],10); - - fclose(fconfig); - return 0; - -} - -int save_config_game(struct computer *object, char *filename, int overwrite) { - - unsigned char key, joy_n; - FILE *fconfig; - - fconfig=fopen(filename,"r"); - if((fconfig!=NULL)&&(!overwrite)) { - fclose(fconfig); - return -1; // file already exists - } - - fconfig = fopen(filename,"wb"); - if (fconfig==NULL) { - return -2; // can't create file - } - - fprintf(fconfig,"joystick1=%c%c",48+object->joystick[0],10); - fprintf(fconfig,"joystick2=%c%c",48+object->joystick[1],10); - fprintf(fconfig,"ay_sound=%c%c",48+object->ay_emul,10); - fprintf(fconfig,"joypad1=%c%c",48+object->joypad_as_joystick[0],10); - fprintf(fconfig,"joypad2=%c%c",48+object->joypad_as_joystick[1],10); - fprintf(fconfig,"rumble1=%c%c",48+object->rumble[0],10); - fprintf(fconfig,"rumble2=%c%c",48+object->rumble[1],10); - - for (joy_n=0; joy_n<2; joy_n++) - for (key=0; key<22; key++) - fprintf(fconfig,"joybutton_%c_%c=%.3d%c",joy_n+48,key+97, object->joybuttonkey[joy_n][key],10); - - fclose(fconfig); - return 0; - -} - -void load_config_smb(struct computer *object) { - - char line[1024],carac,done; - int pos; - FILE *fconfig; - unsigned char smb_enable=0; - - fconfig = fopen("/fbzx-wii/fbzx.smb","r"); - if (fconfig==NULL) { - return; - } - - done=1; - pos=0; - line[0]=0; - while(!feof(fconfig)) { - if (done) { - line[0]=0; - pos=0; - done=0; - } - if (0!=fread(&carac,1,1,fconfig)) { - if ((carac!=13)&&(carac!=10)) { - line[pos]=carac; - if (pos<1023) { - pos++; - } - continue; - } - } - done=1; - line[pos]=0; - if (line[0]=='#') { // comment - continue; - } - if (!strncmp(line,"smb_enable=",11)) { - smb_enable=line[11]-'0'; - continue; - } - if (!strncmp(line,"user=",5)) { - if (line[5]) - strcpy (object->SmbUser,line+5); - continue; - } - if (!strncmp(line,"password=",9)) { - if (line[9]) - strcpy (object->SmbPwd,line+9); - continue; - } - if (!strncmp(line,"share_name=",11)) { - if (line[11]) - strcpy (object->SmbShare,line+11); - continue; - } - - if (!strncmp(line,"smb_ip=",7)) { - if (line[7]) - strcpy (object->SmbIp,line+7); - continue; - } - - if (smb_enable<2) { - object->smb_enable=smb_enable;} - } - - -fclose(fconfig); -} - -int load_config(struct computer *object, char *filename) { - - char config_path[1024]; - char line[1024],carac,done; - int pos, key_sdl=0; - FILE *fconfig; - unsigned char volume=255,mode128k=255,issue=255,joystick1=255,joystick2=255,ay_emul=255,mdr_active=255, - dblscan=255,bw=255, tap_fast=255, joypad1=255, joypad2=255, rumble1=255, rumble2=255, joy_n=255, key_n=255, port=255, autoconf=255; - - if (filename) strcpy(config_path,filename); - else return -2; - - fconfig = fopen(config_path,"rb"); - if (fconfig==NULL) { - return -1; - } - - done=1; - pos=0; - line[0]=0; - while(!feof(fconfig)) { - if (done) { - line[0]=0; - pos=0; - done=0; - } - if (0!=fread(&carac,1,1,fconfig)) { - if ((carac!=13)&&(carac!=10)) { - line[pos]=carac; - if (pos<1023) { - pos++; - } - continue; - } - } - done=1; - line[pos]=0; - if (line[0]=='#') { // comment - continue; - } - if (!strncmp(line,"mode=",5)) { - printf("Cambio a modo %c\n",line[5]); - mode128k=line[5]-'0'; - continue; - } - if (!strncmp(line,"issue=",6)) { - issue=line[6]-'0'; - continue; - } - if (!strncmp(line,"joystick1=",10)) { - joystick1=line[10]-'0'; - continue; - } - if (!strncmp(line,"joystick2=",10)) { - joystick2=line[10]-'0'; - continue; - } - if (!strncmp(line,"ay_sound=",9)) { - ay_emul=line[9]-'0'; - continue; - } - if (!strncmp(line,"interface1=",11)) { - mdr_active=line[11]-'0'; - continue; - } - if (!strncmp(line,"doublescan=",11)) { - dblscan=line[11]-'0'; - continue; - } - if (!strncmp(line,"volume=",7)) { - volume=(line[7]-'A'); - continue; - } - if (!strncmp(line,"bw=",3)) { - bw=(line[3]-'0'); - continue; - } - if (!strncmp(line,"tap_fast=",9)) { - tap_fast=(line[9]-'0'); - continue; - } - if (!strncmp(line,"joypad1=",8)) { - joypad1=line[8]-'0'; - continue; - } - if (!strncmp(line,"joypad2=",8)) { - joypad2=line[8]-'0'; - continue; - } - if (!strncmp(line,"rumble1=",8)) { - rumble1=line[8]-'0'; - continue; - } - if (!strncmp(line,"rumble2=",8)) { - rumble2=line[8]-'0'; - continue; - } - if (!strncmp(line,"port=",5)) { - port=line[5]-'0'; - continue; - } - if (!strncmp(line,"autoconf=",9)) { - autoconf=line[9]-'0'; - continue; - } - if (!strncmp(line,"joybutton_",10)) { - sscanf(line, "joybutton_%c_%c=%3d",&joy_n ,&key_n, &key_sdl); - if ((joy_n<50) && (joy_n>47) && (key_n<119) && (key_n>96)) - object->joybuttonkey[joy_n-48][key_n-97]=key_sdl; - continue; - } - } - - if (mode128k<5) { - object->mode128k=mode128k; - } - if (issue<4) { - object->issue=issue; - } - if (joystick1<4) { - object->joystick[0]=joystick1; - } - if (joystick2<4) { - object->joystick[1]=joystick2; - } - if (ay_emul<2) { - object->ay_emul=ay_emul; - } - if (mdr_active<2) { - object->mdr_active=mdr_active; - } - if (dblscan<2) { - object->dblscan=dblscan; - } - if (bw<2) { - object->bw=bw; - } - if (volume<17) { - object->volume=volume; - set_volume(volume); - } - if (tap_fast<2) { - object->tape_fast_load=tap_fast; - } - if (joypad1<2) { - object->joypad_as_joystick[0]=joypad1; - } - if (joypad2<2) { - object->joypad_as_joystick[1]=joypad2; - } - if (rumble1<2) { - object->rumble[0]=rumble1; - } - if (rumble2<2) { - object->rumble[1]=rumble2; - } - if (port<3) { - object->port=port; - } - if (autoconf<2) { - object->autoconf=autoconf; - } - - fclose(fconfig); - return 0; -} - -int main(int argc,char *argv[]) { - - int bucle,tstados,argumento,fullscreen,dblbuffer,hwsurface,length; - char gamefile[4096],config_path[1024] ; - - word PC=0; - - - // by default, try all sound modes - sound_type=SOUND_AUTOMATIC; - gamefile[0]=0; - ordenador.zaurus_mini=0; - ordenador.text_mini=0; - ordenador.ulaplus=0; - ordenador.ulaplus_reg=0; - fullscreen=0; - dblbuffer=0; - hwsurface=0; - - argumento=0; - jump_frames=0; - curr_frames=0; - ordenador.dblscan=1; - ordenador.bw=0; - - #ifdef DEBUG - fatInitDefault(); - fdebug = fopen("/fbzx-wii/logfile.txt","w"); - #endif - - #ifdef GEKKO - dblbuffer=1; - hwsurface=1; - setenv("HOME", "/fbzx-wii", 1); - - //initialize libfat library - if (!fatInitDefault()) - { - printf("Couldn't initialize SD fat subsytem\n"); - - exit(0); - } - else - printf("SD FAT subsytem initialized\n"); - - #endif - - - computer_init(); - printf("Computer init\n"); - - printf("Modo: %d\n",ordenador.mode128k); - - printf("Set volume\n"); - set_volume(16); - - // load current config - strcpy(config_path,getenv("HOME")); - length=strlen(config_path); - if ((length>0)&&(config_path[length-1]!='/')) - strcat(config_path,"/"); - strcat(config_path,"fbzx.conf"); - - load_config(&ordenador, config_path); - - printf("Modo: %d\n",ordenador.mode128k); - while(argumentopixels; - ordenador.screen_width=ordenador.screen->w; - - //Init SDL Menu - - menu_init(ordenador.screen); - - //Load the splash screen - if (load_zxspectrum_picture()) SDL_FreeSurface (image); - - #ifdef GEKKO - usbismount = InitUSB(); - - load_config_smb(&ordenador); - - if (ordenador.smb_enable) networkisinit = InitNetwork(); - - if (networkisinit && ordenador.smb_enable) ConnectShare(); - - #endif - - // assign initial values for PATH variables - - strcpy(path_snaps,getenv("HOME")); - length=strlen(path_snaps); - if ((length>0)&&(path_snaps[length-1]!='/')) - strcat(path_snaps,"/"); - strcpy(path_taps,path_snaps); - strcpy(path_mdrs,path_snaps); - strcpy(path_scr,path_snaps); - strcpy(path_confs,path_snaps); - strcat(path_snaps,"snapshots"); - strcat(path_taps,"tapes"); - strcat(path_mdrs,"microdrives"); - strcat(path_scr,"scr"); - strcat(path_confs,"configurations"); - - #ifdef GEKKO - if ((ordenador.port==1)&&usbismount) { - strcpy(path_snaps,"usb:/"); - strcpy(path_taps,"usb:/"); - } - if ((ordenador.port==2)&&smbismount) { - strcpy(path_snaps,"smb:/"); - strcpy(path_taps,"smb:/"); - } - #endif - - ordenador.current_tap[0]=0; - - // assign random values to the memory before start execution - - printf("Reset memory\n"); - printf("Modo: %d\n",ordenador.mode128k); - for(bucle=0;bucle<196608;bucle++) - ordenador.memoria[bucle]=(unsigned char) rand(); - - printf("Memory resetted\n"); - ordenador.tap_file=NULL; - printf("Modo: %d\n",ordenador.mode128k); - - // we filter all the events, except keyboard events - - SDL_EventState(SDL_ACTIVEEVENT,SDL_IGNORE); - SDL_EventState(SDL_MOUSEMOTION,SDL_IGNORE); - SDL_EventState(SDL_MOUSEBUTTONDOWN,SDL_IGNORE); - SDL_EventState(SDL_MOUSEBUTTONUP,SDL_IGNORE); - SDL_EventState(SDL_JOYAXISMOTION,SDL_IGNORE); - SDL_EventState(SDL_JOYBALLMOTION,SDL_IGNORE); - SDL_EventState(SDL_JOYHATMOTION,SDL_IGNORE); - SDL_EventState(SDL_JOYBUTTONDOWN,SDL_IGNORE); - SDL_EventState(SDL_JOYBUTTONUP,SDL_IGNORE); - SDL_EventState(SDL_QUIT,SDL_ENABLE); - SDL_EventState(SDL_SYSWMEVENT,SDL_IGNORE); - SDL_EventState(SDL_VIDEORESIZE,SDL_IGNORE); - SDL_EventState(SDL_USEREVENT,SDL_IGNORE); - - SDL_ShowCursor(SDL_DISABLE); - salir=1; - - printf("Init microdrive\n"); - microdrive_init(); - - printf("Reset computer\n"); - ResetComputer(); - - sleep(1); - - printf("Reset screen\n"); - clean_screen(); - - if (sound_aborted==1) { - strcpy(ordenador.osd_text,"Running without sound (read the FAQ)"); - ordenador.osd_time=100; - } - - printf("Modo: %d\n",ordenador.mode128k); - printf("load main game\n"); - load_main_game(gamefile); - printf("Modo: %d\n",ordenador.mode128k); - - sprintf(ordenador.osd_text,"Press Home for menu"); - ordenador.osd_time=200; - - printf("BPP: %d\n",ordenador.bpp); - while(salir) { - - do { - tstados=Z80free_ustep(&procesador); - if(tstados<0) { - printf("Error %X\n",procesador.PC); - exit(1); - } - emulate(tstados); // execute the whole hardware emulation for that number of TSTATES - } while(procesador.Status!=Z80XX); - - PC=procesador.PC; - - /* if PC is 0x0556, a call to LD_BYTES has been made, so if - FAST_LOAD is 1, we must load the block in memory and return */ - - if((!ordenador.mdr_paged)&&(PC==0x0556) && (ordenador.tape_fast_load==1)&&(ordenador.tape_file_type==TAP_TAP)) { - if(ordenador.tap_file!=NULL) - fastload_block(ordenador.tap_file); - else { - sprintf(ordenador.osd_text,"No TAP file selected"); - ordenador.osd_time=50; - } - } - - /* if PC is 0x04C2, a call to SA_BYTES has been made, so if - we want to save to the TAP file, we do it */ - - if((!ordenador.mdr_paged)&&(PC==0x04C2)&&(ordenador.tape_write==1)&&(ordenador.tape_file_type==TAP_TAP)) { - if(ordenador.tap_file!=NULL) - save_file(ordenador.tap_file); - else { - sprintf(ordenador.osd_text,"No TAP file selected"); - ordenador.osd_time=50; - } - } - - /* if ordenador.mdr_paged is 2, we have executed the RET at 0x0700, so - we have to return to the classic ROM */ - - if(ordenador.mdr_paged==2) - ordenador.mdr_paged=0; - - /* if PC is 0x0008 or 0x1708, and we have a microdrive, we have to page - the Interface 1 ROM */ - - if(((PC==0x0008)||(PC==0x1708))&&(ordenador.mdr_active)) - ordenador.mdr_paged = 1; - - /* if PC is 0x0700 and we have a microdrive, we have to unpage - the Interface 1 ROM after the last instruction */ - - if((PC==0x0700)&&(ordenador.mdr_active)) - ordenador.mdr_paged = 2; - - if(ordenador.interr==1) { - read_keyboard (); // read the physical keyboard - Z80free_INT(&procesador,bus_empty()); - ordenador.interr=0; - } - } - - #ifdef GEKKO - if (smbismount) CloseShare (); - DeInitUSB(); - fatUnmount(0); - #endif - - return 0; -} +/* + * Copyright (C) 2012 Fabio Olimpieri + * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "z80free/Z80free.h" +#include "computer.h" +#include "emulator.h" +#include "cargador.h" +#include +#include +#include +#include +#include +#include +#include "characters.h" +#include "menus.h" +#include +#include +#include +#include +#include "sound.h" +#include "tape.h" +#include "microdrive.h" +#include "menu_sdl.h" + +#ifdef GEKKO +#include +#include +#include +#include +#include +#endif + +#ifdef DEBUG +FILE *fdebug; +#define printf(...) fprintf(fdebug,__VA_ARGS__) +#else + #ifdef GEKKO + #define printf(...) + #endif +#endif + +char debug_var=1; + +Z80FREE procesador; +struct computer ordenador; +SDL_Surface *screen; +char salir,sound_aborted; +unsigned char *sound[NUM_SNDBUF]; +char path_snaps[2049]; +char path_taps[2049]; +char path_mdrs[2049]; +char path_scr[2049]; +char path_confs[2049]; +unsigned int colors[80]; +unsigned int jump_frames,curr_frames; +char *filenames[5]; +static SDL_Surface *image; + +bool usbismount = false; +bool networkisinit = false; +bool smbismount = false; + +extern int FULL_DISPLAY_X; //640 +extern int FULL_DISPLAY_Y; //480 +extern int RATIO; + +#if defined(GEKKO) + +/**************************************************************************** + * Mount SMB Share + ****************************************************************************/ + +bool ConnectShare () +{ + + if(smbismount) + return true; + printf("user: %s\n", ordenador.SmbUser); + printf("pass: %s\n", ordenador.SmbPwd); + printf("share: %s\n", ordenador.SmbShare); + printf("ip: %s\n", ordenador.SmbIp); + + int a; + for (a=0;a<3;a++) + if(smbInit(ordenador.SmbUser, ordenador.SmbPwd,ordenador.SmbShare, ordenador.SmbIp)) + {smbismount = true; break;} + + + if(!smbismount) printf("Failed to connect to SMB share\n"); + else { + printf("Established connection to SMB share\n"); + } + + return smbismount; +} + +void CloseShare() +{ + + if(smbismount) { + printf("Disconnected from SMB share\n"); + smbClose("smb"); + } + smbismount = false; +} + +/**************************************************************************** + * init and deinit USB device functions + ****************************************************************************/ + +bool InitUSB() +{ + printf("Initializing USB FAT subsytem ...\n"); + fatUnmount("usb:"); + + // This should wake up the drive + bool isMounted = fatMountSimple("usb", &__io_usbstorage); + + bool isInserted = __io_usbstorage.isInserted(); + if (!isInserted) + { + printf("USB device not found\n"); + return false; + } + + // USB Drive may be "sleeeeping" + // We need to try Mounting a few times to wake it up + int retry = 10; + while (retry && !isMounted) + { + sleep(1); + isMounted = fatMountSimple("usb", &__io_usbstorage); + retry--; + } + if (isMounted) + printf("USB FAT subsytem initialized\n"); + else + printf("Impossible to initialize USB FAT subsytem\n"); + return isMounted; + } + + void DeInitUSB() +{ + fatUnmount("usb:"); + __io_usbstorage.shutdown(); +} + +bool InitNetwork() +{ + char myIP[16]; + + memset(myIP, 0, sizeof(myIP)); + printf("Getting IP address via DHCP...\n"); + + if (if_config(myIP, NULL, NULL, true) < 0) { + printf("No DHCP reply\n"); + return false; + } + printf("Got an address: %s\n",myIP); + return true; +} + +#endif + +int load_zxspectrum_picture() +{ + +image=IMG_Load("/fbzx-wii/fbzx/ZXSpectrum48k.png"); + +if (image == NULL) {printf("Impossible to load image\n"); return 0;} + +SDL_BlitSurface(image, NULL, ordenador.screen, NULL); + +if (ordenador.mustlock) { + SDL_UnlockSurface (ordenador.screen); + SDL_Flip (ordenador.screen); + SDL_LockSurface (ordenador.screen); + } else { + SDL_Flip (ordenador.screen); + } + +return 1; +} + +void SDL_Fullscreen_Switch() +{ + Uint32 flags = screen->flags; + if ( flags & SDL_FULLSCREEN ) + flags &= ~SDL_FULLSCREEN; + else + flags |= SDL_FULLSCREEN; + + screen = SDL_SetVideoMode(screen->w, screen->h, screen->format->BitsPerPixel,flags); +} + +FILE *myfopen(char *filename,char *mode) { + + char tmp[4096]; + FILE *fichero; + + fichero=fopen(filename,mode); + if (fichero!=NULL) { + return (fichero); + } + sprintf(tmp,"/usr/share/%s",filename); + fichero=fopen(tmp,mode); + if (fichero!=NULL) { + return (fichero); + } + sprintf(tmp,"/usr/local/share/%s",filename); + fichero=fopen(tmp,mode); + if (fichero!=NULL) { + return (fichero); + } + #ifdef GEKKO + sprintf(tmp,"/fbzx-wii/%s",filename); + fichero=fopen(tmp,mode); + if (fichero!=NULL) { + return (fichero); + } + #endif + + return (NULL); +} + +char *load_a_rom(char **filenames) { + + char **pointer; + int offset=0; + FILE *fichero; + int size; + + for(pointer=filenames;*pointer!=NULL;pointer++) { + fichero=myfopen(*pointer,"r"); + if(fichero==NULL) { + return (*pointer); + } + size=fread(ordenador.memoria+offset,16384,1,fichero); + offset+=16384; + fclose(fichero); + } + return (NULL); +} + +void load_rom(char type) { + + char *retval; + FILE *fichero; + int size; + + switch(type) { + case 0: + filenames[0]="spectrum-roms/48.rom"; + filenames[1]=NULL; + retval=load_a_rom(filenames); + if (retval) { + printf("Can't load file %s\n",retval); + exit(1); + } + break; + case 1: + filenames[0]="spectrum-roms/128-0.rom"; + filenames[1]="spectrum-roms/128-1.rom"; + filenames[2]=NULL; + retval=load_a_rom(filenames); + if (retval) { + printf("Can't load file %s\n",retval); + exit(1); + } + break; + case 2: + filenames[0]="spectrum-roms/plus2-0.rom"; + filenames[1]="spectrum-roms/plus2-1.rom"; + filenames[2]=NULL; + retval=load_a_rom(filenames); + if (retval) { + printf("Can't load file %s\n",retval); + exit(1); + } + break; + case 3: + // first, try last version of PLUS3 roms + + filenames[0]="spectrum-roms/plus3-41-0.rom"; + filenames[1]="spectrum-roms/plus3-41-1.rom"; + filenames[2]="spectrum-roms/plus3-41-2.rom"; + filenames[3]="spectrum-roms/plus3-41-3.rom"; + filenames[4]=NULL; + retval=load_a_rom(filenames); + if (retval) { + printf("Can't load the Spectrum +3 ROM version 4.1. Trying with version 4.0\n"); + filenames[0]="spectrum-roms/plus3-40-0.rom"; + filenames[1]="spectrum-roms/plus3-40-1.rom"; + filenames[2]="spectrum-roms/plus3-40-2.rom"; + filenames[3]="spectrum-roms/plus3-40-3.rom"; + filenames[4]=NULL; + retval=load_a_rom(filenames); + if (retval) { + printf("Can't load the Spectrum +3 ROM version 4.0. Trying with legacy filenames\n"); + filenames[0]="spectrum-roms/plus3-0.rom"; + filenames[1]="spectrum-roms/plus3-1.rom"; + filenames[2]="spectrum-roms/plus3-2.rom"; + filenames[3]="spectrum-roms/plus3-3.rom"; + filenames[4]=NULL; + retval=load_a_rom(filenames); + if (retval) { + printf("Can't load file %s\n",retval); + exit(1); + } + } + } + break; + case 4: + filenames[0]="spectrum-roms/128-spanish-0.rom"; + filenames[1]="spectrum-roms/128-spanish-1.rom"; + filenames[2]=NULL; + retval=load_a_rom(filenames); + if (retval) { + printf("Can't load file %s\n",retval); + exit(1); + } + break; + } + + fichero=myfopen("spectrum-roms/if1-2.rom","r"); // load Interface1 ROM + if(fichero==NULL) { + // try legacy name + fichero=myfopen("spectrum-roms/if1-v2.rom","r"); + if(fichero==NULL) { + printf("Can't open Interface1 ROM file\n"); + exit(1); + } + } + size=fread(ordenador.shadowrom,8192,1,fichero); + fclose(fichero); +} +void init_sdl() +{ +int retorno, bucle; + +//if (sound_type!=3) + retorno=SDL_Init(SDL_INIT_VIDEO); + /*else + retorno=SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);*/ + if(retorno!=0) { + printf("Can't initialize SDL library. Exiting\n"); + exit(1); + } + + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK)) { + ordenador.use_js=0; + printf("Can't initialize JoyStick subsystem\n"); + } else { + printf("JoyStick subsystem initialized\n"); + ordenador.use_js=1; + if(SDL_NumJoysticks()>0){ + // Open joystick + ordenador.joystick_number = SDL_NumJoysticks(); + if (ordenador.joystick_number>2) ordenador.joystick_number = 2; //Open max 2 joysticks + printf("Try to open %d joysticks \n", ordenador.joystick_number); + for (bucle=0;bucleformat->BytesPerPixel; + printf("Bytes per pixel: %d\n",ordenador.bpp); + + if(SDL_MUSTLOCK(screen)) { + ordenador.mustlock=1; + SDL_LockSurface(screen); + } else + ordenador.mustlock=0; + + printf("Locking screen: %d\n", ordenador.mustlock); + + + printf("Return screen init\n"); + + FULL_DISPLAY_X = resx; + FULL_DISPLAY_Y = resy; + RATIO = 640/FULL_DISPLAY_X; +} + +void init_sound() +{ +int bucle, bucle2,ret2; +// sound initialization + + if (sound_type==SOUND_AUTOMATIC) { + ret2=sound_init(1); // check all sound systems + } else { + ret2=sound_init(0); // try with the one specified in command line + } + if(ret2==0) { + sound_aborted=0; + } else { // if fails, run without sound + sound_type=SOUND_NO; + sound_init(0); + sound_aborted=1; + } + printf("Init sound\n"); + if(ordenador.format) + ordenador.increment=2*ordenador.channels; + else + ordenador.increment=ordenador.channels; + + for(bucle2=0;bucle2mode128k,10); + fprintf(fconfig,"issue=%c%c",48+object->issue,10); + fprintf(fconfig,"ntsc=%c%c",48+object->videosystem,10); + fprintf(fconfig,"joystick1=%c%c",48+object->joystick[0],10); + fprintf(fconfig,"joystick2=%c%c",48+object->joystick[1],10); + fprintf(fconfig,"ay_sound=%c%c",48+object->ay_emul,10); + fprintf(fconfig,"interface1=%c%c",48+object->mdr_active,10); + fprintf(fconfig,"doublescan=%c%c",48+object->dblscan,10); + fprintf(fconfig,"framerate=%c%c",48+jump_frames,10); + fprintf(fconfig,"screen=%c%c",48+object->zaurus_mini,10); + fprintf(fconfig,"text=%c%c",48+object->text_mini,10); + fprintf(fconfig,"precision=%c%c",48+object->precision,10); + fprintf(fconfig,"volume=%c%c",65+(object->volume),10); + fprintf(fconfig,"bw=%c%c",48+object->bw,10); + fprintf(fconfig,"tap_fast=%c%c",48+object->tape_fast_load,10); + fprintf(fconfig,"joypad1=%c%c",48+object->joypad_as_joystick[0],10); + fprintf(fconfig,"joypad2=%c%c",48+object->joypad_as_joystick[1],10); + fprintf(fconfig,"rumble1=%c%c",48+object->rumble[0],10); + fprintf(fconfig,"rumble2=%c%c",48+object->rumble[1],10); + fprintf(fconfig,"port=%c%c",48+object->port,10); + fprintf(fconfig,"autoconf=%c%c",48+object->autoconf,10); + + + for (joy_n=0; joy_n<2; joy_n++) + for (key=0; key<22; key++) + fprintf(fconfig,"joybutton_%c_%c=%.3d%c",joy_n+48,key+97, object->joybuttonkey[joy_n][key],10); + + fclose(fconfig); + return 0; + +} + +int save_config_game(struct computer *object, char *filename, int overwrite) { + + unsigned char key, joy_n; + FILE *fconfig; + + fconfig=fopen(filename,"r"); + if((fconfig!=NULL)&&(!overwrite)) { + fclose(fconfig); + return -1; // file already exists + } + + fconfig = fopen(filename,"wb"); + if (fconfig==NULL) { + return -2; // can't create file + } + + fprintf(fconfig,"joystick1=%c%c",48+object->joystick[0],10); + fprintf(fconfig,"joystick2=%c%c",48+object->joystick[1],10); + fprintf(fconfig,"ay_sound=%c%c",48+object->ay_emul,10); + fprintf(fconfig,"joypad1=%c%c",48+object->joypad_as_joystick[0],10); + fprintf(fconfig,"joypad2=%c%c",48+object->joypad_as_joystick[1],10); + fprintf(fconfig,"rumble1=%c%c",48+object->rumble[0],10); + fprintf(fconfig,"rumble2=%c%c",48+object->rumble[1],10); + + for (joy_n=0; joy_n<2; joy_n++) + for (key=0; key<22; key++) + fprintf(fconfig,"joybutton_%c_%c=%.3d%c",joy_n+48,key+97, object->joybuttonkey[joy_n][key],10); + + fclose(fconfig); + return 0; + +} + +void load_config_smb(struct computer *object) { + + char line[1024],carac,done; + int pos; + FILE *fconfig; + unsigned char smb_enable=0; + + fconfig = fopen("/fbzx-wii/fbzx.smb","r"); + if (fconfig==NULL) { + return; + } + + done=1; + pos=0; + line[0]=0; + while(!feof(fconfig)) { + if (done) { + line[0]=0; + pos=0; + done=0; + } + if (0!=fread(&carac,1,1,fconfig)) { + if ((carac!=13)&&(carac!=10)) { + line[pos]=carac; + if (pos<1023) { + pos++; + } + continue; + } + } + done=1; + line[pos]=0; + if (line[0]=='#') { // comment + continue; + } + if (!strncmp(line,"smb_enable=",11)) { + smb_enable=line[11]-'0'; + continue; + } + if (!strncmp(line,"user=",5)) { + if (line[5]) + strcpy (object->SmbUser,line+5); + continue; + } + if (!strncmp(line,"password=",9)) { + if (line[9]) + strcpy (object->SmbPwd,line+9); + continue; + } + if (!strncmp(line,"share_name=",11)) { + if (line[11]) + strcpy (object->SmbShare,line+11); + continue; + } + + if (!strncmp(line,"smb_ip=",7)) { + if (line[7]) + strcpy (object->SmbIp,line+7); + continue; + } + + if (smb_enable<2) { + object->smb_enable=smb_enable;} + } + + +fclose(fconfig); +} + +int load_config(struct computer *object, char *filename) { + + char config_path[1024]; + char line[1024],carac,done; + int pos, key_sdl=0; + FILE *fconfig; + unsigned char volume=255,mode128k=255,issue=255,ntsc=255, joystick1=255,joystick2=255,ay_emul=255,mdr_active=255, + dblscan=255,framerate =255, screen =255, text=255, precision=255, bw=255, tap_fast=255, + joypad1=255, joypad2=255, rumble1=255, rumble2=255, joy_n=255, key_n=255, port=255, autoconf=255; + + if (filename) strcpy(config_path,filename); + else return -2; + + fconfig = fopen(config_path,"rb"); + if (fconfig==NULL) { + return -1; + } + + done=1; + pos=0; + line[0]=0; + while(!feof(fconfig)) { + if (done) { + line[0]=0; + pos=0; + done=0; + } + if (0!=fread(&carac,1,1,fconfig)) { + if ((carac!=13)&&(carac!=10)) { + line[pos]=carac; + if (pos<1023) { + pos++; + } + continue; + } + } + done=1; + line[pos]=0; + if (line[0]=='#') { // comment + continue; + } + if (!strncmp(line,"mode=",5)) { + printf("Cambio a modo %c\n",line[5]); + mode128k=line[5]-'0'; + continue; + } + if (!strncmp(line,"issue=",6)) { + issue=line[6]-'0'; + continue; + } + if (!strncmp(line,"ntsc=",5)) { + ntsc=line[5]-'0'; + continue; + } + if (!strncmp(line,"joystick1=",10)) { + joystick1=line[10]-'0'; + continue; + } + if (!strncmp(line,"joystick2=",10)) { + joystick2=line[10]-'0'; + continue; + } + if (!strncmp(line,"ay_sound=",9)) { + ay_emul=line[9]-'0'; + continue; + } + if (!strncmp(line,"interface1=",11)) { + mdr_active=line[11]-'0'; + continue; + } + if (!strncmp(line,"screen=",7)) { + screen=line[7]-'0'; + continue; + } + if (!strncmp(line,"text=",5)) { + text=line[5]-'0'; + continue; + } + if (!strncmp(line,"doublescan=",11)) { + dblscan=line[11]-'0'; + continue; + } + if (!strncmp(line,"framerate=",10)) { + framerate=line[10]-'0'; + continue; + } + if (!strncmp(line,"precision=",10)) { + precision=line[10]-'0'; + continue; + } + if (!strncmp(line,"volume=",7)) { + volume=(line[7]-'A'); + continue; + } + if (!strncmp(line,"bw=",3)) { + bw=(line[3]-'0'); + continue; + } + if (!strncmp(line,"tap_fast=",9)) { + tap_fast=(line[9]-'0'); + continue; + } + if (!strncmp(line,"joypad1=",8)) { + joypad1=line[8]-'0'; + continue; + } + if (!strncmp(line,"joypad2=",8)) { + joypad2=line[8]-'0'; + continue; + } + if (!strncmp(line,"rumble1=",8)) { + rumble1=line[8]-'0'; + continue; + } + if (!strncmp(line,"rumble2=",8)) { + rumble2=line[8]-'0'; + continue; + } + if (!strncmp(line,"port=",5)) { + port=line[5]-'0'; + continue; + } + if (!strncmp(line,"autoconf=",9)) { + autoconf=line[9]-'0'; + continue; + } + if (!strncmp(line,"joybutton_",10)) { + sscanf(line, "joybutton_%c_%c=%3d",&joy_n ,&key_n, &key_sdl); + if ((joy_n<50) && (joy_n>47) && (key_n<119) && (key_n>96)) + object->joybuttonkey[joy_n-48][key_n-97]=key_sdl; + continue; + } + } + + if (mode128k<5) { + object->mode128k=mode128k; + } + if (issue<4) { + object->issue=issue; + } + if (issue<2) { + object->videosystem=ntsc; + } + if (joystick1<4) { + object->joystick[0]=joystick1; + } + if (joystick2<4) { + object->joystick[1]=joystick2; + } + if (ay_emul<2) { + object->ay_emul=ay_emul; + } + if (mdr_active<2) { + object->mdr_active=mdr_active; + } + if (dblscan<2) { + object->dblscan=dblscan; + } + if (framerate<6) { + jump_frames=framerate; + } + if (screen<4) { + object->zaurus_mini=screen; + } + if (text<2) { + object->text_mini=text; + } + if (precision<2) { + object->precision=precision; + } + if (bw<2) { + object->bw=bw; + } + if (volume<17) { + object->volume=volume; + set_volume(volume); + } + if (tap_fast<2) { + object->tape_fast_load=tap_fast; + } + if (joypad1<2) { + object->joypad_as_joystick[0]=joypad1; + } + if (joypad2<2) { + object->joypad_as_joystick[1]=joypad2; + } + if (rumble1<2) { + object->rumble[0]=rumble1; + } + if (rumble2<2) { + object->rumble[1]=rumble2; + } + if (port<3) { + object->port=port; + } + if (autoconf<2) { + object->autoconf=autoconf; + } + + fclose(fconfig); + return 0; +} + +int main(int argc,char *argv[]) { + + int bucle,tstados,tstados_screen, argumento,fullscreen,dblbuffer,hwsurface,length; + char gamefile[4096],config_path[1024] ; + + word PC=0; + + + // by default, try all sound modes + sound_type=SOUND_AUTOMATIC; + gamefile[0]=0; + ordenador.zaurus_mini=0; + ordenador.text_mini=0; + ordenador.ulaplus=0; + ordenador.ulaplus_reg=0; + fullscreen=0; + dblbuffer=0; + hwsurface=0; + + argumento=0; + jump_frames=0; + curr_frames=0; + ordenador.dblscan=1; + ordenador.bw=0; + + #ifdef DEBUG + fatInitDefault(); + fdebug = fopen("/fbzx-wii/logfile.txt","w"); + #endif + + #ifdef GEKKO + dblbuffer=1; + hwsurface=1; + setenv("HOME", "/fbzx-wii", 1); + + //initialize libfat library + if (!fatInitDefault()) + { + printf("Couldn't initialize SD fat subsytem\n"); + + exit(0); + } + else + printf("SD FAT subsytem initialized\n"); + + #endif + + + computer_init(); + printf("Computer init\n"); + + printf("Modo: %d\n",ordenador.mode128k); + + printf("Set volume\n"); + set_volume(16); + + // load current config + strcpy(config_path,getenv("HOME")); + length=strlen(config_path); + if ((length>0)&&(config_path[length-1]!='/')) + strcat(config_path,"/"); + strcat(config_path,"fbzx.conf"); + + load_config(&ordenador, config_path); + + printf("Modo: %d\n",ordenador.mode128k); + while(argumentopixels; + ordenador.screen_width=ordenador.screen->w; + + //Init SDL Menu + + font_init(); + menu_init(ordenador.screen); + + //Load the splash screen + if (ordenador.zaurus_mini==0) if (load_zxspectrum_picture()) SDL_FreeSurface (image); + + #ifdef GEKKO + usbismount = InitUSB(); + + load_config_smb(&ordenador); + + if (ordenador.smb_enable) networkisinit = InitNetwork(); + + if (networkisinit && ordenador.smb_enable) ConnectShare(); + + #endif + + // assign initial values for PATH variables + + strcpy(path_snaps,getenv("HOME")); + length=strlen(path_snaps); + if ((length>0)&&(path_snaps[length-1]!='/')) + strcat(path_snaps,"/"); + strcpy(path_taps,path_snaps); + strcpy(path_mdrs,path_snaps); + strcpy(path_scr,path_snaps); + strcpy(path_confs,path_snaps); + strcat(path_snaps,"snapshots"); + strcat(path_taps,"tapes"); + strcat(path_mdrs,"microdrives"); + strcat(path_scr,"scr"); + strcat(path_confs,"configurations"); + + #ifdef GEKKO + if ((ordenador.port==1)&&usbismount) { + strcpy(path_snaps,"usb:/"); + strcpy(path_taps,"usb:/"); + } + if ((ordenador.port==2)&&smbismount) { + strcpy(path_snaps,"smb:/"); + strcpy(path_taps,"smb:/"); + } + #endif + + ordenador.current_tap[0]=0; + + // assign random values to the memory before start execution + + printf("Reset memory\n"); + printf("Modo: %d\n",ordenador.mode128k); + for(bucle=0;bucle<196608;bucle++) + ordenador.memoria[bucle]=(unsigned char) rand(); + + printf("Memory resetted\n"); + ordenador.tap_file=NULL; + printf("Modo: %d\n",ordenador.mode128k); + + // we filter all the events, except keyboard events + + SDL_EventState(SDL_ACTIVEEVENT,SDL_IGNORE); + SDL_EventState(SDL_MOUSEMOTION,SDL_IGNORE); + SDL_EventState(SDL_MOUSEBUTTONDOWN,SDL_IGNORE); + SDL_EventState(SDL_MOUSEBUTTONUP,SDL_IGNORE); + SDL_EventState(SDL_JOYAXISMOTION,SDL_IGNORE); + SDL_EventState(SDL_JOYBALLMOTION,SDL_IGNORE); + SDL_EventState(SDL_JOYHATMOTION,SDL_IGNORE); + SDL_EventState(SDL_JOYBUTTONDOWN,SDL_IGNORE); + SDL_EventState(SDL_JOYBUTTONUP,SDL_IGNORE); + SDL_EventState(SDL_QUIT,SDL_ENABLE); + SDL_EventState(SDL_SYSWMEVENT,SDL_IGNORE); + SDL_EventState(SDL_VIDEORESIZE,SDL_IGNORE); + SDL_EventState(SDL_USEREVENT,SDL_IGNORE); + + SDL_ShowCursor(SDL_DISABLE); + salir=1; + + printf("Init microdrive\n"); + microdrive_init(); + + printf("Reset computer\n"); + ResetComputer(); + + sleep(1); + + printf("Reset screen\n"); + clean_screen(); + + if (sound_aborted==1) { + strcpy(ordenador.osd_text,"Running without sound (read the FAQ)"); + ordenador.osd_time=100; + } + + printf("Modo: %d\n",ordenador.mode128k); + printf("load main game\n"); + load_main_game(gamefile); + printf("Modo: %d\n",ordenador.mode128k); + + sprintf(ordenador.osd_text,"Press Home for menu"); + ordenador.osd_time=200; + + printf("BPP: %d\n",ordenador.bpp); + while(salir) { + + do { + tstados=Z80free_ustep(&procesador); + + if (ordenador.precision) + { + tstados_screen=tstados-ordenador.r_fetch -ordenador.wr -ordenador.io; + if(tstados_screen>0) emulate_screen(tstados_screen); + ordenador.wr=0; + ordenador.r_fetch=0; + ordenador.io=0; + emulate(tstados+ordenador.contention); // execute the whole hardware emulation for that number of TSTATES + ordenador.contention=0; + } + else + if (tstados>0) { + emulate_screen(tstados); + emulate(tstados+ordenador.contention); + ordenador.contention=0; + } + + } while(procesador.Status!=Z80XX); + + PC=procesador.PC; + + /* if PC is 0x0556, a call to LD_BYTES has been made, so if + FAST_LOAD is 1, we must load the block in memory and return */ + + if((!ordenador.mdr_paged)&&(PC==0x0556) && (ordenador.tape_fast_load==1)&&(ordenador.tape_file_type==TAP_TAP)) { + if(ordenador.tap_file!=NULL) + fastload_block(ordenador.tap_file); + else { + sprintf(ordenador.osd_text,"No TAP file selected"); + ordenador.osd_time=50; + } + } + + /* if PC is 0x04C2, a call to SA_BYTES has been made, so if + we want to save to the TAP file, we do it */ + + if((!ordenador.mdr_paged)&&(PC==0x04C2)&&(ordenador.tape_write==1)&&(ordenador.tape_file_type==TAP_TAP)) { + if(ordenador.tap_file!=NULL) + save_file(ordenador.tap_file); + else { + sprintf(ordenador.osd_text,"No TAP file selected"); + ordenador.osd_time=50; + } + } + + /* if ordenador.mdr_paged is 2, we have executed the RET at 0x0700, so + we have to return to the classic ROM */ + + if(ordenador.mdr_paged==2) + ordenador.mdr_paged=0; + + /* if PC is 0x0008 or 0x1708, and we have a microdrive, we have to page + the Interface 1 ROM */ + + if(((PC==0x0008)||(PC==0x1708))&&(ordenador.mdr_active)) + ordenador.mdr_paged = 1; + + /* if PC is 0x0700 and we have a microdrive, we have to unpage + the Interface 1 ROM after the last instruction */ + + if((PC==0x0700)&&(ordenador.mdr_active)) + ordenador.mdr_paged = 2; + + if(ordenador.readkeyboard==1) { + read_keyboard (); // read the physical keyboard + ordenador.readkeyboard = 0; + } + + if(ordenador.interr==1) { + Z80free_INT(&procesador,bus_empty()); + if (ordenador.precision==0) ordenador.interr=0; + } + } + + #ifdef GEKKO + if (smbismount) CloseShare (); + DeInitUSB(); + fatUnmount(0); + #endif + + return 0; +} diff --git a/src/emulator.h b/src/emulator.h index fb3bcad..16d363b 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -1,51 +1,54 @@ -/* - * Copyright (C) 2012 Fabio Olimpieri - * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX Wii - * - * FBZX Wii is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * FBZX Wii is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "z80free/Z80free.h" -#include "computer.h" - -#ifndef emulator_h -#define emulator_h - -#define NUM_SNDBUF 2 - -extern char debug_var; - -extern SDL_Surface *screen; -extern Z80FREE procesador; -extern struct computer ordenador; -extern unsigned char *sound[NUM_SNDBUF]; -extern char path_snaps[2049]; -extern char path_taps[2049]; -extern char path_mdrs[2049]; -extern char path_scr[2049]; -extern char path_confs[2049]; -extern unsigned int colors[80]; -extern unsigned int jump_frames,curr_frames; - -void SDL_Fullscreen_Switch(void); -void load_rom(char); -void load_main_game(char *nombre); -int load_config(struct computer *object, char *filename); -int save_config(struct computer *object, char *filename); -int save_config_game(struct computer *object, char *filename, int overwrite); -FILE *myfopen(char *filename,char *mode); - -#endif +/* + * Copyright (C) 2012 Fabio Olimpieri + * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "z80free/Z80free.h" +#include "computer.h" + +#ifndef emulator_h +#define emulator_h + +#define NUM_SNDBUF 2 + +extern char debug_var; + +extern SDL_Surface *screen; +extern Z80FREE procesador; +extern struct computer ordenador; +extern unsigned char *sound[NUM_SNDBUF]; +extern char path_snaps[2049]; +extern char path_taps[2049]; +extern char path_mdrs[2049]; +extern char path_scr[2049]; +extern char path_confs[2049]; +extern unsigned int colors[80]; +extern unsigned int jump_frames,curr_frames; + +void SDL_Fullscreen_Switch(void); +void load_rom(char); +void load_main_game(char *nombre); +int load_config(struct computer *object, char *filename); +int save_config(struct computer *object, char *filename); +int save_config_game(struct computer *object, char *filename, int overwrite); +FILE *myfopen(char *filename,char *mode); +void init_sdl(); +void init_sound(); +void init_screen(int resx,int resy,int depth,int fullscreen,int dblbuffer,int hwsurface); + +#endif diff --git a/src/gui_sdl.c b/src/gui_sdl.c index a78188d..137854e 100644 --- a/src/gui_sdl.c +++ b/src/gui_sdl.c @@ -1,1135 +1,1201 @@ -/********************************************************************* - * - * Copyright (C) 2012, Fabio Olimpieri - * - * Filename: menu_sdl.c - * Author: Fabio Olimpieri - * Description: a SDL Gui - * This file is part of FBZX Wii - * - * FBZX Wii is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * FBZX Wii is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * - ********************************************************************/ - -#include -#include -#include - -#include "menu_sdl.h" -#include "emulator.h" -#include "VirtualKeyboard.h" -#include "tape.h" -//#include "menus.h" -#include "emulator.h" -#include "cargador.h" - -#define ID_BUTTON_OFFSET 0 -#define ID_AXIS_OFFSET 32 - -extern int usbismount, smbismount; - -#ifdef DEBUG -extern FILE *fdebug; -#define printf(...) fprintf(fdebug,__VA_ARGS__) -#else - #ifdef GEKKO - #define printf(...) - #endif -#endif - -extern int countdown; -void clean_screen(); - - -static const char *main_menu_messages[] = { - /*00*/ "Tape", - /*01*/ "^|Insert|Load|Play|Stop|Rewind|Create|Delete", - /*02*/ "Snapshot", - /*03*/ "^|Load|Save|Delete", - /*04*/ "#1---------------------------------------------", - /*05*/ "Wiimote configuration", - /*06*/ "^|Wiimote1|Wiimote2", - /*07*/ "Emulation settings", - /*08*/ "Confs files", - /*09*/ "Microdrive", - /*10*/ "Tools", - /*11*/ "Reset", - /*12*/ "Help", - /*13*/ "Quit", - NULL -}; - -static const char *emulation_messages[] = { - /*00*/ "Emulated machine", - /*01*/ "^|48k_2|48K_3|128k|+2|+2A/+3|128K_Sp", - /*02*/ "Volume", - /*03*/ "^|0|1|2|3|4|5|6|7|max", - /*04*/ "Tap fast speed", - /*05*/ "^|on|off", - /*06*/ "Turbo mode", - /*07*/ "^|off|speed|ultraspeed", - /*08*/ "Double scan", - /*09*/ "^|on|off", - /*10*/ "TV mode", - /*11*/ "^|Color|B&W", - /*12*/ "AY-3-8912 Emulation", - /*13*/ "^|on|off", - NULL -}; - -static const char *input_messages[] = { - /*00*/ "Joystick type", - /*01*/ "^|Cursor|Kempston|Sinclair1|Sinclair2", - /*02*/ "Bind key to Wiimote", - /*03*/ "^|A|B|1|2|-", - /*04*/ "Bind key to Nunchuk", - /*05*/ "^|Z|C", - /*06*/ "Bind key to Classic", - /*07*/ "^|a|b|x|y|L|R|Zl|Zr|-", - /*08*/ "Bind key to Pad", - /*09*/ "^|Up|Down|Left|Right", - /*10*/ "Use Joypad as Joystick", - /*11*/ "^|On|Off", - /*12*/ "Rumble", - /*13*/ "^|On|Off", - NULL, -}; - -static const char *microdrive_messages[] = { - /*00*/ "Microdrive", - /*01*/ "^|Select|Create|Delete", - /*02*/ " ", - /*03*/ "Interface I", - /*04*/ "^|on|off", - /*05*/ " ", - /*06*/ "Write protection", - /*07*/ "^|on|off", - NULL -}; - -static const char *tools_messages[] = { - /*00*/ "Show keyboard", - /*01*/ " ", - /*02*/ "Save SCR", - /*03*/ " ", - /*04*/ "Load SCR", - /*05*/ " ", - /*06*/ "Insert poke", - /*07*/ " ", - /*08*/ "Port", - /*09*/ "^|sd|usb|smb", - NULL -}; - -static const char *help_messages[] = { - /*00*/ "#2HOME enters the menu system, where arrow keys", - /*01*/ "#2and nunchuck are used to navigate up and down.", - /*02*/ "#2You can bind keyboard keys to the wiimote", - /*03*/ "#2buttons in the 'Wiimote' menu and", - /*04*/ "#2change emulation options in the Settings menu.", - /*05*/ "#2 ", - /*06*/ "#2The easiest way to play a game is to load", - /*07*/ "#2a snapshot (.z80 and .sna files).", - /*08*/ "#2You can also insert a tape file (.tap and .tzx)", - /*09*/ "#2and then load the file in the tape menu.", - /*10*/ "#2 ", - /*11*/ "#2More information is available on the wiki:", - /*12*/ "#2 http://wiibrew.org/wiki/FBZX_Wii", - /*13*/ "#2 ", - /*14*/ "OK", - NULL, -}; - -static const char *confs_messages[] = { - /*00*/ "General configurations", - /*01*/ "^|Load|Save|Delete", - /*02*/ " ", - /*03*/ "Game configurations", - /*04*/ "^|Load|Save|Delete", - /*05*/ " ", - /*06*/ "Load confs automatically", - /*07*/ "^|on|off", - NULL -}; - -void maybe_load_conf(const char *filename) -{ - const char *dir = path_confs; - char *ptr; - char db[256]; - char fb[81]; - - if (filename==NULL) return; - - if (strrchr(filename, '/')) - strncpy(fb, strrchr(filename, '/') + 1, 80); - else - strncpy(fb, filename, 80); - - //remove the extension - ptr = strrchr (fb, '.'); - if (ptr) *ptr = 0; - - snprintf(db, 255, "%s/%s.conf", dir, fb); - if (!load_config(&ordenador,db)) msgInfo("Configurations loaded",2000,NULL) ; - -} - -static void insert_tape() -{ - unsigned char char_id[11]; - int retorno, retval; - - // Maybe should go after the first control?? - if(ordenador.tap_file!=NULL) - rewind_tape(ordenador.tap_file,1); - - ordenador.tape_current_bit=0; - ordenador.tape_current_mode=TAP_TRASH; - - const char *filename = menu_select_file(path_taps, ordenador.current_tap, 0); - - if (filename==NULL) // Aborted - return; - - if (strstr(filename, "None") != NULL) - { - ordenador.current_tap[0] = '\0'; - free((void *)filename); - return; - } - - if (!(ext_matches(filename, ".tap")|ext_matches(filename, ".TAP")|ext_matches(filename, ".tzx")| - ext_matches(filename, ".TZX"))) {free((void *)filename); return;} - - - if(ordenador.tap_file!=NULL) { - fclose(ordenador.tap_file); - } - - if (!strncmp(filename,"smb:",4)) ordenador.tap_file=fopen(filename,"r"); //tinysmb does not work with r+ - else ordenador.tap_file=fopen(filename,"r+"); // read and write - - ordenador.tape_write = 0; // by default, can't record - - if(ordenador.tap_file==NULL) - retorno=-1; - else - retorno=0; - - switch(retorno) { - case 0: // all right - strcpy(ordenador.current_tap,filename); - strcpy(ordenador.last_selected_file,filename); - if (ordenador.autoconf) maybe_load_conf(filename); - break; - case -1: - msgInfo("Error: Can't load that file",3000,NULL); - ordenador.current_tap[0]=0; - free((void *)filename); - return; - break; - } - - free((void *)filename); - - retval=fread(char_id,10,1,ordenador.tap_file); // read the (maybe) TZX header - if((!strncmp(char_id,"ZXTape!",7)) && (char_id[7]==0x1A)&&(char_id[8]==1)) { - ordenador.tape_file_type = TAP_TZX; - rewind_tape(ordenador.tap_file,1); - } else { - ordenador.tape_file_type = TAP_TAP; - rewind_tape(ordenador.tap_file,1); - } -} - -static void delete_tape() -{ - const char *filename = menu_select_file(path_taps, NULL, -1); - - if (filename==NULL) // Aborted - return; - - if ((ext_matches(filename, ".tap")|ext_matches(filename, ".TAP")|ext_matches(filename, ".tzx")| - ext_matches(filename, ".TZX")) - && (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138, FULL_DISPLAY_Y /2-48))) unlink(filename); - - free((void *)filename); -} - - -static void manage_tape(int which) -{ - switch (which) - { - case 0: //Insert - insert_tape(); - break; - case 1: //Emulate load "" - ordenador.kbd_buffer_pointer=6; - countdown=8; - ordenador.keyboard_buffer[0][6]= SDLK_1; //Edit - ordenador.keyboard_buffer[1][6]= SDLK_LSHIFT; - ordenador.keyboard_buffer[0][5]= SDLK_j; //Load - ordenador.keyboard_buffer[1][5]= 0; - ordenador.keyboard_buffer[0][4]= SDLK_p; //" - ordenador.keyboard_buffer[1][4]= SDLK_LCTRL; - ordenador.keyboard_buffer[0][3]= SDLK_p; //" - ordenador.keyboard_buffer[1][3]= SDLK_LCTRL; - ordenador.keyboard_buffer[0][2]= SDLK_RETURN; // Return - ordenador.keyboard_buffer[1][2]= 0; - ordenador.keyboard_buffer[0][1]= SDLK_F6; //F6 - ordenador.keyboard_buffer[1][1]= 0; - break; - case 2: //Play - if ((ordenador.tape_fast_load == 0) || (ordenador.tape_file_type==TAP_TZX)) - ordenador.pause = 0; - break; - case 3: //Stop - if ((ordenador.tape_fast_load == 0) || (ordenador.tape_file_type==TAP_TZX)) - ordenador.pause = 1; - break; - case 4: //Rewind - ordenador.pause=1; - if(ordenador.tap_file!=NULL) { - ordenador.tape_current_mode=TAP_TRASH; - rewind_tape(ordenador.tap_file,1); - } - msgInfo("Tape rewinded",3000,NULL); - break; - case 5: //Create - // Create tape - msgInfo("Not yet implemented",3000,NULL); - break; - case 6: //Delete - delete_tape(); - break; - default: - break; - } -} - -static unsigned int get_machine_model(void) -{ - return ordenador.mode128k + (ordenador.issue==3); -} - -static void set_machine_model(int which) -{ - switch (which) - { - case 0: //48k issue2 - ordenador.issue=2; - ordenador.mode128k=0; - ordenador.ay_emul=0; - break; - case 1: //48k issue3 - ordenador.issue=3; - ordenador.mode128k=0; - ordenador.ay_emul=0; - break; - case 2: //128k - ordenador.issue=3; - ordenador.mode128k=1; - ordenador.ay_emul=1; - break; - case 3: //Amstrad +2 - ordenador.issue=3; - ordenador.mode128k=2; - ordenador.ay_emul=1; - break; - case 4: //Amstrad +2A/+3 - ordenador.issue=3; - ordenador.mode128k=3; - ordenador.ay_emul=1; - ordenador.mdr_active=0; - break; - case 5: //128K Spanish - ordenador.issue=3; - ordenador.mode128k=4; - ordenador.ay_emul=1; - break; - - } -} - -static void emulation_settings(void) -{ - unsigned int submenus[7],submenus_old[7]; - int opt, i; - unsigned char old_mode; - - memset(submenus, 0, sizeof(submenus)); - - submenus[0] = get_machine_model(); - submenus[1] = ordenador.volume/2; - submenus[2] = !ordenador.tape_fast_load; - submenus[3] = ordenador.turbo; - submenus[4] = !ordenador.dblscan; - submenus[5] = ordenador.bw; - submenus[6] = !ordenador.ay_emul; - - for (i=0; i<7; i++) submenus_old[i] = submenus[i]; - old_mode=ordenador.mode128k; - - opt = menu_select_title("Emulation settings menu", - emulation_messages, submenus); - if (opt < 0) - return; - - set_machine_model(submenus[0]); - if (old_mode!=ordenador.mode128k) ResetComputer(); else - ordenador.ay_emul = !submenus[6]; - - ordenador.volume = submenus[1]*2; //I should use set_volume() ? - ordenador.tape_fast_load = !submenus[2]; - ordenador.turbo = submenus[3]; - - curr_frames=0; - switch(ordenador.turbo) - { - case 0: //off - ordenador.tst_sample=3500000/ordenador.freq; - jump_frames=0; - break; - case 1: //speed - ordenador.tst_sample=12000000/ordenador.freq; //5,0 MHz max emulation speed for wii at full frames - jump_frames=3; - break; - case 2: //very speed - ordenador.tst_sample=20000000/ordenador.freq; - jump_frames=24; - break; - default: - break; - } - - ordenador.dblscan = !submenus[4]; - ordenador.bw = submenus[5]; - if (submenus[5]!=submenus_old[5]) computer_set_palete(); - -} - -static void setup_joystick(int joy, unsigned int sdl_key, int joy_key) -{ - int loop; - - //Cancel the previous assignement - it is not possible to assign a same sdl_key to 2 joybuttons - for (loop=0; loop<22; loop++) - if (ordenador.joybuttonkey[joy][loop] == sdl_key) ordenador.joybuttonkey[joy][loop] =0; - - ordenador.joybuttonkey[joy][joy_key] = sdl_key; - -} - -static void input_options(int joy) -{ - const unsigned int wiimote_to_sdl[] = {0, 1, 2, 3, 4}; - const unsigned int nunchuk_to_sdl[] = {7, 8}; - const unsigned int classic_to_sdl[] = {9, 10, 11, 12, 13, 14, 15, 16, 17}; - const unsigned int pad_to_sdl[] = {18, 19, 20, 21}; - int joy_key = 1; - unsigned int sdl_key; - unsigned int submenus[7]; - int opt; - - struct virtkey *virtualkey; - - memset(submenus, 0, sizeof(submenus)); - - submenus[0] = ordenador.joystick[joy]; - submenus[5] = !ordenador.joypad_as_joystick[joy]; - submenus[6] = !ordenador.rumble[joy]; - - opt = menu_select_title("Input menu", - input_messages, submenus); - if (opt < 0) - return; - - ordenador.joystick[joy] = submenus[0]; - ordenador.joypad_as_joystick[joy] = !submenus[5]; - ordenador.rumble[joy] = !submenus[6]; - - if (opt == 0 || opt == 10|| opt == 12) - return; - - virtualkey = get_key(); - if (virtualkey == NULL) - return; - sdl_key = virtualkey->sdl_code; - - if (virtualkey->sdl_code==1) //"Done" selected - {if (virtualkey->caps_on) sdl_key = 304; //Caps Shit - else if (virtualkey->sym_on) sdl_key = 306; //Sym Shit - else return; } - - switch(opt) - { - case 2: // wiimote - joy_key = wiimote_to_sdl[submenus[1]]; break; - case 4: // nunchuk - joy_key = nunchuk_to_sdl[submenus[2]]; break; - case 6: // classic - joy_key = classic_to_sdl[submenus[3]]; break; - case 8: // pad - joy_key = pad_to_sdl[submenus[4]]; break; - default: - break; - } - - setup_joystick(joy, sdl_key, joy_key); - -} - -static void select_mdr() -{ - int retorno, retval; - - const char *filename = menu_select_file(path_mdrs, ordenador.mdr_current_mdr, 0); - - if (filename==NULL) // Aborted - return; - - if (strstr(filename, "None") != NULL) - { - ordenador.mdr_current_mdr[0] = '\0'; - free((void *)filename); - return; - } - - if (!(ext_matches(filename, ".mdr")|ext_matches(filename, ".MDR"))) {free((void *)filename); return;} - - ordenador.mdr_file=fopen(filename,"rb"); // read - if(ordenador.mdr_file==NULL) - retorno=-1; - else { - retorno=0; - retval=fread(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // read the cartridge in memory - ordenador.mdr_modified=0; // not modified - fclose(ordenador.mdr_file); - ordenador.mdr_tapehead=0; - } - - strcpy(ordenador.mdr_current_mdr,filename); - - free((void *)filename); - - switch(retorno) { - case 0: // all right - break; - default: - ordenador.mdr_current_mdr[0]=0; - msgInfo("Error: Can't load that file",3000,NULL); - break; - } -} - -static void delete_mdr() -{ - const char *filename = menu_select_file(path_mdrs, NULL, -1); - - if (filename==NULL) // Aborted - return; - - if ((ext_matches(filename, ".mdr")|ext_matches(filename, ".MDR")) - && (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138, FULL_DISPLAY_Y /2-48))) unlink(filename); - - free((void *)filename); -} - -static void microdrive() -{ - - unsigned int submenus[3], submenus_old[3]; - int opt,retval ; - - memset(submenus, 0, sizeof(submenus)); - - submenus[1] = !ordenador.mdr_active; - submenus[2] = !ordenador.mdr_cartridge[137922]; - - submenus_old[1] = submenus[1]; - submenus_old[2] = submenus[2]; - - opt = menu_select_title("Microdrive menu", - microdrive_messages, submenus); - if (opt < 0) - return; - - ordenador.mdr_active = !submenus[1]; - - - if (submenus[1]!=submenus_old[1]) ResetComputer(); - if (submenus[2]!=submenus_old[2]) - {if(ordenador.mdr_cartridge[137922]) - ordenador.mdr_cartridge[137922]=0; - else - ordenador.mdr_cartridge[137922]=1; - ordenador.mdr_file=fopen(ordenador.mdr_current_mdr,"wb"); // create for write - if(ordenador.mdr_file!=NULL) { - retval=fwrite(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // save cartridge - fclose(ordenador.mdr_file); - ordenador.mdr_file=NULL; - ordenador.mdr_modified=0; - } - } - - if (opt==0) - switch (submenus[0]) - { - case 0: // Select microdrive - select_mdr(); - break; - case 1: // Create microdrive file - // Create microdrive file ; - msgInfo("Not yet implemented",3000,NULL); - break; - case 2: // Delete microdrive file - delete_mdr(); - break; - default: - break; - } -} -void show_keyboard_layout() { - - FILE *fichero; - int bucle1,bucle2,retval; - unsigned char *buffer,valor; - - buffer=screen->pixels; - - fichero=myfopen("fbzx/keymap.bmp","r"); - if (fichero==NULL) { - msgInfo("Keymap picture not found",3000,NULL); - return; - } - - for (bucle1=0;bucle1<344;bucle1++) - for(bucle2=0;bucle2<640;bucle2++) { - retval=fscanf(fichero,"%c",&valor); - paint_one_pixel((unsigned char *)(colors+valor),buffer); - buffer+=ordenador.bpp; - } - SDL_Flip(ordenador.screen); - menu_wait_key_press(); -} - -static void load_scr() -{ - int retorno,loop; - unsigned char value; - FILE *fichero; - unsigned char paleta_tmp[64]; - - - const char *filename = menu_select_file(path_scr, NULL, -1); - - if (filename==NULL) // Aborted - return; - - if (!(ext_matches(filename, ".scr")|ext_matches(filename, ".SCR"))) {free((void *)filename); return;} - - ordenador.osd_text[0]=0; - fichero=fopen(filename,"rb"); - retorno=0; - if (!fichero) { - retorno=-1; - } else { - for(loop=0;loop<6912;loop++) { - if (1==fread(&value,1,1,fichero)) { - *(ordenador.block1 + 0x04000 + loop) = value; - } else { - retorno=-1; - break; - } - } - if (1==fread(paleta_tmp,64,1,fichero)) { - memcpy(ordenador.ulaplus_palete,paleta_tmp,64); - ordenador.ulaplus=1; - } else { - ordenador.ulaplus=0; - } - fclose(fichero); - } - - switch(retorno) { - case 0: // all right - break; - case -1: - msgInfo("Error: Can't load that file",3000,NULL); - break; - default: - break; - } - - free((void *)filename); - -} - -static void save_scr() -{ - const char *dir = path_scr; - const char *tape = ordenador.last_selected_file; - char *ptr; - FILE *fichero; - char db[256]; - char fb[81]; - int retorno,retval; - - // Name (for saves) - TO CHECK - if (tape && strrchr(tape, '/')) - strncpy(fb, strrchr(tape, '/') + 1, 80); - else - strcpy(fb, "unknown"); - - //remove the extension - ptr = strrchr (fb, '.'); - if (ptr) *ptr = 0; - - // Save SCR file - snprintf(db, 255, "%s/%s.scr", dir, fb); - - fichero=fopen(db,"r"); - - if(fichero!=NULL) - { - fclose(fichero); - if (!msgYesNo("Overwrite the exiting file?", 0, FULL_DISPLAY_X /2-160, FULL_DISPLAY_Y /2-48)) - return; // file already exists - } - - fichero=fopen(db,"wb"); // create for write - - if(fichero==NULL) - retorno=-1; - else { - retval=fwrite(ordenador.block1+0x04000,6912,1,fichero); // save screen - if (ordenador.ulaplus!=0) { - retval=fwrite(ordenador.ulaplus_palete,64,1,fichero); // save ULAPlus palete - } - fclose(fichero); - retorno=0; - } - - switch(retorno) { - case 0: - msgInfo("SCR saved",3000,NULL); - break; - case -1: - msgInfo("Can't create file",3000,NULL); - break; - default: - break; - } -} - -static void set_port(int which) -{ - int length; - - switch (which) - { - case 0: //PORT_SD - strcpy(path_snaps,getenv("HOME")); - length=strlen(path_snaps); - if ((length>0)&&(path_snaps[length-1]!='/')) - strcat(path_snaps,"/"); - strcpy(path_taps,path_snaps); - strcat(path_snaps,"snapshots"); - strcat(path_taps,"tapes"); - ordenador.port = which; - break; - case 1: //PORT_USB - if (usbismount) { - strcpy(path_snaps,"usb:/"); - strcpy(path_taps,"usb:/"); - ordenador.port = which;} - else - msgInfo("USB is not mounted",3000,NULL); - break; - case 2: //PORT_SMB - if (smbismount) { - strcpy(path_snaps,"smb:/"); - strcpy(path_taps,"smb:/"); - ordenador.port = which;} - else - msgInfo("SMB is not mounted",3000,NULL); - break; - default: - break; - } -} - -static void tools() -{ - int opt ; - int submenus[1]; - - memset(submenus, 0, sizeof(submenus)); - - submenus[0] = ordenador.port; - - opt = menu_select_title("Tools menu", - tools_messages, submenus); - if (opt < 0) - return; - - set_port(submenus[0]); - - switch(opt) - { - case 0: // Show keyboard - show_keyboard_layout(); - break; - case 2: // Save SCR - save_scr(); - break; - case 4: // Load SCR - load_scr(); - break; - case 6: // Insert poke - // Insert poke ; - msgInfo("Not yet implemented",3000,NULL); - break; - default: - break; - } -} - - -void virtual_keyboard(void) -{ - int key_code; - - virtkey_t *key =get_key(); - if (key) {key_code = key->sdl_code;} else return; - - ordenador.kbd_buffer_pointer=1; - countdown=8; - ordenador.keyboard_buffer[0][1]= key_code; - if (key->caps_on) ordenador.keyboard_buffer[1][1]= SDLK_LSHIFT; - else if (key->sym_on) ordenador.keyboard_buffer[1][1]= SDLK_LCTRL; - else ordenador.keyboard_buffer[1][1]= 0; - - printf ("Push Event: keycode %d\n", key_code); - -} - -static void save_load_snapshot(int which) -{ - const char *dir = path_snaps; - const char *tape = ordenador.last_selected_file; - char *ptr; - char db[256]; - char fb[81]; - int retorno; - - // Name (for saves) - TO CHECK - if (tape && strrchr(tape, '/')) - strncpy(fb, strrchr(tape, '/') + 1, 80); - else - strcpy(fb, "unknown"); - - //remove the extension - ptr = strrchr (fb, '.'); - if (ptr) *ptr = 0; - - switch(which) - { - case 2: - case 0: // Load or delete file - { - const char *filename = menu_select_file(dir, NULL,-1); - - if (!filename) - return; - - if (ext_matches(filename, ".z80")|ext_matches(filename, ".Z80")| - ext_matches(filename, ".sna")|ext_matches(filename, ".SNA")) - { - if (which == 0) // Load snapshot file - { - retorno=load_z80((char *)filename); - - switch(retorno) { - case 0: // all right - strcpy(ordenador.last_selected_file,filename); - if (ordenador.autoconf) maybe_load_conf(filename); - break; - case -1: - msgInfo("Error: Can't load that file",3000,NULL); - break; - case -2: - case -3: - msgInfo("Error: unsuported snap file",3000,NULL); - break; - } - } - else // Delete snashot file - if (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138, FULL_DISPLAY_Y /2-48)) unlink(filename); - } - free((void*)filename); - } break; - case 1: // Save snapshot file - snprintf(db, 255, "%s/%s.z80", dir, fb); - retorno=save_z80(db,0); - switch(retorno) - { - case 0: //OK - msgInfo("Snapshot saved",3000,NULL); - break; - case -1: - if (msgYesNo("Overwrite the exiting file?", 0, FULL_DISPLAY_X /2-160, FULL_DISPLAY_Y /2-48)) - { - save_z80(db,1); //force overwrite - msgInfo("Snapshot saved",3000,NULL); - } - break; - case -2: - msgInfo("Can't create file",3000,NULL); - break; - } - break; - default: - break; - } -} - -static void save_load_game_configurations(int which) -{ - const char *dir = path_confs; - const char *tape = ordenador.last_selected_file; - char *ptr; - char db[256]; - char fb[81]; - int retorno; - - switch(which) - { - case 2: - case 0: // Load or delete file - { - const char *filename = menu_select_file(dir, NULL,-1); - - if (!filename) - return; - - if (ext_matches(filename, ".conf")|ext_matches(filename, ".CONF")) - { - if (which == 0) // Load config file - { - if (!load_config(&ordenador,db)) msgInfo("Game confs loaded",3000,NULL); - break; - } - else // Delete config file - if (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138, FULL_DISPLAY_Y /2-48)) unlink(filename); - } - free((void*)filename); - } break; - case 1: // Save configuration file - - // Name (for game config saves) - TO CHECK - if (tape && strrchr(tape, '/')) - strncpy(fb, strrchr(tape, '/') + 1, 80); - else - { - msgInfo("No file selected",3000,NULL); - return; - } - - //remove the extension - ptr = strrchr (fb, '.'); - - if (ptr) *ptr = 0; - - snprintf(db, 255, "%s/%s.conf", dir, fb); - - retorno=save_config_game(&ordenador,db,0); - - switch(retorno) - { - case 0: //OK - msgInfo("Game confs saved",3000,NULL); - break; - case -1: - if (msgYesNo("Overwrite the exiting file?", 0, FULL_DISPLAY_X /2-160, FULL_DISPLAY_Y /2-48)) - { - save_config_game(&ordenador,db,1); //force overwrite - msgInfo("Game confs saved",3000,NULL); - } - break; - case -2: - msgInfo("Can't create file",3000,NULL); - break; - } - break; - default: - break; - } -} -static void save_load_general_configurations(int which) -{ - - int retorno; - unsigned char old_bw,old_mode; - char config_path[1024]; - int length; - FILE *fconfig; - - strcpy(config_path,getenv("HOME")); - length=strlen(config_path); - if ((length>0)&&(config_path[length-1]!='/')) - strcat(config_path,"/"); - strcat(config_path,"fbzx.conf"); - - switch(which) - { - case 2: - case 0: // Load or delete file - { - fconfig = fopen(config_path,"r"); - if (fconfig==NULL) - { - msgInfo("Can not access the file",3000,NULL); - return; - } - else fclose(fconfig); - - if (which == 0) // Load config file - { - old_bw = ordenador.bw; - old_mode= ordenador.mode128k; - if (!load_config(&ordenador,config_path)) msgInfo("General confs loaded",3000,NULL); - if (old_bw!=ordenador.bw) computer_set_palete(); - if (old_mode != ordenador.mode128k) ResetComputer(); - break; - } - else // Delete config file - if (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138, FULL_DISPLAY_Y /2-48)) unlink(config_path); - - } break; - case 1: // Save configuration file - retorno=save_config(&ordenador,config_path); - - switch(retorno) - { - case 0: //OK - msgInfo("General confs saved",3000,NULL); - break; - case -2: - msgInfo("Can't create file",3000,NULL); - break; - } - break; - default: - break; - } -} -static void manage_configurations() -{ - int opt ; - int submenus[3]; - - memset(submenus, 0, sizeof(submenus)); - - submenus[2]=!ordenador.autoconf; - - opt = menu_select_title("Configurations file menu", - confs_messages, submenus); - if (opt < 0) - return; - - ordenador.autoconf=!submenus[2]; - - switch(opt) - { - case 0: // Save, load and delete general configurations - save_load_general_configurations(submenus[0]); - break; - case 3: // Save, load and delete game configurations - save_load_game_configurations(submenus[1]); - break; - default: - break; - } -} - - -static void help(void) -{ - menu_select_title("FBZX-WII help", - help_messages, NULL); -} - -void main_menu() -{ - int submenus[3]; - int opt; - - memset(submenus, 0, sizeof(submenus)); - - do - { - opt = menu_select_title("Main menu", main_menu_messages, submenus); - if (opt < 0) - break; - - switch(opt) - { - case 0: - manage_tape(submenus[0]); - break; - case 2: - save_load_snapshot(submenus[1]); - break; - case 5: - input_options(submenus[2]); - break; - case 7: - emulation_settings(); - break; - case 8: - manage_configurations(); - break; - case 9: - microdrive(); - break; - case 10: - tools(); - break; - case 11: - ResetComputer (); - ordenador.pause = 1; - if (ordenador.tap_file != NULL) { - ordenador.tape_current_mode = TAP_TRASH; - rewind_tape (ordenador.tap_file,1); - } - break; - case 12: - help(); - break; - case 13: - if (msgYesNo("Are you sure to quit?", 0, FULL_DISPLAY_X /2-138, FULL_DISPLAY_Y /2-48)) - {salir = 0;} - break; - default: - break; - } - } while (opt == 5 || opt == 7 || opt == 9 || opt == 12); - - clean_screen(); - -} +/********************************************************************* + * + * Copyright (C) 2012, Fabio Olimpieri + * + * Filename: menu_sdl.c + * Author: Fabio Olimpieri + * Description: a SDL Gui + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + ********************************************************************/ + +#include +#include +#include + +#include "menu_sdl.h" +#include "emulator.h" +#include "VirtualKeyboard.h" +#include "tape.h" +#include "menus.h" +#include "emulator.h" +#include "cargador.h" + +#define ID_BUTTON_OFFSET 0 +#define ID_AXIS_OFFSET 32 + +extern int usbismount, smbismount; + +#ifdef DEBUG +extern FILE *fdebug; +#define printf(...) fprintf(fdebug,__VA_ARGS__) +#else + #ifdef GEKKO + #define printf(...) + #endif +#endif + +extern int countdown; +void clean_screen(); + + +static const char *main_menu_messages[] = { + /*00*/ "Tape", + /*01*/ "^|Insert|Load|Play|Stop|Rewind|Create|Delete", + /*02*/ "Snapshot", + /*03*/ "^|Load|Save|Delete", + /*04*/ "#1---------------------------------------------", + /*05*/ "Wiimote configuration", + /*06*/ "^|Wiimote1|Wiimote2", + /*07*/ "Emulation settings", + /*08*/ "Screen settings", + /*09*/ "Confs files", + /*10*/ "Microdrive", + /*11*/ "Tools", + /*12*/ "Reset", + /*13*/ "Help", + /*14*/ "Quit", + NULL +}; + +static const char *emulation_messages[] = { + /*00*/ "Emulated machine", + /*01*/ "^|48k_2|48K_3|128k|+2|+2A/+3|128K_Sp|NTSC", + /*02*/ "Volume", + /*03*/ "^|0|1|2|3|4|5|6|7|max", + /*04*/ "Frame rate", + /*05*/ "^|100%|50%|33%|25%|20%", + /*06*/ "Tap fast speed", + /*07*/ "^|on|off", + /*08*/ "Turbo mode", + /*09*/ "^|off|speed|ultraspeed", + /*10*/ "Precision", + /*11*/ "^|on|off", + /*12*/ "AY-3-8912 Emulation", + /*13*/ "^|on|off", + NULL +}; + +static const char *screen_messages[] = { + /*00*/ "Double scan", + /*01*/ "^|on|off", + /*02*/ " ", + /*03*/ "TV mode", + /*04*/ "^|Color|B&W", + /*05*/ " ", + /*06*/ "Resolution", + /*07*/ "^|640X480|320X240", + NULL +}; + +static const char *input_messages[] = { + /*00*/ "Joystick type", + /*01*/ "^|Cursor|Kempston|Sinclair1|Sinclair2", + /*02*/ "Bind key to Wiimote", + /*03*/ "^|A|B|1|2|-", + /*04*/ "Bind key to Nunchuk", + /*05*/ "^|Z|C", + /*06*/ "Bind key to Classic", + /*07*/ "^|a|b|x|y|L|R|Zl|Zr|-", + /*08*/ "Bind key to Pad", + /*09*/ "^|Up|Down|Left|Right", + /*10*/ "Use Joypad as Joystick", + /*11*/ "^|On|Off", + /*12*/ "Rumble", + /*13*/ "^|On|Off", + NULL, +}; + +static const char *microdrive_messages[] = { + /*00*/ "Microdrive", + /*01*/ "^|Select|Create|Delete", + /*02*/ " ", + /*03*/ "Interface I", + /*04*/ "^|on|off", + /*05*/ " ", + /*06*/ "Write protection", + /*07*/ "^|on|off", + NULL +}; + +static const char *tools_messages[] = { + /*00*/ "Show keyboard", + /*01*/ " ", + /*02*/ "Save SCR", + /*03*/ " ", + /*04*/ "Load SCR", + /*05*/ " ", + /*06*/ "Insert poke", + /*07*/ " ", + /*08*/ "Port", + /*09*/ "^|sd|usb|smb", + NULL +}; + +static const char *help_messages[] = { + /*00*/ "#2HOME enters the menu system, where arrow keys", + /*01*/ "#2and nunchuck are used to navigate up and down.", + /*02*/ "#2You can bind keyboard keys to the wiimote", + /*03*/ "#2buttons in the 'Wiimote' menu and", + /*04*/ "#2change emulation options in the Settings menu.", + /*05*/ "#2 ", + /*06*/ "#2The easiest way to play a game is to load", + /*07*/ "#2a snapshot (.z80 and .sna files).", + /*08*/ "#2You can also insert a tape file (.tap and .tzx)", + /*09*/ "#2and then load the file in the tape menu.", + /*10*/ "#2 ", + /*11*/ "#2More information is available on the wiki:", + /*12*/ "#2 http://wiibrew.org/wiki/FBZX_Wii", + /*13*/ "#2 ", + /*14*/ "OK", + NULL, +}; + +static const char *confs_messages[] = { + /*00*/ "General configurations", + /*01*/ "^|Load|Save|Delete", + /*02*/ " ", + /*03*/ "Game configurations", + /*04*/ "^|Load|Save|Delete", + /*05*/ " ", + /*06*/ "Load confs automatically", + /*07*/ "^|on|off", + NULL +}; + +void maybe_load_conf(const char *filename) +{ + const char *dir = path_confs; + char *ptr; + char db[256]; + char fb[81]; + + if (filename==NULL) return; + + if (strrchr(filename, '/')) + strncpy(fb, strrchr(filename, '/') + 1, 80); + else + strncpy(fb, filename, 80); + + //remove the extension + ptr = strrchr (fb, '.'); + if (ptr) *ptr = 0; + + snprintf(db, 255, "%s/%s.conf", dir, fb); + if (!load_config(&ordenador,db)) msgInfo("Configurations loaded",2000,NULL) ; + +} + +static void insert_tape() +{ + unsigned char char_id[11]; + int retorno, retval; + + // Maybe should go after the first control?? + if(ordenador.tap_file!=NULL) + rewind_tape(ordenador.tap_file,1); + + ordenador.tape_current_bit=0; + ordenador.tape_current_mode=TAP_TRASH; + + const char *filename = menu_select_file(path_taps, ordenador.current_tap, 0); + + if (filename==NULL) // Aborted + return; + + if (strstr(filename, "None") != NULL) + { + ordenador.current_tap[0] = '\0'; + free((void *)filename); + return; + } + + if (!(ext_matches(filename, ".tap")|ext_matches(filename, ".TAP")|ext_matches(filename, ".tzx")| + ext_matches(filename, ".TZX"))) {free((void *)filename); return;} + + + if(ordenador.tap_file!=NULL) { + fclose(ordenador.tap_file); + } + + if (!strncmp(filename,"smb:",4)) ordenador.tap_file=fopen(filename,"r"); //tinysmb does not work with r+ + else ordenador.tap_file=fopen(filename,"r+"); // read and write + + ordenador.tape_write = 0; // by default, can't record + + if(ordenador.tap_file==NULL) + retorno=-1; + else + retorno=0; + + switch(retorno) { + case 0: // all right + strcpy(ordenador.current_tap,filename); + strcpy(ordenador.last_selected_file,filename); + if (ordenador.autoconf) maybe_load_conf(filename); + break; + case -1: + msgInfo("Error: Can't load that file",3000,NULL); + ordenador.current_tap[0]=0; + free((void *)filename); + return; + break; + } + + free((void *)filename); + + retval=fread(char_id,10,1,ordenador.tap_file); // read the (maybe) TZX header + if((!strncmp(char_id,"ZXTape!",7)) && (char_id[7]==0x1A)&&(char_id[8]==1)) { + ordenador.tape_file_type = TAP_TZX; + rewind_tape(ordenador.tap_file,1); + } else { + ordenador.tape_file_type = TAP_TAP; + rewind_tape(ordenador.tap_file,1); + } +} + +static void delete_tape() +{ + const char *filename = menu_select_file(path_taps, NULL, -1); + + if (filename==NULL) // Aborted + return; + + if ((ext_matches(filename, ".tap")|ext_matches(filename, ".TAP")|ext_matches(filename, ".tzx")| + ext_matches(filename, ".TZX")) + && (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138/RATIO, FULL_DISPLAY_Y /2-48/RATIO))) unlink(filename); + + free((void *)filename); +} + + +static void manage_tape(int which) +{ + switch (which) + { + case 0: //Insert + insert_tape(); + break; + case 1: //Emulate load "" + ordenador.kbd_buffer_pointer=6; + countdown=8; + ordenador.keyboard_buffer[0][6]= SDLK_1; //Edit + ordenador.keyboard_buffer[1][6]= SDLK_LSHIFT; + ordenador.keyboard_buffer[0][5]= SDLK_j; //Load + ordenador.keyboard_buffer[1][5]= 0; + ordenador.keyboard_buffer[0][4]= SDLK_p; //" + ordenador.keyboard_buffer[1][4]= SDLK_LCTRL; + ordenador.keyboard_buffer[0][3]= SDLK_p; //" + ordenador.keyboard_buffer[1][3]= SDLK_LCTRL; + ordenador.keyboard_buffer[0][2]= SDLK_RETURN; // Return + ordenador.keyboard_buffer[1][2]= 0; + ordenador.keyboard_buffer[0][1]= SDLK_F6; //F6 + ordenador.keyboard_buffer[1][1]= 0; + break; + case 2: //Play + if ((ordenador.tape_fast_load == 0) || (ordenador.tape_file_type==TAP_TZX)) + ordenador.pause = 0; + break; + case 3: //Stop + if ((ordenador.tape_fast_load == 0) || (ordenador.tape_file_type==TAP_TZX)) + ordenador.pause = 1; + break; + case 4: //Rewind + ordenador.pause=1; + if(ordenador.tap_file!=NULL) { + ordenador.tape_current_mode=TAP_TRASH; + rewind_tape(ordenador.tap_file,1); + } + msgInfo("Tape rewinded",3000,NULL); + break; + case 5: //Create + // Create tape + msgInfo("Not yet implemented",3000,NULL); + break; + case 6: //Delete + delete_tape(); + break; + default: + break; + } +} + +static unsigned int get_machine_model(void) +{ + if (ordenador.videosystem == 0) + return (ordenador.mode128k + (ordenador.issue==3)); + else return (6); +} + +static void set_machine_model(int which) +{ + switch (which) + { + case 0: //48k issue2 + ordenador.issue=2; + ordenador.mode128k=0; + ordenador.ay_emul=0; + ordenador.videosystem =0; + break; + case 1: //48k issue3 + ordenador.issue=3; + ordenador.mode128k=0; + ordenador.ay_emul=0; + ordenador.videosystem =0; + break; + case 2: //128k + ordenador.issue=3; + ordenador.mode128k=1; + ordenador.ay_emul=1; + ordenador.videosystem =0; + break; + case 3: //Amstrad +2 + ordenador.issue=3; + ordenador.mode128k=2; + ordenador.ay_emul=1; + ordenador.videosystem =0; + break; + case 4: //Amstrad +2A/+3 + ordenador.issue=3; + ordenador.mode128k=3; + ordenador.ay_emul=1; + ordenador.mdr_active=0; + ordenador.videosystem =0; + break; + case 5: //128K Spanish + ordenador.issue=3; + ordenador.mode128k=4; + ordenador.ay_emul=1; + ordenador.videosystem =0; + break; + case 6: //48k ntsc + ordenador.issue=3; + ordenador.mode128k=0; + ordenador.ay_emul=0; + ordenador.videosystem =1; + break; + } +} + +static void emulation_settings(void) +{ + unsigned int submenus[7],submenus_old[7]; + int opt, i; + unsigned char old_mode, old_videosystem; + + memset(submenus, 0, sizeof(submenus)); + + submenus[0] = get_machine_model(); + submenus[1] = ordenador.volume/2; + submenus[2] = jump_frames; + submenus[3] = !ordenador.tape_fast_load; + submenus[4] = ordenador.turbo; + submenus[5] = !ordenador.precision; + submenus[6] = !ordenador.ay_emul; + + for (i=0; i<7; i++) submenus_old[i] = submenus[i]; + old_mode=ordenador.mode128k; + old_videosystem = ordenador.videosystem; + + opt = menu_select_title("Emulation settings menu", + emulation_messages, submenus); + if (opt < 0) + return; + + set_machine_model(submenus[0]); + if ((old_mode!=ordenador.mode128k)||(old_videosystem!=ordenador.videosystem)) ResetComputer(); else + ordenador.ay_emul = !submenus[6]; + + ordenador.volume = submenus[1]*2; //I should use set_volume() ? + jump_frames = submenus[2]; + ordenador.tape_fast_load = !submenus[3]; + ordenador.turbo = submenus[4]; + + curr_frames=0; + if (submenus[4] != submenus_old[4]) + { + switch(ordenador.turbo) + { + case 0: //off + update_frequency(0); //set machine frequency + jump_frames=0; + break; + case 1: //speed + update_frequency(10000000); + jump_frames=4; + ordenador.precision =0; + break; + case 2: //ultra speed + update_frequency(15000000); + jump_frames=24; + ordenador.precision =0; + break; + default: + break; + } + } + + if (ordenador.turbo==0) ordenador.precision = !submenus[5]; +} + +static void save_load_general_configurations(int); + +static void screen_settings(void) +{ + unsigned int submenus[3],submenus_old[3]; + int opt, i; + + memset(submenus, 0, sizeof(submenus)); + + submenus[0] = !ordenador.dblscan; + submenus[1] = ordenador.bw; + submenus[2] = ordenador.zaurus_mini?1:0; + + for (i=0; i<3; i++) submenus_old[i] = submenus[i]; + + + opt = menu_select_title("Screen settings menu", + screen_messages, submenus); + if (opt < 0) + return; + + ordenador.dblscan = !submenus[0]; + ordenador.bw = submenus[1]; + if (submenus[1]!=submenus_old[1]) computer_set_palete(); + + if (submenus[2] != submenus_old[2]) + { + if (submenus[2]==0) {ordenador.zaurus_mini = 0; ordenador.text_mini=0;} + else {ordenador.zaurus_mini = 3; ordenador.text_mini=1;} + restart_video(); + } +} + +static void setup_joystick(int joy, unsigned int sdl_key, int joy_key) +{ + int loop; + + //Cancel the previous assignement - it is not possible to assign a same sdl_key to 2 joybuttons + for (loop=0; loop<22; loop++) + if (ordenador.joybuttonkey[joy][loop] == sdl_key) ordenador.joybuttonkey[joy][loop] =0; + + ordenador.joybuttonkey[joy][joy_key] = sdl_key; + +} + +static void input_options(int joy) +{ + const unsigned int wiimote_to_sdl[] = {0, 1, 2, 3, 4}; + const unsigned int nunchuk_to_sdl[] = {7, 8}; + const unsigned int classic_to_sdl[] = {9, 10, 11, 12, 13, 14, 15, 16, 17}; + const unsigned int pad_to_sdl[] = {18, 19, 20, 21}; + int joy_key = 1; + unsigned int sdl_key; + unsigned int submenus[7]; + int opt; + + struct virtkey *virtualkey; + + memset(submenus, 0, sizeof(submenus)); + + submenus[0] = ordenador.joystick[joy]; + submenus[5] = !ordenador.joypad_as_joystick[joy]; + submenus[6] = !ordenador.rumble[joy]; + + opt = menu_select_title("Input menu", + input_messages, submenus); + if (opt < 0) + return; + + ordenador.joystick[joy] = submenus[0]; + ordenador.joypad_as_joystick[joy] = !submenus[5]; + ordenador.rumble[joy] = !submenus[6]; + + if (opt == 0 || opt == 10|| opt == 12) + return; + + virtualkey = get_key(); + if (virtualkey == NULL) + return; + sdl_key = virtualkey->sdl_code; + + if (virtualkey->sdl_code==1) //"Done" selected + {if (virtualkey->caps_on) sdl_key = 304; //Caps Shit + else if (virtualkey->sym_on) sdl_key = 306; //Sym Shit + else return; } + + switch(opt) + { + case 2: // wiimote + joy_key = wiimote_to_sdl[submenus[1]]; break; + case 4: // nunchuk + joy_key = nunchuk_to_sdl[submenus[2]]; break; + case 6: // classic + joy_key = classic_to_sdl[submenus[3]]; break; + case 8: // pad + joy_key = pad_to_sdl[submenus[4]]; break; + default: + break; + } + + setup_joystick(joy, sdl_key, joy_key); + +} + +static void select_mdr() +{ + int retorno, retval; + + const char *filename = menu_select_file(path_mdrs, ordenador.mdr_current_mdr, 0); + + if (filename==NULL) // Aborted + return; + + if (strstr(filename, "None") != NULL) + { + ordenador.mdr_current_mdr[0] = '\0'; + free((void *)filename); + return; + } + + if (!(ext_matches(filename, ".mdr")|ext_matches(filename, ".MDR"))) {free((void *)filename); return;} + + ordenador.mdr_file=fopen(filename,"rb"); // read + if(ordenador.mdr_file==NULL) + retorno=-1; + else { + retorno=0; + retval=fread(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // read the cartridge in memory + ordenador.mdr_modified=0; // not modified + fclose(ordenador.mdr_file); + ordenador.mdr_tapehead=0; + } + + strcpy(ordenador.mdr_current_mdr,filename); + + free((void *)filename); + + switch(retorno) { + case 0: // all right + break; + default: + ordenador.mdr_current_mdr[0]=0; + msgInfo("Error: Can't load that file",3000,NULL); + break; + } +} + +static void delete_mdr() +{ + const char *filename = menu_select_file(path_mdrs, NULL, -1); + + if (filename==NULL) // Aborted + return; + + if ((ext_matches(filename, ".mdr")|ext_matches(filename, ".MDR")) + && (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138/RATIO, FULL_DISPLAY_Y /2-48/RATIO))) unlink(filename); + + free((void *)filename); +} + +static void microdrive() +{ + + unsigned int submenus[3], submenus_old[3]; + int opt,retval ; + + memset(submenus, 0, sizeof(submenus)); + + submenus[1] = !ordenador.mdr_active; + submenus[2] = !ordenador.mdr_cartridge[137922]; + + submenus_old[1] = submenus[1]; + submenus_old[2] = submenus[2]; + + opt = menu_select_title("Microdrive menu", + microdrive_messages, submenus); + if (opt < 0) + return; + + ordenador.mdr_active = !submenus[1]; + + + if (submenus[1]!=submenus_old[1]) ResetComputer(); + if (submenus[2]!=submenus_old[2]) + {if(ordenador.mdr_cartridge[137922]) + ordenador.mdr_cartridge[137922]=0; + else + ordenador.mdr_cartridge[137922]=1; + ordenador.mdr_file=fopen(ordenador.mdr_current_mdr,"wb"); // create for write + if(ordenador.mdr_file!=NULL) { + retval=fwrite(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // save cartridge + fclose(ordenador.mdr_file); + ordenador.mdr_file=NULL; + ordenador.mdr_modified=0; + } + } + + if (opt==0) + switch (submenus[0]) + { + case 0: // Select microdrive + select_mdr(); + break; + case 1: // Create microdrive file + // Create microdrive file ; + msgInfo("Not yet implemented",3000,NULL); + break; + case 2: // Delete microdrive file + delete_mdr(); + break; + default: + break; + } +} +void show_keyboard_layout() { + + FILE *fichero; + int bucle1,bucle2,retval; + unsigned char *buffer,valor; + + buffer=screen->pixels; + + fichero=myfopen("fbzx/keymap.bmp","r"); + if (fichero==NULL) { + msgInfo("Keymap picture not found",3000,NULL); + return; + } + + for (bucle1=0;bucle1<344;bucle1++) + for(bucle2=0;bucle2<640;bucle2++) { + retval=fscanf(fichero,"%c",&valor); + paint_one_pixel((unsigned char *)(colors+valor),buffer); + buffer+=ordenador.bpp; + } + SDL_Flip(ordenador.screen); + menu_wait_key_press(); +} + +static void load_scr() +{ + int retorno,loop; + unsigned char value; + FILE *fichero; + unsigned char paleta_tmp[64]; + + + const char *filename = menu_select_file(path_scr, NULL, -1); + + if (filename==NULL) // Aborted + return; + + if (!(ext_matches(filename, ".scr")|ext_matches(filename, ".SCR"))) {free((void *)filename); return;} + + ordenador.osd_text[0]=0; + fichero=fopen(filename,"rb"); + retorno=0; + if (!fichero) { + retorno=-1; + } else { + for(loop=0;loop<6912;loop++) { + if (1==fread(&value,1,1,fichero)) { + *(ordenador.block1 + 0x04000 + loop) = value; + } else { + retorno=-1; + break; + } + } + if (1==fread(paleta_tmp,64,1,fichero)) { + memcpy(ordenador.ulaplus_palete,paleta_tmp,64); + ordenador.ulaplus=1; + } else { + ordenador.ulaplus=0; + } + fclose(fichero); + } + + switch(retorno) { + case 0: // all right + break; + case -1: + msgInfo("Error: Can't load that file",3000,NULL); + break; + default: + break; + } + + free((void *)filename); + +} + +static void save_scr() +{ + const char *dir = path_scr; + const char *tape = ordenador.last_selected_file; + char *ptr; + FILE *fichero; + char db[256]; + char fb[81]; + int retorno,retval; + + // Name (for saves) - TO CHECK + if (tape && strrchr(tape, '/')) + strncpy(fb, strrchr(tape, '/') + 1, 80); + else + strcpy(fb, "unknown"); + + //remove the extension + ptr = strrchr (fb, '.'); + if (ptr) *ptr = 0; + + // Save SCR file + snprintf(db, 255, "%s/%s.scr", dir, fb); + + fichero=fopen(db,"r"); + + if(fichero!=NULL) + { + fclose(fichero); + if (!msgYesNo("Overwrite the exiting file?", 0, FULL_DISPLAY_X /2-160/RATIO, FULL_DISPLAY_Y /2-48/RATIO)) + return; // file already exists + } + + fichero=fopen(db,"wb"); // create for write + + if(fichero==NULL) + retorno=-1; + else { + retval=fwrite(ordenador.block1+0x04000,6912,1,fichero); // save screen + if (ordenador.ulaplus!=0) { + retval=fwrite(ordenador.ulaplus_palete,64,1,fichero); // save ULAPlus palete + } + fclose(fichero); + retorno=0; + } + + switch(retorno) { + case 0: + msgInfo("SCR saved",3000,NULL); + break; + case -1: + msgInfo("Can't create file",3000,NULL); + break; + default: + break; + } +} + +static void set_port(int which) +{ + int length; + + switch (which) + { + case 0: //PORT_SD + strcpy(path_snaps,getenv("HOME")); + length=strlen(path_snaps); + if ((length>0)&&(path_snaps[length-1]!='/')) + strcat(path_snaps,"/"); + strcpy(path_taps,path_snaps); + strcat(path_snaps,"snapshots"); + strcat(path_taps,"tapes"); + ordenador.port = which; + break; + case 1: //PORT_USB + if (usbismount) { + strcpy(path_snaps,"usb:/"); + strcpy(path_taps,"usb:/"); + ordenador.port = which;} + else + msgInfo("USB is not mounted",3000,NULL); + break; + case 2: //PORT_SMB + if (smbismount) { + strcpy(path_snaps,"smb:/"); + strcpy(path_taps,"smb:/"); + ordenador.port = which;} + else + msgInfo("SMB is not mounted",3000,NULL); + break; + default: + break; + } +} + +static void tools() +{ + int opt ; + int submenus[1]; + + memset(submenus, 0, sizeof(submenus)); + + submenus[0] = ordenador.port; + + opt = menu_select_title("Tools menu", + tools_messages, submenus); + if (opt < 0) + return; + + set_port(submenus[0]); + + switch(opt) + { + case 0: // Show keyboard + if (ordenador.zaurus_mini == 0) show_keyboard_layout(); else msgInfo("No picture available in 320X240 resolution",3000,NULL); + break; + case 2: // Save SCR + save_scr(); + break; + case 4: // Load SCR + load_scr(); + break; + case 6: // Insert poke + // Insert poke ; + msgInfo("Not yet implemented",3000,NULL); + break; + default: + break; + } +} + + +void virtual_keyboard(void) +{ + int key_code; + + virtkey_t *key =get_key(); + if (key) {key_code = key->sdl_code;} else return; + + ordenador.kbd_buffer_pointer=1; + countdown=8; + ordenador.keyboard_buffer[0][1]= key_code; + if (key->caps_on) ordenador.keyboard_buffer[1][1]= SDLK_LSHIFT; + else if (key->sym_on) ordenador.keyboard_buffer[1][1]= SDLK_LCTRL; + else ordenador.keyboard_buffer[1][1]= 0; + + printf ("Push Event: keycode %d\n", key_code); + +} + +static void save_load_snapshot(int which) +{ + const char *dir = path_snaps; + const char *tape = ordenador.last_selected_file; + char *ptr; + char db[256]; + char fb[81]; + int retorno; + + // Name (for saves) - TO CHECK + if (tape && strrchr(tape, '/')) + strncpy(fb, strrchr(tape, '/') + 1, 80); + else + strcpy(fb, "unknown"); + + //remove the extension + ptr = strrchr (fb, '.'); + if (ptr) *ptr = 0; + + switch(which) + { + case 2: + case 0: // Load or delete file + { + const char *filename = menu_select_file(dir, NULL,-1); + + if (!filename) + return; + + if (ext_matches(filename, ".z80")|ext_matches(filename, ".Z80")| + ext_matches(filename, ".sna")|ext_matches(filename, ".SNA")) + { + if (which == 0) // Load snapshot file + { + retorno=load_z80((char *)filename); + + switch(retorno) { + case 0: // all right + strcpy(ordenador.last_selected_file,filename); + if (ordenador.autoconf) maybe_load_conf(filename); + break; + case -1: + msgInfo("Error: Can't load that file",3000,NULL); + break; + case -2: + case -3: + msgInfo("Error: unsuported snap file",3000,NULL); + break; + } + } + else // Delete snashot file + if (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138/RATIO, FULL_DISPLAY_Y /2-48/RATIO)) unlink(filename); + } + free((void*)filename); + } break; + case 1: // Save snapshot file + snprintf(db, 255, "%s/%s.z80", dir, fb); + retorno=save_z80(db,0); + switch(retorno) + { + case 0: //OK + msgInfo("Snapshot saved",3000,NULL); + break; + case -1: + if (msgYesNo("Overwrite the exiting file?", 0, FULL_DISPLAY_X /2-160/RATIO, FULL_DISPLAY_Y /2-48/RATIO)) + { + save_z80(db,1); //force overwrite + msgInfo("Snapshot saved",3000,NULL); + } + break; + case -2: + msgInfo("Can't create file",3000,NULL); + break; + } + break; + default: + break; + } +} + +static void save_load_game_configurations(int which) +{ + const char *dir = path_confs; + const char *tape = ordenador.last_selected_file; + char *ptr; + char db[256]; + char fb[81]; + int retorno; + + switch(which) + { + case 2: + case 0: // Load or delete file + { + const char *filename = menu_select_file(dir, NULL,-1); + + if (!filename) + return; + + if (ext_matches(filename, ".conf")|ext_matches(filename, ".CONF")) + { + if (which == 0) // Load config file + { + if (!load_config(&ordenador,db)) msgInfo("Game confs loaded",3000,NULL); + break; + } + else // Delete config file + if (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138/RATIO, FULL_DISPLAY_Y /2-48/RATIO)) unlink(filename); + } + free((void*)filename); + } break; + case 1: // Save configuration file + + // Name (for game config saves) - TO CHECK + if (tape && strrchr(tape, '/')) + strncpy(fb, strrchr(tape, '/') + 1, 80); + else + { + msgInfo("No file selected",3000,NULL); + return; + } + + //remove the extension + ptr = strrchr (fb, '.'); + + if (ptr) *ptr = 0; + + snprintf(db, 255, "%s/%s.conf", dir, fb); + + retorno=save_config_game(&ordenador,db,0); + + switch(retorno) + { + case 0: //OK + msgInfo("Game confs saved",3000,NULL); + break; + case -1: + if (msgYesNo("Overwrite the exiting file?", 0, FULL_DISPLAY_X /2-160/RATIO, FULL_DISPLAY_Y /2-48/RATIO)) + { + save_config_game(&ordenador,db,1); //force overwrite + msgInfo("Game confs saved",3000,NULL); + } + break; + case -2: + msgInfo("Can't create file",3000,NULL); + break; + } + break; + default: + break; + } +} +static void save_load_general_configurations(int which) +{ + + int retorno; + unsigned char old_bw,old_mode; + char config_path[1024]; + int length; + FILE *fconfig; + + strcpy(config_path,getenv("HOME")); + length=strlen(config_path); + if ((length>0)&&(config_path[length-1]!='/')) + strcat(config_path,"/"); + strcat(config_path,"fbzx.conf"); + + switch(which) + { + case 2: + case 0: // Load or delete file + { + fconfig = fopen(config_path,"r"); + if (fconfig==NULL) + { + msgInfo("Can not access the file",3000,NULL); + return; + } + else fclose(fconfig); + + if (which == 0) // Load config file + { + old_bw = ordenador.bw; + old_mode= ordenador.mode128k; + if (!load_config(&ordenador,config_path)) msgInfo("General confs loaded",3000,NULL); + if (old_bw!=ordenador.bw) computer_set_palete(); + if (old_mode != ordenador.mode128k) ResetComputer(); + break; + } + else // Delete config file + if (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138/RATIO, FULL_DISPLAY_Y /2-48/RATIO)) unlink(config_path); + + } break; + case 1: // Save configuration file + retorno=save_config(&ordenador,config_path); + + switch(retorno) + { + case 0: //OK + msgInfo("General confs saved",3000,NULL); + break; + case -2: + msgInfo("Can't create file",3000,NULL); + break; + } + break; + default: + break; + } +} +static void manage_configurations() +{ + int opt ; + int submenus[3]; + + memset(submenus, 0, sizeof(submenus)); + + submenus[2]=!ordenador.autoconf; + + opt = menu_select_title("Configurations file menu", + confs_messages, submenus); + if (opt < 0) + return; + + ordenador.autoconf=!submenus[2]; + + switch(opt) + { + case 0: // Save, load and delete general configurations + save_load_general_configurations(submenus[0]); + break; + case 3: // Save, load and delete game configurations + save_load_game_configurations(submenus[1]); + break; + default: + break; + } +} + + +static void help(void) +{ + menu_select_title("FBZX-WII help", + help_messages, NULL); +} + +void main_menu() +{ + int submenus[3]; + int opt; + + memset(submenus, 0, sizeof(submenus)); + + do + { + opt = menu_select_title("Main menu", main_menu_messages, submenus); + if (opt < 0) + break; + + switch(opt) + { + case 0: + manage_tape(submenus[0]); + break; + case 2: + save_load_snapshot(submenus[1]); + break; + case 5: + input_options(submenus[2]); + break; + case 7: + emulation_settings(); + break; + case 8: + screen_settings(); + break; + case 9: + manage_configurations(); + break; + case 10: + microdrive(); + break; + case 11: + tools(); + break; + case 12: + ResetComputer (); + ordenador.pause = 1; + if (ordenador.tap_file != NULL) { + ordenador.tape_current_mode = TAP_TRASH; + rewind_tape (ordenador.tap_file,1); + } + break; + case 13: + help(); + break; + case 14: + if (msgYesNo("Are you sure to quit?", 0, FULL_DISPLAY_X /2-138/RATIO, FULL_DISPLAY_Y /2-48/RATIO)) + {salir = 0;} + break; + default: + break; + } + } while (opt == 5 || opt == 7 || opt == 10 || opt == 13); + + clean_screen(); + +} diff --git a/src/menu_sdl.c b/src/menu_sdl.c index 4c27ce7..9b9a7a5 100644 --- a/src/menu_sdl.c +++ b/src/menu_sdl.c @@ -1,1002 +1,1025 @@ -/********************************************************************* - * Copyright (C) 2012, Fabio Olimpieri - * Copyright (C) 2009, Simon Kagstrom - * - * Filename: menu_sdl.c - * - * Description: Code for menus (originally for Mophun) - * - * This file is part of FBZX Wii - * - * FBZX Wii is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * FBZX Wii is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - ********************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "menu_sdl.h" -#include "emulator.h" -#include "VirtualKeyboard.h" - - - -typedef struct -{ - int n_entries; - int index; - int sel; -} submenu_t; - -typedef struct -{ - char title[256]; - const char **pp_msgs; - TTF_Font *p_font; - int x1,y1; - int x2,y2; - int text_w; - int text_h; - - int n_submenus; - submenu_t *p_submenus; - - int cur_sel; /* Main selection */ - int start_entry_visible; - int n_entries; -} menu_t; - -static SDL_Surface *real_screen; - -#define IS_SUBMENU(p_msg) ( (p_msg)[0] == '^' ) -#define IS_TEXT(p_msg) ( (p_msg)[0] == '#' || (p_msg)[0] == ' ' ) -#define IS_MARKER(p_msg) ( (p_msg)[0] == '@' ) - -static int is_inited = 0; -static TTF_Font *menu_font16, *menu_font20; -#if defined(GEKKO) -#define FONT_PATH "/fbzx-wii/fbzx/FreeMono.ttf" -#else -#define FONT_PATH "FreeMono.ttf" -#endif - -int fh, fw; - -int msgInfo(char *text, int duration, SDL_Rect *irc) -{ - int len = strlen(text); - int X, Y; - SDL_Rect src; - SDL_Rect rc; - SDL_Rect brc; - - X = (FULL_DISPLAY_X /2) - (len / 2 + 1)*12; - Y = (FULL_DISPLAY_Y /2) - 24; - - brc.x = FULL_DISPLAY_X/2-2*12; - brc.y=Y+42; - brc.w=48; - brc.h=20; - - rc.x = X; - rc.y=Y; - rc.w=12*(len + 2); - rc.h=duration > 0 ? 48 : 80; - - src.x=rc.x+4; - src.y=rc.y+4; - src.w=rc.w; - src.h=rc.h; - - - if (irc) - { - irc->x=rc.x; - irc->y=rc.y; - irc->w=src.w; - irc->h=src.h; - } - SDL_FillRect(real_screen, &src, SDL_MapRGB(real_screen->format, 0, 96, 0)); - SDL_FillRect(real_screen, &rc, SDL_MapRGB(real_screen->format, 128, 128, 128)); - menu_print_font(real_screen, 255,255,255, X+12, Y+12, text,20); - SDL_UpdateRect(real_screen, src.x, src.y, src.w, src.h); - SDL_UpdateRect(real_screen, rc.x, rc.y, rc.w,rc.h); - if (duration > 0) - SDL_Delay(duration); - else if (duration < 0) - { - SDL_FillRect(real_screen, &brc, SDL_MapRGB(real_screen->format, 0x00, 0x80, 0x00)); - menu_print_font(real_screen, 0,0,0, FULL_DISPLAY_X/2-12, Y+42, "OK",20); - SDL_UpdateRect(real_screen, brc.x, brc.y, brc.w, brc.h); - while (!(KEY_SELECT & menu_wait_key_press())) {} - - } - - return 1; -} - -/* -void msgKill(SDL_Rect *rc) -{ - SDL_UpdateRect(real_screen, rc->x, rc->y, rc->w,rc->h); -} -*/ - -int msgYesNo(char *text, int default_opt, int x, int y) -{ - int len = strlen(text); - int X, Y; - SDL_Rect src; - SDL_Rect rc; - SDL_Rect brc; - uint32_t key; - - if (x < 0) - X = (FULL_DISPLAY_X /2) - (len / 2 + 1)*12; - else - X = x; - - if (y < 0) - Y = (FULL_DISPLAY_Y /2) - 48; - else - Y = y; - - rc.x=X; - rc.y=Y; - rc.w=12*(len + 2); - rc.h=80; - - src.x=rc.x+4; - src.y=rc.y+4; - src.w=rc.w; - src.h=rc.h; - - while (1) - { - SDL_FillRect(real_screen, &src, SDL_MapRGB(real_screen->format, 0, 96, 0)); - SDL_FillRect(real_screen, &rc, SDL_MapRGB(real_screen->format, 128, 128, 128)); - menu_print_font(real_screen, 255,255,255, X+12, Y+12, text,20); - - if (default_opt) - { - brc.x=rc.x + rc.w/2-5*12; - brc.y=rc.y+42; - brc.w=12*3; - brc.h=20; - SDL_FillRect(real_screen, &brc, SDL_MapRGB(real_screen->format, 0x00, 0x80, 0x00)); - } - else - { - brc.x=rc.x + rc.w/2+5*12-2*12-6; - brc.y=rc.y+42; - brc.w=12*3; - brc.h=20; - SDL_FillRect(real_screen, &brc, SDL_MapRGB(real_screen->format, 0x80, 0x00, 0x00)); - } - - menu_print_font(real_screen, 255,255,255, rc.x + rc.w/2-5*12, Y+42, "YES",20); - menu_print_font(real_screen, 255,255,255, rc.x + rc.w/2-5*12+8*12, Y+42, "NO",20); - - SDL_UpdateRect(real_screen, src.x, src.y, src.w, src.h); - SDL_UpdateRect(real_screen, rc.x, rc.y, rc.w,rc.h); - SDL_UpdateRect(real_screen, brc.x, brc.y, brc.w,brc.h); - - //SDL_Flip(real_screen); - key = menu_wait_key_press(); - if (key & KEY_SELECT) - { - return default_opt; - } - else if (key & KEY_ESCAPE) - { - return 0; - } - else if (key & KEY_LEFT) - { - default_opt = !default_opt; - } - else if (key & KEY_RIGHT) - { - default_opt = !default_opt; - } - } -} - - - -static int cmpstringp(const void *p1, const void *p2) -{ - const char *p1_s = *(const char**)p1; - const char *p2_s = *(const char**)p2; - - /* Put directories first */ - if (*p1_s == '[' && *p2_s != '[') - return -1; - if (*p1_s != '[' && *p2_s == '[') - return 1; - return strcmp(* (char * const *) p1, * (char * const *) p2); -} - -/* Return true if name ends with ext (for filenames) */ -int ext_matches(const char *name, const char *ext) -{ - int len = strlen(name); - int ext_len = strlen(ext); - - if (len <= ext_len) - return 0; - return (strcmp(name + len - ext_len, ext) == 0); -} - -static int ext_matches_list(const char *name, const char **exts) -{ - const char **p; - - for (p = exts; *p; p++) - { - if (ext_matches(name, *p)) - return 1; - } - - return 0; -} - -static const char **get_file_list(const char *base_dir) -{ - DIR *d = opendir(base_dir); - const char **file_list; - int cur = 0; - struct dirent *de; - int cnt = 16; - - if (!d) - return NULL; - - file_list = (const char**)malloc(cnt * sizeof(char*)); - file_list[cur++] = strdup("None"); - file_list[cur] = NULL; - - for (de = readdir(d); - de; - de = readdir(d)) - { - char buf[255]; - const char *exts[] = {".tap", ".TAP", ".tzx", ".TZX", ".z80",".Z80",".sna", ".SNA", - ".mdr", ".MDR", ".scr", ".SCR", ".conf", ".CONF",NULL}; - struct stat st; - - snprintf(buf, 255, "%s/%s", base_dir, de->d_name); - if (stat(buf, &st) < 0) - continue; - if (S_ISDIR(st.st_mode)&&strcmp(".", de->d_name)) - { - char *p; - size_t len = strlen(de->d_name) + 4; - - p = (char*)malloc( len ); - snprintf(p, len, "[%s]", de->d_name); - file_list[cur++] = p; - file_list[cur] = NULL; - } - else if (ext_matches_list(de->d_name, exts)) - { - char *p; - - p = strdup(de->d_name); - file_list[cur++] = p; - file_list[cur] = NULL; - } - - if (cur > cnt - 2) - { - cnt = cnt + 32; - file_list = (const char**)realloc(file_list, cnt * sizeof(char*)); - if (!file_list) - return NULL; - } - } - closedir(d); - qsort(&file_list[1], cur-1, sizeof(const char *), cmpstringp); - - return file_list; -} - - -static submenu_t *find_submenu(menu_t *p_menu, int index) -{ - int i; - - for (i=0; in_submenus; i++) - { - if (p_menu->p_submenus[i].index == index) - return &p_menu->p_submenus[i]; - } - - return NULL; -} - -void menu_print_font(SDL_Surface *screen, int r, int g, int b, - int x, int y, const char *msg, int font_size) -{ -#define _MAX_STRING 64 - SDL_Surface *font_surf; - SDL_Rect dst = {x, y, 0, 0}; - SDL_Color color = {r, g, b}; - char buf[255]; - unsigned int i; - - memset(buf, 0, sizeof(buf)); - strncpy(buf, msg, 254); - if (buf[0] != '|' && buf[0] != '^' && buf[0] != '.' - && buf[0] != '-' && buf[0] != ' ' && !strstr(buf, " \"")) - { - if (strlen(buf)>_MAX_STRING) - { - //buf[_MAX_STRING-3] = '.'; - //buf[_MAX_STRING-2] = '.'; - //buf[_MAX_STRING-1] = '.'; - buf[_MAX_STRING] = '\0'; - } - } - /* Fixup multi-menu option look */ - for (i = 0; i < strlen(buf) ; i++) - { - if (buf[i] == '^' || buf[i] == '|') - buf[i] = ' '; - } - - if (font_size == 16) font_surf = TTF_RenderUTF8_Blended(menu_font16, buf, color); - else font_surf = TTF_RenderUTF8_Blended(menu_font20, buf, color); - if (!font_surf) - { - fprintf(stderr, "%s\n", TTF_GetError()); - exit(1); - } - - SDL_BlitSurface(font_surf, NULL, screen, &dst); - SDL_FreeSurface(font_surf); -} - - -static void menu_draw(SDL_Surface *screen, menu_t *p_menu, int sel, int font_size) -{ - int font_height = TTF_FontHeight(p_menu->p_font); - int line_height = (font_height + font_height / 4); - int x_start = p_menu->x1; - int y_start = p_menu->y1 + line_height; - SDL_Rect r; - int entries_visible = (p_menu->y2 - p_menu->y1) / line_height - 1; - - int i, y; - - if ( p_menu->n_entries * line_height > p_menu->y2 ) - y_start = p_menu->y1 + line_height; - - if (p_menu->cur_sel - p_menu->start_entry_visible > entries_visible) - { - while (p_menu->cur_sel - p_menu->start_entry_visible > entries_visible) - { - p_menu->start_entry_visible ++; - if (p_menu->start_entry_visible > p_menu->n_entries) - { - p_menu->start_entry_visible = 0; - break; - } - } - } - else if ( p_menu->cur_sel < p_menu->start_entry_visible ) - p_menu->start_entry_visible = p_menu->cur_sel; - - if (strlen(p_menu->title)) - { - r.x = p_menu->x1; - r.y = p_menu->y1; - r.w = p_menu->x2 - p_menu->x1; - r.h = line_height-1; - if (sel < 0) - SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0x40, 0x00, 0x00)); - else - SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0x00, 0xe7, 0xe7)); - menu_print_font(screen, 0,0,0, p_menu->x1, p_menu->y1, p_menu->title, font_size); - } - - for (i = p_menu->start_entry_visible; i <= p_menu->start_entry_visible + entries_visible; i++) - { - const char *msg = p_menu->pp_msgs[i]; - - if (i >= p_menu->n_entries) - break; - if (IS_MARKER(msg)) - p_menu->cur_sel = atoi(&msg[1]); - else - { - y = (i - p_menu->start_entry_visible) * line_height; - - if (sel < 0) - menu_print_font(screen, 0x40,0x40,0x40, - x_start, y_start + y, msg, font_size); - else if (p_menu->cur_sel == i) /* Selected - color */ - menu_print_font(screen, 0,200,0, - x_start, y_start + y, msg, font_size); - else if (IS_SUBMENU(msg)) - { - if (p_menu->cur_sel == i-1) - menu_print_font(screen, 0,200,0, - x_start, y_start + y, msg, font_size); - else - menu_print_font(screen, 0x40,0x40,0x40, - x_start, y_start + y, msg, font_size); - } - else if (msg[0] == '#') - { - switch (msg[1]) - { - case '1': - menu_print_font(screen, 0,0,255, - x_start, y_start + y, msg+2, font_size); - break; - case '2': - menu_print_font(screen, 0x40,0x40,0x40, - x_start, y_start + y, msg+2, font_size); - break; - default: - menu_print_font(screen, 0x40,0x40,0x40, - x_start, y_start + y, msg, font_size); - break; - } - } - else /* Otherwise white */ - menu_print_font(screen, 0x40,0x40,0x40, - x_start, y_start + y, msg, font_size); - if (IS_SUBMENU(msg)) - { - submenu_t *p_submenu = find_submenu(p_menu, i); - int n_pipe = 0; - int n; - - for (n=0; msg[n] != '\0'; n++) - { - /* Underline the selected entry */ - if (msg[n] == '|') - { - int16_t n_chars; - - for (n_chars = 1; msg[n+n_chars] && msg[n+n_chars] != '|'; n_chars++); - - n_pipe++; - if (p_submenu->sel == n_pipe-1) - { - int w; - int h; - - if (TTF_SizeText(p_menu->p_font, "X", &w, &h) < 0) - { - fw = w; - fh = h; - fprintf(stderr, "%s\n", TTF_GetError()); - exit(1); - } - - r = (SDL_Rect){ x_start + (n+1) * w-1, y_start + (i+ 1 - p_menu->start_entry_visible) * ((h + h/4)) -3, (n_chars - 1) * w, 2}; - if (p_menu->cur_sel == i-1) - SDL_FillRect(screen, &r, - SDL_MapRGB(screen->format, 255,0,0)); - else - SDL_FillRect(screen, &r, - SDL_MapRGB(screen->format, 0x40,0x40,0x40)); - break; - } - } - } - } - } - } -} - -static int get_next_seq_y(menu_t *p_menu, int v, int dy, int cicle) -{ - if (v + dy < 0) - {if (cicle) return (p_menu->n_entries - 1); else return 0;} - - if (v + dy > p_menu->n_entries - 1) - {if (cicle) return 0; else return (p_menu->n_entries - 1);} - return v + dy; -} - -static void select_next(menu_t *p_menu, int dx, int dy, int cicle) -{ - int next; - - - p_menu->cur_sel = get_next_seq_y(p_menu, p_menu->cur_sel, dy, cicle); - next = get_next_seq_y(p_menu, p_menu->cur_sel, dy + 1, cicle); - if (p_menu->pp_msgs[p_menu->cur_sel][0] == ' ' || - p_menu->pp_msgs[p_menu->cur_sel][0] == '#' || - IS_SUBMENU(p_menu->pp_msgs[p_menu->cur_sel]) ) - select_next(p_menu, dx, dy, cicle); - - /* If the next is a submenu */ - if (dx != 0 && IS_SUBMENU(p_menu->pp_msgs[next])) - { - submenu_t *p_submenu = find_submenu(p_menu, next); - - p_submenu->sel = (p_submenu->sel + dx) < 0 ? p_submenu->n_entries - 1 : - (p_submenu->sel + dx) % p_submenu->n_entries; - } - else if (dx == -1 && !strcmp(p_menu->pp_msgs[0], "[..]")) - p_menu->cur_sel = 0; -} - -static void select_one(menu_t *p_menu, int sel) -{ - if (sel >= p_menu->n_entries) - sel = 0; - p_menu->cur_sel = sel; - if (p_menu->pp_msgs[p_menu->cur_sel][0] == ' ' || - p_menu->pp_msgs[p_menu->cur_sel][0] == '#' || - IS_SUBMENU(p_menu->pp_msgs[p_menu->cur_sel])) - select_next(p_menu, 0, 1 , 1); -} - -/* -static int is_submenu_title(menu_t *p_menu, int n) -{ - if (n+1 >= p_menu->n_entries) - return 0; - else - return IS_SUBMENU(p_menu->pp_msgs[n+1]); -} -*/ - -static void menu_init_internal(menu_t *p_menu, const char *title, - TTF_Font *p_font, const char **pp_msgs, - int16_t x1, int16_t y1, int16_t x2, int16_t y2) -{ - int submenu; - int j; - - memset(p_menu, 0, sizeof(menu_t)); - - p_menu->pp_msgs = pp_msgs; - p_menu->p_font = p_font; - p_menu->x1 = x1; - p_menu->y1 = y1; - p_menu->x2 = x2; - p_menu->y2 = y2; - - p_menu->text_w = 0; - p_menu->n_submenus = 0; - strcpy(p_menu->title, title); - - for (p_menu->n_entries = 0; p_menu->pp_msgs[p_menu->n_entries]; p_menu->n_entries++) - { - int text_w_font; - - /* Is this a submenu? */ - if (IS_SUBMENU(p_menu->pp_msgs[p_menu->n_entries])) - { - p_menu->n_submenus++; - continue; /* Length of submenus is unimportant */ - } - - if (TTF_SizeText(p_font, p_menu->pp_msgs[p_menu->n_entries], &text_w_font, NULL) != 0) - { - fprintf(stderr, "%s\n", TTF_GetError()); - exit(1); - } - if (text_w_font > p_menu->text_w) - p_menu->text_w = text_w_font; - } - if (p_menu->text_w > p_menu->x2 - p_menu->x1) - p_menu->text_w = p_menu->x2 - p_menu->x1; - - if ( !(p_menu->p_submenus = (submenu_t *)malloc(sizeof(submenu_t) * p_menu->n_submenus)) ) - { - perror("malloc failed!\n"); - exit(1); - } - - j=0; - submenu = 0; - for (; j < p_menu->n_entries; j++) - { - if (IS_SUBMENU(p_menu->pp_msgs[j])) - { - int n; - - p_menu->p_submenus[submenu].index = j; - p_menu->p_submenus[submenu].sel = 0; - p_menu->p_submenus[submenu].n_entries = 0; - for (n=0; p_menu->pp_msgs[j][n] != '\0'; n++) - { - if (p_menu->pp_msgs[j][n] == '|') - p_menu->p_submenus[submenu].n_entries++; - } - submenu++; - } - } - p_menu->text_h = p_menu->n_entries * (TTF_FontHeight(p_font) + TTF_FontHeight(p_font) / 4); -} - -static void menu_fini(menu_t *p_menu) -{ - free(p_menu->p_submenus); -} - -uint32_t menu_wait_key_press(void) -{ - SDL_Event ev; - uint32_t keys = 0; - - while (1) - { - int i, hats, nr; - SDL_Joystick *joy; - static int joy_keys_changed; - static int joy_keys_last; - static int joy_bottons_last[2][7]; - SDL_JoystickUpdate(); - /* Wii-specific, sorry */ - for (nr = 0; nr < ordenador.joystick_number; nr++) { - joy = ordenador.joystick_sdl[nr]; - if (!joy) - continue; - - hats = SDL_JoystickNumHats (joy); - for (i = 0; i < hats; i++) { - Uint8 v = SDL_JoystickGetHat (joy, i); - - if (v & SDL_HAT_UP) - keys |= KEY_UP; - if (v & SDL_HAT_DOWN) - keys |= KEY_DOWN; - if (v & SDL_HAT_LEFT) - keys |= KEY_LEFT; - if (v & SDL_HAT_RIGHT) - keys |= KEY_RIGHT; - } - - Sint16 axis0 = SDL_JoystickGetAxis(joy, 0); - Sint16 axis1 = SDL_JoystickGetAxis(joy, 1); - - if ( axis0 < -15000 ) keys |= KEY_LEFT; - else if (axis0 > 15000 ) keys |= KEY_RIGHT; - - if (axis1 < -15000 ) keys |= KEY_UP; - else if( axis1 > 15000 ) keys |= KEY_DOWN; - - - if ((!SDL_JoystickGetButton(joy, 0) && joy_bottons_last[nr][0]) || /* A */ - (!SDL_JoystickGetButton(joy, 3) && joy_bottons_last[nr][1]) || /* 2 */ - (!SDL_JoystickGetButton(joy, 9) && joy_bottons_last[nr][2]) || /* CA */ - (!SDL_JoystickGetButton(joy, 10) && joy_bottons_last[nr][3])) /* CB */ - keys |= KEY_SELECT; - if ((!SDL_JoystickGetButton(joy, 2) && joy_bottons_last[nr][4]) || /* 1 */ - (!SDL_JoystickGetButton(joy, 11) && joy_bottons_last[nr][5]) || /* CX */ - (!SDL_JoystickGetButton(joy, 12) && joy_bottons_last[nr][6])) /* CY */ - keys |= KEY_ESCAPE; - if (SDL_JoystickGetButton(joy, 5) != 0 || /* + */ - SDL_JoystickGetButton(joy, 18) != 0) /* C+ */ - keys |= KEY_PAGEUP; - if (SDL_JoystickGetButton(joy, 4) != 0 || /* - */ - SDL_JoystickGetButton(joy, 17) != 0) /* C- */ - keys |= KEY_PAGEDOWN; - - joy_bottons_last[nr][0]=SDL_JoystickGetButton(joy, 0) ; /* A */ - joy_bottons_last[nr][1] =SDL_JoystickGetButton(joy, 3) ; /* 2 */ - joy_bottons_last[nr][2] =SDL_JoystickGetButton(joy, 9) ; /* CA */ - joy_bottons_last[nr][3] =SDL_JoystickGetButton(joy, 10) ; /* CB */ - joy_bottons_last[nr][4] =SDL_JoystickGetButton(joy, 2) ; /* 1 */ - joy_bottons_last[nr][5] =SDL_JoystickGetButton(joy, 11) ; /* CX */ - joy_bottons_last[nr][6] =SDL_JoystickGetButton(joy, 12) ; /* CY */ - } - - joy_keys_changed = keys != joy_keys_last; - joy_keys_last = keys; - if (!joy_keys_changed) - keys = 0; - - if (SDL_PollEvent(&ev)) - { - switch(ev.type) - { - case SDL_KEYDOWN: - switch (ev.key.keysym.sym) - { - case SDLK_UP: - keys |= KEY_UP; - break; - case SDLK_DOWN: - keys |= KEY_DOWN; - break; - case SDLK_LEFT: - keys |= KEY_LEFT; - break; - case SDLK_RIGHT: - keys |= KEY_RIGHT; - break; - case SDLK_PAGEDOWN: - keys |= KEY_PAGEDOWN; - break; - case SDLK_PAGEUP: - keys |= KEY_PAGEUP; - break; - case SDLK_RETURN: - case SDLK_SPACE: - keys |= KEY_SELECT; - break; - case SDLK_HOME: - case SDLK_ESCAPE: - keys |= KEY_ESCAPE; - break; - default: - break; - } - break; - case SDL_QUIT: - exit(0); - break; - default: - break; - - } - break; - } - - if (keys != 0) - break; - SDL_Delay(100); - } - return keys; -} - - -extern void PicDisplay(char *name, int off_x, int off_y, int wait); -extern const char **get_t64_list(char *t64); -extern const char **get_prg_list(char *t64); - -extern char curdir[256]; - -static int menu_select_internal(SDL_Surface *screen, - menu_t *p_menu, int *p_submenus, int sel, - void (*select_next_cb)(menu_t *p, void *data), - void *select_next_cb_data, int font_size) -{ - int ret = -1; - int i; - - for (i = 0; i < p_menu->n_submenus; i++) - p_menu->p_submenus[i].sel = p_submenus[i]; - - while(1) - { - SDL_Rect r = {p_menu->x1, p_menu->y1, - p_menu->x2 - p_menu->x1, p_menu->y2 - p_menu->y1}; - uint32_t keys; - int sel_last = p_menu->cur_sel; - - SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0xff, 0xff, 0xff)); - - menu_draw(screen, p_menu, 0, font_size); - SDL_Flip(screen); - - keys = menu_wait_key_press(); - - if (keys & KEY_UP) - select_next(p_menu, 0, -1, 1); - else if (keys & KEY_DOWN) - select_next(p_menu, 0, 1, 1); - else if (keys & KEY_PAGEUP) - select_next(p_menu, 0, -18, 0); - else if (keys & KEY_PAGEDOWN) - select_next(p_menu, 0, 18, 0); - else if (keys & KEY_LEFT) - select_next(p_menu, -1, 0 ,1); - else if (keys & KEY_RIGHT) - select_next(p_menu, 1, 0 ,1); - else if (keys & KEY_ESCAPE) - break; - else if (keys & KEY_SELECT) - { - ret = p_menu->cur_sel; - int i; - - for (i=0; in_submenus; i++) - p_submenus[i] = p_menu->p_submenus[i].sel; - break; - } - /* Invoke the callback when an entry is selected */ - if (sel_last != p_menu->cur_sel && - select_next_cb != NULL) - select_next_cb(p_menu, select_next_cb_data); - } - - SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); - return ret; -} - -int menu_select_sized(const char *title, const char **msgs, int *submenus, int sel, - int x, int y, int x2, int y2, - void (*select_next_cb)(menu_t *p, void *data), - void *select_next_cb_data, int font_size) - -{ - menu_t menu; - int out; - - if (font_size == 16) menu_init_internal(&menu, title, menu_font16, msgs, x, y, x2, y2); - else menu_init_internal(&menu, title, menu_font20, msgs, x, y, x2, y2); - - if (sel >= 0) - select_one(&menu, sel); - out = menu_select_internal(real_screen, &menu, submenus, sel, - select_next_cb, select_next_cb_data, font_size); - - menu_fini(&menu); - - return out; -} - -int menu_select_title(const char *title, const char **msgs, int *submenus) -{ - SDL_FillRect(real_screen, 0, SDL_MapRGB(real_screen->format, 0, 0, 0)); - return menu_select_sized(title, msgs, submenus, 0, - 32, 32, FULL_DISPLAY_X-32, FULL_DISPLAY_Y-32, - NULL, NULL, 20); -} - -int menu_select(const char **msgs, int *submenus) -{ - return menu_select_title("", msgs, submenus); -} - -static const char *menu_select_file_internal(const char *dir_path, - int x, int y, int x2, int y2, const char *selected_file, int which) -{ - const char **file_list = get_file_list(dir_path); - char *sel; - char *out; - const char *ptr_selected_file; - int opt; - int i; - char buf[64]; - - if (file_list == NULL) - return NULL; - - if (selected_file) - { - ptr_selected_file= strrchr(selected_file,'/'); - if (ptr_selected_file) ptr_selected_file++; - else ptr_selected_file = selected_file; - snprintf(buf,64,"file:%s",ptr_selected_file); - opt = menu_select_sized(buf, file_list, NULL, 0, x, y, x2, y2, NULL, NULL, 16); - } - else opt = menu_select_sized("Select file", file_list, NULL, 0, x, y, x2, y2, NULL, NULL ,16); - - if (opt < 0) - return NULL; - sel = strdup(file_list[opt]); - - /* Cleanup everything - file_list is NULL-terminated */ - for ( i = 0; file_list[i]; i++ ) - free((void*)file_list[i]); - free(file_list); - - if (!sel) - return NULL; - /* If this is a folder, enter it recursively */ - if (sel[0] == '[') - { - char buf[255]; - int len = strlen(sel); - int s; - - /* Remove trailing ] */ - sel[len-1] = '\0'; - s = snprintf(buf, 128, "%s/%s", dir_path, sel + 1); - - /* We don't need this anymore */ - free((void*)sel); - /* Too deep recursion! */ - if (s >= sizeof(buf)) - return NULL; - return menu_select_file(buf, selected_file, which); - } - - out = (char*)malloc(strlen(dir_path) + strlen(sel) + 4); - snprintf(out, strlen(dir_path) + strlen(sel) + 4, - "%s/%s", dir_path, sel); - - free(sel); - return out; -} - -/* -const char *menu_select_file_start(const char *dir_path, const char **d64_name) -{ - const char *file = menu_select_file_internal(dir_path, - 32, 32, FULL_DISPLAY_X, FULL_DISPLAY_Y - 32); - - if (!file) - return NULL; - - return file; -} -*/ -const char *menu_select_file(const char *dir_path,const char *selected_file, int which) -{ - if (dir_path == NULL) - dir_path = ""; - return menu_select_file_internal(dir_path, - 0, 32, FULL_DISPLAY_X, FULL_DISPLAY_Y - 32, selected_file, which); -} - -static TTF_Font *read_font(const char *path, int font_size) -{ - TTF_Font *out; - SDL_RWops *rw; - Uint8 *data = (Uint8*)malloc(1 * 1024*1024); - FILE *fp = fopen(path, "r"); - - if (!data) { - fprintf(stderr, "Malloc failed\n"); - exit(1); - } - if (!fp) { - fprintf(stderr, "Could not open font\n"); - exit(1); - } - fread(data, 1, 1 * 1024 * 1024, fp); - rw = SDL_RWFromMem(data, 1 * 1024 * 1024); - if (!rw) - { - fprintf(stderr, "Could not create RW: %s\n", SDL_GetError()); - exit(1); - } - out = TTF_OpenFontRW(rw, 1, font_size); - if (!out) - { - fprintf(stderr, "Unable to open font %s\n", path); - exit(1); - } - fclose(fp); - - return out; -} - -void menu_init(SDL_Surface *screen) -{ - TTF_Init(); - - menu_font16 = read_font(FONT_PATH, 16); - menu_font20 = read_font(FONT_PATH, 20); - - real_screen = screen; - VirtualKeyboard_init(screen, menu_font16); //prima c'era il font 16 alt - is_inited = 1; -} - -int menu_is_inited(void) -{ - return is_inited; -} +/********************************************************************* + * Copyright (C) 2012, Fabio Olimpieri + * Copyright (C) 2009, Simon Kagstrom + * + * Filename: menu_sdl.c + * + * Description: Code for menus (originally for Mophun) + * + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + ********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "menu_sdl.h" +#include "emulator.h" +#include "VirtualKeyboard.h" + + + +typedef struct +{ + int n_entries; + int index; + int sel; +} submenu_t; + +typedef struct +{ + char title[256]; + const char **pp_msgs; + TTF_Font *p_font; + int x1,y1; + int x2,y2; + int text_w; + int text_h; + + int n_submenus; + submenu_t *p_submenus; + + int cur_sel; /* Main selection */ + int start_entry_visible; + int n_entries; +} menu_t; + +static SDL_Surface *real_screen; + +#define IS_SUBMENU(p_msg) ( (p_msg)[0] == '^' ) +#define IS_TEXT(p_msg) ( (p_msg)[0] == '#' || (p_msg)[0] == ' ' ) +#define IS_MARKER(p_msg) ( (p_msg)[0] == '@' ) + +static int is_inited = 0; +static TTF_Font *menu_font16, *menu_font20, *menu_font8, *menu_font10; +#if defined(GEKKO) +#define FONT_PATH "/fbzx-wii/fbzx/FreeMono.ttf" +#else +#define FONT_PATH "FreeMono.ttf" +#endif + +int fh, fw; + +int msgInfo(char *text, int duration, SDL_Rect *irc) +{ + int len = strlen(text); + int X, Y; + SDL_Rect src; + SDL_Rect rc; + SDL_Rect brc; + + X = (FULL_DISPLAY_X /2) - (len / 2 + 1)*12/RATIO; + Y = (FULL_DISPLAY_Y /2) - 24/RATIO; + + brc.x = FULL_DISPLAY_X/2-2*12/RATIO; + brc.y=Y+42/RATIO; + brc.w=48/RATIO; + brc.h=20/RATIO; + + rc.x = X; + rc.y=Y; + rc.w=12*(len + 2)/RATIO; + rc.h=duration > 0 ? 48/RATIO : 80/RATIO; + + src.x=rc.x+4/RATIO; + src.y=rc.y+4/RATIO; + src.w=rc.w; + src.h=rc.h; + + + if (irc) + { + irc->x=rc.x; + irc->y=rc.y; + irc->w=src.w; + irc->h=src.h; + } + SDL_FillRect(real_screen, &src, SDL_MapRGB(real_screen->format, 0, 96, 0)); + SDL_FillRect(real_screen, &rc, SDL_MapRGB(real_screen->format, 128, 128, 128)); + menu_print_font(real_screen, 255,255,255, X+12/RATIO, Y+12/RATIO, text,20); + SDL_UpdateRect(real_screen, src.x, src.y, src.w, src.h); + SDL_UpdateRect(real_screen, rc.x, rc.y, rc.w,rc.h); + if (duration > 0) + SDL_Delay(duration); + else if (duration < 0) + { + SDL_FillRect(real_screen, &brc, SDL_MapRGB(real_screen->format, 0x00, 0x80, 0x00)); + menu_print_font(real_screen, 0,0,0, FULL_DISPLAY_X/2-12/RATIO, Y+42/RATIO, "OK",20); + SDL_UpdateRect(real_screen, brc.x, brc.y, brc.w, brc.h); + while (!(KEY_SELECT & menu_wait_key_press())) {} + + } + + return 1; +} + +/* +void msgKill(SDL_Rect *rc) +{ + SDL_UpdateRect(real_screen, rc->x, rc->y, rc->w,rc->h); +} +*/ + +int msgYesNo(char *text, int default_opt, int x, int y) +{ + int len = strlen(text); + int X, Y; + SDL_Rect src; + SDL_Rect rc; + SDL_Rect brc; + uint32_t key; + + if (x < 0) + X = (FULL_DISPLAY_X /2) - (len / 2 + 1)*12/RATIO; + else + X = x; + + if (y < 0) + Y = (FULL_DISPLAY_Y /2) - 48/RATIO; + else + Y = y; + + rc.x=X; + rc.y=Y; + rc.w=12*(len + 2)/RATIO; + rc.h=80/RATIO; + + src.x=rc.x+4/RATIO; + src.y=rc.y+4/RATIO; + src.w=rc.w; + src.h=rc.h; + + while (1) + { + SDL_FillRect(real_screen, &src, SDL_MapRGB(real_screen->format, 0, 96, 0)); + SDL_FillRect(real_screen, &rc, SDL_MapRGB(real_screen->format, 128, 128, 128)); + menu_print_font(real_screen, 255,255,255, X+12/RATIO, Y+12/RATIO, text,20); + + if (default_opt) + { + brc.x=rc.x + rc.w/2-5*12/RATIO; + brc.y=rc.y+42/RATIO; + brc.w=12*3/RATIO; + brc.h=20/RATIO; + SDL_FillRect(real_screen, &brc, SDL_MapRGB(real_screen->format, 0x00, 0x80, 0x00)); + } + else + { + brc.x=rc.x + rc.w/2+5*12/RATIO-2*12/RATIO-6/RATIO; + brc.y=rc.y+42/RATIO; + brc.w=12*3/RATIO; + brc.h=20/RATIO; + SDL_FillRect(real_screen, &brc, SDL_MapRGB(real_screen->format, 0x80, 0x00, 0x00)); + } + + menu_print_font(real_screen, 255,255,255, rc.x + rc.w/2-5*12/RATIO, Y+42/RATIO, "YES",20); + menu_print_font(real_screen, 255,255,255, rc.x + rc.w/2-5*12/RATIO+8*12/RATIO, Y+42/RATIO, "NO",20); + + SDL_UpdateRect(real_screen, src.x, src.y, src.w, src.h); + SDL_UpdateRect(real_screen, rc.x, rc.y, rc.w,rc.h); + SDL_UpdateRect(real_screen, brc.x, brc.y, brc.w,brc.h); + + //SDL_Flip(real_screen); + key = menu_wait_key_press(); + if (key & KEY_SELECT) + { + return default_opt; + } + else if (key & KEY_ESCAPE) + { + return 0; + } + else if (key & KEY_LEFT) + { + default_opt = !default_opt; + } + else if (key & KEY_RIGHT) + { + default_opt = !default_opt; + } + } +} + + + +static int cmpstringp(const void *p1, const void *p2) +{ + const char *p1_s = *(const char**)p1; + const char *p2_s = *(const char**)p2; + + /* Put directories first */ + if (*p1_s == '[' && *p2_s != '[') + return -1; + if (*p1_s != '[' && *p2_s == '[') + return 1; + return strcmp(* (char * const *) p1, * (char * const *) p2); +} + +/* Return true if name ends with ext (for filenames) */ +int ext_matches(const char *name, const char *ext) +{ + int len = strlen(name); + int ext_len = strlen(ext); + + if (len <= ext_len) + return 0; + return (strcmp(name + len - ext_len, ext) == 0); +} + +static int ext_matches_list(const char *name, const char **exts) +{ + const char **p; + + for (p = exts; *p; p++) + { + if (ext_matches(name, *p)) + return 1; + } + + return 0; +} + +static const char **get_file_list(const char *base_dir) +{ + DIR *d = opendir(base_dir); + const char **file_list; + int cur = 0; + struct dirent *de; + int cnt = 16; + + if (!d) + return NULL; + + file_list = (const char**)malloc(cnt * sizeof(char*)); + file_list[cur++] = strdup("None"); + file_list[cur] = NULL; + + for (de = readdir(d); + de; + de = readdir(d)) + { + char buf[255]; + const char *exts[] = {".tap", ".TAP", ".tzx", ".TZX", ".z80",".Z80",".sna", ".SNA", + ".mdr", ".MDR", ".scr", ".SCR", ".conf", ".CONF",NULL}; + struct stat st; + + snprintf(buf, 255, "%s/%s", base_dir, de->d_name); + if (stat(buf, &st) < 0) + continue; + if (S_ISDIR(st.st_mode)&&strcmp(".", de->d_name)) + { + char *p; + size_t len = strlen(de->d_name) + 4; + + p = (char*)malloc( len ); + snprintf(p, len, "[%s]", de->d_name); + file_list[cur++] = p; + file_list[cur] = NULL; + } + else if (ext_matches_list(de->d_name, exts)) + { + char *p; + + p = strdup(de->d_name); + file_list[cur++] = p; + file_list[cur] = NULL; + } + + if (cur > cnt - 2) + { + cnt = cnt + 32; + file_list = (const char**)realloc(file_list, cnt * sizeof(char*)); + if (!file_list) + return NULL; + } + } + closedir(d); + qsort(&file_list[1], cur-1, sizeof(const char *), cmpstringp); + + return file_list; +} + + +static submenu_t *find_submenu(menu_t *p_menu, int index) +{ + int i; + + for (i=0; in_submenus; i++) + { + if (p_menu->p_submenus[i].index == index) + return &p_menu->p_submenus[i]; + } + + return NULL; +} + +void menu_print_font(SDL_Surface *screen, int r, int g, int b, + int x, int y, const char *msg, int font_size) +{ +#define _MAX_STRING 64 + SDL_Surface *font_surf; + SDL_Rect dst = {x, y, 0, 0}; + SDL_Color color = {r, g, b}; + char buf[255]; + unsigned int i; + + memset(buf, 0, sizeof(buf)); + strncpy(buf, msg, 254); + if (buf[0] != '|' && buf[0] != '^' && buf[0] != '.' + && buf[0] != '-' && buf[0] != ' ' && !strstr(buf, " \"")) + { + if (strlen(buf)>_MAX_STRING) + { + //buf[_MAX_STRING-3] = '.'; + //buf[_MAX_STRING-2] = '.'; + //buf[_MAX_STRING-1] = '.'; + buf[_MAX_STRING] = '\0'; + } + } + /* Fixup multi-menu option look */ + for (i = 0; i < strlen(buf) ; i++) + { + if (buf[i] == '^' || buf[i] == '|') + buf[i] = ' '; + } + + if (FULL_DISPLAY_X == 640) + { + if (font_size == 16) font_surf = TTF_RenderUTF8_Blended(menu_font16, buf, color); + else font_surf = TTF_RenderUTF8_Blended(menu_font20, buf, color); + } + else + { + if (font_size == 16) font_surf = TTF_RenderUTF8_Blended(menu_font8, buf, color); + else font_surf = TTF_RenderUTF8_Blended(menu_font10, buf, color); + } + + if (!font_surf) + { + fprintf(stderr, "%s\n", TTF_GetError()); + exit(1); + } + + SDL_BlitSurface(font_surf, NULL, screen, &dst); + SDL_FreeSurface(font_surf); +} + + +static void menu_draw(SDL_Surface *screen, menu_t *p_menu, int sel, int font_size) +{ + int font_height = TTF_FontHeight(p_menu->p_font); + int line_height = (font_height + font_height / 4); + int x_start = p_menu->x1; + int y_start = p_menu->y1 + line_height; + SDL_Rect r; + int entries_visible = (p_menu->y2 - p_menu->y1) / line_height - 1; + + int i, y; + + if ( p_menu->n_entries * line_height > p_menu->y2 ) + y_start = p_menu->y1 + line_height; + + if (p_menu->cur_sel - p_menu->start_entry_visible > entries_visible) + { + while (p_menu->cur_sel - p_menu->start_entry_visible > entries_visible) + { + p_menu->start_entry_visible ++; + if (p_menu->start_entry_visible > p_menu->n_entries) + { + p_menu->start_entry_visible = 0; + break; + } + } + } + else if ( p_menu->cur_sel < p_menu->start_entry_visible ) + p_menu->start_entry_visible = p_menu->cur_sel; + + if (strlen(p_menu->title)) + { + r.x = p_menu->x1; + r.y = p_menu->y1; + r.w = p_menu->x2 - p_menu->x1; + r.h = line_height-1; + if (sel < 0) + SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0x40, 0x00, 0x00)); + else + SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0x00, 0xe7, 0xe7)); + menu_print_font(screen, 0,0,0, p_menu->x1, p_menu->y1, p_menu->title, font_size); + } + + for (i = p_menu->start_entry_visible; i <= p_menu->start_entry_visible + entries_visible; i++) + { + const char *msg = p_menu->pp_msgs[i]; + + if (i >= p_menu->n_entries) + break; + if (IS_MARKER(msg)) + p_menu->cur_sel = atoi(&msg[1]); + else + { + y = (i - p_menu->start_entry_visible) * line_height; + + if (sel < 0) + menu_print_font(screen, 0x40,0x40,0x40, + x_start, y_start + y, msg, font_size); + else if (p_menu->cur_sel == i) /* Selected - color */ + menu_print_font(screen, 0,200,0, + x_start, y_start + y, msg, font_size); + else if (IS_SUBMENU(msg)) + { + if (p_menu->cur_sel == i-1) + menu_print_font(screen, 0,200,0, + x_start, y_start + y, msg, font_size); + else + menu_print_font(screen, 0x40,0x40,0x40, + x_start, y_start + y, msg, font_size); + } + else if (msg[0] == '#') + { + switch (msg[1]) + { + case '1': + menu_print_font(screen, 0,0,255, + x_start, y_start + y, msg+2, font_size); + break; + case '2': + menu_print_font(screen, 0x40,0x40,0x40, + x_start, y_start + y, msg+2, font_size); + break; + default: + menu_print_font(screen, 0x40,0x40,0x40, + x_start, y_start + y, msg, font_size); + break; + } + } + else /* Otherwise white */ + menu_print_font(screen, 0x40,0x40,0x40, + x_start, y_start + y, msg, font_size); + if (IS_SUBMENU(msg)) + { + submenu_t *p_submenu = find_submenu(p_menu, i); + int n_pipe = 0; + int n; + + for (n=0; msg[n] != '\0'; n++) + { + /* Underline the selected entry */ + if (msg[n] == '|') + { + int16_t n_chars; + + for (n_chars = 1; msg[n+n_chars] && msg[n+n_chars] != '|'; n_chars++); + + n_pipe++; + if (p_submenu->sel == n_pipe-1) + { + int w; + int h; + + if (TTF_SizeText(p_menu->p_font, "X", &w, &h) < 0) + { + fw = w; + fh = h; + fprintf(stderr, "%s\n", TTF_GetError()); + exit(1); + } + + r = (SDL_Rect){ x_start + (n+1) * w-1, y_start + (i+ 1 - p_menu->start_entry_visible) * ((h + h/4)) -3, (n_chars - 1) * w, 2}; + if (p_menu->cur_sel == i-1) + SDL_FillRect(screen, &r, + SDL_MapRGB(screen->format, 255,0,0)); + else + SDL_FillRect(screen, &r, + SDL_MapRGB(screen->format, 0x40,0x40,0x40)); + break; + } + } + } + } + } + } +} + +static int get_next_seq_y(menu_t *p_menu, int v, int dy, int cicle) +{ + if (v + dy < 0) + {if (cicle) return (p_menu->n_entries - 1); else return 0;} + + if (v + dy > p_menu->n_entries - 1) + {if (cicle) return 0; else return (p_menu->n_entries - 1);} + return v + dy; +} + +static void select_next(menu_t *p_menu, int dx, int dy, int cicle) +{ + int next; + + + p_menu->cur_sel = get_next_seq_y(p_menu, p_menu->cur_sel, dy, cicle); + next = get_next_seq_y(p_menu, p_menu->cur_sel, dy + 1, cicle); + if (p_menu->pp_msgs[p_menu->cur_sel][0] == ' ' || + p_menu->pp_msgs[p_menu->cur_sel][0] == '#' || + IS_SUBMENU(p_menu->pp_msgs[p_menu->cur_sel]) ) + select_next(p_menu, dx, dy, cicle); + + /* If the next is a submenu */ + if (dx != 0 && IS_SUBMENU(p_menu->pp_msgs[next])) + { + submenu_t *p_submenu = find_submenu(p_menu, next); + + p_submenu->sel = (p_submenu->sel + dx) < 0 ? p_submenu->n_entries - 1 : + (p_submenu->sel + dx) % p_submenu->n_entries; + } + else if (dx == -1 && !strcmp(p_menu->pp_msgs[0], "[..]")) + p_menu->cur_sel = 0; +} + +static void select_one(menu_t *p_menu, int sel) +{ + if (sel >= p_menu->n_entries) + sel = 0; + p_menu->cur_sel = sel; + if (p_menu->pp_msgs[p_menu->cur_sel][0] == ' ' || + p_menu->pp_msgs[p_menu->cur_sel][0] == '#' || + IS_SUBMENU(p_menu->pp_msgs[p_menu->cur_sel])) + select_next(p_menu, 0, 1 , 1); +} + +/* +static int is_submenu_title(menu_t *p_menu, int n) +{ + if (n+1 >= p_menu->n_entries) + return 0; + else + return IS_SUBMENU(p_menu->pp_msgs[n+1]); +} +*/ + +static void menu_init_internal(menu_t *p_menu, const char *title, + TTF_Font *p_font, const char **pp_msgs, + int16_t x1, int16_t y1, int16_t x2, int16_t y2) +{ + int submenu; + int j; + + memset(p_menu, 0, sizeof(menu_t)); + + p_menu->pp_msgs = pp_msgs; + p_menu->p_font = p_font; + p_menu->x1 = x1; + p_menu->y1 = y1; + p_menu->x2 = x2; + p_menu->y2 = y2; + + p_menu->text_w = 0; + p_menu->n_submenus = 0; + strcpy(p_menu->title, title); + + for (p_menu->n_entries = 0; p_menu->pp_msgs[p_menu->n_entries]; p_menu->n_entries++) + { + int text_w_font; + + /* Is this a submenu? */ + if (IS_SUBMENU(p_menu->pp_msgs[p_menu->n_entries])) + { + p_menu->n_submenus++; + continue; /* Length of submenus is unimportant */ + } + + if (TTF_SizeText(p_font, p_menu->pp_msgs[p_menu->n_entries], &text_w_font, NULL) != 0) + { + fprintf(stderr, "%s\n", TTF_GetError()); + exit(1); + } + if (text_w_font > p_menu->text_w) + p_menu->text_w = text_w_font; + } + if (p_menu->text_w > p_menu->x2 - p_menu->x1) + p_menu->text_w = p_menu->x2 - p_menu->x1; + + if ( !(p_menu->p_submenus = (submenu_t *)malloc(sizeof(submenu_t) * p_menu->n_submenus)) ) + { + perror("malloc failed!\n"); + exit(1); + } + + j=0; + submenu = 0; + for (; j < p_menu->n_entries; j++) + { + if (IS_SUBMENU(p_menu->pp_msgs[j])) + { + int n; + + p_menu->p_submenus[submenu].index = j; + p_menu->p_submenus[submenu].sel = 0; + p_menu->p_submenus[submenu].n_entries = 0; + for (n=0; p_menu->pp_msgs[j][n] != '\0'; n++) + { + if (p_menu->pp_msgs[j][n] == '|') + p_menu->p_submenus[submenu].n_entries++; + } + submenu++; + } + } + p_menu->text_h = p_menu->n_entries * (TTF_FontHeight(p_font) + TTF_FontHeight(p_font) / 4); +} + +static void menu_fini(menu_t *p_menu) +{ + free(p_menu->p_submenus); +} + +uint32_t menu_wait_key_press(void) +{ + SDL_Event ev; + uint32_t keys = 0; + + while (1) + { + int i, hats, nr; + SDL_Joystick *joy; + static int joy_keys_changed; + static int joy_keys_last; + static int joy_bottons_last[2][7]; + SDL_JoystickUpdate(); + /* Wii-specific, sorry */ + for (nr = 0; nr < ordenador.joystick_number; nr++) { + joy = ordenador.joystick_sdl[nr]; + if (!joy) + continue; + + hats = SDL_JoystickNumHats (joy); + for (i = 0; i < hats; i++) { + Uint8 v = SDL_JoystickGetHat (joy, i); + + if (v & SDL_HAT_UP) + keys |= KEY_UP; + if (v & SDL_HAT_DOWN) + keys |= KEY_DOWN; + if (v & SDL_HAT_LEFT) + keys |= KEY_LEFT; + if (v & SDL_HAT_RIGHT) + keys |= KEY_RIGHT; + } + + Sint16 axis0 = SDL_JoystickGetAxis(joy, 0); + Sint16 axis1 = SDL_JoystickGetAxis(joy, 1); + + if ( axis0 < -15000 ) keys |= KEY_LEFT; + else if (axis0 > 15000 ) keys |= KEY_RIGHT; + + if (axis1 < -15000 ) keys |= KEY_UP; + else if( axis1 > 15000 ) keys |= KEY_DOWN; + + + if ((!SDL_JoystickGetButton(joy, 0) && joy_bottons_last[nr][0]) || /* A */ + (!SDL_JoystickGetButton(joy, 3) && joy_bottons_last[nr][1]) || /* 2 */ + (!SDL_JoystickGetButton(joy, 9) && joy_bottons_last[nr][2]) || /* CA */ + (!SDL_JoystickGetButton(joy, 10) && joy_bottons_last[nr][3])) /* CB */ + keys |= KEY_SELECT; + if ((!SDL_JoystickGetButton(joy, 2) && joy_bottons_last[nr][4]) || /* 1 */ + (!SDL_JoystickGetButton(joy, 11) && joy_bottons_last[nr][5]) || /* CX */ + (!SDL_JoystickGetButton(joy, 12) && joy_bottons_last[nr][6])) /* CY */ + keys |= KEY_ESCAPE; + if (SDL_JoystickGetButton(joy, 5) != 0 || /* + */ + SDL_JoystickGetButton(joy, 18) != 0) /* C+ */ + keys |= KEY_PAGEUP; + if (SDL_JoystickGetButton(joy, 4) != 0 || /* - */ + SDL_JoystickGetButton(joy, 17) != 0) /* C- */ + keys |= KEY_PAGEDOWN; + + joy_bottons_last[nr][0]=SDL_JoystickGetButton(joy, 0) ; /* A */ + joy_bottons_last[nr][1] =SDL_JoystickGetButton(joy, 3) ; /* 2 */ + joy_bottons_last[nr][2] =SDL_JoystickGetButton(joy, 9) ; /* CA */ + joy_bottons_last[nr][3] =SDL_JoystickGetButton(joy, 10) ; /* CB */ + joy_bottons_last[nr][4] =SDL_JoystickGetButton(joy, 2) ; /* 1 */ + joy_bottons_last[nr][5] =SDL_JoystickGetButton(joy, 11) ; /* CX */ + joy_bottons_last[nr][6] =SDL_JoystickGetButton(joy, 12) ; /* CY */ + } + + joy_keys_changed = keys != joy_keys_last; + joy_keys_last = keys; + if (!joy_keys_changed) + keys = 0; + + if (SDL_PollEvent(&ev)) + { + switch(ev.type) + { + case SDL_KEYDOWN: + switch (ev.key.keysym.sym) + { + case SDLK_UP: + keys |= KEY_UP; + break; + case SDLK_DOWN: + keys |= KEY_DOWN; + break; + case SDLK_LEFT: + keys |= KEY_LEFT; + break; + case SDLK_RIGHT: + keys |= KEY_RIGHT; + break; + case SDLK_PAGEDOWN: + keys |= KEY_PAGEDOWN; + break; + case SDLK_PAGEUP: + keys |= KEY_PAGEUP; + break; + case SDLK_RETURN: + case SDLK_SPACE: + keys |= KEY_SELECT; + break; + case SDLK_HOME: + case SDLK_ESCAPE: + keys |= KEY_ESCAPE; + break; + default: + break; + } + break; + case SDL_QUIT: + exit(0); + break; + default: + break; + + } + break; + } + + if (keys != 0) + break; + SDL_Delay(100); + } + return keys; +} + + +extern void PicDisplay(char *name, int off_x, int off_y, int wait); +extern const char **get_t64_list(char *t64); +extern const char **get_prg_list(char *t64); + +extern char curdir[256]; + +static int menu_select_internal(SDL_Surface *screen, + menu_t *p_menu, int *p_submenus, int sel, + void (*select_next_cb)(menu_t *p, void *data), + void *select_next_cb_data, int font_size) +{ + int ret = -1; + int i; + + for (i = 0; i < p_menu->n_submenus; i++) + p_menu->p_submenus[i].sel = p_submenus[i]; + + while(1) + { + SDL_Rect r = {p_menu->x1, p_menu->y1, + p_menu->x2 - p_menu->x1, p_menu->y2 - p_menu->y1}; + uint32_t keys; + int sel_last = p_menu->cur_sel; + + SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0xff, 0xff, 0xff)); + + menu_draw(screen, p_menu, 0, font_size); + SDL_Flip(screen); + + keys = menu_wait_key_press(); + + if (keys & KEY_UP) + select_next(p_menu, 0, -1, 1); + else if (keys & KEY_DOWN) + select_next(p_menu, 0, 1, 1); + else if (keys & KEY_PAGEUP) + select_next(p_menu, 0, -18, 0); + else if (keys & KEY_PAGEDOWN) + select_next(p_menu, 0, 18, 0); + else if (keys & KEY_LEFT) + select_next(p_menu, -1, 0 ,1); + else if (keys & KEY_RIGHT) + select_next(p_menu, 1, 0 ,1); + else if (keys & KEY_ESCAPE) + break; + else if (keys & KEY_SELECT) + { + ret = p_menu->cur_sel; + int i; + + for (i=0; in_submenus; i++) + p_submenus[i] = p_menu->p_submenus[i].sel; + break; + } + /* Invoke the callback when an entry is selected */ + if (sel_last != p_menu->cur_sel && + select_next_cb != NULL) + select_next_cb(p_menu, select_next_cb_data); + } + + SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); + return ret; +} + +int menu_select_sized(const char *title, const char **msgs, int *submenus, int sel, + int x, int y, int x2, int y2, + void (*select_next_cb)(menu_t *p, void *data), + void *select_next_cb_data, int font_size) + +{ + menu_t menu; + int out; + + if (FULL_DISPLAY_X == 640) + { + if (font_size == 16) menu_init_internal(&menu, title, menu_font16, msgs, x, y, x2, y2); + else menu_init_internal(&menu, title, menu_font20, msgs, x, y, x2, y2); + } + else + { + if (font_size == 16) menu_init_internal(&menu, title, menu_font8, msgs, x, y, x2, y2); + else menu_init_internal(&menu, title, menu_font10, msgs, x, y, x2, y2); + } + + if (sel >= 0) + select_one(&menu, sel); + out = menu_select_internal(real_screen, &menu, submenus, sel, + select_next_cb, select_next_cb_data, font_size); + + menu_fini(&menu); + + return out; +} + +int menu_select_title(const char *title, const char **msgs, int *submenus) +{ + SDL_FillRect(real_screen, 0, SDL_MapRGB(real_screen->format, 0, 0, 0)); + return menu_select_sized(title, msgs, submenus, 0, + 32/RATIO, 32/RATIO, FULL_DISPLAY_X-32/RATIO, FULL_DISPLAY_Y-32/RATIO, + NULL, NULL, 20); +} + +int menu_select(const char **msgs, int *submenus) +{ + return menu_select_title("", msgs, submenus); +} + +static const char *menu_select_file_internal(const char *dir_path, + int x, int y, int x2, int y2, const char *selected_file, int which) +{ + const char **file_list = get_file_list(dir_path); + char *sel; + char *out; + const char *ptr_selected_file; + int opt; + int i; + char buf[64]; + + if (file_list == NULL) + return NULL; + + if (selected_file) + { + ptr_selected_file= strrchr(selected_file,'/'); + if (ptr_selected_file) ptr_selected_file++; + else ptr_selected_file = selected_file; + snprintf(buf,64,"file:%s",ptr_selected_file); + opt = menu_select_sized(buf, file_list, NULL, 0, x, y, x2, y2, NULL, NULL, 16); + } + else opt = menu_select_sized("Select file", file_list, NULL, 0, x, y, x2, y2, NULL, NULL ,16); + + if (opt < 0) + return NULL; + sel = strdup(file_list[opt]); + + /* Cleanup everything - file_list is NULL-terminated */ + for ( i = 0; file_list[i]; i++ ) + free((void*)file_list[i]); + free(file_list); + + if (!sel) + return NULL; + /* If this is a folder, enter it recursively */ + if (sel[0] == '[') + { + char buf[255]; + int len = strlen(sel); + int s; + + /* Remove trailing ] */ + sel[len-1] = '\0'; + s = snprintf(buf, 128, "%s/%s", dir_path, sel + 1); + + /* We don't need this anymore */ + free((void*)sel); + /* Too deep recursion! */ + if (s >= sizeof(buf)) + return NULL; + return menu_select_file(buf, selected_file, which); + } + + out = (char*)malloc(strlen(dir_path) + strlen(sel) + 4); + snprintf(out, strlen(dir_path) + strlen(sel) + 4, + "%s/%s", dir_path, sel); + + free(sel); + return out; +} + +/* +const char *menu_select_file_start(const char *dir_path, const char **d64_name) +{ + const char *file = menu_select_file_internal(dir_path, + 32, 32, FULL_DISPLAY_X, FULL_DISPLAY_Y - 32); + + if (!file) + return NULL; + + return file; +} +*/ +const char *menu_select_file(const char *dir_path,const char *selected_file, int which) +{ + if (dir_path == NULL) + dir_path = ""; + return menu_select_file_internal(dir_path, + 0, 32/RATIO, FULL_DISPLAY_X, FULL_DISPLAY_Y - 32/RATIO, selected_file, which); +} + +static TTF_Font *read_font(const char *path, int font_size) +{ + TTF_Font *out; + SDL_RWops *rw; + Uint8 *data = (Uint8*)malloc(1 * 1024*1024); + FILE *fp = fopen(path, "r"); + + if (!data) { + fprintf(stderr, "Malloc failed\n"); + exit(1); + } + if (!fp) { + fprintf(stderr, "Could not open font\n"); + exit(1); + } + fread(data, 1, 1 * 1024 * 1024, fp); + rw = SDL_RWFromMem(data, 1 * 1024 * 1024); + if (!rw) + { + fprintf(stderr, "Could not create RW: %s\n", SDL_GetError()); + exit(1); + } + out = TTF_OpenFontRW(rw, 1, font_size); + if (!out) + { + fprintf(stderr, "Unable to open font %s\n", path); + exit(1); + } + fclose(fp); + + return out; +} + +void font_init() +{ + TTF_Init(); + + menu_font16 = read_font(FONT_PATH, 16); + menu_font20 = read_font(FONT_PATH, 20); + menu_font8 = read_font(FONT_PATH, 8); + menu_font10 = read_font(FONT_PATH, 10); +} + +void menu_init(SDL_Surface *screen) +{ + real_screen = screen; + if (FULL_DISPLAY_X == 640) VirtualKeyboard_init(screen, menu_font16); //prima c'era il font 16 alt + else VirtualKeyboard_init(screen, menu_font8); + is_inited = 1; +} + +int menu_is_inited(void) +{ + return is_inited; +} diff --git a/src/menu_sdl.h b/src/menu_sdl.h index f289e4f..da12ad2 100644 --- a/src/menu_sdl.h +++ b/src/menu_sdl.h @@ -1,68 +1,72 @@ -/********************************************************************* - * Copyright (C) 2012, Fabio Olimpieri - * Copyright (C) 2009, Simon Kagstrom - * - * Filename: menu_sdl.h - * - * Description: Code for menus (originally for Mophun) - * - * This file is part of FBZX Wii - * - * FBZX Wii is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * FBZX Wii is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - ********************************************************************/ - -#ifndef __MENU_H__ -#define __MENU_H__ - -#include -#include - -#define KEY_UP 1 -#define KEY_DOWN 2 -#define KEY_LEFT 4 -#define KEY_RIGHT 8 -#define KEY_SELECT 16 -#define KEY_ESCAPE 32 -#define KEY_PAGEDOWN 64 -#define KEY_PAGEUP 128 -#define KEY_HELP 256 -#define FULL_DISPLAY_X 640 -#define FULL_DISPLAY_Y 480 - - -void menu_print_font(SDL_Surface *screen, int r, int g, int b, int x, int y, const char *msg, int font_size); - - -/* Various option selects */ -int menu_select_title(const char *title, const char **pp_msgs, int *p_submenus); -int menu_select(const char **pp_msgs, int *p_submenus); -const char *menu_select_file(const char *dir_path,const char *selected_file, int which); -const char *menu_select_file_start(const char *dir_path, const char **d64_name); - -uint32_t menu_wait_key_press(void); - -extern void msgKill(SDL_Rect *rc); -extern int msgInfo(char *text, int duration, SDL_Rect *rc); - -extern int msgYesNo(char *text, int def,int x, int y); - -void menu_init(SDL_Surface *screen); - -int menu_is_inited(void); - -int ext_matches(const char *name, const char *ext); - - -#endif /* !__MENU_H__ */ +/********************************************************************* + * Copyright (C) 2012, Fabio Olimpieri + * Copyright (C) 2009, Simon Kagstrom + * + * Filename: menu_sdl.h + * + * Description: Code for menus (originally for Mophun) + * + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + ********************************************************************/ + +#ifndef __MENU_H__ +#define __MENU_H__ + +#include +#include + +#define KEY_UP 1 +#define KEY_DOWN 2 +#define KEY_LEFT 4 +#define KEY_RIGHT 8 +#define KEY_SELECT 16 +#define KEY_ESCAPE 32 +#define KEY_PAGEDOWN 64 +#define KEY_PAGEUP 128 +#define KEY_HELP 256 + +int FULL_DISPLAY_X; //640 +int FULL_DISPLAY_Y; //480 +int RATIO; + + +void menu_print_font(SDL_Surface *screen, int r, int g, int b, int x, int y, const char *msg, int font_size); + + +/* Various option selects */ +int menu_select_title(const char *title, const char **pp_msgs, int *p_submenus); +int menu_select(const char **pp_msgs, int *p_submenus); +const char *menu_select_file(const char *dir_path,const char *selected_file, int which); +const char *menu_select_file_start(const char *dir_path, const char **d64_name); + +uint32_t menu_wait_key_press(void); + +extern void msgKill(SDL_Rect *rc); +extern int msgInfo(char *text, int duration, SDL_Rect *rc); + +extern int msgYesNo(char *text, int def,int x, int y); + +void font_init(); + +void menu_init(SDL_Surface *screen); + +int menu_is_inited(void); + +int ext_matches(const char *name, const char *ext); + + +#endif /* !__MENU_H__ */ diff --git a/src/menus.c b/src/menus.c index 5adcf6d..dca3b09 100644 --- a/src/menus.c +++ b/src/menus.c @@ -1,1990 +1,2018 @@ -/* - * Copyright (C) 2012 Fabio Olimpieri - * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX Wii - * - * FBZX Wii is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * FBZX Wii is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "z80free/Z80free.h" -#include "computer.h" -#include "emulator.h" -#include "cargador.h" -#include -#include -#include -#include -#include -#include -#include -#include "characters.h" -#include "menus.h" -#include "tape.h" -#include - - -// shows the settings menu - -void print_copy(unsigned char *fbuffer,int ancho) { - - print_string(fbuffer,"(C) 2003-2011 Raster Software Vigo",-1,455,13,0,ancho); - -} - -int launch_menu(unsigned int key_pressed) { - - int retval=0; - switch(key_pressed) { - - case SDLK_F2: - snapshots_menu (); // manage snapshot files - retval=1; - break; - - case SDLK_F3: - taps_menu (); // manage TAP files - retval=1; - break; - - case SDLK_F4: // settings - settings_menu (); - retval=1; - break; - - case SDLK_F7: - microdrive_menu (); // shows the microdrive menu - retval=1; - break; - - case SDLK_F8: - tools_menu(); - retval=1; - break; - } - return (retval); -} - -void settings_menu() { - - unsigned char *fbuffer,fin; - unsigned char texto[41]; - int ancho=screen->w; - - fbuffer=screen->pixels; - - fin=1; - - texto[0]=0; - - do { - clean_screen(); - - print_string(fbuffer,"Current settings",-1,20,15,0,ancho); - switch(ordenador.mode128k) { - case 0: - if(ordenador.issue==2) - sprintf(texto,"Mode: 48K issue2"); - else - sprintf(texto,"Mode: 48K issue3"); - break; - case 1: - sprintf(texto,"Mode: Sinclair 128K"); - break; - case 2: - sprintf(texto,"Mode: Amstrad +2"); - break; - case 3: - sprintf(texto,"Mode: Amstrad +2A/+3"); - break; - case 4: - sprintf(texto,"Mode: Spanish 128K"); - break; - } - - print_string(fbuffer,texto,-1,45,14,0,ancho); - - switch(ordenador.joystick[0]) { - case 0: - sprintf(texto,"Joystick emulation: Cursor"); - break; - case 1: - sprintf(texto,"Joystick emulation: Kempston"); - break; - case 2: - sprintf(texto,"Joystick emulation: Sinclair (1)"); - break; - case 3: - sprintf(texto,"Joystick emulation: Sinclair (2)"); - break; - } - print_string(fbuffer,texto,-1,65,13,0,ancho); - - if(ordenador.ay_emul) - sprintf(texto,"AY-3-8912 Emulation: enabled"); - else - sprintf(texto,"AY-3-8912 Emulation: disabled"); - - print_string(fbuffer,texto,-1,85,11,0,ancho); - - if(ordenador.mdr_active) - sprintf(texto,"Interface I Emulation: enabled"); - else - sprintf(texto,"Interface I Emulation: disabled"); - - print_string(fbuffer,texto,-1,105,15,0,ancho); - - if(ordenador.dblscan) - sprintf(texto,"Double scan: enabled"); - else - sprintf(texto,"Double scan: disabled"); - - print_string(fbuffer,texto,-1,125,12,0,ancho); - - if(ordenador.turbo) - sprintf(texto,"TURBO mode: enabled"); - else - sprintf(texto,"TURBO mode: disabled"); - print_string(fbuffer,texto,-1,145,14,0,ancho); - - if (ordenador.bw) { - print_string(fbuffer,"TV Set: \001\011B\001\012&\001\014W",-1,165,15,0,ancho); - } else { - print_string(fbuffer,"TV Set: \001\012C\001\014o\001\015l\001\016o\001\013r",-1,165,15,0,ancho); - } - - print_string(fbuffer,"1:",30,190,12,0,ancho); - print_string(fbuffer,"48K issue2",78,190,15,0,ancho); - - print_string(fbuffer,"2:",350,190,12,0,ancho); - print_string(fbuffer,"48K issue3",398,190,15,0,ancho); - - print_string(fbuffer,"3:",30,220,12,0,ancho); - print_string(fbuffer,"Sinclair 128K",78,220,15,0,ancho); - - print_string(fbuffer,"4:",350,220,12,0,ancho); - print_string(fbuffer,"Amstrad +2",398,220,15,0,ancho); - - print_string(fbuffer,"5:",30,250,12,0,ancho); - print_string(fbuffer,"Amstrad +2A/+3",78,250,15,0,ancho); - - print_string(fbuffer,"6:",350,250,12,0,ancho); - print_string(fbuffer,"Spanish 128K",398,250,15,0,ancho); - - print_string(fbuffer,"7:",30,280,12,0,ancho); - print_string(fbuffer,"Cursor",78,280,15,0,ancho); - - print_string(fbuffer,"8:",350,280,12,0,ancho); - print_string(fbuffer,"Kempston",398,280,15,0,ancho); - - print_string(fbuffer,"9:",30,310,12,0,ancho); - print_string(fbuffer,"Sinclair (1)",78,310,15,0,ancho); - - print_string(fbuffer,"0:",350,310,12,0,ancho); - print_string(fbuffer,"Sinclair (2)",398,310,15,0,ancho); - - print_string(fbuffer,"I:",30,340,12,0,ancho); - print_string(fbuffer,"Interface I",78,340,15,0,ancho); - - print_string(fbuffer,"D:",350,340,12,0,ancho); - print_string(fbuffer,"Double Scan",398,340,15,0,ancho); - - print_string(fbuffer,"A:",350,370,12,0,ancho); - print_string(fbuffer,"AY emulation",398,370,15,0,ancho); - print_string(fbuffer,"T:",30,370,12,0,ancho); - print_string(fbuffer,"TURBO mode",78,370,15,0,ancho); - - print_string(fbuffer,"V:",30,400,12,0,ancho); - print_string(fbuffer,"TV Set mode",78,400,15,0,ancho); - - print_string(fbuffer,"ESC:",168,450,12,0,ancho); - print_string(fbuffer,"return emulator",232,450,15,0,ancho); - - switch(wait_key()) { - case SDLK_ESCAPE: - case SDLK_RETURN: - fin=0; - break; - case SDLK_1: - ordenador.issue=2; - ordenador.mode128k=0; - ordenador.ay_emul=0; - ResetComputer(); - break; - case SDLK_2: - ordenador.issue=3; - ordenador.mode128k=0; - ordenador.ay_emul=0; - ResetComputer(); - break; - case SDLK_3: - ordenador.issue=3; - ordenador.mode128k=1; - ordenador.ay_emul=1; - ResetComputer(); - break; - case SDLK_4: - ordenador.issue=3; - ordenador.mode128k=2; - ordenador.ay_emul=1; - ResetComputer(); - break; - case SDLK_5: - ordenador.issue=3; - ordenador.mode128k=3; - ordenador.ay_emul=1; - ordenador.mdr_active=0; - ResetComputer(); - break; - case SDLK_6: - ordenador.issue=3; - ordenador.mode128k=4; - ordenador.ay_emul=1; - ResetComputer(); - break; - case SDLK_7: - ordenador.joystick[0]=0; - break; - case SDLK_8: - ordenador.joystick[0]=1; - break; - case SDLK_9: - ordenador.joystick[0]=2; - break; - case SDLK_0: - ordenador.joystick[0]=3; - break; - case SDLK_i: - if(ordenador.mode128k!=3) { - ordenador.mdr_active=1-ordenador.mdr_active; - ResetComputer(); - } - break; - case SDLK_d: - ordenador.dblscan=1-ordenador.dblscan; - break; - case SDLK_a: - ordenador.ay_emul=1-ordenador.ay_emul; - break; - case SDLK_v: - ordenador.bw=1-ordenador.bw; - computer_set_palete(); - break; - case SDLK_t: - curr_frames=0; - if(ordenador.turbo){ - ordenador.tst_sample=3500000/ordenador.freq; - ordenador.turbo = 0; - jump_frames=0; - } else { - ordenador.tst_sample=12000000/ordenador.freq; //5,0 MHz max emulation speed for wii at full frames - ordenador.turbo = 1; - jump_frames=3; - } - break; - } - } while(fin); - - clean_screen(); -} - -// shows the help menu - -void help_menu() { - - unsigned char *fbuffer,fin; - int ancho=screen->w; - - fbuffer=screen->pixels; - - clean_screen(); - - print_string(fbuffer,"FBZX Wii (1.0)",-1,20,15,0,ancho); - print_string(fbuffer,"Available keys",-1,50,14,0,ancho); - print_string(fbuffer,"Shift:Caps Shift Ctrl:Symbol Shift",-1,95,11,0,ancho); - - print_string(fbuffer,"F1:",14,160,12,0,ancho); - print_string(fbuffer,"this help",62,160,15,0,ancho); - - print_string(fbuffer,"F2:",336,160,12,0,ancho); - print_string(fbuffer,"manage snapshots",382,160,15,0,ancho); - - print_string(fbuffer,"F3:",14,200,12,0,ancho); - print_string(fbuffer,"manage TAP/TZX",62,200,15,0,ancho); - - print_string(fbuffer,"F4:",336,200,12,0,ancho); - print_string(fbuffer,"change settings",382,200,15,0,ancho); - - print_string(fbuffer,"F5:",14,240,12,0,ancho); - print_string(fbuffer,"stop TAPE",62,240,15,0,ancho); - - print_string(fbuffer,"F6:",336,240,12,0,ancho); - print_string(fbuffer,"play TAPE",382,240,15,0,ancho); - - print_string(fbuffer,"F7:",14,280,12,0,ancho); - print_string(fbuffer,"manage MICRODRIVE",62,280,15,0,ancho); - - print_string(fbuffer,"F8:",336,280,12,0,ancho); - print_string(fbuffer,"tools",382,280,15,0,ancho); - - print_string(fbuffer,"F9:",14,320,12,0,ancho); - print_string(fbuffer,"load",62,320,15,0,ancho); - - print_string(fbuffer,"F10:",336,320,12,0,ancho); - print_string(fbuffer,"reset spectrum",398,320,15,0,ancho); - - print_string(fbuffer,"F11/O:",14,360,12,0,ancho); - print_string(fbuffer,"volume low",110,360,15,0,ancho); - - print_string(fbuffer,"F12/P:",336,360,12,0,ancho); - print_string(fbuffer,"volume up",430,360,15,0,ancho); - - print_string(fbuffer,"ESC:",184,400,12,0,ancho); - print_string(fbuffer,"exit emulator",248,400,15,0,ancho); - - //print_copy(fbuffer,ancho); - - fin=1; - do { - unsigned int key = wait_key(); - switch(key) { - case SDLK_ESCAPE: // to exit the help - fin=0; - break; - default: - if (launch_menu(key)) { - fin=0; - } - break; - } - } while(fin); - clean_screen(); -} - - -// shows the POKE menu - -void do_poke() { - - unsigned char *videomem,string[80]; - int ancho,retorno,address,old_value,new_value; - - videomem=screen->pixels; - ancho=screen->w; - - clean_screen(); - - while(1) { - print_string(videomem,"Type address to POKE",-1,32,15,0,ancho); - print_string(videomem,"(ESC to exit)",-1,52,12,0,ancho); - - retorno=ask_value(&address,84,65535); - - clean_screen(); - - if (retorno==2) { - return; - } - - if ((address<16384) && ((ordenador.mode128k != 3) || (1 != (ordenador.mport2 & 0x01)))) { - print_string(videomem,"That address is ROM memory.",-1,13,15,0,ancho); - continue; - } - - switch (address & 0x0C000) { - case 0x0000: - old_value= (*(ordenador.block0 + address)); - break; - - case 0x4000: - old_value= (*(ordenador.block1 + address)); - break; - - case 0x8000: - old_value= (*(ordenador.block2 + address)); - break; - - case 0xC000: - old_value= (*(ordenador.block3 + address)); - break; - default: - old_value=0; - break; - } - - print_string(videomem,"Type new value to POKE",-1,32,15,0,ancho); - print_string(videomem,"(ESC to cancel)",-1,52,12,0,ancho); - sprintf(string,"Address: %d; old value: %d\n",address,old_value); - print_string(videomem,string,-1,130,14,0,ancho); - - retorno=ask_value(&new_value,84,255); - - clean_screen(); - - if (retorno==2) { - continue; - } - - switch (address & 0x0C000) { - case 0x0000: - (*(ordenador.block0 + address))=new_value; - break; - - case 0x4000: - (*(ordenador.block1 + address))=new_value; - break; - - case 0x8000: - (*(ordenador.block2 + address))=new_value; - break; - - case 0xC000: - (*(ordenador.block3 + address))=new_value; - break; - default: - break; - } - - sprintf(string,"Set address %d from %d to %d\n",address,old_value,new_value); - print_string(videomem,string,-1,130,14,0,ancho); - - } -} - -// shows the tools menu - -void tools_menu() { - - unsigned char *fbuffer,fin; - int ancho=screen->w; - - fbuffer=screen->pixels; - - fin=1; - do { - clean_screen(); - - print_string(fbuffer,"Tools",-1,20,15,0,ancho); - - print_string(fbuffer,"1:",14,60,12,0,ancho); - print_string(fbuffer,"show keyboard template",62,60,15,0,ancho); - - print_string(fbuffer,"2:",14,100,12,0,ancho); - print_string(fbuffer,"insert POKEs",62,100,15,0,ancho); - - print_string(fbuffer,"ESC:",14,250,12,0,ancho); - print_string(fbuffer,"return emulator",78,250,15,0,ancho); - - //print_copy(fbuffer,ancho); - - switch(wait_key()) { - case SDLK_ESCAPE: // to exit the help - fin=0; - break; - case SDLK_1: - fin=0; - keyboard_menu(); - break; - case SDLK_2: - fin=0; - do_poke(); - break; - default: - break; - } - - } while(fin); - - clean_screen(); -} - - - - -// shows the SNAPSHOTS menu - -void snapshots_menu() { - - unsigned char *fbuffer,fin; - int ancho=screen->w; - - fbuffer=screen->pixels; - - clean_screen(); - - print_string(fbuffer,"SNAPSHOTS",-1,30,15,0,ancho); - - print_string(fbuffer,"1:",14,100,12,0,ancho); - print_string(fbuffer,"load a Z80/SNA snapshot",62,100,15,0,ancho); - - if(ordenador.mode128k!=3) { // not in +3 mode - print_string(fbuffer,"2:",14,160,12,0,ancho); - print_string(fbuffer,"make a Z80 snapshot",62,160,15,0,ancho); - } else { - print_string(fbuffer,"Can't make snapshots in +3 mode",14,160,15,0,ancho); - } - - print_string(fbuffer,"3: \001\017load a SCR snapshot",14,220,12,0,ancho); - - print_string(fbuffer,"4: \001\017save a SCR snapshot",14,280,12,0,ancho); - - print_string(fbuffer,"ESC: \001\017return to emulator",-1,400,12,0,ancho); - - //print_copy(fbuffer,ancho); - - fin=1; - do { - switch(wait_key()) { - case SDLK_ESCAPE: // to exit the help - fin=0; - break; - case SDLK_1: - fin=0; - load_z80file(); - break; - case SDLK_2: - fin=0; - if(ordenador.mode128k!=3) // not in +3 mode - save_z80file(); - break; - case SDLK_3: - fin=0; - load_scrfile(); - break; - case SDLK_4: - fin=0; - create_scrfile(); - break; - default: - break; - } - } while(fin); - clean_screen(); -} - - -// shows the TAPs menu - -void taps_menu() { - - unsigned char *fbuffer,fin; - int ancho=screen->w; - - fbuffer=screen->pixels; - - fin=1; - do { - clean_screen(); - - print_string(fbuffer,"TAP/TZX files",-1,20,15,0,ancho); - - print_string(fbuffer,"1:",14,60,12,0,ancho); - print_string(fbuffer,"select a TAP/TZX file",62,60,15,0,ancho); - - - print_string(fbuffer,"2:",14,100,12,0,ancho); - print_string(fbuffer,"rewind TAP/TZX file",62,100,15,0,ancho); - - print_string(fbuffer,"3:",14,140,12,0,ancho); - print_string(fbuffer,"fast/normal speed",62,140,15,0,ancho); - - print_string(fbuffer,"4:",14,180,12,0,ancho); - print_string(fbuffer,"write protection",62,180,15,0,ancho); - - print_string(fbuffer,"5:",14,220,12,0,ancho); - print_string(fbuffer,"create TAP file",62,220,15,0,ancho); - - print_string(fbuffer,"ESC:",14,260,12,0,ancho); - print_string(fbuffer,"return emulator",78,260,15,0,ancho); - - print_string(fbuffer,"Current TAP/TZX file is:",-1,310,12,0,ancho); - print_string(fbuffer,ordenador.current_tap,-1,330,12,0,ancho); - - //print_copy(fbuffer,ancho); - - if(ordenador.tape_fast_load) - print_string(fbuffer,"Fast load enabled ",10,420,14,0,ancho); - else - print_string(fbuffer,"Fast load disabled ",10,420,14,0,ancho); - - if(ordenador.tape_write) - print_string(fbuffer,"Write enabled",390,420,14,0,ancho); - else - print_string(fbuffer,"Write disabled",390,420,14,0,ancho); - - switch(wait_key()) { - case SDLK_ESCAPE: // to exit the help - fin=0; - break; - case SDLK_1: - ordenador.pause=1; - select_tapfile(); - break; - case SDLK_2: - fin=0; - ordenador.pause=1; - if(ordenador.tap_file!=NULL) { - ordenador.tape_current_mode=TAP_TRASH; - rewind_tape(ordenador.tap_file,1); - } - sprintf(ordenador.osd_text,"Tape rewinded"); - ordenador.osd_time=50; - break; - case SDLK_3: - ordenador.pause=1; - ordenador.tape_fast_load=1-ordenador.tape_fast_load; - if(ordenador.tap_file!=NULL) { - ordenador.tape_current_mode=TAP_TRASH; - rewind_tape(ordenador.tap_file,1); - } - break; - case SDLK_4: - ordenador.tape_write=1-ordenador.tape_write; - break; - case SDLK_5: - create_tapfile(); - break; - default: - break; - } - - } while(fin); - - clean_screen(); -} - -// shows a menu to allow user to choose a tape file - -void select_tapfile() { - - unsigned char *videomem,*filename; - int ancho,retorno,retval; - unsigned char char_id[11]; - - videomem=screen->pixels; - ancho=screen->w; - - clean_screen(); - - if(ordenador.tap_file!=NULL) - rewind_tape(ordenador.tap_file,1); - - ordenador.tape_current_bit=0; - ordenador.tape_current_mode=TAP_TRASH; - - print_string(videomem,"Choose the TAPE file to load",-1,32,13,0,ancho); - - filename=select_file(path_taps,FILETYPE_TAP_TZX); - - if(filename==NULL) { // Aborted - clean_screen(); - return; - } - - if(ordenador.tap_file!=NULL) { - fclose(ordenador.tap_file); - } - - if (!strncmp(filename,"smb:",4)) ordenador.tap_file=fopen(filename,"r"); //tinysmb does not work with r+ - else ordenador.tap_file=fopen(filename,"r+"); // read and write - ordenador.tape_write = 0; // by default, can't record - if(ordenador.tap_file==NULL) - retorno=-1; - else - retorno=0; - - clean_screen(); - - strcpy(ordenador.current_tap,filename); - - free(filename); - - switch(retorno) { - case 0: // all right - break; - case -1: - print_string(videomem,"Error: Can't load that file",-1,232,10,0,ancho); - print_string(videomem,"Press any key",-1,248,10,0,ancho); - ordenador.current_tap[0]=0; - wait_key(); - break; - } - - retval=fread(char_id,10,1,ordenador.tap_file); // read the (maybe) TZX header - if((!strncmp(char_id,"ZXTape!",7)) && (char_id[7]==0x1A)&&(char_id[8]==1)) { - ordenador.tape_file_type = TAP_TZX; - rewind_tape(ordenador.tap_file,1); - } else { - ordenador.tape_file_type = TAP_TAP; - rewind_tape(ordenador.tap_file,1); - } - - clean_screen(); -} - -void create_tapfile() { - - unsigned char *videomem; - int ancho,retorno; - unsigned char nombre2[1024]; - - videomem=screen->pixels; - ancho=screen->w; - - clean_screen(); - - print_string(videomem,"Choose a name for the TAP file",-1,32,14,0,ancho); - print_string(videomem,"(up to 30 characters)",-1,52,14,0,ancho); - - print_string(videomem,"TAP file will be saved in:",-1,132,12,0,ancho); - print_string(videomem,path_taps,0,152,12,0,ancho); - - - retorno=ask_filename(nombre2,84,"tap",path_taps,NULL); - - clean_screen(); - - if(retorno==2) // abort - return; - - if(ordenador.tap_file!=NULL) - fclose(ordenador.tap_file); - - ordenador.tap_file=fopen(nombre2,"r"); // test if it exists - if(ordenador.tap_file==NULL) - retorno=0; - else - retorno=-1; - - if(!retorno) { - ordenador.tap_file=fopen(nombre2,"a+"); // create for read and write - if(ordenador.tap_file==NULL) - retorno=-2; - else - retorno=0; - } - ordenador.tape_write=1; // allow to write - strcpy(ordenador.current_tap,nombre2); - ordenador.tape_file_type = TAP_TAP; - switch(retorno) { - case 0: - break; - case -1: - print_string(videomem,"File already exists",-1,80,10,0,ancho); - ordenador.current_tap[0]=0; - wait_key(); - break; - case -2: - print_string(videomem,"Can't create file",-1,80,10,0,ancho); - ordenador.current_tap[0]=0; - wait_key(); - break; - } - clean_screen(); -} - -// shows the microdrive menu - -void microdrive_menu() { - - unsigned char *fbuffer,fin; - int retval,ancho=screen->w; - - fbuffer=screen->pixels; - - fin=1; - do { - clean_screen(); - - print_string(fbuffer,"MICRODRIVE files",-1,20,15,0,ancho); - - print_string(fbuffer,"1:",14,60,12,0,ancho); - print_string(fbuffer,"select a MDR file",62,60,15,0,ancho); - - print_string(fbuffer,"2:",14,100,12,0,ancho); - print_string(fbuffer,"create a MDR file",62,100,15,0,ancho); - - print_string(fbuffer,"3:",14,140,12,0,ancho); - print_string(fbuffer,"write protection",62,140,15,0,ancho); - - print_string(fbuffer,"ESC:",14,180,12,0,ancho); - print_string(fbuffer,"return emulator",78,180,15,0,ancho); - - print_string(fbuffer,"Current MDR file is:",-1,300,12,0,ancho); - print_string(fbuffer,ordenador.mdr_current_mdr,-1,320,12,0,ancho); - - //print_copy(fbuffer,ancho); - - if(!ordenador.mdr_cartridge[137922]) - print_string(fbuffer,"Write enabled",-1,420,14,0,ancho); - else - print_string(fbuffer,"Write disabled",-1,420,14,0,ancho); - - switch(wait_key()) { - case SDLK_ESCAPE: // to exit the help - fin=0; - break; - - case SDLK_1: - select_mdrfile(); - break; - case SDLK_2: - create_mdrfile(); - break; - case SDLK_3: - if(ordenador.mdr_cartridge[137922]) - ordenador.mdr_cartridge[137922]=0; - else - ordenador.mdr_cartridge[137922]=1; - ordenador.mdr_file=fopen(ordenador.mdr_current_mdr,"wb"); // create for write - if(ordenador.mdr_file!=NULL) { - retval=fwrite(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // save cartridge - fclose(ordenador.mdr_file); - ordenador.mdr_file=NULL; - ordenador.mdr_modified=0; - } - break; - default: - break; - } - - } while(fin); - - clean_screen(); -} - -// shows a menu to allow user to choose a microdrive file - -void select_mdrfile() { - - unsigned char *videomem,*filename; - int ancho,retorno,retval; - // unsigned char char_id[11]; - - videomem=screen->pixels; - ancho=screen->w; - - clean_screen(); - - print_string(videomem,"Choose the MICRODRIVE file to load",-1,32,13,0,ancho); - - filename=select_file(path_mdrs,FILETYPE_MDR); // MDR files - - if(filename==NULL) { // Aborted - clean_screen(); - return; - } - - ordenador.mdr_file=fopen(filename,"rb"); // read - if(ordenador.mdr_file==NULL) - retorno=-1; - else { - retorno=0; - retval=fread(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // read the cartridge in memory - ordenador.mdr_modified=0; // not modified - fclose(ordenador.mdr_file); - ordenador.mdr_tapehead=0; - } - - clean_screen(); - - strcpy(ordenador.mdr_current_mdr,filename); - - free(filename); - - switch(retorno) { - case 0: // all right - break; - case -1: - print_string(videomem,"Error: Can't load that file",-1,232,10,0,ancho); - print_string(videomem,"Press any key",-1,248,10,0,ancho); - ordenador.mdr_current_mdr[0]=0; - wait_key(); - break; - } - - clean_screen(); -} - -void create_mdrfile() { - - unsigned char *videomem; - int ancho,retorno,bucle,retval; - unsigned char nombre2[1024]; - - videomem=screen->pixels; - ancho=screen->w; - - clean_screen(); - - print_string(videomem,"Choose a name for the MDR file",-1,32,14,0,ancho); - print_string(videomem,"(up to 30 characters)",-1,52,14,0,ancho); - - print_string(videomem,"MDR file will be saved in:",-1,132,12,0,ancho); - print_string(videomem,path_mdrs,0,152,12,0,ancho); - - retorno=ask_filename(nombre2,84,"mdr",path_mdrs, NULL); - - clean_screen(); - - if(retorno==2) // abort - return; - - ordenador.mdr_file=fopen(nombre2,"r"); // test if it exists - if(ordenador.mdr_file==NULL) - retorno=0; - else - retorno=-1; - - if(!retorno) { - ordenador.mdr_file=fopen(nombre2,"wb"); // create for write - if(ordenador.mdr_file==NULL) - retorno=-2; - else { - for(bucle=0;bucle<137921;bucle++) - ordenador.mdr_cartridge[bucle]=0xFF; // erase cartridge - ordenador.mdr_cartridge[137922]=0; - retval=fwrite(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // save cartridge - fclose(ordenador.mdr_file); - ordenador.mdr_file=NULL; - ordenador.mdr_modified=0; - retorno=0; - } - } - strcpy(ordenador.mdr_current_mdr,nombre2); - switch(retorno) { - case 0: - break; - case -1: - print_string(videomem,"File already exists",-1,80,10,0,ancho); - ordenador.mdr_current_mdr[0]=0; - wait_key(); - break; - case -2: - print_string(videomem,"Can't create file",-1,80,10,0,ancho); - ordenador.mdr_current_mdr[0]=0; - wait_key(); - break; - } - clean_screen(); -} - - -void create_scrfile() { - - unsigned char *videomem; - int ancho,retorno,retval; - unsigned char nombre2[1024]; - FILE *fichero; - char *name; - - videomem=screen->pixels; - ancho=screen->w; - - clean_screen(); - - print_string(videomem,"Choose a name for the SCR file",-1,32,14,0,ancho); - print_string(videomem,"(up to 30 characters)",-1,52,14,0,ancho); - - print_string(videomem,"SCR file will be saved in:",-1,132,12,0,ancho); - print_string(videomem,path_snaps,0,152,12,0,ancho); - - if (strlen(ordenador.current_tap)) - { - name=strrchr(ordenador.current_tap,'/'); - if (name) name++; else name = ordenador.current_tap; - } - else - name=NULL; - - retorno=ask_filename(nombre2,84,"scr",path_snaps, name); - - clean_screen(); - - if(retorno==2) // abort - return; - - fichero=fopen(nombre2,"r"); // test if it exists - if(fichero==NULL) - retorno=0; - else { - fclose(fichero); - retorno=-1; - } - - if(!retorno) { - fichero=fopen(nombre2,"wb"); // create for write - if(fichero==NULL) - retorno=-2; - else { - retval=fwrite(ordenador.block1+0x04000,6912,1,fichero); // save screen - if (ordenador.ulaplus!=0) { - retval=fwrite(ordenador.ulaplus_palete,64,1,fichero); // save ULAPlus palete - } - fclose(fichero); - retorno=0; - } - } - - switch(retorno) { - case -1: - print_string(videomem,"File already exists",-1,80,10,0,ancho); - wait_key(); - break; - case -2: - print_string(videomem,"Can't create file",-1,80,10,0,ancho); - wait_key(); - break; - default: - break; - } - clean_screen(); -} - - -int ask_filename(char *nombre_final,int y_coord,char *extension, char *path, char *name) { - - int longitud,retorno; - unsigned char nombre[37],nombre2[38]; - char *ptr; - - unsigned char *videomem; - int ancho; - - videomem=screen->pixels; - ancho=screen->w; - - retorno=0; - - if (!name||(strlen(name)>36)) - { - nombre[0]=127; - nombre[1]=0; - } - else - { - strcpy(nombre,name); - ptr = strrchr (nombre, '.'); - if (ptr) //remove the extension - { - *ptr = 127; - *(ptr+1) = 0; - } - else - nombre[strlen(nombre)-1]=127; - nombre[strlen(nombre)]=0; - } - - longitud=strlen(nombre)-1; - - - do { - sprintf (nombre2, " %s.%s ", nombre,extension); - print_string (videomem, nombre2, -1, y_coord, 15, 0, ancho); - switch (wait_key ()) { - case SDLK_BACKSPACE: - if (longitud > 0) { - nombre[longitud]=0; - longitud--; - nombre[longitud]=127; - } - break; - case SDLK_ESCAPE: - retorno=2; - break; - case SDLK_RETURN: - retorno=1; - break; - case SDLK_a: - if (longitud < 30) { - nombre[longitud++]='a'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_b: - if (longitud < 30) { - nombre[longitud++]='b'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_c: - if (longitud < 30) { - nombre[longitud++]='c'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_d: - if (longitud < 30) { - nombre[longitud++]='d'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_e: - if (longitud < 30) { - nombre[longitud++]='e'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_f: - if (longitud < 30) { - nombre[longitud++]='f'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_g: - if (longitud < 30) { - nombre[longitud++]='g'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_h: - if (longitud < 30) { - nombre[longitud++]='h'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_i: - if (longitud < 30) { - nombre[longitud++]='i'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_j: - if (longitud < 30) { - nombre[longitud++]='j'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_k: - if (longitud < 30) { - nombre[longitud++]='k'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_l: - if (longitud < 30) { - nombre[longitud++]='l'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_m: - if (longitud < 30) { - nombre[longitud++]='m'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_n: - if (longitud < 30) { - nombre[longitud++]='n'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_o: - if (longitud < 30) { - nombre[longitud++]='o'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_p: - if (longitud < 30) { - nombre[longitud++]='p'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_q: - if (longitud < 30) { - nombre[longitud++]='q'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_r: - if (longitud < 30) { - nombre[longitud++]='r'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_s: - if (longitud < 30) { - nombre[longitud++]='s'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_t: - if (longitud < 30) { - nombre[longitud++]='t'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_u: - if (longitud < 30) { - nombre[longitud++]='u'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_v: - if (longitud < 30) { - nombre[longitud++]='v'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_w: - if (longitud < 30) { - nombre[longitud++]='w'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_x: - if (longitud < 30) { - nombre[longitud++]='x'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_y: - if (longitud < 30) { - nombre[longitud++]='y'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_z: - if (longitud < 30) { - nombre[longitud++]='z'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_0: - if (longitud < 30) { - nombre[longitud++]='0'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_1: - if (longitud < 30) { - nombre[longitud++]='1'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_2: - if (longitud < 30) { - nombre[longitud++]='2'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_3: - if (longitud < 30) { - nombre[longitud++]='3'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_4: - if (longitud < 30) { - nombre[longitud++]='4'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_5: - if (longitud < 30) { - nombre[longitud++]='5'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_6: - if (longitud < 30) { - nombre[longitud++]='6'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_7: - if (longitud < 30) { - nombre[longitud++]='7'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_8: - if (longitud < 30) { - nombre[longitud++]='8'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_9: - if (longitud < 30) { - nombre[longitud++]='9'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - case SDLK_MINUS: - if (longitud < 30) { - nombre[longitud++]='-'; - nombre[longitud]=127; - nombre[longitud + 1]=0; - } - break; - } - } while (!retorno); - - nombre[longitud]=0; // erase cursor - - longitud=strlen(path); - if((path[longitud-1]!='/')&&(longitud>1)) - sprintf(nombre_final,"%s/%s.%s",path,nombre,extension); // name - else - sprintf(nombre_final,"%s%s.%s",path,nombre,extension); - - return (retorno); -} - - - - -int ask_value(int *final_value,int y_coord,int max_value) { - - unsigned char nombre2[50]; - unsigned char *videomem; - int ancho,value,tmp,retorno; - - videomem=screen->pixels; - ancho=screen->w; - - retorno=0; - value=0; - do { - sprintf (nombre2, " %d\177 ", value); - print_string (videomem, nombre2, -1, y_coord, 15, 0, ancho); - switch (wait_key ()) { - case SDLK_BACKSPACE: - value/=10; - break; - case SDLK_ESCAPE: - retorno=2; - break; - case SDLK_RETURN: - retorno=1; - break; - case SDLK_0: - tmp=value * 10; - if (tmp <= max_value) { - value=tmp; - } - break; - case SDLK_1: - tmp=1+value * 10; - if (tmp <= max_value) { - value=tmp; - } - break; - case SDLK_2: - tmp=2+value * 10; - if (tmp <= max_value) { - value=tmp; - } - break; - case SDLK_3: - tmp=3+value * 10; - if (tmp <= max_value) { - value=tmp; - } - break; - case SDLK_4: - tmp=4+value * 10; - if (tmp <= max_value) { - value=tmp; - } - break; - case SDLK_5: - tmp=5+value * 10; - if (tmp <= max_value) { - value=tmp; - } - break; - case SDLK_6: - tmp=6+value * 10; - if (tmp <= max_value) { - value=tmp; - } - break; - case SDLK_7: - tmp=7+value * 10; - if (tmp <= max_value) { - value=tmp; - } - break; - case SDLK_8: - tmp=8+value * 10; - if (tmp <= max_value) { - value=tmp; - } - break; - case SDLK_9: - tmp=9+value * 10; - if (tmp <= max_value) { - value=tmp; - } - break; - } - } while (!retorno); - - *final_value=value; - - return (retorno); -} - - - - -// shows a menu to allow user to save a snapshot file - -void save_z80file() { - - unsigned char *videomem; - int ancho,retorno; - unsigned char nombre2[1024]; - char *name; - - videomem=screen->pixels; - ancho=screen->w; - - clean_screen(); - - print_string(videomem,"Choose a name for the Z80 snapshot",-1,32,14,0,ancho); - print_string(videomem,"(up to 30 characters)",-1,52,14,0,ancho); - - print_string(videomem,"Snapshot will be saved in:",-1,132,12,0,ancho); - print_string(videomem,path_snaps,0,152,12,0,ancho); - - if (strlen(ordenador.current_tap)) - { - name=strrchr(ordenador.current_tap,'/'); - if (name) name++; else name = ordenador.current_tap; - } - else - name=NULL; - - retorno=ask_filename(nombre2,84,"z80", path_snaps, name); - - clean_screen(); - - if(retorno==2) // abort - return; - - retorno=save_z80(nombre2,0); - switch(retorno) { - case 0: - break; - case -1: - print_string(videomem,"File already exists",-1,80,10,0,ancho); - wait_key(); - break; - case -2: - print_string(videomem,"Can't create file",-1,80,10,0,ancho); - wait_key(); - break; - } - clean_screen(); -} - -// shows a menu to allow user to load a snapshot file - -void load_z80file() { - - - unsigned char *videomem,*filename; - int ancho,retorno; - - videomem=screen->pixels; - ancho=screen->w; - - clean_screen(); - - print_string(videomem,"Choose the Z80 snapshot file to load",-1,32,13,0,ancho); - - filename=select_file(path_snaps,FILETYPE_Z80); - - if(filename==NULL) { // Aborted - clean_screen(); - return; - } - - retorno=load_z80(filename); - free(filename); - clean_screen(); - - switch(retorno) { - case 0: // all right - break; - case -1: - print_string(videomem,"Error: Can't load that file",-1,232,10,0,ancho); - print_string(videomem,"Press any key",-1,248,10,0,ancho); - wait_key(); - break; - case -2: - case -3: - print_string(videomem,"Error: unsuported snap file",-1,232,10,0,ancho); - print_string(videomem,"Press any key",-1,248,10,0,ancho); - wait_key(); - break; - } - clean_screen(); -} - - -void load_scrfile() { - - - unsigned char *videomem,*filename,value; - int ancho,retorno,loop; - FILE *fichero; - unsigned char paleta_tmp[64]; - - videomem=screen->pixels; - ancho=screen->w; - - clean_screen(); - - print_string(videomem,"Choose the SCR snapshot file to load",-1,32,13,0,ancho); - - filename=select_file(path_snaps,FILETYPE_SCR); - - if(filename==NULL) { // Aborted - clean_screen(); - return; - } - - ordenador.osd_text[0]=0; - fichero=fopen(filename,"rb"); - retorno=0; - if (!fichero) { - retorno=-1; - } else { - for(loop=0;loop<6912;loop++) { - if (1==fread(&value,1,1,fichero)) { - *(ordenador.block1 + 0x04000 + loop) = value; - } else { - retorno=-1; - break; - } - } - if (1==fread(paleta_tmp,64,1,fichero)) { - memcpy(ordenador.ulaplus_palete,paleta_tmp,64); - ordenador.ulaplus=1; - } else { - ordenador.ulaplus=0; - } - fclose(fichero); - } - - free(filename); - clean_screen(); - - switch(retorno) { - case 0: // all right - break; - default: - print_string(videomem,"Error: Can't load that file",-1,232,10,0,ancho); - print_string(videomem,"Press any key",-1,248,10,0,ancho); - wait_key(); - break; - } - clean_screen(); -} - - - -/* fills a FICHERO chained list with all the files and directories contained in PATH. - If KIND is 0, it returns only Snapshots, if is 1, it returns only TAPE files, and - if is 2, it returns only MDR files */ - -struct fichero *read_directory(char *cpath,enum LOAD_FILE_TYPES kind) { - - struct fichero *listhead,*listend; - struct dirent *entry; - DIR *directory; - struct stat estado; - unsigned char path[2049],fichero[2049],extension[5],found; - int bucle,length; - - strcpy(path,cpath); - if('/'!=path[strlen(path)-1]) - strcat(path,"/"); // add the final / to the path - - listhead=malloc(sizeof(struct fichero)); - strcpy(listhead->nombre,".."); - listhead->tipo=2; - listhead->next=NULL; - listend=listhead; - - directory=opendir(path); - if(directory==NULL) - return(listhead); // can't access the directory - - do { - entry=readdir(directory); - if((NULL!=entry)&&(strcmp(entry->d_name,"."))&&(strcmp(entry->d_name,".."))) { - strcpy(fichero,path); - strcat(fichero,entry->d_name); - stat(fichero,&estado); - found=0; // by default is not a valid file... - length=strlen(entry->d_name); - if(length>3) { - extension[4]=0; - for(bucle=0;bucle<4;bucle++) - extension[bucle]=entry->d_name[length-4+bucle]; // copy the 4 last chars of the file (the extension) - switch(kind) { - case FILETYPE_Z80: - if((!strcasecmp(extension,".z80"))||(!strcasecmp(extension,".sna"))) - found=1; // is a .z80 or SNA file - break; - case FILETYPE_TAP_TZX: - if((!strcasecmp(extension,".tap"))||(!strcasecmp(extension,".tzx"))) - found=1; // is a .tap file - break; - case FILETYPE_MDR: - if(!strcasecmp(extension,".mdr")) - found=1; // is a .mdr file - break; - case FILETYPE_SCR: - if(!strcasecmp(extension,".scr")) - found=1; // is a .mdr file - break; - default: - break; - } - } else - found=0; - if(((found)||(S_ISDIR(estado.st_mode)))&&('.'!=entry->d_name[0])) { // is a directory. We must add it - listend->next=malloc(sizeof(struct fichero)); - listend=listend->next; - listend->next=NULL; - strcpy(listend->nombrepath,fichero); - strcpy(listend->nombre,entry->d_name); - if(S_ISDIR(estado.st_mode)) - listend->tipo=1; // a directory - else - listend->tipo=0; // a file - } - } - } while(entry!=NULL); - closedir(directory); - return(listhead); -} - -// deletes a filelist tree, freeing the memory used by it - -void delete_filelist(struct fichero *filelist) { - - struct fichero *fl1,*fl2; - - fl1=fl2=filelist; - - while(fl1!=NULL) { - fl2=fl1->next; - free(fl1); - fl1=fl2; - } -} - - -/* allows user to choose a file from PATH. If KIND=0, only snapshots. If KIND=1, only - TAPE files */ - -char *select_file(char *path,enum LOAD_FILE_TYPES kind) { - - struct fichero *filelist,*fl2; - unsigned char fin,read,*salida; - int bucle,ancho,numitems,selected,from,longitud; - - salida=(unsigned char *)malloc(2049); - salida[0]=0; - - ancho=screen->w; - - fin=1; - read=1; - selected=0; - from=0; - numitems=0; - - filelist=NULL; - - do { - - if(read) { - filelist=read_directory(path,kind); - read=0; - - fl2=filelist; - numitems=0; - while(fl2!=NULL) { // counts the number of items - fl2=fl2->next; - numitems++; - } - selected=0; - from=0; - } - - print_files(filelist,from,selected); - - switch(wait_key()) { - case SDLK_ESCAPE: // to exit the help - fin=0; - break; - case SDLK_UP: - if(selected>0) { - selected--; - if(selected(from+23)) // 23 is the total of items that can be displayed - from++; - } - break; - case SDLK_PAGEUP: - for(bucle=0;bucle<15;bucle++) - if(selected>0) { - selected--; - if(selected(from+23)) // 23 is the total of items that can be displayed - from++; - } - break; - case SDLK_RETURN: - fl2=filelist; - if(selected!=0) - for(bucle=0;buclenext; - switch(fl2->tipo) { - case 0: // select file - strcpy(salida,fl2->nombrepath); - delete_filelist(filelist); - return(salida); // ends returning the filename - break; - case 1: // change directory - strcpy(path,fl2->nombrepath); // new path_taps is namepath - delete_filelist(filelist); // frees the memory - read=1; // and redisplay all the files - break; - case 2: // upper directory - longitud=strlen(path); - if(longitud<2) // there's no upper directory - break; - if('/'==path[longitud-1]) { // is the char ended in '/' ? - path[longitud-1]=0; // eliminated - longitud--; - } - while('/'!=path[longitud-1]) { - longitud--; - path[longitud]=0; - } - if(longitud>2) { // it's not the upper directory - longitud--; - path[longitud]=0; // delete the final '/' - } - read=1; - break; - default: - break; - } - break; - default: - break; - } - } while(fin); - - delete_filelist(filelist); - return(NULL); - -} - -void keyboard_menu() { - - FILE *fichero; - int bucle1,bucle2,retval; - unsigned char *buffer,*buffer2,valor; - - buffer=screen->pixels; - - clean_screen(); - fichero=myfopen("fbzx/keymap.bmp","r"); - if (fichero==NULL) { - strcpy(ordenador.osd_text,"Keymap picture not found"); - ordenador.osd_time=100; - return; - } - if (ordenador.zaurus_mini==0) { - for (bucle1=0;bucle1<344;bucle1++) - for(bucle2=0;bucle2<640;bucle2++) { - retval=fscanf(fichero,"%c",&valor); - paint_one_pixel((unsigned char *)(colors+valor),buffer); - buffer+=ordenador.bpp; - } - } else { - buffer+=(479*ordenador.bpp); - for(bucle1=0;bucle1<344;bucle1++) { - buffer2=buffer; - for(bucle2=0;bucle2<640;bucle2++) { - retval=fscanf(fichero,"%c",&valor); - paint_one_pixel((unsigned char *)(colors+valor),buffer); - buffer+=(480*ordenador.bpp); - } - buffer=buffer2-ordenador.bpp; - } - } - //print_copy(screen->pixels,screen->w); - wait_key(); - clean_screen(); -} - -void clean_screen() { - - int bucle; - unsigned char *buffer; - - buffer=screen->pixels; - - for(bucle=0;bucle<((screen->h)*(screen->w)*(ordenador.bpp));bucle++) - *(buffer++)=0; - -} - -// waits for a keystroke and returns its value - -unsigned int wait_key() { - - char fin; - unsigned int temporal_io=0; - SDL_Event evento; - - fin=1; - - do { - SDL_Flip(ordenador.screen); - if(!SDL_WaitEvent(&evento)) - continue; - - if(evento.type!=SDL_KEYUP) - continue; - - fin=0; - - temporal_io=(unsigned int)evento.key.keysym.sym; - } while(fin); - - return (temporal_io); -} - -// shows the files from the number FROM, and marks the file number MARK - -void print_files(struct fichero *filelist,int from,int mark) { - - struct fichero *fl2; - int bucle,numitems,ancho,pos; - char ink1,ink2; - unsigned char spaces[39]=" "; - unsigned char namefile[2089]; - unsigned char *videomem; - - videomem=screen->pixels; - ancho=screen->w; - - fl2=filelist; - numitems=0; - - while(fl2!=NULL) { // counts the number of items - fl2=fl2->next; - numitems++; - } - - ink1=ink2=0; - - fl2=filelist; - pos=72; - for(bucle=0;bucle=from) { - strcpy(namefile,fl2->nombre); - strcat(namefile,spaces); - namefile[36]=0; // we print up to 36 chars - switch(fl2->tipo) { - case 0: // file - ink1=15; - ink2=0; - break; - case 1: // directory - ink1=12; - ink2=4; - break; - case 2: // parent directory - ink1=10; - ink2=2; - break; - } - if(bucle==mark) - print_string(videomem,namefile,-1,pos,ink2,15,ancho); - else - print_string(videomem,namefile,-1,pos,ink1,0,ancho); - pos+=16; - } - if((pos+16)>460) - break; // reached bottom part of the rectangle - fl2=fl2->next; - } - while((pos+16<460)) { - print_string(videomem,spaces,-1,pos,0,0,ancho); - pos+=16; - } -} +/* + * Copyright (C) 2012 Fabio Olimpieri + * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "z80free/Z80free.h" +#include "computer.h" +#include "emulator.h" +#include "cargador.h" +#include +#include +#include +#include +#include +#include +#include +#include "characters.h" +#include "menus.h" +#include "tape.h" +#include + + +// shows the settings menu + +void print_copy(unsigned char *fbuffer,int ancho) { + + print_string(fbuffer,"(C) 2003-2011 Raster Software Vigo",-1,455,13,0,ancho); + +} + +int launch_menu(unsigned int key_pressed) { + + int retval=0; + switch(key_pressed) { + + case SDLK_F2: + snapshots_menu (); // manage snapshot files + retval=1; + break; + + case SDLK_F3: + taps_menu (); // manage TAP files + retval=1; + break; + + case SDLK_F4: // settings + settings_menu (); + retval=1; + break; + + case SDLK_F7: + microdrive_menu (); // shows the microdrive menu + retval=1; + break; + + case SDLK_F8: + tools_menu(); + retval=1; + break; + } + return (retval); +} + +void settings_menu() { + + unsigned char *fbuffer,fin; + unsigned char texto[41]; + int ancho=screen->w; + + fbuffer=screen->pixels; + + fin=1; + + texto[0]=0; + + do { + clean_screen(); + + print_string(fbuffer,"Current settings",-1,20,15,0,ancho); + switch(ordenador.mode128k) { + case 0: + if(ordenador.issue==2) + sprintf(texto,"Mode: 48K issue2"); + else + sprintf(texto,"Mode: 48K issue3"); + break; + case 1: + sprintf(texto,"Mode: Sinclair 128K"); + break; + case 2: + sprintf(texto,"Mode: Amstrad +2"); + break; + case 3: + sprintf(texto,"Mode: Amstrad +2A/+3"); + break; + case 4: + sprintf(texto,"Mode: Spanish 128K"); + break; + } + + print_string(fbuffer,texto,-1,45,14,0,ancho); + + switch(ordenador.joystick[0]) { + case 0: + sprintf(texto,"Joystick emulation: Cursor"); + break; + case 1: + sprintf(texto,"Joystick emulation: Kempston"); + break; + case 2: + sprintf(texto,"Joystick emulation: Sinclair (1)"); + break; + case 3: + sprintf(texto,"Joystick emulation: Sinclair (2)"); + break; + } + print_string(fbuffer,texto,-1,65,13,0,ancho); + + if(ordenador.ay_emul) + sprintf(texto,"AY-3-8912 Emulation: enabled"); + else + sprintf(texto,"AY-3-8912 Emulation: disabled"); + + print_string(fbuffer,texto,-1,85,11,0,ancho); + + if(ordenador.mdr_active) + sprintf(texto,"Interface I Emulation: enabled"); + else + sprintf(texto,"Interface I Emulation: disabled"); + + print_string(fbuffer,texto,-1,105,15,0,ancho); + + if(ordenador.dblscan) + sprintf(texto,"Double scan: enabled"); + else + sprintf(texto,"Double scan: disabled"); + + print_string(fbuffer,texto,-1,125,12,0,ancho); + + if(ordenador.turbo) + sprintf(texto,"TURBO mode: enabled"); + else + sprintf(texto,"TURBO mode: disabled"); + print_string(fbuffer,texto,-1,145,14,0,ancho); + + if (ordenador.bw) { + print_string(fbuffer,"TV Set: \001\011B\001\012&\001\014W",-1,165,15,0,ancho); + } else { + print_string(fbuffer,"TV Set: \001\012C\001\014o\001\015l\001\016o\001\013r",-1,165,15,0,ancho); + } + + print_string(fbuffer,"1:",30,190,12,0,ancho); + print_string(fbuffer,"48K issue2",78,190,15,0,ancho); + + print_string(fbuffer,"2:",350,190,12,0,ancho); + print_string(fbuffer,"48K issue3",398,190,15,0,ancho); + + print_string(fbuffer,"3:",30,220,12,0,ancho); + print_string(fbuffer,"Sinclair 128K",78,220,15,0,ancho); + + print_string(fbuffer,"4:",350,220,12,0,ancho); + print_string(fbuffer,"Amstrad +2",398,220,15,0,ancho); + + print_string(fbuffer,"5:",30,250,12,0,ancho); + print_string(fbuffer,"Amstrad +2A/+3",78,250,15,0,ancho); + + print_string(fbuffer,"6:",350,250,12,0,ancho); + print_string(fbuffer,"Spanish 128K",398,250,15,0,ancho); + + print_string(fbuffer,"7:",30,280,12,0,ancho); + print_string(fbuffer,"Cursor",78,280,15,0,ancho); + + print_string(fbuffer,"8:",350,280,12,0,ancho); + print_string(fbuffer,"Kempston",398,280,15,0,ancho); + + print_string(fbuffer,"9:",30,310,12,0,ancho); + print_string(fbuffer,"Sinclair (1)",78,310,15,0,ancho); + + print_string(fbuffer,"0:",350,310,12,0,ancho); + print_string(fbuffer,"Sinclair (2)",398,310,15,0,ancho); + + print_string(fbuffer,"I:",30,340,12,0,ancho); + print_string(fbuffer,"Interface I",78,340,15,0,ancho); + + print_string(fbuffer,"D:",350,340,12,0,ancho); + print_string(fbuffer,"Double Scan",398,340,15,0,ancho); + + print_string(fbuffer,"A:",350,370,12,0,ancho); + print_string(fbuffer,"AY emulation",398,370,15,0,ancho); + print_string(fbuffer,"T:",30,370,12,0,ancho); + print_string(fbuffer,"TURBO mode",78,370,15,0,ancho); + + print_string(fbuffer,"V:",30,400,12,0,ancho); + print_string(fbuffer,"TV Set mode",78,400,15,0,ancho); + + print_string(fbuffer,"ESC:",168,450,12,0,ancho); + print_string(fbuffer,"return emulator",232,450,15,0,ancho); + + switch(wait_key()) { + case SDLK_ESCAPE: + case SDLK_RETURN: + fin=0; + break; + case SDLK_1: + ordenador.issue=2; + ordenador.mode128k=0; + ordenador.ay_emul=0; + ResetComputer(); + break; + case SDLK_2: + ordenador.issue=3; + ordenador.mode128k=0; + ordenador.ay_emul=0; + ResetComputer(); + break; + case SDLK_3: + ordenador.issue=3; + ordenador.mode128k=1; + ordenador.ay_emul=1; + ordenador.videosystem=0; + ResetComputer(); + break; + case SDLK_4: + ordenador.issue=3; + ordenador.mode128k=2; + ordenador.ay_emul=1; + ordenador.videosystem=0; + ResetComputer(); + break; + case SDLK_5: + ordenador.issue=3; + ordenador.mode128k=3; + ordenador.ay_emul=1; + ordenador.videosystem=0; + ordenador.mdr_active=0; + ResetComputer(); + break; + case SDLK_6: + ordenador.issue=3; + ordenador.mode128k=4; + ordenador.ay_emul=1; + ordenador.videosystem=0; + ResetComputer(); + break; + case SDLK_7: + ordenador.joystick[0]=0; + break; + case SDLK_8: + ordenador.joystick[0]=1; + break; + case SDLK_9: + ordenador.joystick[0]=2; + break; + case SDLK_0: + ordenador.joystick[0]=3; + break; + case SDLK_i: + if(ordenador.mode128k!=3) { + ordenador.mdr_active=1-ordenador.mdr_active; + ResetComputer(); + } + break; + case SDLK_d: + ordenador.dblscan=1-ordenador.dblscan; + break; + case SDLK_a: + ordenador.ay_emul=1-ordenador.ay_emul; + break; + case SDLK_v: + ordenador.bw=1-ordenador.bw; + computer_set_palete(); + break; + case SDLK_t: + curr_frames=0; + if(ordenador.turbo){ + update_frequency(0); //set machine frequency + ordenador.turbo = 0; + jump_frames=0; + } else { + update_frequency(10000000); //5,0 MHz max emulation speed for wii at full frames + ordenador.turbo = 1; + jump_frames=4; + } + break; + } + } while(fin); + + clean_screen(); +} + +// shows the help menu + +void help_menu() { + + unsigned char *fbuffer,fin; + int ancho=screen->w; + + fbuffer=screen->pixels; + + clean_screen(); + + print_string(fbuffer,"FBZX Wii (1.0)",-1,20,15,0,ancho); + print_string(fbuffer,"Available keys",-1,50,14,0,ancho); + print_string(fbuffer,"Shift:Caps Shift Ctrl:Symbol Shift",-1,95,11,0,ancho); + + print_string(fbuffer,"F1:",14,160,12,0,ancho); + print_string(fbuffer,"this help",62,160,15,0,ancho); + + print_string(fbuffer,"F2:",336,160,12,0,ancho); + print_string(fbuffer,"manage snapshots",382,160,15,0,ancho); + + print_string(fbuffer,"F3:",14,200,12,0,ancho); + print_string(fbuffer,"manage TAP/TZX",62,200,15,0,ancho); + + print_string(fbuffer,"F4:",336,200,12,0,ancho); + print_string(fbuffer,"change settings",382,200,15,0,ancho); + + print_string(fbuffer,"F5:",14,240,12,0,ancho); + print_string(fbuffer,"stop TAPE",62,240,15,0,ancho); + + print_string(fbuffer,"F6:",336,240,12,0,ancho); + print_string(fbuffer,"play TAPE",382,240,15,0,ancho); + + print_string(fbuffer,"F7:",14,280,12,0,ancho); + print_string(fbuffer,"manage MICRODRIVE",62,280,15,0,ancho); + + print_string(fbuffer,"F8:",336,280,12,0,ancho); + print_string(fbuffer,"tools",382,280,15,0,ancho); + + print_string(fbuffer,"F9:",14,320,12,0,ancho); + print_string(fbuffer,"load",62,320,15,0,ancho); + + print_string(fbuffer,"F10:",336,320,12,0,ancho); + print_string(fbuffer,"reset spectrum",398,320,15,0,ancho); + + print_string(fbuffer,"F11/O:",14,360,12,0,ancho); + print_string(fbuffer,"volume low",110,360,15,0,ancho); + + print_string(fbuffer,"F12/P:",336,360,12,0,ancho); + print_string(fbuffer,"volume up",430,360,15,0,ancho); + + print_string(fbuffer,"ESC:",184,400,12,0,ancho); + print_string(fbuffer,"exit emulator",248,400,15,0,ancho); + + //print_copy(fbuffer,ancho); + + fin=1; + do { + unsigned int key = wait_key(); + switch(key) { + case SDLK_ESCAPE: // to exit the help + fin=0; + break; + default: + if (launch_menu(key)) { + fin=0; + } + break; + } + } while(fin); + clean_screen(); +} + + +// shows the POKE menu + +void do_poke() { + + unsigned char *videomem,string[80]; + int ancho,retorno,address,old_value,new_value; + + videomem=screen->pixels; + ancho=screen->w; + + clean_screen(); + + while(1) { + print_string(videomem,"Type address to POKE",-1,32,15,0,ancho); + print_string(videomem,"(ESC to exit)",-1,52,12,0,ancho); + + retorno=ask_value(&address,84,65535); + + clean_screen(); + + if (retorno==2) { + return; + } + + if ((address<16384) && ((ordenador.mode128k != 3) || (1 != (ordenador.mport2 & 0x01)))) { + print_string(videomem,"That address is ROM memory.",-1,13,15,0,ancho); + continue; + } + + switch (address & 0x0C000) { + case 0x0000: + old_value= (*(ordenador.block0 + address)); + break; + + case 0x4000: + old_value= (*(ordenador.block1 + address)); + break; + + case 0x8000: + old_value= (*(ordenador.block2 + address)); + break; + + case 0xC000: + old_value= (*(ordenador.block3 + address)); + break; + default: + old_value=0; + break; + } + + print_string(videomem,"Type new value to POKE",-1,32,15,0,ancho); + print_string(videomem,"(ESC to cancel)",-1,52,12,0,ancho); + sprintf(string,"Address: %d; old value: %d\n",address,old_value); + print_string(videomem,string,-1,130,14,0,ancho); + + retorno=ask_value(&new_value,84,255); + + clean_screen(); + + if (retorno==2) { + continue; + } + + switch (address & 0x0C000) { + case 0x0000: + (*(ordenador.block0 + address))=new_value; + break; + + case 0x4000: + (*(ordenador.block1 + address))=new_value; + break; + + case 0x8000: + (*(ordenador.block2 + address))=new_value; + break; + + case 0xC000: + (*(ordenador.block3 + address))=new_value; + break; + default: + break; + } + + sprintf(string,"Set address %d from %d to %d\n",address,old_value,new_value); + print_string(videomem,string,-1,130,14,0,ancho); + + } +} + +// shows the tools menu + +void tools_menu() { + + unsigned char *fbuffer,fin; + int ancho=screen->w; + + fbuffer=screen->pixels; + + fin=1; + do { + clean_screen(); + + print_string(fbuffer,"Tools",-1,20,15,0,ancho); + + print_string(fbuffer,"1:",14,60,12,0,ancho); + print_string(fbuffer,"show keyboard template",62,60,15,0,ancho); + + print_string(fbuffer,"2:",14,100,12,0,ancho); + print_string(fbuffer,"insert POKEs",62,100,15,0,ancho); + + print_string(fbuffer,"ESC:",14,250,12,0,ancho); + print_string(fbuffer,"return emulator",78,250,15,0,ancho); + + //print_copy(fbuffer,ancho); + + switch(wait_key()) { + case SDLK_ESCAPE: // to exit the help + fin=0; + break; + case SDLK_1: + fin=0; + keyboard_menu(); + break; + case SDLK_2: + fin=0; + do_poke(); + break; + default: + break; + } + + } while(fin); + + clean_screen(); +} + + + + +// shows the SNAPSHOTS menu + +void snapshots_menu() { + + unsigned char *fbuffer,fin; + int ancho=screen->w; + + fbuffer=screen->pixels; + + clean_screen(); + + print_string(fbuffer,"SNAPSHOTS",-1,30,15,0,ancho); + + print_string(fbuffer,"1:",14,100,12,0,ancho); + print_string(fbuffer,"load a Z80/SNA snapshot",62,100,15,0,ancho); + + if(ordenador.mode128k!=3) { // not in +3 mode + print_string(fbuffer,"2:",14,160,12,0,ancho); + print_string(fbuffer,"make a Z80 snapshot",62,160,15,0,ancho); + } else { + print_string(fbuffer,"Can't make snapshots in +3 mode",14,160,15,0,ancho); + } + + print_string(fbuffer,"3: \001\017load a SCR snapshot",14,220,12,0,ancho); + + print_string(fbuffer,"4: \001\017save a SCR snapshot",14,280,12,0,ancho); + + print_string(fbuffer,"ESC: \001\017return to emulator",-1,400,12,0,ancho); + + //print_copy(fbuffer,ancho); + + fin=1; + do { + switch(wait_key()) { + case SDLK_ESCAPE: // to exit the help + fin=0; + break; + case SDLK_1: + fin=0; + load_z80file(); + break; + case SDLK_2: + fin=0; + if(ordenador.mode128k!=3) // not in +3 mode + save_z80file(); + break; + case SDLK_3: + fin=0; + load_scrfile(); + break; + case SDLK_4: + fin=0; + create_scrfile(); + break; + default: + break; + } + } while(fin); + clean_screen(); +} + + +// shows the TAPs menu + +void taps_menu() { + + unsigned char *fbuffer,fin; + int ancho=screen->w; + + fbuffer=screen->pixels; + + fin=1; + do { + clean_screen(); + + print_string(fbuffer,"TAP/TZX files",-1,20,15,0,ancho); + + print_string(fbuffer,"1:",14,60,12,0,ancho); + print_string(fbuffer,"select a TAP/TZX file",62,60,15,0,ancho); + + + print_string(fbuffer,"2:",14,100,12,0,ancho); + print_string(fbuffer,"rewind TAP/TZX file",62,100,15,0,ancho); + + print_string(fbuffer,"3:",14,140,12,0,ancho); + print_string(fbuffer,"fast/normal speed",62,140,15,0,ancho); + + print_string(fbuffer,"4:",14,180,12,0,ancho); + print_string(fbuffer,"write protection",62,180,15,0,ancho); + + print_string(fbuffer,"5:",14,220,12,0,ancho); + print_string(fbuffer,"create TAP file",62,220,15,0,ancho); + + print_string(fbuffer,"ESC:",14,260,12,0,ancho); + print_string(fbuffer,"return emulator",78,260,15,0,ancho); + + print_string(fbuffer,"Current TAP/TZX file is:",-1,310,12,0,ancho); + print_string(fbuffer,ordenador.current_tap,-1,330,12,0,ancho); + + //print_copy(fbuffer,ancho); + + if(ordenador.tape_fast_load) + print_string(fbuffer,"Fast load enabled ",10,420,14,0,ancho); + else + print_string(fbuffer,"Fast load disabled ",10,420,14,0,ancho); + + if(ordenador.tape_write) + print_string(fbuffer,"Write enabled",390,420,14,0,ancho); + else + print_string(fbuffer,"Write disabled",390,420,14,0,ancho); + + switch(wait_key()) { + case SDLK_ESCAPE: // to exit the help + fin=0; + break; + case SDLK_1: + ordenador.pause=1; + select_tapfile(); + break; + case SDLK_2: + fin=0; + ordenador.pause=1; + if(ordenador.tap_file!=NULL) { + ordenador.tape_current_mode=TAP_TRASH; + rewind_tape(ordenador.tap_file,1); + } + sprintf(ordenador.osd_text,"Tape rewinded"); + ordenador.osd_time=50; + break; + case SDLK_3: + ordenador.pause=1; + ordenador.tape_fast_load=1-ordenador.tape_fast_load; + if(ordenador.tap_file!=NULL) { + ordenador.tape_current_mode=TAP_TRASH; + rewind_tape(ordenador.tap_file,1); + } + break; + case SDLK_4: + ordenador.tape_write=1-ordenador.tape_write; + break; + case SDLK_5: + create_tapfile(); + break; + default: + break; + } + + } while(fin); + + clean_screen(); +} + +// shows a menu to allow user to choose a tape file + +void select_tapfile() { + + unsigned char *videomem,*filename; + int ancho,retorno,retval; + unsigned char char_id[11]; + + videomem=screen->pixels; + ancho=screen->w; + + clean_screen(); + + if(ordenador.tap_file!=NULL) + rewind_tape(ordenador.tap_file,1); + + ordenador.tape_current_bit=0; + ordenador.tape_current_mode=TAP_TRASH; + + print_string(videomem,"Choose the TAPE file to load",-1,32,13,0,ancho); + + filename=select_file(path_taps,FILETYPE_TAP_TZX); + + if(filename==NULL) { // Aborted + clean_screen(); + return; + } + + if(ordenador.tap_file!=NULL) { + fclose(ordenador.tap_file); + } + + if (!strncmp(filename,"smb:",4)) ordenador.tap_file=fopen(filename,"r"); //tinysmb does not work with r+ + else ordenador.tap_file=fopen(filename,"r+"); // read and write + ordenador.tape_write = 0; // by default, can't record + if(ordenador.tap_file==NULL) + retorno=-1; + else + retorno=0; + + clean_screen(); + + strcpy(ordenador.current_tap,filename); + + free(filename); + + switch(retorno) { + case 0: // all right + break; + case -1: + print_string(videomem,"Error: Can't load that file",-1,232,10,0,ancho); + print_string(videomem,"Press any key",-1,248,10,0,ancho); + ordenador.current_tap[0]=0; + wait_key(); + break; + } + + retval=fread(char_id,10,1,ordenador.tap_file); // read the (maybe) TZX header + if((!strncmp(char_id,"ZXTape!",7)) && (char_id[7]==0x1A)&&(char_id[8]==1)) { + ordenador.tape_file_type = TAP_TZX; + rewind_tape(ordenador.tap_file,1); + } else { + ordenador.tape_file_type = TAP_TAP; + rewind_tape(ordenador.tap_file,1); + } + + clean_screen(); +} + +void create_tapfile() { + + unsigned char *videomem; + int ancho,retorno; + unsigned char nombre2[1024]; + + videomem=screen->pixels; + ancho=screen->w; + + clean_screen(); + + print_string(videomem,"Choose a name for the TAP file",-1,32,14,0,ancho); + print_string(videomem,"(up to 30 characters)",-1,52,14,0,ancho); + + print_string(videomem,"TAP file will be saved in:",-1,132,12,0,ancho); + print_string(videomem,path_taps,0,152,12,0,ancho); + + + retorno=ask_filename(nombre2,84,"tap",path_taps,NULL); + + clean_screen(); + + if(retorno==2) // abort + return; + + if(ordenador.tap_file!=NULL) + fclose(ordenador.tap_file); + + ordenador.tap_file=fopen(nombre2,"r"); // test if it exists + if(ordenador.tap_file==NULL) + retorno=0; + else + retorno=-1; + + if(!retorno) { + ordenador.tap_file=fopen(nombre2,"a+"); // create for read and write + if(ordenador.tap_file==NULL) + retorno=-2; + else + retorno=0; + } + ordenador.tape_write=1; // allow to write + strcpy(ordenador.current_tap,nombre2); + ordenador.tape_file_type = TAP_TAP; + switch(retorno) { + case 0: + break; + case -1: + print_string(videomem,"File already exists",-1,80,10,0,ancho); + ordenador.current_tap[0]=0; + wait_key(); + break; + case -2: + print_string(videomem,"Can't create file",-1,80,10,0,ancho); + ordenador.current_tap[0]=0; + wait_key(); + break; + } + clean_screen(); +} + +// shows the microdrive menu + +void microdrive_menu() { + + unsigned char *fbuffer,fin; + int retval,ancho=screen->w; + + fbuffer=screen->pixels; + + fin=1; + do { + clean_screen(); + + print_string(fbuffer,"MICRODRIVE files",-1,20,15,0,ancho); + + print_string(fbuffer,"1:",14,60,12,0,ancho); + print_string(fbuffer,"select a MDR file",62,60,15,0,ancho); + + print_string(fbuffer,"2:",14,100,12,0,ancho); + print_string(fbuffer,"create a MDR file",62,100,15,0,ancho); + + print_string(fbuffer,"3:",14,140,12,0,ancho); + print_string(fbuffer,"write protection",62,140,15,0,ancho); + + print_string(fbuffer,"ESC:",14,180,12,0,ancho); + print_string(fbuffer,"return emulator",78,180,15,0,ancho); + + print_string(fbuffer,"Current MDR file is:",-1,300,12,0,ancho); + print_string(fbuffer,ordenador.mdr_current_mdr,-1,320,12,0,ancho); + + //print_copy(fbuffer,ancho); + + if(!ordenador.mdr_cartridge[137922]) + print_string(fbuffer,"Write enabled",-1,420,14,0,ancho); + else + print_string(fbuffer,"Write disabled",-1,420,14,0,ancho); + + switch(wait_key()) { + case SDLK_ESCAPE: // to exit the help + fin=0; + break; + + case SDLK_1: + select_mdrfile(); + break; + case SDLK_2: + create_mdrfile(); + break; + case SDLK_3: + if(ordenador.mdr_cartridge[137922]) + ordenador.mdr_cartridge[137922]=0; + else + ordenador.mdr_cartridge[137922]=1; + ordenador.mdr_file=fopen(ordenador.mdr_current_mdr,"wb"); // create for write + if(ordenador.mdr_file!=NULL) { + retval=fwrite(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // save cartridge + fclose(ordenador.mdr_file); + ordenador.mdr_file=NULL; + ordenador.mdr_modified=0; + } + break; + default: + break; + } + + } while(fin); + + clean_screen(); +} + +// shows a menu to allow user to choose a microdrive file + +void select_mdrfile() { + + unsigned char *videomem,*filename; + int ancho,retorno,retval; + // unsigned char char_id[11]; + + videomem=screen->pixels; + ancho=screen->w; + + clean_screen(); + + print_string(videomem,"Choose the MICRODRIVE file to load",-1,32,13,0,ancho); + + filename=select_file(path_mdrs,FILETYPE_MDR); // MDR files + + if(filename==NULL) { // Aborted + clean_screen(); + return; + } + + ordenador.mdr_file=fopen(filename,"rb"); // read + if(ordenador.mdr_file==NULL) + retorno=-1; + else { + retorno=0; + retval=fread(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // read the cartridge in memory + ordenador.mdr_modified=0; // not modified + fclose(ordenador.mdr_file); + ordenador.mdr_tapehead=0; + } + + clean_screen(); + + strcpy(ordenador.mdr_current_mdr,filename); + + free(filename); + + switch(retorno) { + case 0: // all right + break; + case -1: + print_string(videomem,"Error: Can't load that file",-1,232,10,0,ancho); + print_string(videomem,"Press any key",-1,248,10,0,ancho); + ordenador.mdr_current_mdr[0]=0; + wait_key(); + break; + } + + clean_screen(); +} + +void create_mdrfile() { + + unsigned char *videomem; + int ancho,retorno,bucle,retval; + unsigned char nombre2[1024]; + + videomem=screen->pixels; + ancho=screen->w; + + clean_screen(); + + print_string(videomem,"Choose a name for the MDR file",-1,32,14,0,ancho); + print_string(videomem,"(up to 30 characters)",-1,52,14,0,ancho); + + print_string(videomem,"MDR file will be saved in:",-1,132,12,0,ancho); + print_string(videomem,path_mdrs,0,152,12,0,ancho); + + retorno=ask_filename(nombre2,84,"mdr",path_mdrs, NULL); + + clean_screen(); + + if(retorno==2) // abort + return; + + ordenador.mdr_file=fopen(nombre2,"r"); // test if it exists + if(ordenador.mdr_file==NULL) + retorno=0; + else + retorno=-1; + + if(!retorno) { + ordenador.mdr_file=fopen(nombre2,"wb"); // create for write + if(ordenador.mdr_file==NULL) + retorno=-2; + else { + for(bucle=0;bucle<137921;bucle++) + ordenador.mdr_cartridge[bucle]=0xFF; // erase cartridge + ordenador.mdr_cartridge[137922]=0; + retval=fwrite(ordenador.mdr_cartridge,137923,1,ordenador.mdr_file); // save cartridge + fclose(ordenador.mdr_file); + ordenador.mdr_file=NULL; + ordenador.mdr_modified=0; + retorno=0; + } + } + strcpy(ordenador.mdr_current_mdr,nombre2); + switch(retorno) { + case 0: + break; + case -1: + print_string(videomem,"File already exists",-1,80,10,0,ancho); + ordenador.mdr_current_mdr[0]=0; + wait_key(); + break; + case -2: + print_string(videomem,"Can't create file",-1,80,10,0,ancho); + ordenador.mdr_current_mdr[0]=0; + wait_key(); + break; + } + clean_screen(); +} + + +void create_scrfile() { + + unsigned char *videomem; + int ancho,retorno,retval; + unsigned char nombre2[1024]; + FILE *fichero; + char *name; + + videomem=screen->pixels; + ancho=screen->w; + + clean_screen(); + + print_string(videomem,"Choose a name for the SCR file",-1,32,14,0,ancho); + print_string(videomem,"(up to 30 characters)",-1,52,14,0,ancho); + + print_string(videomem,"SCR file will be saved in:",-1,132,12,0,ancho); + print_string(videomem,path_snaps,0,152,12,0,ancho); + + if (strlen(ordenador.current_tap)) + { + name=strrchr(ordenador.current_tap,'/'); + if (name) name++; else name = ordenador.current_tap; + } + else + name=NULL; + + retorno=ask_filename(nombre2,84,"scr",path_snaps, name); + + clean_screen(); + + if(retorno==2) // abort + return; + + fichero=fopen(nombre2,"r"); // test if it exists + if(fichero==NULL) + retorno=0; + else { + fclose(fichero); + retorno=-1; + } + + if(!retorno) { + fichero=fopen(nombre2,"wb"); // create for write + if(fichero==NULL) + retorno=-2; + else { + retval=fwrite(ordenador.block1+0x04000,6912,1,fichero); // save screen + if (ordenador.ulaplus!=0) { + retval=fwrite(ordenador.ulaplus_palete,64,1,fichero); // save ULAPlus palete + } + fclose(fichero); + retorno=0; + } + } + + switch(retorno) { + case -1: + print_string(videomem,"File already exists",-1,80,10,0,ancho); + wait_key(); + break; + case -2: + print_string(videomem,"Can't create file",-1,80,10,0,ancho); + wait_key(); + break; + default: + break; + } + clean_screen(); +} + + +int ask_filename(char *nombre_final,int y_coord,char *extension, char *path, char *name) { + + int longitud,retorno; + unsigned char nombre[37],nombre2[38]; + char *ptr; + + unsigned char *videomem; + int ancho; + + videomem=screen->pixels; + ancho=screen->w; + + retorno=0; + + if (!name||(strlen(name)>36)) + { + nombre[0]=127; + nombre[1]=0; + } + else + { + strcpy(nombre,name); + ptr = strrchr (nombre, '.'); + if (ptr) //remove the extension + { + *ptr = 127; + *(ptr+1) = 0; + } + else + nombre[strlen(nombre)-1]=127; + nombre[strlen(nombre)]=0; + } + + longitud=strlen(nombre)-1; + + + do { + sprintf (nombre2, " %s.%s ", nombre,extension); + print_string (videomem, nombre2, -1, y_coord, 15, 0, ancho); + switch (wait_key ()) { + case SDLK_BACKSPACE: + if (longitud > 0) { + nombre[longitud]=0; + longitud--; + nombre[longitud]=127; + } + break; + case SDLK_ESCAPE: + retorno=2; + break; + case SDLK_RETURN: + retorno=1; + break; + case SDLK_a: + if (longitud < 30) { + nombre[longitud++]='a'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_b: + if (longitud < 30) { + nombre[longitud++]='b'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_c: + if (longitud < 30) { + nombre[longitud++]='c'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_d: + if (longitud < 30) { + nombre[longitud++]='d'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_e: + if (longitud < 30) { + nombre[longitud++]='e'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_f: + if (longitud < 30) { + nombre[longitud++]='f'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_g: + if (longitud < 30) { + nombre[longitud++]='g'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_h: + if (longitud < 30) { + nombre[longitud++]='h'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_i: + if (longitud < 30) { + nombre[longitud++]='i'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_j: + if (longitud < 30) { + nombre[longitud++]='j'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_k: + if (longitud < 30) { + nombre[longitud++]='k'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_l: + if (longitud < 30) { + nombre[longitud++]='l'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_m: + if (longitud < 30) { + nombre[longitud++]='m'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_n: + if (longitud < 30) { + nombre[longitud++]='n'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_o: + if (longitud < 30) { + nombre[longitud++]='o'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_p: + if (longitud < 30) { + nombre[longitud++]='p'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_q: + if (longitud < 30) { + nombre[longitud++]='q'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_r: + if (longitud < 30) { + nombre[longitud++]='r'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_s: + if (longitud < 30) { + nombre[longitud++]='s'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_t: + if (longitud < 30) { + nombre[longitud++]='t'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_u: + if (longitud < 30) { + nombre[longitud++]='u'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_v: + if (longitud < 30) { + nombre[longitud++]='v'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_w: + if (longitud < 30) { + nombre[longitud++]='w'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_x: + if (longitud < 30) { + nombre[longitud++]='x'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_y: + if (longitud < 30) { + nombre[longitud++]='y'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_z: + if (longitud < 30) { + nombre[longitud++]='z'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_0: + if (longitud < 30) { + nombre[longitud++]='0'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_1: + if (longitud < 30) { + nombre[longitud++]='1'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_2: + if (longitud < 30) { + nombre[longitud++]='2'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_3: + if (longitud < 30) { + nombre[longitud++]='3'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_4: + if (longitud < 30) { + nombre[longitud++]='4'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_5: + if (longitud < 30) { + nombre[longitud++]='5'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_6: + if (longitud < 30) { + nombre[longitud++]='6'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_7: + if (longitud < 30) { + nombre[longitud++]='7'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_8: + if (longitud < 30) { + nombre[longitud++]='8'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_9: + if (longitud < 30) { + nombre[longitud++]='9'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + case SDLK_MINUS: + if (longitud < 30) { + nombre[longitud++]='-'; + nombre[longitud]=127; + nombre[longitud + 1]=0; + } + break; + } + } while (!retorno); + + nombre[longitud]=0; // erase cursor + + longitud=strlen(path); + if((path[longitud-1]!='/')&&(longitud>1)) + sprintf(nombre_final,"%s/%s.%s",path,nombre,extension); // name + else + sprintf(nombre_final,"%s%s.%s",path,nombre,extension); + + return (retorno); +} + + + + +int ask_value(int *final_value,int y_coord,int max_value) { + + unsigned char nombre2[50]; + unsigned char *videomem; + int ancho,value,tmp,retorno; + + videomem=screen->pixels; + ancho=screen->w; + + retorno=0; + value=0; + do { + sprintf (nombre2, " %d\177 ", value); + print_string (videomem, nombre2, -1, y_coord, 15, 0, ancho); + switch (wait_key ()) { + case SDLK_BACKSPACE: + value/=10; + break; + case SDLK_ESCAPE: + retorno=2; + break; + case SDLK_RETURN: + retorno=1; + break; + case SDLK_0: + tmp=value * 10; + if (tmp <= max_value) { + value=tmp; + } + break; + case SDLK_1: + tmp=1+value * 10; + if (tmp <= max_value) { + value=tmp; + } + break; + case SDLK_2: + tmp=2+value * 10; + if (tmp <= max_value) { + value=tmp; + } + break; + case SDLK_3: + tmp=3+value * 10; + if (tmp <= max_value) { + value=tmp; + } + break; + case SDLK_4: + tmp=4+value * 10; + if (tmp <= max_value) { + value=tmp; + } + break; + case SDLK_5: + tmp=5+value * 10; + if (tmp <= max_value) { + value=tmp; + } + break; + case SDLK_6: + tmp=6+value * 10; + if (tmp <= max_value) { + value=tmp; + } + break; + case SDLK_7: + tmp=7+value * 10; + if (tmp <= max_value) { + value=tmp; + } + break; + case SDLK_8: + tmp=8+value * 10; + if (tmp <= max_value) { + value=tmp; + } + break; + case SDLK_9: + tmp=9+value * 10; + if (tmp <= max_value) { + value=tmp; + } + break; + } + } while (!retorno); + + *final_value=value; + + return (retorno); +} + + + + +// shows a menu to allow user to save a snapshot file + +void save_z80file() { + + unsigned char *videomem; + int ancho,retorno; + unsigned char nombre2[1024]; + char *name; + + videomem=screen->pixels; + ancho=screen->w; + + clean_screen(); + + print_string(videomem,"Choose a name for the Z80 snapshot",-1,32,14,0,ancho); + print_string(videomem,"(up to 30 characters)",-1,52,14,0,ancho); + + print_string(videomem,"Snapshot will be saved in:",-1,132,12,0,ancho); + print_string(videomem,path_snaps,0,152,12,0,ancho); + + if (strlen(ordenador.current_tap)) + { + name=strrchr(ordenador.current_tap,'/'); + if (name) name++; else name = ordenador.current_tap; + } + else + name=NULL; + + retorno=ask_filename(nombre2,84,"z80", path_snaps, name); + + clean_screen(); + + if(retorno==2) // abort + return; + + retorno=save_z80(nombre2,0); + switch(retorno) { + case 0: + break; + case -1: + print_string(videomem,"File already exists",-1,80,10,0,ancho); + wait_key(); + break; + case -2: + print_string(videomem,"Can't create file",-1,80,10,0,ancho); + wait_key(); + break; + } + clean_screen(); +} + +// shows a menu to allow user to load a snapshot file + +void load_z80file() { + + + unsigned char *videomem,*filename; + int ancho,retorno; + + videomem=screen->pixels; + ancho=screen->w; + + clean_screen(); + + print_string(videomem,"Choose the Z80 snapshot file to load",-1,32,13,0,ancho); + + filename=select_file(path_snaps,FILETYPE_Z80); + + if(filename==NULL) { // Aborted + clean_screen(); + return; + } + + retorno=load_z80(filename); + free(filename); + clean_screen(); + + switch(retorno) { + case 0: // all right + break; + case -1: + print_string(videomem,"Error: Can't load that file",-1,232,10,0,ancho); + print_string(videomem,"Press any key",-1,248,10,0,ancho); + wait_key(); + break; + case -2: + case -3: + print_string(videomem,"Error: unsuported snap file",-1,232,10,0,ancho); + print_string(videomem,"Press any key",-1,248,10,0,ancho); + wait_key(); + break; + } + clean_screen(); +} + + +void load_scrfile() { + + + unsigned char *videomem,*filename,value; + int ancho,retorno,loop; + FILE *fichero; + unsigned char paleta_tmp[64]; + + videomem=screen->pixels; + ancho=screen->w; + + clean_screen(); + + print_string(videomem,"Choose the SCR snapshot file to load",-1,32,13,0,ancho); + + filename=select_file(path_snaps,FILETYPE_SCR); + + if(filename==NULL) { // Aborted + clean_screen(); + return; + } + + ordenador.osd_text[0]=0; + fichero=fopen(filename,"rb"); + retorno=0; + if (!fichero) { + retorno=-1; + } else { + for(loop=0;loop<6912;loop++) { + if (1==fread(&value,1,1,fichero)) { + *(ordenador.block1 + 0x04000 + loop) = value; + } else { + retorno=-1; + break; + } + } + if (1==fread(paleta_tmp,64,1,fichero)) { + memcpy(ordenador.ulaplus_palete,paleta_tmp,64); + ordenador.ulaplus=1; + } else { + ordenador.ulaplus=0; + } + fclose(fichero); + } + + free(filename); + clean_screen(); + + switch(retorno) { + case 0: // all right + break; + default: + print_string(videomem,"Error: Can't load that file",-1,232,10,0,ancho); + print_string(videomem,"Press any key",-1,248,10,0,ancho); + wait_key(); + break; + } + clean_screen(); +} + + + +/* fills a FICHERO chained list with all the files and directories contained in PATH. + If KIND is 0, it returns only Snapshots, if is 1, it returns only TAPE files, and + if is 2, it returns only MDR files */ + +struct fichero *read_directory(char *cpath,enum LOAD_FILE_TYPES kind) { + + struct fichero *listhead,*listend; + struct dirent *entry; + DIR *directory; + struct stat estado; + unsigned char path[2049],fichero[2049],extension[5],found; + int bucle,length; + + strcpy(path,cpath); + if('/'!=path[strlen(path)-1]) + strcat(path,"/"); // add the final / to the path + + listhead=malloc(sizeof(struct fichero)); + strcpy(listhead->nombre,".."); + listhead->tipo=2; + listhead->next=NULL; + listend=listhead; + + directory=opendir(path); + if(directory==NULL) + return(listhead); // can't access the directory + + do { + entry=readdir(directory); + if((NULL!=entry)&&(strcmp(entry->d_name,"."))&&(strcmp(entry->d_name,".."))) { + strcpy(fichero,path); + strcat(fichero,entry->d_name); + stat(fichero,&estado); + found=0; // by default is not a valid file... + length=strlen(entry->d_name); + if(length>3) { + extension[4]=0; + for(bucle=0;bucle<4;bucle++) + extension[bucle]=entry->d_name[length-4+bucle]; // copy the 4 last chars of the file (the extension) + switch(kind) { + case FILETYPE_Z80: + if((!strcasecmp(extension,".z80"))||(!strcasecmp(extension,".sna"))) + found=1; // is a .z80 or SNA file + break; + case FILETYPE_TAP_TZX: + if((!strcasecmp(extension,".tap"))||(!strcasecmp(extension,".tzx"))) + found=1; // is a .tap file + break; + case FILETYPE_MDR: + if(!strcasecmp(extension,".mdr")) + found=1; // is a .mdr file + break; + case FILETYPE_SCR: + if(!strcasecmp(extension,".scr")) + found=1; // is a .mdr file + break; + default: + break; + } + } else + found=0; + if(((found)||(S_ISDIR(estado.st_mode)))&&('.'!=entry->d_name[0])) { // is a directory. We must add it + listend->next=malloc(sizeof(struct fichero)); + listend=listend->next; + listend->next=NULL; + strcpy(listend->nombrepath,fichero); + strcpy(listend->nombre,entry->d_name); + if(S_ISDIR(estado.st_mode)) + listend->tipo=1; // a directory + else + listend->tipo=0; // a file + } + } + } while(entry!=NULL); + closedir(directory); + return(listhead); +} + +// deletes a filelist tree, freeing the memory used by it + +void delete_filelist(struct fichero *filelist) { + + struct fichero *fl1,*fl2; + + fl1=fl2=filelist; + + while(fl1!=NULL) { + fl2=fl1->next; + free(fl1); + fl1=fl2; + } +} + + +/* allows user to choose a file from PATH. If KIND=0, only snapshots. If KIND=1, only + TAPE files */ + +char *select_file(char *path,enum LOAD_FILE_TYPES kind) { + + struct fichero *filelist,*fl2; + unsigned char fin,read,*salida; + int bucle,ancho,numitems,selected,from,longitud; + + salida=(unsigned char *)malloc(2049); + salida[0]=0; + + ancho=screen->w; + + fin=1; + read=1; + selected=0; + from=0; + numitems=0; + + filelist=NULL; + + do { + + if(read) { + filelist=read_directory(path,kind); + read=0; + + fl2=filelist; + numitems=0; + while(fl2!=NULL) { // counts the number of items + fl2=fl2->next; + numitems++; + } + selected=0; + from=0; + } + + print_files(filelist,from,selected); + + switch(wait_key()) { + case SDLK_ESCAPE: // to exit the help + fin=0; + break; + case SDLK_UP: + if(selected>0) { + selected--; + if(selected(from+23)) // 23 is the total of items that can be displayed + from++; + } + break; + case SDLK_PAGEUP: + for(bucle=0;bucle<15;bucle++) + if(selected>0) { + selected--; + if(selected(from+23)) // 23 is the total of items that can be displayed + from++; + } + break; + case SDLK_RETURN: + fl2=filelist; + if(selected!=0) + for(bucle=0;buclenext; + switch(fl2->tipo) { + case 0: // select file + strcpy(salida,fl2->nombrepath); + delete_filelist(filelist); + return(salida); // ends returning the filename + break; + case 1: // change directory + strcpy(path,fl2->nombrepath); // new path_taps is namepath + delete_filelist(filelist); // frees the memory + read=1; // and redisplay all the files + break; + case 2: // upper directory + longitud=strlen(path); + if(longitud<2) // there's no upper directory + break; + if('/'==path[longitud-1]) { // is the char ended in '/' ? + path[longitud-1]=0; // eliminated + longitud--; + } + while('/'!=path[longitud-1]) { + longitud--; + path[longitud]=0; + } + if(longitud>2) { // it's not the upper directory + longitud--; + path[longitud]=0; // delete the final '/' + } + read=1; + break; + default: + break; + } + break; + default: + break; + } + } while(fin); + + delete_filelist(filelist); + return(NULL); + +} + +void keyboard_menu() { + + FILE *fichero; + int bucle1,bucle2,retval; + unsigned char *buffer,*buffer2,valor; + + buffer=screen->pixels; + + clean_screen(); + fichero=myfopen("fbzx/keymap.bmp","r"); + if (fichero==NULL) { + strcpy(ordenador.osd_text,"Keymap picture not found"); + ordenador.osd_time=100; + return; + } + if (ordenador.zaurus_mini==0) { + for (bucle1=0;bucle1<344;bucle1++) + for(bucle2=0;bucle2<640;bucle2++) { + retval=fscanf(fichero,"%c",&valor); + paint_one_pixel((unsigned char *)(colors+valor),buffer); + buffer+=ordenador.bpp; + } + } else { + buffer+=(479*ordenador.bpp); + for(bucle1=0;bucle1<344;bucle1++) { + buffer2=buffer; + for(bucle2=0;bucle2<640;bucle2++) { + retval=fscanf(fichero,"%c",&valor); + paint_one_pixel((unsigned char *)(colors+valor),buffer); + buffer+=(480*ordenador.bpp); + } + buffer=buffer2-ordenador.bpp; + } + } + //print_copy(screen->pixels,screen->w); + wait_key(); + clean_screen(); +} + +void clean_screen() { + + int bucle; + unsigned char *buffer; + + buffer=screen->pixels; + + for(bucle=0;bucle<((screen->h)*(screen->w)*(ordenador.bpp));bucle++) + *(buffer++)=0; + +} + +// waits for a keystroke and returns its value + +unsigned int wait_key() { + + char fin; + unsigned int temporal_io=0; + SDL_Event evento; + + fin=1; + + do { + SDL_Flip(ordenador.screen); + if(!SDL_WaitEvent(&evento)) + continue; + + if(evento.type!=SDL_KEYUP) + continue; + + fin=0; + + temporal_io=(unsigned int)evento.key.keysym.sym; + } while(fin); + + return (temporal_io); +} + +// shows the files from the number FROM, and marks the file number MARK + +void print_files(struct fichero *filelist,int from,int mark) { + + struct fichero *fl2; + int bucle,numitems,ancho,pos; + char ink1,ink2; + unsigned char spaces[39]=" "; + unsigned char namefile[2089]; + unsigned char *videomem; + + videomem=screen->pixels; + ancho=screen->w; + + fl2=filelist; + numitems=0; + + while(fl2!=NULL) { // counts the number of items + fl2=fl2->next; + numitems++; + } + + ink1=ink2=0; + + fl2=filelist; + pos=72; + for(bucle=0;bucle=from) { + strcpy(namefile,fl2->nombre); + strcat(namefile,spaces); + namefile[36]=0; // we print up to 36 chars + switch(fl2->tipo) { + case 0: // file + ink1=15; + ink2=0; + break; + case 1: // directory + ink1=12; + ink2=4; + break; + case 2: // parent directory + ink1=10; + ink2=2; + break; + } + if(bucle==mark) + print_string(videomem,namefile,-1,pos,ink2,15,ancho); + else + print_string(videomem,namefile,-1,pos,ink1,0,ancho); + pos+=16; + } + if((pos+16)>460) + break; // reached bottom part of the rectangle + fl2=fl2->next; + } + while((pos+16<460)) { + print_string(videomem,spaces,-1,pos,0,0,ancho); + pos+=16; + } +} + +void update_frequency (int freq) +{ +if (freq == 0) + switch (ordenador.mode128k) { + case 0: // 48K + if (ordenador.videosystem==0) ordenador.cpufreq = 3500000; + else ordenador.cpufreq = 3527500; + break; + case 3: // +2A/+3 + case 1: // 128K + case 2: // +2 + case 4: // spanish 128K + ordenador.cpufreq = 3546900; + break; + default: + ordenador.cpufreq = 3500000; + break; + } +else ordenador.cpufreq = freq; + +ordenador.tst_sample=ordenador.cpufreq/ordenador.freq; + +} \ No newline at end of file diff --git a/src/menus.h b/src/menus.h index fb39403..84f6560 100644 --- a/src/menus.h +++ b/src/menus.h @@ -1,54 +1,55 @@ -/* - * Copyright (C) 2012 Fabio Olimpieri - * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX Wii - * - * FBZX Wii is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * FBZX Wii is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -struct fichero { - char nombre[256]; // filename (for files and directories) - char nombrepath[2049]; // filename with path - int tipo; // file type (0=file, 1=directory, 2=parent directory) - struct fichero *next; -}; - -enum LOAD_FILE_TYPES {FILETYPE_Z80, FILETYPE_TAP_TZX, FILETYPE_MDR, FILETYPE_SCR}; - -void clean_screen(); -void help_menu(); -void load_z80file(); -char *select_file(char *,enum LOAD_FILE_TYPES); -struct fichero *read_directory(char *,enum LOAD_FILE_TYPES); -unsigned int wait_key(); -void print_files(struct fichero *,int,int); -void delete_filelist(struct fichero *); -void select_tapfile(); -void save_z80file(); -void settings_menu(); -void snapshots_menu(); -void taps_menu(); -void create_tapfile(); -void select_mdrfile(); -void create_mdrfile(); -void microdrive_menu(); -void keyboard_menu(); -void load_scrfile(); -int ask_filename(char *nombre,int y_coord,char *extension, char *path, char *name); -void create_scrfile(); -void do_poke(); -int ask_value(int *final_value,int y_coord,int max_value); -void tools_menu(); -int launch_menu(unsigned int key_pressed); +/* + * Copyright (C) 2012 Fabio Olimpieri + * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +struct fichero { + char nombre[256]; // filename (for files and directories) + char nombrepath[2049]; // filename with path + int tipo; // file type (0=file, 1=directory, 2=parent directory) + struct fichero *next; +}; + +enum LOAD_FILE_TYPES {FILETYPE_Z80, FILETYPE_TAP_TZX, FILETYPE_MDR, FILETYPE_SCR}; + +void clean_screen(); +void help_menu(); +void load_z80file(); +char *select_file(char *,enum LOAD_FILE_TYPES); +struct fichero *read_directory(char *,enum LOAD_FILE_TYPES); +unsigned int wait_key(); +void print_files(struct fichero *,int,int); +void delete_filelist(struct fichero *); +void select_tapfile(); +void save_z80file(); +void settings_menu(); +void snapshots_menu(); +void taps_menu(); +void create_tapfile(); +void select_mdrfile(); +void create_mdrfile(); +void microdrive_menu(); +void keyboard_menu(); +void load_scrfile(); +int ask_filename(char *nombre,int y_coord,char *extension, char *path, char *name); +void create_scrfile(); +void do_poke(); +int ask_value(int *final_value,int y_coord,int max_value); +void tools_menu(); +int launch_menu(unsigned int key_pressed); +void update_frequency (int freq); diff --git a/src/tape.c b/src/tape.c index b3b3cfa..746008b 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1,772 +1,772 @@ -/* - * Copyright (C) 2012 Fabio Olimpieri - * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX Wii - * - * FBZX Wii is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * FBZX Wii is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "z80free/Z80free.h" -#include "computer.h" -#include "emulator.h" -#include "menus.h" -#include "tape.h" - -int elcontador=0; -int eltstado=0; -char elbit=0; - -/* reads a tape file and updates the readed bit */ - -inline void tape_read(FILE *fichero, int tstados) { - - if(ordenador.pause) - return; - - if(ordenador.tape_file_type == TAP_TAP) - tape_read_tap(fichero,tstados); - else - tape_read_tzx(fichero,tstados); - -} - -// manages TAP files in REAL_MODE - -inline void tape_read_tap (FILE * fichero, int tstados) { - - static unsigned char value, value2; - int retval; - - if (fichero == NULL) - return; - - if (!ordenador.pause) { - if (ordenador.tape_current_mode == TAP_TRASH) { // initialize a new block - retval=fread (&value, 1, 1, fichero); - retval=fread (&value2, 1, 1, fichero); // read block longitude - if (feof (fichero)) { - rewind_tape(fichero,1); - ordenador.tape_current_mode = TAP_TRASH; - return; - } - ordenador.tape_byte_counter = ((unsigned int) value) + 256 * ((unsigned int) value2); - retval=fread (&(ordenador.tape_byte), 1, 1, fichero); - ordenador.tape_bit = 0x80; - ordenador.tape_current_mode = TAP_GUIDE; - ordenador.tape_counter0 = 2168; - ordenador.tape_counter1 = 2168; - if (!(0x80 & ordenador.tape_byte)) - ordenador.tape_counter_rep = 3228; // 4 seconds - else - ordenador.tape_counter_rep = 1614; // 2 seconds - } - - // if there's a pulse still being reproduce, just reproduce it - - if (ordenador.tape_counter0) { - if (ordenador.tape_counter0 > tstados) { - ordenador.tape_readed = 0; // return 0 - ordenador.tape_counter0 -= tstados; // decrement counter; - return; - } else { - tstados -= ordenador.tape_counter0; - ordenador.tape_counter0 = 0; - } - } - - ordenador.tape_readed = 1; // return 1 - if (ordenador.tape_counter1) { - if (ordenador.tape_counter1 > tstados) { - ordenador.tape_counter1 -= tstados; // decrement counter; - return; - } else { - tstados -= ordenador.tape_counter1; - ordenador.tape_counter1 = 0; - ordenador.tape_readed = 0; // return 0 - } - } - - // pulse ended - - switch (ordenador.tape_current_mode) { - case TAP_GUIDE: // guide tone - if (ordenador.tape_counter_rep) { // still into guide tone - ordenador.tape_counter_rep--; - ordenador.tape_counter0 = 2168 - tstados; - ordenador.tape_counter1 = 2168; // new pulse - return; - } else { // guide tone ended. send sync tone - ordenador.tape_counter0 = 667 - tstados; - ordenador.tape_counter1 = 735; // new pulse - ordenador.tape_current_mode = TAP_DATA; // data mode - ordenador.tape_bit = 0x80; // from bit0 to bit7 - return; - } - break; - case TAP_DATA: // data - if (ordenador.tape_byte & ordenador.tape_bit) { // next bit is 1 - ordenador.tape_counter0 = 1710 - tstados; - ordenador.tape_counter1 = 1710; - } else { - ordenador.tape_counter0 = 851 - tstados; - ordenador.tape_counter1 = 852; - } - ordenador.tape_bit = ((ordenador.tape_bit >> 1) & 0x7F); // from bit0 to bit7 - if (!ordenador.tape_bit) { - ordenador.tape_byte_counter--; - if (!ordenador.tape_byte_counter) { // ended the block - ordenador.tape_current_mode = TAP_PAUSE; // pause - ordenador.tape_readed = 0; - ordenador.tape_counter_rep = 3500000; // 1 seconds - return; - } - ordenador.tape_bit = 0x80; - retval=fread (&(ordenador.tape_byte), 1, 1, fichero); // read next byte - if (feof (fichero)) { - rewind_tape(fichero,0); - ordenador.tape_current_mode = TAP_STOP; // stop tape - return; - } - } - break; - case TAP_PAUSE: // pause - ordenador.tape_readed = 0; - if (ordenador.tape_counter_rep > tstados) { - ordenador.tape_counter_rep -= tstados; - } else { - ordenador.tape_counter_rep = 0; - ordenador.tape_current_mode = TAP_TRASH; // read new block - } - return; - break; - case TAP_STOP: - ordenador.tape_current_mode = TAP_TRASH; // initialize - ordenador.pause = 1; // pause it - break; - default: - break; - } - } -} - -// manages TZX files - -inline void tape_read_tzx (FILE * fichero, int tstados) { - - static unsigned char value, value2,value3,value4,done; - static unsigned int bucle,bucle2; - int retval; - - if ((fichero == NULL)||(ordenador.pause)) - return; - - if (ordenador.tape_current_mode == TAP_TRASH) { // initialize a new block - done = 0; - do { - retval=fread(&value,1,1,fichero); // read block ID - //printf("ID: %X en %d\n",value,ftell(fichero)); - if(feof(fichero)) - done = 1; - else - switch(value) { - case 0x10: // classic tape block - done = 1; - bucle = 0; - ordenador.tape_current_bit = 0; - ordenador.tape_bit0_level = 852; - ordenador.tape_bit1_level = 1710; - ordenador.tape_bits_at_end = 8; - ordenador.tape_block_level = 2168; - ordenador.tape_sync_level0 = 667; - ordenador.tape_sync_level1 = 735; - - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); // pause length - ordenador.tape_pause_at_end = ((unsigned int) value2) + 256 * ((unsigned int) value3); - if(ordenador.tape_pause_at_end==0) - ordenador.tape_pause_at_end=10; // to avoid problems - ordenador.tape_pause_at_end *= 3500; - retval=fread (&value, 1, 1, fichero); - - retval=fread (&value2, 1, 1, fichero); // read block longitude - if (feof (fichero)) { - rewind_tape(fichero,1); - ordenador.tape_current_bit = 0; - ordenador.tape_current_mode = TAP_TRASH; - for(bucle=0;bucle<10;bucle++) - retval=fread(&value3,1,1,fichero); // jump over the header - return; - } - ordenador.tape_byte_counter = ((unsigned int) value) + 256 * ((unsigned int) value2); - retval=fread (&(ordenador.tape_byte), 1, 1, fichero); - ordenador.tape_bit = 0x80; - ordenador.tape_current_mode = TAP_GUIDE; - ordenador.tape_counter0 = 2168; - ordenador.tape_counter1 = 2168; - if (!(0x80 & ordenador.tape_byte)) - ordenador.tape_counter_rep = 3228; // 4 seconds - else - ordenador.tape_counter_rep = 1614; // 2 seconds - break; - - case 0x11: // turbo tape block - done = 1; - bucle = 0; - - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); - ordenador.tape_block_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); - ordenador.tape_sync_level0 = ((unsigned int) value2) + 256 * ((unsigned int) value3); - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); - ordenador.tape_sync_level1 = ((unsigned int) value2) + 256 * ((unsigned int) value3); - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); - ordenador.tape_bit0_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); - ordenador.tape_bit1_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); - ordenador.tape_counter_rep = ((unsigned int) value2) + 256 * ((unsigned int) value3); - ordenador.tape_counter_rep /=2; - retval=fread(&value2,1,1,fichero); - ordenador.tape_bits_at_end = value2; - - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); // pause length - ordenador.tape_pause_at_end = ((unsigned int) value2) + 256 * ((unsigned int) value3); - - - if(ordenador.tape_pause_at_end==0) - ordenador.tape_pause_at_end=10; // to avoid problems - ordenador.tape_pause_at_end *= 3500; - - retval=fread (&value, 1, 1, fichero); - retval=fread (&value2, 1, 1, fichero); - retval=fread (&value3, 1, 1, fichero); // read block longitude - ordenador.tape_byte_counter = ((unsigned int) value) + 256 * ((unsigned int) value2) + 65536* ((unsigned int) value3); - - if (feof (fichero)) { - rewind_tape(fichero,1); - ordenador.tape_current_bit = 0; - ordenador.tape_current_mode = TAP_TRASH; - return; - } - - retval=fread (&(ordenador.tape_byte), 1, 1, fichero); - ordenador.tape_bit = 0x80; - ordenador.tape_current_mode = TAP_GUIDE; - ordenador.tape_counter0 = ordenador.tape_block_level; - ordenador.tape_counter1 = ordenador.tape_block_level; - ordenador.tape_current_bit = 0; - break; - - case 0x12: // pure tone - done = 1; - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); // length of pulse in T-states - ordenador.tape_block_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); - ordenador.tape_counter0 = ordenador.tape_block_level; - ordenador.tape_counter1 = 0; - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); // number of pulses - ordenador.tape_counter_rep = ((unsigned int) value2) + 256 * ((unsigned int) value3); - if(ordenador.tape_counter_rep == 0) - done = 0; - ordenador.tape_current_mode = TZX_PURE_TONE; - break; - - case 0x13: // multiple pulses - done=1; - retval=fread(&value2,1,1,fichero); // number of pulses - ordenador.tape_counter_rep = ((unsigned int) value2); - if(ordenador.tape_counter_rep == 0) - done = 0; - else { - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); // length of pulse in T-states - ordenador.tape_counter0 = ((unsigned int) value2) + 256 * ((unsigned int) value3); - ordenador.tape_counter1 = 0; - ordenador.tape_current_mode = TZX_SEQ_PULSES; - } - break; - - case 0x14: // turbo tape block - done = 1; - bucle = 0; - ordenador.tape_current_bit = 0; - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); - ordenador.tape_bit0_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); - ordenador.tape_bit1_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); - retval=fread(&value2,1,1,fichero); - ordenador.tape_bits_at_end = value2; - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); // pause length - ordenador.tape_pause_at_end = ((unsigned int) value2) + 256 * ((unsigned int) value3); - /*if(ordenador.tape_pause_at_end==0) - ordenador.tape_pause_at_end=10;*/ // to avoid problems - ordenador.tape_pause_at_end *= 3500; - retval=fread (&value, 1, 1, fichero); - retval=fread (&value2, 1, 1, fichero); - retval=fread (&value3,1,1,fichero); // read block longitude - if (feof (fichero)) { - rewind_tape(fichero,1); - ordenador.tape_current_bit = 0; - ordenador.tape_current_mode = TAP_TRASH; - return; - } - ordenador.tape_byte_counter = ((unsigned int) value) + 256 * ((unsigned int) value2) + 65536*((unsigned int)value3); - ordenador.tape_bit = 0x80; - retval=fread (&(ordenador.tape_byte), 1, 1, fichero); // read next byte - if((ordenador.tape_byte_counter==1)&&(ordenador.tape_bits_at_end!=8)) { // last byte - for(bucle=ordenador.tape_bits_at_end;bucle<8;bucle++) { - ordenador.tape_byte=((ordenador.tape_byte>>1)&0x7F); - ordenador.tape_bit = ((ordenador.tape_bit>>1)&0x7F); - } - } - ordenador.tape_current_mode = TAP_DATA; - ordenador.tape_counter0 = 0; - ordenador.tape_counter1 = 0; - ordenador.tape_counter_rep = 0; - break; - - case 0x20: // pause - done = 1; - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); // pause length - ordenador.tape_counter_rep = ((unsigned int) value2) + 256 * ((unsigned int) value3); - ordenador.tape_readed = 0; - ordenador.tape_counter0 = 0; - ordenador.tape_counter1 = 0; // 1ms of inversed pulse - if(ordenador.tape_counter_rep == 0) { - ordenador.tape_current_mode = TAP_PAUSE2; // initialize - ordenador.tape_byte_counter = 31500; - break; - } - ordenador.tape_counter_rep *= 3500; - ordenador.tape_current_mode = TAP_PAUSE; - break; - - case 0x21: // group start - retval=fread(&value2,1,1,fichero); - bucle2=(unsigned int) value2; - for(bucle=0;bucle tstados) { - ordenador.tape_readed = ordenador.tape_current_bit; // return current - ordenador.tape_counter0 -= tstados; // decrement counter; - return; - } else { - tstados -= ordenador.tape_counter0; - ordenador.tape_counter0 = 0; - } - } - - ordenador.tape_readed = 1 - ordenador.tape_current_bit; // return oposite current - if (ordenador.tape_counter1) { - if (ordenador.tape_counter1 > tstados) { - ordenador.tape_counter1 -= tstados; // decrement counter; - return; - } else { - tstados -= ordenador.tape_counter1; - ordenador.tape_counter1 = 0; - ordenador.tape_readed = ordenador.tape_current_bit; // return current - } - } - - // pulse ended - - switch (ordenador.tape_current_mode) { - case TAP_FINAL_BIT: - ordenador.tape_current_mode = TAP_TRASH; - break; - case TAP_GUIDE: // guide tone - if (ordenador.tape_counter_rep) { // still into guide tone - ordenador.tape_counter_rep--; - ordenador.tape_counter0 = ordenador.tape_block_level - tstados; - ordenador.tape_counter1 = ordenador.tape_block_level; // new pulse - return; - } else { // guide tone ended. send sync tone - ordenador.tape_counter0 = ordenador.tape_sync_level0 - tstados; - ordenador.tape_counter1 = ordenador.tape_sync_level0; // new pulse - ordenador.tape_current_mode = TAP_DATA; // data mode - ordenador.tape_bit = 0x80; // from bit0 to bit7 - if((ordenador.tape_byte_counter==1)&&(ordenador.tape_bits_at_end!=8)) { // last byte - for(bucle=ordenador.tape_bits_at_end;bucle<8;bucle++) { - ordenador.tape_byte=((ordenador.tape_byte>>1)&0x7F); - ordenador.tape_bit = ((ordenador.tape_bit>>1)&0x7F); - } - } - return; - } - break; - case TAP_DATA: // data - if (ordenador.tape_byte & ordenador.tape_bit) { // next bit is 1 - ordenador.tape_counter0 = ordenador.tape_bit1_level - tstados; - ordenador.tape_counter1 = ordenador.tape_bit1_level; - } else { - ordenador.tape_counter0 = ordenador.tape_bit0_level - tstados; - ordenador.tape_counter1 = ordenador.tape_bit0_level; - } - ordenador.tape_bit = ((ordenador.tape_bit >> 1) & 0x7F); // from bit0 to bit7 - if (!ordenador.tape_bit) { - ordenador.tape_byte_counter--; - if (!ordenador.tape_byte_counter) { // ended the block - if(ordenador.tape_pause_at_end) { - ordenador.tape_current_mode = TAP_PAUSE3; // pause - ordenador.tape_counter_rep = ordenador.tape_pause_at_end; - } else - ordenador.tape_current_mode = TAP_FINAL_BIT; - return; - } - ordenador.tape_bit = 0x80; - retval=fread (&(ordenador.tape_byte), 1, 1, fichero); // read next byte - if (feof (fichero)) { - rewind_tape (fichero,0); - ordenador.tape_current_bit = 0; - ordenador.tape_current_mode = TAP_STOP; // stop tape - return; - } - if((ordenador.tape_byte_counter==1)&&(ordenador.tape_bits_at_end!=8)) { // last byte - for(bucle=ordenador.tape_bits_at_end;bucle<8;bucle++) { - ordenador.tape_byte=((ordenador.tape_byte>>1)&0x7F); - ordenador.tape_bit = ((ordenador.tape_bit>>1)&0x7F); - } - } - } - break; - - case TAP_PAUSE3: // one pulse of 1 ms for ending the bit - ordenador.tape_counter0 = 3500; // 1 ms - ordenador.tape_counter1 = 0; - ordenador.tape_current_mode = TAP_PAUSE; - break; - - case TAP_PAUSE: // pause - ordenador.tape_readed = 0; - ordenador.tape_current_bit = 0; - if (ordenador.tape_counter_rep > tstados) { - ordenador.tape_counter_rep -= tstados; - } else { - ordenador.tape_counter_rep = 0; - ordenador.tape_current_mode = TAP_TRASH; // read new block - } - break; - case TAP_PAUSE2: // pause and stop - ordenador.tape_readed = 0; - ordenador.tape_current_bit = 0; - if (ordenador.tape_counter_rep > tstados) { - ordenador.tape_counter_rep -= tstados; - } else { - ordenador.tape_counter_rep = 0; - ordenador.tape_current_mode = TAP_TRASH; // read new block - ordenador.pause = 1; - } - break; - case TZX_PURE_TONE: - ordenador.tape_counter_rep--; - ordenador.tape_current_bit = 1 - ordenador.tape_current_bit; // invert current bit - if (ordenador.tape_counter_rep) { // still into guide tone - ordenador.tape_counter0 = ordenador.tape_block_level - tstados; - ordenador.tape_counter1 = 0; // new pulse - } else - ordenador.tape_current_mode = TAP_TRASH; // next ID - break; - case TZX_SEQ_PULSES: - ordenador.tape_current_bit = 1 - ordenador.tape_current_bit; // invert current bit - ordenador.tape_counter_rep--; - if(ordenador.tape_counter_rep) { - retval=fread(&value2,1,1,fichero); - retval=fread(&value3,1,1,fichero); // length of pulse in T-states - ordenador.tape_counter0 = ((unsigned int) value2) + 256 * ((unsigned int) value3); - ordenador.tape_counter1 = 0; - } else - ordenador.tape_current_mode = TAP_TRASH; // next ID - break; - - case TAP_STOP: - ordenador.tape_current_bit = 0; - ordenador.tape_current_mode = TAP_TRASH; // initialize - ordenador.pause = 1; // pause it - break; - default: - break; - } -} - -void rewind_tape(FILE *fichero,unsigned char pause) { - - int thebucle; - unsigned char value; - int retval; - - rewind (ordenador.tap_file); - if(ordenador.tape_file_type==TAP_TZX) - for(thebucle=0;thebucle<10;thebucle++) - retval=fread(&value,1,1,ordenador.tap_file); // jump over the header - ordenador.pause=pause; -} - -unsigned char file_empty(FILE *fichero) { - - long position,position2; - - position=ftell(fichero); - fseek(fichero,0,SEEK_END); // set the pointer at end - position2=ftell(fichero); - fseek(fichero,position,SEEK_SET); // return the pointer to the original place - if(position2==0) - return 1; // empty file - else - return 0; -} - -void save_file(FILE *fichero) { - - long position; - unsigned char xor,salir; - byte dato; - int longitud; - - position=ftell(fichero); // store current position - fseek(fichero,0,SEEK_END); // put position at end - xor=0; - - longitud=(int)(procesador.Rm.wr.DE); - longitud+=2; - - dato=(byte)(longitud%256); - fprintf(fichero,"%c",dato); - dato=(byte)(longitud/256); - fprintf(fichero,"%c",dato); // file length - - fprintf(fichero,"%c",procesador.Rm.br.A); // flag - - xor^=procesador.Rm.br.A; - - salir = 0; - do { - if (procesador.Rm.wr.DE == 0) - salir = 2; - if (!salir) { - dato=Z80free_Rd(procesador.Rm.wr.IX); // read data - fprintf(fichero,"%c",dato); - xor^=dato; - procesador.Rm.wr.IX++; - procesador.Rm.wr.DE--; - } - } while (!salir); - fprintf(fichero,"%c",xor); - procesador.Rm.wr.IX++; - procesador.Rm.wr.IX++; - fseek(fichero,position,SEEK_SET); // put position at end - - if(ordenador.tape_fast_load==1) //if we want fast load, we assume we want fast save too - ordenador.other_ret = 1; // next instruction must be RET - - return; -} - -void fastload_block (FILE * fichero) { - - unsigned int longitud; - unsigned char value[65536], salir,empty,flag_found; - unsigned int veces; - int retval; - - ordenador.other_ret = 1; // next instruction must be RET - - if (!(procesador.Rm.br.F & F_C)) { // if Carry=0, is VERIFY, so return OK - procesador.Rm.br.F |= F_C; // verify OK - procesador.Rm.wr.IX += procesador.Rm.wr.DE; - procesador.Rm.wr.DE = 0; - return; - } - - empty=file_empty(fichero); - - - if ((fichero == NULL)||(empty)) { - procesador.Rm.br.F &= (~F_C); // Load error - procesador.Rm.wr.IX += procesador.Rm.wr.DE; - procesador.Rm.wr.DE = 0; - if(empty) - sprintf (ordenador.osd_text, "Tape file empty"); - else - sprintf (ordenador.osd_text, "No tape selected"); - ordenador.osd_time = 100; - return; - } - - veces=0; - - flag_found=0; - do { - retval=fread (value, 2, 1, fichero); // read length of current block - if (feof (fichero)) { // end of file? - veces++; // one more time rewinded - sprintf (ordenador.osd_text, "Tape rewind"); - ordenador.osd_time = 100; - rewind (fichero); // again - retval=fread (value, 2, 1, fichero); // read length of current block - } - longitud = ((unsigned int) value[0]) + 256 * ((unsigned int) value[1]); - retval=fread (value, 1, 1, fichero); // read flag byte - longitud--; - if (value[0] != procesador.Rm.br.A) { // different flag - retval=fread (value, longitud, 1, fichero); // jump to the next block - if (veces==3) { // tape rewinded three times? Block with that flag not found. - sprintf(ordenador.osd_text,"Block with right flag not found"); - ordenador.osd_time = 100; - procesador.Rm.br.F &= (~F_C); // Load error - return; - } - } else - flag_found = 1; - } while(flag_found == 0); - - salir = 0; - do { - if (longitud == 0) - salir = 1; - if (procesador.Rm.wr.DE == 0) - salir = 2; - if (!salir) { - retval=fread (value, 1, 1, fichero); // read byte - Z80free_Wr (procesador.Rm.wr.IX, (byte) value[0]); // store the byte - procesador.Rm.wr.IX++; - procesador.Rm.wr.DE--; - longitud--; - } - } - while (!salir); - - clean_screen (); - - if (salir == 1) { // system wants to load more bytes that the existent - procesador.Rm.br.F &= (~F_C); // Load error - return; - } - - if ((salir == 2) && (longitud != 1)) { // there are more bytes to load - procesador.Rm.br.F &= (~F_C); // Load error - if (longitud > 1) - retval=fread (value, longitud, 1, fichero); // jump to the next block - return; - } - - retval=fread (value, 1, 1, fichero); // jump over the checksum - procesador.Rm.br.F |= F_C; // Load OK - return; - -} +/* + * Copyright (C) 2012 Fabio Olimpieri + * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "z80free/Z80free.h" +#include "computer.h" +#include "emulator.h" +#include "menus.h" +#include "tape.h" + +int elcontador=0; +int eltstado=0; +char elbit=0; + +/* reads a tape file and updates the readed bit */ + +inline void tape_read(FILE *fichero, int tstados) { + + if(ordenador.pause) + return; + + if(ordenador.tape_file_type == TAP_TAP) + tape_read_tap(fichero,tstados); + else + tape_read_tzx(fichero,tstados); + +} + +// manages TAP files in REAL_MODE + +inline void tape_read_tap (FILE * fichero, int tstados) { + + static unsigned char value, value2; + int retval; + + if (fichero == NULL) + return; + + if (!ordenador.pause) { + if (ordenador.tape_current_mode == TAP_TRASH) { // initialize a new block + retval=fread (&value, 1, 1, fichero); + retval=fread (&value2, 1, 1, fichero); // read block longitude + if (feof (fichero)) { + rewind_tape(fichero,1); + ordenador.tape_current_mode = TAP_TRASH; + return; + } + ordenador.tape_byte_counter = ((unsigned int) value) + 256 * ((unsigned int) value2); + retval=fread (&(ordenador.tape_byte), 1, 1, fichero); + ordenador.tape_bit = 0x80; + ordenador.tape_current_mode = TAP_GUIDE; + ordenador.tape_counter0 = 2168; + ordenador.tape_counter1 = 2168; + if (!(0x80 & ordenador.tape_byte)) + ordenador.tape_counter_rep = 3228; // 4 seconds + else + ordenador.tape_counter_rep = 1614; // 2 seconds + } + + // if there's a pulse still being reproduce, just reproduce it + + if (ordenador.tape_counter0) { + if (ordenador.tape_counter0 > tstados) { + ordenador.tape_readed = 0; // return 0 + ordenador.tape_counter0 -= tstados; // decrement counter; + return; + } else { + tstados -= ordenador.tape_counter0; + ordenador.tape_counter0 = 0; + } + } + + ordenador.tape_readed = 1; // return 1 + if (ordenador.tape_counter1) { + if (ordenador.tape_counter1 > tstados) { + ordenador.tape_counter1 -= tstados; // decrement counter; + return; + } else { + tstados -= ordenador.tape_counter1; + ordenador.tape_counter1 = 0; + ordenador.tape_readed = 0; // return 0 + } + } + + // pulse ended + + switch (ordenador.tape_current_mode) { + case TAP_GUIDE: // guide tone + if (ordenador.tape_counter_rep) { // still into guide tone + ordenador.tape_counter_rep--; + ordenador.tape_counter0 = 2168 - tstados; + ordenador.tape_counter1 = 2168; // new pulse + return; + } else { // guide tone ended. send sync tone + ordenador.tape_counter0 = 667 - tstados; + ordenador.tape_counter1 = 735; // new pulse + ordenador.tape_current_mode = TAP_DATA; // data mode + ordenador.tape_bit = 0x80; // from bit0 to bit7 + return; + } + break; + case TAP_DATA: // data + if (ordenador.tape_byte & ordenador.tape_bit) { // next bit is 1 + ordenador.tape_counter0 = 1710 - tstados; + ordenador.tape_counter1 = 1710; + } else { + ordenador.tape_counter0 = 851 - tstados; + ordenador.tape_counter1 = 852; + } + ordenador.tape_bit = ((ordenador.tape_bit >> 1) & 0x7F); // from bit0 to bit7 + if (!ordenador.tape_bit) { + ordenador.tape_byte_counter--; + if (!ordenador.tape_byte_counter) { // ended the block + ordenador.tape_current_mode = TAP_PAUSE; // pause + ordenador.tape_readed = 0; + ordenador.tape_counter_rep = 3500000; // 1 seconds + return; + } + ordenador.tape_bit = 0x80; + retval=fread (&(ordenador.tape_byte), 1, 1, fichero); // read next byte + if (feof (fichero)) { + rewind_tape(fichero,0); + ordenador.tape_current_mode = TAP_STOP; // stop tape + return; + } + } + break; + case TAP_PAUSE: // pause + ordenador.tape_readed = 0; + if (ordenador.tape_counter_rep > tstados) { + ordenador.tape_counter_rep -= tstados; + } else { + ordenador.tape_counter_rep = 0; + ordenador.tape_current_mode = TAP_TRASH; // read new block + } + return; + break; + case TAP_STOP: + ordenador.tape_current_mode = TAP_TRASH; // initialize + ordenador.pause = 1; // pause it + break; + default: + break; + } + } +} + +// manages TZX files + +inline void tape_read_tzx (FILE * fichero, int tstados) { + + static unsigned char value, value2,value3,value4,done; + static unsigned int bucle,bucle2; + int retval; + + if ((fichero == NULL)||(ordenador.pause)) + return; + + if (ordenador.tape_current_mode == TAP_TRASH) { // initialize a new block + done = 0; + do { + retval=fread(&value,1,1,fichero); // read block ID + //printf("ID: %X en %d\n",value,ftell(fichero)); + if(feof(fichero)) + done = 1; + else + switch(value) { + case 0x10: // classic tape block + done = 1; + bucle = 0; + ordenador.tape_current_bit = 0; + ordenador.tape_bit0_level = 852; + ordenador.tape_bit1_level = 1710; + ordenador.tape_bits_at_end = 8; + ordenador.tape_block_level = 2168; + ordenador.tape_sync_level0 = 667; + ordenador.tape_sync_level1 = 735; + + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); // pause length + ordenador.tape_pause_at_end = ((unsigned int) value2) + 256 * ((unsigned int) value3); + if(ordenador.tape_pause_at_end==0) + ordenador.tape_pause_at_end=10; // to avoid problems + ordenador.tape_pause_at_end *= 3500; + retval=fread (&value, 1, 1, fichero); + + retval=fread (&value2, 1, 1, fichero); // read block longitude + if (feof (fichero)) { + rewind_tape(fichero,1); + ordenador.tape_current_bit = 0; + ordenador.tape_current_mode = TAP_TRASH; + for(bucle=0;bucle<10;bucle++) + retval=fread(&value3,1,1,fichero); // jump over the header + return; + } + ordenador.tape_byte_counter = ((unsigned int) value) + 256 * ((unsigned int) value2); + retval=fread (&(ordenador.tape_byte), 1, 1, fichero); + ordenador.tape_bit = 0x80; + ordenador.tape_current_mode = TAP_GUIDE; + ordenador.tape_counter0 = 2168; + ordenador.tape_counter1 = 2168; + if (!(0x80 & ordenador.tape_byte)) + ordenador.tape_counter_rep = 3228; // 4 seconds + else + ordenador.tape_counter_rep = 1614; // 2 seconds + break; + + case 0x11: // turbo tape block + done = 1; + bucle = 0; + + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); + ordenador.tape_block_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); + ordenador.tape_sync_level0 = ((unsigned int) value2) + 256 * ((unsigned int) value3); + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); + ordenador.tape_sync_level1 = ((unsigned int) value2) + 256 * ((unsigned int) value3); + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); + ordenador.tape_bit0_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); + ordenador.tape_bit1_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); + ordenador.tape_counter_rep = ((unsigned int) value2) + 256 * ((unsigned int) value3); + ordenador.tape_counter_rep /=2; + retval=fread(&value2,1,1,fichero); + ordenador.tape_bits_at_end = value2; + + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); // pause length + ordenador.tape_pause_at_end = ((unsigned int) value2) + 256 * ((unsigned int) value3); + + + if(ordenador.tape_pause_at_end==0) + ordenador.tape_pause_at_end=10; // to avoid problems + ordenador.tape_pause_at_end *= 3500; + + retval=fread (&value, 1, 1, fichero); + retval=fread (&value2, 1, 1, fichero); + retval=fread (&value3, 1, 1, fichero); // read block longitude + ordenador.tape_byte_counter = ((unsigned int) value) + 256 * ((unsigned int) value2) + 65536* ((unsigned int) value3); + + if (feof (fichero)) { + rewind_tape(fichero,1); + ordenador.tape_current_bit = 0; + ordenador.tape_current_mode = TAP_TRASH; + return; + } + + retval=fread (&(ordenador.tape_byte), 1, 1, fichero); + ordenador.tape_bit = 0x80; + ordenador.tape_current_mode = TAP_GUIDE; + ordenador.tape_counter0 = ordenador.tape_block_level; + ordenador.tape_counter1 = ordenador.tape_block_level; + ordenador.tape_current_bit = 0; + break; + + case 0x12: // pure tone + done = 1; + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); // length of pulse in T-states + ordenador.tape_block_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); + ordenador.tape_counter0 = ordenador.tape_block_level; + ordenador.tape_counter1 = 0; + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); // number of pulses + ordenador.tape_counter_rep = ((unsigned int) value2) + 256 * ((unsigned int) value3); + if(ordenador.tape_counter_rep == 0) + done = 0; + ordenador.tape_current_mode = TZX_PURE_TONE; + break; + + case 0x13: // multiple pulses + done=1; + retval=fread(&value2,1,1,fichero); // number of pulses + ordenador.tape_counter_rep = ((unsigned int) value2); + if(ordenador.tape_counter_rep == 0) + done = 0; + else { + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); // length of pulse in T-states + ordenador.tape_counter0 = ((unsigned int) value2) + 256 * ((unsigned int) value3); + ordenador.tape_counter1 = 0; + ordenador.tape_current_mode = TZX_SEQ_PULSES; + } + break; + + case 0x14: // turbo tape block + done = 1; + bucle = 0; + ordenador.tape_current_bit = 0; + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); + ordenador.tape_bit0_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); + ordenador.tape_bit1_level = ((unsigned int) value2) + 256 * ((unsigned int) value3); + retval=fread(&value2,1,1,fichero); + ordenador.tape_bits_at_end = value2; + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); // pause length + ordenador.tape_pause_at_end = ((unsigned int) value2) + 256 * ((unsigned int) value3); + /*if(ordenador.tape_pause_at_end==0) + ordenador.tape_pause_at_end=10;*/ // to avoid problems + ordenador.tape_pause_at_end *= 3500; + retval=fread (&value, 1, 1, fichero); + retval=fread (&value2, 1, 1, fichero); + retval=fread (&value3,1,1,fichero); // read block longitude + if (feof (fichero)) { + rewind_tape(fichero,1); + ordenador.tape_current_bit = 0; + ordenador.tape_current_mode = TAP_TRASH; + return; + } + ordenador.tape_byte_counter = ((unsigned int) value) + 256 * ((unsigned int) value2) + 65536*((unsigned int)value3); + ordenador.tape_bit = 0x80; + retval=fread (&(ordenador.tape_byte), 1, 1, fichero); // read next byte + if((ordenador.tape_byte_counter==1)&&(ordenador.tape_bits_at_end!=8)) { // last byte + for(bucle=ordenador.tape_bits_at_end;bucle<8;bucle++) { + ordenador.tape_byte=((ordenador.tape_byte>>1)&0x7F); + ordenador.tape_bit = ((ordenador.tape_bit>>1)&0x7F); + } + } + ordenador.tape_current_mode = TAP_DATA; + ordenador.tape_counter0 = 0; + ordenador.tape_counter1 = 0; + ordenador.tape_counter_rep = 0; + break; + + case 0x20: // pause + done = 1; + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); // pause length + ordenador.tape_counter_rep = ((unsigned int) value2) + 256 * ((unsigned int) value3); + ordenador.tape_readed = 0; + ordenador.tape_counter0 = 0; + ordenador.tape_counter1 = 0; // 1ms of inversed pulse + if(ordenador.tape_counter_rep == 0) { + ordenador.tape_current_mode = TAP_PAUSE2; // initialize + ordenador.tape_byte_counter = 31500; + break; + } + ordenador.tape_counter_rep *= 3500; + ordenador.tape_current_mode = TAP_PAUSE; + break; + + case 0x21: // group start + retval=fread(&value2,1,1,fichero); + bucle2=(unsigned int) value2; + for(bucle=0;bucle tstados) { + ordenador.tape_readed = ordenador.tape_current_bit; // return current + ordenador.tape_counter0 -= tstados; // decrement counter; + return; + } else { + tstados -= ordenador.tape_counter0; + ordenador.tape_counter0 = 0; + } + } + + ordenador.tape_readed = 1 - ordenador.tape_current_bit; // return oposite current + if (ordenador.tape_counter1) { + if (ordenador.tape_counter1 > tstados) { + ordenador.tape_counter1 -= tstados; // decrement counter; + return; + } else { + tstados -= ordenador.tape_counter1; + ordenador.tape_counter1 = 0; + ordenador.tape_readed = ordenador.tape_current_bit; // return current + } + } + + // pulse ended + + switch (ordenador.tape_current_mode) { + case TAP_FINAL_BIT: + ordenador.tape_current_mode = TAP_TRASH; + break; + case TAP_GUIDE: // guide tone + if (ordenador.tape_counter_rep) { // still into guide tone + ordenador.tape_counter_rep--; + ordenador.tape_counter0 = ordenador.tape_block_level - tstados; + ordenador.tape_counter1 = ordenador.tape_block_level; // new pulse + return; + } else { // guide tone ended. send sync tone + ordenador.tape_counter0 = ordenador.tape_sync_level0 - tstados; + ordenador.tape_counter1 = ordenador.tape_sync_level0; // new pulse + ordenador.tape_current_mode = TAP_DATA; // data mode + ordenador.tape_bit = 0x80; // from bit0 to bit7 + if((ordenador.tape_byte_counter==1)&&(ordenador.tape_bits_at_end!=8)) { // last byte + for(bucle=ordenador.tape_bits_at_end;bucle<8;bucle++) { + ordenador.tape_byte=((ordenador.tape_byte>>1)&0x7F); + ordenador.tape_bit = ((ordenador.tape_bit>>1)&0x7F); + } + } + return; + } + break; + case TAP_DATA: // data + if (ordenador.tape_byte & ordenador.tape_bit) { // next bit is 1 + ordenador.tape_counter0 = ordenador.tape_bit1_level - tstados; + ordenador.tape_counter1 = ordenador.tape_bit1_level; + } else { + ordenador.tape_counter0 = ordenador.tape_bit0_level - tstados; + ordenador.tape_counter1 = ordenador.tape_bit0_level; + } + ordenador.tape_bit = ((ordenador.tape_bit >> 1) & 0x7F); // from bit0 to bit7 + if (!ordenador.tape_bit) { + ordenador.tape_byte_counter--; + if (!ordenador.tape_byte_counter) { // ended the block + if(ordenador.tape_pause_at_end) { + ordenador.tape_current_mode = TAP_PAUSE3; // pause + ordenador.tape_counter_rep = ordenador.tape_pause_at_end; + } else + ordenador.tape_current_mode = TAP_FINAL_BIT; + return; + } + ordenador.tape_bit = 0x80; + retval=fread (&(ordenador.tape_byte), 1, 1, fichero); // read next byte + if (feof (fichero)) { + rewind_tape (fichero,0); + ordenador.tape_current_bit = 0; + ordenador.tape_current_mode = TAP_STOP; // stop tape + return; + } + if((ordenador.tape_byte_counter==1)&&(ordenador.tape_bits_at_end!=8)) { // last byte + for(bucle=ordenador.tape_bits_at_end;bucle<8;bucle++) { + ordenador.tape_byte=((ordenador.tape_byte>>1)&0x7F); + ordenador.tape_bit = ((ordenador.tape_bit>>1)&0x7F); + } + } + } + break; + + case TAP_PAUSE3: // one pulse of 1 ms for ending the bit + ordenador.tape_counter0 = 3500; // 1 ms + ordenador.tape_counter1 = 0; + ordenador.tape_current_mode = TAP_PAUSE; + break; + + case TAP_PAUSE: // pause + ordenador.tape_readed = 0; + ordenador.tape_current_bit = 0; + if (ordenador.tape_counter_rep > tstados) { + ordenador.tape_counter_rep -= tstados; + } else { + ordenador.tape_counter_rep = 0; + ordenador.tape_current_mode = TAP_TRASH; // read new block + } + break; + case TAP_PAUSE2: // pause and stop + ordenador.tape_readed = 0; + ordenador.tape_current_bit = 0; + if (ordenador.tape_counter_rep > tstados) { + ordenador.tape_counter_rep -= tstados; + } else { + ordenador.tape_counter_rep = 0; + ordenador.tape_current_mode = TAP_TRASH; // read new block + ordenador.pause = 1; + } + break; + case TZX_PURE_TONE: + ordenador.tape_counter_rep--; + ordenador.tape_current_bit = 1 - ordenador.tape_current_bit; // invert current bit + if (ordenador.tape_counter_rep) { // still into guide tone + ordenador.tape_counter0 = ordenador.tape_block_level - tstados; + ordenador.tape_counter1 = 0; // new pulse + } else + ordenador.tape_current_mode = TAP_TRASH; // next ID + break; + case TZX_SEQ_PULSES: + ordenador.tape_current_bit = 1 - ordenador.tape_current_bit; // invert current bit + ordenador.tape_counter_rep--; + if(ordenador.tape_counter_rep) { + retval=fread(&value2,1,1,fichero); + retval=fread(&value3,1,1,fichero); // length of pulse in T-states + ordenador.tape_counter0 = ((unsigned int) value2) + 256 * ((unsigned int) value3); + ordenador.tape_counter1 = 0; + } else + ordenador.tape_current_mode = TAP_TRASH; // next ID + break; + + case TAP_STOP: + ordenador.tape_current_bit = 0; + ordenador.tape_current_mode = TAP_TRASH; // initialize + ordenador.pause = 1; // pause it + break; + default: + break; + } +} + +void rewind_tape(FILE *fichero,unsigned char pause) { + + int thebucle; + unsigned char value; + int retval; + + rewind (ordenador.tap_file); + if(ordenador.tape_file_type==TAP_TZX) + for(thebucle=0;thebucle<10;thebucle++) + retval=fread(&value,1,1,ordenador.tap_file); // jump over the header + ordenador.pause=pause; +} + +unsigned char file_empty(FILE *fichero) { + + long position,position2; + + position=ftell(fichero); + fseek(fichero,0,SEEK_END); // set the pointer at end + position2=ftell(fichero); + fseek(fichero,position,SEEK_SET); // return the pointer to the original place + if(position2==0) + return 1; // empty file + else + return 0; +} + +void save_file(FILE *fichero) { + + long position; + unsigned char xor,salir; + byte dato; + int longitud; + + position=ftell(fichero); // store current position + fseek(fichero,0,SEEK_END); // put position at end + xor=0; + + longitud=(int)(procesador.Rm.wr.DE); + longitud+=2; + + dato=(byte)(longitud%256); + fprintf(fichero,"%c",dato); + dato=(byte)(longitud/256); + fprintf(fichero,"%c",dato); // file length + + fprintf(fichero,"%c",procesador.Rm.br.A); // flag + + xor^=procesador.Rm.br.A; + + salir = 0; + do { + if (procesador.Rm.wr.DE == 0) + salir = 2; + if (!salir) { + dato=Z80free_Rd(procesador.Rm.wr.IX); // read data + fprintf(fichero,"%c",dato); + xor^=dato; + procesador.Rm.wr.IX++; + procesador.Rm.wr.DE--; + } + } while (!salir); + fprintf(fichero,"%c",xor); + procesador.Rm.wr.IX++; + procesador.Rm.wr.IX++; + fseek(fichero,position,SEEK_SET); // put position at end + + if(ordenador.tape_fast_load==1) //if we want fast load, we assume we want fast save too + ordenador.other_ret = 1; // next instruction must be RET + + return; +} + +void fastload_block (FILE * fichero) { + + unsigned int longitud; + unsigned char value[65536], salir,empty,flag_found; + unsigned int veces; + int retval; + + ordenador.other_ret = 1; // next instruction must be RET + + if (!(procesador.Rm.br.F & F_C)) { // if Carry=0, is VERIFY, so return OK + procesador.Rm.br.F |= F_C; // verify OK + procesador.Rm.wr.IX += procesador.Rm.wr.DE; + procesador.Rm.wr.DE = 0; + return; + } + + empty=file_empty(fichero); + + + if ((fichero == NULL)||(empty)) { + procesador.Rm.br.F &= (~F_C); // Load error + procesador.Rm.wr.IX += procesador.Rm.wr.DE; + procesador.Rm.wr.DE = 0; + if(empty) + sprintf (ordenador.osd_text, "Tape file empty"); + else + sprintf (ordenador.osd_text, "No tape selected"); + ordenador.osd_time = 100; + return; + } + + veces=0; + + flag_found=0; + do { + retval=fread (value, 2, 1, fichero); // read length of current block + if (feof (fichero)) { // end of file? + veces++; // one more time rewinded + sprintf (ordenador.osd_text, "Tape rewind"); + ordenador.osd_time = 100; + rewind (fichero); // again + retval=fread (value, 2, 1, fichero); // read length of current block + } + longitud = ((unsigned int) value[0]) + 256 * ((unsigned int) value[1]); + retval=fread (value, 1, 1, fichero); // read flag byte + longitud--; + if (value[0] != procesador.Rm.br.A) { // different flag + retval=fread (value, longitud, 1, fichero); // jump to the next block + if (veces==3) { // tape rewinded three times? Block with that flag not found. + sprintf(ordenador.osd_text,"Block with right flag not found"); + ordenador.osd_time = 100; + procesador.Rm.br.F &= (~F_C); // Load error + return; + } + } else + flag_found = 1; + } while(flag_found == 0); + + salir = 0; + do { + if (longitud == 0) + salir = 1; + if (procesador.Rm.wr.DE == 0) + salir = 2; + if (!salir) { + retval=fread (value, 1, 1, fichero); // read byte + Z80free_Wr_fake (procesador.Rm.wr.IX, (byte) value[0]); // store the byte + procesador.Rm.wr.IX++; + procesador.Rm.wr.DE--; + longitud--; + } + } + while (!salir); + + clean_screen (); + + if (salir == 1) { // system wants to load more bytes that the existent + procesador.Rm.br.F &= (~F_C); // Load error + return; + } + + if ((salir == 2) && (longitud != 1)) { // there are more bytes to load + procesador.Rm.br.F &= (~F_C); // Load error + if (longitud > 1) + retval=fread (value, longitud, 1, fichero); // jump to the next block + return; + } + + retval=fread (value, 1, 1, fichero); // jump over the checksum + procesador.Rm.br.F |= F_C; // Load OK + return; + +} diff --git a/src/z80free/Z80free.c b/src/z80free/Z80free.c index 6ae5a0d..7817984 100644 --- a/src/z80free/Z80free.c +++ b/src/z80free/Z80free.c @@ -1,786 +1,786 @@ -/* - * Copyright 2008-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of Z80Free, with some bits extracted - * and fixed from libZ80 (from Gabriel Gambetta) - * - * Z80Free is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Z80Free is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "Z80free.h" - -void Z80free_reset(Z80FREE *processor) { - - processor->PC=0; - processor->IFF1=0; - processor->IFF2=0; - processor->Rm.wr.AF=0xFFFF; - processor->Rm.wr.BC=0xFFFF; - processor->Rm.wr.DE=0xFFFF; - processor->Rm.wr.HL=0xFFFF; - processor->Rm.wr.IX=0xFFFF; - processor->Rm.wr.IY=0xFFFF; - processor->Ra.wr.AF=0xFFFF; - processor->Ra.wr.BC=0xFFFF; - processor->Ra.wr.DE=0xFFFF; - processor->Ra.wr.HL=0xFFFF; - processor->HALT=0; - processor->IM=0; - processor->I=0; - processor->Status=0; - processor->IAddr_done=0; - processor->INT_P=0; - processor->NMI_P=0; - -} - -void Z80free_INT(Z80FREE *processor,byte value) { - - processor->INT_P=1; - processor->empty_bus=value; - -} - -int Z80free_step(Z80FREE *processor) { - - int retval=0; - do { - retval+=Z80free_ustep(processor); - } while(processor->Status!=Z80XX); - return (retval); -} - -int Z80free_ustep(Z80FREE *processor) { - - static byte opcode,d1; - int retval=0; - - processor->R++; - if (processor->Status==Z80XX) { - if (processor->NMI_P) { // NMI triggered - if (processor->HALT) { - processor->HALT=0; - processor->PC++; - } - processor->NMI_P=0; - Z80free_doPush(processor,processor->PC); - processor->PC=0x0066; - processor->IFF1=0; // disable INTs - processor->Status=Z80INT; - return(11); // we use 11 tstates for attending a NMI - } - if (processor->INT_P) { - processor->INT_P=0; - if (processor->IFF1==1) { // allow INTs only in this case - if (processor->HALT) { - processor->HALT=0; - processor->PC++; - } - processor->Status=Z80INT; - processor->IFF1=0; - processor->IFF2=0; - Z80free_doPush(processor,processor->PC); - if (processor->IM!=2) { // we will forget IM0 mode for now; maybe in the future... - processor->PC=0x0038; - return (13); - } else { - processor->PC=Z80free_read16(((((word)processor->I)<<8)&0xFF00) | ((word)processor->empty_bus)); - return (19); - } - } - } - } - - if (processor->IFF1>1) // set the right status for interrupts - processor->IFF1--; - - opcode=Z80free_Rd(processor->PC); - processor->PC++; - switch(processor->Status) { - case Z80INT: - processor->Status=Z80XX; - case Z80XX: - if (opcode==0xCB) { - processor->Status=Z80CB; - return 4; - } else if (opcode==0xED) { - processor->Status=Z80ED; - return 4; - } else if (opcode==0xDD) { - processor->Status=Z80DD; - return 4; - } else if (opcode==0xFD) { - processor->Status=Z80FD; - return 4; - } else { - return(Z80free_codes(processor,opcode)); - } - break; - case Z80CB: - processor->Status=Z80XX; - return(Z80free_codesCB(processor,opcode)); - break; - case Z80ED: - processor->Status=Z80XX; - return(Z80free_codesED(processor,opcode)); - break; - case Z80DD: - if (opcode==0xDD) { - return 4; - } - if (opcode==0xFD) { - processor->Status=Z80FD; - return 4; - } - processor->Status=Z80XX; - if (opcode==0xCB) { - d1=Z80free_Rd(processor->PC++); - retval+=Z80free_codesDDCB(processor,d1); - } else { - retval+=Z80free_codesDD(processor,opcode); - } - processor->IAddr_done=0; - return (retval); - break; - case Z80FD: - if (opcode==0xDD) { - processor->Status=Z80DD; - return 4; - } - if (opcode==0xFD) { - return 4; - } - processor->Status=Z80XX; - if (opcode==0xCB) { - d1=Z80free_Rd(processor->PC++); - retval+=Z80free_codesFDCB(processor,d1); - } else { - retval+=Z80free_codesFD(processor,opcode); - } - processor->IAddr_done=0; - return (retval); - break; - } - return 0; -} - - -/* --------------------------------------------------------- - * Flag operations - * --------------------------------------------------------- - */ - -/** Sets a flag */ -inline void Z80free_setFlag(Z80FREE *processor, byte flag) { - - processor->Rm.br.F |= flag; -} - -/** Resets a flag */ -inline void Z80free_resFlag(Z80FREE *processor, byte flag) { - - processor->Rm.br.F &= ~flag; -} - -/** Puts a value in a flag */ -inline void Z80free_valFlag(Z80FREE *processor, byte flag, int val) { - - if (val) - processor->Rm.br.F |= flag; - else - processor->Rm.br.F &= ~flag; -} - -/** Returns a flag */ -inline int Z80free_getFlag(Z80FREE *processor, byte flag) { - - return (processor->Rm.br.F & flag) != 0; -} - - -/* --------------------------------------------------------- - * Flag adjustments - * --------------------------------------------------------- - */ - -int Z80free_parityBit[256] = { - - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 }; - - -inline void Z80free_adjustFlags (Z80FREE *processor, byte val) { - - Z80free_valFlag(processor,F_5, (val & F_5) != 0); - Z80free_valFlag(processor,F_3, (val & F_3) != 0); -} - - -inline void Z80free_adjustFlagSZP (Z80FREE *processor, byte val) { - - Z80free_valFlag(processor,F_S, (val & 0x80) != 0); - Z80free_valFlag(processor,F_Z, (val == 0)); - Z80free_valFlag(processor,F_PV, Z80free_parityBit[val]); -} - - -// Adjust flags after AND, OR, XOR -inline void Z80free_adjustLogicFlag (Z80FREE *processor, int flagH) { - - Z80free_valFlag(processor,F_S, (processor->Rm.br.A & 0x80) != 0); - Z80free_valFlag(processor,F_Z, (processor->Rm.br.A == 0)); - Z80free_valFlag(processor,F_H, flagH); - Z80free_valFlag(processor,F_N, 0); - Z80free_valFlag(processor,F_C, 0); - Z80free_valFlag(processor,F_PV, Z80free_parityBit[processor->Rm.br.A]); - - Z80free_adjustFlags(processor, processor->Rm.br.A); -} - - -/* --------------------------------------------------------- - * Generic operations - * --------------------------------------------------------- - */ - -byte Z80free_readR(Z80FREE *processor) { - Z80free_adjustFlagSZP(processor,(0x7F&processor->R)|(0x80&processor->R2)); - Z80free_valFlag(processor,F_PV,processor->IFF2); - Z80free_valFlag(processor,F_N, 0); - Z80free_valFlag(processor,F_H, 0); - Z80free_adjustFlags(processor,(0x7F&processor->R)|(0x80&processor->R2)); - return ((0x7F&processor->R)|(0x80&processor->R2)); -} - -void Z80free_setR(Z80FREE *processor,byte value) { - processor->R=value; - processor->R2=value; -} - -byte Z80free_readI(Z80FREE *processor) { - - Z80free_adjustFlagSZP(processor,processor->I); - Z80free_valFlag(processor,F_PV,processor->IFF2); - Z80free_valFlag(processor,F_N, 0); - Z80free_valFlag(processor,F_H, 0); - Z80free_adjustFlags(processor,processor->I); - return (processor->I); -} - - -/** Do an arithmetic operation (ADD, SUB, ADC, SBC y CP) */ -byte Z80free_doArithmetic (Z80FREE *processor, byte value1,byte value2, int withCarry, int isSub) { - - static word res; /* To detect carry */ - static byte carry; - - if (withCarry && Z80free_getFlag(processor,F_C)) - carry=1; - else - carry=0; - - if (isSub) { - Z80free_setFlag(processor,F_N); - res = ((word)value1) - ((word)value2) - ((word)carry); - Z80free_valFlag(processor,F_H, ((value1 ^ value2 ^ res) & 0x10) != 0); - Z80free_valFlag(processor,F_PV, (((value1 ^ value2)&0x080) && (((res^value1)&0x080)))); - } else { - Z80free_resFlag(processor,F_N); - res = ((word)value1) + ((word)value2) + ((word)carry); - Z80free_valFlag(processor,F_H, (((value1 & 0x0F) + (value2 & 0x0F)+carry) & 0x10) != 0); - Z80free_valFlag(processor,F_PV, ((((value1 ^ value2)&0x080)==0) && ((res^value1)&0x080))); - } - - Z80free_valFlag(processor,F_S, ((res & 0x080) != 0)); - Z80free_valFlag(processor,F_C, ((res & 0x0100) != 0)); - Z80free_valFlag(processor,F_Z, ((res&0xFF) == 0)); - - Z80free_adjustFlags(processor, res&0xFF); - - return (byte)(res & 0xFF); -} - -word Z80free_doArithmetic16 (Z80FREE *processor, word value1,word value2, int withCarry, int isSub) { - - static word tmp; - static byte Ftmp; - - Ftmp=processor->Rm.br.F; // store the F register to restore the unchanged bits when doing operations without carry - - tmp=(word)Z80free_doArithmetic(processor,(byte)(value1&0x00FF),(byte)(value2&0x00FF),withCarry,isSub); - tmp|=((word)Z80free_doArithmetic(processor,(byte)((value1>>8)&0x00FF),(byte)((value2>>8)&0x00FF),1,isSub))<<8; - if (tmp) { - Z80free_resFlag(processor,F_Z); - } else { - Z80free_setFlag(processor,F_Z); - } - - if (tmp&0x08000) { - Z80free_setFlag(processor,F_S); - } else { - Z80free_resFlag(processor,F_S); - } - - if (!(withCarry|isSub)) { - processor->Rm.br.F &= 0x3B; // preserve the new values of C, N, 3, H and 5 - processor->Rm.br.F |= (Ftmp & 0xC4); // set the old values of P/V, Z and S - } - - return (tmp); -} - -void Z80free_doAND (Z80FREE *processor, byte value) { - - processor->Rm.br.A &= value; - Z80free_adjustLogicFlag(processor, 1); -} - - -void Z80free_doOR (Z80FREE *processor, byte value) { - - processor->Rm.br.A |= value; - Z80free_adjustLogicFlag(processor, 0); -} - - -void Z80free_doXOR (Z80FREE *processor, byte value) { - - processor->Rm.br.A ^= value; - Z80free_adjustLogicFlag(processor, 0); -} - - -void Z80free_doBIT (Z80FREE *processor, int b, byte val) { - - if (val & (1 << b)) - Z80free_resFlag(processor,F_Z | F_PV); - else - Z80free_setFlag(processor,F_Z | F_PV); - - Z80free_setFlag(processor,F_H); - Z80free_resFlag(processor,F_N); - - - if ((b == 7) && !Z80free_getFlag(processor,F_Z)) - Z80free_setFlag(processor,F_S); - else - Z80free_resFlag(processor,F_S); - - /*Z80free_resFlag(processor,F_5); - if ((b == 5) && !Z80free_getFlag(processor,F_Z)) - Z80free_setFlag(processor,F_5); - - Z80free_resFlag(processor,F_3); - if ((b == 3) && !Z80free_getFlag(processor,F_Z)) - Z80free_setFlag(processor,F_3);*/ - Z80free_adjustFlags(processor,val); -} - - -byte Z80free_doSetRes (Z80FREE *processor, int bit, int pos, byte val) { - - if (bit) - val |= (1 << pos); - else - val &= ~(1 << pos); - return val; -} - - - -byte Z80free_doIncDec (Z80FREE *processor, byte val, int isDec) { - - if (isDec) { - Z80free_valFlag(processor,F_PV, (val & 0x80) && !((val - 1) & 0x80)); - val--; - Z80free_valFlag(processor,F_H, (val & 0x0F)==0x0F); - } else { - Z80free_valFlag(processor,F_PV, !(val & 0x80) && ((val + 1) & 0x80)); - val++; - Z80free_valFlag(processor,F_H, (val & 0x0F)==0); - } - - Z80free_valFlag(processor,F_S, ((val & 0x80) != 0)); - Z80free_valFlag(processor,F_Z, (val == 0)); - Z80free_valFlag(processor,F_N, isDec); - - Z80free_adjustFlags(processor, val); - - return val; -} - - -word Z80free_doIncDec16 (Z80FREE *processor, word val, int isDec) { - - if (isDec) { - val--; - } else { - val++; - } - - return val; -} - - -byte Z80free_doRLC (Z80FREE *processor, int adjFlags, byte val) { - - Z80free_valFlag(processor,F_C, (val & 0x80) != 0); - val <<= 1; - val |= (byte)Z80free_getFlag(processor,F_C); - - Z80free_adjustFlags(processor, val); - Z80free_resFlag(processor,F_H | F_N); - - if (adjFlags) - Z80free_adjustFlagSZP(processor, val); - - return val; -} - - -byte Z80free_doRL (Z80FREE *processor, int adjFlags, byte val) { - - int CY = Z80free_getFlag(processor,F_C); - Z80free_valFlag(processor,F_C, (val & 0x80) != 0); - val <<= 1; - val |= (byte)CY; - - Z80free_adjustFlags(processor, val); - Z80free_resFlag(processor,F_H | F_N); - - if (adjFlags) - Z80free_adjustFlagSZP(processor, val); - - return val; -} - - -byte Z80free_doRRC (Z80FREE *processor, int adjFlags, byte val) { - - Z80free_valFlag(processor,F_C, (val & 0x01) != 0); - val >>= 1; - val |= ((byte)Z80free_getFlag(processor,F_C) << 7); - - Z80free_adjustFlags(processor, val); - Z80free_resFlag(processor,F_H | F_N); - - if (adjFlags) - Z80free_adjustFlagSZP(processor, val); - - return val; -} - - -byte Z80free_doRR (Z80FREE *processor, int adjFlags, byte val) { - - int CY = Z80free_getFlag(processor,F_C); - Z80free_valFlag(processor,F_C, (val & 0x01)); - val >>= 1; - val |= (CY << 7); - - Z80free_adjustFlags(processor, val); - Z80free_resFlag(processor,F_H | F_N); - - if (adjFlags) - Z80free_adjustFlagSZP(processor, val); - - return val; -} - - -byte Z80free_doSL (Z80FREE *processor, int isArith, byte val) { - - Z80free_valFlag(processor,F_C, (val & 0x80) != 0); - val <<= 1; - - if (isArith) - val |= 1; - - Z80free_adjustFlags(processor, val); - Z80free_resFlag(processor,F_H | F_N); - Z80free_adjustFlagSZP(processor, val); - - return val; -} - - -byte Z80free_doSR (Z80FREE *processor, int isArith, byte val) { - - static int b; - - b = (val & 0x80); - - Z80free_valFlag(processor,F_C, (val & 0x01) != 0); - val >>= 1; - - if (isArith) - val |= (byte)b; - - Z80free_adjustFlags(processor, val); - Z80free_resFlag(processor,F_H | F_N); - Z80free_adjustFlagSZP(processor, val); - - return val; -} - -void Z80free_doRLD(Z80FREE *processor) { - - static byte tmp,tmp2; - - tmp=processor->Rm.br.A; - tmp2=Z80free_Rd(processor->Rm.wr.HL); - processor->Rm.br.A&=0xF0; - processor->Rm.br.A|=(0x0F&(tmp2>>4)); - Z80free_Wr(processor->Rm.wr.HL,((tmp2<<4)&0xF0)|(tmp&0x0F)); - - Z80free_resFlag(processor,F_H | F_N); - Z80free_adjustFlagSZP(processor, processor->Rm.br.A); - Z80free_adjustFlags(processor, processor->Rm.br.A); - -} - -void Z80free_doRRD(Z80FREE *processor) { - - static byte tmp,tmp2; - - tmp=processor->Rm.br.A; - tmp2=Z80free_Rd(processor->Rm.wr.HL); - processor->Rm.br.A&=0xF0; - processor->Rm.br.A|=(0x0F&tmp2); - Z80free_Wr(processor->Rm.wr.HL,((tmp2>>4)&0x0F)|((tmp<<4)&0xF0)); - - Z80free_resFlag(processor,F_H | F_N); - Z80free_adjustFlagSZP(processor, processor->Rm.br.A); - Z80free_adjustFlags(processor, processor->Rm.br.A); - -} - -void Z80free_doPush (Z80FREE *processor, word val) { - - processor->Rm.wr.SP-=2; - Z80free_write16(processor->Rm.wr.SP, val); -} - - -word Z80free_doPop (Z80FREE *processor) { - - static word val; - - val = Z80free_read16(processor->Rm.wr.SP); - processor->Rm.wr.SP+=2; - - return val; -} - - -/* The DAA opcode - * According to the value in A and the flags set, add a value to A - * - * Flags set Byte (0..9)(0..9) - * -------------------------------------------- - * (None) + &00 - * Carry:+ &60 - * Subtract:+ &00 - * Subtract+Carry:+ &A0 - * Half-carry:+ &06 - * Half-carry+Carry:+ &66 - * Half-carry+Subtract:+ &FA - * Half-carry+Subtract+Carry:+ &9A - * - * Flags set Byte (0..9)(A..F) - * -------------------------------------------- - * (None) + &06 - * Carry:+ &66 - * Subtract:+ &00 - * Subtract+Carry:+ &a0 - * Half-carry:+ &06 - * Half-carry+Carry:+ &66 - * Half-carry+Subtract:+ &fa - * Half-carry+Subtract+Carry:+ &9A - * - * Flags set Byte (A..F)(0..9) - * -------------------------------------------- - * (None) + &60 - * Carry:+ &60 - * Subtract:+ &00 - * Subtract+Carry:+ &A0 - * Half-carry:+ &66 - * Half-carry+Carry:+ &66 - * Half-carry+Subtract:+ &fa - * Half-carry+Subtract+Carry:+ &9A - * - * Flags set Byte (A..F)(A..F) - * -------------------------------------------- - * (None) + &66 - * Carry:+ &66 - * Subtract:+ &00 - * Subtract+Carry:+ &a0 - * Half-carry:+ &66 - * Half-carry+Carry:+ &66 - * Half-carry+Subtract:+ &fa - * Half-carry+Subtract+Carry:+ &9A - */ - -static int Z80free_DAA_BYTETYPE1[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 }; -static int Z80free_DAA_BYTETYPE2[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2 }; - -static byte Z80free_DAA_ADJUSTMENT[4][6] = { - {0x00,0x06,0x00,0x66,0x60,0x66}, - {0x06,0x06,0x06,0x66,0x66,0x66}, - {0x60,0x66,0x60,0x66,0x60,0x66}, - {0x66,0x66,0x66,0x66,0x66,0x66} }; - -void Z80free_doDAA (Z80FREE *processor) { - - byte oldval; - int byteType; - int flagMask = 0; - - /* (0..8)(0..9) = 0 */ - /* (0..8)(A..F) = 1 */ - /* (9) (0..9) = 2 */ - /* (9) (A..F) = 3 */ - /* (A..F)(0..9) = 4 */ - /* (A..F)(A..F) = 5 */ - byteType = Z80free_DAA_BYTETYPE1[(processor->Rm.br.A&0x0F)] | ((Z80free_DAA_BYTETYPE2[(processor->Rm.br.A >> 4)&0x0F]) << 1); - oldval=(processor->Rm.br.A&0x0F); - - if (Z80free_getFlag(processor,F_C)) - flagMask |= 2; - if (Z80free_getFlag(processor,F_H)) - flagMask |= 1; - - if (processor->Rm.br.F&F_N) { - processor->Rm.br.A -= Z80free_DAA_ADJUSTMENT[flagMask][byteType]; - } else { - processor->Rm.br.A += Z80free_DAA_ADJUSTMENT[flagMask][byteType]; - } - if ((byteType<3)&&((processor->Rm.br.F&F_C)==0)) { - Z80free_resFlag(processor,F_C); - } else { - Z80free_setFlag(processor,F_C); - } - - if ((processor->Rm.br.F&F_N)==0) { - if (oldval>9) { - Z80free_setFlag(processor,F_H); - } else { - Z80free_resFlag(processor,F_H); - } - } else { - if (processor->Rm.br.F&F_H) { - if (oldval>5) { - Z80free_resFlag(processor,F_H); - } else { - Z80free_setFlag(processor,F_H); - } - } - } - - processor->Rm.br.F&=0x57; - processor->Rm.br.F|=(processor->Rm.br.A&0xA4); - if (processor->Rm.br.A) { - Z80free_resFlag(processor,F_Z); - } else { - Z80free_setFlag(processor,F_Z); - } - Z80free_valFlag(processor,F_PV, Z80free_parityBit[processor->Rm.br.A]); - Z80free_adjustFlags(processor, processor->Rm.br.A); - -} - -void Z80free_jump_relative(Z80FREE *processor,byte relvar) { - - static word rel2; - - rel2=(word)relvar; - if (relvar&0x080) { - rel2|=0xFF00; - } - processor->PC+=rel2; -} - -word Z80free_addr_relative(Z80FREE *processor,word address) { - - static word rel2; - - if (processor->IAddr_done) { - return (processor->IAddr); - } - processor->IAddr_done=1; - rel2=(word)Z80free_read_param_8(processor); - if (rel2&0x080) { - rel2|=0xFF00; - } - processor->IAddr=address+rel2; - return (address+rel2); -} - -word Z80free_addr_relativeXDCB(Z80FREE *processor,word address,byte d1) { - - static word rel2; - - rel2=(word)d1; - if (rel2&0x080) { - rel2|=0xFF00; - } - processor->IAddr=address+rel2; - return (address+rel2); -} - -void Z80free_write16 (register word addr,register word val) { - - Z80free_Wr(addr, (byte)(val & 0xFF)); - val >>= 8; - addr++; - Z80free_Wr(addr, (byte)(val & 0xFF)); -} - -word Z80free_read16 (register word addr) { - - static word v1; - v1=((word)Z80free_Rd(addr))&0x00FF; - addr++; - return (v1 + ((((word)Z80free_Rd(addr)) << 8)&0xFF00)); -} - -byte Z80free_read_param_8(Z80FREE *processor) { - - return(Z80free_Rd(processor->PC++)); - -} - - -word Z80free_read_param_16(Z80FREE *processor) { - - static word value; - value=Z80free_read16(processor->PC); - processor->PC+=2; - return (value); -} - +/* + * Copyright 2008-2009 (C) Raster Software Vigo (Sergio Costas) + * This file is part of Z80Free, with some bits extracted + * and fixed from libZ80 (from Gabriel Gambetta) + * + * Z80Free is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Z80Free is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "Z80free.h" + +void Z80free_reset(Z80FREE *processor) { + + processor->PC=0; + processor->IFF1=0; + processor->IFF2=0; + processor->Rm.wr.AF=0xFFFF; + processor->Rm.wr.BC=0xFFFF; + processor->Rm.wr.DE=0xFFFF; + processor->Rm.wr.HL=0xFFFF; + processor->Rm.wr.IX=0xFFFF; + processor->Rm.wr.IY=0xFFFF; + processor->Ra.wr.AF=0xFFFF; + processor->Ra.wr.BC=0xFFFF; + processor->Ra.wr.DE=0xFFFF; + processor->Ra.wr.HL=0xFFFF; + processor->HALT=0; + processor->IM=0; + processor->I=0; + processor->Status=0; + processor->IAddr_done=0; + processor->INT_P=0; + processor->NMI_P=0; + +} + +void Z80free_INT(Z80FREE *processor,byte value) { + + processor->INT_P=1; + processor->empty_bus=value; + +} + +int Z80free_step(Z80FREE *processor) { + + int retval=0; + do { + retval+=Z80free_ustep(processor); + } while(processor->Status!=Z80XX); + return (retval); +} + +int Z80free_ustep(Z80FREE *processor) { + + static byte opcode,d1; + int retval=0; + + processor->R++; + if (processor->Status==Z80XX) { + if (processor->NMI_P) { // NMI triggered + if (processor->HALT) { + processor->HALT=0; + processor->PC++; + } + processor->NMI_P=0; + Z80free_doPush(processor,processor->PC); + processor->PC=0x0066; + processor->IFF1=0; // disable INTs + processor->Status=Z80INT; + return(11); // we use 11 tstates for attending a NMI + } + if (processor->INT_P) { + processor->INT_P=0; + if (processor->IFF1==1) { // allow INTs only in this case + if (processor->HALT) { + processor->HALT=0; + processor->PC++; + } + processor->Status=Z80INT; + processor->IFF1=0; + processor->IFF2=0; + Z80free_doPush(processor,processor->PC); + if (processor->IM!=2) { // we will forget IM0 mode for now; maybe in the future... + processor->PC=0x0038; + return (13); //IM1 + } else { + processor->PC=Z80free_read16(((((word)processor->I)<<8)&0xFF00) | ((word)processor->empty_bus)); + return (19); //IM2 + } + } + } + } + + if (processor->IFF1>1) // set the right status for interrupts + processor->IFF1--; + + opcode=Z80free_Rd_fetch(processor->PC); + processor->PC++; + switch(processor->Status) { + case Z80INT: + processor->Status=Z80XX; + case Z80XX: + if (opcode==0xCB) { + processor->Status=Z80CB; + return 4; + } else if (opcode==0xED) { + processor->Status=Z80ED; + return 4; + } else if (opcode==0xDD) { + processor->Status=Z80DD; + return 4; + } else if (opcode==0xFD) { + processor->Status=Z80FD; + return 4; + } else { + return(Z80free_codes(processor,opcode)); + } + break; + case Z80CB: + processor->Status=Z80XX; + return(Z80free_codesCB(processor,opcode)); + break; + case Z80ED: + processor->Status=Z80XX; + return(Z80free_codesED(processor,opcode)); + break; + case Z80DD: + if (opcode==0xDD) { + return 4; + } + if (opcode==0xFD) { + processor->Status=Z80FD; + return 4; + } + processor->Status=Z80XX; + if (opcode==0xCB) { + d1=Z80free_Rd_fetch(processor->PC++); + retval+=Z80free_codesDDCB(processor,d1); + } else { + retval+=Z80free_codesDD(processor,opcode); + } + processor->IAddr_done=0; + return (retval); + break; + case Z80FD: + if (opcode==0xDD) { + processor->Status=Z80DD; + return 4; + } + if (opcode==0xFD) { + return 4; + } + processor->Status=Z80XX; + if (opcode==0xCB) { + d1=Z80free_Rd_fetch(processor->PC++); + retval+=Z80free_codesFDCB(processor,d1); + } else { + retval+=Z80free_codesFD(processor,opcode); + } + processor->IAddr_done=0; + return (retval); + break; + } + return 0; +} + + +/* --------------------------------------------------------- + * Flag operations + * --------------------------------------------------------- + */ + +/** Sets a flag */ +inline void Z80free_setFlag(Z80FREE *processor, byte flag) { + + processor->Rm.br.F |= flag; +} + +/** Resets a flag */ +inline void Z80free_resFlag(Z80FREE *processor, byte flag) { + + processor->Rm.br.F &= ~flag; +} + +/** Puts a value in a flag */ +inline void Z80free_valFlag(Z80FREE *processor, byte flag, int val) { + + if (val) + processor->Rm.br.F |= flag; + else + processor->Rm.br.F &= ~flag; +} + +/** Returns a flag */ +inline int Z80free_getFlag(Z80FREE *processor, byte flag) { + + return (processor->Rm.br.F & flag) != 0; +} + + +/* --------------------------------------------------------- + * Flag adjustments + * --------------------------------------------------------- + */ + +int Z80free_parityBit[256] = { + + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 }; + + +inline void Z80free_adjustFlags (Z80FREE *processor, byte val) { + + Z80free_valFlag(processor,F_5, (val & F_5) != 0); + Z80free_valFlag(processor,F_3, (val & F_3) != 0); +} + + +inline void Z80free_adjustFlagSZP (Z80FREE *processor, byte val) { + + Z80free_valFlag(processor,F_S, (val & 0x80) != 0); + Z80free_valFlag(processor,F_Z, (val == 0)); + Z80free_valFlag(processor,F_PV, Z80free_parityBit[val]); +} + + +// Adjust flags after AND, OR, XOR +inline void Z80free_adjustLogicFlag (Z80FREE *processor, int flagH) { + + Z80free_valFlag(processor,F_S, (processor->Rm.br.A & 0x80) != 0); + Z80free_valFlag(processor,F_Z, (processor->Rm.br.A == 0)); + Z80free_valFlag(processor,F_H, flagH); + Z80free_valFlag(processor,F_N, 0); + Z80free_valFlag(processor,F_C, 0); + Z80free_valFlag(processor,F_PV, Z80free_parityBit[processor->Rm.br.A]); + + Z80free_adjustFlags(processor, processor->Rm.br.A); +} + + +/* --------------------------------------------------------- + * Generic operations + * --------------------------------------------------------- + */ + +byte Z80free_readR(Z80FREE *processor) { + Z80free_adjustFlagSZP(processor,(0x7F&processor->R)|(0x80&processor->R2)); + Z80free_valFlag(processor,F_PV,processor->IFF2); + Z80free_valFlag(processor,F_N, 0); + Z80free_valFlag(processor,F_H, 0); + Z80free_adjustFlags(processor,(0x7F&processor->R)|(0x80&processor->R2)); + return ((0x7F&processor->R)|(0x80&processor->R2)); +} + +void Z80free_setR(Z80FREE *processor,byte value) { + processor->R=value; + processor->R2=value; +} + +byte Z80free_readI(Z80FREE *processor) { + + Z80free_adjustFlagSZP(processor,processor->I); + Z80free_valFlag(processor,F_PV,processor->IFF2); + Z80free_valFlag(processor,F_N, 0); + Z80free_valFlag(processor,F_H, 0); + Z80free_adjustFlags(processor,processor->I); + return (processor->I); +} + + +/** Do an arithmetic operation (ADD, SUB, ADC, SBC y CP) */ +byte Z80free_doArithmetic (Z80FREE *processor, byte value1,byte value2, int withCarry, int isSub) { + + static word res; /* To detect carry */ + static byte carry; + + if (withCarry && Z80free_getFlag(processor,F_C)) + carry=1; + else + carry=0; + + if (isSub) { + Z80free_setFlag(processor,F_N); + res = ((word)value1) - ((word)value2) - ((word)carry); + Z80free_valFlag(processor,F_H, ((value1 ^ value2 ^ res) & 0x10) != 0); + Z80free_valFlag(processor,F_PV, (((value1 ^ value2)&0x080) && (((res^value1)&0x080)))); + } else { + Z80free_resFlag(processor,F_N); + res = ((word)value1) + ((word)value2) + ((word)carry); + Z80free_valFlag(processor,F_H, (((value1 & 0x0F) + (value2 & 0x0F)+carry) & 0x10) != 0); + Z80free_valFlag(processor,F_PV, ((((value1 ^ value2)&0x080)==0) && ((res^value1)&0x080))); + } + + Z80free_valFlag(processor,F_S, ((res & 0x080) != 0)); + Z80free_valFlag(processor,F_C, ((res & 0x0100) != 0)); + Z80free_valFlag(processor,F_Z, ((res&0xFF) == 0)); + + Z80free_adjustFlags(processor, res&0xFF); + + return (byte)(res & 0xFF); +} + +word Z80free_doArithmetic16 (Z80FREE *processor, word value1,word value2, int withCarry, int isSub) { + + static word tmp; + static byte Ftmp; + + Ftmp=processor->Rm.br.F; // store the F register to restore the unchanged bits when doing operations without carry + + tmp=(word)Z80free_doArithmetic(processor,(byte)(value1&0x00FF),(byte)(value2&0x00FF),withCarry,isSub); + tmp|=((word)Z80free_doArithmetic(processor,(byte)((value1>>8)&0x00FF),(byte)((value2>>8)&0x00FF),1,isSub))<<8; + if (tmp) { + Z80free_resFlag(processor,F_Z); + } else { + Z80free_setFlag(processor,F_Z); + } + + if (tmp&0x08000) { + Z80free_setFlag(processor,F_S); + } else { + Z80free_resFlag(processor,F_S); + } + + if (!(withCarry|isSub)) { + processor->Rm.br.F &= 0x3B; // preserve the new values of C, N, 3, H and 5 + processor->Rm.br.F |= (Ftmp & 0xC4); // set the old values of P/V, Z and S + } + + return (tmp); +} + +void Z80free_doAND (Z80FREE *processor, byte value) { + + processor->Rm.br.A &= value; + Z80free_adjustLogicFlag(processor, 1); +} + + +void Z80free_doOR (Z80FREE *processor, byte value) { + + processor->Rm.br.A |= value; + Z80free_adjustLogicFlag(processor, 0); +} + + +void Z80free_doXOR (Z80FREE *processor, byte value) { + + processor->Rm.br.A ^= value; + Z80free_adjustLogicFlag(processor, 0); +} + + +void Z80free_doBIT (Z80FREE *processor, int b, byte val) { + + if (val & (1 << b)) + Z80free_resFlag(processor,F_Z | F_PV); + else + Z80free_setFlag(processor,F_Z | F_PV); + + Z80free_setFlag(processor,F_H); + Z80free_resFlag(processor,F_N); + + + if ((b == 7) && !Z80free_getFlag(processor,F_Z)) + Z80free_setFlag(processor,F_S); + else + Z80free_resFlag(processor,F_S); + + /*Z80free_resFlag(processor,F_5); + if ((b == 5) && !Z80free_getFlag(processor,F_Z)) + Z80free_setFlag(processor,F_5); + + Z80free_resFlag(processor,F_3); + if ((b == 3) && !Z80free_getFlag(processor,F_Z)) + Z80free_setFlag(processor,F_3);*/ + Z80free_adjustFlags(processor,val); +} + + +byte Z80free_doSetRes (Z80FREE *processor, int bit, int pos, byte val) { + + if (bit) + val |= (1 << pos); + else + val &= ~(1 << pos); + return val; +} + + + +byte Z80free_doIncDec (Z80FREE *processor, byte val, int isDec) { + + if (isDec) { + Z80free_valFlag(processor,F_PV, (val & 0x80) && !((val - 1) & 0x80)); + val--; + Z80free_valFlag(processor,F_H, (val & 0x0F)==0x0F); + } else { + Z80free_valFlag(processor,F_PV, !(val & 0x80) && ((val + 1) & 0x80)); + val++; + Z80free_valFlag(processor,F_H, (val & 0x0F)==0); + } + + Z80free_valFlag(processor,F_S, ((val & 0x80) != 0)); + Z80free_valFlag(processor,F_Z, (val == 0)); + Z80free_valFlag(processor,F_N, isDec); + + Z80free_adjustFlags(processor, val); + + return val; +} + + +word Z80free_doIncDec16 (Z80FREE *processor, word val, int isDec) { + + if (isDec) { + val--; + } else { + val++; + } + + return val; +} + + +byte Z80free_doRLC (Z80FREE *processor, int adjFlags, byte val) { + + Z80free_valFlag(processor,F_C, (val & 0x80) != 0); + val <<= 1; + val |= (byte)Z80free_getFlag(processor,F_C); + + Z80free_adjustFlags(processor, val); + Z80free_resFlag(processor,F_H | F_N); + + if (adjFlags) + Z80free_adjustFlagSZP(processor, val); + + return val; +} + + +byte Z80free_doRL (Z80FREE *processor, int adjFlags, byte val) { + + int CY = Z80free_getFlag(processor,F_C); + Z80free_valFlag(processor,F_C, (val & 0x80) != 0); + val <<= 1; + val |= (byte)CY; + + Z80free_adjustFlags(processor, val); + Z80free_resFlag(processor,F_H | F_N); + + if (adjFlags) + Z80free_adjustFlagSZP(processor, val); + + return val; +} + + +byte Z80free_doRRC (Z80FREE *processor, int adjFlags, byte val) { + + Z80free_valFlag(processor,F_C, (val & 0x01) != 0); + val >>= 1; + val |= ((byte)Z80free_getFlag(processor,F_C) << 7); + + Z80free_adjustFlags(processor, val); + Z80free_resFlag(processor,F_H | F_N); + + if (adjFlags) + Z80free_adjustFlagSZP(processor, val); + + return val; +} + + +byte Z80free_doRR (Z80FREE *processor, int adjFlags, byte val) { + + int CY = Z80free_getFlag(processor,F_C); + Z80free_valFlag(processor,F_C, (val & 0x01)); + val >>= 1; + val |= (CY << 7); + + Z80free_adjustFlags(processor, val); + Z80free_resFlag(processor,F_H | F_N); + + if (adjFlags) + Z80free_adjustFlagSZP(processor, val); + + return val; +} + + +byte Z80free_doSL (Z80FREE *processor, int isArith, byte val) { + + Z80free_valFlag(processor,F_C, (val & 0x80) != 0); + val <<= 1; + + if (isArith) + val |= 1; + + Z80free_adjustFlags(processor, val); + Z80free_resFlag(processor,F_H | F_N); + Z80free_adjustFlagSZP(processor, val); + + return val; +} + + +byte Z80free_doSR (Z80FREE *processor, int isArith, byte val) { + + static int b; + + b = (val & 0x80); + + Z80free_valFlag(processor,F_C, (val & 0x01) != 0); + val >>= 1; + + if (isArith) + val |= (byte)b; + + Z80free_adjustFlags(processor, val); + Z80free_resFlag(processor,F_H | F_N); + Z80free_adjustFlagSZP(processor, val); + + return val; +} + +void Z80free_doRLD(Z80FREE *processor) { + + static byte tmp,tmp2; + + tmp=processor->Rm.br.A; + tmp2=Z80free_Rd(processor->Rm.wr.HL); + processor->Rm.br.A&=0xF0; + processor->Rm.br.A|=(0x0F&(tmp2>>4)); + Z80free_Wr(processor->Rm.wr.HL,((tmp2<<4)&0xF0)|(tmp&0x0F)); + + Z80free_resFlag(processor,F_H | F_N); + Z80free_adjustFlagSZP(processor, processor->Rm.br.A); + Z80free_adjustFlags(processor, processor->Rm.br.A); + +} + +void Z80free_doRRD(Z80FREE *processor) { + + static byte tmp,tmp2; + + tmp=processor->Rm.br.A; + tmp2=Z80free_Rd(processor->Rm.wr.HL); + processor->Rm.br.A&=0xF0; + processor->Rm.br.A|=(0x0F&tmp2); + Z80free_Wr(processor->Rm.wr.HL,((tmp2>>4)&0x0F)|((tmp<<4)&0xF0)); + + Z80free_resFlag(processor,F_H | F_N); + Z80free_adjustFlagSZP(processor, processor->Rm.br.A); + Z80free_adjustFlags(processor, processor->Rm.br.A); + +} + +void Z80free_doPush (Z80FREE *processor, word val) { + + processor->Rm.wr.SP-=2; + Z80free_write16(processor->Rm.wr.SP, val); +} + + +word Z80free_doPop (Z80FREE *processor) { + + static word val; + + val = Z80free_read16(processor->Rm.wr.SP); + processor->Rm.wr.SP+=2; + + return val; +} + + +/* The DAA opcode + * According to the value in A and the flags set, add a value to A + * + * Flags set Byte (0..9)(0..9) + * -------------------------------------------- + * (None) + &00 + * Carry:+ &60 + * Subtract:+ &00 + * Subtract+Carry:+ &A0 + * Half-carry:+ &06 + * Half-carry+Carry:+ &66 + * Half-carry+Subtract:+ &FA + * Half-carry+Subtract+Carry:+ &9A + * + * Flags set Byte (0..9)(A..F) + * -------------------------------------------- + * (None) + &06 + * Carry:+ &66 + * Subtract:+ &00 + * Subtract+Carry:+ &a0 + * Half-carry:+ &06 + * Half-carry+Carry:+ &66 + * Half-carry+Subtract:+ &fa + * Half-carry+Subtract+Carry:+ &9A + * + * Flags set Byte (A..F)(0..9) + * -------------------------------------------- + * (None) + &60 + * Carry:+ &60 + * Subtract:+ &00 + * Subtract+Carry:+ &A0 + * Half-carry:+ &66 + * Half-carry+Carry:+ &66 + * Half-carry+Subtract:+ &fa + * Half-carry+Subtract+Carry:+ &9A + * + * Flags set Byte (A..F)(A..F) + * -------------------------------------------- + * (None) + &66 + * Carry:+ &66 + * Subtract:+ &00 + * Subtract+Carry:+ &a0 + * Half-carry:+ &66 + * Half-carry+Carry:+ &66 + * Half-carry+Subtract:+ &fa + * Half-carry+Subtract+Carry:+ &9A + */ + +static int Z80free_DAA_BYTETYPE1[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 }; +static int Z80free_DAA_BYTETYPE2[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2 }; + +static byte Z80free_DAA_ADJUSTMENT[4][6] = { + {0x00,0x06,0x00,0x66,0x60,0x66}, + {0x06,0x06,0x06,0x66,0x66,0x66}, + {0x60,0x66,0x60,0x66,0x60,0x66}, + {0x66,0x66,0x66,0x66,0x66,0x66} }; + +void Z80free_doDAA (Z80FREE *processor) { + + byte oldval; + int byteType; + int flagMask = 0; + + /* (0..8)(0..9) = 0 */ + /* (0..8)(A..F) = 1 */ + /* (9) (0..9) = 2 */ + /* (9) (A..F) = 3 */ + /* (A..F)(0..9) = 4 */ + /* (A..F)(A..F) = 5 */ + byteType = Z80free_DAA_BYTETYPE1[(processor->Rm.br.A&0x0F)] | ((Z80free_DAA_BYTETYPE2[(processor->Rm.br.A >> 4)&0x0F]) << 1); + oldval=(processor->Rm.br.A&0x0F); + + if (Z80free_getFlag(processor,F_C)) + flagMask |= 2; + if (Z80free_getFlag(processor,F_H)) + flagMask |= 1; + + if (processor->Rm.br.F&F_N) { + processor->Rm.br.A -= Z80free_DAA_ADJUSTMENT[flagMask][byteType]; + } else { + processor->Rm.br.A += Z80free_DAA_ADJUSTMENT[flagMask][byteType]; + } + if ((byteType<3)&&((processor->Rm.br.F&F_C)==0)) { + Z80free_resFlag(processor,F_C); + } else { + Z80free_setFlag(processor,F_C); + } + + if ((processor->Rm.br.F&F_N)==0) { + if (oldval>9) { + Z80free_setFlag(processor,F_H); + } else { + Z80free_resFlag(processor,F_H); + } + } else { + if (processor->Rm.br.F&F_H) { + if (oldval>5) { + Z80free_resFlag(processor,F_H); + } else { + Z80free_setFlag(processor,F_H); + } + } + } + + processor->Rm.br.F&=0x57; + processor->Rm.br.F|=(processor->Rm.br.A&0xA4); + if (processor->Rm.br.A) { + Z80free_resFlag(processor,F_Z); + } else { + Z80free_setFlag(processor,F_Z); + } + Z80free_valFlag(processor,F_PV, Z80free_parityBit[processor->Rm.br.A]); + Z80free_adjustFlags(processor, processor->Rm.br.A); + +} + +void Z80free_jump_relative(Z80FREE *processor,byte relvar) { + + static word rel2; + + rel2=(word)relvar; + if (relvar&0x080) { + rel2|=0xFF00; + } + processor->PC+=rel2; +} + +word Z80free_addr_relative(Z80FREE *processor,word address) { + + static word rel2; + + if (processor->IAddr_done) { + return (processor->IAddr); + } + processor->IAddr_done=1; + rel2=(word)Z80free_read_param_8(processor); + if (rel2&0x080) { + rel2|=0xFF00; + } + processor->IAddr=address+rel2; + return (address+rel2); +} + +word Z80free_addr_relativeXDCB(Z80FREE *processor,word address,byte d1) { + + static word rel2; + + rel2=(word)d1; + if (rel2&0x080) { + rel2|=0xFF00; + } + processor->IAddr=address+rel2; + return (address+rel2); +} + +void Z80free_write16 (register word addr,register word val) { + + Z80free_Wr(addr, (byte)(val & 0xFF)); + val >>= 8; + addr++; + Z80free_Wr(addr, (byte)(val & 0xFF)); +} + +word Z80free_read16 (register word addr) { + + static word v1; + v1=((word)Z80free_Rd(addr))&0x00FF; + addr++; + return (v1 + ((((word)Z80free_Rd(addr)) << 8)&0xFF00)); +} + +byte Z80free_read_param_8(Z80FREE *processor) { + + return(Z80free_Rd(processor->PC++)); + +} + + +word Z80free_read_param_16(Z80FREE *processor) { + + static word value; + value=Z80free_read16(processor->PC); + processor->PC+=2; + return (value); +} + diff --git a/src/z80free/Z80free.h b/src/z80free/Z80free.h index 96b4996..3246116 100644 --- a/src/z80free/Z80free.h +++ b/src/z80free/Z80free.h @@ -1,156 +1,159 @@ -/* - * Copyright 2008-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of Z80Free, with some bits extracted - * and fixed from libZ80 (from Gabriel Gambetta) - * - * Z80Free is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Z80Free is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - - -#ifndef Z80FREE_H -#define Z80FREE_H - -#ifdef GEKKO -#include -#endif - -#ifndef Z80_H -typedef unsigned short int word; -typedef unsigned char byte; -#endif - -#define F_S 0x80 -#define F_Z 0x40 -#define F_5 0x20 -#define F_H 0x10 -#define F_3 0x08 -#define F_PV 0x04 -#define F_N 0x02 -#define F_C 0x01 - -//enum Z80free_prefix {Z80XX, Z80CB, Z80DD, Z80ED, Z80FD}; - - -typedef union { - /** Word registers. */ - struct - { - word AF, BC, DE, HL, IX, IY, SP; - } wr; - - /** Byte registers. SP can be accessed partially to simplify the load/save code. */ - - -#if BYTE_ORDER == LITTLE_ENDIAN - struct - { - byte F,A, C,B, E,D, L,H, IXl,IXh, IYl,IYh, P,S; - } br; -#else - - struct - { - byte A,F, B,C, D,E, H,L, IXh,IXl, IYh,IYl, S,P; - } br; - -#endif - -} Z80FRegs; - -/** A Z80 execution context. */ -typedef struct -{ - Z80FRegs Ra; /* Alternate register set (R) */ - Z80FRegs Rm; /* Main register set (R) */ - word PC; /* Program counter */ - byte R; /* Refresh */ - byte R2; /* Upper bit for Refresh */ - byte I; - byte IFF1; /* Interrupt Flipflop 1. If it's 2, decrement it and don't allow INT */ - byte IFF2; /* Interrupt Flipflop 2 */ - byte IM; /* Interrupt mode */ - byte HALT; /* HALT status */ - byte INT_P; /* INT pending */ - byte NMI_P; /* NMI pending */ - byte empty_bus; /* value for empty bus when procesing a maskable int */ - word IAddr; /* address with offset for IX+d and IY+d */ - byte IAddr_done; /* if 1, IAddr contains a valid data */ - enum {Z80XX, Z80CB, Z80DD, Z80ED, Z80FD, Z80INT} Status; -} Z80FREE; - -/* internal Z80 methods */ - -void Z80free_setFlag(Z80FREE *processor, byte flag); -void Z80free_resFlag(Z80FREE *processor, byte flag); -void Z80free_valFlag(Z80FREE *processor, byte flag, int val); -int Z80free_getFlag(Z80FREE *processor, byte flag); -void Z80free_adjustFlags (Z80FREE *processor, byte val); -void Z80free_adjustFlagSZP (Z80FREE *processor, byte val); -void Z80free_adjustLogicFlag (Z80FREE *processor, int flagH); -byte Z80free_doArithmetic (Z80FREE *processor, byte value1,byte value2, int withCarry, int isSub); -word Z80free_doArithmetic16 (Z80FREE *processor, word value1,word value2, int withCarry, int isSub); -void Z80free_doAND (Z80FREE *processor, byte value); -void Z80free_doOR (Z80FREE *processor, byte value); -void Z80free_doXOR (Z80FREE *processor, byte value); -void Z80free_doBIT (Z80FREE *processor, int b, byte val); -byte Z80free_doSetRes (Z80FREE *processor, int bit, int pos, byte val); -byte Z80free_doIncDec (Z80FREE *processor, byte val, int isDec); -word Z80free_doIncDec16 (Z80FREE *processor, word val, int isDec); -byte Z80free_doRLC (Z80FREE *processor, int adjFlags, byte val); -byte Z80free_doRL (Z80FREE *processor, int adjFlags, byte val); -byte Z80free_doRRC (Z80FREE *processor, int adjFlags, byte val); -byte Z80free_doRR (Z80FREE *processor, int adjFlags, byte val); -byte Z80free_doSL (Z80FREE *processor, int isArith, byte val); -byte Z80free_doSR (Z80FREE *processor, int isArith, byte val); -void Z80free_doPush (Z80FREE *processor, word val); -word Z80free_doPop (Z80FREE *processor); -void Z80free_doDAA (Z80FREE *processor); -byte Z80free_readR(Z80FREE *processor); -void Z80free_setR(Z80FREE *processor,byte value); -byte Z80free_readI(Z80FREE *processor); -void Z80free_doRRD(Z80FREE *processor); -void Z80free_doRLD(Z80FREE *processor); - -void Z80free_jump_relative(Z80FREE *processor,byte relvar); -word Z80free_addr_relative(Z80FREE *processor,word address); -word Z80free_addr_relativeXDCB(Z80FREE *processor,word address,byte d1); -byte Z80free_read_param_8(Z80FREE *z80); -word Z80free_read_param_16(Z80FREE *z80); -word Z80free_read16 (register word addr); -void Z80free_write16 (register word addr,register word val); - -/* external Z80 methods */ - -void Z80free_reset(Z80FREE *); -int Z80free_step(Z80FREE *); -int Z80free_ustep(Z80FREE *); -void Z80free_INT(Z80FREE *,byte); - -byte Z80free_Rd (register word Addr); -void Z80free_Wr (register word Addr, register byte Value); -byte Z80free_In (register word Port); -void Z80free_Out (register word Port, register byte Value); - -/* Opcode functions */ - -int Z80free_codes (Z80FREE *processor,byte opcode); -int Z80free_codesCB (Z80FREE *processor,byte opcode); -int Z80free_codesDD (Z80FREE *processor,byte opcode); -int Z80free_codesED (Z80FREE *processor,byte opcode); -int Z80free_codesFD (Z80FREE *processor,byte opcode); -int Z80free_codesDDCB (Z80FREE *processor,byte d1); -int Z80free_codesFDCB (Z80FREE *processor,byte d1); - -#endif +/* + * Copyright 2008-2009 (C) Raster Software Vigo (Sergio Costas) + * This file is part of Z80Free, with some bits extracted + * and fixed from libZ80 (from Gabriel Gambetta) + * + * Z80Free is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Z80Free is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + + +#ifndef Z80FREE_H +#define Z80FREE_H + +#ifdef GEKKO +#include +#endif + +#ifndef Z80_H +typedef unsigned short int word; +typedef unsigned char byte; +#endif + +#define F_S 0x80 +#define F_Z 0x40 +#define F_5 0x20 +#define F_H 0x10 +#define F_3 0x08 +#define F_PV 0x04 +#define F_N 0x02 +#define F_C 0x01 + +//enum Z80free_prefix {Z80XX, Z80CB, Z80DD, Z80ED, Z80FD}; + + +typedef union { + /** Word registers. */ + struct + { + word AF, BC, DE, HL, IX, IY, SP; + } wr; + + /** Byte registers. SP can be accessed partially to simplify the load/save code. */ + + +#if BYTE_ORDER == LITTLE_ENDIAN + struct + { + byte F,A, C,B, E,D, L,H, IXl,IXh, IYl,IYh, P,S; + } br; +#else + + struct + { + byte A,F, B,C, D,E, H,L, IXh,IXl, IYh,IYl, S,P; + } br; + +#endif + +} Z80FRegs; + +/** A Z80 execution context. */ +typedef struct +{ + Z80FRegs Ra; /* Alternate register set (R) */ + Z80FRegs Rm; /* Main register set (R) */ + word PC; /* Program counter */ + byte R; /* Refresh */ + byte R2; /* Upper bit for Refresh */ + byte I; + byte IFF1; /* Interrupt Flipflop 1. If it's 2, decrement it and don't allow INT */ + byte IFF2; /* Interrupt Flipflop 2 */ + byte IM; /* Interrupt mode */ + byte HALT; /* HALT status */ + byte INT_P; /* INT pending */ + byte NMI_P; /* NMI pending */ + byte empty_bus; /* value for empty bus when procesing a maskable int */ + word IAddr; /* address with offset for IX+d and IY+d */ + byte IAddr_done; /* if 1, IAddr contains a valid data */ + enum {Z80XX, Z80CB, Z80DD, Z80ED, Z80FD, Z80INT} Status; +} Z80FREE; + +/* internal Z80 methods */ + +void Z80free_setFlag(Z80FREE *processor, byte flag); +void Z80free_resFlag(Z80FREE *processor, byte flag); +void Z80free_valFlag(Z80FREE *processor, byte flag, int val); +int Z80free_getFlag(Z80FREE *processor, byte flag); +void Z80free_adjustFlags (Z80FREE *processor, byte val); +void Z80free_adjustFlagSZP (Z80FREE *processor, byte val); +void Z80free_adjustLogicFlag (Z80FREE *processor, int flagH); +byte Z80free_doArithmetic (Z80FREE *processor, byte value1,byte value2, int withCarry, int isSub); +word Z80free_doArithmetic16 (Z80FREE *processor, word value1,word value2, int withCarry, int isSub); +void Z80free_doAND (Z80FREE *processor, byte value); +void Z80free_doOR (Z80FREE *processor, byte value); +void Z80free_doXOR (Z80FREE *processor, byte value); +void Z80free_doBIT (Z80FREE *processor, int b, byte val); +byte Z80free_doSetRes (Z80FREE *processor, int bit, int pos, byte val); +byte Z80free_doIncDec (Z80FREE *processor, byte val, int isDec); +word Z80free_doIncDec16 (Z80FREE *processor, word val, int isDec); +byte Z80free_doRLC (Z80FREE *processor, int adjFlags, byte val); +byte Z80free_doRL (Z80FREE *processor, int adjFlags, byte val); +byte Z80free_doRRC (Z80FREE *processor, int adjFlags, byte val); +byte Z80free_doRR (Z80FREE *processor, int adjFlags, byte val); +byte Z80free_doSL (Z80FREE *processor, int isArith, byte val); +byte Z80free_doSR (Z80FREE *processor, int isArith, byte val); +void Z80free_doPush (Z80FREE *processor, word val); +word Z80free_doPop (Z80FREE *processor); +void Z80free_doDAA (Z80FREE *processor); +byte Z80free_readR(Z80FREE *processor); +void Z80free_setR(Z80FREE *processor,byte value); +byte Z80free_readI(Z80FREE *processor); +void Z80free_doRRD(Z80FREE *processor); +void Z80free_doRLD(Z80FREE *processor); + +void Z80free_jump_relative(Z80FREE *processor,byte relvar); +word Z80free_addr_relative(Z80FREE *processor,word address); +word Z80free_addr_relativeXDCB(Z80FREE *processor,word address,byte d1); +byte Z80free_read_param_8(Z80FREE *z80); +word Z80free_read_param_16(Z80FREE *z80); +word Z80free_read16 (register word addr); +void Z80free_write16 (register word addr,register word val); + +/* external Z80 methods */ + +void Z80free_reset(Z80FREE *); +int Z80free_step(Z80FREE *); +int Z80free_ustep(Z80FREE *); +void Z80free_INT(Z80FREE *,byte); + +byte Z80free_Rd (register word Addr); +byte Z80free_Rd_fetch (register word Addr); +void Z80free_Wr (register word Addr, register byte Value); +void Z80free_Wr_fake (register word Addr, register byte Value); +byte Z80free_In (register word Port); +void Z80free_Out (register word Port, register byte Value); +void Z80free_Out_fake (register word Port, register byte Value); + +/* Opcode functions */ + +int Z80free_codes (Z80FREE *processor,byte opcode); +int Z80free_codesCB (Z80FREE *processor,byte opcode); +int Z80free_codesDD (Z80FREE *processor,byte opcode); +int Z80free_codesED (Z80FREE *processor,byte opcode); +int Z80free_codesFD (Z80FREE *processor,byte opcode); +int Z80free_codesDDCB (Z80FREE *processor,byte d1); +int Z80free_codesFDCB (Z80FREE *processor,byte d1); + +#endif diff --git a/src/z80free/Z80free_codesDDCB.c b/src/z80free/Z80free_codesDDCB.c index 8baecb3..333f51b 100644 --- a/src/z80free/Z80free_codesDDCB.c +++ b/src/z80free/Z80free_codesDDCB.c @@ -1,1520 +1,1520 @@ -/* - * Copyright (C) 2008-2009 Sergio Costas (Raster Software Vigo) - * This file is part of Z80Free - * - * Z80Free is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Z80Free is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "Z80free.h" - -int Z80free_codesDDCB (Z80FREE *processor,byte d1) { - static byte tmp1; - static word tmp2; - static byte opcode; - opcode=Z80free_Rd(processor->PC++); - - switch(opcode) { - case 0: // LD_RLC B,(IX+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 1: // LD_RLC C,(IX+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 2: // LD_RLC D,(IX+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 3: // LD_RLC E,(IX+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 4: // LD_RLC H,(IX+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 5: // LD_RLC L,(IX+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 6: // RLC b(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 7: // LD_RLC A,(IX+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 8: // LD_RRC B,(IX+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 9: // LD_RRC C,(IX+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 10: // LD_RRC D,(IX+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 11: // LD_RRC E,(IX+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 12: // LD_RRC H,(IX+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 13: // LD_RRC L,(IX+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 14: // RRC b(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 15: // LD_RRC A,(IX+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 16: // LD_RL B,(IX+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 17: // LD_RL C,(IX+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 18: // LD_RL D,(IX+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 19: // LD_RL E,(IX+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 20: // LD_RL H,(IX+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 21: // LD_RL L,(IX+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 22: // RL b(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 23: // LD_RL A,(IX+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 24: // LD_RR B,(IX+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 25: // LD_RR C,(IX+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 26: // LD_RR D,(IX+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 27: // LD_RR E,(IX+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 28: // LD_RR H,(IX+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 29: // LD_RR L,(IX+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 30: // RR b(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 31: // LD_RR A,(IX+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 32: // LD_SLA B,(IX+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 33: // LD_SLA C,(IX+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 34: // LD_SLA D,(IX+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 35: // LD_SLA E,(IX+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 36: // LD_SLA H,(IX+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 37: // LD_SLA L,(IX+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 38: // SLA b(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 39: // LD_SLA A,(IX+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 40: // LD_SRA B,(IX+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 41: // LD_SRA C,(IX+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 42: // LD_SRA D,(IX+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 43: // LD_SRA E,(IX+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 44: // LD_SRA H,(IX+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 45: // LD_SRA L,(IX+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 46: // SRA b(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 47: // LD_SRA A,(IX+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 48: // LD_SLL B,(IX+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 49: // LD_SLL C,(IX+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 50: // LD_SLL D,(IX+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 51: // LD_SLL E,(IX+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 52: // LD_SLL H,(IX+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 53: // LD_SLL L,(IX+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 54: // SLL b(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 55: // LD_SLL A,(IX+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 56: // LD_SRL B,(IX+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 57: // LD_SRL C,(IX+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 58: // LD_SRL D,(IX+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 59: // LD_SRL E,(IX+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 60: // LD_SRL H,(IX+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 61: // LD_SRL L,(IX+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 62: // SRL b(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 63: // LD_SRL A,(IX+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - return (19); - break; - case 64: // BIT 0,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 65: // BIT 0,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 66: // BIT 0,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 67: // BIT 0,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 68: // BIT 0,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 69: // BIT 0,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 70: // BIT 0,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 71: // BIT 0,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 72: // BIT 1,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 73: // BIT 1,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 74: // BIT 1,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 75: // BIT 1,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 76: // BIT 1,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 77: // BIT 1,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 78: // BIT 1,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 79: // BIT 1,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 80: // BIT 2,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 81: // BIT 2,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 82: // BIT 2,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 83: // BIT 2,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 84: // BIT 2,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 85: // BIT 2,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 86: // BIT 2,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 87: // BIT 2,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 88: // BIT 3,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 89: // BIT 3,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 90: // BIT 3,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 91: // BIT 3,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 92: // BIT 3,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 93: // BIT 3,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 94: // BIT 3,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 95: // BIT 3,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 96: // BIT 4,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 97: // BIT 4,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 98: // BIT 4,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 99: // BIT 4,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 100: // BIT 4,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 101: // BIT 4,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 102: // BIT 4,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 103: // BIT 4,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 104: // BIT 5,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 105: // BIT 5,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 106: // BIT 5,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 107: // BIT 5,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 108: // BIT 5,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 109: // BIT 5,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 110: // BIT 5,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 111: // BIT 5,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 112: // BIT 6,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 113: // BIT 6,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 114: // BIT 6,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 115: // BIT 6,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 116: // BIT 6,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 117: // BIT 6,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 118: // BIT 6,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 119: // BIT 6,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 120: // BIT 7,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 121: // BIT 7,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 122: // BIT 7,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 123: // BIT 7,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 124: // BIT 7,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 125: // BIT 7,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 126: // BIT 7,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 127: // BIT 7,(IX+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 128: // LD_RES B,0,(IX+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 129: // LD_RES C,0,(IX+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 130: // LD_RES D,0,(IX+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 131: // LD_RES E,0,(IX+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 132: // LD_RES H,0,(IX+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 133: // LD_RES L,0,(IX+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 134: // RES 0,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 135: // LD_RES A,0,(IX+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 136: // LD_RES B,1,(IX+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 137: // LD_RES C,1,(IX+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 138: // LD_RES D,1,(IX+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 139: // LD_RES E,1,(IX+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 140: // LD_RES H,1,(IX+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 141: // LD_RES L,1,(IX+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 142: // RES 1,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 143: // LD_RES A,1,(IX+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 144: // LD_RES B,2,(IX+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 145: // LD_RES C,2,(IX+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 146: // LD_RES D,2,(IX+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 147: // LD_RES E,2,(IX+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 148: // LD_RES H,2,(IX+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 149: // LD_RES L,2,(IX+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 150: // RES 2,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 151: // LD_RES A,2,(IX+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 152: // LD_RES B,3,(IX+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 153: // LD_RES C,3,(IX+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 154: // LD_RES D,3,(IX+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 155: // LD_RES E,3,(IX+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 156: // LD_RES H,3,(IX+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 157: // LD_RES L,3,(IX+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 158: // RES 3,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 159: // LD_RES A,3,(IX+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 160: // LD_RES B,4,(IX+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 161: // LD_RES C,4,(IX+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 162: // LD_RES D,4,(IX+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 163: // LD_RES E,4,(IX+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 164: // LD_RES H,4,(IX+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 165: // LD_RES L,4,(IX+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 166: // RES 4,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 167: // LD_RES A,4,(IX+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 168: // LD_RES B,5,(IX+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 169: // LD_RES C,5,(IX+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 170: // LD_RES D,5,(IX+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 171: // LD_RES E,5,(IX+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 172: // LD_RES H,5,(IX+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 173: // LD_RES L,5,(IX+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 174: // RES 5,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 175: // LD_RES A,5,(IX+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 176: // LD_RES B,6,(IX+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 177: // LD_RES C,6,(IX+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 178: // LD_RES D,6,(IX+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 179: // LD_RES E,6,(IX+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 180: // LD_RES H,6,(IX+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 181: // LD_RES L,6,(IX+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 182: // RES 6,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 183: // LD_RES A,6,(IX+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 184: // LD_RES B,7,(IX+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 185: // LD_RES C,7,(IX+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 186: // LD_RES D,7,(IX+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 187: // LD_RES E,7,(IX+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 188: // LD_RES H,7,(IX+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 189: // LD_RES L,7,(IX+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 190: // RES 7,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 191: // LD_RES A,7,(IX+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 192: // LD_SET B,0,(IX+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 193: // LD_SET C,0,(IX+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 194: // LD_SET D,0,(IX+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 195: // LD_SET E,0,(IX+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 196: // LD_SET H,0,(IX+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 197: // LD_SET L,0,(IX+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 198: // SET 0,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 199: // LD_SET A,0,(IX+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 200: // LD_SET B,1,(IX+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 201: // LD_SET C,1,(IX+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 202: // LD_SET D,1,(IX+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 203: // LD_SET E,1,(IX+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 204: // LD_SET H,1,(IX+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 205: // LD_SET L,1,(IX+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 206: // SET 1,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 207: // LD_SET A,1,(IX+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 208: // LD_SET B,2,(IX+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 209: // LD_SET C,2,(IX+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 210: // LD_SET D,2,(IX+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 211: // LD_SET E,2,(IX+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 212: // LD_SET H,2,(IX+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 213: // LD_SET L,2,(IX+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 214: // SET 2,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 215: // LD_SET A,2,(IX+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 216: // LD_SET B,3,(IX+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 217: // LD_SET C,3,(IX+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 218: // LD_SET D,3,(IX+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 219: // LD_SET E,3,(IX+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 220: // LD_SET H,3,(IX+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 221: // LD_SET L,3,(IX+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 222: // SET 3,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 223: // LD_SET A,3,(IX+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 224: // LD_SET B,4,(IX+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 225: // LD_SET C,4,(IX+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 226: // LD_SET D,4,(IX+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 227: // LD_SET E,4,(IX+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 228: // LD_SET H,4,(IX+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 229: // LD_SET L,4,(IX+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 230: // SET 4,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 231: // LD_SET A,4,(IX+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 232: // LD_SET B,5,(IX+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 233: // LD_SET C,5,(IX+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 234: // LD_SET D,5,(IX+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 235: // LD_SET E,5,(IX+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 236: // LD_SET H,5,(IX+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 237: // LD_SET L,5,(IX+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 238: // SET 5,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 239: // LD_SET A,5,(IX+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 240: // LD_SET B,6,(IX+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 241: // LD_SET C,6,(IX+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 242: // LD_SET D,6,(IX+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 243: // LD_SET E,6,(IX+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 244: // LD_SET H,6,(IX+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 245: // LD_SET L,6,(IX+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 246: // SET 6,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 247: // LD_SET A,6,(IX+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 248: // LD_SET B,7,(IX+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 249: // LD_SET C,7,(IX+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 250: // LD_SET D,7,(IX+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 251: // LD_SET E,7,(IX+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 252: // LD_SET H,7,(IX+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 253: // LD_SET L,7,(IX+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 254: // SET 7,(IX+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); - return (19); - break; - case 255: // LD_SET A,7,(IX+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - } - - return -1; -} +/* + * Copyright (C) 2008-2009 Sergio Costas (Raster Software Vigo) + * This file is part of Z80Free + * + * Z80Free is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Z80Free is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "Z80free.h" + +int Z80free_codesDDCB (Z80FREE *processor,byte d1) { + static byte tmp1; + static word tmp2; + static byte opcode; + opcode=Z80free_Rd_fetch(processor->PC++); + + switch(opcode) { + case 0: // LD_RLC B,(IX+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 1: // LD_RLC C,(IX+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 2: // LD_RLC D,(IX+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 3: // LD_RLC E,(IX+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 4: // LD_RLC H,(IX+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 5: // LD_RLC L,(IX+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 6: // RLC b(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 7: // LD_RLC A,(IX+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 8: // LD_RRC B,(IX+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 9: // LD_RRC C,(IX+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 10: // LD_RRC D,(IX+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 11: // LD_RRC E,(IX+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 12: // LD_RRC H,(IX+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 13: // LD_RRC L,(IX+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 14: // RRC b(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 15: // LD_RRC A,(IX+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 16: // LD_RL B,(IX+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 17: // LD_RL C,(IX+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 18: // LD_RL D,(IX+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 19: // LD_RL E,(IX+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 20: // LD_RL H,(IX+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 21: // LD_RL L,(IX+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 22: // RL b(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 23: // LD_RL A,(IX+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 24: // LD_RR B,(IX+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 25: // LD_RR C,(IX+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 26: // LD_RR D,(IX+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 27: // LD_RR E,(IX+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 28: // LD_RR H,(IX+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 29: // LD_RR L,(IX+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 30: // RR b(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 31: // LD_RR A,(IX+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 32: // LD_SLA B,(IX+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 33: // LD_SLA C,(IX+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 34: // LD_SLA D,(IX+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 35: // LD_SLA E,(IX+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 36: // LD_SLA H,(IX+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 37: // LD_SLA L,(IX+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 38: // SLA b(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 39: // LD_SLA A,(IX+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 40: // LD_SRA B,(IX+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 41: // LD_SRA C,(IX+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 42: // LD_SRA D,(IX+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 43: // LD_SRA E,(IX+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 44: // LD_SRA H,(IX+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 45: // LD_SRA L,(IX+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 46: // SRA b(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 47: // LD_SRA A,(IX+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 48: // LD_SLL B,(IX+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 49: // LD_SLL C,(IX+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 50: // LD_SLL D,(IX+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 51: // LD_SLL E,(IX+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 52: // LD_SLL H,(IX+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 53: // LD_SLL L,(IX+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 54: // SLL b(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 55: // LD_SLL A,(IX+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 56: // LD_SRL B,(IX+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 57: // LD_SRL C,(IX+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 58: // LD_SRL D,(IX+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 59: // LD_SRL E,(IX+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 60: // LD_SRL H,(IX+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 61: // LD_SRL L,(IX+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 62: // SRL b(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 63: // LD_SRL A,(IX+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + return (19); + break; + case 64: // BIT 0,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 65: // BIT 0,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 66: // BIT 0,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 67: // BIT 0,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 68: // BIT 0,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 69: // BIT 0,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 70: // BIT 0,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 71: // BIT 0,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 72: // BIT 1,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 73: // BIT 1,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 74: // BIT 1,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 75: // BIT 1,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 76: // BIT 1,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 77: // BIT 1,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 78: // BIT 1,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 79: // BIT 1,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 80: // BIT 2,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 81: // BIT 2,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 82: // BIT 2,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 83: // BIT 2,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 84: // BIT 2,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 85: // BIT 2,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 86: // BIT 2,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 87: // BIT 2,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 88: // BIT 3,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 89: // BIT 3,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 90: // BIT 3,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 91: // BIT 3,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 92: // BIT 3,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 93: // BIT 3,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 94: // BIT 3,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 95: // BIT 3,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 96: // BIT 4,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 97: // BIT 4,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 98: // BIT 4,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 99: // BIT 4,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 100: // BIT 4,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 101: // BIT 4,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 102: // BIT 4,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 103: // BIT 4,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 104: // BIT 5,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 105: // BIT 5,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 106: // BIT 5,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 107: // BIT 5,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 108: // BIT 5,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 109: // BIT 5,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 110: // BIT 5,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 111: // BIT 5,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 112: // BIT 6,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 113: // BIT 6,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 114: // BIT 6,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 115: // BIT 6,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 116: // BIT 6,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 117: // BIT 6,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 118: // BIT 6,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 119: // BIT 6,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 120: // BIT 7,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 121: // BIT 7,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 122: // BIT 7,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 123: // BIT 7,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 124: // BIT 7,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 125: // BIT 7,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 126: // BIT 7,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 127: // BIT 7,(IX+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 128: // LD_RES B,0,(IX+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 129: // LD_RES C,0,(IX+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 130: // LD_RES D,0,(IX+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 131: // LD_RES E,0,(IX+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 132: // LD_RES H,0,(IX+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 133: // LD_RES L,0,(IX+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 134: // RES 0,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 135: // LD_RES A,0,(IX+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 136: // LD_RES B,1,(IX+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 137: // LD_RES C,1,(IX+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 138: // LD_RES D,1,(IX+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 139: // LD_RES E,1,(IX+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 140: // LD_RES H,1,(IX+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 141: // LD_RES L,1,(IX+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 142: // RES 1,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 143: // LD_RES A,1,(IX+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 144: // LD_RES B,2,(IX+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 145: // LD_RES C,2,(IX+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 146: // LD_RES D,2,(IX+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 147: // LD_RES E,2,(IX+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 148: // LD_RES H,2,(IX+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 149: // LD_RES L,2,(IX+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 150: // RES 2,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 151: // LD_RES A,2,(IX+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 152: // LD_RES B,3,(IX+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 153: // LD_RES C,3,(IX+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 154: // LD_RES D,3,(IX+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 155: // LD_RES E,3,(IX+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 156: // LD_RES H,3,(IX+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 157: // LD_RES L,3,(IX+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 158: // RES 3,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 159: // LD_RES A,3,(IX+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 160: // LD_RES B,4,(IX+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 161: // LD_RES C,4,(IX+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 162: // LD_RES D,4,(IX+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 163: // LD_RES E,4,(IX+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 164: // LD_RES H,4,(IX+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 165: // LD_RES L,4,(IX+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 166: // RES 4,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 167: // LD_RES A,4,(IX+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 168: // LD_RES B,5,(IX+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 169: // LD_RES C,5,(IX+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 170: // LD_RES D,5,(IX+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 171: // LD_RES E,5,(IX+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 172: // LD_RES H,5,(IX+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 173: // LD_RES L,5,(IX+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 174: // RES 5,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 175: // LD_RES A,5,(IX+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 176: // LD_RES B,6,(IX+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 177: // LD_RES C,6,(IX+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 178: // LD_RES D,6,(IX+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 179: // LD_RES E,6,(IX+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 180: // LD_RES H,6,(IX+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 181: // LD_RES L,6,(IX+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 182: // RES 6,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 183: // LD_RES A,6,(IX+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 184: // LD_RES B,7,(IX+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 185: // LD_RES C,7,(IX+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 186: // LD_RES D,7,(IX+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 187: // LD_RES E,7,(IX+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 188: // LD_RES H,7,(IX+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 189: // LD_RES L,7,(IX+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 190: // RES 7,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 191: // LD_RES A,7,(IX+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 192: // LD_SET B,0,(IX+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 193: // LD_SET C,0,(IX+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 194: // LD_SET D,0,(IX+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 195: // LD_SET E,0,(IX+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 196: // LD_SET H,0,(IX+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 197: // LD_SET L,0,(IX+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 198: // SET 0,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 199: // LD_SET A,0,(IX+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 200: // LD_SET B,1,(IX+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 201: // LD_SET C,1,(IX+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 202: // LD_SET D,1,(IX+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 203: // LD_SET E,1,(IX+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 204: // LD_SET H,1,(IX+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 205: // LD_SET L,1,(IX+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 206: // SET 1,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 207: // LD_SET A,1,(IX+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 208: // LD_SET B,2,(IX+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 209: // LD_SET C,2,(IX+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 210: // LD_SET D,2,(IX+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 211: // LD_SET E,2,(IX+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 212: // LD_SET H,2,(IX+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 213: // LD_SET L,2,(IX+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 214: // SET 2,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 215: // LD_SET A,2,(IX+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 216: // LD_SET B,3,(IX+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 217: // LD_SET C,3,(IX+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 218: // LD_SET D,3,(IX+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 219: // LD_SET E,3,(IX+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 220: // LD_SET H,3,(IX+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 221: // LD_SET L,3,(IX+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 222: // SET 3,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 223: // LD_SET A,3,(IX+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 224: // LD_SET B,4,(IX+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 225: // LD_SET C,4,(IX+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 226: // LD_SET D,4,(IX+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 227: // LD_SET E,4,(IX+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 228: // LD_SET H,4,(IX+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 229: // LD_SET L,4,(IX+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 230: // SET 4,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 231: // LD_SET A,4,(IX+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 232: // LD_SET B,5,(IX+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 233: // LD_SET C,5,(IX+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 234: // LD_SET D,5,(IX+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 235: // LD_SET E,5,(IX+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 236: // LD_SET H,5,(IX+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 237: // LD_SET L,5,(IX+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 238: // SET 5,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 239: // LD_SET A,5,(IX+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 240: // LD_SET B,6,(IX+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 241: // LD_SET C,6,(IX+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 242: // LD_SET D,6,(IX+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 243: // LD_SET E,6,(IX+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 244: // LD_SET H,6,(IX+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 245: // LD_SET L,6,(IX+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 246: // SET 6,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 247: // LD_SET A,6,(IX+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 248: // LD_SET B,7,(IX+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 249: // LD_SET C,7,(IX+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 250: // LD_SET D,7,(IX+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 251: // LD_SET E,7,(IX+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 252: // LD_SET H,7,(IX+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 253: // LD_SET L,7,(IX+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 254: // SET 7,(IX+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1)))); + return (19); + break; + case 255: // LD_SET A,7,(IX+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IX,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + } + + return -1; +} diff --git a/src/z80free/Z80free_codesFDCB.c b/src/z80free/Z80free_codesFDCB.c index cd07d8f..0ac1428 100644 --- a/src/z80free/Z80free_codesFDCB.c +++ b/src/z80free/Z80free_codesFDCB.c @@ -1,1520 +1,1520 @@ -/* - * Copyright (C) 2008-2009 Sergio Costas (Raster Software Vigo) - * This file is part of Z80Free - * - * Z80Free is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Z80Free is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "Z80free.h" - -int Z80free_codesFDCB (Z80FREE *processor,byte d1) { - static byte tmp1; - static word tmp2; - static byte opcode; - opcode=Z80free_Rd(processor->PC++); - - switch(opcode) { - case 0: // LD_RLC B,(IY+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 1: // LD_RLC C,(IY+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 2: // LD_RLC D,(IY+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 3: // LD_RLC E,(IY+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 4: // LD_RLC H,(IY+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 5: // LD_RLC L,(IY+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 6: // RLC b(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 7: // LD_RLC A,(IY+d) - tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 8: // LD_RRC B,(IY+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 9: // LD_RRC C,(IY+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 10: // LD_RRC D,(IY+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 11: // LD_RRC E,(IY+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 12: // LD_RRC H,(IY+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 13: // LD_RRC L,(IY+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 14: // RRC b(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 15: // LD_RRC A,(IY+d) - tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 16: // LD_RL B,(IY+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 17: // LD_RL C,(IY+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 18: // LD_RL D,(IY+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 19: // LD_RL E,(IY+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 20: // LD_RL H,(IY+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 21: // LD_RL L,(IY+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 22: // RL b(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 23: // LD_RL A,(IY+d) - tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 24: // LD_RR B,(IY+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 25: // LD_RR C,(IY+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 26: // LD_RR D,(IY+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 27: // LD_RR E,(IY+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 28: // LD_RR H,(IY+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 29: // LD_RR L,(IY+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 30: // RR b(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 31: // LD_RR A,(IY+d) - tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 32: // LD_SLA B,(IY+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 33: // LD_SLA C,(IY+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 34: // LD_SLA D,(IY+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 35: // LD_SLA E,(IY+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 36: // LD_SLA H,(IY+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 37: // LD_SLA L,(IY+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 38: // SLA b(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 39: // LD_SLA A,(IY+d) - tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 40: // LD_SRA B,(IY+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 41: // LD_SRA C,(IY+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 42: // LD_SRA D,(IY+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 43: // LD_SRA E,(IY+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 44: // LD_SRA H,(IY+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 45: // LD_SRA L,(IY+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 46: // SRA b(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 47: // LD_SRA A,(IY+d) - tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 48: // LD_SLL B,(IY+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 49: // LD_SLL C,(IY+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 50: // LD_SLL D,(IY+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 51: // LD_SLL E,(IY+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 52: // LD_SLL H,(IY+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 53: // LD_SLL L,(IY+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 54: // SLL b(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 55: // LD_SLL A,(IY+d) - tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 56: // LD_SRL B,(IY+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.B=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 57: // LD_SRL C,(IY+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.C=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 58: // LD_SRL D,(IY+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.D=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 59: // LD_SRL E,(IY+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.E=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 60: // LD_SRL H,(IY+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.H=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 61: // LD_SRL L,(IY+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.L=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 62: // SRL b(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 63: // LD_SRL A,(IY+d) - tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - processor->Rm.br.A=tmp1; - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - return (19); - break; - case 64: // BIT 0,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 65: // BIT 0,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 66: // BIT 0,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 67: // BIT 0,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 68: // BIT 0,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 69: // BIT 0,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 70: // BIT 0,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 71: // BIT 0,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 72: // BIT 1,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 73: // BIT 1,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 74: // BIT 1,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 75: // BIT 1,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 76: // BIT 1,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 77: // BIT 1,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 78: // BIT 1,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 79: // BIT 1,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 80: // BIT 2,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 81: // BIT 2,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 82: // BIT 2,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 83: // BIT 2,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 84: // BIT 2,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 85: // BIT 2,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 86: // BIT 2,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 87: // BIT 2,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 88: // BIT 3,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 89: // BIT 3,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 90: // BIT 3,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 91: // BIT 3,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 92: // BIT 3,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 93: // BIT 3,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 94: // BIT 3,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 95: // BIT 3,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 96: // BIT 4,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 97: // BIT 4,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 98: // BIT 4,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 99: // BIT 4,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 100: // BIT 4,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 101: // BIT 4,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 102: // BIT 4,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 103: // BIT 4,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 104: // BIT 5,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 105: // BIT 5,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 106: // BIT 5,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 107: // BIT 5,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 108: // BIT 5,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 109: // BIT 5,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 110: // BIT 5,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 111: // BIT 5,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 112: // BIT 6,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 113: // BIT 6,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 114: // BIT 6,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 115: // BIT 6,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 116: // BIT 6,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 117: // BIT 6,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 118: // BIT 6,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 119: // BIT 6,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 120: // BIT 7,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 121: // BIT 7,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 122: // BIT 7,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 123: // BIT 7,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 124: // BIT 7,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 125: // BIT 7,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 126: // BIT 7,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 127: // BIT 7,(IY+d) - tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); - Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); - Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); - return (16); - break; - case 128: // LD_RES B,0,(IY+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 129: // LD_RES C,0,(IY+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 130: // LD_RES D,0,(IY+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 131: // LD_RES E,0,(IY+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 132: // LD_RES H,0,(IY+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 133: // LD_RES L,0,(IY+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 134: // RES 0,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 135: // LD_RES A,0,(IY+d) - tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 136: // LD_RES B,1,(IY+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 137: // LD_RES C,1,(IY+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 138: // LD_RES D,1,(IY+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 139: // LD_RES E,1,(IY+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 140: // LD_RES H,1,(IY+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 141: // LD_RES L,1,(IY+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 142: // RES 1,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 143: // LD_RES A,1,(IY+d) - tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 144: // LD_RES B,2,(IY+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 145: // LD_RES C,2,(IY+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 146: // LD_RES D,2,(IY+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 147: // LD_RES E,2,(IY+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 148: // LD_RES H,2,(IY+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 149: // LD_RES L,2,(IY+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 150: // RES 2,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 151: // LD_RES A,2,(IY+d) - tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 152: // LD_RES B,3,(IY+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 153: // LD_RES C,3,(IY+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 154: // LD_RES D,3,(IY+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 155: // LD_RES E,3,(IY+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 156: // LD_RES H,3,(IY+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 157: // LD_RES L,3,(IY+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 158: // RES 3,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 159: // LD_RES A,3,(IY+d) - tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 160: // LD_RES B,4,(IY+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 161: // LD_RES C,4,(IY+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 162: // LD_RES D,4,(IY+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 163: // LD_RES E,4,(IY+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 164: // LD_RES H,4,(IY+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 165: // LD_RES L,4,(IY+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 166: // RES 4,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 167: // LD_RES A,4,(IY+d) - tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 168: // LD_RES B,5,(IY+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 169: // LD_RES C,5,(IY+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 170: // LD_RES D,5,(IY+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 171: // LD_RES E,5,(IY+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 172: // LD_RES H,5,(IY+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 173: // LD_RES L,5,(IY+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 174: // RES 5,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 175: // LD_RES A,5,(IY+d) - tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 176: // LD_RES B,6,(IY+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 177: // LD_RES C,6,(IY+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 178: // LD_RES D,6,(IY+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 179: // LD_RES E,6,(IY+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 180: // LD_RES H,6,(IY+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 181: // LD_RES L,6,(IY+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 182: // RES 6,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 183: // LD_RES A,6,(IY+d) - tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 184: // LD_RES B,7,(IY+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 185: // LD_RES C,7,(IY+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 186: // LD_RES D,7,(IY+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 187: // LD_RES E,7,(IY+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 188: // LD_RES H,7,(IY+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 189: // LD_RES L,7,(IY+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 190: // RES 7,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 191: // LD_RES A,7,(IY+d) - tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 192: // LD_SET B,0,(IY+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 193: // LD_SET C,0,(IY+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 194: // LD_SET D,0,(IY+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 195: // LD_SET E,0,(IY+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 196: // LD_SET H,0,(IY+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 197: // LD_SET L,0,(IY+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 198: // SET 0,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 199: // LD_SET A,0,(IY+d) - tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 200: // LD_SET B,1,(IY+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 201: // LD_SET C,1,(IY+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 202: // LD_SET D,1,(IY+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 203: // LD_SET E,1,(IY+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 204: // LD_SET H,1,(IY+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 205: // LD_SET L,1,(IY+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 206: // SET 1,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 207: // LD_SET A,1,(IY+d) - tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 208: // LD_SET B,2,(IY+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 209: // LD_SET C,2,(IY+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 210: // LD_SET D,2,(IY+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 211: // LD_SET E,2,(IY+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 212: // LD_SET H,2,(IY+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 213: // LD_SET L,2,(IY+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 214: // SET 2,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 215: // LD_SET A,2,(IY+d) - tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 216: // LD_SET B,3,(IY+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 217: // LD_SET C,3,(IY+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 218: // LD_SET D,3,(IY+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 219: // LD_SET E,3,(IY+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 220: // LD_SET H,3,(IY+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 221: // LD_SET L,3,(IY+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 222: // SET 3,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 223: // LD_SET A,3,(IY+d) - tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 224: // LD_SET B,4,(IY+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 225: // LD_SET C,4,(IY+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 226: // LD_SET D,4,(IY+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 227: // LD_SET E,4,(IY+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 228: // LD_SET H,4,(IY+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 229: // LD_SET L,4,(IY+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 230: // SET 4,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 231: // LD_SET A,4,(IY+d) - tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 232: // LD_SET B,5,(IY+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 233: // LD_SET C,5,(IY+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 234: // LD_SET D,5,(IY+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 235: // LD_SET E,5,(IY+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 236: // LD_SET H,5,(IY+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 237: // LD_SET L,5,(IY+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 238: // SET 5,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 239: // LD_SET A,5,(IY+d) - tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 240: // LD_SET B,6,(IY+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 241: // LD_SET C,6,(IY+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 242: // LD_SET D,6,(IY+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 243: // LD_SET E,6,(IY+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 244: // LD_SET H,6,(IY+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 245: // LD_SET L,6,(IY+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 246: // SET 6,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 247: // LD_SET A,6,(IY+d) - tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - case 248: // LD_SET B,7,(IY+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.B=tmp1; - return (19); - break; - case 249: // LD_SET C,7,(IY+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.C=tmp1; - return (19); - break; - case 250: // LD_SET D,7,(IY+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.D=tmp1; - return (19); - break; - case 251: // LD_SET E,7,(IY+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.E=tmp1; - return (19); - break; - case 252: // LD_SET H,7,(IY+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.H=tmp1; - return (19); - break; - case 253: // LD_SET L,7,(IY+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.L=tmp1; - return (19); - break; - case 254: // SET 7,(IY+d) - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); - return (19); - break; - case 255: // LD_SET A,7,(IY+d) - tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); - Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); - processor->Rm.br.A=tmp1; - return (19); - break; - } - - return -1; -} +/* + * Copyright (C) 2008-2009 Sergio Costas (Raster Software Vigo) + * This file is part of Z80Free + * + * Z80Free is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Z80Free is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "Z80free.h" + +int Z80free_codesFDCB (Z80FREE *processor,byte d1) { + static byte tmp1; + static word tmp2; + static byte opcode; + opcode=Z80free_Rd_fetch(processor->PC++); + + switch(opcode) { + case 0: // LD_RLC B,(IY+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 1: // LD_RLC C,(IY+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 2: // LD_RLC D,(IY+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 3: // LD_RLC E,(IY+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 4: // LD_RLC H,(IY+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 5: // LD_RLC L,(IY+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 6: // RLC b(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 7: // LD_RLC A,(IY+d) + tmp1=Z80free_doRLC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 8: // LD_RRC B,(IY+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 9: // LD_RRC C,(IY+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 10: // LD_RRC D,(IY+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 11: // LD_RRC E,(IY+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 12: // LD_RRC H,(IY+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 13: // LD_RRC L,(IY+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 14: // RRC b(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 15: // LD_RRC A,(IY+d) + tmp1=Z80free_doRRC(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 16: // LD_RL B,(IY+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 17: // LD_RL C,(IY+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 18: // LD_RL D,(IY+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 19: // LD_RL E,(IY+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 20: // LD_RL H,(IY+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 21: // LD_RL L,(IY+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 22: // RL b(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 23: // LD_RL A,(IY+d) + tmp1=Z80free_doRL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 24: // LD_RR B,(IY+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 25: // LD_RR C,(IY+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 26: // LD_RR D,(IY+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 27: // LD_RR E,(IY+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 28: // LD_RR H,(IY+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 29: // LD_RR L,(IY+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 30: // RR b(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 31: // LD_RR A,(IY+d) + tmp1=Z80free_doRR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 32: // LD_SLA B,(IY+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 33: // LD_SLA C,(IY+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 34: // LD_SLA D,(IY+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 35: // LD_SLA E,(IY+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 36: // LD_SLA H,(IY+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 37: // LD_SLA L,(IY+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 38: // SLA b(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 39: // LD_SLA A,(IY+d) + tmp1=Z80free_doSL(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 40: // LD_SRA B,(IY+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 41: // LD_SRA C,(IY+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 42: // LD_SRA D,(IY+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 43: // LD_SRA E,(IY+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 44: // LD_SRA H,(IY+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 45: // LD_SRA L,(IY+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 46: // SRA b(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 47: // LD_SRA A,(IY+d) + tmp1=Z80free_doSR(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 48: // LD_SLL B,(IY+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 49: // LD_SLL C,(IY+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 50: // LD_SLL D,(IY+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 51: // LD_SLL E,(IY+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 52: // LD_SLL H,(IY+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 53: // LD_SLL L,(IY+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 54: // SLL b(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 55: // LD_SLL A,(IY+d) + tmp1=Z80free_doSL(processor,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 56: // LD_SRL B,(IY+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.B=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 57: // LD_SRL C,(IY+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.C=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 58: // LD_SRL D,(IY+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.D=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 59: // LD_SRL E,(IY+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.E=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 60: // LD_SRL H,(IY+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.H=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 61: // LD_SRL L,(IY+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.L=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 62: // SRL b(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 63: // LD_SRL A,(IY+d) + tmp1=Z80free_doSR(processor,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + processor->Rm.br.A=tmp1; + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + return (19); + break; + case 64: // BIT 0,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 65: // BIT 0,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 66: // BIT 0,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 67: // BIT 0,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 68: // BIT 0,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 69: // BIT 0,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 70: // BIT 0,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 71: // BIT 0,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,0,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 72: // BIT 1,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 73: // BIT 1,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 74: // BIT 1,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 75: // BIT 1,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 76: // BIT 1,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 77: // BIT 1,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 78: // BIT 1,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 79: // BIT 1,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,1,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 80: // BIT 2,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 81: // BIT 2,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 82: // BIT 2,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 83: // BIT 2,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 84: // BIT 2,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 85: // BIT 2,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 86: // BIT 2,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 87: // BIT 2,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,2,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 88: // BIT 3,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 89: // BIT 3,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 90: // BIT 3,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 91: // BIT 3,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 92: // BIT 3,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 93: // BIT 3,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 94: // BIT 3,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 95: // BIT 3,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,3,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 96: // BIT 4,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 97: // BIT 4,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 98: // BIT 4,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 99: // BIT 4,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 100: // BIT 4,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 101: // BIT 4,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 102: // BIT 4,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 103: // BIT 4,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,4,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 104: // BIT 5,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 105: // BIT 5,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 106: // BIT 5,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 107: // BIT 5,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 108: // BIT 5,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 109: // BIT 5,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 110: // BIT 5,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 111: // BIT 5,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,5,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 112: // BIT 6,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 113: // BIT 6,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 114: // BIT 6,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 115: // BIT 6,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 116: // BIT 6,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 117: // BIT 6,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 118: // BIT 6,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 119: // BIT 6,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,6,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 120: // BIT 7,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 121: // BIT 7,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 122: // BIT 7,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 123: // BIT 7,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 124: // BIT 7,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 125: // BIT 7,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 126: // BIT 7,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 127: // BIT 7,(IY+d) + tmp2=Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1); + Z80free_doBIT(processor,7,Z80free_Rd(tmp2)); + Z80free_adjustFlags (processor, ((byte) (tmp2>>8))); + return (16); + break; + case 128: // LD_RES B,0,(IY+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 129: // LD_RES C,0,(IY+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 130: // LD_RES D,0,(IY+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 131: // LD_RES E,0,(IY+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 132: // LD_RES H,0,(IY+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 133: // LD_RES L,0,(IY+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 134: // RES 0,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 135: // LD_RES A,0,(IY+d) + tmp1=Z80free_doSetRes(processor,0,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 136: // LD_RES B,1,(IY+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 137: // LD_RES C,1,(IY+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 138: // LD_RES D,1,(IY+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 139: // LD_RES E,1,(IY+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 140: // LD_RES H,1,(IY+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 141: // LD_RES L,1,(IY+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 142: // RES 1,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 143: // LD_RES A,1,(IY+d) + tmp1=Z80free_doSetRes(processor,0,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 144: // LD_RES B,2,(IY+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 145: // LD_RES C,2,(IY+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 146: // LD_RES D,2,(IY+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 147: // LD_RES E,2,(IY+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 148: // LD_RES H,2,(IY+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 149: // LD_RES L,2,(IY+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 150: // RES 2,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 151: // LD_RES A,2,(IY+d) + tmp1=Z80free_doSetRes(processor,0,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 152: // LD_RES B,3,(IY+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 153: // LD_RES C,3,(IY+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 154: // LD_RES D,3,(IY+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 155: // LD_RES E,3,(IY+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 156: // LD_RES H,3,(IY+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 157: // LD_RES L,3,(IY+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 158: // RES 3,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 159: // LD_RES A,3,(IY+d) + tmp1=Z80free_doSetRes(processor,0,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 160: // LD_RES B,4,(IY+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 161: // LD_RES C,4,(IY+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 162: // LD_RES D,4,(IY+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 163: // LD_RES E,4,(IY+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 164: // LD_RES H,4,(IY+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 165: // LD_RES L,4,(IY+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 166: // RES 4,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 167: // LD_RES A,4,(IY+d) + tmp1=Z80free_doSetRes(processor,0,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 168: // LD_RES B,5,(IY+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 169: // LD_RES C,5,(IY+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 170: // LD_RES D,5,(IY+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 171: // LD_RES E,5,(IY+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 172: // LD_RES H,5,(IY+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 173: // LD_RES L,5,(IY+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 174: // RES 5,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 175: // LD_RES A,5,(IY+d) + tmp1=Z80free_doSetRes(processor,0,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 176: // LD_RES B,6,(IY+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 177: // LD_RES C,6,(IY+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 178: // LD_RES D,6,(IY+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 179: // LD_RES E,6,(IY+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 180: // LD_RES H,6,(IY+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 181: // LD_RES L,6,(IY+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 182: // RES 6,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 183: // LD_RES A,6,(IY+d) + tmp1=Z80free_doSetRes(processor,0,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 184: // LD_RES B,7,(IY+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 185: // LD_RES C,7,(IY+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 186: // LD_RES D,7,(IY+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 187: // LD_RES E,7,(IY+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 188: // LD_RES H,7,(IY+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 189: // LD_RES L,7,(IY+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 190: // RES 7,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 191: // LD_RES A,7,(IY+d) + tmp1=Z80free_doSetRes(processor,0,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 192: // LD_SET B,0,(IY+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 193: // LD_SET C,0,(IY+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 194: // LD_SET D,0,(IY+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 195: // LD_SET E,0,(IY+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 196: // LD_SET H,0,(IY+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 197: // LD_SET L,0,(IY+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 198: // SET 0,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 199: // LD_SET A,0,(IY+d) + tmp1=Z80free_doSetRes(processor,1,0,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 200: // LD_SET B,1,(IY+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 201: // LD_SET C,1,(IY+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 202: // LD_SET D,1,(IY+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 203: // LD_SET E,1,(IY+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 204: // LD_SET H,1,(IY+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 205: // LD_SET L,1,(IY+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 206: // SET 1,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 207: // LD_SET A,1,(IY+d) + tmp1=Z80free_doSetRes(processor,1,1,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 208: // LD_SET B,2,(IY+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 209: // LD_SET C,2,(IY+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 210: // LD_SET D,2,(IY+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 211: // LD_SET E,2,(IY+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 212: // LD_SET H,2,(IY+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 213: // LD_SET L,2,(IY+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 214: // SET 2,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 215: // LD_SET A,2,(IY+d) + tmp1=Z80free_doSetRes(processor,1,2,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 216: // LD_SET B,3,(IY+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 217: // LD_SET C,3,(IY+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 218: // LD_SET D,3,(IY+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 219: // LD_SET E,3,(IY+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 220: // LD_SET H,3,(IY+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 221: // LD_SET L,3,(IY+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 222: // SET 3,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 223: // LD_SET A,3,(IY+d) + tmp1=Z80free_doSetRes(processor,1,3,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 224: // LD_SET B,4,(IY+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 225: // LD_SET C,4,(IY+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 226: // LD_SET D,4,(IY+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 227: // LD_SET E,4,(IY+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 228: // LD_SET H,4,(IY+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 229: // LD_SET L,4,(IY+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 230: // SET 4,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 231: // LD_SET A,4,(IY+d) + tmp1=Z80free_doSetRes(processor,1,4,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 232: // LD_SET B,5,(IY+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 233: // LD_SET C,5,(IY+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 234: // LD_SET D,5,(IY+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 235: // LD_SET E,5,(IY+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 236: // LD_SET H,5,(IY+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 237: // LD_SET L,5,(IY+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 238: // SET 5,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 239: // LD_SET A,5,(IY+d) + tmp1=Z80free_doSetRes(processor,1,5,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 240: // LD_SET B,6,(IY+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 241: // LD_SET C,6,(IY+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 242: // LD_SET D,6,(IY+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 243: // LD_SET E,6,(IY+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 244: // LD_SET H,6,(IY+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 245: // LD_SET L,6,(IY+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 246: // SET 6,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 247: // LD_SET A,6,(IY+d) + tmp1=Z80free_doSetRes(processor,1,6,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + case 248: // LD_SET B,7,(IY+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.B=tmp1; + return (19); + break; + case 249: // LD_SET C,7,(IY+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.C=tmp1; + return (19); + break; + case 250: // LD_SET D,7,(IY+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.D=tmp1; + return (19); + break; + case 251: // LD_SET E,7,(IY+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.E=tmp1; + return (19); + break; + case 252: // LD_SET H,7,(IY+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.H=tmp1; + return (19); + break; + case 253: // LD_SET L,7,(IY+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.L=tmp1; + return (19); + break; + case 254: // SET 7,(IY+d) + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1)))); + return (19); + break; + case 255: // LD_SET A,7,(IY+d) + tmp1=Z80free_doSetRes(processor,1,7,Z80free_Rd(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1))); + Z80free_Wr(Z80free_addr_relativeXDCB(processor,processor->Rm.wr.IY,d1),tmp1); + processor->Rm.br.A=tmp1; + return (19); + break; + } + + return -1; +}