| 900 | } |
| 901 | |
| 902 | void create_overlay_swap_function(const std::string& function_name, std::ofstream& output_file, const std::vector<FunctionPermutation>& permutations, const RSPRecompilerConfig& config) { |
| 903 | // Includes and permutation protos |
| 904 | fmt::print(output_file, |
| 905 | "#include <map>\n" |
| 906 | "#include <vector>\n\n" |
| 907 | "using RspUcodePermutationFunc = RspExitReason(uint8_t* rdram, RspContext* ctx);\n\n" |
| 908 | "RspExitReason {}(uint8_t* rdram, RspContext* ctx);\n", |
| 909 | config.output_function_name + "_initial"); |
| 910 | |
| 911 | for (const auto& permutation : permutations) { |
| 912 | fmt::print(output_file, "RspExitReason {}(uint8_t* rdram, RspContext* ctx);\n", |
| 913 | config.output_function_name + make_permutation_string(permutation.permutation)); |
| 914 | } |
| 915 | fmt::print(output_file, "\n"); |
| 916 | |
| 917 | // IMEM -> slot index mapping |
| 918 | fmt::print(output_file, |
| 919 | "static const std::map<uint32_t, uint32_t> imemToSlot = {{\n"); |
| 920 | for (size_t i = 0; i < config.overlay_slots.size(); i++) { |
| 921 | const RSPRecompilerOverlaySlotConfig& slot = config.overlay_slots[i]; |
| 922 | |
| 923 | uint32_t imemAddress = slot.text_address & rsp_mem_mask; |
| 924 | fmt::print(output_file, " {{ 0x{:04X}, {} }},\n", |
| 925 | imemAddress, i); |
| 926 | } |
| 927 | fmt::print(output_file, "}};\n\n"); |
| 928 | |
| 929 | // ucode offset -> overlay index mapping (per slot) |
| 930 | fmt::print(output_file, |
| 931 | "static const std::vector<std::map<uint32_t, uint32_t>> offsetToOverlay = {{\n"); |
| 932 | for (const auto& slot : config.overlay_slots) { |
| 933 | fmt::print(output_file, " {{\n"); |
| 934 | for (size_t i = 0; i < slot.overlays.size(); i++) { |
| 935 | const RSPRecompilerOverlayConfig& overlay = slot.overlays[i]; |
| 936 | |
| 937 | fmt::print(output_file, " {{ 0x{:04X}, {} }},\n", |
| 938 | overlay.offset, i); |
| 939 | } |
| 940 | fmt::print(output_file, " }},\n"); |
| 941 | } |
| 942 | fmt::print(output_file, "}};\n\n"); |
| 943 | |
| 944 | // Permutation function pointers |
| 945 | fmt::print(output_file, |
| 946 | "static RspUcodePermutationFunc* permutations[] = {{\n"); |
| 947 | for (const auto& permutation : permutations) { |
| 948 | fmt::print(output_file, " {},\n", |
| 949 | config.output_function_name + make_permutation_string(permutation.permutation)); |
| 950 | } |
| 951 | fmt::print(output_file, "}};\n\n"); |
| 952 | |
| 953 | // Main function |
| 954 | fmt::print(output_file, |
| 955 | "RspExitReason {}(uint8_t* rdram, uint32_t ucode_addr) {{\n" |
| 956 | " RspContext ctx{{}};\n", |
| 957 | config.output_function_name); |
| 958 | |
| 959 | std::string slots_init_str = ""; |
no test coverage detected