Plasm v4.32
Source:       3-LogikerChallenge-2025-3043.pls
Hex:          3-LogikerChallenge-2025-3043.plh
P Tape 8-bit: 3-LogikerChallenge-2025-3043.pl8

         1 %s 3                                           code PleX
         2 {
         3 Logiker Christmas Challenge 2025 to draw a snowflake.
         4 
         5 Method:
         6 The snowflake is symmetrical horizontally & vertically.
         7 If the central vertical & horizontal lines are drawn explicitly,
         8 each line can be defined using a 16-bit data value.
         9 
        10 Option 1:
        11 Define each line of snowflake as a 16-bit data value.
        12 Code needs 1 scan to traverse data forwards.
        13 Data needed for whole pattern.
        14 Code size: 64 words (128 bytes)
        15 
        16 Option 2 (used here):
        17 Split pattern horizontally into 2 halves, and just
        18 define the top half using a set of 16-bit values.
        19 Code needs 2 scans to traverse data forwards and backwards.
        20 Data needed for 1/2 of the pattern.
        21 Code size: 60 words (120 bytes)
        22 
        23 Option 3:
        24 Split pattern into 4 quadrants and just define the
        25 top-left section using a set of 8-bit data values.
        26 Code needs 4 scans to traverse data in forwards
        27 and backwards combinations.
        28 Data needed for 1/4 of the pattern.
        29 Not yet tried; PleX is word-based (16-bits) so this option
        30 will probably be larger than the others.
        31 
        32 Register usage:
        33 r0 - @pattern
        34 r1 - char count
        35 r2 - line count
        36 r3 - char to draw
        37 r4 - boolean to scan forwards or reverse
        38 r5 - star char (TEST only)
        39 }
        40 
        41 #USE_PRINTER 0 ;0 for oper, 1 for printer equ $0000
        42 #TEST 0 ;uses different char on each line to check wrap-round
        42                                           equ $0000
        43 
        44 #STAR '*                                  equ $002A
        45 #SPACE OP_CH_SPACE                        equ $0020
        46 #MAX_WIDTH 19                             equ $0013
        47 #MAX_CHARS MAX_WIDTH - 3 ;allow for central lines being longer
        47                                           equ $0010
        48 #MID_POINT MAX_WIDTH / 2                  equ $0009
        49 #MAX_LINES 9 ;top half excluding central horiz line
        49                                           equ $0009
        50 
        51 %m $10                                          mem 0010
        52   movs r4 0                                         0010 0280
        53   mov r0 pattern ;@top half of snowflake            0011 103C
        53                                                     0012 0043
        54 ?TEST mov r5 'A                                  - 
        55 :out_patt                                slab $0013
        56   movs r2 MAX_LINES                                 0013 0249
        57 .nxt_line                                 lab $0014
        58   callrs out.space ;start of each line              0014 E0A4
        59   mov r1 MAX_CHARS                                  0015 113C
        59                                                     0016 0010
        60 .nxt_ch                                   lab $0017
        61   rotls @r0 1 ;C is set if ms-bit is 1              0017 0A11
        62   callrs out ;draw star or space                    0018 E09F
        63 
        64 	;draw extra star at mid-point of line
        65 	;this forms central vertical line
        66   cmps r1 MID_POINT                                 0019 0C29
        67   callrs.z out.star                                 001A E3A1
        68   dec r1                                            001B 0621
        69   jmprs.nz nxt_ch                                   001C EB7B
        70 
        71   callrs out.space ;draw blank at end of each line  001D E09B
        72   callrs nl                                         001E E093
        73 
        74 	;check scan direction to inc/dec pattern line pointer
        75   cmps r4 0                                         001F 0C80
        76   jmprs.z scan_fwd                                  0020 E302
        77 .scan_rev                                 lab $0021
        78   subs r0 2 ;avoid jump over inc                    0021 0602
        79 .scan_fwd                                 lab $0022
        80   inc r0                                            0022 0401
        81 .end_line                                 lab $0023
        82 ?TEST inc r5                                     - 
        83   dec r2                                            0023 0641
        84   jmprs.nz nxt_line                                 0024 EB70
        85 
        86   cmps r4 0                                         0025 0C80
        87   jmprs.z top_done                                  0026 E302
        88 	;bottom done, all finished
        89   hlt                                               0027 0000
        90 
        91 .top_done                                 lab $0028
        92 	;draw horizontal line at halfway point
        93   mov r1 MAX_WIDTH                                  0028 113C
        93                                                     0029 0013
        94 .nxt_ch_central                           lab $002A
        95   callrs out.star                                   002A E091
        96   dec r1                                            002B 0621
        97   jmprs.nz nxt_ch_central                           002C EB7E
        98   callrs nl                                         002D E084
        99 
       100 	;draw bottom half by scanning pattern in reverse order
       101   dec r0 ;@end of top half of snowflake             002E 0601
       102   inc r4 ;set boolean to scan in reverse            002F 0481
       103   jmprs out_patt                                    0030 E063
       104 
       105 :nl                                      slab $0031
       106 .wait                                     lab $0031
       107 ?USE_PRINTER sys LP_STAT                         - 
       108 ?!USE_PRINTER sys OP_STAT                           0031 009E
       108                                                     0032 2000
       109   jmprs.z wait                                      0033 E37E
       110 ?USE_PRINTER sys LP_WR_LIT | LP_CH_CR            - 
       111 ?!USE_PRINTER sys OP_WR_NL                          0034 009E
       111                                                     0035 2410
       112   ret                                               0036 F03A
       113 
       114 :out                                     slab $0037
       115   jmprs.c star                                      0037 E204
       116 .space                                    lab $0038
       117   mov r3 SPACE                                      0038 133C
       117                                                     0039 0020
       118   jmprs wait                                        003A E003
       119 .star                                     lab $003B
       120 ?TEST mov r3 r5                                  - 
       121 ?!TEST mov r3 STAR                                  003B 133C
       121                                                     003C 002A
       122 .wait                                     lab $003D
       123 ?USE_PRINTER sys LP_STAT                         - 
       124 ?!USE_PRINTER sys OP_STAT                           003D 009E
       124                                                     003E 2000
       125   jmprs.z wait                                      003F E37E
       126 ?USE_PRINTER sys LP_WR_R | $3                    - 
       127 ?!USE_PRINTER sys OP_WR_CH_R | $3                   0040 009E
       127                                                     0041 2403
       128   ret                                               0042 F03A
       129 
       130 ::                                       slab -
       131 
       132 %d                                             data
       133 ;top half of snowflake
       134 .pattern                                  lab $0043
       135   $0000                                             0043 0000
       136   $0240                                             0044 0240
       137   $518A                                             0045 518A
       138   $300C                                             0046 300C
       139   $724E                                             0047 724E
       140   $0990                                             0048 0990
       141   $0420                                             0049 0420
       142   $9249                                             004A 9249
       143   $4992                                             004B 4992
       144 
       145 %is "PleX-Functions.pls"                  inc silent
      i1.0 inc lines suppressed
    i1.429                                           inc end


* Seems ok, mem used: 60 words from $10-$4B

Media stats:
P Tape 8-bit: 3-LogikerChallenge-2025-3043.pl8: chrs $0078
