• 沒有找到結果。

MS-DOS & BIOS-level Programming

N/A
N/A
Protected

Academic year: 2022

Share "MS-DOS & BIOS-level Programming"

Copied!
96
0
0

加載中.... (立即查看全文)

全文

(1)

Computer Organization &

Computer Organization &

Assembly Languages Assembly Languages

Pu-Jen Cheng

MS-DOS & BIOS-level Programming

Adapted from the slides prepared by Kip Irvine for the book, Assembly Language for Intel-Based Computers, 5th Ed

(2)

Chapter Overview

„ MS-DOS and the IBM-PC

„ MS-DOS Function Calls (INT 21h)

„ Standard MS-DOS File I/O Services

„ Standard MS DOS File I/O Services

(3)

MS-DOS and the IBM-PC

„ Real-Address Mode

„ MS-DOS Memory Organization

„ MS-DOS Memory Mapy p

„ Redirecting Input-Output

„ Software Interrupts

„ INT Instruction

„ Interrupt Vectoring Process

„ Common Interrupts

(4)

Real-Address Mode

„ Real-address mode (16-bit mode) programs have the following characteristics:

¾ Max 1 megabyte addressable RAM

¾ Single taskingg g

¾ No memory boundary protection

¾ Offsets are 16 bits

„ IBM PC-DOS: first Real-address OS for IBM-PC

¾ Has roots in Gary Kildall's highly successful Digital Research CP/M

¾ Later renamed to MS-DOS, owned by Microsoft

(5)

Memory Models

(6)

NEAR and FAR Segments

„ NEAR segment

¾ requires only a 16-bit offset

¾ faster execution than FAR

„ FAR segment

¾ 32-bit offset: requires setting both segment and offset values

¾ slower execution than NEAR

(7)

.MODEL Directive

„ The .MODEL directive determines the names and grouping of segments

„ .model tiny

¾ code and data belong to same segment (NEAR) fil t i

¾ .com file extension

„ .model small

¾ both code and data are NEAR

¾ data and stack grouped into DGROUP

„ .model medium

¾ code is FAR, data is NEAR

(8)

.MODEL Directive

„ .model compact

¾ code is NEAR, data is FAR

„ .model huge & .model large

¾ both code and data are FAR

„ .model flat

¾ both code and data are 32-bit NEAR

(9)

MS-DOS Memory Organization

„ Interrupt Vector Table

„ BIOS & DOS data

„ Software BIOS

„ MS-DOS kernel

„ MS DOS kernel

„ Resident command processor

„ Transient programs

„ Video graphics & text

„ Reserved (device controllers)

„ ROM BIOS

(10)

MS-DOS Memory Map

ROM BIOS Reserved

Video Text & Graphics

Video Graphics FFFFF

A0000 B8000 C0000 F0000 Address

VRAM

Resident Command Processor DOS Kernel, Device Drivers Software BIOS

BIOS & DOS Data Interrupt Vector Table 00400

00000

640K RAM Transient Program Area

(available for application programs) Transient Command Processor

(11)

Redirecting Input-Output

(1 of 2)

„ Input-output devices and files are interchangeable

„ Three primary types of I/O:

¾ Standard input (console, keyboard)

¾ Standard output (console, display)

¾ Standard error (console, display)

¾ Standard error (console, display)

„ Symbols borrowed from Unix:

¾ < symbol: get input from

¾ > symbol: send output to

¾ | symbol: pipe output from one process to another

„ Predefined device names:

¾ PRN, CON, LPT1, LPT2, NUL, COM1, COM2

(12)

Redirecting Input-Output

(2 of 2)

¾ Standard input, standard output can both be redirected

¾ Suppose we have created a program named

myprog.exe that reads from standard input and writes to standard output. Following are MS-DOS commands that demonstrate various types of redirection:yp

myprog < infile.txt myprog > outfile.txt

