Here's all the calls to the code to try and properly save & restore
the video state between VC's and the attempts to control updates to
the VC whilst the user is using another. We map between the real
screen address and that used by DOSEMU here too.

Attempts to use a cards own bios require the addition of the parameter
"graphics" to the video statement in "/etc/dosemu.conf". This will make
the emulator try to execute the card's initialization routine which is
normally located at address c000:0003. This can now be changed as an
option.

video_init

The result of setting VM86_SCREEN_BITMAP (at state of Linux 1.1.56):
Each vm86 call will set 32 pages of video mem RD-only
(there may be 1000000 per second)
Write access to RD-only page results in page-fault (mm/memory.c),
which will set a bit in current->screen_bitmap and calls do_wp_page()
which does __get_free_page(GFP_KERNEL) but frees it immediatly,
because copy-on-write is not neccessary and sets RD/WR for the page.
(this could happen 32000000 per second, if the CPU were fast enough)
It would be better to get the DIRTY-bit directly from the page table,
isn't it? A special syscall in emumodule could do this.

-----

reserve_video_memory()

This procedure is trying to eke out all the UMB blocks possible to
maximize your memory under DOSEMU. If you know about dual monitor
setups, you can contribute by putting in the correct graphics page
address values.

vga256_cmap_init

X_close

X_setmode

Resizes the window, also the graphical sizes/video modes.
remember the dos videomodi

X_change_mouse_cursor(void)

