Commit Graph

73 Commits

Author SHA1 Message Date
haven1433
419f83a6fb allow 2-argument sub in thumb
both `sub rd, #` and `sub rd, rn` are now supported
2023-06-30 08:05:33 -05:00
haven1433
d9020df3e2 fix possible crashes 2023-06-21 20:26:39 -05:00
haven1433
f74c1abd45 include unused labels at end of script 2023-01-22 20:20:16 -06:00
haven1433
bf4e766b6b allow tabs in thumb editor
we need to copy both newlines _and_ tabs for the text editor viewmodel, or the spacing won't line up right between colors
2023-01-06 20:55:18 -06:00
haven1433
8a5e5c793c implement additional UBL features
universal branchlink can now handle selection/cut/paste in cases involving pointers and anchors
2022-12-09 08:40:49 -06:00
haven1433
30026eea8d first pass at universal-branch-link feature
this allows us to select/cut/paste thumb routines safely
2022-12-09 00:09:42 -06:00
haven1433
4e7148a5f6 thumb editor is now colored 2022-12-02 11:35:24 -06:00
haven1433
2428ba8231 thumb tool should allow +1's on words 2022-11-02 08:43:08 -05:00
haven1433
ffaf42a7b5 add stm and ! support in thumb scripts 2022-10-29 22:52:42 -05:00
haven1433
cab4966c8a fix bug with single-line multi-line comments
if the start and end of a multi-line comment were on the same line, it wasn't parsed correctly, leading to a memory overflow
2022-10-25 20:05:17 -05:00
haven1433
afe1dc59b9 add alias instruction so that add rX, rX, #Y maps to add rX, #Y 2022-10-16 00:52:42 -05:00
Haven1433
201ecae9be thumb compiler improvements
support multiline comments /**/
support .equ directives
support .hword and .byte directives
2022-09-09 22:40:12 -05:00
Haven1433
2b6bcab364 allow both <anchor>+1 and <anchor+1> to work in thumb code 2022-07-02 12:16:14 -05:00
Haven1433
c119107bbd thumb code should not clear pointers to start+1 2022-06-24 23:07:14 -05:00
Haven1433
8b90b98994 fix parser bug 2022-06-23 21:12:10 -05:00
Haven1433
1b8e03fecf fix bug compiling thumb code 2022-06-08 22:14:49 -05:00
Haven1433
8541249524 writing non-aligned thumb code with ldr commands should work 2022-03-20 20:57:25 -05:00
Haven1433
c1d56fdfa4 Allow register/number <<= operation in thumb
Create a command that is an alias, so the user only has to write one register if they're doing a <<=
2021-12-10 11:09:46 -06:00
Haven1433
c3ad9d3927 Expand a += b to a = a + b for low register instructions
The behavior of the += version of `add` is undefined if both registers are low registers. In this case, we need to patch the instruction to replace it with the more traditional 3 register version: a = a + b.
2021-12-07 20:01:12 -06:00
Benjamin Popp
d52c8a7819 Correctly parse delay-load values with offsets 2021-10-04 16:22:52 -05:00
Benjamin Popp
ec027fb05c Fix assembler bug: multiple labels to the same address
When adjusting addresses based on 4-byte word alignment, make sure to adjust all the labels, not just the first one found for that address.
2021-10-04 16:02:56 -05:00
Benjamin Popp
80c642f24f Add ability to automatically repoint thumb code
* When given 4 instructions, that's enough space to replace it with a load, a branch, and an address.
* If the 4 instructions are such that they don't have any external dependencies (they don't contain a branch or a load), they can be safely moved to a new address.

These two points together mean that we can arbitrarily (and safely) expand almost any function. This should be very useful for both users and prototyping.
2021-09-23 21:57:05 -05:00
Benjamin Popp
ae80071ce5 fix scripting bugs
* script repointing should during ?????? pointer resolution: make sure that the pointer resolves to a different address than the script repoints to. This happened because we were looking for freespace for the new pointer and the moved script at the same time.
* when auto-repointing a script, clear the old pointer format and update their anchors with the new destination. This is not happening automatically because scripts don't hold all their length like other runs do, so repointing them left their pointers behind.
2021-07-29 23:35:13 -05:00
Benjamin Popp
2ad6cb1f56 bl instruction needs to be more permissive
allow address to start with 0x
allow address to have 08000000 added to it
2021-07-21 12:52:01 -05:00
Benjamin Popp
9feb55ad9e Defensive code to prevent a crash
if the code contains multiple labels in a row (which is legal, but weird), the old version of this method would crash.
2021-04-17 21:41:23 -05:00
Benjamin Popp
a49a53c494 Fix overzealous format clearing
When adding a thumb routine, we want to clear out any pointers within the data and write new pointer runs for the new pointers. But we want to keep any anchors that point to the start of the routine.
2021-04-01 08:47:31 -05:00
Benjamin Popp
52a89e5657 Allow thumb compiler to make metadata changes.
Replace the existing method with a pair of methods.
One method requires a token, so that it can make metadata changes.
The other returns a set of runs along with its set of compiled bytes, so that pointers can be adjusted.
2021-03-29 14:15:54 -05:00
Benjamin Popp
c40af6676d Different ldr shouldn't insert the same word multiple times.
Track the target value of deferred ldr instructions so that we can insert each different word only once.
2021-03-29 08:36:57 -05:00
Benjamin Popp
5ea2b312cd Allow deferred instructions to defer named pointers 2021-03-29 07:58:48 -05:00
Benjamin Popp
a1e51724b6 Code cleanup 2021-03-28 21:20:38 -05:00
Benjamin Popp
8409aa199c Introduce Unmapped Constants
Unmapped Constants are much like Unmapped Pointers: they're tracked by the Model, the metadata, and undo, but they don't have a spot in the file. This allows us to create constants using the existing syntax `@constant=value` which can then be referenced in thumb code using `.word`s.
* New test to show that we can save unmapped constants from the ViewModel to Metadata
* New test to show that we can load unmapped constants from Metadata to the Model
* New test to show that we can undo the adding of unmapped constants
* New test to show that unmapped constants can be used in thumb words
2021-03-21 16:23:55 -05:00
Benjamin Popp
0cd4f9613b Improve thumb parser / code search
* ldr can only have positive offsets, no sign.
* During code search, don't follow conditional branch instructions if they're not preceded by a condition. This prevents going on wild chases of data that _looks_ like an instruction, but is actually pointer data. This matters for things like switch statements.
* Improve documentation for thumb  registers.
2021-03-08 23:11:57 -06:00
Benjamin Popp
1edb2d4202 Update search-for-field-usages routine
Since we're looking for where the field of table is used, go ahead and put the code in ArrayRun. Then we only have to pass in an object that knows how to parse thumb code and the index of the field to find usages of.

