Skip to content

Commit

Permalink
Merge pull request #144 from ElectroDeoxys/master
Browse files Browse the repository at this point in the history
Document IR functions and misc fixes
  • Loading branch information
dannye authored Mar 21, 2024
2 parents edda25e + d64bd22 commit 3c907f7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/constants/hardware_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ DEF rHDMA4 EQU $ff54 ; CGB Mode Only - New DMA Destination, Low
DEF rHDMA5 EQU $ff55 ; CGB Mode Only - New DMA Length/Mode/Start

DEF rRP EQU $ff56 ; CGB Mode Only - Infrared Communications Port
DEF RPF_ENREAD EQU %11000000
DEF RPF_DATAIN EQU %00000010 ; 0=Receiving IR Signal, 1=Normal
DEF RPF_WRITE_HI EQU %00000001
DEF RPF_WRITE_LO EQU %00000000

DEF RPB_LED_ON EQU 0
DEF RPB_DATAIN EQU 1

DEF rBGPI EQU $ff68 ; CGB Mode Only - Background Palette Index
DEF rBGPD EQU $ff69 ; CGB Mode Only - Background Palette Data
Expand Down
5 changes: 4 additions & 1 deletion src/engine/link/card_pop.asm
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ LookUpNameInCardPopNameList:
.loop_other_card_pop_name_list
push hl
ld de, sPlayerName
call .CompareNames ; discards result from comparison
call .CompareNames
pop hl
; bug: discards result from comparison
; to fix, uncomment line below
; jr nc, .found_name
ld de, NAME_BUFFER_LENGTH
add hl, de
dec c
Expand Down
30 changes: 15 additions & 15 deletions src/engine/link/ir_core.asm
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
; if carry flag is set, only delays
; if carry not set:
; - set rRP to $c1, wait;
; - set rRP to $c0, wait;
; - set rRP edge up, wait;
; - set rRP edge down, wait;
; - return
Func_19674:
TransmitIRBit:
jr c, .delay_once
ld [hl], $c1
ld [hl], RPF_WRITE_HI | RPF_ENREAD
ld a, 5
jr .loop_delay_1 ; jump to possibly to add more cycles?
.loop_delay_1
dec a
jr nz, .loop_delay_1
ld [hl], $c0
ld [hl], RPF_WRITE_LO | RPF_ENREAD
ld a, 14
jr .loop_delay_2 ; jump to possibly to add more cycles?
.loop_delay_2
Expand All @@ -36,15 +36,15 @@ TransmitByteThroughIR:
push bc
ld b, a
scf ; carry set
call Func_19674
call TransmitIRBit
or a ; carry not set
call Func_19674
call TransmitIRBit
ld c, 8
ld c, 8 ; number of input bits
.loop
ld a, $00
rr b
call Func_19674
call TransmitIRBit
dec c
jr nz, .loop
pop bc
Expand All @@ -65,7 +65,7 @@ ReceiveByteThroughIR_ZeroIfUnsuccessful:
ret

; returns carry if there's some time out
; and output in register a of $ff
; and outputs $ff in register a
; otherwise returns in a some sequence of bits
; related to how rRP sets/unsets bit 1
ReceiveByteThroughIR:
Expand All @@ -78,7 +78,7 @@ ReceiveByteThroughIR:
ld b, 0
ld hl, rRP
.wait_ir
bit 1, [hl]
bit RPB_DATAIN, [hl]
jr z, .ok
dec b
jr nz, .wait_ir
Expand Down Expand Up @@ -112,11 +112,11 @@ ReceiveByteThroughIR:
; if in any of the checks it is unset,
; then a is set to 0
; this is done a total of 9 times
bit 1, [hl]
bit RPB_DATAIN, [hl]
jr nz, .asm_196ec
xor a
.asm_196ec
bit 1, [hl]
bit RPB_DATAIN, [hl]
jr nz, .asm_196f1
xor a
.asm_196f1
Expand All @@ -143,7 +143,7 @@ ReturnZFlagUnsetAndCarryFlagSet:
; called when expecting to transmit data
Func_19705:
ld hl, rRP
.asm_19708
.loop
ldh a, [rJOYP]
bit 1, a
jr z, ReturnZFlagUnsetAndCarryFlagSet
Expand All @@ -153,7 +153,7 @@ Func_19705:
pop hl
call ReceiveByteThroughIR_ZeroIfUnsuccessful
cp $33 ; acknowledge
jr nz, .asm_19708
jr nz, .loop
xor a
ret

Expand Down Expand Up @@ -244,7 +244,7 @@ StartIRCommunications:
call SwitchToCGBNormalSpeed
ld a, P14
ldh [rJOYP], a
ld a, $c0
ld a, RPF_ENREAD
ldh [rRP], a
ret

Expand Down

0 comments on commit 3c907f7

Please sign in to comment.