; ; ********************************************************************* ; ; The Initialisation section of a Redefinable Telesoftware Decoder ; ; ; (C) C.J. Oswald 1982 ; -- rtf2 -- ; ; ********************************************************************* ; ; ; ; *********************************************************************** ; ; A subroutine to initialise all variables & the name tables ; for the RTF decoder ; ; All registers and temporary zero page locations destroyed! ; ; On soft reset locations 0 to 99 are reset in the global vector ; (mostly to zero) ; On hard reset locations 100 to 119 are also reset, commle and ; heapfr are set, and the name tables are set ; ; Hard reset entry ; inital JSR initnt ; initialise name tables in RAM LDAIM :LSB: lospac STA heapfr ; heap is empty LDAIM :MSB: lospac STA heapfr+1 ;LDAIM 255 ;STA commle ; set level of commens to be decode to 255 LDYIM 119 ; zero the first 120 locations in the global vector JMP in2 ; ; Soft reset entry ; softin LDYIM 99 ; zero the first 100 locations in the global vector ; in2 LDAIM 0 ; in1 STAAY GPER DEY BPL in1 ; ;LDYIM 255 ; (Y emerges holding &FF) STY blocks STY oldblo ; Initialise STY noexec ; LDYIM 1 STY thisbl ; set the number of the first block to one STY blockg ; mark the zeroth block as got (it doesn't exist) ; JSR chopqu ; queue is empty ; LDAIM :LSB: stackb STA stackf ; stack is empty LDAIM :MSB: stackb STA stackf+1 ; RTS ; ; *********************************************************************** ; ; A subroutine to produce the default name tables from the ; Command Subroutine Library's index ; ; All registers and temporary zero page locations destroyed! ; initnt JSR setlon ; set pointers ztype, zlo and zhi to lone tables LDYIM 0 ; Y is offset in tables ; int1 LDAIM 1 ; "direct decoding to one byte" entry in table STAIY ztype TYA ; entry in lo-table decodes to itself STAIY zlo LDAIM 0 ; entry in hi-table not used (set to zero) STAIY zhi INY BNE int1 ; ; emerges with all lone entrie decoding to themselves ; now add escape operators in lone tables ; LDAIM &1B ; "escape operator" entry in table STA lonety+&1B STA lonety+&7C STA lonety+&9B STA lonety+&FC ; ; lone tables all initialised ; JSR setesc ; set pointers ztype, zlo and zhi to lone tables ;LDYIM 0 ; Y is offset into tables (Y already holds zero) ; int2 LDAIM &1B STAIY ztype ; "escape operator" entry in table LDAIM 0 STAIY zlo ; set entrie in lo- & hi-tables to 0 for time being STAIY zhi INY BNE int2 ; contin for rest of table ; ; emerges with all escaped entrie being escape operators ; now add command subroutines in escaped tables ; LDYIM &FF ; Y holds the offset from start of index (255/6 entrie max) LDXIM &FF ; X holds the offset from 2nd part of the index ; int4 INY ; move onto 1st field of entry LDAAY libind BEQ int3 ; end of this section of library's index (NUL instead of ; first letter of command subroutine title) INY ; move onto 2nd field of entry INY INY LDAAY libind ; get type of entry (with msb signalling if this ; command subroutine's name appears in the default tables) STA ztempl ANDIM &80 ; get msb BEQ int6 ; this entry does not appear in the default name tables LDA ztempl ANDIM &7F ; get rest of information (type of entry) PHA ; save it ready for storing in name table ; the following code could probably be compacted ; INY ; move offset to command subroutine execution addr field ; (third field of entry) LDAAY libind STA ztempa ; save low byte INY LDAAY libind STA ztempa+1 ; save high byte ; STY ztempl ; save Y ; INX ; move offset in 2nd part of index to field giving ; 1st posn in escaped name table field LDAAX contli ; collect 1st posn in esc name table field int5 TAY ; new posn in name table in Y PLA ; get type of entry PHA ; save it again STAIY ztype ; store it in name table LDA ztempa ; get low byte of execution address STAIY zlo ; store it in name table LDA ztempa+1 ; get high byte STAIY zhi ; store it TYA ; put present posn in name table in A EORIM &80 ; if in bottom half of table, shift to top half BMI int5 ; (now in top half) PLA ; balance stack LDY ztempl ; restore Y JMP int4 ; contin with next command subroutine ; int6 INY ; skip next field INY JMP int4 ; contin ; ; emerges with all the command subroutines set in the escaped ; name tables. Only escaped &1B, &7C, &9B, &FC now to do ; int3 LDAIM 1 ; "direct decoding to one byte" entry in table ; LDYIM &1B ; &1B entry STAIY ztype STY esclo+&1B ; decodes to &1B ; LDYIM &7C ; &7C entry STAIY ztype STY esclo+&7C ; decodes to &7C ; LDYIM &9B ; &9B entry STAIY ztype STY esclo+&9B ; decodes to &9B ; LDYIM &FC ; &FC entry STAIY ztype STY esclo+&FC ; decodes to &FC ; ; All name tables now initialised ; RTS ; ; *********************************************************************** ; ; A subroutine to set the pointers ztype, zlo, zhi ; to the lone name tables ; ; Preserves all registers and temporary zero page locations ; setlon PHA ; save A LDAIM :MSB: lonety STA ztype+1 LDAIM :LSB: lonety STA ztype LDAIM :MSB: lonelo STA zlo+1 LDAIM :LSB: lonelo STA zlo LDAIM :MSB: lonehi STA zhi+1 LDAIM :LSB: lonehi STA zhi PLA ; restore A ; RTS ; ; *********************************************************************** ; ; A subroutine to set the pointers ztype, zlo, zhi ; to the escaped name tables ; ; Preserves all registers and zero page locations ; setesc PHA ; save A LDAIM :MSB: esctyp STA ztype+1 LDAIM :LSB: esctyp STA ztype LDAIM :MSB: esclo STA zlo+1 LDAIM :LSB: esclo STA zlo LDAIM :MSB: eschi STA zhi+1 LDAIM :LSB: eschi STA zhi PLA ; restore A ; RTS ; LNK RTF3