Boriel Basic Forum
CLS/Fade out ASM Sub-routine - Printable Version

+- Boriel Basic Forum (https://forum.boriel.com)
+-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11)
+---- Forum: How-To & Tutorials (https://forum.boriel.com/forumdisplay.php?fid=13)
+---- Thread: CLS/Fade out ASM Sub-routine (/showthread.php?tid=2641)



CLS/Fade out ASM Sub-routine - tubz74 - 2025-10-05

This is a small clear screen, that sort of fades out the screen pixel by pixel to the background colour.  I took it from one of the Melbourne house books, can't remember which one though.

No idea if it breaks anything else, but I've not had any issues.

Code:
SUB CLSFadeOut()
' Fade out Screen Clearing

    ASM

        LD DE,08feh
        NXTFADE:
            LD A,E
            RLCA
            RLCA
            RLCA
            LD E,A
            LD HL,4000H
            LD BC,0018H
            NXT:
                LD A, (HL)
                AND E
                LD (HL),A
                INC HL
            DJNZ NXT
            DEC C
            JR NZ,NXT
            DEC D
        JR NZ,NXTFADE
        LD A,(5C8DH)
        LD (HL),A
        LD D,H
        LD E,L
        INC DE
        LD BC,02C0H
        LDIR
        LD A,(5C48H)
        LD (HL),A
        LD C,3FH
        LDIR
    END ASM

END SUB



RE: CLS/Fade out ASM Sub-routine - boriel - 2025-10-05

Good one!
No, it won't break anything (only IX should be preserved (push/pop) before the function returns).
Also, it's recommended to make your labels private. To do so:
Wrap your ASM routine between
Code:
PROC
...
ENDP
directives.
Declare your labels locals after PROC, with:
LOCAL NXTFADE, NXT
:-)

If your code is BSD / MIT / Apache I can put it in the standard library for other people to use it.


RE: CLS/Fade out ASM Sub-routine - tubz74 - 2025-10-05

Happy for it to be used however by whoever - which ever licence doesn't require anything from me or from the user.