Previous 15994 Revisions Next

r3971 Tuesday 23rd December, 2008 at 20:26:36 UTC by Wilbert Pol
Converted the f3853 implementation into a device.
[src/emu]emu.mak
[src/emu/cpu/f8]f3853.c f3853.h
[src/emu/machine]f3853.c* f3853.h*
[src/mess]mess.mak
[src/mess/drivers]mk1.c

src/emu/cpu/f8/f3853.c
r3970r3971
1/*
2  fairchild f3853 smi static ram interface
3  with integrated interrupt controller and timer
4
5  databook found at www.freetradezone.com
6*/
7
8#include "driver.h"
9#include "f3853.h"
10
11/*
12  the smi does not have DC0 and DC1, only DC0
13  it is not reacting to the cpus DC0/DC1 swap instruction
14  --> might lead to 2 devices having reacting to the same DC0 address
15  and placing their bytes to the databus!
16*/
17
18/*
19   8 bit shift register
20   feedback in0 = not ( (out3 xor out4) xor (out5 xor out7) )
21   interrupt at 0xfe
22   0xff stops register (0xfe never reached!)
23*/
24static UINT8 f3853_value_to_cycle[0x100];
25
26static struct {
27    f3853_config config;
28
29    UINT8 high,low; // bit 7 set to 0 for timer interrupt, to 1 for external interrupt
30    int external_enable;
31    int timer_enable;
32
33    int request_flipflop;
34
35    int priority_line; /* inverted level*/
36    int external_interrupt_line;/* inverted level */
37
38    emu_timer *timer;
39} f3853= { { 0 } };
40#define INTERRUPT_VECTOR(external) (external?f3853.low|(f3853.high<<8)|0x80 \
41               :(f3853.low|(f3853.high<<8))&~0x80)
42
43static void f3853_set_interrupt_request_line(running_machine *machine)
44{
45    if (!f3853.config.interrupt_request)
46      return;
47
48   if (f3853.external_enable&&!f3853.priority_line)
49      f3853.config.interrupt_request(machine, INTERRUPT_VECTOR(TRUE), TRUE);
50   else if (f3853.timer_enable&&!f3853.priority_line&&f3853.request_flipflop)
51      f3853.config.interrupt_request(machine, INTERRUPT_VECTOR(FALSE), TRUE);
52   else
53      f3853.config.interrupt_request(machine, 0, FALSE);
54}
55
56static TIMER_CALLBACK( f3853_timer_callback );
57
58static void f3853_timer_start(UINT8 value)
59{
60   attotime period = (value != 0xff) ? attotime_mul(ATTOTIME_IN_HZ(f3853.config.frequency), f3853_value_to_cycle[value]*31) : attotime_never;
61
62   timer_adjust_oneshot(f3853.timer, period, 0);
63}
64
65static TIMER_CALLBACK( f3853_timer_callback )
66{
67    if (f3853.timer_enable)
68   {
69      f3853.request_flipflop = TRUE;
70      f3853_set_interrupt_request_line(machine);
71    }
72    f3853_timer_start(0xfe);
73}
74
75
76void f3853_init(running_machine *machine, const f3853_config *config)
77{
78   UINT8 reg=0xfe;
79   int i;
80
81   for (i=254/*known to get 0xfe after 255 cycles*/; i>=0; i--)
82   {
83      int o7=reg&0x80?TRUE:FALSE, o5=reg&0x20?TRUE:FALSE,
84         o4=reg&0x10?TRUE:FALSE, o3=reg&8?TRUE:FALSE;
85      f3853_value_to_cycle[reg]=i;
86      reg<<=1;
87      if (!((o7!=o5)!=(o4!=o3))) reg|=1;
88   }
89
90   f3853.config=*config;
91
92   f3853.priority_line=FALSE;
93   f3853.external_interrupt_line=TRUE;
94   f3853.timer = timer_alloc(machine, f3853_timer_callback, NULL);
95}
96
97CPU_RESET( f3853 )
98{
99    // registers indeterminate
100}
101
102void f3853_set_external_interrupt_in_line(running_machine *machine, int level)
103{
104    if (f3853.external_interrupt_line&&!level&& f3853.external_enable)
105   f3853.request_flipflop = TRUE;
106    f3853.external_interrupt_line = level;
107    f3853_set_interrupt_request_line(machine);
108}
109
110void f3853_set_priority_in_line(running_machine *machine, int level)
111{
112    f3853.priority_line=level;
113    f3853_set_interrupt_request_line(machine);
114}
115
116 READ8_HANDLER(f3853_r)
117{
118    UINT8 data=0;
119    switch (offset) {
120    case 0:
121      data=f3853.high;
122      break;
123    case 1:
124      data=f3853.low;
125      break;
126    case 2: // interrupt control; not readable
127    case 3: // timer; not readable
128      break;
129    }
130    return data;
131}
132
133WRITE8_HANDLER(f3853_w)
134{
135   switch (offset) {
136   case 0:
137      f3853.high=data;
138      break;
139   case 1:
140      f3853.low=data;
141      break;
142   case 2: //interrupt control
143      f3853.external_enable = ((data&3)==1);
144      f3853.timer_enable = ((data&3)==3);
145      f3853_set_interrupt_request_line(space->machine);
146      break;
147   case 3: //timer
148      f3853.request_flipflop=FALSE;
149      f3853_set_interrupt_request_line(space->machine);
150      f3853_timer_start(data);
151      break;
152   }
153}
src/emu/cpu/f8/f3853.h
r3970r3971
1/*
2  fairchild f3853 static ram interface smi
3  with integrated interrupt controller and timer
4
5  timer shift register basically the same as in f3851!
6*/
7
8#pragma once
9
10#ifndef __F3853_H__
11#define __F3853_H__
12
13
14#include "cpuintrf.h"
15
16typedef struct _f3853_config f3853_config;
17struct _f3853_config
18{
19    int frequency;
20    void (*interrupt_request)(running_machine *machine, UINT16 addr, int level);
21};
22
23void f3853_init(running_machine *machine, const f3853_config *config);
24CPU_RESET( f3853 );
25
26// ports 0x0c - 0x0f
27 READ8_HANDLER(f3853_r);
28WRITE8_HANDLER(f3853_w);
29
30void f3853_set_external_interrupt_in_line(running_machine *machine, int level);
31void f3853_set_priority_in_line(running_machine *machine, int level);
32
33#endif /* __F3853_H__ */
src/emu/emu.mak
r3970r3971
133133   $(EMUMACHINE)/ds2401.o \
134134   $(EMUMACHINE)/ds2404.o \
135135   $(EMUMACHINE)/eeprom.o \
136   $(EMUMACHINE)/f3853.o \
136137   $(EMUMACHINE)/generic.o \
137138   $(EMUMACHINE)/i2cmem.o \
138139    $(EMUMACHINE)/idectrl.o \
src/emu/machine/f3853.c
r0r3971
1/*
2  fairchild f3853 smi static ram interface
3  with integrated interrupt controller and timer
4
5  databook found at www.freetradezone.com
6*/
7
8#include "driver.h"
9#include "f3853.h"
10
11/*
12  the smi does not have DC0 and DC1, only DC0
13  it is not reacting to the cpus DC0/DC1 swap instruction
14  --> might lead to 2 devices having reacting to the same DC0 address
15  and placing their bytes to the databus!
16*/
17
18
19typedef struct _f3853 f3853_t;
20struct _f3853 {
21    const f3853_config *config;
22
23    UINT8 high,low; // bit 7 set to 0 for timer interrupt, to 1 for external interrupt
24    int external_enable;
25    int timer_enable;
26
27    int request_flipflop;
28
29    int priority_line; /* inverted level*/
30    int external_interrupt_line;/* inverted level */
31
32    emu_timer *timer;
33};
34
35/*
36   8 bit shift register
37   feedback in0 = not ( (out3 xor out4) xor (out5 xor out7) )
38   interrupt at 0xfe
39   0xff stops register (0xfe never reached!)
40*/
41static UINT8 f3853_value_to_cycle[0x100];
42
43
44static TIMER_CALLBACK( f3853_timer_callback );
45#define INTERRUPT_VECTOR(external) ( external ? f3853->low | ( f3853->high << 8 ) | 0x80 \
46               : ( f3853->low | ( f3853->high << 8 ) ) & ~0x80 )
47
48
49INLINE f3853_t *get_safe_token(const device_config *device)
50{
51   assert( device != NULL );
52   assert( device->token != NULL );
53   assert( device->type == DEVICE_GET_INFO_NAME(f3853) );
54   return ( f3853_t * ) device->token;
55}
56
57
58static void f3853_set_interrupt_request_line(const device_config *device)
59{
60   f3853_t   *f3853 = get_safe_token( device );
61
62    if ( ! f3853->config->interrupt_request )
63      return;
64
65   if ( f3853->external_enable && ! f3853->priority_line )
66      f3853->config->interrupt_request(device, INTERRUPT_VECTOR(TRUE), TRUE);
67   else if ( f3853->timer_enable && ! f3853->priority_line && f3853->request_flipflop)
68      f3853->config->interrupt_request(device, INTERRUPT_VECTOR(FALSE), TRUE);
69   else
70      f3853->config->interrupt_request(device, 0, FALSE);
71}
72
73
74static void f3853_timer_start(const device_config *device, UINT8 value)
75{
76   f3853_t   *f3853 = get_safe_token( device );
77
78   attotime period = (value != 0xff) ? attotime_mul(ATTOTIME_IN_HZ(device->clock), f3853_value_to_cycle[value]*31) : attotime_never;
79
80   timer_adjust_oneshot(f3853->timer, period, 0);
81}
82
83
84static TIMER_CALLBACK( f3853_timer_callback )
85{
86   const device_config *device = ptr;
87   f3853_t   *f3853 = get_safe_token( device );
88
89    if (f3853->timer_enable)
90   {
91      f3853->request_flipflop = TRUE;
92      f3853_set_interrupt_request_line( device );
93    }
94    f3853_timer_start( device, 0xfe);
95}
96
97
98void f3853_set_external_interrupt_in_line(const device_config *device, int level)
99{
100   f3853_t   *f3853 = get_safe_token( device );
101
102    if ( f3853->external_interrupt_line && ! level && f3853->external_enable)
103   f3853->request_flipflop = TRUE;
104    f3853->external_interrupt_line = level;
105    f3853_set_interrupt_request_line( device );
106}
107
108
109void f3853_set_priority_in_line(const device_config *device, int level)
110{
111   f3853_t   *f3853 = get_safe_token( device );
112
113    f3853->priority_line = level;
114    f3853_set_interrupt_request_line( device );
115}
116
117
118READ8_DEVICE_HANDLER(f3853_r)
119{
120   f3853_t   *f3853 = get_safe_token( device );
121    UINT8 data=0;
122
123    switch (offset)
124   {
125    case 0:
126      data = f3853->high;
127      break;
128    case 1:
129      data = f3853->low;
130      break;
131    case 2: // interrupt control; not readable
132    case 3: // timer; not readable
133      break;
134    }
135    return data;
136}
137
138
139WRITE8_DEVICE_HANDLER(f3853_w)
140{
141   f3853_t   *f3853 = get_safe_token( device );
142   switch (offset)
143   {
144   case 0:
145      f3853->high = data;
146      break;
147   case 1:
148      f3853->low = data;
149      break;
150   case 2: //interrupt control
151      f3853->external_enable = ((data&3)==1);
152      f3853->timer_enable = ((data&3)==3);
153      f3853_set_interrupt_request_line( device );
154      break;
155   case 3: //timer
156      f3853->request_flipflop = FALSE;
157      f3853_set_interrupt_request_line( device );
158      f3853_timer_start( device, data );
159      break;
160   }
161}
162
163
164static DEVICE_START( f3853 )
165{
166   f3853_t *f3853 = get_safe_token( device );
167   UINT8 reg=0xfe;
168   int i;
169
170   f3853->config = device->static_config;
171
172   for (i=254/*known to get 0xfe after 255 cycles*/; i>=0; i--)
173   {
174      int o7 = ( reg & 0x80 ) ? TRUE : FALSE;
175      int o5 = ( reg & 0x20 ) ? TRUE : FALSE;
176      int o4 = ( reg & 0x10 ) ? TRUE : FALSE;
177      int o3 = ( reg & 8 ) ? TRUE : FALSE;
178      f3853_value_to_cycle[reg]=i;
179      reg<<=1;
180      if (!((o7!=o5)!=(o4!=o3))) reg|=1;
181   }
182
183   f3853->timer = timer_alloc( device->machine, f3853_timer_callback, (void *)device );
184
185   state_save_register_device_item( device, 0, f3853->high );
186   state_save_register_device_item( device, 0, f3853->low );
187   state_save_register_device_item( device, 0, f3853->external_enable );
188   state_save_register_device_item( device, 0, f3853->timer_enable );
189   state_save_register_device_item( device, 0, f3853->request_flipflop );
190   state_save_register_device_item( device, 0, f3853->priority_line );
191   state_save_register_device_item( device, 0, f3853->external_interrupt_line );
192
193   return DEVICE_START_OK;
194}
195
196
197static DEVICE_RESET( f3853 )
198{
199   f3853_t   *f3853 = get_safe_token( device );
200
201   f3853->high = 0;
202   f3853->low = 0;
203   f3853->external_enable = 0;
204   f3853->timer_enable = 0;
205   f3853->request_flipflop = 0;
206   f3853->priority_line = FALSE;
207   f3853->external_interrupt_line = TRUE;
208
209   timer_enable( f3853->timer, 0 );
210}
211
212
213DEVICE_SET_INFO( f3853 )
214{
215   switch ( state )
216   {
217   }
218}
219
220
221DEVICE_GET_INFO( f3853 )
222{
223   switch ( state )
224   {
225      /* --- the following bits of info are returned as 64-bit signed integers --- */
226      case DEVINFO_INT_TOKEN_BYTES:            info->i = sizeof(f3853_t);                  break;
227      case DEVINFO_INT_INLINE_CONFIG_BYTES:      info->i = 0;                           break;
228      case DEVINFO_INT_CLASS:                  info->i = DEVICE_CLASS_PERIPHERAL;            break;
229
230      /* --- the following bits of info are returned as pointers to data or functions --- */
231      case DEVINFO_FCT_SET_INFO:               info->set_info = DEVICE_SET_INFO_NAME(f3853);   break;
232      case DEVINFO_FCT_START:                  info->start = DEVICE_START_NAME(f3853);         break;
233      case DEVINFO_FCT_STOP:                  /* nothing */                           break;
234      case DEVINFO_FCT_RESET:                  info->reset = DEVICE_RESET_NAME(f3853);         break;
235
236      /* --- the following bits of info are returned as NULL-terminated strings --- */
237      case DEVINFO_STR_NAME:                  strcpy(info->s, "F3853");                  break;
238      case DEVINFO_STR_FAMILY:               strcpy(info->s, "F8");                     break;
239      case DEVINFO_STR_VERSION:               strcpy(info->s, "1.0");                     break;
240      case DEVINFO_STR_SOURCE_FILE:            strcpy(info->s, __FILE__);                  break;
241      case DEVINFO_STR_CREDITS:               strcpy(info->s, "Copyright the MAME and MESS Teams"); break;
242   }
243}
244
src/emu/machine/f3853.h
r0r3971
1/*
2  fairchild f3853 static ram interface smi
3  with integrated interrupt controller and timer
4
5  timer shift register basically the same as in f3851!
6*/
7
8#pragma once
9
10#ifndef __F3853_H__
11#define __F3853_H__
12
13#define F3853      DEVICE_GET_INFO_NAME(f3853)
14
15/***************************************************************************
16    TYPE DEFINITIONS
17***************************************************************************/
18
19typedef struct _f3853_config f3853_config;
20struct _f3853_config
21{
22    void (*interrupt_request)(const device_config *device, UINT16 addr, int level);
23};
24
25
26/***************************************************************************
27    DEVICE CONFIGURATION MACROS
28***************************************************************************/
29
30#define MDRV_F3853_ADD(_tag, _clock, _intrf) \
31   MDRV_DEVICE_ADD(_tag, F3853, _clock) \
32   MDRV_DEVICE_CONFIG(_intrf)
33
34
35/* device interface */
36DEVICE_GET_INFO(f3853);
37
38READ8_DEVICE_HANDLER(f3853_r);
39WRITE8_DEVICE_HANDLER(f3853_w);
40
41void f3853_set_external_interrupt_in_line(const device_config *device, int level);
42void f3853_set_priority_in_line(const device_config *device, int level);
43
44#endif /* __F3853_H__ */
src/mess/mess.mak
r3970r3971
11011101   $(MESS_MACHINE)/lynx.o
11021102
11031103$(MESSOBJ)/mk1.a:      \
1104   $(OBJ)/emu/cpu/f8/f3853.o   \
11051104   $(MESS_DRIVERS)/mk1.o
11061105
11071106$(MESSOBJ)/mk2.a:      \
src/mess/drivers/mk1.c
r3970r3971
4242#include "driver.h"
4343
4444#include "cpu/f8/f8.h"
45#include "cpu/f8/f3853.h"
45#include "machine/f3853.h"
4646#include "mk1.lh"
4747
4848#define MAIN_CLOCK   1000000
r3970r3971
104104
105105static ADDRESS_MAP_START( mk1_io, ADDRESS_SPACE_IO, 8 )
106106   AM_RANGE( 0x0, 0x1 ) AM_READWRITE( mk1_f8_r, mk1_f8_w )
107   AM_RANGE( 0xc, 0xf ) AM_READWRITE( f3853_r, f3853_w )
107   AM_RANGE( 0xc, 0xf ) AM_DEVREADWRITE( F3853, "f3853", f3853_r, f3853_w )
108108ADDRESS_MAP_END
109109
110
110111static INPUT_PORTS_START( mk1 )
111112   PORT_START("RESET")   /* 0 */
112113   PORT_DIPNAME ( 0x01, 0x01, "Switch")
r3970r3971
142143   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Black 8    ep") PORT_CODE(KEYCODE_8)
143144INPUT_PORTS_END
144145
145static MACHINE_RESET( mk1 ) {
146}
147146
148static TIMER_CALLBACK( mk1_update_leds ) {
147static TIMER_CALLBACK( mk1_update_leds )
148{
149149   int i;
150150
151151   for ( i = 0; i < 4; i++ ) {
r3970r3971
161161   timer_pulse(machine,  ATTOTIME_IN_HZ(30), NULL, 0, mk1_update_leds );
162162}
163163
164
165static void mk1_interrupt( const device_config *device, UINT16 addr, int level )
166{
167   cpu_set_input_line_vector(device->machine->cpu[0], 0, addr );
168   cpu_set_input_line(device->machine->cpu[0], 0, level ? F8_INT_INTR : F8_INT_NONE );
169}
170
171
172static const f3853_config mk1_config =
173{
174   mk1_interrupt
175};
176
177
164178static MACHINE_DRIVER_START( mk1 )
165179   /* basic machine hardware */
166180   MDRV_CPU_ADD( "main", F8, MAIN_CLOCK )        /* MK3850 */
r3970r3971
169183   MDRV_QUANTUM_TIME(HZ(60))
170184
171185   MDRV_MACHINE_START( mk1 )
172   MDRV_MACHINE_RESET( mk1 )
173186
187   MDRV_F3853_ADD( "f3853", MAIN_CLOCK, mk1_config )
188
174189    /* video hardware */
175190   MDRV_DEFAULT_LAYOUT( layout_mk1 )
176191MACHINE_DRIVER_END
177192
193
178194ROM_START( mk1 )
179195   ROM_REGION(0x10000,"main",0)
180196   ROM_LOAD("82c210-1", 0x0000, 0x800, CRC(278f7bf3) SHA1(b384c95ba691d52dfdddd35987a71e9746a46170))
181197ROM_END
182198
183static void mk1_interrupt( running_machine *machine, UINT16 addr, int level )
184{
185    cpu_set_input_line_vector(machine->cpu[0], 0, addr );
186    cpu_set_input_line(machine->cpu[0], 0, level ? F8_INT_INTR : F8_INT_NONE );
187}
188199
189static const f3853_config mk1_config = {
190   MAIN_CLOCK,
191   mk1_interrupt
192};
193
194static DRIVER_INIT( mk1 ) {
195    f3853_init( machine, &mk1_config );
196}
197
198200/***************************************************************************
199201
200202  Game driver(s)
r3970r3971
203205
204206// seams to be developed by mostek (MK)
205207/*     YEAR   NAME  PARENT  COMPAT  MACHINE INPUT   INIT    CONFIG  COMPANY                 FULLNAME */
206CONS( 1979,  mk1,  0,       0,      mk1,   mk1,   mk1,   NULL,   "Computer Electronic",  "Chess Champion MK I", 0 )
208CONS( 1979,  mk1,  0,       0,      mk1,   mk1,   0,   NULL,   "Computer Electronic",  "Chess Champion MK I", 0 )
207209

Previous 15994 Revisions Next


© 1998-2018 The MESS Team