Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
54 | pj | 1 | /* VGAlib version 1.2 - (c) 1993 Tommy Frandsen */ |
2 | /* */ |
||
3 | /* This library is free software; you can redistribute it and/or */ |
||
4 | /* modify it without any restrictions. This library is distributed */ |
||
5 | /* in the hope that it will be useful, but without any warranty. */ |
||
6 | |||
7 | /* Multi-chipset support Copyright 1993 Harm Hanemaayer */ |
||
8 | /* partially copyrighted (C) 1993 by Hartmut Schirmer */ |
||
9 | |||
10 | #include <stdio.h> |
||
11 | #include "vga.h" |
||
12 | #include "libvga.h" |
||
13 | |||
14 | #define ABS(a) (((a)<0) ? -(a) : (a)) |
||
15 | |||
16 | int vga_drawline(int x1, int y1, int x2, int y2) |
||
17 | { |
||
18 | int dx = x2 - x1; |
||
19 | int dy = y2 - y1; |
||
20 | int ax = ABS(dx) << 1; |
||
21 | int ay = ABS(dy) << 1; |
||
22 | int sx = (dx >= 0) ? 1 : -1; |
||
23 | int sy = (dy >= 0) ? 1 : -1; |
||
24 | |||
25 | int x = x1; |
||
26 | int y = y1; |
||
27 | |||
28 | if (ax > ay) { |
||
29 | int d = ay - (ax >> 1); |
||
30 | while (x != x2) { |
||
31 | vga_drawpixel(x, y); |
||
32 | |||
33 | if (d > 0 || (d == 0 && sx == 1)) { |
||
34 | y += sy; |
||
35 | d -= ax; |
||
36 | } |
||
37 | x += sx; |
||
38 | d += ay; |
||
39 | } |
||
40 | } else { |
||
41 | int d = ax - (ay >> 1); |
||
42 | while (y != y2) { |
||
43 | vga_drawpixel(x, y); |
||
44 | |||
45 | if (d > 0 || (d == 0 && sy == 1)) { |
||
46 | x += sx; |
||
47 | d -= ay; |
||
48 | } |
||
49 | y += sy; |
||
50 | d += ax; |
||
51 | } |
||
52 | } |
||
53 | vga_drawpixel(x, y); |
||
54 | |||
55 | return 0; |
||
56 | } |
||
57 |