OpenCores
URL https://opencores.org/ocsvn/m65c02/m65c02/trunk

Subversion Repositories m65c02

[/] [m65c02/] [trunk/] [Src/] [Microprogram-Sources/] [M65C02_uPgm_V3.txt] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 MichaelA
header
2
Project: M65C02_uP_ROM
3
File Revision: 0019
4
Author(s): Michael A. Morris
5
Description: M65C02 Microprogram
6
endh
7
 
8
--------------------------------------------------------------------------------
9
--
10
--  Copyright 2011-2013 by Michael A. Morris, dba M. A. Morris & Associates
11
--
12
--  All rights reserved. The source code contained herein is publicly released
13
--  under the terms and conditions of the GNU Lesser Public License. No part of
14
--  this source code may be reproduced or transmitted in any form or by any
15
--  means, electronic or mechanical, including photocopying, recording, or any
16
--  information storage and retrieval system in violation of the license under
17
--  which the source code is released.
18
--
19
--  The source code contained herein is free; it may be redistributed and/or
20
--  modified in accordance with the terms of the GNU Lesser General Public
21
--  License as published by the Free Software Foundation; either version 2.1 of
22
--  the GNU Lesser General Public License, or any later version.
23
--
24
--  The source code contained herein is freely released WITHOUT ANY WARRANTY;
25
--  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
26
--  PARTICULAR PURPOSE. (Refer to the GNU Lesser General Public License for
27
--  more details.)
28
--
29
--  A copy of the GNU Lesser General Public License should have been received
30
--  along with the source code contained herein; if not, a copy can be obtained
31
--  by writing to:
32
--
33
--  Free Software Foundation, Inc.
34
--  51 Franklin Street, Fifth Floor
35
--  Boston, MA  02110-1301 USA
36
--
37
--  Further, no use of this source code is permitted in any form or means
38
--  without inclusion of this banner prominently in any derived works.
39
--
40
--  Michael A. Morris
41
--  Huntsville, AL
42
--
43
--------------------------------------------------------------------------------
44
 
