Previous 15994 Revisions Next

r2517 Thursday 1st May, 2008 at 21:10:44 UTC by Miodrag Milanović
[SPECTRUM] Split into multiple drivers and cleanup
[docs]messnew.txt
[src/mess]mess.mak
[src/mess/drivers]pentagon.c* scorpion.c* spec128.c* specpls3.c* spectrum.c timex.c*
[src/mess/includes]spectrum.h
[src/mess/machine]spectrum.c
[src/mess/video]border.c spec128.c* spectrum.c timex.c*

src/mess/includes/spectrum.h
r2516r2517
7171
7272
7373/*----------- defined in drivers/spectrum.c -----------*/
74INPUT_PORTS_EXTERN( spectrum );
75MACHINE_DRIVER_EXTERN( spectrum );
76SYSTEM_CONFIG_EXTERN(spectrum)
77SYSTEM_CONFIG_EXTERN(spectrum_common)
7478
75extern void ts2068_update_memory(running_machine *machine);
76extern int spectrum_128_port_7ffd_data;
77extern int spectrum_plus3_port_1ffd_data;
78extern int ts2068_port_ff_data;
79extern int ts2068_port_f4_data;
79extern READ8_HANDLER(spectrum_port_1f_r);
80extern READ8_HANDLER(spectrum_port_7f_r);
81extern READ8_HANDLER(spectrum_port_df_r);
82extern READ8_HANDLER(spectrum_port_fe_r);
83extern WRITE8_HANDLER(spectrum_port_fe_w);
8084extern int PreviousFE;
85
86/*----------- defined in drivers/spec128.c -----------*/
87MACHINE_DRIVER_EXTERN( spectrum_128 );
88
89extern READ8_HANDLER(spectrum_128_port_fffd_r);
90extern WRITE8_HANDLER(spectrum_128_port_bffd_w);
91extern WRITE8_HANDLER(spectrum_128_port_fffd_w);
8192extern unsigned char *spectrum_128_screen_location;
93extern void spectrum_128_update_memory(running_machine *machine);
94extern int spectrum_128_port_7ffd_data;
8295
83extern void spectrum_128_update_memory(running_machine *machine);
96/*----------- defined in drivers/specpls3.c -----------*/
97extern int spectrum_plus3_port_1ffd_data;
8498extern void spectrum_plus3_update_memory(running_machine *machine);
8599
100/*----------- defined in drivers/spec128.c -----------*/
101extern void ts2068_update_memory(running_machine *machine);
102extern int ts2068_port_ff_data;
103extern int ts2068_port_f4_data;
86104
87105/*----------- defined in video/spectrum.c -----------*/
106extern int frame_number;    /* Used for handling FLASH 1 */
107extern int flash_invert;
88108
109extern PALETTE_INIT( spectrum );
110
89111extern VIDEO_START( spectrum );
90112extern VIDEO_UPDATE( spectrum );
91113extern VIDEO_EOF( spectrum );
92114
115extern unsigned char *spectrum_characterram;
116extern unsigned char *spectrum_colorram;
117
118extern const gfx_layout spectrum_charlayout;
119
120/*----------- defined in video/spec128.c -----------*/
121extern PALETTE_INIT( spectrum_128 );
122
93123extern VIDEO_START( spectrum_128 );
94124extern VIDEO_UPDATE( spectrum_128 );
95125
126
127/*----------- defined in video/timex.c -----------*/
96128extern VIDEO_EOF( ts2068 );
97129extern VIDEO_UPDATE( ts2068 );
98130
99131extern VIDEO_UPDATE( tc2048 );
100132
101extern unsigned char *spectrum_characterram;
102extern unsigned char *spectrum_colorram;
103extern WRITE8_HANDLER ( spectrum_characterram_w );
104extern  READ8_HANDLER  ( spectrum_characterram_r );
105extern WRITE8_HANDLER ( spectrum_colorram_w );
106extern  READ8_HANDLER  ( spectrum_colorram_r );
107
108
109133#endif /* SPECTRUM_H */
src/mess/video/spectrum.c
r2516r2517
1919#include "video/border.h"
2020
2121
22unsigned char *spectrum_characterram;
23unsigned char *spectrum_colorram;
24static unsigned char *charsdirty;
25static int frame_number;    /* Used for handling FLASH 1 */
26static int flash_invert;
22UINT8 *spectrum_characterram;
23UINT8 *spectrum_colorram;
2724
28INLINE void spectrum_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color)
29{
30   *BITMAP_ADDR16(bitmap, y, x) = (UINT16)color;
31}
25int frame_number;    /* Used for handling FLASH 1 */
26int flash_invert;
3227
3328/***************************************************************************
3429  Start the video hardware emulation.
r2516r2517
3732{
3833   frame_number = 0;
3934   flash_invert = 0;
40   spectrum_characterram = auto_malloc(0x1800);
41
42   spectrum_colorram = auto_malloc(0x300);
43
44   charsdirty = auto_malloc(0x300);
45
46   memset(charsdirty,1,0x300);
4735   EventList_Initialise(30000);
4836}
4937
50/* screen is stored as:
5132 chars wide. first 0x100 bytes are top scan of lines 0 to 7 */
5238
53WRITE8_HANDLER (spectrum_characterram_w)
54{
55   spectrum_characterram[offset] = data;
56
57   charsdirty[((offset & 0x0f800)>>3) + (offset & 0x0ff)] = 1;
58}
59
60 READ8_HANDLER (spectrum_characterram_r)
61{
62   return(spectrum_characterram[offset]);
63}
64
65
66WRITE8_HANDLER (spectrum_colorram_w)
67{
68        /* Will eventually be used to emulate hi-res colour effects. No point
69           doing it now as contented memory is not emulated so timings will
70           be way off. (eg Zynaps taking 212 cycles not 224 per scanline)
71        */
72/*        EventList_AddItemOffset(machine, offset+0x5800, data, cpu_getcurrentcycles()); */
73
74   spectrum_colorram[offset] = data;
75   charsdirty[offset] = 1;
76}
77
78 READ8_HANDLER (spectrum_colorram_r)
79{
80   return(spectrum_colorram[offset]);
81}
82
8339/* return the color to be used inverting FLASHing colors if necessary */
8440INLINE unsigned char get_display_color (unsigned char color, int invert)
8541{
r2516r2517
11773}
11874
11975
120/* Update FLASH status for ts2068. Assumes flash update every 1/2s. */
121VIDEO_EOF( ts2068 )
122{
123        EVENT_LIST_ITEM *pItem;
124        int NumItems;
12576
126        frame_number++;
127        if (frame_number >= 30)
128        {
129                frame_number = 0;
130                flash_invert = !flash_invert;
131        }
132
133        /* Empty event buffer for undisplayed frames noting the last border
134           colour (in case colours are not changed in the next frame). */
135        NumItems = EventList_NumEvents();
136        if (NumItems)
137        {
138                pItem = EventList_GetFirstItem();
139                set_last_border_color ( pItem[NumItems-1].Event_Data );
140                EventList_Reset();
141            EventList_SetOffsetStartTime ( ATTOTIME_TO_CYCLES(0, attotime_mul(video_screen_get_scan_period(machine->primary_screen), video_screen_get_vpos(machine->primary_screen))) );
142                logerror ("Event log reset in callback fn.\n");
143        }
144}
145
14677/***************************************************************************
14778  Update the spectrum screen display.
14879
r2516r2517
174105
175106   if (full_refresh)
176107   {
177      memset(charsdirty,1,0x300);
178108      last_invert = flash_invert;
179109   }
180110   else
r2516r2517
182112      /* Update all flashing characters when necessary */
183113      if (last_invert != flash_invert)
184114      {
185         for (count=0;count<0x300;count++)
186            if (spectrum_colorram[count] & 0x80)
187               charsdirty[count] = 1;
188115         last_invert = flash_invert;
189116      }
190117   }
191118
192119    for (count=0;count<32*8;count++)
193120    {
194      if (charsdirty[count]) {
195121         decodechar( screen->machine->gfx[0],count,spectrum_characterram);
196      }
197
198      if (charsdirty[count+256]) {
199122         decodechar( screen->machine->gfx[1],count,&spectrum_characterram[0x800]);
200      }
201
202      if (charsdirty[count+512]) {
203123         decodechar( screen->machine->gfx[2],count,&spectrum_characterram[0x1000]);
204      }
205124   }
206125
207126    for (count=0;count<32*8;count++)
208127    {
209   int sx=count%32;
210   int sy=count/32;
211   unsigned char color;
128      int sx=count%32;
129      int sy=count/32;
130      unsigned char color;
212131
213            if (charsdirty[count]) {
214                    color=get_display_color(spectrum_colorram[count],
215                                            flash_invert);
132        color=get_display_color(spectrum_colorram[count],flash_invert);
216133      drawgfx(bitmap,screen->machine->gfx[0],
217134         count,
218135         color+8, // use 2nd part of palette
219136         0,0,
220                            (sx*8)+SPEC_LEFT_BORDER,(sy*8)+SPEC_TOP_BORDER,
137           (sx*8)+SPEC_LEFT_BORDER,(sy*8)+SPEC_TOP_BORDER,
221138         0,TRANSPARENCY_NONE,0);
222      charsdirty[count] = 0;
223   }
224139
225   if (charsdirty[count+256]) {
226                    color=get_display_color(spectrum_colorram[count+0x100],
227                                            flash_invert);
140        color=get_display_color(spectrum_colorram[count+0x100],flash_invert);
228141      drawgfx(bitmap,screen->machine->gfx[1],
229142         count,
230143         color+8, // use 2nd part of palette
231144         0,0,
232                            (sx*8)+SPEC_LEFT_BORDER,((sy+8)*8)+SPEC_TOP_BORDER,
145         (sx*8)+SPEC_LEFT_BORDER,((sy+8)*8)+SPEC_TOP_BORDER,
233146         0,TRANSPARENCY_NONE,0);
234      charsdirty[count+256] = 0;
235   }
236
237   if (charsdirty[count+512]) {
238                    color=get_display_color(spectrum_colorram[count+0x200],
239                                            flash_invert);
147           
148        color=get_display_color(spectrum_colorram[count+0x200],flash_invert);
240149      drawgfx(bitmap,screen->machine->gfx[2],
241150         count,
242151         color+8, // use 2nd part of palette
243152         0,0,
244                            (sx*8)+SPEC_LEFT_BORDER,((sy+16)*8)+SPEC_TOP_BORDER,
153         (sx*8)+SPEC_LEFT_BORDER,((sy+16)*8)+SPEC_TOP_BORDER,
245154         0,TRANSPARENCY_NONE,0);
246      charsdirty[count+512] = 0;
247155   }
248}
249156
250157    /* When screen refresh is called there is only one blank line
251158        (synchronised with start of screen data) before the border lines.
r2516r2517
259166   return 0;
260167}
261168
262VIDEO_START( spectrum_128 )
169const gfx_layout spectrum_charlayout =
263170{
264   frame_number = 0;
265   flash_invert = 0;
171   8,8,
172   256,
173   1,                  /* 1 bits per pixel */
266174
267   EventList_Initialise(30000);
268}
175   { 0 },               /* no bitplanes; 1 bit per pixel */
269176
270/* Refresh the spectrum 128 screen (code modified from COUPE.C) */
271VIDEO_UPDATE( spectrum_128 )
272{
273        /* for now do a full-refresh */
274        int x, y, b, scrx, scry;
275        unsigned short ink, pap;
276        unsigned char *attr, *scr;
277      int full_refresh = 1;
177   { 0, 1, 2, 3, 4, 5, 6, 7 },
178   { 0, 8*256, 16*256, 24*256, 32*256, 40*256, 48*256, 56*256 },
278179
279        scr=spectrum_128_screen_location;
180   8            /* every char takes 1 consecutive byte */
181};
280182
281        for (y=0; y<192; y++)
282        {
283                scrx=SPEC_LEFT_BORDER;
284                scry=((y&7) * 8) + ((y&0x38)>>3) + (y&0xC0);
285                attr=spectrum_128_screen_location + ((scry>>3)*32) + 0x1800;
183#define ZX_COL_0   MAKE_RGB(0x00, 0x00, 0x00)
184#define ZX_COL_1   MAKE_RGB(0x00, 0x00, 0xbf)
185#define ZX_COL_2   MAKE_RGB(0xbf, 0x00, 0x00)
186#define ZX_COL_3   MAKE_RGB(0xbf, 0x00, 0xbf)
187#define ZX_COL_4   MAKE_RGB(0x00, 0xbf, 0x00)
188#define ZX_COL_5   MAKE_RGB(0x00, 0xbf, 0xbf)
189#define ZX_COL_6   MAKE_RGB(0xbf, 0xbf, 0x00)
190#define ZX_COL_7   MAKE_RGB(0xbf, 0xbf, 0xbf)
191#define ZX_COL_8   MAKE_RGB(0x00, 0x00, 0x00)
192#define ZX_COL_9   MAKE_RGB(0x00, 0x00, 0xff)
193#define ZX_COL_A   MAKE_RGB(0xff, 0x00, 0x00)
194#define ZX_COL_B   MAKE_RGB(0xff, 0x00, 0xff)
195#define ZX_COL_C   MAKE_RGB(0x00, 0xff, 0x00)
196#define ZX_COL_D   MAKE_RGB(0x00, 0xff, 0xff)
197#define ZX_COL_E   MAKE_RGB(0xff, 0xff, 0x00)
198#define ZX_COL_F   MAKE_RGB(0xff, 0xff, 0xff)
286199
287                for (x=0;x<32;x++)
288                {
289                        /* Get ink and paper colour with bright */
290                        if (flash_invert && (*attr & 0x80))
291                        {
292                                ink=((*attr)>>3) & 0x0f;
293                                pap=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
294                        }
295                        else
296                        {
297                                ink=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
298                                pap=((*attr)>>3) & 0x0f;
299                        }
200const rgb_t spectrum_palette[256 + 16] = {
201   ZX_COL_0,ZX_COL_1,ZX_COL_2,ZX_COL_3,ZX_COL_4,ZX_COL_5,ZX_COL_6,ZX_COL_7,ZX_COL_8,ZX_COL_9,ZX_COL_A,ZX_COL_B,ZX_COL_C,ZX_COL_D,ZX_COL_E,ZX_COL_F,
202   
203   ZX_COL_0,ZX_COL_0,ZX_COL_0,ZX_COL_1,ZX_COL_0,ZX_COL_2,ZX_COL_0,ZX_COL_3,ZX_COL_0,ZX_COL_4,ZX_COL_0,ZX_COL_5,ZX_COL_0,ZX_COL_6,ZX_COL_0,ZX_COL_7,
204   ZX_COL_1,ZX_COL_0,ZX_COL_1,ZX_COL_1,ZX_COL_1,ZX_COL_2,ZX_COL_1,ZX_COL_3,ZX_COL_1,ZX_COL_4,ZX_COL_1,ZX_COL_5,ZX_COL_1,ZX_COL_6,ZX_COL_1,ZX_COL_7,
205   ZX_COL_2,ZX_COL_0,ZX_COL_2,ZX_COL_1,ZX_COL_2,ZX_COL_2,ZX_COL_2,ZX_COL_3,ZX_COL_2,ZX_COL_4,ZX_COL_2,ZX_COL_5,ZX_COL_2,ZX_COL_6,ZX_COL_2,ZX_COL_7,   
206   ZX_COL_3,ZX_COL_0,ZX_COL_3,ZX_COL_1,ZX_COL_3,ZX_COL_2,ZX_COL_3,ZX_COL_3,ZX_COL_3,ZX_COL_4,ZX_COL_3,ZX_COL_5,ZX_COL_3,ZX_COL_6,ZX_COL_3,ZX_COL_7,   
207   ZX_COL_4,ZX_COL_0,ZX_COL_4,ZX_COL_1,ZX_COL_4,ZX_COL_2,ZX_COL_4,ZX_COL_3,ZX_COL_4,ZX_COL_4,ZX_COL_4,ZX_COL_5,ZX_COL_4,ZX_COL_6,ZX_COL_4,ZX_COL_7,   
208   ZX_COL_5,ZX_COL_0,ZX_COL_5,ZX_COL_1,ZX_COL_5,ZX_COL_2,ZX_COL_5,ZX_COL_3,ZX_COL_5,ZX_COL_4,ZX_COL_5,ZX_COL_5,ZX_COL_5,ZX_COL_6,ZX_COL_5,ZX_COL_7,
209   ZX_COL_6,ZX_COL_0,ZX_COL_6,ZX_COL_1,ZX_COL_6,ZX_COL_2,ZX_COL_6,ZX_COL_3,ZX_COL_6,ZX_COL_4,ZX_COL_6,ZX_COL_5,ZX_COL_6,ZX_COL_6,ZX_COL_6,ZX_COL_7,
210   ZX_COL_7,ZX_COL_0,ZX_COL_7,ZX_COL_1,ZX_COL_7,ZX_COL_2,ZX_COL_7,ZX_COL_3,ZX_COL_7,ZX_COL_4,ZX_COL_7,ZX_COL_5,ZX_COL_7,ZX_COL_6,ZX_COL_7,ZX_COL_7,   
211   ZX_COL_8,ZX_COL_8,ZX_COL_8,ZX_COL_9,ZX_COL_8,ZX_COL_A,ZX_COL_8,ZX_COL_B,ZX_COL_8,ZX_COL_C,ZX_COL_8,ZX_COL_D,ZX_COL_8,ZX_COL_E,ZX_COL_8,ZX_COL_F,
212   ZX_COL_9,ZX_COL_8,ZX_COL_9,ZX_COL_9,ZX_COL_9,ZX_COL_A,ZX_COL_9,ZX_COL_B,ZX_COL_9,ZX_COL_C,ZX_COL_9,ZX_COL_D,ZX_COL_9,ZX_COL_E,ZX_COL_9,ZX_COL_F,
213   ZX_COL_A,ZX_COL_8,ZX_COL_A,ZX_COL_9,ZX_COL_A,ZX_COL_A,ZX_COL_A,ZX_COL_B,ZX_COL_A,ZX_COL_C,ZX_COL_A,ZX_COL_D,ZX_COL_A,ZX_COL_E,ZX_COL_A,ZX_COL_F,   
214   ZX_COL_B,ZX_COL_8,ZX_COL_B,ZX_COL_9,ZX_COL_B,ZX_COL_A,ZX_COL_B,ZX_COL_B,ZX_COL_B,ZX_COL_C,ZX_COL_B,ZX_COL_D,ZX_COL_B,ZX_COL_E,ZX_COL_B,ZX_COL_F,   
215   ZX_COL_C,ZX_COL_8,ZX_COL_C,ZX_COL_9,ZX_COL_C,ZX_COL_A,ZX_COL_C,ZX_COL_B,ZX_COL_C,ZX_COL_C,ZX_COL_C,ZX_COL_D,ZX_COL_C,ZX_COL_E,ZX_COL_C,ZX_COL_F,   
216   ZX_COL_D,ZX_COL_8,ZX_COL_D,ZX_COL_9,ZX_COL_D,ZX_COL_A,ZX_COL_D,ZX_COL_B,ZX_COL_D,ZX_COL_C,ZX_COL_D,ZX_COL_D,ZX_COL_D,ZX_COL_E,ZX_COL_D,ZX_COL_F,
217   ZX_COL_E,ZX_COL_8,ZX_COL_E,ZX_COL_9,ZX_COL_E,ZX_COL_A,ZX_COL_E,ZX_COL_B,ZX_COL_E,ZX_COL_C,ZX_COL_E,ZX_COL_D,ZX_COL_E,ZX_COL_E,ZX_COL_E,ZX_COL_F,
218   ZX_COL_F,ZX_COL_8,ZX_COL_F,ZX_COL_9,ZX_COL_F,ZX_COL_A,ZX_COL_F,ZX_COL_B,ZX_COL_F,ZX_COL_C,ZX_COL_F,ZX_COL_D,ZX_COL_F,ZX_COL_E,ZX_COL_F,ZX_COL_F
219   };
300220
301                        for (b=0x80;b!=0;b>>=1)
302                        {
303                                if (*scr&b)
304                                        spectrum_plot_pixel(bitmap,scrx++,SPEC_TOP_BORDER+scry,ink);
305                                else
306                                        spectrum_plot_pixel(bitmap,scrx++,SPEC_TOP_BORDER+scry,pap);
307         }
308                scr++;
309                attr++;
310                }
311   }
312221
313   draw_border(screen->machine, bitmap, full_refresh,
314      SPEC_TOP_BORDER, SPEC_DISPLAY_YSIZE, SPEC_BOTTOM_BORDER,
315      SPEC_LEFT_BORDER, SPEC_DISPLAY_XSIZE, SPEC_RIGHT_BORDER,
316      SPEC_LEFT_BORDER_CYCLES, SPEC_DISPLAY_XSIZE_CYCLES,
317      SPEC_RIGHT_BORDER_CYCLES, SPEC128_RETRACE_CYCLES, 200, 0xfe);
318   return 0;
319}
320
321/*******************************************************************
322 *
323 *      Update the TS2068 display.
324 *
325 *      Port ff is used to set the display mode.
326 *
327 *      bits 2..0  Video Mode Select
328 *      000 = Primary DFILE active   (at 0x4000-0x5aff)
329 *      001 = Secondary DFILE active (at 0x6000-0x7aff)
330 *      010 = Extended Colour Mode   (chars at 0x4000-0x57ff, colors 0x6000-0x7aff)
331 *      110 = 64 column mode         (columns 0,2,4,...62 from DFILE 1
332 *                                    columns 1,3,5,...63 from DFILE 2)
333 *      other = unpredictable results
334 *
335 *      bits 5..3  64 column mode ink/paper selection (attribute value in brackets)
336 *      000 = Black/White   (56)        100 = Green/Magenta (28)
337 *      001 = Blue/Yellow   (49)        101 = Cyan/Red      (21)
338 *      010 = Red/Cyan      (42)        110 = Yellow/Blue   (14)
339 *      011 = Magenta/Green (35)        111 = White/Black   (7)
340 *
341 *******************************************************************/
342
343/* Draw a scanline in TS2068/TC2048 hires mode (code modified from COUPE.C) */
344static void ts2068_hires_scanline(bitmap_t *bitmap, int y, int borderlines)
222/* Initialise the palette */
223PALETTE_INIT( spectrum )
345224{
346   int x,b,scrx,scry;
347   unsigned short ink,pap;
348        unsigned char *attr, *scr;
349
350        scrx=TS2068_LEFT_BORDER;
351   scry=((y&7) * 8) + ((y&0x38)>>3) + (y&0xC0);
352
353        scr=mess_ram + y*32;
354        attr=scr + 0x2000;
355
356        for (x=0;x<32;x++)
357   {
358                /* Get ink and paper colour with bright */
359                if (flash_invert && (*attr & 0x80))
360                {
361                        ink=((*attr)>>3) & 0x0f;
362                        pap=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
363                }
364                else
365                {
366                        ink=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
367                        pap=((*attr)>>3) & 0x0f;
368                }
369
370      for (b=0x80;b!=0;b>>=1)
371      {
372                        if (*scr&b)
373         {
374                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,ink);
375                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,ink);
376         }
377         else
378         {
379                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,pap);
380                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,pap);
381         }
382      }
383                scr++;
384                attr++;
385   }
225   palette_set_colors(machine, 0, spectrum_palette, ARRAY_LENGTH(spectrum_palette));
386226}
387
388/* Draw a scanline in TS2068/TC2048 64-column mode */
389static void ts2068_64col_scanline(bitmap_t *bitmap, int y, int borderlines, unsigned short inkcolor)
390{
391   int x,b,scrx,scry;
392        unsigned char *scr1, *scr2;
393
394        scrx=TS2068_LEFT_BORDER;
395   scry=((y&7) * 8) + ((y&0x38)>>3) + (y&0xC0);
396
397        scr1=mess_ram + y*32;
398        scr2=scr1 + 0x2000;
399
400        for (x=0;x<32;x++)
401   {
402      for (b=0x80;b!=0;b>>=1)
403      {
404                        if (*scr1&b)
405                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,inkcolor);
406         else
407                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,7-inkcolor);
408      }
409                scr1++;
410
411      for (b=0x80;b!=0;b>>=1)
412      {
413                        if (*scr2&b)
414                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,inkcolor);
415         else
416                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,7-inkcolor);
417      }
418                scr2++;
419   }
420}
421
422/* Draw a scanline in TS2068/TC2048 lores (normal Spectrum) mode */
423static void ts2068_lores_scanline(bitmap_t *bitmap, int y, int borderlines, int screen)
424{
425   int x,b,scrx,scry;
426   unsigned short ink,pap;
427   unsigned char *attr, *scr;
428
429   scrx=TS2068_LEFT_BORDER;
430   scry=((y&7) * 8) + ((y&0x38)>>3) + (y&0xC0);
431
432   scr = mess_ram + y*32 + screen*0x2000;
433   attr = mess_ram + ((scry>>3)*32) + screen*0x2000 + 0x1800;
434
435   for (x=0;x<32;x++)
436   {
437      /* Get ink and paper colour with bright */
438      if (flash_invert && (*attr & 0x80))
439      {
440         ink=((*attr)>>3) & 0x0f;
441         pap=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
442      }
443      else
444      {
445         ink=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
446         pap=((*attr)>>3) & 0x0f;
447      }
448
449      for (b=0x80;b!=0;b>>=1)
450      {
451         if (*scr&b)
452         {
453            spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,ink);
454            spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,ink);
455         }
456         else
457         {
458            spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,pap);
459            spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,pap);
460         }
461      }
462      scr++;
463      attr++;
464   }
465}
466
467VIDEO_UPDATE( ts2068 )
468{
469   /* for now TS2068 will do a full-refresh */
470   int count;
471   int full_refresh = 1;
472
473        if ((ts2068_port_ff_data & 7) == 6)
474        {
475                /* 64 Column mode */
476                unsigned short inkcolor = (ts2068_port_ff_data & 0x38) >> 3;
477                for (count = 0; count < 192; count++)
478                        ts2068_64col_scanline(bitmap, count, TS2068_TOP_BORDER, inkcolor);
479   }
480        else if ((ts2068_port_ff_data & 7) == 2)
481        {
482                /* Extended Color mode */
483                for (count = 0; count < 192; count++)
484                        ts2068_hires_scanline(bitmap, count, TS2068_TOP_BORDER);
485        }
486        else if ((ts2068_port_ff_data & 7) == 1)
487        {
488                /* Screen 6000-7aff */
489                for (count = 0; count < 192; count++)
490                        ts2068_lores_scanline(bitmap, count, TS2068_TOP_BORDER, 1);
491        }
492        else
493        {
494                /* Screen 4000-5aff */
495                for (count = 0; count < 192; count++)
496                        ts2068_lores_scanline(bitmap, count, TS2068_TOP_BORDER, 0);
497        }
498
499        draw_border(screen->machine, bitmap, full_refresh,
500                TS2068_TOP_BORDER, SPEC_DISPLAY_YSIZE, TS2068_BOTTOM_BORDER,
501                TS2068_LEFT_BORDER, TS2068_DISPLAY_XSIZE, TS2068_RIGHT_BORDER,
502                SPEC_LEFT_BORDER_CYCLES, SPEC_DISPLAY_XSIZE_CYCLES,
503                SPEC_RIGHT_BORDER_CYCLES, SPEC_RETRACE_CYCLES, 200, 0xfe);
504   return 0;
505}
506
507VIDEO_UPDATE( tc2048 )
508{
509   /* for now TS2068 will do a full-refresh */
510   int count;
511   int full_refresh = 1;
512
513   if ((ts2068_port_ff_data & 7) == 6)
514   {
515      /* 64 Column mode */
516      unsigned short inkcolor = (ts2068_port_ff_data & 0x38) >> 3;
517      for (count = 0; count < 192; count++)
518         ts2068_64col_scanline(bitmap, count, SPEC_TOP_BORDER, inkcolor);
519   }
520   else if ((ts2068_port_ff_data & 7) == 2)
521   {
522      /* Extended Color mode */
523      for (count = 0; count < 192; count++)
524         ts2068_hires_scanline(bitmap, count, SPEC_TOP_BORDER);
525   }
526   else if ((ts2068_port_ff_data & 7) == 1)
527   {
528      /* Screen 6000-7aff */
529      for (count = 0; count < 192; count++)
530         ts2068_lores_scanline(bitmap, count, SPEC_TOP_BORDER, 1);
531   }
532   else
533   {
534      /* Screen 4000-5aff */
535      for (count = 0; count < 192; count++)
536         ts2068_lores_scanline(bitmap, count, SPEC_TOP_BORDER, 0);
537   }
538
539   draw_border(screen->machine, bitmap, full_refresh,
540      SPEC_TOP_BORDER, SPEC_DISPLAY_YSIZE, SPEC_BOTTOM_BORDER,
541      TS2068_LEFT_BORDER, TS2068_DISPLAY_XSIZE, TS2068_RIGHT_BORDER,
542      SPEC_LEFT_BORDER_CYCLES, SPEC_DISPLAY_XSIZE_CYCLES,
543      SPEC_RIGHT_BORDER_CYCLES, SPEC_RETRACE_CYCLES, 200, 0xfe);
544   return 0;
545}
src/mess/video/border.c
r2516r2517
6464
6565   for (Count = 0; Count < NumItems; Count++)
6666   {
67      logerror ("Event no %05d, ID = %04x, data = %04x, time = %ld\n", Count, pItem[Count].Event_ID, pItem[Count].Event_Data, (long) pItem[Count].Event_Time);
67//      logerror ("Event no %05d, ID = %04x, data = %04x, time = %ld\n", Count, pItem[Count].Event_ID, pItem[Count].Event_Data, (long) pItem[Count].Event_Time);
6868   }
6969
7070   /* Find the first and second events with the correct ID */
r2516r2517
111111         r.max_y = TotalScreenHeight-1;
112112         fillbitmap(bitmap, machine->pens[CurrBorderColor], &r);
113113
114         logerror ("Setting border colour to %d (Last = %d, Full Refresh = %d)\n", CurrBorderColor, LastDisplayedBorderColor, full_refresh);
114//         logerror ("Setting border colour to %d (Last = %d, Full Refresh = %d)\n", CurrBorderColor, LastDisplayedBorderColor, full_refresh);
115115         LastDisplayedBorderColor = CurrBorderColor;
116116   }
117117   else
r2516r2517
336336         /* Set value to ensure redraw on next frame */
337337         LastDisplayedBorderColor = -1;
338338
339         logerror ("Multi coloured border drawn (last colour = %d)\n", CurrBorderColor);
339//         logerror ("Multi coloured border drawn (last colour = %d)\n", CurrBorderColor);
340340   }
341341
342342   /* Assume all other routines have processed their data from the list */
src/mess/video/spec128.c
r0r2517
1/***************************************************************************
2
3  spectrum.c
4
5  Functions to emulate the video hardware of the ZX Spectrum.
6
7  Changes:
8
9  DJR 08/02/00 - Added support for FLASH 1.
10  DJR 16/05/00 - Support for TS2068/TC2048 hires and 64 column modes.
11  DJR 19/05/00 - Speeded up Spectrum 128 screen refresh.
12  DJR 23/05/00 - Preliminary support for border colour emulation.
13
14***************************************************************************/
15
16#include "driver.h"
17#include "includes/spectrum.h"
18#include "eventlst.h"
19#include "video/border.h"
20
21INLINE void spectrum_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color)
22{
23   *BITMAP_ADDR16(bitmap, y, x) = (UINT16)color;
24}
25
26
27VIDEO_START( spectrum_128 )
28{
29   frame_number = 0;
30   flash_invert = 0;
31
32   EventList_Initialise(30000);
33}
34
35/* Refresh the spectrum 128 screen (code modified from COUPE.C) */
36VIDEO_UPDATE( spectrum_128 )
37{
38        /* for now do a full-refresh */
39        int x, y, b, scrx, scry;
40        unsigned short ink, pap;
41        unsigned char *attr, *scr;
42      int full_refresh = 1;
43
44        scr=spectrum_128_screen_location;
45
46        for (y=0; y<192; y++)
47        {
48                scrx=SPEC_LEFT_BORDER;
49                scry=((y&7) * 8) + ((y&0x38)>>3) + (y&0xC0);
50                attr=spectrum_128_screen_location + ((scry>>3)*32) + 0x1800;
51
52                for (x=0;x<32;x++)
53                {
54                        /* Get ink and paper colour with bright */
55                        if (flash_invert && (*attr & 0x80))
56                        {
57                                ink=((*attr)>>3) & 0x0f;
58                                pap=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
59                        }
60                        else
61                        {
62                                ink=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
63                                pap=((*attr)>>3) & 0x0f;
64                        }
65
66                        for (b=0x80;b!=0;b>>=1)
67                        {
68                                if (*scr&b)
69                                        spectrum_plot_pixel(bitmap,scrx++,SPEC_TOP_BORDER+scry,ink);
70                                else
71                                        spectrum_plot_pixel(bitmap,scrx++,SPEC_TOP_BORDER+scry,pap);
72         }
73                scr++;
74                attr++;
75                }
76   }
77
78   draw_border(screen->machine, bitmap, full_refresh,
79      SPEC_TOP_BORDER, SPEC_DISPLAY_YSIZE, SPEC_BOTTOM_BORDER,
80      SPEC_LEFT_BORDER, SPEC_DISPLAY_XSIZE, SPEC_RIGHT_BORDER,
81      SPEC_LEFT_BORDER_CYCLES, SPEC_DISPLAY_XSIZE_CYCLES,
82      SPEC_RIGHT_BORDER_CYCLES, SPEC128_RETRACE_CYCLES, 200, 0xfe);
83   return 0;
84}
85
86
87
88const rgb_t spectrum_128_palette[16] = {
89   MAKE_RGB(0x00, 0x00, 0x00),
90   MAKE_RGB(0x00, 0x00, 0xbf),
91   MAKE_RGB(0xbf, 0x00, 0x00),
92   MAKE_RGB(0xbf, 0x00, 0xbf),
93   MAKE_RGB(0x00, 0xbf, 0x00),
94   MAKE_RGB(0x00, 0xbf, 0xbf),
95   MAKE_RGB(0xbf, 0xbf, 0x00),
96   MAKE_RGB(0xbf, 0xbf, 0xbf),
97   MAKE_RGB(0x00, 0x00, 0x00),
98   MAKE_RGB(0x00, 0x00, 0xff),
99   MAKE_RGB(0xff, 0x00, 0x00),
100   MAKE_RGB(0xff, 0x00, 0xff),
101   MAKE_RGB(0x00, 0xff, 0x00),
102   MAKE_RGB(0x00, 0xff, 0xff),
103   MAKE_RGB(0xff, 0xff, 0x00),
104   MAKE_RGB(0xff, 0xff, 0xff)
105};
106
107PALETTE_INIT( spectrum_128 )
108{   
109   palette_set_colors(machine, 0, spectrum_128_palette, ARRAY_LENGTH(spectrum_128_palette));
110}
111
src/mess/video/timex.c
r0r2517
1/***************************************************************************
2
3  timex.c
4
5  Functions to emulate the video hardware of the Timex ZX Spectrum clones.
6
7  Changes:
8
9  DJR 08/02/00 - Added support for FLASH 1.
10  DJR 16/05/00 - Support for TS2068/TC2048 hires and 64 column modes.
11  DJR 19/05/00 - Speeded up Spectrum 128 screen refresh.
12  DJR 23/05/00 - Preliminary support for border colour emulation.
13
14***************************************************************************/
15
16#include "driver.h"
17#include "includes/spectrum.h"
18#include "eventlst.h"
19#include "video/border.h"
20
21inline void spectrum_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color)
22{
23   *BITMAP_ADDR16(bitmap, y, x) = (UINT16)color;
24}
25
26/* Update FLASH status for ts2068. Assumes flash update every 1/2s. */
27VIDEO_EOF( ts2068 )
28{
29        EVENT_LIST_ITEM *pItem;
30        int NumItems;
31
32        frame_number++;
33        if (frame_number >= 30)
34        {
35                frame_number = 0;
36                flash_invert = !flash_invert;
37        }
38
39        /* Empty event buffer for undisplayed frames noting the last border
40           colour (in case colours are not changed in the next frame). */
41        NumItems = EventList_NumEvents();
42        if (NumItems)
43        {
44                pItem = EventList_GetFirstItem();
45                set_last_border_color ( pItem[NumItems-1].Event_Data );
46                EventList_Reset();
47            EventList_SetOffsetStartTime ( ATTOTIME_TO_CYCLES(0, attotime_mul(video_screen_get_scan_period(machine->primary_screen), video_screen_get_vpos(machine->primary_screen))) );
48                logerror ("Event log reset in callback fn.\n");
49        }
50}
51
52
53/*******************************************************************
54 *
55 *      Update the TS2068 display.
56 *
57 *      Port ff is used to set the display mode.
58 *
59 *      bits 2..0  Video Mode Select
60 *      000 = Primary DFILE active   (at 0x4000-0x5aff)
61 *      001 = Secondary DFILE active (at 0x6000-0x7aff)
62 *      010 = Extended Colour Mode   (chars at 0x4000-0x57ff, colors 0x6000-0x7aff)
63 *      110 = 64 column mode         (columns 0,2,4,...62 from DFILE 1
64 *                                    columns 1,3,5,...63 from DFILE 2)
65 *      other = unpredictable results
66 *
67 *      bits 5..3  64 column mode ink/paper selection (attribute value in brackets)
68 *      000 = Black/White   (56)        100 = Green/Magenta (28)
69 *      001 = Blue/Yellow   (49)        101 = Cyan/Red      (21)
70 *      010 = Red/Cyan      (42)        110 = Yellow/Blue   (14)
71 *      011 = Magenta/Green (35)        111 = White/Black   (7)
72 *
73 *******************************************************************/
74
75/* Draw a scanline in TS2068/TC2048 hires mode (code modified from COUPE.C) */
76static void ts2068_hires_scanline(bitmap_t *bitmap, int y, int borderlines)
77{
78   int x,b,scrx,scry;
79   unsigned short ink,pap;
80        unsigned char *attr, *scr;
81
82        scrx=TS2068_LEFT_BORDER;
83   scry=((y&7) * 8) + ((y&0x38)>>3) + (y&0xC0);
84
85        scr=mess_ram + y*32;
86        attr=scr + 0x2000;
87
88        for (x=0;x<32;x++)
89   {
90                /* Get ink and paper colour with bright */
91                if (flash_invert && (*attr & 0x80))
92                {
93                        ink=((*attr)>>3) & 0x0f;
94                        pap=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
95                }
96                else
97                {
98                        ink=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
99                        pap=((*attr)>>3) & 0x0f;
100                }
101
102      for (b=0x80;b!=0;b>>=1)
103      {
104                        if (*scr&b)
105         {
106                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,ink);
107                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,ink);
108         }
109         else
110         {
111                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,pap);
112                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,pap);
113         }
114      }
115                scr++;
116                attr++;
117   }
118}
119
120/* Draw a scanline in TS2068/TC2048 64-column mode */
121static void ts2068_64col_scanline(bitmap_t *bitmap, int y, int borderlines, unsigned short inkcolor)
122{
123   int x,b,scrx,scry;
124        unsigned char *scr1, *scr2;
125
126        scrx=TS2068_LEFT_BORDER;
127   scry=((y&7) * 8) + ((y&0x38)>>3) + (y&0xC0);
128
129        scr1=mess_ram + y*32;
130        scr2=scr1 + 0x2000;
131
132        for (x=0;x<32;x++)
133   {
134      for (b=0x80;b!=0;b>>=1)
135      {
136                        if (*scr1&b)
137                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,inkcolor);
138         else
139                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,7-inkcolor);
140      }
141                scr1++;
142
143      for (b=0x80;b!=0;b>>=1)
144      {
145                        if (*scr2&b)
146                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,inkcolor);
147         else
148                                spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,7-inkcolor);
149      }
150                scr2++;
151   }
152}
153
154/* Draw a scanline in TS2068/TC2048 lores (normal Spectrum) mode */
155static void ts2068_lores_scanline(bitmap_t *bitmap, int y, int borderlines, int screen)
156{
157   int x,b,scrx,scry;
158   unsigned short ink,pap;
159   unsigned char *attr, *scr;
160
161   scrx=TS2068_LEFT_BORDER;
162   scry=((y&7) * 8) + ((y&0x38)>>3) + (y&0xC0);
163
164   scr = mess_ram + y*32 + screen*0x2000;
165   attr = mess_ram + ((scry>>3)*32) + screen*0x2000 + 0x1800;
166
167   for (x=0;x<32;x++)
168   {
169      /* Get ink and paper colour with bright */
170      if (flash_invert && (*attr & 0x80))
171      {
172         ink=((*attr)>>3) & 0x0f;
173         pap=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
174      }
175      else
176      {
177         ink=((*attr) & 0x07) + (((*attr)>>3) & 0x08);
178         pap=((*attr)>>3) & 0x0f;
179      }
180
181      for (b=0x80;b!=0;b>>=1)
182      {
183         if (*scr&b)
184         {
185            spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,ink);
186            spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,ink);
187         }
188         else
189         {
190            spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,pap);
191            spectrum_plot_pixel(bitmap,scrx++,scry+borderlines,pap);
192         }
193      }
194      scr++;
195      attr++;
196   }
197}
198
199VIDEO_UPDATE( ts2068 )
200{
201   /* for now TS2068 will do a full-refresh */
202   int count;
203   int full_refresh = 1;
204
205        if ((ts2068_port_ff_data & 7) == 6)
206        {
207                /* 64 Column mode */
208                unsigned short inkcolor = (ts2068_port_ff_data & 0x38) >> 3;
209                for (count = 0; count < 192; count++)
210                        ts2068_64col_scanline(bitmap, count, TS2068_TOP_BORDER, inkcolor);
211   }
212        else if ((ts2068_port_ff_data & 7) == 2)
213        {
214                /* Extended Color mode */
215                for (count = 0; count < 192; count++)
216                        ts2068_hires_scanline(bitmap, count, TS2068_TOP_BORDER);
217        }
218        else if ((ts2068_port_ff_data & 7) == 1)
219        {
220                /* Screen 6000-7aff */
221                for (count = 0; count < 192; count++)
222                        ts2068_lores_scanline(bitmap, count, TS2068_TOP_BORDER, 1);
223        }
224        else
225        {
226                /* Screen 4000-5aff */
227                for (count = 0; count < 192; count++)
228                        ts2068_lores_scanline(bitmap, count, TS2068_TOP_BORDER, 0);
229        }
230
231        draw_border(screen->machine, bitmap, full_refresh,
232                TS2068_TOP_BORDER, SPEC_DISPLAY_YSIZE, TS2068_BOTTOM_BORDER,
233                TS2068_LEFT_BORDER, TS2068_DISPLAY_XSIZE, TS2068_RIGHT_BORDER,
234                SPEC_LEFT_BORDER_CYCLES, SPEC_DISPLAY_XSIZE_CYCLES,
235                SPEC_RIGHT_BORDER_CYCLES, SPEC_RETRACE_CYCLES, 200, 0xfe);
236   return 0;
237}
238
239VIDEO_UPDATE( tc2048 )
240{
241   /* for now TS2068 will do a full-refresh */
242   int count;
243   int full_refresh = 1;
244
245   if ((ts2068_port_ff_data & 7) == 6)
246   {
247      /* 64 Column mode */
248      unsigned short inkcolor = (ts2068_port_ff_data & 0x38) >> 3;
249      for (count = 0; count < 192; count++)
250         ts2068_64col_scanline(bitmap, count, SPEC_TOP_BORDER, inkcolor);
251   }
252   else if ((ts2068_port_ff_data & 7) == 2)
253   {
254      /* Extended Color mode */
255      for (count = 0; count < 192; count++)
256         ts2068_hires_scanline(bitmap, count, SPEC_TOP_BORDER);
257   }
258   else if ((ts2068_port_ff_data & 7) == 1)
259   {
260      /* Screen 6000-7aff */
261      for (count = 0; count < 192; count++)
262         ts2068_lores_scanline(bitmap, count, SPEC_TOP_BORDER, 1);
263   }
264   else
265   {
266      /* Screen 4000-5aff */
267      for (count = 0; count < 192; count++)
268         ts2068_lores_scanline(bitmap, count, SPEC_TOP_BORDER, 0);
269   }
270
271   draw_border(screen->machine, bitmap, full_refresh,
272      SPEC_TOP_BORDER, SPEC_DISPLAY_YSIZE, SPEC_BOTTOM_BORDER,
273      TS2068_LEFT_BORDER, TS2068_DISPLAY_XSIZE, TS2068_RIGHT_BORDER,
274      SPEC_LEFT_BORDER_CYCLES, SPEC_DISPLAY_XSIZE_CYCLES,
275      SPEC_RIGHT_BORDER_CYCLES, SPEC_RETRACE_CYCLES, 200, 0xfe);
276   return 0;
277}
src/mess/machine/spectrum.c
r2516r2517
3535#include "utils.h"
3636
3737
38static unsigned long TapePosition = 0;
3938static void spectrum_setup_sna(running_machine *machine, unsigned char *pSnapshot, unsigned long SnapshotSize);
4039static void spectrum_setup_z80(running_machine *machine, unsigned char *pSnapshot, unsigned long SnapshotSize);
4140static void spectrum_setup_sp(running_machine *machine, unsigned char *pSnapshot, unsigned long SnapshotSize);
42static int spectrum_setup_tap(offs_t address, UINT8 *snapshot_data, int snapshot_length);
41//static int spectrum_setup_tap(offs_t address, UINT8 *snapshot_data, int snapshot_length);
4342
4443TIMEX_CART_TYPE timex_cart_type = TIMEX_CART_NONE;
4544UINT8 timex_cart_chunks = 0x00;
4645UINT8 * timex_cart_data;
47static UINT8 *cassette_snapshot;
48static int cassette_snapshot_size;
4946
5047typedef enum
5148{
r2516r2517
5754}
5855SPECTRUM_SNAPSHOT_TYPE;
5956
60static OPBASE_HANDLER(spectrum_opbaseoverride)
61{
62   if (cassette_snapshot_size > 0)
63      return spectrum_setup_tap(address, cassette_snapshot, cassette_snapshot_size);
64
65   /* Execute code in spectrum 48k screen memory */
66   if ((spectrum_128_port_7ffd_data == -1) && (spectrum_plus3_port_1ffd_data == -1))
67   {
68      if (address>=0x4000 && address<=0x57ff)
69      {
70         opcode_base = opcode_arg_base = spectrum_characterram-0x4000;
71         return -1;
72      }
73      if (address>=0x5800 && address<=0x5aff)
74      {
75         opcode_base = opcode_arg_base = spectrum_colorram-0x5800;
76         return -1;
77      }
78   }
79
80   /* Hack for correct handling 0xffff interrupt vector */
81   if (address == 0x0001)
82      if (cpunum_get_reg(0, REG_PREVIOUSPC)==0xffff)
83      {
84         cpunum_set_reg(0, Z80_PC, 0xfff4);
85         return 0xfff4;
86      }
87   return address;
88}
89
9057MACHINE_RESET( spectrum )
9158{
92   memory_set_opbase_handler(0, spectrum_opbaseoverride);
59   //memory_set_opbase_handler(0, spectrum_opbaseoverride);
9360}
9461
9562SNAPSHOT_LOAD(spectrum)
r2516r2517
136103
137104/*******************************************************************
138105 *
139 *      Override load routine (0x0556 in 48K ROM) if loading .TAP files
140 *      Tape blocks are as follows.
141 *      2 bytes length of block excluding these 2 bytes (LSB first)
142 *      1 byte  flag byte (0x00 for headers, 0xff for data)
143 *      n bytes data
144 *      1 byte  checksum
145 *
146 *      The load routine uses the following registers:
147 *      IX              Start address for block
148 *      DE              Length of block
149 *      A               Flag byte (as above)
150 *      Carry Flag      Set for Load, reset for verify
151 *
152 *      On exit the carry flag is set if loading/verifying was successful.
153 *
154 *      Note: it is not always possible to trap the exact entry to the
155 *      load routine so things get rather messy!
156 *
157 *******************************************************************/
158static int spectrum_setup_tap(offs_t address, UINT8 *snapshot_data, int snapshot_length)
159{
160   running_machine *machine = Machine;
161   int i, tap_block_length, load_length;
162   unsigned char lo, hi, a_reg;
163   unsigned short load_addr, return_addr, af_reg, de_reg, sp_reg;
164   static int data_loaded = 0;         /* Whether any data files (not headers) were loaded */
165
166/*        logerror("PC=%02x\n", address); */
167   /* It is not always possible to trap the call to the actual load
168    * routine so trap the LD-EDGE-1 and LD-EDGE-2 routines which
169    * check the earphone socket.
170    */
171
172   if ((spectrum_128_port_7ffd_data == -1) && (spectrum_plus3_port_1ffd_data == -1))
173   {
174      if (address>=0x4000 && address<=0x57ff)
175      {
176         opcode_base = opcode_arg_base = spectrum_characterram-0x4000;
177         return -1;
178      }
179      if (address>=0x5800 && address<=0x5aff)
180      {
181         opcode_base = opcode_arg_base = spectrum_colorram-0x5800;
182         return -1;
183      }
184   }
185   if (address == 0x0001)
186      if (cpunum_get_reg(0, REG_PREVIOUSPC)==0xffff)
187      {
188         cpunum_set_reg(0, Z80_PC, 0xfff4);
189         return 0xfff4;
190      }
191
192   if (ts2068_port_f4_data == -1)
193   {
194      if ((address < 0x05e3) || (address > 0x0604))
195         return address;
196
197      /* For Spectrum 128/+2/+3 check which rom is paged */
198      if ((spectrum_128_port_7ffd_data != -1) || (spectrum_plus3_port_1ffd_data != -1))
199      {
200         if (spectrum_plus3_port_1ffd_data != -1)
201         {
202            if (!spectrum_plus3_port_1ffd_data & 0x04)
203               return address;
204         }
205         if (!spectrum_128_port_7ffd_data & 0x10)
206            return address;
207      }
208   }
209   else
210   {
211      /* For TS2068 also check that EXROM is paged into bottom 8K.
212       * Code is not relocatable so don't need to check EXROM in other pages.
213       */
214      if ((!ts2068_port_f4_data & 0x01) || (!ts2068_port_ff_data & 0x80))
215         return address;
216      if ((address < 0x018d) || (address > 0x01aa))
217         return address;
218   }
219   lo = snapshot_data[TapePosition] & 0x0ff;
220   hi = snapshot_data[TapePosition + 1] & 0x0ff;
221   tap_block_length = (hi << 8) | lo;
222
223   /* By the time that load has been trapped the block type and carry
224    * flags are in the AF' register. */
225   af_reg = cpunum_get_reg(0, Z80_AF2);
226   a_reg = (af_reg & 0xff00) >> 8;
227
228   if ((a_reg == snapshot_data[TapePosition + 2]) && (af_reg & 0x0001))
229   {
230      /* Correct flag byte and carry flag set so try loading */
231      load_addr = cpunum_get_reg(0, Z80_IX);
232      de_reg = cpunum_get_reg(0, Z80_DE);
233
234      load_length = MIN(de_reg, tap_block_length - 2);
235      load_length = MIN(load_length, 65536 - load_addr);
236      /* Actual number of bytes of block that can be loaded -
237       * Don't try to load past the end of memory */
238
239      for (i = 0; i < load_length; i++)
240         program_write_byte(load_addr + i, snapshot_data[TapePosition + i + 3]);
241      cpunum_set_reg(0, Z80_IX, load_addr + load_length);
242      cpunum_set_reg(0, Z80_DE, de_reg - load_length);
243      if (de_reg == (tap_block_length - 2))
244      {
245         /* Successful load - Set carry flag and A to 0 */
246         if ((de_reg != 17) || (a_reg))
247            data_loaded = 1;      /* Non-header file loaded */
248         cpunum_set_reg(0, Z80_AF, (af_reg & 0x00ff) | 0x0001);
249         logerror("Loaded %04x bytes from address %04x onwards (type=%02x) using tape block at offset %ld\n", load_length,
250                load_addr, a_reg, TapePosition);
251      }
252      else
253      {
254         /* Wrong tape block size - reset carry flag */
255         cpunum_set_reg(0, Z80_AF, af_reg & 0xfffe);
256         logerror("Bad block length %04x bytes wanted starting at address %04x (type=%02x) , Data length of tape block at offset %ld is %04x bytes\n",
257                de_reg, load_addr, a_reg, TapePosition, tap_block_length - 2);
258      }
259   }
260   else
261   {
262      /* Wrong flag byte or verify selected so reset carry flag to indicate failure */
263      cpunum_set_reg(0, Z80_AF, af_reg & 0xfffe);
264      if (af_reg & 0x0001)
265         logerror("Failed to load tape block at offset %ld - type wanted %02x, got type %02x\n", TapePosition, a_reg,
266                snapshot_data[TapePosition + 2]);
267      else
268         logerror("Failed to load tape block at offset %ld - verify selected\n", TapePosition);
269   }
270
271   TapePosition += (tap_block_length + 2);
272   if (TapePosition >= snapshot_length)
273   {
274      /* End of tape - either rewind or disable op base override */
275      if (input_port_read(machine, "CONFIG") & 0x40)
276      {
277         if (data_loaded)
278         {
279            TapePosition = 0;
280            data_loaded = 0;
281            logerror("All tape blocks used! - rewinding tape to start\n");
282         }
283         else
284         {
285            /* Disable .TAP support if no files were loaded to avoid getting caught in infinite loop */
286            logerror("No valid data loaded! - disabling .TAP support\n");
287            cassette_snapshot = NULL;
288            cassette_snapshot_size = 0;
289
290         }
291      }
292      else
293      {
294         logerror("All tape blocks used! - disabling .TAP support\n");
295         cassette_snapshot = NULL;
296         cassette_snapshot_size = 0;
297      }
298   }
299
300   /* Leave the load routine by removing addresses from the stack
301    * until one outside the load routine is found.
302    * eg. SA/LD-RET at address 053f (00e5 on TS2068)
303    */
304   do
305   {
306      sp_reg = cpunum_get_reg(0, Z80_SP);
307      return_addr =
308         ((UINT16) program_read_byte(sp_reg + 0) ) >> 8 |
309         ((UINT16) program_read_byte(sp_reg + 1) ) >> 0;
310
311      sp_reg += 2;
312      cpunum_set_reg(0, Z80_SP, (sp_reg & 0x0ffff));
313      cpunum_set_reg(0, Z80_PC, (return_addr & 0x0ffff));
314   }
315   while (((return_addr != 0x053f) && (return_addr < 0x0605) && (ts2068_port_f4_data == -1)) ||
316         ((return_addr != 0x00e5) && (return_addr < 0x01aa) && (ts2068_port_f4_data != -1)));
317
318          logerror("Load return address=%04x, SP=%04x\n", return_addr, sp_reg);
319
320   return return_addr;
321}
322
323/*******************************************************************
324 *
325106 *      Update the memory and paging of the spectrum being emulated
326107 *
327108 *      if port_7ffd_data is -1 then machine is 48K - no paging
src/mess/mess.mak
r2516r2517
673673$(MESSOBJ)/sinclair.a: \
674674   $(MESS_VIDEO)/border.o      \
675675   $(MESS_VIDEO)/spectrum.o      \
676   $(MESS_VIDEO)/spec128.o      \
677   $(MESS_VIDEO)/timex.o      \
676678   $(MESS_VIDEO)/zx.o      \
677679   $(MESS_DRIVERS)/zx.o      \
678680   $(MESS_MACHINE)/zx.o      \
679681   $(MESS_DRIVERS)/spectrum.o      \
682   $(MESS_DRIVERS)/spec128.o      \
683   $(MESS_DRIVERS)/timex.o      \
684   $(MESS_DRIVERS)/specpls3.o      \
685   $(MESS_DRIVERS)/scorpion.o      \
686   $(MESS_DRIVERS)/pentagon.o      \
680687   $(MESS_MACHINE)/spectrum.o      \
681688   $(MESS_FORMATS)/zx81_p.o      \
682689   $(MESS_DRIVERS)/ql.o      \
src/mess/drivers/pentagon.c
r0r2517
1#include "driver.h"
2#include "includes/spectrum.h"
3#include "devices/snapquik.h"
4#include "devices/cartslot.h"
5#include "devices/cassette.h"
6#include "formats/tzx_cas.h"
7
8extern MACHINE_START( scorpion );
9
10/****************************************************************************************************/
11/* pentagon */
12
13static  READ8_HANDLER(pentagon_port_r)
14{
15   return 0x0ff;
16}
17
18
19static WRITE8_HANDLER(pentagon_port_w)
20{
21}
22
23
24
25/* ports are not decoded full.
26The function decodes the ports appropriately */
27static ADDRESS_MAP_START (pentagon_io, ADDRESS_SPACE_IO, 8)
28   AM_RANGE(0x0000, 0xffff) AM_READWRITE( pentagon_port_r, pentagon_port_w )
29ADDRESS_MAP_END
30
31static MACHINE_RESET( pentagon )
32{
33   /* Bank 5 is always in 0x4000 - 0x7fff */
34   memory_set_bankptr(2, mess_ram + (5<<14));
35
36   /* Bank 2 is always in 0x8000 - 0xbfff */
37   memory_set_bankptr(3, mess_ram + (2<<14));
38}
39
40static MACHINE_DRIVER_START( pentagon )
41   MDRV_IMPORT_FROM( spectrum_128 )
42   MDRV_CPU_MODIFY("main")
43   MDRV_CPU_IO_MAP(pentagon_io, 0)
44   MDRV_MACHINE_START( scorpion )
45   MDRV_MACHINE_RESET( pentagon )
46MACHINE_DRIVER_END
47
48
49/***************************************************************************
50
51  Game driver(s)
52
53***************************************************************************/
54
55
56ROM_START(pentagon)
57   ROM_REGION(0x020000, REGION_CPU1, 0)
58   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
59ROM_END
60
61SYSTEM_CONFIG_EXTERN(specpls3)
62
63/*    YEAR  NAME      PARENT    COMPAT  MACHINE     INPUT       INIT    CONFIG      COMPANY     FULLNAME */
64COMP( ????, pentagon, spectrum, 0,      pentagon,      spectrum,   0,      specpls3,   "???",      "Pentagon", GAME_NOT_WORKING)
src/mess/drivers/specpls3.c
r0r2517
1/***************************************************************************
2
3   NOTE: ****** Specbusy: press N, R, or E to boot *************
4
5
6        Spectrum/Inves/TK90X etc. memory map:
7
8    CPU:
9        0000-3fff ROM
10        4000-ffff RAM
11
12        Spectrum 128/+2/+2a/+3 memory map:
13
14        CPU:
15                0000-3fff Banked ROM/RAM (banked rom only on 128/+2)
16                4000-7fff Banked RAM
17                8000-bfff Banked RAM
18                c000-ffff Banked RAM
19
20        TS2068 memory map: (Can't have both EXROM and DOCK active)
21        The 8K EXROM can be loaded into multiple pages.
22
23    CPU:
24                0000-1fff     ROM / EXROM / DOCK (Cartridge)
25                2000-3fff     ROM / EXROM / DOCK
26                4000-5fff \
27                6000-7fff  \
28                8000-9fff  |- RAM / EXROM / DOCK
29                a000-bfff  |
30                c000-dfff  /
31                e000-ffff /
32
33
34Interrupts:
35
36Changes:
37
3829/1/2000   KT -    Implemented initial +3 emulation.
3930/1/2000   KT -    Improved input port decoding for reading and therefore
40            correct keyboard handling for Spectrum and +3.
4131/1/2000   KT -    Implemented buzzer sound for Spectrum and +3.
42            Implementation copied from Paul Daniel's Jupiter driver.
43            Fixed screen display problems with dirty chars.
44            Added support to load .Z80 snapshots. 48k support so far.
4513/2/2000   KT -    Added Interface II, Kempston, Fuller and Mikrogen
46            joystick support.
4717/2/2000   DJR -   Added full key descriptions and Spectrum+ keys.
48            Fixed Spectrum +3 keyboard problems.
4917/2/2000   KT -    Added tape loading from WAV/Changed from DAC to generic
50            speaker code.
5118/2/2000   KT -    Added tape saving to WAV.
5227/2/2000   KT -    Took DJR's changes and added my changes.
5327/2/2000   KT -    Added disk image support to Spectrum +3 driver.
5427/2/2000   KT -    Added joystick I/O code to the Spectrum +3 I/O handler.
5514/3/2000   DJR -   Tape handling dipswitch.
5626/3/2000   DJR -   Snapshot files are now classifed as snapshots not
57            cartridges.
5804/4/2000   DJR -   Spectrum 128 / +2 Support.
5913/4/2000   DJR -   +4 Support (unofficial 48K hack).
6013/4/2000   DJR -   +2a Support (rom also used in +3 models).
6113/4/2000   DJR -   TK90X, TK95 and Inves support (48K clones).
6221/4/2000   DJR -   TS2068 and TC2048 support (TC2048 Supports extra video
63            modes but doesn't have bank switching or sound chip).
6409/5/2000   DJR -   Spectrum +2 (France, Spain), +3 (Spain).
6517/5/2000   DJR -   Dipswitch to enable/disable disk drives on +3 and clones.
6627/6/2000   DJR -   Changed 128K/+3 port decoding (sound now works in Zub 128K).
6706/8/2000   DJR -   Fixed +3 Floppy support
6810/2/2001   KT  -   Re-arranged code and split into each model emulated.
69            Code is split into 48k, 128k, +3, tc2048 and ts2048
70            segments. 128k uses some of the functions in 48k, +3
71            uses some functions in 128, and tc2048/ts2048 use some
72            of the functions in 48k. The code has been arranged so
73            these functions come in some kind of "override" order,
74            read functions changed to use  READ8_HANDLER and write
75            functions changed to use WRITE8_HANDLER.
76            Added Scorpion256 preliminary.
7718/6/2001   DJR -   Added support for Interface 2 cartridges.
78xx/xx/2001  KS -    TS-2068 sound fixed.
79            Added support for DOCK cartridges for TS-2068.
80            Added Spectrum 48k Psycho modified rom driver.
81            Added UK-2086 driver.
8223/12/2001  KS -    48k machines are now able to run code in screen memory.
83                Programs which keep their code in screen memory
84                like monitors, tape copiers, decrunchers, etc.
85                works now.
86                Fixed problem with interrupt vector set to 0xffff (much
87            more 128k games works now).
88                A useful used trick on the Spectrum is to set
89                interrupt vector to 0xffff (using the table
90                which contain 0xff's) and put a byte 0x18 hex,
91                the opcode for JR, at this address. The first
92                byte of the ROM is a 0xf3 (DI), so the JR will
93                jump to 0xfff4, where a long JP to the actual
94                interrupt routine is put. Due to unideal
95                bankswitching in MAME this JP were to 0001 what
96                causes Spectrum to reset. Fixing this problem
97                made much more software runing (i.e. Paperboy).
98            Corrected frames per second value for 48k and 128k
99            Sincalir machines.
100                There are 50.08 frames per second for Spectrum
101                48k what gives 69888 cycles for each frame and
102                50.021 for Spectrum 128/+2/+2A/+3 what gives
103                70908 cycles for each frame.
104            Remaped some Spectrum+ keys.
105                Presing F3 to reset was seting 0xf7 on keyboard
106                input port. Problem occured for snapshots of
107                some programms where it was readed as pressing
108                key 4 (which is exit in Tapecopy by R. Dannhoefer
109                for example).
110            Added support to load .SP snapshots.
111            Added .BLK tape images support.
112                .BLK files are identical to .TAP ones, extension
113                is an only difference.
11408/03/2002  KS -    #FF port emulation added.
115                Arkanoid works now, but is not playable due to
116                completly messed timings.
117
118Initialisation values used when determining which model is being emulated:
119 48K        Spectrum doesn't use either port.
120 128K/+2    Bank switches with port 7ffd only.
121 +3/+2a     Bank switches with both ports.
122
123Notes:
124 1. No contented memory.
125 2. No hi-res colour effects (need contended memory first for accurate timing).
126 3. Multiface 1 and Interface 1 not supported.
127 4. Horace and the Spiders cartridge doesn't run properly.
128 5. Tape images not supported:
129    .TZX, .SPC, .ITM, .PAN, .TAP(Warajevo), .VOC, .ZXS.
130 6. Snapshot images not supported:
131    .ACH, .PRG, .RAW, .SEM, .SIT, .SNX, .ZX, .ZXS, .ZX82.
132 7. 128K emulation is not perfect - the 128K machines crash and hang while
133    running quite a lot of games.
134 8. Disk errors occur on some +3 games.
135 9. Video hardware of all machines is timed incorrectly.
13610. EXROM and HOME cartridges are not emulated.
13711. The TK90X and TK95 roms output 0 to port #df on start up.
13812. The purpose of this port is unknown (probably display mode as TS2068) and
139    thus is not emulated.
140
141Very detailed infos about the ZX Spectrum +3e can be found at
142
143http://www.z88forever.org.uk/zxplus3e/
144
145*******************************************************************************/
146
147#include "driver.h"
148#include "includes/spectrum.h"
149#include "eventlst.h"
150#include "devices/snapquik.h"
151#include "devices/cartslot.h"
152#include "devices/cassette.h"
153#include "sound/ay8910.h"
154#include "sound/speaker.h"
155#include "formats/tzx_cas.h"
156
157/* +3 hardware */
158#include "machine/nec765.h"
159#include "devices/dsk.h"
160
161
162/****************************************************************************************************/
163/* Spectrum + 3 specific functions */
164/* This driver uses some of the spectrum_128 functions. The +3 is similar to a spectrum 128
165but with a disc drive */
166
167int spectrum_plus3_port_1ffd_data = -1;
168
169
170static const nec765_interface spectrum_plus3_nec765_interface =
171{
172      NULL,
173      NULL
174};
175
176
177static const int spectrum_plus3_memory_selections[]=
178{
179      0,1,2,3,
180      4,5,6,7,
181      4,5,6,3,
182      4,7,6,3
183};
184
185static WRITE8_HANDLER(spectrum_plus3_port_3ffd_w)
186{
187      if (~input_port_read(machine, "CONFIG") & 0x20)
188            nec765_data_w(machine, 0,data);
189}
190
191static  READ8_HANDLER(spectrum_plus3_port_3ffd_r)
192{
193      if (input_port_read(machine, "CONFIG") & 0x20)
194            return 0xff;
195      else
196            return nec765_data_r(machine, 0);
197}
198
199
200static  READ8_HANDLER(spectrum_plus3_port_2ffd_r)
201{
202      if (input_port_read(machine, "CONFIG") & 0x20)
203            return 0xff;
204      else
205            return nec765_status_r(machine, 0);
206}
207
208
209void spectrum_plus3_update_memory(running_machine *machine)
210{
211   if (spectrum_128_port_7ffd_data & 8)
212   {
213         logerror("+3 SCREEN 1: BLOCK 7\n");
214         spectrum_128_screen_location = mess_ram + (7<<14);
215   }
216   else
217   {
218         logerror("+3 SCREEN 0: BLOCK 5\n");
219         spectrum_128_screen_location = mess_ram + (5<<14);
220   }
221
222   if ((spectrum_plus3_port_1ffd_data & 0x01)==0)
223   {
224         int ram_page;
225         unsigned char *ram_data;
226
227         /* ROM switching */
228         unsigned char *ChosenROM;
229         int ROMSelection;
230
231         /* select ram at 0x0c000-0x0ffff */
232         ram_page = spectrum_128_port_7ffd_data & 0x07;
233         ram_data = mess_ram + (ram_page<<14);
234
235         memory_set_bankptr(4, ram_data);
236
237         logerror("RAM at 0xc000: %02x\n",ram_page);
238
239         /* Reset memory between 0x4000 - 0xbfff in case extended paging was being used */
240         /* Bank 5 in 0x4000 - 0x7fff */
241         memory_set_bankptr(2, mess_ram + (5<<14));
242
243         /* Bank 2 in 0x8000 - 0xbfff */
244         memory_set_bankptr(3, mess_ram + (2<<14));
245
246
247         ROMSelection = ((spectrum_128_port_7ffd_data>>4) & 0x01) |
248            ((spectrum_plus3_port_1ffd_data>>1) & 0x02);
249
250         /* rom 0 is editor, rom 1 is syntax, rom 2 is DOS, rom 3 is 48 BASIC */
251
252         ChosenROM = memory_region(REGION_CPU1) + 0x010000 + (ROMSelection<<14);
253
254         memory_set_bankptr(1, ChosenROM);
255         memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x3fff, 0, 0, SMH_UNMAP);
256
257         logerror("rom switch: %02x\n", ROMSelection);
258   }
259   else
260   {
261         /* Extended memory paging */
262
263         const int *memory_selection;
264         int MemorySelection;
265         unsigned char *ram_data;
266
267         MemorySelection = (spectrum_plus3_port_1ffd_data>>1) & 0x03;
268
269         memory_selection = &spectrum_plus3_memory_selections[(MemorySelection<<2)];
270
271         ram_data = mess_ram + (memory_selection[0]<<14);
272         memory_set_bankptr(1, ram_data);
273         /* allow writes to 0x0000-0x03fff */
274         memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x3fff, 0, 0, SMH_BANK1);
275
276         ram_data = mess_ram + (memory_selection[1]<<14);
277         memory_set_bankptr(2, ram_data);
278
279         ram_data = mess_ram + (memory_selection[2]<<14);
280         memory_set_bankptr(3, ram_data);
281
282         ram_data = mess_ram + (memory_selection[3]<<14);
283         memory_set_bankptr(4, ram_data);
284
285         logerror("extended memory paging: %02x\n",MemorySelection);
286      }
287}
288
289
290
291static WRITE8_HANDLER(spectrum_plus3_port_7ffd_w)
292{
293      /* D0-D2: RAM page located at 0x0c000-0x0ffff */
294      /* D3 - Screen select (screen 0 in ram page 5, screen 1 in ram page 7 */
295      /* D4 - ROM select - which rom paged into 0x0000-0x03fff */
296      /* D5 - Disable paging */
297
298      /* disable paging? */
299      if (spectrum_128_port_7ffd_data & 0x20)
300            return;
301
302      /* store new state */
303      spectrum_128_port_7ffd_data = data;
304
305      /* update memory */
306      spectrum_plus3_update_memory(machine);
307}
308
309static WRITE8_HANDLER(spectrum_plus3_port_1ffd_w)
310{
311
312      /* D0-D1: ROM/RAM paging */
313      /* D2: Affects if d0-d1 work on ram/rom */
314      /* D3 - Disk motor on/off */
315      /* D4 - parallel port strobe */
316
317      floppy_drive_set_motor_state(image_from_devtype_and_index(IO_FLOPPY, 0), data & (1<<3));
318      floppy_drive_set_motor_state(image_from_devtype_and_index(IO_FLOPPY, 1), data & (1<<3));
319      floppy_drive_set_ready_state(image_from_devtype_and_index(IO_FLOPPY, 0), 1, 1);
320      floppy_drive_set_ready_state(image_from_devtype_and_index(IO_FLOPPY, 1), 1, 1);
321
322      spectrum_plus3_port_1ffd_data = data;
323
324      /* disable paging? */
325      if ((spectrum_128_port_7ffd_data & 0x20)==0)
326      {
327            /* no */
328            spectrum_plus3_update_memory(machine);
329      }
330}
331
332/* decoding as per spectrum FAQ on www.worldofspectrum.org */
333static  READ8_HANDLER ( spectrum_plus3_port_r )
334{
335    if ((offset & 1)==0)
336    {
337       return spectrum_port_fe_r(machine, offset);
338    }
339
340    if ((offset & 2)==0)
341    {
342       switch ((offset>>14) & 0x03)
343       {
344         /* +3 fdc,memory,centronics */
345         case 0:
346         {
347            switch ((offset>>12) & 0x03)
348            {
349               /* +3 centronics */
350               case 0:
351                  break;
352
353               /* +3 fdc status */
354               case 2:
355                  return spectrum_plus3_port_2ffd_r(machine, offset);
356               /* +3 fdc data */
357               case 3:
358                  return spectrum_plus3_port_3ffd_r(machine, offset);
359
360               default:
361                  break;
362            }
363         }
364         break;
365
366         /* 128k AY data */
367         case 3:
368            return spectrum_128_port_fffd_r(machine, offset);
369
370         default:
371            break;
372       }
373    }
374
375    return video_screen_get_vpos(machine->primary_screen)<193 ? spectrum_128_screen_location[0x1800|(video_screen_get_vpos(machine->primary_screen)&0xf8)<<2]:0xff;
376}
377
378static WRITE8_HANDLER ( spectrum_plus3_port_w )
379{
380      if ((offset & 1)==0)
381            spectrum_port_fe_w(machine, offset, data);
382
383      /* the following is not decoded exactly, need to check
384        what is correct! */
385
386      if ((offset & 2)==0)
387      {
388         switch ((offset>>14) & 0x03)
389         {
390            /* +3 fdc,memory,centronics */
391            case 0:
392            {
393               switch ((offset>>12) & 0x03)
394               {
395                  /* +3 centronics */
396                  case 0:
397                  {
398
399
400                  }
401                  break;
402
403                  /* +3 memory */
404                  case 1:
405                     spectrum_plus3_port_1ffd_w(machine, offset, data);
406                     break;
407
408                  /* +3 fdc data */
409                  case 3:
410                     spectrum_plus3_port_3ffd_w(machine, offset, data);
411                     break;
412
413                  default:
414                     break;
415               }
416            }
417            break;
418
419            /* 128k memory */
420            case 1:
421               spectrum_plus3_port_7ffd_w(machine, offset, data);
422               break;
423
424            /* 128k AY data */
425            case 2:
426               spectrum_128_port_bffd_w(machine, offset, data);
427               break;
428
429            /* 128K AY register */
430            case 3:
431               spectrum_128_port_fffd_w(machine, offset, data);
432
433            default:
434               break;
435         }
436      }
437
438/*logerror("Write %02x to +3 port: %04x\n", data, offset); */
439}
440
441/* ports are not decoded full.
442The function decodes the ports appropriately */
443static ADDRESS_MAP_START (spectrum_plus3_io, ADDRESS_SPACE_IO, 8)
444      AM_RANGE(0x0000, 0xffff) AM_READWRITE( spectrum_plus3_port_r, spectrum_plus3_port_w )
445ADDRESS_MAP_END
446
447static MACHINE_RESET( spectrum_plus3 )
448{
449   memset(mess_ram,0,128*1024);
450   
451   nec765_init(&spectrum_plus3_nec765_interface, NEC765A, NEC765_RDY_PIN_CONNECTED);
452
453   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 0), FLOPPY_DRIVE_SS_40);
454   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 1), FLOPPY_DRIVE_SS_40);
455
456   /* Initial configuration */
457   spectrum_128_port_7ffd_data = 0;
458   spectrum_plus3_port_1ffd_data = 0;
459   spectrum_plus3_update_memory(machine);
460
461   MACHINE_RESET_CALL(spectrum);
462}
463
464static MACHINE_DRIVER_START( spectrum_plus3 )
465   MDRV_IMPORT_FROM( spectrum_128 )
466   MDRV_CPU_MODIFY("main")
467   MDRV_CPU_IO_MAP(spectrum_plus3_io, 0)
468   MDRV_SCREEN_MODIFY("main")
469   MDRV_SCREEN_REFRESH_RATE(50.01)
470
471   MDRV_MACHINE_RESET( spectrum_plus3 )
472MACHINE_DRIVER_END
473
474/***************************************************************************
475
476  Game driver(s)
477
478***************************************************************************/
479
480ROM_START(specpl2a)
481   ROM_REGION(0x20000,REGION_CPU1,0)
482   ROM_LOAD("p2a41_0.rom",0x10000,0x4000, CRC(30c9f490) SHA1(62ec15a4af56cd1d206d0bd7011eac7c889a595d))
483   ROM_LOAD("p2a41_1.rom",0x14000,0x4000, CRC(a7916b3f) SHA1(1a7812c383a3701e90e88d1da086efb0c033ac72))
484   ROM_LOAD("p2a41_2.rom",0x18000,0x4000, CRC(c9a0b748) SHA1(8df145d10ff78f98138682ea15ebccb2874bf759))
485   ROM_LOAD("p2a41_3.rom",0x1c000,0x4000, CRC(b88fd6e3) SHA1(be365f331942ec7ec35456b641dac56a0dbfe1f0))
486   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
487ROM_END
488
489ROM_START(specpls3)
490   ROM_REGION(0x20000,REGION_CPU1,0)
491   ROM_LOAD("pl3-0.rom",0x10000,0x4000, CRC(17373da2) SHA1(e319ed08b4d53a5e421a75ea00ea02039ba6555b))
492   ROM_LOAD("pl3-1.rom",0x14000,0x4000, CRC(f1d1d99e) SHA1(c9969fc36095a59787554026a9adc3b87678c794))
493   ROM_LOAD("pl3-2.rom",0x18000,0x4000, CRC(3dbf351d) SHA1(22e50c6ba4157a3f6a821bd9937cd26e292775c6))
494   ROM_LOAD("pl3-3.rom",0x1c000,0x4000, CRC(04448eaa) SHA1(65f031caa8148a5493afe42c41f4929deab26b4e))
495   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
496ROM_END
497
498ROM_START(specp3sp)
499   ROM_REGION(0x20000,REGION_CPU1,0)
500   ROM_LOAD("plus3sp0.rom",0x10000,0x4000, CRC(1f86147a) SHA1(e9b0a60a1a8def511d59090b945d175bdc646346))
501   ROM_LOAD("plus3sp1.rom",0x14000,0x4000, CRC(a8ac4966) SHA1(4e48f196427596c7990c175d135c15a039c274a4))
502   ROM_LOAD("plus3sp2.rom",0x18000,0x4000, CRC(f6bb0296) SHA1(09fc005625589ef5992515957ce7a3167dec24b2))
503   ROM_LOAD("plus3sp3.rom",0x1c000,0x4000, CRC(f6d25389) SHA1(ec8f644a81e2e9bcb58ace974103ea960361bad2))
504   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
505ROM_END
506
507ROM_START(specpl3e)
508   ROM_REGION(0x20000,REGION_CPU1,0)
509   ROM_LOAD("roma-en.rom",0x10000,0x8000, CRC(2d533344) SHA1(5ff2dae32eb745d87e0b54c595d1d20a866f316f))
510   ROM_LOAD("romb-en.rom",0x18000,0x8000, CRC(ef8d5d92) SHA1(983aa53aa76e25a3af123c896016bacf6829b72b))
511   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
512ROM_END
513
514ROM_START(specp3es)
515   ROM_REGION(0x20000,REGION_CPU1,0)
516   ROM_LOAD("roma-es.rom",0x10000,0x8000, CRC(ba694b4b) SHA1(d15d9e43950483cffc79f1cfa89ecb114a88f6c2))
517   ROM_LOAD("romb-es.rom",0x18000,0x8000, CRC(61ed94db) SHA1(935b14c13db75d872de8ad0d591aade0adbbc355))
518   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
519ROM_END
520
521static void specpls3_floppy_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
522{
523   /* floppy */
524   switch(state)
525   {
526      /* --- the following bits of info are returned as 64-bit signed integers --- */
527      case MESS_DEVINFO_INT_COUNT:                     info->i = 2; break;
528
529      default:                              legacydsk_device_getinfo(devclass, state, info); break;
530   }
531}
532
533SYSTEM_CONFIG_START(specpls3)
534   CONFIG_IMPORT_FROM(spectrum_common)
535   CONFIG_DEVICE(specpls3_floppy_getinfo)
536   CONFIG_RAM_DEFAULT(128 * 1024)
537SYSTEM_CONFIG_END
538
539
540/*    YEAR  NAME      PARENT    COMPAT  MACHINE     INPUT       INIT    CONFIG      COMPANY     FULLNAME */
541COMP( 1987, specpl2a, spec128,  0,      spectrum_plus3,spectrum,   0,      specpls3,   "Amstrad plc",          "ZX Spectrum +2a" , 0 )
542COMP( 1987, specpls3, spec128,  0,      spectrum_plus3,spectrum,   0,      specpls3,   "Amstrad plc",          "ZX Spectrum +3" , 0 )
543COMP( 1987, specp3sp, spec128,  0,      spectrum_plus3,spectrum,   0,      specpls3,   "Amstrad plc",          "ZX Spectrum +3 (Spain)" , 0 )
544COMP( 2000, specpl3e, spec128,  0,      spectrum_plus3,spectrum,   0,      specpls3,   "Amstrad plc",          "ZX Spectrum +3e" , GAME_COMPUTER_MODIFIED )
545COMP( 2000, specp3es, spec128,  0,      spectrum_plus3,spectrum,   0,      specpls3,   "Amstrad plc",          "ZX Spectrum +3e (Spain)" , GAME_COMPUTER_MODIFIED )
src/mess/drivers/scorpion.c
r0r2517
1/***************************************************************************
2
3   NOTE: ****** Specbusy: press N, R, or E to boot *************
4
5
6        Spectrum/Inves/TK90X etc. memory map:
7
8    CPU:
9        0000-3fff ROM
10        4000-ffff RAM
11
12        Spectrum 128/+2/+2a/+3 memory map:
13
14        CPU:
15                0000-3fff Banked ROM/RAM (banked rom only on 128/+2)
16                4000-7fff Banked RAM
17                8000-bfff Banked RAM
18                c000-ffff Banked RAM
19
20        TS2068 memory map: (Can't have both EXROM and DOCK active)
21        The 8K EXROM can be loaded into multiple pages.
22
23    CPU:
24                0000-1fff     ROM / EXROM / DOCK (Cartridge)
25                2000-3fff     ROM / EXROM / DOCK
26                4000-5fff \
27                6000-7fff  \
28                8000-9fff  |- RAM / EXROM / DOCK
29                a000-bfff  |
30                c000-dfff  /
31                e000-ffff /
32
33
34Interrupts:
35
36Changes:
37
3829/1/2000   KT -    Implemented initial +3 emulation.
3930/1/2000   KT -    Improved input port decoding for reading and therefore
40            correct keyboard handling for Spectrum and +3.
4131/1/2000   KT -    Implemented buzzer sound for Spectrum and +3.
42            Implementation copied from Paul Daniel's Jupiter driver.
43            Fixed screen display problems with dirty chars.
44            Added support to load .Z80 snapshots. 48k support so far.
4513/2/2000   KT -    Added Interface II, Kempston, Fuller and Mikrogen
46            joystick support.
4717/2/2000   DJR -   Added full key descriptions and Spectrum+ keys.
48            Fixed Spectrum +3 keyboard problems.
4917/2/2000   KT -    Added tape loading from WAV/Changed from DAC to generic
50            speaker code.
5118/2/2000   KT -    Added tape saving to WAV.
5227/2/2000   KT -    Took DJR's changes and added my changes.
5327/2/2000   KT -    Added disk image support to Spectrum +3 driver.
5427/2/2000   KT -    Added joystick I/O code to the Spectrum +3 I/O handler.
5514/3/2000   DJR -   Tape handling dipswitch.
5626/3/2000   DJR -   Snapshot files are now classifed as snapshots not
57            cartridges.
5804/4/2000   DJR -   Spectrum 128 / +2 Support.
5913/4/2000   DJR -   +4 Support (unofficial 48K hack).
6013/4/2000   DJR -   +2a Support (rom also used in +3 models).
6113/4/2000   DJR -   TK90X, TK95 and Inves support (48K clones).
6221/4/2000   DJR -   TS2068 and TC2048 support (TC2048 Supports extra video
63            modes but doesn't have bank switching or sound chip).
6409/5/2000   DJR -   Spectrum +2 (France, Spain), +3 (Spain).
6517/5/2000   DJR -   Dipswitch to enable/disable disk drives on +3 and clones.
6627/6/2000   DJR -   Changed 128K/+3 port decoding (sound now works in Zub 128K).
6706/8/2000   DJR -   Fixed +3 Floppy support
6810/2/2001   KT  -   Re-arranged code and split into each model emulated.
69            Code is split into 48k, 128k, +3, tc2048 and ts2048
70            segments. 128k uses some of the functions in 48k, +3
71            uses some functions in 128, and tc2048/ts2048 use some
72            of the functions in 48k. The code has been arranged so
73            these functions come in some kind of "override" order,
74            read functions changed to use  READ8_HANDLER and write
75            functions changed to use WRITE8_HANDLER.
76            Added Scorpion256 preliminary.
7718/6/2001   DJR -   Added support for Interface 2 cartridges.
78xx/xx/2001  KS -    TS-2068 sound fixed.
79            Added support for DOCK cartridges for TS-2068.
80            Added Spectrum 48k Psycho modified rom driver.
81            Added UK-2086 driver.
8223/12/2001  KS -    48k machines are now able to run code in screen memory.
83                Programs which keep their code in screen memory
84                like monitors, tape copiers, decrunchers, etc.
85                works now.
86                Fixed problem with interrupt vector set to 0xffff (much
87            more 128k games works now).
88                A useful used trick on the Spectrum is to set
89                interrupt vector to 0xffff (using the table
90                which contain 0xff's) and put a byte 0x18 hex,
91                the opcode for JR, at this address. The first
92                byte of the ROM is a 0xf3 (DI), so the JR will
93                jump to 0xfff4, where a long JP to the actual
94                interrupt routine is put. Due to unideal
95                bankswitching in MAME this JP were to 0001 what
96                causes Spectrum to reset. Fixing this problem
97                made much more software runing (i.e. Paperboy).
98            Corrected frames per second value for 48k and 128k
99            Sincalir machines.
100                There are 50.08 frames per second for Spectrum
101                48k what gives 69888 cycles for each frame and
102                50.021 for Spectrum 128/+2/+2A/+3 what gives
103                70908 cycles for each frame.
104            Remaped some Spectrum+ keys.
105                Presing F3 to reset was seting 0xf7 on keyboard
106                input port. Problem occured for snapshots of
107                some programms where it was readed as pressing
108                key 4 (which is exit in Tapecopy by R. Dannhoefer
109                for example).
110            Added support to load .SP snapshots.
111            Added .BLK tape images support.
112                .BLK files are identical to .TAP ones, extension
113                is an only difference.
11408/03/2002  KS -    #FF port emulation added.
115                Arkanoid works now, but is not playable due to
116                completly messed timings.
117
118Initialisation values used when determining which model is being emulated:
119 48K        Spectrum doesn't use either port.
120 128K/+2    Bank switches with port 7ffd only.
121 +3/+2a     Bank switches with both ports.
122
123Notes:
124 1. No contented memory.
125 2. No hi-res colour effects (need contended memory first for accurate timing).
126 3. Multiface 1 and Interface 1 not supported.
127 4. Horace and the Spiders cartridge doesn't run properly.
128 5. Tape images not supported:
129    .TZX, .SPC, .ITM, .PAN, .TAP(Warajevo), .VOC, .ZXS.
130 6. Snapshot images not supported:
131    .ACH, .PRG, .RAW, .SEM, .SIT, .SNX, .ZX, .ZXS, .ZX82.
132 7. 128K emulation is not perfect - the 128K machines crash and hang while
133    running quite a lot of games.
134 8. Disk errors occur on some +3 games.
135 9. Video hardware of all machines is timed incorrectly.
13610. EXROM and HOME cartridges are not emulated.
13711. The TK90X and TK95 roms output 0 to port #df on start up.
13812. The purpose of this port is unknown (probably display mode as TS2068) and
139    thus is not emulated.
140
141Very detailed infos about the ZX Spectrum +3e can be found at
142
143http://www.z88forever.org.uk/zxplus3e/
144
145*******************************************************************************/
146
147#include "driver.h"
148#include "includes/spectrum.h"
149#include "eventlst.h"
150#include "devices/snapquik.h"
151#include "devices/cartslot.h"
152#include "devices/cassette.h"
153#include "sound/ay8910.h"
154#include "sound/speaker.h"
155#include "formats/tzx_cas.h"
156
157/* +3 hardware */
158#include "machine/nec765.h"
159#include "devices/dsk.h"
160
161/****************************************************************************************************/
162/* BETADISK/TR-DOS disc controller emulation */
163/* microcontroller KR1818VG93 is a russian wd179x clone */
164#include "machine/wd17xx.h"
165
166/*
167DRQ (D6) and INTRQ (D7).
168DRQ - signal showing request of data by microcontroller
169INTRQ - signal of completion of execution of command.
170*/
171
172static int betadisk_status;
173static int betadisk_active;
174
175static void betadisk_wd179x_callback(running_machine *machine, wd17xx_state_t state, void *param)
176{
177   switch (state)
178   {
179      case WD17XX_DRQ_SET:
180      {
181         betadisk_status |= (1<<6);
182      }
183      break;
184
185      case WD17XX_DRQ_CLR:
186      {
187         betadisk_status &=~(1<<6);
188      }
189      break;
190
191      case WD17XX_IRQ_SET:
192      {
193         betadisk_status |= (1<<7);
194      }
195      break;
196
197      case WD17XX_IRQ_CLR:
198      {
199         betadisk_status &=~(1<<7);
200      }
201      break;
202   }
203}
204
205MACHINE_START( scorpion )
206{
207   betadisk_active = 0;
208   betadisk_status = 0x03f;
209   wd17xx_init(machine, WD_TYPE_179X, betadisk_wd179x_callback, NULL);
210}
211
212/****************************************************************************************************/
213/* Zs Scorpion 256 */
214
215/*
216port 7ffd. full compatibility with Zx spectrum 128. digits are:
217
218D0-D2 - number of RAM page to put in C000-FFFF
219D3    - switch of address for RAM of screen. 0 - 4000, 1 - c000
220D4    - switch of ROM : 0-zx128, 1-zx48
221D5    - 1 in this bit will block further output in port 7FFD, until reset.
222*/
223
224/*
225port 1ffd - additional port for resources of computer.
226
227D0    - block of ROM in 0-3fff. when set to 1 - allows read/write page 0 of RAM
228D1    - selects ROM expansion. this rom contains main part of service monitor.
229D2    - not used
230D3    - used for output in RS-232C
231D4    - extended RAM. set to 1 - connects RAM page with number 8-15 in
232    C000-FFFF. number of page is given in gidits D0-D2 of port 7FFD
233D5    - signal of strobe for interface centronics. to form the strobe has to be
234    set to 1.
235D6-D7 - not used. ( yet ? )
236*/
237
238/* rom 0=zx128, 1=zx48, 2 = service monitor, 3=tr-dos */
239
240static int scorpion_256_port_1ffd_data = 0;
241
242static void scorpion_update_memory(running_machine *machine)
243{
244   unsigned char *ChosenROM;
245   int ROMSelection;
246   read8_machine_func rh;
247   write8_machine_func wh;
248
249   if (spectrum_128_port_7ffd_data & 8)
250   {
251      logerror("SCREEN 1: BLOCK 7\n");
252      spectrum_128_screen_location = mess_ram + (7<<14);
253   }
254   else
255   {
256      logerror("SCREEN 0: BLOCK 5\n");
257      spectrum_128_screen_location = mess_ram + (5<<14);
258   }
259
260   /* select ram at 0x0c000-0x0ffff */
261   {
262      int ram_page;
263      unsigned char *ram_data;
264
265      ram_page = (spectrum_128_port_7ffd_data & 0x07) | ((scorpion_256_port_1ffd_data & 0x10)>>1);
266      ram_data = mess_ram + (ram_page<<14);
267
268      memory_set_bankptr(4, ram_data);
269
270      logerror("RAM at 0xc000: %02x\n",ram_page);
271   }
272
273   if (scorpion_256_port_1ffd_data & 0x01)
274   {
275      /* ram at 0x0000 */
276      logerror("RAM at 0x0000\n");
277
278      /* connect page 0 of ram to 0x0000 */
279      rh = SMH_BANK1;
280      wh = SMH_BANK1;
281      memory_set_bankptr(1, mess_ram+(8<<14));
282   }
283   else
284   {
285      /* rom at 0x0000 */
286      logerror("ROM at 0x0000\n");
287
288      /* connect page 0 of rom to 0x0000 */
289      rh = SMH_BANK1;
290      wh = SMH_NOP;
291
292      if (scorpion_256_port_1ffd_data & 0x02)
293      {
294         ROMSelection = 2;
295      }
296      else
297      {
298         /* ROM switching */
299         ROMSelection = ((spectrum_128_port_7ffd_data>>4) & 0x01) ;
300      }
301      /* rom 0 is 128K rom, rom 1 is 48 BASIC */
302      ChosenROM = memory_region(REGION_CPU1) + 0x010000 + (ROMSelection<<14);
303
304      memory_set_bankptr(1, ChosenROM);
305
306      logerror("rom switch: %02x\n", ROMSelection);
307   }
308   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x3fff, 0, 0, rh);
309   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x3fff, 0, 0, wh);
310}
311
312
313static WRITE8_HANDLER(scorpion_port_7ffd_w)
314{
315   logerror("scorpion 7ffd w: %02x\n", data);
316
317   /* disable paging? */
318   if (spectrum_128_port_7ffd_data & 0x20)
319      return;
320
321   /* store new state */
322   spectrum_128_port_7ffd_data = data;
323
324   /* update memory */
325   scorpion_update_memory(machine);
326}
327
328static WRITE8_HANDLER(scorpion_port_1ffd_w)
329{
330   logerror("scorpion 1ffd w: %02x\n", data);
331
332   scorpion_256_port_1ffd_data = data;
333
334   /* disable paging? */
335   if ((spectrum_128_port_7ffd_data & 0x20)==0)
336   {
337      scorpion_update_memory(machine);
338   }
339}
340
341
342/* not sure if decoding is full or partial on scorpion */
343/* TO BE CHECKED! */
344static  READ8_HANDLER(scorpion_port_r)
345{
346
347    /* KT: the following is not decoded exactly, need to check what
348     is correct */
349    if ((offset & 2)==0)
350    {
351       switch ((offset>>8) & 0xff)
352       {
353            case 0xff: return spectrum_128_port_fffd_r(machine, offset);
354            case 0x1f: return spectrum_port_1f_r(machine, offset);
355            case 0x7f: return spectrum_port_7f_r(machine, offset);
356            case 0xdf: return spectrum_port_df_r(machine, offset);
357       }
358    }
359    switch (offset & 0x0ff)
360    {
361       case 0x0fe:
362          return spectrum_port_fe_r(machine, offset);
363/*      case 0x01f:
364         return wd17xx_status_r(machine, offset);
365      case 0x03f:
366         return wd17xx_track_r(machine, offset);
367      case 0x05f:
368         return wd17xx_sector_r(machine, offset);
369      case 0x07f:
370         return wd17xx_data_r(machine, offset);
371      case 0x0ff:
372         return betadisk_status;*/
373    }
374    return 0xff;
375}
376
377
378/* not sure if decoding is full or partial on scorpion */
379/* TO BE CHECKED! */
380static WRITE8_HANDLER(scorpion_port_w)
381{
382    switch (offset & 0x0ff)
383    {
384      case 0xfe : spectrum_port_fe_w(machine, offset, data);
385               break;
386      default:
387          if ((offset & 2)==0)
388         {
389               switch ((offset>>8) & 0xf0)
390               {
391                  case 0x70:
392                        scorpion_port_7ffd_w(machine, offset, data);
393                        break;
394                  case 0xb0:
395                        spectrum_128_port_bffd_w(machine, offset, data);
396                        break;
397                  case 0xf0:
398                        spectrum_128_port_fffd_w(machine, offset, data);
399                        break;
400                  case 0x10:
401                        scorpion_port_1ffd_w(machine, offset, data);
402                        break;
403                  default:
404                        logerror("Write %02x to scorpion port: %04x\n", data, offset);
405               }
406         }
407         else
408         {
409            logerror("Write %02x to scorpion port: %04x\n", data, offset);
410         }
411   }
412}
413
414
415
416/* ports are not decoded full.
417The function decodes the ports appropriately */
418static ADDRESS_MAP_START (scorpion_io, ADDRESS_SPACE_IO, 8)
419   AM_RANGE(0x0000, 0xffff) AM_READWRITE(scorpion_port_r, scorpion_port_w)
420ADDRESS_MAP_END
421
422
423static MACHINE_RESET( scorpion )
424{
425   memset(mess_ram,0,256*1024);
426   
427   /* Bank 5 is always in 0x4000 - 0x7fff */
428   memory_set_bankptr(2, mess_ram + (5<<14));
429
430   /* Bank 2 is always in 0x8000 - 0xbfff */
431   memory_set_bankptr(3, mess_ram + (2<<14));
432
433   spectrum_128_port_7ffd_data = 0;
434   scorpion_256_port_1ffd_data = 0;
435
436   scorpion_update_memory(machine);   
437}
438
439static MACHINE_DRIVER_START( scorpion )
440   MDRV_IMPORT_FROM( spectrum_128 )
441   MDRV_CPU_MODIFY("main")
442   MDRV_CPU_IO_MAP(scorpion_io, 0)
443   MDRV_MACHINE_START( scorpion )
444   MDRV_MACHINE_RESET( scorpion )
445MACHINE_DRIVER_END
446
447
448
449/***************************************************************************
450
451  Game driver(s)
452
453***************************************************************************/
454
455ROM_START(scorpion)
456   ROM_REGION(0x020000, REGION_CPU1, 0)
457   ROM_LOAD("scorp0.rom",0x010000, 0x4000, CRC(0eb40a09))
458   ROM_LOAD("scorp1.rom",0x014000, 0x4000, CRC(9d513013))
459   ROM_LOAD("scorp2.rom",0x018000, 0x4000, CRC(fd0d3ce1))
460   ROM_LOAD("scorp3.rom",0x01c000, 0x4000, CRC(1fe1d003))
461   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
462ROM_END
463
464
465SYSTEM_CONFIG_EXTERN(spectrum)
466
467SYSTEM_CONFIG_START(scorpion)
468   CONFIG_IMPORT_FROM(spectrum)
469   CONFIG_RAM_DEFAULT(256 * 1024)
470SYSTEM_CONFIG_END
471
472/*    YEAR  NAME      PARENT    COMPAT  MACHINE     INPUT       INIT    CONFIG      COMPANY     FULLNAME */
473COMP( ????, scorpion, 0,       0,      scorpion,      spectrum,   0,      scorpion,   "Zonov and Co.",      "Zs Scorpion 256", 0 )
src/mess/drivers/spectrum.c
r2516r2517
150150#include "devices/snapquik.h"
151151#include "devices/cartslot.h"
152152#include "devices/cassette.h"
153#include "sound/ay8910.h"
154153#include "sound/speaker.h"
155154#include "formats/tzx_cas.h"
156155
157/* +3 hardware */
158#include "machine/nec765.h"
159#include "devices/dsk.h"
160156
161157
162static const struct AY8910interface spectrum_ay_interface =
163{
164   AY8910_LEGACY_OUTPUT,
165   AY8910_DEFAULT_LOADS,
166   NULL
167};
168
169
170158/****************************************************************************************************/
171159/* Spectrum 48k functions */
172160
r2516r2517
179167
180168int PreviousFE = 0;
181169
182static WRITE8_HANDLER(spectrum_port_fe_w)
170WRITE8_HANDLER(spectrum_port_fe_w)
183171{
184172   unsigned char Changed;
185173
r2516r2517
207195   PreviousFE = data;
208196}
209197
210
211
212
213198static ADDRESS_MAP_START (spectrum_mem, ADDRESS_SPACE_PROGRAM, 8)
214199   AM_RANGE(0x0000, 0x3fff) AM_ROM
215   AM_RANGE(0x4000, 0x57ff) AM_READWRITE( spectrum_characterram_r, spectrum_characterram_w )
216   AM_RANGE(0x5800, 0x5aff) AM_READWRITE( spectrum_colorram_r, spectrum_colorram_w )
200   AM_RANGE(0x4000, 0x57ff) AM_RAM AM_BASE(&spectrum_characterram )
201   AM_RANGE(0x5800, 0x5aff) AM_RAM AM_BASE(&spectrum_colorram )
217202   AM_RANGE(0x5b00, 0xffff) AM_RAM
218203ADDRESS_MAP_END
219204
220205/* KT: more accurate keyboard reading */
221206/* DJR: Spectrum+ keys added */
222static  READ8_HANDLER(spectrum_port_fe_r)
207READ8_HANDLER(spectrum_port_fe_r)
223208{
224209   int lines = offset>>8;
225210   int data = 0xff;
r2516r2517
288273}
289274
290275/* kempston joystick interface */
291static  READ8_HANDLER(spectrum_port_1f_r)
276READ8_HANDLER(spectrum_port_1f_r)
292277{
293278  return input_port_read(machine, "KEMPSTON") & 0x1f;
294279}
295280
296281/* fuller joystick interface */
297static  READ8_HANDLER(spectrum_port_7f_r)
282READ8_HANDLER(spectrum_port_7f_r)
298283{
299284  return input_port_read(machine, "FULLER") | (0xff^0x8f);
300285}
301286
302287/* mikrogen joystick interface */
303static  READ8_HANDLER(spectrum_port_df_r)
288READ8_HANDLER(spectrum_port_df_r)
304289{
305290  return input_port_read(machine, "MIKROGEN") | (0xff^0x1f);
306291}
r2516r2517
338323   AM_RANGE(0x0000, 0xffff) AM_READWRITE( spectrum_port_r, spectrum_port_w )
339324ADDRESS_MAP_END
340325
341
342326/****************************************************************************************************/
343/* functions and data used by spectrum 128, spectrum +2, spectrum +3 and scorpion */
344static unsigned char *spectrum_ram = NULL;
345
346static void spectrum_alloc_ram(int ram_size_in_k)
347{
348   spectrum_ram = (unsigned char *)auto_malloc(ram_size_in_k*1024);
349   memset(spectrum_ram, 0, ram_size_in_k*1024);
350}
351
352
353/****************************************************************************************************/
354/* Spectrum 128 specific functions */
355
356int spectrum_128_port_7ffd_data = -1;
357unsigned char *spectrum_128_screen_location = NULL;
358
359static WRITE8_HANDLER(spectrum_128_port_7ffd_w)
360{
361   /* D0-D2: RAM page located at 0x0c000-0x0ffff */
362   /* D3 - Screen select (screen 0 in ram page 5, screen 1 in ram page 7 */
363   /* D4 - ROM select - which rom paged into 0x0000-0x03fff */
364   /* D5 - Disable paging */
365
366   /* disable paging? */
367   if (spectrum_128_port_7ffd_data & 0x20)
368         return;
369
370   /* store new state */
371   spectrum_128_port_7ffd_data = data;
372
373   /* update memory */
374   spectrum_128_update_memory(machine);
375}
376
377extern void spectrum_128_update_memory(running_machine *machine)
378{
379   unsigned char *ChosenROM;
380   int ROMSelection;
381
382   if (spectrum_128_port_7ffd_data & 8)
383   {
384         logerror("SCREEN 1: BLOCK 7\n");
385         spectrum_128_screen_location = spectrum_ram + (7<<14);
386   }
387   else
388   {
389         logerror("SCREEN 0: BLOCK 5\n");
390         spectrum_128_screen_location = spectrum_ram + (5<<14);
391   }
392
393   /* select ram at 0x0c000-0x0ffff */
394   {
395         int ram_page;
396         unsigned char *ram_data;
397
398         ram_page = spectrum_128_port_7ffd_data & 0x07;
399         ram_data = spectrum_ram + (ram_page<<14);
400
401         memory_set_bankptr(4, ram_data);
402         memory_set_bankptr(8, ram_data);
403
404         logerror("RAM at 0xc000: %02x\n",ram_page);
405   }
406
407   /* ROM switching */
408   ROMSelection = ((spectrum_128_port_7ffd_data>>4) & 0x01);
409
410   /* rom 0 is 128K rom, rom 1 is 48 BASIC */
411
412   ChosenROM = memory_region(REGION_CPU1) + 0x010000 + (ROMSelection<<14);
413
414   memory_set_bankptr(1, ChosenROM);
415
416   logerror("rom switch: %02x\n", ROMSelection);
417}
418
419
420
421static WRITE8_HANDLER(spectrum_128_port_bffd_w)
422{
423   AY8910_write_port_0_w(machine, 0, data);
424}
425
426static WRITE8_HANDLER(spectrum_128_port_fffd_w)
427{
428   AY8910_control_port_0_w(machine, 0, data);
429}
430
431static  READ8_HANDLER(spectrum_128_port_fffd_r)
432{
433   return AY8910_read_port_0_r(machine, 0);
434}
435
436static  READ8_HANDLER ( spectrum_128_port_r )
437{
438    if ((offset & 1)==0)
439    {
440       return spectrum_port_fe_r(machine, offset);
441    }
442
443    if ((offset & 2)==0)
444    {
445      switch ((offset>>14) & 0x03)
446      {
447         default:
448            break;
449
450         case 3:
451            return spectrum_128_port_fffd_r(machine, offset);
452      }
453    }
454
455    /* don't think these are correct! */
456    if ((offset & 0xff)==0x1f)
457       return spectrum_port_1f_r(machine, offset);
458
459    if ((offset & 0xff)==0x7f)
460       return spectrum_port_7f_r(machine, offset);
461
462    if ((offset & 0xff)==0xdf)
463       return spectrum_port_df_r(machine, offset);
464
465    return video_screen_get_vpos(machine->primary_screen)<193 ? spectrum_128_screen_location[0x1800|(video_screen_get_vpos(machine->primary_screen)&0xf8)<<2]:0xff;
466}
467
468static WRITE8_HANDLER ( spectrum_128_port_w )
469{
470      if ((offset & 1)==0)
471            spectrum_port_fe_w(machine, offset,data);
472
473      /* Only decodes on A15, A14 & A1 */
474      else if ((offset & 2)==0)
475      {
476            switch ((offset>>8) & 0xc0)
477            {
478                  case 0x40:
479                        spectrum_128_port_7ffd_w(machine, offset, data);
480                        break;
481                  case 0x80:
482                        spectrum_128_port_bffd_w(machine, offset, data);
483                        break;
484                  case 0xc0:
485                        spectrum_128_port_fffd_w(machine, offset, data);
486                        break;
487                  default:
488                        logerror("Write %02x to 128 port: %04x\n", data, offset);
489            }
490      }
491      else
492      {
493         logerror("Write %02x to 128 port: %04x\n", data, offset);
494      }
495}
496
497/* ports are not decoded full.
498The function decodes the ports appropriately */
499static ADDRESS_MAP_START (spectrum_128_io, ADDRESS_SPACE_IO, 8)
500   AM_RANGE(0x0000, 0xffff) AM_READWRITE( spectrum_128_port_r, spectrum_128_port_w )
501ADDRESS_MAP_END
502
503static ADDRESS_MAP_START (spectrum_128_mem, ADDRESS_SPACE_PROGRAM, 8)
504   AM_RANGE( 0x0000, 0x3fff) AM_READWRITE( SMH_BANK1, SMH_BANK5 )
505   AM_RANGE( 0x4000, 0x7fff) AM_READWRITE( SMH_BANK2, SMH_BANK6 )
506   AM_RANGE( 0x8000, 0xbfff) AM_READWRITE( SMH_BANK3, SMH_BANK7 )
507   AM_RANGE( 0xc000, 0xffff) AM_READWRITE( SMH_BANK4, SMH_BANK8 )
508ADDRESS_MAP_END
509
510static MACHINE_RESET( spectrum_128 )
511{
512   spectrum_alloc_ram(128);
513
514   /* 0x0000-0x3fff always holds ROM */
515
516   /* Bank 5 is always in 0x4000 - 0x7fff */
517   memory_set_bankptr(2, spectrum_ram + (5<<14));
518   memory_set_bankptr(6, spectrum_ram + (5<<14));
519
520   /* Bank 2 is always in 0x8000 - 0xbfff */
521   memory_set_bankptr(3, spectrum_ram + (2<<14));
522   memory_set_bankptr(7, spectrum_ram + (2<<14));
523
524   /* set initial ram config */
525   spectrum_128_port_7ffd_data = 0;
526   spectrum_128_update_memory(machine);
527
528   MACHINE_RESET_CALL(spectrum);
529}
530
531/****************************************************************************************************/
532/* Spectrum + 3 specific functions */
533/* This driver uses some of the spectrum_128 functions. The +3 is similar to a spectrum 128
534but with a disc drive */
535
536int spectrum_plus3_port_1ffd_data = -1;
537
538
539static const nec765_interface spectrum_plus3_nec765_interface =
540{
541      NULL,
542      NULL
543};
544
545
546static const int spectrum_plus3_memory_selections[]=
547{
548      0,1,2,3,
549      4,5,6,7,
550      4,5,6,3,
551      4,7,6,3
552};
553
554static WRITE8_HANDLER(spectrum_plus3_port_3ffd_w)
555{
556      if (~input_port_read(machine, "CONFIG") & 0x20)
557            nec765_data_w(machine, 0,data);
558}
559
560static  READ8_HANDLER(spectrum_plus3_port_3ffd_r)
561{
562      if (input_port_read(machine, "CONFIG") & 0x20)
563            return 0xff;
564      else
565            return nec765_data_r(machine, 0);
566}
567
568
569static  READ8_HANDLER(spectrum_plus3_port_2ffd_r)
570{
571      if (input_port_read(machine, "CONFIG") & 0x20)
572            return 0xff;
573      else
574            return nec765_status_r(machine, 0);
575}
576
577
578void spectrum_plus3_update_memory(running_machine *machine)
579{
580   if (spectrum_128_port_7ffd_data & 8)
581   {
582         logerror("+3 SCREEN 1: BLOCK 7\n");
583         spectrum_128_screen_location = spectrum_ram + (7<<14);
584   }
585   else
586   {
587         logerror("+3 SCREEN 0: BLOCK 5\n");
588         spectrum_128_screen_location = spectrum_ram + (5<<14);
589   }
590
591   if ((spectrum_plus3_port_1ffd_data & 0x01)==0)
592   {
593         int ram_page;
594         unsigned char *ram_data;
595
596         /* ROM switching */
597         unsigned char *ChosenROM;
598         int ROMSelection;
599
600         /* select ram at 0x0c000-0x0ffff */
601         ram_page = spectrum_128_port_7ffd_data & 0x07;
602         ram_data = spectrum_ram + (ram_page<<14);
603
604         memory_set_bankptr(4, ram_data);
605         memory_set_bankptr(8, ram_data);
606
607         logerror("RAM at 0xc000: %02x\n",ram_page);
608
609         /* Reset memory between 0x4000 - 0xbfff in case extended paging was being used */
610         /* Bank 5 in 0x4000 - 0x7fff */
611         memory_set_bankptr(2, spectrum_ram + (5<<14));
612         memory_set_bankptr(6, spectrum_ram + (5<<14));
613
614         /* Bank 2 in 0x8000 - 0xbfff */
615         memory_set_bankptr(3, spectrum_ram + (2<<14));
616         memory_set_bankptr(7, spectrum_ram + (2<<14));
617
618
619         ROMSelection = ((spectrum_128_port_7ffd_data>>4) & 0x01) |
620            ((spectrum_plus3_port_1ffd_data>>1) & 0x02);
621
622         /* rom 0 is editor, rom 1 is syntax, rom 2 is DOS, rom 3 is 48 BASIC */
623
624         ChosenROM = memory_region(REGION_CPU1) + 0x010000 + (ROMSelection<<14);
625
626         memory_set_bankptr(1, ChosenROM);
627         memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x3fff, 0, 0, SMH_UNMAP);
628
629         logerror("rom switch: %02x\n", ROMSelection);
630   }
631   else
632   {
633         /* Extended memory paging */
634
635         const int *memory_selection;
636         int MemorySelection;
637         unsigned char *ram_data;
638
639         MemorySelection = (spectrum_plus3_port_1ffd_data>>1) & 0x03;
640
641         memory_selection = &spectrum_plus3_memory_selections[(MemorySelection<<2)];
642
643         ram_data = spectrum_ram + (memory_selection[0]<<14);
644         memory_set_bankptr(1, ram_data);
645         memory_set_bankptr(5, ram_data);
646         /* allow writes to 0x0000-0x03fff */
647         memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x3fff, 0, 0, SMH_BANK5);
648
649         ram_data = spectrum_ram + (memory_selection[1]<<14);
650         memory_set_bankptr(2, ram_data);
651         memory_set_bankptr(6, ram_data);
652
653         ram_data = spectrum_ram + (memory_selection[2]<<14);
654         memory_set_bankptr(3, ram_data);
655         memory_set_bankptr(7, ram_data);
656
657         ram_data = spectrum_ram + (memory_selection[3]<<14);
658         memory_set_bankptr(4, ram_data);
659         memory_set_bankptr(8, ram_data);
660
661         logerror("extended memory paging: %02x\n",MemorySelection);
662      }
663}
664
665
666
667static WRITE8_HANDLER(spectrum_plus3_port_7ffd_w)
668{
669      /* D0-D2: RAM page located at 0x0c000-0x0ffff */
670      /* D3 - Screen select (screen 0 in ram page 5, screen 1 in ram page 7 */
671      /* D4 - ROM select - which rom paged into 0x0000-0x03fff */
672      /* D5 - Disable paging */
673
674      /* disable paging? */
675      if (spectrum_128_port_7ffd_data & 0x20)
676            return;
677
678      /* store new state */
679      spectrum_128_port_7ffd_data = data;
680
681      /* update memory */
682      spectrum_plus3_update_memory(machine);
683}
684
685static WRITE8_HANDLER(spectrum_plus3_port_1ffd_w)
686{
687
688      /* D0-D1: ROM/RAM paging */
689      /* D2: Affects if d0-d1 work on ram/rom */
690      /* D3 - Disk motor on/off */
691      /* D4 - parallel port strobe */
692
693      floppy_drive_set_motor_state(image_from_devtype_and_index(IO_FLOPPY, 0), data & (1<<3));
694      floppy_drive_set_motor_state(image_from_devtype_and_index(IO_FLOPPY, 1), data & (1<<3));
695      floppy_drive_set_ready_state(image_from_devtype_and_index(IO_FLOPPY, 0), 1, 1);
696      floppy_drive_set_ready_state(image_from_devtype_and_index(IO_FLOPPY, 1), 1, 1);
697
698      spectrum_plus3_port_1ffd_data = data;
699
700      /* disable paging? */
701      if ((spectrum_128_port_7ffd_data & 0x20)==0)
702      {
703            /* no */
704            spectrum_plus3_update_memory(machine);
705      }
706}
707
708/* decoding as per spectrum FAQ on www.worldofspectrum.org */
709static  READ8_HANDLER ( spectrum_plus3_port_r )
710{
711    if ((offset & 1)==0)
712    {
713       return spectrum_port_fe_r(machine, offset);
714    }
715
716    if ((offset & 2)==0)
717    {
718       switch ((offset>>14) & 0x03)
719       {
720         /* +3 fdc,memory,centronics */
721         case 0:
722         {
723            switch ((offset>>12) & 0x03)
724            {
725               /* +3 centronics */
726               case 0:
727                  break;
728
729               /* +3 fdc status */
730               case 2:
731                  return spectrum_plus3_port_2ffd_r(machine, offset);
732               /* +3 fdc data */
733               case 3:
734                  return spectrum_plus3_port_3ffd_r(machine, offset);
735
736               default:
737                  break;
738            }
739         }
740         break;
741
742         /* 128k AY data */
743         case 3:
744            return spectrum_128_port_fffd_r(machine, offset);
745
746         default:
747            break;
748       }
749    }
750
751    return video_screen_get_vpos(machine->primary_screen)<193 ? spectrum_128_screen_location[0x1800|(video_screen_get_vpos(machine->primary_screen)&0xf8)<<2]:0xff;
752}
753
754static WRITE8_HANDLER ( spectrum_plus3_port_w )
755{
756      if ((offset & 1)==0)
757            spectrum_port_fe_w(machine, offset, data);
758
759      /* the following is not decoded exactly, need to check
760        what is correct! */
761
762      if ((offset & 2)==0)
763      {
764         switch ((offset>>14) & 0x03)
765         {
766            /* +3 fdc,memory,centronics */
767            case 0:
768            {
769               switch ((offset>>12) & 0x03)
770               {
771                  /* +3 centronics */
772                  case 0:
773                  {
774
775
776                  }
777                  break;
778
779                  /* +3 memory */
780                  case 1:
781                     spectrum_plus3_port_1ffd_w(machine, offset, data);
782                     break;
783
784                  /* +3 fdc data */
785                  case 3:
786                     spectrum_plus3_port_3ffd_w(machine, offset, data);
787                     break;
788
789                  default:
790                     break;
791               }
792            }
793            break;
794
795            /* 128k memory */
796            case 1:
797               spectrum_plus3_port_7ffd_w(machine, offset, data);
798               break;
799
800            /* 128k AY data */
801            case 2:
802               spectrum_128_port_bffd_w(machine, offset, data);
803               break;
804
805            /* 128K AY register */
806            case 3:
807               spectrum_128_port_fffd_w(machine, offset, data);
808
809            default:
810               break;
811         }
812      }
813
814/*logerror("Write %02x to +3 port: %04x\n", data, offset); */
815}
816
817/* ports are not decoded full.
818The function decodes the ports appropriately */
819static ADDRESS_MAP_START (spectrum_plus3_io, ADDRESS_SPACE_IO, 8)
820      AM_RANGE(0x0000, 0xffff) AM_READWRITE( spectrum_plus3_port_r, spectrum_plus3_port_w )
821ADDRESS_MAP_END
822
823static MACHINE_RESET( spectrum_plus3 )
824{
825   spectrum_alloc_ram(128);
826
827   nec765_init(&spectrum_plus3_nec765_interface, NEC765A, NEC765_RDY_PIN_CONNECTED);
828
829   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 0), FLOPPY_DRIVE_SS_40);
830   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 1), FLOPPY_DRIVE_SS_40);
831
832   /* Initial configuration */
833   spectrum_128_port_7ffd_data = 0;
834   spectrum_plus3_port_1ffd_data = 0;
835   spectrum_plus3_update_memory(machine);
836
837   MACHINE_RESET_CALL(spectrum);
838}
839
840
841/****************************************************************************************************/
842/* TS2048 specific functions */
843
844
845int ts2068_port_ff_data = -1; /* Display enhancement control */
846int ts2068_port_f4_data = -1; /* Horizontal Select Register */
847
848static  READ8_HANDLER(ts2068_port_f4_r)
849{
850      return ts2068_port_f4_data;
851}
852
853static WRITE8_HANDLER(ts2068_port_f4_w)
854{
855      ts2068_port_f4_data = data;
856      ts2068_update_memory(machine);
857}
858
859static WRITE8_HANDLER(ts2068_port_f5_w)
860{
861      AY8910_control_port_0_w(machine, 0, data);
862}
863
864static  READ8_HANDLER(ts2068_port_f6_r)
865{
866      /* TODO - Reading from register 14 reads the joystick ports
867           set bit 8 of address to read joystick #1
868           set bit 9 of address to read joystick #2
869           if both bits are set then OR values
870           Bit 0 up, 1 down, 2 left, 3 right, 7 fire active low. Other bits 1
871        */
872      return AY8910_read_port_0_r(machine, 0);
873}
874
875static WRITE8_HANDLER(ts2068_port_f6_w)
876{
877      AY8910_write_port_0_w(machine, 0, data);
878}
879
880static  READ8_HANDLER(ts2068_port_ff_r)
881{
882      return ts2068_port_ff_data;
883}
884
885static WRITE8_HANDLER(ts2068_port_ff_w)
886{
887      /* Bits 0-2 Video Mode Select
888           Bits 3-5 64 column mode ink/paper selection
889                    (See ts2068_vh_screenrefresh for more info)
890           Bit  6   17ms Interrupt Inhibit
891           Bit  7   Cartridge (0) / EXROM (1) select
892        */
893      ts2068_port_ff_data = data;
894      ts2068_update_memory(machine);
895      logerror("Port %04x write %02x\n", offset, data);
896}
897
898
899static READ8_HANDLER ( ts2068_port_r )
900{
901   switch (offset & 0xff)
902   {
903      /* Note: keys only decoded on port #fe not all even ports so
904           ports #f4 & #f6 correctly read */
905      case 0xf4: return ts2068_port_f4_r(machine, offset);
906      case 0xf6: return ts2068_port_f6_r(machine, offset);
907      case 0xff: return ts2068_port_ff_r(machine, offset);
908
909      case 0xfe: return spectrum_port_fe_r(machine, offset);
910      case 0x1f: return spectrum_port_1f_r(machine, offset);
911      case 0x7f: return spectrum_port_7f_r(machine, offset);
912      case 0xdf: return spectrum_port_df_r(machine, offset);
913   }
914   logerror("Read from port: %04x\n", offset);
915
916   return 0xff;
917}
918
919static WRITE8_HANDLER ( ts2068_port_w )
920{
921/* Ports #fd & #fc were reserved by Timex for bankswitching and are not used
922   by either the hardware or system software.
923   Port #fb is the Thermal printer port and works exactly as the Sinclair
924   Printer - ie not yet emulated.
925*/
926   switch (offset & 0xff)
927   {
928      case 0xfe: spectrum_port_fe_w(machine, offset,data); break;
929      case 0xf4: ts2068_port_f4_w(machine, offset,data); break;
930      case 0xf5: ts2068_port_f5_w(machine, offset,data); break;
931      case 0xf6: ts2068_port_f6_w(machine, offset,data); break;
932      case 0xff: ts2068_port_ff_w(machine, offset,data); break;
933      default:
934            logerror("Write %02x to Port: %04x\n", data, offset);
935   }
936}
937
938
939
940/*******************************************************************
941 *
942 *      Bank switch between the 3 internal memory banks HOME, EXROM
943 *      and DOCK (Cartridges). The HOME bank contains 16K ROM in the
944 *      0-16K area and 48K RAM fills the rest. The EXROM contains 8K
945 *      ROM and can appear in every 8K segment (ie 0-8K, 8-16K etc).
946 *      The DOCK is empty and is meant to be occupied by cartridges
947 *      you can plug into the cartridge dock of the 2068.
948 *
949 *      The address space is divided into 8 8K chunks. Bit 0 of port
950 *      #f4 corresponds to the 0-8K chunk, bit 1 to the 8-16K chunk
951 *      etc. If the bit is 0 then the chunk is controlled by the HOME
952 *      bank. If the bit is 1 then the chunk is controlled by either
953 *      the DOCK or EXROM depending on bit 7 of port #ff. Note this
954 *      means that that the Z80 can't see chunks of the EXROM and DOCK
955 *      at the same time.
956 *
957 *******************************************************************/
958void ts2068_update_memory(running_machine *machine)
959{
960   unsigned char *ChosenROM, *ExROM, *DOCK;
961   read8_machine_func rh;
962   write8_machine_func wh;
963
964   DOCK = timex_cart_data;
965
966   ExROM = memory_region(REGION_CPU1) + 0x014000;
967
968   if (ts2068_port_f4_data & 0x01)
969   {
970      if (ts2068_port_ff_data & 0x80)
971      {
972            rh = SMH_BANK1;
973            wh = SMH_UNMAP;
974            memory_set_bankptr(1, ExROM);
975            logerror("0000-1fff EXROM\n");
976      }
977      else
978      {
979         if (timex_cart_type == TIMEX_CART_DOCK)
980         {
981            memory_set_bankptr(1, DOCK);
982            rh = SMH_BANK1;
983            if (timex_cart_chunks&0x01)
984               wh = SMH_BANK9;
985            else
986               wh = SMH_UNMAP;
987         }
988         else
989         {
990            rh = SMH_NOP;
991            wh = SMH_UNMAP;
992         }
993         logerror("0000-1fff Cartridge\n");
994      }
995   }
996   else
997   {
998      ChosenROM = memory_region(REGION_CPU1) + 0x010000;
999      memory_set_bankptr(1, ChosenROM);
1000      rh = SMH_BANK1;
1001      wh = SMH_UNMAP;
1002      logerror("0000-1fff HOME\n");
1003   }
1004   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x1fff, 0, 0, rh);
1005   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x1fff, 0, 0, wh);
1006
1007   if (ts2068_port_f4_data & 0x02)
1008   {
1009      if (ts2068_port_ff_data & 0x80)
1010      {
1011         memory_set_bankptr(2, ExROM);
1012         rh = SMH_BANK2;
1013         wh = SMH_UNMAP;
1014         logerror("2000-3fff EXROM\n");
1015      }
1016      else
1017      {
1018         if (timex_cart_type == TIMEX_CART_DOCK)
1019         {
1020            memory_set_bankptr(2, DOCK+0x2000);
1021            rh = SMH_BANK2;
1022            if (timex_cart_chunks&0x02)
1023               wh = SMH_BANK10;
1024            else
1025               wh = SMH_UNMAP;
1026         }
1027         else
1028         {
1029            rh = SMH_NOP;
1030            wh = SMH_UNMAP;
1031         }
1032         logerror("2000-3fff Cartridge\n");
1033      }
1034   }
1035   else
1036   {
1037      ChosenROM = memory_region(REGION_CPU1) + 0x012000;
1038      memory_set_bankptr(2, ChosenROM);
1039      rh = SMH_BANK2;
1040      wh = SMH_UNMAP;
1041      logerror("2000-3fff HOME\n");
1042   }
1043   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x2000, 0x3fff, 0, 0, rh);
1044   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x2000, 0x3fff, 0, 0, wh);
1045
1046   if (ts2068_port_f4_data & 0x04)
1047   {
1048      if (ts2068_port_ff_data & 0x80)
1049      {
1050         memory_set_bankptr(3, ExROM);
1051         rh = SMH_BANK3;
1052         wh = SMH_UNMAP;
1053         logerror("4000-5fff EXROM\n");
1054      }
1055      else
1056      {
1057         if (timex_cart_type == TIMEX_CART_DOCK)
1058         {
1059            memory_set_bankptr(3, DOCK+0x4000);
1060            rh = SMH_BANK3;
1061            if (timex_cart_chunks&0x04)
1062               wh = SMH_BANK11;
1063            else
1064               wh = SMH_UNMAP;
1065         }
1066         else
1067         {
1068            rh = SMH_NOP;
1069            wh = SMH_UNMAP;
1070         }
1071         logerror("4000-5fff Cartridge\n");
1072      }
1073   }
1074   else
1075   {
1076      memory_set_bankptr(3, mess_ram);
1077      memory_set_bankptr(11, mess_ram);
1078      rh = SMH_BANK3;
1079      wh = SMH_BANK11;
1080      logerror("4000-5fff RAM\n");
1081   }
1082   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x5fff, 0, 0, rh);
1083   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x5fff, 0, 0, wh);
1084
1085   if (ts2068_port_f4_data & 0x08)
1086   {
1087      if (ts2068_port_ff_data & 0x80)
1088      {
1089         memory_set_bankptr(4, ExROM);
1090         rh = SMH_BANK4;
1091         wh = SMH_UNMAP;
1092         logerror("6000-7fff EXROM\n");
1093      }
1094      else
1095      {
1096            if (timex_cart_type == TIMEX_CART_DOCK)
1097            {
1098               memory_set_bankptr(4, DOCK+0x6000);
1099               rh = SMH_BANK4;
1100               if (timex_cart_chunks&0x08)
1101                  wh = SMH_BANK12;
1102               else
1103                  wh = SMH_UNMAP;
1104            }
1105            else
1106            {
1107               rh = SMH_NOP;
1108               wh = SMH_UNMAP;
1109            }
1110            logerror("6000-7fff Cartridge\n");
1111      }
1112   }
1113   else
1114   {
1115      memory_set_bankptr(4, mess_ram + 0x2000);
1116      memory_set_bankptr(12, mess_ram + 0x2000);
1117      rh = SMH_BANK4;
1118      wh = SMH_BANK12;
1119      logerror("6000-7fff RAM\n");
1120   }
1121   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x6000, 0x7fff, 0, 0, rh);
1122   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x6000, 0x7fff, 0, 0, wh);
1123
1124   if (ts2068_port_f4_data & 0x10)
1125   {
1126      if (ts2068_port_ff_data & 0x80)
1127      {
1128         memory_set_bankptr(5, ExROM);
1129         rh = SMH_BANK5;
1130         wh = SMH_UNMAP;
1131         logerror("8000-9fff EXROM\n");
1132      }
1133      else
1134      {
1135         if (timex_cart_type == TIMEX_CART_DOCK)
1136         {
1137            memory_set_bankptr(5, DOCK+0x8000);
1138            rh = SMH_BANK5;
1139            if (timex_cart_chunks&0x10)
1140               wh = SMH_BANK13;
1141            else
1142               wh = SMH_UNMAP;
1143         }
1144         else
1145         {
1146            rh = SMH_NOP;
1147            wh = SMH_UNMAP;
1148         }
1149         logerror("8000-9fff Cartridge\n");
1150      }
1151   }
1152   else
1153   {
1154      memory_set_bankptr(5, mess_ram + 0x4000);
1155      memory_set_bankptr(13, mess_ram + 0x4000);
1156      rh = SMH_BANK5;
1157      wh = SMH_BANK13;
1158      logerror("8000-9fff RAM\n");
1159   }
1160   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x8000, 0x9fff, 0, 0,rh);
1161   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x8000, 0x9fff, 0, 0,wh);
1162
1163   if (ts2068_port_f4_data & 0x20)
1164   {
1165      if (ts2068_port_ff_data & 0x80)
1166      {
1167         memory_set_bankptr(6, ExROM);
1168         rh = SMH_BANK6;
1169         wh = SMH_UNMAP;
1170         logerror("a000-bfff EXROM\n");
1171      }
1172      else
1173      {
1174         if (timex_cart_type == TIMEX_CART_DOCK)
1175         {
1176            memory_set_bankptr(6, DOCK+0xa000);
1177            rh = SMH_BANK6;
1178            if (timex_cart_chunks&0x20)
1179               wh = SMH_BANK14;
1180            else
1181               wh = SMH_UNMAP;
1182         }
1183         else
1184         {
1185            rh = SMH_NOP;
1186            wh = SMH_UNMAP;
1187         }
1188         logerror("a000-bfff Cartridge\n");
1189      }
1190   }
1191   else
1192   {
1193      memory_set_bankptr(6, mess_ram + 0x6000);
1194      memory_set_bankptr(14, mess_ram + 0x6000);
1195      rh = SMH_BANK6;
1196      wh = SMH_BANK14;
1197      logerror("a000-bfff RAM\n");
1198   }
1199   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa000, 0xbfff, 0, 0, rh);
1200   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa000, 0xbfff, 0, 0, wh);
1201
1202   if (ts2068_port_f4_data & 0x40)
1203   {
1204      if (ts2068_port_ff_data & 0x80)
1205      {
1206         memory_set_bankptr(7, ExROM);
1207         rh = SMH_BANK7;
1208         wh = SMH_UNMAP;
1209         logerror("c000-dfff EXROM\n");
1210      }
1211      else
1212      {
1213         if (timex_cart_type == TIMEX_CART_DOCK)
1214         {
1215            memory_set_bankptr(7, DOCK+0xc000);
1216            rh = SMH_BANK7;
1217            if (timex_cart_chunks&0x40)
1218               wh = SMH_BANK15;
1219            else
1220               wh = SMH_UNMAP;
1221         }
1222         else
1223         {
1224            rh = SMH_NOP;
1225            wh = SMH_UNMAP;
1226         }
1227         logerror("c000-dfff Cartridge\n");
1228      }
1229   }
1230   else
1231   {
1232      memory_set_bankptr(7, mess_ram + 0x8000);
1233      memory_set_bankptr(15, mess_ram + 0x8000);
1234      rh = SMH_BANK7;
1235      wh = SMH_BANK15;
1236      logerror("c000-dfff RAM\n");
1237   }
1238   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xdfff, 0, 0, rh);
1239   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xdfff, 0, 0, wh);
1240
1241   if (ts2068_port_f4_data & 0x80)
1242   {
1243      if (ts2068_port_ff_data & 0x80)
1244      {
1245         memory_set_bankptr(8, ExROM);
1246         rh = SMH_BANK8;
1247         wh = SMH_UNMAP;
1248         logerror("e000-ffff EXROM\n");
1249      }
1250      else
1251      {
1252         if (timex_cart_type == TIMEX_CART_DOCK)
1253         {
1254            memory_set_bankptr(8, DOCK+0xe000);
1255            rh = SMH_BANK8;
1256            if (timex_cart_chunks&0x80)
1257               wh = SMH_BANK16;
1258            else
1259               wh = SMH_UNMAP;
1260         }
1261         else
1262         {
1263            rh = SMH_NOP;
1264            wh = SMH_UNMAP;
1265         }
1266         logerror("e000-ffff Cartridge\n");
1267      }
1268   }
1269   else
1270   {
1271      memory_set_bankptr(8, mess_ram + 0xa000);
1272      memory_set_bankptr(16, mess_ram + 0xa000);
1273      rh = SMH_BANK8;
1274      wh = SMH_BANK16;
1275      logerror("e000-ffff RAM\n");
1276   }
1277   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xe000, 0xffff, 0, 0, rh);
1278   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xe000, 0xffff, 0, 0, wh);
1279}
1280
1281
1282static ADDRESS_MAP_START (ts2068_io, ADDRESS_SPACE_IO, 8)
1283   AM_RANGE(0x0000, 0xffff) AM_READWRITE( ts2068_port_r, ts2068_port_w )
1284ADDRESS_MAP_END
1285
1286static ADDRESS_MAP_START (ts2068_mem, ADDRESS_SPACE_PROGRAM, 8)
1287   AM_RANGE(0x0000, 0x1fff) AM_READWRITE( SMH_BANK1, SMH_BANK9 )
1288   AM_RANGE(0x2000, 0x3fff) AM_READWRITE( SMH_BANK2, SMH_BANK10 )
1289   AM_RANGE(0x4000, 0x5fff) AM_READWRITE( SMH_BANK3, SMH_BANK11 )
1290   AM_RANGE(0x6000, 0x7fff) AM_READWRITE( SMH_BANK4, SMH_BANK12 )
1291   AM_RANGE(0x8000, 0x9fff) AM_READWRITE( SMH_BANK5, SMH_BANK13 )
1292   AM_RANGE(0xa000, 0xbfff) AM_READWRITE( SMH_BANK6, SMH_BANK14 )
1293   AM_RANGE(0xc000, 0xdfff) AM_READWRITE( SMH_BANK7, SMH_BANK15 )
1294   AM_RANGE(0xe000, 0xffff) AM_READWRITE( SMH_BANK8, SMH_BANK16 )
1295ADDRESS_MAP_END
1296
1297
1298static MACHINE_RESET( ts2068 )
1299{
1300   ts2068_port_ff_data = 0;
1301   ts2068_port_f4_data = 0;
1302   ts2068_update_memory(machine);
1303
1304   MACHINE_RESET_CALL(spectrum);
1305}
1306
1307
1308/****************************************************************************************************/
1309/* TC2048 specific functions */
1310
1311
1312static void tc2048_port_ff_w(int offset, int data)
1313{
1314      ts2068_port_ff_data = data;
1315      logerror("Port %04x write %02x\n", offset, data);
1316}
1317
1318static  READ8_HANDLER ( tc2048_port_r )
1319{
1320      if ((offset & 1)==0)
1321            return spectrum_port_fe_r(machine, offset);
1322      switch (offset & 0xff)
1323      {
1324            case 0xff: return ts2068_port_ff_r(machine, offset);
1325            case 0x1f: return spectrum_port_1f_r(machine, offset);
1326            case 0x7f: return spectrum_port_7f_r(machine, offset);
1327            case 0xdf: return spectrum_port_df_r(machine, offset);
1328      }
1329
1330      logerror("Read from port: %04x\n", offset);
1331      return 0xff;
1332}
1333
1334static WRITE8_HANDLER ( tc2048_port_w )
1335{
1336      if ((offset & 1)==0)
1337            spectrum_port_fe_w(machine, offset,data);
1338      else if ((offset & 0xff)==0xff)
1339            tc2048_port_ff_w(offset, data);
1340      else
1341      {
1342            logerror("Write %02x to Port: %04x\n", data, offset);
1343      }
1344}
1345
1346/* ports are not decoded full.
1347The function decodes the ports appropriately */
1348static ADDRESS_MAP_START (tc2048_io, ADDRESS_SPACE_IO, 8)
1349   AM_RANGE(0x0000, 0xffff) AM_READWRITE( tc2048_port_r, tc2048_port_w )
1350ADDRESS_MAP_END
1351
1352static ADDRESS_MAP_START (tc2048_mem, ADDRESS_SPACE_PROGRAM, 8)
1353   AM_RANGE( 0x0000, 0x3fff) AM_ROM
1354   AM_RANGE( 0x4000, 0xffff) AM_READWRITE( SMH_BANK1, SMH_BANK2 )
1355ADDRESS_MAP_END
1356
1357static MACHINE_RESET( tc2048 )
1358{
1359   memory_set_bankptr(1, mess_ram);
1360   memory_set_bankptr(2, mess_ram);
1361   ts2068_port_ff_data = 0;
1362
1363   MACHINE_RESET_CALL(spectrum);
1364}
1365
1366
1367/****************************************************************************************************/
1368/* BETADISK/TR-DOS disc controller emulation */
1369/* microcontroller KR1818VG93 is a russian wd179x clone */
1370#include "machine/wd17xx.h"
1371
1372/*
1373DRQ (D6) and INTRQ (D7).
1374DRQ - signal showing request of data by microcontroller
1375INTRQ - signal of completion of execution of command.
1376*/
1377
1378static int betadisk_status;
1379static int betadisk_active;
1380#ifdef UNUSED_FUNCTION
1381static void (*betadisk_memory_update)(void);
1382
1383static OPBASE_HANDLER(betadisk_opbase_handler)
1384{
1385
1386   int pc;
1387
1388   pc = activecpu_get_pc();
1389
1390   if ((pc & 0xc000)!=0x0000)
1391   {
1392      /* outside rom area */
1393      betadisk_active = 0;
1394
1395      betadisk_memory_update();
1396   }
1397   else
1398   {
1399      /* inside rom area, switch on betadisk */
1400   //  betadisk_active = 1;
1401
1402   //  betadisk_memory_update();
1403   }
1404
1405
1406   return pc & 0x0ffff;
1407}
1408#endif
1409
1410static void betadisk_wd179x_callback(running_machine *machine, wd17xx_state_t state, void *param)
1411{
1412   switch (state)
1413   {
1414      case WD17XX_DRQ_SET:
1415      {
1416         betadisk_status |= (1<<6);
1417      }
1418      break;
1419
1420      case WD17XX_DRQ_CLR:
1421      {
1422         betadisk_status &=~(1<<6);
1423      }
1424      break;
1425
1426      case WD17XX_IRQ_SET:
1427      {
1428         betadisk_status |= (1<<7);
1429      }
1430      break;
1431
1432      case WD17XX_IRQ_CLR:
1433      {
1434         betadisk_status &=~(1<<7);
1435      }
1436      break;
1437   }
1438}
1439
1440#ifdef UNUSED_FUNCTION
1441/* these are active only when betadisk is enabled */
1442static WRITE8_HANDLER(betadisk_w)
1443{
1444
1445   if (betadisk_active)
1446   {
1447
1448   }
1449}
1450
1451/* these are active only when betadisk is enabled */
1452static  READ8_HANDLER(betadisk_r)
1453{
1454   if (betadisk_active)
1455   {
1456      /* decoding of these ports might be wrong - to be checked! */
1457      if ((offset & 0x01f)==0x01f)
1458      {
1459         switch (offset & 0x0ff)
1460         {
1461
1462         }
1463      }
1464
1465   }
1466
1467   return 0x0ff;
1468}
1469#endif
1470
1471MACHINE_START( scorpion )
1472{
1473   betadisk_active = 0;
1474   betadisk_status = 0x03f;
1475   wd17xx_init(machine, WD_TYPE_179X, betadisk_wd179x_callback, NULL);
1476}
1477
1478/****************************************************************************************************/
1479/* Zs Scorpion 256 */
1480
1481/*
1482port 7ffd. full compatibility with Zx spectrum 128. digits are:
1483
1484D0-D2 - number of RAM page to put in C000-FFFF
1485D3    - switch of address for RAM of screen. 0 - 4000, 1 - c000
1486D4    - switch of ROM : 0-zx128, 1-zx48
1487D5    - 1 in this bit will block further output in port 7FFD, until reset.
1488*/
1489
1490/*
1491port 1ffd - additional port for resources of computer.
1492
1493D0    - block of ROM in 0-3fff. when set to 1 - allows read/write page 0 of RAM
1494D1    - selects ROM expansion. this rom contains main part of service monitor.
1495D2    - not used
1496D3    - used for output in RS-232C
1497D4    - extended RAM. set to 1 - connects RAM page with number 8-15 in
1498    C000-FFFF. number of page is given in gidits D0-D2 of port 7FFD
1499D5    - signal of strobe for interface centronics. to form the strobe has to be
1500    set to 1.
1501D6-D7 - not used. ( yet ? )
1502*/
1503
1504/* rom 0=zx128, 1=zx48, 2 = service monitor, 3=tr-dos */
1505
1506static int scorpion_256_port_1ffd_data = 0;
1507
1508static void scorpion_update_memory(running_machine *machine)
1509{
1510   unsigned char *ChosenROM;
1511   int ROMSelection;
1512   read8_machine_func rh;
1513   write8_machine_func wh;
1514
1515   if (spectrum_128_port_7ffd_data & 8)
1516   {
1517      logerror("SCREEN 1: BLOCK 7\n");
1518      spectrum_128_screen_location = spectrum_ram + (7<<14);
1519   }
1520   else
1521   {
1522      logerror("SCREEN 0: BLOCK 5\n");
1523      spectrum_128_screen_location = spectrum_ram + (5<<14);
1524   }
1525
1526   /* select ram at 0x0c000-0x0ffff */
1527   {
1528      int ram_page;
1529      unsigned char *ram_data;
1530
1531      ram_page = (spectrum_128_port_7ffd_data & 0x07) | ((scorpion_256_port_1ffd_data & (1<<4))>>1);
1532      ram_data = spectrum_ram + (ram_page<<14);
1533
1534      memory_set_bankptr(4, ram_data);
1535      memory_set_bankptr(8, ram_data);
1536
1537      logerror("RAM at 0xc000: %02x\n",ram_page);
1538   }
1539
1540   if (scorpion_256_port_1ffd_data & (1<<0))
1541   {
1542      /* ram at 0x0000 */
1543      logerror("RAM at 0x0000\n");
1544
1545      /* connect page 0 of ram to 0x0000 */
1546      rh = SMH_BANK1;
1547      wh = SMH_BANK5;
1548      memory_set_bankptr(1, spectrum_ram+(8<<14));
1549      memory_set_bankptr(5, spectrum_ram+(8<<14));
1550   }
1551   else
1552   {
1553      /* rom at 0x0000 */
1554      logerror("ROM at 0x0000\n");
1555
1556      /* connect page 0 of rom to 0x0000 */
1557      rh = SMH_BANK1;
1558      wh = SMH_NOP;
1559
1560      if (scorpion_256_port_1ffd_data & (1<<1))
1561      {
1562         ROMSelection = 2;
1563      }
1564      else
1565      {
1566
1567         /* ROM switching */
1568         ROMSelection = ((spectrum_128_port_7ffd_data>>4) & 0x01);
1569      }
1570
1571      /* rom 0 is 128K rom, rom 1 is 48 BASIC */
1572      ChosenROM = memory_region(REGION_CPU1) + 0x010000 + (ROMSelection<<14);
1573
1574      memory_set_bankptr(1, ChosenROM);
1575
1576      logerror("rom switch: %02x\n", ROMSelection);
1577   }
1578   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x3fff, 0, 0, rh);
1579   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x3fff, 0, 0, wh);
1580}
1581
1582
1583static WRITE8_HANDLER(scorpion_port_7ffd_w)
1584{
1585   logerror("scorpion 7ffd w: %02x\n", data);
1586
1587   /* disable paging? */
1588   if (spectrum_128_port_7ffd_data & 0x20)
1589      return;
1590
1591   /* store new state */
1592   spectrum_128_port_7ffd_data = data;
1593
1594   /* update memory */
1595   scorpion_update_memory(machine);
1596}
1597
1598static WRITE8_HANDLER(scorpion_port_1ffd_w)
1599{
1600   logerror("scorpion 1ffd w: %02x\n", data);
1601
1602   scorpion_256_port_1ffd_data = data;
1603
1604   /* disable paging? */
1605   if ((spectrum_128_port_7ffd_data & 0x20)==0)
1606   {
1607      scorpion_update_memory(machine);
1608   }
1609}
1610
1611
1612/* not sure if decoding is full or partial on scorpion */
1613/* TO BE CHECKED! */
1614static  READ8_HANDLER(scorpion_port_r)
1615{
1616    if ((offset & 1)==0)
1617    {
1618       return spectrum_port_fe_r(machine, offset);
1619    }
1620
1621    /* KT: the following is not decoded exactly, need to check what
1622     is correct */
1623    if ((offset & 2)==0)
1624    {
1625       switch ((offset>>8) & 0xff)
1626       {
1627            case 0xff: return spectrum_128_port_fffd_r(machine, offset);
1628            case 0x1f: return spectrum_port_1f_r(machine, offset);
1629            case 0x7f: return spectrum_port_7f_r(machine, offset);
1630            case 0xdf: return spectrum_port_df_r(machine, offset);
1631       }
1632    }
1633#if 0
1634    switch (offset & 0x0ff)
1635    {
1636      case 0x01f:
1637         return wd17xx_status_r(machine, offset);
1638      case 0x03f:
1639         return wd17xx_track_r(machine, offset);
1640      case 0x05f:
1641         return wd17xx_sector_r(machine, offset);
1642      case 0x07f:
1643         return wd17xx_data_r(machine, offset);
1644      case 0x0ff:
1645         return betadisk_status;
1646    }
1647#endif
1648    logerror("Read from scorpion port: %04x\n", offset);
1649
1650    return 0xff;
1651}
1652
1653
1654/* not sure if decoding is full or partial on scorpion */
1655/* TO BE CHECKED! */
1656static WRITE8_HANDLER(scorpion_port_w)
1657{
1658   if ((offset & 1)==0)
1659      spectrum_port_fe_w(machine, offset, data);
1660
1661   else if ((offset & 2)==0)
1662   {
1663         switch ((offset>>8) & 0xf0)
1664         {
1665            case 0x70:
1666                  scorpion_port_7ffd_w(machine, offset, data);
1667                  break;
1668            case 0xb0:
1669                  spectrum_128_port_bffd_w(machine, offset, data);
1670                  break;
1671            case 0xf0:
1672                  spectrum_128_port_fffd_w(machine, offset, data);
1673                  break;
1674            case 0x10:
1675                  scorpion_port_1ffd_w(machine, offset, data);
1676                  break;
1677            default:
1678                  logerror("Write %02x to scorpion port: %04x\n", data, offset);
1679         }
1680   }
1681   else
1682   {
1683      logerror("Write %02x to scorpion port: %04x\n", data, offset);
1684   }
1685}
1686
1687
1688
1689/* ports are not decoded full.
1690The function decodes the ports appropriately */
1691static ADDRESS_MAP_START (scorpion_io, ADDRESS_SPACE_IO, 8)
1692   AM_RANGE(0x0000, 0xffff) AM_READWRITE(scorpion_port_r, scorpion_port_w)
1693ADDRESS_MAP_END
1694
1695static MACHINE_RESET( scorpion )
1696{
1697   spectrum_alloc_ram(256);
1698
1699   /* Bank 5 is always in 0x4000 - 0x7fff */
1700   memory_set_bankptr(2, spectrum_ram + (5<<14));
1701   memory_set_bankptr(6, spectrum_ram + (5<<14));
1702
1703   /* Bank 2 is always in 0x8000 - 0xbfff */
1704   memory_set_bankptr(3, spectrum_ram + (2<<14));
1705   memory_set_bankptr(7, spectrum_ram + (2<<14));
1706
1707   spectrum_128_port_7ffd_data = 0;
1708   scorpion_256_port_1ffd_data = 0;
1709
1710   scorpion_update_memory(machine);
1711}
1712
1713/****************************************************************************************************/
1714/* pentagon */
1715
1716static  READ8_HANDLER(pentagon_port_r)
1717{
1718   return 0x0ff;
1719}
1720
1721
1722static WRITE8_HANDLER(pentagon_port_w)
1723{
1724}
1725
1726
1727
1728/* ports are not decoded full.
1729The function decodes the ports appropriately */
1730static ADDRESS_MAP_START (pentagon_io, ADDRESS_SPACE_IO, 8)
1731   AM_RANGE(0x0000, 0xffff) AM_READWRITE( pentagon_port_r, pentagon_port_w )
1732ADDRESS_MAP_END
1733
1734static MACHINE_RESET( pentagon )
1735{
1736   spectrum_alloc_ram(128);
1737
1738   /* Bank 5 is always in 0x4000 - 0x7fff */
1739   memory_set_bankptr(2, spectrum_ram + (5<<14));
1740   memory_set_bankptr(6, spectrum_ram + (5<<14));
1741
1742   /* Bank 2 is always in 0x8000 - 0xbfff */
1743   memory_set_bankptr(3, spectrum_ram + (2<<14));
1744   memory_set_bankptr(7, spectrum_ram + (2<<14));
1745}
1746
1747/****************************************************************************************************/
1748
1749static const gfx_layout spectrum_charlayout =
1750{
1751   8,8,
1752   256,
1753   1,                  /* 1 bits per pixel */
1754
1755   { 0 },               /* no bitplanes; 1 bit per pixel */
1756
1757   { 0, 1, 2, 3, 4, 5, 6, 7 },
1758   { 0, 8*256, 16*256, 24*256, 32*256, 40*256, 48*256, 56*256 },
1759
1760   8            /* every char takes 1 consecutive byte */
1761};
1762
1763327static GFXDECODE_START( spectrum )
1764328   GFXDECODE_ENTRY( 0, 0x0, spectrum_charlayout, 0, 0x80 )
1765329   GFXDECODE_ENTRY( 0, 0x0, spectrum_charlayout, 0, 0x80 )
1766330   GFXDECODE_ENTRY( 0, 0x0, spectrum_charlayout, 0, 0x80 )
1767331GFXDECODE_END
1768332
1769static INPUT_PORTS_START( spectrum )
333INPUT_PORTS_START( spectrum )
1770334   PORT_START_TAG("LINE0") /* [0] 0xFEFE */
1771335   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS SHIFT") PORT_CODE(KEYCODE_LSHIFT)
1772336   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Z  COPY    :      LN       BEEP") PORT_CODE(KEYCODE_Z)
r2516r2517
1892456   PORT_BIT(0x1f, IP_ACTIVE_LOW, IPT_UNUSED)
1893457INPUT_PORTS_END
1894458
1895#define ZX_COL_0   MAKE_RGB(0x00, 0x00, 0x00)
1896#define ZX_COL_1   MAKE_RGB(0x00, 0x00, 0xbf)
1897#define ZX_COL_2   MAKE_RGB(0xbf, 0x00, 0x00)
1898#define ZX_COL_3   MAKE_RGB(0xbf, 0x00, 0xbf)
1899#define ZX_COL_4   MAKE_RGB(0x00, 0xbf, 0x00)
1900#define ZX_COL_5   MAKE_RGB(0x00, 0xbf, 0xbf)
1901#define ZX_COL_6   MAKE_RGB(0xbf, 0xbf, 0x00)
1902#define ZX_COL_7   MAKE_RGB(0xbf, 0xbf, 0xbf)
1903#define ZX_COL_8   MAKE_RGB(0x00, 0x00, 0x00)
1904#define ZX_COL_9   MAKE_RGB(0x00, 0x00, 0xff)
1905#define ZX_COL_A   MAKE_RGB(0xff, 0x00, 0x00)
1906#define ZX_COL_B   MAKE_RGB(0xff, 0x00, 0xff)
1907#define ZX_COL_C   MAKE_RGB(0x00, 0xff, 0x00)
1908#define ZX_COL_D   MAKE_RGB(0x00, 0xff, 0xff)
1909#define ZX_COL_E   MAKE_RGB(0xff, 0xff, 0x00)
1910#define ZX_COL_F   MAKE_RGB(0xff, 0xff, 0xff)
1911459
1912const rgb_t spectrum_palette[256 + 16] = {
1913   ZX_COL_0,ZX_COL_1,ZX_COL_2,ZX_COL_3,ZX_COL_4,ZX_COL_5,ZX_COL_6,ZX_COL_7,ZX_COL_8,ZX_COL_9,ZX_COL_A,ZX_COL_B,ZX_COL_C,ZX_COL_D,ZX_COL_E,ZX_COL_F,
1914   
1915   ZX_COL_0,ZX_COL_0,ZX_COL_0,ZX_COL_1,ZX_COL_0,ZX_COL_2,ZX_COL_0,ZX_COL_3,ZX_COL_0,ZX_COL_4,ZX_COL_0,ZX_COL_5,ZX_COL_0,ZX_COL_6,ZX_COL_0,ZX_COL_7,
1916   ZX_COL_1,ZX_COL_0,ZX_COL_1,ZX_COL_1,ZX_COL_1,ZX_COL_2,ZX_COL_1,ZX_COL_3,ZX_COL_1,ZX_COL_4,ZX_COL_1,ZX_COL_5,ZX_COL_1,ZX_COL_6,ZX_COL_1,ZX_COL_7,
1917   ZX_COL_2,ZX_COL_0,ZX_COL_2,ZX_COL_1,ZX_COL_2,ZX_COL_2,ZX_COL_2,ZX_COL_3,ZX_COL_2,ZX_COL_4,ZX_COL_2,ZX_COL_5,ZX_COL_2,ZX_COL_6,ZX_COL_2,ZX_COL_7,   
1918   ZX_COL_3,ZX_COL_0,ZX_COL_3,ZX_COL_1,ZX_COL_3,ZX_COL_2,ZX_COL_3,ZX_COL_3,ZX_COL_3,ZX_COL_4,ZX_COL_3,ZX_COL_5,ZX_COL_3,ZX_COL_6,ZX_COL_3,ZX_COL_7,   
1919   ZX_COL_4,ZX_COL_0,ZX_COL_4,ZX_COL_1,ZX_COL_4,ZX_COL_2,ZX_COL_4,ZX_COL_3,ZX_COL_4,ZX_COL_4,ZX_COL_4,ZX_COL_5,ZX_COL_4,ZX_COL_6,ZX_COL_4,ZX_COL_7,   
1920   ZX_COL_5,ZX_COL_0,ZX_COL_5,ZX_COL_1,ZX_COL_5,ZX_COL_2,ZX_COL_5,ZX_COL_3,ZX_COL_5,ZX_COL_4,ZX_COL_5,ZX_COL_5,ZX_COL_5,ZX_COL_6,ZX_COL_5,ZX_COL_7,
1921   ZX_COL_6,ZX_COL_0,ZX_COL_6,ZX_COL_1,ZX_COL_6,ZX_COL_2,ZX_COL_6,ZX_COL_3,ZX_COL_6,ZX_COL_4,ZX_COL_6,ZX_COL_5,ZX_COL_6,ZX_COL_6,ZX_COL_6,ZX_COL_7,
1922   ZX_COL_7,ZX_COL_0,ZX_COL_7,ZX_COL_1,ZX_COL_7,ZX_COL_2,ZX_COL_7,ZX_COL_3,ZX_COL_7,ZX_COL_4,ZX_COL_7,ZX_COL_5,ZX_COL_7,ZX_COL_6,ZX_COL_7,ZX_COL_7,   
1923   ZX_COL_8,ZX_COL_8,ZX_COL_8,ZX_COL_9,ZX_COL_8,ZX_COL_A,ZX_COL_8,ZX_COL_B,ZX_COL_8,ZX_COL_C,ZX_COL_8,ZX_COL_D,ZX_COL_8,ZX_COL_E,ZX_COL_8,ZX_COL_F,
1924   ZX_COL_9,ZX_COL_8,ZX_COL_9,ZX_COL_9,ZX_COL_9,ZX_COL_A,ZX_COL_9,ZX_COL_B,ZX_COL_9,ZX_COL_C,ZX_COL_9,ZX_COL_D,ZX_COL_9,ZX_COL_E,ZX_COL_9,ZX_COL_F,
1925   ZX_COL_A,ZX_COL_8,ZX_COL_A,ZX_COL_9,ZX_COL_A,ZX_COL_A,ZX_COL_A,ZX_COL_B,ZX_COL_A,ZX_COL_C,ZX_COL_A,ZX_COL_D,ZX_COL_A,ZX_COL_E,ZX_COL_A,ZX_COL_F,   
1926   ZX_COL_B,ZX_COL_8,ZX_COL_B,ZX_COL_9,ZX_COL_B,ZX_COL_A,ZX_COL_B,ZX_COL_B,ZX_COL_B,ZX_COL_C,ZX_COL_B,ZX_COL_D,ZX_COL_B,ZX_COL_E,ZX_COL_B,ZX_COL_F,   
1927   ZX_COL_C,ZX_COL_8,ZX_COL_C,ZX_COL_9,ZX_COL_C,ZX_COL_A,ZX_COL_C,ZX_COL_B,ZX_COL_C,ZX_COL_C,ZX_COL_C,ZX_COL_D,ZX_COL_C,ZX_COL_E,ZX_COL_C,ZX_COL_F,   
1928   ZX_COL_D,ZX_COL_8,ZX_COL_D,ZX_COL_9,ZX_COL_D,ZX_COL_A,ZX_COL_D,ZX_COL_B,ZX_COL_D,ZX_COL_C,ZX_COL_D,ZX_COL_D,ZX_COL_D,ZX_COL_E,ZX_COL_D,ZX_COL_F,
1929   ZX_COL_E,ZX_COL_8,ZX_COL_E,ZX_COL_9,ZX_COL_E,ZX_COL_A,ZX_COL_E,ZX_COL_B,ZX_COL_E,ZX_COL_C,ZX_COL_E,ZX_COL_D,ZX_COL_E,ZX_COL_E,ZX_COL_E,ZX_COL_F,
1930   ZX_COL_F,ZX_COL_8,ZX_COL_F,ZX_COL_9,ZX_COL_F,ZX_COL_A,ZX_COL_F,ZX_COL_B,ZX_COL_F,ZX_COL_C,ZX_COL_F,ZX_COL_D,ZX_COL_F,ZX_COL_E,ZX_COL_F,ZX_COL_F
1931   };
1932
1933const rgb_t spectrum_128_palette[16] = {
1934   ZX_COL_0,ZX_COL_1,ZX_COL_2,ZX_COL_3,ZX_COL_4,ZX_COL_5,ZX_COL_6,ZX_COL_7,ZX_COL_8,ZX_COL_9,ZX_COL_A,ZX_COL_B,ZX_COL_C,ZX_COL_D,ZX_COL_E,ZX_COL_F
1935};
1936
1937/* Initialise the palette */
1938static PALETTE_INIT( spectrum )
1939{
1940   palette_set_colors(machine, 0, spectrum_palette, ARRAY_LENGTH(spectrum_palette));
1941}
1942
1943static PALETTE_INIT( spectrum_128 )
1944{   
1945   palette_set_colors(machine, 0, spectrum_128_palette, ARRAY_LENGTH(spectrum_128_palette));
1946}
1947
1948460static INTERRUPT_GEN( spec_interrupt )
1949461{
1950462   cpunum_set_input_line(machine, 0, 0, HOLD_LINE);
1951463}
1952464
1953
1954
1955static MACHINE_DRIVER_START( spectrum )
465MACHINE_DRIVER_START( spectrum )
1956466   /* basic machine hardware */
1957467   MDRV_CPU_ADD_TAG("main", Z80, 3500000)        /* 3.5 Mhz */
1958468   MDRV_CPU_PROGRAM_MAP(spectrum_mem, 0)
r2516r2517
1990500MACHINE_DRIVER_END
1991501
1992502
1993static MACHINE_DRIVER_START( spectrum_128 )
1994   MDRV_IMPORT_FROM( spectrum )
1995
1996   MDRV_CPU_REPLACE("main", Z80, 3500000)        /* 3.5 Mhz */
1997   MDRV_CPU_PROGRAM_MAP(spectrum_128_mem, 0)
1998   MDRV_CPU_IO_MAP(spectrum_128_io, 0)
1999
2000   MDRV_MACHINE_RESET( spectrum_128 )
2001
2002    /* video hardware */
2003   MDRV_SCREEN_MODIFY("main")
2004   MDRV_PALETTE_LENGTH(16)
2005   MDRV_PALETTE_INIT( spectrum_128 )
2006   MDRV_SCREEN_REFRESH_RATE(50.021)
2007   MDRV_VIDEO_START( spectrum_128 )
2008   MDRV_VIDEO_UPDATE( spectrum_128 )
2009
2010   /* sound hardware */
2011   MDRV_SOUND_ADD(AY8912, 1773400)
2012   MDRV_SOUND_CONFIG(spectrum_ay_interface)
2013   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
2014MACHINE_DRIVER_END
2015
2016
2017static MACHINE_DRIVER_START( spectrum_plus3 )
2018   MDRV_IMPORT_FROM( spectrum_128 )
2019   MDRV_CPU_MODIFY("main")
2020   MDRV_CPU_IO_MAP(spectrum_plus3_io, 0)
2021   MDRV_SCREEN_MODIFY("main")
2022   MDRV_SCREEN_REFRESH_RATE(50.01)
2023
2024   MDRV_MACHINE_RESET( spectrum_plus3 )
2025MACHINE_DRIVER_END
2026
2027
2028static MACHINE_DRIVER_START( ts2068 )
2029   MDRV_IMPORT_FROM( spectrum_128 )
2030   MDRV_CPU_REPLACE("main", Z80, 3580000)        /* 3.58 Mhz */
2031   MDRV_CPU_PROGRAM_MAP(ts2068_mem, 0)
2032   MDRV_CPU_IO_MAP(ts2068_io, 0)
2033
2034   MDRV_MACHINE_RESET( ts2068 )
2035
2036    /* video hardware */
2037   MDRV_SCREEN_MODIFY("main")
2038   MDRV_SCREEN_REFRESH_RATE(60)
2039   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
2040   MDRV_SCREEN_SIZE(TS2068_SCREEN_WIDTH, TS2068_SCREEN_HEIGHT)
2041   MDRV_SCREEN_VISIBLE_AREA(0, TS2068_SCREEN_WIDTH-1, 0, TS2068_SCREEN_HEIGHT-1)
2042
2043   MDRV_VIDEO_UPDATE( ts2068 )
2044   MDRV_VIDEO_EOF( ts2068 )
2045MACHINE_DRIVER_END
2046
2047
2048static MACHINE_DRIVER_START( uk2086 )
2049   MDRV_IMPORT_FROM( ts2068 )
2050   MDRV_SCREEN_MODIFY("main")
2051   MDRV_SCREEN_REFRESH_RATE(50)
2052MACHINE_DRIVER_END
2053
2054
2055static MACHINE_DRIVER_START( tc2048 )
2056   MDRV_IMPORT_FROM( spectrum )
2057   MDRV_CPU_MODIFY("main")
2058   MDRV_CPU_PROGRAM_MAP(tc2048_mem, 0)
2059   MDRV_CPU_IO_MAP(tc2048_io, 0)
2060
2061   MDRV_SCREEN_MODIFY("main")
2062   MDRV_SCREEN_REFRESH_RATE(50)
2063
2064   MDRV_MACHINE_RESET( tc2048 )
2065
2066    /* video hardware */
2067   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
2068   MDRV_SCREEN_SIZE(TS2068_SCREEN_WIDTH, SPEC_SCREEN_HEIGHT)
2069   MDRV_SCREEN_VISIBLE_AREA(0, TS2068_SCREEN_WIDTH-1, 0, SPEC_SCREEN_HEIGHT-1)
2070
2071   MDRV_VIDEO_START( spectrum_128 )
2072   MDRV_VIDEO_UPDATE( tc2048 )
2073MACHINE_DRIVER_END
2074
2075
2076static MACHINE_DRIVER_START( scorpion )
2077   MDRV_IMPORT_FROM( spectrum_128 )
2078   MDRV_CPU_MODIFY("main")
2079   MDRV_CPU_IO_MAP(scorpion_io, 0)
2080   MDRV_MACHINE_START( scorpion )
2081   MDRV_MACHINE_RESET( scorpion )
2082MACHINE_DRIVER_END
2083
2084
2085static MACHINE_DRIVER_START( pentagon )
2086   MDRV_IMPORT_FROM( spectrum_128 )
2087   MDRV_CPU_MODIFY("main")
2088   MDRV_CPU_IO_MAP(pentagon_io, 0)
2089   MDRV_MACHINE_START( scorpion )
2090   MDRV_MACHINE_RESET( pentagon )
2091MACHINE_DRIVER_END
2092
2093
2094503/***************************************************************************
2095504
2096505  Game driver(s)
r2516r2517
2133542   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2134543ROM_END
2135544
2136ROM_START(spec128)
2137   ROM_REGION(0x18000,REGION_CPU1,0)
2138   ROM_LOAD("zx128_0.rom",0x10000,0x4000, CRC(e76799d2) SHA1(4f4b11ec22326280bdb96e3baf9db4b4cb1d02c5))
2139   ROM_LOAD("zx128_1.rom",0x14000,0x4000, CRC(b96a36be) SHA1(80080644289ed93d71a1103992a154cc9802b2fa))
2140   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2141ROM_END
2142545
2143ROM_START(spec128s)
2144   ROM_REGION(0x18000,REGION_CPU1,0)
2145   ROM_LOAD("zx128s0.rom",0x10000,0x4000, CRC(453d86b2) SHA1(968937b1c750f0ef6205f01c6db4148da4cca4e3))
2146   ROM_LOAD("zx128s1.rom",0x14000,0x4000, CRC(6010e796) SHA1(bea3f397cc705eafee995ea629f4a82550562f90))
2147   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2148ROM_END
2149
2150ROM_START(specpls2)
2151   ROM_REGION(0x18000,REGION_CPU1,0)
2152   ROM_LOAD("zxp2_0.rom",0x10000,0x4000, CRC(5d2e8c66) SHA1(72703f9a3e734f3c23ec34c0727aae4ccbef9a91))
2153   ROM_LOAD("zxp2_1.rom",0x14000,0x4000, CRC(98b1320b) SHA1(de8b0d2d0379cfe7c39322a086ca6da68c7f23cb))
2154   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2155ROM_END
2156
2157ROM_START(specpl2a)
2158   ROM_REGION(0x20000,REGION_CPU1,0)
2159   ROM_LOAD("p2a41_0.rom",0x10000,0x4000, CRC(30c9f490) SHA1(62ec15a4af56cd1d206d0bd7011eac7c889a595d))
2160   ROM_LOAD("p2a41_1.rom",0x14000,0x4000, CRC(a7916b3f) SHA1(1a7812c383a3701e90e88d1da086efb0c033ac72))
2161   ROM_LOAD("p2a41_2.rom",0x18000,0x4000, CRC(c9a0b748) SHA1(8df145d10ff78f98138682ea15ebccb2874bf759))
2162   ROM_LOAD("p2a41_3.rom",0x1c000,0x4000, CRC(b88fd6e3) SHA1(be365f331942ec7ec35456b641dac56a0dbfe1f0))
2163   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2164ROM_END
2165
2166ROM_START(specpls3)
2167   ROM_REGION(0x20000,REGION_CPU1,0)
2168   ROM_LOAD("pl3-0.rom",0x10000,0x4000, CRC(17373da2) SHA1(e319ed08b4d53a5e421a75ea00ea02039ba6555b))
2169   ROM_LOAD("pl3-1.rom",0x14000,0x4000, CRC(f1d1d99e) SHA1(c9969fc36095a59787554026a9adc3b87678c794))
2170   ROM_LOAD("pl3-2.rom",0x18000,0x4000, CRC(3dbf351d) SHA1(22e50c6ba4157a3f6a821bd9937cd26e292775c6))
2171   ROM_LOAD("pl3-3.rom",0x1c000,0x4000, CRC(04448eaa) SHA1(65f031caa8148a5493afe42c41f4929deab26b4e))
2172   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2173ROM_END
2174
2175546ROM_START(specpls4)
2176547   ROM_REGION(0x10000,REGION_CPU1,0)
2177548   ROM_LOAD("plus4.rom",0x0000,0x4000, CRC(7e0f47cb) SHA1(c103e89ef58e6ade0c01cea0247b332623bd9a30))
r2516r2517
2196567   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2197568ROM_END
2198569
2199ROM_START(tc2048)
2200   ROM_REGION(0x10000,REGION_CPU1,0)
2201   ROM_LOAD("tc2048.rom",0x0000,0x4000, CRC(f1b5fa67) SHA1(febb2d495b6eda7cdcb4074935d6e9d9f328972d))
2202   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2203ROM_END
2204570
2205ROM_START(ts2068)
2206   ROM_REGION(0x16000,REGION_CPU1,0)
2207   ROM_LOAD("ts2068_h.rom",0x10000,0x4000, CRC(bf44ec3f) SHA1(1446cb2780a9dedf640404a639fa3ae518b2d8aa))
2208   ROM_LOAD("ts2068_x.rom",0x14000,0x2000, CRC(ae16233a) SHA1(7e265a2c1f621ed365ea23bdcafdedbc79c1299c))
2209ROM_END
2210
2211ROM_START(uk2086)
2212   ROM_REGION(0x16000,REGION_CPU1,0)
2213   ROM_LOAD("uk2086_h.rom",0x10000,0x4000, CRC(5ddc0ca2) SHA1(1d525fe5cdc82ab46767f665ad735eb5363f1f51))
2214   ROM_LOAD("ts2068_x.rom",0x14000,0x2000, CRC(ae16233a) SHA1(7e265a2c1f621ed365ea23bdcafdedbc79c1299c))
2215ROM_END
2216
2217ROM_START(specp2fr)
2218   ROM_REGION(0x18000,REGION_CPU1,0)
2219   ROM_LOAD("plus2fr0.rom",0x10000,0x4000, CRC(c684c535) SHA1(56684c4c85a616e726a50707483b9a42d8e724ed))
2220   ROM_LOAD("plus2fr1.rom",0x14000,0x4000, CRC(f5e509c5) SHA1(7e398f62689c9d90a36d3a101351ec9987207308))
2221   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2222ROM_END
2223
2224ROM_START(specp2sp)
2225   ROM_REGION(0x18000,REGION_CPU1,0)
2226   ROM_LOAD("plus2sp0.rom",0x10000,0x4000, CRC(e807d06e) SHA1(8259241b28ff85441f1bedc2bee53445767c51c5))
2227   ROM_LOAD("plus2sp1.rom",0x14000,0x4000, CRC(41981d4b) SHA1(ec0d5a158842d20601b4fbeaefc6668db979d0e1))
2228   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2229ROM_END
2230
2231ROM_START(specp3sp)
2232   ROM_REGION(0x20000,REGION_CPU1,0)
2233   ROM_LOAD("plus3sp0.rom",0x10000,0x4000, CRC(1f86147a) SHA1(e9b0a60a1a8def511d59090b945d175bdc646346))
2234   ROM_LOAD("plus3sp1.rom",0x14000,0x4000, CRC(a8ac4966) SHA1(4e48f196427596c7990c175d135c15a039c274a4))
2235   ROM_LOAD("plus3sp2.rom",0x18000,0x4000, CRC(f6bb0296) SHA1(09fc005625589ef5992515957ce7a3167dec24b2))
2236   ROM_LOAD("plus3sp3.rom",0x1c000,0x4000, CRC(f6d25389) SHA1(ec8f644a81e2e9bcb58ace974103ea960361bad2))
2237   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2238ROM_END
2239
2240ROM_START(specpl3e)
2241   ROM_REGION(0x20000,REGION_CPU1,0)
2242   ROM_LOAD("roma-en.rom",0x10000,0x8000, CRC(2d533344) SHA1(5ff2dae32eb745d87e0b54c595d1d20a866f316f))
2243   ROM_LOAD("romb-en.rom",0x18000,0x8000, CRC(ef8d5d92) SHA1(983aa53aa76e25a3af123c896016bacf6829b72b))
2244   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2245ROM_END
2246
2247ROM_START(specp3es)
2248   ROM_REGION(0x20000,REGION_CPU1,0)
2249   ROM_LOAD("roma-es.rom",0x10000,0x8000, CRC(ba694b4b) SHA1(d15d9e43950483cffc79f1cfa89ecb114a88f6c2))
2250   ROM_LOAD("romb-es.rom",0x18000,0x8000, CRC(61ed94db) SHA1(935b14c13db75d872de8ad0d591aade0adbbc355))
2251   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2252ROM_END
2253
2254ROM_START(scorpion)
2255   ROM_REGION(0x020000, REGION_CPU1, 0)
2256   ROM_LOAD("scorp0.rom",0x010000, 0x4000, CRC(0eb40a09))
2257   ROM_LOAD("scorp1.rom",0x014000, 0x4000, CRC(9d513013))
2258   ROM_LOAD("scorp2.rom",0x018000, 0x4000, CRC(fd0d3ce1))
2259   ROM_LOAD("scorp3.rom",0x01c000, 0x4000, CRC(1fe1d003))
2260   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2261ROM_END
2262
2263ROM_START(pentagon)
2264   ROM_REGION(0x020000, REGION_CPU1, 0)
2265   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
2266ROM_END
2267
2268571static void spectrum_common_cassette_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
2269572{
2270573   /* cassette */
r2516r2517
2287590   CONFIG_DEVICE(cartslot_device_getinfo)
2288591SYSTEM_CONFIG_END
2289592
2290static void specpls3_floppy_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
2291{
2292   /* floppy */
2293   switch(state)
2294   {
2295      /* --- the following bits of info are returned as 64-bit signed integers --- */
2296      case MESS_DEVINFO_INT_COUNT:                     info->i = 2; break;
2297
2298      default:                              legacydsk_device_getinfo(devclass, state, info); break;
2299   }
2300}
2301
2302SYSTEM_CONFIG_START(specpls3)
2303   CONFIG_IMPORT_FROM(spectrum_common)
2304   CONFIG_DEVICE(specpls3_floppy_getinfo)
2305SYSTEM_CONFIG_END
2306
2307static void ts2068_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
2308{
2309   /* cartslot */
2310   switch(state)
2311   {
2312      /* --- the following bits of info are returned as 64-bit signed integers --- */
2313      case MESS_DEVINFO_INT_COUNT:                     info->i = 1; break;
2314
2315      /* --- the following bits of info are returned as pointers to data or functions --- */
2316      case MESS_DEVINFO_PTR_LOAD:                     info->load = DEVICE_IMAGE_LOAD_NAME(timex_cart); break;
2317      case MESS_DEVINFO_PTR_UNLOAD:                  info->unload = DEVICE_IMAGE_UNLOAD_NAME(timex_cart); break;
2318
2319      /* --- the following bits of info are returned as NULL-terminated strings --- */
2320      case MESS_DEVINFO_STR_FILE_EXTENSIONS:            strcpy(info->s = device_temp_str(), "dck"); break;
2321
2322      default:                              cartslot_device_getinfo(devclass, state, info); break;
2323   }
2324}
2325
2326SYSTEM_CONFIG_START(ts2068)
2327   CONFIG_IMPORT_FROM(spectrum_common)
2328   CONFIG_DEVICE(ts2068_cartslot_getinfo)
2329   CONFIG_RAM_DEFAULT(48 * 1024)
2330SYSTEM_CONFIG_END
2331
2332SYSTEM_CONFIG_START(tc2048)
2333   CONFIG_IMPORT_FROM(spectrum)
2334   CONFIG_RAM_DEFAULT(48 * 1024)
2335SYSTEM_CONFIG_END
2336
2337593/*    YEAR  NAME      PARENT    COMPAT  MACHINE     INPUT       INIT    CONFIG      COMPANY     FULLNAME */
2338594COMP( 1982, spectrum, 0,        0,      spectrum,      spectrum,   0,      spectrum,   "Sinclair Research",   "ZX Spectrum" , 0)
2339595COMP( 2000, specpls4, spectrum, 0,      spectrum,      spectrum,   0,      spectrum,   "Sinclair Research",   "ZX Spectrum +4", GAME_COMPUTER_MODIFIED )
r2516r2517
2345601COMP( 1986, inves,    spectrum, 0,      spectrum,      spectrum,   0,      spectrum,   "Investronica",   "Inves Spectrum 48K+" , 0)
2346602COMP( 1985, tk90x,    spectrum, 0,      spectrum,      spectrum,   0,      spectrum,   "Micro Digital",   "TK-90x Color Computer" , 0)
2347603COMP( 1986, tk95,     spectrum, 0,      spectrum,      spectrum,   0,      spectrum,   "Micro Digital",   "TK-95 Color Computer" , 0)
2348COMP( 1984, tc2048,   spectrum, 0,      tc2048,         spectrum,   0,      tc2048,      "Timex of Portugal",   "TC-2048" , 0)
2349COMP( 1983, ts2068,   spectrum, 0,      ts2068,         spectrum,   0,      ts2068,      "Timex Sinclair",   "TS-2068" , 0)
2350COMP( 1986, uk2086,   spectrum, 0,      uk2086,         spectrum,   0,      ts2068,      "Unipolbrit",   "UK-2086 ver. 1.2" , 0)
2351
2352COMP( 1986, spec128,  0,       0,      spectrum_128,   spectrum,   0,      spectrum,   "Sinclair Research",    "ZX Spectrum 128" , 0 )
2353COMP( 1985, spec128s, spec128,  0,      spectrum_128,   spectrum,   0,      spectrum,   "Sinclair Research",    "ZX Spectrum 128 (Spain)" , 0 )
2354COMP( 1986, specpls2, spec128,  0,      spectrum_128,   spectrum,   0,      spectrum,   "Amstrad plc",          "ZX Spectrum +2" , 0 )
2355COMP( 1987, specpl2a, spec128,  0,      spectrum_plus3,spectrum,   0,      specpls3,   "Amstrad plc",          "ZX Spectrum +2a" , 0 )
2356COMP( 1987, specpls3, spec128,  0,      spectrum_plus3,spectrum,   0,      specpls3,   "Amstrad plc",          "ZX Spectrum +3" , 0 )
2357
2358COMP( 1986, specp2fr, spec128,  0,      spectrum_128,   spectrum,   0,      spectrum,   "Amstrad plc",          "ZX Spectrum +2 (France)" , 0 )
2359COMP( 1986, specp2sp, spec128,  0,      spectrum_128,   spectrum,   0,      spectrum,   "Amstrad plc",          "ZX Spectrum +2 (Spain)" , 0 )
2360COMP( 1987, specp3sp, spec128,  0,      spectrum_plus3,spectrum,   0,      specpls3,   "Amstrad plc",          "ZX Spectrum +3 (Spain)" , 0 )
2361COMP( 2000, specpl3e, spec128,  0,      spectrum_plus3,spectrum,   0,      specpls3,   "Amstrad plc",          "ZX Spectrum +3e" , GAME_COMPUTER_MODIFIED )
2362COMP( 2000, specp3es, spec128,  0,      spectrum_plus3,spectrum,   0,      specpls3,   "Amstrad plc",          "ZX Spectrum +3e (Spain)" , GAME_COMPUTER_MODIFIED )
2363
2364COMP( ????, scorpion, 0,       0,      scorpion,      spectrum,   0,      specpls3,   "Zonov and Co.",      "Zs Scorpion 256", 0 )
2365COMP( ????, pentagon, spectrum, 0,      pentagon,      spectrum,   0,      specpls3,   "???",      "Pentagon", GAME_NOT_WORKING)
src/mess/drivers/spec128.c
r0r2517
1/***************************************************************************
2
3   NOTE: ****** Specbusy: press N, R, or E to boot *************
4
5
6        Spectrum/Inves/TK90X etc. memory map:
7
8    CPU:
9        0000-3fff ROM
10        4000-ffff RAM
11
12        Spectrum 128/+2/+2a/+3 memory map:
13
14        CPU:
15                0000-3fff Banked ROM/RAM (banked rom only on 128/+2)
16                4000-7fff Banked RAM
17                8000-bfff Banked RAM
18                c000-ffff Banked RAM
19
20        TS2068 memory map: (Can't have both EXROM and DOCK active)
21        The 8K EXROM can be loaded into multiple pages.
22
23    CPU:
24                0000-1fff     ROM / EXROM / DOCK (Cartridge)
25                2000-3fff     ROM / EXROM / DOCK
26                4000-5fff \
27                6000-7fff  \
28                8000-9fff  |- RAM / EXROM / DOCK
29                a000-bfff  |
30                c000-dfff  /
31                e000-ffff /
32
33
34Interrupts:
35
36Changes:
37
3829/1/2000   KT -    Implemented initial +3 emulation.
3930/1/2000   KT -    Improved input port decoding for reading and therefore
40            correct keyboard handling for Spectrum and +3.
4131/1/2000   KT -    Implemented buzzer sound for Spectrum and +3.
42            Implementation copied from Paul Daniel's Jupiter driver.
43            Fixed screen display problems with dirty chars.
44            Added support to load .Z80 snapshots. 48k support so far.
4513/2/2000   KT -    Added Interface II, Kempston, Fuller and Mikrogen
46            joystick support.
4717/2/2000   DJR -   Added full key descriptions and Spectrum+ keys.
48            Fixed Spectrum +3 keyboard problems.
4917/2/2000   KT -    Added tape loading from WAV/Changed from DAC to generic
50            speaker code.
5118/2/2000   KT -    Added tape saving to WAV.
5227/2/2000   KT -    Took DJR's changes and added my changes.
5327/2/2000   KT -    Added disk image support to Spectrum +3 driver.
5427/2/2000   KT -    Added joystick I/O code to the Spectrum +3 I/O handler.
5514/3/2000   DJR -   Tape handling dipswitch.
5626/3/2000   DJR -   Snapshot files are now classifed as snapshots not
57            cartridges.
5804/4/2000   DJR -   Spectrum 128 / +2 Support.
5913/4/2000   DJR -   +4 Support (unofficial 48K hack).
6013/4/2000   DJR -   +2a Support (rom also used in +3 models).
6113/4/2000   DJR -   TK90X, TK95 and Inves support (48K clones).
6221/4/2000   DJR -   TS2068 and TC2048 support (TC2048 Supports extra video
63            modes but doesn't have bank switching or sound chip).
6409/5/2000   DJR -   Spectrum +2 (France, Spain), +3 (Spain).
6517/5/2000   DJR -   Dipswitch to enable/disable disk drives on +3 and clones.
6627/6/2000   DJR -   Changed 128K/+3 port decoding (sound now works in Zub 128K).
6706/8/2000   DJR -   Fixed +3 Floppy support
6810/2/2001   KT  -   Re-arranged code and split into each model emulated.
69            Code is split into 48k, 128k, +3, tc2048 and ts2048
70            segments. 128k uses some of the functions in 48k, +3
71            uses some functions in 128, and tc2048/ts2048 use some
72            of the functions in 48k. The code has been arranged so
73            these functions come in some kind of "override" order,
74            read functions changed to use  READ8_HANDLER and write
75            functions changed to use WRITE8_HANDLER.
76            Added Scorpion256 preliminary.
7718/6/2001   DJR -   Added support for Interface 2 cartridges.
78xx/xx/2001  KS -    TS-2068 sound fixed.
79            Added support for DOCK cartridges for TS-2068.
80            Added Spectrum 48k Psycho modified rom driver.
81            Added UK-2086 driver.
8223/12/2001  KS -    48k machines are now able to run code in screen memory.
83                Programs which keep their code in screen memory
84                like monitors, tape copiers, decrunchers, etc.
85                works now.
86                Fixed problem with interrupt vector set to 0xffff (much
87            more 128k games works now).
88                A useful used trick on the Spectrum is to set
89                interrupt vector to 0xffff (using the table
90                which contain 0xff's) and put a byte 0x18 hex,
91                the opcode for JR, at this address. The first
92                byte of the ROM is a 0xf3 (DI), so the JR will
93                jump to 0xfff4, where a long JP to the actual
94                interrupt routine is put. Due to unideal
95                bankswitching in MAME this JP were to 0001 what
96                causes Spectrum to reset. Fixing this problem
97                made much more software runing (i.e. Paperboy).
98            Corrected frames per second value for 48k and 128k
99            Sincalir machines.
100                There are 50.08 frames per second for Spectrum
101                48k what gives 69888 cycles for each frame and
102                50.021 for Spectrum 128/+2/+2A/+3 what gives
103                70908 cycles for each frame.
104            Remaped some Spectrum+ keys.
105                Presing F3 to reset was seting 0xf7 on keyboard
106                input port. Problem occured for snapshots of
107                some programms where it was readed as pressing
108                key 4 (which is exit in Tapecopy by R. Dannhoefer
109                for example).
110            Added support to load .SP snapshots.
111            Added .BLK tape images support.
112                .BLK files are identical to .TAP ones, extension
113                is an only difference.
11408/03/2002  KS -    #FF port emulation added.
115                Arkanoid works now, but is not playable due to
116                completly messed timings.
117
118Initialisation values used when determining which model is being emulated:
119 48K        Spectrum doesn't use either port.
120 128K/+2    Bank switches with port 7ffd only.
121 +3/+2a     Bank switches with both ports.
122
123Notes:
124 1. No contented memory.
125 2. No hi-res colour effects (need contended memory first for accurate timing).
126 3. Multiface 1 and Interface 1 not supported.
127 4. Horace and the Spiders cartridge doesn't run properly.
128 5. Tape images not supported:
129    .TZX, .SPC, .ITM, .PAN, .TAP(Warajevo), .VOC, .ZXS.
130 6. Snapshot images not supported:
131    .ACH, .PRG, .RAW, .SEM, .SIT, .SNX, .ZX, .ZXS, .ZX82.
132 7. 128K emulation is not perfect - the 128K machines crash and hang while
133    running quite a lot of games.
134 8. Disk errors occur on some +3 games.
135 9. Video hardware of all machines is timed incorrectly.
13610. EXROM and HOME cartridges are not emulated.
13711. The TK90X and TK95 roms output 0 to port #df on start up.
13812. The purpose of this port is unknown (probably display mode as TS2068) and
139    thus is not emulated.
140
141Very detailed infos about the ZX Spectrum +3e can be found at
142
143http://www.z88forever.org.uk/zxplus3e/
144
145*******************************************************************************/
146
147#include "driver.h"
148#include "includes/spectrum.h"
149#include "eventlst.h"
150#include "devices/snapquik.h"
151#include "devices/cartslot.h"
152#include "devices/cassette.h"
153#include "sound/ay8910.h"
154#include "sound/speaker.h"
155#include "formats/tzx_cas.h"
156
157static const struct AY8910interface spectrum_ay_interface =
158{
159   AY8910_LEGACY_OUTPUT,
160   AY8910_DEFAULT_LOADS,
161   NULL
162};
163
164/****************************************************************************************************/
165/* Spectrum 128 specific functions */
166
167int spectrum_128_port_7ffd_data = -1;
168unsigned char *spectrum_128_screen_location = NULL;
169
170static WRITE8_HANDLER(spectrum_128_port_7ffd_w)
171{
172   /* D0-D2: RAM page located at 0x0c000-0x0ffff */
173   /* D3 - Screen select (screen 0 in ram page 5, screen 1 in ram page 7 */
174   /* D4 - ROM select - which rom paged into 0x0000-0x03fff */
175   /* D5 - Disable paging */
176
177   /* disable paging? */
178   if (spectrum_128_port_7ffd_data & 0x20)
179         return;
180
181   /* store new state */
182   spectrum_128_port_7ffd_data = data;
183
184   /* update memory */
185   spectrum_128_update_memory(machine);
186}
187
188void spectrum_128_update_memory(running_machine *machine)
189{
190   unsigned char *ChosenROM;
191   int ROMSelection;
192
193   if (spectrum_128_port_7ffd_data & 8)
194   {
195         logerror("SCREEN 1: BLOCK 7\n");
196         spectrum_128_screen_location = mess_ram + (7<<14);
197   }
198   else
199   {
200         logerror("SCREEN 0: BLOCK 5\n");
201         spectrum_128_screen_location = mess_ram + (5<<14);
202   }
203
204   /* select ram at 0x0c000-0x0ffff */
205   {
206         int ram_page;
207         unsigned char *ram_data;
208
209         ram_page = spectrum_128_port_7ffd_data & 0x07;
210         ram_data = mess_ram + (ram_page<<14);
211
212         memory_set_bankptr(4, ram_data);
213
214         logerror("RAM at 0xc000: %02x\n",ram_page);
215   }
216
217   /* ROM switching */
218   ROMSelection = ((spectrum_128_port_7ffd_data>>4) & 0x01);
219
220   /* rom 0 is 128K rom, rom 1 is 48 BASIC */
221
222   ChosenROM = memory_region(REGION_CPU1) + 0x010000 + (ROMSelection<<14);
223
224   memory_set_bankptr(1, ChosenROM);
225
226   logerror("rom switch: %02x\n", ROMSelection);
227}
228
229
230
231WRITE8_HANDLER(spectrum_128_port_bffd_w)
232{
233   AY8910_write_port_0_w(machine, 0, data);
234}
235
236WRITE8_HANDLER(spectrum_128_port_fffd_w)
237{
238   AY8910_control_port_0_w(machine, 0, data);
239}
240
241READ8_HANDLER(spectrum_128_port_fffd_r)
242{
243   return AY8910_read_port_0_r(machine, 0);
244}
245
246static  READ8_HANDLER ( spectrum_128_port_r )
247{
248    if ((offset & 1)==0)
249    {
250       return spectrum_port_fe_r(machine, offset);
251    }
252
253    if ((offset & 2)==0)
254    {
255      switch ((offset>>14) & 0x03)
256      {
257         default:
258            break;
259
260         case 3:
261            return spectrum_128_port_fffd_r(machine, offset);
262      }
263    }
264
265    /* don't think these are correct! */
266    if ((offset & 0xff)==0x1f)
267       return spectrum_port_1f_r(machine, offset);
268
269    if ((offset & 0xff)==0x7f)
270       return spectrum_port_7f_r(machine, offset);
271
272    if ((offset & 0xff)==0xdf)
273       return spectrum_port_df_r(machine, offset);
274
275    return video_screen_get_vpos(machine->primary_screen)<193 ? spectrum_128_screen_location[0x1800|(video_screen_get_vpos(machine->primary_screen)&0xf8)<<2]:0xff;
276}
277
278static WRITE8_HANDLER ( spectrum_128_port_w )
279{
280      if ((offset & 1)==0)
281            spectrum_port_fe_w(machine, offset,data);
282
283      /* Only decodes on A15, A14 & A1 */
284      else if ((offset & 2)==0)
285      {
286            switch ((offset>>8) & 0xc0)
287            {
288                  case 0x40:
289                        spectrum_128_port_7ffd_w(machine, offset, data);
290                        break;
291                  case 0x80:
292                        spectrum_128_port_bffd_w(machine, offset, data);
293                        break;
294                  case 0xc0:
295                        spectrum_128_port_fffd_w(machine, offset, data);
296                        break;
297                  default:
298                        logerror("Write %02x to 128 port: %04x\n", data, offset);
299            }
300      }
301      else
302      {
303         logerror("Write %02x to 128 port: %04x\n", data, offset);
304      }
305}
306
307/* ports are not decoded full.
308The function decodes the ports appropriately */
309static ADDRESS_MAP_START (spectrum_128_io, ADDRESS_SPACE_IO, 8)
310   AM_RANGE(0x0000, 0xffff) AM_READWRITE( spectrum_128_port_r, spectrum_128_port_w )
311ADDRESS_MAP_END
312
313static ADDRESS_MAP_START (spectrum_128_mem, ADDRESS_SPACE_PROGRAM, 8)
314   AM_RANGE( 0x0000, 0x3fff) AM_READWRITE( SMH_BANK1, SMH_BANK1 )
315   AM_RANGE( 0x4000, 0x7fff) AM_READWRITE( SMH_BANK2, SMH_BANK2 )
316   AM_RANGE( 0x8000, 0xbfff) AM_READWRITE( SMH_BANK3, SMH_BANK3 )
317   AM_RANGE( 0xc000, 0xffff) AM_READWRITE( SMH_BANK4, SMH_BANK4 )
318ADDRESS_MAP_END
319
320static MACHINE_RESET( spectrum_128 )
321{
322   memset(mess_ram,0,128*1024);
323   /* 0x0000-0x3fff always holds ROM */
324
325   /* Bank 5 is always in 0x4000 - 0x7fff */
326   memory_set_bankptr(2, mess_ram + (5<<14));
327
328   /* Bank 2 is always in 0x8000 - 0xbfff */
329   memory_set_bankptr(3, mess_ram + (2<<14));
330
331   /* set initial ram config */
332   spectrum_128_port_7ffd_data = 0;
333   spectrum_128_update_memory(machine);
334
335   MACHINE_RESET_CALL(spectrum);
336}
337
338MACHINE_DRIVER_START( spectrum_128 )
339   MDRV_IMPORT_FROM( spectrum )
340
341   MDRV_CPU_REPLACE("main", Z80, 3500000)        /* 3.5 Mhz */
342   MDRV_CPU_PROGRAM_MAP(spectrum_128_mem, 0)
343   MDRV_CPU_IO_MAP(spectrum_128_io, 0)
344
345   MDRV_MACHINE_RESET( spectrum_128 )
346
347    /* video hardware */
348   MDRV_SCREEN_MODIFY("main")
349   MDRV_PALETTE_LENGTH(16)
350   MDRV_PALETTE_INIT( spectrum_128 )
351   MDRV_SCREEN_REFRESH_RATE(50.021)
352   MDRV_VIDEO_START( spectrum_128 )
353   MDRV_VIDEO_UPDATE( spectrum_128 )
354
355   /* sound hardware */
356   MDRV_SOUND_ADD(AY8912, 1773400)
357   MDRV_SOUND_CONFIG(spectrum_ay_interface)
358   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
359MACHINE_DRIVER_END
360
361
362
363
364/***************************************************************************
365
366  Game driver(s)
367
368***************************************************************************/
369
370
371ROM_START(spec128)
372   ROM_REGION(0x18000,REGION_CPU1,0)
373   ROM_LOAD("zx128_0.rom",0x10000,0x4000, CRC(e76799d2) SHA1(4f4b11ec22326280bdb96e3baf9db4b4cb1d02c5))
374   ROM_LOAD("zx128_1.rom",0x14000,0x4000, CRC(b96a36be) SHA1(80080644289ed93d71a1103992a154cc9802b2fa))
375   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
376ROM_END
377
378ROM_START(spec128s)
379   ROM_REGION(0x18000,REGION_CPU1,0)
380   ROM_LOAD("zx128s0.rom",0x10000,0x4000, CRC(453d86b2) SHA1(968937b1c750f0ef6205f01c6db4148da4cca4e3))
381   ROM_LOAD("zx128s1.rom",0x14000,0x4000, CRC(6010e796) SHA1(bea3f397cc705eafee995ea629f4a82550562f90))
382   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
383ROM_END
384
385ROM_START(specpls2)
386   ROM_REGION(0x18000,REGION_CPU1,0)
387   ROM_LOAD("zxp2_0.rom",0x10000,0x4000, CRC(5d2e8c66) SHA1(72703f9a3e734f3c23ec34c0727aae4ccbef9a91))
388   ROM_LOAD("zxp2_1.rom",0x14000,0x4000, CRC(98b1320b) SHA1(de8b0d2d0379cfe7c39322a086ca6da68c7f23cb))
389   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
390ROM_END
391
392ROM_START(specpl2a)
393   ROM_REGION(0x20000,REGION_CPU1,0)
394   ROM_LOAD("p2a41_0.rom",0x10000,0x4000, CRC(30c9f490) SHA1(62ec15a4af56cd1d206d0bd7011eac7c889a595d))
395   ROM_LOAD("p2a41_1.rom",0x14000,0x4000, CRC(a7916b3f) SHA1(1a7812c383a3701e90e88d1da086efb0c033ac72))
396   ROM_LOAD("p2a41_2.rom",0x18000,0x4000, CRC(c9a0b748) SHA1(8df145d10ff78f98138682ea15ebccb2874bf759))
397   ROM_LOAD("p2a41_3.rom",0x1c000,0x4000, CRC(b88fd6e3) SHA1(be365f331942ec7ec35456b641dac56a0dbfe1f0))
398   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
399ROM_END
400
401
402ROM_START(specp2fr)
403   ROM_REGION(0x18000,REGION_CPU1,0)
404   ROM_LOAD("plus2fr0.rom",0x10000,0x4000, CRC(c684c535) SHA1(56684c4c85a616e726a50707483b9a42d8e724ed))
405   ROM_LOAD("plus2fr1.rom",0x14000,0x4000, CRC(f5e509c5) SHA1(7e398f62689c9d90a36d3a101351ec9987207308))
406   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
407ROM_END
408
409ROM_START(specp2sp)
410   ROM_REGION(0x18000,REGION_CPU1,0)
411   ROM_LOAD("plus2sp0.rom",0x10000,0x4000, CRC(e807d06e) SHA1(8259241b28ff85441f1bedc2bee53445767c51c5))
412   ROM_LOAD("plus2sp1.rom",0x14000,0x4000, CRC(41981d4b) SHA1(ec0d5a158842d20601b4fbeaefc6668db979d0e1))
413   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
414ROM_END
415
416SYSTEM_CONFIG_START(spec128)
417   CONFIG_IMPORT_FROM(spectrum)
418   CONFIG_RAM_DEFAULT(128 * 1024)
419SYSTEM_CONFIG_END
420
421
422/*    YEAR  NAME      PARENT    COMPAT  MACHINE     INPUT       INIT    CONFIG      COMPANY     FULLNAME */
423COMP( 1986, spec128,  0,      0,      spectrum_128,   spectrum,   0,      spec128,   "Sinclair Research",    "ZX Spectrum 128" , 0 )
424COMP( 1985, spec128s, spec128,  0,      spectrum_128,   spectrum,   0,      spec128,   "Sinclair Research",    "ZX Spectrum 128 (Spain)" , 0 )
425COMP( 1986, specpls2, spec128,  0,      spectrum_128,   spectrum,   0,      spec128,   "Amstrad plc",          "ZX Spectrum +2" , 0 )
426COMP( 1986, specp2fr, spec128,  0,      spectrum_128,   spectrum,   0,      spec128,   "Amstrad plc",          "ZX Spectrum +2 (France)" , 0 )
427COMP( 1986, specp2sp, spec128,  0,      spectrum_128,   spectrum,   0,      spec128,   "Amstrad plc",          "ZX Spectrum +2 (Spain)" , 0 )
src/mess/drivers/timex.c
r0r2517
1/***************************************************************************
2
3   NOTE: ****** Specbusy: press N, R, or E to boot *************
4
5
6        Spectrum/Inves/TK90X etc. memory map:
7
8    CPU:
9        0000-3fff ROM
10        4000-ffff RAM
11
12        Spectrum 128/+2/+2a/+3 memory map:
13
14        CPU:
15                0000-3fff Banked ROM/RAM (banked rom only on 128/+2)
16                4000-7fff Banked RAM
17                8000-bfff Banked RAM
18                c000-ffff Banked RAM
19
20        TS2068 memory map: (Can't have both EXROM and DOCK active)
21        The 8K EXROM can be loaded into multiple pages.
22
23    CPU:
24                0000-1fff     ROM / EXROM / DOCK (Cartridge)
25                2000-3fff     ROM / EXROM / DOCK
26                4000-5fff \
27                6000-7fff  \
28                8000-9fff  |- RAM / EXROM / DOCK
29                a000-bfff  |
30                c000-dfff  /
31                e000-ffff /
32
33
34Interrupts:
35
36Changes:
37
3829/1/2000   KT -    Implemented initial +3 emulation.
3930/1/2000   KT -    Improved input port decoding for reading and therefore
40            correct keyboard handling for Spectrum and +3.
4131/1/2000   KT -    Implemented buzzer sound for Spectrum and +3.
42            Implementation copied from Paul Daniel's Jupiter driver.
43            Fixed screen display problems with dirty chars.
44            Added support to load .Z80 snapshots. 48k support so far.
4513/2/2000   KT -    Added Interface II, Kempston, Fuller and Mikrogen
46            joystick support.
4717/2/2000   DJR -   Added full key descriptions and Spectrum+ keys.
48            Fixed Spectrum +3 keyboard problems.
4917/2/2000   KT -    Added tape loading from WAV/Changed from DAC to generic
50            speaker code.
5118/2/2000   KT -    Added tape saving to WAV.
5227/2/2000   KT -    Took DJR's changes and added my changes.
5327/2/2000   KT -    Added disk image support to Spectrum +3 driver.
5427/2/2000   KT -    Added joystick I/O code to the Spectrum +3 I/O handler.
5514/3/2000   DJR -   Tape handling dipswitch.
5626/3/2000   DJR -   Snapshot files are now classifed as snapshots not
57            cartridges.
5804/4/2000   DJR -   Spectrum 128 / +2 Support.
5913/4/2000   DJR -   +4 Support (unofficial 48K hack).
6013/4/2000   DJR -   +2a Support (rom also used in +3 models).
6113/4/2000   DJR -   TK90X, TK95 and Inves support (48K clones).
6221/4/2000   DJR -   TS2068 and TC2048 support (TC2048 Supports extra video
63            modes but doesn't have bank switching or sound chip).
6409/5/2000   DJR -   Spectrum +2 (France, Spain), +3 (Spain).
6517/5/2000   DJR -   Dipswitch to enable/disable disk drives on +3 and clones.
6627/6/2000   DJR -   Changed 128K/+3 port decoding (sound now works in Zub 128K).
6706/8/2000   DJR -   Fixed +3 Floppy support
6810/2/2001   KT  -   Re-arranged code and split into each model emulated.
69            Code is split into 48k, 128k, +3, tc2048 and ts2048
70            segments. 128k uses some of the functions in 48k, +3
71            uses some functions in 128, and tc2048/ts2048 use some
72            of the functions in 48k. The code has been arranged so
73            these functions come in some kind of "override" order,
74            read functions changed to use  READ8_HANDLER and write
75            functions changed to use WRITE8_HANDLER.
76            Added Scorpion256 preliminary.
7718/6/2001   DJR -   Added support for Interface 2 cartridges.
78xx/xx/2001  KS -    TS-2068 sound fixed.
79            Added support for DOCK cartridges for TS-2068.
80            Added Spectrum 48k Psycho modified rom driver.
81            Added UK-2086 driver.
8223/12/2001  KS -    48k machines are now able to run code in screen memory.
83                Programs which keep their code in screen memory
84                like monitors, tape copiers, decrunchers, etc.
85                works now.
86                Fixed problem with interrupt vector set to 0xffff (much
87            more 128k games works now).
88                A useful used trick on the Spectrum is to set
89                interrupt vector to 0xffff (using the table
90                which contain 0xff's) and put a byte 0x18 hex,
91                the opcode for JR, at this address. The first
92                byte of the ROM is a 0xf3 (DI), so the JR will
93                jump to 0xfff4, where a long JP to the actual
94                interrupt routine is put. Due to unideal
95                bankswitching in MAME this JP were to 0001 what
96                causes Spectrum to reset. Fixing this problem
97                made much more software runing (i.e. Paperboy).
98            Corrected frames per second value for 48k and 128k
99            Sincalir machines.
100                There are 50.08 frames per second for Spectrum
101                48k what gives 69888 cycles for each frame and
102                50.021 for Spectrum 128/+2/+2A/+3 what gives
103                70908 cycles for each frame.
104            Remaped some Spectrum+ keys.
105                Presing F3 to reset was seting 0xf7 on keyboard
106                input port. Problem occured for snapshots of
107                some programms where it was readed as pressing
108                key 4 (which is exit in Tapecopy by R. Dannhoefer
109                for example).
110            Added support to load .SP snapshots.
111            Added .BLK tape images support.
112                .BLK files are identical to .TAP ones, extension
113                is an only difference.
11408/03/2002  KS -    #FF port emulation added.
115                Arkanoid works now, but is not playable due to
116                completly messed timings.
117
118Initialisation values used when determining which model is being emulated:
119 48K        Spectrum doesn't use either port.
120 128K/+2    Bank switches with port 7ffd only.
121 +3/+2a     Bank switches with both ports.
122
123Notes:
124 1. No contented memory.
125 2. No hi-res colour effects (need contended memory first for accurate timing).
126 3. Multiface 1 and Interface 1 not supported.
127 4. Horace and the Spiders cartridge doesn't run properly.
128 5. Tape images not supported:
129    .TZX, .SPC, .ITM, .PAN, .TAP(Warajevo), .VOC, .ZXS.
130 6. Snapshot images not supported:
131    .ACH, .PRG, .RAW, .SEM, .SIT, .SNX, .ZX, .ZXS, .ZX82.
132 7. 128K emulation is not perfect - the 128K machines crash and hang while
133    running quite a lot of games.
134 8. Disk errors occur on some +3 games.
135 9. Video hardware of all machines is timed incorrectly.
13610. EXROM and HOME cartridges are not emulated.
13711. The TK90X and TK95 roms output 0 to port #df on start up.
13812. The purpose of this port is unknown (probably display mode as TS2068) and
139    thus is not emulated.
140
141Very detailed infos about the ZX Spectrum +3e can be found at
142
143http://www.z88forever.org.uk/zxplus3e/
144
145*******************************************************************************/
146
147#include "driver.h"
148#include "includes/spectrum.h"
149#include "eventlst.h"
150#include "devices/snapquik.h"
151#include "devices/cartslot.h"
152#include "devices/cassette.h"
153#include "sound/speaker.h"
154#include "sound/ay8910.h"
155#include "formats/tzx_cas.h"
156
157/****************************************************************************************************/
158/* TS2048 specific functions */
159
160
161int ts2068_port_ff_data = -1; /* Display enhancement control */
162int ts2068_port_f4_data = -1; /* Horizontal Select Register */
163
164static  READ8_HANDLER(ts2068_port_f4_r)
165{
166      return ts2068_port_f4_data;
167}
168
169static WRITE8_HANDLER(ts2068_port_f4_w)
170{
171      ts2068_port_f4_data = data;
172      ts2068_update_memory(machine);
173}
174
175static WRITE8_HANDLER(ts2068_port_f5_w)
176{
177      AY8910_control_port_0_w(machine, 0, data);
178}
179
180static  READ8_HANDLER(ts2068_port_f6_r)
181{
182      /* TODO - Reading from register 14 reads the joystick ports
183           set bit 8 of address to read joystick #1
184           set bit 9 of address to read joystick #2
185           if both bits are set then OR values
186           Bit 0 up, 1 down, 2 left, 3 right, 7 fire active low. Other bits 1
187        */
188      return AY8910_read_port_0_r(machine, 0);
189}
190
191static WRITE8_HANDLER(ts2068_port_f6_w)
192{
193      AY8910_write_port_0_w(machine, 0, data);
194}
195
196static  READ8_HANDLER(ts2068_port_ff_r)
197{
198      return ts2068_port_ff_data;
199}
200
201static WRITE8_HANDLER(ts2068_port_ff_w)
202{
203      /* Bits 0-2 Video Mode Select
204           Bits 3-5 64 column mode ink/paper selection
205                    (See ts2068_vh_screenrefresh for more info)
206           Bit  6   17ms Interrupt Inhibit
207           Bit  7   Cartridge (0) / EXROM (1) select
208        */
209      ts2068_port_ff_data = data;
210      ts2068_update_memory(machine);
211      logerror("Port %04x write %02x\n", offset, data);
212}
213
214
215static READ8_HANDLER ( ts2068_port_r )
216{
217   switch (offset & 0xff)
218   {
219      /* Note: keys only decoded on port #fe not all even ports so
220           ports #f4 & #f6 correctly read */
221      case 0xf4: return ts2068_port_f4_r(machine, offset);
222      case 0xf6: return ts2068_port_f6_r(machine, offset);
223      case 0xff: return ts2068_port_ff_r(machine, offset);
224
225      case 0xfe: return spectrum_port_fe_r(machine, offset);
226      case 0x1f: return spectrum_port_1f_r(machine, offset);
227      case 0x7f: return spectrum_port_7f_r(machine, offset);
228      case 0xdf: return spectrum_port_df_r(machine, offset);
229   }
230   logerror("Read from port: %04x\n", offset);
231
232   return 0xff;
233}
234
235static WRITE8_HANDLER ( ts2068_port_w )
236{
237/* Ports #fd & #fc were reserved by Timex for bankswitching and are not used
238   by either the hardware or system software.
239   Port #fb is the Thermal printer port and works exactly as the Sinclair
240   Printer - ie not yet emulated.
241*/
242   switch (offset & 0xff)
243   {
244      case 0xfe: spectrum_port_fe_w(machine, offset,data); break;
245      case 0xf4: ts2068_port_f4_w(machine, offset,data); break;
246      case 0xf5: ts2068_port_f5_w(machine, offset,data); break;
247      case 0xf6: ts2068_port_f6_w(machine, offset,data); break;
248      case 0xff: ts2068_port_ff_w(machine, offset,data); break;
249      default:
250            logerror("Write %02x to Port: %04x\n", data, offset);
251   }
252}
253
254
255
256/*******************************************************************
257 *
258 *      Bank switch between the 3 internal memory banks HOME, EXROM
259 *      and DOCK (Cartridges). The HOME bank contains 16K ROM in the
260 *      0-16K area and 48K RAM fills the rest. The EXROM contains 8K
261 *      ROM and can appear in every 8K segment (ie 0-8K, 8-16K etc).
262 *      The DOCK is empty and is meant to be occupied by cartridges
263 *      you can plug into the cartridge dock of the 2068.
264 *
265 *      The address space is divided into 8 8K chunks. Bit 0 of port
266 *      #f4 corresponds to the 0-8K chunk, bit 1 to the 8-16K chunk
267 *      etc. If the bit is 0 then the chunk is controlled by the HOME
268 *      bank. If the bit is 1 then the chunk is controlled by either
269 *      the DOCK or EXROM depending on bit 7 of port #ff. Note this
270 *      means that that the Z80 can't see chunks of the EXROM and DOCK
271 *      at the same time.
272 *
273 *******************************************************************/
274void ts2068_update_memory(running_machine *machine)
275{
276   unsigned char *ChosenROM, *ExROM, *DOCK;
277   read8_machine_func rh;
278   write8_machine_func wh;
279
280   DOCK = timex_cart_data;
281
282   ExROM = memory_region(REGION_CPU1) + 0x014000;
283
284   if (ts2068_port_f4_data & 0x01)
285   {
286      if (ts2068_port_ff_data & 0x80)
287      {
288            rh = SMH_BANK1;
289            wh = SMH_UNMAP;
290            memory_set_bankptr(1, ExROM);
291            logerror("0000-1fff EXROM\n");
292      }
293      else
294      {
295         if (timex_cart_type == TIMEX_CART_DOCK)
296         {
297            memory_set_bankptr(1, DOCK);
298            rh = SMH_BANK1;
299            if (timex_cart_chunks&0x01)
300               wh = SMH_BANK9;
301            else
302               wh = SMH_UNMAP;
303         }
304         else
305         {
306            rh = SMH_NOP;
307            wh = SMH_UNMAP;
308         }
309         logerror("0000-1fff Cartridge\n");
310      }
311   }
312   else
313   {
314      ChosenROM = memory_region(REGION_CPU1) + 0x010000;
315      memory_set_bankptr(1, ChosenROM);
316      rh = SMH_BANK1;
317      wh = SMH_UNMAP;
318      logerror("0000-1fff HOME\n");
319   }
320   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x1fff, 0, 0, rh);
321   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x1fff, 0, 0, wh);
322
323   if (ts2068_port_f4_data & 0x02)
324   {
325      if (ts2068_port_ff_data & 0x80)
326      {
327         memory_set_bankptr(2, ExROM);
328         rh = SMH_BANK2;
329         wh = SMH_UNMAP;
330         logerror("2000-3fff EXROM\n");
331      }
332      else
333      {
334         if (timex_cart_type == TIMEX_CART_DOCK)
335         {
336            memory_set_bankptr(2, DOCK+0x2000);
337            rh = SMH_BANK2;
338            if (timex_cart_chunks&0x02)
339               wh = SMH_BANK10;
340            else
341               wh = SMH_UNMAP;
342         }
343         else
344         {
345            rh = SMH_NOP;
346            wh = SMH_UNMAP;
347         }
348         logerror("2000-3fff Cartridge\n");
349      }
350   }
351   else
352   {
353      ChosenROM = memory_region(REGION_CPU1) + 0x012000;
354      memory_set_bankptr(2, ChosenROM);
355      rh = SMH_BANK2;
356      wh = SMH_UNMAP;
357      logerror("2000-3fff HOME\n");
358   }
359   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x2000, 0x3fff, 0, 0, rh);
360   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x2000, 0x3fff, 0, 0, wh);
361
362   if (ts2068_port_f4_data & 0x04)
363   {
364      if (ts2068_port_ff_data & 0x80)
365      {
366         memory_set_bankptr(3, ExROM);
367         rh = SMH_BANK3;
368         wh = SMH_UNMAP;
369         logerror("4000-5fff EXROM\n");
370      }
371      else
372      {
373         if (timex_cart_type == TIMEX_CART_DOCK)
374         {
375            memory_set_bankptr(3, DOCK+0x4000);
376            rh = SMH_BANK3;
377            if (timex_cart_chunks&0x04)
378               wh = SMH_BANK11;
379            else
380               wh = SMH_UNMAP;
381         }
382         else
383         {
384            rh = SMH_NOP;
385            wh = SMH_UNMAP;
386         }
387         logerror("4000-5fff Cartridge\n");
388      }
389   }
390   else
391   {
392      memory_set_bankptr(3, mess_ram);
393      memory_set_bankptr(11, mess_ram);
394      rh = SMH_BANK3;
395      wh = SMH_BANK11;
396      logerror("4000-5fff RAM\n");
397   }
398   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x5fff, 0, 0, rh);
399   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x5fff, 0, 0, wh);
400
401   if (ts2068_port_f4_data & 0x08)
402   {
403      if (ts2068_port_ff_data & 0x80)
404      {
405         memory_set_bankptr(4, ExROM);
406         rh = SMH_BANK4;
407         wh = SMH_UNMAP;
408         logerror("6000-7fff EXROM\n");
409      }
410      else
411      {
412            if (timex_cart_type == TIMEX_CART_DOCK)
413            {
414               memory_set_bankptr(4, DOCK+0x6000);
415               rh = SMH_BANK4;
416               if (timex_cart_chunks&0x08)
417                  wh = SMH_BANK12;
418               else
419                  wh = SMH_UNMAP;
420            }
421            else
422            {
423               rh = SMH_NOP;
424               wh = SMH_UNMAP;
425            }
426            logerror("6000-7fff Cartridge\n");
427      }
428   }
429   else
430   {
431      memory_set_bankptr(4, mess_ram + 0x2000);
432      memory_set_bankptr(12, mess_ram + 0x2000);
433      rh = SMH_BANK4;
434      wh = SMH_BANK12;
435      logerror("6000-7fff RAM\n");
436   }
437   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x6000, 0x7fff, 0, 0, rh);
438   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x6000, 0x7fff, 0, 0, wh);
439
440   if (ts2068_port_f4_data & 0x10)
441   {
442      if (ts2068_port_ff_data & 0x80)
443      {
444         memory_set_bankptr(5, ExROM);
445         rh = SMH_BANK5;
446         wh = SMH_UNMAP;
447         logerror("8000-9fff EXROM\n");
448      }
449      else
450      {
451         if (timex_cart_type == TIMEX_CART_DOCK)
452         {
453            memory_set_bankptr(5, DOCK+0x8000);
454            rh = SMH_BANK5;
455            if (timex_cart_chunks&0x10)
456               wh = SMH_BANK13;
457            else
458               wh = SMH_UNMAP;
459         }
460         else
461         {
462            rh = SMH_NOP;
463            wh = SMH_UNMAP;
464         }
465         logerror("8000-9fff Cartridge\n");
466      }
467   }
468   else
469   {
470      memory_set_bankptr(5, mess_ram + 0x4000);
471      memory_set_bankptr(13, mess_ram + 0x4000);
472      rh = SMH_BANK5;
473      wh = SMH_BANK13;
474      logerror("8000-9fff RAM\n");
475   }
476   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x8000, 0x9fff, 0, 0,rh);
477   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x8000, 0x9fff, 0, 0,wh);
478
479   if (ts2068_port_f4_data & 0x20)
480   {
481      if (ts2068_port_ff_data & 0x80)
482      {
483         memory_set_bankptr(6, ExROM);
484         rh = SMH_BANK6;
485         wh = SMH_UNMAP;
486         logerror("a000-bfff EXROM\n");
487      }
488      else
489      {
490         if (timex_cart_type == TIMEX_CART_DOCK)
491         {
492            memory_set_bankptr(6, DOCK+0xa000);
493            rh = SMH_BANK6;
494            if (timex_cart_chunks&0x20)
495               wh = SMH_BANK14;
496            else
497               wh = SMH_UNMAP;
498         }
499         else
500         {
501            rh = SMH_NOP;
502            wh = SMH_UNMAP;
503         }
504         logerror("a000-bfff Cartridge\n");
505      }
506   }
507   else
508   {
509      memory_set_bankptr(6, mess_ram + 0x6000);
510      memory_set_bankptr(14, mess_ram + 0x6000);
511      rh = SMH_BANK6;
512      wh = SMH_BANK14;
513      logerror("a000-bfff RAM\n");
514   }
515   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa000, 0xbfff, 0, 0, rh);
516   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa000, 0xbfff, 0, 0, wh);
517
518   if (ts2068_port_f4_data & 0x40)
519   {
520      if (ts2068_port_ff_data & 0x80)
521      {
522         memory_set_bankptr(7, ExROM);
523         rh = SMH_BANK7;
524         wh = SMH_UNMAP;
525         logerror("c000-dfff EXROM\n");
526      }
527      else
528      {
529         if (timex_cart_type == TIMEX_CART_DOCK)
530         {
531            memory_set_bankptr(7, DOCK+0xc000);
532            rh = SMH_BANK7;
533            if (timex_cart_chunks&0x40)
534               wh = SMH_BANK15;
535            else
536               wh = SMH_UNMAP;
537         }
538         else
539         {
540            rh = SMH_NOP;
541            wh = SMH_UNMAP;
542         }
543         logerror("c000-dfff Cartridge\n");
544      }
545   }
546   else
547   {
548      memory_set_bankptr(7, mess_ram + 0x8000);
549      memory_set_bankptr(15, mess_ram + 0x8000);
550      rh = SMH_BANK7;
551      wh = SMH_BANK15;
552      logerror("c000-dfff RAM\n");
553   }
554   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xdfff, 0, 0, rh);
555   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xdfff, 0, 0, wh);
556
557   if (ts2068_port_f4_data & 0x80)
558   {
559      if (ts2068_port_ff_data & 0x80)
560      {
561         memory_set_bankptr(8, ExROM);
562         rh = SMH_BANK8;
563         wh = SMH_UNMAP;
564         logerror("e000-ffff EXROM\n");
565      }
566      else
567      {
568         if (timex_cart_type == TIMEX_CART_DOCK)
569         {
570            memory_set_bankptr(8, DOCK+0xe000);
571            rh = SMH_BANK8;
572            if (timex_cart_chunks&0x80)
573               wh = SMH_BANK16;
574            else
575               wh = SMH_UNMAP;
576         }
577         else
578         {
579            rh = SMH_NOP;
580            wh = SMH_UNMAP;
581         }
582         logerror("e000-ffff Cartridge\n");
583      }
584   }
585   else
586   {
587      memory_set_bankptr(8, mess_ram + 0xa000);
588      memory_set_bankptr(16, mess_ram + 0xa000);
589      rh = SMH_BANK8;
590      wh = SMH_BANK16;
591      logerror("e000-ffff RAM\n");
592   }
593   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xe000, 0xffff, 0, 0, rh);
594   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xe000, 0xffff, 0, 0, wh);
595}
596
597
598static ADDRESS_MAP_START (ts2068_io, ADDRESS_SPACE_IO, 8)
599   AM_RANGE(0x0000, 0xffff) AM_READWRITE( ts2068_port_r, ts2068_port_w )
600ADDRESS_MAP_END
601
602static ADDRESS_MAP_START (ts2068_mem, ADDRESS_SPACE_PROGRAM, 8)
603   AM_RANGE(0x0000, 0x1fff) AM_READWRITE( SMH_BANK1, SMH_BANK9 )
604   AM_RANGE(0x2000, 0x3fff) AM_READWRITE( SMH_BANK2, SMH_BANK10 )
605   AM_RANGE(0x4000, 0x5fff) AM_READWRITE( SMH_BANK3, SMH_BANK11 )
606   AM_RANGE(0x6000, 0x7fff) AM_READWRITE( SMH_BANK4, SMH_BANK12 )
607   AM_RANGE(0x8000, 0x9fff) AM_READWRITE( SMH_BANK5, SMH_BANK13 )
608   AM_RANGE(0xa000, 0xbfff) AM_READWRITE( SMH_BANK6, SMH_BANK14 )
609   AM_RANGE(0xc000, 0xdfff) AM_READWRITE( SMH_BANK7, SMH_BANK15 )
610   AM_RANGE(0xe000, 0xffff) AM_READWRITE( SMH_BANK8, SMH_BANK16 )
611ADDRESS_MAP_END
612
613
614static MACHINE_RESET( ts2068 )
615{
616   ts2068_port_ff_data = 0;
617   ts2068_port_f4_data = 0;
618   ts2068_update_memory(machine);
619
620   MACHINE_RESET_CALL(spectrum);
621}
622
623
624/****************************************************************************************************/
625/* TC2048 specific functions */
626
627
628static void tc2048_port_ff_w(int offset, int data)
629{
630      ts2068_port_ff_data = data;
631      logerror("Port %04x write %02x\n", offset, data);
632}
633
634static  READ8_HANDLER ( tc2048_port_r )
635{
636      if ((offset & 1)==0)
637            return spectrum_port_fe_r(machine, offset);
638      switch (offset & 0xff)
639      {
640            case 0xff: return ts2068_port_ff_r(machine, offset);
641            case 0x1f: return spectrum_port_1f_r(machine, offset);
642            case 0x7f: return spectrum_port_7f_r(machine, offset);
643            case 0xdf: return spectrum_port_df_r(machine, offset);
644      }
645
646      logerror("Read from port: %04x\n", offset);
647      return 0xff;
648}
649
650static WRITE8_HANDLER ( tc2048_port_w )
651{
652      if ((offset & 1)==0)
653            spectrum_port_fe_w(machine, offset,data);
654      else if ((offset & 0xff)==0xff)
655            tc2048_port_ff_w(offset, data);
656      else
657      {
658            logerror("Write %02x to Port: %04x\n", data, offset);
659      }
660}
661
662/* ports are not decoded full.
663The function decodes the ports appropriately */
664static ADDRESS_MAP_START (tc2048_io, ADDRESS_SPACE_IO, 8)
665   AM_RANGE(0x0000, 0xffff) AM_READWRITE( tc2048_port_r, tc2048_port_w )
666ADDRESS_MAP_END
667
668static ADDRESS_MAP_START (tc2048_mem, ADDRESS_SPACE_PROGRAM, 8)
669   AM_RANGE( 0x0000, 0x3fff) AM_ROM
670   AM_RANGE( 0x4000, 0xffff) AM_READWRITE( SMH_BANK1, SMH_BANK2 )
671ADDRESS_MAP_END
672
673static MACHINE_RESET( tc2048 )
674{
675   memory_set_bankptr(1, mess_ram);
676   memory_set_bankptr(2, mess_ram);
677   ts2068_port_ff_data = 0;
678
679   MACHINE_RESET_CALL(spectrum);
680}
681
682
683
684static MACHINE_DRIVER_START( ts2068 )
685   MDRV_IMPORT_FROM( spectrum_128 )
686   MDRV_CPU_REPLACE("main", Z80, 3580000)        /* 3.58 Mhz */
687   MDRV_CPU_PROGRAM_MAP(ts2068_mem, 0)
688   MDRV_CPU_IO_MAP(ts2068_io, 0)
689
690   MDRV_MACHINE_RESET( ts2068 )
691
692    /* video hardware */
693   MDRV_SCREEN_MODIFY("main")
694   MDRV_SCREEN_REFRESH_RATE(60)
695   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
696   MDRV_SCREEN_SIZE(TS2068_SCREEN_WIDTH, TS2068_SCREEN_HEIGHT)
697   MDRV_SCREEN_VISIBLE_AREA(0, TS2068_SCREEN_WIDTH-1, 0, TS2068_SCREEN_HEIGHT-1)
698
699   MDRV_VIDEO_UPDATE( ts2068 )
700   MDRV_VIDEO_EOF( ts2068 )
701MACHINE_DRIVER_END
702
703
704static MACHINE_DRIVER_START( uk2086 )
705   MDRV_IMPORT_FROM( ts2068 )
706   MDRV_SCREEN_MODIFY("main")
707   MDRV_SCREEN_REFRESH_RATE(50)
708MACHINE_DRIVER_END
709
710
711static MACHINE_DRIVER_START( tc2048 )
712   MDRV_IMPORT_FROM( spectrum )
713   MDRV_CPU_MODIFY("main")
714   MDRV_CPU_PROGRAM_MAP(tc2048_mem, 0)
715   MDRV_CPU_IO_MAP(tc2048_io, 0)
716
717   MDRV_SCREEN_MODIFY("main")
718   MDRV_SCREEN_REFRESH_RATE(50)
719
720   MDRV_MACHINE_RESET( tc2048 )
721
722    /* video hardware */
723   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
724   MDRV_SCREEN_SIZE(TS2068_SCREEN_WIDTH, SPEC_SCREEN_HEIGHT)
725   MDRV_SCREEN_VISIBLE_AREA(0, TS2068_SCREEN_WIDTH-1, 0, SPEC_SCREEN_HEIGHT-1)
726
727   MDRV_VIDEO_START( spectrum_128 )
728   MDRV_VIDEO_UPDATE( tc2048 )
729MACHINE_DRIVER_END
730
731
732
733/***************************************************************************
734
735  Game driver(s)
736
737***************************************************************************/
738
739ROM_START(tc2048)
740   ROM_REGION(0x10000,REGION_CPU1,0)
741   ROM_LOAD("tc2048.rom",0x0000,0x4000, CRC(f1b5fa67) SHA1(febb2d495b6eda7cdcb4074935d6e9d9f328972d))
742   ROM_CART_LOAD(0, "rom", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
743ROM_END
744
745ROM_START(ts2068)
746   ROM_REGION(0x16000,REGION_CPU1,0)
747   ROM_LOAD("ts2068_h.rom",0x10000,0x4000, CRC(bf44ec3f) SHA1(1446cb2780a9dedf640404a639fa3ae518b2d8aa))
748   ROM_LOAD("ts2068_x.rom",0x14000,0x2000, CRC(ae16233a) SHA1(7e265a2c1f621ed365ea23bdcafdedbc79c1299c))
749ROM_END
750
751ROM_START(uk2086)
752   ROM_REGION(0x16000,REGION_CPU1,0)
753   ROM_LOAD("uk2086_h.rom",0x10000,0x4000, CRC(5ddc0ca2) SHA1(1d525fe5cdc82ab46767f665ad735eb5363f1f51))
754   ROM_LOAD("ts2068_x.rom",0x14000,0x2000, CRC(ae16233a) SHA1(7e265a2c1f621ed365ea23bdcafdedbc79c1299c))
755ROM_END
756
757
758static void ts2068_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
759{
760   /* cartslot */
761   switch(state)
762   {
763      /* --- the following bits of info are returned as 64-bit signed integers --- */
764      case MESS_DEVINFO_INT_COUNT:                     info->i = 1; break;
765
766      /* --- the following bits of info are returned as pointers to data or functions --- */
767      case MESS_DEVINFO_PTR_LOAD:                     info->load = DEVICE_IMAGE_LOAD_NAME(timex_cart); break;
768      case MESS_DEVINFO_PTR_UNLOAD:                  info->unload = DEVICE_IMAGE_UNLOAD_NAME(timex_cart); break;
769
770      /* --- the following bits of info are returned as NULL-terminated strings --- */
771      case MESS_DEVINFO_STR_FILE_EXTENSIONS:            strcpy(info->s = device_temp_str(), "dck"); break;
772
773      default:                              cartslot_device_getinfo(devclass, state, info); break;
774   }
775}
776
777SYSTEM_CONFIG_START(ts2068)
778   CONFIG_IMPORT_FROM(spectrum_common)
779   CONFIG_DEVICE(ts2068_cartslot_getinfo)
780   CONFIG_RAM_DEFAULT(48 * 1024)
781SYSTEM_CONFIG_END
782
783SYSTEM_CONFIG_START(tc2048)
784   CONFIG_IMPORT_FROM(spectrum)
785   CONFIG_RAM_DEFAULT(48 * 1024)
786SYSTEM_CONFIG_END
787
788/*    YEAR  NAME      PARENT    COMPAT  MACHINE     INPUT       INIT    CONFIG      COMPANY     FULLNAME */
789COMP( 1984, tc2048,   spectrum, 0,      tc2048,         spectrum,   0,      tc2048,      "Timex of Portugal",   "TC-2048" , 0)
790COMP( 1983, ts2068,   spectrum, 0,      ts2068,         spectrum,   0,      ts2068,      "Timex Sinclair",   "TS-2068" , 0)
791COMP( 1986, uk2086,   spectrum, 0,      uk2086,         spectrum,   0,      ts2068,      "Unipolbrit",   "UK-2086 ver. 1.2" , 0)
docs/messnew.txt
r2516r2517
5454
5555- [SPECIAL] Added Erik clone, and fixed bank switch problem [Miodrag Milanovic]
5656
57- [SPECTRUM] Split into multiple drivers and cleanup[Miodrag Milanovic]
58
5759- [T1000HX] Fixed bug #1130.  [Wilbert Pol]
5860
5961- [THOMSON] Fixed crashes with non-default ram sizes.  (bug #1443) [Antoine

Previous 15994 Revisions Next


© 1998-2018 The MESS Team