-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpoly.asm
90 lines (84 loc) · 2.28 KB
/
poly.asm
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
80
81
82
83
84
85
86
87
88
89
90
;===================================================================================================
; Polygons
;
; Written By: Oded Cnaan (oded.8bit@gmail.com)
; Site: http://odedc.net
; Licence: GPLv3 (see LICENSE file)
; Package: GrLib
;
; Description:
; Draws polygons
;===================================================================================================
LOCALS @@
;---------------------------------------------
; To draw a polygon, you need to define an array
; and pass its pointer along with the number of
; points in the array.
;
; The array should contain **points** (x and y) as
; follows:
;
; DATASEG
; POLY dw 5,30,100,50,200,100
;
; This is an array with the following points:
; 1. POLY[0] = (5,30)
; 2. POLY[1] = (100,50)
; 3. POLY[2] = (200,100)
;
; and the call goes like that:
; push 3 ; there are 3 points
; push offset POLY ; pointer to POLY array
; call GR_DrawPolygon
;---------------------------------------------
PROC GR_DrawPolygon
store_sp_bp
pusha
; now the stack is
; bp+0 => old base pointer
; bp+2 => return address
; bp+4 => param2 (array ptr)
; bp+6 => param1 (size)
; saved registers
mov cx, [WORD bp+6]
mov si, 0 ; index to points
@@_drawpoly:
mov di, [word bp+4]
add di, si
mov ax, [WORD di] ; x1 value
add di, 2
mov bx, [WORD di] ; y1 value
push ax
push bx
cmp cx, 1
jg @@_notlast
mov di, [word bp+4] ; move to first point
sub di, 2
mov si, 0
@@_notlast:
add di, 2
mov ax, [WORD di] ; x2 value
add di, 2
mov bx, [WORD di] ; y2 value
push ax
push bx
call GR_DrawLine
add si, 4
loop @@_drawpoly
popa
restore_sp_bp
ret 4
ENDP GR_DrawPolygon
;////////////////////////////////////////////////////////////////////////////
; FUNCTION LIKE MACROS
;////////////////////////////////////////////////////////////////////////////
;----------------------------------------------------------------------
; Draw a polygon
;
; grm_DrawPolygon (numPoints, polygonOffset)
;----------------------------------------------------------------------
MACRO grm_DrawPolygon numPoints, polygonOffset
push numPoints
push polygonOffset
call GR_DrawPolygon
ENDM