Author Topic: 8X+ > flash writing question  (Read 13532 times)

0 Members and 1 Guest are viewing this topic.

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 346
  • Rating: +47/-0
    • View Profile
Re: 8X+ > flash writing question
« Reply #15 on: July 03, 2014, 09:44:57 pm »
I took a look at the datasheet, to understand things better.
Also, while i was thinking of a way to optimize the code, i found something worth mentionning (still in the wikiti code example).
First, let me put it there again :
Code: [Select]
   ld a,b
   xor (hl)
   bit 7,a
   jr z,programdone
   bit 5,(hl) !!!
   jr z,programwaitloop
As you can see, the code actually does 2 separate readings (XOR (HL) & BIT 5,(HL)).
The thing is, that if the chip happens to switch from "status" to "data" mode right before the second reading, bit 5 of actual data will be tested, potentially leading to an unwanted abort instruction.
To avoid that, i guess there is no other choice but to read only once, save the reading into a register, to be sure that you read bits 7 & 5 from the same byte.
Am i right about that potential breach ?

#####

As i said earlier, i decided to optimize the code in favor of fast & successful writings.
Here is what i intend to use :
Code: [Select]
;b = byte
;de = address

   ld hl,$0AAA
   ld (hl),l

   ld hl,$0555
   ld (hl),l

   ld a,$A0
   ld ($0AAA),a

   ld a,b
   ld (de),a

read

   ld a,(de)

   cp b ; yep, cp the fastest option for fast & successful writings (using xor directly would add 4 cycles for the backup)
   ret z

   ld c,a ; backup, to be sure to read bit 5 of the same byte later

   xor b
   ret p

   bit 5,c
   jp z,read

   ld a,$F0
   ld ($0000),a

   scf

   ret

;cf = 0 (success) | 1 (failure)
Thx in advance for letting me know if something is wrong or if you think it could be optimized more...
« Last Edit: July 05, 2014, 03:32:57 pm by the_mad_joob »

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: 8X+ > flash writing question
« Reply #16 on: July 04, 2014, 05:05:45 am »
I think in the majority of cases jr z will be faster than jp z, i'm not sure but i would assume that you wouldn't come across an error very often. When jr doesn't take the jump, it's both faster and smaller than jp (i'm talking about after the bit 5,c).

EDIT: Disregard what i said, i just looked at the code a bit more closely and realize that bit 5 would be set not reset if there was an error  :-X
« Last Edit: July 04, 2014, 06:03:31 am by chickendude »

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: 8X+ > flash writing question
« Reply #17 on: July 05, 2014, 03:11:48 pm »
The thing is, that if the chip happens to switch from "status" to "data" mode right before the second reading, bit 5 of actual data will be tested, potentially leading to an unwanted abort instruction.
Am i right about that potential breach ?
That can happen, and in fact probably happens a lot, but it's not a problem unless your routine also returns an error status. Issuing the reset command in read mode does nothing, so there's no reason to go out of your way to prevent that.
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 346
  • Rating: +47/-0
    • View Profile
Re: 8X+ > flash writing question
« Reply #18 on: July 05, 2014, 03:23:24 pm »
That can happen, and in fact probably happens a lot, but it's not a problem unless your routine also returns an error status. Issuing the reset command in read mode does nothing, so there's no reason to go out of your way to prevent that.
Interesting...
But yes, my code will have to specify if an error occured.
Thx for your time, again =]
« Last Edit: July 05, 2014, 03:31:28 pm by the_mad_joob »

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: 8X+ > flash writing question
« Reply #19 on: July 05, 2014, 03:58:10 pm »
Yes, my code will specify if an error occured.
Thx for your time, again =]
In that case, have the error handler check the data to see if it's actually different, which will be slightly faster.
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 346
  • Rating: +47/-0
    • View Profile
Re: 8X+ > flash writing question
« Reply #20 on: July 05, 2014, 04:08:49 pm »
In that case, have the error handler check the data to see if it's actually different, which will be slightly faster.
Good to know.
Is the error handler system-dependant ?
Cause if yes, my project will be totally free from the TI-OS.
I guess i would have to use IM 2 or something to be able to do that...
« Last Edit: July 05, 2014, 04:12:35 pm by the_mad_joob »

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: 8X+ > flash writing question
« Reply #21 on: July 05, 2014, 05:14:00 pm »
Is the error handler system-dependant ?
No, I mean, in your flash write routine, when you see an error, double check if the data is in fact different than what was intended to be written, and only report an error if it's different. This will save you from the logic of retaining the status read value in a register.
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: 8X+ > flash writing question
« Reply #22 on: July 05, 2014, 08:10:51 pm »
Yo Streety =]
Something between an OS and a shell...
That sounds interesting. You have my attention.
I'm not a nerd but I pretend:

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 346
  • Rating: +47/-0
    • View Profile
Re: 8X+ > flash writing question
« Reply #23 on: July 06, 2014, 04:44:16 am »
No, I mean, in your flash write routine, when you see an error, double check if the data is in fact different than what was intended to be written, and only report an error if it's different. This will save you from the logic of retaining the status read value in a register.
Oh, my bad (thought you were talking about using the OS error handler).
I think i'll use that then :
Code: [Select]
;c = byte
;de = address

   ld hl,$0AAA
   ld (hl),l

   ld hl,$0555
   ld (hl),l

   ld a,$A0
   ld ($0AAA),a

   ex de,hl
   ld (hl),c

check

   ld a,c

   xor (hl)
   ret p

   bit 5,(hl)
   jp z,check

   ld a,c

   xor (hl)
   ret p

   ld a,$F0
   ld ($0000),a

   scf

   ret

;cf = 0 (success) | 1 (failure)

That sounds interesting. You have my attention.
I honestly don't know if that project will see the light, but i'll do my best =]

EDIT :

DrDnar, You said earlier that the calc would probably crash if batteries are low during a flash operation.
Isn't DQ5 (bit 5) supposed to handle that ?
Anyway, i already intended to check the batteries before starting any operation, but i guess it would be hard to detect batteries becoming low enough right in the middle of an operation...
« Last Edit: July 06, 2014, 05:11:10 am by the_mad_joob »

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: 8X+ > flash writing question
« Reply #24 on: July 06, 2014, 06:44:16 am »
Yo Streety =]
Something between an OS and a shell...
That sounds interesting. You have my attention.
^ That. :P

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 346
  • Rating: +47/-0
    • View Profile
Re: 8X+ > flash writing question
« Reply #25 on: August 22, 2014, 05:13:12 pm »
It's me, again.
So, does anybody know how i am supposed to handle batteries becoming low in the middle of a writing operation ?
I mean, is it necessary to check them before every single write attempt ?
If yes, that would slow down large writings quite a lot...