45
--------------------------------------------------------------------------------
46
-- Revision History:
47
--------------------------------------------------------------------------------
48
--
49
--  0001    11D09   mam     Initial development.
50
--
51
--  0002    11D17   mam     Continued development.
52
--
53
--  0003    12A21   mam     Continued development, added En_PC field, removed
54
--                          Bus Interface Unit (BIU) and Program Control Unit
55
--                          (PCU) control fields and changed Memory Data Output
56
--                          field to Memory Data Output/Input Field. The BIU and
57
--                          PCU concepts deemed to complex for this implementa-
58
--                          tion. Implementation now relies on direct control of
59
--                          the bus cycles by the microprogram. Conditional exe-
60
--                          cution of most branches is now used to allow the uP
61
--                          execution to be controlled by the test signals. this
62
--                          allows tighter and faster uPgms, and facilitates the
63
--                          implementation of the uPgm.
64
--
65
--  0004    12A22   mam     Completed development of the MAM6502 microprogram.
66
--                          Added comments below regarding the implementation of
67
--                          the conditional branches discussed in note 0003. No
68
--                          attempt is made to minimize the number or length of
69
--                          the microroutines. Only five instructions are used,
70
--                          and no subroutines are used. Several direct address-
71
--                          microroutines are equivalent. Since several of these
72
--                          addressing modes yield the same effective address,
73
--                          they could be combined, but it is unlikely to save
74
--                          enough to allow the branch address field and MPC
75
--                          address register to be decreased from 8 to 7 bits.
76
--
77
--  0005    12B07   mam     Completed the restructing of the microprogram. the
78
--                          basic structure remains the same. However, issues
79
--                          related to the pipelining of the instruction decode
80
--                          (fixed microword) have been corrected by incorpora-
81
--                          ting a instruction decode ROM directly into the uP
82
--                          ROM itself. This corrects the primary issue which is
83
--                          that the first microword of each instruction se-
84
--                          quence needed to be specific for each instruction or
85
--                          addressing mode. With the previous architecture, too
86
--                          much special handling logic was needed to ensure
87
--                          proper execution of individual instructions. The
88
--                          special logic needed was proving to be difficult to
89
--                          implement, and thus violating the primary motivation
90
--                          for the development of the control unit as a micro-
91
--                          programmed state machine. With the new structure,
92
--                          the first microword on the control unit is deter-
93
--                          simultaneously with the look-up in the instruction
94
--                          decoder ROM of the fixed instruction microword. The
95
--                          format of the Instruction Decode ROM has been sim-
96
--                          plified, and the actual opcode embedded in the
97
--                          fixed microword in order to preserve a width of 32
98
--                          for this ROM and that of the variable microwords. If
99
--                          this field is left out, since its contents matches
100
--                          the input, then the total amount of microwords (var
101
--                          plus fixed) is 32 + 24 = 56 bits. The two level,
102
--                          i.e. fixed and variable microcode, will be main-
103
--                          tained because the 24 bits of the fixed microword is
104
--                          required until the control unit indicates that the
105
--                          instruction is ready to execute, i.e. enable ALU.
106
--                          The final major change was that the specific modifi-
107
--                          cations to many of the branching instructions of the
108
--                          MAM6502_MPC (based on the F9408A_MPC) have been un-
109
--                          done, and conditional execution applied, under con-
110
--                          trol of control field in the variable microword, to
111
--                          all instructions of the MPC. This allows the micro-
112
--                          programmed state machine, i.e. control unit, to been
113
--                          responsible for the synchronization and capture of
114
--                          external data. The automatic cycle wait delay that
115
--                          is now built in for all MPC instructions, can be
116
--                          automatically performed if the microprogram allows
117
--                          it explicitly, or it can simply use multiple states
118
--                          to implement the required timing and external bus
119
--                          synchronization. Finally, the external memory was
120
--                          defined as a LUT RAM. This means that data reads and
121
--                          data writes are single clock cycle operations. The
122
--                          Rdy cycle completion signal will stretch the control
123
--                          unit operations dependent on the external memory. If
124
--                          needed, additional logic can be added, and the con-
125
--                          trol unit should execute instructions as required.
126
--
127
--  0006    12B16   MAM     Completed checkout of the basic instructions and
128
--                          addressing modes: Jumps, Branches, push/pop, all
129
--                          alu operations with immediate operands, acc modes
130
--                          instructions, all flag set/clear instructions, and
131
--                          all other implied operand instructions except BRK.
132
--                          Optimized microroutines to eliminate state redundant
133
--                          with _Nxt (Fetch/Execute) state. This eliminates the
134
--                          second state of Push/Pop instructions, all immediate
135
--                          operand instructions, and all branches. Labels moved
136
--                          and grouped with the _Nxt label as a reminder that
137
--                          this optimization is included.
138
--
139
--  0007    12B19   MAM     Added missing instruction: STZ dp,X
140
--
141
--  0008    12B20   MAM     Reworked the _Int and _Brk microroutines. Added the
142
--                          ISR strobe to the third cycle, i.e. Push P state, to
143
--                          explicitly clear D and set I before start of inter-
144
--                          rupt/trap service routine.
145
--
146
--  0009    12B22   MAM     Added limited support for interrupt handling at spe-
147
--                          cific instruction boundaries. The Branch Multi-Way
148
--                          MPC instruction is used in the last state of each
149
--                          microsequence to sample the external Int signal. the
150
--                          configuration of the _Nxt and _Int microstates form
151
--                          a 2-way branch table. The last state in a microse-
152
--                          points to this 2-way table, and if the Int signal is
153
--                          asserted, then the _Int microsequence is executed,
154
--                          otherwise the normal instruction fetch/decode of the
155
--                          next instruction is performed by the BRV1 instruc-
156
--                          at _Nxt.
157
--
158
--  0010    12B23   MAM     Completed conversion of the microcode for the other
159
--                          instruction groups, except the RMW groups, to sup-
160
--                          port interrupts. Due to the overlapped nature of the
161
--                          fetch and execute, the first microstate in _Int was
162
--                          set to signal Done. In this way while PCH is being
163
--                          pushed, the instruction is being executed. A problem
164
--                          still remains in how to deal with the extra cycle
165
--                          required to complete ADC/SBC in BCD mode. The BCD
166
--                          adder requires an extra cycle to complete adjustment
167
--                          of the two BCD digits following the initial binary
168
--                          sum.
169
--
170
--  0011    12B24   MAM     Changed microprogram for CLI/SEI so that they are
171
--                          interruptable. That is, if IRQ/NMI is asserted when
172
--                          these instruction enable/disable interrupts, then
173
--                          the trap will not be taken until the completion of
174
--                          instruction which follows. (BCD operations issue
175
--                          rectified in change made to M65C02_Core/M65C02_ALU
176
--                          modules.)
177
--
178
--  0012    12B25   MAM     Added WE_R to _Int microstate to allow instruction
179
--                          being interrupted to complete. All other elements
180
--                          needed to correctly interrupt an instruction made
181
--                          to module M65C02_Core. Added a second jump table for
182
--                          normal or interrupt processing of RMW instructions.
183
--                          _Nxt/_Int are not acceptable since they assert WE_R
184
--                          to allow instruction to complete while PCH is being
185
--                          pushed. RMW instructions have already written any
186
--                          registers, so a second WE_R could corrupt memory or
187
--                          the PSW. Thus, the BRV1 and BRV2 microstates in the
188
--                          RMW jump table do not assert WE_R.
189
--
190
--  0013    12C04   MAM     Made corrections to all RMW operations. Change makes
191
--                          the output of the ALU come out on the output data
192
--                          bus on the correct cycle. The ALU provides the out-
193
--                          put on the cycle following the read, so there's no
194
--                          need for a cycle to wait on ALU Valid before writing
195
--                          result back to memory.
196
--
197
--  0014    12D28   MAM     Corrected the _LDX_abs instruction. Improperly took
198
--                          branch to _RO_AbsX instead of _RO_Abs. (Notified of
199
--                          error by Windfall @forum.6502.org.)
200
--
201
--  0015    12K17   MAM     Corrected entry for $22 from BRV1 to BRV3. Added
202
--                          Done to the _Brk_imm microword. Matches Done for the
203
--                          M65C02_MPCv3, and does not significantly alter the
204
--                          significance of the Done signal; Done is asserted
205
--                          for two cycles for BRK whereas it is asserted for
206
--                          one cycle for other instructions. It is asserted for
207
--                          two cycles because the _BRK microroutine is being
208
--                          shared between BRK and interrupt handling. If sepa-
209
--                          rate routines are used, then Done could be made to
210
--                          assert for only one cycle.
211
--
212
--  0016    12K20   MAM     Added Wait to microprogram word 0. This allows then
213
--                          Ack_In line to be deasserted during reset and before
214
--                          the start of microprogram execution.
215
--
216
--  0017    12L09   MAM     Added support for WAI, STP, and indirect jumps for
217
--                          NMI and IRQ/BRK. Also added indirect jump for RST,
218
--                          but without pushes to the stack required for other
219
--                          exceptions.
220
--
221
--  0018    12L15   MAM     Added Rockwell instructions. RMBx/SMBx instructions
222
--                          use to the _RMW_DP microroutine to execute. The BBRx
223
--                          and BBSx instructions use a new microroutine to exe-
224
--                          cute: _BByx_dp_rel.
225
--
226
--  0019    13B16   MAM     Corrected state of Wait in the microcode for WAI. A
227
--                          cut and paste error from M65C02_uPgm_V3a.txt
228
--
229
--------------------------------------------------------------------------------
230
--  Comments
231
--------------------------------------------------------------------------------
232
--
233
--  The microprogram controller being targeted is the F9408A MPC. That control-
234
--  ler provides for sequential execution (FTCH), microroutine subroutines (RTS,
235
--  BSR), multi0way branching (BMW), unconditional externally controlled branch-
236
--  ing (BRV0, BRV1, BRV2, BRV3), and conditional branching using external test
237
--  inputs (BTL0, BTH0, BTL1, BTH1, BTL2, BTH2, BTL3, BTH3). Past use of this
238
--  controller has been focused on using the FTCH, BRV0, BSR, RTS, and BTL0/BTH0
239
--  as the basis of control. An external multiplexer controlled by the microword
240
--  and tied to the T0 test pin has been used for most tests. BRV0 has been used
241
--  in a conventional manner, and as such, it has only been used as an uncondi-
242
--  tional branch to a microprogram address supplied in the microword. No extra-
243
--  ordinary use of these basic control structures has been attempted.
244
--
245
--  With the program and data memory of the target, the M65C02 synthesizable
246
--  microprocessor/microcomputer, external to the core, there is a need to
247
--  implement a memory interface. From an implementation perspective, the exter-
248
--  nal memory interface would need to supply a ready signal so that the M65C02
249
--  logic can capture any input data into the instruction register, IR, one of
250
--  the two internal temporary operand registers, OP1 and OP2, or one of the
251
--  programmer-visible registers of the processor core: A, X, Y, P, or S.
252
--
253
--  If the direct approach to using the F9408A MPC is maintained, a number of
254
--  additional clock cycles will be added to each operation. A discrete logic
255
--  FSM approach for the processor core controller would branch to any number of
256
--  multiple states as needed to minimize the total number of cycles needed to
257
--  implement any instruction of the processor core. A microprogrammed approach
258
--  for implementing the processor core is the objective because it provides a
259
--  more flexible approach to the implementation, and provides an easier path to
260
--  upgrading the instruction set with additional instructions from the Rockwell
261
--  and the Western Design Center versions of the basic processor core. With an
262
--  F9408A MPC, a simple straight forward approach can be taken to the develop-
263
--  ment of the microprogrammed state machine. Without using external logic to
264
--  augment the operation of the F9408A, the resulting micoprogram can be limit-
265
--  ed to simple, single variable tests, which will result in the additional of
266
--  clock cycles to most operations/algorithms. This is not a limitation of the
267
--  F9408A MPC itself, or microprogramming in general, but of the application in
268
--  which the F9408A is included.
269
--
270
--  Mult-way branching in standard FSMs is natural, but is also one of the most
271
--  difficult design aspects of FSMs. Depending on the type of FSM being develp-
272
--  ed, implementing (area and speed) efficient state transition equations for
273
--  FSMs with many branches in many states is difficult and can be very diffi-
274
--  cult to test and debug. The same statement applies to microprogrammed state
275
--  machines, and is one reason why most MPCs have only a limited number of
276
--  instructions which support multi-way branching. However, microprogrammed
277
--  state machines are not limited by the architectural limitation imposed by
278
--  standard MPCs. A controller such as the SAM448 allowed 4-way and/or 16-way
279
--  branching on each state transition. The difficulty in applying such a device
280
--  is the complexity that the state machine designer must deal with on each
281
--  state transition, and the wasted resources that result when the FSM doesn't
282
--  require that capability in each state.
283
--
284
--  The M65C02 supports the reset trap, a non-maskable interrupt (NMI), a mask-
285
--  able interrupt, and the break instruction trap. In most cases, the two
286
--  interrupts are evaluated at the completion of each instruction. However, the
287
--  first instruction after one of these traps/interrupts is always executed. To
288
--  allow for this behavior to be easily implemented, BRV1 is used to initiate
289
--  the execution of a instruction regardless of the state of the NMI and/or IRQ
290
--  signals. BMW is used to test up to three signals and select the appropriate
291
--  action. Thus, most instructions will initiate the fetch of the next instruc-
292
--  tion by terminating their execution with BMW. Using a 2-way table, the BMW
293
--  will either complete the execution of the current instruction and the fetch
294
--  of the next instruction's opcode, or it will branch into the interrupt/traps
295
--  handler microroutine. Single cycle instructions will use BRV3 for the same
296
--  purpose, but implemented in a different manner. The next state for BMW is
297
--  either BRV1 or BRV2. BRV1 is used to complete the execution of an instruc-
298
--  tion and fetch the next instruction's opcode. BRV2 is used to capture the
299
--  interrupt vector. Both IRQ/NMI and BRK start with a BRV2 instruction. BRV3
300
--  performs the same function as BRV1, but the next state is either the first
301
--  state of the next instruction or the interrupt/trap microroutine.
302
--
303
--  The microprogram behavior is based on two assumptions: (1) external memory
304
--  is of a type in which the read data available is related to the address pre-
305
--  sented during the cycle, i.e. asynchronous, no-wait state RAM; and (2) the
306
--  PC control field causes the modification of the PC for the next clock cycle.
307
--  With these two assumptions, the microprogram starts with an unconditional
308
--  jump to a 2-way jump table which initiates the fetch of an instruction op-
309
--  code from memory, or vectors to the microprogram's interrupt handler. The
310
--  BRV1 instruction is used to capture and decode using ROM/RMA the fetched op-
311
--  code. The opcode is used directly as it is being read from memory to provide
312
--  to address a 256-way branch table in the microprogram ROM, and simultaneous-
313
--  ly a second decode ROM/RAM that provides the fixed portion of each instruc-
314
--  tions operation. That is, the 256-way instruction decoder built into
315
--  the microprogram ROM is the decoder for the variable microprogram, and the
316
--  second ROM is the decoder for the fixed microprogram. The variable micropro-
317
--  gram implements the control sequences necessary for an instruction from the
318
--  perspective of the addressing mode of the instruction, and the fixed micro-
319
--  program word defines the ALU operation to be performed when all operands are
320
--  available. The fixed microword is applied to the ALU under control of the
321
--  microprogram. Altogether the number of bits required is 32 for the variable
322
--  microwords, and 24 for the fixed microword, or 56 bits total. (An additional
323
--  8 bits are included in the fixed microword, but they are simply reserved for
324
--  future use should that be required.) For debugging purposes, the opcode is
325
--  also loaded into the Instruction Register (IR).
326
--
327
--  Following the initial word at address 0, there are 31 microwords reserved
328
--  for future use. The intended use of these 31 locations is as a microprogram
329
--  bootloader for the remainder of the microprogram microstore, and for the
330
--  fixed instruction decoder ROM. Thus, at some future date, it may be possible
331
--  to update the microprogram ROMs dynamically from external memory or a serial
332
--  port.
333
--
334
--  The 2-way jump table, which is the target of the first unconditional branch,
335
--  is has two locations which are expected to be accessed by a BMW instruction.
336
--  The first location is labeled as _Nxt to signify that it is the fetch cycle
337
--  for the next opcode. The second location is used to initiate the interrupt
338
--  handler in the event that the external INT signal is asserted. An external
339
--  interrupt handler is expected to determine if an NMI or unmasked IRQ inter-
340
--  rupt should be taken. If INT is asserted, then the BRV2 instruction in the
341
--  second location of the jump table will capture the interrupt vector and jump
342
--  to the microprogram's interrupt handler.
343
--
344
--  Following the jump table are microroutines for handling specific instruc-
345
--  tions, or for handling specific addressing modes. The most significant 256
346
--  locations in the microprogram ROM/RAM constitute the initial microstate for
347
--  each of the 256 possible instruction opcodes. In the present implementation
348
--  only 177/178 of these instructions represent valid instructions. The remain-
349
--  der are executed as NOPs, and are reserved for future use. (The Rockwell
350
--  extensions use an additonal 32 of the opcodes, leaving 46 opcodes undefined.
351
--  Western Design Center, in implementing the W65C802 uses all of the instruc-
352
--  tions to provide emulation of the W65C02 and extend it to 16-bit operation.)
353
--
354
--  A second 2-way jump table is included specifically for the RMW instructions.
355
--  The purpose of the microword with the BRV1 instruction is to complete the
356
--  execution of the current instruction, and simultaneously to fetch and decode
357
--  the next instruction. For most instructions the ALU operation is performed
358
--  during in a terminal microstate with a BRV1 instruction which has Done and
359
--  Reg_WE asserted. For RMW instructions, the ALU operation initiated by the
360
--  Reg_WE control field occurs before the write back to memory of the computed
361
--  result. To use a BMW instruction to jump to the same 2-way jump table used
362
--  for RO or WO multicycle instructions may result in the M65C02 registers,
363
--  including the PSW, being written twice during a cycle. To avoid this poten-
364
--  tial issue, a second BRV1, BRV2 2-way jump accessed by a BMW instruction is
365
--  used for the RMW instructions. The BRV1 microstate in the RMW jump table
366
--  does not include a Reg_WE field control value, but does assert Done. This
367
--  allows the RMW to complete in the same fashion as other multicycle instruc-
368
--  tions, but prevents any of the registers or the PSW from being written more
369
--  than once per instruction cycle.
370
--
371
--  In implementing the microroutines, no attempt was made to combine the micro-
372
--  routines for various addressing modes such as Pre-Indexed and Post-Indexed
373
--  Data Page or Absolute that yield the same result. Therefore, the bit in the
374
--  fixed microword which previously identified the indexe register used by a
375
--  specific opcode has been reused for other purposes. The result of this opti-
376
--  mization is that all of the indexed addressing modes require separate micro-
377
--  routines for correct implementation. All that being the case, the implemen-
378
--  tation of the M65C02 microprogram uses only 256 microwords for instruction
379
--  decode, and an additional 79 microwords to implement the complete micropro-
380
--  gram. Therefore, there remains 177 microwords with which to implement addi-
381
--  tional instructions or capabilities such as bootloading the microprogram
382
--  memory. The current implementation uses approximately 1.88 microwords per
383
--  instruction, and this includes the 78 unimplemented/unused opcodes which the
384
--  M65C02 implements as NOPs. If those opcodes are not included, then a total
385
--  of 257 states, 178 + 79, are used to implement the M65C02 microprogram, or
386
--  1.444 microwords per instruction. The number of microstates per instruction
387
--  are a good measure of the efficiency of the implementation. For virtually
388
--  all instructions, the M65C02, due to its pipelined implementation, saves at
389
--  least one cycle per instruction when compared to the W65C02, R65C02, or the
390
--  original MOS6502 implementations.
391
--
392
--  The test program used for diagnostics and proofing of the implementation is
393
--  averaging 1.88 clock cycles per instruction. This is an improvement of more
394
--  than 40% over a standard implementation of the 6502 instruction set.
395
--
396
--------------------------------------------------------------------------------
397
--------------------------------------------------------------------------------
398
--
399
--  Deleted Comments - 12B11, mam, the implementation no longer follows the
400
--      basic plan for the use of the F9408A MPC as described below. The BRV1
401
--      and BMW instructions are used as described below, but the other modifi-
402
--      cations described below were determined to not be relevant during ini-
403
--      tial testing. Thus, a new plan was developed for the implementation of
404
--      both the core and the microprogram. In the new plan, the F9408A MPC was
405
--      modified (and renamed M65C02_MPC) so that all instructions, under con-
406
--      trol of the microprogram, would wait for the completion of a memory cy-
407
--      cle, or would proceed without waiting. In this manner, the simplicity of
408
--      the F9408A MPC is preserved and operation without wait states can be
409
--      achieved easily. The deleted comments are preserved below for historical
410
--      completeness.
411
--
412
--------------------------------------------------------------------------------
413
--
414
--  Therefore, some extraordinary use of the F9408A MPC branching instructions
415
--  will be required to achieve to goal of reducing the number of clock cycles
416
--  required for instruction processing, while maintaining a microprogrammed
417
--  implementation approach. The first modification is to have the core logic
418
--  recognize when a F9408A branch is active. Fortunately, if the F9408A is not
419
--  executing a FTCH instruction, it is executing a branch instruction. There is
420
--  only one BMW instruction, the F9408A provides a code for which BRVx instruc-
421
--  tions is being executed, and the test input branch instructions can easily
422
--  be detected by the 1 in the MSB of the instruction code.
423
--
424
--  The desired operational change to the behaviour of these branch instructions
425
--  is that when a branch is being executed and a memory cycle is simultaneously
426
--  in progress, logic in the core will inhibit the control fields to the core's
427
--  functional units. (As a standard practice, a 0 control field is a NOP.) In
428
--  this manner, when the external memory transfer acknowledge signal is pro-
429
--  vided, then the desired operation is gated into the functional unit. This
430
--  allows the simultaneous operation of the core logic and the external memory
431
--  interface. Presently, only two of the test inputs of the F9408A MPC are used
432
--  in this application: T0 - connects to Ack, and T1 - connects to ALU Ready.
433
--  In the case of a BTL0 loop waiting for the memory to deliver the instruction
434
--  or the operands, while the Ack is not asserted the F9408A will loop as ex-
435
--  pected, but the microword control fields for the functional units will be
436
--  inhibited, i.e. forced to logic 0, so that on the clock cycle that Ack is
437
--  returned, the functional units will receive the control field values encoded
438
--  into the microword. It is generally expected that the BTL0 loop is a loop to
439
--  itself. Furthermore, since T0 is only connected to a single signal, the in-
440
--  hibit logic discussed above can be activated strictly based on the instruc-
441
--  tion. The T1 pin is connected to a test signal that will not be tested while
442
--  a memory cycle is pending, so no combination of the Ack and ALU Rdy signals
443
--  is required. It is expected that the designer will not initiate a memory
444
--  operation while waiting for a multi-cycel ALU operation to complete.
445
--
446
--  Additional modifications are required for the BRVx instructions, which will
447
--  be used for several different internal functions. The BRV0 instruction will
448
--  be used for conditional direct branching, the BRV1 instruction will be used
449
--  for conditional branching based on the output of the IR decoder ROM. The
450
--  BRV2 instruction will be used for branching to trap and interrupt handlers.
451
--
452
--  When a BRV0 instruction is used, the Ack signal will be used as a control to
453
--  multiplex the proper address onto the BA bus of the F9408A MPC. If a memory
454
--  access is being performed when a BRV0 instruction is used, then Ack will
455
--  gate the present MA address onto the BA bus until Ack is asserted, and then
456
--  the BA field in the microword will be gated onto the F9408A BA bus. This
457
--  will keep the MPC in the same state until the memory responds with Ack. If
458
--  Ack is not asserted and a memory cycle is being performed, then the func-
459
--  tional unit control fields are inhibited.
460
--
461
--  When a BRV1 instruction is used, a BA multiplexer is required but the inputs
462
--  are the addressing mode index from the IR decoder, and the microword address
463
--  bus, MA. In all other respects, the BRV1 instruction performs in the same
464
--  manner as described above for BRV0.
465
--
466
--  The BRV2 instruction is used a bit differently. The Via[1:0] outputs of The
467
--  F9408A are decoded and when found to be a 2'b10, the multi-way pins MW[2:0]
468
--  and the IR BRK instruction signal are used to load {OP2, OP1} with the vec-
469
--  address for Reset, NMI, and IRQ. In this way, the core can branch directly
470
--  the the trap routine in the lower memory area. The assumption is that these
471
--  vectors are located in ROM, (actually, the vectors are direct inputs to the
472
--  MAM6502 processor core.) and the core will branch to a location is lower
473
--  memory where a four byte area is allocated for the JMP abs instruction to
474
--  the interrupt/trap handler.
475
--
476
--  All of these modifications to the behavior of the basic F9408A MPC are pro-
477
--  vided by external logic. The following microprogram reflects the modifica-
478
--  tions described above. The basic organization of the microprogram is:
479
--
480
--      (1) jump table indexed by the address mode index of the IR decoder;
481
--      (2) BMW trap/interrupt/instruction multi-way branch table (mod 8)
482
--      (3) microroutines to complete any multi-byte/multi-cycle instructions;
483
--
484
--------------------------------------------------------------------------------
485
--------------------------------------------------------------------------------
486
--
487
--------------------------------------------------------------------------------
488
-- F9408A Instruction definitions
489
--------------------------------------------------------------------------------
490
 
