predef.asm 930 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. Predef::
  2. ; Call predefined function a.
  3. ; To preserve other registers, have the
  4. ; destination call GetPredefRegisters.
  5. ; Save the predef id for GetPredefPointer.
  6. ld [wPredefID], a
  7. ; A hack for LoadDestinationWarpPosition.
  8. ; See LoadTilesetHeader (predef $19).
  9. ld a, [H_LOADEDROMBANK]
  10. ld [wPredefParentBank], a
  11. push af
  12. ld a, BANK(GetPredefPointer)
  13. ld [H_LOADEDROMBANK], a
  14. ld [MBC1RomBank], a
  15. call GetPredefPointer
  16. ld a, [wPredefBank]
  17. ld [H_LOADEDROMBANK], a
  18. ld [MBC1RomBank], a
  19. ld de, .done
  20. push de
  21. jp hl
  22. .done
  23. pop af
  24. ld [H_LOADEDROMBANK], a
  25. ld [MBC1RomBank], a
  26. ret
  27. GetPredefRegisters::
  28. ; Restore the contents of register pairs
  29. ; when GetPredefPointer was called.
  30. ld a, [wPredefRegisters + 0]
  31. ld h, a
  32. ld a, [wPredefRegisters + 1]
  33. ld l, a
  34. ld a, [wPredefRegisters + 2]
  35. ld d, a
  36. ld a, [wPredefRegisters + 3]
  37. ld e, a
  38. ld a, [wPredefRegisters + 4]
  39. ld b, a
  40. ld a, [wPredefRegisters + 5]
  41. ld c, a
  42. ret