Print string

I drew a string using hankaku.bin 8×16 font provided by the X86 OS book.
First, I converted the 4096 byte bin file into elf format.

hankaku.o: hankaku.bin                                                                                     
  $(OBJCOPY) -I binary -O elf32-littlearm -B arm $< $@                                                     

when you convert that way, you can refer to the address in .data section by _hankaku_bin_obj_start as below.

void printstr(int x, int y, char *str, char color) {
  size_t len = strlen(str);
  for (int i = 0; i < len; i++) {
    char c = str[i];
    myputchar(x + i * 8, y, c, color);
  }
}

void myputchar(int x, int y, char c, char color) {
  char *hankaku = (char *)&_binary_hankaku_bin_start;
  char *base = (char *)fbRequest.fbBaseAddress;
  char *p;
  char d;

  for (int i = 0; i < 16; i++) {
    p = base + (y + i) * kWidth + x;
    d = hankaku[c * 16 + i];
...                                                

And it's displayed by this!

  printstr(10, 0, "HOG", 7);
  printstr(10 + 8 * 3, 0, "E", 1);

Today's code: https://github.com/sokoide/rpi-baremetal -> 005_character.

hoge

Leave a Reply

Your email address will not be published. Required fields are marked *