pouët.net

Go to bottom

Christmas Diamonds by Finnish Gold

28 byte Christmas Diamonds in Assembler

Author: serato / finnish gold
Category: Christmas Challenge
System:   PET
Language: PET "64tass" Assembler
Len source code: 604
Len exe file:    42
Len code only:   28
Instructions:
Load PRG and run
Description:
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.
Comments:
1. Cursor right must be used instead of space, so as to not overwrite the mirrored 
output.
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. The X register is set to 0, 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).
Go to top