home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Emulation / Atari800 / piaold.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  6KB  |  294 lines

  1. #include <stdio.h>
  2.  
  3. #include "atari.h"
  4. #include "cpu.h"
  5. #include "pia.h"
  6. #include "platform.h"
  7.  
  8. #define FALSE 0
  9. #define TRUE 1
  10.  
  11. static char *rcsid = "$Id: pia.c,v 1.10 1997/03/31 09:34:33 david Exp $";
  12.  
  13. UBYTE PACTL;
  14. UBYTE PBCTL;
  15. UBYTE PORTA;
  16. UBYTE PORTB;
  17.  
  18. int xe_bank = -1;
  19.  
  20. int rom_inserted;
  21. UBYTE atari_basic[8192];
  22. UBYTE atarixl_os[16384];
  23. static UBYTE under_atari_basic[8192];
  24. static UBYTE under_atarixl_os[16384];
  25. static UBYTE atarixe_memory[65536];
  26. static UBYTE atarixe_16kbuffer[16384];
  27.  
  28. static UBYTE PORTA_mask = 0xff;
  29. static UBYTE PORTB_mask = 0xff;
  30.  
  31. void PIA_Initialise (int *argc, char *argv[])
  32. {
  33.   PORTA = 0xff;
  34.   PORTB = 0xff;
  35. }
  36.  
  37. UBYTE PIA_GetByte (UWORD addr)
  38. {
  39.   UBYTE byte;
  40.  
  41.   if (machine == Atari)
  42.     addr &= 0xff03;
  43.   switch (addr)
  44.     {
  45.     case _PACTL :
  46.       byte = PACTL;
  47.       break;
  48.     case _PBCTL :
  49.       byte = PBCTL;
  50. #ifdef DEBUG1
  51.       printf ("RD: PBCTL = %x, PC = %x\n", PBCTL, PC);
  52. #endif
  53.       break;
  54.     case _PORTA :
  55.       byte = Atari_PORT (0);
  56.       byte &= PORTA_mask;
  57.       break;
  58.     case _PORTB :
  59.       switch (machine)
  60.     {
  61.     case Atari :
  62.       byte = Atari_PORT (1);
  63.           byte &= PORTB_mask;
  64.       break;
  65.     case AtariXL :
  66.     case AtariXE :
  67.       byte = PORTB;
  68.       byte &= PORTB_mask;
  69.       break;
  70.     default :
  71.       printf ("Fatal Error in pia.c: PIA_GetByte(): Unknown machine\n");
  72.       Atari800_Exit (FALSE);
  73.       exit (1);
  74.       break;
  75.     }
  76.       break;
  77.     }
  78.  
  79.   return byte;
  80. }
  81.  
  82. int PIA_PutByte (UWORD addr, UBYTE byte)
  83. {
  84.   if (machine == Atari)
  85.     addr &= 0xff03;
  86.  
  87.   switch (addr)
  88.     {
  89.     case _PACTL :
  90.       PACTL = byte;
  91.       break;
  92.     case _PBCTL :
  93.       PBCTL = byte;
  94. #ifdef DEBUG1
  95.       printf ("WR: PBCTL = %x, PC = %x\n", PBCTL, PC);
  96. #endif
  97.       break;
  98.     case _PORTA :
  99.       if (!(PACTL & 0x04))
  100.         PORTA_mask = ~byte;
  101.       break;
  102.     case _PORTB :          
  103.       if (!(PBCTL & 0x04)) {
  104.     PORTB_mask = ~byte;
  105.     break;
  106.       }
  107.       switch (machine) {
  108.     case Atari :
  109.       break;
  110.     case AtariXE :
  111.       {
  112.         int cpu_flag = (byte & 0x10);
  113. #ifdef DEBUG
  114.         int antic_flag = (byte & 0x20);
  115. #endif
  116.         int bank = (byte & 0x0c) >> 2;
  117.  
  118. #ifdef DEBUG
  119.         printf ("CPU = %d, ANTIC = %d, XE BANK = %d\n",
  120.             cpu_flag, antic_flag, bank);
  121. #endif
  122.  
  123. /*
  124.  * Possible Bank Transitions
  125.  *
  126.  * Main        -> Main
  127.  * Main        -> Bank1,2,3,4
  128.  * Bank1,2,3,4 -> Main
  129.  * Bank1,2,3,4 -> Bank1,2,3,4
  130.  */
  131.         if (cpu_flag)
  132.           {
  133.         if (xe_bank != -1)
  134.           {
  135.             memcpy (&atarixe_memory[xe_bank*16384],
  136.                 &memory[0x4000],
  137.                 16384);
  138.             memcpy (&memory[0x4000], atarixe_16kbuffer, 16384);
  139.             xe_bank = -1;
  140.           }
  141.           }
  142.         else if (bank != xe_bank)
  143.           {
  144.         if (xe_bank == -1)
  145.           {
  146.             memcpy (atarixe_16kbuffer,
  147.                 &memory[0x4000],
  148.                 16384);
  149.           }
  150.         else
  151.           {
  152.             memcpy (&atarixe_memory[xe_bank*16384],
  153.                 &memory[0x4000],
  154.                 16384);
  155.           }
  156.  
  157.         memcpy (&memory[0x4000],
  158.             &atarixe_memory[bank*16384],
  159.             16384);
  160.         xe_bank = bank;
  161.           }
  162.       }
  163.     case AtariXL :
  164. #ifdef DEBUG
  165.       printf ("Storing %x to PORTB, PC = %x\n", byte, regPC);
  166. #endif
  167. /*
  168.  * Enable/Disable OS ROM 0xc000-0xcfff and 0xd800-0xffff
  169.  */
  170. /*
  171.       if (!(PORTB & 0x01))
  172.         {
  173.           memcpy (under_atarixl_os, memory+0xc000, 0x1000);
  174.           memcpy (under_atarixl_os+0x1800, memory+0xd800, 0x2800);
  175.         }
  176. */
  177.       if (byte & 0x01)
  178.         {
  179. #ifdef DEBUG
  180.           printf ("OS ROM Enabled\n");
  181. #endif
  182.           if (!(PORTB & 0x01)) {
  183.         memcpy (under_atarixl_os,memory+0xc000,0x1000);
  184.         memcpy (under_atarixl_os+0x1800,memory+0xd800,0x2800);
  185.         memcpy (memory+0xc000, atarixl_os, 0x1000);
  186.         memcpy (memory+0xd800, atarixl_os+0x1800, 0x2800);
  187.         SetROM (0xc000, 0xcfff);
  188.         SetROM (0xd800, 0xffff);
  189.           }
  190.         }
  191.       else
  192.         {
  193. #ifdef DEBUG
  194.           printf ("OS ROM Disabled\n");
  195. #endif
  196.           if (PORTB & 0x01) {
  197.         memcpy (memory+0xc000, under_atarixl_os, 0x1000);
  198.         memcpy (memory+0xd800, under_atarixl_os+0x1800, 0x2800);
  199.         SetRAM (0xc000, 0xcfff);
  200.         SetRAM (0xd800, 0xffff);
  201.           }
  202.         }
  203. /*
  204.     =====================================
  205.     An Atari XL/XE can only disable Basic
  206.     Other cartridge cannot be disable
  207.     =====================================
  208. */
  209.       if (!rom_inserted)
  210.         {
  211. /*
  212.  * If RAM is currently enabled between 0xa000 and
  213.  * 0xbfff then under_atari_basic is updated
  214.  */
  215.  
  216. /*
  217.           if (PORTB & 0x02)
  218.         {
  219.           memcpy (under_atari_basic, memory+0xa000, 0x2000);
  220.         }
  221. */
  222.  
  223. /*
  224.  * Enable/Disable BASIC ROM
  225.  */
  226.           if (byte & 0x02)
  227.         {
  228. #ifdef DEBUG
  229.           printf ("BASIC disabled\n");
  230. #endif
  231.           if (!(PORTB & 0x02)) {
  232.             memcpy (memory+0xa000, under_atari_basic, 0x2000);
  233.             SetRAM (0xa000, 0xbfff);
  234.           }
  235.         }
  236.           else
  237.         {
  238. #ifdef DEBUG
  239.           printf ("BASIC enabled\n");
  240. #endif
  241.           if (PORTB & 0x02) {
  242.             memcpy (under_atari_basic,memory+0xa000,0x2000);
  243.             memcpy (memory+0xa000, atari_basic, 0x2000);
  244.             SetROM (0xa000, 0xbfff);
  245.           }
  246.         }
  247.         }
  248. /*
  249.  * Enable/Disable Self Test ROM
  250.  */
  251.  
  252. /*
  253.       if (PORTB & 0x80)
  254.         {
  255.           memcpy (under_atarixl_os+0x1000, memory+0x5000, 0x800);
  256.         }
  257. */
  258.  
  259.       if (byte & 0x80)
  260.         {
  261. #ifdef DEBUG
  262.           printf ("Self Test ROM Disabled\n");
  263. #endif
  264.           if (!(PORTB & 0x80)) {
  265.         memcpy (memory+0x5000, under_atarixl_os+0x1000, 0x800);
  266.         SetRAM (0x5000, 0x57ff);
  267.           }
  268.         }
  269.       else
  270.         {
  271. #ifdef DEBUG
  272.           printf ("Self Test ROM Enabled\n");
  273. #endif
  274.           if (PORTB & 0x80) {
  275.         memcpy (under_atarixl_os+0x1000,memory+0x5000,0x800);
  276.         memcpy (memory+0x5000, atarixl_os+0x1000, 0x800);
  277.         SetROM (0x5000, 0x57ff);
  278.           }
  279.         }
  280.  
  281.       PORTB = byte;
  282.       break;
  283.     default :
  284.       printf ("Fatal Error in pia.c: PIA_PutByte(): Unknown machine\n");
  285.       Atari800_Exit (FALSE);
  286.       exit (1);
  287.       break;
  288.     }
  289.       break;
  290.     }
  291.  
  292.   return FALSE;
  293. }
  294.