Presentation is loading. Please wait.

Presentation is loading. Please wait.

Project Assignment Snake Game/Car Acceleration Meter Min 10 Pages 10 min Presentation Max 5 group members Submitting Date: lab 2:Dec 27, 2014 Lab 3: Dec.

Similar presentations


Presentation on theme: "Project Assignment Snake Game/Car Acceleration Meter Min 10 Pages 10 min Presentation Max 5 group members Submitting Date: lab 2:Dec 27, 2014 Lab 3: Dec."— Presentation transcript:

1 Project Assignment Snake Game/Car Acceleration Meter Min 10 Pages 10 min Presentation Max 5 group members Submitting Date: lab 2:Dec 27, 2014 Lab 3: Dec 22, 2014

2 Keyboard and Cursor Chapter 8

3 C’s interaction with PC computer  IBM extended character codes, which enable a program to read the function keys; cursor control keys and special key combinations  ANSI.SYS control function, which give the programmer control over where the cursor is on the screen and permit other operations as well All most all programs- word processors, database programs and games – need to make use of these capabilities to provide more sophisticated level of interaction with user

4 Extended keyboard codes letters, numbers and punctuation, such keys generate one-byte ASCII codes The PC provides a second set of 256 keys and key combinations by using an extended code. Extended code consists of two bytes; the first byte is 0 and the second byte is a number indicating the particular key or key combination. 97 0 59 Always 0 Extended code 2 bytes Function key F1 Normal code 1 byte Letter ‘a’

5 Exploring the Extended Codes #include void main(void) { clrscr(); unsigned char key, key2; while ((key=getch())!='\r') { if (key == 0) { key2 = getch(); printf("%3d %3d\n", key, key2); } else printf("%3d\n",key); } getch(); } Output: 0 59 0 60 0 61 97 98

6 ANSI.SYS cursor control For accessing I/O devices, ANSI.SYS file used. ANSI stands for American National Standards Institute ANSI.SYS file provides a standardized set of codes for cursor control It is a section of code written to control an I/O device, which is added to the operating system((DOS) after DOS is installed ANSI.SYS interacts all the numeric codes being sent to the screen for printing For escape code (a special sequence of characters), the ANSI.SYS file deals with the code itself, moving the cursor or performing other functions For normal character, it is simply passed on the regular video routines in ROM, which display it on the screen in the usual way

7 One-Key Extended Codes Second Byte(Decimal)Key that Generates Extended Codes 59 F1 60 F2 61 F3 62 F4 63 F5 64 F6 65 F7 66 F8 67 F9 68 F10 71 Home 72 Up arrow 73 Pg Up 75 Left arrow 77 Right arrow 79 End 80 Down arrow 81 Pg Dn 82 Ins 83 Del

8 Two-Key Extended Codes Second Byte(Decimal)Key that Generates Extended Codes 15 Shift Tab 16 to 25 Alt Q,W,E,R,T,Y,U,I,O,P 30 to 38 Alt A,S,D,F,G,H,J,K,L 44 to 50 Alt Z,X,C,V,B,N,M 84 to 93 Shift F1 to F10 94 to 103 Ctrl F1 to F10 104 to 113 Alt F1 to F10 114 Ctrl PrtSc 115 Ctrl Left Arrow 116 Ctrl Right Arrow 117 Ctrl End 118 Ctrl PgDn 119 Ctrl Home 120 to 131 Alt 1,2,3,4,5,6,7,8,9,0,-,= 132 Ctrl PgUp

9 Installing ANSI.SYS ANSI.SYS is an optional part of DOS Installed each time at power up of computer CONFIG.SYS file used to refer the ANSI.SYS file for installation DEVICE = C:\ANSI.SYS It incorporated with operating system

10 Cursor Control with ANSI.SYS Cursor control is achieved with ANSI.SYS using escape sequences All ANSI.SYS commands begin with the escape sequence, “\x1B[“. CodeEffect [2] Erase screen and home cursor [K Erase to end of line [A Cursor up one row [B Cursor down one row [C Cursor right one column [D Cursor left one column [%d;%df Cursor to row and column specified [s Save cursor position [u Restore position [%dA Cursor up number of rows specified [%dB Cursor down number of rows specified [%dC Cursor right number of columns specified [%dD Cursor left one row number of columns specified

11 Cursor Control with ASCI.SYS #include void main(void) { while (getche()!= '\r') printf("\x1B[B"); getch(); } #include #define C_DOWN "\x1B[B" void main(void) { while (getche()!= '\r') printf( C_DOWN); getch(); } Output: H A C K E R

12 Character Attributes Every character is stored in the display memory as two bytes: one for the ASCII code of the character and one for the attribute 0Turns off attributes: normal white on black 1Bold(high intensity) 4Underline 5Blinking 7Reverse video; black on white 8Invisible; black on black

13 Key reassignment Assigning strings to function keys enables to configure keyboard for the kind of work usually do. For example, if you write lot of C programs, you might want to list the C source files in a particular directory: C>dir*.CPP If this string assign to a function key, it save lot of time printing this prase

14 Assigns function keys to string typed by user #include main() { char string[81]; int key; clrscr(); printf("enter number of function key:"); gets(string); key=atoi(string); /*conver string to integer*/ puts("enter string to assign to that key:"); gets(string); printf("\x 1B[0;%d;\"%s\";13p",key+58,string); getch(); }

15 Command-line arguments When invoke a program from the operating system, we type program name and other various items i.e. C> notepad Letter.txt By putting the right things inside the parentheses of main, we can allow our program to read command-line argument to its heart’s content. C automatically adds the capability to read these arguments to all C programs.

16 Uses command-line arguments #include void main(int argc,char *argv[]) { int key; clrscr(); if(argc!=3) { printf("example usage : C>funkey0 2 dir"); exit(); } key=atoi(argv[1]); printf("\x1B[0;%d;\"%s\";13p",key+58,argv[2]); getch(); }

17 Redirect of input and output Redirection provides an easy way to save the results of a program; it use vaguely similar that of the [Ctrl][PrtSc] key combination to save output to the printer, except that the result can be sent to a disk. Output can be redirected to go to a file instead of the screen; input can be redirected to come from a file instead of the keyboard.

18 Echos typing to the screen #include main() { int ch=0; while( (ch=getch() )!='\r') putchar(ch); putchar('\r'); }


Download ppt "Project Assignment Snake Game/Car Acceleration Meter Min 10 Pages 10 min Presentation Max 5 group members Submitting Date: lab 2:Dec 27, 2014 Lab 3: Dec."

Similar presentations


Ads by Google