Jump to content

Photo

Randomize virtual player colors in DPC+?


14 replies to this topic

#1 jrok OFFLINE  

jrok

    Stargunner

  • 1,155 posts

Posted Fri May 13, 2016 11:34 AM

I've noticed it's fairly straightforward to randomize P0's colors with the statement:
 
 player0color = rand

 

Is there a similarly simple method of assigning random colors to a virtual player?

 

Thanks,


Edited by jrok, Fri May 13, 2016 11:39 AM.


#2 RevEng OFFLINE  

RevEng

    River Patroller

  • 4,839 posts
  • Bitnik
  • Location:bottom of the stack

Posted Fri May 13, 2016 5:09 PM

It's not as simple with DPC+. DPC+ maintains ARM memory pointers to virtual player's color, so you need to call a DPC+ function to update these pointer values.

For player1color: it would look like...
 
 asm
 lda #<(playerpointers+18)
 sta DF0LOW
 lda #(>(playerpointers+18)) & $0F
 sta DF0HI
 LDX rand
 STX DF0WRITE
 LDA #0
 STA DF0WRITE
end

For player2colors change the 18's to 20's. For player3colors: change the 18's to 22's. Keep adding +2 for later colors.

#3 jrok OFFLINE  

jrok

    Stargunner

  • Topic Starter
  • 1,155 posts

Posted Fri May 13, 2016 6:27 PM

Thank you!



#4 jrok OFFLINE  

jrok

    Stargunner

  • Topic Starter
  • 1,155 posts

Posted Mon May 16, 2016 4:15 PM

I have related question:

 

Suppose I wanted to do the following:

 

- Define the colors for each line of a virtual sprite (in a data statement, I'm guessing?  Then push them into the sprite?)

- Add a multiple of 16 to each line when the code is run.

 

I'm trying to build a palette swapping function, preserving each line's brightness while shifting the hue.

 

Thanks again.



#5 RevEng OFFLINE  

RevEng

    River Patroller

  • 4,839 posts
  • Bitnik
  • Location:bottom of the stack

Posted Mon May 16, 2016 7:53 PM

Ok, so I dug into this a bit more and refreshed myself on the details... I've updated my previous explanation as a result, but the code I gave earlier still holds.

Changing the hue values isn't going to happen easily. When you use player#colors: with DPC+, the color values are stored in "ROM" same as with other kernels. bB then sets up the ARM player#color pointers to point to where that ROM color data appears in ARM memory.

Since it's all in ROM, you'd first need to change that ARM pointer to point to ARM RAM instead, so you can modify the contents. I tried pointing it to the bB DPC+ stack page, but that didn't seem to work correctly.

I'm sure I'm missing some ARM pointer implementation detail, but I've reached the limit of my knowledge here.

#6 jrok OFFLINE  

jrok

    Stargunner

  • Topic Starter
  • 1,155 posts

Posted Tue May 17, 2016 12:33 AM

No worries.  Just in case I wasn't explaining myself right, I wrote a little test program a while back that does a similar color swap with the playfield object.


 set kernel DPC+
 
 dim PF_line = a
 dim chroma = b
 dim chroma_shift = c
 
 goto Start bank2
 
 bank 2
 
Start
 
 playfield:
 ..............XXX...............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 .............XXXXX..............
 ..............XXX...............
end
 
 data zonelumshift
 $00,$00,$02,$02,$04,$06,$08,$0A,$0C,$0E,
 $00,$00,$00,$02,$02,$02,$04,$04,$04,$06,
 $02,$02,$04,$04,$02,$02,$04,$04,$02,$02,
 $00,$02,$04,$06,$08,$08,$06,$04,$02,$00,
 $00,$02,$00,$04,$00,$06,$00,$08,$00,$0A
end 
 
 chroma = 16
 
WritePFColorLoop
 
 DF0FRACINC=128
 DF1FRACINC=128
 DF2FRACINC=128
 DF3FRACINC=128
 DF4FRACINC=128
 DF6FRACINC=128
 
 DF7HI = 10
 DF7LOW = 52
 
PFColor
 for temp1 = 0 to zonelumshift_length
    DF7PUSH = zonelumshift[PF_line] + chroma
    PF_line = PF_line + 1
 next
 PF_line = 0
 
 rem  Press and release the fire button to change the color
 if joy0fire then chroma_shift = 1
 if !joy0fire && chroma_shift then chroma_shift = 0 : chroma =  chroma + 16
 
 drawscreen
 
 goto WritePFColorLoop
 

It's been a couple of years since I've tucked into bB, and I forget how I determined the hi and lo pointers for the playfield.  I assume I could use a similar technique to color the background, right?


Edited by jrok, Tue May 17, 2016 9:53 AM.


#7 RevEng OFFLINE  

RevEng

    River Patroller

  • 4,839 posts
  • Bitnik
  • Location:bottom of the stack

Posted Tue May 17, 2016 9:34 AM

I assume I could use a similar technique to color the background, right?


Sort of confused if we're talking about sprite colors or background playfield colors. Your earlier post talked about sprite colors, here you mention background [playfield] colors.

bB DPC+ playfields (and colors) are RAM based, and can be modified, swapped, etc. bB DPC+ players (and colors) are pointers to ROM, which can't be modified. (in theory, you can point them to RAM, and modify the RAM, but I can't get this to work.)

