[Coco] OS9 HEX to DECIMAL conversion.

coco at jechar.ca coco at jechar.ca
Sat May 26 20:46:14 EDT 2018


Well I have a version that solves my original problem although
I would like to add a few more features yet.

{ SOURCE FOLLOWS }

PROCEDURE Ih_drv
PARAM a:STRING[4];b:STRING[4]
DIM hs:STRING
DIM drv:INTEGER
DIM dno:REAL
DIM yh:REAL
DIM yl:REAL
DIM y:REAL
DIM yhi:INTEGER
DIM yhp:REAL
DIM ylr:REAL
DIM yli:INTEGER
DIM bfile:STRING[16]
DIM cfile:STRING[16]
DIM current:STRING[10]
DIM fp1:BYTE
DIM fp2:BYTE
DIM er:INTEGER
DIM wpc:STRING
DIM ofs:STRING
hs="$"
IF  a="-?" THEN
   PRINT "Ih WPC & Ofs Prameter Calculator"
   PRINT
   PRINT "Assumes Drive Zero Offset=$52DDC"
   PRINT
   PRINT "SYNTAX:"
   PRINT "ih_drv -?  This help message."
   PRINT "ih_drv n   Where n is a number sets the dmode"
   PRINT "           of /ih for drive number n."
   PRINT
   PRINT "(c) CC - GNU"
   END
ENDIF
bfile="/dd/SYS/ihbase"
ON ERROR GOTO 139
OPEN #fp1,bfile:READ
PRINT "Alternate Base Extended Offsets"
PRINT "To be Supported in Future Versions"
GOTO 139
REM Untill we suport alternate base offsets.
GOTO 200
REM If a alternate offset base is loaded skip the standard base.
139  er:=ERR
REM  Standard Cloud9 CF card offset to HBD Drive 0.
      yh=VAL("$52")
      yl=VAL("$DDC")
200 REM
PRINT
drv=VAL(a)
dno=FLOAT(drv)
y=yh*4096.0+yl+(dno*630.0)
yhi=FIX(((y/4096)-0.5))
yhir=FLOAT(yhi)
yhp=yhir*4096.0
ylr=y-yhp
yli=FIX(ylr)

cfile="/dd/SYS/cihxofs"
ON ERROR GOTO 300
OPEN #fp2, cfile:UPDATE
GOTO 400
300 er:=ERR
REM If it does not exist create it.
SHELL "echo>"+cfile
400 REM
PRINT
PRINT USING "S,H3,H3",hs,yhi,yli
PRINT #fp2 USING "S,H3,H3",hs,yhi,yli
PRINT
SEEK #fp2,0
READ #fp2,current
wpc=MID$(current,2,2)
ofs=MID$(current,4,4)
PRINT "WPC = ",wpc
PRINT "OFS = ",ofs
SHELL "dmode /ih wpc="+wpc+" ofs="+ofs
PRINT
PRINT "/ih setup for drive #",a
REM - Future enhancement b= -d SHELL "dir /ih"
END

{ Source Block End }

I put this in the file ih_drv.b09 and when I load
it I get an error.

.b09
^
Ih_drv
ERROR #110
Ready

Ignored the error and Packed it anyway and the program
works fine.

To all who have helped so far Wayne,Curtis,James ect. Thank You
the program is very useful to me.

However I would like to add 3 features yet more for general benefit then 
my own.

1. I would like just typing ih_drv to give help just like
    ih_drv -?

2. I would like ih_drv n -d
    to display the directory of drive n by spawning dir or
    rsdos as appropriate.

3. For me the Hard coded address of drive zero is ok but people
    with other IDE systems may not have there drive zero at address
    $052DDC as I do. I would like to have the program read it's
    drive base address from a file called /dd/SYS/ihbase

Any suggestions would be appreciated, I have attemped 1. and 2. and ran 
into problems.

