 ttl UniFLEX Monitor ROM
 sttl Equates
 pag
 abs

*
* Monitor ROM for booting UniFLEX and handling the UniFLEX
* interrupt processing.
*

* Macro definitions

seti macro
 orcc #$50
 endm

clri macro
 andcc #!$50
 endm


* System equates

romadr equ $f800 starting rom address
vector equ $fff0 vector addresses
usrvec equ $ffe0 user vector addresses
romstk equ $be80 rom stack start

datbox equ $f400 dat box address
scrtrm equ $f000 scratchpad ram
conswt equ $f3fe configuration switch
tskreg equ $f3ff task select register

KILLI equ 5 kill signal
FALTI equ 7 fault signal
TIMEI equ 9 timeout signal

* System space segment definitions

sysseg equ 0 system tables
txtseg equ 5 system text
usrseg equ 11 stack segment
bufseg equ 12 I/O buffers
tfrseg equ 13 transfer buffers
iodseg equ 14 I/O device segment
romseg equ 15 rom

* Hard defined physical addresses

ramap equ $0100 8K of ram at address $00000
romap equ $ffff I/O and ROM at $fe000
nomap equ $ffff black hole segments (void space)

* Memory map definitions

segadr equ 16 number of segments per address space
segmax equ 256 max number of segments
segsiz equ 4096 segment size in bytes

nmicnt equ scrtrm+$10 nmi counter

 org $f100 scratch ram variables

stradr rmb 2
endadr rmb 2


* low ram interrupt vectors

 org sysseg<<12

irqvec rmb 2 maskable interrupt
swivec rmb 2 swi 1
sw2vec rmb 2 swi 2
sw3vec rmb 2 swi 3
nmivec rmb 2 non-maskable interrupt
frqvec rmb 2 fast interrupt

* low memory system storage

cputyp rmb 2 cpu type
usrtop rmb 1 current user segment
kernal rmb 1 kernal/user state (-1 = user address space)
chpflg rmb 1 change process flag
chtask rmb 2 change process vector
corcnt rmb 1 core segment count
lstmem rmb 2 mem table end marker
teluch rmb 1 user change flag
memmsk rmb 1 dat cell mask
romspr rmb 1 spare byte for rom


* System and global memory maps

 org (sysseg<<12)+$100

sysmap rmb segadr system memory map
cormap rmb segmax available memory list


* User block definitions

 org (usrseg<<12)+$f40

sysstk equ * system stack starts here
usp rmb 2 user stack pointer
urelod rmb 1 map reload flag
umapno rmb 1 task map number
usrmap rmb segadr user task memory map

usercc rmb 1 condition codes
userd rmb 2 D register
userx rmb 2 X register
userpc rmb 2 PC register
userpb rmb 1 sys call post byte


* interrupt vector definitions

 org vector

 fdb extrn
 fdb swi3
 fdb swi2
 fdb firq
 fdb irq
 fdb swi
 fdb nmi
 fdb reset

 org usrvec

 fdb uextrn
 fdb uswi3
 fdb uswi2
 fdb ufirq
 fdb uirq
 fdb uswi
 fdb unmi
 fdb ureset


 sttl Initial ROM Processing
 pag

*
* Rom code starts here
*

 org romadr

*
* I/O Vectors
*
 fdb pdata print a string (X)
 fdb hexbyt print one hex byte (A)
 fdb outsp print a single space
 fdb inch read one character from terminal

rinit lds #romstk set stack
 seti
 clra set dp
 tfr a,dp
 clr nmicnt
 ldd #ramap reload the ram map
 sta datbox+usrseg
 stb datbox+sysseg set up user and system segments
 lda #nomap>>8 fill system map with blackholes
 ldb #segadr get length of map
 ldx #sysmap+segadr point to map
rinit2 sta 0,-x stuff into map cell
 decb dec the count
 bne rinit2
 ldd #romap complete the initial map
 std iodseg,x set rom and io
 std datbox+iodseg
 ldd #ramap
 sta usrseg,x set user segment
 sta usrtop
 stb sysseg,x set system segment
 clra init the direct page register
 sta cputyp clear cpu type
 sta chpflg clear change task flag
 sta corcnt zero core count
 sta urelod
 sta umapno
 sta memmsk
 sta teluch
 jsr tinit init the terminal
 ldx #hello point to string
 jsr pdata print the string
 ldy #irqvec point to int vectors
 ldx #unhand and unhandeled routine
 ldb #6 set count
rinit4 stx 0,y++ store vector
 leax 7,x point to next panic
 decb
 bne rinit4
 stx chtask set change task vector

 sttl Main Monitor Loop
 pag

*
* Main monitor loop (command processor)
*

* temp equates

dlen equ 24 temp size in bytes

ascii equ 0-24 ascii data buffer
segmnt equ 16-24 active segmrnt number
offset equ 17-24 active segment offset
limit equ 19-24 extended address limits
count equ 22-24 local count field
digit equ 23-24 temp

* Loop starts here

montor leau 0,s mark stack
 leas dlen,s make temp space
nxtcmd ldx #prompt point to prompt string
 jsr pdata output it
 jsr inch get response
 jsr outsp output space
 ldx #commnd point to command table
 bsr search search for command
 jsr [1,x] execute command
 bra nxtcmd repeat

* Search command table for command

search cmpa 0,x is it this guy?
 beq searc2
 leax 3,x skip this one
 tst 0,x end of list?
 bne search
searc2 rts return

* Command table

commnd fcb $d carriage return
 fdb dummy
 fcb 'C Configure command
 fdb figlef
 fcb 'D Disk boot
 fdb dboot
 fcb 'W Winchester boot
 fdb wdboot
 fcb 'E Examine
 fdb examin
 fcb 'M Mapper
 fdb mapper
 fcb 0 end of table
 fdb badcmd


* Configure the system command

figlef jsr config do configuration
 lda corcnt get core count
 adda #7 add in system core count
 sta count,u save it
 ldd #0 set count to 0
figle2 adda #4 covert to decimal
 daa
 adcb #0 add in carry
 dec count,u
 bne figle2 finished?
 tstb more than 99K of memory?
 beq figle4
 exg a,b do upper digit now
 adda #$30
 jsr outch output it
 exg b,a get low back
figle4 jsr hexbyt output byte
 jsr outsp output space
 lda #'K output 'K'
 jmp outch


* Disk boot command

dboot jsr config configure system
 jsr loadip load the ipl sector
 lbne hexbyt output bad status
 lds #sysstk setup UniFLEX stack
 jmp 0,x go do the boot

* Winchester boot command

wdboot jsr config configure system
 jsr wdload load the bootstrap loader
 lbne hexbyt output bad status
 lds #sysstk set up UniFLEX stack
 jmp 0,x go do the boot


* Bad command

badcmd ldx #sorry point to string
 jsr pdata output it
dummy rts return
