class Z80::Stdlib

Z80::Stdlib - Macros with commonly used memory routines.

require 'z80'

class MyLib
    include Z80
    macro_import Stdlib

    export :auto

    ns :clear_memory do
                    pop  hl
                [e, d, c, b].each do |r|
                    ld   r, [hl]
                    inc  hl
                end
                    push hl
                    ex   de, hl
                    clrmem
                    ret
    end

    ns :copy_memory do
                    pop  hl
                [e, d, c, b, a].each do |r|
                    ld   r, [hl]
                    inc  hl
                end
                    inc  hl
                    push hl
                    dec  hl
                    ld   h, [hl]
                    ld   l, a
                    memcpy
                    ret
    end
end

class Program
    include Z80
    include Z80::TAP

    destination addr 0x5800

                call mylib.copy_memory
                dw   destination
                dw   +source
                dw   source
                # ...
                call mylib.clear_memory
                dw   destination
                dw   +source
                # ...
                ret

    source      data "Some data..."
    import      MyLib, :mylib
end

program = Program.new 0x8000
puts program.debug