CHAPTER 6: STAND-ALONE OPERATION OF A PROGRAM

The user may wish to run programs written in Pascal/MT+ in a ROM based system. This has been a design goal from the beginning and has been done successfully by many users.

The steps required to put a program into ROM are presented below.

  1. Set the hardware stack pointer using $Z (Section 2.2.4.4). The hardware stack default address is the address pointed to by locations 6 and 7 in your CP/M system. If more room is needed for the hardware stack (128 bytes is the default), see the section in Chapter 5 describing how to save more space.

  2. If the program is performing any I/O you have three choices:

    1. Use redirected I/O for all READ and WRITE statements: This replaces the run-time character I/O routines with user written I/O routines (Section 3.7.2).

    2. Rewrite GET, @RNC, and @WNC: @RNC is the run-time read-next-character routine, and @WNC is the write-next-character routine. GET must be rewritten because the read-integer and read-real routines call GET.

    3. Build a simulated CP/M BDOS in your org 0 PROM: If you are constructing a program to run in a totally stand-alone environment (e.g. An Intel SBC-80/10 board) you can write an assembly language module to be linked in front of your program which: 1) jumps around the code which simulates the BDOS and 2) simulates the CP/M BDOS for functions 1: Console Input, 2: Console Output and 5: List Output. The function number will be in the C-register and the data for output will be in the E-register. For input (function 1) return the data in the A-register. All registers are free for use and there is nothing on the stack except the return address. This is just a suggestion, MT MicroSYSTEMS will not provide detailed application support for this method.

  3. The user of a ROM based system may wish to shorten and/or eliminate the INPUT and OUTPUT FIB storage located in the @INI module. This storage is required for TEXT file I/O compatibility but may not be needed in a ROM based environment. The user should be cautious and make sure that any changes to INPUT and OUTPUT are also handled corresponcingly in @RST (read a string from a file) and @CWT (wait for EOLN to be true on a file). Run-time package source code not accompanying the distribution disks may be purchased separately. Check the list in Chapter 1 for run-time source accompanying the software. If the user's program does not do any READ{LN} and/or WRITE{LN} calls and is not recursive and does not use the heap or overlays, then then the @INI procedure can be rewritten in the user's program as:
        PROCEDURE @INI;
        BEGIN
        END;
    

  4. When using the PROCEDURE INTERRUPT [vector] construct for interrupt procedures in a ROM based system, note that the compiler attempts to store into the interrupt vectors. This cannot be done in a ROM environment. The user must construct an assembly language module and link this as the main program (first file). This assembly language module must contain JMP instructions at the interrupt vector locations to jump to the Pascal interrupt routines. The locations of the interrupt routines may be found by using the /M linker switch.

  5. DIVMOD.MAC is provided in source code form because the integer and real divide routines contain a direct call to CP/M for the divide by 0 error message. The user must make appropriate adjustments if this error may ever occur during the execution of his / her program.

  6. Link any changed run-time routines before linking the run-time library to resolve the references, making sure that the /S switch is used:
        LINKMT USERPROG,MYWNC,MYRNC,GET,MYINI,PASLIB/S
    

  7. Strings cannot live below 100H so if you have any constant strings (either named or literal) in the beginning of your program it is suggested that you fill out the remaining space in the first PROM with a table or just with a DS to get the Pascal/MT+ program to exist at locations greater 100H Remember, if you put tables and/or data first that you must jump around them to begin execution of the Pascal program starting with its first byte.

    Listed below are three skeletons for the @INI, @RNC, and @WNC routines which can be used in ROM environments.

    ;---------------------------------------------------------------;
    ;       SAMPLE INITIALIZATION ROUTINE                           ;
    ;---------------------------------------------------------------;
    
            PUBLIC  @INI
            PUBLIC  @SYSIN          ;SYSTEM INPUT VECTOR
            PUBLIC  @SYSOUT         ;SYSTEM OUTPUT VECTOR
            PUBLIC  INPUT           ;DEFAULT INPUT FIB
                                    ;THIS MUST BE PRESENT EVEN IF NO
                                    ;FILE I/O IS DONE
            PUBLIC  OUTPUT          ;AGAIN MUST BE PRESENT EVEN IF NO
                                    ;FILE I/O IS DONE
            EXTRN   @RNC
            EXTRN   @WNC
    
    @INI:
            LXI     H,@RNC
            SHLD    @SYSIN
    
            LXI     H,@WNC
            SHLD    @SYSOUT
    
    ;
    ;       ... ADD MORE HERE FOR HEAP, ETC. PRUNE FROM STANDARD @INI
    ;
            RET
    
            DSEG
    
    @SYSIN: DS      2
    @SYSOUT: DS     2
    
    INPUT:  DS      1               ;DUMMY FIB
    OUTPUT: DS      1               ;DUMMY FIB
            END                     ;AND THAT'S A SIMPLE ONE
    
    ;---------------------------------------------------------------;
    ;       SAMPLE @RNC - READ NEXT CHARACTER ROUTINE               ;
    ;---------------------------------------------------------------;
    
            PUBLIC  @RNC
    @RNC:
            ; INCLUDE CODE HERE TO GET CHARACTER INTO A-REG AND
            ; ECHO IT. ALSO IF USER WANTS TO SIMULATE CON: THE
            ; THE DRIVER MUST ECHO BACKSPACE AS <BACKSPACE, SPACE,
            ; BACKSPACE> AND CR AS CR/LF
            MOV     L,A
            MVI     H,0
            XTHL            ;PUT FUNC VALUE ON STACK AND
                            ;RET ADDR IN HL
            PCHL            ;RETURN
            END
    
    ;---------------------------------------------------------------;
    ;       SAMPLE @WNC - WRITE NEXT CHARACTER ROUTINE              ;
    ;---------------------------------------------------------------;
    
            PUBLIC  @WNC
    
    @WNC:
            POP     H       ;GET RET ADDR
            XTHL            ;PUT IT BACK AND GET PARM CHAR
    
            ; CODE HERE TO WRITE CHARACTER IN L-REG TO OUTPUT DEVICE
            ; IF USER WANTS TO SIMULATE CON: COMPLETELY THE USER
            ; MUST OUTPUT CR AS CR/LF
    
            RET
            END