Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ResetBoard:
- ld hl,Board
- ld de,Board+1
- ld bc,BoardSize-1
- ld a,OffCellData
- ld (hl),a
- ldir
- ; ld de,BgColor
- ; call ChangeRectColor
- ld de,0 ; X
- ld l,0 ; Y
- ld bc,320 ; Width
- ld h,240 ; Height
- ld a,BgColor
- call FillRect
- call RenderBoard
- ld bc,(Rows/2)*256+Cols/2
- ld.sis (Cursor-M),bc
- call DrawCursor
- xor a ; Prevent accidental "keypresses"
- ret
- ResetBoard2:
- ld hl,NewBoard
- ld de,NewBoard+1
- ld bc,BoardSize-1
- xor a
- ld (hl),a
- ldir
- ret
- LdBoard:
- ; DE = mem loc of board to load
- ; DE and HL are sorta switched; DE is the source and HL is the destination
- ld hl,Board
- ld bc,BoardSize/8
- LdBoard_Loop:
- push bc
- ld a,(de)
- bit 0,a
- call z,LdBoard_On
- inc hl
- bit 1,a
- call z,LdBoard_On
- inc hl
- bit 2,a
- call z,LdBoard_On
- inc hl
- bit 3,a
- call z,LdBoard_On
- inc hl
- bit 4,a
- call z,LdBoard_On
- inc hl
- bit 5,a
- call z,LdBoard_On
- inc hl
- bit 6,a
- call z,LdBoard_On
- inc hl
- bit 7,a
- call z,LdBoard_On
- inc hl
- inc de
- pop bc
- dec bc
- jp nz,LdBoard_Loop
- jp RenderBoard
- LdBoard_On:
- ld (hl),OnCellData
- ret
- LdBoard_Off:
- ld (hl),OffCellData
- ret
- SpreadToAdj:
- call SafeDecX
- call IncCell
- call SafeDecY
- call IncCell
- call SafeIncX
- call IncCell
- call SafeIncX
- call IncCell
- call SafeIncY
- call IncCell
- call SafeIncY
- call IncCell
- call SafeDecX
- call IncCell
- call SafeDecX
- jp IncCell
- IncCell:
- call GetCell
- ld de,NewBoard-Board
- add hl,de
- inc (hl)
- ret
- ConwayCell: ; Evaluates a cell at x=b, y=c and redraws (must call GetCell first); destroys AF, BC
- push hl
- ld de,NewBoard-Board
- add hl,de
- ld a,(hl)
- pop hl
- cp 3 ; Compare A (neighboring cells) to 3
- jp z,CellOn ; If A=3, CellOn
- jp nc,CellOff ; ElseIf A >= 3, CellOff (A must be >3, because it can't equal 3)
- cp 2 ; Compare A to 2
- jp c,CellOff ; If A<2, CellOff
- ret ; If A=2, keep current state (on or off)
- CellOn:
- ld a,(hl)
- cp OnCellData
- ret z
- ld a,OnCellData
- ld (hl),a
- ld a,OnCellColor
- jp DrawCell
- CellOff:
- ld a,(hl)
- cp OffCellData
- ret z
- ld a,OffCellData
- ld (hl),a
- ld a,OffCellColor
- jp DrawCell
- GetCell: ; Stores the memory location of the cell at x=b, y=c into HL; destroys HL, DE
- push bc
- dec b
- dec c
- or a ; maybe not needed?
- sbc hl,hl
- ld l,c
- add hl,hl ; x2
- add hl,hl ; x4
- add hl,hl ; x8
- push hl
- pop de
- add hl,hl ; x16
- add hl,hl ; x32
- add hl,de ; x40
- ld de,0
- ld e,b
- add hl,de
- ld de,Board
- add hl,de
- pop bc
- ret
- ; *
- ; * MATH STUFF
- ; *
- AMult8: ; Multiplies A by 8
- sla a ; x2
- sla a ; x4
- sla a ; x8
- ret
- HLMult8: ; Multiplies HL by 8
- add hl,hl ; x2
- add hl,hl ; x4
- add hl,hl ; x8
- ret
- HLMult10: ; Multiplies HL by 10
- add hl,hl ; x2
- push hl
- pop de
- add hl,hl ; x4
- add hl,hl ; x8
- add hl,de ; x10
- ret
- ; AMult5: ; Multiplies A by 5
- ; push bc
- ; ld b,a
- ; sla a
- ; sla a
- ; add a,b
- ; pop bc
- ; ret
- ; HLMult5: ; Multiplies HL by 5
- ; push bc
- ; ld b,h
- ; ld c,l
- ; add hl,hl
- ; add hl,hl
- ; add hl,bc
- ; pop bc
- ; ret
- SafeIncX:
- ld a,b
- inc a
- cp Cols+1
- jp nc,Min_X
- ld b,a
- ret
- Min_X:
- ld b,1
- ret
- SafeIncY:
- ld a,c
- inc a
- cp Rows+1
- jp nc,Min_Y
- ld c,a
- ret
- Min_Y:
- ld c,1
- ret
- SafeDecX:
- dec b
- jp z,Max_X
- ret
- Max_X:
- ld b,Cols
- ret
- SafeDecY:
- dec c
- jp z,Max_Y
- ret
- Max_Y:
- ld c,Rows
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement