lorom

;Compressed scroll PLM
;By SMILEuser96
;How to use: like a regular scroll PLM, but the format of the data is different
;One byte encodes both a screen and a scroll color
;The highest 6 bits define a screen. The lowest two bits define the scroll color.
;Byte 00 is the terminator (this means scroll 00 can't be set to red)
;For example: 13 01 80 is the scroll data for the original landing site scroll PLM.
;With this, it is: 4D 00

!PLM_Header =      $84B707 ;Overwrite PLM $B707, solid scroll PLM
!FreeSpace_One =   $84B382 ;Overwrite solid scroll PLM setup
!FreeSpace_Two =   $84AF92 ;Overwrite solid scroll PLM instruction list
!FreeSpace_Three = $848B93 ;Overwrite solid scroll PLM scroll update

org !PLM_Header
  dw Init, Main
  
org !FreeSpace_One
Init:
  LDX $1C87,y : LDA #$B046 : JSR $82B4 ;Set trigger block
  RTS

org !FreeSpace_Two
Main:
  dw $86B4 ;Sleep until triggered
  dw UpdateScroll
  dw $8724, Main ;Sleep again
  
org !FreeSpace_Three
UpdateScroll:
  PHB : PHX : PHY
  STZ $1E17
  
  LDY $1DC7,x ;Room argument
  PEA $8F00 : PLB : PLB ;DB = $8F
  LDA #$0000 : SEP #$20
  
;Loop
- LDA $0000,y : CMP #$FC : BNE + : JMP $8B79   ;If byte=FC, end
+ STA $12 : AND #$03 : STA $14      ;$14 = color
  LDA $12 : LSR #2 : TAX : LDA $14  ;X = screen, and restore color to A
  STA $7ECD20,x                     ;Set screen color
  INY : BRA -                       ;Next