AppleIIAsm-Collection/disks/disk3_arrays/T.ADIM81.SUB.MIN
nathanriggs ad58479739 Disk 3: ARRAYS 0.3.0 updates
- major bugfixes, especially in 2D arrays
- separated each subroutine into own file
- reconfigured arrays to use 1-based indexing
- Arrays.demo uses macros now
- added overflow error handling to get and put routines
2019-01-20 19:14:17 -05:00

93 lines
2.1 KiB
Plaintext

ADIM81
PLA
STA RETADR
PLA
STA RETADR+1
PLA
STA :FILL ; FILL VALUE
PLA
STA :ESIZE ; ELEMENT SIZE
STA :ESZBAK
PLA
STA :ASIZE ; ARRAY SIZE
STA :ASZBAK
PLA
STA ADDR1 ; ARRAY ADDRESS
PLA
STA ADDR1+1
LDY #0
LDA #0
STY SCRATCH
BEQ :ENTLP
:DOADD
CLC
ADC :ASIZE
TAX
TYA
ADC SCRATCH
TAY
TXA
:LP
ASL :ASIZE
ROL SCRATCH
:ENTLP
LSR :ESIZE
BCS :DOADD
BNE :LP
CLC
INX
INX ; INCREASE BY TWO
; TO MAKE ROOM FOR SIZES
BCC :NOINY ; IF .X ROLLS OVER, INC .Y
INY
:NOINY
STX :MSIZE ; LOW BYTE
STY :MSIZE+1 ; HIGH BYTE
LDA :FILL ; FILL VALUE
LDX :MSIZE+1
BEQ :PART ; IF NO WHOLE PAGES, JUST PART
LDY #0
:FULL
STA (ADDR1),Y
INY ; NEXT BYTE
BNE :FULL ; LOOP UNTIL PAGE DONE
INC ADDR1+1 ; GO TO NEXT PAGE
DEX
BNE :FULL ; LOOP IF PAGES LEFT
:PART
LDX :MSIZE ; PARTIAL PAGE BYTES
BEQ :MFEXIT ; EXIT IF = 0
LDY #0
:PARTLP
STA (ADDR1),Y ; STORE VAL
INY ; INC INDEX
DEX ; DEC COUNTER
BNE :PARTLP ; LOOP UNTIL DONE
:MFEXIT
LDY #0
LDA :ASZBAK
STA (ADDR1),Y
INY
LDA :ESZBAK
STA (ADDR1),Y
LDA RETADR+1
PHA
LDA RETADR
PHA
LDY ADDR1 ; LOW
LDX ADDR1+1 ; HIGH
LDA :ASZBAK
LDA :MSIZE
STA RETURN
LDA :MSIZE+1
STA RETURN+1
LDA #2
STA RETLEN ; 2 BYTE LENGTH
RTS
:MSIZE DS 2
:ASIZE DS 1
:ESIZE DS 1
:ASZBAK DS 1
:ESZBAK DS 1
:FILL DS 1