Sponsored by BoysStuff.co.uk




           Hardware Access Using AmigaBASIC And ARexx Interpreters.
           --------------------------------------------------------

  This is an introductory notice that as from 'www.thecryptmag.com',
  Issue 54, there are going to be articles about HW access using nothing
  more than the two main interpreters released free as part of the OSs of
  the day...

                             AmigaBASIC and ARexx.

  (Note, NOT ABasic; although YOU could experiment with this by converting
  ANY existing AmigaBASIC code to suit and passing on your modified code to
  be printed in the magazine at a later date. :)

  AmigaBASIC, written by Microsoft, is the more powerful of the two as you
  can generate your own simple GUI without any special extras. ARexx on
  the other hand requires special libraries to generate GUIs and other
  things we take for granted when coding in AmigaBASIC.

  There will also occasionally be ACE Basic Compiler code, Assembler code,
  Python code, C(++) code and many others IF these are needed or to show
  other methods for meeting the required performance for each step.

  I will try to use ANY code where the compiler/interpreter is available
  'FREE' on AMINET so that NO real expenditure will be required.

  For example VBCC or Dice-C, C(++) Compilers, A68K assembler for 68000
  instruction set and maybe 68020 instruction set and blink the linker.
  At the moment though these extra coding formats will be optional.

  As we get further into any HW access I will describe a project, either
  NEW or an existing one of my own to show the potential of the 'obsolete'
  classic AMIGA.

  The first in this issue is 'Port-Access.bas' and 'Port-Access.rexx' for
  the above interpreters. The code is inside the article(s) for both
  formats AND will be able to be downloaded from AMINET in the forseeable
  future. HW_ACCESS_STARTER is a taster for future articles, describing
  the above port accesses in this magazine, Issue 53. From Issue 54 we
  will be starting the hardware access proper. There WILL be pauses from
  the series for other projects or AMIGA related things that may be of
  more interest to you.

  HW_ACCESS_PART1 will be the first of the main series of articles in the
  magazine Issue 54.

  Now get out your ancient A500 or bigger and let it start doing some real
  work without tying up current, serious technology, PCs that are totally
  inaccessable to the electronics hobbyist these days.

  Have fun and enjoy finding simple solutions to often difficult problems.

============================================================================

                             Port Access Notes.
                             ------------------

  ~Port_Access.b~ is an AmigaBASIC program AND ~Port_Access.rexx~ an ARexx
  script to access:-

  1) The Parallel Port directly and write 8 bit data to it.
  2) The Parellel Port directly and read 8 bit data from it.
  3) The Games Port and write ones and zeros to Pin 6 of that port.
  4) The Games Port and read the state of Pin 6 of that port.
  5) Turning the audio filter off and simultaneously dimming the power lamp.
  6) Turning the audio filter on and brightening up the power lamp.

  These are working example scripts to show that direct hardware access
  is easily possible without the need for compilers of any sort.

  As both interpreters are part of various AMIGA OSs then you can experiment
  with these scripts to access other parts of the same hardware AND/OR other
  hardware that exists inside ANY classic AMIGA.

  Note that these scripts DO NOT work under (Win)UAE so don't bother trying.

  The AmigaBASIC version was originally sent to ~AIO~ and was published
  in that ~online~ mag' of the day BUT for some unforseen reason it was
  corrupt and didn't get seen by the AMIGA masses. So now it has been
  re-issued inside this mag'.

  Note, a more full ARexx article can be found on AMINET as:-

                 http://main.aminet.net/dev/src/HW-Access.lha

  OR...


               http://main.aminet.net/util/rexx/HW-ARexx-Hack.lha

  Both are identical.

  WARNING!!! Before trying out these scripts switch OFF the AMIGA and
  disconnect ANYTHING from the Games Port AND Parallel port.

  READ THE ~WARNING.~ SECTION BELOW!!!

----------------------------------------------------------------------------

  The AmigaBASIC Code:-
  ---------------------

