Prev: F953 Up: Map Next: FA2B
F9F3: White noise generator
Bank 7's own copy of F0C6, byte for byte identical to it apart from the two references to the <interrupt flag>, which point at this bank's copy at b7pm_wait_for_interrupt rather than the main bank's. Reached as instrument 3 from F893.
The disassembler took these 56 bytes for data; they are code.
Input
A Duration (3 or 9 in practice)
b7_play_noise F9F3 LD E,A Set E to duration counter
b7n_outer_loop F9F4 LD D,$32 Set D to inner counter 50
b7n_loop F9F6 LD HL,$9618 Point at rng_seed
F9F9 INC (HL) Increment first byte of rng_seed by 3
F9FA INC (HL)
F9FB INC (HL)
F9FC LD B,(HL) Load it into B
F9FD INC HL Advance to second byte of rng_seed
Note that this is a different order of operations than in rng/961B.
F9FE LD A,(HL) Subtract 141 from second byte of rng_seed
F9FF SUB $8D
FA01 LD (HL),A
FA02 ADD A,B Add first and second rng_seed bytes together
FA03 INC HL Advance to third byte of seed
FA04 RLCA Rotate A left by 1
FA05 RRC (HL) Rotate third byte of seed right by 1
FA07 ADD A,(HL) Add it to A
FA08 LD (HL),A Write it back
FA09 AND $10 Take a tap off at bit 4
FA0B JR Z,b7n_continue Jump to b7n_continue if zero
b7n_make_noise FA0D LD A,$18 Delay for (24 - E) iterations
FA0F SUB E
FA10 LD B,A
b7n_delay_loop_1 FA11 DJNZ b7n_delay_loop_1 Delay
FA13 LD A,$18 Set EAR + MIC bits
FA15 OUT ($FE),A
FA17 LD B,E Delay for E iterations
b7n_delay_loop_2 FA18 DJNZ b7n_delay_loop_2 Delay
FA1A XOR A Clear EAR + MIC bits
FA1B OUT ($FE),A
b7n_continue FA1D DEC D Decrement inner counter
FA1E JR NZ,b7n_loop Jump to b7n_loop if non-zero
The same dead interrupt check the main bank's copy carries: AND A clears carry, so the RET C below is never taken.
FA20 LD A,($F3BC) Read A from the <interrupt flag> at b7pm_wait_for_interrupt
FA23 AND A Set flags
FA24 RET C Bug: Carry is cleared by AND A so this makes no sense
FA25 DEC E Decrement duration counter
FA26 JR NZ,b7n_outer_loop Jump to b7n_outer_loop if non-zero
FA28 JP $F3BB Exit via b7pm_wait_for_interrupt (b7pm_wait_for_interrupt)
Prev: F953 Up: Map Next: FA2B