Thursday, May 26, 2011

More great info from Beth!!

Hello everyone, 
I was able to get a hold of Beth again and ask her some more questions and she graciously responded with the following:
___________________________________________
Hi Beth, 

I was able to get my hands on a copy of DOS Tool Kit for the Apple II, which is the Apple 6502 Assembler/Editor.  Now that I have an assembler I will able to start figuring out how to write some assembly code.  I know this will take a while but I have start somewhere right? 
Question:  The memory address region for the Apple IIe with regard to Hi-Res page 1 is $2000 to $3FFF.   

Is this to say that the range from $2000 to $3FFF is each individual pixel on the screen?   
This seems too big because I have another chart that shows the entire screen layout and it starts at $2000 at the upper left corner then goes to $23D0 at the bottom left, but across the top it shows $00 to $27, which I assume are each byte width from 0 to 39!   

If this is the case, then would the actual memory graphics range be $2000 to $23F7 that reprents a pixel on the screen? 

I’ve done a lot of playing around with the poking dots on the screen using the 8192 value. I have even used the DRAW command and placed shapes on the screen using the same 8192 values.  But from what I’m learning about Assembly I don’t think I get how you would place a character or a shape directly into a memory location. 

I know that you can poke to a specific address in TEXT mode like “POKE 1024,01 and you would end up poking the ascII value of the letter A on the screen at the 0,0 address location.  With this process I think I can figure out that if I created a new set of characters using a character generator I could replace all of the ascII characters that I wouldn’t use in the game, such as all the lower case characters or Inverse character!  With all these new ASCII characters, which would be representing all the tiles on the map, I could do everything in TEXT mode instead of Hi-Res graphics mode.  Maybe….   Since each ASCII character is made up of a byte of information I understand that this byte could be loaded using the ADL command and moved into a memory location by moving from the accumulator to a memory region in the TEXT mode, which is $400 to $7F7 if I use the same memory value logic.   

Is this correct?? 

Now if I still want to use the Hi-Res page 1 graphics mode, which is range $2000 to $23F7, “I think”, then I would need to figure out how to use assembly code to place the same ASCII character into a memory region OR place a shape into a memory location.  Placing a shape into memory is beyond me because a shape is created using more than one byte of information.  I know that when a shape is created it is placed in a shape table which has a starting location for shape 0 then it has another starting location for shape 1, and so on…   There seems to be multiple bytes of information that make up the entire shape table.   

Another question:  You know how when you create a shape table they give you an address where the table is loaded such as; PRINT CHR$(4) “BLOAD SHAPES, A16384” 

The A16384 is the starting location of the entire shape table but what is this value A16384?  Is this a DEC memory location and does this equates to $4000 in Hex?  How do you equate this value A16384 into the memory locations they are in?  I realize that if you have let’s say 50 shapes, all these shapes would start somewhere and take up a range of memory locations right? 

The reason I gave you the value A16384 is because the program “The Complete Graphics System”, which I use to create the shapes, always uses the starting location address of A16384 and says the table will end no further than location 28499.   

Would you use assembly code to grab each byte range that make up the shapes and place them in a memory location on the Hi-Res screen? 
I don’t mean to blast you with a bunch of questions but I feel as though my brain is very close to having a “light bulb moment” and some factors are keeping it from happening.  I feel like I’m close to really understanding this but there are some issues that seem to elude me… if you know what I mean? 
Thanks for any help you can give. 
Sincerely, 
Joe
______________________________
Joseph, 

Okay, first things first. Forget about the using Text mode. And forget about shape tables. Those are both dead-ends. Yes, you can accomplish things with them, yes you could get tiles to draw with either one. I wrote applications in basic using both and completed full little games – but the speed wasn’t there. If you want to really do this, you simply need to copy from your in-memory tiles to the on-screen part of memory.

For a discussion on the insanity that was the Apple 2 hi-res graphics memory layout, here’s a link:


Specifically, start in from “Hands-On Practice with Standard Hi-Res”
That gives you the addresses of the tile “boxes” you want on the screen. There are 40 across at 7 pixels wide and 24 high at 8 pixels each. 
Specifically, start in from “Hands-On Practice with Standard Hi-Res”

You should play around with pushing bits as it calls out, e.g. 2028:1, until you understand how to put pixels into each tile. You can make yourself a chart with all the tile addresses, even.  

One of the crazy things to remember is that the memory is interleaved. So your vertical lines are organized like so: 