If you wish to modify the PF background color, change the "DF7HI" index to point to another queue/page in your example. IIRC, it's probably 11 for background colors. The "DF7LOW" value is the byte offset within the playfield data.

#8 jrok OFFLINE  

jrok

    Stargunner

  • Topic Starter
  • 1,155 posts

Posted Tue May 17, 2016 5:12 PM

Sort of confused if we're talking about sprite colors or background playfield colors. Your earlier post talked about sprite colors, here you mention background [playfield] colors.

bB DPC+ playfields (and colors) are RAM based, and can be modified, swapped, etc. bB DPC+ players (and colors) are pointers to ROM, which can't be modified. (in theory, you can point them to RAM, and modify the RAM, but I can't get this to work.).

 

Sorry, I drifted off topic there.  Yeah, that was the original question, I just included that sample in case I wasn't explaining the desired (sprite) effect well enough. 

 

 

If you wish to modify the PF background color, change the "DF7HI" index to point to another queue/page in your example. IIRC, it's probably 11 for background colors...

 

 

Yes, it is.  I tried to RTFM for this, but I couldn't find it documented anywhere.  Thanks, again.



#9 RevEng OFFLINE  

RevEng

    River Patroller

  • 4,839 posts
  • Bitnik
  • Location:bottom of the stack

Posted Tue May 17, 2016 7:44 PM

No worries. Glad to help!

#10 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Star Raider

  • 81 posts

Posted Tue Apr 17, 2018 7:03 PM

I've been playing around with changing the pf and bgcolors for a couple days and came up with a really cool thing for my game but now that I got a chance to try it on real hardware it doesn't change anything, so I tried jrok's code and it works in stella but just boots a black screen on real hardware (mine atleast)

 

Here's my little test that does boot up but doesn't change anything like it does in stella, Something wrong with my code? like byte offset (I used the d variable to pick those numbers) or has this never worked on real hardware?

 

Attached File  colorchange.bas   7.12KB   20 downloads



#11 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Star Raider

  • 81 posts

Posted Tue May 1, 2018 9:46 AM

I really need some help with my question above.



#12 Karl G ONLINE  

Karl G

    Moonsweeper

  • 378 posts

Posted Tue May 1, 2018 9:59 AM

At least as a starting point, your playfield definition is messed up.  It is inconsistently indented (which makes it hard to read), some lines are not indented at all (everything other than the "end" statement needs to be indented by at least once character), and some lines are the wrong length (all of them should be 32 characters).



#13 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Star Raider

  • 81 posts

Posted Wed May 2, 2018 5:00 PM

Ok I fixed that, and changed every temp variables to regular ones, moved some stuff around and tried different things until I thought it could only be the value for DF7LOW that's wrong, so I changed it to a counter and thought it must hit the right number some time and have some effect? So right now in stella the pf and bgcolors scrolls and you can change colors with the fire button, but on real hardware it has no effect..

 

 

   d=d+1 ;df7low counter
   if joy0fire then chroma =  chroma + 16
 
  DF7HI = 10
  DF7LOW = d
 
 ;.............................rails
 PF_line = 0
 
PFColor
 for e = 1 to 9
    DF7PUSH = zonelumshift[PF_line] + chroma
    PF_line = PF_line + 1
 next
 
 
 ;...........................top wall
 PF_line = 0
 
  DF7HI = 11
  DF7LOW = d
 
  for e = 1 to 10
    DF7PUSH = zonelumshift3[PF_line] + chroma
    PF_line = PF_line + 1
 next
 
 
 ;...........................bottom wall
  PF_line = 0
 
  DF7HI = 11
  DF7LOW = d
 
  for e = 1 to 10
    DF7PUSH = zonelumshift2[PF_line] + chroma
    PF_line = PF_line + 1
 next
 
 
 
 
Just a normal display of the colors in the initialization????
 
Attached File  colorchange (2).bas   7.02KB   13 downloads

Edited by Lillapojkenpćön, Wed May 2, 2018 5:01 PM.


#14 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Star Raider

  • 81 posts

Posted Fri May 4, 2018 8:48 AM

Got it to work

 

Attached File  colorchange (5).bas   6.35KB   14 downloads



#15 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Star Raider

  • 81 posts

Posted Tue May 8, 2018 9:19 AM

I have a related question..

Does storing values to DF0HI, DF0LOW and DF0PUSH take alot of cycles similar to using the stack?






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users