Previous 15994 Revisions Next

r7146 Saturday 23rd January, 2010 at 14:44:34 UTC by Stefano Priore
[SPECTRUM] Moved snapshot & quickload code to formats/
[src/mess]mess.mak
[src/mess/drivers]spectrum.c timex.c
[src/mess/formats]spec_snqk.c* spec_snqk.h* timex_dck.c* timex_dck.h*
[src/mess/includes]spectrum.h

src/mess/includes/spectrum.h
r7145r7146
44 *
55 ****************************************************************************/
66
7#ifndef SPECTRUM_H
8#define SPECTRUM_H
7#ifndef __SPECTRUM_H__
8#define __SPECTRUM_H__
99
1010#include "devices/snapquik.h"
1111#include "devices/cartslot.h"
r7145r7146
4646#define TS2068_RIGHT_BORDER  96   /* Number of right hand border pixels */
4747#define TS2068_SCREEN_WIDTH (TS2068_LEFT_BORDER + TS2068_DISPLAY_XSIZE + TS2068_RIGHT_BORDER)
4848
49typedef enum
50{
51   TIMEX_CART_NONE,
52   TIMEX_CART_DOCK,
53   TIMEX_CART_EXROM,
54   TIMEX_CART_HOME
55} TIMEX_CART_TYPE;
56
57/*----------- defined in machine/spectrum.c -----------*/
58extern TIMEX_CART_TYPE timex_cart_type;
59extern UINT8 timex_cart_chunks;
60extern UINT8 * timex_cart_data;
61
62DEVICE_IMAGE_LOAD( timex_cart );
63DEVICE_IMAGE_UNLOAD( timex_cart );
64
65extern MACHINE_RESET( spectrum );
66
67extern SNAPSHOT_LOAD( spectrum );
68extern QUICKLOAD_LOAD( spectrum );
69
70
7149/*----------- defined in drivers/spectrum.c -----------*/
7250extern unsigned char *spectrum_screen_location;
7351
r7145r7146
7553INPUT_PORTS_EXTERN( spec_plus );
7654
7755MACHINE_DRIVER_EXTERN( spectrum );
56extern MACHINE_RESET( spectrum );
7857
7958extern READ8_HANDLER(spectrum_port_1f_r);
8059extern READ8_HANDLER(spectrum_port_7f_r);
r7145r7146
11897
11998extern VIDEO_UPDATE( tc2048 );
12099
121#endif /* SPECTRUM_H */
100#endif /* __SPECTRUM_H__ */
src/mess/formats/spec_snqk.c
r0r7146
1/***************************************************************************
2
3  mess/machine/spectrum.c
4
5  Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
6  I/O ports)
7
8  Changes:
9
10  KT 31/1/00 - Added support for .Z80. At the moment only 48k files are supported!
11  DJR 8/2/00 - Added checks to avoid trying to load 128K .Z80 files into 48K machine!
12  DJR 20/2/00 - Added support for .TAP files.
13  -----------------27/02/00 10:54-------------------
14  KT 27/2/00 - Added my changes for the WAV support
15  --------------------------------------------------
16  DJR 14/3/00 - Fixed +3 tape loading and added option to 'rewind' tapes when end reached.
17  DJR 21/4/00 - Added support for 128K .SNA and .Z80 files.
18  DJR 21/4/00 - Ensure 48K Basic ROM is used when running 48K snapshots on 128K machine.
19  DJR 03/5/00 - Fixed bug of not decoding last byte of .Z80 blocks.
20  DJR 08/5/00 - Fixed TS2068 .TAP loading.
21  DJR 19/5/00 - .TAP files are now classified as cassette files.
22  DJR 02/6/00 - Added support for .SCR files (screendumps).
23
24***************************************************************************/
25
26#include "emu.h"
27#include "cpu/z80/z80.h"
28#include "includes/spectrum.h"
29#include "eventlst.h"
30#include "video/border.h"
31#include "sound/ay8910.h"
32#include "formats/spec_snqk.h"
33#include "utils.h"
34
35
36void spectrum_setup_sna(running_machine *machine, unsigned char *pSnapshot, unsigned long SnapshotSize);
37void spectrum_setup_z80(running_machine *machine, unsigned char *pSnapshot, unsigned long SnapshotSize);
38void spectrum_setup_sp(running_machine *machine, unsigned char *pSnapshot, unsigned long SnapshotSize);
39
40/*******************************************************************
41 *
42 *      Update the memory and paging of the spectrum being emulated
43 *
44 *      if port_7ffd_data is -1 then machine is 48K - no paging
45 *      if port_1ffd_data is -1 then machine is 128K
46 *      if neither port is -1 then machine is +2a/+3
47 *
48 *      Note: the 128K .SNA and .Z80 file formats do not store the
49 *      port 1FFD setting so it is necessary to calculate the appropriate
50 *      value for the ROM paging.
51 *
52 *******************************************************************/
53static void spectrum_update_paging(running_machine *machine)
54{
55    if (spectrum_128_port_7ffd_data == -1)
56        return;
57    if (spectrum_plus3_port_1ffd_data == -1)
58        spectrum_128_update_memory(machine);
59
60    else
61    {
62        if (spectrum_128_port_7ffd_data & 0x10)
63            /* Page in Spec 48K basic ROM */
64            spectrum_plus3_port_1ffd_data = 0x04;
65        else
66            spectrum_plus3_port_1ffd_data = 0;
67        spectrum_plus3_update_memory(machine);
68    }
69}
70
71/* Page in the 48K Basic ROM. Used when running 48K snapshots on a 128K machine. */
72static void spectrum_page_basicrom(running_machine *machine)
73{
74    if (spectrum_128_port_7ffd_data == -1)
75        return;
76    spectrum_128_port_7ffd_data |= 0x10;
77    spectrum_update_paging(machine);
78}
79
80
81SNAPSHOT_LOAD(spectrum)
82{
83   UINT8 *snapshot_data = NULL;
84
85   snapshot_data = (UINT8*)malloc(snapshot_size);
86   if (!snapshot_data)
87      goto error;
88
89   image_fread(image, snapshot_data, snapshot_size);
90
91   if (!mame_stricmp(file_type, "sna"))
92   {
93      if ((snapshot_size != 49179) && (snapshot_size != 131103) && (snapshot_size != 147487))
94      {
95         logerror("Invalid .SNA file size.\n");
96         goto error;
97      }
98      spectrum_setup_sna(image->machine, snapshot_data, snapshot_size);
99   }
100   else if (!mame_stricmp(file_type, "sp"))
101   {
102      if (snapshot_data[0]!='S' && snapshot_data[1]!='P')
103      {
104         logerror("Invalid .SP signature.\n");
105         goto error;
106      }
107      spectrum_setup_sp(image->machine, snapshot_data, snapshot_size);
108   }
109   else
110   {
111      spectrum_setup_z80(image->machine, snapshot_data, snapshot_size);
112   }
113   free(snapshot_data);
114   //logerror("Snapshot loaded - new PC = %04x\n", (unsigned) cpu_get_reg(devtag_get_device(image->machine, "maincpu"), Z80_PC) & 0x0ffff);
115   return INIT_PASS;
116
117error:
118   if (snapshot_data)
119      free(snapshot_data);
120   return INIT_FAIL;
121}
122
123/*******************************************************************
124 *
125 *      Load a .SP file.
126 *
127 *      There are only 48K .SP files and their format is as follows:
128 *      Offset  Size    Description (all registers stored with LSB first)
129 *      0       2       "SP" (signature)
130 *      2       2       Program length in bytes (normally 49152 for 48K snaps, or 16384 for 16K snaps)
131 *      4       2       Program location (normally 16384)
132 *      6       8       BC,DE,HL,AF
133 *      14      4       IX,IY
134 *      18      8       BC',DE',HL',AF'
135 *      26      2       R,I
136 *      28      4       SP,PC
137 *      32      2       0 (reserved for future use)
138 *      34      1   Border color
139 *      35      1       0 (reserved for future use)
140 *      36      2       Status word
141 *      38      -       RAM dump
142 *
143 *  Status word:
144 *  Bit Description
145 *  15-8    Reserved for future use
146 *  7-6 Reserved for internal use (0)
147 *  5   Flash: 0=INK/1=PAPER
148 *  4   Interrupt pending for execution
149 *  3   If 1, IM 0; if 0, bit 1 determines interrupt mode
150 *          (Spectrum v 0.99e had this behaviour reversed, and this
151 *      bit was not used in versions previous to v 0.99e)
152 *  2   IFF2 (internal use)
153 *  1   Interrupt Mode (if bit 3 reset): 0=>IM1, 1=>IM2
154 *  0   IFF1: 0=DI/1=EI
155 *
156 *******************************************************************/
157void spectrum_setup_sp(running_machine *machine, unsigned char *pSnapshot, unsigned long SnapshotSize)
158{
159   int i;
160   UINT8 lo, hi, data;
161   UINT16 offset, size;
162   UINT16 status;
163   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
164
165   lo = pSnapshot[2] & 0x0ff;
166   hi = pSnapshot[3] & 0x0ff;
167   size = (hi << 8) | lo;
168   logerror ("Snapshot data size: %d.\n", size);
169   lo = pSnapshot[4] & 0x0ff;
170   hi = pSnapshot[5] & 0x0ff;
171   offset = (hi << 8) | lo;
172   logerror ("Snapshot data offset: %d.\n", offset);
173
174   lo = pSnapshot[6] & 0x0ff;
175   hi = pSnapshot[7] & 0x0ff;
176   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_BC, (hi << 8) | lo);
177   lo = pSnapshot[8] & 0x0ff;
178   hi = pSnapshot[9] & 0x0ff;
179   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_DE, (hi << 8) | lo);
180   lo = pSnapshot[10] & 0x0ff;
181   hi = pSnapshot[11] & 0x0ff;
182   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_HL, (hi << 8) | lo);
183   lo = pSnapshot[12] & 0x0ff;
184   hi = pSnapshot[13] & 0x0ff;
185   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_AF, (hi << 8) | lo);
186
187   lo = pSnapshot[14] & 0x0ff;
188   hi = pSnapshot[15] & 0x0ff;
189   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IX, (hi << 8) | lo);
190   lo = pSnapshot[16] & 0x0ff;
191   hi = pSnapshot[17] & 0x0ff;
192   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IY, (hi << 8) | lo);
193
194   lo = pSnapshot[18] & 0x0ff;
195   hi = pSnapshot[19] & 0x0ff;
196   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_BC2, (hi << 8) | lo);
197   lo = pSnapshot[20] & 0x0ff;
198   hi = pSnapshot[21] & 0x0ff;
199   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_DE2, (hi << 8) | lo);
200   lo = pSnapshot[22] & 0x0ff;
201   hi = pSnapshot[23] & 0x0ff;
202   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_HL2, (hi << 8) | lo);
203   lo = pSnapshot[24] & 0x0ff;
204   hi = pSnapshot[25] & 0x0ff;
205   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_AF2, (hi << 8) | lo);
206
207   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_R, (pSnapshot[26] & 0x0ff));
208   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_I, (pSnapshot[27] & 0x0ff));
209
210   lo = pSnapshot[28] & 0x0ff;
211   hi = pSnapshot[29] & 0x0ff;
212   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_SP, (hi << 8) | lo);
213   lo = pSnapshot[30] & 0x0ff;
214   hi = pSnapshot[31] & 0x0ff;
215   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_PC, (hi << 8) | lo);
216
217   lo = pSnapshot[32] & 0x0ff;
218   hi = pSnapshot[33] & 0x0ff;
219   if (((hi << 8) | lo)!=0)
220      logerror("Unknown meaning of word on position 32: %04x.\n", (hi << 8) | lo);
221
222   /* Set border colour */
223   spectrum_PreviousFE = (spectrum_PreviousFE & 0xf8) | (pSnapshot[34] & 0x07);
224   EventList_Reset();
225   border_set_last_color(pSnapshot[34] & 0x07);
226   border_force_redraw();
227
228   if ((pSnapshot[35]&0x0ff)!=0)
229      logerror("Unknown meaning of byte on position 35: %02x.\n", pSnapshot[35]&0x0ff);
230
231        lo = pSnapshot[36] & 0x0ff;
232   hi = pSnapshot[37] & 0x0ff;
233   status = (hi << 8) | lo;
234
235   data = (status & 0x01);
236   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IFF1, data);
237   data = (status & 0x04) >> 2;
238   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IFF2, data);
239
240   data = (status & 0x08) >> 3;
241   if (data)
242      cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IM, 0);
243   else
244   {
245      data = (status & 0x02) >> 1;
246      if (data)
247         cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IM, 2);
248      else
249         cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IM, 1);
250   }
251
252   data = (status & 0x10) >> 4;
253   cputag_set_input_line(machine, "maincpu", 0, data);
254   cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, data);
255   cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 0);
256
257   spectrum_page_basicrom(machine);
258
259   /* memory dump */
260   for (i = 0; i < size; i++)
261      memory_write_byte(space, i + offset, pSnapshot[38 + i]);
262}
263
264/*******************************************************************
265 *
266 *      Load a 48K or 128K .SNA file.
267 *
268 *      48K Format as follows:
269 *      Offset  Size    Description (all registers stored with LSB first)
270 *      0       1       I
271 *      1       18      HL',DE',BC',AF',HL,DE,BC,IY,IX
272 *      19      1       Interrupt (bit 2 contains IFF2 1=EI/0=DI
273 *      20      1       R
274 *      21      4       AF,SP
275 *      25      1       Interrupt Mode (0=IM0/1=IM1/2=IM2)
276 *      26      1       Border Colour (0..7)
277 *      27      48K     RAM dump 0x4000-0xffff
278 *      PC is stored on stack.
279 *
280 *      128K Format as follows:
281 *      Offset  Size    Description
282 *      0       27      Header as 48K
283 *      27      16K     RAM bank 5 (0x4000-0x7fff)
284 *      16411   16K     RAM bank 2 (0x8000-0xbfff)
285 *      32795   16K     RAM bank n (0xc000-0xffff - currently paged bank)
286 *      49179   2       PC
287 *      49181   1       port 7FFD setting
288 *      49182   1       TR-DOS rom paged (1=yes)
289 *      49183   16K     remaining RAM banks in ascending order
290 *
291 *      The bank in 0xc000 is always included even if it is page 2 or 5
292 *      in which case it is included twice.
293 *
294 *******************************************************************/
295void spectrum_setup_sna(running_machine *machine, unsigned char *pSnapshot, unsigned long SnapshotSize)
296{
297   int i, j, usedbanks[8];
298   long bank_offset;
299   unsigned char lo, hi, data;
300   unsigned short addr;
301   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
302
303   if ((SnapshotSize != 49179) && (spectrum_128_port_7ffd_data == -1))
304   {
305      logerror("Can't load 128K .SNA file into 48K machine\n");
306      return;
307   }
308
309   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_I, (pSnapshot[0] & 0x0ff));
310   lo = pSnapshot[1] & 0x0ff;
311   hi = pSnapshot[2] & 0x0ff;
312   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_HL2, (hi << 8) | lo);
313   lo = pSnapshot[3] & 0x0ff;
314   hi = pSnapshot[4] & 0x0ff;
315   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_DE2, (hi << 8) | lo);
316   lo = pSnapshot[5] & 0x0ff;
317   hi = pSnapshot[6] & 0x0ff;
318   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_BC2, (hi << 8) | lo);
319   lo = pSnapshot[7] & 0x0ff;
320   hi = pSnapshot[8] & 0x0ff;
321   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_AF2, (hi << 8) | lo);
322   lo = pSnapshot[9] & 0x0ff;
323   hi = pSnapshot[10] & 0x0ff;
324   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_HL, (hi << 8) | lo);
325   lo = pSnapshot[11] & 0x0ff;
326   hi = pSnapshot[12] & 0x0ff;
327   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_DE, (hi << 8) | lo);
328   lo = pSnapshot[13] & 0x0ff;
329   hi = pSnapshot[14] & 0x0ff;
330   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_BC, (hi << 8) | lo);
331   lo = pSnapshot[15] & 0x0ff;
332   hi = pSnapshot[16] & 0x0ff;
333   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IY, (hi << 8) | lo);
334   lo = pSnapshot[17] & 0x0ff;
335   hi = pSnapshot[18] & 0x0ff;
336   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IX, (hi << 8) | lo);
337   data = (pSnapshot[19] & 0x04) >> 2;
338   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IFF2, data);
339   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IFF1, data);
340   data = (pSnapshot[20] & 0x0ff);
341   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_R, data);
342   lo = pSnapshot[21] & 0x0ff;
343   hi = pSnapshot[22] & 0x0ff;
344   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_AF, (hi << 8) | lo);
345   lo = pSnapshot[23] & 0x0ff;
346   hi = pSnapshot[24] & 0x0ff;
347   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_SP, (hi << 8) | lo);
348   data = (pSnapshot[25] & 0x0ff);
349   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IM, data);
350
351   /* Set border colour */
352   spectrum_PreviousFE = (spectrum_PreviousFE & 0xf8) | (pSnapshot[26] & 0x07);
353   EventList_Reset();
354   border_set_last_color(pSnapshot[26] & 0x07);
355   border_force_redraw();
356
357   cputag_set_input_line(machine, "maincpu", 0, data);
358   cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, data);
359   cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 0);
360
361   if (SnapshotSize == 49179)
362      /* 48K Snapshot */
363      spectrum_page_basicrom(machine);
364   else
365   {
366      /* 128K Snapshot */
367      spectrum_128_port_7ffd_data = (pSnapshot[49181] & 0x0ff);
368      spectrum_update_paging(machine);
369   }
370
371   /* memory dump */
372   for (i = 0; i < 49152; i++)
373   {
374      memory_write_byte(space,i + 16384, pSnapshot[27 + i]);
375   }
376
377   if (SnapshotSize == 49179)
378   {
379      /* get pc from stack */
380      addr = cpu_get_reg(devtag_get_device(machine, "maincpu"), Z80_SP) & 0xFFFF;
381
382      lo = memory_read_byte(space,addr + 0);
383      hi = memory_read_byte(space,addr + 1);
384      cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_PC, (hi << 8) | lo);
385      memory_write_byte(space, addr + 0, 0);
386      memory_write_byte(space, addr + 1, 0);
387
388      memory_write_byte(space, 0x5CB0, 0xff); // Set NMIADD system variable to make game run
389                                    //  when directly started with cart mounted
390      addr += 2;
391      cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_SP, (addr & 0x0ffff));
392   }
393   else
394   {
395      /* Set up other RAM banks */
396      bank_offset = 49183;
397      for (i = 0; i < 8; i++)
398         usedbanks[i] = 0;
399
400      usedbanks[5] = 1;            /* 0x4000-0x7fff */
401      usedbanks[2] = 1;            /* 0x8000-0xbfff */
402      usedbanks[spectrum_128_port_7ffd_data & 0x07] = 1;   /* Banked memory */
403
404      for (i = 0; i < 8; i++)
405      {
406         if (!usedbanks[i])
407         {
408            logerror("Loading bank %d from offset %ld\n", i, bank_offset);
409            spectrum_128_port_7ffd_data &= 0xf8;
410            spectrum_128_port_7ffd_data += i;
411            spectrum_update_paging(machine);
412            for (j = 0; j < 16384; j++)
413               memory_write_byte(space,j + 49152, pSnapshot[bank_offset + j]);
414            bank_offset += 16384;
415         }
416      }
417
418      /* Reset paging */
419      spectrum_128_port_7ffd_data = (pSnapshot[49181] & 0x0ff);
420      spectrum_update_paging(machine);
421
422      /* program counter */
423      lo = pSnapshot[49179] & 0x0ff;
424      hi = pSnapshot[49180] & 0x0ff;
425      cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_PC, (hi << 8) | lo);
426   }
427}
428
429
430static void spectrum_z80_decompress_block(running_machine *machine,unsigned char *pSource, int Dest, int size)
431{
432   unsigned char ch;
433   int i;
434   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
435
436   do
437   {
438      /* get byte */
439      ch = pSource[0];
440
441      /* either start 0f 0x0ed, 0x0ed, xx yy or
442         * single 0x0ed */
443      if (ch == (unsigned char) 0x0ed)
444      {
445         if (pSource[1] == (unsigned char) 0x0ed)
446         {
447
448            /* 0x0ed, 0x0ed, xx yy */
449            /* repetition */
450
451            int count;
452            int data;
453
454            count = (pSource[2] & 0x0ff);
455
456            if (count == 0)
457               return;
458
459            data = (pSource[3] & 0x0ff);
460
461            pSource += 4;
462
463            if (count > size)
464               count = size;
465
466            size -= count;
467
468            for (i = 0; i < count; i++)
469            {
470               memory_write_byte(space,Dest, data);
471               Dest++;
472            }
473         }
474         else
475         {
476            /* single 0x0ed */
477            memory_write_byte(space,Dest, ch);
478            Dest++;
479            pSource++;
480            size--;
481
482         }
483      }
484      else
485      {
486         /* not 0x0ed */
487         memory_write_byte(space,Dest, ch);
488         Dest++;
489         pSource++;
490         size--;
491      }
492
493   }
494   while (size > 0);
495}
496
497static SPECTRUM_Z80_SNAPSHOT_TYPE spectrum_identify_z80 (unsigned char *pSnapshot, unsigned long SnapshotSize)
498{
499   unsigned char lo, hi, data;
500
501   if (SnapshotSize < 30)
502      return SPECTRUM_Z80_SNAPSHOT_INVALID;   /* Invalid file */
503
504   lo = pSnapshot[6] & 0x0ff;
505   hi = pSnapshot[7] & 0x0ff;
506   if (hi || lo)
507      return SPECTRUM_Z80_SNAPSHOT_48K_OLD;   /* V1.45 - 48K only */
508
509   lo = pSnapshot[30] & 0x0ff;
510   hi = pSnapshot[31] & 0x0ff;
511   data = pSnapshot[34] & 0x0ff;         /* Hardware mode */
512
513   if ((hi == 0) && (lo == 23))
514   {                  /* V2.01 */                     /* V2.01 format */
515      switch (data)
516      {
517         case 0:
518         case 1:   return SPECTRUM_Z80_SNAPSHOT_48K;
519         case 2:   return SPECTRUM_Z80_SNAPSHOT_SAMRAM;
520         case 3:
521         case 4:   return SPECTRUM_Z80_SNAPSHOT_128K;
522         case 128: return SPECTRUM_Z80_SNAPSHOT_TS2068;
523      }
524   }
525
526   if ((hi == 0) && (lo == 54))
527   {                  /* V3.0x */                     /* V2.01 format */
528      switch (data)
529      {
530         case 0:
531         case 1:
532         case 3:   return SPECTRUM_Z80_SNAPSHOT_48K;
533         case 2:   return SPECTRUM_Z80_SNAPSHOT_SAMRAM;
534         case 4:
535         case 5:
536         case 6:   return SPECTRUM_Z80_SNAPSHOT_128K;
537         case 128: return SPECTRUM_Z80_SNAPSHOT_TS2068;
538      }
539   }
540
541   return SPECTRUM_Z80_SNAPSHOT_INVALID;
542}
543
544/* now supports 48k & 128k .Z80 files */
545void spectrum_setup_z80(running_machine *machine, unsigned char *pSnapshot, unsigned long SnapshotSize)
546{
547   int i;
548   unsigned char lo, hi, data;
549   SPECTRUM_Z80_SNAPSHOT_TYPE z80_type;
550   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
551
552   z80_type = spectrum_identify_z80(pSnapshot, SnapshotSize);
553
554   switch (z80_type)
555   {
556      case SPECTRUM_Z80_SNAPSHOT_INVALID:
557            logerror("Invalid .Z80 file\n");
558            return;
559      case SPECTRUM_Z80_SNAPSHOT_48K_OLD:
560      case SPECTRUM_Z80_SNAPSHOT_48K:
561            logerror("48K .Z80 file\n");
562            if (!strcmp(machine->gamedrv->name,"ts2068"))
563               logerror("48K .Z80 file in TS2068\n");
564            break;
565      case SPECTRUM_Z80_SNAPSHOT_128K:
566            logerror("128K .Z80 file\n");
567            if (spectrum_128_port_7ffd_data == -1)
568            {
569               logerror("Not a 48K .Z80 file\n");
570               return;
571            }
572            if (!strcmp(machine->gamedrv->name,"ts2068"))
573            {
574               logerror("Not a TS2068 .Z80 file\n");
575               return;
576            }
577            break;
578      case SPECTRUM_Z80_SNAPSHOT_TS2068:
579            logerror("TS2068 .Z80 file\n");
580            if (strcmp(machine->gamedrv->name,"ts2068"))
581               logerror("Not a TS2068 machine\n");
582            break;
583      case SPECTRUM_Z80_SNAPSHOT_SAMRAM:
584            logerror("Hardware not supported - .Z80 file\n");
585            return;
586   }
587
588   /* AF */
589   hi = pSnapshot[0] & 0x0ff;
590   lo = pSnapshot[1] & 0x0ff;
591   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_AF, (hi << 8) | lo);
592   /* BC */
593   lo = pSnapshot[2] & 0x0ff;
594   hi = pSnapshot[3] & 0x0ff;
595   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_BC, (hi << 8) | lo);
596   /* HL */
597   lo = pSnapshot[4] & 0x0ff;
598   hi = pSnapshot[5] & 0x0ff;
599   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_HL, (hi << 8) | lo);
600
601   /* SP */
602   lo = pSnapshot[8] & 0x0ff;
603   hi = pSnapshot[9] & 0x0ff;
604   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_SP, (hi << 8) | lo);
605
606   /* I */
607   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_I, (pSnapshot[10] & 0x0ff));
608
609   /* R */
610   data = (pSnapshot[11] & 0x07f) | ((pSnapshot[12] & 0x01) << 7);
611   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_R, data);
612
613   /* Set border colour */
614   spectrum_PreviousFE = (spectrum_PreviousFE & 0xf8) | ((pSnapshot[12] & 0x0e) >> 1);
615   EventList_Reset();
616   border_set_last_color((pSnapshot[12] & 0x0e) >> 1);
617   border_force_redraw();
618
619   lo = pSnapshot[13] & 0x0ff;
620   hi = pSnapshot[14] & 0x0ff;
621   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_DE, (hi << 8) | lo);
622
623   lo = pSnapshot[15] & 0x0ff;
624   hi = pSnapshot[16] & 0x0ff;
625   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_BC2, (hi << 8) | lo);
626
627   lo = pSnapshot[17] & 0x0ff;
628   hi = pSnapshot[18] & 0x0ff;
629   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_DE2, (hi << 8) | lo);
630
631   lo = pSnapshot[19] & 0x0ff;
632   hi = pSnapshot[20] & 0x0ff;
633   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_HL2, (hi << 8) | lo);
634
635   hi = pSnapshot[21] & 0x0ff;
636   lo = pSnapshot[22] & 0x0ff;
637   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_AF2, (hi << 8) | lo);
638
639   lo = pSnapshot[23] & 0x0ff;
640   hi = pSnapshot[24] & 0x0ff;
641   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IY, (hi << 8) | lo);
642
643   lo = pSnapshot[25] & 0x0ff;
644   hi = pSnapshot[26] & 0x0ff;
645   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IX, (hi << 8) | lo);
646
647   /* Interrupt Flip/Flop */
648   if (pSnapshot[27] == 0)
649   {
650      cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IFF1, 0);
651      /* cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IRQ_STATE, 0); */
652   }
653   else
654   {
655      cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IFF1, 1);
656      /* cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IRQ_STATE, 1); */
657   }
658
659   cputag_set_input_line(machine, "maincpu", 0, data);
660   cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, data);
661   cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 0);
662
663   /* IFF2 */
664   if (pSnapshot[28] != 0)
665   {
666      data = 1;
667   }
668   else
669   {
670      data = 0;
671   }
672   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IFF2, data);
673
674   /* Interrupt Mode */
675   cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_IM, (pSnapshot[29] & 0x03));
676
677   if (z80_type == SPECTRUM_Z80_SNAPSHOT_48K_OLD)
678   {
679      lo = pSnapshot[6] & 0x0ff;
680      hi = pSnapshot[7] & 0x0ff;
681      cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_PC, (hi << 8) | lo);
682
683      spectrum_page_basicrom(machine);
684
685      if ((pSnapshot[12] & 0x020) == 0)
686      {
687         logerror("Not compressed\n");   /* not compressed */
688         for (i = 0; i < 49152; i++)
689            memory_write_byte(space,i + 16384, pSnapshot[30 + i]);
690      }
691      else
692      {
693         logerror("Compressed\n");   /* compressed */
694         spectrum_z80_decompress_block(machine, pSnapshot + 30, 16384, 49152);
695      }
696   }
697   else
698   {
699      unsigned char *pSource;
700      int header_size;
701
702      header_size = 30 + 2 + ((pSnapshot[30] & 0x0ff) | ((pSnapshot[31] & 0x0ff) << 8));
703
704      lo = pSnapshot[32] & 0x0ff;
705      hi = pSnapshot[33] & 0x0ff;
706      cpu_set_reg(devtag_get_device(machine, "maincpu"), Z80_PC, (hi << 8) | lo);
707
708      if ((z80_type == SPECTRUM_Z80_SNAPSHOT_128K) || ((z80_type == SPECTRUM_Z80_SNAPSHOT_TS2068) && !strcmp(machine->gamedrv->name,"ts2068")))
709      {
710         const device_config *ay8912 = devtag_get_device(machine, "ay8912");
711
712         /* Only set up sound registers for 128K machine or TS2068! */
713         for (i = 0; i < 16; i++)
714         {
715            ay8910_address_w(ay8912, 0, i);
716            ay8910_data_w(ay8912, 0, pSnapshot[39 + i]);
717         }
718         ay8910_address_w(ay8912, 0, pSnapshot[38]);
719      }
720
721      pSource = pSnapshot + header_size;
722
723      if (z80_type == SPECTRUM_Z80_SNAPSHOT_48K)
724         /* Ensure 48K Basic ROM is used */
725         spectrum_page_basicrom(machine);
726
727      do
728      {
729         unsigned short length;
730         unsigned char page;
731         int Dest = 0;
732
733         length = (pSource[0] & 0x0ff) | ((pSource[1] & 0x0ff) << 8);
734         page = pSource[2];
735
736         if (z80_type == SPECTRUM_Z80_SNAPSHOT_48K || z80_type == SPECTRUM_Z80_SNAPSHOT_TS2068)
737         {
738            switch (page)
739            {
740               case 4:   Dest = 0x08000;   break;
741               case 5:   Dest = 0x0c000;   break;
742               case 8:   Dest = 0x04000;   break;
743               default: Dest = 0; break;
744            }
745         }
746         else
747         {
748            /* 3 = bank 0, 4 = bank 1 ... 10 = bank 7 */
749            if ((page >= 3) && (page <= 10))
750            {
751               /* Page the appropriate bank into 0xc000 - 0xfff */
752               spectrum_128_port_7ffd_data = page - 3;
753               spectrum_update_paging(machine);
754               Dest = 0x0c000;
755            }
756            else
757               /* Other values correspond to ROM pages */
758               Dest = 0x0;
759         }
760
761         if (Dest != 0)
762         {
763            if (length == 0x0ffff)
764            {
765               /* block is uncompressed */
766               logerror("Not compressed\n");
767
768               /* not compressed */
769               for (i = 0; i < 16384; i++)
770                  memory_write_byte(space,i + Dest, pSource[i]);
771            }
772            else
773            {
774               logerror("Compressed\n");
775
776               /* block is compressed */
777               spectrum_z80_decompress_block(machine,&pSource[3], Dest, 16384);
778            }
779         }
780
781         /* go to next block */
782         pSource += (3 + length);
783      }
784      while ((pSource - pSnapshot) < SnapshotSize);
785
786      if ((spectrum_128_port_7ffd_data != -1) && (z80_type != SPECTRUM_Z80_SNAPSHOT_48K))
787      {
788         /* Set up paging */
789         spectrum_128_port_7ffd_data = (pSnapshot[35] & 0x0ff);
790         spectrum_update_paging(machine);
791      }
792      if ((z80_type == SPECTRUM_Z80_SNAPSHOT_48K) && !strcmp(machine->gamedrv->name,"ts2068"))
793      {
794         ts2068_port_f4_data = 0x03;
795         ts2068_port_ff_data = 0x00;
796         ts2068_update_memory(machine);
797      }
798      if (z80_type == SPECTRUM_Z80_SNAPSHOT_TS2068 && !strcmp(machine->gamedrv->name,"ts2068"))
799      {
800         ts2068_port_f4_data = pSnapshot[35];
801         ts2068_port_ff_data = pSnapshot[36];
802         ts2068_update_memory(machine);
803      }
804   }
805}
806
807QUICKLOAD_LOAD(spectrum)
808{
809   const address_space *space = cputag_get_address_space(image->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
810   int i;
811   int quick_addr = 0x4000;
812   int quick_length;
813   UINT8 *quick_data;
814   int read_;
815
816   quick_length = image_length(image);
817   quick_data = (UINT8 *)malloc(quick_length);
818   if (!quick_data)
819      return INIT_FAIL;
820
821   read_ = image_fread(image, quick_data, quick_length);
822   if (read_ != quick_length)
823      return INIT_FAIL;
824
825   for (i = 0; i < quick_length; i++)
826      memory_write_byte(space,i + quick_addr, quick_data[i]);
827
828   logerror("quick loading at %.4x size:%.4x\n", quick_addr, quick_length);
829   return INIT_PASS;
830}
src/mess/formats/spec_snqk.h
r0r7146
1/*****************************************************************************
2 *
3 * formats/spec_snqk.h
4 *
5 ****************************************************************************/
6
7#ifndef __SPEC_SNQK_H__
8#define __SPEC_SNQK_H__
9
10#include "devices/snapquik.h"
11#include "devices/cartslot.h"
12
13typedef enum
14{
15    SPECTRUM_SNAPSHOT_NONE,
16    SPECTRUM_SNAPSHOT_SNA,
17    SPECTRUM_SNAPSHOT_Z80,
18    SPECTRUM_SNAPSHOT_SP,
19    SPECTRUM_TAPEFILE_TAP
20} SPECTRUM_SNAPSHOT_TYPE;
21
22typedef enum {
23    SPECTRUM_Z80_SNAPSHOT_INVALID,
24    SPECTRUM_Z80_SNAPSHOT_48K_OLD,
25    SPECTRUM_Z80_SNAPSHOT_48K,
26    SPECTRUM_Z80_SNAPSHOT_SAMRAM,
27    SPECTRUM_Z80_SNAPSHOT_128K,
28    SPECTRUM_Z80_SNAPSHOT_TS2068
29} SPECTRUM_Z80_SNAPSHOT_TYPE;
30
31SNAPSHOT_LOAD( spectrum );
32QUICKLOAD_LOAD( spectrum );
33
34#endif  /* __SPEC_SNQK_H__ */
No newline at end of file
src/mess/formats/timex_dck.c
r0r7146
1/***************************************************************************
2
3  mess/machine/spectrum.c
4
5  Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
6  I/O ports)
7
8  Changes:
9
10  KT 31/1/00 - Added support for .Z80. At the moment only 48k files are supported!
11  DJR 8/2/00 - Added checks to avoid trying to load 128K .Z80 files into 48K machine!
12  DJR 20/2/00 - Added support for .TAP files.
13  -----------------27/02/00 10:54-------------------
14  KT 27/2/00 - Added my changes for the WAV support
15  --------------------------------------------------
16  DJR 14/3/00 - Fixed +3 tape loading and added option to 'rewind' tapes when end reached.
17  DJR 21/4/00 - Added support for 128K .SNA and .Z80 files.
18  DJR 21/4/00 - Ensure 48K Basic ROM is used when running 48K snapshots on 128K machine.
19  DJR 03/5/00 - Fixed bug of not decoding last byte of .Z80 blocks.
20  DJR 08/5/00 - Fixed TS2068 .TAP loading.
21  DJR 19/5/00 - .TAP files are now classified as cassette files.
22  DJR 02/6/00 - Added support for .SCR files (screendumps).
23
24***************************************************************************/
25
26#include "emu.h"
27#include "formats/timex_dck.h"
28#include "video/border.h"
29#include "sound/ay8910.h"
30#include "utils.h"
31
32
33
34DEVICE_IMAGE_LOAD( timex_cart )
35{
36   int file_size;
37   UINT8 * file_data;
38
39   int chunks_in_file = 0;
40
41   int i;
42
43   logerror ("Trying to load cart\n");
44
45   file_size = image_length(image);
46
47   if (file_size < 0x09)
48   {
49      logerror ("Bad file size\n");
50      return INIT_FAIL;
51   }
52
53   file_data = (UINT8 *)malloc(file_size);
54   if (file_data == NULL)
55   {
56      logerror ("Memory allocating error\n");
57      return INIT_FAIL;
58   }
59
60   image_fread(image, file_data, file_size);
61
62   for (i=0; i<8; i++)
63      if(file_data[i+1]&0x02)   chunks_in_file++;
64
65   if (chunks_in_file*0x2000+0x09 != file_size)
66   {
67      free (file_data);
68      logerror ("File corrupted\n");
69      return INIT_FAIL;
70   }
71
72   switch (file_data[0x00])
73   {
74      case 0x00:   logerror ("DOCK cart\n");
75            timex_cart_type = TIMEX_CART_DOCK;
76            timex_cart_data = (UINT8*) malloc (0x10000);
77            if (!timex_cart_data)
78            {
79               free (file_data);
80               logerror ("Memory allocate error\n");
81               return INIT_FAIL;
82            }
83            chunks_in_file = 0;
84            for (i=0; i<8; i++)
85            {
86               timex_cart_chunks = timex_cart_chunks | ((file_data[i+1]&0x01)<<i);
87               if (file_data[i+1]&0x02)
88               {
89                  memcpy (timex_cart_data+i*0x2000, file_data+0x09+chunks_in_file*0x2000, 0x2000);
90                  chunks_in_file++;
91               }
92               else
93               {
94                  if (file_data[i+1]&0x01)
95                     memset (timex_cart_data+i*0x2000, 0x00, 0x2000);
96                  else
97                     memset (timex_cart_data+i*0x2000, 0xff, 0x2000);
98               }
99            }
100            free (file_data);
101            break;
102
103      default:   logerror ("Cart type not supported\n");
104            free (file_data);
105            timex_cart_type = TIMEX_CART_NONE;
106            return INIT_FAIL;
107   }
108
109   logerror ("Cart loaded\n");
110   logerror ("Chunks %02x\n", timex_cart_chunks);
111   return INIT_PASS;
112}
113
114DEVICE_IMAGE_UNLOAD( timex_cart )
115{
116   if (timex_cart_data)
117   {
118      free (timex_cart_data);
119      timex_cart_data = NULL;
120   }
121   timex_cart_type = TIMEX_CART_NONE;
122   timex_cart_chunks = 0x00;
123}
src/mess/formats/timex_dck.h
r0r7146
1/*****************************************************************************
2 *
3 * formats/timex_dck.h
4 *
5 ****************************************************************************/
6
7#ifndef __TIMEX_DCK_H__
8#define __TIMEX_DCK_H__
9
10#include "devices/snapquik.h"
11#include "devices/cartslot.h"
12
13typedef enum
14{
15    TIMEX_CART_NONE,
16    TIMEX_CART_DOCK,
17    TIMEX_CART_EXROM,
18    TIMEX_CART_HOME
19} TIMEX_CART_TYPE;
20
21extern TIMEX_CART_TYPE timex_cart_type;
22extern UINT8 timex_cart_chunks;
23extern UINT8 *timex_cart_data;
24
25DEVICE_IMAGE_LOAD( timex_cart );
26DEVICE_IMAGE_UNLOAD( timex_cart );
27
28#endif  /* __TIMEX_DCK_H__ */
No newline at end of file
src/mess/mess.mak
r7145r7146
13141314   $(MESS_DRIVERS)/scorpion.o   \
13151315   $(MESS_DRIVERS)/atm.o      \
13161316   $(MESS_DRIVERS)/pentagon.o   \
1317   $(MESS_MACHINE)/spectrum.o   \
13181317   $(MESS_FORMATS)/trd_dsk.o   \
13191318   $(MESS_MACHINE)/beta.o      \
13201319   $(MESS_FORMATS)/zx81_p.o   \
13211320   $(MESS_FORMATS)/tzx_cas.o   \
1321   $(MESS_FORMATS)/spec_snqk.o   \
1322   $(MESS_FORMATS)/timex_dck.o   \
13221323   $(MESS_DRIVERS)/ql.o      \
13231324   $(MESS_VIDEO)/zx8301.o      \
13241325   $(MESS_MACHINE)/zx8302.o   \
src/mess/drivers/spectrum.c
r7145r7146
154154#include "devices/cartslot.h"
155155#include "devices/cassette.h"
156156#include "formats/tzx_cas.h"
157#include "formats/spec_snqk.h"
157158
158159unsigned char *spectrum_screen_location = NULL;
159160
r7145r7146
198199   spectrum_PreviousFE = data;
199200}
200201
202static DIRECT_UPDATE_HANDLER(spectrum_direct)
203{
204    /* Hack for correct handling 0xffff interrupt vector */
205    if (address == 0x0001)
206        if (cpu_get_reg(devtag_get_device(space->machine, "maincpu"), REG_GENPCBASE)==0xffff)
207        {
208            cpu_set_reg(devtag_get_device(space->machine, "maincpu"), Z80_PC, 0xfff4);
209            return 0xfff4;
210        }
211    return address;
212}
213
214MACHINE_RESET( spectrum )
215{
216    const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
217    memory_set_direct_update_handler(space, spectrum_direct);
218}
219
201220static ADDRESS_MAP_START (spectrum_mem, ADDRESS_SPACE_PROGRAM, 8)
202221   AM_RANGE(0x0000, 0x3fff) AM_ROM
203222   AM_RANGE(0x4000, 0x5aff) AM_RAM AM_BASE(&spectrum_video_ram )
src/mess/drivers/timex.c
r7145r7146
154154#include "sound/speaker.h"
155155#include "sound/ay8910.h"
156156#include "formats/tzx_cas.h"
157#include "formats/spec_snqk.h"
158#include "formats/timex_dck.h"
157159#include "machine/beta.h"
158160#include "devices/messram.h"
159161
162TIMEX_CART_TYPE timex_cart_type = TIMEX_CART_NONE;
163UINT8 timex_cart_chunks = 0x00;
164UINT8 *timex_cart_data;
165
160166static const ay8910_interface spectrum_ay_interface =
161167{
162168   AY8910_LEGACY_OUTPUT,

Previous 15994 Revisions Next


© 1998-2018 The MESS Team