[Coco] OS9 HEX to DECIMAL conversion.
James Jones
jejones3141 at gmail.com
Sun Jun 3 17:41:31 EDT 2018
About INPUT #fp1," Reading Zero Drive Base Offset Data ... ",zb ...the
BASIC09 manual says this about the INPUT statement:
When the INPUT statement is encountered, program execution is suspended and
a "?" prompt is displayed. If the optional prompt string is given, it is
displayed instead of the normal "?" prompt. This means that the INPUT
statement is really *both* an input and output statement. Therefore, if a
path other than the default standard input path is used, the path should be
open in UPDATE mode. This makes INPUT dangerous if used on disk files,
unless you like prompts in your data (use READ).
so I'm not sure INPUT is what you want.
On Sat, Jun 2, 2018 at 2:31 PM, <coco at jechar.ca> wrote:
> I have created the Final Version.
> All features implemented, let me know If there are any
> issues I have overlooked.
>
> {SOURCE START}
> PROCEDURE Ih_drv
> DIM hs:STRING
> DIM drv:INTEGER
> DIM dno:REAL
> DIM zb:STRING
> DIM zh:STRING[4]
> DIM zl:STRING[4]
> DIM yhs:STRING
> DIM yls:STRING
> 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
> DIM af:STRING
> DIM al:INTEGER
> DIM ad:STRING[1]
> DIM i:INTEGER
> DIM ta:STRING
> PARAM a:STRING[4];b:STRING[4]
> 10 ON ERROR GOTO 1000
> 20 IF a="-?" THEN
> GOTO 1010
> END
> ENDIF
> REM Constants
> hs="$"
> al=LEN(a)
> af=MID$(a,1,1)
> IF af="=" THEN
> a=MID$(a,2,al)
> al=al-1
> IF al=0 THEN
> END
> ENDIF
> ENDIF
> REM Data Verification
> IF al>=4 THEN
> GOTO 1020
> ENDIF
> FOR i=1 TO al
> ad=MID$(a,i,1)
> IF ((ad<"0") OR (ad>"9")) THEN
> GOTO 1020
> END
> ENDIF
> NEXT i
> bfile="/dd/SYS/ihbase"
> ON ERROR GOTO 139
> OPEN #fp1,bfile:READ
> INPUT #fp1," Reading Zero Drive Base Offset Data ... ",zb
> PRINT "Alternate Base Extended Offset is ",zb
> zh=MID$(zb,1,4)
> zl="$"+MID$(zb,5,3)
> yh=VAL(zh)
> yl=VAL(zl)
> GOTO 200
> END
> 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.
> CREATE #fp2,cfile:UPDATE
> REM Write a default value if the file is empty.
> current="$FFFFFF"
> WRITE #fp2,current
> SEEK #fp2,0
> 400 REM
> 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 - Show Directory
> 500 ON ERROR GOTO 502
> 501 GOTO 503
> 502 END
> 503 REM Process Second Parameter
> IF b="-d" THEN
> GOTO 510
> ELSE
> IF b="-r" THEN
> GOSUB 540
> ENDIF
> ENDIF
> 510 ON ERROR GOTO 520
> SHELL "dir /ih"
> END
> 520 er=ERR
> ON ERROR
> REM - Directory Listing Failed
> IF b<>"-d" THEN
> END
> ENDIF
> PRINT "OS9 Directory Listing Failed."
> 530 INPUT "Do you want to try RSDOS (y/N) ?",ta
> IF ta="y" THEN
> GOSUB 540
> ENDIF
> END
> 540 REM GOSUB - Display RSDOS directtory.
> SHELL "shell x load /dd/util/rsdos"
> SHELL "shell x rsdos -dir /ih"
> RETURN
> 1000 er=ERR
> ON ERROR
> IF er=56 THEN
> PRINT
> ELSE
> END
> ENDIF
> 1010 PRINT " Ih WPC & Ofs Prameter Calculator v2.3"
> PRINT
> PRINT " Default Drive Zero Offset=$52DDC"
> PRINT " Alternate Drive Zero Offset may be set in /dd/sys/ihbase"
> PRINT
> PRINT " SYNTAX:(*Commands shown in UPPER but should be typed in lower
> case. )"
> PRINT " IH_DRV -? This help message."
> PRINT " IH_DRV N Where n is the number that sets the dmode of /ih"
> PRINT " for drive number n."
> PRINT " IH_DRV =N .. "
> PRINT " IH_DRV N -D .. and also lists 'OS9' directory."
> PRINT " IH_DRV N -R .. and also lists 'RSDOS' directory."
> PRINT
> PRINT " (c) CC - GNU Special Thanks to Curtis & Wanye "
> END
> 1020 PRINT ">> n must be 0 to 999 ."
> END
> {SOURCE END}
>
> This Ends this Thread.
>
>
> On 2018-05-28 08:46, coco at jechar.ca wrote:
>
>> On 2018-05-27 12:05, L. Curtis Boyle wrote:
>>
>>> On May 26, 2018, at 6:46 PM, coco at jechar.ca wrote:
>>>
>>>>
>>>> Well I have a version that solves my original problem although
>>>> I would like to add a few more features yet.
>>>>
>>>> […]
>>>>
>>>> I put this in the file ih_drv.b09 and when I load
>>>> it I get an error.
>>>>
>>>> .b09
>>>> ^
>>>> Ih_drv
>>>> ERROR #110
>>>> Ready
>>>>
>>>
>>> If you are trying to run it by typing 'BASIC09 lh_drv.b09’, you will
>>> get errors like that. You need to pack it (which you mentioned that
>>> you have already done), and then run it with either ‘runb lh_drv’ (if
>>> you are using the stock SHELL), or just ‘lh_drv’ (if you are running
>>> Shellplus). It’s easier to pass parameters with Shellplus as well, as
>>> has been mentioned before; you don’t need to surround the parameters
>>> in quotes.
>>> (If you want to avoid that error when loading BASIC09 source, just
>>> launch BASIC09 by itself ‘basic09’, and then LOAD ih_drv.b09 at the B:
>>> prompt).
>>>
>>> I mucked with your code for a bit, and for some strange reason, if I
>>> did ON ERROR to trap a parameter error (#56) to check if no parameters
>>> were sent, it would go to the routine properly, but when I tried to
>>> shut ON ERROR off and then GOTO where you were printing the help
>>> message, it would then exit with the error anyways. I changed the help
>>> message to be a subroutine instead (both from the error 56 ON ERROR,
>>> and from passing it ‘-?’, and now that works (using shellplus). I did
>>> try moving PARAM to after the DIM statements (the examples in the
>>> BASIC09 manual show this), but that made no difference (and I tried a
>>> couple of other things that are still in this listing that follow, but
>>> you can clean those up if you wish). I had to change your creating of
>>> /dd/sys/cihxofs to use CREATE instead of SHELL “ECHO”; otherwise, you
>>> didn’t have a path to the file to write to. I also have it write a
>>> default value so it has something to read (you may need to change that
>>> value).
>>>
>>> PROCEDURE Ih_drv
>>> 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
>>> PARAM a:STRING[4];b:STRING[4]
>>>
>>> 10 ON ERROR GOTO 1000
>>> 20 IF a="-?" THEN
>>> GOSUB 5000
>>> 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.
>>> CREATE #fp2,cfile:UPDATE
>>> REM Write a default value if the file is empty.
>>> REM Change this if needed.
>>> current="0000"
>>> WRITE #fp2,current
>>> SEEK #fp2,0
>>> 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
>>>
>>> 1000 er=ERR
>>> ON ERROR
>>> PRINT "Error #";er;" trapped"
>>> IF er=56 THEN
>>> PRINT "At least 1 parameter is required"
>>> PRINT " use 'ih_drv -?' for help"
>>> GOSUB 5000
>>> END
>>> ENDIF
>>>
>>> 5000 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"
>>>
>> Thanks for the code improvements, I will look them over in a few days,
>> very busy with gardening now, and try out your version.
>> P.S. Yes it's shell plus I am using.
>>
>> RETURN
>>>
>>>
>>>
>>>
>>>
>>>
>>>> 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.
>>>>
>>>> Coco mailing list
>>>> Coco at maltedmedia.com
>>>> https://pairlist5.pair.net/mailman/listinfo/coco
>>>>
>>>>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>
More information about the Coco
mailing list