491
RTS         .asm    0       -- Return from Subroutine
492
BSR         .asm    1       -- Branch to subroutine
493
FTCH        .asm    2       -- Fetch next instruction
494
BMW         .asm    3       -- Branch multi-way
495
BRV0        .asm    4       -- Branch via 0
496
BRV1        .asm    5       -- Branch via 1
497
BRV2        .asm    6       -- Branch via 2
498
BRV3        .asm    7       -- Branch via 3
499
BTH0        .asm    8       -- Branch if T0 is high
500
BTH1        .asm    9       -- Branch if T1 is high
501
BTH2        .asm    10      -- Branch if T2 is high
502
BTH3        .asm    11      -- Branch if T3 is high
503
BTL0        .asm    12      -- Branch if T0 is low
504
BTL1        .asm    13      -- Branch if T1 is low
505
BTL2        .asm    14      -- Branch if T2 is low
506
BTL3        .asm    15      -- Branch if T3 is low
507
 
508
--------------------------------------------------------------------------------
509
-- ROM ( output ) Field definitions
510
--------------------------------------------------------------------------------
511
 
512
Inst        .def    4       -- Instruction
513
BA          .def    9       -- Branch Address
514
Wait        .def    1       -- Conditional Execution Required
515
En          .def    2       -- Enable ALU, and Sample Interrupts
516
NA_Cntl     .def    4       -- Next Address Control Field
517
PC_Cntl     .def    2       -- Program Counter Control Field
518
IO_Cntl     .def    2       -- I/O Cycle Control Field
519
--DI_Cntl     .def    2       -- Data Input Demultiplexer Control Field
520
DIO_Cntl    .def    2       -- Data Input/Output Demux/Mux Control Field
521
--DO_Cntl     .def    2       -- Data Output Multiplexer Control Field
522
Stk_Cntl    .def    2       -- ALU Stack Pointer Control Field
523
RegWE_Cntl  .def    3       -- Register Write Enable (A, X, Y, S, P)
524
PSW_Cntl    .def    1       -- Asserted to Clear D and Set I in PSW
525
 
