 ttl UniFLEX Stand Alone Status
 pag
 opt nol
 lib ../params
 lib ../macdefs
 lib ../struct
 lib ../varbls
 lib ../systabs
 opt lis
 pag
 sttl Vectors
 data
*
* System Vectors
*
 fdb 00f
 fdb 01f
 fdb 02f
 fdb 03f
00 rzb 4
01 rzb 4
02 rzb 4
03 rzb 4
 sttl Main Processing
 pag
Status
 lds #(USRLOC<<12)+USTKO set up stack pointer
 clr kernal set "system" mode
 lbsr syscon init system console
 ldx #00f
 jsr Pdata
 jsr p_tasks
 jsr p_devs
 bra *

00 fcc $d,'UniFLEX Stand Alone Status - 05/27/83:',$d,0

 sttl Print Task Table Info
 pag
p_tasks
 ldx #00f
 jsr Pdata
 ldy tsktab get pointer to first task table entry
0 lda tsstat,y get task id
 beq 1f skip if none
 tfr y,d
 jsr Phex2
 jsr Space
 fcb 4
 ldd tstid,y
 jsr Phex2
 jsr Space
 fcb 7
 ldd tstidp,y parent task id
 jsr Phex2
 jsr Space
 fcb 3
 lda tsstat,y
 jsr Phex
 lda #'/
 jsr Putch
 lda tsmode,y
 jsr Phex
 jsr Space
 fcb 6
 lda tsprir,y
 jsr prt_prir print priority
 jsr Space
 fcb 2
 ldd tsuid,y
 jsr Phex2
 jsr Space
 fcb 2
 ldd tsevnt,y
 jsr Phex2
 jsr Space
 fcb 6
 ldd tslink,y
 jsr Phex2
 jsr Space
 fcb 7
 ldd tsslnk,y
 jsr Phex2
 ldx #01f
 jsr Pdata
1 leay TSKSIZ,y bump to next entry
 cmpy tskend last entry?
 blo 0b
 ldx #02f
 jsr Pdata
 ldd runlst
 jsr Phex2
 ldx #03f
 jsr Pdata
 ldd slplst
 jsr Phex2
 jsr Space
 fcb 2
 ldd slplst+2
 jsr Phex2
 ldx #01f
 jsr Pdata
99 rts
*
prt_prir tfr a,b compute 16 bit value
 sex
 ldx #p_tab search priority table
0 cmpd ,x found priority?
 ble 1f yes - exit
 leax 4,x no - bump to next entry
 bra 0b
1 ldx 2,x get string
 jsr Pdata
 rts
*
p_tab
 fdb USERPR,p_taba
 fdb SLEPPR,p_tab9
 fdb WAITPR,p_tab8
 fdb TTYOPR,p_tab7
 fdb TTYIPR,p_tab6
 fdb PIPEPR,p_tab5
 fdb WBUFPR,p_tab4
 fdb BUFPR,p_tab3
 fdb NFDNPR,p_tab2
 fdb FDNPR,p_tab1
 fdb SWAPPR,p_tab0
p_tab0 fcc 'swap',0
p_tab1 fcc 'upd ',0
p_tab2 fcc 'fdn ',0
p_tab3 fcc 'i/o ',0
p_tab4 fcc 'buf ',0
p_tab5 fcc 'pipe',0
p_tab6 fcc 'in  ',0
p_tab7 fcc 'out ',0
p_tab8 fcc 'wait',0
p_tab9 fcc 'slp ',0
p_taba fcc 'run ',0
p_tabb fcc '????',0

00 fcc $d,'Task Table:',$d,$d
 fcc 'Addr Task Id  Parent Id  Status  Priority  User Event  '
 fcc 'Run-link Sleep-link',$d,0
01 fcc $d,0
02 fcc $d,'Run List Head = ',0
03 fcc $d,'Sleep List Head = ',0

 sttl Print Device Table Info
 pag
p_devs
99 rts

 sttl System I/O Routines
 pag

*
* Space - Print a number of spaces
*    jsr Space
*    fcb #
*
Space pshs d,x save registers
 ldx 4,s get parameter pointer
 ldb ,x+
 stx 4,s replace return address
0 lda #$20 space character
 pshs d
 bsr Putch print character
 puls d
 decb
 bgt 0b
 puls d,x,pc return

*
* Putch
*
* Write one character to the console terminal.
*

Putch pshs cc,a,x save data
 seti mask ints
 ldx scon point to console
 beq syspc4 is it null?
 jsr systpc write character
syspc4 puls cc,a,x,pc return

*
* syscon
*
* Initialize the system console
*

syscon ldx scon get address
 beq 99f is it null?
 jsr sysrtt reset port
99 rts

*
* Pdata
*
* Print a message on the system console
*

Pdata lda 0,x+ get next character
 beq 99f end of message?
 cmpa #$0D carriage return?
 bne 0f no - continue
 bsr Putch yes - send CR/LF
 lda #$0A
0 bsr Putch send out character
 bra Pdata repeat
99 rts

*
* Phex2 - Print 2 hex digits
* Phex  - Print a single hex digit (2 nibbles)
*
Phex2 pshs d
 bsr Phex
 lda 1,s
 bsr Phex
 puls d,pc
*
Phex pshs a save value
 lsra
 lsra
 lsra
 lsra
 bsr P_nib output nibble
 puls a
 anda #$0F
 bsr P_nib
 rts
*
P_nib pshs x save register
 ldx #00f
 lda a,x get character
 puls x restore register
 bsr Putch print character
 rts
*
00 fcc '0123456789ABCDEF'

*
* sysdec
*
* Print the decimal number in D on the console.
*

sysdec pshs d save number
 ldd #4 set temps
 pshs d save temps
 ldd 2,s get the number
 ldx #sysct point to constants
sysde4 bsr sysdo output digit
 leax 2,x next constant
 dec 1,s dec the count
 bne sysde4 loop til done
 tfr b,a get last digit
 bsr syshr output it
 leas 2,s clean up stack
 puls d,pc return


*
* sysdo
*
* Output digit in D.
*

sysdo clr 0,-s clear flag
sysdo2 cmpd 0,x compare to constant
 blo sysdo5
sysdo4 subd 0,x dec number by constant
 inc 0,s bump count
 bra sysdo2 repeat
sysdo5 pshs a save digit
 lda 1,s get count
 bne sysdo6
 tst 4,s output any yet?
 beq sysdo7 if not, exit
sysdo6 inc 4,s set output digit flag
 bsr syshr output the digit
sysdo7 puls a reset number
 leas 1,s clean up stack
 rts return

*
* syshr
*
* Output right hex digit in A.
*

syshr anda #$f mask right half
 adda #$30 add in ASCII bias
 cmpa #'9 greater than 9?
 bls syshr2
 adda #7 add in bias
syshr2 lbra Putch output it


* decimal constants

sysct fdb 10000
 fdb 1000
 fdb 100
 fdb 10

 ifc &a,"s1"
 lib sys_acia_SA
 else
 ifc &a,"s2"
 lib sys_acia_SA
 else
 ifc &a,"s3"
 lib sys_acia_SA
 else
 ifc &a,"s4"
 lib sys_8274_SA
 else
 ifc &a,"g1"
 lib sys_acia_SA
 else
 ifc &a,"g2"
 lib sys_acia_SA
 else
 endif
 endif
 endif
 endif
 endif
 endif

 ifc &a,"s1"
scon fdb $E000 System Console Port
 else
 ifc &a,"s2"
scon fdb $E400 System Console Port
 else
 ifc &a,"s3"
scon fdb $E000 System Console Port
 else
 ifc &a,"s4"
scon fdb $E000 System Console Port
 else
 ifc &a,"g1"
scon fdb $E000 System Console Port
 else
 ifc &a,"g2"
scon fdb $E000 System Console Port
 endif
 endif
 endif
 endif
 endif
 endif

 end Status
