hexadecimal integer to code page 437 character in vga

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
anthony
Posts: 9
Joined: Sat Jun 18, 2022 10:42 am

hexadecimal integer to code page 437 character in vga

Post 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;
            }
        }
    }
}
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: hexadecimal integer to code page 437 character in vga

Post 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?
anthony
Posts: 9
Joined: Sat Jun 18, 2022 10:42 am

Re: hexadecimal integer to code page 437 character in vga

Post 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█
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: hexadecimal integer to code page 437 character in vga

Post by Octocontrabass »

Sounds like there's a problem with your putc_at() function. You didn't post the code for that.
anthony
Posts: 9
Joined: Sat Jun 18, 2022 10:42 am

Re: hexadecimal integer to code page 437 character in vga

Post 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;
}
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: hexadecimal integer to code page 437 character in vga

Post 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.
anthony
Posts: 9
Joined: Sat Jun 18, 2022 10:42 am

Re: hexadecimal integer to code page 437 character in vga

Post 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
Post Reply