Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
C#
Write a TSR program in C that will clear all the contents of the screen and print your VU ID and Name (BC0000000-Name) at the center of the video text memory available at 0xB8000000 whenever Alt+Ctrl+D combination is pressed from keyboard.

Note that you have to take the backup of the contents of video text memory before clearing the screen. And, whenever Alt+Ctrl+R combination is pressed from the keyboard, all the contents of video text memory should be restored.


My Code for this Problem:
Problem occurs at the end of the code for keyboard interrupt
C#
//CLRSCREEN AND Character Printing Program
#include<DOS.H>
#include<stdio.h>
void interrupt (*old)();
void interrupt scrnsvr();
//void interrupt (*oldkey)();
//void interrupt newkey();
//void cls();              SALMAN HAIDER

unsigned char far *scr = (unsigned char far*)0xb8000680;
unsigned char far *src = (unsigned char far*)0xb8000000;
unsigned char far *sch = (unsigned char far*)0x00400017;
int i,j;
char charsrc[4000];

void interrupt scrnsvr(){

//saving contents
    for(i=0; i < 4000; i++)
    charsrc[i] = *(src+i);
//Clearing Screen
    for(i=0; i < 4000; i+=2)
    {
        *(src + i) = 0x20;
        *(src + i + 1) = 0x07;
    }
}
//Prints RollNo and Name at Center of Graphics Text Memory
void charPrint(){
    *scr = 0x6D;
    *(scr+1) = 0x70;
    *(scr+2) = 0x63;
    *(scr+3) = 0x07;
    *(scr+4) = 0x31;
    *(scr+5) = 0x07;
    *(scr+6) = 0x34;
    *(scr+7) = 0x07;
    *(scr+8) = 0x30;
    *(scr+9) = 0x07;
    *(scr+10) = 0x34;
    *(scr+11) = 0x07;
    *(scr+12) = 0x30;
    *(scr+13) = 0x07;
    *(scr+14) = 0x32;
    *(scr+15) = 0x07;
    *(scr+16) = 0x32;
    *(scr+17) = 0x07;
    *(scr+18) = 0x39;
    *(scr+19) = 0x07;
    *(scr+20) = 0x37;
    *(scr+159) = 0x07;
    *(scr+160) = 0x53;
    *(scr+161) = 0x07;
    *(scr+162) = 0x61;
    *(scr+163) = 0x07;
    *(scr+164) = 0x6C;
    *(scr+165) = 0x07;
    *(scr+166) = 0x6D;
    *(scr+167) = 0x07;
    *(scr+168) = 0x61;
    *(scr+169) = 0x07;
    *(scr+170) = 0x6E;
    *(scr+171) = 0x07;
    *(scr+172) = 0x20;
    *(scr+173) = 0x07;
    *(scr+174) = 0x48;
    *(scr+175) = 0x07;
    *(scr+176) = 0x61;
    *(scr+177) = 0x07;
    *(scr+178) = 0x69;
    *(scr+179) = 0x07;
    *(scr+180) = 0x64;
    *(scr+181) = 0x07;
    *(scr+182) = 0x65;
    *(scr+183) = 0x07;
    *(scr+184) = 0x72;
}
void restore(){
    for(j=0; j < 4000; j++)
        *(src + j) = charsrc[j];
}
/*
void interrupt newkey(){
    *sch = 24;
    *(sch+1) = 34;
       geninterrupt(0x65);
       charPrint();
       (*oldkey)();
*/

void main(){
//Cls
//  oldkey = getvect(0x09);
//  setvect(0x09, newkey);

    old = getvect(0x65);
    setvect(0x65,scrnsvr);
    keep(0,1000);
//Function
    _AH = 0x09;
       if(_AL==0x1D && _AL==0x38 && _AL==0x20)
     {
      geninterrupt(0x65);
      charPrint();
     }
      else if(_AL==0x1D && _AL==0x38 && _AL==0x13)
    {
      restore();
     }
}
}


What I have tried:

I tried many times to put the scan code of Keyboard buttons in Ah but failed please correct me the code.
Posted
Updated 12-May-16 11:41am
Comments
Dave Kreskowiak 12-May-16 17:02pm    
Are you seriously writing a DOS app? Who runs DOS anymore?
DevilShadow 12-May-16 23:05pm    
just for my practice i want a TSR for all that purpose
Dave Kreskowiak 13-May-16 6:49am    
I haven't written code like this in over 20 years. You're treading around around in an environment and type of application that nobody has messed with in at least 15 years. The support base for this kind of app is down to nearly 0. DOS and TSR apps have been dead for quite a long time now.
Sergey Alexandrovich Kryukov 12-May-16 17:38pm    
This is not "interrupt". Each touch to the keyboard already generates a hardware interrupt, and the whole chain of events resulting from an event like that is all about interrupt processing, which can be done on some different levels.

It is normally done in Assembly Language; and it's not a problem to do it in C++ inline assembly, the way I personally like. Of course, it can be done only for unprotected OS such as DOS. In modern systems, it goes to drivers.

—SA
DevilShadow 12-May-16 23:06pm    
but in System programming we write TSR using C language in Borland C++ or DOSBOX Turbo C++

1 solution

Please see my comment to the question, which is the major part of the answer. For BIOS interrupt, please see: INT 16H — Wikipedia, the free encyclopedia[^].

On this level, you can work at the level of keyboard scan codes.

As I already tried to explain in my comment, "generate interrupt" is absurd. This is not how things work. For some education, see also: Inversion of control — Wikipedia, the free encyclopedia[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900