[A83] Re: BASIC interpreter


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

[A83] Re: BASIC interpreter




Thanks a lot!!!

Thomas Lutz
Stevens Institute of Technology

-----Original Message-----
From: assembly-83-bounce@lists.ticalc.org
[mailto:assembly-83-bounce@lists.ticalc.org] On Behalf Of Henk Poley
Sent: Monday, December 17, 2001 2:09 PM
To: assembly-83@lists.ticalc.org
Subject: [A83] Re: BASIC interpreter


> Van: Thomas Lutz <tlutz@stevens-tech.edu>
>=20
> 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 =3D sizebytes pointer
     inc    de                  ;
     inc    de                  ;
     ld     (pBASIC_start),de   ;
     push   de                  ;
     dec    de                  ;
     dec    de                  ;
     call   _getVarSize         ; DE =3D sizebytes + 2, HL =3D intact
     add    hl,de               ;
     ld     (pBASIC_end),hl     ; Store end of BASIC prog
     pop    de                  ; DE =3D sizebytes pointer
     inc    de                  ;
     inc    de                  ; DE =3D 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.

;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
; '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)     ;
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
_errundefined       =3D  $467B     ; ERR:UNDEFINED <<
_errargument        =3D  $4672     ; ERR:ARGUMENT <<
_errsyntax          =3D  $466C     ; ERR:SYNTAX <<
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
_getProgInfo        =3D  $4426
_chkfindsym         =3D  $442A
_findsym            =3D  $442E
_delVar             =3D  $44AA
_deleteMem          =3D  $44B2
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
OP1                 =3D  $8039
userMemOffset       =3D  $8565
CMDShadow           =3D  $9157
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
STRINGOBJ           =3D  $04
PROGOBJ             =3D  $05
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
#define RelocBuf CMDShadow
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
startup:
     .db "CD2644D5C9"       ; call _findprogsym / push de / ret
startupSize =3D ($ - startup) / 2
     .db "=D4?0000?"          ; End / :0000 / :[asm prog]
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
;Together this (=3D 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 =3D E (also nonsense)
;39      ADD   HL,SP            ; HL =3D HL + SP [-400,0] (carry is now
set)
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3Dend of =
starter=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
;D43F30  CALL  NC,($303F)       ; do nothing
;3030    JR    NC,($+$30+2)     ; do nothing
;3037    JR    NC,($+$37+2)     ; do nothing
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
; HL =3D points right here
     ld     de,DelStart-$       ;
     add    hl,de               ;
     ld     bc,DelEnd-DelStart  ; <=3D 128 !!!
     ld     de,RelocBuf         ;
     push   de                  ;
     ldir                       ;
     ret                        ; 'Jump' to CMDShadow
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
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
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
; Now precalc some data
;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
     ld     hl,($9148)          ; HL =3D BASIC_End
     ld     de,($9146)          ; DE =3D BASIC_cursor
     or     a                   ;
     sbc    hl,de               ;
     ex     de,hl               ; DE =3D bytes till end of BASIC prog
                                ; HL =3D BASIC_cursor
    =20
     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 =3D 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                  ;
    =20
     ld     ($9146),hl          ; Store new BASIC_cursor
     ld     de,OP1              ;
     ld     a,PROGOBJ           ;
    =20
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
    =20
     push   hl                  ;
     call   _getProgInfo        ;
     ld     (VATpointer),hl     ;
     pop    hl                  ;
     jp     c,_errundefined     ;
     ld     ($9146),hl          ; Store new BASIC_cursor
     ld     hl,(VATpointer)     ;
     jp     _delVar             ;
    =20
DelEnd:
     .db "=D4HPOLEY=D4"







References: