Page 1 of 1

hexadecimal integer to code page 437 character in vga

Posted: Thu Aug 04, 2022 12:27 pm
by anthony
i have a putc function which takes in a const char* but i want to have a hexadecimal integer which corresponds to a code page 437 and i have no idea what to do

here is my code

Code: Select all

void Console::putc(char c) {
    if (c == '\n') {
        row++;
        col = 0;
    } else if (c == '\t') {
        col += 4;
    } else if (c == '\v') {
        row += 4;
    } else if (c == '\r') {
        col = 0;
    } else {
        putc_at(c, color, col, row);
        if (++col == 80) {
            col = 0;
            if (++row == 25) {
                row = 0;
            }
        }
    }
}

Re: hexadecimal integer to code page 437 character in vga

Posted: Thu Aug 04, 2022 1:01 pm
by Octocontrabass
Your putc function takes a char, not a pointer to char. You can already pass it an integer value because char is an integer.

What exactly are you trying to do that doesn't already work?

Re: hexadecimal integer to code page 437 character in vga

Posted: Thu Aug 04, 2022 1:14 pm
by anthony
Octocontrabass wrote:Your putc function takes a char, not a pointer to char. You can already pass it an integer value because char is an integer.

What exactly are you trying to do that doesn't already work?
i was trying to print ā–ˆ so i did putc(0xDB); with 0xDB being ā–ˆ in cp437 but instead i get something like ā–ˆSā–ˆ

Re: hexadecimal integer to code page 437 character in vga

Posted: Thu Aug 04, 2022 1:23 pm
by Octocontrabass
Sounds like there's a problem with your putc_at() function. You didn't post the code for that.

Re: hexadecimal integer to code page 437 character in vga

Posted: Thu Aug 04, 2022 1:24 pm
by anthony
Octocontrabass wrote:Sounds like there's a problem with your putc_at() function. You didn't post the code for that.
here is my putc_at()

Code: Select all

void Console::putc_at(char c, uint8_t color, size_t x, size_t y) {
    const size_t idx = y * 80 + x;
    buffer[idx] = (uint16_t)c | (uint16_t)color << 8;
}

Re: hexadecimal integer to code page 437 character in vga

Posted: Thu Aug 04, 2022 1:32 pm
by Octocontrabass
You're converting a signed char to uint16_t, so it's getting sign-extended. Use unsigned char or a bitwise AND to mask the unneeded bits.

I'm not sure that explains the results you're getting, though. There may be issues with how your kernel is linked or loaded.

Re: hexadecimal integer to code page 437 character in vga

Posted: Thu Aug 04, 2022 1:45 pm
by anthony
Octocontrabass wrote:You're converting a signed char to uint16_t, so it's getting sign-extended. Use unsigned char or a bitwise AND to mask the unneeded bits.

I'm not sure that explains the results you're getting, though. There may be issues with how your kernel is linked or loaded.
turns out i accidentally said putc uses const char* when its actually puts that uses const char* and i should have been using putc the entire time since it uses char
edit: nevermind turns out by coincidence putc printed the character i was trying to print and i thought it worked