aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorFilippos Karapetis2014-02-17 12:05:40 +0200
committerFilippos Karapetis2014-02-17 12:05:40 +0200
commit715a5f9bbec102c58fd145a65cc2c678813bf4f9 (patch)
treee6b7b437d6e1d214927baaa821871f1a3b55bb78 /engines/sci
parented400d57fce69a88c9cdaf6dde03c89e22925968 (diff)
downloadscummvm-rg350-715a5f9bbec102c58fd145a65cc2c678813bf4f9.tar.gz
scummvm-rg350-715a5f9bbec102c58fd145a65cc2c678813bf4f9.tar.bz2
scummvm-rg350-715a5f9bbec102c58fd145a65cc2c678813bf4f9.zip
SCI: Adapt the segment and offset getters/setters for SCI3
This is by no means complete, but it's a good start. It is based on an earlier discussion on the subject, and it allows us to use the highest two bits from the segment for offset addresses
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/engine/vm_types.cpp37
-rw-r--r--engines/sci/engine/vm_types.h25
2 files changed, 44 insertions, 18 deletions
diff --git a/engines/sci/engine/vm_types.cpp b/engines/sci/engine/vm_types.cpp
index 5327dd1a2e..00b55c64b3 100644
--- a/engines/sci/engine/vm_types.cpp
+++ b/engines/sci/engine/vm_types.cpp
@@ -28,6 +28,43 @@
namespace Sci {
+SegmentId reg_t::getSegment() const {
+ if (getSciVersion() <= SCI_VERSION_2_1) {
+ return _segment;
+ } else {
+ // Return the lower 14 bits of the segment
+ return (_segment & 0x3FFF);
+ }
+}
+
+void reg_t::setSegment(SegmentId segment) {
+ if (getSciVersion() <= SCI_VERSION_2_1) {
+ _segment = segment;
+ } else {
+ // Set the lower 14 bits of the segment, and preserve the upper 2 ones for the offset
+ _segment = (_segment & 0xC000) | (segment & 0x3FFF);
+ }
+}
+
+uint32 reg_t::getOffset() const {
+ if (getSciVersion() <= SCI_VERSION_2_1) {
+ return _offset;
+ } else {
+ // Return the lower 16 bits from the offset, and the 17th and 18th bits from the segment
+ return ((_segment & 0xC000) << 2) | _offset;
+ }
+}
+
+void reg_t::setOffset(uint32 offset) {
+ if (getSciVersion() <= SCI_VERSION_2_1) {
+ _offset = offset;
+ } else {
+ // Store the lower 16 bits in the offset, and the 17th and 18th bits in the segment
+ _offset = offset & 0xFFFF;
+ _segment = ((offset & 0x30000) >> 2) | (_segment & 0x3FFF);
+ }
+}
+
reg_t reg_t::lookForWorkaround(const reg_t right, const char *operation) const {
SciTrackOriginReply originReply;
SciWorkaroundSolution solution = trackOriginAndFindWorkaround(0, arithmeticWorkarounds, &originReply);
diff --git a/engines/sci/engine/vm_types.h b/engines/sci/engine/vm_types.h
index 22bd8beaa1..a181bf19cd 100644
--- a/engines/sci/engine/vm_types.h
+++ b/engines/sci/engine/vm_types.h
@@ -35,36 +35,25 @@ struct reg_t {
SegmentId _segment;
uint16 _offset;
- inline SegmentId getSegment() const {
- return _segment;
- }
-
- inline void setSegment(SegmentId segment) {
- _segment = segment;
- }
-
- inline uint16 getOffset() const {
- return _offset;
- }
-
- inline void setOffset(uint16 offset) {
- _offset = offset;
- }
+ SegmentId getSegment() const;
+ void setSegment(SegmentId segment);
+ uint32 getOffset() const;
+ void setOffset(uint32 offset);
inline void incOffset(int16 offset) {
setOffset(getOffset() + offset);
}
inline bool isNull() const {
- return (_offset | getSegment()) == 0;
+ return (getOffset() | getSegment()) == 0;
}
inline uint16 toUint16() const {
- return _offset;
+ return (uint16)getOffset();
}
inline int16 toSint16() const {
- return (int16)_offset;
+ return (int16)getOffset();
}
bool isNumber() const {