gfx.S 3.13 KB
Newer Older
Florian Schulze's avatar
Florian Schulze committed
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
[GLOBAL _get_block]
[GLOBAL _put_block]

[EXTERN ___djgpp_base_address]


[SECTION .text]


; void get_block(char page, long x, long y, long width, long height, char *buffer);

_get_block
	push	ebp
	mov	ebp,esp
	pusha

	mov	eax,[ebp+12]
	mov	[.x],eax
	mov	eax,[ebp+16]
	mov	[.y],eax
	mov	eax,[ebp+20]
	mov	[.draw_width],eax
	mov	eax,[ebp+24]
	mov	[.draw_height],eax
	mov	eax,[ebp+28]
	mov	[.buf_ptr],eax

	mov	eax,[.x]
	or	eax,eax
	jns	.11

	neg	eax
	cmp	eax,[ebp+20]
	jge	near .exit

	mov	dword [.x],0
	sub	[.draw_width],eax
	add	[.buf_ptr],eax

.11
	cmp	dword [.x],400
	jge	near .exit

	mov	eax,[.y]
	or	eax,eax
	jns	.12

	neg	eax
	cmp	eax,[ebp+24]
	jge	near .exit

	mov	dword [.y],0
	sub	[.draw_height],eax
	imul	dword [ebp+20]
	add	[.buf_ptr],eax

.12
	cmp	eax,256
	jge	near .exit

	mov	edi,0xa0000
	sub	edi,[___djgpp_base_address]
	xor	eax,eax
	mov	al,[ebp+8]
	shl	eax,15
	add	edi,eax
	mov	eax,100
	imul	dword [.y]
	add	edi,eax
	mov	[.vga_ptr],edi

	mov	dword [.c1],0

.1
	mov	edx,0x3ce
        mov	eax,[.x]
	add	eax,[.c1]
	shl	eax,8
	and	ah,3
	mov	al,4
	out	dx,ax

	mov	esi,[.vga_ptr]
	mov	eax,[.x]
	add	eax,[.c1]
	sar	eax,2
	add	esi,eax

	mov	edi,[.buf_ptr]
	add	edi,[.c1]

	mov	ebx,[.draw_height]

.2
	mov	ecx,[.draw_width]
	add	ecx,3
	sub	ecx,[.c1]
	shr	ecx,2
	mov	edx,ecx
	cmp	ecx,0
	jle	.4

.3
	mov	al,[esi]
	mov	[edi],al
	inc	esi
	add	edi,4
	dec	cx
	jnz	.3

.4
	add	esi,100
	sub	esi,edx

	add	edi,[ebp+20]
	mov	eax,edx
	shl	eax,2
	sub	edi,eax

	dec	ebx
	jnz	.2

	inc	byte [.c1]
	cmp	byte [.c1],4
	jl	near .1

.exit
	popa
	pop	ebp
	ret

.c1		dd	0
.vga_ptr	dd	0
.x		dd	0
.y		dd	0
.draw_width	dd	0
.draw_height	dd	0
.buf_ptr	dd	0


; void put_block(char page, long x, long y, long width, long height, char *buffer);

_put_block
	push	ebp
	mov	ebp,esp
	pusha

	mov	eax,[ebp+12]
	mov	[.x],eax
	mov	eax,[ebp+16]
	mov	[.y],eax
	mov	eax,[ebp+20]
	mov	[.draw_width],eax
	mov	eax,[ebp+24]
	mov	[.draw_height],eax
	mov	eax,[ebp+28]
	mov	[.buf_ptr],eax

	mov	eax,[.x]
	or	eax,eax
	jns	.11

	neg	eax
	cmp	eax,[ebp+20]
	jge	near .exit

	mov	dword [.x],0
	sub	[.draw_width],eax
	add	[.buf_ptr],eax

.11
	cmp	dword [.x],400
	jge	near .exit

	mov	eax,[.y]
	or	eax,eax
	jns	.12

	neg	eax
	cmp	eax,[ebp+24]
	jge	near .exit

	mov	dword [.y],0
	sub	[.draw_height],eax
	imul	dword [ebp+20]
	add	[.buf_ptr],eax

.12
	cmp	eax,256
	jge	near .exit

	mov	edi,0xa0000
	sub	edi,[___djgpp_base_address]
	xor	eax,eax
	mov	al,[ebp+8]
	shl	eax,15
	add	edi,eax
	mov	eax,100
	imul	dword [.y]
	add	edi,eax
	mov	[.vga_ptr],edi

	mov	dword [.c1],0

.1
	mov	edx,0x3c4
	mov	eax,0x100
        mov	ecx,[.x]
	add	ecx,[.c1]
	and	ecx,3
	shl	eax,cl
	mov	al,2
	out	dx,ax

	mov	esi,[.buf_ptr]
	add	esi,[.c1]

	mov	edi,[.vga_ptr]
	mov	eax,[.x]
	add	eax,[.c1]
	sar	eax,2
	add	edi,eax

	mov	ebx,[.draw_height]

.2
	mov	ecx,[.draw_width]
	add	ecx,3
	sub	ecx,[.c1]
	shr	ecx,2
	mov	edx,ecx
	cmp	ecx,0
	jle	.4

.3
	mov	al,[esi]
	mov	[edi],al
	add	esi,4
	inc	edi
	dec	ecx
	jnz	.3

.4
	add	esi,[ebp+20]
	mov	eax,edx
	shl	eax,2
	sub	esi,eax

	add	edi,100
	sub	edi,edx

	dec	ebx
	jnz	.2

	inc	byte [.c1]
	cmp	byte [.c1],4
	jl	near .1

.exit
	popa
	pop	ebp
	ret

.c1		dd	0
.vga_ptr	dd	0
.x		dd	0
.y		dd	0
.draw_width	dd	0
.draw_height	dd	0
.buf_ptr	dd	0