Now using host frame buffer and sending the whole frame upon swap buffers.
BitArray saved the day to implement proper BitBlit.
Any font now drawing nicely.
1.1 --- a/FutabaVfd.vcxproj Thu May 22 22:36:43 2014 +0200
1.2 +++ b/FutabaVfd.vcxproj Sat May 24 00:43:18 2014 +0200
1.3 @@ -104,6 +104,7 @@
1.4 </ItemDefinitionGroup>
1.5 <ItemGroup>
1.6 <ClCompile Include="..\hidapi\windows\hid.c" />
1.7 + <ClCompile Include="src\BitArray.cpp" />
1.8 <ClCompile Include="src\FutabaVfd.cpp" />
1.9 <ClCompile Include="src\HidDevice.cpp" />
1.10 <ClCompile Include="src\Main.cpp" />
1.11 @@ -111,6 +112,7 @@
1.12 </ItemGroup>
1.13 <ItemGroup>
1.14 <ClInclude Include="..\hidapi\hidapi\hidapi.h" />
1.15 + <ClInclude Include="inc\BitArray.h" />
1.16 <ClInclude Include="inc\FutabaVfd.h" />
1.17 <ClInclude Include="inc\HidDevice.h" />
1.18 <ClInclude Include="inc\HidReport.h" />
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/inc/BitArray.h Sat May 24 00:43:18 2014 +0200
2.3 @@ -0,0 +1,159 @@
2.4 +/***************************************************************************
2.5 +* Arrays of Arbitrary Bit Length
2.6 +*
2.7 +* File : bitarray.h
2.8 +* Purpose : Header file for class supporting the creation and
2.9 +* manipulation of arbitrary length arrays of bits.
2.10 +* Author : Michael Dipperstein
2.11 +* Date : July 23, 2004
2.12 +*
2.13 +****************************************************************************
2.14 +* HISTORY
2.15 +*
2.16 +* $Id: bitarray.h,v 1.5 2010/02/04 03:31:43 michael Exp $
2.17 +* $Log: bitarray.h,v $
2.18 +* Revision 1.5 2010/02/04 03:31:43 michael
2.19 +* Replaced vector<unsigned char> with an array of unsigned char.
2.20 +*
2.21 +* Made updates for GCC 4.4.
2.22 +*
2.23 +* Revision 1.4 2007/08/06 05:23:12 michael
2.24 +* Updated for LGPL Version 3.
2.25 +*
2.26 +* All methods that don't modify object have been made
2.27 +* const to increase functionality of const bit_array_c.
2.28 +*
2.29 +* All assignment operators return a reference to the object being assigned a value so that operator chaining will work.
2.30 +*
2.31 +* Added >> and << operators.
2.32 +*
2.33 +* Revision 1.3 2006/04/30 23:34:07 michael
2.34 +* Improved performance by incorporating Benjamin Schindler's
2.35 +* <bschindler@student.ethz.ch> changes to pass arguments as a reference.
2.36 +*
2.37 +* Revision 1.2 2004/08/05 22:17:04 michael
2.38 +* Add overloads for bitwise operators returning values.
2.39 +* Add a more natural looking way to set bit values.
2.40 +*
2.41 +* Revision 1.1.1.1 2004/08/04 13:28:20 michael
2.42 +* bit_array_c
2.43 +*
2.44 +****************************************************************************
2.45 +*
2.46 +* Bitarray: An ANSI C++ class for manipulating arbitrary length bit arrays
2.47 +* Copyright (C) 2004, 2006-2007, 2010 by
2.48 +* Michael Dipperstein (mdipper@alumni.engr.ucsb.edu)
2.49 +*
2.50 +* This file is part of the bit array library.
2.51 +*
2.52 +* The bit array library is free software; you can redistribute it and/or
2.53 +* modify it under the terms of the GNU Lesser General Public License as
2.54 +* published by the Free Software Foundation; either version 3 of the
2.55 +* License, or (at your option) any later version.
2.56 +*
2.57 +* The bit array library is distributed in the hope that it will be useful,
2.58 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
2.59 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
2.60 +* General Public License for more details.
2.61 +*
2.62 +* You should have received a copy of the GNU Lesser General Public License
2.63 +* along with this program. If not, see <http://www.gnu.org/licenses/>.
2.64 +*
2.65 +***************************************************************************/
2.66 +#ifndef BIT_ARRAY_H
2.67 +#define BIT_ARRAY_H
2.68 +
2.69 +/***************************************************************************
2.70 +* INCLUDED FILES
2.71 +***************************************************************************/
2.72 +#include <ostream>
2.73 +
2.74 +/***************************************************************************
2.75 +* TYPE DEFINITIONS
2.76 +***************************************************************************/
2.77 +class BitArray;
2.78 +
2.79 +/**
2.80 +*/
2.81 +class BitArrayIndex
2.82 +{
2.83 + public:
2.84 + BitArrayIndex(BitArray *array, const unsigned int index);
2.85 +
2.86 + /* assignment */
2.87 + void operator=(const bool src);
2.88 +
2.89 + private:
2.90 + BitArray *m_BitArray; /* array index applies to */
2.91 + unsigned int m_Index; /* index of bit in array */
2.92 +};
2.93 +
2.94 +/**
2.95 +*/
2.96 +class BitArray
2.97 +{
2.98 + public:
2.99 + BitArray(const int numBits);
2.100 + BitArray(unsigned char *array, const int numBits);
2.101 +
2.102 + virtual ~BitArray(void);
2.103 +
2.104 + void Dump(std::ostream &outStream);
2.105 +
2.106 + const unsigned int SizeInBits() { return m_NumBits; };
2.107 + const unsigned int SizeInBytes() { return m_SizeInBytes; };
2.108 +
2.109 + /* set/clear functions */
2.110 + void SetAll(void);
2.111 + void ClearAll(void);
2.112 + void SetBit(const unsigned int bit);
2.113 + void SetBitValue(const unsigned int bit, bool aValue);
2.114 + void ClearBit(const unsigned int bit);
2.115 +
2.116 + BitArrayIndex operator()(const unsigned int bit);
2.117 +
2.118 + /* boolean operator */
2.119 + bool operator[](const unsigned int bit) const;
2.120 + bool operator==(const BitArray &other) const;
2.121 + bool operator!=(const BitArray &other) const;
2.122 + bool operator<(const BitArray &other) const;
2.123 + bool operator<=(const BitArray &other) const;
2.124 + bool operator>(const BitArray &other) const;
2.125 + bool operator>=(const BitArray &other) const;
2.126 +
2.127 + /* bitwise operators */
2.128 + BitArray operator&(const BitArray &other) const;
2.129 + BitArray operator^(const BitArray &other) const;
2.130 + BitArray operator|(const BitArray &other) const;
2.131 + BitArray operator~(void) const;
2.132 +
2.133 + BitArray operator<<(const unsigned int count) const;
2.134 + BitArray operator>>(const unsigned int count) const;
2.135 +
2.136 + /* increment/decrement */
2.137 + BitArray& operator++(void); /* prefix */
2.138 + BitArray& operator++(int dummy); /* postfix */
2.139 + BitArray& operator--(void); /* prefix */
2.140 + BitArray& operator--(int dummy); /* postfix */
2.141 +
2.142 + /* assignments */
2.143 + BitArray& operator=(const BitArray &src);
2.144 +
2.145 + BitArray& operator&=(const BitArray &src);
2.146 + BitArray& operator^=(const BitArray &src);
2.147 + BitArray& operator|=(const BitArray &src);
2.148 + BitArray& Not(void); /* negate (~=) */
2.149 +
2.150 + BitArray& operator<<=(unsigned const int shifts);
2.151 + BitArray& operator>>=(unsigned const int shifts);
2.152 +
2.153 + unsigned char* Ptr(){return m_Array;}
2.154 + const unsigned char* Ptr() const{return m_Array;}
2.155 +
2.156 + protected:
2.157 + unsigned int m_NumBits; /* number of bits in the array */
2.158 + unsigned int m_SizeInBytes;
2.159 + unsigned char *m_Array; /* vector of characters */
2.160 +};
2.161 +
2.162 +#endif /* ndef BIT_ARRAY_H */
3.1 --- a/inc/FutabaVfd.h Thu May 22 22:36:43 2014 +0200
3.2 +++ b/inc/FutabaVfd.h Sat May 24 00:43:18 2014 +0200
3.3 @@ -7,6 +7,7 @@
3.4
3.5 #include "hidapi.h"
3.6 #include "HidDevice.h"
3.7 +#include "BitArray.h"
3.8
3.9 #ifndef MIN
3.10 #define MIN(a,b) (((a)<(b))?(a):(b))
3.11 @@ -29,6 +30,11 @@
3.12 const unsigned short KFutabaVendorId = 0x1008;
3.13 const unsigned short KFutabaProductIdGP1212A01A = 0x100C;
3.14 const unsigned short KFutabaProductIdGP1212A02A = 0x1013; //Or is it 0x1015
3.15 +const int KGP12xWidthInPixels = 256;
3.16 +const int KGP12xHeightInPixels = 64;
3.17 +const int KGP12xPixelsPerByte = 8;
3.18 +const int KGP12xFrameBufferSizeInBytes = KGP12xWidthInPixels*KGP12xHeightInPixels/KGP12xPixelsPerByte; //256*64/8=2048
3.19 +const int KGP12xFrameBufferPixelCount = KGP12xWidthInPixels*KGP12xHeightInPixels;
3.20
3.21 //typedef struct hid_device_info HidDeviceInfo;
3.22
3.23 @@ -88,6 +94,8 @@
3.24 virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn)=0;
3.25 virtual void SetAllPixels(unsigned char aOn)=0;
3.26 virtual int FrameBufferSizeInBytes() const=0;
3.27 + //virtual int BitBlit(unsigned char* aSrc, unsigned char aSrcWidth, unsigned char aSrcHeight, unsigned char aTargetX, unsigned char aTargetY) const=0;
3.28 +
3.29 };
3.30
3.31 /**
3.32 @@ -110,14 +118,16 @@
3.33 {
3.34 public:
3.35 GP1212A01A();
3.36 + ~GP1212A01A();
3.37 //
3.38 int Open();
3.39 //From FutabaGraphicVfd
3.40 - virtual int WidthInPixels() const {return 256;};
3.41 - virtual int HeightInPixels() const {return 64;};
3.42 + virtual int WidthInPixels() const {return KGP12xWidthInPixels;};
3.43 + virtual int HeightInPixels() const {return KGP12xHeightInPixels;};
3.44 virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn);
3.45 virtual void SetAllPixels(unsigned char aPattern);
3.46 - virtual int FrameBufferSizeInBytes() const {return 2048;}; //256*64/8
3.47 + virtual int FrameBufferSizeInBytes() const {return KGP12xFrameBufferSizeInBytes;};
3.48 + virtual void BitBlit(BitArray& aBitmap, unsigned char aSrcWidth, unsigned char aSrcHeight, unsigned char aTargetX, unsigned char aTargetY) const;
3.49 //From FutabaVfd
3.50 virtual void SetBrightness(int aBrightness);
3.51 virtual void Clear();
3.52 @@ -135,6 +145,8 @@
3.53 //
3.54 void ToggleOffScreenMode();
3.55 bool OffScreenMode() const {return iOffScreenMode;};
3.56 + //
3.57 +
3.58
3.59 private:
3.60 enum DW
3.61 @@ -147,6 +159,7 @@
3.62 unsigned char OffScreenY() const;
3.63 void SendClearCommand();
3.64 void OffScreenTranslation(unsigned char& aX, unsigned char& aY);
3.65 + void ResetBuffers();
3.66
3.67 private:
3.68 unsigned char iDisplayPositionX;
3.69 @@ -157,7 +170,11 @@
3.70 ///
3.71 //FutabaVfdReport iReport;
3.72 ///
3.73 - //unsigned char iPixelBuffer[256][128];
3.74 + //unsigned char iFrameBuffer[256*64];
3.75 + BitArray* iFrameBuffer;
3.76 + //unsigned char iFrameBeta[256*64];
3.77 + //unsigned char *iFrontBuffer;
3.78 + //unsigned char *iBackBuffer;
3.79 };
3.80
3.81
4.1 --- a/inc/MainWindow.h Thu May 22 22:36:43 2014 +0200
4.2 +++ b/inc/MainWindow.h Sat May 24 00:43:18 2014 +0200
4.3 @@ -124,7 +124,7 @@
4.4 FXFont* iCurrentFont;
4.5 FXTGAImage* iFontImage;
4.6 ///Used the following to convert our bitmap into display format
4.7 - unsigned char* iPixelBuffer;
4.8 + BitArray* iPixelBuffer;
4.9
4.10 struct hid_device_info *devices;
4.11 hid_device *connected_device;
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/src/BitArray.cpp Sat May 24 00:43:18 2014 +0200
5.3 @@ -0,0 +1,1012 @@
5.4 +/***************************************************************************
5.5 +* Arrays of Arbitrary Bit Length
5.6 +*
5.7 +* File : bitarray.cpp
5.8 +* Purpose : Provides object with methods for creation and manipulation of
5.9 +* arbitrary length arrays of bits.
5.10 +*
5.11 +* Bit arrays are implemented as vectors of unsigned chars. Bit
5.12 +* 0 is the MSB of char 0, and the last bit is the least
5.13 +* significant (non-spare) bit of the last unsigned char.
5.14 +*
5.15 +* Example: array of 20 bits (0 through 19) with 8 bit unsigned
5.16 +* chars requires 3 unsigned chars (0 through 2) to
5.17 +* store all the bits.
5.18 +*
5.19 +* char 0 1 2
5.20 +* +--------+--------+--------+
5.21 +* | | | |
5.22 +* +--------+--------+--------+
5.23 +* bit 01234567 8911111111111XXXX
5.24 +* 012345 6789
5.25 +*
5.26 +* Author : Michael Dipperstein
5.27 +* Date : July 23, 2004
5.28 +*
5.29 +****************************************************************************
5.30 +* HISTORY
5.31 +*
5.32 +* $Id: bitarray.cpp,v 1.7 2010/02/04 03:31:43 michael Exp $
5.33 +* $Log: bitarray.cpp,v $
5.34 +* Revision 1.7 2010/02/04 03:31:43 michael
5.35 +* Replaced vector<unsigned char> with an array of unsigned char.
5.36 +*
5.37 +* Made updates for GCC 4.4.
5.38 +*
5.39 +* Revision 1.5 2007/08/06 05:23:29 michael
5.40 +* Updated for LGPL Version 3.
5.41 +*
5.42 +* All methods that don't modify object have been made
5.43 +* const to increase functionality of const bit_array_c.
5.44 +*
5.45 +* All assignment operators return a reference to the object being assigned a value so that operator chaining will work.
5.46 +*
5.47 +* Added >> and << operators.
5.48 +*
5.49 +* Revision 1.3 2006/04/30 23:34:07 michael
5.50 +* Improved performance by incorporating Benjamin Schindler's
5.51 +* <bschindler@student.ethz.ch> changes to pass arguments as a reference.
5.52 +*
5.53 +* Revision 1.2 2004/08/05 22:16:49 michael
5.54 +* Add overloads for bitwise operators returning values.
5.55 +* Add a more natural looking way to set bit values.
5.56 +*
5.57 +* Revision 1.1.1.1 2004/08/04 13:28:20 michael
5.58 +* bit_array_c
5.59 +*
5.60 +****************************************************************************
5.61 +*
5.62 +* Bitarray: An ANSI C++ class for manipulating arbitrary length bit arrays
5.63 +* Copyright (C) 2004, 2006-2007, 2010 by
5.64 +* Michael Dipperstein (mdipper@alumni.engr.ucsb.edu)
5.65 +*
5.66 +* This file is part of the bit array library.
5.67 +*
5.68 +* The bit array library is free software; you can redistribute it and/or
5.69 +* modify it under the terms of the GNU Lesser General Public License as
5.70 +* published by the Free Software Foundation; either version 3 of the
5.71 +* License, or (at your option) any later version.
5.72 +*
5.73 +* The bit array library is distributed in the hope that it will be useful,
5.74 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
5.75 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
5.76 +* General Public License for more details.
5.77 +*
5.78 +* You should have received a copy of the GNU Lesser General Public License
5.79 +* along with this program. If not, see <http://www.gnu.org/licenses/>.
5.80 +*
5.81 +***************************************************************************/
5.82 +
5.83 +/***************************************************************************
5.84 +* INCLUDED FILES
5.85 +***************************************************************************/
5.86 +#include <iostream>
5.87 +#include <climits>
5.88 +#include "bitarray.h"
5.89 +
5.90 +using namespace std;
5.91 +
5.92 +/***************************************************************************
5.93 +* MACROS
5.94 +***************************************************************************/
5.95 +
5.96 +/* make CHAR_BIT 8 if it's not defined in limits.h */
5.97 +#ifndef CHAR_BIT
5.98 +#warning CHAR_BIT not defined. Assuming 8 bits.
5.99 +#define CHAR_BIT 8
5.100 +#endif
5.101 +
5.102 +/* position of bit within character */
5.103 +#define BIT_CHAR(bit) ((bit) / CHAR_BIT)
5.104 +
5.105 +/* array index for character containing bit */
5.106 +//SL: that for big endian?
5.107 +//#define BIT_IN_CHAR(bit) (1 << (CHAR_BIT - 1 - ((bit) % CHAR_BIT)))
5.108 +//SL: I guess we want little endian for our Futaba GP1212A01A
5.109 +#define BIT_IN_CHAR(bit) (1 << (((bit) % CHAR_BIT)))
5.110 +
5.111 +/* number of characters required to contain number of bits */
5.112 +#define BITS_TO_CHARS(bits) ((((bits) - 1) / CHAR_BIT) + 1)
5.113 +
5.114 +/* most significant bit in a character */
5.115 +#define MS_BIT (1 << (CHAR_BIT - 1))
5.116 +
5.117 +/***************************************************************************
5.118 +* METHODS
5.119 +***************************************************************************/
5.120 +
5.121 +/***************************************************************************
5.122 +* Method : bit_array_c - constructor
5.123 +* Description: This is the bit_array_c constructor. It reserves memory
5.124 +* for the vector storing the array.
5.125 +* Parameters : numBits - number of bits in the array
5.126 +* Effects : Allocates vectory for array bits
5.127 +* Returned : None
5.128 +***************************************************************************/
5.129 +BitArray::BitArray(const int numBits):
5.130 + m_NumBits(numBits)
5.131 +{
5.132 + m_SizeInBytes = BITS_TO_CHARS(numBits);
5.133 +
5.134 +
5.135 + /* allocate space for bit array */
5.136 + m_Array = new unsigned char[m_SizeInBytes];
5.137 +
5.138 + /* set all bits to 0 */
5.139 + fill_n(m_Array, m_SizeInBytes, 0);
5.140 +}
5.141 +
5.142 +/***************************************************************************
5.143 +* Method : bit_array_c - constructor
5.144 +* Description: This is the bit_array_c constructor. It copies the
5.145 +* for contents of a vector of unsigned char into the
5.146 +* bitarray.
5.147 +* Parameters : vect - vector to be copied
5.148 +* numBits - number of bits in the array
5.149 +* Effects : Allocates vectory for array bits
5.150 +* Returned : None
5.151 +***************************************************************************/
5.152 +BitArray::BitArray(unsigned char *array, const int numBits):
5.153 + m_NumBits(numBits),
5.154 + m_Array(array)
5.155 +{
5.156 +}
5.157 +
5.158 +/***************************************************************************
5.159 +* Method : ~bit_array_c - destructor
5.160 +* Description: This is the bit_array_c destructor. At this point it's
5.161 +* just a place holder.
5.162 +* Parameters : None
5.163 +* Effects : None
5.164 +* Returned : None
5.165 +***************************************************************************/
5.166 +BitArray::~BitArray(void)
5.167 +{
5.168 + delete[] m_Array;
5.169 +}
5.170 +
5.171 +/***************************************************************************
5.172 +* Method : Dump
5.173 +* Description: This method dumps the conents of a bit array to stdout.
5.174 +* The format of the dump is a series of bytes represented in
5.175 +* hexadecimal.
5.176 +* Parameters : outStream - stream to write to
5.177 +* Effects : Array contents are dumped to stdout
5.178 +* Returned : None
5.179 +***************************************************************************/
5.180 +void BitArray::Dump(std::ostream &outStream)
5.181 +{
5.182 + int size;
5.183 +
5.184 + size = BITS_TO_CHARS(m_NumBits);
5.185 +
5.186 + outStream.width(2);
5.187 + outStream.fill('0');
5.188 + outStream << uppercase << hex << (int)(m_Array[0]); /* first byte */
5.189 +
5.190 + for (int i = 1; i < size; i++)
5.191 + {
5.192 + /* remaining bytes with a leading space */
5.193 + outStream << " ";
5.194 + outStream.width(2);
5.195 + outStream.fill('0');
5.196 + outStream << (int)(m_Array[i]);
5.197 + }
5.198 +
5.199 + outStream << dec;
5.200 +}
5.201 +
5.202 +/***************************************************************************
5.203 +* Method : SetAll
5.204 +* Description: This method sets every bit in the bit array to 1. This
5.205 +* method uses UCHAR_MAX to determine what it means to set
5.206 +* all bits in an unsigned char, so it is crucial that the
5.207 +* machine implementation of unsigned char utilizes all of
5.208 +* the bits in the memory allocated for an unsigned char.
5.209 +* Parameters : None
5.210 +* Effects : Each of the bits used in the bit array are set to 1.
5.211 +* Unused (spare) bits are set to 0.
5.212 +* Returned : None
5.213 +***************************************************************************/
5.214 +void BitArray::SetAll(void)
5.215 +{
5.216 + int bits, size;
5.217 + unsigned char mask;
5.218 +
5.219 + size = BITS_TO_CHARS(m_NumBits);
5.220 +
5.221 + /* set bits in all bytes to 1 */
5.222 + fill_n(m_Array, size, UCHAR_MAX);
5.223 +
5.224 + /* zero any spare bits so increment and decrement are consistent */
5.225 + bits = m_NumBits % CHAR_BIT;
5.226 + if (bits != 0)
5.227 + {
5.228 + mask = UCHAR_MAX << (CHAR_BIT - bits);
5.229 + m_Array[BIT_CHAR(m_NumBits - 1)] = mask;
5.230 + }
5.231 +}
5.232 +
5.233 +/***************************************************************************
5.234 +* Method : ClearAll
5.235 +* Description: This method sets every bit in the bit array to 0.
5.236 +* Parameters : None
5.237 +* Effects : Each of the bits in the bit array are set to 0.
5.238 +* Returned : None
5.239 +***************************************************************************/
5.240 +void BitArray::ClearAll(void)
5.241 +{
5.242 + int size;
5.243 +
5.244 + size = BITS_TO_CHARS(m_NumBits);
5.245 +
5.246 + /* set bits in all bytes to 0 */
5.247 + fill_n(m_Array, size, 0);
5.248 +}
5.249 +
5.250 +/***************************************************************************
5.251 +* Method : SetBit
5.252 +* Description: This method sets a bit in the bit array to 1.
5.253 +* Parameters : bit - the number of the bit to set
5.254 +* Effects : The specified bit will be set to 1.
5.255 +* Returned : None
5.256 +***************************************************************************/
5.257 +void BitArray::SetBit(const unsigned int bit)
5.258 +{
5.259 + if (m_NumBits <= bit)
5.260 + {
5.261 + return; /* bit out of range */
5.262 + }
5.263 +
5.264 + m_Array[BIT_CHAR(bit)] |= BIT_IN_CHAR(bit);
5.265 +}
5.266 +
5.267 +/**
5.268 +*/
5.269 +void BitArray::SetBitValue(const unsigned int bit, bool aValue)
5.270 + {
5.271 + if (aValue)
5.272 + {
5.273 + SetBit(bit);
5.274 + }
5.275 + else
5.276 + {
5.277 + ClearBit(bit);
5.278 + }
5.279 + }
5.280 +
5.281 +/***************************************************************************
5.282 +* Method : ClearBit
5.283 +* Description: This method sets a bit in the bit array to 0.
5.284 +* Parameters : bit - the number of the bit to clear
5.285 +* Effects : The specified bit will be set to 0.
5.286 +* Returned : None
5.287 +***************************************************************************/
5.288 +void BitArray::ClearBit(const unsigned int bit)
5.289 +{
5.290 + unsigned char mask;
5.291 +
5.292 + if (m_NumBits <= bit)
5.293 + {
5.294 + return; /* bit out of range */
5.295 + }
5.296 +
5.297 + /* create a mask to zero out desired bit */
5.298 + mask = BIT_IN_CHAR(bit);
5.299 + mask = ~mask;
5.300 +
5.301 + m_Array[BIT_CHAR(bit)] &= mask;
5.302 +}
5.303 +
5.304 +/***************************************************************************
5.305 +* Method : operator()
5.306 +* Description: Overload of the () operator. This method approximates
5.307 +* array indices used for assignment. It returns a
5.308 +* bit_array_index_c which includes an = method used to
5.309 +* set bit values.
5.310 +* Parameters : bit - index of array bit
5.311 +* Effects : None
5.312 +* Returned : bit_array_index_c (pointer to bit)
5.313 +***************************************************************************/
5.314 +BitArrayIndex BitArray::operator()(const unsigned int bit)
5.315 +{
5.316 + BitArrayIndex result(this, bit);
5.317 +
5.318 + return result;
5.319 +}
5.320 +
5.321 +/***************************************************************************
5.322 +* Method : operator[]
5.323 +* Description: Overload of the [] operator. This method returns the
5.324 +* value of a bit in the bit array.
5.325 +* Parameters : bit - index of array bit
5.326 +* Effects : None
5.327 +* Returned : The value of the specified bit.
5.328 +***************************************************************************/
5.329 +bool BitArray::operator[](const unsigned int bit) const
5.330 +{
5.331 + return((m_Array[BIT_CHAR(bit)] & BIT_IN_CHAR(bit)) != 0);
5.332 +}
5.333 +
5.334 +/***************************************************************************
5.335 +* Method : operator==
5.336 +* Description: overload of the == operator
5.337 +* Parameters : other - bit array to compare
5.338 +* Effects : None
5.339 +* Returned : True if this == other. Otherwise false.
5.340 +***************************************************************************/
5.341 +bool BitArray::operator==(const BitArray &other) const
5.342 +{
5.343 + if (m_NumBits != other.m_NumBits)
5.344 + {
5.345 + /* unequal sizes */
5.346 + return false;
5.347 + }
5.348 +
5.349 + return (this->m_Array == other.m_Array);
5.350 +}
5.351 +
5.352 +/***************************************************************************
5.353 +* Method : operator!=
5.354 +* Description: overload of the != operator
5.355 +* Parameters : other - bit array to compare
5.356 +* Effects : None
5.357 +* Returned : True if this != other. Otherwise false.
5.358 +***************************************************************************/
5.359 +bool BitArray::operator!=(const BitArray &other) const
5.360 +{
5.361 + if (m_NumBits != other.m_NumBits)
5.362 + {
5.363 + /* unequal sizes */
5.364 + return true;
5.365 + }
5.366 +
5.367 + return (this->m_Array != other.m_Array);
5.368 +}
5.369 +
5.370 +/***************************************************************************
5.371 +* Method : operator<
5.372 +* Description: overload of the < operator
5.373 +* Parameters : other - bit array to compare
5.374 +* Effects : None
5.375 +* Returned : True if this < other. Otherwise false.
5.376 +***************************************************************************/
5.377 +bool BitArray::operator<(const BitArray &other) const
5.378 +{
5.379 + if (m_NumBits != other.m_NumBits)
5.380 + {
5.381 + /* unequal sizes */
5.382 + return false;
5.383 + }
5.384 +
5.385 + return (this->m_Array < other.m_Array);
5.386 +}
5.387 +
5.388 +/***************************************************************************
5.389 +* Method : operator<=
5.390 +* Description: overload of the <= operator
5.391 +* Parameters : other - bit array to compare
5.392 +* Effects : None
5.393 +* Returned : True if this <= other. Otherwise false.
5.394 +***************************************************************************/
5.395 +bool BitArray::operator<=(const BitArray &other) const
5.396 +{
5.397 + if (m_NumBits != other.m_NumBits)
5.398 + {
5.399 + /* unequal sizes */
5.400 + return false;
5.401 + }
5.402 +
5.403 + return (this->m_Array <= other.m_Array);
5.404 +}
5.405 +
5.406 +/***************************************************************************
5.407 +* Method : operator>
5.408 +* Description: overload of the > operator
5.409 +* Parameters : other - bit array to compare
5.410 +* Effects : None
5.411 +* Returned : True if this > other. Otherwise false.
5.412 +***************************************************************************/
5.413 +bool BitArray::operator>(const BitArray &other) const
5.414 +{
5.415 + if (m_NumBits != other.m_NumBits)
5.416 + {
5.417 + /* unequal sizes */
5.418 + return false;
5.419 + }
5.420 +
5.421 + return (this->m_Array > other.m_Array);
5.422 +}
5.423 +
5.424 +/***************************************************************************
5.425 +* Method : operator>=
5.426 +* Description: overload of the >= operator
5.427 +* Parameters : other - bit array to compare
5.428 +* Effects : None
5.429 +* Returned : True if this >= other. Otherwise false.
5.430 +***************************************************************************/
5.431 +bool BitArray::operator>=(const BitArray &other) const
5.432 +{
5.433 + if (m_NumBits != other.m_NumBits)
5.434 + {
5.435 + /* unequal sizes */
5.436 + return false;
5.437 + }
5.438 +
5.439 + return (this->m_Array >= other.m_Array);
5.440 +}
5.441 +
5.442 +/***************************************************************************
5.443 +* Method : operator~
5.444 +* Description: overload of the ~ operator. Negates all non-spare bits in
5.445 +* bit array
5.446 +* Parameters : None
5.447 +* Effects : None
5.448 +* Returned : value of this after bitwise not
5.449 +***************************************************************************/
5.450 +BitArray BitArray::operator~(void) const
5.451 +{
5.452 + BitArray result(this->m_NumBits);
5.453 + result = *this;
5.454 + result.Not();
5.455 +
5.456 + return result;
5.457 +}
5.458 +
5.459 +/***************************************************************************
5.460 +* Method : operator&
5.461 +* Description: overload of the & operator. Performs a bitwise and
5.462 +* between the source array and this bit array.
5.463 +* Parameters : other - bit array on righthand side of &
5.464 +* Effects : None
5.465 +* Returned : value of bitwise and of this and other.
5.466 +***************************************************************************/
5.467 +BitArray BitArray::operator&(const BitArray &other) const
5.468 +{
5.469 + BitArray result(this->m_NumBits);
5.470 + result = *this;
5.471 + result &= other;
5.472 +
5.473 + return result;
5.474 +}
5.475 +
5.476 +
5.477 +/***************************************************************************
5.478 +* Method : operator^
5.479 +* Description: overload of the ^ operator. Performs a bitwise xor
5.480 +* between the source array and this bit array.
5.481 +* Parameters : other - bit array on righthand side of ^
5.482 +* Effects : None
5.483 +* Returned : value of bitwise xor of this and other.
5.484 +***************************************************************************/
5.485 +BitArray BitArray::operator^(const BitArray &other) const
5.486 +{
5.487 + BitArray result(this->m_NumBits);
5.488 + result = *this;
5.489 + result ^= other;
5.490 +
5.491 + return result;
5.492 +}
5.493 +
5.494 +/***************************************************************************
5.495 +* Method : operator|
5.496 +* Description: overload of the | operator. Performs a bitwise or
5.497 +* between the source array and this bit array.
5.498 +* Parameters : other - bit array on righthand side of |
5.499 +* Effects : None
5.500 +* Returned : value of bitwise or of this and other.
5.501 +***************************************************************************/
5.502 +BitArray BitArray::operator|(const BitArray &other) const
5.503 +{
5.504 + BitArray result(this->m_NumBits);
5.505 + result = *this;
5.506 + result |= other;
5.507 +
5.508 + return result;
5.509 +}
5.510 +
5.511 +/***************************************************************************
5.512 +* Method : operator<<
5.513 +* Description: overload of the << operator. Performs a bitwise left
5.514 +* shift of this bit array.
5.515 +* Parameters : count - the number of bits to shift left
5.516 +* Effects : None
5.517 +* Returned : result of bitwise left shift
5.518 +***************************************************************************/
5.519 +BitArray BitArray::operator<<(const unsigned int count) const
5.520 +{
5.521 + BitArray result(this->m_NumBits);
5.522 + result = *this;
5.523 + result <<= count;
5.524 +
5.525 + return result;
5.526 +}
5.527 +
5.528 +/***************************************************************************
5.529 +* Method : operator>>
5.530 +* Description: overload of the >> operator. Performs a bitwise right
5.531 +* shift of this bit array.
5.532 +* Parameters : count - the number of bits to shift right
5.533 +* Effects : None
5.534 +* Returned : result of bitwise right shift
5.535 +***************************************************************************/
5.536 +BitArray BitArray::operator>>(const unsigned int count) const
5.537 +{
5.538 + BitArray result(this->m_NumBits);
5.539 + result = *this;
5.540 + result >>= count;
5.541 +
5.542 + return result;
5.543 +}
5.544 +
5.545 +/***************************************************************************
5.546 +* Method : operator++ (prefix)
5.547 +* Description: overload of the ++ operator. Increments the contents of
5.548 +* a bit array. Overflows cause rollover.
5.549 +* Parameters : None
5.550 +* Effects : Bit array contents are incremented
5.551 +* Returned : Reference to this array after increment
5.552 +***************************************************************************/
5.553 +BitArray& BitArray::operator++(void)
5.554 +{
5.555 + int i;
5.556 + unsigned char maxValue; /* maximum value for current char */
5.557 + unsigned char one; /* least significant bit in current char */
5.558 +
5.559 + if (m_NumBits == 0)
5.560 + {
5.561 + return *this; /* nothing to increment */
5.562 + }
5.563 +
5.564 + /* handle arrays that don't use every bit in the last character */
5.565 + i = (m_NumBits % CHAR_BIT);
5.566 + if (i != 0)
5.567 + {
5.568 + maxValue = UCHAR_MAX << (CHAR_BIT - i);
5.569 + one = 1 << (CHAR_BIT - i);
5.570 + }
5.571 + else
5.572 + {
5.573 + maxValue = UCHAR_MAX;
5.574 + one = 1;
5.575 + }
5.576 +
5.577 + for (i = BIT_CHAR(m_NumBits - 1); i >= 0; i--)
5.578 + {
5.579 + if (m_Array[i] != maxValue)
5.580 + {
5.581 + m_Array[i] = m_Array[i] + one;
5.582 + return *this;
5.583 + }
5.584 + else
5.585 + {
5.586 + /* need to carry to next byte */
5.587 + m_Array[i] = 0;
5.588 +
5.589 + /* remaining characters must use all bits */
5.590 + maxValue = UCHAR_MAX;
5.591 + one = 1;
5.592 + }
5.593 + }
5.594 +
5.595 + return *this;
5.596 +}
5.597 +
5.598 +/***************************************************************************
5.599 +* Method : operator++ (postfix)
5.600 +* Description: overload of the ++ operator. Increments the contents of
5.601 +* a bit array. Overflows cause rollover.
5.602 +* Parameters : dumy - needed for postfix increment
5.603 +* Effects : Bit array contents are incremented
5.604 +* Returned : Reference to this array after increment
5.605 +***************************************************************************/
5.606 +BitArray& BitArray::operator++(int dummy)
5.607 +{
5.608 + ++(*this);
5.609 + return *this;
5.610 +}
5.611 +
5.612 +/***************************************************************************
5.613 +* Method : operator-- (prefix)
5.614 +* Description: overload of the -- operator. Decrements the contents of
5.615 +* a bit array. Underflows cause rollover.
5.616 +* Parameters : None
5.617 +* Effects : Bit array contents are decremented
5.618 +* Returned : None
5.619 +***************************************************************************/
5.620 +BitArray& BitArray::operator--(void)
5.621 +{
5.622 + int i;
5.623 + unsigned char maxValue; /* maximum value for current char */
5.624 + unsigned char one; /* least significant bit in current char */
5.625 +
5.626 + if (m_NumBits == 0)
5.627 + {
5.628 + return *this; /* nothing to decrement */
5.629 + }
5.630 +
5.631 + /* handle arrays that don't use every bit in the last character */
5.632 + i = (m_NumBits % CHAR_BIT);
5.633 + if (i != 0)
5.634 + {
5.635 + maxValue = UCHAR_MAX << (CHAR_BIT - i);
5.636 + one = 1 << (CHAR_BIT - i);
5.637 + }
5.638 + else
5.639 + {
5.640 + maxValue = UCHAR_MAX;
5.641 + one = 1;
5.642 + }
5.643 +
5.644 + for (i = BIT_CHAR(m_NumBits - 1); i >= 0; i--)
5.645 + {
5.646 + if (m_Array[i] >= one)
5.647 + {
5.648 + m_Array[i] = m_Array[i] - one;
5.649 + return *this;
5.650 + }
5.651 + else
5.652 + {
5.653 + /* need to borrow from the next byte */
5.654 + m_Array[i] = maxValue;
5.655 +
5.656 + /* remaining characters must use all bits */
5.657 + maxValue = UCHAR_MAX;
5.658 + one = 1;
5.659 + }
5.660 + }
5.661 +
5.662 + return *this;
5.663 +}
5.664 +
5.665 +/***************************************************************************
5.666 +* Method : operator-- (postfix)
5.667 +* Description: overload of the -- operator. Decrements the contents of
5.668 +* a bit array. Underflows cause rollover.
5.669 +* Parameters : dumy - needed for postfix decrement
5.670 +* Effects : Bit array contents are decremented
5.671 +* Returned : None
5.672 +***************************************************************************/
5.673 +BitArray& BitArray::operator--(int dummy)
5.674 +{
5.675 + --(*this);
5.676 + return *this;
5.677 +}
5.678 +
5.679 +/***************************************************************************
5.680 +* Method : operator=
5.681 +* Description: overload of the = operator. Copies source contents into
5.682 +* this bit array.
5.683 +* Parameters : src - Source bit array
5.684 +* Effects : Source bit array contents are copied into this array
5.685 +* Returned : Reference to this array after copy
5.686 +***************************************************************************/
5.687 +BitArray& BitArray::operator=(const BitArray &src)
5.688 +{
5.689 + if (*this == src)
5.690 + {
5.691 + /* don't do anything for a self assignment */
5.692 + return *this;
5.693 + }
5.694 +
5.695 + if (m_NumBits != src.m_NumBits)
5.696 + {
5.697 + /* don't do assignment with different array sizes */
5.698 + return *this;
5.699 + }
5.700 +
5.701 + if ((m_NumBits == 0) || (src.m_NumBits == 0))
5.702 + {
5.703 + /* don't do assignment with unallocated array */
5.704 + return *this;
5.705 + }
5.706 +
5.707 + /* copy bits from source */
5.708 + int size;
5.709 + size = BITS_TO_CHARS(m_NumBits);
5.710 +
5.711 + copy(src.m_Array, &src.m_Array[size], this->m_Array);
5.712 + return *this;
5.713 +}
5.714 +
5.715 +/***************************************************************************
5.716 +* Method : operator&=
5.717 +* Description: overload of the &= operator. Performs a bitwise and
5.718 +* between the source array and this bit array. This bit
5.719 +* array will contain the result.
5.720 +* Parameters : src - Source bit array
5.721 +* Effects : Results of bitwise and are stored in this array
5.722 +* Returned : Reference to this array after and
5.723 +***************************************************************************/
5.724 +BitArray& BitArray::operator&=(const BitArray &src)
5.725 +{
5.726 + int size;
5.727 +
5.728 + size = BITS_TO_CHARS(m_NumBits);
5.729 +
5.730 + if (m_NumBits != src.m_NumBits)
5.731 + {
5.732 + /* don't do assignment with different array sizes */
5.733 + return *this;
5.734 + }
5.735 +
5.736 + /* AND array one unsigned char at a time */
5.737 + for(int i = 0; i < size; i++)
5.738 + {
5.739 + m_Array[i] = m_Array[i] & src.m_Array[i];
5.740 + }
5.741 +
5.742 + return *this;
5.743 +}
5.744 +
5.745 +/***************************************************************************
5.746 +* Method : operator^=
5.747 +* Description: overload of the ^= operator. Performs a bitwise xor
5.748 +* between the source array and this bit array. This bit
5.749 +* array will contain the result.
5.750 +* Parameters : src - Source bit array
5.751 +* Effects : Results of bitwise xor are stored in this array
5.752 +* Returned : Reference to this array after xor
5.753 +***************************************************************************/
5.754 +BitArray& BitArray::operator^=(const BitArray &src)
5.755 +{
5.756 + int size;
5.757 +
5.758 + size = BITS_TO_CHARS(m_NumBits);
5.759 +
5.760 + if (m_NumBits != src.m_NumBits)
5.761 + {
5.762 + /* don't do assignment with different array sizes */
5.763 + return *this;
5.764 + }
5.765 +
5.766 + /* XOR array one unsigned char at a time */
5.767 + for(int i = 0; i < size; i++)
5.768 + {
5.769 + m_Array[i] = m_Array[i] ^ src.m_Array[i];
5.770 + }
5.771 +
5.772 + return *this;
5.773 +}
5.774 +
5.775 +/***************************************************************************
5.776 +* Method : operator|=
5.777 +* Description: overload of the |= operator. Performs a bitwise or
5.778 +* between the source array and this bit array. This bit
5.779 +* array will contain the result.
5.780 +* Parameters : src - Source bit array
5.781 +* Effects : Results of bitwise or are stored in this array
5.782 +* Returned : Reference to this array after or
5.783 +***************************************************************************/
5.784 +BitArray& BitArray::operator|=(const BitArray &src)
5.785 +{
5.786 + int size;
5.787 +
5.788 + size = BITS_TO_CHARS(m_NumBits);
5.789 +
5.790 + if (m_NumBits != src.m_NumBits)
5.791 + {
5.792 + /* don't do assignment with different array sizes */
5.793 + return *this;
5.794 + }
5.795 +
5.796 + /* OR array one unsigned char at a time */
5.797 + for(int i = 0; i < size; i++)
5.798 + {
5.799 + m_Array[i] = m_Array[i] | src.m_Array[i];
5.800 + }
5.801 +
5.802 + return *this;
5.803 +}
5.804 +
5.805 +/***************************************************************************
5.806 +* Method : Not
5.807 +* Description: Negates all non-spare bits in bit array.
5.808 +* Parameters : None
5.809 +* Effects : Contents of bit array are negated. Any spare bits are
5.810 +* left at 0.
5.811 +* Returned : Reference to this array after not
5.812 +***************************************************************************/
5.813 +BitArray& BitArray::Not(void)
5.814 +{
5.815 + int bits;
5.816 + unsigned char mask;
5.817 + int size;
5.818 +
5.819 + size = BITS_TO_CHARS(m_NumBits);
5.820 +
5.821 + if (m_NumBits == 0)
5.822 + {
5.823 + /* don't do not with unallocated array */
5.824 + return *this;
5.825 + }
5.826 +
5.827 + /* NOT array one unsigned char at a time */
5.828 + for(int i = 0; i < size; i++)
5.829 + {
5.830 + m_Array[i] = ~m_Array[i];
5.831 + }
5.832 +
5.833 + /* zero any spare bits so increment and decrement are consistent */
5.834 + bits = m_NumBits % CHAR_BIT;
5.835 + if (bits != 0)
5.836 + {
5.837 + mask = UCHAR_MAX << (CHAR_BIT - bits);
5.838 + m_Array[BIT_CHAR(m_NumBits - 1)] &= mask;
5.839 + }
5.840 +
5.841 + return *this;
5.842 +}
5.843 +
5.844 +/***************************************************************************
5.845 +* Method : operator<<=
5.846 +* Description: overload of the <<= operator. Performs a left shift on
5.847 +* this bit array. This bit array will contain the result.
5.848 +* Parameters : shifts - number of bit positions to shift
5.849 +* Effects : Results of the shifts are stored in this array
5.850 +* Returned : Reference to this array after shift
5.851 +***************************************************************************/
5.852 +BitArray& BitArray::operator<<=(const unsigned int shifts)
5.853 +{
5.854 + int i;
5.855 + int chars = shifts / CHAR_BIT; /* number of whole byte shifts */
5.856 +
5.857 + if (shifts >= m_NumBits)
5.858 + {
5.859 + /* all bits have been shifted off */
5.860 + this->ClearAll();
5.861 + return *this;
5.862 + }
5.863 +
5.864 + /* first handle big jumps of bytes */
5.865 + if (chars > 0)
5.866 + {
5.867 + int size;
5.868 +
5.869 + size = BITS_TO_CHARS(m_NumBits);
5.870 +
5.871 + for (i = 0; (i + chars) < size; i++)
5.872 + {
5.873 + m_Array[i] = m_Array[i + chars];
5.874 + }
5.875 +
5.876 + /* now zero out new bytes on the right */
5.877 + for (i = size; chars > 0; chars--)
5.878 + {
5.879 + m_Array[i - chars] = 0;
5.880 + }
5.881 + }
5.882 +
5.883 + /* now we have at most CHAR_BIT - 1 bit shifts across the whole array */
5.884 + for (i = 0; i < (int)(shifts % CHAR_BIT); i++)
5.885 + {
5.886 + for (unsigned int j = 0; j < BIT_CHAR(m_NumBits - 1); j++)
5.887 + {
5.888 + m_Array[j] <<= 1;
5.889 +
5.890 + /* handle shifts across byte bounds */
5.891 + if (m_Array[j + 1] & MS_BIT)
5.892 + {
5.893 + m_Array[j] |= 0x01;
5.894 + }
5.895 + }
5.896 +
5.897 + m_Array[BIT_CHAR(m_NumBits - 1)] <<= 1;
5.898 + }
5.899 +
5.900 + return *this;
5.901 +}
5.902 +
5.903 +/***************************************************************************
5.904 +* Method : operator>>=
5.905 +* Description: overload of the >>= operator. Performs a right shift on
5.906 +* this bit array. This bit array will contain the result.
5.907 +* Parameters : shifts - number of bit positions to shift
5.908 +* Effects : Results of the shifts are stored in this array
5.909 +* Returned : Reference to this array after shift
5.910 +***************************************************************************/
5.911 +BitArray& BitArray::operator>>=(const unsigned int shifts)
5.912 +{
5.913 + int i;
5.914 + char mask;
5.915 + int chars = shifts / CHAR_BIT; /* number of whole byte shifts */
5.916 +
5.917 + if (shifts >= m_NumBits)
5.918 + {
5.919 + /* all bits have been shifted off */
5.920 + this->ClearAll();
5.921 + return *this;
5.922 + }
5.923 +
5.924 + /* first handle big jumps of bytes */
5.925 + if (chars > 0)
5.926 + {
5.927 + for (i = BIT_CHAR(m_NumBits - 1); (i - chars) >= 0; i--)
5.928 + {
5.929 + m_Array[i] = m_Array[i - chars];
5.930 + }
5.931 +
5.932 + /* now zero out new bytes on the right */
5.933 + for (; chars > 0; chars--)
5.934 + {
5.935 + m_Array[chars - 1] = 0;
5.936 + }
5.937 + }
5.938 +
5.939 + /* now we have at most CHAR_BIT - 1 bit shifts across the whole array */
5.940 + for (i = 0; i < (int)(shifts % CHAR_BIT); i++)
5.941 + {
5.942 + for (unsigned int j = BIT_CHAR(m_NumBits - 1); j > 0; j--)
5.943 + {
5.944 + m_Array[j] >>= 1;
5.945 +
5.946 + /* handle shifts across byte bounds */
5.947 + if (m_Array[j - 1] & 0x01)
5.948 + {
5.949 + m_Array[j] |= MS_BIT;
5.950 + }
5.951 + }
5.952 +
5.953 + m_Array[0] >>= 1;
5.954 + }
5.955 +
5.956 + /***********************************************************************
5.957 + * zero any spare bits that are shifted beyond the end of the bit array
5.958 + * so that increment and decrement are consistent.
5.959 + ***********************************************************************/
5.960 + i = m_NumBits % CHAR_BIT;
5.961 + if (i != 0)
5.962 + {
5.963 + mask = UCHAR_MAX << (CHAR_BIT - i);
5.964 + m_Array[BIT_CHAR(m_NumBits - 1)] &= mask;
5.965 + }
5.966 +
5.967 + return *this;
5.968 +}
5.969 +
5.970 +/***************************************************************************
5.971 +* Method : bit_array_index_c - constructor
5.972 +* Description: This is the bit_array_index_c constructor. It stores a
5.973 +* pointer to the bit array and the bit index.
5.974 +* Parameters : array - pointer to bit array
5.975 +* index - index of bit in array
5.976 +* Effects : Pointer to bit array and bit index are stored.
5.977 +* Returned : None
5.978 +***************************************************************************/
5.979 +BitArrayIndex::BitArrayIndex(BitArray *array,
5.980 + const unsigned int index)
5.981 +{
5.982 + m_BitArray = array;
5.983 + m_Index = index;
5.984 +}
5.985 +
5.986 +/***************************************************************************
5.987 +* Method : operator=
5.988 +* Description: overload of the = operator. Sets the bit array bit to
5.989 +* the value of src.
5.990 +* Parameters : src - bit value
5.991 +* Effects : Bit pointed to by this object is set to the value of
5.992 +* source.
5.993 +* Returned : None
5.994 +***************************************************************************/
5.995 +void BitArrayIndex::operator=(const bool src)
5.996 +{
5.997 + if (m_BitArray == NULL)
5.998 + {
5.999 + return; /* no array */
5.1000 + }
5.1001 +
5.1002 + if (m_BitArray->SizeInBits() <= m_Index)
5.1003 + {
5.1004 + return; /* index is out of bounds */
5.1005 + }
5.1006 +
5.1007 + if (src)
5.1008 + {
5.1009 + m_BitArray->SetBit(m_Index);
5.1010 + }
5.1011 + else
5.1012 + {
5.1013 + m_BitArray->ClearBit(m_Index);
5.1014 + }
5.1015 +}
6.1 --- a/src/FutabaVfd.cpp Thu May 22 22:36:43 2014 +0200
6.2 +++ b/src/FutabaVfd.cpp Sat May 24 00:43:18 2014 +0200
6.3 @@ -71,19 +71,40 @@
6.4 // class GP1212A01A
6.5 //
6.6
6.7 -GP1212A01A::GP1212A01A():iDisplayPositionX(0),iDisplayPositionY(0),iOffScreenMode(true)
6.8 +GP1212A01A::GP1212A01A():
6.9 + iDisplayPositionX(0),iDisplayPositionY(0),
6.10 + iOffScreenMode(true),iFrameBuffer(NULL)
6.11 {
6.12 + //ResetBuffers();
6.13 }
6.14
6.15 +/**
6.16 +*/
6.17 +GP1212A01A::~GP1212A01A()
6.18 + {
6.19 + delete iFrameBuffer;
6.20 + iFrameBuffer=NULL;
6.21 + }
6.22 +
6.23 +/**
6.24 +*/
6.25 int GP1212A01A::Open()
6.26 {
6.27 int success = HidDevice::Open(KFutabaVendorId,KFutabaProductIdGP1212A01A,NULL);
6.28 if (success)
6.29 {
6.30 + delete iFrameBuffer;
6.31 + iFrameBuffer = NULL;
6.32 + iFrameBuffer=new BitArray(KGP12xFrameBufferPixelCount);
6.33 SetNonBlocking(1);
6.34 //Since we can't get our display position we for it to our default
6.35 //This makes sure frames are in sync from the start
6.36 SetDisplayPosition(iDisplayPositionX,iDisplayPositionY);
6.37 + //Now clear both front and back buffer on host and device
6.38 + Clear();
6.39 + SwapBuffers();
6.40 + Clear();
6.41 + SwapBuffers();
6.42 }
6.43 return success;
6.44 }
6.45 @@ -93,7 +114,32 @@
6.46 void GP1212A01A::SetPixel(unsigned char aX, unsigned char aY, bool aOn)
6.47 {
6.48 //Just specify a one pixel block
6.49 - SetPixelBlock(aX,aY,0x00,0x01,aOn);
6.50 + //SetPixelBlock(aX,aY,0x00,0x01,aOn);
6.51 + //
6.52 + //int byteOffset=(aX*HeightInPixels()+aY)/8;
6.53 + //int bitOffset=(aX*HeightInPixels()+aY)%8;
6.54 + //iFrameBuffer[byteOffset] |= ( (aOn?0x01:0x00) << bitOffset );
6.55 + if (aOn)
6.56 + {
6.57 + iFrameBuffer->SetBit(aX*HeightInPixels()+aY);
6.58 + }
6.59 + else
6.60 + {
6.61 + iFrameBuffer->ClearBit(aX*HeightInPixels()+aY);
6.62 + }
6.63 + }
6.64 +
6.65 +/**
6.66 +*/
6.67 +void GP1212A01A::BitBlit(BitArray& aBitmap, unsigned char aSrcWidth, unsigned char aSrcHeight, unsigned char aTargetX, unsigned char aTargetY) const
6.68 + {
6.69 + for (int i=0;i<aSrcWidth;i++)
6.70 + {
6.71 + for (int j=0;j<aSrcHeight;j++)
6.72 + {
6.73 + iFrameBuffer->SetBitValue((aTargetX+i)*HeightInPixels()+aTargetY+j,aBitmap[+i*aSrcHeight+j]);
6.74 + }
6.75 + }
6.76 }
6.77
6.78 /**
6.79 @@ -109,7 +155,10 @@
6.80 //SetPixelBlock(0,0,63,sizeof(screen),screen);
6.81
6.82 //Using pattern SetPixelBlock variant.
6.83 - SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),aPattern);
6.84 + memset(iFrameBuffer->Ptr(),aPattern,FrameBufferSizeInBytes());
6.85 + //
6.86 +
6.87 +
6.88 }
6.89
6.90 /**
6.91 @@ -220,14 +269,13 @@
6.92
6.93
6.94 /**
6.95 -Clear our display's screen.
6.96 -This operation is performed off screen to avoid tearing.
6.97 +Clear our client side back buffer.
6.98 +Call to SwapBuffers must follow to actually clear the display.
6.99 */
6.100 void GP1212A01A::Clear()
6.101 {
6.102 - //Using pattern SetPixelBlock variant.
6.103 - //First fill our off screen buffer with the desired values
6.104 - SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),(unsigned char)0x00);
6.105 + //memset(iFrameBuffer->Ptr(),0x00,FrameBufferSizeInBytes());
6.106 + iFrameBuffer->ClearAll();
6.107 }
6.108
6.109 /**
6.110 @@ -297,7 +345,14 @@
6.111 //Only perform buffer swapping if off screen mode is enabled
6.112 if (OffScreenMode())
6.113 {
6.114 + //Send host back buffer to device back buffer
6.115 + SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),iFrameBuffer->Ptr());
6.116 + //Swap device front and back buffer
6.117 SetDisplayPosition(iDisplayPositionX,OffScreenY());
6.118 + //Swap host buffers
6.119 + //unsigned char* backBuffer=iBackBuffer;
6.120 + //iBackBuffer = iFrontBuffer;
6.121 + //iFrontBuffer = backBuffer;
6.122 }
6.123 }
6.124
6.125 @@ -312,6 +367,17 @@
6.126 aY+=HeightInPixels()-iDisplayPositionY;
6.127 }
6.128 }
6.129 +
6.130 +
6.131 +/**
6.132 +*/
6.133 +void GP1212A01A::ResetBuffers()
6.134 + {
6.135 + //iFrameBuffer->ClearAll();
6.136 + //memset(iFrameBuffer,0x00,sizeof(iFrameBuffer));
6.137 + //memset(iFrameBeta,0x00,sizeof(iFrameBeta));
6.138 + }
6.139 +
6.140 /**
6.141 */
6.142 void GP1212A01A::RequestId()
7.1 --- a/src/test.cpp Thu May 22 22:36:43 2014 +0200
7.2 +++ b/src/test.cpp Sat May 24 00:43:18 2014 +0200
7.3 @@ -790,26 +790,23 @@
7.4 //Create display pixel buffer from our image pixels
7.5 int w=iFontImage->getWidth();
7.6 int h=iFontImage->getHeight();
7.7 - int pixelBufferSize=(w*h)/8;
7.8 - iPixelBuffer = new unsigned char[pixelBufferSize];
7.9 - memset(iPixelBuffer,0x00,pixelBufferSize);
7.10 + int pixelCount=(w*h);
7.11 + iPixelBuffer = new BitArray(pixelCount);
7.12 for (int i=0;i<w;i++)
7.13 {
7.14 for (int j=0;j<h;j++)
7.15 - {
7.16 - int byteOffset=(i*h+j)/8;
7.17 - int bitOffset=(i*h+j)%8;
7.18 + {
7.19 FXColor color=iFontImage->getPixel(i,j);
7.20 if (color!=0xffffffff)
7.21 {
7.22 - iPixelBuffer[byteOffset] |= ( 1 << bitOffset );
7.23 + iPixelBuffer->SetBit(i*h+j);
7.24 }
7.25 }
7.26 }
7.27
7.28 if (iVfd01.IsOpen())
7.29 {
7.30 - iVfd01.SetPixelBlock(0,0,h-1,pixelBufferSize,iPixelBuffer);
7.31 + iVfd01.BitBlit(*iPixelBuffer,w,h,0,0);
7.32 iVfd01.SwapBuffers();
7.33 }
7.34