vblanknmi.asm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. ;this nmi uses a maximum of 20 scanlines while streaming brr frames to the spc
  2. NMI:
  3. php
  4. rep #$39
  5. pha
  6. phb
  7. phd
  8. phx
  9. phy
  10. lda.w #$0000
  11. tcd
  12. sep #$20
  13. lda.l $004210 ;reset nmi flag
  14. lda #$81
  15. pha
  16. plb
  17. stz.w $4201 ;clear iobit
  18. lda.b HdmaFlags ;check which hdma channels need to be activated
  19. and #$fc ;exclude channel #0,1(reserved for normal dma)
  20. sta.w $420C ;set hdma channels and disable dma channel
  21. rep #$31
  22. lda W12SEL
  23. sta $2123
  24. lda W1L
  25. sta $2126
  26. lda W2L
  27. sta $2128
  28. lda WBGLOG
  29. sta $212a
  30. lda WMS
  31. sta $212e
  32. sep #$20
  33. lda WOBJSEL
  34. sta $2125
  35. lda.b Mosaic
  36. sta.w $2106
  37. sep #$20
  38. ldx FrameCounterLo ;increment word framecounter
  39. inx ;
  40. stx FrameCounterLo ;
  41. lda ScreenMode ;set screenmode and bg sizes
  42. sta $2105 ;
  43. lda MainScreen ;setup main and subscreen
  44. sta $212c ;
  45. lda SubScreen ;setup main and subscreen
  46. sta $212d ;
  47. ;
  48. lda BGTilesVram12 ;set offsets in vram for tiles
  49. sta $210B ;of bg1 and bg2
  50. lda BGTilesVram34 ;set offsets in vram for tiles
  51. sta $210C ;of bg1 and bg2
  52. lda BG1TilemapVram ;set offset of bg1 tilemap in vram
  53. sta $2107 ;
  54. lda BG2TilemapVram ;set offset of bg2 tilemap in vram
  55. sta $2108 ;
  56. lda BG3TilemapVram ;set offset of bg3 tilemap in vram
  57. sta $2109 ;
  58. lda BG4TilemapVram ;set offset of bg3 tilemap in vram
  59. sta $210a ;
  60. lda.w CGWsel ;colour add/sub config
  61. sta $2130
  62. lda.w CgadsubConfig
  63. sta $2131
  64. lda.w FixedColourB
  65. and.b #%00011111
  66. ora.b #%10000000
  67. sta $2132
  68. lda.w FixedColourG
  69. and.b #%00011111
  70. ora.b #%01000000
  71. sta $2132
  72. lda.w FixedColourR
  73. and.b #%00011111
  74. ora.b #%00100000
  75. sta $2132
  76. lda BG1HOfLo ;set bg1 h-offset
  77. sta $210d ;
  78. lda BG1HOfHi ;
  79. sta $210d ;
  80. lda BG1VOfLo ;set bg1 v-offset
  81. sta $210e ;
  82. lda BG1VOfHi ;
  83. sta $210e ;
  84. lda BG2HOfLo ;set bg2 h-offset
  85. sta $210f ;
  86. lda BG2HOfHi ;
  87. sta $210f ;
  88. lda BG2VOfLo ;set bg2 v-offset
  89. sta $2110 ;
  90. lda BG2VOfHi ;
  91. sta $2110 ;
  92. lda ObjSel
  93. sta $2101
  94. ;this (writing to regs $4209,$4207,$4200) somehow breaks vblank flag setting in reg $4210,$4200)
  95. lda.b IrqRoutineNumberBuffer
  96. sta.b IrqRoutineNumber ;if this is zero, irqs are disabled
  97. beq NmiDisableHIrq
  98. rep #$31 ;store current h-counter in reg
  99. lda.b IrqVCounter
  100. sta.w $4209 ;v
  101. lda.b IrqHCounter
  102. sta.w $4207 ;h
  103. sep #$20
  104. lda.b InterruptEnableFlags
  105. ora.b #%00110000 ;enable v and h irq, will take effect next frame. irq is only triggered if both positions match
  106. sta.b InterruptEnableFlags
  107. sta.w $4200 ;should be ok. hope it breaks nothing
  108. bra NmiHIrqDone
  109. NmiDisableHIrq:
  110. sep #$20
  111. lda.b InterruptEnableFlags
  112. and.b #%11001111 ;disable h-irq
  113. sta.b InterruptEnableFlags
  114. sta.w $4200
  115. NmiHIrqDone:
  116. sep #$20
  117. lda.b #$80
  118. sta.w $2100
  119. ; jsr ProcessHdmaList
  120. jsr IrqCheckTilemapFlags
  121. jsr ProcessDmaFifo
  122. jsr IrqBrightness
  123. ; jsr DMATileMapToVramBG3
  124. ;moved to irq. that way, screen might turn black during long transfers, but at least the data gets uploaded reliably
  125. lda ScreenBrightness ;setup screen brightness
  126. and.b #$7f
  127. sta $2100
  128. jsr Random ;update random numbers
  129. jsr SpcHandlerMain
  130. rep #$31
  131. lda.b CheckJoypadMode
  132. and.w #%11
  133. asl a
  134. tax
  135. sep #$20
  136. jsr (CheckJoypadModeLUT,x)
  137. rep #$39
  138. ply
  139. plx
  140. pld
  141. plb
  142. pla
  143. plp
  144. rts
  145. rti ;return from nmi