Previous Next Contents Index
The control routine

This routine is called from 'START' at #0008, when the DISCiPLE system is paged in.
It has three main tasks:
- If a disc channel has been requested, it jumps to the required 'input' or
  'output' routine.
- If a hook/command code is used, it jumps to the required routine.
- If an error occurred in the 'main' ROM, it checks whether a DISCiPLE command was
  used. If so the corresponding routine is called, otherwise a return is made to
  the 'main' ROM, except when the DISCiPLE variable ONERR holds a non zero address.
  In that case a CALBAS to that address is made.

0597 START_3    LD   (#1DD6),HL          DISCiPLE's CH_ADD (D_CH_ADD).
059A            LD   (#1DEA),A
059D            POP  HL                  Get RETurn address (usually points to
059E            PUSH HL                  the error code).
059F            PUSH DE

Now see if a DISCiPLE channel has been requested.

05A0            AND  A
05A1            LD   DE,#15FE            If a channel has been requested, this
                                         is the RETurn address stored by the
                                         CALL #162C in the 'CALL-SUB' subroutine
                                         in the Spectrum ROM.
05A4            SBC  HL,DE
05A6            POP  DE
05A7            JR   NZ,#05C7,START_4    Jump if no channels have been requested.
05A9            LD   HL,#0050,UNPAGE_1   Make UNPAGE_1 RETurn address
05AC            PUSH HL

Now see if the channel requested is the "P" channel. The DISCiPLE "P" channel differs
only from the Spectrum's in the 'input' and 'output' addresses. For the DISCiPLE they
both are #0008. There is no information in the channel on what the DISCiPLE system's
in/output addresses are (as with "D" channels). So it has to be handled separately.

05AD            PUSH BC
05AE            LD   HL,(23631)          Fetch CHANS.
05B1            LD   BC,16               Point to "P" channel.
05B4            ADD  HL,BC
05B5            SBC  HL,DE               DE holds address of requested channel.
05B7            POP  BC
05B8            LD   A,(#1DEA)           Restore A register.
05BB            JP   Z,#1783,PCHAN_OUT   Jump if DISCiPLE "P" channel was used.
05BE            LD   HL,4                DE holds address of routine pointer-4. See
                                         #15EF in 'main' ROM.
05C1            ADD  HL,DE               HL now holds address of routine pointer.
05C2            LD   E,(HL)
05C3            INC  HL                  Fetch routine address.
05C4            LD   D,(HL)
05C5            EX   DE,HL               HL now points to the routine.
05C6            JP   (HL)                Jump to the appropriate 'input' or
                                         'output' routine.

At this point, the DISCiPLE has been paged-in by an error in the 'main' ROM or by a
hook/command code. When an error occurred during a CALBAS and D_ERR_SP isn't zero,
the error has to be handled by the 'main' ROM. If D_ERR_SP is zero, the error is
reported to the routine which executed a CALBAS.

05C7 START_4    LD   A,(#1DE5)           Check if the DISCiPLE CALLed a Spectrum
05CA            CP   #47                 ROM routine.
05CC            JR   NZ,#05EC,START_5    Jump if it didn't.
05CE            XOR  A
05CF            LD   (#1DE5),A           Clear CALBAS executing.
05D2            LD   (#1ACF),A           Clear FLAGS3.
05D5            POP  HL                  Fetch RETurn address.
05D6            RST  #10,CALBAS          This CALL's a LD A,(HL) in the Spectrum
05D7            DEFW #007B               ROM, so the error code is fetched.
05D9            LD   (23610),A           Store the error code in ERR_NR.
05DC            LD   HL,(#0296)          Fetch D_ERR_SP.
05DF            LD   A,H
05E0            OR   L                   Jump if D_ERR_SP was zero, that is when
05E1            JP   Z,#06D6,SPEC_ERR2   the 'main' ROM has to handle the error.
05E4            LD   A,(23610)           Copy error code in A register.
05E7            SET  7,A                 Signal 'Spectrum error'.
05E9            LD   SP,HL               Clear stack.
05EA            SCF                      Signal 'error and exit', someone else has
05EB            RET                      to handle the error.

Now it is most likely that the DISCiPLE has to handle the problem which the 'main' ROM
couldn't. So see if it is an error or a hook/command code.

05EC START_5    POP  HL                  Fetch address of error or hook/command
                                         code (the byte after RST #08).
05ED            RST  #10,CALBAS          Fetch the byte.
05EE            DEFW #007B
05F0            LD   (IY+0),A            Store it in ERR_NR.
05F3            CP   255                 Check if the error is 'OK'.
05F5            JP   Z,#2948,REP_20      Give 'OK GDOS' message if so.
05F8            SUB  27                  Adjust range, hookcodes start at 0 now.
05FA            JP   NC,#04C3,HOOK_CODE  Jump if it is a hook or command code.
05FD            CP   240                 Jump if the error is
05FF            JR   Z,#060E,TEST_INPUT  'Nonsense in BASIC'.
0601            CP   243
0603            JR   Z,#060E,TEST_INPUT  Also if it is 'Invalid filename'.
0605            CP   252
0607            JR   Z,#060E,TEST_INPUT  Or 'Invalid stream'.
0609            CP   230
060B            JP   NZ,#06CD,SPEC_ERR   Jump to the 'main' ROM error handler if
                                         it isn't 'Variable not found'.
060E TEST_INPUT BIT  5,(IY+55)           Use 'main' ROM error handler also if in
0612            JP   NZ,#06CD,SPEC_ERR   INPUT mode.

Now a loop is entered to find the BASIC command which produced the error. The way in
which this is done is very simple, a backward search is made until a byte value >= 206
(value of first BASIC command 'DEF FN') is found. There are a few cases in which this
algorithm fails, e.g.:
-When a number in a BASIC line is followed by its hidden representation (starts
 with a CHR$ 14 number marker), this could contain a byte >= 206.
-If the line the error occurred on doesn't contain a BASIC command the searching
 continues until a byte value >= 206 is found. So line length, line number and even
 previous lines could be searched.

0615            LD   HL,(23645)          Fetch CH_ADD.
0619            LD   A,(HL)
061A            CP   206                 Test for DEF FN (first BASIC command).
061C            JR   C,#0618,FIND_COM    Loop until a byte >= 206 is found.
061E            LD   (23645),HL          Update CH_ADD.
0621            RST  48,SYNTAX_Z
0622            JR   NZ,#0651,RUNTIME    Jump during RUNtime.

The following loop removes all number representations from the line.

0624            DEC  HL                  Balance "INC HL" below.
0625            LD   C,0                 ???? C isn't used.
0628            LD   A,(HL)              Next character.
0629            CP   14                  Is it a 'number' marker ?
062B            JR   NZ,#064C,NO_NUM     Jump if not.
062D            PUSH BC
062E            PUSH HL
062F            LD   BC,6
0632            RST  #10,CALBAS          Reclaim the 6 bytes forming a number
0633            DEFW #19E8,RECLAIM_2     and the 'number marker'.
0635            POP  HL
0636            PUSH HL
0637            LD   DE,(#1DD6)          Fetch D_CH_ADD.
063B            AND  A                   Jump if the number bytes reclaimed were
063C            SBC  HL,DE               after the character pointed to by
063E            JR   NC,#064A,NXT_1      D_CH_ADD.
0640            EX   DE,HL               Otherwise D_CH_ADD has to be updated.
0641            LD   BC,6
0644            AND  A                   The character pointed by D_CH_ADD has
0645            SBC  HL,BC               been moved '6' bytes down.
0647            LD   (#1DD6),HL          Update D_CH_ADD.
064A NXT_1      POP  HL
064B            POP  BC
064C NO_NUM     LD   A,(HL)
064D            CP   13
064F            JR   NZ,#0627,RCLM_NUM   Repeat until 'end of line' is found.

Now the work areas and some DISCiPLE variables are cleared.

0651 RUNTIME    RST  #10,CALBAS          Clear Spectrum work areas by calling
0652            DEFW #16BF,SET_WORK      'SET_WORK' in 'main' ROM.
0654            LD   HL,#1DF4
0657            LD   BC,60
065A RESET_VARS LD   (HL),255            Reset DISCiPLE work areas, including
065C            INC  HL                  UFIA1 and UFIA2.
065D            DEC  BC
065E            LD   A,B
065F            OR   C
0660            JR   NZ,#065A,RESET_VARS
0662            LD   (#1ACF),A           Clear FLAGS3.
0665            LD   A,#44               Signal 'System loaded'.
0667            LD   (#1DE4),A
066A            LD   IX,#1AC3            Point to DISCiPLE system variables.

Finally the command is fetched from the line, and if its a 'new' command the
appropriate routine is called.

066E            CALL #002C,GET_C_RAM     Fetch the command.
0671            LD   (#1DFF),A           Store it.

This part is also called from the network server routine at #0325.

0674 EXEC_COMM  CP   207                 Is the command 'CAT' ?
0676            JP   Z,#0855,CAT         Jump to the CAT routine if so.
0679            CP   208                 Also for 'FORMAT',...
067B            JP   Z,#102C,FORMAT
067E            CP   209                 ...'MOVE',...
0680            JP   Z,#10B1,MOVE
0683            CP   210                 ...'ERASE',...
0685            JP   Z,#0932,ERASE
0688            CP   211                 ...'OPEN #',...
068A            JP   Z,#1216,OPEN#
068D            CP   212                 ...'CLOSE #',...
068F            JP   Z,#13C4,CLOSE#
0692            CP   213                 ...'MERGE',...
0694            JP   Z,#0DF8,MERGE
0697            CP   214                 ...'VERIFY',...
0699            JP   Z,#0DF3,VERIFY
069C            CP   239                 ...'LOAD',...
069E            JP   Z,#0DEE,LOAD
06A1            CP   244                 ...'POKE',...
06A3            JP   Z,#0438,POKE@
06A6            CP   248                 ...'SAVE',...
06A8            JP   Z,#0D41,SAVE
06AB            CP   251                 ...'CLS',...
06AD            JP   Z,#1467,CLS#
06B0            CP   253                 ...'CLEAR',...
06B2            JP   Z,#13E7,CLEAR#
06B5            CP   255                 ...'COPY',...
06B7            JP   Z,#1621,COPY
06BA            LD   HL,(#02A6)          Fetch ONERR address.
06BD            LD   A,H
06BE            OR   L
06BF            JR   Z,#06CD,SPEC_ERR    Jump if no ON ERROR address.
06C1            LD   (#06C8),HL          Store it so it can be CALBASsed.
06C4            LD   A,(#1DFF)           Fetch command which has to be examined
06C7            RST  #10,CALBAS          by user-routine (BASIC extensions).
06C8            DEFW #0000,EXT_BASIC     CALL the extend BASIC routine(s).
06CA            JP   #0419,END           Test end of command and exit.

This routine must be entered with the error code in (ERR_NR), and does the same as
the 'main' ROM  'ERROR' restart, except when error messages are to be supressed. This
is indicated by a non zero value in 23728.

06CD SPEC_ERR   LD   HL,(#1DD6)          Fetch D_CH_ADD.
06D0            LD   (23645),HL          Restore CH_ADD.
06D3            LD   (23647),HL          Restore X_PTR.
06D6 SPEC_ERR2  LD   HL,#0058
06D9            RST  #30,SYNTAX_Z        RETurn to #58, which is in ERROR_2, in
06DA            JP   Z,#004F,UNPAGE_HL   the Spectrum ROM when checking syntax.
06DD            LD   A,(23728)
06E0            AND  A                   Also RETurn to #58 in 'main' ROM when
06E1            JP   Z,#004F,UNPAGE_HL   error messages aren't to be supressed.
06E4            LD   A,(23610)           Otherwise signal 'Spectrum error'.
06E7            SET  7,A
06E9            LD   (23610),A
06EC            LD   HL,#1B7D,STMT_R_1   And RETurn to STMT_R_1 in the Spectrum
06EF            JP   #004F,UNPAGE_HL     ROM.

This routine loads one byte from the network.

06F4            CALL #2963,JN_INPUT      Call the ROM routine.
06F7            POP  IX
06F9            RET

This routine saves one byte to the network.

06FC            CALL #2966,JN_OUTPUT     Call the ROM routine.
06FF            POP  IX
0701            RET
Previous Next Contents Index