The question you are now reading is about a comment on this question, about overflow bugs in some Pokemon game. A comment on that question says:
It was Game Freak's first project. They just were sloppy programmers. This function merely divides by four, in the usual Game Freak style of doing things.
; 92bbe (24:6bbe) Unreferenced_Function92bbe: ; 92bbe push hl srl a srl a add LOW(.Unknown_92bce) ld l, a ld a, 0 adc HIGH(.Unknown_92bce) ld h, a ld a, [hl] pop hl ret ; 92bce .Unknown_92bce: ; 92bce db 0, 1, 2, 3, 4, 5
It starts off by saving HL, and I can see it restores HL at the end. That's because it uses HL to construct some kind of pointer which is discarded at the end.
srl a is obviously going to divide
a by two, so doing that twice should divide it by four! The next thing should be to restore HL (or not push it in the first place) and the return, right?
But it's hardly worth putting just
srl a;srl a in a subroutine. So there's more: from what I can see, it's computing a pointer to the array marked
.Unknown_92bce offset by the accumulator. In other words, it's going to use the value in the accumulator to look up ... the value in the accumulator. If the accumulator is
3 for example, then fetch
3 from the array.
And then obviously it restores
hl and returns.
Am I missing something? Is this subroutine equivalent to the following?
Unreferenced_Function92bbe: srl a srl a ret