save method
void
save()
Implementation
void save() async {
if (Z.inInterrupt) {
return;
}
Z.inInterrupt = true;
//calculates the local jump offset (ref 4.7)
int jumpToLabelOffset(int jumpByte) {
if (BinaryHelper.isSet(jumpByte, 6)) {
//single byte offset
return BinaryHelper.bottomBits(jumpByte, 6);
} else {
//create the 14-bit offset value with next byte
final val = (BinaryHelper.bottomBits(jumpByte, 6) << 8) | readb();
//convert to Dart signed int (14-bit MSB is the sign bit)
return ((val & 0x2000) == 0x2000) ? -(16384 - val) : val;
}
}
final jumpByte = readb();
bool branchOn = BinaryHelper.isSet(jumpByte, 7);
final offset = jumpToLabelOffset(jumpByte);
if (branchOn) {
final result = await Z.sendIO({
"command": ioCommands.save,
"file_data": Quetzal.save(programCounter+ (offset - 2))
});
Z.inInterrupt = false;
if (result) programCounter += offset - 2;
Z.callAsync(Z.runIt);
} else {
final result = await Z
.sendIO({"command": ioCommands.save, "file_data": Quetzal.save(programCounter)});
Z.inInterrupt = false;
if (!result) programCounter += offset - 2;
Z.callAsync(Z.runIt);
}
}