SCREEN START 0 
    LDA #65
    JSUB scrfill
    JSUB scrclear   
    LDA #77
    JSUB scrfill
    JSUB scrclear
    LDA #88 
    JSUB scrfill
    JSUB scrclear 
    LDA #99
    STA znak
    LDA #25 
    STA row
    LDA #30
    STA col
    JSUB printch
    LDA #30
    STA row
    JSUB printch
HALT J HALT
    END SCREEN

scrfill     STA znak    
loop_fill   LDA y 
            MUL scrcols
            ADD screen
            ADD x
            STA pix_ptr
            LDA znak
            STCH @pix_ptr
            LDA x
            ADD #1
            STA x
            COMP scrcols
            JLT loop_fill
            CLEAR A
            STA x
            LDA y
            ADD #1
            STA y 
            COMP scrrows
            JLT loop_fill
            
            CLEAR A
            STA x 
            STA y
            LDA znak
            RSUB


.address = screen + y * scrcols + x
scrclear    STA old_val 
loop_clear  LDA y 
            MUL scrcols
            ADD screen
            ADD x
            STA pix_ptr
            CLEAR A
            STCH @pix_ptr
            LDA x
            ADD #1
            STA x
            COMP scrcols
            JLT loop_clear
            CLEAR A
            STA x
            LDA y
            ADD #1
            STA y
            COMP scrrows
            JLT loop_clear
        
            CLEAR A
            STA x
            STA y
            LDA old_val
            RSUB        

printch STA old_val
        LDA row
        MUL scrcols
        ADD screen
        ADD col 
        STA pix_ptr
        LDA znak
        STCH @pix_ptr

        CLEAR A
        LDA old_val 
        RSUB
        


row WORD 0 
col WORD 0 
old_val WORD 0 
znak WORD 0 
x WORD 0 
y WORD 0
pix_ptr WORD 0 
screen WORD X'00B800'
scrcols WORD 25
scrrows WORD 80
scrlen WORD 2000