This function seems to be called each screen_update :(
It is called in base/mouse/mouse.c:mouse_cursor(int) a lot for show and
hide.

X_redraw_screen

Redraws the entire screen, also in graphics mode
Used for expose events etc.

returns:
nothing

Arguments are:

none

X_update_screen

Updates the X screen, in text mode and in graphics mode.
Both text and graphics in X have to be smarter and improved.

X_update_screen returns 0 if nothing was updated, 1 if the whole
screen was updated, and 2 for a partial update.

It is called in arch/linux/async/signal.c::SIGALRM_call() as part
of a struct video_system (see end of X.c) every 50 ms or
every 10 ms if 2 was returned, depending somewhat on various config
options as e.g. config.X_updatefreq and VIDEO_CHECK_DIRTY.
At least it is supposed to do that.

Arguments are:

none

set_mouse_position

DO NOT REMOVE THIS TEST!!!
It is magic, without it EMS fails on my machine under X.
Perhaps someday when we don't use a buggy /proc/self/mem..
-- EB 18 May 1998
A slightly further look says it's not the test so much as
suppressing noop resize events...
-- EB 1 June 1998

VGA_emulate_outb

VGA_emulate_inb

Emulates reads from VGA ports.
This is a hardware emulation function.

Arguments are:

port - The port being read from.

vga_emu_fault

vga_emu_fault() is used to catch video access, and handle it.
This function is called from arch/linux/async/sigsegv.c::dosemu_fault1().
The sigcontext_struct is defined in include/cpu.h.
Now it catches only changes in a 4K page, but maybe it is useful to
catch each video access. The problem when you do that is, you have to
simulate each instruction which could write to the video memory.
It is easy to get the place where the exception happens (scp->cr2),
but what are those changes?
An other problem is, it could eat a lot of time, but it does now also.

Arguments are:

scp - A pointer to a struct sigcontext_struct holding some relevant data.

vga_emu_init

vga_emu_init() must be called before using the VGAEmu functions.
It is only called from env/video/X.c::X_init() at the moment.
This function basically initializes the global variable `vga' and
allocates the VGA memory.

It does in particular *not* map any memory into the range
0xa0000 - 0xc0000, this is done as part of a VGA mode switch.

There should be an accompanying vga_emu_done().

Arguments are:

vedt - Pointer to struct describing the type of display we are actually

attached to.

vga_emu_update

vga_emu_update() scans the VGA memory for dirty (= written to since last
update) pages and returns the changed area in *veut. See the definition
of vga_emu_update_type in env/video/vgaemu_inside.h for details.

You will need to call this function repeatedly until it returns 0 to
grab all changes. You can specify an upper limit for the size of the
area that will be returned using `veut->max_max_len' and `veut->max_len'.
See the example in env/video/X.c how this works.

If the return value of vga_emu_update() is >= 0, it is the number of changed
pages, -1 means there are still changed pages but the maximum update chunk size
(`veut->max_max_len') was exceeded.

This function does in its current form not work for Hercules modes; it
does, however work for text modes, although this feature is currently
not used.

Arguments are:

veut - A pointer to a vga_emu_update_type object holding all relevant info.

vga_emu_switch_bank

vga_emu_switch_bank() is used to emulate video-bankswitching.

This function returns True on success and False on error, usually
indicating an invalid bank number.

Arguments are:

bank - The bank to switch to.

vga_emu_find_mode

Searches a video mode with the requested mode number.

The search starts with the mode *after* the mode `vmi' points to.
If `vmi' == NULL, starts at the beginning of the internal mode table.
`mode' may be a standard VGA mode number (0 ... 0x7f) or a
VESA mode number (>= 0x100). The mode number may have its don't-clear-bit
(bit 7 or bit 15) or its use-lfb-bit (bit 14) set.
The special mode number -1 will match any mode and may be used to
scan through the whole table.

Returns NULL if no mode was found and a pointer into the mode table
otherwise. The returned pointer is a suitable argument for subsequent
calls to this function.

You should (and can) access the mode table only through this function.

Arguments are:

mode - video mode.

vmi - pointer into internal mode list

vga_emu_setmode

Set a video mode.

Switches to `mode' with text sizes `width' and `height' or (if no such
mode was found) at least `width' and `height'.

Arguments are:

mode - The new video mode.

width - Number of text columns.

height - Number of text rows.

dirty_all_video_pages

Marks the whole VGA memory as modified.

vga_emu_set_text_page

Set visible text page.

`vga.display_start' is set to `page' * `page_size'.
This function works only in text modes.

vbe_init

Initializes the VGA/VBE BIOS and the VBE support.

Arguments are:

vedt - Pointer to struct describing the type of display we are actually

attached to.

vesa_emu_fault

vesa_emu_fault() is used to handle video ROM accesses.
This function is called from env/video/vgaemu.c:vga_emu_fault().
The sigcontext_struct is defined in include/cpu.h
It just jumps over the instruction (LWORD (eip) += instr-len)
which caused the write exception to the video ROM. It is needed for
some dirty programs that try to write to a ROM (dos=high,umb seems
to do this, but not on all PC's). We're sure now, nobody can write to
the ROM and we don't crash on it, just ignore as it should be!

Arguments are:

scp - A pointer to a struct sigcontext_struct holding some relevant data.

do_vesa_int

This is the VESA interrupt handler.

It is called from base/bios/int10.c::int10(). The VESA interrupt is called
with 0x4f in AH and the function number (0x00 ... 0x10) in AL.

This is what DOS applications see as their video BIOS. It will be
mapped at 0xc000:0x0000 and typically be less than one page in size.
This video BIOS is write-protected, write accesses to this memory
are emulated by vesa_emu_fault() in env/video/vesa.c.

It doesn't have much functionality, just stores the VESA mode table
and the protected mode interface necessary for VESA BIOS Extension (VBE)
support.

Note that some parts of the video BIOS are added by vbe_init()
in env/video/vesa.c.

DAC_init

DAC_dirty_all

DAC_set_read_index

Specifies which palette entry is read.
This is a hardware emulation function.

DAC_set_write_index

Specifies which palette entry is written.
This is a hardware emulation function.

DAC_read_value

Read a value from the DAC. Each read will cycle through the registers for
red, green and blue. After a ``blue read'' the read index will be
incremented. Read vgadoc3 if you want to know more about the DAC.
This is a hardware emulation function.

DAC_write_value

Write a value to the DAC. Each write will cycle through the registers for
red, green and blue. After a ``blue write'' the write index will be
incremented.
This is a hardware emulation function.

DAC_set_pel_mask

Sets the pel mask and marks all DAC entries as dirty.
This is a hardware emulation function.

DAC_get_entry

Returns a complete DAC entry (r,g,b). Color values are AND-ed with the
pel mask.
This is an interface function.

DAC_read_entry

DAC_get_dirty_entry

Searches the DAC_dirty list for the first dirty entry. Returns the
changed entrynumber and fills in the entry if a dirty entry is found or
returns -1 otherwise.
This is an interface function.

DAC_set_entry

Sets a complete DAC entry (r,g,b).
This is an interface function for the int 10 handler.

DAC_get_pel_mask

Returns the current pel mask. Drawing functions should get the pel
mask and AND it with the pixel values to get the correct pixel value.
This is *very* slow to implement and fortunately this register is used
very rare. Maybe the implementation should be in vgaemu, maybe in the
vgaemu client...
This is an interface function.

MDA_init

Initializes the monochrome card. First detects which monochrome
card is used, because the Hercules RamFont and the Hercules InColor
need one more register to be initialized. If there is no monochrome
card at all, we just think there is one and poke an peek in the void.
After the detection the card is initialized.

After MDA_init() the VGA is configured, something in video.c
or console.c "reprograms" the monochrome card again in such a way
that I always have to run hgc.com before I can use any program that
uses the monochrome card. I've spent a day trying to find it, but I
can't figure out. Something is writing to one of the following ports:
0x3b4, 0x3b5, 0x3b8, 0x3b9, 0x3ba, 0x3bb, 0x3bf.
The problem occurs at (at least) the following 2 systems:

This module handles the int10 video functions.
Most functions here change only the video memory and status
variables; the actual screen is then rendered asynchronously
after these by Video->update_screen.

VGA_emulate_outb

VGA_emulate_inb

Emulates reads from VGA ports.
This is a hardware emulation function.

Arguments are:

port - The port being read from.

vga_emu_fault

vga_emu_fault() is used to catch video access, and handle it.
This function is called from arch/linux/async/sigsegv.c::dosemu_fault1().
The sigcontext_struct is defined in include/cpu.h.
Now it catches only changes in a 4K page, but maybe it is useful to
catch each video access. The problem when you do that is, you have to
simulate each instruction which could write to the video memory.
It is easy to get the place where the exception happens (scp->cr2),
but what are those changes?
An other problem is, it could eat a lot of time, but it does now also.

Arguments are:

scp - A pointer to a struct sigcontext_struct holding some relevant data.

vga_emu_init

vga_emu_init() must be called before using the VGAEmu functions.
It is only called from env/video/X.c::X_init() at the moment.
This function basically initializes the global variable `vga' and
allocates the VGA memory.

It does in particular *not* map any memory into the range
0xa0000 - 0xc0000, this is done as part of a VGA mode switch.

There should be an accompanying vga_emu_done().

Arguments are:

vedt - Pointer to struct describing the type of display we are actually

attached to.

vga_emu_update

vga_emu_update() scans the VGA memory for dirty (= written to since last
update) pages and returns the changed area in *veut. See the definition
of vga_emu_update_type in env/video/vgaemu_inside.h for details.

You will need to call this function repeatedly until it returns 0 to
grab all changes. You can specify an upper limit for the size of the
area that will be returned using `veut->max_max_len' and `veut->max_len'.
See the example in env/video/X.c how this works.

If the return value of vga_emu_update() is >= 0, it is the number of changed
pages, -1 means there are still changed pages but the maximum update chunk size
(`veut->max_max_len') was exceeded.

This function does in its current form not work for Hercules modes; it
does, however work for text modes, although this feature is currently
not used.

Arguments are:

veut - A pointer to a vga_emu_update_type object holding all relevant info.

vga_emu_switch_bank

vga_emu_switch_bank() is used to emulate video-bankswitching.

This function returns True on success and False on error, usually
indicating an invalid bank number.

Arguments are:

bank - The bank to switch to.

vga_emu_find_mode

Searches a video mode with the requested mode number.

The search starts with the mode *after* the mode `vmi' points to.
If `vmi' == NULL, starts at the beginning of the internal mode table.
`mode' may be a standard VGA mode number (0 ... 0x7f) or a
VESA mode number (>= 0x100). The mode number may have its don't-clear-bit
(bit 7 or bit 15) or its use-lfb-bit (bit 14) set.
The special mode number -1 will match any mode and may be used to
scan through the whole table.

Returns NULL if no mode was found and a pointer into the mode table
otherwise. The returned pointer is a suitable argument for subsequent
calls to this function.

You should (and can) access the mode table only through this function.

Arguments are:

mode - video mode.

vmi - pointer into internal mode list

vga_emu_setmode

Set a video mode.

Switches to `mode' with text sizes `width' and `height' or (if no such
mode was found) at least `width' and `height'.

Arguments are:

mode - The new video mode.

width - Number of text columns.

height - Number of text rows.

dirty_all_video_pages

Marks the whole VGA memory as modified.

vga_emu_set_text_page

Set visible text page.

`vga.display_start' is set to `page' * `page_size'.
This function works only in text modes.