Ok - now I'm not *that far* away from implementing this. I'm circling the drain and generally am able to substitute values for the bottom half to get different palettes from the menu bar. I'm having trouble (presumably) with getting the hblank timing right, and still having slight issues getting the scrolling right. Perhaps filling in these gaps in my understanding will help me get this fully functional. Mind you, a lot of this is from your collective posts, searching the forums, and trial and error, so there may be some ugliness or redundancy here...this is more the blunt instrument approach, and now I need someone with a shaper set of proverbial tools.
First I want to get things lining up right, and then I'll worry about protections against sprite zero misses.
In the vBlank, I take care of the initial run through the palettes. After which, the code looks something like this:
Code:
LDA readyToCheckSpr0 ;; making sure nametable is loaded and sprties are drawn before checking for a sprite 0 hit
;; early vBlanks were happening before nametable / sprites were being loaded / drawn
;; causing hit to fail and the game freezing.
BEQ skipWaitingForSpriteZeroHit
;; turn on rendering to check for sprite 0 hit
LDA #%000111110
STA $2001
LDA #%10010000
STA #2000
;; check for sprite 0 hit
WaitNotSprite0: ;; I know there is a better way to do this as described...again, this is blunt-instrumenting
LDA $2002
AND #%01000000
BNE WaitNotSprite0
WaitSprite0: ;; I know there is a better way to do this as described...again this is blunt-instrumenting
LDA $2002
AND #%01000000
BEQ WaitSprite0
;;;;; sprite 0 is now detected (it is at #$b0 - i think the first pixel hit is a few pixels later), so now wait until end of scanline for beginning of hblank
LDX #$08 ;; arbitrary number here as to how long it takes to get to end of scanline
WaitScanline:
DEX
BNE WaitScanline:
;;;;;;;; presumably, now we are in hBlank, if the above wait was timed right.
;;;;;;; my guess is I should put the writes to 2006 and turning off rendering *before* waiting for the scanline so less is done
;;;;;; during the hblank, and this can substitute for some of the loop time...is that sound?
bit $2002
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDA #$00
STA $2001
STA $2000
;;;;;;;; change the palette
bit $2007
bit $2007
bit $2007
LDA #$18 ;; brown
STA $2007 ;;; now the last value in the first subpalette should be *brown*
;;;; now we have to set 2006/2005/2005/2006 to match the scroll position...
;;;; this part has been really tricky. I'm not sure exactly where or what to adjust.
;;; for now, I'm doing two writes to $2006, i've tried sandwiching two writes to $2005 between, I've tried many
;;;; arbitrary values but am not ever really getting results I expect.
;;; this gets me close to lined up:
LDA #$00
STA $2006
LDA #$c8
STA $2006
;;; now that scroll is lined up, wait for the hblank again to continue on?
LDX #$08 ;; i know this value will have to be played with to get it right
WaitScanLine2:
DEX
BNE WaitScanLine2
skipWaitingForSpriteZeroHit: ;; if the nametable / sprite 0 were not loaded/drawn yet, from above.
Again, this gets me super close. You can see in the image the brown - it is replacing the *peach* color spot (in the topmost part of the screen, peach is subpal0, color 3...below brown is subpal0 color3...Eureka, it works!
but...not quite there...)
Attachment:
close.png [ 3.42 KiB | Viewed 719 times ]
So...the immediate questions become, how do I better finely adjust the y-scroll (played around with writes to $2005...this didn't seem to work, so I suppose I'm doing something wrong), and also, how to adjust my scan-line waits correctly to properly get to start of hblank?
Additionally - I liked the idea of loading A,X,andY with the color values and firing them off, but in this context I don't see how that would be possible since I'm using two of those values in the scanline wait for hblank loop. Would love thoughts on that.