Presentation is loading. Please wait.

Presentation is loading. Please wait.

The CRTC Interface Essential aspects of display page and cursor control for standard 80-column by 25-row text.

Similar presentations


Presentation on theme: "The CRTC Interface Essential aspects of display page and cursor control for standard 80-column by 25-row text."— Presentation transcript:

1 The CRTC Interface Essential aspects of display page and cursor control for standard 80-column by 25-row text

2 Problem background For proper display of text that applications wish to write to the STDOUT device-file, our ‘os630’ program will need to reposition the CRT cursor This will involve directly programming certain registers in the CRT Controller (i.e., hardware) For cooperation with messages that our ‘trackldr’ boot-loader displays (it uses int-0x10), we also need to set some variable-values located in the ROM-BIOS DATA AREA (i.e., software) This lesson will explore these two issues

3 Hardware registers The CRT Controller is a peripheral chip It implements 25 standard CRTC registers Access to these registers is accomplished via a multiplexing scheme that uses just two I/O port-addresses: address-port:0x03D4 data-port:0x03D5

4 The relevant CRTC registers We are only concerned with 6 (of the 25) standard CRTC registers: 0x0A:CURSOR_START 0x0B:CURSOR_END 0x0C:START_ADDRESS_HI 0x0D:START_ADDRESS_LO 0x0E:CURSOR_LOCATION_HI 0x0F:CURSOR_LOCATION_LO

5 8x16 character box scanline 0 scanline 1 scanline 2 scanline 3 scanline 4 scanline 5 scanline 6 scanline 7 scanline 8 scanline 9 scanline 10 scanline 11 scanline 12 scanline 13 scanline 14 scanline 15 Cursor_start = 12 Cursor_end = 13

6 CURSOR START/END dis- able starting_scanline skewending_scanline 76543210 76543210 Index 0x0A: Index 0x0B: CURSOR_START REGISTER CURSOR_END REGISTER

7 Organization of VRAM Page 0 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Base_Address = 0xB8000 4KB

8 Changing the visual page 7654321076543210 START_ADDRESS_HISTART_ADDRESS_LO register-index 0x0C register-index 0x0D Programming example: // switches display to vram page 5 // the offset to visual page 5 (in words) is 0x2800 (= 5 * 2048) movdx, #0x03D4// port-address in register DX movax, #0x280C// value=0x28, register=0x0C outdx, ax// write value to CRTC register movax, #0x000D// value=0x00, register=0x0D outdx, ax// write value to CRTC register

9 Moving the CRT’s cursor 7654321076543210 CURSOR_LOCATION_HICURSOR_LOCATION_LO register-index 0x0Eregister-index 0x0F Programming example: // moves cursor to row 4, column 9, on page 0 movdx, #0x03D4// port-address in register DX movbx, #4// row-number imulbx, #80// times cells-per-row addbx, #9// plus column-number movah, bh// offset’s MSB moval, #0x0E// CURSOR_HI index outdx, ax// write value to CRTC register movah, bl// offset’s LSB moval, #0x0F// CURSOR_LO index outdx, ax// write value to CRTC register

10 Scrolling the screen Here’s a code-fragment that will scroll the contents of vram page 0 up by one line: movax, 0xB800// address vram page 0 movds, ax// with DS register moves, ax// also ES register movdi, #0// destination is top line movsi, #160// source is one line lower cld// do forward copying movcx, #1920// 24 times 80 rep movsw movax, #0x0720// blank character/color mov cx, #80// characters on bottom line rep stosw

11 Linux uses hardware scrolling The value of the CRT START_ADDRESS is reprogrammed, to change the region of visible vram by one line (i.e., add #80) So instead of subdividing vram into eight 4KB pages, the entire 32KB vram is one continuous page, but only partially visible To scroll up by one line, Linux adds #80 to the value of the CRT_START_ADDRESS

12 The ROM-BIOS variables Several variables in the ROM-BIOS DATA AREA are used by the VIDEO ROM-BIOS routins (i.e., int-0x10) to keep track of the current visisible page and of the positions of the cursors on each of the eight pages The locations of these variables are part of the IBM-PC BIOS standard, and as such are widely documented

13 Standard addresses 0x449 (byte) video mode-number 0x44A (word) number of columns on screen 0x44C (word) current page-size (in bytes) 0x44E (word) current page-address 0x450 (byte array) cursor-positions (col,row) 0x460 (cursor type) (END, START) 0x462 (byte) current page-number 0x463 (word) CRTC i/o port-address

14 Real-mode INT-0x10 services 0x00: set_display_mode 0x01: set_cursor_type 0x02: set_cursor_position 0x03: get_cursor_position_and_type 0x05: select_new_video_page 0x06: scroll_current_page_up 0x07: scroll_current_page_down 0x08: read_char_and_attrib_from_screen 0x09: write_char_and_attrib_to_screen 0x0A: write char_only_to_screen 0x0E: write_teletype_to_active_page 0x0F: return_video_status 0x13: write_string NOTE: These ROM-BIOS services are not available in protected-mode

15 Cursor-movement demo To illustrate reprogramming of the six CRT controller registers, we wrote ‘arrows.s’ It lets the user control the cursor position and visible page by using arrow-keys It also changes the height of the cursor An unusual feature (not recommended) is its use of “polled mode” keyboard device- programming (instead of “interrupt-driven”)

16 Polling the status-register The keyboard interrupts are masked The keyboard controller’s status-register is read and reread in a tight loop until bit #0 is set, indicating that a key was pressed and thus the output-buffer is now “full” Then the output-buffer register is read by the CPU to get the key’s “scancode” For arrow-keys, the cursor is moved Other keys are ignored (except ESCAPE)

17 Disadvantage of polling Almost all of the CPU’s time is consumed by continually reading the status-register So this would not be a good design to use in writing a multitasking operating system On the other hand, for single-tasking it has the advantage of not requiring a interrupt service routine to be written, so the demo code can be shorter and simpler

18 Another noteworthy feature The ‘arrows.s’ demo uses a ‘jump-table’ to efficiently dispatch control to appropriate subroutines, based on a variable’s value This is a similar programming situation to using a ‘switch’ statement in C/C++ The jump-table avoids the long chain of ‘compare-and-branch’ statements for all the various possible cases that can occur

19 In-Class exercise To insure your mastery of the jump-table concept, and cement your grasp of how the CRTC START_ADDRESS registers are programmed, try modifying the demo to incorporate these additional actions: when one of the function-keys F1-F7 is pressed, the display is switched to the correspondingly numbered display-page


Download ppt "The CRTC Interface Essential aspects of display page and cursor control for standard 80-column by 25-row text."

Similar presentations


Ads by Google