life-sketch.lst

life-sketch.lst (10388 bytes)

 AS V1.42 Beta [Bld 300] - Source File life-sketch.s - Page 1 - 10/15/2026 06:45:56 PM


    1/   0 :                                org 0
    2/   0 :                            bits_old:
    3/   0 : 00 00                          dw 0
    4/   2 :                            neighbor_count:
    5/   2 : 00                             db 0
    6/   3 :                            tmp:
    7/   3 : 00                             db 0
    8/   4 :                            
    9/ 200 :                                org $200
   10/ 200 :                            
   11/ 200 :                            get_cell:
   12/ 200 :                                ; assumes: ZP "bits_old" points at the right location
   13/ 200 :                                ; input: Linear cell # in A. (OR possibly the X-coordinate if 32x16, Y coordinate accounted in  bits_old)
   14/ 200 :                                ; output: Carry set if cell is live
   15/ 200 :                                ; destroys x, y
   16/ 200 :                                ; caller can then restore its neighbor count (LDA doesn't set C) and ADC #$0 to increment it or not
   17/ 200 : AA                             tax         ; we need a copy later
   18/ 201 : 29 07                          and #$7
   19/ 203 : A8                             tay         ; now y has the shift distance
   20/ 204 :                            
   21/ 204 : 8A                             txa         ; told ya
   22/ 205 : 4A                             lsr
   23/ 206 : 4A                             lsr
   24/ 207 : 4A                             lsr         ; shift out the low bits
   25/ 208 : AA                             tax         ; now x has the offset of the byte of interest
   26/ 209 : B5 00                          lda bits_old,x   ; now a register has the relevant byte
   27/ 20B :                            
   28/ 20B :                            get_cell_loop:  ; shift 1 to 8 times (not 0 to 7) so relevant bit is in carry
   29/ 20B : 0A                             asl
   30/ 20C : 88                             dey
   31/ 20D : D0 FC                          bne get_cell_loop
   32/ 20F :                                
   33/ 20F : 60                             rts
   34/ 210 :                            
   35/ 210 :                            census_cell:
   36/ 210 :                                ; input: Linear cell # in A
   37/ 210 :                                ; side effect: updates neighbor_count
   38/ 210 :                                ; output: the new value of neighbor_count is in A -- this property is not used
   39/ 210 :                                ; stack used: 2
   40/ 210 :                                ; destroys all registers
   41/ 210 : 20 00 02                       jsr get_cell
   42/ 213 : A5 02                          lda neighbor_count
   43/ 215 : 69 00                          adc #$0
   44/ 217 : 85 02                          sta neighbor_count
   45/ 219 : 60                             rts
   46/ 21A :                            
   47/ 21A :                            ; These move routines are for 16x16 boards, not 32x32
   48/ 21A :                            move_up:
   49/ 21A :                                ; input: Linear cell# in A
   50/ 21A :                                ; output: new linear cell# in A
   51/ 21A : 18                             clc
   52/ 21B : E9 10                          sbc #16
   53/ 21D : 60                             rts
   54/ 21E :                            
   55/ 21E :                            move_down:
   56/ 21E :                                ; input: Linear cell# in A
   57/ 21E :                                ; output: new linear cell# in A
   58/ 21E : 18                             clc
   59/ 21F : E9 10                          sbc #16
   60/ 221 : 60                             rts
 AS V1.42 Beta [Bld 300] - Source File life-sketch.s - Page 2 - 10/15/2026 06:45:56 PM


   61/ 222 :                            
   62/ 222 :                            move_right:
   63/ 222 :                                ; input: Linear cell# in A
   64/ 222 :                                ; output: new linear cell# in A
   65/ 222 :                                ; destroys: x, y, tmp
   66/ 222 : A8                             tay
   67/ 223 : 29 F0                          and #$F0
   68/ 225 : 85 03                          sta tmp
   69/ 227 : 98                             tya
   70/ 228 : 18                             clc
   71/ 229 : 69 01                          adc #01     ; no inc a!!
   72/ 22B : 29 0F                          and #$0F
   73/ 22D : 05 03                          ora tmp
   74/ 22F :                            
   75/ 22F : 60                             rts
   76/ 230 :                            
   77/ 230 :                            move_left:
   78/ 230 :                                ; input: Linear cell# in A
   79/ 230 :                                ; output: new linear cell# in A
   80/ 230 :                                ; destroys: tmp
   81/ 230 :                                ; stack used: 1
   82/ 230 : 48                             pha
   83/ 231 : 29 F0                          and #$F0
   84/ 233 : 85 03                          sta tmp
   85/ 235 : 68                             pla
   86/ 236 : 18                             clc         ; no dec a!!
   87/ 237 : E9 01                          sbc #01
   88/ 239 : 29 0F                          and #$0F
   89/ 23B : 05 03                          ora tmp
   90/ 23D :                            
   91/ 23D : 60                             rts
   92/ 23E :                            
   93/ 23E :                            compute_cell:
   94/ 23E : A2 00                          ldx #0
   95/ 240 : 86 02                          stx neighbor_count
   96/ 242 : 20 30 02                       jsr move_left
   97/ 245 : 20 10 02                       jsr census_cell
   98/ 248 : 20 1A 02                       jsr move_up
   99/ 24B : 20 10 02                       jsr census_cell
  100/ 24E : 20 22 02                       jsr move_right
  101/ 251 : 20 10 02                       jsr census_cell
  102/ 254 : 20 22 02                       jsr move_right
  103/ 257 : 20 10 02                       jsr census_cell
  104/ 25A : 20 1E 02                       jsr move_down
  105/ 25D : 20 10 02                       jsr census_cell
  106/ 260 : 20 1E 02                       jsr move_down
  107/ 263 : 20 10 02                       jsr census_cell
  108/ 266 : 20 30 02                       jsr move_left
  109/ 269 : 20 10 02                       jsr census_cell
  110/ 26C : 20 30 02                       jsr move_left
  111/ 26F : 20 10 02                       jsr census_cell
  112/ 272 : 20 1A 02                       jsr move_up
  113/ 275 : 20 10 02                       jsr census_cell
  114/ 278 : 20 1A 02                       jsr move_up
  115/ 27B : 20 10 02                       jsr census_cell
  116/ 27E :                            
  117/ 27E : 20 22 02                       jsr move_right
  118/ 281 : 20 00 02                       jsr get_cell
  119/ 284 : A9 00                          lda #0
  120/ 286 : 69 00                          adc #0                  ; a now holds 0 if dead, 1 if live. **CARRY IS CLEAR**
 AS V1.42 Beta [Bld 300] - Source File life-sketch.s - Page 3 - 10/15/2026 06:45:56 PM


  121/ 288 : 05 02                          ora neighbor_count      ; a now holds neighbor_count if dead, or neighbor_count | 1 if live, so 2->3 if live
  122/ 28A : C9 03                          cmp #3                  ; now if should live or be born, A has 0
  123/ 28C : A9 00                          lda #0
  124/ 28E : E9 00                          sbc #0                  ; CF has "should live or be born"
  125/ 290 :                                ; fall through to put cell
  126/ 290 :                            
  127/ 290 :                            
  128/ 290 :                            put_cell:
  129/ 290 :                                ; to be done
  130/ 290 :                                ; input: CF flag for new cell live/dead status
  131/ 290 :                                ; notes: if you assume that cells are always put in order .. 
  132/ 290 :                                ; preload a byte with #$01 (or maybe #$80? depending on shift direction) and shift each new bit in
  133/ 290 :                                ; as soon as you *shift out* a 1 into carry, you need to go on to the next byte
  134/ 290 : 00                             brk
  135/ 291 :                            
 AS V1.42 Beta [Bld 300] - Source File life-sketch.s - Page 4 - 10/15/2026 06:45:56 PM


  Symbol Table (* = unused):
  --------------------------

*ARCHITECTURE :                                      "x86_64-unknown-linux" - |
 BITS_OLD :                       0 C | *CASESENSITIVE :                  0 - |
 CENSUS_CELL :                  210 C | *COMPUTE_CELL :                 23E C |
*CONSTPI :     3.141592653589793239 - | *DATE :                "10/15/2026" - |
*FALSE :                          0 - | *FLOATMAX :   1.18973149535725E4932 - |
 GET_CELL :                     200 C |  GET_CELL_LOOP :                20B C |
*HAS64 :                          1 - | *INTWIDTH :                      80 - |
*LISTON :                         1 - | *MACEXP :                         7 - |
*MOMCPU :                      6502 - | *MOMCPUNAME :                "6502" - |
 MOVE_DOWN :                    21E C |  MOVE_LEFT :                    230 C |
 MOVE_RIGHT :                   222 C |  MOVE_UP :                      21A C |
 NEIGHBOR_COUNT :                 2 C | *NESTMAX :                      100 - |
*PUT_CELL :                     290 C | *RELAXED :                        0 - |
*TIME :               "06:45:56 PM" - |  TMP :                            3 C |
*TRUE :                           1 - | *VERSION :                     142F - |

     29 symbols
     19 unused symbols

 AS V1.42 Beta [Bld 300] - Source File life-sketch.s - Page 5 - 10/15/2026 06:45:56 PM


  Code Pages:
  ----------

STANDARD (0 changed characters)

1 code page

0.00 seconds assembly time

    135 lines source file
      1 pass
      0 errors
      0 warnings

life-sketch.s

life-sketch.s (3065 bytes)

    org 0
bits_old:
    dw 0
neighbor_count:
    db 0
tmp:
    db 0

    org $200

get_cell:
    ; assumes: ZP "bits_old" points at the right location
    ; input: Linear cell # in A. (OR possibly the X-coordinate if 32x16, Y coordinate accounted in  bits_old)
    ; output: Carry set if cell is live
    ; destroys x, y
    ; caller can then restore its neighbor count (LDA doesn't set C) and ADC #$0 to increment it or not
    tax         ; we need a copy later
    and #$7
    tay         ; now y has the shift distance

    txa         ; told ya
    lsr
    lsr
    lsr         ; shift out the low bits
    tax         ; now x has the offset of the byte of interest
    lda bits_old,x   ; now a register has the relevant byte

get_cell_loop:  ; shift 1 to 8 times (not 0 to 7) so relevant bit is in carry
    asl
    dey
    bne get_cell_loop

    rts

census_cell:
    ; input: Linear cell # in A
    ; side effect: updates neighbor_count
    ; output: the new value of neighbor_count is in A -- this property is not used
    ; stack used: 2
    ; destroys all registers
    jsr get_cell
    lda neighbor_count
    adc #$0
    sta neighbor_count
    rts

; These move routines are for 16x16 boards, not 32x32
move_up:
    ; input: Linear cell# in A
    ; output: new linear cell# in A
    clc
    sbc #16
    rts

move_down:
    ; input: Linear cell# in A
    ; output: new linear cell# in A
    clc
    sbc #16
    rts

move_right:
    ; input: Linear cell# in A
    ; output: new linear cell# in A
    ; destroys: x, y, tmp
    tay
    and #$F0
    sta tmp
    tya
    clc
    adc #01     ; no inc a!!
    and #$0F
    ora tmp

    rts

move_left:
    ; input: Linear cell# in A
    ; output: new linear cell# in A
    ; destroys: tmp
    ; stack used: 1
    pha
    and #$F0
    sta tmp
    pla
    clc         ; no dec a!!
    sbc #01
    and #$0F
    ora tmp

    rts

compute_cell:
    ldx #0
    stx neighbor_count
    jsr move_left
    jsr census_cell
    jsr move_up
    jsr census_cell
    jsr move_right
    jsr census_cell
    jsr move_right
    jsr census_cell
    jsr move_down
    jsr census_cell
    jsr move_down
    jsr census_cell
    jsr move_left
    jsr census_cell
    jsr move_left
    jsr census_cell
    jsr move_up
    jsr census_cell
    jsr move_up
    jsr census_cell

    jsr move_right
    jsr get_cell
    lda #0
    adc #0                  ; a now holds 0 if dead, 1 if live. **CARRY IS CLEAR**
    ora neighbor_count      ; a now holds neighbor_count if dead, or neighbor_count | 1 if live, so 2->3 if live
    cmp #3                  ; now if should live or be born, A has 0
    lda #0
    sbc #0                  ; CF has "should live or be born"
    ; fall through to put cell


put_cell:
    ; to be done
    ; input: CF flag for new cell live/dead status
    ; notes: if you assume that cells are always put in order .. 
    ; preload a byte with #$01 (or maybe #$80? depending on shift direction) and shift each new bit in
    ; as soon as you *shift out* a 1 into carry, you need to go on to the next byte
    brk