src/emu/cpu/f8/f3853.c
| r3970 | r3971 | |
| 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 | | */ |
| 24 | | static UINT8 f3853_value_to_cycle[0x100]; |
| 25 | | |
| 26 | | static 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 | | |
| 43 | | static 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 | | |
| 56 | | static TIMER_CALLBACK( f3853_timer_callback ); |
| 57 | | |
| 58 | | static 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 | | |
| 65 | | static 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 | | |
| 76 | | void 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 | | |
| 97 | | CPU_RESET( f3853 ) |
| 98 | | { |
| 99 | | // registers indeterminate |
| 100 | | } |
| 101 | | |
| 102 | | void 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 | | |
| 110 | | void 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 | | |
| 133 | | WRITE8_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/machine/f3853.c
| r0 | r3971 | |
| 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 | typedef struct _f3853 f3853_t; |
| 20 | struct _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 | */ |
| 41 | static UINT8 f3853_value_to_cycle[0x100]; |
| 42 | |
| 43 | |
| 44 | static 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 | |
| 49 | INLINE 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 | |
| 58 | static 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 | |
| 74 | static 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 | |
| 84 | static 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 | |
| 98 | void 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 | |
| 109 | void 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 | |
| 118 | READ8_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 | |
| 139 | WRITE8_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 | |
| 164 | static 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 | |
| 197 | static 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 | |
| 213 | DEVICE_SET_INFO( f3853 ) |
| 214 | { |
| 215 | switch ( state ) |
| 216 | { |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | |
| 221 | DEVICE_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/mess/drivers/mk1.c
| r3970 | r3971 | |
| 42 | 42 | #include "driver.h" |
| 43 | 43 | |
| 44 | 44 | #include "cpu/f8/f8.h" |
| 45 | | #include "cpu/f8/f3853.h" |
| 45 | #include "machine/f3853.h" |
| 46 | 46 | #include "mk1.lh" |
| 47 | 47 | |
| 48 | 48 | #define MAIN_CLOCK 1000000 |
| r3970 | r3971 | |
| 104 | 104 | |
| 105 | 105 | static ADDRESS_MAP_START( mk1_io, ADDRESS_SPACE_IO, 8 ) |
| 106 | 106 | 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 ) |
| 108 | 108 | ADDRESS_MAP_END |
| 109 | 109 | |
| 110 | |
| 110 | 111 | static INPUT_PORTS_START( mk1 ) |
| 111 | 112 | PORT_START("RESET") /* 0 */ |
| 112 | 113 | PORT_DIPNAME ( 0x01, 0x01, "Switch") |
| r3970 | r3971 | |
| 142 | 143 | PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Black 8 ep") PORT_CODE(KEYCODE_8) |
| 143 | 144 | INPUT_PORTS_END |
| 144 | 145 | |
| 145 | | static MACHINE_RESET( mk1 ) { |
| 146 | | } |
| 147 | 146 | |
| 148 | | static TIMER_CALLBACK( mk1_update_leds ) { |
| 147 | static TIMER_CALLBACK( mk1_update_leds ) |
| 148 | { |
| 149 | 149 | int i; |
| 150 | 150 | |
| 151 | 151 | for ( i = 0; i < 4; i++ ) { |
| r3970 | r3971 | |
| 161 | 161 | timer_pulse(machine, ATTOTIME_IN_HZ(30), NULL, 0, mk1_update_leds ); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | |
| 165 | static 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 | |
| 172 | static const f3853_config mk1_config = |
| 173 | { |
| 174 | mk1_interrupt |
| 175 | }; |
| 176 | |
| 177 | |
| 164 | 178 | static MACHINE_DRIVER_START( mk1 ) |
| 165 | 179 | /* basic machine hardware */ |
| 166 | 180 | MDRV_CPU_ADD( "main", F8, MAIN_CLOCK ) /* MK3850 */ |
| r3970 | r3971 | |
| 169 | 183 | MDRV_QUANTUM_TIME(HZ(60)) |
| 170 | 184 | |
| 171 | 185 | MDRV_MACHINE_START( mk1 ) |
| 172 | | MDRV_MACHINE_RESET( mk1 ) |
| 173 | 186 | |
| 187 | MDRV_F3853_ADD( "f3853", MAIN_CLOCK, mk1_config ) |
| 188 | |
| 174 | 189 | /* video hardware */ |
| 175 | 190 | MDRV_DEFAULT_LAYOUT( layout_mk1 ) |
| 176 | 191 | MACHINE_DRIVER_END |
| 177 | 192 | |
| 193 | |
| 178 | 194 | ROM_START( mk1 ) |
| 179 | 195 | ROM_REGION(0x10000,"main",0) |
| 180 | 196 | ROM_LOAD("82c210-1", 0x0000, 0x800, CRC(278f7bf3) SHA1(b384c95ba691d52dfdddd35987a71e9746a46170)) |
| 181 | 197 | ROM_END |
| 182 | 198 | |
| 183 | | static 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 | | } |
| 188 | 199 | |
| 189 | | static const f3853_config mk1_config = { |
| 190 | | MAIN_CLOCK, |
| 191 | | mk1_interrupt |
| 192 | | }; |
| 193 | | |
| 194 | | static DRIVER_INIT( mk1 ) { |
| 195 | | f3853_init( machine, &mk1_config ); |
| 196 | | } |
| 197 | | |
| 198 | 200 | /*************************************************************************** |
| 199 | 201 | |
| 200 | 202 | Game driver(s) |
| r3970 | r3971 | |
| 203 | 205 | |
| 204 | 206 | // seams to be developed by mostek (MK) |
| 205 | 207 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |
| 206 | | CONS( 1979, mk1, 0, 0, mk1, mk1, mk1, NULL, "Computer Electronic", "Chess Champion MK I", 0 ) |
| 208 | CONS( 1979, mk1, 0, 0, mk1, mk1, 0, NULL, "Computer Electronic", "Chess Champion MK I", 0 ) |
| 207 | 209 | |