mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-23 20:59:42 +02: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:
parent
71c9c7dd78
commit
623f3ccbe3
@ -3,7 +3,7 @@ CC=mipsel-linux-gcc
|
|||||||
|
|
||||||
CFLAGS=-Wall -g -O9 -march=mips32
|
CFLAGS=-Wall -g -O9 -march=mips32
|
||||||
LDFLAGS=-lm
|
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
|
.PHONY: all asm sch clean spotless
|
||||||
|
|
||||||
|
@ -17,10 +17,10 @@
|
|||||||
#include "ubb-vga.h"
|
#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);
|
uint32_t *fb = map(0x01d00000, 4*320*240);
|
||||||
uint8_t *p = f;
|
uint8_t *p, *q;
|
||||||
int x, y;
|
int x, y;
|
||||||
uint32_t pix;
|
uint32_t pix;
|
||||||
uint8_t r, g, b;
|
uint8_t r, g, b;
|
||||||
@ -28,14 +28,16 @@ void grabfb(void *f, int xres, int yres)
|
|||||||
assert(xres == 640);
|
assert(xres == 640);
|
||||||
assert(yres == 480);
|
assert(yres == 480);
|
||||||
for (y = 0; y != 240; y++) {
|
for (y = 0; y != 240; y++) {
|
||||||
|
p = f[y*2];
|
||||||
|
q = f[y*2+1];
|
||||||
for (x = 0; x != 320; x++) {
|
for (x = 0; x != 320; x++) {
|
||||||
pix = *fb++;
|
pix = *fb++;
|
||||||
r = pix >> 16;
|
r = pix >> 16;
|
||||||
g = pix >> 8;
|
g = pix >> 8;
|
||||||
b = pix;
|
b = pix;
|
||||||
p[0] = p[320] = ccube_map(r, g, b)*0x11;
|
*p = *q = ccube_map(r, g, b)*0x11;
|
||||||
p++;
|
p++;
|
||||||
|
q++;
|
||||||
}
|
}
|
||||||
p += 320;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
ubb-vga/physmem.c
Normal file
35
ubb-vga/physmem.c
Normal 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;
|
||||||
|
}
|
@ -22,25 +22,28 @@
|
|||||||
char *img_name;
|
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;
|
int x, y;
|
||||||
|
uint8_t *p;
|
||||||
uint8_t v, last = 0;
|
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++) {
|
for (x = 0; x != xres; x++) {
|
||||||
v = ccube_map(ppm[0], ppm[1], ppm[2]);
|
v = ccube_map(ppm[0], ppm[1], ppm[2]);
|
||||||
if (x & 1) {
|
if (x & 1) {
|
||||||
*f++ = last | v;
|
*p++ = last | v;
|
||||||
} else {
|
} else {
|
||||||
last = v << 4;
|
last = v << 4;
|
||||||
}
|
}
|
||||||
ppm += 3;
|
ppm += 3;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ppmimg(void *f, int xres, int yres)
|
void ppmimg(void **f, int xres, int yres)
|
||||||
{
|
{
|
||||||
uint8_t *ppm;
|
uint8_t *ppm;
|
||||||
int xr = 0, yr = 0;
|
int xr = 0, yr = 0;
|
||||||
|
@ -40,11 +40,11 @@
|
|||||||
#define WHITE 0xf
|
#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;
|
uint8_t *p;
|
||||||
|
|
||||||
p = f+((y*xres+x) >> 1);
|
p = f[y]+(x >> 1);
|
||||||
if (x & 1)
|
if (x & 1)
|
||||||
*p = (*p & 0xf0) | c;
|
*p = (*p & 0xf0) | c;
|
||||||
else
|
else
|
||||||
@ -61,7 +61,7 @@ static void pixel(void *f, int xres, int x, int y, uint8_t c)
|
|||||||
#define CBAR_Y1 0.75
|
#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;
|
int i, x, y;
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
@ -81,7 +81,7 @@ static void color_bars(void *f, int xres, int yres, ...)
|
|||||||
#define GRID 50
|
#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 n, o;
|
||||||
int i, a, b;
|
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, xres, yres, 0);
|
||||||
grill(f, yres, xres, 1);
|
grill(f, yres, xres, 1);
|
||||||
@ -129,7 +129,7 @@ static void grid(void *f, int xres, int yres)
|
|||||||
/* ----- Diagonal lines meeting at the sides ------------------------------- */
|
/* ----- 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;
|
int i;
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ static void sides(void *f, int xres, int yres)
|
|||||||
/* ----- Text -------------------------------------------------------------- */
|
/* ----- 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;
|
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)
|
uint8_t color, int side)
|
||||||
{
|
{
|
||||||
while (n--) {
|
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)
|
uint8_t color, int side)
|
||||||
{
|
{
|
||||||
int dx, dy;
|
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)
|
uint8_t color, int side)
|
||||||
{
|
{
|
||||||
switch (c) {
|
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)
|
uint8_t color, int side)
|
||||||
{
|
{
|
||||||
while (*s) {
|
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)
|
uint8_t color, int side)
|
||||||
{
|
{
|
||||||
text(f, xres, x+n*(1-3*(int) strlen(s))/2, y-2*n, s, n, color, 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 ------------------------------------------- */
|
/* ----- Generate the test image ------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
void tstimg(void *f, int xres, int yres)
|
void tstimg(void **f, int xres, int yres)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
|
|
||||||
memset(f, 0, xres*yres/2);
|
|
||||||
grid(f, xres, yres);
|
grid(f, xres, yres);
|
||||||
sides(f, xres, yres);
|
sides(f, xres, yres);
|
||||||
color_bars(f, xres, yres);
|
color_bars(f, xres, yres);
|
||||||
|
@ -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);
|
uint8_t ccube_map(uint8_t r, uint8_t g, uint8_t b);
|
||||||
void ccube_init(void);
|
void ccube_init(void);
|
||||||
|
|
||||||
|
/* physmem.c */
|
||||||
|
|
||||||
|
void **calloc_phys_vec(size_t n, size_t size);
|
||||||
|
|
||||||
/* grabfb.c */
|
/* grabfb.c */
|
||||||
|
|
||||||
void grabfb(void *f, int xres, int yres);
|
void grabfb(void **f, int xres, int yres);
|
||||||
|
|
||||||
/* tstimg.c */
|
/* tstimg.c */
|
||||||
|
|
||||||
void tstimg(void *f, int xres, int yres);
|
void tstimg(void **f, int xres, int yres);
|
||||||
|
|
||||||
/* ppmimg.c */
|
/* ppmimg.c */
|
||||||
|
|
||||||
extern char *img_name;
|
extern char *img_name;
|
||||||
|
|
||||||
void ppmimg(void *f, int xres, int yres);
|
void ppmimg(void **f, int xres, int yres);
|
||||||
|
|
||||||
#endif /* !UBB_VGA_H */
|
#endif /* !UBB_VGA_H */
|
||||||
|
@ -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 */
|
/* VSYNC */
|
||||||
PDDATC = VSYNC;
|
PDDATC = VSYNC;
|
||||||
@ -351,8 +351,8 @@ static void frame(const uint32_t *f)
|
|||||||
PDDATS = HSYNC;
|
PDDATS = HSYNC;
|
||||||
until(mode->line_cycles-US(0.79));
|
until(mode->line_cycles-US(0.79));
|
||||||
|
|
||||||
for (p = f; p != f+mode->yres*mode->line_words; p += mode->line_words)
|
for (p = f; p != f+mode->yres; p++)
|
||||||
line(p);
|
line(*p);
|
||||||
|
|
||||||
/* Back porch */
|
/* Back porch */
|
||||||
hdelay(14);
|
hdelay(14);
|
||||||
@ -362,18 +362,13 @@ static void frame(const uint32_t *f)
|
|||||||
/* ----- Command-line parsing and main loop -------------------------------- */
|
/* ----- 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;
|
int i;
|
||||||
|
|
||||||
f = malloc((mode->yres*mode->line_words)*4);
|
|
||||||
if (!f) {
|
|
||||||
perror("malloc");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
memset(f, 0, sizeof(f));
|
|
||||||
ccube_init();
|
ccube_init();
|
||||||
|
f = calloc_phys_vec(mode->yres, mode->xres/2);
|
||||||
gen(f, mode->xres, mode->yres);
|
gen(f, mode->xres, mode->yres);
|
||||||
|
|
||||||
disable_interrupts();
|
disable_interrupts();
|
||||||
@ -400,7 +395,7 @@ static void usage(const char *name)
|
|||||||
|
|
||||||
int main(int argc, char *const *argv)
|
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 frames;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user