1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-06-25 09:17:37 +03:00

ubb-vga2: non-contiguous allocation of frame buffer memory

- ubb-vga.h (calloc_phys_vec), physmem.c: non-contiguous memory allocator
  (for now, without really considering any mapping to physical memory)
- Makefile (OBJS): added physmem.o
- ubb-vga.h (grabfb), grabfb.c (grabfb): API change for non-contiguous
  frame buffer
- ubb-vga.h (ppmimg), ppmimg.c (convert, ppmimg): API change for
  non-contiguous frame buffer
- ubb-vga.h (tstimg), tstimg.c (pixel, color_bars, grill, grid, sides,
  dot, line45, arc, printc, text, ctext, tstimg): API change for
  non-contiguous frame buffer
- tstimg.c (tstimg): we no longer need to clear the frame buffer
- ubb-vga.c (frame, session, main): use a vector of line buffers instead
  of a contiguous frame buffer
This commit is contained in:
Werner Almesberger 2011-04-29 13:04:02 -03:00
parent 71c9c7dd78
commit 623f3ccbe3
7 changed files with 77 additions and 39 deletions

View File

@ -3,7 +3,7 @@ CC=mipsel-linux-gcc
CFLAGS=-Wall -g -O9 -march=mips32
LDFLAGS=-lm
OBJS=ubb-vga2.o grabfb.o tstimg.o ppm.o ppmimg.o ccube.o
OBJS=ubb-vga2.o grabfb.o tstimg.o ppm.o ppmimg.o ccube.o physmem.o
.PHONY: all asm sch clean spotless

View File

@ -17,10 +17,10 @@
#include "ubb-vga.h"
void grabfb(void *f, int xres, int yres)
void grabfb(void **f, int xres, int yres)
{
uint32_t *fb = map(0x01d00000, 4*320*240);
uint8_t *p = f;
uint8_t *p, *q;
int x, y;
uint32_t pix;
uint8_t r, g, b;
@ -28,14 +28,16 @@ void grabfb(void *f, int xres, int yres)
assert(xres == 640);
assert(yres == 480);
for (y = 0; y != 240; y++) {
p = f[y*2];
q = f[y*2+1];
for (x = 0; x != 320; x++) {
pix = *fb++;
r = pix >> 16;
g = pix >> 8;
b = pix;
p[0] = p[320] = ccube_map(r, g, b)*0x11;
*p = *q = ccube_map(r, g, b)*0x11;
p++;
q++;
}
p += 320;
}
}

35
ubb-vga/physmem.c Normal file
View File

@ -0,0 +1,35 @@
/*
* physmem.c - Physical memory allocator
*
* 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 <string.h>
#include <unistd.h>
#include <sys/types.h>
/*
* dummy implementation
*/
void **calloc_phys_vec(size_t n, size_t size)
{
void **vec;
int i;
vec = sbrk(sizeof(void *)*n);
for (i = 0; i != n; i++) {
vec[i] = sbrk(size);
memset(vec[i], 0, size);
}
return vec;
}

View File

