1 / 58

Chapter 15 BIOS-Level Programming

Chapter 15 BIOS-Level Programming. Assembly Language for Intel-Based Computers , 4th edition Kip R. Irvine. Chapter Overview. Review Chapter 13 Keyboard Input with INT 16h VIDEO Programming with INT 10h Drawing Graphics Using INT 10h Memory-Mapped Graphics Mouse Programming.

theo
Download Presentation

Chapter 15 BIOS-Level Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 15BIOS-Level Programming Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine

  2. Chapter Overview • Review Chapter 13 • Keyboard Input with INT 16h • VIDEO Programming with INT 10h • Drawing Graphics Using INT 10h • Memory-Mapped Graphics • Mouse Programming

  3. Interrupts: • Hardware interrupt: in response to a request by a hardware device that needs attention. Hardware interrupts occur at "unexpected" times. • Software interrupt: A call to DOS or BIOS in response to a interrupt instruction (INT) in the program being processed. • Exception: An automatically generated trap in response to an exceptional condition such as division by zero.

  4. Hardware Interrupt Steps • 0. The program is executing in the CPU • 1. The hardware device needs attention and requests an interrupt. • 2. The CPU finishes processing the current instruction. It the saves its "state" (flags and CS:IP) on the stack. • 3. The address of the interrupt handler is obtained from the Interrupt Vector Table.

  5. Hardware Interrupt Steps • 4. The CPU loads the address of the interrupt handler into the IP. • 5. The interrupt handler code is processed. • 6. When the interrupt handler is finished, the CPU pops the "state" (CS:IP and Flags) back from the stack. • 7. Execution of original program continues beginning at the next instruction.

  6. Hardware Interrupts Device Program Interrupt table Interrupt Code Stack 0 4 3 1 1 2 5 7 6

  7. Hardware Interrupt Comments • Some interrupt operations are so critical that the interrupt driver may disable other interrupts until the critical operation is completed. • In IBM terminology, hardware interrupts are known as an IRQ. Each device is assigned a number which determines the Interrupt Vector entry of the appropriate interrupt handler.

  8. Software Interrupt • Software interrupt. Works much the same way but steps 1 and 2 are replaced by an INT ninstruction in the code. The number n determines the table entry specifying location of the interrupt handler desired.

  9. Common Software Interrupts • INT 10h Video services • INT 16h Keyboard services • INT 21h DOS services - "DOS function calls" Most interrupts use AH to specify the desired operation (function)

  10. INT 21h functions

  11. 0 1 2 … characters input number of characters input (excluding <CR>) max characters allowed (including <CR>) INT 21h functions (continues)

  12. Keyboard Input functions Summary

  13. INT 21h functions (continues)

  14. INT 21h functions (continues)

  15. INT 21h functions (continues)

  16. INT 21h functions (continues)

  17. BIOS I/O functions • Advantages: • Faster • More control • "Understands" video monitors • Disadvantages • Cannot be redirected • Somewhat harder to use

  18. Keyboard Input with INT 16h • How the Keyboard Works • INT 16h Functions • Set Typematic Rate (03h) • Push Key into Keyboard Buffer (05h) • Wait for Key (10h) • Check Keyboard Buffer (11h) • Get Keyboard Flags • Clearing the Keyboard Buffer

  19. Keyboard input: ASCII and Scan Codes • ASCII code: one of the 127 characters in ASCII alphabet. Values from 1 to 127. • Many keys do not have an ASCII code. Examples: All Alt keys like Alt A, F1, Shift F2, Control F3, right arrow, Home, Insert, ... • Non-ASCII keys have an ASCII code of 00 or E0h. • BIOS functions provide both ASCII code and Scan code

  20. Scan Codes: Examples • CharacterScanASCII A 1E 41 a 1E 61 ^A 1E 01 Alt A 1E 00 • F1 3B 00 Shift F1 54 00 ^ F1 5E 00 Alt F1 68 00 • Home 47 E0 4D E0

  21. How the Keyboard Works Input Port sc Keyboard sc sc, ac Typeahead Buffer INT 9h handler sc, ac ac INT 16h handler INT 21h handler

  22. INT 16h Functions • Set Typematic Rate (03h) • Push Key into Keyboard Buffer (05h) • Wait for Key (10h) • Check Keyboard Buffer (11h) • Get Keyboard Flags • Clearing the Keyboard Buffer

  23. Set Typematic Rate (03h) • Set Typematic repeat rate • AH = 3 AL = 5 • BH = repeat delay • 0 = 250ms • 1 = 500ms • 2 = 750ms • 3 = 1000ms • BL = repeat rate • 0 = fastest • 1Fh = slowest Mov AX, 0305h Mov BH, 1 Mov BL, 0Fh INT 16h

  24. Push Key into Keyboard Buffer (05h) • Push key into typeahead buffer* • A key consists of ac and sc • AH = 5, CH = scan code, CL = ASCII code mov AH, 5 mov CH, 3Bh ; scan code for F1 key mov CL, 0 ; ASCII code INT 16h * If buffer is full, CF=1 and AL =1; otherwise CF = 0, AL = 0

  25. Wait for Key 10h • Remove a key from the buffer • If no key is in the buffer, wait for a key • AH = 10h • Return sc in AH, ac in AL • Every key has a scan code • Keys for non-ASCII characters have 00h or E0h as the ASCII code • Does not echo, can't be redirected. mov AH, 10h INT 16h mov scanCode, AH mov ASCIICode, AL

  26. Sample Program • Get input keystrokes and display both the ASCII code and the scan code of each key. Terminates as Esc is pressed TITLE Keyboard Display (keybd.asm) Include Irvine16.inc .code main PROC mov ax,@data mov ds,ax call ClrScr ; clear screen L1: mov ah,10h ; keyboard input int 16h ; using BIOS call DumpRegs ; look at AH, AL cmp al,1Bh ; ESC key pressed? jne L1 ; no: repeat the loop call ClrScr ; clear screen exit main ENDP END main

  27. Scan Codes: BIOS vs. DOS • BIOS: You get scan code and ASCII value every time! Special keys have a ASCII code of either 00h or E0h • DOS: You only get the scan code if the ASCII code is 00h. Codes come one at a time with the ASCII code first.

  28. Processing scan codes in DOS 28 mov ah, 01h ; Input char - DOSint 21h ; Input the ASCII codecmp al, 00h ; is it ASCII 0?jne processASCIIcharint 21h ; read scancodemov aScanCode, al

  29. Processing scan codes in BIOS mov ah, 10h ; Input char – BIOS int 16h ; get scan and ASCII cmp al, 0E0h ; is it an extended key? je scankey cmp al, 00h ; is it an ASCII key? jne ASCIIKey scankey: ; process scancode in ah

  30. Check Keyboard Buffer 11h • Check if any keys are waiting • Returns the ac and sc of the next available key • Not remove the key from the buffer mov ah, 11h int 16h jz NoKeyWaiting ;no key in buffer mov scanCode, ah mov ASCIICode, al

  31. Get Keyboard Flags 12h • Returns current state of the keyboard flags • Returns copy of the keyboard flags in AX • Keyboard flags are in the BIOS data area mov ah, 12h int 16h mov keyFlags, ax

  32. Get Keyboard Flags 12h

  33. Three Levels of Video LevelCompatibilitySpeedRedirection DOS high slow yes BIOS high medium no Direct medium high no • DOS output is generic. There are "no" special video effects • BIOS video "understands" video and allows special effects • Direct video allows everything but do it yourself

  34. A 0 Do not blink Text Attributes • Color text Background Foreground0 0 0 0 0 1 1 1 0111 White character 0000 Black background

  35. Pages • Most adapters and most modes allow multiple pages • BIOS allows writing to any of the pages even if it is not currently displayed • Example uses: • Write to hidden page and then display that page to create an "instantaneous" switch in the display • Save old screen data while doing a special page

  36. Text Mode Colors CodeColorCodeColor0000 black 1000 gray0001 blue 1001 light blue0010 green 1010 light green0011 cyan 1011 light cyan0100 red 1100 light red0101 magenta 1101 light magenta0110 brown 1110 yellow0111 light gray 1111 bright white

  37. Function 0Fh: Get Video ModeFunction 00h: Set Video Mode mov ah, 0Fh ; Get video modeint 10hmov vmodeOld, almov columnOld, ah mov pageOld, bhmov ah, 00h ; Set video modemov al, vmodeNewint 10h

  38. Function 03h: Get Cursor LocationFunction 02h: Set Cursor Location mov ah, 3 ; get cursor location mov bh, vpage int 10h mov cursor, CX ; CH = starting scan line, CL = ending mov position, DX ; DH = row, DL = col mov ah, 2 ; set cursor location mov dh, row mov dl, col mov bh, vpage int 10h

  39. Function 08h: Read character and attribute Function 09h: Write character and attribute mov ah, 08h ; Read char. and attrmov bh, videoPageint 10h mov aChar, almov theAttribute, ah mov ah, 09h ; Write char. and attrmov al, aCharmov bh, videoPagemov bl, theAttribute mov cx, repeatCountint 10h

  40. Function 0Ah: Write character • Just like 09h except that the attribute is unchanged mov ah, 0Ah ; Write charmov al, aCharmov bh, videoPagemov cx, repeatCountint 10h

  41. Functions 06h (07h): Scroll up (down) • Specify a window by its corners • Specify the number of lines to scroll in window • Number lines = 0 means all lines • Row and columns numbering starts with 0 mov ah, 06h ; scroll window upmov al, numLinesmov ch, topRowmov cl, leftColumnmov dh, bottomRowmov dl, rightColumnmov bh, theAttributeint 10h AB Scrool up one line AB AB

  42. Restore the screen • Recall that after changing the video mode, pages, or attributes we should restore the screen before terminating the program mov ah, 0h ; Set video modemov al, vmodeOldint 10h mov ah, 05h ; Set video pagemov al, pageOldint 10h

  43. Toggle Blinking and Intensity Modes • Set the highest bit of a color attribute to either control the color intensity or blink the character • AL = 3; BL: 0 = intesity, 1 = blinking mov ah, 10h ; blinking/intensitymov al, 3 mov bl, 1 ; enable blinkingint 10h * Video display must run in a full screen mode

  44. Function 0Eh: Teletype output • Print the character, move cursor to right, go to beginning of next line if needed mov ah, 0Eh ; Write char and advance cursormov al, aCharmov bh, videoPageint 10h

  45. Function 13h: String Teletype output • Print the string at a given row and column • String may contain both characters and attribute values .data colorStr byte ‘A’, 1Fh, ‘B’, 1Ch, ‘C’, 1Bh row byte 10 col byte 20 .code mov ax, SEG colorStr mov es, ax mov ah, 13h ; Write stringmov al, 2 ; write modemov bh, videoPagemov CX, (SIZEOF colorStr)/2 mov dh, row mov dl, col mov bp, OFFSET colorStr int 10h

  46. Function 0Ch: Write Graphics Pixel • Draw a pixel on the screen in graphics mode • Slow, most write directly into video memory mov ah, 0Ch mov al, pixelValue mov bh, videoPage mov CX, x_coord mov DX, y_coord int 10h

  47. Function 0Dh: Read Graphics Pixel • Read a pixel from the screen at a given row and column mov ah, 0Dh mov bh, videoPage mov CX, x_coord mov DX, y_coord int 10h mov pixelValue, al

  48. Mouse ProgrammingINT 33h • Requires device driver program to be installed • Mouse movement are tracked in mickeys • 1 mickey = 1/200 of an inch of mouse travel • 8 mickeys = 1 horizontal pixel 16 mikeys = 1 vertical pixel

  49. Reset Mouse and Get Status • AX = 0FFFFh; BX = number of mouse buttons if mouse support is available • AX = 0 if no mouse found • Centered on the screen, video page 0 • Mouse pointer hidden • Internal counter is set to -1 mov ax, 0 int 33h cmp ax, 0 je MouseNotAvailable

  50. Showing/Hiding the Mouse Pointer mov ax, 1 ;show mouse pointer int 33h ;internal counter is incremented mov ax, 2 ;hide mouse pointer int 33h ;internal counter is decremented

More Related