Previous 199869 Revisions Next

r40623 Sunday 6th September, 2015 at 18:51:18 UTC by Ariane Fugmann
M2COMM - initial commit
[src/mame/machine]m2comm.c* m2comm.h*

trunk/src/mame/machine/m2comm.c
r0r249135
1// license:BSD-3-Clause
2// copyright-holders:Ariane Fugmann
3
4/*
5Sega MODEL2 COMMUNICATION BOARD 837-10537
6( http://images.arianchen.de/sega-comm/daytona_comm.jpg )
7|-----------------------------------------------------------------------------|
8| |-------------------|                             |-------------------|     |
9| |-------------------|                             |-------------------|     |
10|          CN5                                               CN4           -- |
11| LED    Z80        LH5268A          16726.7        JP6 JP5 JP4 JP1        || |
12|                                                                         C|| |
13|        315-5751   315-5752                        uPD72103              N|| |
14|                                                                     JP7 8|| |
15|        LH5268A    LH5268A                                           JP8  || |
16|                                                                     JP9  -- |
17|        LH5268A    LH5268A                         315-5753A    315-5547     |
18|                                                                             |
19|                                                                         CN6 |
20| CN9                                                                         |
21|                                                                         CN7 |
22|          CN3                      CN2                      CN1              |
23| |-------------------|    |-------------------|    |-------------------|     |
24| |-------------------|    |-------------------|    |-------------------|     |
25|-----------------------------------------------------------------------------|
26
27   Setup:
28      Z80        Zilog Z0840008PSC Z80 CPU (DIP40)
29      LH5268A    SHARP LH5268AD-10LL 8k x8 SRAM (DIP28)
30      uPD72103   NEC uPD72103 HDLC/Frame Relay Controller (QFP80)
31      16726.7    M27C1001 128k x8 EPROM (DIP32, labelled 'EPR-16726')
32      315-5751   Lattice GAL16V8B-25LP PAL (DIP20)
33      315-5752   Lattice GAL16V8B-25LP PAL (DIP20)
34      315-5753A  AMI 18CV8PC-15 PAL (DIP20)
35      315-5547   AMI 18CV8PC-25 PAL (DIP20)
36
37   Board:
38      837-10537  Daytona USA
39
40   EEPROM:
41      16726.7    Daytona USA
42
43
44Sega PC BD MODEL2 A-CRX COMMUNICATION 837-11525
45( http://images.arianchen.de/sega-comm/srally_comm.jpg )
46|-------------------------------------------------------------------------------------------|
47| |-------------------|                             |-------------------|    |---------|    |
48| |-------------------|                             |-------------------|    |---------|    |
49|          CN5                                               CN4                CN10        |
50| LED    Z80        LH5268A          16726.7        JP6 JP5 JP4 JP1                         |
51|                                                                                           |
52|        315-5751   315-5752                        uPD72103                                |
53|                                                                                           |
54|        LH5268A    LH5268A                                                                 |
55|                                                                                        -- |
56|        LH5268A    LH5268A                         315-5753A    315-5547                || |
57|                                                                                       C|| |
58|                                                                                       N|| |
59| CN9                                                                                   8|| |
60|                                                                                   JP7  || |
61|          CN3                      CN2                      CN1                    JP8  -- |
62| |-------------------|    |-------------------|    |-------------------|           JP9     |
63| |-------------------|    |-------------------|    |-------------------|                   |
64|-------------------------------------------------------------------------------------------|
65
66   Setup:
67      Z80        Zilog Z0840008PSC Z80 CPU (DIP40)
68      LH5268A    SHARP LH5268AD-10LL 8k x8 SRAM (DIP28)
69      uPD72103   NEC uPD72103 HDLC/Frame Relay Controller (QFP80)
70      16726.7    M27C1001 128k x8 EPROM (DIP32, labelled 'EPR-16726')
71      315-5751   Lattice GAL16V8B-25LP PAL (DIP20)
72      315-5752   Lattice GAL16V8B-25LP PAL (DIP20)
73      315-5753A  AMI 18CV8PC-15 PAL (DIP20)
74      315-5547   AMI 18CV8PC-25 PAL (DIP20)
75
76   Board:
77      837-11525
78      837-11572  Sega Rally Championship
79
80   EEPROM:
81      16726.7    Sega Rally Championship
82      18643A.7   ManxTT
83
84
85Sega PC BD MODEL2 B-CRX COMMUNICATION 837-11615
86( http://images.arianchen.de/sega-comm/model2b-com_top.jpg )
87|-------------------------------------------------------------------------------------------|
88|                                                                                           |
89|  --                                                                                       |
90|  ||          18643A.7    MB84256A        Z80                                              |
91| C||                                                      MB84256A                         |
92| N||  JP9                       uPD72103A 315-5751                                         |
93| 8||  JP8                                                 MB84256A                         |
94|  ||  JP7                                 315-5752                                         |
95|  --                                                      MB84256A                         |
96|                                                                                           |
97|                                                          MB84256A                         |
98|                                          315-5753A                                        |
99| LED                                                                                       |
100|                                                    315-5547A                              |
101|                                                                                           |
102|                                                                              CN1          |
103|                                                                    |-------------------|  |
104|                                                  CN3               |-------------------|  |
105|-------------------------------------------------------------------------------------------|
106
107   Setup:
108      Z80          Zilog Z0840008PSC Z80 CPU (DIP40)
109      MB84256A     Fujitsu MB84256A-70LL 32k x8 SRAM (SDIP28)
110      uPD72103A    NEC uPD72103 HDLC/Frame Relay Controller (QFP80)
111      18643A.7     M27C1001 128k x8 EPROM (DIP32, labelled 'EPR-18643A')
112      315-5751     Lattice GAL16V8B-25LP PAL (DIP20)
113      315-5752     Lattice GAL16V8B-25LP PAL (DIP20)
114      315-5753A    ICT PEEL18CV8P-15 PAL (DIP20)
115      315-5547A    AMI 18CV8PC-25 PAL (DIP20)
116
117   Board:
118      837-11615    Virtua On
119      837-11615-02 Virtua On
120
121   EEPROM:
122      18643.7      Virtua On
123      18643A.7     Virtua On
124
125
126
127
128Sega PC BD MODEL2 C-CRX COMMUNICATION 837-12839
129|-------------------------------------------------------------------------------------------|
130|                                                                                           |
131|  --                                                                                       |
132|  ||          18643A.7    MB84256A        Z80                                              |
133| C||                                                      MB84256A                         |
134| N||  JP9                       uPD72103A 315-5751                                         |
135| 8||  JP8                                                 MB84256A                         |
136|  ||  JP7                                 315-5752                                         |
137|  --                                                      MB84256A                         |
138|                                                                                           |
139|                                                          MB84256A                         |
140|                                          315-5753A                                        |
141| LED                                                                                       |
142|                                                    315-5547A                              |
143|                                                                                           |
144|                                                                              CN1          |
145|                                                                    |-------------------|  |
146|                                                  CN3               |-------------------|  |
147|-------------------------------------------------------------------------------------------|
148
149   Setup:
150      Z80        Zilog Z0840008PSC Z80 CPU (DIP40)
151      MB84256A   Fujitsu MB84256A-70LL 32k x8 SRAM (SDIP28)
152      uPD72103A  NEC uPD72103 HDLC/Frame Relay Controller (QFP80)
153      18643A.7   M27C1001 128k x8 EPROM (DIP32, labelled 'EPR-18643A')
154      315-5751   Lattice GAL16V8B-25LP PAL (DIP20)
155      315-5752   Lattice GAL16V8B-25LP PAL (DIP20)
156      315-5753A  ICT PEEL18CV8P-15 PAL (DIP20)
157      315-5547A  AMI 18CV8PC-25 PAL (DIP20)
158
159   Board:
160      837-12839  Sega Touring Car Championship
161
162   EEPROM:
163      18643A.7   Sega Touring Car Championship
164*/
165
166#include "machine/m2comm.h"
167
168//#define __M2COMM_VERBOSE__
169
170MACHINE_CONFIG_FRAGMENT( m2comm )
171MACHINE_CONFIG_END
172
173//**************************************************************************
174//  GLOBAL VARIABLES
175//**************************************************************************
176
177const device_type M2COMM = &device_creator<m2comm_device>;
178
179//-------------------------------------------------
180//  machine_config_additions - device-specific
181//  machine configurations
182//-------------------------------------------------
183
184machine_config_constructor m2comm_device::device_mconfig_additions() const
185{
186   return MACHINE_CONFIG_NAME( m2comm );
187}
188
189//**************************************************************************
190//  LIVE DEVICE
191//**************************************************************************
192
193//-------------------------------------------------
194//  m2comm_device - constructor
195//-------------------------------------------------
196
197m2comm_device::m2comm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
198   device_t(mconfig, M2COMM, "MODEL2 COMMUNICATION BD", tag, owner, clock, "m2comm", __FILE__),
199   m_line_rx(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE ),
200   m_line_tx(OPEN_FLAG_READ)
201{
202   // prepare localhost "filename"
203   m_localhost[0] = 0;
204   strcat(m_localhost, "socket.");
205   strcat(m_localhost, mconfig.options().comm_localhost());
206   strcat(m_localhost, ":");
207   strcat(m_localhost, mconfig.options().comm_localport());
208
209   // prepare remotehost "filename"
210   m_remotehost[0] = 0;
211   strcat(m_remotehost, "socket.");
212   strcat(m_remotehost, mconfig.options().comm_remotehost());
213   strcat(m_remotehost, ":");
214   strcat(m_remotehost, mconfig.options().comm_remoteport());
215}
216
217//-------------------------------------------------
218//  device_start - device-specific startup
219//-------------------------------------------------
220
221void m2comm_device::device_start()
222{
223}
224
225//-------------------------------------------------
226//  device_reset - device-specific reset
227//-------------------------------------------------
228
229void m2comm_device::device_reset()
230{
231   set_linktype(16726);
232   m_zfg = 0;
233   m_cn = 0;
234   m_fg = 0;
235}
236
237READ8_MEMBER(m2comm_device::zfg_r)
238{
239   UINT8 result = m_zfg | 0xFE;
240#ifdef __M2COMM_VERBOSE__
241   printf("m2comm-zfg_r: read register %02x for value %02x\n", offset, result);
242#endif
243   return result;
244}
245
246WRITE8_MEMBER(m2comm_device::zfg_w)
247{
248#ifdef __M2COMM_VERBOSE__
249   printf("m2comm-zfg_w: %02x\n", data);
250#endif
251   m_zfg = data & 0x01;
252}
253
254READ8_MEMBER(m2comm_device::share_r)
255{
256   UINT8 result = m_shared[offset];
257#ifdef __M2COMM_VERBOSE__
258   printf("m2comm-share_r: read shared memory %02x for value %02x\n", offset, result);
259#endif
260   return result;
261}
262
263WRITE8_MEMBER(m2comm_device::share_w)
264{
265#ifdef __M2COMM_VERBOSE__
266   printf("m2comm-share_w: %02x %02x\n", offset, data);
267#endif
268   m_shared[offset] = data;
269}
270
271READ8_MEMBER(m2comm_device::cn_r)
272{
273   return m_cn;
274}
275
276WRITE8_MEMBER(m2comm_device::cn_w)
277{
278   m_cn = data & 0x01;
279
280#ifndef __M2COMM_SIMULATION__
281   if (!m_cn)
282      device_reset();
283#else
284   if (!m_cn)
285   {
286      // reset command
287      printf("M2COMM: board disabled\n");
288      m_linkenable = 0x00;
289   }
290   else
291   {
292      // init command
293      printf("M2COMM: board enabled\n");
294      m_linkenable = 0x01;
295      m_linkid = 0x00;
296      m_linkalive = 0x00;
297      m_linkcount = 0x00;
298      m_linktimer = 0x04; //0x00E8; // 58 fps * 4s
299     
300      comm_tick();
301   }
302#endif
303}
304
305READ8_MEMBER(m2comm_device::fg_r)
306{
307   return m_fg | (~m_zfg << 7);
308}
309
310WRITE8_MEMBER(m2comm_device::fg_w)
311{
312   m_fg = data & 0x01;
313}
314
315void m2comm_device::check_vint_irq()
316{
317#ifndef __M2COMM_SIMULATION__
318#else
319   comm_tick();
320#endif
321}
322
323#ifdef __M2COMM_SIMULATION__
324void m2comm_device::set_linktype(UINT16 linktype)
325{
326   m_linktype = linktype;
327   
328   switch (m_linktype)
329   {
330      case 16726:
331         // Daytona USA / Sega Rally Championship
332         printf("M2COMM: set mode 'EPR-16726 - Daytona USA'\n");
333         break;
334   }
335}
336
337void m2comm_device::comm_tick()
338{
339   switch (m_linktype)
340   {
341      case 16726:
342         // Daytona USA / Sega Rally Championship
343         comm_tick_16726();
344         break;
345   }
346}
347
348void m2comm_device::comm_tick_16726()
349{
350   if (m_linkenable == 0x01)   
351   {
352      m_zfg ^= 1;
353
354      int frameStart = 0x2000;
355      int frameOffset = 0x0000;
356      int frameSize = 0x01c0;
357      int dataSize = frameSize + 1;
358      int togo = 0;
359      int recv = 0;
360      int idx = 0;
361
362      bool isMaster = (m_fg == 0x01);
363      bool isSlave = (m_fg == 0x00);
364
365      // if link not yet established...
366      if (m_linkalive == 0x00)
367      {
368         // waiting...
369         m_shared[0] = 0x00;
370         m_shared[2] = 0xff;
371         m_shared[3] = 0xff;
372         
373         // check rx socket
374         if (!m_line_rx.is_open())
375         {
376            printf("M2COMM: listen on %s\n", m_localhost);
377            m_line_rx.open(m_localhost);
378         }
379         
380         // check tx socket
381         if (!m_line_tx.is_open())
382         {
383            printf("M2COMM: connect to %s\n", m_remotehost);
384            m_line_tx.open(m_remotehost);
385         }
386         
387         // if both sockets are there check ring
388         if ((m_line_rx.is_open()) && (m_line_tx.is_open()))
389         {
390            // try to read one messages
391            recv = m_line_rx.read(m_buffer, dataSize);
392            while (recv != 0)
393            {
394               // check if complete message
395               if (recv == dataSize)
396               {
397                  // check if message id
398                  idx = m_buffer[0];
399
400                  // 0xFF - link id
401                  if (idx == 0xff)
402                  {
403                     if (isMaster)
404                     {
405                        // master gets first id and starts next state
406                        m_linkid = 0x01;
407                        m_linkcount = m_buffer[1];
408                        m_linktimer = 0x01;
409                     }
410                     else if (isSlave)
411                     {
412                        m_buffer[1]++;
413                        m_linkid = m_buffer[1];
414
415                        // forward message
416                        m_line_tx.write(m_buffer, dataSize);
417                     }
418                  }
419                 
420                  // 0xFE - link size
421                  else if (idx == 0xfe)
422                  {
423                     if (isSlave)
424                     {
425                        m_linkcount = m_buffer[1];
426
427                        // forward message
428                        m_line_tx.write(m_buffer, dataSize);
429                     }
430                     
431                     // consider it done
432                     printf("M2COMM: link established - id %02x of %02x\n", m_linkid, m_linkcount);
433                     m_linkalive = 0x01;
434                     
435                     // write to shared mem
436                     m_shared[0] = 0x01;
437                     m_shared[2] = m_linkid;
438                     m_shared[3] = m_linkcount;
439                  }
440               }
441               else
442               {
443                  // got only part of a message - read the rest (and drop it)
444                  // TODO: combine parts and push to "ring buffer"
445                  togo = dataSize - recv;
446                  while (togo > 0){
447                     recv = m_line_rx.read(m_buffer, togo);
448                     togo -= recv;
449                  }
450                  printf("M2COMM: droped a message...\n");
451               }
452               
453               if (m_linkalive == 0x00)
454                  recv = m_line_rx.read(m_buffer, dataSize);
455               else
456                  recv = 0;
457            }
458           
459            // if we are master and link is not yet established
460            if (isMaster && (m_linkalive == 0x00))
461            {
462               // send first packet
463               if (m_linktimer == 0x00)
464               {
465                  m_buffer[0] = 0xff;
466                  m_buffer[1] = 0x01;
467                  m_line_tx.write(m_buffer, dataSize);
468               }
469
470               // send second packet
471               else if (m_linktimer == 0x01)
472               {
473                  m_buffer[0] = 0xfe;
474                  m_buffer[1] = m_linkcount;
475                  m_line_tx.write(m_buffer, dataSize);
476
477                  // consider it done
478                  printf("M2COMM: link established - id %02x of %02x\n", m_linkid, m_linkcount);
479                  m_linkalive = 0x01;
480
481                  // write to shared mem
482                  m_shared[0] = 0x01;
483                  m_shared[2] = m_linkid;
484                  m_shared[3] = m_linkcount;
485               }
486
487               else if (m_linktimer > 0x02)
488               {
489                  // decrease delay timer
490                  m_linktimer--;
491                  if (m_linktimer == 0x02)
492                     m_linktimer = 0x00;
493               }
494            }
495         }
496      }   
497
498      // update "ring buffer" if link established
499      if (m_linkalive == 0x01)
500      {
501         int togo = 0;
502         // try to read one messages
503         int recv = m_line_rx.read(m_buffer, dataSize);
504         while (recv != 0)
505         {
506            // check if complete message
507            if (recv == dataSize)
508            {
509               // check if valid id
510               int idx = m_buffer[0];
511               if (idx > 0 && idx <= m_linkcount) {
512                  int slotFrom = m_linkid - idx;
513                  int slotDest = slotFrom + m_linkcount;
514                  while (slotDest < 9) {
515                     slotDest += m_linkcount;
516                  }
517                  while (slotDest - m_linkcount > 0) {
518                     slotFrom = slotDest - m_linkcount;
519                     if (slotDest < 9) {
520                        int frameOffset1 = frameStart + slotFrom * frameSize;
521                        int frameOffset2 = frameStart + slotDest * frameSize;
522                        for (int j = 0x00 ; j < frameSize ; j++)
523                        {
524                           m_shared[frameOffset2 + j] = m_shared[frameOffset1 + j];
525                        }                       
526                     }
527                     slotDest -= m_linkcount;
528                  }
529                  if (slotDest > 0) {
530                     // save message to "ring buffer"
531                     frameOffset = frameStart + (slotDest * frameSize);
532                     for (int j = 0x00 ; j < frameSize ; j++)
533                     {
534                        m_shared[frameOffset + j] = m_buffer[1 + j];
535                     }
536                  }
537                  if (idx != m_linkid)
538                  {
539                     // forward message to other nodes
540                     m_line_tx.write(m_buffer, dataSize);
541                  }
542               } else {
543                  if (!isMaster && idx == 0xF0){
544                     // 0xF0 - master addional bytes
545                     for (int j = 0x05 ; j < 0x10 ; j++)
546                     {
547                        m_shared[j] = m_buffer[1 + j];
548                     }
549
550                     // forward message to other nodes
551                     m_line_tx.write(m_buffer, dataSize);
552                  }
553               }
554            }
555            else
556            {
557               // got only part of a message - read the rest (and drop it)
558               // TODO: combine parts and push to "ring buffer"
559               togo = dataSize - recv;
560               while (togo > 0){
561                  recv = m_line_rx.read(m_buffer, togo);
562                  togo -= recv;
563               }
564               printf("M2COMM: droped a message...\n");
565            }
566            recv = m_line_rx.read(m_buffer, dataSize);
567         }
568
569         // push message to other nodes
570         m_buffer[0] = m_linkid;
571         for (int j = 0x00 ; j < frameSize ; j++)
572         {
573            m_buffer[1 + j] = m_shared[frameStart + j];
574         }
575         m_line_tx.write(m_buffer, dataSize);
576
577         // master sends some additional status bytes
578         if (isMaster){
579            m_buffer[0] = 0xF0;
580            for (int j = 0x00 ; j < frameSize ; j++)
581            {
582               m_buffer[1 + j] = 0x00;
583            }
584            for (int j = 0x05 ; j < 0x10 ; j++)
585            {
586               m_buffer[1 + j] = m_shared[j];
587            }
588            // push message to other nodes
589            m_line_tx.write(m_buffer, dataSize);
590         }
591      }
592     
593      // clear 03
594      //TODO:m_shared[3] = 0x00;
595   }   
596}
597#endif
trunk/src/mame/machine/m2comm.h
r0r249135
1// license:BSD-3-Clause
2// copyright-holders:Ariane Fugmann
3#pragma once
4
5#ifndef __M2COMM_H__
6#define __M2COMM_H__
7
8#define __M2COMM_SIMULATION__
9
10#include "emu.h"
11
12#define MCFG_M2COMM_ADD(_tag ) \
13   MCFG_DEVICE_ADD(_tag, M2COMM, 0)
14   
15//**************************************************************************
16//  TYPE DEFINITIONS
17//**************************************************************************
18
19class m2comm_device : public device_t
20{
21public:
22   // construction/destruction
23   m2comm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
24
25   // optional information overrides
26   virtual machine_config_constructor device_mconfig_additions() const;
27
28   // single bit registers (74LS74)
29   DECLARE_READ8_MEMBER(zfg_r);
30   DECLARE_WRITE8_MEMBER(zfg_w);
31   // shared memory 2k
32   DECLARE_READ8_MEMBER(share_r);
33   DECLARE_WRITE8_MEMBER(share_w);
34
35   // public API - stuff that gets called from host
36   // shared memory 16k
37   // reads/writes at I/O 0x01a10000-0x01a13fff
38   // - share_r
39   // - share_w
40   // single bit registers (74LS74)
41   // reads/writes at I/O 0x01a14000
42   DECLARE_READ8_MEMBER(cn_r);
43   DECLARE_WRITE8_MEMBER(cn_w);
44   // reads/writes at I/O 0x01a14002
45   DECLARE_READ8_MEMBER(fg_r);
46   DECLARE_WRITE8_MEMBER(fg_w);
47
48  // IRQ logic - 5 = VINT, 7 = DLC
49   void check_vint_irq();
50#ifdef __M2COMM_SIMULATION__
51   void set_linktype(UINT16 linktype);
52#endif
53
54protected:
55   // device-level overrides
56   virtual void device_start();
57   virtual void device_reset();
58
59private:
60   UINT8 m_shared[0x4000]; // 16k shared memory
61   UINT8   m_zfg;                  // z80 flip gate? purpose unknown, bit0 is stored
62   UINT8   m_cn;                     // bit0 is used to enable/disable the comm board
63   UINT8   m_fg;                     // flip gate? purpose unknown, bit0 is stored, bit7 is connected to ZFG bit 0
64   
65   emu_file m_line_rx;    // rx line - can be either differential, simple serial or toslink
66   emu_file m_line_tx;    // tx line - is differential, simple serial and toslink
67   char m_localhost[256];
68   char m_remotehost[256];
69   UINT8 m_buffer[0x4000];
70   
71#ifdef __M2COMM_SIMULATION__
72   UINT8 m_linkenable;
73   UINT16 m_linktimer;
74   UINT8 m_linkalive;
75   UINT8 m_linkid;
76   UINT8 m_linkcount;
77
78   UINT16 m_linktype;
79   
80   void comm_tick();
81   
82   void comm_tick_16726();
83#endif
84};
85
86// device type definition
87extern const device_type M2COMM;
88
89#endif  /* __M2COMM_H__ */


Previous 199869 Revisions Next


© 1997-2024 The MAME Team