-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathanim.asm
182 lines (152 loc) · 5.17 KB
/
anim.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
;===================================================================================================
; Animations
;
; Written By: Oded Cnaan ([email protected])
; Site: http://odedc.net
; Licence: GPLv3 (see LICENSE file)
; Package: GrLib
;
; Description:
; Managing animations
;===================================================================================================
LOCALS @@
;---------------------------------------------------------------
; Plays a sprite in a given coords
;
; PlaySpriteInPlace(word index_to_draw, word bmp_struct_addr,
; word bmp_struct_seg, word x, word y,
; word sprite_w, word num_sprites)
;
;---------------------------------------------------------------
PROC PlaySpriteInPlace
store_sp_bp
define_local_vars 6
pusha
push ds
push es
; now the stack is
; bp-12 => sprite y
; bp-10 => img data ptr
; bp-8 => current y
; bp-6 => img width
; bp-4 => img height
; bp-2 => xTop
; bp+0 => old base pointer
; bp+2 => return address
; bp+4 => num_sprites
; bp+6 => sprite_w
; bp+8 => y
; bp+10 => x
; bp+12 => bmp_struct_seg
; bp+14 => bmp_struct_addr
; bp+16 => index_to_draw
; saved registers
;{
varXTop equ [word bp-2]
varXTop_ equ bp-2
varImgHeight equ [word bp-4]
varImgHeight_ equ bp-4
varImgWidth equ [word bp-6]
varImgWidth_ equ bp-6
varCurrY equ [word bp-8]
varCurrY_ equ bp-8
varDataPtr equ [word bp-10]
varDataPtr_ equ bp-10
varSpriteY equ [word bp-12]
varSpriteY_ equ bp-12
frameIndex equ [word bp+16]
structAddress equ [word bp+14]
structSegment equ [word bp+12]
xCoord equ [word bp+10]
xCoord_ equ bp+10
yCoord equ [word bp+8]
yCoord_ equ bp+8
spriteWidth equ [word bp+6]
spriteWidth_ equ bp+6
numSprites equ [word bp+4]
;}
mov ax, frameIndex ; index
cmp ax, numSprites ; num frames
jb @@frames_ok
mov bx, numSprites ; num frames
div bl
shr ax,8 ; mod stored in ah
mov frameIndex,ax ; index = index mod frames
@@frames_ok:
mov ax, frameIndex
mul spriteWidth
mov varXTop, ax ; xTop = x * sprite_w
push structSegment
pop ds ; ds = struct seg
mov di, structAddress ; ds:di = struct ptr
mov si, di
add si, BMP_HEIGHT_OFFSET
mov cx, [word ds:si]
mov varImgHeight, cx ; img Height
mov dx, [word ds:si+2]
mov varImgWidth, dx ; Img Width
is_valid_coord_vga_mem xCoord_, yCoord_, spriteWidth_, varImgHeight_
cmp ax,0
ja @@err_coord
@@ok:
mov varSpriteY,0
push structAddress ; struct addr
push structSegment ; struct seg
call SendPalStruct
push [word GR_START_ADDR]
pop es
mov ax, yCoord ; yTop
add ax, varImgHeight ; height
mov varCurrY,ax ; y=Ytop+Height
mov cx, varImgHeight ; height
mov si, di
add si, BMP_DATA_SEG_OFFSET
mov varDataPtr,0
push [word si]
pop ds
xor si,si
xor di,di
translate_coord_to_buf_addr varDataPtr_, varXTop_, varSpriteY_, varImgWidth_
; cx = height, ds:si = data, es:di = screen
@@DrawLoop:
push cx
push si
cld ; Clear direction flag, for movsb.
mov cx, spriteWidth ; sprite width
translate_coord_to_vga_addr xCoord_, varCurrY_
; source DS:SI
; dest ES:DI
; len CX
rep movsb ; Copy line in buffer to screen.
pop si
add si, varImgWidth ; si += img width
dec varCurrY ; y--
pop cx
loop @@DrawLoop
jmp @@end
@@err_coord:
@@end:
pop es
pop ds
popa
restore_sp_bp
ret 14
ENDP PlaySpriteInPlace
;////////////////////////////////////////////////////////////////////////////
; FUNCTION LIKE MACROS
;////////////////////////////////////////////////////////////////////////////
;----------------------------------------------------------------------
;
;
; grm_XXXX (XXX, XXX)
;----------------------------------------------------------------------
MACRO grm_PlaySpriteInPlace index_to_draw, bmp_struct_addr, bmp_struct_seg, x, y, sprite_w, num_sprites
push index_to_draw
push bmp_struct_addr
push bmp_struct_seg
push x
push y
push sprite_w
push num_sprites
call PlaySpriteInPlace
ENDM