OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:57 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: hexadecimal integer to code page 437 character in vga
PostPosted: Thu Aug 04, 2022 12:27 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: hexadecimal integer to code page 437 character in vga
PostPosted: Thu Aug 04, 2022 1:01 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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?


Top
 Profile  
 
 Post subject: Re: hexadecimal integer to code page 437 character in vga
PostPosted: Thu Aug 04, 2022 1:14 pm 
Offline

Joined: Sat Jun 18, 2022 10:42 am
Posts: 9
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ā–ˆ


Top
 Profile  
 
 Post subject: Re: hexadecimal integer to code page 437 character in vga
PostPosted: Thu Aug 04, 2022 1:23 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Sounds like there's a problem with your putc_at() function. You didn't post the code for that.


Top
 Profile  
 
 Post subject: Re: hexadecimal integer to code page 437 character in vga
PostPosted: Thu Aug 04, 2022 1:24 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: hexadecimal integer to code page 437 character in vga
PostPosted: Thu Aug 04, 2022 1:32 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.


Top
 Profile  
 
 Post subject: Re: hexadecimal integer to code page 437 character in vga
PostPosted: Thu Aug 04, 2022 1:45 pm 
Offline

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Garnek0, SanderR and 50 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group