gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/examples/cross-platform/text_basic/src/main.c
1 #include <gbdk/platform.h>
2 #include <stdint.h>
3 #include "Font.h"
4
5
6 uint8_t GetCharacterVRamTile(char character) {
7
8 uint8_t vramTile=0;
9
10
11 // Char's can be interpreted as integers
12 // We don't need to map every alpha-numeric character
13 // We can use basic math to simplify A-Z and 0-9
14 if (character >= 'a' && character <= 'z') vramTile = (character - 'a') + 1;
15 else if (character >= 'A' && character <= 'Z') vramTile = (character - 'A') + 1;
16 else if (character >= '0' && character <= '9') vramTile = (character - '0') + 27;
17 else {
18 switch(character) {
19 case '!': vramTile = 37; break;
20 case ':': vramTile = 38; break;
21 case '?': vramTile = 39; break;
22 case '/': vramTile = 40; break;
23 case '=': vramTile = 41; break;
24 case ',': vramTile = 42; break;
25 case '.': vramTile = 43; break;
26 case '<': vramTile = 44; break;
27 case '>': vramTile = 45; break;
28 }
29 }
30
31 return vramTile;
32
33 }
34
35 void DrawText(uint8_t column, uint8_t row, char* text){
36
37 // Get the address of the first tile in the row
38 uint8_t* vramAddress = get_bkg_xy_addr(column,row);
39
40 uint16_t index=0;
41
42 while(text[index]!='\0'){
43
44 char character = text[index];
45
46 // Draw our character at the address
47 // THEN, increment the address
48 uint8_t vramTile = GetCharacterVRamTile(character);
49
50 set_vram_byte(vramAddress++,vramTile);
51
52 #if defined(SEGA)
53 set_vram_byte(vramAddress++,0);
54 #endif
55
56 index++;
57
58 }
59 }
60
61 void main(void)
62 {
63 SHOW_BKG;
64
65 set_native_tile_data(0,Font_TILE_COUNT,Font_tiles);
66
67 fill_bkg_rect(0,0,DEVICE_SCREEN_WIDTH,DEVICE_SCREEN_HEIGHT,0);
68
69 // We'll pass zero for the final argument, to draw the text instantly
70 DrawText(1,1,"GBDK Text Example");
71 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.