scene.org File Archive

File download

<root>­/­parties­/­2022­/­vccc22­/­christmas_star_challenge/danalog_c128_basic7_vc3-2022.zip

File size:
1 685 886 bytes (1.61M)
File date:
2022-12-30 11:32:13
Download count:
all-time: 9

Preview

  • file_id.diz 2.98K
  • result 40 cols.png 572.18K
  • result 80 cols.png 571.72K
  • source.png 575.13K
  • xmas star 22.bas.txt 283B
  • xmas star 22.prg 198B

file_id.diz

XmasStar22 C128

Author: @danalog@notso.cloud
Category: Christmas Challenge
System:   C128
Language: BASIC 7.0
Len source code: 283
Len exe file:    196
Instructions:
If using VICE, open the x128 emulator and drag the "xmas star 22.prg" file to the application window. It will autostart the program. After it finishes drawing, hit any key to exit back to BASIC. The code is designed to adjust the output based on 40 or 80 columns, so feel free to switch to 80 column mode with the GRAPHIC5 command and try it again.

Description:
The basic idea I went with was to represent the upper left quadrant of the star as a series of bit patterns, which are stored in a DATA statement, then to loop over the pattern and draw mirrored copies of the pattern to the right and bottom.

00001000 - 8
00001100 - 12
00001110 - 14
00001111 - 15
11111111 - 255
01111111 - 127
00111111 - 63
00011111 - 31
00001111 - 15

Line 0 clears the screen, sets up the bit patterns data, and PEEKs the 40/80 column setting and sets variable M (for mode) according to some math to make it be 1 for 40 cols or 2 for 80. If M is 2 (80 cols) we turn on 2Mhz FAST mode. I chose not to do so in 40 columns because it would blank the screen and I wanted to watch it being drawn.

Line 1 loops 9 times, reading the next bit pattern into variable P each time. Then it handles a special case to draw the middle column of the snowflake. If the middle column needs to be drawn, as it does for bit patterns 0 - 4, we set X to the middle column coordinate and call a subroutine to draw the star there.

Line 2 loops over each bit in the current bit pattern in p: If a bit is set, we set X to where we want to draw the star, then call the drawing subroutine. We do so twice in order to mirror the star in the X direction. The drawing routine itself handles mirroring in the Y. If a bit is not set, no drawing is performed.

Line 3 Invokes NEXT J in order to finish looping over the bit pattern, then I to go to the next bit pattern. Drawing proceeds from the middle of the snowflake to the outside. After looping is finished, we're done, so we wait for a keypress, then exit to BASIC.

Line 4 is the drawing routine. It uses the CHAR command to set the position of the cursor and draws either 1 star or 2 stars at its location. The value M is used in two ways here. First, it acts as a multiplier for the X coordinate. If M is 1 (40 cols), X remains the same, but if M is 2 (80 cols) it doubles X so that our snowflake is proportioned correctly on the 80 column screen. It's also used with LEFT$("**",m), which will evaluate to 1 star for 40 columns and 2 stars for 80. I is used to calculate the Y coordinate, and we draw both the top and bottom part before returning from the subroutine.
 
Comments:
This is horribly inefficient and slow, and in the case of drawing the center row actually draws it twice because of the hard-coded Y mirroring in Line 4. The main challenge I set myself was to fit this into 5 lines or fewer and to support both 40 and 80 columns.