# HG changeset patch
# User JeanDo
# Date 1305981536 -7200
# Node ID d5240792be51833db2cb6211b892310ddb95f326
# Parent  06299199dfb9aa4408ec65a35864104eb2ee8335
BUGFIX Altimeter random value (SAFE_2BYTE_COPY was not bank safe).

diff -r 06299199dfb9 -r d5240792be51 code_part1/OSTC_code_asm_part1/isr.asm
--- a/code_part1/OSTC_code_asm_part1/isr.asm	Fri May 20 01:34:59 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/isr.asm	Sat May 21 14:38:56 2011 +0200
@@ -33,15 +33,17 @@
 ; Because the ISR can happend at any time, the read should be redone if bytes
 ; changed inbetween.
 ;
-; NOTE: Destination might be in any bank, so be BANK SAFE on b
-
-SAFE_2BYTE_COPY MACRO  a, b
+; Trashes: WREG and TABLAT
+; NOTE: Destination might be in any bank, so be BANK SAFE.
+;
+SAFE_2BYTE_COPY MACRO  from, to
         local   retry
 retry:
-        movf    a+1,W                   ; High byte in W, (CURRENT BANK ONLY)
-        movff   WREG,b+1                ; and destination.
-        movff   a,b                     ; Copy low byte.
-        xorwf   a+1,W                   ; High byte changed ??? (CURRENT BANK ONLY)
+        movff   from+1,WREG             ; High byte in W.
+        movff   WREG,to+1               ; and destination.
+        movff   from+0,to+0             ; Copy low byte.
+        movff   from+1,TABLAT           ; another bank-safe read.
+        xorwf   TABLAT,W                ; High byte changed ?
         bnz     retry
         ENDM