mga_vid.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,405 行 · 第 1/3 页
C
1,405 行
writeb( 1, mga_mmio_base + X_DATAREG); // Disable color keying on alpha channel writeb( XCOLMSK, mga_mmio_base + PALWTADD); writeb( 0x00, mga_mmio_base + X_DATAREG); writeb( X_COLKEY, mga_mmio_base + PALWTADD); writeb( 0x00, mga_mmio_base + X_DATAREG); // Set up color key registers writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD); writeb( r, mga_mmio_base + X_DATAREG); writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD); writeb( g, mga_mmio_base + X_DATAREG); writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD); writeb( b, mga_mmio_base + X_DATAREG); // Set up color key mask registers writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD); writeb( 0xff, mga_mmio_base + X_DATAREG); writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD); writeb( 0xff, mga_mmio_base + X_DATAREG); writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD); writeb( 0xff, mga_mmio_base + X_DATAREG); } else { // Disable colorkeying writeb( XKEYOPMODE, mga_mmio_base + PALWTADD); writeb( 0, mga_mmio_base + X_DATAREG); }} // Backend Scaler writel( regs.besctl, mga_mmio_base + BESCTL); if(is_g400) writel( regs.beslumactl, mga_mmio_base + BESLUMACTL); writel( regs.bespitch, mga_mmio_base + BESPITCH); writel( regs.besa1org, mga_mmio_base + BESA1ORG); writel( regs.besa1corg, mga_mmio_base + BESA1CORG); writel( regs.besa2org, mga_mmio_base + BESA2ORG); writel( regs.besa2corg, mga_mmio_base + BESA2CORG); writel( regs.besb1org, mga_mmio_base + BESB1ORG); writel( regs.besb1corg, mga_mmio_base + BESB1CORG); writel( regs.besb2org, mga_mmio_base + BESB2ORG); writel( regs.besb2corg, mga_mmio_base + BESB2CORG); if(is_g400) { writel( regs.besa1c3org, mga_mmio_base + BESA1C3ORG); writel( regs.besa2c3org, mga_mmio_base + BESA2C3ORG); writel( regs.besb1c3org, mga_mmio_base + BESB1C3ORG); writel( regs.besb2c3org, mga_mmio_base + BESB2C3ORG); } writel( regs.beshcoord, mga_mmio_base + BESHCOORD); writel( regs.beshiscal, mga_mmio_base + BESHISCAL); writel( regs.beshsrcst, mga_mmio_base + BESHSRCST); writel( regs.beshsrcend, mga_mmio_base + BESHSRCEND); writel( regs.beshsrclst, mga_mmio_base + BESHSRCLST); writel( regs.besvcoord, mga_mmio_base + BESVCOORD); writel( regs.besviscal, mga_mmio_base + BESVISCAL); writel( regs.besv1srclst, mga_mmio_base + BESV1SRCLST); writel( regs.besv1wght, mga_mmio_base + BESV1WGHT); writel( regs.besv2srclst, mga_mmio_base + BESV2SRCLST); writel( regs.besv2wght, mga_mmio_base + BESV2WGHT); //update the registers somewhere between 1 and 2 frames from now. writel( regs.besglobctl + ((readl(mga_mmio_base + VCOUNT)+2)<<16), mga_mmio_base + BESGLOBCTL); if (mga_verbose > 1) { printf("[mga] wrote BES registers\n"); printf("[mga] BESCTL = 0x%08x\n", readl(mga_mmio_base + BESCTL)); printf("[mga] BESGLOBCTL = 0x%08x\n", readl(mga_mmio_base + BESGLOBCTL)); printf("[mga] BESSTATUS= 0x%08x\n", readl(mga_mmio_base + BESSTATUS)); }#ifdef CRTC2 writel(((readl(mga_mmio_base + C2CTL) & ~0x03e00000) + (cregs.c2ctl & 0x03e00000)), mga_mmio_base + C2CTL); writel(((readl(mga_mmio_base + C2DATACTL) & ~0x000000ff) + (cregs.c2datactl & 0x000000ff)), mga_mmio_base + C2DATACTL); // ctrc2 // disable CRTC2 acording to specs writel(cregs.c2misc, mga_mmio_base + C2MISC); if (mga_verbose > 1) printf("[mga] c2offset = %d\n",cregs.c2offset); writel(cregs.c2offset, mga_mmio_base + C2OFFSET); writel(cregs.c2startadd0, mga_mmio_base + C2STARTADD0); writel(cregs.c2pl2startadd0, mga_mmio_base + C2PL2STARTADD0); writel(cregs.c2pl3startadd0, mga_mmio_base + C2PL3STARTADD0); writel(cregs.c2spicstartadd0, mga_mmio_base + C2SPICSTARTADD0);#endif }#ifdef MGA_ALLOW_IRQstatic void enable_irq(){ long int cc; cc = readl(mga_mmio_base + IEN); writeb( 0x11, mga_mmio_base + CRTCX); writeb(0x20, mga_mmio_base + CRTCD ); /* clear 0, enable off */ writeb(0x00, mga_mmio_base + CRTCD ); /* enable on */ writeb(0x10, mga_mmio_base + CRTCD ); /* clear = 1 */ writel( regs.besglobctl , mga_mmio_base + BESGLOBCTL); return;}static void disable_irq(){ writeb( 0x11, mga_mmio_base + CRTCX); writeb(0x20, mga_mmio_base + CRTCD ); /* clear 0, enable off */ return;}void mga_handle_irq(int irq, void *dev_id/*, struct pt_regs *pregs*/) { long int cc; if ( irq != -1 ) { cc = readl(mga_mmio_base + STATUS); if ( ! (cc & 0x10) ) return; /* vsyncpen */ } regs.besctl = (regs.besctl & ~0x07000000) + (mga_next_frame << 25); writel( regs.besctl, mga_mmio_base + BESCTL ); #ifdef CRTC2// sem pridat vyber obrazku !!!! crtc2_frame_sel(mga_next_frame);#endif if ( irq != -1 ) { writeb( 0x11, mga_mmio_base + CRTCX); writeb( 0, mga_mmio_base + CRTCD ); writeb( 0x10, mga_mmio_base + CRTCD ); } return;}#endif /* MGA_ALLOW_IRQ */static int mga_config_playback(vidix_playback_t *config){ unsigned int i; int x, y, sw, sh, dw, dh; int besleft, bestop, ifactor, ofsleft, ofstop, baseadrofs, weight, weights;#ifdef CRTC2#define right_margin 0#define left_margin 18#define hsync_len 46#define lower_margin 10#define vsync_len 4#define upper_margin 39 unsigned int hdispend = (config->src.w + 31) & ~31; unsigned int hsyncstart = hdispend + (right_margin & ~7); unsigned int hsyncend = hsyncstart + (hsync_len & ~7); unsigned int htotal = hsyncend + (left_margin & ~7); unsigned int vdispend = config->src.h; unsigned int vsyncstart = vdispend + lower_margin; unsigned int vsyncend = vsyncstart + vsync_len; unsigned int vtotal = vsyncend + upper_margin;#endif if ((config->num_frames < 1) || (config->num_frames > 4)) { printf("[mga] illegal num_frames: %d, setting to %d\n", config->num_frames, MGA_DEFAULT_FRAMES); config->num_frames = MGA_DEFAULT_FRAMES; } x = config->dest.x; y = config->dest.y; sw = config->src.w; sh = config->src.h; dw = config->dest.w; dh = config->dest.h; config->dest.pitch.y=32; config->dest.pitch.u=config->dest.pitch.v=32; if (mga_verbose) printf("[mga] Setting up a %dx%d-%dx%d video window (src %dx%d) format %X\n", dw, dh, x, y, sw, sh, config->fourcc); if ((sw < 4) || (sh < 4) || (dw < 4) || (dh < 4)) { printf("[mga] Invalid src/dest dimensions\n"); return(EINVAL); } //FIXME check that window is valid and inside desktop sw+=sw&1; switch(config->fourcc) { case IMGFMT_I420: case IMGFMT_IYUV: case IMGFMT_YV12: sh+=sh&1; config->frame_size = ((sw + 31) & ~31) * sh + (((sw + 31) & ~31) * sh) / 2; break; case IMGFMT_YUY2: case IMGFMT_UYVY: config->frame_size = ((sw + 31) & ~31) * sh * 2; break; default: printf("[mga] Unsupported pixel format: %x\n", config->fourcc); return(ENOTSUP); } config->offsets[0] = 0; for (i = 1; i < config->num_frames+1; i++) config->offsets[i] = i*config->frame_size; config->offset.y=0; if(config->fourcc == IMGFMT_I420 || config->fourcc == IMGFMT_IYUV) { config->offset.u=((sw + 31) & ~31) * sh; config->offset.v=config->offset.u+((sw + 31) & ~31) * sh /4; } else { config->offset.v=((sw + 31) & ~31) * sh; config->offset.u=config->offset.v+((sw + 31) & ~31) * sh /4; } mga_src_base = (mga_ram_size*0x100000-config->num_frames*config->frame_size); if (mga_src_base < 0) { printf("[mga] not enough memory for frames!\n"); return(EFAULT); } mga_src_base &= (~0xFFFF); /* 64k boundary */ if (mga_verbose > 1) printf("[mga] YUV buffer base: %#x\n", mga_src_base); config->dga_addr = mga_mem_base + mga_src_base; /* for G200 set Interleaved UV planes */ if (!is_g400) config->flags = VID_PLAY_INTERLEAVED_UV | INTERLEAVING_UV; //Setup the BES registers for a three plane 4:2:0 video source regs.besglobctl = 0; switch(config->fourcc) { case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_IYUV: regs.besctl = 1 // BES enabled + (0<<6) // even start polarity + (1<<10) // x filtering enabled + (1<<11) // y filtering enabled + (1<<16) // chroma upsampling + (1<<17) // 4:2:0 mode + (1<<18); // dither enabled break; case IMGFMT_YUY2: regs.besctl = 1 // BES enabled + (0<<6) // even start polarity + (1<<10) // x filtering enabled + (1<<11) // y filtering enabled + (1<<16) // chroma upsampling + (0<<17) // 4:2:2 mode + (1<<18); // dither enabled regs.besglobctl = 0; // YUY2 format selected break; case IMGFMT_UYVY: regs.besctl = 1 // BES enabled + (0<<6) // even start polarity + (1<<10) // x filtering enabled + (1<<11) // y filtering enabled + (1<<16) // chroma upsampling + (0<<17) // 4:2:2 mode + (1<<18); // dither enabled regs.besglobctl = 1<<6; // UYVY format selected break; } //Disable contrast and brightness control regs.besglobctl |= (1<<5) + (1<<7); regs.beslumactl = (0x7f << 16) + (0x80<<0); regs.beslumactl = 0x80<<0; //Setup destination window boundaries besleft = x > 0 ? x : 0; bestop = y > 0 ? y : 0; regs.beshcoord = (besleft<<16) + (x + dw-1); regs.besvcoord = (bestop<<16) + (y + dh-1); //Setup source dimensions regs.beshsrclst = (sw - 1) << 16; regs.bespitch = (sw + 31) & ~31 ; //Setup horizontal scaling ifactor = ((sw-1)<<14)/(dw-1); ofsleft = besleft - x; regs.beshiscal = ifactor<<2; regs.beshsrcst = (ofsleft*ifactor)<<2; regs.beshsrcend = regs.beshsrcst + (((dw - ofsleft - 1) * ifactor) << 2); //Setup vertical scaling ifactor = ((sh-1)<<14)/(dh-1); ofstop = bestop - y; regs.besviscal = ifactor<<2; baseadrofs = ((ofstop*regs.besviscal)>>16)*regs.bespitch; regs.besa1org = (uint32_t) mga_src_base + baseadrofs; regs.besa2org = (uint32_t) mga_src_base + baseadrofs + 1*config->frame_size; regs.besb1org = (uint32_t) mga_src_base + baseadrofs + 2*config->frame_size; regs.besb2org = (uint32_t) mga_src_base + baseadrofs + 3*config->frame_size;if(config->fourcc==IMGFMT_YV12 ||config->fourcc==IMGFMT_IYUV ||config->fourcc==IMGFMT_I420 ){ // planar YUV frames: if (is_g400) baseadrofs = (((ofstop*regs.besviscal)/4)>>16)*regs.bespitch; else baseadrofs = (((ofstop*regs.besviscal)/2)>>16)*regs.bespitch; if(config->fourcc==IMGFMT_YV12){ regs.besa1corg = (uint32_t) mga_src_base + baseadrofs + regs.bespitch * sh ; regs.besa2corg = (uint32_t) mga_src_base + baseadrofs + 1*config->frame_size + regs.bespitch * sh; regs.besb1corg = (uint32_t) mga_src_base + baseadrofs + 2*config->frame_size + regs.bespitch * sh; regs.besb2corg = (uint32_t) mga_src_base + baseadrofs + 3*config->frame_size + regs.bespitch * sh; regs.besa1c3org = regs.besa1corg + ((regs.bespitch * sh) / 4); regs.besa2c3org = regs.besa2corg + ((regs.bespitch * sh) / 4); regs.besb1c3org = regs.besb1corg + ((regs.bespitch * sh) / 4); regs.besb2c3org = regs.besb2corg + ((regs.bespitch * sh) / 4); } else { regs.besa1c3org = (uint32_t) mga_src_base + baseadrofs + regs.bespitch * sh ; regs.besa2c3org = (uint32_t) mga_src_base + baseadrofs + 1*config->frame_size + regs.bespitch * sh; regs.besb1c3org = (uint32_t) mga_src_base + baseadrofs + 2*config->frame_size + regs.bespitch * sh; regs.besb2c3org = (uint32_t) mga_src_base + baseadrofs + 3*config->frame_size + regs.bespitch * sh; regs.besa1corg = regs.besa1c3org + ((regs.bespitch * sh) / 4); regs.besa2corg = regs.besa2c3org + ((regs.bespitch * sh) / 4); regs.besb1corg = regs.besb1c3org + ((regs.bespitch * sh) / 4); regs.besb2corg = regs.besb2c3org + ((regs.bespitch * sh) / 4); }} weight = ofstop * (regs.besviscal >> 2); weights = weight < 0 ? 1 : 0; regs.besv2wght = regs.besv1wght = (weights << 16) + ((weight & 0x3FFF) << 2); regs.besv2srclst = regs.besv1srclst = sh - 1 - (((ofstop * regs.besviscal) >> 16) & 0x03FF);#ifdef CRTC2 // pridat hlavni registry - tj. casovani ...switch(config->fourcc){ case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_IYUV: cregs.c2ctl = 1 // CRTC2 enabled + (1<<1) // external clock + (0<<2) // external clock + (1<<3) // pixel clock enable - not needed ??? + (0<<4) // high prioryty req + (1<<5) // high prioryty req + (0<<6) // high prioryty req + (1<<8) // high prioryty req max + (0<<9) // high prioryty req max + (0<<10) // high prioryty req max + (0<<20) // CRTC1 to DAC + (1<<21) // 420 mode + (1<<22) // 420 mode + (1<<23) // 420 mode + (0<<24) // single chroma line for 420 mode - need to be corrected + (0<<25) /*/ interlace mode - need to be corrected*/ + (0<<26) // field legth polariry + (0<<27) // field identification polariry + (1<<28) // VIDRST detection mode + (0<<29) // VIDRST detection mode + (1<<30) // Horizontal counter preload + (1<<31) // Vertical counter preload ; cregs.c2datactl = 1 // disable dither - propably not needed, we are already in YUV mode + (1<<1) // Y filter enable + (1<<2) // CbCr filter enable + (0<<3) // subpicture enable (disabled) + (0<<4) // NTSC enable (disabled - PAL) + (0<<5) // C2 static subpicture enable (disabled) + (0<<6) // C2 subpicture offset division (disabled) + (0<<7) // 422 subformat selection !/* + (0<<8) // 15 bpp high alpha + (0<<9) // 15 bpp high alpha + (0<<10) // 15 bpp high alpha + (0<<11) // 15 bpp high alpha + (0<<12) // 15 bpp high alpha + (0<<13) // 15 bpp high alpha + (0<<14) // 15 bpp high alpha + (0<<15) // 15 bpp high alpha + (0<<16) // 15 bpp low alpha + (0<<17) // 15 bpp low alpha + (0<<18) // 15 bpp low alpha + (0<<19) // 15 bpp low alpha + (0<<20) // 15 bpp low alpha + (0<<21) // 15 bpp low alpha + (0<<22) // 15 bpp low alpha + (0<<23) // 15 bpp low alpha + (0<<24) // static subpicture key + (0<<25) // static subpicture key + (0<<26) // static subpicture key + (0<<27) // static subpicture key + (0<<28) // static subpicture key*/ ; break; case IMGFMT_YUY2: cregs.c2ctl = 1 // CRTC2 enabled + (1<<1) // external clock + (0<<2) // external clock + (1<<3) // pixel clock enable - not needed ??? + (0<<4) // high prioryty req - acc to spec + (1<<5) // high prioryty req + (0<<6) // high prioryty req // 7 reserved + (1<<8) // high prioryty req max + (0<<9) // high prioryty req max + (0<<10) // high prioryty req max // 11-19 reserved + (0<<20) // CRTC1 to DAC + (1<<21) // 422 mode + (0<<22) // 422 mode + (1<<23) // 422 mode + (0<<24) // single chroma line for 420 mode - need to be corrected + (0<<25) /*/ interlace mode - need to be corrected*/ + (0<<26) // field legth polariry + (0<<27) // field identification polariry + (1<<28) // VIDRST detection mode + (0<<29) // VIDRST detection mode + (1<<30) // Horizontal counter preload + (1<<31) // Vertical counter preload ; cregs.c2datactl = 1 // disable dither - propably not needed, we are already in YUV mode + (1<<1) // Y filter enable + (1<<2) // CbCr filter enable + (0<<3) // subpicture enable (disabled) + (0<<4) // NTSC enable (disabled - PAL) + (0<<5) // C2 static subpicture enable (disabled) + (0<<6) // C2 subpicture offset division (disabled) + (0<<7) // 422 subformat selection !/* + (0<<8) // 15 bpp high alpha + (0<<9) // 15 bpp high alpha + (0<<10) // 15 bpp high alpha + (0<<11) // 15 bpp high alpha
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?