Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void printString(char*);
- void readString(char*);
- void readSector(char*,int);
- void readFile(char*, char*);
- void executeProgram(char* name, int segment);
- void terminate();
- int mod (int, int);
- int div(int, int);
- void handleInterrupt21(int , char* , int , int );
- void terminate()
- main(){
- /*
- char line[80];
- printString("Enter a line: \0");
- readString(line);
- printString(line);
- while (1){
- }
- */
- //testing readfile
- /*
- char buffer[13312]; //this is the maximum size of a file
- makeInterrupt21();
- interrupt(0x21, 3, "messag\0", buffer, 0); //read the file into buffer
- interrupt(0x21, 0, buffer, 0, 0); //print out the file
- while(1); //hang up
- */
- //testing executeProgram
- makeInterrupt21();
- interrupt(0x21, 4, "tstprg\0", 0x2000, 0);
- while(1);
- }
- void executeProgram(char* name, int segment){
- char buffer[13312];
- int counter;
- readFile(name, buffer);
- for(counter=0; counter<13312; counter++){
- putInMemory(segment,counter,buffer[counter]);
- }
- //launchProgram(int segment)
- launchProgram(segment);
- }
- void readFile(char* filename, char* address){
- int flag = 0;
- int filecounter;
- int lettercounter;
- int sectorcounter;
- int sectors[26];
- int persector;
- readSector(address, 2);
- for(filecounter=0; filecounter<16; filecounter++)
- {
- if(address[filecounter*32]!=0x0){
- for(lettercounter=0; lettercounter<6; lettercounter++){
- if(address[filecounter*32+lettercounter]!=filename[lettercounter]){
- flag=0;
- break;
- }else{
- flag=1;
- }
- }
- if(flag==1){
- for(sectorcounter=0; sectorcounter<26; sectorcounter++){
- sectors[sectorcounter]= address[filecounter*32+6+sectorcounter];
- }
- for(persector=0; persector<26; persector++){
- readSector(address+(persector*512), sectors[persector]);
- }
- }
- }
- }
- if(flag==0){
- printString("file cannot be found ");
- }
- return;
- }
- void terminate(){
- for(;;){
- }
- }
- void printString(char* string){
- int i = 0;
- char ch;
- while (string[i] != '\0')
- {
- ch = string[i];
- interrupt(0x10,0xe*256+ch,0,0,0);
- if (ch == 13)
- interrupt(0x10,0xe*0x100+10,0x0,0x0,0x0);
- i++;
- }
- return;
- }
- void readString(char* line)
- {
- int i = 0;
- char ascii ;
- while (ascii != 0xd)
- {
- ascii = interrupt(0x16, 0x0, 0x0, 0x0, 0x0);
- line[i] = ascii;
- interrupt(0x10,0xe*0x100+ascii,0x0,0x0,0x0);
- if (ascii == 13)
- interrupt(0x10,0xe*0x100+10,0x0,0x0,0x0);
- i++;
- if (ascii == 0x8){
- interrupt(0x10,0xe*256+0x20,0x0,0x0,0x0);
- interrupt(0x10,0xe*256+0x8,0x0,0x0,0x0);
- }
- }
- *(line + i) = 0xa;
- i++;
- *(line + i) = 0x0;
- return ;
- }
- void readSector(char* buffer,int sector){
- int relativesector;
- int head;
- int track;
- int tmp1;
- int tmp2;
- tmp1=mod(sector,18);
- relativesector=tmp1+1;
- tmp2=div(sector,18);
- head = mod(tmp2,2);
- track = div(sector,36);
- interrupt(0x13,2*256+1,buffer,track*256+relativesector,head*256+0);
- return;
- }
- int mod (int x, int y){
- int result;
- int tmp1;
- int tmp2;
- tmp1= div(x,y);
- tmp2=y*tmp1;
- result= x-tmp2;
- return result;
- }
- int div(int x, int y) {
- int result = 0;
- while(x>=y){
- x=x-y;
- result++;}
- return result;
- }
- /*void handleInterrupt21(int ax, int bx, int cx, int dx){
- printString("Hello World\0");
- }*/
- void handleInterrupt21(int ax, char* bx, int cx, int dx){
- if (ax==0){
- printString(bx);
- }
- else {
- if (ax==1){
- readString(bx);
- }
- else {
- if (ax==2){
- readSector(bx,cx);
- }
- else {
- if(ax==3){
- readFile(bx,cx);
- } else{
- if(ax==4){
- executeProgram(bx, cx);
- } else {
- printString("error\0");
- }
- }
- }
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement