Flashing text

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
Uranium
Posts: 16
Joined: Fri Jul 04, 2008 8:00 am

Flashing text

Post by Uranium »

Ok, basically, working on a new OS in textmode, it refreshes alot because it has to constantly check what it is displaying to the screen incase something has changed. On emulators (Virtual Box, QEMU and VMWare Workstation) it runs smoothly, exactly how I plan. But on real hardware (two shitty old graphics cards and an old monitor & my laptop) all but one line on the display flashes on and off.

To cover all possible corners, I implemented double buffering and it didn't make the slightest bit of difference. The flashing occurs about twice a second and (again) on all but one line (which is the most confusing thing).

Here are the textmode functions which are called:

Code: Select all

word *screen_memory  = (word *)0;
word *screen_memory1 = (word *)0x000B8000;

void textmode_install(void)
{
	screen_memory = (word *)malloc(80 * 25 * sizeof(word));
}

void textmode_flush(void)
{
	memcpyw(screen_memory1, screen_memory, 80 * 25);
}

void textmode_clear(void)
{
	memsetw(screen_memory, (text_color << 8) | ' ', 80 * 25);
	cursor_xpos = 0, cursor_ypos = 0;
	textmode_updatecursor();
}

void textmode_writeline(char *line, int index)
{
	bool null   = FALSE;

	int i;
	for(i = 0; i < 80; i++) {
		if(!null) {
			if(line[i])
				screen_memory[(80 * index) + i] = (text_color << 8) | line[i];
			else
				null = TRUE;
		}
		if(null) screen_memory[(80 * index) + i]= (text_color << 8) | ' ';
	}
}
The part of code which does the rendering: (This is called every second by the RTC interrupt)
It basically scans through a linked list to find the 23 events which are going to occur next, places them in order, and displays them to the screen

Code: Select all

	event_t *EventList[23];
	memset(&EventList, 0, sizeof(event_t *) * 23);

	event_t *EventPointer = FirstEvent;
	int i;
	while(EventPointer) {
		for(i = 0; i < 23; i++) {
			if(!EventList[i]) {
				EventList[i] = EventPointer;
				break;
			}else if(EarlierRecord(&(EventPointer->TimeOfEvent), &(EventList[i]->TimeOfEvent))) {
				memmove(&(EventList[i + 1]), &(EventList[i]), 23 - i);
				EventList[i] = EventPointer;
				break;
			}
		}
		EventPointer = EventPointer->NextEvent;
	}

	record_t CurrentTime;
	rtc_CopyTime(&CurrentTime);

	char HeaderLineOne[] = "00:00:00 00/00/00 - TimetableOS by Andrew Carter";
	char HeaderLineTwo[] = "Time     Date     ID   Description";
	
	RecordToString(&CurrentTime, HeaderLineOne);

	textmode_settextcolor(COLOR_BLACK, COLOR_LTRED);
	textmode_clear();
	textmode_settextcolor(COLOR_BLACK, COLOR_LTBROWN);
	textmode_writeline(HeaderLineOne, 0);
	textmode_settextcolor(COLOR_BLACK, COLOR_RED);
	textmode_writeline(HeaderLineTwo, 1); // << Line which isn't flashing
	textmode_settextcolor(COLOR_BLACK, COLOR_LTRED);

	static char buffer[80] = "00:00:00 00/00/00 ";
	buffer[22] = ' ';
	for(i = 0; EventList[i] && (i < 23); i++){
		RecordToString(&(EventList[i]->TimeOfEvent), buffer);
		memcpy(buffer + 18, EventList[i]->ID, 4);
		memcpy(buffer + 23, EventList[i]->Description, 57);
		textmode_writeline(buffer, 2 + i);
	}

	textmode_flush();
The second line is the line which isn't flashing, even though it is written in the same method as the first.

HALP!?!?!
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Flashing text

Post by bewing »

As I recall, in textmode, if the BACKGROUND color has a value higher than 7, then the FOREGROUND will flash (and the actual background color used will be masked with a 7). All of the "light" colors have values higher than 7. Therefore, you cannot implement a "dark text on light screen" theme, unless you use "medium blue" for your light screen (color #3) or "medium gray" (color #7). The reason line 2 doesn't flash is that you are using color #4 (red) for your background.

None of the emulators bother trying to emulate the flashing text -- they just display the background color as if the whole 4 bits should be encoded as a color.
User avatar
Walling
Member
Member
Posts: 158
Joined: Mon Dec 04, 2006 6:06 am
Location: Berlin, Germany

Re: Flashing text

Post by Walling »

I think you can change that behaviour by setting some registers in the VGA attribute controller. I don't know much about it in general, but as far as the documentation I recall it has a register controlling whether bit 8 of the attribute field controls blinking or not. You want to disable blinking and enable light background colours. These links might be helpful: Attribute Controller Registers and Accessing the VGA Registers. Look for the BLINK bit in register index 0x10. Please let me know if it works out.
Post Reply