Author Topic: AY-3-8910 - can't write odd values to its registers?  (Read 5056 times)

0 Members and 1 Guest are viewing this topic.

Offline nockieboyTopic starter

  • Super Contributor
  • ***
  • Posts: 1812
  • Country: england
Re: AY-3-8910 - can't write odd values to its registers?
« Reply #25 on: February 27, 2019, 06:36:50 pm »
All sorted now.

Yes, it was because of AQ8 - which is just A8 from the Z80 through a buffer.

I'd misunderstood (or more likely forgotten) the operation of OUT (C),A - so it was the contents of the A register on A8-A15 that was throwing the address decode out for the PSG.  It's working fine now that I've disconnected AQ8 from the 521 and grounded that pin.

Thanks for your help and advice everyone - it's much appreciated. :)  I'll probably be back later for problems with the analogue stage - still getting rubbish out of the speaker, but I've got some more testing I can do with that end before I worry everyone else with it.   :-+
« Last Edit: February 27, 2019, 08:19:47 pm by nockieboy »
 

Offline nick_d

  • Regular Contributor
  • *
  • Posts: 120
Re: AY-3-8910 - can't write odd values to its registers?
« Reply #26 on: February 27, 2019, 11:14:44 pm »
Good that you got it solved. The Z80's handling of A8-A15 for IO cycles is indeed quite weird, something that has been addressed in the Z180 by adding the IN0 and OUT0 instructions, though unfortunately they're longer and slower.

To clarify my earlier suggestion I meant that the Z80 chip could have been damaged or faulty with a fault that only affected a subset of IO write cycles. But since you have other IO devices on the bus as you mention, that was unlikely.

Anyway the A-Y chips are uber cool, I would LOVE to have a Mockingboard for my souped up Apple IIe some day!

cheers, Nick
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 7676
  • Country: ca
Re: AY-3-8910 - can't write odd values to its registers?
« Reply #27 on: February 27, 2019, 11:31:21 pm »
A last note, I think 74F inputs float low as opposed to 'LS and TTL which float high. This would affect your address select dipswitch circuit.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15794
  • Country: fr
Re: AY-3-8910 - can't write odd values to its registers?
« Reply #28 on: February 28, 2019, 02:57:17 pm »
the Z80 only uses the lower 8 address bits for IN/OUT requests, so the upper 8 address bits may hold any value - I don't think this is specified. So don't use them for decoding IO accesses.

thats not true, Z80 uses all 16 address lines for IN/OUT operations.

