[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'Hello world' for monitor mode and an assembler?



Alistair J Ross (mail@ataliross.co.uk) wrote:

: Anyway, here is Michael's (thank you!) earlier 'Hello World!' program:

: On Wed, 08 Sep 2004 19:28:08 +0000, Michael J. Mahon wrote:

: > 300: ldy #0
: >  lda 320,y
: >  jsr fded
: >  iny
: >  cpy #d
: >  bne 302
: >  jsr fd8e
: >  rts

: I tapped it in and got it working just fine. This is what I made out of
: it:

: 300: ldy #0  	; y register (index) set equal to 0 
: 302: lda 320,y	; place contents of $320 into the y register 

Correction:  Place contents of $320+y into Accumulator

: 305: jsr fded	; jump to subroutine at $fded (for outputting text)

$FDED calls the internal COUT routine which outputs the character in the
Accumulator as a single byte character on what UNIX people would call
"STDOUT".  Technically, it's the routine at CSW.  For now that means the
screen...but if you'd hooked to another output device, COUT would send
characters there with no further action required on your part.
 
: 308: iny	; increment y register (index) 
: 309: cpy #d	; compare y register -has loop gone on for #d ? 
: 30B: bne 302	; branch not equal. Branch to $302
: 30D: jsr fd8e	; jump to subroutine at $fd8e 
: 310: rts	; return from subroutine
: 	...

:       1  2  3  4  5  6  7  8  9  a  b  c  d
: 320: c8 e5 ec ec ef ac a0 f7 ef 42 ec e4 a1   === $d
:       H  e  l  l  o  ,     w  o  r  l  d  !


: Here are the things which I can't quite understand yet:

: 30B: bne 302	; branch not equal. Branch to $302

: I understand this quite well, it is basically a goto. It goes to $302 to
: perform a loop to print out the whole 'string' of characters. However, Why
: is is bne? What makes it 'not-equal'? Is it the value of $y to #d? If so,
: how does bne work this out?

It's not so much a GOTO as an IF...THEN.  Specifically, IF the result of
the compare operation is NOT EQUAL to zero, then branch to $302.  If the
value of Y is #$0D, then the compare would result in Y-#$0D=0 so the zero
flag would be set.  No, you can't get the result of Y-#$0D with a CMP; you
just get a flag that says it's equal or it's not.

: 30D: jsr fd8e	; jump to subroutine at $fd8e

: Okay, I understand that a subroutine is at $fd8e, but what's it doing, and
: more importantly, how can I find out what all the other subroutines in the
: Monitor / Basic routines are (as I note from the Apple II reference guide
: that 56k - 64k or E000-FFFF is used for just this). Line number 305 also
: goes to FDED, which I someone else said is used to display characters. How
: does a mere mortal know that these areas in memory do such wonderful
: things?!

I've got a list around here somewhere...Apple very nicely documented a
bunch of these machine language entry points.  I can't find my good
references right now, but I am guessing that's a call to CROUT, which
sends a carriage return to the current output device.  It would make sense
that I don't recognize it as I never use CROUT; instead I put a #$8D into
the Accumulator and call COUT...which accomplishes the same thing.

: 310: rts	; return from subroutine

: Next up is the final line of the main code - what subroutine are we
: returning from here? Is it the one from 30D above? (I would have logically
: thought a return would be issued up near FD8E).

We're returning from whatever routine called our routine.  If you run it
via the Monitor, using 300G, then it's the Monitor's command parser.  If
you run it from Applesoft, then it's Applesoft's command parser.  If from
another assembly routine, then from whatever did a JSR $0300.  If you
really want to know, you could pop it off the stack and look.

In higher level languages, programs have starting and ending points.  That
isn't true for assembly language routines, because the assembly is always
called by something, and it always has someplace to go when it finishes,
unless the program ends by locking up the machine.

: On to my final point, about inputting text:

: > This problem can be simplified on a IIgs by using the ASCII input mode
: > of the monitor, like this:
: > 
: > 320:"Hello, world!"
: > which is quite convenient, or a similar mode on the enhanced //e
: > monitor, like this:
: > 
: > 320:'H 'e 'l 'l 'o ', '  'w 'o 'r 'l 'd '!

: I am now an owner of a //e and have been using it for 2 days.
: Before I was just using a ][+, so now can I access this 'enhanced'
: monitor? So far, the only way I have been able to use the mini-assembler
: is to load up my system master dos disk, and then do 'load applesoft' at
: the ] prompt. Then doing a call-151 and then an F666G. Certainly typing
: the text in as above would be a lot easier than looking up the hex for
: each char. I have printed off the ascii table but it's still a bit slow to
: do!

When you start up your //e, how does it identify itself on the very first
splash screen? Does it call itself an "Apple ][", or does it call itself an
"Apple //e"?  If it says, "Apple ][", then you have an original Apple ][e,
and you can only get to the Mini Assembler via Integer BASIC. 
Incidentally, if you boot the System Master, you need not "LOAD
APPLESOFT".  Instead, just do an INT at the ] prompt, then a CALL -151
from the > prompt.

If your machine calls itself an "Apple //e", then you have the "enhanced"
Apple //e with the 65C02 CPU and a different set of ROMs.  On that one,
boot any disk you like, do NOT switch to Integer BASIC (as that switches
out the built-in ROM), type "CALL -151" at the ] prompt, then "!" at the *
prompt to get to the Mini-Assembler.

: I will get using a proper assembler at some point as I immediately see the
: benefit of using one. I have tapped this program into merlin, as I say and
: I did see how everything fitted in easier - less manual calculation, but
: for now, for the real learning curve, I'll do it all the old fashioned way
: to make sure I have the best understanding.

Have fun!

--Dave Althoff, ][.
-- 
    /X\        _       _               _  *** Have fun.  Be safe. ***
   /XXX\      /X\     /X\_      _     /X\__      _     _        _____
  /XXXXX\    /XXX\  _/XXXX\_   /X\   /XXXXX\    /X\   /X\      /XXXXX
_/XXXXXXX\__/XXXXX\/XXXXXXXX\_/XXX\_/XXXXXXX\__/XXX\_/XXX\_/\_/XXXXXX