Fun time!
Judging by how it happens with statues in level 3, enemy patterns works like that:
Language: asm
; Jump forward:
$D374:85 00 STA $0000 = #$50
$D376:6C 00 00 JMP ($0000) = $A2CD
$A2CD:20 20 D3 JSR $D320
$D320:A5 8F LDA GlobalTmr = #$AB
$D322:65 90 ADC RNG = #$84
$D324:85 90 STA RNG = #$84
$D326:E6 90 INC RNG = #$30 ; RNG = GlobalTmr + RNG + 1
$D328:60 RTS (from $D320)
$A2D0:29 03 AND #$03 ; RNG AND 0b11
$A2D2:D0 03 BNE $A2D7 ; result != 0 ? branch to $A2D7
$A2D4:4C 74 A2 JMP $A274 ; else jump to $A274
$A274:A9 00 LDA #$00
$A276:9D 0E 04 STA State,X @ $041C = #$08 ; State = 0, allowing to jump forward
$A279:A9 1D LDA #$1D
$A27B:9D 5E 04 STA $045E,X @ $046C = #$14
$A27E:4C DF A2 JMP $A2DF
$A2DF:20 66 8D JSR $8D66
$8D66:A6 B1 LDX $00B1 = #$0E
$8D68:FE 0E 04 INC State,X @ $041C = #$00
$8D6B:FE 0E 04 INC State,X @ $041C = #$01 ; State = 2, jump forward
$8D6E:60 RTS (from $8D66)
; Jump on the place:
$D374:85 00 STA $0000 = #$50
$D376:6C 00 00 JMP ($0000) = $A2CD
$A2CD:20 20 D3 JSR $D320
$D320:A5 8F LDA GlobalTmr = #$7B
$D322:65 90 ADC RNG = #$49
$D324:85 90 STA RNG = #$49
$D326:E6 90 INC RNG = #$C5 ; RNG = GlobalTmr + RNG + 1
$D328:60 RTS (from $D320)
$A2D0:29 03 AND #$03 ; RNG AND 0b11
$A2D2:D0 03 BNE $A2D7 ; result != 0 ? branch to $A2D7
$A2D7:A9 23 LDA #$23
$A2D9:9D 5E 04 STA $045E,X @ $046C = #$14
$A2DC:4C DF A2 JMP $A2DF
$A2DF:20 66 8D JSR $8D66
$8D66:A6 B1 LDX $00B1 = #$0E
$8D68:FE 0E 04 INC State,X @ $041C = #$08
$8D6B:FE 0E 04 INC State,X @ $041C = #$09 ; State = #$0A, jump up
$8D6E:60 RTS (from $8D66)
Boss actions depend on RNG + Global timer + Player Xpos. So do stone positions and timing for boss 4.
Language: asm
; Shoot (State=0x12):
$AF28:20 20 D3 JSR $D320
$D320:A5 8F LDA GlobalTmr = #$C7
$D322:65 90 ADC RNG = #$2E
$D324:85 90 STA RNG = #$2E
$D326:E6 90 INC RNG = #$F5
$D328:60 RTS (from $D320)
$AF2B:65 96 ADC XposP = #$C9
$AF2D:85 90 STA RNG = #$F6
$AF2F:29 40 AND #$40
$AF31:F0 07 BEQ $AF3A
$AF3A:A6 B1 LDX $00B1 = #$0C
$AF3C:A9 1E LDA #$1E
$AF3E:9D 2E 04 STA Timer,X @ $043A = #$00
$AF41:A9 00 LDA #$00
$AF43:4C C7 B0 JMP $B0C7
$B0C7:85 B2 STA $00B2 = #$00
$B0C9:20 66 8D JSR $8D66
$8D66:A6 B1 LDX $00B1 = #$0C
$8D68:FE 0E 04 INC State,X @ $041A = #$0E
$8D6B:FE 0E 04 INC State,X @ $041A = #$0F
$8D6E:60 RTS (from $8D66)
; Step (State=0x18):
$AF28:20 20 D3 JSR $D320
$D320:A5 8F LDA GlobalTmr = #$C7
$D322:65 90 ADC RNG = #$2E
$D324:85 90 STA RNG = #$2E
$D326:E6 90 INC RNG = #$F5
$D328:60 RTS (from $D320)
$AF2B:65 96 ADC XposP = #$CB
$AF2D:85 90 STA RNG = #$F6
$AF2F:29 40 AND #$40
$AF31:F0 07 BEQ $AF3A
$AF33:A6 B1 LDX $00B1 = #$0C
$AF35:A9 14 LDA #$14
$AF37:9D 0E 04 STA State,X @ $041A = #$0E
$AF3A:A6 B1 LDX $00B1 = #$0C
$AF3C:A9 1E LDA #$1E
$AF3E:9D 2E 04 STA Timer,X @ $043A = #$00
$AF41:A9 00 LDA #$00
$AF43:4C C7 B0 JMP $B0C7
$B0C7:85 B2 STA $00B2 = #$00
$B0C9:20 66 8D JSR $8D66
$8D66:A6 B1 LDX $00B1 = #$0C
$8D68:FE 0E 04 INC State,X @ $041A = #$14
$8D6B:FE 0E 04 INC State,X @ $041A = #$15
$8D6E:60 RTS (from $8D66)
Movied script int he above post.
Boss 5 position:
Language: asm
$B5B5:20 20 D3 JSR $D320
$D320:A5 8F LDA GlobalTmr = #$37 ; Usual RNG roll
$D322:65 90 ADC RNG = #$74 ; Mix global timer with RNG
$D324:85 90 STA RNG = #$74
$D326:E6 90 INC RNG = #$AC
$D328:60 RTS (from $D320)
$B5B8:65 96 ADC PlrXposLo = #$43 ; Mix player Xpos in
$B5BA:85 90 STA RNG = #$AD
$B5BC:29 20 AND #$20
$B5BE:18 CLC
$B5BF:69 C0 ADC #$C0
$B5C1:85 B6 STA $00B6 = #$00 ; Set some resulting mess to $B6
; [...]
$B5D4:A5 8F LDA GlobalTmr = #$38 ; Mess with global timer a bit more
$B5D6:20 EC B5 JSR $B5EC
$B5EC:A6 B6 LDX $00B6 = #$E0
$B5EE:A0 01 LDY #$01
$B5F0:29 01 AND #$01
$B5F2:D0 07 BNE $B5FB
$B5F4:A5 B6 LDA $00B6 = #$E0 ; Load $B6 again
$B5F6:49 FF EOR #$FF ; Mess with it
$B5F8:AA TAX
$B5F9:A0 00 LDY #$00
$B5FB:8A TXA
$B5FC:A6 B1 LDX SlotPtr = #$0C
$B5FE:9D AE 04 STA XposLo,X @ $04BA = #$20 ; Set boss Xpos
$B601:98 TYA
$B602:9D 3E 04 STA DeathFlg,X @ $044A = #$00
$B605:60 RTS (from $B5EC)
And finally Boss 5 8-frame rule. He gets available only every 8th frame as you enter his room. I have no freaking idea how it works, but $B2 is critical, since $B3-$B5 don't seem to change during those frames.
Language: asm
$B680:A5 8F LDA GlobalTmr = #$00 A:80 X:0C Y:06 S:FB P:NvUBdIzC
$B682:25 B5 AND $00B5 = #$07 A:00 X:0C Y:06 S:FB P:nvUBdIZC
$B684:D0 0B BNE $B691 A:00 X:0C Y:06 S:FB P:nvUBdIZC
$B686:A5 B2 LDA $00B2 = #$00 A:00 X:0C Y:06 S:FB P:nvUBdIZC
$B688:C5 B3 CMP $00B3 = #$06 A:00 X:0C Y:06 S:FB P:nvUBdIZC
$B68A:F0 08 BEQ $B694 A:00 X:0C Y:06 S:FB P:NvUBdIzc
$B68C:18 CLC A:00 X:0C Y:06 S:FB P:NvUBdIzc
$B68D:65 B4 ADC $00B4 = #$02 A:00 X:0C Y:06 S:FB P:NvUBdIzc
$B68F:85 B2 STA $00B2 = #$00 A:02 X:0C Y:06 S:FB P:nvUBdIzc
$B691:4C 97 B6 JMP $B697 A:02 X:0C Y:06 S:FB P:nvUBdIzc
$B697:A5 B8 LDA $00B8 = #$00 A:02 X:0C Y:06 S:FB P:nvUBdIzc
$B699:F0 05 BEQ $B6A0 A:00 X:0C Y:06 S:FB P:nvUBdIZc
$B6A0:A6 B1 LDX SlotPtr = #$0C A:00 X:0C Y:06 S:FB P:nvUBdIZc
$B6A2:A9 09 LDA #$09 A:00 X:0C Y:06 S:FB P:nvUBdIzc
$B6A4:9D 6E 04 STA $046E,X @ $047A = #$09 A:09 X:0C Y:06 S:FB P:nvUBdIzc
$B6A7:A4 B2 LDY $00B2 = #$02 A:09 X:0C Y:06 S:FB P:nvUBdIzc
$B6A9:B9 BF B6 LDA $B6BF,Y @ $B6C1 = #$00 A:09 X:0C Y:02 S:FB P:nvUBdIzc
$B6AC:9D 7E 04 STA $047E,X @ $048A = #$00 A:00 X:0C Y:02 S:FB P:nvUBdIZc
$B6AF:B9 BE B6 LDA $B6BE,Y @ $B6C0 = #$E4 A:00 X:0C Y:02 S:FB P:nvUBdIZc
$B6B2:F0 09 BEQ $B6BD A:E4 X:0C Y:02 S:FB P:NvUBdIzc
$B6B4:1D 3E 04 ORA DeathFlg,X @ $044A = #$01 A:E4 X:0C Y:02 S:FB P:NvUBdIzc
$B6B7:9D 4E 04 STA Sprite,X @ $045A = #$00 A:E5 X:0C Y:02 S:FB P:NvUBdIzc
$B6BA:4C 7D 8F JMP $8F7D A:E5 X:0C Y:02 S:FB P:NvUBdIzc
$8F7D:A6 B1 LDX SlotPtr = #$0C A:E5 X:0C Y:02 S:FB P:NvUBdIzc
$8F7F:BC 4E 04 LDY Sprite,X @ $045A = #$E5 A:E5 X:0C Y:02 S:FB P:nvUBdIzc