Mercurial > repos > blastem
annotate vos_program_module.c @ 1369:3e7a921718de
Fix handling of test register selected sprite layer in border area. Gets rid of the border garbage in the "disco floor/ceiling" scene of OD2
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 23 May 2017 19:09:57 -0700 |
parents | de6f00204fa2 |
children |
rev | line source |
---|---|
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <stdio.h> |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <stddef.h> |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include <string.h> |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "vos_program_module.h" |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 static uint16_t big16(uint8_t ** src) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 uint16_t ret = *((*src)++) << 8; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 ret |= *((*src)++); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 return ret; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 static uint32_t big32(uint8_t ** src) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 uint32_t ret = *((*src)++) << 24; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 ret |= *((*src)++) << 16; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 ret |= *((*src)++) << 8; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 ret |= *((*src)++); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 return ret; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 static void string_(uint8_t ** src, uint16_t *len, char * str, uint32_t storage) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 *len = big16(src); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 memcpy(str, *src, storage); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 *src += storage; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 if (*len >= storage) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 *len = storage; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 } else { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 str[*len] = 0; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 if (storage & 1) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 (*src)++; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 #define string(src, field) string_(src, &(field).len, (field).str, sizeof((field).str)) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 int vos_read_header(FILE * f, vos_program_module *out) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 uint8_t buffer[4096]; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 if (fread(buffer, 1, sizeof(buffer), f) != sizeof(buffer)) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 return 0; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 uint8_t *cur = buffer; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 out->version = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 string(&cur, out->binder_version); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 string(&cur, out->binder_options); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 string(&cur, out->system_name); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 string(&cur, out->user_name); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 out->date_bound = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 out->main_entry_link.code_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 out->main_entry_link.static_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 out->user_boundary = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 out->n_modules = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 out->n_external_vars = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 out->n_link_names = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 out->n_unsnapped_links = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 out->n_vm_pages = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 out->n_header_pages = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 for (int i = 0; i < 3; i++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 for (int j = 0; j < 4; j++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 out->info[i][j].address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 out->info[i][j].len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 out->module_map_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 out->module_map_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 out->external_vars_map_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 out->external_vars_map_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 out->link_names_map_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 out->link_names_map_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 out->link_map_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 out->link_map_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 out->header_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 out->header_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 memcpy(out->access_info, cur, sizeof(out->access_info)); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 cur += sizeof(out->access_info); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 out->flags = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 out->n_tasks = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 for (int i = 0; i < 3; i++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 out->task_static_len[i] = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 out->stack_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 out->n_entries = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 out->entry_map_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 out->entry_map_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 out->pop_version = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 out->processor = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 string(&cur, out->release_name); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 out->relocation_info.map_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 out->relocation_info.map_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 out->relocation_info.n_relocations = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 out->high_water_mark = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 string(&cur, out->copyright_notice); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 for (int i = 0; i < 14; i++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 out->module_origins[i] = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 out->processor_family = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 string(&cur, out->program_name); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 out->string_pool_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 out->string_pool_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 out->obj_dir_map_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 out->obj_dir_map_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 for (int i = 0; i < 3; i++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 out->global_offset_table_address[i] = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 for (int i = 0; i < 3; i++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 out->block_map_info[i].address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 out->block_map_info[i].len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 out->section_map_file_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 out->section_map_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 out->section_map_len = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 out->n_sections = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 out->max_heap_size = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 out->max_program_size = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 out->max_stack_size = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 out->stack_fence_size = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 out->module_map_entries = NULL; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 out->external_vars = NULL; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 return 1; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 #define MODULE_MAP_ENTRY_SIZE 74 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 int vos_read_alloc_module_map(FILE * f, vos_program_module *header) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 if (header->module_map_len != header->n_modules * MODULE_MAP_ENTRY_SIZE) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 return 0; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 uint8_t * buf = malloc(header->module_map_len); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 fseek(f, header->module_map_address + 0x1000 - header->user_boundary, SEEK_SET); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 if (fread(buf, 1, header->module_map_len, f) != header->module_map_len) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 free(buf); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 return 0; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 uint8_t * cur = buf; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 header->module_map_entries = malloc(sizeof(vos_module_map_entry) * header->n_modules); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 for (int i = 0; i < header->n_modules; i++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 string(&cur, header->module_map_entries[i].name); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 for (int j = 0; j < 5; j++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 header->module_map_entries[i].unknown[j] = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 header->module_map_entries[i].code_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 header->module_map_entries[i].code_length = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 header->module_map_entries[i].foo_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 header->module_map_entries[i].foo_length = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 header->module_map_entries[i].bar_address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 header->module_map_entries[i].bar_length = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 for (int j = 0; j < 3; j++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 header->module_map_entries[i].unknown2[j] = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 return 1; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 #define EXTERNAL_VAR_ENTRY_SIZE 44 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 int vos_read_alloc_external_vars(FILE * f, vos_program_module *header) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 if (header->external_vars_map_len != header->n_external_vars * EXTERNAL_VAR_ENTRY_SIZE) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 return 0; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 uint8_t * buf = malloc(header->external_vars_map_len); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 fseek(f, header->external_vars_map_address + 0x1000 - header->user_boundary, SEEK_SET); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 if (fread(buf, 1, header->external_vars_map_len, f) != header->external_vars_map_len) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 free(buf); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 return 0; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 uint8_t * cur = buf; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 header->external_vars = malloc(sizeof(vos_external_var_entry) * header->n_external_vars); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 for (int i = 0; i < header->n_external_vars; i++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 string(&cur, header->external_vars[i].name); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 header->external_vars[i].address = big32(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 for (int j = 0; j < 3; j++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 header->external_vars[i].unknown[j] = big16(&cur); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 return 1; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 void vos_header_cleanup(vos_program_module *header) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 free(header->module_map_entries); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 free(header->external_vars); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 } |