Skip to content
This repository was archived by the owner on Apr 7, 2025. It is now read-only.

Commit 2d5b3b5

Browse files
author
AnimatorPro
committed
Merge pull request #8 from wangds/play_c
Convert PLAY ASM to C.
2 parents aea9a9d + 190b285 commit 2d5b3b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+756
-1384
lines changed

src/COMMON/a1blit_.c

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* a1blit_.c */
2+
3+
#include "a1blit_.h"
4+
#include "clipit_.h"
5+
6+
void
7+
a1blit(int width, int height,
8+
int sx, int sy, const UBYTE *src, int sstride,
9+
int dx, int dy, UBYTE *dst, int dstride, int col)
10+
{
11+
if (!clipblit_(&width, &height, &sx, &sy, &dx, &dy))
12+
return;
13+
14+
src += sstride * sy + (sx >> 3);
15+
dst += dstride * dy + dx;
16+
17+
for (; height > 0; height--) {
18+
const UBYTE *sp = src;
19+
UBYTE *dp = dst;
20+
UBYTE bits = *sp++;
21+
UBYTE mask = 0x80 >> (sx & 7);
22+
int count = width;
23+
24+
for (;;) {
25+
if (bits & mask) {
26+
*dp = col;
27+
}
28+
29+
if (--count <= 0)
30+
break;
31+
32+
dp++;
33+
mask >>= 1;
34+
if (mask == 0) {
35+
bits = *sp++;
36+
mask = 0x80;
37+
}
38+
}
39+
40+
src += sstride;
41+
dst += dstride;
42+
}
43+
}

src/COMMON/a1blit_.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef A1BLIT_H
2+
#define A1BLIT_H
3+
4+
#include "jimk.h"
5+
6+
/* Function: a1blit
7+
*
8+
* Blit from single bit-plane source to byte-a-pixel destination.
9+
* 1's in source are set to colour in destination. 0's in source
10+
* have no effect on destination. Used to implement menu icons,
11+
* most text, and the cursor.
12+
*
13+
* width - width of blit in pixels.
14+
* height - height of blit in pixels.
15+
* sx, sy - coordinates of upper left corner of source.
16+
* src - pointer to source bit-plane.
17+
* sstride - how many bytes from one line of source to next.
18+
* dx, dy - coordinates of upper left corner of destination.
19+
* dst - pointer to destination byte-plane.
20+
* dstride - how many bytes from one line of destination to next.
21+
* col - colour 1's in source are set to in destination.
22+
*/
23+
extern void
24+
a1blit(int width, int height,
25+
int sx, int sy, const UBYTE *src, int sstride,
26+
int dx, int dy, UBYTE *dst, int dstride, int col);
27+
28+
#ifndef SLUFF
29+
30+
#define cdraw_brush(brush, x, y, col) \
31+
a1blit(16, 16, 0, 0, brush, 2, (x)-8, (y)-8, vf.p, vf.bpr, col)
32+
33+
#define draw_brush(brush, x, y, col) \
34+
a1blit(16, 16, 0, 0, brush, 2, x, y, vf.p, vf.bpr, col)
35+
36+
#endif /* SLUFF */
37+
38+
#endif

src/COMMON/a2blit_.c

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* a2blit_.c */
2+
3+
#include "a2blit_.h"
4+
#include "clipit_.h"
5+
6+
void
7+
a2blit(int width, int height,
8+
int sx, int sy, const UBYTE *src, int sstride,
9+
int dx, int dy, UBYTE *dst, int dstride, int fg, int bg)
10+
{
11+
if (!clipblit_(&width, &height, &sx, &sy, &dx, &dy))
12+
return;
13+
14+
src += sstride * sy + (sx >> 3);
15+
dst += dstride * dy + dx;
16+
17+
for (; height > 0; height--) {
18+
const UBYTE *sp = src;
19+
UBYTE *dp = dst;
20+
UBYTE bits = *sp++;
21+
UBYTE mask = 0x80 >> (sx & 7);
22+
int count = width;
23+
24+
for (;;) {
25+
if (bits & mask) {
26+
*dp = fg;
27+
}
28+
else {
29+
*dp = bg;
30+
}
31+
32+
if (--count <= 0)
33+
break;
34+
35+
dp++;
36+
mask >>= 1;
37+
if (mask == 0) {
38+
bits = *sp++;
39+
mask = 0x80;
40+
}
41+
}
42+
43+
src += sstride;
44+
dst += dstride;
45+
}
46+
}

src/COMMON/a2blit_.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef A2BLIT_H
2+
#define A2BLIT_H
3+
4+
#include "jimk.h"
5+
6+
/* Function: a2blit
7+
*
8+
* Blit from single bit-plane source to byte-a-pixel destination.
9+
* 1's in source are set to foreground colour in destination. 0's in source
10+
* are set to background colour in destination. Used to implement text
11+
* in string requestors and in places where one message writes over another.
12+
*
13+
* width - width of blit in pixels.
14+
* height - height of blit in pixels.
15+
* sx, sy - coordinates of upper left corner of source.
16+
* src - pointer to source bit-plane.
17+
* sstride - how many bytes from one line of source to next.
18+
* dx, dy - coordinates of upper left corner of destination.
19+
* dst - pointer to destination byte-plane.
20+
* dstride - how many bytes from one line of destination to next.
21+
* fg - colour 1's in source are set to in destination.
22+
* bg - colour 0's in source are set to in destination.
23+
*/
24+
extern void
25+
a2blit(int width, int height,
26+
int sx, int sy, const UBYTE *src, int sstride,
27+
int dx, int dy, UBYTE *dst, int dstride, int fg, int bg);
28+
29+
#endif

src/COMMON/blit8_.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* blit8_.c */
2+
3+
#include <string.h>
4+
#include "blit8_.h"
5+
#include "clipit_.h"
6+
7+
void
8+
blit8(int width, int height,
9+
int sx, int sy, const UBYTE *src, int sstride,
10+
int dx, int dy, UBYTE *dst, int dstride)
11+
{
12+
if (!clipblit_(&width, &height, &sx, &sy, &dx, &dy))
13+
return;
14+
15+
src += sstride * sy + sx;
16+
dst += dstride * dy + dx;
17+
18+
for (; height > 0; height--) {
19+
memcpy(dst, src, width);
20+
21+
src += sstride;
22+
dst += dstride;
23+
}
24+
}

src/COMMON/blit8_.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef BLIT8_H
2+
#define BLIT8_H
3+
4+
#include "jimk.h"
5+
6+
/* Function: blit8
7+
*
8+
* This blits from a byte-plane source to a byte-plane destination.
9+
* It does not handle overlapping source and destination. This is
10+
* used all over the place: to save and restore what is under the
11+
* cursor or under a menu, to paste the cel when key colour clear is
12+
* turned off, etc.
13+
*
14+
* width - width of blit in pixels.
15+
* height - height of blit in pixels.
16+
* sx, sy - coordinates of upper left corner of source.
17+
* src - pointer to source byte-plane.
18+
* sstride - how many bytes from one line of source to next.
19+
* dx, dy - coordinates of upper left corner of destination.
20+
* dst - pointer to destination byte-plane.
21+
* dstride - how many bytes from one line of destination to next.
22+
*/
23+
extern void
24+
blit8(int width, int height,
25+
int sx, int sy, const UBYTE *src, int sstride,
26+
int dx, int dy, UBYTE *dst, int dstride);
27+
28+
#endif

src/COMMON/cblock_.c

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* cblock_.c */
2+
3+
#include <string.h>
4+
#include "cblock_.h"
5+
#include "clipit_.h"
6+
7+
static int
8+
clipblock(int *rx, int *ry, int *rwidth, int *rheight)
9+
{
10+
int sx = 0;
11+
int sy = 0;
12+
13+
return clipblit_(rwidth, rheight, &sx, &sy, rx, ry);
14+
}
15+
16+
void
17+
xorblock(UBYTE *dst, int x, int y, int width, int height, int col)
18+
{
19+
if (!clipblock(&x, &y, &width, &height))
20+
return;
21+
22+
dst += WIDTH * y + x;
23+
24+
for (; height > 0; height--) {
25+
UBYTE *p = dst;
26+
int i;
27+
28+
for (i = 0; i < width; i++)
29+
*p++ ^= col;
30+
31+
dst += WIDTH;
32+
}
33+
}
34+
35+
void
36+
cblock(UBYTE *dst, int x, int y, int width, int height, int col)
37+
{
38+
dst += WIDTH * y + x;
39+
40+
for (; height > 0; height--) {
41+
memset(dst, col, width);
42+
dst += WIDTH;
43+
}
44+
}
45+
46+
void
47+
chli(UBYTE *dst, int x, int y, int width, int col)
48+
{
49+
dst += WIDTH * y + x;
50+
memset(dst, col, width);
51+
}
52+
53+
void
54+
cvli(UBYTE *dst, int x, int y, int height, int col)
55+
{
56+
dst += WIDTH * y + x;
57+
58+
for (; height > 0; height--) {
59+
*dst = col;
60+
dst += WIDTH;
61+
}
62+
}
63+
64+
void
65+
cdot(UBYTE *dst, int x, int y, int col)
66+
{
67+
if ((0 < x && x < WIDTH) && (0 < y && y < HEIGHT))
68+
dst[WIDTH * y + x] = col;
69+
}

src/COMMON/cblock_.h

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#ifndef CBLOCK_H
2+
#define CBLOCK_H
3+
4+
#include "jimk.h"
5+
6+
/* Function: xorblock
7+
*
8+
* Exclusive or a rectangle with colour. Clipped to fit 320x200 screen.
9+
* Used for text cursor.
10+
*
11+
* dst - byte plane to draw on.
12+
* x,y - upper left corner of rectangle.
13+
* width, height - dimensions of rectangle in pixels.
14+
* col - colour to xor with block.
15+
*/
16+
extern void xorblock(UBYTE *dst, int x, int y, int width, int height, int col);
17+
18+
/* Function: cblock
19+
*
20+
* Draw a rectangle in a solid colour. Not clipped.
21+
* Used heavily by menu drawing routines.
22+
*
23+
* dst - byte plane to draw on.
24+
* x, y - upper left corner of rectangle.
25+
* width, height - dimensions of rectangle in pixels.
26+
* col - colour to set block.
27+
*/
28+
extern void cblock(UBYTE *dst, int x, int y, int width, int height, int col);
29+
30+
/* Function: chli
31+
*
32+
* Draw a horizontal line in a solid colour. Not clipped. Used by
33+
* menu routines.
34+
*
35+
* dst - byte plane to draw on.
36+
* x, y - left end of line.
37+
* width - width of line.
38+
* col - colour of line.
39+
*/
40+
extern void chli(UBYTE *dst, int x, int y, int width, int col);
41+
42+
/* Function: cvli
43+
*
44+
* Draw a vertical line in a solid colour. Not clipped. Used by
45+
* menu routines.
46+
*
47+
* dst - byte plane to draw on.
48+
* x, y - left end of line.
49+
* height - height of line.
50+
* col - colour of line.
51+
*/
52+
extern void cvli(UBYTE *dst, int x, int y, int height, int col);
53+
54+
/* Function: cdot
55+
*
56+
* Draw a single pixel dot. Clipped to 320x200.
57+
*
58+
* dst - byte plane to draw on.
59+
* x, y - screen position.
60+
* col - dot colour.
61+
*/
62+
extern void cdot(UBYTE *dst, int x, int y, int col);
63+
64+
#ifndef SLUFF
65+
66+
#define xorrop(col, x, y, width, height) \
67+
xorblock(vf.p, x, y, width, height, col)
68+
69+
#define colblock(col, x, y, x2, y2) \
70+
cblock(vf.p, x, y, (x2)-(x)+1, (y2)-(y)+1, col)
71+
72+
#define colrop(col, x, y, width, height) \
73+
cblock(vf.p, x, y, (width+1), (height+1), col)
74+
75+
#define color_hslice(y, height, col) \
76+
cblock(vf.p, 0, y, vf.w, height, col)
77+
78+
#define hline(y, x0, x1, col) \
79+
chli(vf.p, x0, y, (x1)-(x0)+1, col)
80+
81+
#define vline(x, y0, y1, col) \
82+
cvli(vf.p, x, y0, (y1)-(y0)+1, col)
83+
84+
#endif /* SLUFF */
85+
86+
#endif

0 commit comments

Comments
 (0)