Prev: 9AA9 Up: Map Next: 9B0C
9AB4: Play one note on the beeper
Used by the routines at play_tune_until_key and play_tune.
A note is a byte: bits 0-5 the note (0 a rest), bits 6-7 its length less one, in units. A note's entry in note_table gives the half-period as a delay count and the number of cycles in one unit; the beeper is toggled between $00 and $10 (black border throughout) for length times that many cycles. A rest waits about 0.13 seconds a unit.
Input
A The note
DE The tune, at the note
Output
DE The next note
play_note 9AB4 AND $3F The note's entry
9AB6 JR Z,play_note_5
9AB8 LD L,A
9AB9 LD H,$00
9ABB ADD HL,HL
9ABC CALL add_a_to_hl
9ABF LD BC,note_table
9AC2 ADD HL,BC
9AC3 LD B,(HL) Delay count (B, C) and cycles in a unit
9AC4 INC HL
9AC5 LD C,(HL)
9AC6 INC HL
9AC7 LD L,(HL)
9AC8 LD H,$00
9ACA LD A,(DE) Times the length
9ACB RLCA
9ACC RLCA
9ACD AND $03
9ACF INC A
9AD0 PUSH DE
9AD1 LD E,L
9AD2 LD D,H
play_note_0 9AD3 DEC A
9AD4 JR Z,play_note_1
9AD6 ADD HL,DE
9AD7 JR play_note_0
play_note_1 9AD9 POP DE
play_note_2 9ADA PUSH BC Half a cycle low...
9ADB XOR A
9ADC OUT ($FE),A
play_note_3 9ADE DJNZ play_note_3
9AE0 DEC C
9AE1 JR NZ,play_note_3
9AE3 POP BC ...and half high
9AE4 PUSH BC
9AE5 LD A,$10
9AE7 OUT ($FE),A
play_note_4 9AE9 DJNZ play_note_4
9AEB DEC C
9AEC JR NZ,play_note_4
9AEE POP BC Until the cycles are done
9AEF DEC HL
9AF0 LD A,H
9AF1 OR L
9AF2 JR NZ,play_note_2
9AF4 INC DE
9AF5 RET
play_note_5 9AF6 LD A,(DE) A rest: about 0.13 seconds a unit
9AF7 INC DE
9AF8 RLCA
9AF9 RLCA
9AFA AND $03
9AFC INC A
9AFD LD L,A
9AFE LD BC,$430B
play_note_6 9B01 PUSH BC
play_note_7 9B02 DEC BC
9B03 LD A,B
9B04 OR C
9B05 JR NZ,play_note_7
9B07 POP BC
9B08 DEC L
9B09 JR NZ,play_note_6
9B0B RET
Prev: 9AA9 Up: Map Next: 9B0C