REM ***********************************************************************
REM
REM Parallel Port and Games Port access using STANDARD BASIC only.
REM
REM Original (C)1996 B.Walker, (G0LCU).
REM
REM Checked against AmigaBASIC, ACE Basic Compiler, Cursor Basic Compiler,
REM and HiSoft Basic Compiler. Some modifications may be required for the
REM ancient ABasiC Intepreter of Pre-Workbench 1.3x.
REM
REM This is ready for AmigaBASIC, an old style A500 and OS1.3x.
REM
REM ***********************************************************************

REM Set up any string variables.
  LET a$="(C)2001 B.Walker, G0LCU."
REM Set up any numerical variables.
  LET n=0
  LET byteval=0

REM ~CIAA~ address for register ~pra~.
  LET pra=12574721
REM ~CIAA~ address for register ~prb~.
  LET prb=12574977
REM ~CIAA~ address for direction of port ~pra~, (1=OUTPUT).
  LET ddra=12575233
REM ~CIAA~ address for direction of port ~prb~, (1=OUTPUT).
  LET ddrb=12575489

REM Store single byte values of these addresses for future use.
  LET valpra=PEEK(pra)
  LET valprb=PEEK(prb)
  LET valddra=PEEK(ddra)
  LET valddrb=PEEK(ddrb)
REM Bit 0 of port ~ddra~ DO NOT CHANGE...
REM Bit 1 of port ~ddra~ switches the ~LED~ ON or OFF, (1=ON).
REM Bits 2 to 5 inclusive of port ~ddra~ DO NOT CHANGE...
REM Bits 6 and 7 of port ~ddra~ alter PIN 6 of the mouse/games ports, (1=OUTPUT).
REM Port ~ddrb~ controls the parallel port, all bits, (1=OUTPUT).
  LET newvalpra=valpra
  IF newvalpra>=128 THEN LET newvalpra=newvalpra-128
  LET newvalddra=valddra
  IF newvalddra>=128 THEN LET newvalddra=newvalddra-128

REM Initial copyright line.
  CLS
  COLOR 1,0
  LOCATE 2,28
  PRINT a$
  GOTO start1:

REM Simple setup screen.
start:
  CLS
start1:
  LOCATE 5,10
  PRINT "Press ~w~ or ~W~ for writing data bytes to the parallel port."
  LOCATE 7,10
  PRINT "Press ~r~ or ~R~ for reading data bytes from the parallel port."
  LOCATE 9,10
  PRINT "Press ~g~ to read from PIN 6 of the games port only."

  LOCATE 11,10
  PRINT "Press ~G~ to write to PIN 6 of the games port only."
  LOCATE 13,10
  PRINT "Press ~l~ to turn the power light UP or ON."
  LOCATE 15,10
  PRINT "Press ~L~ to turn the power light DOWN or OFF."
  LOCATE 17,10
  PRINT "Press ~q~ or ~Q~ to quit."
  

REM This is the main loop.
mainloop:
  LET a$=INKEY$
  IF a$="w" OR a$="W" THEN GOTO parallelwrite:
  IF a$="r" OR a$="R" THEN GOTO parallelread:
  IF a$="G" THEN GOTO gamesportwrite:
  IF a$="g" THEN GOTO gamesportread:
  IF a$="l" THEN GOSUB lightup:
  IF a$="L" THEN GOSUB lightdown:
  IF a$="q" OR a$="Q" THEN GOTO getout:
  GOTO mainloop:

REM Write byte values to the parallel port.
parallelwrite:
  CLS
  LET n=0
REM Set all bits to outputs.
  POKE ddrb,255
loop1:
  POKE prb,n
  LET byteval=PEEK(prb)
  LOCATE 10,19
  PRINT "Decimal value at the parallel port is";byteval;CHR$(8);".   "

  LOCATE 12,26
  PRINT "Press ~SPACE BAR~ to exit."
  LET a$=INKEY$
  IF a$=" " THEN GOTO start:
  LET n=n+1
  IF n>255 THEN LET n=0
  GOTO loop1:

REM Read byte values from the parallel port.
parallelread:
  CLS
REM Set all bits to inputs.
  POKE ddrb,0
loop2:
  LET byteval=PEEK(prb)
  LOCATE 10,19
  PRINT "Decimal value at the parallel port is";byteval;CHR$(8);".   "
  LOCATE 12,26
  PRINT "Press ~SPACE BAR~ to exit."

  LET a$=INKEY$
  IF a$=" " THEN GOTO start:
  GOTO loop2:

REM Write ~1~s and ~0~s to PIN 6 of the games port.
gamesportwrite:
  CLS
REM Force bit 7 of ~pra~ as an output.
  POKE ddra,(newvalddra+128)
REM Set bit 7 of ~pra~ to a value ~1~.
loop3:
  POKE pra,(newvalpra+128)
  LET n=PEEK(pra)
  LOCATE 8,19
  PRINT "Value should be greater than ~127~:-";n;CHR$(8);".   "
REM Set bit 7 of ~pra~ to a value ~0~.
  POKE pra,newvalpra
  LET n=PEEK(pra)
  LOCATE 10,21
  PRINT "Value should be less than ~128~:-";n;CHR$(8);".   "
  LOCATE 12,26
  PRINT "Press ~SPACE BAR~ to exit."

  LET a$=INKEY$
  IF a$=" " THEN GOTO start:
  GOTO loop3:

REM Read the state of PIN 6 of the games port.
gamesportread:
  CLS
  POKE pra,valpra
  POKE ddra,valddra
loop4:
  LET n=PEEK(pra)
  LOCATE 10,9
  PRINT "Less than ~128~ when PIN 6 of the games port pulled LOW:-";n;CHR$(8);".   "
  LOCATE 12,26
  PRINT "Press ~SPACE BAR~ to exit."
  LET a$=INKEY$
  IF a$=" " THEN GOTO start:
  GOTO loop4:

REM Turn the POWER light UP or ON.
lightup:
  POKE ddra,valddra
  POKE pra,252
  RETURN

REM Turn the POWER light DOWN or OFF.
lightdown:
  POKE ddra,valddra
  POKE pra,254
  RETURN

REM Exit routine.
REM Reset all of the ports back to their original state.
getout:
  POKE pra,valpra
  POKE prb,valprb
  POKE ddra,valddra
  POKE ddrb,valddrb
  END

----------------------------------------------------------------------------

  The ARexx code:-
  ----------------

/* ------------------------------------------ */
/* Port-Access.rexx, (C)2004 B.Walker, G0LCU. */
/* ------------------------------------------ */

/* Direct port programming using AREXX. */

/* Set up any constants or variables. */
  mousetrap=1
  portvalue=0
  number='0'
  copyright='9'x'$VER: Port-Access.rexx_Version_0.92.00_20-11-2004_(C)G0LCU.'

/* Use ECHO for ordinary printing to the screen and SAY for printing results. */
  DO FOREVER
    ECHO 'c'x
    SAY copyright
    ECHO 'a'x'd'x'9'x'9'x'1) Read from the parallel port.'
    ECHO '9'x'9'x'2) Write to the parallel port.'
    ECHO 'a'x'd'x'9'x'9'x'3) Read from pin 6 of the games port.'
    ECHO '9'x'9'x'4) Write to pin 6 of the games port.'
    ECHO 'a'x'd'x'9'x'9'x'5) Power light bright or on.'
    ECHO '9'x'9'x'6) Power light dim or off.'
    ECHO 'a'x'd'x'9'x'9'x'7) Quit this program.'
    ECHO 'a'x'd'x'9'x'9'x'Type in a number and then press ENTER/RETURN:-'
    PULL number
    IF number='1' THEN CALL readparallelport
    IF number='2' THEN CALL writeparallelport
    IF number='3' THEN CALL gamesportread
    IF number='4' THEN CALL gamesportwrite
    IF number='5' THEN CALL lighton
    IF number='6' THEN CALL lightoff
    IF number='7' THEN CALL getout
  END

/* Set up the parallel port screen. */
parallelportsetup:
  ECHO 'c'x
  ECHO '9'x'9'x'Open the parallel port for access...'
  ECHO 'a'x'd'x'9'x'9'x'Data direction address is at $BFE301...'
