libdragon
Loading...
Searching...
No Matches
vi.h
Go to the documentation of this file.
1
7#ifndef __LIBDRAGON_VI_H
8#define __LIBDRAGON_VI_H
9
10#include <stdint.h>
11#include <stdbool.h>
12#include "regsinternal.h"
13#include "n64sys.h"
14
21#define VI_REGISTERS_ADDR 0xA4400000
23#define VI_REGISTERS_COUNT 14
24
32typedef struct vi_config_s{
33 uint32_t regs[VI_REGISTERS_COUNT];
35
38#define VI_REGISTERS ((volatile uint32_t*)VI_REGISTERS_ADDR)
40#define VI_CTRL (&VI_REGISTERS[0])
42#define VI_ORIGIN (&VI_REGISTERS[1])
44#define VI_WIDTH (&VI_REGISTERS[2])
46#define VI_V_INTR (&VI_REGISTERS[3])
48#define VI_V_CURRENT (&VI_REGISTERS[4])
50#define VI_BURST (&VI_REGISTERS[5])
53#define VI_V_SYNC (&VI_REGISTERS[6])
55#define VI_H_SYNC (&VI_REGISTERS[7])
57#define VI_H_SYNC_LEAP (&VI_REGISTERS[8])
59#define VI_H_VIDEO (&VI_REGISTERS[9])
61#define VI_V_VIDEO (&VI_REGISTERS[10])
63#define VI_V_BURST (&VI_REGISTERS[11])
65#define VI_X_SCALE (&VI_REGISTERS[12])
67#define VI_Y_SCALE (&VI_REGISTERS[13])
68
70#define VI_TO_REGISTER(index) (((index) >= 0 && (index) <= VI_REGISTERS_COUNT)? &VI_REGISTERS[index] : NULL)
71
73#define VI_TO_INDEX(reg) ((reg) - VI_REGISTERS)
74
80static const vi_config_t vi_ntsc_p = {.regs = {
81 0x00000000, 0x00000000, 0x00000000, 0x00000002,
82 0x00000000, 0x03e52239, 0x0000020d, 0x00000c15,
83 0x0c150c15, 0x006c02ec, 0x002501ff, 0x000e0204,
84 0x00000000, 0x00000000 }};
85static const vi_config_t vi_pal_p = {.regs = {
86 0x00000000, 0x00000000, 0x00000000, 0x00000002,
87 0x00000000, 0x0404233a, 0x00000271, 0x00150c69,
88 0x0c6f0c6e, 0x00800300, 0x005f0239, 0x0009026b,
89 0x00000000, 0x00000000 }};
90static const vi_config_t vi_mpal_p = {.regs = {
91 0x00000000, 0x00000000, 0x00000000, 0x00000002,
92 0x00000000, 0x04651e39, 0x0000020d, 0x00040c11,
93 0x0c190c1a, 0x006c02ec, 0x002501ff, 0x000e0204,
94 0x00000000, 0x00000000 }};
95static const vi_config_t vi_ntsc_i = {.regs = {
96 0x00000000, 0x00000000, 0x00000000, 0x00000002,
97 0x00000000, 0x03e52239, 0x0000020c, 0x00000c15,
98 0x0c150c15, 0x006c02ec, 0x002301fd, 0x000e0204,
99 0x00000000, 0x00000000 }};
100static const vi_config_t vi_pal_i = {.regs = {
101 0x00000000, 0x00000000, 0x00000000, 0x00000002,
102 0x00000000, 0x0404233a, 0x00000270, 0x00150c69,
103 0x0c6f0c6e, 0x00800300, 0x005d0237, 0x0009026b,
104 0x00000000, 0x00000000 }};
105static const vi_config_t vi_mpal_i = {.regs = {
106 0x00000000, 0x00000000, 0x00000000, 0x00000002,
107 0x00000000, 0x04651e39, 0x0000020c, 0x00000c10,
108 0x0c1c0c1c, 0x006c02ec, 0x002301fd, 0x000b0202,
109 0x00000000, 0x00000000 }};
113static const vi_config_t vi_config_presets[2][3] = {
114 {vi_pal_p, vi_ntsc_p, vi_mpal_p},
115 {vi_pal_i, vi_ntsc_i, vi_mpal_i}
116};
117
121#define VI_DEDITHER_FILTER_ENABLE (1<<16)
123#define VI_PIXEL_ADVANCE_DEFAULT (0b0011 << 12)
125#define VI_PIXEL_ADVANCE_BBPLAYER (0b0001 << 12)
127#define VI_AA_MODE_NONE (0b11 << 8)
129#define VI_AA_MODE_RESAMPLE (0b10 << 8)
131#define VI_AA_MODE_RESAMPLE_FETCH_NEEDED (0b01 << 8)
133#define VI_AA_MODE_RESAMPLE_FETCH_ALWAYS (0b00 << 8)
135#define VI_CTRL_SERRATE (1<<6)
137#define VI_DIVOT_ENABLE (1<<4)
139#define VI_GAMMA_ENABLE (1<<3)
141#define VI_GAMMA_DITHER_ENABLE (1<<2)
143#define VI_CTRL_TYPE (0b11)
145#define VI_CTRL_TYPE_32_BPP (0b11)
147#define VI_CTRL_TYPE_16_BPP (0b10)
149#define VI_CTRL_TYPE_BLANK (0b00)
150
153#define VI_ORIGIN_SET(value) ((value & 0xFFFFFF) << 0)
154
157#define VI_WIDTH_SET(value) ((value & 0xFFF) << 0)
158
161#define VI_V_CURRENT_VBLANK 2
162
165#define VI_V_INTR_SET(value) ((value & 0x3FF) << 0)
167#define VI_V_INTR_DEFAULT 0x3FF
168
171#define VI_BURST_START(value) ((value & 0x3F) << 20)
173#define VI_VSYNC_WIDTH(value) ((value & 0x7) << 16)
175#define VI_BURST_WIDTH(value) ((value & 0xFF) << 8)
177#define VI_HSYNC_WIDTH(value) ((value & 0xFF) << 0)
178
180#define VI_BURST_START_NTSC 62
182#define VI_VSYNC_WIDTH_NTSC 5
184#define VI_BURST_WIDTH_NTSC 34
186#define VI_HSYNC_WIDTH_NTSC 57
187
189#define VI_BURST_START_PAL 64
191#define VI_VSYNC_WIDTH_PAL 4
193#define VI_BURST_WIDTH_PAL 35
195#define VI_HSYNC_WIDTH_PAL 58
196
199#define VI_X_SCALE_SET(value) (( 1024*(value) + 320 ) / 640)
200
203#define VI_Y_SCALE_SET(value) (( 1024*(value) + 120 ) / 240)
204
213inline void vi_write_safe(volatile uint32_t *reg, uint32_t value){
214 assert(reg); /* This should never happen */
215 *reg = value;
217}
218
225inline void vi_write_config(const vi_config_t* config)
226{
227 /* This should never happen */
228 assert(config);
229
230 /* Just straight copy */
231 for( int i = 0; i < VI_REGISTERS_COUNT; i++ )
232 {
233 /* Don't clear interrupts */
234 if( i == 3 ) { continue; }
235 if( i == 4 ) { continue; }
236
237 *VI_TO_REGISTER(i) = config->regs[i];
239 }
240}
241
248static inline void vi_write_dram_register( void const * const dram_val )
249{
252}
253
255static inline void vi_wait_for_vblank()
256{
257 while(*VI_V_CURRENT != VI_V_CURRENT_VBLANK ) { }
258}
259
261static inline bool vi_is_active()
262{
264}
265
267static inline void vi_set_blank_image()
268{
270}
271
272
273#ifdef __cplusplus
274extern "C" {
275#endif
276
277
278#ifdef __cplusplus
279}
280#endif
281
/* vi */
283
284#endif
#define VI_CTRL_TYPE_BLANK
VI_CTRL Register setting: set the framebuffer source as blank (no data and no sync,...
Definition vi.h:149
#define VI_CTRL_TYPE
VI_CTRL Register setting: framebuffer source format.
Definition vi.h:143
#define VI_TO_REGISTER(index)
VI register by index (0-13)
Definition vi.h:70
#define VI_V_CURRENT
VI Index register of the current half line, sampled once per line.
Definition vi.h:48
void vi_write_config(const vi_config_t *config)
Write a set of video registers to the VI.
Definition vi.h:225
#define VI_H_VIDEO
VI Index register of start/end of the active video image, in screen pixels.
Definition vi.h:59
void vi_write_safe(volatile uint32_t *reg, uint32_t value)
Write a set of video registers to the VI.
Definition vi.h:213
#define VI_V_CURRENT_VBLANK
VI_V_CURRENT Register: default value for vblank begin line.
Definition vi.h:161
#define VI_REGISTERS_COUNT
Number of useful 32-bit registers at the register base.
Definition vi.h:23
#define VI_CTRL
VI Index register of controlling general display filters/bitdepth configuration.
Definition vi.h:40
#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:42
#define VI_ORIGIN_SET(value)
VI_ORIGIN Register: set the address of a framebuffer.
Definition vi.h:153
Video Interface register structure.
Definition vi.h:32
#define PhysicalAddr(_addr)
Return the physical memory address for a given address.
Definition n64sys.h:124
#define MEMORY_BARRIER()
Memory barrier to ensure in-order execution.
Definition n64sys.h:150
N64 System Interface.
Register definitions for various hardware in the N64.