myprog < infile.txt > outfile.txt

(13)

Interrupt Vector Table

„ Each entry contains a 32-bit segment/offset address that points to an interrupt service routine

„ Offset =

interruptNumber

* 4

„ The following are only examples:g y p

(14)

Software Interrupts

„ The INT instruction executes a software interrupt.

„ The code that handles the interrupt is called an interrupt handler.

Syntax:

„ Syntax: INT number

(number = 0..FFh)

The Interrupt Vector Table (IVT) holds a 32-bit segment- offset address for each possible interrupt handler.

Interrupt Service Routine (ISR) is another name for interrupt handler.

(15)

Interrupt Vectoring Process

mov...

int 10h add...

F000:F065 F066 F067 F068

sti cld

push es

1 2 .

3

Calling program Interrupt Handler

F000:F065

3069 F000:AB62

. .

. IRET

(entry for INT 10)

Interrupt Vector Table

4

(16)

Common Interrupts

„ INT 10h Video Services

„ INT 16h Keyboard Services

„ INT 17h Printer Services

„ INT 17h Printer Services

„ INT 1Ah Time of Day

„ INT 1Ch User Timer Interrupt

„ INT 21h MS-DOS Services

(17)

Hardware Interrupts

„ Generated by the Intel 8259 Programmable Interrupt Contoller (PIC)

¾ in response to a hardware signal

„ Interrupt Request Levels (IRQ)

i it b d i t t h d l

¾ priority-based interrupt scheduler

¾ brokers simultaneous interrupt requests

¾ prevents low-priority interrupt from interrupting a high- priority interrupt

(18)

Common IRQ Assignments

„ 0 System timer

„ 1 Keyboard

„ 2 Programmable Interrupt Controller

„ 3 COM2 (serial)

„ 3 COM2 (serial)

„ 4 COM1 (serial)

„ 5 LPT2 (printer)

„ 6 Floppy disk controller

„ 7 LPT1 (printer)

(19)

Common IRQ Assignments

„ 8 CMOS real-time clock

„ 9 modem, video, network, sound, and USB controllers

„ 10 (available) 11 ( il bl )

„ 11 (available)

„ 12 mouse

„ 13 Math coprocessor

„ 14 Hard disk controller

„ 15 (available)

(20)

Interrupt Control Instructions

„ STI – set interrupt flag

¾ enables external interrupts

¾ always executed at beginning of an interrupt handler

„ CLI – clear interrupt flag

di bl l i

¾ disables external interrupts

¾ used before critical code sections that cannot be interrupted

¾ suspends the system timer

(21)

What's Next

„ MS-DOS and the IBM-PC

„ MS-DOS Function Calls (INT 21h)

„ Standard MS-DOS File I/O Services

„ Standard MS DOS File I/O Services

(22)

MS-DOS Function Calls (INT 21h)

„ ASCII Control Characters

„ Selected Output Functions

„ Selected Input Functionsp

„ Example: String Encryption

„ Date/Time Functions

(23)

AH=4Ch: Terminate Process

„ Ends the current process (program), returns an optional 8-bit return code to the calling process.

„ A return code of 0 usually indicates successful completion

completion.

mov ah,4Ch ; terminate process mov al,0 ; return code

int 21h

; Same as:

.EXIT 0

(24)

Selected Output Functions

„ ASCII control characters

„ 02h, 06h - Write character to standard output 05h Write character to default printer

„ 05h - Write character to default printer

„ 09h - Write string to standard output

„ 40h - Write string to file or device

(25)

ASCII Control Characters

¾ 08h - Backspace (moves one column to the left)

¾ 09h - Horizontal tab (skips forward n columns)

¾ 0Ah - Line feed (moves to next output line) Many INT 21h functions act upon the following control characters:

¾ 0Ah Line feed (moves to next output line)

¾ 0Ch - Form feed (moves to next printer page)

¾ 0Dh - Carriage return (moves to leftmost output column)

