Adding and reading byte variable from the bit array?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Adding and reading byte variable from the bit array?

    Hello.
    I'm upgrading my ST7920 "library", so letters can have variable width, for better visual appearance.
    For this purpose, I plan to have single, screen-wide bit array, in which I will write the corresponding bits from the characters.
    For this I will need the following

    take say bits 2 to 5 from some byte variable and write them into bits 5 to 8 of bit array.
    How should I?
    One way I see is to make a loop, which will read bit by bit and write it bit by bit. But this is time consuming, and I believe, there should be faster ways to do this?
    I know that I can do something like this buf[5]=char.1 which will write bit 1 of char variable into 5th position into buf array. But what about more "wide", several bit operations?

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Adding and reading byte variable from the bit array?

    The best I can think of is shifting & bit masks. If you want to use bits 2 through 5, create a generic temporary variable to put the interim result. Right shift it to put the 1st needed bit at the 0 position, then AND mask it. The Temp variable will now be %0000 xxxx. Reverse the process for the destination variable using an OR mask first, then left shift it to put the key bits in %xxxx 0000.
    Code:
    SourceVar VAR BYTE
    DestVar VAR BYTE
    TempVar VAR BYTE
    
    TempVar = (SourceVar >> 2) AND $0F
    DestVar = (TempVar << 4) OR $F0
    or maybe
    Code:
    DestVar = (SourceVar << 2) AND $F0

  3. #3


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Adding and reading byte variable from the bit array?

    Have you tried something like this?

    Code:
    Myword2.5 = Mybyte1.2          'move bit 2 of Mybyte1 to bit 5 Myword2
    Myword2.6 = Mybyte1.3        
    Myword2.7 = Mybyte1.4        
    Myword2.8 = Mybyte1.5
    Last edited by mark_s; - 18th May 2022 at 20:40.

  4. #4
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Adding and reading byte variable from the bit array?

    The issue is that these boundaries should be changeable, since different chars will have different pixel width.
    There are two ways of doing this - all capitals have same width and all non-capital letters have another, smaller width. This indeed reduces some visual gaps, but not exactly what I want.
    So my idea is to have a spare, "mask" byte for each character, which will define it's width and entry and exit points.
    Say, there's "t", it is 4 pixels wide, and "mask" for it will look like this 00011110. zeros will be trimmed, and bits #5,4,3,2,1 from the letter shape will be added to output image.
    Another, more complex idea, is to do it "ZX Spectrum way", via complex STR/MID/LEN/ASC and other statements, currently not implemented, but still doable, in PBP....

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Adding and reading byte variable from the bit array?

    FOR X=1 to 5
    Y=Z.X
    NEXT

    As I understand, such operation is not possible in PBP, I mean, it is not possible to substitute variable as a bit part identifier for another variable?

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,380


    Did you find this post helpful? Yes | No

    Default Re: Adding and reading byte variable from the bit array?

    As I understand, such operation is not possible in PBP, I mean, it is not possible to substitute variable as a bit part identifier for another variable?
    where did you get that idea, it is very possible with the correct syntax

    suggest a read of the manual re

    Applying Offsets to Bits within a Variable or Register
    Warning I'm not a teacher

  7. #7
    Join Date
    Feb 2013
    Posts
    1,078


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Adding and reading byte variable from the bit array?

    I didn't get the idea, I just tried it and it gives syntax error......

Similar Threads

  1. Checking Bit of a Byte using another variable
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th December 2010, 16:02
  2. adding new word variable ?
    By iugmoh in forum General
    Replies: 4
    Last Post: - 21st February 2008, 01:26
  3. Setting / resetting a variable bit within a byte
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th February 2008, 19:38
  4. Bit/Byte array for Hserin/Hserout
    By mrx23 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd September 2006, 00:07
  5. Word array behaving like byte array.... wierd
    By forgie in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 2nd August 2005, 16:43

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts