#165161 - dovoto - Thu Dec 11, 2008 5:23 am
www.devkitpro.org
I am in need of feedback on the new APIs (mainly the background, sprite, console, and keyboard stuff). If anyone has constructive views to share and perhaps be incorporated into the next libnds feel free to express them.
_________________
www.drunkencoders.com
#165164 - nanou - Thu Dec 11, 2008 8:20 am
The keyboard looks really nice and clean to use. I haven't run the example (not setup to compile on this system) so I haven't seen it in action yet. I'm surprised there's no example for asynchronous input though.
_________________
- nanou
#165173 - dovoto - Thu Dec 11, 2008 1:15 pm
nanou wrote: |
The keyboard looks really nice and clean to use. I haven't run the example (not setup to compile on this system) so I haven't seen it in action yet. I'm surprised there's no example for asynchronous input though. |
Good point, i will add one this afternoon.
_________________
www.drunkencoders.com
#165174 - nanou - Thu Dec 11, 2008 2:30 pm
I just compiled and checked the example. It's pretty good, I can't complain about the presentation and I'm sure there's some logical way of switching the image whatnot, but something about it bugs me: when I tap just above the keyboard I get (seemingly) random character input. (Though I think it relates to the x position, I didn't investigate too closely.)
I'll be starting to make use of the input (and some other things on the list) in my own code in the next few days so I'll let you know if I have any noteworthy thoughts.
I haven't looked into the console too closely, but I get the impression that there's only one text colour available at a time while using the default font. Is this so? If so, would it make sense to extend the ansi console to include support for multicolour text and the like? I still haven't directly touched tiles (or sprites, my apps so far have all been simply computational and/or use bitmap graphics) so I really don't have a grasp of the way the console really works yet.
_________________
- nanou
#165188 - dovoto - Thu Dec 11, 2008 8:56 pm
nanou wrote: |
I just compiled and checked the example. It's pretty good, I can't complain about the presentation and I'm sure there's some logical way of switching the image whatnot, but something about it bugs me: when I tap just above the keyboard I get (seemingly) random character input. (Though I think it relates to the x position, I didn't investigate too closely.) |
Fixed and in CVS. Thank you.
nanou wrote: |
I haven't looked into the console too closely, but I get the impression that there's only one text colour available at a time while using the default font. Is this so? |
When using 16 color tiled backgrounds (the default) the engine uses all 16 palettes. By default these palettes are initialized to the colors specified by the ansii escape sequences (see hello_world for an example of printing in color). You can change the font palette using escape sequences in the format string or by directly setting console.fontPal attribute on the currently selected console. The font palette tells the engine which palette to use (not directly which color).
The console uses color 15 of each palette with white being color 15 of palette 15 (or color entry 255).
This should work with extended palettes as well although you will have to load the colors manually into these palettes.
In other words the console supports multi color text out of the box as long as you have no more than 16 unique colors on screen.
nanou wrote: |
Async keyboard example |
Not sure if this is exactly what you are looking for but here is how you do it with the current release (below you will find how to do it with the next release as i have modified it a bit)
Code: |
#include <nds.h>
#include <stdio.h>
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
touchPosition touch;
consoleDemoInit(); //setup the sub screen for printing
keyboardInit(keyboardGetDefault());
keyboardShow();
while(1) {
// scanKeys(); keyboard update calls scankeys internally
keyboardUpdate();
if(keysDown() & KEY_TOUCH)
{
touchRead(&touch);
int key = keyboardGetKey(touch.px, touch.py);
if(key > 0)
iprintf("%c", key);
}
swiWaitForVBlank();
}
return 0;
}
|
Code: |
#include <nds.h>
#include <stdio.h>
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
consoleDemoInit(); //setup the sub screen for printing
keyboardInit(keyboardGetDefault());
keyboardShow();
while(1) {
//no longer interferes with scanKeys();
int key = keyboardUpdate();
if(key > 0)
iprintf("%c", key);
swiWaitForVBlank();
}
return 0;
}
|
_________________
www.drunkencoders.com
#165192 - MaesterRowen - Fri Dec 12, 2008 6:21 am
Hey there,
I appreciate the hard work put forth on this toolchain.
First, I like the new sprite API , it is very convenient.
One thing I am having trouble with is the new background API. Is there a way to directly manipulate the backgrounds offset on the LCD?
For instance, I want to take bg3 = bgInit(...) and instead of starting it at (0,0), offset it to be at say: (20,20)
Or because I am fairly newer to the DS scene, is there more documentation on how to use the new Background API beyond what the examples show?
Other than that, I think the new functionality of the sprite APIs and the console/keyboard are wonderful!
Thanks for the hard work.
#165193 - MaesterRowen - Fri Dec 12, 2008 7:24 am
Nevermind,
I figured out to just use the original register names to get the old style.
Thanks!
#165195 - nanou - Fri Dec 12, 2008 8:42 am
dovoto wrote: |
[In other words the console supports multi color text out of the box as long as you have no more than 16 unique colors on screen. |
Awesome. Thanks for the clarification.
Quote: |
nanou wrote: | Async keyboard example |
Not sure if this is exactly what you are looking for but here is how you do it with the current release (below you will find how to do it with the next release as i have modified it a bit) |
Yeah, that's just what I was thinking.
_________________
- nanou
#165208 - Ludo6431 - Fri Dec 12, 2008 10:38 pm
It's too high level for me, it's so Palib-like.
It's a pity :s
#165209 - AntonioND - Fri Dec 12, 2008 10:43 pm
Great update, Dovoto!!
#165210 - wintermute - Fri Dec 12, 2008 11:14 pm
Ludo6431 wrote: |
It's too high level for me, it's so Palib-like.
It's a pity :s |
The low level access still exists, there's nothing forcing you to use the new APIs.
The main motivation behind these changes is to make things easier for those who think the thin wrapper we already provide for experienced coders is "too hard". Ultimately we intend the toolchain and support libraries to be accessible enough for novices to get started on the DS reasonably quickly without getting into the bad habits that are encouraged by tutorial writers without the experience to know how bad their examples are.
If the new APIs are "palib like" enough to satisfy the audience attracted by high level libraries like HAMlib and PAlib then the community as a whole will benefit a great deal.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#165214 - Ludo6431 - Sat Dec 13, 2008 12:38 am
Hum, ok.
But i haven't any access to the registers :
idon't know how "convert" this :
Code: |
void InitVideo() {
videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
vramSetBankA(VRAM_A_MAIN_BG_0x06000000); //|
vramSetBankB(VRAM_B_MAIN_BG_0x06020000); //| 3*96Ko cons?cutifs pour MAIN, MAIN1 & MAIN2
vramSetBankD(VRAM_D_MAIN_BG_0x06040000); //| (96Ko de libre @ BG_BMP_RAM(18))
BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3);
BG3_XDX = 1 << 8;
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = 1 << 8;
BG3_CX = 0;
BG3_CY = 0;
BG2_CR = BG_BMP16_256x256 | BG_BMP_BASE(6) | BG_PRIORITY(2);
BG2_XDX = 1 << 8;
BG2_XDY = 0;
BG2_YDX = 0;
BG2_YDY = 1 << 8;
BG2_CX = 0;
BG2_CY = 0;
videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_BMP);
vramSetBankC(VRAM_C_SUB_BG_0x06200000); // 8Ko pour le texte et 96Ko pour SUB
SUB_BG0_CR = BG_MAP_BASE(3);
BG_PALETTE_SUB[255] = RGB15(31,0,0);
consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(3), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
consoleClear();
SUB_BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(2) | BG_PRIORITY(3);
SUB_BG3_XDX = 1 << 8;
SUB_BG3_XDY = 0;
SUB_BG3_YDX = 0;
SUB_BG3_YDY = 1 << 8;
SUB_BG3_CX = 0;
SUB_BG3_CY = 0;
lcdMainOnBottom();
}
void swapMAINbuf() {
if(swaped) BG2_CR = BG_BMP16_256x256 | BG_BMP_BASE(6) | BG_PRIORITY(2);
else BG2_CR = BG_BMP16_256x256 | BG_BMP_BASE(12) | BG_PRIORITY(2);
swaped^=1;
}
void hideConsole() {
videoSetModeSub(MODE_5_2D/* | DISPLAY_BG0_ACTIVE*/ | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_BMP);
}
void showConsole() {
videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_BMP);
}
void setBrightness(u8 screen, s16 bright) {
u16 mode = 1 << 14;
if(bright < 0) {
mode = 2 << 14;
bright = -bright;
}
if(bright > 16) bright = 16;
*(vuint16 *)(0x0400006C + (0x1000 * screen)) = bright | mode;
//#define BRIGHTNESS (*(vuint16*)0x0400006C)
//#define SUB_BRIGHTNESS (*(vuint16*)0x0400106C)
} |
#165216 - wintermute - Sat Dec 13, 2008 1:22 am
Most of the register definitions have now been changed to the standard names used in gbatek. The include file <nds/registers_alt.h> shows a cross reference from the old deprecated names to the new names.
The console code has been revamped a bit and now needs initialised in a slightly different way.
Code: |
void InitVideo() {
videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
vramSetBankA(VRAM_A_MAIN_BG_0x06000000); //|
vramSetBankB(VRAM_B_MAIN_BG_0x06020000); //| 3*96Ko cons?cutifs pour MAIN, MAIN1 & MAIN2
vramSetBankD(VRAM_D_MAIN_BG_0x06040000); //| (96Ko de libre @ BG_BMP_RAM(18))
REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3);
REG_BG3PA = 1 << 8;
REG_BG3PB = 0;
REG_BG3PC = 0;
REG_BG3PD = 1 << 8;
REG_BG3X = 0;
REG_BG3Y = 0;
REG_BG2CNT = BG_BMP16_256x256 | BG_BMP_BASE(6) | BG_PRIORITY(2);
REG_BG2PA = 1 << 8;
REG_BG2PB = 0;
REG_BG2PC = 0;
REG_BG2PD = 1 << 8;
REG_BG2X = 0;
REG_BG2Y = 0;
videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_BMP);
vramSetBankC(VRAM_C_SUB_BG_0x06200000); // 8Ko pour le texte et 96Ko pour SUB
REG_BG0CNT_SUB = BG_MAP_BASE(3);
BG_PALETTE_SUB[255] = RGB15(31,0,0);
consoleInit(NULL, 0,BgType_Text4bpp, BgSize_T_256x256, 3, 0, false);
consoleClear();
REG_BG3CNT_SUB = BG_BMP16_256x256 | BG_BMP_BASE(2) | BG_PRIORITY(3);
REG_BG3PA_SUB = 1 << 8;
REG_BG3PA_SUB = 0;
REG_BG3PB_SUB = 0;
REG_BG3PC_SUB = 1 << 8;
REG_BG3X_SUB = 0;
REG_BG3Y_SUB = 0;
lcdMainOnBottom();
}
int swaped = 0;
void swapMAINbuf() {
if(swaped) REG_BG2CNT = BG_BMP16_256x256 | BG_BMP_BASE(6) | BG_PRIORITY(2);
else REG_BG2CNT = BG_BMP16_256x256 | BG_BMP_BASE(12) | BG_PRIORITY(2);
swaped^=1;
}
void hideConsole() {
videoSetModeSub(MODE_5_2D/* | DISPLAY_BG0_ACTIVE*/ | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_BMP);
}
void showConsole() {
videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_BMP);
}
void setBrightness(u8 screen, s16 bright) {
u16 mode = 1 << 14;
if(bright < 0) {
mode = 2 << 14;
bright = -bright;
}
if(bright > 16) bright = 16;
*(vuint16 *)(0x0400006C + (0x1000 * screen)) = bright | mode;
//#define BRIGHTNESS (*(vuint16*)0x0400006C)
//#define SUB_BRIGHTNESS (*(vuint16*)0x0400106C)
}
|
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#165218 - Ludo6431 - Sat Dec 13, 2008 1:34 am
Hum, ok so very good ;)
Thanks a lot.
_________________
Sorry for my poor english, I'm french.
#165219 - Jevin - Sat Dec 13, 2008 1:49 am
When can we expect to see updated buildscripts? Gotta give the *BSDers some love! :)
#165226 - dovoto - Sat Dec 13, 2008 4:32 pm
MaesterRowen wrote: |
One thing I am having trouble with is the new background API. Is there a way to directly manipulate the backgrounds offset on the LCD?
For instance, I want to take bg3 = bgInit(...) and instead of starting it at (0,0), offset it to be at say: (20,20)
Or because I am fairly newer to the DS scene, is there more documentation on how to use the new Background API beyond what the examples show?
|
To manipulate the "offset" you can scroll the background.
bgSetScroll(id, x,y) or bgSetScrollf(id, x,y) where x and y are the offset in int or fixed (16.8 signed) respectivly. If you use the scroll or rotate functionality of the api you must call bgUpdate(id) once per frame.
As for documents:
http://libnds.devkitpro.org/
Or, if you have doxygen installed you can type "make docs" from the libnds source directory (would need to grab the source tarball from the SF release for this)
Quote: |
It's too high level for me, it's so Palib-like.
It's a pity :s
|
I tried to make the api as thin as possible, basically most of it is wrapping register calls with minimal logic (this is more maintainable for us, easier to document, and easier to remember).
I made an effort to ensure you could mix the api and direct register access and I am pretty sure I succeeded in all but background scrolling and rotation (some state management was necessary in this area).
_________________
www.drunkencoders.com
#165232 - Ludo6431 - Sat Dec 13, 2008 9:22 pm
Yes, you're right, i must apologize.
I was thinking that the registers aren't available, only the bgInit function...
You've done a very good work, thanks.
_________________
Sorry for my poor english, I'm french.
#165235 - sigmaris - Sun Dec 14, 2008 1:27 am
How come in the new background API, bgGetMapPtr() and bgGetGfxPtr() return u16** ? Shouldn't it be simply u16* ? Or am I misunderstanding what these functions are supposed to do? I am trying to modify a background's map while the game is running to animate some tiles.
#165241 - dovoto - Sun Dec 14, 2008 4:55 pm
sigmaris wrote: |
How come in the new background API, bgGetMapPtr() and bgGetGfxPtr() return u16** ? Shouldn't it be simply u16* ? Or am I misunderstanding what these functions are supposed to do? I am trying to modify a background's map while the game is running to animate some tiles. |
hrm...will check that out when i get back. Definitely not right if so.
_________________
www.drunkencoders.com
#165279 - dovoto - Mon Dec 15, 2008 11:59 pm
sigmaris wrote: |
How come in the new background API, bgGetMapPtr() and bgGetGfxPtr() return u16** ? Shouldn't it be simply u16* ? Or am I misunderstanding what these functions are supposed to do? I am trying to modify a background's map while the game is running to animate some tiles. |
Weird, must have slipped through our QA department ;)
Sorry for the delay but return type fixed and updated in the cvs and thanks
_________________
www.drunkencoders.com
#165282 - sigmaris - Tue Dec 16, 2008 1:37 am
cool! I noticed it worked when cast to u16* anyway. The new API is very nice, and also the enhancements in IPC and the integration of Maxmod :)
#165474 - M3d10n - Mon Dec 22, 2008 4:16 pm
wintermute wrote: |
Most of the register definitions have now been changed to the standard names used in gbatek. |
What? Awesome! This makes it much easier to use gbatek as a reference.
#165491 - wintermute - Tue Dec 23, 2008 2:12 am
Yeah, that was kind of the point of the exercise really :p
There are still a few left to move over but we're getting there.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#165589 - AxemRed - Mon Dec 29, 2008 5:15 am
In videoGL.c:
Code: |
int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, GL_TEXTURE_PARAM_ENUM param, const uint8* texture) {
...
addr = DynamicArrayGet(&glGlob->texturePtrs, glGlob->activeTexture);
...
}
|
Can cause problems because the relevant element of the texturePtrs array is never explicitly set to a value before you call this function.
#165591 - dovoto - Mon Dec 29, 2008 5:43 am
AxemRed wrote: |
In videoGL.c:
Code: |
int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, GL_TEXTURE_PARAM_ENUM param, const uint8* texture) {
...
addr = DynamicArrayGet(&glGlob->texturePtrs, glGlob->activeTexture);
...
}
|
Can cause problems because the relevant element of the texturePtrs array is never explicitly set to a value before you call this function. |
hrm...
Code: |
for(i = 0; i < 16; i++)
DynamicArraySet(&glGlob->texturePtrs, i, (void*)0);
|
added to glInit, thanks
_________________
www.drunkencoders.com
#165682 - pilch - Sat Jan 03, 2009 3:33 pm
I saw that card.h has changed a bit.
Does card functions really works ? (I never managed to read from the card)
#165685 - Dwedit - Sat Jan 03, 2009 4:49 pm
I think Libgba/Libnds could use some blitting or 'software sprite' functions for the 16-color tiled video modes.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#165686 - Echo49 - Sat Jan 03, 2009 7:53 pm
If I download the installer from the devkitpro site, does it grab the newest (checked) code from CVS? Or will I have to update the changes mentioned in this thread manually?
Also, when it says irqs are now inited before main, what's the "proper" way to set which functions are called for each irq?
#165692 - dovoto - Sun Jan 04, 2009 1:55 am
Echo49 wrote: |
If I download the installer from the devkitpro site, does it grab the newest (checked) code from CVS? Or will I have to update the changes mentioned in this thread manually?
|
The installer downloads the latest official release which is the topic of this thread.
Directly using the SVN version of libnds should be reserved for those who don't mind a bit of frustration. Libnds has a small team so the quality of the current SVN repo is occasionally lacking and answering support emails about it tends to frustrate the developers (in other words if you are not the type who can peak into the source code and provide us detailed information about the nature of a bug we are probably going to ignore any support questions you have on the non official release).
_________________
www.drunkencoders.com
#165693 - dovoto - Sun Jan 04, 2009 1:57 am
Echo49 wrote: |
Also, when it says irqs are now inited before main, what's the "proper" way to set which functions are called for each irq? |
http://libnds.devkitpro.org/a00072.html#5343d11a5c11bd860918c390b81a68ce
_________________
www.drunkencoders.com
#165698 - Echo49 - Sun Jan 04, 2009 6:38 am
Thanks dovoto - I just wanted to make sure before I upgraded and begin the task of find+replacing my code.
I just want to clarify the point on interrupts - all I have to do is remove irqInit() and it'll be fine?
#165700 - dovoto - Sun Jan 04, 2009 4:03 pm
Echo49 wrote: |
Thanks dovoto - I just wanted to make sure before I upgraded and begin the task of find+replacing my code.
I just want to clarify the point on interrupts - all I have to do is remove irqInit() and it'll be fine? |
Yes, that is really the only change to IRQs in this release other than vblank irq is enabled before main (no handler is installed for it though so you are still welcome to install your own vblank handler). Re-enabling vblank should have no ill effects.
_________________
www.drunkencoders.com
#165708 - AxemRed - Sun Jan 04, 2009 10:46 pm
I've found something interesting:
Code: |
//doesn't work, ARM7 never receives the message
//fifoSendValue32(FIFO_USER_07, value);
//works
if (!fifoSendValue32(FIFO_USER_07, value)) {
iprintf("Error sending message to ARM7\n");
}
|
It appears GCC can get a bit overenthusiastic with its optimizations if you don't need the return value. Couldn't really find the problem in the libnds source -- maybe a missing volatile keyword somewhere?
#165712 - Dwedit - Mon Jan 05, 2009 12:40 am
Care to fix the issue with dirnext (struct stat size is smaller than it should be, so bytes in memory after the struct get overwritten when you call dirnext)
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#165722 - hacker013 - Mon Jan 05, 2009 3:27 pm
AxemRed wrote: |
I've found something interesting:
Code: |
//doesn't work, ARM7 never receives the message
//fifoSendValue32(FIFO_USER_07, value);
//works
if (!fifoSendValue32(FIFO_USER_07, value)) {
iprintf("Error sending message to ARM7\n");
}
|
It appears GCC can get a bit overenthusiastic with its optimizations if you don't need the return value. Couldn't really find the problem in the libnds source -- maybe a missing volatile keyword somewhere? |
fifoSendValue32 has 3 arguments
_________________
Website / Blog
Let the nds be with you.
#165845 - AxemRed - Fri Jan 09, 2009 12:30 pm
hacker013 wrote: |
AxemRed wrote: | I've found something interesting:
Code: |
//doesn't work, ARM7 never receives the message
//fifoSendValue32(FIFO_USER_07, value);
//works
if (!fifoSendValue32(FIFO_USER_07, value)) {
iprintf("Error sending message to ARM7\n");
}
|
It appears GCC can get a bit overenthusiastic with its optimizations if you don't need the return value. Couldn't really find the problem in the libnds source -- maybe a missing volatile keyword somewhere? |
fifoSendValue32 has 3 arguments |
In 1.3.1 it's declared as:
Code: |
bool fifoSendValue32(int channel, u32 value32); |
Trying out the new keyboard I noticed a typo in a function name:
Code: |
int keboardGetChar(void); |
and in keyboardInit BG_PALETTE_SUB is always used even if keyboardOnSub is false:
Code: |
dmaCopy(keyboard->palette, BG_PALETTE_SUB, keyboard->paletteLen);
dmaCopy(keyboard->lower->mapDataPressed, bgGetMapPtr(keyboard->background),
keyboard->lower->width * keyboard->lower->height * keyboard->grid_height * keyboard->grid_width / 64 * 2);
BG_PALETTE_SUB[255] = RGB15(31,31,31);
|
#165846 - dovoto - Fri Jan 09, 2009 12:55 pm
AxemRed wrote: |
Trying out the new keyboard I noticed a typo in a function name:
Code: | int keboardGetChar(void); |
and in keyboardInit BG_PALETTE_SUB is always used even if keyboardOnSub is false:
Code: |
dmaCopy(keyboard->palette, BG_PALETTE_SUB, keyboard->paletteLen);
dmaCopy(keyboard->lower->mapDataPressed, bgGetMapPtr(keyboard->background),
keyboard->lower->width * keyboard->lower->height * keyboard->grid_height * keyboard->grid_width / 64 * 2);
BG_PALETTE_SUB[255] = RGB15(31,31,31);
|
|
Both of these issues have been brought to my attention and will be fixed with next release. Just need to iron out a few things with the sprite api. Thank you for the feedback.
_________________
www.drunkencoders.com
#165848 - headspin - Fri Jan 09, 2009 1:08 pm
Sorry if this has been asked before but why does it take so long for binaries to initialise and display something onscreen? All the examples take about 15 seconds or so to do anything. I noticed this both in emu's and hardware and I don't remember this back when I was using DKP r20.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
#165849 - dovoto - Fri Jan 09, 2009 3:48 pm
headspin wrote: |
Sorry if this has been asked before but why does it take so long for binaries to initialise and display something onscreen? All the examples take about 15 seconds or so to do anything. I noticed this both in emu's and hardware and I don't remember this back when I was using DKP r20. |
I have not noticed this, all are instant on in both no$ and on hardware for me. can you be more specific? are you using libfat?
_________________
www.drunkencoders.com
#165891 - headspin - Sun Jan 11, 2009 6:36 pm
dovoto wrote: |
I have not noticed this, all are instant on in both no$ and on hardware for me. can you be more specific? are you using libfat? |
Okay I just tested a few of the demo's it turns out it's just iDeaS not hardware. Sorry my mistake!
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
#166101 - Echo49 - Mon Jan 26, 2009 9:46 pm
What happens when you don't have a free channel and you call soundPlaySample()? Does it return -1 or does it wait until there is one?
#166299 - ChronoDK - Wed Feb 04, 2009 9:54 am
This new background system seems really nice! A few questions came up when trying to get older code working with this new system.
First, how do I use extended palettes? I would expect a parameter in the BgInit function, but there is none. Also where do I copy the palettes to now?
More questions might show up later :)
#166389 - cory1492 - Sat Feb 07, 2009 9:12 am
First, thanks for all the ongoing DK updates! Getting something unusual here after updating using the DKp updater and figured someone may like to hear about it. I'm compiling the EZ5s dldi under current DKPro via updater, source is linked below the error.
Has anyone linked anything successfully against card.o of libnds9.a in the recent dkpro? It is using memcpy internally without being able to link it with ld later, changing the command array of cardReadID() to static or //removing it and refs to it out of the lib fixes the problem, though I have my doubts using static would do anything good for the function or the rest of the lib if anyone is actually using it.
Code: |
Cory@HOME2 /h/devkitPro/proj/_EZ5/ez5s
$ make
linking ez5s.elf
h:/devkitPro/libnds/lib\libnds9.a(card.o): In function `cardReadID':
/Users/davem/projects/devkitPro/libnds-master/libnds/arm9/../source/common/card.c:116: undefined reference to `memcpy'
collect2: ld returned 1 exit status
make[1]: *** [/h/devkitPro/proj/_EZ5/ez5s-dldi-R20-opt_debug/ez5s-dldi-R20-opt_debug.elf] Error 1
make: *** [build] Error 2 |
And the source giving me this error.
Tried to pull the latest libnds from svn today as well just to double check if it's been fixed somewhere already before posting this, GRIT and a /../ in the path for the keyboardgfx png killed that build pretty quick. Two glitches for the price of one, I guess. (edit:/ I see keyboardgfx has been fixed, cures the issue with svn not building for me but the earlier memcpy linking is still an issue.)
#166513 - Echo49 - Mon Feb 09, 2009 10:29 am
I've noticed that in timers.h TIMER_FREQ_x(n) is defined as
Code: |
#define TIMER_FREQ_x(n) (-(0x2000000>>x)/(n)) |
However, on gbatek it says the frequency is 33513982, not 0x2000000 (33554432). As a result, the calculated value differs by about 20 ticks.
I know 20 ticks isn't much time (0.6ms), but my program requires timer accuracy in short bursts over long periods time. The 20 tick difference adds up fairly quickly, resulting in around 500ms of delay after 3 minutes. At the moment I'm using my own modified macro with the gbatek value, but I would prefer to use the one defined in libnds. Any chance of a fix?
#166516 - eKid - Mon Feb 09, 2009 10:45 am
0.6 microseconds, why do you need so much accuracy? 0x2000000 is sometimes convenient because it can be divided by powers of 2 nicely.
#166517 - Echo49 - Mon Feb 09, 2009 10:52 am
ms = millisecond (micro is ?)
I'm double buffering audio from a file as a libfat/audio/doublebuffer exercise, and the delay adds up fairly quickly causing my audio to become out of sync. In reality the delay when using the libnds macro is much more than 0.6ms, though I haven't pinpointed exactly how this is the case yet.
In any case, wouldn't it be better to use the "proper" value rather than an approximation?
Code: |
#include <nds.h>
#include <stdio.h>
#include <fat.h>
#define SIZE 11025
#define SAMPLERATE 22050
u8 *buffer, *buffer2;
FILE* file;
bool swap = true;
bool fill = false;
u8* getBuffer() {
if (swap)
return buffer;
else
return buffer2;
}
void timerHandler()
{
soundPlaySample(getBuffer(), SoundFormat_8Bit, SIZE, SAMPLERATE, 127, 64, false, 0);
swap = !swap;
fill = true;
}
int main() {
irqEnable(IRQ_TIMER0);
irqSet(IRQ_TIMER0, timerHandler);
soundEnable();
consoleDemoInit(); //setup the sub screen for printing
if (!fatInitDefault())
{
iprintf("fat cat");
return -1;
}
file = fopen("music.raw","rb");
if (!file) {
iprintf("no file");
return -1;
}
//align to 4 bytes
buffer = (u8*)new u32[(SIZE>>2)+1];
buffer2 = (u8*)new u32[(SIZE>>2)+1];
fread(getBuffer(),1,SIZE,file);
// formula for data is -(F*t)/1024, F=33513982 (gbatek), t=SIZE/SAMPLERATE=0.5
// TIMER_FREQ_1024(n) uses F=33554432 which isn't accurate enough
TIMER0_DATA = -16364;
TIMER0_CR = TIMER_ENABLE | TIMER_IRQ_REQ | TIMER_DIV_1024;
while(1)
{
if (fill) {
fread(getBuffer(),1,SIZE,file);
fill = false;
}
swiWaitForVBlank();
}
return 0;
} |
#166520 - eKid - Mon Feb 09, 2009 11:10 am
erm.. 20 33mhz ticks is 0.6 microseconds but I see you're using /1024 prescaler. When streaming audio, you really don't want to have *any* inaccuracies or it will drift out of sync easily. The way to do that is not use these macros and just have a timer (or two) to count samples (where it is based on the sound channel's frequency) to know where you are in the ring buffer.
#166521 - Echo49 - Mon Feb 09, 2009 11:21 am
Could you show me an example of how to sync the timer and the playback? I'm not sure how I can do this using the libnds sound functions (or whether I even can)
#166523 - eKid - Mon Feb 09, 2009 11:34 am
Hm, it's easy if the libnds sound functions had a way to set the sound channel timer directly... (request for soundSetTimer(...) :)
Also, I just noticed that you are playing each half of the buffer each timer tick. That can't work properly because of some of the sound hardware quirks. You have to use one channel that plays the ring buffer as a loop.
#166566 - Echo49 - Mon Feb 09, 2009 9:30 pm
Ok, I'll look into that.
edit: Seems to work fine with a ring buffer now. Cheers!
#166592 - Lazy1 - Wed Feb 11, 2009 2:52 am
The new sound system needs a way to reserve/block channels on the arm9 from being used.
I have channels 0 and 1 playing music from an OPL2 emulator on the arm7, normally this works fine but if a sound is played before the arm7 starts playing the song one channel will play loud static instead.
I'm trying to think of a workaround for this but any other ideas would be helpful.
#166596 - Echo49 - Wed Feb 11, 2009 5:47 am
Lazy1 wrote: |
The new sound system needs a way to reserve/block channels on the arm9 from being used. |
I agree. I noticed that both soundPause() and soundKill() do the exact same thing - change the enable bit to 0. Doesn't this mean that a paused channel could be used by another sample, rendering soundResume() useless?
#166676 - Lazy1 - Fri Feb 13, 2009 8:30 pm
Moving the music to channels 6/7 stopped the problems I was having, however this will probably still break at some point.
#168720 - Synthetic - Sun May 17, 2009 5:34 am
I just updated to the latest version of devkitarm and libnds, and I'm seeing the behavior that headspin was talking about, on hardware.
I compiled the helloworld example, put it on my Cyclo Evolution (latest firmware), and it sits for ~15 seconds with both screens white. When the hello world does display, the framecounter starts at 0, so this is happening before the vblank irq starts?