| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| vc-3_system_interrupt_table [2026/01/21 01:49] – appledog | vc-3_system_interrupt_table [2026/01/22 22:19] (current) – appledog |
|---|
| |
| == INT 05h - Pao Alto Tiny Basic | == INT 05h - Pao Alto Tiny Basic |
| First let's discuss the memory map used by our implementation of Pao Alto Tiny Basic. | === Memory Map |
| | ; PATB System Memory ($01ED00-$01EDFF, 256 bytes available) |
| ==== PATB System Memory | .equ PATB_VARIABLES $01ED00 ; 26 vars × 2 bytes = 52 bytes ($01ED00-$01ED33) |
| Found at $01ED00-$01EDFF, 256 bytes available. | .equ PATB_EXPR_STACK $01ED40 ; Expression stack, 64 bytes ($01ED40-$01ED7F) |
| | .equ PATB_EXPR_SP $01ED80 ; Expression stack pointer (2 bytes) |
| * .equ PATB_VARIABLES $01ED00 ; 26 vars × 2 bytes = 52 bytes ($01ED00-$01ED33) | .equ PATB_GOSUB_STACK $01ED82 ; GOSUB stack, 32 bytes (16 levels × 2 bytes) |
| * .equ PATB_EXPR_STACK $01ED40 ; Expression stack, 64 bytes ($01ED40-$01ED7F) | .equ PATB_GOSUB_SP $01EDA2 ; GOSUB stack pointer (2 bytes) |
| * .equ PATB_EXPR_SP $01ED80 ; Expression stack pointer (2 bytes) | .equ PATB_FOR_STACK $01EDA4 ; FOR stack, 40 bytes (8 levels × 5 bytes) |
| * .equ PATB_GOSUB_STACK $01ED82 ; GOSUB stack, 32 bytes (16 levels × 2 bytes) | .equ PATB_FOR_SP $01EDCC ; FOR stack pointer (2 bytes) |
| * .equ PATB_GOSUB_SP $01EDA2 ; GOSUB stack pointer (2 bytes) | .equ PATB_PROGRAM_PTR $01EDCE ; Current program line pointer (3 bytes) |
| * .equ PATB_FOR_STACK $01EDA4 ; FOR stack, 40 bytes (8 levels × 5 bytes) | .equ PATB_IL_PTR $01EDD1 ; Current IL instruction pointer (3 bytes) |
| * .equ PATB_FOR_SP $01EDCC ; FOR stack pointer (2 bytes) | .equ PATB_INPUT_PTR $01EDD4 ; Current input pointer (3 bytes) |
| * .equ PATB_PROGRAM_PTR $01EDCE ; Current program line pointer (3 bytes) | .equ PATB_RANDSEED $01EDD7 ; Random seed (2 bytes) |
| * .equ PATB_IL_PTR $01EDD1 ; Current IL instruction pointer (3 bytes) | .equ PATB_STATUS $01EDD9 ; Status flags (1 byte) |
| * .equ PATB_INPUT_PTR $01EDD4 ; Current input pointer (3 bytes) | ; Bit 0: Running (1) / Stopped (0) |
| * .equ PATB_RANDSEED $01EDD7 ; Random seed (2 bytes) | ; Bit 1: Error flag |
| * .equ PATB_STATUS $01EDD9 ; Status flags (1 byte) | ; Bit 2: Break flag |
| * ; Bit 0: Running (1) / Stopped (0) | .equ PATB_PROGRAM_BASE $030100 ; Start of program storage (Bank 3, offset $100) |
| * ; Bit 1: Error flag | .equ PATB_PROGRAM_END $03FFFF ; End (almost 64KB for programs) |
| * ; Bit 2: Break flag | |
| |
| === Function Dispatch | === Function Dispatch |
| INT 05h - PALO ALTO TINY BASIC SYSTEM | ; === EXECUTION CONTROL (AH=$00-$0F) === |
| Complete implementation for PATB IL interpreter | ; AH=$00: RUN_PROGRAM - Start execution from line number or beginning |
| | ; AH=$01: STOP_PROGRAM - Stop execution |
| | ; AH=$02: CONTINUE - Continue from current position |
| | ; AH=$03: EXEC_IL_STEP - Execute one IL instruction |
| | ; AH=$04: EXEC_IL_CONT - Execute IL until completion |
| | ; AH=$05: GET_STATUS - Get interpreter status |
| | ; AH=$06: SET_STATUS - Set interpreter status flags |
| | ; AH=$07: RESET_INTERP - Reset interpreter state |
| | ; |
| | ; === VARIABLE MANAGEMENT (AH=$10-$1F) === |
| | ; AH=$10: VAR_GET - Get variable value by letter |
| | ; AH=$11: VAR_SET - Set variable value by letter |
| | ; AH=$12: VAR_CLEAR_ALL - Clear all variables to 0 |
| | ; AH=$13: VAR_GET_ADDR - Get address of variable storage |
| | ; |
| | ; === EXPRESSION STACK (AH=$20-$2F) === |
| | ; AH=$20: EXPR_PUSH - Push value to expression stack |
| | ; AH=$21: EXPR_POP - Pop value from expression stack |
| | ; AH=$22: EXPR_PEEK - Peek at top of stack |
| | ; AH=$23: EXPR_CLEAR - Clear expression stack |
| | ; AH=$24: EXPR_DEPTH - Get current stack depth |
| | ; |
| | ; === PROGRAM LINE MANAGEMENT (AH=$30-$3F) === |
| | ; $30-$37: Search/Navigate |
| | ; $30: LINE_FIND - Find line by number (forward) |
| | ; $31: LINE_NEXT - Get next line |
| | ; $32: LINE_FIND_REVERSE - Find line by number (backward) |
| | ; $33: LINE_PREV - Get previous line |
| | ; $36-$39: Modify |
| | ; $36: LINE_INSERT - Insert or replace line |
| | ; $37: LINE_DELETE - Delete line by number |
| | ; $38: LINE_REMOVE_SPACE - Add space for new program line |
| | ; $39: LINE_MAKE_SPACE - remove unused line space |
| | ; $3A-$3F: Utility |
| | ; $3A: LINE_FIRST - Get first line |
| | ; $3B: LINE_CLEAR_ALL - Clear entire program (NEW) |
| | ; $3C: LINE_COUNT - Count total lines |
| | ; $3F: PROGRAM_END - ELM points to end of program |
| | ; |
| | ; === GOSUB/RETURN STACK (AH=$40-$4F) === |
| | ; AH=$40: GOSUB_PUSH - Push return address for GOSUB |
| | ; AH=$41: GOSUB_POP - Pop return address for RETURN |
| | ; AH=$42: GOSUB_CLEAR - Clear GOSUB stack |
| | ; |
| | ; === FOR/NEXT STACK (AH=$50-$5F) === |
| | ; AH=$50: FOR_PUSH - Push FOR loop context |
| | ; AH=$51: FOR_POP - Pop FOR loop context |
| | ; AH=$52: FOR_PEEK - Peek at current FOR loop |
| | ; AH=$53: FOR_CLEAR - Clear FOR stack |
| | ; AH=$54: FOR_FIND_VAR - Find FOR loop by variable letter |
| | ; |
| | ; === INPUT/OUTPUT HELPERS (AH=$60-$6F) === |
| | ; AH=$60: IO_GETCHAR - Get next character from input buffer |
| | ; AH=$61: IO_PUTCHAR - Output character to screen |
| | ; AH=$62: IO_GETNUM - Parse number from input |
| | ; AH=$63: IO_PUTNUM - Output number to screen |
| | ; AH=$64: IO_NEWLINE - Output CR/LF |
| | ; AH=$65: IO_GETLINE - Get line of input from user |
| | ; AH=$66: IO_PRINT_STR - Print string at pointer |
| | ; |
| | ; === STRING/TOKEN HELPERS (AH=$70-$8F) === |
| | ; AH=$70: STR_COMPARE - Compare strings for keyword matching |
| | ; AH=$71: STR_TO_UPPER - Convert string to uppercase |
| | ; AH=$72: STR_SKIP_SPACE - Skip whitespace in ELM string |
| | ; AH=$73: STR_IS_DIGIT - Check if character is digit |
| | ; AH=$74: STR_IS_ALPHA - Check if character is letter |
| | ; AH=$75: STR_LENGTH - Get string length |
| | ; AH=$76: STR_COPY - Copy string from src to dst |
| | ; AH=$77: STR_CONCAT - Concatenate two strings |
| | ; AH=$78: STR_LEFT - Extract left N characters (LEFT$) |
| | ; AH=$79: STR_RIGHT - Extract right N characters (RIGHT$) |
| | ; AH=$7A: STR_MID - Extract middle substring (MID$) |
| | ; AH=$7B: STR_CHR - Convert byte to character (CHR$) |
| | ; AH=$7C: STR_ASC - Convert character to byte (ASC) |
| | ; AH=$7D: STR_VAL - Convert string to number (VAL) |
| | ; AH=$7E: STR_STR - Convert number to string (STR$) |
| | ; AH=$7F: STR_FIND - Find substring within string (INSTR) |
| | ; AH=$80: STR_LTRIM - Trim leading whitespace |
| | ; AH=$81: STR_RTRIM - Trim trailing whitespace |
| | ; AH=$82: STR_TRIM - Trim both leading and trailing whitespace |
| | ; AH=$83: STR_REVERSE - Reverse a string |
| | ; AH=$84: STR_REPEAT - Repeat character N times (STRING$) |
| | ; AH=$85: STR_SPLIT - Split string at delimiter |
| | ; AH=$86: STR_REPLACE - Replace substring with another |
| | ; AH=$87-$8F: (Reserved for future string operations) |
| | ; |
| | ; === ARITHMETIC/LOGIC HELPERS (AH=$90-$9F) === |
| | ; AH=$90: MATH_ADD - Pop two values, push sum |
| | ; AH=$91: MATH_SUB - Pop two values, push difference |
| | ; AH=$92: MATH_MUL - Pop two values, push product |
| | ; AH=$93: MATH_DIV - Pop two values, push quotient |
| | ; AH=$94: MATH_NEG - Negate top of stack |
| | ; AH=$95: MATH_RND - Generate random number |
| | ; AH=$96-$9F: (Reserved) |
| | ; |
| | ; === COMPARISON HELPERS (AH=$A0-$AF) === |
| | ; AH=$A0: CMP_EQ - Compare equal |
| | ; AH=$A1: CMP_NE - Compare not equal |
| | ; AH=$A2: CMP_LT - Compare less than |
| | ; AH=$A3: CMP_GT - Compare greater than |
| | ; AH=$A4: CMP_LE - Compare less than or equal |
| | ; AH=$A5: CMP_GE - Compare greater than or equal |
| | ; AH=$A6-$AF: (Reserved) |
| | ; |
| | ; === ERROR HANDLING (AH=$B0-$BF) === |
| | ; AH=$B0: ERROR_SET - Set error flag and message |
| | ; AH=$B1: ERROR_GET - Get current error code |
| | ; AH=$B2: ERROR_CLEAR - Clear error flag |
| | ; AH=$B3: ERROR_PRINT - Print error message |
| | ; AH=$B4-$BF: (Reserved) |
| | ; |
| | ; === IL INTERPRETER CORE (AH=$F0-$FF) === |
| | ; AH=$F0: IL_INIT - Initialize IL interpreter |
| | ; AH=$F1: IL_LOAD - Load IL code into memory |
| | ; AH=$F2: IL_FETCH - Fetch next IL instruction |
| | ; AH=$F3: IL_DISPATCH - Dispatch IL instruction |
| | ; ============================================================================ |
| |
| ==== EXECUTION CONTROL (AH=$00-$0F) | |
| ; AH=$00: RUN_PROGRAM - Start execution from line number or beginning | |
| ; AH=$01: STOP_PROGRAM - Stop execution | |
| ; AH=$02: CONTINUE - Continue from current position | |
| ; AH=$03: EXEC_IL_STEP - Execute one IL instruction | |
| ; AH=$04: EXEC_IL_CONT - Execute IL until completion | |
| ; AH=$05: GET_STATUS - Get interpreter status | |
| ; AH=$06: SET_STATUS - Set interpreter status flags | |
| ; AH=$07: RESET_INTERP - Reset interpreter state | |
| ; | |
| ; === VARIABLE MANAGEMENT (AH=$10-$1F) === | |
| ; AH=$10: VAR_GET - Get variable value by letter | |
| ; AH=$11: VAR_SET - Set variable value by letter | |
| ; AH=$12: VAR_CLEAR_ALL - Clear all variables to 0 | |
| ; AH=$13: VAR_GET_ADDR - Get address of variable storage | |
| ; | |
| ; === EXPRESSION STACK (AH=$20-$2F) === | |
| ; AH=$20: EXPR_PUSH - Push value to expression stack | |
| ; AH=$21: EXPR_POP - Pop value from expression stack | |
| ; AH=$22: EXPR_PEEK - Peek at top of stack | |
| ; AH=$23: EXPR_CLEAR - Clear expression stack | |
| ; AH=$24: EXPR_DEPTH - Get current stack depth | |
| ; | |
| ; === PROGRAM LINE MANAGEMENT (AH=$30-$3F) === | |
| ; AH=$30: LINE_FIND - Find line by number | |
| ; AH=$31: LINE_NEXT - Get next line | |
| ; AH=$32: LINE_INSERT - Insert or replace line | |
| ; AH=$33: LINE_DELETE - Delete line by number | |
| ; AH=$34: LINE_FIRST - Get first line in program | |
| ; AH=$35: LINE_CLEAR_ALL - Clear entire program (NEW) | |
| ; AH=$36: LINE_COUNT - Count total lines | |
| ; | |
| ; === GOSUB/RETURN STACK (AH=$40-$4F) === | |
| ; AH=$40: GOSUB_PUSH - Push return address for GOSUB | |
| ; AH=$41: GOSUB_POP - Pop return address for RETURN | |
| ; AH=$42: GOSUB_CLEAR - Clear GOSUB stack | |
| ; | |
| ; === FOR/NEXT STACK (AH=$50-$5F) === | |
| ; AH=$50: FOR_PUSH - Push FOR loop context | |
| ; AH=$51: FOR_POP - Pop FOR loop context | |
| ; AH=$52: FOR_PEEK - Peek at current FOR loop | |
| ; AH=$53: FOR_CLEAR - Clear FOR stack | |
| ; AH=$54: FOR_FIND_VAR - Find FOR loop by variable letter | |
| ; | |
| ; === INPUT/OUTPUT HELPERS (AH=$60-$6F) === | |
| ; AH=$60: IO_GETCHAR - Get next character from input buffer | |
| ; AH=$61: IO_PUTCHAR - Output character to screen | |
| ; AH=$62: IO_GETNUM - Parse number from input | |
| ; AH=$63: IO_PUTNUM - Output number to screen | |
| ; AH=$64: IO_NEWLINE - Output CR/LF | |
| ; AH=$65: IO_GETLINE - Get line of input from user | |
| ; AH=$66: IO_PRINT_STR - Print string at pointer | |
| ; | |
| ; === STRING/TOKEN HELPERS (AH=$70-$7F) === | |
| ; AH=$70: STR_COMPARE - Compare strings for keyword matching | |
| ; AH=$71: STR_TO_UPPER - Convert string to uppercase | |
| ; AH=$72: STR_SKIP_SPACE - Skip whitespace in string | |
| ; AH=$73: STR_IS_DIGIT - Check if character is digit | |
| ; AH=$74: STR_IS_ALPHA - Check if character is letter | |
| ; | |
| ; === ARITHMETIC/LOGIC HELPERS (AH=$80-$8F) === | |
| ; AH=$80: MATH_ADD - Pop two values, push sum | |
| ; AH=$81: MATH_SUB - Pop two values, push difference | |
| ; AH=$82: MATH_MUL - Pop two values, push product | |
| ; AH=$83: MATH_DIV - Pop two values, push quotient | |
| ; AH=$84: MATH_NEG - Negate top of stack | |
| ; AH=$85: MATH_RND - Generate random number | |
| ; | |
| ; === COMPARISON HELPERS (AH=$90-$9F) === | |
| ; AH=$90: CMP_EQ - Compare equal (pop 2, push 1 if true, 0 if false) | |
| ; AH=$91: CMP_NE - Compare not equal | |
| ; AH=$92: CMP_LT - Compare less than | |
| ; AH=$93: CMP_GT - Compare greater than | |
| ; AH=$94: CMP_LE - Compare less than or equal | |
| ; AH=$95: CMP_GE - Compare greater than or equal | |
| ; | |
| ; === ERROR HANDLING (AH=$A0-$AF) === | |
| ; AH=$A0: ERROR_SET - Set error flag and message | |
| ; AH=$A1: ERROR_GET - Get current error code | |
| ; AH=$A2: ERROR_CLEAR - Clear error flag | |
| ; AH=$A3: ERROR_PRINT - Print error message | |
| ; | |
| ; === IL INTERPRETER CORE (AH=$F0-$FF) === | |
| ; AH=$F0: IL_INIT - Initialize IL interpreter | |
| ; AH=$F1: IL_LOAD - Load IL code into memory | |
| ; AH=$F2: IL_FETCH - Fetch next IL instruction | |
| ; AH=$F3: IL_DISPATCH - Dispatch IL instruction | |
| ; ============================================================================ | |
| |
| |