EhBASIC enhacement suggestion
EhBASIC enhacement suggestion
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.
Rich Cini
http://cini.classiccmp.org
http://altair32.classiccmp.org
GitHub Repro: https://github.com/RichCini
http://cini.classiccmp.org
http://altair32.classiccmp.org
GitHub Repro: https://github.com/RichCini
Re: EhBASIC enhacement suggestion
(Just for reference, that was perhaps this discussion
viewtopic.php?p=48612#p48612
which, I think, is about FRE(0) returning a signed number)
viewtopic.php?p=48612#p48612
which, I think, is about FRE(0) returning a signed number)
Re: EhBASIC enhacement suggestion
Yup, correct. That's it. Thanks BigEd.
Rich Cini
http://cini.classiccmp.org
http://altair32.classiccmp.org
GitHub Repro: https://github.com/RichCini
http://cini.classiccmp.org
http://altair32.classiccmp.org
GitHub Repro: https://github.com/RichCini
-
ArnoldLayne
- Posts: 109
- Joined: 28 Dec 2014
- Location: Munich, Germany
- Contact:
Re: EhBASIC enhacement suggestion
RichCini wrote:
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.
https://bitbucket.org/steckschwein/stec ... 6b0a20653f
the toupper macro just contains
Code: Select all
cmp #$60 ; Is lowercase?
bcc :+
and #$DF
:
Re: EhBASIC enhacement suggestion
ArnoldLayne wrote:
RichCini wrote:
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.
https://bitbucket.org/steckschwein/stec ... 6b0a20653f
the toupper macro just contains
Code: Select all
cmp #$60 ; Is lowercase?
bcc :+
and #$DF
:
Rich Cini
http://cini.classiccmp.org
http://altair32.classiccmp.org
GitHub Repro: https://github.com/RichCini
http://cini.classiccmp.org
http://altair32.classiccmp.org
GitHub Repro: https://github.com/RichCini
-
ArnoldLayne
- Posts: 109
- Joined: 28 Dec 2014
- Location: Munich, Germany
- Contact:
Re: EhBASIC enhacement suggestion
RichCini wrote:
Ahhh, this is really good. I'll give it a try. Thanks!
Re: EhBASIC enhacement suggestion
I like the patch. There is just a tiny problem. Characters in variable names not in the token dictionary get converted to upper case.Characters not in the dictionary are JKQXYZ. To restore the lower case character after an unsuccessful dictionary search you must redirect a branchto a new label
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
Code: Select all
new
Ready
10 aj=kl+pqr
list
10 aJ=Kl+pQr
ReadyCode: 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
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
edit: updated where to find the patch
Last edited by Klaus2m5 on Thu Jan 18, 2018 3:45 pm, edited 1 time in total.
6502 sources on GitHub: https://github.com/Klaus2m5
-
ArnoldLayne
- Posts: 109
- Joined: 28 Dec 2014
- Location: Munich, Germany
- Contact:
Re: EhBASIC enhacement suggestion
Klaus2m5 wrote:
I like the patch. There is just a tiny problem. Characters in variable names not in the token dictionary get converted to upper case.
Klaus2m5 wrote:
If there is no objection i will add the complete patch to my list. https://github.com/Klaus2m5/6502_EhBASI ... quirks.txt
Re: EhBASIC enhacement suggestion
ArnoldLayne wrote:
Klaus2m5 wrote:
I like the patch. There is just a tiny problem. Characters in variable names not in the token dictionary get converted to upper case.
Klaus2m5 wrote:
If there is no objection i will add the complete patch to my list. https://github.com/Klaus2m5/6502_EhBASI ... quirks.txt
Rich Cini
http://cini.classiccmp.org
http://altair32.classiccmp.org
GitHub Repro: https://github.com/RichCini
http://cini.classiccmp.org
http://altair32.classiccmp.org
GitHub Repro: https://github.com/RichCini
Re: EhBASIC enhacement suggestion
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:
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.
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 endAny 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
You forgot to restore A after it is destroyed by EOR/AND! Did you ever test your patch?
6502 sources on GitHub: https://github.com/Klaus2m5
Re: EhBASIC enhacement suggestion
Klaus2m5 wrote:
You forgot to restore A after it is destroyed by EOR/AND! Did you ever test your patch?
Re: EhBASIC enhacement suggestion
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.
6502 sources on GitHub: https://github.com/Klaus2m5
Re: EhBASIC enhacement suggestion
Please do. I haven't had opportunity to test the patch yet however, keep this in mind. 