2018-11-10 22:41:05 +00:00
|
|
|
*
|
|
|
|
*``````````````````````````````*
|
2018-12-12 19:29:06 +00:00
|
|
|
* AGET82 : INIT 2D ARRAY *
|
2018-11-10 22:41:05 +00:00
|
|
|
*- -*
|
|
|
|
* THIS GETS THE ADDRESS OF AN *
|
2018-12-12 19:29:06 +00:00
|
|
|
* ELEMENT AT THE INDEX OF *
|
|
|
|
* [:XIDX],[:YIDX]. *
|
2018-11-10 22:41:05 +00:00
|
|
|
*- -*
|
|
|
|
* CLOBBERS: *
|
|
|
|
* *
|
|
|
|
* FLAGS: ????---- REG: AXYM *
|
|
|
|
*- -*
|
|
|
|
* CYCLES: ??? *
|
|
|
|
* SIZE: *
|
|
|
|
*- -*
|
|
|
|
* USAGE: *
|
|
|
|
* *
|
2018-12-12 19:29:06 +00:00
|
|
|
* LDA #>$300 ; ARRAY ADDR *
|
|
|
|
* PHA *
|
|
|
|
* LDA #<$300 *
|
|
|
|
* PHA *
|
|
|
|
* LDA #2 ; X INDEX *
|
|
|
|
* PHA *
|
|
|
|
* LDA #3 ; Y INDEX *
|
|
|
|
* PHA *
|
|
|
|
* JSR AGET82 *
|
2018-11-10 22:41:05 +00:00
|
|
|
*- -*
|
|
|
|
* ENTRY *
|
|
|
|
* *
|
|
|
|
* TOP OF STACK *
|
|
|
|
* *
|
|
|
|
* LOW BYTE OF RETURN ADDRESS *
|
|
|
|
* HI BYTE OF RETURN ADDRESS *
|
|
|
|
* Y INDEX OF ELEMENT *
|
|
|
|
* X INDEX OF ELEMENT *
|
|
|
|
* LOW BYTE OF ARRAY ADDRESS *
|
|
|
|
* HIGH BYTE OF ARRAY ADDRESS *
|
|
|
|
*- -*
|
|
|
|
* EXIT *
|
|
|
|
* *
|
|
|
|
* TOP OF STACK *
|
|
|
|
* *
|
|
|
|
* LOW BYTE OF RETURN ADDRESS *
|
|
|
|
* HI BYTE OF RETURN ADDRESS *
|
|
|
|
* *
|
2018-12-12 19:29:06 +00:00
|
|
|
* .Y = LO BYTE OF ELEM ADDR *
|
|
|
|
* .X = HI BYTE OF ELEM ADDR *
|
|
|
|
* .A = ELEMENT/RETURN LENGTH *
|
|
|
|
* *
|
|
|
|
* [RETURN] = VALUE FOUND AT *
|
|
|
|
* SPECIFIED INDEX. *
|
|
|
|
* *
|
|
|
|
* [RETLEN] = LENGTH IN BYTES *
|
|
|
|
* OF THE RETURN VALUE. *
|
2018-11-10 22:41:05 +00:00
|
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
|
|
*
|
|
|
|
AGET82
|
|
|
|
*
|
|
|
|
** SAVE RETURN ADDRESS
|
|
|
|
*
|
|
|
|
PLA
|
|
|
|
STA RETADR
|
|
|
|
PLA
|
|
|
|
STA RETADR+1
|
|
|
|
*
|
|
|
|
** GET PARAMETERS
|
|
|
|
*
|
|
|
|
PLA
|
|
|
|
STA :YIDX
|
|
|
|
PLA
|
|
|
|
STA :XIDX
|
|
|
|
PLA
|
|
|
|
STA ADDR1
|
|
|
|
PLA
|
|
|
|
STA ADDR1+1
|
2019-01-21 00:14:17 +00:00
|
|
|
DEC :XIDX
|
|
|
|
DEC :YIDX
|
|
|
|
*
|
|
|
|
** GET ARRAY SIZES
|
2018-11-10 22:41:05 +00:00
|
|
|
*
|
|
|
|
LDY #2
|
|
|
|
LDA (ADDR1),Y ; ELEMENT LENGTH
|
|
|
|
STA :MCAND ; ELEMENT LENGTH
|
2019-01-21 00:14:17 +00:00
|
|
|
STA :ELEN
|
|
|
|
DEY
|
|
|
|
LDA (ADDR1),Y ; Y LENGTH
|
|
|
|
STA :YLEN
|
|
|
|
DEY
|
|
|
|
LDA (ADDR1),Y ; X LENGTH
|
|
|
|
STA :XLEN
|
2018-12-12 19:29:06 +00:00
|
|
|
LDA #0
|
|
|
|
STA :MCAND+1
|
2018-11-10 22:41:05 +00:00
|
|
|
*
|
2019-01-21 00:14:17 +00:00
|
|
|
********************************
|
|
|
|
*
|
|
|
|
* ERROR CONTROL
|
|
|
|
*
|
|
|
|
********************************
|
|
|
|
*
|
|
|
|
LDA ERRCTRL
|
|
|
|
CMP #1
|
|
|
|
BEQ :CHKERR
|
|
|
|
JMP :ERREND
|
|
|
|
:CHKERR
|
|
|
|
LDA :XIDX ; IF X > MAX LEN
|
|
|
|
CLC
|
|
|
|
ADC #1
|
|
|
|
CMP :XLEN
|
|
|
|
BCS :XOVF
|
|
|
|
JMP :ERRCONT1
|
|
|
|
:XOVF
|
|
|
|
_ERR :E_SID;:E_XOVF;:E_DUMP;:XIDX;#15
|
|
|
|
:ERRCONT1
|
|
|
|
LDA :YIDX ; IF Y > MAX LEN
|
|
|
|
CLC
|
|
|
|
ADC #1
|
|
|
|
CMP :YLEN
|
|
|
|
BCS :YOVF
|
|
|
|
JMP :ERRCONT2
|
|
|
|
:YOVF
|
|
|
|
_ERR :E_SID;:E_YOVF;:E_DUMP;:XIDX;#15
|
|
|
|
:ERRCONT2
|
|
|
|
LDA :XIDX ; IF INDEX IS 0, ERR
|
|
|
|
CMP #255
|
|
|
|
BEQ :XOVF
|
|
|
|
:ERRCONT3
|
|
|
|
LDA :YIDX
|
|
|
|
CMP #255
|
|
|
|
BEQ :YOVF
|
|
|
|
*
|
|
|
|
********************************
|
|
|
|
*
|
|
|
|
:ERREND
|
2018-11-10 22:41:05 +00:00
|
|
|
*
|
2019-01-21 00:14:17 +00:00
|
|
|
********************************
|
|
|
|
*
|
|
|
|
** MULTIPLY Y-INDEX BY Y-LENGTH
|
2018-11-10 22:41:05 +00:00
|
|
|
LDA #0
|
2019-01-21 00:14:17 +00:00
|
|
|
*
|
2018-11-10 22:41:05 +00:00
|
|
|
TAY
|
|
|
|
STY SCRATCH
|
|
|
|
BEQ :ENTLP
|
|
|
|
*
|
|
|
|
:DOADD
|
|
|
|
CLC
|
2019-01-21 00:14:17 +00:00
|
|
|
ADC :YIDX
|
2018-11-10 22:41:05 +00:00
|
|
|
TAX
|
|
|
|
*
|
|
|
|
TYA
|
|
|
|
ADC SCRATCH
|
|
|
|
TAY
|
|
|
|
TXA
|
|
|
|
*
|
|
|
|
:LP
|
2019-01-21 00:14:17 +00:00
|
|
|
ASL :YIDX
|
2018-11-10 22:41:05 +00:00
|
|
|
ROL SCRATCH
|
|
|
|
:ENTLP
|
2019-01-21 00:14:17 +00:00
|
|
|
LSR :YLEN
|
2018-11-10 22:41:05 +00:00
|
|
|
BCS :DOADD
|
|
|
|
BNE :LP
|
|
|
|
*
|
|
|
|
STX :MLIER
|
|
|
|
STY :MLIER+1
|
|
|
|
*
|
2019-01-21 00:14:17 +00:00
|
|
|
** NOW ADD X INDEX
|
|
|
|
*
|
|
|
|
CLC
|
|
|
|
LDA :MLIER
|
|
|
|
ADC :XIDX
|
|
|
|
STA :MLIER
|
|
|
|
BCC :CONTADD
|
|
|
|
LDA :MLIER+1
|
|
|
|
ADC #1
|
|
|
|
STA :MLIER+1
|
|
|
|
:CONTADD
|
|
|
|
*
|
2018-11-10 22:41:05 +00:00
|
|
|
** NOW MULTIPLY BY LENGTH OF ELEMENTS
|
|
|
|
*
|
|
|
|
LDA #0
|
|
|
|
STA :PROD+2
|
|
|
|
STA :PROD+3
|
|
|
|
LDX #$10
|
|
|
|
:SHIFTR LSR :MLIER+1
|
|
|
|
ROR :MLIER
|
|
|
|
BCC :ROTR
|
|
|
|
LDA :PROD+2
|
|
|
|
CLC
|
|
|
|
ADC :MCAND
|
|
|
|
STA :PROD+2
|
|
|
|
LDA :PROD+3
|
|
|
|
ADC :MCAND+1
|
|
|
|
:ROTR
|
|
|
|
ROR
|
|
|
|
STA :PROD+3
|
|
|
|
ROR :PROD+2
|
|
|
|
ROR :PROD+1
|
|
|
|
ROR :PROD
|
|
|
|
DEX
|
|
|
|
BNE :SHIFTR
|
|
|
|
*
|
2018-12-12 19:29:06 +00:00
|
|
|
CLC
|
2018-11-10 22:41:05 +00:00
|
|
|
INC :PROD ; INCREASE BY 3
|
|
|
|
INC :PROD
|
|
|
|
INC :PROD
|
2018-12-12 19:29:06 +00:00
|
|
|
BCC :NOCAR
|
|
|
|
INC :PROD+1
|
|
|
|
:NOCAR
|
2018-11-10 22:41:05 +00:00
|
|
|
*
|
|
|
|
** NOW ADD BASE ADDRESS OF ARRAY TO GET
|
|
|
|
** THE ADDRESS OF THE INDEX VALUE
|
|
|
|
*
|
|
|
|
CLC
|
|
|
|
LDA :PROD
|
|
|
|
ADC ADDR1
|
|
|
|
STA :PROD
|
|
|
|
LDA :PROD+1
|
|
|
|
ADC ADDR1+1
|
|
|
|
STA :PROD+1
|
|
|
|
*
|
|
|
|
** RETURN ADDRESS IN Y(LOW) AND X(HIGH)
|
|
|
|
*
|
|
|
|
LDY :PROD
|
|
|
|
LDX :PROD+1
|
2019-01-21 00:14:17 +00:00
|
|
|
STY ADDR1
|
|
|
|
STX ADDR1+1
|
|
|
|
LDY #0
|
|
|
|
:RLP
|
|
|
|
LDA (ADDR1),Y
|
|
|
|
STA RETURN,Y
|
|
|
|
INY
|
|
|
|
CPY :ELEN
|
|
|
|
BNE :RLP
|
|
|
|
LDA :ELEN
|
|
|
|
STA RETLEN
|
2018-11-10 22:41:05 +00:00
|
|
|
*
|
|
|
|
** RESTORE RETURN ADDRESS
|
|
|
|
*
|
|
|
|
LDA RETADR+1
|
|
|
|
PHA
|
|
|
|
LDA RETADR
|
|
|
|
PHA
|
|
|
|
*
|
2019-01-21 00:14:17 +00:00
|
|
|
LDA RETLEN
|
|
|
|
LDY ADDR1
|
|
|
|
LDX ADDR1+1
|
2018-11-10 22:41:05 +00:00
|
|
|
RTS
|
|
|
|
*
|
|
|
|
** DATA
|
|
|
|
*
|
|
|
|
:XIDX DS 2
|
|
|
|
:YIDX DS 2
|
2019-01-21 00:14:17 +00:00
|
|
|
:XLEN DS 1
|
|
|
|
:YLEN DS 1
|
2018-11-10 22:41:05 +00:00
|
|
|
:PROD DS 4
|
|
|
|
:MLIER DS 2
|
|
|
|
:MCAND DS 2
|
2019-01-21 00:14:17 +00:00
|
|
|
:ELEN DS 1
|
|
|
|
*
|
|
|
|
:E_SID ASC "AGET82 (GET82 MACRO)",00
|
|
|
|
:E_DUMP ASC ":XIDX(2) :YIDX(2) :XLEN(1) :YLEN(1)"
|
|
|
|
ASC ":PROD(4) :MLIER(2) :MCAND(2) :ELEN(1)",00
|
|
|
|
:E_XOVF ASC "X-OVERFLOW! X IS > MAXIMUM OR IS 0.",00
|
|
|
|
:E_YOVF ASC "Y-OVERFLOW! Y IS > MAX OR IS 0.",00
|
2018-11-10 22:41:05 +00:00
|
|
|
*
|