¾ 1Bh - Escape character

(26)

INT 21h Functions 02h and 06h:

Write Character to Standard Output

Write the letter 'A' to standard output:

mov ah,02h mov dl,’A’

int 21h

Write a backspace to standard output:

mov ah,06h mov dl,08h int 21h

(27)

INT 21h Function 05h:

Write Character to Default Printer

Write the letter 'A':

mov ah,05h mov dl,65 int 21h

Write a horizontal tab:

mov ah,05h mov dl,09h int 21h

(28)

INT 21h Function 09h:

Write String to Standard Output

.data

• The string must be terminated by a '$' character.

• DS must point to the string's segment, and DX must contain the string's offset:

string BYTE "This is a string$"

.code

mov ah,9

mov dx,OFFSET string int 21h

(29)

INT 21h Function 40h:

Write String to File or Device

.data

message "Writing a string to the console"

bytesWritten WORD ?

Input: BX = file or device handle (console = 1), CX = number of bytes to write, DS:DX = address of array

.code

mov ah,40h mov bx,1

mov cx,LENGTHOF message mov dx,OFFSET message int 21h

mov bytesWritten,ax

(30)

Selected Input Functions

„ 01h, 06h - Read character from standard input

„ 0Ah - Read array of buffered characters from standard inputp

„ 0Bh - Get status of the standard input buffer

„ 3Fh - Read from file or device

(31)

INT 21h Function 01h:

Read single character from standard input

• Echoes the input character

• Waits for input if the buffer is empty

• Checks for Ctrl-Break (^C)

• Acts on control codes such as horizontal Tab

.data

char BYTE ? .code

mov ah,01h int 21h

mov char,al

(32)

INT 21h Function 06h:

Read character from standard input without waiting

d t

• Does not echo the input character

• Does not wait for input (use the Zero flag to check for an input character)

• Example: repeats loop until a character is pressed.

.data

char BYTE ? .code

L1: mov ah,06h ; keyboard input

mov dl,0FFh ; don't wait for input int 21h

jz L1 ; no character? repeat loop mov char,al ; character pressed: save it call DumpRegs ; display registers

(33)

INT 21h Function 0Ah:

Read buffered array from standard input (1 of 2)

• Requires a predefined structure to be set up that describes the maximum input size and holds the input characters.

• Example:

count = 80

KEYBOARD STRUCT

maxInput BYTE count ; max chars to input inputCount BYTE ? ; actual input count buffer BYTE count DUP(?) ; holds input chars KEYBOARD ENDS

Directives: STRUCT, ENDS, ALIGN (Chap10)

(34)

INT 21h Function 0Ah

(2 of 2)

.data

kybdData KEYBOARD <>

code

Executing the interrupt:

.code

mov ah,0Ah

mov dx,OFFSET kybdData int 21h

(35)

INT 21h Function 0Bh:

Get status of standard input buffer

L1: mov ah,0Bh ; get buffer status int 21h

• Can be interrupted by Ctrl-Break (^C)

• Example: loop until a key is pressed. Save the key in a variable:

int 21h

cmp al,0 ; buffer empty?

je L1 ; yes: loop again mov ah,1 ; no: input the key int 21h

mov char,al ; and save it

(36)

Example: String Encryption

XORVAL = 239 ; any value between 0-255 .code

main PROC

mov ax,@data

Reads from standard input, encrypts each byte, writes to standard output.

mov ds,ax

L1: mov ah,6 ; direct console input

mov dl,0FFh ; don't wait for character int 21h ; AL = character

jz L2 ; quit if ZF = 1 (EOF) xor al,XORVAL

mov ah,6 ; write to output mov dl,al

int 21h

jmp L1 ; repeat the loop L2: exit

(37)

INT 21h Function 3Fh:

Read from file or device

.data

inputBuffer BYTE 127 dup(0)

• Reads a block of bytes.

