Previous 199869 Revisions Next

r36272 Thursday 5th March, 2015 at 20:16:45 UTC by David Haywood
Merge branch 'master' of https://github.com/mamedev/mame
[src/emu/cpu/hmcs40]hmcs40.c hmcs40.h hmcs40op.inc

trunk/src/emu/cpu/hmcs40/hmcs40.c
r244783r244784
6565
6666static ADDRESS_MAP_START(data_160x4, AS_DATA, 8, hmcs40_cpu_device)
6767   AM_RANGE(0x00, 0x7f) AM_RAM
68   AM_RANGE(0x80, 0x9f) AM_RAM AM_MIRROR(0x70)
68   AM_RANGE(0x80, 0x8f) AM_RAM AM_MIRROR(0x30)
69   AM_RANGE(0xc0, 0xcf) AM_RAM AM_MIRROR(0x30)
6970ADDRESS_MAP_END
7071
7172
r244783r244784
9596         );
9697         break;
9798
99      case STATE_GENPC:
100         string.printf("%03X", m_pc << 1);
101         break;
102
98103      default: break;
99104   }
100105}
r244783r244784
123128   m_data = &space(AS_DATA);
124129   m_prgmask = (1 << m_prgwidth) - 1;
125130   m_datamask = (1 << m_datawidth) - 1;
131   m_xmask = (1 << (m_datawidth - 4)) - 1;
126132
127133   m_read_d.resolve_safe(0);
128134   m_write_d.resolve_safe();
r244783r244784
130136   // zerofill
131137   memset(m_stack, 0, sizeof(m_stack));
132138   m_op = 0;
139   m_arg = 0;
133140   m_pc = 0;
134141   m_a = 0;
135142   m_b = 0;
r244783r244784
143150   // register for savestates
144151   save_item(NAME(m_stack));
145152   save_item(NAME(m_op));
153   save_item(NAME(m_arg));
146154   save_item(NAME(m_pc));
147155   save_item(NAME(m_a));
148156   save_item(NAME(m_b));
r244783r244784
162170   state_add(HMCS40_Y,   "Y",   m_y).formatstr("%01X");
163171   state_add(HMCS40_SPY, "SPY", m_spy).formatstr("%01X");
164172
165   state_add(STATE_GENPC, "curpc", m_pc).formatstr("%04X").noshow();
173   state_add(STATE_GENPC, "curpc", m_pc).formatstr("%03X").noshow();
166174   state_add(STATE_GENFLAGS, "GENFLAGS", m_s).formatstr("%2s").noshow();
167175
168176   m_icountptr = &m_icount;
r244783r244784
176184
177185void hmcs40_cpu_device::device_reset()
178186{
179   m_pc = 0;
187   m_pc = 0xffff & m_prgmask;
180188   m_op = 0;
181189}
182190
r244783r244784
186194//  execute
187195//-------------------------------------------------
188196
197inline void hmcs40_cpu_device::increment_pc()
198{
199   // PC lower bits is a LFSR identical to TI TMS1000
200   UINT8 mask = 0x3f;
201   UINT8 low = m_pc & mask;
202   int fb = (low << 1 & 0x20) == (low & 0x20);
203
204   if (low == (mask >> 1))
205      fb = 1;
206   else if (low == mask)
207      fb = 0;
208
209   m_pc = (m_pc & ~mask) | ((m_pc << 1 | fb) & mask);
210}
211
212inline void hmcs40_cpu_device::fetch_arg()
213{
214   // P is the only 2-byte opcode
215   if (m_op == 0x3ff)
216   {
217      m_icount--;
218      m_arg = m_program->read_word(m_pc << 1);
219      increment_pc();
220   }
221}
222
189223void hmcs40_cpu_device::execute_run()
190224{
191225   while (m_icount > 0)
192226   {
193227      m_icount--;
194228     
195      debugger_instruction_hook(this, m_pc);
196      m_op = m_program->read_byte(m_pc);
197      m_pc = (m_pc + 1) & m_prgmask;
229      debugger_instruction_hook(this, m_pc << 1);
230      m_op = m_program->read_word(m_pc << 1);
231      increment_pc();
232      fetch_arg();
198233   }
199234}
trunk/src/emu/cpu/hmcs40/hmcs40.h
r244783r244784
6868   int m_datawidth;
6969   int m_prgmask;
7070   int m_datamask;
71   int m_xmask;
7172   int m_stack_levels; // number of callstack levels
7273   UINT16 m_stack[4];  // max 4
7374   UINT16 m_op;
75   UINT16 m_arg;
7476   int m_icount;
7577   
7678   UINT16 m_pc;        // Program Counter
r244783r244784
8789   devcb_read16 m_read_d;
8890   devcb_write16 m_write_d;
8991
92   // misc internal helpers
93   void increment_pc();
94   void fetch_arg();
95
96   UINT8 ram_r();
97   void ram_w(UINT8 data);
98   void pop_stack();
99   void push_stack();
100
90101   // opcode handlers
91102   void op_lab();
92103   void op_lba();
r244783r244784
104115   void op_ayy();
105116   void op_syy();
106117   void op_xspx();
107   void op_sxpy();
118   void op_xspy();
108119   void op_xspxy();
109120
110121   void op_lam();
trunk/src/emu/cpu/hmcs40/hmcs40op.inc
r244783r244784
22
33// internal helpers
44
5inline UINT8 hmcs40_cpu_device::ram_r()
6{
7   UINT8 address = (m_x << 4 | m_y) & m_datamask;
8   return m_data->read_byte(address) & 0xf;
9}
10
11inline void hmcs40_cpu_device::ram_w(UINT8 data)
12{
13   UINT8 address = (m_x << 4 | m_y) & m_datamask;
14   m_data->write_byte(address, data & 0xf);
15}
16
17void hmcs40_cpu_device::pop_stack()
18{
19   m_pc = m_stack[0] & m_prgmask;
20   for (int i = 0; i < m_stack_levels-1; i++)
21      m_stack[i] = m_stack[i+1];
22}
23
24void hmcs40_cpu_device::push_stack()
25{
26   for (int i = m_stack_levels-1; i >= 1; i--)
27      m_stack[i] = m_stack[i-1];
28   m_stack[0] = m_pc;
29}
30
531void hmcs40_cpu_device::op_illegal()
632{
733   logerror("%s unknown opcode $%03X at $%04X\n", tag(), m_op, m_pc);
r244783r244784
1642void hmcs40_cpu_device::op_lab()
1743{
1844   // LAB: Load A from B
19   op_illegal();
45   m_a = m_b;
2046}
2147
2248void hmcs40_cpu_device::op_lba()
2349{
2450   // LBA: Load B from A
25   op_illegal();
51   m_b = m_a;
2652}
2753
2854void hmcs40_cpu_device::op_lay()
2955{
3056   // LAY: Load A from Y
31   op_illegal();
57   m_a = m_y;
3258}
3359
3460void hmcs40_cpu_device::op_laspx()
3561{
3662   // LASPX: Load A from SPX
37   op_illegal();
63   m_a = m_spx;
3864}
3965
4066void hmcs40_cpu_device::op_laspy()
4167{
4268   // LASPY: Load A from SPY
43   op_illegal();
69   m_a = m_spy;
4470}
4571
4672void hmcs40_cpu_device::op_xamr()
4773{
4874   // XAMR m: Exchange A and MR(m)
49   op_illegal();
75   
76   // determine MR(Memory Register) location
77   UINT8 y = m_op & 0xf;
78   UINT8 x = (y > 3) ? 0xf : (y + 12);
79   UINT8 address = (x << 4 | y) & m_datamask;
80   
81   UINT8 old_a = m_a;
82   m_a = m_data->read_byte(address) & 0xf;
83   m_data->write_byte(address, old_a & 0xf);
5084}
5185
5286
r244783r244784
5589void hmcs40_cpu_device::op_lxa()
5690{
5791   // LXA: Load X from A
58   op_illegal();
92   m_x = m_a;
5993}
6094
6195void hmcs40_cpu_device::op_lya()
6296{
6397   // LYA: Load Y from A
64   op_illegal();
98   m_y = m_a;
6599}
66100
67101void hmcs40_cpu_device::op_lxi()
68102{
69103   // LXI i: Load X from Immediate
70   op_illegal();
104   m_x = m_op & 0xf;
71105}
72106
73107void hmcs40_cpu_device::op_lyi()
74108{
75109   // LYI i: Load Y from Immediate
76   op_illegal();
110   m_y = m_op & 0xf;
77111}
78112
79113void hmcs40_cpu_device::op_iy()
80114{
81115   // IY: Increment Y
82   op_illegal();
116   m_y = (m_y + 1) & 0xf;
117   m_s = (m_y != 0);
83118}
84119
85120void hmcs40_cpu_device::op_dy()
86121{
87122   // DY: Decrement Y
88   op_illegal();
123   m_y = (m_y - 1) & 0xf;
124   m_s = (m_y != 0xf);
89125}
90126
91127void hmcs40_cpu_device::op_ayy()
92128{
93129   // AYY: Add A to Y
94   op_illegal();
130   m_y += m_a;
131   m_s = m_y >> 4 & 1;
132   m_y &= 0xf;
95133}
96134
97135void hmcs40_cpu_device::op_syy()
98136{
99137   // SYY: Subtract A from Y
100   op_illegal();
138   m_y -= m_a;
139   m_s = ~m_y >> 4 & 1;
140   m_y &= 0xf;
101141}
102142
103143void hmcs40_cpu_device::op_xspx()
104144{
105145   // XSPX: Exchange X and SPX
106   op_illegal();
146   UINT8 old_x = m_x;
147   m_x = m_spx;
148   m_spx = old_x;
107149}
108150
109void hmcs40_cpu_device::op_sxpy()
151void hmcs40_cpu_device::op_xspy()
110152{
111   // SXPY: Exchange Y and SPY
112   op_illegal();
153   // XSPY: Exchange Y and SPY
154   UINT8 old_y = m_y;
155   m_y = m_spy;
156   m_spy = old_y;
113157}
114158
115159void hmcs40_cpu_device::op_xspxy()
116160{
117161   // XSPXY: Exchange X and SPX, Y and SPY
118   op_illegal();
162   op_xspx();
163   op_xspy();
119164}
120165
121166
r244783r244784
124169void hmcs40_cpu_device::op_lam()
125170{
126171   // LAM (XY): Load A from Memory
127   op_illegal();
172   m_a = ram_r();
173   op_xspxy();
128174}
129175
130176void hmcs40_cpu_device::op_lbm()
131177{
132178   // LBM (XY): Load B from Memory
133   op_illegal();
179   m_b = ram_r();
180   op_xspxy();
134181}
135182
136183void hmcs40_cpu_device::op_xma()
137184{
138185   // XMA (XY): Exchange Memory and A
139   op_illegal();
186   UINT8 old_a = m_a;
187   m_a = ram_r();
188   ram_w(old_a);
189   op_xspxy();
140190}
141191
142192void hmcs40_cpu_device::op_xmb()
143193{
144194   // XMB (XY): Exchange Memory and B
145   op_illegal();
195   UINT8 old_b = m_b;
196   m_b = ram_r();
197   ram_w(old_b);
198   op_xspxy();
146199}
147200
148201void hmcs40_cpu_device::op_lmaiy()
149202{
150203   // LMAIY (X): Load Memory from A, Increment Y
151   op_illegal();
204   ram_w(m_a);
205   op_iy();
206   op_xspx();
152207}
153208
154209void hmcs40_cpu_device::op_lmady()
155210{
156211   // LMADY (X): Load Memory from A, Decrement Y
157   op_illegal();
212   ram_w(m_a);
213   op_dy();
214   op_xspx();
158215}
159216
160217
r244783r244784
163220void hmcs40_cpu_device::op_lmiiy()
164221{
165222   // LMIIY i: Load Memory from Immediate, Increment Y
166   op_illegal();
223   ram_w(m_op & 0xf);
224   op_iy();
167225}
168226
169227void hmcs40_cpu_device::op_lai()
170228{
171229   // LAI i: Load A from Immediate
172   op_illegal();
230   m_a = m_op & 0xf;
173231}
174232
175233void hmcs40_cpu_device::op_lbi()
176234{
177235   // LBI i: Load B from Immediate
178   op_illegal();
236   m_b = m_op & 0xf;
179237}
180238
181239


Previous 199869 Revisions Next


© 1997-2024 The MAME Team