526
--------------------------------------------------------------------------------
527
-- Constant definitions
528
--------------------------------------------------------------------------------
529
 
530
--  Next Address Control Definitions
531
 
532
PC          .equ    0       -- NA <= PC (default)
533
Inc         .equ    1       -- NA <= PC + 1
534
MAR         .equ    2       -- NA <= MAR + 0
535
Nxt         .equ    3       -- NA <= MAR + 1
536
Stk         .equ    4       -- NA <= SP + 0
537
DPN         .equ    5       -- NA <= {0, OP1} + 0
538
DPX         .equ    6       -- NA <= {0, OP1} + {0, X}
539
DPY         .equ    7       -- NA <= {0, OP1} + {0, Y}
540
LDA         .equ    8       -- NA <= {OP2, OP1} + 0
541
LDAX        .equ    14      -- NA <= {OP2, OP1} + {0, X}
542
LDAY        .equ    15      -- NA <= {OP2, OP1} + {0, Y}
543
 
544
--  Program Counter Control Field
545
 
546
Pls         .equ    1       -- PC <= PC + 1
547
Jmp         .equ    2       -- PC <= NA
548
Rel         .equ    3       -- PC <= PC + (CC ? {{8{DI[7]}}, DI} : 1)
549
 
550
--  Bus Interface Unit Definitions
551
 
552
WR          .equ    1       -- Bus Operand Write
553
RD          .equ    2       -- Bus Operand Read
554
IF          .equ    3       -- Bus Insruction Fetch
555
 
556
--  Memory Data Input Demultiplexer Definitions
557
 
558
ALU         .equ    0       -- M   <= DI
559
OP2         .equ    1       -- OP2 <= DI
560
OP1         .equ    2       -- OP1 <= DI
561
IR          .equ    3       -- IR  <= DI
562
 
563
--  Memory Data Output Multiplexer Definitions
564
 
565
--ALU         .equ    0       -- DO  <= Out
566
PCH         .equ    1       -- DO  <= PCH
567
PCL         .equ    2       -- DO  <= PCL
568
PSW         .equ    3       -- DO  <= PSW (P)
569
 
570
--  ALU Stack Operation Definitions
571
 
572
Psh         .equ    2       -- S <= S - 1
573
Pop         .equ    3       -- S <= S + 1
574
 
575
--  Register Write Enable Control Field Definitions
576
 
577
WE_A        .equ    1       -- Write Enable A
578
WE_X        .equ    2       -- Write Enable X
579
WE_Y        .equ    3       -- Write Enable Y
580
WE_R        .equ    4       -- Write Enable Register - write selected register
581
WE_S        .equ    5       -- Write Enable S
582
WE_P        .equ    6       -- Write Enable P
583
WE_M        .equ    7       -- Write Enable M(emory)
584
 
585
--  Miscellaneous Control Field Definitions
586
 
587
ISR         .equ    1       -- Assert ISR: Clear D, Set I
588
 
589
--------------------------------------------------------------------------------
590
--
591
--  Microprogram Controller Resources
592
--
593
--  T[0]    -   Valid - ALU Operation Complete/Done
594
--  T[1]    -   Unused
595
--  T[2]    -   Unused
596
--  T[3]    -   Unused
597
--
598
--  Via[0]  -   BA, but also waits for the completion of a memory or ALU cycle
599
--  Via[1]  -   Instruction Decoder, effectively functions as a 256 way branch
600
--  Via[2]  -   Samples Vector and loads it into {OP2, OP1}
601
--  Via[3]  -   Instruction Decoder with branch to Interrupt Handler, _Int
602
--
603
--  MW[2:0] -   MW[2] - uP_BA[2]; MW[1] - uP_BA[1]; MW[0] - Int;
604
--
605
--   xx0    -   Instruction Fetch
606
--   xx1    -   Interrupt Trap
607
--
608
--------------------------------------------------------------------------------
609
-- MAM6502 Microprogram Start
610
--------------------------------------------------------------------------------
611
 
612
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
613
 
614
_Start: .org    0
615
    BRV2    _Rst,1,1,,, IF                      -- Load {OP2, OP1} with Vector
616
_Rst:
617
    FTCH    $,1,0,,, RD, OP1                    -- Read Indirect Dst Ptr Lo
618
    FTCH    $,1,0, Nxt, Jmp, RD, OP2            -- Read Indirect Dst Ptr Hi
619
--
620
    BRV1    $,1,1,, Pls, IF, IR                 -- Instruction Fetch
621
 
622
--  this space reserved for future use - boot loader for the microprogram ROMs
623
 
624
--------------------------------------------------------------------------------
625
--------------------------------------------------------------------------------
626
-- 2-Way Jump Table: _Nxt and _Int
627
--------------------------------------------------------------------------------
628
--------------------------------------------------------------------------------
629
-- Instruction Fetch and Execute Microstate
630
--------------------------------------------------------------------------------
631
_Nxt:   .org    32
632
_Psh:
633
_Pop:
634
_Rel:
635
_Imm:
636
    BRV1    _Nxt,1,1,, Pls, IF, IR,, WE_R           -- Instruction Fetch/Execute
637
 
638
--------------------------------------------------------------------------------
639
--  Interrupt Entry - NMI, (unmasked) IRQ (falls through to _BRK)
640
--------------------------------------------------------------------------------
641
 
642
_Int:
643
    BRV2    _Brk,1,1, Stk,, WR, PCH, Psh, WE_R      -- Push PCH, capture Vector
644
 
645
--------------------------------------------------------------------------------
646
--  BRK Entry - BRK #imm (_Int falls through to _Brk, see comment above)
647
--------------------------------------------------------------------------------
648
 
649
_Brk:
650
    FTCH    $,1,0, Stk,, WR, PCL, Psh               -- Push PCL
651
    FTCH    $,1,0, Stk, Jmp, WR, PSW, Psh,, ISR     -- Push P; Clr D, Set I
652
--
653
    FTCH    $,1,0, LDA,, RD, OP1                    -- Read Indirect Dst Ptr Lo
654
    FTCH    $,1,0, Nxt, Jmp, RD, OP2                -- Read Indirect Dst Ptr Hi
655
--
656
    BRV1    $,1,1,, Pls, IF, IR                     -- Instruction Fetch
657
 
658
--------------------------------------------------------------------------------
659
--  Jump To Subroutine - JSR Abs                    (Not interruptable)
660
--------------------------------------------------------------------------------
661
 
662
_JSR:
663
    FTCH    $,1,0,,, IF, OP2                        -- Load Indirect Dst Ptr Lo
664
    FTCH    $,1,0, Stk,, WR, PCH, Psh               -- Push PC Hi
665
    BRV0    _Nxt,1,0, Stk, Jmp, WR, PCL, Psh        -- Push PC Lo
666
 
667
--------------------------------------------------------------------------------
668
--  Return from Interrupt - RTI                     (Not interruptable)
669
--------------------------------------------------------------------------------
670
 
671
_RTI:
672
    FTCH    $,1,0, Stk,, RD, OP1, Pop, WE_P         -- Pop PCL
673
    FTCH    $,1,0, Stk, Jmp, RD, OP2, Pop           -- Pop PCH
674
--
675
    BRV1    $,1,1,, Pls, IF, IR                     -- Next, no Reg_WE, P okay
676
 
677
--------------------------------------------------------------------------------
678
--  Return From Subroutine - RTS                    (Not interruptable)
679
--------------------------------------------------------------------------------
680
 
681
_RTS:
682
    BRV0    _Nxt,1,0, Stk, Jmp, RD, OP2, Pop        -- Pop PCH
683
 
684
--------------------------------------------------------------------------------
685
--  Jump Absolute - JMP  Abs                        (Not interruptable)
686
--------------------------------------------------------------------------------
687
 
688
_Jmp:
689
    BRV0    _Nxt,1,0,, Jmp, IF, OP2
690
 
691
--------------------------------------------------------------------------------
692
--  Jump Indirect - JMP (Abs)                       (Not interruptable)
693
--------------------------------------------------------------------------------
694
 
695
_JmpI:
696
    FTCH    $,1,0,, Pls, IF, OP2                    -- Load Indirect Dst Ptr Lo
697
    FTCH    $,1,0, LDA,, RD, OP1                    -- Read Indirect Dst Ptr Hi
698
    BRV0    _Nxt,1,0, Nxt, Jmp, RD, OP2             -- Goto Next
699
 
700
--------------------------------------------------------------------------------
701
--  Jump Pre-Indexed Indirect - JMP (Abs, X)       (Not interruptable)
702
--------------------------------------------------------------------------------
703
 