• Can be interrupted by Ctrl-Break (^C)

• Example: Read string from keyboard:

bytesRead WORD ? .code

mov ah,3Fh

mov bx,0 ; keyboard handle

mov cx,127 ; max bytes to read

mov dx,OFFSET inputBuffer ; target location int 21h

mov bytesRead,ax ; save character count

(38)

Date/Time Functions

„ 2Ah - Get system date

„ 2Bh - Set system date *

„ 2Ch - Get system time

„ 2Ch Get system time

„ 2Dh - Set system time *

(39)

INT 21h Function 2Ah:

Get system date

mov ah,2Ah int 21h

mov year cx

• Returns year in CX, month in DH, day in DL, and day of week in AL

mov year,cx mov month,dh mov day,dl

mov dayOfWeek,al

(40)

INT 21h Function 2Bh:

Set system date

mov ah,2Bh mov cx,year mov dh month

• Sets the system date. AL = 0 if the function was not successful in modifying the date.

mov dh,month mov dl,day int 21h cmp al,0 jne failed

(41)

INT 21h Function 2Ch:

Get system time

mov ah,2Ch int 21h

• Returns hours (0-23) in CH, minutes (0-59) in CL, and seconds (0-59) in DH, and hundredths (0-99) in DL.

int 21h

mov hours,ch mov minutes,cl mov seconds,dh

(42)

INT 21h Function 2Dh:

Set system time

mov ah,2Dh mov ch,hours

• Sets the system date. AL = 0 if the function was not successful in modifying the time.

mov cl,minutes mov dh,seconds int 21h

cmp al,0 jne failed

(43)

Example: Displaying Date and Time

„ Displays the system date and time, using INT 21h Functions 2Ah, 2Ch, and 2h.

„ Demonstrates simple date formatting

„ Sample output:p p

Date: 12-8-2001, Time: 23:01:23

(44)

What's Next

„ MS-DOS and the IBM-PC

„ MS-DOS Function Calls (INT 21h)

„ Standard MS-DOS File I/O

„ Standard MS DOS File I/O Services

(45)

Standard MS-DOS File I/O Services

„ 716Ch - Create or open file

„ 3Eh - Close file handle

„ 42h - Move file pointer

„ 5706h - Get file creation date and time

„ Selected Irvine16 Library Procedures

„ Example: Read and Copy a Text File

„ Reading the MS-DOS Command Tail

„ Example: Creating a Binary File

(46)

INT 21h Function 716Ch:

Create or open file

• AX = 716Ch

• BX = access mode (0 = read, 1 = write, 2 = read/write)

• CX = attributes (0 = normal, 1 = read only, 2 = hidden, 3 = system, 8 = volume ID, 20h = archive)y , , )

• DX = action (1 = open, 2 = truncate, 10h = create)

• DS:SI = segment/offset of filename

• DI = alias hint (optional)

(47)

Example: Create a New File

mov ax,716Ch ; extended open/create

mov bx,2 ; read-write

mov cx,0 ; normal attribute

mov dx,10h + 02h ; action: create + truncate mov si,OFFSET Filename

mov si,OFFSET Filename int 21h

jc failed

mov handle,ax ; file handle

mov actionTaken,cx ; action taken to open file

(48)

Example: Open an Existing File

mov ax,716Ch ; extended open/create mov bx,0 ; read-only

mov cx,0 ; normal attribute mov dx,1 ; open existing file mov si,OFFSET Filename

mov si,OFFSET Filename int 21h

jc failed

mov handle,ax ; file handle

mov actionTaken,cx ; action taken to open file

(49)

INT 21h Function 3Eh:

Close file handle

.data

• Use the same file handle that was returned by INT 21h when the file was opened.

• Example:

filehandle WORD ? .code

mov ah,3Eh

mov bx,filehandle int 21h

jc failed

(50)

INT 21h Function 42h:

