mirror of
https://github.com/elliotnunn/supermario.git
synced 2024-11-29 05:49:19 +00:00
200 lines
4.5 KiB
Plaintext
200 lines
4.5 KiB
Plaintext
|
TITLE 'StdMacros.a'
|
||
|
;---------------------------------------------------------------------------
|
||
|
; File: StdMacros.a
|
||
|
;
|
||
|
; Contains: This file contains macros which are used throughout the test software
|
||
|
; to define records in a convenient way.
|
||
|
;
|
||
|
; Written by: CPU diagnostics and Test Engineering
|
||
|
;
|
||
|
; Copyright: © 1990 by Apple Computer, Inc., all rights reserved.
|
||
|
;
|
||
|
; Change History (most recent first):
|
||
|
;
|
||
|
; <1> 8/31/90 SS first checked in
|
||
|
;
|
||
|
;
|
||
|
;---------------------------------------------------------------------------
|
||
|
|
||
|
IF &TYPE('StdMacros')='UNDEFINED' THEN
|
||
|
|
||
|
StdMacros EQU 1
|
||
|
|
||
|
CASE ON
|
||
|
PRINT NOMDIR
|
||
|
|
||
|
;---------------------------------------------------------------------------
|
||
|
; The following four macros, STRUCTURE, DSF, ENDSTRUCT, and STRUCTITEM are
|
||
|
; used to declare a 'C'-type structure. These macros are used to create a
|
||
|
; RECORD which provides offsets into a structure, and to create another
|
||
|
; MACRO which is used to define a entry for a constant table of structures.
|
||
|
;
|
||
|
; A symbol table is used to store structure information. The following is
|
||
|
; an example of creating structure offsets:
|
||
|
;
|
||
|
; TheCStruct STRUCTURE 0
|
||
|
; DSF.L aLong
|
||
|
; DSF.B aByte
|
||
|
; DSF.B anotherByte
|
||
|
; DSF.W aWord
|
||
|
; ENDSTRUCT
|
||
|
;
|
||
|
; It would be used as:
|
||
|
; WITH TheCStruct
|
||
|
; move.l aLong(a0),d0 ;Offset is 0
|
||
|
; move.b anotherByte(a0),d0 ;Offset is 5
|
||
|
; sub.l #sizeofTheCStruct,sp ;Subtract 8 from stack pointer
|
||
|
; ENDWITH
|
||
|
;
|
||
|
; A MACRO to define a table entry would look like this:
|
||
|
;
|
||
|
; MACRO
|
||
|
; TheCStructItem &items
|
||
|
; STRUCTITEM TheCStruct, &items
|
||
|
; ENDM
|
||
|
;
|
||
|
; And used as:
|
||
|
;
|
||
|
; ANewTable PROC ;aLong aByte anotherByte aWord
|
||
|
; TheCStructItem ($12345678, 3, 7, $5A5A)
|
||
|
; TheCStructItem ($87654321, 9, 32, $A5A5)
|
||
|
; ENDPROC
|
||
|
;
|
||
|
;---------------------------------------------------------------------------
|
||
|
|
||
|
; The symbol table, used for defining all structures, is initialized
|
||
|
|
||
|
GBLA &structSymTbl
|
||
|
&structSymTbl SETA &NEWSYMTBL
|
||
|
|
||
|
|
||
|
; macro STRUCTURE
|
||
|
; - adds the structure name to symbol table with a field count of zero (value entry)
|
||
|
; - initializes globals &structName and &structIdx
|
||
|
; - code produced:
|
||
|
; &name RECORD &offset
|
||
|
|
||
|
MACRO
|
||
|
&name STRUCTURE &offset
|
||
|
|
||
|
GBLC &structName
|
||
|
GBLA &structSymTbl, &structIdx
|
||
|
|
||
|
IF &FINDSYM (&structSymTbl, &name) THEN
|
||
|
AERROR 'MACRO ERROR: Structure name already exists'
|
||
|
EXITM
|
||
|
ENDIF
|
||
|
|
||
|
IF &ENTERSYM (&structSymTbl, &name, 0, 0) = 0 THEN
|
||
|
AERROR 'MACRO ERROR: Error adding structure name to symbol table'
|
||
|
EXITM
|
||
|
ENDIF
|
||
|
|
||
|
&structName SETC &name
|
||
|
&structIdx SETA 1
|
||
|
|
||
|
&name RECORD &offset
|
||
|
|
||
|
ENDM
|
||
|
|
||
|
|
||
|
; macro DSF
|
||
|
; - adds structure name concatted with idx to symbol table, with a value of &fieldName,
|
||
|
; and flags set to &size
|
||
|
; - increments globals &structIdx
|
||
|
; - code produced:
|
||
|
; &fieldName DS.&size 1
|
||
|
|
||
|
MACRO
|
||
|
DSF.&size &fieldName
|
||
|
|
||
|
GBLC &structName
|
||
|
GBLA &structSymTbl, &structIdx
|
||
|
LCLC &symEntry
|
||
|
LCLA &iSize
|
||
|
|
||
|
&symEntry SETC &CONCAT(&structName, &I2S(&structIdx))
|
||
|
&iSize SETA &ORD(&size)
|
||
|
|
||
|
IF &ENTERSYM (&structSymTbl, &symEntry, &fieldName, &iSize) = 0 THEN
|
||
|
AERROR 'MACRO ERROR: Error adding structure field to symbol table'
|
||
|
EXITM
|
||
|
ENDIF
|
||
|
|
||
|
&structIdx SETA &structIdx + 1
|
||
|
|
||
|
&fieldName DS.&size 1
|
||
|
|
||
|
ENDM
|
||
|
|
||
|
; macro ENDSTRUCT
|
||
|
; - adds the field count to the symbol table as the value entry for the structure name
|
||
|
; - code produced:
|
||
|
; sizeof&structName EQU *
|
||
|
; ENDR
|
||
|
|
||
|
MACRO
|
||
|
ENDSTRUCT
|
||
|
|
||
|
GBLC &structName
|
||
|
GBLA &structSymTbl, &structIdx
|
||
|
|
||
|
IF &ENTERSYM (&structSymTbl, &structName, 0, &structIdx - 1) = 0 THEN
|
||
|
AERROR 'MACRO ERROR: Error adding structure size to symbol table'
|
||
|
EXITM
|
||
|
ENDIF
|
||
|
|
||
|
sizeof&structName EQU *
|
||
|
|
||
|
ENDR
|
||
|
|
||
|
ENDM
|
||
|
|
||
|
; macro STRUCTITEM
|
||
|
; - finds &name in symbol table and validates number of entries in &field based on value
|
||
|
; stored with structure name symbol
|
||
|
; - for each field entry, get field size from symbol table and produce code:
|
||
|
; DC.&size &fields[&idx]
|
||
|
|
||
|
MACRO
|
||
|
STRUCTITEM &name, &fields
|
||
|
|
||
|
GBLA &structSymTbl
|
||
|
LCLC &symEntry, &size
|
||
|
LCLA &fieldCnt, &idx
|
||
|
|
||
|
&fieldCnt SETA &NBR (&fields)
|
||
|
|
||
|
IF &FINDSYM (&structSymTbl, &name) = 0 THEN
|
||
|
AERROR 'MACRO ERROR: Structure name not found'
|
||
|
EXITM
|
||
|
ENDIF
|
||
|
|
||
|
IF &SYSFLAGS <> &fieldCnt THEN
|
||
|
AERROR 'MACRO ERROR: Invalid number of structure fields'
|
||
|
EXITM
|
||
|
ENDIF
|
||
|
|
||
|
&idx SETA 1
|
||
|
WHILE &idx <= &fieldCnt DO
|
||
|
|
||
|
&symEntry SETC &CONCAT(&name, &I2S(&idx))
|
||
|
|
||
|
IF &FINDSYM (&structSymTbl, &symEntry) = 0 THEN
|
||
|
AERROR 'MACRO ERROR: Structure field not found'
|
||
|
EXITM
|
||
|
ENDIF
|
||
|
|
||
|
&size SETC &CHR(&SYSFLAGS)
|
||
|
|
||
|
DC.&size &fields[&idx]
|
||
|
|
||
|
&idx SETA &idx + 1
|
||
|
|
||
|
ENDWHILE
|
||
|
|
||
|
ENDM
|
||
|
|
||
|
|
||
|
ENDIF
|