Your methodology for the input buffer does make sense - I know that the Apple ][ allocates a 256 byte input buffer which the system parses after Return is pressed. And since only one program is going to be using the input buffer at a time, there really is no point of dynamically allocating it if you don't want to.

Also, I have read some of those readings that Ashbad posted, and I agree that they will be helpful to you. I'll try to explain dynamic memory allocation concisely so that you'll understand what you'd have to do.
1. At the beginning, you know that you have access to some large chunk of memory. You know its position and size, and you want to be able to dynamically allocate that block of memory to any program that requires it. So, you start by setting aside some data to tell you where that is.
2. Sooner or later, someone will ask for some memory. You go into your data that tells you about your memory and see if you have enough space to give them. If you do, you subtract that off the end of your block and hand the pointer to the requested memory back to them. If you don't, return NULL to indicate that there is no memory for them to use.
3. The hard part of this is when someone says that they're done with the memory you gave them. This immediately raises two problems:
- First, there is the problem of how large that memory was in the first place. One option would be to force the system to remember how big its allocations were. While that is workable in some situations, it would be much more convenient to just free the pointer in question. Thus, when handing memory back to the user, you not only need to subtract off the memory they're taking, but also two extra bytes before the pointer to store the size of the allocation (which you write in at the time). Then, when they're done with the memory, you simply go back a little, read those two bytes, and give yourself all that memory back.
- Then comes the much more obvious problem of fragmentation. The allocation they gave back may well be in between two other outstanding allocations, so we need to resolve that problem. The way we do this is add a field to our block data (the one that told us the position and size of our original block) that can point to another piece of data indicating where a viable block is. This modification involves several modifications (and opportunities) in both getting and giving memory:
- When freeing some memory, you need to check if that memory is adjacent to some other free memory (one or two blocks).
- If it's adjacent to just the end of one, you just add the size back.
- If it's adjacent to just the beginning of one, you add the size back and subtract the position back.
- If it's adjacent to neither, you allocate a new block (using your dynamic allocation call you already have), and attach it to one of the blocks you already have.
- If it's adjacent to both, you delete the later block (using the deallocation call you're in the middle of writing) and add its size plus the size of the allocation you just got back to the size of the earlier block. (NOTE that this is not implemented in my code piece above).
- When searching for a desired block (either for one that's big enough or one that's adjacent), you do the following:
- Keep track of where you currently are (this tracking will be persistent over multiple searches)
- Look at each block, one by one. If it fits your conditions, follow through with them. If it doesn't, go on by setting the current pointer to the "next" pointer on the node you're currently looking at.
- If you got back to where you started, abort your search.
- When inserting a new node into the list, you decide which node you want to put it after (any node will do, let's call it the current node). Set your new node's next pointer to the current node's next node, and then set your current node's next pointer to the new node.
- When creating your initial node, set it's "next" to itself. That way the list will always go in a loop, even when inserting new nodes. (NOTE that my memory allocator does NOT do this, but works the same nonetheless)
- And you will note that the only list node you have stored statically is the one at the very beginning, which tells you where your master block is. All of the other nodes are stored happily in your dynamic memory, allowing you to have as many nodes as you want.
- (For more on these semantics, see http://en.wikipedia.org/wiki/Linked_list, since this data structure follows that pattern)
- And now that you're using this linked list structure, you can go ahead and take advantage of that by starting your system with as many blocks of memory as you want, which may or may not be contiguous. For instance, you can make one for each and every page of RAM.
Essentially, when the system is used properly, it keeps careful track of what memory is free for you to use, and programs can go on allocating and deallocating new pieces of memory freely.

In your case, you would want to extend this by having two separate lists - one for RAM for general purpose allocations, and one for Archive memory for saving files. Since you can't easily write to Flash, you should store enough data with your files (at least being able to mark them dirty) to reconstruct your Archive nodes by parsing it, so you don't lose your filesystem to a RAM clear.
I'll take care of memory management later, for now, update ! Very Happy

After hours of work, I've finally got backspace erasing working !



You can't imagine how much time I wasted on it looking for a dummy error : I was trying to do
Code:
 add hl,$F000
Razz
yep.


Code:
add hl,$F000
got me far too!

How large is this OS? 512KB on-calc (as formatted)?
The 8xu is 78K large. It's the 83+ BE ROM which is 512K, not the OS itself Smile
is it possible to change formatting of the ROM so that you can make the os smaller, and take up less space (adding more free room), or is 512K the limit?
I don't know ...I use KnightOS's build system that SirCmpwn provided me. And 512K isn't the limit, since for example 83+s' TI-OS 1.19 is 540K large (only the 8xu, not the ROM).
are you planning on making your OS support linking to a computer and sending/recieving specially made programs/games to be run by this OS?
Of course I plan it Smile I planned it to be the main purpose of this OS : making 3rd-party programming easier.
matrefeytontias wrote:
I don't know ...I use KnightOS's build system that SirCmpwn provided me. And 512K isn't the limit, since for example 83+s' TI-OS 1.19 is 540K large (only the 8xu, not the ROM).

The TI-OS 1.19 is 540K large because it's encrypted, which bloats its size compared to what it is on the calc.

And this is nice progress! By the way, forget what I said about using my memory management system to page your Archive - since you can't clear bits without clearing the entire page, you can safely assume that any space of zeroes is free space to store files. But the directory tree is still valid advice, and you can also store the file contents along with the file metadata.

As for loading programs, since you aren't constrained to the TIOS's memory rules, you can use memory mapping to make your programs run at $4000, leaving 32K of RAM wide open for you. Of course, since this requires 3 RAM pages to work properly, this will only work on the 84 Plus or either Silver Edition. Look at this for more details: http://wikiti.brandonw.net/index.php?title=83Plus:Memory_Mapping
There's no way I'd made my OS 83+ BE-incompatible, since I only own a 83+ BE.

Also, why do you say that running programs from $4000 will let 32K of RAM ? When booting, the OS unlocks RAM from $C000 to $FFFF, making this area usable, so it's more like 48K of free RAM that the programs will have on a 83+ SE/84+, and 32K on a 83+ BE.
matrefeytontias wrote:
There's no way I'd made my OS 83+ BE-incompatible, since I only own a 83+ BE.

Totally understandable. In that case, you could make programs run starting from $8000 on RAM Page 1, initializing the proper sized block in the memory allocator.

Quote:
Also, why do you say that running programs from $4000 will let 32K of RAM ? When booting, the OS unlocks RAM from $C000 to $FFFF, making this area usable, so it's more like 48K of free RAM that the programs will have on a 83+ SE/84+, and 32K on a 83+ BE.

What I meant is that your program has at least 32 K of wide open space to use for data and calculations, both stack and heap, that isn't taken up by the program's code. However, if you use RAM page 0 to keep your OS's static variables as well as your call stack, you would have slightly less space to work with.
So maybe I'll do this : keep a 3-bytes pointer to something like TI-OS's VAT in RAM (page, low and high), this VAT-ish thing and all variables in Flash and run programs from $8000. I think it's the configuration which lets the most free space for program execution.
Update !

Got the argument parsing work Smile



I planned command input like this : when you input a command, you can specify two kinds of parameters, classic and special. A special parameter is the minus character - followed by one letter, and a classic parameter is at least one letter, A to Z, or one number, 0 to 9. Special parameters will be copied to another memory area than classic parameters so they'll be easier to handle by user programs.

As I said sonner, each and every command will be a program stored in the filesystem (currently working on it) and which will be ran with the given arguments, if any. So, the OS itself will be a tiny command-line which can run programs, a filesystem, and many, many functions for the programmers to use in their programs.

The main interest of this OS is that I try to make it use as little RAM as possible, so there will be a great free space for user programs. Also, I try to provide as many routines as possible to make user programs as small as possible, allowing for even more features in each.
Can I see the source code?
Of course, I just made a GitHub repository : https://github.com/matrefeytontias/cmdOS
matrefeytontias wrote:
The main interest of this OS is that I try to make it use as little RAM as possible, so there will be a great free space for user programs. Also, I try to provide as many routines as possible to make user programs as small as possible, allowing for even more features in each.
Good! Don't forget to make $C000-$FFFF executable so that that's feasible. Smile Presumably you'll have $0000 be your fixed OS page, as you must, then $4000 have a swapped-in OS page with routines, and $8000-$FFFF mostly executable except for a few OS RAM areas and the stack?
I unlock all available RAM during boot, so it will stay like that for the whole OS's life Smile

And yeah, $0000 to $3FFF will be the fixed OS page, $4000 to $7FFF is the ROM page 0 with all of the functions, and $8000 to $FFFF is free mem with a few OS RAM areas.
matrefeytontias wrote:
I unlock all available RAM during boot, so it will stay like that for the whole OS's life Smile

And yeah, $0000 to $3FFF will be the fixed OS page, $4000 to $7FFF is the ROM page 0 with all of the functions, and $8000 to $FFFF is free mem with a few OS RAM areas.


Are you going to implement a task scheduler/psuedo-multitasking? If so, I'd consider thinking about running programs from non-RAM pages, and organizing RAM to hold the stacks/heaps/etc. for each program instead; that was what I planned/partially implemented for NucleoOS. However, if you're not doing any multitasking, using RAM for program execution as well is a very sound decision.

EDIT: Here was some of the original planning for Nucleo; the thread might be of interest of you, namely because of my notes on the matter and some great feedback from AHelper and christop: http://www.cemetech.net/forum/viewtopic.php?t=7422&start=0 You might also want to at least skim through the (now monstrously large) GlassOS thread, and perhaps look at the GOS source (which I'm almost positive is open-sourced) -- it's by far the best example of a 3rd party OS you're going to find for inspiration.
My way is all planned : no multitasking, execution from command line in RAM, files always in archive, and maximum opening to 3rd-party development. That means, I'll need help to setup a connection between calc and PC, and between two calcs.
cool!

Are you planning on doing a pure "cmd" feel, or would you eventually do a TI-OS/GUI feel?
  
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 2 of 3
» 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