💾 Archived View for mirrors.apple2.org.za › archive › ground.icaen.uiowa.edu › MiscInfo › Empson › b… captured on 2024-07-09 at 01:39:29.

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Newsgroups: comp.sys.apple2.programmer
Path: news.uiowa.edu!news.physics.uiowa.edu!math.ohio-state.edu!uwm.edu!lll-winken.llnl.gov!ames!waikato!comp.vuw.ac.nz!actrix.gen.nz!dempson
From: dempson@atlantis.actrix.gen.nz (David Empson)
Subject: Re: Calling ProDOS with assembly language
Message-ID: <DL2Jqq.BGo@actrix.gen.nz>
Sender: news@actrix.gen.nz (News Administrator)
Organization: Actrix - Internet Services
Date: Fri, 12 Jan 1996 12:52:01 GMT
References: <30F5F041.2EB1@postoffice.ptd.net>
X-Nntp-Posting-Host: atlantis.actrix.gen.nz
Lines: 107

In article <30F5F041.2EB1@postoffice.ptd.net>,
Jason A Long  <rajal@postoffice.ptd.net> wrote:
> I'd like to do some machine langauge programming.  I am very familiar
> with Applesoft but I'd like to move on to something faster.  My question
> is, how do I load and save files without Applesoft?  I would appreciate
> just a short segment of code in machine language showing how simple
> operations such as "BSAVE" and "BLOAD" are done.

What environment were you thinking of using?  Are you going to use BIN
files which are executed under BASIC.SYSTEM, or do you want to try
writing a standalone SYS file?

A SYS file has no choice: it must use the ProDOS Machine Language
Interface (MLI).  A BIN file under BASIC.SYSTEM can use the MLI, or it
can make use of BASIC.SYSTEM's mechanism for executing a limited set
of disk commands from a machine code program.

The MLI allows much more flexibility, but generally requires more code
than doing similar operations through BASIC.SYSTEM.

For example, to do the equivalent of a BLOAD would require at least
three (usually four) calls to the MLI: OPEN, possibly GET_EOF, READ and
CLOSE.  If you also wanted to know the auxiliary type (load address),
you would need to make a GET_FILE_INFO call.  Each of these calls
requires a parameter block, most of which could be set up in advance
as pre-initialized variables in your assembly language source code.
(You need to copy some information around after opening the file, e.g.
the reference number.)

By comparison, a BLOAD can be done in a single call to BASIC.SYSTEM,
by setting up the text of the BLOAD command and making the appropriate
call.  (There is a restriction: this facility is only available if the
machine code program is being executed from a CALL or BRUN within a
BASIC program, not directly from the command line.)

Another option is to make MLI calls through BASIC.SYSTEM, using the set
of parameter blocks provided by BASIC.SYSTEM on its global page.  This
doesn't really gain much, but is useful in small programs that don't
want to set aside the memory required for the parameter blocks.
BASIC.SYSTEM can also be used to provide buffering memory for file I/O
buffers.

In all cases, you need to handle error situations yourself.  An error
is indicated by the carry flag being set after the call, with the
error code in the accumulator.  You need to work out what to do about
the error.  If you are using the "pass a command to BASIC" method, you
can make a call to cause the error to be sent back to the controlling
BASIC program, where it can invoke an ONERR GOTO handler, for example.

The "pass a command to BASIC" method doesn't support the following
commands properly: RUN, - (dash), LOAD, CHAIN, READ, WRITE, APPEND,
EXEC.  Other commands should work properly.

> Also, if there are any good reference books available about machine
> language programming and also using ProDOS, please refer me to them.

Just considering ProDOS:

The horse's mouth is Apple's "ProDOS-8 Technical Reference Manual".  It
covers most aspects of using ProDOS from machine language, including
full documentation on the MLI and BASIC.SYSTEM callbacks, how to write
a system program, interrupt handlers, clock drivers, device driver
firmware, etc.  It also has low-level information on the directory and
file structures on disk.

Unfortunately, it isn't available any more.

Two other good books are as follows.  They both cover similar material,
but the former is aimed more at beginners, and the latter more at
advanced programmers (it contains a lot more low-level technical
information).

Apple ProDOS: Advanced Features for Programmers, by Gary B. Little
(Brady books, published in 1985, ISBN 0-89303-441-X).  I doubt this
book is available any more.

Beneath Apple ProDOS, by Don Worth and Pieter Lechner (Quality
Software).  This book IS still available, from Byte Works.  

