コード例 #1
0
        private List <UInt32> writeSubroutineForceFetchFakeVentureCard(VAVAddr fakeVentureCard)
        {
            PowerPcAsm.Pair16Bit v = PowerPcAsm.make16bitValuePair((UInt32)fakeVentureCard);

            // precondition: r3 is ChanceCardUI *
            // ChanceCardUI->field_0x34 is ChanceBoard *
            // ChanceBoard->field_0x158 is current venture card id

            var asm = new List <UInt32>();

            asm.Add(PowerPcAsm.lis(6, v.upper16Bit));      // \
            asm.Add(PowerPcAsm.addi(6, 6, v.lower16Bit));  // / r6 <- forceVentureCardVariable
            asm.Add(PowerPcAsm.lwz(4, 0x0, 6));            // | r4 <- forceVentureCard
            asm.Add(PowerPcAsm.cmpwi(4, 0x0));             // | if(forceVentureCard != 0)
            asm.Add(PowerPcAsm.beq(7));                    // | {
            asm.Add(PowerPcAsm.lwz(5, 0x34, 3));           // |   r5 <- ChanceCardUI.ChanceBoard
            asm.Add(PowerPcAsm.stw(4, 0x158, 5));          // |   ChanceBoard.currentVentureCardId <- r4
            asm.Add(PowerPcAsm.li(5, 0));                  // |\  forceVentureCard <- 0
            asm.Add(PowerPcAsm.stw(5, 0x0, 6));            // |/
            asm.Add(PowerPcAsm.li(8, 0x0));                // |   r8 <- 0 (the venture card is initialized)
            asm.Add(PowerPcAsm.blr());                     // |   return r4 and r8
                                                           // | }
            asm.Add(PowerPcAsm.li(4, -0x1));               // | r4 <- -1
            asm.Add(PowerPcAsm.li(8, 0x3));                // | r8 <- 3 (the venture card is continued to be executed)
            asm.Add(PowerPcAsm.blr());                     // | return r4 and r8


            return(asm);
        }
コード例 #2
0
        /// <summary>
        /// Write the subroutine which takes a compressed venture card table as input and writes it into ventureCardDecompressedTableAddr
        /// </summary>
        /// <param name="ventureCardDecompressedTableAddr">The address for the reserved memory space to store the decompressed venture card table in</param>
        private List <UInt32> writeSubroutine(VAVAddr ventureCardDecompressedTableAddr)
        {
            var asm = new List <UInt32>();

            PowerPcAsm.Pair16Bit ventureCardTableAddrPair = PowerPcAsm.make16bitValuePair((UInt32)ventureCardDecompressedTableAddr);
            ///
            /// assume:
            /// r6 = ventureCardCompressedTableAddr
            ///
            /// variables:
            /// r4 = ventureCardId
            /// r5 = ventureCardCompressedTableAddr
            /// r6 = ventureCardDecompressedTableAddr
            /// r7 = ventureCardCompressedWord
            /// r8 = bitIndex
            /// r0 = tmp / currentByte
            ///
            /// return:
            /// r6 = ventureCardDecompressedTableAddr
            ///
            asm.Add(PowerPcAsm.li(4, 0));                                                           // ventureCardId = 0
            asm.Add(PowerPcAsm.mr(5, 6));                                                           // r6 is ventureCardCompressedTableAddr at this point. Copy it to r5 with which we will be working
            asm.Add(PowerPcAsm.lis(6, ventureCardTableAddrPair.upper16Bit));                        // \ load the ventureCardDecompressedTableAddr into r6. This address is
            asm.Add(PowerPcAsm.addi(6, 6, ventureCardTableAddrPair.lower16Bit));                    // /  where we will store the decompressed venture card table.
            int whileVentureCardIdSmaller128 = asm.Count;                                           // do {

            {                                                                                       //
                asm.Add(PowerPcAsm.li(0, 0));                                                       //     \ load the next compressed word from ventureCardCompressedTableAddr
                asm.Add(PowerPcAsm.lwzx(7, 5, 0));                                                  //     /  into r7. We will decompress the venture card table word by word.
                asm.Add(PowerPcAsm.li(8, 31));                                                      //     bitIndex = 31
                int whileBitIndexGreaterEqual32 = asm.Count;                                        //     do
                {                                                                                   //     {
                    asm.Add(PowerPcAsm.mr(0, 7));                                                   //         get the current compressed word
                    asm.Add(PowerPcAsm.srw(0, 0, 8));                                               //         shift it bitIndex times to the right
                    asm.Add(PowerPcAsm.andi(0, 0, 1));                                              //         retrieve the lowest bit of it -> r0 contains the decompressed venture card byte now.
                    asm.Add(PowerPcAsm.stbx(0, 4, 6));                                              //         store it into ventureCardDecompressedTableAddr[ventureCardId]
                    asm.Add(PowerPcAsm.subi(8, 8, 1));                                              //         bitIndex--
                    asm.Add(PowerPcAsm.addi(4, 4, 1));                                              //         ventureCardId++
                    asm.Add(PowerPcAsm.cmpwi(8, 0));                                                //
                    asm.Add(PowerPcAsm.bge(asm.Count, whileBitIndexGreaterEqual32));                //     } while(bitIndex >= 0)
                }                                                                                   //
                asm.Add(PowerPcAsm.addi(5, 5, 4));                                                  //     ventureCardCompressedTableAddr += 4
                asm.Add(PowerPcAsm.cmpwi(4, 128));                                                  //
                asm.Add(PowerPcAsm.blt(asm.Count, whileVentureCardIdSmaller128));                   // } while(ventureCardId < 128)
            }                                                                                       //
            asm.Add(PowerPcAsm.li(4, 0));                                                           // \ reset r4 = 0
            asm.Add(PowerPcAsm.li(5, 0));                                                           // / reset r5 = 0
            asm.Add(PowerPcAsm.blr());                                                              // return

            return(asm);
        }
