Example #1
0
        public static FieldAccess <ushort> GetSub(Compact cpt, int mode)
        {
            switch (mode)
            {
            case 0:
                return(new FieldAccess <ushort>(() => cpt.Core.baseSub, v => cpt.Core.baseSub = v));

            case 2:
                return(new FieldAccess <ushort>(() => cpt.Core.baseSub_off, v => cpt.Core.baseSub_off = v));

            case 4:
                return(new FieldAccess <ushort>(() => cpt.Core.actionSub, v => cpt.Core.actionSub = v));

            case 6:
                return(new FieldAccess <ushort>(() => cpt.Core.actionSub_off, v => cpt.Core.actionSub_off = v));

            case 8:
                return(new FieldAccess <ushort>(() => cpt.Core.getToSub, v => cpt.Core.getToSub = v));

            case 10:
                return(new FieldAccess <ushort>(() => cpt.Core.getToSub_off, v => cpt.Core.getToSub_off = v));

            case 12:
                return(new FieldAccess <ushort>(() => cpt.Core.extraSub, v => cpt.Core.extraSub = v));

            case 14:
                return(new FieldAccess <ushort>(() => cpt.Core.extraSub_off, v => cpt.Core.extraSub_off = v));

            default:
                throw new InvalidOperationException(string.Format("Invalid Mode ({0})", mode));
            }
        }
Example #2
0
        public DisplayedText LowTextManager(uint textNum, ushort width, ushort logicNum, byte color, bool center)
        {
            GetText(textNum);
            DisplayedText textInfo = DisplayText(_textBuffer.ToString(), null, center, width, color);

            uint    compactNum = Logic.FIRST_TEXT_COMPACT;
            Compact cpt        = _skyCompact.FetchCpt((ushort)compactNum);

            while (cpt.Core.status != 0)
            {
                compactNum++;
                cpt = _skyCompact.FetchCpt((ushort)compactNum);
            }

            cpt.Core.flag = (ushort)(compactNum - Logic.FIRST_TEXT_COMPACT + FirstTextBuffer);

            SkyEngine.ItemList[cpt.Core.flag] = textInfo.TextData;

            cpt.Core.logic  = logicNum;
            cpt.Core.status = Logic.ST_LOGIC | Logic.ST_FOREGROUND | Logic.ST_RECREATE;
            cpt.Core.screen = (ushort)Logic.ScriptVariables[Logic.SCREEN];

            textInfo.CompactNum = (ushort)compactNum;
            return(textInfo);
        }
Example #3
0
        public void FnPointerText(uint pointedId, ushort mouseX, ushort mouseY)
        {
            var ptrComp = _skyCompact.FetchCpt((ushort)pointedId);
            var text    = LowTextManager(ptrComp.Core.cursorText, Logic.TEXT_MOUSE_WIDTH, Logic.L_CURSOR, 242, false);

            Logic.ScriptVariables[Logic.CURSOR_ID] = text.CompactNum;
            if (Logic.ScriptVariables[Logic.MENU] != 0)
            {
                _mouseOfsY = Logic.TOP_LEFT_Y - 2;
                if (mouseX < 150)
                {
                    _mouseOfsX = Logic.TOP_LEFT_X + 24;
                }
                else
                {
                    _mouseOfsX = Logic.TOP_LEFT_X - 8 - text.TextWidth;
                }
            }
            else
            {
                _mouseOfsY = Logic.TOP_LEFT_Y - 10;
                if (mouseX < 150)
                {
                    _mouseOfsX = Logic.TOP_LEFT_X + 13;
                }
                else
                {
                    _mouseOfsX = Logic.TOP_LEFT_X - 8 - text.TextWidth;
                }
            }
            Compact textCompact = _skyCompact.FetchCpt(text.CompactNum);

            LogicCursor(textCompact, mouseX, mouseY);
        }
Example #4
0
        private bool FnFetchPlace(uint id, uint b, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)id);

            _scriptVariables[RESULT] = cpt.Core.place;
            return(true);
        }
Example #5
0
        private bool FnSetMegaSet(uint mega, uint setNo, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)mega);

            cpt.Core.megaSet = (ushort)(setNo * NEXT_MEGA_SET);
            return(true);
        }
Example #6
0
        private bool FnGetTo(uint targetPlaceId, uint mode, uint c)
        {
            _compact.Core.upFlag = (ushort)mode; // save mode for action script
            _compact.Core.mode  += 4;            // next level up
            Compact cpt = _skyCompact.FetchCpt(_compact.Core.place);

            if (cpt == null)
            {
                // TODO: warning("can't find _compact's getToTable. Place compact is NULL");
                return(false);
            }
            var raw = _skyCompact.FetchCptRaw(cpt.Core.getToTableId);

            if (raw == null)
            {
                //TODO:  warning("Place compact's getToTable is NULL");
                return(false);
            }

            var getToTable = new UShortAccess(raw, 0);

            while (getToTable.Value != targetPlaceId)
            {
                getToTable.Offset += 4;
            }

            // get new script
            SkyCompact.GetSub(_compact, _compact.Core.mode).Field = getToTable[1];
            SkyCompact.GetSub(_compact, (ushort)(_compact.Core.mode + 2)).Field = 0;

            return(false); // drop out of script
        }
Example #7
0
        private bool FnChangeName(uint id, uint textNo, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)id);

            cpt.Core.cursorText = (ushort)textNo;
            return(true);
        }
Example #8
0
        private bool FnSendFastSync(uint mega, uint sync, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)mega);

            cpt.Core.sync = (ushort)(sync & 0xffff);
            return(true);
        }
Example #9
0
        private bool FnSendRequest(uint target, uint scr, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)target);

            cpt.Core.request = (ushort)(scr & 0xffff);
            return(false);
        }
Example #10
0
        private bool FnClearRequest(uint target, uint b, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)target);

            cpt.Core.request = 0;
            return(true);
        }
Example #11
0
        private void Stopped()
        {
            // waiting for another mega to move or give-up trying
            //
            // this mode will always be set up from a special script
            // that will be one level higher than the script we
            // would wish to restart from

            Compact cpt = _skyCompact.FetchCpt(_compact.Core.waitingFor);

            if (cpt != null)
            {
                if (cpt.Core.mood == 0 && Collide(cpt))
                {
                    return;
                }
            }

            // we are free, continue processing the script

            // restart script one level below
            SkyCompact.GetSub(_compact, _compact.Core.mode - 2).Field = 0;
            _compact.Core.waitingFor = 0xffff;

            _compact.Core.logic = L_SCRIPT;
            LogicScript();
        }
Example #12
0
        private bool FnPersonHere(uint id, uint room, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)id);

            _scriptVariables[RESULT] = cpt.Core.screen == room ? 1U : 0;
            return(true);
        }
Example #13
0
        private bool FnMouseOn(uint a, uint b, uint c)
        {
            //switch on the mouse highlight
            Compact cpt = _skyCompact.FetchCpt((ushort)a);

            cpt.Core.status |= ST_MOUSE;
            return(true);
        }
Example #14
0
        private bool FnSort(uint mega, uint b, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)mega);

            cpt.Core.status &= 0xfff8;
            cpt.Core.status |= ST_SORT;
            return(true);
        }
Example #15
0
        private bool FnUnhighlight(uint item, uint b, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)item);

            cpt.Core.frame--;
            cpt.Core.getToFlag = 0;
            return(true);
        }
Example #16
0
        private bool FnAltSetAlternate(uint target, uint scr, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)target);

            cpt.Core.alt   = (ushort)(scr & 0xffff);
            cpt.Core.logic = L_ALT;
            return(false);
        }
Example #17
0
        private bool GetGridValues(uint x, uint y, uint width, Compact cpt, out byte resGrid, out int resBitNum, out uint resWidth)
        {
            int bitPos;

            resGrid   = 0;
            resBitNum = 0;
            resWidth  = 0;
            if (y < TopLeftY)
            {
                return(false); // off screen
            }
            y  -= TopLeftY;
            y >>= 3; // convert to blocks
            if (y >= Screen.GameScreenHeight >> 3)
            {
                return(false); // off screen
            }
            bitPos = (int)(y * 40);
            width++;
            x >>= 3; // convert to blocks

            if (x < TopLeftX >> 3)
            {
                // at least partially off screen
                if (x + width < TopLeftX >> 3)
                {
                    return(false); // completely off screen
                }
                width -= (TopLeftX >> 3) - x;
                x      = 0;
            }
            else
            {
                x -= TopLeftX >> 3;
            }

            if (Screen.GameScreenWidth >> 3 <= x)
            {
                return(false);                           // off screen
            }
            if (Screen.GameScreenWidth >> 3 < x + width) // partially off screen
            {
                width = (Screen.GameScreenWidth >> 3) - x;
            }

            bitPos += (int)x;
            System.Diagnostics.Debug.Assert((_gridConvertTable[cpt.Core.screen] >= 0) && (_gridConvertTable[cpt.Core.screen] < TotNoGrids));
            resGrid = (byte)_gridConvertTable[cpt.Core.screen];

            var tmpBits = 0x1F - (bitPos & 0x1F);

            bitPos   &= ~0x1F; // divide into dword address and bit number
            bitPos   += tmpBits;
            resBitNum = bitPos;
            resWidth  = width;
            return(true);
        }
Example #18
0
        private bool FnNoSpritesA6(uint us, uint b, uint c)
        {
            // stop the compact printing
            // remove foreground, background & sort
            Compact cpt = _skyCompact.FetchCpt((ushort)us);

            cpt.Core.status &= 0xfff8;
            return(true);
        }
Example #19
0
        private bool FnNewBackground(uint sprite, uint b, uint c)
        {
            // Make sprite a background sprite
            Compact cpt = _skyCompact.FetchCpt((ushort)sprite);

            cpt.Core.status &= 0xfff8;
            cpt.Core.status |= ST_BACKGROUND;
            return(true);
        }
Example #20
0
        private bool FnTheyStartSub(uint mega, uint scr, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)mega);

            cpt.Core.mode += 4;
            SkyCompact.GetSub(cpt, cpt.Core.mode).Field = (ushort)(scr & 0xffff);
            SkyCompact.GetSub(cpt, (ushort)(cpt.Core.mode + 2)).Field = (ushort)(scr >> 16);
            return(true);
        }
Example #21
0
 public void LogicCursor(Compact textCompact, ushort mouseX, ushort mouseY)
 {
     textCompact.Core.xcood = (ushort)(mouseX + _mouseOfsX);
     textCompact.Core.ycood = (ushort)(mouseY + _mouseOfsY);
     if (textCompact.Core.ycood < Logic.TOP_LEFT_Y)
     {
         textCompact.Core.ycood = Logic.TOP_LEFT_Y;
     }
 }
