Christmas Diamonds by Finnish Gold

26 byte Christmas Diamonds in Assembler

Author: serato / finnish gold
Category: Christmas Challenge
System:   C64
Language: C64 "64tass" Assembler
Len source code: 593
Len exe file:    40
Len code only:   26
Load PRG and run
The desired repeating diamond pattern may be constructed as the union of forward-
leaning diagonal stripes /// and backward-leaning diagonal stripes \\\. The forward-
leaning stripes are easily rendered by repeatedly printing an asterisk every sixth 
character, with the output wrapped on a text width of 19 characters. The backward-
leaning stripes are a simple mirror image of the forward-leaning ones.
The code uses the CHROUT routine to advance the Kernal's cursor from left to right, 
while simultaneously counting the Y register down and using STA (PNT),y to write the 
mirrored output directly to screen memory. When the Y register underflows, a carriage
return is output. The X register is used to count the gaps between asterisks. A zero 
page counter that defaults to 58 is used as the exit condition.
1. Cursor right must be used instead of space, so as to not overwrite the mirrored 
2. The unintended opcode LAX #'*' is used to load X and A simultaneously with 42. 
Although this is an "unstable" opcode, this use is considered safe as A is $1d
immediately prior, and OR'd with the most common magic constant of $ee gives $ff.
3. To effect the correct spacing of asterisks, X is compared with '*'+6, ie 48. This 
ensures the correct pattern is drawn, but also provides for the correct indentation 
of the first line. X register is 0 by default, so the first asterisk is placed on the
48th character. This results in the first asterisk being drawn on the 10th column 
after 2 empty lines (of 19).