Jump to content
Lillapojkenpåön

Some DPC+ color examples

Recommended Posts

Here's some bB examples of stuff that's not easy to figure out, so might save somebody some time.

 

 

 

Change color behind score without minikernel

CHANGE_COLOR_BEHIND_SCORE.bas

 

Change scorecolor

SCORE_COLORCYCLE.bas

 

Change playfieldcolor on any row/rows you want

CHANGE_PLAYFIELD_COLOR.bas

 

Change backgroundcolor on any row/rows you want

CHANGE_BACKGROUND_COLOR.bas

 

 

 

I'll try and come up with some more.

  • Like 5

Share this post


Link to post
Share on other sites

This is awesome and might be just what I needed to get over my developmental hump!

 

Currently I had an issue where I would change parts of the playfield colors but had a difficult time changing them back when done with them. Probably an easy fix that I'm just not seeing but this might be an easier way then what I had been working with!

Edited by KevKelley

Share this post


Link to post
Share on other sites

I was looking at the example code. I kind of understand it but trying to adapt it into my program is boggling me.

 

I see how moving the cursor and pressing fire changes the color but what is confusing me is how to basically have a line
(or couple lines change together) and how exactly everything works, like the purpose of the constants or what these do DF0LOW, DF0HI, DF0PUSH?

Share this post


Link to post
Share on other sites

I might be wrong but this is how I understand it..

 

I recently had to ask about the constants myself and why you couldn't just do this

DF0LOW = #<(PFCOLS)
DF0HI = #(>PFCOLS) & $0F
RevEng had this to say:
"the "#" "<" and ">" value modifiers don't really belong to the language proper, they come from assembly language. So the parsing that happens during regular variable assignments doesn't work with them, but the const command doesn't do any parsing and passes them to the underlying assembly code intact"
So it's just a workaround to get the correct values when using bB, if you use inline assembly you don't need the constants
asm
lda #<(PFCOLS)
sta DF0LOW
lda #(>PFCOLS) & $0F
sta DF0HI
end

If you open bB.1.1d.reveng41 / includes / DPCplusbB you'll see that just like A is a nickname for a RIOT RAM address, PFCOLS is a nickname for a DPC RAM address, and the next 256 bytes after that is reserved for playfield color data,

 

the kernel points a Fractional Data Fetcher to that data..

lda <PFCOLS
sta DF4FRACLOW
lda (>PFCOLS) & $0F
sta DF4FRACHI
then reads that data every other line and stores it to the colupf register
lda #<DF4FRACDATA
sta COLUPF
how often the colors are updated depends on how you set up DF4FRACINC before drawscreen
DF4FRACINC = 255 will increment the fetcher after every read and update the color every other line
DF4FRACINC = 128 will icrement the fetcher every other read and update the color every fourth line etc.
These fetchers are part of why there's time to do so much in the DPC+ kernel, because they increment automaticly after each read, depending on how you primed them.
Anyway, this code just points to the color data and pushes new values into it, here's an assembly example if that makes more sense,
if you wanted three rows to be white, and those three rows to be another three rows from the top of the screen
asm
lda #<(PFCOLS+6) ; point to the sixth byte in the color data
sta DF0LOW
lda #(>PFCOLS) & $0F
sta DF0HI
lda $0E ; white
sta DF0PUSH ; changes the sixth byte/row
sta DF0PUSH ; changes the fifth byte/row
sta DF0PUSH ; changes the fourth byte/row
end

Share this post


Link to post
Share on other sites

Okay. I think I understand. I had originally thought I was going crazy when I combed through Random Terrain's website and admittedly, when I look through many of the sample programs online I have a hard time figuring them out while they can be very well documented and rather straightforward... But I find them extremely valuable in my learning. I find this helpful since my end goal is to learn batariBasic and eventually assembly.

 

I think I got your explanation down and plan on playing around with it to see if I can get it work for my game.

 

So a recap:

 

asm

lda #<(PFCOLS+6) ; point to the sixth byte in the color data

sta DF0LOW

lda #(>PFCOLS) & $0F

sta DF0HI

 

lda $0E ; white

sta DF0PUSH ; changes the sixth byte/row

sta DF0PUSH ; changes the fifth byte/row

sta DF0PUSH ; changes the fourth byte/row

end

 

The first PFCOLS label sets the starting row (pointing to the bytes where the colors) and the second PFCOLS line sets the ending row, effectively creating a range for the later lines to change to a particular color. I would assume if I wanted different colors then a different lda would precede each DF0PUSH.

 

Currently, in my game when I have one area change playfield I redraw the entire playfield, or at most up until I don't need to change anything else so this method would probably use less space as well.

Share this post


Link to post
Share on other sites

Since memory addresses are 16-bit such as $1234 you have to split it up into two bytes

< takes LSB (least significant byte) aka low byte, the $34 part of the address

> takes MSB (most significant byte) aka high byte, the $12 part of the address

 

$12 would be the page and $34 the location on that page, a page has 256 different locations.

 

I'm shure PFCOLS is the beginning of a page so there's 256 bytes until the next page begins,

that way the high byte that holds the page never has to change.

 

I'm not shure what address PFCOLS is, but let's say it's $0700

 

$0700 ; holds the first color

$0701 ; second color

$0702 ; etc..

$0703

 

then when compiling our previous example

 

lda #<(PFCOLS+6) ; point to the sixth byte in the color data
sta DF0LOW
lda #(>PFCOLS) & $0F
sta DF0HI

 

 

the compiler first replaces the labels with the values:

lda #<$0706 ; point to the sixth byte in the color data
sta DF0LOW
lda #>$0700
sta DF0HI

 

It then extracts the MSB and LSB:

lda #$06 ; point to the sixth byte in the color data
sta DF0LOW
lda #$07
sta DF0HI

 

then you will push to $0706, I did not explain the & $0F since I don't know what it does myself?

Edited by Lillapojkenpåön

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   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...