@ -22,25 +22,28 @@
char *img_name;
static void convert(uint8_t *f, int xres, int yres, uint8_t *ppm)
static void convert(void **f, int xres, int yres, uint8_t *ppm)
{
int x, y;
uint8_t *p;
uint8_t v, last = 0;
for (y = 0; y != yres; y++)
for (y = 0; y != yres; y++) {
p = f[y];
for (x = 0; x != xres; x++) {
v = ccube_map(ppm[0], ppm[1], ppm[2]);
if (x & 1) {
*f++ = last | v;
*p++ = last | v;
} else {
last = v << 4;
}
ppm += 3;
}
}
}
void ppmimg(void *f, int xres, int yres)
void ppmimg(void **f, int xres, int yres)
{
uint8_t *ppm;
int xr = 0, yr = 0;

View File

@ -40,11 +40,11 @@
#define WHITE 0xf
static void pixel(void *f, int xres, int x, int y, uint8_t c)
static void pixel(void **f, int xres, int x, int y, uint8_t c)
{
uint8_t *p;
p = f+((y*xres+x) >> 1);
p = f[y]+(x >> 1);
if (x & 1)
*p = (*p & 0xf0) | c;
else
@ -61,7 +61,7 @@ static void pixel(void *f, int xres, int x, int y, uint8_t c)
#define CBAR_Y1 0.75
static void color_bars(void *f, int xres, int yres, ...)
static void color_bars(void **f, int xres, int yres, ...)
{
int i, x, y;
uint8_t c;
@ -81,7 +81,7 @@ static void color_bars(void *f, int xres, int yres, ...)
#define GRID 50
static void grill(void *f, int ares, int bres, int swap)
static void grill(void **f, int ares, int bres, int swap)
{
int n, o;
int i, a, b;
@ -119,7 +119,7 @@ static void grill(void *f, int ares, int bres, int swap)
}
static void grid(void *f, int xres, int yres)
static void grid(void **f, int xres, int yres)
{
grill(f, xres, yres, 0);
grill(f, yres, xres, 1);
@ -129,7 +129,7 @@ static void grid(void *f, int xres, int yres)
/* ----- Diagonal lines meeting at the sides ------------------------------- */
static void sides(void *f, int xres, int yres)
static void sides(void **f, int xres, int yres)
{
int i;
@ -151,7 +151,7 @@ static void sides(void *f, int xres, int yres)
/* ----- Text -------------------------------------------------------------- */
static void dot(void *f, int xres, int x, int y, int color, int side)
static void dot(void **f, int xres, int x, int y, int color, int side)
{
int xi, yi;
@ -161,7 +161,7 @@ static void dot(void *f, int xres, int x, int y, int color, int side)
}
static void line45(void *f, int xres, int x, int y, int dx, int dy, int n,
static void line45(void **f, int xres, int x, int y, int dx, int dy, int n,
uint8_t color, int side)
{
while (n--) {
@ -173,7 +173,7 @@ static void line45(void *f, int xres, int x, int y, int dx, int dy, int n,
}
static void arc(void *f, int xres, int x, int y, int n, int q,
static void arc(void **f, int xres, int x, int y, int n, int q,
uint8_t color, int side)
{
int dx, dy;
@ -192,7 +192,7 @@ static void arc(void *f, int xres, int x, int y, int n, int q,
}
static void printc(void *f, int xres, int x, int y, char c, int n,
static void printc(void **f, int xres, int x, int y, char c, int n,
uint8_t color, int side)
{
switch (c) {
@ -299,7 +299,7 @@ static void printc(void *f, int xres, int x, int y, char c, int n,
}
static void text(void *f, int xres, int x, int y, const char *s, int n,
static void text(void **f, int xres, int x, int y, const char *s, int n,
uint8_t color, int side)
{
while (*s) {
@ -311,7 +311,7 @@ static void text(void *f, int xres, int x, int y, const char *s, int n,
static void ctext(void *f, int xres, int x, int y, const char *s, int n,
static void ctext(void **f, int xres, int x, int y, const char *s, int n,
uint8_t color, int side)
{
text(f, xres, x+n*(1-3*(int) strlen(s))/2, y-2*n, s, n, color, side);
@ -321,11 +321,10 @@ static void ctext(void *f, int xres, int x, int y, const char *s, int n,
/* ----- Generate the test image ------------------------------------------- */
void tstimg(void *f, int xres, int yres)
void tstimg(void **f, int xres, int yres)
{
char buf[20];
memset(f, 0, xres*yres/2);
grid(f, xres, yres);
sides(f, xres, yres);
color_bars(f, xres, yres);

View File

@ -31,18 +31,22 @@ void *map(off_t addr, size_t size);
uint8_t ccube_map(uint8_t r, uint8_t g, uint8_t b);
void ccube_init(void);
/* physmem.c */
void **calloc_phys_vec(size_t n, size_t size);
/* grabfb.c */
void grabfb(void *f, int xres, int yres);
void grabfb(void **f, int xres, int yres);
/* tstimg.c */
void tstimg(void *f, int xres, int yres);
void tstimg(void **f, int xres, int yres);
/* ppmimg.c */
extern char *img_name;
void ppmimg(void *f, int xres, int yres);
void ppmimg(void **f, int xres, int yres);
#endif /* !UBB_VGA_H */

View File

@ -328,9 +328,9 @@ static void hdelay(int cycles)
}
static void frame(const uint32_t *f)
static void frame(void *const *f)
{
const uint32_t *p;
void *const *p;
/* VSYNC */
PDDATC = VSYNC;
@ -351,8 +351,8 @@ static void frame(const uint32_t *f)
PDDATS = HSYNC;
until(mode->line_cycles-US(0.79));
for (p = f; p != f+mode->yres*mode->line_words; p += mode->line_words)
line(p);
for (p = f; p != f+mode->yres; p++)
line(*p);
/* Back porch */
hdelay(14);
@ -362,18 +362,13 @@ static void frame(const uint32_t *f)
/* ----- Command-line parsing and main loop -------------------------------- */
static void session(void (*gen)(void *fb, int xres, int yres), int frames)
static void session(void (*gen)(void **fb, int xres, int yres), int frames)
{
uint32_t *f;
void **f;
int i;
f = malloc((mode->yres*mode->line_words)*4);
if (!f) {
perror("malloc");
exit(1);
}
memset(f, 0, sizeof(f));
ccube_init();
f = calloc_phys_vec(mode->yres, mode->xres/2);
gen(f, mode->xres, mode->yres);
disable_interrupts();
@ -400,7 +395,7 @@ static void usage(const char *name)
int main(int argc, char *const *argv)
{
void (*gen)(void *fb, int xres, int yres) = grabfb;
void (*gen)(void **fb, int xres, int yres) = grabfb;
int frames;
int c;