Move file pointer

mov ah,42h

mov al,0 ; offset from beginning mov bx,handle

mov cx offsetHi

Permits random access to a file (text or binary).

mov cx,offsetHi mov dx,offsetLo int 21h

AL indicates how the pointer's offset is calculated:

0: Offset from the beginning of the file

1: Offset from the current pointer location 2: Offset from the end of the file

(51)

INT 21h Function 5706h:

Get file creation date and time

mov ax,5706h

• Obtains the date and time when a file was created (not necessarily the same date and time when the file was last modified or accessed.)

mov bx,handle ; handle of open file int 21h

jc error mov date,dx mov time,cx

mov milliseconds,si

(52)

ReadString Procedure

The ReadString procedure from the Irvine16 library reads a string from standard input and returns a null-terminated string.

When calling it, pass a pointer to a buffer in DX. Pass a count of the maximum number of characters to input, plus 1, in CX.

Writestring inputs the string from the user, returning when either of the following events occurs:

.data

buffer BYTE 20 DUP(?) .code

mov dx,OFFSET buffer mov cx,LENGTHOF buffer call ReadString

1.CX –1 characters were entered.

2.The user pressed the Enter key.

(53)

ReadString Implementation

ReadString PROC

push cx ; save registers push si

push cx ; save character count mov si,dx ; point to input buffer dec cx ; save room for null byte L1: mov ah,1 ; function: keyboard input

int 21h ; returns character in AL cmp al,0Dh ; end of line?

je L2 ; yes: exit

mov [si],al ; no: store the character inc si ; increment buffer pointer loop L1 ; loop until CX=0

L2: mov BYTE PTR [si],0 ; insert null byte pop ax ; original digit count

sub ax,cx ; AX = size of input string pop si ; restore registers

pop cx ret

ReadString ENDP ; returns AX = size of string

(54)

PC-BIOS

„ The BIOS (Basic Input-Output System)

provides low-level hardware drivers for the operating system.

¾ accessible to 16-bit applications

¾ written in assembly language, of coursey g g ,

¾ source code published by IBM in early 1980's

„ Advantages over MS-DOS:

¾ permits graphics and color programming

¾ faster I/O speeds

¾ read mouse, serial port, parallel port

¾ low-level disk access

(55)

BIOS Data Area

„ Fixed-location data area at address 00400h

¾ this area is also used by MS-DOS

¾ this area is accessible under Windows 98 & Windows Me, but not under Windows NT, 2000, or XP.

„ Contents:

„ Contents:

¾ Serial and parallel port addresses

¾ Hardware list, memory size

¾ Keyboard status flags, keyboard buffer pointers, keyboard buffer data

¾ Video hardware configuration

¾ Timer data

(56)

What's Next

„ Introduction

„ Keyboard Input with INT 16h

„ VIDEO Programming with INT 10hg g

„ Drawing Graphics Using INT 10h

„ Memory-Mapped Graphics

„ Mouse Programming

(57)

Keyboard Input with INT 16h

„ How the Keyboard Works

„ INT 16h Functions

(58)

How the Keyboard Works

„ Keystroke sends a scan code to the keyboard serial input port

„ Interrupt triggered: INT 9h service routine executes

„ Scan code and ASCII code inserted into keyboard

„ Scan code and ASCII code inserted into keyboard typeahead buffer

Keyboard

INT 9h handler

INT 16h handler INT 21h handler

typeahead buffer

input port sc

sc sc, ac

sc, ac ac

sc = scan code ac = ASCII code

(59)

Keyboard Flags

16-bits, located at 0040:0017h – 0018h.

(60)

INT 16h Functions

„ Provide low-level access to the keyboard, more so than MS-DOS.

„ Input-output cannot be redirected at the command prompt.

„ Function number is always in the AH register

„ Function number is always in the AH register

„ Important functions:

¾ set typematic rate

¾ push key into buffer

¾ wait for key

¾ check keyboard buffer

¾ get keyboard flags

(61)

Function 10h: Wait for Key

.data

scanCode BYTE ? ASCIICode BYTE ?

If a key is waiting in the buffer, the function returns it immediately. If no key is waiting, the program pauses (blocks), waiting for user input.

ASCIICode BYTE ? .code

mov ah,10h int 16h

mov scanCode,ah mov ASCIICode,al

(62)

Function 12h: Get Keyboard Flags

.data

keyFlags WORD ?

Retrieves a copy of the keyboard status flags from the BIOS data area.

.code

mov ah,12h int 16h

mov keyFlags,ax

(63)

Clearing the Keyboard Buffer

L1: mov ah,11h ; check keyboard buffer int 16h ; any key pressed?

jz noKey ; no: exit now

mov ah 10h ; yes: remove from buffer

Function 11h clears the Zero flag if a key is waiting in the keyboard typeahead buffer.

mov ah,10h ; yes: remove from buffer int 16h

cmp ah,scanCode ; was it the exit key?

je quit ; yes: exit now (ZF=1) jmp L1 ; no: check buffer again

noKey: ; no key pressed

or al,1 ; clear zero flag quit:

(64)

What's Next

„ Introduction

„ Keyboard Input with INT 16h

„ VIDEO Programming with INT 10h

„ Drawing Graphics Using INT 10h

„ Memory-Mapped Graphics

„ Mouse Programming

(65)

VIDEO Programming with INT 10h

„ Basic Background

„ Controlling the Color

„ INT 10h Video Functions

„ Library Procedure Examples

(66)

Video Modes

„ Graphics video modes

¾ draw pixel by pixel

¾ multiple colors

„ Text video modes

h i h d f b d

¾ character output, using hardware or software-based font table

¾ mode 3 (color text) is the default

¾ default range of 80 columns by 25 rows.

¾ color attribute byte contains foreground and background colors

(67)

Three Levels of Video Access

„ MS-DOS function calls

¾ slow, but they work on any MS-DOS machine

¾ I/O can be redirected

„ BIOS function calls

di f k l ll S OS b d

¾ medium-fast, work on nearly all MS-DOS-based machines

¾ I/O cannot be redirected

„ Direct memory-mapped video

¾ fast – works only on 100% IBM-compatible computers

¾ cannot be redirected

¾ does not work under Windows NT, 2000, or XP

(68)

Controlling the Color

„ Mix primary colors: red, yellow, blue

¾ called subtractive mixing

¾ add the intensity bit for 4th channel

„ Examples:

¾ red + green + blue = light gray (0111)g g g y ( )

¾ intensity + green + blue = white (1111)

¾ green + blue = cyan (0011)

¾ red + blue = magenta (0101)

„ Attribute byte:

¾ 4 MSB bits = background

¾ 4 LSB bits = foreground

(69)

Constructing Attribute Bytes

„ Color constants defined in Irvine32.inc and Irvine16.inc:

„ Examples:

Li ht t t bl b k d

¾ Light gray text on a blue background:

„ (blue SHL 4) OR lightGray

¾ White text on a red background:

„ (red SHL 4) OR white

(70)

INT 10h Video Functions

„ AH register contains the function number

„ 00h: Set video mode

¾ text modes listed in Table 15-6

¾ graphics modes listed in Table 15-6

„ 01h: Set cursor lines01h: Set cursor lines

„ 02h: Set cursor position

„ 03h: Get cursor position and size

„ 06h: Scroll window up

„ 07h: Scroll window down

„ 08h: Read character and attribute

(71)

INT 10h Video Functions (cont)

„ 09h: Write character and attribute

„ 0Ah: Write character

„ 10h (AL = 03h): Toggle blinking/intensity bit

„ 0Fh: Get video mode

„ 13h: Write string in teletype mode

(72)

Displaying a Color String

