Return to BASIC

Anything Sinclair Basic related; history, development, tips

Return to BASIC

Postby Forthretro.new.fr on Mon Feb 08, 2010 9:51 pm

Hello friends,

I am sure the answer to be somewhere, but let ask it again :
I have a program I call from the BASIC with the usual RAND USR XXXX

But in the program I will use all the REG and the Stack.
My question is : where is the information for to comeback to the BASIC ?
In the STACK ? In a REG ?
If in the stack I can do, at the start of the program something like
POP DE
LD (save_return),DE
....
Then
LD DE, (save_return)
PUSH DE
C9

But none of the solution seems to work

Merci
User avatar
Forthretro.new.fr
 
Posts: 31
Joined: Thu Nov 19, 2009 9:34 pm

Re: Return to BASIC

Postby sirmorris on Mon Feb 08, 2010 11:01 pm

I seem to remember that BC has something to do with it :)

if the machine code is:
LD BC, returnvalue
RET

LET N = USR(..)

will put the return value in the variable N.

Don't use IX and IY, AF' registers in slow mode - you'll crash the computer. If you do use them in FAST, make sure that IY = $4000 on return.

Charlie
5 x -go-hold rings, 4 x calling birds, 3 x french hens, 2 x turtle doves and 1 x partridge (in a pear tree)
User avatar
sirmorris
 
Posts: 334
Joined: Thu May 08, 2008 4:45 pm
Location: oxon, uk

Re: Return to BASIC

Postby siggi on Mon Feb 08, 2010 11:06 pm

Forthretro.new.fr wrote:Hello friends,

I am sure the answer to be somewhere, but let ask it again :
I have a program I call from the BASIC with the usual RAND USR XXXX

But in the program I will use all the REG and the Stack.

If you run the program in SLOW mode, NEVER touch the IX, IY and AF' registers, because they are used by the display routine and /INT and /NMI. The only exception is, when you want to write your own display driver and you know, what you do ...

My question is : where is the information for to comeback to the BASIC ?
In the STACK ? In a REG ?
If in the stack I can do, at the start of the program something like
POP DE
LD (save_return),DE
....
Then
LD DE, (save_return)
PUSH DE
C9

But none of the solution seems to work

Merci


The solution is

RST 08H
DEFB 0xFF

That calls the Basic error routine with "error" 0, cleans up the stack and jumps back to BASIC.

HTH Siggi
There are 10 types of people in this world: those who understand binary and those who don't.
siggi
 
Posts: 156
Joined: Thu May 08, 2008 8:30 am
Location: Germany

Re: Return to BASIC

Postby Forthretro.new.fr on Tue Feb 09, 2010 1:01 am

Many thanks for the answer. It helped me to understand the RAND USR !

With a debug I noted that the adress of the SP allway was 7FEA at the start.

While the SP was at 7FEA I could come back to the BASIC with C9.

However FORTH change the Stack adress later. It is why the computer crashed with any C9.

The solution was to put 7FEA in a 'return_adress' and for to exit, to use the instruction

ED 7B 'return_adress' ; LD SP, (return_adress) -> LD SP , 7FEA
C9


OK !!!
User avatar
Forthretro.new.fr
 
Posts: 31
Joined: Thu Nov 19, 2009 9:34 pm

Re: Return to BASIC

Postby XavSnap on Fri Apr 09, 2010 4:23 pm

Hi,

There's a call adresse to ignore all asm/basic errors.
How you can use eratics basic codes like:

10 Print USR <your address>,"HELLO BOYS"
20 END

or
10 LET A$=STR$ USR <your address>+"HELLO BOYS"
20 END


a CALL xxxx will come back to the basic PC, but will ignore all the end of the basic line !
The "HELLO BOYS" will be ignored !
end the END wil be execute.
The famous "Call" is used in my "Something to do," codes !
upated!!!

ORG +16514

@DECODE=07BD
@DEST=+16402
@DFILE=+16396
@SEED=+16434
@FAST=2D6
@SLOW=2BF
@CLS=A2A
@KEYLOW=+16421
@KEYHI=+16422
@NXTL= 4029
@KEYB=02BB
@SCROLL=0C0E
@AKEY=+3893

@EXTERR=005B

@RETBAS
JP EXTERR
----------------------------
1 RET *****************
2 LET A$=STR$ USR 16514+"DATAS"
3 PRINT


In this exemple :
A$=A$ (Null string) after the line 2.
(Basic Line breaked after the RAND USR xxxx)

Before the "Call 5B" the next line is the line 2 address.
Datas offset = (NXTL)+4+6+5+5+2
="++++"(x4)+"LET A$=RAND USR"(x6)+"16514xxxxx"(x10)+"+~"(x2)

NextLIne (@NXTL= 4029) after the "Call 5B", is the line 3 address. (Address-3= the last quote)

Note: DEST = A$ Vars memory offset! (data =+3) in cas a string value.
Last edited by XavSnap on Sat Apr 10, 2010 7:47 am, edited 1 time in total.
User avatar
XavSnap
 
Posts: 236
Joined: Sat May 10, 2008 3:23 pm

Re: Return to BASIC

Postby XavSnap on Sat Apr 10, 2010 7:40 am

Hello guys,

I wrote a little exemple:
Xur file :

Code: Select all
    10  REM [HEX:\
2A,29,40,2B,2B,01,00,00,\
3E,0B,2B,03,BE,20,FB,79,\
3D,32,20,40,EB,13,D5,21,\
20,00,0B,ED,42,7D,1F,37,\
01,00,0A,4F,CD,D6,02,CD,\
F5,08,D1,3A,20,40,06,00,\
4F,CD,6B,0B,CD,0E,0C,CD,\
BF,02,C3,5B,00 ]

    20 PRINT USR 16514;"HELLO ..."
    30 PRINT USR 16514;"THIS IS A DEMO"
    40 PRINT USR 16514;"USING AN asm DATA TRANSFERT"
    50 PRINT USR 16514;"AND THE JP 005B FUNCTION"
    60 LET A$=STR$ USR 16514+"-.-"
    70 LET A$=STR$ USR 16514+"-1-"
    80 LET A$=STR$ USR 16514+"-2-"
    90 LET A$=STR$ USR 16514+"-3-"
   100 LET A$=STR$ USR 16514+"-4-"
   110 LET A$=STR$ USR 16514+"-5-"
   120 RUN SIN SIN SIN SIN SIN SIN PI

Xur ASM 2 codes:
Code: Select all
; WELCOME TO MY ARTIC
; ASSEMBLER 2 DEMO.
;------------------------


ORG +16514

;CONSTANTS
@DECODE=07BD
@DEST=+16402
@DFILE=+16396

@FRAMES=+16436
@SEED=+16434

@KEYLOW=+16421
@KEYHI=+16422
@NXTL= 4029
@EXTERR=005B
@TEMP8=4020

; PRINT AT FUNCTION
; SET CURSOR
; BC = X,Y VALUES
@CURSEUR=8F5
@CLEAR=A2A
@KBD=2BB

;PRINT A STRING
; DE= STRING OFFSET
; BC= STRING LEN
@CHAINE=B6B

@DECODE=7BD

;BASIC FUNCTIONS.
@SLOW=2BF
@FAST=2D6
@CLS=A2A
; SCROLL FUNCTION
@SCROLL=C0E

;
@START
; - GET DATAS
LD HL,(NXTL)
DEC HL
DEC HL
LD BC,0

;SEARCH THE FIRST
, -"- CHARACTER
LD A,0B
@RETCNT
DEC HL
INC BC
CP (HL)
JR NZ RETCNT
LD A,C
DEC A
LD (TEMP8),A
; A REGISTER IS STORED
; IN MEMORY
; A= STRING LEN

;SAVE DE (SWAP HL AND DE)
EX DE,HL
INC DE
PUSH DE
; COMPUTE THE Y COORD
; (32-STRING LENGHT)/2
LD HL,+32
DEC BC
SBC HL,BC
LD A,L
RRA ; A REGISTER/2
; RESET CARRY IF NOT
; A PAIR VALUE
SCF
LD BC,0A00
LD C,A 

CALL FAST

CALL CURSEUR
POP DE
LD A,(TEMP8)
LD B,0
LD C,A 
CALL CHAINE
CALL SCROLL
CALL SLOW
; IGNORE THE END OFF
; BASIC LINE
JP EXTERR


Have fun...
Attachments
Demo.p
Display, Datas transfert and bios 5Bh Basic call back.
(1.26 KiB) Downloaded 7 times
User avatar
XavSnap
 
Posts: 236
Joined: Sat May 10, 2008 3:23 pm


Return to Sinclair BASIC

Who is online

Users browsing this forum: No registered users and 0 guests

cron