int DMA_read_memory (int nchan, void *buf, int pos, int len)

{

    struct dma_regs *r = &dma_controllers[nchan > 3].regs[nchan & 3];

    target_phys_addr_t addr = ((r->pageh & 0x7f) << 24) | (r->page << 16) | r->now[ADDR];



    if (r->mode & 0x20) {

        int i;

        uint8_t *p = buf;



        cpu_physical_memory_read (addr - pos - len, buf, len);

        /* What about 16bit transfers? */

        for (i = 0; i < len >> 1; i++) {

            uint8_t b = p[len - i - 1];

            p[i] = b;

        }

    }

    else

        cpu_physical_memory_read (addr + pos, buf, len);



    return len;

}

int DMA_read_memory (int nchan, void *buf, int pos, int len)

{

    struct dma_regs *r = &dma_controllers[nchan > 3].regs[nchan & 3];

    target_phys_addr_t addr = ((r->pageh & 0x7f) << 24) | (r->page << 16) | r->now[ADDR];



    if (r->mode & 0x20) {

        int i;

        uint8_t *p = buf;



        cpu_physical_memory_read (addr - pos - len, buf, len);

        

        for (i = 0; i < len >> 1; i++) {

            uint8_t b = p[len - i - 1];

            p[i] = b;

        }

    }

    else

        cpu_physical_memory_read (addr + pos, buf, len);



    return len;

}

int FUNC_0 (int VAR_0, void *VAR_1, int VAR_2, int VAR_3)

{

    struct dma_regs *VAR_4 = &dma_controllers[VAR_0 > 3].regs[VAR_0 & 3];

    target_phys_addr_t addr = ((VAR_4->pageh & 0x7f) << 24) | (VAR_4->page << 16) | VAR_4->now[ADDR];



    if (VAR_4->mode & 0x20) {

        int VAR_5;

        uint8_t *p = VAR_1;



        cpu_physical_memory_read (addr - VAR_2 - VAR_3, VAR_1, VAR_3);

        

        for (VAR_5 = 0; VAR_5 < VAR_3 >> 1; VAR_5++) {

            uint8_t b = p[VAR_3 - VAR_5 - 1];

            p[VAR_5] = b;

        }

    }

    else

        cpu_physical_memory_read (addr + VAR_2, VAR_1, VAR_3);



    return VAR_3;

}

int FUNC_0 (int VAR_0, void *VAR_1, int VAR_2, int VAR_3)
{ struct dma_regs *VAR_4 = &dma_controllers[VAR_0 > 3].regs[VAR_0 & 3]; target_phys_addr_t addr = ((VAR_4->pageh & 0x7f) << 24) | (VAR_4->page << 16) | VAR_4->now[ADDR]; if (VAR_4->mode & 0x20) { int VAR_5; uint8_t *p = VAR_1; cpu_physical_memory_read (addr - VAR_2 - VAR_3, VAR_1, VAR_3); for (VAR_5 = 0; VAR_5 < VAR_3 >> 1; VAR_5++) { uint8_t b = p[VAR_3 - VAR_5 - 1]; p[VAR_5] = b; } } else
cpu_physical_memory_read (addr + VAR_2, VAR_1, VAR_3); return VAR_3; }