gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Custom sprintf

#3997 - Jack Handey - Sat Mar 15, 2003 3:06 am

Does anyone have their own custom sprintf? Or does anyone know how to write one?

#4036 - Lord Graga - Sun Mar 16, 2003 7:38 pm

You mean a write text function?

#4052 - satanicfreak2 - Mon Mar 17, 2003 2:57 am

download my tetris demo. It has the source code for writing text.

#4263 - niltsair - Wed Mar 26, 2003 7:23 am

You can also output some text on the Mappy emulator...
http://www.bottledlight.com/

By using this code :
Code:
ARM SDT Code:
void dprint(char *string) {
  __asm {
    mov r2, r0
    mov r0, #0xC0DED00D
    mov r1, #0
    and r0, r0, r0
  }
}

Code:
GCC Code:
void dprint(const char *sz) {
  asm volatile("
    mov r2, %0
    ldr r0, =0xc0ded00d
    mov r1, #0
    and r0, r0, r0
  " :
  /* No output */ :
  "r" (sz) :
  "r0", "r1", "r2");
}

(From Mappy Specs Document)

I found it usefull for debug purpose, no need find ways to display strings or numbers on the Gba Screen (by using some tiles like i did at first, or pixels).

#4278 - joet - Wed Mar 26, 2003 1:52 pm

To handle the variable args use va_list and vsprintf:

Code:

void txprint(char *string, ...){
    va_list argptr;

    va_start(argptr, string);
    vsprintf(text_data, string, argptr);
    va_end(argptr);
   
    _print(text_data);
}


(You'll need ot include stdarg.h)