Page 1 of 1
EhBASIC enhacement suggestion
Posted: Tue Jan 17, 2017 1:00 am
by RichCini
Within another thread, there was a suggestion for changing certain function returns from signed to unsigned. One other fix I thought of that is probably very easy is upper-case/lower-case key word interpretation...unless there is some compilation switch I missed somewhere. I keep forgetting to put on the CAPS LOCK so I keep getting errors. Minorly annoying, but I thought I'd mention it if people are thinking of making changes to the code.
Re: EhBASIC enhacement suggestion
Posted: Tue Jan 17, 2017 10:45 am
by BigEd
(Just for reference, that was perhaps this discussion
viewtopic.php?p=48612#p48612
which, I think, is about FRE(0) returning a signed number)
Re: EhBASIC enhacement suggestion
Posted: Tue Jan 17, 2017 9:04 pm
by RichCini
Yup, correct. That's it. Thanks BigEd.
Re: EhBASIC enhacement suggestion
Posted: Wed Jan 18, 2017 11:04 am
by ArnoldLayne
One other fix I thought of that is probably very easy is upper-case/lower-case key word interpretation...unless there is some compilation switch I missed somewhere.
That's what I did in my port to my homebrew machine, check out this commit:
https://bitbucket.org/steckschwein/stec ... 6b0a20653f
the toupper macro just contains
Code: Select all
cmp #$60 ; Is lowercase?
bcc :+
and #$DF
:
This modification only makes the tokenizer case insensitive, LIST will still show keywords in uppercase and you will get uppercase and lowercase variable names as a bonus.
Re: EhBASIC enhacement suggestion
Posted: Wed Jan 18, 2017 12:46 pm
by RichCini
One other fix I thought of that is probably very easy is upper-case/lower-case key word interpretation...unless there is some compilation switch I missed somewhere.
That's what I did in my port to my homebrew machine, check out this commit:
https://bitbucket.org/steckschwein/stec ... 6b0a20653f
the toupper macro just contains
Code: Select all
cmp #$60 ; Is lowercase?
bcc :+
and #$DF
:
This modification only makes the tokenizer case insensitive, LIST will still show keywords in uppercase and you will get uppercase and lowercase variable names as a bonus.
Ahhh, this is really good. I'll give it a try. Thanks!
Re: EhBASIC enhacement suggestion
Posted: Thu Jan 19, 2017 8:01 am
by ArnoldLayne
Ahhh, this is really good. I'll give it a try. Thanks!
Let me know if you run into any issues. I am quite new to EhBasic, it's very likely I overlooked something.
Re: EhBASIC enhacement suggestion
Posted: Thu Jan 19, 2017 2:57 pm
by Klaus2m5
I like the patch. There is just a tiny problem. Characters in variable names not in the token dictionary get converted to upper case.
Code: Select all
new
Ready
10 aj=kl+pqr
list
10 aJ=Kl+pQr
Ready
Characters not in the dictionary are JKQXYZ. To restore the lower case character after an unsuccessful dictionary search you must redirect a branch
Code: Select all
LAB_13D0
CMP (ut2_pl),Y ; compare with keyword first character table byte
BEQ LAB_13D1 ; go do word_table_chr if match
; *** replace
; BCC LAB_13EA ; if < keyword first character table byte go restore
; *** with
BCC PATCH_LC2 ; if < keyword first character table byte go restore
; *** end
; Y and save to crunched
to a new label
Code: Select all
; now find the end of this word in the table
LAB_141B
LDA (ut2_pl),Y ; get table byte
PHP ; save status
INY ; increment table index
PLP ; restore byte status
BPL LAB_141B ; if not end of keyword go do next
LDA (ut2_pl),Y ; get byte from keyword table
BNE LAB_13D8 ; go test next word if not zero byte (end of table)
; reached end of table with no match
; *** add label
PATCH_LC2
; *** end
LDA Ibuffs,X ; restore byte from input buffer
BPL LAB_13EA ; branch always (all bytes in buffer are $00-$7F)
; go save byte in output and continue crunching
If there is no objection i will add the complete patch to my list.
https://github.com/Klaus2m5/6502_EhBASI ... ds_mod.txt
edit: updated where to find the patch
Re: EhBASIC enhacement suggestion
Posted: Thu Jan 19, 2017 6:04 pm
by ArnoldLayne
I like the patch. There is just a tiny problem. Characters in variable names not in the token dictionary get converted to upper case.
Ha, I knew I'd overlook something. I applied you patch and it works perfectly.
No objection from me.
Re: EhBASIC enhacement suggestion
Posted: Thu Jan 19, 2017 6:58 pm
by RichCini
I like the patch. There is just a tiny problem. Characters in variable names not in the token dictionary get converted to upper case.
Ha, I knew I'd overlook something. I applied you patch and it works perfectly.
No objection from me.
I'm good with it. Thanks!
Re: EhBASIC enhacement suggestion
Posted: Wed Jan 17, 2018 5:40 pm
by jbevren
Hey guys,
Sorry for waking a relatively old thread, but I was working with the 6502 badge and had challenges with the upper case requirements. Before finding this thread I had already written prototype code to fix this and it's a bit different from what I found here so I thought I'd share for review.
The code is written to patch the badge version of EhBASIC so labels may differ some, and the patch quoted at the bottom will almost certainly not cleanly apply.
First, a bit of my mind: The difference between upper case and lower case is $20, calculated by subtracting 'A' from 'a', $61 - $41. This inverted becomes $DF, a mask to either convert lower to upper case with AND, or to similarly mask a mismatch while using EOR as a compare:
Code: Select all
+; jbev start
+ EOR Ibuffs,x ; check bits against table
+ AND #$DF ; DF masks the upper/lower case bit
+; was: CMP Ibuffs,X ; compare with byte from input buffer
+; jbev end
As seen above, the CMP was replaced with EOR:AND. This does slow the tokenize code down, but as it's generally only used during program entry I feel it's worth the performance loss.
Any thoughts on this method? As a very novice assembly programmer I may have some error in my logic but by this point there shouldn't be anything but alpha characters in .A and during the full-keyword search. The only flaw is when handling the first-character search, so a bit more patching would be needed to prevent J from matching *, for example. The code is also modified with space in mind. I could unroll the loops for speed during the first eight checks but didn't consider it worth the extra bytes in memory to save some 24 cycles.
The text below is a 'diff' format patch between the original and modified code.
Code: Select all
--- basic.asm.orig 2018-01-17 11:30:35.152970124 -0500
+++ basic.asm 2018-01-17 12:29:05.407284754 -0500
@@ -1053,8 +1053,25 @@
LDY #$00 ; clear table pointer
LAB_13D0
+; JBEV - refactor this for case insensitive tokenization
+; Yes, this slows down tokenization, but it's not a routine that gets
+; used often, so a bit of slowdown here should be ok.
+; The first step, EOR, will result in a zero output on uppercase match,
+; and a $20 on lowercase match.
+; The second step, AND #$DF, will mask that $20 bit so the original BEQ
+; will function as normal for the token match search.
+
+; jbev start
+ CPY #8 ; do a standard compare for the non-alpha entries.
+ BCS JB_LC1 ; not at the 'A' ent yet?
CMP (ut2_pl),Y ; compare with keyword first character table byte
- BEQ LAB_13D1 ; go do word_table_chr if match
+ JMP JB_LC2 ; jump around the patch
+
+JB_LC1 EOR (ut2_pl),Y ; check bits against first char table byte
+ AND #$DF ; DF masks the upper/lower case bit
+; jbev end
+
+JB_LC2 BEQ LAB_13D1 ; go do word_table_chr if match
BCC LAB_13EA ; if < keyword first character table byte go restore
; Y and save to crunched
@@ -1063,6 +1080,8 @@
BNE LAB_13D0 ; and loop (branch always)
; have matched first character of some keyword
+; JBEV - refactor this for case-insensitive tokenization
+; JBEV - the EOR/AND route was taken as the high bit test is necessary at 13D6.
LAB_13D1
TYA ; copy matching index
@@ -1084,7 +1103,13 @@
BMI LAB_13EA ; all bytes matched so go save token
INX ; next buffer byte
- CMP Ibuffs,X ; compare with byte from input buffer
+
+; jbev start
+ EOR Ibuffs,x ; check bits against table
+ AND #$DF ; DF masks the upper/lower case bit
+; was: CMP Ibuffs,X ; compare with byte from input buffer
+; jbev end
+
BEQ LAB_13D6 ; go compare next if match
BNE LAB_1417 ; branch if >< (not found keyword)
Re: EhBASIC enhacement suggestion
Posted: Thu Jan 18, 2018 10:15 am
by Klaus2m5
You forgot to restore A after it is destroyed by EOR/AND! Did you ever test your patch?
Re: EhBASIC enhacement suggestion
Posted: Thu Jan 18, 2018 2:19 pm
by jbevren
You forgot to restore A after it is destroyed by EOR/AND! Did you ever test your patch?
Thanks! I haven't tested yet, and knew I was missing something but wasn't sure what

Re: EhBASIC enhacement suggestion
Posted: Sat Jan 20, 2018 1:12 pm
by Klaus2m5
After I took a closer look it appears that the second part of jbevren's patch is faster and shorter than mine. So I will change the patch accordingly.
Re: EhBASIC enhacement suggestion
Posted: Thu Jan 25, 2018 2:40 pm
by jbevren
Please do. I haven't had opportunity to test the patch yet however, keep this in mind.
