
 sttl System Configuration
 pag
*
* Configure the system
*

* equates

mapmsk equ $0f segment map mask
tstpat equ $99AA memory test pattern
tstloc equ (tfrseg<<12)+$f0 test position
useres equ $0001 user resident page
sysres equ $0000 system resident page

* code starts here

config ldx #tstpat setup pattern
 ldy #cormap+segmax setup page table pointer
 ldb #segmax-1 setup max page number
check bsr getpag map in a page
 stx tstloc write test pattern
 cmpx tstloc is memory there?
 bne nomem
 pshs b save count
check2 bsr getpag map in next page
 stb tstloc+1
 subb #1 dec count by 1
 bcc check2
 puls b
 bsr getpag reselect the page
 cmpb tstloc+1 is memory there?
 beq gotmem

* here if no memory

nomem clra set page number to zero

* here for memory found

gotmem sta 0,-y store into mem table
 subb #1 dec the count
 bcc check
 leax 0,y point to start of table

* setup system address space

syssup clr sysres,x clear out system and user pages
 clr useres,x
 ldy #sysmap+txtseg point to user segment
 ldb #NSPG set length
syssu2 bsr getnxt get next segment
 beq memfal crash if no memory!
 sta 0,y+ save in map
 decb dec the count
 bne syssu2
 clr corcnt set core count to zero
 ldy #cormap point to core map
syssu4 bsr getnxt get next page
 beq syssu5 no more?
 sta 0,y+ save in table
 inc corcnt bump core counter
 bra syssu4 repeat
syssu5 sty lstmem save last mem pointer
 ldx #sysmap point to system map
 ldy #datbox point to datbox
 ldb #segadr get segment count
syssu6 lda 0,x+ reload datbox from map
 sta 0,y+
 decb dec the count
 bne syssu6
 rts return

* map in a memory page

getpag tfr b,a get page number
 eora #mapmsk invert the page mask
 sta datbox+tfrseg map into address space
 rts return

* get next valid memory segment

getnxt cmpx #cormap+segmax end of map?
 beq getnx2
 lda 0,x+ get next page
 beq getnxt keep looking if zero
getnx2 rts return

* No memory panic

memfal bsr panic report panic
 fcc 'Not Enough Memory!',0
