Lecture 5: Interrupts in Turbo C++

Slides:



Advertisements
Similar presentations
Register In computer architecture, a processor register is a small amount of storage available on the CPU whose contents can be accessed more quickly than.
Advertisements

Registers of the 8086/ /2002 JNM.
MICROPROCESSORS TWO TYPES OF MODELS ARE USED :  PROGRAMMER’S MODEL :- THIS MODEL SHOWS FEATURES, SUCH AS INTERNAL REGISTERS, ADDRESS,DATA & CONTROL BUSES.
Introduction to 8086 Microprocessor
SOFTWARE ARCHITECTURE OF THE 8088 AND 8086 MICROPROCESSORS
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#3) By Dr. Syed Noman.
Outline  Examine some of the H/W supplied with a typical PC and consider the software required to control it.  Introduce Commkit, a software tool that.
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Introduction to Interrupts
Gursharan Singh Tatla Block Diagram of Intel 8086 Gursharan Singh Tatla 19-Apr-17.
Unit-1 PREPARED BY: PROF. HARISH I RATHOD COMPUTER ENGINEERING DEPARTMENT GUJARAT POWER ENGINEERING & RESEARCH INSTITUTE Advance Processor.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
The 8086 Microprocessor The 8086, announced in 1978, was the first 16-bit microprocessor introduced by Intel Corporation 8086 is 16-bit MPU. Externally.
An Introduction to 8086 Microprocessor.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
1 Fundamental of Computer Suthida Chaichomchuen : SCC
Types of Registers (8086 Microprocessor Based)
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
3.4 Addressing modes Specify the operand to be used. To generate an address, a segment register is used also. Immediate addressing: the operand is a number.
Structure and Role of a Processor
Internal Programming Architecture or Model
Intel 8086 MICROPROCESSOR ARCHITECTURE
ΜComputer Structure μProcessor Memory Bus System I/O Ports.
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
An Introduction to 8086 Microprocessor.
MICROPROCESSOR BASED SYSTEM DESIGN
CS501 Advanced Computer Architecture
Microprocessor and Assembly Language
Microprocessor Systems Design I
UNIT Architecture M.Brindha AP/EIE
Introduction to 8086 Microprocessor
Interrupts In 8085 and 8086.
8086 Microprocessor.
Computer Organization & Assembly Language Chapter 3
Intel 8086 MICROPROCESSOR Architecture.
Microprocessor and Assembly Language
Basic Microprocessor Architecture
Intel 8088 (8086) Microprocessor Structure
Microprocessor and Assembly Language
Basic of Computer Organization
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
The slides must be understood in Lecture 5
Introduction to Assembly Language
BIC 10503: COMPUTER ARCHITECTURE
Computer System Overview
Intel 8088 (8086) Microprocessor Structure
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
CS 301 Fall 2002 Computer Organization
The Microprocessor & Its Architecture
COMPUTER PERIPHERALS AND INTERFACES
Symbolic Instruction and Addressing
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Unit:08 Software Interrupts
Computer Architecture CST 250
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Unit-I 80386DX Architecture
Computer System Overview
Lecture 6: Structure and Class
Chapter 6 –Symbolic Instruction and Addressing
Process.
Chapter 8: Instruction Set 8086 CPU Architecture
8086 microprocessior PIN OUT DIAGRAM OF  Power supply and frequency signals  It uses 5V DC supply at V CC pin 40, and uses ground at V SS pin.
Presentation transcript:

Lecture 5: Interrupts in Turbo C++ Concepts of Interrupts Programs for interrupts: Keyboard Video Time 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

Execution of an Instruction (review) Fetch the instruction from the memory Execution of an instruction is achieved by a sequence of commands issues by the control unit. Fetch the operands from the memory Perform the operation Update the program counter no Check interrupt yes Interrupt processing Next Instruction 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

Execution of a Program (review) Fetch the instruction from the memory Fetch the operands from the memory Perform the operation LOAD b, R1 Update the program counter A program is a sequence of instructions. no Check interrupt yes Fetch the instruction from the memory Fetch the operands from the memory Perform the operation ADD R1, 1 Update the program counter a = b + 1; no Check interrupt yes Fetch the instruction from the memory Fetch the operands from the memory Perform the operation STORE R1, a Update the program counter no Check interrupt yes …... 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Interrupt Interrupt is a mechanism for diverting the attention of a processor when a particular event occurs, such as I/O device requests. Interrupts cause a break in the normal execution of a program. 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

A Break in the Normal Execution of a Program Fetch the instruction from the memory Interrupt The execution of the program can be temporarily stopped to allow a special piece of software -- an interrupt service routine -- to run. When the routine has finished, the program resumes. + efficient and responsive - difficult to program Fetch the operands from the memory Perform the operation Update the program counter no Check interrupt yes Fetch the instruction from the memory Fetch the operands from the memory Perform the operation Interrupt Processing and Service Update the program counter Check interrupt yes Fetch the instruction from the memory Fetch the operands from the memory Perform the operation Update the program counter no Check interrupt yes Interrupt processing 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Steps taken to process Interrupt 1. On receipt of the interrupt, the processor after executing the current instruction, branches to an interrupt processing routine. The routine is commonly known as Interrupt Handler. 2. The Interrupt Handler will save the current processor data (registers, status register, PC) and determine which device has interrupt the processor (polling). 3. Execution then branches to the so called Interrupt Service Routine associated with the device (causing the interrupt) and the processor executes data transfer. 4. The interrupt system is enable so that further interrupts may be recognized. 5. Return to that program the execution of which was suspended after recognizing the interrupt. 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

Find out which device causes interrupt Processing and Service Disable interrupts Save environment Find out which device causes interrupt Branch to specific interrupt service routine ISR 1 ISR i ISR n Restore environment Enable interrupts 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Interrupt Vectors the segmented addresses that specify the locations of interrupt handlers are called interrupt “vectors” an interrupt handler is a function/subroutine that takes care of the interrupt. There are 256 interrupt vectors stored in interrupt vector table located at the beginning of the memory some are reserved and some can be used by users 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Types of Interrupt • Hardware Interrupts • CPU Interrupts • Software Interrupts 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Hardware Interrupts Hardware interrupts are generated by device control and supervised by PIC (programmable interrupt control) chip. Interrupt No. Functions 0x02 NMI: non-maskable interrupt, memory parity 0x08 timer (18 per second) 0x09 keyboard 0x0A interrupt from controller 2 0x0B, 0x0C serial port2,1 0x0D parallel port 2 0x0E diskette 0x0F parallel port 1 (for printer) Here, NMI has top priority and is serviced immediately, and it cannot be turned off. It occurs due to some significant error, such as power failure. HERE: 0x stands for hexadecimal notations: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F, where A stands for ten, B eleven, C, twelve, D thirteen, E fourteen, F fifteen. Therefore, 0x200 is 2x16x16 plus 0 which is 512 in decimal. For decimal notations: 200=2x10x10. 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie CPU Interrupts CPU interrupts are generated in response to a fatal program error, or for program flow control 0x00 division by zero 0x01 generated after every instruction when in single-step mode 0x02 generated when a program reaches a breakpoint set by user 0x04 arithmetic overflow 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Software Interrupts Software interrupts are generated by using the software interrupt instruction. In turbo C: #include <dos.h> geninterrupt(n); BIOS interrupts: provides the most direct, low level interaction with the I/O devices and give a device-independent interface which hides all the details of the hardware architecture from programmers and includes interrupt numbers: 0x05, 0x10-0x1C, 0x48. DOS interrupts: are parts and the DOS operating system, handle file and memory management and executive services: 0x20-0x60 General use interrupts: can be written by users for their own service routines: 0x61-0x67 Notice: no need to remember all the interrupt vectors. Focus on 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie A Register INPUT OUTPUT D Q CLOCK D: data input Q: output of data in the register 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Architecture of PC Registers Scratch-pad Registers AH BH CH DH AL BL CL DL AX (accumulator) BX (base) CX (count) DX (data) CS (code segment) DS (data segment) SS (stack segment) ES (extra segment) IP (instruction pointer) SP (stack pointer) BP (base pointer) SI (source index) DI (destination index) Flags 7 7 15 Segment Registers 15 Offset Registers OF DF IF TF SF ZF AF PF CF 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Access Registers in Turbo C REGISTERS PSUDO-VARIABLES in C AX _AX (_AH _AL) BX _BX (_BH, _BL) CX _CX (_CH, _CL) DX _DX (_DH, _DL) CS _CS DS _DS SS _SS ES _ES SP _SP BP _BP SI _SI DI _DI Flags _FLAGS 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie The Flag Register in IBM PC 15 OF DF IF TF SF ZF AF PF CF IF is the interrupt flag which controls whether interrupts are enabled. IF=1: The CPU will deal with interrupt requests. IF=0: The CPU will ignore interrupt requests. CF Carry flag Indicates an arithmetic carry OF Overflow flag Indicates a signed arithmetic overflow ZF Zero flag Indicates a zero result or an equal comparison SF Sign flag Indicates a negative result or comparison PF Parity flag Indicates an even number of 1 bits AF Auxiliary carry flag …. DF Direction flag Controls increment direction in string operastions TF Trap flag Controls single-step operation (used by DEBUG). 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie BIOS Keyboard Services They are invoked with interrupt 0x16 with the following Service numbers in the register AH (_AH in Turbo C). service# functionality 0x00 Read Next Keyboard Character 0x01 Report Whether Character Ready 0x02 Get Shift Status 0x03 Set Typematic Rate and Delay 0x05 Keyboard Write 0x10 Extended Keyboard Read 0x11 Get Extended Keystroke Status 0x12 Get Extended Shift Status Notice: 1. Service numbers are parameters pass to the subroutines/interrupt handlers 2. Try to remember the meaning of service 0x00 and 0x01 for interrupt 0x16. 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Interrupt 0x16 Service 0x00 Service 0x00 reports the next keyboard input character. If there is no character in the BIOS keyboard buffer, it waits until one is ready. The character is removed from the BIOS keyboard buffer after it is read. The auxiliary byte returned in AH is either the character ID for special characters or the standard PC-keyboard scan code identifying the pressed key. Each character is reported as a pair of bytes. The main byte returned in AL is either 0 for special characters, or an ASCII code for ASCII characters. To invoke this service to read a character into a variable x in Turbo C, we do: char x; _AH=0x0; geninterrupt(0x16); x=_AL; 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie An Example of Getting a Key from Keyboard char x; int y; _AH=0x0; geninterrupt(0x16); x=_AL; cout <<“The key is: ”<< x <<endl; declare x to be “char” type choose service 0x0 with _AH invoke interrupt 0x16 get ASCII code of key from _AL print the key out Remember to include dos.h in your file. 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie A Function to get a key char get_key_number () { //return type of the function is char char a; _AH=0x00; //service number 0x00 geninterrupt(0x16); //interrupt 0x16 a=_AL; //_AL is the key return tmp; //return the value } Demo the program A:key.cpp in the lecture. 1. Show the program 2. Run the program 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Interrupt 0x16 Service 0x01 Service 0x01 tests whether a keyboard input character is ready. The zero flag (ZF) is used as the signal: 1 indicates no input is ready, 0 indicates a character is ready. In the latter case, the character is not removed from the BIOS keyboard buffer until it is read by service 0x00. To invoke this service in Turbo C, we do: char x; _AH=0x01; geninterrupt(0x16); To test whether a character is ready after the above steps in Turbo C, we do: if (_FLAGS&0x40==64); to check whether ZF is 1. 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Use Keyboard BIOS to Read To write a program to read a char from BIOS keyboard buffer, one may first use service 0x01 interrupt 0x16 to test whether there is a key stored in the BIOS buffer, then use service 0x00 interrupt 0x16 to read it. int ch; _AH=0x01; geninterrupt(0x16); temp=_FLAGS&0x40; /*must put the data to temp, see slide 32 */ if (temp==0) { _AH=0; ch=_AL; } The difference is that the computer does not have to wait for users to type it. 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Caution when using Pseudo-Variables Pseudo-variables refer to CPU registers which are used by other programs which may run at the same time. One must assign values right before using them and read values right after obtaining them, especially when we program in C. Be careful about the following: A pseudo-variable has no address The values one place in pseudo-variables may NOT be preserved for any length of time. Values of pseudo-variables may not remain the same across a function call. Do not change values of _CS, _SS, _SP, nor _BP since they are used by machine code produced by Turbo C compiler. 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Write a function to get a character int key_ready() {//return 1 if a key is ready, 0 otherwise long int x; _AH=1; //service number 0x01 geninterrupt(0x16); //interrupt 0x16 x=_FLAGS; //get flag register if (x&0x40==0) {return 1;} //if ZF==0 a key is ready else return 0; //else no key } char read_a_key() { //return char if a key is ready if (key_ready()) {return get_key_number().x;} else return 0; 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Shoot a bullet when press a key #include<dos.h> #include <graphics.h> #include<iostream.h> #include<conio.h> void show(int i,float h, float v); void erease(int i, float h, float v); void main(void) { int driver = DETECT,mode; int i,j,i1,s1; int y=1; initgraph(&driver,&mode,"D:\\bc31\\bgi"); setcolor(WHITE); line(1,400,400,400); for ( i = 0; i < 80; i++ ) show(i, 5.0, 9.0); y=1; _AH=0x01; geninterrupt(0x16);// y=_FLAGS&0x40; if(y == 0) {s1=1;i1=i; _AH=0x00; geninterrupt(0x16);} if (s1==1) {show(i-i1, 10.0, 8.0); } delay (300); erease(i, 5.0, 9.0); if (s1==1) erease(i-i1, 10.0, 8.0); } closegraph(); void show(int i, float h, float v) { int x, y; x=h*i; y=v*i-0.15*i*i; setcolor(RED); circle(400-x,400-y,2); void erease(int i, float h, float v) { int x, y; setcolor(BLACK); 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Video Interrupt Services(for general knowledge, will not be tested) Most of the useful video services are found in the BIOS through interrupt 0x10. Some MS-DOS video services are provided through interrupt 0x21. They are user programmed interrupts to produce output to the video screen. Usually, one puts the function/service number in the register AH and then invokes the corresponding interrupt. Very often there are some parameters for these functions/services which are put in register AL, BX, CX, or DX. 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie BIOS Video Service Interrupt 0x10 service# functionality service# functionality 0x0C write pixel 0x0D read pixel 0x0E write char in tty mode 0x0F get current video mode 0x10 color palette interface 0x11 char generator interface 0x12 alternate select 0x13 write character string 0x14/15 (PC convertible only) 0x1A read/wri. dsp. cmb. code 0x1B return functionality 0x1C save/restore video state 0x00 set video mode 0x01 set cursor size 0x02 set cursor position 0x03 read cursor position 0x04 read light-pen position 0x05 set active display page 0x06 scroll window up 0x07 scroll window down 0x08 read character/attribute 0x09 write character/attribute 0x0A write character 0x0B set 4-color palette 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Interrupt 0x10 Service 0x0E: Write char in TTY mode . The service number 0x0E is put in register AH. The char to be written is put in AL. The display page number is put in BH and the foreground color is in BL. The character is written at the cursor location, and the cursor is advanced one position, wrapping over to new line or scrolling the screen as needed. There are four characters that service 0x0E reacts to according to their ASCII meaning: 0x07 beep, 0x08 backspace, 0x0A linefeed, 0x0D carriage return. All other characters are displayed normally. 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Output Characters Display character “a” Feed a new line _AH=0x0E; _AL=97; _BH=1; geninterrupt(0x10); _AH=0x0E; _AL=0x0A; _BH=1; geninterrupt(0x10); Back one space Beep _AH=0x0E; _AL=0x08; _BH=1; geninterrupt(0x10); _AH=0x0E; _AL=0x07; _BH=1; geninterrupt(0x10); 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie A Function for Output a Char void output_a_char(int x) { //x is the ASCII code of char _AH=0x0E; _AL=x; _BH=1; geninterrupt(0x10); } Call the function to output characters output_a_char(97); //output ‘A’ output_a_char(8); //backspace output_a_char(7); //output a ring output_a_char(0x0A); //a new line 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Another Function for Output a Char void output2_a_char(char x) { //x is a char type int tmp; tmp=x; //convert to ASCII code _AH=0x0E; //service number 0x0E _AL=tmp; //output tmp _BH=1; geninterrupt(0x10); //interrupt 0x10 } Call the function to output characters output2_a_char(‘A’); //output “A” output2_a_char(‘B’); //output “B” 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Time Services (Clock) Interrupt 0x21 Service 0x2C: CH contains the hours (0-23) CL contains the minutes (0-59) DH contains the seconds (0-59) DL contains hundredths of a second (0-99). 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Time Services (Clock) int i,j,k,l; _AH=0x2C; //service 0x2C for get time interrupt(0x21); //interrupt 0x21 i=_CH; j=_CL; k=_DH; l=_DL; cout<<i<<“ Hours”<<j<<“ Minutes ”<<k<<“ Seconds ”<<l; 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Get the Time of Hitting a Key Using the above functions written with interrupts, we may obtain the approximate time of hitting a key as follows: int i,j,k,l; read_a_key(); /*call function read_a_key(); */ _AH=0x2C; //service 0x2C for get time interrupt(0x21); //interrupt 0x21 i=_CH; j=_CL; k=_DH; l=_DL; cout<<i<<“ Hours”<<j<<“ Minutes ”<<k<<“ Seconds ”<<l; 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Arrays An array is a collection of two or more adjacent memory cells, called array elements, that are associated with a particular symbolic name. To declare an array int x[3]; (We declared an array with name x. It contains 3 elements. Each is of int type.The index starts with 0) x[0] x[1] x[2] 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

Use an array in the program include <iostream.h> void main(void) { int x[10],i; for (i=0; i<=9; i++) cin>>x[i]; cout<< x[i]; } The index of the elements can change. The index of the first element of an array is 0. x[0], x[1], x[2], x[3], x[4] x[5], x[6], x[7], x[8], x[9] 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Initialize an array include <iostream.h> void main(void) { int x[10]={1,2,2,2,3,4,5,6,7,9} ,i; for (i=0; i<=9; i++) cout<< x[i]<<“ ”; } 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie An array of characters include <iostream.h> void main(void) { char x[3]={‘a’, ‘b’, ‘c’} ,i; for (i=0; i<=9; i++) cout<< x[i]; } 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Exercise What does the following program output? include <iostream.h> void main(void) { int x[10]={8, 7, 9, 10, 1, 3, 3, 8, 2, 5} , i, j; for (i=0; i<=9; i++) for(j=9; j>i; j--) if (x[i]>x[j]) { y=x[i]; x[i]=x[j]; x[j]=y; } for(j=0; j<=9; j++) cout<< x[j]; cout<<“\n”; } 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

Shoot bullets whenever press key +plane #include<dos.h> #include <graphics.h> #include<conio.h> void show(int i,float h, float v); void erease(int i, float h, float v); void planeshow(int i); void ereasep(int i); void main(void) { int driver = DETECT,mode; int i,j,i1,s1,k; int y=1; int a[100]; for(i=0; i<=99; i++) a[i]=0; initgraph(&driver,&mode,"D:\\bc31\\bgi"); setcolor(WHITE); line(1,400,400,400); j=1; for ( i = 0; i < 80; i++ ) setcolor(BLUE); planeshow(5*i); setcolor(YELLOW); planeshow(5*(i-8)); show(i, 5.0, 9.0); y=1; _AH=0x01; geninterrupt(0x16);// y=_FLAGS&0x40; if(y == 0) {j=j+1;a[j]=i; _AH=0x00; geninterrupt(0x16);} for (k=2; k<=j; k++) if (a[k]!=0) {show(i-a[k], 10.0+0.5*k, 8.0+0.1*k); } delay (300); ereasep(5*i); ereasep(5*(i-8)); erease(i, 5.0, 9.0); if (a[k]!=0) {erease(i-a[k], 10.0+0.5*k, 8.0+0.1*k); } } closegraph(); void show(int i, float h, float v) { int x, y; x=h*i; y=v*i-0.15*i*i; setcolor(RED); circle(400-x,400-y,2); void erease(int i, float h, float v) { int x, y; x=h*i; y=v*i-0.15*i*i; setcolor(BLACK); circle(400-x,400-y,2); } void planeshow(int i) int j; circle(i+5, 202, 2); circle(i+3, 204, 2); for (j=0; j<=8; j++) circle(i+j, 200, 2); circle(i+5, 198, 2); circle(i+3, 196, 2); void ereasep(int i) 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie

a-shoot bullet u-plane up i-plane down #include<dos.h> #include <graphics.h> #include<conio.h> void show(int i,float h, float v); void erease(int i, float h, float v); void planeshow(int i,int k); void ereasep(int i, int k); void main(void) { int driver = DETECT,mode; int i,j,i1,s1,k; int y=1,xx=0; char x; int a[100]; for(i=0; i<=99; i++) a[i]=0; initgraph(&driver,&mode,"a:\\bgi"); setcolor(WHITE); line(1,400,400,400); j=1; for ( i = 0; i < 80; i++ ) setcolor(BLUE); planeshow(5*i, 5); show(i, 5.0, 9.0); y=1; _AH=0x01; geninterrupt(0x16); y=_FLAGS&0x40; if(y == 0) { _AH=0x00; geninterrupt(0x16); x=_AL; if (x == 'a') {j=j+1;a[j]=i;} if (x =='u' ) {sound(700); xx=xx-5;} if (x =='i' ) {sound(200); xx=xx+5;} } setcolor(YELLOW); planeshow(5*(i-8), xx); for (k=2; k<=j; k++) if (a[k]!=0) {show(i-a[k], 10.0+0.5*k, 8.0+0.1*k); } delay (300); nosound(); ereasep(5*i, 5); ereasep(5*(i-8), xx); erease(i, 5.0, 9.0); if (a[k]!=0) {erease(i-a[k], 10.0+0.5*k, 8.0+0.1*k); } closegraph(); void show(int i, float h, float v) { int x, y; x=h*i; y=v*i-0.15*i*i; setcolor(RED); circle(400-x,400-y,2); void erease(int i, float h, float v) { int x, y; x=h*i; y=v*i-0.15*i*i; setcolor(BLACK); circle(400-x,400-y,2); } void planeshow(int i,int k) int j; circle(i+5, 202+k, 2); circle(i+3, 204+k, 2); for (j=0; j<=8; j++) circle(i+j, 200+k, 2); circle(i+5, 198+k, 2); circle(i+3, 196+k, 2); void ereasep(int i, int k) 11/22/2018 CS3369 Real Time Control Software/DENG Xiaotie