Michael's Daemon v 2.0 - Copyright 1989 by Michael Pender This product is shareware. If you use it often send me $30 to cover the time I spend writing things like this. If you don't like it, give it to someone else. People should feel free to distribute this to bulletin boards, user nets, among friends, etc. I ask that companies that would distribute my products clear it with me first (read that permission required in writing.) Daemon is an addition designed for the BASIC.SYSTEM environment to allow multitasking applications on the IIe, IIc, and Laser series of computers. At this time Daemon does not appear to like the mouse cards of the apple IIgs, hence amusingly enough, Daemon only provides multitasking on computers older than the gs. Daemon REQUIRES a mouse card, but not a mouse. Future versions of Daemon (3.0) will be designed to access clock cards, should a mouse card not be available. Daemon is basically a programming tool to allow people unfamiliar with interrupt processing to write routines which will run in the background, transparent to the user, in effect multitasking. What actually happens: Sixty times a second the mouse card generates an interrupt. In response to the interrupt Prodos calls the Daemon driver to process the interrupt. Being an interrupt generated by the mouse card, it is not necessary to clear it, it will clear itself. The installer for the individual tasks sets a calling frequency of 0-255, where the frequency is the number of interrupts to SKIP between each call to the driver. Daemon in turn issues a JSR instruction to the entry point for each installed task in turn, and WAITS (read that: DOES NOT INTERRUPT AGAIN) for each task in turn to issue an RTS command, at which point Daemon calls the next routine in its list until no more drivers remain to be called. As of version 2.0 Daemon supports up to eight parallel tasks, in addition to the foreground job. To the user this means they can have a little clock in the corner of the screen, or that their IIe or IIc or Laser (maybe even the gs and the c+, I don't know yet) can act like it has a clock card, even if it doesn't. This is the effect of a feature I call a softcard, a non-physical device which performs the function of a physical device, but does not take up a physical slot in the machine. In a similar fashion, the SHORT routine under SHELL performs a hardware function, without actually existing as a physical device in the computer. Similarly, a routine called SOFTKB installs some advanced keyboard features without actually existing as a physical device in the computer. This is a side-effect of multitasking, but is an important effect in and of itself. Routines can be written (and are being written) to allow generic modem, printer, screen and keyboard drivers, adding features not otherwise possible, and to BASIC it all just appears as a card in the computer. But I digress... This version is loads into memory at $6000, and determines whether or not it is already present by checking for the existance of an existing interrupt routine at $BF80 (the Prodos interrupt driver table). If a routine already exists, Daemon will not load. This program is called a "Daemon" because it is a spurious interrupt driver, it accepts all interrupts. If it were to be forced to load into the interrupt table after another routine had been established the first task would no longer receive interrupts, Daemon would intercept them and declare them as it's own. If it is not present it requests 2 pages of memory (512 bytes for itself and its buffers). If no error occurs it relocates and protects itself. IT DOES NOT ACTIVATE INTERRUPTS ON LOADING. This was to prevent the program loading it into memory from suddenly being subjected to an interrupt request it was not prepared for. Daemon does not activate until called through the CONNVEC vector. However, it is not the CONNVEC routine that allocates the Prodos Interrupt driver. This means if the permanent disconnect routine is called (RMMTVEC) and then the CONNVEC vector is called as far as Prodos is concerned DAEMON is no longer present, and as soon as 255 interrupts go unprepared for, the system will crash with System Error 01, unclaimed interrupt. The included files: Daemon is the task driver, as stated earlier, it loads in at $6000, and relocates the important code to protect it. Q. How then does one find daemon to install their own tasks? A. Get the MSB of interrupt vector #1, it will be the msb of Daemon. The access to Daemon's functions is handled using vectors: $4000 CONNVEC - vector to reconnect Daemon if it has been disconnected, or to start in the first place. Daemon does not active itself on loading, just in case it would conflict with other commands. $4003 DISCVEC - vector to TEMPORARILY disconnect Daemon, it "disconnects" it by using the SEI instruction to ignore interrupts. A CLI instruction would clear it, or a person can call the CONNVEC routine. $4006 RMMTVEC - PERMANENTLY remove Daemon. This also removes the prodos interrupt vector, so DO NOT CALL CONNVEC AFTER CALLING RMMTVEC!!! You must reload Daemon. $4009 ADDVEC - JSR here to add a new task, Daemon takes care of this for you. On calling the X register should contain the lsb of the task's address, the A register should conatin the msb of the task's address and the Y register should contain the frequency at which the routine should be called. Y = 0 signifies call every 1/60th second, Y = 1 signifies call every 1/30th second, etc, up to 255 which is call every 4.25 seconds. On exit, if the Carry is clear, the routine was added, if carry returns set the table already contains the maximum number of eight tasks. The manipulation of the vector table is not the best, but it works. The y register will contain the task number assigned 0-7, this would be necessary should you decide to terminate the task (it is not necessary to terminate DAEMON to remove a task). $400C REMVEC - Load the accumulator with the value of the task routine to remove and call here. The value passed will be anded with 7 to force it to a value between 0-7. It will then be removed from active service. The other files: DON - SHELL command to enable multitasking. DOFF - SHELL command to temporarily disable multitasking using the DISCVEC routine. DREM - SHELL command to remove Daemon from memory, do not use DON after using DREM, it must be reloaded. CLOCK - Reads the Prodos time and puts a little clock in the upper right corner of the screen, this will work with Prodos compatible clock cards, and does not require Softclock if you have a clock card installed. INSTALL - If you have a routine you want to try as a background task use this install command, it will prompt for the address, and calling frequency. For example, from the monitor: *2000: EE 0 4 60 Then from install just choose address 8192, frequency 0 and the upper left corner will cycle incessantly. **** If using SHELL just type INSTALL, if not using shell, you must BLOAD INSTALL.BIN, then run INSTALL.BAS. SOFTCLOCK - Install a prodos compatible clock in your computer, based on the interrupts generated by your mouse card. It keeps good time, even with disk accesses. The power of this program lies not in its ability to do trivial tasks, like placing a clock in the corner of the screen, but as an addition to the BASIC programming environment that allows one to write simple programs and not have to worry about the details of interrupt processing. The clock routines presented here are merely an amusement, if I didn't have a lab to do for tomorrow I'd write a keyboard buffer routine with or without keyclick for those that want it, and maybe take a crack at writing a print spooler or modem driver. Please remember, this version of the program is submitted for testing only, I will write a version that relocates and protects itself and upload that soon, this is merely to show what I've done so far in the hopes of obtaining suggestions as to where improvements could/should be made. I never really hit it off with modems, anybody want to write a modem driver for the SSC card and save me doing it?