 ttl GIMIX UniFLEX ROM
 pag
*
* 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
rompag equ $ff00 resident rom page
vector equ $fff0 vector addresses
romstk equ $be80 rom stack start

datbox equ $fff0 dat box address

* System space segment definitions

sysseg equ 0 system tables
txtseg equ 5 system text
NSPG equ 6 Number System Pages
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 $0e0f 8K of ram at address $00000
romap equ $f1f0 I/O and ROM at $fe000
nomap equ $f3f2 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


* 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


* 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
uswiv rmb 2 user swi vector
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 0 reserved
 fdb swi3
 fdb swi2
 fdb firq
 fdb irq
 fdb swi
 fdb nmi
 fdb reset


 pag

*
* Rom code starts here
*

 org romadr

rinit ldd #ramap reload the ram map
 sta datbox+usrseg
 stb datbox+sysseg set up user and system segments
 lds #romstk set rom stack
 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
 ldd #ramap
 sta usrseg,x set user segment
 sta usrtop
 stb sysseg,x set system segment
 clra init the direct page register
 tfr a,dp
 sta cputyp clear cpu type
 sta chpflg clear change task flag
 sta corcnt zero core count
 coma
 sta kernal set non-kernal space
 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
 ldx #unswi2
 stx uswiv set swi 2 vector

 pag

*
* Main monitor loop (command processor)
*

* temp equates

dlen equ 28 temp size in bytes

ascii equ 0-dlen ascii data buffer
segmnt equ 16-dlen active segment number
offset equ 17-dlen active segment offset
limit equ 19-dlen extended address limits
count equ 22-dlen local count field
digit equ 23-dlen temp
lowadr equ 24-dlen dump address (low addr)
hiadr equ 26-dlen

* 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 8" Disk boot
 fdb dboot
 fcb 'E Examine system memory
 fdb examine
 fcb 'M Modify System memory
 fdb modify
 fcb 'J Jump to program in system memory
 fdb jumpprg
 fcb 0 end of table
 fdb badcmd


* Configure the system command

figlef jsr config do configuration
 lda corcnt get core count
 adda #NSPG+2 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


* 8" Disk boot command

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

* Bad command

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

 pag
