6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Apr 18, 2024 12:12 pm

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: Tue Jan 17, 2017 1:00 am 
Offline
User avatar

Joined: Wed Sep 03, 2003 6:53 pm
Posts: 150
Location: Long Island, NY
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
Build Master and maintainer of the Altair32 Emulation project
http://cini.classiccmp.org
http://altair32.classiccmp.org


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 17, 2017 10:45 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10789
Location: England
(Just for reference, that was perhaps this discussion
viewtopic.php?p=48612#p48612
which, I think, is about FRE(0) returning a signed number)


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 17, 2017 9:04 pm 
Offline
User avatar

Joined: Wed Sep 03, 2003 6:53 pm
Posts: 150
Location: Long Island, NY
Yup, correct. That's it. Thanks BigEd.

_________________
Rich Cini
Build Master and maintainer of the Altair32 Emulation project
http://cini.classiccmp.org
http://altair32.classiccmp.org


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 18, 2017 11:04 am 
Offline

Joined: Sun Dec 28, 2014 11:04 pm
Posts: 81
Location: Munich, Germany
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.


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:
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.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 18, 2017 12:46 pm 
Offline
User avatar

Joined: Wed Sep 03, 2003 6:53 pm
Posts: 150
Location: Long Island, NY
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.


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:
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!

_________________
Rich Cini
Build Master and maintainer of the Altair32 Emulation project
http://cini.classiccmp.org
http://altair32.classiccmp.org


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 19, 2017 8:01 am 
Offline

Joined: Sun Dec 28, 2014 11:04 pm
Posts: 81
Location: Munich, Germany
RichCini wrote:

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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 19, 2017 2:57 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
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:
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:
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:
                              ; 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

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Last edited by Klaus2m5 on Thu Jan 18, 2018 3:45 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 19, 2017 6:04 pm 
Offline

Joined: Sun Dec 28, 2014 11:04 pm
Posts: 81
Location: Munich, Germany
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.

Ha, I knew I'd overlook something. I applied you patch and it works perfectly.

Klaus2m5 wrote:
If there is no objection i will add the complete patch to my list. https://github.com/Klaus2m5/6502_EhBASI ... quirks.txt

No objection from me.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 19, 2017 6:58 pm 
Offline
User avatar

Joined: Wed Sep 03, 2003 6:53 pm
Posts: 150
Location: Long Island, NY
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.

Ha, I knew I'd overlook something. I applied you patch and it works perfectly.

Klaus2m5 wrote:
If there is no objection i will add the complete patch to my list. https://github.com/Klaus2m5/6502_EhBASI ... quirks.txt

No objection from me.


I'm good with it. Thanks!

_________________
Rich Cini
Build Master and maintainer of the Altair32 Emulation project
http://cini.classiccmp.org
http://altair32.classiccmp.org


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 17, 2018 5:40 pm 
Offline

Joined: Thu Apr 24, 2014 3:35 am
Posts: 10
Location: Upstate NY
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:
+; 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:
--- 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)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 18, 2018 10:15 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 18, 2018 2:19 pm 
Offline

Joined: Thu Apr 24, 2014 3:35 am
Posts: 10
Location: Upstate NY
Klaus2m5 wrote:
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 :)


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 20, 2018 1:12 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 25, 2018 2:40 pm 
Offline

Joined: Thu Apr 24, 2014 3:35 am
Posts: 10
Location: Upstate NY
Please do. I haven't had opportunity to test the patch yet however, keep this in mind. :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: