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 <_sid.h>
26 #include <_vic2.h>
27 #include <_vic3.h>
28 #include <_vic4.h>
29 
31 struct __hypervisor {
32  union {
33  uint8_t htrap[64];
34  struct {
36  uint8_t rega; // 0xD640
38  uint8_t regx; // 0xD641
39  uint8_t unused1; // 0xD642
41  uint8_t regz; // 0xD643
43  uint8_t regb; // 0xD644
45  uint8_t spl; // 0xD645
47  uint8_t sph; // 0xD646
49  uint8_t pflags; // 0xD647
51  uint8_t pcl; // 0xD648
53  uint8_t pch; // 0xD649
54  uint8_t maplo1; // 0xD64A
55  uint8_t maplo2; // 0xD64B
56  uint8_t maphi1; // 0xD64C
57  uint8_t maphi2; // 0xD64D
58  uint8_t maplomb; // 0xD64E
59  uint8_t maphimb; // 0xD64F
61  uint8_t port00; // 0xD650
63  uint8_t port01; // 0xD651
64  uint8_t vicmode; // 0xD652
65  uint8_t dma_src_mb; // 0xD653
67  uint8_t dma_dst_hb; // 0xD654
69  uint32_t dmaladdr; // 0xD655
70  uint8_t vflop; // 0xD659
71  uint8_t unused2[22]; // 0xD65A
73  uint8_t georambase; // 0xD670
75  uint8_t georammask; // 0xD671
78  uint8_t matrixen; // 0xD672
79  uint8_t unused3[9]; // 0xD673
81  uint8_t uartdata; // 0xD67C
82  uint8_t watchdog; // 0xD67D
84  uint8_t hicked; // 0xD67E
86  uint8_t enterexit; // 0xD67F
87  };
88  };
89 };
90 #ifdef __cplusplus
91 static_assert(sizeof(struct __hypervisor) == 64);
92 #endif
93 
95 struct __cpu_math {
96  union {
97  uint8_t divout_fract8;
98  uint16_t divout_fract16;
99  uint32_t divout_fract32;
100  };
101  union {
102  uint8_t divout_whole8;
103  uint16_t divout_whole16;
104  uint32_t divout_whole32;
105  };
106  union {
107  uint8_t multina8;
108  uint16_t multina16;
109  uint32_t multina32;
110  };
111  union {
112  uint8_t multinb8;
113  uint16_t multinb16;
114  uint32_t multinb32;
115  };
117  union {
118  uint8_t multout8;
119  uint16_t multout16;
120  uint32_t multout32;
121 #ifdef __clang__
122  uint64_t multout64;
123 #endif
124  uint8_t multout[8];
125  };
126  uint32_t mathin[16];
127 };
128 #ifdef __cplusplus
129 static_assert(sizeof(__cpu_math) == 88);
130 #endif
131 
133 struct __color_palette {
134  uint8_t red[256];
135  uint8_t green[256];
136  uint8_t blue[256];
137 };
138 
140 #define CPU_PORTDDR (*(volatile uint8_t *)0x0000)
141 #define CPU_PORT (*(volatile uint8_t *)0x0001)
143 #define DEFAULT_SCREEN (*(volatile uint8_t *)0x0800)
145 #define VICII (*(volatile struct __vic2 *)0xd000)
147 #define VICIV (*(volatile struct __vic4 *)0xd000)
149 #define PALETTE (*(volatile struct __color_palette *)0xd100)
151 #define SID1 (*(volatile struct __sid *)0xd400)
153 #define SID2 (*(volatile struct __sid *)0xd420)
155 #define SID3 (*(volatile struct __sid *)0xd440)
157 #define SID4 (*(volatile struct __sid *)0xd460)
159 #define SIDMODE (*(volatile uint8_t *)0xd63c)
161 #define HYPERVISOR (*(volatile struct __hypervisor *)0xd640)
163 #define ETHERNET (*(volatile struct __45E100 *)0xd6e0)
165 #define MATHBUSY (*(volatile uint8_t *)0xd70f)
167 #define MATH (*(volatile struct __cpu_math *)0xd768)
169 #define CIA1 (*(volatile struct __6526 *)0xdc00)
171 #define CIA2 (*(volatile struct __6526 *)0xdd00)
173 
175 enum
176 #ifdef __clang__
177  : uint8_t
178 #endif
179 {
180  COLOR_BLACK = 0x00,
181  COLOR_WHITE = 0x01,
182  COLOR_RED = 0x02,
183  COLOR_CYAN = 0x03,
184  COLOR_PURPLE = 0x04,
185  COLOR_GREEN = 0x05,
186  COLOR_BLUE = 0x06,
187  COLOR_YELLOW = 0x07,
188  COLOR_ORANGE = 0x08,
189  COLOR_BROWN = 0x09,
198  COLOR_CARROT = 0x12,
200  COLOR_PANDAN = 0x14,
205  COLOR_SEASKY = 0x19,
212 };
213 
214 #ifdef __clang__
215 #pragma clang diagnostic pop
216 #endif
217 
218 #ifdef __cplusplus
219 } // extern block
220 #endif
221 #endif // _MEGA65_H
COLOR_SMURFBLUE
@ COLOR_SMURFBLUE
Definition: mega65.h:206
_45E100.h
std::uint16_t
::uint16_t uint16_t
Definition: cstdint:22
_sid.h
COLOR_BROWN
@ COLOR_BROWN
Definition: mega65.h:189
COLOR_SOURGRAPE
@ COLOR_SOURGRAPE
Definition: mega65.h:209
COLOR_PANDAN
@ COLOR_PANDAN
Definition: mega65.h:200
COLOR_GREEN
@ COLOR_GREEN
Definition: mega65.h:185
COLOR_THEOTHERCYAN
@ COLOR_THEOTHERCYAN
Definition: mega65.h:204
std::uint8_t
::uint8_t uint8_t
Definition: cstdint:21
COLOR_GURUMEDITATION
@ COLOR_GURUMEDITATION
Definition: mega65.h:196
COLOR_PLUMSAUCE
@ COLOR_PLUMSAUCE
Definition: mega65.h:208
COLOR_YELLOW
@ COLOR_YELLOW
Definition: mega65.h:187
COLOR_LIGHTGREEN
@ COLOR_LIGHTGREEN
Definition: mega65.h:193
COLOR_HOTTAMALES
@ COLOR_HOTTAMALES
Definition: mega65.h:211
_vic3.h
COLOR_LIGHTBLUE
@ COLOR_LIGHTBLUE
Definition: mega65.h:194
COLOR_SEASICKGREEN
@ COLOR_SEASICKGREEN
Definition: mega65.h:201
COLOR_SEASKY
@ COLOR_SEASKY
Definition: mega65.h:205
COLOR_MIDGREY
@ COLOR_MIDGREY
Definition: mega65.h:192
COLOR_DARKGREY
@ COLOR_DARKGREY
Definition: mega65.h:191
COLOR_RED
@ COLOR_RED
Definition: mega65.h:182
COLOR_BLUE
@ COLOR_BLUE
Definition: mega65.h:186
COLOR_SCREENOFDEATH
@ COLOR_SCREENOFDEATH
Definition: mega65.h:207
COLOR_RAMBUTAN
@ COLOR_RAMBUTAN
Definition: mega65.h:197
COLOR_BLACK
@ COLOR_BLACK
Definition: mega65.h:180
COLOR_CYAN
@ COLOR_CYAN
Definition: mega65.h:183
_vic4.h
_6526.h
COLOR_LEMONTART
@ COLOR_LEMONTART
Definition: mega65.h:199
COLOR_LIGHTGREY
@ COLOR_LIGHTGREY
Definition: mega65.h:195
COLOR_BUBBLEGUM
@ COLOR_BUBBLEGUM
Definition: mega65.h:210
std::uint64_t
::uint64_t uint64_t
Definition: cstdint:24
COLOR_WHITE
@ COLOR_WHITE
Definition: mega65.h:181
COLOR_PURPLE
@ COLOR_PURPLE
Definition: mega65.h:184
COLOR_SLIMERGREEN
@ COLOR_SLIMERGREEN
Definition: mega65.h:203
COLOR_SOYLENTGREEN
@ COLOR_SOYLENTGREEN
Definition: mega65.h:202
std::uint32_t
::uint32_t uint32_t
Definition: cstdint:23
_vic2.h
COLOR_ORANGE
@ COLOR_ORANGE
Definition: mega65.h:188
COLOR_CARROT
@ COLOR_CARROT
Definition: mega65.h:198
COLOR_LIGHTRED
@ COLOR_LIGHTRED
Definition: mega65.h:190