vblank.asm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. VBlank::
  2. push af
  3. push bc
  4. push de
  5. push hl
  6. ld a, [H_LOADEDROMBANK]
  7. ld [wVBlankSavedROMBank], a
  8. ld a, [hSCX]
  9. ld [rSCX], a
  10. ld a, [hSCY]
  11. ld [rSCY], a
  12. ld a, [wDisableVBlankWYUpdate]
  13. and a
  14. jr nz, .ok
  15. ld a, [hWY]
  16. ld [rWY], a
  17. .ok
  18. call AutoBgMapTransfer
  19. call VBlankCopyBgMap
  20. call RedrawRowOrColumn
  21. call VBlankCopy
  22. call VBlankCopyDouble
  23. call UpdateMovingBgTiles
  24. call $ff80 ; hOAMDMA
  25. ld a, BANK(PrepareOAMData)
  26. ld [H_LOADEDROMBANK], a
  27. ld [MBC1RomBank], a
  28. call PrepareOAMData
  29. ; VBlank-sensitive operations end.
  30. call Random
  31. ld a, [H_VBLANKOCCURRED]
  32. and a
  33. jr z, .skipZeroing
  34. xor a
  35. ld [H_VBLANKOCCURRED], a
  36. .skipZeroing
  37. ld a, [H_FRAMECOUNTER]
  38. and a
  39. jr z, .skipDec
  40. dec a
  41. ld [H_FRAMECOUNTER], a
  42. .skipDec
  43. call FadeOutAudio
  44. ld a, [wAudioROMBank] ; music ROM bank
  45. ld [H_LOADEDROMBANK], a
  46. ld [MBC1RomBank], a
  47. cp BANK(Audio1_UpdateMusic)
  48. jr nz, .checkForAudio2
  49. .audio1
  50. call Audio1_UpdateMusic
  51. jr .afterMusic
  52. .checkForAudio2
  53. cp BANK(Audio2_UpdateMusic)
  54. jr nz, .audio3
  55. .audio2
  56. call Music_DoLowHealthAlarm
  57. call Audio2_UpdateMusic
  58. jr .afterMusic
  59. .audio3
  60. call Audio3_UpdateMusic
  61. .afterMusic
  62. callba TrackPlayTime ; keep track of time played
  63. ld a, [hDisableJoypadPolling]
  64. and a
  65. call z, ReadJoypad
  66. ld a, [wVBlankSavedROMBank]
  67. ld [H_LOADEDROMBANK], a
  68. ld [MBC1RomBank], a
  69. pop hl
  70. pop de
  71. pop bc
  72. pop af
  73. reti
  74. DelayFrame::
  75. ; Wait for the next vblank interrupt.
  76. ; As a bonus, this saves battery.
  77. NOT_VBLANKED EQU 1
  78. ld a, NOT_VBLANKED
  79. ld [H_VBLANKOCCURRED], a
  80. .halt
  81. halt
  82. ld a, [H_VBLANKOCCURRED]
  83. and a
  84. jr nz, .halt
  85. ret