@@ -288,28 +288,34 @@ bitflags! {
288
288
}
289
289
290
290
trait Notified {
291
- fn notified_add ( self , other : Self , sreg : & mut SReg ) -> Self ;
292
- fn notified_sub ( self , other : Self , sreg : & mut SReg ) -> Self ;
291
+ fn notified_add ( self , other : Self , sreg : & mut SReg , remove : bool ) -> Self ;
292
+ fn notified_sub ( self , other : Self , sreg : & mut SReg , remove : bool ) -> Self ;
293
293
}
294
294
295
295
impl Notified for u8 {
296
- fn notified_add ( self , other : Self , sreg : & mut SReg ) -> Self {
296
+ fn notified_add ( self , other : Self , sreg : & mut SReg , remove : bool ) -> Self {
297
+ println ! ( "notified; check: {:?}" , self . checked_add( other) ) ;
297
298
match self . checked_add ( other) {
298
299
Some ( val) => {
299
- sreg. remove ( SReg :: C ) ;
300
+ if remove {
301
+ sreg. remove ( SReg :: C ) ;
302
+ }
300
303
val
301
304
}
302
305
None => {
306
+ println ! ( "insert" ) ;
303
307
sreg. insert ( SReg :: C ) ;
304
308
self . wrapping_add ( other)
305
309
}
306
310
}
307
311
}
308
312
309
- fn notified_sub ( self , other : Self , sreg : & mut SReg ) -> Self {
313
+ fn notified_sub ( self , other : Self , sreg : & mut SReg , remove : bool ) -> Self {
310
314
match self . checked_sub ( other) {
311
315
Some ( val) => {
312
- sreg. remove ( SReg :: C ) ;
316
+ if remove {
317
+ sreg. remove ( SReg :: C ) ;
318
+ }
313
319
val
314
320
} ,
315
321
None => {
@@ -329,16 +335,16 @@ struct Alu {
329
335
impl Alu {
330
336
fn compute ( & self , aol : bool , aom : bool , aoh : bool , sreg : & mut SReg ) -> u8 {
331
337
match ( aoh, aom, aol) {
332
- ( false , false , false ) => self . primary . notified_add ( self . secondary , sreg) ,
333
- ( false , false , true ) => self . primary . notified_sub ( self . secondary , sreg) ,
338
+ ( false , false , false ) => self . primary . notified_add ( self . secondary , sreg, true ) ,
339
+ ( false , false , true ) => self . primary . notified_sub ( self . secondary , sreg, true ) ,
334
340
( false , true , false ) => self
335
341
. primary
336
- . notified_add ( self . secondary , sreg)
337
- . notified_add ( sreg . contains ( SReg :: C ) as u8 , sreg) ,
342
+ . notified_add ( sreg . contains ( SReg :: C ) as u8 , sreg, true )
343
+ . notified_add ( self . secondary , sreg, false ) ,
338
344
( false , true , true ) => self
339
345
. primary
340
- . notified_sub ( self . secondary , sreg)
341
- . notified_sub ( sreg . contains ( SReg :: C ) as u8 , sreg) ,
346
+ . notified_sub ( sreg . contains ( SReg :: C ) as u8 , sreg, true )
347
+ . notified_sub ( self . secondary , sreg, false ) ,
342
348
( true , false , false ) => !( self . primary & self . secondary ) ,
343
349
( true , false , true ) => self . primary | self . secondary ,
344
350
_ => 0x00 ,
@@ -352,17 +358,17 @@ impl Alu {
352
358
sreg. insert ( SReg :: L ) ;
353
359
sreg. remove ( SReg :: E ) ;
354
360
sreg. remove ( SReg :: G ) ;
355
- } ,
361
+ }
356
362
Ordering :: Equal => {
357
363
sreg. remove ( SReg :: L ) ;
358
364
sreg. insert ( SReg :: E ) ;
359
365
sreg. remove ( SReg :: G ) ;
360
- } ,
366
+ }
361
367
Ordering :: Greater => {
362
368
sreg. remove ( SReg :: L ) ;
363
369
sreg. remove ( SReg :: E ) ;
364
370
sreg. insert ( SReg :: G ) ;
365
- } ,
371
+ }
366
372
} ,
367
373
( false , true , false ) => sreg. set ( SReg :: Z , self . primary == 0 ) ,
368
374
( false , true , true ) => self . primary = bus,
@@ -662,9 +668,7 @@ impl State {
662
668
} else if cw. contains ( ControlWord :: LA ) {
663
669
match self . addr {
664
670
0x0000 ..=0xF7FF => self . mem [ self . addr as usize ] ,
665
- 0xF800 ..=0xFFCF => {
666
- self . text_buffer . get ( self . addr - 0xF800 )
667
- }
671
+ 0xF800 ..=0xFFCF => self . text_buffer . get ( self . addr - 0xF800 ) ,
668
672
0xFFD0 ..=0xFFFC => match self . peripherals . get ( & ( ( self . addr - 0xFFC0 ) as u8 ) ) {
669
673
Some ( periph) => unsafe {
670
674
if let Ok ( stateful_read) =
@@ -817,7 +821,6 @@ impl State {
817
821
818
822
self . timer = self . timer . wrapping_add ( 1 ) ;
819
823
820
-
821
824
if cw. contains ( ControlWord :: CR ) {
822
825
self . ctrl . clock = 0 ;
823
826
} else {
0 commit comments