!pr2
!lm12
!rm75
My Own Little Bell......................Bob Sander-Cederlof

The other day I was working on my Apple at home, and the kids were trying to sleep in the same room.  The program I was working on needed to indicate erroneous input by a bell, and I had to test it.  Suddenly I realized how loud and sharp the Apple bell is!

With all that motivation, I threw together this little routine which makes a soft and pleasant tone to use for my own little bell.  It generates fifty repetitions of a triple-toggle pattern, with time intervals selected for their harmonious character.

Lines 1070, 1170, and 1180 establish a loop equivalent to the Applesoft code:

     FOR X = 50 TO 1 STEP -1: . . . : NEXT

In assembly language it frequently occurs that backwards running loop counts are easier to use than forward ones, and this is just such a case.

Examine lines 1080-1160, and you will see a pattern repeated three times.  In each case I load A with a value, call MON.DELAY, and toggle the speaker.  The value passed to MON.DELAY is first 14, then 10, and then 6.  MON.DELAY is a subroutine in the Apple Monitor ROM which delays an amount of time depending on what value you pass in the A-register, according to the following formula:

     # cycles delay = 2.5*N*N + 13.5*N +13

This includes the six cycles of the JSR used to call the subroutine.  Each cycle is...well, the Apple clock is roughly 1.023 MHz...so a cycle is about .9775 microseconds long.  The counts of 14, 10, and 6 give intervals between toggles of 630.5, 204, and 195 (including the overhead instructions in SC.BELL).

You can play with the values, and try creating your own variations.  You might try adding a fourth toggle per loop, changing the number of loops, changing the delay counts, and so on.  Have fun!
