UTF-8/게임보이/wla-dx

< UTF-8/게임보이
十八子(십팔자) (토론 | 기여)님의 2024년 3월 25일 (월) 00:45 판 (十八子님이 UTF-8/게임보이 문서를 넘겨주기를 만들지 않고 UTF-8/게임보이/wla-dx 문서로 이동했습니다)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

게임보이() UTF-8 디코딩 函數(함수). 出力(출력)은 레지스터 c, d, e에 UTF-32로 디코딩되어 나온다.

맨밑의 @nextByte는 다음 臺詞(대사) 바이트를 가져오는 役割(역할)을 하며, 게임마다 따로 具顯(구현)하여야 한다.

; @param b: Bank number to read from
; @param hl: Start address to read from
; @return c: Unicode codepoint, upper 1 byte
; @return de: Unicode codepoint, lower 2 bytes
decodeUTF8:
    ld c, $00
    ld d, $00

    call @nextByte

    bit 7, a
    jr z, @singleByte
    bit 5, a
    jr z, @doubleByte
    bit 4, a
    jr z, @tripleByte
    bit 3, a
    jr z, @quadByte
    jr @end

@singleByte:
    and a, $7f
    ld e, a
    jr @end

@doubleByte:
    push af
    and a, $1c
    rrca
    rrca
    ld d, a
    jr @lastByte

@tripleByte:
    and a, $0f
    rlca
    rlca
    rlca
    rlca
    ld d, a

    call @nextByte

    push af
    and a, $3c
    rrca
    rrca
    or d
    ld d, a

    jr @lastByte

@quadByte:
    and a, $07
    rlca
    rlca
    ld c, a

    call @nextByte

    push af
    and a, $30
    rrca
    rrca
    rrca
    rrca
    or c
    ld c, a

    pop af
    and a, $0f
    rlca
    rlca
    rlca
    rlca
    ld d, a

    call @nextByte

    push af
    and a, $3c
    rrca
    rrca
    or d
    ld d, a

    jr @lastByte

@lastByte:
    pop af
    and a, $03
    rrca
    rrca
    ld e, a

    call @nextByte

    and a, $3f
    or e
    ld e, a

@end:
    ret

;; Read next byte from hl, incrementing hl itself
@nextByte:
    ld a, :@nextByte
    call readByteFromBankAndReturn
    inc hl
    ret