Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lda #0
- sta $0
- lda #2
- sta $1
- lda #0 ;debug counter
- sta $11
- lda #2
- sta $12
- ;====================================================
- loopOne:
- lda $FE
- and #1
- sta ($0),y
- clc
- lda $0
- adc #1
- sta $0
- lda $1
- adc #0
- sta $1
- cmp #6
- beq memoryFilled
- jmp loopOne
- ;====================================================
- memoryFilled:
- jsr resetEverything
- notDoneYet:
- jsr countLife ;count life around cell
- lda ($0),y
- cmp #1
- beq cellWasAlive
- ;otherwise, the cell is NOT living
- jsr currentCellDead
- jmp cellChecked
- cellWasAlive:
- jsr currentCellAlive
- jmp cellChecked
- cellChecked:
- ;jsr debug
- sta ($4),y ;Store final cell checked value in the buffer
- jsr incrementPointers
- lda $1
- cmp #6
- beq doneNow
- ;it was not equal, jump back
- jmp notDoneYet
- doneNow: ;here lies the rub, done now is not jumping here properly
- jsr resetEverything
- jsr copyNewBuffer
- jmp memoryFilled
- ;reset stuff, including $10
- ;====================================================
- resetEverything:
- lda #0 ;screen pointer
- sta $0
- lda #2
- sta $1
- lda #0 ;screen reading pointer
- sta $2
- lda #2
- sta $3
- lda #0 ;buffer pointer
- sta $4
- lda #$10
- sta $5
- lda #0 ;life count
- sta $10
- rts
- ;====================================================
- countLife:
- ;center screen reading pointer
- lda $0
- sta $2
- lda $1
- sta $3
- ;TODO!!
- ;since the data is all in one stream, we need to account for the fact that
- ;the map is 2d, and wraps around every 32 pixels.
- ;if cell is far left, don't calculate up left, left, or down left
- ;if cell is far right, don't calculate up right, right, or down right
- ldx #0
- ;x--
- ;---
- ;---
- sec
- lda $2
- sbc #33 ;move up one row, left a column
- sta $2
- lda $3
- sbc #0 ;carry subtract
- sta $3
- jsr addLife
- ;-x-
- ;---
- ;---
- clc
- lda $2
- adc #1 ;move right one
- sta $2
- lda $3
- adc #0
- sta $3
- jsr addLife
- ;--x
- ;---
- ;---
- clc
- lda $2
- adc #1 ;move right one
- sta $2
- lda $3
- adc #0
- sta $3
- jsr addLife
- ;center screen reading pointer
- lda $0
- sta $2
- lda $1
- sta $2
- ;---
- ;x--
- ;---
- sec
- lda $2
- sbc #1 ;move left one
- sta $2
- lda $3
- sbc #0 ;carry subtract
- sta $3
- jsr addLife
- ;---
- ;--x
- ;---
- clc
- lda $2
- adc #2 ;move right two
- sta $2
- lda $3
- adc #0
- sta $3
- jsr addLife
- ;center screen reading pointer
- lda $0
- sta $2
- lda $1
- sta $2
- ;---
- ;---
- ;x--
- clc
- lda $2
- adc #31 ;move down one, left one
- sta $2
- lda $3
- adc #0
- sta $3
- jsr addLife
- ;---
- ;---
- ;-x-
- clc
- lda $2
- adc #1 ;move right one
- sta $2
- lda $3
- adc #0
- sta $3
- jsr addLife
- ;---
- ;---
- ;--x
- clc
- lda $2
- adc #1 ;move right one
- sta $2
- lda $3
- adc #0
- sta $3
- jsr addLife
- rts
- ;====================================================
- addLife:
- lda ($2),y
- cmp #1
- bne noLife
- inc $10
- noLife:
- rts
- ;====================================================
- currentCellDead:
- ; If there are 3 neighboring cells, it is alive
- ; Any other case, it is dead.
- lda $10
- cmp #3
- beq deadCellAlive
- ;no? then it's dead.
- lda #0
- jmp currentCellDeadEnd
- deadCellAlive:
- lda #1
- jmp currentCellDeadEnd
- currentCellDeadEnd:
- rts
- ;====================================================
- currentCellAlive:
- lda $10
- ;useless notes - cmp actually compares and sets flags as if
- ;subtract had taken place... so if it's equal, carry flag will
- ;be set, and the equal flag will be set. If it's more than,
- ;just the carry flag will be set. If it's less than, none
- ;of the flags will be set.
- ; Any live cell with fewer than two live neighbours dies,
- ; Any live cell with two or three live neighbours lives
- ; Any live cell with more than three live neighbours dies
- cmp #2
- bcs cellEQGT2
- ;less than 2, cell dies
- lda #0
- jmp currentCellAliveEnd
- cellEQGT2:
- BNE cellGT2
- ;equal to 2, cell lives
- lda #1
- jmp currentCellAliveEnd
- cellGT2:
- cmp #3
- bne cellGT3
- ;equal to 3, cell lives
- lda #1
- jmp currentCellAliveEnd
- cellGT3:
- ;greater than 3, cell dies
- lda #0
- jmp currentCellAliveEnd
- currentCellAliveEnd:
- rts
- ;====================================================
- incrementPointers:
- clc
- lda $0 ;increment screen pointer
- adc #1
- sta $0
- lda $1
- adc #0
- sta $1
- clc
- lda $4 ;increment buffer pointer
- adc #1
- sta $4
- lda $5
- adc #0
- sta $5
- rts
- ;====================================================
- copyNewBuffer:
- lda ($4),y
- sta ($0),y
- jsr incrementPointers
- lda $1
- cmp #6
- bne copyNewBuffer
- rts
- debug:
- lda #$d
- sta ($11),y
- inc $11
- rts
Add Comment
Please, Sign In to add comment