Write one character and attribute:

mov si,OFFSET string . . .

mov ah,9 ; write character/attribute mov al,[si] ; character to display

mov bh 0 ; video page 0

mov bh,0 ; video page 0 mov bl,color ; attribute

or bl,10000000b ; set blink/intensity bit mov cx,1 ; display it one time

int 10h

(73)

Gotoxy Procedure

;--- --

Gotoxy PROC

;

; Sets the cursor position on video page 0.

; Receives: DH,DL = row, column

R t thi

; Returns: nothing

;--- ---

pusha

mov ah,2 mov bh,0 int 10h popa

ret

Gotoxy ENDP

(74)

Clrscr Procedure

Clrscr PROC pusha

mov ax,0600h ; scroll window up

mov cx,0 ; upper left corner (0,0) mov dx,184Fh ; lower right corner

(24,79)

bh 7 l tt ib t

mov bh,7 ; normal attribute int 10h ; call BIOS

mov ah,2 ; locate cursor at 0,0 mov bh,0 ; video page 0

mov dx,0 ; row 0, column 0 int 10h

popa ret

Clrscr ENDP

(75)

What's Next

„ Introduction

„ Keyboard Input with INT 16h

„ VIDEO Programming with INT 10hg g

„ Drawing Graphics Using INT 10h

„ Memory-Mapped Graphics

„ Mouse Programming

(76)

Drawing Graphics Using INT 10h

„ INT 10h Pixel-Related Functions

„ DrawLine Program

„ Cartesian Coordinates Program

„ Converting Cartesian Coordinates to

„ Converting Cartesian Coordinates to Screen Coordinates

(77)

INT 10h Pixel-Related Functions

„ Slow performance

„ Easy to program

„ 0Ch: Write graphics pixel

„ 0Dh: Read graphics pixel

(78)

DrawLine Program

„ Draws a straight line, using INT 10h function calls

„ Saves and restores current video mode

„ Excerpt from the

DrawLine

program (DrawLine.asm):

mov ah,0Ch ; write pixel

mov al,color ; pixel color mov bh,0 ; video page 0

mov cx,currentX int 10h

(79)

Cartesian Coordinates Program

„ Draws the X and Y axes of a Cartesian coordinate system

„ Uses video mode 6A (800 x 600, 16 colors)

„ Name: Pixel2.asm

„ Important procedures:

¾ DrawHorizLine

¾ DrawVerticalLine

(80)

Converting Cartesian Coordinates to Screen Coordinates

„ Screen coordinates place the origin (0,0) at the upper-left corner of the screen

„ Graphing functions often need to display negative values

¾ move origin point to the middle of the screen

„ For Cartesian coordinates X, Y and origin points

sOrigX

and

sOrigY

, screen X and screen Y are calculated as:

¾ sx = (sOrigX + X)

¾ sy = (sOrigY – Y)

(81)

What's Next

„ Introduction

„ Keyboard Input with INT 16h

„ VIDEO Programming with INT 10hg g

„ Drawing Graphics Using INT 10h

„ Memory-Mapped Graphics

„ Mouse Programming

(82)

Memory-Mapped Graphics

„ Binary values are written to video RAM

¾ video adapter must use standard address

„ Very fast performance

¾ no BIOS or DOS routines to get in the way

(83)

Mode 13h: 320 X 200, 256 Colors

„ Mode 13h graphics (320 X 200, 256 colors)

¾ Fairly easy to program

¾ read and write video adapter via IN and OUT instructions

¾ pixel mapping scheme (1 byte per pixel)

¾ pixel-mapping scheme (1 byte per pixel)

(84)

Mode 13h Details

„ OUT Instruction

¾ 16-bit port address assigned to DX register

¾ output value in AL, AX, or EAX

¾ Example:

mov dx,3c8h ; port address mov dx,3c8h ; port address

mov al,20h ; value to be sent out dx,al ; send to the port

