Dseg.mac

From Intellivision Wiki
Revision as of 08:20, 4 December 2010 by Mr z (talk | contribs) (Protected "Dseg.mac" ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite)))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


NOTE: This file has been superseded by cart.mac. You should consider using cart.mac instead of this file.

Functions Provided

MacroAction performedNotes
label SCRATCH lenAllocate len storage locations in 8-bit Scratchpad RAM, assigning the address to labelAllocated range will be in 8-bit memory from $102 - $1EF.
label SYSTEM lenAllocate len storage locations in 16-bit System RAM, assigning the address to labelAllocated range will be in 16-bit memory from $2F0 - $35F.



Examples

(todo... please contribute!)

Notes

These routines expect to have sole authority over how the 8-bit Scratchpad RAM and 16-bit System RAM are allocated. They are not compatible with programs that use the EXEC, as the EXEC reserves some of these locations to itself. The SCRATCH macro does not disturb the interrupt service vector at $100 - $101.

When using this scheme, you should use the SYSTEM macro to declare a stack, and set the stack pointer (R6) to point to this stack early in your initialization. For instance:

STACK   SYSTEM  32          ; Reserve 32 words of stack space
        MVII    #STACK, R6  ; Initialize stack pointer

Note that you will effectively lose the previous contents of your stack when you do this, which is why it should be one of the first things you do in your initialization.

To get an idea of how much Scratchpad RAM and System RAM your program uses, look for the symbols ".SCRMEM" and ".SYSMEM" in the assembler listing file or symbol dump file. .SCRMEM indicates the first free location of Scratchpad RAM, and .SYSMEM indicates the first free location of System RAM. The macros allocate from the bottom of memory toward the top. Therefore, $1F0 - .SCRMEM gives the remaining amount of 8-bit Scratchpad RAM, and $360 - .SYSMEM gives the remaining amount of 16-bit System RAM.

Source Code

;* ======================================================================== *;
;*  These routines are placed into the public domain by their author.  All  *;
;*  copyright rights are hereby relinquished on the routines and data in    *;
;*  this file.  -- Joseph Zbiciak, 2008                                     *;
;* ======================================================================== *;
            IF (DEFINED _DSEG_MAC) == 0
_DSEG_MAC   EQU     1

;; ======================================================================== ;;
;;  SCRATCH   Declare a variable in 8-bit (scratch) memory                  ;;
;;  SYSTEM    Declare a variable in 16-bit (system) memory                  ;;
;;                                                                          ;;
;;  These macros provide a convenient method for declaring variables in the ;;
;;  Intellivision's internal memory.  Rather than rely on EQUs and one's    ;;
;;  own memory, you can use these macros to declare your variables in RAM.  ;;
;;                                                                          ;;
;;  Both work identically, with the only difference being which pool of     ;;
;;  memory the variable gets allocated in.  SCRATCH allocates storage in    ;;
;;  8-bit memory at $102 through $1EF.  SYSTEM allocates storage in 16-bit  ;;
;;  memory at $2F0 through $35F.                                            ;;
;;                                                                          ;;
;;  Both macros expect to own the entire pool.  If you manually allocate    ;;
;;  some addresses in either range and use these macros, the two may clash. ;;
;;  You will need to adapt these to skip those addresses, or change the     ;;
;;  manual allocations to use these macros.                                 ;;
;;                                                                          ;;
;;  USAGE                                                                   ;;
;;                                                                          ;;
;;      label SCRATCH len                                                   ;;
;;      label SYSTEM  len                                                   ;;
;;                                                                          ;;
;;  where 'label' is the name of the label to associate with the memory     ;;
;;  range, and 'len' is how many locations to set aside (typically 1).      ;;
;;                                                                          ;;
;;  EXAMPLES                                                                ;;
;;                                                                          ;;
;;      FLAG  SCRATCH 1     ; Allocate 1 8-bit location, named "FLAG"       ;;
;;      STACK SYSTEM  32    ; Allocate 32 16-bit locations, named "STACK"   ;;
;;                                                                          ;;
;;  Note:  For the "STACK" example, this won't place your stack there       ;;
;;  unless you also do "MVII #STACK, R6" to relocate your stack.            ;;
;; ======================================================================== ;;

.SCRMEM     SET     $102
.SYSMEM     SET     $2F0

MACRO       SCRATCH l
            EQU     .SCRMEM
            LISTING "off"
.SCRMEM     SET     .SCRMEM + %l%
            IF      .SCRMEM > $1F0
                ERR     "Scratch Memory Overflow"
            ENDI
            LISTING "prev"
ENDM

MACRO       SYSTEM  l
            EQU     .SYSMEM
            LISTING "off"
.SYSMEM     SET     .SYSMEM + %l%
            IF      .SYSMEM > $360
                ERR     "System Memory Overflow"
            ENDI
            LISTING "prev"
ENDM

            ENDI

;; ======================================================================== ;;
;;  End of File:  dseg.mac                                                  ;;
;; ======================================================================== ;;