VIA 1 CA2 behaviour when switching from output to input

Modding and Technical Issues

Moderator: Moderators

Post Reply
Willymanilly
Vic 20 Newbie
Posts: 8
Joined: Tue Dec 06, 2016 4:20 am
Website: http://www.z64k.com
Location: Australia
Occupation: APS

VIA 1 CA2 behaviour when switching from output to input

Post by Willymanilly »

I've started implementing VIA shift register behaviour for the emulators in Z64K (http://www.z64k.com) and am using the shift register test programs from the VICE repository (https://sourceforge.net/p/vice-emu/code ... 20/via_sr/).

What I don't fully understand is what is triggering the CA2 IRQ flag in the tests that read the interrupt flag. I know the CA2 pin on VIA1 usually acts as an output to control the tape deck motor. My guess that I have implemented into the VIC 20 emulator of Z64K is there must be a delay before CA2 in input mode is grounded. I've used a delay of 407 cycles to be able to pass the tests.

I don't have a real VIC 20 to work with so I am limited in the testing I can do myself. I spoke to the author of the test programs and he confirmed the reference data was created on a plain vic20 with 8k expansion, from a sd2iec. NO tape connected

Can anyone confirm/deny my theory of what is happening reflects what happens on real hardware?

Code: Select all

VIASR10IFR.PRG
    clock : PC  :              AB   DB    AC  X  Y SP           TA   TB   SR IFR CA2 countdown

    579932: 13c7:STA $9110,X   13c7 9d    00 0c 00 fb nv1BdIzC  26ab d727 00 00 0
    579933: 13c8:              13c8 10    00 0c 00 fb nv1BdIzC  26aa d726 00 00 0
    579934: 13ca:              13c9 91    00 0c 00 fb nv1BdIzC  26a9 d725 00 00 0
    579935: 13ca:              911c fe    00 0c 00 fb nv1BdIzC  26a8 d724 00 00 0
    579936: 13ca:              911c 00    00 0c 00 fb nv1BdIzC  26a7 d723 00 00 407  <== change CA2 from output to input (CA2 mode set to 0)
    579937: 13ca:DEX           13ca ca    00 0c 00 fb nv1BdIzC  26a6 d722 00 00 406
    579938: 13cb:              13cb 10    00 0c 00 fb nv1BdIzC  26a5 d721 00 00 405
    .
    .
    .
    580242: 10fb:LDA #$80      10fb a9    00 ff 00 fd Nv1BdIzC  ffff ff9b 00 00 101
    580243: 10fd:              10fc 80    00 ff 00 fd Nv1BdIzC  0000 ff9a 00 00 100
    580244: 10fd:STA $9118     10fd 8d    80 ff 00 fd Nv1BdIzC  ffff ff99 00 00 99
    580245: 10fe:              10fe 18    80 ff 00 fd Nv1BdIzC  0000 ff98 00 00 98
    580246: 1100:              10ff 91    80 ff 00 fd Nv1BdIzC  ffff ff97 00 00 97
    580247: 1100:              9118 80    80 ff 00 fd Nv1BdIzC  0000 ff96 00 00 96
    580248: 1100:LDA #$00      1100 a9    80 ff 00 fd Nv1BdIzC  ffff ff95 00 00 95
    580249: 1102:              1101 00    80 ff 00 fd Nv1BdIzC  0000 ff94 00 00 94
    580250: 1102:STA $9119     1102 8d    00 ff 00 fd nv1BdIZC  ffff ff93 00 00 93
    580251: 1103:              1103 19    00 ff 00 fd nv1BdIZC  0000 ff92 00 00 92
    580252: 1105:              1104 91    00 ff 00 fd nv1BdIZC  ffff ff91 00 00 91
    580253: 1105:              9119 00    00 ff 00 fd nv1BdIZC  0000 0080 00 00 90   <== Timer B = 80
    580254: 1105:LDA #$c0      1105 a9    00 ff 00 fd nv1BdIZC  ffff 007f 00 00 89
    580255: 1107:              1106 c0    00 ff 00 fd nv1BdIZC  0000 007e 00 00 88
    580256: 1107:STA $9114     1107 8d    c0 ff 00 fd Nv1BdIzC  ffff 007d 00 00 87
    580257: 1108:              1108 14    c0 ff 00 fd Nv1BdIzC  0000 007c 00 00 86
    580258: 110a:              1109 91    c0 ff 00 fd Nv1BdIzC  ffff 007b 00 00 85
    580259: 110a:              9114 c0    c0 ff 00 fd Nv1BdIzC  00c0 007a 00 00 84
    580260: 110a:LDA #$00      110a a9    c0 ff 00 fd Nv1BdIzC  00bf 0079 00 00 83
    580261: 110c:              110b 00    c0 ff 00 fd Nv1BdIzC  00be 0078 00 00 82
    580262: 110c:STA $9115     110c 8d    00 ff 00 fd nv1BdIZC  00bd 0077 00 00 81
    580263: 110d:              110d 15    00 ff 00 fd nv1BdIZC  00bc 0076 00 00 80
    580264: 110f:              110e 91    00 ff 00 fd nv1BdIZC  00bb 0075 00 00 79
    580265: 110f:              9115 00    00 ff 00 fd nv1BdIZC  00c0 0074 00 00 78  <== Timer A = c0
    580266: 110f:LDA #$00      110f a9    00 ff 00 fd nv1BdIZC  00bf 0073 00 00 77
    580267: 1111:              1110 00    00 ff 00 fd nv1BdIZC  00be 0072 00 00 76
    580268: 1111:STA $911b     1111 8d    00 ff 00 fd nv1BdIZC  00bd 0071 00 00 75
    580269: 1112:              1112 1b    00 ff 00 fd nv1BdIZC  00bc 0070 00 00 74
    580270: 1114:              1113 91    00 ff 00 fd nv1BdIZC  00bb 006f 00 00 73
    580271: 1114:              911b 00    00 ff 00 fd nv1BdIZC  00ba 006e 00 00 72  <== ACR = 0 (SHIFT mode 0)
    580272: 1114:LDA $9111     1114 ad    00 ff 00 fd nv1BdIZC  00b9 006d 00 00 71
    580273: 1115:              1115 11    00 ff 00 fd nv1BdIZC  00b8 006c 00 00 70
    580274: 1117:              1116 91    00 ff 00 fd nv1BdIZC  00b7 006b 00 00 69
    580275: 1117:              9111 fc    00 ff 00 fd nv1BdIZC  00b6 006a 00 00 68  <== READ ORA (clear CA1 and CA2 IRQ flags)
    580276: 1117:LDA $9110     1117 ad    fc ff 00 fd Nv1BdIzC  00b5 0069 00 00 67
    580277: 1118:              1118 10    fc ff 00 fd Nv1BdIzC  00b4 0068 00 00 66
    580278: 111a:              1119 91    fc ff 00 fd Nv1BdIzC  00b3 0067 00 00 65
    580279: 111a:              9110 ff    fc ff 00 fd Nv1BdIzC  00b2 0066 00 00 64 <== READ ORB  (clear CB1 and CB2 IRQ flags)
    580280: 111a:LDX $03       111a a6    ff ff 00 fd Nv1BdIzC  00b1 0065 00 00 63
    580281: 111b:              111b 03    ff ff 00 fd Nv1BdIzC  00b0 0064 00 00 62
    580282: 111c:              0003 01    ff ff 00 fd Nv1BdIzC  00af 0063 00 00 61
    580283: 111c:STX $911a     111c 8e    ff 01 00 fd nv1BdIzC  00ae 0062 00 00 60
    580284: 111d:              111d 1a    ff 01 00 fd nv1BdIzC  00ad 0061 00 00 59
    580285: 111f:              111e 91    ff 01 00 fd nv1BdIzC  00ac 0060 00 00 58
    580286: 111f:              911a 01    ff 01 00 fd nv1BdIzC  00ab 005f 01 00 57 <== SR = 1
    580287: 111f:LDA $02       111f a5    ff 01 00 fd nv1BdIzC  00aa 005e 01 00 56
    580288: 1120:              1120 02    ff 01 00 fd nv1BdIzC  00a9 005d 01 00 55
    580289: 1121:              0002 10    ff 01 00 fd nv1BdIzC  00a8 005c 01 00 54
    580290: 1121:STA $911b     1121 8d    10 01 00 fd nv1BdIzC  00a7 005b 01 00 53
    580291: 1122:              1122 1b    10 01 00 fd nv1BdIzC  00a6 005a 01 00 52
    580292: 1124:              1123 91    10 01 00 fd nv1BdIzC  00a5 0059 01 00 51
    580293: 1124:              911b 10    10 01 00 fd nv1BdIzC  00a4 005a 01 08 50 <== ACR = 10 (SHIFT mode 4)
    580294: 1124:LDA $911d     1124 ad    10 01 00 fd nv1BdIzC  00a3 0059 01 08 49
    580295: 1125:              1125 1d    10 01 00 fd nv1BdIzC  00a2 0058 01 08 48
    580296: 1127:              1126 91    10 01 00 fd nv1BdIzC  00a1 0057 01 08 47
    580297: 1127:              911d 08    10 01 00 fd nv1BdIzC  00a0 0056 01 08 46
    580298: 1127:STA $0c       1127 85    08 01 00 fd nv1BdIzC  009f 0055 01 08 45  <== 08
    580299: 1128:              1128 0c    08 01 00 fd nv1BdIzC  009e 0054 01 08 44
    580300: 1129:              000c 08    08 01 00 fd nv1BdIzC  009d 0053 01 08 43
    580301: 1129:LDA $911d     1129 ad    08 01 00 fd nv1BdIzC  009c 0052 01 08 42
    580302: 112a:              112a 1d    08 01 00 fd nv1BdIzC  009b 0051 01 08 41
    580303: 112c:              112b 91    08 01 00 fd nv1BdIzC  009a 0050 01 08 40
    580304: 112c:              911d 08    08 01 00 fd nv1BdIzC  0099 004f 01 08 39
    580305: 112c:STA $0d       112c 85    08 01 00 fd nv1BdIzC  0098 004e 01 08 38  <== 08
    580306: 112d:              112d 0d    08 01 00 fd nv1BdIzC  0097 004d 01 08 37
    580307: 112e:              000d 08    08 01 00 fd nv1BdIzC  0096 004c 01 08 36
    580308: 112e:LDA $911d     112e ad    08 01 00 fd nv1BdIzC  0095 004b 01 08 35
    580309: 112f:              112f 1d    08 01 00 fd nv1BdIzC  0094 004a 01 08 34
    580310: 1131:              1130 91    08 01 00 fd nv1BdIzC  0093 0049 01 08 33
    580311: 1131:              911d 08    08 01 00 fd nv1BdIzC  0092 0048 01 08 32
    580312: 1131:STA $0e       1131 85    08 01 00 fd nv1BdIzC  0091 0047 01 08 31  <== 08
    580313: 1132:              1132 0e    08 01 00 fd nv1BdIzC  0090 0046 01 08 30
    580314: 1133:              000e 08    08 01 00 fd nv1BdIzC  008f 0045 01 08 29
    580315: 1133:LDA $911d     1133 ad    08 01 00 fd nv1BdIzC  008e 0044 01 08 28
    580316: 1134:              1134 1d    08 01 00 fd nv1BdIzC  008d 0043 01 08 27
    580317: 1136:              1135 91    08 01 00 fd nv1BdIzC  008c 0042 01 08 26
    580318: 1136:              911d 08    08 01 00 fd nv1BdIzC  008b 0041 01 08 25
    580319: 1136:STA $0f       1136 85    08 01 00 fd nv1BdIzC  008a 0040 01 08 24  <== 08
    580320: 1137:              1137 0f    08 01 00 fd nv1BdIzC  0089 003f 01 08 23
    580321: 1138:              000f 08    08 01 00 fd nv1BdIzC  0088 003e 01 08 22
    580322: 1138:LDA $911d     1138 ad    08 01 00 fd nv1BdIzC  0087 003d 01 08 21
    580323: 1139:              1139 1d    08 01 00 fd nv1BdIzC  0086 003c 01 08 20
    580324: 113b:              113a 91    08 01 00 fd nv1BdIzC  0085 003b 01 08 19
    580325: 113b:              911d 08    08 01 00 fd nv1BdIzC  0084 003a 01 08 18
    580326: 113b:STA $10       113b 85    08 01 00 fd nv1BdIzC  0083 0039 01 08 17  <== 08
    580327: 113c:              113c 10    08 01 00 fd nv1BdIzC  0082 0038 01 08 16
    580328: 113d:              0010 08    08 01 00 fd nv1BdIzC  0081 0037 01 08 15
    580329: 113d:LDA $911d     113d ad    08 01 00 fd nv1BdIzC  0080 0036 01 08 14
    580330: 113e:              113e 1d    08 01 00 fd nv1BdIzC  007f 0035 01 08 13
    580331: 1140:              113f 91    08 01 00 fd nv1BdIzC  007e 0034 01 08 12
    580332: 1140:              911d 08    08 01 00 fd nv1BdIzC  007d 0033 01 08 11
    580333: 1140:STA $11       1140 85    08 01 00 fd nv1BdIzC  007c 0032 01 08 10  <== 08
    580334: 1141:              1141 11    08 01 00 fd nv1BdIzC  007b 0031 01 08 9
    580335: 1142:              0011 08    08 01 00 fd nv1BdIzC  007a 0030 01 08 8
    580336: 1142:LDA $911d     1142 ad    08 01 00 fd nv1BdIzC  0079 002f 01 08 7
    580337: 1143:              1143 1d    08 01 00 fd nv1BdIzC  0078 002e 01 08 6
    580338: 1145:              1144 91    08 01 00 fd nv1BdIzC  0077 002d 01 08 5
    580339: 1145:              911d 08    08 01 00 fd nv1BdIzC  0076 002c 01 08 4
    580340: 1145:STA $12       1145 85    08 01 00 fd nv1BdIzC  0075 002b 01 08 3  <== 08
    580341: 1146:              1146 12    08 01 00 fd nv1BdIzC  0074 002a 01 08 2
    580342: 1147:              0012 08    08 01 00 fd nv1BdIzC  0073 0029 01 08 1
    580343: 1147:LDA $911d     1147 ad    08 01 00 fd nv1BdIzC  0072 0028 01 09 0
    580344: 1148:              1148 1d    08 01 00 fd nv1BdIzC  0071 0027 01 09 0
    580345: 114a:              1149 91    08 01 00 fd nv1BdIzC  0070 0026 01 09 0
    580346: 114a:              911d 09    08 01 00 fd nv1BdIzC  006f 0025 01 09 0
    580347: 114a:STA $13       114a 85    09 01 00 fd nv1BdIzC  006e 0024 01 09 0  <== 09  What causes CA2 IRQ flag to be triggered?
    580348: 114b:              114b 13    09 01 00 fd nv1BdIzC  006d 0023 01 09 0
    580349: 114c:              0013 09    09 01 00 fd nv1BdIzC  006c 0022 01 09 0
    580350: 114c:LDA $911d     114c ad    09 01 00 fd nv1BdIzC  006b 0021 01 09 0
    580351: 114d:              114d 1d    09 01 00 fd nv1BdIzC  006a 0020 01 09 0
    580352: 114f:              114e 91    09 01 00 fd nv1BdIzC  0069 001f 01 09 0
    580353: 114f:              911d 09    09 01 00 fd nv1BdIzC  0068 001e 01 09 0
    580354: 114f:STA $14       114f 85    09 01 00 fd nv1BdIzC  0067 001d 01 09 0
    580355: 1150:              1150 14    09 01 00 fd nv1BdIzC  0066 001c 01 09 0
    580356: 1151:              0014 09    09 01 00 fd nv1BdIzC  0065 001b 01 09 0
    580357: 1151:LDA $911d     1151 ad    09 01 00 fd nv1BdIzC  0064 001a 01 09 0
    580358: 1152:              1152 1d    09 01 00 fd nv1BdIzC  0063 0019 01 09 0
    580359: 1154:              1153 91    09 01 00 fd nv1BdIzC  0062 0018 01 09 0
    580360: 1154:              911d 09    09 01 00 fd nv1BdIzC  0061 0017 01 09 0
    580361: 1154:STA $15       1154 85    09 01 00 fd nv1BdIzC  0060 0016 01 09 0
    580362: 1155:              1155 15    09 01 00 fd nv1BdIzC  005f 0015 01 09 0
    580363: 1156:              0015 09    09 01 00 fd nv1BdIzC  005e 0014 01 09 0
    580364: 1156:LDA $911d     1156 ad    09 01 00 fd nv1BdIzC  005d 0013 01 09 0
    580365: 1157:              1157 1d    09 01 00 fd nv1BdIzC  005c 0012 01 09 0
    580366: 1159:              1158 91    09 01 00 fd nv1BdIzC  005b 0011 01 09 0
    580367: 1159:              911d 09    09 01 00 fd nv1BdIzC  005a 0010 01 09 0
    580368: 1159:STA $16       1159 85    09 01 00 fd nv1BdIzC  0059 000f 01 09 0
    580369: 115a:              115a 16    09 01 00 fd nv1BdIzC  0058 000e 01 09 0
    580370: 115b:              0016 09    09 01 00 fd nv1BdIzC  0057 000d 01 09 0
    580371: 115b:LDA $911d     115b ad    09 01 00 fd nv1BdIzC  0056 000c 01 09 0
    580372: 115c:              115c 1d    09 01 00 fd nv1BdIzC  0055 000b 01 09 0
    580373: 115e:              115d 91    09 01 00 fd nv1BdIzC  0054 000a 01 09 0
    580374: 115e:              911d 09    09 01 00 fd nv1BdIzC  0053 0009 01 09 0
    580375: 115e:STA $17       115e 85    09 01 00 fd nv1BdIzC  0052 0008 01 09 0
    580376: 115f:              115f 17    09 01 00 fd nv1BdIzC  0051 0007 01 09 0
    580377: 1160:              0017 09    09 01 00 fd nv1BdIzC  0050 0006 01 09 0
    580378: 1160:LDA $911d     1160 ad    09 01 00 fd nv1BdIzC  004f 0005 01 09 0
    580379: 1161:              1161 1d    09 01 00 fd nv1BdIzC  004e 0004 01 09 0
    580380: 1163:              1162 91    09 01 00 fd nv1BdIzC  004d 0003 01 09 0
    580381: 1163:              911d 09    09 01 00 fd nv1BdIzC  004c 0002 01 09 0
    580382: 1163:STA $18       1163 85    09 01 00 fd nv1BdIzC  004b 0001 01 09 0
    580383: 1164:              1164 18    09 01 00 fd nv1BdIzC  004a 0000 01 09 0
    580384: 1165:              0018 09    09 01 00 fd nv1BdIzC  0049 0081 02 29 0  <==TA IRQ flag set
    580385: 1165:LDA $911d     1165 ad    09 01 00 fd nv1BdIzC  0048 0080 02 29 0
    580386: 1166:              1166 1d    09 01 00 fd nv1BdIzC  0047 007f 02 29 0
    580387: 1168:              1167 91    09 01 00 fd nv1BdIzC  0046 007e 02 29 0
    580388: 1168:              911d 29    09 01 00 fd nv1BdIzC  0045 007d 02 29 0
    580389: 1168:STA $19       1168 85    29 01 00 fd nv1BdIzC  0044 007c 02 29 0
    580390: 1169:              1169 19    29 01 00 fd nv1BdIzC  0043 007b 02 29 0
    580391: 116a:              0019 29    29 01 00 fd nv1BdIzC  0042 007a 02 29 0
    580392: 116a:LDA $911d     116a ad    29 01 00 fd nv1BdIzC  0041 0079 02 29 0
    580393: 116b:              116b 1d    29 01 00 fd nv1BdIzC  0040 0078 02 29 0
    580394: 116d:              116c 91    29 01 00 fd nv1BdIzC  003f 0077 02 29 0
    580395: 116d:              911d 29    29 01 00 fd nv1BdIzC  003e 0076 02 29 0
    580396: 116d:STA $1a       116d 85    29 01 00 fd nv1BdIzC  003d 0075 02 29 0
    580397: 116e:              116e 1a    29 01 00 fd nv1BdIzC  003c 0074 02 29 0
    580398: 116f:              001a 29    29 01 00 fd nv1BdIzC  003b 0073 02 29 0
    580399: 116f:LDA $911d     116f ad    29 01 00 fd nv1BdIzC  003a 0072 02 29 0
    580400: 1170:              1170 1d    29 01 00 fd nv1BdIzC  0039 0071 02 29 0
    580401: 1172:              1171 91    29 01 00 fd nv1BdIzC  0038 0070 02 29 0
    580402: 1172:              911d 29    29 01 00 fd nv1BdIzC  0037 006f 02 29 0
    580403: 1172:STA $1b       1172 85    29 01 00 fd nv1BdIzC  0036 006e 02 29 0
    580404: 1173:              1173 1b    29 01 00 fd nv1BdIzC  0035 006d 02 29 0
    580405: 1174:              001b 29    29 01 00 fd nv1BdIzC  0034 006c 02 29 0
    580406: 1174:LDA $911d     1174 ad    29 01 00 fd nv1BdIzC  0033 006b 02 29 0
    580407: 1175:              1175 1d    29 01 00 fd nv1BdIzC  0032 006a 02 29 0
    580408: 1177:              1176 91    29 01 00 fd nv1BdIzC  0031 0069 02 29 0
    580409: 1177:              911d 29    29 01 00 fd nv1BdIzC  0030 0068 02 29 0
    580410: 1177:STA $1c       1177 85    29 01 00 fd nv1BdIzC  002f 0067 02 29 0
    580411: 1178:              1178 1c    29 01 00 fd nv1BdIzC  002e 0066 02 29 0
    580412: 1179:              001c 29    29 01 00 fd nv1BdIzC  002d 0065 02 29 0
    580413: 1179:LDA $911d     1179 ad    29 01 00 fd nv1BdIzC  002c 0064 02 29 0
    580414: 117a:              117a 1d    29 01 00 fd nv1BdIzC  002b 0063 02 29 0
    580415: 117c:              117b 91    29 01 00 fd nv1BdIzC  002a 0062 02 29 0
    580416: 117c:              911d 29    29 01 00 fd nv1BdIzC  0029 0061 02 29 0
    580417: 117c:STA $1d       117c 85    29 01 00 fd nv1BdIzC  0028 0060 02 29 0
    580418: 117d:              117d 1d    29 01 00 fd nv1BdIzC  0027 005f 02 29 0
    580419: 117e:              001d 29    29 01 00 fd nv1BdIzC  0026 005e 02 29 0
    580420: 117e:LDA $911d     117e ad    29 01 00 fd nv1BdIzC  0025 005d 02 29 0
    580421: 117f:              117f 1d    29 01 00 fd nv1BdIzC  0024 005c 02 29 0
    580422: 1181:              1180 91    29 01 00 fd nv1BdIzC  0023 005b 02 29 0
    580423: 1181:              911d 29    29 01 00 fd nv1BdIzC  0022 005a 02 29 0
    580424: 1181:STA $1e       1181 85    29 01 00 fd nv1BdIzC  0021 0059 02 29 0
    580425: 1182:              1182 1e    29 01 00 fd nv1BdIzC  0020 0058 02 29 0
    580426: 1183:              001e 29    29 01 00 fd nv1BdIzC  001f 0057 02 29 0
    580427: 1183:LDA $911d     1183 ad    29 01 00 fd nv1BdIzC  001e 0056 02 29 0
    580428: 1184:              1184 1d    29 01 00 fd nv1BdIzC  001d 0055 02 29 0
    580429: 1186:              1185 91    29 01 00 fd nv1BdIzC  001c 0054 02 29 0
    580430: 1186:              911d 29    29 01 00 fd nv1BdIzC  001b 0053 02 29 0
    580431: 1186:STA $1f       1186 85    29 01 00 fd nv1BdIzC  001a 0052 02 29 0
    580432: 1187:              1187 1f    29 01 00 fd nv1BdIzC  0019 0051 02 29 0
    580433: 1188:              001f 29    29 01 00 fd nv1BdIzC  0018 0050 02 29 0
    580434: 1188:LDA $911d     1188 ad    29 01 00 fd nv1BdIzC  0017 004f 02 29 0
    580435: 1189:              1189 1d    29 01 00 fd nv1BdIzC  0016 004e 02 29 0
    580436: 118b:              118a 91    29 01 00 fd nv1BdIzC  0015 004d 02 29 0
    580437: 118b:              911d 29    29 01 00 fd nv1BdIzC  0014 004c 02 29 0
    580438: 118b:STA $20       118b 85    29 01 00 fd nv1BdIzC  0013 004b 02 29 0
    580439: 118c:              118c 20    29 01 00 fd nv1BdIzC  0012 004a 02 29 0
    580440: 118d:              0020 29    29 01 00 fd nv1BdIzC  0011 0049 02 29 0
    580441: 118d:LDA $911d     118d ad    29 01 00 fd nv1BdIzC  0010 0048 02 29 0
    580442: 118e:              118e 1d    29 01 00 fd nv1BdIzC  000f 0047 02 29 0
    580443: 1190:              118f 91    29 01 00 fd nv1BdIzC  000e 0046 02 29 0
    580444: 1190:              911d 29    29 01 00 fd nv1BdIzC  000d 0045 02 29 0
    580445: 1190:STA $21       1190 85    29 01 00 fd nv1BdIzC  000c 0044 02 29 0
    580446: 1191:              1191 21    29 01 00 fd nv1BdIzC  000b 0043 02 29 0
    580447: 1192:              0021 29    29 01 00 fd nv1BdIzC  000a 0042 02 29 0
    580448: 1192:LDA $911d     1192 ad    29 01 00 fd nv1BdIzC  0009 0041 02 29 0
    580449: 1193:              1193 1d    29 01 00 fd nv1BdIzC  0008 0040 02 29 0
    580450: 1195:              1194 91    29 01 00 fd nv1BdIzC  0007 003f 02 29 0
    580451: 1195:              911d 29    29 01 00 fd nv1BdIzC  0006 003e 02 29 0
    580452: 1195:STA $22       1195 85    29 01 00 fd nv1BdIzC  0005 003d 02 29 0
    580453: 1196:              1196 22    29 01 00 fd nv1BdIzC  0004 003c 02 29 0
    580454: 1197:              0022 29    29 01 00 fd nv1BdIzC  0003 003b 02 29 0
    580455: 1197:LDA $911d     1197 ad    29 01 00 fd nv1BdIzC  0002 003a 02 29 0
    580456: 1198:              1198 1d    29 01 00 fd nv1BdIzC  0001 0039 02 29 0
    580457: 119a:              1199 91    29 01 00 fd nv1BdIzC  0000 0038 02 29 0
    580458: 119a:              911d 29    29 01 00 fd nv1BdIzC  ffff 0037 02 69 0   <==TB IRQ flag set
    580459: 119a:STA $23       119a 85    29 01 00 fd nv1BdIzC  00c0 0036 02 69 0
    580460: 119b:              119b 23    29 01 00 fd nv1BdIzC  00bf 0035 02 69 0
    580461: 119c:              0023 29    29 01 00 fd nv1BdIzC  00be 0034 02 69 0
    580462: 119c:LDA $911d     119c ad    29 01 00 fd nv1BdIzC  00bd 0033 02 69 0
    580463: 119d:              119d 1d    29 01 00 fd nv1BdIzC  00bc 0032 02 69 0
    580464: 119f:              119e 91    29 01 00 fd nv1BdIzC  00bb 0031 02 69 0
    580465: 119f:              911d 69    29 01 00 fd nv1BdIzC  00ba 0030 02 69 0
    580466: 119f:STA $24       119f 85    69 01 00 fd nv1BdIzC  00b9 002f 02 69 0
    580467: 11a0:              11a0 24    69 01 00 fd nv1BdIzC  00b8 002e 02 69 0
    580468: 11a1:              0024 69    69 01 00 fd nv1BdIzC  00b7 002d 02 69 0

User avatar
Mike
Herr VC
Posts: 4843
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: VIA 1 CA2 behaviour when switching from output to input

Post by Mike »

Here's the relevant part of the VIC-20 schematics. I took the freedom to rearrange and clear up the circuit:

Image

As you can see, R21 and C43 form a low-pass circuit. When CA2 is switched to input, it effectively behaves the same as if its output is on H-level. At some time, the voltage divider of the internal pullup in CA2 and R20 + R21|| C43 can cross some threshold voltage and thus trigger an interrupt. For the following calculations, I disregard the base current of Q3:

The pull-up in CA2 is around 5K, thus C43 can be assumed to reach 5 V x (10K / (5K + 1K + 10K)) ~= 3.1 V when it has been discharged before (over R20, with CA2 = 0). CA2 then "sees" 5 V x (11K / (5K + 1K + 10K)) ~= 3.4 V, which is good enough to be detected as H-level.

The time constant is (6K || 10K) x .01 uF ~= 37.5 us. Roughly the same time is needed so U_CA2 increases above 2.4 Volts.

I'd thus expect an interrupt to be triggered, if CA2 is set to positive edge, CA2 output was 0 before and then switched to input, after roughly 40 us. You tell a figure of ~400 cycles - possibly whatever is attached to the tape port could also have an influence ...
User avatar
MCes
Vic 20 Afficionado
Posts: 458
Joined: Fri Jul 24, 2015 1:19 am
Location: Italy

Re: VIA 1 CA2 behaviour when switching from output to input

Post by MCes »

..... Voltage on C 43//R10 is limited at 0,7V by B-E junction of Q3 (Vbe) ......

...when C43 is discharge the level on CA2 input is read as "L", it happens at power switch on of the board or after a sufficient time of CA2 output="L" (C43 discharged by CA2 output via R20 resistor),then the voltage will rise to approx 1,4V [Vbe+ I(R20)*R20], voltage that is a "misunderstanding" level between "L" and "H" (0.4V...2,4V).

Tomorrow I'll can measure the theoretical 1,4V on a real VIC 20....
"Two things are infinite, the universe and human stupidity, and I am not yet completely sure about the universe." (Albert Einstein)
User avatar
Mike
Herr VC
Posts: 4843
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: VIA 1 CA2 behaviour when switching from output to input

Post by Mike »

MCes wrote:..... Voltage on C 43//R10 is limited at 0,7V by B-E junction of Q3 (Vbe) ......
Indeed. Ube *is* effectively clamped. I shouldn't have disregarded the base current. :)
...when C43 is discharge the level on CA2 input is read as "L", it happens at power switch on of the board or after a sufficient time of CA2 output="L" (C43 discharged by CA2 output via R20 resistor),then the voltage will rise to approx 1,4V [Vbe+ I(R20)*R20], voltage that is a "misunderstanding" level between "L" and "H" (0.4V...2,4V).
With I_R20 sourcing around something between 0.5 and 1 mA, you'll most probably arrive at that figure. And the charge-up *will* proceed much slower, i.e. the 400 us figure stated by Willymanilly should be about right.
groepaz
Vic 20 Scientist
Posts: 1191
Joined: Wed Aug 25, 2010 5:30 pm

Re: VIA 1 CA2 behaviour when switching from output to input

Post by groepaz »

i guess we really need 1541 versions of those tests :) (ie its not really a VIA emulation thing - its a VIC20 specific thing here)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
Willymanilly
Vic 20 Newbie
Posts: 8
Joined: Tue Dec 06, 2016 4:20 am
Website: http://www.z64k.com
Location: Australia
Occupation: APS

Re: VIA 1 CA2 behaviour when switching from output to input

Post by Willymanilly »

Thanks for looking into this and explaining the behaviour of that part of the circuit in more detail. My level of knowledge with electronics is only just enough for me to be able to read a schematic and get a basic understanding how the components interact with each other. ;)
possibly whatever is attached to the tape port could also have an influence ...
The reference data was created with an SD2IEC device connected so maybe that has an influence...
Tomorrow I'll can measure the theoretical 1,4V on a real VIC 20....
It will be great to see results of real measurements against the theory! The ~400 us figure I came up with was simply deduced as the number that allowed all the Shift Register Test programs to trigger the CA2 IRQ flag in time in the emulator to match the reference data from the real VIC 20.
Willymanilly
Vic 20 Newbie
Posts: 8
Joined: Tue Dec 06, 2016 4:20 am
Website: http://www.z64k.com
Location: Australia
Occupation: APS

