summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/compile/20071114-1.c
blob: ddfbfefff4599759083e96f334d7bb7c80440b54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* PR tree-optimization/34046 */
/* Origin: dcb <dcb314@hotmail.com> */

typedef unsigned char bool8;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;

struct SIAPU
{
    uint8 *PC;
    uint8 *RAM;
    uint8 Bit;
    uint32 Address;
    uint8 *WaitAddress1;
    uint8 *WaitAddress2;
    uint8 _Carry;
};

struct SAPU
{
    bool8 ShowROM;
    uint8 OutPorts [4];
    uint8 ExtraRAM [64];
    uint16 TimerTarget [3];
};

struct SAPU APU;
struct SIAPU IAPU;

void S9xSetAPUControl (uint8 byte);
void S9xSetAPUDSP (uint8 byte);
uint8 S9xGetAPUDSP ();

uint8 S9xAPUGetByte (uint32 Address)
{
  Address &= 0xffff;

  if (Address <= 0xff && Address >= 0xf0)
    {
      if (Address >= 0xf4 && Address <= 0xf7)
	{
	  IAPU.WaitAddress2 = IAPU.WaitAddress1;
	  IAPU.WaitAddress1 = IAPU.PC;
	  return (IAPU.RAM [Address]);
	}
      else if (Address == 0xf3)
	return (S9xGetAPUDSP ());

      if (Address >= 0xfd)
	{
	  IAPU.WaitAddress2 = IAPU.WaitAddress1;
	  IAPU.WaitAddress1 = IAPU.PC;
	  uint8 t = IAPU.RAM [Address];
	  IAPU.RAM [Address] = 0;
	  return (t);
	}

      return (IAPU.RAM [Address]);
    }
 else
   return (IAPU.RAM [Address]);
}

void S9xAPUSetByte (uint8 byte, uint32 Address)
{
  Address &= 0xffff;

  if (Address <= 0xff && Address >= 0xf0)
    {
      if (Address == 0xf3)
	S9xSetAPUDSP (byte);
      else if (Address >= 0xf4 && Address <= 0xf7)
	APU.OutPorts [Address - 0xf4] = byte;
      else if (Address == 0xf1)
	S9xSetAPUControl (byte);
      else if (Address < 0xfd)
	{
	  IAPU.RAM [Address] = byte;
	  if (Address >= 0xfa)
	    {
	      if (byte == 0)
		APU.TimerTarget [Address - 0xfa] = 0x100;
	      else
		APU.TimerTarget [Address - 0xfa] = byte;
	    }
	}
    }
  else
    {
      if (Address < 0xffc0)
	IAPU.RAM [Address] = byte;
      else
	{
	  APU.ExtraRAM [Address - 0xffc0] = byte;
	  if (!APU.ShowROM)
	    IAPU.RAM [Address] = byte;
	}
    }
}

void ApuCA ()
{
  IAPU.Address = *(uint16 *) (IAPU.PC + 1);
  IAPU.Bit = (uint8)(IAPU.Address >> 13);
  if ((IAPU._Carry))
    S9xAPUSetByte (S9xAPUGetByte (IAPU.Address) | (1 << IAPU.Bit), IAPU.Address);
  else
    S9xAPUSetByte (S9xAPUGetByte (IAPU.Address) & ~(1 << IAPU.Bit), IAPU.Address);
}