Previous 199869 Revisions Next

r24786 Wednesday 7th August, 2013 at 10:57:14 UTC by Dirk Best
74181.c: converted to a device
[src/emu/machine]74181.c 74181.h
[src/mame/drivers]berzerk.c

trunk/src/mame/drivers/berzerk.c
r24785r24786
2727      m_colorram(*this, "colorram"),
2828      m_maincpu(*this, "maincpu"),
2929      m_s14001a(*this, "speech"),
30      m_ls181_10c(*this, "ls181_10c"),
31      m_ls181_12c(*this, "ls181_12c"),
3032      m_custom(*this, "exidy") { }
3133
3234   required_shared_ptr<UINT8> m_videoram;
r24785r24786
3436   
3537   required_device<cpu_device> m_maincpu;
3638   required_device<s14001a_device> m_s14001a;
39   required_device<ttl74181_device> m_ls181_10c;
40   required_device<ttl74181_device> m_ls181_12c;
3741   required_device<exidy_sound_device> m_custom;
3842     
3943   UINT8 m_magicram_control;
r24785r24786
360364
361365#define NUM_PENS    (0x10)
362366
363#define LS181_12C   (0)
364#define LS181_10C   (1)
365367
366
367368void berzerk_state::video_start()
368369{
369   TTL74181_config(machine(), LS181_12C, 0);
370   TTL74181_write(LS181_12C, TTL74181_INPUT_M, 1, 1);
371
372   TTL74181_config(machine(), LS181_10C, 0);
373   TTL74181_write(LS181_10C, TTL74181_INPUT_M, 1, 1);
370   m_ls181_10c->mode_w(1);
371   m_ls181_12c->mode_w(1);
374372}
375373
376374
r24785r24786
395393      m_intercept = 0;
396394
397395   /* perform ALU step */
398   TTL74181_write(LS181_12C, TTL74181_INPUT_A0, 4, shift_flop_output & 0x0f);
399   TTL74181_write(LS181_10C, TTL74181_INPUT_A0, 4, shift_flop_output >> 4);
400   TTL74181_write(LS181_12C, TTL74181_INPUT_B0, 4, current_video_data & 0x0f);
401   TTL74181_write(LS181_10C, TTL74181_INPUT_B0, 4, current_video_data >> 4);
402   TTL74181_write(LS181_12C, TTL74181_INPUT_S0, 4, m_magicram_control >> 4);
403   TTL74181_write(LS181_10C, TTL74181_INPUT_S0, 4, m_magicram_control >> 4);
396   m_ls181_12c->input_a_w(shift_flop_output >> 0);
397   m_ls181_10c->input_a_w(shift_flop_output >> 4);
398   m_ls181_12c->input_b_w(current_video_data >> 0);
399   m_ls181_10c->input_b_w(current_video_data >> 4);
400   m_ls181_12c->select_w(m_magicram_control >> 4);
401   m_ls181_10c->select_w(m_magicram_control >> 4);
404402
405   alu_output = (TTL74181_read(LS181_10C, TTL74181_OUTPUT_F0, 4) << 4) |
406               (TTL74181_read(LS181_12C, TTL74181_OUTPUT_F0, 4) << 0);
403   alu_output = m_ls181_10c->function_r() << 4 | m_ls181_12c->function_r();
407404
408405   m_videoram[offset] = alu_output ^ 0xff;
409406
r24785r24786
10931090   MCFG_CPU_PROGRAM_MAP(berzerk_map)
10941091   MCFG_CPU_IO_MAP(berzerk_io_map)
10951092
1096
10971093   MCFG_NVRAM_ADD_0FILL("nvram")
10981094
1095   MCFG_TTL74181_ADD("ls181_10c")
1096   MCFG_TTL74181_ADD("ls181_12c")
1097
10991098   /* video hardware */
11001099
11011100   MCFG_SCREEN_ADD("screen", RASTER)
trunk/src/emu/machine/74181.c
r24785r24786
1/*
2 * 74181
3 *
4 * 4-bit arithmetic Logic Unit
5 *
6 */
1/***************************************************************************
72
8#include "emu.h"
9#include "74181.h"
3    74181
104
5    4-Bit Arithmetic Logic Unit
116
7***************************************************************************/
128
13#define TTL74181_MAX_CHIPS      (2)
14#define TTL74181_INPUT_TOTAL    (14)
15#define TTL74181_OUTPUT_TOTAL   (8)
9#include "74181.h"
1610
1711
12//**************************************************************************
13//  DEVICE DEFINITIONS
14//**************************************************************************
1815
19struct TTL74181_state
20{
21   UINT8 inputs[TTL74181_INPUT_TOTAL];
22   UINT8 outputs[TTL74181_OUTPUT_TOTAL];
23   UINT8 dirty;
24};
16const device_type TTL74181 = &device_creator<ttl74181_device>;
2517
26static TTL74181_state chips[TTL74181_MAX_CHIPS];
2718
19//**************************************************************************
20//  LIVE DEVICE
21//**************************************************************************
2822
29void TTL74181_config(running_machine &machine, int which, void *intf)
30{
31   TTL74181_state *c;
23//-------------------------------------------------
24//  ttl74181_device - constructor
25//-------------------------------------------------
3226
33   assert_always(machine.phase() == MACHINE_PHASE_INIT, "Can only call at init time!");
34   assert_always(intf == 0, "Interface must be NULL");
35   assert_always((which >= 0) && (which < TTL74181_MAX_CHIPS), "Exceeded maximum number of 74181 chips");
36
37   c = &chips[which];
38
39   c->dirty = 1;
40
41   state_save_register_item_array(machine, "TTL74181", NULL, which, c->inputs);
42   state_save_register_item_array(machine, "TTL74181", NULL, which, c->outputs);
43   state_save_register_item      (machine, "TTL74181", NULL, which, c->dirty);
27ttl74181_device::ttl74181_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
28   device_t(mconfig, TTL74181, "TTL74181", tag, owner, clock, "ttl74181", __FILE__),
29   m_a(0),
30   m_b(0),
31   m_s(0),
32   m_m(0),
33   m_c(0)
34{
4435}
4536
37//-------------------------------------------------
38//  device_start - device-specific startup
39//-------------------------------------------------
4640
47void TTL74181_reset(int which)
41void ttl74181_device::device_start()
4842{
49   /* nothing to do */
43   // register for state saving
44   save_item(NAME(m_a));
45   save_item(NAME(m_b));
46   save_item(NAME(m_s));
47   save_item(NAME(m_m));
48   save_item(NAME(m_c));
5049}
5150
51//-------------------------------------------------
52//  device_post_load - called after loading a saved state
53//-------------------------------------------------
5254
53static void TTL74181_update(int which)
55void ttl74181_device::device_post_load()
5456{
55   TTL74181_state *c = &chips[which];
57   // after loading a state re-initialize our output lines
58   update();
59}
5660
57   UINT8 a0 =  c->inputs[TTL74181_INPUT_A0];
58   UINT8 a1 =  c->inputs[TTL74181_INPUT_A1];
59   UINT8 a2 =  c->inputs[TTL74181_INPUT_A2];
60   UINT8 a3 =  c->inputs[TTL74181_INPUT_A3];
6161
62   UINT8 b0 =  c->inputs[TTL74181_INPUT_B0];
63   UINT8 b1 =  c->inputs[TTL74181_INPUT_B1];
64   UINT8 b2 =  c->inputs[TTL74181_INPUT_B2];
65   UINT8 b3 =  c->inputs[TTL74181_INPUT_B3];
62//**************************************************************************
63//  ARITHMETHIC UNIT
64//**************************************************************************
6665
67   UINT8 s0 =  c->inputs[TTL74181_INPUT_S0];
68   UINT8 s1 =  c->inputs[TTL74181_INPUT_S1];
69   UINT8 s2 =  c->inputs[TTL74181_INPUT_S2];
70   UINT8 s3 =  c->inputs[TTL74181_INPUT_S3];
66void ttl74181_device::update()
67{
68   // inputs
69   int a0 = BIT(m_a, 0), a1 = BIT(m_a, 1), a2 = BIT(m_a, 2), a3 = BIT(m_a, 3);
70   int b0 = BIT(m_b, 0), b1 = BIT(m_b, 1), b2 = BIT(m_b, 2), b3 = BIT(m_b, 3);
71   int s0 = BIT(m_s, 0), s1 = BIT(m_s, 1), s2 = BIT(m_s, 2), s3 = BIT(m_s, 3);
72   int mp = !m_m;
7173
72   UINT8 cp =  c->inputs[TTL74181_INPUT_C];
73   UINT8 mp = !c->inputs[TTL74181_INPUT_M];
74   // intermediate calculations
75   int ap0 = !(a0 | (b0 & s0) | (s1 & !b0));
76   int bp0 = !(((!b0) & s2 & a0) | (a0 & b0 & s3));
77   int ap1 = !(a1 | (b1 & s0) | (s1 & !b1));
78   int bp1 = !(((!b1) & s2 & a1) | (a1 & b1 & s3));
79   int ap2 = !(a2 | (b2 & s0) | (s1 & !b2));
80   int bp2 = !(((!b2) & s2 & a2) | (a2 & b2 & s3));
81   int ap3 = !(a3 | (b3 & s0) | (s1 & !b3));
82   int bp3 = !(((!b3) & s2 & a3) | (a3 & b3 & s3));
7483
75   UINT8 ap0 = !(a0 | (b0 & s0) | (s1 & !b0));
76   UINT8 bp0 = !(((!b0) & s2 & a0) | (a0 & b0 & s3));
77   UINT8 ap1 = !(a1 | (b1 & s0) | (s1 & !b1));
78   UINT8 bp1 = !(((!b1) & s2 & a1) | (a1 & b1 & s3));
79   UINT8 ap2 = !(a2 | (b2 & s0) | (s1 & !b2));
80   UINT8 bp2 = !(((!b2) & s2 & a2) | (a2 & b2 & s3));
81   UINT8 ap3 = !(a3 | (b3 & s0) | (s1 & !b3));
82   UINT8 bp3 = !(((!b3) & s2 & a3) | (a3 & b3 & s3));
84   int fp0 = !(m_c & mp) ^ ((!ap0) & bp0);
85   int fp1 = (!((mp & ap0) | (mp & bp0 & m_c))) ^ ((!ap1) & bp1);
86   int fp2 = (!((mp & ap1) | (mp & ap0 & bp1) | (mp & m_c & bp0 & bp1))) ^ ((!ap2) & bp2);
87   int fp3 = (!((mp & ap2) | (mp & ap1 & bp2) | (mp & ap0 & bp1 & bp2) | (mp & m_c & bp0 & bp1 & bp2))) ^ ((!ap3) & bp3);
8388
84   UINT8 fp0 = !(cp & mp) ^ ((!ap0) & bp0);
85   UINT8 fp1 = (!((mp & ap0) | (mp & bp0 & cp))) ^ ((!ap1) & bp1);
86   UINT8 fp2 = (!((mp & ap1) | (mp & ap0 & bp1) | (mp & cp & bp0 & bp1))) ^ ((!ap2) & bp2);
87   UINT8 fp3 = (!((mp & ap2) | (mp & ap1 & bp2) | (mp & ap0 & bp1 & bp2) | (mp & cp & bp0 & bp1 & bp2))) ^ ((!ap3) & bp3);
88
89   UINT8 aeqb = fp0 & fp1 & fp2 & fp3;
90   UINT8 pp = !(bp0 & bp1 & bp2 & bp3);
91   UINT8 gp = !((ap0 & bp1 & bp2 & bp3) | (ap1 & bp2 & bp3) | (ap2 & bp3) | ap3);
92   UINT8 cn4 = (!(cp & bp0 & bp1 & bp2 & bp3)) | gp;
93
94   c->outputs[TTL74181_OUTPUT_F0]   = fp0;
95   c->outputs[TTL74181_OUTPUT_F1]   = fp1;
96   c->outputs[TTL74181_OUTPUT_F2]   = fp2;
97   c->outputs[TTL74181_OUTPUT_F3]   = fp3;
98   c->outputs[TTL74181_OUTPUT_AEQB] = aeqb;
99   c->outputs[TTL74181_OUTPUT_P]    = pp;
100   c->outputs[TTL74181_OUTPUT_G]    = gp;
101   c->outputs[TTL74181_OUTPUT_CN4]  = cn4;
89   // outputs
90   m_f = fp0 | fp1 << 1 | fp2 << 2 | fp3 << 3;
91   m_equals = fp0 & fp1 & fp2 & fp3;
92   m_p = !(bp0 & bp1 & bp2 & bp3);
93   m_g = !((ap0 & bp1 & bp2 & bp3) | (ap1 & bp2 & bp3) | (ap2 & bp3) | ap3);
94   m_cn = (!(m_c & bp0 & bp1 & bp2 & bp3)) | m_g;
10295}
10396
104
105void TTL74181_write(int which, int startline, int lines, UINT8 data)
97void ttl74181_device::input_a_w(UINT8 data)
10698{
107   int line;
108   TTL74181_state *c;
99   data &= 0x0f;
109100
110   assert_always((which >= 0) && (which < TTL74181_MAX_CHIPS), "Chip index out of range");
111
112   c = &chips[which];
113
114   assert_always(c != NULL, "Invalid index - chip has not been configured");
115   assert_always(lines >= 1, "Must set at least one line");
116   assert_always(lines <= 4, "Can't set more than 4 lines at once");
117   assert_always((startline + lines) <= TTL74181_INPUT_TOTAL, "Input line index out of range");
118
119   for (line = 0; line < lines; line++)
101   if (m_a != data)
120102   {
121      UINT8 input = (data >> line) & 0x01;
103      m_a = data;
104      update();
105   }
106}
122107
123      if (c->inputs[startline + line] != input)
124      {
125         c->inputs[startline + line] = input;
108void ttl74181_device::input_b_w(UINT8 data)
109{
110   data &= 0x0f;
126111
127         c->dirty = 1;
128      }
112   if (m_b != data)
113   {
114      m_b = data;
115      update();
129116   }
130117}
131118
132
133UINT8 TTL74181_read(int which, int startline, int lines)
119void ttl74181_device::select_w(UINT8 data)
134120{
135   int line;
136   UINT8 data;
137   TTL74181_state *c;
121   m_s &= data & 0x0f;
138122
139   assert_always((which >= 0) && (which < TTL74181_MAX_CHIPS), "Chip index out of range");
140
141   c = &chips[which];
142
143   assert_always(c != NULL, "Invalid index - chip has not been configured");
144   assert_always(lines >= 1, "Must read at least one line");
145   assert_always(lines <= 4, "Can't read more than 4 lines at once");
146   assert_always((startline + lines) <= TTL74181_OUTPUT_TOTAL, "Output line index out of range");
147
148   if (c->dirty)
123   if (m_s != data)
149124   {
150      TTL74181_update(which);
151
152      c->dirty = 0;
125      m_s = data;
126      update();
153127   }
128}
154129
155
156   data = 0;
157
158   for (line = 0; line < lines; line++)
130WRITE_LINE_MEMBER( ttl74181_device::mode_w )
131{
132   if (m_m != state)
159133   {
160      data = data | (c->outputs[startline + line] << line);
134      m_m = state;
135      update();
161136   }
137}
162138
163   return data;
139WRITE_LINE_MEMBER( ttl74181_device::carry_w )
140{
141   if (m_c != state)
142   {
143      m_c = state;
144      update();
145   }
164146}
trunk/src/emu/machine/74181.h
r24785r24786
1/*
2 * 74181
3 *
4 * 4-Bit Arithmetic Logic Unit
5 *
6 */
1/***************************************************************************
72
3    74181
84
9/* constants for setting input lines */
10#define TTL74181_INPUT_A0       (0)
11#define TTL74181_INPUT_A1       (1)
12#define TTL74181_INPUT_A2       (2)
13#define TTL74181_INPUT_A3       (3)
14#define TTL74181_INPUT_B0       (4)
15#define TTL74181_INPUT_B1       (5)
16#define TTL74181_INPUT_B2       (6)
17#define TTL74181_INPUT_B3       (7)
18#define TTL74181_INPUT_S0       (8)
19#define TTL74181_INPUT_S1       (9)
20#define TTL74181_INPUT_S2       (10)
21#define TTL74181_INPUT_S3       (11)
22#define TTL74181_INPUT_C        (12)
23#define TTL74181_INPUT_M        (13)
5    4-Bit Arithmetic Logic Unit
246
25/* constants for reads output lines */
26#define TTL74181_OUTPUT_F0      (0)
27#define TTL74181_OUTPUT_F1      (1)
28#define TTL74181_OUTPUT_F2      (2)
29#define TTL74181_OUTPUT_F3      (3)
30#define TTL74181_OUTPUT_AEQB    (4)
31#define TTL74181_OUTPUT_P       (5)
32#define TTL74181_OUTPUT_G       (6)
33#define TTL74181_OUTPUT_CN4     (7)
7***************************************************************************/
348
9#pragma once
3510
36void TTL74181_config(running_machine &machine, int chip, void *interface);
37void TTL74181_reset(int chip);
11#ifndef __74181_H__
12#define __74181_H__
3813
39void TTL74181_write(int chip, int startline, int lines, UINT8 data);
40UINT8 TTL74181_read(int chip, int startline, int lines);
14#include "emu.h"
15
16
17//**************************************************************************
18//  INTERFACE CONFIGURATION MACROS
19//**************************************************************************
20
21#define MCFG_TTL74181_ADD(_tag) \
22   MCFG_DEVICE_ADD(_tag, TTL74181, 0) \
23
24
25//**************************************************************************
26//  TYPE DEFINITIONS
27//**************************************************************************
28
29// ======================> ttl74181_device
30
31class ttl74181_device : public device_t
32{
33public:
34   // construction/destruction
35   ttl74181_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
36
37   // inputs
38   void input_a_w(UINT8 data);
39   void input_b_w(UINT8 data);
40   void select_w(UINT8 data);
41   DECLARE_WRITE_LINE_MEMBER( mode_w );
42   DECLARE_WRITE_LINE_MEMBER( carry_w );
43
44   // outputs
45   UINT8 function_r() { return m_f; }
46   DECLARE_READ_LINE_MEMBER( carry_r ) { return m_cn; }
47   DECLARE_READ_LINE_MEMBER( generate_r ) { return m_g; }
48   DECLARE_READ_LINE_MEMBER( propagate_r ) { return m_p; }
49   DECLARE_READ_LINE_MEMBER( equals_r ) { return m_equals; }
50
51protected:
52   // device-level overrides
53   virtual void device_start();
54   virtual void device_post_load();
55
56private:
57   void update();
58
59   // inputs
60   UINT8 m_a;
61   UINT8 m_b;
62   UINT8 m_s;
63   int m_m;
64   int m_c;
65
66   // outputs
67   UINT8 m_f;
68   int m_cn;
69   int m_g;
70   int m_p;
71   int m_equals;
72};
73
74
75// device type definition
76extern const device_type TTL74181;
77
78
79#endif  /* __74181_H__ */

Previous 199869 Revisions Next


© 1997-2024 The MAME Team