-
Notifications
You must be signed in to change notification settings - Fork 41
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
gb: add delay and memcpy detection #95
Comments
Busy loops.wait
dec a
jr nz, .wait memcpy routinesCopyData::
; Copy bc bytes from hl to de.
ld a, [hli]
ld [de], a
inc de
dec bc
ld a, c
or b
jr nz, CopyData
ret from https://github.com/pret/pokered/blob/30c244ae4f1acc6f018499ceaa9b138367d7bedf/home/copy.asm#L15 Also: ; Copy bytes from one area to another.
; @param de: Source
; @param hl: Destination
; @param bc: Length
Memcopy:
ld a, [de]
ld [hli], a
inc de
dec bc
ld a, b
or a, c
jp nz, Memcopy
ret from https://gbdev.io/gb-asm-tutorial/part2/functions.html Another example that can only copy up to 255 bytes. .loop
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .loop
ret from https://github.com/pret/pokered/blob/30c244ae4f1acc6f018499ceaa9b138367d7bedf/home/vcopy.asm#L439 Also: .loop_17:
ld a, [de]
ld [hl], a
inc l
inc e
dec b
jr nz, .loop_17 Also: COPY_TILES::
ldi a, [hl]
ld [de], a
inc de
dec bc
ld a, b
or c
jr nz, COPY_TILES memset routines.loop
ld [hli], a
dec c
jr nz, .loop
dec b
jr nz, .loop
jp Delay3 from https://github.com/pret/pokered/blob/30c244ae4f1acc6f018499ceaa9b138367d7bedf/home/copy2.asm#L180 Also: .x
ld [hli], a
dec c
jr nz, .x .x
ld [hli], a
dec b
jr nz, .x strcpy routines; copies a string from de to hl
CopyString::
ld a, [de]
inc de
ld [hli], a
cp "@"
jr nz, CopyString
ret |
Possible elimination of register checks in loops? .x:
ld a, [$FF00+$41]
and $03
jr nz, .x |
If the routine is in WRAM or HRAM, than the first instruction in the routine could be changed to an invalid instruction that could then be hijacked into a memcpy or memset instruction. |
Add detection of busy loops, or loops that wait for a status. Such loops may include:
A use case is where the emulation speed can be increased because all ROMs perform at least one of the tasks written above in some cases. Instead of executing each task instruction by instruction, a look-ahead should be used to determine whether the task can be performed with high-level emulation instead (eg. calling memcpy() in peanut-gb).
The text was updated successfully, but these errors were encountered: