home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1996 / ARCHIVE_96.iso / discs / mag_discs / volume_9 / issue_02 / weather / faxdisp < prev   
Text File  |  1995-07-04  |  2KB  |  109 lines

  1. /*  > c.faxdisp   */
  2. /*  sets up via, uses assembler (afax) to get data and display it */
  3. /*  no limit to amount of data, can be run off radio */
  4. /* set sampling freq. for pixels per line, 1000Hz and 500 pix/line */
  5.  
  6. #include "kernel.h"
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. #define pcr 0x0c
  11. #define acr 0x0b
  12. #define tmrlo 0x04
  13. #define tmrhi 0x05
  14. #define ifr 0x0d
  15.  
  16. /*  some subroutines to help the main program   */
  17.  
  18. void awrite(int offset,int value)
  19. /* writes 'value' to address 'offset' in VIA space */
  20.  
  21. {
  22.   _kernel_swi_regs point1,point2,*ptr1,*ptr2 ;
  23.   int code =0x80940 , pno=0 , block=0 ;
  24. ptr1=&point1;
  25. ptr2=&point2;
  26. point1.r[0]=pno;
  27. point1.r[1]=block;
  28. point1.r[2]=offset;
  29. point1.r[3]=value ;
  30. _kernel_swi(code,ptr1,ptr2) ;
  31.  
  32. }
  33.  
  34.  
  35. int aread(int offset)
  36. /* returns a value read from address 'offset' in VIA space */
  37.  
  38. {
  39.   _kernel_swi_regs point1,point2,*ptr1,*ptr2 ;
  40.   int code =0x80941,temp , pno=0 , block=0 ;
  41.   ptr1=&point1;
  42.   ptr2=&point2;
  43.   point1.r[0]=pno; 
  44.   point1.r[1]=block;
  45.   point1.r[2]=offset;
  46.   _kernel_swi(code,ptr1,ptr2) ; 
  47.   temp=point2.r[3] ; 
  48.   return temp ;
  49.  
  50. }
  51.  
  52.  
  53.  
  54. void sync()
  55. /* sets the timing mode for use of the expansion bus */
  56. /* with the 6522 VIA */
  57.  
  58. {
  59.   _kernel_swi_regs point1,point2,*ptr1,*ptr2 ;
  60.   int podno=0, code=0x80947;
  61.  
  62.   ptr1=&point1 ;
  63.   ptr2=&point2 ;
  64.   point1.r[0]=podno;
  65.   _kernel_swi(code,ptr1,ptr2);
  66. }
  67.  
  68. /* afax is defined  and color[] is used outside this program */
  69.  
  70. extern    void  afax(void)  ;
  71.           char  color[16] = {0xff,0xfe,0xfd,0xfc,
  72.                              0xd3,0xd2,0xd1,0xd0,
  73.                              0x2f,0x2e,0x2d,0x2c,
  74.                              0x03,0x02,0x01,0x00 } ;  
  75.  
  76.  
  77. int main()                     
  78. {
  79.   void awrite(int,int);
  80.   void sync(void) ;
  81.   void afax(void) ;
  82.   int aread(int);
  83.  
  84.   int value, value2, temp, ddra=3  ;
  85.   int porta=1,portb=0, ctrlo,ctrhi ;
  86.  
  87.   sync() ;
  88. /* set timer mode and request the sampling frequency  */
  89.   value=0xee ;
  90.   awrite(pcr,value) ; /* cb2 , ca2 high */
  91.   value=0xc0 ; 
  92.   awrite(acr,value);
  93.   printf("Sampling frequency, max. of 10 000Hz ");
  94.   scanf("%d",&value);
  95.   value2=1e6 /(value) ;
  96.   ctrlo=( value2 % 256)-2 ;
  97.   awrite(tmrlo,ctrlo);
  98.   ctrhi=value2 / 256 ;
  99.   awrite(tmrhi,ctrhi);  /* timer/clock now running */
  100.   printf("ctrlo=%d, ctrhi=%d\n",ctrlo,ctrhi) ;
  101.   temp=0;
  102.   awrite(ddra,temp);    /* port A input */
  103.   temp=aread(portb);
  104.   temp=aread(porta) ;           /* ensure ca1 is reset   */
  105.   afax() ;                      /* call the display program */
  106.  
  107. }
  108.  
  109.