5. The Video group of Modules

All of the Video handling code is in the "video" subdirectory.

There is one file for each video card or chipset and the master file. To Add a new card, it needs a set of save & restore routines putting in a file here.

5.1. Functions in env/video/video.c

These are the functions defined in env/video/video.c.

5.1.1. video_init

Set pointer to correct structure of functions to initialize, close, etc... video routines.

5.2. Remarks in env/video/video.c

Here the sleeping lion will be awoken and eat much of CPU time !!!

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.

5.3. Functions in env/video/X.c

These are the functions defined in env/video/X.c.

5.3.1. X_init

Initialize everything X-related.

5.3.2. X_close

Destroy the window, unload font, pixmap and colormap.

5.3.3. X_shm_init

Check availability of the MIT-SHM shared memory extension.

5.3.4. X_shm_init

Turn off usage of the MIT-SHM shared memory extension.

5.3.5. X_set_mouse_cursor

called by mouse.c to hide/display the mouse and set it's position. This is currently the only callback from mouse.c to X.

5.3.6. X_handle_events

Handle pending X events (called from SIGALRM handler).

5.3.7. graphics_cmap_init

Allocate a colormap for graphics modes and initialize it. Do mostly nothing on true color displays. Otherwise, do: - if colormaps have less than 256 entries (notably 16 or 2 colors), don't use a private colormap - if a shared map is requested and there are less than 36 colors (3/4/3) available, use a private colormap

Note: Text modes always use the screen's default colormap.

5.3.8. X_set_videomode

This is the interface function called by the video subsystem to set a video mode.

NOTE: The actual mode is taken from the global variable "video_mode".

5.3.9. X_setmode

Set the video mode. If init_vga is zero, this will only reinitialize the current mode. The other arguments are ignored in this case.

5.3.10. X_update_screen

Update the part of the screen which has changed, in text mode and in graphics mode. Usually called from the SIGALRM handler.

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 top 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.

5.3.11. set_mouse_position

Place the mouse on the right position.

5.4. Remarks in env/video/X.c

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

5.5. Functions in env/video/vgaemu.c

These are the functions defined in env/video/vgaemu.c.

5.5.1. VGA_emulate_outb

Emulates writes to VGA ports. This is a hardware emulation function.

Arguments are:

  • port - The port being written to.

  • value - The value written,

5.5.2. VGA_emulate_inb

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

Arguments are:

  • port - The port being read from.

5.5.3. 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.

MODIFICATION: VGA mode 12h under X is supported in exactly the way that was suggested above. Not every instruction needs to be simulated in order to make this feature useful, just the ones used to access video RAM by key applications (Borland BGI, Protel, etc.).

MODIFICATION: all VGA modes now work and almost all instructions are simulated.

Arguments are:

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

5.5.4. 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.

5.5.5. 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.

5.5.6. vgaemu_switch_plane

vgaemu_switch_plane() maps the specified plane.

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

Arguments are:

  • plane (0..3) - The plane to map.

5.5.7. 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.

5.5.8. 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

5.5.9. 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.

5.5.10. vga_emu_set_textsize

Sets the text mode resolution. Typically called after a font change.

Arguments are:

  • width - Number of text columns.

  • height - Number of text rows.

5.5.11. dirty_all_video_pages

Marks the whole VGA memory as modified.

5.5.12. 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.

Arguments are:

  • page - Number of the text page.

  • page_size - Size of one text page.

5.5.13. dirty_all_vga_colors

Marks all colors as changed.

5.5.14. changed_vga_colors

Checks DAC and Attribute Controller to find all colors with changed RGB-values. Returns number of changed colors. Note: the list _must_ be large enough, that is, have at least min(256, (1 << vga.pixel_size)) entries!

Arguments are:

  • de - list of DAC entries to store changed colors in

5.5.15. vgaemu_adj_cfg

Adjust VGAEmu according to VGA register changes.

5.6. Functions in env/video/vesa.c

These are the functions defined in env/video/vesa.c.

5.6.1. 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.

5.6.2. 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.

5.7. Functions in env/video/attremu.c

These are the functions defined in env/video/attremu.c.

5.7.1. Attr_init

Initializes the attribute controller. This is an interface function.

5.7.2. Attr_get_entry

Directly reads the Attribute Controller's registers. This is an interface function.

5.7.3. Attr_set_entry

Directly sets the Attribute Controller's registers. This is an interface function.

5.7.4. Attr_read_value

Emulates reads from the attribute controller. This is a hardware emulation function.

5.7.5. Attr_write_value

Emulates writes to attribute controller combined index and data register. Read VGADOC for details. This is a hardware emulation function.

5.7.6. Attr_get_index

Returns the current index of the attribute controller. This is a hardware emulation function, though in fact this function is undefined in a real attribute controller. Well, it is exactly what my VGA board (S3) does. -- sw This is a hardware emulation function.

