Commit d838d4dc authored by Sergio Costas's avatar Sergio Costas

Now uses ENUMs instead of raw values

parent 981d4827
......@@ -90,11 +90,11 @@ int save_z80(char *filename) {
procesador.Rm.br.C, procesador.Rm.br.B, procesador.Rm.br.L,
procesador.Rm.br.H); // AF, BC and HL
if (ordenador->mode128k == 0) // 48K
fprintf(fichero, "%c%c", (byte) (procesador.PC & 0x0FF),
(byte) ((procesador.PC >> 8) & 0xFF)); // PC
else
if (ordenador->current_mode == MODE_48K) {// 48K
fprintf(fichero, "%c%c", (byte) (procesador.PC & 0x0FF), (byte) ((procesador.PC >> 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,
......@@ -118,8 +118,9 @@ int save_z80(char *filename) {
value = 0;
fprintf(fichero, "%c", value);
value = procesador.IM;
if (ordenador->issue == 2)
if (!ordenador->issue_3) {
value |= 4;
}
switch (keyboard->joystick) {
case JOYSTICK_KEMPSTON:
value |= 64;
......@@ -133,7 +134,7 @@ int save_z80(char *filename) {
}
fprintf(fichero, "%c", value);
if (ordenador->mode128k == 0) { // 48K
if (ordenador->current_mode == MODE_48K) { // 48K
fwrite((ordenador->memoria + 147456), 16384, 1, fichero); // video memory
fwrite((ordenador->memoria + 98304), 32768, 1, fichero); // memory pages 2 & 3
fclose(fichero);
......@@ -258,10 +259,10 @@ int load_z80(const char *filename) {
if (tempo[29] & 0x04) {
printf("Issue 2\n");
snap->issue = 2; // issue2
snap->issue_3= false; // issue2
} else {
printf("Issue 3\n");
snap->issue = 3; // issue3
snap->issue_3 = true; // issue3
}
snap->A = tempo[0];
......@@ -488,7 +489,7 @@ int load_sna(const char *filename) {
for (loop = 0; loop < 16; loop++)
snap->ay_regs[loop] = 0;
snap->ay_latch = 0;
snap->issue = 3;
snap->issue_3 = true;
snap->joystick = 1; //kempston
snap->I = tempo[0];
......@@ -589,14 +590,14 @@ void load_snap(struct z80snapshot *snap) {
switch (snap->type) {
case 0: // 48k
printf("Mode 48K\n");
ordenador->mode128k = 0; // 48K mode
ordenador->issue = snap->issue;
ordenador->current_mode = MODE_48K; // 48K mode
ordenador->issue_3 = snap->issue_3;
ResetComputer();
break;
case 1: // 128k
printf("Mode 128K\n");
ordenador->mode128k = 2; // +2 mode
ordenador->issue = 3;
ordenador->current_mode = MODE_P2; // +2 mode
ordenador->issue_3 = true;
ResetComputer();
printf("Pager: %X\n", snap->pager);
Z80free_Out(0x7FFD, snap->pager);
......
......@@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#include "computer.hh"
......@@ -23,7 +23,8 @@
struct z80snapshot {
byte A,F,B,C,D,E,H,L,AA,FF,BB,CC,DD,EE,HH,LL,R,I,IFF1,IFF2,Imode,issue;
byte A,F,B,C,D,E,H,L,AA,FF,BB,CC,DD,EE,HH,LL,R,I,IFF1,IFF2,Imode;
bool issue_3;
word PC,IX,IY,SP;
byte type; // bit 0/1: 48K/128K/+3
byte border; // border color
......
......@@ -49,8 +49,8 @@ computer::computer() {
this->page48k = 0;
this->bus_counter = 0;
this->port254 = 0;
this->issue = 3;
this->mode128k = 0;
this->issue_3 = true;
this->current_mode = MODE_48K;
this->turbo = false;
this->turbo_play = true;
......@@ -81,7 +81,7 @@ bool computer::callback_receiver(string signal_received, class Signals *object)
return true;
}
if (signal_received == "pause_tape_48k") {
if ((this->mode128k == 0) || ((this->mport1 & 0x20) != 0)) {
if ((this->current_mode == MODE_48K) || ((this->mport1 & 0x20) != 0)) {
OOTape->set_pause(true);
llsound->set_speed(ordenador->turbo); // set speed to the desired mode
}
......@@ -94,7 +94,7 @@ bool computer::callback_receiver(string signal_received, class Signals *object)
byte computer::bus_empty () {
if (ordenador->mode128k != 3)
if (ordenador->current_mode != MODE_P3)
return (screen->bus_value);
else
return (255); // +2A and +3 returns always 255
......@@ -133,14 +133,13 @@ void computer::do_contention() {
return;
}
int ccicles=(this->cicles_counter-14335)%8;
int ccicles=(this->cicles_counter-14335) % 8;
if (ccicles>5) {
return;
}
this->emulate(6-ccicles);
}
// resets the computer and loads the right ROMs
......@@ -150,7 +149,7 @@ void ResetComputer () {
static int bucle;
Z80free_reset (&procesador);
load_rom (ordenador->mode128k);
load_rom (ordenador->current_mode);
......@@ -160,26 +159,26 @@ void ResetComputer () {
ordenador->mport1 = 0;
ordenador->mport2 = 0;
ordenador->video_offset = 0; // video in page 9 (page 5 in 128K)
switch (ordenador->mode128k) {
case 0: // 48K
switch (ordenador->current_mode) {
case MODE_48K: // 48K
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)
ordenador->block3 = ordenador->memoria + 65536; // 3rd block in page 7 (page 3 in 128K)
ordenador->mport1 = 32; // access to port 7FFD disabled
break;
case 3: // +2A/+3
case MODE_P3: // +2A/+3
Z80free_Out (0x1FFD, 0); // Here must NOT be a break, because +2A and +3 need both OUT, at 1FFD and 7FFD
case 1: // 128K
case 2: // +2
case 4: // spanish 128K
case MODE_128K: // 128K
case MODE_P2: // +2
case MODE_128K_SPA: // spanish 128K
Z80free_Out (0x7FFD, 0); // set the page for 128K (both spanish and british), +2, +2A and +3
break;
}
spk_ay->reset();
keyboard->reset();
screen->reset(ordenador->mode128k);
screen->reset(ordenador->current_mode);
microdrive->reset();
mouse->reset();
}
......@@ -198,7 +197,7 @@ void computer::write_memory (uint16_t Addr, uint8_t Value) {
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)))
if ((ordenador->current_mode == MODE_P3) && (1 == (ordenador->mport2 & 0x01)))
*(ordenador->block0 + Addr) = (unsigned char) Value;
break;
......@@ -221,7 +220,7 @@ byte Z80free_Rd (word Addr) {
if((microdrive->mdr_active)&&(microdrive->mdr_paged)&&(Addr<8192)) // Interface I
return((byte)ordenador->shadowrom[Addr]);
switch (ordenador->other_ret) {
case 1:
ordenador->other_ret = 0;
......@@ -264,11 +263,13 @@ uint8_t computer::read_memory(uint16_t Addr) {
void Z80free_Out (word Port, byte Value) {
// Microdrive access
register word maskport;
if (((Port&0x0001)==0)||((Port>=0x4000)&&(Port<0x8000))) {
ordenador->do_contention();
if (ordenador->current_mode != MODE_P3) {
ordenador->do_contention();
}
}
// ULAPlus
......@@ -284,7 +285,7 @@ void Z80free_Out (word Port, byte Value) {
if(((Port &0x0018)!=0x0018)&&(microdrive->mdr_active))
microdrive->out(Port,Value);
// ULA port (A0 low)
if (!(Port & 0x0001)) {
......@@ -301,12 +302,12 @@ void Z80free_Out (word Port, byte Value) {
// Memory page (7FFD & 1FFD)
if (ordenador->mode128k==3) {
if (ordenador->current_mode == MODE_P3) {
maskport=0x0FFD;
} else {
maskport=0x3FFD;
}
if (((Port|maskport) == 0x7FFD) && (0 == (ordenador->mport1 & 0x20))) {
ordenador->mport1 = (unsigned char) Value;
screen->set_memory_pointers (); // set the pointers
......@@ -335,7 +336,9 @@ byte Z80free_In (word Port) {
byte pines;
if (((Port&0x0001)==0)||((Port>=0x4000)&&(Port<0x8000))) {
ordenador->do_contention();
if (ordenador->current_mode != MODE_P3) {
ordenador->do_contention();
}
}
temporal_io = (unsigned int) Port;
......@@ -365,12 +368,14 @@ byte Z80free_In (word Port) {
pines &= keyboard->s15;
if (OOTape->get_pause()) {
if (ordenador->issue == 2) {
if (ordenador->port254 & 0x18)
if (!ordenador->issue_3) {
if (ordenador->port254 & 0x18) {
pines |= 0x40;
}
} else {
if (ordenador->port254 & 0x10)
if (ordenador->port254 & 0x10) {
pines |= 0x40;
}
}
if (random()<(RAND_MAX/200)) { // add tape noise when paused
pines |= 0x40;
......
......@@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#ifndef computer_h
......@@ -40,6 +40,8 @@ enum tapmodes {TAP_GUIDE, TAP_DATA, TAP_PAUSE, TAP_TRASH, TAP_STOP, TAP_PAUSE2,
enum taptypes {TAP_TAP, TAP_TZX};
enum CurrentMode {MODE_48K, MODE_128K, MODE_P2, MODE_P3, MODE_128K_SPA};
class computer : public Signals {
public:
unsigned int temporal_io;
......@@ -62,8 +64,8 @@ public:
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
bool issue_3; // 2= 48K issue 2, 3= 48K issue 3
enum CurrentMode current_mode;
unsigned char port254;
......
......@@ -48,7 +48,7 @@ unsigned int jump_frames, curr_frames;
string filenames[5];
string load_a_rom(string *filenames) {
string *pointer;
int offset=0;
ifstream *fichero;
......@@ -103,7 +103,7 @@ void load_rom(char type) {
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";
......@@ -144,7 +144,7 @@ void load_rom(char type) {
}
break;
}
fichero=llscreen->myfopen("spectrum-roms/if1-2.rom",ios::in|ios::binary); // load Interface1 ROM
if(fichero == NULL) {
delete fichero;
......@@ -162,7 +162,7 @@ void load_rom(char type) {
}
void end_system() {
delete(llsound);
delete(llscreen);
......@@ -172,7 +172,7 @@ void load_main_game(const char *nombre) {
int longitud;
char *puntero;
longitud=strlen(nombre);
if (longitud<5) {
return;
......@@ -182,7 +182,7 @@ void load_main_game(const char *nombre) {
load_z80(nombre);
return;
}
if ((0==strcasecmp(".tap",puntero))||(0==strcasecmp(".tzx",puntero))) {
ordenador->current_tap = nombre;
OOTape->load_file(nombre);
......@@ -191,11 +191,11 @@ void load_main_game(const char *nombre) {
}
void save_config() {
char config_path[1024];
int length;
FILE *fconfig;
strcpy(config_path,getenv("HOME"));
length=strlen(config_path);
if ((length>0)&&(config_path[length-1]!='/'))
......@@ -205,8 +205,8 @@ void save_config() {
if (fconfig==NULL) {
return;
}
fprintf(fconfig,"mode=%c%c",48+ordenador->mode128k,10);
fprintf(fconfig,"issue=%c%c",48+ordenador->issue,10);
fprintf(fconfig,"mode=%c%c",48+ordenador->current_mode,10);
fprintf(fconfig,"issue=%c%c",(ordenador->issue_3 ? 51 : 50),10);
fprintf(fconfig,"joystick=%c%c",48+keyboard->joystick,10);
fprintf(fconfig,"ay_sound=%c%c",48+spk_ay->ay_emul,10);
fprintf(fconfig,"interface1=%c%c",48+microdrive->mdr_active,10);
......@@ -220,13 +220,13 @@ void save_config() {
}
void load_config() {
char config_path[1024];
char line[1024],carac,done;
int length,pos;
FILE *fconfig;
unsigned char volume=255,mode128k=255,issue=255,joystick=255,ay_emul=255,mdr_active=255,dblscan=255,bw=255,fast=255,turboload=255,mouse_enabled=255;
strcpy(config_path,getenv("HOME"));
length=strlen(config_path);
if ((length>0)&&(config_path[length-1]!='/'))
......@@ -236,7 +236,7 @@ void load_config() {
if (fconfig==NULL) {
return;
}
done=1;
pos=0;
line[0]=0;
......@@ -305,12 +305,28 @@ void load_config() {
continue;
}
}
if (mode128k<5) {
ordenador->mode128k=mode128k;
switch (mode128k) {
case 0:
ordenador->current_mode = MODE_48K;
break;
case 1:
ordenador->current_mode = MODE_128K;
break;
case 2:
ordenador->current_mode = MODE_P2;
break;
case 3:
ordenador->current_mode = MODE_P3;
break;
case 4:
ordenador->current_mode = MODE_128K_SPA;
break;
}
}
if (issue<4) {
ordenador->issue=issue;
ordenador->issue_3 = issue == 3;
}
if (joystick<4) {
switch (joystick) {
......@@ -352,7 +368,7 @@ void load_config() {
if (volume<255) {
llsound->set_volume(volume);
}
fclose(fconfig);
}
......@@ -426,7 +442,7 @@ int main(int argc,char *argv[]) {
curr_frames = 0;
printf("Computer init\n");
printf("Modo: %d\n",ordenador->mode128k);
printf("Modo: %d\n",ordenador->current_mode);
atexit(end_system);
......@@ -451,15 +467,15 @@ int main(int argc,char *argv[]) {
// assign random values to the memory before start execution
printf("Reset memory\n");
printf("Modo: %d\n",ordenador->mode128k);
printf("Modo: %d\n",ordenador->current_mode);
for(bucle=0;bucle<196608;bucle++)
ordenador->memoria[bucle]=(unsigned char) rand();
printf("Memory resetted\n");
printf("Modo: %d\n",ordenador->mode128k);
printf("Modo: %d\n",ordenador->current_mode);
salir=1;
printf("Init microdrive\n");
......@@ -475,10 +491,10 @@ int main(int argc,char *argv[]) {
osd->set_message("Running without sound (read the FAQ)",2000);
}
printf("Modo: %d\n",ordenador->mode128k);
printf("Modo: %d\n",ordenador->current_mode);
printf("load main game\n");
load_main_game(parse.gamefile.c_str());
printf("Modo: %d\n",ordenador->mode128k);
printf("Modo: %d\n",ordenador->current_mode);
osd->set_message("Press F1 for help",4000);
......
......@@ -153,27 +153,28 @@ void settings_menu() {
llscreen->clear_screen();
llscreen->print_string("Current settings",-1,0,15,0);
switch(ordenador->mode128k) {
case 0:
if(ordenador->issue==2)
sprintf(texto,"Mode: \001\01648K issue2");
else
switch(ordenador->current_mode) {
case MODE_48K:
if(ordenador->issue_3) {
sprintf(texto,"Mode: \001\01648K issue3");
} else {
sprintf(texto,"Mode: \001\01648K issue2");
}
break;
case 1:
case MODE_128K:
sprintf(texto,"Mode: \001\016Sinclair 128K");
break;
case 2:
case MODE_P2:
sprintf(texto,"Mode: \001\016Amstrad +2");
break;
case 3:
case MODE_P3:
sprintf(texto,"Mode: \001\016Amstrad +2A/+3");
break;
case 4:
case MODE_128K_SPA:
sprintf(texto,"Mode: \001\016Spanish 128K");
break;
}
llscreen->print_string(texto,-1,2,15,0);
switch(keyboard->joystick) {
......@@ -274,39 +275,39 @@ void settings_menu() {
fin=0;
break;
case SDLK_1:
ordenador->issue=2;
ordenador->mode128k=0;
ordenador->issue_3 = false;
ordenador->current_mode = MODE_48K;
spk_ay->ay_emul=0;
ResetComputer();
break;
case SDLK_2:
ordenador->issue=3;
ordenador->mode128k=0;
ordenador->issue_3 = true;
ordenador->current_mode = MODE_48K;
spk_ay->ay_emul=0;
ResetComputer();
break;
case SDLK_3:
ordenador->issue=3;
ordenador->mode128k=1;
ordenador->issue_3 = true;
ordenador->current_mode = MODE_128K;
spk_ay->ay_emul=1;
ResetComputer();
break;
case SDLK_4:
ordenador->issue=3;
ordenador->mode128k=2;
ordenador->issue_3 = true;
ordenador->current_mode = MODE_P2;
spk_ay->ay_emul=1;
ResetComputer();
break;
case SDLK_5:
ordenador->issue=3;
ordenador->mode128k=3;
ordenador->issue_3 = true;
ordenador->current_mode = MODE_P3;
spk_ay->ay_emul=1;
microdrive->mdr_active=0;
ResetComputer();
break;
case SDLK_6:
ordenador->issue=3;
ordenador->mode128k=4;
ordenador->issue_3 = true;
ordenador->current_mode = MODE_128K_SPA;
spk_ay->ay_emul=1;
ResetComputer();
break;
......@@ -324,7 +325,7 @@ void settings_menu() {
keyboard->joystick=JOYSTICK_SINCLAIR2;
break;
case SDLK_i:
if(ordenador->mode128k!=3) {
if(ordenador->current_mode != MODE_P3) {
microdrive->mdr_active=1-microdrive->mdr_active;
ResetComputer();
}
......@@ -390,7 +391,7 @@ void do_poke() {
return;
}
if ((address<16384) && ((ordenador->mode128k != 3) || (1 != (ordenador->mport2 & 0x01)))) {
if ((address<16384) && ((ordenador->current_mode != MODE_P3) || (1 != (ordenador->mport2 & 0x01)))) {
llscreen->print_string("That address is ROM memory.",-1,1,15,0);
continue;
}
......@@ -512,7 +513,7 @@ void snapshots_menu() {
llscreen->print_string("1: \001\017load a Z80/SNA snapshot",14,4,12,0);
if(ordenador->mode128k!=3) { // not in +3 mode
if(ordenador->current_mode != MODE_P3) { // not in +3 mode
llscreen->print_string("2: \001\017make a Z80 snapshot",14,6,12,0);
} else {
llscreen->print_string("Can't make snapshots in +3 mode",14,6,15,0);
......@@ -538,8 +539,9 @@ void snapshots_menu() {
break;
case SDLK_2:
fin=0;
if(ordenador->mode128k!=3) // not in +3 mode
if(ordenador->current_mode != MODE_P3) { // not in +3 mode
save_z80file();
}
break;
case SDLK_3:
fin=0;
......
......@@ -123,7 +123,7 @@ void Screen::set_memory_pointers () {
// assign ROMs and, if in special mode, RAM for the whole blocks
if ((ordenador->mode128k == 3)) {
if ((ordenador->current_mode == MODE_P3)) {
if (ordenador->mport2 & 0x01) { // +2A/+3 special mode
ordenador->page48k = 0; // no 48K ROM paged in
ram = (unsigned int) (ordenador->mport1 & 0x06); // bits 1&2
......@@ -166,7 +166,7 @@ void Screen::set_memory_pointers () {
ordenador->block0 = ordenador->memoria + (16384 * rom);
ordenador->page48k = (rom==3) ? 1 : 0; // 48K ROM is in ROM page 3
}
} else if (ordenador->mode128k == 0) {
} else if (ordenador->current_mode == MODE_48K ) {
ordenador->block0 = ordenador->memoria;
ordenador->page48k = 1;
} else { // ROMs for 128K/+2 mode
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment