Esempio n. 1
0
        public static Screen 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);
            }
            //TODO: read layer2

            int w = screenOffset.width;
            int h = screenOffset.height;

            if (ConfigScript.getScreenVertical())
            {
                Utils.swap(ref w, ref h);
                result = Utils.transpose(result, w, h);
            }

            return(new Screen(new BlockLayer(result), w, h));
        }
 public OffsetRec[] getScreensOffsetsForLevels() {
   var ans = new OffsetRec[] {
     new OffsetRec(0x16149 - 96  , 1  , 17*96, 96, 17),
     new OffsetRec(0x18149 - 24  , 1  , 24*64, 24, 64),
     new OffsetRec(0x16CB7 - 168 , 1  , 168*11, 168  , 11),
     new OffsetRec(0x14012 - 168 , 1  , 168*17, 168  , 17),
     new OffsetRec(0x14C72 - 62  , 1  , 62*33 , 62   , 33),
     new OffsetRec(0x18C21 - 64  , 1  , 64*33 , 64   , 33),
     new OffsetRec(0x12012 - 64  , 1  , 64*33 , 64   , 33),
     new OffsetRec(0x12DF6 - 33  , 1  , 33*55 , 33   , 55),
     new OffsetRec(0x17536 - 64  , 1  , 64*33 , 64   , 33)
   };
   return ans;  
 }
Esempio n. 3
0
        //save screensData from firstScreenIndex to ConfigScript.screensOffset[currentOffset]
        public static void saveScreensToOffset(OffsetRec screensRec, Screen[] screensData, int firstScreenIndex, int currentOffsetIndex, int layerNo)
        {
            var  arrayToSave  = Globals.dumpdata != null ? Globals.dumpdata : Globals.romdata;
            int  wordLen      = ConfigScript.getWordLen();
            bool littleEndian = ConfigScript.isLittleEndian();
            //write back tiles
            int dataStride = ConfigScript.getScreenDataStride();

            for (int i = 0; i < screensRec.recCount; i++)
            {
                var curScrNo    = firstScreenIndex + i;
                var curScreen   = screensData[curScrNo];
                var dataToWrite = curScreen.layers[layerNo].data;
                if (ConfigScript.getScreenVertical())
                {
                    dataToWrite = Utils.transpose(dataToWrite, screensRec.width, screensRec.height);
                }
                int addr = screensRec.beginAddr + i * screensRec.recSize * (dataStride * wordLen);
                if (wordLen == 1)
                {
                    for (int x = 0; x < screensRec.recSize; x++)
                    {
                        arrayToSave[addr + x * dataStride] = (byte)ConfigScript.backConvertScreenTile(dataToWrite[x]);
                    }
                }
                else if (wordLen == 2)
                {
                    if (littleEndian)
                    {
                        for (int x = 0; x < screensRec.recSize; x++)
                        {
                            Utils.writeWordLE(arrayToSave, addr + x * (dataStride * wordLen), ConfigScript.backConvertScreenTile(dataToWrite[x]));
                        }
                    }
                    else
                    {
                        for (int x = 0; x < screensRec.recSize; x++)
                        {
                            Utils.writeWord(arrayToSave, addr + x * (dataStride * wordLen), ConfigScript.backConvertScreenTile(dataToWrite[x]));
                        }
                    }
                }

                //write physics info, if it present
                if (curScreen.physicsLayer != null)
                {
                    ConfigScript.savePhysicsLayerFunc?.Invoke(curScrNo, curScreen.physicsLayer.data);
                }
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private void saveScreens(OffsetRec screensRec, int[][] screensData)
        {
            var  arrayToSave  = Globals.dumpdata != null ? Globals.dumpdata : Globals.romdata;
            int  wordLen      = ConfigScript.getWordLen();
            bool littleEndian = ConfigScript.isLittleEndian();
            //write back tiles
            int dataStride = ConfigScript.getScreenDataStride();

            for (int i = 0; i < screensRec.recCount; i++)
            {
                int addr = screensRec.beginAddr + i * screensRec.recSize * (dataStride * wordLen);
                if (wordLen == 1)
                {
                    for (int x = 0; x < screensRec.recSize; x++)
                    {
                        arrayToSave[addr + x * dataStride] = (byte)ConfigScript.backConvertScreenTile(screensData[i][x]);
                    }
                }
                else if (wordLen == 2)
                {
                    if (littleEndian)
                    {
                        for (int x = 0; x < screensRec.recSize; x++)
                        {
                            Utils.writeWordLE(arrayToSave, addr + x * (dataStride * wordLen), ConfigScript.backConvertScreenTile(screensData[i][x]));
                        }
                    }
                    else
                    {
                        for (int x = 0; x < screensRec.recSize; x++)
                        {
                            Utils.writeWord(arrayToSave, addr + x * (dataStride * wordLen), ConfigScript.backConvertScreenTile(screensData[i][x]));
                        }
                    }
                }
            }
        }
Esempio n. 6
0
 private void saveScreens(OffsetRec screensRec, int[][] screensData)
 {
     var arrayToSave = Globals.dumpdata != null ? Globals.dumpdata : Globals.romdata;
     int wordLen = ConfigScript.getWordLen();
     bool littleEndian = ConfigScript.isLittleEndian();
     //write back tiles
     int dataStride = ConfigScript.getScreenDataStride();
     for (int i = 0; i < screensRec.recCount; i++)
     {
         int addr = screensRec.beginAddr + i * screensRec.recSize * (dataStride * wordLen);
         if (wordLen == 1)
         {
             for (int x = 0; x < screensRec.recSize; x++)
                 arrayToSave[addr + x * dataStride] = (byte)ConfigScript.backConvertScreenTile(screensData[i][x]);
         }
         else if (wordLen == 2)
         {
             if (littleEndian)
             {
                 for (int x = 0; x < screensRec.recSize; x++)
                     Utils.writeWordLE(arrayToSave, addr + x * (dataStride * wordLen), ConfigScript.backConvertScreenTile(screensData[i][x]));
             }
             else
             {
                 for (int x = 0; x < screensRec.recSize; x++)
                     Utils.writeWord(arrayToSave, addr + x * (dataStride * wordLen), ConfigScript.backConvertScreenTile(screensData[i][x]));
             }
         }
     }
 }
Esempio n. 7
0
        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;
                }
            }

            screensOffset = new OffsetRec[1];

            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, -1, -1));
            if ((screensOffset[0].beginAddr == 0) && (screensOffset[0].recSize == 0))
            {
                screensOffset = callFromScript(asm, data, "*.getScreensOffsetsForLevels", new OffsetRec[1]);
            }
            if ((screensOffset[0].width <= 0) || (screensOffset[0].height <= 0))
            {
                throw new Exception("Screen width and height must be defined and be positive numbers");
            }
            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);
            useGbGraphics              = callFromScript(asm, data, "*.isUseGbGraphics", false);
            blockSize4x4               = callFromScript(asm, data, "*.isBlockSize4x4", false);
            buildScreenFromSmallBlocks = callFromScript(asm, data, "isBuildScreenFromSmallBlocks", false);
            getLevelRecsFunc           = callFromScript <GetLevelRecsFunc>(asm, data, "*.getLevelRecsFunc", ConfigScript.getLevelRecsFuncDefault());

            //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);
            maxObjCoordY = callFromScript(asm, data, "*.getMaxObjCoordY", -1);
            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]);
            getBigBlocksCountFunc = callFromScript <GetBigBlocksCountFunc>(asm, data, "*.getBigBlocksCountFunc");

            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];
            getBigBlocksAddrFuncs = new GetBigBlocksAddrFunc[bigBlocksHierarchyCount];

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

            getSegaMappingFunc         = callFromScript <GetSegaMappingFunc>(asm, data, "*.getSegaMappingFunc", (int index) => 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");
            getBlocksAddrFunc          = callFromScript <GetBlocksAddrFunc> (asm, data, "*.getBlocksAddrFunc");
            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");
            selectObjectBigFunc = callFromScript <SelectObjectBigFunc>(asm, data, "*.getSelectObjectBigFunc");

            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);
            scrollByteArray         = callFromScript(asm, data, "*.getScrollByteArray", new byte[0]);

            blocksCount        = callFromScript(asm, data, "*.getBlocksCount", 256);
            getBlocksCountFunc = callFromScript <GetBlocksCountFunc>(asm, data, "*.getBlocksCountFunc");

            blocksPicturesFilename = callFromScript(asm, data, "getBlocksFilename", "");

            loadScreensFunc = callFromScript <LoadScreensFunc>(asm, data, "*.loadScreensFunc");
            saveScreensFunc = callFromScript <SaveScreensFunc>(asm, data, "*.saveScreensFunc");

            loadPhysicsLayerFunc = callFromScript <LoadPhysicsLayer>(asm, data, "*.loadPhysicsLayerFunc");
            savePhysicsLayerFunc = callFromScript <SavePhysicsLayer>(asm, data, "*.savePhysicsLayerFunc");
            physicsBlocksCount   = callFromScript(asm, data, "*.getPhysicsBlocksCount", 256);

            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);

            getGroupsFunc = callFromScript <GetGroupsFunc>(asm, data, "*.getGroupsFunc", () => new GroupRec[0]);

            palBytesAddr        = callFromScript(asm, data, "*.getPalBytesAddr", -1);
            physicsBytesAddr    = callFromScript(asm, data, "*.getPhysicsBytesAddr", -1);
            getPalBytesAddrFunc = callFromScript <GetPalBytesAddrFunc>(asm, data, "*.getPalBytesAddrFunc");

            defaultScale = callFromScript(asm, data, "*.getDefaultScale", -1.0f);

            loadAllPlugins(asm, data);

            ConfigScript.videoNes.updateColorsFromConfig();
        }
 public OffsetRec[] getScreensOffsetsForLevels()
 {
     var ans = new OffsetRec[] {
       new OffsetRec(  90441 - 96 , 1, 17*96, 96, 17),
       new OffsetRec(0x18149 - 24 , 1, 24*64, 24, 64),
       new OffsetRec(  93367 , 1  , 168*10, 168  , 10),
       new OffsetRec(  81938 , 1  , 168*16, 168  , 16),
       new OffsetRec(  85106 , 1  , 62*32 , 62   , 32),
       new OffsetRec(0x18C21 , 1  , 64*32 , 64   , 32),
       new OffsetRec(0x12012 , 1  , 64*32 , 64   , 32),
       new OffsetRec(0x12DF6 , 1  , 33*54 , 33   , 54),
       new OffsetRec(95542   , 1  , 64*32 , 64   , 32)
     };
     return ans;
 }
Esempio n. 9
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;
     if (wordLen == 1)
     {
         for (int i = 0; i < screenOffset.recSize; i++)
             result[i] = ConfigScript.convertScreenTile(arrayWithData[beginAddr + i * dataStride]);
         for (int i = screenOffset.recSize; i < 64; i++)
             result[i] = ConfigScript.convertScreenTile(0); //need this?
     }
     else if (wordLen == 2)
     {
         if (littleEndian)
         {
             for (int i = 0; i < screenOffset.recSize; i++)
                 result[i] = ConfigScript.convertScreenTile(Utils.readWordLE(arrayWithData, beginAddr + i * (dataStride * wordLen)));
         }
         else
         {
             for (int i = 0; i < screenOffset.recSize; i++)
                 result[i] = ConfigScript.convertScreenTile(Utils.readWord(arrayWithData, beginAddr + i * (dataStride * wordLen)));
         }
     }
     return result;
 }