6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 11:02 pm

All times are UTC




Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu Mar 07, 2024 12:13 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 690
Location: North Tejas
barrym95838 wrote:
drogon wrote:
Most (at least in the 8-bit world) have just a line number and end of line token, or line number + length. The latter is in my TinyBasic - so GOTO/GOSUB involves a linear search, but at least it can skip lines as it knows their length.

I added the length feature to VTL02, and included a condition that would allow "find" to start the linear search at the next line rather than the first line, making forward "GOTO"s less clunky. It worked so well that I decided to re-use it to find the next line during normal execution as well, at the expense of a handful of clocks.

Does that work well enough to also store the length at the end of each line to speed up the search for a lower line number?

You would need to structure it as:

<previous line text><CR><prev length><current length><current line text><CR>...


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 07, 2024 12:32 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1399
Location: Scotland
BillG wrote:
barrym95838 wrote:
drogon wrote:
Most (at least in the 8-bit world) have just a line number and end of line token, or line number + length. The latter is in my TinyBasic - so GOTO/GOSUB involves a linear search, but at least it can skip lines as it knows their length.

I added the length feature to VTL02, and included a condition that would allow "find" to start the linear search at the next line rather than the first line, making forward "GOTO"s less clunky. It worked so well that I decided to re-use it to find the next line during normal execution as well, at the expense of a handful of clocks.

Does that work well enough to also store the length at the end of each line to speed up the search for a lower line number?

You would need to structure it as:

<previous line text><CR><prev length><current length><current line text><CR>...


It's akin to linked-list vs. doubly linked-list data structures - the programming burden (code size, testing) vs. simplicity and smaller code. In traditional memory constrained 8-bit systems, I suspect going for smaller code and simplicity is a bigger win... (or maybe the writers of them back in the 70s and early 80s just didn't have the knowledge then?

My "big" BASIC (written in C) does a pre-run-time fix-up and scans the code for GOTO/GOSUB references and replaces them with a token containing the address of the line, so no searches during run-time. This also means no GOTO {expression}, but I can live with that as you can code mostly line-number free if desired.

I think there was an Atari Basic that did this sort of pre-run-time scan to speed it up too, but I may be wrong...

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 07, 2024 4:51 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1927
Location: Sacramento, CA, USA
drogon wrote:
Would the overhead of saying "is the target greater than the current line number, or less than or equal?" and picking the appropriate algorithm worth the time to do the test and the extra RAM needed (in a minimal RAM system) ?

I think you might need a good selection of old BASIC programs to find out...

-Gordon

I got the idea from a certain Mr. Gates. I think that the only way for a human to notice the difference would be to run some rather large programs with a bunch of loops, like "Super Star Trek" or similar. I have a version that is stalled in the fixed-point navigation routines ... and has been for some time.

Some of these performance features that weren't in Frank's original 6800 implementation came after my realization that I wasn't going to fit VTL02 into 768 ROMable bytes at my coding skill level. I changed my goal to 1KB or less and used that extra breathing room to add a few features, like proper cold initialization of the user area, five additional binary operators, the VTL-2 equivalents of PEEK & POKE, and performance enhancements. I know a bit more now than I did then, and there's a non-zero chance that I or someone more skillful than I could revisit the 6800 source and try to fit the original features inside 768 bytes of 6502 (or 65c02) assembly, but that ship has probably sailed, at least for me in my current situation.

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Last edited by barrym95838 on Thu Mar 07, 2024 8:13 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 07, 2024 5:24 pm 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 387
Location: Minnesota
Quote:
My "big" BASIC (written in C) does a pre-run-time fix-up and scans the code for GOTO/GOSUB references and replaces them with a token containing the address of the line, so no searches during run-time. This also means no GOTO {expression}, but I can live with that as you can code mostly line-number free if desired.


The idea of a RUN command triggering some sort of pre-scan that checks for various mistakes before they can happen and/or speeds up later lookups is not a new one, though not one that 6502 Microsoft BASICs adopted.

This book https://www.wang2200.org/2200tech/Implementing%20BASICs.pdf touches on the concept.

Overall I think it's a horrible book, far too preachy in its "this is the way it's done" attitude and refusal to acknowledge that there are in fact alternative approaches. But it has one or two ideas I hadn't seen before.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 07, 2024 5:43 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Thanks for the link! (And the warning)


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 07, 2024 9:54 pm 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 660
Location: Potsdam, DE
Indeed thanks. But it's a bit of a jar to my brain to see the first illustration has Top of Memory as smallest memory address, and Bottom of Memory as largest...

Neil


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 08, 2024 3:01 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 690
Location: North Tejas
drogon wrote:
It's akin to linked-list vs. doubly linked-list data structures - the programming burden (code size, testing) vs. simplicity and smaller code. In traditional memory constrained 8-bit systems, I suspect going for smaller code and simplicity is a bigger win... (or maybe the writers of them back in the 70s and early 80s just didn't have the knowledge then?

Except that storing the length of the line instead of the address of the adjacent line is that it does not need to be adjusted when lines are inserted or deleted.


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 08, 2024 10:09 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 690
Location: North Tejas
teamtempest wrote:

I bought that book back in the day and totally forgot about it. I do not know where it is now...


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 08, 2024 10:18 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 690
Location: North Tejas
barnacle wrote:
But it's a bit of a jar to my brain to see the first illustration has Top of Memory as smallest memory address, and Bottom of Memory as largest...

Funny how that works...

We are accustomed to the lower left as the origin for charts.

Whereas we use the upper left of a display device as the origin with exceptions like OS/2 Presentation Manager.

And some people have real problems with stacks growing downward (toward lower address) on most processors meaning that the top of the stack is at a lower address than the bottom.

Don't get me started on electron vs conventional current flow...


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 08, 2024 4:39 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1927
Location: Sacramento, CA, USA
BillG wrote:
Except that storing the length of the line instead of the address of the adjacent line is that it does not need to be adjusted when lines are inserted or deleted.

Yeah, I never understood why Applesoft and friends used 16-bit absolute line links instead of 8-bit relative. It seems like a waste of a perfectly good byte for every line and adds an unnecessary burden to the line editor when inserting/deleting.
Attachment:
linelinks.PNG
linelinks.PNG [ 6.07 KiB | Viewed 2710 times ]

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 09, 2024 12:03 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 690
Location: North Tejas
8-bit relative has its price at run-time: an addition or subtraction involving the line's actual address.


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 09, 2024 1:41 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1927
Location: Sacramento, CA, USA
BillG wrote:
8-bit relative has its price at run-time: an addition or subtraction involving the line's actual address.

The 6502 does it in such a way that the difference is negligible, and in fact slightly favors the relative technique:
Code:
nextln:
    ldy  #0         ; [2]
    lda  (txt),y    ; [5]
    clc             ; [2]
    adc  txt        ; [3]
    sta  txt        ; [3]
    bcc  next99     ; [2*]
    inc  txt+1      ; [5]
next99:
    ...             ; best case 18, worst 22

nextln:
    ldy  #0         ; [2]
    lda  (txt),y    ; [5]
    tax             ; [2]
    iny             ; [2]
    lda  (txt),y    ; [5*]
    sta  txt+1      ; [3]
    stx  txt        ; [3]
    ...             ; best case 22, worst 23

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 09, 2024 1:48 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 690
Location: North Tejas
Touché

How could forget that the 6502 is not like the 680x where I can simply do

ldx 0,X


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 29 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: