Quantcast
Channel: stardot.org.uk
Viewing all articles
Browse latest Browse all 2978

programming • Parsing web address (http(s)://) in 6502 getting extra /

$
0
0
Hey all,
I've almost moved my pretty slow Beeb web browser (basic) over to assembly. But I'm struggling to get it to split some hyperlink addresses correctly. For example some local links on a page might be <a href="about.html".... rather than <a href="/about.html". Or links may be the full address nickh.org/about.html (as an aside I have no idea who Nick H is, it's just a Web 1.0 website I've been using for testing found using the Wiby.org web 1 search engine surprise me feature).

The problem I'm having is my 6502 code is adding an extra / even when it is not needed, and I have no idea why (html parsing code below). To add context to send the telnet request to get a website it needs to be formatted as:

GET <directory> HTTP/1.1
Host: www.site.com
Connection: Close

So http://beebs.ddns.net/connecting is sent as:

GET /connecting HTTP/1.1
Host: beebs.ddns.net
Connection: Close

Unfortunately my code is sending GET //connecting rather than /connecting (....infuriating!), but it's fine handling hyperlinks formatted as connecting.html (as it adds the /).

The memory addresses I'm using are called urlstorage which store an index of all the links that are currently displayed on the screen, address which stores the web address fed to Host: in the telnet request and dir which stores the directory fed to GET.

An image paints a thousand words....
Working with no preceding /'s
page.png
noslashURLSZoom.png
MemorySlashAddedZoom.png
Adding extra / where not needed:
URLSzoom.png
extra slash zoom.png
6502 Assembly:

Code:

.HyperlinkFollow  JSR osrdch;User enters link to follow A-z  STA followlink;Value entered ftored in follow link  LDA #65  STA link;Reset value in link to A for next page.HyperlinkFollowFindURLZero  LDX #0  LDY #0.HyperlinkFollowFindURL  LDA urlstorage,X;Load links for current page store in urlstorage (format <1>(link letter)http://www/website.com/cats<2>)  CMP #1;Check for start of link  BEQ HyperlinkFollowFindINC;Go here if link found  INX;If not check the next character of urlstorage  CPX lasturlptr;Is this the end of the list of links?  BEQ HyprelinkNotFound;If it is display not found message  JMP HyperlinkFollowFindURL;Restart loop.HyperlinkFollowFindINC  INX;Get next character (should be the link label letter)  LDA urlstorage,X;Load this into A  CMP followlink;Compare this against the link chosen  BEQ HyperlinkFollowMatch;Go here if they match  JMP HyperlinkFollowFindURL;Go back to searching for the next link if they do not.HyperlinkFollowMatch  INX;Get next character (should be h)  LDA urlstorage,X;Load this in to A  CMP #104;Is it a h?  BEQ HypelinkFollowMatchAddress;If it is go here and start to process http(s)  JMP HyperlinkFollowMatchDIRZero;If not it's a file, page or directory, go her to place it in the directory string e.g. /cats or cats.html.HyprelinkNotFound  JMP ReturnFromMenuEntry;.HyperlinkFollowMatchDIRZero  LDY #0;Reset Y to use as pointer  LDA urlstorage,X;Reload in character from URL storage  CMP #47;Is it a /  BNE HyperlinkDIRAddSlash;If it doesn't start with / add one (this would be a link like about.html rather than /about.html or website.com/about.html)  JMP HyperlinkFollowMatchDIR                               ;Go here to check for the end of http or https ://.HyperlinkDIRAddSlash  LDA #47  STA dir,Y  INY.HyperlinkFollowMatchDIR  LDA urlstorage,X;  CMP #2;Is this the end of the address? (terminated with #2)  BEQ HyerlinkFollowMatchComplete;If the address is complete go here  STA dir,Y;If not store the current character from urlstorage in the directory string  INX;Increase X pointer for urlstorage  INY;Increase Y pointer for directory storage  JMP HyperlinkFollowMatchDIR;Loop.HypelinkFollowMatchAddress  LDY #0;Reset Y pointer  INX;Move along to the 7th character which should be a / (either the first or second depending on http https)  INX  INX  INX  INX.HyperlinkFollowSlash  INX  LDA urlstorage,X;Load the this character in to A  CMP #47;Is this a /  BEQ HyperlinkFollowSlash;If it is a / loop  JSR ClearAddress;If not clear the address string (where the address for the dialer is stored)  LDY #0;Reset Y pointer.HyperlinkFollowMoveURLtoAddress  LDA urlstorage,X;This should now be the URL minus the http / https :// section  CMP #47;Is it a /  BEQ HypelinkFollowMatchAddressComplete;If it is then it has read in the domain so go here  STA address,Y;Store the current character in the address string  INY;Increase the y pointer for the address  INX;Increase the X pointer for URL storage  JMP HyperlinkFollowMoveURLtoAddress;Loop until / is found.HypelinkFollowMatchAddressComplete  INY;move past the last character stored in address  LDA #13;add <cr> to the end of the sting (for dialer)  STA address,Y;  INY;increase y pointer for address  LDA #0;Store 0 to terminate the address (so dialer knows the end)  STA address,Y  JMP HyperlinkFollowMatchDIRZero;load either / or the sub dir or the file into dir.HyerlinkFollowMatchComplete  JMP ClearURLStorage;clear the urls stored for the current displayed page area.ReturnFromUrlClear  JSR ClearSerialBuffer;empty any remaining parts of the previous website from the serial buffer  JMP NewDial;dial the next website address and directory.
Any help as always very welcome, go easy on me it's only my 3rd 6502 project. And apologies for the screenshot quality I have to run BeebEm under wine and for some reason the debug window ignores the DPI setting.

Statistics: Posted by vela025 — Thu Apr 24, 2025 8:53 pm



Viewing all articles
Browse latest Browse all 2978

Trending Articles