Omnimaga
Calculator Community => TI Calculators => General Calculator Help => Topic started by: SirCmpwn on September 09, 2010, 07:19:08 pm
-
Hello!
Several people may want to write their own OSes, but I know from experience that it is very hard finding out where to start. I have put together a small tutorial and a basic kernel so that anyone who wants to can get started building their own OSes.
If anyone wants to skip the struggle of simply getting something to boot, I have attached KnightKernelBasic, which is what I gave to Eeems to build Rouge on. It requires ZDS (http://www.brandonw.net/crap/zds368.exe), and I recommend using TI Developer (http://www.sourceforge.net/projects/tidev) with it as well.
Every OS needs these, just to boot:
*Page 00
*A valid OS header
But if you want it to actually do anything useful, it needs to:
*Initialize the LCD
*Set up memory
*Initialize the stack
You should have some other stuff, but that's all you really *need.* In order to boot and display something pretty, you really just need to have page 00, the stack, LCD, and a header. A basic OS header looks like this:
jr Boot
db 0,0,0,0,0,0
db 0, 0 ; rst 08h
db 0,0,0,0,0
db 0, 0 ; rst 10h
db 0,0,0,0,0
db 0,0 ; rst 18h
db 0,0,0,0,0
db 0, 0 ; rst 20h
db 0,0,0,0,0
db 0,0 ; rst 28h
db 0,0,0,0,0
db 0,0 ; rst 30h
db 0,0,0,0,0,0,0
db 0, 0 ; rst 38h / System Interrupt
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0
jp Boot
dw 0A55Ah
Boot:
; This executes at boot
You could copy this into a document and start coding at Boot: and have an OS. This is also valid and signable, and may be sent to a calculator. It is worth noting that you need to have an interrupt or risk crashing the calculator. Add it at rst 38h:
; System Interrupt Routines
SysInterrupt:
exx
ex af, af'
in a, (04h)
bit 0, a
jr nz, HandleON
bit 1, a
jr nz, HandleTimer1
bit 2, a
jr nz, HandleTimer2
bit 4, a
jr nz, HandleLink
jr InterruptDone
HandleON:
in a, (03h)
res 0, a
out (03h), a
set 0, a
out (03h), a
; ON interrupt
jr InterruptDone
HandleTimer1:
in a, (03h)
res 1, a
out (03h), a
set 1, a
out (03h), a
; Timer one interrupt (might be best to merge with timer 2)
jr InterruptDone
HandleTimer2:
in a, (03h)
res 2, a
out (03h), a
set 2, a
out (03h), a
; Timer two interrupt
jr InterruptDone
HandleLink:
in a, (03h)
res 4, a
out (03h), a
set 4, a
out (03h), a
; Link interrupt
InterruptDone:
ex af, af'
exx
ei
ret
This is a basic interrupt with blank spots to put your code. In order to actually compile and test your OS, you need to sign it. It may also be useful to convert it to a ROM for testing. TI Developer (http://www.sourceforge.net/projects/tidev) will do this for you automatically, but if you don't want to use ZDS (http://www.brandonw.net/crap/zds368.exe) or TI Developer, you can use os2tools (http://www.ticalc.org/pub/win/os2tools.zip).
Simple code to set up the LCD so you can draw on it:
ld a, 40h
out (10h), a
ld a, 05h
call LCDDelay
out (10h), a
ld a, 01h
call LCDDelay
out (10h), a
ld a, 3
call LCDDelay
out (10h), a
ld a, 0F6h
call LCDDelay
out (10h), a
And to set up memory (ROM 00\ROM 01\RAM 01\RAM 00):
ld a, 1 ; Set flash page 1 in bank 1.
out (6), a
in a, (2) ;get calc version
rlca ;Roll bit 7 into carry.
ld a, 41h ; Set ram page 1 in bank 2.
jr nc, LowerModel
HigherModel:
out (5),a
ld a,81h
out (7),a
jr Done
LowerModel:
out (6), a
out (7),a
Done:
Now go build some OSes!
-
O_o woah
do we have to use ZDS? I find ZDS very confusing
(of course, I dont think I will be writing OSes very soon XD )
-
You don't have to use ZDS. I just recommend it.
-
I added this to the tutorial thread. It looks great.
What are TI-Developer, ZDS, and os2tools though?
-
ah, ok
now, how would the .bin be turned into a .8xu?
-
TI Developer does it for you, qazz42, or you can use the programs included in os2tools.
meishe91, they are respectively, a development tool to simplify the process (written by yours truly), an IDE, and tools for signing OSes and such.
-
hmm, I will keep this in mind when I learn asm :)
-
Ah ok, so you wrote all of them?
-
He wrote TI-Developer.
Also nice tutorial Sir, I'll sticky this topic in case. I recommend people to be careful with OS projects, though. Those are ambitious projects and I do not recommend them for novice programmers.
-
I've already posted this on Cemetech, but I'll also do it here.
[cross-post starts here]
Tutorials are always good :)
However, I recommend you use .org, unless ZDS doesn't support that.
In the end you will need to compile it. Here's my current OS build script (not that is has anything to build right now :P)
tools\brass "src\Page $00.z80"
tools\bin2hex "Page $00.bin" 20 0000 > "Page $00.hex"
tools\brass "src\Page $1D.z80"
tools\bin2hex "Page $1D.bin" 20 4000 > "Page $1D.hex"
tools\ostools-0.1\multihex 00 "Page $00.hex" 1D "Page $1D.hex" > os.hex
tools\ostools-0.1\packxxu os.hex -o os84.8xu -t 83p -q 0A -v 0.01 -h 255
tools\ostools-0.1\packxxu os.hex -o os83.8xu -t 83p -q 04 -v 0.01 -h 255
tools\rabbitsign\rabbitsign -t 8xu -k tools\keys\0A.key -K 0A -g -p -r os84.8xu
tools\rabbitsign\rabbitsign -t 8xu -k tools\keys\04.key -K 04 -g -p -r os83.8xu
del os83.8xu os84.8xu
copy src\PartesOS.h + *.inc PartesOS.h
del *.bin*
del *.hex
del PartesOS*.8xu
ren os83-signed.8xu "PartesOS 83+.8xu"
ren os84-signed.8xu "PartesOS 84+.8xu"
Note that you need OS Tools (http://www.ticalc.org/archives/files/fileinfo/350/35057.html) and RabbitSign (http://www.ticalc.org/archives/files/fileinfo/383/38392.html) (Windows version here (http://www.ticalc.org/archives/files/fileinfo/420/42035.html)). You'll also need the OS signing keys. (http://brandonw.net/calcstuff/keys.zip)
You can customize this to fit your needs (right now it's set to how my folders are set up, along with the OS name). Note that you need to set your assembler of choice to produce hex output. (Brass for some reason doesn't handle it properly, so I wrote my own bin2hex program. TASM doesn't have this problem)
The -v argument of packxxu can be changed to reflect OS version, though the other arguments should be left as is. Note that this script builds OS's for both the 83+(SE) and 84+(SE).
And yes, go build some OS's! :D
-
He wrote TI-Developer.
Also nice tutorial Sir, I'll sticky this topic in case. I recommend people to be careful with OS projects, though. Those are ambitious projects and I do not recommend them for novice programmers.
Thank you, and OSes are indeed not for the beginning programmer. This is an extremely advanced tutorial.
-
ANother thing to consider is that when KOS comes out, let's not flood the OS scene with like 40 third party OSes with no compatibility between each others. With computers we already have troubles keeping up with 3 different kind of popular OSes x.x
-
How do you have the interrupt code be at 38h?
-
This is potentially very useful for people who want to create an OS! I remember reading somewhere in something about the keys that there should be documentation on how to create an OS... now there is.
It's a shame that there's no documentation for building a 68k OS (that I know of, anyway), as I wanted to eventually have a go at a WFRNG OS for 68k calcs (after I actually learn 68k assembly)...
-
I wanted to eventually have a go at a WFRNG OS for 68k calcs
-.- XD
I wonder if there are still some stuff somewhere about 68K calcs that could explain it... maybe the tutorials are in French, though. Maybe you would have to ask the author of Pedrom
-
Or Punix (http://sourceforge.net/projects/punix/), the other 68k OS that I just found about yesterday when reading some old ticalc.org news article (and with the assistance of a search engine).
But yeah. I didn't feel like looking through yAronet with Google Translate, especially since I don't know enough 68k assembly right now to even begin to work on an OS.
-
Wow I didn't knew about that one. Nice find.
-
Wow I didn't knew about that one. Nice find.
It was in this article (http://www.ticalc.org/archives/news/articles/14/144/144591.html), and mentioned by either Kevin Kofler or Lionel Debroux when they were arguing, in particular about GCC4TI adding back Flash OS support.
-
Oh ok I see, I thought it was in an older news, specifically about the OS itself.
And typical KK stuff in the comment there x.x (although this is nothing compared to what I saw on french forums in 2004-06)
-
How do you have the interrupt code be at 38h?
The hardware automatically RST 38H when an interrupt fires in IM 1.
If you are already using my code from the first post, make sure you update the first block after my edit. I had an extra zero in there by mistake.
-
Anyone done the WFRNG yet? ;D
-
*facepalm* :P
The kernel does include random number generation... :)
-
*facepalm* :P
The kernel does include random number generation... :)
LOL! And the first thing anybody's gotta do as soon as KOS comes out is port a certain number-guessing game ;)
-
Yeah, I can feel the fail now...
By the way, the random number generator is pretty good about random numbers, it updates the seed every time it executes, and the OS updates the seed on every interrupt.
-
Wow, that's great!
So you can't really "predict" the rands like on the TI-OS anymore...
-
It's hard to predict many on the TI-OS though, due to all possibilities but yeah it's possible, if you write numbers down or something, to do luck manipulation, like in games, by setting the seed to something specific then running the game before the boss fight.
-
You can predict the numbers, it's just harder; you have to factor in things like ON presses and link activity, as well as the entire time the calculator has been on.
-
It's hard to predict many on the TI-OS though, due to all possibilities but yeah it's possible, if you write numbers down or something, to do luck manipulation, like in games, by setting the seed to something specific then running the game before the boss fight.
Yeah, when we did a certain project in math class a few years ago, we were supposed to use dice to get our individual "stats". I convinced my teacher to let me use the num generator on an 83 instead, then stored 0 to rand and got two sixes (the max) :D
-
Doesnt the z80 have an R register that can be used for Random number generation that is much harder to calculate? I believe Axe random numbers use something like this...
-
Doesnt the z80 have an R register that can be used for Random number generation that is much harder to calculate? I believe Axe random numbers use something like this...
Yes it has a R register but this isn't a random number, it's the refresh register. it could easily be used as a seed though...
-
Nice tutorial Sir! ;D
-
I wonder what kind of randomizing Iambian uses in E:SoR...