llvm-mos-sdk
cx16.h
Go to the documentation of this file.
1 // Copyright 2022 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 // Originally from cc65. Modified from original version.
7 
8 // clang-format off
9 
10 /*****************************************************************************/
11 /* */
12 /* cx16.h */
13 /* */
14 /* CX16 system-specific definitions */
15 /* For prerelease 39 */
16 /* */
17 /* */
18 /* This software is provided "as-is", without any expressed or implied */
19 /* warranty. In no event will the authors be held liable for any damages */
20 /* arising from the use of this software. */
21 /* */
22 /* Permission is granted to anyone to use this software for any purpose, */
23 /* including commercial applications, and to alter it and redistribute it */
24 /* freely, subject to the following restrictions: */
25 /* */
26 /* 1. The origin of this software must not be misrepresented; you must not */
27 /* claim that you wrote the original software. If you use this software */
28 /* in a product, an acknowledgment in the product documentation would be */
29 /* appreciated, but is not required. */
30 /* 2. Altered source versions must be plainly marked as such, and must not */
31 /* be misrepresented as being the original software. */
32 /* 3. This notice may not be removed or altered from any source */
33 /* distribution. */
34 /* */
35 /*****************************************************************************/
36 
37 #ifndef _CX16_H
38 #define _CX16_H
39 
40 #include <stdbool.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /* Check for errors */
47 #ifndef __CX16__
48 # error This module may be used only when compiling for the CX16!
49 #endif
50 
51 
52 
53 /*****************************************************************************/
54 /* Data */
55 /*****************************************************************************/
56 
57 
58 
59 /* Additional output character codes */
60 #define CH_COLOR_SWAP 0x01
61 #define CH_UNDERLINE 0x04
62 #define CH_WHITE 0x05
63 #define CH_BOLD 0x06
64 #define CH_BACKSPACE 0x08
65 #define CH_ITALIC 0x0B
66 #define CH_OUTLINE 0x0C
67 #define CH_FONT_ISO 0x0F
68 #define CH_RED 0x1C
69 #define CH_GREEN 0x1E
70 #define CH_BLUE 0x1F
71 #define CH_ORANGE 0x81
72 #define CH_FONT_PET 0x8F
73 #define CH_BLACK 0x90
74 #define CH_ATTR_CLEAR 0x92
75 #define CH_BROWN 0x95
76 #define CH_PINK 0x96
77 #define CH_LIGHTRED CH_PINK
78 #define CH_GRAY1 0x97
79 #define CH_GRAY2 0x98
80 #define CH_LIGHTGREEN 0x99
81 #define CH_LIGHTBLUE 0x9A
82 #define CH_GRAY3 0x9B
83 #define CH_PURPLE 0x9C
84 #define CH_YELLOW 0x9E
85 #define CH_CYAN 0x9F
86 #define CH_SHIFT_SPACE 0xA0
87 
88 /* Additional key defines */
89 #define CH_SHIFT_TAB 0x18
90 #define CH_HELP 0x84
91 #define CH_F1 0x85
92 #define CH_F2 0x89
93 #define CH_F3 0x86
94 #define CH_F4 0x8A
95 #define CH_F5 0x87
96 #define CH_F6 0x8B
97 #define CH_F7 0x88
98 #define CH_F8 0x8C
99 #define CH_F9 0x10
100 #define CH_F10 0x15
101 #define CH_F11 0x16
102 #define CH_F12 0x17
103 
104 /* Color defines */
105 #define COLOR_BLACK 0x00
106 #define COLOR_WHITE 0x01
107 #define COLOR_RED 0x02
108 #define COLOR_CYAN 0x03
109 #define COLOR_PURPLE 0x04
110 #define COLOR_GREEN 0x05
111 #define COLOR_BLUE 0x06
112 #define COLOR_YELLOW 0x07
113 #define COLOR_ORANGE 0x08
114 #define COLOR_BROWN 0x09
115 #define COLOR_PINK 0x0A
116 #define COLOR_LIGHTRED COLOR_PINK
117 #define COLOR_GRAY1 0x0B
118 #define COLOR_GRAY2 0x0C
119 #define COLOR_LIGHTGREEN 0x0D
120 #define COLOR_LIGHTBLUE 0x0E
121 #define COLOR_GRAY3 0x0F
122 
124 enum : unsigned char {
125  // Masks for JoyState::data0
126  JOY_BTN_B_MASK = 1 << 7,
127  JOY_BTN_Y_MASK = 1 << 6,
128  JOY_SELECT_MASK = 1 << 5,
129  JOY_START_MASK = 1 << 4,
130  JOY_UP_MASK = 1 << 3,
131  JOY_DOWN_MASK = 1 << 2,
132  JOY_LEFT_MASK = 1 << 1,
133  JOY_RIGHT_MASK = 1 << 0,
134  // Masks for JoyState::data1
135  JOY_BTN_A_MASK = 1 << 7,
136  JOY_BTN_X_MASK = 1 << 6,
139 };
140 
142 #define JOY_KEYBOARD 0
143 #define JOY_SNES_PORT1 1
144 #define JOY_SNES_PORT2 2
145 #define JOY_SNES_PORT3 3
146 #define JOY_SNES_PORT4 4
147 
149 typedef struct {
150  union {
151  struct {
152  unsigned char data0;
153  unsigned char data1;
154  };
155  unsigned short data;
156  };
157  bool detached;
158 
159 #ifdef __cplusplus
160  bool button_a() const { return !(data1 & JOY_BTN_A_MASK); }
161  bool button_b() const { return !(data0 & JOY_BTN_B_MASK); }
162  bool button_x() const { return !(data1 & JOY_BTN_X_MASK); }
163  bool button_y() const { return !(data0 & JOY_BTN_Y_MASK); }
164  bool fire_left() const { return !(data1 & JOY_FIRE_LEFT_MASK); }
165  bool fire_right() const { return !(data1 & JOY_FIRE_RIGHT_MASK); }
166  bool select() const { return !(data0 & JOY_SELECT_MASK); }
167  bool start() const { return !(data0 & JOY_START_MASK); }
168  bool north() const { return !(data0 & JOY_UP_MASK); }
169  bool south() const { return !(data0 & JOY_DOWN_MASK); }
170  bool east() const { return !(data0 & JOY_RIGHT_MASK); }
171  bool west() const { return !(data0 & JOY_LEFT_MASK); }
172  bool north_east() const { return !(data0 & (JOY_UP_MASK | JOY_RIGHT_MASK)); }
173  bool north_west() const { return !(data0 & (JOY_UP_MASK | JOY_LEFT_MASK)); }
174  bool south_east() const {
175  return !(data0 & (JOY_DOWN_MASK | JOY_RIGHT_MASK));
176  }
177  bool south_west() const { return !(data0 & (JOY_DOWN_MASK | JOY_LEFT_MASK)); }
178 #endif
179 } JoyState;
180 
181 /* Additional mouse button mask */
182 #define MOUSE_BTN_MIDDLE 0x02
183 
184 /* get_tv() return codes
185 ** set_tv() argument codes
186 ** NOTE: llvm-mos-sdk added newer 240P modes
187 */
188 enum : unsigned char {
189  TV_NONE = 0x00,
205 };
206 
207 /* Video modes for videomode() */
208 #define VIDEOMODE_80x60 0x00
209 #define VIDEOMODE_80x30 0x01
210 #define VIDEOMODE_40x60 0x02
211 #define VIDEOMODE_40x30 0x03
212 #define VIDEOMODE_40x15 0x04
213 #define VIDEOMODE_20x30 0x05
214 #define VIDEOMODE_20x15 0x06
215 #define VIDEOMODE_80COL VIDEOMODE_80x60
216 #define VIDEOMODE_40COL VIDEOMODE_40x30
217 #define VIDEOMODE_320x240 0x80
218 #define VIDEOMODE_SWAP (-1)
219 
220 /* VERA's address increment/decrement numbers */
221 enum : unsigned char {
222  VERA_DEC_0 = ((0 << 1) | 1) << 3,
223  VERA_DEC_1 = ((1 << 1) | 1) << 3,
224  VERA_DEC_2 = ((2 << 1) | 1) << 3,
225  VERA_DEC_4 = ((3 << 1) | 1) << 3,
226  VERA_DEC_8 = ((4 << 1) | 1) << 3,
227  VERA_DEC_16 = ((5 << 1) | 1) << 3,
228  VERA_DEC_32 = ((6 << 1) | 1) << 3,
229  VERA_DEC_64 = ((7 << 1) | 1) << 3,
230  VERA_DEC_128 = ((8 << 1) | 1) << 3,
231  VERA_DEC_256 = ((9 << 1) | 1) << 3,
232  VERA_DEC_512 = ((10 << 1) | 1) << 3,
233  VERA_DEC_40 = ((11 << 1) | 1) << 3,
234  VERA_DEC_80 = ((12 << 1) | 1) << 3,
235  VERA_DEC_160 = ((13 << 1) | 1) << 3,
236  VERA_DEC_320 = ((14 << 1) | 1) << 3,
237  VERA_DEC_640 = ((15 << 1) | 1) << 3,
238  VERA_INC_0 = ((0 << 1) | 0) << 3,
239  VERA_INC_1 = ((1 << 1) | 0) << 3,
240  VERA_INC_2 = ((2 << 1) | 0) << 3,
241  VERA_INC_4 = ((3 << 1) | 0) << 3,
242  VERA_INC_8 = ((4 << 1) | 0) << 3,
243  VERA_INC_16 = ((5 << 1) | 0) << 3,
244  VERA_INC_32 = ((6 << 1) | 0) << 3,
245  VERA_INC_64 = ((7 << 1) | 0) << 3,
246  VERA_INC_128 = ((8 << 1) | 0) << 3,
247  VERA_INC_256 = ((9 << 1) | 0) << 3,
248  VERA_INC_512 = ((10 << 1) | 0) << 3,
249  VERA_INC_40 = ((11 << 1) | 0) << 3,
250  VERA_INC_80 = ((12 << 1) | 0) << 3,
251  VERA_INC_160 = ((13 << 1) | 0) << 3,
252  VERA_INC_320 = ((14 << 1) | 0) << 3,
253  VERA_INC_640 = ((15 << 1) | 0) << 3
254 };
255 
256 /* VERA's interrupt flags */
257 #define VERA_IRQ_VSYNC 0b00000001
258 #define VERA_IRQ_RASTER 0b00000010
259 #define VERA_IRQ_SPR_COLL 0b00000100
260 #define VERA_IRQ_AUDIO_LOW 0b00001000
261 
263 enum : unsigned char {
265  ROM_KEYBD = 1,
267  ROM_FAT32 = 3,
268  ROM_BASIC = 4,
271  ROM_DIAG = 7,
272  ROM_GRAPH = 8,
273  ROM_DEMO = 9,
274  ROM_AUDIO = 10,
275  ROM_UTIL = 11,
276  ROM_BANNEX = 12,
280 };
281 
282 /* Define hardware. */
283 
284 #define RAM_BANK (*(volatile unsigned char *)0x00)
285 #define ROM_BANK (*(volatile unsigned char *)0x01)
286 
287 #include <_6522.h>
288 #define VIA1 (*(volatile struct __6522 *)0x9F00)
289 #define VIA2 (*(volatile struct __6522 *)0x9F10)
290 
291 /* A structure with the Video Enhanced Retro Adapter's external registers */
292 struct __vera {
293  unsigned short address; /* Address for data ports */
294  unsigned char address_hi;
295  unsigned char data0; /* Data port 0 */
296  unsigned char data1; /* Data port 1 */
297  unsigned char control; /* Control register */
298  unsigned char irq_enable; /* Interrupt enable bits */
299  unsigned char irq_flags; /* Interrupt flags */
300  unsigned char irq_raster; /* Line where IRQ will occur */
301  union {
302  struct { /* Visible when DCSEL flag = 0 */
303  unsigned char video; /* Flags to enable video layers */
304  unsigned char hscale; /* Horizontal scale factor */
305  unsigned char vscale; /* Vertical scale factor */
306  unsigned char border; /* Border color (NTSC mode) */
307  };
308  struct { /* Visible when DCSEL flag = 1 */
309  unsigned char hstart; /* Horizontal start position */
310  unsigned char hstop; /* Horizontal stop position */
311  unsigned char vstart; /* Vertical start position */
312  unsigned char vstop; /* Vertical stop position */
313  };
314  struct { /* Visible when DCSEL flag = 2 */
315  unsigned char fxctrl;
316  unsigned char fxtilebase;
317  unsigned char fxmapbase;
318  unsigned char fxmult;
319  };
320  struct { /* Visible when DCSEL flag = 3 */
321  unsigned char fxxincrl;
322  unsigned char fxxincrh;
323  unsigned char fxyincrl;
324  unsigned char fxyincrh;
325  };
326  struct { /* Visible when DCSEL flag = 4 */
327  unsigned char fxxposl;
328  unsigned char fxxposh;
329  unsigned char fxyposl;
330  unsigned char fxyposh;
331  };
332  struct { /* Visible when DCSEL flag = 5 */
333  unsigned char fxxposs;
334  unsigned char fxyposs;
335  unsigned char fxpolyfilll;
336  unsigned char fxpolyfillh;
337  };
338  struct { /* Visible when DCSEL flag = 6 */
339  unsigned char fxcachel;
340  unsigned char fxcachem;
341  unsigned char fxcacheh;
342  unsigned char fxcacheu;
343  };
344  struct { /* Visible when DCSEL flag = 63 */
345  unsigned char dcver0;
346  unsigned char dcver1;
347  unsigned char dcver2;
348  unsigned char dcver3;
349  };
350  } display;
351  struct {
352  unsigned char config; /* Layer map geometry */
353  unsigned char mapbase; /* Map data address */
354  unsigned char tilebase; /* Tile address and geometry */
355  unsigned int hscroll; /* Smooth scroll horizontal offset */
356  unsigned int vscroll; /* Smooth scroll vertical offset */
357  } layer0;
358  struct {
359  unsigned char config;
360  unsigned char mapbase;
361  unsigned char tilebase;
362  unsigned int hscroll;
363  unsigned int vscroll;
364  } layer1;
365  struct {
366  unsigned char control; /* PCM format */
367  unsigned char rate; /* Sample rate */
368  unsigned char data; /* PCM output queue */
369  } audio; /* Pulse-Code Modulation registers */
370  struct {
371  unsigned char data;
372  unsigned char control;
373  } spi; /* SD card interface */
374 };
375 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201103L)
376 static_assert(sizeof(struct __vera) == 32, "struct __vera must be 32 bytes");
377 #endif
378 
379 #define VERA (*(volatile struct __vera *)0x9F20)
380 
381 /* Audio chip */
382 struct __ym2151 {
383  union {
384  unsigned char reg; /* Register number for data */
385  unsigned char status; /* Busy flag */
386  };
387  unsigned char data;
388 };
389 #define YM2151 (*(volatile struct __ym2151 *)0x9F40)
390 
392 struct __vera_psg {
393  union {
394  unsigned short freq;
395  struct {
396  unsigned char freq_lo;
397  unsigned char freq_hi;
398  };
399  };
400  unsigned char volume;
401  unsigned char waveform;
402 };
403 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201103L)
404 static_assert(sizeof(struct __vera_psg) == 4, "struct __vera_psg must be 4 bytes");
405 #endif
406 
407 /* A structure with the x16emu's settings registers */
408 struct __emul {
409  unsigned char debug; /* Boolean: debugging enabled */
410  unsigned char vera_action; /* Boolean: displaying VERA activity */
411  unsigned char keyboard; /* Boolean: displaying typed keys */
412  unsigned char echo; /* How to send Kernal output to host */
413  unsigned char save_on_exit; /* Boolean: save machine state on exit */
414  unsigned char gif_method; /* Control GIF (0=pause; 1=single; 2=resume) */
415  unsigned char wav_method; /* Control WAV (0=pause; 1=record; 2=autostart) */
416  unsigned char cmd_key_off; /* Boolean: disable emulator command keys */
417  unsigned long const cycle_count; /* Running total of CPU cycles (8 MHz.) */
418  unsigned char const unused2[1];
419  unsigned char const keymap; /* Keyboard layout number */
420  char const detect[2]; /* "16" if running on x16emu */
421 };
422 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201103L)
423 static_assert(sizeof(struct __emul) == 16, "struct __emul must be 16 bytes");
424 #endif
425 
426 #define EMULATOR (*(volatile struct __emul *)0x9FB0)
427 
428 /* An array window into the half Mebibyte or two Mebibytes of banked RAM */
429 #define BANK_RAM ((volatile unsigned char *)0xA000)
430 
431 /*****************************************************************************/
432 /* CX16 kernal functions */
433 /*****************************************************************************/
434 
435 /* Kernel function structure type definitions */
436 typedef struct
437 {
438  unsigned char year, mon, day, hour, min, sec, jif;
439 } cx16_date_time_t; /* cx16_k_clock_get_date_time() */
440 
441 typedef struct
442 {
443  unsigned int width, height;
444  unsigned char depth;
445 } cx16_fb_info_t; /* cx16_k_fb_get_info_depth() */
446 
447 typedef struct
448 {
449  void *fb_init;
450  void *fb_get_info;
463 } graph_fb_functions_t; /* cx16_k_graph_init() */
464 
465 typedef struct
466 {
467  int x, y;
468 } graph_pos_t; /* fb_graph_put_char() */
469 
470 typedef struct
471 {
472  int x, y;
473 } mouse_pos_t; /* cx16_k_mouse_get() */
474 
475 typedef struct
476 {
477  unsigned char mode, columns, rows;
478 } screen_mode_info_t; /* cx16_k_screen_mode_get() */
479 
480 /* Kernal-level functions */
481 unsigned char cx16_k_bsave(void *startaddr, void *endaddr_plusone) __attribute__((leaf)); // returns 0 on success
482 void cx16_k_clock_get_date_time(cx16_date_time_t *datetime_ptr) __attribute__((leaf));
483 void cx16_k_clock_set_date_time(unsigned char year, unsigned char mon, unsigned char day, unsigned char hour, unsigned char min, unsigned char sec, unsigned char jif) __attribute__((leaf));
484 unsigned char cx16_k_console_get_char(void) __attribute__((leaf));
485 void cx16_k_console_init(unsigned int x, unsigned int y, unsigned int width, unsigned int height) __attribute__((leaf));
486 void cx16_k_console_put_char(unsigned char c, unsigned char wrapwordflag) __attribute__((leaf));
487 void cx16_k_console_put_image(void *imageaddr, unsigned int width, unsigned int height) __attribute__((leaf));
488 void cx16_k_console_set_paging_message(void *msgaddr) __attribute__((leaf));
489 void cx16_k_enter_basic(unsigned char coldstart) __attribute__((noreturn));
490 unsigned long cx16_k_entropy_get(void) __attribute__((leaf)); // returns 24-bit value
491 void cx16_k_fb_cursor_next_line(unsigned int x) __attribute__((leaf));
492 void cx16_k_fb_cursor_position(unsigned int x, unsigned int y) __attribute__((leaf));
493 void cx16_k_fb_fill_pixels(unsigned int count, unsigned int step, unsigned char color) __attribute__((leaf));
494 void cx16_k_fb_filter_pixels(void *filterfunc, unsigned int count) __attribute__((leaf));
495 void cx16_k_fb_get_info(cx16_fb_info_t *info_ptr) __attribute__((leaf));
496 unsigned char fb_get_pixel(void) __attribute__((leaf));
497 void cx16_k_fb_get_pixels(void *pixeladdr, unsigned int count) __attribute__((leaf));
498 void cx16_k_fb_init(void) __attribute__((leaf));
499 void cx16_k_fb_move_pixels(unsigned int sx, unsigned int sy, unsigned int tx, unsigned int ty, unsigned int count) __attribute__((leaf));
500 void cx16_k_fb_set_8_pixels(unsigned char pattern, unsigned char color) __attribute__((leaf));
501 void cx16_k_fb_set_8_pixels_opaque(unsigned char pattern, unsigned char mask, unsigned char color1, unsigned char color2) __attribute__((leaf));
502 void cx16_k_fb_set_palette(void *paladdr, unsigned char index, unsigned char count) __attribute__((leaf));
503 void cx16_k_graph_clear(void) __attribute__((leaf));
504 void cx16_k_graph_draw_image(unsigned int x, unsigned int y, void *imageaddr, unsigned int width, unsigned int height) __attribute__((leaf));
505 void cx16_k_graph_draw_line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) __attribute__((leaf));
506 void cx16_k_graph_draw_oval(unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int corner_radius, unsigned char fillflag) __attribute__((leaf));
507 void cx16_k_graph_draw_rect(unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int corner_radius, unsigned char fillflag) __attribute__((leaf));
508 long cx16_k_graph_get_char_size(unsigned char c, unsigned char style) __attribute__((leaf)); // if printable returns info (0x00bbwwhh), else negative style byte (0xFF0000ss)
509 void cx16_k_graph_init(graph_fb_functions_t *fb_funcs_ptr) __attribute__((leaf));
510 void cx16_k_graph_move_rect(unsigned int sx, unsigned int sy, unsigned int tx, unsigned int ty, unsigned int width, unsigned int height) __attribute__((leaf));
511 void cx16_k_graph_put_char(graph_pos_t *pos_ptr, unsigned char c) __attribute__((leaf));
512 void cx16_k_graph_set_colors(unsigned char stroke, unsigned char fill, unsigned char background) __attribute__((leaf));
513 void cx16_k_graph_set_font(void *fontaddr) __attribute__((leaf));
514 void cx16_k_graph_set_window(unsigned int x, unsigned int y, unsigned int width, unsigned int height) __attribute__((leaf));
515 int cx16_k_i2c_read_byte(unsigned char device, unsigned char offset) __attribute__((leaf)); // returns negative on error
516 int cx16_k_i2c_write_byte(unsigned char device, unsigned char offset, unsigned char byte) __attribute__((leaf)); // return negative on error
517 
526 JoyState cx16_k_joystick_get(unsigned char joystick_num);
527 
528 void cx16_k_joystick_scan(void) __attribute__((leaf));
529 unsigned char cx16_k_kbdbuf_get_modifiers(void) __attribute__((leaf));
530 int cx16_k_kbdbuf_peek(unsigned char *index_ptr)
531  __attribute__((leaf)); // returns negative if empty, if index_ptr non-NULL
532  // set contents to queue length
533 void cx16_k_kbdbuf_put(unsigned char c) __attribute__((leaf));
534 const char* cx16_k_keymap_get_id(void) __attribute__((leaf));
535 unsigned char cx16_k_keymap_set(const char* identifier) __attribute__((leaf)); // returns 0 on success
536 long cx16_k_macptr(unsigned char count, unsigned char noadvance, void *destaddr) __attribute__((leaf)); // return negative if not supported
537 void cx16_k_memory_copy(void *source, void *target, unsigned int num_bytes) __attribute__((leaf));
538 unsigned int cx16_k_memory_crc(void *dataaddr, unsigned int num_bytes) __attribute__((leaf));
539 void cx16_k_memory_decompress(void *inaddr, void *outaddr) __attribute__((leaf));
540 void cx16_k_memory_fill(void *addr, unsigned int num_bytes, unsigned char value) __attribute__((leaf));
541 void cx16_k_monitor(void) __attribute__((noreturn));
542 void cx16_k_mouse_config(unsigned char showmouse, unsigned char xsize8, unsigned char ysize8) __attribute__((leaf));
543 unsigned char cx16_k_mouse_get(mouse_pos_t *mouse_pos_ptr) __attribute__((leaf)); // returns mouse button byte
544 void cx16_k_mouse_scan(void) __attribute__((leaf));
545 unsigned long cx16_k_rdtim(void) __attribute__((leaf));
546 unsigned char cx16_k_screen_mode_get(screen_mode_info_t *info_ptr) __attribute__((leaf)); // returns 0 on success
547 unsigned char cx16_k_screen_mode_set(unsigned char mode) __attribute__((leaf)); // returns 0 on success
548 void cx16_k_screen_set_charset(unsigned char charset_type, void *charsetaddr) __attribute__((leaf));
549 unsigned char cx16_k_sprite_set_image(unsigned char num, unsigned char w, unsigned char h, unsigned char maskflag, void *imageaddr, void *maskaddr, unsigned char bpp) __attribute__((leaf)); // returns 0 on success
550 unsigned char cx16_k_sprite_set_position(unsigned char sprnum, unsigned int xpos, unsigned int ypos) __attribute__((leaf)); // returns 0 on success
551 
552 /* cc65 compatible cx16 functions */
553 
554 /* Return the number of 8K RAM banks that the machine has */
555 /* at 0xA000-0xBFFF using MEMTOP (64=512K up to 256=2MB) */
556 unsigned short get_numbanks(void) __attribute__((leaf)); // return number of 8K RAM banks at 0xA000-0xBFFF (64=512K up to 256=2MB)
557 
558 /* Get the ROM build version.
559 ** -1 -- custom build
560 ** Negative -- prerelease build
561 ** Positive -- release build
562 */
563 signed char get_ostype(void) __attribute__((leaf)); // return ROM build version (negative pre-release, -1=custom)
564 
565 /* Return the video signal type that the machine is using.
566 ** Return a TV_xx constant.
567 */
568 unsigned char get_tv(void) __attribute__((leaf)); // return TV_* enum constant for current video signal type
569 
570 /* Set the video signal type that the machine will use.
571 ** Call with a TV_xx constant.
572 ** NOTE: Be careful, can overrides user setting for current monitor type (set in config menu)
573 */
574 void set_tv(unsigned char type) __attribute__((leaf)); // set video signal type using TV_* enum constant
575 
576 /* Display the layers that are "named" by the bit flags in layers.
577 ** A value of 0b01 shows layer 0, a value of 0b10 shows layer 1,
578 ** a value of 0b11 shows both layers. Return the previous value.
579 */
580 unsigned char vera_layer_enable(unsigned char layers) __attribute__((leaf)); // enable/disable VERA layers 0/1 (bits 0/1), returns previous
581 
582 /* Enable the sprite engine when mode is non-zero (true);
583 ** disable sprites when mode is zero. Return the previous mode.
584 */
585 unsigned char vera_sprites_enable(unsigned char enable) __attribute__((leaf)); // enable/disable VERA sprites (0=off, non-zero=on), returns previous
586 
587 /* Set the video mode, return the old mode.
588 ** Return -1 if Mode isn't valid.
589 ** Call with one of the VIDEOMODE_xx constants.
590 */
591 signed char videomode(signed char mode) __attribute__((leaf)); // set video mode using VIDEOMODE_* enum constant, returns previous or -1 if error
592 
593 /* Get a byte from a location in VERA's internal address space. */
594 unsigned char vpeek(unsigned long addr) __attribute__((leaf)); // read byte from VERA VRAM address
595 
596 /* Put a byte into a location in VERA's internal address space.
597 ** (addr is second instead of first for the sake of code efficiency.)
598 */
599 void vpoke(unsigned char data, unsigned long addr) __attribute__((leaf)); // write byte value to VERA VRAM address
600 
601 void waitvsync(void); // wait for the vertical blank interrupt
602 
603 #ifdef __cplusplus
604 }
605 #endif
606 #endif // _CX16_H
JoyState
Status of SNES joystick populated by cx16_k_joystick_get();.
Definition: cx16.h:149
get_ostype
signed char get_ostype(void) __attribute__((leaf))
VERA_INC_512
@ VERA_INC_512
Definition: cx16.h:248
JOY_BTN_X_MASK
@ JOY_BTN_X_MASK
Definition: cx16.h:136
get_numbanks
unsigned short get_numbanks(void) __attribute__((leaf))
JOY_START_MASK
@ JOY_START_MASK
Definition: cx16.h:129
JoyState::data
unsigned short data
data0 and data1 combined
Definition: cx16.h:155
videomode
signed char videomode(signed char mode) __attribute__((leaf))
cx16_k_kbdbuf_peek
int cx16_k_kbdbuf_peek(unsigned char *index_ptr) __attribute__((leaf))
cx16_k_joystick_scan
void cx16_k_joystick_scan(void) __attribute__((leaf))
cx16_k_memory_decompress
void cx16_k_memory_decompress(void *inaddr, void *outaddr) __attribute__((leaf))
VERA_INC_16
@ VERA_INC_16
Definition: cx16.h:243
cx16_k_graph_draw_oval
void cx16_k_graph_draw_oval(unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int corner_radius, unsigned char fillflag) __attribute__((leaf))
cx16_k_joystick_get
JoyState cx16_k_joystick_get(unsigned char joystick_num)
JOY_LEFT_MASK
@ JOY_LEFT_MASK
Definition: cx16.h:132
JOY_BTN_B_MASK
@ JOY_BTN_B_MASK
Definition: cx16.h:126
cx16_k_fb_get_pixels
void cx16_k_fb_get_pixels(void *pixeladdr, unsigned int count) __attribute__((leaf))
VERA_INC_4
@ VERA_INC_4
Definition: cx16.h:241
VERA_DEC_1
@ VERA_DEC_1
Definition: cx16.h:223
ROM_BANNEX
@ ROM_BANNEX
BASIC Annex (code for some added BASIC functions)
Definition: cx16.h:276
cx16_k_graph_draw_image
void cx16_k_graph_draw_image(unsigned int x, unsigned int y, void *imageaddr, unsigned int width, unsigned int height) __attribute__((leaf))
cx16_k_monitor
void cx16_k_monitor(void) __attribute__((noreturn))
VERA_DEC_160
@ VERA_DEC_160
Definition: cx16.h:235
cx16_k_rdtim
unsigned long cx16_k_rdtim(void) __attribute__((leaf))
cx16_k_kbdbuf_put
void cx16_k_kbdbuf_put(unsigned char c) __attribute__((leaf))
TV_VGA
@ TV_VGA
Definition: cx16.h:190
TV_NTSC_MONO_240P
@ TV_NTSC_MONO_240P
Definition: cx16.h:203
data
char const void * data
Definition: neslib.h:92
cx16_fb_info_t
Definition: cx16.h:441
cx16_k_keymap_set
unsigned char cx16_k_keymap_set(const char *identifier) __attribute__((leaf))
JOY_SELECT_MASK
@ JOY_SELECT_MASK
Definition: cx16.h:128
TV_NONE2_240P
@ TV_NONE2_240P
Definition: cx16.h:201
VERA_INC_160
@ VERA_INC_160
Definition: cx16.h:251
fb_get_pixel
unsigned char fb_get_pixel(void) __attribute__((leaf))
cx16_k_fb_cursor_next_line
void cx16_k_fb_cursor_next_line(unsigned int x) __attribute__((leaf))
graph_fb_functions_t::fb_get_info
void * fb_get_info
Definition: cx16.h:450
cx16_k_graph_draw_rect
void cx16_k_graph_draw_rect(unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int corner_radius, unsigned char fillflag) __attribute__((leaf))
TV_VGA2
@ TV_VGA2
Definition: cx16.h:194
ROM_X16EDIT1
@ ROM_X16EDIT1
The built-in text editor.
Definition: cx16.h:277
cx16_k_graph_put_char
void cx16_k_graph_put_char(graph_pos_t *pos_ptr, unsigned char c) __attribute__((leaf))
JOY_FIRE_RIGHT_MASK
@ JOY_FIRE_RIGHT_MASK
Definition: cx16.h:138
ROM_BASLOAD
@ ROM_BASLOAD
A transpiler that converts BASLOAD dialect to BASIC V2.
Definition: cx16.h:279
graph_fb_functions_t::fb_set_pixel
void * fb_set_pixel
Definition: cx16.h:456
VERA_INC_64
@ VERA_INC_64
Definition: cx16.h:245
vera_sprites_enable
unsigned char vera_sprites_enable(unsigned char enable) __attribute__((leaf))
graph_pos_t
Definition: cx16.h:465
VERA_DEC_4
@ VERA_DEC_4
Definition: cx16.h:225
VERA_INC_2
@ VERA_INC_2
Definition: cx16.h:240
TV_RGB
@ TV_RGB
Definition: cx16.h:192
cx16_k_console_set_paging_message
void cx16_k_console_set_paging_message(void *msgaddr) __attribute__((leaf))
VERA_DEC_8
@ VERA_DEC_8
Definition: cx16.h:226
TV_RGB2_240P
@ TV_RGB2_240P
Definition: cx16.h:204
VERA_INC_40
@ VERA_INC_40
Definition: cx16.h:249
graph_fb_functions_t::fb_cursor_next_line
void * fb_cursor_next_line
Definition: cx16.h:453
TV_NONE
@ TV_NONE
Definition: cx16.h:189
mouse_pos_t
Definition: cx16.h:470
cx16_k_console_get_char
unsigned char cx16_k_console_get_char(void) __attribute__((leaf))
cx16_k_i2c_write_byte
int cx16_k_i2c_write_byte(unsigned char device, unsigned char offset, unsigned char byte) __attribute__((leaf))
ROM_AUDIO
@ ROM_AUDIO
Audio API routines.
Definition: cx16.h:274
TV_RGB_240P
@ TV_RGB_240P
Definition: cx16.h:200
y1
byte byte byte y1
Definition: api.h:72
h
byte byte byte byte h
Definition: api.h:27
cx16_k_fb_set_8_pixels
void cx16_k_fb_set_8_pixels(unsigned char pattern, unsigned char color) __attribute__((leaf))
cx16_k_graph_set_font
void cx16_k_graph_set_font(void *fontaddr) __attribute__((leaf))
graph_fb_functions_t::fb_set_palette
void * fb_set_palette
Definition: cx16.h:451
hour
uint8_t hour
VERA_DEC_80
@ VERA_DEC_80
Definition: cx16.h:234
cx16_k_graph_move_rect
void cx16_k_graph_move_rect(unsigned int sx, unsigned int sy, unsigned int tx, unsigned int ty, unsigned int width, unsigned int height) __attribute__((leaf))
VERA_DEC_64
@ VERA_DEC_64
Definition: cx16.h:229
get_tv
unsigned char get_tv(void) __attribute__((leaf))
VERA_DEC_256
@ VERA_DEC_256
Definition: cx16.h:231
JOY_FIRE_LEFT_MASK
@ JOY_FIRE_LEFT_MASK
Definition: cx16.h:137
cx16_k_console_init
void cx16_k_console_init(unsigned int x, unsigned int y, unsigned int width, unsigned int height) __attribute__((leaf))
VERA_INC_320
@ VERA_INC_320
Definition: cx16.h:252
cx16_k_clock_get_date_time
void cx16_k_clock_get_date_time(cx16_date_time_t *datetime_ptr) __attribute__((leaf))
vpeek
unsigned char vpeek(unsigned long addr) __attribute__((leaf))
JOY_BTN_Y_MASK
@ JOY_BTN_Y_MASK
Definition: cx16.h:127
JoyState::data1
unsigned char data1
Bits: A X FireL FireR 1 1 1 1.
Definition: cx16.h:153
cx16_k_sprite_set_image
unsigned char cx16_k_sprite_set_image(unsigned char num, unsigned char w, unsigned char h, unsigned char maskflag, void *imageaddr, void *maskaddr, unsigned char bpp) __attribute__((leaf))
ROM_X16EDIT2
@ ROM_X16EDIT2
The built-in text editor.
Definition: cx16.h:278
index
char index
Definition: nesdoug.h:113
graph_fb_functions_t::fb_cursor_position
void * fb_cursor_position
Definition: cx16.h:452
cx16_k_fb_set_8_pixels_opaque
void cx16_k_fb_set_8_pixels_opaque(unsigned char pattern, unsigned char mask, unsigned char color1, unsigned char color2) __attribute__((leaf))
cx16_k_i2c_read_byte
int cx16_k_i2c_read_byte(unsigned char device, unsigned char offset) __attribute__((leaf))
graph_fb_functions_t::fb_fill_pixels
void * fb_fill_pixels
Definition: cx16.h:460
TV_RGB2
@ TV_RGB2
Definition: cx16.h:196
JOY_RIGHT_MASK
@ JOY_RIGHT_MASK
Definition: cx16.h:133
graph_fb_functions_t::fb_get_pixels
void * fb_get_pixels
Definition: cx16.h:455
count
const void uint16_t count
Definition: memory.h:58
cx16_date_time_t::year
unsigned char year
Definition: cx16.h:438
VERA_DEC_640
@ VERA_DEC_640
Definition: cx16.h:237
JoyState::detached
bool detached
True if joystick is disconnected.
Definition: cx16.h:157
graph_fb_functions_t::fb_move_pixels
void * fb_move_pixels
Definition: cx16.h:462
TV_NTSC_COLOR_240P
@ TV_NTSC_COLOR_240P
Definition: cx16.h:199
x
byte x
Definition: api.h:26
cx16_k_sprite_set_position
unsigned char cx16_k_sprite_set_position(unsigned char sprnum, unsigned int xpos, unsigned int ypos) __attribute__((leaf))
cx16_k_graph_clear
void cx16_k_graph_clear(void) __attribute__((leaf))
x1
byte byte x1
Definition: api.h:72
cx16_k_graph_get_char_size
long cx16_k_graph_get_char_size(unsigned char c, unsigned char style) __attribute__((leaf))
VERA_DEC_0
@ VERA_DEC_0
Definition: cx16.h:222
y
byte byte y
Definition: api.h:26
screen_mode_info_t
Definition: cx16.h:475
graph_fb_functions_t::fb_init
void * fb_init
Definition: cx16.h:449
cx16_k_fb_cursor_position
void cx16_k_fb_cursor_position(unsigned int x, unsigned int y) __attribute__((leaf))
VERA_DEC_512
@ VERA_DEC_512
Definition: cx16.h:232
graph_fb_functions_t::fb_get_pixel
void * fb_get_pixel
Definition: cx16.h:454
cx16_k_graph_draw_line
void cx16_k_graph_draw_line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) __attribute__((leaf))
cx16_k_keymap_get_id
const char * cx16_k_keymap_get_id(void) __attribute__((leaf))
cx16_k_bsave
unsigned char cx16_k_bsave(void *startaddr, void *endaddr_plusone) __attribute__((leaf))
day
uint8_t day
VERA_DEC_128
@ VERA_DEC_128
Definition: cx16.h:230
TV_NTSC_MONO
@ TV_NTSC_MONO
Definition: cx16.h:195
cx16_k_mouse_scan
void cx16_k_mouse_scan(void) __attribute__((leaf))
TV_VGA2_240P
@ TV_VGA2_240P
Definition: cx16.h:202
cx16_k_memory_crc
unsigned int cx16_k_memory_crc(void *dataaddr, unsigned int num_bytes) __attribute__((leaf))
VERA_INC_256
@ VERA_INC_256
Definition: cx16.h:247
cx16_k_fb_fill_pixels
void cx16_k_fb_fill_pixels(unsigned int count, unsigned int step, unsigned char color) __attribute__((leaf))
VERA_DEC_16
@ VERA_DEC_16
Definition: cx16.h:227
cx16_k_fb_set_palette
void cx16_k_fb_set_palette(void *paladdr, unsigned char index, unsigned char count) __attribute__((leaf))
cx16_k_mouse_config
void cx16_k_mouse_config(unsigned char showmouse, unsigned char xsize8, unsigned char ysize8) __attribute__((leaf))
VERA_INC_0
@ VERA_INC_0
Definition: cx16.h:238
ROM_KERNAL
@ ROM_KERNAL
KERNAL operating system and drivers.
Definition: cx16.h:264
graph_fb_functions_t::fb_set_8_pixels
void * fb_set_8_pixels
Definition: cx16.h:458
ROM_UTIL
@ ROM_UTIL
System Configuration (Date/Time, Display Preferences)
Definition: cx16.h:275
vpoke
void vpoke(unsigned char data, unsigned long addr) __attribute__((leaf))
cx16_k_fb_get_info
void cx16_k_fb_get_info(cx16_fb_info_t *info_ptr) __attribute__((leaf))
w
byte byte byte w
Definition: api.h:26
ROM_CHARSET
@ ROM_CHARSET
PETSCII and ISO character sets (uploaded into VRAM)
Definition: cx16.h:270
cx16_fb_info_t::depth
unsigned char depth
Definition: cx16.h:444
ROM_GRAPH
@ ROM_GRAPH
Kernal graph and font routines.
Definition: cx16.h:272
cx16_k_graph_set_colors
void cx16_k_graph_set_colors(unsigned char stroke, unsigned char fill, unsigned char background) __attribute__((leaf))
VERA_INC_128
@ VERA_INC_128
Definition: cx16.h:246
JOY_BTN_A_MASK
@ JOY_BTN_A_MASK
Definition: cx16.h:135
cx16_k_memory_fill
void cx16_k_memory_fill(void *addr, unsigned int num_bytes, unsigned char value) __attribute__((leaf))
TV_VGA_240P
@ TV_VGA_240P
Definition: cx16.h:198
JoyState::data0
unsigned char data0
Bits: B Y Select Start Up Down Left Right.
Definition: cx16.h:152
cx16_k_memory_copy
void cx16_k_memory_copy(void *source, void *target, unsigned int num_bytes) __attribute__((leaf))
cx16_date_time_t
Definition: cx16.h:436
VERA_INC_8
@ VERA_INC_8
Definition: cx16.h:242
graph_fb_functions_t::fb_set_8_pixels_opaque
void * fb_set_8_pixels_opaque
Definition: cx16.h:459
ROM_CMDRDOS
@ ROM_CMDRDOS
The computer-based CMDR-DOS for FAT32 SD cards.
Definition: cx16.h:266
ROM_DEMO
@ ROM_DEMO
Demo routines.
Definition: cx16.h:273
cx16_k_clock_set_date_time
void cx16_k_clock_set_date_time(unsigned char year, unsigned char mon, unsigned char day, unsigned char hour, unsigned char min, unsigned char sec, unsigned char jif) __attribute__((leaf))
graph_fb_functions_t::fb_filter_pixels
void * fb_filter_pixels
Definition: cx16.h:461
VERA_DEC_320
@ VERA_DEC_320
Definition: cx16.h:236
cx16_fb_info_t::width
unsigned int width
Definition: cx16.h:443
cx16_k_mouse_get
unsigned char cx16_k_mouse_get(mouse_pos_t *mouse_pos_ptr) __attribute__((leaf))
VERA_INC_32
@ VERA_INC_32
Definition: cx16.h:244
waitvsync
void waitvsync(void)
TV_NONE2
@ TV_NONE2
Definition: cx16.h:193
cx16_k_console_put_image
void cx16_k_console_put_image(void *imageaddr, unsigned int width, unsigned int height) __attribute__((leaf))
set_tv
void set_tv(unsigned char type) __attribute__((leaf))
address
uint8_t uint16_t address
Definition: bios.h:180
mouse_pos_t::y
int y
Definition: cx16.h:472
cx16_k_graph_set_window
void cx16_k_graph_set_window(unsigned int x, unsigned int y, unsigned int width, unsigned int height) __attribute__((leaf))
ROM_MONITOR
@ ROM_MONITOR
Machine Language Monitor.
Definition: cx16.h:269
cx16_k_enter_basic
void cx16_k_enter_basic(unsigned char coldstart) __attribute__((noreturn))
graph_fb_functions_t::fb_set_pixels
void * fb_set_pixels
Definition: cx16.h:457
VERA_DEC_32
@ VERA_DEC_32
Definition: cx16.h:228
cx16_k_fb_init
void cx16_k_fb_init(void) __attribute__((leaf))
VERA_INC_80
@ VERA_INC_80
Definition: cx16.h:250
graph_pos_t::y
int y
Definition: cx16.h:467
VERA_DEC_2
@ VERA_DEC_2
Definition: cx16.h:224
ROM_DIAG
@ ROM_DIAG
Memory diagnostic.
Definition: cx16.h:271
TV_NTSC_COLOR
@ TV_NTSC_COLOR
Definition: cx16.h:191
cx16_k_fb_filter_pixels
void cx16_k_fb_filter_pixels(void *filterfunc, unsigned int count) __attribute__((leaf))
cx16_k_fb_move_pixels
void cx16_k_fb_move_pixels(unsigned int sx, unsigned int sy, unsigned int tx, unsigned int ty, unsigned int count) __attribute__((leaf))
_6522.h
cx16_k_screen_mode_set
unsigned char cx16_k_screen_mode_set(unsigned char mode) __attribute__((leaf))
cx16_k_graph_init
void cx16_k_graph_init(graph_fb_functions_t *fb_funcs_ptr) __attribute__((leaf))
ROM_BASIC
@ ROM_BASIC
BASIC interpreter.
Definition: cx16.h:268
cx16_k_kbdbuf_get_modifiers
unsigned char cx16_k_kbdbuf_get_modifiers(void) __attribute__((leaf))
VERA_INC_1
@ VERA_INC_1
Definition: cx16.h:239
TV_NONE_240P
@ TV_NONE_240P
Definition: cx16.h:197
JOY_UP_MASK
@ JOY_UP_MASK
Definition: cx16.h:130
ROM_FAT32
@ ROM_FAT32
The FAT32 driver itself.
Definition: cx16.h:267
mode
const void uint16_t uint8_t mode
Definition: memory.h:58
vera_layer_enable
unsigned char vera_layer_enable(unsigned char layers) __attribute__((leaf))
VERA_DEC_40
@ VERA_DEC_40
Definition: cx16.h:233
cx16_k_screen_set_charset
void cx16_k_screen_set_charset(unsigned char charset_type, void *charsetaddr) __attribute__((leaf))
screen_mode_info_t::rows
unsigned char rows
Definition: cx16.h:477
ROM_KEYBD
@ ROM_KEYBD
Keyboard layout tables.
Definition: cx16.h:265
cx16_k_console_put_char
void cx16_k_console_put_char(unsigned char c, unsigned char wrapwordflag) __attribute__((leaf))
VERA_INC_640
@ VERA_INC_640
Definition: cx16.h:253
cx16_k_macptr
long cx16_k_macptr(unsigned char count, unsigned char noadvance, void *destaddr) __attribute__((leaf))
JOY_DOWN_MASK
@ JOY_DOWN_MASK
Definition: cx16.h:131
graph_fb_functions_t
Definition: cx16.h:447
c
byte byte c
Definition: api.h:59
cx16_k_screen_mode_get
unsigned char cx16_k_screen_mode_get(screen_mode_info_t *info_ptr) __attribute__((leaf))
year
uint8_t year
cx16_k_entropy_get
unsigned long cx16_k_entropy_get(void) __attribute__((leaf))