; ; ********************************************************************* ; ; The Command Subroutines for a Redefinable Telesoftware Decoder ; ; ; (C) C.J. Oswald 1982 ; -- rtf9 -- ; ; ********************************************************************* ; ; ; The command subroutine ; ; Destroys all registers & temporary zero page locations ; dlc JSR match ; match requested command subroutine title with index entry ; returns with XA=execution address, ztempl=type of ; command and Y=position in name tables JSR setlon ; set ztype, zlo and zhi to point to lone name tables ; dc STAIY zhi ; save execution address in name tables TXA STAIY zlo LDA ztempl ; save type entry in name tables STAIY ztype CLC ; ensure carry is clear RTS ; ; The command subroutine ; ; Destroys all registers & temporary zero page locations ; dec JSR match JSR setesc ; set ztype, zlo and zhi to point to escaped name tables JMP dc ; match LDYIM 4 ; push name & letters of command subroutine's title ; match1 JSR decode PHA DEY BNE match1 LDAIM :LSB: libind ; set ztempa to point to libind STA ztempa LDAIM :MSB: libind STA ztempa+1 PLA ; get last letter of requested title TAY ; store in Y PLA ; middle letter in X TAX PLA ; first letter in A JSR match7 ; attempt to match title with an entry in library's index BCC match8 ; successful match PHA ; save first letter LDA extral ; set ztempa to point to extension of library's index BEQ match9 ; no extension - ie command reuested not available STA ztempa+1 LDA extral STA ztempa PLA ; restore first letter JSR match7 ; attempt again to match (this time in extension index) BCS match9 ; match fails - ie command requested not available ; ; Successful match of requested command subroutine title and entry in ; index. ztempl=type of command, XA=execution address ; match8 STA ztempa+1 ; save msb of execution address PLA ; get position of entry in name tables TAY LDA ztempa+1 ; restore msb of execution address RTS ; ; Cannot find the command subroutine requested ; - give an error message and abort ; match9 LDAIM &CB ; error code for command subroutine not available JMP error ; ; AttemptAX to match command subroutine title (in A,Y) to an entry ; in the library's index pointed to by ztempa ; match7 STA ztempl ; put first letter of title in ztempl TYA ; and last letter on stack PHA LDYIM 0 ; offset of zero from start of index ; match3 LDAIY ztempa ; test for 1st letter of title being NUL BEQ match2 ; (yes - end of this section of index) CMP ztempl ; first letter same as requested? BNE match4 ; (no) INY ; move onto 2nd letter of title in index TXA CMPIY ztempa ; second letter same as requested? BNE match5 ; (no) INY ; move onto 3rd letter of title in index PLA PHA ; keep stack level constant CMPIY ztempa ; third letter same as requested? BNE match6 ; (no) ; ; The titles match! ; PLA ; balance stack INY ; move onto second field of entry LDAIY ztempa ANDIM &7F ; remove any default name table information in top bit STA ztempl ; save type of command at ztempl INY ; move onto the third field of entry LDAIY ztempa TAX ; execution address in XA INY LDAIY ztempa CLC ; ensure carry is clear (indicates successful search) RTS ; ; Try next entry ; match4 INY ; match5 INY ; match6 INY INY INY INY ; offset pointer now at next entry JMP match3 ; try again ; ; End of this section of the index - no match so far ; match2 PLA ; restore A,Y TAY LDA ztempl SEC ; set carry to indicate lack of success RTS ; ; ********************************************************************** ; ; The command subroutine ; ; Destroys all registers & temporary zero page locations ; deb LDAIM endofb ; mark end of block JSR buffer LDAIM :LSB: checkc STA ztempa LDAIM :MSB: checkc STA ztempa+1 JSR dlocat ; decode operan (crc) and store at checkc CPXIM 0 BEQ deb1 ; no crc LDA crc CMP checkc BNE crcerr ; there is a reception error LDA crc+1 CMP checkc+1 BEQ deb1 ; crc is OK ; ; There has been a crc error due to bad reception ; ask for block to be retransmitted ; crcerr LDAIM 0 STA pass LDAIM retran ; code for retran JSR buffer CLC ; ensure carry is clear RTS ; ; ; Entry point for ens of teletext block debtxt LDAIM endofb ; mark end of block JSR buffer ; Entry point for end of block with no CRC ; debnoc ; deb1 LDA pass ; see if on 1st pass CMPIM 1 BMI deberr ; on zeroth pass (should not occur!) BNE deb2 ; on 2nd pass ; ; At end of block on 1st pass ; LDAIM retu00 ; move back to start of block JSR buffer INC pass ; set pass=2 JMP deb7 ; return from subroutine ; ; Reached end of block without locating start of block ; give error code & abort ; deberr LDAIM cantfi ; error code for can't find start of block JMP error ; ; On 2nd pass at end of block ; deb2 LDAIM unlo02 ; empty the page so as not to get it again JSR buffer LDA lastbl ; is this the last block in the file? BEQ deb3 ; (no) LDA thisbl ; get the number of this block STA blocks ; set it to be the total number of blocks LDAIM 0 ; clear last block flag STA lastbl ; deb3 INC blockn ; increment count of blocks got LDA blocks ; see if all the blocks have now been got CMP blockn BEQ deb4 ; (yes) LDAIM 0 ; set to zeroth pass of data STA pass LDA ordern BEQ deb9 ; order of blocks matters LDAIM nextpa ; code for next block at the head of a chain JMP deb10 ; deb9 LDAIM next02 ; code for next block in a chain ; deb10 ; JSR buffer ; get next block of telesoftware loaded LDA thisbl ; mark this block as got LSRA ; divide the no. of this block by 8 LSRA LSRA TAY ; offset in bytes from base of blockg of the bit ; ; corresponding to this block LDA thisbl ; get the no. of this block again ANDIM 7 ; get the 3 lsb's TAX LDAIM 1 ; put one set bit in A CPXIM 0 ; shift that bit X times BEQ deb8 ; deb6 ASLA DEX BNE deb6 ; deb8 ORAAY blockg ; or with byte that holds bit corresponding to block STAAY blockg ; and replace (ie set that bit) ; INC thisbl ; increment block number in case blocks unnumbered ; deb7 CLC ; ensure carry is clear (not EOF) RTS ; ; All blocks have now been got ; deb4 SEC ; set the carry to indicate EOF RTS ; ; *********************************************************************** ; ; A subroutine to print commens ; ; Preserves all registers and temporary zero page locations ; printc JSR saveal LDA commen ; copy commen pointer to zero page STA ztempa LDA commen+1 STA ztempa+1 LDYIM 0 LDAIY ztempa ; get length of commen TAX ; pcomm INY LDAIY ztempa ; get next byte of commen JSR osasci ; print it DEX BNE pcomm JSR restor RTS ; ; *********************************************************************** ; LNK TLINK