home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / MEMORIA / EXTMOVE.ZIP / EXDEMO.C next >
Encoding:
C/C++ Source or Header  |  1987-02-09  |  3.4 KB  |  136 lines

  1. /*-------------------------------------------------------------*/
  2. /* DT , EXMOVE                                    Feb-5, 87    */
  3. /*                                                Uwe          */
  4. /*-------------------------------------------------------------*/
  5.  
  6. # include <dos.h>       /* segment abd offset information */
  7. # include <stdio.h>     /* file I/O */
  8. # include <conio.h>     /* I/O for ports */
  9.  
  10. # define MAXROWS 512    /* resolution of video frame */
  11. # define MAXCOLS 512
  12. # define MEMORYHI 0xA0
  13.  
  14. unsigned char huge Buffer[MAXROWS][MAXCOLS];
  15. unsigned int SegBuf;
  16. unsigned int OffBuf;
  17. unsigned int MemHi;
  18. unsigned int MemLo;
  19.  
  20.  
  21. main()
  22. {
  23.     ReadImage();
  24.     FillBuffer(0,0,128,128,255);
  25.     WriteImage();
  26.     StoreImage();
  27.     RetrieveImage();
  28. }
  29.  
  30.  
  31.  
  32. /*-------------------------------------------------------------*/
  33. GetMoveParam(RowBuf,ColBuf)
  34. unsigned int RowBuf,ColBuf;
  35.  
  36. {
  37.     char far *PtrBuf;
  38.  
  39.     PtrBuf = &Buffer[RowBuf][ColBuf];
  40.     SegBuf = FP_SEG(PtrBuf);
  41.     OffBuf = FP_OFF(PtrBuf);
  42.     MemHi  = MEMORYHI + (RowBuf >> 7);  /* divided by 128 */
  43.     MemLo  = OffBuf;
  44. }
  45. /*-------------------------------------------------------------*/
  46. ReadImage()
  47. {
  48.     unsigned int i;
  49.  
  50.     for (i=0; i<MAXROWS; i=i+128) {
  51.         GetMoveParam(i,0);
  52.         ext_to_conv(SegBuf,OffBuf,MemHi,MemLo,0xFFFF);
  53.     }
  54. }
  55. /*-------------------------------------------------------------*/
  56. WriteImage()
  57. {
  58.     unsigned int i;
  59.  
  60.     for (i=0; i<MAXROWS; i=i+128) {
  61.         GetMoveParam(i,0);
  62.         conv_to_ext(MemHi,MemLo,SegBuf,OffBuf,0xFFFF);
  63.     }
  64. }
  65. /*-------------------------------------------------------------*/
  66. FillBuffer(StartRow,StartCol,StopRow,StopCol,Value)
  67. unsigned int  StartRow,StartCol,StopRow,StopCol;
  68. unsigned char Value;
  69.  
  70. {
  71.     unsigned int i,j;
  72.     /*
  73.     printf("\nPlease insert 5 paramaters separated by blanks");
  74.     printf("\n/UpRow/UpCol/LoRow/LoCol/Pixel : ");
  75.     scanf("%u %u %u %u %u",&StartRow,&StartCol,
  76.                            &StopRow,&StopCol,&Value);
  77.     */
  78.  
  79.  
  80.  
  81.     for (i=StartRow; i<StopRow; i++)  {
  82.         for (j=StartCol; j<StopCol; j++)  {
  83.             Buffer[i][j] = Value;
  84.         }
  85.     }
  86. }
  87. /*-------------------------------------------------------------*/
  88. StoreImage()
  89. {
  90.     FILE *stream;
  91.     char Fname[20];
  92.     unsigned char Factor;
  93.     int i,j;
  94.  
  95.     /*
  96.     printf("\nPlease insert File Name :        ");
  97.     scanf("%s",Fname);
  98.     printf("\nPlease insert Reduction Factor : ");
  99.     scanf("%u",&Factor);
  100.     */
  101.     Factor = 8;
  102.  
  103.     stream = fopen("Test1.dt","w");
  104.     fputc(Factor,stream);
  105.     for (i=0; i<512; i=i+Factor)  {
  106.         for (j=0; j<512; j=j+Factor)  {
  107.             fputc(Buffer[i][j],stream);
  108.         }
  109.     }
  110.     fclose(stream);
  111. }
  112. /*-------------------------------------------------------------*/
  113. RetrieveImage()
  114. {
  115.     FILE *stream;
  116.     char Fname[20];
  117.     unsigned char Factor;
  118.     int i,j;
  119.     /*
  120.     printf("\nPlease insert File Name :        ");
  121.     scanf("%s",Fname);
  122.     */
  123.  
  124.     stream = fopen("test1.dt","r");
  125.     Factor = Fgetc(stream);
  126.     printf("\nReduction Factor : %u\n",Factor);
  127.     for (i=0; i<(512/Factor); i++)  {
  128.         for (j=0; j<(512/Factor); j++)  {
  129.             Buffer[i][j] = fgetc(stream);
  130.             printf("%4u ",Buffer[i][j]);
  131.         }
  132.     }
  133.     fclose(stream);
  134. }
  135. /*-------------------------------------------------------------*/
  136.