On 2018-05-24 14:03, Wayne Campbell wrote:
> Glad it helped you. Note that in Basic09 comments can be entered 3
> ways:
> 
> ! at the beginning of a line, will be converted to REM by Basic09
> REM at the beginning of a line
> (* at the beginning of a line, will not be changed by Basic09
> 
> You can add a comment after a instruction on the same source line by
> using the \ statement concatente character. Ex: PRINT myFile \ ! This
> is a file name including full pathlist
> 
> Lastly, there is no *) comment character. Basic09 does not have block
> comments, and the *) characters are added by the programmer to
> simulate a block style comment. I use (* *) on most of the comments I
> put in my code that span multiple lines, but each line must start with
> (* to be recognized by Basic09 as a comment line. For comments on the
> same line as a instruction statement I use either ! or (*, but the
> latter without the *) closing characters.
> 
> As for your next question, I am unable to answer that. Perhaps someone
> else on this list can answer it for you.
> 
> On May 24, 2018 10:21 AM, <coco at jechar.ca> wrote:
> 
>> Thanks for the programming example
>> 
>> Thanks to the "dw s l 'serverpath'" command I was able to
>> cut and paste your code from my email to a file and upload
>> it easy.
>> 
>> I needed to make some small changes to make it work the
>> revised code below.
>> 
>> PROCEDURE texist
>> REM Example Provided by Wayne Campbell
>> 
>> DIM myFile:STRING[80]
>> DIM path:BYTE
>> DIM er:INTEGER
>> myFile="/DD/myDir/myFile"
>> 
>> ON ERROR GOTO 200
>> OPEN #path, myFile:READ
>> REM (* READ mode prevents accidental writes or updates *)
>> 
>> CLOSE #path
>> PRINT myFile; " exists"
>> END
>> 200 er:=ERR
>> IF er=216 THEN
>> PRINT myFile; " does not exist"
>> ENDIF
>> END
>> 
>> Now one more question. Is there a test that can be done
>> from basic09 to determine if a drive is OS9, RSDOS or something else
>> ?
>> 
>> On 2018-05-23 16:04, Wayne Campbell wrote:
>>> The way to check a file's existence is to try to open it. Using an
>>> error trap you can test for a 216 (file not found) error if
>> opening it
>>> fails. If it exists it will be open, so if you don't want it open
>> you
>>> need to close it. Example:
>>> 
>>> DIM myFile:STRING[80]
>>> DIM path:BYTE
>>> DIM er:INTEGER
>>> 
>>> myFile:="/DD/myDir/myFile"
>>> 
>>> ON ERROR GOTO 200
>>> OPEN #path, myFile:READ (* READ mode prevents accidental writes or
>>> updates
>>> CLOSE #path
>>> PRINT myFile; " exists"
>>> END
>>> 200 er:=ERR
>>> IF er=216 THEN
>>> PRINT myFile; " does not exist"
>>> ENDIF
>>> END
>>> 
>>> On Wed, May 23, 2018, 9:42 AM <coco at jechar.ca> wrote:
>>> 
>>>> Thanks very much for the help. The main thing I wanted to do
>>>> is now done however I have some Ideas to make my program better
>> and
>>>> more
>>>> flexible. Do you know if there is a way
>>>> in basic09 to check weather or not a file exists ?
>>>> 
>>>> On 2018-05-21 14:14, Wayne Campbell wrote:
>>>>> I have to check to be sure, but I believe you can't pass
>>>> parameters
>>>>> from the command line to unpacked procedures in Basic09. You
>> must
>>>> pack
>>>>> the procedure first, then launch the procedure from the command
>>>> line.
>>>>> Examples:
>>>>> 
>>>>> OS9:MyProc 12 3
>>>>> 
>>>>> or
>>>>> 
>>>>> OS9:RunB MyProc 12 3
>>>>> 
>>>>> The syntax for parameter statements is:
>>>>> 
>>>>> PARAM myVar:STRING[; myVar2:STRING[128]; myVar3:INTEGER; etc.]
>>>>> 
>>>>> To run the procedure in Basic09's workspace, launch Basic09 from
>>>> the
>>>>> command line, load the procedure source file, then use the run
>>>> command
>>>>> within Basic09:
>>>>> 
>>>>> B:run myProc("myVar", "myVar2")
>>>>> 
>>>>> Within Basic09 you can pass parameters of all atomic types
>> (except
>>>>> BYTE type):
>>>>> 
>>>>> B:run myProc(12, 45.6,TRUE,"myString")
>>>>> 
>>>>> Hope this helps. If you still have questions, I will answer them
>>>> as
>>>>> best I can. If something isn't clear, ask again.
>>>>> 
>>>>> Wayne
>>>>> 
>>>>> On Mon, May 21, 2018, 8:34 AM <coco at jechar.ca> wrote:
>>>>> 
>>>>>> So based on what you said I tryed
>>>>>> 
>>>>>> PROCEDURE add
>>>>>> PRAM as:STRING
>>>>>> PRAM bs:STRING
>>>>>> a=VAL(as)
>>>>>> b=VAL(bs)
>>>>>> print a+b
>>>>>> END
>>>>>> 
>>>>>> Still dosn't work what is the PRECISE syntax for PARAM
>>>>>> and when I call the routine will
>>>>>> 
>>>>>> basic09 add 5 8
>>>>>> 
>>>>>> be okay or do I need to call as
>>>>>> 
>>>>>> basic09 add "5" "8"
>>>>>> 
>>>>>> On 2018-05-20 20:33, Wayne Campbell wrote:
>>>>>>> As the first response to your email says the key word is
>> PARAM,
>>>>>> not
>>>>>>> PARAMETER. Also, if you're using nitros9 and shell+, the
>>>>>> parameters
>>>>>>> will be
>>>>>>> passed as strings. You will have to use string parameters to
>>>>>> receive
>>>>>>> the
>>>>>>> numbers and then convert those strings to actual numbers. Also
>>>>>> again,
>>>>>>> DIMing parameters or variables requires the use of type
>>>>>> identifiers.
>>>>>>> These
>>>>>>> are Atomic types, unless you have defined a complex type.
>> Atomic
>>>>>> types
>>>>>>> are:
>>>>>>> 
>>>>>>> REAL
>>>>>>> INTEGER
>>>>>>> BOOLEAN
>>>>>>> BYTE
>>>>>>> STRING
>>>>>>> USER DEFINED (COMPLEX TYPE)
>>>>>>> 
>>>>>>> STRING without a length modifier defaults to 32 characters.
>> Use
>>>>>>> STRING[size] to set a length from 1 to 32767 (max length).
>>>>>>> 
>>>>>>> 
>>>>>>> On Sun, May 20, 2018, 2:51 PM <coco at jechar.ca> wrote:
>>>>>>> 
>>>>>>>> Thanks for the Info.
>>>>>>>> 
>>>>>>>> For my problem with HEX calculations I have found a solution
>>>>>>>> Involving breaking the number into 2 sets of three Hex digits
>>>> and
>>>>>> 
>>>>>>>> using
>>>>>>>> FLOAT and FIX to convert to REAL for the Math and then back
>> to
>>>>>> Integer
>>>>>>>> to PRINT USING H3.
>>>>>>>> 
>>>>>>>> I an ready to go on to the next step where I want to pass
>>>>>>>> parameters from the command line to my program, so not having
>>>>>> written
>>>>>>>> basic09 code in 15 years I looked for a sample program from
>>>> the
>>>>>>>> manual.
>>>>>>>> 
>>>>>>>> The program I found I have listed below.
>>>>>>>> 
>>>>>>>> PROCEDURE add
>>>>>>>> PARAMETER a,b
>>>>>>>> PRINT a+b
>>>>>>>> END
>>>>>>>> 
>>>>>>>> This is exactly as I wrote it as I used list add>/p
>>>>>>>> to send it to a file on my PC and then cut and pasted it into
>>>>>>>> this email.
>>>>>>>> 
>>>>>>>> But something is wrong as I get these errors.
>>>>>>>> 
>>>>>>>> add
>>>>>>>> PARAMETER a,b
>>>>>>>> ^
>>>>>>>> ERROR #027
>>>>>>>> ERROR #051
>>>>>>>> Ready
>>>>>>>> B:
>>>>>>>> 
>>>>>>>> 
>>>>>>>> Help Please!
>>>>>>>> 
>>>>>>>> On 2018-05-19 20:39, L. Curtis Boyle wrote:
>>>>>>>>> Discord is an app (available for multiple platforms, or
>>>> through
>>>>>> a web
>>>>>>>>> browser), which you can get here:
>>>>>>>>> https://discordapp.com
>>>>>>>>> 
>>>>>>>>> Then, find the server “TRS-80 CoCo TALK”.
>>>>>>>>> 
>>>>>>>>> L. Curtis Boyle
>>>>>>>>> curtisboyle at sasktel.net
>>>>>>>>> 
>>>>>>>>>> On May 19, 2018, at 3:30 PM, coco at jechar.ca wrote:
>>>>>>>>>> 
>>>>>>>>>> Thanks for the Info it is giving me some ideas about what I
>>>>>> may have
>>>>>>>>>> to do to deal with these calculations.
>>>>>>>>>> 
>>>>>>>>>> What URL is "Discord" at ?
>>>>>>>>>> 
>>>>>>>>>> On 2018-05-16 14:41, L. Curtis Boyle wrote:
>>>>>>>>>> Your error is due to pushing beyond the signed 16 bit
>> limits
>>>>>> of the
>>>>>>>>>> hex routines in BASIC09. It does work fine within 16 bit
>>>>>> signed
>>>>>>>>>> values
>>>>>>>>>> (I put some screenshots of test source code, and a sample
>>>> run,
>>>>>> in
>>>>>>>>>> the
>>>>>>>>>> BASIC09 section on Discord).
>>>>>>>>>> On May 16, 2018, at 12:19 PM, James Jones
>>>>>> <jejones3141 at gmail.com>
>>>>>>>>>> wrote:
>>>>>>>>>> Tried it out. VAL("$61A80") gives an error 67, "illegal
>>>>>> argument".
>>>>>>>>>> VAL("A80") prints as 2688., so VAL() returns a REAL, which
>> I
>>>>>> guess
>>>>>>>>>> it has
>>>>>>>>>> to for consistency with other BASICs. Hex PRINT USING
>> output
>>>>>> claims
>>>>>>>>>> to be
>>>>>>>>>> fine with printing a REAL, but perhaps the VAL() code for
>> hex
>>>>>>>>>> doesn't
>>>>>>>>>> handle values that won't fit in an INTEGER. (What's 61A80?
>>>>>> 400000 in
>>>>>>>>>> hex.)
>>>>>>>> 
>>>>>>>> --
>>>>>>>> Coco mailing list
>>>>>>>> Coco at maltedmedia.com
>>>>>>>> https://pairlist5.pair.net/mailman/listinfo/coco
>>>>>>>> 


More information about the Coco mailing list