### Author Topic: [z80] Writing to flash  (Read 8587 times)

0 Members and 1 Guest are viewing this topic.

#### Matrefeytontias

• Axe roxxor (kinda)
• LV10 31337 u53r (Next: 2000)
• Posts: 1982
• Rating: +310/-12
• Axe roxxor
##### Re: [z80] Writing to flash
« Reply #15 on: March 23, 2013, 10:18:40 am »
Oh I see. So instead of rearchiving it to the same place and then erase the entire sector, it archives it in a free sector. Then when there are no free sectors left, it Garbage Collect and then erase sectors with no variables inside.

But how do I know if a sector is OK to be erased or if there's something inside since you can't turn bits ON when they're OFF ?

EDIT : maybe I can turn to $FE the first byte of a sector when it's in use, and then turn it to 0 when it's ready to be erased ? « Last Edit: March 23, 2013, 10:22:53 am by Matrefeytontias » #### Xeda112358 • they/them • Moderator • LV12 Extreme Poster (Next: 5000) • Posts: 4687 • Rating: +718/-6 • Calc-u-lator, do doo doo do do do. ##### Re: [z80] Writing to flash « Reply #16 on: March 23, 2013, 10:22:00 am » The OS stores a byte (FE, maybe?) at the start of the file data. When it is marked for deletion, reset bit 1 to make it FC. Follow that by the size of the data so that you can figure out where the next variable is. Once you reach an FF byte, that is free to start writing data to. You have to be careful about how you handle crossing sectors. The OS usually does not let variable be split across sectors, but being split across flash pages is fine. #### Matrefeytontias • Axe roxxor (kinda) • LV10 31337 u53r (Next: 2000) • Posts: 1982 • Rating: +310/-12 • Axe roxxor ##### Re: [z80] Writing to flash « Reply #17 on: March 23, 2013, 10:24:54 am » Yeah I just edited But the danger is that a data which was in flash actually had a$FF byte inside. And I can't put a size word since I can't easily write what I want.

EDIT : By the way, how do you read from flash ? The page only says how to write to it ...
« Last Edit: March 23, 2013, 11:51:44 am by Matrefeytontias »

#### Xeda112358

• they/them
• Moderator
• LV12 Extreme Poster (Next: 5000)
• Posts: 4687
• Rating: +718/-6
• Calc-u-lator, do doo doo do do do.
##### Re: [z80] Writing to flash
« Reply #18 on: March 23, 2013, 01:20:14 pm »
You can definitely put a size word O.o And if you put in a size word, you just jump over all of the data, so you don't need to worry about a program having an FF since you jump over it. The bytes might look like:
FE0900EF004048656C6C6FC9 FE040001020304 FFFFFFFF...

When you read the first byte, it is FE, so the next two bytes are 0900 (the size bytes for 9 bytes), so you skip the next 9 bytes and now the pointer is at FE, the next size bytes tell it to skip 4 bytes, and now you are pointing to an FF byte that you can overwrite.

#### Dapianokid

• LV7 Elite (Next: 700)
• Posts: 539
• Rating: +46/-27
• That one dude
##### Re: [z80] Writing to flash
« Reply #19 on: March 23, 2013, 01:43:16 pm »
If I were to write an OS, and this is just me, I'd have variable storage hinge entirely on my VAT, and update my VAT (or MFT) updated every time a variable is moved if I, say, need a new sector to be erased. I'd copy the contents of that sector to some area in RAM and then write that data to a new sector.
Please tell me I'm not a newb for suggesting this!
Keep trying.

#### Matrefeytontias

• Axe roxxor (kinda)
• LV10 31337 u53r (Next: 2000)
• Posts: 1982
• Rating: +310/-12
• Axe roxxor
##### Re: [z80] Writing to flash
« Reply #20 on: March 23, 2013, 04:35:04 pm »
I can't afford to copy the content of a whole sector to RAM, because let's say that the calc is running a 32K-large program (all of the available RAM of a 83+ BE), I can't copy 16K of datas without overwriting some parts of this program. I need everything to be done in archive.

That's why I'll keep everything related to a program bundled, including its content, which won't change since there are no ways to edit stuffs. As I said in the cmdOS thread, every feature to include will be up to 3rd-party programmers, which are way better than me anyway.

#### Lionel Debroux

• LV11 Super Veteran (Next: 3000)
• Posts: 2135
• Rating: +290/-45
##### Re: [z80] Writing to flash
« Reply #21 on: March 23, 2013, 04:45:06 pm »
Quote
... for the NOR Flash found, for instance, in TI-Z80 and TI-68k calculators
The NAND Flash found in Nspires, and most large Flash chips in fact (NAND is denser, AFAIK), is another story.
The rule of thumb is that any random access / eXecute In Place Flash memory is NOR.
« Last Edit: March 23, 2013, 04:45:38 pm by Lionel Debroux »
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.

#### DrDnar

• LV7 Elite (Next: 700)
• Posts: 546
• Rating: +97/-1
##### Re: [z80] Writing to flash
« Reply #22 on: March 23, 2013, 04:56:50 pm »
The ASIC will only let code on certain flash pages unlock flash. See port 21 for a list of such pages and the page on protected ports for how to unlock flash. Prudence suggests that normally you keep flash locked, although frankly, it's actually hard to issue a write or erase command accidentally, so keeping flash unlocked all the time isn't that dangerous. Nevertheless, you should confine modifying protected ports and writing to flash to be an OS-only thing. But, it would be nice to have functions for overwriting bytes in existing files, so user programs can have the option of leaving blank space in files to be filled later for whatever purpose.
« Last Edit: March 23, 2013, 05:02:49 pm by DrDnar »
"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

#### Matrefeytontias

• Axe roxxor (kinda)
• LV10 31337 u53r (Next: 2000)
• Posts: 1982
• Rating: +310/-12
• Axe roxxor
##### Re: [z80] Writing to flash
« Reply #23 on: March 23, 2013, 06:11:12 pm »
It's even something hard to me to reset a bit of the archive, don't ask me to overwrite a byte

#### Dapianokid

• LV7 Elite (Next: 700)
• Posts: 539
• Rating: +46/-27
• That one dude
##### Re: [z80] Writing to flash
« Reply #24 on: March 23, 2013, 06:27:01 pm »
TIOS uses a swap sector, doesn't it?
Do that!
Keep trying.

#### thepenguin77

• z80 Assembly Master
• LV10 31337 u53r (Next: 2000)
• Posts: 1591
• Rating: +823/-5
• The game in my avatar is bit.ly/p0zPWu
##### Re: [z80] Writing to flash
« Reply #25 on: March 24, 2013, 10:23:24 pm »
If you really want to see how to write to flash, you should take a look at how the boot code does it. (Attached) (The random sub_48c5 runs the routine that IX is pointing to in ram).

The boot code does a pretty good job of flash writing, so, you don't have to copy the code line by line, but, in the end, yours should look pretty similar.

And like xeda said, reading from flash is no different than reading from ram. Just swap the page in and go. (Using ports 06 and 07 of course).

Before you get too far in your OS, I would definitely suggest you disassemble the boot code and at least disassemble the boot path through the OS. There are a few reasons I say this, and here they are:
1. You need to see what happens in the boot code before your OS gets control
2. Doing all of this will teach you a bit more about the hardware of the calculator
3. You can learn quite a bit from the different routines in the boot code (and you may actually want to use them)
4. Seeing how TI-OS handles the boot sequence could guide you in writing your own.

Now, you don't have to disassemble these two. But I would highly recommend you do the boot code. I learned so much when I did that and I think it would really help you.
zStart v1.3.013 9-20-2013
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
-Runer112