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?
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
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
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....
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?
Re: Adding and reading byte variable from the bit array?
Quote:
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
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......