Christmas Diamonds
diamond pattern (6502 assembly) 1.0 Author: David Payne Category: Christmas Challenge 2023 System: BBC Micro Language: 6502 assembly Len source code: 284 bytes Len exe file: 32 bytes Len code only: 32 bytes Instructions: Save the VCCC.ssd file on your local PC From the https://bbc.godbolt.org website click on Discs From examples or local Choose file select the saved VCCC.ssd file enter *RUN VCCC23 Description: The diamond pattern is 19x19 characters (0 to 18 in the screen coordinates) the x coordinate is translated into a number from the below table (e.g. x=0 -> 3) 3210123210123210123 the y coordinate is translated into a number from the above table (e.g. y=1 -> 2) when one of the numbers is 3 and the other one is 0 OR when one of the numbers is 2 and the other one is 1 output an asterisk else output a space or more simply... when the 2 numbers add up to 3 output an asterisk else output a space the program consists of an outer y loop and an inner x loop, both loop 19 times at the end of the x loop a new line is output a lookup table is used to get the numbers for x and y to simplify the code, rather than the rule being the 2 numbers add up to 3, the following rule is used instead: the 2 numbers when exclusive ORed together equal 42 42 being the ASCII code for an asterisk the 1st 2 entries in the lookup table are in fact the last 2 bytes of the code, which saves 2 bytes these are: 229 96 which means that the next 2 table entries become: 74 (96 EOR 42) 207 (229 EOR 42) and the rest of the table follows the established pattern (the next few entries being 74, 96, 229, etc.) Also, as the table repeats after every 6 entries, only the first 6 entries are needed initially; the rest of the table is built up as the program runs Comments: To produce the VCCC23 executable: Copy and paste the SOURCE.txt file into jsbeeb (https://bbc.godbolt.org) enter RUN enter *SAVE VCCC23 53 73 10FORI%=0TO2STEP2 20P%=&53 30[OPT I% 40.loop1 LDX #data-2 50.loop2 LDA 0,X 60STA 6,X 70.eor EOR data-2 80CMP #42 90BEQ skip 100LDA #32 110.skip JSR &FFEE 120INX 130BPL loop2 140JSR &FFE7 150INC eor+1 160BPL loop1 170RTS 180.data EQUB 74 190EQUB 207 200EQUB 74 210EQUB 96 220] 230NEXT
[ back to the prod ]