home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / Geneve / 9640news / CAT36 / EMULSRC.ZIP / VDP.C < prev   
Text File  |  1993-04-21  |  2KB  |  102 lines

  1. /* TI-99/4A Emulator.
  2.  
  3.    VDP Emulator part.
  4.  
  5.    The adresses through which the VDP is addressed are:
  6.  
  7.    >8800:    VDP read data
  8.    >8802:    VDP read status
  9.    >8C00:    VDP write data
  10.    >8C02:    VDP write address
  11.  
  12.    These addresses are not fully decoded, so the same adressing is achieved
  13.    throughout the >8800..>8FFF area. (e.g. >8800=>8804=>8808=... etc.)
  14. */
  15.  
  16. void init_vdp(void)
  17. {
  18.     vdp=(byte *)calloc(VDP_MEMSIZE,1);
  19.     if (vdp==NULL)
  20.     {
  21.         printf("Not enough memory for VDP.\n");
  22.         exit(0);
  23.     }
  24.     VdpAddressCounter=0;
  25.     CRT_ROWS=24;
  26.     CRT_COLS=32;
  27.     CRT_SIZE=CRT_ROWS*CRT_COLS;
  28. }
  29.  
  30.  
  31. word vdp_read(word address)
  32. {
  33.     if(address&1)  /* VDP read status. */
  34.     return(DEFAULT_VDP_STATUS<<8);
  35.  
  36.  
  37.     else        /* VDP read data */
  38.     return(*(vdp+VdpAddressCounter++)<<8);
  39.  
  40. }
  41.  
  42. void vdp_write(word address,word data)
  43. {
  44.     static int VACparity=0;    /* retains the parity of the VDPWA actions */
  45.  
  46.     if (address&1)    /* write address (>8Cx2 addressed) */
  47.     {
  48.         VACparity=!VACparity;
  49.         VdpAddressCounter>>=8;
  50.         VdpAddressCounter|=(data&0xFF00);
  51.         if (!VACparity)
  52.         {
  53.             if (data&0x8000)
  54.                 vdp_write_to_register(VdpAddressCounter);
  55.             VdpAddressCounter&=0x3FFF;
  56.         }
  57.     }
  58.     else
  59.     {
  60.         byte vdpbyte;
  61.         vdpbyte=data>>8;
  62.         if ((VdpAddressCounter<CRT_SIZE)&&
  63.           (vdpbyte!=*(vdp+VdpAddressCounter))) update_crt(vdpbyte);
  64.         *(vdp+VdpAddressCounter++)=vdpbyte;
  65.     }
  66. }
  67.  
  68. void update_crt(byte data)
  69. {
  70.     byte ccode;
  71.  
  72.     ccode=data-((data>=126)? 96:0);    /* TI-BASIC offset */
  73.     if (ccode<31) ccode=219;
  74.     if ((ccode==0)||(ccode==31)) ccode=32;
  75.     print_at(    1+VdpAddressCounter%CRT_COLS,
  76.             1+(int)VdpAddressCounter/CRT_COLS,
  77.             ccode);
  78. }
  79.  
  80. void vdp_write_to_register(word regdata)
  81. {
  82.     int vdpregister,value;
  83.     vdpregister=(regdata>>8)&0x3F;
  84.     value=regdata&0xFF;
  85.     if (vdpregister==1)
  86.     {
  87.         value&=0x10;
  88.         if (value==0x10) CRT_COLS=40;
  89.         if (value==0)     CRT_COLS=32;
  90.         if (CRT_SIZE!=CRT_ROWS*CRT_COLS)
  91.         {
  92.             CRT_SIZE=CRT_ROWS*CRT_COLS;
  93.             clear_screen();
  94.             for(    VdpAddressCounter=0;
  95.                 VdpAddressCounter<CRT_SIZE;
  96.                 VdpAddressCounter++)
  97.                 update_crt(*(vdp+VdpAddressCounter));
  98.         }
  99.  
  100.     }
  101. }
  102.