XiPU uROM Generator
URomData Class Reference

This class contains a whole generated microcode for all instructions. More...

#include <uromdata.h>

Collaboration diagram for URomData:
[legend]

Public Member Functions

 URomData ()
 Default constructor for creating an empty uROM opcode table. More...
 
void addInstruction (const Instruction &instruction)
 
bool saveFiles (const QString &urom0Path, const QString &urom1Path)
 

Static Public Attributes

static const int INSTRUCTION_QUANTITY = 256
 Support only for 256 opcodes. More...
 
static const int INSTRUCTION_CYCLE_QUANTITY = 16
 Every instruction can get only 16 steps. More...
 
static const int ADDRESS_FLAG_C_POSITION = 12
 Position of the carry bit received from ALU to the control unit. More...
 
static const int ADDRESS_FLAG_Z_POSITION = 13
 Position of the zero bit received from ALU to the control unit. More...
 
static const int UROM_SIZE = 32768
 uROM size for low and high banks More...
 

Private Attributes

QVector< QVector< unsigned char > > data = { QVector<unsigned char>(UROM_SIZE), QVector<unsigned char>(UROM_SIZE) }
 Data container for low and high banks. More...
 

Detailed Description

This class contains a whole generated microcode for all instructions.

Definition at line 22 of file uromdata.h.

Constructor & Destructor Documentation

◆ URomData()

URomData::URomData ( )

Default constructor for creating an empty uROM opcode table.

Definition at line 15 of file uromdata.cpp.

16 {
17  this->data[0].fill(0);
18  this->data[1].fill(0);
19 }
QVector< QVector< unsigned char > > data
Data container for low and high banks.
Definition: uromdata.h:40

References data.

Member Function Documentation

◆ addInstruction()

void URomData::addInstruction ( const Instruction instruction)

Add an instruction to the uROM opcode table

Parameters
instructionInstruction to add

Definition at line 26 of file uromdata.cpp.

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 }
@ 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
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
static const int ADDRESS_FLAG_C_POSITION
Position of the carry bit received from ALU to the control unit.
Definition: uromdata.h:28

References Instruction::AB, Instruction::ABXY, ADDRESS_FLAG_C_POSITION, ADDRESS_FLAG_Z_POSITION, Instruction::Any, data, Instruction::getArg0(), Instruction::getArg1(), Instruction::getC(), UCode::getCode0(), UCode::getCode1(), Instruction::getOpcode(), Instruction::getStepList(), Step::getUCode(), Instruction::getZ(), INSTRUCTION_CYCLE_QUANTITY, and INSTRUCTION_QUANTITY.

Referenced by URom::URom().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveFiles()

bool URomData::saveFiles ( const QString &  urom0Path,
const QString &  urom1Path 
)

Save a binary microcode to files

Parameters
urom0PathPath to the first output file
urom1PathPath to the second output file
Returns
Status of the save operation

Definition at line 82 of file uromdata.cpp.

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 }
static const int UROM_SIZE
uROM size for low and high banks
Definition: uromdata.h:31

References data, and UROM_SIZE.

Referenced by URom::saveFiles().

Here is the caller graph for this function:

Field Documentation

◆ ADDRESS_FLAG_C_POSITION

const int URomData::ADDRESS_FLAG_C_POSITION = 12
static

Position of the carry bit received from ALU to the control unit.

Definition at line 28 of file uromdata.h.

Referenced by addInstruction().

◆ ADDRESS_FLAG_Z_POSITION

const int URomData::ADDRESS_FLAG_Z_POSITION = 13
static

Position of the zero bit received from ALU to the control unit.

Definition at line 29 of file uromdata.h.

Referenced by addInstruction().

◆ data

QVector<QVector<unsigned char> > URomData::data = { QVector<unsigned char>(UROM_SIZE), QVector<unsigned char>(UROM_SIZE) }
private

Data container for low and high banks.

Definition at line 40 of file uromdata.h.

Referenced by addInstruction(), saveFiles(), and URomData().

◆ INSTRUCTION_CYCLE_QUANTITY

const int URomData::INSTRUCTION_CYCLE_QUANTITY = 16
static

Every instruction can get only 16 steps.

Definition at line 26 of file uromdata.h.

Referenced by addInstruction().

◆ INSTRUCTION_QUANTITY

const int URomData::INSTRUCTION_QUANTITY = 256
static

Support only for 256 opcodes.

Definition at line 25 of file uromdata.h.

Referenced by addInstruction(), and URom::URom().

◆ UROM_SIZE

const int URomData::UROM_SIZE = 32768
static

uROM size for low and high banks

Definition at line 31 of file uromdata.h.

Referenced by saveFiles().


The documentation for this class was generated from the following files: