Skip to content

Commit 49ffd4f

Browse files
committed
Introduce BlitterOr operation (backported from b23d3a3)
1 parent 11d671b commit 49ffd4f

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

include/blitter.h

+11
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ void BitmapCopyMasked(const BitmapT *dst, u_short x, u_short y,
128128
void BitmapCopyArea(const BitmapT *dst, u_short dx, u_short dy,
129129
const BitmapT *src, const Area2D *area);
130130

131+
/* Blitter or operation. */
132+
/* TODO: does not behave correctly for unaligned `x` */
133+
void BlitterOrSetup(const BitmapT *dst, u_short x, u_short y,
134+
const BitmapT *src);
135+
void BlitterOrStart(short dstbpl, short srcbpl);
136+
137+
#define BlitterOr(dst, dstbpl, x, y, src, srcbpl) ({ \
138+
BlitterOrSetup((dst), (x), (y), (src)); \
139+
BlitterOrStart((dstbpl), (srcbpl)); \
140+
})
141+
131142
/* Blitter fill. */
132143
void BlitterFillArea(const BitmapT *bitmap, short plane, const Area2D *area);
133144

lib/libblit/BitmapOr.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <blitter.h>
2+
3+
void BitmapOr(const BitmapT *dst, u_short x, u_short y, const BitmapT *src) {
4+
short i, n = min(dst->depth, src->depth);
5+
6+
BlitterOrSetup(dst, x, y, src);
7+
for (i = 0; i < n; i++)
8+
BlitterOrStart(i, i);
9+
}

lib/libblit/BlitterOr.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <blitter.h>
2+
3+
typedef struct {
4+
const BitmapT *src;
5+
const BitmapT *dst;
6+
u_int start;
7+
u_short size;
8+
} StateT;
9+
10+
static StateT state[1];
11+
12+
/* Supports any (x, y) and any source bitmap width. */
13+
void BlitterOrSetup(const BitmapT *dst, u_short x, u_short y,
14+
const BitmapT *src)
15+
{
16+
/* Calculate real blit width. It can be greater than src->bytesPerRow! */
17+
u_short width = (x & 15) + src->width;
18+
u_short bytesPerRow = ((width + 15) & ~15) >> 3;
19+
u_short srcmod = src->bytesPerRow - bytesPerRow;
20+
u_short dstmod = dst->bytesPerRow - bytesPerRow;
21+
u_short bltafwm = FirstWordMask[x & 15];
22+
u_short bltalwm = LastWordMask[width & 15];
23+
u_short bltshift = rorw(x & 15, 4);
24+
25+
state->src = src;
26+
state->dst = dst;
27+
state->start = ((x & ~15) >> 3) + y * dst->bytesPerRow;
28+
state->size = (src->height << 6) | (bytesPerRow >> 1);
29+
30+
WaitBlitter();
31+
32+
custom->bltcon0 = A_OR_B | (SRCA | SRCB | DEST) | bltshift;
33+
custom->bltcon1 = 0;
34+
custom->bltafwm = bltafwm;
35+
custom->bltalwm = bltalwm;
36+
custom->bltamod = srcmod;
37+
custom->bltbmod = dstmod;
38+
custom->bltdmod = dstmod;
39+
}
40+
41+
void BlitterOrStart(short dstbpl, short srcbpl) {
42+
void *srcbpt = state->src->planes[srcbpl];
43+
void *dstbpt = state->dst->planes[dstbpl] + state->start;
44+
u_short bltsize = state->size;
45+
46+
WaitBlitter();
47+
48+
custom->bltapt = srcbpt;
49+
custom->bltbpt = dstbpt;
50+
custom->bltdpt = dstbpt;
51+
custom->bltsize = bltsize;
52+
}

lib/libblit/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ SOURCES := \
99
BitmapDecSaturated.c \
1010
BitmapIncSaturated.c \
1111
BitmapMakeMask.c \
12+
BitmapOr.c \
1213
BitmapSetArea.c \
1314
BlitterCopy.c \
1415
BlitterCopyArea.c \
1516
BlitterCopyFast.c \
1617
BlitterCopyMasked.c \
1718
BlitterFillArea.c \
19+
BlitterOr.c \
1820
BlitterLine.c \
1921
BlitterSetArea.c \
2022
BlitterSetMaskArea.c \
21-
WordMask.c \
23+
WordMask.c
2224

2325
include $(TOPDIR)/build/lib.mk

0 commit comments

Comments
 (0)