rem statements

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
the7778
Posts: 14
Joined: Sat Oct 05, 2019 5:14 pm

rem statements

Post by the7778 »

can machine code be stored in rem statements in multiple lines?
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: rem statements

Post by mrtinb »

Yes.

You have to manually keep track of a which address each REM line is.

In your assembly you set the address with the ORG directive.

If you create relocatable code, you don't have to assemble the source each time the REM line location is moved in memory.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: rem statements

Post by XavSnap »

Hi,
True.
There's a ROM jump to get the line offset , but i can't remember this code.
:oops:
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: rem statements

Post by mrtinb »

In this post, you can see in line 20, that the first position of content of the REM in line 10 is calculated.

The last number in the line (here 76) depends on the length of line 10.

So the variable S contains the start address of the contents of the REM. And the REM statement does not have to be the first line of program. However the code has to be relocatable (no CALL or JP og LD with addresses).
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: rem statements

Post by XavSnap »

Code: Select all

LD HL,$000A ; line number=10
PUSH DE
CALL $09D8 ; offset to HL
POP DE
Add six bytes to HL, to retrieve de byte after the "REM" token. [edit] 5 bytes ! not 6.
Last edited by XavSnap on Mon Oct 07, 2019 3:14 am, edited 1 time in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Crayon21
Posts: 346
Joined: Sun Nov 04, 2018 2:33 am

Re: rem statements

Post by Crayon21 »

How do i do this from BASIC. All i have access to is LET and POKE. I know how to use REM, how to i use the LET statement to do this?

been away for an eternity so i'm rusty :lol:
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: rem statements

Post by XavSnap »

Hi,
Ok, a little demo to use a REM server…
Cap0016.jpg
Note:
0 REM is the Jump server how get the #line poked in 16514.
1 REM Display "HELLO"
2 REM Display "WOLD"
3 REM Display "[grey chars]"
SP is the REM line number.
CALL is the line O routine offset.
The POKE SP must be a line between 1 and 255.
Never 0, the server will jump to the line #0... and will loop on itself!

You had to poke the 16515 memory offset to get a higher line number.
POKE 16515,0
IF line>255 THEN POKE 16515, int(line/256)
POKE 16514, (line-(PEEK 16515*256))

ASM part:

Code: Select all

;; 
;; Compile with "tasm -80 -b program.asm program.p" 
;; 
 
#define db .byte ; TASM cross-assembler definitions 
#define dw .word 
#define ds .block 
#define org .org 
#define end .end 
 
   org     $4009 
 
;= System variables ============================================ 
 
   db 0     ;VERSN 
   dw 0     ;E_PPC 
   dw dfile      ;D_FILE 
   dw dfile+1    ;DF_CC 
   dw var   ;VARS 
   dw 0     ;DEST 
   dw var+1      ;E_LINE 
   dw last-1     ;CH_ADD 
   dw 0     ;X_PTR 
   dw last  ;STKBOT 
   dw last  ;STKEND 
   db 0     ;BERG 
   dw membot     ;MEM 
   db 0     ;not used 
   db 2     ;DF_SZ 
   dw 1     ;S_TOP 
   db $FF,$FF,$FF     ;LAST_K 
   db 55    ;MARGIN 
   dw dfile      ;NXTLIN 
   dw 0     ;OLDPPC 
   db 0     ;FLAGX 
   dw 0     ;STRLEN 
   dw $0C8D      ;T_ADDR 
   dw 0     ;SEED 
   dw $FFFF      ;FRAMES 
   db 0,0   ;COORDS 
   db $BC   ;PR_CC 
   db 33,24      ;S_POSN 
   db 01000000B  ;CDFLAG 
prtbuff:
   ds 33    ;Print buffer 
membot: 
   ds 30    ;Calculator´s memory area 
   ds 2     ;not used 
 
;= First BASIC line, asm code ================================== 
 
line0: 
   db 0,0 
   dw line1-$-2 
   db $ea   ; REM 
 
data1: 
   dw $0000 ;Store data line.
	LD HL,(data1)
	CALL $09D8 ; offset to HL
	LD BC,5
	ADD HL,BC
	JP (HL)
 
   db $76   ;N/L 

line1: 
   db 0,1 
   dw line2-$-2 
   db $ea   ; REM 

	ld BC,endtext1-text1 
	ld DE,text1  
	call $b6b
	RET ; ==========================
text1:
db H,E,L,L,O
endtext1:

   db $76   ;N/L 

line2: 
   db 0,2 
   dw line3-$-2 
   db $ea   ; REM 

	ld BC,endtext2-text2 
	ld DE,text2
	call $b6b
	RET ; ==========================
text2:
db _,W,O,R,L,D
endtext2:


   db $76   ;N/L 

line3: 
   db 0,3 
   dw dfile-$-2 
   db $ea   ; REM 
;;
	LD A,$08 
	LD B,$20 
inv1:
	RST 10H ; Display= A reg.
	DJNZ inv1
	LD A,$88 
	LD B,$20 
inv2:
	RST 10H ; Display= A reg.
	DJNZ inv2
	RET ; ==========================

;;
   db $76   ;N/L
 
;- Display file -------------------------------------------- 
 
dfile: 
   db $76 
   db $76,$76,$76,$76,$76,$76,$76,$76 
   db $76,$76,$76,$76,$76,$76,$76,$76 
   db $76,$76,$76,$76,$76,$76,$76,$76 
 
;- BASIC-Variables ---------------------------------------- 
 
var: 
   db $80 
 
;- End of program area ---------------------------- 
 
last: 
 
   end 

A	.equ $26
B	.equ $27
C	.equ $28
D	.equ $29
E	.equ $2A
F	.equ $2B
G	.equ $2C
H	.equ $2D
I	.equ $2E
J	.equ $2F
K	.equ $30
L	.equ $31
M	.equ $32
N	.equ $33
O	.equ $34
P	.equ $35
Q	.equ $36
R	.equ $37
S	.equ $38
T	.equ $39
U	.equ $3A
V	.equ $3B
W	.equ $3C
X	.equ $3D
Y	.equ $3E
Z	.equ $3F
_	.equ $00
_0	.equ $1C
_1	.equ $1D
_2	.equ $1E
_3	.equ $1F
_4	.equ $20
_5	.equ $21
_6	.equ $22
_7	.equ $23
_8	.equ $24
_9	.equ $25
Basic program:

Code: Select all

     0  REM [HEX:\
00,00,2A,82,40,CD,D8,09,\
01,05,00,09,E9 ]

     1  REM [HEX:\
01,05,00,11,9F,40,CD,6B,\
0B,C9,2D,2A,31,31,34 ]

     2  REM [HEX:\
01,06,00,11,B4,40,CD,6B,\
0B,C9,00,3C,34,37,31,29\
 ]

     3  REM [HEX:\
3E,08,06,20,D7,10,FD,3E,\
88,06,20,D7,10,FD,C9 ]

10 LET SP=16514
20 LET CALL=16516
30 POKE SP,1
40 RAND USR CALL
50 POKE SP,2
60 RAND USR CALL
70 POKE SP,3
80 RAND USR CALL
Have fun !
Last edited by XavSnap on Mon Oct 07, 2019 4:17 am, edited 1 time in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: rem statements

Post by XavSnap »

Hi,
Something else in basic…

Code: Select all

...
1000 RAND USR PEEK 16425+PEEK 16426*256+5
1100 REM <your asm code>
2000 RAND USR PEEK 16425+PEEK 16426*256+5
3000 REM <your asm code>
...
PEEK 16425 : Get the NXT_LINE basic variable. (Next basic line offset to read!)
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply