llvm-mos-sdk
supervision.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 Adrian "asie" Siekierka
3  *
4  * Licensed under the Apache License, Version 2.0 with LLVM Exceptions,
5  * See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
6  * information.
7  */
8 
9 #include <stdint.h>
10 
11 #ifndef _SUPERVISION_H
12 #define _SUPERVISION_H
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #define SV_SYSTEM_CLOCK_HZ 4000000
19 #define SV_LCD_WIDTH 160
20 #define SV_LCD_HEIGHT 160
21 
22 #define SV_TRIGGER_START 0x80
23 #define SV_TRIGGER_STOP 0x00
24 
25 struct __sv_lcd {
26  uint8_t width;
27  uint8_t height;
28  uint8_t x;
29  uint8_t y;
30 };
31 #define SV_LCD (*(volatile struct __sv_lcd*) 0x2000)
32 
33 struct __sv_vdma {
34  const void *cpu;
35  uint16_t vram;
37  uint8_t trigger;
38 };
39 #define SV_VDMA (*(volatile struct __sv_vdma*) 0x2008)
40 #define SV_VDMA_FROM_VRAM(addr) ((uint16_t) (addr))
41 #define SV_VDMA_TO_VRAM(addr) (((uint16_t) (addr)) | 0x4000)
42 
43 struct __sv_tone {
44  uint16_t divider;
45  uint8_t control;
47 };
48 #define SV_AUDIO_TONE_R (*(volatile struct __sv_tone*) 0x2010)
49 #define SV_AUDIO_TONE_L (*(volatile struct __sv_tone*) 0x2014)
50 
51 #define SV_AUDIO_TONE_REPEAT 0x40
52 #define SV_AUDIO_TONE_ONESHOT 0x00
53 #define SV_AUDIO_TONE_DUTY_12_5 0x00
54 #define SV_AUDIO_TONE_DUTY_25 0x10
55 #define SV_AUDIO_TONE_DUTY_50 0x20
56 #define SV_AUDIO_TONE_DUTY_75 0x30
57 #define SV_AUDIO_TONE_VOLUME(n) (n)
58 
59 struct __sv_noise {
60  uint8_t voldiv;
62  uint8_t control;
63 };
64 #define SV_AUDIO_NOISE (*(volatile strut __sv_noise*) 0x2028)
65 
66 #define SV_AUDIO_NOISE_DIV_8 0x00
67 #define SV_AUDIO_NOISE_DIV_16 0x01
68 #define SV_AUDIO_NOISE_DIV_32 0x02
69 #define SV_AUDIO_NOISE_DIV_64 0x03
70 #define SV_AUDIO_NOISE_DIV_128 0x04
71 #define SV_AUDIO_NOISE_DIV_256 0x05
72 #define SV_AUDIO_NOISE_DIV_512 0x06
73 #define SV_AUDIO_NOISE_DIV_1024 0x07
74 #define SV_AUDIO_NOISE_DIV_2048 0x08
75 #define SV_AUDIO_NOISE_DIV_4096 0x09
76 #define SV_AUDIO_NOISE_DIV_8192 0x0A
77 #define SV_AUDIO_NOISE_DIV_16384 0x0B
78 #define SV_AUDIO_NOISE_DIV_32768 0x0C
79 #define SV_AUDIO_NOISE_DIV_65536 0x0D
80 
81 #define SV_AUDIO_NOISE_ENABLE 0x10
82 #define SV_AUDIO_NOISE_LEFT 0x08
83 #define SV_AUDIO_NOISE_RIGHT 0x04
84 #define SV_AUDIO_NOISE_MONO 0x0C
85 #define SV_AUDIO_NOISE_REPEAT 0x02
86 #define SV_AUDIO_NOISE_ONESHOT 0x00
87 #define SV_AUDIO_NOISE_TAP_15 0x01
88 #define SV_AUDIO_NOISE_TAP_7 0x00
89 
90 struct __sv_adma {
91  const void *src;
93  uint8_t control;
94  uint8_t trigger;
95 };
96 #define SV_AUDIO_DMA (*(volatile struct __sv_adma*) 0x2018)
97 
98 #define SV_AUDIO_DMA_BANK(n) ((n) << 4)
99 #define SV_AUDIO_DMA_LEFT 0x08
100 #define SV_AUDIO_DMA_RIGHT 0x04
101 #define SV_AUDIO_DMA_MONO 0x0C
102 #define SV_AUDIO_DMA_DIV_256 0x00
103 #define SV_AUDIO_DMA_DIV_512 0x01
104 #define SV_AUDIO_DMA_DIV_1024 0x02
105 #define SV_AUDIO_DMA_DIV_2048 0x03
106 
107 #define SV_JOY (*(volatile uint8_t *) 0x2020)
108 #define SV_JOY_START 0x80
109 #define SV_JOY_SELECT 0x40
110 #define SV_JOY_A 0x20
111 #define SV_JOY_B 0x10
112 #define SV_JOY_UP 0x08
113 #define SV_JOY_DOWN 0x04
114 #define SV_JOY_LEFT 0x02
115 #define SV_JOY_RIGHT 0x01
116 
117 struct __sv_link {
118  uint8_t data;
119  uint8_t dir;
120 };
121 #define SV_LINK (*(volatile struct __sv_link*) 0x2021)
122 
123 struct __sv_sys {
124  uint8_t timer_divider;
125  uint8_t irq_timer_ack;
126  uint8_t irq_audio_dma_ack;
127  uint8_t control;
128  uint8_t irq_status;
129 };
130 #define SV_SYS (*(volatile struct __sv_sys*) 0x2023)
131 
132 #define SV_IRQ_STATUS_TIMER 0x01
133 #define SV_IRQ_STATUS_AUDIO_DMA 0x02
134 
135 #define SV_SYS_NMI_ENABLE 0x01
136 #define SV_SYS_NMI_DISABLE 0x00
137 #define SV_SYS_IRQ_TIMER_ENABLE 0x02
138 #define SV_SYS_IRQ_TIMER_DISABLE 0x00
139 #define SV_SYS_IRQ_AUDIO_DMA_ENABLE 0x04
140 #define SV_SYS_IRQ_AUDIO_DMA_DISABLE 0x00
141 #define SV_SYS_LCD_ENABLE 0x08
142 #define SV_SYS_LCD_DISABLE 0x00
143 #define SV_SYS_TIMER_PRESCALER_256 0x00
144 #define SV_SYS_TIMER_PRESCALER_16384 0x10
145 #define SV_SYS_BANK_MASK 0xE0
146 #define SV_SYS_BANK(n) ((n) << 5)
147 
148 #define SV_RAM ((uint8_t*) 0x0000)
149 #define SV_VRAM ((uint8_t*) 0x4000)
150 #define SV_ROM ((uint8_t*) 0x8000)
151 #define SV_ROM_FIXED ((uint8_t*) 0xC000)
152 
153 #define SV_VRAM_WIDTH 192
154 #define SV_VRAM_HEIGHT 170
155 #define SV_VRAM_PITCH 48
156 #define SV_VRAM_ROW(y) ((uint8_t*) (0x4000 + ((y) * SV_VRAM_PITCH)))
157 
158 #define SV_COLOR_WHITE 0x00
159 #define SV_COLOR_LIGHT_GREY 0x01
160 #define SV_COLOR_DARK_GREY 0x02
161 #define SV_COLOR_BLACK 0x03
162 
164 void sv_sys_control_set(uint8_t value);
165 void sv_lcd_init(void);
166 void sv_lcd_clear(void);
167 void sv_lcd_enable(void);
168 void sv_lcd_disable(void);
169 void sv_dma_to_vram(void *dest, const void *src, uint16_t len);
170 void sv_dma_from_vram(void *dest, const void *src, uint16_t len);
171 
178 __attribute__((leaf, callback(2))) void banked_call(uint8_t bank_id,
179  void (*method)(void));
180 __attribute__((leaf)) uint8_t sv_bank_get(void);
181 __attribute__((leaf)) void sv_bank_set(uint8_t id);
182 
183 #define SV_CART_ROM_KB(kb) \
184  asm(".globl __cart_rom_size\n__cart_rom_size = " #kb)
185 
186 #ifdef __cplusplus
187 }
188 #endif
189 
190 #endif
sv_lcd_init
void sv_lcd_init(void)
std::uint16_t
::uint16_t uint16_t
Definition: cstdint:22
data
char const void * data
Definition: neslib.h:92
sv_dma_from_vram
void sv_dma_from_vram(void *dest, const void *src, uint16_t len)
sv_sys_control_get
uint8_t sv_sys_control_get(void)
sv_lcd_enable
void sv_lcd_enable(void)
length
uint8_t uint16_t uint16_t length
Definition: bios.h:181
std::uint8_t
::uint8_t uint8_t
Definition: cstdint:21
sv_lcd_clear
void sv_lcd_clear(void)
sv_dma_to_vram
void sv_dma_to_vram(void *dest, const void *src, uint16_t len)
src
const void * src
Definition: memory.h:57
x
byte x
Definition: api.h:26
y
byte byte y
Definition: api.h:26
method
void(* method)(void))
Definition: supervision.h:179
dir
byte byte byte byte byte dir
Definition: api.h:114
bank_id
char bank_id
Definition: mapper.h:97
sv_lcd_disable
void sv_lcd_disable(void)
sv_sys_control_set
void sv_sys_control_set(uint8_t value)
len
char len
Definition: nesdoug.h:26