Please post any comments / improvement ideas :)


; ########################################
.386
.model flat, stdcall
option casemap :none

; ########################################

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

; ########################################

ID3Tag STRUCT
szTitle db 31 dup (?)
szArtist db 31 dup (?)
szAlbum db 31 dup (?)
szYear db 5 dup (?)
szComment db 29 dup (?)
ID3Tag ENDS

; ########################################

.data
szTestMp3 db "test1.mp3", 0

; ########################################

.data?
szID3Tag db 122 dup (?)
hFile dd ?
nTmp dd ?
id3 ID3Tag <>

; ########################################

.code

start:


invoke CreateFile, addr szTestMp3, GENERIC_READ, \
FILE_SHARE_READ, 0, \
OPEN_EXISTING, 0, 0
mov hFile, eax

invoke SetFilePointer, eax, -125, 0, FILE_END

invoke ReadFile, hFile, addr szID3Tag, 122, addr nTmp, 0

invoke CloseHandle, hFile

lea edi, szID3Tag
lea esi, id3.szTitle
xor ecx, ecx
@@:
mov al, byte ptr [edi]
mov byte ptr [esi], al
inc edi
inc esi
inc ecx
cmp ecx, 30
jne @B

lea esi, id3.szArtist
xor ecx, ecx
@@:
mov al, byte ptr [edi]
mov byte ptr [esi], al
inc edi
inc esi
inc ecx
cmp ecx, 30
jne @B

lea esi, id3.szAlbum
xor ecx, ecx
@@:
mov al, byte ptr [edi]
mov byte ptr [esi], al
inc edi
inc esi
inc ecx
cmp ecx, 30
jne @B

lea esi, id3.szYear
xor ecx, ecx
@@:
mov al, byte ptr [edi]
mov byte ptr [esi], al
inc edi
inc esi
inc ecx
cmp ecx, 4
jne @B

lea esi, id3.szComment
xor ecx, ecx
@@:
mov al, byte ptr [edi]
mov byte ptr [esi], al
inc edi
inc esi
inc ecx
cmp ecx, 28
jne @B

invoke MessageBox, 0, addr id3.szTitle, 0, 0
invoke MessageBox, 0, addr id3.szArtist, 0, 0
invoke MessageBox, 0, addr id3.szAlbum, 0, 0
invoke MessageBox, 0, addr id3.szYear, 0, 0
invoke MessageBox, 0, addr id3.szComment, 0, 0

invoke ExitProcess, 0

end start

; ########################################
Posted on 2001-12-30 15:38:29 by bazik
Why not replace the loop with a rep movsd :

lea esi, szID3Tag
lea edi, id3.szTitle
; xor ecx, ecx
mov ecx, 7 ; 30/4
rep movsd
mov ax, WORD PTR ; last word
mov WORD PTR , ax
add esi, 2

Use a proc to save code :

CopyString PROC src:DWORD, dst:DWORD
mov esi, src
mov edi, dst
mov ecx, 7 ; 30/4
rep movsd
mov ax, WORD PTR ; last word
mov WORD PTR , ax
add esi, 2
ret
CopyString ENDP
Posted on 2001-12-30 17:44:44 by Dr. Manhattan
I like it, but shouldn't it check if there IS a id3.1 tag? I've got lots of mp3's without them. In that case, all the strings consist only of y's with two dots on top of them (I seem to remember that being char 255, but I'm not sure).
Posted on 2001-12-31 05:32:47 by Qweerdy

I like it, but shouldn't it check if there IS a id3.1 tag? I've got lots of mp3's without them. In that case, all the strings consist only of y's with two dots on top of them (I seem to remember that being char 255, but I'm not sure).


Hi :)
This is part of my Media Player... I just wrote it as a test prog. Moved the above function to a PROC and check the return value. If there's now ID3 tag for artist and title, it will add "???". Any other fields stay empty.
Posted on 2001-12-31 07:34:28 by bazik
THank you for this code
Posted on 2002-01-16 23:12:27 by Duker