$2000,  (Line 0)
$2400,
$2800, (Line 2)
$2C00,
$3000, (Line 4)
$3400,
$3800, (Line 6)
$3C00,
$2080, (Line 8)
$2480,
$2880, (Line 10)
$2C80,
$3080 (Line 12)
Etc.

Don’t feel bad about this – the memory isn’t laid out simply. It’s got a pattern that makes sense, but it was designed the way it was because of the crazy hardware in that box. 

Okay…if you played around with pushing enough bits you should get the idea. Now I’m going to assume you have a good idea of: 
1.       Where each of the tiles start 
2.       What bits make which colors for each address. 

Now you want to copy using Assembly. What you do is to put shapes into memory in the exact same way you want them to appear on the screen. Those will be your tiles. And by having the tiles existing at one place in memory, you can copy that memory multiple times onto the screen to have it draw multiple tiles. So you store your mountains once, off the screen, and then fill in each graphic mountain tile as many times as necessary. 

For the sake of example, I’m going to say you have a tile in memory at $1000. This “tile” is the same size as a tile on the screen, so it’s 7 pixels wide by 8 rows tall. A description of this tile might be as such: 

$1000: 0x7F 
$1001: 0x03   
$1002: 0x44  
$1003: 0x72  
$1004: 0x01  
$1005: 0x1B  
$1006: 0x68  
$1007: 0x10 
Now you need to copy those bits to where you want on the screen. Let’s say you want to put it at the tile at memory address $2000 and the tile at $2100. Conceptually, you want to copy like so: 

$1000 -> copy to -> $2000             $1000 -> copy to -> $2100 
$1001 -> copy to -> $2400             $1001 -> copy to -> $2500 
$1002 -> copy to -> $2800             $1002 -> copy to -> $2900 
Etc. 

Another link, of 6502, is here: 
You should scroll about halfway down to the section on “Instruction Set By Purpose”. For copying, you want to pay close attention to the Accumulator and Index instructions. There’s a lot of other great how-to info on this page as well, you should really check out everything in the “By Purpose” section.

On the Apple II you have 3 “registers” which you can use. This keeps things nice and simple. They are A, X, and Y. (Accumulator, X & Y indexes). You can load them from memory, do comparisons and math based on them, and store them back to memory. 

So…conceptually, you want to do something like: 

1.       Read from $1000 into the Accumulator. This stores 0x7F in the Accumulator. 
2.       Store the value in the Accumulator into memory at $2000. This stores 0x7F into $2000. 

The instructions for doing this would be like so: 

1.       LDA $1000                           (LDA as in “Load A” or “Load Accumulator”) 
2.       STA $2000                            (STA as in “Store A” or “Store Accumulator”) 

From there, the next step is to create a loop that runs through your bytes and copies them. I’m not going to try to write out that loop for you in detail (I sent you the “copy memory” link separately, as I recall) but conceptually, you could do something like this: 
1.       Loop through your read memory 8 times, grabbing each byte sequentially. 
2.       Loop through the write address 8 times, storing the value and incrementing the address by $400 for each byte (thus copying down the vertical row). 
  
You could implement this like so (this is assembly-esque pseudo-code ymmv):

  
1.       Put the source address ($1000) in X         (done as two operations so it can be stored in zero-page)
2.       Put the dest address ($2000) in Y              (as above) 
3.       STX, $A5 
4.       STX, $A6                                                              (This puts 0x1000 into zero-page address $A5 & $A6) 
5.       STY, $A7                                                               (This puts 0x2000 into zero-page address $A7 & $A8) 
6.       STY, $A8 
7.       LDX #$00                                                              (set X to 0) 
8.       LDY #$20                                                              (set Y to 0x20 – the value in $A7) 
9.       LDA  ($A5, X)                                                      (this is “indirect addressing” and is now the same as LDA $1000) 
10.   STA  $A7                                                               (same as STA $2000) 
11.   INX                                                                         (“increment x” -  x is now equal to 1) 
12.   INY                                                                         (do this 4 times – you could also do this by adding 0x04 to Y) 
13.   STY $A7                                                                (this stores 0x24 into $A7) 
14.   LDA ($A5, X)                                                       (this is now the same as LDA $1001) 
15.   STA $A7                                                                (this is now the same as STA $2400) 
16.   Etc… 
  
You can be clever with loops and such, different addressing modes, etc. It just depends on how you want to layout your memory and what makes the most sense to you.   
  
I hope that helps! 
  
-          Beth

No comments:

Post a Comment