@@ -213,15 +213,15 @@ export class AVRIOPort {
213
213
cpu . writeHooks [ portConfig . DDR ] = ( value : u8 ) => {
214
214
const portValue = cpu . data [ portConfig . PORT ] ;
215
215
cpu . data [ portConfig . DDR ] = value ;
216
- this . updatePinRegister ( portValue , value ) ;
217
216
this . writeGpio ( portValue , value ) ;
217
+ this . updatePinRegister ( value ) ;
218
218
return true ;
219
219
} ;
220
220
cpu . writeHooks [ portConfig . PORT ] = ( value : u8 ) => {
221
221
const ddrMask = cpu . data [ portConfig . DDR ] ;
222
222
cpu . data [ portConfig . PORT ] = value ;
223
- this . updatePinRegister ( value , ddrMask ) ;
224
223
this . writeGpio ( value , ddrMask ) ;
224
+ this . updatePinRegister ( ddrMask ) ;
225
225
return true ;
226
226
} ;
227
227
cpu . writeHooks [ portConfig . PIN ] = ( value : u8 ) => {
@@ -230,8 +230,8 @@ export class AVRIOPort {
230
230
const ddrMask = cpu . data [ portConfig . DDR ] ;
231
231
const portValue = oldPortValue ^ value ;
232
232
cpu . data [ portConfig . PORT ] = portValue ;
233
- this . updatePinRegister ( portValue , ddrMask ) ;
234
233
this . writeGpio ( portValue , ddrMask ) ;
234
+ this . updatePinRegister ( ddrMask ) ;
235
235
return true ;
236
236
} ;
237
237
// The following hook is used by the timer compare output to override GPIO pins:
@@ -258,7 +258,9 @@ export class AVRIOPort {
258
258
break ;
259
259
}
260
260
}
261
- this . writeGpio ( cpu . data [ portConfig . PORT ] , cpu . data [ portConfig . DDR ] ) ;
261
+ const ddrMask = cpu . data [ portConfig . DDR ] ;
262
+ this . writeGpio ( cpu . data [ portConfig . PORT ] , ddrMask ) ;
263
+ this . updatePinRegister ( ddrMask ) ;
262
264
} ;
263
265
264
266
// External interrupts
@@ -355,11 +357,11 @@ export class AVRIOPort {
355
357
if ( value ) {
356
358
this . pinValue |= bitMask ;
357
359
}
358
- this . updatePinRegister ( this . cpu . data [ this . portConfig . PORT ] , this . cpu . data [ this . portConfig . DDR ] ) ;
360
+ this . updatePinRegister ( this . cpu . data [ this . portConfig . DDR ] ) ;
359
361
}
360
362
361
- private updatePinRegister ( port : u8 , ddr : u8 ) {
362
- const newPin = ( this . pinValue & ~ ddr ) | ( port & ddr ) ;
363
+ private updatePinRegister ( ddr : u8 ) {
364
+ const newPin = ( this . pinValue & ~ ddr ) | ( this . lastValue & ddr ) ;
363
365
this . cpu . data [ this . portConfig . PIN ] = newPin ;
364
366
if ( this . lastPin !== newPin ) {
365
367
for ( let index = 0 ; index < 8 ; index ++ ) {
0 commit comments