 ttl GIMIX III UniFLEX ROM
 sttl Hardware Definitions
 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
rompag equ $ff00 resident rom page
vector equ $fff0 vector addresses
romstk equ $be80 rom stack start
CPURAM equ $E400 On Board Scratchpad RAM
TSR equ $E280 Task Select/Status Register
FUSE equ $FB00 Task Switching "FUSE"

datbox equ $F800 dat box address

* On-board DMA controller
 org $FC00
DMA_SCR rmb 1 Source control
DMA_SAR rmb 2 Source address
DMA_DCR rmb 1 Destination control
DMA_DAR rmb 2 Destination address
DMA_CNT rmb 2 Byte count

* 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

ROMmap equ $01FF 2K ROM at $FF800
RAM0map equ $0000 4K RAM
RAM1map equ $0002 4K RAM
IO0map equ $01FC $FE000 (I/O Slots)
IO1map equ $01FE $FF000 (Disk controllers)
NOMEM equ $F3 Black Hole??
DATsense equ $00 DAT is not inverted

* 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
swi2vec rmb 2 swi 2
swi3vec rmb 2 swi 3
nmivec rmb 2 non-maskable interrupt
firqvec 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
urelod rmb 1 reload mapping regs
umapno rmb 1 memory map #
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

*
* IOP Definitions
*

 lib fio
 lib ../iop/fio_codes
 lib systty

*
* ROM Processing Data
*
 org CPURAM
ascii rmb 16 ascii data buffer
segmnt rmb 1 active segment number
offset rmb 2 active segment offset
limit rmb 3 extended address limits
count rmb 1 local count field
digit rmb 1 temp
lowadr rmb 2 dump address (low addr)
hiadr rmb 2
ttybuf rmb TT_SIZ used for ttyset/ttyget calls
SWI3_tmp rmb 12 used during System call processing
rom_version rmb 1 IOP ROM Version #

 org CPURAM+$80
MAXMAPS equ 8 Number of DAT maps
datcopy rmb segadr*MAXMAPS copy of DAT contents (UniFLEX form)


* interrupt vector definitions

 org vector

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



 sttl ROM Initialization
 pag

*
* Rom code starts here
*

 org romadr
*
* ROM Entry Point Vectors (used by UniFLEX)
*
 fdb pdata print null terminated string
 fdb hexbyt print A in hex
 fdb outsp print a space
 fdb outch print a character
 fdb tinit initialize system console

*
* Initialize DAT for ROM use
*
reset lda #datbox>>8 -- shorten addressing
 tfr a,dp
 setdp datbox>>8
 ldd #ROMmap
 std datbox+((romseg*2)+1)*2 $F800-$FFFF
 ldd #RAM0map
 std datbox+((usrseg*2)+0)*2 $B000-$B7FF
 addd #1
 std datbox+((usrseg*2)+1)*2 $B800-$BFFF
 ldd #RAM1map
 std datbox+((sysseg*2)+0)*2 $0000-$07FF
 addd #1
 std datbox+((sysseg*2)+1)*2 $0800-$0FFF
 ldd #IO0map
 std datbox+((iodseg*2)+0)*2 $FE000 at $E000
 addd #1
 std datbox+((iodseg*2)+1)*2 $FE800 at $E800
 ldd #IO1map
 std datbox+((romseg*2)+0)*2 $FF000 at $F000
 lds #romstk set rom stack
 clra -- reset addressing
 tfr a,dp
 setdp $00
* Print message
 jsr iop_init go initialize the IOP
 jsr tinit init the terminal
 jsr raw_mode ROM uses RAW I/O
 ldx #hello point to string
 jsr pdata print the string
 lda rom_version
 pshs a
 lsra
 lsra
 lsra
 lsra
 lbsr hexbyt
 lda #'.
 jsr outch
 puls a
 anda #$0F
 lbsr hexbyt
 lda #NOMEM fill system map with blackholes
 ldb #segadr get length of map
 ldx #sysmap+segadr point to map
 ldu #datcopy+segadr
reset10 sta 0,-x stuff into map cell
 sta 0,-u also into copy
 decb dec the count
 bne reset10
 lda #(ROMmap>>1)&$FF complete the initial map
 sta romseg,x
 sta romseg,u
 lda #(IO0map>>1)&$FF
 sta iodseg,x
 sta iodseg,u
 lda #(RAM0map>>1)&$FF
 sta usrseg,x
 sta usrseg,u
 sta usrtop
 lda #(RAM1map>>1)&$FF
 sta sysseg,x set system segment
 sta sysseg,u
* Initialize DAT copy
 ldu #datcopy+segadr
 ldb #MAXMAPS-1
00 pshs b
 ldb #segadr Number of segments / map
 lda #NOMEM
10 sta ,u+ init entry
 decb
 bne 10b
 puls b
 decb last map?
 bne 00b
*
 clra init the direct page register
 sta chpflg clear change task flag
 sta corcnt zero core count
 coma
 sta kernal set non-kernal space
 lda #$80 Set up CPU indicator = GIMIX III
 sta cputyp set cpu type
 ldu #irqvec point to int vectors
 ldx #unhand and unhandled routine
 ldb #6 set count
reset20 stx 0,u++ store vector
 leax 8,x point to next panic
 decb
 bne reset20
 stx chtask set change task vector

 sttl ROM Command Processing
 pag

*
* Main monitor loop (command processor)
*

* Loop starts here

montor leau 0,s mark stack
 ldb TSR
 bitb #%00010000 check user option jumper
 beq nxtcmd jump if installed
 lbsr cmiboot try to boot from system winchester
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 'U 5" Disk boot
 fdb mboot
 fcb 'W Boot from CMI Winchester
 fdb cmiboot
 fcb 'E Examine system memory
 fdb examine
 fcb 'M Modify System memory
 fdb modify
 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 save it
 ldd #0 set count to 0
figle2 adda #4 covert to decimal
 daa
 adcb #0 add in carry
 dec count
 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 bsr loadip load the ipl sector
 lbne hexbyt output bad status
 lds #sysstk setup UniFLEX stack
 jmp 0,x go do the boot

* 5" Disk boot command

mboot jsr config configure system
 ldb #$14 select drive #2
 bra dboot0

* Bad command

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