assemblybasicz80zxspectrum

Rapid screen drawing in Z80 Assembler + BASIC on emulator


Following the instruction of Chapter 10 of First Steps in Z80 Assembly Language by Darryl Sloan: Firstly, we fill the screen with a BASIC program of random colored "hello" messages. The assembler code, as I understand it, is then able to copy that screen data and print it back after the screen is cleared.

However, I just get a black screen instead of the random collection of coloured hello.

This is the asm

ORG 50000; Origin statement
LD HL, 30000 ; start address
LD BC, 6912 ; number of bytes to copy
LD DE, 16384 ; destination address
LDIR
RET

and the BASIC

40 PRINT INK INT (RND*8); PAPER INT (RND*8); "Hello";
50 GO TO 50

I understand the concept and the code, however unlike the author, I'm not using an emulator with a built in assembler. - Which is where I may be going wrong.

The source document is made free available and can be found here


Solution

  • As @Jester already pointed out, that snippet of code you posted is copying the contents of memory 30000-36911 to the display memory, which at the time of execution is most likely filled with 0s, hence the black screen.

    You need to transfer the contents of the screen to that area of memory first with a complementary transfer routine:

    ORG 50020; Origin statement
    LD HL, 16384; start address of screen
    LD BC, 6912 ; number of bytes to copy
    LD DE, 30000; destination address
    LDIR
    RET
    

    And invoke from basic as usual:

    RANDOMIZE USR 50020 --> save screen to ram

    RANDOMIZE USR 50000 --> transfer ram back to screen