Identify if the star command is one we can handle - 322 bytes (1.9%)


§1. Handle a star command that the OS doesn't know.

.handleUnrecognisedStarCommand = $8167
    PHA                                                 }
    TYA                                                 } remember A,Y
    PHA                                                 }

    JSR .getPrivateWorkspaceAddress                     

    Loop to check user star command against each star command in our table
    LDX #0                                              
    STX .vduTempStoreDC                                 command index = 0
    STY .vduTempStoreDA                                 index into user input string = 0

.tryNextCommand = $8173
    LDY .vduTempStoreDA                                 Y = start of user input string
    JSR .checkForCommandMatch                           

    BEQ .starCommandFound                               if (command found) then branch

    Skip forward to end of command
-
    INX                                                 
    LDA .commandNameTable,X                             
    BNE -                                               

    INC .vduTempStoreDC                                 increment command index
    INX                                                 skip past terminator
    LDA .commandNameTable,X                             
    BNE .tryNextCommand                                 if (not at end of table) then branch

.exitRestoringAXYLocal = $8188
    JMP .exitRestoringAXY                               

.skipSpacesLoop = $818b
    INY                                                 }
.starCommandFound = $818c
    LDA (.stringInputBufferAddressLow),Y                }
    CMP #' '                                            } skip past spaces
    BEQ .skipSpacesLoop                                 }

    ASL .vduTempStoreDC                                 double the command index to get a
                                                        table offset
    BEQ .skipGXRActiveCheck                             if (star GXR) then branch

    LDX .currentlySelectedROM                           }
    LDA .romWorkspaceBytes,X                            }
    BEQ .exitRestoringAXYLocal                          } if (GXR is not active) then branch
                                                        } (exit)

.skipGXRActiveCheck = $819d
    LDX .vduTempStoreDC                                                     
    CPX #.endOfCommandsNotRequiringSpriteSpace - .starCommandAddressTable   first set of
                                                                            commands don't
                                                                            require sprite
                                                                            space allocated
    BCC .getCommandAddressFromTableAndCallIt                                if (no sprite
                                                                            space needed)
                                                                            then branch

    Check we have sprite memory
    STY .vduTempStoreDD                                 store Y
    JSR .getPrivateWorkspaceAddress                     make sure we have the workspace
                                                        address

    LDY #.workspaceOffsetSpritePages                    }
    LDA (.privateWorkspaceLow),Y                        } check for no sprite memory
    BEQ .noSpriteMemoryError                            } if (no sprite memory allocated)
                                                        } then branch

    Check we are in a graphics MODE
    LDY .vduTempStoreDD                                                 recall Y
    CPX #.endOfCommandsRequiringSpriteSpace - .starCommandAddressTable  third set of
                                                                        commands need to be
                                                                        in a graphics MODE
    BCC .getCommandAddressFromTableAndCallIt                            if (in second set of
                                                                        commands) then branch

    LDA .vduPixelsPerByteMinusOne                       }
    BEQ .notAGraphicsMODEError                          } if (not in a graphics MODE) then
                                                        } branch

.getCommandAddressFromTableAndCallIt = $81b9
    LDX .vduTempStoreDC                                 
    LDA .starCommandAddressTable,X                      }
    STA .vduTempStoreDA                                 }
    LDA .starCommandAddressTable + 1,X                  } get routine's address from
    STA .vduTempStoreDB                                 } the table

    CLC                                                 }
    TYA                                                 }
    ADC .stringInputBufferAddressLow                    }
    TAX                                                 } XY = pointer to (remainder of)
    LDY .stringInputBufferAddressHigh                   } user input string
    BCC +                                               }
    INY                                                 }
+
    JSR .jumpToRoutine                                  call *command routine

    LDX .currentlySelectedROM                           }
    PLA                                                 }
    TAY                                                 } restore registers
    PLA                                                 }
    LDA #0                                              zero indicates the service call has
                                                        been handled.
    RTS                                                 

§2. Jump to routine to implement the specific star command.

.jumpToRoutine = $81da
    JMP (.vduTempStoreDA)                               jump to address in DA/DB to handle
                                                        star command

§3. noSpriteMemoryError.

.noSpriteMemoryError = $81dd
    JSR .generateError                                  does not return
    !byte $80                                           error number
    !text "No sprite memory",0                          error message

§4. notAGraphicsMODEError.

.notAGraphicsMODEError = $81f2
    JSR .generateError                                  does not return
    !byte $81                                           error number
    !text "Not a graphics mode",0                       error message

§5. commandNameTable.

.commandNameTable = $820a
    !text "gxr"      , 0                                enable GXR
    !text "flood"    , 0                                allocate memory for flood fill
    !text "noflood"  , 0                                deallocate memory for flood fill
    !text "nogxr"    , 0                                disable GXR
    !text "sspace"   , 0                                allocate space for sprites

    !text "schoose"  , 0                                requires allocated sprite space
    !text "sdelete"  , 0                                requires allocated sprite space
    !text "sload"    , 0                                requires allocated sprite space
    !text "smerge"   , 0                                requires allocated sprite space
    !text "snew"     , 0                                requires allocated sprite space
    !text "srenumber", 0                                requires allocated sprite space
    !text "ssave"    , 0                                requires allocated sprite space

    !text "sedit"    , 0                                call when in a graphics MODE
    !text "sget"     , 0                                call when in a graphics MODE
    !byte 0                                             terminator

§6. *HELP names.

.graphicsNameTable = $8267
    !text "graphics" , 0                                
.spritesNameTable = $8270
    !text "sprites"  , 0                                

§7. starCommandAddressTable.

.starCommandAddressTable = $8278
    !word .starGXR                                      enable GXR
    !word .starFlood                                    allocate memory for flood fill
    !word .starNoFlood                                  deallocate memory for flood fill
    !word .starNoGXR                                    disable GXR
    !word .starSSpace                                   allocate space for sprites
.endOfCommandsNotRequiringSpriteSpace = $8282
    !word .starSChoose                                  requires allocated sprite space
    !word .starSDelete                                  requires allocated sprite space
    !word .starSLoad                                    requires allocated sprite space
    !word .starSMerge                                   requires allocated sprite space
    !word .starSNew                                     requires allocated sprite space
    !word .starSRenumber                                requires allocated sprite space
    !word .starSSave                                    requires allocated sprite space
.endOfCommandsRequiringSpriteSpace = $8290
    !word .starSEdit                                    call when in a graphics MODE
    !word .starSGet                                     call when in a graphics MODE

§8. Check for a match to a star command or *HELP name.

.checkForCommandMatch = $8294
    LDA (.stringInputBufferAddressLow),Y                get character from user input
    INY                                                 move to next character
    CMP #'.'                                            check for abbreviation
    BEQ .endOfMatch                                     if (ends in dot) then branch

    ORA #$20                                            ensure lower case
    CMP .commandNameTable,X                             check against entry in table
    BNE .endOfMatch                                     if (doesn't match command) then
                                                        branch

    INX                                                 move to next character in table
    LDA .commandNameTable,X                             get next character from table
    BNE .checkForCommandMatch                           if (next character not zero) then
                                                        branch

.endOfMatch = $82a8
    RTS