; ; ********************************************************************* ; ; The stack managing section of a Redefinable Telesoftware Decoder ; ; ; (C) C.J. Oswald 1982 ; -- rtf3 -- ; ; ********************************************************************* erro01 * &100 ; ; ; *********************************************************************** ; ; A subroutine to save all the registers and temporary zero page ; locations on the soft stack ; ; Does NOT preserve registers and temporary zero page locations itself! ; ; The following code could probably be compacted ; saveal PHA ; Put A,X,Y,ztempa and ztempl on hard stack TXA PHA TYA PHA LDA ztempa PHA LDA ztempa+1 PHA LDA ztempl PHA LDA stackf ; copy stack pointer to zero page STA ztempa LDA stackf+1 STA ztempa+1 LDYIM 0 ; offset of zero from the pointer ; sa1 PLA ; transfer data that was put temporarily on the main stack STAIY ztempa INY ; next free location on soft stack CPYIM 6 ; all six items transferred? BNE sa1 TYA ; load A with 6 LDY ztempa+1 ; get msb of soft stack pointer CLC ADC ztempa ; update soft stack pointer STA stackf BCC sa2 ; msb of pointer does not need incrementing INY ; (it does) ; sa2 STY stackf+1 CPYIM :MSB: stackt BMI sa3 ; the stack is not full yet BNE sa4 ; the stack has overflowed - give an error message & abort CMPIM :LSB: stackt BCC sa3 ; the stack is not full yet ; ; The soft stack has overflowed - give an error message & abort ; sa4 LDAIM nostac ; error code for out of soft stack workspace JMP error ; ; Soft stack now has relevant data on it ; sa3 RTS ; ; *********************************************************************** ; ; A subroutine to restore all the registers and temporary zero page ; locations to the values that they were when saveal was last called ; restor LDA stackf ; move the soft stack pointer back 6 positions LDY stackf+1 SEC SBCIM 6 BCS ra1 ; msb of pointer unaffected by subtraction DEY ; ra1 STA stackf ; put back new value of pointer STA ztempa STY stackf+1 STY ztempa+1 LDYIM 5 ; offset of 5 from new pointer position ; ra2 LDAIY ztempa ; get item from soft stack PHA ; temporarily put it on main stack DEY ; offset moved to next item BPL ra2 PLA ; move items from main stack to original registers &c STA ztempl PLA STA ztempa+1 PLA STA ztempa PLA TAY PLA TAX PLA RTS ; *********************************************************************** ; A subroutine to return the byte at the head of the queue of decode ; telesoftware. If the queue is empty, it calls qname to replenish it. ; ; PreservesAY X and temporary zero page locations ; decode JSR saveal ; save registers and temporary zero page locations ; d5 LDA queue ; check if anything is in queue CMP headqu LDA queue+1 SBC headqu+1 BCC d1 ; something in queue ; ; Nothing in queue ; d2 JSR chopqu ; reinitialise queue JSR qname ; decode a name BCC d5 ; if all of file has not been loaded, go round again ; ; End of telesoftware file ; d4 PLA ; see where this subroutine was called from TAY PLA CPYIM :LSB: (fromge+2) BNE d6 ; not called from gettel subroutine CMPIM :MSB: (fromge+2) BNE d6 ; not called from gettel subroutine ; ; This subroutine called from gettel subroutine, and so the EOF ; is OK, and should be signalled by setting the carry bit with A=0 ; PHA ; restore return address TYA PHA JSR restor ; restore registers and temporary zero page locations SEC ; C=1 RTS ; ; This subroutine not called from gettel subroutine, and so the EOF ; is unexpected. Give an error message and abort ; d6 LDAIM unex00 ; error code for unexpected end of file JMP error ; ; There is already something waiting in the queue - get it ; d1 LDA headqu PHP STA ztempa LDA headqu+1 STA ztempa+1 LDYIM 0 LDAIY ztempa ; get the byte from the head of the queue DEC headqu ; decrement pointer PLP BNE d7 DEC headqu+1 ; d7 PHA JSR restor ; restore registers and temporary zero page locations PLA ; pass the byte in A CLC ; ensure carry is clear RTS ; ; *********************************************************************** ; ; Subroutine to call the input buffer control routines (an OSWORD call) ; ; PreservesAY X and temporary zero page locations ; ; The code name for the select routine is passed in A ; buffer STA bufflo ; save code name for select routine Pha JSR saveal ; save A, X, Y & temporary zero page locations Pla CmpIM next01 BEQ bfctrl CmpIM next02 BEQ bfctrl CmpIM nextpa BNE bfct00 bfctrl Lda commle Bpl bfct00 Jsr stri02 = 13 = 10 = "Searching..." = 13 = 10 = 0 bfct00 LDXIM :LSB: bufflo ; set XY to point to bufflo LDYIM :MSB: bufflo LDAIM contro ; handle is contro JSR osword ; OSWORD call ;bit &FF ;bpl bfctrl3 ; LOW LEVEL TEST FOR ESCAPE ;LDAIM &7E ;JSR OSBYTE ;LdaIM nomore ; NOT GOOD ENOUGH, NEEDS CLOSE OF EXEC FILE ;Jmp error ;.bfctrl3 JSR restor ; restore A, X, Y & temporary zero page locations RTS ; ; *********************************************************************** ; ; Error handling subroutine ; error PHA ; save error code JSR softin ; reinitialise stack, variables, etc & close file LDYIM (errore-errorm+1) ; copy error message from paged ROM to RAM ; error1 LDAAY errorm STAAY erro01 DEY BPL error1 PLA ; restore error code STA erro01+1 ; store it with error message JMP erro01 ; execute brk ; errorm BRK NOP = "Telesoftware error" BRK errore ; ; *********************************************************************** ; ; A subroutine to decode the number of bytes requested (in A) ; and add them to the top of the heap, adjusting heapfr as is ; necessary ; ; PreservesAY X and temporary zero page locations ; heapby PHA ; save A JSR saveal ; save registers and temporary zero page locations LDA heapfr ; set ztempa to point to top of heap STA ztempa LDA heapfr+1 STA ztempa+1 PLA ; restore A INC operan ; set operan flag LDYIM 0 ; offset of zero STAIY ztempa ; save length of data as the first byte TAX ; number of bytes in X BEQ hpb1 ; length of zero (!) ; hpb2 INY ; increment offset JSR decode ; get next decode byte STAIY ztempa ; save it in heap DEX BNE hpb2 ; continue until end of operan ; hpb1 TYA ; offset of last item in A SEC ; increment heapfr by offset plus one ADC heapfr STA heapfr BCC hpb3 INC heapfr+1 ; hpb3 DEC operan ; restore operan to its original value JSR restor ; restore registers and temporary zero page locations RTS ; LNK RTF4