Command line parameters

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
User avatar
guddler
Posts: 431
Joined: Sat Apr 04, 2009 9:43 am
Location: W.Somerset
Contact:

Command line parameters

Post by guddler » Sun Sep 16, 2018 7:40 pm

Hi - are there any examples anywhere of how command line parameters are handled in ASM when you are NOT using BBC Basic, but instead using BeebASM? For example, I have a bit of code that writes to a SWBank but I want to accept the bank ID as a parameter. This isn't for any meaningful project, just for me to learn a few things.

All of my books assume BBC Basic because they are from BITD but honestly, BBC Basic is just gobbledigook to me and would be yet another thing to have to learn. Assembler and the intricacies' of the BCC series itself are enough without adding more to it. I'm using BeebASM on a Mac and cross compiling to BeebEm but I'm trying to avoid BeebASM unique directives so that I can also use LancASM on a real Master. I'm using that because I've still not been able to put together a working ADE setup to try.

Thanks for any pointers.
Last edited by guddler on Sun Sep 16, 2018 7:41 pm, edited 1 time in total.

User avatar
IanS
Posts: 636
Joined: Mon Aug 31, 2009 6:02 pm
Contact:

Re: Command line parameters

Post by IanS » Sun Sep 16, 2018 9:48 pm

Is the info on the beebwiki any help -
http://beebwiki.mdfs.net/Reading_command_line

User avatar
guddler
Posts: 431
Joined: Sat Apr 04, 2009 9:43 am
Location: W.Somerset
Contact:

Re: Command line parameters

Post by guddler » Sun Sep 16, 2018 10:13 pm

I think so, yes - thank you. It does go on about tube processors a bit and that was kind of next on my list but I think it's OK.

I haven't looked at what is on mdfs.net in any detail because to get there I had to change my DNS server settings. I use my own server first and foremost (for ad-blocking purposes) and then forward any non-local requests to 1.1.1.1 or 1.0.0.1 but on those servers mdfs.net does not resolve. I don't have a clue why.

It is only this afternoon that I have caved in and done something that I hate doing and gone back to using Google's DNS servers as forwarders :(

Downside, i have no clue what the hell Google are doing with my DNS resolution history, on the plus side, I can now get to mdfs.net!

User avatar
jgharston
Posts: 3184
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Command line parameters

Post by jgharston » Mon Sep 17, 2018 3:28 pm

guddler wrote:
Sun Sep 16, 2018 10:13 pm
I think so, yes - thank you. It does go on about tube processors a bit and that was kind of next on my list but I think it's OK.
The bit in the first paragraph is all you need to reading the command line parameters for a file run from disk that executes in the I/O processor. If you are not writing code to execute in a second processor, you can ignore the bit about writing code that executes in a second processor.

Code: Select all

\ lptr    = address in zero page to point to command line parameters
\ Note, four bytes are read, so lptr+2 and lptr+3 are overwritten
   
LDA #1:LDY #0:LDX #lptr:JSR OSARGS   :\ Read address of command line parameters
   
\ (lptr),Y now points to the start of the command's parameters
\ So, for example, you can then do:
.loop
LDA (lptr),Y:JSR OSASCI :\ Copy command line to current output
INY:CMP #13:BNE loop
RTS

\ Or, for example:
LDX lptr+0:LDY lptr+1   :\ XY=>text on command line
LDA #&40:JSR OSFIND     :\ Use it as a filename to open for input
TAY:BNE errFileNotFound
...

\ If you want to step past a filename to find suffixed parameters, eg:
.skipname
LDA (lptr),Y:INY
CMP #ASC"!":BCS skipname :\ Step past until space or ctrl
DEY
.skipspace
LDA (lptr),Y:INY
CMP #ASC" ":BEQ skipspace :\ Step past spaces
DEY
:
\ (lptr),Y now => anything after the first space-deliminated parameter
\ lptr=>the first parameter
You can also look at the source at http://mdfs.net/Software/CommandSrc/ for demonstrations of command line parsing. The source for SRLOAD and SRSAVE also show how to parse parameters with GSINT/GSREAD.
Last edited by jgharston on Mon Sep 17, 2018 3:30 pm, edited 2 times in total.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
jgharston
Posts: 3184
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Command line parameters

Post by jgharston » Mon Sep 17, 2018 3:30 pm

There may be a few typos above, I've just typed it live. Play around and learn. ;)

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

Post Reply