]> git.sur5r.net Git - cc65/blob - include/6502.h
f95df48050d8cfdc1b2da2abb50510e6ac231101
[cc65] / include / 6502.h
1 /*
2  * 6502.h
3  *
4  * Ullrich von Bassewitz, 20.09.1998
5  */
6
7
8
9 #ifndef _6502_H
10 #define _6502_H
11
12
13
14 /* Possible returns of getcpu() */
15 #define CPU_6502        0
16 #define CPU_65C02       1
17 #define CPU_65816       2
18
19 unsigned char getcpu (void);
20 /* Detect the CPU the program is running on */
21
22
23
24 /* Macros for CPU instructions */
25 #define BRK()   __asm__ ("\tbrk")
26 #define CLI()   __asm__ ("\tcli")
27 #define SEI()   __asm__ ("\tsei")
28
29
30
31 /* Struct that holds the registers for the sys function */
32 struct regs {
33     unsigned char a;            /* A register value */
34     unsigned char x;            /* X register value */
35     unsigned char y;            /* Y register value */
36     unsigned char flags;        /* Flags value */
37     unsigned      pc;           /* Program counter */
38 };
39
40 /* Defines for the flags in the regs structure */
41 #define F_NEG           0x80    /* N flag */
42 #define F_OVF           0x40    /* V flag */
43 #define F_BRK           0x10    /* B flag */
44 #define F_DEC           0x08    /* D flag */
45 #define F_IEN           0x04    /* I flag */
46 #define F_ZERO          0x02    /* Z flag */
47 #define F_CARRY         0x01    /* C flag */
48
49 /* Function to call any machine language subroutine. All registers in the
50  * regs structure are passed into the routine and the results are passed
51  * out. Some of the flags are ignored on input. The called routine must
52  * end with an RTS.
53  */
54 void __fastcall__ _sys (struct regs* r);
55
56
57
58 /* Set and reset the break vector. The given user function is called if
59  * a break occurs. The values of the registers may be read from the brk_...
60  * variables. The value in brk_pc will point to the address that contains
61  * the brk instruction.
62  * The set_brk function will install an exit handler that will reset the
63  * vector if the program ends.
64  */
65
66 extern unsigned char brk_a;     /* A register value */
67 extern unsigned char brk_x;     /* X register value */
68 extern unsigned char brk_y;     /* Y register value */
69 extern unsigned char brk_sr;    /* Status register */
70 extern unsigned brk_pc;         /* PC value */
71
72 typedef void (*brk_handler) (void);
73 /* Type of the break handler */
74
75 void __fastcall__ set_brk (brk_handler f);
76 /* Set the break vector to the given address, return the old address */
77
78 void reset_brk (void);
79 /* Reset the break vector to the original value */
80
81
82
83 /* End of 6502.h */
84 #endif
85
86
87