Hello,

  I needed a Port I/O routine for the Z80 that would accept the address as a 
parameter, so I wrote 2 functions with inline ASM to do it. I would have used 
sfr, but the addresses need to be passed as a parameter (ie. I can't just 
#define or hardcode them).

  I'm pretty new to ASM, and with all the warning in the manual about 
protecting the registers I just wanted to check with some experienced people to 
see if these functions looked OK. They do work fine under emulation, haven't 
tried them on real hardware.

//these 2 are outside of the functions so the symbols will be seen by the ASM 
code
static uint8 io_val;
static uint8 io_addr;

uint8 io_read(uint8 addr) {
        io_addr = addr;
        _asm
        push af
        push bc
        ld bc, (_io_addr)
        in a, (c)
        ld (_io_val), a
        pop bc
        pop af
        _endasm;
        return io_val;
}

void io_write(uint8 addr, uint8 val) {
        io_addr = addr;
        io_val = val;
        _asm
        push af
        push bc
        ld a,(_io_val)
        ld bc,(_io_addr)
        out (c),a
        pop bc
        pop af
        _endasm;
}

Best regards,
 Indy Sams
 mailto:i...@driftsolutions.com


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to