Jump to content
  • entries
    334
  • comments
    900
  • views
    258,189

Whoops part 2


Guest

476 views

Yes, the WIP is almost done. I just need to add in the new digging sprites (and redo the old ones which I did by hand).Unfortunately, I'm going to have to find someplace to squeeze them in. I had this great idea about how to squeeze in the REFPn bit, but it didn't pan out. At one point I noticed that HMPn only uses the top 4 bits while REFPn uses bit 3. Ah-ha! I thought. If I multiply XPOS by two, change the SBC #15 in the repositioning routine to SBC #30, and double the HPOS table, I can make the LSB of XPOS be the left/right bit, and put the REFPn bit in the HPOS table. Cool! That means REFPn won't require an extra read, and there just happens to be 3 extra cycles in the current kernel which could be used to update REFPn. I even came up with a using AND/CMP/ROL to put the right/left bit into the XPOS LSB.Unfortunately, I'd forgotten that my repositioning routine assumes the sprite is unused if the MSB is set. So the sprites on the right side of the screen disappeared. Took me a bit to figure it out / remember. Sigh.So REFPn get postponed until the great kernel rewrite (not the reflection kernel, but removing the need for the forground bitmaps). Which, unfortunately, means I have to find 40 free bytes to squeeze in two sprites.Oh, I also loaded Leprechaun onto my CC2 (LEPRCH00 SC SC) for some real-life testing. One thing I immediately noticed (especially since I flipped the PF/player priority) was the green enemies were a little tough to see. The player is also a little dark. I'll try to remember to bump up the luma a little in this next WIP.

3 Comments


Recommended Comments

I'm really enjoying both playing the WIPs and reading about their development. Fun stuff, and I'm picking up some tips, too. :)

 

I'm looking forward to the WIP with digging; it is really hard if you can't dig!

Link to comment
I'm really enjoying both playing the WIPs and reading about their development.  Fun stuff, and I'm picking up some tips, too. :)

 

I'm looking forward to the WIP with digging; it is really hard if you can't dig!

I'd be interesting in finding out what tips you've picked up.

 

One item I rediscovered when creating the gold blit routine (below) was how to write processing loops on the 6502 where registers, cycles & RAM are precious.

 

Basically you write from the inside out, almost the reverse of traditional programming. Start with the chunk of code inside the innermost loop and code it as efficiently as possible. Then code the end of the loop (typically DEX, BNE or BPL). Finally code your loop initialization. If you have loops inside of loops code the inner loop initialization at the same time you code the end of the outer loop.

 

Take a break, then go back and re-write it; checking every assumption and every branch destination. Double check that registers contain what is needed at each point.

 

I'm finding it a good habit to note in the comments any non-obvious assumptions or tricks I've used like the state of the carry bit. That way if I make changes to the code later I can easily re-validate those assumptions.

 

   lda    #<GMASK0    ; offset of gold
   sta    FG_PTR
   lda    #PF_YMAX/8-1; start at bottom of gold
   sta    TEMP
   lda    #PF_YMAX-4  ; start at bottom of background
4$
   sta    PF_PTR
   ldx    #>BGBM0+$E0 ; offset to $FC-$FF
3$
   stx    PF_PTR+1    ; save bank pointers
   stx    FG_PTR+1
   ldy    TEMP        ; gold byte pointer
   lda    (FG_PTR),y  ; load mask
   beq    2$          ; nothing to do!
   sta    TEMP2       ; save mask
   ldy    #2          ; three lines 2-0 (6-4)
1$
   lda    TEMP2       ; load mask
   ora    (PF_PTR),y  ; add gold to background
   tax
   lda    SCDATA,x    ; SuperCharger write
   lda    (PF_PTR),y
   dey                ; next line
   bpl    1$
2$
   ldx    PF_PTR+1    ; next bank
   inx
   bne    3$          ; loop
   dec    TEMP        ; next row
   bmi    9$          ; done!
   lda    PF_PTR      ; update background pointer
   sec
   sbc    #8
   bne    4$
9$

Believe it or not, this routine worked the first time. Notice the labels are from the inside out. One of the decision points I had to make was whether to loop over the bitmaps or the banks first. It turned out looping over the banks was easier, so it became the middle loop.

 

I played with the idea of using the Stack Pointer as temporary storage, but LDA ZP required one less cycle than TSX/TXA.

 

There's some other tricks in with the offsets & index registers.

Link to comment
I'd be interesting in finding out what tips you've picked up.

The interesting way you multiplexed your sprites, for one thing. I haven't yet quite wrapped my head around intelligent flicker, so I'm always trying to pick up ideas on that.

Also, this:

At one point I noticed that HMPn only uses the top 4 bits while REFPn uses bit 3. Ah-ha! I thought. If I multiply XPOS by two, change the SBC #15 in the repositioning routine to SBC #30, and double the HPOS table, I can make the LSB of XPOS be the left/right bit, and put the REFPn bit in the HPOS table. Cool!

That's very interesting...I've never thought of doubling the x position of something and then subtracting 30 instead of 15 in order to get an extra bit into the table of HMxx values. Cool is right!

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...