/* Click mouse button to exit. */
  ECHO 'a'x'd'x'9'x'9'x'Click left mouse button to exit...'
/* Access the parallel port directly. */
  ECHO 'a'x'a'x'd'x'9'x'9'x'Data transfer address is at $BFE101...'
  ECHO
  RETURN

/* Set the parallel port for read only. */
readparallelport:
  CALL parallelportsetup
/* Set prarllel port data lines to read. */
  EXPORT('00BFE301'x,'00'x,1)
  portvalue=IMPORT('00BFE101'x,1)
/* Read initial value from parallel port. */
  SAY '9'x'9'x'Value at the port is:- '||C2D(portvalue)||'.   '
/* Parallel port reading. */
  DO FOREVER
    portvalue=IMPORT('00BFE101'x,1)
    SAY 'b'x'9'x'9'x'Value at the port is:- '||C2D(portvalue)||'.   '
/* Click left mouse button to exit. */
    DO FOR 250
      mousetrap=IMPORT('00BFE001'x,1)
      IF BITTST(mousetrap,6)=0 THEN RETURN
    END
  END

/* Set the parallel port to write only. */
writeparallelport:
  CALL parallelportsetup
/* Set prarllel port data lines to write. */
  EXPORT('00BFE301'x,'FF'x,1)
  ECHO '9'x'9'x'Value at the port is:- FFH.'
/* Write to the parallel port. */
  DO FOREVER
/* Write the value 85 decimal, (55 Hexadecimal), to the port. */
    ECHO 'b'x'9'x'9'x'Value at the port is:- 55H.'
    DO FOR 10
      EXPORT('00BFE101'x,'55'x,1)
/* Click left mouse button to exit. */
      mousetrap=IMPORT('00BFE001'x,1)
      IF BITTST(mousetrap,6)=0 THEN RETURN
    END
/* Write the value 170 decimal, (AA Hexadecimal), to the port. */
    ECHO 'b'x'9'x'9'x'Value at the port is:- AAH.'
    DO FOR 10
      EXPORT('00BFE101'x,'AA'x,1)
/* Click left mouse button to exit. */
      mousetrap=IMPORT('00BFE001'x,1)
      IF BITTST(mousetrap,6)=0 THEN RETURN
    END
  END

/* Set up the games port screen. */
gamesportsetup:
  ECHO 'c'x
  ECHO '9'x'9'x'Open the games port for access...'
  ECHO 'a'x'd'x'9'x'9'x'Data direction address is at $BFE201...'
/* Click mouse button to exit. */
  ECHO 'a'x'd'x'9'x'9'x'Click left mouse button to exit...'
/* Access the games port directly. */
  ECHO 'a'x'a'x'd'x'9'x'9'x'Data transfer address is at $BFE001...'
  ECHO
  RETURN

/* Write to pin 6 of the games port. */
gamesportwrite:
  CALL gamesportsetup
/* Set up games port pin 6 for write only. */
  EXPORT('00BFE201'x,'83'x,1)
  ECHO '9'x'9'x'Value at pin 6 is:- 1.'
/* Click left mouse button to exit. */
  DO FOREVER
    ECHO 'b'x'9'x'9'x'Value at pin 6 is:- 0.'
    DO FOR 10
      EXPORT('00BFE001'x,'7C'x,1)
      mousetrap=IMPORT('00BFE001'x,1)
      IF BITTST(mousetrap,6)=0 THEN RETURN
    END
    ECHO 'b'x'9'x'9'x'Value at pin 6 is:- 1.'
    DO FOR 10
      EXPORT('00BFE001'x,'FC'x,1)
      mousetrap=IMPORT('00BFE001'x,1)
      IF BITTST(mousetrap,6)=0 THEN RETURN
    END
  END

/* Read pin 6 of the games port. */
gamesportread:
  CALL gamesportsetup
/* Set up games port pin 6 for read only. */
  EXPORT('00BFE201'x,'03'x,1)
  ECHO '9'x'9'x'Value at pin 6 is:- 1.'
