Previous 15994 Revisions Next

r3811 Thursday 11th December, 2008 at 13:44:35 UTC by Miodrag Milanović
Made device of ttl74145, and did fix on acrnsys1
[src/mess/drivers]acrnsys1.c sym1.c
[src/mess/includes]sym1.h
[src/mess/machine]74145.c 74145.h sym1.c

src/mess/includes/sym1.h
r3810r3811
1313#define SYM1_H_
1414
1515#include "machine/6532riot.h"
16#include "machine/74145.h"
1617
1718/* SYM-1 main (and only) oscillator Y1 */
1819#define SYM1_CLOCK  XTAL_1MHz
r3810r3811
2728/*----------- defined in machine/sym1.c -----------*/
2829
2930extern const riot6532_interface sym1_r6532_interface;
30
31extern const ttl74145_interface sym1_ttl74145_intf;
3132DRIVER_INIT( sym1 );
3233MACHINE_RESET( sym1 );
3334
src/mess/machine/74145.c
r3810r3811
4646#include "74145.h"
4747
4848
49
5049/*****************************************************************************
51 Macros
52*****************************************************************************/
53
54
55#define MAX_74145   (1)
56
57
58
59/*****************************************************************************
6050 Type definitions
6151*****************************************************************************/
6252
6353
64typedef struct _ttl74145_state ttl74145_state;
65struct _ttl74145_state
54typedef struct _ttl74145_t ttl74145_t;
55struct _ttl74145_t
6656{
6757   /* Pointer to our interface */
6858   const ttl74145_interface *intf;
r3810r3811
7161   UINT16 number;
7262};
7363
74
75
7664/*****************************************************************************
77 Global variables
65 Implementation
7866*****************************************************************************/
7967
68INLINE ttl74145_t *get_safe_token(const device_config *device)
69{
70   assert(device != NULL);
71   assert(device->token != NULL);
8072
81static ttl74145_state ttl74145[MAX_74145];
73   return (ttl74145_t *)device->token;
74}
8275
76WRITE8_DEVICE_HANDLER( ttl74145_w ) {
77   /* Decode number */
78   ttl74145_t *ttl74145 = get_safe_token(device);
79   UINT16 new_number = bcd_2_dec(data & 0x0f);
80   
81   /* Call output callbacks if the number changed */
82   if (new_number != ttl74145->number)
83   {
84      const ttl74145_interface *i = ttl74145->intf;
85   
86      if (i->output_line_0) i->output_line_0(device, new_number == 0);
87      if (i->output_line_1) i->output_line_1(device, new_number == 1);
88      if (i->output_line_2) i->output_line_2(device, new_number == 2);
89      if (i->output_line_3) i->output_line_3(device, new_number == 3);
90      if (i->output_line_4) i->output_line_4(device, new_number == 4);
91      if (i->output_line_5) i->output_line_5(device, new_number == 5);
92      if (i->output_line_6) i->output_line_6(device, new_number == 6);
93      if (i->output_line_7) i->output_line_7(device, new_number == 7);
94      if (i->output_line_8) i->output_line_8(device, new_number == 8);
95      if (i->output_line_9) i->output_line_9(device, new_number == 9);
96   }
97   
98   /* Update state */
99   ttl74145->number = new_number;     
100}
83101
102READ16_DEVICE_HANDLER( ttl74145_r ) {
103   ttl74145_t *ttl74145 = get_safe_token(device);
104   
105   return ttl74145->number;
106}
84107
85/*****************************************************************************
86 Implementation
87*****************************************************************************/
108/* Device Interface */
88109
89
90/* Config */
91void ttl74145_config(running_machine *machine, int which, const ttl74145_interface *intf)
110static DEVICE_START( ttl74145 )
92111{
93   assert_always(mame_get_phase(machine) == MAME_PHASE_INIT,
94      "Can only call ttl74145_config at init time!");
95   assert_always(which < MAX_74145,
96      "'which' exceeds maximum number of configured 74145s!");
112   ttl74145_t *ttl74145 = get_safe_token(device);
113   // validate arguments
97114
98   /* Assign interface */
99   ttl74145[which].intf = intf;
115   assert(device != NULL);
116   assert(device->tag != NULL);
117   assert(strlen(device->tag) < 20);
118   assert(device->static_config != NULL);
100119
101   /* Initialize */
102   ttl74145_reset(which);
120   ttl74145->intf = device->static_config;
121   ttl74145->number = 0;
122   
123   // register for state saving
124   state_save_register_item(device->machine, "ttl74145", device->tag, 0, ttl74145->number);
125   return DEVICE_START_OK;
103126}
104127
128static DEVICE_RESET( ttl74145 )
129{
130   ttl74145_t *ttl74145 = get_safe_token(device);
131   ttl74145->number = 0;
132}
105133
106/* Reset */
107void ttl74145_reset(int which)
134static DEVICE_SET_INFO( ttl74145 )
108135{
109   ttl74145[which].number = 0;
136   switch (state)
137   {
138      /* no parameters to set */
139   }
110140}
111141
112
113/* Data Write */
114static void ttl74145_write(int which, offs_t offset, UINT8 data)
142DEVICE_GET_INFO( ttl74145 )
115143{
116   /* Decode number */
117   UINT16 new_number = bcd_2_dec(data & 0x0f);
118
119   /* Call output callbacks if the number changed */
120   if (new_number != ttl74145[which].number)
144   switch (state)
121145   {
122      const ttl74145_interface *i = ttl74145[which].intf;
146      /* --- the following bits of info are returned as 64-bit signed integers --- */
147      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(ttl74145_t);               break;
148      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
149      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
123150
124      if (i->output_line_0) i->output_line_0(new_number == 0);
125      if (i->output_line_1) i->output_line_1(new_number == 1);
126      if (i->output_line_2) i->output_line_2(new_number == 2);
127      if (i->output_line_3) i->output_line_3(new_number == 3);
128      if (i->output_line_4) i->output_line_4(new_number == 4);
129      if (i->output_line_5) i->output_line_5(new_number == 5);
130      if (i->output_line_6) i->output_line_6(new_number == 6);
131      if (i->output_line_7) i->output_line_7(new_number == 7);
132      if (i->output_line_8) i->output_line_8(new_number == 8);
133      if (i->output_line_9) i->output_line_9(new_number == 9);
151      /* --- the following bits of info are returned as pointers to data or functions --- */
152      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(ttl74145); break;
153      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(ttl74145);      break;
154      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
155      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(ttl74145);      break;
156
157      /* --- the following bits of info are returned as NULL-terminated strings --- */
158      case DEVINFO_STR_NAME:                     info->s = "TTL74145";                  break;
159      case DEVINFO_STR_FAMILY:                  info->s = "TTL74145";                  break;
160      case DEVINFO_STR_VERSION:                  info->s = "1.0";                     break;
161      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                     break;
162      case DEVINFO_STR_CREDITS:                  info->s = "Copyright MESS Team";         break;
134163   }
135
136   /* Update state */
137   ttl74145[which].number = new_number;
138164}
139
140
141WRITE8_HANDLER( ttl74145_0_w ) { ttl74145_write(0, offset, data); }
142READ16_HANDLER( ttl74145_0_r ) { return ttl74145[0].number; }
src/mess/machine/74145.h
r3810r3811
77#ifndef TTL74145_H_
88#define TTL74145_H_
99
10/***************************************************************************
11    MACROS
12***************************************************************************/
13
14#define TTL74145      DEVICE_GET_INFO_NAME(ttl74145)
15
16/***************************************************************************
17    TYPE DEFINITIONS
18***************************************************************************/
19
20typedef void (*ttl74145_output_line_func)(const device_config *device, int state);
21#define TTL74145_OUTPUT_LINE(name)   void name(const device_config *device, int state )
22
23
1024/* Interface */
1125typedef struct _ttl74145_interface ttl74145_interface;
1226struct _ttl74145_interface
1327{
1428   /* Outputs */
15   void (*output_line_0)(int state);
16   void (*output_line_1)(int state);
17   void (*output_line_2)(int state);
18   void (*output_line_3)(int state);
19   void (*output_line_4)(int state);
20   void (*output_line_5)(int state);
21   void (*output_line_6)(int state);
22   void (*output_line_7)(int state);
23   void (*output_line_8)(int state);
24   void (*output_line_9)(int state);
29   ttl74145_output_line_func output_line_0;
30   ttl74145_output_line_func output_line_1;
31   ttl74145_output_line_func output_line_2;
32   ttl74145_output_line_func output_line_3;
33   ttl74145_output_line_func output_line_4;
34   ttl74145_output_line_func output_line_5;
35   ttl74145_output_line_func output_line_6;
36   ttl74145_output_line_func output_line_7;
37   ttl74145_output_line_func output_line_8;
38   ttl74145_output_line_func output_line_9;
2539};
2640
27/* Configuration */
28void ttl74145_config(running_machine *machine, int which, const ttl74145_interface *intf);
29void ttl74145_reset(int which);
3041
42/***************************************************************************
43    FUNCTION PROTOTYPES
44***************************************************************************/
45
46/* device interface */
47DEVICE_GET_INFO( ttl74145 );
48
3149/* Standard handlers */
32WRITE8_HANDLER( ttl74145_0_w );
33READ16_HANDLER( ttl74145_0_r );
50WRITE8_DEVICE_HANDLER( ttl74145_w );
51READ16_DEVICE_HANDLER( ttl74145_r );
3452
53/***************************************************************************
54    DEVICE CONFIGURATION MACROS
55***************************************************************************/
56
57#define MDRV_TTL74145_ADD(_tag, _intrf) \
58   MDRV_DEVICE_ADD(_tag, TTL74145) \
59   MDRV_DEVICE_CONFIG(_intrf)
60
61
3562#endif /*TTL74145_H_*/
src/mess/machine/sym1.c
r3810r3811
3333******************************************************************************/
3434
3535
36static void sym1_74145_output_0_w(int state)
36TTL74145_OUTPUT_LINE(sym1_74145_output_0_w)
3737{
3838   if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 0);
3939}
4040
4141
42static void sym1_74145_output_1_w(int state)
42TTL74145_OUTPUT_LINE(sym1_74145_output_1_w)
4343{
4444   if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 1);
4545}
4646
4747
48static void sym1_74145_output_2_w(int state)
48TTL74145_OUTPUT_LINE(sym1_74145_output_2_w)
4949{
5050   if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 2);
5151}
5252
5353
54static void sym1_74145_output_3_w(int state)
54TTL74145_OUTPUT_LINE(sym1_74145_output_3_w)
5555{
5656   if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 3);
5757}
5858
5959
60static void sym1_74145_output_4_w(int state)
60TTL74145_OUTPUT_LINE(sym1_74145_output_4_w)
6161{
6262   if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 4);
6363}
6464
6565
66static void sym1_74145_output_5_w(int state)
66TTL74145_OUTPUT_LINE(sym1_74145_output_5_w)
6767{
6868   if (state) timer_adjust_oneshot(led_update, LED_REFRESH_DELAY, 5);
6969}
r3810r3811
7676
7777
7878/* The speaker is connected to output 6 of the 74145 */
79static void sym1_74145_output_6_w(int state)
79TTL74145_OUTPUT_LINE(sym1_74145_output_6_w)
8080{
8181   speaker_level_w(0, state);
8282}
r3810r3811
137137   riot_port_b = data;
138138
139139   /* first 4 pins are connected to the 74145 */
140   ttl74145_0_w( cpu_get_address_space( device->machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0, data & 0x0f);
140   ttl74145_w( (device_config*)device_list_find_by_tag( device->machine->config->devicelist, TTL74145, "ttl74145" ), 0, data & 0x0f);
141141}
142142
143143
r3810r3811
150150};
151151
152152
153static const ttl74145_interface ttl74145_intf =
153const ttl74145_interface sym1_ttl74145_intf =
154154{
155155   sym1_74145_output_0_w,  /* connected to DS0 */
156156   sym1_74145_output_1_w,  /* connected to DS1 */
r3810r3811
287287   via_config(1, &via1);
288288   via_config(2, &via2);
289289
290   /* configure 74145 */
291   ttl74145_config(machine, 0, &ttl74145_intf);
292
293290   /* allocate a timer to refresh the led display */
294291   led_update = timer_alloc(machine, led_refresh, NULL);
295292}
r3810r3811
298295MACHINE_RESET( sym1 )
299296{
300297   via_reset();
301   ttl74145_reset(0);
302298
303299   /* make 0xf800 to 0xffff point to the last half of the monitor ROM
304300      so that the CPU can find its reset vectors */
src/mess/drivers/sym1.c
r3810r3811
1313/* Peripheral chips */
1414#include "machine/6532riot.h"
1515#include "machine/6522via.h"
16#include "machine/74145.h"
1617
1718/* Layout */
1819#include "sym1.lh"
r3810r3811
132133
133134   /* devices */
134135   MDRV_RIOT6532_ADD("riot", SYM1_CLOCK, sym1_r6532_interface)
136   MDRV_TTL74145_ADD("ttl74145", sym1_ttl74145_intf)
135137MACHINE_DRIVER_END
136138
137139
src/mess/drivers/acrnsys1.c
r3810r3811
3535
3636static WRITE8_DEVICE_HANDLER( ins8154_b1_port_a_w )
3737{
38   ttl74145_0_w(cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0, data & 0x07);
38   ttl74145_w((device_config*)device_list_find_by_tag( device->machine->config->devicelist, TTL74145, "ttl74145" ), 0, data & 0x07);
3939}
4040
4141static WRITE8_DEVICE_HANDLER( acrnsys1_led_segment_w )
r3810r3811
5454   NULL
5555};
5656
57static void acrnsys1_7445_output_0_w(int state) { if (state) key_digit = 0; }
58static void acrnsys1_7445_output_1_w(int state) { if (state) key_digit = 1; }
59static void acrnsys1_7445_output_2_w(int state) { if (state) key_digit = 2; }
60static void acrnsys1_7445_output_3_w(int state) { if (state) key_digit = 3; }
61static void acrnsys1_7445_output_4_w(int state) { if (state) key_digit = 4; }
62static void acrnsys1_7445_output_5_w(int state) { if (state) key_digit = 5; }
63static void acrnsys1_7445_output_6_w(int state) { if (state) key_digit = 6; }
64static void acrnsys1_7445_output_7_w(int state) { if (state) key_digit = 7; }
57TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_0_w ) { if (state) key_digit = 0; }
58TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_1_w ) { if (state) key_digit = 1; }
59TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_2_w ) { if (state) key_digit = 2; }
60TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_3_w ) { if (state) key_digit = 3; }
61TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_4_w ) { if (state) key_digit = 4; }
62TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_5_w ) { if (state) key_digit = 5; }
63TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_6_w ) { if (state) key_digit = 6; }
64TTL74145_OUTPUT_LINE ( acrnsys1_7445_output_7_w ) { if (state) key_digit = 7; }
6565
6666static const ttl74145_interface ic8_7445 =
6767{
r3810r3811
7979
8080static DRIVER_INIT( acrnsys1 )
8181{
82   ttl74145_config(machine, 0, &ic8_7445);
8382}
8483
8584static MACHINE_RESET( acrnsys1 )
8685{
87   ttl74145_reset(0);
8886}
8987
9088
r3810r3811
9795   AM_RANGE(0x0000, 0x03ff) AM_RAM
9896   AM_RANGE(0x0e00, 0x0e7f) AM_MIRROR(0x100) AM_DEVREADWRITE(INS8154, "b1", ins8154_r, ins8154_w)
9997   AM_RANGE(0x0e80, 0x0eff) AM_MIRROR(0x100) AM_RAM
100   AM_RANGE(0xfe00, 0xffff) AM_MIRROR(0x600) AM_ROM
98   AM_RANGE(0xfe00, 0xffff) AM_ROM
10199ADDRESS_MAP_END
102100
103101
r3810r3811
189187   MDRV_DEVICE_CONFIG(ins8154_b1)
190188   
191189   MDRV_DEFAULT_LAYOUT(layout_acrnsys1)
190   
191   MDRV_TTL74145_ADD("ttl74145", ic8_7445)
192192MACHINE_DRIVER_END
193193
194194

Previous 15994 Revisions Next


© 1998-2018 The MESS Team