9.1 Font Data

Three functions are provided for determining the starting address of each font in the drive's internal ROM.


9.1.1 Obtaining Storage Offset Addresses for Kanji

The storage offset addresses for kanji can be obtained by calling LeoGetKAdr().

Arguments are encoded using Shift-JIS codes.


LeoGetKAdr( ) function


#include<PR/leo.h>

int LeoGetKAdr(int sjiscode);

sjiscode kanji Shift-JIS code


The value returned by this function is the offset from the starting address of the font data in DDROM (see Chapter 4). As is mentioned in Chapter 4, the starting address of font data in DDROM (0x000a_0000) is defined by DDROM_FONT_START in leo.h. Thus, when using EPI functions to tranfer data from DDROM by DMA, specify the following for the address.

DDROM_FONT_START+offset
(offset indicates the return value of this function)

See the next page for a specific example.

These data are represented in 4-bit (16 dot x 16 dot) Intensitexture format. To find which specific codes represent each kanji character, please see "Appendix B, Drive Internal Font Data."

16 x 16 x 4 = 1024(bit)= 128(Byte)

As mentioned previously, the EPI functions is used to load kanji data into RDRAM. An example, from DMA transfer to storage in TMEM, is shown below.

Example

i=LeoGetKAdr(sjiscode);

dmaIOMessageBuf.hdr.pri         = OS_MESG_PRI_NORMAL;
dmaIOMessageBuf.hdr.retQueue    = &dmaMessageQ;
dmaIOMessageBuf.dramAddr        = &kbuffer[kanadr];
dmaIOMessageBuf.devAddr         = DDROM_FONT_START + i;
dmaIOMessageBuf.size            = 128;

handler->transferInfo.cmdType  = OS_OTHERS;
osEPiStartDma(handler, &dmaIOMessageBuf, OS_READ);
 
gDPLoadTextureBlock_4b( glistp++,&kbuffer[kanadr],G_IM_FMT_I,16,
                        16,0,G_TX_CLAMP,G_TX_CLAMP,G_TX_NOMASK,
                        G_TX_NOMASK,G_TX_NOLOD,G_TX_NOLOD);
gSPTextureRectangle(glistp++,x<<2,y<<2,(x+16)<<2,(y+16)<<2,
                        0,0,0,0x400,0x400);


9.1.2 Obtaining Storage Offset Addresses and Other Information for Alphabetic Characters - 1

Storage offset addresses and other information for alphabetic characters can be obtained using LeoGetAAdr(). For more specific information on values for the argument code, please see "Appendix B, Drive Internal Font Data."

If a value like that described above is inserted for code, the character width is stored for dx, character height for dy, and the vertical location of the character body for cy (see figure below). The return value is the offset from the beginning of the fonts in DDROM. Based on this offset value, font data can be transferred from DDROM by DMA using the Epi functions. When transferring data by DMA, the starting address must be set to a 2-byte boundary. However, because the offset must always be a multiple of 2, this is not a particular concern. That is, assuming offset to be the return value of the function LeoGetAAdr( ), the address should be specified as follows.

DDROM_FONT_START + offset

See the following Example.

These data are represented in 4-bit Intensity Texture format. The amount of memory needed to represent of 1 character can be calculated from the width dx and height dy of the character as follows.

dx x dy x 4(bits) = dx x dy / 2(bytes)

However, it is risky to use DMA to send data whose size is not a multiple of 16. (For more information, see the description of the OS_DCACHE_ROUNDUP_ADDR function.) Consequently, the value given to the EPI functions as the transfer size is the smallest multiple of 16 that exceeds dx x dy / 2 and is calculated as follows.

( ( (dx x dy / 2) + 15 ) >> 4 ) << 4

In the following example, a fixed data size of 128 bytes is specified because it was determined that transferring slightly more data than indicated by the above calculation would allow faster data transfer (no characters exceed 128 bytes in size.). Which approach is best can be determined depending on the case.

Values different from the type shown above cannot be used for code. A return value of -1 means that the character is unreadable.

Relationship between dx, dy, and cy


LeoGetAAdr( ) function


#include<PR/leo.h>