5.8. Functions in env/video/dacemu.c

These are the functions defined in env/video/dacemu.c.

5.8.1. DAC_init

Initializes the DAC. It depends on a correct value in vga.pixel_size. This function should be called during VGA mode initialization. This is an interface function.

5.8.2. DAC_set_width

Sets the DAC width. Typical values are 6 or 8 bits. In theory, we support other values as well (untested). This is an interface function.

5.8.3. DAC_get_entry

Returns a complete DAC entry (r, g, b). Don't forget to set DAC_entry.index first! This is an interface function.

5.8.4. DAC_set_entry

Sets a complete DAC entry (r,g,b). This is an interface function.

5.8.5. DAC_rgb2gray

Converts a DAC register's RGB values to gray scale. This is an interface function.

5.8.6. DAC_set_read_index

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

5.8.7. DAC_set_write_index

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

5.8.8. 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 VGADOC4 if you want to know more about the DAC. This is a hardware emulation function.

5.8.9. 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.

5.8.10. DAC_get_pel_mask

Returns the current PEL mask. Note that changed_vga_colors() already applies the PEL mask; so applications should not worry too much about it. This is a hardware emulation function.

5.8.11. DAC_set_pel_mask

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

5.8.12. DAC_get_state

Returns the current state of the DAC. This is a hardware emulation function.

5.9. Functions in env/video/crtcemu.c

These are the functions defined in env/video/crtcemu.c.

5.9.1. CRTC_init

Initializes the CRT Controller. This is an interface function.

5.10. Functions in env/video/dualmon.c

These are the functions defined in env/video/dualmon.c.

5.10.1. 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.

returns: nothing

Arguments are:

  • none

5.11. Remarks in env/video/dualmon.c

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:

- AMD 386DX40, Trident 9000/512Kb ISA, Hercules Graphics Card Plus - Intel 486DX2/66, Cirrus Logic 5426/1Mb VLB, Hercules clone

The problem doesn't occur when I start dosemu from a telnet connection or from a VT100 terminal. (Erik Mouw, jakmouw@et.tudelft.nl)

5.12. Functions in env/video/vgaemu.c

These are the functions defined in env/video/vgaemu.c.

5.12.1. VGA_emulate_outb

Emulates writes to VGA ports. This is a hardware emulation function.

Arguments are:

  • port - The port being written to.

  • value - The value written,

5.12.2. VGA_emulate_inb

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

Arguments are:

  • port - The port being read from.

5.12.3. 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.

MODIFICATION: VGA mode 12h under X is supported in exactly the way that was suggested above. Not every instruction needs to be simulated in order to make this feature useful, just the ones used to access video RAM by key applications (Borland BGI, Protel, etc.).

MODIFICATION: all VGA modes now work and almost all instructions are simulated.

Arguments are:

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

5.12.4. 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.

5.12.5. 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.

5.12.6. vgaemu_switch_plane

vgaemu_switch_plane() maps the specified plane.

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

Arguments are:

  • plane (0..3) - The plane to map.

5.12.7. 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.

5.12.8. 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

5.12.9. 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.

5.12.10. vga_emu_set_textsize

Sets the text mode resolution. Typically called after a font change.

Arguments are:

  • width - Number of text columns.

  • height - Number of text rows.

5.12.11. dirty_all_video_pages

Marks the whole VGA memory as modified.

5.12.12. 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.

Arguments are:

  • page - Number of the text page.

  • page_size - Size of one text page.

5.12.13. dirty_all_vga_colors

Marks all colors as changed.

5.12.14. changed_vga_colors

Checks DAC and Attribute Controller to find all colors with changed RGB-values. Returns number of changed colors. Note: the list _must_ be large enough, that is, have at least min(256, (1 << vga.pixel_size)) entries!

Arguments are:

  • de - list of DAC entries to store changed colors in

5.12.15. vgaemu_adj_cfg

Adjust VGAEmu according to VGA register changes.

5.13. Functions in env/video/instremu.c

These are the functions defined in env/video/instremu.c.

5.13.1. instr_len

Returns the length of an instruction; 0 if it could not be determined.

5.13.2. instr_sim

instr_sim is used to simulate instructions that access the VGA video memory in planar modes when using X as the video output device.

It is necessary to do this in order to simulate the effects of the hardware VGA controller in X mode.

If the return value is 0, it means the instruction was not one that for which a simulation is provided. The return value is 1 for success, but the function exits because we need to go back to the DOSEMU's main loop or count runs out.

Arguments are:

  • x86: the structure holding everything about the cpu-state we need.

5.13.3. instr_emu

instr_emu is the main interface to instr_sim. It puts the processor state in the x86 structure.

Arguments are:

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

  • cp - A pointer to the instruction to be simulated