## CHAPTER 12

### Command/Statement Extensions (Version 1.1 Only)

MCS BASIC-52 V1.1 provides a simple, but yet effective way for the user to add commands and/or statements to the ones that are provided on the chip. All the user must do is write a few simple programs that will reside in external code memory. The step by step approach is as follows:

STEP 1

The user must first inform the MCS BASIC-52 device that the expansion options are available. This is done by putting the character 5AH in code memory location 2002H. When MCS BASIC-52 enters the command mode it will examine code memory location 2002H. If a 5AH is in this location, MCS BASIC-52 will call external code memory location 2048H. The user must write a short routine to set bit 45 (2DH), which is bit 5 of internal memory location 37 (decimal) and place this routine at code memory location 2048H. Setting bit 45 tells MCS BASIC-52 that the expansion option is available. The following simple code will accomplish all that is stated above:

        ORG 2002H
        DB 5AH

        ORG 2048H
        SETB 45
        RET

STEP 2

With bit 45 set, MCS BASIC-52 will call external code memory location 2078H everytime it attempts to tokenize a line that has been entered. At location 2078H, the user must load the DPTR (data pointer) with the address of the user supplied lookup table, complete with tokens.

STEP 3

The user needs the following information to generate a user token table:

1) The user tokens are the numbers 10H through 1FH (16 tokens available).

2) The user token table begins with the token, followed by the ASCII text that is to be represented by that token, followed by a zero (00H) indicating the end of the ASCII, followed by the next token.

3) The table is terminated with the character 0FFH.

EXAMPLE:

               ORG 2078H
               MOV DPTR,#USER_TABLE
               RET

               ORG     2200H           ; THIS DOES NOT NEED TO BE
                                       ; IN THIS LOCATION
    USER_TABLE:

               DB      10H             ; FIRST TOKEN
               DB      'DISPLAY'       ; USER KEYWORD
               DB      00H             ; KEYWORD TERMINATOR

               DB      11H             ; SECOND TOKEN
               DB      'TRANSFER'      ; SECOND USER KEYWORD
               DB      00H             ; KEYWORD TERMINATOR

               DB      12H             ; THIRD TOKEN (UP TO 16)
               DB      'ROTATE'        ; THIRD USER KEYWORD
               DB      0FFH            ; END OF USER TABLE

This same user table is used when MCS BASIC-52 "de-tokenizes" a line during a LIST.

STEP 4

Step 3 tokenizes the user keyword, this means that MCS BASIC-52 translates the user keyword into the user token. So, in the preceding example, the keyword TRANSFER would be replaced with the token 11H. When MCS BASIC-52 attempts to execute the user token, it first makes sure that the user expansion option bit is set (bit 45), then calls location 2070H to get the address of the user vector table. This address is placed in the DPTR. The user vector table consist of series of data words that define the address of the user assembly language routines.

EXAMPLE:

              ORG 2070H                ; LOCATION BASIC CALLS TO
                                       ; GET USER LOOKUP
              MOV DPTR,#VECTOR_TABLE

    VECTOR_TABLE:                      ;
              DW      RUN_DISPLAY      ; ADDRESS OF DISPLAY
                                       ; ROUTINE, TOKEN (10H)
              DW      RUN_TRANSFER     ; ADDRESS OF TRANSFER
                                       ; ROUTINE, TOKEN (11H)
              DW      RUN_ROTATE       ; ADDRESS OF ROTATE
                                       ; ROUTINE, TOKEN (12H)
                                       ;
              ORG     2300H            ; AGAIN, THESE ROUTINES
                                       ; MAY BE PLACED ANYWHERE
                                       ;
    RUN_DISPLAY:                       ;
                                       ; USER ASM CODE FOR DISPLAY GOES HERE
                                       ;
    RUN_TRANSFER:                      ;
                                       ; USER ASM CODE FOR TRANSFER GOES HERE
                                       ;
    RUN_ROTATE:                        ;
                                       ;USER ASM CODE FOR ROTATE GOES HERE
                                       ;

Note that the ordinal position of the data words in the user vector table must correspond to the token, so the user statement with the token 10H must be the first DW entry in the vector table, 11H, the second, 12H, the third, and so on. The order of the tokens in the user table is not important!! The following user lookup table would function properly with the previous example:

EXAMPLE:

    USER_TABLE:
              DB      13H             ; THE TOKENS DO NOT HAVE
              DB      'ROTATE'        ; TO BE IN ORDER IN THE
              DB      00H             ; USER LOOKUP TABLE

              DB      10H
              DB      'DISPLAY'
              DB      00H

              DB      12H
              DB      'TRANSFER'
              DB      0FFH            ; END OF TA8LE

