Podcast
Questions and Answers
What type of events does a mouse detect?
What type of events does a mouse detect?
- Presses, releases, and movement (correct)
- Keyboard presses
- Network connectivity status
- Screen resolution changes
What is the purpose of the two counters in a mouse?
What is the purpose of the two counters in a mouse?
- To count the number of clicks
- To measure movement in the X and Y directions (correct)
- To store the mouse's serial number
- To track the time since the last click
How many bytes are in a mouse data packet?
How many bytes are in a mouse data packet?
- 3 (correct)
- 1
- 4
- 2
What is the primary function of the Keyboard Controller (KBC) in the context of mouse operation?
What is the primary function of the Keyboard Controller (KBC) in the context of mouse operation?
In a mouse data packet, what information is contained in the first byte?
In a mouse data packet, what information is contained in the first byte?
What is the purpose of the 'Write Byte to Mouse' command?
What is the purpose of the 'Write Byte to Mouse' command?
Which KBC port is used to write the actual command or argument byte to the mouse?
Which KBC port is used to write the actual command or argument byte to the mouse?
What is the function of the 0xF5
command in mouse operation?
What is the function of the 0xF5
command in mouse operation?
What is the significance of the interrupt request IRQ12
in mouse operation?
What is the significance of the interrupt request IRQ12
in mouse operation?
What is 'stream mode' in the context of mouse operation?
What is 'stream mode' in the context of mouse operation?
How does a program interact with the KBC to interface with the mouse?
How does a program interact with the KBC to interface with the mouse?
In event-driven design, what is the role of an event dispatcher?
In event-driven design, what is the role of an event dispatcher?
What is the difference between a Mealy machine and a Moore machine in the context of state machines?
What is the difference between a Mealy machine and a Moore machine in the context of state machines?
Why are function pointers useful in event-driven programming?
Why are function pointers useful in event-driven programming?
What is the purpose of the Video BIOS Extension (VBE)?
What is the purpose of the Video BIOS Extension (VBE)?
What is the key difference between text mode and graphic mode in video display?
What is the key difference between text mode and graphic mode in video display?
In direct-color mode, how is the color of each pixel stored in VRAM?
In direct-color mode, how is the color of each pixel stored in VRAM?
What is the role of sys_int86
in Minix 3 when configuring the video card?
What is the role of sys_int86
in Minix 3 when configuring the video card?
What is the purpose of vm_map_phys
when accessing VRAM?
What is the purpose of vm_map_phys
when accessing VRAM?
What is the X Pixmap (XPM) format used for in the context of video display?
What is the X Pixmap (XPM) format used for in the context of video display?
What determines the speed of animation of sprites?
What determines the speed of animation of sprites?
What is the key advantage of vector graphics over raster graphics?
What is the key advantage of vector graphics over raster graphics?
What is the purpose of Vertical Sync (VSync) in video rendering?
What is the purpose of Vertical Sync (VSync) in video rendering?
What is the primary purpose of double buffering in computer graphics?
What is the primary purpose of double buffering in computer graphics?
What is page flipping in the context of video memory management?
What is page flipping in the context of video memory management?
In the context of moving sprites, why is resetting pixels important, and what is a drawback of doing it directly in the visible framebuffer?
In the context of moving sprites, why is resetting pixels important, and what is a drawback of doing it directly in the visible framebuffer?
Triple buffering adds a second back buffer to the rendering pipeline. How does this specifically address limitations encountered even when using VSync with double buffering?
Triple buffering adds a second back buffer to the rendering pipeline. How does this specifically address limitations encountered even when using VSync with double buffering?
Consider a scenario where a game developer aims to minimize both tearing and input lag. Given the trade-offs between different buffering techniques, which combination would be optimal, and why?
Consider a scenario where a game developer aims to minimize both tearing and input lag. Given the trade-offs between different buffering techniques, which combination would be optimal, and why?
A developer implements a custom memory manager for sprites in a game, aiming to optimize memory usage and reduce fragmentation. The manager uses a free list and a buddy system. During testing, they observe that, despite sufficient total memory available, new sprite allocations occasionally fail. What is the most likely cause of this issue?
A developer implements a custom memory manager for sprites in a game, aiming to optimize memory usage and reduce fragmentation. The manager uses a free list and a buddy system. During testing, they observe that, despite sufficient total memory available, new sprite allocations occasionally fail. What is the most likely cause of this issue?
Flashcards
Mouse Operation
Mouse Operation
Detects presses, releases, and movement. Movement uses X and Y counters, reset after communication.
Mouse Communication
Mouse Communication
The mouse informs the KBC of events by sending a 3-byte data packet via a serial line. Each byte goes to KBC's OUT_BUF; KBC triggers IRQ12.
Data Packet - Byte 1
Data Packet - Byte 1
Contains flags for X/Y overflow, button states (middle, right, left), and MSB of delta X/Y. Bit 3 is always set.
Data Packet - Byte 2
Data Packet - Byte 2
Signup and view all the flashcards
Data Packet - Byte 3
Data Packet - Byte 3
Signup and view all the flashcards
Stream Mode
Stream Mode
Signup and view all the flashcards
Remote Mode
Remote Mode
Signup and view all the flashcards
Sending Commands to Mouse
Sending Commands to Mouse
Signup and view all the flashcards
Command 0xFF
Command 0xFF
Signup and view all the flashcards
Command 0xF6
Command 0xF6
Signup and view all the flashcards
Command 0xF5
Command 0xF5
Signup and view all the flashcards
Command 0xF4
Command 0xF4
Signup and view all the flashcards
Command 0xF3
Command 0xF3
Signup and view all the flashcards
Command 0xF0
Command 0xF0
Signup and view all the flashcards
Command 0xEB
Command 0xEB
Signup and view all the flashcards
Command 0xEA
Command 0xEA
Signup and view all the flashcards
Mouse Acknowledgment
Mouse Acknowledgment
Signup and view all the flashcards
Event Driven Design
Event Driven Design
Signup and view all the flashcards
Events
Events
Signup and view all the flashcards
Event Handler
Event Handler
Signup and view all the flashcards
Dispatchers
Dispatchers
Signup and view all the flashcards
State Machines
State Machines
Signup and view all the flashcards
Pointers
Pointers
Signup and view all the flashcards
Switch Statement (Events)
Switch Statement (Events)
Signup and view all the flashcards
Function Pointer Table
Function Pointer Table
Signup and view all the flashcards
Video Card Components
Video Card Components
Signup and view all the flashcards
Text Mode
Text Mode
Signup and view all the flashcards
Graphic Mode
Graphic Mode
Signup and view all the flashcards
Direct-color Mode
Direct-color Mode
Signup and view all the flashcards
Sprite Animation
Sprite Animation
Signup and view all the flashcards
Study Notes
Mouse Operation
- Detects presses, releases, and movement events.
- Uses two 9-bit 2's complement counters for X and Y directions, reset after communication.
- Some touchpads communicate absolute positions
- Informs the KBC of events by sending a 3-byte data packet via a serial line.
- Each byte of the packet is placed in the KBC's
OUT_BUF
. - The KBC triggers
IRQ12
(which isIRQ4
onPIC 2
) for each received byte.
Data Packet Structure
- Byte 1: Contains overflow flags for X and Y deltas and button states.
- Includes the MSB of the Y delta.
- Includes the MSB of the X delta.
- Indicates middle, right, and left button states (
1
if pressed). - Bit 3 is always set to
1
.
- Byte 2: Contains the 8 LSB of the X-axis relative displacement (delta X).
- Combined with the X MSB from Byte 1, forms a 9-bit 2's complement integer.
- Byte 3: Contains the 8 LSB of the Y-axis relative displacement (delta Y).
- Combined with the Y MSB from Byte 1, forms a 9-bit 2's complement integer.
Mouse Operation Modes
- Stream Mode (Default): Continuously sends data packets to the KBC at a fixed rate whenever mouse events occur.
- Remote Mode: Sends data packets only when explicitly requested by the KBC.
Mouse Commands
- Sent to the mouse via the KBC using the "Write Byte to Mouse" command (
0xD4
), written to the KBC's command port (0x64
). - The byte to be sent (command or argument) is written to the KBC's data port (
0x60
). 0xFF
: Resets the mouse.0xF6
: Sets default values.0xF5
: Disables data reporting (used in stream mode before other commands).0xF4
: Enables data reporting (stream mode only).0xF3
: Sets the sample rate.0xF0
: Sets remote mode.0xEB
: Reads data (requests a data packet in remote mode).0xEA
: Sets stream mode.0xE9
: Requests status (mouse configuration).0xE8
: Sets the resolution.0xE7
/0xE6
: Sets the scale (2:1
or1:1
).- The mouse sends an acknowledgment byte (
0xFA
for ACK,0xFE
for NACK,0xFC
for ERROR) in response to most received bytes. - The ACK byte is placed in the KBC's
OUT_BUF
and must be read from port0x60
. - For commands that trigger a data response, the mouse sends the response after acknowledging the last byte of the command.
- The mouse must be first disabled using the command
0xF5
before sending other commands in stream mode after enabling data report.
Mouse Implementation Details
- Interacting with the mouse requires interfacing with the KBC (i8042) using I/O ports
0x60
(data) and0x64
(status/command). - Mouse interrupts (
IRQ12
) are subscribed usingsys_irqsetpolicy()
.IRQ_EXCLUSIVE
is important to prevent interference from Minix's default mouse handler.
- The interrupt handler does not need to explicitly check
OBF
orAUX
bits, as the KBC uses differentIRQ
lines for the keyboard and mouse. - Since the mouse data packet has 3 bytes, these bytes must be assembled in the driver.
- A buffer and counter are used. The 1st byte has bit 3 set, as a hint for synchronization. All 3 bytes must belong to the same package, requiring checking.
Event Driven Design
- Programs wait for events to occur and react to them, instead of executing top-down.
- They wait for clients to signal an event and then act.
- Events: Signals that something interesting has happened, such as mouse clicks, timer triggers, or data arrival from the network.
- Event handler: Specific code sections that handle each event type.
- Dispatchers: Manage event handlers by listening for events and calling the correct handler.
State Machines
- State machines can function with event driven design.
- The program can be in different "modes". How it responds to an event may change based on the current "mode" or state.
- Useful when the event handler depends on input event and process state (Mealy machine), or when it depends only on process state (Moore machine).
- Example states:
INIT
,DRAW
,COMP
with events likeRDOWN
(right button pressed),RUP
(right button released).
Event Processing
- Application Dependent: IH performs more processing and may decide what the event means for the program.
- Application Independent: IH only gets raw data from the hardware, and other parts of the program decide what to do with it.
- Device drivers in Minix 3 generally use an application-independent approach, processing interrupt notifications.
Function Pointers
- Store the address of a function in memory, treating functions as data.
- Allow assigning functions to variables.
- Allow storing functions in arrays, structs, or unions.
- Functions can be passed as arguments to other functions.
- Functions can be returned from other functions.
- Example:
int (*fp)(int);
declares a pointer to a function that takes anint
and returns anint
.
Function Pointers in Events
- Useful for linking events to their handlers.
- Events
- Switch Statement: Selects the event handler based on event type.
- Table of Function Pointers: An array where each index corresponds to an event type and stores the pointer to the handler.
- State Machines: The event handler depends on the current state and the event.
- Two-Dimensional Table: Indexed by state and event.
- Menus: Each menu item executes a specific action.
- Each menu entry stores a pointer to the function.
- Device Drivers
- Generic Operations: Defines a common interface for different devices.
- Flexibility: allows replacing operations to adapt to different hardware
Video Card
- Interfaces between the computer and the monitor.
- GPU: Controls the screen hardware and performs rendering, reducing CPU usage.
- VRAM: Memory storing data to be rendered on the screen.
- BIOS ROM/Flash: Non-volatile memory containing firmware and code for basic video I/O operations, such as VBE.
x86 Registers
Register | Size | Parts | Typical Use |
---|---|---|---|
AL |
8 bits | Low of AX |
8-bit data/operations |
AH |
8 bits | High of AX |
BIOS functions, MSB operations |
AX |
16 bits | AH + AL |
Real mode (16-bit) |
EAX |
32 bits | Extends AX |
Protected/64 bit mode |
Video Modes
- Text Mode: Grid of characters (e.g., 80x25).
- Graphic Mode: Matrix of pixels, each with a color stored in VRAM.
- Direct-color mode: the color of each pixel is stored directly in VRAM, using 3 intensity values (Red, Green, Blue - RGB)
- 8 bits / color / pixel
- Indexed mode: stores an index of a table (palette) of colors in VRAM. The palette contains the definition (RGB intensities) of each color.
- 8 bit index -> 256 colors
Memory Model
- Determines how video memory is organized.
- Linear Mode: Pixels are stored contiguously in memory in a linear framebuffer.
- Requires knowing the framebuffer base address (
vbe_get_mode_info()
), pixel coordinates, and number of bytes used to encode the color.
- Requires knowing the framebuffer base address (
Video Card Configuration
- Minix 3 typically starts in text mode.
- The GPU is configured using standardized interfaces through BIOS and VBE.
- BIOS services are provided through interrupts (
INT xx
). - VBE (Video BIOS Extension): Supports higher resolutions using INT
0x10
, differentiated by theAH
register value.
- BIOS services are provided through interrupts (
- Calls to real-mode BIOS can be made from user level in Minix 3 using the
sys_int86
kernel call, which temporarily switches from 32-bit protected mode to 16-bit real mode. - Arguments for BIOS calls are passed through CPU registers represented by the
reg86_t
struct.
VRAM Access
- Images can be drawn on the screen from graphic mode.
Obtain the physical memory address of the framebuffer using
vbe_get_mode_info()
(or implement your own using VBE function0x01
). Thevbe_mode_info_t
struct contains:- Screen dimensions.
- Color depth.
- Physical base address of the framebuffer (
PhysBasePtr
).
- Mapping the region of physical memory into the process's virtual address space using kernel calls.
Process user-level cannot directly access the physical memory, hence
sys_privtcl
(usingSYS_PRIV_ADD_MEM
) andvm_map_phys
are used for mapping. Returns virtual address (void *video_mem
). - After mapping VRAM, it is accessed using pointers. The pointer type dictates the number of bytes per pixel.
- 3 bytes per pixel: Use
memcpy
or astruct
. Pointer arithmetic automatically handles pixel traversal based on the pointer type.
- 3 bytes per pixel: Use
reg86_t
struct: is the union of anonymous structs that allow the access of IA32 registers:uint32_t *
,uint16_t *
,uint8_t *
Image Display (XPM)
- Images represented as a pixmap (array of pixel color values).
- X Pixmap (XPM): Format where pixel colors are represented by strings in a C file.
xpm_load()
: Converts XPM to raw pixmap, reads the XPM, then creates a pixel with the specified color. The image (img.bytes
) is then copied to VRAM.
Raster Graphics
- Image stored directly in a framebuffer
- Simple Hardware
- Constant time to redraw
- Images often have jagged edges
Vector Graphics
- Allow to draw smooth lines
- Complex Harware
- Update rate depends on number of paths in the image
- May flicker if image becomes to large
Sprites
- Sprites are separate overlay images that do not alter the background with position, dimensions, speed, and a pointer to its pixmap.
- The pixmap includes a transparent color which should not be copied to the VRAM, allowing background to be visible.
- A collision can be detected is a non-transparent pixel overlaps a non-background pixel.
create_sprite()
anddestroy_sprite()
manages allocated and the deallocation of the sprite.
Moving Sprites
- Sprite movement is obtained by changing a sprite in an order to make different pixmaps.
- Pixels have to be redefined to there original starting point so that the Sprite appears to move correctly.
Vertical Sync
- To solve screen tearing sync screen refreseh swaps during the interval vetween frames to ensure they do not tear.
Double Buffering
- Draw the back frame, write everything on the background from the back buffer and transfer write the result back to VRAM. This reduces time and is faster, but may cause tearing.
Page Flipping
- instant background swap to another one to save on performance issues.
Technique | Eliminates Tearing? | Reduces Trails? | Overhead | Complexity |
---|---|---|---|---|
Reset of Pixels | No | Yes | Low | Low |
Double Buffering | Partial | Yes | Moderate | Moderate |
Page Flipping | Partial | Yes | Low | High |
VSync + Double Buffer | Yes | Yes | Moderate | Moderate |
Triple Buffering | Yes | Yes | High | High |
Animating Sprites
- Involves changing the image of the sprite over time.
- Animation speed is measured by the number of frames each image is shown for before changing the next.
- An animated sprite can be created using
create_animSprite()
, which takes an array of XPMs as input.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.