Of the three books, I'd recommend Gary Little's one for learning how
to program ProDOS, and Apple's manual as a reference once you are
familiar with the concepts involved.  Beneath Apple ProDOS can double
as the reference.

For machine language programming in general: that is a bit harder.

You will NEED a good reference on the processor, and ideally a manual
which covers all of the ROM routines provided by the machine (e.g. the
appropriate Apple technical/firmware reference manual).

A book I found quite good when I was learning machine code programming
was "Programming the Apple II in Assembly Language" by Rodnay Zaks
(Sybex books).  (Actually, I got this book after I'd already taught
myself most of what I needed, but it was still useful.)  This book is
heavily based on Zaks' earlier book "Programming the 6502", which I
also had (but sold after I bought the newer book).  The later book
covers 65C02 programming in detail, as well as many techniques
involved in programming on the Apple II.

Gary Little's "Inside the Apple IIe" is a good source for firmware
documentation (I prefer the official Apple manuals, mainly because
I've had them longer).  It also covers some 6502 basics, but doesn't
go into a lot of detail.
-- 
David Empson
dempson@actrix.gen.nz
Snail mail: P.O. Box 27-103, Wellington, New Zealand
Path: news.uiowa.edu!news.physics.uiowa.edu!math.ohio-state.edu!uwm.edu!post.its.mcw.edu!usenet
From: Ron Kneusel <rkneusel@post.its.mcw.edu>
Newsgroups: comp.sys.apple2.programmer
Subject: Re: Calling ProDOS with assembly language
Date: Fri, 12 Jan 1996 09:30:08 -0600
Organization: Medical College of Wisconsin, General Internal Medicine
Lines: 58
Message-ID: <30F67E80.5485@post.its.mcw.edu>
References: <30F5F041.2EB1@postoffice.ptd.net>
NNTP-Posting-Host: jldh449-1.intmed.mcw.edu
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 2.0b4 (Win95; I)

Jason A Long wrote:
> 
> I'd like to do some machine langauge programming.  I am very familiar
> with Applesoft but I'd like to move on to something faster.  My question
> is, how do I load and save files without Applesoft?  I would appreciate
> just a short segment of code in machine language showing how simple
> operations such as "BSAVE" and "BLOAD" are done.
> 
> Also, if there are any good reference books available about machine
> language programming and also using ProDOS, please refer me to them.
> 
> Thanks in advance,
> Jason A Long

I use a copy of Little's "ProDOS: Advanced Features for Programmers" 
(or similar sounding title)

Basically, you only get BSAVE and BLOAD in ProDOS when you have the
BASIC.SYSTEM file loaded.  With out it you need to use the ProDOS
MLI interface (Machine Language Interface).  It is really pretty easy
to use and includes a bunch of commands for opening files, reading and
writing bytes (or blocks), deleting files, creating files, etc.  With
the MLI you open a file regardless of its type.. it doesn't care.

All the commands work the same way:

JSR MLI  (address is $BF00)
HEX $CA  (single byte command code, $CA = read from open file)
DW  TBL  (lo/hi address of a parameter table used by all commands)
BCS ERR  (return code in A, carry set if an error occured)
..
..
TBL HEX $03   (1st byte always number of parameters in the table)
    HEX $01   (ProDOS file reference number, 1 for first open file (?))
    DW  BUFF  (lo/hi address of data buffer -- receives the bytes read)
    HEX 0000  (# bytes actually read returned here, lo/hi)

N.B. The above is from memory so I'm not responsible of slight inaccuracies!
The general form is correct.

The Little book details all the commands with examples and includes 
examples of device drivers and installing new commands to extend
BASIC.SYSTEM.  I use it extensively as I play around with modifying
QForth which I will eventually get up on my web site:

http://kreeft.intmed.mcw.edu/software.html

Hope this helps a bit.. now you need to find the book!

- Ron

---------------------------------------+----------------------------------
Ron Kneusel, rkneusel@post.its.mcw.edu | http://kreeft.intmed.mcw.edu/ 
For Mac, Apple II, Forth, and CP/M files web or FTP to my homepage!
--------------------------------------------------------------------------
!!! The Phil Keaggy Home Page = http://kreeft.intmed.mcw.edu/phil.html
--------------------------------------------------------------------------
Systems Specialist, GIM-Medical College of Wisconsin, Milwaukee, Wisconsin