        IFUND   IODRIVERBODY
IODRIVERBODY    EQU     0
IODRIVERPOLL    EQU     0
IODRIVERRAM     EQU     0
ROMONLY EQU     1
TEMPX           EQU     0
TIMEOUT:FUSE            EQU     2
        TITLE   COPYRIGHT (C) 1982 PSITECH
        NAME    PSITECH SDOS/MT TIME SHARE PRIMITIVE ROUTINES
        psr     1
        pcc     1
        ifund   m6800
m6800   equ     1
m6809   equ     0
m6801   equ     0
        fin     m6800
        FIN     IODRIVERBODY
        ifund   romonly
romonly equ     0
        fin     romonly
        IF      IODRIVERBODY!ROMONLY
        PAGE    DEFINITIONS
*
*******************************************************************
*
*       SCRATCHPAD ALLOCATION
*
WUFROM          EQU     2
FROM            EQU     4
LIMIT           EQU     6
WUBYTES         EQU     LIMIT
WUJMPX          EQU     LIMIT+1
*
*       SDOS SACRED AREA ALLOCATION
*
USERSPSAVE      EQU     $F1

*
*       PACE 480 HARDWARE DEFS
*
BANKSELECT      EQU     $FAE6   STORE HERE TO SELECT RAM BANK
SYSTEMBANK      EQU     0
INTVECTOR       EQU     $FFF8
IOQUANTUM       EQU     60/4    = 250 MS.
CPUQUANTUM      EQU     60*2    = 2 SECONDS
        PAGE
*       LOCAL SCRATCH PAD
::      SET     *
        ORG     $FF00   RAM STORAGE
MTCRASHINFO     RMB     8       SAVE SOME ROOM FOR MT TO TELL US HOW HE DIED
USERBANK        RMB     1       WHERE WE KEEP THE USER NUMBER
SYSTEMSPACEINTPTR       RMB     2       SAVES CONTENTS OF INTVECTOR FOR SYSTEM SPACE

QUANTUM FCB     0       NUMBER TO 60HZ TICKS LEFT BEFORE THIS USER GETS BUMPED
QUANTUMTHRESHOLD FCB 0  MINIMUM ABORTABLE TIMESLICE QUANTUM
REMAININGQUANTUM FCB 0  AMOUNT OF TIMESLICE REMAINING WHEN ABORTED

UNSWITCHEDBYTES RMB     2       2 BYTES THAT DON'T GET SWITCHED (SEE COPYTO...)
SYSTEMSPSAVE            FDB     0       where to save ths system stack pointer
TIMESLICEUP             FDB     0       where to go on quantum done
********* WARNING:
********* IF STACK SPACE HERE IS NOT SUFFICIENT, THE SYSTEM WILL BLOW UP!
********* NEEDS ENOUGH STACK FOR CONTEXT BLOCK, SCRATCH PAD, THE 16 BYTES
********* THAT COPYTO... WILL PUSH, AND A FEW SPARES
        RMB     7+8+16+10       SPACE FOR INTERRUPT SYSTEM TO PLAY IN
CONTINUESTACK
        FCB     $FF     this takes care of the 6800's funny stack pointer
        FCB     $FF     DUMMY CC WITH INTERRUPTS DISABLED
        FCB     0,0     DUMMY B,A REGISTERS
        FDB     0       DUMMY X
        FDB     USERRTI         WHERE TO RETURN TO AFTER SERVICING INTERRUPT
*
        PAGE    INTERRUPT HANDLING LOGIC
        IF      M6800!M6801
        ORG     $F000   WHERE TO PUT THE PRIMITIVE ROUTINES
        ELSE    (6809)
        ORG     $E000
        FIN
USERSPACESYSCALL ; USER SYSCALL TRANSFERS CONTROL HERE
        STX     TEMPX   PUSH REST OF CONTEXT BLOCK
        LDAA    TEMPX
        LDAB    TEMPX+1
        PSHB            PUSH (X)
        PSHA
        PSHA            PUSH TRASHED (A)
        PSHA            PUSH TRASHED (B)
        IF      M6800!M6801
        CLRA            MAKE AN INTERRUPT-ENABLED CC AND CARRY CLEAR
        ELSE    (6809)
        LDAA    #$80    CARRY CLEAR AND ENTIRE SET
        FIN     M6800...
        PSHA            PUSH (CC)
        NOP             NO SURPRISES, PLEEZ...
        SEI
        STS     USERSPSAVE      SAVE USER STACK IN HIS SPACE
        LDAA    #SYSTEMBANK     GET THE SYSTEM
        STAA    BANKSELECT
        LDX     SYSTEMSPACEINTPTR TELL THE INTERRUPT SYSTEM
        STX     INTVECTOR
        LDS     SYSTEMSPSAVE            SWITCH TO SYSTEM TASK'S STACK POINTER
        CLI             LET THE SUN SHINE AGAIN
        LDAA    QUANTUM
        ADDA    REMAININGQUANTUM
        RTS             RETURN CONTROL TO SYSTEM TASK

USERSPACEINTERRUPT ; AN INTERRUPT OCCURRING WHILE USER IS RUNNING COMES HERE
        STS     USERSPSAVE              CONTEXT BLOCK IS PUSHED, SAVE 