[Coco] OS9 HEX to DECIMAL conversion.

L. Curtis Boyle curtisboyle at sasktel.net
Sun May 27 12:05:28 EDT 2018


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"
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
> 



More information about the Coco mailing list