„ Color Indexes

¾ color integer value is an index into a table of colors called a palette

(85)

Color Indexes in Mode 13h

(86)

RGB Colors

Additive mixing of light (red, green, blue). Intensities vary from 0 to 255.

Examples:

(87)

What's Next

„ Introduction

„ Keyboard Input with INT 16h

„ VIDEO Programming with INT 10hg g

„ Drawing Graphics Using INT 10h

„ Memory-Mapped Graphics

„ Mouse Programming

(88)

Mouse Programming

„ MS-DOS functions for reading the mouse

„ Mickey – unit of measurement (200th of an inch)

¾ mickeys-to-pixels ratio (8 x 16) is variable

„ INT 33h functions

„ Mouse Tracking Program Example

(89)

Reset Mouse and Get Status

„ INT 33h, AX = 0

„ Example:

mov ax,0 int 33h cmp ax,0

je MouseNotAvailable mov numberOfButtons,bx

(90)

Show/Hide Mouse

„ INT 33h, AX = 1 (show), AX = 2 (hide)

„ Example:

mov ax,1 ; show int 33h

mov ax,2 ; hide int 33h

(91)

Get Mouse Position & Status

„ INT 33h, AX = 4

„ Example:

mov ax,4

mov cx,200 ; X-position mov dx,100 ; Y-position int 33h

(92)

Get Button Press Information

„ INT 33h, AX = 5

„ Example:

mov ax,5

mov bx,0 ; button ID

int 33h

test ax,1 ; left button down?

jz skip ; no - skip

mov X_coord,cx ; yes: save coordinates mov Y_coord,dx

(93)

Other Mouse Functions

„ AX = 6: Get Button Release Information

„ AX = 7: Set Horizontal Limits

„ AX = 8: Set Vertical Limits

(94)

Mouse Tracking Program

„ Tracks the movement of the text mouse cursor

„ X and Y coordinates are continually updated in the lower-right corner of the screen

„ When the user presses the left button, the

’ i i i di l d i h l l f mouse’s position is displayed in the lower left corner of the screen

„ Source code (c:\Irvine\Examples\ch15\mouse.asm)

(95)

Set Mouse Position

„ INT 33h, AX = 3

„ Example:

mov ax,3 int 33h test bx 1 test bx,1

jne Left_Button_Down test bx,2

jne Right_Button_Down test bx,4

jne Center_Button_Down mov Xcoord,cx

mov yCoord,dx

(96)

Summary

„ Working at the BIOS level gives you a high level of control over hardware

„ Use INT 16h for keyboard control

„ Use INT 10h for video text

„ Use memory-mapped I/O for graphics

„ Use INT 33h for the mouse

參考文獻

Outline

相關文件

MOV reg,data reg ← data 轉移立即資料(data)到暫存器 reg 內 MOV dreg,sreg dreg ← sreg 轉移暫存器 sreg 的內容到暫存器 dreg MOV segreg,reg segreg ← reg

•  Please select Multiline Text and insert it into the survey. •  Optional item: you can set the minimum and maximum characters count in the edit panel on the right.. Save

• A function is a piece of program code that accepts input arguments from the caller, and then returns output arguments to the caller.. • In MATLAB, the syntax of functions is

It costs &gt;1TB memory to simply save the raw  graph data (without attributes, labels nor content).. This can cause problems for

• BP can not correct the latent error neurons by adjusting their succeeding layers.. • AIR tree can trace the errors in a latent layer that near the front

For a deep NNet for written character recognition from raw pixels, which type of features are more likely extracted after the first hidden layer.

L1: add eax,myArray[esi] ; add each integer to sum add esi,4 ; point to next integer loop L1 ; repeat for array size mov theSum,eax ; store the

Keyboard, mouse, and other pointing devices; touch screens, pen input, other input for smart phones, game controllers, digital cameras, voice input, video input,. scanners