Z80 Basic for the Monsputer

Several people made their own Z80 computer. I found this one which run Microsoft BASIC, so I made it run on the Monsputer.

Grant’s 7-chip Z80 computer

Just some minor modifications specific to the hardware were needed to set the baud rate, and initialize the interrupts.

By looking in the assembler code, there is an interesting and clever trick: instead of putting relative jumps, which take 2 bytes, there are ‘skip’ instructions which only take 1 byte!
(In those times, RAM was costly and every bytes counted)

How they do this? The ‘skip’ instruction is really a 8-bit or 16-bit load immediate instruction. The 8-bit allows to skip 1 byte, the 16-bit one allows to skip 2 bytes. Let’s see this in action.

The following code is an example with a relative jump.

sbr_val2:
        push    hl
        ld      hl,#value2
        jr      sbr_ex
sbr_val1: 
        push    hl
sbr_ex:
        <instructions>
        pop     hl
        ret

With the skip trick, it becomes:

sbr_val2:
        push    hl
        ld      hl,#value2

        .db     0x3e    ;ld a,#0xE5 used as a skip instruction:
                        ;push hl is read as a data byte and
                        ;is not executed
sbr_val1:
        push    hl
sbr_ex:
        <instructions>
        pop     hl
        ret
Advertisements
This entry was posted in Monsputer, Software, Z80. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s