Example #22
0
        public ushort DoAutoRoute(Compact cpt)
        {
            var cptScreen = (byte)cpt.Core.screen;
            var cptWidth = (byte)SkyCompact.GetMegaSet(cpt).gridWidth;
            InitWalkGrid(cptScreen, cptWidth);

            byte startX, startY, destX, destY;
            short initStaX, initStaY, initDestX, initDestY;

            ClipCoordX(cpt.Core.xcood, out startX, out initStaX);
            ClipCoordY(cpt.Core.ycood, out startY, out initStaY);
            ClipCoordX(cpt.Core.arTargetX, out destX, out initDestX);
            ClipCoordY(cpt.Core.arTargetY, out destY, out initDestY);

            var raw = _skyCompact.FetchCptRaw(cpt.Core.animScratchId);
            Array.Clear(raw, 0, 64);
            var routeDest = new UShortAccess(raw, 0);
            if ((startX == destX) && (startY == destY))
                return 2;

            var routeGrid = new UShortAccess(_routeGrid, 0);
            if (routeGrid[(destY + 1) * RouteGridWidth + destX + 1] != 0)
            {
                //if ((cpt == &Sky::SkyCompact::foster) && (cptScreen == 12) && (destX == 2) && (destY == 14)) {
                if (_skyCompact.CptIsId(cpt, (ushort)CptIds.Foster) && (cptScreen == 12) && (destX == 2) &&
                    (destY == 14))
                {
                    /* workaround for Scriptbug #1043047
                       In screen 12 (the pipe factory) Joey can block Foster's target
                       coordinates (2/14). This is normally not too tragic, but in the
                       scene when foster gets thrown out by Lamb (first time you enter
                       the pipe factory), the game would enter an infinite loop. */
                    routeGrid[(destY + 1) * RouteGridWidth + destX + 1] = 0;
                    // hide this part joey from the grid
                }
                else
                    return 1; // AR destination is an unaccessible block
            }

            if (!CalcWalkGrid(startX, startY, destX, destY))
                return 1; // can't find route to block

            var routeData = MakeRouteData(destX, destY);
            // the route is done.
            // if there was an initial x movement (due to clipping) tag it onto the start
            routeData = CheckInitMove(routeData, initStaX);

            byte cnt = 0;
            do
            {
                routeDest[cnt] = routeData[cnt];
                routeDest[cnt + 1] = routeData[cnt + 1];
                cnt += 2;
            } while (routeData[cnt - 2] != 0);
            return 0;
        }
Example #23
0
        private bool FnAssignBase(uint id, uint scr, uint c)
        {
            Compact cpt = _skyCompact.FetchCpt((ushort)id);

            cpt.Core.mode        = C_BASE_MODE;
            cpt.Core.logic       = L_SCRIPT;
            cpt.Core.baseSub     = (ushort)(scr & 0xffff);
            cpt.Core.baseSub_off = (ushort)(scr >> 16);
            return(true);
        }
Example #24
0
        public UShortAccess GetGrafixPtr(Compact cpt)
        {
            var gfxBase = FetchCptRaw(cpt.Core.grafixProgId);

            if (gfxBase == null)
            {
                return(null);
            }

            return(new UShortAccess(gfxBase, cpt.Core.grafixProgPos * 2));
        }
Example #25
0
        public void Engine()
        {
            do
            {
                var    raw       = _skyCompact.FetchCptRaw((ushort)_scriptVariables[LOGIC_LIST_NO]);
                var    logicList = new UShortAccess(raw, 0);
                ushort id;
                while ((id = logicList[0]) != 0)
                {
                    logicList.Offset += 2;
                    // 0 means end of list
                    if (id == 0xffff)
                    {
                        // Change logic data address
                        raw       = _skyCompact.FetchCptRaw(logicList[0]);
                        logicList = new UShortAccess(raw, 0);
                        continue;
                    }

                    _scriptVariables[CUR_ID] = id;
                    _compact = _skyCompact.FetchCpt(id);

                    // check the id actually wishes to be processed
                    if ((_compact.Core.status & (1 << 6)) == 0)
                    {
                        continue;
                    }

                    // ok, here we process the logic bit system

                    if ((_compact.Core.status & (1 << 7)) != 0)
                    {
                        _skyGrid.RemoveObjectFromWalk(_compact);
                    }

                    Debug.Instance.Logic(_compact.Core.logic);
                    _logicTable[_compact.Core.logic]();

                    if ((_compact.Core.status & (1 << 7)) != 0)
                    {
                        _skyGrid.ObjectToWalk(_compact);
                    }

                    // a sync sent to the compact is available for one cycle
                    // only. that cycle has just ended so remove the sync.
                    // presumably the mega has just reacted to it.
                    _compact.Core.sync = 0;
                }
                // usually this loop is run only once, it'll only be run a second time if the game
                // script just asked the user to enter a copy protection code.
                // this is done to prevent the copy protection screen from flashing up.
                // (otherwise it would be visible for 1/50 second)
            } while (CheckProtection());
        }
