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

Re: Lo-Res Hijinks ... Enjoy!



"John B. Matthews" <nospam@nospam.com> wrote in message 
nospam-3303F8.23170602062005@news-rdr-01.ohiordc.rr.com">news:nospam-3303F8.23170602062005@news-rdr-01.ohiordc.rr.com...
> In article <C9wne.31214$9A2.23366@edtnps89>,

> Works fine on KEGS-OSX (0.65) and KEGS (0.91).
>
> Snakebyte is quite a tour-de-force! It took a minute to understand how the
> keys work. Somehow I expected all four arrows to work instead of just two.
>
> Are you using a lookup table for gbascalc? See, for example,
> <http://www.wright.edu/~john.matthews/apple2.html#lr>.
>
> Would you consider supplying source, especially for your STARTUP program?
>
> Can you outline the method you use to embed machine code in your Applesoft
> programs?

Hi John

Grab a Cappuccino, it's going to be a long one! :)

Thank you for checking it out! - I'm glad you enjoyed Snakebyte!  It's been 
a
real labor of love getting it to where it is today.  I originally had the 
four
arrow keys written into the code, but the way I had it written, it was so
slow going through all the IF ... THENs for keyboard that I removed them
and went with a left/right arrow to turn the snake.  Of course that was
before I rewrote the code to not even execute the IF ... THENs on the
occasion that a key was not being pressed.  For sentimental reasons,
I left the snake control as it is now with just left/right arrows.

If the RESET vector is screwing up your looking at the source, simply
let the game get going, press CTRL-C and then press ESC.  It'll undo
the RESET vector modifications, and return you to ( ] ) an applesoft
prompt with the program in-tact for easy listing.  After you CTRL-C
and ESC, if you've pressed RESET during the game operation, you'll
need to hit RESET again at the applesoft prompt, to re-hook DOS 3.3
so you can CATALOG, LOAD, SAVE, etc.

As for GBASCALC,

The glory of GBASCALC is you don't need a lookup table.  Simply Load
the Accumulator with the line number (0-23) of the horizontal line you'd 
like
to work with and then JSR to GBASCALC.  For Example, say I wanted to
work on line one (PLOT 0,0 : PLOT 0,1) of the Lo-Res Screen.  I'd
LDA #$00 and then JSR to the GBASCALC ($F847) routine.  The routine
returns, after storing the memory location of the line requested in zero 
page
locations $26, $27 - of course 6502 eccentric, lo-order byte ($26)
then high order byte ($27).  So after the JSR to GBASCALC, $26
and $27 would read as follows (assuming again, a LDA #$00)

26- 00
27- 04

Or in proper addressing notation: $0400 - aka PLOT 0,0 : PLOT 0,1

So if you Indirect Indexed "($26),Y" load and Indirect Indexed "($26),Y"
store the accumulator, all the heavy lifting of calculating screen memory
locations is done via GBASCALC, and the fun stuff is left to you, the
programmer!

GBASCALC is GREAT for moving data to and from / from and to, but if
you want the ML equivalent of PLOT or HLIN / VLIN, you'll have to learn
to use MASK and COLOR to set the proper dot - either top or bottom as
you would like.  MASK simply EORs a $0F or a $F0 to plot to top or bottom
as required, keeping in mind, each two dots on the display under Lo-Res
only take 1 text character to produce.  - Example:  PLOT 0,0 and PLOT 0,1
means only one byte of data is stored at $0400.  For example, at the apple-
soft prompt, set GR and then CALL -151 to get into the monitor

Then type:

400:FF

You'll see the equivalent of "COLOR=15 : PLOT 0,0 : PLOT 0,1"

Try it with variations and see what happens:

400:F0

400:F9

400:0A

etc.

The $FF is a Byte representing the color codes for two dots on the
screen, the high-order nibble represents the color for the bottom block
and the lo-order nibble represents the color for the top block.

So to get a red over black block, you'd type the following:

400:01     ;  0 - nibble for bottom block = black (0) and
                ;  1 - nibble for top block = red (1)

And, you might've guessed it, $0-$F is 0-15 for the Lo-Res
COLOR= command.

That's why GBASCALC is good for moving, not really for plotting
specific points.  It moves both the "0" and the "1" from our above
example, at the same time.

Here's a zipfile with the source for SnakeByte ML routines included:

http://www.turbo-2.com/apple/sb05.zip

I can do a disassembly of STARTUP for you, but admittedly, the
file handling program is just a generic one I had on a disk that I
included for ease of program selection at run-time.

A quick synopsis is as follows:

The applesoft program calls a ML routine to relocate the animation code
into it's native location, then JSRs to it.  After you press a key, it
returns, and JMPs to $820 or the native location (and applesoft
appended location) of the File handling routine.  Pretty straight-
forward, hey?  I will however do a disassembly of it and highlight
the different program segments for you and how they do what they
do, just for ease of understanding.  But you'll have to give me a
day or so to remember what trickery and tom-foolery I used in
assembling that program!  Not to mention, I'll have to ADT it
to my GS so I can resend it and capture it as a text-file on my PC :)

Applesoft - ML append...

Now, for appending ML routines to Applesoft, it's pretty easy
really, but takes a little planning to be sure.

AF and B0 are zero page locations used to determine how many
bytes the SAVE command will put onto disk.  Or more accurately,
the end location of an applesoft file in memory.

So if I have an Applesoft program as follows:

10 TEXT : HOME
20 PRINT "Applesoft program"
30 END

and I want to append a machine language routine to it, I'll do the
following:

- I'll run a ML program to "blank memory to zeros"
(you'll want to blank $800 - $9000 or so for ease of snooping)

- Type "FP" under DOS 3.3, or "NEW" under ProDOS

- Load the Applesoft program

- Snoop around from $800 on to find a suitable location
  after the applesoft program to set "xxxx" to - or where
  to load the ML program for appending to applesoft

- Then,

I'll edit the applesoft program to include a "CALL xxxx" line
to whatever routine I'm including.  xxxx is the decimal equivalent
of the hexadecimal start address for the ML routine that is going to
be appended.

Be sure to leave about 20-30 "00" Bytes after the Applesoft program
before appending the ML routine.  Safety net! :)

Then, I'll BLOAD the routine (with any necessary relocating code to
ensure the code runs in it's "native" memory range) to "xxxx" and find
the end of the ML routine with a simple snoop through memory lane.

*800.9600  <return>

and when I see a bunch of zeros, I know I've found  the end of
the routine.  At that point, I'll set AF.B0 to indicate the end of the
appended routine.

So for example, applesoft program goes from $800 - $1000 say,
and the ML routine resides at $1025 to $1500.  I'll set
AF and B0 to indicate this:

AF:01
B0:15

Then back to ( ] ) and type "SAVE TEST"

It'll save the Applesoft program and memory up to $1501 as a
single Applesoft file.  Then the applesoft call "xxxx" instruction
jumps us to the ML routine after which, an RTS ($60) returns
us to applesoft control.

Hopefully that's somewhat clear! :)

Later,
Craig