Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. ;------------------------------------------------------------------------------
  2. ; [ efram chunk ]
  3. ; I wrote this because I needed something that could bank in/out the
  4. ; EasyFlash code, perform copies and memory swaps, and not occupy RAM
  5. ; where the game exists, all while fitting in the lower half of the
  6. ; page (because EasyAPI uses the upper half.)
  7. ; This starts at $DF03 to give us XBANK address at $DF00 and two
  8. ; variables to do whatever with at $DF01 and $DF02. Plus it fits nicely
  9. ; if you think of this as a jumptable entry address or something.
  10. ; (Don't mind my rants, these are notes to help ME think.)
  11. ;------------------------------------------------------------------------------
  12.  
  13. .scope EFRAM
  14. BASE = $DF03-START
  15.  
  16. ;------------------------------------------------------------------------------
  17. ; [ rom call jump ]
  18. ; A = low address to jump. If high address is needed too, write it
  19. ; externally or something. I use $A000 because it fits my driver.
  20. ;------------------------------------------------------------------------------
  21.  
  22. START:
  23. sta ROMADDR+1+BASE
  24. jsr ENABLE+BASE
  25. ROMADDR: jsr $A000
  26.  
  27. ;------------------------------------------------------------------------------
  28. ; [ disable ef-rom ]
  29. ; Turn off the EasyFlash LED and banking.
  30. ; The "bne" instruction is used at the end to save space.
  31. ;------------------------------------------------------------------------------
  32.  
  33. DISABLE:
  34. ROMCONF: lda #$F5
  35. pha
  36. lda #%00000100
  37. bne SWCOMMON
  38.  
  39. ;------------------------------------------------------------------------------
  40. ; [ swap ]
  41. ; note: source and destination must be written externally.
  42. ; Use SWAPSRC1, SWAPSRC2, SWAPDST1, and SWAPDST2.
  43. ; $FFFF is used as a temp address because it's all one bits and this
  44. ; somehow benefits the life of the EasyFlash.
  45. ; This only does up to one page at a time (the length is determined by
  46. ; the X register) and banks out EasyFlash during the operation. It will
  47. ; bank EasyFlash back in after it is finished.
  48. ; Also note that due to the way the indexing is done, the swapping will
  49. ; start at ADDRESS+1. Not a problem if X is zero, it will do a whole
  50. ; page. But keep this in mind for all other values.
  51. ;------------------------------------------------------------------------------
  52.  
  53. SWAP:
  54. .scope SWAPSEC
  55. jsr DISABLE+BASE
  56. LOOP:
  57. SRC1: lda $FFFF,x
  58. DST1: ldy $FFFF,x
  59. DST2: sta $FFFF,x
  60. tya
  61. SRC2: sta $FFFF,x
  62. dex
  63. bne LOOP
  64. .endscope
  65.  
  66. ;------------------------------------------------------------------------------
  67. ; [ enable ef-rom ]
  68. ; All other roms are enabled as a side-effect & EasyFlash LED is on.
  69. ;------------------------------------------------------------------------------
  70.  
  71. ENABLE:
  72. lda $01
  73. sta ROMCONF+1+BASE
  74. ora #$07
  75. pha
  76. lda #%10000111
  77.  
  78. ;------------------------------------------------------------------------------
  79. ; [ set ef-rom state ]
  80. ; A = EasyFlash $DE02 state
  81. ;------------------------------------------------------------------------------
  82.  
  83. SWCOMMON:
  84. sta $DE02
  85. pla
  86. sta $01
  87.  
  88. ;------------------------------------------------------------------------------
  89. ; [ retore bank ]
  90. ; This is the ONLY return point from the loader.
  91. ; All functions lead here. Functions may also JSR here just to set
  92. ; the EasyFlash bank.
  93. ;------------------------------------------------------------------------------
  94.  
  95. SETBANK:
  96. BNK: lda #$01
  97. RESTBNK:
  98. sta $DE00
  99. rts
  100.  
  101. ;------------------------------------------------------------------------------
  102. ; [ copy ]
  103. ; note: source and destination must be written externally to
  104. ; SRC+1/SRC+2 and DST+1/DST+2.
  105. ; X = highbyte length (two's complement)
  106. ; Y = lowbyte length (two's complement)
  107. ; The "bne RESTBNK" line is the *actual* exit point in this function.
  108. ; I have tried a number of methods and this hybrid self-modifying and
  109. ; absolute-indexing method is the fastest I could get. It does require
  110. ; a bit of setup due to the file length needing to be two's complement.
  111. ; Even using zeropage was slower because of the indirect addressing.
  112. ; BIT+BVC is used to determine if we are crossing EasyFlash banks.
  113. ; Due to this, you CANNOT tell it not to use the high bank. However,
  114. ; by writing different values to COPYWRP you can at least tell it you
  115. ; don't want the low bank (the value $A0 will work OK for this.) The
  116. ; default wrap value is $80.
  117. ;------------------------------------------------------------------------------
  118.  
  119. COPY:
  120. .scope COPYSEC
  121. jsr SETBANK+BASE
  122. LOOP:
  123. SRC: lda $FFFF,y
  124. DST: sta $FFFF,y
  125. iny
  126. beq BANKCHK
  127. CTROK:
  128. inx
  129. bne LOOP
  130. inc LEN+BASE
  131. bne LOOP
  132. lda #$01
  133. sta BNK+1+BASE
  134. bne RESTBNK
  135. BANKCHK:
  136. inc SRC+2+BASE
  137. inc DST+2+BASE
  138. bit SRC+2+BASE
  139. bvc CTROK
  140. WRP: lda #$80
  141. sta SRC+2+BASE
  142. inc BNK+1+BASE
  143. jsr SETBANK+BASE
  144. jmp CTROK+BASE
  145. LEN: .byte $00
  146. .endscope
  147.  
  148. ;------------------------------------------------------------------------------
  149. ; [ footer ]
  150. ; I used to put padding here, but now that this routine is pretty much
  151. ; finished I removed it.
  152. ;------------------------------------------------------------------------------
  153.  
  154. END:
  155. .endscope
  156. EFRAMSIZE = EFRAM::END-EFRAM::START
  157.  
  158. ;------------------------------------------------------------------------------
  159. ; [ exports ]
  160. ; To be used when writing internal variables externally.
  161. ;------------------------------------------------------------------------------
  162.  
  163. EFMEMCONF := EFRAM::ROMCONF+1+EFRAM::BASE
  164. EFDISABLE := EFRAM::DISABLE+EFRAM::BASE
  165. EFENABLE := EFRAM::ENABLE+EFRAM::BASE
  166. EFCOPY := EFRAM::COPY+EFRAM::BASE
  167. COPYSRC := EFRAM::COPYSEC::SRC+1+EFRAM::BASE
  168. COPYDST := EFRAM::COPYSEC::DST+1+EFRAM::BASE
  169. COPYBNK := EFRAM::BNK+1+EFRAM::BASE
  170. COPYWRP := EFRAM::COPYSEC::WRP+1+EFRAM::BASE
  171. COPYLEN := EFRAM::COPYSEC::LEN+EFRAM::BASE
  172. EFSWAP := EFRAM::SWAP+EFRAM::BASE
  173. SWAPSRC1 := EFRAM::SWAPSEC::SRC1+1+EFRAM::BASE
  174. SWAPSRC2 := EFRAM::SWAPSEC::SRC2+1+EFRAM::BASE
  175. SWAPDST1 := EFRAM::SWAPSEC::DST1+1+EFRAM::BASE
  176. SWAPDST2 := EFRAM::SWAPSEC::DST2+1+EFRAM::BASE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement