Skip to content

Commit

Permalink
Introduce BlitterOr operation (backported from b23d3a3)
Browse files Browse the repository at this point in the history
  • Loading branch information
cahirwpz committed Dec 16, 2023
1 parent 11d671b commit 49ffd4f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
11 changes: 11 additions & 0 deletions include/blitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ void BitmapCopyMasked(const BitmapT *dst, u_short x, u_short y,
void BitmapCopyArea(const BitmapT *dst, u_short dx, u_short dy,
const BitmapT *src, const Area2D *area);

/* Blitter or operation. */
/* TODO: does not behave correctly for unaligned `x` */
void BlitterOrSetup(const BitmapT *dst, u_short x, u_short y,
const BitmapT *src);
void BlitterOrStart(short dstbpl, short srcbpl);

#define BlitterOr(dst, dstbpl, x, y, src, srcbpl) ({ \
BlitterOrSetup((dst), (x), (y), (src)); \
BlitterOrStart((dstbpl), (srcbpl)); \
})

/* Blitter fill. */
void BlitterFillArea(const BitmapT *bitmap, short plane, const Area2D *area);

Expand Down
9 changes: 9 additions & 0 deletions lib/libblit/BitmapOr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <blitter.h>

void BitmapOr(const BitmapT *dst, u_short x, u_short y, const BitmapT *src) {
short i, n = min(dst->depth, src->depth);

BlitterOrSetup(dst, x, y, src);
for (i = 0; i < n; i++)
BlitterOrStart(i, i);
}
52 changes: 52 additions & 0 deletions lib/libblit/BlitterOr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <blitter.h>

typedef struct {
const BitmapT *src;
const BitmapT *dst;
u_int start;
u_short size;
} StateT;

static StateT state[1];

/* Supports any (x, y) and any source bitmap width. */
void BlitterOrSetup(const BitmapT *dst, u_short x, u_short y,
const BitmapT *src)
{
/* Calculate real blit width. It can be greater than src->bytesPerRow! */
u_short width = (x & 15) + src->width;
u_short bytesPerRow = ((width + 15) & ~15) >> 3;
u_short srcmod = src->bytesPerRow - bytesPerRow;
u_short dstmod = dst->bytesPerRow - bytesPerRow;
u_short bltafwm = FirstWordMask[x & 15];
u_short bltalwm = LastWordMask[width & 15];
u_short bltshift = rorw(x & 15, 4);

state->src = src;
state->dst = dst;
state->start = ((x & ~15) >> 3) + y * dst->bytesPerRow;
state->size = (src->height << 6) | (bytesPerRow >> 1);

WaitBlitter();

custom->bltcon0 = A_OR_B | (SRCA | SRCB | DEST) | bltshift;
custom->bltcon1 = 0;
custom->bltafwm = bltafwm;
custom->bltalwm = bltalwm;
custom->bltamod = srcmod;
custom->bltbmod = dstmod;
custom->bltdmod = dstmod;
}

void BlitterOrStart(short dstbpl, short srcbpl) {
void *srcbpt = state->src->planes[srcbpl];
void *dstbpt = state->dst->planes[dstbpl] + state->start;
u_short bltsize = state->size;

WaitBlitter();

custom->bltapt = srcbpt;
custom->bltbpt = dstbpt;
custom->bltdpt = dstbpt;
custom->bltsize = bltsize;
}
4 changes: 3 additions & 1 deletion lib/libblit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ SOURCES := \
BitmapDecSaturated.c \
BitmapIncSaturated.c \
BitmapMakeMask.c \
BitmapOr.c \
BitmapSetArea.c \
BlitterCopy.c \
BlitterCopyArea.c \
BlitterCopyFast.c \
BlitterCopyMasked.c \
BlitterFillArea.c \
BlitterOr.c \
BlitterLine.c \
BlitterSetArea.c \
BlitterSetMaskArea.c \
WordMask.c \
WordMask.c

include $(TOPDIR)/build/lib.mk

0 comments on commit 49ffd4f

Please sign in to comment.