sumeet
Posts: 21
Joined: Mon Jan 15, 2018 3:34 pm

Text mode for Raspberry Pi 3

Tue Jan 16, 2018 11:45 am

I want to develop a text console for RPi3 similar to text based OS shells like Windows Command Prompt or bash. I don't want to develop a full shell but just something where I can see what I type on the keyboard.

I had experimented with x86 assembly years ago and it has a text mode and graphical modes. In the text mode you simply write the character code to the framebuffer and it is displayed on the screen. But I am not able to find any info on text mode for RPi3. Does it have a text mode or will I have to implement my console using graphical mode by plotting pixels in bitmap fonts?

bzt
Posts: 98
Joined: Sat Oct 14, 2017 9:57 pm

Re: Text mode for Raspberry Pi 3

Tue Jan 16, 2018 12:23 pm

Hi sumeet,

You won't find any info because there's no such thing. VGA text mode is a remnant of the past, newer video controllers do not have it at all (maybe emulate it), and it is not accessible for UEFI firmware either.

On modern machines (as well as on the Raspberry Pi) you have a linear frame buffer with packed pixels (pixels encode RGB channels directly, palettes are obsolete too). With that you can plot dots on the screen easily. If you want to mimic text mode, you'll have to implement it yourself, just like linux kernel does with it's text consoles. VGA had a bitmap for each character in it's ROM, you'll need something similar. Linux uses inlined bitmaps and PC Screen Font format for that, which is basically the same bitchunk but with a 32 bytes header (and an optional unicode/glyph translation table). I wrote a tutorial on how to use a PSF file to display characters on the Raspberry Pi, feel free to explore it.

Cheers,
bzt

jahboater
Posts: 2484
Joined: Wed Feb 04, 2015 6:38 pm

Re: Text mode for Raspberry Pi 3

Tue Jan 16, 2018 12:41 pm

Deleted.
Last edited by jahboater on Tue Jan 16, 2018 1:31 pm, edited 1 time in total.

User avatar
Paeryn
Posts: 1892
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Text mode for Raspberry Pi 3

Tue Jan 16, 2018 1:06 pm

jahboater, this is in the bare-metal section so we assume there is no Linux or any other OS providing anything. As such the only display mode you get is what the VC4 provides (usually just a full-screen bitmap), if you want text you have to draw the characters yourself.
She who travels light — forgot something.

bzt
Posts: 98
Joined: Sat Oct 14, 2017 9:57 pm

Re: Text mode for Raspberry Pi 3

Tue Jan 16, 2018 1:14 pm

@jahboater: I think by "text mode" the OP was referring to the old display mode of Hercules / CGA / EGA / MGA / VGA cards, where the screen was divided into 9x16 pixel boxes, each described by 2 bytes in memory: one for a character code, and another for the color/attribute. The card took a 8x16 bitmap indexed by the character from it's ROM and displayed it in the given color, skipping the 9th column. That mode is still available (or emulated) on computers which emulate legacy BIOS, but not on UEFI-only machines and on the Raspberry Pi. There you have to draw your own bitmaps in order to display text.

Cheers,
bzt

sumeet
Posts: 21
Joined: Mon Jan 15, 2018 3:34 pm

Re: Text mode for Raspberry Pi 3

Tue Jan 16, 2018 1:26 pm

Thanks @bzt

@jahboater I know how to write code on Windows and Linux - I have been doing that for decades :)

I am only doing this for learning how things work at a low level (without OS).

jahboater
Posts: 2484
Joined: Wed Feb 04, 2015 6:38 pm

Re: Text mode for Raspberry Pi 3

Tue Jan 16, 2018 1:33 pm

Sorry, went straight to post itself and missed the bare metal bit :-(
Post deleted.

LdB
Posts: 701
Joined: Wed Dec 07, 2016 2:29 pm

Re: Text mode for Raspberry Pi 3

Tue Jan 16, 2018 3:45 pm

If you look at any of the samples we do it all the time.

https://github.com/LdB-ECM/Raspberry-Pi ... /README.md

Essentially there are two things you need

1.) a bitmap font for the screen either 8x8 or 8x16 works well.
I just convert them the binaries to a standard C array .. look at Font8x16.h

2.) You need the graphics routine to place the font bitmaps

Step 2 is a little tricky because there are different screen colour depths 16 bit, 24 and 32 bit colour and I select the right one depending what depth you select when you initialize the screen.

What we are doing is basically
http://wiki.osdev.org/VGA_Fonts

It's just a little more complex because we have multiple screen modes and I actually provide a number of graphics primitives

ClearArea ....... will clear an area of the screen from top left to bottom right coords in the given colour
VertLine ...... Draws a vertical line from Y1 to Y2 at coord x in the given colour (heavily optimized)
HorzLine ..... Draws a horizontal line from X1 to X2 at coord Y in the given colour (Heavily optimized)
DiagLine ..... Draws a line from X1,Y1 to X2,Y2 in given colour. (Can be vertical or horizontal but much slower than above)
WriteChar .... Write the character at the given X,Y cordinate in the font and fore and back colour given
TransparentWriteChar .... Transparent write the character at the given X,Y cordinate in the font and fore colour given
PutImage .... Place the binary image to screen at position X,Y

sumeet
Posts: 21
Joined: Mon Jan 15, 2018 3:34 pm

Re: Text mode for Raspberry Pi 3

Wed Jan 17, 2018 7:55 pm

@LdB Thank you. Your code looks great!!!! I would love to use Visual Studio 2017 which you have mentioned in the README. But under the code directories I cannot find any sln file. How should I open the code in Visual Studio?

Return to “Bare metal”

Who is online

Users browsing this forum: No registered users and 4 guests