Beispiel #1
0
        public static int[] getScreen(OffsetRec screenOffset, int screenIndex)
        {
            var result        = new int[Math.Max(64, screenOffset.recSize)];
            var arrayWithData = Globals.dumpdata != null ? Globals.dumpdata : Globals.romdata;
            int dataStride    = ConfigScript.getScreenDataStride();
            int wordLen       = ConfigScript.getWordLen();
            //bool littleEndian = ConfigScript.isLittleEndian();
            int beginAddr = screenOffset.beginAddr + screenIndex * screenOffset.recSize * dataStride * wordLen;

            for (int i = 0; i < screenOffset.recSize; i++)
            {
                result[i] = readBlockIndexFromMap(arrayWithData, beginAddr, i);
            }
            return(result);
        }
        public static void LoadFromFile(string fileName)
        {
            programStartDirectory = AppDomain.CurrentDomain.BaseDirectory + "/";
            configDirectory       = Path.GetDirectoryName(fileName) + "/";

            var    asm            = new AsmHelper(CSScript.LoadCode(File.ReadAllText(fileName)));
            object data           = null;
            bool   metaDataExists = true;

            try
            {
                object metaData = null;
                try
                {
                    metaData = asm.CreateObject("MetaData");
                }
                catch (Exception)
                {
                    metaDataExists = false;
                }
                if (metaDataExists)
                {
                    var scriptText = callFromScript(asm, metaData, "*.makeConfig", "");
                    var patchDict  = callFromScript(asm, metaData, "*.getPatchDictionary", new Dictionary <string, object>());
                    scriptText = Utils.patchConfigTemplate(scriptText, patchDict);
                    asm        = new AsmHelper(CSScript.LoadCode(scriptText));
                    data       = asm.CreateObject("Data");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            if (!metaDataExists)
            {
                try
                {
                    data = asm.CreateObject("Data");
                }
                catch (Exception)
                {
                    return;
                }
            }

            levelsCount   = callFromScript(asm, data, "*.getLevelsCount", 1);
            screensOffset = new OffsetRec[levelsCount];

            palOffset               = callFromScript(asm, data, "*.getPalOffset", new OffsetRec(0, 1, 0));
            videoOffset             = callFromScript(asm, data, "*.getVideoOffset", new OffsetRec(0, 1, 0));
            videoObjOffset          = callFromScript(asm, data, "*.getVideoObjOffset", new OffsetRec(0, 1, 0));
            blocksOffset            = callFromScript(asm, data, "*.getBlocksOffset", new OffsetRec(0, 1, 0));
            screensOffset[0]        = callFromScript(asm, data, "*.getScreensOffset", new OffsetRec(0, 1, 0));
            screensOffset[0].width  = callFromScript(asm, data, "*.getScreenWidth", 8);
            screensOffset[0].height = callFromScript(asm, data, "*.getScreenHeight", 8);
            if ((screensOffset[0].beginAddr == 0) && (screensOffset[0].recSize == 0))
            {
                screensOffset = callFromScript(asm, data, "*.getScreensOffsetsForLevels", new OffsetRec[1]);
            }
            screensOffset2             = callFromScript(asm, data, "*.getScreensOffset2", new OffsetRec(0, 1, 0));
            screenVertical             = callFromScript(asm, data, "*.getScreenVertical", false);
            screenDataStride           = callFromScript(asm, data, "*.getScreenDataStride", 1);
            wordLen                    = callFromScript(asm, data, "*.getWordLen", 1);
            littleEndian               = callFromScript(asm, data, "*.isLittleEndian", false);
            useSegaGraphics            = callFromScript(asm, data, "*.isUseSegaGraphics", false);
            blockSize4x4               = callFromScript(asm, data, "*.isBlockSize4x4", false);
            buildScreenFromSmallBlocks = callFromScript(asm, data, "isBuildScreenFromSmallBlocks", false);
            layersCount                = callFromScript(asm, data, "*.getLayersCount", 1);
            levelRecs                  = callFromScript(asm, data, "*.getLevelRecs", new List <LevelRec>()
            {
                new LevelRec(0, 0, 1, 1, 0)
            });

            //todo: remove or change to many lists interface
            minObjCoordX = callFromScript(asm, data, "*.getMinObjCoordX", 0);
            minObjCoordY = callFromScript(asm, data, "*.getMinObjCoordY", 0);
            minObjType   = callFromScript(asm, data, "*.getMinObjType", 0);
            maxObjCoordX = callFromScript(asm, data, "*.getMaxObjCoordX", -1); //ConfigScript.getScreenWidth() * 32
            maxObjCoordY = callFromScript(asm, data, "*.getMaxObjCoordY", -1); //ConfigScript.getScreenHeight() * 32;
            maxObjType   = callFromScript(asm, data, "*.getMaxObjType", -1);   //256

            bigBlocksHierarchyCount = callFromScript <int>(asm, data, "*.getBigBlocksHierarchyCount", 1);

            bigBlocksCounts = new int[bigBlocksHierarchyCount];
            for (int hierLevel = 0; hierLevel < bigBlocksHierarchyCount; hierLevel++)
            {
                bigBlocksCounts[hierLevel] = callFromScript(asm, data, "*.getBigBlocksCountHierarchy", 256, hierLevel);
            }
            bigBlocksCounts[0] = callFromScript(asm, data, "*.getBigBlocksCount", bigBlocksCounts[0]);

            bigBlocksOffsets = new OffsetRec[bigBlocksHierarchyCount];
            for (int hierLevel = 0; hierLevel < bigBlocksHierarchyCount; hierLevel++)
            {
                bigBlocksOffsets[hierLevel] = callFromScript(asm, data, "*.getBigBlocksOffsetHierarchy", new OffsetRec(0, 1, 0), hierLevel);
            }
            bigBlocksOffsets[0] = callFromScript(asm, data, "*.getBigBlocksOffset", bigBlocksOffsets[0]);

            getVideoPageAddrFunc = callFromScript <GetVideoPageAddrFunc>(asm, data, "*.getVideoPageAddrFunc");
            getVideoChunkFunc    = callFromScript <GetVideoChunkFunc>(asm, data, "*.getVideoChunkFunc");
            setVideoChunkFunc    = callFromScript <SetVideoChunkFunc>(asm, data, "*.setVideoChunkFunc");

            getBigBlocksFuncs = new GetBigBlocksFunc[bigBlocksHierarchyCount];
            setBigBlocksFuncs = new SetBigBlocksFunc[bigBlocksHierarchyCount];
            getBigBlocksFuncs = callFromScript <GetBigBlocksFunc[]>(asm, data, "*.getBigBlocksFuncs", new GetBigBlocksFunc[1]);
            setBigBlocksFuncs = callFromScript <SetBigBlocksFunc[]>(asm, data, "*.setBigBlocksFuncs", new SetBigBlocksFunc[1]);
            if (!buildScreenFromSmallBlocks)
            {
                getBigBlocksFuncs[0] = callFromScript <GetBigBlocksFunc>(asm, data, "*.getBigBlocksFunc", getBigBlocksFuncs[0]);
                setBigBlocksFuncs[0] = callFromScript <SetBigBlocksFunc>(asm, data, "*.setBigBlocksFunc", setBigBlocksFuncs[0]);
            }

            getSegaMappingFunc         = callFromScript <GetSegaMappingFunc>(asm, data, "*.getSegaMappingFunc", (int index) => { return(Utils.readLinearBigBlockData(0, index)); });
            setSegaMappingFunc         = callFromScript <SetSegaMappingFunc>(asm, data, "*.setSegaMappingFunc", (int index, byte[] bb) => { Utils.writeLinearBigBlockData(0, index, bb); });
            getBlocksFunc              = callFromScript <GetBlocksFunc>(asm, data, "*.getBlocksFunc");
            setBlocksFunc              = callFromScript <SetBlocksFunc>(asm, data, "*.setBlocksFunc");
            getPalFunc                 = callFromScript <GetPalFunc>(asm, data, "*.getPalFunc");
            setPalFunc                 = callFromScript <SetPalFunc>(asm, data, "*.setPalFunc");
            getObjectsFunc             = callFromScript <GetObjectsFunc>(asm, data, "*.getObjectsFunc");
            setObjectsFunc             = callFromScript <SetObjectsFunc>(asm, data, "*.setObjectsFunc");
            sortObjectsFunc            = callFromScript <SortObjectsFunc>(asm, data, "*.sortObjectsFunc");
            getLayoutFunc              = callFromScript <GetLayoutFunc>(asm, data, "*.getLayoutFunc", Utils.getDefaultLayoutFunc());
            setLayoutFunc              = callFromScript <SetLayoutFunc>(asm, data, "*.setLayoutFunc", null);
            convertScreenTileFunc      = callFromScript <ConvertScreenTileFunc>(asm, data, "*.getConvertScreenTileFunc");
            backConvertScreenTileFunc  = callFromScript <ConvertScreenTileFunc>(asm, data, "*.getBackConvertScreenTileFunc");
            getBigTileNoFromScreenFunc = callFromScript <GetBigTileNoFromScreenFunc>(asm, data, "*.getBigTileNoFromScreenFunc", Utils.getBigTileNoFromScreen);
            setBigTileToScreenFunc     = callFromScript <SetBigTileToScreenFunc>(asm, data, "*.setBigTileToScreenFunc", Utils.setBigTileToScreen);
            getObjectDictionaryFunc    = callFromScript <GetObjectDictionaryFunc>(asm, data, "*.getObjectDictionaryFunc");
            loadSegaBackFunc           = callFromScript <LoadSegaBackFunc>(asm, data, "*.loadSegaBackFunc");
            saveSegaBackFunc           = callFromScript <SaveSegaBackFunc>(asm, data, "*.saveSegaBackFunc");
            segaBackWidth              = callFromScript(asm, data, "*.getSegaBackWidth", 64);
            segaBackHeight             = callFromScript(asm, data, "*.getSegaBackHeight", 32);

            drawObjectFunc    = callFromScript <DrawObjectFunc>(asm, data, "*.getDrawObjectFunc");
            drawObjectBigFunc = callFromScript <DrawObjectBigFunc>(asm, data, "*.getDrawObjectBigFunc");

            renderToMainScreenFunc = callFromScript <RenderToMainScreenFunc>(asm, data, "*.getRenderToMainScreenFunc");

            isBigBlockEditorEnabled = callFromScript(asm, data, "*.isBigBlockEditorEnabled", true);
            isBlockEditorEnabled    = callFromScript(asm, data, "*.isBlockEditorEnabled", true);
            isEnemyEditorEnabled    = callFromScript(asm, data, "*.isEnemyEditorEnabled", true);
            objTypesPicturesDir     = callFromScript(asm, data, "*.getObjTypesPicturesDir", "obj_sprites");

            showScrollsInLayout     = callFromScript(asm, data, "*.isShowScrollsInLayout", true);
            scrollsOffsetFromLayout = callFromScript(asm, data, "*.getScrollsOffsetFromLayout", 0);

            blocksCount = callFromScript(asm, data, "*.getBlocksCount", 256);

            blocksPicturesFilename = callFromScript(asm, data, "getBlocksFilename", "");
            if (blocksPicturesFilename != "")
            {
                if (!File.Exists(ConfigScript.getBlocksPicturesFilename()))
                {
                    throw new Exception("File does not exists: " + ConfigScript.getBlocksPicturesFilename());
                }
            }
            blocksPicturesWidth     = callFromScript(asm, data, "getPictureBlocksWidth", 32);
            usePicturesInstedBlocks = blocksPicturesFilename != "";

            blockTypeNames = callFromScript(asm, data, "getBlockTypeNames", defaultBlockTypeNames);

            groups = callFromScript(asm, data, "getGroups", new GroupRec[0]);

            palBytesAddr = callFromScript(asm, data, "getPalBytesAddr", -1);

            loadAllPlugins(asm, data);
        }