Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Flood:
- ;Inputs:
- ; HL points to the buffer (cannot be at saveSScreen)
- ; BC=(x,y)
- ;Needs these RAM addresses:
- ; TempWord1
- ; TempWord2
- ; TempWord3
- ld hl,(TempWord1)
- push bc
- ld de,86ECh
- xor a
- ld bc,768
- ld (de),a
- inc de
- dec c
- jr nz,$-3
- dec b
- jr nz,$-6
- pop bc
- push bc
- call GetPixelLoc
- pop bc
- ret nc
- ld de,(TempWord1)
- add hl,de
- and (hl)
- ret nz
- FloodFill:
- ld de,1 ;Direction
- ;DE is the direction (x,y)
- ;BC is the current coordinates
- FloodFillLoop:
- push bc
- call GetPixelLoc
- jr nc,ChangeDirection
- push hl
- push af
- ld bc,(TempWord1)
- add hl,bc
- and (hl)
- ld (TempWord3),hl
- pop hl
- ld a,h
- pop hl
- jr nz,ChangeDirection
- ld bc,86ECh
- add hl,bc
- ld b,a
- or (hl)
- ld (hl),a
- ld a,b
- ; ld bc,86ECh
- ; add hl,bc
- ; or (hl)
- ; ld (hl),a
- ; pop hl
- ; ld bc,(TempWord1)
- ; add hl,bc
- ; pop af
- ; ld b,a
- ; and (hl)
- ; ld a,b
- ; jr nz,ChangeDirection
- ld hl,(TempWord3)
- pop bc
- ld (TempWord2),bc
- or (hl)
- ld (hl),a
- FloodFillLoop0:
- ld a,d
- add a,b
- ld b,a
- ld a,e
- add a,c
- ld c,a
- jp FloodFillLoop
- ChangeDirection:
- pop bc
- ld bc,(TempWord2)
- ld a,d
- or a
- jr nz,UpDown
- call CheckLeftRight
- jp z,FloodFillLoop0
- jr NextPath
- UpDown:
- call CheckUpDown
- jp z,FloodFillLoop0
- NextPath:
- ld hl,86ECh
- xor a
- ld d,a
- ld e,a
- ld c,64
- ld b,12
- PathFind:
- cp (hl)
- jr z,$+15
- push bc
- push de
- push hl
- ld a,(hl)
- call PathFound
- pop hl
- jr z,PathSelected
- xor a
- pop de
- pop bc
- inc hl
- inc d
- djnz PathFind
- ld d,0
- inc e
- dec c
- jr nz,PathFind-2
- jp BufferToLCD
- PathSelected:
- pop hl
- pop hl
- jp FloodFillLoop0
- PathFound:
- ld c,e
- ld b,d
- sla b
- sla b
- sla b
- dec b
- ld a,(hl)
- FindXVal:
- inc b
- add a,a
- jr nc,$-2
- ld (TempWord2),a
- ld (TempWord3),bc
- ;Now BC has the adjusted coordinates
- call CheckLeftRight
- ret z
- call CheckUpDown
- ret z
- call GetPixelLoc
- ld bc,86ECh
- add hl,bc
- cpl
- and (hl)
- ld (hl),a
- ld a,(TempWord2)
- ld bc,(TempWord3)
- or a
- jr nz,FindXVal
- inc a
- ret
- CheckLeftRight:
- ld de,$FF00
- push bc
- dec b
- call GetPixelLoc
- jr nc,$+11
- ld bc,(TempWord1)
- add hl,bc
- and (hl)
- jr nz,$+4
- pop bc
- ret z
- pop bc
- ld d,1
- push bc
- inc b
- call GetPixelLoc
- jr nc,$+11
- ld bc,(TempWord1)
- add hl,bc
- and (hl)
- jr nz,$+4
- pop bc
- ret z
- inc b
- pop bc
- ret
- CheckUpDown:
- ld de,$00FF
- push bc
- dec c
- call GetPixelLoc
- jr nc,$+11
- ld bc,(TempWord1)
- add hl,bc
- and (hl)
- jr nz,$+4
- pop bc
- ret z
- pop bc
- ld e,1
- push bc
- inc c
- call GetPixelLoc
- jr nc,$+11
- ld bc,(TempWord1)
- add hl,bc
- and (hl)
- jr nz,$+4
- pop bc
- ret z
- inc c
- pop bc
- ret
- GetPixelLoc:
- ;Input:
- ; b is X
- ; c is y
- ;Output:
- ; HL points to byte
- ; A is the mask
- ; nc if not computed, c if computed
- ld a,c
- cp 64 \ ret nc
- ld a,b
- cp 96 \ ret nc
- ld l,c
- ld h,0
- ld b,h
- add hl,hl
- add hl,bc
- add hl,hl
- add hl,hl
- ld b,a
- rrca \ rrca \ rrca
- and 0Fh
- ld c,a
- ld a,b
- ld b,0
- add hl,bc
- and 7
- ld b,a
- inc b
- ld a,1
- rrca
- djnz $-1
- scf
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement