Author: Stephen Harrison
Category: Christmas Challenge 2022
System: Acorn BBC Micro (Model A, B, B+, Master)
Language: BASIC (BBC BASIC 2)
Len source code: 77 bytes
Len exe file: 77 bytes
Len code only: 77 bytes
Instructions:
Either mount the pre-made ssd disk image "BBCBASICstar.ssd" directly with your BBC Micro emulator (B-em, BeebEm, etc.) and type CHAIN"BBCstar", or import the file "$.BBCstar" to your BBC emulator.
Description:
The code uses two variables, X and A. A is the main loop counter, going from -25 to +25. The star is encoded in the DATA statement at the end of the file (description below). Within the loop, the data is read directly by reference to the TOP (end of file) pointer, subtracting 3 (get past end of file marker) and then further subtracting the absolute (+ve) value of loop counter A. Using the absolute value of A is important because the star is symmetrical, so this way we only need to encode half the star. So when the loop counter moves from -ve to +ve, the lower half of the star is reproduced by re-reading the data used for the top half (absolute value of A goes from 25 to 0, then back to 25 again).
X is the ASCII code of the character to print out, and alternates on each cycle of the loop, between a star (#42) or a space (#32). The final 26 bytes of code following the "DATA" statement represent the image, in the format number of spaces (as 1 character) then number of stars (as 1 character), eg. the first row of the star is coded as 4,1,7,1,31 (4 spaces, 1 star, 7 spaces, 1 star, then 31 spaces to loop to next line...). But to avoid having unprintable control characters (ASCII<32) in the BASIC code, the data is further encoded by adding the value of X to each data point (recall X is always either 32 or 42). This means the data can be typed and displayed as normal characters (4 1 7 1 31 becomes $ + ' + ?).
Overall this gives the target star in 77 bytes of fully BBC BASIC 2 compliant code, which exits cleanly and can be typed into the computer by the user unaided (without any tricks).
Comments:
1 additional byte can be saved by removing the term "DATA" from the line, so the code ends with the encoded data straight after the "NEXT:" statement eg. ":NEXT:$+'+?...". This runs and plots the star correctly, however it causes the code to exit with a "No such variable" error after the star is plotted (size 76 bytes).