Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clearing Screen
#1
I adapted some Screen clearing routines posted on WOS here: <!-- m --><a class="postlink" href="http://www.worldofspectrum.org/forums/showthread.php?t=38426">http://www.worldofspectrum.org/forums/s ... hp?t=38426</a><!-- m --> for ZXBC. Maybe useful for other coders:
Code:
sub ShiftClearScr()
    asm
        ld b,8        ;'8 bits to rotate out per byte
    CLSNloop:
        call clearscreennice
        djnz CLSNloop
        jr CLSNEnd
    clearscreennice:
        ld hl,16383    ;'just before display file
    CLSNcloop:
        inc hl
        ld a,h
        cp 88        ;'into address 22528 yet?
        ret z        ;'yep return
        sla (hl)    ;'nope, shift the byte
        jr CLSNcloop    ;'keep going
    CLSNEnd:
    end asm
end sub
Code:
sub SpiralTrailClearScr()
    asm
        ei
        ld      hl,patterns01
loop1:
        halt
        
        ld      a,(hl)  
        inc     hl    
        
        or      a  
        jp      z,end02  
        
        ld      c,a  
        and     127  
        ld      d,a  
        
        ld      b,3  
        ld      e,0  
                
loop2:
        ld      a,(de)

        bit     7,c  
        jr      z,tmp1  

        or      (hl)    
        jr      tmp2  

tmp1:
    and     (hl)

tmp2:
    ld      (de),a
        inc     e  
        jr      nz,loop2  
        
        ld      a,d  
        add     a,8  
        ld      d,a  
        djnz    loop2
        
        inc     hl  
        jr      loop1  
        
        jp end02
                  
patterns01:
        db      64+128,128,64+128,64,64+128,32,64+128,16
        db      64+128,8,64,127,64+128,4,64,191
        db      64+128,2,64,223,64+128,1,64,239
        db      65+128,1,64,247,66+128,1,64,251
        db      67+128,1,64,253,68+128,1,64,254
        db      69+128,1,65,254,70+128,1,66,254
        db      71+128,1,67,254,71+128,2,68,254
        db      71+128,4,69,254,71+128,8,70,254
        db      71+128,16,71,254,71+128,32,71,253
        db      71+128,64,71,251,71+128,128,71,247
        db      70+128,128,71,239,69+128,128,71,223
        db      68+128,128,71,191,67+128,128,71,127
        db      66+128,128,70,127,65+128,128,69,127
        db      65+128,64,68,127,65+128,32,67,127
        db      65+128,16,66,127,65+128,8,65,127
        db      65+128,4,65,191,65+128,2,65,223
        db      66+128,2,65,239,67+128,2,65,247
        db      68+128,2,65,251,69+128,2,65,253
        db      70+128,2,66,253,70+128,4,67,253
        db      70+128,8,68,253,70+128,16,69,253
        db      70+128,32,70,253,70+128,64,70,251
        db      69+128,64,70,247,68+128,64,70,239
        db      67+128,64,70,223,66+128,64,70,191
        db      66+128,32,69,191,66+128,16,68,191
        db      66+128,8,67,191,66+128,4,66,191    
        db      67+128,4,66,223,68+128,4,66,239    
        db      69+128,4,66,247,69+128,8,66,251    
        db      69+128,16,67,251,69+128,32,68,251
        db      68+128,32,69,251,67+128,32,69,247  
        db      67+128,16,69,239,67+128,8,69,223    
        db      68+128,8,68,223,68+128,16,67,223    
        db      67,239,67,247,68,247,68,239
        
        db      0
    end02:
    end asm
end sub
Code:
sub SpiralClearScr()
    asm
                ei  
                ld      hl,patterns
loop01:
                halt

                ld      a,(hl)
                inc     hl

                or      a
                jp      z,clearend2

                ld      d,a

                ld      c,(hl)
                inc     hl

                ld      b,3
                ld      e,0

loop02:          ld      a,(de)
                and     c
                ld      (de),a
                inc     e
                jr      nz,loop02

                ld      a,d
                add     a,8
                ld      d,a
                djnz    loop02

                jr      loop01

                jp clearend2

patterns:
                db      64,127, 64,191, 64,223, 64,239
                db      64,247, 64,251, 64,253, 64,254
                db      65,254, 66,254, 67,254, 68,254
                db      69,254, 70,254, 71,254, 71,253
                db      71,251, 71,247, 71,239, 71,223
                db      71,191, 71,127, 70,127, 69,127
                db      68,127, 67,127, 66,127, 65,127
                db      65,191, 65,223, 65,239, 65,247
                db      65,251, 65,253, 66,253, 67,253
                db      68,253, 69,253, 70,253, 70,251
                db      70,247, 70,239, 70,223, 70,191
                db      69,191, 68,191, 67,191, 66,191
                db      66,223, 66,239, 66,247, 66,251
                db      67,251, 68,251, 69,251, 69,247
                db      69,239, 69,223, 68,223, 67,223
                db      67,239, 67,247, 68,247, 68,239

                db      0
clearend2:
    end asm
end sub
Code:
sub RandomClearScr()
    asm
            ld hl,0        ;'point hl somewhere in ROM
            ld b,6        ;'using 48k ROM you need 5 or more repeats to empty screen
        CLSloop1:
            call CLSStart1
            djnz CLSloop1
            jr CLSend1
        CLSStart1:
            ld de,16383    ;'start of display file-1
        CLScloop:
            inc de        ;'move into and through display file
            inc hl        ;'and ROM
            ld a,d        ;'are we out of display file and into attributes yet?
            cp 88
            ret z            ;'yep return
            ld a,(de)    ;'nope, AND the data together and give the fadeaway effect
            and (hl)
            ld (de),a
            jr CLScloop    ;'keep going
        CLSend1:
    end asm
end sub
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#2
Great!!! 8)

Note: you can add FASTCALL to these subs, for a little optimization (in the future, 0 parameters & 0 local var functions and subs will be automatically fastcalled, but not at the moment)
Reply
#3
boriel Wrote:Great!!! 8)

Note: you can add FASTCALL to these subs, for a little optimization (in the future, 0 parameters & 0 local var functions and subs will be automatically fastcalled, but not at the moment)
I was about to make this as fastcall routines, but after all it is not necessary as they don't need to be called fast as possible (maybe just to save some memory?).
What you wrote about the future plans to make SUB/FUNCTION with no parameters automatically fastcalled, sounds great!
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#4
is there a function to copy and paste graphics to the screen?
e.g. when sprites move against a pre-drawn background

obviously it will be slower than using pure machine code but y'know


Copy: for copying the background when it has to be replaced
Paste:draw the copied graphics back to the screen
Reply
#5
Slenkar - not exactly, but if you want to work on something, look in the wiki library. There are several graphics routines in there that put to the screen. Fourspriter also copies away from the screen - you might want to examine that. It is character based, though.


<!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m -->
Reply
#6
ok thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)