.data
LBM_Handle dd 0
LBM_Size dd 0
LBM_Width dd 0
LBM_Height dd 0
LBM_Palette dd 0
LBM_nPlanes dd 0
LBM_PixelSize dd 0
LBM_Output dd 0
LBM_Flag dd 0
LBM_CallBack dd 0
LBM_ColorCount dd 0
;------------------------ end of common
LBM_Output2 dd 0
LBM_Masking dd 0
LBM_Compression dd 0
LBM_RLE_Data dd 0
LBM_BitStream dd 0
LBM_ILBM dd 0
LBM_HAM dd 0
LBM_EHB dd 0
LBM_Atari dd 0
LBM_BitPlanSize dd 0
.code
;-------------------------------------------------------------------
align 4
Load_HAM: mov LBM_HAM,1
Load_LBM: call Load_File
jc Load_LBM_Unknow
mov LBM_Handle,eax
mov LBM_Size,ecx
mov esi,LBM_Handle
mov eax,[esi]
cmp eax,'MROF'
jne Load_GIF_Unknow
Load_LBM_l1: mov eax,[esi]
cmp eax,'DHMB'
je Load_LBM_BMHD_Found
inc esi
jmp Load_LBM_l1
Load_LBM_BMHD_Found:
add esi,4
mov ebx,[esi]
bswap ebx
movzx eax,Word ptr [esi+4]
xchg al,ah
inc eax
and eax,-2
mov LBM_Width,eax
movzx eax,Word ptr [esi+6]
xchg al,ah
mov LBM_Height,eax
movzx eax,Byte ptr [esi+12]
mov LBM_nPlanes,eax
movzx eax,Byte ptr [esi+13]
mov LBM_Masking,eax
movzx eax,Byte ptr [esi+14]
mov LBM_Compression,eax
add esi,ebx
cmp LBM_nPlanes,24
je Load_LBM_TrueColor
cmp LBM_nPlanes,32
je Load_LBM_TrueColor
Load_LBM_l2: mov eax,[esi]
cmp eax,'PAMC'
je Load_LBM_CMAP_Found
inc esi
jmp Load_LBM_l2
Load_LBM_CMAP_Found:
add esi,4
mov ebx,[esi]
bswap ebx
mov eax,ebx
xor edx,edx
mov ecx,3
div ecx
mov LBM_ColorCount,eax
lea eax,[esi+4]
mov LBM_Palette,eax
add esi,ebx
Load_LBM_TrueColor:
mov LBM_HAM,0
mov ebp,LBM_Handle
add ebp,LBM_Size
Load_LBM_l3: mov eax,[esi]
cmp eax,'GMAC'
je Load_LBM_CAMG_Found
inc esi
cmp esi,ebp
jb Load_LBM_l3
mov esi,LBM_Handle
jmp Load_LBM_l4
Load_LBM_CAMG_Found:
mov eax,[esi+8]
bswap eax
and eax,880h
je Load_LBM_l4
test eax,800h
je Load_LBM_NoHAM
mov LBM_HAM,1
Load_LBM_NoHAM: test eax,80h
je Load_LBM_NoEHB
mov LBM_EHB,1
Load_LBM_NoEHB: mov esi,LBM_Handle
Load_LBM_l4: mov eax,[esi]
cmp eax,'YDOB'
je Load_LBM_BODY_Found
inc esi
jmp Load_LBM_l4
Load_LBM_BODY_Found:
add esi,8
mov LBM_RLE_Data,esi
mov esi,LBM_Handle
add esi,4
mov LBM_ILBM,0
Load_LBM_l5: mov eax,[esi]
cmp eax,'MBLI'
je Load_LBM_ILBM_Found
inc esi
cmp eax,'DHMB'
jne Load_LBM_l5
dec LBM_ILBM
Load_LBM_ILBM_Found:
inc LBM_ILBM
call Decode_LBM
call Translate_BitPlanes
cmp LBM_HAM,1
jne Load_LBM_NoHAM2
call Decode_HAM
Load_LBM_NoHAM2:
cmp LBM_EHB,1
jne Load_LBM_End
call Decode_EHB
Load_LBM_End: mov LBM_HAM,0
mov LBM_EHB,0
clc
ret
Load_LBM_Unknow:
mov LBM_HAM,0
mov LBM_EHB,0
stc
ret
;-------------------------------------------------------------------
align 4
Decode_LBM: mov eax,LBM_Width
add eax,7
shr eax,3
test eax,1
je Decode_LBM_WidthPadded
inc eax
Decode_LBM_WidthPadded:
mov ebx,LBM_nPlanes
cmp LBM_Masking,1
jne Decode_LBM_NoMask
inc ebx
Decode_LBM_NoMask:
xor edx,edx
mul ebx
mov ebx,LBM_Height
xor edx,edx
mul ebx
push eax
shl eax,1
push eax
mov eax,LBM_Width
mov ebx,LBM_Height
xor edx,edx
mul ebx
mov ebx,LBM_nPlanes
shr ebx,3
or ebx,ebx
jne Decode_LBM_8bit
inc ebx
Decode_LBM_8bit:
mov LBM_PixelSize,ebx
xor edx,edx
mul ebx
push eax
push L GMEM_FIXED or GMEM_ZEROINIT
call LocalAlloc
mov LBM_Output,eax
push L GMEM_FIXED or GMEM_ZEROINIT
call LocalAlloc
mov LBM_Output2,eax
mov edi,eax
pop edx
cmp LBM_Compression,0
je Decode_LBM_Normal
mov esi,LBM_RLE_Data
mov eax,[esi]
cmp eax,'TADV'
jne Decode_LBM_Amiga
mov LBM_Atari,1
jmp Decode_LBM_Atari
Decode_LBM_Amiga:
cmp LBM_ILBM,0
je Decode_LBM_DP2e_l1
mov edx,LBM_Height
Decode_LBM_l1: push edx
mov edx,LBM_nPlanes
cmp LBM_Masking,1
jne Decode_LBM_l2
inc edx
Decode_LBM_l2: push edx
mov edx,LBM_Width
add edx,7
shr edx,3
test edx,1
je Decode_LBM_l3
inc edx
Decode_LBM_l3: mov al,[esi]
cmp al,-128
je Decode_LBM_NOP
or al,al
js Decode_LBM_rep
movsx ecx,al
inc ecx
sub edx,ecx
inc esi
rep movsb
or edx,edx
jne Decode_LBM_l3
pop edx
dec edx
jne Decode_LBM_l2
pop edx
dec edx
jne Decode_LBM_l1
ret
Decode_LBM_rep: inc esi
movsx ecx,al
neg ecx
inc ecx
sub edx,ecx
mov al,[esi]
rep stosb
inc esi
or edx,edx
jne Decode_LBM_l3
pop edx
dec edx
jne Decode_LBM_l2
pop edx
dec edx
jne Decode_LBM_l1
ret
Decode_LBM_NOP: inc esi
jmp Decode_LBM_l3
Decode_LBM_DP2e_l1:
mov al,[esi]
cmp al,-128
je Decode_LBM_DP2e_NOP
or al,al
js Decode_LBM_DP2e_rep
movsx ecx,al
inc ecx
sub edx,ecx
inc esi
rep movsb
or edx,edx
js Decode_LBM_DP2e_err
jne Decode_LBM_DP2e_l1
Decode_LBM_DP2e_err:
ret
Decode_LBM_DP2e_rep:
inc esi
movsx ecx,al
neg ecx
inc ecx
sub edx,ecx
mov al,[esi]
rep stosb
inc esi
or edx,edx
js Decode_LBM_DP2e_err
jne Decode_LBM_DP2e_l1
ret
Decode_LBM_DP2e_NOP:
inc esi
jmp Decode_LBM_DP2e_l1
Decode_LBM_Normal:
cld
mov ecx,edx
mov esi,LBM_RLE_Data
rep movsb
ret
Decode_LBM_Atari:
xor edx,edx
mov eax,LBM_Width
shr eax,3
mul LBM_Height
mov LBM_BitPlanSize,eax
mov ecx,LBM_nPlanes
Decode_LBM_Atari_l1:
push ecx
push edi
push esi
add esi,8
movzx eax,Word ptr [esi]
xchg al,ah
lea ebp,[esi+eax]
sub eax,3
add esi,2
mov ecx,eax
Decode_LBM_Atari_l2:
push ecx
movsx ecx,Byte ptr[esi]
or ecx,ecx
je Decode_LBM_Atari_NOP
js Decode_LBM_Atari_Normal
cmp ecx,1
je Decode_LBM_Atari_RunLenght
mov ax,ds:[ebp]
rep stosw
add ebp,2
inc esi
pop ecx
dec ecx
jne Decode_LBM_Atari_l2
jmp Decode_LBM_Atari_LoopClose
Decode_LBM_Atari_RunLenght:
movzx ecx,Word ptr ds:[ebp]
xchg cl,ch
mov ax,ds:[ebp+2]
rep stosw
pop ecx
add ebp,4
inc esi
dec ecx
jne Decode_LBM_Atari_l2
jmp Decode_LBM_Atari_LoopClose
Decode_LBM_Atari_Normal:
neg ecx
push esi
mov esi,ebp
rep movsw
mov ebp,esi
pop esi
inc esi
pop ecx
dec ecx
jne Decode_LBM_Atari_l2
jmp Decode_LBM_Atari_LoopClose
Decode_LBM_Atari_NOP:
inc esi
pop ecx
dec ecx
jne Decode_LBM_Atari_l2
jmp Decode_LBM_Atari_LoopClose
Decode_LBM_Atari_LoopClose:
pop esi
mov eax,[esi+4]
bswap eax
add esi,8
add esi,eax
cmp esi,ebp
je Decode_LBM_Atari_ok1
push esi
mov ecx,esi
sub ecx,ebp
js Decode_LBM_Atari_ok1
shr ecx,1
mov ebp,esi
rep movsw
pop esi
Decode_LBM_Atari_ok1:
pop edi
add edi,LBM_BitPlanSize
pop ecx
dec ecx
jne Decode_LBM_Atari_l1
clc
ret
;-------------------------------------------------------------------
align 4
Translate_BitPlanes:
mov esi,LBM_Output2
mov edi,LBM_Output
cmp LBM_ILBM,1
jne Translate_NoBitPlanes
cmp LBM_Atari,1
je Translate_Atari
mov edx,LBM_Height
Translate_BitPlanes_l0:
mov ebx,0
push edx
Translate_BitPlanes_l1:
mov edx,LBM_Width
mov LBM_BitStream,0
push edi
Translate_BitPlanes_l2:
xor eax,eax
call LBM_GetBit
mov ebp,[edi]
rcl eax,1
mov cl,bl
shl eax,cl
or ebp,eax
mov [edi],ebp
add edi,LBM_PixelSize
dec edx
jne Translate_BitPlanes_l2
pop edi
mov eax,LBM_BitStream
add eax,7
shr eax,3
test eax,1
je Translate_BitPlanes_Padded
inc eax
Translate_BitPlanes_Padded:
add esi,eax
inc ebx
cmp ebx,LBM_nPlanes
jb Translate_BitPlanes_l1
push eax
xor edx,edx
mov eax,LBM_Width
mov ebx,LBM_PixelSize
mul ebx
add edi,eax
pop eax
cmp LBM_Masking,1
jne Translate_BitPlanes_nomask
add esi,eax
Translate_BitPlanes_nomask:
pop edx
dec edx
jne Translate_BitPlanes_l0
push LBM_Output2
call LocalFree
mov edi,LBM_Output
ret
Translate_NoBitPlanes:
mov eax,LBM_Width
mov ebx,LBM_Height
xor edx,edx
mul ebx
mov ecx,eax
rep movsb
push LBM_Output2
call LocalFree
mov edi,LBM_Output
ret
Translate_Atari:
xor edx,edx
mov eax,LBM_Width
shr eax,4
mul LBM_Height
mov ebp,eax
mov edx,LBM_nPlanes
mov esi,LBM_Output2
mov edi,LBM_Output
Translate_Atari_l1:
mov ecx,LBM_Width
shr ecx,4
push edi
Translate_Atari_l2:
push ecx
mov ecx,LBM_Height
push edi
Translate_Atari_l3:
push ecx
movzx eax,Word ptr [esi]
xchg al,ah
mov ecx,16
Translate_Atari_l4:
shl ax,1
mov bl,[edi]
rcr bl,1
mov [edi],bl
inc edi
dec ecx
jne Translate_Atari_l4
add esi,2
add edi,LBM_Width
sub edi,16
pop ecx
dec ecx
jne Translate_Atari_l3
pop edi
add edi,16
pop ecx
dec ecx
jne Translate_Atari_l2
pop edi
dec edx
jne Translate_Atari_l1
push LBM_Output2
call LocalFree
mov edi,LBM_Output
xor edx,edx
mov eax,LBM_Width
mul LBM_Height
mov ecx,eax
Translate_Atari_l5:
mov al,[edi]
shr al,4
mov [edi],al
inc edi
dec ecx
jne Translate_Atari_l5
mov edi,LBM_Output
ret
;-------------------------------------------------------------------
align 4
Decode_HAM: mov eax,LBM_Width
mov ebx,LBM_Height
xor edx,edx
mul ebx
push eax
shl eax,2
push eax
push L GMEM_FIXED or GMEM_ZEROINIT
call LocalAlloc
mov edi,eax
pop ecx
push eax
mov esi,LBM_Output
mov ebx,LBM_Palette
Decode_HAM_l1: mov al,[esi]
push ecx
mov ecx,8
sub ecx,LBM_nPlanes
shl al,cl
pop ecx
mov ah,al
shr ah,6
and eax,33fh
cmp ah,1
je Decode_HAM_B
cmp ah,2
je Decode_HAM_R
cmp ah,3
je Decode_HAM_G
push ecx
mov ecx,8
sub ecx,LBM_nPlanes
shr al,cl
pop ecx
lea edx,[eax*2+eax]
mov eax,[ebx+edx]
bswap eax
shr eax,8
mov [edi],eax
add edi,4
inc esi
dec ecx
jne Decode_HAM_l1
jmp Decode_HAM_End
Decode_HAM_R: and eax,0ffh
mov edx,[edi-4]
shl eax,18
and edx,0ffffh
or edx,eax
mov [edi],edx
add edi,4
inc esi
dec ecx
jne Decode_HAM_l1
jmp Decode_HAM_End
Decode_HAM_G: and eax,0ffh
mov edx,[edi-4]
shl eax,10
and edx,0ff00ffh
or edx,eax
mov [edi],edx
add edi,4
inc esi
dec ecx
jne Decode_HAM_l1
jmp Decode_HAM_End
Decode_HAM_B: and eax,0ffh
mov edx,[edi-4]
shl eax,2
and edx,0ffff00h
or edx,eax
mov [edi],edx
add edi,4
inc esi
dec ecx
jne Decode_HAM_l1
Decode_HAM_End: push LBM_Output
call LocalFree
pop LBM_Output
mov LBM_PixelSize,4
ret
;-------------------------------------------------------------------
align 4
Decode_EHB: mov eax,LBM_Width
mov ebx,LBM_Height
xor edx,edx
mul ebx
push eax
shl eax,2
push eax
push L GMEM_FIXED or GMEM_ZEROINIT
call LocalAlloc
mov edi,eax
pop ecx
push eax
mov esi,LBM_Output
mov ebx,LBM_Palette
Decode_EHB_l1: movzx eax,Byte ptr [esi]
test al,20h
jne Decode_EHB_Brighten
lea edx,[eax*2+eax]
mov eax,[ebx+edx]
bswap eax
shr eax,8
mov [edi],eax
add edi,4
inc esi
dec ecx
jne Decode_EHB_l1
jmp Decode_EHB_End
Decode_EHB_Brighten:
and eax,1fh
lea edx,[eax*2+eax]
mov eax,[ebx+edx]
bswap eax
and eax,0fefefefeh
shr eax,9
mov [edi],eax
add edi,4
inc esi
dec ecx
jne Decode_EHB_l1
Decode_EHB_End: push LBM_Output
call LocalFree
pop LBM_Output
mov LBM_PixelSize,4
ret
;-------------------------------------------------------------------
align 4
LBM_GetBit: push eax ebx ecx
mov ebx,LBM_BitStream
inc LBM_BitStream
mov cl,bl
and cl,7
inc cl
shr ebx,3
mov al,[esi+ebx]
rcl al,cl
pop ecx ebx eax
ret
;-------------------------------------------------------------------