Thanks, Michael.
--
Michael Searle - sea...@longacre.demon.co.uk
> Does anyone here know the internal format of line numbers in BBC BASIC 5, as
> used by commands using a line reference? (I don't mean the 2-byte number at
> the start of each line. GOTO, GOSUB etc use a different 3 or 4 byte format.
> It isn't mentioned in the 'BASIC technical information' section of the
> Master 128 reference manuals. (no, I don't have the PRMs.)
>
The encoding can be unpacked in some nice short 6502 code,
but here's my version:
;------------------------------------------------------------------------
; Convert a basic tokenised line number into an integer
;
; In R1 = pointer to just after the &8D byte
; Out R0 = number
; R1 = pointer just beyond line number
;
.basdecodeln
LDRB R0, [R1], #1
ANDS R2, R0, #&20
MOVne R2, #&80
TST R0, #&10
ADDeq R2, R2, #&40
TST R0, #&04
ADDeq R2, R2, #&4000
TST R0, #&08
ADDne R2, R2, #&8000
LDRB R0, [R1], #1
AND R0, R0, #&3F
ORR R2, R2, R0
LDRB R0, [R1], #1
AND R0, R0, #&3F
ORR R0, R2, R0, LSL #8
MOVS pc, lr
Or,
+---+---+---+---++---+---+---+---+
byte 1 | ? | ? | 7 | 6 || f | e | ? | ? |
+---+---+---+---++---+---+---+---+
+---+---+---+---++---+---+---+---+
byte 2 | ? | ? | 5 | 4 || 3 | 2 | 1 | 0 |
+---+---+---+---++---+---+---+---+
+---+---+---+---++---+---+---+---+
byte 3 | ? | ? | d | c || b | a | 9 | 8 |
+---+---+---+---++---+---+---+---+
I *think* the '?'s are always set.
Cy.
As far as I remember, little about BASIC is in the PRMs, it's in the BASIC V
manual (which I don't have here). It said something like:
The encoding scheme uses a fixed number of bytes, so that renumber does not have
to change line lengths when it encounters GOTOs etc.
The ecoding sheme has been changed on BASIC V so that the bytes used to encode
the line number have the top bit clear, so that the line numbers bytes did not
confuse (?) tokenisers. I think only 6 bits (64 combinations) are encoded in
each of the three bytes, giving 18 bits to hold the 16 bit line number. The
3 bytes are preceded by a token (don't know which - hopefully obvious from a
tokenised program)
Hope these ramblings help,
Nick
PS Has anyone apart from me noticed that Zap gets confused by top bit set
characters outside string quotes (eg REM statements)?
--
C:\> ECHO f 0000:0000 ffff 66 | DEBUG
Me, guv! I've even chatted with Dom Symes about it (nice bloke). It's a
bit of a pathological problem - my main problem with it is that when (for
example) pressing the pound sign brings up 'FALSE', it only moves the caret
one space instead of five. Otherwise, we'd be back to sinclair speccy type
BASIC entry. Hmm, there's a thought ;-)
--
=============================================================================
=======================Campaign against MIME=================================
=============================================================================
=============================================================================
Ah, I had lots of fun with that.. I released several versions of StrongED
before I discovered (ok, someone told me..) that those line numbers are in
a funny format. Never use the darn things myself.
Here's the routine I came up with trough trial and error :
.BTTCode ;------- Coded constant (Token &8D)
; 3 bytes with bits all jumbled up!
LDRB R1,[R12],#1
LDRB R2,[R12],#1
LDRB R3,[R12],#1
AND R1,R1,#%00111100
EOR R1,R1,#%00010100
AND R0,R2,#%00111111
MOV R14,R1,LSR#4
ORR R0,R0,R14,LSL#6
AND R3,R3,#%00111111
ORR R0,R0,R3,LSL#8
MOV R14,R1,LSR#2
ORR R0,R0,R14,LSL#14
;------- Value is now in R0
And here's something Sophie sent me :
> Packed constant line numbers are in a funny form in order to
> prevent them ever containing a token (embarassing if they do:
> WHILE, IF THEN ELSE ENDIF and others could get damaged).
>
> ;get line number to r0. EQ if succeed, NE otherwise
> ;uses r0,r1,r10
> SPTSTN LDRB R10,[LINE],#1
> CMP R10,#" "
> BEQ SPTSTN
> CMP R10,#TCONST
> MOVNE PC,R14
> SPGETN LDRB R10,[LINE],#1
> MOV R0,R10,LSL #2
> AND R1,R0,#&C0
> LDRB R10,[LINE],#1
> EOR R1,R1,R10
> LDRB R10,[LINE],#1
> EOR R0,R10,R0,LSL #2
> AND R0,R0,#255
> ORR R0,R1,R0,LSL #8
> MOV PC,R14
Cheers,
Guttorm