#161973 - vuurrobin - Thu Aug 21, 2008 11:48 pm
hello everybody
I have some questions (again), and some stuff that I wan't to check if I understand them correctly. seeing as I got some good help the last few times, I'm posting here again.
the first thing isn't really a question, but I want to make sure that I understand mapping vram and that virtual memory good and correctly, seeing as I haven't found a place that explained it well, IMHO. now the best way to test if you know it correctly is to explain it to someone else so you will have to force it into words. so that is exactly what I am going to do :). this way, I can see if I know everything good enough to put it into words, you can check if it is correct, and other people who have trouble understanding this will have a place to read an explanation about this. plus if I ever decide to write a tutorial, I'll have a part already done (although I would probably need to rewrite it).
so here go's:
I know that I am going through this very fast and that I am skipping some stuff. but, AFAIK, that is the only thing you need to do to set up a background that involves the vram. so my question is, is my idea of how vram mapping works correct or am I way off?
and now for the other questions:
2. I looked at a vram table on dev-scene and I notised that vram A and B can't be used for sub backgrounds but vram C can. why is that, what does vram C has that vram A and B doesn't have (besides a libnds function). some hardware restriction? also the adress of VRAM_A_LCD and VRAM_A_TEXTURE_SLOT0 is the same?
3. pataters manual uses dmacopyhalfwords instead of dmacopy because it expicity tells the dma that we want to copy 16 bits at a time (?). it also says that it uses priority channel 3 because dmacopy uses it automaticly. however it doesn't say what the priority channel does so I know when to change it. I looked at gbatek, but I coudn't really figure it out. it says something about when the transfer starts, but then go's to the cardridge slots? so where is the channel used for and how important is it?
4. after looking through different tutorials, I found 3 different ways to move data, using the dma, using swiCopy() and using a for loop. what is the best way to use, or, when should I use what?
5. when I was looking trough console.h from libnds, I notised that the body of the functions weren't included. I tried searching for the bodys, but I coudn't find them. where are the bodys of the functions declared? if I would see the code, I would probably know better what the consoleDemoInit() uses and how to change that.
6. what program(s) do you use for tilemap editing, tile/sprite/background editing, palette editing ect. just wondering what other people are using.
I really hope someone can help me with these questions.
I have some questions (again), and some stuff that I wan't to check if I understand them correctly. seeing as I got some good help the last few times, I'm posting here again.
the first thing isn't really a question, but I want to make sure that I understand mapping vram and that virtual memory good and correctly, seeing as I haven't found a place that explained it well, IMHO. now the best way to test if you know it correctly is to explain it to someone else so you will have to force it into words. so that is exactly what I am going to do :). this way, I can see if I know everything good enough to put it into words, you can check if it is correct, and other people who have trouble understanding this will have a place to read an explanation about this. plus if I ever decide to write a tutorial, I'll have a part already done (although I would probably need to rewrite it).
so here go's:
me wrote: |
To use the main and sub graphics engines, we need to put our data into video ram (vram) memory. but the engines don't have vram reserved for them. Instead, the DS has 9 seperated vram banks (called A-I) that you first have to asign to them. This way you can decide how much memory you want to give to each engine and where they should use it for, backgrounds, sprites, tilemaps or something else.
However, we can't asign vram to an engine directly. The DS has some virtual vram memory to keep track which vram bank is asigned to which engine. so we must first asign a vram bank to an adress in the virtual vram, point the engine to the same place, and then store our data there. so when the engine is going to look for its data, it going to look at the adress in the virtual vram, which will point the engine to the vram bank we have chosen. to asign a vram bank we use an function from libnds, vramSetBankX(), with X being the bank we want to set/asign to virtual vram. in the brackets () we place the memory adress where we want to asign the vram bank to. thankfully, libnds provides some defines to make it easier for us. an example of setting vram bank A (which is 128 kb) for a background on the main engine to adress 0x06040000 is this: vramSetBankA(VRAM_A_MAIN_BG_0x06000000) pretty simple right. now lets asign bank B also to main background right next to A, so it will form 1 block of 256 kb (usefull for big backgrounds), and bank C to sub background. we wont use this much further along, but it is good to see it anyway: vramSetBankB(VRAM_B_MAIN_BG_0x06020000) vramSetBankC(VRAM_C_SUB_BG_0x06200000) now we point bg3 (the one we turned on when we turned the mode for the engine on) to the adress in virtual memory. we do this by asigning the adress into the controll register of the background we're using. while we are asigning the adress into the register, we will also specefy what kind of background we're using and what the priority of showing is by ORing "|" them on. here is an example of asigning the adress into the controll register: BG3_CR= BG_BMP16_128x128 | //the kind of background BG_BMP_BASE(0) | //the memory adress of the virtual vram where we placed vram bank A BG_PRIORITY(3) //the priority of the background, the first part asigns the kind of background, in this case a 16 bit bmp with a size of 128*128. the second part is the adress of the virtual vram. it currently point to 0x06000000, where we asigned vram bank A, if you would increase the number in the brackets, you would point the background 16 kb further. so BG_BMP_BASE(4) would point (4*16 =) 64 kb further. this way you can have 2 64 kb backgrounds in bank A. BG_BMP_BASE(8) would point to just after bank A and to the start of where we asigned bank B. with the priority of a background, the ds knows if it should display the background on top of the other backgrounds or below them. it is a number between 0 and 3, 3 being the lowest and thus being displayed on bottem, and 0 being the highest and displayed on top. after setting the background, we need to put our data into vram. we will be using the direct memory acces (DMA), since it allows the reading and writing of memory independently of the CPU. dmaCopy(vuurrobinBitmap, // This variable is generated for us by grit. (uint16 *)BG_BMP_RAM(0), // Our address for sub background 3. vuurrobinBitmapLen) // This length (in bytes) is generated for us by grit. the first argument is the start of our data that we want to copy from. seeing as we converted the picture with grit, it was nice enough to also give a pointer to its starting point. the second argument is the place in vram where would like the data to be copy'd to. it works just like BG_BMP_BASE() works with setting the background register, so make sure that the number in the brackets of (uint16 *)BG_BMP_RAM() is the same as the number with BG_BMP_BASE(). the thirth argument is the length of the data we want to copy. grit will also give the length in bytes so we can use that (thank you grit :) ). |
I know that I am going through this very fast and that I am skipping some stuff. but, AFAIK, that is the only thing you need to do to set up a background that involves the vram. so my question is, is my idea of how vram mapping works correct or am I way off?
and now for the other questions:
2. I looked at a vram table on dev-scene and I notised that vram A and B can't be used for sub backgrounds but vram C can. why is that, what does vram C has that vram A and B doesn't have (besides a libnds function). some hardware restriction? also the adress of VRAM_A_LCD and VRAM_A_TEXTURE_SLOT0 is the same?
3. pataters manual uses dmacopyhalfwords instead of dmacopy because it expicity tells the dma that we want to copy 16 bits at a time (?). it also says that it uses priority channel 3 because dmacopy uses it automaticly. however it doesn't say what the priority channel does so I know when to change it. I looked at gbatek, but I coudn't really figure it out. it says something about when the transfer starts, but then go's to the cardridge slots? so where is the channel used for and how important is it?
4. after looking through different tutorials, I found 3 different ways to move data, using the dma, using swiCopy() and using a for loop. what is the best way to use, or, when should I use what?
5. when I was looking trough console.h from libnds, I notised that the body of the functions weren't included. I tried searching for the bodys, but I coudn't find them. where are the bodys of the functions declared? if I would see the code, I would probably know better what the consoleDemoInit() uses and how to change that.
6. what program(s) do you use for tilemap editing, tile/sprite/background editing, palette editing ect. just wondering what other people are using.
I really hope someone can help me with these questions.