; Scaler by Oerg866

; scaler-specific RAM values

RAM_ScaleValue EQU $FFC000
RAM_ScaleVanishingPoint EQU $FFC002
RAM_ScaleCurrent EQU $FFC004
RAM_ScaleTable EQU $FF8000   

ScaleInit:
    DisableInts
    move.l (ScrollVINT), (RAM_VINTLoc)
    move.l (ScrollVINT+4), (RAM_VINTLoc+4)
    lea (WriteTable), a0
    lea (RAM_HINT), a1
    move.w #WriteTable_End-WriteTable-1, d0
@CopyHint
    move.b (a0)+, (a1)+
    dbf d0, @CopyHint
    lea (RAM_ScaleTable), a6
    EnableInts
    rts
    
ScrollVINT: 
    jmp GenerateScrollTable
    
GenerateScrolltable:
    lea (ScaleLUT), a6
    moveq #0, d7
    move.w (RAM_ScaleValue), d7
    lsl.w #2, d7
    move.l (a6,d7.w), d6
    moveq #0, d5
    move.w (RAM_ScaleVanishingPoint), d5 
    lsr.w d5, d7
    subq.w #1, d7
    neg.w d7
;   move.l d7, d4
;   moveq #0, d7
    swap d7
    move.w #0, d7
    move.w (RAM_ScaleValue), d5
;   subq #1, d5
    lea (RAM_ScaleTable), a5
@WriteScroll:
    add.l d6, d7
    swap d7
    move.w d7, (a5)+
    swap d7
    dbf d5, @Writescroll    
    move.w #224-1, d5
    sub.w (RAM_ScaleValue), d5
    swap d7
@WriteScroll2:
    move.w d7, (a5)+
    subq.w #1, d7
    dbf d5, @WriteScroll2
    lea (RAM_ScaleTable), a6
    rte

WriteTable:
    move.l #$40000010,($C00004)
    move.w (a6)+, ($C00000)
    move.w #0, ($C00000)
@NoReset
    rte
WriteTable_End:
    
ScaleLUT:
    incbin "./spheres/scale.LUT"