68kcounter
Version:
68000 ASM source code cycle counter
70 lines (69 loc) • 1.89 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const evaluate_1 = __importDefault(require("../parse/evaluate"));
const nodes_1 = require("../parse/nodes");
const syntax_1 = require("../syntax");
/**
* Get byte size of directive statement
*/
function directiveSize({ opcode: { op, qualifier }, operands }, vars) {
// DC:
if (op.name === syntax_1.Directives.DC && qualifier) {
if (qualifier.name === syntax_1.Qualifiers.B) {
return operandBytes(operands);
}
else {
return operands.length * qualifierBytes[qualifier.name];
}
}
if (op.name === syntax_1.Directives.DB) {
return operandBytes(operands);
}
if (op.name === syntax_1.Directives.DW) {
return operands.length * 2;
}
if (op.name === syntax_1.Directives.DL) {
return operands.length * 4;
}
// DCB / DS:
if ((op.name === syntax_1.Directives.DCB || op.name === syntax_1.Directives.DS) &&
qualifier &&
operands[0]) {
const n = evaluate_1.default(operands[0].text, vars);
if (n) {
const bytes = qualifierBytes[qualifier.name];
return bytes * n;
}
}
return 0;
}
exports.default = directiveSize;
const qualifierBytes = {
B: 1,
W: 2,
L: 4,
S: 4,
D: 8,
Q: 8,
X: 12,
};
/**
* Get byte count for a list of operands on dc.b / db
*
* Handles quoted strings as well as individual byte values.
*/
function operandBytes(operands) {
let count = 0;
for (const arg of operands) {
if (arg instanceof nodes_1.StringNode) {
count += arg.value.length;
}
else {
count++;
}
}
return count;
}