Commit de4aa7fd authored by Sergio Costas's avatar Sergio Costas

Merge branch 'sdl2'

parents 52b99b08 33fb0536
# VERSIONS #
* Version 4.0.0 (2018-08-11)
* Now fullscreen works fine with Wayland (ported to SDL2)
* Version 3.9.1 (2018-05-01)
* Removed unused printfs
* Version 3.9.0 (2018-05-01)
......
......@@ -25,23 +25,7 @@ architectures. Please, read the file PORTS to know more details about this.
FBZX is based in Z80FREE, which you can find into the folder z80free.
To work with FBZX you need:
* A FrameBuffer-capable graphic card (or compatible with X-windows)
* A Linux system with FrameBuffer configured (can use X too)
* Sound Card with ALSA or OSS drivers (optional)
In order to get the maximum performance, your FrameBuffer driver must allow to
change to 640x480 or 480x640 resolution in 8 bits. Only the old VESAFB driver can
have problems with this fact, so if you use this driver, be sure to boot your
Linux box in 640x480 in 8 bits. If you don't do this, SDL will emulate that
mode, resulting in a high performance penalty. If you use an specific Framebuffer
driver, or the VESAFB driver from kernels 2.6, just don't worry: FBZX will
automagically change the graphic mode when starts.
Of course, currently that is no problem thanks to the high speed of computers.
## WHAT CAPABILITIES HAVE FBZX?
## WHAT CAPABILITIES HAVE FBZX
FBZX can emulate the original 48K spectrum (issue 2 and issue 3), the original
128K, the Amstrad +2, the Amstrad +2A and the Spanish 128K.
......@@ -69,7 +53,7 @@ with the cursor keys (fire is emulated with the right ALT key, ALT-GR
key, WINDOWS MENU key or WINDOWS SYSTEM right key), or with a real
JoyStick.
## HOW DO I USE FBZX?
## HOW DO I USE FBZX
To run FBZX just type
......@@ -117,9 +101,17 @@ You can change the order with
That way it will try firts with OSS, then with ALSA.
FBZX works in X too, but it would run slower due to the penalty of the X
FBZX works in X and Wayland too, but it would run slower due to the penalty of the X
Window System. Fortunately this only applies to old systems. Current
computers can run FBZX under X without problem.
computers can run FBZX under X or Wayland without problem.
Anyway, there is a command line option to get the maximum performance. This
is -setres. Using it, when switching to fullscreen it will try to change the
screen resolution to the right one. But it only works in Xwindows; in
Wayland, or when not using that option, FBZX will keep the current resolution
and scale the picture. If you have a graphics driver with hardware acceleration,
you won't have performance problems anyway, so this mode is better than changing
the resolution.
The PC keyboard works exactly like the Spectrum keyboard (but only numbers and
letters). ENTER key is Return, CAPS SHIFT is in both Shift keys, and SYMBOL
......@@ -165,7 +157,7 @@ F12 is volume up.
If your system doesn't have function keys, you can use TAB plus keys 0 to 9
to emulate them (F11 is TAB and O, and F12 is TAB and P).
## HOW DO I CHOOSE A FILE WITH THE TAP/TZX OR Z80/SNA SELECTOR?
## HOW TO CHOOSE A FILE WITH THE TAP/TZX OR Z80/SNA SELECTOR
You can choose a file just by moving the white bar with the cursor keys. You
can use also the RePag and AvPag to jump over 12 positions.
......@@ -182,7 +174,7 @@ to save from programs that use them (it can save programs without header, too,
since the emulator intercepts the call to SA-BYTES). Each new block is added at
the end of the file, but only if the SAVE operation is enabled for this file.
## HOW DOES WORK THE FAST SPEED LOAD FOR TAP/TZX FILES?
## HOW DOES WORK THE FAST SPEED LOAD FOR TAP/TZX FILES
Just type LOAD "" in the emulator (or choose the TAPE LOADER option in the 128K
menu) and the tape will automagically load. This only works with programs that
......@@ -206,7 +198,7 @@ change the TURBO WHILE PLAYING mode to ENABLED, so the computer (and the tape)
will run faster when the tape is playing (F6 key), but will return to normal
speed when the tape is paused (F5 key or end-of-tape).
## HOW DOES WORK THE FAST SPEED SAVE FOR TAP/TZX FILES?
## HOW DOES WORK THE FAST SPEED SAVE FOR TAP/TZX FILES
If write is enabled, using the SAVE command will add blocks to the currently
selected tape file, no matter if FAST-LOAD is enabled or not. By default,
......@@ -215,7 +207,7 @@ new TAP/TZX file is created from scratch. This functionality works with any
program that uses the SA-BYTES ROM routine, no matter if enters at 04C2 (like
the classic spectrum 48K rom) or at 04C6 (like the Spectrum +3).
## HOW DOES WORK THE INTERFACE I AND MICRODRIVE EMULATION?
## HOW DOES WORK THE INTERFACE I AND MICRODRIVE EMULATION
FBZX can emulate an Interface I with one microdrive attached, but only when
working as Spectrum 48K, 128K or +2, never as +2A/+3 since it's incompatible.
......
CC=g++ -c -O2 -g
CPP=g++ -c -O2 -g
LN=g++ -O2 -g
FLAGS = -O2
CFLAGS += `pkg-config --cflags sdl libpulse-simple alsa` -D D_SOUND_PULSE -D D_SOUND_ALSA -D D_SOUND_OSS
CPPFLAGS += `pkg-config --cflags sdl libpulse-simple alsa` -D D_SOUND_PULSE -D D_SOUND_ALSA -D D_SOUND_OSS
LDFLAGS += `pkg-config --libs sdl libpulse-simple alsa`
CC=g++ -c $(FLAGS)
CPP=g++ -c $(FLAGS)
LN=g++
CFLAGS += `pkg-config --cflags sdl2 libpulse-simple alsa` -D D_SOUND_PULSE -D D_SOUND_ALSA -D D_SOUND_OSS
CPPFLAGS += `pkg-config --cflags sdl2 libpulse-simple alsa` -D D_SOUND_PULSE -D D_SOUND_ALSA -D D_SOUND_OSS
LDFLAGS += `pkg-config --libs sdl2 libpulse-simple alsa`
fbzx: cargador.o cmdline.o computer.o emulator.o keyboard.o llscreen.o llsound.o menus.o microdrive.o mouse.o osd.o screen.o signals.o spk_ay.o tape.o Z80free.o Z80free_codes.o Z80free_codesCB.o Z80free_codesED.o Z80free_codesDD.o Z80free_codesFD.o Z80free_codesDDCB.o Z80free_codesFDCB.o
......@@ -15,22 +17,22 @@ Z80free.o: z80free/Z80free.c z80free/Z80free.h
Z80free_codes.o: z80free/Z80free_codes.c z80free/Z80free.h
$(CC) -o Z80free_codes.o z80free/Z80free_codes.c
Z80free_codesCB.o: z80free/Z80free_codesCB.c z80free/Z80free.h
$(CC) -o Z80free_codesCB.o z80free/Z80free_codesCB.c
Z80free_codesED.o: z80free/Z80free_codesED.c z80free/Z80free.h
$(CC) -o Z80free_codesED.o z80free/Z80free_codesED.c
Z80free_codesDD.o: z80free/Z80free_codesDD.c z80free/Z80free.h
$(CC) -o Z80free_codesDD.o z80free/Z80free_codesDD.c
Z80free_codesFD.o: z80free/Z80free_codesFD.c z80free/Z80free.h
$(CC) -o Z80free_codesFD.o z80free/Z80free_codesFD.c
Z80free_codesDDCB.o: z80free/Z80free_codesDDCB.c z80free/Z80free.h
$(CC) -o Z80free_codesDDCB.o z80free/Z80free_codesDDCB.c
Z80free_codesFDCB.o: z80free/Z80free_codesFDCB.c z80free/Z80free.h
$(CC) -o Z80free_codesFDCB.o z80free/Z80free_codesFDCB.c
......@@ -78,3 +80,4 @@ spk_ay.o: spk_ay.cpp spk_ay.hh llsound.hh computer.hh screen.hh signals.hh llscr
tape.o: tape.cpp z80free/Z80free.h tape.hh signals.hh emulator.hh screen.hh osd.hh computer.hh llscreen.hh
$(CPP) $(CPPFLAGS) -o tape.o tape.cpp
CC=g++ -c -O2
CPP=g++ -c -O2
LN=g++ -O2
FLAGS = -O2
CFLAGS += `pkg-config --cflags sdl libpulse-simple alsa` -D D_SOUND_PULSE -D D_SOUND_ALSA -D D_SOUND_OSS
CPPFLAGS += `pkg-config --cflags sdl libpulse-simple alsa` -D D_SOUND_PULSE -D D_SOUND_ALSA -D D_SOUND_OSS
LDFLAGS += `pkg-config --libs sdl libpulse-simple alsa`
CC=g++ -c $(FLAGS)
CPP=g++ -c $(FLAGS)
LN=g++
CFLAGS += `pkg-config --cflags sdl2 libpulse-simple alsa` -D D_SOUND_PULSE -D D_SOUND_ALSA -D D_SOUND_OSS
CPPFLAGS += `pkg-config --cflags sdl2 libpulse-simple alsa` -D D_SOUND_PULSE -D D_SOUND_ALSA -D D_SOUND_OSS
LDFLAGS += `pkg-config --libs sdl2 libpulse-simple alsa`
#basecmd $(CPP) $(CPPFLAGS)
#extra_obj Z80free.o Z80free_codes.o Z80free_codesCB.o Z80free_codesED.o Z80free_codesDD.o Z80free_codesFD.o Z80free_codesDDCB.o Z80free_codesFDCB.o
......@@ -17,21 +19,21 @@ Z80free.o: z80free/Z80free.c z80free/Z80free.h
Z80free_codes.o: z80free/Z80free_codes.c z80free/Z80free.h
$(CC) -o Z80free_codes.o z80free/Z80free_codes.c
Z80free_codesCB.o: z80free/Z80free_codesCB.c z80free/Z80free.h
$(CC) -o Z80free_codesCB.o z80free/Z80free_codesCB.c
Z80free_codesED.o: z80free/Z80free_codesED.c z80free/Z80free.h
$(CC) -o Z80free_codesED.o z80free/Z80free_codesED.c
Z80free_codesDD.o: z80free/Z80free_codesDD.c z80free/Z80free.h
$(CC) -o Z80free_codesDD.o z80free/Z80free_codesDD.c
Z80free_codesFD.o: z80free/Z80free_codesFD.c z80free/Z80free.h
$(CC) -o Z80free_codesFD.o z80free/Z80free_codesFD.c
Z80free_codesDDCB.o: z80free/Z80free_codesDDCB.c z80free/Z80free.h
$(CC) -o Z80free_codesDDCB.o z80free/Z80free_codesDDCB.c
Z80free_codesFDCB.o: z80free/Z80free_codesFDCB.c z80free/Z80free.h
$(CC) -o Z80free_codesFDCB.o z80free/Z80free_codesFDCB.c
\ No newline at end of file
......@@ -28,14 +28,13 @@
#include "spk_ay.hh"
void uncompress_z80(FILE *fichero, int length, unsigned char *memo) {
unsigned char byte_loaded, EDfound, counter;
int position;
int position;
counter = 0;
counter = 0;
byte_loaded = 0;
EDfound = 0;
position = 0;
EDfound = 0;
position = 0;
printf("Descomprimo de longitud %d\n", length);
......@@ -44,8 +43,9 @@ void uncompress_z80(FILE *fichero, int length, unsigned char *memo) {
memo[position++] = byte_loaded;
counter--;
continue;
} else
} else {
fread(&byte_loaded, 1, 1, fichero);
}
if (EDfound == 2) { // we have two EDs
counter = byte_loaded;
......@@ -59,7 +59,7 @@ void uncompress_z80(FILE *fichero, int length, unsigned char *memo) {
} else {
if (EDfound == 1) { // we found ED xx. We write ED and xx
memo[position++] = 0xED;
EDfound = 0;
EDfound = 0;
}
if (position >= length) {
break;
......@@ -67,12 +67,10 @@ void uncompress_z80(FILE *fichero, int length, unsigned char *memo) {
memo[position++] = byte_loaded;
}
} while (position < length);
}
int save_z80(char *filename) {
FILE *fichero;
FILE * fichero;
unsigned char value, bucle;
fichero = fopen(filename, "r");
......@@ -83,39 +81,41 @@ int save_z80(char *filename) {
fichero = fopen(filename, "w");
if (fichero == NULL)
if (fichero == NULL) {
return -2; // can't create file
}
fprintf(fichero, "%c%c%c%c%c%c", procesador.Rm.br.A, procesador.Rm.br.F,
procesador.Rm.br.C, procesador.Rm.br.B, procesador.Rm.br.L,
procesador.Rm.br.H); // AF, BC and HL
procesador.Rm.br.C, procesador.Rm.br.B, procesador.Rm.br.L,
procesador.Rm.br.H); // AF, BC and HL
if (ordenador->current_mode == MODE_48K) {// 48K
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", 0, 0); // 128K
}
fprintf(fichero, "%c%c", procesador.Rm.br.P, procesador.Rm.br.S); // SP
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) | ((screen->border << 1) & 0x0E))); // I, R and border color
(((procesador.R2 >> 7) & 0x01) | ((screen->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);
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)
if (procesador.IFF1) {
value = 1;
else
} else {
value = 0;
}
fprintf(fichero, "%c", value);
if (procesador.IFF2)
if (procesador.IFF2) {
value = 1;
else
} else {
value = 0;
}
fprintf(fichero, "%c", value);
value = procesador.IM;
if (!ordenador->issue_3) {
......@@ -125,36 +125,39 @@ int save_z80(char *filename) {
case JOYSTICK_KEMPSTON:
value |= 64;
break;
case JOYSTICK_SINCLAIR1:
value |= 128;
break;
case JOYSTICK_SINCLAIR2:
value |= 192;
break;
}
fprintf(fichero, "%c", value);
if (ordenador->current_mode == MODE_48K) { // 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
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", 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", spk_ay->get_latch()); // last selected AY register
for (bucle = 0; bucle < 16; bucle++)
(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", spk_ay->get_latch()); // last selected AY register
for (bucle = 0; bucle < 16; bucle++) {
fprintf(fichero, "%c", spk_ay->get_value(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
fprintf(fichero, "%c%c", 0xFF, 0xFF); // length=0xFFFF (uncompressed)
fprintf(fichero, "%c", bucle + 3); // page number
fwrite(ordenador->memoria + (16384 * bucle) + 65536, 16384, 1, fichero); // store page
}
fclose(fichero);
......@@ -162,19 +165,17 @@ int save_z80(char *filename) {
}
int load_z80(const char *filename) {
struct z80snapshot *snap;
unsigned char tempo[30], tempo2[56], type, compressed, page, byte_read[3];
unsigned char *memo;
unsigned char tempo[30], tempo2[56], type, compressed, page, byte_read[3];
unsigned char * memo;
FILE *fichero;
int longitud = 0, longitud2, bucle;
int longitud = 0, longitud2, bucle;
memo = (unsigned char *) malloc(49152);
snap = (struct z80snapshot *) malloc(sizeof(struct z80snapshot));
longitud = strlen(filename);
if ((longitud > 4)
&& (0 == strcasecmp(".sna", filename + (longitud - 4)))) {
if ((longitud > 4) && (0 == strcasecmp(".sna", filename + (longitud - 4)))) {
printf("Read SNA file\n");
free(memo);
free(snap);
......@@ -183,8 +184,9 @@ int load_z80(const char *filename) {
printf("Read Z80 file\n");
for (bucle = 0; bucle < 16; bucle++)
for (bucle = 0; bucle < 16; bucle++) {
snap->ay_regs[bucle] = 0;
}
fichero = fopen(filename, "r");
if (fichero == NULL) {
......@@ -198,7 +200,7 @@ int load_z80(const char *filename) {
if ((tempo[6] == 0) && (tempo[7] == 0)) { // extended Z80
printf("It's an extended Z80 file\n");
type = 1; // new type
type = 1; // new type
fread(tempo2, 1, 2, fichero); // read the length of the extension
......@@ -213,25 +215,28 @@ int load_z80(const char *filename) {
printf("Length: %d\n", longitud);
fread(tempo2 + 2, 1, longitud, fichero);
if (longitud == 23) // z80 ver 2.01
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
} else {
// z80 ver 3.0x
switch (tempo2[4]) {
case 0:
......@@ -239,27 +244,31 @@ int load_z80(const char *filename) {
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
type = 0; // old type
snap->type = 0; // 48k
}
if (tempo[29] & 0x04) {
printf("Issue 2\n");
snap->issue_3= false; // issue2
snap->issue_3 = false; // issue2
} else {
printf("Issue 3\n");
snap->issue_3 = true; // issue3
......@@ -273,16 +282,17 @@ int load_z80(const char *filename) {
snap->H = tempo[5];
if (type) {
snap->PC = ((word) tempo2[2]) + 256 * ((word) tempo2[3]);
for (bucle = 0; bucle < 16; bucle++)
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);
snap->I = tempo[10];
snap->R = (tempo[11] & 0x7F);
if (tempo[12] == 255) {
printf("Byte 12 is 255! doing 1\n");
......@@ -301,8 +311,8 @@ int load_z80(const char *filename) {
compressed = 0;
}
snap->E = tempo[13];
snap->D = tempo[14];
snap->E = tempo[13];
snap->D = tempo[14];
snap->CC = tempo[15];
snap->BB = tempo[16];
snap->EE = tempo[17];
......@@ -314,23 +324,27 @@ int load_z80(const char *filename) {
snap->IY = ((word) tempo[23]) + 256 * ((word) tempo[24]);
snap->IX = ((word) tempo[25]) + 256 * ((word) tempo[26]);
if (tempo[27] != 0)
if (tempo[27] != 0) {
snap->IFF1 = 1;
else
} else {
snap->IFF1 = 0;
}
if (tempo[28] != 0)
if (tempo[28] != 0) {
snap->IFF2 = 1;
else
} 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;
......@@ -338,83 +352,97 @@ int load_z80(const char *filename) {
snap->joystick = ((tempo[29] >> 6) & 0x03);
if (type)
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
* return -3;*/
// z80 file not yet supported
while (!feof(fichero)) {
fread(byte_read, 3, 1, fichero);
if (feof(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
if (longitud2 == 0xFFFF) { // uncompressed raw data
fread(snap->page[page], 16384, 1, fichero);
else
} else {
uncompress_z80(fichero, 16384, snap->page[page]);
}
}
} else {
while (!feof(fichero)) {
fread(byte_read, 3, 1, fichero);
if (feof(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
if (longitud2 == 0xFFFF) { // uncompressed raw data
fread(snap->page[page], 16384, 1, fichero);
else
} else {
uncompress_z80(fichero, 16384, snap->page[page]);
}
}
}
} else {
if (compressed) {
// 48k compressed z80 loader
......@@ -425,7 +453,6 @@ int load_z80(const char *filename) {
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
......@@ -433,7 +460,6 @@ int load_z80(const char *filename) {
fread(snap->page[1], 16384, 1, fichero);
fread(snap->page[2], 16384, 1, fichero);
}
}
load_snap(snap);
......@@ -444,18 +470,17 @@ int load_z80(const char *filename) {
}
int load_sna(const char *filename) {
unsigned char *tempo;
unsigned char *tempo2;
unsigned char type = 0;
FILE *fichero;
unsigned char * tempo;
unsigned char * tempo2;
unsigned char type = 0;
FILE * fichero;
struct z80snapshot *snap;
unsigned char v1, v2;
unsigned char v1, v2;
int addr, loop;
tempo = (unsigned char *) malloc(49179);
tempo = (unsigned char *) malloc(49179);
tempo2 = (unsigned char *) malloc(98308);
snap = (struct z80snapshot *) malloc(sizeof(struct z80snapshot));
snap = (struct z80snapshot *) malloc(sizeof(struct z80snapshot));
printf("Loading SNA file\n");
......@@ -485,14 +510,15 @@ int load_sna(const char *filename) {
snap->type = type;
//Some inits
for (loop = 0; loop < 16; loop++)
// Some inits
for (loop = 0; loop < 16; loop++) {
snap->ay_regs[loop] = 0;
}
snap->ay_latch = 0;
snap->issue_3 = true;
snap->joystick = 1; //kempston
snap->issue_3 = true;
snap->joystick = 1; // kempston
snap->I = tempo[0];
snap->I = tempo[0];
snap->LL = tempo[1];
snap->HH = tempo[2];
snap->EE = tempo[3];
......@@ -524,17 +550,16 @@ int load_sna(const char *filename) {
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->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];
v1 = tempo[23];
v2 = tempo[24];
addr = ((int) v1) + 256 * ((int) v2);
if ((addr < 16384) || (addr >= 65534)) {
free(tempo);
......@@ -544,13 +569,13 @@ int load_sna(const char *filename) {
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;
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;
snap->SP += 2;
snap->IFF1 = snap->IFF2;
memcpy(snap->page[0], tempo + 27, 16384);
<