summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2023-03-28 16:40:03 -0600
committerGitHub <noreply@github.com>2023-03-28 16:40:03 -0600
commit8d118db0b25edfbabb059e4b977e339ca9d8f885 (patch)
tree6a30217aed7887e33a4253ddc88ce6fe0966020b /tools
parent889520b045f70b073ec1616f8d27621af76c5178 (diff)
Labelling of some hard-coded addr to syms (#294)
* Updated final displaylist symbol * Cleaned up loader script * Random changes * Various naming and decomp
Diffstat (limited to 'tools')
-rw-r--r--tools/displaylist_packer.c20
-rw-r--r--tools/generate_segment_headers.py56
-rw-r--r--tools/generate_vertice_count.py34
3 files changed, 96 insertions, 14 deletions
diff --git a/tools/displaylist_packer.c b/tools/displaylist_packer.c
index 6ee802575..07fd636d1 100644
--- a/tools/displaylist_packer.c
+++ b/tools/displaylist_packer.c
@@ -235,18 +235,10 @@ void pack(FILE *input_file, FILE *output_file) {
case 0xB6:
data[count++] = 0x57;
break;
- case 0xFF:
- data[count++] = 0xFF;
- if (cmd) {
- p1 = ARG1(cmd);
- if (p1 <= 32) {
- for (i = 0; i < p1; i++) {
- data[count++] = 0x00;
- }
- }
- }
- goto eos; // end of switch
- break;
+ //case 0xFF:
+ // data[count++] = 0xFF;
+ // goto eos; // end of switch
+ // break;
default:
printf("Error: Unknown Opcode: 0x%X\n", opCode);
printf("Opcode written to file as 0xEE\n");
@@ -256,8 +248,8 @@ void pack(FILE *input_file, FILE *output_file) {
offset += 4;
}
- eos: ;
-
+ //eos: ;
+ data[count++] = 0xFF;
size_t num_elements_written = fwrite(data, sizeof(uint8_t), count, output_file);
if (num_elements_written != count) {
printf("Failed to write data to file.\n");
diff --git a/tools/generate_segment_headers.py b/tools/generate_segment_headers.py
new file mode 100644
index 000000000..0a3a895a2
--- /dev/null
+++ b/tools/generate_segment_headers.py
@@ -0,0 +1,56 @@
+import subprocess
+
+# This script generates headers for course segmented packed displaylist data
+
+dir_path = "build/us/courses/"
+output_file = "include/packed_displaylist_symbols_gen.h"
+
+sym_list = []
+
+# Run objdump for each packed.inc.elf file in courses/
+for filename in subprocess.check_output(f"find {dir_path} -name packed.inc.elf", shell=True).decode().splitlines():
+ file_output = subprocess.check_output(f"objdump -t {filename} | grep ' .data\| .bss' | awk '$6 != \"\" {{print $1, $5, $6}}'", shell=True)
+ file_output = file_output.decode()
+
+ # Create temporary list of (addr, name) tuples from file_output
+ sym_list_tmp = []
+ for line in file_output.splitlines():
+ addr, size, name = line.split()
+ # Skip lines with the .data directive
+ if (name == ".data"):
+ continue
+
+ sym_list_tmp.append((addr, size, name))
+
+ # Sort the tmp list
+ sym_list_tmp = sorted(sym_list_tmp, key=lambda x: x[0])
+
+ # Generate the final displaylist symbol for courses
+ # Take the last addr and add its size
+ end_addr = '0{:X}'.format(int(sym_list_tmp[-1][0], 16) + int(sym_list_tmp[-1][1], 16))
+
+ end_name = sym_list_tmp[-1][2].split("dl_")[0] + "end"
+
+ sym_list_tmp.append((end_addr, '0', end_name))
+
+ # Magic number to insert a newline after every file.
+ sym_list_tmp.append((0xFFFFFFFF, '0',"newline"))
+ # Copy to the main list
+ sym_list.extend(sym_list_tmp)
+
+# Write includes and defines to the header file
+with open(output_file, "w") as f:
+
+ # Write comments
+ f.write("// Generated by tools/generate_segment_headers.py\n\n")
+
+ # Write includes
+ f.write("#include <macros.h>\n\n")
+
+ # Write #define statements to header file
+ for addr, size, name in sym_list:
+ # Add two newlines for readability
+ if (name == "newline"):
+ f.write("\n\n")
+ continue
+ f.write(f"#define {name} ((uintptr_t) 0x{addr.upper()})\n")
diff --git a/tools/generate_vertice_count.py b/tools/generate_vertice_count.py
new file mode 100644
index 000000000..233a40fd2
--- /dev/null
+++ b/tools/generate_vertice_count.py
@@ -0,0 +1,34 @@
+import sys
+import subprocess
+
+# This script generates vertice count for course geography used in the courseTable.
+
+dir_path = "build/us/courses/"
+output_file = "include/vertice_count_gen.h"
+
+sym_list = []
+output = ""
+
+# Run objdump for each model.inc.elf file in courses/
+for filename in subprocess.check_output(f"find {dir_path} -name model.inc.elf", shell=True).decode().splitlines():
+ file_output = subprocess.check_output(f"objdump -t {filename} | grep ' .data\| .bss' | awk '$6 != \"\" {{print $5, $6}}'", shell=True)
+ output += file_output.decode()
+
+# Write includes and defines to the header file
+with open(output_file, "w") as f:
+
+ # Write comments
+ f.write("// Generated by tools/generate_vertice_count.py\n\n")
+
+ # Write includes
+ f.write("#include <macros.h>\n\n")
+
+ # Write defines
+ for line in output.splitlines():
+ addr, name = line.split()
+ if (name == ".data"):
+ continue
+
+ # (size / 14) -> fill with zeros to make complete u32 -> toUppercase()
+ # One vertice = 14 bytes. objdump outputs the size. Divide size by 14.
+ f.write(f"#define {name}_count 0x{hex(int(addr, 16) // 14)[2:].zfill(8).upper()}\n\n")