Core Native GBA 0.0.17
create your own game-engine with just lua for nitendo game boy advance console.
Loading...
Searching...
No Matches
draw_line.c
Go to the documentation of this file.
1#include "zeebo.h"
2
3void draw_cmd_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
4{
5 int dx = x2 - x1;
6 int dy = y2 - y1;
7 int xstep = (x1 < x2) ? 1 : -1;
8 int ystep = (y1 < y2) ? 1 : -1;
9 int dd;
10
11 if (dx < 0) {
12 dx = -dx;
13 }
14 if (dy < 0) {
15 dy = -dy;
16 }
17
18 uint16_t *dst = (uint16_t *)(0x06000000 + (y1 * 240 + x1) * 2);
19 int dstPitch = 240;
20
21 if (dx >= dy) {
22 dd = 2 * dy - dx;
23 for (int i = 0; i <= dx; i++) {
24 *dst = draw_color.pixel;
25 if (dd >= 0) {
26 dd -= 2 * dx;
27 dst += ystep * dstPitch;
28 }
29 dd += 2 * dy;
30 dst += xstep;
31 }
32 } else {
33 dd = 2 * dx - dy;
34 for (int i = 0; i <= dy; i++) {
35 *dst = draw_color.pixel;
36 if (dd >= 0) {
37 dd -= 2 * dy;
38 dst += xstep;
39 }
40 dd += 2 * dx;
41 dst += ystep * dstPitch;
42 }
43 }
44}
color_t draw_color
Definition draw_color.c:7
void draw_cmd_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
Definition draw_line.c:3
uint16_t pixel
Definition zeebo.h:11