/* Click left mouse button to exit. */
  DO FOREVER
    DO FOR 50
      mousetrap=IMPORT('00BFE001'x,1)
      IF BITTST(mousetrap,6)=0 THEN RETURN
    END
    IF BITTST(mousetrap,7)=0 THEN ECHO 'b'x'9'x'9'x'Value at pin 6 is:- 0.'
    DO FOR 50
      mousetrap=IMPORT('00BFE001'x,1)
      IF BITTST(mousetrap,6)=0 THEN RETURN
    END
    IF BITTST(mousetrap,7)=1 THEN ECHO 'b'x'9'x'9'x'Value at pin 6 is:- 1.'
  END

/* Turn the power light on or up. */
lighton:
  EXPORT('00BFE001'x,'FC'x,1)
  RETURN

/* Turn the power light off or down. */
lightoff:
  EXPORT('00BFE001'x,'FE'x,1)
  RETURN

/* Exit the program safely. */
getout:
  EXPORT('00BFE301'x,'FF'x,1)
  EXPORT('00BFE201'x,'03'x,1)
  EXPORT('00BFE101'x,'FF'x,1)
  EXPORT('00BFE001'x,'FC'x,1)
  ECHO 'c'x
  SAY copyright
  ECHO 'a'x'a'x'a'x'd'x'7'x'9'x'9'x'9'x'Click on CLOSE gadget to Quit.'
  EXIT(0)

----------------------------------------------------------------------------

As a finale there are two more BASIC variants:-

             http://main.aminet.net/dev/amos/HWA_AMOS1-3.lha

For the, (AMOS1.3), AMOS 1.3 INTERPRETER version.

And...

              http://main.aminet.net/dev/basic/HWA-ACE.lha

For the ACE Basic Compiler version.

============================================================================

                                IMPORTANT:-
                                -----------


    The Legal Stuff:-
    -----------------

    These programs are Freeware and no profit will be made from them,
    also all of the files must remain unaltered and intact including this
    one. The author is not responsible for any damage to, or loss of, or
    failure of equipment or data caused in any way by the use of these
    programs. There is NO warranty with the use of these software releases
    and YOU USE THEM AT YOUR OWN RISK.

----------------------------------------------------------------------------

    Testing Evaluation:-
    --------------------

    An A1200(HD) in 2MB, 6MB and 10MB modes using trapdoor memory AND/OR
    PCMCIA memory expansions. Also tested on an A600(HD) in 2MB and 6MB
    modes. All test conditions were/are running STANDARD KS2.0x to 3.1x,
    and using standard ~topaz 8~ fonts throughout.

    I have no idea what a strange configuration setup will create so refer
    to the ~The Legal Stuff~ above.

----------------------------------------------------------------------------

                                 WARNING.
                                 --------

  1) DISCONNECT any faulty equipment under test from the MAINS supply.
  2) If a DC supply is used do NOT reverse polarity the connections.
  3) Do NOT power up any electronic item until it is safe to do so.
  4) CHECK and RECHECK all of your construction and repair work thoroughly.
  5) Handle ALL tools used with care.
  6) Beware of ALL types of solvents, glues and etching fluids.
  7) NEVER leave a soldering iron switched on unattended.
  8) KEEP everything OUT of the reach of small children.
  9) Switch OFF the AMIGA before disconnecting or connecting any hardware.
 10) And finally read 1) to 9) again.

----------------------------------------------------------------------------

   Contact:-
   ---------

   Mr Barry Walker, G0LCU.

   Email:-     wisecracker@tesco.net
   URL:-       http://homepages.tesco.net/wisecracker/G0LCU.HTM

   Author of the ~TestGear?~ projects in the ~docs/hard~ drawer of AMINET.

----------------------------------------------------------------------------

   A very useful HardWare related site, (C) Anthony Hoffman, for
   modifications, schematics, repairs and the like is:-

                          http://amiga.serveftp.net/

============================================================================




RIYAN Productions

AmigaZ Logo
Amiga Roundtable Podcast