int LeoGetAAdr(int code, int *dx, int *dy, int *cy);

code code

dx character width

dy character height

cy vertical lacationof character body

Example

ofs=LeoGetAAdr(code,&dx,&dy,&cy);
 
dmaIOMessageBuf.hdr.pri         = OS_MESG_PRI_NORMAL;
dmaIOMessageBuf.hdr.retQueue    = &dmaMessageQ;
dmaIOMessageBuf.dramAddr        = &kbuffer[kanadr];
dmaIOMessageBuf.devAddr         = DDROM_FONT_START + ofs;
dmaIOMessageBuf.size            = 128;
 
handler->transferInfo.cmdType  = OS_OTHERS;
osEPiStartDma(handler, &dmaIOMessageBuf, OS_READ);
 
gDPLoadTextureTile_4b(glistp++,&kbuffer[kanadr],G_IM_FMT_I,
                        (dx+1)&~1,dy,0,0,(dx-1)<<G_TEXTURE_IMAGE_FRAC,
                        (dy-1)<<G_TEXTURE_IMAGE_FRAC,0,G_TX_CLAMP,
                        G_TX_CLAMP,G_TX_NOMASK,G_TX_NOMASK,G_TX_NOLOD,
                        G_TX_NOLOD);
gSPTextureRectangle(glistp++,x<<2,(y-cy)<<2,(x+dx)<<2,
                        (y-cy+dy)<<2,0,0,0,0x400,0x400);


9.1.3 Obtaining Storage Offset Addresses and Other Information for Alphabetic Characters - 2

Storage offset addresses and other information for alphabetic characters can be obtained by calling LeoGetAAdr(), described in the previous section. However, because this function converts codes to addresses and other information each time it is called, using it is not the most efficient means of obtaining this information. When the alphabetic characters used in a game are prepared beforehand, it is more convenient to use following function.


LeoGetAAdr2( )function


#include<PR/leo.h>

int LeoGetAAdr2(u32 ccode, int *dx, int *dy, int *cy);

ccode character code

dx character width

dy character height

cy vertical location of character body


(Please note that the character codes for this function are different from those used by LeoGetAAdr().)

If a value like that described above is inserted for the argument ccode, the character width is stored for dx, character height for dy, and the vertical location of the character body for cy (see figure in previous section). The return value is the offset from the beginning of the fonts in DDROM. When using Epi functions to transfer data from DDROM by DMA, the address is specified as follows.

DDROM_FONT_START+offset
(offset is the return value of this function)

For information on the data format and the amount of data needed to represent 1 character, see Section 9.1.2.

The character code ccode represents data for a 32-bit character and can be created using the special tool called asccode. asccode usage is as follows.

First prepare a text file with the following types of character string data.

0, Super Mario 64

5, Wave Race 64 11, Mario Kart 64

The numerals 0, 5, and 11 indicate the font #. (For information on font #, see APPENDIX B, Drive Internal Fonts.) Assume, for example, that the name of this file is string and that the following is entered at the command line.

% asccode string

As a result, a file is created that contains the converted character code strings, as shown below (The filename in this example is string.c.).

unsigned string0[]={
67336724,114259726,107715344,93558800,111626256,40212,56150
548,86874128,111626256,99756564,106207248,40212,24742420,21
858836,0};
unsigned string1[]={
1585843223,1602787342,1634048014,1609795598,1487761176,1575
459606,1602787342,1606576142,1609795598,1487761176,15200819
42,1515952918,0};
unsigned string2[]={
3183115030,3210180624,3231606800,3221314326,3228067856,3127
996184,3179973398,3210180624,3231606800,3233438228,31279961
84,3151592214,3148446486,0};

string0 is a character string data that corresponds to "Super Mario 64", string1 corresponds to "Wave Race 64", and string2 corresponds to "Mario Kart 64". Each of these array elements is a character code that corresponds to a character in the original string.

Only values obtained as asccode output can be used for ccode. If the value returned is a -1, then the character is unreadable.


9.1.4 Items to Note

When using strings containing the following 2-byte Shift-JIS codes with a MIPS compiler, a '\' (backslash) character should be placed immediately after that character.