-
Notifications
You must be signed in to change notification settings - Fork 5
/
draw.c
79 lines (66 loc) · 1.77 KB
/
draw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdlib.h>
#include "32x.h"
#include "types.h"
#define DRAW_DST_BITS 8
#include "draw_inc.h"
#undef DRAW_DST_BITS
#define DRAW_DST_BITS 16
#include "draw_inc.h"
#undef DRAW_DST_BITS
rect_t scissor;
draw_spritefn_t draw_spritefn(int flags)
{
if (flags & DRAWSPR_PRECISE)
{
draw8_spr8func_t* funcs = draw8spr8funcs;
if (flags & DRAWSPR_SCALE) funcs += 4;
return (draw_spritefn_t)funcs[(flags & 3) ^ 3];
}
else
{
draw16_spr8func_t* funcs = draw16spr8funcs;
if (flags & DRAWSPR_SCALE) funcs += 4;
return (draw_spritefn_t)funcs[(flags & 3) ^ 3];
}
}
void draw_handle_drawspritecmd(drawsprcmd_t *cmd)
{
void* fb = (void *)((uint16_t *)(cmd->flags & DRAWSPR_OVERWRITE ? &MARS_OVERWRITE_IMG : &MARS_FRAMEBUFFER) + 0x100);
draw_spritefn_t fn = draw_spritefn(cmd->flags);
fn(fb, cmd);
}
void draw_setScissor(int16_t x, int16_t y, int16_t w, int16_t h)
{
scissor.x1 = x;
scissor.y1 = y;
scissor.x2 = scissor.x1 + w;
scissor.y2 = scissor.y1 + h;
}
// returns 2 if fully clipped
// returns 1 if partially clipped
// otherwise returns 0
int draw_clip(int x, int y, int w, int h, rect_t* cliprect)
{
int cl, cr, ct, cb;
if (x + w < scissor.x1 || y + h < scissor.y1)
return 2;
if (x >= scissor.x2 || y >= scissor.y2)
return 2;
cl = cr = 0;
ct = cb = 0;
if (w + x > scissor.x2)
cr = w + x - scissor.x2;
if (x < scissor.x1)
cl = scissor.x1 - x;
if (h + y > scissor.y2)
cb = h + y - scissor.y2;
if (y < scissor.y1)
ct = scissor.y1 - y;
if (w <= cr + cl || h <= cb + ct)
return 2;
cliprect->x1 = cl;
cliprect->x2 = cr;
cliprect->y1 = ct;
cliprect->y2 = cb;
return (ct | cl | cr | cb ? 1 : 0);
}