From 8643e457fa1fc84987018caf6e5394071d937dad Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 27 Apr 2011 20:59:29 -0300 Subject: [PATCH] ubb-vga2: move image generation out of the main program - ubb-vga2.c (session, grab): made the frame buffer "void *" and pass frame buffer resolution - ubb-vga.h: color encoding and items shared between compilation units - ubb-vga2.c (thres, pattern, grab), grabfb.c: move to grabfb.c - ubb-vga2.c (map): make global, for use by grabfb.c - ubb-vga2.c (pick, pattern, tricolor, grid): removed obsolete test image generators - Makefile (OBJS, ubb-vga2): added grabfb.o - Makefile (clean): remove only .o files - Makefile (spotless): remove only executables --- ubb-vga/Makefile | 6 ++- ubb-vga/grabfb.c | 51 ++++++++++++++++++++++++ ubb-vga/ubb-vga.h | 33 ++++++++++++++++ ubb-vga/ubb-vga2.c | 96 ++-------------------------------------------- 4 files changed, 93 insertions(+), 93 deletions(-) create mode 100644 ubb-vga/grabfb.c create mode 100644 ubb-vga/ubb-vga.h diff --git a/ubb-vga/Makefile b/ubb-vga/Makefile index 245b8f2..0f16e5a 100644 --- a/ubb-vga/Makefile +++ b/ubb-vga/Makefile @@ -2,11 +2,14 @@ CC=mipsel-linux-gcc CFLAGS=-Wall -g -O9 -march=mips32 +OBJS=ubb-vga2.o grabfb.o .PHONY: all asm sch clean spotless all: ubb-vga ubb-vga2 +ubb-vga2: $(OBJS) + asm: ubb-vga.c $(CC) $(CFLAGS) -S $< @@ -14,6 +17,7 @@ sch: eeschema `pwd`/ubb-vga.sch clean: - rm -f ubb-vga ubb-vga2 + rm -f $(OBJS) spotless: clean + rm -f ubb-vga ubb-vga2 diff --git a/ubb-vga/grabfb.c b/ubb-vga/grabfb.c new file mode 100644 index 0000000..c37b74f --- /dev/null +++ b/ubb-vga/grabfb.c @@ -0,0 +1,51 @@ +/* + * grabfb.c - Grab the Ben's main frame buffer + * + * Written 2011 by Werner Almesberger + * Copyright 2011 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include +#include + +#include "ubb-vga.h" + + +uint8_t thres = 63; + + +static uint8_t pattern(int r, int g, int b) +{ + return ((r ? R_VAL : 0) | (g ? G_VAL : 0) | (b ? B_VAL : 0))*0x11; +} + + +void grabfb(void *f, int xres, int yres) +{ + uint32_t *fb = map(0x01d00000, 4*320*240); + uint8_t *p = f; + int x, y; + uint32_t pix; + uint8_t r, g, b; + + assert(xres == 640); + assert(yres == 480); + for (y = 0; y != 240; y++) { + for (x = 0; x != 320; x++) { + pix = *fb++; + r = pix >> 16; + g = pix >> 8; + b = pix; + p[0] = p[320] = + pattern(r >= thres, g >= thres, b >= thres); + p++; + } + p += 320; + } +} diff --git a/ubb-vga/ubb-vga.h b/ubb-vga/ubb-vga.h new file mode 100644 index 0000000..2f16d2d --- /dev/null +++ b/ubb-vga/ubb-vga.h @@ -0,0 +1,33 @@ +/* + * ubb-vga.h - Output video on UBB with more or less VGA timing + * + * Written 2011 by Werner Almesberger + * Copyright 2011 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef UBB_VGA_H +#define UBB_VGA_H + +#include +#include + + +#define R_VAL (1 << 3) +#define G_VAL (1 << 0) +#define B_VAL (1 << 1) +#define Y_VAL (1 << 2) + + +void *map(off_t addr, size_t size); + + +extern uint8_t thres; + +void grabfb(void *f, int xres, int yres); + +#endif /* !UBB_VGA_H */ diff --git a/ubb-vga/ubb-vga2.c b/ubb-vga/ubb-vga2.c index 64d7ecb..6b24653 100644 --- a/ubb-vga/ubb-vga2.c +++ b/ubb-vga/ubb-vga2.c @@ -34,8 +34,9 @@ #include #include +#include "ubb-vga.h" + -static uint8_t thres = 63; static int bad; /* ----- I/O pin assignment ------------------------------------------------ */ @@ -139,7 +140,7 @@ static void release_timer(void) } -static void *map(off_t addr, size_t size) +void *map(off_t addr, size_t size) { int fd; void *mem; @@ -386,95 +387,6 @@ static void frame(const uint32_t *f) } -/* ----- Frame buffer image generation ------------------------------------- */ - - -#if 0 -static uint32_t pick(int set, int bit, uint32_t val) -{ - return set == bit ? val >> 8 : 0; -} - - -static uint32_t pattern(int set, int r, int g, int b) -{ - return pick(set, r, R) | pick(set, g, G) | pick(set, b, B); -} - -static void tricolor(uint32_t *f) -{ - int pairs = 2*line_pairs*240; - int i; - - for (i = 0; i != pairs/3; i++) { - f[i & ~1] = R; - f[i | 1] = G | B; - } - for (; i != pairs*2/3; i++) { - f[i & ~1] = G; - f[i | 1] = R | B; - } - - for (; i != pairs; i++) { - f[i & ~1] = B; - f[i | 1] = R | G; - } -} - - -static void grid(uint8_t *f) -{ - static uint32_t col[8] = { - R | G | B, - R, - R | G, - G, - G | B, - B, - R | B, - R | G | B, - }; - int i, x, y; - - for (i = 0; i != 8; i++) { - x = i*line_pairs/4+line_pairs/8; - for (y = 0; y != 240; y++) { - uint8_t *p = f+y*2*line_pairs+x; - p[0] = p[1] = col[i] >> 8; - } - } -} -#endif - - -static uint8_t pattern(int r, int g, int b) -{ - return (r ? 0x88 : 0) | (g ? 0x11 : 0) | (b ? 0x22 : 0); -} - - -static void grab(uint8_t *f) -{ - uint32_t *fb = map(0x01d00000, 4*320*240); - int x, y; - uint32_t pix; - uint8_t r, g, b; - - for (y = 0; y != 240; y++) { - for (x = 0; x != 320; x++) { - pix = *fb++; - r = pix >> 16; - g = pix >> 8; - b = pix; - f[0] = f[320] = - pattern(r >= thres, g >= thres, b >= thres); - f++; - } - f += 320; - } -} - - /* ----- Command-line parsing and main loop -------------------------------- */ @@ -484,7 +396,7 @@ static void session(int frames) int i; memset(f, 0, sizeof(f)); - grab((uint8_t *) f); + grabfb(f, 640, 480); // grid(f); disable_interrupts();