vga_vmode.h
1 // **************************************************************************** 2 // 3 // VGA videomodes 4 // 5 // file derived from the PicoVGA project 6 // https://github.com/Panda381/PicoVGA 7 // by Miroslav Nemecek 8 // 9 // **************************************************************************** 10 11 #ifndef _VGA_VMODE_H 12 #define _VGA_VMODE_H 13 14 // video timings 15 typedef struct { 16 // horizontal 17 float htot; // total scanline in [us] 18 float hfront; // H front porch (after image, before HSYNC) in [us] 19 float hsync; // H sync pulse in [us] 20 float hback; // H back porch (after HSYNC, before image) in [us] 21 float hfull; // H full visible in [us] (corresponding to 'wfull' pixels) 22 23 // vertical 24 u16 vtot; // total scanlines (both subframes) 25 u16 vmax; // maximal height 26 27 // frame 28 u16 vsync; // V sync (half-)pulses 29 u16 vpost; // V sync post half-pulses 30 u16 vback; // V back porch (after VSYNC, before image) 31 u16 vact; // active visible scanlines 32 u16 vfront; // V front porch (after image, before VSYNC) 33 u16 vpre; // V sync pre half-pulses 34 35 bool psync; // positive synchronization 36 } sVideo; 37 38 39 // === Monitor videomodes 40 41 // EGA 8:5 640x400 (5:4 500x400, 4:3 528x400, 16:9 704x400), vert. 70 Hz, hor. 31.4685 kHz, pixel clock 25.175 MHz 42 extern const sVideo VideoEGA; 43 // VGA 4:3 640x480 (16:9 848x480), vert. 60 Hz, hor. 31.4685 kHz, pixel clock 25.175 MHz 44 extern const sVideo VideoVGA; 45 46 47 48 // required configuration to initialize VGA output 49 typedef struct { 50 u16 width; // width in pixels 51 u16 height; // height in lines 52 u16 wfull; // width of full screen, corresponding to 'hfull' time (0=use 'width' parameter) 53 const sVideo* video; // used video timings 54 u32 freq; // required minimal system frequency in kHz (real frequency can be higher) 55 u32 fmax; // maximal system frequency in kHz (limit resolution if needed) 56 bool dbly; // double in Y direction 57 bool lockfreq; // lock required frequency, do not change it 58 } sVgaCfg; 59 60 // videomode table - used to setup video driver 61 typedef struct { 62 // screen resolution 63 u16 width; // width in pixels 64 u16 height; // height in lines 65 u16 wfull; // width of full screen (corresponding to 'hfull' time) 66 u16 wmax; // maximal width (corresponding to 'hmax' time) 67 68 // setup PLL system clock 69 u32 freq; // system clock frequency in kHz 70 u32 vco; // VCO frequency in kHz 71 u16 fbdiv; // fbdiv PLL divider 72 u8 pd1; // postdiv1 73 u8 pd2; // postdiv2 74 75 // setup PIO state machine 76 u16 div; // divide base state machine clock 77 u16 cpp; // state machine clocks per pixel 78 u8 prog; // layer program LAYERPROG_* 79 80 // horizontal timings 81 u16 htot; // total state machine clocks per line 82 u16 hfront; // H front porch in state machine clocks (min. 2) 83 u16 hsync; // H sync pulse in state machine clocks (min. 4) 84 u16 hback; // H back porch in state machine clocks (min. 13) 85 float hfreq; // horizontal frequency in [Hz] 86 87 // vertical timings 88 u16 vtot; // total scanlines (both sub-frames) 89 u16 vmax; // maximal height 90 float vfreq; // vertical frequency in [Hz] 91 92 // frame 93 u16 vsync; // V sync (half-)pulses 94 u16 vpost; // V sync post (half-)pulses 95 u16 vback; // V back porch (after VSYNC, before image) 96 u16 vact; // active visible scanlines 97 u16 vfront; // V front porch (after image, before VSYNC) 98 u16 vpre; // V sync pre (half-)pulses 99 u16 vfirst; // first active scanline 100 101 // flags 102 bool lockfreq; // lock current frequency, do not change it 103 bool dbly; // double scanlines 104 bool psync; // positive synchronization 105 } sVmode; 106 107 // output device 108 enum { 109 DEV_VGA=0, // VGA monitor 110 111 DEV_MAX 112 }; 113 114 // preset videomode resolution 115 enum { 116 RES_ZX = 0, // 256x192 117 RES_CGA, // 320x200 118 RES_QVGA, // 320x240 119 RES_EGA, // 512x400 120 RES_VGA, // 640x480 121 122 RES_MAX 123 }; 124 125 126 extern sVmode Vmode; // videomode setup 127 extern sVgaCfg Cfg; // required configuration 128 129 // initialize default VGA configuration 130 void VgaCfgDef(sVgaCfg* cfg); 131 132 // calculate videomode setup 133 // cfg ... required configuration 134 // vmode ... destination videomode setup for driver 135 void VgaCfg(const sVgaCfg* cfg, sVmode* vmode); 136 137 // initialize videomode 138 // dev ... device DEV_* 139 // res ... resolution RES_* 140 const sVmode* Video(u8 dev, u8 res); 141 142 #endif // _VGA_VMODE_H