XiPU uROM Generator
uromdata.cpp
Go to the documentation of this file.
1 /*
2  * Author: Pawel Jablonski
3  * E-mail: pj@xirx.net
4  * WWW: xirx.net
5  * GIT: git.xirx.net
6  *
7  * License: You can use this code however you like
8  * but leave information about the original author.
9  * Code is free for non-commercial and commercial use.
10  */
11 
12 #include "uromdata.h"
13 
14 //! Default constructor for creating an empty uROM opcode table
16 {
17  this->data[0].fill(0);
18  this->data[1].fill(0);
19 }
20 
21 /**
22  * Add an instruction to the uROM opcode table
23  *
24  * @param instruction Instruction to add
25  */
26 void URomData::addInstruction(const Instruction &instruction)
27 {
28  int opcodeWidth = 1;
29 
30  // Calculate how many consecutive opcodes the instruction uses
31  opcodeWidth *= ((instruction.getArg0() == Instruction::Arg::AB) ? 2 : 1);
32  opcodeWidth *= ((instruction.getArg0() == Instruction::Arg::ABXY) ? 4 : 1);
33 
34  opcodeWidth *= ((instruction.getArg1() == Instruction::Arg::AB) ? 2 : 1);
35  opcodeWidth *= ((instruction.getArg1() == Instruction::Arg::ABXY) ? 4 : 1);
36 
37  // Calculate how many steps is used by the instruction
38  int stepQuantity = qMin(instruction.getStepList().size(), INSTRUCTION_CYCLE_QUANTITY);
39 
40  // Add instruction entrys to the opcode table
41  for(int i = 0; i < opcodeWidth; i++)
42  {
43  for(int s = 0; s < stepQuantity; s++)
44  {
45  // Calculate the base offset of the entry
46  int offsetBase = ((static_cast<int>(s) * INSTRUCTION_QUANTITY) + static_cast<int>(instruction.getOpcode()) + i);
47  Step step = instruction.getStepList().at(s);
48 
49  // Fill only entries where the carry and the zero flags fit to the selected by instruction
50  for(int c = 0; c < 2; c++)
51  {
52  for(int z = 0; z < 2; z++)
53  {
54  if(!((instruction.getC() == Instruction::Flag::Any) || (static_cast<int>(instruction.getC()) == c)))
55  {
56  continue;
57  }
58 
59  if(!((instruction.getZ() == Instruction::Flag::Any) || (static_cast<int>(instruction.getZ()) == z)))
60  {
61  continue;
62  }
63 
64  int offset = (offsetBase + (c << ADDRESS_FLAG_C_POSITION) + (z << ADDRESS_FLAG_Z_POSITION));
65 
66  this->data[0][offset] = step.getUCode().getCode0();
67  this->data[1][offset] = step.getUCode().getCode1();
68  }
69  }
70  }
71  }
72 }
73 
74 /**
75  * Save a binary microcode to files
76  *
77  * @param urom0Path Path to the first output file
78  * @param urom1Path Path to the second output file
79  *
80  * @return Status of the save operation
81  */
82 bool URomData::saveFiles(const QString &urom0Path, const QString &urom1Path)
83 {
84  QFile urom0File(urom0Path);
85 
86  // Try to save the first output file
87  if(urom0File.open(QIODevice::WriteOnly))
88  {
89  urom0File.write(reinterpret_cast<const char *>(this->data[0].constData()), UROM_SIZE);
90  urom0File.close();
91  }
92  else
93  {
94  return(false);
95  }
96 
97  QFile urom1File(urom1Path);
98 
99  // Try to save the second output file
100  if(urom1File.open(QIODevice::WriteOnly))
101  {
102  urom1File.write(reinterpret_cast<const char *>(this->data[1].constData()), UROM_SIZE);
103  urom1File.close();
104  }
105  else
106  {
107  return(false);
108  }
109 
110  return(true);
111 }
112 
This class contains atomic steps for the control unit of defined instruction.
Definition: instruction.h:21
@ Any
Accept both values.
Arg getArg0() const
Definition: instruction.cpp:74
@ ABXY
Main and auxiliary registers.
@ AB
Only main registers.
Flag getZ() const
unsigned char getOpcode() const
Definition: instruction.cpp:64
Arg getArg1() const
Definition: instruction.cpp:84
const QList< Step > & getStepList() const
Flag getC() const
Definition: step.h:24
const UCode & getUCode() const
Definition: step.cpp:46
unsigned char getCode0() const
Definition: ucode.cpp:41
unsigned char getCode1() const
Definition: ucode.cpp:51
static const int INSTRUCTION_CYCLE_QUANTITY
Every instruction can get only 16 steps.
Definition: uromdata.h:26
URomData()
Default constructor for creating an empty uROM opcode table.
Definition: uromdata.cpp:15
static const int ADDRESS_FLAG_Z_POSITION
Position of the zero bit received from ALU to the control unit.
Definition: uromdata.h:29
static const int INSTRUCTION_QUANTITY
Support only for 256 opcodes.
Definition: uromdata.h:25
bool saveFiles(const QString &urom0Path, const QString &urom1Path)
Definition: uromdata.cpp:82
static const int UROM_SIZE
uROM size for low and high banks
Definition: uromdata.h:31
void addInstruction(const Instruction &instruction)
Definition: uromdata.cpp:26
static const int ADDRESS_FLAG_C_POSITION
Position of the carry bit received from ALU to the control unit.
Definition: uromdata.h:28
QVector< QVector< unsigned char > > data
Data container for low and high banks.
Definition: uromdata.h:40