Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[metal] Start exploring graphical video modes for VGA console #637

Merged
merged 11 commits into from
Oct 2, 2022
Merged

[metal] Start exploring graphical video modes for VGA console #637

merged 11 commits into from
Oct 2, 2022

Conversation

tkchia
Copy link
Contributor

@tkchia tkchia commented Sep 22, 2022

To do:

Edit 2022-09-26: in addition:

tkchia added 2 commits September 22, 2022 18:28
- Factor __invert_memory() into two routines, to make it
  easier for other libc routines to create their own negative
  address mappings
- Tweak __invert_memory() to map only the usable memory as
  given in the 0xe820 memory map, and no more
- Arrange for VGA console initialization to map video memory
  separately into virtual memory (in case needed)
- Rename libc/vga/vga-init.S to libc/vga/rlinit-vga.S, to
  reduce confusion as to the module's purpose
This should hopefully help us adapt the VGA console code, to
work with video modes other than 80 × 25 × 16 text.
@tkchia tkchia marked this pull request as draft September 23, 2022 14:04
@tkchia tkchia marked this pull request as ready for review September 23, 2022 14:05
@tkchia
Copy link
Contributor Author

tkchia commented Sep 23, 2022

Is there any good way for me to mark this pull request as being "dependent" on another pull request (namely, #636)? I think I will need the functionality I implemented in #636 in order to move forward on this PR.

@tkchia tkchia marked this pull request as draft September 23, 2022 14:11
@tkchia tkchia marked this pull request as ready for review September 24, 2022 22:14
@tkchia tkchia changed the title Bare metal VGA: detect graphics video modes at startup [metal] Start exploring graphical video modes for VGA console Sep 26, 2022
tkchia added 4 commits September 26, 2022 18:23
If the user holds down one of the Shift keys at boot time,
the program will dump a list of all usable VESA VBE video
modes on the VGA console.
Video mode switching works.  Character output, not so much.
(The tty code still thinks it is writing text mode characters.)
@tkchia
Copy link
Contributor Author

tkchia commented Sep 26, 2022

Video mode switching now works. Character output, not so much.

20220926-1
20220926-2

@ghaerr
Copy link
Contributor

ghaerr commented Sep 26, 2022

Hello @tkchia,

Video mode switching now works.

Wow, super nice work, and great display!

Character output, not so much.

I have just completed a text and graphics console emulator for Cosmopolitan, based on SDL, which will compile on Linux and macOS. I have used this to further some of the ideas discussed in #638. In particular, it includes a glyph drawing function and memory-based font that will work for all the modes shown in your screenshot above. I will post that code shortly, which should allow you to rapidly get graphical console text output running in short order.

Thank you!

@tkchia
Copy link
Contributor Author

tkchia commented Sep 26, 2022

Hello @ghaerr,

Thanks! I look forward to seeing what you have.

@tkchia
Copy link
Contributor Author

tkchia commented Sep 26, 2022

Hello @ghaerr,

Incidentally, have you sent a copyright assignment or copyright disclaimer e-mail to @jart yet (#616 (comment))? I think this will be needed to ultimately get your contributions included upstream. Thank you!

@ghaerr
Copy link
Contributor

ghaerr commented Sep 26, 2022

Hello @tkchia,

Incidentally, have you sent a copyright assignment or copyright disclaimer e-mail to @jart yet

Yes I have. However, seeing your progress on the VGA console in the past 10 days, I thought to at least post something that you might use ASAP, to allow you to continue making progress at full speed :)

I think this will be needed to ultimately get your contributions included upstream.

Yes. In this particular case, the "console emulator" isn't actually a Cosmopolitan binary, as it uses the (fairly extensive and not-likely-easily ported) SDL library to allow for graphical display and proper emulation of 32bpp, 24bpp and 16bpp framebuffer formats, and possibly to be used in the Cosmopolitan test suite for upcoming graphical library routines. I am not sure how @jart wants things like this organized.

Thank you!

@paulwratt
Copy link

paulwratt commented Sep 29, 2022

in that video mode output on the headers line change wid & ht to (capital) X & Y (space pad them if need be) - that will improve "eye" recognition and you dont need to understand english to decypher what they refer to.

EDIT: alternatively you could place (centered) x between the values and change header to (centered) size (or X x Y or X Y), eg:

     mode#      size    bpp     mode#     X x Y    bpp     mode#     X   Y    bpp
  G 0x410d   320 x 200   15  G 0x410e   320 x 200   16  G 0x4110   640 x 480   15
  G 0x4116  1024 x 768   15  G 0x4113   800 x 600   16  G 0x4114   800 x 600   15
  G 0x411a  1280 x 1024  16  G 0x411d  1600 x 1200  15  G 0x411e  1600 x 1200  16
  T 0x4002    80 x 25     4  T 0x4003    80 x 25     4

NOTE: there are no extended text modes in there? (80x50, 256 color (8bpp), 132x50, etc)

@tkchia
Copy link
Contributor Author

tkchia commented Sep 30, 2022

Hello @paulwratt,

EDIT: alternatively you could place (centered) x between the values and change header to (centered) size (or X x Y or X Y), eg:

I think I will leave that as an exercise for whoever is interested. 🙂

NOTE: there are no extended text modes in there? (80x50, 256 color (8bpp), 132x50, etc)

Strangely no, as far as I can tell. There are also no (directly supported) extended text modes on the actual (non-VM) PC which I am testing with.

Mode 0x4013 or 0x0013 — i.e. the MCGA 320 × 200 × 256-colour video mode — does exist, but my code filters out video modes that are not direct colour modes, so it is not listed.

Thank you!

@tkchia
Copy link
Contributor Author

tkchia commented Sep 30, 2022

OK — the user can now select which video mode to switch to, after pressing the ⇧ Shift key at startup.

I also added a quick test routine to have the protected mode code draw a glyph (in two different colours) in the middle of the screen.

20220930-1
20220930-2

Copy link
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm loving watching the progress unfold so quickly on this. You're doing fabulous work. You're making Cosmopolitan a true operating system!

_rlinit_vesa:
push %es
pushw $0
testb $0b00000011,0x0417 # read keyboard shift state (as
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've re-enabled the Wiki feature on this repository. Knowledge like a magic shift key for VGA config would be a good thing to have documented there! Put anything on the wiki you want!

// @return CF = 0 if we decided to set a new video mode, CF = 1 otherwise

.real
.code16
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[high level optional suggestion] You are so good at writing real mode code. But is there no other way? Is it possible to control this stuff from long mode using i/o ports? Surely there's got to be some i/o ports that are generally well-supported and well-defined on x86-64 PCs and servers. Because it'd be nice to have more stuff written in C if possible rather than depending on BIOS interfaces if we don't have to. Our support vector is 2006+ so if a consensus exists after that year for i/o ports let's use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @jart,

This is (still) beyond my capability at the moment, I am afraid, if it is possible. That is, I have not quite found a simple way to reliably switch modes, without going through VESA (in the case of legacy BIOS boot) or EFI GOP (in the case of UEFI boot). I suspect that at least some parts of the mode switching must be done differently for different graphics cards.

Thank you!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. I'm sure as the work evolves it'll attract more people who can help us!

@@ -58,9 +52,194 @@ ssize_t sys_writev_vga(struct Fd *fd, const struct iovec *iov, int iovlen) {
return wrote;
}

static void _vga_init_test(void *vid_buf, unsigned char vid_type,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like code we'll probably want to TODO move into examples/ soon. This isn't needed for production code, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jart : yes, it is not really needed. Thank you!

@jart jart merged commit ecb2ef7 into jart:master Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants