Getting integer into USR routine

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Prime
Posts: 134
Joined: Thu Mar 24, 2011 3:02 am

Getting integer into USR routine

Post by Prime »

Hi,

I want to write a couple usr routine that will take parameters, both 8 bits so that I can write quick implementations of the spectrum basic in and out routines, as this will make testing hardware from basic easier....

something like :

Code: Select all

10 REM Out example
20 RAND USR 16514, 25, 32

30 REM In example
40 LET X=USR 16517, 25
Cherrs.

Phill.
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: Getting integer into USR routine

Post by sirmorris »

Something like this?

Code: Select all

; --¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬--¬
;
; A commandline of the form:
;
; PRINT USR DRIVER,C,P1,P2,P3,P4
;
; is parsed into the command block structure above. 
; where C is a command, either I{nit}, D{ir}, or L{oad}, {S}ave or {X} = debug.
; The PX args are optional according to the command. They need to be valid expressions.
;
Attached. See CardMenu.asm

This was my original mmc driver :) It's written for TASM but you should be able to convert it.
Attachments
testbed.zip
(27.81 KiB) Downloaded 263 times
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: Getting integer into USR routine

Post by Andy Rea »

This old thread may be useful also,

http://forum.tlienhard.com/TS1000/www.t ... 262984.htm

but for simple stuff requiring only 1 or 2 numeric vars i usually just poke the data into the code before calling it.

Regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Getting integer into USR routine

Post by XavSnap »

Hi,

Code: Select all

DEST		.equ $4012
STKEND		.equ $401C
FIND_INT	.equ $0EA7
EXTERR		.equ $005B 

.org 16514
	LD HL,(DEST)	;GET VARs Value.
	LD DE,(STKEND)	;Point to the stack
	LD BC,5		;COPY THE VALUE...
	AND A		;Clean carry.
	SBC HL,BC	;
	LDIR		;COPY THE VALUE 5 bytes...
	CALL FIND_INT	; CALL ROM BIOS

	LD D,B
	CALL DISPLAY_HEX
	LD D,C
	CALL DISPLAY_HEX
	;RETURN THE VARS VALUE in BC.
	JP EXTERR ; Basic Break fuction! Ignore line instructions.


DISPLAY_HEX:
	LD A,D
	SRL A
	SRL A
	SRL A
	SRL A
	AND $0F
	ADD A,$9C
	RST 10H
	LD A,D
	AND $0F
	ADD A,$9C
	RST 10H
	RET
.end

Code: Select all

# to get a floating point value in ASM!.
# SET Basic variable.

 ; 0 REM:    50 Bytes@4082-40B3
16514:42,18,64,237,91,28,64,1,5
16523:0,167,237,66,237,176,205
16530:167,14,80,205,159,64,81
16537:205,159,64,195,91,0,122
16544:203,63,203,63,203,63,203
16551:63,230,15,198,156,215,122
16558:230,15,198,156,215,201
--------------------------------
     
     0  REM [HEX:\
2A,12,40,ED,5B,1C,40,01,\
05,00,A7,ED,42,ED,B0,CD,\
A7,0E,50,CD,9F,40,51,CD,\
9F,40,C3,5B,00,7A,CB,3F,\
CB,3F,CB,3F,CB,3F,E6,0F,\
C6,9C,D7,7A,E6,0F,C6,9C,\
D7,C9 ]

     5 CLS 
    10 LET X=1234
    20 PRINT X+USR 16514
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Getting integer into USR routine

Post by XavSnap »

Hi,

Have a look to this part of codes.
I use it in the "Star Trek,Last battle" game.

Code: Select all

;------- TASM ASM mnemonics. -------
; Compile this file using:
; Set TASMOPTS = -b
; tasm -80 ThisCode.tas MyBinary.BIN
;-----------------------------------
; Zx81 Program name: VB81 XuR [MAGECO_disassembler_rom.P] : Empty Basic Segment.
; REM   line   name: D=16004/16600 : H=3E84/40D8

#define ORG  .org       ; TASM cross-assembler definitions
#define equ  .equ

;------- Rom and Ram Symbols -------
RAM_VARS equ $4010
RAM_S_POSN equ $4039
LOC_ADDR equ $0918
STACK_BC equ $1520
PRINT_FP equ $15DB
REPORT_D equ $03A6
CLS equ $0A2A
RAM_LAST_K equ $4025
DEBOUNCE equ $0F4B
DECODE equ $07BD
RAM_PRBUFF02 equ $403E
RAM_D_FILE equ $400C
RAM_SPARE2 equ $407B
RAM_FRAMES equ $4034
RAM_SPARE1 equ $4021
RAM_DBOUNCE equ $4027

ORG 16514

; 1= Numeric (A)
; 2= Chars  (A$)
; 3= Numeric FOR...NEXT (A)
; 4= Numeric (AA)
; 5= Chars ARRAY (A$(x) or A$(x,x))
; 6= Numeric ARRAY (A(x) or A(x,x))
VAR_TYPEDATA:
db $00

Scan_VAR:
	LD HL,(RAM_VARS) ; GET VARS

Scan_VAR_type:
	LD A,(HL) 
	BIT 7,A 
	JR NZ, Lb3EB2
	RES 6,A 
	BIT 5,A 
	JR Z, Lb3E9E

; Numeric (A) : Single lettre numeric variable.
	RST 10H ; Display= A reg.

Lb3E93:
	CALL Lb3F47
Lb3E99:
	JR Scan_VAR_type

Lb3E9E:
	SET 5,A

; Chars (A$) : Single lettre variable.
	RST 10H ; Display= A reg.

	CALL Lb3F20 
	XOR A ; Reset A register A=0 Ci=0
	INC HL 
Lb3EAF:
	ADD HL,BC 
	JR Lb3E99
Lb3EB2:
	CP $80
; EXIT SCAN !
	RET Z 
	RES 7,A 
	CP $60 
	JR C, Lb3EDD 

	RES 6,A

; FOR - NEXT var (ONE CHAR).
	RST 10H ; Display= A reg.


	CALL Lb3F47 
	CALL Lb3F48 
	CALL Lb3F48 

	CALL Lb3F21
	DEC BC 
	INC HL 

	JR Lb3E99
Lb3EDD:


	BIT 5,A 
	JR Z, Lb3EED

; Numeric (AA) : multi-lettres numeric variable.
Lb3EE1:
	RST 10H ; Display= A reg.

	INC HL 
	LD A,(HL) 
	BIT 7,A 
	JR Z, Lb3EE1
	RES 7,A
	; Numeric (AA) : Last char.
	RST 10H ; Display= A reg.
	JR Lb3E93 
Lb3EED:
	SET 5,A 
	BIT 6,A 
	JR Z, Lb3F1D
	RES 6,A

; Chars ARRAY (A$(x) or A$(x,x)) : Char. Array variable.
	RST 10H ; Display= A reg.

Lb3EF9:
	CALL Lb3F20
	INC HL
	JR Lb3EAF

Lb3F1D:
; Numeric ARRAY (A(x) or A(x,x)) : Num. Array variable.
	RST 10H ; Display= A reg.

	JR Lb3EF9
Lb3F20:
	INC HL 
Lb3F21:
	LD C,(HL) 
	INC HL 
	LD B,(HL) 
	RET ; ==========================

Lb3F47:
	INC HL 
Lb3F48:

	LD BC,$0005 
	ADD HL,BC
	RET ; ==========================

.end
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply