library updates

- added _RDUMP to required library
- added MSWAP to common library
- deleted full required library from each disk except #2, replaced with min versions (still need to update demos accordingly)
- added beginnings of error handling in required library
This commit is contained in:
nathanriggs 2019-01-09 15:12:55 -05:00
parent 5c0e432186
commit dafe80d008
18 changed files with 4333 additions and 2982 deletions

View File

@ -130,7 +130,7 @@ This disk is dedicated to common and useful subroutines that don't necessarily f
* `MMOVE`: Move a block of memory to another block of memory.
* `ZLOAD`: Retrieve previously save zero page values from a given address and restore them to the zero page.
* `ZSAVE`: Save the zero page memory locations not used by applesoft, dos, etc. to another memory location.
* ~~`MSWAP`~~
* `MSWAP`: Swap a memory range at one address with another.
* required.mac
* `_DUMP`: Dump the contents of a block of memory. This displays hex values only, and is primarily useful for debugging.
@ -140,7 +140,7 @@ This disk is dedicated to common and useful subroutines that don't necessarily f
* `_PRNT`: A standard print routine that mirrors that found in STDIO. This, too, is used mostly for debugging.
* `_SPAR`: Set Parameter. Transfer the contents of one memory location or a literal to the [PARAM] register.
* `_WAIT`: A simple routine that waits for a keypress. Again, useful for debugging.
* ~~`_RDMP`: Registry Dump.~~
* `_RDMP`: Registry Dump without halting execution.
### Disk 3: Arrays
@ -463,6 +463,7 @@ Once Macros are mostly finished in how they are called, you can find how to use
_ISLIT | ```_ISLIT [data]``` | inserts executable code at pointer
_ISSTR | ```_ISSTR [data]``` | inserts executable code at pointer
_PRNT | ```_PRNT [string or address]``` | prints provided literal string
_RDUMP | ```_RDUMP``` | nothing; outputs registry values
_SPAR | ```_SPAR [src address];[length]``` | moves data at address to [param]
_WAIT | ```_WAIT``` | Nothing; wait for keypress.
ADD16 | ```ADD16 [word 1];[word 2] ``` | .Y = lobyte of sum
@ -510,6 +511,7 @@ Once Macros are mostly finished in how they are called, you can find how to use
. | . | .X, .Y = length of string
MFILL | ```MFILL [address start];[length in bytes];[fill value]``` | Nothing useful
MMOVE | ```MMOVE [src addr];[dest addr];[length in bytes]``` | Nothing useful
MSWAP | ```MSWAP [first address];[second address];[length]``` | Nothing
MUL8 | ```MUL8 [multiplicand byte];[multiplier byte]``` | .Y = lobyte of product (word)
. | . | .X = hibyte of product (word)
. | . | [RETURN] = quotient

View File

@ -12,6 +12,7 @@ A general purpose ASM libriary for the Apple II. Assembled in Merlin 8 Pro.
## Table of Contents
* [Introduction](#introduction)
* [FAQ](#faq)
* ~~How to use this Documentation~~
* [Disk Overviews](#disk-overviews)
* [Disk 1: STDIO](#disk-1-stdio)
* [Disk 2: COMMON](#disk-2-common-required)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -729,4 +729,99 @@ ZMLOAD
*
:RETADR DS 2
*
*``````````````````````````````*
* MEMSWAP :: MEMORY SWAP *
*- -*
* SWAPS THE VALUES STORED IN *
* TWO BLOCKS OF SEQUENTIAL *
* MEMORY. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
* LDA #>$6A00 *
* PHA *
* LDA #<$6A00 *
* PHA *
* LDA #>$300 *
* PHA *
* LDA #<$300 *
* PHA *
* LDA #$100 *
* PHA *
* JSR MEMSWAP *
*- -*
* ENTRY *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* LOW BYTE OF FIRST ADDRESS *
* HIGH BYTE OF FIRST ADDRESS *
* LOBYTE OF SECOND ADDRESS *
* HIBYTE OF SECOND ADDRESS *
*- -*
* EXIT *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
MEMSWAP
*
** GET RETURN ADDRESS
*
PLA
STA RETADR
PLA
STA RETADR+1
*
** GET VARIABLES
*
PLA
STA :LENGTH
PLA
STA ADDR1
PLA
STA ADDR1+1
PLA
STA ADDR2
PLA
STA ADDR2+1
*
LDY #255 ; COUNTER
:LP
INY
LDA (ADDR1),Y
TAX ; X CONTAINS ADDR1 VAL
LDA (ADDR2),Y ; A CONTAINS ADDR2 VAL
STA (ADDR1),Y
TXA
STA (ADDR2),Y
CPY :LENGTH
BNE :LP
*
** RESTORE RETURN ADDRESS
*
LDA RETADR+1
PHA
LDA RETADR
PHA
*
RTS
*
** VARIABLES
*
:LENGTH DS 1
*
COMMONX RTS

View File

@ -172,3 +172,33 @@ ZLOAD MAC
PHA
JSR ZMLOAD
<<<
*
*``````````````````````````````*
* MSWAP :: SWAP MEMORY BLOCKS *
*- -*
* SWAPS THE VALUES STORE IN *
* ONE LOCATION WITH ANOTHER *
*- -*
* PARAMETERS: *
* *
* ]1 = FIRST ADDRESS *
* ]2 = SECOND ADDRESS *
* ]3 = LENGTH IN BYTES (BYTE) *
*- -*
* SAMPLE USAGE: *
* MSWAP $300;$400;#$90 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
MSWAP MAC
LDA #>]2
PHA
LDA #<]2
PHA
LDA #>]1
PHA
LDA #<]1
PHA
LDA ]3
PHA
JSR MEMSWAP
<<<

View File

@ -36,11 +36,27 @@ RESULT2 EQU $FC
*
REENTRY EQU $3D0
*
** ERROR HANDLING MEMORY LOCATIONS
*
** THIS DESIGNATES A 16-BYTE BLOCK OF MEMORY
** THAT HOLDS DATA RELATED TO IDENTIFYING
** RUNTIME VALUES FOR DEBUGGING.
*
ERRLOC EQU $0C00
*
** ERROR HANDLING
*
** SET ERRSTOP TO 1 IF YOU WANT THE PROGRAM TO
** HALT WHEN A RUNTIME ERROR OCCURS (BRK)
*
LDA #1
STA ERRSTOP
*
** SET ERRMESG TO 1 IF YOU WANT THE LIBRARY TO
** OUTPUT AN ERROR MESSAGE WHEN AN ERROR OCCURS,
** RATHER THAN JUST PASSING THE ERROR BACK TO
** THE CALLING ROUTINE.
*
LDA #1
STA ERRMESG
*
JMP VARSKIP
ERRSTOP DS 1
ERRMESG DS 1
VARSKIP
*

View File

@ -0,0 +1,17 @@
ADDR1 EQU $06
ADDR2 EQU $08
ADDR3 EQU $EB
ADDR4 EQU $ED
SCRATCH EQU $19
SCRATCH2 EQU $1E
RETADR EQU $FE
RESULT EQU $FA
RESULT2 EQU $FC
REENTRY EQU $3D0
LDA #1
STA ERRMESG
STA ERRSTOP
JMP VARSKIP
ERRSTOP DS 1
ERRMESG DS 1
VARSKIP

View File

@ -92,39 +92,39 @@ __DUMP
PLA
STA :LENGTH
PLA
STA ADDR1
STA ADDR3
PLA
STA ADDR1+1
STA ADDR3+1
*
LDA #$8D
JSR $FDF0
LDA ADDR1+1
LDA ADDR3+1
AND #$F0
LSR
LSR
LSR
LSR
TAX
LDA :HEXTAB,X
LDA HEXTAB,X
JSR $FDF0
LDA ADDR1+1
LDA ADDR3+1
AND #$0F
TAX
LDA :HEXTAB,X
LDA HEXTAB,X
JSR $FDF0
LDA ADDR1
LDA ADDR3
AND #$F0
LSR
LSR
LSR
LSR
TAX
LDA :HEXTAB,X
LDA HEXTAB,X
JSR $FDF0
LDA ADDR1
LDA ADDR3
AND #$0F
TAX
LDA :HEXTAB,X
LDA HEXTAB,X
JSR $FDF0
LDA #186 ; :
JSR $FDF0
@ -133,21 +133,21 @@ __DUMP
*
LDY #0
:LP
LDA (ADDR1),Y
LDA (ADDR3),Y
AND #$F0 ; MASK RIGHT
LSR
LSR
LSR
LSR
STA :LEFT
LDA (ADDR1),Y
LDA (ADDR3),Y
AND #$0F ; MASK LEFT
STA :RIGHT
LDX :LEFT
LDA :HEXTAB,X
LDA HEXTAB,X
JSR $FDF0
LDX :RIGHT
LDA :HEXTAB,X
LDA HEXTAB,X
JSR $FDF0
LDA #160
JSR $FDF0
@ -168,7 +168,6 @@ __DUMP
:RIGHT DS 1
:LEFT DS 1
:LENGTH DS 1
:HEXTAB ASC "0123456789ABCDEF"
*
*``````````````````````````````*
* __P: PRINT FOLLOWING ASC *
@ -208,6 +207,149 @@ __W
JSR $FD0C
RTS
*
*``````````````````````````````*
* __RDMP: REGISTRY DUMP *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
__RDMP
STA :A
STX :X
STY :Y
:C BCC :C0
BCS :C1
:Z BEQ :Z1
BNE :Z0
:N BMI :N1
BPL :N0
:O BVC :O0
BVS :O1
JMP :RDUMP
:C0 LDA #0
STA :CARRY
JMP :Z
:C1 LDA #1
STA :CARRY
JMP :Z
:Z1 LDA #1
STA :ZERO
JMP :N
:Z0 LDA #0
STA :ZERO
JMP :N
:N1 LDA #1
STA :NEGATIVE
JMP :O
:N0 LDA #0
STA :NEGATIVE
JMP :O
:O0 LDA #0
STA :OVERFLOW
JMP :RDUMP
:O1 LDA #1
STA :OVERFLOW
*
:RDUMP
_PRNT " ",8D8D
_PRNT "REGISTRY DUMP",8D
_PRNT "=============",8D
_PRNT "A: "
LDA :A
AND #$F0 ; MASK RIGHT
LSR
LSR
LSR
LSR
STA :LEFT
LDA :A
AND #$0F ; MASK LEFT
STA :RIGHT
LDX :LEFT
LDA HEXTAB,X
JSR $FDF0
LDX :RIGHT
LDA HEXTAB,X
JSR $FDF0
_PRNT " ",8D
_PRNT "X: "
LDA :X
AND #$F0 ; MASK RIGHT
LSR
LSR
LSR
LSR
STA :LEFT
LDA :X
AND #$0F ; MASK LEFT
STA :RIGHT
LDX :LEFT
LDA HEXTAB,X
JSR $FDF0
LDX :RIGHT
LDA HEXTAB,X
JSR $FDF0
_PRNT " ",8D
_PRNT "Y: "
LDA :Y
AND #$F0 ; MASK RIGHT
LSR
LSR
LSR
LSR
STA :LEFT
LDA :Y
AND #$0F ; MASK LEFT
STA :RIGHT
LDX :LEFT
LDA HEXTAB,X
JSR $FDF0
LDX :RIGHT
LDA HEXTAB,X
JSR $FDF0
_PRNT " ",8D8D
_PRNT "STATUS FLAGS",8D
_PRNT "============",8D8D
LDA #0
CMP :CARRY
BEQ :CARCLR
_PRNT "CARRY: SET",8D
JMP :TESTN
:CARCLR _PRNT "CARRY: CLEAR",8D
:TESTN LDA #0
CMP :NEGATIVE
BEQ :NEGCLR
_PRNT "NEGATIVE: SET",8D
JMP :TESTZ
:NEGCLR _PRNT "NEGATIVE: CLEAR",8D
:TESTZ LDA #0
CMP :ZERO
BEQ :ZCLR
_PRNT "ZERO: SET",8D
JMP :TESTO
:ZCLR _PRNT "ZERO: CLEAR",8D
:TESTO
LDA #0
CMP :OVERFLOW
BEQ :OCLR
_PRNT "OVERFLOW: SET",8D
JMP :FIN
:OCLR _PRNT "OVERFLOW: CLEAR",8D8D8D
:FIN
RTS
*
** DATA
*
:A DS 1
:X DS 1
:Y DS 1
:LEFT DS 1
:RIGHT DS 1
:OVERFLOW DS 1
:NEGATIVE DS 1
:CARRY DS 1
:ZERO DS 1
HEXTAB ASC "0123456789ABCDEF"
*
*
********************************
* *
* GLOBAL VARIABLES *

View File

@ -0,0 +1,285 @@
__GETRET
*
LDY #255
PLA
STA ADDR1
PLA
STA ADDR1+1
*
:LP
INY
LDA RETURN,Y
STA (ADDR1),Y
CPY RETLEN
BNE :LP
LDA ADDR1+1
PHA
LDA ADDR1
PHA
RTS
__SETPARM
*
LDY #255
PLA
STA ADDR1
PLA
STA ADDR1+1
*
:LP
INY
LDA (ADDR1),Y
STA PARAM,Y
CPY PARLEN
BNE :LP
LDA ADDR1+1
PHA
LDA ADDR1
PHA
RTS
__DUMP
*
PLA
STA :RET
PLA
STA :RET+1
PLA
STA :LENGTH
PLA
STA ADDR3
PLA
STA ADDR3+1
*
LDA #$8D
JSR $FDF0
LDA ADDR3+1
AND #$F0
LSR
LSR
LSR
LSR
TAX
LDA HEXTAB,X
JSR $FDF0
LDA ADDR3+1
AND #$0F
TAX
LDA HEXTAB,X
JSR $FDF0
LDA ADDR3
AND #$F0
LSR
LSR
LSR
LSR
TAX
LDA HEXTAB,X
JSR $FDF0
LDA ADDR3
AND #$0F
TAX
LDA HEXTAB,X
JSR $FDF0
LDA #186 ; :
JSR $FDF0
LDA #160 ; SPC
JSR $FDF0
*
LDY #0
:LP
LDA (ADDR3),Y
AND #$F0 ; MASK RIGHT
LSR
LSR
LSR
LSR
STA :LEFT
LDA (ADDR3),Y
AND #$0F ; MASK LEFT
STA :RIGHT
LDX :LEFT
LDA HEXTAB,X
JSR $FDF0
LDX :RIGHT
LDA HEXTAB,X
JSR $FDF0
LDA #160
JSR $FDF0
INY
CPY :LENGTH
BNE :LP
LDA :RET+1
PHA
LDA :RET
PHA
*
RTS
*
:RET DS 2
:RIGHT DS 1
:LEFT DS 1
:LENGTH DS 1
__P
PLA
STA ADDR1
PLA
STA ADDR1+1
LDY #1
:LP LDA (ADDR1),Y
BEQ :DONE
JSR $FDF0
INY
BNE :LP
:DONE CLC
TYA
ADC ADDR1
STA ADDR1
LDA ADDR1+1
ADC #0
PHA
LDA ADDR1
PHA
RTS
__W
JSR $FD0C
RTS
__RDMP
STA :A
STX :X
STY :Y
:C BCC :C0
BCS :C1
:Z BEQ :Z1
BNE :Z0
:N BMI :N1
BPL :N0
:O BVC :O0
BVS :O1
JMP :RDUMP
:C0 LDA #0
STA :CARRY
JMP :Z
:C1 LDA #1
STA :CARRY
JMP :Z
:Z1 LDA #1
STA :ZERO
JMP :N
:Z0 LDA #0
STA :ZERO
JMP :N
:N1 LDA #1
STA :NEGATIVE
JMP :O
:N0 LDA #0
STA :NEGATIVE
JMP :O
:O0 LDA #0
STA :OVERFLOW
JMP :RDUMP
:O1 LDA #1
STA :OVERFLOW
*
:RDUMP
_PRNT " ",8D8D
_PRNT "REGISTRY DUMP",8D
_PRNT "=============",8D
_PRNT "A: "
LDA :A
AND #$F0 ; MASK RIGHT
LSR
LSR
LSR
LSR
STA :LEFT
LDA :A
AND #$0F ; MASK LEFT
STA :RIGHT
LDX :LEFT
LDA HEXTAB,X
JSR $FDF0
LDX :RIGHT
LDA HEXTAB,X
JSR $FDF0
_PRNT " ",8D
_PRNT "X: "
LDA :X
AND #$F0 ; MASK RIGHT
LSR
LSR
LSR
LSR
STA :LEFT
LDA :X
AND #$0F ; MASK LEFT
STA :RIGHT
LDX :LEFT
LDA HEXTAB,X
JSR $FDF0
LDX :RIGHT
LDA HEXTAB,X
JSR $FDF0
_PRNT " ",8D
_PRNT "Y: "
LDA :Y
AND #$F0 ; MASK RIGHT
LSR
LSR
LSR
LSR
STA :LEFT
LDA :Y
AND #$0F ; MASK LEFT
STA :RIGHT
LDX :LEFT
LDA HEXTAB,X
JSR $FDF0
LDX :RIGHT
LDA HEXTAB,X
JSR $FDF0
_PRNT " ",8D8D
_PRNT "STATUS FLAGS",8D
_PRNT "============",8D8D
LDA #0
CMP :CARRY
BEQ :CARCLR
_PRNT "CARRY: SET",8D
JMP :TESTN
:CARCLR _PRNT "CARRY: CLEAR",8D
:TESTN LDA #0
CMP :NEGATIVE
BEQ :NEGCLR
_PRNT "NEGATIVE: SET",8D
JMP :TESTZ
:NEGCLR _PRNT "NEGATIVE: CLEAR",8D
:TESTZ LDA #0
CMP :ZERO
BEQ :ZCLR
_PRNT "ZERO: SET",8D
JMP :TESTO
:ZCLR _PRNT "ZERO: CLEAR",8D
:TESTO
LDA #0
CMP :OVERFLOW
BEQ :OCLR
_PRNT "OVERFLOW: SET",8D
JMP :FIN
:OCLR _PRNT "OVERFLOW: CLEAR",8D8D8D
:FIN
RTS
*
** DATA
*
:A DS 1
:X DS 1
:Y DS 1
:LEFT DS 1
:RIGHT DS 1
:OVERFLOW DS 1
:NEGATIVE DS 1
:CARRY DS 1
:ZERO DS 1
HEXTAB ASC "0123456789ABCDEF"
RETLEN DS 1 ; RETURN VALUE BYTE LENGTH
RETURN DS 256
PARLEN DS 1
PARAM DS 256

View File

@ -15,6 +15,68 @@
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
*``````````````````````````````*
* _ISLIT: DETERMINES WHETHER A *
* PARAM IS LITERAL OR *
* NOT, AND CHANGES *
* APPROPRIATELY. FOR *
* MACRO USE ONLY. *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
_ISLIT MAC
IF #=]1 ; IF ]1 IS A LITERAL
LDA ]1/$100 ; GET HI
PHA
LDA ]1 ; GET LO
PHA
ELSE ; ]1 IS ADDRESS
LDA ]1+1 ; SO GET HIGH VAL FROM ADDR
PHA
LDA ]1 ; THEN LO VAL
PHA
FIN
<<<
*
*``````````````````````````````*
* _ISSTR: DETERMINES WHETHER A *
* PARAM IS A STRING OR *
* NOT, AND CHANGES *
* APPROPRIATELY. FOR *
* MACRO USE ONLY. *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
_ISSTR MAC
IF "=]1 ; IF ]1 IS A STRING
*
** STORE STRING AT TEMP ADDRESS, THEN
** PUSH TEMP ADDRESS
*
JMP STRCONT
]STRTMP STR ]1
STRCONT
LDY #0
LDA ]STRTMP
STA PARLEN
STA PARAM
]STRLP1
INY
LDA ]STRTMP,Y
STA PARAM,Y
CPY PARLEN
BNE ]STRLP1
*
LDA #>PARAM ; GET HI
PHA
LDA #<PARAM ; GET LO
PHA
ELSE ; ]1 IS ADDRESS
LDA #>]1 ; SO GET HIBYTE OF ADDR
PHA
LDA #<]1 ; THEN LOBYTE
PHA
FIN
<<<
*
*``````````````````````````````*
* _GRET: GET RETURN VALUE *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
@ -70,3 +132,11 @@ _WAIT MAC
JSR __W
<<<
*
*``````````````````````````````*
* _RDUMP: DUMP REGISTERS *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
_RDUMP MAC
JSR __RDMP
<<<
*

View File

@ -0,0 +1,75 @@
_ISLIT MAC
IF #=]1 ; IF ]1 IS A LITERAL
LDA ]1/$100 ; GET HI
PHA
LDA ]1 ; GET LO
PHA
ELSE ; ]1 IS ADDRESS
LDA ]1+1 ; SO GET HIGH VAL FROM ADDR
PHA
LDA ]1 ; THEN LO VAL
PHA
FIN
<<<
_ISSTR MAC
IF "=]1 ; IF ]1 IS A STRING
JMP STRCONT
]STRTMP STR ]1
STRCONT
LDY #0
LDA ]STRTMP
STA PARLEN
STA PARAM
]STRLP1
INY
LDA ]STRTMP,Y
STA PARAM,Y
CPY PARLEN
BNE ]STRLP1
*
LDA #>PARAM ; GET HI
PHA
LDA #<PARAM ; GET LO
PHA
ELSE ; ]1 IS ADDRESS
LDA #>]1 ; SO GET HIBYTE OF ADDR
PHA
LDA #<]1 ; THEN LOBYTE
PHA
FIN
<<<
_GRET MAC
LDA #>]1
PHA
LDA #<]1
PHA
JSR __GETRET
<<<
_SPAR MAC
LDA #>]1
PHA
LDA #<]1
PHA
JSR __SETPARM
<<<
_DUMP MAC
LDA #>]1
PHA
LDA #<]1
PHA
LDA ]2
PHA
JSR __DUMP
<<<
_PRNT MAC
JSR __P
ASC ]1
HEX 00
<<<
_WAIT MAC
JSR __W
<<<
_RDUMP MAC
JSR __RDMP
<<<
*