The New Peter Norton Programmer's Guide to The IBM PC & PS/2

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Peter Norton; Richard Wilton
Edition: 2
Publisher: Microsoft Press
Year: 1988

Language: English
Tags: IBM PC; IBM PS/2; Programming; ROM BIOS; BIOS; BIOS Interrupts; DOS; DOS Interrupts; DOS Functions; ROM BIOS Video Services; ROM BIOS Disk Services; ROM BIOS Keyboard Services

Cover
Contents
Introduction
Some Comments on Philosophy
How to Use This Book
What's New in This Edition
Other Resources
1 Anatomy of the PCs and PS/2s
The Microprocessor
The 8088 Microprocessor
The 8086 Microprocessor
The 80286 Microprocessor
The 80386 Microprocessor
The Math Coprocessor
The Support Chips
The Programmable Interrupt Controller
The DMA Controller
The Clock Generator
The Programmable Interval Timer
Video Controllers
Input/Output Controllers
Linking the Parts: The Bus
The Address Bus
The Data Bus
Micro Channel Architecture
Memory
CPU Address Space
The System Memory Map
Design Philosophy
2 The Ins and Outs
How the 8086 Communicates
The 8086 Data Formats
How the 8086 Addresses Memory
Segmented Addresses
80286 and 80386 Protected-Mode Addresses
Address Compatibility
The 8086 Registers
The Scratch-Pad Registers
The Segment Registers
The Offset Registers
The Flags Register
Addressing Memory Through Registers
Rules for Using Registers
How the 8086 Uses I/O Ports
How the 8086 Uses Interrupts
Software Interrupts
Hardware Interrupts
3 The ROM Software
The Start-Up ROM
The ROM BIOS
Interrupt Vectors
Key Low-Memory Addresses
The ROM Version and Machine-ID Markers
The ROM BASIC
The ROM Extensions
Comments
4 Video Basics
The Video Subsystems
Memory and the Video Subsystems
Creating the Screen Image
The Video Display Modes
Video Mode Control
Display Resolution
The Use of Color
Color-Suppressed Modes
Color in Text and Graphics Modes
Inside the Display Memory
Display Pages in Text Modes
Display Pages in Graphics Modes
Displaying Characters in Text and Graphics Modes
Controlling the Video Display
Direct Hardware Control
Compatibility Considerations
5 Disk Basics
Disk Data Mapping
Data Storage
Bootable Disks
DOS Disk Formats
Diskette Formats
Fixed-Disk Formats
The Disk’s Logical Structure
How DOS Organizes the Disk
The Logical Structure in Detail
The Boot Sector
The Root Directory
The Files Area
The File Allocation Table
Comments
Copy Protection
6 Keyboard Basics
Keyboard Operation
Keystrokes and Scan Codes
Communicating with the ROM BIOS
Translating the Scan Codes
Entering ASCII Codes Directly
Keyboard Data Format
The ASCII Keys
The Special Keys
ROM BIOS Keyboard Control
The Insert State
The Caps Lock State
The Num Lock State
The Keyboard-Hold State
The Toggle-Key States
Comments
7 Clocks, Timers, and Sound Generation
Clocks and Timers
The CPU Clock
System Timers
Using the System Timer Tick
The Physics of Sound
How the Computer Produces Sound
Timer-Chip Sound Control
Direct Speaker Control
Speaker Volume and Sound Quality
The Real-Time Clock
Using the Date and Time
Setting the Alarm
8 ROM BIOS Basics
The ROM BIOS Philosophy
The ROM BIOS Service Interrupts
ROM BIOS Service Operating Characteristics
Creating an Assembly-Language Interface
The Basic Form of an Interface Routine
Advanced BIOS Interface
9 ROM BIOS Video Services
Accessing the ROM BIOS Video Services
Service OOH (decimal 0): Set Video Mode
Service 01H (decimal 1): Set Cursor Size
Service 02H (decimal 2): Set Cursor Position
Service 03H (decimal 3): Read Cursor Position
Service 04H (decimal 4): Read Light-Pen Position
Service 05H (decimal 5): Set Active Display Page
Service 06H (decimal 6): Scroll Window Up
Service 07H (decimal 7): Scroll Window Down
Service 08H (decimal 8): Read Character and Attribute
Service 09H (decimal 9): Write Character and Attribute
Service OAH (decimal 10): Write Character
Service OBH (decimal 11): Set 4-Color Palette
Service OCH (decimal 12): Write Pixel
Service ODH (decimal 13): Read Pixel
Service OEH (decimal 14): Write Character in Teletype Mode
Service OFH (decimal 15): Get Current Video Mode
Service 10H (decimal 16): Color Palette Interface
10 ROM BIOS Disk Services
The ROM BIOS Disk Services
Service OOH (decimal 0): Reset Disk System
Service 01H (decimal 1): Get Disk Status
Service 02H (decimal 2): Read Disk Sectors
Service 03H (decimal 3): Write Disk Sectors
Service 04H (decimal 4): Verify Disk Sectors
Service 05H (decimal 5): Format Disk Track
Service 06H (decimal 6): Format PC/XT Fixed-Disk Track
Service 07H (decimal 7): Format PC/XT Fixed Disk
Service 08H (decimal 8): Get Disk-Drive Parameters
Service 09H (decimal 9): Initialize Fixed-Disk Parameter Tables
Service 0AH and 0BH (decimal 10 and 11): Read and Write Long
Service 0CH (decimal 12): Seek to Cylinder
Service 0DH (decimal 13): Alternate Fixed-Disk Reset
Service 10H (decimal 16): Test for Drive Ready
Service 11H (decimal 17): Recalibrate Drive
Service 15H (decimal 21): Get Disk Type
Service 16H (decimal 22): Diskette Change Status
Service I7H (decimal 23): Set Diskette Type
Service 18H (decimal 24): Set Media Type for Format
Service 19H (decimal 25): Park Heads
Service 1AH (decimal 26): Format ESDI Unit
Disk-Base Tables
Comments and Examples
11 ROM BIOS Keyboard Services
Accessing the Keyboard Services
Service OOH (decimal 0): Read Next Keyboard Character
Service 01H (decimal 1): Report Whether Character Ready
Service 02H (decimal 2): Get Shift Status
Service 03H (decimal 3): Set Typematic Rate and Delay
Service 05H (decimal 5): Keyboard Write
Service 10H (decimal 16): Extended Keyboard Read
Service 11H (decimal 17): Get Extended Keystroke Status
Service 12H (decimal 18): Get Extended Shift Status
Comments and Example
12 Miscellaneous Services
RS-232 Serial Communications Services
Service OOH (decimal 0): Initialize Serial Port
Service 01H (decimal 1): Send Out One Character
Service 02H (decimal 2): Receive One Character
Service 03H (decimal 3): Get Serial Port Status
Service 04H (decimal 4): Initialize Extended Serial Port
Service 05H (decimal 5): Control Extended Communications Port
Miscellaneous System Services
Service OOH (decimal 0): Turn On Cassette Motor
Service 01H (decimal 1): Turn Off Cassette Motor
Service 02H (decimal 2): Read Cassette Data Blocks
Service 03H (decimal 3): Write Cassette Data Blocks
Service 21H (decimal 33): Read or Write PS/2 POST Error Log
Service 83H (decimal 131): Start or Cancel Interval Timer
Service 84H (decimal 132): Read Joystick Input
Service 86H (decimal 134): Wait During a Specified Interval
Service 87H (decimal 135): Protected-Mode Data Move
Service 88H (decimal 136): Get Extended Memory Size
Service 89H (decimal 137): Switch to Protected Mode
Service C0H (decimal 192): Get System Configuration Parameters
Service C1H (decimal 193): Get ROM BIOS Extended Data Segment
Service C2H (decimal 194): Pointing-Device Interface
Service C3H (decimal 195): Enable/Disable Watchdog Timer
Service C4H (decimal 196): Programmable Option Select
ROM BIOS Hooks
Service 4FH (decimal 79): Keyboard Intercept
Service 80H (decimal 128): Device Open
Service 81H (decimal 129): Device Close
Service 82H (decimal 130): Program Termination
Service 85H (decimal 133): Sys Req Keystroke
Service 90H (decimal 144): Device Busy
Service 91H (decimal 145): Interrupt Complete
Printer Services
Service OOH (decimal 0): Send 1 Byte to Printer
Service 01H (decimal 1): Initialize Printer
Service 02H (decimal 2): Get Printer Status
Other Services
Interrupt 05H (decimal 5): Print-Screen Service
Interrupt 11H (decimal 17): Equipment-List Service
Interrupt 12H (decimal 18): Memory-Size Service
Interrupt 18H (decimal 24): ROM BASIC Loader Service
Interrupt 19H (decimal 25): Bootstrap Loader Service
Interrupt 1AH (decimal 26): Time-of-Day Services
13 ROM BIOS Services Summary
Short Summary
Long Summary
14 DOS Basics
The Pros and Cons of Using the DOS Services
DOS: A Disk-Service Cornucopia
DOS and Video: A Difficult Match
DOS Version Differences
Diskette Format Considerations
Comments
15 DOS Interrupts
The Five Main DOS Interrupts
Interrupt 20H (decimal 32): Program Terminate
Interrupt 21H (decimal 33): General DOS Services
Interrupts 25H and 26H (decimal 37 and 38): Absolute Disk Read and Write
Interrupt 27H (decimal 39): Terminate and Stay Resident
The Multiplex Interrupt
The Three DOS Address Interrupts
Interrupt 22H (decimal 34): Terminate Address
Interrupt 23H (decimal 35): Ctrl-C Handler Address
Interrupt 24H (decimal 36): Critical Error-Handler Address
The DOS Idle Interrupt
The Program Segment Prefix (PSP)
The Internal Structure of the PSP
An Example
16 DOS Functions: Version 1
Interrupt 21H Functions: DOS Version 1
Function OOH (decimal 0): Terminate
Function 01H (decimal 1): Character Input with Echo
Function 02H (decimal 2): Character Output
Function 03H (decimal 3): Auxiliary Input
Function 04H (decimal 4): Auxiliary Output
Function 05H (decimal 5): Printer Output
Function 06H (decimal 6): Direct Console Input/Output
Function 07H (decimal 7): Direct Console Input Without Echo
Function 08H (decimal 8): Console Input Without Echo
Function 09H (decimal 9): String Output
Function OAH (decimal 10): Buffered Keyboard Input
Function OBH (decimal 11): Check Keyboard Status
Function OCH (decimal 12): Flush Keyboard Buffer, Read Keyboard
Function 0DH (decimal 13): Flush Disk Buffers
Function 0EH (decimal 14): Select Disk Drive
Function 0FH (decimal 15): Open File
Function 10H (decimal 16): Close File
Function 11H (decimal 17): Find First Matching Directory Entry
Function 12H (decimal 18): Find Next Matching Directory Entry
Function 13H (decimal 19): Delete File
Function 14H (decimal 20): Sequential Read
Function 15H (decimal 21): Sequential Write
Function 16H (decimal 22): Create File
Function 17H (decimal 23): Rename File
Function 19H (decimal 25): Get Current Disk
Function 1AH (decimal 26): Set Disk Transfer Area
Function 1BH (decimal 27): Get Default Drive Information
Function 1CH (decimal 28): Get Specified Drive Information
Function 21H (decimal 33): Read Random Record
Function 22H (decimal 34): Write Random Record
Function 23H (decimal 35): Get File Size
Function 24H (decimal 36): Set FCB Random Record Field
Function 25H (decimal 37): Set Interrupt Vector
Function 26H (decimal 38): Create New Program Segment Prefix
Function 27H (decimal 39): Read Random Records
Function 28H (decimal 40): Write Random Records
Function 29H (decimal 41): Parse Filename
Function 2AH (decimal 42): Get Date
Function 2BH (decimal 43): Set Date
Function 2CH (decimal 44): Get Time
Function 2DH (decimal 45): Set Time
Function 2EH (decimal 46): Set Verify Flag
The File Control Block
FCB Fields
Extended FCB Fields
An Example
17 DOS Functions: Versions 2.0 and Later
Enhancements in DOS Versions 2 and 3
Consistent Error Codes
ASCIIZ Strings
File Handles
Installable Device Drivers
Interrupt 21H Functions: DOS Versions 2.0 and Later
Function 2FH (decimal 47): Get DTA Address
Function 30H (decimal 48): Get DOS Version Number
Function 31H (decimal 49): Terminate and Stay Resident
Function 33H (decimal 51): Get/Set Ctrl-C Flag
Function 35H (decimal 53): Get Interrupt Vector
Function 36H (decimal 54): Get Disk Free Space
Function 38H (decimal 56): Get/Set Country-Dependent Information
Function 39H (decimal 57): Create Directory
Function 3AH (decimal 58): Remove Directory
Function 3BH (decimal 59): Change Current Directory
Function 3CH (decimal 60): Create File
Function 3DH (decimal 61): Open Handle
Function 3EH (decimal 62): Close Handle
Function 3FH (decimal 63): Read from File or Device
Function 40H (decimal 64): Write to File or Device
Function 41H (decimal 65): Delete File
Function 42H (decimal 66): Move File Pointer
Function 43H (decimal 67): Get/Set File Attributes
Function 44H (decimal 68): IOCTL—I/O Control for Devices
Function 45H (decimal 69): Duplicate Handle
Function 46H (decimal 70): Force Duplicate Handle
Function 47H (decimal 71): Get Current Directory
Function 48H (decimal 72): Allocate Memory Block
Function 49H (decimal 73): Free Memory Block
Function 4AH (decimal 74): Resize Memory Block
Function 4BH (decimal 75): EXEC—Load and Execute a Program
Function 4CH (decimal 76): Terminate with Return Code
Function 4DH (decimal 77): Get Return Code
Function 4EH (decimal 78): Find First Matching Directory Entry
Function 4FH (decimal 79): Find Next Matching Directory Entry
Function 54H (decimal 84): Get Verify Flag
Function 56H (decimal 86): Rename File
Function 57H (decimal 87): Get/Set File Date and Time
Function 58H (decimal 88): Get/Set Memory Allocation Strategy
Function 59H (decimal 89): Get Extended Error Information
Function 5AH (decimal 90): Create Temporary File
Function 5BH (decimal 91): Create New File
Function 5CH (decimal 92): Lock/Unlock File Region
Function 5EH (decimal 94): Network Machine Name and Printer Setup
Function 5FH (decimal 95): Network Redirection
Function 62H (decimal 98): Get PSP Address
Function 65H (decimal 101): Get Extended Country Information
Function 66H (decimal 102): Get/Set Global Code Page
Function 67H (decimal 103): Set Handle Count
Function 68H (decimal 104): Commit File
18 DOS Functions Summary
Short Summary
Long Summary
19 Program Building
Structure of an Executable Program
The Memory Map
The Use of Registers
Memory Models
Subroutine Interfaces
Combining Program Modules
Step 1: Writing the Source Code
Step 2: Translating the Source Code
Step 3: Linking
Step 4: Converting File Formats
Step 5: Creating Object Libraries
Using LINK
Linking a Self-contained Program
Linking a Program to a Library
Linking Object Files
20 Programming Languages
Language Specifics
Assembly Language
Logical Organization
Learning About Interface Conventions
Writing and Linking Assembler Programs
The C Language
Parameter Passing
Memory Model Variations
Naming Conventions
Data Representation
Interpreted BASIC
The Subroutine Interface
Data Representation
Compiled BASIC
The Subroutine Interface
Data Representation
Turbo Pascal
The Subroutine Interface
Data Representation
A Parting Comment
Appendix A: Installable Device Drivers
Overview
How Device Drivers Work
The ANSI Driver
ANSI Screen Control
ANSI Keyboard Control
The Pros and Cons of the ANSI Driver
Appendix B: Hexadecimal Arithmetic
Bits and Hexadecimal
Segmented Addresses and Hexadecimal Notation
Decimal-Hexadecimal Conversion
Using BASIC for Hex Arithmetic
Hex Addition
Hex Multiplication
Appendix C: About Characters
The Standard and Extended Character Sets
The Character Format
The First 32 ASCII Characters
The Box-Drawing Characters
The Graph and Block Characters
Text File Formatting Conventions
Ordinary Text File Formats
Word-Processor Text Formats
Appendix D: DOS Version 4
New Features in DOS Version 4
Interrupt 21H Functions in DOS Version 4
Function 33H (decimal 51): Get/Set System Value
Function 44H (decimal 68): IOCTL—I/O Control for Devices
Function 65H (decimal 101): Get Extended Country Information
Function 6CH (decimal 108): Extended Open/Create
Interrupts 25H and 26H
The DOS Version 4 Disk Boot Sector
The Extended BIOS Parameter Block
The Volume Serial Number
A Sample Routine
DOS Version 4 in Perspective
Index
Numbers
A
B
C
D
E
F
G-H
I
J-K
L-M
N-O
P
Q-R
S
T-U
V-W