CPCWiki forum

General Category => Programming => Topic started by: HAL6128 on 14:56, 19 April 18

Title: quick question regarding an OUT command
Post by: HAL6128 on 14:56, 19 April 18
Is it correct that an OUT command on the CPC works different to other 8-Bit compuer with a Z80A processor? So it's not possible to use Block I/O transfers like the example below because an OUT command on the CPC is more a OUT(B),A than an regular OUT (C),A?

PORT EQU &FF10
LD B,100
LD A,0
.loop
OUT (PORT),A
DJNZ loop
Title: Re: quick question regarding an OUT command
Post by: keith56 on 15:22, 19 April 18
You are correct, B and C are used as the address on the Amstrad CPC, as it uses a 16 bit address bus for OUT commands... many devices on the CPC reply to whole ranges, so C often does not need to be set, but whatever the command says, eg OUT (&FF),A... B will be used as the top half of the port address.. making OTIR pretty unusable, and even OUTI problematic

It's not just the CPC, the Sam Coupe and ZX spectrum do it too, and it's actually in the Z80 documentation - I used to think it was just a CPC quirk, but it's not the case
Title: Re: quick question regarding an OUT command
Post by: gerald on 15:49, 19 April 18
Quote from: HAL 6128 on 14:56, 19 April 18
Is it correct that an OUT command on the CPC works different to other 8-Bit compuer with a Z80A processor? So it's not possible to use Block I/O transfers like the example below because an OUT command on the CPC is more a OUT(B),A than an regular OUT (C),A?

PORT EQU &FF10
LD B,100
LD A,0
.loop
OUT (PORT),A
DJNZ loop

The OUT works exactly as on other Z80 based system  :D
The difference is that amstrad decided to use the full 16bit address for IO instead of the more commonly used 8bit LSB mode.
And the OUTR/INR OUTI/INI only works with the 8bit LSB addressing mode.
Title: Re: quick question regarding an OUT command
Post by: andycadley on 23:56, 19 April 18
All Z80s put BC on the address bus when an OUT (C),x instruction occurs. The original intention of Zilog was that only the lower 8-bits would ever be considered significant, but this was widely ignored and so instructions, such as OTIR, designed around that principle are of very limited usage.
Title: Re: quick question regarding an OUT command
Post by: HAL6128 on 09:48, 20 April 18
Ok, thank you.
I'm trying to convert a piece of code from a MSX to a CPC (example below).
So, first question is the MSX is doing this different?
Second question ist: I realized that some assembler (Maxam, WinApe or RASM) are truncating the constant PORT to &FF (MSB), so I have to load the PORT additionally with LD BC,PORT?
Title: Re: quick question regarding an OUT command
Post by: roudoudou on 11:32, 20 April 18
The OUT (im8),A is barely unusable with CPC for the reasons mentionned above. Anyway the instruction OUT (im16),A does not exists  :D

The INI, OUTI, IND, OUTD are used on a CPC but you have to put an INC B before each use to fix the pre-decrementation of this register.
Title: Re: quick question regarding an OUT command
Post by: keith56 on 13:43, 20 April 18
It's very important too! My palette switching code was corrupting floppy disks at one point, because I was using OUTI, and not INC B!!!
Title: Re: quick question regarding an OUT command
Post by: GUNHED on 13:48, 21 April 18
Whatever values the MSX does sent to an port, it will be different on CPC side. The address is different and the data most likely too (except maybe the soundchip somewhat).

On CPC you usually do this:

LD BC,&XXXX
OUT (C),C

This will send the data (C) to the port (BC). In this case C doesn't matter in the port address. This works finde for CRTC, PIO, PSG.


For external hardware you can use:

LD BC,&XXXX
LD A,data
OUT (C),A

Sends data (A) to port (BC). This works for FDC and all other stuff.
Powered by SMFPacks Menu Editor Mod