Page 1 of 1

Machine Language help

Posted: Thu Oct 31, 2019 2:08 am
by blittled
I'm writing a program and the first step is determining where REMS are in the program so for the first step I wrote
READPRG:
LD HL, STARTPROG
REMLOOP:
INC HL // Bypass line number
INC HL
LD A,(HL) // Get length of line
LD C,A
INC HL
LD A,(HL)
LD B, A
DEC BC // Adjust for HL to read first token
INC HL
LD A,(HL)
CP $EA // check for REM
JR NZ,NOREM
LD DE,(rems) // Increment number of rems found
INC DE
LD (rems),DE
NOREM:
ADC HL,BC // Point to next line
PUSH HL
LD DE,(D_FILE)
SBC HL,DE
JR C,EXIT
POP HL
JP REMLOOP
EXIT:
POP HL
LD BC,(rems) // Return with number of rems
RET
In the NOREM section I add the line length (BC) to the Pointer (HL) I then check to see if the Pointer is equal to or passes the D_FILE address with SBC HL,DE but It is incorrect since it only looks at the first line in the program. What is the best way to check to see if HL is equal to or greater than the D_FILE address?

Re: Machine Language help

Posted: Thu Oct 31, 2019 2:41 am
by XavSnap
Hi,
PUSH HL
LD DE,(D_FILE)
SBC HL,DE
JR C,EXIT
POP HL
Tyr a 'JP n,EXIT' .
n=true if the result is a negative value

Re: Machine Language help

Posted: Thu Oct 31, 2019 9:19 pm
by GCHarder
Using the ROMs find line address routine at 09D8 LINE-ADDR. may work better. or not, for your REM loop.

For a given BASIC line number this subroutine will return the starting address of the actual line or the starting address of the following line if it does not exist (C reset).

09D8 LINE-ADDR PUSH HL
LD HL,+PROGRAM
LD D,H
LD E,L
09DE NEXT-TEST POP BC
CALL 09EA,CP-LINES
RET NC
PUSH BC
CALL 09F2,NEXT-ONE
EX DE,HL
JR 09DE,NEXT-TEST

Re: Machine Language help

Posted: Fri Nov 01, 2019 1:33 am
by XavSnap
Hi,
Using the ROMs find line address routine at 09D8 LINE-ADDR
Yes, this ROM sub-routine seem working in a pure ASM program, but it erase some Basic variables and the Basic monitor seem to hang if you try to back to the Basic program…
Not cool !

Re: Machine Language help

Posted: Fri Nov 01, 2019 2:06 am
by blittled
Thanks all, I did change the JR To JP P. I forgot about the conditional JP :oops: The Line-ADDR Routine does look helpful but I got my routine working with my code so I'll keep it as is.

My idea is to use REM lines for DATA. Each REM will have RTTTL data for use with the ZX-GAME in it. From that I will build a look up table with each entry containing 10 bytes for name, length of RTTTL and Start address of RTTTL. I will then use the LUT to construct a menu that you can select a song from to play.