[go: up one dir, main page]

Menu

[r83]: / engine / bitmap_a.asm  Maximize  Restore  History

Download this file

117 lines (86 with data), 3.4 kB

  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
;
; Optional Assembly bitmask code.
; This is only used if you #define USE_ASM in ire_game
;
; Written more for amusement than for speed :-)
;
[BITS 32]
[global _SetBit_ASM]
[global _ResetBit_ASM]
[global _GetBit_ASM]
[EXTERN _cmap_width]
[EXTERN _cmap_height]
[SECTION .text]
;
; Set a bit in the collision matrix
;
_SetBit_ASM:
push ebp
mov ebp,esp
pushad
mov eax, [_cmap_width]
mov edi, [ebp+16] ; EDI is the collision matrix
mov edx, [ebp+12] ; Get Y coordinate
mov ebx, [ebp+8] ; Get X coordinate
mul edx ; Get offset, Y*width
add edi, eax ; EDI now points to the right byte column
mov ecx, ebx ; Save the X coordinate in CX
shr ebx, 3 ; Divide by 8, to get the byte
add edi, ebx ; Add the X coordinate
and cl, 7 ; Get the bit offset, 0-7 from the remainder
mov al, 1 ; Set AL to be one, and shift it by CL
shl al, cl ; Now we have the bitmask for ORing
or [edi], al ; Set the bit we want
popad
pop ebp
ret
;
; Reset a bit in the collision matrix
;
_ResetBit_ASM:
push ebp
mov ebp,esp
pushad
mov eax, [_cmap_width]
mov edi, [ebp+16] ; EDI is the collision matrix
mov edx, [ebp+12] ; Get Y coordinate
mov ebx, [ebp+8] ; Get X coordinate
mul edx ; Get offset, Y*width
add edi, eax ; EDI now points to the right byte column
mov ecx, ebx ; Save the X coordinate in CX
shr ebx, 3 ; Divide by 8, to get the byte
add edi, ebx ; Add the X coordinate
and cl, 7 ; Get the bit offset, 0-7 from the remainder
mov al, 1 ; Set AL to be one, and shift it by CL
shl al, cl ; Now we have the bitmask for ORing
xor al,255 ; Invert it
and [edi], al ; Set the bit we want
popad
pop ebp
ret
;
; Get the state of an element in the collision matrix
;
_GetBit_ASM:
push ebp
mov ebp,esp
xor eax,eax ; Zero EAX for the return
pushad
mov edi, [ebp+16] ; EDI is the collision matrix
mov eax, [_cmap_width]
mov edx, [ebp+12] ; Get Y coordinate
mov ebx, [ebp+8] ; Get X coordinate
mul edx ; Get offset, Y*width
add edi, eax ; EDI now points to the right byte column
mov ecx, ebx ; Save the X coordinate in CX
shr ebx, 3 ; Divide by 8, to get the byte
add edi, ebx ; Add the X coordinate
and cx, 7 ; Get the bit offset, 0-7 from the remainder
mov al, [edi] ; Copy the interesting byte into al
btc ax,cx ; Get the contents of bit CL in byte AL
; Carry Flag is now set to this value
popad ; EAX returns to zero
pop ebp
salc ; SET AL=CARRY - http://www.x86.org
ret ; SALC is undocumented but present in all
; known x86 compatible microprocessors