Difference between revisions of "Christmas Star"

From SizeCoding
Jump to: navigation, search
(Christmas Star from the Vintage Computing Christmas Challenger 2022)
 
(Added Serato's 34 entry for C64)
Line 27: Line 27:
 
* etc
 
* etc
 
==Winning Entries==
 
==Winning Entries==
 +
=== Winning entry for C64 ===
 +
The shortest entry for the C64 was submitted by Serato with 34 bytes:
 +
<syntaxhighlight lang="6502">
 +
chrout = $FFD2 ; Kernal routine outputs char in A
 +
plot = $E50C ; Kernal routine moves cursor to (y,x)
 +
pnt = $d1    ; Pointer to the start of the current screen line
 +
row = $b3 ; zp var that always starts at 3
 +
*      = $1000
 +
do_2nd ldx row ; render "upside down" triangles
 +
do_line ldy #9 ; render one row of triangle, and its x-mirror image
 +
jsr plot ; move cursor to column 9 on row x
 +
ldy #17 ; start x-mirrored image in column 17
 +
lda #'*' ; the star of the show
 +
do_asks jsr chrout ; print star, advancing kernal cursor to right
 +
sta (pnt),y ; write x-mirrored star with mirrored cursor
 +
dey ; advance mirrored cursor to left
 +
cpy row ; test against line y=x to form diagonal
 +
bne do_asks
 +
cpx row ; check if these weere "upside down" triangles
 +
bne do_2nd ; if not, draw the upside down ones
 +
sys lda #$10 ; entry point of routine, start with y mirrored
 +
sec ; wish this could be avoided, feels like a wasted byte
 +
isc row ; increment bottom row counter and put (16 - row) in A
 +
tax ; we need in x register
 +
bpl do_line ; repeat until row < 0, then fall through
 +
rts
 +
</syntaxhighlight>
 +
Serato's entry was provided with the following comments:
 +
<nowiki>The required octogram may be constructed as the union of four right triangles reflected four ways in x and y axes. The central loop renders one row of the triangle, plus its horizontal mirror image. The outer loop iterates over normal and mirror image screen rows. The result is all four triangles being rendered on top of each other. Saved a byte with unintended 6502 opcode ISC which combines INC and SBC to both increment a counter and load (16 minus) its value into A.</nowiki>

Revision as of 14:50, 28 December 2022

The challenge

During the Vintage Computing Christmas Challenge 2022 the goal was to create the shape of a given Christmas star with as few bytes as possible. All platforms and languages were allowed. The star should look exactly like shown below.

              *       *
              **     **
              ***   ***
              **** ****
          *****************
           ***************
            *************
             ***********
              *********
             ***********
            *************
           ***************
          *****************
              **** ****
              ***   ***
              **     **
              *       *

There were mainly two kinds of approaches:

  • draw character by character
  • mirror triangles
  • etc

Winning Entries

Winning entry for C64

The shortest entry for the C64 was submitted by Serato with 34 bytes:

		chrout = $FFD2	; Kernal routine outputs char in A
		plot = $E50C	; Kernal routine moves cursor to (y,x)
		pnt = $d1     	; Pointer to the start of the current screen line
		row = $b3		; zp var that always starts at 3
*       = $1000
do_2nd	ldx row			; render "upside down" triangles
do_line	ldy #9			; render one row of triangle, and its x-mirror image
		jsr plot		; move cursor to column 9 on row x
		ldy #17			; start x-mirrored image in column 17
		lda #'*'		; the star of the show
do_asks	jsr chrout		; print star, advancing kernal cursor to right
		sta (pnt),y		; write x-mirrored star with mirrored cursor
		dey				; advance mirrored cursor to left
		cpy row			; test against line y=x to form diagonal
		bne do_asks		
		cpx row			; check if these weere "upside down" triangles
		bne do_2nd		; if not, draw the upside down ones
sys		lda #$10		; entry point of routine, start with y mirrored
		sec				; wish this could be avoided, feels like a wasted byte
		isc row			; increment bottom row counter and put (16 - row) in A
		tax				; we need in x register
		bpl do_line		; repeat until row < 0, then fall through
		rts

Serato's entry was provided with the following comments:

The required octogram may be constructed as the union of four right triangles reflected four ways in x and y axes. The central loop renders one row of the triangle, plus its horizontal mirror image. The outer loop iterates over normal and mirror image screen rows. The result is all four triangles being rendered on top of each other. Saved a byte with unintended 6502 opcode ISC which combines INC and SBC to both increment a counter and load (16 minus) its value into A.