Path: news1.icaen!news.uiowa.edu!NewsNG.Chicago.Qual.Net!207.24.245.130!nyd.news.ans.net!news.idt.net!netnews.com!newspeer1.nac.net!news.new-york.net!newsmaster.cc.columbia.edu!osiris.giss.nasa.gov!newsfeed.gsfc.nasa.gov!usenet From: Geraldine.A.Wright.1@gsfc.nasa.gov (Geraldine Wright) Newsgroups: comp.sys.apple2.programmer Subject: GSoft BASIC question Date: 12 Apr 1999 12:30:20 GMT Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Lines: 32 Message-ID: <7esp0s$b98@post.gsfc.nasa.gov> NNTP-Posting-Host: gerryw.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: Text/Plain; charset=US-ASCII X-Newsreader: WinVN 0.99.7 Xref: news1.icaen comp.sys.apple2.programmer:10499 I am attempting to write a user tool for use with GSoft so I can make use of some simple machine language routines in my programs. I have gotten it to the point where it can be loaded from GSoft with the LOADLIBRARY command. Some, but not all of the functions work, and I am trying to figure out what is wrong. The ones that work are the SUB's that neither require an input nor deliver an output, and the FUNCTION's that need no input but deliver an output. All the ones that fail are FUNCTION's that require an input. In order to see if the problem was in the function itself, I commented out all the statements in my source code in one of those functions, with the exception of CLC LDA $00 RTL and then reassembled & linked the tool. Nothing changed in the behavior. When I call the function, it crashes into the monitor. If anyone else has experience writing some of these things, I would appreciate some advice. More info: I am using Merlin 8/16 for my assembly and linking. I instruct the linker to make the OMF segment segment of Kind $00. Using a block editor, I have compared my user tool with the GameTool tool which comes with GSoft to see if I can spot any obvious differences. The only difference I can really spot is that the GameTool has a segment for calling the ExpressLoader, and my code does not. I wouldn't expect that to make a difference, but if it does, could someone explain why to me? -- --------------------------------------- Geraldine Wright (the Applesoft-aholic) Geraldine.A.Wright.1@gsfc.nasa.gov --------------------------------------- "Big, fat hairy deal!" -Garfield Path: news1.icaen!news.uiowa.edu!NewsNG.Chicago.Qual.Net!128.174.5.49!vixen.cso.uiuc.edu!howland.erols.net!cpk-news-hub1.bbnplanet.com!cam-news-feed1.bbnplanet.com!news.gtei.net!news.delphi.com!news From: kws@delphi.com Newsgroups: comp.sys.apple2.programmer Subject: Re: GSoft BASIC question Date: Mon, 12 Apr 99 10:49:12 -0500 Organization: Delphi (info@delphi.com email, 800-695-4005 voice) Lines: 7 Message-ID: <5xf7h2A.kws@delphi.com> References: <7esp0s$b98@post.gsfc.nasa.gov> NNTP-Posting-Host: 199.93.4.2 X-To: Geraldine Wright Xref: news1.icaen comp.sys.apple2.programmer:10500 Have you examined the _source_ for the included tools and/or read your Toolbox books? There are a few fine points for writing tools, such as 2 return addresses on the stack (which would affect where you think passed parameters are, and where to store results). The "Expressload" segment doesn't matter. It makes tool loading faster, but for a small file, the difference is negligible. Path: news1.icaen!news.uiowa.edu!news.physics.uiowa.edu!math.ohio-state.edu!howland.erols.net!newsfeed.cwix.com!198.138.0.5!newshub.northeast.verio.net!news.new-york.net!newsmaster.cc.columbia.edu!osiris.giss.nasa.gov!newsfeed.gsfc.nasa.gov!usenet From: Geraldine.A.Wright.1@gsfc.nasa.gov (Geraldine Wright) Newsgroups: comp.sys.apple2.programmer Subject: Re: GSoft BASIC question Date: 12 Apr 1999 19:34:10 GMT Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Lines: 24 Message-ID: <7ethri$m9l@post.gsfc.nasa.gov> References: <7esp0s$b98@post.gsfc.nasa.gov> <5xf7h2A.kws@delphi.com> NNTP-Posting-Host: gerryw.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: Text/Plain; charset=US-ASCII X-Newsreader: WinVN 0.99.7 Xref: news1.icaen comp.sys.apple2.programmer:10501 In article <5xf7h2A.kws@delphi.com>, kws@delphi.com says... >Have you examined the _source_ for the included tools and/or read >your Toolbox books? There are a few fine points for writing tools, >such as 2 return addresses on the stack (which would affect where you >think passed parameters are, and where to store results). Yes. I used the source code for the GameTool tool as a pattern for my tool, as well as consulting the Toolbox references. Since I am able to retrieve values from functions that return something, I believe I have navigated the 2 return addresses issue correctly. What I have not mastered is getting a passed parameter to the functions that require input. It seems to bomb, whether I even try to use the passed value or not. Just the process of getting the value to the function isn't working. There must be something I am missing. BTW, I have tried loading and using the tool after doing a shift-boot, and it still bombed, so I don't think the an Init or DA is to blame. -- --------------------------------------- Geraldine Wright (the Applesoft-aholic) Geraldine.A.Wright.1@gsfc.nasa.gov --------------------------------------- "Big, fat hairy deal!" -Garfield Path: news1.icaen!news.uiowa.edu!news.physics.uiowa.edu!math.ohio-state.edu!news.cis.ohio-state.edu!news.ems.psu.edu!newsfeed.stanford.edu!remarQ73!supernews.com!remarQ.com!remarQ69!news.remarQ.com!xjustdavex From: David Miller Newsgroups: comp.sys.apple2.programmer Subject: Re: GSoft BASIC question Date: Mon, 12 Apr 1999 17:12:10 -0400 Organization: Posted via RemarQ Communities, Inc. Lines: 23 Message-ID: <120419991712109737%xjustdavex@glis.net> References: <7esp0s$b98@post.gsfc.nasa.gov> <5xf7h2A.kws@delphi.com> <7ethri$m9l@post.gsfc.nasa.gov> NNTP-Posting-Host: 216.115.80.245 NNTP-Posting-Date: Mon, 12 Apr 1999 21:12:09 GMT X-Trace: 923951529.542.72 ZZYOAESJW50F5D873C usenet1.supernews.com X-Complaints-To: newsabuse@remarQ.com MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 8bit Mail-Copies-To: nobody User-Agent: YA-NewsWatcher/4.2.2 Xref: news1.icaen comp.sys.apple2.programmer:10502 In article <7ethri$m9l@post.gsfc.nasa.gov>, Geraldine Wright wrote: > Yes. I used the source code for the GameTool tool as a pattern for my > tool, as well as consulting the Toolbox references. Since I am able to > retrieve values from functions that return something, I believe I have > navigated the 2 return addresses issue correctly. What I have not mastered > is getting a passed parameter to the functions that require input. It > seems to bomb, whether I even try to use the passed value or not. Just the > process of getting the value to the function isn't working. There must be > something I am missing. I haven't looked at user tools for GSoft yet, so I'm not sure how things are being passed, but if it's using C-style parameter passing, than your assembly routines need to expect something to be passed, and pass something back, whether or not they really need to. If you are not returning anything, just return a NULL. On the other hand, if it's not using C-style parameter passing, than you can ignore everything I just said. :) -- Dave Miller - remove the x's to reply Path: news1.icaen!news.uiowa.edu!NewsNG.Chicago.Qual.Net!129.79.6.160!news.indiana.edu!logbridge.uoregon.edu!newsfeed.berkeley.edu!intgwpad.nntp.telstra.net!vic.nntp.telstra.net!not-for-mail From: Peter Watson Subject: Re: GSoft BASIC question Newsgroups: comp.sys.apple2.programmer References: <7esp0s$b98@post.gsfc.nasa.gov> <5xf7h2A.kws@delphi.com> <7ethri$m9l@post.gsfc.nasa.gov> User-Agent: tin/pre-1.4-980226 (UNIX) (Linux/2.0.30 (i586)) Lines: 24 Message-ID: <%0FQ2.19$wh2.824@vic.nntp.telstra.net> Date: Tue, 13 Apr 1999 10:30:19 GMT NNTP-Posting-Host: 203.8.161.1 X-Complaints-To: abuse@telstra.net X-Trace: vic.nntp.telstra.net 923999419 203.8.161.1 (Tue, 13 Apr 1999 20:30:19 EST) NNTP-Posting-Date: Tue, 13 Apr 1999 20:30:19 EST Organization: Customer of Telstra Big Pond Direct Xref: news1.icaen comp.sys.apple2.programmer:10503 Geraldine Wright wrote: >In article <5xf7h2A.kws@delphi.com>, kws@delphi.com says... >>Have you examined the _source_ for the included tools and/or read >>your Toolbox books? There are a few fine points for writing tools, >>such as 2 return addresses on the stack (which would affect where you >>think passed parameters are, and where to store results). > >Yes. I used the source code for the GameTool tool as a pattern for my >tool, as well as consulting the Toolbox references. Since I am able to >retrieve values from functions that return something, I believe I have >navigated the 2 return addresses issue correctly. What I have not mastered >is getting a passed parameter to the functions that require input. It >seems to bomb, whether I even try to use the passed value or not. Just the >process of getting the value to the function isn't working. There must be >something I am missing. I'm at work, and it's been a long time to do this from memory, but don't you actually have to remove the input parameters from the stack before returning? This would explain why you can return values if there are no input parameters. -- Peter Watson -- Write to MSDOS disks on the Apple IIgs? -- Impossible! ;-) Path: news1.icaen!news.uiowa.edu!NewsNG.Chicago.Qual.Net!198.87.88.26!news.altair.com!news.kodak.com!news-nysernet-16.sprintlink.net!news-east1.sprintlink.net!news-peer-europe.sprintlink.net!news.sprintlink.net!Sprint!netnews.com!europa.clark.net!209.150.97.11!feeder.qis.net!newsfeed.nyu.edu!newsmaster.cc.columbia.edu!osiris.giss.nasa.gov!newsfeed.gsfc.nasa.gov!usenet From: Geraldine.A.Wright.1@gsfc.nasa.gov (Geraldine Wright) Newsgroups: comp.sys.apple2.programmer Subject: Re: GSoft BASIC question Date: 13 Apr 1999 12:49:03 GMT Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Lines: 17 Message-ID: <7evefv$ho6@post.gsfc.nasa.gov> References: <7esp0s$b98@post.gsfc.nasa.gov> <5xf7h2A.kws@delphi.com> <7ethri$m9l@post.gsfc.nasa.gov> <%0FQ2.19$wh2.824@vic.nntp.telstra.net> NNTP-Posting-Host: gerryw.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: Text/Plain; charset=US-ASCII X-Newsreader: WinVN 0.99.7 Xref: news1.icaen comp.sys.apple2.programmer:10504 In article <%0FQ2.19$wh2.824@vic.nntp.telstra.net>, NOpawSPAM@NOpa.ausom.net.auSPAM says... >I'm at work, and it's been a long time to do this from memory, but don't >you actually have to remove the input parameters from the stack before >returning? This would explain why you can return values if there are no >input parameters. Yes, and that turned out out be my mistake. I fixed the functions that require an input so they remove the input from the stack before returning to the calling program. Things seem to be working now. -- --------------------------------------- Geraldine Wright (the Applesoft-aholic) Geraldine.A.Wright.1@gsfc.nasa.gov --------------------------------------- "Big, fat hairy deal!" -Garfield Newsgroups: comp.sys.apple2.programmer Subject: Re: GSoft BASIC question From: dempson@actrix.gen.nz (David Empson) Date: Wed, 14 Apr 1999 02:18:42 +1200 Message-ID: <1dq8ai8.1a3u1a1j06ekgN@dempson.actrix.gen.nz> References: <7esp0s$b98@post.gsfc.nasa.gov> Organization: Empsoft X-Newsreader: MacSOUP 2.3 NNTP-Posting-Host: 202.49.157.176 X-Trace: 14 Apr 1999 02:17:49 NZST, 202.49.157.176 Lines: 104 Path: news1.icaen!news.uiowa.edu!NewsNG.Chicago.Qual.Net!128.174.5.49!vixen.cso.uiuc.edu!logbridge.uoregon.edu!ihug.co.nz!news.iprolink.co.nz!news.actrix.gen.nz!dempson Xref: news1.icaen comp.sys.apple2.programmer:10505 Geraldine Wright wrote: > I am attempting to write a user tool for use with GSoft so I can make use > of some simple machine language routines in my programs. [snip] > All the ones that fail are FUNCTION's that require an input. I've been reading the replies so far, and it sounds like everyone is thinking on the right track. I have definitely looked at source (or at least disassemblies) for user toolsets, and I have a vague recollection that I started writing one myself a fair while ago (god knows what it did, though). I'm not at all familiar with how GSoft lets you access the toolbox, but I assume it gives you some way of prototyping toolbox functions and specifying the toolset and call number (which gets loaded into X). Anyway, lets see if I can give you a working example of a very simple tool call, which accepts a word-sized parameter and returns a word-sized result. All the function does is to increment the argument by 1. In C, this function would be defined: pascal word ExampleCall(word argument); On entry to the call, the stack looks like this: |--------------| | space for | | result | <-- SP + 9 |--------------| | argument | | | <-- SP + 7 |--------------| | return | | address | | #1 | <-- SP + 4 |--------------| | return | | address | | #2 | <-- SP + 1 |--------------| <-- SP You need to process the argument, store the result, and remove the argument from the stack before returning. For this example, I'll use stack-relative addressing. In a more complex case, you'll probably find it easier to move the stack pointer into the direct page register and refer to the parameters via direct page addressing mode. ExampleCall lda 7,s ; Fetch the argument inc ; Add one sta 9,s ; Store the result * Now we need to delete the argument, shuffling six bytes up the * stack. Note that this must be done in the right order, or you'll * end up copying the same pair of bytes into each of the three words. lda 5,s sta 7,s ; Start at the top lda 3,s sta 5,s ; and work down lda 1,s sta 3,s ; to the bottom pla ; Arbitrary - removes two bytes from the stack * Set up the error result and return clc lda #0 rtl If you have more than one argument, the main point to consider is that the arguments are pushed onto the stack left to right, so the first argument is at the highest address (furthest from the stack pointer). > I am using Merlin 8/16 for my assembly and linking. I instruct the linker > to make the OMF segment segment of Kind $00. Using a block editor, I have > compared my user tool with the GameTool tool which comes with GSoft to see > if I can spot any obvious differences. The only difference I can really > spot is that the GameTool has a segment for calling the ExpressLoader Not exactly. It probably has an ExpressLoad segment first. This just lets the system load the file faster, if you are running under System 5.0 or later. An ExpressLoad segment is optional, and it doesn't contain any code, just easier to process relocation data. I wouldn't expect this to affect anything. In Merlin, there might be a utility to create an expressload segment. There was such a utility with APW 1.1 and/or later versions of ORCA/Shell, called "Express". Eventually the ORCA linker supported it directly. I have a vague idea that Merlin 16+ has a linker option to do this, but I can't be sure of that. (Boy I'm getting rusty! It is at least three and probably four years since I wrote any code on the IIgs, and probably longer since I last used Merlin.) -- David Empson dempson@actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand