Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.59 KB | None | 0 0
  1. void printString(char*);
  2. void readString(char*);
  3. void readSector(char*,int);
  4. void readFile(char*, char*);
  5. void executeProgram(char* name, int segment);
  6. void terminate();
  7. int mod (int, int);
  8. int div(int, int);
  9. void handleInterrupt21(int , char* , int , int );
  10. void terminate()
  11. main(){
  12. /*
  13. char line[80];
  14. printString("Enter a line: \0");
  15. readString(line);
  16. printString(line);
  17. while (1){
  18. }
  19.  
  20. */
  21.  
  22. //testing readfile
  23. /*
  24. char buffer[13312]; //this is the maximum size of a file
  25. makeInterrupt21();
  26. interrupt(0x21, 3, "messag\0", buffer, 0); //read the file into buffer
  27. interrupt(0x21, 0, buffer, 0, 0); //print out the file
  28. while(1); //hang up
  29. */
  30.  
  31. //testing executeProgram
  32.  
  33. makeInterrupt21();
  34. interrupt(0x21, 4, "tstprg\0", 0x2000, 0);
  35. while(1);  
  36.  
  37.  
  38. }
  39.  
  40. void executeProgram(char* name, int segment){
  41.  
  42. char buffer[13312];
  43. int counter;
  44. readFile(name, buffer);
  45. for(counter=0; counter<13312; counter++){
  46. putInMemory(segment,counter,buffer[counter]);
  47. }
  48. //launchProgram(int segment)
  49. launchProgram(segment);
  50.                
  51.  
  52. }
  53.  
  54. void readFile(char* filename, char* address){
  55.  
  56. int flag = 0;
  57. int filecounter;
  58. int lettercounter; 
  59. int sectorcounter;
  60. int sectors[26];
  61. int persector;
  62. readSector(address, 2);
  63.  
  64. for(filecounter=0; filecounter<16; filecounter++)
  65. {
  66.     if(address[filecounter*32]!=0x0){
  67.            
  68.         for(lettercounter=0; lettercounter<6; lettercounter++){
  69.             if(address[filecounter*32+lettercounter]!=filename[lettercounter]){
  70.                 flag=0;
  71.                 break;
  72.             }else{
  73.                 flag=1;        
  74.             }
  75.         }
  76.        
  77.         if(flag==1){
  78.            
  79.             for(sectorcounter=0; sectorcounter<26; sectorcounter++){
  80.                 sectors[sectorcounter]= address[filecounter*32+6+sectorcounter];
  81.             }
  82.  
  83.             for(persector=0; persector<26; persector++){
  84.                 readSector(address+(persector*512), sectors[persector]);           
  85.             }      
  86.         }  
  87.     }
  88. }  
  89.  
  90. if(flag==0){
  91. printString("file cannot be found ");
  92. }
  93.  
  94. return;
  95. }
  96.  
  97.  
  98. void terminate(){
  99.  
  100. for(;;){
  101. }
  102. }
  103.  
  104.  
  105. void printString(char* string){
  106. int i = 0;
  107. char ch;
  108.  while (string[i] != '\0')
  109.    {
  110.     ch = string[i];
  111.     interrupt(0x10,0xe*256+ch,0,0,0);
  112.     if (ch == 13)
  113.     interrupt(0x10,0xe*0x100+10,0x0,0x0,0x0);
  114.     i++;
  115.    }
  116. return;
  117. }
  118.  
  119. void readString(char* line)
  120. {
  121.  int i = 0;
  122.  char ascii ;
  123.  while (ascii != 0xd)
  124.    {
  125.     ascii = interrupt(0x16, 0x0, 0x0, 0x0, 0x0);
  126.     line[i] = ascii;
  127.     interrupt(0x10,0xe*0x100+ascii,0x0,0x0,0x0);
  128.    
  129.     if (ascii == 13)
  130. interrupt(0x10,0xe*0x100+10,0x0,0x0,0x0);
  131.     i++;
  132. if (ascii == 0x8){
  133. interrupt(0x10,0xe*256+0x20,0x0,0x0,0x0);
  134. interrupt(0x10,0xe*256+0x8,0x0,0x0,0x0);
  135.  
  136. }
  137.    }
  138.  
  139.  *(line + i) = 0xa;
  140. i++;
  141.  *(line + i) = 0x0;
  142.  return ;
  143. }
  144.  
  145.  
  146. void readSector(char* buffer,int sector){
  147. int relativesector;
  148. int head;
  149. int track;
  150. int tmp1;
  151. int tmp2;
  152. tmp1=mod(sector,18);
  153. relativesector=tmp1+1;
  154. tmp2=div(sector,18);
  155. head = mod(tmp2,2);
  156. track = div(sector,36);
  157. interrupt(0x13,2*256+1,buffer,track*256+relativesector,head*256+0);
  158. return;
  159. }
  160.  
  161. int mod (int x, int y){
  162. int result;
  163. int tmp1;
  164. int tmp2;
  165. tmp1= div(x,y);
  166. tmp2=y*tmp1;
  167. result= x-tmp2;
  168. return result;
  169. }
  170.  
  171. int div(int x, int y) {
  172.     int result = 0;
  173. while(x>=y){
  174. x=x-y;
  175. result++;}
  176.  
  177.     return result;
  178. }
  179.  
  180. /*void handleInterrupt21(int ax, int bx, int cx, int dx){
  181.     printString("Hello World\0");
  182. }*/
  183. void handleInterrupt21(int ax, char* bx, int cx, int dx){
  184. if (ax==0){
  185.     printString(bx);
  186. }
  187. else {
  188.     if (ax==1){
  189.  
  190.      readString(bx);
  191.     }
  192.     else {
  193.         if (ax==2){
  194.             readSector(bx,cx);
  195.  
  196.         }
  197.         else {
  198.             if(ax==3){
  199.                 readFile(bx,cx);
  200.             } else{
  201.                 if(ax==4){
  202.                     executeProgram(bx, cx);
  203.                  } else {
  204.                 printString("error\0");
  205.     }
  206. }
  207. }
  208. return;
  209. }
  210. }
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement