Advertisement
Guest User

SNES Utils

a guest
Oct 20th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //******************************************************************************
  2. //* snes_utils.inc
  3. //* (c) 2016 qwertymodo
  4. //*
  5. //* Some basic SNES utility macros.  Currently only supports standard Hi/LoROM.
  6. //*
  7. //* seek: Sets PC to the input address and moves the write pointer according to
  8. //*       defined Hi/LoROM mapping.
  9. //*
  10. //* sseek: Sets PC to the SlowROM equivalent of the input address, regardless
  11. //*        of FastROM definition and sets the write pointer according to
  12. //*        defined HiROM/LoROM mapping.
  13. //*
  14. //* fseek: Sets PC to the FastROM equivalent of the input address if FastROM is
  15. //*        defined, otherwise directly to the given address, and sets the write
  16. //*        pointer according to defined Hi/LoROM mapping.
  17. //*
  18. //* org:   xkas compatibility macro.  Simple alias for seek.
  19. //*
  20. //* jmf:   Jump Long FastROM.
  21. //*
  22. //* jsf:   Jump to Subroutine Long FastROM.
  23. //******************************************************************************
  24.  
  25. if !{defined _snes_utils_inc} {
  26. define _snes_utils_inc()
  27.  
  28. if {defined fastrom} {
  29.     define rombank($800000)
  30. } else {
  31.     define rombank($000000)
  32. }
  33.  
  34.  
  35. macro seek(variable address) {
  36.     if {defined hirom} {
  37.         origin (address) & $3FFFFF
  38.         base address
  39.     } else if {defined exhirom} {
  40.         origin (address & 0x3fffff) | ((~address >> 1) & 0x400000)
  41.         base address
  42.     } else { // default to lorom
  43.         origin ((address & $7F0000) >> 1) | (address & $7FFF)
  44.         base address
  45.     }
  46. }
  47.  
  48.  
  49. macro sseek(variable address) {
  50.     if {defined hirom} {
  51.         origin (address) & $3FFFFF
  52.         base address & ~{rombank}
  53.     } else if {defined exhirom} {
  54.         origin (address & 0x3fffff) | ((~address >> 1) & 0x400000)
  55.         base address & ~{rombank}
  56.     } else {
  57.         origin ((address & $7F0000) >> 1) | (address & $7FFF)
  58.         base address & ~{rombank}
  59.     }
  60. }
  61.  
  62.  
  63. macro fseek(variable address) {
  64.     if {defined hirom} {
  65.         origin (address) & $3FFFFF
  66.         base address | {rombank}
  67.     } else if {defined exhirom} {
  68.         origin (address & 0x3fffff) | ((~address >> 1) & 0x400000)
  69.         base address | {rombank}
  70.     } else {
  71.         origin ((address & $7F0000) >> 1) | (address & $7FFF)
  72.         base address | {rombank}
  73.     }
  74. }
  75.  
  76.  
  77. macro org(variable address) {
  78.     seek(address)
  79. }
  80.  
  81.  
  82. macro jmf(variable address) {
  83.     jml address | {rombank}
  84. }
  85.  
  86.  
  87. macro jsf(variable address) {
  88.     jsl address | {rombank}
  89. }
  90.  
  91.  
  92. macro assert_end(variable address) {
  93.     if pc() & ~{rombank} > (address & ~{rombank}) {
  94.         evaluate size((pc() & ~{rombank}) - (address & ~{rombank}))
  95.         seek(address)
  96.         evaluate offset(origin())
  97.         error "{size} byte overrun occurred at file offset {offset}"
  98.     }
  99. }
  100.  
  101.  
  102. macro CHECKSUM(variable sum) {
  103.     seek($FFDC)
  104.     dw sum^$FFFF, sum
  105. }
  106.  
  107.  
  108. if {defined input} {
  109.     insert "{input}"
  110. }
  111.  
  112.  
  113. } // _snes_utils_inc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement