libdragon
vi.h
Go to the documentation of this file.
1
6#ifndef __LIBDRAGON_VI_H
7#define __LIBDRAGON_VI_H
8
9#include <stdint.h>
10#include <stdbool.h>
11#include "regsinternal.h"
12#include "n64sys.h"
13
20#define VI_REGISTERS_ADDR 0xA4400000
22#define VI_REGISTERS_COUNT 14
23
31typedef struct vi_config_s{
32 uint32_t regs[VI_REGISTERS_COUNT];
34
37#define VI_REGISTERS ((volatile uint32_t*)VI_REGISTERS_ADDR)
39#define VI_CTRL (&VI_REGISTERS[0])
41#define VI_ORIGIN (&VI_REGISTERS[1])
43#define VI_WIDTH (&VI_REGISTERS[2])
45#define VI_V_INTR (&VI_REGISTERS[3])
47#define VI_V_CURRENT (&VI_REGISTERS[4])
49#define VI_BURST (&VI_REGISTERS[5])
52#define VI_V_SYNC (&VI_REGISTERS[6])
54#define VI_H_SYNC (&VI_REGISTERS[7])
56#define VI_H_SYNC_LEAP (&VI_REGISTERS[8])
58#define VI_H_VIDEO (&VI_REGISTERS[9])
60#define VI_V_VIDEO (&VI_REGISTERS[10])
62#define VI_V_BURST (&VI_REGISTERS[11])
64#define VI_X_SCALE (&VI_REGISTERS[12])
66#define VI_Y_SCALE (&VI_REGISTERS[13])
67
69#define VI_TO_REGISTER(index) (((index) >= 0 && (index) <= VI_REGISTERS_COUNT)? &VI_REGISTERS[index] : NULL)
70
72#define VI_TO_INDEX(reg) ((reg) - VI_REGISTERS)
73
79static const vi_config_t vi_ntsc_p = {.regs = {
80 0x00000000, 0x00000000, 0x00000000, 0x00000002,
81 0x00000000, 0x03e52239, 0x0000020d, 0x00000c15,
82 0x0c150c15, 0x006c02ec, 0x002501ff, 0x000e0204,
83 0x00000000, 0x00000000 }};
84static const vi_config_t vi_pal_p = {.regs = {
85 0x00000000, 0x00000000, 0x00000000, 0x00000002,
86 0x00000000, 0x0404233a, 0x00000271, 0x00150c69,
87 0x0c6f0c6e, 0x00800300, 0x005f0239, 0x0009026b,
88 0x00000000, 0x00000000 }};
89static const vi_config_t vi_mpal_p = {.regs = {
90 0x00000000, 0x00000000, 0x00000000, 0x00000002,
91 0x00000000, 0x04651e39, 0x0000020d, 0x00040c11,
92 0x0c190c1a, 0x006c02ec, 0x002501ff, 0x000e0204,
93 0x00000000, 0x00000000 }};
94static const vi_config_t vi_ntsc_i = {.regs = {
95 0x00000000, 0x00000000, 0x00000000, 0x00000002,
96 0x00000000, 0x03e52239, 0x0000020c, 0x00000c15,
97 0x0c150c15, 0x006c02ec, 0x002301fd, 0x000e0204,
98 0x00000000, 0x00000000 }};
99static const vi_config_t vi_pal_i = {.regs = {
100 0x00000000, 0x00000000, 0x00000000, 0x00000002,
101 0x00000000, 0x0404233a, 0x00000270, 0x00150c69,
102 0x0c6f0c6e, 0x00800300, 0x005d0237, 0x0009026b,
103 0x00000000, 0x00000000 }};
104static const vi_config_t vi_mpal_i = {.regs = {
105 0x00000000, 0x00000000, 0x00000000, 0x00000002,
106 0x00000000, 0x04651e39, 0x0000020c, 0x00000c10,
107 0x0c1c0c1c, 0x006c02ec, 0x002301fd, 0x000b0202,
108 0x00000000, 0x00000000 }};
112static const vi_config_t vi_config_presets[2][3] = {
113 {vi_pal_p, vi_ntsc_p, vi_mpal_p},
114 {vi_pal_i, vi_ntsc_i, vi_mpal_i}
115};
116
120#define VI_DEDITHER_FILTER_ENABLE (1<<16)
122#define VI_PIXEL_ADVANCE_DEFAULT (0b0011 << 12)
124#define VI_PIXEL_ADVANCE_BBPLAYER (0b0001 << 12)
126#define VI_AA_MODE_NONE (0b11 << 8)
128#define VI_AA_MODE_RESAMPLE (0b10 << 8)
130#define VI_AA_MODE_RESAMPLE_FETCH_NEEDED (0b01 << 8)
132#define VI_AA_MODE_RESAMPLE_FETCH_ALWAYS (0b00 << 8)
134#define VI_CTRL_SERRATE (1<<6)
136#define VI_DIVOT_ENABLE (1<<4)
138#define VI_GAMMA_ENABLE (1<<3)
140#define VI_GAMMA_DITHER_ENABLE (1<<2)
142#define VI_CTRL_TYPE (0b11)
144#define VI_CTRL_TYPE_32_BPP (0b11)
146#define VI_CTRL_TYPE_16_BPP (0b10)
148#define VI_CTRL_TYPE_BLANK (0b00)
149
152#define VI_ORIGIN_SET(value) ((value & 0xFFFFFF) << 0)
153
156#define VI_WIDTH_SET(value) ((value & 0xFFF) << 0)
157
160#define VI_V_CURRENT_VBLANK 2
161
164#define VI_V_INTR_SET(value) ((value & 0x3FF) << 0)
166#define VI_V_INTR_DEFAULT 0x3FF
167
170#define VI_BURST_START(value) ((value & 0x3F) << 20)
172#define VI_VSYNC_WIDTH(value) ((value & 0x7) << 16)
174#define VI_BURST_WIDTH(value) ((value & 0xFF) << 8)
176#define VI_HSYNC_WIDTH(value) ((value & 0xFF) << 0)
177
179#define VI_BURST_START_NTSC 62
181#define VI_VSYNC_WIDTH_NTSC 5
183#define VI_BURST_WIDTH_NTSC 34
185#define VI_HSYNC_WIDTH_NTSC 57
186
188#define VI_BURST_START_PAL 64
190#define VI_VSYNC_WIDTH_PAL 4
192#define VI_BURST_WIDTH_PAL 35
194#define VI_HSYNC_WIDTH_PAL 58
195
198#define VI_X_SCALE_SET(value) (( 1024*(value) + 320 ) / 640)
199
202#define VI_Y_SCALE_SET(value) (( 1024*(value) + 120 ) / 240)
203
212inline void vi_write_safe(volatile uint32_t *reg, uint32_t value){
213 assert(reg); /* This should never happen */
214 *reg = value;
216}
217
224inline void vi_write_config(const vi_config_t* config)
225{
226 /* This should never happen */
227 assert(config);
228
229 /* Just straight copy */
230 for( int i = 0; i < VI_REGISTERS_COUNT; i++ )
231 {
232 /* Don't clear interrupts */
233 if( i == 3 ) { continue; }
234 if( i == 4 ) { continue; }
235
236 *VI_TO_REGISTER(i) = config->regs[i];
238 }
239}
240
247static inline void vi_write_dram_register( void const * const dram_val )
248{
251}
252
254static inline void vi_wait_for_vblank()
255{
256 while(*VI_V_CURRENT != VI_V_CURRENT_VBLANK ) { }
257}
258
260static inline bool vi_is_active()
261{
263}
264
266static inline void vi_set_blank_image()
267{
269}
270
271
272#ifdef __cplusplus
273extern "C" {
274#endif
275
276
277#ifdef __cplusplus
278}
279#endif
280 /* vi */
282
283#endif
#define VI_CTRL_TYPE_BLANK
VI_CTRL Register setting: set the framebuffer source as blank (no data and no sync,...
Definition: vi.h:148
#define VI_CTRL_TYPE
VI_CTRL Register setting: framebuffer source format.
Definition: vi.h:142
#define VI_TO_REGISTER(index)
VI register by index (0-13)
Definition: vi.h:69
#define VI_V_CURRENT
VI Index register of the current half line, sampled once per line.
Definition: vi.h:47
void vi_write_config(const vi_config_t *config)
Write a set of video registers to the VI.
Definition: vi.h:224
#define VI_H_VIDEO
VI Index register of start/end of the active video image, in screen pixels.
Definition: vi.h:58
void vi_write_safe(volatile uint32_t *reg, uint32_t value)
Write a set of video registers to the VI.
Definition: vi.h:212
#define VI_V_CURRENT_VBLANK
VI_V_CURRENT Register: default value for vblank begin line.
Definition: vi.h:160
#define VI_REGISTERS_COUNT
Number of useful 32-bit registers at the register base.
Definition: vi.h:22
#define VI_CTRL
VI Index register of controlling general display filters/bitdepth configuration.
Definition: vi.h:39
#define VI_ORIGIN
VI Index register of RDRAM base address of the video output Frame Buffer. This can be changed as need...
Definition: vi.h:41
#define VI_ORIGIN_SET(value)
VI_ORIGIN Register: set the address of a framebuffer.
Definition: vi.h:152
Video Interface register structure.
Definition: vi.h:31
#define PhysicalAddr(_addr)
Return the physical memory address for a given address.
Definition: n64sys.h:108
#define MEMORY_BARRIER()
Memory barrier to ensure in-order execution.
Definition: n64sys.h:134
N64 System Interface.
Register definitions for various hardware in the N64.