Space saving setting the ink and paper colours
Traditionally to set the Ink / Paper and Border colours as well as enabling (or disabling!) Flash, Bright, Over and.or Inverse we would use something like this:
10 BORDER 0 : PAPER 0 : INK 7 : BRIGHT 0 : OVER 0 : INVERSE 0 : FLASH 0 : CLS
Which gives us non Bright white Ink on black Paper. This takes approximately 69 bytes.
There is a much more efficient and space saving method of doing this, useful if the setting for RamTop (CLEAR) is so low there is insufficient space to include a lot of Basic.
We can simply say:
POKE 23693 , X This is known as ATTR_P
POKE 23624 , X This is known as BORD_CR
23693 controls the main screen colours and 23624 controls the lower screen (what would be lines 22 and 23 in effect) and border. To work out the value here you can resort to using the following table:
Bits 0 1 2 control the Ink
Bits 3 4 5 control the Paper
Bit 6 is the Bright control
Bit 7 is the Flash control
It is slightly hard work to do this by hand even with using BIN but there is a far, far easier method and it is one I nearly always use. Simply initially set the Paper and Ink colours to the choices you require along with the Flash control and other effects. Now clear the screen and do a:
PRINT AT 2,2 ; PEEK 22528
Note that if you have chosen the same Paper/Ink colours you must insert an Ink or Paper colour here so you can see the result, example:
PRINT AT 2,2 ; INK 5 ; PEEK 22528
Also note it is strongly recommended to have the AT so you do not overwrite the area where it is "looking" as 22528 is the top left attribute square. All being well a value will be displayed and this is the one to use in the poke(s)
Repeat this for the border if you wish a different colour combination. The advantage of using 23624 for the border has another bonus too, you can set the Bright element and Ink to values you'd not normally be able to in the Border area, for instance:
POKE 23624 , 78
POKE 23693 , 78
78 is Blue Paper, yellow Ink and Bright enabled, ie: 10 POKE 23624 , 78 : POKE 23693 , 78 : CLS
To take us back to the Basic example above with a black screen and non Bright white Ink we find the value needed with PEEK 22528 and it is 7 so we can now write this:
10 POKE 23693 , 7 : POKE 23624 , 7 : CLS
The file size has now dropped from 69 to 48 bytes, which may not sound a great deal however when space is very tight it can make all the difference. There are further savings to be had via the use of VAL which will be detailed in another article.
Proof is in the pudding (as they say) so see the screenshot at the end of this article. 'Full' is the Basic containing all the control statements where as 'Poke' just contains the Pokes. Both contain the CLS too.
It should be noted these may have odd "live while editing" effects in 128K Basic and it is best where possible to insert and test them in 48K mode, even if you plan to use 128K mode for your program, while Basic is running they should function as expected.
I hope you find this article of some helpful value. Enjoy!
- Metalmickey likes this