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

  1. /* TI-99/4A emulator memory access handler.
  2.    This part handles all memory read/write operations.
  3.    The memory is assumed to contain 32,768 words of 16 bits each.
  4.    The memory mapped devices will be hard-coded, and any access to them
  5.    will be initiated via this memory access handler.
  6. */
  7. int exbaspage=0;
  8.  
  9. void init_cpu(void)
  10. {
  11.     mem=(word *)calloc(CPU_MEMSIZE,1);
  12.     if (mem==NULL)
  13.     {
  14.         printf("Not enough memory for CPU ram\n");
  15.         exit(0);
  16.     }
  17. }
  18.  
  19. word memory_read(word adr)
  20. {
  21.     word address;
  22.  
  23.     address=adr>>1;                /* address is word oriented    */
  24.     if (paging&&(adr>=0x7000)&&(adr<0x8000)&&exbaspage) address+=0x1000;
  25.  
  26.     if ((adr<(word)0x8400)||(adr>=(word)0xA000))
  27.     {
  28.         if     (adr&1) return(*(mem+address)<<8);
  29.             else    return(*(mem+address));
  30.     }
  31.  
  32.     if ((adr&0x1c00)==0x0800)     return(vdp_read(address));
  33.     if ((adr&0x1c00)==0x1800)     return(grom_read(address));
  34.     return((word)0);    /* undecoded memory */
  35. }
  36.  
  37. void memory_write(word adr,word data)
  38. {
  39.     word     page,address;
  40.  
  41.     address=adr>>1;
  42.     page=adr>>13;
  43.  
  44.     if ((page==0)||(page==2)) return; /* write has no effect in ROM */
  45.  
  46.     if (paging&&(page==3))
  47.     {
  48.         if (adr<0x6004) exbaspage=address&1;
  49.         return;
  50.     }
  51.     if (!((page==4)&&(adr>=(word)0x8400)))
  52.     {
  53.         if (adr&1)
  54.         *(mem+address)=(*(mem+address)&0xFF00)|(data>>8);
  55.         else *(mem+address)=data;
  56.         return;
  57.     }
  58.  
  59.     if ((adr&0x1c00)==0x0c00) {  vdp_write(address,data); return; }
  60.     if ((adr&0x1c00)==0x1c00) { grom_write(address,data); return; }
  61.     if ((adr&0x1f00)==0x0400) { sound_access(data);          return; }
  62.  
  63. } /* end of memory_write() */
  64.  
  65. void vdp_interrupt(void)
  66. {
  67.     if (IMASK)
  68.     {
  69.         int val;
  70.  
  71.         /* Interrupt counter */
  72.  
  73.         val=*(mem+0x41bc);
  74.         *(mem+0x41bc)=(val&0xFF00)|((val+1)&0xFF);
  75.         sound_handler();
  76.     }
  77. }
  78.  
  79.