glank

watch file syntax

Nov 21st, 2017
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.21 KB | None | 0 0
  1. # a watch file is a normal text (*.txt) file containing names, types, and addresses of watches.
  2. # like this document, which happens to be a valid watch file.
  3. # each line in the file can have one watch entry.
  4. # the '#' character starts a line comment (like this one).
  5. # comments are just plain text that gets ignored when importing watches from a watch file.
  6. # watches look like this:
  7.  
  8. "this is a watch" u16 0x80001234  # oh, comments can also appear at the end of a watch line
  9.  
  10. # the name of the watch goes first, contained in double quotes.
  11. # after it comes the data type. valid data types are:
  12. # u8,  s8,  x8  : one-byte value (signed format, unsigned format, hex format)
  13. # u16, s16, x16 : two-byte value (ditto)
  14. # u32, s32, x32 : four-byte value (ditto)
  15. # f32           : four-byte value, 32-bit ieee 754 single-precision floating-point format
  16.  
  17. # finally comes the address. in the example above, the address is just a simple hexadecimal number.
  18. # numbers can start with '0x' for hexadeciaml, '0b' for binary, '0' for octal,
  19. # or any digit other than zero for decimal.
  20. # but the address can also be a more complex expression, with arithmetic and indirection.
  21. # the available arithmetic operators are:
  22. # * / % : multiplication, division, and remainder
  23. # + -   : addition and subtraction
  24. # here's an example address with arithmetic operations:
  25.  
  26. "complex address with arithmetic" f32 5 * (3 + 4)
  27.  
  28. # the address in this example becomes the result of the arithmetic expression, which is equal to:
  29. # 5 * (3 + 4) = 5 * (7) = 35
  30. # obviously this isn't very useful, since you could have just written '35' as the address
  31. # (and also 35 isn't even a valid address). that's where indirection comes in.
  32.  
  33. # indirection is the act of replacing part of an expression with the value at the address given by that expression.
  34. # this is done by enclosing the sub-expression in [square brackets].
  35. # if we do this with the address in the first example we get:
  36.  
  37. "this is also a watch" u16 [0x80001234]
  38.  
  39. # this expression no longer means "the address i want is 0x80001234", but instead means
  40. # "the address i want is the value located at 0x80001234 in memory".
  41. # so whatever 32-bit value happens to be at 0x80001234 when this watch is imported,
  42. # that's going to be the address of the new watch.
  43. # this is useful for computing the address of dynamically loaded things, such as most actors.
  44. # the value given by the indirection doesn't need to be an actual address though.
  45. # it can be a smaller part that is needed to compute the address of a bigger expression.
  46. # the result of an indirection can be used in arithmetic just like any number. there can also be nested indirection:
  47. # [[0x80001234 + 0x20] + [0x80003210] * 0x31]
  48. # the expression above means: "add 0x20 to 0x80001234, then get the value at the resulting address.
  49. # multiply the value at 0x80003210 by 0x31. take these two values and add them together.
  50. # then, since the whole thing is enclosed in square brackets, get the value at the address resulting
  51. # from the last summation and use that as the new watch address."
  52.  
  53. # in all of the above uses of indirection, the type of the value to get is implicitly a 32-bit integer.
  54. # but, other types can be used as well by explicitly preceding the square brackets with a mode indicator.
  55. # the following modes are available:
  56. # b.[0x80001234]  : one-byte value, sign-extended to 32 bits.
  57. # bz.[0x80001234] : ditto, zero-extended to 32 bits.
  58. # h.[0x80001234]  : two-byte (16-bit halfword) value, sign-extended to 32 bits.
  59. # hz.[0x80001234] : ditto, zero-extended to 32 bits.
  60. # w.[0x80001234]  : four-byte value (32-bit word, the default mode when no mode is explicitly specified)
  61.  
  62. # finally, there are a few builtin symbols that can be used in address expressions.
  63. # whenever one of these are encountered, they are replaced by the address represented by that symbol.
  64.  
  65. "link x" f32 link + 0x24
  66.  
  67. # the above expression results in whatever address the link actor is loaded at, plus 0x24.
  68. # this happens to be the address of link's x-coordinate.
  69. # these symbols exist:
  70. # link  : gets replaced by the starting address of the link actor
  71. # ctxt  : gets replaced by the address of the global context
  72. # file  : gets replaced by the address of the current zelda file data
Add Comment
Please, Sign In to add comment