;Implementation of SoftMMU - initialize ;====================================== #include "sm.h.txt" .global sm_init .global sm_getfreelistpage ;Include the init source files for each expansion #define routine getsources #include "sm_include.h.txt" ;Jump tables sm_initlo: #define routine jumptable #define prefix < #define param_init #include "sm_include.h.txt" sm_inithi: #define routine jumptable #define prefix > #define param_init #include "sm_include.h.txt" ;------- sm_init: ;------- ;Call each installed source's init function ;There is only one instance of the sm_init ;program ever, so we can selfmod the dispatch ;call. lda #$08 ;get 8 bytes of userzp jsr set_zpsize ldx sm_memsrc ;loop through the memory sources - lda sm_initlo,x ;get their "init" vector sta j1+1 lda sm_inithi,x sta j1+2 j1: jsr $ffff ;do it dex ;hey, init function, keep .X intact! bpl - rts ;------------------ sm_getfreelistpage: ;------------------ ;A global helper routine to allocate a free list ;page for the memory source. sei stx tmpzp ;save the expansion number ldx #$22 ;say it's kernel data (??) ldy #$ff ;no i/o jsr spalloc bcs + ;catch all errors txa ldx tmpzp cli sta sm_page,x ;save the location of the free list page sta userzp+1 ;plus, save a pointer to it at userzp lda #$00 sta userzp + rts ;---------------- ;just some comparisons of different dispatch methods ;---------------- ;4 lda xxxx,X ;3 pha ;4 lda xxxx,X ;3 pha ;6 rts ;== 20 cycles ; 9 bytes ; ;4 lda xxxx,X ;3 sta zp ;4 lda xxxx,X ;3 sta zp+1 ;5 jmp (00zp) ;== 19 cycles ; 13 bytes ; 2 zp bytes ; ;4 lda xxxx,X ;4 sta selfmod ;4 lda xxxx,X ;4 sta selfmod+1 ;3 jmp selfmod ;== 19 cycles ; 15 bytes