The user may also use the command/statement extension option to re-define the syntax of MCS BASIC- 52. This is done simply by placing your own syntax in the user table and placing the appropriate BASIC token in front of your re-defined keyword. A complete listing of all MCS BASIC-52 tokens and keywords are provided. MCS BASIC-52 will always list out the program using the user defined syntax, but it will still accept the standard keyword as a valid instruction. As an example, suppose that the user would like to substitute the keyword HEXOUT for PH1., then the user would generate the following entry in the user table:

EXAMPLE:

    USER_TABLE:
              DB      8FH             ; TOKEN FOR PH1.
              DB      'HEXOUT'        ; TO BE IN ORDER IN THE
              DB      00H             ; USER LOOKUP TABLE

              DB      10H
              DB      'DISPLAY'
              DB      00H

                                      ; REST OF USER_TABLE

              DB      0FFH            ; END OF TABLE

MCS BASIC-52 will now accept the keyword HEXOUT and it will function in a manner identical to PH1. PH1 will still function correctly, however HEXOUT will be displayed when the user LISTs a program.

    TOKEN     KEYWORD          TOKEN     KEYWORD          TOKEN     KEYWORD

    80H       LET                   0B0H      ABS                 0E1H      **
    81H       CLEAR                 0B1H      INT                 0E2H      *
    82H       PUSH                  0B2H      SGN                 0E3H      +
    83H       GOTO                  0B3H      NOT                 0E4H      /
    84H       PWM                   0B4H      COS                 0E5H      -
    85H       PH0.                  0B5H      TAN                 0E6H      .XOR.
    86H       UI                    0B6H      SIN                 0E7H      .AND.
    87H       UO                    0B7H      SOR                 0E8H      .OR.
    88H       POP                   0B8H      CBY                 0E9H      - (NEGATE)
    89H       PRINT                 0B9H      EXP                 0EAH      =
    89H       P.                    0BAH      ATN                 0EBH      >=
    89H       ? (V1.1)              0BBH      LOG                 0ECH      <=
    8AH       CALL                  0BCH      DBY                 0EDH      <>
    8BH       DIM                   0BDH      XBY                 0EEH      <
    8CH       STRING                0BEH      PI                  0EFH      >
    8DH       BAUD                  0BFH      RND                 0F0H      RUN
    8EH       CLOCK                 0C0H      GET                 0FlH      LIST
    8FH       PH1.                  0C1H      FREE                0F2H      NULL
    90H       STOP                  0C2H      LEN                 0F3H      NEW
    91H       ONTIME                0C3H      XTAL                0F4H      CONT
    92H       ONEX1                 0C4H      MTOP                0F3H      PROG (not V1.2)
    93H       RETI                  0C5H      TIME                0F6H      XFER
    94H       DO                    0C6H      IE                  0F7H      RAM
    95H       RESTORE               0C7H      IP                  0F8H      ROM
    96H       REM                   0C8H      TIMER0              0F9H      FPROG (not V1.2)
    97H       NEXT                  0C9H      TIMER1              0FAH      not used
    98H       ONERR                 0CAH      TIMER2 (not V1.2)   0FBH      not used
    99H       ON                    0CBH      T2CON (not V1.2)    0FCH      not used
    9AH       INPUT                 0CCH      TCON                0FDH      not used
    9BH       READ                  0CDH      TMOD                0FEH      not used
    9CH       DATA                  0CEH      RCAP2 (not V1.2)    0FFH      not used
    9DH       RETURN                0CFH      PORT1
    9EH       IF                    0D0H      PCON
    9FH       GOSUB                 0D1H      ASC(
    0A0H      FOR                   0D2H      USING(
    0A1H      WHILE                 0D2H      U.(
    0A2H      UNTIL                 0D3H      CHR(
    0A3H      END                   0D4H      not used
    0A4H      TAB                   0D5H      not used
    0A5H      THEN                  0D6H      not used
    0A6H      TO                    0D7H      not used
    0A7H      STEP                  0D8H      not used
    0A8H      ELSE                  0D9H      not used
    0A9H      SPC                   0DAH      not used
    0AAH      CR                    0DBH      not used
    0ABH      IDLE                  0DCH      not used
    0ACH      ST@ (V1.1)            0DDH      not used
    0ADH      LD@ (V1.1)            0DEH      not used
    0AEH      PGM (V1.1, not V1.2)  0DFH      not used
    0AFH      RROM(V1.1)            0E0H      (

        V1.1  - This statement is only available in version 1.1
    not V1.2  - This statement has been disabled in version 1.2 and 1.2a