#6255 - Daedro - Wed May 21, 2003 3:09 am
Hello everyone, sorry to bother you all again but I am stumped and have tried altering the saving positions. My BG02 when I load it is using my BG01 tiles and palette.. the shape is still there, but its replaced with other parts of my BG01.
The code is:
Code: |
#include "gba.h"
#include "screenmode.h"
#include "keypad.h"
#include "background.h"
#include "gfx.c"
#include "astart.c"
#include "bstart.c"
void DMA_Copy(u8 channel, void* source, void* dest, u32 WordCount, u32 mode)
{
switch (channel)
{
case 0:
REG_DMA0SAD = (u32)source;
REG_DMA0DAD = (u32)dest;
REG_DMA0CNT = WordCount | mode;
break;
case 1:
REG_DMA1SAD = (u32)source;
REG_DMA1DAD = (u32)dest;
REG_DMA1CNT = WordCount | mode;
break;
case 2:
REG_DMA2SAD = (u32)source;
REG_DMA2DAD = (u32)dest;
REG_DMA2CNT = WordCount | mode;
break;
case 3:
REG_DMA3SAD = (u32)source;
REG_DMA3DAD = (u32)dest;
REG_DMA3CNT = WordCount | mode;
break;
}
}
void BlitBG(u16* bgMap, const u16* data, int dataw, int x, int y)
{
int loopx,loopy;
x = x >> 3;
y = y >> 3;
for(loopy = 0; loopy < 32; loopy++)
{
for(loopx = 0; loopx < 32; loopx++)
{
bgMap[loopx + loopy * 32] = data[(loopx+x) + (loopy+y) * dataw];
}
}
}
int main()
{
int x=0,y=0;
u16* bg0map =(u16*)ScreenBaseBlock(31);
u16* bg1map =(u16*)ScreenBaseBlock(30);
REG_BG0CNT = BG_COLOR_256 | TEXTBG_SIZE_256x256 | (31 << SCREEN_SHIFT) | WRAPAROUND;
REG_BG1CNT = BG_COLOR_256 | TEXTBG_SIZE_256x256 | (30 << SCREEN_SHIFT) | WRAPAROUND;
SetMode(MODE_0 | BG0_ENABLE | BG1_ENABLE);
DMA_Copy(2,(void*)bstartMap.bstartPal,(void*)BGPaletteMem,256,DMA_16NOW);
DMA_Copy(2,(void*)bstartMap.bstartTData,(void*)CharBaseBlock(0),bstartMap.bstartTDSize/4,DMA_32NOW);
DMA_Copy(3,(void*)astartMap.astartPal,(void*)BGPaletteMem,256,DMA_16NOW);
DMA_Copy(3,(void*)astartMap.astartTData,(void*)CharBaseBlock(0),astartMap.astartTDSize/4,DMA_32NOW);
BlitBG(bg0map,astartMap.astartLayers[0].astartData, astartMap.astartLayers[0].w,0,0);
while(1)
{
while(!(REG_DISPSTAT & 1));
if (!((*KEYS) & KEY_A))
{
BlitBG(bg1map,bstartMap.bstartLayers[0].bstartData, bstartMap.bstartLayers[0].w,0,0);
}
while((REG_DISPSTAT & 1));
}
}
|
I excluded some other irrelivent code, hope I didnt exclude needed code to determine the problem. If anyone is feeling like a code brainiac then they might help me fix code exactly like this accept when you Press A you go to a PlotBG(); which works, but I lose the BG I was on and have the new one.. just let me know.
Thanks in advance!
Eric Muyser
#6258 - niltsair - Wed May 21, 2003 3:58 am
Bg0 as highter priority tha Bg1 by default (i think), so if Bg0 has no pixels that use color 0 of the palette, then it'll entirely cover Bg1. You can see if it's the case by checking the content of each layer in VisualBoy Advance (Tools-Map Viewer)
#6259 - Daedro - Wed May 21, 2003 4:09 am
Yeah, or ctrl+1 or 2.. I tried that all. I dont exactly understand, but if you mean the first color ( color 0 ) is covering Bg1 because it doesnt have the color in the palette, thats not it. The Bg1 and Bg0 are showing up, The Bg1 is fine and perfect, Bg0 has half transparent so I can see them both there. The only thing is they are sharing the DMA memory, or video memory or whatever. I have Bg1 and Bg0 using one palette when I have two laoded as you see by my code. I want Bg0 to use the astart.astartPal and I want Bg1 to use the bstartMap.bstartPal. I somehow have them both using the same one. I dont have time to exactly see what your saying, I'll check out later. Can anyone see something wrong in the code to fix so each Bg has its own palette?
#6261 - sgeos - Wed May 21, 2003 4:28 am
Daedro wrote: |
Can anyone see something wrong in the code to fix so each Bg has its own palette? |
It looks to me like you are setting your BGs to 256 colors. You can have only one 256 color palette in that mode. You'll have to either use different part of the palette, or use 16 colors and specify the palette explicitly.
Keep in mind that the tile format use for 256 color tiles and 16 color tiles is a different.
-Brendan
#6262 - Daedro - Wed May 21, 2003 5:51 am
Well I already use enough colors as it is and still have a scetchy image for BG0, plus the colors from BG1.. ha.. I am screwed.
I changed the BG_COLOR_256 to BG_COLOR_16, not working great ( that is the variable )
I know this is A LOT to ask, but if anyones but to it could they change or add to my code so it works with 16 colors, or do I have to change the whole image? ( ahhhhhh )
#6263 - sgeos - Wed May 21, 2003 6:14 am
Daedro wrote: |
I know this is A LOT to ask, but if anyones but to it could they change or add to my code so it works with 16 colors, or do I have to change the whole image? ( ahhhhhh ) |
I'm fine with reading something over, looking for bugs and giving advice, but generally speaking I expect people to fix thier own code. They learn more that way, and it's less work for me.
Daedro wrote: |
Well I already use enough colors as it is and still have a scetchy image for BG0, plus the colors from BG1.. ha.. I am screwed. |
I'm not sure what you mean by this. You *will* need to load two 16 color palettes. BG palette 0 starts at 0x05000000, and palette 1 at 0x05000020. You'll also need to convert your tiles to 16 color format. Take it one step at a time, and I'm sure you'll be able to figure it out.
Daedro wrote: |
I changed the BG_COLOR_256 to BG_COLOR_16, not working great ( that is the variable ) |
256 color tiles and 16 color tiles use different formats. You'll need to convert your tiles to 16 color format. Make one simple tile first, and try to get it to display properly in 16 color mode. Then try changing the palette for that one tile.
-Brendan
#6264 - Daedro - Wed May 21, 2003 6:38 am
Well I have it in 16 colors in mode 4 and its all scwished up to about a little less than half, and it looks more like tiles than the image.. probably becuase I made it in mode0 the tile mode. Should I just stretch it, I know how.. and remake the image in mode4? but in mode 4 I lose 2 bg's man..
Iif their is still a way to get 16 color mode in mode0 PLEASE LET ME KNOW, and show me how or DIRECT ME if possible. THANK YOU.
Is it true I can get better looking graphics in 16 color mode because their are like 5 tile modes with the 16 colors.. can I use like 2 of those tile modes and have half a graphic on one side at bg2 and half the other graphic on the other side as bg3 to look like one image?
Eric
#6266 - Daedro - Wed May 21, 2003 6:49 am
sgeos wrote: |
Daedro wrote: | I know this is A LOT to ask, but if anyones but to it could they change or add to my code so it works with 16 colors, or do I have to change the whole image? ( ahhhhhh ) |
I'm fine with reading something over, looking for bugs and giving advice, but generally speaking I expect people to fix thier own code. They learn more that way, and it's less work for me.
Daedro wrote: | Well I already use enough colors as it is and still have a scetchy image for BG0, plus the colors from BG1.. ha.. I am screwed. |
I'm not sure what you mean by this. You *will* need to load two 16 color palettes. BG palette 0 starts at 0x05000000, and palette 1 at 0x05000020. You'll also need to convert your tiles to 16 color format. Take it one step at a time, and I'm sure you'll be able to figure it out.
Daedro wrote: | I changed the BG_COLOR_256 to BG_COLOR_16, not working great ( that is the variable ) |
256 color tiles and 16 color tiles use different formats. You'll need to convert your tiles to 16 color format. Make one simple tile first, and try to get it to display properly in 16 color mode. Then try changing the palette for that one tile.
-Brendan |
Well if your going to recommend this, I understand and will do it. But if your going to recommend something that is already going to take forever, could you recommend a good map editor where it wont multiply that task by 5? I have to change all the data with my current one.. the problem is no other program codes it like this one, but I want to use it in the end, and its very primative as for map making. Its the map editor from thepernproject tutorials it outputs the palette, the color for every pixel, and the tiles.. it seems advanced, but I could just use the palette and data one its just I sometimes never get a palette when using programs that output like that and it confuses me.
-I understand now.. so this does mean I can use 2 palettes for my two bg's and have them how I want them?
-Is it possible to use 3 and make the graphics more detailed?
-I can overwrite the Bg palettes 0x05000000 and 0x05000020 after I am done with them with new bg's and such without difficulty.. as long as I am not using more than all of them.. meaning I can infact use all the palettes if ever necessary?
Thanks a lot, I now know why most games are done in 16 colors.. and this is going to be a lot harder than I thought.
Thanks for the info, any ideas on these questions?
Eric Muyser
#6267 - sgeos - Wed May 21, 2003 7:05 am
Daedro wrote: |
Well I have it in 16 colors in mode 4... Iif their is still a way to get 16 color mode in mode0 |
You don't need to use mode 4. You can mode 0 with 16 colors.
In no particular order: Set DISPCNT to mode 0 and turn on whatever BGs you want. It sounds like you want BGs 0 and 1. Set BGxCNT to the proper character and screen base blocks. Load your palette data. Load your tile data.
The data tile data contains the character number and the palette number, and well as other info like v-flip. The pern project tutorial covers this and documents the tile formats, as well as the bg registers, etc.
Daedro wrote: |
Is it true I can get better looking graphics in 16 color mode because their are like 5 tile modes with the 16 colors.. can I use like 2 of those tile modes and have half a graphic on one side at bg2 and half the other graphic on the other side as bg3 to look like one image? |
16 color modes are better because A) you can load more gfx in VRAM, and B) you can efficiently use the same gfx with different colors many places at once.
Some blending can be done using 256 colors that simply can not be done with only 16. In theory, 256 color graphics should look better in exchange for space. In practice I usually don't even use all 16!
-Brendan
#6269 - sgeos - Wed May 21, 2003 7:33 am
Daedro wrote: |
But if your going to recommend something that is already going to take forever, could you recommend a good map editor where it wont multiply that task by 5? |
You can probably use the same data and load it into VRAM differently.
Daedro wrote: |
I have to change all the data with my current one... Its the map editor from thepernproject tutorials it outputs the palette, the color for every pixel, and the tiles |
I've never used it. If I were actually going to convert the format, I'd write a small program to do it for me.
Daedro wrote: |
...but I could just use the palette and data one its just I sometimes never get a palette when using programs that output like that and it confuses me |
Strange. At any rate, there is nothing magical about the output of that program. You can load anything you want into VRAM. It doesn't matter where you get it from. Just save the palette(s) you want to use somewhere, and then use them.
Daedro wrote: |
-I understand now.. so this does mean I can use 2 palettes for my two bg's and have them how I want them? |
You can, and have to, set the palette for each tile of the bg. If you want and entire BG to use a certain palette, then OR each tile of the BG map with the palette number for that BG, then load the tile into the screen base block. Note that the palette is stored from bits 12 to 15, so it needs to be shifted 12 spots before you OR it. The tile number does not need to be shifted.
Daedro wrote: |
-Is it possible to use 3 and make the graphics more detailed? |
You can choose between one palette of 256 colors, or sixteen palettes of 16 colors each. You don't have to use all the palettes or colors.
Daedro wrote: |
-I can overwrite the Bg palettes 0x05000000 and 0x05000020 after I am done with them with new bg's and such without difficulty.. as long as I am not using more than all of them.. meaning I can infact use all the palettes if ever necessary? |
You can overwrite any of the palettes whenever you feel like it. (You might not be able to in the vdraw actually.) It will change the colors of anything that uses that palette when the screen next refreshes itself.
Daedro wrote: |
Thanks a lot, I now know why most games are done in 16 colors.. and this is going to be a lot harder than I thought. |
You are welcome. It might be more work than you thought, but I'm not convinced it will be harder. People are doing their best to make things as easy as possible.
Daedro wrote: |
Thanks for the info, any ideas on these questions? |
Most of the above is covered in the pern project tutorial. I suggest you reread it. I still refer to it from time to time, although I usually turn the cowbite spec or gbatek instead.
-Brendan
#6272 - tepples - Wed May 21, 2003 8:51 am
sgeos wrote: |
You can overwrite any of the palettes whenever you feel like it. (You might not be able to in the vdraw actually.) |
I change palette entries during draw all the time. It's a cheap form of profiling: Code: |
PALRAM[0] = 0; /* blacken the background */
do_complicated_function();
PALRAM[0] = normal_bgcolor; |
This creates a horizontal bar across the screen, and the height of the bar is proportional to how un-optimized my function is. And yes, it works even in the middle of the scanline.
Lots of games do something slightly simpler get a more complicated sky, with hblank DMA to PALRAM[0].
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#6280 - niltsair - Wed May 21, 2003 2:48 pm
For your Tiles/Map creation, i used http://tilestudio.sourceforge.net/ for my first project. Worked great. The only complain was that there was no way to detect flipped tile, migth have changed with the new version. It's a generic Tile/Map editor, so you can write your own script to export your data (and you'll have to) It is very versatile.
For your color problem, in every tile mode(Mode 0,1,2) you decide the color mode for each layer ( 256colors or 16colors). When using 16colors, the palette area is divided in 16. The color 0 of each palette is the see through color. Each tiles entry in the map must now be told wich palette to use (0 to 15) by giving the value of it from bit 12-15. The pern project has nice table of how each value is stored.
#6289 - sgeos - Wed May 21, 2003 6:48 pm
tepples wrote: |
I change palette entries during draw all the time. It's a cheap form of profiling: Code: | PALRAM[0] = 0; /* blacken the background */
do_complicated_function();
PALRAM[0] = normal_bgcolor; |
This creates a horizontal bar across the screen, and the height of the bar is proportional to how un-optimized my function is. And yes, it works even in the middle of the scanline. |
That is a really neat way of profiling. If you change it in the middle of a scanline, does the bar start in the middle for that scanline?
niltsair wrote: |
For your color problem, in every tile mode(Mode 0,1,2) you decide the color mode for each layer ( 256colors or 16colors) |
Rotation and scaling BG maps can only use 256 colors. The rotation BG in mode 1 must be 256 colors. Mode 2 only has rotation BGs- they'll use 256 colors. In modes 0 and 1, your BGs can actually use different color modes.
-Brendan
#6291 - tepples - Wed May 21, 2003 6:59 pm
sgeos wrote: |
[Changing the background color] is a really neat way of profiling. |
I use it because I started out on the NES, which had no VCOUNT or timers.
Quote: |
If you change it in the middle of a scanline, does the bar start in the middle for that scanline? |
Yes. However, a change done during hblank is not visible until the start of the next line.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#6293 - sgeos - Wed May 21, 2003 10:04 pm
tepples wrote: |
Quote: | If you change it in the middle of a scanline, does the bar start in the middle for that scanline? |
Yes. However, a change done during hblank is not visible until the start of the next line. |
I don't imagine that there is any reliable way to figure out what pixel in the scanline is being processed at a given time. That would be really neat.
-Brendan
#6297 - DekuTree64 - Thu May 22, 2003 12:45 am
I think you can use timers to accurately time mid-scanline interrupts, probably reset the timer on HBlank, but I've heard that on hardware, if you change something in the middle of a tile, the rest of that tile will appear as garbage (the rest of the line past the start of the next tile will be fine though). That might only be if you change screen data mid-line though, so palettes might be different.
According to the Cowbite spec, there's 228 cycles in HBlank, and 1004 in HDraw, so I suppose that would mean 1004/240=4.18333 cycles per pixel. SO set the timer register to 228 + ((274159 * x) >> 16). But then you'd have to subtract the cycles needed to do that calculation too, and probably a few for the interrupt setting up and checking REG_IF and stuff, so it would probably only be good for demos where you can kind fo trial-and-error time it.
#6298 - Daedro - Thu May 22, 2003 1:45 am
I will definetly re-read that tutorial. I was skipped threw a lot of it and just refered back to it as I had no clue what they were talking about before.
About TileStudio, how do I export, I export a map to 8bit and it comes out in wierd funky langauge with qoutes """""" everywhere.
Now to clarify, thepernproject does have a tutorial telling me how to define each tile to a certain palette, not just what bits they are but the actual code. Not for me to just geuss at. I went their and stared at the screen for 10 minutes at one spot about fading, not much info, and all it said was you fade with BIT07 and REG_BLDMOD .. I dont know exactly what I am suppose to do out of this, I now know the info but I cannot script it with that. Also, I have never seen any source having each tile defined to a certain palette bit, is it better to do that ( ie. faster or more advanced for less bugs? )
Anyway, I didnt mean that about how hard it would be. I was under the idea I would have to split tiles into two and have one with some dots here and another with some dots their for a second. I wont need two palettes for one BG though right? I mean if it doesnt have too many colors... I have mostly brown in the two BG's.
What is with that cowbite thing? I saw once all the defines they had and it was a lot, but I went back their when I heard about it becuase last time was an accident and its like Mappy or something? an emulator that you can program games in or something.. it looks neat, but I couldnt get it to work.
Since this is such a long post, anyone want to see what I have been trying to do anyway? Maybe give them an idea as what route I should take:
http://members.shaw.ca/daedro/
They are seperate for a reason, which is later in the script.
#6300 - djei-dot - Thu May 22, 2003 11:55 am
So what are the advantages of having 16 16 color palettes instead of one 256 color palette?
Because the number of colors is the same (16x16=256), the 16 color palettes have less one color each because of the transparent one, and only 256 color palettes are allowed to do scaling/rotation!
Is it simply because it can be faster to update a few 16 color palettes than the entire 256 color one?
#6303 - Touchstone - Thu May 22, 2003 2:36 pm
djei-dot wrote: |
So what are the advantages of having 16 16 color palettes instead of one 256 color palette? |
Tile size my friend. If your tiles only use 16 colors, each pixel is only 4 bits instead of 8 bits. One 16 color tile use 32 bytes of VRAM whereas one 256 color tile use 64 bytes.
_________________
You can't beat our meat
#6304 - niltsair - Thu May 22, 2003 2:36 pm
The main benefit is the fact that you get to have the double of tiles available (since they each fit in 8bits instead of 16). There's also a question of color management. Easier to attribute a set of color for each thing.
So far i've been using 256colors mode because i felt it was easier to start with, but on a larger game, 16colors would be the way to go. A lot can be done with only 16colors.
About TileStudio, you need to write your own output script. To help you out check how one is written and see the tutorial page for a list fo command you can use in the script. There use to be a Script page around for the Gba.. Ah found it http://www.cs.kun.nl/is/ts/.
I created mine from it, but lost it in a reformating of my drive :/ I know it can seems like a lot of work, but it's really worth it. That way you'll be able to have total control on how you want to use your data in your .h files. An important feature in the export file, is #Tinytiles which transform all of your tiles to 8x8 tiles (if you were using larger one in the editor)
To create your palette, you need to displat the color used (in View menu or such) then go in the palette manager, and choose New Palette, it'll takes the color of your picture. If you can understand french, here's a tutorial about using TileStudio for the Gba http://www.ifrance.com/edorul/french/chapitre11.htm
#6318 - Daedro - Fri May 23, 2003 1:02 am
niltsair wrote: |
For your Tiles/Map creation, i used http://tilestudio.sourceforge.net/ for my first project. |
..I do not ask for recommendations of what people used to use, can anyone recommend a program they actually use now and is good as they are experienced?
How do I define a tile to a certain part of the 16 color palette like someone said to do. This is in programming for the gba, I am not talking about Tile Studio. How do I define tile 0x0065 (brownish) to address 0x6000000 and 5 knotches over to the 16 brownish palette colors (16*5=80) so 0x6000080 is what I define it to? if so, how?... And lets say the define for 0x6000080 will be REG1TILE ... I dont know how to make REG1TILE = 0x0065 in code, can I get help with the actual code please.
Anyone? Thank you.
#6324 - tepples - Fri May 23, 2003 5:19 am
Daedro wrote: |
How do I define a tile to a certain part of the 16 color palette like someone said to do. |
Do you know how to write to the map? To set a map entry to use color palette 5 (entries numbered 0x51-0x5f stored in addresses 0x050000a2-0x050000bf), set its four most significant bits to 5 (that is, OR with 0x5000). Do likewise for various values of 5.
Have you read the tutorials? Or do they not adequately cover the 16-color tile modes?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#6327 - Daedro - Fri May 23, 2003 8:04 am
Well.. what are "the tutorials" refering to?
The pernproject tutorials go into little depth with 16 colors, and more in 256.
Quote: |
In the GBA case these tiles are 8x8 and can be either 16-color or 256-color bitmaps.
bits 12-15: 16-color palette number. Ignored if it is a 256-color background
bit 7: If 1 then 256-color mode else 16-color mode |
All the info I saw on 16-colors.
Okay, I understand what your saying. I have understanded most of what everyone is saying. I do not need the numbers and bit codes, or any of that anymore. I just have been saying over that I do not know the code. Code, being how to set something to 5. I actually did sit here for a while trying to think of how to do the code and explored others.. no idea.
Set 5 to the four bits which are 12, 13, 14, 15 .. BIT12=4096.. so what? how do I set a number to a number.. put bit12 to 0x4096.. i dont know. Set 0x5000 to BIT12 as TILE1 and set TILE1 to 5? I see too many methods of setting things, *stars and u16's and bits and consts.. I will read the C programming for dummies, I am buying a few books to find out these, but for now can I please get some sample code to help me learn which is how I learned whatever I do know. I have over 70 source code demos and the only one that uses 16 colors on a bg is the Cauldron game.. ever tried trying to find your way around in that code, bah.. I checked and he seperated his tiles but didnt even set them to any palette they are just on the first one in color 16... I must have mist the coding. Anyone have any good tutorials or source codes or examples of 16 colors on a BACKGROUND? that actually define the Tiles if that is what I have to do.
#6328 - sgeos - Fri May 23, 2003 8:17 am
Daedro wrote: |
Set 5 to the four bits which are 12, 13, 14, 15 .. BIT12=4096.. so what? how do I set a number to a number.. put bit12 to 0x4096.. i dont know. |
It sounds to me like you need to improve your C. This is really basic C stuff. Look into "bitwise operations". These are very important to know.
Bit 12 is a location. 0x4096 is a number. If you set certain bits, then you get certan numbers. If you set bit 12 and only bit 12, you get 0x1000, or 4096. (I think you meant 4096 instead of 0x4096 above.) If you want to set bits 12 to 15 to the number 5, do this:
value = value | (5 << 12);
Take 5, shift it left 12 bits, and or it with the current value to get the new one.
-Brendan
#6329 - Daedro - Fri May 23, 2003 9:31 am
I dont know anything, I am so mad with this I am always freaking. I looked over C books, how am I suppose to remember the variables, numbers, locations, blah, blah, blah when I cant do a gameboy one. I am suppose to learn those, and then not even use half of them in a gameboy file?
Yeah.. u huh this makes no sense to me, the value part.. I know I am suppose to enter something but I dont know what.
value = value | (5 << 12); ...?
#define TILE1 (0x050000a2 | 0x050000bf)
TILE1 = BIT12 | (5 << 12);
or
#define TILE1 0x05000
TILE1 = BIT12 | (5 << 12);
I am so zone out of this I dont even understand the english sentence "Take 5, shift it left 12 bits, and or it with the current value to get the new one. " Its that dang cauldron game.. I searched like 25 of its file to try and figure out how to define a tile and it makes no damn sense anymore... plus I skipped threw three 500 page C++ programming books.. and 50 different sources for demos, its all merging. I cant look at anymore coding, it makes no sense anymore.. maybe I can get this defining a tile try for the third day tomorrow.
#6345 - niltsair - Fri May 23, 2003 3:59 pm
Here's a small example, not tested.
Code: |
//Defines
//0. Load your palette in memory
...
//1. Create your tiles.
#define TILE1 ((u16*)0x6000000) //Pointer to First Tile in Video Memory
#define TILE2 ((u16*)0x6000010) //Pointer to Second Tile in Video Memory
u8 i(0);
u16 val1(0);
u16 val2(0);
//In 16color mode, we fit 4 pixels in 1 value;
// To set them all to color 5 (1001 1001 1001 1001) = 0x5555
val1 = 0x5555
val2 = 0x6666
/ /There's 8x8 pixels to set, 4 at a time
while ( i < 8*8 /4 )
{
TILE1[i] = val1;
i++;
}
//Create a second tiles
/ /There's 8x8 pixels to set, 4 at a time
i = 0;
while ( i < 8*8 /4 )
{
TILE2[i] = val2;
i++;
}
//2. Fill a Map with tiles
#define MAP31 ((u16*)0x600F800 )
u16 tile1(0);
u16 tile2(0);
tile1 = 0; //assign the tile number (bit 0-9)
tile1 |= (0<<10); //assign the horizontal flip (which is none) (bit10)
tile1 |= (0<<11); //assign the vertical flip (which is none) (bit 11)
tile1 |= (0<<12); //this tile will use palette 0 (bit 12-15)
tile2 = 1; //assign the tile number (bit 0-9)
tile2 |= (0<<10); //assign the horizontal flip (which is none) (bit10)
tile2 |= (0<<11); //assign the vertical flip (which is none) (bit 11)
tile2 |= (0<<12); //this tile will use palette 0 (bit 12-15)
u16 j(0)
//There's 32x32 Tiles in a basic 256x256 map
while( j < 32*32 )
{
if( j % 2 == 0 )
MAP31[j] = tile1;
else
MAP31[j] = tile2;
j++;
}
3. Set your DisplayRegister to displat Map31
... |
Now, this code is far from optimized, but i hope clearer. This will produce a map that show alternate block of color 5 and 6.
So, in order to display the color 5, you first need to create a tile having this color. Then you tell a map to displat that tile
(0<<12); Is a bits operation that mean take the value of 0, and move it 12 bits to the left.
Ex: 0000 1001 << 3 ====> 0100 1000
tile1 |= ... Is also a bits it means keep all the bits set to 1 in tile, and also set the bits that are in ...
Ex: 0011 0000 |= 0000 1111 ===> 0011 1111
Hope this help a bit.
#6401 - Daedro - Sat May 24, 2003 11:23 am
The code makes sense to me. I understand now how you change the values of own tile very well now. I feel I understand how you change the palette for an individual tile, tile2 |= (0<<12); if tile2 |= (1<<12); would be palette 1 to make sure? The |= is still unknown to my of what it means, that would be some C sign I will get to learning which is probably used in a lot of programming langauges. The part:
Code: |
u16 j(0)
//There's 32x32 Tiles in a basic 256x256 map
while( j < 32*32 )
{
if( j % 2 == 0 )
MAP31[j] = tile1;
else
MAP31[j] = tile2;
j++;
} |
Is a little hard to understand, It works. However, their were a few minor changes that had to be done for debuging obviously.
I have a few problems though. Some things in this code arent needed or are ment to do something and are not. I have been trying to change certain things that should be changable with this code and it does not work. For example the code:
tile2 = 1; //assign the tile number (bit 0-9)
tile2 |= (0<<10); //assign the horizontal flip (which is none) (bit10)
tile2 |= (0<<11); //assign the vertical flip (which is none) (bit 11)
tile2 |= (0<<12); //this tile will use palette 0 (bit 12-15)
does absolutely nothing. ..uhm "//assign the tile number (bit 0-9)" this bit 0-9 is wierd, if I add 1 to it for each tile how can it be in bits 0-9? isnt this the actual tile number?
#define TILE2 ((u16*)0x6000010)
should be
#define TILE2 ((u16*)0x6000020)
it goes by 20's.. but I can go by 2's when using this code...
Was this ment to define where the tile will be located? becuase I thought that was done in the mapdata not here. I can change where the tiles are placed with that.
// To set them all to color 5 (1001 1001 1001 1001) = 0x5555
val1 = 0x5555
val2 = 0x6666
How does 1001 1001 1001 1001 = 5555? and where do you go pase val9 = 0x9999 .. So this is setting it to palette 5 in char base 0x6000000? or to the actual color number 5 in the palette?
while ( i < 8*8 /4 )
{
TILE1[i] = val1;
i++;
}
You cant do this as your not defining 8*8 pixels, your actually defining 8*8 tiles.. so now what does it change to? 1*1 /1 ?
All this defining to the Tile1 isnt nessecary is it? I havent seen one source having each tile defined.. But then I could have missed it becuase it might be writen to just add 20 to the 0x6000000 for each tile, and 1 to the tile for each tile and have better more ocmpact design which is what I will do when I actually get it to work. Any more ideas? I am missing something here.. I cant get it to work exactly right yet, hard to find where the tile is coming from, and I should be able to tell that.
Thanks a lot though for all this, it helps a lot for understanding how it works, this has been useful.. not productive yet though, where are these tiles coming from? I defined them exactly like it is in Tile1 as you show and go to Map view and see the part I changed and it says its Tile: 341 ( WHERE DID THAT COME FROM, lol)
Did you write this up or did you take it from some demo source?
Eric Muyser
#6408 - Daedro - Sat May 24, 2003 7:02 pm
Oh okay, I understand it all now. At least I understand the basics, but I dont know why I need the code 0x04005 though.
Code: |
#define TILE2 ((u16*)0x6000010) //Pointer to Second Tile in Video Memory |
This I think was ment to point to the tile 2 in the tiles, but what it actually points to is the tile on the map. But since we are pointing to the map it isnt 0x6000010 (should be 0x6000020 anyway) it would be 0x6000002.
This is where you go outta wack, this is actually the believe it or not the tile AND the palette. I set it to 0x04006 to have it on tile 6 and palette 4, or 0x08002 have tile 2 on palette 8. I find this wierd, to have them both on that, since I dont have anything defining a tile this must take over since the first tile define isnt defining the tile from the tiles. But it makes sense, each palette would have its own section.. 8, 7, 6, and then add the tile.
Code: |
while ( i < 8*8 /4 )
{
TILE1[i] = val1;
i++;
} |
This I fixed and works fine, defining the val1 which is the tile and palette to the map tile TILE1. But the while ( i < 8*8 /4 ) is changed to while ( i < 1*1 /1 ) which makes that whole part pointless, but I dont know if it can be excluded.
Code: |
tile1 = 0; //assign the tile number (bit 0-9)
tile1 |= (0<<10); //assign the horizontal flip (which is none) (bit10)
tile1 |= (0<<11); //assign the vertical flip (which is none) (bit 11)
tile1 |= (0<<12); //this tile will use palette 0 (bit 12-15) |
This is the part that is lost, this part was suppose to be the palette and tile number and not val1 = 0x5555 which I have no clue what was suppose to be. That entire code isnt working, I wish it were though becuase it seems to make more sense and easier to use, on the other hand only having to input 0x04005 is very useful.
Code: |
#define MAP31 ((u16*)0x600F800 ) |
Where exactly is this defined to?
Code: |
while( j < 32*32 )
{
if( j % 2 == 0 )
MAP31[j] = tile1;
else
MAP31[j] = tile2;
j++;
} |
I dont even include this anymore, I dont know what it does. If it is important could you tell me what it is suppose to do? and how I am suppose to add another tile when if and else are take.. I am suppose to have 32*32 tiles in there?
Is there any way to exclude the part about defining the TILE1 which points to the map, will it just go to the spot it should? becuase it seems defining where the tile should be is extra work that is not needed. Plus that means if the tile is re used I have to define it to a different location too.
Thanks again, it is very useful to be exploring with these codes and learning more about how the coding of palettes work. Any ideas on some of these problems?[/b]