File: cpu_asm.c

package info (click to toggle)
atari800 0.9.8a-2
  • links: PTS
  • area: contrib
  • in suites: potato, slink
  • size: 1,844 kB
  • ctags: 3,008
  • sloc: ansic: 29,881; asm: 2,142; makefile: 78; sh: 8
file content (226 lines) | stat: -rw-r--r-- 5,008 bytes parent folder | download
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include	<stdio.h>
#include	<stdlib.h>
#ifdef ATARIST
#include	<osbind.h>
#endif

static char *rcsid = "$Id: cpu_asm.c,v 1.2 1998/02/21 15:02:46 david Exp $";

#define	FALSE	0
#define	TRUE	1

#include	"atari.h"
#include	"cpu_asm.h"
#include	"pia.h"
#include	"gtia.h"
#include	"sio.h"
#include	"pokey.h"
#include	"antic.h"


long CEKEJ;
extern UBYTE IRQ;
extern int wsync_halt;

extern UWORD break_addr;

/*
   ==========================================================
   Emulated Registers and Flags are kept local to this module
   ==========================================================
 */

#define	GetByte(addr)		((attrib[addr] == HARDWARE) ? Atari800_GetByte(addr) : memory[addr])
#define	PutByte(addr,byte)	if (attrib[addr] == RAM) memory[addr] = byte; else if (attrib[addr] == HARDWARE) if (Atari800_PutByte(addr,byte)) break;


#define RAM 0
#define ROM 1
#define HARDWARE 2
int count[256];

extern void tisk(void);
UBYTE memory[65536];

UBYTE attrib[65536];


/*
   ===============================================================
   Z flag: This actually contains the result of an operation which
   would modify the Z flag. The value is tested for
   equality by the BEQ and BNE instruction.
   ===============================================================
 */



UBYTE BCDtoDEC[256];
UBYTE DECtoBCD[256];

void CPU_Reset(void)
{
	int i;

	for (i = 0; i < 256; i++) {
		BCDtoDEC[i] = ((i >> 4) & 0xf) * 10 + (i & 0xf);
		DECtoBCD[i] = (((i % 100) / 10) << 4) | (i % 10);
#ifdef PROFILE
		count[i] = 0;
#endif
	}

	IRQ = 0x00;

	regP = 0x20;				/* The unused bit is always 1 */
	regS = 0xff;
	regPC = (GetByte(0xfffd) << 8) | GetByte(0xfffc);
}

 /*  it was there only for debug purposes.....
    #define PHP data =  (N & 0x80); \
    data |= V ? 0x40 : 0; \
    data |= (regP & 0x3c); \
    data |= (Z == 0) ? 0x02 : 0; \
    data |= C; \
    memory[0x0100 + S--] = data;

    void NMI (void)
    {
    UBYTE S = regS;
    UBYTE data;

    memory[0x0100 + S--] = regPC >> 8;
    memory[0x0100 + S--] = regPC & 0xff;
    memory[0x100 + S--] = regP;
    SetI;
    regPC = (memory[0xfffb] << 8) | memory[0xfffa];
    regS = S;
    }
  */

void SetRAM(int addr1, int addr2)
{
	int i;

	for (i = addr1; i <= addr2; i++) {
		attrib[i] = RAM;
	}
}

void SetROM(int addr1, int addr2)
{
	int i;

	for (i = addr1; i <= addr2; i++) {
		attrib[i] = ROM;
	}
}

void SetHARDWARE(int addr1, int addr2)
{
	int i;

	for (i = addr1; i <= addr2; i++) {
		attrib[i] = HARDWARE;
	}
}

UBYTE GETBYTE(UWORD addr)
{
	UBYTE byte;
/*
   ============================================================
   GTIA, POKEY, PIA and ANTIC do not fully decode their address
   ------------------------------------------------------------
   PIA (At least) is fully decoded when emulating the XL/XE
   ============================================================
 */
	switch (addr & 0xff00) {
	case 0xd000:				/* GTIA */
		byte = GTIA_GetByte(addr - 0xd000);
		break;
	case 0xd200:				/* POKEY */
		byte = POKEY_GetByte(addr - 0xd200);
		break;
	case 0xd300:				/* PIA */
		byte = PIA_GetByte(addr - 0xd300);
		break;
	case 0xd400:				/* ANTIC */
		byte = ANTIC_GetByte(addr - 0xd400);
		break;
	case 0xc000:				/* GTIA - 5200 */
		byte = GTIA_GetByte(addr - 0xc000);
		break;
	case 0xe800:				/* POKEY - 5200 */
		byte = POKEY_GetByte(addr - 0xe800);
		break;
	case 0xeb00:				/* POKEY - 5200 */
		byte = POKEY_GetByte(addr - 0xeb00);
		break;
	default:
		break;
	}

	return byte;
}

int PUTBYTE(UWORD addr, UBYTE byte)
{
	int abort = TRUE;			/*FALSE; */
/*
   ============================================================
   GTIA, POKEY, PIA and ANTIC do not fully decode their address
   ------------------------------------------------------------
   PIA (At least) is fully decoded when emulating the XL/XE
   ============================================================
 */
	switch (addr & 0xff00) {
	case 0xd000:				/* GTIA */
		abort = GTIA_PutByte(addr - 0xd000, byte);
		break;
	case 0xd200:				/* POKEY */
		abort = POKEY_PutByte(addr - 0xd200, byte);
		break;
	case 0xd300:				/* PIA */
		abort = PIA_PutByte(addr - 0xd300, byte);
		break;
	case 0xd400:				/* ANTIC */
		abort = ANTIC_PutByte(addr - 0xd400, byte);
		if (wsync_halt)
			abort = TRUE;
		break;
	case 0xd500:				/* Super Cartridges */
		abort = SuperCart_PutByte(addr, byte);
		break;
	case 0xc000:				/* GTIA - 5200 */
		abort = GTIA_PutByte(addr - 0xc000, byte);
		break;
	case 0xeb00:				/* POKEY - 5200 */
		abort = POKEY_PutByte(addr - 0xeb00, byte);
		break;
	default:
		break;
	}

	return abort;
}

void CPU_GetStatus(void)
{
	CPUGET();
}

void GenerateIRQ(void)
{
	IRQ = 1;
	GO(0);						/* does not execute any instruction */
}

void tisk(void)
{
	void *adresa = (long *) 0x400000;
	printf("OLD %d %d %d %d %d %d\n", *(UBYTE *) (adresa - 1), *(UBYTE *) (adresa - 2),
		   *(UBYTE *) (adresa - 3), *(UBYTE *) (adresa - 4), *(UBYTE *) (adresa - 5), *(UWORD *) (adresa - 8));
	printf("NEW %d %d %d %d %d %d\n", regP, regS, regA, regX, regY, regPC);
}