Previous 15994 Revisions Next

r14143 Monday 23rd January, 2012 at 20:55:36 UTC by Olivier Galibert
next: checkpoint (nw)
[src/emu]delegate.h emu.mak
[src/emu/machine]am8530h.c am8530h.h mccs1850.c mccs1850.h ncr539x.c
[src/mess]mess.mak
[src/mess/drivers]next.c
[src/mess/includes]next.h
[src/mess/machine]mb8795.c mb8795.h n82077aa.c n82077aa.h ncr5390.c ncr5390.h nextkbd.c nextkbd.h nextmo.c nextmo.h

src/emu/emu.mak
r14142r14143
165165   $(EMUMACHINE)/adc1038.o      \
166166   $(EMUMACHINE)/adc1213x.o   \
167167   $(EMUMACHINE)/am53cf96.o   \
168   $(EMUMACHINE)/am8530h.o      \
169168   $(EMUMACHINE)/amigafdc.o   \
170169   $(EMUMACHINE)/at28c16.o      \
171170   $(EMUMACHINE)/cdp1852.o      \
src/emu/machine/am8530h.c
r14142r14143
1#include "am8530h.h"
2
3const device_type AM8530H = &device_creator<am8530h_device>;
4
5am8530h_device::am8530h_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, AM8530H, "AM8530H", tag, owner, clock)
6{
7}
8
9void am8530h_device::set_int_change_cb(int_cb_t _int_change_cb)
10{
11   int_change_cb = _int_change_cb;
12}
13
14
15void am8530h_device::device_start()
16{
17}
18
19READ8_MEMBER( am8530h_device::ca_r )
20{
21   return 0xff;
22}
23
24READ8_MEMBER( am8530h_device::cb_r )
25{
26   return 0xff;
27}
28
29READ8_MEMBER( am8530h_device::da_r )
30{
31   return 0x40;
32}
33
34READ8_MEMBER( am8530h_device::db_r )
35{
36   return 0x40;
37}
38
39WRITE8_MEMBER( am8530h_device::ca_w )
40{
41   fprintf(stderr, "ca_w %x, %02x\n", offset, data);
42}
43
44WRITE8_MEMBER( am8530h_device::cb_w )
45{
46   fprintf(stderr, "cb_w %x, %02x\n", offset, data);
47}
48
49WRITE8_MEMBER( am8530h_device::da_w )
50{
51   fprintf(stderr, "da_w %x, %02x\n", offset, data);
52}
53
54WRITE8_MEMBER( am8530h_device::db_w )
55{
56   fprintf(stderr, "db_w %x, %02x\n", offset, data);
57}
src/emu/machine/am8530h.h
r14142r14143
1#ifndef __AM8530H_H__
2#define __AM8530H_H__
3
4#include "emu.h"
5
6#define MCFG_AM8530H_ADD(_tag, _int_change_cb)   \
7   MCFG_DEVICE_ADD(_tag, AM8530H, 0)   \
8   downcast<am8530h_device *>(device)->set_int_change_cb(_int_change_cb);
9
10class am8530h_device : public device_t {
11public:
12   typedef delegate<void ()> int_cb_t;
13
14   am8530h_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
15   void set_int_change_cb(int_cb_t int_change_cb);
16
17   DECLARE_READ8_MEMBER(ca_r);
18   DECLARE_READ8_MEMBER(cb_r);
19   DECLARE_READ8_MEMBER(da_r);
20   DECLARE_READ8_MEMBER(db_r);
21
22   DECLARE_WRITE8_MEMBER(ca_w);
23   DECLARE_WRITE8_MEMBER(cb_w);
24   DECLARE_WRITE8_MEMBER(da_w);
25   DECLARE_WRITE8_MEMBER(db_w);
26
27   void data_a_w(UINT8 val);
28   void data_b_w(UINT8 val);
29
30   void int_ack();
31   bool int_level_get();
32
33protected:
34   virtual void device_start();
35
36private:
37   int_cb_t int_change_cb;
38};
39
40extern const device_type AM8530H;
41
42#endif
src/emu/machine/mccs1850.c
r14142r14143
131131      m_ram[REGISTER_STATUS] &= ~STATUS_IT;
132132   }
133133
134   m_out_int_func(interrupt ? ASSERT_LINE : CLEAR_LINE);
134   if(!int_cb.isnull())
135      int_cb(interrupt);
135136}
136137
137138
r14142r14143
139140//  set_pse_line -
140141//-------------------------------------------------
141142
142inline void mccs1850_device::set_pse_line(int state)
143inline void mccs1850_device::set_pse_line(bool state)
143144{
144145   m_pse = state;
145146
146   m_out_pse_func(m_pse);
147   if(!pse_cb.isnull())
148      pse_cb(m_pse);
147149}
148150
149151
r14142r14143
156158   switch (offset)
157159   {
158160   case REGISTER_COUNTER_LATCH:
161   case REGISTER_COUNTER_LATCH+3: // Required by the NeXT power on test
159162      // load counter value into latch
160163      m_ram[REGISTER_COUNTER_LATCH] = m_counter >> 24;
161164      m_ram[REGISTER_COUNTER_LATCH + 1] = m_counter >> 16;
r14142r14143
195198      if (data & CONTROL_PD)
196199      {
197200         if (LOG) logerror("MCCS1850 '%s' Power Down\n", tag());
198         set_pse_line(0);
201         set_pse_line(false);
199202      }
200203
201204      if (data & CONTROL_AR)
r14142r14143
262265      else
263266      {
264267         // wake up
265         set_pse_line(1);
268         set_pse_line(true);
266269      }
267270   }
268271}
r14142r14143
291294{
292295}
293296
294
295//-------------------------------------------------
296//  device_config_complete - perform any
297//  operations now that the configuration is
298//  complete
299//-------------------------------------------------
300
301void mccs1850_device::device_config_complete()
297void mccs1850_device::set_cb(cb_t _int_cb, cb_t _pse_cb, cb_t _nuc_cb)
302298{
303   // inherit a copy of the static data
304   const mccs1850_interface *intf = reinterpret_cast<const mccs1850_interface *>(static_config());
305   if (intf != NULL)
306      *static_cast<mccs1850_interface *>(this) = *intf;
307
308   // or initialize to defaults if none provided
309   else
310   {
311      memset(&m_out_int_cb, 0, sizeof(m_out_int_cb));
312      memset(&m_out_pse_cb, 0, sizeof(m_out_pse_cb));
313      memset(&m_out_nuc_cb, 0, sizeof(m_out_nuc_cb));
314   }
299   int_cb = _int_cb;
300   pse_cb = _pse_cb;
301   nuc_cb = _nuc_cb;
315302}
316303
317304
r14142r14143
321308
322309void mccs1850_device::device_start()
323310{
324   // resolve callbacks
325   m_out_int_func.resolve(m_out_int_cb, *this);
326   m_out_pse_func.resolve(m_out_pse_cb, *this);
327   m_out_nuc_func.resolve(m_out_nuc_cb, *this);
328
329311   // allocate timers
330312   m_clock_timer = timer_alloc(TIMER_CLOCK);
331313   m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768));
r14142r14143
456438
457439         if (m_bits == 8)
458440         {
459            if (LOG) logerror("MCCS1850 '%s' %s Address %u\n", tag(), BIT(m_address, 7) ? "Write" : "Read", m_address & 0x7f);
441            if (LOG) logerror("MCCS1850 '%s' %s Address %02x\n", tag(), BIT(m_address, 7) ? "Write" : "Read", m_address & 0x7f);
460442
461443            m_bits = 0;
462444            m_state = STATE_DATA;
r14142r14143
559541         check_interrupt();
560542      }
561543
562      set_pse_line(1);
544      set_pse_line(true);
563545   }
564546}
565547
src/emu/machine/mccs1850.h
r14142r14143
3131//  INTERFACE CONFIGURATION MACROS
3232//**************************************************************************
3333
34#define MCFG_MCCS1850_ADD(_tag, _clock, _config) \
34#define MCFG_MCCS1850_ADD(_tag, _clock, _int_cb, _pse_cb, _nuc_cb)   \
3535   MCFG_DEVICE_ADD(_tag, MCCS1850, _clock)   \
36   MCFG_DEVICE_CONFIG(_config)
36   downcast<mccs1850_device *>(device)->set_cb(_int_cb, _pse_cb, _nuc_cb);
3737
3838
39#define MCCS1850_INTERFACE(name) \
40   const mccs1850_interface (name) =
41
42
43
4439//**************************************************************************
4540//  TYPE DEFINITIONS
4641//**************************************************************************
4742
48// ======================> mccs1850_interface
49
50struct mccs1850_interface
51{
52   devcb_write_line      m_out_int_cb;
53   devcb_write_line      m_out_pse_cb;
54   devcb_write_line      m_out_nuc_cb;
55};
56
57
58
5943// ======================> mccs1850_device
6044
6145class mccs1850_device :   public device_t,
6246                  public device_rtc_interface,
63                  public device_nvram_interface,
64                        public mccs1850_interface
47                  public device_nvram_interface
6548{
6649public:
50   typedef delegate<void (bool state)> cb_t;
51
6752    // construction/destruction
6853    mccs1850_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
54   void set_cb(cb_t int_cb, cb_t pse_cb, cb_t nuc_cb);
6955
7056   DECLARE_WRITE_LINE_MEMBER( ce_w );
7157   DECLARE_WRITE_LINE_MEMBER( sck_w );
r14142r14143
7763
7864protected:
7965    // device-level overrides
80   virtual void device_config_complete();
8166    virtual void device_start();
8267    virtual void device_reset();
8368   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
r14142r14143
9378
9479private:
9580   inline void check_interrupt();
96   inline void set_pse_line(int state);
81   inline void set_pse_line(bool state);
9782   inline UINT8 read_register(offs_t offset);
9883   inline void write_register(offs_t offset, UINT8 data);
9984   inline void advance_seconds();
10085
10186   static const device_timer_id TIMER_CLOCK = 0;
10287
103   devcb_resolved_write_line   m_out_int_func;
104   devcb_resolved_write_line   m_out_pse_func;
105   devcb_resolved_write_line   m_out_nuc_func;
88   cb_t int_cb, pse_cb, nuc_cb;
10689
10790   UINT8 m_ram[0x80];         // RAM
10891
src/emu/machine/ncr539x.c
r14142r14143
1111#include "emu.h"
1212#include "ncr539x.h"
1313
14#define VERBOSE         (0)
15#define VERBOSE_READS   (0)
14#define VERBOSE         (1)
15#define VERBOSE_READS   (1)
1616
1717enum
1818{
src/emu/delegate.h
r14142r14143
761761   delegate &operator=(const basetype &src) { *static_cast<basetype *>(this) = src; return *this; }
762762};
763763
764// Some useful delegates
764765
766typedef delegate<void (bool state)> line_cb_t;
767
765768#endif   /* __DELEGATE_H__ */
src/mess/machine/mb8795.h
r14142r14143
1#ifndef MB8795_H
2#define MB8795_H
3
4#define MCFG_MB8795_ADD(_tag, _tx_irq, _rx_irq, _tx_drq, _rx_drq)    \
5   MCFG_DEVICE_ADD(_tag, MB8795, 0)                                 \
6   downcast<mb8795_device *>(device)->set_irq_cb(_tx_irq, _rx_irq); \
7   downcast<mb8795_device *>(device)->set_drq_cb(_tx_drq, _rx_drq);
8
9class mb8795_device :   public device_t,
10                  public device_network_interface
11{
12public:
13   mb8795_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
14
15   void set_irq_cb(line_cb_t tx, line_cb_t rx);
16   void set_drq_cb(line_cb_t tx, line_cb_t rx);
17
18   DECLARE_ADDRESS_MAP(map, 8);
19
20   DECLARE_READ8_MEMBER(txstat_r);
21   DECLARE_WRITE8_MEMBER(txstat_w);
22   DECLARE_READ8_MEMBER(txmask_r);
23   DECLARE_WRITE8_MEMBER(txmask_w);
24   DECLARE_READ8_MEMBER(rxstat_r);
25   DECLARE_WRITE8_MEMBER(rxstat_w);
26   DECLARE_READ8_MEMBER(rxmask_r);
27   DECLARE_WRITE8_MEMBER(rxmask_w);
28   DECLARE_READ8_MEMBER(txmode_r);
29   DECLARE_WRITE8_MEMBER(txmode_w);
30   DECLARE_READ8_MEMBER(rxmode_r);
31   DECLARE_WRITE8_MEMBER(rxmode_w);
32   DECLARE_WRITE8_MEMBER(reset_w);
33   DECLARE_READ8_MEMBER(tdc_lsb_r);
34   DECLARE_READ8_MEMBER(mac_r);
35   DECLARE_WRITE8_MEMBER(mac_w);
36
37   void tx_dma_w(UINT8 data, bool eof);
38   void rx_dma_r(UINT8 &data, bool &eof);
39
40protected:
41   virtual void device_start();
42   virtual void device_reset();
43   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
44
45   virtual void recv_cb(UINT8 *buf, int len);
46   virtual bool mcast_chk(const UINT8* buf, int len);
47
48private:
49   enum { TIMER_TX, TIMER_RX };
50
51   // Lifted from netbsd
52   enum {
53      EN_TXS_READY        = 0x80, /* ready for packet */
54      EN_TXS_BUSY         = 0x40, /* receive carrier detect */
55      EN_TXS_TXRECV       = 0x20, /* transmission received */
56      EN_TXS_SHORTED      = 0x10, /* possible coax short */
57      EN_TXS_UNDERFLOW    = 0x08, /* underflow on xmit */
58      EN_TXS_COLLERR      = 0x04, /* collision detected */
59      EN_TXS_COLLERR16    = 0x02, /* 16th collision error */
60      EN_TXS_PARERR       = 0x01, /* parity error in tx data */
61
62      EN_RXS_OK           = 0x80, /* packet received ok */
63      EN_RXS_RESET        = 0x10, /* reset packet received */
64      EN_RXS_SHORT        = 0x08, /* < minimum length */
65      EN_RXS_ALIGNERR     = 0x04, /* alignment error */
66      EN_RXS_CRCERR       = 0x02, /* CRC error */
67      EN_RXS_OVERFLOW     = 0x01, /* receiver FIFO overflow */
68
69      EN_TMD_COLLMASK     = 0xf0, /* collision count */
70      EN_TMD_COLLSHIFT    =    4,
71      EN_TMD_PARIGNORE    = 0x08, /* ignore parity */
72      EN_TMD_TURBO1       = 0x04,
73      EN_TMD_LB_DISABLE   = 0x02, /* loop back disabled */
74      EN_TMD_DISCONTENT   = 0x01, /* disable contention (rx carrier) */
75
76      EN_RMD_TEST         = 0x80, /* must be zero */
77      EN_RMD_ADDRSIZE     = 0x10, /* reduces NODE match to 5 chars */
78      EN_RMD_SHORTENABLE  = 0x08, /* "rx packets >= 10 bytes" - <? */
79      EN_RMD_RESETENABLE  = 0x04, /* detect "reset" ethernet frames */
80      EN_RMD_WHATRECV     = 0x03, /* controls what packets are received */
81      EN_RMD_RECV_PROMISC = 0x03, /* all packets */
82      EN_RMD_RECV_MULTI   = 0x02, /* accept broad/multicasts */
83      EN_RMD_RECV_NORMAL  = 0x01, /* accept broad/limited multicasts */
84      EN_RMD_RECV_NONE    = 0x00, /* accept no packets */
85
86      EN_RST_RESET        = 0x80 /* reset interface */
87   };
88
89   UINT8 mac[6];
90   UINT8 txbuf[2000], rxbuf[2000];
91   UINT8 txstat, txmask, rxstat, rxmask, txmode, rxmode;
92   UINT16 txlen, rxlen, txcount;
93   bool drq_tx, drq_rx, irq_tx, irq_rx;
94   emu_timer *timer_tx, *timer_rx;
95
96   line_cb_t irq_tx_cb, irq_rx_cb, drq_tx_cb, drq_rx_cb;
97
98   void check_irq();
99   void start_send();
100   void receive();
101   bool recv_is_broadcast();
102   bool recv_is_me();
103   bool recv_is_multicast();
104   bool recv_is_local_multicast();
105};
106
107extern const device_type MB8795;
108
109#endif
src/mess/machine/ncr5390.c
r14142r14143
1#define ADDRESS_MAP_MODERN
2
3#include "emu.h"
4#include "ncr5390.h"
5
6const device_type NCR5390 = &device_creator<ncr5390_device>;
7
8DEVICE_ADDRESS_MAP_START(map, 8, ncr5390_device)
9   AM_RANGE(0x0, 0x0) AM_READWRITE(tcount_lo_r, tcount_lo_w)
10   AM_RANGE(0x1, 0x1) AM_READWRITE(tcount_hi_r, tcount_hi_w)
11   AM_RANGE(0x2, 0x2) AM_READWRITE(fifo_r, fifo_w)
12   AM_RANGE(0x3, 0x3) AM_READWRITE(command_r, command_w)
13   AM_RANGE(0x4, 0x4) AM_READWRITE(status_r, bus_id_w)
14   AM_RANGE(0x5, 0x5) AM_READWRITE(istatus_r, timeout_w)
15   AM_RANGE(0x6, 0x6) AM_READWRITE(seq_step_r, sync_period_w)
16   AM_RANGE(0x7, 0x7) AM_READWRITE(fifo_flags_r, sync_offset_w)
17   AM_RANGE(0x8, 0x8) AM_READWRITE(conf_r, conf_w)
18   AM_RANGE(0x9, 0x9) AM_WRITE(clock_w)
19ADDRESS_MAP_END
20
21ncr5390_device::ncr5390_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
22        : device_t(mconfig, NCR5390, "5390 SCSI", tag, owner, clock)
23{
24}
25
26void ncr5390_device::device_start()
27{
28   save_item(NAME(command));
29   save_item(NAME(config));
30   save_item(NAME(status));
31   save_item(NAME(istatus));
32   save_item(NAME(fifo_pos));
33   save_item(NAME(fifo));
34   save_item(NAME(tcount));
35   save_item(NAME(mode));
36   save_item(NAME(command_pos));
37   save_item(NAME(irq));
38   save_item(NAME(drq));
39   save_item(NAME(clock_conv));
40
41   tcount = 0;
42   config = 0;
43   status = 0;
44   bus_id = 0;
45   select_timeout = 0;
46   tm = timer_alloc(0);
47   memset(devices, 0, sizeof(devices));
48   for(int i=0; i != slots->devs_present; i++)
49      SCSIAllocInstance(machine(),
50                    slots->devices[i].scsiClass,
51                    devices+i,
52                    slots->devices[i].diskregion);
53}
54
55void ncr5390_device::device_reset()
56{
57   fifo_pos = 0;
58   memset(fifo, 0, sizeof(fifo));
59
60   clock_conv = 2;
61   sync_period = 5;
62   sync_offset = 0;
63   config &= 7;
64   status &= 0x97;
65   istatus = 0;
66   irq = false;
67   if(!irq_cb.isnull())
68      irq_cb(irq);
69   reset_soft();
70}
71
72void ncr5390_device::reset_soft()
73{
74   status &= 0xef;
75   drq = false;
76   if(!drq_cb.isnull())
77      drq_cb(drq);
78   reset_disconnect();
79}
80
81void ncr5390_device::reset_disconnect()
82{
83   command_pos = 0;
84   memset(command, 0, sizeof(command));
85   mode = MODE_D;
86}
87
88void ncr5390_device::set_cb(line_cb_t _irq_cb, line_cb_t _drq_cb)
89{
90   irq_cb = _irq_cb;
91   drq_cb = _drq_cb;
92}
93
94void ncr5390_device::set_slots(const SCSIConfigTable &_slots)
95{
96   slots = &_slots;
97}
98
99void ncr5390_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
100{
101   switch(param) {
102   case T_SELECT_TIMEOUT:
103      logerror("ncr5390: select timeout\n");
104      istatus |= I_DISCONNECT;
105      check_irq();
106      break;
107
108   default:
109      logerror("ncr5390: device_timer unexpected param %d\n", param);
110      exit(0);
111   }   
112}
113
114void ncr5390_device::delay(int cycles, int param)
115{
116   if(!clock_conv)
117      return;
118   cycles *= clock_conv;
119   tm->adjust(clocks_to_attotime(cycles), param);
120}
121
122READ8_MEMBER(ncr5390_device::tcount_lo_r)
123{
124   fprintf(stderr, "ncr5390: tcount_lo_r (%08x)\n", cpu_get_pc(&space.device()));
125   return tcount;
126}
127
128WRITE8_MEMBER(ncr5390_device::tcount_lo_w)
129{
130   tcount = (tcount & 0xff00) | data;
131   fprintf(stderr, "ncr5390: tcount_lo_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
132}
133
134READ8_MEMBER(ncr5390_device::tcount_hi_r)
135{
136   fprintf(stderr, "ncr5390: tcount_hi_r (%08x)\n", cpu_get_pc(&space.device()));
137   return tcount >> 8;
138}
139
140WRITE8_MEMBER(ncr5390_device::tcount_hi_w)
141{
142   tcount = (tcount & 0x00ff) | (data << 8);
143   fprintf(stderr, "ncr5390: tcount_hi_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
144}
145
146READ8_MEMBER(ncr5390_device::fifo_r)
147{
148   UINT8 r;
149   if(fifo_pos) {
150      r = fifo[0];
151      fifo_pos--;
152      memmove(fifo, fifo+1, fifo_pos);
153   } else
154      r = 0;
155   fprintf(stderr, "ncr5390: fifo_r %02x (%08x)\n", r, cpu_get_pc(&space.device()));
156   return r;
157}
158
159WRITE8_MEMBER(ncr5390_device::fifo_w)
160{
161   fprintf(stderr, "ncr5390: fifo_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
162   if(fifo_pos != 16)
163      fifo[fifo_pos++] = data;
164}
165
166READ8_MEMBER(ncr5390_device::command_r)
167{
168   fprintf(stderr, "ncr5390: command_r (%08x)\n", cpu_get_pc(&space.device()));
169   return command[0];
170}
171
172WRITE8_MEMBER(ncr5390_device::command_w)
173{
174   fprintf(stderr, "ncr5390: command_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
175   if(command_pos == 2) {
176      status |= S_GROSS_ERROR;
177      check_irq();
178      return;
179   }
180   command[command_pos++] = data;
181   if(command_pos == 1)
182      start_command();
183}
184
185void ncr5390_device::command_pop_and_chain()
186{
187   if(command_pos) {
188      command_pos--;
189      if(command_pos) {
190         command[0] = command[1];
191         start_command();
192      }
193   }
194}
195
196void ncr5390_device::start_command()
197{
198   if(!check_valid_command(command[0] & 0x7f)) {
199      logerror("ncr5390: invalid command %02x\n", command[0]);
200      istatus |= I_ILLEGAL;
201      check_irq();
202      return;
203   }
204
205   bool msg;
206   int extra;
207   int total_len;
208   command_params_size(msg, extra);
209   if(fifo_pos < extra) {
210      logerror("ncr5390: cmd without extra bytes (fp=%d, extra=%d)\n", fifo_pos, extra);
211      exit(0);
212   }
213   if(msg) {
214      if(fifo_pos < extra+1) {
215         logerror("ncr5390: cmd without msg header (fp=%d, extra=%d)\n", fifo_pos, extra);
216         exit(0);
217      }
218      int len = derive_msg_size(fifo[extra]);
219      if(fifo_pos < extra+len) {
220         logerror("ncr5390: cmd without complete msg (fp=%d, extra=%d, len=%d)\n", fifo_pos, extra, len);
221         exit(0);
222      }
223      total_len = len+extra;
224   } else
225      total_len = extra;
226
227   logerror("ncr5390: fifo_pos = %d, total_len = %d\n", fifo_pos, total_len);
228
229   switch((command[0] >> 4) & 7) {
230   case 0: start_command_misc(); break;
231   case 4: start_command_disconnected(); break;
232   case 2: start_command_target(); break;
233   case 1: start_command_initiator(); break;
234   }
235}
236
237bool ncr5390_device::check_valid_command(UINT8 cmd)
238{
239   int subcmd = cmd & 15;
240   switch((cmd >> 4) & 7) {
241   case 0: return subcmd <= 3;
242   case 4: return mode == MODE_D && subcmd <= 5;
243   case 2: return mode == MODE_T && subcmd <= 13 && subcmd != 6;
244   case 1: return mode == MODE_I && (subcmd <= 2 || subcmd == 8 || subcmd == 10);
245   }
246   return false;
247}
248
249void ncr5390_device::command_params_size(bool &msg, int &extra)
250{
251   msg = false;
252   extra = 0;
253   int subcmd = command[0] & 15;
254   switch((command[0] >> 4) & 7) {
255   case 0:
256      break;
257
258   case 4:
259      extra = subcmd == 0 || subcmd == 2 || subcmd == 3 ? 1 : 0;
260      msg = subcmd == 1 || subcmd == 2;
261      break;
262
263   case 2:
264      extra =   subcmd >= 3 && subcmd <= 5 ? 2 : 0;
265      msg = subcmd <= 2;
266      break;
267
268   case 1:
269      break;
270   }
271}
272
273int ncr5390_device::derive_msg_size(UINT8 msg_id)
274{
275   const static int sizes[8] = { 6, 10, 6, 6, 6, 12, 6, 10 };
276   return sizes[msg_id >> 5];
277}
278
279void ncr5390_device::start_command_misc()
280{
281   UINT8 subcmd = command[0] & 15;
282   switch(subcmd) {
283   case 0: // Nop
284      command_pop_and_chain();
285      break;
286
287   case 1: // Fifo flush
288      fifo_pos = 0;
289      command_pop_and_chain();
290      break;
291
292   case 2: // Device reset
293      device_reset();
294      break;
295
296   case 3: // SCSI bus reset
297      reset_soft();
298      break;
299
300   default:
301      logerror("ncr5390: start unimplemented misc(%d)\n", subcmd);
302      exit(0);
303   }
304}
305
306void ncr5390_device::start_command_disconnected()
307{
308   UINT8 subcmd = command[0] & 15;
309   switch(subcmd) {
310   case 2:
311      delay(8192*select_timeout, T_SELECT_TIMEOUT);
312      break;
313
314   default:
315      logerror("ncr5390: start unimplemented disconnected(%d)\n", subcmd);
316      device_reset();
317      break;
318   }
319}
320
321void ncr5390_device::start_command_target()
322{
323   UINT8 subcmd = command[0] & 15;
324   switch(subcmd) {
325   default:
326      logerror("ncr5390: start unimplemented target(%d)\n", subcmd);
327      exit(0);
328   }
329}
330
331void ncr5390_device::start_command_initiator()
332{
333   UINT8 subcmd = command[0] & 15;
334   switch(subcmd) {
335   default:
336      logerror("ncr5390: start unimplemented initiator(%d)\n", subcmd);
337      exit(0);
338   }
339}
340
341void ncr5390_device::check_irq()
342{
343   bool oldirq = irq;
344   irq = istatus != 0;
345   if(irq != oldirq && !irq_cb.isnull())
346      irq_cb(irq);
347
348}
349
350READ8_MEMBER(ncr5390_device::status_r)
351{
352   fprintf(stderr, "ncr5390: status_r (%08x)\n", cpu_get_pc(&space.device()));
353   return status;
354}
355
356WRITE8_MEMBER(ncr5390_device::bus_id_w)
357{
358   bus_id = data & 7;
359}
360
361READ8_MEMBER(ncr5390_device::istatus_r)
362{
363   UINT8 res = istatus;
364   status = istatus = 0;
365   check_irq();
366   if(res)
367      command_pop_and_chain();
368
369   fprintf(stderr, "ncr5390: istatus_r (%08x)\n", cpu_get_pc(&space.device()));
370   return res;
371}
372
373WRITE8_MEMBER(ncr5390_device::timeout_w)
374{
375   select_timeout = data;
376}
377
378READ8_MEMBER(ncr5390_device::seq_step_r)
379{
380   fprintf(stderr, "ncr5390: seq_step_r (%08x)\n", cpu_get_pc(&space.device()));
381   return 0x00;
382}
383
384WRITE8_MEMBER(ncr5390_device::sync_period_w)
385{
386   sync_period = data & 0x1f;
387}
388
389READ8_MEMBER(ncr5390_device::fifo_flags_r)
390{
391   return fifo_pos;
392}
393
394WRITE8_MEMBER(ncr5390_device::sync_offset_w)
395{
396   sync_offset = data & 0x0f;
397}
398
399READ8_MEMBER(ncr5390_device::conf_r)
400{
401   return config;
402}
403
404WRITE8_MEMBER(ncr5390_device::conf_w)
405{
406   config = data;
407}
408
409WRITE8_MEMBER(ncr5390_device::clock_w)
410{
411   clock_conv = data & 0x07;
412}
413
src/mess/machine/n82077aa.c
r14142r14143
66
77DEVICE_ADDRESS_MAP_START(amap, 8, n82077aa_device)
88   AM_RANGE(0x0, 0x0) AM_READ(sra_r)
9   AM_RANGE(0x1, 0x1) AM_READ(sra_r)
9   AM_RANGE(0x1, 0x1) AM_READ(srb_r)
1010   AM_RANGE(0x2, 0x2) AM_READWRITE(dor_r, dor_w)
1111   AM_RANGE(0x3, 0x3) AM_READWRITE(tdr_r, tdr_w)
1212   AM_RANGE(0x4, 0x4) AM_READWRITE(msr_r, dsr_w)
r14142r14143
1414   AM_RANGE(0x7, 0x7) AM_READWRITE(dir_r, ccr_w)
1515ADDRESS_MAP_END
1616
17int n82077aa_device::rates[4] = { 500000, 300000, 250000, 1000000 };
18
1719n82077aa_device::n82077aa_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, N82077AA, "N82077AA", tag, owner, clock)
1820{
1921}
r14142r14143
2325   mode = _mode;
2426}
2527
28void n82077aa_device::setup_intrq_cb(line_cb cb)
29{
30   intrq_cb = cb;
31}
32
33void n82077aa_device::setup_drq_cb(line_cb cb)
34{
35   drq_cb = cb;
36}
37
2638void n82077aa_device::device_start()
2739{
40   static const char *names[] = { "fd0", "fd1", "fd2", "fd3" };
41   for(int i=0; i != 4; i++) {
42      flopi[i].tm = timer_alloc(i);
43      flopi[i].id = i;
44      floppy_connector *con = machine().device<floppy_connector>(names[i]);
45      if(con) {
46         flopi[i].dev = con->get_device();
47         flopi[i].dev->setup_index_pulse_cb(floppy_image_device::index_pulse_cb(FUNC(n82077aa_device::index_callback), this));
48      } else
49         flopi[i].dev = 0;
50   }
2851}
2952
3053void n82077aa_device::device_reset()
3154{
55   main_phase = PHASE_CMD;
56   for(int i=0; i<4; i++) {
57      flopi[i].main_state = IDLE;
58      flopi[i].sub_state = IDLE;
59      flopi[i].irq = false;
60      flopi[i].live = false;
61   }
62   dor = 0x00;
63   fifo_pos = 0;
64   command_pos = 0;
65   result_pos = 0;
66   fifocfg = 0x10;
67   cur_live.fi = 0;
68   cur_irq = false;
69   drq = false;
70   live_abort();
3271}
3372
3473READ8_MEMBER(n82077aa_device::sra_r)
3574{
36   fprintf(stderr, "sra_r (%08x)\n", cpu_get_pc(&space.device()));
37   return 0;
75   UINT8 sra = 0;
76   int fid = dor & 3;
77   floppy_info &fi = flopi[fid];
78   if(fi.dir)
79      sra |= 0x01;
80   if(fi.index)
81      sra |= 0x04;
82   if((dsr & 3) == 0 || (dsr & 3) == 3)
83      sra |= 0x08;
84   if(fi.dev && fi.dev->trk00_r())
85      sra |= 0x10;
86   if(fi.main_state == SEEK_WAIT_STEP_SIGNAL_TIME)
87      sra |= 0x20;
88   sra |= 0x40;
89   if(cur_irq)
90      sra |= 0x80;
91   if(mode == MODE_M30)
92      sra ^= 0x1f;
93   fprintf(stderr, "sra_r %02x (%08x)\n", sra, cpu_get_pc(&space.device()));
94   return sra;
3895}
3996
4097READ8_MEMBER(n82077aa_device::srb_r)
4198{
42   fprintf(stderr, "sra_r (%08x)\n", cpu_get_pc(&space.device()));
99   fprintf(stderr, "srb_r (%08x)\n", cpu_get_pc(&space.device()));
43100   return 0;
44101}
45102
46103READ8_MEMBER(n82077aa_device::dor_r)
47104{
48   fprintf(stderr, "dor_r (%08x)\n", cpu_get_pc(&space.device()));
105   fprintf(stderr, "dor_r %02x (%08x)\n", dor, cpu_get_pc(&space.device()));
49106   return dor;
50107}
51108
r14142r14143
54111   UINT8 diff = dor ^ data;
55112   dor = data;
56113   fprintf(stderr, "dor_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
57   if(diff & 4)
114   if((diff & 4) && !(data & 4))
58115      device_reset();
116   else
117      for(int i=0; i<4; i++) {
118         floppy_info &fi = flopi[i];
119         if(fi.dev && (diff & (0x10 << i)))
120            fi.dev->mon_w(!(dor & (0x10 << i)));
121      }
122           
59123}
60124
61125READ8_MEMBER(n82077aa_device::tdr_r)
r14142r14143
71135
72136READ8_MEMBER(n82077aa_device::msr_r)
73137{
74   if(cpu_get_pc(&space.device()) != 0x10111fa)
75      fprintf(stderr, "msr_r (%08x)\n", cpu_get_pc(&space.device()));
76   return 0;
138   UINT32 msr = 0;
139   switch(main_phase) {
140   case PHASE_CMD:
141      msr |= 0x80;
142      if(command_pos)
143         msr |= 0x10;
144      break;
145   case PHASE_EXEC:
146      msr |= 0x10;
147      break;
148
149   case PHASE_RESULT:
150      msr |= 0xd0;
151      break;
152   }
153   for(int i=0; i<4; i++)
154      if(flopi[i].main_state == RECALIBRATE)
155         msr |= 1<<i;
156
157   //   fprintf(stderr, "msr_r %02x (%08x)\n", msr, cpu_get_pc(&space.device()));
158   return msr;
77159}
78160
79161WRITE8_MEMBER(n82077aa_device::dsr_w)
r14142r14143
84166
85167READ8_MEMBER(n82077aa_device::fifo_r)
86168{
87   fprintf(stderr, "fifo_r (%08x)\n", cpu_get_pc(&space.device()));
88   return 0;
169   UINT8 r = 0;
170   switch(main_phase) {
171   case PHASE_RESULT:
172      r = result[0];
173      result_pos--;
174      memmove(result, result+1, result_pos);
175      if(!result_pos)
176         main_phase = PHASE_CMD;
177      break;
178   default:
179      fprintf(stderr, "fifo_r in phase %d\n", main_phase);
180      //      exit(1);
181   }
182
183   fprintf(stderr, "fifo_r %02x (%08x)\n", r, cpu_get_pc(&space.device()));
184   return r;
89185}
90186
91187WRITE8_MEMBER(n82077aa_device::fifo_w)
92188{
93189   fprintf(stderr, "fifo_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
190   switch(main_phase) {
191   case PHASE_CMD: {
192      command[command_pos++] = data;
193      int cmd = check_command();
194      if(cmd == C_INCOMPLETE)
195         break;
196      if(cmd == C_INVALID) {
197         fprintf(stderr, "Invalid on %02x\n", command[0]);
198         //         exit(1);
199         command_pos = 0;
200         return;
201      }
202      start_command(cmd);
203      break;
204   }
205   default:
206      fprintf(stderr, "fifo_w in phase %d\n", main_phase);
207      exit(1);
208   }
94209}
95210
96211READ8_MEMBER(n82077aa_device::dir_r)
r14142r14143
102217WRITE8_MEMBER(n82077aa_device::ccr_w)
103218{
104219   fprintf(stderr, "ccr_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
105   ccr = data;
220   dsr = (dsr & 0xfc) | (data & 3);
106221}
222
223void n82077aa_device::set_drq(bool state)
224{
225   if(state != drq) {
226      drq = state;
227      if(!drq_cb.isnull())
228         drq_cb(drq);
229   }
230}
231
232bool n82077aa_device::get_drq() const
233{
234   return drq;
235}
236
237void n82077aa_device::fifo_push(UINT8 data)
238{
239   if(fifo_pos == 16) {
240      fprintf(stderr, "Overflow\n");
241      return;
242   }
243   fifo[fifo_pos++] = data;
244   fifo_expected--;
245   if(!drq) {
246      int thr = (fifocfg & 15)+1;
247      if(!fifo_expected || fifo_pos >= thr || (fifocfg & 0x20))
248         set_drq(true);
249   }
250}
251
252void n82077aa_device::fifo_expect(int size, bool write)
253{
254   fifo_expected = size;
255   fifo_write = write;
256}
257
258UINT8 n82077aa_device::dma_r()
259{
260   if(!fifo_pos)
261      return 0;
262   UINT8 r = fifo[0];
263   fifo_pos--;
264   memmove(fifo, fifo+1, fifo_pos);
265   if(!fifo_pos)
266      set_drq(false);
267   return r;
268}
269
270void n82077aa_device::live_start(floppy_info &fi, int state)
271{
272   cur_live.tm = machine().time();
273   cur_live.state = state;
274   cur_live.next_state = -1;
275   cur_live.fi = &fi;
276   cur_live.shift_reg = 0;
277   cur_live.crc = 0xffff;
278   cur_live.bit_counter = 0;
279   cur_live.data_separator_phase = false;
280   cur_live.data_reg = 0;
281   cur_live.previous_type = live_info::PT_NONE;
282   cur_live.data_bit_context = false;
283   cur_live.byte_counter = 0;
284   cur_live.pll.reset(cur_live.tm);
285   //   cur_live.pll.set_clock(attotime::from_hz(rates[dsr & 3]*2));
286   cur_live.pll.set_clock(attotime::from_hz(rates[dsr & 3]));
287   checkpoint_live = cur_live;
288   fi.live = true;
289
290   live_run();
291}
292
293void n82077aa_device::checkpoint()
294{
295   if(cur_live.fi)
296      cur_live.pll.commit(cur_live.fi->dev, cur_live.tm);
297   checkpoint_live = cur_live;
298}
299
300void n82077aa_device::rollback()
301{
302   cur_live = checkpoint_live;
303}
304
305void n82077aa_device::live_delay(int state)
306{
307   cur_live.next_state = state;
308   if(cur_live.tm != machine().time())
309      cur_live.fi->tm->adjust(cur_live.tm - machine().time());
310}
311
312void n82077aa_device::live_sync()
313{
314   if(!cur_live.tm.is_never()) {
315      if(cur_live.tm > machine().time()) {
316         rollback();
317         live_run(machine().time());
318         cur_live.pll.commit(cur_live.fi->dev, cur_live.tm);
319      }
320      if(cur_live.tm == machine().time()) {
321         cur_live.pll.commit(cur_live.fi->dev, cur_live.tm);
322         if(cur_live.next_state != -1) {
323            cur_live.state = cur_live.next_state;
324            cur_live.next_state = -1;
325         }
326         if(cur_live.state == IDLE) {
327            cur_live.tm = attotime::never;
328            cur_live.fi->live = false;
329            cur_live.fi = 0;
330         }
331      }
332      cur_live.next_state = -1;
333      checkpoint();
334   }
335}
336
337void n82077aa_device::live_abort()
338{
339     
340   if(!cur_live.tm.is_never() && cur_live.tm > machine().time()) {
341      rollback();
342      live_run(machine().time());
343   }
344
345   if(cur_live.fi) {
346      cur_live.pll.stop_writing(cur_live.fi->dev, cur_live.tm);
347      cur_live.fi->live = false;
348      cur_live.fi = 0;
349   }
350
351   cur_live.tm = attotime::never;
352   cur_live.state = IDLE;
353   cur_live.next_state = -1;
354}
355
356void n82077aa_device::live_run(attotime limit)
357{
358   if(cur_live.state == IDLE || cur_live.next_state != -1)
359      return;
360
361   if(limit == attotime::never) {
362      if(cur_live.fi->dev)
363         limit = cur_live.fi->dev->time_next_index();
364      if(limit == attotime::never) {
365         // Happens when there's no disk or if the fdc is not
366         // connected to a drive, hence no index pulse. Force a
367         // sync from time to time in that case, so that the main
368         // cpu timeout isn't too painful.  Avoids looping into
369         // infinity looking for data too.
370
371         limit = machine().time() + attotime::from_msec(1);
372         cur_live.fi->tm->adjust(attotime::from_msec(1));
373      }
374   }
375
376   for(;;) {
377      switch(cur_live.state) {
378      case SEARCH_ADDRESS_MARK_HEADER:
379         if(read_one_bit(limit))
380            return;
381#if 0
382         fprintf(stderr, "%s: shift = %04x data=%02x c=%d\n", tts(cur_live.tm).cstr(), cur_live.shift_reg,
383               (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) |
384               (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) |
385               (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) |
386               (cur_live.shift_reg & 0x0100 ? 0x10 : 0x00) |
387               (cur_live.shift_reg & 0x0040 ? 0x08 : 0x00) |
388               (cur_live.shift_reg & 0x0010 ? 0x04 : 0x00) |
389               (cur_live.shift_reg & 0x0004 ? 0x02 : 0x00) |
390               (cur_live.shift_reg & 0x0001 ? 0x01 : 0x00),
391               cur_live.bit_counter);
392#endif
393
394         if(cur_live.shift_reg == 0x4489) {
395            cur_live.crc = 0x443b;
396            cur_live.data_separator_phase = false;
397            cur_live.bit_counter = 0;
398            cur_live.state = READ_HEADER_BLOCK_HEADER;
399         }
400         break;
401
402      case READ_HEADER_BLOCK_HEADER: {
403         if(read_one_bit(limit))
404            return;
405#if 0
406         fprintf(stderr, "%s: shift = %04x data=%02x counter=%d\n", tts(cur_live.tm).cstr(), cur_live.shift_reg,
407               (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) |
408               (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) |
409               (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) |
410               (cur_live.shift_reg & 0x0100 ? 0x10 : 0x00) |
411               (cur_live.shift_reg & 0x0040 ? 0x08 : 0x00) |
412               (cur_live.shift_reg & 0x0010 ? 0x04 : 0x00) |
413               (cur_live.shift_reg & 0x0004 ? 0x02 : 0x00) |
414               (cur_live.shift_reg & 0x0001 ? 0x01 : 0x00),
415               cur_live.bit_counter);
416#endif
417         if(cur_live.bit_counter & 15)
418            break;
419
420         int slot = cur_live.bit_counter >> 4;
421
422         if(slot < 3) {
423            if(cur_live.shift_reg != 0x4489)
424               cur_live.state = SEARCH_ADDRESS_MARK_HEADER;
425            break;
426         }
427         if(cur_live.data_reg != 0xfe) {
428            cur_live.state = SEARCH_ADDRESS_MARK_HEADER;
429            break;
430         }
431
432         cur_live.bit_counter = 0;
433         cur_live.state = READ_ID_BLOCK_TO_LOCAL;
434
435         break;
436      }
437
438      case READ_ID_BLOCK_TO_LOCAL: {
439         if(read_one_bit(limit))
440            return;
441         if(cur_live.bit_counter & 15)
442            break;
443         int slot = (cur_live.bit_counter >> 4)-1;
444         cur_live.idbuf[slot] = cur_live.data_reg;
445         if(slot == 5) {
446            live_delay(IDLE);
447            return;
448         }
449         break;
450      }
451
452      case SEARCH_ADDRESS_MARK_DATA:
453         if(read_one_bit(limit))
454            return;
455#if 0
456         fprintf(stderr, "%s: shift = %04x data=%02x c=%d.%x\n", tts(cur_live.tm).cstr(), cur_live.shift_reg,
457               (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) |
458               (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) |
459               (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) |
460               (cur_live.shift_reg & 0x0100 ? 0x10 : 0x00) |
461               (cur_live.shift_reg & 0x0040 ? 0x08 : 0x00) |
462               (cur_live.shift_reg & 0x0010 ? 0x04 : 0x00) |
463               (cur_live.shift_reg & 0x0004 ? 0x02 : 0x00) |
464               (cur_live.shift_reg & 0x0001 ? 0x01 : 0x00),
465               cur_live.bit_counter >> 4, cur_live.bit_counter & 15);
466#endif
467         if(cur_live.bit_counter > 43*16) {
468            live_delay(SEARCH_ADDRESS_MARK_DATA_FAILED);
469            return;
470         }
471
472         if(cur_live.bit_counter >= 28*16 && cur_live.shift_reg == 0x4489) {
473            cur_live.crc = 0x443b;
474            cur_live.data_separator_phase = false;
475            cur_live.bit_counter = 0;
476            cur_live.state = READ_DATA_BLOCK_HEADER;
477         }
478         break;
479
480      case READ_DATA_BLOCK_HEADER: {
481         if(read_one_bit(limit))
482            return;
483#if 0
484         fprintf(stderr, "%s: shift = %04x data=%02x counter=%d\n", tts(cur_live.tm).cstr(), cur_live.shift_reg,
485               (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) |
486               (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) |
487               (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) |
488               (cur_live.shift_reg & 0x0100 ? 0x10 : 0x00) |
489               (cur_live.shift_reg & 0x0040 ? 0x08 : 0x00) |
490               (cur_live.shift_reg & 0x0010 ? 0x04 : 0x00) |
491               (cur_live.shift_reg & 0x0004 ? 0x02 : 0x00) |
492               (cur_live.shift_reg & 0x0001 ? 0x01 : 0x00),
493               cur_live.bit_counter);
494#endif
495         if(cur_live.bit_counter & 15)
496            break;
497
498         int slot = cur_live.bit_counter >> 4;
499
500         if(slot < 3) {
501            if(cur_live.shift_reg != 0x4489) {
502               live_delay(SEARCH_ADDRESS_MARK_DATA_FAILED);
503               return;
504            }
505            break;
506         }
507         if(cur_live.data_reg != 0xfb && cur_live.data_reg != 0xfd) {
508            live_delay(SEARCH_ADDRESS_MARK_DATA_FAILED);
509            return;
510         }
511
512         cur_live.bit_counter = 0;
513         cur_live.state = READ_SECTOR_DATA;
514         break;
515      }
516
517      case SEARCH_ADDRESS_MARK_DATA_FAILED:
518         //         status |= S_RNF;
519         cur_live.state = IDLE;
520         return;
521
522      case READ_SECTOR_DATA: {
523         if(read_one_bit(limit))
524            return;
525         if(cur_live.bit_counter & 15)
526            break;
527         int slot = (cur_live.bit_counter >> 4)-1;
528         if(slot < sector_size) {
529            // Sector data
530            live_delay(READ_SECTOR_DATA_BYTE);
531            return;
532
533         } else if(slot < sector_size+2) {
534            // CRC
535            if(slot == sector_size+1) {
536               live_delay(IDLE);
537               return;
538            }
539         }
540
541         break;
542      }
543
544      case READ_SECTOR_DATA_BYTE:
545         //         fprintf(stderr, "databyte = %02x\n", cur_live.data_reg);
546         fifo_push(cur_live.data_reg);
547         cur_live.state = READ_SECTOR_DATA;
548         checkpoint();
549         break;
550
551      default:
552         logerror("%s: Unknown live state %d\n", tts(cur_live.tm).cstr(), cur_live.state);
553         return;
554      }
555   }
556}
557
558int n82077aa_device::check_command()
559{
560   // 0.000010 read track
561   // 00000011 specify
562   // 00000100 sense drive status
563   // ..000101 write data
564   // ...00110 read data
565   // 00000111 recalibrate
566   // 00001000 sense interrupt status
567   // ..001001 write deleted data
568   // 0.001010 read id
569   // ...01100 read deleted data
570   // 0.001101 format track
571   // 00001110 dumpreg
572   // 00001111 seek
573   // 00010000 version
574   // ...10001 scan equal
575   // 00010010 perpendicular mode
576   // 00010011 configure
577   // .0010100 lock
578   // ...10110 verify
579   // ...11001 scan low or equal
580   // ...11101 scan high or equal
581   // 1.001111 relative seek
582
583   switch(command[0]) {
584   case 0x03:
585      return command_pos == 3 ? C_SPECIFY     : C_INCOMPLETE;
586
587   case 0x06: case 0x26: case 0x46: case 0x66: case 0x86: case 0xa6: case 0xc6: case 0xe6:
588      return command_pos == 9 ? C_READ_DATA   : C_INCOMPLETE;
589
590   case 0x07:
591      return command_pos == 2 ? C_RECALIBRATE : C_INCOMPLETE;
592
593   case 0x08:
594      return C_SENSE_INTERRUPT_STATUS;
595
596   case 0x0f:
597     
598   case 0x12:
599      return command_pos == 2 ? C_PERPENDICULAR : C_INCOMPLETE;
600
601   case 0x13:
602      return command_pos == 4 ? C_CONFIGURE   : C_INCOMPLETE;
603
604   default:
605      return C_INVALID;
606   }
607}
608
609void n82077aa_device::start_command(int cmd)
610{
611   command_pos = 0;
612   result_pos = 0;
613   main_phase = PHASE_EXEC;
614   switch(cmd) {
615   case C_CONFIGURE:
616      fprintf(stderr, "Configure %02x %02x %02x\n",
617            command[1], command[2], command[3]);
618      // byte 1 is ignored, byte 3 is precompensation-related
619      fifocfg = command[2];
620      main_phase = PHASE_CMD;
621      break;
622
623   case C_PERPENDICULAR:
624      main_phase = PHASE_CMD;
625      break;
626
627   case C_READ_DATA:
628      read_data_start(flopi[command[1] & 3]);
629      break;
630
631   case C_RECALIBRATE:
632      recalibrate_start(flopi[command[1] & 3]);
633      main_phase = PHASE_CMD;
634      break;
635
636   case C_SENSE_INTERRUPT_STATUS: {
637      main_phase = PHASE_RESULT;
638
639      int fid;
640      for(fid=0; fid<4 && !flopi[fid].irq; fid++);
641      if(fid == 4) {
642         result[0] = 0x80;
643         result_pos = 1;
644         break;
645      }
646      floppy_info &fi = flopi[fid];
647      fi.irq = false;
648      result[0] = (fi.status << 6) | 0x20 | fid;
649      result[1] = fi.pcn;
650      result_pos = 2;
651      check_irq();
652      break;
653   }
654
655   case C_SPECIFY:
656      fprintf(stderr, "Specify %02x %02x\n",
657            command[1], command[2]);
658      spec = (command[1] << 8) | command[2];
659      main_phase = PHASE_CMD;
660      break;
661
662   default:
663      fprintf(stderr, "start command %d\n", cmd);
664      exit(1);
665   }
666}
667
668void n82077aa_device::command_end(floppy_info &fi, int status)
669{
670   fi.main_state = fi.sub_state = IDLE;
671   fi.irq = true;
672   fi.status = status;
673   check_irq();
674}
675
676void n82077aa_device::recalibrate_start(floppy_info &fi)
677{
678   fi.main_state = RECALIBRATE;
679   fi.sub_state = SEEK_WAIT_STEP_TIME_DONE;
680   fi.dir = 1;
681   seek_continue(fi);
682}
683
684void n82077aa_device::delay_cycles(emu_timer *tm, int cycles)
685{
686   tm->adjust(attotime::from_double(double(cycles)/rates[dsr & 3]));
687}
688
689void n82077aa_device::seek_continue(floppy_info &fi)
690{
691   for(;;) {
692      switch(fi.sub_state) {
693      case SEEK_MOVE:
694         if(fi.dev) {
695            fi.dev->dir_w(fi.dir);
696            fi.dev->stp_w(0);
697         }
698         fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME;
699         fi.tm->adjust(attotime::from_nsec(2500));
700         return;
701
702      case SEEK_WAIT_STEP_SIGNAL_TIME:
703         return;
704
705      case SEEK_WAIT_STEP_SIGNAL_TIME_DONE:
706         if(fi.dev)
707            fi.dev->stp_w(1);
708
709         fi.sub_state = SEEK_WAIT_STEP_TIME;
710         delay_cycles(fi.tm, 500*(16-(spec >> 12)));
711         return;
712
713      case SEEK_WAIT_STEP_TIME:
714         return;
715
716      case SEEK_WAIT_STEP_TIME_DONE: {
717         bool done = false;
718         switch(fi.main_state) {
719         case RECALIBRATE:
720            done = !fi.dev || !fi.dev->trk00_r();
721            if(done)
722               fi.pcn = 0;
723            break;
724         }
725         if(done) {
726            fprintf(stderr, "Seek done\n");
727            command_end(fi, 0);
728            return;
729         }
730         fi.sub_state = SEEK_MOVE;         
731         break;
732      }
733      }
734   }
735}
736
737void n82077aa_device::read_data_start(floppy_info &fi)
738{
739   fi.main_state = READ_DATA;
740   fi.sub_state = HEAD_LOAD_DONE;
741   
742   fprintf(stderr, "Read data%s%s%s\n",
743         command[0] & 0x80 ? " mt" : "",
744         command[0] & 0x40 ? " mfm" : "",
745         command[0] & 0x20 ? " sk" : "");
746   fprintf(stderr, "  cmd=%02x sel=%x chrn=(%d, %d, %d, %d) eot=%02x gpl=%02x dtl=%02x\n",
747         command[0],
748         command[1],
749         command[2],
750         command[3],
751         command[4],
752         128 << (command[5] & 7),
753         command[6],
754         command[7],
755         command[8]);
756   fprintf(stderr, "  rate=%d\n", rates[dsr & 3]);
757   if(fi.dev)
758      fi.dev->ss_w(command[1] & 8);
759   read_data_continue(fi);
760}
761
762void n82077aa_device::read_data_continue(floppy_info &fi)
763{
764   for(;;) {
765      switch(fi.sub_state) {
766      case HEAD_LOAD_DONE:
767         counter = 0;
768         fi.sub_state = SCAN_ID;
769         live_start(fi, SEARCH_ADDRESS_MARK_HEADER);
770         return;
771
772      case SCAN_ID:
773         if(!sector_matches()) {
774            live_start(fi, SEARCH_ADDRESS_MARK_HEADER);
775            return;
776         }
777         if(cur_live.crc) {
778            fprintf(stderr, "Header CRC error\n");
779            live_start(fi, SEARCH_ADDRESS_MARK_HEADER);
780            return;
781         }
782         sector_size = 128 << (cur_live.idbuf[3] & 3);
783         fifo_expect(sector_size, false);
784         fi.sub_state = SECTOR_READ;
785         live_start(fi, SEARCH_ADDRESS_MARK_DATA);
786         return;
787
788      case SCAN_ID_FAILED:
789         fprintf(stderr, "RNF\n");
790         command_end(fi, 1);
791         return;
792
793      case SECTOR_READ:
794         if(cur_live.crc) {
795            fprintf(stderr, "CRC error\n");
796         }
797         command[4]++;
798         command[6]--;
799         fprintf(stderr, "One sector done -> %d.\n", command[6]);
800         if(command[6]) {
801            fi.sub_state = HEAD_LOAD_DONE;
802            break;
803         }
804         main_phase = PHASE_RESULT;
805         result[0] = 0;
806         result[1] = 0;
807         result[2] = 0;
808         result[3] = command[2];
809         result[4] = command[3];
810         result[5] = command[4];
811         result[6] = command[5];
812         result_pos = 7;
813         command_end(fi, 0);
814         return;
815
816      default:
817         logerror("%s: read sector unknown sub-state %d\n", ttsn().cstr(), fi.sub_state);
818         return;
819      }
820   }
821}
822
823void n82077aa_device::check_irq()
824{
825   bool old_irq = cur_irq;
826   cur_irq = false;
827   for(int i=0; i<4; i++)
828      cur_irq = cur_irq || flopi[i].irq;
829   if(cur_irq != old_irq && !intrq_cb.isnull())
830      intrq_cb(cur_irq);
831}
832
833astring n82077aa_device::tts(attotime t)
834{
835   char buf[256];
836   int nsec = t.attoseconds / ATTOSECONDS_PER_NANOSECOND;
837   sprintf(buf, "%4d.%03d,%03d,%03d", int(t.seconds), nsec/1000000, (nsec/1000)%1000, nsec % 1000);
838   return buf;
839}
840
841astring n82077aa_device::ttsn()
842{
843   return tts(machine().time());
844}
845
846void n82077aa_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
847{
848   live_sync();
849
850   floppy_info &fi = flopi[id];
851   switch(fi.sub_state) {
852   case SEEK_WAIT_STEP_SIGNAL_TIME:
853      fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME_DONE;
854      break;
855   case SEEK_WAIT_STEP_TIME:
856      fi.sub_state = SEEK_WAIT_STEP_TIME_DONE;
857      break;
858   }
859
860   general_continue(fi);
861}
862
863void n82077aa_device::index_callback(floppy_image_device *floppy, int state)
864{
865   int fid;
866   for(fid=0; fid<4; fid++)
867      if(flopi[fid].dev == floppy)
868         break;
869
870   assert(fid != 4);
871   floppy_info &fi = flopi[fid];
872
873   live_sync();
874   fi.index = state;
875
876   if(!state) {
877      general_continue(fi);
878      return;
879   }
880
881   switch(fi.sub_state) {
882   case IDLE:
883      break;
884
885   case SCAN_ID:
886      counter++;
887      if(counter == 2)
888         fi.sub_state = SCAN_ID_FAILED;
889      break;
890
891   default:
892      logerror("%s: Index pulse on unknown sub-state %d\n", ttsn().cstr(), fi.sub_state);
893      break;
894   }
895
896   general_continue(fi);
897}
898
899
900void n82077aa_device::general_continue(floppy_info &fi)
901{
902   if(fi.live && cur_live.state != IDLE) {
903      live_run();
904      if(cur_live.state != IDLE)
905         return;
906   }
907
908   switch(fi.main_state) {
909   case IDLE:
910      break;
911
912   case RECALIBRATE:
913      seek_continue(fi);
914      break;
915
916   case READ_DATA:
917      read_data_continue(fi);
918      break;
919
920   default:
921      logerror("%s: general_continue on unknown main-state %d\n", ttsn().cstr(), fi.main_state);
922      break;
923   }
924}
925
926bool n82077aa_device::read_one_bit(attotime limit)
927{
928   int bit = cur_live.pll.get_next_bit(cur_live.tm, cur_live.fi->dev, limit);
929   if(bit < 0)
930      return true;
931   cur_live.shift_reg = (cur_live.shift_reg << 1) | bit;
932   cur_live.bit_counter++;
933   if(cur_live.data_separator_phase) {
934      cur_live.data_reg = (cur_live.data_reg << 1) | bit;
935      if((cur_live.crc ^ (bit ? 0x8000 : 0x0000)) & 0x8000)
936         cur_live.crc = (cur_live.crc << 1) ^ 0x1021;
937      else
938         cur_live.crc = cur_live.crc << 1;
939   }
940   cur_live.data_separator_phase = !cur_live.data_separator_phase;
941   return false;
942}
943
944bool n82077aa_device::write_one_bit(attotime limit)
945{
946   bool bit = cur_live.shift_reg & 0x8000;
947   if(cur_live.pll.write_next_bit(bit, cur_live.tm, cur_live.fi->dev, limit))
948      return true;
949   if(cur_live.bit_counter & 1) {
950      if((cur_live.crc ^ (bit ? 0x8000 : 0x0000)) & 0x8000)
951         cur_live.crc = (cur_live.crc << 1) ^ 0x1021;
952      else
953         cur_live.crc = cur_live.crc << 1;
954   }
955   cur_live.shift_reg = cur_live.shift_reg << 1;
956   cur_live.bit_counter--;
957   return false;
958}
959
960bool n82077aa_device::sector_matches() const
961{
962   if(1)
963      fprintf(stderr, "match %d %d %d %d - %d %d %d %d\n",
964            cur_live.idbuf[0], cur_live.idbuf[1], cur_live.idbuf[2], cur_live.idbuf[3],
965            command[2], command[3], command[4], command[5]);
966   return
967      cur_live.idbuf[0] == command[2] &&
968      cur_live.idbuf[1] == command[3] &&
969      cur_live.idbuf[2] == command[4] &&
970      cur_live.idbuf[3] == command[5];
971}
972
973void n82077aa_device::pll_t::set_clock(attotime _period)
974{
975   period = _period;
976   period_adjust_base = period * 0.05;
977   min_period = period * 0.75;
978   max_period = period * 1.25;
979}
980
981void n82077aa_device::pll_t::reset(attotime when)
982{
983   ctime = when;
984   phase_adjust = attotime::zero;
985   freq_hist = 0;
986   write_position = 0;
987   write_start_time = attotime::never;
988}
989
990void n82077aa_device::pll_t::start_writing(attotime tm)
991{
992   write_start_time = tm;
993   write_position = 0;
994}
995
996void n82077aa_device::pll_t::stop_writing(floppy_image_device *floppy, attotime tm)
997{
998   commit(floppy, tm);
999   write_start_time = attotime::never;
1000}
1001
1002void n82077aa_device::pll_t::commit(floppy_image_device *floppy, attotime tm)
1003{
1004   if(write_start_time.is_never() || tm == write_start_time)
1005      return;
1006
1007   if(floppy)
1008      floppy->write_flux(write_start_time, tm, write_position, write_buffer);
1009   write_start_time = tm;
1010   write_position = 0;
1011}
1012
1013int n82077aa_device::pll_t::get_next_bit(attotime &tm, floppy_image_device *floppy, attotime limit)
1014{
1015   attotime edge = floppy ? floppy->get_next_transition(ctime) : attotime::never;
1016
1017   attotime next = ctime + period + phase_adjust;
1018
1019#if 0
1020   if(!edge.is_never())
1021      fprintf(stderr, "transition_time=%s, next=%s\n", tts(edge).cstr(), tts(next).cstr());
1022#endif
1023
1024   if(next > limit)
1025      return -1;
1026
1027   ctime = next;
1028
1029   if(edge.is_never() || edge >= next) {
1030      // No transition in the window means 0 and pll in free run mode
1031      phase_adjust = attotime::zero;
1032      tm = next;
1033      return 0;
1034   }
1035
1036   // Transition in the window means 1, and the pll is adjusted
1037
1038   attotime delta = edge - (next - period/2);
1039
1040   phase_adjust = 0.65*delta;
1041
1042   if(delta < attotime::zero) {
1043      if(freq_hist < 0)
1044         freq_hist--;
1045      else
1046         freq_hist = -1;
1047   } else if(delta > attotime::zero) {
1048      if(freq_hist > 0)
1049         freq_hist++;
1050      else
1051         freq_hist = 1;
1052   } else
1053      freq_hist = 0;
1054
1055   if(freq_hist) {
1056      int afh = freq_hist < 0 ? -freq_hist : freq_hist;
1057      if(afh > 1) {
1058         attotime aper = attotime::from_double(period_adjust_base.as_double()*delta.as_double()/period.as_double());
1059         period += aper;
1060
1061         if(period < min_period)
1062            period = min_period;
1063         else if(period > max_period)
1064            period = max_period;
1065      }
1066   }
1067
1068   return 1;
1069}
1070
1071bool n82077aa_device::pll_t::write_next_bit(bool bit, attotime &tm, floppy_image_device *floppy, attotime limit)
1072{
1073   if(write_start_time.is_never()) {
1074      write_start_time = ctime;
1075      write_position = 0;
1076   }
1077
1078   attotime etime = ctime + period;
1079   if(etime > limit)
1080      return true;
1081
1082   if(write_position < ARRAY_LENGTH(write_buffer))
1083      write_buffer[write_position++] = ctime + period/2;
1084
1085   tm = etime;
1086   ctime = etime;
1087   return false;
1088}
src/mess/machine/ncr5390.h
r14142r14143
1#ifndef NCR5390_H
2#define NCR5390_H
3
4#include "machine/scsi.h"
5
6#define MCFG_NCR5390_ADD(_tag, _clock, _irq, _drq, _slots)   \
7   MCFG_DEVICE_ADD(_tag, NCR5390, _clock)                  \
8   downcast<ncr5390_device *>(device)->set_cb(_irq, _drq); \
9   downcast<ncr5390_device *>(device)->set_slots(_slots);
10
11class ncr5390_device : public device_t
12{
13public:
14   ncr5390_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
15   void set_cb(line_cb_t irq_cb, line_cb_t drq_cb);
16   void set_slots(const SCSIConfigTable &slots);
17   
18   DECLARE_ADDRESS_MAP(map, 8);
19
20   DECLARE_READ8_MEMBER(tcount_lo_r);
21   DECLARE_WRITE8_MEMBER(tcount_lo_w);
22   DECLARE_READ8_MEMBER(tcount_hi_r);
23   DECLARE_WRITE8_MEMBER(tcount_hi_w);
24   DECLARE_READ8_MEMBER(fifo_r);
25   DECLARE_WRITE8_MEMBER(fifo_w);
26   DECLARE_READ8_MEMBER(command_r);
27   DECLARE_WRITE8_MEMBER(command_w);
28   DECLARE_READ8_MEMBER(status_r);
29   DECLARE_WRITE8_MEMBER(bus_id_w);
30   DECLARE_READ8_MEMBER(istatus_r);
31   DECLARE_WRITE8_MEMBER(timeout_w);
32   DECLARE_READ8_MEMBER(seq_step_r);
33   DECLARE_WRITE8_MEMBER(sync_period_w);
34   DECLARE_READ8_MEMBER(fifo_flags_r);
35   DECLARE_WRITE8_MEMBER(sync_offset_w);
36   DECLARE_READ8_MEMBER(conf_r);
37   DECLARE_WRITE8_MEMBER(conf_w);
38   DECLARE_WRITE8_MEMBER(clock_w);
39
40protected:
41   virtual void device_start();
42   virtual void device_reset();
43    virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
44
45private:
46   enum { MODE_D, MODE_T, MODE_I };
47   enum { T_SELECT_TIMEOUT };
48   enum {
49      S_GROSS_ERROR = 0x40,
50      S_PARITY      = 0x20,
51      S_TC0         = 0x10,
52      S_TCC         = 0x08,
53
54      I_SCSI_RESET  = 0x80,
55      I_ILLEGAL     = 0x40,
56      I_DISCONNECT  = 0x20,
57      I_BUS         = 0x10,
58      I_FUNCTION    = 0x08,
59      I_RESELECTED  = 0x04,
60      I_SELECT_ATN  = 0x02,
61      I_SELECTED    = 0x01,
62   };
63
64   const SCSIConfigTable *slots;
65   SCSIInstance *devices[8];
66
67   emu_timer *tm;
68
69   UINT8 command[2], config, status, istatus;
70   UINT8 clock_conv, sync_offset, sync_period, bus_id, select_timeout;
71   UINT8 fifo[16];
72   UINT16 tcount;
73   int mode, fifo_pos, command_pos;
74
75   bool irq, drq;
76
77   line_cb_t irq_cb, drq_cb;
78
79   void start_command();
80   bool check_valid_command(UINT8 cmd);
81   void command_params_size(bool &msg, int &extra);
82   int derive_msg_size(UINT8 msg_id);
83   void start_command_misc();
84   void start_command_disconnected();
85   void start_command_target();
86   void start_command_initiator();
87   void command_pop_and_chain();
88   void check_irq();
89
90   void reset_soft();
91   void reset_disconnect();
92
93   void delay(int cycles, int param);
94};
95
96extern const device_type NCR5390;
97
98#endif
src/mess/machine/nextmo.c
r14142r14143
1#define ADDRESS_MAP_MODERN
2
3#include "emu.h"
4#include "nextmo.h"
5
6const device_type NEXTMO = &device_creator<nextmo_device>;
7
8DEVICE_ADDRESS_MAP_START(map, 8, nextmo_device)
9   AM_RANGE(0x04, 0x04) AM_READWRITE(r4_r, r4_w)
10   AM_RANGE(0x05, 0x05) AM_READWRITE(r5_r, r5_w)
11   AM_RANGE(0x06, 0x06) AM_READWRITE(r6_r, r6_w)
12   AM_RANGE(0x07, 0x07) AM_READWRITE(r7_r, r7_w)
13   AM_RANGE(0x08, 0x08) AM_READWRITE(r8_r, r8_w)
14   AM_RANGE(0x09, 0x09) AM_READWRITE(r9_r, r9_w)
15   AM_RANGE(0x0a, 0x0a) AM_READWRITE(ra_r, ra_w)
16   AM_RANGE(0x0b, 0x0b) AM_READWRITE(rb_r, rb_w)
17   AM_RANGE(0x10, 0x17) AM_READWRITE(r10_r, r10_w)
18ADDRESS_MAP_END
19
20nextmo_device::nextmo_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
21        : device_t(mconfig, NEXTMO, "NeXT Magneto-optical drive", tag, owner, clock)
22{
23}
24
25void nextmo_device::set_cb(cb_t _irq_cb, cb_t _drq_cb)
26{
27   irq_cb = _irq_cb;
28   drq_cb = _drq_cb;
29}
30
31void nextmo_device::device_start()
32{
33}
34
35void nextmo_device::device_reset()
36{
37}
38
39READ8_MEMBER(nextmo_device::r4_r)
40{
41   fprintf(stderr, "nextmo: r4_r %02x (%08x)\n", r4, cpu_get_pc(&space.device()));
42   return r4;
43}
44
45WRITE8_MEMBER(nextmo_device::r4_w)
46{
47   if(r4 & 1)
48      device_reset();
49   r4 = (r4 & (~data & 0xfc)) | (data & 3);
50   fprintf(stderr, "nextmo: r4_w %02x (%08x)\n", r4, cpu_get_pc(&space.device()));
51}
52
53READ8_MEMBER(nextmo_device::r5_r)
54{
55   fprintf(stderr, "nextmo: r5_r %02x (%08x)\n", r5, cpu_get_pc(&space.device()));
56   return r5;
57}
58
59WRITE8_MEMBER(nextmo_device::r5_w)
60{
61   r5 = data;
62   fprintf(stderr, "nextmo: r5_w %02x (%08x)\n", r5, cpu_get_pc(&space.device()));
63}
64
65READ8_MEMBER(nextmo_device::r6_r)
66{
67   fprintf(stderr, "nextmo: r6_r %02x (%08x)\n", r6, cpu_get_pc(&space.device()));
68   return r6;
69}
70
71WRITE8_MEMBER(nextmo_device::r6_w)
72{
73   r6 = data;
74   fprintf(stderr, "nextmo: r6_w %02x (%08x)\n", r6, cpu_get_pc(&space.device()));
75}
76
77READ8_MEMBER(nextmo_device::r7_r)
78{
79   fprintf(stderr, "nextmo: r7_r %02x (%08x)\n", r7, cpu_get_pc(&space.device()));
80   return r7;
81}
82
83WRITE8_MEMBER(nextmo_device::r7_w)
84{
85   r7 = data;
86   fprintf(stderr, "nextmo: r7_w %02x (%08x)\n", r7, cpu_get_pc(&space.device()));
87   if(r7 & 0xc0) {
88      fprintf(stderr, "nextmo: start dma %02x %02x\n", r6, r7);
89      sector_pos = 0;
90      if(!drq_cb.isnull())
91         drq_cb(true);
92   }     
93}
94
95UINT8 nextmo_device::dma_r()
96{
97   UINT8 r = 0;
98   if(r7 & 0x80)
99      r = sector[sector_pos++];
100   check_dma_end();
101   return r;
102}
103
104void nextmo_device::dma_w(UINT8 data)
105{
106   if(r7 & 0x40)
107      sector[sector_pos++] = data;
108   check_dma_end();
109}
110
111void nextmo_device::check_dma_end()
112{
113   int limit;
114   if(r7 & 0x40)
115      limit = r6 & 0x20 ? 0x510 : 0x400;
116   else
117      limit = r6 & 0x20 ? 0x400 : 0x510;
118   if(sector_pos == limit) {
119      if(!drq_cb.isnull())
120         drq_cb(false);
121      if(r7 & 0x40) {
122         if(r6 & 0x20)
123            check_ecc();
124         else
125            compute_ecc();
126      }
127      r7 &= 0x3f;
128      r4 |= 0x08;
129   }
130}
131
132READ8_MEMBER(nextmo_device::r8_r)
133{
134   fprintf(stderr, "nextmo: r8_r (%08x)\n", cpu_get_pc(&space.device()));
135   return 0x00;
136}
137
138WRITE8_MEMBER(nextmo_device::r8_w)
139{
140   fprintf(stderr, "nextmo: r8_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
141}
142
143READ8_MEMBER(nextmo_device::r9_r)
144{
145   fprintf(stderr, "nextmo: r9_r (%08x)\n", cpu_get_pc(&space.device()));
146   return 0x00;
147}
148
149WRITE8_MEMBER(nextmo_device::r9_w)
150{
151   fprintf(stderr, "nextmo: r9_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
152}
153
154READ8_MEMBER(nextmo_device::ra_r)
155{
156   fprintf(stderr, "nextmo: ra_r (%08x)\n", cpu_get_pc(&space.device()));
157   return 0x00;
158}
159
160WRITE8_MEMBER(nextmo_device::ra_w)
161{
162   fprintf(stderr, "nextmo: ra_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
163}
164
165READ8_MEMBER(nextmo_device::rb_r)
166{
167   fprintf(stderr, "nextmo: rb_r (%08x)\n", cpu_get_pc(&space.device()));
168   return 0x24;
169}
170
171WRITE8_MEMBER(nextmo_device::rb_w)
172{
173   fprintf(stderr, "nextmo: rb_w %02x (%08x)\n", data, cpu_get_pc(&space.device()));
174}
175
176READ8_MEMBER(nextmo_device::r10_r)
177{
178   fprintf(stderr, "nextmo: r10_r %d (%08x)\n", offset, cpu_get_pc(&space.device()));
179   return 0x00;
180}
181
182WRITE8_MEMBER(nextmo_device::r10_w)
183{
184   fprintf(stderr, "nextmo: r10_w %d, %02x (%08x)\n", offset, data, cpu_get_pc(&space.device()));
185}
186
187void nextmo_device::check_ecc()
188{
189   fprintf(stderr, "nextmo: check_ecc\n");
190   for(int i=0; i<0x400; i++)
191      sector[i] = i;
192}
193
194void nextmo_device::compute_ecc()
195{
196   fprintf(stderr, "nextmo: compute_ecc\n");
197   memset(sector+0x400, 0, 0x110);
198}
src/mess/machine/n82077aa.h
r14142r14143
22#define __N82077AA_H__
33
44#include "emu.h"
5#include "imagedev/floppy.h"
56
67#define MCFG_N82077AA_ADD(_tag, _mode)   \
78   MCFG_DEVICE_ADD(_tag, N82077AA, 0)   \
r14142r14143
910
1011class n82077aa_device : public device_t {
1112public:
13   typedef delegate<void (bool state)> line_cb;
14
1215   enum { MODE_AT, MODE_PS2, MODE_M30 };
1316
1417   n82077aa_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
1518   void set_mode(int mode);
19   void setup_intrq_cb(line_cb cb);
20   void setup_drq_cb(line_cb cb);
1621
1722   DECLARE_ADDRESS_MAP(amap, 8);
1823
r14142r14143
2934   DECLARE_READ8_MEMBER (dir_r);
3035   DECLARE_WRITE8_MEMBER(ccr_w);
3136
37   UINT8 dma_r();
38   void dma_w(UINT8 data);
39   bool get_drq() const;
40
3241protected:
3342   virtual void device_start();
3443   virtual void device_reset();
44   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
3545
3646private:
47   enum {
48      PHASE_CMD, PHASE_EXEC, PHASE_RESULT
49   };
50
51   enum {
52      // General "doing nothing" state
53      IDLE,
54
55      // Main states
56      RECALIBRATE,
57      READ_DATA,
58
59      // Sub-states
60      SEEK_MOVE,
61      SEEK_WAIT_STEP_SIGNAL_TIME,
62      SEEK_WAIT_STEP_SIGNAL_TIME_DONE,
63      SEEK_WAIT_STEP_TIME,
64      SEEK_WAIT_STEP_TIME_DONE,
65
66      HEAD_LOAD_DONE,
67
68      SCAN_ID,
69      SCAN_ID_FAILED,
70
71      SECTOR_READ,
72
73      // Live states
74      SEARCH_ADDRESS_MARK_HEADER,
75      READ_HEADER_BLOCK_HEADER,
76      READ_DATA_BLOCK_HEADER,
77      READ_ID_BLOCK_TO_LOCAL,
78      SEARCH_ADDRESS_MARK_DATA,
79      SEARCH_ADDRESS_MARK_DATA_FAILED,
80      READ_SECTOR_DATA,
81      READ_SECTOR_DATA_BYTE,
82     
83   };
84
85   struct pll_t {
86      attotime ctime, period, min_period, max_period, period_adjust_base, phase_adjust;
87
88      attotime write_start_time;
89      attotime write_buffer[32];
90      int write_position;
91      int freq_hist;
92
93      void set_clock(attotime period);
94      void reset(attotime when);
95      int get_next_bit(attotime &tm, floppy_image_device *floppy, attotime limit);
96      bool write_next_bit(bool bit, attotime &tm, floppy_image_device *floppy, attotime limit);
97      void start_writing(attotime tm);
98      void commit(floppy_image_device *floppy, attotime tm);
99      void stop_writing(floppy_image_device *floppy, attotime tm);
100   };
101
102   struct floppy_info {
103      emu_timer *tm;
104      floppy_image_device *dev;
105      int id;
106      int main_state, sub_state;
107      int dir, status;
108      UINT8 pcn;
109      bool irq, live, index;
110   };
111
112   struct live_info {
113      enum { PT_NONE, PT_CRC_1, PT_CRC_2 };
114
115      attotime tm;
116      int state, next_state;
117      floppy_info *fi;
118      UINT16 shift_reg;
119      UINT16 crc;
120      int bit_counter, byte_counter, previous_type;
121      bool data_separator_phase, data_bit_context;
122      UINT8 data_reg;
123      UINT8 idbuf[6];
124      pll_t pll;
125   };
126
127   static int rates[4];
128
37129   int mode;
130   int main_phase;
131   int counter;
38132
39   UINT8 dor, dsr, ccr, msr;
133   live_info cur_live, checkpoint_live;
134   line_cb intrq_cb, drq_cb;
135   bool cur_irq, drq;
136   floppy_info flopi[4];
137
138   int fifo_pos, fifo_expected, command_pos, result_pos;
139   bool fifo_write;
140   UINT8 dor, dsr, msr, fifo[16], command[16], result[16];
141   UINT8 fifocfg;
142   UINT16 spec;
143   int sector_size;
144
145   static astring tts(attotime t);
146   astring ttsn();
147
148   enum {
149      C_CONFIGURE,
150      C_PERPENDICULAR,
151      C_READ_DATA,
152      C_RECALIBRATE,
153      C_SENSE_INTERRUPT_STATUS,
154      C_SPECIFY,
155
156      C_INVALID,
157      C_INCOMPLETE,
158   };
159
160   void delay_cycles(emu_timer *tm, int cycles);
161   void check_irq();
162   void fifo_expect(int size, bool write);
163   void fifo_push(UINT8 data);
164   void set_drq(bool state);
165
166   int check_command();
167   void start_command(int cmd);
168   void command_end(floppy_info &fi, int status);
169
170   void recalibrate_start(floppy_info &fi);
171   void seek_continue(floppy_info &fi);
172
173   void read_data_start(floppy_info &fi);
174   void read_data_continue(floppy_info &fi);
175
176   void general_continue(floppy_info &fi);
177   void index_callback(floppy_image_device *floppy, int state);
178   bool sector_matches() const;
179
180   void live_start(floppy_info &fi, int live_state);
181   void live_abort();
182   void checkpoint();
183   void rollback();
184   void live_delay(int state);
185   void live_sync();
186   void live_run(attotime limit = attotime::never);
187
188   bool read_one_bit(attotime limit);
189   bool write_one_bit(attotime limit);
40190};
41191
42192extern const device_type N82077AA;
src/mess/machine/nextmo.h
r14142r14143
1#ifndef NEXTMO_H
2#define NEXTMO_H
3
4#define MCFG_NEXTMO_ADD(_tag, _irq, _drq)                  \
5   MCFG_DEVICE_ADD(_tag, NEXTMO, 0)                       \
6   downcast<nextmo_device *>(device)->set_cb(_irq, _drq);
7
8class nextmo_device : public device_t
9{
10public:
11   typedef delegate<void (bool state)> cb_t;
12
13   nextmo_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
14
15   void set_cb(cb_t irq_cb, cb_t drq_cb);
16
17   DECLARE_ADDRESS_MAP(map, 32);
18
19   DECLARE_READ8_MEMBER(r4_r);
20   DECLARE_WRITE8_MEMBER(r4_w);
21   DECLARE_READ8_MEMBER(r5_r);
22   DECLARE_WRITE8_MEMBER(r5_w);
23   DECLARE_READ8_MEMBER(r6_r);
24   DECLARE_WRITE8_MEMBER(r6_w);
25   DECLARE_READ8_MEMBER(r7_r);
26   DECLARE_WRITE8_MEMBER(r7_w);
27   DECLARE_READ8_MEMBER(r8_r);
28   DECLARE_WRITE8_MEMBER(r8_w);
29   DECLARE_READ8_MEMBER(r9_r);
30   DECLARE_WRITE8_MEMBER(r9_w);
31   DECLARE_READ8_MEMBER(ra_r);
32   DECLARE_WRITE8_MEMBER(ra_w);
33   DECLARE_READ8_MEMBER(rb_r);
34   DECLARE_WRITE8_MEMBER(rb_w);
35   DECLARE_READ8_MEMBER(r10_r);
36   DECLARE_WRITE8_MEMBER(r10_w);
37
38   UINT8 dma_r();
39   void dma_w(UINT8 data);
40
41protected:
42   virtual void device_start();
43   virtual void device_reset();
44
45private:
46   UINT8 sector[0x510];
47   UINT8 r4, r5, r6, r7;
48   cb_t irq_cb, drq_cb;
49   int sector_pos;
50
51   void check_dma_end();
52   void check_ecc();
53   void compute_ecc();
54};
55
56extern const device_type NEXTMO;
57
58#endif
src/mess/machine/nextkbd.c
r14142r14143
5454   control |= FLAG_DATA;
5555   if(!(control & FLAG_INT)) {
5656      control |= FLAG_INT;
57      int_change_cb();
57      int_change_cb(true);
5858   }
5959}
6060
r14142r14143
101101
102102READ32_MEMBER( nextkbd_device::ctrl_r )
103103{
104   //   logerror("nextkbd: ctrl_r %08x @ %08x\n", control, mem_mask);
104105   return control;
105106}
106107
r14142r14143
111112
112113READ32_MEMBER( nextkbd_device::data_r )
113114{
114   control &= ~FLAG_DATA;
115   UINT32 old = control;
116   control &= ~(FLAG_DATA|FLAG_INT);
117   if(old & FLAG_INT)
118      int_change_cb(false);
115119   return data;
116120}
117121
r14142r14143
126130      control = data;
127131   }
128132   if(diff & FLAG_INT)
129      int_change_cb();
133      int_change_cb(control & FLAG_INT);
134   //   logerror("nextkbd: ctrl_w %08x @ %08x\n", data, mem_mask);
130135}
131136
132137WRITE32_MEMBER( nextkbd_device::ctrl2_w )
133138{
139   //   logerror("nextkbd: ctrl2_w %08x @ %08x\n", data, mem_mask);
134140}
135141
136142WRITE32_MEMBER( nextkbd_device::data_w )
r14142r14143
145151         modifiers_state |= field.mask;
146152      else
147153         modifiers_state &= ~field.mask;
148      fifo_push(modifiers_state);
154      fifo_push(modifiers_state | (1<<28));
149155   } else {
150156      int index;
151157      for(index=0; index < 32; index++)
r14142r14143
156162      UINT16 val = index | modifiers_state | KEYVALID;
157163      if(newval)
158164         val |= KEYUP;
159      fifo_push(val);
165      fifo_push(val | (1<<28));
160166   }
161167   send();
162168}
src/mess/machine/nextkbd.h
r14142r14143
99
1010class nextkbd_device : public device_t {
1111public:
12   typedef delegate<void ()> int_cb_t;
12   typedef delegate<void (bool state)> int_cb_t;
1313
1414   nextkbd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
1515   void set_int_change_cb(int_cb_t int_change_cb);
src/mess/machine/mb8795.c
r14142r14143
1#define ADDRESS_MAP_MODERN
2
3#include "emu.h"
4#include "mb8795.h"
5
6const device_type MB8795 = &device_creator<mb8795_device>;
7
8DEVICE_ADDRESS_MAP_START(map, 8, mb8795_device)
9   AM_RANGE(0x0, 0x0) AM_READWRITE(txstat_r, txstat_w)
10   AM_RANGE(0x1, 0x1) AM_READWRITE(txmask_r, txmask_w)
11   AM_RANGE(0x2, 0x2) AM_READWRITE(rxstat_r, rxstat_w)
12   AM_RANGE(0x3, 0x3) AM_READWRITE(rxmask_r, rxmask_w)
13   AM_RANGE(0x4, 0x4) AM_READWRITE(txmode_r, txmode_w)
14   AM_RANGE(0x5, 0x5) AM_READWRITE(rxmode_r, rxmode_w)
15   AM_RANGE(0x6, 0x6) AM_WRITE(reset_w)
16   AM_RANGE(0x7, 0x7) AM_READ(tdc_lsb_r)
17   AM_RANGE(0x8, 0xf) AM_READWRITE(mac_r, mac_w) // Mapping limitation, real is up to 0xd
18ADDRESS_MAP_END
19
20mb8795_device::mb8795_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
21   : device_t(mconfig, MB8795, "Fujitsu MB8795", tag, owner, clock),
22     device_network_interface(mconfig, *this, 10)
23{
24}
25
26void mb8795_device::set_irq_cb(line_cb_t tx, line_cb_t rx)
27{
28   irq_tx_cb = tx;
29   irq_rx_cb = rx;
30}
31
32void mb8795_device::set_drq_cb(line_cb_t tx, line_cb_t rx)
33{
34   drq_tx_cb = tx;
35   drq_rx_cb = rx;
36}
37
38void mb8795_device::check_irq()
39{
40   bool old_irq_tx = irq_tx;
41   bool old_irq_rx = irq_rx;
42   irq_tx = txstat & txmask;
43   irq_rx = rxstat & rxmask;
44   if(irq_tx != old_irq_tx && !irq_tx_cb.isnull())
45      irq_tx_cb(irq_tx);
46   if(irq_rx != old_irq_rx && !irq_rx_cb.isnull())
47      irq_rx_cb(irq_rx);
48}
49
50void mb8795_device::device_start()
51{
52   memset(mac, 0, 6);
53   timer_tx = timer_alloc(TIMER_TX);
54   timer_rx = timer_alloc(TIMER_RX);
55}
56
57void mb8795_device::device_reset()
58{
59   txstat = EN_TXS_READY;
60   txmask = 0x00;
61   rxstat = 0x00;
62   rxmask = 0x00;
63   txmode = 0x00;
64   rxmode = 0x00;
65
66   drq_tx = drq_rx = false;
67   irq_tx = irq_rx = false;
68
69   txlen = rxlen = txcount = 0;
70
71   set_promisc(true);
72
73   start_send();   
74}
75
76void mb8795_device::recv_cb(UINT8 *buf, int len)
77{
78   memcpy(rxbuf, buf, len);
79   rxlen = len;
80   receive();
81}
82
83bool mb8795_device::mcast_chk(const UINT8 *buf, int len)
84{
85   return true;
86}
87
88READ8_MEMBER(mb8795_device::txstat_r)
89{
90   //   fprintf(stderr, "mb8795: txstat_r %02x (%08x)\n", txstat, cpu_get_pc(&space.device()));
91   return txstat;
92}
93
94WRITE8_MEMBER(mb8795_device::txstat_w)
95{
96   txstat = txstat & (0xf0 | ~data);
97   check_irq();
98   fprintf(stderr, "mb8795: txstat_w %02x (%08x)\n", txstat, cpu_get_pc(&space.device()));
99}
100
101READ8_MEMBER(mb8795_device::txmask_r)
102{
103   fprintf(stderr, "mb8795: txmask_r %02x (%08x)\n", txmask, cpu_get_pc(&space.device()));
104   return txmask;
105}
106
107WRITE8_MEMBER(mb8795_device::txmask_w)
108{
109   txmask = data & 0xaf;
110   check_irq();
111   fprintf(stderr, "mb8795: txmask_w %02x (%08x)\n", txmask, cpu_get_pc(&space.device()));
112}
113
114READ8_MEMBER(mb8795_device::rxstat_r)
115{
116   fprintf(stderr, "mb8795: rxstat_r %02x (%08x)\n", rxstat, cpu_get_pc(&space.device()));
117   return rxstat;
118}
119
120WRITE8_MEMBER(mb8795_device::rxstat_w)
121{
122   rxstat = rxstat & (0x70 | ~data);
123   check_irq();
124   fprintf(stderr, "mb8795: rxstat_w %02x (%08x)\n", rxstat, cpu_get_pc(&space.device()));
125}
126
127READ8_MEMBER(mb8795_device::rxmask_r)
128{
129   fprintf(stderr, "mb8795: rxmask_r %02x (%08x)\n", rxmask, cpu_get_pc(&space.device()));
130   return rxmask;
131}
132
133WRITE8_MEMBER(mb8795_device::rxmask_w)
134{
135   rxmask = data & 0x9f;
136   check_irq();
137   fprintf(stderr, "mb8795: rxmask_w %02x (%08x)\n", rxmask, cpu_get_pc(&space.device()));
138}
139
140READ8_MEMBER(mb8795_device::txmode_r)
141{
142   fprintf(stderr, "mb8795: txmode_r %02x (%08x)\n", txmode, cpu_get_pc(&space.device()));
143   return txmode;
144}
145
146WRITE8_MEMBER(mb8795_device::txmode_w)
147{
148   txmode = data;
149   fprintf(stderr, "mb8795: txmode_w %02x (%08x)\n", txmode, cpu_get_pc(&space.device()));
150}
151
152READ8_MEMBER(mb8795_device::rxmode_r)
153{
154   fprintf(stderr, "mb8795: rxmode_r %02x (%08x)\n", rxmode, cpu_get_pc(&space.device()));
155   return rxmode;
156}
157
158WRITE8_MEMBER(mb8795_device::rxmode_w)
159{
160   rxmode = data;
161   fprintf(stderr, "mb8795: rxmode_w %02x (%08x)\n", rxmode, cpu_get_pc(&space.device()));
162}
163
164WRITE8_MEMBER(mb8795_device::reset_w)
165{
166   if(data & EN_RST_RESET)
167      device_reset();
168}
169
170READ8_MEMBER(mb8795_device::tdc_lsb_r)
171{
172   fprintf(stderr, "mb8795: tdc_lsb_r %02x (%08x)\n", txcount & 0xff, cpu_get_pc(&space.device()));
173   return txcount;
174}
175
176READ8_MEMBER(mb8795_device::mac_r)
177{
178   if(offset < 6)
179      return mac[offset];
180   if(offset == 7) {
181      fprintf(stderr, "mb8795: tdc_msb_r %02x (%08x)\n", txcount >> 8, cpu_get_pc(&space.device()));
182      return (txcount >> 8) & 0x3f;
183   }
184   return 0;
185}
186
187WRITE8_MEMBER(mb8795_device::mac_w)
188{
189   if(offset < 6) {
190      mac[offset] = data;
191      set_mac((const char *)mac);
192   }
193}
194
195void mb8795_device::start_send()
196{
197   timer_tx->adjust(attotime::zero);
198}
199
200void mb8795_device::tx_dma_w(UINT8 data, bool eof)
201{
202   txbuf[txlen++] = data;
203   if(txstat & EN_TXS_READY) {
204      txstat &= ~EN_TXS_READY;
205      check_irq();
206   }
207
208   drq_tx = false;
209   if(!drq_tx_cb.isnull())
210      drq_tx_cb(drq_tx);
211   
212   if(eof) {
213      fprintf(stderr, "mb8795: send packet, dest=%02x.%02x.%02x.%02x.%02x.%02x len=%04x\n",
214            txbuf[0], txbuf[1], txbuf[2], txbuf[3], txbuf[4], txbuf[5],
215            txlen);
216      if(!(txmode & EN_TMD_LB_DISABLE))
217         fprintf(stderr, " -> loopback active\n");
218
219      if(!(txmode & EN_TMD_LB_DISABLE)) {
220         memcpy(rxbuf, txbuf, txlen);
221         rxlen = txlen;
222         receive();
223      }
224      send(txbuf, txlen);
225      txlen = 0;
226      txstat |= EN_TXS_READY;
227      txcount++;
228      start_send();
229   } else
230      timer_tx->adjust(attotime::from_nsec(800));
231}
232
233void mb8795_device::rx_dma_r(UINT8 &data, bool &eof)
234{
235   drq_rx = false;
236   if(!drq_rx_cb.isnull())
237      drq_rx_cb(drq_rx);
238
239   if(rxlen) {
240      data = rxbuf[0];
241      rxlen--;
242      memmove(rxbuf, rxbuf+1, rxlen);
243   } else
244      data = 0;
245
246   if(rxlen) {
247      timer_rx->adjust(attotime::from_nsec(800));
248      eof = false;
249   } else
250      eof = true;
251}
252
253void mb8795_device::receive()
254{
255   fprintf(stderr, "mb8975: received packet for %02x.%02x.%02x.%02x.%02x.%02x len=%04x, mode=%d\n",
256         rxbuf[0], rxbuf[1], rxbuf[2], rxbuf[3], rxbuf[4], rxbuf[5],
257         rxlen, rxmode & 3);
258   bool keep;
259   switch(rxmode & EN_RMD_WHATRECV) {
260   case EN_RMD_RECV_NONE:
261      keep = false;
262      break;
263   case EN_RMD_RECV_NORMAL:
264      keep = recv_is_broadcast() || recv_is_me() || recv_is_local_multicast();
265      break;
266   case EN_RMD_RECV_MULTI:
267      keep = recv_is_broadcast() || recv_is_me() || recv_is_multicast();
268      break;
269   case EN_RMD_RECV_PROMISC:
270      keep = true;
271      break;
272   }
273   fprintf(stderr, " -> %s\n", keep ? "kept" : "dropped");
274   if(!keep)
275      rxlen = false;
276   else {
277      rxstat |= EN_RXS_OK;
278      check_irq();
279      timer_rx->adjust(attotime::zero);
280   }
281}
282
283bool mb8795_device::recv_is_broadcast()
284{
285   return
286      rxbuf[0] == 0xff &&
287      rxbuf[1] == 0xff &&
288      rxbuf[2] == 0xff &&
289      rxbuf[3] == 0xff &&
290      rxbuf[4] == 0xff &&
291      rxbuf[5] == 0xff;
292}
293
294bool mb8795_device::recv_is_me()
295{
296   return
297      rxbuf[0] == mac[0] &&
298      rxbuf[1] == mac[1] &&
299      rxbuf[2] == mac[2] &&
300      rxbuf[3] == mac[3] &&
301      rxbuf[4] == mac[4] &&
302      ((rxmode & EN_RMD_ADDRSIZE) || rxbuf[5] == mac[5]);
303}
304
305bool mb8795_device::recv_is_local_multicast()
306{
307   return
308      (rxbuf[0] & 0x01) &&
309      (rxbuf[0] & 0xfe) == mac[0] &&
310      rxbuf[1] == mac[1] &&
311      rxbuf[2] == mac[2];
312}
313
314bool mb8795_device::recv_is_multicast()
315{
316   return rxbuf[0] & 0x01;
317}
318
319void mb8795_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
320{
321   if(id == TIMER_TX) {
322      drq_tx = true;
323      if(!drq_tx_cb.isnull())
324         drq_tx_cb(drq_tx);
325   }
326
327   if(id == TIMER_RX && rxlen) {
328      drq_rx = true;
329      if(!drq_rx_cb.isnull())
330         drq_rx_cb(drq_rx);
331   }
332}
333
334
src/mess/includes/next.h
r14142r14143
77#include "cpu/m68000/m68000.h"
88#include "imagedev/flopdrv.h"
99#include "machine/mccs1850.h"
10#include "machine/am8530h.h"
10#include "machine/8530scc.h"
1111#include "machine/nextkbd.h"
1212#include "machine/n82077aa.h"
13#include "machine/ncr5390.h"
14#include "machine/mb8795.h"
15#include "machine/nextmo.h"
16#include "imagedev/chd_cd.h"
17#include "imagedev/harddriv.h"
1318
1419class next_state : public driver_device
1520{
r14142r14143
2025        rtc(*this, "rtc"),
2126        scc(*this, "scc"),
2227        keyboard(*this, "keyboard"),
28        scsi(*this, "scsi"),
29        net(*this, "net"),
30        mo(*this, "mo"),
2331        fdc(*this, "fdc")
2432   { }
2533
2634   required_device<cpu_device> maincpu;
2735   required_device<mccs1850_device> rtc;
28   required_device<am8530h_device> scc;
36   required_device<scc8530_t> scc;
2937   required_device<nextkbd_device> keyboard;
30   required_device<n82077aa_device> fdc;
38   required_device<ncr5390_device> scsi;
39   required_device<mb8795_device> net;
40   required_device<nextmo_device> mo;
41   optional_device<n82077aa_device> fdc; // 040 only
3142
3243   UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
3344
r14142r14143
3849   WRITE32_MEMBER( scr2_w );
3950   READ32_MEMBER( scr1_r );
4051   READ32_MEMBER( irq_status_r );
41   WRITE32_MEMBER( irq_status_w );
4252   READ32_MEMBER( irq_mask_r );
4353   WRITE32_MEMBER( irq_mask_w );
4454   READ32_MEMBER( modisk_r );
4555   READ32_MEMBER( network_r );
4656   READ32_MEMBER( event_counter_r );
4757   READ32_MEMBER( dsp_r );
58   READ32_MEMBER( fdc_control_r );
59   WRITE32_MEMBER( fdc_control_w );
60   READ32_MEMBER( dma_ctrl_r );
61   WRITE32_MEMBER( dma_ctrl_w );
62   WRITE32_MEMBER( dma_040_ctrl_w );
63   READ32_MEMBER( dma_regs_r );
64   WRITE32_MEMBER( dma_regs_w );
65   READ32_MEMBER( scsictrl_r );
66   WRITE32_MEMBER( scsictrl_w );
67   READ32_MEMBER( phy_r );
68   WRITE32_MEMBER( phy_w );
69   READ32_MEMBER( timer_data_r );
70   WRITE32_MEMBER( timer_data_w );
71   READ32_MEMBER( timer_ctrl_r );
72   WRITE32_MEMBER( timer_ctrl_w );
4873
4974   UINT32 scr2;
5075   UINT32 irq_status;
5176   UINT32 irq_mask;
77   int irq_level;
5278   UINT32 *vram;
79   UINT8 scsictrl, scsistat;
5380
54   void scc_int();
55   void keyboard_int();
81   UINT32 phy[2];
5682
83   attotime timer_tbase;
84   UINT16 timer_vbase;
85   UINT32 timer_data;
86   UINT32 timer_ctrl;
87   emu_timer *timer_tm;
88
89   UINT32 eventc_latch;
90
91   void scc_irq(int state);
92   void keyboard_irq(bool state);
93
94   void scsi_irq(bool state);
95   void scsi_drq(bool state);
96
97   void fdc_irq(bool state);
98   void fdc_drq(bool state);
99
100   void net_tx_irq(bool state);
101   void net_rx_irq(bool state);
102   void net_tx_drq(bool state);
103   void net_rx_drq(bool state);
104
105   void mo_irq(bool state);
106   void mo_drq(bool state);
107
108   static const SCSIConfigTable scsi_devices;
109   static const floppy_format_type floppy_formats[];
110   static const cdrom_interface cdrom_intf;
111   static const harddisk_interface harddisk_intf;
112   
57113protected:
114   struct dma_slot {
115      UINT32 start, limit, chain_start, chain_limit, current;
116      UINT8 state;
117      bool supdate, drq;
118   };
119
120   enum {
121      // write bits
122      DMA_SETENABLE    = 0x01,
123      DMA_SETSUPDATE   = 0x02,
124      DMA_SETREAD      = 0x04,
125      DMA_CLRCOMPLETE  = 0x08,
126      DMA_RESET        = 0x10,
127      DMA_INITBUF      = 0x20,
128      DMA_INITBUFTURBO = 0x40,
129
130      // read bits
131      DMA_ENABLE       = 0x01,
132      DMA_SUPDATE      = 0x02,
133      DMA_READ         = 0x04,
134      DMA_COMPLETE     = 0x08,
135      DMA_BUSEXC       = 0x10,
136   };
137
138   static const char *dma_targets[0x20];
139   static const int dma_irqs[0x20];
140   static const int scsi_clocks[4];
141
142   dma_slot dma_slots[0x20];
143   UINT32 esp;
144
58145   virtual void machine_start();
59146   virtual void machine_reset();
147
148   void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
149   void timer_start();
150   void timer_update();
151
152   void irq_set(int id, bool raise);
153   void irq_check();
154   const char *dma_name(int slot);
155   void dma_do_ctrl_w(int slot, UINT8 data);
156   void dma_drq_w(int slot, bool state);
157   void dma_read(int slot, UINT8 &val, bool &eof, bool &err);
158   void dma_write(int slot, UINT8 val, bool eof, bool &err);
159   void dma_check_end(int slot, bool eof);
160   void dma_done(int slot);
161   void dma_end(int slot);
60162};
61163
62164#endif
src/mess/mess.mak
r14142r14143
512512   $(MESS_MACHINE)/s100.o      \
513513   $(MESS_MACHINE)/upd765.o   \
514514   $(MESS_MACHINE)/ncr5380.o   \
515   $(MESS_MACHINE)/ncr5390.o   \
515516   $(MESS_MACHINE)/pc_lpt.o   \
516517   $(MESS_MACHINE)/pc_mouse.o   \
517518   $(MESS_MACHINE)/pcf8593.o   \
r14142r14143
541542   $(MESS_MACHINE)/wd1772.o   \
542543   $(MESS_MACHINE)/3c503.o      \
543544   $(MESS_FORMATS)/z80bin.o   \
545   $(MESS_MACHINE)/n82077aa.o   \
546   $(MESS_MACHINE)/mb8795.o   \
544547
545548
546549
r14142r14143
12101213$(MESSOBJ)/next.a:            \
12111214   $(MESS_DRIVERS)/next.o      \
12121215   $(MESS_MACHINE)/nextkbd.o   \
1213   $(MESS_MACHINE)/n82077aa.o   \
1216   $(MESS_MACHINE)/nextmo.o   \
12141217
12151218$(MESSOBJ)/nintendo.a:         \
12161219   $(MESS_MACHINE)/nes_mmc.o   \
src/mess/drivers/next.c
r14142r14143
1919#define ADDRESS_MAP_MODERN
2020
2121#include "includes/next.h"
22#include "machine/pc_fdc.h"
22#include "formats/pc_dsk.h"
23#include "formats/mfi_dsk.h"
2324
2425UINT32 next_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
2526{
r14142r14143
141142   return 0x00012002; // TODO
142143}
143144
144READ32_MEMBER( next_state::irq_status_r )
145// Interrupt subsystem
146// source    bit   level
147// nmi       31    7
148// pfail     30    7
149// timer     29    6
150// enetxdma  28    6
151// enetrdma  27    6
152// scsidma   26    6
153// diskdma   25    6
154// prndma    24    6
155// sndoutdma 23    6
156// sndindma  22    6
157// sccdma    21    6
158// dspdma    20    6
159// m2rdma    19    6
160// r2mdma    18    6
161// scc       17    5
162// remote    16    5
163// bus       15    5
164// dsp4      14    4
165// disk      13    3
166// scsi      12    3
167// printer   11    3
168// enetx     10    3
169// enetr      9    3
170// soundovr   8    3
171// phone      7    3 -- floppy
172// dsp3       6    3
173// video      5    3
174// monitor    4    3
175// kbdmouse   3    3
176// power      2    3
177// softint1   1    2
178// softint0   0    1
179
180void next_state::irq_set(int id, bool raise)
145181{
146   return irq_status;
182   UINT32 mask = 1U << id;
183   if(raise)
184      irq_status |= mask;
185   else
186      irq_status &= ~mask;
187   irq_check();
147188}
148189
149WRITE32_MEMBER( next_state::irq_status_w )
190
191READ32_MEMBER( next_state::irq_status_r )
150192{
151   COMBINE_DATA(&irq_status);
193   return irq_status;
152194}
153195
154196READ32_MEMBER( next_state::irq_mask_r )
r14142r14143
159201WRITE32_MEMBER( next_state::irq_mask_w )
160202{
161203   COMBINE_DATA(&irq_mask);
204   irq_check();
162205}
163206
164READ32_MEMBER( next_state::modisk_r)
207void next_state::irq_check()
165208{
166   return 0; // return 0 atm
209   UINT32 act = irq_status & irq_mask;
210   int bit;
211   for(bit=31; bit >= 0 && !(act & (1U << bit)); bit--);
212
213   int level;
214   if     (bit <  0) level = 0;
215   else if(bit <  1) level = 1;
216   else if(bit <  2) level = 2;
217   else if(bit < 14) level = 3;
218   else if(bit < 15) level = 4;
219   else if(bit < 18) level = 5;
220   else if(bit < 30) level = 6;
221   else              level = 7;
222
223   fprintf(stderr, "IRQ info %08x/%08x - %d\n", irq_status, irq_mask, level);
224
225   if(level != irq_level) {
226      maincpu->set_input_line(irq_level, CLEAR_LINE);
227      maincpu->set_input_line_and_vector(level, ASSERT_LINE, M68K_INT_ACK_AUTOVECTOR);
228      irq_level = level;
229   }
167230}
168231
232const char *next_state::dma_targets[0x20] = {
233   0, "scsi", 0, 0, "soundout", "disk", 0, 0,
234   "soundin", "printer", 0, 0, "scc", "dsp", 0, 0,
235   "s-enetx", "enetx", 0, 0, "s-enetr", "enetr", 0, 0,
236   "video", 0, 0, 0, "r2m", "m2r", 0, 0
237};
238
239const int next_state::dma_irqs[0x20] = {
240   -1, 26, -1, -1, 23, 25, -1, -1, 22, 24, -1, -1, 21, 20, -1, -1,
241   -1, 28, -1, -1, -1, 27, -1, -1, -2, -1, -1, -1, 18, 19, -1, -1
242};
243
244const char *next_state::dma_name(int slot)
245{
246   static char buf[32];
247   if(dma_targets[slot])
248      return dma_targets[slot];
249   sprintf(buf, "<%02x>", slot);
250   return buf;
251}
252
253void next_state::dma_drq_w(int slot, bool state)
254{
255   //   fprintf(stderr, "DMA drq_w %d, %d\n", slot, state);
256   dma_slot &ds = dma_slots[slot];
257   ds.drq = state;
258   if(state && (ds.state & DMA_ENABLE)) {
259      address_space *space = maincpu->memory().space(AS_PROGRAM);
260      if(ds.state & DMA_READ) {
261         while(ds.drq) {
262            UINT8 val;
263            bool eof;
264            bool err;
265            dma_read(slot, val, eof, err);
266            if(err) {
267               ds.state = (ds.state & ~DMA_ENABLE) | DMA_BUSEXC;
268               fprintf(stderr, "DMA: bus error on read slot %d\n", slot);
269               return;
270            }
271            if(0)
272               fprintf(stderr, "DMA [%08x] = %02x\n", ds.current, val);
273            space->write_byte(ds.current++, val);
274            dma_check_end(slot, eof);
275            if(!(ds.state & DMA_ENABLE))
276               return;
277         }
278      } else {
279         while(ds.drq) {
280            UINT8 val = space->read_byte(ds.current++);
281            bool eof = ds.current == (ds.limit & 0x7fffffff) && (ds.limit & 0x80000000);
282            bool err;
283            dma_write(slot, val, eof, err);
284            if(err) {
285               ds.state = (ds.state & ~DMA_ENABLE) | DMA_BUSEXC;
286               fprintf(stderr, "DMA: bus error on write slot %d\n", slot);
287               return;
288            }
289            dma_check_end(slot, false);
290            if(!(ds.state & DMA_ENABLE))
291               return;
292         }
293      }
294   }
295}
296
297void next_state::dma_read(int slot, UINT8 &val, bool &eof, bool &err)
298{
299   err = false;
300   eof = false;
301   switch(slot) {
302   case 1:
303      val = fdc->dma_r();
304      break;
305
306   case 5:
307      val = mo->dma_r();
308      break;
309
310   case 21:
311      net->rx_dma_r(val, eof);
312      break;
313
314   default:
315      err = true;
316      val = 0;
317      break;
318   }
319}
320
321void next_state::dma_write(int slot, UINT8 data, bool eof, bool &err)
322{
323   err = false;
324   switch(slot) {
325   case 4:
326      break;
327
328   case 5:
329      mo->dma_w(data);
330      break;
331
332   case 17:
333      net->tx_dma_w(data, eof);
334      break;
335
336   default:
337      err = true;
338      break;
339   }
340}
341
342void next_state::dma_end(int slot)
343{
344   dma_slot &ds = dma_slots[slot];
345   if(ds.supdate) {
346      dma_slot &ds1 = dma_slots[(slot-1) & 31];
347      ds1.start = ds.start;
348      ds1.limit = ds.current;
349      ds.start = ds.chain_start;
350      ds.limit = ds.chain_limit;
351      ds.current = ds.start;
352      ds.supdate = false;
353   } else
354      ds.state &= ~DMA_ENABLE;
355   ds.state |= DMA_COMPLETE;
356   if(dma_irqs[slot] >= 0)
357      irq_set(dma_irqs[slot], true);
358}
359
360void next_state::dma_check_end(int slot, bool eof)
361{
362   dma_slot &ds = dma_slots[slot];
363   if(eof || ds.current == (ds.limit & 0x7fffffff))
364      dma_end(slot);
365}
366
367READ32_MEMBER( next_state::dma_regs_r)
368{
369   int slot = offset >> 2;
370   int reg = offset & 3;
371
372   const char *name = dma_name(slot);
373
374   fprintf(stderr, "dma_regs_r %s:%d (%08x)\n", name, reg, cpu_get_pc(&space.device()));
375   switch(reg) {
376   case 0:
377      return dma_slots[slot].start;
378   case 1:
379      return dma_slots[slot].limit;
380   case 2:
381      return dma_slots[slot].chain_start;
382   case 3: default:
383      return dma_slots[slot].chain_limit;
384   }
385}
386
387WRITE32_MEMBER( next_state::dma_regs_w)
388{
389   int slot = offset >> 2;
390   int reg = offset & 3;
391
392   const char *name = dma_name(slot);
393
394   fprintf(stderr, "dma_regs_w %s:%d %08x (%08x)\n", name, reg, data, cpu_get_pc(&space.device()));
395   switch(reg) {
396   case 0:
397      dma_slots[slot].start = data;
398      dma_slots[slot].current = data;
399      break;
400   case 1:
401      dma_slots[slot].limit = data;
402      break;
403   case 2:
404      dma_slots[slot].chain_start = data;
405      break;
406   case 3:
407      dma_slots[slot].chain_limit = data;
408      break;
409   }
410}
411
412READ32_MEMBER( next_state::dma_ctrl_r)
413{
414   int slot = offset >> 2;
415   int reg = offset & 3;
416
417   const char *name = dma_name(slot);
418
419   fprintf(stderr, "dma_ctrl_r %s:%d %02x (%08x)\n", name, reg, dma_slots[slot].state, cpu_get_pc(&space.device()));
420
421   return reg ? 0 : dma_slots[slot].state << 24;
422}
423
424WRITE32_MEMBER( next_state::dma_ctrl_w)
425{
426   int slot = offset >> 2;
427   int reg = offset & 3;
428   const char *name = dma_name(slot);
429   fprintf(stderr, "dma_ctrl_w %s:%d %08x @ %08x (%08x)\n", name, reg, data, mem_mask, cpu_get_pc(&space.device()));
430   if(!reg) {
431      if(ACCESSING_BITS_16_23)
432         dma_do_ctrl_w(slot, data >> 16);
433      else if(ACCESSING_BITS_24_31)
434         dma_do_ctrl_w(slot, data >> 24);
435   }
436}
437
438WRITE32_MEMBER( next_state::dma_040_ctrl_w)
439{
440   int slot = offset >> 2;
441   int reg = offset & 3;
442   if(!reg && ACCESSING_BITS_16_23)
443      dma_do_ctrl_w(slot, data >> 16);
444}
445
446void next_state::dma_do_ctrl_w(int slot, UINT8 data)
447{
448   const char *name = dma_name(slot);
449#if 0
450   fprintf(stderr, "dma_ctrl_w %s %02x (%08x)\n", name, data, cpu_get_pc(maincpu));
451
452   fprintf(stderr, "  ->%s%s%s%s%s%s%s\n",
453         data & DMA_SETENABLE ? " enable" : "",
454         data & DMA_SETSUPDATE ? " supdate" : "",
455         data & DMA_SETREAD ? " read" : "",
456         data & DMA_CLRCOMPLETE ? " complete" : "",
457         data & DMA_RESET ? " reset" : "",
458         data & DMA_INITBUF ? " initbuf" : "",
459         data & DMA_INITBUFTURBO ? " initbufturbo" : "");
460#endif
461   if(data & DMA_SETENABLE)
462      fprintf(stderr, "dma enable %s %s %08x (%08x)\n", name, data & DMA_SETREAD ? "read" : "write", (dma_slots[slot].limit-dma_slots[slot].start) & 0x7fffffff, cpu_get_pc(maincpu));
463
464   dma_slot &ds = dma_slots[slot];
465   if(data & (DMA_RESET|DMA_INITBUF|DMA_INITBUFTURBO)) {
466      ds.state = 0;
467      if(dma_irqs[slot] >= 0)
468         irq_set(dma_irqs[slot], false);
469   }
470   if(data & DMA_SETSUPDATE) {
471      ds.state |= DMA_SUPDATE;
472      ds.supdate = true;
473   }
474   if(data & DMA_SETREAD)
475      ds.state |= DMA_READ;
476   if(data & DMA_CLRCOMPLETE) {
477      ds.state &= ~DMA_COMPLETE;
478      if(dma_irqs[slot] >= 0)
479         irq_set(dma_irqs[slot], false);
480   }
481   if(data & DMA_SETENABLE) {
482      ds.state |= DMA_ENABLE;
483      //      fprintf(stderr, "dma slot %d drq=%s\n", slot, ds.drq ? "on" : "off");
484      if(ds.drq)
485         dma_drq_w(slot, ds.drq);
486   }
487}
488
489const int next_state::scsi_clocks[4] = { 10000000, 12000000, 20000000, 16000000 };
490
491READ32_MEMBER( next_state::scsictrl_r )
492{
493   fprintf(stderr, "read %08x\n", cpu_get_pc(&space.device()));
494   return (scsictrl << 24) | (scsistat << 16);
495}
496
497WRITE32_MEMBER( next_state::scsictrl_w )
498{
499   if(ACCESSING_BITS_24_31) {
500      scsictrl = data >> 24;
501      if(scsictrl & 0x02)
502         scsi->reset();
503      device_t::static_set_clock(*scsi, scsi_clocks[scsictrl >> 6]);
504
505      fprintf(stderr, "SCSIctrl %dMHz int=%s dma=%s dmadir=%s%s%s dest=%s (%08x)\n",
506            scsi_clocks[scsictrl >> 6]/1000000,
507            scsictrl & 0x20 ? "on" : "off",
508            scsictrl & 0x10 ? "on" : "off",
509            scsictrl & 0x08 ? "read" : "write",
510            scsictrl & 0x04 ? " flush" : "",
511            scsictrl & 0x02 ? " reset" : "",
512            scsictrl & 0x01 ? "wd3392" : "ncr5390",
513            cpu_get_pc(&space.device()));
514   }
515   if(ACCESSING_BITS_16_23) {
516      scsistat = data >> 16;
517      fprintf(stderr, "SCSIstat %02x (%08x)\n", data, cpu_get_pc(&space.device()));
518   }
519}
520
169521READ32_MEMBER( next_state::event_counter_r)
170522{
171523   // Event counters, around that time, are usually fixed-frequency counters.
r14142r14143
173525
174526   // The nexttrb rom seems pretty convinced that it's 20 bits only.
175527
176   return machine().time().as_ticks(1000000) & 0xfffff;
528   if(ACCESSING_BITS_24_31)
529      eventc_latch = machine().time().as_ticks(1000000) & 0xfffff;
530   return eventc_latch;
177531}
178532
179READ32_MEMBER( next_state::network_r)
533READ32_MEMBER( next_state::dsp_r)
180534{
181   return 0xffffffff;
535   return 0x7fffffff;
182536}
183537
184READ32_MEMBER( next_state::dsp_r)
538WRITE32_MEMBER( next_state::fdc_control_w )
185539{
186   return 0xffffffff;
540   fprintf(stderr, "FDC write %02x (%08x)\n", data >> 24, cpu_get_pc(&space.device()));
187541}
188542
189void next_state::scc_int()
543READ32_MEMBER( next_state::fdc_control_r )
190544{
545   // Type of floppy present?
546   // Seems to behave identically as long as b24-25 is non-zero
547   // Zero means no floppy
548
549   fprintf(stderr, "FDC read (%08x)\n", cpu_get_pc(&space.device()));
550   return 0 << 24;
191551}
192552
193void next_state::keyboard_int()
553READ32_MEMBER( next_state::phy_r )
194554{
555   logerror("phy_r %d %08x (%08x)\n", offset, phy[offset], cpu_get_pc(&space.device()));
556   return phy[offset] | (0 << 24);
195557}
196558
559WRITE32_MEMBER( next_state::phy_w )
560{
561   COMBINE_DATA(phy+offset);
562   logerror("phy_w %d %08x (%08x)\n", offset, phy[offset], cpu_get_pc(&space.device()));
563}
564
565void next_state::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
566{
567   irq_set(29, true);
568}
569
570READ32_MEMBER( next_state::timer_data_r )
571{
572   if(timer_ctrl & 0x80000000)
573      timer_update();
574   return timer_data;
575}
576
577WRITE32_MEMBER( next_state::timer_data_w )
578{
579   if(timer_ctrl & 0x80000000)
580      timer_update();
581   COMBINE_DATA(&timer_data);
582   timer_data &= 0xffff0000;
583   if(timer_ctrl & 0x80000000)
584      timer_start();
585}
586
587READ32_MEMBER( next_state::timer_ctrl_r )
588{
589   irq_set(29, false);
590   return timer_ctrl;
591}
592
593WRITE32_MEMBER( next_state::timer_ctrl_w )
594{
595   bool oldact = timer_ctrl & 0x80000000;
596   COMBINE_DATA(&timer_ctrl);
597   bool newact = timer_ctrl & 0x80000000;
598   if(oldact != newact) {
599      if(oldact) {
600         timer_update();
601         irq_set(29, false);
602      } else
603         timer_start();
604   }
605}
606
607void next_state::timer_update()
608{
609   int delta = timer_vbase - (machine().time() - timer_tbase).as_ticks(1000000);
610   if(delta < 0)
611      delta = 0;
612   timer_data = delta << 16;
613}
614
615void next_state::timer_start()
616{
617   timer_tbase = machine().time();
618   timer_vbase = timer_data >> 16;
619   timer_tm->adjust(attotime::from_usec(timer_vbase));
620}
621
622void next_state::scc_irq(int state)
623{
624   irq_set(17, state);
625}
626
627void next_state::keyboard_irq(bool state)
628{
629   irq_set(3, state);
630}
631
632void next_state::fdc_irq(bool state)
633{
634   irq_set(7, state);
635}
636
637void next_state::fdc_drq(bool state)
638{
639   dma_drq_w(1, state);
640}
641
642void next_state::net_tx_irq(bool state)
643{
644   irq_set(10, state);
645}
646
647void next_state::net_rx_irq(bool state)
648{
649   irq_set(9, state);
650}
651
652void next_state::net_tx_drq(bool state)
653{
654   dma_drq_w(17, state);
655}
656
657void next_state::net_rx_drq(bool state)
658{
659   dma_drq_w(21, state);
660}
661
662void next_state::mo_irq(bool state)
663{
664   irq_set(13, state);
665}
666
667void next_state::mo_drq(bool state)
668{
669   dma_drq_w(5, state);
670}
671
672void next_state::scsi_irq(bool state)
673{
674   irq_set(12, state);
675}
676
677void next_state::scsi_drq(bool state)
678{
679   dma_drq_w(26, state);
680}
681
197682void next_state::machine_start()
198683{
199684   save_item(NAME(scr2));
200685   save_item(NAME(irq_status));
201686   save_item(NAME(irq_mask));
687   save_item(NAME(irq_level));
688   save_item(NAME(phy));
689   save_item(NAME(scsictrl));
690   save_item(NAME(timer_tbase));
691   save_item(NAME(timer_vbase));
692   save_item(NAME(timer_data));
693   save_item(NAME(timer_ctrl));
694   save_item(NAME(eventc_latch));
695
696   timer_tm = timer_alloc(0);
697
698   if(fdc) {
699      fdc->setup_intrq_cb(n82077aa_device::line_cb(FUNC(next_state::fdc_irq), this));
700      fdc->setup_drq_cb(n82077aa_device::line_cb(FUNC(next_state::fdc_drq), this));
701   }
202702}
203703
204704void next_state::machine_reset()
r14142r14143
206706   scr2 = 0;
207707   irq_status = 0;
208708   irq_mask = 0;
709   irq_level = 0;
710   esp = 0;
711   scsictrl = 0;
712   phy[0] = phy[1] = 0;
713   eventc_latch = 0;
714   timer_vbase = 0;
715   timer_data = 0;
716   timer_ctrl = 0;
717   dma_drq_w(4, true); // soundout
209718}
210719
211720static ADDRESS_MAP_START( next_mem, AS_PROGRAM, 32, next_state )
212721   AM_RANGE(0x00000000, 0x0001ffff) AM_ROM AM_REGION("user1", 0)
213722   AM_RANGE(0x01000000, 0x0101ffff) AM_ROM AM_REGION("user1", 0)
214//  AM_RANGE(0x02000010, 0x02000010) AM_MIRROR(0x300000) SCSI DMA CSR
215//  AM_RANGE(0x02000040, 0x02000040) AM_MIRROR(0x300000) SOUNDOUT DMA CSR
216//  AM_RANGE(0x02000050, 0x02000050) AM_MIRROR(0x300000) DISK DMA CSR
217//  AM_RANGE(0x02000080, 0x02000080) AM_MIRROR(0x300000) SOUNDIN DMA CSR
218//  AM_RANGE(0x02000090, 0x02000090) AM_MIRROR(0x300000) PRINTER DMA CSR
219//  AM_RANGE(0x020000c0, 0x020000c0) AM_MIRROR(0x300000) SCC DMA CSR
220//  AM_RANGE(0x020000d0, 0x020000d0) AM_MIRROR(0x300000) DSP DMA CSR
221//  AM_RANGE(0x02000110, 0x02000110) AM_MIRROR(0x300000) ENETX DMA CSR
222//  AM_RANGE(0x02000150, 0x02000150) AM_MIRROR(0x300000) ENETR DMA CSR
223//  AM_RANGE(0x02000180, 0x02000180) AM_MIRROR(0x300000) VIDEO DMA CSR
224//  AM_RANGE(0x020001c0, 0x020001c0) AM_MIRROR(0x300000) R2M DMA CSR
225//  AM_RANGE(0x020001d0, 0x020001d0) AM_MIRROR(0x300000) M2R DMA CSR
226   AM_RANGE(0x02006000, 0x02006003) AM_MIRROR(0x300000) AM_READ(network_r) // ethernet
723   AM_RANGE(0x02000000, 0x020001ff) AM_MIRROR(0x300200) AM_READWRITE(dma_ctrl_r, dma_ctrl_w)
724   AM_RANGE(0x02004000, 0x020041ff) AM_MIRROR(0x300200) AM_READWRITE(dma_regs_r, dma_regs_w)
725   AM_RANGE(0x02006000, 0x0200600f) AM_MIRROR(0x300000) AM_DEVICE8("net", mb8795_device, map, 0xffffffff)
227726//  AM_RANGE(0x02006010, 0x02006013) AM_MIRROR(0x300000) memory timing
228   AM_RANGE(0x02007000, 0x02007003) AM_MIRROR(0x300000) AM_READWRITE(irq_status_r,irq_status_w)
727   AM_RANGE(0x02007000, 0x02007003) AM_MIRROR(0x300000) AM_READ(irq_status_r)
229728   AM_RANGE(0x02007800, 0x02007803) AM_MIRROR(0x300000) AM_READWRITE(irq_mask_r,irq_mask_w)
230729   AM_RANGE(0x02008000, 0x02008003) AM_MIRROR(0x300000) AM_READ(dsp_r)
231730   AM_RANGE(0x0200c000, 0x0200c003) AM_MIRROR(0x300000) AM_READ(scr1_r)
r14142r14143
235734   AM_RANGE(0x0200e000, 0x0200e00b) AM_MIRROR(0x300000) AM_DEVICE("keyboard", nextkbd_device, amap)
236735//  AM_RANGE(0x0200f000, 0x0200f003) AM_MIRROR(0x300000) printer
237736//  AM_RANGE(0x02010000, 0x02010003) AM_MIRROR(0x300000) brightness
238   AM_RANGE(0x02012004, 0x02012007) AM_MIRROR(0x300000) AM_READ(modisk_r)
239//  AM_RANGE(0x02014000, 0x02014003) AM_MIRROR(0x300000) SCSI
240   AM_RANGE(0x02014100, 0x02014107) AM_MIRROR(0x300000) AM_DEVICE8("fdc", n82077aa_device, amap, 0xffffffff)
241//  AM_RANGE(0x02016000, 0x02016003) AM_MIRROR(0x300000) timer
242//  AM_RANGE(0x02016004, 0x02016007) AM_MIRROR(0x300000) timer CSR
243   AM_RANGE(0x02018000, 0x02018003) AM_MIRROR(0x300000) AM_DEVREADWRITE8("scc", am8530h_device, ca_r, ca_w, 0xff000000)
244   AM_RANGE(0x02018000, 0x02018003) AM_MIRROR(0x300000) AM_DEVREADWRITE8("scc", am8530h_device, cb_r, cb_w, 0x00ff0000)
245   AM_RANGE(0x02018000, 0x02018003) AM_MIRROR(0x300000) AM_DEVREADWRITE8("scc", am8530h_device, da_r, da_w, 0x0000ff00)
246   AM_RANGE(0x02018000, 0x02018003) AM_MIRROR(0x300000) AM_DEVREADWRITE8("scc", am8530h_device, db_r, db_w, 0x000000ff)
737   AM_RANGE(0x02012000, 0x0201201f) AM_MIRROR(0x300000) AM_DEVICE8("mo", nextmo_device, map, 0xffffffff)
738   AM_RANGE(0x02014000, 0x0201400f) AM_MIRROR(0x300000) AM_DEVICE8("scsi", ncr5390_device, map, 0xffffffff)
739   AM_RANGE(0x02114020, 0x02114023) AM_MIRROR(0x300000) AM_READWRITE(scsictrl_r, scsictrl_w)
740   AM_RANGE(0x02016000, 0x02016003) AM_MIRROR(0x300000) AM_READWRITE(timer_data_r, timer_data_w)
741   AM_RANGE(0x02016004, 0x02016007) AM_MIRROR(0x300000) AM_READWRITE(timer_ctrl_r, timer_ctrl_w)
742   AM_RANGE(0x02018000, 0x02018003) AM_MIRROR(0x300000) AM_DEVREADWRITE8("scc", scc8530_t, reg_r, reg_w, 0xffffffff)
247743//  AM_RANGE(0x02018004, 0x02018007) AM_MIRROR(0x300000) SCC CLK
248744//  AM_RANGE(0x02018100, 0x02018103) AM_MIRROR(0x300000) Color RAMDAC
249745//  AM_RANGE(0x02018104, 0x02018107) AM_MIRROR(0x300000) Color CSR
r14142r14143
251747//  AM_RANGE(0x02018198, 0x0201819f) AM_MIRROR(0x300000) warp 9c VRAM timing
252748   AM_RANGE(0x0201a000, 0x0201a003) AM_MIRROR(0x300000) AM_READ(event_counter_r) // EVENTC
253749//  AM_RANGE(0x020c0000, 0x020c0004) AM_MIRROR(0x300000) BMAP
750   AM_RANGE(0x020c0030, 0x020c0037) AM_MIRROR(0x300000) AM_READWRITE(phy_r, phy_w)
254751//  AM_RANGE(0x02000000, 0x0201ffff) AM_MIRROR(0x300000) AM_READWRITE8(io_r,io_w,0xffffffff) //intentional fall-through
255752   AM_RANGE(0x04000000, 0x07ffffff) AM_RAM //work ram
256753   AM_RANGE(0x0b000000, 0x0b03ffff) AM_RAM AM_BASE(vram) //vram
r14142r14143
265762//  AM_RANGE(0x2c000000, 0x2c1fffff) Color VRAM
266763ADDRESS_MAP_END
267764
765static ADDRESS_MAP_START( next_040_mem, AS_PROGRAM, 32, next_state )
766   AM_RANGE(0x02000000, 0x020001ff) AM_MIRROR(0x300000) AM_READWRITE(dma_ctrl_r, dma_040_ctrl_w)
767   AM_RANGE(0x02014100, 0x02014107) AM_MIRROR(0x300000) AM_DEVICE8("fdc", n82077aa_device, amap, 0xffffffff)
768   AM_RANGE(0x02014108, 0x0201410b) AM_MIRROR(0x300000) AM_READWRITE(fdc_control_r, fdc_control_w)
769
770   AM_IMPORT_FROM(next_mem)
771ADDRESS_MAP_END
772
268773/* Input ports */
269774static INPUT_PORTS_START( next )
270775INPUT_PORTS_END
r14142r14143
278783   palette_set_color(machine, 3,MAKE_RGB(0xff,0xff,0xff));
279784}
280785
281static MCCS1850_INTERFACE( rtc_intf )
282{
283    DEVCB_NULL, // RTCINT
284    DEVCB_NULL,
285    DEVCB_NULL
786const floppy_format_type next_state::floppy_formats[] = {
787   FLOPPY_PC_FORMAT,
788   FLOPPY_MFI_FORMAT,
789   NULL
286790};
287791
288static const floppy_interface next_floppy_interface =
289{
290    DEVCB_NULL,
291    DEVCB_NULL,
292    DEVCB_NULL,
293    DEVCB_NULL,
294    DEVCB_NULL,
295    FLOPPY_STANDARD_3_5_DSED,
296    LEGACY_FLOPPY_OPTIONS_NAME(default),
297    "floppy_3_5",
298   NULL
792static SLOT_INTERFACE_START( next_floppies )
793   SLOT_INTERFACE( "35hd", FLOPPY_35_HD )
794SLOT_INTERFACE_END
795
796const SCSIConfigTable next_state::scsi_devices = {
797   2,
798   {
799      { SCSI_ID_0, "harddisk0", SCSI_DEVICE_HARDDISK },
800      { SCSI_ID_1, "cdrom",     SCSI_DEVICE_CDROM }
801   }
299802};
300803
804const cdrom_interface next_state::cdrom_intf = { NULL, NULL };
805const harddisk_interface next_state::harddisk_intf = { NULL, NULL, "next_hdd", NULL };
806
301807static MACHINE_CONFIG_START( next, next_state )
302808    /* basic machine hardware */
303809    MCFG_CPU_ADD("maincpu",M68030, XTAL_25MHz)
r14142r14143
315821    MCFG_PALETTE_INIT(next)
316822
317823   // devices
318   MCFG_MCCS1850_ADD("rtc", XTAL_32_768kHz, rtc_intf)
319   MCFG_LEGACY_FLOPPY_DRIVE_ADD(FLOPPY_0, next_floppy_interface)
320   MCFG_AM8530H_ADD("scc", am8530h_device::int_cb_t(FUNC(next_state::scc_int), static_cast<next_state *>(owner)))
321   MCFG_NEXTKBD_ADD("keyboard", nextkbd_device::int_cb_t(FUNC(next_state::keyboard_int), static_cast<next_state *>(owner)))
322   MCFG_N82077AA_ADD("fdc", n82077aa_device::MODE_PS2)
824   MCFG_MCCS1850_ADD("rtc", XTAL_32_768kHz,
825                 mccs1850_device::cb_t(), mccs1850_device::cb_t(), mccs1850_device::cb_t())
826   MCFG_SCC8530_ADD("scc", XTAL_25MHz, scc8530_t::intrq_cb_t(FUNC(next_state::scc_irq), static_cast<next_state *>(owner)))
827   MCFG_NEXTKBD_ADD("keyboard", nextkbd_device::int_cb_t(FUNC(next_state::keyboard_irq), static_cast<next_state *>(owner)))
828   MCFG_NCR5390_ADD("scsi", 10000000,
829                line_cb_t(FUNC(next_state::scsi_irq), static_cast<next_state *>(owner)),
830                line_cb_t(FUNC(next_state::scsi_drq), static_cast<next_state *>(owner)),
831                next_state::scsi_devices)
832   MCFG_MB8795_ADD("net",
833               line_cb_t(FUNC(next_state::net_tx_irq), static_cast<next_state *>(owner)),
834               line_cb_t(FUNC(next_state::net_rx_irq), static_cast<next_state *>(owner)),
835               line_cb_t(FUNC(next_state::net_tx_drq), static_cast<next_state *>(owner)),
836               line_cb_t(FUNC(next_state::net_rx_drq), static_cast<next_state *>(owner)))
837   MCFG_NEXTMO_ADD("mo",
838               nextmo_device::cb_t(FUNC(next_state::mo_irq), static_cast<next_state *>(owner)),
839               nextmo_device::cb_t(FUNC(next_state::mo_drq), static_cast<next_state *>(owner)))
323840
841   MCFG_CDROM_ADD("cdrom", next_state::cdrom_intf)
842   MCFG_HARDDISK_CONFIG_ADD("harddisk0", next_state::harddisk_intf)
843
324844   // software list
325845   MCFG_SOFTWARE_LIST_ADD("flop_list", "next")
326846MACHINE_CONFIG_END
327847
328848static MACHINE_CONFIG_DERIVED( next040, next )
329   MCFG_CPU_REPLACE("maincpu", M68040, XTAL_33MHz)
330   MCFG_CPU_PROGRAM_MAP(next_mem)
849   MCFG_CPU_REPLACE("maincpu", M68040, XTAL_25MHz)
850   MCFG_CPU_PROGRAM_MAP(next_040_mem)
851
852   MCFG_N82077AA_ADD("fdc", n82077aa_device::MODE_PS2)
853   MCFG_FLOPPY_DRIVE_ADD("fd0", next_floppies, "35hd", 0, next_state::floppy_formats)
331854MACHINE_CONFIG_END
332855
333856/* ROM definition */
r14142r14143
341864   ROMX_LOAD( "rev_1.0_proto.bin", 0x0000, 0x10000, CRC(F44974F9) SHA1(09EAF9F5D47E379CFA0E4DC377758A97D2869DDC), ROM_BIOS(3)) /* Label: "(C) 1989 NeXT, Inc. // All Rights Reserved. // Release 1.0 // 1142.00", no underlabel */
342865
343866   ROM_REGION( 0x20, "rtc", 0 )
344   ROM_LOAD( "nvram.bin", 0x00, 0x20, BAD_DUMP CRC(7cb74196) SHA1(faa2177c2a08a6b76a6242761a9c0a8b64c4da6e) )
867   ROM_LOAD( "nvram.bin", 0x00, 0x20, CRC(52162469) SHA1(f49888af63d2d2658db4f41b3345cae153f42884) )
345868ROM_END
346869
347870ROM_START( nextnt ) // 68040 non-turbo
r14142r14143
374897   ROM_LOAD( "nvram-trb.bin", 0x00, 0x20, CRC(2516dd08) SHA1(b20afe82efee5b625fb8afda14a1d14aabc8e07e) )
375898ROM_END
376899
900static DRIVER_INIT(nexttrb)
901{
902   UINT32 *rom = (UINT32 *)(machine.region("user1")->base());
903   rom[0x329c/4] = 0x70004e71; // memory test funcall
904   rom[0x32a0/4] = 0x4e712400;
905   rom[0x03f8/4] = 0x001a4e71; // rom checksum
906   rom[0x03fc/4] = 0x4e714e71;
907}
908
909static DRIVER_INIT(next)
910{
911   UINT32 *rom = (UINT32 *)(machine.region("user1")->base());
912   rom[0x3f48/4] = 0x2f017000; // memory test funcall
913   rom[0x3f4c/4] = 0x4e712400;
914   rom[0x00b8/4] = 0x001a4e71; // rom checksum
915   rom[0x00bc/4] = 0x4e714e71;
916}
917
377918/* Driver */
378919
379920/*    YEAR  NAME    PARENT  COMPAT   MACHINE    INPUT    INIT    COMPANY                 FULLNAME               FLAGS */
380COMP( 1987, next,   0,          0,   next,      next,    0,      "Next Software Inc",   "NeXT Computer",      GAME_NOT_WORKING | GAME_NO_SOUND)
921COMP( 1987, next,   0,          0,   next,      next,    next,      "Next Software Inc",   "NeXT Computer",      GAME_NOT_WORKING | GAME_NO_SOUND)
381922COMP( 1990, nextnt, next,       0,   next040,   next,    0,      "Next Software Inc",   "NeXT (Non Turbo)",      GAME_NOT_WORKING | GAME_NO_SOUND)
382COMP( 1992, nexttrb,next,       0,   next040,   next,    0,      "Next Software Inc",   "NeXT (Turbo)",         GAME_NOT_WORKING | GAME_NO_SOUND)
923COMP( 1992, nexttrb,next,       0,   next040,   next,    nexttrb, "Next Software Inc",   "NeXT (Turbo)",         GAME_NOT_WORKING | GAME_NO_SOUND)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team