// // BwgBurn - CD-R/CD-RW/DVD-R/DVD-RW burning program for Windows XP // // Copyright (C) 2006 by Jack W. Griffin (butchg@comcast.net) // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the // // Free Software Foundation, Inc., // 59 Temple Place, Suite 330, // Boston, MA 02111-1307 USA // using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace Bwg.Scsi { /// /// This object represents a single mode page in a mode table. /// public class ModePage : Result { #region private member variables /// /// The data associated with the page table. This data also includes the page code and length /// data elements from the mode page data. /// protected byte[] m_page_data; #endregion #region constructor /// /// This is the constructor for the mode page object. It builds a mode page object from /// the raw reply area from the SCSI device. /// /// A pointer to the raw reply area /// The size of the raw reply area in bytes /// The offset to the mode page data public ModePage(IntPtr buffer, int size, ref ushort offset) : base(buffer, size) { byte b = Get8(offset); offset++; byte len = Get8(offset); offset++; m_page_data = new byte[len + 2]; m_page_data[0] = b; m_page_data[1] = len; for(int i = 0 ; i < len ; i++) m_page_data[i + 2] = Get8(offset++); } #endregion #region public properties /// /// This is the data that makes up this mode page /// public byte[] PageData { get { return m_page_data; } } /// /// The length of this mode page in bytes /// public ushort Length { get { return (ushort)m_page_data.GetLength(0); } } /// /// The page code for this page /// public byte PageCode { get { return (byte)(m_page_data[0] & 0x3f); } } /// /// If true, these parameters are saved permanently /// public bool ParametersSavable { get { return ((m_page_data[0] & 0x80) != 0) ? true : false; } set { if (value) m_page_data[0] |= 0x80; else m_page_data[0] &= 0x7f; } } #endregion #region public methods /// /// Retreive a 32 bit value from a mode page /// /// offset in the page to the value /// a 32 bit value retreived from the mode page data public int ModeGet32(int offset) { return m_page_data[offset + 0] << 24 | m_page_data[offset + 1] << 16 | m_page_data[offset + 2] << 8 | m_page_data[offset + 3] << 0; } /// /// Set a 32 bit value in a mode page /// /// offset in the page to where the value will be placed /// the value to write public void ModeSet32(int offset, int value) { m_page_data[offset + 0] = (byte)((value >> 24) & 0xff); m_page_data[offset + 1] = (byte)((value >> 16) & 0xff); m_page_data[offset + 2] = (byte)((value >> 8) & 0xff); m_page_data[offset + 3] = (byte)((value >> 0) & 0xff); } /// /// /// /// /// public ushort ModeGet16(int offset) { return (ushort)(m_page_data[offset + 0] << 8 | m_page_data[offset + 1] << 0); } /// /// /// /// /// public void ModeSet16(int offset, ushort value) { m_page_data[offset + 0] = (byte)((value >> 8) & 0xff); m_page_data[offset + 1] = (byte)((value >> 0) & 0xff); } #endregion } }