The following code should write A to (HL). It runs from RAM with Flash unlocked, but doesn't work. Ideas?

Code:
ld b, a
ld a, $AA
ld ($0AAA), a
ld a, $55
ld ($0555), a
ld a, $A0
ld ($0AAA), a
ld a, b
ld (hl), a
Not sure, but TI uses an unlock sequence closer to this, which is also using port 6 to toggle pages like it's part of the flash write sequence. I'm not sure if it's all that necessary since I haven't tried it any other way, but it works.


Code:

;In: C=page B=byteToWrite
 in a,(6)
 ld a,c
 push af
  ld a,2   \ out (6),a
  ld a,$AA \ ld ($6AAA),a
  ld a,1   \ out (6),a
  ld a,$55 \ ld ($5555),a
  ld a,2   \ out (6),a
  ld a,$A0 \ ld ($6AAA),a
 pop af
 out (6),a
 ld (hl),b

EDIT: I know it's not optimized. I pulled it from another project and made hasty edits to it

EDIT2: My guess [removed]... was wrong.

EDIT3: You what!? Forgot to unlock flash? Well, it's good to know that you can get by with putting less bits on the address lines.
No, the tweet was incorrect. It turns out that the problem lies somewhere else, testing your code now.
EDIT: Trying your code did not work.
This is the full code used in Update, which was tested and verified to work on BrandonW's walmart calculator. I don't actually check for write failure, but still. Might want to check that pointer to make sure it's advancing and that you're not trying to write a 1 where a zero is too many times.


Code:
WriteFlashByte: ;Write a byte. B=data,DE=adr,A=page.
 ex de,hl
 ld c,a
 in a,(6)
 ld (WriteFlashByteRestore+1),a
 ld a,c
 push af
  ld a,2   \ out (6),a
  ld a,$AA \ ld ($6AAA),a
  ld a,1   \ out (6),a
  ld a,$55 \ ld ($5555),a
  ld a,2   \ out (6),a
  ld a,$A0 \ ld ($6AAA),a
 pop af
 out (6),a
 ld (hl),b
WriteFlashByteLoop:
 ld a,(hl)
 ld c,a
 xor b
 and $80
 jr z,WriteFlashSuccess
 bit 5,c
 jr z,WriteFlashByteLoop
 ld a,(hl)
 xor b
 and $80
 jr nz,WriteFlashFailure
WriteFlashSuccess:
 call WriteFlashByteRestore
 xor a
 ret
WriteFlashFailure:
 call WriteFlashByteRestore
 xor a
 inc a
 ret
WriteFlashByteRestore:
 ld a,00
 out (6),a
 ld (hl),$F0
 ex de,hl
 inc de
 ret


EDIT: The code that runs this routine doesn't check for failure. I just never checked to see what happens if it fails. If I recall correctly, what happens if you try to write a 1 where a zero is causes the code above to become trapped in an endless loop. I don't check for that sort of problem. You might want to. The Flash chip has other ways to check for failure other than the way TI uses.
You should just be able to AND the existing value with the requested value before the write to avoid this, correct?
EDIT: Further investigation reveals that Flash is, in fact, locked. I'm not sure why; the following executes from 1C/3C/7C:

Code:
ld a, i
push af
ld a, 1
di
nop
nop
im 1
di
out ($14), a
pop af
ret po
ei
ret


Works great on the emulator...
During a supposed Flash write, the value you read isn't exactly the data that should be written. You've got to put it back to read mode before you can do that. I'm probably just not understanding the advice you're giving me, but I noted that your unlock code is a little off.

My guess is that the ASIC wants the following in this order:

Code:
 ld a,1
 nop
 nop
 im 1
 di
 out ($14),a

When I last looked up the information, the order the instructions appear does matter, guesses being that the chip wants to see those instructions in that order before the "out ($14),a".

The code above has been verified on Brandon's TI-84+SE walmart calculator on page $7C. Haven't tried anywhere else but it ought to work.

EDIT: Wait. Your code doesn't look a whole lot different other than an extra di between the ld a,1 and the other stuff. Now that's interesting.

EDIT2: Changed to $7C. What was I thinking? Update can't possibly run from $6C...
Did you mean $7C?
Regardless, I was able to get it working with a dedicated routine for port $14 (instead of out (c), b), and seeing as other ports do not need the sequence to write to, it's all good.
EDIT: Here is my optimized WriteFlashByte routine. Swap the page you want in, and it writes A to (HL):

Code:
and (hl)
ld b, a
ld a, $AA
ld ($0AAA), a
ld a, $55
ld ($0555), a
ld a, $A0
ld ($0AAA), a
ld (hl), b
Loop:
ld a, b
xor (hl)
bit 7, a
jr z, Done
bit 5, (hl)
jr z, Loop
Done: ; Or error
ld (hl), $F0
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement