llvm-mos-sdk
mega65.h
Go to the documentation of this file.
1 // Copyright 2023 LLVM-MOS Project
2 // Licensed under the Apache License, Version 2.0 with LLVM Exceptions.
3 // See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
4 // information.
5 
6 #ifndef _MEGA65_H
7 #define _MEGA65_H
8 
9 #include <stdint.h>
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #ifdef __clang__
16 #pragma clang diagnostic push
17 #pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
18 #pragma clang diagnostic ignored "-Wnested-anon-types"
19 #pragma clang diagnostic ignored "-Wgnu-binary-literal"
20 #pragma clang diagnostic ignored "-Wfixed-enum-extension"
21 #endif
22 
23 #include <_45E100.h>
24 #include <_6526.h>
25 #include <_dmagic.h>
26 #include <_sid.h>
27 #include <_vic2.h>
28 #include <_vic3.h>
29 #include <_vic4.h>
30 
32 struct __hypervisor {
33  union {
34  uint8_t htrap[64];
35  struct {
37  uint8_t rega; // 0xD640
39  uint8_t regx; // 0xD641
40  uint8_t unused1; // 0xD642
42  uint8_t regz; // 0xD643
44  uint8_t regb; // 0xD644
46  uint8_t spl; // 0xD645
48  uint8_t sph; // 0xD646
50  uint8_t pflags; // 0xD647
52  uint8_t pcl; // 0xD648
54  uint8_t pch; // 0xD649
55  uint8_t maplo1; // 0xD64A
56  uint8_t maplo2; // 0xD64B
57  uint8_t maphi1; // 0xD64C
58  uint8_t maphi2; // 0xD64D
59  uint8_t maplomb; // 0xD64E
60  uint8_t maphimb; // 0xD64F
62  uint8_t port00; // 0xD650
64  uint8_t port01; // 0xD651
65  uint8_t vicmode; // 0xD652
66  uint8_t dma_src_mb; // 0xD653
68  uint8_t dma_dst_hb; // 0xD654
70  uint32_t dmaladdr; // 0xD655
71  uint8_t vflop; // 0xD659
72  uint8_t unused2[22]; // 0xD65A
74  uint8_t georambase; // 0xD670
76  uint8_t georammask; // 0xD671
79  uint8_t matrixen; // 0xD672
80  uint8_t unused3[9]; // 0xD673
82  uint8_t uartdata; // 0xD67C
83  uint8_t watchdog; // 0xD67D
85  uint8_t hicked; // 0xD67E
87  uint8_t enterexit; // 0xD67F
88  };
89  };
90 };
91 #ifdef __cplusplus
92 static_assert(sizeof(struct __hypervisor) == 64);
93 #endif
94 
96 struct __cpu_math {
97  union {
98  uint8_t divout_fract8;
99  uint16_t divout_fract16;
100  uint32_t divout_fract32;
101  };
102  union {
103  uint8_t divout_whole8;
104  uint16_t divout_whole16;
105  uint32_t divout_whole32;
106  };
107  union {
108  uint8_t multina8;
109  uint16_t multina16;
110  uint32_t multina32;
111  };
112  union {
113  uint8_t multinb8;
114  uint16_t multinb16;
115  uint32_t multinb32;
116  };
118  union {
119  uint8_t multout8;
120  uint16_t multout16;
121  uint32_t multout32;
122 #ifdef __clang__
123  uint64_t multout64;
124 #endif
125  uint8_t multout[8];
126  };
127  uint32_t mathin[16];
128 };
129 #ifdef __cplusplus
130 static_assert(sizeof(__cpu_math) == 88);
131 #endif
132 
134 struct __color_palette {
135  uint8_t red[256];
136  uint8_t green[256];
137  uint8_t blue[256];
138 };
139 
141 #define CPU_PORTDDR (*(volatile uint8_t *)0x0000)
142 #define CPU_PORT (*(volatile uint8_t *)0x0001)
144 #define DEFAULT_SCREEN (*(volatile uint8_t *)0x0800)
146 #define VICII (*(volatile struct __vic2 *)0xd000)
148 #define VICIV (*(volatile struct __vic4 *)0xd000)
150 #define PALETTE (*(volatile struct __color_palette *)0xd100)
152 #define SID1 (*(volatile struct __sid *)0xd400)
154 #define SID2 (*(volatile struct __sid *)0xd420)
156 #define SID3 (*(volatile struct __sid *)0xd440)
158 #define SID4 (*(volatile struct __sid *)0xd460)
160 #define SIDMODE (*(volatile uint8_t *)0xd63c)
162 #define HYPERVISOR (*(volatile struct __hypervisor *)0xd640)
164 #define ETHERNET (*(volatile struct __45E100 *)0xd6e0)
166 #define DMA (*(volatile struct DMAgicController *)0xd700)
168 #define MATHBUSY (*(volatile uint8_t *)0xd70f)
170 #define MATH (*(volatile struct __cpu_math *)0xd768)
172 #define CIA1 (*(volatile struct __6526 *)0xdc00)
174 #define CIA2 (*(volatile struct __6526 *)0xdd00)
176 
178 enum
179 #ifdef __clang__
180  : uint8_t
181 #endif
182 {
183  COLOR_BLACK = 0x00,
184  COLOR_WHITE = 0x01,
185  COLOR_RED = 0x02,
186  COLOR_CYAN = 0x03,
187  COLOR_PURPLE = 0x04,
188  COLOR_GREEN = 0x05,
189  COLOR_BLUE = 0x06,
190  COLOR_YELLOW = 0x07,
191  COLOR_ORANGE = 0x08,
192  COLOR_BROWN = 0x09,
201  COLOR_CARROT = 0x12,
203  COLOR_PANDAN = 0x14,
208  COLOR_SEASKY = 0x19,
215 };
216 
217 #ifdef __clang__
218 #pragma clang diagnostic pop
219 #endif
220 
221 #ifdef __cplusplus
222 } // extern block
223 #endif
224 #endif // _MEGA65_H
_45E100.h
COLOR_DARKGREY
@ COLOR_DARKGREY
Definition: mega65.h:194
std::uint16_t
::uint16_t uint16_t
Definition: cstdint:22
COLOR_PANDAN
@ COLOR_PANDAN
Definition: mega65.h:203
_sid.h
COLOR_SEASKY
@ COLOR_SEASKY
Definition: mega65.h:208
COLOR_LEMONTART
@ COLOR_LEMONTART
Definition: mega65.h:202
COLOR_CARROT
@ COLOR_CARROT
Definition: mega65.h:201
COLOR_ORANGE
@ COLOR_ORANGE
Definition: mega65.h:191
COLOR_GURUMEDITATION
@ COLOR_GURUMEDITATION
Definition: mega65.h:199
COLOR_GREEN
@ COLOR_GREEN
Definition: mega65.h:188
COLOR_BUBBLEGUM
@ COLOR_BUBBLEGUM
Definition: mega65.h:213
std::uint8_t
::uint8_t uint8_t
Definition: cstdint:21
COLOR_SEASICKGREEN
@ COLOR_SEASICKGREEN
Definition: mega65.h:204
COLOR_SOYLENTGREEN
@ COLOR_SOYLENTGREEN
Definition: mega65.h:205
COLOR_BLACK
@ COLOR_BLACK
Definition: mega65.h:183
COLOR_PURPLE
@ COLOR_PURPLE
Definition: mega65.h:187
_vic3.h
COLOR_HOTTAMALES
@ COLOR_HOTTAMALES
Definition: mega65.h:214
COLOR_SLIMERGREEN
@ COLOR_SLIMERGREEN
Definition: mega65.h:206
COLOR_LIGHTGREEN
@ COLOR_LIGHTGREEN
Definition: mega65.h:196
COLOR_BROWN
@ COLOR_BROWN
Definition: mega65.h:192
COLOR_THEOTHERCYAN
@ COLOR_THEOTHERCYAN
Definition: mega65.h:207
COLOR_MIDGREY
@ COLOR_MIDGREY
Definition: mega65.h:195
COLOR_LIGHTBLUE
@ COLOR_LIGHTBLUE
Definition: mega65.h:197
COLOR_SMURFBLUE
@ COLOR_SMURFBLUE
Definition: mega65.h:209
_vic4.h
_dmagic.h
COLOR_BLUE
@ COLOR_BLUE
Definition: mega65.h:189
_6526.h
COLOR_RED
@ COLOR_RED
Definition: mega65.h:185
COLOR_SOURGRAPE
@ COLOR_SOURGRAPE
Definition: mega65.h:212
std::uint64_t
::uint64_t uint64_t
Definition: cstdint:24
COLOR_PLUMSAUCE
@ COLOR_PLUMSAUCE
Definition: mega65.h:211
COLOR_LIGHTRED
@ COLOR_LIGHTRED
Definition: mega65.h:193
COLOR_YELLOW
@ COLOR_YELLOW
Definition: mega65.h:190
std::uint32_t
::uint32_t uint32_t
Definition: cstdint:23
COLOR_CYAN
@ COLOR_CYAN
Definition: mega65.h:186
_vic2.h
COLOR_LIGHTGREY
@ COLOR_LIGHTGREY
Definition: mega65.h:198
COLOR_WHITE
@ COLOR_WHITE
Definition: mega65.h:184
COLOR_SCREENOFDEATH
@ COLOR_SCREENOFDEATH
Definition: mega65.h:210
COLOR_RAMBUTAN
@ COLOR_RAMBUTAN
Definition: mega65.h:200