vprette, on Sat Feb 4, 2012 11:16 AM, said:
Quote
Great! Then it is apparent that your tracker variables were being overwritten with the engine's data. Just keep this in mind. All RAM variables in your game must be allocated using the SCRATCH or SYSTEM, or any of the other allocation macros included in "Cart.mac."
is this concerning also the font to be written in the RAM? my next step is to use the fonts of you, so I have to understand where I set GRAM offset and call your LETTERS proc
Yes. P-Machinery includes macros to allocate GRAM. The idea is to statically allocate the GRAM that you will need for each state, so that the framework can keep track of how much is available. Also, by encapsulating the GRAM allocation, it makes it easier to control access to it. To this end, there are macros that support loading sprite graphics and displaying background tiles. These are all within the "graphix.mac" file.
Take a look at the GRAM_BLOCK definition in the main source file. It contains commentary on how to allocation GRAM tiles for sprites and general use.
In your case, you want to allocate a block of GRAM for the fonts, so you will use the DEFINE_GRAM_BLOCK() macro. You'll have something like this:
; =============================================================
; The GRAM_BLOCK structure defines symbols that represent
; pointers to the various graphic assets in GRAM.
;
; P-Mach offers a complimentary set of macros and sub-routines
; that use the GRAM_BLOCK structure to manage and manipulate
; the GRAM.
; =============================================================
GRAM_BLOCK STRUCT 0
RESET_GRAM
; NOTE: YRES (Double vertical resolution) sprites need to start
; on an even numbered GRAM card. We define these first to
; ensure that they start on card number zero, which is even.
; SPRITE BLOCKS:
; Use the DEFINE_SPRITE_GRAM() macro to
; allocate GRAM blocks for game sprites.
; --------------------------------------
; DEFINE_SPRITE_GRAM(Sprite0, vDouble)
; DEFINE_SPRITE_GRAM(Sprite1, vDouble)
; DEFINE_SPRITE_GRAM(Sprite2, vDouble)
; DEFINE_SPRITE_GRAM(Sprite3, vDouble)
; DEFINE_SPRITE_GRAM(Sprite4, vDouble)
; DEFINE_SPRITE_GRAM(Sprite5, vDouble)
; DEFINE_SPRITE_GRAM(Sprite6, vDouble)
; DEFINE_SPRITE_GRAM(Sprite7, vSingle)
; --------------------------------------
; BACKGROUND BLOCKS:
; Use the DEFINE_GRAM_BLOCK() macro to
; allocate GRAM blocks for the background
; and other assets.
; --------------------------------------
; DEFINE_GRAM_BLOCK(PlayField, 240)
; --------------------------------------
DEFINE_GRAM_BLOCK(Font, 26)
ENDS
That will allocate 26 cards in GRAM to a label called "Font". From then on, you can refer to that block by the label "
GRAM_BLOCK.Font".
You'll also notice in the "graphix.mac" file that some macros accept a "block" as an argument, for instance,
GRAM_BASE_CARD(block). Whenever you see something requiring a "block" you only need to provide the label of your allocated GRAM_BLOCK. So, if you wanted to know the base card number in GRAM for your fonts block, you would use it like this:
MVII #GRAM_BASE_CARD(Font), R1
The macro will expand the label "Font" to "
GRAM_BLOCK.Font".
Now,
DEFINE_GRAM_BLOCK() only allocates the memory; you still need to load the fonts from ROM into GRAM. For this, you use the family of macros included in "load_data.mac". The basic load macro is LOAD_DATA(), which just performs a block-copy. However, to simplify loading to GRAM, there is another macro called
LOAD_GRAM_BLOCK(). The usage is,
;; ======================================================================== ;;
;; LOAD_GRAM_BLOCK(source, dest) ;;
;; Loads a complete block of data into GRAM. ;;
;; ;;
;; ARGUMENTS ;;
;; source The name of the source block in ROM to load. The name ;;
;; corresponds to the label pointing to the start of the data ;;
;; source block. ;;
;; ;;
;; dest A GRAM_BLOCK record field that contains the pointer to the ;;
;; destination. The Macro will expand it to GRAM_BLOCK.%dest%. ;;
;; ======================================================================== ;;
For this to work, you'll need to define your ROM data blocks like this:
; ===================================================================
FONTS PROC
; GRAM Tile: 65
; --------------------------------
; ........ - %00000000
DECLE $0000 ; ........ - %00000000
; .######. - %01111110
DECLE $827E ; #.....#. - %10000010
; #.....#. - %10000010
DECLE $8682 ; #....##. - %10000110
; .####.#. - %01111010
DECLE $007A ; ........ - %00000000
; --------------------------------
; GRAM Tile: 66
; --------------------------------
; #....... - %10000000
DECLE $8080 ; #....... - %10000000
; #.####.. - %10111100
DECLE $C2BC ; ##....#. - %11000010
; #.....#. - %10000010
DECLE $8282 ; #.....#. - %10000010
; ######.. - %11111100
DECLE $00FC ; ........ - %00000000
; --------------------------------
@@data_size EQU ($ - FONTS)
ENDP
; ===================================================================
Notice the bottom: The
@@data_size label defines the length of the block. Saying
($ - FONTS) is the same as saying "the current address pointer minus the beginning of the block," which will yield the word size of the block.
This is important, because the LOAD_DATA() macros need to know how much data to load. The
LOAD_GRAM_BLOCK() macro
expects this label to be defined in the source block. It simplifies and automates loading without having to really know or keep track of the length of data.
And lastly, when should you call the
LOAD_GRAM_BLOCK() macro? Well, during initialization, of course!
-dZ.