added instruction functionality
This commit is contained in:
parent
483a16c194
commit
d4754a048d
9 changed files with 754 additions and 170 deletions
80
simulator_SIC_XE/include/utils.h
Normal file
80
simulator_SIC_XE/include/utils.h
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
// ==============================
|
||||
// SIC/XE Utility Functions
|
||||
// ==============================
|
||||
|
||||
// Instruction bit extraction utilities
|
||||
inline int getXBit(int b2) {
|
||||
return (b2 & 0x80) ? 1 : 0;
|
||||
}
|
||||
|
||||
inline int getBPBits(int b2) {
|
||||
return (b2 >> 5) & 0x03;
|
||||
}
|
||||
|
||||
enum class AddressingMode {
|
||||
IMMEDIATE,
|
||||
INDIRECT,
|
||||
SIMPLE,
|
||||
SIC_DIRECT,
|
||||
INVALID
|
||||
};
|
||||
|
||||
// Get addressing mode from ni bits
|
||||
AddressingMode getAddressingMode(int ni);
|
||||
|
||||
|
||||
// convert to signed 24-bit integer
|
||||
inline int toSIC24(int value) {
|
||||
value &= 0xFFFFFF;
|
||||
if (value & 0x800000) {
|
||||
value -= 0x1000000;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
inline int setCC(int sw, int cc) {
|
||||
sw &= ~CC_MASK;
|
||||
sw |= (cc & CC_MASK);
|
||||
return sw;
|
||||
}
|
||||
|
||||
inline int sic_comp(int a, int b, int sw) {
|
||||
int sa = toSIC24(a);
|
||||
int sb = toSIC24(b);
|
||||
|
||||
int cc;
|
||||
if (sa < sb) {
|
||||
cc = CC_LT;
|
||||
} else if (sa == sb) {
|
||||
cc = CC_EQ;
|
||||
} else {
|
||||
cc = CC_GT;
|
||||
}
|
||||
|
||||
return setCC(sw, cc);
|
||||
}
|
||||
|
||||
inline int sic_comp(double a, double b, int sw) {
|
||||
int cc;
|
||||
if (a < b) {
|
||||
cc = CC_LT;
|
||||
} else if (a == b) {
|
||||
cc = CC_EQ;
|
||||
} else {
|
||||
cc = CC_GT;
|
||||
}
|
||||
|
||||
return setCC(sw, cc);
|
||||
}
|
||||
|
||||
|
||||
inline int getCC(int sw) {
|
||||
return sw & CC_MASK;
|
||||
}
|
||||
|
||||
#endif // UTILS_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue