Previous 15994 Revisions Next

r12882 Sunday 18th September, 2011 at 13:28:56 UTC by Sandro Ronco
[KC] Started modernizing/cleaning up the driver and fixed typestar loading in kc85_2/3. (no whatsnew)
[src/mess/drivers]kc.c
[src/mess/includes]kc.h
[src/mess/machine]kc.c
[src/mess/video]kc.c

src/mess/machine/kc.c
r12881r12882
22#include "emu.h"
33#include "includes/kc.h"
44
5/* Components */
6#include "machine/z80ctc.h"
7#include "machine/z80pio.h"
8#include "machine/z80sio.h"
9#include "cpu/z80/z80.h"
10#include "sound/speaker.h"
11
12/* Devices */
13#include "imagedev/cassette.h"
14#include "machine/ram.h"
15
165#define KC_DEBUG 0
176#define LOG(x) do { if (KC_DEBUG) logerror x; } while (0)
187
19
20static void kc85_4_update_0x0c000(running_machine &machine);
21static void kc85_4_update_0x0e000(running_machine &machine);
22static void kc85_4_update_0x08000(running_machine &machine);
23
24/* PIO PORT A: port 0x088:
25
26bit 7: ROM C (BASIC)
27bit 6: Tape Motor on
28bit 5: LED
29bit 4: K OUT
30bit 3: WRITE PROTECT RAM 0
31bit 2: IRM
32bit 1: ACCESS RAM 0
33bit 0: CAOS ROM E
34*/
35
36/* PIO PORT B: port 0x089:
37bit 7: BLINK ENABLE (1=blink, 0=no blink)
38bit 6: WRITE PROTECT RAM 8
39bit 5: ACCESS RAM 8
40bit 4: TONE 4
41bit 3: TONE 3
42bit 2: TONE 2
43bit 1: TONE 1
44bit 0: TRUCK */
45
46
47/* load image */
48static int kc_load(device_image_interface &image, unsigned char **ptr)
49{
50   int datasize;
51   unsigned char *data;
52
53   /* get file size */
54   datasize = image.length();
55
56   if (datasize!=0)
57   {
58      /* malloc memory for this data */
59      data = (unsigned char *)auto_alloc_array(image.device().machine(), unsigned char, datasize);
60
61      if (data!=NULL)
62      {
63         /* read whole file */
64         image.fread( data, datasize);
65
66         *ptr = data;
67
68         logerror("File loaded!\r\n");
69
70         /* ok! */
71         return 1;
72      }
73   }
74
75   return 0;
76}
77
788struct kcc_header
799{
80   unsigned char   name[10];
81   unsigned char   reserved[6];
82   unsigned char   anzahl;
83   unsigned char   load_address_l;
84   unsigned char   load_address_h;
85   unsigned char   end_address_l;
86   unsigned char   end_address_h;
87   unsigned char   execution_address_l;
88   unsigned char   execution_address_h;
89   unsigned char   pad[128-2-2-2-1-16];
10   UINT8   name[10];
11   UINT8   reserved[6];
12   UINT8   number_addresses;
13   UINT8   load_address_l;
14   UINT8   load_address_h;
15   UINT8   end_address_l;
16   UINT8   end_address_h;
17   UINT8   execution_address_l;
18   UINT8   execution_address_h;
19   UINT8   pad[128-2-2-2-1-16];
9020};
9121
9222/* appears to work a bit.. */
r12881r12882
9626/* load snapshot */
9727QUICKLOAD_LOAD(kc)
9828{
99   unsigned char *data;
29   kc_state *state = image.device().machine().driver_data<kc_state>();
30   UINT8 *data;
10031   struct kcc_header *header;
10132   int addr;
10233   int datasize;
10334   int execution_address;
10435   int i;
10536
106   if (!kc_load(image, &data))
37   /* get file size */
38   datasize = image.length();
39
40   if (datasize != 0)
41   {
42      /* malloc memory for this data */
43      data = (UINT8 *)auto_alloc_array(image.device().machine(), UINT8, datasize);
44
45      if (data != NULL)
46         image.fread( data, datasize);
47   }
48   else
49   {
10750      return IMAGE_INIT_FAIL;
51   }
10852
10953   header = (struct kcc_header *) data;
11054   addr = (header->load_address_l & 0x0ff) | ((header->load_address_h & 0x0ff)<<8);
r12881r12882
11761      datasize = image.length() - 128;
11862   }
11963
64   address_space *space = state->m_maincpu->memory().space( AS_PROGRAM );
65
12066   for (i=0; i<datasize; i++)
121      ram_get_ptr(image.device().machine().device(RAM_TAG))[(addr+i) & 0x0ffff] = data[i+128];
67      space->write_byte((addr+i) & 0xffff, data[i+128]);
12268
123   if (execution_address != 0 && header->anzahl >= 3 )
69   if (execution_address != 0 && header->number_addresses >= 3 )
12470   {
12571      // if specified, jumps to the quickload start address
126      cpu_set_reg(image.device().machine().device("maincpu"), STATE_GENPC, execution_address);
72      cpu_set_reg(state->m_maincpu, STATE_GENPC, execution_address);
12773   }
12874
12975   auto_free(image.device().machine(), data);
r12881r12882
13480}
13581
13682
137/*****************/
138/* MODULE SYSTEM */
139/*****************/
83//**************************************************************************
84//  MODULE SYSTEM EMULATION
85//**************************************************************************
14086
141/* The KC85/4 and KC85/3 are "modular systems". These computers can be expanded with modules.
142*/
87// The KC85/4 and KC85/3 are "modular systems". These computers can be expanded with modules.
14388
14489/*
14590    Module ID       Module Name         Module Description
r12881r12882
164109    e3              M029                DAU1
165110*/
166111
167static void kc85_module_system_init(running_machine &machine)
112READ8_MEMBER( kc_state::expansion_read )
168113{
169   kc_state *state = machine.driver_data<kc_state>();
170
171   state->m_expansions[0] = machine.device<kcexp_slot_device>("m1");
172   state->m_expansions[1] = machine.device<kcexp_slot_device>("m2");
173   state->m_expansions[2] = machine.device<kcexp_slot_device>("exp");
174}
175
176static READ8_HANDLER ( kc_expansion_read )
177{
178   kc_state *state = space->machine().driver_data<kc_state>();
179114   UINT8 result = 0xff;
180115
181116   // assert MEI line of first slot
182   state->m_expansions[0]->mei_w(ASSERT_LINE);
117   m_expansions[0]->mei_w(ASSERT_LINE);
183118
184119   for (int i=0; i<3; i++)
185      state->m_expansions[i]->read(offset, result);
120      m_expansions[i]->read(offset, result);
186121
187122   return result;
188123}
189124
190static WRITE8_HANDLER ( kc_expansion_write )
125WRITE8_MEMBER( kc_state::expansion_write )
191126{
192   kc_state *state = space->machine().driver_data<kc_state>();
193
194127   // assert MEI line of first slot
195   state->m_expansions[0]->mei_w(ASSERT_LINE);
128   m_expansions[0]->mei_w(ASSERT_LINE);
196129
197130   for (int i=0; i<3; i++)
198      state->m_expansions[i]->write(offset, data);
131      m_expansions[i]->write(offset, data);
199132}
200133
201134/*
r12881r12882
210143    Id's for known modules are listed above.
211144*/
212145
213READ8_HANDLER ( kc_expansion_io_read )
146READ8_MEMBER( kc_state::expansion_io_read )
214147{
215   kc_state *state = space->machine().driver_data<kc_state>();
216148   UINT8 result = 0xff;
217149
218150   // assert MEI line of first slot
219   state->m_expansions[0]->mei_w(ASSERT_LINE);
151   m_expansions[0]->mei_w(ASSERT_LINE);
220152
221153   if ((offset & 0xff) == 0x80)
222154   {
223155      UINT8 slot_id = (offset>>8) & 0xff;
224156
225157      if (slot_id == 0x08 || slot_id == 0x0c)
226         result = state->m_expansions[(slot_id - 8) >> 2]->module_id_r();
158         result = m_expansions[(slot_id - 8) >> 2]->module_id_r();
227159      else
228         state->m_expansions[2]->io_read(offset, result);
160         m_expansions[2]->io_read(offset, result);
229161   }
230162   else
231163   {
232164      for (int i=0; i<3; i++)
233         state->m_expansions[i]->io_read(offset, result);
165         m_expansions[i]->io_read(offset, result);
234166   }
235167
236168   return result;
237169}
238170
239WRITE8_HANDLER ( kc_expansion_io_write )
171WRITE8_MEMBER( kc_state::expansion_io_write )
240172{
241   kc_state *state = space->machine().driver_data<kc_state>();
242
243173   // assert MEI line of first slot
244   state->m_expansions[0]->mei_w(ASSERT_LINE);
174   m_expansions[0]->mei_w(ASSERT_LINE);
245175
246176   if ((offset & 0xff) == 0x80)
247177   {
248178      UINT8 slot_id = (offset>>8) & 0xff;
249179
250180      if (slot_id == 0x08 || slot_id == 0x0c)
251         state->m_expansions[(slot_id - 8) >> 2]->control_w(data);
181         m_expansions[(slot_id - 8) >> 2]->control_w(data);
252182      else
253         state->m_expansions[2]->io_write(offset, data);
183         m_expansions[2]->io_write(offset, data);
254184   }
255185   else
256186   {
257187      for (int i=0; i<3; i++)
258         state->m_expansions[i]->io_write(offset, data);
188         m_expansions[i]->io_write(offset, data);
259189   }
260190}
261191
262192// module read/write handlers
263static READ8_HANDLER ( kc_expansion_4000_r ){ return kc_expansion_read(space, offset + 0x4000); }
264static WRITE8_HANDLER( kc_expansion_4000_w ){ kc_expansion_write(space, offset + 0x4000, data); }
265static READ8_HANDLER ( kc_expansion_8000_r ){ return kc_expansion_read(space, offset + 0x8000); }
266static WRITE8_HANDLER( kc_expansion_8000_w ){ kc_expansion_write(space, offset + 0x8000, data); }
267static READ8_HANDLER ( kc_expansion_c000_r ){ return kc_expansion_read(space, offset + 0xc000); }
268static WRITE8_HANDLER( kc_expansion_c000_w ){ kc_expansion_write(space, offset + 0xc000, data); }
269static READ8_HANDLER ( kc_expansion_e000_r ){ return kc_expansion_read(space, offset + 0xe000); }
270static WRITE8_HANDLER( kc_expansion_e000_w ){ kc_expansion_write(space, offset + 0xe000, data); }
193READ8_MEMBER ( kc_state::expansion_4000_r ){ return expansion_read(space, offset + 0x4000); }
194WRITE8_MEMBER( kc_state::expansion_4000_w ){ expansion_write(space, offset + 0x4000, data); }
195READ8_MEMBER ( kc_state::expansion_8000_r ){ return expansion_read(space, offset + 0x8000); }
196WRITE8_MEMBER( kc_state::expansion_8000_w ){ expansion_write(space, offset + 0x8000, data); }
197READ8_MEMBER ( kc_state::expansion_c000_r ){ return expansion_read(space, offset + 0xc000); }
198WRITE8_MEMBER( kc_state::expansion_c000_w ){ expansion_write(space, offset + 0xc000, data); }
199READ8_MEMBER ( kc_state::expansion_e000_r ){ return expansion_read(space, offset + 0xe000); }
200WRITE8_MEMBER( kc_state::expansion_e000_w ){ expansion_write(space, offset + 0xe000, data); }
271201
272202
273/**********************/
274/* CASSETTE EMULATION */
275/**********************/
276/* used by KC85/4 and KC85/3 */
203//**************************************************************************
204//  CASSETTE EMULATION
205//**************************************************************************
206
277207/*
278208    The cassette motor is controlled by bit 6 of PIO port A.
279209    The cassette read data is connected to /ASTB input of the PIO.
r12881r12882
296226static TIMER_CALLBACK(kc_cassette_timer_callback)
297227{
298228   kc_state *state = machine.driver_data<kc_state>();
299   int bit;
300229
301   /* the cassette data is linked to /astb input of
302    the pio. */
230   /* the cassette data is linked to /astb input of the pio. */
231   int bit = (state->m_cassette->input() > 0.0038) ? 1 : 0;
303232
304   bit = 0;
305
306   /* get data from cassette */
307   if ((machine.device<cassette_image_device>(CASSETTE_TAG))->input() > 0.0038)
308      bit = 1;
309
310233   /* update astb with bit */
311   z80pio_astb_w(state->m_kc85_z80pio,bit & state->m_ardy);
234   z80pio_astb_w(state->m_z80pio, bit & state->m_ardy);
312235}
313236
314static void   kc_cassette_init(running_machine &machine)
237void kc_state::cassette_set_motor(int motor_state)
315238{
316   kc_state *state = machine.driver_data<kc_state>();
317   state->m_cassette_timer = machine.scheduler().timer_alloc(FUNC(kc_cassette_timer_callback));
318}
319
320static void   kc_cassette_set_motor(running_machine &machine, int motor_state)
321{
322   kc_state *state = machine.driver_data<kc_state>();
323239   /* state changed? */
324   if (((state->m_cassette_motor_state^motor_state)&0x01)!=0)
240   if (((m_cassette_motor_state^motor_state)&0x01) != 0)
325241   {
326242      /* set new motor state in cassette device */
327      machine.device<cassette_image_device>(CASSETTE_TAG)->change_state(
328         motor_state ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED,
329         CASSETTE_MASK_MOTOR);
243      m_cassette->change_state(motor_state ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR);
330244
331245      if (motor_state)
332246      {
333247         /* start timer */
334         state->m_cassette_timer->adjust(attotime::zero, 0, KC_CASSETTE_TIMER_FREQUENCY);
248         m_cassette_timer->adjust(attotime::zero, 0, KC_CASSETTE_TIMER_FREQUENCY);
335249      }
336250      else
337251      {
338252         /* stop timer */
339         state->m_cassette_timer->reset();
253         m_cassette_timer->reset();
340254      }
341255   }
342256
343257   /* store new state */
344   state->m_cassette_motor_state = motor_state;
258   m_cassette_motor_state = motor_state;
345259}
346260
347261/*
r12881r12882
369283    truck signal resets, 5v signal for set.
370284    output gives k0 and k1.
371285
372
373
374
375286*/
376287
377288
378289
379/*********************************************************************/
290//**************************************************************************
291//  KC85 bankswitch
292//**************************************************************************
380293
381/* port 0x084/0x085:
382
383bit 7: RAF3
384bit 6: RAF2
385bit 5: RAF1
386bit 4: RAF0
387bit 3: FPIX. high resolution
388bit 2: BLA1 .access screen
389bit 1: BLA0 .pixel/color
390bit 0: BILD .display screen 0 or 1
391*/
392
393/* port 0x086/0x087:
394
395bit 7: ROCC
396bit 6: ROF1
397bit 5: ROF0
398bit 4-2 are not connected
399bit 1: WRITE PROTECT RAM 4
400bit 0: ACCESS RAM 4
401*/
402
403
404/* KC85/4 specific */
405
406
407
408
409/* port 0x086:
410
411bit 7: CAOS ROM C
412bit 6:
413bit 5:
414bit 4:
415bit 3:
416bit 2:
417bit 1: write protect ram 4
418bit 0: ram 4
419*/
420
421static void kc85_4_update_0x08000(running_machine &machine)
422{
423   kc_state *state = machine.driver_data<kc_state>();
424   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
425   unsigned char *ram_page;
426
427    if (state->m_kc85_pio_data[1] & (1<<5))
428    {
429      int ram8_block;
430      unsigned char *mem_ptr;
431
432      /* ram8 block chosen */
433      ram8_block = ((state->m_kc85_84_data)>>4) & 0x01;
434
435      mem_ptr = ram_get_ptr(machine.device(RAM_TAG))+0x08000+(ram8_block<<14);
436
437      memory_set_bankptr(machine, "bank3", mem_ptr);
438      memory_set_bankptr(machine, "bank4", mem_ptr+0x02800);
439      space->install_read_bank(0x8000, 0xa7ff, "bank3");
440      space->install_read_bank(0xa800, 0xbfff, "bank4");
441
442      /* write protect RAM8 ? */
443      if ((state->m_kc85_pio_data[1] & (1<<6))==0)
444      {
445         /* ram8 is enabled and write protected */
446         space->nop_write(0x8000, 0xa7ff);
447         space->nop_write(0xa800, 0xbfff);
448      }
449      else
450      {
451         LOG(("RAM8 write enabled\n"));
452
453         /* ram8 is enabled and write enabled */
454         space->install_write_bank(0x8000, 0xa7ff, "bank9");
455         space->install_write_bank(0xa800, 0xbfff, "bank10");
456         memory_set_bankptr(machine, "bank9", mem_ptr);
457         memory_set_bankptr(machine, "bank10", mem_ptr+0x02800);
458      }
459    }
460    else
461    {
462      LOG(("Module at ram8\n"));
463
464      space->install_legacy_read_handler (0x8000, 0xbfff, FUNC(kc_expansion_8000_r));
465      space->install_legacy_write_handler(0x8000, 0xbfff, FUNC(kc_expansion_8000_w));
466    }
467
468   /* if IRM is enabled override block 3/9 settings */
469   if (state->m_kc85_pio_data[0] & (1<<2))
470   {
471      /* IRM enabled - has priority over RAM8 enabled */
472      ram_page = kc85_4_get_video_ram_base(machine, (state->m_kc85_84_data & 0x04), (state->m_kc85_84_data & 0x02));
473
474      memory_set_bankptr(machine, "bank3", ram_page);
475      memory_set_bankptr(machine, "bank9", ram_page);
476      space->install_read_bank(0x8000, 0xa7ff, "bank3");
477      space->install_write_bank(0x8000, 0xa7ff, "bank9");
478
479      ram_page = kc85_4_get_video_ram_base(machine, 0, 0);
480
481      memory_set_bankptr(machine, "bank4", ram_page + 0x2800);
482      memory_set_bankptr(machine, "bank10", ram_page + 0x2800);
483      space->install_read_bank(0xa800, 0xbfff, "bank4");
484      space->install_write_bank(0xa800, 0xbfff, "bank10");
485   }
486}
487
488294/* update status of memory area 0x0000-0x03fff */
489static void kc85_4_update_0x00000(running_machine &machine)
295void kc_state::update_0x00000()
490296{
491   kc_state *state = machine.driver_data<kc_state>();
492   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
297   address_space *space = m_maincpu->memory().space( AS_PROGRAM );
493298
494299   /* access ram? */
495   if (state->m_kc85_pio_data[0] & (1<<1))
300   if (m_pio_data[0] & (1<<1))
496301   {
497302      LOG(("ram0 enabled\n"));
498303
499304      /* yes; set address of bank */
500305      space->install_read_bank(0x0000, 0x3fff, "bank1");
501      memory_set_bankptr(machine, "bank1", ram_get_ptr(machine.device(RAM_TAG)));
306      memory_set_bankptr(machine(), "bank1", m_ram_base);
502307
503308      /* write protect ram? */
504      if ((state->m_kc85_pio_data[0] & (1<<3))==0)
309      if ((m_pio_data[0] & (1<<3)) == 0)
505310      {
506311         /* yes */
507312         LOG(("ram0 write protected\n"));
r12881r12882
513318      {
514319         LOG(("ram0 write enabled\n"));
515320
516         /* ram is enabled and write enabled; and set address of bank */
517         space->install_write_bank(0x0000, 0x3fff, "bank7");
518         memory_set_bankptr(machine, "bank7", ram_get_ptr(machine.device(RAM_TAG)));
321         /* ram is enabled and write enabled */
322         space->install_write_bank(0x0000, 0x3fff, "bank1");
519323      }
520324   }
521325   else
522326   {
523      LOG(("Module at ram0!\n"));
327      LOG(("Module at 0x0000\n"));
524328
525      space->install_legacy_read_handler (0x0000, 0x3fff, FUNC(kc_expansion_read));
526      space->install_legacy_write_handler(0x0000, 0x3fff, FUNC(kc_expansion_write));
329      space->install_read_handler (0x0000, 0x3fff, 0, 0, read8_delegate(FUNC(kc_state::expansion_read), this), 0);
330      space->install_write_handler(0x0000, 0x3fff, 0, 0, write8_delegate(FUNC(kc_state::expansion_write), this), 0);
527331   }
528332}
529333
530334/* update status of memory area 0x4000-0x07fff */
531static void kc85_4_update_0x04000(running_machine &machine)
335void kc_state::update_0x04000()
532336{
533   kc_state *state = machine.driver_data<kc_state>();
534   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
337   address_space *space = m_maincpu->memory().space( AS_PROGRAM );
535338
536   /* access ram? */
537   if (state->m_kc85_86_data & (1<<0))
538   {
539      UINT8 *mem_ptr;
339   LOG(("Module at 0x4000\n"));
540340
541      mem_ptr = ram_get_ptr(machine.device(RAM_TAG)) + 0x04000;
341   space->install_read_handler (0x4000, 0x7fff, 0, 0, read8_delegate(FUNC(kc_state::expansion_4000_r), this), 0);
342   space->install_write_handler(0x4000, 0x7fff, 0, 0, write8_delegate(FUNC(kc_state::expansion_4000_w), this), 0);
542343
543      /* yes */
544      space->install_read_bank(0x4000, 0x7fff, "bank2");
545      /* set address of bank */
546      memory_set_bankptr(machine, "bank2", mem_ptr);
547
548      /* write protect ram? */
549      if ((state->m_kc85_86_data & (1<<1))==0)
550      {
551         /* yes */
552         LOG(("ram4 write protected\n"));
553
554         /* ram is enabled and write protected */
555         space->nop_write(0x4000, 0x7fff);
556      }
557      else
558      {
559         LOG(("ram4 write enabled\n"));
560
561         /* ram is enabled and write enabled */
562         space->install_write_bank(0x4000, 0x7fff, "bank8");
563         /* set address of bank */
564         memory_set_bankptr(machine, "bank8", mem_ptr);
565      }
566   }
567   else
568   {
569      LOG(("Module at ram4!\n"));
570
571      space->install_legacy_read_handler (0x4000, 0x7fff, FUNC(kc_expansion_4000_r));
572      space->install_legacy_write_handler(0x4000, 0x7fff, FUNC(kc_expansion_4000_w));
573   }
574
575344}
576345
577346
578347/* update memory address 0x0c000-0x0e000 */
579static void kc85_4_update_0x0c000(running_machine &machine)
348void kc_state::update_0x0c000()
580349{
581   kc_state *state = machine.driver_data<kc_state>();
582   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
350   address_space *space = m_maincpu->memory().space( AS_PROGRAM );
583351
584   if (state->m_kc85_86_data & (1<<7))
352   if ((m_pio_data[0] & (1<<7)) && machine().region("basic")->base() != NULL)
585353   {
586      /* CAOS rom takes priority */
587      LOG(("CAOS rom 0x0c000\n"));
588
589      memory_set_bankptr(machine, "bank5",machine.region("caos")->base());
590      space->install_read_bank(0xc000, 0xdfff, "bank5");
591      space->unmap_write(0xc000, 0xdfff);
592   }
593   else if (state->m_kc85_pio_data[0] & (1<<7))
594   {
595354      /* BASIC takes next priority */
596355           LOG(("BASIC rom 0x0c000\n"));
597356
598        memory_set_bankptr(machine, "bank5", machine.region("basic")->base());
599      space->install_read_bank(0xc000, 0xdfff, "bank5");
357        memory_set_bankptr(machine(), "bank4", machine().region("basic")->base());
358      space->install_read_bank(0xc000, 0xdfff, "bank4");
600359      space->unmap_write(0xc000, 0xdfff);
601360   }
602361   else
603362   {
604363      LOG(("Module at 0x0c000\n"));
605364
606      space->install_legacy_read_handler (0xc000, 0xdfff, FUNC(kc_expansion_c000_r));
607      space->install_legacy_write_handler(0xc000, 0xdfff, FUNC(kc_expansion_c000_w));
365      space->install_read_handler (0xc000, 0xdfff, 0, 0, read8_delegate(FUNC(kc_state::expansion_c000_r), this), 0);
366      space->install_write_handler(0xc000, 0xdfff, 0, 0, write8_delegate(FUNC(kc_state::expansion_c000_w), this), 0);
608367   }
609368}
610369
611370/* update memory address 0x0e000-0x0ffff */
612static void kc85_4_update_0x0e000(running_machine &machine)
371void kc_state::update_0x0e000()
613372{
614   kc_state *state = machine.driver_data<kc_state>();
615   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
616   if (state->m_kc85_pio_data[0] & (1<<0))
373   address_space *space = m_maincpu->memory().space( AS_PROGRAM );
374
375   if (m_pio_data[0] & (1<<0))
617376   {
618377      /* enable CAOS rom in memory range 0x0e000-0x0ffff */
619378      LOG(("CAOS rom 0x0e000\n"));
620379      /* read will access the rom */
621      memory_set_bankptr(machine, "bank6",machine.region("caos")->base() + 0x2000);
622      space->install_read_bank(0xe000, 0xffff,"bank6");
380      memory_set_bankptr(machine(), "bank5", machine().region("caos")->base() + 0x2000);
381      space->install_read_bank(0xe000, 0xffff, "bank5");
623382      space->unmap_write(0xe000, 0xffff);
624383   }
625384   else
626385   {
627386      LOG(("Module at 0x0e000\n"));
628387
629      space->install_legacy_read_handler (0xe000, 0xffff, FUNC(kc_expansion_e000_r));
630      space->install_legacy_write_handler(0xe000, 0xffff, FUNC(kc_expansion_e000_w));
388      space->install_read_handler (0xe000, 0xffff, 0, 0, read8_delegate(FUNC(kc_state::expansion_e000_r), this), 0);
389      space->install_write_handler(0xe000, 0xffff, 0, 0, write8_delegate(FUNC(kc_state::expansion_e000_w), this), 0);
631390   }
632391}
633392
634/* PIO PORT A: port 0x088:
635393
636bit 7: ROM C (BASIC)
637bit 6: Tape Motor on
638bit 5: LED
639bit 4: K OUT
640bit 3: WRITE PROTECT RAM 0
641bit 2: IRM
642bit 1: ACCESS RAM 0
643bit 0: CAOS ROM E
644*/
645
646static READ8_DEVICE_HANDLER ( kc85_4_pio_porta_r )
394/* update status of memory area 0x08000-0x0ffff */
395void kc_state::update_0x08000()
647396{
648   kc_state *state = device->machine().driver_data<kc_state>();
649   return state->m_kc85_pio_data[0];
650}
397   address_space *space = m_maincpu->memory().space( AS_PROGRAM );
651398
652static WRITE8_DEVICE_HANDLER ( kc85_4_pio_porta_w )
653{
654   kc_state *state = device->machine().driver_data<kc_state>();
655   state->m_kc85_pio_data[0] = data;
399    if (m_pio_data[0] & (1<<2))
400    {
401        /* IRM enabled */
402        LOG(("IRM enabled\n"));
656403
657   kc85_4_update_0x0c000(device->machine());
658   kc85_4_update_0x0e000(device->machine());
659   kc85_4_update_0x08000(device->machine());
660   kc85_4_update_0x00000(device->machine());
404      memory_set_bankptr(machine(), "bank3", m_ram_base + 0x4000);
405      space->install_readwrite_bank(0x8000, 0xbfff, "bank3");
406    }
407    else
408    {
409      LOG(("Module at 0x8000!\n"));
661410
662   kc_cassette_set_motor(device->machine(), (data>>6) & 0x01);
411      space->install_read_handler(0x8000, 0xbfff, 0, 0, read8_delegate(FUNC(kc_state::expansion_8000_r), this), 0);
412      space->install_write_handler(0x8000, 0xbfff, 0, 0, write8_delegate(FUNC(kc_state::expansion_8000_w), this), 0);
413    }
663414}
664415
665/* PIO PORT B: port 0x089:
666bit 7: BLINK
667bit 6: WRITE PROTECT RAM 8
668bit 5: ACCESS RAM 8
669bit 4: TONE 4
670bit 3: TONE 3
671bit 2: TONE 2
672bit 1: TONE 1
673bit 0: TRUCK */
674416
675static READ8_DEVICE_HANDLER ( kc85_4_pio_portb_r )
417/* update status of memory area 0x4000-0x07fff */
418void kc85_4_state::update_0x04000()
676419{
677   kc_state *state = device->machine().driver_data<kc_state>();
678   return state->m_kc85_pio_data[1];
679}
420   address_space *space = m_maincpu->memory().space( AS_PROGRAM );
680421
681static WRITE8_DEVICE_HANDLER ( kc85_4_pio_portb_w )
682{
683   kc_state *state = device->machine().driver_data<kc_state>();
684   device_t *speaker = device->machine().device(SPEAKER_TAG);
685   state->m_kc85_pio_data[1] = data;
422   /* access ram? */
423   if (m_port_86_data & (1<<0))
424   {
425      LOG(("RAM4 enabled\n"));
686426
687   int speaker_level;
427      /* yes */
428      space->install_read_bank(0x4000, 0x7fff, "bank2");
429      /* set address of bank */
430      memory_set_bankptr(machine(), "bank2", m_ram_base + 0x4000);
688431
689   kc85_4_update_0x08000(device->machine());
432      /* write protect ram? */
433      if ((m_port_86_data & (1<<1)) == 0)
434      {
435         /* yes */
436         LOG(("ram4 write protected\n"));
690437
691   /* 16 speaker levels */
692   speaker_level = (data>>1) & 0x0f;
438         /* ram is enabled and write protected */
439         space->nop_write(0x4000, 0x7fff);
440      }
441      else
442      {
443         LOG(("ram4 write enabled\n"));
693444
694   /* this might not be correct, the range might
695    be logarithmic and not linear! */
696   speaker_level_w(speaker, (speaker_level<<4));
697}
445         /* ram is enabled and write enabled */
446         space->install_write_bank(0x4000, 0x7fff, "bank2");
447      }
448   }
449   else
450   {
451      LOG(("Module at 0x4000\n"));
698452
453      space->install_read_handler (0x4000, 0x7fff, 0, 0, read8_delegate(FUNC(kc_state::expansion_4000_r), this), 0);
454      space->install_write_handler(0x4000, 0x7fff, 0, 0, write8_delegate(FUNC(kc_state::expansion_4000_w), this), 0);
455   }
699456
700WRITE8_HANDLER ( kc85_4_86_w )
701{
702   kc_state *state = space->machine().driver_data<kc_state>();
703   LOG(("0x086 W: %02x\n",data));
704
705   state->m_kc85_86_data = data;
706
707   kc85_4_update_0x0c000(space->machine());
708   kc85_4_update_0x04000(space->machine());
709457}
710458
711 READ8_HANDLER ( kc85_4_86_r )
459/* update memory address 0x0c000-0x0e000 */
460void kc85_4_state::update_0x0c000()
712461{
713   kc_state *state = space->machine().driver_data<kc_state>();
714   return state->m_kc85_86_data;
715}
462   address_space *space = m_maincpu->memory().space( AS_PROGRAM );
716463
717
718WRITE8_HANDLER ( kc85_4_84_w )
719{
720   kc_state *state = space->machine().driver_data<kc_state>();
721   LOG(("0x084 W: %02x\n",data));
722
723   state->m_kc85_84_data = data;
724
725   kc85_4_video_ram_select_bank(space->machine(), data & 0x01);
726
727   kc85_4_update_0x08000(space->machine());
728}
729
730 READ8_HANDLER ( kc85_4_84_r )
731{
732   kc_state *state = space->machine().driver_data<kc_state>();
733   return state->m_kc85_84_data;
734}
735/*****************************************************************/
736
737/* update memory region 0x0c000-0x0e000 */
738static void kc85_3_update_0x0c000(running_machine &machine)
739{
740   kc_state *state = machine.driver_data<kc_state>();
741   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
742
743   if (state->m_kc85_pio_data[0] & (1<<7) && machine.region("basic")->base() != NULL)
464   if (m_port_86_data & (1<<7))
744465   {
745      /* BASIC takes next priority */
746      LOG(("BASIC rom 0x0c000\n"));
466      /* CAOS rom takes priority */
467      LOG(("CAOS rom 0x0c000\n"));
747468
748      memory_set_bankptr(machine, "bank4", machine.region("basic")->base());
469      memory_set_bankptr(machine(), "bank4", machine().region("caos")->base());
749470      space->install_read_bank(0xc000, 0xdfff, "bank4");
750471      space->unmap_write(0xc000, 0xdfff);
751472   }
752473   else
753474   {
754      LOG(("Module at 0x0c000\n"));
755
756      space->install_legacy_read_handler (0xc000, 0xdfff, FUNC(kc_expansion_c000_r));
757      space->install_legacy_write_handler(0xc000, 0xdfff, FUNC(kc_expansion_c000_w));
475      kc_state::update_0x0c000();
758476   }
759477}
760478
761/* update memory address 0x0e000-0x0ffff */
762static void kc85_3_update_0x0e000(running_machine &machine)
479void kc85_4_state::update_0x08000()
763480{
764   kc_state *state = machine.driver_data<kc_state>();
765   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
481   address_space *space = m_maincpu->memory().space( AS_PROGRAM );
766482
767   if (state->m_kc85_pio_data[0] & (1<<0))
483   if (m_pio_data[0] & (1<<2))
768484   {
769      /* enable CAOS rom in memory range 0x0e000-0x0ffff */
770      LOG(("CAOS rom 0x0e000\n"));
485      /* IRM enabled - has priority over RAM8 enabled */
486      LOG(("IRM enabled\n"));
771487
772      memory_set_bankptr(machine, "bank5",machine.region("caos")->base());
773      space->install_read_bank(0xe000, 0xffff, "bank5");
774      space->unmap_write(0xe000, 0xffff);
775   }
776   else
777   {
778      LOG(("Module at 0x0e000\n"));
488      UINT8* ram_page = (UINT8*)kc85_4_get_video_ram_base(machine(), (m_port_84_data & 0x04), (m_port_84_data & 0x02));
779489
780      space->install_legacy_read_handler (0xe000, 0xffff, FUNC(kc_expansion_e000_r));
781      space->install_legacy_write_handler(0xe000, 0xffff, FUNC(kc_expansion_e000_w));
782   }
783}
490      memory_set_bankptr(machine(), "bank3", ram_page);
491      space->install_readwrite_bank(0x8000, 0xa7ff, "bank3");
784492
785/* update status of memory area 0x0000-0x03fff */
786/* SMH_BANK(1) is used for read operations and SMH_BANK(6) is used
787for write operations */
788static void kc85_3_update_0x00000(running_machine &machine)
789{
790   kc_state *state = machine.driver_data<kc_state>();
791   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
493      ram_page = (UINT8*)kc85_4_get_video_ram_base(machine(), 0, 0);
792494
793   /* access ram? */
794   if (state->m_kc85_pio_data[0] & (1<<1))
795   {
796      LOG(("ram0 enabled\n"));
495      memory_set_bankptr(machine(), "bank6", ram_page + 0x2800);
496      space->install_readwrite_bank(0xa800, 0xbfff, "bank6");
497   }
498    else if (m_pio_data[1] & (1<<5))
499    {
500      LOG(("RAM8 enabled\n"));
797501
798      /* yes */
799      space->install_read_bank(0x0000, 0x3fff, "bank1");
800      /* set address of bank */
801      memory_set_bankptr(machine, "bank1", ram_get_ptr(machine.device(RAM_TAG)));
502      int ram8_block;
503      UINT8 *mem_ptr;
802504
803      /* write protect ram? */
804      if ((state->m_kc85_pio_data[0] & (1<<3))==0)
805      {
806         /* yes */
807         LOG(("ram0 write protected\n"));
505      /* ram8 block chosen */
808506
809         /* ram is enabled and write protected */
810         space->nop_write(0x0000, 0x3fff);
507      if (ram_get_size(m_ram) == 64 * 1024)
508      {
509         // kc85_4 64K RAM
510         ram8_block = ((m_port_84_data)>>4) & 0x01;
511         mem_ptr = m_ram_base + 0x8000 + (ram8_block<<14);
811512      }
812513      else
813514      {
814         LOG(("ram0 write enabled\n"));
815
816         /* ram is enabled and write enabled */
817         space->install_write_bank(0x0000, 0x3fff, "bank6");
818         /* set address of bank */
819         memory_set_bankptr(machine, "bank6", ram_get_ptr(machine.device(RAM_TAG)));
515         // kc85_5 224K RAM
516         if ((m_port_84_data & 0x0e) == 0)
517         {
518            ram8_block = ((m_port_84_data)>>4) & 0x01;
519            mem_ptr = m_ram_base + (ram8_block<<14);
520         }
521         else
522         {
523            ram8_block = (((m_port_84_data)>>4) & 0x0f) - 2;
524            mem_ptr = m_ram_base + (ram8_block<<14);
525         }
820526      }
821   }
822   else
823   {
824      LOG(("Module at ram0!\n"));
825527
826      space->install_legacy_read_handler (0x0000, 0x3fff, FUNC(kc_expansion_read));
827      space->install_legacy_write_handler(0x0000, 0x3fff, FUNC(kc_expansion_write));
828   }
829}
528      memory_set_bankptr(machine(), "bank3", mem_ptr);
529      memory_set_bankptr(machine(), "bank6", mem_ptr + 0x2800);
530      space->install_read_bank(0x8000, 0xa7ff, "bank3");
531      space->install_read_bank(0xa800, 0xbfff, "bank6");
830532
831/* update status of memory area 0x08000-0x0ffff */
832/* SMH_BANK(3) is used for read, SMH_BANK(8) is used for write */
833static void kc85_3_update_0x08000(running_machine &machine)
834{
835   kc_state *state = machine.driver_data<kc_state>();
836   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
837   unsigned char *ram_page;
838
839    if (state->m_kc85_pio_data[0] & (1<<2))
840    {
841        /* IRM enabled */
842        LOG(("IRM enabled\n"));
843      ram_page = ram_get_ptr(machine.device(RAM_TAG))+0x08000;
844
845      memory_set_bankptr(machine, "bank3", ram_page);
846      memory_set_bankptr(machine, "bank8", ram_page);
847      space->install_read_bank(0x8000, 0xbfff, "bank3");
848      space->install_write_bank(0x8000, 0xbfff, "bank8");
849    }
850    else if (state->m_kc85_pio_data[1] & (1<<5))
851    {
852      /* RAM8 ACCESS */
853      LOG(("RAM8 enabled\n"));
854      ram_page = ram_get_ptr(machine.device(RAM_TAG)) + 0x04000;
855
856      memory_set_bankptr(machine, "bank3", ram_page);
857      space->install_read_bank(0x8000, 0xbfff, "bank3");
858
859533      /* write protect RAM8 ? */
860      if ((state->m_kc85_pio_data[1] & (1<<6))==0)
534      if ((m_pio_data[1] & (1<<6)) == 0)
861535      {
862         LOG(("RAM8 write protected\n"));
863536         /* ram8 is enabled and write protected */
864         space->nop_write(0x8000, 0xbfff);
537         LOG(("RAM8 write protected\n"));
538
539         space->nop_write(0x8000, 0xa7ff);
540         space->nop_write(0xa800, 0xbfff);
865541      }
866542      else
867543      {
868544         LOG(("RAM8 write enabled\n"));
545
869546         /* ram8 is enabled and write enabled */
870         space->install_write_bank(0x8000, 0xbfff, "bank8");
871         memory_set_bankptr(machine, "bank8",ram_page);
547         space->install_write_bank(0x8000, 0xa7ff, "bank3");
548         space->install_write_bank(0xa800, 0xbfff, "bank6");
872549      }
873550    }
874551    else
875552    {
876      LOG(("Module at ram8!\n"));
553      LOG(("Module at 0x8000\n"));
877554
878      space->install_legacy_read_handler (0x8000, 0xbfff, FUNC(kc_expansion_8000_r));
879      space->install_legacy_write_handler(0x8000, 0xbfff, FUNC(kc_expansion_8000_w));
555      space->install_read_handler(0x8000, 0xbfff, 0, 0, read8_delegate(FUNC(kc_state::expansion_8000_r), this), 0);
556      space->install_write_handler(0x8000, 0xbfff, 0, 0, write8_delegate(FUNC(kc_state::expansion_8000_w), this), 0);
880557    }
881558}
882559
560//**************************************************************************
561//  KC85 Z80PIO Interface
562//**************************************************************************
883563
564
884565/* PIO PORT A: port 0x088:
885566
886567bit 7: ROM C (BASIC)
r12881r12882
893574bit 0: CAOS ROM E
894575*/
895576
896static READ8_DEVICE_HANDLER ( kc85_3_pio_porta_r )
577READ8_MEMBER( kc_state::pio_porta_r )
897578{
898   kc_state *state = device->machine().driver_data<kc_state>();
899
900   return state->m_kc85_pio_data[0];
579   return m_pio_data[0];
901580}
902581
903static WRITE8_DEVICE_HANDLER ( kc85_3_pio_porta_w )
582WRITE8_MEMBER( kc_state::pio_porta_w )
904583{
905   kc_state *state = device->machine().driver_data<kc_state>();
906   state->m_kc85_pio_data[0] = data;
584   if (m_pio_data[0] != data) // to avoid a severe slowdown during cassette loading
585   {
586      m_pio_data[0] = data;
907587
908   kc85_3_update_0x0c000(device->machine());
909   kc85_3_update_0x0e000(device->machine());
910   kc85_3_update_0x00000(device->machine());
588      update_0x00000();
589      update_0x08000();
590      update_0x0c000();
591      update_0x0e000();
911592
912   kc_cassette_set_motor(device->machine(), (data>>6) & 0x01);
593      cassette_set_motor(BIT(data, 6));
594   }
913595}
914596
915597
r12881r12882
923605bit 1: TONE 1
924606bit 0: TRUCK */
925607
926static READ8_DEVICE_HANDLER ( kc85_3_pio_portb_r )
608READ8_MEMBER( kc_state::pio_portb_r )
927609{
928   kc_state *state = device->machine().driver_data<kc_state>();
929
930   return state->m_kc85_pio_data[1];
610   return m_pio_data[1];
931611}
932612
933static WRITE8_DEVICE_HANDLER ( kc85_3_pio_portb_w )
613WRITE8_MEMBER( kc_state::pio_portb_w )
934614{
935   kc_state *state = device->machine().driver_data<kc_state>();
936   device_t *speaker = device->machine().device(SPEAKER_TAG);
937   state->m_kc85_pio_data[1] = data;
615   m_pio_data[1] = data;
938616
939   int speaker_level;
617   update_0x08000();
940618
941   kc85_3_update_0x08000(device->machine());
942
943619   /* 16 speaker levels */
944   speaker_level = (data>>1) & 0x0f;
620   int speaker_level = (data>>1) & 0x0f;
945621
946622   /* this might not be correct, the range might
947623    be logarithmic and not linear! */
948   speaker_level_w(speaker, (speaker_level<<4));
624   speaker_level_w(m_speaker, (speaker_level<<4));
949625}
950626
627/* port 0x84/0x85:
951628
952/*****************************************************************/
629bit 7: RAF3
630bit 6: RAF2
631bit 5: RAF1
632bit 4: RAF0
633bit 3: FPIX. high resolution
634bit 2: BLA1 .access screen
635bit 1: BLA0 .pixel/color
636bit 0: BILD .display screen 0 or 1
637*/
953638
954#if 0
955DIRECT_UPDATE_HANDLER( kc85_3_opbaseoverride )
639WRITE8_MEMBER( kc85_4_state::kc85_4_84_w )
956640{
957   memory_set_direct_update_handler(0,0);
641   LOG(("0x84 W: %02x\n", data));
958642
959   kc85_3_update_0x00000(machine);
643   m_port_84_data = data;
960644
961   return (cpunum_get_reg(0, STATE_GENPC) & 0x0ffff);
645   kc85_4_video_ram_select_bank(machine(), data & 0x01);
646
647   update_0x08000();
962648}
963649
650READ8_MEMBER( kc85_4_state::kc85_4_84_r )
651{
652   return m_port_84_data;
653}
964654
965DIRECT_UPDATE_HANDLER( kc85_4_opbaseoverride )
655
656/* port 0x86/0x87:
657
658bit 7: ROCC
659bit 6: ROF1
660bit 5: ROF0
661bit 4-2 are not connected
662bit 1: WRITE PROTECT RAM 4
663bit 0: ACCESS RAM 4
664*/
665
666WRITE8_MEMBER( kc85_4_state::kc85_4_86_w )
966667{
967   memory_set_direct_update_handler(0,0);
668   LOG(("0x86 W: %02x\n", data));
968669
969   kc85_4_update_0x00000(machine);
670   m_port_86_data = data;
970671
971   return (cpunum_get_reg(0, STATE_GENPC) & 0x0ffff);
672   update_0x0c000();
673   update_0x04000();
972674}
973#endif
974675
975
976static TIMER_CALLBACK(kc85_reset_timer_callback)
676READ8_MEMBER( kc85_4_state::kc85_4_86_r )
977677{
978   cpu_set_reg(machine.device("maincpu"), STATE_GENPC, 0x0f000);
678   return m_port_86_data;
979679}
980680
681/*****************************************************************/
981682
683
982684/* callback for ardy output from PIO */
983685/* used in KC85/4 & KC85/3 cassette interface */
984static void kc85_pio_ardy_callback(device_t *device, int state)
686WRITE_LINE_MEMBER( kc_state::pio_ardy_cb)
985687{
986   kc_state *drvstate = device->machine().driver_data<kc_state>();
987   drvstate->m_ardy = state & 0x01;
988
989   if (state)
990   {
991      LOG(("PIO A Ready\n"));
992   }
688   m_ardy = state & 0x01;
993689}
994690
995691/* callback for brdy output from PIO */
996692/* used in KC85/4 & KC85/3 keyboard interface */
997static void kc85_pio_brdy_callback(device_t *device, int state)
693WRITE_LINE_MEMBER( kc_state::pio_brdy_cb)
998694{
999   kc_state *drvstate = device->machine().driver_data<kc_state>();
1000   drvstate->m_brdy = state & 0x01;
1001
1002   if (state)
1003   {
1004      LOG(("PIO B Ready\n"));
1005   }
695   m_brdy = state & 0x01;
1006696}
1007697
1008Z80PIO_INTERFACE( kc85_2_pio_intf )
1009{
1010   DEVCB_CPU_INPUT_LINE("maincpu", 0),                  /* callback when change interrupt status */
1011   DEVCB_HANDLER(kc85_3_pio_porta_r),                  /* port A read callback */
1012   DEVCB_HANDLER(kc85_3_pio_porta_w),                  /* port A write callback */
1013   DEVCB_LINE(kc85_pio_ardy_callback),                  /* portA ready active callback */
1014   DEVCB_HANDLER(kc85_3_pio_portb_r),                  /* port B read callback */
1015   DEVCB_HANDLER(kc85_3_pio_portb_w),                  /* port B write callback */
1016   DEVCB_LINE(kc85_pio_brdy_callback)                  /* portB ready active callback */
1017};
1018
1019Z80PIO_INTERFACE( kc85_4_pio_intf )
1020{
1021   DEVCB_CPU_INPUT_LINE("maincpu", 0),                  /* callback when change interrupt status */
1022   DEVCB_HANDLER(kc85_4_pio_porta_r),                  /* port A read callback */
1023   DEVCB_HANDLER(kc85_4_pio_porta_w),                  /* port A write callback */
1024   DEVCB_LINE(kc85_pio_ardy_callback),                  /* portA ready active callback */
1025   DEVCB_HANDLER(kc85_4_pio_portb_r),                  /* port B read callback */
1026   DEVCB_HANDLER(kc85_4_pio_portb_w),                  /* port B write callback */
1027   DEVCB_LINE(kc85_pio_brdy_callback)                  /* portB ready active callback */
1028};
1029
1030698/* used in cassette write -> K0 */
1031static WRITE_LINE_DEVICE_HANDLER(kc85_zc0_callback)
699WRITE_LINE_MEMBER( kc_state::ctc_zc0_callback )
1032700{
1033701
1034
1035702}
1036703
1037704/* used in cassette write -> K1 */
1038static WRITE_LINE_DEVICE_HANDLER(kc85_zc1_callback)
705WRITE_LINE_MEMBER( kc_state::ctc_zc1_callback)
1039706{
1040707
1041708}
1042709
1043
1044static TIMER_CALLBACK(kc85_15khz_timer_callback)
710static TIMER_CALLBACK(kc85_15khz_timer_callback )
1045711{
1046   device_t *device = (device_t *)ptr;
1047   kc_state *state = device->machine().driver_data<kc_state>();
712   kc_state *state = machine.driver_data<kc_state>();
1048713
1049714   /* toggle state of square wave */
1050715   state->m_kc85_15khz_state^=1;
1051716
1052717   /* set clock input for channel 2 and 3 to ctc */
1053   z80ctc_trg0_w(device, state->m_kc85_15khz_state);
1054   z80ctc_trg1_w(device, state->m_kc85_15khz_state);
718   z80ctc_trg0_w(state->m_z80ctc, state->m_kc85_15khz_state);
719   z80ctc_trg1_w(state->m_z80ctc, state->m_kc85_15khz_state);
720}
1055721
1056   state->m_kc85_15khz_count++;
722static TIMER_CALLBACK(kc85_50hz_timer_callback)
723{
724   kc_state *state = machine.driver_data<kc_state>();
1057725
1058   if (state->m_kc85_15khz_count>=312)
1059   {
1060      state->m_kc85_15khz_count = 0;
726   /* toggle state of square wave */
727   state->m_kc85_50hz_state^=1;
1061728
1062      /* toggle state of square wave */
1063      state->m_kc85_50hz_state^=1;
1064
1065      /* set clock input for channel 2 and 3 to ctc */
1066      z80ctc_trg2_w(device, state->m_kc85_50hz_state);
1067      z80ctc_trg3_w(device, state->m_kc85_50hz_state);
1068   }
729   /* set clock input for channel 2 and 3 to ctc */
730   z80ctc_trg2_w(state->m_z80ctc, state->m_kc85_50hz_state);
731   z80ctc_trg3_w(state->m_z80ctc, state->m_kc85_50hz_state);
1069732}
1070733
1071734/* video blink */
1072static WRITE_LINE_DEVICE_HANDLER( kc85_zc2_callback )
735WRITE_LINE_MEMBER( kc_state::ctc_zc2_callback )
1073736{
1074   kc_state *drvstate = device->machine().driver_data<kc_state>();
1075737   /* is blink enabled? */
1076   if (drvstate->m_kc85_pio_data[1] & (1<<7))
738   if (m_pio_data[1] & (1<<7))
1077739   {
1078740      /* yes */
1079741      /* toggle state of blink to video hardware */
1080      kc85_video_set_blink_state(device->machine(), state);
742      kc85_video_set_blink_state(machine(), state);
1081743   }
1082744}
1083745
1084Z80CTC_INTERFACE( kc85_ctc_intf )
1085{
1086   0,
1087    DEVCB_CPU_INPUT_LINE("maincpu", 0),
1088   DEVCB_LINE(kc85_zc0_callback),
1089   DEVCB_LINE(kc85_zc1_callback),
1090    DEVCB_LINE(kc85_zc2_callback)
1091};
1092746
1093
1094747/* keyboard callback */
1095WRITE_LINE_DEVICE_HANDLER(kc85_keyboard_cb)
748WRITE_LINE_MEMBER( kc_state::keyboard_cb )
1096749{
1097   kc_state *drv_state = device->machine().driver_data<kc_state>();
1098   z80pio_bstb_w(device->machine().device("z80pio"), state & drv_state->m_brdy);
750   z80pio_bstb_w(m_z80pio, state & m_brdy);
1099751
1100   /* FIXME: understand why the PIO fail to acknowledge the irq on kc85_2/3 */
1101   z80pio_d_w(device->machine().device("z80pio"), 1, drv_state->m_kc85_pio_data[1]);
752   // FIXME: understand why the PIO fail to acknowledge the irq on kc85_2/3
753   z80pio_d_w(m_z80pio, 1, m_pio_data[1]);
1102754}
1103755
1104756
1105const kc_keyb_interface kc85_keyboard_interface =
757void kc_state::machine_start()
1106758{
1107   DEVCB_LINE(kc85_keyboard_cb)
1108};
759   m_cassette_timer = machine().scheduler().timer_alloc(FUNC(kc_cassette_timer_callback));
1109760
1110MACHINE_START(kc85)
1111{
1112   kc_cassette_init(machine);
761   // kc85 has a 50 Hz input to the ctc channel 2 and 3
762   // channel 2 this controls the video colour flash
763   // kc85 has a 15 kHz (?) input to the ctc channel 0 and 1
764   // channel 0 and channel 1 are used for cassette write
765   machine().scheduler().timer_pulse(attotime::from_hz(50), FUNC(kc85_50hz_timer_callback), 0, NULL);
766   machine().scheduler().timer_pulse(attotime::from_hz(15625), FUNC(kc85_15khz_timer_callback), 0, NULL);
1113767
1114   machine.scheduler().timer_pulse(attotime::from_hz(15625), FUNC(kc85_15khz_timer_callback), 0, (void *)machine.device("z80ctc"));
1115   machine.scheduler().timer_set(attotime::zero, FUNC(kc85_reset_timer_callback));
1116}
768   m_ram_base = ram_get_ptr(m_ram);
1117769
1118static void   kc85_common_init(running_machine &machine)
1119{
1120   kc_state *state = machine.driver_data<kc_state>();
1121
1122   /* kc85 has a 50 Hz input to the ctc channel 2 and 3 */
1123   /* channel 2 this controls the video colour flash */
1124   /* kc85 has a 15 kHz (?) input to the ctc channel 0 and 1 */
1125   /* channel 0 and channel 1 are used for cassette write */
1126   state->m_kc85_50hz_state = 0;
1127   state->m_kc85_15khz_state = 0;
1128   state->m_kc85_15khz_count = 0;
1129   kc85_module_system_init(machine);
770   m_expansions[0] = machine().device<kcexp_slot_device>("m1");
771   m_expansions[1] = machine().device<kcexp_slot_device>("m2");
772   m_expansions[2] = machine().device<kcexp_slot_device>("exp");
1130773}
1131774
1132/*****************************************************************/
1133
1134MACHINE_RESET( kc85_4 )
775void kc_state::machine_reset()
1135776{
1136   kc_state *state = machine.driver_data<kc_state>();
1137   state->m_kc85_84_data = 0x0828;
1138   state->m_kc85_86_data = 0x063;
1139   /* enable CAOS rom in range 0x0e000-0x0ffff */
1140   /* ram0 enable, irm enable */
1141   state->m_kc85_pio_data[0] = 0x0f;
1142   state->m_kc85_pio_data[1] = 0x0f1;
777   m_pio_data[0] = 0x0f;
778   m_pio_data[1] = 0xf1;
1143779
1144   state->m_kc85_z80pio = machine.device("z80pio");
780   update_0x00000();
781   update_0x04000();
782   update_0x08000();
783   update_0x0c000();
784   update_0x0e000();
1145785
1146   kc85_4_update_0x04000(machine);
1147   kc85_4_update_0x08000(machine);
1148   kc85_4_update_0x0c000(machine);
1149   kc85_4_update_0x0e000(machine);
786   m_kc85_50hz_state = 0;
787   m_kc85_15khz_state = 0;
1150788
1151   kc85_common_init(machine);
1152
1153   kc85_4_update_0x00000(machine);
1154
1155
1156#if 0
1157789   /* this is temporary. Normally when a Z80 is reset, it will
1158790    execute address 0. It appears the KC85 series pages the rom
1159791    at address 0x0000-0x01000 which has a single jump in it,
1160792    can't see yet where it disables it later!!!! so for now
1161793    here will be a override */
1162   memory_set_direct_update_handler(0, kc85_4_opbaseoverride);
1163#endif
794   cpu_set_reg(m_maincpu, STATE_GENPC, 0x0f000);
1164795}
1165796
1166MACHINE_RESET( kc85_3 )
797void kc85_4_state::machine_reset()
1167798{
1168   kc_state *state = machine.driver_data<kc_state>();
1169   state->m_kc85_pio_data[0] = 0x0f;
1170   state->m_kc85_pio_data[1] = 0x0f1;
799   kc_state::machine_reset();
1171800
1172   memory_set_bankptr(machine, "bank2",ram_get_ptr(machine.device(RAM_TAG))+0x0c000);
1173   memory_set_bankptr(machine, "bank7",ram_get_ptr(machine.device(RAM_TAG))+0x0c000);
1174
1175   state->m_kc85_z80pio = machine.device("z80pio");
1176
1177   kc85_3_update_0x08000(machine);
1178   kc85_3_update_0x0c000(machine);
1179   kc85_3_update_0x0e000(machine);
1180
1181   kc85_common_init(machine);
1182
1183   kc85_3_update_0x00000(machine);
1184
1185#if 0
1186   /* this is temporary. Normally when a Z80 is reset, it will
1187    execute address 0. It appears the KC85 series pages the rom
1188    at address 0x0000-0x01000 which has a single jump in it,
1189    can't see yet where it disables it later!!!! so for now
1190    here will be a override */
1191   memory_set_direct_update_handler(0, kc85_3_opbaseoverride);
1192#endif
801   m_port_84_data = 0x00;
802   m_port_86_data = 0x00;
1193803}
src/mess/video/kc.c
r12881r12882
88
99#include "emu.h"
1010#include "includes/kc.h"
11#include "machine/ram.h"
1211
1312/* KC85/4 and KC85/3 common graphics hardware */
1413
r12881r12882
564563
565564
566565
567VIDEO_START( kc85_4 )
566void kc85_4_state::video_start()
568567{
569   kc_state *state = machine.driver_data<kc_state>();
570   kc85_common_vh_start(machine);
568   kc85_common_vh_start(machine());
571569
572   state->m_kc85_4_video_ram = auto_alloc_array(machine, UINT8,
570   m_video_ram = auto_alloc_array(machine(), UINT8,
573571      (KC85_4_SCREEN_COLOUR_RAM_SIZE*2) +
574572      (KC85_4_SCREEN_PIXEL_RAM_SIZE*2));
575573
576   state->m_kc85_4_display_video_ram = state->m_kc85_4_video_ram;
574   m_display_video_ram = m_video_ram;
577575}
578576
579577void kc85_4_video_ram_select_bank(running_machine &machine, int bank)
580578{
581   kc_state *state = machine.driver_data<kc_state>();
579   kc85_4_state *state = machine.driver_data<kc85_4_state>();
582580   /* calculate address of video ram to display */
583581   unsigned char *video_ram;
584582
585   video_ram = state->m_kc85_4_video_ram;
583   video_ram = state->m_video_ram;
586584
587585   if (bank!=0)
588586   {
r12881r12882
591589               KC85_4_SCREEN_COLOUR_RAM_SIZE);
592590   }
593591
594   state->m_kc85_4_display_video_ram = video_ram;
592   state->m_display_video_ram = video_ram;
595593}
596594
597595unsigned char *kc85_4_get_video_ram_base(running_machine &machine, int bank, int colour)
598596{
599   kc_state *state = machine.driver_data<kc_state>();
597   kc85_4_state *state = machine.driver_data<kc85_4_state>();
600598   /* base address: screen 0 pixel data */
601   unsigned char *addr = state->m_kc85_4_video_ram;
599   unsigned char *addr = state->m_video_ram;
602600
603601   if (bank!=0)
604602   {
r12881r12882
635633***************************************************************************/
636634SCREEN_UPDATE( kc85_4 )
637635{
638   kc_state *state = screen->machine().driver_data<kc_state>();
636   kc85_4_state *state = screen->machine().driver_data<kc85_4_state>();
639637#if 0
640   unsigned char *pixel_ram = state->m_kc85_4_display_video_ram;
638   unsigned char *pixel_ram = state->m_display_video_ram;
641639   unsigned char *colour_ram = pixel_ram + 0x04000;
642640
643641   int x,y;
r12881r12882
661659#endif
662660   struct grab_info grab_data;
663661
664   grab_data.pixel_ram = state->m_kc85_4_display_video_ram;
665   grab_data.colour_ram = state->m_kc85_4_display_video_ram + 0x04000;
662   grab_data.pixel_ram = state->m_display_video_ram;
663   grab_data.colour_ram = state->m_display_video_ram + 0x04000;
666664
667665   kc85_common_process_frame(screen->machine(), bitmap, kc85_4_pixel_grab_callback,&grab_data);
668666
r12881r12882
673671 KC85/3 video
674672***************************************************************************/
675673
676VIDEO_START( kc85_3 )
674void kc_state::video_start()
677675{
678   kc85_common_vh_start(machine);
676   kc85_common_vh_start(machine());
679677}
680678
681679
r12881r12882
715713***************************************************************************/
716714SCREEN_UPDATE( kc85_3 )
717715{
716   kc_state *state = screen->machine().driver_data<kc_state>();
717
718718#if 0
719719   /* colour ram takes up 0x02800 bytes */
720720      unsigned char *pixel_ram = ram_get_ptr(machine.device(RAM_TAG))+0x08000;
r12881r12882
758758
759759   struct grab_info grab_data;
760760
761   grab_data.pixel_ram = ram_get_ptr(screen->machine().device(RAM_TAG))+0x08000;
762   grab_data.colour_ram = ram_get_ptr(screen->machine().device(RAM_TAG))+0x08000 + 0x02800;
761   grab_data.pixel_ram = state->m_ram_base + 0x04000;
762   grab_data.colour_ram = state->m_ram_base + 0x04000 + 0x02800;
763763
764764   kc85_common_process_frame(screen->machine(), bitmap, kc85_3_pixel_grab_callback,&grab_data);
765765
src/mess/includes/kc.h
r12881r12882
77#ifndef KC_H_
88#define KC_H_
99
10/* Devices */
11#include "imagedev/cassette.h"
12#include "machine/ram.h"
13
14// Components
15#include "cpu/z80/z80.h"
1016#include "cpu/z80/z80daisy.h"
1117#include "machine/z80ctc.h"
1218#include "machine/z80pio.h"
19#include "machine/ram.h"
20#include "machine/kc_keyb.h"
21#include "cpu/z80/z80daisy.h"
22#include "sound/speaker.h"
23#include "sound/wave.h"
24
25// Devices
26#include "imagedev/cassette.h"
1327#include "imagedev/snapquik.h"
14#include "machine/kc_keyb.h"
28
29// Expansions
1530#include "machine/kcexp.h"
1631#include "machine/kc_ram.h"
1732#include "machine/kc_rom.h"
1833#include "machine/kc_d002.h"
1934#include "machine/kc_d004.h"
2035
36
2137#define KC85_4_CLOCK 1750000
2238#define KC85_3_CLOCK 1750000
2339
r12881r12882
3349{
3450public:
3551   kc_state(const machine_config &mconfig, device_type type, const char *tag)
36      : driver_device(mconfig, type, tag) { }
52      : driver_device(mconfig, type, tag),
53        m_maincpu(*this, "maincpu"),
54        m_z80pio(*this, "z80pio"),
55        m_z80ctc(*this, "z80ctc"),
56        m_ram(*this, RAM_TAG),
57        m_speaker(*this, SPEAKER_TAG),
58        m_cassette(*this, CASSETTE_TAG)
59   { }
3760
38   int m_kc85_pio_data[2];
39   device_t *m_kc85_z80pio;
40   emu_timer *m_cassette_timer;
41   int m_cassette_motor_state;
42   unsigned char m_ardy;
43   unsigned char m_brdy;
44   int m_kc85_84_data;
45   int m_kc85_86_data;
46   int m_kc85_50hz_state;
47   int m_kc85_15khz_state;
48   int m_kc85_15khz_count;
49   int m_kc85_blink_state;
50   unsigned char *m_kc85_4_display_video_ram;
51   unsigned char *m_kc85_4_video_ram;
61   required_device<cpu_device> m_maincpu;
62   required_device<z80pio_device> m_z80pio;
63   required_device<z80ctc_device> m_z80ctc;
64   required_device<device_t> m_ram;
65   required_device<device_t> m_speaker;
66   required_device<cassette_image_device> m_cassette;
5267
53   kcexp_slot_device *m_expansions[3];
68   // defined in machine/kc.c
69   virtual void machine_start();
70   virtual void machine_reset();
71
72   // modules read/write
73   DECLARE_READ8_MEMBER ( expansion_read );
74   DECLARE_WRITE8_MEMBER( expansion_write );
75   DECLARE_READ8_MEMBER ( expansion_4000_r );
76   DECLARE_WRITE8_MEMBER( expansion_4000_w );
77   DECLARE_READ8_MEMBER ( expansion_8000_r );
78   DECLARE_WRITE8_MEMBER( expansion_8000_w );
79   DECLARE_READ8_MEMBER ( expansion_c000_r );
80   DECLARE_WRITE8_MEMBER( expansion_c000_w );
81   DECLARE_READ8_MEMBER ( expansion_e000_r );
82   DECLARE_WRITE8_MEMBER( expansion_e000_w );
83   DECLARE_READ8_MEMBER ( expansion_io_read );
84   DECLARE_WRITE8_MEMBER( expansion_io_write );
85
86   // bankswitch
87   virtual void update_0x00000();
88   virtual void update_0x04000();
89   virtual void update_0x08000();
90   virtual void update_0x0c000();
91   virtual void update_0x0e000();
92
93   // PIO callback
94   DECLARE_READ8_MEMBER( pio_porta_r );
95   DECLARE_READ8_MEMBER( pio_portb_r );
96   DECLARE_WRITE_LINE_MEMBER( pio_ardy_cb);
97   DECLARE_WRITE_LINE_MEMBER( pio_brdy_cb);
98   DECLARE_WRITE8_MEMBER( pio_porta_w );
99   DECLARE_WRITE8_MEMBER( pio_portb_w );
100
101   // CTC callback
102   DECLARE_WRITE_LINE_MEMBER( ctc_zc0_callback );
103   DECLARE_WRITE_LINE_MEMBER( ctc_zc1_callback );
104   DECLARE_WRITE_LINE_MEMBER( ctc_zc2_callback );
105
106   // keyboard
107   DECLARE_WRITE_LINE_MEMBER( keyboard_cb );
108
109   // cassette
110   void cassette_set_motor(int motor_state);
111
112   // defined in video/kc.c
113   virtual void video_start();
114
115   // driver state
116   UINT8 *            m_ram_base;
117   int             m_pio_data[2];
118   emu_timer *         m_cassette_timer;
119   int             m_cassette_motor_state;
120   UINT8            m_ardy;
121   UINT8            m_brdy;
122   int             m_kc85_50hz_state;
123   int             m_kc85_15khz_state;
124   int               m_kc85_blink_state;
125
126   kcexp_slot_device *   m_expansions[3];
54127};
55128
56129
130class kc85_4_state : public kc_state
131{
132public:
133   kc85_4_state(const machine_config &mconfig, device_type type, const char *tag)
134      : kc_state(mconfig, type, tag)
135      { }
136
137   // defined in machine/kc.c
138   virtual void machine_reset();
139
140   virtual void update_0x04000();
141   virtual void update_0x08000();
142   virtual void update_0x0c000();
143
144   DECLARE_READ8_MEMBER( kc85_4_86_r );
145   DECLARE_READ8_MEMBER( kc85_4_84_r );
146   DECLARE_WRITE8_MEMBER( kc85_4_86_w );
147   DECLARE_WRITE8_MEMBER( kc85_4_84_w );
148
149   // defined in video/kc.c
150   virtual void video_start();
151
152   // driver state
153   UINT8            m_port_84_data;
154   UINT8            m_port_86_data;
155   UINT8 *            m_video_ram;
156   UINT8 *            m_display_video_ram;
157};
158
159
57160/*----------- defined in video/kc.c -----------*/
58161
59162extern PALETTE_INIT( kc85 );
60163
61164void kc85_video_set_blink_state(running_machine &machine, int data);
62165
63VIDEO_START( kc85_3 );
64VIDEO_START( kc85_4 );
65166SCREEN_UPDATE( kc85_3 );
66167SCREEN_UPDATE( kc85_4 );
67168
r12881r12882
75176
76177QUICKLOAD_LOAD( kc );
77178
78MACHINE_START( kc85 );
79MACHINE_RESET( kc85_3 );
80MACHINE_RESET( kc85_4 );
81
82/* cassette */
83READ8_HANDLER(kc85_4_84_r);
84WRITE8_HANDLER(kc85_4_84_w);
85
86READ8_HANDLER(kc85_4_86_r);
87WRITE8_HANDLER(kc85_4_86_w);
88
89extern const z80pio_interface kc85_2_pio_intf;
90extern const z80pio_interface kc85_4_pio_intf;
91extern const z80ctc_interface kc85_ctc_intf;
92extern const kc_keyb_interface kc85_keyboard_interface;
93
94
95/*** MODULE SYSTEM ***/
96
97READ8_HANDLER ( kc_expansion_io_read );
98WRITE8_HANDLER ( kc_expansion_io_write );
99
100179#endif /* KC_H_ */
src/mess/drivers/kc.c
r12881r12882
1111
1212 ******************************************************************************/
1313
14 #define ADDRESS_MAP_MODERN
15
1416/* Core includes */
1517#include "emu.h"
1618#include "includes/kc.h"
1719
18/* Components */
19#include "machine/z80ctc.h"
20#include "machine/z80pio.h"
21#include "machine/z80sio.h"
22#include "cpu/z80/z80.h"
23#include "cpu/z80/z80daisy.h"
24#include "sound/speaker.h"
25#include "sound/wave.h"
2620
27/* Devices */
28#include "imagedev/cassette.h"
29#include "machine/ram.h"
30
31static ADDRESS_MAP_START(kc85_4_io, AS_IO, 8)
21static ADDRESS_MAP_START(kc85_4_io, AS_IO, 8, kc85_4_state)
3222   ADDRESS_MAP_UNMAP_HIGH
3323   AM_RANGE(0x0084, 0x0085) AM_MIRROR(0xff00) AM_READWRITE(kc85_4_84_r, kc85_4_84_w)
3424   AM_RANGE(0x0086, 0x0087) AM_MIRROR(0xff00) AM_READWRITE(kc85_4_86_r, kc85_4_86_w)
35   AM_RANGE(0x0088, 0x008b) AM_MIRROR(0xff00) AM_DEVREADWRITE("z80pio", z80pio_cd_ba_r, z80pio_cd_ba_w)
36   AM_RANGE(0x008c, 0x008f) AM_MIRROR(0xff00) AM_DEVREADWRITE("z80ctc", z80ctc_r, z80ctc_w)
25   AM_RANGE(0x0088, 0x008b) AM_MIRROR(0xff00) AM_DEVREADWRITE_LEGACY("z80pio", z80pio_cd_ba_r, z80pio_cd_ba_w)
26   AM_RANGE(0x008c, 0x008f) AM_MIRROR(0xff00) AM_DEVREADWRITE_LEGACY("z80ctc", z80ctc_r, z80ctc_w)
3727
38   AM_RANGE(0x0000, 0xffff) AM_READWRITE(kc_expansion_io_read, kc_expansion_io_write)
28   AM_RANGE(0x0000, 0xffff) AM_READWRITE(expansion_io_read, expansion_io_write)
3929ADDRESS_MAP_END
4030
41static ADDRESS_MAP_START(kc85_4_mem, AS_PROGRAM, 8)
31static ADDRESS_MAP_START(kc85_4_mem, AS_PROGRAM, 8, kc85_4_state)
4232   ADDRESS_MAP_UNMAP_HIGH
43   AM_RANGE(0x0000, 0x3fff) AM_READ_BANK("bank1") AM_WRITE_BANK("bank7")
44   AM_RANGE(0x4000, 0x7fff) AM_READ_BANK("bank2") AM_WRITE_BANK("bank8")
45   AM_RANGE(0x8000, 0xa7ff) AM_READ_BANK("bank3") AM_WRITE_BANK("bank9")
46//  AM_RANGE(0xa800, 0xbfff) AM_RAM
47   AM_RANGE(0xa800, 0xbfff) AM_READ_BANK("bank4") AM_WRITE_BANK("bank10")
48   AM_RANGE(0xc000, 0xdfff) AM_READ_BANK("bank5")
49   AM_RANGE(0xe000, 0xffff) AM_READ_BANK("bank6")
33   AM_RANGE(0x0000, 0x3fff) AM_READWRITE_BANK("bank1")
34   AM_RANGE(0x4000, 0x7fff) AM_READWRITE_BANK("bank2")
35   AM_RANGE(0x8000, 0xa7ff) AM_READWRITE_BANK("bank3")
36   AM_RANGE(0xa800, 0xbfff) AM_READWRITE_BANK("bank6")
37   AM_RANGE(0xc000, 0xdfff) AM_READ_BANK("bank4")
38   AM_RANGE(0xe000, 0xffff) AM_READ_BANK("bank5")
5039ADDRESS_MAP_END
5140
52static ADDRESS_MAP_START(kc85_3_mem, AS_PROGRAM, 8)
41static ADDRESS_MAP_START(kc85_3_mem, AS_PROGRAM, 8, kc_state)
5342   ADDRESS_MAP_UNMAP_HIGH
54   AM_RANGE(0x0000, 0x3fff) AM_READ_BANK("bank1") AM_WRITE_BANK("bank6")
55   AM_RANGE(0x4000, 0x7fff) AM_READ_BANK("bank2") AM_WRITE_BANK("bank7")
56   AM_RANGE(0x8000, 0xbfff) AM_READ_BANK("bank3") AM_WRITE_BANK("bank8")
43   AM_RANGE(0x0000, 0x3fff) AM_READWRITE_BANK("bank1")
44   AM_RANGE(0x4000, 0x7fff) AM_READWRITE_BANK("bank2")
45   AM_RANGE(0x8000, 0xbfff) AM_READWRITE_BANK("bank3")
5746   AM_RANGE(0xc000, 0xdfff) AM_READ_BANK("bank4")
5847   AM_RANGE(0xe000, 0xffff) AM_READ_BANK("bank5")
5948ADDRESS_MAP_END
6049
61static ADDRESS_MAP_START(kc85_3_io, AS_IO, 8)
50static ADDRESS_MAP_START(kc85_3_io, AS_IO, 8, kc_state)
6251   ADDRESS_MAP_UNMAP_HIGH
63   AM_RANGE(0x0088, 0x008b) AM_MIRROR(0xff00) AM_DEVREADWRITE("z80pio", z80pio_cd_ba_r, z80pio_cd_ba_w)
64   AM_RANGE(0x008c, 0x008f) AM_MIRROR(0xff00) AM_DEVREADWRITE("z80ctc", z80ctc_r, z80ctc_w)
52   AM_RANGE(0x0088, 0x008b) AM_MIRROR(0xff00) AM_DEVREADWRITE_LEGACY("z80pio", z80pio_cd_ba_r, z80pio_cd_ba_w)
53   AM_RANGE(0x008c, 0x008f) AM_MIRROR(0xff00) AM_DEVREADWRITE_LEGACY("z80ctc", z80ctc_r, z80ctc_w)
6554
66   AM_RANGE(0x0000, 0xffff) AM_READWRITE(kc_expansion_io_read, kc_expansion_io_write)
55   AM_RANGE(0x0000, 0xffff) AM_READWRITE(expansion_io_read, expansion_io_write)
6756ADDRESS_MAP_END
6857
6958static INPUT_PORTS_START( kc85 )
r12881r12882
7160
7261
7362/* pio is last in chain and therefore has highest priority */
74
7563static const z80_daisy_config kc85_daisy_chain[] =
7664{
7765   { "z80pio" },
r12881r12882
10492SLOT_INTERFACE_END
10593
10694
95Z80PIO_INTERFACE( kc85_pio_intf )
96{
97   DEVCB_CPU_INPUT_LINE("maincpu", 0),                  /* callback when change interrupt status */
98   DEVCB_DRIVER_MEMBER(kc_state, pio_porta_r),            /* port A read callback */
99   DEVCB_DRIVER_MEMBER(kc_state, pio_porta_w),            /* port A write callback */
100   DEVCB_DRIVER_LINE_MEMBER(kc_state, pio_ardy_cb),      /* portA ready active callback */
101   DEVCB_DRIVER_MEMBER(kc_state, pio_portb_r),            /* port B read callback */
102   DEVCB_DRIVER_MEMBER(kc_state, pio_portb_w),            /* port B write callback */
103   DEVCB_DRIVER_LINE_MEMBER(kc_state, pio_brdy_cb)         /* portB ready active callback */
104};
105
106Z80CTC_INTERFACE( kc85_ctc_intf )
107{
108   0,
109    DEVCB_CPU_INPUT_LINE("maincpu", 0),
110   DEVCB_DRIVER_LINE_MEMBER(kc_state, ctc_zc0_callback),
111   DEVCB_DRIVER_LINE_MEMBER(kc_state, ctc_zc1_callback),
112   DEVCB_DRIVER_LINE_MEMBER(kc_state, ctc_zc2_callback)
113};
114
115const kc_keyb_interface kc85_keyboard_interface =
116{
117   DEVCB_DRIVER_LINE_MEMBER(kc_state, keyboard_cb)
118};
119
107120static MACHINE_CONFIG_START( kc85_3, kc_state )
108121   /* basic machine hardware */
109122   MCFG_CPU_ADD("maincpu", Z80, KC85_3_CLOCK)
r12881r12882
112125   MCFG_CPU_CONFIG(kc85_daisy_chain)
113126   MCFG_QUANTUM_TIME(attotime::from_hz(60))
114127
115   MCFG_MACHINE_START( kc85 )
116   MCFG_MACHINE_RESET( kc85_3 )
117
118   MCFG_Z80PIO_ADD( "z80pio", 1379310.344828, kc85_2_pio_intf )
128   MCFG_Z80PIO_ADD( "z80pio", 1379310.344828, kc85_pio_intf )
119129   MCFG_Z80CTC_ADD( "z80ctc", 1379310.344828, kc85_ctc_intf )
120130
121131   /* video hardware */
r12881r12882
130140   MCFG_PALETTE_LENGTH(KC85_PALETTE_SIZE)
131141   MCFG_PALETTE_INIT( kc85 )
132142
133   MCFG_VIDEO_START( kc85_3 )
134
135143   MCFG_KC_KEYBOARD_ADD("keyboard", XTAL_4MHz, kc85_keyboard_interface)
136144
137145   /* sound hardware */
r12881r12882
158166
159167   /* internal ram */
160168   MCFG_RAM_ADD(RAM_TAG)
161   MCFG_RAM_DEFAULT_SIZE("64K")
169   MCFG_RAM_DEFAULT_SIZE("32K")
162170MACHINE_CONFIG_END
163171
164172
165static MACHINE_CONFIG_DERIVED( kc85_4, kc85_3 )
166
167   MCFG_CPU_REPLACE("maincpu", Z80, KC85_4_CLOCK)
173static MACHINE_CONFIG_START( kc85_4, kc85_4_state )
174   /* basic machine hardware */
175   MCFG_CPU_ADD("maincpu", Z80, KC85_4_CLOCK)
168176   MCFG_CPU_PROGRAM_MAP(kc85_4_mem)
169177   MCFG_CPU_IO_MAP(kc85_4_io)
170178   MCFG_CPU_CONFIG(kc85_daisy_chain)
179   MCFG_QUANTUM_TIME(attotime::from_hz(60))
171180
172   MCFG_MACHINE_RESET( kc85_4 )
181   MCFG_Z80PIO_ADD( "z80pio", 1379310.344828, kc85_pio_intf )
182   MCFG_Z80CTC_ADD( "z80ctc", 1379310.344828, kc85_ctc_intf )
173183
174   MCFG_VIDEO_START( kc85_4 )
184   /* video hardware */
185   MCFG_SCREEN_ADD("screen", RASTER)
186   MCFG_SCREEN_REFRESH_RATE(50)
187   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
188   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
189   MCFG_SCREEN_SIZE(KC85_SCREEN_WIDTH, KC85_SCREEN_HEIGHT)
190   MCFG_SCREEN_VISIBLE_AREA(0, (KC85_SCREEN_WIDTH - 1), 0, (KC85_SCREEN_HEIGHT - 1))
191   MCFG_SCREEN_UPDATE( kc85_4 )
175192
176   MCFG_DEVICE_REMOVE( "z80pio" )
177   MCFG_Z80PIO_ADD( "z80pio", 1379310.344828, kc85_4_pio_intf )
193   MCFG_PALETTE_LENGTH(KC85_PALETTE_SIZE)
194   MCFG_PALETTE_INIT( kc85 )
178195
179   MCFG_SCREEN_MODIFY("screen")
180   MCFG_SCREEN_UPDATE( kc85_4 )
196   MCFG_KC_KEYBOARD_ADD("keyboard", XTAL_4MHz, kc85_keyboard_interface)
197
198   /* sound hardware */
199   MCFG_SPEAKER_STANDARD_MONO("mono")
200   MCFG_SOUND_WAVE_ADD(WAVE_TAG, CASSETTE_TAG)
201   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
202   MCFG_SOUND_ADD(SPEAKER_TAG, SPEAKER_SOUND, 0)
203   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
204
205   /* devices */
206   MCFG_QUICKLOAD_ADD("quickload", kc, "kcc", 2)
207
208   MCFG_CASSETTE_ADD( CASSETTE_TAG, default_cassette_interface )
209
210   /* cartridge slot */
211   MCFG_KC85_CARTRIDGE_ADD("m1", "m2", kc85_exp_interface, kc85_cart, NULL, NULL)
212   MCFG_KC85_CARTRIDGE_ADD("m2", "exp", kc85_exp_interface, kc85_cart, NULL, NULL)
213
214   /* expansion interface */
215   MCFG_KC85_EXPANSION_ADD("exp", NULL, kc85_exp_interface, kc85_exp , NULL, NULL)
216
217   /* Software lists */
218   MCFG_SOFTWARE_LIST_ADD("cart_list", "kc85_cart")
219
220   /* internal ram */
221   MCFG_RAM_ADD(RAM_TAG)
222   MCFG_RAM_DEFAULT_SIZE("64K")
181223MACHINE_CONFIG_END
182224
183225static MACHINE_CONFIG_DERIVED( kc85_5, kc85_4 )
184
185226   /* internal ram */
186227   MCFG_RAM_MODIFY(RAM_TAG)
187228   MCFG_RAM_DEFAULT_SIZE("224K")
188229MACHINE_CONFIG_END
189230
190ROM_START(kc85_4)
191   ROM_REGION(0x2000, "basic", 0)
192    ROM_LOAD("basic_c0.854", 0x0000, 0x2000, CRC(dfe34b08) SHA1(c2e3af55c79e049e811607364f88c703b0285e2e))
193231
194    ROM_REGION(0x4000, "caos", ROMREGION_ERASEFF)
195    ROM_SYSTEM_BIOS(0, "caos42", "CAOS 4.2" )
196    ROMX_LOAD("caos__c0.854", 0x0000, 0x1000, CRC(57d9ab02) SHA1(774fc2496a59b77c7c392eb5aa46420e7722797e), ROM_BIOS(1))
197    ROMX_LOAD("caos__e0.854", 0x2000, 0x2000, CRC(ee273933) SHA1(4300f7ff813c1fb2d5c928dbbf1c9e1fe52a9577), ROM_BIOS(1))
198   ROM_SYSTEM_BIOS(1, "caos41", "CAOS 4.1" )
199   ROMX_LOAD( "caos41c.854", 0x0000, 0x1000, CRC(c7e1c011) SHA1(acd998e3d9e8f592cd884aafc8ac4d291e40e097), ROM_BIOS(2))
200   ROMX_LOAD( "caos41e.854", 0x2000, 0x2000, CRC(60e045e5) SHA1(e19819fb477dcb742a13729a9bf5943d63abe863), ROM_BIOS(2))
232ROM_START(kc85_2)
233   ROM_REGION(0x4000, "caos", ROMREGION_ERASEFF)
234   ROM_SYSTEM_BIOS(0, "hc900", "HC900 CAOS" )
235   ROMX_LOAD( "hc900.852",    0x2000, 0x2000, CRC(e6f4c0ab) SHA1(242a777788c774c5f764313361b1e0a65139ab32), ROM_BIOS(1))
236   ROM_SYSTEM_BIOS(1, "caos22", "CAOS 2.2" )
237   ROMX_LOAD( "caos__e0.852", 0x2000, 0x2000, CRC(48d5624c) SHA1(568dd59bfad4c604ba36bc05b094fc598a642f85), ROM_BIOS(2))
201238ROM_END
202239
203240ROM_START(kc85_3)
204241   ROM_REGION(0x2000, "basic", 0)
205    ROM_LOAD( "basic_c0.853", 0x0000, 0x2000, CRC(dfe34b08) SHA1(c2e3af55c79e049e811607364f88c703b0285e2e))
242   ROM_LOAD( "basic_c0.853", 0x0000, 0x2000, CRC(dfe34b08) SHA1(c2e3af55c79e049e811607364f88c703b0285e2e))
206243
207244   ROM_REGION(0x4000, "caos", ROMREGION_ERASEFF)
208    ROM_SYSTEM_BIOS(0, "caos31", "CAOS 3.1" )
209   ROMX_LOAD( "caos__e0.853", 0x0000, 0x2000, CRC(639e4864) SHA1(efd002fc9146116936e6e6be0366d2afca33c1ab), ROM_BIOS(1))
245   ROM_SYSTEM_BIOS(0, "caos31", "CAOS 3.1" )
246   ROMX_LOAD( "caos__e0.853", 0x2000, 0x2000, CRC(639e4864) SHA1(efd002fc9146116936e6e6be0366d2afca33c1ab), ROM_BIOS(1))
210247   ROM_SYSTEM_BIOS(1, "caos33", "CAOS 3.3" )
211   ROMX_LOAD( "caos33.853",   0x0000, 0x2000, CRC(ca0fecad) SHA1(20447d27c9aa41a1c7a3d6ad0699edb06a207aa6), ROM_BIOS(2))
248   ROMX_LOAD( "caos33.853",   0x2000, 0x2000, CRC(ca0fecad) SHA1(20447d27c9aa41a1c7a3d6ad0699edb06a207aa6), ROM_BIOS(2))
212249   ROM_SYSTEM_BIOS(2, "caos34", "CAOS 3.4" )
213   ROMX_LOAD( "caos34.853",   0x0000, 0x2000, CRC(d0245a3e) SHA1(ee9f8e7427b9225ae2cecbcfb625d629ab6a601d), ROM_BIOS(3))
250   ROMX_LOAD( "caos34.853",   0x2000, 0x2000, CRC(d0245a3e) SHA1(ee9f8e7427b9225ae2cecbcfb625d629ab6a601d), ROM_BIOS(3))
214251   ROM_SYSTEM_BIOS(3, "pi88ge", "OS PI/88 (yellow/blue)" )
215   ROMX_LOAD( "pi88_ge.853",  0x0000, 0x2000, CRC(4bf0cfde) SHA1(b8373a44e4553197e3dd23008168d5214b878837), ROM_BIOS(4))
252   ROMX_LOAD( "pi88_ge.853",  0x2000, 0x2000, CRC(4bf0cfde) SHA1(b8373a44e4553197e3dd23008168d5214b878837), ROM_BIOS(4))
216253   ROM_SYSTEM_BIOS(4, "pi88sw", "OS PI/88 (black/white)" )
217   ROMX_LOAD( "pi88_sw.853",  0x0000, 0x2000, CRC(f7d2e8fc) SHA1(9b5c068f10ff34bc3253f5b51abad51c8da9dd5d), ROM_BIOS(5))
254   ROMX_LOAD( "pi88_sw.853",  0x2000, 0x2000, CRC(f7d2e8fc) SHA1(9b5c068f10ff34bc3253f5b51abad51c8da9dd5d), ROM_BIOS(5))
218255   ROM_SYSTEM_BIOS(5, "pi88ws", "OS PI/88 (white/blue)" )
219   ROMX_LOAD( "pi88_ws.853",  0x0000, 0x2000, CRC(9ef4efbf) SHA1(b8b6f606b76bce9fb7fcd61a14120e5e026b6b6e), ROM_BIOS(6))
256   ROMX_LOAD( "pi88_ws.853",  0x2000, 0x2000, CRC(9ef4efbf) SHA1(b8b6f606b76bce9fb7fcd61a14120e5e026b6b6e), ROM_BIOS(6))
220257ROM_END
221258
222ROM_START(kc85_2)
259ROM_START(kc85_4)
260   ROM_REGION(0x2000, "basic", 0)
261   ROM_LOAD("basic_c0.854", 0x0000, 0x2000, CRC(dfe34b08) SHA1(c2e3af55c79e049e811607364f88c703b0285e2e))
223262   ROM_REGION(0x4000, "caos", ROMREGION_ERASEFF)
224   ROM_SYSTEM_BIOS(0, "hc900", "HC900 CAOS" )
225   ROMX_LOAD( "hc900.852",    0x0000, 0x2000, CRC(e6f4c0ab) SHA1(242a777788c774c5f764313361b1e0a65139ab32), ROM_BIOS(1))
226   ROM_SYSTEM_BIOS(1, "caos22", "CAOS 2.2" )
227   ROMX_LOAD( "caos__e0.852", 0x0000, 0x2000, CRC(48d5624c) SHA1(568dd59bfad4c604ba36bc05b094fc598a642f85), ROM_BIOS(2))
263   ROM_SYSTEM_BIOS(0, "caos42", "CAOS 4.2" )
264   ROMX_LOAD("caos__c0.854", 0x0000, 0x1000, CRC(57d9ab02) SHA1(774fc2496a59b77c7c392eb5aa46420e7722797e), ROM_BIOS(1))
265   ROMX_LOAD("caos__e0.854", 0x2000, 0x2000, CRC(ee273933) SHA1(4300f7ff813c1fb2d5c928dbbf1c9e1fe52a9577), ROM_BIOS(1))
266   ROM_SYSTEM_BIOS(1, "caos41", "CAOS 4.1" )
267   ROMX_LOAD( "caos41c.854", 0x0000, 0x1000, CRC(c7e1c011) SHA1(acd998e3d9e8f592cd884aafc8ac4d291e40e097), ROM_BIOS(2))
268   ROMX_LOAD( "caos41e.854", 0x2000, 0x2000, CRC(60e045e5) SHA1(e19819fb477dcb742a13729a9bf5943d63abe863), ROM_BIOS(2))
228269ROM_END
229270
230271ROM_START(kc85_5)
r12881r12882
232273   ROM_LOAD("basic_c0.855", 0x0000, 0x8000, CRC(0ed9f8b0) SHA1(be2c68a5b461014c57e33a127c3ffb32b0ff2346))
233274
234275   ROM_REGION(0x4000, "caos", ROMREGION_ERASEFF)
235    ROM_SYSTEM_BIOS(0, "caos44", "CAOS 4.4" )
236    ROMX_LOAD( "caos__c0.855",0x0000, 0x2000, CRC(f56d5c18) SHA1(2cf8023ee71ca50b92f9f151b7519f59727d1c79), ROM_BIOS(1))
276   ROM_SYSTEM_BIOS(0, "caos44", "CAOS 4.4" )
277   ROMX_LOAD( "caos__c0.855",0x0000, 0x2000, CRC(f56d5c18) SHA1(2cf8023ee71ca50b92f9f151b7519f59727d1c79), ROM_BIOS(1))
237278   ROMX_LOAD( "caos__e0.855",0x2000, 0x2000, CRC(1dbc2e6d) SHA1(53ba4394d96e287ff8af01322af1e9879d4e77c4), ROM_BIOS(1))
238279   ROM_SYSTEM_BIOS(1, "caos43", "CAOS 4.3" )
239280   ROMX_LOAD( "caos43c.855", 0x0000, 0x2000, CRC(2f0f9eaa) SHA1(5342be5104206d15e7471b094c7749a8a3d708ad), ROM_BIOS(2))

Previous 15994 Revisions Next


© 1998-2018 The MESS Team