Re: VIA 1 CA2 behaviour when switching from output to input

Post by Willymanilly »

groepaz wrote:i guess we really need 1541 versions of those tests :) (ie its not really a VIA emulation thing - its a VIC20 specific thing here)
1541 versions of the tests would be great in addition to the VIC 20 ones! I know it wasn't intended with your test programs but I think it's a good discovery that the CA2 IRQ can potentially be triggered after resetting the VIA registers to 0 in the VIC 20. :)
groepaz
Vic 20 Scientist
Posts: 1191
Joined: Wed Aug 25, 2010 5:30 pm

Re: VIA 1 CA2 behaviour when switching from output to input

Post by groepaz »

indeed it is. there should be a separate test program just for this =P
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
MCes
Vic 20 Afficionado
Posts: 458
Joined: Fri Jul 24, 2015 1:19 am
Location: Italy

Re: VIA 1 CA2 behaviour when switching from output to input

Post by MCes »

On a real VIC20 board I measured 1,36V on MOS6522, in another board (equipped with rockwell R6522AP) I measured 1,44V.
Both of them are not well recognizable levels: "L" has to be less than 0.4V, "H" has to be more than 2.4V.
"Two things are infinite, the universe and human stupidity, and I am not yet completely sure about the universe." (Albert Einstein)
Willymanilly
Vic 20 Newbie
Posts: 8
Joined: Tue Dec 06, 2016 4:20 am
Website: http://www.z64k.com
Location: Australia
Occupation: APS

Re: VIA 1 CA2 behaviour when switching from output to input

Post by Willymanilly »

I guess that means the time that CA2 will be triggered when transistioning from an output to an input could vary between computers then? For now I will keep the constant time to discharge at around 400us in the emulator to match the reference data I have on hand from the shift register test suite. This as something I'll do more research on at a future date and will update my VIC20 VIA emulation as appropriate when more test programs and/or data becomes available, or when I finally get my hands on a real VIC20. :)
User avatar
MCes
Vic 20 Afficionado
Posts: 458
Joined: Fri Jul 24, 2015 1:19 am
Location: Italy

Re: VIA 1 CA2 behaviour when switching from output to input

Post by MCes »

I think that into VIC20 the CA2 of UAB3 is employed in a way that exclude the possibility of use it as input, consequently its input functionality can't be tested, and don't care....

It can care only if you want transform your VIC20 also in a 6522 chips testing machine, in that case UAB3 place has to be fitted with a "ZIF" socket , Q3 has to be substituted with a mosfet as BS170 (mosfet is drived by voltage and don't clamp the input voltage) and opened R21: now the voltage can reach a full "H" level without loosing the normal VIC20 functionality.

Note: 2SC1815 and BS170 have same container but different pin-out
low_pass.png
"Two things are infinite, the universe and human stupidity, and I am not yet completely sure about the universe." (Albert Einstein)
Post Reply