Routines |
Prev: 2996 | Up: Map | Next: 2AB1 |
The present string can be sliced using this subroutine. The subroutine is entered with the parameters of the string being present on the top of the calculator stack and in the registers A, B, C, D and E. Initially the SYNTAX/RUN flag is tested and the parameters of the string are fetched only if a line is being executed.
|
||||||||||
SLICING | 2A52 | CALL SYNTAX_Z | Check the flag. | |||||||
2A55 | CALL NZ,STK_FETCH | Take the parameters off the stack in 'run-time'. | ||||||||
The possibility of the 'slice' being '()' has to be considered.
|
||||||||||
2A58 | RST $20 | Get the next character. | ||||||||
2A59 | CP ")" | Is it a ')'? | ||||||||
2A5B | JR Z,SL_STORE | Jump forward if it is so. | ||||||||
Before proceeding the registers are manipulated as follows:
|
||||||||||
2A5D | PUSH DE | The 'start' goes on the machine stack. | ||||||||
2A5E | XOR A | The A register is cleared and saved. | ||||||||
2A5F | PUSH AF | |||||||||
2A60 | PUSH BC | The 'length' is saved briefly. | ||||||||
2A61 | LD DE,$0001 | Presume that the 'slice' is to begin with the first character. | ||||||||
2A64 | RST $18 | Get the first character. | ||||||||
2A65 | POP HL | Pass the 'length' to HL. | ||||||||
The first parameter of the 'slice' is now evaluated.
|
||||||||||
2A66 | CP $CC | Is the present character a 'TO'? | ||||||||
2A68 | JR Z,SL_SECOND | The first parameter, by default, will be '1' if the jump is taken. | ||||||||
2A6A | POP AF | At this stage A is zero. | ||||||||
2A6B | CALL INT_EXP2 | BC is made to hold the first parameter. A will hold +FF if there has been an 'out of range' error. | ||||||||
2A6E | PUSH AF | Save the value anyway. | ||||||||
2A6F | LD D,B | Transfer the first parameter to DE. | ||||||||
2A70 | LD E,C | |||||||||
2A71 | PUSH HL | Save the 'length' briefly. | ||||||||
2A72 | RST $18 | Get the present character. | ||||||||
2A73 | POP HL | Restore the 'length'. | ||||||||
2A74 | CP $CC | Is the present character a 'TO'? | ||||||||
2A76 | JR Z,SL_SECOND | Jump forward to consider the second parameter if it is so; otherwise show that there is a closing bracket. | ||||||||
2A78 | CP ")" | |||||||||
This entry point is used by the routine at STK_VAR.
|
||||||||||
SL_RPT_C | 2A7A | JP NZ,REPORT_C | ||||||||
At this point a 'slice' of a single character has been identified. e.g. A$(4).
|
||||||||||
2A7D | LD H,D | The last character of the 'slice' is also the first character. | ||||||||
2A7E | LD L,E | |||||||||
2A7F | JR SL_DEFINE | Jump forward. | ||||||||
The second parameter of a 'slice' is now evaluated.
|
||||||||||
SL_SECOND | 2A81 | PUSH HL | Save the 'length' briefly. | |||||||
2A82 | RST $20 | Get the next character. | ||||||||
2A83 | POP HL | Restore the 'length'. | ||||||||
2A84 | CP ")" | Is the present character a ')'? | ||||||||
2A86 | JR Z,SL_DEFINE | Jump if there is not a second parameter. | ||||||||
2A88 | POP AF | If the first parameter was in range A will hold zero, otherwise +FF. | ||||||||
2A89 | CALL INT_EXP2 | Make BC hold the second parameter. | ||||||||
2A8C | PUSH AF | Save the 'error register'. | ||||||||
2A8D | RST $18 | Get the present character. | ||||||||
2A8E | LD H,B | Pass the result obtained from INT_EXP2 to the HL register pair. | ||||||||
2A8F | LD L,C | |||||||||
2A90 | CP ")" | Check that there is a closing bracket now. | ||||||||
2A92 | JR NZ,SL_RPT_C | |||||||||
The 'new' parameters are now defined.
|
||||||||||
SL_DEFINE | 2A94 | POP AF | Fetch the 'error register'. | |||||||
2A95 | EX (SP),HL | The second parameter goes on the stack and the 'start' goes to HL. | ||||||||
2A96 | ADD HL,DE | The first parameter is added to the 'start'. | ||||||||
2A97 | DEC HL | Go back a location to get it correct. | ||||||||
2A98 | EX (SP),HL | The 'new start' goes on the stack and the second parameter goes to HL. | ||||||||
2A99 | AND A | Subtract the first parameters from the second to find the length of the 'slice'. | ||||||||
2A9A | SBC HL,DE | |||||||||
2A9C | LD BC,$0000 | Initialise the 'new length'. | ||||||||
2A9F | JR C,SL_OVER | A negative 'slice' is a 'null string' rather than an error condition. | ||||||||
2AA1 | INC HL | Allow for the inclusive byte. | ||||||||
2AA2 | AND A | Only now test the 'error register'. | ||||||||
2AA3 | JP M,REPORT_3 | Jump if either parameter was out of range for the string. | ||||||||
2AA6 | LD B,H | Transfer the 'new length' to BC. | ||||||||
2AA7 | LD C,L | |||||||||
SL_OVER | 2AA8 | POP DE | Get the 'new start'. | |||||||
2AA9 | RES 6,(IY+$01) | Ensure that a string is still indicated (reset bit 6 of FLAGS). | ||||||||
SL_STORE | 2AAD | CALL SYNTAX_Z | Return at this point if checking syntax; otherwise continue into STK_ST_0. | |||||||
2AB0 | RET Z |
Prev: 2996 | Up: Map | Next: 2AB1 |