scene.org File Archive

File download

<root>­/­parties­/­2021­/­vintagecomputingchristmaschallenge21­/­challenge/oh8mxl_bbcmicro_basic_vc3-2021.zip

File size:
124 304 bytes (121.39K)
File date:
2021-12-25 12:55:53
Download count:
all-time: 11

Preview

  • oh8mxl_bbcmicro.ssd 2.50K
  • oh8mxl_bbcmicro_basic_vc3-2021.diz 2.16K
  • oh8mxl_bbcmicro_code.txt 77B
  • oh8mxl_bbcmicro_image.png 39.32K
  • oh8mxl_bbcmicro_image2.png 42.27K
  • oh8mxl_bbcmicro_image3.png 50.63K

file_id.diz

THE CHALLENGE (optimized for minimum size)

Author: Juhani Tapaninen @oh8mxl

System: BBC MODEL B

Language used (name and possibly version): Basic, OS 1.20

Length of source code: 77 bytes;   from text file using ANSI encoding 

Length of executable file: 41 bytes;   with command *INFO "OH8MXL"

Instructions on how to run the code:
- install BeebEm
- Load disc 0: oh8mxl_bbcmicro.ssd
- LOAD "OH8MXL"
- RUN

Description of how the code works: 

The code for reference,

1FORT=4TO17:S=T DIV4:W=T MOD4*S+S-2ANDS<4:FORP=19-W TO21+W:VDU31,P,T,42:NEXT,

T loops the tree from top to bottom. The S equation gives the section number of the tree (1 to 4), W equation gives the half-width of tree (minus one) at current height. The P loop prints the stars centered to screen using efficient VDU command.

In more detail:

Variables:
T=Tree line number from top to bottom, 4 to 17
S=tree Section number 1 to 4 from top to bottom
W=half-Width of the tree at current line not including the trunk at the center of the tree -1
P=Position where to print the next star char

I started with 2 FOR loops, the first looping through 3 widening sections of the tree and second looping the four lines in each section, and adding the width of the stump separately. The width was calculated from the FOR variables. 

After several iterations I noticed that the tree half-width not including trunk at highest 11 lines of the tree can be calculated in one FOR loop with equation
W=(T MOD 4)*(T DIV 4+1)+T DIV 4 (code has evolved since then, not usable anymore)

This equation was further reduced by using the tree section variable S.

Then, I noticed that I could add even the stump of the tree into the same width calculating equation with the "ANDS<4" logic operation part. For this to work I had to change the W variable not to be "tree half width w/o trunk" but "tree half width w/o trunk -1" since the logic operation returns 0 when we are at the stump.

Finally, tweaking the FOR loop to run from 4 to 17 instead of 0 to 13 took 2 bits away from the S equation, yay! (It had a "+1" part in it.)

It took many iterations during several evenings to reduce the code to current state.