z80:Text Routines

From Learn @ Cemetech
Jump to navigationJump to search

One of the easiest ways to communicate with the user is through text. The OS offers a slew of routines, but here are a few more to add to your list of routines:

PutSI

Standing for "Put String Immediate," a routine like this can really add up to be a wonderful way to save memory, especially for programs relying heavily on text. What you do is call this routine with your text data directly following the call. For example:

   call PutSI
        .db 3,3,"String",0

Here is the code:

   PutSI:
        pop hl
        ld c,(hl)
        inc hl
        ld b,(hl)
        inc hl
        ld (curRow),bc
        bcall(_PutS)
        jp (hl)

To give an idea of how much memory it saves, you save 1 byte after using this routine twice (it makes up for the size of the routine) and saves an additional 7 bytes each time it is used.

VPutSI

Along the same lines as PutSI:

   VPutSI:
        pop hl
        ld c,(hl)
        inc hl
        ld b,(hl)
        inc hl
        ld (penCol),bc
        bcall(_VPutS)
        jp (hl)

PutS_App

To use bcall(_PutS), the string must be in RAM. In Apps, this means you need to copy the string to RAM before displaying it. Or, you could make a routine like this:

   PutS_App:
   ;Inputs:
   ;     HL points to the zero-terminated string
        ld a,(hl)
        or a
        ret z
        inc hl
        bcall(_PutC)
        jr PutS_App