コード例 #3
0
        private List <UInt32> writeGetTextureForCustomSquareRoutine(byte register_textureType, byte register_squareType)
        {
            var asm = new List <UInt32>();

            asm.Add(PowerPcAsm.li(register_textureType, 0x1));    // textureType = 1
            asm.Add(PowerPcAsm.cmpwi(register_squareType, 0x2e)); // if(squareType == 0x2e)
            asm.Add(PowerPcAsm.beq(2));                           // {
            asm.Add(PowerPcAsm.blr());                            //   return textureType;
                                                                  // } else {
            asm.Add(PowerPcAsm.li(register_textureType, 0x5));    //   textureType = 5
            asm.Add(PowerPcAsm.blr());                            //   return textureType;
                                                                  // }
            return(asm);
        }
コード例 #4
0
        private List <UInt32> writeSubroutineGetNumMapsInZone(List <MapDescriptor> mapDescriptors)
        {
            // precondition:  r3  _ZONE_TYPE
            // postcondition: r3  num maps
            var asm = new List <UInt32>();

            for (short i = 0; i < 6; i++)
            {
                asm.Add(PowerPcAsm.cmpwi(3, i));
                asm.Add(PowerPcAsm.bne(3));
                asm.Add(PowerPcAsm.li(3, (short)(from m in mapDescriptors where m.Zone == i && m.MapSet == 0 select m).Count()));
                asm.Add(PowerPcAsm.blr());
            }
            asm.Add(PowerPcAsm.blr());
            return(asm);
        }
コード例 #5
0
        private List <UInt32> writeRuleSetFromMapRoutine(AddressMapper addressMapper, VAVAddr routineStartAddress)
        {
            var Game_GetRuleFlag = addressMapper.toVersionAgnosticAddress((BSVAddr)0x801cca98);

            // precondition: r24 is mapId
            // precondition: r25 is global rule set which we are gonna use to store the linkreturn
            var asm = new List <UInt32>();

            asm.Add(PowerPcAsm.mflr(25));
            asm.Add(PowerPcAsm.mr(3, 24));                                             // r3 <- r24
            asm.Add(PowerPcAsm.bl(routineStartAddress, asm.Count, Game_GetRuleFlag));  // r3 <- bl Game_GetRuleFlag(r3)
            asm.Add(PowerPcAsm.stw(3, 0x53f4, 29));                                    // gameRule <- r3
            asm.Add(PowerPcAsm.mtlr(25));
            asm.Add(PowerPcAsm.blr());                                                 // return
            return(asm);
        }
コード例 #6
0
        private List <UInt32> writeSubroutineInitMapIdsForMapIcons(AddressMapper addressMapper, VAVAddr entryAddr)
        {
            var JUtility_memset = addressMapper.toVersionAgnosticAddress((BSVAddr)0x80004714);
            // precondition: r3 is newly created map icon array
            //               r16 is the amount of map ids in the array (size / 4)
            //               r24 is unused
            // postcondition: r24 is the map icon array
            var asm = new List <UInt32>();

            asm.Add(PowerPcAsm.mflr(24));                                     // save the link register
            asm.Add(PowerPcAsm.li(4, -1));                                    // fill with 0xff
            asm.Add(PowerPcAsm.rlwinm(5, 16, 0x3, 0x0, 0x1d));                // get the size of the array
            asm.Add(PowerPcAsm.bl(entryAddr, asm.Count, JUtility_memset));    // call JUtility_memset(array*, 0xff, array.size)
            asm.Add(PowerPcAsm.mtlr(24));                                     // restore the link register
            asm.Add(PowerPcAsm.mr(24, 3));                                    // move array* to r24
            asm.Add(PowerPcAsm.blr());                                        // return
            return(asm);
        }