summaryrefslogtreecommitdiff
path: root/src/os9x_asm_cpu.c
blob: 2c920b72b501985aa8c8cb9bf112469b11a34a2b (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "snes9x.h"
#include "apu.h"
#include "ppu.h"
#include "cpuexec.h"
//#include "cpuops.h"

#include "os9x_asm_cpu.h"

//#define __debug_c_irq__
//#define __debug_c_nmi__
//#define __debug_c_hblank__
//#define __debug_c_io__

void asm_S9xSetPCBase(uint32 Address)
{
#ifdef __debug_c_setpc__
   printf("spcb\n");
#endif
   S9xSetPCBase(Address);
}


#ifdef _C_GW_
#define PushW(w) \
    S9xSetWord (w, Registers.S.W - 1);\
    Registers.S.W -= 2;
#define PushB(b)\
    S9xSetByte (b, Registers.S.W--);


void asm_S9xMainLoop(void)
{
   //S9xPackStatus();
   //printf("asmMainLoop Enter(0x%08x).\n", CPU.Flags);
   asmMainLoop(&CPU);
   //printf("asmMainLoop Exit(0x%08x, %d).\n", CPU.PC - CPU.PCBase, CPU.Cycles);
   //S9xUnpackStatus();
}

void asm_S9xDoHBlankProcessing(void)
{
#ifdef __debug_c_hblank__
   printf("hblank\n");
#endif
   // S9xUnpackStatus(); // not needed
   S9xDoHBlankProcessing();
   // S9xPackStatus();
}


uint8 asm_S9xGetByte(uint32 Address)
{
#ifdef __debug_c_io__
   printf("gb\n");
#endif
   return S9xGetByte(Address);
}

uint16 asm_S9xGetWord(uint32 Address)
{
#ifdef __debug_c_io__
   printf("gw\n");
#endif
   return S9xGetWord(Address);
}


void asm_S9xSetByte(uint32 Address, uint8 value)
{
#ifdef __debug_c_io__
   printf("sb\n");
#endif
   S9xSetByte(value, Address);
}

void asm_S9xSetWord(uint32 Address, uint16 value)
{
#ifdef __debug_c_io__
   printf("sw\n");
#endif
   S9xSetWord(value, Address);
}


void asm_S9xOpcode_NMI(void)
{
#ifdef __debug_c_nmi__
   printf("nmi\n");
#endif
   // S9xUnpackStatus(); // not needed

   if (!CheckEmulation())
   {
      PushB(Registers.PB);
      PushW(CPU.PC - CPU.PCBase);
      // S9xPackStatus ();
      PushB(Registers.PL);
      ClearDecimal();
      SetIRQ();

      Registers.PB = 0;
      // c = 0; // unused
#ifdef USE_SA1
      if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x20))
         S9xSetPCBase(Memory.FillRAM [0x220c] |
                      (Memory.FillRAM [0x220d] << 8));
      else
#endif
         S9xSetPCBase(S9xGetWord(0xFFEA));
#ifdef VAR_CYCLES
      CPU.Cycles += TWO_CYCLES;
#else
      CPU.Cycles += 8;
#endif
   }
   else
   {
      PushW(CPU.PC - CPU.PCBase);
      // S9xPackStatus (); // not needed
      PushB(Registers.PL);
      ClearDecimal();
      SetIRQ();

      Registers.PB = 0;
      // ICPU.ShiftedPB = 0; // unused
#ifdef USE_SA1
      if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x20))
         S9xSetPCBase(Memory.FillRAM [0x220c] |
                      (Memory.FillRAM [0x220d] << 8));
      else
#endif
         S9xSetPCBase(S9xGetWord(0xFFFA));
#ifdef VAR_CYCLES
      CPU.Cycles += ONE_CYCLE;
#else
      CPU.Cycles += 6;
#endif
   }

   // S9xPackStatus(); // not needed
}

void asm_S9xOpcode_IRQ(void)
{
#ifdef __debug_c_irq__
   printf("irq\n");
#endif
   // S9xUnpackStatus(); // not needed

   if (!CheckEmulation())
   {
      PushB(Registers.PB);
      PushW(CPU.PC - CPU.PCBase);
      // S9xPackStatus (); // not needed
      PushB(Registers.PL);
      ClearDecimal();
      SetIRQ();

      Registers.PB = 0;
      // ICPU.ShiftedPB = 0; // unused

#ifdef USE_SA1
      if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x40))
         S9xSetPCBase(Memory.FillRAM [0x220e] |
                      (Memory.FillRAM [0x220f] << 8));
      else
#endif
         S9xSetPCBase(S9xGetWord(0xFFEE));
#ifdef VAR_CYCLES
      CPU.Cycles += TWO_CYCLES;
#else
      CPU.Cycles += 8;
#endif
   }
   else
   {
      PushW(CPU.PC - CPU.PCBase);
      // S9xPackStatus (); // not needed
      PushB(Registers.PL);
      ClearDecimal();
      SetIRQ();

      Registers.PB = 0;
      // ICPU.ShiftedPB = 0; // unused

#ifdef USE_SA1
      if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x40))
         S9xSetPCBase(Memory.FillRAM [0x220e] |
                      (Memory.FillRAM [0x220f] << 8));
      else
#endif
         S9xSetPCBase(S9xGetWord(0xFFFE));
#ifdef VAR_CYCLES
      CPU.Cycles += ONE_CYCLE;
#else
      CPU.Cycles += 6;
#endif
   }

   // S9xPackStatus(); // not needed
}
#endif