6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Apr 26, 2024 7:07 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Nov 28, 2012 2:41 am 
Offline

Joined: Mon Nov 26, 2012 3:40 am
Posts: 42
This project is incomplete, but I'd thought I'd share... I'm going to just cut/paste the Readme and attach the files.

==============================
It Lives!

This little project started as an attempt to reserve-engineer the Apple
ProDOS kernel. The sequence of events went something like this; A friend
of mine found a functioning Apple IIc in 2009. I thought it would be
cute to put a mini-unix shell on it. Sadly, I have no idea how to code a
OS kernel and only have the so-so grasp of 6502 machine code. I thought
I could take some of the existing multitasking 6502 kernels out there
(Contiki, Geck/OS, or some of the nano-kernels that float about) and
build a shell around it. This is when I discovered that the Apple II has
no interrupt-bound timer chip in it at all, making on-the-fly
multitasking impossible. I saw tricks that overrode the BRK opcode (You
would assemble your code and use BRK to return from subroutines as
opposed to an RTS. The IRQ handler would then munge the stack, call the
kernel, and then the kernel would give time to another program), but
that was dumb and non-portable.

I put the whole idea away until I came across Davix, which was a
unix-shell wrapped around ProDOS. It was cute, but it was just a shell.
I thought it would be neat to see something a little closer to the
metal.

In my travels on the internets, I discovered "Beneath Apple ProDOS" by
Don Worth and Pieter Lechner. It described the guts of the older ProDOS,
and an assembly listing, but without the opcodes. It just had symbols
and comments in order. (I'm guessing to cover for copyright
infringement). Using that as a guide, I disassembled the 512 byte ProDOS
bootloader. I now could boot my own kernels. (And make my own boot
errors!)

The "code" in the book only covered ProDOS up to version 1.3, and the
last known version was 2.0.3. It was an interesting archaeological dig.
There was even code in there for booting an Apple ///, the failed
business computer made by the company.

I decided to tackle reversing the whole 1.3 kernel, but that was too
much. It consisted of disassembling a binary blob chunk, aligning it
with the stripped "source" and coming up with something I could
re-compile. It was just too big.

I then discovered the ProDOS 1.7 code was posted on the internet in it's
entirety. I decided that this code was too cool to let rot, so I started
a project to bring it back to life.

And here it is!

I did have to make some compromises.

x1) The bootloader is one from a later version with the Apple /// boot
code removed. It's useless. x2) I stripped the Ednet code. For those who
don't know. Ednet was Apple's attempt to wire the schools with Apple II
Appletalk networks for fileshareing with a Mac server. We even had one
in our school. The Ednet code had to go because my rather awesome
assembler has a real goofy way of doing defines (It defines against
symbols, and not macros). I'm a lazy programmer, and could't get the
defines to work right. I also found no real benefit of adding the Ednet
code, I did away with the defines and made it a straight ProDOS
assembly. If you want to add the Ednet code back in, more power to you.
x3) Even though my awesome assembler can take advantage of newer
technologies like linkers and relocatable code, I'm using the old
compile method and generating binary blobs (for the most part). I also
had to turn the Merlin assembler-like syntax to ca65's more updated
vocabulary. This means I had to replace the psudo-opcodes with macros.

That's pretty much the guided tour. If you want, look at the code
yourself. It's all pretty much there. When I'm done, I plan on diffing
it up to 2.0.3.

From there, I'll see if I can't get it to multitask. Thunderclocks have
programmable IRQ timers. We will see.


Attachments:
prodos_src.zip [2.8 MiB]
Downloaded 247 times
Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 28, 2012 4:13 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8428
Location: Southern California
Quote:
This is when I discovered that the Apple II has
no interrupt-bound timer chip in it at all, making on-the-fly
multitasking impossible.

Wow, are you serious? No timer at all? No 6520, 6521, 6522, 6526, 6530, or 6532?? What does it have in it? Does it not even have a way to do a time-of-day clock? A TOD clock might not have fine enough resolution, but it seems unimaginable that they didn't make some kind of provision. You could still do coöperative round-robin multitasking, but each task has to be written to do it and know how to do its part. The amount of time spent in each task is not critical as long as it's within a certain range so the time distribution among the tasks is not too uneven. [Edit, 5/15/14: I posted an article on simple methods of doing multitasking without a multitasking OS, at http://wilsonminesco.com/multitask/index.html.]

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 28, 2012 7:38 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Quote:
I saw tricks that overrode the BRK opcode (You would assemble your code and use BRK to return from subroutines as opposed to an RTS. The IRQ handler would then munge the stack, call the kernel, and then the kernel would give time to another program), but that was dumb and non-portable.
An amusing approach!


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 28, 2012 9:03 am 
Offline

Joined: Mon Nov 26, 2012 3:40 am
Posts: 42
GARTHWILSON wrote:
Quote:
This is when I discovered that the Apple II has
no interrupt-bound timer chip in it at all, making on-the-fly
multitasking impossible.

Wow, are you serious? No timer at all? No 6520, 6521, 6522, 6526, 6530, or 6532?? What does it have in it? Does it not even have a way to do a time-of-day clock? A TOD clock might not have fine enough resolution, but it seems unimaginable that they didn't make some kind of provision. You could still do coöperative round-robin multitasking, but each task has to be written to do it and know how to do its part. The amount of time spent in each task is not critical as long as it's within a certain range so the time distribution among the tasks is not too uneven.


Besides the empty card bus, The NMI in an Apple II is hard-wired to the keyboard (Open-apple + Reset), Most other minicomputer implementations I've seen, the NMI is wired to either a video sync pulse or some kind of programmable timer. There is a hack where you can take a single wire and connect the NMI pin to the video sync signal, but you lose floppy control because you can't service an interrupt while transferring data to/from the floppy. (The head position and data transfer are done by counting cycles).

There are add-on clock cards (Thunderclock) that you can control interrupts with, but nothing out of the box.


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 28, 2012 6:08 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8428
Location: Southern California
So is it not even able to keep time of day? If it can, what's the resolution? (You could still do coöperative multitasking though.)

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 02, 2012 8:20 am 
Offline

Joined: Mon Nov 26, 2012 3:40 am
Posts: 42
An out-of the-box Apple II did not have a real time clock in it. The Thunderclock add-on card did. The Thunderclock also had a programmable timer chip in it attached to the IRQ line. It had the ability to tell the time of day down to the second. Sadly, the Thunderclock wasn't Y2K compatible and counted up to 2003 or so before it's epoch counter wrapped around.

The mouse card also had a timer chip in it too, but that didn't come with the computer out-of-the-box either. Keep in mind, the Apple was a low-cost microcomputer and things like timer chips added to the expense.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 20 guests


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 post attachments in this forum

Search for:
Jump to: