News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Read Struct problem

Started by ragdog, November 16, 2011, 04:28:10 PM

Previous topic - Next topic

ragdog

Hi

I Have a problem by reading this struct

; Damn! ...record field names must be unique...
; So i prepend names with 'td'
tdBits RECORD \
tdAdr:4, ; bits4-7  Adr
tdControl:4 ; bits0-3  Control

TRACK_DATA STRUCT ; sizeof = 8
Reserved BYTE ? ; 000h
tdBits <> ; 001h
TrackNumber BYTE ? ; 002h
Reserved1 BYTE ? ; 003h
Address BYTE 4 dup(?) ; 004h
TRACK_DATA ENDS


LOCAL   toc:CDROM_TOC     

lea    esi,toc.TrackData     
assume esi:ptr TRACK_DATA

movzx edi,[esi].tdBits.tdControl           <<<<<<<<<<<


How can i read it out tdControl ? for check if Audio or data Track

c++

// - toc.TrackData[].Control & AUDIO_DATA_TRACK == 0 -> AUDIO TRACK
// - toc.TrackData[].Control & AUDIO_DATA_TRACK == 1 -> DATA TRACK

Here is my code

Header:


MAXIMUM_NUMBER_TRACKS equ 100
MAXIMUM_CDROM_SIZE equ 804

;
; CD ROM Table OF Contents (TOC)
;
; Format 0 - Get table of contents
;

; Damn! ...record field names must be unique...
; So i prepend names with 'td'
tdBits RECORD \
tdAdr:4, ; bits4-7  Adr
tdControl:4 ; bits0-3  Control

TRACK_DATA STRUCT ; sizeof = 8
Reserved BYTE ? ; 000h
tdBits <> ; 001h
TrackNumber BYTE ? ; 002h
Reserved1 BYTE ? ; 003h
Address BYTE 4 dup(?) ; 004h
TRACK_DATA ENDS

PTRACK_DATA typedef ptr TRACK_DATA

CDROM_TOC STRUCT ; sizeof = 0324h

; Header
_Length BYTE 2 dup(?) ; 000h  original name Length
FirstTrack BYTE ? ; 002h
LastTrack BYTE ? ; 003h
; Track data
TrackData TRACK_DATA MAXIMUM_NUMBER_TRACKS dup(<?>) ; 004h
CDROM_TOC ENDS
PCDROM_TOC typedef ptr CDROM_TOC
CDROM_TOC_SIZEequ sizeof CDROM_TOC





Greets

ragdog

#1
I have solved to read out the bitfield struct
With two ways

Struct

AUDIO_DATA_TRACK EQU 4h
TRACK_DATA STRUCT
Reserved BYTE ?
TRACK_DATA_ RECORD     AAAdr : 4,AAControl : 4
TRACK_DATA_ BYTE ?
TrackNumber BYTE ?
Reserved1 BYTE ?
Address BYTE 4 dup (?)
TRACK_DATA ENDS

PTRACK_DATA typedef ptr TRACK_DATA


way 1.
lea    esi,toc.TrackData       
            assume esi:ptr TRACK_DATA
                 movzx eax,[esi].TRACK_DATA_
               AND EAX,AUDIO_DATA_TRACK

                .if eax!=AUDIO_DATA_TRACK
                        invoke  wsprintf,addr szBuf,CTEXT ("Track %02d Audio"),ecx
                 .else
                    invoke  wsprintf,addr szBuf,CTEXT ("Track %02d Data"),ecx
                       


or other good solution

lea    esi,toc.TrackData       
            assume esi:ptr TRACK_DATA
               .if [esi].TRACK_DATA_ & AUDIO_DATA_TRACK
                         invoke  wsprintf,addr szBuf,CTEXT ("Track %02d Data"),ecx
                 .else
                   
                        invoke  wsprintf,addr szBuf,CTEXT ("Track %02d Audio"),ecx
               .endif

ToutEnMasm

The translate of the ntddcdrm.h (\WinDDK\7600.16385.1 the more recent) given by the translator (windows.inc subforum)
don't agree with that.
Quote
;
; CD ROM Table OF Contents (TOC)
; Format 0 - Get table of contents
;
RECATRACK_DATA      RECORD     ABAdr : 4,           
            ABControl : 4
                                                          ;4+4 = 8 bits <<<<<<<<<<<<<< a byte

TRACK_DATA   STRUCT
   Reserved BYTE ?
   RECATRACK_DATA BYTE ?
   TrackNumber BYTE ?
   Reserved1 BYTE ?
   Address BYTE 4 dup (?)
TRACK_DATA      ENDS



CDROM_TOC   STRUCT
   length1 BYTE 2 dup (?) ; add two bytes for this field
   FirstTrack BYTE ?
   LastTrack BYTE ?
   TrackData TRACK_DATA MAXIMUM_NUMBER_TRACKS dup (<>)
CDROM_TOC      ENDS


CDROM_TOC_SIZE   equ   < CDROM_TOC>
;
; CD ROM Table OF Contents
; Format 1 - Session Information
;

CDROM_TOC_SESSION_DATA   STRUCT
   length1 BYTE 2 dup (?) ; add two bytes for this field
   FirstCompleteSession BYTE ?
   LastCompleteSession BYTE ?
   TrackData TRACK_DATA 1 dup (<>)
CDROM_TOC_SESSION_DATA      ENDS


ragdog

With your translater have i this result


RECATRACK_DATA      RECORD     ABAdr : 4,           
            ABControl : 4
                                                          ;4+4 = 8 bits <<<<<<<<<<<<<< a byte

TRACK_DATA   STRUCT
   Reserved BYTE ?
   RECATRACK_DATA BYTE ?
   TrackNumber BYTE ?
   Reserved1 BYTE ?
   Address BYTE 4 dup (?)
TRACK_DATA      ENDS


With h2incx from Japheth with commandline switch -q


TRACK_DATA struct
Reserved BYTE ?
TRACK_DATA_R0_Control equ 0fh
TRACK_DATA_R0_Adr equ 0f0h
TRACK_DATA_R0 BYTE ?
TrackNumber BYTE ?
Reserved1 BYTE ?
Address BYTE 4 dup (?)
TRACK_DATA ends



I have make a test this works without records field (RECATRACK_DATA      RECORD     ABAdr : 4,      ABControl : 4)
in my source


TRACK_DATA struct
      Reserved         BYTE ?
     TRACK_DATA_ BYTE ? An my mod you have say 4+4=8bits is a byte
     TrackNumber        BYTE ?
      Reserved1        BYTE ?
     Address          BYTE 4 dup (?)
TRACK_DATA ends


By all 3 structs have i the same results


Thanks and greets,

ragdog

Quotedon't agree with that.

With what?

ToutEnMasm


sorry
Quote
tdBits RECORD \
   tdAdr:4,         ; bits4-7  Adr
   tdControl:4         ; bits0-3  Control
I haven't see that this  was on comment ; bits4-7  Adr