Hello everyone,
Does anyone know in Basic how to extract the ink, paper, bright and flash values from an ATTR value?
I'm trying to copy a character from one character square to another along with its attributes. The problem is that the attributes of the character I want to copy are not constant.
I remember that Bright adds 64 to the value and Flash adds 128.
Can a formula or formulas be applied a formula or formulas to ATTR?
Something like If ATTR(y,x)=n Then... let ink= :let paper= :let Bright= :Let Flash= etc.
Thank you for your help.
Phil
Extracting ink, paper etc. from ATTR value?
Re: Extracting ink, paper etc. from ATTR value?
Attr.Byte = FLASH x 128 + BRIGHT x 64 + PAPER x 8 + INK
Coder of ZXOOM, Euphoria 2D, ZX Like Pascal, Russian Railway Magnate...
Re: Extracting ink, paper etc. from ATTR value?
Thank you Andrew. That' s great. Phil
Re: Extracting ink, paper etc. from ATTR value?
Using Andrew's formula, I wrote a program to do it. First you enter in values for ATTR and then extract the values out again...
Code: Select all
10 INPUT "ink?";i;"paper?";p;"bright?";b;"flash?";f
15 PRINT AT 0,0; INK i; PAPER p; BRIGHT b; FLASH f;"a"
20 LET a=ATTR (0,0)
25 PRINT a
30 LET af=0: IF a>127 THEN LET af=1: LET a=a-128
35 LET ab=0: IF a>63 THEN LET ab=1: LET a=a-64
40 IF a>7 THEN LET ap=INT (a/8): LET ai=a-(ap*8)
45 IF a<8 THEN LET ap=0: LET ai=a
50 PRINT "ink ";ai
55 PRINT "paper ";ap
60 PRINT "bright ";ab
65 PRINT "flash ";af
70 PAUSE 0: CLS : GO TO 10
Re: Extracting ink, paper etc. from ATTR value?
The ATTR command converts the x,y into a memory address and PEEK's it and returns the data.
you could use a DEF FN to do to the same conversion
This code will yield the same result as LET att=ATTR (0,0)
You can then set INK/PAPER/FLASH/BRIGHT by POKE'ing attributes directly to the memory.
This code will set the attribute at 0,0 to INK 1; PAPER 0; FLASH 1. If you just need to copy the attributes you can just PEEK and POKE without breaking the data into each component.
you could use a DEF FN to do to the same conversion
Code: Select all
10 DEF FN a(y,x)=22528+x+(y*32)
20 LET att=PEEK FN a(0,0)
You can then set INK/PAPER/FLASH/BRIGHT by POKE'ing attributes directly to the memory.
Code: Select all
10 DEF FN a(y,x)=22528+x+(y*32)
20 POKE FN a(0,0),129
Re: Extracting ink, paper etc. from ATTR value?
Thank you very much MonkZy. That's an efficient piece of code. I'll try it out.
Phil
Phil
Re: Extracting ink, paper etc. from ATTR value?
That worked a treat. Copying the attributes from 0,0 to 1,0.
Perfect. Thanks again.
Perfect. Thanks again.
Code: Select all
10 INPUT "ink?";i;"paper?";p;"bright?";b;"flash?";f
15 PRINT INK i; PAPER p; BRIGHT b; FLASH f;"a"
20 DEF FN a(y,x)=22528+x+(y*32)
25 LET att=PEEK FN a(0,0)
30 PRINT "a"
35 POKE FN a(1,0),att
40 PAUSE 0: CLS : GO TO 10