Example #26
0
        public void ObjectToWalk(Compact cpt)
        {
            int  bitNum;
            uint width;
            byte gridIdx;

            if (GetGridValues(cpt, out gridIdx, out bitNum, out width))
            {
                ObjectToWalk(gridIdx, bitNum, width);
            }
        }
Example #27
0
        private bool FnMouseOff(uint a, uint b, uint c)
        {
            //switch off the mouse highlight
            Compact cpt = _skyCompact.FetchCpt((ushort)a);

            unchecked
            {
                cpt.Core.status &= (ushort)~ST_MOUSE;
            }
            return(true);
        }
Example #28
0
        private bool FnHighlight(uint itemNo, uint pen, uint c)
        {
            pen -= 11;
            pen ^= 1;
            pen += 241;
            Compact textCompact = _skyCompact.FetchCpt((ushort)itemNo);
            var     sprData     = SkyEngine.ItemList[textCompact.Core.flag];

            _skyText.ChangeTextSpriteColor(sprData, (byte)pen);
            return(true);
        }
Example #29
0
        public void RemoveGrid(uint x, uint y, uint width, Compact cpt)
        {
            int  resBitPos;
            uint resWidth;
            byte resGridIdx;

            if (GetGridValues(x, y, width, cpt, out resGridIdx, out resBitPos, out resWidth))
            {
                RemoveObjectFromWalk(resGridIdx, resBitPos, resWidth);
            }
        }
Example #30
0
        public void PlotGrid(uint x, uint y, uint width, Compact cpt)
        {
            int  resBitPos;
            uint resWidth;
            byte resGridIdx;

            if (GetGridValues(x, y, width - 1, cpt, out resGridIdx, out resBitPos, out resWidth))
            {
                ObjectToWalk(resGridIdx, resBitPos, resWidth);
            }
        }
Example #31
0
        public UShortAccess GetTurnTable(Compact cpt, ushort dir)
        {
            if (dir > 4)
            {
                throw new ArgumentOutOfRangeException("dir", string.Format("No TurnTable ({0}) in MegaSet ({1})", dir, cpt.Core.megaSet));
            }

            var m         = GetMegaSet(cpt);
            var turnTable = FetchCptRaw(m.turnTableId);

            return(new UShortAccess(turnTable, 10 * dir));
        }
Example #32
0
 public void ObjectToWalk(Compact cpt)
 {
     int bitNum;
     uint width;
     byte gridIdx;
     if (GetGridValues(cpt, out gridIdx, out bitNum, out width))
         ObjectToWalk(gridIdx, bitNum, width);
 }
Example #33
0
 public void LogicCursor(Compact textCompact, ushort mouseX, ushort mouseY)
 {
     textCompact.Core.xcood = (ushort)(mouseX + _mouseOfsX);
     textCompact.Core.ycood = (ushort)(mouseY + _mouseOfsY);
     if (textCompact.Core.ycood < Logic.TOP_LEFT_Y)
         textCompact.Core.ycood = Logic.TOP_LEFT_Y;
 }
Example #34
0
        private void DrawSprite(byte[] spriteInfo, Compact sprCompact)
        {
            if (spriteInfo == null)
            {
                // TODO: warning("Screen::drawSprite Can't draw sprite. Data %d was not loaded", sprCompact.frame >> 6);
                sprCompact.Core.status = 0;
                return;
            }
            var sprDataFile = ServiceLocator.Platform.ToStructure<DataFileHeader>(spriteInfo, 0);
            _sprWidth = sprDataFile.s_width;
            _sprHeight = sprDataFile.s_height;
            _maskX1 = _maskX2 = 0;
            var spriteData = (sprCompact.Core.frame & 0x3F) * sprDataFile.s_sp_size;
            spriteData += ServiceLocator.Platform.SizeOf<DataFileHeader>();
            var spriteY = sprCompact.Core.ycood + sprDataFile.s_offset_y - TopLeftY;
            if (spriteY < 0)
            {
                spriteY = -spriteY;
                if (_sprHeight <= (uint)spriteY)
                {
                    _sprWidth = 0;
                    return;
                }
                _sprHeight -= (ushort)spriteY;
                spriteData += sprDataFile.s_width * spriteY;
                spriteY = 0;
            }
            else
            {
                var botClip = GameScreenHeight - sprDataFile.s_height - spriteY;
                if (botClip < 0)
                {
                    botClip = -botClip;
                    if (_sprHeight <= (uint)botClip)
                    {
                        _sprWidth = 0;
                        return;
                    }
                    _sprHeight -= (ushort)botClip;
                }
            }
            _sprY = (uint)spriteY;
            var spriteX = sprCompact.Core.xcood + sprDataFile.s_offset_x - TopLeftX;
            if (spriteX < 0)
            {
                spriteX = -spriteX;
                if (_sprWidth <= (uint)spriteX)
                {
                    _sprWidth = 0;
                    return;
                }
                _sprWidth -= (ushort)spriteX;
                _maskX1 = spriteX;
                spriteX = 0;
            }
            else
            {
                var rightClip = GameScreenWidth - (sprDataFile.s_width + spriteX);
                if (rightClip < 0)
                {
                    rightClip = -rightClip + 1;
                    if (_sprWidth <= (uint)rightClip)
                    {
                        _sprWidth = 0;
                        return;
                    }
                    _sprWidth -= (ushort)rightClip;
                    _maskX2 = rightClip;
                }
            }
            _sprX = (uint)spriteX;
            var screenPtr = _sprY * GameScreenWidth + _sprX;
            if ((_sprHeight > 192) || (_sprY > 192))
            {
                _sprWidth = 0;
                return;
            }
            if ((_sprX + _sprWidth > 320) || (_sprY + _sprHeight > 192))
            {
                // TODO: warning("Screen::drawSprite fatal error: got x = %d, y = %d, w = %d, h = %d", _sprX, _sprY, _sprWidth, _sprHeight);
                _sprWidth = 0;
                return;
            }

            for (ushort cnty = 0; cnty < _sprHeight; cnty++)
            {
                for (ushort cntx = 0; cntx < _sprWidth; cntx++)
                    if (spriteInfo[spriteData + cntx + _maskX1] != 0)
                        Current[screenPtr + cntx] = spriteInfo[spriteData + cntx + _maskX1];
                spriteData += _sprWidth + _maskX2 + _maskX1;
                screenPtr += GameScreenWidth;
            }
            // Convert the sprite coordinate/size values to blocks for vertical mask and/or vector to game
            _sprWidth += (ushort)(_sprX + GridW - 1);
            _sprHeight += (ushort)(_sprY + GridH - 1);

            _sprX >>= GridWShift;
            _sprWidth >>= GridWShift;
            _sprY >>= GridHShift;
            _sprHeight >>= GridHShift;

            _sprWidth -= (ushort)_sprX;
            _sprHeight -= (ushort)_sprY;
        }
Example #35
0
 public ushort GetId(Compact cpt)
 {
     var len = _compacts.GetLength(0);
     for (int i = 0; i < len; i++)
     {
         var len2 = _compacts[i].Length;
         for (int j = 0; j < len2; j++)
         {
             if (Equals(_compacts[i][j]?.Data, cpt))
             {
                 return (ushort)((i << 12) | j);
             }
         }
     }
     return 0;
 }
Example #36
0
 private bool GetGridValues(Compact cpt, out byte resGrid, out int resBitNum, out uint resWidth)
 {
     var width = SkyCompact.GetMegaSet(cpt).gridWidth;
     return GetGridValues(cpt.Core.xcood, cpt.Core.ycood, width, cpt, out resGrid, out resBitNum, out resWidth);
 }
Example #37
0
 /// <summary>
 /// Needed for some workaround where the engine has to check if it's currently processing joey, for example
 /// </summary>
 /// <param name="cpt"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool CptIsId(Compact cpt, ushort id)
 {
     return cpt == FetchCpt(id);
 }
Example #38
0
 public void RemoveGrid(uint x, uint y, uint width, Compact cpt)
 {
     int resBitPos;
     uint resWidth;
     byte resGridIdx;
     if (GetGridValues(x, y, width, cpt, out resGridIdx, out resBitPos, out resWidth))
         RemoveObjectFromWalk(resGridIdx, resBitPos, resWidth);
 }
Example #39
0
 /// <summary>
 ///     Gets the n'th mega set specified by a megaSet from a Compact object.
 /// </summary>
 /// <param name="cpt">Compact object.</param>
 /// <returns>the n'th mega set specified by a megaSet from a Compact object</returns>
 public static MegaSet GetMegaSet(Compact cpt)
 {
     switch (cpt.Core.megaSet)
     {
         case 0:
             return cpt.Core.megaSet0;
         case NextMegaSet:
             return cpt.Core.megaSet1;
         case NextMegaSet * 2:
             return cpt.Core.megaSet2;
         case NextMegaSet * 3:
             return cpt.Core.megaSet3;
         default:
             throw new InvalidOperationException(string.Format("Invalid MegaSet ({0})", cpt.Core.megaSet));
     }
 }
Example #40
0
        public FieldAccess<ushort> GetCompactElem(Compact cpt, ushort off)
        {
            ushort compactSize = (ushort)GetCompactField.Length;
            ushort megasetSize = (ushort)GetMegaSetField.Length;
            ushort turntableSize = 100;

            if (off < compactSize)
                return new FieldAccess<ushort>(() => GetCompactField[off](cpt), v => SetCompactField[off](cpt, v));
            off -= compactSize;

            if (off < megasetSize)
                return new FieldAccess<ushort>(() => GetMegaSetField[off](cpt.Core.megaSet0),
                    v => SetMegaSetField[off](cpt.Core.megaSet0, v));

            off -= megasetSize;
            if (off < turntableSize)
                return new FieldAccess<ushort>(() => FetchCptRaw(cpt.Core.megaSet0.turnTableId).ToUInt16(off / 2),
                    v => FetchCptRaw(cpt.Core.megaSet0.turnTableId).WriteUInt16(off / 2, v));

            off -= turntableSize;
            if (off < megasetSize)
                return new FieldAccess<ushort>(() => GetMegaSetField[off](cpt.Core.megaSet1),
                    v => SetMegaSetField[off](cpt.Core.megaSet1, v));

            off -= megasetSize;
            if (off < turntableSize)
                return new FieldAccess<ushort>(() => FetchCptRaw(cpt.Core.megaSet1.turnTableId).ToUInt16(off / 2),
                    v => FetchCptRaw(cpt.Core.megaSet1.turnTableId).WriteUInt16(off / 2, v));

            off -= turntableSize;
            if (off < megasetSize)
                return new FieldAccess<ushort>(() => GetMegaSetField[off](cpt.Core.megaSet2),
                    v => SetMegaSetField[off](cpt.Core.megaSet2, v));

            off -= megasetSize;
            if (off < turntableSize)
                return new FieldAccess<ushort>(() => FetchCptRaw(cpt.Core.megaSet2.turnTableId).ToUInt16(off / 2),
                    v => FetchCptRaw(cpt.Core.megaSet2.turnTableId).WriteUInt16(off / 2, v));

            off -= turntableSize;
            if (off < megasetSize)
                return new FieldAccess<ushort>(() => GetMegaSetField[off](cpt.Core.megaSet3),
                    v => SetMegaSetField[off](cpt.Core.megaSet3, v));

            off -= megasetSize;
            if (off < turntableSize)
                return new FieldAccess<ushort>(() => FetchCptRaw(cpt.Core.megaSet3.turnTableId).ToUInt16(off / 2),
                    v => FetchCptRaw(cpt.Core.megaSet3.turnTableId).WriteUInt16(off / 2, v));
            off -= turntableSize;

            throw new NotSupportedException(string.Format("Offset {0:X2} out of bounds of compact",
                off + compactSize + 4 * megasetSize + 4 * 100));
        }
Example #41
0
        public UShortAccess GetGrafixPtr(Compact cpt)
        {
            var gfxBase = FetchCptRaw(cpt.Core.grafixProgId);
            if (gfxBase == null)
                return null;

            return new UShortAccess(gfxBase, cpt.Core.grafixProgPos * 2);
        }
Example #42
0
 public void PlotGrid(uint x, uint y, uint width, Compact cpt)
 {
     int resBitPos;
     uint resWidth;
     byte resGridIdx;
     if (GetGridValues(x, y, width - 1, cpt, out resGridIdx, out resBitPos, out resWidth))
         ObjectToWalk(resGridIdx, resBitPos, resWidth);
 }
Example #43
0
        public UShortAccess GetTurnTable(Compact cpt, ushort dir)
        {
            if (dir > 4) throw new ArgumentOutOfRangeException("dir", string.Format("No TurnTable ({0}) in MegaSet ({1})", dir, cpt.Core.megaSet));

            var m = GetMegaSet(cpt);
            var turnTable = FetchCptRaw(m.turnTableId);
            return new UShortAccess(turnTable, 10 * dir);
        }
Example #44
0
        private bool GetGridValues(uint x, uint y, uint width, Compact cpt, out byte resGrid, out int resBitNum, out uint resWidth)
        {
            int bitPos;
            resGrid = 0;
            resBitNum = 0;
            resWidth = 0;
            if (y < TopLeftY)
                return false; // off screen
            y -= TopLeftY;
            y >>= 3; // convert to blocks
            if (y >= Screen.GameScreenHeight >> 3)
                return false; // off screen
            bitPos = (int)(y * 40);
            width++;
            x >>= 3; // convert to blocks

            if (x < TopLeftX >> 3)
            {
                // at least partially off screen
                if (x + width < TopLeftX >> 3)
                    return false; // completely off screen
                width -= (TopLeftX >> 3) - x;
                x = 0;
            }
            else
                x -= TopLeftX >> 3;

            if (Screen.GameScreenWidth >> 3 <= x)
                return false; // off screen
            if (Screen.GameScreenWidth >> 3 < x + width) // partially off screen
                width = (Screen.GameScreenWidth >> 3) - x;

            bitPos += (int)x;
            System.Diagnostics.Debug.Assert((_gridConvertTable[cpt.Core.screen] >= 0) && (_gridConvertTable[cpt.Core.screen] < TotNoGrids));
            resGrid = (byte)_gridConvertTable[cpt.Core.screen];

            var tmpBits = 0x1F - (bitPos & 0x1F);
            bitPos &= ~0x1F; // divide into dword address and bit number
            bitPos += tmpBits;
            resBitNum = bitPos;
            resWidth = width;
            return true;
        }
Example #45
0
 public static FieldAccess<ushort> GetSub(Compact cpt, int mode)
 {
     switch (mode)
     {
         case 0:
             return new FieldAccess<ushort>(() => cpt.Core.baseSub, v => cpt.Core.baseSub = v);
         case 2:
             return new FieldAccess<ushort>(() => cpt.Core.baseSub_off, v => cpt.Core.baseSub_off = v);
         case 4:
             return new FieldAccess<ushort>(() => cpt.Core.actionSub, v => cpt.Core.actionSub = v);
         case 6:
             return new FieldAccess<ushort>(() => cpt.Core.actionSub_off, v => cpt.Core.actionSub_off = v);
         case 8:
             return new FieldAccess<ushort>(() => cpt.Core.getToSub, v => cpt.Core.getToSub = v);
         case 10:
             return new FieldAccess<ushort>(() => cpt.Core.getToSub_off, v => cpt.Core.getToSub_off = v);
         case 12:
             return new FieldAccess<ushort>(() => cpt.Core.extraSub, v => cpt.Core.extraSub = v);
         case 14:
             return new FieldAccess<ushort>(() => cpt.Core.extraSub_off, v => cpt.Core.extraSub_off = v);
         default:
             throw new InvalidOperationException(string.Format("Invalid Mode ({0})", mode));
     }
 }