My first post on Cemetech Very Happy !!

So I have wanted to write an OS for a while now while using my schools (linux supporting) chromebook.
I barley got it working on linux, especially crostini's quirky usb stuff making linking weird.
So I pulled out this old windows computer.


I want to write my filesystem but don't really understand how to start writing and erasing flash.I know i have to unlock from a privledged page and then do some sequence but the pe jumps and stuff I don't understand.
Can anyone explain or give example code with lots of comments
Sorry if this is lengthy and thankyou
(had bad wording, had to edit once)
The relevant things are port protection and the flash command interface.

Unlocking flash, as you noted, requires unlocking it by writing to port 0x14, which is protected by the calculator ASIC. There's a block of logic inside the calculator's ASIC that looks for the bytes 0, 0, 0xed, 0x56, 0xf3 to be read in sequence from protected addresess in flash, and when that sequence is detected then the following instruction is allowed to write to a protected port.

As for programming flash, these sequences are defined by the flash chip and summarized nicely in Table 5 of the datasheet:

Your code needs to arrange for the appropriate sequence of address/data pairs to be sent to the flash, which means your code must not be executing from flash itself and nothing else may either (like an interrupt handler).

Looking at the code to write a byte (from the WikiTI page I linked above):
Code:
writeFlashByteRaw:
; Flash program sequence
   ld   a, 0AAh   ; First bus cycle---unlock
   ld   (0AAAh), a
   ld   a, 55h   ; Second bus cycle---unlock
   ld   (0555h), a
   ld   a, 0A0h   ; Third bus cycle---write command
   ld   (0AAAh), a
   ld   (hl), b   ; Fourth bus cycle---program data

This clearly maps to row 12 of the table: a byte program command.

The algorithm for polling when a write completes is a bit less clear, but for that you've got Table 6 and the associated text:

Code:
   ld a,b
   xor   (hl)
   bit   7, a
   jr   z, programDone
   bit   5, (hl)
   jr   z, programWaitLoop
abortProgram:
   ld   a, 0F0h
   ld   (0000h), a
   inc   a
programDone:
   ret
Here B contains the data written, so xor (hl) is checking which bits of the data being read from the chip have flipped. "DQ7#" means it changes state when program is in progress and goes back when done, so this jumps to programDone when bit 7 returns to the value it had in the written byte. Bit 5 gets set to 1 if the write times out and this then sends a Reset command (row 2 in table 5) if that occurs, to get the chip back to normal operation.
I understande the first table , plus i knew the fact that from a privledged page i have to

Code:

  xor a
  out ($14),a
  ret

to lock
and to unlock

Code:

  ld a,1
  out ($14),a
  ret

but I dont understand this knightos code that is suppsose to this simple task

Code:

.org 0x4000

    rst 0 ; Crash before runaway code breaks things

jp _unlockFlash
jp _lockFlash

_unlockFlash:
    ld a,i
    jp pe, _
    ld a, i
_:  push af
    di
    ld a, 1
    nop
    nop
    im 1
    di
    out (PORT_FLASHRWCONTROL), a
    pop af
    ret po
    ei
    ret
   
_lockFlash:
    ld a,i
    jp pe, _
    ld a, i
_:  push af
    di
    xor a
    nop
    nop
    im 1
    di
    out (PORT_FLASHRWCONTROL), a
    pop af
    ret po
    ei
    ret


EDIT: does the fact that the first table has the command and 2 sets of possible addresses mean i can starat by writing $aa to $x555 or $xaaa and it wont make a difference
ti_kid wrote:
I understande the first table , plus i knew the fact that from a privledged page i have to

Code:

  xor a
  out ($14),a
  ret

to lock
and to unlock

Code:

  ld a,1
  out ($14),a
  ret

That won't work, because you must use the appropriate sequence when writing to a privileged port otherwise your write will be ignored.

Quote:
but I dont understand this knightos code that is suppsose to this simple task
Since now you've shared the code you're confused about, I can comment on it.

Code:

_unlockFlash:
    ld a,i     ; Copy IFF2 to P/V flag
    jp pe, _   ; Skip if IFF2 is set
    ld a, i    ; Not sure why we're reloading
_:  push af    ; Stash flags for later
    di         ; Disable interrupts to ensure the critical sequence doesn't get interrupted
    ld a, 1    ; Value to write to flash control port
    ; Critical sequence, cannot be modified otherwise the write won't work
    nop
    nop
    im 1
    di
    out (PORT_FLASHRWCONTROL), a
    ; End critical sequence
    pop af    ; Restore stashed flags
    ret po    ; Return early if IFF2 was clear (interrupts were disabled to begin)
    ei        ; .. otherwise enable interrupts before returning
    ret


Quote:
EDIT: does the fact that the first table has the command and 2 sets of possible addresses mean i can starat by writing $aa to $x555 or $xaaa and it wont make a difference
Only the byte commands are usable because the calculator has the flash configured in byte mode (which is set by strapping one of the pins on the flash chip). Word-mode commands won't work.
Oh I didn't see the [Word] and [Byte] labels on the side, thank you for all the help especially on these comments also I'm guessing that the start of the code
Code:
 _unlockFlash:
  ld a,i
  jp pe, _
  ld a,i
_: push af

can be just

Code:
  push af
  
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