For non-prefixed IN/OUT operations, the high byte address is taken from register A.
So, this code:
Code: [Select]
LD    A,#AA
OUT (#55),A

is equals to OUT (#AA55),#55

For #ED prefixed IN/OUT operations, 16-bit address is taken from register BC.

I haven't used a Z80 in ages, hence the "IIRC"... and I didn't remember that. That's old memories, but I don't think I have ever used anything but the lower 8 bits for IN/OUT operations.

That said, the upper 8 address bits with the OUT (n),A instruction kinda looks like a trick, since it will output the same byte on the data bus than on the upper 8 address bits. Could be put to use I guess, but that's kind of funky nonetheless.

I downloaded the Z80 user manual to refresh memory (my own). What's somewhat confusing (and maybe why I, and probably others, have never thought of using the upper 8 address bits) is that, whereas it's indeed stated in the instruction set description, the /IORQ pin function description says ('Overview' section):
Quote
Input/Output Request (output, active Low, tristate). IORQ indicates that
the lower half of the address bus holds a valid I/O address for an I/O read or
write operation.

So I'm wondering whether this upper half trick wasn't added as an afterthought or something, and the manual not completely updated. Looks like I just learned a Z80 trick more than 20 years since I last used one. ;D

And in the OP's case, since he wasn't taking care of the upper half anyway, there was no reason to use anything but the lower half.

Brings back fond memories!
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 4135
  • Country: 00
Re: AY-3-8910 - can't write odd values to its registers?
« Reply #29 on: February 28, 2019, 04:16:51 pm »

So I'm wondering whether this upper half trick wasn't added as an afterthought or something, and the manual not completely updated. Looks like I just learned a Z80 trick more than 20 years since I last used one. ;D


I was used Z80 a long time ago, there are a lot of different documentation about Z80, I don't remember exactly where this feature is described, but this is well known behavior and it works on all Z80 modifications and clones in the same way. This behavior was used in some ZX Spectrum programs for fast access to the port with 16-bit decoding. For example it is extensively used in demos from Code Busters group to access AY8910 which uses A14 and A15 lines for port address decoding.

There is also one instruction that works in different way on different Z80 clones.
OUT (BC),#00 writes #FF on some Z80 modifications and #00 on original Z80.
But this instruction is undocumented.  :)
« Last Edit: February 28, 2019, 04:39:21 pm by radiolistener »
 

Offline nick_d

  • Regular Contributor
  • *
  • Posts: 120
Re: AY-3-8910 - can't write odd values to its registers?
« Reply #30 on: February 28, 2019, 09:50:39 pm »
The IN/OUT (C),reg instruction has always treated the port address as 16 bit, it's really kind of a misnomer since it acts as (BC),reg. Based on the mnemonic which only refers to C, it could have been an unintentional feature but I believe it is a reliable one which works on all Z80. I would have to check whether 8080/8085 have this instruction and if so what they do with A8-A15.

It's the IN/OUT (immed),reg which is the funky one as discussed. The behaviour of putting A on the bus seems to be an accident even though many rely on the behaviour as mentioned in the thread.

That's why the Z180, which uses a quarter of the 00-FF space for the internal peripherals, uses the (C),reg form unchanged but adds the IN0/OUT0 (immed),reg instructions to do the right thing in 16 bit IO spaces without breaking Z80 compatibility. I never use the original funky versions on the Z180!

cheers, Nick
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 4135
  • Country: 00
Re: AY-3-8910 - can't write odd values to its registers?
« Reply #31 on: February 28, 2019, 11:07:17 pm »
The behaviour of putting A on the bus seems to be an accident

no, this behavior is well known and works on all Z80 clones.

That's why the Z180, which uses a quarter of the 00-FF space for the internal peripherals, uses the (C),reg form unchanged but adds the IN0/OUT0 (immed),reg instructions to do the right thing in 16 bit IO spaces without breaking Z80 compatibility. I never use the original funky versions on the Z180!

hm, I also never used Z180, but one time I tried to use it's code on Z80 and it seems to work ok.
So I think they should be byte-compatible. Do you know what is the opcode of IN0/OUT0?
Just want to check how it corresponds to Z80 opcode...

Found some doc for Z180, it claims that Z180 also uses register A for A15..A8, the same as Z80:
https://www.wfms.org/sb180/z180qa.pdf
Code: [Select]
A) 8080 type instruction
IN A,(n) OUT (n),A
A15-A8 ←Acc

It also claims that the new instructions IN0/OUT0 uses zero for A15..A8. These instructions was added for on-chip peripherals.
Code: [Select]
D) Z180 original instructions which force A15-A8 to 0
IN0 OUT0 OTIM OTIMR OTDM OTDMR TSTIO
A15-A8 ←0

Very interesting what is opcode for IN0/OUT0, because all non-prefixed opcodes already used by Z80. So I think Z180 uses some unused prefix for these instructions

Updated: found it in z180 emulator source code
https://github.com/lgblgblgb/xep128/blob/master/z80ex/z180ex.c

0xED 0x08 : IN0  C,(n)
0xED 0x09 : OUT0 (n),C

For Z80 these opcodes works as undocumented NOP :)
« Last Edit: February 28, 2019, 11:28:27 pm by radiolistener »
 
The following users thanked this post: nick_d


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf