[A83] Re: BASIC interpreter


[Prev][Next][Index][Thread]

[A83] Re: BASIC interpreter




> Van: Thomas Lutz <tlutz@stevens-tech.edu>
> 
> Is there a way to find out the location of the BASIC interpreter?? (i.e.
> when you run an asm program from within a basic program, can you tell
> where the interpreter is??
> )
> thanks!

I guess you meant to say "where the BASIC interpreter left off". That can
be found at:

[Ti83:]
 Byte 913B Type of running BASIC program
    8 913C Name of currently running BASIC program
 Word 9144 Pointer to start of running BASIC program
 Word 9146 Pointer to currently interpreted byte in running BASIC prog
 Word 9148 Pointer to last byte of data in running BASIC program

[Ti83+:]
Byte  9652                    - Type of running BASIC program
8     9653                    - Name of running BASIC program
Word  965B                    - Pointer to start of running BASIC program
Word  965D                    - Pointer to current position in BASIC prog
Word  965F                    - Pointer to last byte of BASIC program

I've also got the Ti82 adress but these aren't very usefull since the BASIC
interpreter isn't 'running' when you enter an assembly prog on the Ti82.

An example of how to load the pointer from the previous running BASIC
program:

     call   _cpyTo1FPST         ; last FPS entry -> OP1[0,8]
     call   _findProgSym        ; Get program location
     push   de                  ; DE = sizebytes pointer
     inc    de                  ;
     inc    de                  ;
     ld     (pBASIC_start),de   ;
     push   de                  ;
     dec    de                  ;
     dec    de                  ;
     call   _getVarSize         ; DE = sizebytes + 2, HL = intact
     add    hl,de               ;
     ld     (pBASIC_end),hl     ; Store end of BASIC prog
     pop    de                  ; DE = sizebytes pointer
     inc    de                  ;
     inc    de                  ; DE = data pointer
     ld     hl,(OPS)            ; Get operator stack pointer
     ld     bc,6                ; Add 6 to get cursor offset
     add    hl,bc               ;
     call   LD_HL_MHL           ; Get cursor offset
     add    hl,de               ; Add cursor offset to program location
     ld     (pBASIC_cursor),hl  ;
     ret                        ;

An example program (Ti83), it deletes a program, the small starter is
created by Jean Carot (aka Yhean).
Syntax: send(9prgmDELP:(prgmXXX)
There are probably some opts to be done, but most of the code isn't needed
anymore when you port it to Venus.

;=========================================================
; '1'-'9'
;30 e    JR NC,(PC+e)  ;
;31 n n  LD SP,nn      ; AH!!!
;32 n n  LD (nn),A     ;
;33      INC SP        ; AH!
;34      INC (HL)      ;
;35      DEC (HL)      ;
;36 n    LD (HL),n     ;
;37      SCF           ;
;38 e    JR C,(PC+e)   ;
;39      ADD HL,SP     ;
; 'A'-'F'
;41      LD B,C        ;
;42      LD B,D        ;
;43      LD B,E        ;
;44      LD B,H        ;
;45      LD B,L        ;
;46      LD B,(HL)     ;
;=========================================================
_errundefined       =  $467B     ; ERR:UNDEFINED <<
_errargument        =  $4672     ; ERR:ARGUMENT <<
_errsyntax          =  $466C     ; ERR:SYNTAX <<
;=========================================================
_getProgInfo        =  $4426
_chkfindsym         =  $442A
_findsym            =  $442E
_delVar             =  $44AA
_deleteMem          =  $44B2
;=========================================================
OP1                 =  $8039
userMemOffset       =  $8565
CMDShadow           =  $9157
;=========================================================
STRINGOBJ           =  $04
PROGOBJ             =  $05
;=========================================================
#define RelocBuf CMDShadow
;=========================================================
startup:
     .db "CD2644D5C9"       ; call _findprogsym / push de / ret
startupSize = ($ - startup) / 2
     .db "Ô?0000?"          ; End / :0000 / :[asm prog]
;=========================================================
;Together this (= non-safeStartup) translates to:
;------------------------------------------------
;xxxx    xxxx                   ; ..sizebytes.. (should be a
do-nothing-OPcode)
;43      LD    B,E              ; nonsense load
;44      LD    B,H              ; nonsense load
;323634  LD    ($3436),A        ; nonsense, write to ROM...
;34      INC   (HL)             ; nonsense increment
;44      LD    B,H              ; nonsense load
;35      DEC   (HL)             ; nonsense decrement
;43      LD    B,E              ; B = E (also nonsense)
;39      ADD   HL,SP            ; HL = HL + SP [-400,0] (carry is now set)
;=================end of starter==========================
;D43F30  CALL  NC,($303F)       ; do nothing
;3030    JR    NC,($+$30+2)     ; do nothing
;3037    JR    NC,($+$37+2)     ; do nothing
;=========================================================
; HL = points right here
     ld     de,DelStart-$       ;
     add    hl,de               ;
     ld     bc,DelEnd-DelStart  ; <= 128 !!!
     ld     de,RelocBuf         ;
     push   de                  ;
     ldir                       ;
     ret                        ; 'Jump' to CMDShadow
;=========================================================
DelStart:
     ld     bc,$0000            ; Hmm, else BC isn't zero...
     ld     (userMemOffset),bc  ;
     ld     hl,$9327            ;
     ld     de,startupSize      ;
     call   _deleteMem          ; Remove startup

     .ds    startupSize         ; NOPs
;=========================================================
; Now precalc some data
;=========================================================
     ld     hl,($9148)          ; HL = BASIC_End
     ld     de,($9146)          ; DE = BASIC_cursor
     or     a                   ;
     sbc    hl,de               ;
     ex     de,hl               ; DE = bytes till end of BASIC prog
                                ; HL = BASIC_cursor
     
     ld     bc,8+1              ; Maximum 8 bytes in name
sizeLoop:
     ld     h,d                 ;
     ld     l,e                 ;
     dec    bc                  ;
     or     a                   ;
     sbc    hl,bc               ;
     jr     c,sizeLoop          ;

     ; BC = max namestring size
     ld     hl,($9146)          ; Recall BASIC_cursor
     inc    hl                  ;
     ld     a,$3E               ; ':'
     cp     (hl)                ;
     jp     nz,_errsyntax       ;
     inc    hl                  ;
     ld     a,$10               ; '('
     cp     (hl)                ;
     jp     nz,_errsyntax       ;
     inc    hl                  ;
     ld     ($9146),hl          ; Store new BASIC_cursor
     ld     a,$5F               ; 'prgm'
     cp     (hl)                ;
     jp     nz,_errargument     ;
     inc    hl                  ;
     
     ld     ($9146),hl          ; Store new BASIC_cursor
     ld     de,OP1              ;
     ld     a,PROGOBJ           ;
     
nameLoop:
     ld     (de),a              ;
     ld     a,(hl)              ;
     inc    de                  ;
     inc    hl                  ;
     cp     '?'                 ; tEnter
     jr     z,endNameLoop       ;
     cp     $11                 ; ')'
     jr     z,endNameLoop       ;
     djnz   nameLoop            ;
endNameLoop:
     xor    a                   ;
     ld     (de),a              ; Add zero-terminator
     
     push   hl                  ;
     call   _getProgInfo        ;
     ld     (VATpointer),hl     ;
     pop    hl                  ;
     jp     c,_errundefined     ;
     ld     ($9146),hl          ; Store new BASIC_cursor
     ld     hl,(VATpointer)     ;
     jp     _delVar             ;
     
DelEnd:
     .db "ÔHPOLEYÔ"




Follow-Ups: