<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.sizecoding.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=GeirS</id>
		<title>SizeCoding - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://www.sizecoding.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=GeirS"/>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/wiki/Special:Contributions/GeirS"/>
		<updated>2026-05-04T13:04:41Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.0</generator>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=Christmas_Tree&amp;diff=994</id>
		<title>Christmas Tree</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=Christmas_Tree&amp;diff=994"/>
				<updated>2021-12-30T00:19:40Z</updated>
		
		<summary type="html">&lt;p&gt;GeirS: Added creation date of version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Case Study]]&lt;br /&gt;
==The challenge==&lt;br /&gt;
During the [https://demozoo.org/parties/4398/ Vintage Computing Christmas Challenge 2021] the goal was to create the shape of a given Christmas tree with as few bytes as possible. All platforms and languages were allowed.&lt;br /&gt;
The tree should be centered and look exactly like shown bellow.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
                          *&lt;br /&gt;
                         ***&lt;br /&gt;
                        *****&lt;br /&gt;
                       *******&lt;br /&gt;
                         ***&lt;br /&gt;
                       *******&lt;br /&gt;
                     ***********&lt;br /&gt;
                   ***************&lt;br /&gt;
                        ***** &lt;br /&gt;
                     *********** &lt;br /&gt;
                  ***************** &lt;br /&gt;
               *********************** &lt;br /&gt;
                         ***&lt;br /&gt;
                         ***&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
There were mainly two kinds of approaches:&lt;br /&gt;
* calculate stars using a formula&lt;br /&gt;
* save amount of stars within data&lt;br /&gt;
Do to the trunk of the tree, the second type was more efficient. &lt;br /&gt;
==Winning Entries==&lt;br /&gt;
=== Shortest DOS version ===&lt;br /&gt;
The shortest DOS version with 44 bytes came from Hellmood:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=nasm&amp;gt;&lt;br /&gt;
org 100h			; define start of code for data access&lt;br /&gt;
db 80				; screen width, located at [SI], also &amp;quot;push ax&amp;quot;&lt;br /&gt;
mov bx,d			; pointer to data for XLAT&lt;br /&gt;
mov cx,1120			; 14 lines with 80 chars each&lt;br /&gt;
X: mov ax,cx		; get current sequence position&lt;br /&gt;
div byte [si]		; transform to [X,Y] in AL, AH&lt;br /&gt;
xlat				; get tree width for current line number&lt;br /&gt;
sub ah,40			; center tree in the middle&lt;br /&gt;
jnc F				; - &lt;br /&gt;
neg ah				; -&lt;br /&gt;
F: sub ah,al		; inside or outside tree?&lt;br /&gt;
salc				; set AL depending on carry flag&lt;br /&gt;
imul ax,byte -42	; transform into STAR or nothing&lt;br /&gt;
int 29h				; write current char to screen&lt;br /&gt;
loop X				; repeat unil all chars are plotter&lt;br /&gt;
ret					; return to prompt (JMP to former AX=0x0000)&lt;br /&gt;
d:db 2,2,12,9,6,3,8,6,4,2,4,3,2,1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Winning entry for C64 ===&lt;br /&gt;
The shortest entry overall was for the C64 and was submitted by Serato with only 37 bytes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
		!cpu 6510			; enable unintended opcodes in ACME assembler&lt;br /&gt;
&lt;br /&gt;
		chrout = $FFD2&lt;br /&gt;
		crlf = $AAD7&lt;br /&gt;
		pntr = $D3&lt;br /&gt;
		width = 40&lt;br /&gt;
&lt;br /&gt;
		;; BASIC header&lt;br /&gt;
		*= $0801&lt;br /&gt;
		!word +, 10&lt;br /&gt;
		!byte $9e&lt;br /&gt;
		!text &amp;quot;2092&amp;quot;&lt;br /&gt;
		!byte 0&lt;br /&gt;
+		!word 0&lt;br /&gt;
table&lt;br /&gt;
		!byte -1  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -15 &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -17 &lt;br /&gt;
		!byte -23 &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
code&lt;br /&gt;
--		lsr&lt;br /&gt;
		sbc #(128-width/2)&lt;br /&gt;
		sta pntr&lt;br /&gt;
		lda #'*'&lt;br /&gt;
-		jsr chrout&lt;br /&gt;
		inx&lt;br /&gt;
		bne -&lt;br /&gt;
		jsr crlf&lt;br /&gt;
		iny&lt;br /&gt;
entry&lt;br /&gt;
		lax table,y&lt;br /&gt;
		bmi --&lt;br /&gt;
		rts&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Serato's entry was provided with the following comments:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;This entry to the Christmas Tree challenge saves space in six ways:&lt;br /&gt;
&lt;br /&gt;
 1. Using the c64 kernal routines to output individual characters and carriage return/linefeed. These routines save/restore X/Y allowing the registers to be used as loop counters.&lt;br /&gt;
&lt;br /&gt;
 2. Writing to the PNTR kernal variable to indent each row.&lt;br /&gt;
&lt;br /&gt;
 3. Using the unintended LAX opcode to simultaneously load A and X with the table values.&lt;br /&gt;
&lt;br /&gt;
 4. Storing the row widths as 2's complement negative values, to simplify the indent calculation to divide by two (LSR) and subtract (SBC). The inner loop simply counts back up to zero for rendering the correct width.&lt;br /&gt;
&lt;br /&gt;
 5. BASIC loads the Y register from address $30d. This defaults to 0 on startup, so Y does not need to be initialised.&lt;br /&gt;
&lt;br /&gt;
 6. Placing the table before the code in memory, the MSB of the table entries do not match the MSB of the first opcode (LSR), allowing the outer loop exit condition to be set implicitly in the Negative flag as the table values are read.&lt;br /&gt;
&lt;br /&gt;
These optimisations result in 37 bytes of machine code and data. Two further optimisations are possible each of which save 1 byte, but break the rules of this challenge:&lt;br /&gt;
&lt;br /&gt;
 a - LSR and SBC can be replaced with the unintended opcode ARR, if you are willing to &amp;quot;centre&amp;quot; the tree on a virtual screen width of 32 chars.&lt;br /&gt;
&lt;br /&gt;
 b - The BASIC interpreter leaves the line number in the zero page word at $39, so by setting the line number in the basic header to the address of the table, &amp;quot;LAX ($39),y&amp;quot; can be used for the table access.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Optimized post-deadline versions==&lt;br /&gt;
===36 bytes version for C64===&lt;br /&gt;
The C64 version was shortened by altering the calculation so the default register values on start cause the first line to be drawn, shortening the table by one entry.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
		!cpu 6510			; enable unintended opcodes in ACME assembler&lt;br /&gt;
&lt;br /&gt;
		chrout = $FFD2&lt;br /&gt;
		crlf = $AAD7&lt;br /&gt;
		pntr = $D3&lt;br /&gt;
		width = 40&lt;br /&gt;
&lt;br /&gt;
		;; BASIC header&lt;br /&gt;
		*= $0801&lt;br /&gt;
		!word +, 10&lt;br /&gt;
		!byte $9e&lt;br /&gt;
		!text &amp;quot;2074&amp;quot;&lt;br /&gt;
		!byte 0&lt;br /&gt;
+		!word 0&lt;br /&gt;
table&lt;br /&gt;
;		!byte -1  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -15 &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -17 &lt;br /&gt;
		!byte -23 &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
code&lt;br /&gt;
--		adc	#width-1&lt;br /&gt;
		lsr&lt;br /&gt;
		sta pntr&lt;br /&gt;
		lda #'*'&lt;br /&gt;
-		jsr chrout&lt;br /&gt;
		inx&lt;br /&gt;
		bmi -&lt;br /&gt;
		jsr crlf&lt;br /&gt;
		iny&lt;br /&gt;
		lax table-1,y&lt;br /&gt;
		bmi --&lt;br /&gt;
		rts&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===32 bytes version for ZX Spectrum===&lt;br /&gt;
After the deadline following entry for the ZX Spectrum with only 35 bytes was submitted by reddie and optimized by char to 32 bytes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;z80&amp;quot;&amp;gt;&lt;br /&gt;
# Christmas Tree post-event build, ZX Spectrum version&lt;br /&gt;
# tnx to Manwe for info about event, better late than never =)&lt;br /&gt;
# first version - 35 bytes - (c) reddie, 2021.12.25&lt;br /&gt;
# optimized to 32 bytes by char, 2021.12.26 - huge thanks from me!&lt;br /&gt;
# full final object len  = 32 bytes (from label &amp;quot;data&amp;quot; to label &amp;quot;end&amp;quot;)&lt;br /&gt;
# data array len  = 14 bytes; code len = 18 bytes, 13 Z80 instructions&lt;br /&gt;
# execute from Basic only! entry point  = 61455, or just run TRD image&lt;br /&gt;
# and then run &amp;quot;ctree32b&amp;quot; Basic-program, it will load &amp;amp; start the code&lt;br /&gt;
# TRD file also contains source text in ALASM format&lt;br /&gt;
&lt;br /&gt;
data	org	-16*256+1&lt;br /&gt;
	defb	-5,-5,-25,-19,-13,-7,-17,-13,-9,-5,-9,-7,-5,-3&lt;br /&gt;
&lt;br /&gt;
start	dec	c&lt;br /&gt;
	jr	z,$	;stop when finished&lt;br /&gt;
	ld	a,23	;set coords via ROM procedure&lt;br /&gt;
	rst	16&lt;br /&gt;
	ld	a,(bc)	;line len in negative format&lt;br /&gt;
	ld	e,a&lt;br /&gt;
	rra&lt;br /&gt;
	sub	b	;centering&lt;br /&gt;
print	rst	16&lt;br /&gt;
	ld	a,&amp;quot;*&amp;quot;&lt;br /&gt;
	inc	e&lt;br /&gt;
	jr	nz,print&lt;br /&gt;
	jr	start&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===35 bytes version for Plus/4===&lt;br /&gt;
The following optimized version for the Commodore Plus/4 was created after the deadline:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502tasm&amp;quot;&amp;gt;&lt;br /&gt;
# Plus/4 Christmas Tree by GeirS, 2021-12-29&lt;br /&gt;
# Assemble using 64tass (replace hash with semicolon first, except for 'lda #$2a')&lt;br /&gt;
&lt;br /&gt;
BtmRow		= $0c00+$28*$18	# Address of bottom screen row&lt;br /&gt;
Screen		= BtmRow-$6c	# Adjustment for ($100-$28)/2&lt;br /&gt;
ScrollUp	= $da89			# KERNAL routine to scroll screen upwards&lt;br /&gt;
VarTab		= $2d			# Pointer: Start of BASIC variables&lt;br /&gt;
&lt;br /&gt;
			* = $1001		# Load address&lt;br /&gt;
&lt;br /&gt;
# BASIC stub&lt;br /&gt;
			.word (NextLine),0&lt;br /&gt;
			.null $9e,format(&amp;quot;%4d&amp;quot;, Start)&lt;br /&gt;
NextLine&lt;br /&gt;
			.word 0&lt;br /&gt;
&lt;br /&gt;
# Code and data (35 bytes total)&lt;br /&gt;
RowLoop&lt;br /&gt;
			lsr				# Calculate screen offset&lt;br /&gt;
			tay&lt;br /&gt;
			lda #$2a		# Asterisk character&lt;br /&gt;
CharLoop&lt;br /&gt;
			sta Screen,y	# Put char in bottom screen row&lt;br /&gt;
			iny&lt;br /&gt;
			inx&lt;br /&gt;
			bne CharLoop	# Loop for all chars&lt;br /&gt;
Start&lt;br /&gt;
			jsr ScrollUp	# Scroll the screen upwards (x=0 after)&lt;br /&gt;
			dec VarTab		# Adjust address of char count to use next&lt;br /&gt;
			lax (VarTab,x)	# Load char count into both a and x&lt;br /&gt;
			bmi RowLoop		# Loop while not done&lt;br /&gt;
			rts&lt;br /&gt;
&lt;br /&gt;
# Asterisk counts (negative values to optimize the code)&lt;br /&gt;
			.char -3,-3,-23,-17,-11,-5,-15,-11,-7,-3,-7,-5,-3,-1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>GeirS</name></author>	</entry>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=Christmas_Tree&amp;diff=993</id>
		<title>Christmas Tree</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=Christmas_Tree&amp;diff=993"/>
				<updated>2021-12-29T13:00:30Z</updated>
		
		<summary type="html">&lt;p&gt;GeirS: Replaced semicolon with hash for better formatting of comments&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Case Study]]&lt;br /&gt;
==The challenge==&lt;br /&gt;
During the [https://demozoo.org/parties/4398/ Vintage Computing Christmas Challenge 2021] the goal was to create the shape of a given Christmas tree with as few bytes as possible. All platforms and languages were allowed.&lt;br /&gt;
The tree should be centered and look exactly like shown bellow.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
                          *&lt;br /&gt;
                         ***&lt;br /&gt;
                        *****&lt;br /&gt;
                       *******&lt;br /&gt;
                         ***&lt;br /&gt;
                       *******&lt;br /&gt;
                     ***********&lt;br /&gt;
                   ***************&lt;br /&gt;
                        ***** &lt;br /&gt;
                     *********** &lt;br /&gt;
                  ***************** &lt;br /&gt;
               *********************** &lt;br /&gt;
                         ***&lt;br /&gt;
                         ***&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
There were mainly two kinds of approaches:&lt;br /&gt;
* calculate stars using a formula&lt;br /&gt;
* save amount of stars within data&lt;br /&gt;
Do to the trunk of the tree, the second type was more efficient. &lt;br /&gt;
==Winning Entries==&lt;br /&gt;
=== Shortest DOS version ===&lt;br /&gt;
The shortest DOS version with 44 bytes came from Hellmood:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=nasm&amp;gt;&lt;br /&gt;
org 100h			; define start of code for data access&lt;br /&gt;
db 80				; screen width, located at [SI], also &amp;quot;push ax&amp;quot;&lt;br /&gt;
mov bx,d			; pointer to data for XLAT&lt;br /&gt;
mov cx,1120			; 14 lines with 80 chars each&lt;br /&gt;
X: mov ax,cx		; get current sequence position&lt;br /&gt;
div byte [si]		; transform to [X,Y] in AL, AH&lt;br /&gt;
xlat				; get tree width for current line number&lt;br /&gt;
sub ah,40			; center tree in the middle&lt;br /&gt;
jnc F				; - &lt;br /&gt;
neg ah				; -&lt;br /&gt;
F: sub ah,al		; inside or outside tree?&lt;br /&gt;
salc				; set AL depending on carry flag&lt;br /&gt;
imul ax,byte -42	; transform into STAR or nothing&lt;br /&gt;
int 29h				; write current char to screen&lt;br /&gt;
loop X				; repeat unil all chars are plotter&lt;br /&gt;
ret					; return to prompt (JMP to former AX=0x0000)&lt;br /&gt;
d:db 2,2,12,9,6,3,8,6,4,2,4,3,2,1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Winning entry for C64 ===&lt;br /&gt;
The shortest entry overall was for the C64 and was submitted by Serato with only 37 bytes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
		!cpu 6510			; enable unintended opcodes in ACME assembler&lt;br /&gt;
&lt;br /&gt;
		chrout = $FFD2&lt;br /&gt;
		crlf = $AAD7&lt;br /&gt;
		pntr = $D3&lt;br /&gt;
		width = 40&lt;br /&gt;
&lt;br /&gt;
		;; BASIC header&lt;br /&gt;
		*= $0801&lt;br /&gt;
		!word +, 10&lt;br /&gt;
		!byte $9e&lt;br /&gt;
		!text &amp;quot;2092&amp;quot;&lt;br /&gt;
		!byte 0&lt;br /&gt;
+		!word 0&lt;br /&gt;
table&lt;br /&gt;
		!byte -1  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -15 &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -17 &lt;br /&gt;
		!byte -23 &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
code&lt;br /&gt;
--		lsr&lt;br /&gt;
		sbc #(128-width/2)&lt;br /&gt;
		sta pntr&lt;br /&gt;
		lda #'*'&lt;br /&gt;
-		jsr chrout&lt;br /&gt;
		inx&lt;br /&gt;
		bne -&lt;br /&gt;
		jsr crlf&lt;br /&gt;
		iny&lt;br /&gt;
entry&lt;br /&gt;
		lax table,y&lt;br /&gt;
		bmi --&lt;br /&gt;
		rts&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Serato's entry was provided with the following comments:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;This entry to the Christmas Tree challenge saves space in six ways:&lt;br /&gt;
&lt;br /&gt;
 1. Using the c64 kernal routines to output individual characters and carriage return/linefeed. These routines save/restore X/Y allowing the registers to be used as loop counters.&lt;br /&gt;
&lt;br /&gt;
 2. Writing to the PNTR kernal variable to indent each row.&lt;br /&gt;
&lt;br /&gt;
 3. Using the unintended LAX opcode to simultaneously load A and X with the table values.&lt;br /&gt;
&lt;br /&gt;
 4. Storing the row widths as 2's complement negative values, to simplify the indent calculation to divide by two (LSR) and subtract (SBC). The inner loop simply counts back up to zero for rendering the correct width.&lt;br /&gt;
&lt;br /&gt;
 5. BASIC loads the Y register from address $30d. This defaults to 0 on startup, so Y does not need to be initialised.&lt;br /&gt;
&lt;br /&gt;
 6. Placing the table before the code in memory, the MSB of the table entries do not match the MSB of the first opcode (LSR), allowing the outer loop exit condition to be set implicitly in the Negative flag as the table values are read.&lt;br /&gt;
&lt;br /&gt;
These optimisations result in 37 bytes of machine code and data. Two further optimisations are possible each of which save 1 byte, but break the rules of this challenge:&lt;br /&gt;
&lt;br /&gt;
 a - LSR and SBC can be replaced with the unintended opcode ARR, if you are willing to &amp;quot;centre&amp;quot; the tree on a virtual screen width of 32 chars.&lt;br /&gt;
&lt;br /&gt;
 b - The BASIC interpreter leaves the line number in the zero page word at $39, so by setting the line number in the basic header to the address of the table, &amp;quot;LAX ($39),y&amp;quot; can be used for the table access.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Optimized post-deadline versions==&lt;br /&gt;
===36 bytes version for C64===&lt;br /&gt;
The C64 version was shortened by altering the calculation so the default register values on start cause the first line to be drawn, shortening the table by one entry.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
		!cpu 6510			; enable unintended opcodes in ACME assembler&lt;br /&gt;
&lt;br /&gt;
		chrout = $FFD2&lt;br /&gt;
		crlf = $AAD7&lt;br /&gt;
		pntr = $D3&lt;br /&gt;
		width = 40&lt;br /&gt;
&lt;br /&gt;
		;; BASIC header&lt;br /&gt;
		*= $0801&lt;br /&gt;
		!word +, 10&lt;br /&gt;
		!byte $9e&lt;br /&gt;
		!text &amp;quot;2074&amp;quot;&lt;br /&gt;
		!byte 0&lt;br /&gt;
+		!word 0&lt;br /&gt;
table&lt;br /&gt;
;		!byte -1  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -15 &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -17 &lt;br /&gt;
		!byte -23 &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
code&lt;br /&gt;
--		adc	#width-1&lt;br /&gt;
		lsr&lt;br /&gt;
		sta pntr&lt;br /&gt;
		lda #'*'&lt;br /&gt;
-		jsr chrout&lt;br /&gt;
		inx&lt;br /&gt;
		bmi -&lt;br /&gt;
		jsr crlf&lt;br /&gt;
		iny&lt;br /&gt;
		lax table-1,y&lt;br /&gt;
		bmi --&lt;br /&gt;
		rts&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===32 bytes version for ZX Spectrum===&lt;br /&gt;
After the deadline following entry for the ZX Spectrum with only 35 bytes was submitted by reddie and optimized by char to 32 bytes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;z80&amp;quot;&amp;gt;&lt;br /&gt;
# Christmas Tree post-event build, ZX Spectrum version&lt;br /&gt;
# tnx to Manwe for info about event, better late than never =)&lt;br /&gt;
# first version - 35 bytes - (c) reddie, 2021.12.25&lt;br /&gt;
# optimized to 32 bytes by char, 2021.12.26 - huge thanks from me!&lt;br /&gt;
# full final object len  = 32 bytes (from label &amp;quot;data&amp;quot; to label &amp;quot;end&amp;quot;)&lt;br /&gt;
# data array len  = 14 bytes; code len = 18 bytes, 13 Z80 instructions&lt;br /&gt;
# execute from Basic only! entry point  = 61455, or just run TRD image&lt;br /&gt;
# and then run &amp;quot;ctree32b&amp;quot; Basic-program, it will load &amp;amp; start the code&lt;br /&gt;
# TRD file also contains source text in ALASM format&lt;br /&gt;
&lt;br /&gt;
data	org	-16*256+1&lt;br /&gt;
	defb	-5,-5,-25,-19,-13,-7,-17,-13,-9,-5,-9,-7,-5,-3&lt;br /&gt;
&lt;br /&gt;
start	dec	c&lt;br /&gt;
	jr	z,$	;stop when finished&lt;br /&gt;
	ld	a,23	;set coords via ROM procedure&lt;br /&gt;
	rst	16&lt;br /&gt;
	ld	a,(bc)	;line len in negative format&lt;br /&gt;
	ld	e,a&lt;br /&gt;
	rra&lt;br /&gt;
	sub	b	;centering&lt;br /&gt;
print	rst	16&lt;br /&gt;
	ld	a,&amp;quot;*&amp;quot;&lt;br /&gt;
	inc	e&lt;br /&gt;
	jr	nz,print&lt;br /&gt;
	jr	start&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===35 bytes version for Plus/4===&lt;br /&gt;
The following optimized version for the Commodore Plus/4 was created after the deadline:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502tasm&amp;quot;&amp;gt;&lt;br /&gt;
# Plus/4 Christmas Tree by GeirS&lt;br /&gt;
# Assemble using 64tass (replace hash with semicolon first, except for 'lda #$2a')&lt;br /&gt;
&lt;br /&gt;
BtmRow		= $0c00+$28*$18	# Address of bottom screen row&lt;br /&gt;
Screen		= BtmRow-$6c	# Adjustment for ($100-$28)/2&lt;br /&gt;
ScrollUp	= $da89			# KERNAL routine to scroll screen upwards&lt;br /&gt;
VarTab		= $2d			# Pointer: Start of BASIC variables&lt;br /&gt;
&lt;br /&gt;
			* = $1001		# Load address&lt;br /&gt;
&lt;br /&gt;
# BASIC stub&lt;br /&gt;
			.word (NextLine),0&lt;br /&gt;
			.null $9e,format(&amp;quot;%4d&amp;quot;, Start)&lt;br /&gt;
NextLine&lt;br /&gt;
			.word 0&lt;br /&gt;
&lt;br /&gt;
# Code and data (35 bytes total)&lt;br /&gt;
RowLoop&lt;br /&gt;
			lsr				# Calculate screen offset&lt;br /&gt;
			tay&lt;br /&gt;
			lda #$2a		# Asterisk character&lt;br /&gt;
CharLoop&lt;br /&gt;
			sta Screen,y	# Put char in bottom screen row&lt;br /&gt;
			iny&lt;br /&gt;
			inx&lt;br /&gt;
			bne CharLoop	# Loop for all chars&lt;br /&gt;
Start&lt;br /&gt;
			jsr ScrollUp	# Scroll the screen upwards (x=0 after)&lt;br /&gt;
			dec VarTab		# Adjust address of char count to use next&lt;br /&gt;
			lax (VarTab,x)	# Load char count into both a and x&lt;br /&gt;
			bmi RowLoop		# Loop while not done&lt;br /&gt;
			rts&lt;br /&gt;
&lt;br /&gt;
# Asterisk counts (negative values to optimize the code)&lt;br /&gt;
			.char -3,-3,-23,-17,-11,-5,-15,-11,-7,-3,-7,-5,-3,-1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>GeirS</name></author>	</entry>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=Christmas_Tree&amp;diff=991</id>
		<title>Christmas Tree</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=Christmas_Tree&amp;diff=991"/>
				<updated>2021-12-29T10:20:02Z</updated>
		
		<summary type="html">&lt;p&gt;GeirS: Added 35 byte Plus/4 version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Case Study]]&lt;br /&gt;
==The challenge==&lt;br /&gt;
During the [https://demozoo.org/parties/4398/ Vintage Computing Christmas Challenge 2021] the goal was to create the shape of a given Christmas tree with as few bytes as possible. All platforms and languages were allowed.&lt;br /&gt;
The tree should be centered and look exactly like shown bellow.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
                          *&lt;br /&gt;
                         ***&lt;br /&gt;
                        *****&lt;br /&gt;
                       *******&lt;br /&gt;
                         ***&lt;br /&gt;
                       *******&lt;br /&gt;
                     ***********&lt;br /&gt;
                   ***************&lt;br /&gt;
                        ***** &lt;br /&gt;
                     *********** &lt;br /&gt;
                  ***************** &lt;br /&gt;
               *********************** &lt;br /&gt;
                         ***&lt;br /&gt;
                         ***&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
There were mainly two kinds of approaches:&lt;br /&gt;
* calculate stars using a formula&lt;br /&gt;
* save amount of stars within data&lt;br /&gt;
Do to the trunk of the tree, the second type was more efficient. &lt;br /&gt;
==Winning Entries==&lt;br /&gt;
=== Shortest DOS version ===&lt;br /&gt;
The shortest DOS version with 44 bytes came from Hellmood:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=nasm&amp;gt;&lt;br /&gt;
org 100h			; define start of code for data access&lt;br /&gt;
db 80				; screen width, located at [SI], also &amp;quot;push ax&amp;quot;&lt;br /&gt;
mov bx,d			; pointer to data for XLAT&lt;br /&gt;
mov cx,1120			; 14 lines with 80 chars each&lt;br /&gt;
X: mov ax,cx		; get current sequence position&lt;br /&gt;
div byte [si]		; transform to [X,Y] in AL, AH&lt;br /&gt;
xlat				; get tree width for current line number&lt;br /&gt;
sub ah,40			; center tree in the middle&lt;br /&gt;
jnc F				; - &lt;br /&gt;
neg ah				; -&lt;br /&gt;
F: sub ah,al		; inside or outside tree?&lt;br /&gt;
salc				; set AL depending on carry flag&lt;br /&gt;
imul ax,byte -42	; transform into STAR or nothing&lt;br /&gt;
int 29h				; write current char to screen&lt;br /&gt;
loop X				; repeat unil all chars are plotter&lt;br /&gt;
ret					; return to prompt (JMP to former AX=0x0000)&lt;br /&gt;
d:db 2,2,12,9,6,3,8,6,4,2,4,3,2,1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Winning entry for C64 ===&lt;br /&gt;
The shortest entry overall was for the C64 and was submitted by Serato with only 37 bytes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
		!cpu 6510			; enable unintended opcodes in ACME assembler&lt;br /&gt;
&lt;br /&gt;
		chrout = $FFD2&lt;br /&gt;
		crlf = $AAD7&lt;br /&gt;
		pntr = $D3&lt;br /&gt;
		width = 40&lt;br /&gt;
&lt;br /&gt;
		;; BASIC header&lt;br /&gt;
		*= $0801&lt;br /&gt;
		!word +, 10&lt;br /&gt;
		!byte $9e&lt;br /&gt;
		!text &amp;quot;2092&amp;quot;&lt;br /&gt;
		!byte 0&lt;br /&gt;
+		!word 0&lt;br /&gt;
table&lt;br /&gt;
		!byte -1  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -15 &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -17 &lt;br /&gt;
		!byte -23 &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
code&lt;br /&gt;
--		lsr&lt;br /&gt;
		sbc #(128-width/2)&lt;br /&gt;
		sta pntr&lt;br /&gt;
		lda #'*'&lt;br /&gt;
-		jsr chrout&lt;br /&gt;
		inx&lt;br /&gt;
		bne -&lt;br /&gt;
		jsr crlf&lt;br /&gt;
		iny&lt;br /&gt;
entry&lt;br /&gt;
		lax table,y&lt;br /&gt;
		bmi --&lt;br /&gt;
		rts&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Serato's entry was provided with the following comments:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;This entry to the Christmas Tree challenge saves space in six ways:&lt;br /&gt;
&lt;br /&gt;
 1. Using the c64 kernal routines to output individual characters and carriage return/linefeed. These routines save/restore X/Y allowing the registers to be used as loop counters.&lt;br /&gt;
&lt;br /&gt;
 2. Writing to the PNTR kernal variable to indent each row.&lt;br /&gt;
&lt;br /&gt;
 3. Using the unintended LAX opcode to simultaneously load A and X with the table values.&lt;br /&gt;
&lt;br /&gt;
 4. Storing the row widths as 2's complement negative values, to simplify the indent calculation to divide by two (LSR) and subtract (SBC). The inner loop simply counts back up to zero for rendering the correct width.&lt;br /&gt;
&lt;br /&gt;
 5. BASIC loads the Y register from address $30d. This defaults to 0 on startup, so Y does not need to be initialised.&lt;br /&gt;
&lt;br /&gt;
 6. Placing the table before the code in memory, the MSB of the table entries do not match the MSB of the first opcode (LSR), allowing the outer loop exit condition to be set implicitly in the Negative flag as the table values are read.&lt;br /&gt;
&lt;br /&gt;
These optimisations result in 37 bytes of machine code and data. Two further optimisations are possible each of which save 1 byte, but break the rules of this challenge:&lt;br /&gt;
&lt;br /&gt;
 a - LSR and SBC can be replaced with the unintended opcode ARR, if you are willing to &amp;quot;centre&amp;quot; the tree on a virtual screen width of 32 chars.&lt;br /&gt;
&lt;br /&gt;
 b - The BASIC interpreter leaves the line number in the zero page word at $39, so by setting the line number in the basic header to the address of the table, &amp;quot;LAX ($39),y&amp;quot; can be used for the table access.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Optimized post-deadline versions==&lt;br /&gt;
===36 bytes version for C64===&lt;br /&gt;
The C64 version was shortened by altering the calculation so the default register values on start cause the first line to be drawn, shortening the table by one entry.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
		!cpu 6510			; enable unintended opcodes in ACME assembler&lt;br /&gt;
&lt;br /&gt;
		chrout = $FFD2&lt;br /&gt;
		crlf = $AAD7&lt;br /&gt;
		pntr = $D3&lt;br /&gt;
		width = 40&lt;br /&gt;
&lt;br /&gt;
		;; BASIC header&lt;br /&gt;
		*= $0801&lt;br /&gt;
		!word +, 10&lt;br /&gt;
		!byte $9e&lt;br /&gt;
		!text &amp;quot;2074&amp;quot;&lt;br /&gt;
		!byte 0&lt;br /&gt;
+		!word 0&lt;br /&gt;
table&lt;br /&gt;
;		!byte -1  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -7  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -15 &lt;br /&gt;
		!byte -5  &lt;br /&gt;
		!byte -11 &lt;br /&gt;
		!byte -17 &lt;br /&gt;
		!byte -23 &lt;br /&gt;
		!byte -3  &lt;br /&gt;
		!byte -3  &lt;br /&gt;
code&lt;br /&gt;
--		adc	#width-1&lt;br /&gt;
		lsr&lt;br /&gt;
		sta pntr&lt;br /&gt;
		lda #'*'&lt;br /&gt;
-		jsr chrout&lt;br /&gt;
		inx&lt;br /&gt;
		bmi -&lt;br /&gt;
		jsr crlf&lt;br /&gt;
		iny&lt;br /&gt;
		lax table-1,y&lt;br /&gt;
		bmi --&lt;br /&gt;
		rts&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===32 bytes version for ZX Spectrum===&lt;br /&gt;
After the deadline following entry for the ZX Spectrum with only 35 bytes was submitted by reddie and optimized by char to 32 bytes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;z80&amp;quot;&amp;gt;&lt;br /&gt;
# Christmas Tree post-event build, ZX Spectrum version&lt;br /&gt;
# tnx to Manwe for info about event, better late than never =)&lt;br /&gt;
# first version - 35 bytes - (c) reddie, 2021.12.25&lt;br /&gt;
# optimized to 32 bytes by char, 2021.12.26 - huge thanks from me!&lt;br /&gt;
# full final object len  = 32 bytes (from label &amp;quot;data&amp;quot; to label &amp;quot;end&amp;quot;)&lt;br /&gt;
# data array len  = 14 bytes; code len = 18 bytes, 13 Z80 instructions&lt;br /&gt;
# execute from Basic only! entry point  = 61455, or just run TRD image&lt;br /&gt;
# and then run &amp;quot;ctree32b&amp;quot; Basic-program, it will load &amp;amp; start the code&lt;br /&gt;
# TRD file also contains source text in ALASM format&lt;br /&gt;
&lt;br /&gt;
data	org	-16*256+1&lt;br /&gt;
	defb	-5,-5,-25,-19,-13,-7,-17,-13,-9,-5,-9,-7,-5,-3&lt;br /&gt;
&lt;br /&gt;
start	dec	c&lt;br /&gt;
	jr	z,$	;stop when finished&lt;br /&gt;
	ld	a,23	;set coords via ROM procedure&lt;br /&gt;
	rst	16&lt;br /&gt;
	ld	a,(bc)	;line len in negative format&lt;br /&gt;
	ld	e,a&lt;br /&gt;
	rra&lt;br /&gt;
	sub	b	;centering&lt;br /&gt;
print	rst	16&lt;br /&gt;
	ld	a,&amp;quot;*&amp;quot;&lt;br /&gt;
	inc	e&lt;br /&gt;
	jr	nz,print&lt;br /&gt;
	jr	start&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===35 bytes version for Plus/4===&lt;br /&gt;
The following optimized version for the Commodore Plus/4 was created after the deadline:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502tasm&amp;quot;&amp;gt;&lt;br /&gt;
; Plus/4 Christmas Tree by GeirS&lt;br /&gt;
; Assemble using 64tass&lt;br /&gt;
&lt;br /&gt;
BtmRow		= $0c00+$28*$18	; Address of bottom screen row&lt;br /&gt;
Screen		= BtmRow-$6c	; Adjustment for ($100-$28)/2&lt;br /&gt;
ScrollUp	= $da89			; KERNAL routine to scroll screen upwards&lt;br /&gt;
VarTab		= $2d			; Pointer: Start of BASIC variables&lt;br /&gt;
&lt;br /&gt;
			* = $1001		; Load address&lt;br /&gt;
&lt;br /&gt;
; BASIC stub&lt;br /&gt;
			.word (NextLine),0&lt;br /&gt;
			.null $9e,format(&amp;quot;%4d&amp;quot;, Start)&lt;br /&gt;
NextLine&lt;br /&gt;
			.word 0&lt;br /&gt;
&lt;br /&gt;
; Code and data (35 bytes total)&lt;br /&gt;
RowLoop&lt;br /&gt;
			lsr				; Calculate screen offset&lt;br /&gt;
			tay&lt;br /&gt;
			lda #$2a		; Asterisk character&lt;br /&gt;
CharLoop&lt;br /&gt;
			sta Screen,y	; Put char in bottom screen row&lt;br /&gt;
			iny&lt;br /&gt;
			inx&lt;br /&gt;
			bne CharLoop	; Loop for all chars&lt;br /&gt;
Start&lt;br /&gt;
			jsr ScrollUp	; Scroll the screen upwards (x=0 after)&lt;br /&gt;
			dec VarTab		; Adjust address of char count to use next&lt;br /&gt;
			lax (VarTab,x)	; Load char count into both a and x&lt;br /&gt;
			bmi RowLoop		; Loop while not done&lt;br /&gt;
			rts&lt;br /&gt;
&lt;br /&gt;
; Asterisk counts (negative values to optimize the code)&lt;br /&gt;
			.char -3,-3,-23,-17,-11,-5,-15,-11,-7,-3,-7,-5,-3,-1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>GeirS</name></author>	</entry>

	</feed>