How to create a new line in a Basic program...

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

How to create a new line in a Basic program...

Post by XavSnap »

There'is two way to type 3 lines in Basic…

Code: Select all

100 PRINT "HELLO"
110 PRINT "WORLD"
200 STOP
And, this way…

Image

Code: Select all

     0  REM [HEX:\
21,7D,40,56,23,5E,E5,2A,\
42,40,AF,ED,52,28,0B,38,\
3A,E1,23,5E,23,56,19,23,\
18,E9,E1,E5,E5,23,4E,23,\
46,09,03,03,03,03,23,E5,\
78,2F,47,79,2F,4F,03,2A,\
29,40,09,22,29,40,E1,E5,\
CD,AD,09,E1,D1,1B,E5,2A,\
1C,40,AF,ED,52,23,E5,C1,\
E1,ED,B0,ED,4B,40,40,2A,\
29,40,09,22,29,40,E1,2B,\
E5,CD,9E,09,E1,ED,4B,42,\
40,70,23,71,ED,4B,40,40,\
0B,0B,0B,0B,23,71,23,70,\
23,22,44,40,09,2B,36,76,\
ED,4B,44,40,C9 ]
   200 STOP
   300 LET A$="HELLO"
   310 LET NL=100
   320 GOSUB 2190
   330 LET A$="WORLD"
   340 LET NL=110
   350 GOSUB 2190
   400 LIST 100
   600 STOP 
  2190 LET AL=LEN A$+8
  2195 POKE 16449,INT (AL/256)
  2200 POKE 16448,AL-256*INT (AL/256)
  2210 POKE 16451,INT (NL/256)
  2220 POKE 16450,NL-256*INT (NL/256)
  2240 LET A=USR 16514
  2250 POKE A,245
  2260 POKE A+1,11
  2280 FOR I=1 TO LEN A$
  2290 POKE A+1+I,CODE A$(I)
  2300 NEXT I
  2305 POKE A+1+I,11
  2310 RETURN 
  9990 SAVE  "MAKELINEs"
  9999 LIST 100

Code: Select all

;------- TASM ASM mnemonics. -------
; Compile this file using:
; Set TASMOPTS = -b
; tasm -80 ThisCode.tas MyBinary.BIN
;-----------------------------------
; Zx81 Program name: VB81 XuR [MS33_COURBES_HR.P] : SAVE"COURBES" Line 9990
; REM   line   name: 7 REM:   121 Bytes@421C-4294

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

;------------------------------------
;-Basic sub-routine entry.          -
;+----------------------------------+
;+----------------------------------+

;------- Rom and Ram Symbols -------
RAM_NXTLIN equ $4029
POINTERS equ $09AD
RAM_STKEND equ $401C
MAKE_ROOM equ $099E
PRT_Buffer1 equ $4040 ;Line LENGHT (16448)
PRT_Buffer2 equ $4042 ;Line NUMBER (16450)
PRT_Buffer3 equ $4044 ;Start line (command offset)

ORG $4082 ; 16514
Lb421C:
	LD HL,$407D 
Lb421F:
	LD D,(HL) 
	INC HL 
	LD E,(HL) 
	PUSH HL 
	LD HL,(PRT_Buffer2) 
	XOR A 
	SBC HL,DE 
	JR Z, Lb4236 ; [$4236:16950]
	JR C, Lb4267 ; [$4267:16999]
	POP HL 
	INC HL 
	LD E,(HL) 
	INC HL 
	LD D,(HL) 
	ADD HL,DE 
	INC HL 
	JR Lb421F ; [$421F:16927]
Lb4236:
	POP HL 
	PUSH HL 
	PUSH HL 
	INC HL 
	LD C,(HL) 
	INC HL 
	LD B,(HL) 
	ADD HL,BC 
	INC BC 
	INC BC 
	INC BC 
	INC BC 
	INC HL 
	PUSH HL 
	LD A,B 
	CPL 
	LD B,A 
	LD A,C 
	CPL 
	LD C,A 
	INC BC 
	LD HL,(RAM_NXTLIN) ; GET NXT-LINE
	ADD HL,BC 
	LD (RAM_NXTLIN),HL ; SET NXT-LINE
	POP HL 
	PUSH HL 
	CALL POINTERS ; [POINTERS]
	POP HL 
	POP DE 
	DEC DE 
	PUSH HL 
	LD HL,(RAM_STKEND) ; GET STKEND
	XOR A 
	SBC HL,DE 
	INC HL 
	PUSH HL 
	POP BC 
	POP HL 
	LDIR 
Lb4267:
	LD BC,(PRT_Buffer1) 
	LD HL,(RAM_NXTLIN) ; GET NXT-LINE
	ADD HL,BC 
	LD (RAM_NXTLIN),HL ; SET NXT-LINE
	POP HL 
	DEC HL 
	PUSH HL 
	CALL MAKE_ROOM ; [MAKE-ROOM]
	POP HL 
	LD BC,(PRT_Buffer2) 
	LD (HL),B 
	INC HL 
	LD (HL),C 
	LD BC,(PRT_Buffer1) 
	DEC BC 
	DEC BC 
	DEC BC 
	DEC BC 
	INC HL 
	LD (HL),C 
	INC HL 
	LD (HL),B 
	INC HL 
	LD (PRT_Buffer3),HL 
	ADD HL,BC 
	DEC HL 
	LD (HL),$76 
	LD BC,(PRT_Buffer3)
	RET ; ==========================
.end
MAKELINES.P
(1.49 KiB) Downloaded 141 times
Have Fun…
Can be used to create a REM tooo...
Last edited by XavSnap on Thu Oct 29, 2020 5:23 pm, edited 2 times in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
mrtinb
Posts: 1911
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: How to create a new line in a Basic program...

Post by mrtinb »

Thank you for a working example. I've tried to do this previously and gave up.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: How to create a new line in a Basic program...

Post by XavSnap »

Hi Martin,

This code is a part of "Courbes HR" from the Micro-Systèmes #33.
Used to add a LET line (LET X="myvalues") in a Basic loop.

"Traceur de courbes haute résolution."
http://abandonlistings.free.fr/microsystemes/index.htm

http://abandonlistings.free.fr/microsys ... HR_n33.zip

I had to move and change the temp buffer to pass values to ASM codes.

Other link : AutoRem from Dessony: viewtopic.php?f=11&t=3849
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply