llvm-mos-sdk
rp6502.h
Go to the documentation of this file.
1 #ifndef _RP6502_H
2 #define _RP6502_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 /* RP6502 RIA $FFE0-$FFF9 */
9 struct __RP6502 {
10  const unsigned char ready;
11  unsigned char tx;
12  const unsigned char rx;
13  const unsigned char vsync;
14  unsigned char rw0;
15  unsigned char step0;
16  unsigned int addr0;
17  unsigned char rw1;
18  unsigned char step1;
19  unsigned int addr1;
20  unsigned char xstack;
21  unsigned int errno;
22  unsigned char op;
23  unsigned char irq;
24  const unsigned char spin;
25  const unsigned char busy;
26  const unsigned char lda;
27  unsigned char a;
28  const unsigned char ldx;
29  unsigned char x;
30  const unsigned char rts;
31  unsigned int sreg;
32 };
33 #define RIA (*(volatile struct __RP6502 *)0xFFE0)
34 
35 #define RIA_READY_TX_BIT 0x80
36 #define RIA_READY_RX_BIT 0x40
37 #define RIA_BUSY_BIT 0x80
38 
39 /* OS operation numbers */
40 
41 #define RIA_OP_EXIT 0xFF
42 #define RIA_OP_ZXSTACK 0x00
43 #define RIA_OP_XREG 0x01
44 #define RIA_OP_PHI2 0x02
45 #define RIA_OP_CODEPAGE 0x03
46 #define RIA_OP_LRAND 0x04
47 #define RIA_OP_STDIN_OPT 0x05
48 #define RIA_OP_CLOCK 0x0F
49 #define RIA_OP_CLOCK_GETRES 0x10
50 #define RIA_OP_CLOCK_GETTIME 0x11
51 #define RIA_OP_CLOCK_SETTIME 0x12
52 #define RIA_OP_CLOCK_GETTIMEZONE 0x13
53 #define RIA_OP_OPEN 0x14
54 #define RIA_OP_CLOSE 0x15
55 #define RIA_OP_READ_XSTACK 0x16
56 #define RIA_OP_READ_XRAM 0x17
57 #define RIA_OP_WRITE_XSTACK 0x18
58 #define RIA_OP_WRITE_XRAM 0x19
59 #define RIA_OP_LSEEK 0x1A
60 #define RIA_OP_UNLINK 0x1B
61 #define RIA_OP_RENAME 0x1C
62 
63 /* C API for the operating system. */
64 
65 int xregn(char device, char channel, unsigned char address, unsigned count,
66  ...);
67 int phi2(void);
68 int codepage(void);
69 long lrand(void);
70 int stdin_opt(unsigned long ctrl_bits, unsigned char str_length);
71 int read_xstack(void *buf, unsigned count, int fildes);
72 int read_xram(unsigned buf, unsigned count, int fildes);
73 int write_xstack(const void *buf, unsigned count, int fildes);
74 int write_xram(unsigned buf, unsigned count, int fildes);
75 
76 /* Temporary home for standard library headers. */
77 
78 #define STDIN_FILENO 0
79 #define STDOUT_FILENO 1
80 #define STDERR_FILENO 2
81 
82 #define O_RDONLY 0x01
83 #define O_WRONLY 0x02
84 #define O_RDWR 0x03
85 #define O_CREAT 0x10
86 #define O_TRUNC 0x20
87 #define O_APPEND 0x40
88 #define O_EXCL 0x80
89 
90 #define SEEK_CUR 0
91 #define SEEK_END 1
92 #define SEEK_SET 2
93 
94 int open(const char *name, int flags, ...);
95 int read(int fildes, void *buf, unsigned count);
96 int write(int fildes, const void *buf, unsigned count);
97 int close(int fd);
98 long lseek(int fd, long offset, int whence);
99 unsigned char _sysremove(const char *name);
100 unsigned char _sysrename(const char *oldpath, const char *newpath);
101 
102 /* XRAM structure helpers */
103 
104 #define xram0_struct_set(addr, type, member, val) \
105  RIA.addr0 = (unsigned)(&((type *)0)->member) + (unsigned)addr; \
106  switch (sizeof(((type *)0)->member)) { \
107  case 1: \
108  RIA.rw0 = val; \
109  break; \
110  case 2: \
111  RIA.step0 = 1; \
112  RIA.rw0 = val & 0xff; \
113  RIA.rw0 = (val >> 8) & 0xff; \
114  break; \
115  case 4: \
116  RIA.step0 = 1; \
117  RIA.rw0 = (unsigned long)val & 0xff; \
118  RIA.rw0 = ((unsigned long)val >> 8) & 0xff; \
119  RIA.rw0 = ((unsigned long)val >> 16) & 0xff; \
120  RIA.rw0 = ((unsigned long)val >> 24) & 0xff; \
121  break; \
122  }
123 
124 #define xram1_struct_set(addr, type, member, val) \
125  RIA.addr1 = (unsigned)(&((type *)0)->member) + (unsigned)addr; \
126  switch (sizeof(((type *)0)->member)) { \
127  case 1: \
128  RIA.rw1 = val; \
129  break; \
130  case 2: \
131  RIA.step1 = 1; \
132  RIA.rw1 = val & 0xff; \
133  RIA.rw1 = (val >> 8) & 0xff; \
134  break; \
135  case 4: \
136  RIA.step1 = 1; \
137  RIA.rw1 = (unsigned long)val & 0xff; \
138  RIA.rw1 = ((unsigned long)val >> 8) & 0xff; \
139  RIA.rw1 = ((unsigned long)val >> 16) & 0xff; \
140  RIA.rw1 = ((unsigned long)val >> 24) & 0xff; \
141  break; \
142  }
143 
144 typedef struct {
145  unsigned char x_wrap; // bool
146  unsigned char y_wrap; // bool
147  int x_pos_px;
148  int y_pos_px;
151  unsigned xram_data_ptr;
153  unsigned xram_font_ptr;
155 
156 typedef struct {
157  unsigned char x_wrap; // bool
158  unsigned char y_wrap; // bool
159  int x_pos_px;
160  int y_pos_px;
163  unsigned xram_data_ptr;
165  unsigned xram_tile_ptr;
167 
168 typedef struct {
169  unsigned char x_wrap; // bool
170  unsigned char y_wrap; // bool
171  int x_pos_px;
172  int y_pos_px;
173  int width_px;
175  unsigned xram_data_ptr;
178 
179 typedef struct {
180  int x_pos_px;
181  int y_pos_px;
182  unsigned xram_sprite_ptr;
183  unsigned char log_size;
184  unsigned char has_opacity_metadata; // bool
186 
187 typedef struct {
188  int transform[6];
189  int x_pos_px;
190  int y_pos_px;
191  unsigned xram_sprite_ptr;
192  unsigned char log_size;
193  unsigned char has_opacity_metadata; // bool
195 
196 /* Values in __oserror are the union of these FatFs errors and errno.h */
197 
198 typedef enum {
199  FR_OK = 32, /* Succeeded */
200  FR_DISK_ERR, /* A hard error occurred in the low level disk I/O layer */
201  FR_INT_ERR, /* Assertion failed */
202  FR_NOT_READY, /* The physical drive cannot work */
203  FR_NO_FILE, /* Could not find the file */
204  FR_NO_PATH, /* Could not find the path */
205  FR_INVALID_NAME, /* The path name format is invalid */
206  FR_DENIED, /* Access denied due to prohibited access or directory full */
207  FR_EXIST, /* Access denied due to prohibited access */
208  FR_INVALID_OBJECT, /* The file/directory object is invalid */
209  FR_WRITE_PROTECTED, /* The physical drive is write protected */
210  FR_INVALID_DRIVE, /* The logical drive number is invalid */
211  FR_NOT_ENABLED, /* The volume has no work area */
212  FR_NO_FILESYSTEM, /* There is no valid FAT volume */
213  FR_MKFS_ABORTED, /* The f_mkfs() aborted due to any problem */
214  FR_TIMEOUT, /* Could not get a grant to access the volume within defined
215  period */
216  FR_LOCKED, /* The operation is rejected according to the file sharing policy
217  */
218  FR_NOT_ENOUGH_CORE, /* LFN working buffer could not be allocated */
219  FR_TOO_MANY_OPEN_FILES, /* Number of open files > FF_FS_LOCK */
220  FR_INVALID_PARAMETER /* Given parameter is invalid */
221 } FRESULT;
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #endif /* _RP6502_H */
vga_mode1_config_t::x_wrap
unsigned char x_wrap
Definition: rp6502.h:145
phi2
int phi2(void)
vga_mode4_asprite_t::log_size
unsigned char log_size
Definition: rp6502.h:192
vga_mode3_config_t::xram_palette_ptr
unsigned xram_palette_ptr
Definition: rp6502.h:176
vga_mode2_config_t::xram_palette_ptr
unsigned xram_palette_ptr
Definition: rp6502.h:164
FR_DISK_ERR
@ FR_DISK_ERR
Definition: rp6502.h:200
FR_NO_FILESYSTEM
@ FR_NO_FILESYSTEM
Definition: rp6502.h:212
FR_LOCKED
@ FR_LOCKED
Definition: rp6502.h:216
vga_mode4_sprite_t::xram_sprite_ptr
unsigned xram_sprite_ptr
Definition: rp6502.h:182
FR_DENIED
@ FR_DENIED
Definition: rp6502.h:206
vga_mode4_asprite_t::y_pos_px
int y_pos_px
Definition: rp6502.h:190
FR_MKFS_ABORTED
@ FR_MKFS_ABORTED
Definition: rp6502.h:213
open
int open(const char *name, int flags,...)
FR_INVALID_PARAMETER
@ FR_INVALID_PARAMETER
Definition: rp6502.h:220
vga_mode4_asprite_t
Definition: rp6502.h:187
vga_mode1_config_t::xram_font_ptr
unsigned xram_font_ptr
Definition: rp6502.h:153
close
int close(int fd)
vga_mode4_asprite_t::xram_sprite_ptr
unsigned xram_sprite_ptr
Definition: rp6502.h:191
vga_mode2_config_t::xram_data_ptr
unsigned xram_data_ptr
Definition: rp6502.h:163
vga_mode1_config_t::height_chars
int height_chars
Definition: rp6502.h:150
vga_mode2_config_t::width_tiles
int width_tiles
Definition: rp6502.h:161
FR_NOT_ENABLED
@ FR_NOT_ENABLED
Definition: rp6502.h:211
vga_mode1_config_t::y_pos_px
int y_pos_px
Definition: rp6502.h:148
lseek
long lseek(int fd, long offset, int whence)
FR_NOT_ENOUGH_CORE
@ FR_NOT_ENOUGH_CORE
Definition: rp6502.h:218
FR_INVALID_OBJECT
@ FR_INVALID_OBJECT
Definition: rp6502.h:208
FR_OK
@ FR_OK
Definition: rp6502.h:199
vga_mode3_config_t
Definition: rp6502.h:168
read_xstack
int read_xstack(void *buf, unsigned count, int fildes)
vga_mode3_config_t::height_px
int height_px
Definition: rp6502.h:174
vga_mode3_config_t::x_pos_px
int x_pos_px
Definition: rp6502.h:171
FR_INVALID_DRIVE
@ FR_INVALID_DRIVE
Definition: rp6502.h:210
_sysrename
unsigned char _sysrename(const char *oldpath, const char *newpath)
vga_mode1_config_t::xram_palette_ptr
unsigned xram_palette_ptr
Definition: rp6502.h:152
vga_mode3_config_t::y_wrap
unsigned char y_wrap
Definition: rp6502.h:170
channel
char channel
Definition: famitone2.h:31
vga_mode2_config_t::height_tiles
int height_tiles
Definition: rp6502.h:162
vga_mode4_sprite_t::x_pos_px
int x_pos_px
Definition: rp6502.h:180
count
const void uint16_t count
Definition: memory.h:58
vga_mode4_sprite_t
Definition: rp6502.h:179
vga_mode4_sprite_t::log_size
unsigned char log_size
Definition: rp6502.h:183
FR_NO_PATH
@ FR_NO_PATH
Definition: rp6502.h:204
lrand
long lrand(void)
vga_mode1_config_t::y_wrap
unsigned char y_wrap
Definition: rp6502.h:146
FR_NO_FILE
@ FR_NO_FILE
Definition: rp6502.h:203
x
byte x
Definition: api.h:26
read
int read(int fildes, void *buf, unsigned count)
FR_INVALID_NAME
@ FR_INVALID_NAME
Definition: rp6502.h:205
vga_mode4_asprite_t::has_opacity_metadata
unsigned char has_opacity_metadata
Definition: rp6502.h:193
write_xstack
int write_xstack(const void *buf, unsigned count, int fildes)
FR_WRITE_PROTECTED
@ FR_WRITE_PROTECTED
Definition: rp6502.h:209
vga_mode1_config_t::xram_data_ptr
unsigned xram_data_ptr
Definition: rp6502.h:151
FR_TIMEOUT
@ FR_TIMEOUT
Definition: rp6502.h:214
FR_NOT_READY
@ FR_NOT_READY
Definition: rp6502.h:202
vga_mode4_sprite_t::y_pos_px
int y_pos_px
Definition: rp6502.h:181
write
int write(int fildes, const void *buf, unsigned count)
errno
#define errno
Definition: errno.h:9
vga_mode4_asprite_t::x_pos_px
int x_pos_px
Definition: rp6502.h:189
vga_mode2_config_t::x_pos_px
int x_pos_px
Definition: rp6502.h:159
vga_mode2_config_t::y_wrap
unsigned char y_wrap
Definition: rp6502.h:158
vga_mode1_config_t::x_pos_px
int x_pos_px
Definition: rp6502.h:147
write_xram
int write_xram(unsigned buf, unsigned count, int fildes)
vga_mode2_config_t::xram_tile_ptr
unsigned xram_tile_ptr
Definition: rp6502.h:165
read_xram
int read_xram(unsigned buf, unsigned count, int fildes)
vga_mode4_sprite_t::has_opacity_metadata
unsigned char has_opacity_metadata
Definition: rp6502.h:184
xregn
int xregn(char device, char channel, unsigned char address, unsigned count,...)
address
uint8_t uint16_t address
Definition: bios.h:180
FRESULT
FRESULT
Definition: rp6502.h:198
FR_TOO_MANY_OPEN_FILES
@ FR_TOO_MANY_OPEN_FILES
Definition: rp6502.h:219
vga_mode3_config_t::width_px
int width_px
Definition: rp6502.h:173
FR_EXIST
@ FR_EXIST
Definition: rp6502.h:207
_sysremove
unsigned char _sysremove(const char *name)
vga_mode2_config_t::y_pos_px
int y_pos_px
Definition: rp6502.h:160
stdin_opt
int stdin_opt(unsigned long ctrl_bits, unsigned char str_length)
vga_mode2_config_t
Definition: rp6502.h:156
codepage
int codepage(void)
vga_mode3_config_t::y_pos_px
int y_pos_px
Definition: rp6502.h:172
vga_mode1_config_t::width_chars
int width_chars
Definition: rp6502.h:149
vga_mode3_config_t::xram_data_ptr
unsigned xram_data_ptr
Definition: rp6502.h:175
vga_mode3_config_t::x_wrap
unsigned char x_wrap
Definition: rp6502.h:169
vga_mode2_config_t::x_wrap
unsigned char x_wrap
Definition: rp6502.h:157
FR_INT_ERR
@ FR_INT_ERR
Definition: rp6502.h:201
vga_mode1_config_t
Definition: rp6502.h:144