Have each step just do a single search and return all results. This makes all the loops in one place, while all the searching is clearly separated.

Use a `FindAllCommands` method to handle watching for `mov` instructions and branch instructions, as well as watching for an instruction that uses the specified register and matches a predicate. This makes the algorithm more flexible and a bit easier to read, because it makes the top-level method fairly straightforward.
2021-03-07 23:09:55 -06:00
Benjamin Popp
3f866f1be8 First pass at searching for movestat[...].power uses.
No active code yet. Works for Emerald/FireRed.
2021-03-05 09:08:20 -06:00
Benjamin Popp
7502075ca2 Display known anchor names in bl commands 2021-02-18 22:02:29 -06:00
Benjamin Popp
92f73ddb87 Allow thumb script words and ldr commands to use anchors with offsets 2021-02-17 13:38:58 -06:00
Benjamin Popp
feacfd1a19 Don't add the nop before .words if the code starts at a non-multiple of 4 2021-01-21 13:05:14 -06:00
Benjamin Popp
6a4a3f62a2 Allow thumb in paste scripts
* ViewPort needs to be able to understand thumb directives. This means that .whatever must be interpreted as a directive and not as a constant. So constant names are required to *contain* at least one dot. For example, `.some.number`.
* When reading data that's been pasted in, if you find a `.thumb` directive, read until you find a `.end` directive, then interpret that whole thing as a thumb script, all at once.
* allow the `.end` directive to appear in thumb code
* `.align` directives should work in the viewport. Other directives that appear towards the top of thumb scripts before the `thumb` directive should be ignored.
2021-01-20 15:46:54 -06:00
Benjamin Popp
86a1706647 Thumb parse improvements
* Allow parsing numbers even if they don't start with the # prefix.
* Allow parsing of various ldr/str commands without needing to include an offset.
2021-01-20 07:56:40 -06:00
Benjamin Popp
8217f92c1e Allow pc/lr to be inside {} for push/pop instruction
This more closely matches the spec: https://developer.arm.com/documentation/dui0204/j/arm-and-thumb-instructions/memory-access-instructions/push-and-pop
2021-01-19 22:27:18 -06:00
Benjamin Popp
c5b56211f4 Thumb compiler improvements
Allow # on numbers during delayed ldr instructions
Expand selection based on increased code length as the user edits the script.
2020-10-10 21:23:27 -05:00
Benjamin Popp
ea22201fe9 Improve thumb compiler
* `ldr rn, #` requires an input to be a multiple of 4
* `ldrh rn, #` requires an input to be a multiple of 2
* `ldrb rn, #` requires an input to be a multiple of 1
* `add sp, #` and `sub sp, #` require the input to be a multiple of 4
* `add rd, sp, #` and `add rd, pc, #` require the input to be a multiple of 4
2020-10-07 09:03:01 -05:00
Benjamin Popp
53e6479706 Make it possible to compile Tarma's thumb to bin (part 1)
* Adding in the source / bin files for testing
* Added the "skip instruction" to handle macros that need have no meaning
* Added a "PatchInstruction" method to do some instruction conversions: add negative to subtract positive, etc
* Fixed a bug that prevented me from opening .bin files.
2020-10-05 22:34:58 -05:00
Benjamin Popp
40c81c614e Thumb compiler improvements
* Allow labels to be at the start of a line that has more stuff on it
* Allow words to start with the 0x hexadecimal prefix
* Allow pointer words to display the anchor during decompile
* Allow inline words to have a +1 modifier
2020-09-09 22:46:37 -05:00
Benjamin Popp
f6e9127f2d allow inline words when compiling thumb
example:  ldr r0, =255
The instuction gets queued to be written later, and space is left for it in the form of a `nop`.
Then the next time we hit the end of a section (b, bx, or pop pc), we write the word and we go back and write the instruction, now that we know the location of the word.
2020-09-09 07:38:55 -05:00
Benjamin Popp
107b1b8c1f Allow parsing hex numbers 2020-09-08 19:01:36 -05:00
Benjamin Popp
30f6a6ac73 Fix thumb compiler bug
4-byte align when writing words
2020-06-05 15:42:52 -05:00
Benjamin Popp
8b1517f740 Don't crash when editing thumb code 2020-06-05 14:14:24 -05:00
Benjamin Popp
ffe37fa9f4 Fix failing test
Also use automated code review
2020-05-27 23:28:39 -05:00
Benjamin Popp
4572cc217b Implement the ability to add uncompressed sprite/palette runs via ViewPort.Edit
There's a lot of refactor I need for this section of the codebase (parsing run formats) but that can come later.
2020-03-25 20:57:39 -05:00