704
_JmpXI:
705
    FTCH    $,1,0,, Pls, IF, OP2                    -- Load Indirect Dst Ptr Lo
706
    FTCH    $,1,0, LDAX,, RD, OP1                   -- Read Indirect Dst Ptr Hi
707
    BRV0    _Nxt,1,0, Nxt, Jmp, RD, OP2             -- Goto Next
708
 
709
--------------------------------------------------------------------------------
710
--  Memory Read-Only Data Page Direct - xxx DP
711
--------------------------------------------------------------------------------
712
 
713
_RO_DP:
714
    BMW     _Nxt,1,0, DPN,, RD, OP1                     -- Read DP Mem
715
 
716
-----------------------------------------------------------------------------
717
--  Memory Read-Only Pre-Indexed Data Page Direct - xxx DP, X
718
--------------------------------------------------------------------------------
719
 
720
_RO_DPX:
721
    BMW     _Nxt,1,0, DPX,, RD, OP1                     -- Read DP Mem
722
 
723
--------------------------------------------------------------------------------
724
--  Memory Read-Only Post-Indexed Data Page Direct - xxx DP, Y
725
--------------------------------------------------------------------------------
726
 
727
_RO_DPY:
728
    BMW     _Nxt,1,0, DPY,, RD, OP1                     -- Read DP Mem
729
 
730
------------------------------------------------------------------------------
731
--  Memory Read-Only Data Page Indirect - xxx (DP)
732
--------------------------------------------------------------------------------
733
 
734
_RO_DPI:
735
    FTCH    $,1,0, DPN,, RD, OP1                        -- Read DP Mem Ptr Lo
736
    FTCH    $,1,0, Nxt,, RD, OP2                        -- Read DP Mem Ptr Hi
737
    BMW     _Nxt,1,0, LDA,, RD, OP1                     -- Read Operand
738
 
739
--------------------------------------------------------------------------------
740
--  Memory Read-Only Pre-Indexed Data Page Indirect - xxx (DP, X)
741
--------------------------------------------------------------------------------
742
 
743
_RO_DPXI:
744
    FTCH    $,1,0, DPX,, RD, OP1                    -- Read DP Mem Ptr Lo (DP,X)
745
    FTCH    $,1,0, Nxt,, RD, OP2                        -- Read DP Mem Ptr Hi
746
    BMW     _Nxt,1,0, LDA,, RD, OP1                     -- Read Operand
747
 
748
--------------------------------------------------------------------------------
749
--  Memory Read-Only Post-Indexed Data Page Indirect - xxx (DP), Y
750
--------------------------------------------------------------------------------
751
 
752
_RO_DPIY:
753
    FTCH    $,1,0, DPN,, RD, OP1                        -- Read DP Mem Ptr Lo
754
    FTCH    $,1,0, Nxt,, RD, OP2                        -- Read DP Mem Ptr Hi
755
    BMW     _Nxt,1,0, LDAY,, RD, OP1                    -- Read Operand (DP),Y
756
 
757
--------------------------------------------------------------------------------
758
--  Memory Read-Only Absolute - xxx Abs
759
--------------------------------------------------------------------------------
760
 
761
_RO_Abs:
762
    FTCH    $,1,0,, Pls, IF, OP2                        -- Read Mem Ptr Hi
763
    BMW     _Nxt,1,0, LDA,, RD, OP1                     -- Read Operand
764
 
765
--------------------------------------------------------------------------------
766
--  Memory Read-Only Pre-Indexed Absolute - xxx Abs, X
767
--------------------------------------------------------------------------------
768
 
769
_RO_AbsX:
770
    FTCH    $,1,0,, Pls, IF, OP2                        -- Read Mem Ptr Hi
771
    BMW     _Nxt,1,0, LDAX,, RD, OP1                    -- Read Operand Abs,X
772
 
773
--------------------------------------------------------------------------------
774
--  Memory Read-Only Post-Indexed Absolute - xxx Abs, Y
775
--------------------------------------------------------------------------------
776
 
777
_RO_AbsY:
778
    FTCH    $,1,0,, Pls, IF, OP2                        -- Read Mem Ptr Hi
779
    BMW     _Nxt,1,0, LDAY,, RD, OP1                    -- Read Operand Abs,Y
780
 
781
--------------------------------------------------------------------------------
782
--  Memory Write-Only Data Page Direct - xxx DP
783
--------------------------------------------------------------------------------
784
 
785
_WO_DP:
786
    BMW     _Nxt,1,0, DPN,, WR                          -- Write to DP
787
 
788
-----------------------------------------------------------------------------
789
--  Memory Write-Only Pre-Indexed Data Page Direct - xxx DP, X
790
--------------------------------------------------------------------------------
791
 
792
_WO_DPX:
793
    BMW    _Nxt,1,0, DPX,, WR                          -- Write to DP,X
794
 
795
-----------------------------------------------------------------------------
796
--  Memory Write-Only Post-Indexed Data Page Direct - xxx DP, Y
797
--------------------------------------------------------------------------------
798
 
799
_WO_DPY:
800
    BMW     _Nxt,1,0, DPY,, WR                          -- Write to DP,Y
801
 
802
--------------------------------------------------------------------------------
803
--  Memory Write-Only Data Page Indirect - xxx (DP)
804
--------------------------------------------------------------------------------
805
 
806
_WO_DPI:
807
    FTCH    $,1,0, DPN,, RD, OP1                        -- Read DP Mem Ptr Lo
808
    FTCH    $,1,0, Nxt,, RD, OP2                        -- Read DP Mem Ptr Hi
809
    BMW     _Nxt,1,0, LDA,, WR                          -- Write to (DP)
810
 
811
--------------------------------------------------------------------------------
812
--  Memory Write-Only Data Page Indirect - xxx (DP, X)
813
--------------------------------------------------------------------------------
814
 
815
_WO_DPXI:
816
    FTCH    $,1,0, DPX,, RD, OP1                        -- Read DP Mem Ptr Lo
817
    FTCH    $,1,0, Nxt,, RD, OP2                        -- Read DP Mem Ptr Hi
818
    BMW     _Nxt,1,0, LDA,, WR                          -- Write to (DP)
819
 
820
--------------------------------------------------------------------------------
821
--  Memory Write-Only Post-Indexed Data Page Indirect - xxx (DP), Y
822
--------------------------------------------------------------------------------
823
 
824
_WO_DPIY:
825
    FTCH    $,1,0, DPN,, RD, OP1                        -- Read DP Mem Ptr Lo
826
    FTCH    $,1,0, Nxt,, RD, OP2                        -- Read DP Mem Ptr Hi
827
    BMW     _Nxt,1,0, LDAY,, WR                         -- Write to (DP)
828
 
829
--------------------------------------------------------------------------------
830
--  Memory Write-Only Absolute - xxx Abs
831
--------------------------------------------------------------------------------
832
 
833
_WO_Abs:
834
    FTCH    $,1,0,, Pls, IF, OP2                        -- Read Mem Ptr Hi
835
    BMW     _Nxt,1,0, LDA,, WR                          -- Write to Abs
836
 
837
--------------------------------------------------------------------------------
838
--  Memory Write-Only Pre-Indexed Absolute - xxx Abs, X
839
--------------------------------------------------------------------------------
840
 
841
_WO_AbsX:
842
    FTCH    $,1,0,, Pls, IF, OP2                        -- Read Mem Ptr Hi
843
    BMW     _Nxt,1,0, LDAX,, WR                         -- Write to Abs,X
844
 
845
--------------------------------------------------------------------------------
846
--  Memory Write-Only Post-Indexed Absolute - xxx Abs, Y
847
--------------------------------------------------------------------------------
848
 
849
_WO_AbsY:
850
    FTCH    $,1,0,, Pls, IF, OP2                        -- Read Mem Ptr Hi
851
    BMW     _Nxt,1,0, LDAY,, WR                         -- Write to Abs,Y
852
 
853
--------------------------------------------------------------------------------
854
--  2-way Read-Modify-Write Instruction/Interrupt Jump Table
855
--------------------------------------------------------------------------------
856
 
857
_RMW:       .org    96
858
    BRV1    _RMW,1,1,, Pls, IF, IR                  -- Instruction Fetch/Execute
859
    BRV2    _Brk,1,1, Stk, , WR, PCH, Psh           -- Push PCH, capture Vector
860
 
861
--------------------------------------------------------------------------------
862
--  Memory Read-Modify-Write Data Page Direct - xxx DP
863
--------------------------------------------------------------------------------
864
 
865
_RMW_DP:
866
    FTCH    $,1,0, DPN,, RD, OP1                        -- Read from DP
867
    BMW     _RMW,1,0, MAR,, WR,,,WE_R                   -- Write to DP
868
 
869
--------------------------------------------------------------------------------
870
--  Memory Read-Modify-Write Pre-Indexed Data Page Direct - xxx DP, X
871
--------------------------------------------------------------------------------
872
 
873
_RMW_DPX:
874
    FTCH    $,1,0, DPX,, RD, OP1                        -- Read from DP,X
875
    BMW     _RMW,1,0, MAR,, WR,,,WE_R                   -- Write to DP,X
876
 
877
--------------------------------------------------------------------------------
878
--  Memory Read-Modify-Write Post-Indexed Data Page Direct - xxx DP, Y
879
--------------------------------------------------------------------------------
880
 
881
_RMW_DPY:
882
    FTCH    $,1,0, DPY,, RD, OP1                        -- Read from DP,Y
883
    BMW     _RMW,1,0, MAR,, WR,,,WE_R                   -- Write to DP,Y
884
 
885
--------------------------------------------------------------------------------
886
--  Memory Read-Modify-Write Absolute - xxx Abs
887
--------------------------------------------------------------------------------
888
 
889
_RMW_Abs:
890
    FTCH    $,1,0,, Pls, IF, OP2                        -- Read Mem Ptr Hi
891
    FTCH    $,1,0, LDA,, RD, OP1                        -- Read from Abs
892
    BMW     _RMW,1,0, MAR,, WR,,,WE_R                   -- Write to Abs
893
 
894
--------------------------------------------------------------------------------
895
--  Memory Read-Modify-Write Pre-Indexed Absolute - xxx Abs, X
896
--------------------------------------------------------------------------------
897
 
898
_RMW_AbsX:
899
    FTCH    $,1,0,, Pls, IF, OP2                        -- Read Mem Ptr Hi
900
    FTCH    $,1,0, LDAX,, RD, OP1                       -- Read from Abs,X
901
    BMW     _RMW,1,0, MAR,, WR,,,WE_R                   -- Write to Abs,X
902
 
903
--------------------------------------------------------------------------------
904
--  Memory Read-Modify-Write Post-Indexed Absolute - xxx Abs, Y
905
--------------------------------------------------------------------------------
906
 
907
_RMW_AbsY:
908
    FTCH    $,1,0,, Pls, IF, OP2                        -- Read Mem Ptr Hi
909
    FTCH    $,1,0, LDAY,, RD, OP1                       -- Read from Abs,Y
910
    BMW     _RMW,1,0, MAR,, WR,,,WE_R                   -- Write to Abs,Y
911
 
912
--------------------------------------------------------------------------------
913
--  Rockwell BBRx/BBSx dp,rel instructions
914
--------------------------------------------------------------------------------
915
 
916
_BByx_dp_rel:
917
    FTCH    $,1,0, DPN,, RD, OP1                        -- Read from DP
918
    BRV0    _Nxt,1,0,, Rel, IF, OP1                     -- Read rel value
919
 
920
--------------------------------------------------------------------------------
921
--  End of Microprogram Routines for Normal Instructions
922
--------------------------------------------------------------------------------
923
 
924
_End_uPgm:
925
 
926
--------------------------------------------------------------------------------
927
--  WAI - Wait for Interrupt
928
--------------------------------------------------------------------------------
929
 
930
_WAI:       .org    252     -- Set up 4-way table for WAI instruction
931
    BMW     _WAI,1,0        -- No external interrupts asserted
932
    BRV0    _Int,1,0        -- Int asserted by NMI, do NMI interrupt
933
    BRV0    _Nxt,1,0        -- xIRQ asserted with IRQ_Msk asserted, continue
934
    BRV0    _Int,1,0        -- Int asserted by xIRQ, do IRQ interrupt
935
 
936
_IDEC_Start:    .org    256
937
 
938
--------------------------------------------------------------------------------
939
--  Start of Instruction Decode Table (Entry for each Opcode)
940
--
941
--  Instead of being organized in numerical order, the table is organized by
942
--  rows: the least significant nibble and the most significant nibble of the
943
--  opcode are swapped. This organization more clearly shows the arrangement of
944
--  the addressing modes of the WDC W65C02 microprocessor being emulated. It al-
945
--  so more clearly shows the regularity of the ALU instructions that are imple-
946
--  mented. The implementation of the microprogram is first based on the addres-
947
--  sing mode, and then on the ALU function. Single cycle instructions will be
948
--  easily recognized in the following table because their table entry use the
949
--  BRV3 MPC instruction. Multi-cycle instructions use the BRV0 MPC instruction
950
--  to vector a microroutine in the lower 256 words of the microprogram ROM/RAM.
951
--  Single byte instructions such as BRK, RTS, RTI, and register push/pull in-
952
--  structions (PHA, PLA, PHP, PLP, PHX, PLX, PHY, PLY), and multi-byte instruc-
953
--  tions like JSR abs are implemented with special microroutines that perform
954
--  the necessary stack accesses. The remainder of the microroutines are orga-
955
--  nized by addressing mode, and whether the mode is used in a RO, WO, or RMW
956
--  manner.
957
--
958
--  Microprogram Word Format:
959
--
960
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
961
--
962
--------------------------------------------------------------------------------
963
 
964
--------------------------------------------------------------------------------
965
--  Row 0 : 0x00-0xF0 (All branches/JMPs/JSR implemented as uninterruptable)
966
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
967
--------------------------------------------------------------------------------
968
_BRK_imm:
969
    BRV2    _Brk,1,1, Stk,, WR, PCH, Psh, WE_P      -- Start Break Handler
970
_BPL_rel:
971
    BRV0    _Rel,1,0,, Rel, IF, OP1                 -- Read rel Value
972
_JSR_abs:
973
    BRV0    _JSR,1,0,, Pls, IF, OP1                 -- Read Dst Ptr Lo
974
_BMI_rel:
975
    BRV0    _Rel,1,0,, Rel, IF, OP1                 -- Read rel Value
976
_RTI_imp:
977
    BRV0    _RTI,1,0, Stk,, RD, OP1, Pop            -- Read PSW from Stack
978
_BVC_rel:
979
    BRV0    _Rel,1,0,, Rel, IF, OP1                 -- Read rel Value
980
_RTS_imp:
981
    BRV0    _RTS,1,0, Stk,, RD, OP1, Pop            -- Read PCL from Stack
982
_BVS_rel:
983
    BRV0    _Rel,1,0,, Rel, IF, OP1                 -- Read rel Value
984
_BRA_rel:
985
    BRV0    _Rel,1,0,, Rel, IF, OP1                 -- Read rel Value
986
_BCC_rel
987
    BRV0    _Rel,1,0,, Rel, IF, OP1                 -- Read rel Value
988
_LDY_imm:
989
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read #imm Value
990
_BCS_rel:
991
    BRV0    _Rel,1,0,, Rel, IF, OP1                 -- Read rel Value
992
_CPY_imm:
993
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read #imm Value
994
_BNE_rel:
995
    BRV0    _Rel,1,0,, Rel, IF, OP1                 -- Read rel Value
996
_CPX_imm:
997
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read #imm Value
998
_BEQ_rel:
999
    BRV0    _Rel,1,0,, Rel, IF, OP1                 -- Read rel Value
1000
--------------------------------------------------------------------------------
1001
-- Row 1 : 0x01-0xF1
1002
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1003
--------------------------------------------------------------------------------
1004
_ORA_dpXi:
1005
    BRV0    _RO_DPXI,1,0,, Pls, IF, OP1             -- Read DP Ptr
1006
_ORA_dpiY:
1007
    BRV0    _RO_DPIY,1,0,, Pls, IF, OP1             -- Read DP Ptr
1008
_AND_dpXi:
1009
    BRV0    _RO_DPXI,1,0,, Pls, IF, OP1             -- Read DP Ptr
1010
_AND_dpiY:
1011
    BRV0    _RO_DPIY,1,0,, Pls, IF, OP1             -- Read DP Ptr
1012
_EOR_dpXi:
1013
    BRV0    _RO_DPXI,1,0,, Pls, IF, OP1             -- Read DP Ptr
1014
_EOR_dpiY:
1015
    BRV0    _RO_DPIY,1,0,, Pls, IF, OP1             -- Read DP Ptr
1016
_ADC_dpXi:
1017
    BRV0    _RO_DPXI,1,0,, Pls, IF, OP1             -- Read DP Ptr
1018
_ADC_dpiY:
1019
    BRV0    _RO_DPIY,1,0,, Pls, IF, OP1             -- Read DP Ptr
1020
_STA_dpXi:
1021
    BRV0    _WO_DPXI,1,0,, Pls, IF, OP1             -- Read DP Ptr
1022
_STA_dpiY:
1023
    BRV0    _WO_DPIY,1,0,, Pls, IF, OP1             -- Read DP Ptr
1024
_LDA_dpXi:
1025
    BRV0    _RO_DPXI,1,0,, Pls, IF, OP1             -- Read DP Ptr
1026
_LDA_dpiY:
1027
    BRV0    _RO_DPIY,1,0,, Pls, IF, OP1             -- Read DP Ptr
1028
_CMP_dpXi:
1029
    BRV0    _RO_DPXI,1,0,, Pls, IF, OP1             -- Read DP Ptr
1030
_CMP_dpiY:
1031
    BRV0    _RO_DPIY,1,0,, Pls, IF, OP1             -- Read DP Ptr
1032
_SBC_dpXi:
1033
    BRV0    _RO_DPXI,1,0,, Pls, IF, OP1             -- Read DP Ptr
1034
_SBC_dpiY:
1035
    BRV0    _RO_DPIY,1,0,, Pls, IF, OP1             -- Read DP Ptr
1036
--------------------------------------------------------------------------------
1037
-- Row 2 : 0x02-0xF2
1038
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1039
--------------------------------------------------------------------------------
1040
_NOP_02:
1041
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1042
_ORA_dpi:
1043
    BRV0    _RO_DPI,1,0,, Pls, IF, OP1              -- Read DP
1044
_NOP_22:
1045
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1046
_AND_dpi:
1047
    BRV0    _RO_DPI,1,0,, Pls, IF, OP1              -- Read DP
1048
_NOP_42:
1049
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1050
_EOR_dpi:
1051
    BRV0    _RO_DPI,1,0,, Pls, IF, OP1              -- Read DP
1052
_NOP_62:
1053
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1054
_ADC_dpi:
1055
    BRV0    _RO_DPI,1,0,, Pls, IF, OP1              -- Read DP
