Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Other Link Movement Functions (WIP) #2

Open
vulcandth opened this issue Aug 19, 2022 · 0 comments
Open

Other Link Movement Functions (WIP) #2

vulcandth opened this issue Aug 19, 2022 · 0 comments
Labels
enhancement New feature or request Link Movement Branch Issues with Link Movement

Comments

@vulcandth
Copy link
Owner

vulcandth commented Aug 19, 2022

LinkMovementCheckRoomInBuffer::
; Input: hl: ring buffer to store in.
; Output: de: Pointer to Head, Sets Z flag if no room.
; clobbers hl, a
	dec hl
	ld a, [hld]
	ld e, a
	ld a, [hld]
	ld d, a

	ld a, [hld]
	ld h, [hl]
	ld l, a

	ld a, l
	sub e
	ld l, a
	ld a, h
	sbc d
	ld h, a

	ld a, l
	cp 1 ; Sets Z flag if no room.
	ret

LinkMovementStoreByte::
	; Input: a: Byte to store, hl: ring buffer to store in. 
	; Output: Z flag if no room.
	; clobbers hl, de, b
	ld b, a
	push hl
	call LinkMovementCheckRoomInBuffer
	pop hl
	ret z

	inc de
	push hl
	ld a, 16
	add l
	ld l, a
	adc h
	sub l
	cp d
	jr nz, .continue
	ld a, l
	cp e
	jr nz, .continue
	ld hl, -16
	add de, hl
.continue
	pop hl

	dec hl
	ld a, e
	ld [hld], a
	ld a, d
	ld [hl], a
	ld a, b
	ld [de], a
	ret

LinkMovementCheckBufferEmpty::
; Input: hl: ring buffer to store in.
; Output: hl: Pointer to Head, Sets Z flag if no room.
; clobbers hl, a
	dec hl
	ld a, [hld]
	ld e, a
	ld a, [hld]
	ld d, a

	ld a, [hld]
	ld h, [hl]
	ld l, a

	ld a, e
	sub l
	ld e, a
	ld a, d
	sbc h
	ld d, a

	ld a, e
	cp 1 ; Sets Z flag if no room.
	ret

LinkMovementGetByte::
	; Input: hl: ring buffer to get byte from
	; Output: a: byte from buffer, Z flag if buffer is empty
	; clobbers hl, de, b
	push hl
	call LinkMovementCheckBufferEmpty
	pop de
	ret z

	dec 
	
	; WIP

	ret
@vulcandth vulcandth added the enhancement New feature or request label Aug 19, 2022
@vulcandth vulcandth added the Link Movement Branch Issues with Link Movement label Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Link Movement Branch Issues with Link Movement
Projects
None yet
Development

No branches or pull requests

1 participant