Previous 15994 Revisions Next

r3868 Thursday 18th December, 2008 at 15:37:56 UTC by Miodrag Milanović
WD17XX and NEC765 converted to device
[docs]messnew.txt
[src/mess/devices]coco_fdc.c flopdrv.c flopdrv.h thomflop.c
[src/mess/drivers]a310.c amstrad.c apf.c at.c atarist.c b2m.c bbc.c bebox.c bw2.c cgenie.c coco.c compis.c comx35.c concept.c dgn_beta.c einstein.c enterp.c exidy.c geneve.c kc.c mbee.c msx.c nascom1.c nc.c newbrain.c oric.c orion.c osborne1.c osi.c partner.c pc.c pc8801.c pcw.c pcw16.c pentagon.c samcoupe.c scorpion.c sg1000.c sord.c special.c specpls3.c svi318.c thomson.c ti99_4x.c trs80.c vector06.c x68k.c
[src/mess/includes]bbc.h cgenie.h coco.h compis.h comx35.h concept.h dgn_beta.h kc.h mbee.h msx.h nascom1.h oric.h osborne1.h partner.h pc8801.h samcoupe.h special.h svi318.h trs80.h
[src/mess/machine]99_dsk.c 99_dsk.h at.c b2m.c bbc.c bebox.c beta.c beta.h cgenie.c coco.c compis.c comx35.c concept.c conkort.c dgn_beta.c kc.c mbee.c msx.c msx_slot.c nascom1.c nec765.c nec765.h oric.c orion.c osborne1.c partner.c pc.c pc8801.c pc_fdc.c pc_fdc.h samcoupe.c special.c svi318.c trs80.c vector06.c wd17xx.c wd17xx.h

src/mess/includes/compis.h
r3867r3868
1414
1515#include "driver.h"
1616#include "machine/msm8251.h"
17#include "machine/nec765.h"
1718
1819/*----------- defined in machine/compis.c -----------*/
1920
r3867r3868
2324extern const struct pic8259_interface compis_pic8259_master_config;
2425extern const struct pic8259_interface compis_pic8259_slave_config;
2526extern const msm8251_interface compis_usart_interface;
27extern const nec765_interface compis_fdc_interface;
2628
2729DRIVER_INIT(compis);
2830MACHINE_RESET(compis);
src/mess/includes/kc.h
r3867r3868
1111#include "machine/z80ctc.h"
1212#include "machine/z80pio.h"
1313#include "devices/snapquik.h"
14#include "machine/nec765.h"
1415
15
1616#define KC85_4_CLOCK 1750000
1717#define KC85_3_CLOCK 1750000
1818
r3867r3868
4343
4444/*----------- defined in machine/kc.c -----------*/
4545
46extern const nec765_interface kc_fdc_interface;
4647extern QUICKLOAD_LOAD( kc );
4748
4849MACHINE_RESET( kc85_3 );
src/mess/includes/dgn_beta.h
r3867r3868
77#ifndef DGN_BETA_H_
88#define DGN_BETA_H_
99
10#include "machine/wd17xx.h"
1011
1112#define DGNBETA_CPU_SPEED_HZ      2000000   /* 2MHz */
1213#define DGNBETA_FRAMES_PER_SECOND   50
r3867r3868
6364
6465/*----------- defined in machine/dgn_beta.c -----------*/
6566
67extern const wd17xx_interface dgnbeta_wd17xx_interface;
6668MACHINE_START( dgnbeta );
6769
6870// Page IO at FE00
src/mess/includes/mbee.h
r3867r3868
77#ifndef MBEE_H_
88#define MBEE_H_
99
10#include "machine/wd17xx.h"
1011#include "cpu/z80/z80daisy.h"
1112
1213/*----------- defined in machine/mbee.c -----------*/
1314
15extern const wd17xx_interface mbee_wd17xx_interface;
16
1417MACHINE_RESET( mbee );
15MACHINE_START( mbee );
1618
1719extern UINT8 *mbee_workram;
1820
src/mess/includes/coco.h
r3867r3868
1010#define COCO_H_
1111
1212#include "devices/snapquik.h"
13#include "machine/wd17xx.h"
1314
14
1515#define COCO_CPU_SPEED_HZ      894886   /* 0.894886 MHz */
1616#define COCO_FRAMES_PER_SECOND   (COCO_CPU_SPEED_HZ / 57.0 / 263)
1717#define COCO_CPU_SPEED         (ATTOTIME_IN_HZ(COCO_CPU_SPEED_HZ))
r3867r3868
3838
3939
4040/*----------- defined in machine/coco.c -----------*/
41
41extern const wd17xx_interface dragon_wd17xx_interface;
42extern const wd17xx_interface coco_wd17xx_interface;
43extern const wd17xx_interface dgnalpha_wd17xx_interface;
4244extern UINT8 coco3_gimereg[16];
4345
4446MACHINE_START( dragon32 );
src/mess/includes/concept.h
r3867r3868
1212#define CONCEPT_H_
1313
1414#include "machine/6522via.h"
15#include "machine/wd17xx.h"
1516
1617/*----------- defined in machine/concept.c -----------*/
1718
1819extern const via6522_interface concept_via6522_intf;
20extern const wd17xx_interface concept_wd17xx_interface;
1921
2022MACHINE_START(concept);
2123VIDEO_START(concept);
src/mess/includes/msx.h
r3867r3868
77#ifndef MSX_H_
88#define MSX_H_
99
10#include "machine/wd17xx.h"
1011
1112#define MSX_MAX_CARTS   (2)
1213
r3867r3868
4849
4950extern MSX msx1;
5051extern const ppi8255_interface msx_ppi8255_interface;
51
52extern const wd17xx_interface msx_wd17xx_interface;
5253/* start/stop functions */
5354extern DRIVER_INIT( msx );
5455extern MACHINE_START( msx );
src/mess/includes/cgenie.h
r3867r3868
77#ifndef CGENIE_H_
88#define CGENIE_H_
99
10#include "machine/wd17xx.h"
1011
1112/*----------- defined in audio/cgenie.c -----------*/
1213
r3867r3868
1920/*----------- defined in machine/cgenie.c -----------*/
2021
2122extern UINT8 *cgenie_fontram;
23extern const wd17xx_interface cgenie_wd17xx_interface;
2224
2325DEVICE_IMAGE_LOAD( cgenie_floppy );
2426
src/mess/includes/pc8801.h
r3867r3868
77#ifndef PC8801_H_
88#define PC8801_H_
99
10#include "machine/nec765.h"
1011
1112/*----------- defined in machine/pc8801.c -----------*/
1213
1314extern const ppi8255_interface pc8801_8255_config_0;
1415extern const ppi8255_interface pc8801_8255_config_1;
16extern const nec765_interface pc8801_fdc_interface;
1517
1618WRITE8_HANDLER(pc8801_write_interrupt_level);
1719WRITE8_HANDLER(pc8801_write_interrupt_mask);
src/mess/includes/oric.h
r3867r3868
88#define ORIC_H_
99
1010#include "machine/6522via.h"
11#include "machine/wd17xx.h"
1112
12
1313/*----------- defined in machine/oric.c -----------*/
1414
1515extern const via6522_interface oric_6522_interface;
1616extern const via6522_interface telestrat_via2_interface;
17extern const wd17xx_interface oric_wd17xx_interface;
1718
1819MACHINE_START( oric );
1920MACHINE_RESET( oric );
src/mess/includes/partner.h
r3867r3868
99
1010#include "machine/8255ppi.h"
1111#include "machine/8257dma.h"
12#include "machine/wd17xx.h"
1213
1314/*----------- defined in machine/partner.c -----------*/
1415
r3867r3868
1920extern DEVICE_IMAGE_LOAD( partner_floppy );
2021
2122extern const dma8257_interface partner_dma;
23extern const wd17xx_interface partner_wd17xx_interface;
2224
2325extern WRITE8_HANDLER (partner_mem_page_w );
2426extern WRITE8_HANDLER (partner_win_memory_page_w);
src/mess/includes/nascom1.h
r3867r3868
88#define NASCOM1_H_
99
1010#include "devices/snapquik.h"
11#include "machine/wd17xx.h"
1112
1213
1314/*----------- defined in machine/nascom1.c -----------*/
1415
16extern const wd17xx_interface nascom2_wd17xx_interface;
17
1518DRIVER_INIT( nascom1 );
1619DEVICE_IMAGE_LOAD( nascom1_cassette );
1720DEVICE_IMAGE_UNLOAD( nascom1_cassette );
18MACHINE_START( nascom2 );
1921SNAPSHOT_LOAD( nascom1 );
2022
2123READ8_HANDLER( nascom2_fdc_select_r );
src/mess/includes/special.h
r3867r3868
3939
4040extern DRIVER_INIT( erik );
4141extern MACHINE_RESET( erik );
42extern MACHINE_START( erik );
4342
4443extern READ8_HANDLER ( erik_rr_reg_r );
4544extern WRITE8_HANDLER( erik_rr_reg_w );
src/mess/includes/osborne1.h
r3867r3868
2222DEVICE_IMAGE_LOAD( osborne1_floppy );
2323
2424DRIVER_INIT( osborne1 );
25MACHINE_START( osborne1 );
2625MACHINE_RESET( osborne1 );
2726
2827/* Osborne1 specific daisy chain interface */
src/mess/includes/samcoupe.h
r3867r3868
3434void samcoupe_update_memory(const address_space *space);
3535
3636WRITE8_HANDLER( samcoupe_ext_mem_w );
37MACHINE_START( samcoupe );
3837MACHINE_RESET( samcoupe );
3938
4039
src/mess/includes/comx35.h
r3867r3868
22#define __COMX35__
33
44#include "devices/snapquik.h"
5#include "machine/wd17xx.h"
56
67#define SCREEN_TAG         "main"
78#define MC6845_SCREEN_TAG   "mc6845"
r3867r3868
6970
7071/* ---------- defined in machine/comx35.c ---------- */
7172
73extern const wd17xx_interface comx35_wd17xx_interface;
74
7275WRITE8_HANDLER( comx35_bank_select_w );
7376READ8_HANDLER( comx35_io_r );
7477READ8_HANDLER( comx35_io2_r );
src/mess/includes/trs80.h
r3867r3868
88#define TRS80_H_
99
1010#include "devices/snapquik.h"
11#include "machine/wd17xx.h"
1112
12
1313#define TRS80_FONT_W 6
1414#define TRS80_FONT_H 12
1515
1616
1717/*----------- defined in machine/trs80.c -----------*/
1818
19extern const wd17xx_interface trs80_wd17xx_interface;
1920extern UINT8 trs80_port_ff;
2021
2122DEVICE_IMAGE_LOAD( trs80_floppy );
2223QUICKLOAD_LOAD( trs80_cmd );
2324
24MACHINE_START( trs80 );
2525MACHINE_RESET( trs80 );
2626DRIVER_INIT( trs80 );
2727DRIVER_INIT( lnw80 );
src/mess/includes/svi318.h
r3867r3868
1111
1212#include "machine/8255ppi.h"
1313#include "machine/ins8250.h"
14#include "machine/wd17xx.h"
1415
1516/*----------- defined in machine/svi318.c -----------*/
1617
1718extern const ppi8255_interface svi318_ppi8255_interface;
1819extern const ins8250_interface svi318_ins8250_interface[2];
20extern const wd17xx_interface svi_wd17xx_interface;
1921
2022DRIVER_INIT( svi318 );
2123MACHINE_START( svi318_pal );
src/mess/includes/bbc.h
r3867r3868
1414#include "machine/6522via.h"
1515#include "machine/6850acia.h"
1616#include "machine/i8271.h"
17#include "machine/wd17xx.h"
1718#include "machine/upd7002.h"
1819
1920
r3867r3868
2122
2223extern const via6522_interface bbcb_system_via;
2324extern const via6522_interface bbcb_user_via;
24
25extern const wd17xx_interface bbc_wd17xx_interface;
2526DRIVER_INIT( bbc );
2627DRIVER_INIT( bbcm );
2728
src/mess/machine/dgn_beta.c
r3867r3868
657657static WRITE8_HANDLER(d_pia1_pa_w)
658658{
659659   int   HALT_DMA;
660
660   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
661   
661662   /* Only play with halt line if halt bit changed since last write */
662663   if((data & 0x80)!=d_pia1_pa_last)
663664   {
r3867r3868
678679   }
679680
680681   /* Drive selects are binary encoded on PA0 & PA1 */
681   wd17xx_set_drive(~data & DSMask);
682   wd17xx_set_drive(fdc,~data & DSMask);
682683
683684   /* Set density of WD2797 */
684685   if (data & DDenCtrl)
685686   {
686      wd17xx_set_density(DEN_FM_LO);
687      wd17xx_set_density(fdc,DEN_FM_LO);
687688      LOG_DISK(("Set density low %d\n",(data & DDenCtrl)));
688689   }
689690   else
690691   {
691      wd17xx_set_density(DEN_MFM_LO);
692      wd17xx_set_density(fdc,DEN_MFM_LO);
692693      LOG_DISK(("Set density high %d\n",(data & DDenCtrl)));
693694   }
694695}
r3867r3868
883884/* Dragon Beta onboard FDC */
884885/********************************************************************************************/
885886
886static void dgnbeta_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param)
887static WD17XX_CALLBACK( dgnbeta_fdc_callback )
887888{
888889   /* The INTRQ line goes through pia2 ca1, in exactly the same way as DRQ from DragonDos does */
889890   /* DRQ is routed through various logic to the FIRQ inturrupt line on *BOTH* CPUs */
890   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
891   const address_space *space = cpu_get_address_space( device->machine->cpu[0], ADDRESS_SPACE_PROGRAM );
891892
892   switch(event)
893   switch(state)
893894   {
894895      case WD17XX_IRQ_CLR:
895896         pia_2_ca1_w(space, 0, CLEAR_LINE);
r3867r3868
899900         break;
900901      case WD17XX_DRQ_CLR:
901902         /*wd2797_drq=CLEAR_LINE;*/
902         cpu1_recalc_firq(machine, CLEAR_LINE);
903         cpu1_recalc_firq(device->machine, CLEAR_LINE);
903904         break;
904905      case WD17XX_DRQ_SET:
905906         /*wd2797_drq=ASSERT_LINE;*/
906         cpu1_recalc_firq(machine, ASSERT_LINE);
907         cpu1_recalc_firq(device->machine, ASSERT_LINE);
907908         break;
908909   }
909910
910   LOG_DISK(("dgnbeta_fdc_callback(%d)\n",event));
911   LOG_DISK(("dgnbeta_fdc_callback(%d)\n",state));
911912}
912913
914const wd17xx_interface dgnbeta_wd17xx_interface = { dgnbeta_fdc_callback, NULL };
915
913916 READ8_HANDLER(dgnbeta_wd2797_r)
914917{
915918   int result = 0;
919   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
916920
917921   switch(offset & 0x03)
918922   {
919923      case 0:
920         result = wd17xx_status_r(space, 0);
924         result = wd17xx_status_r(fdc, 0);
921925         LOG_DISK(("Disk status=%2.2X\n",result));
922926         break;
923927      case 1:
924         result = wd17xx_track_r(space, 0);
928         result = wd17xx_track_r(fdc, 0);
925929         break;
926930      case 2:
927         result = wd17xx_sector_r(space, 0);
931         result = wd17xx_sector_r(fdc, 0);
928932         break;
929933      case 3:
930         result = wd17xx_data_r(space, 0);
934         result = wd17xx_data_r(fdc, 0);
931935         break;
932936      default:
933937         break;
r3867r3868
938942
939943WRITE8_HANDLER(dgnbeta_wd2797_w)
940944{
945   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
946
941947    switch(offset & 0x3)
942948   {
943949      case 0:
944950         /* disk head is encoded in the command byte */
945951         /* But only for Type 3/4 commands */
946952         if(data & 0x80)
947            wd17xx_set_side((data & 0x02) ? 1 : 0);
948         wd17xx_command_w(space, 0, data);
953            wd17xx_set_side(fdc,(data & 0x02) ? 1 : 0);
954         wd17xx_command_w(fdc, 0, data);
949955         break;
950956      case 1:
951         wd17xx_track_w(space, 0, data);
957         wd17xx_track_w(fdc, 0, data);
952958         break;
953959      case 2:
954         wd17xx_sector_w(space, 0, data);
960         wd17xx_sector_w(fdc, 0, data);
955961         break;
956962      case 3:
957         wd17xx_data_w(space, 0, data);
963         wd17xx_data_w(fdc, 0, data);
958964         break;
959965   };
960966}
r3867r3868
10271033
10281034static void dgnbeta_reset(running_machine *machine)
10291035{
1036   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
1037
10301038   system_rom = memory_region(machine, "main");
10311039
10321040   /* Make sure CPU 1 is started out halted ! */
r3867r3868
10611069   DMA_NMI_LAST=0x80;         /* start with DMA NMI inactive, as pulled up */
10621070//   DMA_NMI=CLEAR_LINE;         /* start with DMA NMI inactive */
10631071
1064   wd17xx_reset(machine);
1065   wd17xx_set_density(DEN_MFM_LO);
1066   wd17xx_set_drive(0);
1072   wd17xx_set_density(fdc,DEN_MFM_LO);
1073   wd17xx_set_drive(fdc,0);
10671074
10681075   videoram=mess_ram;         /* Point video ram at the start of physical ram */
10691076}
r3867r3868
10771084
10781085   init_video(machine);
10791086
1080   wd17xx_init(machine, WD_TYPE_179X,dgnbeta_fdc_callback, NULL);
10811087   cpu_set_dasm_override(machine->cpu[0],dgnbeta_dasm_override);
10821088
10831089   add_reset_callback(machine, dgnbeta_reset);
src/mess/machine/conkort.c
r3867r3868
232232
233233static WRITE8_HANDLER( slow_ctrl_w )
234234{
235   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
235236   /*
236237
237238      bit      description
r3867r3868
248249   */
249250
250251   /* drive selection */
251   if (!BIT(data, 0)) wd17xx_set_drive(0);
252   if (!BIT(data, 1)) wd17xx_set_drive(1);
253//   if (!BIT(data, 2)) wd17xx_set_drive(2);
252   if (!BIT(data, 0)) wd17xx_set_drive(fdc,0);
253   if (!BIT(data, 1)) wd17xx_set_drive(fdc,1);
254//   if (!BIT(data, 2)) wd17xx_set_drive(fdc,2);
254255
255256   /* motor enable */
256257   floppy_drive_set_motor_state(get_floppy_image(0), !BIT(data, 3));
r3867r3868
259260   floppy_drive_set_ready_state(get_floppy_image(1), 1, 1);
260261
261262   /* disk side selection */
262   wd17xx_set_side(!BIT(data, 4));
263   wd17xx_set_side(fdc,!BIT(data, 4));
263264
264265   if (!BIT(data, 7))
265266   {
266267      /* FDC master reset */
267      wd17xx_reset(space->machine);
268      wd17xx_reset(fdc);
268269   }
269270}
270271
r3867r3868
397398static ADDRESS_MAP_START( slow_io_map, ADDRESS_SPACE_IO, 8 )
398399   ADDRESS_MAP_GLOBAL_MASK(0xff)
399400   AM_RANGE(0x7c, 0x7f) AM_DEVREADWRITE(Z80PIO, CONKORT_Z80PIO_TAG, z80pio_alt_r, z80pio_alt_w)
400   AM_RANGE(0xbc, 0xbf) AM_READWRITE(wd17xx_r, wd17xx_w)
401   AM_RANGE(0xbc, 0xbf) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_r, wd17xx_w)
401402   AM_RANGE(0xdf, 0xdf) AM_WRITE(slow_status_w)
402403   AM_RANGE(0xef, 0xef) AM_WRITE(slow_ctrl_w)
403404ADDRESS_MAP_END
r3867r3868
417418//   AM_RANGE(0x3f, 0x3f) AM_WRITE()
418419//   AM_RANGE(0x4f, 0x4f) AM_WRITE()
419420   AM_RANGE(0x5d, 0x5d) AM_READ(fast_ctrl_r)
420   AM_RANGE(0x68, 0x6b) AM_READ(wd17xx_r)
421   AM_RANGE(0x78, 0x7b) AM_WRITE(wd17xx_w)
421   AM_RANGE(0x68, 0x6b) AM_DEVREAD(WD1793, "wd1793", wd17xx_r)
422   AM_RANGE(0x78, 0x7b) AM_DEVWRITE(WD1793, "wd1793", wd17xx_w)
422423   AM_RANGE(0x87, 0x87) AM_DEVREADWRITE(Z80DMA, CONKORT_Z80DMA_TAG, z80dma_r, z80dma_w)
423424ADDRESS_MAP_END
424425
r3867r3868
680681
681682/* FD1791 */
682683
683static void slow_wd1791_callback(running_machine *machine, wd17xx_state_t state, void *param)
684static WD17XX_CALLBACK( slow_wd1791_callback )
684685{
685   slow_t *conkort = get_safe_token_machine_slow(machine);
686   slow_t *conkort = get_safe_token_machine_slow(device->machine);
686687
687688   switch(state)
688689   {
r3867r3868
699700   }
700701}
701702
703static const wd17xx_interface slow_wd17xx_interface = { slow_wd1791_callback, NULL };
704
702705/* FD1793 */
703706
704static void fast_wd1793_callback(running_machine *machine, wd17xx_state_t state, void *param)
707static WD17XX_CALLBACK( fast_wd1793_callback )
705708{
706   fast_t *conkort = get_safe_token_machine_fast(machine);
709   fast_t *conkort = get_safe_token_machine_fast(device->machine);
707710
708711   switch(state)
709712   {
r3867r3868
720723   }
721724}
722725
726static const wd17xx_interface fast_wd17xx_interface = { fast_wd1793_callback };
727
723728/* Machine Driver */
724729
725730static MACHINE_DRIVER_START( luxor_55_10828 )
r3867r3868
729734   MDRV_CPU_CONFIG(slow_daisy_chain)
730735
731736   MDRV_Z80PIO_ADD(CONKORT_Z80PIO_TAG, pio_intf)
737   MDRV_WD179X_ADD("wd179x", slow_wd17xx_interface )     
732738MACHINE_DRIVER_END
733739
734740static MACHINE_DRIVER_START( luxor_55_21046 )
r3867r3868
739745
740746   MDRV_DEVICE_ADD(CONKORT_Z80DMA_TAG, Z80DMA)
741747   MDRV_DEVICE_CONFIG(dma_intf)
748   
749   MDRV_WD1793_ADD("wd1793", fast_wd17xx_interface )   
742750MACHINE_DRIVER_END
743751
744752/* ROMs */
r3867r3868
808816   astring_printf(tempstring, "%s:%s", device->tag, CONKORT_Z80PIO_TAG);
809817   conkort->z80pio = devtag_get_device(device->machine, Z80PIO, astring_c(tempstring));
810818
811   /* initialize FDC */
812   wd17xx_init(device->machine, WD_TYPE_179X, slow_wd1791_callback, NULL); // FD1791-01
813
814819   /* register for state saving */
815820   state_save_register_device_item(device, 0, conkort->status);
816821   state_save_register_device_item(device, 0, conkort->data);
r3867r3868
824829
825830static DEVICE_RESET( luxor_55_10828 )
826831{
827   wd17xx_reset(device->machine);
832
828833}
829834
830835static DEVICE_SET_INFO( luxor_55_10828 )
r3867r3868
882887   astring_printf(tempstring, "%s:%s", device->tag, CONKORT_Z80DMA_TAG);
883888   conkort->z80dma = devtag_get_device(device->machine, Z80DMA, astring_c(tempstring));
884889
885   /* initialize FDC */
886   wd17xx_init(device->machine, WD_TYPE_1793, fast_wd1793_callback, NULL); // FD1793-01
887
888890   /* register for state saving */
889891   state_save_register_device_item(device, 0, conkort->status);
890892   state_save_register_device_item(device, 0, conkort->data);
r3867r3868
897899
898900static DEVICE_RESET( luxor_55_21046 )
899901{
900   /* reset the FDC */
901   wd17xx_reset(device->machine);
902902}
903903
904904static DEVICE_SET_INFO( luxor_55_21046 )
src/mess/machine/msx_slot.c
r3867r3868
11271127
11281128MSX_SLOT_RESET(diskrom)
11291129{
1130   wd17xx_reset (machine);
1130   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
1131   wd17xx_reset(fdc);   
11311132}
11321133
11331134static READ8_HANDLER (msx_diskrom_page1_r)
11341135{
1136   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
11351137   switch (offset) {
1136   case 0: return wd17xx_status_r (space, 0);
1137   case 1: return wd17xx_track_r (space, 0);
1138   case 2: return wd17xx_sector_r (space, 0);
1139   case 3: return wd17xx_data_r (space, 0);
1138   case 0: return wd17xx_status_r (fdc, 0);
1139   case 1: return wd17xx_track_r (fdc, 0);
1140   case 2: return wd17xx_sector_r (fdc, 0);
1141   case 3: return wd17xx_data_r (fdc, 0);
11401142   case 7: return msx1.dsk_stat;
11411143   default:
11421144      return msx1.state[1]->mem[offset + 0x3ff8];
r3867r3868
11451147
11461148static READ8_HANDLER (msx_diskrom_page2_r)
11471149{
1150   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
11481151   if (offset >= 0x7f8) {
11491152      switch (offset) {
11501153      case 0x7f8:
1151         return wd17xx_status_r (space, 0);
1154         return wd17xx_status_r (fdc, 0);
11521155      case 0x7f9:
1153         return wd17xx_track_r (space, 0);
1156         return wd17xx_track_r (fdc, 0);
11541157      case 0x7fa:
1155         return wd17xx_sector_r (space, 0);
1158         return wd17xx_sector_r (fdc, 0);
11561159      case 0x7fb:
1157         return wd17xx_data_r (space, 0);
1160         return wd17xx_data_r (fdc, 0);
11581161      case 0x7ff:
11591162         return msx1.dsk_stat;
11601163      default:
r3867r3868
11931196
11941197MSX_SLOT_WRITE(diskrom)
11951198{
1196   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
1199   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
11971200   if (addr >= 0xa000 && addr < 0xc000) {
11981201      addr -= 0x4000;
11991202   }
12001203   switch (addr) {
12011204   case 0x7ff8:
1202      wd17xx_command_w (space, 0, val);
1205      wd17xx_command_w (fdc, 0, val);
12031206      break;
12041207   case 0x7ff9:
1205      wd17xx_track_w (space, 0, val);
1208      wd17xx_track_w (fdc, 0, val);
12061209      break;
12071210   case 0x7ffa:
1208      wd17xx_sector_w (space, 0, val);
1211      wd17xx_sector_w (fdc, 0, val);
12091212      break;
12101213   case 0x7ffb:
1211      wd17xx_data_w (space, 0, val);
1214      wd17xx_data_w (fdc, 0, val);
12121215      break;
12131216   case 0x7ffc:
1214      wd17xx_set_side (val & 1);
1217      wd17xx_set_side (fdc,val & 1);
12151218      state->mem[0x3ffc] = val | 0xfe;
12161219      break;
12171220   case 0x7ffd:
1218      wd17xx_set_drive (val & 1);
1221      wd17xx_set_drive (fdc,val & 1);
12191222      if ((state->mem[0x3ffd] ^ val) & 0x40) {
12201223         set_led_status (0, !(val & 0x40));
12211224      }
r3867r3868
12401243
12411244MSX_SLOT_RESET(diskrom2)
12421245{
1243   wd17xx_reset (machine);
1246   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
1247   wd17xx_reset (fdc);
12441248}
12451249
12461250static READ8_HANDLER (msx_diskrom2_page1_r)
12471251{
1252   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
12481253   switch (offset) {
1249   case 0: return wd17xx_status_r(space, 0);
1250   case 1: return wd17xx_track_r(space, 0);
1251   case 2: return wd17xx_sector_r(space, 0);
1252   case 3: return wd17xx_data_r(space, 0);
1254   case 0: return wd17xx_status_r(fdc, 0);
1255   case 1: return wd17xx_track_r(fdc, 0);
1256   case 2: return wd17xx_sector_r(fdc, 0);
1257   case 3: return wd17xx_data_r(fdc, 0);
12531258   case 4: return msx1.dsk_stat;
12541259   default:
12551260      return msx1.state[1]->mem[offset + 0x3ff8];
r3867r3868
12581263
12591264static  READ8_HANDLER (msx_diskrom2_page2_r)
12601265{
1266   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
12611267   if (offset >= 0x7b8) {
12621268      switch (offset) {
12631269      case 0x7b8:
1264         return wd17xx_status_r (space, 0);
1270         return wd17xx_status_r (fdc, 0);
12651271      case 0x7b9:
1266         return wd17xx_track_r (space, 0);
1272         return wd17xx_track_r (fdc, 0);
12671273      case 0x7ba:
1268         return wd17xx_sector_r (space, 0);
1274         return wd17xx_sector_r (fdc, 0);
12691275      case 0x7bb:
1270         return wd17xx_data_r (space, 0);
1276         return wd17xx_data_r (fdc, 0);
12711277      case 0x7bc:
12721278         return msx1.dsk_stat;
12731279      default:
r3867r3868
13051311
13061312MSX_SLOT_WRITE(diskrom2)
13071313{
1308   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
1314   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
13091315   if (addr >= 0xa000 && addr < 0xc000) {
13101316      addr -= 0x4000;
13111317   }
13121318   switch (addr) {
13131319   case 0x7fb8:
1314      wd17xx_command_w (space, 0, val);
1320      wd17xx_command_w (fdc, 0, val);
13151321      break;
13161322   case 0x7fb9:
1317      wd17xx_track_w (space, 0, val);
1323      wd17xx_track_w (fdc, 0, val);
13181324      break;
13191325   case 0x7fba:
1320      wd17xx_sector_w (space, 0, val);
1326      wd17xx_sector_w (fdc, 0, val);
13211327      break;
13221328   case 0x7fbb:
1323      wd17xx_data_w (space, 0, val);
1329      wd17xx_data_w (fdc, 0, val);
13241330      break;
13251331   case 0x7fbc:
1326      wd17xx_set_side (val & 1);
1332      wd17xx_set_side (fdc,val & 1);
13271333      state->mem[0x3fbc] = val | 0xfe;
1328      wd17xx_set_drive (val & 1);
1334      wd17xx_set_drive (fdc,val & 1);
13291335      if ((state->mem[0x3fbc] ^ val) & 0x40) {
13301336         set_led_status (0, !(val & 0x40));
13311337      }
src/mess/machine/mbee.c
r3867r3868
2828static UINT8 fdc_head = 0;
2929static UINT8 fdc_den = 0;
3030static UINT8 fdc_status = 0;
31static void mbee_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param);
3231
3332UINT8 *mbee_workram;
3433
r3867r3868
5150   memory_set_bank(machine, 1, 1);
5251}
5352
54MACHINE_START( mbee )
53static WD17XX_CALLBACK( mbee_fdc_callback )
5554{
56   wd17xx_init(machine, WD_TYPE_179X,mbee_fdc_callback, NULL);
57}
58
59static void mbee_fdc_callback(running_machine *machine, wd17xx_state_t state, void *param)
60{
6155   switch( state )
6256   {
6357   case WD17XX_IRQ_CLR:
r3867r3868
7771    }
7872}
7973
74const wd17xx_interface mbee_wd17xx_interface = { mbee_fdc_callback, NULL };
75
8076 READ8_HANDLER ( mbee_fdc_status_r )
8177{
8278   logerror("mbee fdc_motor_r $%02X\n", fdc_status);
r3867r3868
8581
8682WRITE8_HANDLER ( mbee_fdc_motor_w )
8783{
84   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
8885   logerror("mbee fdc_motor_w $%02X\n", data);
8986   /* Controller latch bits
9087    * 0-1   driver select
r3867r3868
9592   fdc_drv = data & 3;
9693   fdc_head = (data >> 2) & 1;
9794   fdc_den = (data >> 3) & 1;
98   wd17xx_set_drive(fdc_drv);
99   wd17xx_set_side(fdc_head);
95   wd17xx_set_drive(fdc,fdc_drv);
96   wd17xx_set_side(fdc,fdc_head);
10097   if (data & (1<<3))
10198   {
102      wd17xx_set_density(DEN_FM_HI);
99      wd17xx_set_density(fdc,DEN_FM_HI);
103100   }
104101   else
105102   {
106      wd17xx_set_density(DEN_MFM_LO);
103      wd17xx_set_density(fdc,DEN_MFM_LO);
107104   }
108105
109106}
src/mess/machine/coco.c
r3867r3868
393393   coco3_sam_set_maptype
394394};
395395
396static coco_cartridge *coco_cart;
396coco_cartridge *coco_cart;
397397static emu_timer *cart_timer;
398398static emu_timer *nmi_timer;
399399static emu_timer *halt_timer;
r3867r3868
12311231
12321232WRITE8_HANDLER ( dgnalpha_psg_porta_write )
12331233{
1234   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
12341235   /* Bits 0..3 are the drive select lines for the internal floppy interface */
12351236   /* Bit 4 is the motor on, in the real hardware these are inverted on their way to the drive */
12361237   /* Bits 5,6,7 are connected to /DDEN, ENP and 5/8 on the WD2797 */
12371238   switch (data & 0xF)
12381239   {
12391240      case(0x01) :
1240         wd17xx_set_drive(0);
1241         wd17xx_set_drive(fdc,0);
12411242         break;
12421243      case(0x02) :
1243         wd17xx_set_drive(1);
1244         wd17xx_set_drive(fdc,1);
12441245         break;
12451246      case(0x04) :
1246         wd17xx_set_drive(2);
1247         wd17xx_set_drive(fdc,2);
12471248         break;
12481249      case(0x08) :
1249         wd17xx_set_drive(3);
1250         wd17xx_set_drive(fdc,3);
12501251         break;
12511252   }
12521253}
r3867r3868
16501651/* Dragon Alpha onboard FDC */
16511652/********************************************************************************************/
16521653
1653static void   dgnalpha_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param)
1654static WD17XX_CALLBACK( dgnalpha_fdc_callback )
16541655{
16551656   /* The NMI line on the alphaAlpha is gated through IC16 (early PLD), and is gated by pia2 CA2  */
16561657   /* The DRQ line goes through pia2 cb1, in exactly the same way as DRQ from DragonDos does */
16571658   /* for pia1 cb1 */
16581659
1659   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
1660   const address_space *space = cpu_get_address_space( device->machine->cpu[0], ADDRESS_SPACE_PROGRAM );
16601661
1661   switch(event)
1662   switch(state)
16621663   {
16631664      case WD17XX_IRQ_CLR:
1664         cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, CLEAR_LINE);
1665         cpu_set_input_line(device->machine->cpu[0], INPUT_LINE_NMI, CLEAR_LINE);
16651666         break;
16661667      case WD17XX_IRQ_SET:
16671668         if(dgnalpha_just_reset)
r3867r3868
16711672         else
16721673         {
16731674            if (pia_get_output_ca2_z(2))
1674               cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, ASSERT_LINE);
1675               cpu_set_input_line(device->machine->cpu[0], INPUT_LINE_NMI, ASSERT_LINE);
16751676         }
16761677         break;
16771678      case WD17XX_DRQ_CLR:
r3867r3868
16861687/* The Dragon Alpha hardware reverses the order of the WD2797 registers */
16871688READ8_HANDLER(wd2797_r)
16881689{
1690   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
16891691   int result = 0;
16901692
16911693   switch(offset & 0x03)
16921694   {
16931695      case 0:
1694         result = wd17xx_data_r(space, 0);
1696         result = wd17xx_data_r(fdc, 0);
16951697         break;
16961698      case 1:
1697         result = wd17xx_sector_r(space, 0);
1699         result = wd17xx_sector_r(fdc, 0);
16981700         break;
16991701      case 2:
1700         result = wd17xx_track_r(space, 0);
1702         result = wd17xx_track_r(fdc, 0);
17011703         break;
17021704      case 3:
1703         result = wd17xx_status_r(space, 0);
1705         result = wd17xx_status_r(fdc, 0);
17041706         break;
17051707      default:
17061708         break;
r3867r3868
17111713
17121714WRITE8_HANDLER(wd2797_w)
17131715{
1716   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
17141717    switch(offset & 0x3)
17151718   {
17161719      case 0:
1717         wd17xx_data_w(space, 0, data);
1720         wd17xx_data_w(fdc, 0, data);
17181721         break;
17191722      case 1:
1720         wd17xx_sector_w(space, 0, data);
1723         wd17xx_sector_w(fdc, 0, data);
17211724         break;
17221725      case 2:
1723         wd17xx_track_w(space, 0, data);
1726         wd17xx_track_w(fdc, 0, data);
17241727         break;
17251728      case 3:
1726         wd17xx_command_w(space, 0, data);
1729         wd17xx_command_w(fdc, 0, data);
17271730
17281731         /* disk head is encoded in the command byte */
1729         wd17xx_set_side((data & 0x02) ? 1 : 0);
1732         wd17xx_set_side(fdc,(data & 0x02) ? 1 : 0);
17301733         break;
17311734   };
17321735}
r3867r3868
29993002   /* dgnalpha_just_reset, is here to flag that we should ignore the first irq generated */
30003003   /* by the WD2797, it is reset to 0 after the first inurrupt */
30013004   dgnalpha_just_reset=1;
3002
3003   wd17xx_init(machine, WD_TYPE_179X, dgnalpha_fdc_callback, NULL);
30043005}
30053006
3007const wd17xx_interface dgnalpha_wd17xx_interface = {
3008   dgnalpha_fdc_callback,
3009   NULL
3010};
30063011/******* Machine Setups CoCos **********/
30073012
30083013MACHINE_START( coco )
src/mess/machine/99_dsk.c
r3867r3868
367367/*
368368   callback called whenever DRQ/IRQ state change
369369*/
370static void fdc_callback(running_machine *machine, wd17xx_state_t event, void *param)
370static WD17XX_CALLBACK( fdc_callback )
371371{
372   switch (event)
372   switch (state)
373373   {
374374   case WD17XX_IRQ_CLR:
375375      DRQ_IRQ_status &= ~fdc_IRQ;
r3867r3868
387387      break;
388388   }
389389
390   fdc_handle_hold(machine);
390   fdc_handle_hold(device->machine);
391391}
392392
393const wd17xx_interface ti99_wd17xx_interface = { fdc_callback, NULL };
394
395
393396/*
394397   Initializes all available controllers. This routine is only used in the
395398   init state of the emulator. During the normal operation, only the
r3867r3868
397400*/
398401void ti99_floppy_controllers_init_all(running_machine *machine)
399402{
400   /* initialize the controller chip for TI FDC, CC, BwG */
401   wd17xx_init(machine, WD_TYPE_179X, fdc_callback, NULL);
402
403403   /* initialize the controller chip for HFDC */
404404   smc92x4_init(0, & hfdc_intf);
405405
r3867r3868
414414*/
415415
416416/* prototypes */
417static void fdc_callback(running_machine *machine, wd17xx_state_t event, void *param);
418417static TIMER_CALLBACK(motor_on_timer_callback);
419418static int fdc_cru_r(running_machine *machine, int offset);
420419static void fdc_cru_w(running_machine *machine, int offset, int data);
r3867r3868
437436*/
438437void ti99_fdc_reset(running_machine *machine)
439438{
439   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
440440   ti99_disk_DSR = memory_region(machine, region_dsr) + offset_fdc_dsr;
441441   DSEL = 0;
442442   DSKnum = -1;
r3867r3868
448448   use_80_track_drives = FALSE;
449449
450450   ti99_peb_set_card_handlers(0x1100, & fdc_handlers);
451   wd17xx_reset(machine);      /* resets the fdc */
452   wd17xx_set_density(DEN_FM_LO);
451   wd17xx_reset(fdc);      /* resets the fdc */
452   wd17xx_set_density(fdc,DEN_FM_LO);
453453}
454454
455455/*
r3867r3868
491491*/
492492static void fdc_cru_w(running_machine *machine, int offset, int data)
493493{
494   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
495   
494496   switch (offset)
495497   {
496498   case 0:
r3867r3868
539541            {
540542               DSKnum = drive;
541543
542               wd17xx_set_drive(DSKnum);
544               wd17xx_set_drive(fdc,DSKnum);
543545               /*wd17xx_set_side(DSKside);*/
544546            }
545547         }
r3867r3868
558560   case 7:
559561      /* Select side of disk (bit 7) */
560562      DSKside = data;
561      wd17xx_set_side(DSKside);
563      wd17xx_set_side(fdc,DSKside);
562564      break;
563565   }
564566}
r3867r3868
569571*/
570572static  READ8_HANDLER(fdc_mem_r)
571573{
574   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
575   
572576   switch (offset)
573577   {
574578   case 0x1FF0:               /* Status register */
575      return (wd17xx_status_r(space, offset) ^ 0xFF);
579      return (wd17xx_status_r(fdc, offset) ^ 0xFF);
576580      break;
577581   case 0x1FF2:               /* Track register */
578      return wd17xx_track_r(space, offset) ^ 0xFF;
582      return wd17xx_track_r(fdc, offset) ^ 0xFF;
579583      break;
580584   case 0x1FF4:               /* Sector register */
581      return wd17xx_sector_r(space, offset) ^ 0xFF;
585      return wd17xx_sector_r(fdc, offset) ^ 0xFF;
582586      break;
583587   case 0x1FF6:               /* Data register */
584      return wd17xx_data_r(space, offset) ^ 0xFF;
588      return wd17xx_data_r(fdc, offset) ^ 0xFF;
585589      break;
586590   default:                  /* DSR ROM */
587591      return ti99_disk_DSR[offset];
r3867r3868
594598*/
595599static WRITE8_HANDLER(fdc_mem_w)
596600{
601   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
602   
597603   data ^= 0xFF;   /* inverted data bus */
598604
599605   switch (offset)
600606   {
601607   case 0x1FF8:               /* Command register */
602      wd17xx_command_w(space, offset, data);
608      wd17xx_command_w(fdc, offset, data);
603609      break;
604610   case 0x1FFA:               /* Track register */
605      wd17xx_track_w(space, offset, data);
611      wd17xx_track_w(fdc, offset, data);
606612      break;
607613   case 0x1FFC:               /* Sector register */
608      wd17xx_sector_w(space, offset, data);
614      wd17xx_sector_w(fdc, offset, data);
609615      break;
610616   case 0x1FFE:               /* Data register */
611      wd17xx_data_w(space, offset, data);
617      wd17xx_data_w(fdc, offset, data);
612618      break;
613619   }
614620}
r3867r3868
644650#if HAS_99CCFDC
645651void ti99_ccfdc_reset(running_machine *machine)
646652{
653   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
654   
647655   ti99_disk_DSR = memory_region(machine, region_dsr) + offset_ccfdc_dsr;
648656   DSEL = 0;
649657   DSKnum = -1;
r3867r3868
656664
657665   ti99_peb_set_card_handlers(0x1100, & ccfdc_handlers);
658666
659   wd17xx_reset(machine);      /* initialize the floppy disk controller */
660   wd17xx_set_density(DEN_MFM_LO);
667   wd17xx_reset(fdc);      /* initialize the floppy disk controller */
668   wd17xx_set_density(fdc,DEN_MFM_LO);
661669}
662670#endif
663671
r3867r3868
696704*/
697705static void ccfdc_cru_w(running_machine *machine, int offset, int data)
698706{
707   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
708   
699709   switch (offset)
700710   {
701711   case 0:
r3867r3868
741751            {
742752               DSKnum = drive;
743753
744               wd17xx_set_drive(DSKnum);
745               /*wd17xx_set_side(DSKside);*/
754               wd17xx_set_drive(fdc,DSKnum);
755               /*wd17xx_set_side(fdc,DSKside);*/
746756            }
747757         }
748758         else
r3867r3868
760770   case 7:
761771      /* Select side of disk (bit 7) */
762772      DSKside = data;
763      wd17xx_set_side(DSKside);
773      wd17xx_set_side(fdc,DSKside);
764774      break;
765775
766776   case 10:
767777      /* double density enable (active low) */
768      wd17xx_set_density(data ? DEN_FM_LO : DEN_MFM_LO);
778      wd17xx_set_density(fdc,data ? DEN_FM_LO : DEN_MFM_LO);
769779      break;
770780
771781   case 11:
r3867r3868
855865*/
856866void ti99_bwg_reset(running_machine *machine)
857867{
868   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
869   
858870   ti99_disk_DSR = memory_region(machine, region_dsr) + offset_bwg_dsr;
859871        bwg_ram = memory_region(machine, region_dsr) + offset_bwg_ram;
860872   bwg_ram_offset = 0;
r3867r3868
872884       
873885   ti99_peb_set_card_handlers(0x1100, & bwg_handlers);
874886
875   wd17xx_reset(machine);      /* initialize the floppy disk controller */
876   wd17xx_set_density(DEN_MFM_LO);
887   wd17xx_reset(fdc);      /* initialize the floppy disk controller */
888   wd17xx_set_density(fdc,DEN_MFM_LO);
877889}
878890
879891/*
r3867r3868
910922*/
911923static void bwg_cru_w(running_machine *machine, int offset, int data)
912924{
925   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
926   
913927   switch (offset)
914928   {
915929   case 0:
r3867r3868
955969            {
956970               DSKnum = drive;
957971
958               wd17xx_set_drive(DSKnum);
959               /*wd17xx_set_side(DSKside);*/
972               wd17xx_set_drive(fdc,DSKnum);
973               /*wd17xx_set_side(fdc,DSKside);*/
960974            }
961975         }
962976         else
r3867r3868
974988   case 7:
975989      /* Select side of disk (bit 7) */
976990      DSKside = data;
977      wd17xx_set_side(DSKside);
991      wd17xx_set_side(fdc,DSKside);
978992      break;
979993
980994   case 10:
981995      /* double density enable (active low) */
982      wd17xx_set_density(data ? DEN_FM_LO : DEN_MFM_LO);
996      wd17xx_set_density(fdc,data ? DEN_FM_LO : DEN_MFM_LO);
983997      break;
984998
985999   case 11:
r3867r3868
10251039*/
10261040static  READ8_HANDLER(bwg_mem_r)
10271041{
1042   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
1043   
10281044   int reply = 0;
10291045
10301046   if (offset < 0x1c00)
r3867r3868
10441060         switch (offset)
10451061         {
10461062         case 0x1FF0:               /* Status register */
1047            reply = wd17xx_status_r(space, offset);
1063            reply = wd17xx_status_r(fdc, offset);
10481064            break;
10491065         case 0x1FF2:               /* Track register */
1050            reply = wd17xx_track_r(space, offset);
1066            reply = wd17xx_track_r(fdc, offset);
10511067            break;
10521068         case 0x1FF4:               /* Sector register */
1053            reply = wd17xx_sector_r(space, offset);
1069            reply = wd17xx_sector_r(fdc, offset);
10541070            break;
10551071         case 0x1FF6:               /* Data register */
1056            reply = wd17xx_data_r(space, offset);
1072            reply = wd17xx_data_r(fdc, offset);
10571073            break;
10581074         default:
10591075            reply = 0;
r3867r3868
10681084*/
10691085static WRITE8_HANDLER(bwg_mem_w)
10701086{
1087   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
1088   
10711089   if (offset < 0x1c00)
10721090      ;
10731091   else if (offset < 0x1fe0)
r3867r3868
10881106         switch (offset)
10891107         {
10901108         case 0x1FF8:               /* Command register */
1091            wd17xx_command_w(space, offset, data);
1109            wd17xx_command_w(fdc, offset, data);
10921110            break;
10931111         case 0x1FFA:               /* Track register */
1094            wd17xx_track_w(space, offset, data);
1112            wd17xx_track_w(fdc, offset, data);
10951113            break;
10961114         case 0x1FFC:               /* Sector register */
1097            wd17xx_sector_w(space, offset, data);
1115            wd17xx_sector_w(fdc, offset, data);
10981116            break;
10991117         case 0x1FFE:               /* Data register */
1100            wd17xx_data_w(space, offset, data);
1118            wd17xx_data_w(fdc, offset, data);
11011119            break;
11021120         }
11031121      }
src/mess/machine/99_dsk.h
r3867r3868
1#ifndef TI99_DSK_H_
2#define TI99_DSK_H_
3
4#include "machine/wd17xx.h"
5
16FLOPPY_OPTIONS_EXTERN(ti99);
27
38void ti99_floppy_controllers_init_all(running_machine *machine);
r3867r3868
712#endif
813void ti99_bwg_reset(running_machine *machine);
914void ti99_hfdc_reset(running_machine *machine);
15
16extern const wd17xx_interface ti99_wd17xx_interface;
17#endif /* TI99_DSK_H_ */
src/mess/machine/b2m.c
r3867r3868
233233static WRITE8_DEVICE_HANDLER (b2m_ext_8255_portc_w )
234234{     
235235   UINT8 drive = ((data >> 1) & 1) ^ 1;
236   UINT8 side  = (data  & 1) ^ 1;
236   UINT8 side  = (data  & 1) ^ 1;   
237   device_config *fdc = (device_config*)device_list_find_by_tag( device->machine->config->devicelist, WD1793, "wd1793");
237238   
238239   if (b2m_drive!=drive) {
239      wd17xx_set_drive(drive);
240      wd17xx_set_drive(fdc,drive);
240241      b2m_drive = drive;
241242   }
242243   if (b2m_side!=side) {
243      wd17xx_set_side(side);
244      wd17xx_set_side(fdc,side);
244245      b2m_side = side;
245246   }
246247}
r3867r3868
329330
330331MACHINE_START(b2m)
331332{
332   wd17xx_init(machine, WD_TYPE_1793, NULL , NULL);   
333   wd17xx_set_pause_time(10);
333   wd17xx_set_pause_time((device_config*)device_list_find_by_tag( machine->config->devicelist, WD1793, "wd1793"),10);
334334}
335335
336336static IRQ_CALLBACK(b2m_irq_callback)
r3867r3868
353353MACHINE_RESET(b2m)
354354{   
355355   b2m_sound_input = 0;
356   
357   wd17xx_reset(machine);
358   
356     
359357   b2m_side = 0;
360358   b2m_drive = 0;
361   wd17xx_set_side(0);
362   wd17xx_set_drive(0);
363359
364360   cpu_set_irq_callback(machine->cpu[0], b2m_irq_callback);
365361   b2m_set_bank(machine,7);
src/mess/machine/oric.c
r3867r3868
705705   }
706706}
707707
708static void oric_jasmin_wd179x_callback(running_machine *machine, int State)
708static WD17XX_CALLBACK( oric_jasmin_wd179x_callback )
709709{
710   switch (State)
710   switch (state)
711711   {
712712      /* DRQ is connected to interrupt */
713713      case WD17XX_DRQ_CLR:
714714      {
715715         oric_irqs &=~(1<<1);
716716
717         oric_refresh_ints(machine);
717         oric_refresh_ints(device->machine);
718718      }
719719      break;
720720
r3867r3868
722722      {
723723         oric_irqs |= (1<<1);
724724
725         oric_refresh_ints(machine);
725         oric_refresh_ints(device->machine);
726726      }
727727      break;
728728
r3867r3868
734734static READ8_HANDLER (oric_jasmin_r)
735735{
736736   const device_config *via_0 = device_list_find_by_tag(space->machine->config->devicelist, VIA6522, "via6522_0");
737   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
737738   unsigned char data = 0x0ff;
738739
739740   switch (offset & 0x0f)
740741   {
741742      /* jasmin floppy disc interface */
742743      case 0x04:
743         data = wd17xx_status_r(space, 0);
744         data = wd17xx_status_r(fdc, 0);
744745         break;
745746      case 0x05:
746         data =wd17xx_track_r(space, 0);
747         data =wd17xx_track_r(fdc, 0);
747748         break;
748749      case 0x06:
749         data = wd17xx_sector_r(space, 0);
750         data = wd17xx_sector_r(fdc, 0);
750751         break;
751752      case 0x07:
752         data = wd17xx_data_r(space, 0);
753         data = wd17xx_data_r(fdc, 0);
753754         break;
754755      default:
755756         data = via_r(via_0, offset & 0x0f);
r3867r3868
764765static WRITE8_HANDLER(oric_jasmin_w)
765766{
766767   const device_config *via_0 = device_list_find_by_tag(space->machine->config->devicelist, VIA6522, "via6522_0");
768   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
767769   switch (offset & 0x0f)
768770   {
769771      /* microdisc floppy disc interface */
770772      case 0x04:
771         wd17xx_command_w(space, 0, data);
773         wd17xx_command_w(fdc, 0, data);
772774         break;
773775      case 0x05:
774         wd17xx_track_w(space, 0, data);
776         wd17xx_track_w(fdc, 0, data);
775777         break;
776778      case 0x06:
777         wd17xx_sector_w(space, 0, data);
779         wd17xx_sector_w(fdc, 0, data);
778780         break;
779781      case 0x07:
780         wd17xx_data_w(space, 0, data);
782         wd17xx_data_w(fdc, 0, data);
781783         break;
782784      /* bit 0 = side */
783785      case 0x08:
784         wd17xx_set_side(data & 0x01);
786         wd17xx_set_side(fdc,data & 0x01);
785787         break;
786788      /* any write will cause wd179x to reset */
787789      case 0x09:
788         wd17xx_reset(space->machine);
790         wd17xx_reset(fdc);
789791         break;
790792      case 0x0a:
791793         logerror("jasmin overlay ram w: %02x PC: %04x\n",data,cpu_get_pc(space->machine->cpu[0]));
r3867r3868
802804      case 0x0d:
803805      case 0x0e:
804806      case 0x0f:
805         wd17xx_set_drive(offset & 0x03);
807         wd17xx_set_drive(fdc,offset & 0x03);
806808         break;
807809
808810      default:
r3867r3868
857859   oric_refresh_ints(machine);
858860}
859861
860static void oric_microdisc_wd179x_callback(running_machine *machine, int State)
862static WD17XX_CALLBACK( oric_microdisc_wd179x_callback )
861863{
862   switch (State)
864   switch (state)
863865   {
864866      case WD17XX_IRQ_CLR:
865867      {
r3867r3868
867869
868870         oric_wd179x_int_state = 0;
869871
870         oric_microdisc_refresh_wd179x_ints(machine);
872         oric_microdisc_refresh_wd179x_ints(device->machine);
871873      }
872874      break;
873875
r3867r3868
877879
878880         oric_wd179x_int_state = 1;
879881
880         oric_microdisc_refresh_wd179x_ints(machine);
882         oric_microdisc_refresh_wd179x_ints(device->machine);
881883      }
882884      break;
883885
r3867r3868
969971READ8_HANDLER (oric_microdisc_r)
970972{
971973   unsigned char data = 0x0ff;
972
974   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
975   
973976   switch (offset & 0x0ff)
974977   {
975978      /* microdisc floppy disc interface */
976979      case 0x00:
977         data = wd17xx_status_r(space, 0);
980         data = wd17xx_status_r(fdc, 0);
978981         break;
979982      case 0x01:
980         data =wd17xx_track_r(space, 0);
983         data =wd17xx_track_r(fdc, 0);
981984         break;
982985      case 0x02:
983         data = wd17xx_sector_r(space, 0);
986         data = wd17xx_sector_r(fdc, 0);
984987         break;
985988      case 0x03:
986         data = wd17xx_data_r(space, 0);
989         data = wd17xx_data_r(fdc, 0);
987990         break;
988991      case 0x04:
989992         data = port_314_r | 0x07f;
r3867r3868
10081011
10091012WRITE8_HANDLER(oric_microdisc_w)
10101013{
1014   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
10111015   switch (offset & 0x0ff)
10121016   {
10131017      /* microdisc floppy disc interface */
10141018      case 0x00:
1015         wd17xx_command_w(space, 0, data);
1019         wd17xx_command_w(fdc, 0, data);
10161020         break;
10171021      case 0x01:
1018         wd17xx_track_w(space, 0, data);
1022         wd17xx_track_w(fdc, 0, data);
10191023         break;
10201024      case 0x02:
1021         wd17xx_sector_w(space, 0, data);
1025         wd17xx_sector_w(fdc, 0, data);
10221026         break;
10231027      case 0x03:
1024         wd17xx_data_w(space, 0, data);
1028         wd17xx_data_w(fdc, 0, data);
10251029         break;
10261030      case 0x04:
10271031      {
r3867r3868
10351039         /* bit 4: side */
10361040         /* bit 3: double density enable */
10371041         /* bit 0: enable FDC IRQ to trigger IRQ on CPU */
1038         wd17xx_set_drive((data>>5) & 0x03);
1039         wd17xx_set_side((data>>4) & 0x01);
1042         wd17xx_set_drive(fdc,(data>>5) & 0x03);
1043         wd17xx_set_side(fdc,(data>>4) & 0x01);
10401044         if (data & (1<<3))
10411045         {
10421046            density = DEN_MFM_LO;
r3867r3868
10461050            density = DEN_FM_HI;
10471051         }
10481052
1049         wd17xx_set_density(density);
1053         wd17xx_set_density(fdc,density);
10501054
10511055         oric_microdisc_set_mem_0x0c000(space->machine);
10521056         oric_microdisc_refresh_wd179x_ints(space->machine);
r3867r3868
10861090/*********************************************************/
10871091
10881092
1089static void oric_wd179x_callback(running_machine *machine, wd17xx_state_t State, void *param)
1093static WD17XX_CALLBACK(oric_wd179x_callback)
10901094{
1091   switch (input_port_read(machine, "FLOPPY") &  0x07)
1095   switch (input_port_read(device->machine, "FLOPPY") &  0x07)
10921096   {
10931097      default:
10941098      case ORIC_FLOPPY_INTERFACE_NONE:
10951099      case ORIC_FLOPPY_INTERFACE_APPLE2:
10961100         return;
10971101      case ORIC_FLOPPY_INTERFACE_MICRODISC:
1098         oric_microdisc_wd179x_callback(machine, State);
1102         oric_microdisc_wd179x_callback(device, state, param);
10991103         return;
11001104      case ORIC_FLOPPY_INTERFACE_JASMIN:
1101         oric_jasmin_wd179x_callback(machine, State);
1105         oric_jasmin_wd179x_callback(device, state, param);
11021106         return;
11031107   }
11041108}
11051109
1110const wd17xx_interface oric_wd17xx_interface = { oric_wd179x_callback, NULL };
1111
11061112DEVICE_START( oric_floppy )
11071113{
11081114   /* TODO - THIS DOES NOT MULTITASK BETWEEN ORIC BASICDSKs AND MFM DISKS */
r3867r3868
11551161   oric_is_telestrat = 0;
11561162
11571163   oric_ram_0x0c000 = auto_malloc(16384);
1158
1159   wd17xx_init(machine, WD_TYPE_179X,oric_wd179x_callback, NULL);
11601164}
11611165
11621166
r3867r3868
15451549   /* disable os rom, enable microdisc rom */
15461550   /* 0x0c000-0x0dfff will be ram, 0x0e000-0x0ffff will be microdisc rom */
15471551    port_314_w = 0x0ff^((1<<7) | (1<<1));
1548
1549   wd17xx_init(machine, WD_TYPE_179X,oric_wd179x_callback, NULL);
15501552}
src/mess/machine/at.c
r3867r3868
404404   dma8237_drq_write( at_devices.dma8237_1, FDC_DMA, state);
405405}
406406
407static device_config * at_get_device(running_machine *machine )
408{
409   return (device_config*)device_list_find_by_tag( machine->config->devicelist, NEC765A, "nec765");   
410}
411
407412static const struct pc_fdc_interface fdc_interface =
408413{
409   NEC765A,
410   NEC765_RDY_PIN_NOT_CONNECTED,
411414   at_fdc_interrupt,
412415   at_fdc_dma_drq,
416   NULL,
417   at_get_device
413418};
414419
415420
src/mess/machine/vector06.c
r3867r3868
171171
172172WRITE8_HANDLER(vector_disc_w)
173173{
174   wd17xx_set_side (((data & 4) >> 2) ^ 1);
175    wd17xx_set_drive(data & 1);               
174   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
175   wd17xx_set_side (fdc,((data & 4) >> 2) ^ 1);
176    wd17xx_set_drive(fdc,data & 1);               
176177}
177178
178179DEVICE_IMAGE_LOAD( vector_floppy )
r3867r3868
204205
205206MACHINE_START( vector06 )
206207{
207   wd17xx_init(machine, WD_TYPE_1793, NULL , NULL);
208   wd17xx_set_density (DEN_FM_HI);
208   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD1793, "wd1793");
209   wd17xx_set_density (fdc, DEN_FM_HI);
209210}
210211
211212MACHINE_RESET( vector06 )
r3867r3868
227228   vector_color_index = 0;
228229   vector_video_mode = 0;
229230   timer_pulse(machine, ATTOTIME_IN_HZ(50), NULL, 0, reset_check_callback);
230   
231   wd17xx_reset(machine);
232   wd17xx_set_pause_time(0);
233231}
src/mess/machine/orion.c
r3867r3868
7171
7272MACHINE_START( orion128 )
7373{
74   wd17xx_init(machine, WD_TYPE_1793, NULL , NULL);
75   wd17xx_set_density (DEN_FM_HI);   
74   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD1793, "wd1793");
75
76   wd17xx_set_density (fdc,DEN_FM_HI);   
7677   orion_video_mode_mask = 7;
7778}
7879
r3867r3868
158159
159160MACHINE_RESET ( orion128 )
160161{     
161   wd17xx_reset(machine);
162   wd17xx_set_density (DEN_FM_HI);   
163162   orion128_video_page = 0;
164163   orion128_video_mode = 0;
165164   orion128_memory_page = -1;
r3867r3868
205204
206205static WRITE8_HANDLER ( orion_disk_control_w )
207206{
208   wd17xx_set_side(((data & 0x10) >> 4) ^ 1);
209    wd17xx_set_drive(data & 3);           
207   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
208
209   wd17xx_set_side(fdc,((data & 0x10) >> 4) ^ 1);
210    wd17xx_set_drive(fdc,data & 3);           
210211}
211212
212213READ8_HANDLER ( orion128_floppy_r )
213214{   
215   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
216
214217   switch(offset) {
215218      case 0x0   :
216      case 0x10 : return wd17xx_status_r(space,0);
219      case 0x10 : return wd17xx_status_r(fdc,0);
217220      case 0x1    :
218      case 0x11 : return wd17xx_track_r(space,0);
221      case 0x11 : return wd17xx_track_r(fdc,0);
219222      case 0x2  :
220      case 0x12 : return wd17xx_sector_r(space,0);
223      case 0x12 : return wd17xx_sector_r(fdc,0);
221224      case 0x3  :
222      case 0x13 : return wd17xx_data_r(space,0);
225      case 0x13 : return wd17xx_data_r(fdc,0);
223226   }   
224227   return 0xff;
225228}
226229
227230WRITE8_HANDLER ( orion128_floppy_w )
228231{     
232   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
233   
229234   switch(offset) {
230235      case 0x0   :
231      case 0x10 : wd17xx_command_w(space,0,data); break;
236      case 0x10 : wd17xx_command_w(fdc,0,data); break;
232237      case 0x1    :
233      case 0x11 : wd17xx_track_w(space,0,data);break;
238      case 0x11 : wd17xx_track_w(fdc,0,data);break;
234239      case 0x2  :
235      case 0x12 : wd17xx_sector_w(space,0,data);break;
240      case 0x12 : wd17xx_sector_w(fdc,0,data);break;
236241      case 0x3  :
237      case 0x13 : wd17xx_data_w(space,0,data);break;
242      case 0x13 : wd17xx_data_w(fdc,0,data);break;
238243      case 0x4  :
239244      case 0x14 :
240245      case 0x20 : orion_disk_control_w(space, offset, data);break;
r3867r3868
267272
268273MACHINE_START( orionz80 )
269274{
270   wd17xx_init(machine, WD_TYPE_1793, NULL , NULL);
271   wd17xx_set_density (DEN_FM_HI);
275   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD1793, "wd1793");
276
277   wd17xx_set_density (fdc,DEN_FM_HI);
272278   mc146818_init(machine, MC146818_IGNORE_CENTURY);
273279   orion_video_mode_mask = 7;
274280}
r3867r3868
375381   memory_set_bankptr(machine, 3, mess_ram + 0xf000);     
376382   memory_set_bankptr(machine, 5, memory_region(machine, "main") + 0xf800);     
377383   
378   wd17xx_reset(machine);
384
379385   orion128_video_page = 0;
380386   orion128_video_mode = 0;
381387   orionz80_memory_page = 0;
r3867r3868
437443
438444MACHINE_START( orionpro )
439445{
440   wd17xx_init(machine, WD_TYPE_1793, NULL , NULL);
441   wd17xx_set_density (DEN_FM_HI);
446   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD1793, "wd1793");
447   wd17xx_set_density (fdc,DEN_FM_HI);
442448}
443449
444450static WRITE8_HANDLER ( orionpro_memory_page_w );
r3867r3868
533539MACHINE_RESET ( orionpro )
534540{   
535541   radio86_init_keyboard();   
536   
537   wd17xx_reset(machine);
538542
539543   orion128_video_page = 0;
540544   orion128_video_mode = 0;
r3867r3868
558562}
559563
560564READ8_HANDLER ( orionpro_io_r ) {
565   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
566     
561567   switch (offset & 0xff) {     
562568      case 0x00 : return 0x56;
563569      case 0x04 : return orionpro_ram0_segment;
r3867r3868
566572      case 0x08 : return orionpro_page;
567573      case 0x09 : return orionpro_rom2_segment;
568574      case 0x0a : return orionpro_dispatcher;
569      case 0x10 : return wd17xx_status_r(space,0);
570      case 0x11 : return wd17xx_track_r(space,0);
571      case 0x12 : return wd17xx_sector_r(space,0);
572      case 0x13 : return wd17xx_data_r(space,0);
575      case 0x10 : return wd17xx_status_r(fdc,0);
576      case 0x11 : return wd17xx_track_r(fdc,0);
577      case 0x12 : return wd17xx_sector_r(fdc,0);
578      case 0x13 : return wd17xx_data_r(fdc,0);
573579      case 0x18 :
574580      case 0x19 :
575581      case 0x1a :
r3867r3868
587593}
588594
589595WRITE8_HANDLER ( orionpro_io_w ) {
596   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
597     
590598   switch (offset & 0xff) {     
591599      case 0x04 : orionpro_ram0_segment = data; orionpro_bank_switch(space->machine); break;     
592600      case 0x05 : orionpro_ram1_segment = data; orionpro_bank_switch(space->machine); break;
r3867r3868
594602      case 0x08 : orionpro_page = data;         orionpro_bank_switch(space->machine); break;
595603      case 0x09 : orionpro_rom2_segment = data; orionpro_bank_switch(space->machine); break;
596604      case 0x0a : orionpro_dispatcher = data;   orionpro_bank_switch(space->machine); break;
597      case 0x10 : wd17xx_command_w(space,0,data); break;
598      case 0x11 : wd17xx_track_w(space,0,data);break;
599      case 0x12 : wd17xx_sector_w(space,0,data);break;
600      case 0x13 : wd17xx_data_w(space,0,data);break;
605      case 0x10 : wd17xx_command_w(fdc,0,data); break;
606      case 0x11 : wd17xx_track_w(fdc,0,data);break;
607      case 0x12 : wd17xx_sector_w(fdc,0,data);break;
608      case 0x13 : wd17xx_data_w(fdc,0,data);break;
601609      case 0x14 : orion_disk_control_w(space, 9, data);break;
602610      case 0x18 :
603611      case 0x19 :
src/mess/machine/nascom1.c
r3867r3868
5555 *
5656 *************************************/
5757
58static void nascom2_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param)
58static WD17XX_CALLBACK( nascom2_fdc_callback )
5959{
60   switch (event)
60   switch (state)
6161   {
6262   case WD17XX_IRQ_SET: nascom2_fdc.irq = 1; break;
6363   case WD17XX_IRQ_CLR: nascom2_fdc.irq = 0; break;
r3867r3868
6767}
6868
6969
70const wd17xx_interface nascom2_wd17xx_interface = { nascom2_fdc_callback, NULL };
71
72
7073READ8_HANDLER( nascom2_fdc_select_r )
7174{
7275   return nascom2_fdc.select | 0xa0;
r3867r3868
7578
7679WRITE8_HANDLER( nascom2_fdc_select_w )
7780{
81   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
7882   nascom2_fdc.select = data;
7983
8084   logerror("nascom2_fdc_select_w: %02x\n", data);
8185
82   if (data & 0x01) wd17xx_set_drive(0);
83   if (data & 0x02) wd17xx_set_drive(1);
84   if (data & 0x04) wd17xx_set_drive(2);
85   if (data & 0x08) wd17xx_set_drive(3);
86   if (data & 0x10) wd17xx_set_side((data & 0x10) >> 4);
86   if (data & 0x01) wd17xx_set_drive(fdc,0);
87   if (data & 0x02) wd17xx_set_drive(fdc,1);
88   if (data & 0x04) wd17xx_set_drive(fdc,2);
89   if (data & 0x08) wd17xx_set_drive(fdc,3);
90   if (data & 0x10) wd17xx_set_side(fdc,(data & 0x10) >> 4);
8791}
8892
8993
r3867r3868
103107DEVICE_IMAGE_LOAD( nascom2_floppy )
104108{
105109   int sides, sectors;
106
110   device_config *fdc = (device_config*)device_list_find_by_tag( image->machine->config->devicelist, WD1793, "wd1793");
107111   if (!image_has_been_created(image))
108112   {
109113      switch (image_length(image))
r3867r3868
111115      case 80 * 2 * 2 * 8 * 256:
112116         sides = 2;
113117         sectors = 2 * 8;
114         wd17xx_set_density(DEN_FM_HI);
118         wd17xx_set_density(fdc,DEN_FM_HI);
115119         break;
116120
117121      case 80 * 1 * 2 * 8 * 256:
118122         sides = 1;
119123         sectors = 2 * 8;
120         wd17xx_set_density(DEN_FM_HI);
124         wd17xx_set_density(fdc,DEN_FM_HI);
121125         break;
122126
123127      default:
r3867r3868
290294 *
291295 *************************************/
292296
293MACHINE_START( nascom2 )
294{
295   wd17xx_init(machine, WD_TYPE_1793, nascom2_fdc_callback, NULL);
296}
297
298
299297MACHINE_RESET( nascom1 )
300298{
301299   nascom1_hd6402 = device_list_find_by_tag( machine->config->devicelist, AY31015, "hd6402" );
src/mess/machine/osborne1.c
r3867r3868
7474READ8_HANDLER( osborne1_2000_r )
7575{
7676   UINT8   data = 0xFF;
77
77   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, MB8877, "mb8877");
7878   /* Check whether regular RAM is enabled */
7979   if ( ! osborne1.bank2_enabled )
8080   {
r3867r3868
8585      switch( offset & 0x0F00 )
8686      {
8787      case 0x100:   /* Floppy */
88         data = wd17xx_r( space, offset );
88         data = wd17xx_r( fdc, offset );
8989         break;
9090      case 0x200:   /* Keyboard */
9191         /* Row 0 */
r3867r3868
121121
122122WRITE8_HANDLER( osborne1_2000_w )
123123{
124   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, MB8877, "mb8877");
124125   /* Check whether regular RAM is enabled */
125126   if ( ! osborne1.bank2_enabled )
126127   {
r3867r3868
136137      switch( offset & 0x0F00 )
137138      {
138139      case 0x100:   /* Floppy */
139         wd17xx_w( space, offset, data );
140         wd17xx_w( fdc, offset, data );
140141         break;
141142      case 0x900:   /* IEEE488 PIA */
142143         pia_0_w( space, offset & 0x03, data );
r3867r3868
276277
277278static WRITE8_HANDLER( video_pia_port_a_w )
278279{
280   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, MB8877, "mb8877");
279281   osborne1.new_start_x = data >> 1;
280   wd17xx_set_density( ( data & 0x01 ) ? DEN_FM_LO : DEN_FM_HI );
282   wd17xx_set_density(fdc, ( data & 0x01 ) ? DEN_FM_LO : DEN_FM_HI );
281283
282284   //logerror("Video pia port a write: %02X, density set to %s\n", data, data & 1 ? "DEN_FM_LO" : "DEN_FM_HI" );
283285}
r3867r3868
285287
286288static WRITE8_HANDLER( video_pia_port_b_w )
287289{
290   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, MB8877, "mb8877");
288291   osborne1.new_start_y = data & 0x1F;
289292   osborne1.beep = ( data & 0x20 ) ? 1 : 0;
290293   if ( data & 0x40 )
291294   {
292      wd17xx_set_drive( 0 );
295      wd17xx_set_drive( fdc, 0 );
293296   }
294297   else if ( data & 0x80 )
295298   {
296      wd17xx_set_drive( 1 );
299      wd17xx_set_drive( fdc, 1 );
297300   }
298301   //logerror("Video pia port b write: %02X\n", data );
299302}
r3867r3868
412415DEVICE_IMAGE_LOAD( osborne1_floppy )
413416{
414417   int size, sectors, sectorsize;
418   device_config *fdc = (device_config*)device_list_find_by_tag( image->machine->config->devicelist, MB8877, "mb8877");
415419
416420   if ( ! image_has_been_created( image ) )
417421   {
r3867r3868
422426      case 40 * 10 * 256:
423427         sectors = 10;
424428         sectorsize = 256;
425         wd17xx_set_density( DEN_FM_LO );
429         wd17xx_set_density( fdc, DEN_FM_LO );
426430         break;
427431      case 40 * 5 * 1024:
428432         sectors = 5;
429433         sectorsize = 1024;
430         wd17xx_set_density( DEN_FM_HI );
434         wd17xx_set_density( fdc, DEN_FM_HI );
431435         break;
432436      case 40 * 8 * 512:
433437         sectors = 8;
434438         sectorsize = 512;
435         wd17xx_set_density( DEN_FM_LO );
439         wd17xx_set_density( fdc, DEN_FM_LO );
436440         return INIT_FAIL;
437441      case 40 * 18 * 128:
438442         sectors = 18;
439443         sectorsize = 128;
440         wd17xx_set_density( DEN_FM_LO );
444         wd17xx_set_density( fdc, DEN_FM_LO );
441445         return INIT_FAIL;
442446      case 40 * 9 * 512:
443447         sectors = 9;
444448         sectorsize = 512;
445         wd17xx_set_density( DEN_FM_HI );
449         wd17xx_set_density( fdc, DEN_FM_HI );
446450         return INIT_FAIL;
447451      default:
448452         return INIT_FAIL;
r3867r3868
471475}
472476
473477
474MACHINE_START( osborne1 )
475{
476   /* Configure the floppy disk interface */
477   wd17xx_init( machine, WD_TYPE_MB8877, NULL, NULL );
478}   
479
480
481478MACHINE_RESET( osborne1 )
482479{
483480   const address_space* space = cpu_get_address_space(machine->cpu[0],ADDRESS_SPACE_PROGRAM);
src/mess/machine/wd17xx.c
r3867r3868
2424        the host should read the id data through the data register. This
2525        was accomplished by making this change in the wd17xx_read_id
2626        function:
27         -               wd17xx_complete_command(w, DELAY_DATADONE);
27         -               wd17xx_complete_command(device, DELAY_DATADONE);
2828         +               wd17xx_set_data_request();
2929
3030   TODO:
r3867r3868
5454#define DELAY_DATADONE   3
5555
5656
57/* enumeration to specify the type of FDC; there are subtle differences */
58typedef enum
59{
60   WD_TYPE_1770,
61   WD_TYPE_1772,
62   WD_TYPE_1773,
63   WD_TYPE_179X,
64   WD_TYPE_1793,
65   WD_TYPE_2793,
5766
67   /* duplicate constants */
68   WD_TYPE_177X = WD_TYPE_1770,
69   WD_TYPE_MB8877 = WD_TYPE_179X
70} wd17xx_type_t;
71
72
5873/***************************************************************************
5974
6075   Constants
r3867r3868
138153
139154***************************************************************************/
140155
141typedef struct _wd17xx_info wd17xx_info;
142struct _wd17xx_info
156typedef struct _wd17xx_t wd17xx_t;
157struct _wd17xx_t
143158{
144   void   (*callback)(running_machine *, wd17xx_state_t event, void *param);   /* callback for IRQ status */
145   void   *callback_param;
146159   DENSITY   density;            /* FM/MFM, single / double density */
147160   wd17xx_type_t type;
148161   UINT8   track_reg;            /* value of track register */
r3867r3868
178191   int      data_direction;
179192
180193   UINT8   ipl;               /* index pulse */   
194   
195   emu_timer *busy_timer;
196
197   /* this is the drive currently selected */
198   UINT8 current_drive;
199
200   /* this is the head currently selected */
201   UINT8 hd;
202
203   /* pause time when writeing/reading sector */
204   int pause_time;
205   
206   /* Pointer to interface */
207   const wd17xx_interface *intf;
181208};
182209
210INLINE wd17xx_t *get_safe_token(const device_config *device)
211{
212   assert(device != NULL);
213   assert(device->token != NULL);
183214
215   return (wd17xx_t *)device->token;
216}
184217
218
185219/***************************************************************************
186220
187221   Read track stuff
r3867r3868
240274
241275***************************************************************************/
242276
243static void wd17xx_complete_command(wd17xx_info *, int delay);
244static void wd17xx_clear_data_request(running_machine *);
245static void wd17xx_set_data_request(running_machine *);
246static void wd17xx_timed_data_request(void);
247static void wd17xx_set_irq(running_machine *, wd17xx_info *);
248static emu_timer *busy_timer = NULL;
249
250/* one wd controlling multiple drives */
251static wd17xx_info wd;
252
253/* this is the drive currently selected */
254static UINT8 current_drive;
255
256/* this is the head currently selected */
257static UINT8 hd = 0;
258
259/* pause time when writeing/reading sector */
260static int wd17xx_pause_time;
277static void wd17xx_complete_command(const device_config *device, int delay);
278static void wd17xx_clear_data_request(const device_config *device);
279static void wd17xx_set_data_request(const device_config *device);
280static void wd17xx_timed_data_request(const device_config *device);
281static void wd17xx_set_irq(const device_config *device);
261282/**************************************************************************/
262283
263static const device_config *wd17xx_current_image(void)
284static const device_config *wd17xx_current_image(const device_config *device)
264285{
265   return image_from_devtype_and_index(IO_FLOPPY, current_drive);
286   wd17xx_t *w = get_safe_token(device);
287   return image_from_devtype_and_index(IO_FLOPPY, w->current_drive);
266288}
267289
268290
269291
270292/* use this to determine which drive is controlled by WD */
271void wd17xx_set_drive(UINT8 drive)
293void wd17xx_set_drive(const device_config *device,UINT8 drive)
272294{
273   current_drive = drive;
295   wd17xx_t *w = get_safe_token(device);
296   w->current_drive = drive;
274297}
275298
276
277
278void wd17xx_set_side(UINT8 head)
299void wd17xx_set_side(const device_config *device,UINT8 head)
279300{
301   wd17xx_t *w = get_safe_token(device);
280302   if (VERBOSE)
281303   {
282      if (head != hd)
304      if (head != w->hd)
283305         logerror("wd17xx_set_side: $%02x\n", head);
284306   }
285   hd = head;
307   w->hd = head;
286308}
287309
288310
289311
290void wd17xx_set_density(DENSITY density)
312void wd17xx_set_density(const device_config *device,DENSITY density)
291313{
292   wd17xx_info *w = &wd;
314   wd17xx_t *w = get_safe_token(device);
293315
294316   if (VERBOSE)
295317   {
r3867r3868
304326
305327static TIMER_CALLBACK(wd17xx_busy_callback)
306328{
307   wd17xx_info *info = (wd17xx_info *) ptr;
308   wd17xx_set_irq(machine, info);
309   timer_reset(busy_timer, attotime_never);
329   const device_config *device = ptr;
330   wd17xx_t *w = get_safe_token(device);
331   wd17xx_set_irq(device);
332   timer_reset(w->busy_timer, attotime_never);
310333}
311334
312335
313336
314static void wd17xx_set_busy(wd17xx_info *w, attotime duration)
337static void wd17xx_set_busy(const device_config *device, attotime duration)
315338{
339   wd17xx_t *w = get_safe_token(device);
316340   w->status |= STA_1_BUSY;
317   timer_adjust_oneshot(busy_timer, duration, 0);
341   timer_adjust_oneshot(w->busy_timer, duration, 0);
318342}
319343
320344
321345
322346/* BUSY COUNT DOESN'T WORK PROPERLY! */
323347
324static void wd17xx_restore(running_machine *machine, wd17xx_info *w)
348static void wd17xx_restore(const device_config *device)
325349{
326350   UINT8 step_counter;
327
328   if (current_drive >= device_count(machine, IO_FLOPPY))
351   wd17xx_t *w = get_safe_token(device);
352   
353   if (w->current_drive >= device_count(device->machine, IO_FLOPPY))
329354      return;
330355
331356   step_counter = 255;
r3867r3868
342367   /* reset busy count */
343368   w->busy_count = 0;
344369
345   if (image_slotexists(wd17xx_current_image()))
370   if (image_slotexists(wd17xx_current_image(device)))
346371   {
347372      /* keep stepping until track 0 is received or 255 steps have been done */
348      while (!(floppy_drive_get_flag_state(wd17xx_current_image(), FLOPPY_DRIVE_HEAD_AT_TRACK_0)) && (step_counter!=0))
373      while (!(floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_HEAD_AT_TRACK_0)) && (step_counter!=0))
349374      {
350375         /* update time to simulate seek time busy signal */
351376         w->busy_count++;
352         floppy_drive_seek(wd17xx_current_image(), w->direction);
377         floppy_drive_seek(wd17xx_current_image(device), w->direction);
353378         step_counter--;
354379      }
355380   }
r3867r3868
361386   w->busy_count = 0;   //w->busy_count * ((w->data & FDC_STEP_RATE) + 1);
362387
363388   /* when command completes set irq */
364   wd17xx_set_irq(w);
389   wd17xx_set_irq(device);
365390#endif
366   wd17xx_set_busy(w, ATTOTIME_IN_USEC(100));
391   wd17xx_set_busy(device, ATTOTIME_IN_USEC(100));
367392}
368393
369394
r3867r3868
371396static TIMER_CALLBACK(wd17xx_misc_timer_callback);
372397static TIMER_CALLBACK(wd17xx_read_sector_callback);
373398static TIMER_CALLBACK(wd17xx_write_sector_callback);
374static void wd17xx_index_pulse_callback(const device_config *img, int state);
399static void wd17xx_index_pulse_callback(const device_config *controller,const device_config *img, int state);
375400
376void wd17xx_reset(running_machine *machine)
377{
378   int i;
379   for (i = 0; i < device_count(machine, IO_FLOPPY); i++)
380   {
381      const device_config *img = image_from_devtype_and_index(IO_FLOPPY, i);
382      floppy_drive_set_index_pulse_callback(img, wd17xx_index_pulse_callback);
383      floppy_drive_set_rpm( img, 300.);
384   }
385401
386   wd17xx_restore(machine, &wd);
387}
388
389
390
391void wd17xx_init(running_machine *machine, wd17xx_type_t type, void (*callback)(running_machine *, wd17xx_state_t, void *), void *param)
392{
393   assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call wd17xx_init at init time!");
394
395   memset(&wd, 0, sizeof(wd));
396   wd.status = STA_1_TRACK0;
397   wd.type = type;
398   wd.callback = callback;
399   wd.callback_param = param;
400//   wd.status_ipl = STA_1_IPL;
401   wd.density = DEN_MFM_LO;
402   busy_timer = timer_alloc(machine, wd17xx_busy_callback, &wd);
403   wd.timer = timer_alloc(machine, wd17xx_misc_timer_callback, NULL);
404   wd.timer_rs = timer_alloc(machine, wd17xx_read_sector_callback, NULL);
405   wd.timer_ws = timer_alloc(machine, wd17xx_write_sector_callback, NULL);
406   wd17xx_pause_time = 40;
407   wd17xx_reset(machine);
408}
409
410
411
412402/* track writing, converted to format commands */
413static void write_track(wd17xx_info * w)
403static void write_track(const device_config *device)
414404{
405   wd17xx_t *w = get_safe_token(device);
415406   int i;
416407   for (i=0;i+4<w->data_offset;)
417408   {
r3867r3868
424415         int len     = w->buffer[i+4];
425416         int filler  = 0xe5; /* IBM and Thomson */
426417         int density = w->density;
427         floppy_drive_format_sector(wd17xx_current_image(),side,sector,track,
428                  hd,sector,density?1:0,filler);
418         floppy_drive_format_sector(wd17xx_current_image(device),side,sector,track,
419                  w->hd,sector,density?1:0,filler);
429420         (void)len;
430421         i += 128; /* at least... */
431422      }
r3867r3868
437428
438429
439430/* read an entire track */
440static void read_track(running_machine *machine, wd17xx_info * w)
431static void read_track(const device_config *device)
441432{
433   wd17xx_t *w = get_safe_token(device);
442434#if 0
443435   UINT8 *psrc;      /* pointer to track format structure */
444436   UINT8 *pdst;      /* pointer to track buffer */
r3867r3868
560552
561553   w->data_count = (w->density) ? TRKSIZE_DD : TRKSIZE_SD;
562554
563   floppy_drive_read_track_data_info_buffer( wd17xx_current_image(), hd, (char *)w->buffer, &(w->data_count) );
555   floppy_drive_read_track_data_info_buffer( wd17xx_current_image(device), w->hd, (char *)w->buffer, &(w->data_count) );
564556
565557   w->data_offset = 0;
566558
567   wd17xx_set_data_request(machine);
559   wd17xx_set_data_request(device);
568560   w->status |= STA_2_BUSY;
569561   w->busy_count = 0;
570562}
r3867r3868
597589
598590
599591/* read the next data address mark */
600static void wd17xx_read_id(running_machine *machine, wd17xx_info * w)
592static void wd17xx_read_id(const device_config *device)
601593{
602594   chrn_id id;
595   wd17xx_t *w = get_safe_token(device);
603596
604597   w->status &= ~(STA_2_CRC_ERR | STA_2_REC_N_FND);
605598
606599   /* get next id from disc */
607   if (floppy_drive_get_next_id(wd17xx_current_image(), hd, &id))
600   if (floppy_drive_get_next_id(wd17xx_current_image(device), w->hd, &id))
608601   {
609602      UINT16 crc = 0xffff;
610603
r3867r3868
635628      w->status |= STA_2_BUSY;
636629      w->busy_count = 0;
637630
638      wd17xx_set_data_request(machine);
631      wd17xx_set_data_request(device);
639632
640633      logerror("read id succeeded.\n");
641634   }
r3867r3868
646639      //w->sector = w->track_reg;
647640      logerror("read id failed\n");
648641
649      wd17xx_complete_command(w, DELAY_ERROR);
642      wd17xx_complete_command(device, DELAY_ERROR);
650643   }
651644}
652645
653646
654647
655static void wd17xx_index_pulse_callback(const device_config *img, int state)
648static void wd17xx_index_pulse_callback(const device_config *controller, const device_config *img, int state)
656649{
657   wd17xx_info *w = &wd;
658   if ( img != wd17xx_current_image() )
650   wd17xx_t *w = get_safe_token(controller);
651   if ( img != wd17xx_current_image(controller) )
659652      return;
660653   w->ipl = state;
661654}
662655
663656
664657
665static int wd17xx_has_side_select(void)
658static int wd17xx_has_side_select(const device_config *device)
666659{
667   return (wd.type == WD_TYPE_1773) || (wd.type == WD_TYPE_1793) || (wd.type == WD_TYPE_2793);
660   wd17xx_t *w = get_safe_token(device);
661   return (w->type == WD_TYPE_1773) || (w->type == WD_TYPE_1793) || (w->type == WD_TYPE_2793);
668662}
669663
670664
671665
672static int wd17xx_locate_sector(wd17xx_info *w)
666static int wd17xx_locate_sector(const device_config *device)
673667{
674668   UINT8 revolution_count;
675669   chrn_id id;
676
670   wd17xx_t *w = get_safe_token(device);
671   
677672   revolution_count = 0;
678673
679674   w->status &= ~STA_2_REC_N_FND;
680675
681676   while (revolution_count!=4)
682677   {
683      if (floppy_drive_get_next_id(wd17xx_current_image(), hd, &id))
678      if (floppy_drive_get_next_id(wd17xx_current_image(device), w->hd, &id))
684679      {
685680         /* compare track */
686681         if (id.C == w->track_reg)
687682         {
688683            /* compare head, if we were asked to */
689            if (!wd17xx_has_side_select() || (id.H == w->head) || (w->head == (UINT8) ~0))
684            if (!wd17xx_has_side_select(device) || (id.H == w->head) || (w->head == (UINT8) ~0))
690685            {
691686               /* compare id */
692687               if (id.R == w->sector)
r3867r3868
705700      }
706701
707702       /* index set? */
708      if (floppy_drive_get_flag_state(wd17xx_current_image(), FLOPPY_DRIVE_INDEX))
703      if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_INDEX))
709704      {
710705         /* update revolution count */
711706         revolution_count++;
r3867r3868
715710}
716711
717712
718static int wd17xx_find_sector(wd17xx_info *w)
713static int wd17xx_find_sector(const device_config *device)
719714{
720   if ( wd17xx_locate_sector(w) )
715   wd17xx_t *w = get_safe_token(device);
716   if ( wd17xx_locate_sector(device) )
721717   {
722718      return 1;
723719   }
r3867r3868
728724   if (VERBOSE)
729725      logerror("track %d sector %d not found!\n", w->track_reg, w->sector);
730726
731   wd17xx_complete_command(w, DELAY_ERROR);
727   wd17xx_complete_command(device, DELAY_ERROR);
732728
733729   return 0;
734730}
r3867r3868
736732
737733
738734/* read a sector */
739static void wd17xx_read_sector(wd17xx_info *w)
735static void wd17xx_read_sector(const device_config *device)
740736{
737   wd17xx_t *w = get_safe_token(device);
741738   w->data_offset = 0;
742739
743740   /* side compare? */
r3867r3868
746743   else
747744      w->head = ~0;
748745
749   if (wd17xx_find_sector(w))
746   if (wd17xx_find_sector(device))
750747   {
751748      w->data_count = w->sector_length;
752749
753750      /* read data */
754      floppy_drive_read_sector_data(wd17xx_current_image(), hd, w->sector_data_id, (char *)w->buffer, w->sector_length);
751      floppy_drive_read_sector_data(wd17xx_current_image(device), w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length);
755752
756      wd17xx_timed_data_request();
753      wd17xx_timed_data_request(device);
757754
758755      w->status |= STA_2_BUSY;
759756      w->busy_count = 0;
r3867r3868
762759
763760
764761
765static void wd17xx_callback(running_machine *machine, wd17xx_info *w, wd17xx_state_t state)
762static void wd17xx_callback(const device_config *device, wd17xx_state_t state)
766763{
767   if (w->callback)
768      (*w->callback)(machine, state, w->callback_param);
764   wd17xx_t *w = get_safe_token(device);
765   void *param = NULL;
766   if (w->intf->callback_param)
767      param = (*w->intf->callback_param)(device);
768   if (w->intf->callback)
769      (*w->intf->callback)(device, state, param);
769770}
770771
771772
772773
773static void   wd17xx_set_irq(running_machine *machine, wd17xx_info *w)
774static void   wd17xx_set_irq(const device_config *device)
774775{
776   wd17xx_t *w = get_safe_token(device);
775777   w->status &= ~STA_2_BUSY;
776778   /* generate an IRQ */
777   wd17xx_callback(machine, w, WD17XX_IRQ_SET);
779   wd17xx_callback(device, WD17XX_IRQ_SET);
778780}
779781
780782
r3867r3868
790792
791793static TIMER_CALLBACK(wd17xx_misc_timer_callback)
792794{
795   const device_config *device = ptr;
793796   int callback_type = param;
794   wd17xx_info *w = &wd;
797   wd17xx_t *w = get_safe_token(device);
795798
796799   switch(callback_type) {
797800   case MISCCALLBACK_COMMAND:
798801      /* command callback */
799      wd17xx_set_irq(machine, w);
802      wd17xx_set_irq(device);
800803      break;
801804
802805   case MISCCALLBACK_DATA:
803806      /* data callback */
804807      /* ok, trigger data request now */
805      wd17xx_set_data_request(machine);
808      wd17xx_set_data_request(device);
806809      break;
807810   }
808811
r3867r3868
819822or bytes missed */
820823/* TJL - I have add a parameter to allow the emulation to specify the delay
821824*/
822static void wd17xx_complete_command(wd17xx_info *w, int delay)
825static void wd17xx_complete_command(const device_config *device, int delay)
823826{
824827   int usecs;
828   wd17xx_t *w = get_safe_token(device);
825829
826830   w->data_count = 0;
827831
r3867r3868
837841
838842
839843
840static void wd17xx_write_sector(wd17xx_info *w)
844static void wd17xx_write_sector(const device_config *device)
841845{
846   wd17xx_t *w = get_safe_token(device);
842847   /* at this point, the disc is write enabled, and data
843848    * has been transfered into our buffer - now write it to
844849    * the disc image or to the real disc
r3867r3868
851856      w->head = ~0;
852857
853858   /* find sector */
854   if (wd17xx_find_sector(w))
859   if (wd17xx_find_sector(device))
855860   {
856861      w->data_count = w->sector_length;
857862
858863      /* write data */
859      floppy_drive_write_sector_data(wd17xx_current_image(), hd, w->sector_data_id, (char *)w->buffer, w->sector_length,w->write_cmd & 0x01);
864      floppy_drive_write_sector_data(wd17xx_current_image(device), w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length,w->write_cmd & 0x01);
860865   }
861866}
862867
863868
864869
865870/* verify the seek operation by looking for a id that has a matching track value */
866static void wd17xx_verify_seek(wd17xx_info *w)
871static void wd17xx_verify_seek(const device_config *device)
867872{
868873   UINT8 revolution_count;
869874   chrn_id id;
875   wd17xx_t *w = get_safe_token(device);
870876
871877   revolution_count = 0;
872878
r3867r3868
877883   /* must be found within 5 revolutions otherwise error */
878884   while (revolution_count!=5)
879885   {
880      if (floppy_drive_get_next_id(wd17xx_current_image(), hd, &id))
886      if (floppy_drive_get_next_id(wd17xx_current_image(device), w->hd, &id))
881887      {
882888         /* compare track */
883889         if (id.C == w->track_reg)
r3867r3868
888894      }
889895
890896       /* index set? */
891      if (floppy_drive_get_flag_state(wd17xx_current_image(), FLOPPY_DRIVE_INDEX))
897      if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_INDEX))
892898      {
893899         /* update revolution count */
894900         revolution_count++;
r3867r3868
903909
904910
905911/* clear a data request */
906static void wd17xx_clear_data_request(running_machine *machine)
912static void wd17xx_clear_data_request(const device_config *device)
907913{
908   wd17xx_info *w = &wd;
914   wd17xx_t *w = get_safe_token(device);
909915
910916//   w->status_drq = 0;
911   wd17xx_callback(machine, w, WD17XX_DRQ_CLR);
917   wd17xx_callback(device, WD17XX_DRQ_CLR);
912918   w->status &= ~STA_2_DRQ;
913919}
914920
915921
916922
917923/* set data request */
918static void wd17xx_set_data_request(running_machine *machine)
924static void wd17xx_set_data_request(const device_config *device)
919925{
920   wd17xx_info *w = &wd;
926   wd17xx_t *w = get_safe_token(device);
921927
922928   if (w->status & STA_2_DRQ)
923929   {
r3867r3868
927933
928934   /* set drq */
929935//   w->status_drq = STA_2_DRQ;
930   wd17xx_callback(machine, w, WD17XX_DRQ_SET);
936   wd17xx_callback(device, WD17XX_DRQ_SET);
931937   w->status |= STA_2_DRQ;
932938}
933939
r3867r3868
936942/* callback to initiate read sector */
937943static TIMER_CALLBACK(wd17xx_read_sector_callback)
938944{
939   wd17xx_info *w = &wd;
945   const device_config *device = ptr;
946   wd17xx_t *w = get_safe_token(device);
940947
941948   /* ok, start that read! */
942949
943950   if (VERBOSE)
944951      logerror("wd179x: Read Sector callback.\n");
945952
946   if (!floppy_drive_get_flag_state(wd17xx_current_image(), FLOPPY_DRIVE_READY))
947      wd17xx_complete_command(w, DELAY_NOTREADY);
953   if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
954      wd17xx_complete_command(device, DELAY_NOTREADY);
948955   else
949      wd17xx_read_sector(w);
956      wd17xx_read_sector(device);
950957
951958   /* stop it, but don't allow it to be free'd */
952959   timer_reset(w->timer_rs, attotime_never);
r3867r3868
957964/* callback to initiate write sector */
958965static TIMER_CALLBACK(wd17xx_write_sector_callback)
959966{
960   wd17xx_info *w = &wd;
967   const device_config *device = ptr;
968   wd17xx_t *w = get_safe_token(device);
961969
962970   /* ok, start that write! */
963971
964972   if (VERBOSE)
965973      logerror("wd179x: Write Sector callback.\n");
966974
967   if (!floppy_drive_get_flag_state(wd17xx_current_image(), FLOPPY_DRIVE_READY))
968      wd17xx_complete_command(w, DELAY_NOTREADY);
975   if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
976      wd17xx_complete_command(device, DELAY_NOTREADY);
969977   else
970978   {
971979
972980      /* drive write protected? */
973      if (floppy_drive_get_flag_state(wd17xx_current_image(),FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
981      if (floppy_drive_get_flag_state(wd17xx_current_image(device),FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
974982      {
975983         w->status |= STA_2_WRITE_PRO;
976984
977         wd17xx_complete_command(w, DELAY_ERROR);
985         wd17xx_complete_command(device, DELAY_ERROR);
978986      }
979987      else
980988      {
r3867r3868
985993            w->head = ~0;
986994
987995         /* attempt to find it first before getting data from cpu */
988         if (wd17xx_find_sector(w))
996         if (wd17xx_find_sector(device))
989997         {
990998            /* request data */
991999            w->data_offset = 0;
9921000            w->data_count = w->sector_length;
9931001
994            wd17xx_set_data_request(machine);
1002            wd17xx_set_data_request(device);
9951003
9961004            w->status |= STA_2_BUSY;
9971005            w->busy_count = 0;
r3867r3868
10061014
10071015
10081016/* setup a timed data request - data request will be triggered in a few usecs time */
1009static void wd17xx_timed_data_request(void)
1017static void wd17xx_timed_data_request(const device_config *device)
10101018{
10111019   int usecs;
1012   wd17xx_info *w = &wd;
1020   wd17xx_t *w = get_safe_token(device);
10131021
10141022   usecs = floppy_drive_get_datarate_in_us(w->density);
10151023
r3867r3868
10201028
10211029
10221030/* setup a timed read sector - read sector will be triggered in a few usecs time */
1023static void wd17xx_timed_read_sector_request(void)
1031static void wd17xx_timed_read_sector_request(const device_config *device)
10241032{
10251033   int usecs;
1026   wd17xx_info *w = &wd;
1034   wd17xx_t *w = get_safe_token(device);
10271035
1028   usecs = wd17xx_pause_time; /* How long should we wait? How about 40 micro seconds? */
1036   usecs = w->pause_time; /* How long should we wait? How about 40 micro seconds? */
10291037
10301038   /* set new timer */
10311039   timer_reset(w->timer_rs, ATTOTIME_IN_USEC(usecs));
r3867r3868
10341042
10351043
10361044/* setup a timed write sector - write sector will be triggered in a few usecs time */
1037static void wd17xx_timed_write_sector_request(void)
1045static void wd17xx_timed_write_sector_request(const device_config *device)
10381046{
10391047   int usecs;
1040   wd17xx_info *w = &wd;
1048   wd17xx_t *w = get_safe_token(device);
10411049
1042   usecs = wd17xx_pause_time; /* How long should we wait? How about 40 micro seconds? */
1050   usecs = w->pause_time; /* How long should we wait? How about 40 micro seconds? */
10431051
10441052   /* set new timer */
10451053   timer_reset(w->timer_ws, ATTOTIME_IN_USEC(usecs));
10461054}
10471055
1048void wd17xx_set_pause_time(int usec)
1056void wd17xx_set_pause_time(const device_config *device,int usec)
10491057{
1050   wd17xx_pause_time = usec;
1058   wd17xx_t *w = get_safe_token(device);
1059   w->pause_time = usec;
10511060}
10521061
10531062/* read the FDC status register. This clears IRQ line too */
1054 READ8_HANDLER ( wd17xx_status_r )
1063 READ8_DEVICE_HANDLER ( wd17xx_status_r )
10551064{
1056   wd17xx_info *w = &wd;
1065   wd17xx_t *w = get_safe_token(device);
10571066   int result = w->status;
10581067
1059   wd17xx_callback(space->machine, w, WD17XX_IRQ_CLR);
1068   wd17xx_callback(device, WD17XX_IRQ_CLR);
10601069//   if (w->busy_count)
10611070//   {
10621071//      if (!--w->busy_count)
r3867r3868
10721081
10731082      /* set track 0 state */
10741083      result &=~STA_1_TRACK0;
1075      if (floppy_drive_get_flag_state(wd17xx_current_image(), FLOPPY_DRIVE_HEAD_AT_TRACK_0))
1084      if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_HEAD_AT_TRACK_0))
10761085         result |= STA_1_TRACK0;
10771086
1078   //   floppy_drive_set_ready_state(wd17xx_current_image(), 1,1);
1087   //   floppy_drive_set_ready_state(wd17xx_current_image(device), 1,1);
10791088      w->status &= ~STA_1_NOT_READY;
10801089
10811090      /* TODO: What is this?  We need some more info on this */
10821091      if ((w->type == WD_TYPE_179X) || (w->type == WD_TYPE_1793) || (w->type == WD_TYPE_1773))
10831092      {
1084         if (!floppy_drive_get_flag_state(wd17xx_current_image(), FLOPPY_DRIVE_READY))
1093         if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
10851094            w->status |= STA_1_NOT_READY;
10861095      }
10871096      else
10881097      {
1089         if (floppy_drive_get_flag_state(wd17xx_current_image(), FLOPPY_DRIVE_READY))
1098         if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
10901099            w->status |= STA_1_NOT_READY;
10911100      }
10921101   }
r3867r3868
11061115
11071116
11081117/* read the FDC track register */
1109READ8_HANDLER ( wd17xx_track_r )
1118READ8_DEVICE_HANDLER ( wd17xx_track_r )
11101119{
1111   wd17xx_info *w = &wd;
1120   wd17xx_t *w = get_safe_token(device);
11121121
11131122   if (VERBOSE)
11141123      logerror("wd17xx_track_r: $%02X\n", w->track_reg);
r3867r3868
11191128
11201129
11211130/* read the FDC sector register */
1122READ8_HANDLER ( wd17xx_sector_r )
1131READ8_DEVICE_HANDLER ( wd17xx_sector_r )
11231132{
1124   wd17xx_info *w = &wd;
1133   wd17xx_t *w = get_safe_token(device);
11251134
11261135   if (VERBOSE)
11271136      logerror("wd17xx_sector_r: $%02X\n", w->sector);
r3867r3868
11321141
11331142
11341143/* read the FDC data register */
1135 READ8_HANDLER ( wd17xx_data_r )
1144 READ8_DEVICE_HANDLER ( wd17xx_data_r )
11361145{
1137   wd17xx_info *w = &wd;
1146   wd17xx_t *w = get_safe_token(device);
11381147
11391148   if (w->data_count >= 1)
11401149   {
11411150      /* clear data request */
1142      wd17xx_clear_data_request(space->machine);
1151      wd17xx_clear_data_request(device);
11431152
11441153      /* yes */
11451154      w->data = w->buffer[w->data_offset++];
r3867r3868
11651174         /* Check we should handle the next sector for a multi record read */
11661175         if ( w->command_type == TYPE_II && w->command == FDC_READ_SEC && ( w->read_cmd & 0x10 ) ) {
11671176            w->sector++;
1168            if (wd17xx_locate_sector(w))
1177            if (wd17xx_locate_sector(device))
11691178            {
11701179               w->data_count = w->sector_length;
11711180
11721181               /* read data */
1173               floppy_drive_read_sector_data(wd17xx_current_image(), hd, w->sector_data_id, (char *)w->buffer, w->sector_length);
1182               floppy_drive_read_sector_data(wd17xx_current_image(device), w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length);
11741183
1175               wd17xx_timed_data_request();
1184               wd17xx_timed_data_request(device);
11761185
11771186               w->status |= STA_2_BUSY;
11781187               w->busy_count = 0;
11791188            } else {
1180               wd17xx_complete_command(w, DELAY_DATADONE);
1189               wd17xx_complete_command(device, DELAY_DATADONE);
11811190
11821191               if (VERBOSE)
11831192                  logerror("wd17xx_data_r(): multi data read completed\n");
r3867r3868
11851194         } else {
11861195            /* Delay the INTRQ 3 byte times becuase we need to read two CRC bytes and
11871196               compare them with a calculated CRC */
1188            wd17xx_complete_command(w, DELAY_DATADONE);
1197            wd17xx_complete_command(device, DELAY_DATADONE);
11891198
11901199            if (VERBOSE)
11911200               logerror("wd17xx_data_r(): data read completed\n");
r3867r3868
11941203      else
11951204      {
11961205         /* issue a timed data request */
1197         wd17xx_timed_data_request();
1206         wd17xx_timed_data_request(device);
11981207      }
11991208   }
12001209   else
r3867r3868
12071216
12081217
12091218/* write the FDC command register */
1210WRITE8_HANDLER ( wd17xx_command_w )
1219WRITE8_DEVICE_HANDLER ( wd17xx_command_w )
12111220{
1212   wd17xx_info *w = &wd;
1221   wd17xx_t *w = get_safe_token(device);
12131222
1214   floppy_drive_set_motor_state(wd17xx_current_image(), 1);
1215   floppy_drive_set_ready_state(wd17xx_current_image(), 1,0);
1223   floppy_drive_set_motor_state(wd17xx_current_image(device), 1);
1224   floppy_drive_set_ready_state(wd17xx_current_image(device), 1,0);
12161225   /* also cleared by writing command */
1217   wd17xx_callback(space->machine, w, WD17XX_IRQ_CLR);
1226   wd17xx_callback(device, WD17XX_IRQ_CLR);
12181227
12191228   /* clear write protected. On read sector, read track and read dam, write protected bit is clear */
12201229   w->status &= ~((1<<6) | (1<<5) | (1<<4));
r3867r3868
12281237      w->data_offset = 0;
12291238      w->status &= ~(STA_2_BUSY);
12301239
1231      wd17xx_clear_data_request(space->machine);
1240      wd17xx_clear_data_request(device);
12321241
12331242      if (data & 0x0f)
12341243      {
r3867r3868
12601269         w->command_type = TYPE_II;
12611270         w->status &= ~STA_2_LOST_DAT;
12621271         w->status |= STA_2_BUSY;
1263         wd17xx_clear_data_request(space->machine);
1272         wd17xx_clear_data_request(device);
12641273
1265         wd17xx_timed_read_sector_request();
1274         wd17xx_timed_read_sector_request(device);
12661275
12671276         return;
12681277      }
r3867r3868
12771286         w->command_type = TYPE_II;
12781287         w->status &= ~STA_2_LOST_DAT;
12791288         w->status |= STA_2_BUSY;
1280         wd17xx_clear_data_request(space->machine);
1289         wd17xx_clear_data_request(device);
12811290
1282         wd17xx_timed_write_sector_request();
1291         wd17xx_timed_write_sector_request(device);
12831292
12841293         return;
12851294      }
r3867r3868
12921301         w->command = data & ~FDC_MASK_TYPE_III;
12931302         w->command_type = TYPE_III;
12941303         w->status &= ~STA_2_LOST_DAT;
1295         wd17xx_clear_data_request(space->machine);
1304         wd17xx_clear_data_request(device);
12961305#if 1
12971306//         w->status = seek(w, w->track, w->head, w->sector);
12981307         if (w->status == 0)
1299            read_track(space->machine, w);
1308            read_track(device);
13001309#endif
13011310         return;
13021311      }
r3867r3868
13081317
13091318         w->command_type = TYPE_III;
13101319         w->status &= ~STA_2_LOST_DAT;
1311         wd17xx_clear_data_request(space->machine);
1320         wd17xx_clear_data_request(device);
13121321
1313         if (!floppy_drive_get_flag_state(wd17xx_current_image(), FLOPPY_DRIVE_READY))
1322         if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
13141323            {
1315            wd17xx_complete_command(w, DELAY_NOTREADY);
1324            wd17xx_complete_command(device, DELAY_NOTREADY);
13161325            }
13171326            else
13181327            {
13191328
13201329                /* drive write protected? */
1321                if (floppy_drive_get_flag_state(wd17xx_current_image(),FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
1330                if (floppy_drive_get_flag_state(wd17xx_current_image(device),FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
13221331                {
13231332                    /* yes */
13241333                    w->status |= STA_2_WRITE_PRO;
13251334                    /* quit command */
1326                    wd17xx_complete_command(w, DELAY_ERROR);
1335                    wd17xx_complete_command(device, DELAY_ERROR);
13271336                }
13281337                else
13291338                {
13301339                    w->command = data & ~FDC_MASK_TYPE_III;
13311340                    w->data_offset = 0;
13321341                    w->data_count = (w->density) ? TRKSIZE_DD : TRKSIZE_SD;
1333                    wd17xx_set_data_request(space->machine);
1342                    wd17xx_set_data_request(device);
13341343
13351344                    w->status |= STA_2_BUSY;
13361345                    w->busy_count = 0;
r3867r3868
13461355
13471356         w->command_type = TYPE_III;
13481357         w->status &= ~STA_2_LOST_DAT;
1349           wd17xx_clear_data_request(space->machine);
1358           wd17xx_clear_data_request(device);
13501359
1351         if (!floppy_drive_get_flag_state(wd17xx_current_image(), FLOPPY_DRIVE_READY))
1360         if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY))
13521361            {
1353            wd17xx_complete_command(w, DELAY_NOTREADY);
1362            wd17xx_complete_command(device, DELAY_NOTREADY);
13541363            }
13551364            else
13561365            {
1357                wd17xx_read_id(space->machine, w);
1366                wd17xx_read_id(device);
13581367            }
13591368         return;
13601369      }
r3867r3868
13751384      if (VERBOSE)
13761385         logerror("wd17xx_command_w $%02X RESTORE\n", data);
13771386
1378      wd17xx_restore(space->machine, w);
1387      wd17xx_restore(device);
13791388   }
13801389
13811390   if ((data & ~FDC_MASK_TYPE_I) == FDC_SEEK)
r3867r3868
14181427         /* update track reg */
14191428         w->track_reg += w->direction;
14201429
1421         floppy_drive_seek(wd17xx_current_image(), w->direction);
1430         floppy_drive_seek(wd17xx_current_image(device), w->direction);
14221431      }
14231432
14241433      /* simulate seek time busy signal */
14251434      w->busy_count = 0;   //w->busy_count * ((data & FDC_STEP_RATE) + 1);
14261435#if 0
1427      wd17xx_set_irq(w);
1436      wd17xx_set_irq(device);
14281437#endif
1429      wd17xx_set_busy(w, ATTOTIME_IN_USEC(100));
1438      wd17xx_set_busy(device, ATTOTIME_IN_USEC(100));
14301439
14311440   }
14321441
r3867r3868
14401449      /* simulate seek time busy signal */
14411450      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
14421451
1443      floppy_drive_seek(wd17xx_current_image(), w->direction);
1452      floppy_drive_seek(wd17xx_current_image(device), w->direction);
14441453
14451454      if (data & FDC_STEP_UPDATE)
14461455         w->track_reg += w->direction;
14471456
14481457#if 0
1449      wd17xx_set_irq(w);
1458      wd17xx_set_irq(device);
14501459#endif
1451      wd17xx_set_busy(w, ATTOTIME_IN_USEC(100));
1460      wd17xx_set_busy(device, ATTOTIME_IN_USEC(100));
14521461
14531462
14541463   }
r3867r3868
14631472      /* simulate seek time busy signal */
14641473      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
14651474
1466      floppy_drive_seek(wd17xx_current_image(), w->direction);
1475      floppy_drive_seek(wd17xx_current_image(device), w->direction);
14671476
14681477      if (data & FDC_STEP_UPDATE)
14691478         w->track_reg += w->direction;
14701479#if 0
1471      wd17xx_set_irq(w);
1480      wd17xx_set_irq(device);
14721481#endif
1473      wd17xx_set_busy(w, ATTOTIME_IN_USEC(100));
1482      wd17xx_set_busy(device, ATTOTIME_IN_USEC(100));
14741483
14751484   }
14761485
r3867r3868
14851494      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
14861495
14871496      /* for now only allows a single drive to be selected */
1488      floppy_drive_seek(wd17xx_current_image(), w->direction);
1497      floppy_drive_seek(wd17xx_current_image(device), w->direction);
14891498
14901499      if (data & FDC_STEP_UPDATE)
14911500         w->track_reg += w->direction;
14921501
14931502#if 0
1494      wd17xx_set_irq(w);
1503      wd17xx_set_irq(device);
14951504#endif
1496      wd17xx_set_busy(w, ATTOTIME_IN_USEC(100));
1505      wd17xx_set_busy(device, ATTOTIME_IN_USEC(100));
14971506   }
14981507
14991508//   if (w->busy_count==0)
r3867r3868
15091518   if (data & FDC_STEP_VERIFY)
15101519   {
15111520      /* verify seek */
1512      wd17xx_verify_seek(w);
1521      wd17xx_verify_seek(device);
15131522   }
15141523}
15151524
15161525
15171526
15181527/* write the FDC track register */
1519WRITE8_HANDLER ( wd17xx_track_w )
1528WRITE8_DEVICE_HANDLER ( wd17xx_track_w )
15201529{
1521   wd17xx_info *w = &wd;
1530   wd17xx_t *w = get_safe_token(device);
15221531   w->track_reg = data;
15231532
15241533   if (VERBOSE)
r3867r3868
15281537
15291538
15301539/* write the FDC sector register */
1531WRITE8_HANDLER ( wd17xx_sector_w )
1540WRITE8_DEVICE_HANDLER ( wd17xx_sector_w )
15321541{
1533   wd17xx_info *w = &wd;
1542   wd17xx_t *w = get_safe_token(device);
15341543   w->sector = data;
15351544   if (VERBOSE)
15361545      logerror("wd17xx_sector_w $%02X\n", data);
r3867r3868
15391548
15401549
15411550/* write the FDC data register */
1542WRITE8_HANDLER ( wd17xx_data_w )
1551WRITE8_DEVICE_HANDLER ( wd17xx_data_w )
15431552{
1544   wd17xx_info *w = &wd;
1553   wd17xx_t *w = get_safe_token(device);
15451554
15461555   if (w->data_count > 0)
15471556   {
15481557      /* clear data request */
1549      wd17xx_clear_data_request(space->machine);
1558      wd17xx_clear_data_request(device);
15501559
15511560      /* put byte into buffer */
15521561      if (VERBOSE_DATA)
r3867r3868
15571566      if (--w->data_count < 1)
15581567      {
15591568         if (w->command == FDC_WRITE_TRK)
1560            write_track(w);
1569            write_track(device);
15611570         else
1562            wd17xx_write_sector(w);
1571            wd17xx_write_sector(device);
15631572
15641573         w->data_offset = 0;
15651574
1566         wd17xx_complete_command(w, DELAY_DATADONE);
1575         wd17xx_complete_command(device, DELAY_DATADONE);
15671576      }
15681577      else
15691578      {
15701579         /* yes... setup a timed data request */
1571         wd17xx_timed_data_request();
1580         wd17xx_timed_data_request(device);
15721581      }
15731582
15741583   }
r3867r3868
15821591
15831592
15841593
1585 READ8_HANDLER( wd17xx_r )
1594 READ8_DEVICE_HANDLER( wd17xx_r )
15861595{
15871596   UINT8 result = 0;
15881597
15891598   switch(offset % 4) {
15901599   case 0:
1591      result = wd17xx_status_r(space, 0);
1600      result = wd17xx_status_r(device, 0);
15921601      break;
15931602   case 1:
1594      result = wd17xx_track_r(space, 0);
1603      result = wd17xx_track_r(device, 0);
15951604      break;
15961605   case 2:
1597      result = wd17xx_sector_r(space, 0);
1606      result = wd17xx_sector_r(device, 0);
15981607      break;
15991608   case 3:
1600      result = wd17xx_data_r(space, 0);
1609      result = wd17xx_data_r(device, 0);
16011610      break;
16021611   }
16031612   return result;
r3867r3868
16051614
16061615
16071616
1608WRITE8_HANDLER( wd17xx_w )
1617WRITE8_DEVICE_HANDLER( wd17xx_w )
16091618{
16101619   switch(offset % 4) {
16111620   case 0:
1612      wd17xx_command_w(space, 0, data);
1621      wd17xx_command_w(device, 0, data);
16131622      break;
16141623   case 1:
1615      wd17xx_track_w(space, 0, data);
1624      wd17xx_track_w(device, 0, data);
16161625      break;
16171626   case 2:
1618      wd17xx_sector_w(space, 0, data);
1627      wd17xx_sector_w(device, 0, data);
16191628      break;
16201629   case 3:
1621      wd17xx_data_w(space, 0, data);
1630      wd17xx_data_w(device, 0, data);
16221631      break;
16231632   }
16241633}
16251634
1635const wd17xx_interface default_wd17xx_interface = { NULL, NULL };
1636
1637/* device interface */
1638static device_start_err common_start(const device_config *device, wd17xx_type_t device_type)
1639{
1640   wd17xx_t *w = get_safe_token(device);
1641
1642   assert(device != NULL);
1643   assert(device->tag != NULL);
1644   assert(strlen(device->tag) < 20);
1645   assert(device->static_config != NULL);
1646
1647   w->intf = device->static_config;
1648   
1649   w->status = STA_1_TRACK0;
1650   w->type = device_type;
1651   w->density = DEN_MFM_LO;
1652   w->busy_timer = timer_alloc(device->machine, wd17xx_busy_callback, (void*)device);
1653   w->timer = timer_alloc(device->machine, wd17xx_misc_timer_callback, (void*)device);
1654   w->timer_rs = timer_alloc(device->machine, wd17xx_read_sector_callback, (void*)device);
1655   w->timer_ws = timer_alloc(device->machine, wd17xx_write_sector_callback, (void*)device);
1656   w->pause_time = 40;
1657     
1658   return DEVICE_START_OK;
1659
1660}
1661
1662static DEVICE_RESET( wd17xx )
1663{
1664   wd17xx_t *w = get_safe_token(device);
1665   int i;
1666   
1667   for (i = 0; i < device_count(device->machine, IO_FLOPPY); i++)
1668   {
1669      const device_config *img = image_from_devtype_and_index(IO_FLOPPY, i);
1670      floppy_drive_set_controller(img,device);
1671      floppy_drive_set_index_pulse_callback(img, wd17xx_index_pulse_callback);
1672      floppy_drive_set_rpm( img, 300.);
1673   }
1674
1675   w->current_drive = 0;
1676   w->hd = 0;
1677
1678   wd17xx_restore(device);
1679}
1680
1681void wd17xx_reset(const device_config *device)
1682{
1683   device_reset_wd17xx(device);
1684}
1685
1686static DEVICE_START( wd1770 )
1687{
1688   return common_start(device, WD_TYPE_1770);
1689}
1690static DEVICE_START( wd1772 )
1691{
1692   return common_start(device, WD_TYPE_1772);
1693}
1694static DEVICE_START( wd1773 )
1695{
1696   return common_start(device, WD_TYPE_1773);
1697}
1698static DEVICE_START( wd179x )
1699{
1700   return common_start(device, WD_TYPE_179X);
1701}
1702static DEVICE_START( wd1793 )
1703{
1704   return common_start(device, WD_TYPE_1793);
1705}
1706static DEVICE_START( wd2793 )
1707{
1708   return common_start(device, WD_TYPE_2793);
1709}
1710static DEVICE_START( wd177x )
1711{
1712   return common_start(device, WD_TYPE_177X);
1713}
1714static DEVICE_START( mb8877 )
1715{
1716   return common_start(device, WD_TYPE_MB8877);
1717}
1718
1719static DEVICE_SET_INFO( wd17xx )
1720{
1721   switch (state)
1722   {
1723      /* no parameters to set */
1724   }
1725}
1726
1727DEVICE_GET_INFO( wd1770 )
1728{
1729   switch (state)
1730   {
1731      /* --- the following bits of info are returned as 64-bit signed integers --- */
1732      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(wd17xx_t);               break;
1733      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
1734      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
1735
1736      /* --- the following bits of info are returned as pointers to data or functions --- */
1737      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(wd17xx); break;
1738      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(wd1770);      break;
1739      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
1740      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(wd17xx);      break;
1741
1742      /* --- the following bits of info are returned as NULL-terminated strings --- */
1743      case DEVINFO_STR_NAME:                     info->s = "WD1770";                  break;
1744      case DEVINFO_STR_FAMILY:                  info->s = "WD17xx";                  break;
1745      case DEVINFO_STR_VERSION:                  info->s = "1.0";                     break;
1746      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                     break;
1747      case DEVINFO_STR_CREDITS:                  info->s = "Copyright MESS Team";         break;
1748   }
1749}
1750
1751
1752DEVICE_GET_INFO( wd1772 )
1753{
1754   switch (state)
1755   {
1756      /* --- the following bits of info are returned as NULL-terminated strings --- */
1757      case DEVINFO_STR_NAME:                     info->s = "WD1772";            break;
1758
1759      /* --- the following bits of info are returned as pointers to data or functions --- */
1760      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(wd1772);   break;
1761
1762      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
1763   }
1764}
1765DEVICE_GET_INFO( wd1773 )
1766{
1767   switch (state)
1768   {
1769      /* --- the following bits of info are returned as NULL-terminated strings --- */
1770      case DEVINFO_STR_NAME:                     info->s = "WD1773";            break;
1771
1772      /* --- the following bits of info are returned as pointers to data or functions --- */
1773      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(wd1773);   break;
1774
1775      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
1776   }
1777}
1778DEVICE_GET_INFO( wd179x )
1779{
1780   switch (state)
1781   {
1782      /* --- the following bits of info are returned as NULL-terminated strings --- */
1783      case DEVINFO_STR_NAME:                     info->s = "WD179x";            break;
1784
1785      /* --- the following bits of info are returned as pointers to data or functions --- */
1786      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(wd179x);   break;
1787
1788      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
1789   }
1790}
1791DEVICE_GET_INFO( wd1793 )
1792{
1793   switch (state)
1794   {
1795      /* --- the following bits of info are returned as NULL-terminated strings --- */
1796      case DEVINFO_STR_NAME:                     info->s = "WD1793";            break;
1797
1798      /* --- the following bits of info are returned as pointers to data or functions --- */
1799      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(wd1793);   break;
1800
1801      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
1802   }
1803}
1804DEVICE_GET_INFO( wd2793 )
1805{
1806   switch (state)
1807   {
1808      /* --- the following bits of info are returned as NULL-terminated strings --- */
1809      case DEVINFO_STR_NAME:                     info->s = "WD2793";            break;
1810
1811      /* --- the following bits of info are returned as pointers to data or functions --- */
1812      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(wd2793);   break;
1813
1814      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
1815   }
1816}
1817DEVICE_GET_INFO( wd177x )
1818{
1819   switch (state)
1820   {
1821      /* --- the following bits of info are returned as NULL-terminated strings --- */
1822      case DEVINFO_STR_NAME:                     info->s = "WD177x";            break;
1823
1824      /* --- the following bits of info are returned as pointers to data or functions --- */
1825      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(wd177x);   break;
1826
1827      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
1828   }
1829}
1830DEVICE_GET_INFO( mb8877 )
1831{
1832   switch (state)
1833   {
1834      /* --- the following bits of info are returned as NULL-terminated strings --- */
1835      case DEVINFO_STR_NAME:                     info->s = "MB8877";            break;
1836
1837      /* --- the following bits of info are returned as pointers to data or functions --- */
1838      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(mb8877);   break;
1839
1840      default:                               DEVICE_GET_INFO_CALL(wd1770);            break;
1841   }
1842}
1843
src/mess/machine/wd17xx.h
r3867r3868
1212
1313#include "devices/flopdrv.h"
1414
15/***************************************************************************
16    MACROS
17***************************************************************************/
1518
19#define WD1770      DEVICE_GET_INFO_NAME(wd1770)
20#define WD1772      DEVICE_GET_INFO_NAME(wd1772)
21#define WD1773      DEVICE_GET_INFO_NAME(wd1773)
22#define WD179X      DEVICE_GET_INFO_NAME(wd179x)
23#define WD1793      DEVICE_GET_INFO_NAME(wd1793)
24#define WD2793      DEVICE_GET_INFO_NAME(wd2793)
25#define WD177X      DEVICE_GET_INFO_NAME(wd177x)
26#define MB8877      DEVICE_GET_INFO_NAME(mb8877)
1627
1728/***************************************************************************
18
19   Constants and enumerations
20
29    TYPE DEFINITIONS
2130***************************************************************************/
2231
2332typedef enum
r3867r3868
2837   WD17XX_DRQ_SET
2938} wd17xx_state_t;
3039
31/* enumeration to specify the type of FDC; there are subtle differences */
32typedef enum
33{
34   WD_TYPE_1770,
35   WD_TYPE_1772,
36   WD_TYPE_1773,
37   WD_TYPE_179X,
38   WD_TYPE_1793,
39   WD_TYPE_2793,
4040
41   /* duplicate constants */
42   WD_TYPE_177X = WD_TYPE_1770,
43   WD_TYPE_MB8877 = WD_TYPE_179X
44} wd17xx_type_t;
41typedef void (*wd17xx_callback_func)(const device_config *device, wd17xx_state_t state, void *param);
42#define WD17XX_CALLBACK(name)   void name(const device_config *device, wd17xx_state_t state, void *param )
4543
44typedef void* (*wd17xx_param_callback_func)(const device_config *device);
45#define WD17XX_PARAM_CALLBACK(name)   void* name(const device_config *device)
4646
4747
48/* Interface */
49typedef struct _wd17xx_interface wd17xx_interface;
50struct _wd17xx_interface
51{
52   wd17xx_callback_func callback;
53   wd17xx_param_callback_func callback_param;
54};
55
4856/***************************************************************************
57    FUNCTION PROTOTYPES
58***************************************************************************/
4959
50   Prototypes
60/* device interface */
61extern DEVICE_GET_INFO(wd1770);
62extern DEVICE_GET_INFO(wd1772);
63extern DEVICE_GET_INFO(wd1773);
64extern DEVICE_GET_INFO(wd179x);
65extern DEVICE_GET_INFO(wd1793);
66extern DEVICE_GET_INFO(wd2793);
67extern DEVICE_GET_INFO(wd177x);
68extern DEVICE_GET_INFO(mb8877);
5169
52***************************************************************************/
70void wd17xx_reset(const device_config *device);
5371
54void wd17xx_init(running_machine *machine, wd17xx_type_t type, void (*callback)(running_machine *, wd17xx_state_t, void *), void *param);
55void wd17xx_reset(running_machine *machine);
56
5772/* the following are not strictly part of the wd179x hardware/emulation
5873but will be put here for now until the flopdrv code has been finalised more */
59void wd17xx_set_drive(UINT8);      /* set drive wd179x is accessing */
60void wd17xx_set_side(UINT8);      /* set side wd179x is accessing */
61void wd17xx_set_density(DENSITY);   /* set density */
74void wd17xx_set_drive(const device_config *device, UINT8);      /* set drive wd179x is accessing */
75void wd17xx_set_side(const device_config *device, UINT8);      /* set side wd179x is accessing */
76void wd17xx_set_density(const device_config *device, DENSITY);   /* set density */
6277
63READ8_HANDLER( wd17xx_status_r );
64READ8_HANDLER( wd17xx_track_r );
65READ8_HANDLER( wd17xx_sector_r );
66READ8_HANDLER( wd17xx_data_r );
78READ8_DEVICE_HANDLER( wd17xx_status_r );
79READ8_DEVICE_HANDLER( wd17xx_track_r );
80READ8_DEVICE_HANDLER( wd17xx_sector_r );
81READ8_DEVICE_HANDLER( wd17xx_data_r );
6782
68WRITE8_HANDLER( wd17xx_command_w );
69WRITE8_HANDLER( wd17xx_track_w );
70WRITE8_HANDLER( wd17xx_sector_w );
71WRITE8_HANDLER( wd17xx_data_w );
83WRITE8_DEVICE_HANDLER( wd17xx_command_w );
84WRITE8_DEVICE_HANDLER( wd17xx_track_w );
85WRITE8_DEVICE_HANDLER( wd17xx_sector_w );
86WRITE8_DEVICE_HANDLER( wd17xx_data_w );
7287
73READ8_HANDLER( wd17xx_r );
74WRITE8_HANDLER( wd17xx_w );
88READ8_DEVICE_HANDLER( wd17xx_r );
89WRITE8_DEVICE_HANDLER( wd17xx_w );
7590
76void wd17xx_set_pause_time(int usec); /* default is 40 usec if not set */
91void wd17xx_set_pause_time(const device_config *device, int usec); /* default is 40 usec if not set */
92
93extern const wd17xx_interface default_wd17xx_interface;
94/***************************************************************************
95    DEVICE CONFIGURATION MACROS
96***************************************************************************/
97
98#define MDRV_WD1770_ADD(_tag, _intrf) \
99   MDRV_DEVICE_ADD(_tag, WD1770) \
100   MDRV_DEVICE_CONFIG(_intrf)
101
102#define MDRV_WD1772_ADD(_tag, _intrf) \
103   MDRV_DEVICE_ADD(_tag, WD1772) \
104   MDRV_DEVICE_CONFIG(_intrf)
105
106#define MDRV_WD1773_ADD(_tag, _intrf) \
107   MDRV_DEVICE_ADD(_tag, WD1773) \
108   MDRV_DEVICE_CONFIG(_intrf)
109
110#define MDRV_WD179X_ADD(_tag, _intrf) \
111   MDRV_DEVICE_ADD(_tag, WD179X) \
112   MDRV_DEVICE_CONFIG(_intrf)
113
114#define MDRV_WD1793_ADD(_tag, _intrf) \
115   MDRV_DEVICE_ADD(_tag, WD1793) \
116   MDRV_DEVICE_CONFIG(_intrf)
117
118#define MDRV_WD2793_ADD(_tag, _intrf) \
119   MDRV_DEVICE_ADD(_tag, WD2793) \
120   MDRV_DEVICE_CONFIG(_intrf)
121
122#define MDRV_WD177X_ADD(_tag, _intrf) \
123   MDRV_DEVICE_ADD(_tag, WD177X) \
124   MDRV_DEVICE_CONFIG(_intrf)
125
126#define MDRV_MB8877_ADD(_tag, _intrf) \
127   MDRV_DEVICE_ADD(_tag, MB8877) \
128   MDRV_DEVICE_CONFIG(_intrf)
129
130   
77131#endif /* WD179X_H */
78132
79133
134
src/mess/machine/samcoupe.c
r3867r3868
1010#include "driver.h"
1111#include "includes/samcoupe.h"
1212#include "devices/basicdsk.h"
13#include "machine/wd17xx.h"
1413#include "machine/msm6242.h"
1514
1615
r3867r3868
189188   samcoupe_update_memory(space);
190189}
191190
192
193MACHINE_START( samcoupe )
194{
195    wd17xx_init(machine, WD_TYPE_1772, NULL, NULL);
196}
src/mess/machine/comx35.c
r3867r3868
143143   return INIT_FAIL;
144144}
145145
146static void comx35_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param)
146static WD17XX_CALLBACK( comx35_fdc_callback )
147147{
148   comx35_state *state = machine->driver_data;
148   comx35_state *driver_state = device->machine->driver_data;
149149
150   switch (event)
150   switch (state)
151151   {
152152   case WD17XX_IRQ_SET:
153      state->fdc_irq = 1;
153      driver_state->fdc_irq = 1;
154154      break;
155155
156156   case WD17XX_IRQ_CLR:
157      state->fdc_irq = 0;
157      driver_state->fdc_irq = 0;
158158      break;
159159
160160   case WD17XX_DRQ_SET:
161      if (state->fdc_drq_enable)
161      if (driver_state->fdc_drq_enable)
162162      {
163         state->cdp1802_ef4 = 1;
163         driver_state->cdp1802_ef4 = 1;
164164      }
165165      break;
166166
167167   case WD17XX_DRQ_CLR:
168      if (state->fdc_drq_enable)
168      if (driver_state->fdc_drq_enable)
169169      {
170         state->cdp1802_ef4 = 0;
170         driver_state->cdp1802_ef4 = 0;
171171      }
172172      break;
173173   }
174174}
175175
176const wd17xx_interface comx35_wd17xx_interface = { comx35_fdc_callback, NULL };
177
176178static UINT8 fdc_r(const address_space *space)
177179{
178180   comx35_state *state = space->machine->driver_data;
181   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1770, "wd1770");
179182
180183   UINT8 data;
181184
r3867r3868
185188   }
186189   else
187190   {
188      data = wd17xx_r(space, state->fdc_addr);
191      data = wd17xx_r(fdc, state->fdc_addr);
189192   }
190193
191194   return data;
r3867r3868
193196
194197static void fdc_w(const address_space *space, UINT8 data)
195198{
199   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1770, "wd1770");
196200   /*
197201
198202      bit      description
r3867r3868
216220
217221      if (BIT(data, 2))
218222      {
219         wd17xx_set_drive(0);
223         wd17xx_set_drive(fdc,0);
220224      }     
221225      else if (BIT(data, 3))
222226      {
223         wd17xx_set_drive(1);
227         wd17xx_set_drive(fdc,1);
224228      }
225229
226230      state->fdc_drq_enable = BIT(data, 4);
r3867r3868
230234         state->cdp1802_ef4 = 1;
231235      }
232236
233      wd17xx_set_side(BIT(data, 5));
237      wd17xx_set_side(fdc,BIT(data, 5));
234238   }
235239   else
236240   {
237241      // write data to WD1770
238242
239      wd17xx_w(space, state->fdc_addr, data);
243      wd17xx_w(fdc, state->fdc_addr, data);
240244   }
241245}
242246
r3867r3868
610614
611615   state->pal_ntsc = CDP1869_PAL;
612616
613   /* initialize floppy disc controller */
614
615   wd17xx_init(machine, WD_TYPE_1770, comx35_fdc_callback, NULL);
616
617617   /* register for state saving */
618618
619619   state_save_register_postload(machine, comx35_state_save_postload, NULL);
src/mess/machine/trs80.c
r3867r3868
203203    return INIT_PASS;
204204}
205205
206static void trs80_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param);
207
208
209206MACHINE_RESET( trs80 )
210207{
211208   cassette_data = 0x00;
r3867r3868
287284   }
288285}
289286
290
291MACHINE_START( trs80 )
292{
293   wd17xx_init(machine, WD_TYPE_179X,trs80_fdc_callback, NULL);
294}
295
296
297287/*************************************
298288 *
299289 *            Port handlers.
r3867r3868
355345   trs80_fdc_interrupt_internal(device->machine);
356346}
357347
358void trs80_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param)
348static WD17XX_CALLBACK( trs80_fdc_callback )
359349{
360   switch (event)
350   switch (state)
361351   {
362352      case WD17XX_IRQ_CLR:
363353         irq_status &= ~IRQ_FDC;
364354         break;
365355      case WD17XX_IRQ_SET:
366         trs80_fdc_interrupt_internal(machine);
356         trs80_fdc_interrupt_internal(device->machine);
367357         break;
368358      case WD17XX_DRQ_CLR:
369359      case WD17XX_DRQ_SET:
r3867r3868
372362   }
373363}
374364
365const wd17xx_interface trs80_wd17xx_interface = { trs80_fdc_callback, NULL };
366
367
375368INTERRUPT_GEN( trs80_frame_interrupt )
376369{
377370}
r3867r3868
408401WRITE8_HANDLER( trs80_motor_w )
409402{
410403   UINT8 drive = 255;
404   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
411405
412406   LOG(("trs80 motor_w $%02X\n", data));
413407
r3867r3868
446440   if (drive > 3)
447441      return;
448442
449    wd17xx_set_drive(drive);
450   wd17xx_set_side(head);
443    wd17xx_set_drive(fdc,drive);
444   wd17xx_set_side(fdc,head);
451445
452446}
453447
src/mess/machine/svi318.c
r3867r3868
338338
339339static SVI318_FDC_STRUCT svi318_fdc;
340340
341static void svi_fdc_callback(running_machine *machine, wd17xx_state_t state, void *param)
341static WD17XX_CALLBACK( svi_fdc_callback )
342342{
343343   switch( state )
344344   {
r3867r3868
357357   }
358358}
359359
360const wd17xx_interface svi_wd17xx_interface = { svi_fdc_callback, NULL };
361
360362static WRITE8_HANDLER( svi318_fdc_drive_motor_w )
361363{
364   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
362365   switch (data & 3)
363366   {
364367   case 1:
365      wd17xx_set_drive(0);
368      wd17xx_set_drive(fdc,0);
366369      svi318_fdc.driveselect = 0;
367370      break;
368371   case 2:
369      wd17xx_set_drive(1);
372      wd17xx_set_drive(fdc,1);
370373      svi318_fdc.driveselect = 1;
371374      break;
372375   }
r3867r3868
375378static WRITE8_HANDLER( svi318_fdc_density_side_w )
376379{
377380   const device_config *image;
381   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
378382
379   wd17xx_set_density(data & 0x01 ? DEN_FM_LO:DEN_MFM_LO);
383   wd17xx_set_density(fdc, data & 0x01 ? DEN_FM_LO:DEN_MFM_LO);
380384
381   wd17xx_set_side(data & 0x02 ? 1:0);
385   wd17xx_set_side(fdc, data & 0x02 ? 1:0);
382386
383387   image = image_from_devtype_and_index(IO_FLOPPY, svi318_fdc.driveselect);
384388   if (image_exists(image))
r3867r3868
608612MACHINE_START( svi318_ntsc )
609613{
610614   TMS9928A_configure(&svi318_tms9928a_interface);
611   wd17xx_init(machine, WD_TYPE_179X, svi_fdc_callback, NULL);
612615}
613616
614617MACHINE_START( svi318_pal )
615618{
616619   TMS9928A_configure(&svi318_tms9929a_interface);
617   wd17xx_init(machine, WD_TYPE_179X, svi_fdc_callback, NULL);
618620}
619621
620622MACHINE_RESET( svi318 )
r3867r3868
624626
625627   svi.bank_switch = 0xff;
626628   svi318_set_banks(machine);
627
628   wd17xx_reset(machine);
629629}
630630
631631INTERRUPT_GEN( svi318_interrupt )
r3867r3868
787787READ8_HANDLER( svi318_io_ext_r )
788788{
789789   UINT8 data = 0xff;
790   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
790791
791792   if (svi.bankLow == SVI_CART) {
792793      return 0xff;
r3867r3868
820821      break;
821822
822823   case 0x30:
823      data = wd17xx_status_r(space, 0);
824      data = wd17xx_status_r(fdc, 0);
824825      break;
825826   case 0x31:
826      data = wd17xx_track_r(space, 0);
827      data = wd17xx_track_r(fdc, 0);
827828      break;
828829   case 0x32:
829      data = wd17xx_sector_r(space, 0);
830      data = wd17xx_sector_r(fdc, 0);
830831      break;
831832   case 0x33:
832      data = wd17xx_data_r(space, 0);
833      data = wd17xx_data_r(fdc, 0);
833834      break;
834835   case 0x34:
835836      data = svi318_fdc_irqdrq_r(space, 0);
r3867r3868
846847
847848WRITE8_HANDLER( svi318_io_ext_w )
848849{
850   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
851   
849852   if (svi.bankLow == SVI_CART) {
850853      return;
851854   }
r3867r3868
879882      break;
880883
881884   case 0x30:
882      wd17xx_command_w(space, 0, data);
885      wd17xx_command_w(fdc, 0, data);
883886      break;
884887   case 0x31:
885      wd17xx_track_w(space, 0, data);
888      wd17xx_track_w(fdc, 0, data);
886889      break;
887890   case 0x32:
888      wd17xx_sector_w(space, 0, data);
891      wd17xx_sector_w(fdc, 0, data);
889892      break;
890893   case 0x33:
891      wd17xx_data_w(space, 0, data);
894      wd17xx_data_w(fdc, 0, data);
892895      break;
893896   case 0x34:
894897      svi318_fdc_drive_motor_w(space, 0, data);
src/mess/machine/compis.c
r3867r3868
289289/*-------------------------------------------------------------------------*/
290290static void compis_fdc_reset(running_machine *machine)
291291{
292   nec765_reset(machine, 0);
292   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, NEC765A, "nec765");     
293   
294   nec765_reset(fdc, 0);
293295
294296   /* set FDC at reset */
295   nec765_set_reset_state(machine, 1);
297   nec765_set_reset_state(fdc, 1);
296298}
297299
298300static void compis_fdc_tc(running_machine *machine, int state)
299301{
302   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, NEC765A, "nec765");
300303   /* Terminal count if iSBX-218A has DMA enabled */
301304     if (input_port_read(machine, "DSW1"))
302305   {
303      nec765_set_tc_state(machine, state);
306      nec765_set_tc_state(fdc, state);
304307   }
305308}
306309
307static void compis_fdc_int(running_machine *machine,int state)
310static NEC765_INTERRUPT( compis_fdc_int )
308311{
309312   /* No interrupt requests if iSBX-218A has DMA enabled */
310     if (!input_port_read(machine, "DSW1") && state)
313     if (!input_port_read(device->machine, "DSW1") && state)
311314   {
312315      compis_osp_pic_irq(COMPIS_IRQ_SBX0_INT1);
313316   }
314317}
315318
316static void compis_fdc_dma_drq(running_machine *machine,int state, int read)
319static NEC765_DMA_REQUEST( compis_fdc_dma_drq )
317320{
318321   /* DMA requst if iSBX-218A has DMA enabled */
319     if (input_port_read(machine, "DSW1") && state)
322     if (input_port_read(device->machine, "DSW1") && state)
320323   {
321324      //compis_dma_drq(state, read);
322325   }
323326}
324327
325static const nec765_interface compis_fdc_interface =
328const nec765_interface compis_fdc_interface =
326329{
327330   compis_fdc_int,
328   compis_fdc_dma_drq
331   compis_fdc_dma_drq,
332   NULL,
333   NEC765_RDY_PIN_CONNECTED
329334};
330335
331336READ16_HANDLER (compis_fdc_dack_r)
332337{
338   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
333339   UINT16 data;
334   data = 0xffff;
340   data = 0xffff;   
335341   /* DMA acknowledge if iSBX-218A has DMA enabled */
336342     if (input_port_read(space->machine, "DSW1"))
337343     {
338      data = nec765_dack_r(space, 0);
344      data = nec765_dack_r(fdc, 0);
339345   }
340346
341347   return data;
r3867r3868
343349
344350WRITE16_HANDLER (compis_fdc_w)
345351{
352   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
346353   switch(offset)
347354   {
348355      case 2:
349         nec765_data_w(space, 0, data);
356         nec765_data_w(fdc, 0, data);
350357         break;
351358      default:
352359         logerror("FDC Unknown Port Write %04X = %04X\n", offset, data);
r3867r3868
356363
357364READ16_HANDLER (compis_fdc_r)
358365{
366   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
359367   UINT16 data;
360368   data = 0xffff;
361369   switch(offset)
362370   {
363371      case 0:
364         data = nec765_status_r(space, 0);
372         data = nec765_status_r(fdc, 0);
365373         break;
366374      case 1:
367         data = nec765_data_r(space, 0);
375         data = nec765_data_r(fdc, 0);
368376         break;
369377      default:
370378         logerror("FDC Unknown Port Read %04X\n", offset);
r3867r3868
15451553   compis_cpu_init(machine);
15461554
15471555   /* FDC */
1548   nec765_init(machine, &compis_fdc_interface, NEC765A, NEC765_RDY_PIN_CONNECTED);
15491556   compis_fdc_reset(machine);
15501557
15511558   /* Keyboard */
src/mess/machine/nec765.c
r3867r3868
3333   NEC765_EXECUTION_PHASE_WRITE
3434} NEC765_PHASE;
3535
36/* supported versions */
37typedef enum
38{
39   TYPE_NEC765A = 0,
40   TYPE_NEC765B = 1,
41   TYPE_SMC37C78 = 2,
42   TYPE_NEC72065 = 3
43} NEC765_VERSION;
44
45
3646/* uncomment the following line for verbose information */
3747#define LOG_VERBOSE      1
38#define LOG_COMMAND      0
39#define LOG_EXTRA      0
40#define LOG_INTERRUPT   0
48#define LOG_COMMAND      1
49#define LOG_EXTRA      1
50#define LOG_INTERRUPT   1
4151
4252/* uncomment this to not allow end of cylinder "error" */
4353#define NO_END_OF_CYLINDER
r3867r3868
6373
6474#define NEC765_RESET 0x080
6575
66typedef struct nec765
76typedef struct _nec765_t nec765_t;
77struct _nec765_t
6778{
6879   unsigned long   sector_counter;
6980   /* version of fdc to emulate */
r3867r3868
117128   int timer_type;
118129
119130   emu_timer *command_timer;
120} NEC765;
131   
132   char *data_buffer;
133   const nec765_interface *intf;
134};
121135
122136//static void nec765_setup_data_request(unsigned char Data);
123static void nec765_setup_command(running_machine *machine);
137static void nec765_setup_command(const device_config *device);
124138static TIMER_CALLBACK(nec765_continue_command);
125static int nec765_sector_count_complete(running_machine *machine);
126static void nec765_increment_sector(running_machine *machine);
127static void nec765_update_state(running_machine *machine);
128static void nec765_set_dma_drq(running_machine *machine,int state);
129static void nec765_set_int(running_machine *machine,int state);
139static int nec765_sector_count_complete(const device_config *device);
140static void nec765_increment_sector(const device_config *device);
141static void nec765_update_state(const device_config *device);
142static void nec765_set_dma_drq(const device_config *device,int state);
143static void nec765_set_int(const device_config *device,int state);
130144
131static NEC765 fdc;
132static char nec765_data_buffer[32*1024];
133
134
135static nec765_interface nec765_iface;
136
137
138145static const INT8 nec765_cmd_size[32] =
139146{
140147   1,1,9,3,2,9,9,2,1,9,2,1,9,6,1,3,
141148   1,9,1,1,1,1,9,1,1,9,1,1,1,9,1,1
142149};
143150
151INLINE nec765_t *get_safe_token(const device_config *device)
152{
153   assert(device != NULL);
154   assert(device->token != NULL);
144155
156   return (nec765_t *)device->token;
157}
145158
146static const device_config *current_image(running_machine *machine)
159static const device_config *current_image(const device_config *device)
147160{
148161   const device_config *image = NULL;
162   nec765_t *fdc = get_safe_token(device);
149163
150   if (!nec765_iface.get_image)
164   if (!fdc->intf->get_image)
151165   {
152      if (fdc.drive < device_count(machine, IO_FLOPPY))
153         image = image_from_devtype_and_index(IO_FLOPPY, fdc.drive);
166      if (fdc->drive < device_count(device->machine, IO_FLOPPY))
167         image = image_from_devtype_and_index(IO_FLOPPY, fdc->drive);
154168   }
155169   else
156170   {
157      image = nec765_iface.get_image(machine, fdc.drive);
171      image = fdc->intf->get_image(device, fdc->drive);
158172   }
159173   return image;
160174}
161175
162static void nec765_setup_drive_and_side(void)
176static void nec765_setup_drive_and_side(const device_config *device)
163177{
178   nec765_t *fdc = get_safe_token(device);
164179   /* drive index nec765 sees */
165   fdc.drive = fdc.nec765_command_bytes[1] & 0x03;
180   fdc->drive = fdc->nec765_command_bytes[1] & 0x03;
166181   /* side index nec765 sees */
167   fdc.side = (fdc.nec765_command_bytes[1]>>2) & 0x01;
182   fdc->side = (fdc->nec765_command_bytes[1]>>2) & 0x01;
168183}
169184
170185
171186/* setup status register 0 based on data in status register 1 and 2 */
172static void nec765_setup_st0(void)
187static void nec765_setup_st0(const device_config *device)
173188{
189   nec765_t *fdc = get_safe_token(device);
174190   /* clear completition status bits, drive bits and side bits */
175   fdc.nec765_status[0] &= ~((1<<7) | (1<<6) | (1<<2) | (1<<1) | (1<<0));
191   fdc->nec765_status[0] &= ~((1<<7) | (1<<6) | (1<<2) | (1<<1) | (1<<0));
176192   /* fill in drive */
177   fdc.nec765_status[0] |= fdc.drive | (fdc.side<<2);
193   fdc->nec765_status[0] |= fdc->drive | (fdc->side<<2);
178194
179195   /* fill in completion status bits based on bits in st0, st1, st2 */
180196   /* no error bits set */
181   if ((fdc.nec765_status[1] | fdc.nec765_status[2])==0)
197   if ((fdc->nec765_status[1] | fdc->nec765_status[2])==0)
182198   {
183199      return;
184200   }
185201
186   fdc.nec765_status[0] |= 0x040;
202   fdc->nec765_status[0] |= 0x040;
187203}
188204
189205
r3867r3868
194210   return 1<<(n+7);
195211}
196212
197static void nec765_set_data_request(void)
213static void nec765_set_data_request(const device_config *device)
198214{
199   fdc.FDC_main |= 0x080;
215   nec765_t *fdc = get_safe_token(device);
216   fdc->FDC_main |= 0x080;
200217}
201218
202static void nec765_clear_data_request(void)
219static void nec765_clear_data_request(const device_config *device)
203220{
204   fdc.FDC_main &= ~0x080;
221   nec765_t *fdc = get_safe_token(device);
222   fdc->FDC_main &= ~0x080;
205223}
206224
207static void nec765_seek_complete(running_machine *machine)
208{
225static void nec765_seek_complete(const device_config *device)
226{   
209227   /* tested on Amstrad CPC */
210228
211229   /* if a seek is done without drive connected: */
r3867r3868
259277      This indicates it is always ready!!!!!
260278   */
261279
262   const device_config *img = current_image(machine);
263
280   const device_config *img = current_image(device);
281   nec765_t *fdc = get_safe_token(device);
282   
264283   if (!img)
265284      return;
266285
267   fdc.pcn[fdc.drive] = fdc.ncn;
286   fdc->pcn[fdc->drive] = fdc->ncn;
268287
269288   /* drive ready? */
270289   if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
r3867r3868
272291      /* yes */
273292
274293      /* recalibrate? */
275      if (fdc.nec765_flags & NEC765_SEEK_OPERATION_IS_RECALIBRATE)
294      if (fdc->nec765_flags & NEC765_SEEK_OPERATION_IS_RECALIBRATE)
276295      {
277296         /* yes */
278297
r3867r3868
280299         if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_HEAD_AT_TRACK_0))
281300         {
282301            /* yes. Seek complete */
283            fdc.nec765_status[0] = 0x020;
302            fdc->nec765_status[0] = 0x020;
284303         }
285304         else
286305         {
287306            /* no, track 0 failed after 77 steps */
288            fdc.nec765_status[0] = 0x040 | 0x020 | 0x010;
307            fdc->nec765_status[0] = 0x040 | 0x020 | 0x010;
289308         }
290309      }
291310      else
r3867r3868
293312         /* no, seek */
294313
295314         /* seek complete */
296         fdc.nec765_status[0] = 0x020;
315         fdc->nec765_status[0] = 0x020;
297316      }
298317   }
299318   else
300319   {
301320      /* abnormal termination, not ready */
302      fdc.nec765_status[0] = 0x040 | 0x020 | 0x08;
321      fdc->nec765_status[0] = 0x040 | 0x020 | 0x08;
303322   }
304323
305324   /* set drive and side */
306   fdc.nec765_status[0] |= fdc.drive | (fdc.side<<2);
325   fdc->nec765_status[0] |= fdc->drive | (fdc->side<<2);
307326
308   nec765_set_int(machine,0);
309   nec765_set_int(machine,1);
327   nec765_set_int(device,0);
328   nec765_set_int(device,1);
310329
311   fdc.nec765_flags &= ~NEC765_SEEK_ACTIVE;
330   fdc->nec765_flags &= ~NEC765_SEEK_ACTIVE;
312331}
313332
314333static TIMER_CALLBACK(nec765_seek_timer_callback)
315334{
335   const device_config *device = ptr;
336   nec765_t *fdc = get_safe_token(device);
316337   /* seek complete */
317   nec765_seek_complete(machine);
338   nec765_seek_complete(device);
318339
319   timer_reset(fdc.seek_timer, attotime_never);
340   timer_reset(fdc->seek_timer, attotime_never);
320341}
321342
322static void nec765_timer_func(running_machine *machine, int timer_type)
343static void nec765_timer_func(const device_config *device, int timer_type)
323344{
345   nec765_t *fdc = get_safe_token(device);
324346   /* type 0 = data transfer mode in execution phase */
325   if (fdc.timer_type == 0)
347   if (fdc->timer_type == 0)
326348   {
327349      /* set data request */
328      nec765_set_data_request();
350      nec765_set_data_request(device);
329351
330      fdc.timer_type = 4;
352      fdc->timer_type = 4;
331353
332      if (!(fdc.nec765_flags & NEC765_DMA_MODE))
354      if (!(fdc->nec765_flags & NEC765_DMA_MODE))
333355      {
334356         /* for pcw */
335         timer_reset(fdc.timer, ATTOTIME_IN_USEC(27));
357         timer_reset(fdc->timer, ATTOTIME_IN_USEC(27));
336358      }
337359      else
338360      {
339         nec765_timer_func(machine, fdc.timer_type);
361         nec765_timer_func(device, fdc->timer_type);
340362      }
341363   }
342   else if (fdc.timer_type==2)
364   else if (fdc->timer_type==2)
343365   {
344366      /* result phase begin */
345367
346368      /* generate a int for specific commands */
347      switch (fdc.command) {
369      switch (fdc->command) {
348370      case 2:      /* read a track */
349371      case 5:      /* write data */
350372      case 6:      /* read data */
r3867r3868
355377      case 17:   /* scan equal */
356378      case 19:   /* scan low or equal */
357379      case 29:   /* scan high or equal */
358         nec765_set_int(machine,1);
380         nec765_set_int(device,1);
359381         break;
360382
361383      default:
362384         break;
363385      }
364386
365      nec765_set_data_request();
387      nec765_set_data_request(device);
366388
367      timer_reset(fdc.timer, attotime_never);
389      timer_reset(fdc->timer, attotime_never);
368390   }
369   else if (fdc.timer_type == 4)
391   else if (fdc->timer_type == 4)
370392   {
371393      /* if in dma mode, a int is not generated per byte. If not in  DMA mode
372394      a int is generated per byte */
373      if (fdc.nec765_flags & NEC765_DMA_MODE)
395      if (fdc->nec765_flags & NEC765_DMA_MODE)
374396      {
375         nec765_set_dma_drq(machine,1);
397         nec765_set_dma_drq(device,1);
376398      }
377399      else
378400      {
379         if (fdc.FDC_main & (1<<7))
401         if (fdc->FDC_main & (1<<7))
380402         {
381403            /* set int to indicate data is ready */
382            nec765_set_int(machine,1);
404            nec765_set_int(device,1);
383405         }
384406      }
385407
386      timer_reset(fdc.timer, attotime_never);
408      timer_reset(fdc->timer, attotime_never);
387409   }
388410}
389411
390412static TIMER_CALLBACK(nec765_timer_callback)
391{
392   nec765_timer_func(machine,param);
413{   
414   const device_config *device = ptr;
415   nec765_timer_func(device,param);
393416}
394417
395418/* after (32-27) the DRQ is set, then 27 us later, the int is set.
r3867r3868
398421effectively disabled by reading the data before the NMI int can be set.
399422*/
400423
401static void nec765_setup_timed_generic(running_machine *machine, int timer_type, attotime duration)
424static void nec765_setup_timed_generic(const device_config *device, int timer_type, attotime duration)
402425{
403   fdc.timer_type = timer_type;
426   nec765_t *fdc = get_safe_token(device);
427   
428   fdc->timer_type = timer_type;
404429
405   if (!(fdc.nec765_flags & NEC765_DMA_MODE))
430   if (!(fdc->nec765_flags & NEC765_DMA_MODE))
406431   {
407      timer_adjust_oneshot(fdc.timer, duration, 0);
432      timer_adjust_oneshot(fdc->timer, duration, 0);
408433   }
409434   else
410435   {
411      nec765_timer_func(machine,fdc.timer_type);
412      timer_reset(fdc.timer, attotime_never);
436      nec765_timer_func(device,fdc->timer_type);
437      timer_reset(fdc->timer, attotime_never);
413438   }
414439}
415440
416441/* setup data request */
417static void nec765_setup_timed_data_request(running_machine *machine, int bytes)
442static void nec765_setup_timed_data_request(const device_config *device, int bytes)
418443{
419444   /* setup timer to trigger in NEC765_DATA_RATE us */
420   nec765_setup_timed_generic(machine, 0, ATTOTIME_IN_USEC(32-27)   /*NEC765_DATA_RATE)*bytes*/);
445   nec765_setup_timed_generic(device, 0, ATTOTIME_IN_USEC(32-27)   /*NEC765_DATA_RATE)*bytes*/);
421446}
422447
423448/* setup result data request */
424static void nec765_setup_timed_result_data_request(running_machine *machine)
449static void nec765_setup_timed_result_data_request(const device_config *device)
425450{
426   nec765_setup_timed_generic(machine, 2, ATTOTIME_IN_USEC(NEC765_DATA_RATE*2));
451   nec765_setup_timed_generic(device, 2, ATTOTIME_IN_USEC(NEC765_DATA_RATE*2));
427452}
428453
429454
430455/* sets up a timer to issue a seek complete in signed_tracks time */
431static void nec765_setup_timed_int(int signed_tracks)
456static void nec765_setup_timed_int(const device_config *device,int signed_tracks)
432457{
458   nec765_t *fdc = get_safe_token(device);
433459   /* setup timer to signal after seek time is complete */
434   timer_adjust_periodic(fdc.seek_timer, attotime_zero, 0, double_to_attotime(fdc.srt_in_ms*abs(signed_tracks)*0.001));
460   timer_adjust_periodic(fdc->seek_timer, attotime_zero, 0, double_to_attotime(fdc->srt_in_ms*abs(signed_tracks)*0.001));
435461}
436462
437static void nec765_seek_setup(running_machine *machine, int is_recalibrate)
463static void nec765_seek_setup(const device_config *device, int is_recalibrate)
438464{
439465   const device_config *img;
440466   int signed_tracks;
467   nec765_t *fdc = get_safe_token(device);
441468
442   fdc.nec765_flags |= NEC765_SEEK_ACTIVE;
469   fdc->nec765_flags |= NEC765_SEEK_ACTIVE;
443470
444471   if (is_recalibrate)
445472   {
446473      /* head cannot be specified with recalibrate */
447      fdc.nec765_command_bytes[1] &=~0x04;
474      fdc->nec765_command_bytes[1] &=~0x04;
448475   }
449476
450   nec765_setup_drive_and_side();
477   nec765_setup_drive_and_side(device);
451478
452   img = current_image(machine);
479   img = current_image(device);
453480
454   fdc.FDC_main |= (1<<fdc.drive);
481   fdc->FDC_main |= (1<<fdc->drive);
455482
456483   /* recalibrate command? */
457484   if (is_recalibrate)
458485   {
459      fdc.nec765_flags |= NEC765_SEEK_OPERATION_IS_RECALIBRATE;
486      fdc->nec765_flags |= NEC765_SEEK_OPERATION_IS_RECALIBRATE;
460487
461      fdc.ncn = 0;
488      fdc->ncn = 0;
462489
463490      /* if drive is already at track 0, or drive is not ready */
464491      if (
r3867r3868
467494         )
468495      {
469496         /* seek completed */
470         nec765_seek_complete(machine);
497         nec765_seek_complete(device);
471498      }
472499      else
473500      {
r3867r3868
496523            /* perform seek - if drive isn't present it will not do anything */
497524            floppy_drive_seek(img, signed_tracks);
498525
499            nec765_setup_timed_int(signed_tracks);
526            nec765_setup_timed_int(device,signed_tracks);
500527         }
501528         else
502529         {
503            nec765_seek_complete(machine);
530            nec765_seek_complete(device);
504531         }
505532      }
506533   }
507534   else
508535   {
509536
510      fdc.nec765_flags &= ~NEC765_SEEK_OPERATION_IS_RECALIBRATE;
537      fdc->nec765_flags &= ~NEC765_SEEK_OPERATION_IS_RECALIBRATE;
511538
512      fdc.ncn = fdc.nec765_command_bytes[2];
539      fdc->ncn = fdc->nec765_command_bytes[2];
513540
514541      /* get signed tracks */
515      signed_tracks = fdc.ncn - fdc.pcn[fdc.drive];
542      signed_tracks = fdc->ncn - fdc->pcn[fdc->drive];
516543
517544      /* if no tracks to seek, or drive is not ready, seek is complete */
518545      if ((signed_tracks==0) || (!floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)))
519546      {
520         nec765_seek_complete(machine);
547         nec765_seek_complete(device);
521548      }
522549      else
523550      {
r3867r3868
525552         floppy_drive_seek(img, signed_tracks);
526553
527554         /* seek complete - issue an interrupt */
528         nec765_setup_timed_int(signed_tracks);
555         nec765_setup_timed_int(device,signed_tracks);
529556      }
530557   }
531558
532    nec765_idle();
559    nec765_idle(device);
533560
534561}
535562
536563
537564
538static void nec765_setup_execution_phase_read(running_machine *machine, char *ptr, int size)
565static void nec765_setup_execution_phase_read(const device_config *device, char *ptr, int size)
539566{
540   fdc.FDC_main |= 0x040;                     /* FDC->CPU */
567   nec765_t *fdc = get_safe_token(device);
568   fdc->FDC_main |= 0x040;                     /* FDC->CPU */
541569
542   fdc.nec765_transfer_bytes_count = 0;
543   fdc.nec765_transfer_bytes_remaining = size;
544   fdc.execution_phase_data = ptr;
545   fdc.nec765_phase = NEC765_EXECUTION_PHASE_READ;
570   fdc->nec765_transfer_bytes_count = 0;
571   fdc->nec765_transfer_bytes_remaining = size;
572   fdc->execution_phase_data = ptr;
573   fdc->nec765_phase = NEC765_EXECUTION_PHASE_READ;
546574
547   nec765_setup_timed_data_request(machine, 1);
575   nec765_setup_timed_data_request(device, 1);
548576}
549577
550static void nec765_setup_execution_phase_write(running_machine *machine, char *ptr, int size)
578static void nec765_setup_execution_phase_write(const device_config *device, char *ptr, int size)
551579{
552   fdc.FDC_main &= ~0x040;                     /* FDC->CPU */
580   nec765_t *fdc = get_safe_token(device);
581   
582   fdc->FDC_main &= ~0x040;                     /* FDC->CPU */
553583
554   fdc.nec765_transfer_bytes_count = 0;
555   fdc.nec765_transfer_bytes_remaining = size;
556   fdc.execution_phase_data = ptr;
557   fdc.nec765_phase = NEC765_EXECUTION_PHASE_WRITE;
584   fdc->nec765_transfer_bytes_count = 0;
585   fdc->nec765_transfer_bytes_remaining = size;
586   fdc->execution_phase_data = ptr;
587   fdc->nec765_phase = NEC765_EXECUTION_PHASE_WRITE;
558588
559589   /* setup a data request with first byte */
560   nec765_setup_timed_data_request(machine,1);
590   nec765_setup_timed_data_request(device,1);
561591}
562592
563593
564static void nec765_setup_result_phase(running_machine *machine, int byte_count)
594static void nec765_setup_result_phase(const device_config *device, int byte_count)
565595{
566   fdc.FDC_main |= 0x040;                     /* FDC->CPU */
567   fdc.FDC_main &= ~0x020;                    /* not execution phase */
596   nec765_t *fdc = get_safe_token(device);
597   
598   fdc->FDC_main |= 0x040;                     /* FDC->CPU */
599   fdc->FDC_main &= ~0x020;                    /* not execution phase */
568600
569   fdc.nec765_transfer_bytes_count = 0;
570   fdc.nec765_transfer_bytes_remaining = byte_count;
571   fdc.nec765_phase = NEC765_RESULT_PHASE;
601   fdc->nec765_transfer_bytes_count = 0;
602   fdc->nec765_transfer_bytes_remaining = byte_count;
603   fdc->nec765_phase = NEC765_RESULT_PHASE;
572604
573   nec765_setup_timed_result_data_request(machine);
605   nec765_setup_timed_result_data_request(device);
574606}
575607
576void nec765_idle(void)
608void nec765_idle(const device_config *device)
577609{
578   fdc.FDC_main &= ~0x040;                     /* CPU->FDC */
579   fdc.FDC_main &= ~0x020;                    /* not execution phase */
580   fdc.FDC_main &= ~0x010;                     /* not busy */
581   fdc.nec765_phase = NEC765_COMMAND_PHASE_FIRST_BYTE;
610   nec765_t *fdc = get_safe_token(device);
611   
612   fdc->FDC_main &= ~0x040;                     /* CPU->FDC */
613   fdc->FDC_main &= ~0x020;                    /* not execution phase */
614   fdc->FDC_main &= ~0x010;                     /* not busy */
615   fdc->nec765_phase = NEC765_COMMAND_PHASE_FIRST_BYTE;
582616
583   nec765_set_data_request();
617   nec765_set_data_request(device);
584618}
585619
586620
587621
588622/* change flags */
589static void nec765_change_flags(running_machine *machine,unsigned int flags, unsigned int mask)
623static void nec765_change_flags(const device_config *device,unsigned int flags, unsigned int mask)
590624{
591625   unsigned int new_flags;
592626   unsigned int changed_flags;
593
627   nec765_t *fdc = get_safe_token(device);
628   
594629   assert((flags & ~mask) == 0);
595630
596631   /* compute the new flags and which ones have changed */
597   new_flags = fdc.nec765_flags & ~mask;
632   new_flags = fdc->nec765_flags & ~mask;
598633   new_flags |= flags;
599   changed_flags = fdc.nec765_flags ^ new_flags;
600   fdc.nec765_flags = new_flags;
634   changed_flags = fdc->nec765_flags ^ new_flags;
635   fdc->nec765_flags = new_flags;
601636
602637   /* if interrupt changed, call the handler */
603   if ((changed_flags & NEC765_INT) && nec765_iface.interrupt)
604      nec765_iface.interrupt(machine,(fdc.nec765_flags & NEC765_INT) ? 1 : 0);
638   if ((changed_flags & NEC765_INT) && fdc->intf->interrupt)
639      fdc->intf->interrupt(device,(fdc->nec765_flags & NEC765_INT) ? 1 : 0);
605640
606641   /* if DRQ changed, call the handler */
607   if ((changed_flags & NEC765_DMA_DRQ) && nec765_iface.dma_drq)
608      nec765_iface.dma_drq(machine,(fdc.nec765_flags & NEC765_DMA_DRQ) ? 1 : 0, fdc.FDC_main & (1<<6));
642   if ((changed_flags & NEC765_DMA_DRQ) && fdc->intf->dma_drq)
643      fdc->intf->dma_drq(device,(fdc->nec765_flags & NEC765_DMA_DRQ) ? 1 : 0, fdc->FDC_main & (1<<6));
609644}
610645
611646
612647
613648/* set int output */
614static void nec765_set_int(running_machine *machine, int state)
649static void nec765_set_int(const device_config *device, int state)
615650{
616651   if (LOG_INTERRUPT)
617652      logerror("nec765_set_int(): state=%d\n", state);
618   nec765_change_flags(machine, state ? NEC765_INT : 0, NEC765_INT);
653   nec765_change_flags(device, state ? NEC765_INT : 0, NEC765_INT);
619654}
620655
621656
622657
623658/* set dma request output */
624static void nec765_set_dma_drq(running_machine *machine, int state)
659static void nec765_set_dma_drq(const device_config *device, int state)
625660{
626   nec765_change_flags(machine, state ? NEC765_DMA_DRQ : 0, NEC765_DMA_DRQ);
661   nec765_change_flags(device, state ? NEC765_DMA_DRQ : 0, NEC765_DMA_DRQ);
627662}
628663
629664
r3867r3868
656691/* done when ready state of drive changes */
657692/* this ignores if command is active, in which case command should terminate immediatly
658693with error */
659static void nec765_set_ready_change_callback(const device_config *img, int state)
694static void nec765_set_ready_change_callback(const device_config *controller, const device_config *img, int state)
660695{
696   nec765_t *fdc = get_safe_token(controller);
661697   int drive = image_index_in_device(img);
662698
663699   logerror("nec765: ready state change\n");
664700
665701   /* drive that changed state */
666   fdc.nec765_status[0] = 0x0c0 | drive;
702   fdc->nec765_status[0] = 0x0c0 | drive;
667703
668704   /* not ready */
669   if (state==0 && fdc.rdy_pin == NEC765_RDY_PIN_CONNECTED )
670      fdc.nec765_status[0] |= 8;
705   if (state==0 && fdc->intf->rdy_pin == NEC765_RDY_PIN_CONNECTED )
706      fdc->nec765_status[0] |= 8;
671707
672708   /* trigger an int */
673   nec765_set_int(img->machine, 1);
709   nec765_set_int(controller, 1);
674710}
675711
676712
677
678
679void nec765_init(running_machine *machine, const nec765_interface *iface, NEC765_VERSION version, NEC765_RDY_PIN rdy_pin)
680{
681   int i;
682
683   fdc.version = version;
684   fdc.rdy_pin = rdy_pin;
685   fdc.timer = timer_alloc(machine, nec765_timer_callback, NULL);
686   fdc.seek_timer = timer_alloc(machine, nec765_seek_timer_callback, NULL);
687   fdc.command_timer = timer_alloc(machine, nec765_continue_command, NULL);
688   memset(&nec765_iface, 0, sizeof(nec765_interface));
689
690   if (iface)
691   {
692      memcpy(&nec765_iface, iface, sizeof(nec765_interface));
693   }
694
695   fdc.nec765_flags &= NEC765_FDD_READY;
696
697   nec765_reset(machine, 0);
698
699   for (i = 0; i < device_count(machine, IO_FLOPPY); i++)
700      floppy_drive_set_ready_state_change_callback(image_from_devtype_and_index(IO_FLOPPY, i), nec765_set_ready_change_callback);
701}
702
703
704713/* terminal count input */
705void nec765_set_tc_state(running_machine *machine, int state)
714void nec765_set_tc_state(const device_config *device, int state)
706715{
707716   int old_state;
717   nec765_t *fdc = get_safe_token(device);
708718
709   old_state = fdc.nec765_flags;
719   old_state = fdc->nec765_flags;
710720
711721   /* clear drq */
712   nec765_set_dma_drq(machine, 0);
722   nec765_set_dma_drq(device, 0);
713723
714   fdc.nec765_flags &= ~NEC765_TC;
724   fdc->nec765_flags &= ~NEC765_TC;
715725   if (state)
716726   {
717      fdc.nec765_flags |= NEC765_TC;
727      fdc->nec765_flags |= NEC765_TC;
718728   }
719729
720730   /* changed state? */
721   if (((fdc.nec765_flags^old_state) & NEC765_TC)!=0)
731   if (((fdc->nec765_flags^old_state) & NEC765_TC)!=0)
722732   {
723733      /* now set? */
724      if ((fdc.nec765_flags & NEC765_TC)!=0)
734      if ((fdc->nec765_flags & NEC765_TC)!=0)
725735      {
726736         /* yes */
727         if (fdc.timer)
737         if (fdc->timer)
728738         {
729            if (fdc.timer_type==0)
739            if (fdc->timer_type==0)
730740            {
731               timer_reset(fdc.timer, attotime_never);
741               timer_reset(fdc->timer, attotime_never);
732742
733743
734744            }
735745         }
736746
737747#ifdef NO_END_OF_CYLINDER
738         timer_adjust_oneshot(fdc.command_timer, attotime_zero, 0);
748         timer_adjust_oneshot(fdc->command_timer, attotime_zero, 0);
739749#else
740         nec765_update_state(machine);
750         nec765_update_state(device);
741751#endif
742752      }
743753   }
744754}
745755
746READ8_HANDLER(nec765_status_r)
756READ8_DEVICE_HANDLER(nec765_status_r)
747757{
758   nec765_t *fdc = get_safe_token(device);
748759   if (LOG_EXTRA)
749      logerror("nec765 status r: %02x\n",fdc.FDC_main);
750   return fdc.FDC_main;
760      logerror("nec765 status r: %02x\n",fdc->FDC_main);
761   return fdc->FDC_main;
751762}
752763
753764
r3867r3868
758769if SK==1, and we are executing a read deleted data command, and a data mark is found,
759770skip it. */
760771
761static int nec765_read_skip_sector(void)
772static int nec765_read_skip_sector(const device_config *device)
762773{
774   nec765_t *fdc = get_safe_token(device);
763775   /* skip set? */
764   if ((fdc.nec765_command_bytes[0] & (1<<5))!=0)
776   if ((fdc->nec765_command_bytes[0] & (1<<5))!=0)
765777   {
766778      /* read data? */
767      if (fdc.command == 0x06)
779      if (fdc->command == 0x06)
768780      {
769781         /* did we just find a sector with deleted data mark? */
770         if (fdc.data_type == NEC765_DAM_DELETED_DATA)
782         if (fdc->data_type == NEC765_DAM_DELETED_DATA)
771783         {
772784            /* skip it */
773785            return TRUE;
r3867r3868
775787      }
776788      /* deleted data? */
777789      else
778      if (fdc.command == 0x0c)
790      if (fdc->command == 0x0c)
779791      {
780792         /* did we just find a sector with data mark ? */
781         if (fdc.data_type == NEC765_DAM_DATA)
793         if (fdc->data_type == NEC765_DAM_DATA)
782794         {
783795            /* skip it */
784796            return TRUE;
r3867r3868
801813  - if the index is seen twice while it is searching for a sector, then the sector cannot be found
802814*/
803815
804static void nec765_get_next_id(running_machine *machine, chrn_id *id)
816static void nec765_get_next_id(const device_config *device, chrn_id *id)
805817{
806   const device_config *img = current_image(machine);
818   nec765_t *fdc = get_safe_token(device);
819   const device_config *img = current_image(device);
807820
808821   /* get next id from disc */
809   floppy_drive_get_next_id(img, fdc.side,id);
822   floppy_drive_get_next_id(img, fdc->side,id);
810823
811   fdc.sector_id = id->data_id;
824   fdc->sector_id = id->data_id;
812825
813826   /* set correct data type */
814   fdc.data_type = NEC765_DAM_DATA;
827   fdc->data_type = NEC765_DAM_DATA;
815828   if (id->flags & ID_FLAG_DELETED_DATA)
816829   {
817      fdc.data_type = NEC765_DAM_DELETED_DATA;
830      fdc->data_type = NEC765_DAM_DELETED_DATA;
818831   }
819832}
820833
821static int nec765_get_matching_sector(running_machine *machine)
834static int nec765_get_matching_sector(const device_config *device)
822835{
823   const device_config *img = current_image(machine);
836   nec765_t *fdc = get_safe_token(device);
837   const device_config *img = current_image(device);
824838   chrn_id id;
825839
826840   /* number of times we have seen index hole */
r3867r3868
829843   /* get sector id's */
830844   do
831845    {
832      nec765_get_next_id(machine, &id);
846      nec765_get_next_id(device, &id);
833847
834848      /* tested on Amstrad CPC - All bytes must match, otherwise
835849      a NO DATA error is reported */
836      if (id.R == fdc.nec765_command_bytes[4])
850      if (id.R == fdc->nec765_command_bytes[4])
837851      {
838         if (id.C == fdc.nec765_command_bytes[2])
852         if (id.C == fdc->nec765_command_bytes[2])
839853         {
840            if (id.H == fdc.nec765_command_bytes[3])
854            if (id.H == fdc->nec765_command_bytes[3])
841855            {
842               if (id.N == fdc.nec765_command_bytes[5])
856               if (id.N == fdc->nec765_command_bytes[5])
843857               {
844858                  /* end of cylinder is set if:
845859                  1. sector data is read completely (i.e. no other errors occur like
846860                  no data.
847861                  2. sector being read is same specified by EOT
848862                  3. terminal count is not received */
849                  if (fdc.nec765_command_bytes[4]==fdc.nec765_command_bytes[6])
863                  if (fdc->nec765_command_bytes[4]==fdc->nec765_command_bytes[6])
850864                  {
851865                     /* set end of cylinder */
852                     fdc.nec765_status[1] |= NEC765_ST1_END_OF_CYLINDER;
866                     fdc->nec765_status[1] |= NEC765_ST1_END_OF_CYLINDER;
853867                  }
854868
855869                  return TRUE;
r3867r3868
862876            in the read/write command did not match the C value read from the disc */
863877
864878            /* no data - checked on Amstrad CPC */
865            fdc.nec765_status[1] |= NEC765_ST1_NO_DATA;
879            fdc->nec765_status[1] |= NEC765_ST1_NO_DATA;
866880            /* bad C value */
867            fdc.nec765_status[2] |= NEC765_ST2_WRONG_CYLINDER;
881            fdc->nec765_status[2] |= NEC765_ST2_WRONG_CYLINDER;
868882
869883            if (id.C == 0x0ff)
870884            {
871885               /* the C value is 0x0ff which indicates a bad track in the IBM soft-sectored
872886               format */
873               fdc.nec765_status[2] |= NEC765_ST2_BAD_CYLINDER;
887               fdc->nec765_status[2] |= NEC765_ST2_BAD_CYLINDER;
874888            }
875889
876890            return FALSE;
r3867r3868
887901   while (index_count!=2);
888902
889903   /* no data - specified sector ID was not found */
890    fdc.nec765_status[1] |= NEC765_ST1_NO_DATA;
904    fdc->nec765_status[1] |= NEC765_ST1_NO_DATA;
891905
892906   return 0;
893907}
894908
895static void nec765_read_complete(running_machine *machine)
909static void nec765_read_complete(const device_config *device)
896910{
897
911   nec765_t *fdc = get_safe_token(device);
898912/* causes problems!!! - need to fix */
899913#ifdef NO_END_OF_CYLINDER
900914   /* set end of cylinder */
901   fdc.nec765_status[1] &= ~NEC765_ST1_END_OF_CYLINDER;
915   fdc->nec765_status[1] &= ~NEC765_ST1_END_OF_CYLINDER;
902916#else
903917   /* completed read command */
904918
r3867r3868
909923      */
910924
911925   /* if end of cylinder is set, and we did receive a terminal count, then clear it */
912   if ((fdc.nec765_flags & NEC765_TC)!=0)
926   if ((fdc->nec765_flags & NEC765_TC)!=0)
913927   {
914928      /* set end of cylinder */
915      fdc.nec765_status[1] &= ~NEC765_ST1_END_OF_CYLINDER;
929      fdc->nec765_status[1] &= ~NEC765_ST1_END_OF_CYLINDER;
916930   }
917931#endif
918932
919   nec765_setup_st0();
933   nec765_setup_st0(device);
920934
921   fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
922   fdc.nec765_result_bytes[1] = fdc.nec765_status[1];
923   fdc.nec765_result_bytes[2] = fdc.nec765_status[2];
924   fdc.nec765_result_bytes[3] = fdc.nec765_command_bytes[2]; /* C */
925   fdc.nec765_result_bytes[4] = fdc.nec765_command_bytes[3]; /* H */
926   fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */
927   fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */
935   fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
936   fdc->nec765_result_bytes[1] = fdc->nec765_status[1];
937   fdc->nec765_result_bytes[2] = fdc->nec765_status[2];
938   fdc->nec765_result_bytes[3] = fdc->nec765_command_bytes[2]; /* C */
939   fdc->nec765_result_bytes[4] = fdc->nec765_command_bytes[3]; /* H */
940   fdc->nec765_result_bytes[5] = fdc->nec765_command_bytes[4]; /* R */
941   fdc->nec765_result_bytes[6] = fdc->nec765_command_bytes[5]; /* N */
928942
929   nec765_setup_result_phase(machine,7);
943   nec765_setup_result_phase(device,7);
930944}
931945
932static void nec765_read_data(running_machine *machine)
946static void nec765_read_data(const device_config *device)
933947{
934   const device_config *img = current_image(machine);
948   nec765_t *fdc = get_safe_token(device);
949   const device_config *img = current_image(device);
935950
936951   if (!(floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY)))
937952   {
938      fdc.nec765_status[0] = 0x0c0 | (1<<4) | fdc.drive | (fdc.side<<2);
939      fdc.nec765_status[1] = 0x00;
940      fdc.nec765_status[2] = 0x00;
953      fdc->nec765_status[0] = 0x0c0 | (1<<4) | fdc->drive | (fdc->side<<2);
954      fdc->nec765_status[1] = 0x00;
955      fdc->nec765_status[2] = 0x00;
941956
942      fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
943      fdc.nec765_result_bytes[1] = fdc.nec765_status[1];
944      fdc.nec765_result_bytes[2] = fdc.nec765_status[2];
945      fdc.nec765_result_bytes[3] = fdc.nec765_command_bytes[2]; /* C */
946      fdc.nec765_result_bytes[4] = fdc.nec765_command_bytes[3]; /* H */
947      fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */
948      fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */
949      nec765_setup_result_phase(machine,7);
957      fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
958      fdc->nec765_result_bytes[1] = fdc->nec765_status[1];
959      fdc->nec765_result_bytes[2] = fdc->nec765_status[2];
960      fdc->nec765_result_bytes[3] = fdc->nec765_command_bytes[2]; /* C */
961      fdc->nec765_result_bytes[4] = fdc->nec765_command_bytes[3]; /* H */
962      fdc->nec765_result_bytes[5] = fdc->nec765_command_bytes[4]; /* R */
963      fdc->nec765_result_bytes[6] = fdc->nec765_command_bytes[5]; /* N */
964      nec765_setup_result_phase(device,7);
950965      return;
951966   }
952967
953968   if (LOG_VERBOSE)
954      logerror("sector c: %02x h: %02x r: %02x n: %02x\n",fdc.nec765_command_bytes[2], fdc.nec765_command_bytes[3],fdc.nec765_command_bytes[4], fdc.nec765_command_bytes[5]);
969      logerror("sector c: %02x h: %02x r: %02x n: %02x\n",fdc->nec765_command_bytes[2], fdc->nec765_command_bytes[3],fdc->nec765_command_bytes[4], fdc->nec765_command_bytes[5]);
955970
956971   /* find a sector to read data from */
957972   {
r3867r3868
962977      do
963978      {
964979         /* get matching sector */
965         if (nec765_get_matching_sector(machine))
980         if (nec765_get_matching_sector(device))
966981         {
967982
968983            /* skip it? */
969            if (nec765_read_skip_sector())
984            if (nec765_read_skip_sector(device))
970985            {
971986               /* yes */
972987
973988               /* check that we haven't finished reading all sectors */
974               if (nec765_sector_count_complete(machine))
989               if (nec765_sector_count_complete(device))
975990               {
976991                  /* read complete */
977                  nec765_read_complete(machine);
992                  nec765_read_complete(device);
978993                  return;
979994               }
980995
981996               /* read not finished */
982997
983998               /* increment sector count */
984               nec765_increment_sector(machine);
999               nec765_increment_sector(device);
9851000            }
9861001            else
9871002            {
r3867r3868
9921007         else
9931008         {
9941009            /* error in finding sector */
995            nec765_read_complete(machine);
1010            nec765_read_complete(device);
9961011            return;
9971012         }
9981013      }
r3867r3868
10021017   {
10031018      int data_size;
10041019
1005      data_size = nec765_n_to_bytes(fdc.nec765_command_bytes[5]);
1020      data_size = nec765_n_to_bytes(fdc->nec765_command_bytes[5]);
10061021
1007      floppy_drive_read_sector_data(img, fdc.side, fdc.sector_id,nec765_data_buffer,data_size);
1022      floppy_drive_read_sector_data(img, fdc->side, fdc->sector_id,fdc->data_buffer,data_size);
10081023
1009        nec765_setup_execution_phase_read(machine,nec765_data_buffer, data_size);
1024        nec765_setup_execution_phase_read(device,fdc->data_buffer, data_size);
10101025   }
10111026}
10121027
10131028
1014static void nec765_format_track(running_machine *machine)
1029static void nec765_format_track(const device_config *device)
10151030{
1016   const device_config *img = current_image(machine);
1031   nec765_t *fdc = get_safe_token(device);
1032   const device_config *img = current_image(device);
10171033
10181034   /* write protected? */
10191035   if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
10201036   {
1021      fdc.nec765_status[1] |= NEC765_ST1_NOT_WRITEABLE;
1037      fdc->nec765_status[1] |= NEC765_ST1_NOT_WRITEABLE;
10221038
1023      nec765_setup_st0();
1039      nec765_setup_st0(device);
10241040      /* TODO: Check result is correct */
1025         fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
1026            fdc.nec765_result_bytes[1] = fdc.nec765_status[1];
1027            fdc.nec765_result_bytes[2] = fdc.nec765_status[2];
1028         fdc.nec765_result_bytes[3] = fdc.format_data[0];
1029         fdc.nec765_result_bytes[4] = fdc.format_data[1];
1030         fdc.nec765_result_bytes[5] = fdc.format_data[2];
1031         fdc.nec765_result_bytes[6] = fdc.format_data[3];
1032         nec765_setup_result_phase(machine,7);
1041         fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
1042            fdc->nec765_result_bytes[1] = fdc->nec765_status[1];
1043            fdc->nec765_result_bytes[2] = fdc->nec765_status[2];
1044         fdc->nec765_result_bytes[3] = fdc->format_data[0];
1045         fdc->nec765_result_bytes[4] = fdc->format_data[1];
1046         fdc->nec765_result_bytes[5] = fdc->format_data[2];
1047         fdc->nec765_result_bytes[6] = fdc->format_data[3];
1048         nec765_setup_result_phase(device,7);
10331049
10341050      return;
10351051   }
10361052
1037    nec765_setup_execution_phase_write(machine, &fdc.format_data[0], 4);
1053    nec765_setup_execution_phase_write(device, &fdc->format_data[0], 4);
10381054}
10391055
1040static void nec765_read_a_track(running_machine *machine)
1056static void nec765_read_a_track(const device_config *device)
10411057{
1058   nec765_t *fdc = get_safe_token(device);
10421059   int data_size;
10431060
10441061   /* SKIP not allowed with this command! */
r3867r3868
10461063   /* get next id */
10471064   chrn_id id;
10481065
1049   nec765_get_next_id(machine, &id);
1066   nec765_get_next_id(device, &id);
10501067
10511068   /* TO BE CONFIRMED! */
10521069   /* check id from disc */
1053   if (id.C==fdc.nec765_command_bytes[2])
1070   if (id.C==fdc->nec765_command_bytes[2])
10541071   {
1055      if (id.H==fdc.nec765_command_bytes[3])
1072      if (id.H==fdc->nec765_command_bytes[3])
10561073      {
1057         if (id.R==fdc.nec765_command_bytes[4])
1074         if (id.R==fdc->nec765_command_bytes[4])
10581075         {
1059            if (id.N==fdc.nec765_command_bytes[5])
1076            if (id.N==fdc->nec765_command_bytes[5])
10601077            {
10611078               /* if ID found, then no data is not set */
10621079               /* otherwise no data will remain set */
1063               fdc.nec765_status[1] &=~NEC765_ST1_NO_DATA;
1080               fdc->nec765_status[1] &=~NEC765_ST1_NO_DATA;
10641081            }
10651082         }
10661083      }
r3867r3868
10691086
10701087   data_size = nec765_n_to_bytes(id.N);
10711088
1072   floppy_drive_read_sector_data(current_image(machine), fdc.side, fdc.sector_id,nec765_data_buffer,data_size);
1089   floppy_drive_read_sector_data(current_image(device), fdc->side, fdc->sector_id,fdc->data_buffer,data_size);
10731090
1074   nec765_setup_execution_phase_read(machine,nec765_data_buffer, data_size);
1091   nec765_setup_execution_phase_read(device,fdc->data_buffer, data_size);
10751092}
10761093
1077static int nec765_just_read_last_sector_on_track(running_machine *machine)
1094static int nec765_just_read_last_sector_on_track(const device_config *device)
10781095{
1079   if (floppy_drive_get_flag_state(current_image(machine), FLOPPY_DRIVE_INDEX))
1096   if (floppy_drive_get_flag_state(current_image(device), FLOPPY_DRIVE_INDEX))
10801097      return 1;
10811098   return 0;
10821099}
10831100
1084static void nec765_write_complete(running_machine *machine)
1101static void nec765_write_complete(const device_config *device)
10851102{
1103   nec765_t *fdc = get_safe_token(device);
10861104
10871105/* causes problems!!! - need to fix */
10881106#ifdef NO_END_OF_CYLINDER
10891107        /* set end of cylinder */
1090        fdc.nec765_status[1] &= ~NEC765_ST1_END_OF_CYLINDER;
1108        fdc->nec765_status[1] &= ~NEC765_ST1_END_OF_CYLINDER;
10911109#else
10921110   /* completed read command */
10931111
r3867r3868
10981116    */
10991117
11001118   /* if end of cylinder is set, and we did receive a terminal count, then clear it */
1101   if ((fdc.nec765_flags & NEC765_TC)!=0)
1119   if ((fdc->nec765_flags & NEC765_TC)!=0)
11021120   {
11031121      /* set end of cylinder */
1104      fdc.nec765_status[1] &= ~NEC765_ST1_END_OF_CYLINDER;
1122      fdc->nec765_status[1] &= ~NEC765_ST1_END_OF_CYLINDER;
11051123   }
11061124#endif
11071125
1108   nec765_setup_st0();
1126   nec765_setup_st0(device);
11091127
1110    fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
1111    fdc.nec765_result_bytes[1] = fdc.nec765_status[1];
1112    fdc.nec765_result_bytes[2] = fdc.nec765_status[2];
1113    fdc.nec765_result_bytes[3] = fdc.nec765_command_bytes[2]; /* C */
1114    fdc.nec765_result_bytes[4] = fdc.nec765_command_bytes[3]; /* H */
1115    fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */
1116    fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */
1128    fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
1129    fdc->nec765_result_bytes[1] = fdc->nec765_status[1];
1130    fdc->nec765_result_bytes[2] = fdc->nec765_status[2];
1131    fdc->nec765_result_bytes[3] = fdc->nec765_command_bytes[2]; /* C */
1132    fdc->nec765_result_bytes[4] = fdc->nec765_command_bytes[3]; /* H */
1133    fdc->nec765_result_bytes[5] = fdc->nec765_command_bytes[4]; /* R */
1134    fdc->nec765_result_bytes[6] = fdc->nec765_command_bytes[5]; /* N */
11171135
1118    nec765_setup_result_phase(machine,7);
1136    nec765_setup_result_phase(device,7);
11191137}
11201138
11211139
1122static void nec765_write_data(running_machine *machine)
1140static void nec765_write_data(const device_config *device)
11231141{
1124   if (!(floppy_drive_get_flag_state(current_image(machine), FLOPPY_DRIVE_READY)))
1142   nec765_t *fdc = get_safe_token(device);
1143   if (!(floppy_drive_get_flag_state(current_image(device), FLOPPY_DRIVE_READY)))
11251144   {
1126      fdc.nec765_status[0] = 0x0c0 | (1<<4) | fdc.drive | (fdc.side<<2);
1127        fdc.nec765_status[1] = 0x00;
1128        fdc.nec765_status[2] = 0x00;
1145      fdc->nec765_status[0] = 0x0c0 | (1<<4) | fdc->drive | (fdc->side<<2);
1146        fdc->nec765_status[1] = 0x00;
1147        fdc->nec765_status[2] = 0x00;
11291148
1130        fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
1131        fdc.nec765_result_bytes[1] = fdc.nec765_status[1];
1132        fdc.nec765_result_bytes[2] = fdc.nec765_status[2];
1133        fdc.nec765_result_bytes[3] = fdc.nec765_command_bytes[2]; /* C */
1134        fdc.nec765_result_bytes[4] = fdc.nec765_command_bytes[3]; /* H */
1135        fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */
1136        fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */
1137      nec765_setup_result_phase(machine,7);
1149        fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
1150        fdc->nec765_result_bytes[1] = fdc->nec765_status[1];
1151        fdc->nec765_result_bytes[2] = fdc->nec765_status[2];
1152        fdc->nec765_result_bytes[3] = fdc->nec765_command_bytes[2]; /* C */
1153        fdc->nec765_result_bytes[4] = fdc->nec765_command_bytes[3]; /* H */
1154        fdc->nec765_result_bytes[5] = fdc->nec765_command_bytes[4]; /* R */
1155        fdc->nec765_result_bytes[6] = fdc->nec765_command_bytes[5]; /* N */
1156      nec765_setup_result_phase(device,7);
11381157      return;
11391158   }
11401159
11411160   /* write protected? */
1142   if (floppy_drive_get_flag_state(current_image(machine), FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
1161   if (floppy_drive_get_flag_state(current_image(device), FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
11431162   {
1144      fdc.nec765_status[1] |= NEC765_ST1_NOT_WRITEABLE;
1163      fdc->nec765_status[1] |= NEC765_ST1_NOT_WRITEABLE;
11451164
1146      nec765_write_complete(machine);
1165      nec765_write_complete(device);
11471166      return;
11481167   }
11491168
1150   if (nec765_get_matching_sector(machine))
1169   if (nec765_get_matching_sector(device))
11511170   {
11521171      int data_size;
11531172
1154      data_size = nec765_n_to_bytes(fdc.nec765_command_bytes[5]);
1173      data_size = nec765_n_to_bytes(fdc->nec765_command_bytes[5]);
11551174
1156        nec765_setup_execution_phase_write(machine,nec765_data_buffer, data_size);
1175        nec765_setup_execution_phase_write(device,fdc->data_buffer, data_size);
11571176   }
11581177    else
11591178    {
1160        nec765_setup_result_phase(machine,7);
1179        nec765_setup_result_phase(device,7);
11611180    }
11621181}
11631182
11641183
11651184/* return true if we have read all sectors, false if not */
1166static int nec765_sector_count_complete(running_machine *machine)
1185static int nec765_sector_count_complete(const device_config *device)
11671186{
1187   nec765_t *fdc = get_safe_token(device);
11681188/* this is not correct?? */
11691189#if 1
11701190   /* if terminal count has been set - yes */
1171   if (fdc.nec765_flags & NEC765_TC)
1191   if (fdc->nec765_flags & NEC765_TC)
11721192   {
11731193      /* completed */
11741194      return 1;
r3867r3868
11771197
11781198
11791199   /* multi-track? */
1180   if (fdc.nec765_command_bytes[0] & 0x080)
1200   if (fdc->nec765_command_bytes[0] & 0x080)
11811201   {
11821202      /* it appears that in multi-track mode,
11831203      the EOT parameter of the command is ignored!? -
r3867r3868
11921212      */
11931213
11941214      /* if just read last sector and on side 1 - finish */
1195      if ((nec765_just_read_last_sector_on_track(machine)) &&
1196         (fdc.side==1))
1215      if ((nec765_just_read_last_sector_on_track(device)) &&
1216         (fdc->side==1))
11971217      {
11981218         return 1;
11991219      }
12001220
12011221      /* if not on second side then we haven't finished yet */
1202      if (fdc.side!=1)
1222      if (fdc->side!=1)
12031223      {
12041224         /* haven't finished yet */
12051225         return 0;
r3867r3868
12081228   else
12091229   {
12101230      /* sector id == EOT? */
1211      if ((fdc.nec765_command_bytes[4]==fdc.nec765_command_bytes[6]))
1231      if ((fdc->nec765_command_bytes[4]==fdc->nec765_command_bytes[6]))
12121232      {
12131233
12141234         /* completed */
r3867r3868
12181238#else
12191239
12201240   /* if terminal count has been set - yes */
1221   if (fdc.nec765_flags & NEC765_TC)
1241   if (fdc->nec765_flags & NEC765_TC)
12221242   {
12231243      /* completed */
12241244      return 1;
r3867r3868
12771297  */
12781298
12791299   /* sector id == EOT? */
1280   if ((fdc.nec765_command_bytes[4]==fdc.nec765_command_bytes[6]))
1300   if ((fdc->nec765_command_bytes[4]==fdc->nec765_command_bytes[6]))
12811301   {
12821302      /* multi-track? */
1283      if (fdc.nec765_command_bytes[0] & 0x080)
1303      if (fdc->nec765_command_bytes[0] & 0x080)
12841304      {
1285         /* if we have reached EOT (fdc.nec765_command_bytes[6])
1305         /* if we have reached EOT (fdc->nec765_command_bytes[6])
12861306         on side 1, then read is complete */
1287         if (fdc.side==1)
1307         if (fdc->side==1)
12881308            return 1;
12891309
12901310         return 0;
r3867r3868
12991319   return 0;
13001320}
13011321
1302static void   nec765_increment_sector(running_machine *machine)
1322static void   nec765_increment_sector(const device_config *device)
13031323{
1324   nec765_t *fdc = get_safe_token(device);
13041325   /* multi-track? */
1305   if (fdc.nec765_command_bytes[0] & 0x080)
1326   if (fdc->nec765_command_bytes[0] & 0x080)
13061327   {
13071328      /* reached EOT? */
1308      /* if (fdc.nec765_command_bytes[4]==fdc.nec765_command_bytes[6])*/
1309      if (nec765_just_read_last_sector_on_track(machine))
1329      /* if (fdc->nec765_command_bytes[4]==fdc->nec765_command_bytes[6])*/
1330      if (nec765_just_read_last_sector_on_track(device))
13101331      {
13111332         /* yes */
13121333
13131334         /* reached EOT */
13141335         /* change side to 1 */
1315         fdc.side = 1;
1336         fdc->side = 1;
13161337         /* reset sector id to 1 */
1317         fdc.nec765_command_bytes[4] = 1;
1338         fdc->nec765_command_bytes[4] = 1;
13181339         /* set head to 1 for get next sector test */
1319         fdc.nec765_command_bytes[3] = 1;
1340         fdc->nec765_command_bytes[3] = 1;
13201341      }
13211342      else
13221343      {
13231344         /* increment */
1324         fdc.nec765_command_bytes[4]++;
1345         fdc->nec765_command_bytes[4]++;
13251346      }
13261347
13271348   }
13281349   else
13291350   {
1330      fdc.nec765_command_bytes[4]++;
1351      fdc->nec765_command_bytes[4]++;
13311352   }
13321353}
13331354
r3867r3868
13371358the data is not skipped. The data is read, but the control mark is set and the read is stopped */
13381359/* if SK==0, and we are executing a read deleted data command, and a data sector is found,
13391360the data is not skipped. The data is read, but the control mark is set and the read is stopped */
1340static int nec765_read_data_stop(void)
1361static int nec765_read_data_stop(const device_config *device)
13411362{
1363   nec765_t *fdc = get_safe_token(device);
13421364   /* skip not set? */
1343   if ((fdc.nec765_command_bytes[0] & (1<<5))==0)
1365   if ((fdc->nec765_command_bytes[0] & (1<<5))==0)
13441366   {
13451367      /* read data? */
1346      if (fdc.command == 0x06)
1368      if (fdc->command == 0x06)
13471369      {
13481370         /* did we just read a sector with deleted data? */
1349         if (fdc.data_type == NEC765_DAM_DELETED_DATA)
1371         if (fdc->data_type == NEC765_DAM_DELETED_DATA)
13501372         {
13511373            /* set control mark */
1352            fdc.nec765_status[2] |= NEC765_ST2_CONTROL_MARK;
1374            fdc->nec765_status[2] |= NEC765_ST2_CONTROL_MARK;
13531375
13541376            /* quit */
13551377            return TRUE;
r3867r3868
13571379      }
13581380      /* deleted data? */
13591381      else
1360      if (fdc.command == 0x0c)
1382      if (fdc->command == 0x0c)
13611383      {
13621384         /* did we just read a sector with data? */
1363         if (fdc.data_type == NEC765_DAM_DATA)
1385         if (fdc->data_type == NEC765_DAM_DATA)
13641386         {
13651387            /* set control mark */
1366            fdc.nec765_status[2] |= NEC765_ST2_CONTROL_MARK;
1388            fdc->nec765_status[2] |= NEC765_ST2_CONTROL_MARK;
13671389
13681390            /* quit */
13691391            return TRUE;
r3867r3868
13771399
13781400static TIMER_CALLBACK(nec765_continue_command)
13791401{
1380   if ((fdc.nec765_phase == NEC765_EXECUTION_PHASE_READ) ||
1381      (fdc.nec765_phase == NEC765_EXECUTION_PHASE_WRITE))
1402   const device_config *device = ptr;
1403   nec765_t *fdc = get_safe_token(device);
1404   if ((fdc->nec765_phase == NEC765_EXECUTION_PHASE_READ) ||
1405      (fdc->nec765_phase == NEC765_EXECUTION_PHASE_WRITE))
13821406   {
1383      switch (fdc.command)
1407      switch (fdc->command)
13841408        {
13851409         /* read a track */
13861410         case 0x02:
13871411         {
1388            fdc.sector_counter++;
1412            fdc->sector_counter++;
13891413
13901414            /* sector counter == EOT */
1391            if (fdc.sector_counter==fdc.nec765_command_bytes[6])
1415            if (fdc->sector_counter==fdc->nec765_command_bytes[6])
13921416            {
13931417               /* TODO: Add correct info here */
13941418
1395               fdc.nec765_status[1] |= NEC765_ST1_END_OF_CYLINDER;
1419               fdc->nec765_status[1] |= NEC765_ST1_END_OF_CYLINDER;
13961420
1397               nec765_setup_st0();
1421               nec765_setup_st0(device);
13981422
1399               fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
1400               fdc.nec765_result_bytes[1] = fdc.nec765_status[1];
1401               fdc.nec765_result_bytes[2] = fdc.nec765_status[2];
1402               fdc.nec765_result_bytes[3] = fdc.nec765_command_bytes[2]; /* C */
1403               fdc.nec765_result_bytes[4] = fdc.nec765_command_bytes[3]; /* H */
1404               fdc.nec765_result_bytes[5] = fdc.nec765_command_bytes[4]; /* R */
1405               fdc.nec765_result_bytes[6] = fdc.nec765_command_bytes[5]; /* N */
1423               fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
1424               fdc->nec765_result_bytes[1] = fdc->nec765_status[1];
1425               fdc->nec765_result_bytes[2] = fdc->nec765_status[2];
1426               fdc->nec765_result_bytes[3] = fdc->nec765_command_bytes[2]; /* C */
1427               fdc->nec765_result_bytes[4] = fdc->nec765_command_bytes[3]; /* H */
1428               fdc->nec765_result_bytes[5] = fdc->nec765_command_bytes[4]; /* R */
1429               fdc->nec765_result_bytes[6] = fdc->nec765_command_bytes[5]; /* N */
14061430
1407               nec765_setup_result_phase(machine,7);
1431               nec765_setup_result_phase(device,7);
14081432            }
14091433            else
14101434            {
1411               nec765_read_a_track(machine);
1435               nec765_read_a_track(device);
14121436            }
14131437         }
14141438         break;
r3867r3868
14161440         /* format track */
14171441         case 0x0d:
14181442         {
1419            floppy_drive_format_sector(current_image(machine), fdc.side, fdc.sector_counter,
1420               fdc.format_data[0], fdc.format_data[1],
1421               fdc.format_data[2], fdc.format_data[3],
1422               fdc.nec765_command_bytes[5]);
1443            floppy_drive_format_sector(current_image(device), fdc->side, fdc->sector_counter,
1444               fdc->format_data[0], fdc->format_data[1],
1445               fdc->format_data[2], fdc->format_data[3],
1446               fdc->nec765_command_bytes[5]);
14231447
1424            fdc.sector_counter++;
1448            fdc->sector_counter++;
14251449
14261450            /* sector_counter = SC */
1427            if (fdc.sector_counter == fdc.nec765_command_bytes[3])
1451            if (fdc->sector_counter == fdc->nec765_command_bytes[3])
14281452            {
14291453               /* TODO: Check result is correct */
1430               fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
1431               fdc.nec765_result_bytes[1] = fdc.nec765_status[1];
1432               fdc.nec765_result_bytes[2] = fdc.nec765_status[2];
1433               fdc.nec765_result_bytes[3] = fdc.format_data[0];
1434               fdc.nec765_result_bytes[4] = fdc.format_data[1];
1435               fdc.nec765_result_bytes[5] = fdc.format_data[2];
1436               fdc.nec765_result_bytes[6] = fdc.format_data[3];
1437               nec765_setup_result_phase(machine,7);
1454               fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
1455               fdc->nec765_result_bytes[1] = fdc->nec765_status[1];
1456               fdc->nec765_result_bytes[2] = fdc->nec765_status[2];
1457               fdc->nec765_result_bytes[3] = fdc->format_data[0];
1458               fdc->nec765_result_bytes[4] = fdc->format_data[1];
1459               fdc->nec765_result_bytes[5] = fdc->format_data[2];
1460               fdc->nec765_result_bytes[6] = fdc->format_data[3];
1461               nec765_setup_result_phase(device,7);
14381462            }
14391463            else
14401464            {
1441               nec765_format_track(machine);
1465               nec765_format_track(device);
14421466            }
14431467         }
14441468         break;
r3867r3868
14511475            UINT8 ddam;
14521476
14531477            ddam = 0;
1454            if (fdc.command == 0x09)
1478            if (fdc->command == 0x09)
14551479            {
14561480               ddam = 1;
14571481            }
14581482
14591483            /* write data to disc */
1460            floppy_drive_write_sector_data(current_image(machine), fdc.side, fdc.sector_id,nec765_data_buffer,nec765_n_to_bytes(fdc.nec765_command_bytes[5]),ddam);
1484            floppy_drive_write_sector_data(current_image(device), fdc->side, fdc->sector_id,fdc->data_buffer,nec765_n_to_bytes(fdc->nec765_command_bytes[5]),ddam);
14611485
1462            if (nec765_sector_count_complete(machine))
1486            if (nec765_sector_count_complete(device))
14631487            {
1464               nec765_increment_sector(machine);
1465               nec765_write_complete(machine);
1488               nec765_increment_sector(device);
1489               nec765_write_complete(device);
14661490            }
14671491            else
14681492            {
1469               nec765_increment_sector(machine);
1470               nec765_write_data(machine);
1493               nec765_increment_sector(device);
1494               nec765_write_data(device);
14711495            }
14721496         }
14731497         break;
r3867r3868
14801504            /* read all sectors? */
14811505
14821506            /* sector id == EOT */
1483            if (nec765_sector_count_complete(machine) || nec765_read_data_stop())
1507            if (nec765_sector_count_complete(device) || nec765_read_data_stop(device))
14841508             {
1485               nec765_read_complete(machine);
1509               nec765_read_complete(device);
14861510            }
14871511            else
14881512            {
1489               nec765_increment_sector(machine);
1490               nec765_read_data(machine);
1513               nec765_increment_sector(device);
1514               nec765_read_data(device);
14911515            }
14921516            }
14931517            break;
r3867r3868
14991523}
15001524
15011525
1502static int nec765_get_command_byte_count(void)
1526static int nec765_get_command_byte_count(const device_config *device)
15031527{
1504   fdc.command = fdc.nec765_command_bytes[0] & 0x01f;
1528   nec765_t *fdc = get_safe_token(device);
1529   fdc->command = fdc->nec765_command_bytes[0] & 0x01f;
15051530
1506   if (fdc.version==NEC765A)
1531   if (fdc->version==TYPE_NEC765A)
15071532   {
1508       return nec765_cmd_size[fdc.command];
1533       return nec765_cmd_size[fdc->command];
15091534    }
15101535   else
15111536   {
1512      if (fdc.version==SMC37C78)
1537      if (fdc->version==TYPE_SMC37C78)
15131538      {
1514         switch (fdc.command)
1539         switch (fdc->command)
15151540         {
15161541            /* version */
15171542            case 0x010:
r3867r3868
15401565            /* seek/relative seek are together! */
15411566
15421567            default:
1543               return nec765_cmd_size[fdc.command];
1568               return nec765_cmd_size[fdc->command];
15441569         }
15451570      }
15461571   }
15471572
1548   return nec765_cmd_size[fdc.command];
1573   return nec765_cmd_size[fdc->command];
15491574}
15501575
15511576
15521577
15531578
15541579
1555void nec765_update_state(running_machine *machine)
1580void nec765_update_state(const device_config *device)
15561581{
1557   switch (fdc.nec765_phase) {
1582   nec765_t *fdc = get_safe_token(device);
1583   switch (fdc->nec765_phase) {
15581584   case NEC765_RESULT_PHASE:
15591585      /* set data reg */
1560      fdc.nec765_data_reg = fdc.nec765_result_bytes[fdc.nec765_transfer_bytes_count];
1586      fdc->nec765_data_reg = fdc->nec765_result_bytes[fdc->nec765_transfer_bytes_count];
15611587
1562      if (fdc.nec765_transfer_bytes_count == 0)
1588      if (fdc->nec765_transfer_bytes_count == 0)
15631589      {
15641590         /* clear int for specific commands */
1565         switch (fdc.command) {
1591         switch (fdc->command) {
15661592         case 2:   /* read a track */
15671593         case 5:   /* write data */
15681594         case 6:   /* read data */
r3867r3868
15731599         case 17:   /* scan equal */
15741600         case 19:   /* scan low or equal */
15751601         case 29:   /* scan high or equal */
1576            nec765_set_int(machine, 0);
1602            nec765_set_int(device, 0);
15771603            break;
15781604
15791605         default:
r3867r3868
15821608      }
15831609
15841610      if (LOG_VERBOSE)
1585         logerror("NEC765: RESULT: %02x\n", fdc.nec765_data_reg);
1611         logerror("NEC765: RESULT: %02x\n", fdc->nec765_data_reg);
15861612
1587      fdc.nec765_transfer_bytes_count++;
1588      fdc.nec765_transfer_bytes_remaining--;
1613      fdc->nec765_transfer_bytes_count++;
1614      fdc->nec765_transfer_bytes_remaining--;
15891615
1590      if (fdc.nec765_transfer_bytes_remaining==0)
1616      if (fdc->nec765_transfer_bytes_remaining==0)
15911617      {
1592         nec765_idle();
1618         nec765_idle(device);
15931619      }
15941620      else
15951621      {
1596         nec765_set_data_request();
1622         nec765_set_data_request(device);
15971623      }
15981624      break;
15991625
16001626   case NEC765_EXECUTION_PHASE_READ:
16011627      /* setup data register */
1602      fdc.nec765_data_reg = fdc.execution_phase_data[fdc.nec765_transfer_bytes_count];
1603      fdc.nec765_transfer_bytes_count++;
1604      fdc.nec765_transfer_bytes_remaining--;
1628      fdc->nec765_data_reg = fdc->execution_phase_data[fdc->nec765_transfer_bytes_count];
1629      fdc->nec765_transfer_bytes_count++;
1630      fdc->nec765_transfer_bytes_remaining--;
16051631
16061632      if (LOG_EXTRA)
1607         logerror("EXECUTION PHASE READ: %02x\n", fdc.nec765_data_reg);
1633         logerror("EXECUTION PHASE READ: %02x\n", fdc->nec765_data_reg);
16081634
1609      if ((fdc.nec765_transfer_bytes_remaining==0) || (fdc.nec765_flags & NEC765_TC))
1635      if ((fdc->nec765_transfer_bytes_remaining==0) || (fdc->nec765_flags & NEC765_TC))
16101636      {
1611         timer_adjust_oneshot(fdc.command_timer, attotime_zero, 0);
1637         timer_adjust_oneshot(fdc->command_timer, attotime_zero, 0);
16121638      }
16131639      else
16141640      {
16151641         /* trigger int */
1616         nec765_setup_timed_data_request(machine,1);
1642         nec765_setup_timed_data_request(device,1);
16171643      }
16181644      break;
16191645
16201646   case NEC765_COMMAND_PHASE_FIRST_BYTE:
1621      fdc.FDC_main |= 0x10;                      /* set BUSY */
1647      fdc->FDC_main |= 0x10;                      /* set BUSY */
16221648
16231649      if (LOG_VERBOSE)
1624         logerror("nec765(): pc=0x%08x command=0x%02x\n", cpu_get_pc(machine->cpu[0]), fdc.nec765_data_reg);
1650         logerror("nec765(): pc=0x%08x command=0x%02x\n", cpu_get_pc(device->machine->cpu[0]), fdc->nec765_data_reg);
16251651
16261652      /* seek in progress? */
1627      if (fdc.nec765_flags & NEC765_SEEK_ACTIVE)
1653      if (fdc->nec765_flags & NEC765_SEEK_ACTIVE)
16281654      {
16291655         /* any command results in a invalid - I think that seek, recalibrate and
16301656         sense interrupt status may work*/
1631         fdc.nec765_data_reg = 0;
1657         fdc->nec765_data_reg = 0;
16321658      }
16331659
1634      fdc.nec765_command_bytes[0] = fdc.nec765_data_reg;
1660      fdc->nec765_command_bytes[0] = fdc->nec765_data_reg;
16351661
1636      fdc.nec765_transfer_bytes_remaining = nec765_get_command_byte_count();
1662      fdc->nec765_transfer_bytes_remaining = nec765_get_command_byte_count(device);
16371663
1638      fdc.nec765_transfer_bytes_count = 1;
1639      fdc.nec765_transfer_bytes_remaining--;
1664      fdc->nec765_transfer_bytes_count = 1;
1665      fdc->nec765_transfer_bytes_remaining--;
16401666
1641      if (fdc.nec765_transfer_bytes_remaining==0)
1667      if (fdc->nec765_transfer_bytes_remaining==0)
16421668      {
1643         nec765_setup_command(machine);
1669         nec765_setup_command(device);
16441670      }
16451671      else
16461672      {
16471673         /* request more data */
1648         nec765_set_data_request();
1649         fdc.nec765_phase = NEC765_COMMAND_PHASE_BYTES;
1674         nec765_set_data_request(device);
1675         fdc->nec765_phase = NEC765_COMMAND_PHASE_BYTES;
16501676      }
16511677        break;
16521678
16531679    case NEC765_COMMAND_PHASE_BYTES:
16541680      if (LOG_VERBOSE)
1655         logerror("nec765(): pc=0x%08x command=0x%02x\n", cpu_get_pc(machine->cpu[0]), fdc.nec765_data_reg);
1681         logerror("nec765(): pc=0x%08x command=0x%02x\n", cpu_get_pc(device->machine->cpu[0]), fdc->nec765_data_reg);
16561682
1657      fdc.nec765_command_bytes[fdc.nec765_transfer_bytes_count] = fdc.nec765_data_reg;
1658      fdc.nec765_transfer_bytes_count++;
1659      fdc.nec765_transfer_bytes_remaining--;
1683      fdc->nec765_command_bytes[fdc->nec765_transfer_bytes_count] = fdc->nec765_data_reg;
1684      fdc->nec765_transfer_bytes_count++;
1685      fdc->nec765_transfer_bytes_remaining--;
16601686
1661      if (fdc.nec765_transfer_bytes_remaining==0)
1687      if (fdc->nec765_transfer_bytes_remaining==0)
16621688      {
1663         nec765_setup_command(machine);
1689         nec765_setup_command(device);
16641690      }
16651691      else
16661692      {
16671693         /* request more data */
1668         nec765_set_data_request();
1694         nec765_set_data_request(device);
16691695      }
16701696      break;
16711697
16721698    case NEC765_EXECUTION_PHASE_WRITE:
1673      fdc.execution_phase_data[fdc.nec765_transfer_bytes_count]=fdc.nec765_data_reg;
1674      fdc.nec765_transfer_bytes_count++;
1675      fdc.nec765_transfer_bytes_remaining--;
1699      fdc->execution_phase_data[fdc->nec765_transfer_bytes_count]=fdc->nec765_data_reg;
1700      fdc->nec765_transfer_bytes_count++;
1701      fdc->nec765_transfer_bytes_remaining--;
16761702
1677      if ((fdc.nec765_transfer_bytes_remaining == 0) || (fdc.nec765_flags & NEC765_TC))
1703      if ((fdc->nec765_transfer_bytes_remaining == 0) || (fdc->nec765_flags & NEC765_TC))
16781704      {
1679         timer_adjust_oneshot(fdc.command_timer, attotime_zero, 0);
1705         timer_adjust_oneshot(fdc->command_timer, attotime_zero, 0);
16801706      }
16811707      else
16821708      {
1683         nec765_setup_timed_data_request(machine,1);
1709         nec765_setup_timed_data_request(device,1);
16841710      }
16851711      break;
16861712   }
16871713}
16881714
16891715
1690READ8_HANDLER(nec765_data_r)
1716READ8_DEVICE_HANDLER(nec765_data_r)
16911717{
1692   if ((fdc.FDC_main & 0x0c0) == 0x0c0)
1718   nec765_t *fdc = get_safe_token(device);
1719   
1720   if ((fdc->FDC_main & 0x0c0) == 0x0c0)
16931721   {
16941722      if (
1695         (fdc.nec765_phase == NEC765_EXECUTION_PHASE_READ) ||
1696         (fdc.nec765_phase == NEC765_EXECUTION_PHASE_WRITE))
1723         (fdc->nec765_phase == NEC765_EXECUTION_PHASE_READ) ||
1724         (fdc->nec765_phase == NEC765_EXECUTION_PHASE_WRITE))
16971725      {
16981726
16991727         /* reading the data byte clears the interrupt */
1700         nec765_set_int(space->machine,CLEAR_LINE);
1728         nec765_set_int(device,CLEAR_LINE);
17011729      }
17021730
17031731      /* reset data request */
1704      nec765_clear_data_request();
1732      nec765_clear_data_request(device);
17051733
17061734      /* update state */
1707      nec765_update_state(space->machine);
1735      nec765_update_state(device);
17081736   }
17091737
17101738   if (LOG_EXTRA)
1711      logerror("DATA R: %02x\n", fdc.nec765_data_reg);
1739      logerror("DATA R: %02x\n", fdc->nec765_data_reg);
17121740
1713   return fdc.nec765_data_reg;
1741   return fdc->nec765_data_reg;
17141742}
17151743
1716WRITE8_HANDLER(nec765_data_w)
1744WRITE8_DEVICE_HANDLER(nec765_data_w)
17171745{
1746   nec765_t *fdc = get_safe_token(device);
1747   
17181748   if (LOG_EXTRA)
17191749      logerror("DATA W: %02x\n", data);
17201750
17211751   /* write data to data reg */
1722   fdc.nec765_data_reg = data;
1752   fdc->nec765_data_reg = data;
17231753
1724   if ((fdc.FDC_main & 0x0c0)==0x080)
1754   if ((fdc->FDC_main & 0x0c0)==0x080)
17251755   {
17261756      if (
1727         (fdc.nec765_phase == NEC765_EXECUTION_PHASE_READ) ||
1728         (fdc.nec765_phase == NEC765_EXECUTION_PHASE_WRITE))
1757         (fdc->nec765_phase == NEC765_EXECUTION_PHASE_READ) ||
1758         (fdc->nec765_phase == NEC765_EXECUTION_PHASE_WRITE))
17291759      {
17301760
17311761         /* reading the data byte clears the interrupt */
1732         nec765_set_int(space->machine, CLEAR_LINE);
1762         nec765_set_int(device, CLEAR_LINE);
17331763      }
17341764
17351765      /* reset data request */
1736      nec765_clear_data_request();
1766      nec765_clear_data_request(device);
17371767
17381768      /* update state */
1739      nec765_update_state(space->machine);
1769      nec765_update_state(device);
17401770   }
17411771}
17421772
1743static void nec765_setup_invalid(running_machine *machine)
1773static void nec765_setup_invalid(const device_config *device)
17441774{
1745   fdc.command = 0;
1746   fdc.nec765_result_bytes[0] = 0x080;
1747   nec765_setup_result_phase(machine,1);
1775   nec765_t *fdc = get_safe_token(device);
1776   
1777   fdc->command = 0;
1778   fdc->nec765_result_bytes[0] = 0x080;
1779   nec765_setup_result_phase(device,1);
17481780}
17491781
1750static void nec765_setup_command(running_machine *machine)
1782static void nec765_setup_command(const device_config *device)
17511783{
1784   nec765_t *fdc = get_safe_token(device);
1785   
17521786   static const char *const commands[] =
17531787   {
17541788      NULL,                  /* [00] */
r3867r3868
17741808      "Lock"                  /* [14] */
17751809   };
17761810
1777   const device_config *img = current_image(machine);
1811   const device_config *img = current_image(device);
17781812   const char *cmd = NULL;
17791813   chrn_id id;
17801814
17811815   /* if not in dma mode set execution phase bit */
1782   if (!(fdc.nec765_flags & NEC765_DMA_MODE))
1816   if (!(fdc->nec765_flags & NEC765_DMA_MODE))
17831817   {
1784        fdc.FDC_main |= 0x020;              /* execution phase */
1818        fdc->FDC_main |= 0x020;              /* execution phase */
17851819   }
17861820
17871821   if (LOG_COMMAND)
17881822   {
1789      if ((fdc.nec765_command_bytes[0] & 0x1f) < sizeof(commands) / sizeof(commands[0]))
1790         cmd = commands[fdc.nec765_command_bytes[0] & 0x1f];
1823      if ((fdc->nec765_command_bytes[0] & 0x1f) < sizeof(commands) / sizeof(commands[0]))
1824         cmd = commands[fdc->nec765_command_bytes[0] & 0x1f];
17911825      logerror("nec765_setup_command(): Setting up command 0x%02X (%s)\n",
1792         fdc.nec765_command_bytes[0] & 0x1f, cmd ? cmd : "???");
1826         fdc->nec765_command_bytes[0] & 0x1f, cmd ? cmd : "???");
17931827   }
17941828
1795   switch (fdc.nec765_command_bytes[0] & 0x1f)
1829   switch (fdc->nec765_command_bytes[0] & 0x1f)
17961830   {
17971831      case 0x03:      /* specify */
17981832         /* setup step rate */
1799         fdc.srt_in_ms = 16-((fdc.nec765_command_bytes[1]>>4) & 0x0f);
1833         fdc->srt_in_ms = 16-((fdc->nec765_command_bytes[1]>>4) & 0x0f);
18001834
1801         fdc.nec765_flags &= ~NEC765_DMA_MODE;
1835         fdc->nec765_flags &= ~NEC765_DMA_MODE;
18021836
1803         if ((fdc.nec765_command_bytes[2] & 0x01)==0)
1837         if ((fdc->nec765_command_bytes[2] & 0x01)==0)
18041838         {
1805            fdc.nec765_flags |= NEC765_DMA_MODE;
1839            fdc->nec765_flags |= NEC765_DMA_MODE;
18061840         }
18071841
1808         nec765_idle();
1842         nec765_idle(device);
18091843         break;
18101844
18111845      case 0x04:  /* sense drive status */
1812         nec765_setup_drive_and_side();
1846         nec765_setup_drive_and_side(device);
18131847
1814         fdc.nec765_status[3] = fdc.drive | (fdc.side<<2);
1848         fdc->nec765_status[3] = fdc->drive | (fdc->side<<2);
18151849
18161850         if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_DISK_WRITE_PROTECTED))
18171851         {
1818            fdc.nec765_status[3] |= 0x40;
1852            fdc->nec765_status[3] |= 0x40;
18191853         }
18201854
18211855         if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
18221856         {
1823            fdc.nec765_status[3] |= 0x20;
1857            fdc->nec765_status[3] |= 0x20;
18241858         }
18251859
18261860         if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_HEAD_AT_TRACK_0))
18271861         {
1828            fdc.nec765_status[3] |= 0x10;
1862            fdc->nec765_status[3] |= 0x10;
18291863         }
18301864
1831         fdc.nec765_status[3] |= 0x08;
1865         fdc->nec765_status[3] |= 0x08;
18321866
18331867         /* two side and fault not set but should be? */
1834         fdc.nec765_result_bytes[0] = fdc.nec765_status[3];
1835         nec765_setup_result_phase(machine,1);
1868         fdc->nec765_result_bytes[0] = fdc->nec765_status[3];
1869         nec765_setup_result_phase(device,1);
18361870         break;
18371871
18381872      case 0x07:          /* recalibrate */
1839         nec765_seek_setup(machine, 1);
1873         nec765_seek_setup(device, 1);
18401874         break;
18411875
18421876      case 0x0f:          /* seek */
1843         nec765_seek_setup(machine, 0);
1877         nec765_seek_setup(device, 0);
18441878         break;
18451879
18461880      case 0x0a:      /* read id */
1847         nec765_setup_drive_and_side();
1881         nec765_setup_drive_and_side(device);
18481882
1849         fdc.nec765_status[0] = fdc.drive | (fdc.side<<2);
1850         fdc.nec765_status[1] = 0;
1851         fdc.nec765_status[2] = 0;
1883         fdc->nec765_status[0] = fdc->drive | (fdc->side<<2);
1884         fdc->nec765_status[1] = 0;
1885         fdc->nec765_status[2] = 0;
18521886
18531887         /* drive ready? */
18541888         if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_READY))
r3867r3868
18711905               do
18721906               {
18731907                  /* get next id from disc */
1874                  if (floppy_drive_get_next_id(img, fdc.side, &id))
1908                  if (floppy_drive_get_next_id(img, fdc->side, &id))
18751909                  {
18761910                     /* got an id - quit */
18771911                     break;
r3867r3868
18861920               while (index_count!=2);
18871921
18881922               /* at this point, we have seen a id or two index pulses have occured! */
1889               fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
1890               fdc.nec765_result_bytes[1] = fdc.nec765_status[1];
1891               fdc.nec765_result_bytes[2] = fdc.nec765_status[2];
1892               fdc.nec765_result_bytes[3] = id.C; /* C */
1893               fdc.nec765_result_bytes[4] = id.H; /* H */
1894               fdc.nec765_result_bytes[5] = id.R; /* R */
1895               fdc.nec765_result_bytes[6] = id.N; /* N */
1923               fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
1924               fdc->nec765_result_bytes[1] = fdc->nec765_status[1];
1925               fdc->nec765_result_bytes[2] = fdc->nec765_status[2];
1926               fdc->nec765_result_bytes[3] = id.C; /* C */
1927               fdc->nec765_result_bytes[4] = id.H; /* H */
1928               fdc->nec765_result_bytes[5] = id.R; /* R */
1929               fdc->nec765_result_bytes[6] = id.N; /* N */
18961930
1897               nec765_setup_result_phase(machine,7);
1931               nec765_setup_result_phase(device,7);
18981932            }
18991933            else
19001934            {
r3867r3868
19091943            /* what are id values when drive not ready? */
19101944
19111945            /* not ready, abnormal termination */
1912            fdc.nec765_status[0] |= (1<<3) | (1<<6);
1913            fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
1914            fdc.nec765_result_bytes[1] = fdc.nec765_status[1];
1915            fdc.nec765_result_bytes[2] = fdc.nec765_status[2];
1916            fdc.nec765_result_bytes[3] = 0; /* C */
1917            fdc.nec765_result_bytes[4] = 0; /* H */
1918            fdc.nec765_result_bytes[5] = 0; /* R */
1919            fdc.nec765_result_bytes[6] = 0; /* N */
1946            fdc->nec765_status[0] |= (1<<3) | (1<<6);
1947            fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
1948            fdc->nec765_result_bytes[1] = fdc->nec765_status[1];
1949            fdc->nec765_result_bytes[2] = fdc->nec765_status[2];
1950            fdc->nec765_result_bytes[3] = 0; /* C */
1951            fdc->nec765_result_bytes[4] = 0; /* H */
1952            fdc->nec765_result_bytes[5] = 0; /* R */
1953            fdc->nec765_result_bytes[6] = 0; /* N */
19201954         }
19211955         break;
19221956
19231957
19241958      case 0x08: /* sense interrupt status */
19251959         /* interrupt pending? */
1926         if (fdc.nec765_flags & NEC765_INT)
1960         if (fdc->nec765_flags & NEC765_INT)
19271961         {
19281962            /* yes. Clear int */
1929            nec765_set_int(machine, CLEAR_LINE);
1963            nec765_set_int(device, CLEAR_LINE);
19301964
19311965            /* clear drive seek bits */
1932            fdc.FDC_main &= ~(1 | 2 | 4 | 8);
1966            fdc->FDC_main &= ~(1 | 2 | 4 | 8);
19331967
19341968            /* return status */
1935            fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
1969            fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
19361970            /* return pcn */
1937            fdc.nec765_result_bytes[1] = fdc.pcn[fdc.drive];
1971            fdc->nec765_result_bytes[1] = fdc->pcn[fdc->drive];
19381972
19391973            /* return result */
1940            nec765_setup_result_phase(machine,2);
1974            nec765_setup_result_phase(device,2);
19411975         }
19421976         else
19431977         {
1944            if(fdc.version == NEC72065 && (fdc.FDC_main & 0x0f) == 0x00)
1978            if(fdc->version == TYPE_NEC72065 && (fdc->FDC_main & 0x0f) == 0x00)
19451979            {  // based on XM6
1946               nec765_setup_invalid(machine);
1980               nec765_setup_invalid(device);
19471981            }
19481982            else
19491983            {
19501984               /* no int */
1951               fdc.nec765_result_bytes[0] = 0x80;
1985               fdc->nec765_result_bytes[0] = 0x80;
19521986               /* return pcn */
1953               fdc.nec765_result_bytes[1] = fdc.pcn[fdc.drive];
1987               fdc->nec765_result_bytes[1] = fdc->pcn[fdc->drive];
19541988
19551989               /* return result */
1956               nec765_setup_result_phase(machine,2);
1990               nec765_setup_result_phase(device,2);
19571991            }
19581992         }
19591993         break;
19601994
19611995      case 0x06:  /* read data */
1962         nec765_setup_drive_and_side();
1996         nec765_setup_drive_and_side(device);
19631997
1964         fdc.nec765_status[0] = fdc.drive | (fdc.side<<2);
1965         fdc.nec765_status[1] = 0;
1966         fdc.nec765_status[2] = 0;
1998         fdc->nec765_status[0] = fdc->drive | (fdc->side<<2);
1999         fdc->nec765_status[1] = 0;
2000         fdc->nec765_status[2] = 0;
19672001
1968         nec765_read_data(machine);
2002         nec765_read_data(device);
19692003         break;
19702004
19712005      case 0x0c:
19722006         /* read deleted data */
1973         nec765_setup_drive_and_side();
2007         nec765_setup_drive_and_side(device);
19742008
1975         fdc.nec765_status[0] = fdc.drive | (fdc.side<<2);
1976         fdc.nec765_status[1] = 0;
1977         fdc.nec765_status[2] = 0;
2009         fdc->nec765_status[0] = fdc->drive | (fdc->side<<2);
2010         fdc->nec765_status[1] = 0;
2011         fdc->nec765_status[2] = 0;
19782012
19792013         /* .. for now */
1980         nec765_read_data(machine);
2014         nec765_read_data(device);
19812015         break;
19822016
19832017      case 0x09:
19842018         /* write deleted data */
1985         nec765_setup_drive_and_side();
2019         nec765_setup_drive_and_side(device);
19862020
1987         fdc.nec765_status[0] = fdc.drive | (fdc.side<<2);
1988         fdc.nec765_status[1] = 0;
1989         fdc.nec765_status[2] = 0;
2021         fdc->nec765_status[0] = fdc->drive | (fdc->side<<2);
2022         fdc->nec765_status[1] = 0;
2023         fdc->nec765_status[2] = 0;
19902024
19912025         /* ... for now */
1992         nec765_write_data(machine);
2026         nec765_write_data(device);
19932027         break;
19942028
19952029      case 0x02:
19962030         /* read a track */
1997         nec765_setup_drive_and_side();
2031         nec765_setup_drive_and_side(device);
19982032
1999         fdc.nec765_status[0] = fdc.drive | (fdc.side<<2);
2000         fdc.nec765_status[1] = 0;
2001         fdc.nec765_status[2] = 0;
2033         fdc->nec765_status[0] = fdc->drive | (fdc->side<<2);
2034         fdc->nec765_status[1] = 0;
2035         fdc->nec765_status[2] = 0;
20022036
2003         fdc.nec765_status[0] |= NEC765_ST1_NO_DATA;
2037         fdc->nec765_status[0] |= NEC765_ST1_NO_DATA;
20042038
20052039         /* wait for index */
20062040         do
20072041         {
20082042            /* get next id from disc */
2009            floppy_drive_get_next_id(img, fdc.side,&id);
2043            floppy_drive_get_next_id(img, fdc->side,&id);
20102044         }
20112045         while ((floppy_drive_get_flag_state(img, FLOPPY_DRIVE_INDEX))==0);
20122046
2013         fdc.sector_counter = 0;
2047         fdc->sector_counter = 0;
20142048
2015         nec765_read_a_track(machine);
2049         nec765_read_a_track(device);
20162050         break;
20172051
20182052      case 0x05:  /* write data */
2019         nec765_setup_drive_and_side();
2053         nec765_setup_drive_and_side(device);
20202054
2021         fdc.nec765_status[0] = fdc.drive | (fdc.side<<2);
2022         fdc.nec765_status[1] = 0;
2023         fdc.nec765_status[2] = 0;
2055         fdc->nec765_status[0] = fdc->drive | (fdc->side<<2);
2056         fdc->nec765_status[1] = 0;
2057         fdc->nec765_status[2] = 0;
20242058
2025         nec765_write_data(machine);
2059         nec765_write_data(device);
20262060         break;
20272061
20282062      case 0x0d:   /* format a track */
2029         nec765_setup_drive_and_side();
2063         nec765_setup_drive_and_side(device);
20302064
2031         fdc.nec765_status[0] = fdc.drive | (fdc.side<<2);
2032         fdc.nec765_status[1] = 0;
2033         fdc.nec765_status[2] = 0;
2065         fdc->nec765_status[0] = fdc->drive | (fdc->side<<2);
2066         fdc->nec765_status[1] = 0;
2067         fdc->nec765_status[2] = 0;
20342068
2035         fdc.sector_counter = 0;
2069         fdc->sector_counter = 0;
20362070
2037         nec765_format_track(machine);
2071         nec765_format_track(device);
20382072         break;
20392073
20402074      default:   /* invalid */
2041         switch (fdc.version)
2075         switch (fdc->version)
20422076         {
2043            case NEC765A:
2044            case NEC72065:
2045               nec765_setup_invalid(machine);
2077            case TYPE_NEC765A:
2078            case TYPE_NEC72065:
2079               nec765_setup_invalid(device);
20462080               break;
20472081
2048            case NEC765B:
2082            case TYPE_NEC765B:
20492083               /* from nec765b data sheet */
2050               if ((fdc.nec765_command_bytes[0] & 0x01f)==0x010)
2084               if ((fdc->nec765_command_bytes[0] & 0x01f)==0x010)
20512085               {
20522086                  /* version */
2053                  fdc.nec765_status[0] = 0x090;
2054                  fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
2055                  nec765_setup_result_phase(machine,1);
2087                  fdc->nec765_status[0] = 0x090;
2088                  fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
2089                  nec765_setup_result_phase(device,1);
20562090               }
20572091               break;
20582092
2059            case SMC37C78:
2093            case TYPE_SMC37C78:
20602094               /* TO BE COMPLETED!!! !*/
2061               switch (fdc.nec765_command_bytes[0] & 0x1f)
2095               switch (fdc->nec765_command_bytes[0] & 0x1f)
20622096               {
20632097                  case 0x10:      /* version */
2064                     fdc.nec765_status[0] = 0x90;
2065                     fdc.nec765_result_bytes[0] = fdc.nec765_status[0];
2066                     nec765_setup_result_phase(machine,1);
2098                     fdc->nec765_status[0] = 0x90;
2099                     fdc->nec765_result_bytes[0] = fdc->nec765_status[0];
2100                     nec765_setup_result_phase(device,1);
20672101                     break;
20682102
20692103                  case 0x13:      /* configure */
2070                     nec765_idle();
2104                     nec765_idle(device);
20712105                     break;
20722106
20732107                  case 0x0e:      /* dump reg */
2074                     fdc.nec765_result_bytes[0] = fdc.pcn[0];
2075                     fdc.nec765_result_bytes[1] = fdc.pcn[1];
2076                     fdc.nec765_result_bytes[2] = fdc.pcn[2];
2077                     fdc.nec765_result_bytes[3] = fdc.pcn[3];
2108                     fdc->nec765_result_bytes[0] = fdc->pcn[0];
2109                     fdc->nec765_result_bytes[1] = fdc->pcn[1];
2110                     fdc->nec765_result_bytes[2] = fdc->pcn[2];
2111                     fdc->nec765_result_bytes[3] = fdc->pcn[3];
20782112
2079                     nec765_setup_result_phase(machine,10);
2113                     nec765_setup_result_phase(device,10);
20802114                     break;
20812115
20822116                  case 0x12:      /* perpendicular mode */
2083                     nec765_idle();
2117                     nec765_idle(device);
20842118                     break;
20852119
20862120                  case 0x14:      /* lock */
2087                     nec765_setup_result_phase(machine,1);
2121                     nec765_setup_result_phase(device,1);
20882122                     break;
20892123               }
20902124               break;
r3867r3868
20942128
20952129
20962130/* dma acknowledge write */
2097WRITE8_HANDLER(nec765_dack_w)
2131WRITE8_DEVICE_HANDLER(nec765_dack_w)
20982132{
20992133   /* clear request */
2100   nec765_set_dma_drq(space->machine, CLEAR_LINE);
2134   nec765_set_dma_drq(device, CLEAR_LINE);
21012135
21022136   /* write data */
2103   nec765_data_w(space, offset, data);
2137   nec765_data_w(device, offset, data);
21042138}
21052139
2106READ8_HANDLER(nec765_dack_r)
2140READ8_DEVICE_HANDLER(nec765_dack_r)
21072141{
21082142   /* clear data request */
2109   nec765_set_dma_drq(space->machine,CLEAR_LINE);
2143   nec765_set_dma_drq(device,CLEAR_LINE);
21102144
21112145   /* read data */
2112   return nec765_data_r(space, offset);
2146   return nec765_data_r(device, offset);
21132147}
21142148
21152149
2116void nec765_reset(running_machine *machine, int offset)
2150void nec765_reset(const device_config *device, int offset)
21172151{
2152   nec765_t *fdc = get_safe_token(device);
2153   
21182154   /* nec765 in idle state - ready to accept commands */
2119   nec765_idle();
2155   nec765_idle(device);
21202156
21212157   /* set int low */
2122   nec765_set_int(machine, 0);
2158   nec765_set_int(device, 0);
21232159   /* set dma drq output */
2124   nec765_set_dma_drq(machine,0);
2160   nec765_set_dma_drq(device,0);
21252161
21262162   /* tandy 100hx assumes that after NEC is reset, it is in DMA mode */
2127   fdc.nec765_flags |= NEC765_DMA_MODE;
2163   fdc->nec765_flags |= NEC765_DMA_MODE;
21282164
21292165   /* if ready input is set during reset generate an int */
2130   if (fdc.nec765_flags & NEC765_FDD_READY)
2166   if (fdc->nec765_flags & NEC765_FDD_READY)
21312167   {
21322168      int i;
21332169      int a_drive_is_ready;
21342170
2135      fdc.nec765_status[0] = 0x080 | 0x040;
2171      fdc->nec765_status[0] = 0x080 | 0x040;
21362172
21372173      /* for the purpose of pc-xt. If any of the drives have a disk inserted,
2138      do not set not-ready - need to check with pc_fdc.c whether all drives
2174      do not set not-ready - need to check with pc_fdc->c whether all drives
21392175      are checked or only the drive selected with the drive select bits?? */
21402176
21412177      a_drive_is_ready = 0;
2142      for (i = 0; i < device_count(machine, IO_FLOPPY); i++)
2178      for (i = 0; i < device_count(device->machine, IO_FLOPPY); i++)
21432179      {
21442180         if (image_exists(image_from_devtype_and_index(IO_FLOPPY, i)))
21452181         {
r3867r3868
21492185
21502186      }
21512187
2152      if (!a_drive_is_ready && fdc.rdy_pin == NEC765_RDY_PIN_CONNECTED )
2188      if (!a_drive_is_ready && fdc->intf->rdy_pin == NEC765_RDY_PIN_CONNECTED )
21532189      {
2154         fdc.nec765_status[0] |= 0x08;
2190         fdc->nec765_status[0] |= 0x08;
21552191      }
21562192
2157      nec765_set_int(machine, 1);
2193      nec765_set_int(device, 1);
21582194   }
21592195}
21602196
2161void nec765_set_reset_state(running_machine *machine, int state)
2197void nec765_set_reset_state(const device_config *device, int state)
21622198{
2199   nec765_t *fdc = get_safe_token(device);
2200   
21632201   int flags;
21642202
21652203   /* get previous reset state */
2166   flags = fdc.nec765_flags;
2204   flags = fdc->nec765_flags;
21672205
21682206   /* set new reset state */
21692207   /* clear reset */
2170   fdc.nec765_flags &= ~NEC765_RESET;
2208   fdc->nec765_flags &= ~NEC765_RESET;
21712209
21722210   /* reset */
21732211   if (state)
21742212   {
2175      fdc.nec765_flags |= NEC765_RESET;
2213      fdc->nec765_flags |= NEC765_RESET;
21762214
2177      nec765_set_int(machine, 0);
2215      nec765_set_int(device, 0);
21782216   }
21792217
21802218   /* reset changed state? */
2181   if (((flags^fdc.nec765_flags) & NEC765_RESET)!=0)
2219   if (((flags^fdc->nec765_flags) & NEC765_RESET)!=0)
21822220   {
21832221      /* yes */
21842222
21852223      /* no longer reset */
2186      if ((fdc.nec765_flags & NEC765_RESET)==0)
2224      if ((fdc->nec765_flags & NEC765_RESET)==0)
21872225      {
21882226         /* reset nec */
2189         nec765_reset(machine, 0);
2227         nec765_reset(device, 0);
21902228      }
21912229   }
21922230}
21932231
21942232
2195void   nec765_set_ready_state(int state)
2233void nec765_set_ready_state(const device_config *device, int state)
21962234{
2235   nec765_t *fdc = get_safe_token(device);
2236   
21972237   /* clear ready state */
2198   fdc.nec765_flags &= ~NEC765_FDD_READY;
2238   fdc->nec765_flags &= ~NEC765_FDD_READY;
21992239
22002240   if (state)
22012241   {
2202      fdc.nec765_flags |= NEC765_FDD_READY;
2242      fdc->nec765_flags |= NEC765_FDD_READY;
22032243   }
22042244}
2245
2246
2247/* Device Interface */
2248
2249static device_start_err common_start(const device_config *device, int device_type)
2250{
2251   nec765_t *fdc = get_safe_token(device);
2252   // validate arguments
2253
2254   assert(device != NULL);
2255   assert(device->tag != NULL);
2256   assert(strlen(device->tag) < 20);
2257   assert(device->static_config != NULL);
2258   
2259   fdc->intf = device->static_config;
2260
2261   fdc->version = device_type;
2262   fdc->timer = timer_alloc(device->machine, nec765_timer_callback, (void*)device);
2263   fdc->seek_timer = timer_alloc(device->machine, nec765_seek_timer_callback, (void*)device);
2264   fdc->command_timer = timer_alloc(device->machine, nec765_continue_command, (void*)device);
2265
2266   fdc->nec765_flags &= NEC765_FDD_READY;
2267   fdc->data_buffer = auto_malloc(32*1024);
2268
2269
2270   // register for state saving
2271   //state_save_register_item(device->machine, "nec765", device->tag, 0, nec765->number);
2272   return DEVICE_START_OK;
2273}
2274
2275static DEVICE_START( nec765a )
2276{
2277   return common_start(device, TYPE_NEC765A);
2278}
2279
2280static DEVICE_START( nec765b )
2281{
2282   return common_start(device, TYPE_NEC765B);
2283}
2284
2285static DEVICE_START( smc37c78 )
2286{
2287   return common_start(device, TYPE_SMC37C78);
2288}
2289
2290static DEVICE_START( nec72065 )
2291{
2292   return common_start(device, TYPE_NEC72065);
2293}
2294
2295static DEVICE_RESET( nec765 )
2296{
2297   int i;
2298     
2299   for (i = 0; i < device_count(device->machine, IO_FLOPPY); i++) {
2300      const device_config *img = image_from_devtype_and_index(IO_FLOPPY, i);
2301      floppy_drive_set_controller(img, device);
2302      floppy_drive_set_ready_state_change_callback(img, nec765_set_ready_change_callback);
2303   }
2304   
2305   nec765_reset(device,0);
2306}
2307
2308static DEVICE_SET_INFO( nec765 )
2309{
2310   switch (state)
2311   {
2312      /* no parameters to set */
2313   }
2314}
2315
2316DEVICE_GET_INFO( nec765a )
2317{
2318   switch (state)
2319   {
2320      /* --- the following bits of info are returned as 64-bit signed integers --- */
2321      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(nec765_t);               break;
2322      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
2323      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
2324
2325      /* --- the following bits of info are returned as pointers to data or functions --- */
2326      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(nec765); break;
2327      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(nec765a);   break;
2328      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
2329      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(nec765);   break;
2330
2331      /* --- the following bits of info are returned as NULL-terminated strings --- */
2332      case DEVINFO_STR_NAME:                     info->s = "NEC765A";                  break;
2333      case DEVINFO_STR_FAMILY:                  info->s = "NEC765A";                  break;
2334      case DEVINFO_STR_VERSION:                  info->s = "1.0";                     break;
2335      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                     break;
2336      case DEVINFO_STR_CREDITS:                  info->s = "Copyright MESS Team";         break;
2337   }
2338}
2339
2340
2341DEVICE_GET_INFO( nec765b )
2342{
2343   switch (state)
2344   {
2345      /* --- the following bits of info are returned as NULL-terminated strings --- */
2346      case DEVINFO_STR_NAME:                     info->s = "NEC765B";            break;
2347
2348      /* --- the following bits of info are returned as pointers to data or functions --- */
2349      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(nec765b);   break;
2350
2351      default:                               DEVICE_GET_INFO_CALL(nec765a);            break;
2352   }
2353}
2354
2355DEVICE_GET_INFO( smc37c78 )
2356{
2357   switch (state)
2358   {
2359      /* --- the following bits of info are returned as NULL-terminated strings --- */
2360      case DEVINFO_STR_NAME:                     info->s = "SMC37C78";            break;
2361
2362      /* --- the following bits of info are returned as pointers to data or functions --- */
2363      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(smc37c78);   break;
2364
2365      default:                               DEVICE_GET_INFO_CALL(nec765a);            break;
2366   }
2367}
2368
2369DEVICE_GET_INFO( nec72065 )
2370{
2371   switch (state)
2372   {
2373      /* --- the following bits of info are returned as NULL-terminated strings --- */
2374      case DEVINFO_STR_NAME:                     info->s = "NEC72065";            break;
2375
2376      /* --- the following bits of info are returned as pointers to data or functions --- */
2377      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(nec72065);   break;
2378
2379      default:                               DEVICE_GET_INFO_CALL(nec765a);            break;
2380   }
2381}
src/mess/machine/nec765.h
r3867r3868
1111
1212#include "devices/flopdrv.h"
1313
14/***************************************************************************
15    MACROS
16***************************************************************************/
1417
15/* supported versions */
16typedef enum
17{
18   NEC765A = 0,
19   NEC765B = 1,
20   SMC37C78 = 2,
21   NEC72065 = 3
22} NEC765_VERSION;
18#define NEC765A      DEVICE_GET_INFO_NAME(nec765a)
19#define NEC765B      DEVICE_GET_INFO_NAME(nec765b)
20#define SMC37C78   DEVICE_GET_INFO_NAME(smc37c78)
21#define NEC72065   DEVICE_GET_INFO_NAME(nec72065)
2322
23/***************************************************************************
24    TYPE DEFINITIONS
25***************************************************************************/
26
2427/* RDY pin connected state */
2528typedef enum
2629{
r3867r3868
3134#define NEC765_DAM_DELETED_DATA 0x0f8
3235#define NEC765_DAM_DATA 0x0fb
3336
37typedef void (*nec765_interrupt_func)(const device_config *device, int state);
38#define NEC765_INTERRUPT(name)   void name(const device_config *device, int state )
39
40typedef void (*nec765_dma_drq_func)(const device_config *device, int state,int read_write);
41#define NEC765_DMA_REQUEST(name)   void name(const device_config *device, int state,int read_write )
42
43typedef const device_config *(*nec765_get_image_func)(const device_config *device, int floppy_index);
44#define NEC765_GET_IMAGE(name)   const device_config *name(const device_config *device, int floppy_index )
45
46
3447typedef struct nec765_interface
3548{
3649   /* interrupt issued */
37   void   (*interrupt)(running_machine *machine,int state);
50   nec765_interrupt_func interrupt;
3851
3952   /* dma data request */
40   void   (*dma_drq)(running_machine *machine,int state,int read_write);
53   nec765_dma_drq_func dma_drq;
4154
4255   /* image lookup */
43   const device_config *(*get_image)(running_machine *machine,int floppy_index);
56   nec765_get_image_func get_image;
57   
58   NEC765_RDY_PIN rdy_pin;   
4459} nec765_interface;
4560
46/* init nec765 interface */
47void nec765_init(running_machine *machine, const nec765_interface *iface, NEC765_VERSION version, NEC765_RDY_PIN rdy_pin);
48/* set nec765 terminal count input state */
49void nec765_set_tc_state(running_machine *machine, int);
50/* set nec765 ready input*/
51void nec765_set_ready_state(int);
5261
53void nec765_idle(void);
62/***************************************************************************
63    FUNCTION PROTOTYPES
64***************************************************************************/
5465
66/* device interface */
67DEVICE_GET_INFO( nec765a );
68DEVICE_GET_INFO( nec765b );
69DEVICE_GET_INFO( smc37c78 );
70DEVICE_GET_INFO( nec72065 );
71
5572/* read of data register */
56READ8_HANDLER(nec765_data_r);
73READ8_DEVICE_HANDLER(nec765_data_r);
5774/* write to data register */
58WRITE8_HANDLER(nec765_data_w);
75WRITE8_DEVICE_HANDLER(nec765_data_w);
5976/* read of main status register */
60READ8_HANDLER(nec765_status_r);
77READ8_DEVICE_HANDLER(nec765_status_r);
6178
6279/* dma acknowledge with write */
63WRITE8_HANDLER(nec765_dack_w);
80WRITE8_DEVICE_HANDLER(nec765_dack_w);
6481/* dma acknowledge with read */
65READ8_HANDLER(nec765_dack_r);
82READ8_DEVICE_HANDLER(nec765_dack_r);
6683
6784/* reset nec765 */
68void nec765_reset(running_machine *machine, int);
85void nec765_reset(const device_config *device, int);
6986
7087/* reset pin of nec765 */
71void nec765_set_reset_state(running_machine *machine, int);
88void nec765_set_reset_state(const device_config *device, int);
7289
90/* set nec765 terminal count input state */
91void nec765_set_tc_state(const device_config *device, int);
92/* set nec765 ready input*/
93void nec765_set_ready_state(const device_config *device,int);
94
95void nec765_idle(const device_config *device);
96
7397/*********************/
7498/* STATUS REGISTER 1 */
7599
r3867r3868
91115command, or FDC encounters a Data Mark when executing a read deleted data command */
92116#define NEC765_ST2_CONTROL_MARK (1<<6)
93117
118/***************************************************************************
119    DEVICE CONFIGURATION MACROS
120***************************************************************************/
121
122#define MDRV_NEC765A_ADD(_tag, _intrf) \
123   MDRV_DEVICE_ADD(_tag, NEC765A) \
124   MDRV_DEVICE_CONFIG(_intrf)
125
126#define MDRV_NEC765A_MODIFY(_tag, _intrf) \
127  MDRV_DEVICE_MODIFY(_tag, NEC765A)         \
128  MDRV_DEVICE_CONFIG(_intrf)
129
130#define MDRV_NEC765A_REMOVE(_tag)      \
131  MDRV_DEVICE_REMOVE(_tag, NEC765A)
132
133#define MDRV_NEC765B_ADD(_tag, _intrf) \
134   MDRV_DEVICE_ADD(_tag, NEC765B) \
135   MDRV_DEVICE_CONFIG(_intrf)
136
137#define MDRV_NEC765B_MODIFY(_tag, _intrf) \
138  MDRV_DEVICE_MODIFY(_tag, NEC765B)         \
139  MDRV_DEVICE_CONFIG(_intrf)
140
141#define MDRV_NEC765B_REMOVE(_tag)      \
142  MDRV_DEVICE_REMOVE(_tag, NEC765B)
143
144#define MDRV_SMC37C78_ADD(_tag, _intrf) \
145   MDRV_DEVICE_ADD(_tag, SMC37C78) \
146   MDRV_DEVICE_CONFIG(_intrf)
147
148#define MDRV_SMC37C78_MODIFY(_tag, _intrf) \
149  MDRV_DEVICE_MODIFY(_tag, SMC37C78)         \
150  MDRV_DEVICE_CONFIG(_intrf)
151
152#define MDRV_SMC37C78_REMOVE(_tag)      \
153  MDRV_DEVICE_REMOVE(_tag, SMC37C78)
154
155#define MDRV_NEC72065_ADD(_tag, _intrf) \
156   MDRV_DEVICE_ADD(_tag, NEC72065) \
157   MDRV_DEVICE_CONFIG(_intrf)
158
159#define MDRV_NEC72065_MODIFY(_tag, _intrf) \
160  MDRV_DEVICE_MODIFY(_tag, NEC72065)         \
161  MDRV_DEVICE_CONFIG(_intrf)
162
163#define MDRV_NEC72065_REMOVE(_tag)      \
164  MDRV_DEVICE_REMOVE(_tag, NEC72065)
165
94166#endif /* NEC765_H */
95167
168
src/mess/machine/concept.c
r3867r3868
566566   LC_FMMFM_mask   = (1 << LC_FMMFM_bit)
567567};
568568
569static void fdc_callback(running_machine *machine, wd17xx_state_t event, void *param);
570569
571570static  READ8_HANDLER(concept_fdc_reg_r);
572571static WRITE8_HANDLER(concept_fdc_reg_w);
r3867r3868
577576   fdc_local_status = 0;
578577   fdc_local_command = 0;
579578
580   wd17xx_init(machine, WD_TYPE_179X, fdc_callback, NULL);
581
582579   install_expansion_slot(slot, concept_fdc_reg_r, concept_fdc_reg_w, concept_fdc_rom_r, NULL);
583580}
584581
585static void fdc_callback(running_machine *machine, wd17xx_state_t event, void *param)
582static WD17XX_CALLBACK( fdc_callback )
586583{
587   switch (event)
584   switch (state)
588585   {
589586      case WD17XX_IRQ_CLR:
590587         fdc_local_status &= ~LS_INT_mask;
r3867r3868
601598   }
602599}
603600
601const wd17xx_interface concept_wd17xx_interface = { fdc_callback, NULL };
602
604603static  READ8_HANDLER(concept_fdc_reg_r)
605604{
605   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
606606   switch (offset)
607607   {
608608   case 0:
r3867r3868
612612
613613   case 8:
614614      /* FDC STATUS REG */
615      return wd17xx_status_r(space, offset);
615      return wd17xx_status_r(fdc, offset);
616616      break;
617617
618618   case 9:
619619      /* FDC TRACK REG */
620      return wd17xx_track_r(space, offset);
620      return wd17xx_track_r(fdc, offset);
621621      break;
622622
623623   case 10:
624624      /* FDC SECTOR REG */
625      return wd17xx_sector_r(space, offset);
625      return wd17xx_sector_r(fdc, offset);
626626      break;
627627
628628   case 11:
629629      /* FDC DATA REG */
630      return wd17xx_data_r(space, offset);
630      return wd17xx_data_r(fdc, offset);
631631      break;
632632   }
633633
r3867r3868
637637static WRITE8_HANDLER(concept_fdc_reg_w)
638638{
639639   int current_drive;
640
640   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
641641   switch (offset)
642642   {
643643   case 0:
644644      /* local command reg */
645645      fdc_local_command = data;
646646
647      wd17xx_set_side((data & LC_FLPSD1_mask) != 0);
647      wd17xx_set_side(fdc,(data & LC_FLPSD1_mask) != 0);
648648      current_drive = ((data >> LC_DE0_bit) & 1) | ((data >> (LC_DE1_bit-1)) & 2);
649      wd17xx_set_drive(current_drive);
649      wd17xx_set_drive(fdc, current_drive);
650650      /*motor_on = (data & LC_MOTOROF_mask) == 0;*/
651651      // floppy_drive_set_motor_state(image_from_devtype_and_index(IO_FLOPPY, current_drive), (data & LC_MOTOROF_mask) == 0 ? 1 : 0);
652652      /*flp_8in = (data & LC_FLP8IN_mask) != 0;*/
653      wd17xx_set_density((data & LC_FMMFM_mask) ? DEN_FM_LO : DEN_MFM_LO);
653      wd17xx_set_density(fdc, (data & LC_FMMFM_mask) ? DEN_FM_LO : DEN_MFM_LO);
654654      floppy_drive_set_ready_state(image_from_devtype_and_index(IO_FLOPPY, current_drive), 1, 0);
655655      break;
656656
657657   case 8:
658658      /* FDC COMMAMD REG */
659      wd17xx_command_w(space, offset, data);
659      wd17xx_command_w(fdc, offset, data);
660660      break;
661661
662662   case 9:
663663      /* FDC TRACK REG */
664      wd17xx_track_w(space, offset, data);
664      wd17xx_track_w(fdc, offset, data);
665665      break;
666666
667667   case 10:
668668      /* FDC SECTOR REG */
669      wd17xx_sector_w(space, offset, data);
669      wd17xx_sector_w(fdc, offset, data);
670670      break;
671671
672672   case 11:
673673      /* FDC DATA REG */
674      wd17xx_data_w(space, offset, data);
674      wd17xx_data_w(fdc, offset, data);
675675      break;
676676   }
677677}
src/mess/machine/msx.c
r3867r3868
295295   msx_vdp_interrupt
296296};
297297
298static void msx_wd179x_int (running_machine *machine, wd17xx_state_t state, void *param);
299298
300299MACHINE_START( msx )
301300{
r3867r3868
305304
306305MACHINE_START( msx2 )
307306{
308   wd17xx_init (machine, WD_TYPE_179X, msx_wd179x_int, NULL);
309   wd17xx_set_density (DEN_FM_HI);
307   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
308   wd17xx_set_density (fdc,DEN_FM_HI);
310309   msx1.dsk_stat = 0x7f;
311310}
312311
r3867r3868
634633
635634*/
636635
637static void msx_wd179x_int (running_machine *machine, wd17xx_state_t state, void *param)
636static WD17XX_CALLBACK( msx_wd179x_int )
638637{
639638   switch (state)
640639   {
r3867r3868
645644   }
646645}
647646
647const wd17xx_interface msx_wd17xx_interface = { msx_wd179x_int, NULL };
648648
649649DEVICE_IMAGE_LOAD( msx_floppy )
650650{
src/mess/machine/cgenie.c
r3867r3868
9393}
9494
9595
96static void cgenie_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param);
97
9896MACHINE_RESET( cgenie )
9997{
10098   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
r3867r3868
203201   memory_install_write8_handler(space, 0x4000, 0x4000 + mess_ram_size - 1, 0, 0, cgenie_videoram_w);
204202   videoram = mess_ram;
205203   memory_set_bankptr(machine, 1, mess_ram);
206
207   /* set up FDC */
208   wd17xx_init(machine, WD_TYPE_179X, cgenie_fdc_callback, NULL);
209204}
210205
211206
r3867r3868
481476
482477 READ8_HANDLER( cgenie_status_r )
483478{
479   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
484480   /* If the floppy isn't emulated, return 0 */
485481   if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 )
486482      return 0;
487   return wd17xx_status_r(space, offset);
483   return wd17xx_status_r(fdc, offset);
488484}
489485
490486 READ8_HANDLER( cgenie_track_r )
491487{
488   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
492489   /* If the floppy isn't emulated, return 0xff */
493490   if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 )
494491      return 0xff;
495   return wd17xx_track_r(space, offset);
492   return wd17xx_track_r(fdc, offset);
496493}
497494
498495 READ8_HANDLER( cgenie_sector_r )
499496{
497   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
500498   /* If the floppy isn't emulated, return 0xff */
501499   if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 )
502500      return 0xff;
503   return wd17xx_sector_r(space, offset);
501   return wd17xx_sector_r(fdc, offset);
504502}
505503
506504 READ8_HANDLER(cgenie_data_r )
507505{
506   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
508507   /* If the floppy isn't emulated, return 0xff */
509508   if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 )
510509      return 0xff;
511   return wd17xx_data_r(space, offset);
510   return wd17xx_data_r(fdc, offset);
512511}
513512
514513WRITE8_HANDLER( cgenie_command_w )
515514{
515   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
516516   /* If the floppy isn't emulated, return immediately */
517517   if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 )
518518      return;
519   wd17xx_command_w(space, offset, data);
519   wd17xx_command_w(fdc, offset, data);
520520}
521521
522522WRITE8_HANDLER( cgenie_track_w )
523523{
524   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
524525   /* If the floppy isn't emulated, ignore the write */
525526   if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 )
526527      return;
527   wd17xx_track_w(space, offset, data);
528   wd17xx_track_w(fdc, offset, data);
528529}
529530
530531WRITE8_HANDLER( cgenie_sector_w )
531532{
533   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
532534   /* If the floppy isn't emulated, ignore the write */
533535   if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 )
534536      return;
535   wd17xx_sector_w(space, offset, data);
537   wd17xx_sector_w(fdc, offset, data);
536538}
537539
538540WRITE8_HANDLER( cgenie_data_w )
539541{
542   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
540543   /* If the floppy isn't emulated, ignore the write */
541544   if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 )
542545      return;
543   wd17xx_data_w(space, offset, data);
546   wd17xx_data_w(fdc, offset, data);
544547}
545548
546549 READ8_HANDLER( cgenie_irq_status_r )
r3867r3868
560563   }
561564}
562565
563void cgenie_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param)
566static WD17XX_CALLBACK( cgenie_fdc_callback )
564567{
565568   /* if disc hardware is not enabled, do not cause an int */
566   if (!( input_port_read(machine, "DSW0") & 0x80 ))
569   if (!( input_port_read(device->machine, "DSW0") & 0x80 ))
567570      return;
568571
569   switch( event )
572   switch( state )
570573   {
571574      case WD17XX_IRQ_CLR:
572575         irq_status &= ~IRQ_FDC;
r3867r3868
575578         if( (irq_status & IRQ_FDC) == 0 )
576579         {
577580            irq_status |= IRQ_FDC;
578            cpu_set_input_line(machine->cpu[0], 0, HOLD_LINE);
581            cpu_set_input_line(device->machine->cpu[0], 0, HOLD_LINE);
579582         }
580583         break;
581584      case WD17XX_DRQ_CLR:
r3867r3868
585588   }
586589}
587590
591const wd17xx_interface cgenie_wd17xx_interface = { cgenie_fdc_callback, NULL };
592
588593WRITE8_HANDLER( cgenie_motor_w )
589594{
595   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
590596   UINT8 drive = 255;
591597
592598   logerror("cgenie motor_w $%02X\n", data);
r3867r3868
609615   /* currently selected drive */
610616   motor_drive = drive;
611617
612   wd17xx_set_drive(drive);
613   wd17xx_set_side(head);
618   wd17xx_set_drive(fdc,drive);
619   wd17xx_set_side(fdc,head);
614620}
615621
616622/*************************************
src/mess/machine/beta.c
r3867r3868
3535   betadisk_status = 0;
3636}
3737
38void betadisk_wd179x_callback(running_machine *machine, wd17xx_state_t state, void *param)
38static WD17XX_CALLBACK( betadisk_wd179x_callback )
3939{
4040   switch (state)
4141   {
r3867r3868
6565   }
6666}
6767
68const wd17xx_interface beta_wd17xx_interface = { betadisk_wd179x_callback, NULL };
69
6870READ8_HANDLER(betadisk_status_r)
6971{
7072   if (betadisk_active==1) {
71      return wd17xx_status_r(space, offset);
73      return wd17xx_status_r((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset);
7274   } else {
7375      return 0xff;
7476   }
r3867r3868
7779READ8_HANDLER(betadisk_track_r)
7880{
7981   if (betadisk_active==1) {
80      return wd17xx_track_r(space, offset);
82      return wd17xx_track_r((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset);
8183   } else {
8284      return 0xff;
8385   }
r3867r3868
8688READ8_HANDLER(betadisk_sector_r)
8789{
8890   if (betadisk_active==1) {
89      return wd17xx_sector_r(space, offset);
91      return wd17xx_sector_r((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset);
9092   } else {
9193      return 0xff;
9294   }
r3867r3868
9597READ8_HANDLER(betadisk_data_r)
9698{
9799   if (betadisk_active==1) {
98      return wd17xx_data_r(space, offset);
100      return wd17xx_data_r((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset);
99101   } else {
100102      return 0xff;
101103   }
r3867r3868
112114
113115WRITE8_HANDLER(betadisk_param_w)
114116{
117   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
115118   if (betadisk_active==1) {
116        wd17xx_set_drive ( data & 3); 
117        wd17xx_set_side ((data & 0x10) ? 0 : 1 );
118        wd17xx_set_density(data & 0x20 ? DEN_MFM_HI : DEN_FM_LO );
119        wd17xx_set_drive(fdc, data & 3); 
120        wd17xx_set_side (fdc,(data & 0x10) ? 0 : 1 );
121        wd17xx_set_density(fdc, data & 0x20 ? DEN_MFM_HI : DEN_FM_LO );
119122        if ((data & 0x04) == 0) // reset
120123        {
121           wd17xx_reset(space->machine);   
124           wd17xx_reset(fdc);   
122125        }         
123126        betadisk_status = (data & 0x3f) | betadisk_status;
124127     }
r3867r3868
127130WRITE8_HANDLER(betadisk_command_w)
128131{
129132   if (betadisk_active==1) {
130      wd17xx_command_w(space, offset, data);
133      wd17xx_command_w((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset, data);
131134   }   
132135}
133136
134137WRITE8_HANDLER(betadisk_track_w)
135138{
136139   if (betadisk_active==1) {
137      wd17xx_track_w(space, offset, data);
140      wd17xx_track_w((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset, data);
138141   }   
139142}
140143
141144WRITE8_HANDLER(betadisk_sector_w)
142145{
143146   if (betadisk_active==1) {
144      wd17xx_sector_w(space, offset, data);
147      wd17xx_sector_w((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset, data);
145148   }   
146149}
147150
148151WRITE8_HANDLER(betadisk_data_w)
149152{
150153   if (betadisk_active==1) {
151      wd17xx_data_w(space, offset, data);
154      wd17xx_data_w((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset, data);
152155   }   
153156}
154157
src/mess/machine/beta.h
r3867r3868
1616void betadisk_enable(void);
1717void betadisk_disable(void);
1818void betadisk_clear_status(void);
19void betadisk_wd179x_callback(running_machine *machine, wd17xx_state_t state, void *param);
2019
20extern const wd17xx_interface beta_wd17xx_interface;
21
2122READ8_HANDLER(betadisk_status_r);
2223READ8_HANDLER(betadisk_track_r);
2324READ8_HANDLER(betadisk_sector_r);
src/mess/machine/pc8801.c
r3867r3868
795795
796796READ8_HANDLER(pc8801fd_nec765_tc)
797797{
798  nec765_set_tc_state(space->machine, 1);
799  nec765_set_tc_state(space->machine, 0);
798  device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
799  nec765_set_tc_state(fdc, 1);
800  nec765_set_tc_state(fdc, 0);
800801  return 0;
801802}
802803
803804/* callback for /INT output from FDC */
804static void pc8801_fdc_interrupt(running_machine *machine,int state)
805static NEC765_INTERRUPT( pc8801_fdc_interrupt )
805806{
806    cpu_set_input_line(machine->cpu[1], 0, state ? HOLD_LINE : CLEAR_LINE);
807    cpu_set_input_line(device->machine->cpu[1], 0, state ? HOLD_LINE : CLEAR_LINE);
807808}
808809
809810/* callback for /DRQ output from FDC */
810static void pc8801_fdc_dma_drq(running_machine *machine,int state, int read_)
811static NEC765_DMA_REQUEST( pc8801_fdc_dma_drq )
811812{
812813}
813814
814static const struct nec765_interface pc8801_fdc_interface=
815const nec765_interface pc8801_fdc_interface=
815816{
816817   pc8801_fdc_interrupt,
817   pc8801_fdc_dma_drq
818   pc8801_fdc_dma_drq,
819   NULL,
820   NEC765_RDY_PIN_CONNECTED
818821};
819822
820823static void pc8801_init_5fd(running_machine *machine)
r3867r3868
824827      cpu_suspend(machine->cpu[1], SUSPEND_REASON_DISABLE, 1);
825828   else
826829      cpu_resume(machine->cpu[1], SUSPEND_REASON_DISABLE);
827   nec765_init(machine, &pc8801_fdc_interface,NEC765A,NEC765_RDY_PIN_CONNECTED);
828830   cpu_set_input_line_vector(machine->cpu[1],0,0);
829831   floppy_drive_set_motor_state(image_from_devtype_and_index(IO_FLOPPY, 0), 1);
830832   floppy_drive_set_motor_state(image_from_devtype_and_index(IO_FLOPPY, 1), 1);
src/mess/machine/partner.c
r3867r3868
2828   radio86_tape_value = 0x80;
2929}
3030
31static void partner_wd17xx_callback(running_machine *machine, wd17xx_state_t state, void *param)
31static WD17XX_CALLBACK( partner_wd17xx_callback )
3232{
33   const device_config *dma8257 = device_list_find_by_tag(machine->config->devicelist, DMA8257, "dma8257");
33   const device_config *dma8257 = device_list_find_by_tag(device->machine->config->devicelist, DMA8257, "dma8257");
3434   switch(state)
3535   {
3636      case WD17XX_IRQ_CLR:
r3867r3868
4444         break;
4545   }
4646}
47
48const wd17xx_interface partner_wd17xx_interface = { partner_wd17xx_callback, NULL };
49
4750MACHINE_START(partner)
4851{
49   wd17xx_init(machine, WD_TYPE_1793, partner_wd17xx_callback , NULL);
50   wd17xx_set_density (DEN_MFM_HI);   
51   wd17xx_set_pause_time(10);
52   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD1793, "wd1793");
53   wd17xx_set_density (fdc,DEN_MFM_HI);   
54   wd17xx_set_pause_time(fdc,10);
5255}
5356
5457DEVICE_IMAGE_LOAD( partner_floppy )
r3867r3868
105108}
106109
107110static READ8_HANDLER ( partner_floppy_r ) {
111   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
112   
108113   if (offset<0x100) {
109114      switch(offset & 3) {
110         case 0x00 : return wd17xx_status_r(space,0);
111         case 0x01 : return wd17xx_track_r(space,0);
112         case 0x02 : return wd17xx_sector_r(space,0);
115         case 0x00 : return wd17xx_status_r(fdc,0);
116         case 0x01 : return wd17xx_track_r(fdc,0);
117         case 0x02 : return wd17xx_sector_r(fdc,0);
113118         default   :
114                  return wd17xx_data_r(space,0);
119                  return wd17xx_data_r(fdc,0);
115120      }
116121   } else {
117122      return 0;
r3867r3868
119124}
120125
121126static WRITE8_HANDLER ( partner_floppy_w ) {
127   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
128   
122129   if (offset<0x100) {
123130      switch(offset & 3) {
124         case 0x00 : wd17xx_command_w(space,0,data); break;
125         case 0x01 : wd17xx_track_w(space,0,data);break;
126         case 0x02 : wd17xx_sector_w(space,0,data);break;
127         default   : wd17xx_data_w(space,0,data);break;
131         case 0x00 : wd17xx_command_w(fdc,0,data); break;
132         case 0x01 : wd17xx_track_w(fdc,0,data);break;
133         case 0x02 : wd17xx_sector_w(fdc,0,data);break;
134         default   : wd17xx_data_w(fdc,0,data);break;
128135      }
129136   } else {
130137      if (((data >> 6) & 1)==1) {
131         wd17xx_set_drive(0);
138         wd17xx_set_drive(fdc,0);
132139      }
133140      if (((data >> 3) & 1)==1) {
134         wd17xx_set_drive(1);
141         wd17xx_set_drive(fdc,1);
135142      }     
136      wd17xx_set_side(data >> 7);       
143      wd17xx_set_side(fdc,data >> 7);       
137144   }
138145}
139146
r3867r3868
376383
377384static READ8_DEVICE_HANDLER ( partner_wd17xx_data_r )
378385{
379   return wd17xx_data_r(cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM), offset);
386   device_config *fdc = (device_config*)device_list_find_by_tag( device->machine->config->devicelist, WD1793, "wd1793");
387   return wd17xx_data_r(fdc, offset);
380388}
381389
382390static WRITE8_DEVICE_HANDLER ( partner_wd17xx_data_w )
383391{
384   wd17xx_data_w(cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM), offset, data);
392   device_config *fdc = (device_config*)device_list_find_by_tag( device->machine->config->devicelist, WD1793, "wd1793");
393   wd17xx_data_w(fdc, offset, data);
385394}
386395
387396const dma8257_interface partner_dma =
r3867r3868
397406   { 0, 0, 0, 0 }
398407};
399408
400/*
401const dma8257_interface partner_dma =
402{
403   0,
404   XTAL_16MHz / 9,
405409
406   radio86_dma_read_byte,
407   partner_dma_write_byte,
408
409   { wd17xx_data_r,  0, 0, 0 },
410   { wd17xx_data_w, 0, radio86_write_video, 0 },
411   { 0, 0, 0, 0 }
412};
413*/
414
415
416410MACHINE_RESET( partner )
417411{
418412   partner_mem_page = 0;
419413   partner_win_mem_page = 0;
420414   partner_bank_switch(machine);
421   wd17xx_reset(machine);
422415}
src/mess/machine/pc_fdc.c
r3867r3868
5555/* Prototypes */
5656
5757static TIMER_CALLBACK( watchdog_timeout );
58static void pc_fdc_hw_interrupt(running_machine *machine,int state);
59static void pc_fdc_hw_dma_drq(running_machine *machine,int,int);
60static const device_config *pc_fdc_get_image(running_machine *machine,int floppy_index);
6158
62static const nec765_interface pc_fdc_nec765_interface =
59static NEC765_INTERRUPT(  pc_fdc_hw_interrupt );
60static NEC765_DMA_REQUEST(pc_fdc_hw_dma_drq);
61static NEC765_GET_IMAGE ( pc_fdc_get_image);
62
63const nec765_interface pc_fdc_nec765_connected_interface =
6364{
6465   pc_fdc_hw_interrupt,
6566   pc_fdc_hw_dma_drq,
66   pc_fdc_get_image
67   pc_fdc_get_image,
68   NEC765_RDY_PIN_CONNECTED
6769};
6870
71const nec765_interface pc_fdc_nec765_not_connected_interface =
72{
73   pc_fdc_hw_interrupt,
74   pc_fdc_hw_dma_drq,
75   pc_fdc_get_image,
76   NEC765_RDY_PIN_NOT_CONNECTED
77};
78
79static const device_config* pc_get_device(running_machine *machine)
80{
81   return (*fdc->fdc_interface.get_device)(machine);
82}
83
6984static void pc_fdc_reset(running_machine *machine)
7085{
7186   /* setup reset condition */
r3867r3868
7590   /* bit 7 is disk change */
7691   fdc->digital_input_register = 0x07f;
7792
78   nec765_reset(machine, 0);
93   nec765_reset(pc_get_device(machine),0);
7994
8095   /* set FDC at reset */
81   nec765_set_reset_state(machine, 1);
96   nec765_set_reset_state(pc_get_device(machine), 1);
8297}
8398
8499
r3867r3868
97112      memcpy(&fdc->fdc_interface, iface, sizeof(fdc->fdc_interface));
98113
99114   /* setup nec765 interface */
100   nec765_init(machine, &pc_fdc_nec765_interface, iface->nec765_type, iface->nec765_rdy_pin);
115   //nec765_init(machine, &pc_fdc_nec765_interface, iface->nec765_type, iface->nec765_rdy_pin);
101116
102117   fdc->watchdog = timer_alloc(machine,  watchdog_timeout, NULL );
103118
r3867r3868
112127
113128
114129
115static const device_config *pc_fdc_get_image(running_machine *machine, int floppy_index)
130static NEC765_GET_IMAGE ( pc_fdc_get_image )
116131{
117132   const device_config *image = NULL;
118133
119134   if (!fdc->fdc_interface.get_image)
120135   {
121      if (floppy_index < device_count(machine, IO_FLOPPY))
136      if (floppy_index < device_count(device->machine, IO_FLOPPY))
122137         image = image_from_devtype_and_index(IO_FLOPPY, floppy_index);
123138   }
124139   else
r3867r3868
138153   /* if dma is not enabled, tc's are not acknowledged */
139154   if ((fdc->digital_output_register & PC_FDC_FLAGS_DOR_DMA_ENABLED)!=0)
140155   {
141      nec765_set_tc_state(machine, state);
156      nec765_set_tc_state(pc_get_device(machine), state);
142157   }
143158}
144159
145160
146161
147void pc_fdc_hw_interrupt(running_machine *machine,int state)
162static NEC765_INTERRUPT(  pc_fdc_hw_interrupt )
148163{
149164   fdc->int_state = state;
150165
r3867r3868
154169
155170   /* send irq */
156171   if (fdc->fdc_interface.pc_fdc_interrupt)
157      fdc->fdc_interface.pc_fdc_interrupt(machine, state);
172      fdc->fdc_interface.pc_fdc_interrupt(device->machine, state);
158173}
159174
160175
r3867r3868
169184   /* if dma is not enabled, dacks are not acknowledged */
170185   if ((fdc->digital_output_register & PC_FDC_FLAGS_DOR_DMA_ENABLED)!=0)
171186   {
172      data = nec765_dack_r(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0);
187      data = nec765_dack_r(pc_get_device(machine), 0);
173188   }
174189
175190   return data;
r3867r3868
183198   if ((fdc->digital_output_register & PC_FDC_FLAGS_DOR_DMA_ENABLED)!=0)
184199   {
185200      /* dma acknowledge - and send byte to fdc */
186      nec765_dack_w(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0,data);
201      nec765_dack_w(pc_get_device(machine), 0,data);
187202   }
188203}
189204
190205
191206
192void pc_fdc_hw_dma_drq(running_machine *machine, int state, int read_)
207static NEC765_DMA_REQUEST( pc_fdc_hw_dma_drq )
193208{
194209   fdc->dma_state = state;
195   fdc->dma_read = read_;
210   fdc->dma_read = read_write;
196211
197212   /* if dma is not enabled, drqs are masked */
198213   if ((fdc->digital_output_register & PC_FDC_FLAGS_DOR_DMA_ENABLED)==0)
199214      return;
200215
201216   if (fdc->fdc_interface.pc_fdc_dma_drq)
202      fdc->fdc_interface.pc_fdc_dma_drq(machine,state, read_);
217      fdc->fdc_interface.pc_fdc_dma_drq(device->machine,state, read_write);
203218}
204219
205220
r3867r3868
209224   if ((data & 0x080)!=0)
210225   {
211226      /* set ready state */
212      nec765_set_ready_state(1);
227      nec765_set_ready_state(pc_get_device(machine),1);
213228
214229      /* toggle reset state */
215      nec765_set_reset_state(machine, 1);
216       nec765_set_reset_state(machine, 0);
230      nec765_set_reset_state(pc_get_device(machine), 1);
231       nec765_set_reset_state(pc_get_device(machine), 0);
217232
218233      /* bit is self-clearing */
219234      data &= ~0x080;
r3867r3868
274289   /* changing the DMA enable bit, will affect the dma drq state
275290   from reaching us - if dma is enabled this will send it through
276291   otherwise it will be ignored */
277   pc_fdc_hw_dma_drq(machine, fdc->dma_state, fdc->dma_read);
292   pc_fdc_hw_dma_drq(pc_get_device(machine), fdc->dma_state, fdc->dma_read);
278293
279294   /* changing the DMA enable bit, will affect the irq state
280295   from reaching us - if dma is enabled this will send it through
281296   otherwise it will be ignored */
282   pc_fdc_hw_interrupt(machine, fdc->int_state);
297   pc_fdc_hw_interrupt(pc_get_device(machine), fdc->int_state);
283298
284299   /* reset? */
285300   if ((fdc->digital_output_register & PC_FDC_FLAGS_DOR_FDC_ENABLED)==0)
r3867r3868
302317      what is not yet clear is if this is a result of the drives ready state
303318      changing...
304319      */
305         nec765_set_ready_state(1);
320         nec765_set_ready_state(pc_get_device(machine),1);
306321
307322      /* set FDC at reset */
308      nec765_set_reset_state(machine, 1);
323      nec765_set_reset_state(pc_get_device(machine), 1);
309324   }
310325   else
311326   {
312327      pc_fdc_set_tc_state(machine, 0);
313328
314329      /* release reset on fdc */
315      nec765_set_reset_state(machine, 0);
330      nec765_set_reset_state(pc_get_device(machine), 0);
316331   }
317332}
318333
r3867r3868
391406      what is not yet clear is if this is a result of the drives ready state
392407      changing...
393408      */
394         nec765_set_ready_state(1);
409         nec765_set_ready_state(pc_get_device(machine),1);
395410
396411      /* set FDC at reset */
397      nec765_set_reset_state(machine, 1);
412      nec765_set_reset_state(pc_get_device(machine), 1);
398413   }
399414   else
400415   {
401416      pc_fdc_set_tc_state(machine, 0);
402417
403418      /* release reset on fdc */
404      nec765_set_reset_state(machine, 0);
419      nec765_set_reset_state(pc_get_device(machine), 0);
405420   }
406421
407422   logerror("pcjr_fdc_dor_w: changing dor from %02x to %02x\n", fdc->digital_output_register, data);
r3867r3868
425440      case 3: /* tape drive select? */
426441         break;
427442      case 4:
428         data = nec765_status_r(space, 0);
443         data = nec765_status_r(pc_get_device(space->machine), 0);
429444         break;
430445      case 5:
431         data = nec765_data_r(space, offset);
446         data = nec765_data_r(pc_get_device(space->machine), offset);
432447         break;
433448      case 6: /* FDC reserved */
434449         break;
r3867r3868
464479         pc_fdc_data_rate_w(space->machine, data);
465480         break;
466481      case 5:
467         nec765_data_w(space, 0, data);
482         nec765_data_w(pc_get_device(space->machine), 0, data);
468483         break;
469484      case 6:
470485         /* FDC reserved */
src/mess/machine/pc_fdc.h
r3867r3868
2525
2626/* main interface */
2727struct pc_fdc_interface
28{
29   NEC765_VERSION nec765_type;
30   NEC765_RDY_PIN nec765_rdy_pin;
28{   
3129   void (*pc_fdc_interrupt)(running_machine*,int);
32   void (*pc_fdc_dma_drq)(running_machine*,int,int);
30   void (*pc_fdc_dma_drq)(running_machine*,int,int);   
3331   const device_config *(*get_image)(int floppy_index);
32   device_config *(*get_device)(running_machine*);
3433};
3534
35extern const nec765_interface pc_fdc_nec765_connected_interface;
36extern const nec765_interface pc_fdc_nec765_not_connected_interface;
3637
3738void pc_fdc_init(running_machine *machine, const struct pc_fdc_interface *iface);
3839void pc_fdc_set_tc_state(running_machine *machine, int state);
src/mess/machine/bebox.c
r3867r3868
426426   return image_from_devtype_and_index(IO_FLOPPY, 0);
427427}
428428
429static device_config * bebox_get_device(running_machine *machine )
430{
431   return (device_config*)device_list_find_by_tag( machine->config->devicelist, SMC37C78, "smc37c78");   
432}
429433
434
430435static const struct pc_fdc_interface bebox_fdc_interface =
431436{
432   SMC37C78,
433   NEC765_RDY_PIN_CONNECTED,
434437   bebox_fdc_interrupt,
435438   bebox_fdc_dma_drq,
436   bebox_fdc_get_image
439   bebox_fdc_get_image,
440   bebox_get_device
437441};
438442
439443
src/mess/machine/special.c
r3867r3868
246246
247247MACHINE_START( specimx )
248248{
249   wd17xx_init(machine, WD_TYPE_1793, NULL , NULL);
250   wd17xx_set_density (DEN_FM_HI);
249   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD1793, "wd1793");
250   wd17xx_set_density (fdc,DEN_FM_HI);
251251}
252252
253253static TIMER_CALLBACK( setup_pit8253_gates ) {
r3867r3868
262262{
263263   specimx_set_bank(machine, 2,0x00); // Initiali load ROM disk
264264   specimx_color = 0x70;   
265   wd17xx_reset(machine);
266   wd17xx_set_side(0);
267265   timer_set(machine,  attotime_zero, NULL, 0, setup_pit8253_gates );
268266}
269267
r3867r3868
274272
275273WRITE8_HANDLER( specimx_disk_ctrl_w )
276274{   
275   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
277276
278277   switch(offset) {             
279278      case 2 :                 
280             wd17xx_set_side(data & 1);                     
279             wd17xx_set_side(fdc,data & 1);                     
281280            break;         
282281      case 3 :           
283             wd17xx_set_drive(data & 1);           
282             wd17xx_set_drive(fdc,data & 1);           
284283             break;
285284         
286285  } 
r3867r3868
403402   erik_background = 0;
404403}
405404
406MACHINE_START( erik )
407{
408   wd17xx_init(machine, WD_TYPE_1793, NULL , NULL);
409}
410
411405MACHINE_RESET( erik )
412406{
413   wd17xx_reset(machine);     
414   
415407   RR_register = 0x00;   
416408   RC_register = 0x00;
417409   erik_set_bank(machine);           
r3867r3868
446438}
447439
448440WRITE8_HANDLER( erik_disk_reg_w ) {
449   wd17xx_set_side (data & 1);   
450   wd17xx_set_drive((data >> 1) & 1);
441   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1793, "wd1793");
442   
443   wd17xx_set_side (fdc,data & 1);   
444   wd17xx_set_drive(fdc,(data >> 1) & 1);
451445   if((data >>2) & 1) {
452      wd17xx_set_density (DEN_FM_LO);
446      wd17xx_set_density (fdc,DEN_FM_LO);
453447   } else {
454      wd17xx_set_density (DEN_FM_HI);
448      wd17xx_set_density (fdc,DEN_FM_HI);
455449  }   
456450}
src/mess/machine/pc.c
r3867r3868
10721072   dma8237_drq_write( pc_devices.dma8237, FDC_DMA, state);
10731073}
10741074
1075static device_config * pc_get_device(running_machine *machine )
1076{
1077   return (device_config*)device_list_find_by_tag( machine->config->devicelist, NEC765A, "nec765");   
1078}
10751079
10761080static const struct pc_fdc_interface fdc_interface_nc =
10771081{
1078   NEC765A,
1079   NEC765_RDY_PIN_NOT_CONNECTED,
10801082   pc_fdc_interrupt,
10811083   pc_fdc_dma_drq,
1084   NULL,
1085   pc_get_device
10821086};
10831087
10841088static void pc_set_irq_line(int irq, int state) {
src/mess/machine/bbc.c
r3867r3868
16711671
16721672static int bbc_1770_IntEnabled;
16731673
1674static void bbc_wd177x_callback(running_machine *machine, wd17xx_state_t event, void *param)
1674static WD17XX_CALLBACK( bbc_wd177x_callback)
16751675{
1676   int state;
1676   int bbc_state;
16771677   /* wd177x_IRQ_SET and latch bit 4 (nmi_enable) are NAND'ED together
16781678      wd177x_DRQ_SET and latch bit 4 (nmi_enable) are NAND'ED together
16791679      the output of the above two NAND gates are then OR'ED together and sent to the 6502 NMI line.
r3867r3868
16861686     The nmi is edge triggered, and triggers on a +ve edge.
16871687   */
16881688
1689   logerror("callback $%02X\n", event);
1689   logerror("callback $%02X\n", state);
16901690
16911691
16921692   /* update bbc_wd177x_drq_irq_state depending on event */
1693   switch (event)
1693   switch (state)
16941694   {
16951695        case WD17XX_DRQ_SET:
16961696      {
r3867r3868
17211721   if (((bbc_wd177x_drq_irq_state & 3)!=0) && (bbc_1770_IntEnabled))
17221722   {
17231723      /* int trigger */
1724      state = 1;
1724      bbc_state = 1;
17251725   }
17261726   else
17271727   {
17281728      /* do not trigger int */
1729      state = 0;
1729      bbc_state = 0;
17301730   }
17311731
17321732   /* nmi is edge triggered, and triggers when the state goes from clear->set.
17331733   Here we are checking this transition before triggering the nmi */
1734   if (state!=previous_wd177x_int_state)
1734   if (bbc_state!=previous_wd177x_int_state)
17351735   {
1736      if (state)
1736      if (bbc_state)
17371737      {
17381738         /* I'll pulse it because if I used hold-line I'm not sure
17391739         it would clear - to be checked */
1740         cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI,PULSE_LINE);
1740         cpu_set_input_line(device->machine->cpu[0], INPUT_LINE_NMI,PULSE_LINE);
17411741      }
17421742   }
17431743
1744   previous_wd177x_int_state = state;
1744   previous_wd177x_int_state = bbc_state;
17451745
17461746}
17471747
1748const wd17xx_interface bbc_wd17xx_interface = {
1749   bbc_wd177x_callback,
1750   NULL
1751};
1752
17481753static WRITE8_HANDLER(bbc_wd177x_status_w)
17491754{
1755   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");   
17501756   drive_control = data;
17511757
17521758   /* set drive */
1753   if ((data>>0) & 0x01) wd17xx_set_drive(0);
1754   if ((data>>1) & 0x01) wd17xx_set_drive(1);
1759   if ((data>>0) & 0x01) wd17xx_set_drive(fdc,0);
1760   if ((data>>1) & 0x01) wd17xx_set_drive(fdc,1);
17551761
17561762   /* set side */
1757   wd17xx_set_side((data>>2) & 0x01);
1763   wd17xx_set_side(fdc,(data>>2) & 0x01);
17581764
17591765   /* set density */
17601766   if ((data>>3) & 0x01)
17611767   {
17621768      /* single density */
1763      wd17xx_set_density(DEN_FM_HI);
1769      wd17xx_set_density(fdc,DEN_FM_HI);
17641770   }
17651771   else
17661772   {
17671773      /* double density */
1768      wd17xx_set_density(DEN_MFM_LO);
1774      wd17xx_set_density(fdc,DEN_MFM_LO);
17691775   }
17701776
17711777   bbc_1770_IntEnabled=(((data>>4) & 0x01)==0);
r3867r3868
17751781
17761782
17771783READ8_HANDLER ( bbc_wd1770_read )
1778{
1784{   
17791785   int retval=0xff;
1786   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
17801787   switch (offset)
17811788   {
17821789   case 4:
1783      retval=wd17xx_status_r(space, 0);
1790      retval=wd17xx_status_r(fdc, 0);
17841791      break;
17851792   case 5:
1786      retval=wd17xx_track_r(space, 0);
1793      retval=wd17xx_track_r(fdc, 0);
17871794      break;
17881795   case 6:
1789      retval=wd17xx_sector_r(space, 0);
1796      retval=wd17xx_sector_r(fdc, 0);
17901797      break;
17911798   case 7:
1792      retval=wd17xx_data_r(space, 0);
1799      retval=wd17xx_data_r(fdc, 0);
17931800      break;
17941801   default:
17951802      break;
r3867r3868
18011808
18021809WRITE8_HANDLER ( bbc_wd1770_write )
18031810{
1811   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
18041812   logerror("wd177x write: $%02X  $%02X\n", offset,data);
18051813   switch (offset)
18061814   {
r3867r3868
18081816      bbc_wd177x_status_w(space, 0, data);
18091817      break;
18101818   case 4:
1811      wd17xx_command_w(space, 0, data);
1819      wd17xx_command_w(fdc, 0, data);
18121820      break;
18131821   case 5:
1814      wd17xx_track_w(space, 0, data);
1822      wd17xx_track_w(fdc, 0, data);
18151823      break;
18161824   case 6:
1817      wd17xx_sector_w(space, 0, data);
1825      wd17xx_sector_w(fdc, 0, data);
18181826      break;
18191827   case 7:
1820      wd17xx_data_w(space, 0, data);
1828      wd17xx_data_w(fdc, 0, data);
18211829      break;
18221830   default:
18231831      break;
r3867r3868
18641872
18651873static WRITE8_HANDLER( bbc_opus_status_w )
18661874{
1875   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
18671876   drive_control = data;
18681877
18691878   /* set drive */
1870   if ((data>>1) & 0x01) wd17xx_set_drive(0);
1871   if ((data>>2) & 0x01) wd17xx_set_drive(1);
1879   if ((data>>1) & 0x01) wd17xx_set_drive(fdc,0);
1880   if ((data>>2) & 0x01) wd17xx_set_drive(fdc,1);
18721881
18731882   /* set side */
1874   wd17xx_set_side((data>>0) & 0x01);
1883   wd17xx_set_side(fdc,(data>>0) & 0x01);
18751884
18761885   /* set density */
18771886   if ((data>>5) & 0x01)
18781887   {
18791888      /* single density */
1880      wd17xx_set_density(DEN_FM_HI);
1889      wd17xx_set_density(fdc,DEN_FM_HI);
18811890   }
18821891   else
18831892   {
18841893      /* double density */
1885      wd17xx_set_density(DEN_MFM_LO);
1894      wd17xx_set_density(fdc,DEN_MFM_LO);
18861895   }
18871896
18881897   bbc_1770_IntEnabled=(data>>4) & 0x01;
r3867r3868
18911900
18921901READ8_HANDLER( bbc_opus_read )
18931902{
1903   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
18941904   logerror("wd177x read: $%02X\n", offset);
18951905
18961906   if (bbc_DFSType==6)
r3867r3868
19001910         switch (offset)
19011911         {
19021912            case 0xf8:
1903               return wd17xx_status_r(space, 0);
1913               return wd17xx_status_r(fdc, 0);
19041914               break;
19051915            case 0xf9:
1906               return wd17xx_track_r(space, 0);
1916               return wd17xx_track_r(fdc, 0);
19071917               break;
19081918            case 0xfa:
1909               return wd17xx_sector_r(space, 0);
1919               return wd17xx_sector_r(fdc, 0);
19101920               break;
19111921            case 0xfb:
1912               return wd17xx_data_r(space, 0);
1922               return wd17xx_data_r(fdc, 0);
19131923               break;
19141924         }
19151925
r3867r3868
19221932
19231933WRITE8_HANDLER (bbc_opus_write)
19241934{
1935   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
19251936   logerror("wd177x write: $%02X  $%02X\n", offset,data);
19261937
19271938   if (bbc_DFSType==6)
r3867r3868
19311942         switch (offset)
19321943         {
19331944            case 0xf8:
1934               wd17xx_command_w(space, 0, data);
1945               wd17xx_command_w(fdc, 0, data);
19351946               break;
19361947            case 0xf9:
1937               wd17xx_track_w(space, 0, data);
1948               wd17xx_track_w(fdc, 0, data);
19381949               break;
19391950            case 0xfa:
1940               wd17xx_sector_w(space, 0, data);
1951               wd17xx_sector_w(fdc, 0, data);
19411952               break;
19421953            case 0xfb:
1943               wd17xx_data_w(space, 0, data);
1954               wd17xx_data_w(fdc, 0, data);
19441955               break;
19451956            case 0xfc:
19461957               bbc_opus_status_w(space, 0,data);
r3867r3868
19671978READ8_HANDLER ( bbcm_wd1770_read )
19681979{
19691980   int retval=0xff;
1981   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
19701982   switch (offset)
19711983   {
19721984   case 0:
1973      retval=wd17xx_status_r(space, 0);
1985      retval=wd17xx_status_r(fdc, 0);
19741986      break;
19751987   case 1:
1976      retval=wd17xx_track_r(space, 0);
1988      retval=wd17xx_track_r(fdc, 0);
19771989      break;
19781990   case 2:
1979      retval=wd17xx_sector_r(space, 0);
1991      retval=wd17xx_sector_r(fdc, 0);
19801992      break;
19811993   case 3:
1982      retval=wd17xx_data_r(space, 0);
1994      retval=wd17xx_data_r(fdc, 0);
19831995      break;
19841996   default:
19851997      break;
r3867r3868
19902002
19912003WRITE8_HANDLER ( bbcm_wd1770_write )
19922004{
2005   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
19932006   //logerror("wd177x write: $%02X  $%02X\n", offset,data);
19942007   switch (offset)
19952008   {
19962009   case 0:
1997      wd17xx_command_w(space, 0, data);
2010      wd17xx_command_w(fdc, 0, data);
19982011      break;
19992012   case 1:
2000      wd17xx_track_w(space, 0, data);
2013      wd17xx_track_w(fdc, 0, data);
20012014      break;
20022015   case 2:
2003      wd17xx_sector_w(space, 0, data);
2016      wd17xx_sector_w(fdc, 0, data);
20042017      break;
20052018   case 3:
2006      wd17xx_data_w(space, 0, data);
2019      wd17xx_data_w(fdc, 0, data);
20072020      break;
20082021   default:
20092022      break;
r3867r3868
20182031
20192032WRITE8_HANDLER ( bbcm_wd1770l_write )
20202033{
2034   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
20212035   drive_control = data;
20222036
20232037   /* set drive */
2024   if ((data>>0) & 0x01) wd17xx_set_drive(0);
2025   if ((data>>1) & 0x01) wd17xx_set_drive(1);
2038   if ((data>>0) & 0x01) wd17xx_set_drive(fdc,0);
2039   if ((data>>1) & 0x01) wd17xx_set_drive(fdc,1);
20262040
20272041   /* set side */
2028   wd17xx_set_side((data>>4) & 0x01);
2042   wd17xx_set_side(fdc,(data>>4) & 0x01);
20292043
20302044   /* set density */
20312045   if ((data>>5) & 0x01)
20322046   {
20332047      /* single density */
2034      wd17xx_set_density(DEN_FM_HI);
2048      wd17xx_set_density(fdc,DEN_FM_HI);
20352049   }
20362050   else
20372051   {
20382052      /* double density */
2039      wd17xx_set_density(DEN_MFM_LO);
2053      wd17xx_set_density(fdc,DEN_MFM_LO);
20402054   }
20412055
20422056//   bbc_1770_IntEnabled=(((data>>4) & 0x01)==0);
r3867r3868
21902204   //   break;
21912205   //case 4: case 5: case 6:
21922206      previous_wd177x_int_state=1;
2193       wd17xx_init(machine, WD_TYPE_177X,bbc_wd177x_callback, NULL);
21942207   //   break;
21952208   //}
21962209}
r3867r3868
22262239   //case 0:   case 1: case 2: case 3:
22272240   //   break;
22282241   //case 4: case 5: case 6:
2229       wd17xx_reset(machine);
22302242   //   break;
22312243   //}
22322244}
r3867r3868
22402252
22412253   /* bank 6 is the paged ROMs     from b000 to bfff */
22422254   memory_configure_bank(machine, 6, 0, 16, memory_region(machine, "user1") + 0x3000, 1<<14);
2243
2244   wd17xx_init(machine, WD_TYPE_177X,bbc_wd177x_callback, NULL);
22452255}
22462256
22472257MACHINE_RESET( bbcbp )
r3867r3868
22562266
22572267
22582268   previous_wd177x_int_state=1;
2259    wd17xx_reset(machine);
22602269}
22612270
22622271
r3867r3868
22732282   /* Set ROM/IO bank to point to rom */
22742283   memory_set_bankptr( machine, 8, memory_region(machine, "user1")+0x43c00);
22752284   memory_install_read_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM),0xFC00,0xFEFF,0,0,8);
2276
2277   wd17xx_init(machine, WD_TYPE_177X,bbc_wd177x_callback, NULL);
22782285}
22792286
22802287MACHINE_RESET( bbcm )
r3867r3868
22882295   bbcb_IC32_initialise();
22892296
22902297
2291   previous_wd177x_int_state=1;
2292    wd17xx_reset(machine);
2298   previous_wd177x_int_state=1;   
22932299}
src/mess/machine/kc.c
r3867r3868
203203
204204WRITE8_HANDLER(kc85_disc_hw_terminal_count_w)
205205{
206   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
206207   logerror("kc85 disc hw tc w: %02x\n",data);
207   nec765_set_tc_state(space->machine, data & 0x01);
208   nec765_set_tc_state(fdc, data & 0x01);
208209}
209210
210211
211212/* callback for /INT output from FDC */
212static void kc85_fdc_interrupt(running_machine *machine, int state)
213static NEC765_INTERRUPT( kc85_fdc_interrupt )
213214{
214215   kc85_disc_hw_input_gate &=~(1<<6);
215216   if (state)
r3867r3868
217218}
218219
219220/* callback for /DRQ output from FDC */
220static void kc85_fdc_dma_drq(running_machine *machine, int state, int read_)
221static NEC765_DMA_REQUEST( kc85_fdc_dma_drq )
221222{
222223   kc85_disc_hw_input_gate &=~(1<<7);
223224   if (state)
224225      kc85_disc_hw_input_gate |=(1<<7);
225226}
226227
227static const struct nec765_interface kc_fdc_interface=
228const nec765_interface kc_fdc_interface=
228229{
229230   kc85_fdc_interrupt,
230   kc85_fdc_dma_drq
231   kc85_fdc_dma_drq,
232   NULL,
233   NEC765_RDY_PIN_CONNECTED   
231234};
232235
233236static TIMER_CALLBACK(kc85_disk_reset_timer_callback)
r3867r3868
240243{
241244   timer_set(machine, attotime_zero, NULL, 0, kc85_disk_reset_timer_callback);
242245
243   nec765_init(machine, &kc_fdc_interface,NEC765A,NEC765_RDY_PIN_CONNECTED);
244
245246   /* hold cpu at reset */
246247   cpu_set_input_line(machine->cpu[1], INPUT_LINE_RESET, ASSERT_LINE);
247248}
src/mess/devices/flopdrv.c
r3867r3868
5757   /* default RPM */
5858   pDrive->rpm = 300;
5959
60   pDrive->controller = NULL;
61   
6062   floppy_drive_set_disk_image_interface(img, iface);
6163}
6264
r3867r3868
8183   }
8284
8385   if (pDrive->index_pulse_callback)
84      pDrive->index_pulse_callback(img, pDrive->index);
86      pDrive->index_pulse_callback(pDrive->controller, img, pDrive->index);
8587}
8688
8789
r3867r3868
9597
9698
9799/* set the callback for the index pulse */
98void floppy_drive_set_index_pulse_callback(const device_config *img, void (*callback)(const device_config *image, int state))
100void floppy_drive_set_index_pulse_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *image, int state))
99101{
100102   struct floppy_drive *pDrive = get_drive(img);
101103   pDrive->index_pulse_callback = callback;
102104}
103105
104106
105void floppy_drive_set_ready_state_change_callback(const device_config *img, void (*callback)(const device_config *img, int state))
107void floppy_drive_set_ready_state_change_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *img, int state))
106108{
107109   struct floppy_drive *pDrive = get_drive(img);
108110   pDrive->ready_state_change_callback = callback;
r3867r3868
169171      {
170172         /* trigger state change callback */
171173         if (drv->ready_state_change_callback)
172            drv->ready_state_change_callback(img, new_state);
174            drv->ready_state_change_callback(drv->controller, img, new_state);
173175      }
174176   }
175177}
r3867r3868
510512   struct floppy_drive *drv = get_drive(img);
511513   drv->rpm = rpm;
512514}
515
516void floppy_drive_set_controller(const device_config *img, const device_config *controller)
517{
518   struct floppy_drive *drv = get_drive(img);
519   drv->controller = controller;
520}
521
src/mess/devices/flopdrv.h
r3867r3868
9595   /* index pulse timer */
9696   void   *index_timer;
9797   /* index pulse callback */
98   void   (*index_pulse_callback)(const device_config *image, int state);
98   void   (*index_pulse_callback)(const device_config *controller,const device_config *image, int state);
9999   /* rotation per minute => gives index pulse frequency */
100100   float rpm;
101101   /* current index pulse value */
102102   int index;
103103
104   void   (*ready_state_change_callback)(const device_config *img, int state);
104   void   (*ready_state_change_callback)(const device_config *controller,const device_config *img, int state);
105105
106106   unsigned char id_buffer[4];
107107
108108   int id_index;
109109    chrn_id ids[32];
110110
111   const device_config *controller;
112   
111113   floppy_interface interface_;
112114};
113115
114116/* a callback which will be executed if the ready state of the drive changes e.g. not ready->ready, ready->not ready */
115void floppy_drive_set_ready_state_change_callback(const device_config *img, void (*callback)(const device_config *img, int state));
117void floppy_drive_set_ready_state_change_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *img, int state));
116118
117119/* floppy drive types */
118120typedef enum
r3867r3868
121123   FLOPPY_DRIVE_DS_80
122124} floppy_type;
123125
124void floppy_drive_set_index_pulse_callback(const device_config *img, void (*callback)(const device_config *image, int state));
126void floppy_drive_set_index_pulse_callback(const device_config *img, void (*callback)(const device_config *controller,const device_config *image, int state));
125127
126128/* set flag state */
127129int floppy_drive_get_flag_state(const device_config *img, int flag);
r3867r3868
164166*/
165167void floppy_drive_set_rpm(const device_config *image, float rpm);
166168
167
169void floppy_drive_set_controller(const device_config *img, const device_config *controller);
168170#endif /* FLOPDRV_H */
src/mess/devices/coco_fdc.c
r3867r3868
109109    fdc_callback - callback from the FDC
110110-------------------------------------------------*/
111111
112static void fdc_callback(running_machine *machine, wd17xx_state_t state, void *param)
112static WD17XX_CALLBACK( fdc_callback )
113113{
114114   coco_cartridge *cartridge = (coco_cartridge *) param;
115115   fdc_info *info = fdc_get_info(cartridge);
r3867r3868
136136   (*info->update_lines)(cartridge);
137137}
138138
139extern coco_cartridge *coco_cart;
139140
141static WD17XX_PARAM_CALLBACK( get_coco_cart )
142{
143   return coco_cart;
144}
140145
146const wd17xx_interface dragon_wd17xx_interface = {
147   fdc_callback,
148   get_coco_cart
149};
150const wd17xx_interface coco_wd17xx_interface = {
151   fdc_callback,
152   get_coco_cart
153};
154
155
141156/*-------------------------------------------------
142157    fdc_init - general function to initialize FDC
143158-------------------------------------------------*/
144159
145160static void fdc_init(running_machine *machine,
146161   coco_cartridge *cartridge,
147   wd17xx_type_t type,
148162   void (*update_lines)(coco_cartridge *cartridge),
149163   int initial_drq)
150164{
r3867r3868
156170   info->drq = initial_drq ? 1 : 0;
157171
158172   /* initialize FDC */
159   wd17xx_init(machine, type, fdc_callback, (void *) cartridge);
173//   wd17xx_init(machine, type, fdc_callback, (void *) cartridge);
160174}
161175
162176
r3867r3868
216230
217231static void fdc_coco_init(coco_cartridge *cartridge)
218232{
219   fdc_init(Machine, cartridge, WD_TYPE_1773, fdc_coco_update_lines, 1);
233   fdc_init(Machine, cartridge, fdc_coco_update_lines, 1);
220234}
221235
222236
r3867r3868
228242
229243static void fdc_coco_dskreg_w(coco_cartridge *cartridge, UINT8 data)
230244{
245   running_machine *machine = Machine;
246   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD1773, "wd1773");
231247   fdc_info *info = fdc_get_info(cartridge);
232248   UINT8 drive = 0;
233249   UINT8 head = 0;
r3867r3868
272288
273289   (*info->update_lines)(cartridge);
274290
275   wd17xx_set_drive(drive);
276   wd17xx_set_side(head);
277   wd17xx_set_density((info->dskreg & 0x20) ? DEN_MFM_LO : DEN_FM_LO);
291   wd17xx_set_drive(fdc,drive);
292   wd17xx_set_side(fdc,head);
293   wd17xx_set_density(fdc,(info->dskreg & 0x20) ? DEN_MFM_LO : DEN_FM_LO);
278294}
279295
280296
r3867r3868
286302static UINT8 fdc_coco_r(coco_cartridge *cartridge, UINT16 addr)
287303{
288304   running_machine *machine = Machine;
289   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
305   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD1773, "wd1773");
290306   UINT8 result = 0;
291307   switch(addr & 0xEF)
292308   {
293309      case 8:
294         result = wd17xx_status_r(space, 0);
310         result = wd17xx_status_r(fdc, 0);
295311         break;
296312      case 9:
297         result = wd17xx_track_r(space, 0);
313         result = wd17xx_track_r(fdc, 0);
298314         break;
299315      case 10:
300         result = wd17xx_sector_r(space, 0);
316         result = wd17xx_sector_r(fdc, 0);
301317         break;
302318      case 11:
303         result = wd17xx_data_r(space, 0);
319         result = wd17xx_data_r(fdc, 0);
304320         break;
305321   }
306322   return result;
r3867r3868
315331static void fdc_coco_w(coco_cartridge *cartridge, UINT16 addr, UINT8 data)
316332{
317333   running_machine *machine = Machine;
318   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
334   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD1773, "wd1773");
319335   switch(addr & 0xEF)
320336   {
321337      case 0: case 1: case 2: case 3:
r3867r3868
323339         fdc_coco_dskreg_w(cartridge, data);
324340         break;
325341      case 8:
326         wd17xx_command_w(space, 0, data);
342         wd17xx_command_w(fdc, 0, data);
327343         break;
328344      case 9:
329         wd17xx_track_w(space, 0, data);
345         wd17xx_track_w(fdc, 0, data);
330346         break;
331347      case 10:
332         wd17xx_sector_w(space, 0, data);
348         wd17xx_sector_w(fdc, 0, data);
333349         break;
334350      case 11:
335         wd17xx_data_w(space, 0, data);
351         wd17xx_data_w(fdc, 0, data);
336352         break;
337353   };
338354}
r3867r3868
540556
541557static void fdc_dragon_init(coco_cartridge *cartridge)
542558{
543   fdc_init(Machine, cartridge, WD_TYPE_179X, fdc_dragon_update_lines, 0);
559   fdc_init(Machine, cartridge, fdc_dragon_update_lines, 0);
544560}
545561
546562
r3867r3868
552568
553569static void fdc_dragon_dskreg_w(coco_cartridge *cartridge, UINT8 data)
554570{
571   running_machine *machine = Machine;
572   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
555573   fdc_info *info = fdc_get_info(cartridge);
556574
557575   if (LOG_FDC)
r3867r3868
569587   }
570588
571589   if (data & 0x04)
572      wd17xx_set_drive(data & 0x03);
590      wd17xx_set_drive(fdc,data & 0x03);
573591
574   wd17xx_set_density((data & 0x08) ? DEN_FM_LO: DEN_MFM_LO);
592   wd17xx_set_density(fdc,(data & 0x08) ? DEN_FM_LO: DEN_MFM_LO);
575593   info->dskreg = data;
576594}
577595
r3867r3868
584602static UINT8 fdc_dragon_r(coco_cartridge *cartridge, UINT16 addr)
585603{
586604   running_machine *machine = Machine;
587   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
605   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
588606   UINT8 result = 0;
589607   switch(addr & 0xEF)
590608   {
591609      case 0:
592         result = wd17xx_status_r(space, 0);
610         result = wd17xx_status_r(fdc, 0);
593611         break;
594612      case 1:
595         result = wd17xx_track_r(space, 0);
613         result = wd17xx_track_r(fdc, 0);
596614         break;
597615      case 2:
598         result = wd17xx_sector_r(space, 0);
616         result = wd17xx_sector_r(fdc, 0);
599617         break;
600618      case 3:
601         result = wd17xx_data_r(space, 0);
619         result = wd17xx_data_r(fdc, 0);
602620         break;
603621   }
604622   return result;
r3867r3868
613631static void fdc_dragon_w(coco_cartridge *cartridge, UINT16 addr, UINT8 data)
614632{
615633   running_machine *machine = Machine;
616   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
634   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
617635   switch(addr & 0xEF)
618636   {
619637      case 0:
620         wd17xx_command_w(space, 0, data);
638         wd17xx_command_w(fdc, 0, data);
621639
622640         /* disk head is encoded in the command byte */
623641         /* Only for type 3 & 4 commands */
624642         if (data & 0x80)
625            wd17xx_set_side((data & 0x02) ? 1 : 0);
643            wd17xx_set_side(fdc,(data & 0x02) ? 1 : 0);
626644         break;
627645      case 1:
628         wd17xx_track_w(space, 0, data);
646         wd17xx_track_w(fdc, 0, data);
629647         break;
630648      case 2:
631         wd17xx_sector_w(space, 0, data);
649         wd17xx_sector_w(fdc, 0, data);
632650         break;
633651      case 3:
634         wd17xx_data_w(space, 0, data);
652         wd17xx_data_w(fdc, 0, data);
635653         break;
636654      case 8: case 9: case 10: case 11:
637655      case 12: case 13: case 14: case 15:
src/mess/devices/thomflop.c
r3867r3868
270270
271271static READ8_HANDLER ( to7_5p14_r )
272272{
273   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD2793, "wd2793");
274   
273275   if ( offset < 4 )
274      return wd17xx_r( space, offset );
276      return wd17xx_r( fdc, offset );
275277   else if ( offset == 8 )
276278      return to7_5p14_select;
277279   else
r3867r3868
283285
284286static WRITE8_HANDLER( to7_5p14_w )
285287{
288   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD2793, "wd2793");
286289   if ( offset < 4 )
287      wd17xx_w( space, offset, data );
290      wd17xx_w( fdc, offset, data );
288291   else if ( offset == 8 )
289292   {
290293      /* drive select */
r3867r3868
304307
305308      dens = (data & 0x80) ? DEN_FM_LO : DEN_MFM_LO;
306309      thom_floppy_set_density( dens );
307      wd17xx_set_density( dens );
310      wd17xx_set_density( fdc, dens );
308311
309312      to7_5p14_select = data;
310313
311314      if ( drive != -1 )
312315      {
313316         thom_floppy_active( space->machine, 0 );
314         wd17xx_set_drive( drive );
315         wd17xx_set_side( side );
317         wd17xx_set_drive( fdc, drive );
318         wd17xx_set_side( fdc, side );
316319         LOG(( "%f $%04x to7_5p14_w: $%02X set drive=%i side=%i density=%s\n",
317320               attotime_to_double(timer_get_time(space->machine)), cpu_get_previouspc( space->machine->cpu[0] ),
318321               data, drive, side, (dens == DEN_FM_LO) ? "FM" : "MFM" ));
r3867r3868
328331static void to7_5p14_reset( running_machine *machine )
329332{
330333   int i;
334   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD2793, "wd2793");   
331335   LOG(( "to7_5p14_reset: CD 90-640 controller\n" ));
332336   thom_floppy_set_density( DEN_MFM_LO );
333   wd17xx_reset(machine);
337   wd17xx_reset(fdc);
334338   for ( i = 0; i < device_count( machine, IO_FLOPPY ); i++ )
335339   {
336340      const device_config * img = image_from_devtype_and_index( IO_FLOPPY, i );
r3867r3868
345349static void to7_5p14_init( running_machine *machine )
346350{
347351   LOG(( "to7_5p14_init: CD 90-640 controller\n" ));
348   wd17xx_init( machine, WD_TYPE_2793, NULL, NULL );
349352   state_save_register_global( machine, to7_5p14_select );
350353}
351354
r3867r3868
424427            attotime_to_double(timer_get_time(space->machine)), cpu_get_previouspc( space->machine->cpu[0] ), offset, data );
425428}
426429
427static void to7_5p14_index_pulse_callback( const device_config *device, int index_pulse )
430static void to7_5p14_index_pulse_callback( const device_config *controller,const device_config *image, int state )
428431{
429   mc6843_set_index_pulse( devtag_get_device(device->machine, MC6843, "mc6843"), index_pulse );
432   mc6843_set_index_pulse( devtag_get_device(image->machine, MC6843, "mc6843"), state );
430433}
431434
432435static void to7_5p14sd_reset( running_machine *machine )
r3867r3868
525528
526529
527530
528static void to7_qdd_index_pulse_cb ( const device_config* img, int state )
531static void to7_qdd_index_pulse_cb ( const device_config *controller,const device_config *image, int state )
529532{
530533   to7qdd->index_pulse = state;
531534
r3867r3868
537540      to7qdd->data_size = 0;
538541   }
539542
540   VLOG(( "%f to7_qdd_pulse_cb: state=%i\n", attotime_to_double(timer_get_time(img->machine)), state ));
543   VLOG(( "%f to7_qdd_pulse_cb: state=%i\n", attotime_to_double(timer_get_time(image->machine)), state ));
541544}
542545
543546
r3867r3868
954957
955958
956959
957static void thmfc_floppy_index_pulse_cb ( const device_config *img, int state )
960static void thmfc_floppy_index_pulse_cb ( const device_config *controller,const device_config *image, int state )
958961{
959   if ( img != thmfc_floppy_image() )
962   if ( image != thmfc_floppy_image() )
960963      return;
961964
962965   if ( thmfc_floppy_is_qdd() )
963966   {
964967      /* pulse each time the whole-disk spiraling track ends */
965      floppy_drive_set_rpm( img, 16.92f /* 423/25 */ );
968      floppy_drive_set_rpm( image, 16.92f /* 423/25 */ );
966969      thmfc1->ipl = state;
967970      if ( state )
968971      {
r3867r3868
973976   }
974977   else
975978   {
976      floppy_drive_set_rpm( img, 300. );
979      floppy_drive_set_rpm( image, 300. );
977980      thmfc1->ipl = state;
978981      if ( state  )
979982         thmfc1->data_raw_idx = 0;
980983   }
981984
982   VLOG(( "%f thmfc_floppy_index_pulse_cb: state=%i\n", attotime_to_double(timer_get_time(img->machine)), state ));
985   VLOG(( "%f thmfc_floppy_index_pulse_cb: state=%i\n", attotime_to_double(timer_get_time(image->machine)), state ));
983986}
984987
985988
src/mess/drivers/dgn_beta.c
r3867r3868
338338   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
339339
340340   MDRV_VIDEO_UPDATE( dgnbeta )
341   
342   MDRV_WD179X_ADD("wd179x", dgnbeta_wd17xx_interface )   
341343MACHINE_DRIVER_END
342344
343345ROM_START(dgnbeta)
src/mess/drivers/nc.c
r3867r3868
13221322};
13231323
13241324
1325static void nc200_fdc_interrupt(running_machine *machine, int state)
1325static NEC765_INTERRUPT( nc200_fdc_interrupt )
13261326{
13271327#if 0
13281328    nc_irq_latch &=~(1<<5);
r3867r3868
13391339            nc_irq_status |=(1<<5);
13401340    }
13411341
1342    nc_update_interrupts(machine);
1342    nc_update_interrupts(device->machine);
13431343}
13441344
1345static const struct nec765_interface nc200_nec765_interface=
1345static const nec765_interface nc200_nec765_interface=
13461346{
13471347    nc200_fdc_interrupt,
13481348    NULL,
1349    NULL,
1350    NEC765_RDY_PIN_CONNECTED
13491351};
13501352
13511353#ifdef UNUSED_FUNCTION
r3867r3868
13691371
13701372    nc_common_init_machine(machine);
13711373
1372    nec765_init(machine, &nc200_nec765_interface, NEC765A,NEC765_RDY_PIN_CONNECTED);
13731374    /* double sided, 80 track drive */
13741375   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 0), FLOPPY_DRIVE_DS_80);
13751376   //floppy_drive_set_index_pulse_callback(image_from_devtype_and_index(IO_FLOPPY, 0), nc200_floppy_drive_index_callback);
r3867r3868
15191520
15201521static WRITE8_HANDLER(nc200_memory_card_wait_state_w)
15211522{
1523   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
15221524   LOG_DEBUG(("nc200 memory card wait state: PC: %04x %02x\n",cpu_get_pc(space->machine->cpu[0]),data));
15231525#if 0
15241526   floppy_drive_set_motor_state(0,1);
15251527   floppy_drive_set_ready_state(0,1,1);
15261528#endif
1527   nec765_set_tc_state(space->machine, (data & 0x01));
1529   nec765_set_tc_state(fdc, (data & 0x01));
15281530}
15291531
15301532/* bit 2: backlight: 1=off, 0=on */
r3867r3868
15541556   AM_RANGE(0xc0, 0xc0) AM_DEVREADWRITE(MSM8251, "uart", msm8251_data_r, msm8251_data_w)
15551557   AM_RANGE(0xc1, 0xc1) AM_DEVREADWRITE(MSM8251, "uart", msm8251_status_r, msm8251_control_w)
15561558   AM_RANGE(0xd0, 0xd1) AM_READWRITE(mc146818_port_r, mc146818_port_w)
1557   AM_RANGE(0xe0, 0xe0) AM_READ(nec765_status_r)
1558   AM_RANGE(0xe1, 0xe1) AM_READWRITE(nec765_data_r, nec765_data_w)
1559   AM_RANGE(0xe0, 0xe0) AM_DEVREAD(NEC765A, "nec765", nec765_status_r)
1560   AM_RANGE(0xe1, 0xe1) AM_DEVREADWRITE(NEC765A, "nec765",nec765_data_r, nec765_data_w)
15591561ADDRESS_MAP_END
15601562
15611563static INPUT_PORTS_START(nc200)
r3867r3868
17381740
17391741   /* no rtc */
17401742   MDRV_DEVICE_REMOVE("rtc", TC8521)
1743   
1744   MDRV_NEC765A_ADD("nec765", nc200_nec765_interface)
17411745MACHINE_DRIVER_END
17421746
17431747
src/mess/drivers/sord.c
r3867r3868
131131
132132static WRITE8_HANDLER(fd5_tc_w)
133133{
134   nec765_set_tc_state(space->machine, 1);
135   nec765_set_tc_state(space->machine, 0);
134   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
135   nec765_set_tc_state(fdc, 1);
136   nec765_set_tc_state(fdc, 0);
136137}
137138
138139/* 0x020 fd5 writes to this port to communicate with m5 */
r3867r3868
141142/* 0x040 */
142143/* 0x050 */
143144static ADDRESS_MAP_START(sord_fd5_io, ADDRESS_SPACE_IO, 8)
144   AM_RANGE(0x000, 0x000) AM_READ(nec765_status_r)
145   AM_RANGE(0x001, 0x001) AM_READWRITE(nec765_data_r, nec765_data_w)
145   AM_RANGE(0x000, 0x000) AM_DEVREAD( NEC765A, "nec765", nec765_status_r)
146   AM_RANGE(0x001, 0x001) AM_DEVREADWRITE( NEC765A, "nec765", nec765_data_r, nec765_data_w)
146147   AM_RANGE(0x010, 0x010) AM_READWRITE(fd5_data_r, fd5_data_w)
147148   AM_RANGE(0x020, 0x020) AM_WRITE(fd5_communication_w)
148149   AM_RANGE(0x030, 0x030) AM_READ(fd5_communication_r)
r3867r3868
151152ADDRESS_MAP_END
152153
153154/* nec765 data request is connected to interrupt of z80 inside fd5 interface */
154static void sord_fd5_fdc_interrupt(running_machine *machine, int state)
155static NEC765_INTERRUPT( sord_fd5_fdc_interrupt )
155156{
156157   if (state)
157158   {
158      cpu_set_input_line(machine->cpu[1], 0, HOLD_LINE);
159      cpu_set_input_line(device->machine->cpu[1], 0, HOLD_LINE);
159160   }
160161   else
161162   {
162      cpu_set_input_line(machine->cpu[1], 0,CLEAR_LINE);
163      cpu_set_input_line(device->machine->cpu[1], 0,CLEAR_LINE);
163164   }
164165}
165166
166167static const struct nec765_interface sord_fd5_nec765_interface=
167168{
168169   sord_fd5_fdc_interrupt,
169   NULL
170   NULL,
171   NULL,
172   NEC765_RDY_PIN_CONNECTED
170173};
171174
172static void sord_fd5_init(running_machine *machine)
173{
174   nec765_init(machine, &sord_fd5_nec765_interface,NEC765A,NEC765_RDY_PIN_CONNECTED);
175}
176
177175static MACHINE_RESET( sord_m5_fd5 )
178176{
179177   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 0), FLOPPY_DRIVE_SS_40);
180178   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 1), FLOPPY_DRIVE_SS_40);
181   sord_fd5_init(machine);
182179   MACHINE_RESET_CALL(sord_m5);
183180   ppi8255_set_port_c((device_config*)device_list_find_by_tag( machine->config->devicelist, PPI8255, "ppi8255" ), 0x50);
184181}
r3867r3868
652649   MDRV_DEVICE_ADD("printer", PRINTER)
653650
654651   MDRV_CASSETTE_ADD( "cassette", sordm5_cassette_config )
652     
655653MACHINE_DRIVER_END
656654
657655
r3867r3868
667665
668666   MDRV_INTERLEAVE(20)
669667   MDRV_MACHINE_RESET( sord_m5_fd5 )
668   
669   MDRV_NEC765A_ADD("nec765", sord_fd5_nec765_interface)
670670MACHINE_DRIVER_END
671671
672672
src/mess/drivers/mbee.c
r3867r3868
115115   AM_RANGE(0x0b, 0x0b) AM_MIRROR(0x10) AM_READWRITE(mbee_video_bank_r, mbee_video_bank_w)
116116   AM_RANGE(0x0c, 0x0c) AM_MIRROR(0x10) AM_READWRITE(m6545_status_r, m6545_index_w)
117117   AM_RANGE(0x0d, 0x0d) AM_MIRROR(0x10) AM_READWRITE(m6545_data_r, m6545_data_w)
118   AM_RANGE(0x44, 0x44) AM_READWRITE(wd17xx_status_r, wd17xx_command_w)
119   AM_RANGE(0x45, 0x45) AM_READWRITE(wd17xx_track_r, wd17xx_track_w)
120   AM_RANGE(0x46, 0x46) AM_READWRITE(wd17xx_sector_r, wd17xx_sector_w)
121   AM_RANGE(0x47, 0x47) AM_READWRITE(wd17xx_data_r, wd17xx_data_w)
118   AM_RANGE(0x44, 0x44) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_status_r, wd17xx_command_w)
119   AM_RANGE(0x45, 0x45) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_track_r, wd17xx_track_w)
120   AM_RANGE(0x46, 0x46) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_sector_r, wd17xx_sector_w)
121   AM_RANGE(0x47, 0x47) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_data_r, wd17xx_data_w)
122122   AM_RANGE(0x48, 0x48) AM_READWRITE(mbee_fdc_status_r, mbee_fdc_motor_w)
123123ADDRESS_MAP_END
124124
r3867r3868
409409   MDRV_CPU_VBLANK_INT("main", mbee_interrupt)
410410
411411   MDRV_MACHINE_RESET( mbee )
412   MDRV_MACHINE_START( mbee )
413412
414413   MDRV_Z80PIO_ADD( "z80pio", mbee_z80pio_intf )
415414
r3867r3868
438437   MDRV_Z80BIN_QUICKLOAD_ADD(mbee, 2)
439438
440439   MDRV_CASSETTE_ADD( "cassette", default_cassette_config )
440   
441   MDRV_WD179X_ADD("wd179x", mbee_wd17xx_interface )
441442MACHINE_DRIVER_END
442443
443444
src/mess/drivers/pentagon.c
r3867r3868
1111#include "machine/wd17xx.h"
1212#include "machine/beta.h"
1313
14static MACHINE_START( pentagon )
15{
16   wd17xx_init(machine, WD_TYPE_179X, betadisk_wd179x_callback, NULL);
17}
1814
1915static int ROMSelection;
2016
r3867r3868
111107   spectrum_128_port_7ffd_data = 0;
112108
113109   pentagon_update_memory(machine);   
114     
115   wd17xx_reset(machine);   
116110}
117111
118112static MACHINE_DRIVER_START( pentagon )
119113   MDRV_IMPORT_FROM( spectrum_128 )
120114   MDRV_CPU_MODIFY("main")
121115   MDRV_CPU_IO_MAP(pentagon_io, 0)
122   MDRV_MACHINE_START( pentagon )
123116   MDRV_MACHINE_RESET( pentagon )
117     
118   MDRV_WD179X_ADD("wd179x", beta_wd17xx_interface )
124119MACHINE_DRIVER_END
125120
126121
src/mess/drivers/coco.c
r3867r3868
1717#include "machine/6883sam.h"
1818#include "includes/coco.h"
1919#include "devices/basicdsk.h"
20#include "machine/wd17xx.h"
2021#include "machine/6551.h"
2122#include "formats/coco_dsk.h"
2223#include "formats/coco_cas.h"
r3867r3868
667668   MDRV_SNAPSHOT_ADD(coco_pak, "pak", 0)
668669
669670   MDRV_CASSETTE_ADD( "cassette", coco_cassette_config )
671   
672   MDRV_WD179X_ADD("wd179x", dragon_wd17xx_interface )
670673MACHINE_DRIVER_END
671674
672675static MACHINE_DRIVER_START( dragon64 )
r3867r3868
699702
700703   /* acia */
701704   MDRV_DEVICE_ADD("acia", ACIA6551)
705   
706   MDRV_WD179X_ADD("wd179x", dragon_wd17xx_interface )
702707MACHINE_DRIVER_END
703708
704709static MACHINE_DRIVER_START( d64plus )
r3867r3868
731736
732737   /* acia */
733738   MDRV_DEVICE_ADD("acia", ACIA6551)
739   
740   MDRV_WD179X_ADD("wd179x", dragon_wd17xx_interface )
734741MACHINE_DRIVER_END
735742
736743static MACHINE_DRIVER_START( dgnalpha )
r3867r3868
766773
767774   /* acia */
768775   MDRV_DEVICE_ADD("acia", ACIA6551)
776   
777   MDRV_WD179X_ADD("wd179x", dgnalpha_wd17xx_interface )
769778MACHINE_DRIVER_END
770779
771780static MACHINE_DRIVER_START( tanodr64 )
r3867r3868
798807
799808   /* acia */
800809   MDRV_DEVICE_ADD("acia", ACIA6551)
810   
811   MDRV_WD1773_ADD("wd1773", coco_wd17xx_interface )   
801812MACHINE_DRIVER_END
802813
803814static MACHINE_DRIVER_START( coco )
r3867r3868
831842
832843   /* cassette */
833844   MDRV_CASSETTE_ADD( "cassette", coco_cassette_config )
845   
846   MDRV_WD1773_ADD("wd1773", coco_wd17xx_interface )   
834847MACHINE_DRIVER_END
835848
836849static MACHINE_DRIVER_START( coco2 )
r3867r3868
864877
865878   /* cassette */
866879   MDRV_CASSETTE_ADD( "cassette", coco_cassette_config )
880   
881   MDRV_WD1773_ADD("wd1773", coco_wd17xx_interface )   
867882MACHINE_DRIVER_END
868883
869884static MACHINE_DRIVER_START( coco2b )
r3867r3868
897912
898913   /* cassette */
899914   MDRV_CASSETTE_ADD( "cassette", coco_cassette_config )
915   
916   MDRV_WD1773_ADD("wd1773", coco_wd17xx_interface )   
900917MACHINE_DRIVER_END
901918
902919static MACHINE_DRIVER_START( coco3 )
src/mess/drivers/concept.c
r3867r3868
3434#include "formats/basicdsk.h"
3535#include "devices/harddriv.h"
3636#include "machine/mm58274c.h"
37#include "machine/wd17xx.h"
3738
3839static ADDRESS_MAP_START(concept_memmap, ADDRESS_SPACE_PROGRAM, 16)
3940   AM_RANGE(0x000000, 0x000007) AM_ROM AM_REGION("main", 0x010000)    /* boot ROM mirror */
r3867r3868
9293
9394   /* via */
9495   MDRV_VIA6522_ADD("via6522_0", 1022750, concept_via6522_intf)
96   
97   MDRV_WD179X_ADD("wd179x", concept_wd17xx_interface )
9598MACHINE_DRIVER_END
9699
97100
src/mess/drivers/pcw16.c
r3867r3868
12021202   pcw16_trigger_fdc_int(machine);
12031203}
12041204
1205static device_config * pcw16_get_device(running_machine *machine )
1206{
1207   return (device_config*)device_list_find_by_tag( machine->config->devicelist, NEC765A, "nec765");   
1208}
1209
12051210static const struct pc_fdc_interface pcw16_fdc_interface=
12061211{
1207   NEC765A,
1208   NEC765_RDY_PIN_CONNECTED,
12091212   pcw16_fdc_interrupt,
1210   NULL
1213   NULL,
1214   NULL,
1215   pcw16_get_device
12111216};
12121217
12131218
r3867r3868
14231428
14241429   /* printer */
14251430   /* MDRV_DEVICE_ADD("printer", PRINTER) */
1431   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_connected_interface)
14261432MACHINE_DRIVER_END
14271433
14281434
src/mess/drivers/msx.c
r3867r3868
278278#include "deprecat.h"
279279#include "machine/8255ppi.h"
280280#include "machine/tc8521.h"
281#include "machine/wd17xx.h"
281282#include "video/tms9928a.h"
282283#include "video/v9938.h"
283284#include "includes/msx_slot.h"
r3867r3868
10651066   MDRV_DEVICE_ADD("printer", PRINTER)
10661067
10671068   MDRV_CASSETTE_ADD( "cassette", msx_cassette_config )
1069   
1070   MDRV_WD179X_ADD("wd179x", msx_wd17xx_interface )   
10681071MACHINE_DRIVER_END
10691072
10701073
r3867r3868
11321135
11331136   /* real time clock */
11341137   MDRV_DEVICE_ADD("rtc", TC8521)
1138   
1139   MDRV_WD179X_ADD("wd179x", msx_wd17xx_interface )   
11351140MACHINE_DRIVER_END
11361141
11371142
src/mess/drivers/b2m.c
r3867r3868
3838   AM_RANGE(0x14, 0x15) AM_DEVREADWRITE(PIC8259, "pic8259", pic8259_r, pic8259_w )
3939   AM_RANGE(0x18, 0x18) AM_DEVREADWRITE(MSM8251, "uart", msm8251_data_r,msm8251_data_w)
4040   AM_RANGE(0x19, 0x19) AM_DEVREADWRITE(MSM8251, "uart", msm8251_status_r,msm8251_control_w)
41     AM_RANGE(0x1c, 0x1c) AM_READWRITE(wd17xx_status_r,wd17xx_command_w)
42     AM_RANGE(0x1d, 0x1d) AM_READWRITE(wd17xx_track_r,wd17xx_track_w)
43     AM_RANGE(0x1e, 0x1e) AM_READWRITE(wd17xx_sector_r,wd17xx_sector_w)
44     AM_RANGE(0x1f, 0x1f) AM_READWRITE(wd17xx_data_r,wd17xx_data_w)   
41     AM_RANGE(0x1c, 0x1c) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_status_r,wd17xx_command_w)
42     AM_RANGE(0x1d, 0x1d) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_track_r,wd17xx_track_w)
43     AM_RANGE(0x1e, 0x1e) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_sector_r,wd17xx_sector_w)
44     AM_RANGE(0x1f, 0x1f) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_data_r,wd17xx_data_w)   
4545ADDRESS_MAP_END
4646
4747static ADDRESS_MAP_START( b2m_rom_io, ADDRESS_SPACE_IO, 8 )
r3867r3868
205205
206206   /* uart */
207207   MDRV_DEVICE_ADD("uart", MSM8251)
208   
209   MDRV_WD1793_ADD("wd1793", default_wd17xx_interface )
208210MACHINE_DRIVER_END
209211
210212static MACHINE_DRIVER_START( b2mrom )
r3867r3868
254256COMP( 1989, b2m,    0,        0,      b2m,       b2m,       b2m,     b2m,     "BNPO",                "Bashkiria-2M",    GAME_NOT_WORKING)
255257COMP( 1989, b2mrom,   b2m,    0,      b2mrom,      b2m,       b2m,     b2m,     "BNPO",                "Bashkiria-2M ROM-disk",    GAME_NOT_WORKING)
256258
259
src/mess/drivers/thomson.c
r3867r3868
760760/* modem */
761761     MDRV_DEVICE_ADD( "acia6850", ACIA6850 )
762762     MDRV_DEVICE_CONFIG( to7_modem )
763
763     
764     MDRV_WD2793_ADD("wd2793", default_wd17xx_interface )
764765MACHINE_DRIVER_END
765766
766767static MACHINE_DRIVER_START ( t9000 )
src/mess/drivers/cgenie.c
r3867r3868
432432   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.75)
433433
434434   MDRV_CASSETTE_ADD( "cassette", cgenie_cassette_config )
435
436   MDRV_WD179X_ADD("wd179x", cgenie_wd17xx_interface )
435437MACHINE_DRIVER_END
436438
437439/***************************************************************************
src/mess/drivers/scorpion.c
r3867r3868
157157#include "machine/wd17xx.h"
158158#include "machine/beta.h"
159159
160static MACHINE_START( scorpion )
161{
162   wd17xx_init(machine, WD_TYPE_179X, betadisk_wd179x_callback, NULL);
163}
164
165160/****************************************************************************************************/
166161/* Zs Scorpion 256 */
167162
r3867r3868
319314   scorpion_256_port_1ffd_data = 0;
320315
321316   scorpion_update_memory(machine);   
322     
323   wd17xx_reset(machine);   
324   
317         
325318   timer_pulse(machine, ATTOTIME_IN_HZ(50), NULL, 0, nmi_check_callback);
326319}
327320
r3867r3868
329322   MDRV_IMPORT_FROM( spectrum_128 )
330323   MDRV_CPU_MODIFY("main")
331324   MDRV_CPU_IO_MAP(scorpion_io, 0)
332   MDRV_MACHINE_START( scorpion )
333325   MDRV_MACHINE_RESET( scorpion )
326   
327   MDRV_WD179X_ADD("wd179x", beta_wd17xx_interface )
334328MACHINE_DRIVER_END
335329
336330
src/mess/drivers/specpls3.c
r3867r3868
170170static const nec765_interface spectrum_plus3_nec765_interface =
171171{
172172      NULL,
173      NULL
173      NULL,
174      NULL,
175      NEC765_RDY_PIN_CONNECTED
174176};
175177
176178
r3867r3868
185187static WRITE8_HANDLER(spectrum_plus3_port_3ffd_w)
186188{
187189      if (~input_port_read(space->machine, "CONFIG") & 0x20)
188            nec765_data_w(space, 0,data);
190            nec765_data_w((device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765"), 0,data);
189191}
190192
191193static  READ8_HANDLER(spectrum_plus3_port_3ffd_r)
r3867r3868
193195      if (input_port_read(space->machine, "CONFIG") & 0x20)
194196            return 0xff;
195197      else
196            return nec765_data_r(space, 0);
198            return nec765_data_r((device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765"), 0);
197199}
198200
199201
r3867r3868
202204      if (input_port_read(space->machine, "CONFIG") & 0x20)
203205            return 0xff;
204206      else
205            return nec765_status_r(space, 0);
207            return nec765_status_r((device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765"), 0);
206208}
207209
208210
r3867r3868
349351{
350352   memset(mess_ram,0,128*1024);
351353   
352   nec765_init(machine, &spectrum_plus3_nec765_interface, NEC765A, NEC765_RDY_PIN_CONNECTED);
353
354354   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 0), FLOPPY_DRIVE_SS_40);
355355   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 1), FLOPPY_DRIVE_SS_40);
356356
r3867r3868
370370   MDRV_SCREEN_REFRESH_RATE(50.01)
371371
372372   MDRV_MACHINE_RESET( spectrum_plus3 )
373   
374   MDRV_NEC765A_ADD("nec765", spectrum_plus3_nec765_interface)
373375MACHINE_DRIVER_END
374376
375377/***************************************************************************
src/mess/drivers/x68k.c
r3867r3868
727727// NEC uPD72065 at 0xe94000
728728static WRITE16_HANDLER( x68k_fdc_w )
729729{
730   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC72065, "nec72065");
730731   unsigned int drive, x;
731732   switch(offset)
732733   {
733734   case 0x00:
734735   case 0x01:
735      nec765_data_w(space, 0,data);
736      nec765_data_w(fdc, 0,data);
736737      break;
737738   case 0x02:  // drive option signal control
738739      x = data & 0x0f;
r3867r3868
801802{
802803   unsigned int ret;
803804   int x;
805   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC72065, "nec72065");
806   
804807   switch(offset)
805808   {
806809   case 0x00:
807      return nec765_status_r(space, 0);
810      return nec765_status_r(fdc, 0);
808811   case 0x01:
809      return nec765_data_r(space, 0);
812      return nec765_data_r(fdc, 0);
810813   case 0x02:
811814      ret = 0x00;
812815      for(x=0;x<4;x++)
r3867r3868
833836   }
834837}
835838
836static void fdc_irq(running_machine *machine,int state)
839static NEC765_INTERRUPT( fdc_irq )
837840{
838841   if((sys.ioc.irqstatus & 0x04) && state == ASSERT_LINE)
839842   {
r3867r3868
841844      sys.ioc.irqstatus |= 0x80;
842845      current_irq_line = 1;
843846      logerror("FDC: IRQ triggered\n");
844      cpu_set_input_line_and_vector(machine->cpu[0],1,ASSERT_LINE,current_vector[1]);
847      cpu_set_input_line_and_vector(device->machine->cpu[0],1,ASSERT_LINE,current_vector[1]);
845848   }
846849}
847850
848851static int x68k_fdc_read_byte(running_machine *machine,int addr)
849852{
850853   int data = -1;
854   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, NEC72065, "nec72065");
851855
852856   if(sys.fdc.drq_state != 0)
853      data = nec765_dack_r(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0);
857      data = nec765_dack_r(fdc, 0);
854858//  logerror("FDC: DACK reading\n");
855859   return data;
856860}
857861
858862static void x68k_fdc_write_byte(running_machine *machine,int addr, int data)
859863{
860   nec765_dack_w(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0, data);
864   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, NEC72065, "nec72065");
865   nec765_dack_w(fdc, 0, data);
861866}
862867
863static void fdc_drq(running_machine *machine,int state, int read_write)
868static NEC765_DMA_REQUEST ( fdc_drq )
864869{
865870   sys.fdc.drq_state = state;
866871}
r3867r3868
890895
891896static WRITE8_HANDLER( x68k_ct_w )
892897{
898   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC72065, "nec72065");
893899   // CT1 and CT2 bits from YM2151 port 0x1b
894900   // CT1 - ADPCM clock - 0 = 8MHz, 1 = 4MHz
895901   // CT2 - 1 = Set ready state of FDC
896   nec765_set_ready_state(data & 0x01);
902   nec765_set_ready_state(fdc,data & 0x01);
897903   sys.adpcm.clock = data & 0x02;
898904   x68k_set_adpcm(space->machine);
899905   okim6258_set_clock(0, data & 0x02 ? 4000000 : 8000000);
r3867r3868
16541660static const nec765_interface fdc_interface =
16551661{
16561662   fdc_irq,
1657   fdc_drq
1663   fdc_drq,
1664   NULL,
1665   NEC765_RDY_PIN_CONNECTED
16581666};
16591667
16601668static const ym2151_interface x68k_ym2151_interface =
r3867r3868
20082016   sys.crtc.reg[7] = 552;  // Vertical end
20092017   sys.crtc.reg[8] = 27;   // Horizontal adjust
20102018
2011   nec765_reset(machine, 0);
20122019   mfp_init();
20132020
20142021   x68k_scanline = video_screen_get_vpos(machine->primary_screen);// = sys.crtc.reg[6];  // Vertical start
r3867r3868
20692076
20702077   // start LED timer
20712078   timer_adjust_periodic(led_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(400));
2072
2073   nec765_init(machine, &fdc_interface,NEC72065,NEC765_RDY_PIN_CONNECTED);
2074   nec765_reset(machine, 0);
20752079}
20762080
20772081static DRIVER_INIT( x68000 )
r3867r3868
21722176    MDRV_SOUND_ROUTE(ALL_OUTPUTS, "right", 1.00)
21732177
21742178   MDRV_NVRAM_HANDLER( generic_0fill )
2179
2180   MDRV_NEC72065_ADD("nec72065", fdc_interface)   
21752181MACHINE_DRIVER_END
21762182
2177
21782183static SYSTEM_CONFIG_START(x68000)
21792184   CONFIG_DEVICE(x68k_floppy_getinfo)
21802185   CONFIG_RAM(0x100000)
src/mess/drivers/atarist.c
r3867r3868
4444
4545static void atarist_fdc_dma_transfer(running_machine *machine)
4646{
47   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD1772, "wd1772");
4748   const address_space *program = cputag_get_address_space(machine, "main", ADDRESS_SPACE_PROGRAM);
4849   atarist_state *state = machine->driver_data;
4950
r3867r3868
5556         {
5657            UINT8 data = memory_read_byte_8be(program, state->fdc_dmabase);
5758
58            wd17xx_data_w(program, 0, data);
59            wd17xx_data_w(fdc, 0, data);
5960         }
6061         else
6162         {
62            UINT8 data = wd17xx_data_r(program, 0);
63            UINT8 data = wd17xx_data_r(fdc, 0);
6364
6465            memory_write_byte_8be(program, state->fdc_dmabase, data);
6566         }
r3867r3868
8485   }
8586}
8687
87static void atarist_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param)
88static WD17XX_CALLBACK( atarist_fdc_callback )
8889{
89   atarist_state *state = machine->driver_data;
90   atarist_state *driver_state = device->machine->driver_data;
9091
91   switch (event)
92   switch (state)
9293   {
9394   case WD17XX_IRQ_SET:
94      state->fdc_irq = 1;
95      driver_state->fdc_irq = 1;
9596      break;
9697
9798   case WD17XX_IRQ_CLR:
98      state->fdc_irq = 0;
99      driver_state->fdc_irq = 0;
99100      break;
100101
101102   case WD17XX_DRQ_SET:
102      state->fdc_status |= ATARIST_FLOPPY_STATUS_FDC_DATA_REQUEST;
103      atarist_fdc_dma_transfer(machine);
103      driver_state->fdc_status |= ATARIST_FLOPPY_STATUS_FDC_DATA_REQUEST;
104      atarist_fdc_dma_transfer(device->machine);
104105      break;
105106
106107   case WD17XX_DRQ_CLR:
107      state->fdc_status &= ~ATARIST_FLOPPY_STATUS_FDC_DATA_REQUEST;
108      driver_state->fdc_status &= ~ATARIST_FLOPPY_STATUS_FDC_DATA_REQUEST;
108109      break;
109110   }
110111}
111112
113const wd17xx_interface atarist_wd17xx_interface = { atarist_fdc_callback, NULL };
114
112115static READ16_HANDLER( atarist_fdc_data_r )
113116{
114117   atarist_state *state = space->machine->driver_data;
118   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1772, "wd1772");
115119
116120   if (state->fdc_mode & ATARIST_FLOPPY_MODE_SECTOR_COUNT)
117121   {
r3867r3868
128132      }
129133      else
130134      {
131         return wd17xx_r(space, (state->fdc_mode & ATARIST_FLOPPY_MODE_ADDRESS_MASK) >> 1);
135         return wd17xx_r(fdc, (state->fdc_mode & ATARIST_FLOPPY_MODE_ADDRESS_MASK) >> 1);
132136      }
133137   }
134138}
r3867r3868
136140static WRITE16_HANDLER( atarist_fdc_data_w )
137141{
138142   atarist_state *state = space->machine->driver_data;
139
143   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1772, "wd1772");
144   
140145   if (state->fdc_mode & ATARIST_FLOPPY_MODE_SECTOR_COUNT)
141146   {
142147      if (data == 0)
r3867r3868
159164      }
160165      else
161166      {
162         wd17xx_w(space, (state->fdc_mode & ATARIST_FLOPPY_MODE_ADDRESS_MASK) >> 1, data);
167         wd17xx_w(fdc, (state->fdc_mode & ATARIST_FLOPPY_MODE_ADDRESS_MASK) >> 1, data);
163168      }
164169   }
165170}
r3867r3868
12781283
12791284static WRITE8_HANDLER( ym2149_port_a_w )
12801285{
1281   wd17xx_set_side(BIT(data, 0) ? 0 : 1);
1286   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1772, "wd1772");
1287   wd17xx_set_side(fdc, BIT(data, 0) ? 0 : 1);
12821288
12831289   if (!BIT(data, 1))
12841290   {
1285      wd17xx_set_drive(0);
1291      wd17xx_set_drive(fdc,0);
12861292   }
12871293
12881294   if (!BIT(data, 2))
12891295   {
1290      wd17xx_set_drive(1);
1296      wd17xx_set_drive(fdc,1);
12911297   }
12921298
12931299   // 0x08 = RTS
r3867r3868
14941500
14951501   /* configure devices */
14961502   centronics_config(0, atarist_centronics_config);
1497   wd17xx_init(machine, WD_TYPE_1772, atarist_fdc_callback, NULL);
14981503
14991504   /* set CPU interrupt callback */
15001505   cpu_set_irq_callback(machine->cpu[0], atarist_int_ack);
r3867r3868
15901595
15911596   /* configure devices */
15921597   centronics_config(0, atarist_centronics_config);
1593   wd17xx_init(machine, WD_TYPE_1772, atarist_fdc_callback, NULL);
1594
1598   
15951599   /* set CPU interrupt callback */
15961600   cpu_set_irq_callback(machine->cpu[0], atarist_int_ack);
15971601
r3867r3868
16491653
16501654static WRITE8_HANDLER( stbook_ym2149_port_a_w )
16511655{
1652   wd17xx_set_side((data & 0x01) ? 0 : 1);
1656   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1772, "wd1772");
1657   wd17xx_set_side(fdc,(data & 0x01) ? 0 : 1);
16531658
16541659   if (!(data & 0x02))
16551660   {
1656      wd17xx_set_drive(0);
1661      wd17xx_set_drive(fdc,0);
16571662   }
16581663
16591664   if (!(data & 0x04))
16601665   {
1661      wd17xx_set_drive(1);
1666      wd17xx_set_drive(fdc,1);
16621667   }
16631668
16641669   // 0x08 = RTS
r3867r3868
17441749
17451750   /* configure devices */
17461751   centronics_config(0, atarist_centronics_config);
1747   wd17xx_init(machine, WD_TYPE_1772, atarist_fdc_callback, NULL);
17481752   rp5c15_init(machine, &rtc_intf);
17491753
17501754   /* set CPU interrupt callback */
r3867r3868
18051809   MDRV_DEVICE_CONFIG(acia_ikbd_intf)
18061810   MDRV_DEVICE_ADD("acia_1", ACIA6850)
18071811   MDRV_DEVICE_CONFIG(acia_midi_intf)
1812   
1813   MDRV_WD1772_ADD("wd1772", atarist_wd17xx_interface )
18081814MACHINE_DRIVER_END
18091815
18101816static MACHINE_DRIVER_START( megast )
r3867r3868
18661872   MDRV_DEVICE_CONFIG(acia_ikbd_intf)
18671873   MDRV_DEVICE_ADD("acia_1", ACIA6850)
18681874   MDRV_DEVICE_CONFIG(acia_midi_intf)
1875   
1876   MDRV_WD1772_ADD("wd1772", atarist_wd17xx_interface )
18691877MACHINE_DRIVER_END
18701878
18711879static MACHINE_DRIVER_START( megaste )
r3867r3868
19191927   MDRV_DEVICE_CONFIG(stbook_acia_ikbd_intf)
19201928   MDRV_DEVICE_ADD("acia_1", ACIA6850)
19211929   MDRV_DEVICE_CONFIG(acia_midi_intf)
1930   
1931   MDRV_WD1772_ADD("wd1772", atarist_wd17xx_interface )
19221932MACHINE_DRIVER_END
19231933
19241934/* ROMs */
src/mess/drivers/geneve.c
r3867r3868
514514   /* tms9902 */
515515   MDRV_TMS9902_ADD("tms9902_0", tms9902_params_0)
516516   MDRV_TMS9902_ADD("tms9902_1", tms9902_params_1)
517   
518   MDRV_WD179X_ADD("wd179x", ti99_wd17xx_interface )
517519MACHINE_DRIVER_END
518520
519521
src/mess/drivers/sg1000.c
r3867r3868
194194   AM_RANGE(0xbe, 0xbe) AM_READWRITE(TMS9928A_vram_r, TMS9928A_vram_w)
195195   AM_RANGE(0xbf, 0xbf) AM_READWRITE(TMS9928A_register_r, TMS9928A_register_w)
196196   AM_RANGE(0xdc, 0xdf) AM_DEVREADWRITE(PPI8255, "ppi8255_0", ppi8255_r, ppi8255_w)
197   AM_RANGE(0xe0, 0xe0) AM_READ(nec765_status_r)
198   AM_RANGE(0xe1, 0xe1) AM_READWRITE(nec765_data_r, nec765_data_w)
197   AM_RANGE(0xe0, 0xe0) AM_DEVREAD(NEC765A, "nec765", nec765_status_r)
198   AM_RANGE(0xe1, 0xe1) AM_DEVREADWRITE(NEC765A, "nec765", nec765_data_r, nec765_data_w)
199199   AM_RANGE(0xe4, 0xe7) AM_DEVREADWRITE(PPI8255, "ppi8255_1", ppi8255_r, ppi8255_w)
200200   AM_RANGE(0xe8, 0xe8) AM_DEVREADWRITE(MSM8251, "uart", msm8251_data_r, msm8251_data_w)
201201   AM_RANGE(0xe9, 0xe9) AM_DEVREADWRITE(MSM8251, "uart", msm8251_status_r, msm8251_control_w)
r3867r3868
641641
642642static WRITE8_DEVICE_HANDLER( sf7000_ppi8255_c_w )
643643{
644   device_config *fdc = (device_config*)device_list_find_by_tag( device->machine->config->devicelist, NEC765A, "nec765");
644645   /*
645646        Signal  Description
646647
r3867r3868
659660   floppy_drive_set_ready_state(image_from_devtype_and_index(IO_FLOPPY, 0), 1, 0);
660661
661662   /* FDC terminal count */
662   nec765_set_tc_state(device->machine, data & 0x04);
663   nec765_set_tc_state(fdc, data & 0x04);
663664
664665   /* FDC reset */
665666   if (data & 0x08)
666667   {
667      nec765_reset(device->machine, 0);
668      nec765_reset(fdc, 0);
668669   }
669670
670671   /* ROM selection */
r3867r3868
695696};
696697
697698/* callback for /INT output from FDC */
698static void sf7000_fdc_interrupt(running_machine *machine,int state)
699static NEC765_INTERRUPT( sf7000_fdc_interrupt )
699700{
700   sg1000_state *driver_state = machine->driver_data; // TODO
701   sg1000_state *driver_state = device->machine->driver_data; // TODO
701702
702703   driver_state->fdc_irq = state;
703704}
704705
705static void sf7000_fdc_index_callback(const device_config *img, int state)
706static void sf7000_fdc_index_callback(const device_config *controller, const device_config *img, int state)
706707{
707708   sg1000_state *driver_state = img->machine->driver_data;
708709
r3867r3868
712713static const struct nec765_interface sf7000_nec765_interface =
713714{
714715   sf7000_fdc_interrupt,
715   NULL
716   NULL,
717   NULL,
718   NEC765_RDY_PIN_CONNECTED
716719};
717720
718721static const CENTRONICS_CONFIG sf7000_centronics_config[1] = {
r3867r3868
730733   TMS9928A_configure(&tms9928a_interface);
731734
732735   /* configure FDC */
733   nec765_init(machine, &sf7000_nec765_interface, NEC765A, NEC765_RDY_PIN_CONNECTED);
734736   floppy_drive_set_index_pulse_callback(image_from_devtype_and_index(IO_FLOPPY, 0), sf7000_fdc_index_callback);
735737
736738   /* configure PPI */
r3867r3868
856858
857859   /* uart */
858860   MDRV_DEVICE_ADD("uart", MSM8251)
861   
862   MDRV_NEC765A_ADD("nec765", sf7000_nec765_interface)     
859863MACHINE_DRIVER_END
860864
861865/* ROMs */
src/mess/drivers/exidy.c
r3867r3868
342342static MACHINE_START( exidy )
343343{
344344   MACHINE_START_CALL( exidyd );
345   wd17xx_init(machine, WD_TYPE_179X, NULL, NULL);
346345}
347346
348347static MACHINE_RESET( exidyd )
r3867r3868
375374
376375static  READ8_HANDLER ( exidy_wd179x_r )
377376{
377   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
378378   switch (offset & 0x03)
379379   {
380380   case 0:
381      return wd17xx_status_r(space, offset);
381      return wd17xx_status_r(fdc, offset);
382382   case 1:
383      return wd17xx_track_r(space, offset);
383      return wd17xx_track_r(fdc, offset);
384384   case 2:
385      return wd17xx_sector_r(space, offset);
385      return wd17xx_sector_r(fdc, offset);
386386   case 3:
387      return wd17xx_data_r(space, offset);
387      return wd17xx_data_r(fdc, offset);
388388   default:
389389      return 0xff;
390390   }
r3867r3868
392392
393393static WRITE8_HANDLER ( exidy_wd179x_w )
394394{
395   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
395396   switch (offset & 0x03)
396397   {
397398   case 0:
398      wd17xx_command_w(space, offset, data);
399      wd17xx_command_w(fdc, offset, data);
399400      return;
400401   case 1:
401      wd17xx_track_w(space, offset, data);
402      wd17xx_track_w(fdc, offset, data);
402403      return;
403404   case 2:
404      wd17xx_sector_w(space, offset, data);
405      wd17xx_sector_w(fdc, offset, data);
405406      return;
406407   case 3:
407      wd17xx_data_w(space, offset, data);
408      wd17xx_data_w(fdc, offset, data);
408409      return;
409410   default:
410411      break;
r3867r3868
825826
826827   MDRV_CASSETTE_ADD( "cassette1", exidy_cassette_config )
827828   MDRV_CASSETTE_ADD( "cassette2", exidy_cassette_config )
829   
830   MDRV_WD179X_ADD("wd179x", default_wd17xx_interface )
828831MACHINE_DRIVER_END
829832
830833static MACHINE_DRIVER_START( exidyd )
src/mess/drivers/pc8801.c
r3867r3868
463463static ADDRESS_MAP_START( pc8801fd_io , ADDRESS_SPACE_IO, 8)
464464   ADDRESS_MAP_GLOBAL_MASK(0xff)
465465   AM_RANGE(0xf8, 0xf8) AM_READ( pc8801fd_nec765_tc )
466   AM_RANGE(0xfa, 0xfa) AM_READ( nec765_status_r )
467   AM_RANGE(0xfb, 0xfb) AM_READWRITE( nec765_data_r, nec765_data_w )
466   AM_RANGE(0xfa, 0xfa) AM_DEVREAD(NEC765A, "nec765", nec765_status_r )
467   AM_RANGE(0xfb, 0xfb) AM_DEVREADWRITE(NEC765A, "nec765", nec765_data_r, nec765_data_w )
468468   AM_RANGE(0xfc, 0xff) AM_DEVREADWRITE( PPI8255, "ppi8255_1", ppi8255_r, ppi8255_w )
469469ADDRESS_MAP_END
470470
r3867r3868
559559   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
560560   MDRV_SOUND_ADD("beep", BEEP, 0)
561561   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
562   
563   MDRV_NEC765A_ADD("nec765", pc8801_fdc_interface)
562564MACHINE_DRIVER_END
563565
564566
src/mess/drivers/pcw.c
r3867r3868
104104#define VERBOSE 0
105105#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
106106
107static void pcw_fdc_interrupt(running_machine*,int);
107static NEC765_INTERRUPT( pcw_fdc_interrupt );
108108
109109// pointer to pcw ram
110110unsigned int roller_ram_addr;
r3867r3868
136136static const nec765_interface pcw_nec765_interface =
137137{
138138   pcw_fdc_interrupt,
139   NULL
139   NULL,
140   NULL,
141   NEC765_RDY_PIN_CONNECTED
140142};
141143
142144/* determines if int line is held or cleared */
r3867r3868
213215}
214216
215217/* fdc interrupt callback. set/clear fdc int */
216static void pcw_fdc_interrupt(running_machine *machine,int state)
218static NEC765_INTERRUPT( pcw_fdc_interrupt )
217219{
218220   pcw_system_status &= ~(1<<5);
219221
r3867r3868
223225      pcw_system_status |= (1<<5);
224226   }
225227
226   pcw_trigger_fdc_int(machine);
228   pcw_trigger_fdc_int(device->machine);
227229}
228230
229231
r3867r3868
431433
432434static WRITE8_HANDLER(pcw_system_control_w)
433435{
436   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
434437   LOG(("SYSTEM CONTROL: %d\n",data));
435438
436439   switch (data)
r3867r3868
516519      /* set fdc terminal count */
517520      case 5:
518521      {
519         nec765_set_tc_state(space->machine, 1);
522         nec765_set_tc_state(fdc, 1);
520523      }
521524      break;
522525
523526      /* clear fdc terminal count */
524527      case 6:
525528      {
526         nec765_set_tc_state(space->machine, 0);
529         nec765_set_tc_state(fdc, 0);
527530      }
528531      break;
529532
r3867r3868
650653
651654static READ8_HANDLER(pcw_fdc_r)
652655{
656   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
653657   /* from Jacob Nevins docs. FDC I/O is not fully decoded */
654658   if (offset & 1)
655659   {
656      return nec765_data_r(space, 0);
660      return nec765_data_r(fdc, 0);
657661   }
658662
659   return nec765_status_r(space, 0);
663   return nec765_status_r(fdc, 0);
660664}
661665
662666static WRITE8_HANDLER(pcw_fdc_w)
663667{
668   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
664669   /* from Jacob Nevins docs. FDC I/O is not fully decoded */
665670   if (offset & 1)
666671   {
667      nec765_data_w(space, 0,data);
672      nec765_data_w(fdc, 0,data);
668673   }
669674}
670675
r3867r3868
744749
745750static MACHINE_START( pcw )
746751{
747   nec765_init(machine, &pcw_nec765_interface,NEC765A,NEC765_RDY_PIN_CONNECTED);
748752   fdc_interrupt_code = 0;
749753   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 0), FLOPPY_DRIVE_DS_80);
750754}
r3867r3868
10031007   MDRV_SPEAKER_STANDARD_MONO("mono")
10041008   MDRV_SOUND_ADD("beep", BEEP, 0)
10051009   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
1010   
1011   MDRV_NEC765A_ADD("nec765", pcw_nec765_interface)
10061012MACHINE_DRIVER_END
10071013
10081014
src/mess/drivers/osi.c
r3867r3868
355355   C011 ACIAIO         DISK CONTROLLER ACIA I/O PORT
356356*/
357357
358static void osi470_index_callback(const device_config *img, int state)
358static void osi470_index_callback(const device_config *controller, const device_config *img, int state)
359359{
360360   osi_state *driver_state = img->machine->driver_data;
361361
src/mess/drivers/bw2.c
r3867r3868
284284   return INIT_FAIL;
285285}
286286
287static void bw2_wd17xx_callback(running_machine *machine, wd17xx_state_t state, void *param)
287static WD17XX_CALLBACK( bw2_wd17xx_callback )
288288{
289289   switch(state)
290290   {
291291      case WD17XX_IRQ_CLR:
292         cputag_set_input_line(machine, Z80_TAG, INPUT_LINE_IRQ0, CLEAR_LINE);
292         cputag_set_input_line(device->machine, Z80_TAG, INPUT_LINE_IRQ0, CLEAR_LINE);
293293         break;
294294
295295      case WD17XX_IRQ_SET:
296         cputag_set_input_line(machine, Z80_TAG, INPUT_LINE_IRQ0, HOLD_LINE);
296         cputag_set_input_line(device->machine, Z80_TAG, INPUT_LINE_IRQ0, HOLD_LINE);
297297         break;
298298
299299      case WD17XX_DRQ_CLR:
300         cputag_set_input_line(machine, Z80_TAG, INPUT_LINE_NMI, CLEAR_LINE);
300         cputag_set_input_line(device->machine, Z80_TAG, INPUT_LINE_NMI, CLEAR_LINE);
301301         break;
302302
303303      case WD17XX_DRQ_SET:
304         if (cpu_get_reg(machine->cpu[0], Z80_HALT))
304         if (cpu_get_reg(device->machine->cpu[0], Z80_HALT))
305305         {
306            cputag_set_input_line(machine, Z80_TAG, INPUT_LINE_NMI, HOLD_LINE);
306            cputag_set_input_line(device->machine, Z80_TAG, INPUT_LINE_NMI, HOLD_LINE);
307307         }
308308         break;
309309   }
r3867r3868
312312static READ8_HANDLER( bw2_wd2797_r )
313313{
314314   UINT8 result = 0xff;
315   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
315316
316317   switch (offset & 0x03)
317318   {
318319      case 0:
319         result = wd17xx_status_r(space, 0);
320         result = wd17xx_status_r(fdc, 0);
320321         break;
321322      case 1:
322         result = wd17xx_track_r(space, 0);
323         result = wd17xx_track_r(fdc, 0);
323324         break;
324325      case 2:
325         result = wd17xx_sector_r(space, 0);
326         result = wd17xx_sector_r(fdc, 0);
326327         break;
327328      case 3:
328         result = wd17xx_data_r(space, 0);
329         result = wd17xx_data_r(fdc, 0);
329330         break;
330331   }
331332
r3867r3868
334335
335336static WRITE8_HANDLER( bw2_wd2797_w )
336337{
338   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
337339   switch (offset & 0x3)
338340   {
339341      case 0:
r3867r3868
345347            {
346348               int side = BIT(data, 1);
347349
348               wd17xx_set_side(side);
350               wd17xx_set_side(fdc,side);
349351
350352               data &= ~0x02;
351353            }
352354         }
353355
354         wd17xx_command_w(space, 0, data);
356         wd17xx_command_w(fdc, 0, data);
355357
356358         break;
357359      case 1:
358         wd17xx_track_w(space, 0, data);
360         wd17xx_track_w(fdc, 0, data);
359361         break;
360362      case 2:
361         wd17xx_sector_w(space, 0, data);
363         wd17xx_sector_w(fdc, 0, data);
362364         break;
363365      case 3:
364         wd17xx_data_w(space, 0, data);
366         wd17xx_data_w(fdc, 0, data);
365367         break;
366368   };
367369}
r3867r3868
371373
372374static WRITE8_DEVICE_HANDLER( bw2_ppi8255_a_w )
373375{
376   device_config *fdc = (device_config*)device_list_find_by_tag( device->machine->config->devicelist, WD179X, "wd179x");
374377   /*
375378
376379      PA0     KB0 Keyboard line select 0
r3867r3868
391394   if (BIT(data, 4))
392395   {
393396      state->selected_drive = 0;
394      wd17xx_set_drive(state->selected_drive);
397      wd17xx_set_drive(fdc,state->selected_drive);
395398   }
396399
397400   if (BIT(data, 5))
398401   {
399402      state->selected_drive = 1;
400      wd17xx_set_drive(state->selected_drive);
403      wd17xx_set_drive(fdc,state->selected_drive);
401404   }
402405
403406   /* assumption: select is tied low */
r3867r3868
592595static MACHINE_START( bw2 )
593596{
594597   bw2_state *state = machine->driver_data;
598   device_config *fdc = (device_config*)device_list_find_by_tag( machine->config->devicelist, WD179X, "wd179x");
595599
600
596601   centronics_config(0, bw2_centronics_config);
597602
598   wd17xx_init(machine, WD_TYPE_179X, bw2_wd17xx_callback, NULL); // really WD2797
599   wd17xx_set_density(DEN_MFM_LO);
603   wd17xx_set_density(fdc,DEN_MFM_LO);
600604
601605   /* find devices */
602606   state->msm8251 = devtag_get_device(machine, MSM8251, MSM8251_TAG);
r3867r3868
824828   bw2_charram_r,
825829};
826830
831const wd17xx_interface bw2_wd17xx_interface = { bw2_wd17xx_callback, NULL };
832
827833static MACHINE_DRIVER_START( bw2 )
828834   MDRV_DRIVER_DATA(bw2_state)
829835
r3867r3868
861867
862868   /* uart */
863869   MDRV_DEVICE_ADD(MSM8251_TAG, MSM8251)
870     
871   MDRV_WD179X_ADD("wd179x", default_wd17xx_interface )         
864872MACHINE_DRIVER_END
865873
866874/***************************************************************************
src/mess/drivers/oric.c
r3867r3868
2727#include "sound/ay8910.h"
2828#include "machine/6522via.h"
2929#include "machine/6551.h"
30
30#include "machine/wd17xx.h"
3131#include "includes/apple2.h"
3232
3333/*
r3867r3868
388388
389389   /* via */
390390   MDRV_VIA6522_ADD( "via6522_0", 1000000, oric_6522_interface )
391   
392   MDRV_WD179X_ADD("wd179x", oric_wd17xx_interface )
391393MACHINE_DRIVER_END
392394
393395
src/mess/drivers/enterp.c
r3867r3868
172172};
173173
174174
175static void enterp_wd177x_callback(running_machine *machine, wd17xx_state_t event, void *param);
176175
177176static void enterprise_reset(running_machine *machine)
178177{
r3867r3868
235234
236235static MACHINE_START(enterprise)
237236{
238   wd17xx_init(machine, WD_TYPE_177X, enterp_wd177x_callback, NULL);
239237   add_reset_callback(machine, enterprise_reset);
240238}
241239
242240static READ8_HANDLER ( enterprise_wd177x_read )
243241{
242   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
244243   switch (offset & 0x03)
245244   {
246245   case 0:
247      return wd17xx_status_r(space, offset);
246      return wd17xx_status_r(fdc, offset);
248247   case 1:
249      return wd17xx_track_r(space, offset);
248      return wd17xx_track_r(fdc, offset);
250249   case 2:
251      return wd17xx_sector_r(space, offset);
250      return wd17xx_sector_r(fdc, offset);
252251   case 3:
253      return wd17xx_data_r(space, offset);
252      return wd17xx_data_r(fdc, offset);
254253   default:
255254      break;
256255   }
r3867r3868
260259
261260static WRITE8_HANDLER (   enterprise_wd177x_write )
262261{
262   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
263263   switch (offset & 0x03)
264264   {
265265   case 0:
266      wd17xx_command_w(space, offset, data);
266      wd17xx_command_w(fdc, offset, data);
267267      return;
268268   case 1:
269      wd17xx_track_w(space, offset, data);
269      wd17xx_track_w(fdc, offset, data);
270270      return;
271271   case 2:
272      wd17xx_sector_w(space, offset, data);
272      wd17xx_sector_w(fdc, offset, data);
273273      return;
274274   case 3:
275      wd17xx_data_w(space, offset, data);
275      wd17xx_data_w(fdc, offset, data);
276276      return;
277277   default:
278278      break;
r3867r3868
317317
318318static char EXDOS_CARD_R = 0;
319319
320static void enterp_wd177x_callback(running_machine *machine, wd17xx_state_t State, void *param)
320static WD17XX_CALLBACK( enterp_wd177x_callback )
321321{
322   if (State==WD17XX_IRQ_CLR)
322   if (state==WD17XX_IRQ_CLR)
323323   {
324324      EXDOS_CARD_R &= ~0x02;
325325   }
326326
327   if (State==WD17XX_IRQ_SET)
327   if (state==WD17XX_IRQ_SET)
328328   {
329329      EXDOS_CARD_R |= 0x02;
330330   }
331331
332   if (State==WD17XX_DRQ_CLR)
332   if (state==WD17XX_DRQ_CLR)
333333   {
334334      EXDOS_CARD_R &= ~0x080;
335335   }
336336
337   if (State==WD17XX_DRQ_SET)
337   if (state==WD17XX_DRQ_SET)
338338   {
339339      EXDOS_CARD_R |= 0x080;
340340   }
341341}
342342
343const wd17xx_interface enterp_wd17xx_interface = { enterp_wd177x_callback, NULL };
343344
344345
345346static WRITE8_HANDLER ( exdos_card_w )
346347{
348   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
347349   /* drive side */
348350   int head = (data>>4) & 0x01;
349351
350352   int drive = EXDOS_GetDriveSelection(data);
351353
352   wd17xx_set_drive(drive);
353   wd17xx_set_side(head);
354   wd17xx_set_drive(fdc,drive);
355   wd17xx_set_side(fdc,head);
354356}
355357
356358/* bit 0 - ??
r3867r3868
561563   MDRV_SOUND_ADD("custom", CUSTOM, 0)
562564   MDRV_SOUND_CONFIG(dave_custom_sound)
563565   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
566   
567   MDRV_WD177X_ADD("wd177x", enterp_wd17xx_interface )
564568MACHINE_DRIVER_END
565569
566570ROM_START( ep128 )
src/mess/drivers/at.c
r3867r3868
470470
471471   /* harddisk */
472472   MDRV_IMPORT_FROM( pc_hdc )
473   
474   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
473475MACHINE_DRIVER_END
474476
475477
r3867r3868
523525
524526   /* harddisk */
525527   MDRV_IMPORT_FROM( pc_hdc )
528   
529   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
526530MACHINE_DRIVER_END
527531
528532
r3867r3868
583587
584588   /* harddisk */
585589   MDRV_IMPORT_FROM( pc_hdc )
590   
591   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
586592MACHINE_DRIVER_END
587593
588594
r3867r3868
645651
646652   /* harddisk */
647653   MDRV_IMPORT_FROM( pc_hdc )
654   
655   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
648656MACHINE_DRIVER_END
649657
650658
r3867r3868
704712
705713   /* harddisk */
706714   MDRV_IMPORT_FROM( pc_hdc )
715   
716   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
707717MACHINE_DRIVER_END
708718
709719
src/mess/drivers/apf.c
r3867r3868
329329{
330330   pia_config(machine, 1,&apf_imagination_pia_interface);
331331   apf_common_init(machine);
332   wd17xx_init(machine, WD_TYPE_179X, NULL, NULL);
333332}
334333
335334static MACHINE_START( apf_m1000 )
r3867r3868
340339static WRITE8_HANDLER(apf_dischw_w)
341340{
342341   int drive;
342   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x");
343343
344344   /* bit 3 is index of drive to select */
345345   drive = (data>>3) & 0x01;
346346
347   wd17xx_set_drive(drive);
347   wd17xx_set_drive(fdc, drive);
348348
349349   logerror("disc w %04x %04x\n",offset,data);
350350}
r3867r3868
361361}
362362
363363static WRITE8_HANDLER(apf_wd179x_command_w)
364{
365   wd17xx_command_w(space, offset,~data);
364{   
365   wd17xx_command_w((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset,~data);
366366}
367367
368368static WRITE8_HANDLER(apf_wd179x_track_w)
369369{
370   wd17xx_track_w(space, offset,~data);
370   wd17xx_track_w((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset,~data);
371371}
372372
373373static WRITE8_HANDLER(apf_wd179x_sector_w)
374374{
375   wd17xx_sector_w(space, offset,~data);
375   wd17xx_sector_w((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset,~data);
376376}
377377
378378static WRITE8_HANDLER(apf_wd179x_data_w)
379379{
380   wd17xx_data_w(space, offset,~data);
380   wd17xx_data_w((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset,~data);
381381}
382382
383383static READ8_HANDLER(apf_wd179x_status_r)
384384{
385   return ~wd17xx_status_r(space, offset);
385   return ~wd17xx_status_r((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset);
386386}
387387
388388static READ8_HANDLER(apf_wd179x_track_r)
389389{
390   return ~wd17xx_track_r(space, offset);
390   return ~wd17xx_track_r((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset);
391391}
392392
393393static READ8_HANDLER(apf_wd179x_sector_r)
394394{
395   return ~wd17xx_sector_r(space, offset);
395   return ~wd17xx_sector_r((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset);
396396}
397397
398398static READ8_HANDLER(apf_wd179x_data_r)
399399{
400   return wd17xx_data_r(space, offset);
400   return wd17xx_data_r((device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD179X, "wd179x"), offset);
401401}
402402
403403static ADDRESS_MAP_START(apf_imagination_map, ADDRESS_SPACE_PROGRAM, 8)
r3867r3868
658658   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
659659
660660   MDRV_CASSETTE_ADD( "cassette", apf_cassette_config )
661   
662   MDRV_WD179X_ADD("wd179x", default_wd17xx_interface )   
661663MACHINE_DRIVER_END
662664
663
664665static MACHINE_DRIVER_START( apf_m1000 )
665666   MDRV_IMPORT_FROM( apf_imagination )
666667   MDRV_CPU_MODIFY( "main" )
src/mess/drivers/vector06.c
r3867r3868
2828   AM_RANGE( 0x00, 0x03) AM_READWRITE(vector_8255_1_r, vector_8255_1_w )
2929   AM_RANGE( 0x04, 0x07) AM_READWRITE(vector_8255_2_r, vector_8255_2_w )
3030   AM_RANGE( 0x0C, 0x0C) AM_WRITE ( vector06_color_set )
31   AM_RANGE( 0x18, 0x18) AM_READWRITE(wd17xx_data_r,wd17xx_data_w)       
32   AM_RANGE( 0x19, 0x19) AM_READWRITE(wd17xx_sector_r,wd17xx_sector_w)
33   AM_RANGE( 0x1A, 0x1A) AM_READWRITE(wd17xx_track_r,wd17xx_track_w)
34     AM_RANGE( 0x1B, 0x1B) AM_READWRITE(wd17xx_status_r,wd17xx_command_w)
31   AM_RANGE( 0x18, 0x18) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_data_r,wd17xx_data_w)       
32   AM_RANGE( 0x19, 0x19) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_sector_r,wd17xx_sector_w)
33   AM_RANGE( 0x1A, 0x1A) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_track_r,wd17xx_track_w)
34     AM_RANGE( 0x1B, 0x1B) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_status_r,wd17xx_command_w)
3535     AM_RANGE( 0x1C, 0x1C) AM_WRITE(vector_disc_w)
3636ADDRESS_MAP_END
3737
r3867r3868
185185   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
186186
187187   MDRV_CASSETTE_ADD( "cassette", vector_cassette_config )
188 
188   
189   MDRV_WD1793_ADD("wd1793", default_wd17xx_interface )     
189190MACHINE_DRIVER_END
190191
191192/* ROM definition */
src/mess/drivers/partner.c
r3867r3868
1111#include "cpu/i8085/i8085.h"
1212#include "machine/8255ppi.h"
1313#include "machine/8257dma.h"
14#include "machine/wd17xx.h"
1415#include "video/i8275.h"
1516#include "devices/cassette.h"
1617#include "devices/basicdsk.h"
r3867r3868
166167   MDRV_DEVICE_CONFIG(partner_dma)
167168
168169   MDRV_CASSETTE_ADD( "cassette", partner_cassette_config )
170   
171   MDRV_WD1793_ADD("wd1793", partner_wd17xx_interface )
169172MACHINE_DRIVER_END
170173
171174
src/mess/drivers/orion.c
r3867r3868
1212#include "cpu/i8085/i8085.h"
1313#include "machine/8255ppi.h"
1414#include "machine/mc146818.h"
15#include "machine/wd17xx.h"
1516#include "devices/basicdsk.h"
1617#include "devices/cassette.h"
1718#include "devices/cartslot.h"
r3867r3868
116117   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
117118
118119   MDRV_CASSETTE_ADD( "cassette", orion_cassette_config )
120   
121   MDRV_WD1793_ADD("wd1793", default_wd17xx_interface )     
119122MACHINE_DRIVER_END
120123
121124static MACHINE_DRIVER_START( orion128ms )
r3867r3868
170173   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
171174
172175   MDRV_CASSETTE_ADD( "cassette", orion_cassette_config )
176   
177   MDRV_WD1793_ADD("wd1793", default_wd17xx_interface )     
173178MACHINE_DRIVER_END
174179
175180static MACHINE_DRIVER_START( orionz80ms )
r3867r3868
214219   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
215220
216221   MDRV_CASSETTE_ADD( "cassette", orion_cassette_config )
222   
223   MDRV_WD1793_ADD("wd1793", default_wd17xx_interface )     
217224MACHINE_DRIVER_END
218225
219226
src/mess/drivers/bebox.c
r3867r3868
138138   MDRV_PCI_BUS_DEVICE(1, NULL, NULL, mpc105_pci_read, mpc105_pci_write)
139139   MDRV_PCI_BUS_DEVICE(1, NULL, NULL, cirrus5430_pci_read, cirrus5430_pci_write)
140140   /*MDRV_PCI_BUS_DEVICE(12, NULL, NULL, scsi53c810_pci_read, scsi53c810_pci_write)*/
141   
142   MDRV_SMC37C78_ADD("smc37c78", pc_fdc_nec765_connected_interface)
141143MACHINE_DRIVER_END
142144
143145static MACHINE_DRIVER_START( bebox2 )
src/mess/drivers/nascom1.c
r3867r3868
9898   AM_RANGE(0x01, 0x01) AM_READWRITE(nascom1_port_01_r, nascom1_port_01_w)
9999   AM_RANGE(0x02, 0x02) AM_READ(nascom1_port_02_r)
100100   AM_RANGE(0x04, 0x07) AM_DEVREADWRITE( Z80PIO, "z80pio", z80pio_r, z80pio_w )
101   AM_RANGE(0xe0, 0xe3) AM_READWRITE(wd17xx_r, wd17xx_w)
101   AM_RANGE(0xe0, 0xe3) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_r, wd17xx_w)
102102   AM_RANGE(0xe4, 0xe4) AM_READWRITE(nascom2_fdc_select_r, nascom2_fdc_select_w)
103103   AM_RANGE(0xe5, 0xe5) AM_READ(nascom2_fdc_status_r)
104104ADDRESS_MAP_END
r3867r3868
313313   MDRV_CPU_REPLACE("main", Z80, XTAL_16MHz/8)
314314   MDRV_CPU_IO_MAP(nascom2_io, 0)
315315
316   MDRV_MACHINE_START(nascom2)
317
318316   /* video hardware */
319317   MDRV_SCREEN_MODIFY("main")
320318   MDRV_SCREEN_SIZE(48 * 8, 16 * 14)
321319   MDRV_SCREEN_VISIBLE_AREA(0, 48 * 8 - 1, 0, 16 * 14 - 1)
322320   MDRV_GFXDECODE(nascom2)
323321   MDRV_VIDEO_UPDATE(nascom2)
322   
323   MDRV_WD1793_ADD("wd1793", nascom2_wd17xx_interface )
324324MACHINE_DRIVER_END
325325
326326
src/mess/drivers/newbrain.c
r3867r3868
542542
543543static WRITE8_HANDLER( fdc_auxiliary_w )
544544{
545   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
545546   /*
546547
547548      bit      description
r3867r3868
560561   floppy_drive_set_motor_state(image_from_devtype_and_index(IO_FLOPPY, 0), BIT(data, 0));
561562   floppy_drive_set_ready_state(image_from_devtype_and_index(IO_FLOPPY, 0), 1, 0);
562563
563   nec765_set_reset_state(space->machine, BIT(data, 1));
564   nec765_set_reset_state(fdc, BIT(data, 1));
564565
565   nec765_set_tc_state(space->machine, BIT(data, 2));
566   nec765_set_tc_state(fdc, BIT(data, 2));
566567}
567568
568569static READ8_HANDLER( fdc_control_r )
r3867r3868
971972static ADDRESS_MAP_START( newbrain_fdc_io_map, ADDRESS_SPACE_IO, 8 )
972973   ADDRESS_MAP_UNMAP_HIGH
973974   ADDRESS_MAP_GLOBAL_MASK(0xff)
974   AM_RANGE(0x00, 0x00) AM_READ(nec765_status_r)
975   AM_RANGE(0x01, 0x01) AM_READWRITE(nec765_data_r, nec765_data_w)
975   AM_RANGE(0x00, 0x00) AM_DEVREAD( NEC765A, "nec765", nec765_status_r)
976   AM_RANGE(0x01, 0x01) AM_DEVREADWRITE( NEC765A, "nec765", nec765_data_r, nec765_data_w)
976977   AM_RANGE(0x20, 0x20) AM_WRITE(fdc_auxiliary_w)
977978   AM_RANGE(0x40, 0x40) AM_READ(fdc_control_r)
978979ADDRESS_MAP_END
r3867r3868
10981099   acia_interrupt
10991100};
11001101
1101static void newbrain_fdc_interrupt(running_machine *machine, int state)
1102static NEC765_INTERRUPT( newbrain_fdc_interrupt )
11021103{
1103   newbrain_state *driver_state = machine->driver_data;
1104   newbrain_state *driver_state = device->machine->driver_data;
11041105
11051106   driver_state->fdc_int = state;
11061107}
11071108
1108static const struct nec765_interface newbrain_nec765_interface =
1109static const nec765_interface newbrain_nec765_interface =
11091110{
11101111   newbrain_fdc_interrupt,
1111   NULL
1112   NULL,
1113   NULL,
1114   NEC765_RDY_PIN_NOT_CONNECTED
11121115};
11131116
11141117static const z80ctc_interface newbrain_ctc_intf =
r3867r3868
11651168      memory_set_bank(machine, bank, 0);
11661169   }
11671170
1168   /* initialize devices */
1169
1170   nec765_init(machine, &newbrain_nec765_interface, NEC765A, NEC765_RDY_PIN_NOT_CONNECTED);
1171
11721171   /* allocate reset timer */
11731172   
11741173   state->reset_timer = timer_alloc(machine, reset_tick, NULL);
r3867r3868
12701269   /* acia */
12711270   MDRV_DEVICE_ADD("acia_0", ACIA6850)
12721271   MDRV_DEVICE_CONFIG(newbrain_acia_intf)   
1272     
1273   MDRV_NEC765A_ADD("nec765", newbrain_nec765_interface)   
12731274MACHINE_DRIVER_END
12741275
12751276static MACHINE_DRIVER_START( newbraim )
src/mess/drivers/einstein.c
r3867r3868
598598static WRITE8_HANDLER(einstein_fdc_w)
599599{
600600   int reg = offset & 0x03;
601   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
601602
602603   logerror("fdc w: PC: %04x %04x %02x\n",cpu_get_pc(space->machine->cpu[0]),offset,data);
603604
r3867r3868
605606   {
606607      case 0:
607608      {
608         wd17xx_command_w(space, reg, data);
609         wd17xx_command_w(fdc, reg, data);
609610      }
610611      break;
611612
612613      case 1:
613614      {
614         wd17xx_track_w(space, reg, data);
615         wd17xx_track_w(fdc, reg, data);
615616      }
616617      break;
617618
618619      case 2:
619620      {
620         wd17xx_sector_w(space, reg, data);
621         wd17xx_sector_w(fdc, reg, data);
621622      }
622623      break;
623624
624625      case 3:
625626      {
626         wd17xx_data_w(space, reg, data);
627         wd17xx_data_w(fdc, reg, data);
627628      }
628629      break;
629630   }
r3867r3868
633634static  READ8_HANDLER(einstein_fdc_r)
634635{
635636   int reg = offset & 0x03;
637   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
636638
637639   logerror("fdc r: PC: %04x %04x\n",cpu_get_pc(space->machine->cpu[0]),offset);
638640
r3867r3868
640642   {
641643      case 0:
642644      {
643         return wd17xx_status_r(space, reg);
645         return wd17xx_status_r(fdc, reg);
644646      }
645647      break;
646648
647649      case 1:
648650      {
649         return wd17xx_track_r(space, reg);
651         return wd17xx_track_r(fdc, reg);
650652      }
651653      break;
652654
653655      case 2:
654656      {
655         return wd17xx_sector_r(space, reg);
657         return wd17xx_sector_r(fdc, reg);
656658      }
657659      break;
658660
659661      case 3:
660662      {
661         return wd17xx_data_r(space, reg);
663         return wd17xx_data_r(fdc, reg);
662664      }
663665      break;
664666   }
r3867r3868
823825
824826static WRITE8_HANDLER(einstein_drive_w)
825827{
828   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD177X, "wd177x");
829
826830   /* bit 4: side select */
827831   /* bit 3: select drive 3 */
828832   /* bit 2: select drive 2 */
r3867r3868
831835
832836   logerror("drive w: PC: %04x %04x %02x\n",cpu_get_pc(space->machine->cpu[0]),offset,data);
833837
834   wd17xx_set_side((data>>4) & 0x01);
838   wd17xx_set_side(fdc,(data>>4) & 0x01);
835839
836840   if (data & 0x01)
837841   {
838      wd17xx_set_drive(0);
842      wd17xx_set_drive(fdc,0);
839843   }
840844   else
841845   if (data & 0x02)
842846   {
843      wd17xx_set_drive(1);
847      wd17xx_set_drive(fdc,1);
844848   }
845849   else
846850   if (data & 0x04)
847851   {
848      wd17xx_set_drive(2);
852      wd17xx_set_drive(fdc,2);
849853   }
850854   else
851855   if (data & 0x08)
852856   {
853      wd17xx_set_drive(3);
857      wd17xx_set_drive(fdc,3);
854858   }
855859}
856860
r3867r3868
14261430static MACHINE_START( einstein )
14271431{
14281432   TMS9928A_configure(&tms9928a_interface);
1429   wd17xx_init(machine, WD_TYPE_177X, NULL, NULL);
14301433
14311434   einstein_z80pio = device_list_find_by_tag( machine->config->devicelist, Z80PIO, "z80pio" );
14321435}
r3867r3868
17461749
17471750   /* uart */
17481751   MDRV_DEVICE_ADD("uart", MSM8251)
1752   
1753   MDRV_WD177X_ADD("wd177x", default_wd17xx_interface )
17491754MACHINE_DRIVER_END
17501755
17511756
src/mess/drivers/special.c
r3867r3868
5252   AM_RANGE(0xf1, 0xf1) AM_READWRITE(erik_rr_reg_r, erik_rr_reg_w)
5353   AM_RANGE(0xf2, 0xf2) AM_READWRITE(erik_rc_reg_r, erik_rc_reg_w)
5454   AM_RANGE(0xf3, 0xf3) AM_READWRITE(erik_disk_reg_r, erik_disk_reg_w)
55   AM_RANGE(0xf4, 0xf4) AM_READWRITE(wd17xx_status_r, wd17xx_command_w)
56   AM_RANGE(0xf5, 0xf5) AM_READWRITE(wd17xx_track_r, wd17xx_track_w)
57   AM_RANGE(0xf6, 0xf6) AM_READWRITE(wd17xx_sector_r, wd17xx_sector_w)
58   AM_RANGE(0xf7, 0xf7) AM_READWRITE(wd17xx_data_r, wd17xx_data_w)
55   AM_RANGE(0xf4, 0xf4) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_status_r, wd17xx_command_w)
56   AM_RANGE(0xf5, 0xf5) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_track_r, wd17xx_track_w)
57   AM_RANGE(0xf6, 0xf6) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_sector_r, wd17xx_sector_w)
58   AM_RANGE(0xf7, 0xf7) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_data_r, wd17xx_data_w)
5959ADDRESS_MAP_END
6060
6161static ADDRESS_MAP_START(specimx_mem, ADDRESS_SPACE_PROGRAM, 8)
r3867r3868
6666    AM_RANGE( 0xffc0, 0xffdf ) AM_RAMBANK(4)
6767    AM_RANGE( 0xffe0, 0xffe3 ) AM_READWRITE(specialist_keyboard_r,specialist_keyboard_w) // 8255 for keyboard
6868    AM_RANGE( 0xffe4, 0xffe7 ) AM_RAM //external 8255
69    AM_RANGE( 0xffe8, 0xffe8 ) AM_READWRITE(wd17xx_status_r,wd17xx_command_w)
70    AM_RANGE( 0xffe9, 0xffe9 ) AM_READWRITE(wd17xx_track_r,wd17xx_track_w)
71    AM_RANGE( 0xffea, 0xffea ) AM_READWRITE(wd17xx_sector_r,wd17xx_sector_w)
72    AM_RANGE( 0xffea, 0xffeb ) AM_READWRITE(wd17xx_data_r,wd17xx_data_w)
69    AM_RANGE( 0xffe8, 0xffe8 ) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_status_r,wd17xx_command_w)
70    AM_RANGE( 0xffe9, 0xffe9 ) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_track_r,wd17xx_track_w)
71    AM_RANGE( 0xffea, 0xffea ) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_sector_r,wd17xx_sector_w)
72    AM_RANGE( 0xffea, 0xffeb ) AM_DEVREADWRITE(WD1793, "wd1793", wd17xx_data_r,wd17xx_data_w)
7373    AM_RANGE( 0xffec, 0xffef ) AM_DEVREADWRITE(PIT8253, "pit8253", pit8253_r, pit8253_w)
7474    AM_RANGE( 0xfff0, 0xfff3 ) AM_READWRITE(specimx_disk_ctrl_r, specimx_disk_ctrl_w)
7575    AM_RANGE( 0xfff8, 0xfff8 ) AM_READWRITE(specimx_video_color_r,specimx_video_color_w)
r3867r3868
380380   MDRV_SOUND_ADD("custom", CUSTOM, 0)
381381   MDRV_SOUND_CONFIG(specimx_sound_interface)
382382   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
383     
384   MDRV_WD1793_ADD("wd1793", default_wd17xx_interface )   
383385MACHINE_DRIVER_END
384386
385387static MACHINE_DRIVER_START( erik )
r3867r3868
389391    MDRV_CPU_IO_MAP(erik_io_map, 0)
390392
391393    MDRV_MACHINE_RESET( erik )
392    MDRV_MACHINE_START( erik )
393394
394395   MDRV_PPI8255_ADD( "ppi8255", specialist_ppi8255_interface )
395396
r3867r3868
413414   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
414415
415416   MDRV_CASSETTE_ADD( "cassette", special_cassette_config )
417   
418   MDRV_WD1793_ADD("wd1793", default_wd17xx_interface )   
416419MACHINE_DRIVER_END
417420
418421/* ROM definition */
src/mess/drivers/osborne1.c
r3867r3868
3737#include "driver.h"
3838#include "cpu/z80/z80.h"
3939#include "devices/basicdsk.h"
40#include "machine/wd17xx.h"
4041#include "cpu/z80/z80daisy.h"
4142#include "includes/osborne1.h"
4243
r3867r3868
168169   MDRV_CPU_IO_MAP( osborne1_io, 0 )
169170   MDRV_CPU_CONFIG( osborne1_daisy_chain )
170171
171   MDRV_MACHINE_START( osborne1 )
172172   MDRV_MACHINE_RESET( osborne1 )
173173
174174   MDRV_DEVICE_ADD( "osborne1_daisy", OSBORNE1_DAISY )
r3867r3868
184184   MDRV_SPEAKER_STANDARD_MONO( "mono" )
185185   MDRV_SOUND_ADD( "beep", BEEP, 0 )
186186   MDRV_SOUND_ROUTE( ALL_OUTPUTS, "mono", 1.00 )
187   
188   MDRV_MB8877_ADD("mb8877", default_wd17xx_interface )
189   
187190MACHINE_DRIVER_END
188191
189192
src/mess/drivers/amstrad.c
r3867r3868
428428   amstrad_ppi_portc_w    /* port C write */
429429};
430430
431static void aleste_interrupt(running_machine *machine,int state)
431static NEC765_INTERRUPT( aleste_interrupt )
432432{
433433   if(state == CLEAR_LINE)
434434      aleste_fdc_int = 0;
r3867r3868
440440static const nec765_interface amstrad_nec765_interface =
441441{
442442   NULL,
443   NULL
443   NULL,
444   NULL,
445   NEC765_RDY_PIN_CONNECTED
444446};
445447
446448/* Aleste uses an 8272A, with the interrupt flag visible on PPI port B */
447449static const nec765_interface aleste_8272_interface =
448450{
449451   aleste_interrupt,
450   NULL
452   NULL,
453   NULL,
454   NEC765_RDY_PIN_CONNECTED   
451455};
452456
453457/* pointers to current ram configuration selected for banks */
r3867r3868
12421246
12431247static READ8_HANDLER ( AmstradCPC_ReadPortHandler )
12441248{
1249   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
12451250   unsigned char data = 0xFF;
12461251   unsigned int r1r0 = (unsigned int)((offset & 0x0300) >> 8);
12471252   m6845_personality_t crtc_type;
r3867r3868
13241329            int b8b0 = ((offset & (1<<8)) >> (8 - 1)) | (offset & (0x01));
13251330            switch (b8b0) {
13261331              case 0x02: {
1327                    data = nec765_status_r(space, 0);
1332                    data = nec765_status_r(fdc, 0);
13281333              } break;
13291334              case 0x03: {
1330                    data = nec765_data_r(space, 0);
1335                    data = nec765_data_r(fdc, 0);
13311336              } break;
13321337              default: {
13331338              } break;
r3867r3868
13411346/* Offset handler for write */
13421347static WRITE8_HANDLER ( AmstradCPC_WritePortHandler )
13431348{
1349   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, NEC765A, "nec765");
13441350   if ((offset & (1<<15)) == 0)
13451351   {
13461352      if(aleste_mode & 0x04) // Aleste mode
r3867r3868
14561462           break;
14571463
14581464        case 0x03: /* Write Data register of FDC */
1459               nec765_data_w(space, 0,data);
1465               nec765_data_w(fdc, 0,data);
14601466            break;
14611467            default:
14621468            break;
r3867r3868
20442050
20452051   if(amstrad_system_type != SYSTEM_GX4000)
20462052   {
2047      nec765_init(machine, &amstrad_nec765_interface,NEC765A/*?*/,NEC765_RDY_PIN_CONNECTED);
20482053      floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 0),  FLOPPY_DRIVE_SS_40);
20492054      floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 1),  FLOPPY_DRIVE_SS_40);
20502055   }
r3867r3868
22422247   amstrad_common_init(machine);
22432248   amstrad_reset_machine(machine);
22442249
2245   nec765_init(machine, &aleste_8272_interface,NEC765A,NEC765_RDY_PIN_CONNECTED);
22462250   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 0),  FLOPPY_DRIVE_DS_80);
22472251   floppy_drive_set_geometry(image_from_devtype_and_index(IO_FLOPPY, 1),  FLOPPY_DRIVE_DS_80);
22482252}
r3867r3868
29842988   MDRV_SNAPSHOT_ADD(amstrad, "sna", 0)
29852989
29862990   MDRV_CASSETTE_ADD( "cassette", amstrad_cassette_config )
2991   
2992   MDRV_NEC765A_ADD("nec765", amstrad_nec765_interface)
29872993MACHINE_DRIVER_END
29882994
29892995
r3867r3868
30323038   MDRV_DEVICE_REMOVE("printer", PRINTER)
30333039
30343040   MDRV_CASSETTE_REMOVE( "cassette" )
3041   MDRV_NEC765A_REMOVE( "nec765" )
30353042MACHINE_DRIVER_END
30363043
30373044
r3867r3868
30453052   MDRV_PALETTE_LENGTH(32+64)
30463053   MDRV_PALETTE_INIT(aleste)
30473054   MDRV_NVRAM_HANDLER(mc146818)
3055   MDRV_NEC765A_MODIFY("nec765", aleste_8272_interface)
30483056MACHINE_DRIVER_END
30493057
30503058
src/mess/drivers/a310.c
r3867r3868
177177   a310_memc_reset();
178178}
179179
180static void a310_wd177x_callback(running_machine *machine, wd17xx_state_t event, void *param)
180static WD17XX_CALLBACK ( a310_wd177x_callback )
181181{
182   switch (event)
182   switch (state)
183183   {
184184      case WD17XX_IRQ_CLR:
185185         a310_iocregs[12] &= ~A310_FIQ_FLOPPY;
186186         break;
187187
188188      case WD17XX_IRQ_SET:
189         a310_request_fiq(machine, A310_FIQ_FLOPPY);
189         a310_request_fiq(device->machine, A310_FIQ_FLOPPY);
190190         break;
191191
192192      case WD17XX_DRQ_CLR:
r3867r3868
194194         break;
195195
196196      case WD17XX_DRQ_SET:
197         a310_request_fiq(machine, A310_FIQ_FLOPPY_DRQ);
197         a310_request_fiq(device->machine, A310_FIQ_FLOPPY_DRQ);
198198         break;
199199   }
200200}
r3867r3868
203203static MACHINE_START( a310 )
204204{
205205   a310_pagesize = 0;
206   wd17xx_init(machine, WD_TYPE_1772, a310_wd177x_callback, NULL);
207206
208207   vbl_timer = timer_alloc(machine, a310_vblank, NULL);
209208   timer_adjust_oneshot(vbl_timer, attotime_never, 0);
r3867r3868
367366
368367static READ32_HANDLER(ioc_r)
369368{
369   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1772, "wd1772");   
370370   if (offset >= 0x80000 && offset < 0xc0000)
371371   {
372372      switch (offset & 0x1f)
r3867r3868
407407   else if (offset >= 0xc4000 && offset <= 0xc4010)
408408   {
409409      logerror("17XX: R @ addr %x mask %08x\n", offset*4, mem_mask);
410      return wd17xx_data_r(space, offset&0xf);
410      return wd17xx_data_r(fdc, offset&0xf);
411411   }
412412   else
413413   {
r3867r3868
420420
421421static WRITE32_HANDLER(ioc_w)
422422{
423   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1772, "wd1772");   
423424   if (offset >= 0x80000 && offset < 0xc0000)
424425   {
425426//      logerror("IOC: W %02x @ reg %s (PC=%x)\n", data&0xff, ioc_regnames[offset&0x1f], cpu_get_pc( space->cpu ));
r3867r3868
504505   else if (offset >= 0xc4000 && offset <= 0xc4010)
505506   {
506507      logerror("17XX: %x to addr %x mask %08x\n", data, offset*4, mem_mask);
507      wd17xx_data_w(space, offset&0xf, data&0xff);
508      wd17xx_data_w(fdc, offset&0xf, data&0xff);
508509   }
509510   else if (offset == 0xd40006)
510511   {
511512      // latch A
512513      if (data & 1)
513514      {
514         wd17xx_set_drive(0);
515         wd17xx_set_drive(fdc,0);
515516      }
516517      if (data & 2)
517518      {
518         wd17xx_set_drive(1);
519         wd17xx_set_drive(fdc,1);
519520      }
520521      if (data & 4)
521522      {
522         wd17xx_set_drive(2);
523         wd17xx_set_drive(fdc,2);
523524      }
524525      if (data & 8)
525526      {
526         wd17xx_set_drive(3);
527         wd17xx_set_drive(fdc,3);
527528      }
528529
529      wd17xx_set_side((data & 0x10)>>4);
530      wd17xx_set_side(fdc,(data & 0x10)>>4);
530531
531532   }
532533   else if (offset == 0xd40010)
533534   {
534535      // latch B
535      wd17xx_set_density((data & 2) ? DEN_MFM_LO : DEN_MFM_HI);
536      wd17xx_set_density(fdc,(data & 2) ? DEN_MFM_LO : DEN_MFM_HI);
536537   }
537538   else
538539   {
r3867r3868
856857   PORT_BIT (0xf8, 0x80, IPT_UNUSED)
857858INPUT_PORTS_END
858859
860const wd17xx_interface a310_wd17xx_interface = {
861   a310_wd177x_callback,
862   NULL
863};
859864
860865static MACHINE_DRIVER_START( a310 )
861866   /* basic machine hardware */
r3867r3868
880885   MDRV_SPEAKER_STANDARD_MONO("a310")
881886   MDRV_SOUND_ADD("dac", DAC, 0)
882887   MDRV_SOUND_ROUTE(0, "a310", 1.00)
888   
889   MDRV_WD1772_ADD("wd1772", a310_wd17xx_interface )
883890MACHINE_DRIVER_END
884891
885
886892ROM_START(a310)
887893   ROM_REGION(0x800000, "main", 0)
888894   ROM_SYSTEM_BIOS(0, "311", "RiscOS 3.11 (29 Sep 1992)")
r3867r3868
900906/*    YEAR  NAME  PARENT  COMPAT  MACHINE  INPUT     INIT  CONFIG  COMPANY  FULLNAME */
901907COMP( 1988, a310, 0,      0,      a310,    a310,  a310, NULL,   "Acorn", "Archimedes 310 (Risc OS 3.11)", GAME_NOT_WORKING)
902908
909
src/mess/drivers/samcoupe.c
r3867r3868
8080
8181static READ8_HANDLER( samcoupe_disk_r )
8282{
83   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1772, "wd1772");
84   
8385   /* drive and side is encoded into bit 5 and 3 */
84   wd17xx_set_drive((offset >> 4) & 1);
85   wd17xx_set_side((offset >> 2) & 1);
86   wd17xx_set_drive(fdc,(offset >> 4) & 1);
87   wd17xx_set_side(fdc,(offset >> 2) & 1);
8688
8789   /* bit 1 and 2 select the controller register */
8890   switch (offset & 0x03)
8991   {
90   case 0: return wd17xx_status_r(space, 0);
91   case 1: return wd17xx_track_r(space, 0);
92   case 2: return wd17xx_sector_r(space, 0);
93   case 3: return wd17xx_data_r(space, 0);
92   case 0: return wd17xx_status_r(fdc, 0);
93   case 1: return wd17xx_track_r(fdc, 0);
94   case 2: return wd17xx_sector_r(fdc, 0);
95   case 3: return wd17xx_data_r(fdc, 0);
9496   }
9597
9698   return 0xff;
r3867r3868
99101
100102static WRITE8_HANDLER( samcoupe_disk_w )
101103{
104   device_config *fdc = (device_config*)device_list_find_by_tag( space->machine->config->devicelist, WD1772, "wd1772");
105
102106   /* drive and side is encoded into bit 5 and 3 */
103   wd17xx_set_drive((offset >> 4) & 1);
104   wd17xx_set_side((offset >> 2) & 1);
107   wd17xx_set_drive(fdc,(offset >> 4) & 1);
108   wd17xx_set_side(fdc,(offset >> 2) & 1);
105109
106110   /* bit 1 and 2 select the controller register */
107111   switch (offset & 0x03)
108112   {
109   case 0: wd17xx_command_w(space, 0, data); break;
110   case 1: wd17xx_track_w(space, 0, data);   break;
111   case 2: wd17xx_sector_w(space, 0, data);  break;
112   case 3: wd17xx_data_w(space, 0, data);    break;
113   case 0: wd17xx_command_w(fdc, 0, data); break;
114   case 1: wd17xx_track_w(fdc, 0, data);   break;
115   case 2: wd17xx_sector_w(fdc, 0, data);  break;
116   case 3: wd17xx_data_w(fdc, 0, data);    break;
113117   }
114118}
115119
r3867r3868
517521   MDRV_CPU_IO_MAP(samcoupe_io, 0)
518522   MDRV_CPU_VBLANK_INT("main", samcoupe_frame_interrupt)
519523
520   MDRV_MACHINE_START(samcoupe)
521524   MDRV_MACHINE_RESET(samcoupe)
522525
523526    /* video hardware */
r3867r3868
540543   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
541544   MDRV_SOUND_ADD("saa1099", SAA1099, SAMCOUPE_XTAL_X1/3) /* 8 MHz */
542545   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
546   
547   MDRV_WD1772_ADD("wd1772", default_wd17xx_interface )   
543548MACHINE_DRIVER_END
544549
545550
546
547551/*************************************
548552 *
549553 *  ROM definitions
src/mess/drivers/comx35.c
r3867r3868
390390   MDRV_QUICKLOAD_ADD(comx35, "comx", 0)
391391
392392   MDRV_CASSETTE_ADD( "cassette", comx35_cassette_config )
393
394   MDRV_WD1770_ADD("wd1770", comx35_wd17xx_interface )   
393395MACHINE_DRIVER_END
394396
395397static MACHINE_DRIVER_START( comx35n )
src/mess/drivers/trs80.c
r3867r3868
9494#define FW   TRS80_FONT_W
9595#define FH   TRS80_FONT_H
9696
97static READ8_HANDLER (trs80_wd179x_r)
97static READ8_DEVICE_HANDLER (trs80_wd179x_r)
9898{
99   if (input_port_read(space->machine, "CONFIG") & 0x80)
99   if (input_port_read(device->machine, "CONFIG") & 0x80)
100100   {
101      return wd17xx_status_r(space, offset);
101      return wd17xx_status_r(device, offset);
102102   }
103103   else
104104   {
r3867r3868
125125   AM_RANGE(0x37e0, 0x37e3) AM_READWRITE(trs80_irq_status_r, trs80_motor_w)
126126   AM_RANGE(0x37e4, 0x37e7) AM_NOP
127127   AM_RANGE(0x37e8, 0x37eb) AM_READWRITE(trs80_printer_r, trs80_printer_w)
128   AM_RANGE(0x37ec, 0x37ec) AM_READWRITE(trs80_wd179x_r, wd17xx_command_w)
129   AM_RANGE(0x37ed, 0x37ed) AM_READWRITE(wd17xx_track_r, wd17xx_track_w)
130   AM_RANGE(0x37ee, 0x37ee) AM_READWRITE(wd17xx_sector_r, wd17xx_sector_w)
131   AM_RANGE(0x37ef, 0x37ef) AM_READWRITE(wd17xx_data_r, wd17xx_data_w)
128   AM_RANGE(0x37ec, 0x37ec) AM_DEVREADWRITE(WD179X, "wd179x", trs80_wd179x_r, wd17xx_command_w)
129   AM_RANGE(0x37ed, 0x37ed) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_track_r, wd17xx_track_w)
130   AM_RANGE(0x37ee, 0x37ee) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_sector_r, wd17xx_sector_w)
131   AM_RANGE(0x37ef, 0x37ef) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_data_r, wd17xx_data_w)
132132   AM_RANGE(0x37f0, 0x37ff) AM_NOP
133133   AM_RANGE(0x3800, 0x38ff) AM_READ(trs80_keyboard_r)
134134   AM_RANGE(0x3900, 0x3bff) AM_NOP
r3867r3868
159159   AM_RANGE(0xea, 0xea) AM_NOP
160160   AM_RANGE(0xeb, 0xeb) AM_NOP
161161   AM_RANGE(0xec, 0xec) AM_WRITENOP
162   AM_RANGE(0xf0, 0xf0) AM_READWRITE(trs80_wd179x_r, wd17xx_command_w)
163   AM_RANGE(0xf1, 0xf1) AM_READWRITE(wd17xx_track_r, wd17xx_track_w)
164   AM_RANGE(0xf2, 0xf2) AM_READWRITE(wd17xx_sector_r, wd17xx_sector_w)
165   AM_RANGE(0xf3, 0xf3) AM_READWRITE(wd17xx_data_r, wd17xx_data_w)
162   AM_RANGE(0xf0, 0xf0) AM_DEVREADWRITE(WD179X, "wd179x", trs80_wd179x_r, wd17xx_command_w)
163   AM_RANGE(0xf1, 0xf1) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_track_r, wd17xx_track_w)
164   AM_RANGE(0xf2, 0xf2) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_sector_r, wd17xx_sector_w)
165   AM_RANGE(0xf3, 0xf3) AM_DEVREADWRITE(WD179X, "wd179x", wd17xx_data_r, wd17xx_data_w)
166166   AM_RANGE(0xf4, 0xf4) AM_WRITENOP
167167   AM_RANGE(0xf8, 0xf8) AM_WRITENOP
168168   AM_RANGE(0xff, 0xff) AM_READWRITE(trs80_port_ff_r, trs80_port_ff_w)
r3867r3868
386386   MDRV_CPU_PERIODIC_INT(trs80_timer_interrupt, 40)
387387   MDRV_INTERLEAVE(1)
388388
389   MDRV_MACHINE_START( trs80 )
390389   MDRV_MACHINE_RESET( trs80 )
391390
392391    /* video hardware */
r3867r3868
412411   MDRV_QUICKLOAD_ADD(trs80_cmd, "cmd", 0.5)
413412
414413   MDRV_CASSETTE_ADD( "cassette", default_cassette_config )
414   
415   MDRV_WD179X_ADD("wd179x", trs80_wd17xx_interface )
415416MACHINE_DRIVER_END
416417
417
418418static MACHINE_DRIVER_START( model1 )
419419   MDRV_IMPORT_FROM( level1 )
420420   MDRV_CPU_MODIFY( "main" )
src/mess/drivers/svi318.c
r3867r3868
1414#include "includes/svi318.h"
1515#include "video/tms9928a.h"
1616#include "machine/8255ppi.h"
17#include "machine/wd17xx.h"
1718#include "devices/basicdsk.h"
1819#include "devices/printer.h"
1920#include "devices/cartslot.h"
r3867r3868
303304   MDRV_DEVICE_ADD("printer", PRINTER)
304305
305306   MDRV_CASSETTE_ADD( "cassette", svi318_cassette_config )
307     
308   MDRV_WD179X_ADD("wd179x", svi_wd17xx_interface )
306309MACHINE_DRIVER_END
307310
308311static MACHINE_DRIVER_START( svi318n )
src/mess/drivers/pc.c
r3867r3868
13671367
13681368   /* harddisk */
13691369   MDRV_IMPORT_FROM( pc_hdc )
1370   
1371   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
13701372MACHINE_DRIVER_END
13711373
13721374
r3867r3868
14211423
14221424   /* harddisk */
14231425   MDRV_IMPORT_FROM( pc_hdc )
1426   
1427   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
14241428MACHINE_DRIVER_END
14251429
14261430static const cassette_config ibm5150_cassette_config =
r3867r3868
14871491   MDRV_IMPORT_FROM( pc_hdc )
14881492
14891493   MDRV_CASSETTE_ADD( "cassette", ibm5150_cassette_config )
1494   
1495   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)   
14901496MACHINE_DRIVER_END
14911497
14921498static MACHINE_DRIVER_START( pccga )
r3867r3868
15411547
15421548   /* harddisk */
15431549   MDRV_IMPORT_FROM( pc_hdc )
1550   
1551   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
15441552MACHINE_DRIVER_END
15451553
15461554
r3867r3868
15881596
15891597   /* harddisk */
15901598   MDRV_IMPORT_FROM( pc_hdc )
1599   
1600   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
15911601MACHINE_DRIVER_END
15921602
15931603
r3867r3868
16411651
16421652   /* harddisk */
16431653   MDRV_IMPORT_FROM( pc_hdc )
1654   
1655   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
16441656MACHINE_DRIVER_END
16451657
16461658
r3867r3868
16811693
16821694   /* harddisk */
16831695   MDRV_IMPORT_FROM( pc_hdc )
1696   
1697   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
16841698MACHINE_DRIVER_END
16851699
16861700
r3867r3868
17231737
17241738   /* harddisk */
17251739   MDRV_IMPORT_FROM( pc_hdc )
1740   
1741   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
17261742MACHINE_DRIVER_END
17271743
17281744
r3867r3868
17681784
17691785   /* harddisk */
17701786   MDRV_IMPORT_FROM( pc_hdc )
1787   
1788   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
17711789MACHINE_DRIVER_END
17721790
17731791
r3867r3868
18171835
18181836   /* harddisk */
18191837   MDRV_IMPORT_FROM( pc_hdc )
1838   
1839   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
18201840MACHINE_DRIVER_END
18211841
18221842
r3867r3868
18591879
18601880   /* harddisk */
18611881   MDRV_IMPORT_FROM( pc_hdc )
1882   
1883   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
18621884MACHINE_DRIVER_END
18631885
18641886
r3867r3868
19001922   MDRV_DEVICE_ADD("printer3", PRINTER)
19011923
19021924   MDRV_CASSETTE_ADD( "cassette", ibm5150_cassette_config )
1925   
1926   MDRV_NEC765A_ADD("nec765", pc_fdc_nec765_not_connected_interface)
19031927MACHINE_DRIVER_END
19041928
19051929#if 0
src/mess/drivers/ti99_4x.c
r3867r3868
552552   /* tms9902 */
553553   MDRV_TMS9902_ADD("tms9902_0", tms9902_params_0)
554554   MDRV_TMS9902_ADD("tms9902_1", tms9902_params_1)     
555   
556   MDRV_WD179X_ADD("wd179x", ti99_wd17xx_interface )
555557MACHINE_DRIVER_END
556558
557559static MACHINE_DRIVER_START(ti99_4_50hz)
r3867r3868
598600   /* tms9902 */
599601   MDRV_TMS9902_ADD("tms9902_0", tms9902_params_0)
600602   MDRV_TMS9902_ADD("tms9902_1", tms9902_params_1)     
603   
604   MDRV_WD179X_ADD("wd179x", ti99_wd17xx_interface )
601605MACHINE_DRIVER_END
602606
603607static MACHINE_DRIVER_START(ti99_4a_60hz)
r3867r3868
645649   /* tms9902 */
646650   MDRV_TMS9902_ADD("tms9902_0", tms9902_params_0)
647651   MDRV_TMS9902_ADD("tms9902_1", tms9902_params_1)     
652   
653   MDRV_WD179X_ADD("wd179x", ti99_wd17xx_interface )   
648654MACHINE_DRIVER_END
649655
650656
r3867r3868
692698   /* tms9902 */
693699   MDRV_TMS9902_ADD("tms9902_0", tms9902_params_0)
694700   MDRV_TMS9902_ADD("tms9902_1", tms9902_params_1)   
701   
702   MDRV_WD179X_ADD("wd179x", ti99_wd17xx_interface )
695703MACHINE_DRIVER_END
696704
697705
r3867r3868
746754   MDRV_TMS9901_ADD("tms9901", tms9901reset_param_ti99_4x)
747755   /* tms9902 */
748756   MDRV_TMS9902_ADD("tms9902_0", tms9902_params_0)
749   MDRV_TMS9902_ADD("tms9902_1", tms9902_params_1)     
757   MDRV_TMS9902_ADD("tms9902_1", tms9902_params_1)
758   
759   MDRV_WD179X_ADD("wd179x", ti99_wd17xx_interface )     
750760MACHINE_DRIVER_END
751761
752762
src/mess/drivers/bbc.c
r3867r3868
770770   MDRV_MACHINE_RESET( bbcb )
771771   MDRV_VIDEO_START( bbcb )
772772   MDRV_VIA6522_ADD("via6522_1", 1000000, bbcb_user_via)
773
774   MDRV_WD177X_ADD("wd177x", bbc_wd17xx_interface )
773775MACHINE_DRIVER_END
774776
775777
r3867r3868
781783   MDRV_MACHINE_RESET( bbcbp )
782784   MDRV_VIDEO_START( bbcbp )
783785   MDRV_VIA6522_ADD("via6522_1", 1000000, bbcb_user_via)
786   MDRV_WD177X_ADD("wd177x", bbc_wd17xx_interface )
784787MACHINE_DRIVER_END
785788
786789
r3867r3868
792795   MDRV_MACHINE_RESET( bbcbp )
793796   MDRV_VIDEO_START( bbcbp )
794797   MDRV_VIA6522_ADD("via6522_1", 1000000, bbcb_user_via)
798   MDRV_WD177X_ADD("wd177x", bbc_wd17xx_interface )
795799MACHINE_DRIVER_END
796800
797801
r3867r3868
841845   MDRV_UPD7002_ADD("upd7002",BBC_uPD7002)
842846   MDRV_VIA6522_ADD("via6522_0", 1000000, bbcb_system_via)
843847   MDRV_VIA6522_ADD("via6522_1", 1000000, bbcb_user_via)
848   MDRV_WD177X_ADD("wd177x", bbc_wd17xx_interface )
844849MACHINE_DRIVER_END
845850
846851static void bbc_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
src/mess/drivers/compis.c
r3867r3868
4040#include "machine/pit8253.h"
4141#include "machine/pic8259.h"
4242#include "machine/mm58274c.h"
43#include "machine/nec765.h"
4344#include "formats/cpis_dsk.h"
4445
4546
r3867r3868
275276   
276277   /* rtc */
277278   MDRV_MM58274C_ADD("mm58274c", compis_mm58274c_interface)   
279   
280   MDRV_NEC765A_ADD("nec765", compis_fdc_interface)
278281MACHINE_DRIVER_END
279282
280283/***************************************************************************
src/mess/drivers/kc.c
r3867r3868
333333ADDRESS_MAP_END
334334
335335static ADDRESS_MAP_START(kc85_disc_hw_io, ADDRESS_SPACE_IO, 8)
336   AM_RANGE(0x0f0, 0x0f0) AM_READ(nec765_status_r)
337   AM_RANGE(0x0f1, 0x0f1) AM_READWRITE(nec765_data_r, nec765_data_w)
338   AM_RANGE(0x0f2, 0x0f3) AM_READWRITE(nec765_dack_r, nec765_dack_w)
336   AM_RANGE(0x0f0, 0x0f0) AM_DEVREAD( NEC765A, "nec765", nec765_status_r)
337   AM_RANGE(0x0f1, 0x0f1) AM_DEVREADWRITE( NEC765A, "nec765", nec765_data_r, nec765_data_w)
338   AM_RANGE(0x0f2, 0x0f3) AM_DEVREADWRITE( NEC765A, "nec765", nec765_dack_r, nec765_dack_w)
339339   AM_RANGE(0x0f4, 0x0f5) AM_READ(kc85_disc_hw_input_gate_r)
340340   /*{0x0f6, 0x0f7, SMH_NOP},*/      /* for controller */
341341   AM_RANGE(0x0f8, 0x0f9) AM_WRITE( kc85_disc_hw_terminal_count_w) /* terminal count */
r3867r3868
348348   MDRV_CPU_IO_MAP(kc85_disc_hw_io, 0)
349349
350350   MDRV_Z80CTC_ADD( "z80ctc_1", kc85_disc_ctc_intf )
351   
352   MDRV_NEC765A_ADD("nec765", kc_fdc_interface)
351353MACHINE_DRIVER_END
352354
353355
docs/messnew.txt
r3867r3868
9393
9494- Changed the I8271 implementation to be a device.  [Miodrag Milanovic]
9595
96- Changed the WD17XX implementation to be a device.  [Miodrag Milanovic]
97
98- Changed the NEC765 implementation to be a device.  [Miodrag Milanovic]
99
96100- Various code cleanups.  [Atari Ace]
97101
98102- Fixed regression that could cause hanging when creating an image from the

Previous 15994 Revisions Next


© 1998-2018 The MESS Team