XGA graphics

Programming, for all ages and all languages.
Post Reply
User avatar
PavelChekov
Member
Member
Posts: 113
Joined: Mon Sep 21, 2020 9:51 am
Location: Aboard the Enterprise

XGA graphics

Post by PavelChekov »

How would I modify this for XGA screens:

Code: Select all

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
 
#include <kernel/tty.h>
 
#include "vga.h"
 
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
static uint16_t* const VGA_MEMORY = (uint16_t*) 0xB8000;
 
static size_t terminal_row;
static size_t terminal_column;
static uint8_t terminal_color;
static uint16_t* terminal_buffer;
 
void terminal_initialize(void) {
	terminal_row = 0;
	terminal_column = 0;
	terminal_color = vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK);
	terminal_buffer = VGA_MEMORY;
	for (size_t y = 0; y < VGA_HEIGHT; y++) {
		for (size_t x = 0; x < VGA_WIDTH; x++) {
			const size_t index = y * VGA_WIDTH + x;
			terminal_buffer[index] = vga_entry(' ', terminal_color);
		}
	}
}
 
void terminal_setcolor(uint8_t color) {
	terminal_color = color;
}
 
void terminal_putentryat(unsigned char c, uint8_t color, size_t x, size_t y) {
	const size_t index = y * VGA_WIDTH + x;
	terminal_buffer[index] = vga_entry(c, color);
}
 
void terminal_putchar(char c) {
	unsigned char uc = c;
	terminal_putentryat(uc, terminal_color, terminal_column, terminal_row);
	if (++terminal_column == VGA_WIDTH) {
		terminal_column = 0;
		if (++terminal_row == VGA_HEIGHT)
			terminal_row = 0;
	}
}
 
void terminal_write(const char* data, size_t size) {
	for (size_t i = 0; i < size; i++)
		terminal_putchar(data[i]);
}
 
void terminal_writestring(const char* data) {
	terminal_write(data, strlen(data));
}
:mrgreen:
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: XGA graphics

Post by PeterX »

Are you sure the following is correct?

Code: Select all

      if (++terminal_row == VGA_HEIGHT)
         terminal_row = 0;
I would expect scrolling instead.

And XGA: I can't find info about XGA text mode on the net. So I guess if a XGA screen has text mode, it will be VGA compatible. Sorry, I don't know.

Greetings
Peter
User avatar
PavelChekov
Member
Member
Posts: 113
Joined: Mon Sep 21, 2020 9:51 am
Location: Aboard the Enterprise

Re: XGA graphics

Post by PavelChekov »

I assumed that it was right because I copied off of the wiki page.
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: XGA graphics

Post by PeterX »

PavelCheckov wrote:I assumed that it was right because I copied off of the wiki page.
Well, it kind of works. But it will jump to the first line when it reaches the bottom of the screen. That's usually not very reader-friendly. So I would suggest scrolling intead (copying every line one line "higher" and then continue printing at the bottom of the screen.)

EDIT:
I changed https://wiki.osdev.org/Meaty_Skeleton#k ... 86.2Ftty.c
I hope the code I added is not ugly or complicated and has no bugs.

Greetings
Peter
sj95126
Member
Member
Posts: 151
Joined: Tue Aug 11, 2020 12:14 pm

Re: XGA graphics

Post by sj95126 »

PeterX wrote:And XGA: I can't find info about XGA text mode on the net. So I guess if a XGA screen has text mode, it will be VGA compatible.
XGA was IBM's attempt at creating a new graphics standard for their PS/2 line way back in the late '80s. It was fully VGA backwards-compatible. Beyond that, I don't know if the specifications were ever publicly released.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: XGA graphics

Post by bzt »

PeterX wrote:Well, it kind of works. But it will jump to the first line when it reaches the bottom of the screen. That's usually not very reader-friendly. So I would suggest scrolling intead (copying every line one line "higher" and then continue printing at the bottom of the screen.)
That's the purpose of the wiki: give a bare minimal working example. It was never a goal to provide fully featured, well-organized source code that anybody can copy'n'paste ;-) Just blindly copying code together without understanding is kinda supposed to fail :-)
PeterX wrote:EDIT:
I changed https://wiki.osdev.org/Meaty_Skeleton#k ... 86.2Ftty.c
I hope the code I added is not ugly or complicated and has no bugs.
Looks okay to me, thank you very much Peter!
sj95126 wrote:XGA was IBM's attempt at creating a new graphics standard for their PS/2 line way back in the late '80s. It was fully VGA backwards-compatible. Beyond that, I don't know if the specifications were ever publicly released.
I have a book on it, but it is by no means an official document. According to that book, teletype mode (aka. text mode) is exactly the same as VGA's, there's only difference in graphics mode resolutions and packed pixel formats.

Cheers,
bzt
sj95126
Member
Member
Posts: 151
Joined: Tue Aug 11, 2020 12:14 pm

Re: XGA graphics

Post by sj95126 »

Btw, I was looking through my dumping ground of ancient technical documents and downloads and found that a package released in the 1990s called "VGADOC 4/WHATVGA 2.00" has technical specs on the XGA I/O registers. You can still find this package with a google search.
Post Reply