1056
_NOP_82:
1057
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1058
_STA_dpi:
1059
    BRV0    _WO_DPI,1,0,, Pls, IF, OP1              -- Read DP
1060
_LDX_imm:
1061
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read #imm Value
1062
_LDA_dpi:
1063
    BRV0    _RO_DPI,1,0,, Pls, IF, OP1              -- Read DP
1064
_NOP_C2:
1065
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1066
_CMP_dpi:
1067
    BRV0    _RO_DPI,1,0,, Pls, IF, OP1              -- Read DP
1068
_NOP_E2:
1069
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1070
_SBC_dpi:
1071
    BRV0    _RO_DPI,1,0,, Pls, IF, OP1              -- Read DP
1072
--------------------------------------------------------------------------------
1073
-- Row 3 : 0x03-0xF3
1074
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1075
--------------------------------------------------------------------------------
1076
_NOP_03:
1077
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1078
_NOP_13:
1079
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1080
_NOP_23:
1081
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1082
_NOP_33:
1083
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1084
_NOP_43:
1085
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1086
_NOP_53:
1087
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1088
_NOP_63:
1089
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1090
_NOP_73:
1091
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1092
_NOP_83:
1093
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1094
_NOP_93:
1095
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1096
_NOP_A3:
1097
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1098
_NOP_B3:
1099
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1100
_NOP_C3:
1101
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1102
_NOP_D3:
1103
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1104
_NOP_E3:
1105
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1106
_NOP_F3:
1107
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1108
--------------------------------------------------------------------------------
1109
-- Row 4 : 0x04-0xF4
1110
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1111
--------------------------------------------------------------------------------
1112
_TSB_dp:
1113
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1114
_TRB_dp:
1115
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1116
_BIT_dp:
1117
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1118
_BIT_dpX:
1119
    BRV0    _RO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1120
_NOP_44:
1121
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1122
_NOP_54:
1123
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1124
_STZ_dp:
1125
    BRV0    _WO_DP,1,0,, Pls, IF, OP1               -- Read DP
1126
_STZ_dpX:
1127
    BRV0    _WO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1128
_STY_dp:
1129
    BRV0    _WO_DP,1,0,, Pls, IF, OP1               -- Read DP
1130
_STY_dpX:
1131
    BRV0    _WO_DPX,1,0,, Pls, IR, OP1              -- Read DP
1132
_LDY_dp:
1133
    BRV0    _RO_DP,1,0,, Pls, IR, OP1               -- Read DP
1134
_LDY_dpX:
1135
    BRV0    _RO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1136
_CPY_dp:
1137
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1138
_NOP_D4:
1139
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1140
_CPX_dp:
1141
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1142
_NOP_F4:
1143
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1144
--------------------------------------------------------------------------------
1145
-- Row 5 : 0x05-0xF5
1146
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1147
--------------------------------------------------------------------------------
1148
_ORA_dp:
1149
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1150
_ORA_dpX:
1151
    BRV0    _RO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1152
_AND_dp:
1153
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1154
_AND_dpX:
1155
    BRV0    _RO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1156
_EOR_dp:
1157
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1158
_EOR_dpX:
1159
    BRV0    _RO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1160
_ADC_dp:
1161
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1162
_ADC_dpX:
1163
    BRV0    _RO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1164
_STA_dp:
1165
    BRV0    _WO_DP,1,0,, Pls, IF, OP1               -- Read DP
1166
_STA_dpX:
1167
    BRV0    _WO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1168
_LDA_dp:
1169
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1170
_LDA_dpX:
1171
    BRV0    _RO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1172
_CMP_dp:
1173
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1174
_CMP_dpX:
1175
    BRV0    _RO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1176
_SBC_dp:
1177
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1178
_SBC_dpX:
1179
    BRV0    _RO_DPX,1,0,, Pls, IF, OP1              -- Read DP
1180
--------------------------------------------------------------------------------
1181
-- Row 6 : 0x06-0xF6
1182
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1183
--------------------------------------------------------------------------------
1184
_ASL_dp:
1185
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1186
_ASL_dpX:
1187
    BRV0    _RMW_DPX,1,0,, Pls, IF, OP1             -- Read DP
1188
_ROL_dp:
1189
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1190
_ROL_dpX:
1191
    BRV0    _RMW_DPX,1,0,, Pls, IF, OP1             -- Read DP
1192
_LSR_dp:
1193
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1194
_LSR_dpX:
1195
    BRV0    _RMW_DPX,1,0,, Pls, IF, OP1             -- Read DP
1196
_ROR_dp:
1197
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1198
_ROR_dpX:
1199
    BRV0    _RMW_DPX,1,0,, Pls, IF, OP1             -- Read DP
1200
_STX_dp:
1201
    BRV0    _WO_DP,1,0,, Pls, IF, OP1               -- Read DP
1202
_STX_dpY:
1203
    BRV0    _WO_DPY,1,0,, Pls, IF, OP1              -- Read DP
1204
_LDX_dp:
1205
    BRV0    _RO_DP,1,0,, Pls, IF, OP1               -- Read DP
1206
_LDX_dpY:
1207
    BRV0    _RO_DPY,1,0,, Pls, IF, OP1              -- Read DP
1208
_DEC_dp:
1209
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1210
_DEC_dpX:
1211
    BRV0    _RMW_DPX,1,0,, Pls, IF, OP1             -- Read DP
1212
_INC_dp:
1213
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1214
_INC_dpX:
1215
    BRV0    _RMW_DPX,1,0,, Pls, IF, OP1             -- Read DP
1216
--------------------------------------------------------------------------------
1217
-- Row 7 : 0x07-0xF7 (Rockwell Instructions: RMBx/SMBx dp)
1218
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1219
--------------------------------------------------------------------------------
1220
_RMB0_dp:
1221
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1222
_RMB1_dp:
1223
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1224
_RMB2_dp:
1225
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1226
_RMB3_dp:
1227
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1228
_RMB4_dp:
1229
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1230
_RMB5_dp:
1231
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1232
_RMB6_dp:
1233
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1234
_RMB7_dp:
1235
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1236
_SMB0_dp:
1237
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1238
_SMB1_dp:
1239
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1240
_SMB2_dp:
1241
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1242
_SMB3_dp:
1243
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1244
_SMB4_dp:
1245
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1246
_SMB5_dp:
1247
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1248
_SMB6_dp:
1249
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1250
_SMB7_dp:
1251
    BRV0    _RMW_DP,1,0,, Pls, IF, OP1              -- Read DP
1252
--------------------------------------------------------------------------------
1253
-- Row 8 : 0x08-0xF8
1254
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1255
--------------------------------------------------------------------------------
1256
_PHP:
1257
    BRV0    _Psh,1,0, Stk,, WR,, Psh                -- Push P
1258
_CLC:
1259
    BRV3    $,1,3,, Pls, IF, IR,, WE_P              -- Clear Carry Flag
1260
_PLP:
1261
    BRV0    _Pop,1,0, Stk,, RD, OP1, Pop            -- Pop P
1262
_SEC:
1263
    BRV3    $,1,3,, Pls, IF, IR,, WE_P              -- Set Carry Flag
1264
_PHA:
1265
    BRV0    _Psh,1,0, Stk,, WR,, Psh                -- Push A
1266
_CLI:
1267
    BRV1    $,1,1,, Pls, IF, IR,, WE_P              -- Clear Interrupt Mask Flg
1268
_PLA:
1269
    BRV0    _Pop,1,0, Stk,, RD, OP1, Pop            -- Pop A
1270
_SEI:
1271
    BRV1    $,1,1,, Pls, IF, IR,, WE_P              -- Set Interrupt Mask Flag
1272
_DEY:
1273
    BRV3    $,1,3,, Pls, IF, IR,, WE_Y              -- Decrement Y
1274
_TYA:
1275
    BRV3    $,1,3,, Pls, IF, IR,, WE_A              -- Transfer Y to A
1276
_TAY:
1277
    BRV3    $,1,3,, Pls, IF, IR,, WE_Y              -- Transfer A to Y
1278
_CLV:
1279
    BRV3    $,1,3,, Pls, IF, IR,, WE_P              -- Clear oVerflow Flag
1280
_INY:
1281
    BRV3    $,1,3,, Pls, IF, IR,, WE_Y              -- Increment Y
1282
_CLD:
1283
    BRV3    $,1,3,, Pls, IF, IR,, WE_P              -- Clear Decimal Mode Flag
1284
_INX:
1285
    BRV3    $,1,3,, Pls, IF, IR,, WE_X              -- Increment X
1286
_SED:
1287
    BRV3    $,1,3,, Pls, IF, IR,, WE_P              -- Set Decimal Mode Flag
1288
--------------------------------------------------------------------------------
1289
-- Row 9 : 0x09-0xF9
1290
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1291
--------------------------------------------------------------------------------
1292
_ORA_imm:
1293
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read Immediate Operand
1294
_ORA_absY:
1295
    BRV0    _RO_AbsY,1,0,, Pls, IF, OP1             -- Read Mem Ptr Lo
1296
_AND_imm:
1297
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read Immediate Operand
1298
_AND_absY:
1299
    BRV0    _RO_AbsY,1,0,, Pls, IF, OP1             -- Read Mem Ptr Lo
1300
_EOR_imm:
1301
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read Immediate Operand
1302
_EOR_absY:
1303
    BRV0    _RO_AbsY,1,0,, Pls, IF, OP1             -- Read Mem Ptr Lo
1304
_ADC_imm:
1305
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read Immediate Operand
1306
_ADC_absY:
1307
    BRV0    _RO_AbsY,1,0,, Pls, IF, OP1             -- Read Mem Ptr Lo
1308
_BIT_imm:
1309
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read Immediate Operand
1310
_STA_absY:
1311
    BRV0    _WO_AbsY,1,0,, Pls, IF, OP1             -- Read Mem Ptr Lo
1312
_LDA_imm:
1313
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read Immediate Operand
1314
_LDA_absY:
1315
    BRV0    _RO_AbsY,1,0,, Pls, IF, OP1             -- Read Mem Ptr Lo
1316
_CMP_imm:
1317
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read Immediate Operand
1318
_CMP_absY:
1319
    BRV0    _RO_AbsY,1,0,, Pls, IF, OP1             -- Read Mem Ptr Lo
1320
_SBC_imm:
1321
    BMW     _Imm,1,0,, Pls, IF, OP1                 -- Read Immediate Operand
1322
_SBC_absY:
1323
    BRV0    _RO_AbsY,1,0,, Pls, IF, OP1             -- Read Mem Ptr Lo
1324
--------------------------------------------------------------------------------
1325
-- Row A : 0x0A-0xFA
1326
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1327
--------------------------------------------------------------------------------
1328
_ASL_A:
1329
    BRV3    $,1,3,, Pls, IF, IR,, WE_A              -- Arithmetic Shift A Left
1330
_INC_A:
1331
    BRV3    $,1,3,, Pls, IF, IR,, WE_A              -- Increment A
1332
_ROL_A:
1333
    BRV3    $,1,3,, Pls, IF, IR,, WE_A              -- Rotate A Left
1334
_DEC_A:
1335
    BRV3    $,1,3,, Pls, IF, IR,, WE_A              -- Decrement A
1336
_LSR_A:
1337
    BRV3    $,1,3,, Pls, IF, IR,, WE_A              -- Logical Shift A Right
1338
_PHY:
1339
    BRV0    _Psh,1,0, Stk,, WR,, Psh                -- Push Y
1340
_ROR_A:
1341
    BRV3    $,1,3,, Pls, IF, IR,, WE_A              -- Rotate A Right
1342
_PLY:
1343
    BRV0    _Pop,1,0, Stk,, RD, OP1, Pop            -- Pop Y
1344
_TXA:
1345
    BRV3    $,1,3,, Pls, IF, IR,, WE_A              -- Transfer X to A
1346
_TXS:
1347
    BRV3    $,1,3,, Pls, IF, IR,, WE_S              -- Transfer X to S
1348
_TAX:
1349
    BRV3    $,1,3,, Pls, IF, IR,, WE_X              -- Transfer A to X
1350
_TSX:
1351
    BRV3    $,1,3,, Pls, IF, IR,, WE_X              -- Transfer S to X
1352
_DEX:
1353
    BRV3    $,1,3,, Pls, IF, IR,, WE_X              -- Decrement X
1354
_PHX:
1355
    BRV0    _Psh,1,0, Stk,, WR,, Psh                -- Push X
1356
_NOP:   -- the real NOP
1357
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip True NOP Instruction
1358
_PLX:
1359
    BRV0    _Pop,1,0, Stk,, RD, OP1, Pop            -- Pop X
1360
--------------------------------------------------------------------------------
1361
-- Row B : 0x0B-0xFB
1362
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1363
--------------------------------------------------------------------------------
1364
_NOP_0B:
1365
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1366
_NOP_1B:
1367
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1368
_NOP_2B:
1369
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1370
_NOP_3B:
1371
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1372
_NOP_4B:
1373
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1374
_NOP_5B:
1375
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1376
_NOP_6B:
1377
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1378
_NOP_7B:
1379
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1380
_NOP_8B:
1381
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1382
_NOP_9B:
1383
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1384
_NOP_AB:
1385
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1386
_NOP_BB:
1387
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1388
_WAI_CB:
1389
    BRV0    _WAI,1,0                                -- Wait for Interrupt
1390
_STP_DB:
1391
    BRV0    $,0,0                                   -- Stop execution
1392
_NOP_EB:
1393
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1394
_NOP_FB:
1395
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1396
--------------------------------------------------------------------------------
1397
-- Row C : 0x0C-0xFC
1398
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1399
--------------------------------------------------------------------------------
1400
_TSB_abs:
1401
    BRV0    _RMW_Abs,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1402
_TRB_abs:
1403
    BRV0    _RMW_Abs,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1404
_BIT_abs:
1405
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1406
_BIT_absX:
1407
    BRV0    _RO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1408
_JMP_abs:
1409
    BRV0    _Jmp,1,0,, Pls, IF, OP1                 -- Read Dst Ptr Lo
1410
_NOP_5C:
1411
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1412
_JMP_absi:
1413
    BRV0    _JmpI,1,0,, Pls, IF, OP1                -- Read Dst Ptr Lo
1414
_JMP_absXi:
1415
    BRV0    _JmpXI,1,0,, Pls, IF, OP1               -- Read Dst Ptr Lo
1416
_STY_abs:
1417
    BRV0    _WO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1418
_STZ_abs:
1419
    BRV0    _WO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1420
_LDY_abs:
1421
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1422
_LDY_absX:
1423
    BRV0    _RO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1424
_CPY_abs:
1425
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1426
_NOP_DC:
1427
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1428
_CPX_abs:
1429
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1430
_NOP_FC:
1431
    BRV3    $,1,3,, Pls, IF, IR                     -- Skip Invalid Instruction
1432
--------------------------------------------------------------------------------
1433
-- Row D : 0x0D-0xFD
1434
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1435
--------------------------------------------------------------------------------
1436
_ORA_abs:
1437
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1438
_ORA_absX:
1439
    BRV0    _RO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1440
_AND_abs:
1441
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1442
_AND_absX:
1443
    BRV0    _RO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1444
_EOR_abs:
1445
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1446
_EOR_absX:
1447
    BRV0    _RO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1448
_ADC_abs:
1449
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1450
_ADC_absX:
1451
    BRV0    _RO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1452
_STA_abs:
1453
    BRV0    _WO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1454
_STA_absX:
1455
    BRV0    _WO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1456
_LDA_abs:
1457
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1458
_LDA_absX:
1459
    BRV0    _RO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1460
_CMP_abs:
1461
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1462
_CMP_absX:
1463
    BRV0    _RO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1464
_SBC_abs:
1465
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1466
_SBC_absX:
1467
    BRV0    _RO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1468
--------------------------------------------------------------------------------
1469
-- Row E : 0x0E-0xFE
1470
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1471
--------------------------------------------------------------------------------
1472
_ASL_abs:
1473
    BRV0    _RMW_Abs,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1474
_ASL_absX:
1475
    BRV0    _RMW_AbsX,1,0,, Pls, IF, OP1            -- Read Dst Ptr Lo
1476
_ROL_abs:
1477
    BRV0    _RMW_Abs,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1478
_ROL_absX:
1479
    BRV0    _RMW_AbsX,1,0,, Pls, IF, OP1            -- Read Dst Ptr Lo
1480
_LSR_abs:
1481
    BRV0    _RMW_Abs,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1482
_LSR_absX:
1483
    BRV0    _RMW_AbsX,1,0,, Pls, IF, OP1            -- Read Dst Ptr Lo
1484
_ROR_abs:
1485
    BRV0    _RMW_Abs,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1486
_ROR_absX:
1487
    BRV0    _RMW_AbsX,1,0,, Pls, IF, OP1            -- Read Dst Ptr Lo
1488
_STX_abs:
1489
    BRV0    _WO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1490
_STZ_absX:
1491
    BRV0    _WO_AbsX,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1492
_LDX_abs:
1493
    BRV0    _RO_Abs,1,0,, Pls, IF, OP1              -- Read Dst Ptr Lo
1494
_LDX_absY:
1495
    BRV0    _RO_AbsY,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1496
_DEC_abs:
1497
    BRV0    _RMW_Abs,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1498
_DEC_absX:
1499
    BRV0    _RMW_AbsX,1,0,, Pls, IF, OP1            -- Read Dst Ptr Lo
1500
_INC_abs:
1501
    BRV0    _RMW_Abs,1,0,, Pls, IF, OP1             -- Read Dst Ptr Lo
1502
_INC_absX:
1503
    BRV0    _RMW_AbsX,1,0,, Pls, IF, OP1            -- Read Dst Ptr Lo
1504
--------------------------------------------------------------------------------
1505
-- Row F : 0x0F-0xFF (Rockwell Instructions: BBRx/BBSx dp,rel)
1506
--  I   BA, Wt, En, NA, PC, IO, DI, SP, Reg_WE, ISR
1507
--------------------------------------------------------------------------------
1508
_BBR0_dp_rel:
1509
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1510
_BBR1_dp_rel:
1511
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1512
_BBR2_dp_rel:
1513
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1514
_BBR3_dp_rel:
1515
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1516
_BBR4_dp_rel:
1517
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1518
_BBR5_dp_rel:
1519
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1520
_BBR6_dp_rel:
1521
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1522
_BBR7_dp_rel:
1523
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1524
_BBS0_dp_rel:
1525
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1526
_BBS1_dp_rel:
1527
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1528
_BBS2_dp_rel:
1529
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1530
_BBS3_dp_rel:
1531
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1532
_BBS4_dp_rel:
1533
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1534
_BBS5_dp_rel:
1535
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1536
_BBS6_dp_rel:
1537
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1538
_BBS7_dp_rel:
1539
    BRV0    _BByx_dp_rel,1,0,, Pls, IF, OP1         -- Read DP
1540
--------------------------------------------------------------------------------
1541
--  End of Instruction Decode Table
1542
--------------------------------------------------------------------------------
1543
 
1544
_Last:  .org 512
1545
 
1546
_end:

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.