Completed module 'block'

This commit is contained in:
Curtis F Kaylor 2018-07-30 20:03:56 -04:00
parent bbb55e2946
commit 40b51fcb36
4 changed files with 492 additions and 329 deletions

View File

@ -17,6 +17,7 @@ the variable length (at index 8).
Usage: at the beginning of the program use the directives
#include <stddef.h02>
#include <memory.h02>
#include <string.h02>
#include <block.h02>
@ -37,74 +38,103 @@ The following application functions are defined:
a block is the byte after the last byte of memory in
the block.
Although a block usually begins on a 256 byte
Although a block usually ends on a 256 byte
boundary, this is not required.
Note: Sets variables blkslo and blkshi.
Note: Sets variables blkelo and blkehi.
blkseg(n); Block Segment: Set block segment size to n.
Required before calls any calls that manipulate
block segments.
Note: Sets blklen to n.
blkset(c); Block Set: Fill entire block with character c,
blkset(c); Block Set: Fills entire block with character c,
leaving block pointer at end of block.
Used to initialize a block before use.
Should be called with an argument of 0, to initialize
a block before use.
blkrst(); Block Reset: Set block segment pointer to block
blkrst(); Block Reset: Sets block segment pointer to block
begin address.
This routine is called before populating a block with
calls to the blkapd function.
calls to the blkput function.
blknxt(); Block Next: Move block pointer forward by the segment
blkptr(&d); Block Pointer: Sets the block pointer to the address
of b.
Does not validate that the address is within the
beginning and ending address of the block.
Note: Sets variables blkslo and blkshi.
blknxt(); Block Next: Moves block pointer forward by the segment
length set by a prior blkseg call.
If the block pointer is moved past the end of the
block, a value of 0 (false) is returned. Otherwise,
a value of 255 (true) is returned.
block, or the segmebt length is set to 0, a value of
#TRUE is returned. Otherwise, a value of #FALSE is
returned.
blkput(n ,&m); Block Append: Copy n bytes of array m to block
at current pointer location, and moves block pointer
blkprv(); Block Previous: Moves block pointer backward by the
segment length set by a prior blkseg call.
If the block pointer is moved past the beginning of
the block, or the segmebt length is set to 0, a value
of #TRUE is returned. Otherwise, a value of #FALSE is
returned.
blkput(n ,&m); Block Put: Copies n bytes of array m to a block at the
current pointer location, and moves block the pointer
forward by the segment length set by a prior blkseg
call.
If the appended bytes would overflow the end of the
block, no bytes are copied and a value of 0 (false)
is returned. Otherwise, the bytes are copied and
a value of 255 (true) is returned.
block, no bytes are copied and a value of #FALSE is
returned. Otherwise, the bytes are copied and a value
of #TRUE is returned.
Note: Sets dstlo and dsthi to the block pointer prior
to the copy, updates blkslo and blkshi, then calls
Note: Sets dstlo and dsthi to blklo and blkhi prior
to the copy, updates blklo and blkhi, then calls
the memcpy function.
blkget(n ,&m); Block Get: Copy n bytes from block at current
pointer location to array m, and moves block pointer
blkget(n ,&m); Block Get: Copies n bytes from a block at the current
pointer location to array m, and moves the pointer
forward by the segment length set by a prior blkseg
call.
If the copied bytes would overflow the end of the
block, no bytes are copied and a value of 0 (false)
is returned. Otherwise, the bytes are copied and
a value of 255 (true) is returned.
block, no bytes are copied and a value #FALSE is
returned. Otherwise, the bytes are copied and a value
of #TRUE is returned.
Note: Sets dstlo and dsthi to the address of m,
srclo and srchi to the block pointer prior to the
srclo and srchi to blklo and blkhi prior to the
copy, updates blkslo and blkshi, then calls the
memcpy function.
blkswp(n); Block Swap: Swaps n bytes of array m with the current
block segment (pointed to by the block pointer. The
block pointer is not changed.
Requires a prior call to the memdst function specifying
an array at least n bytes long, which is used for
temporary storage.
Note: Sets temp0 to n, copies blklo and blkhi to dstlo,
and dsthi, and calls memswp.
blkmem(n ,&m); Block Memory search: Search block for n byte long
segment matching array m.
If a matching segment is found, the value 255 (true)
is returned and the destination pointer is set to the
If a matching segment is found, the value #TRUE is
returned and the destination pointer is set to the
address of the matching segment, allowing it to be
overwritten with a subsequent memcpy call. Otherwise,
the value 0 (false) is returned.
the value #FALSE is returned.
Note: Sets srclo and srchi to the address of m,
dstlo and dsthi to the address of the matching segment,
and temp0 to n. Does not change the block pointer.
@ -121,17 +151,6 @@ The following application functions are defined:
segment, temp0 to n, and copies dstlo and dsthi to
temp1 and temp2. Does not change the block pointer.
blkswp(n); Block Swap: Swaps n bytes of array m with the current
block segment (pointed to by the block pointer. The
block pointer is not changed.
Requires a prior call to the memdst function specifying
an array at least n bytes long, which is used for
temporary storage.
Note: Sets temp0 to n, copies blklo and blkhi to dstlo,
and dsthi, and calls memswp.
blksrt(&m); Block Sort: Sort segments in block by initial string,
using array m as temporary storage.
@ -144,6 +163,14 @@ The following application functions are defined:
Note: Uses the selection sort algorithm. Sets temp1
and temp2 to the address of array m.
blkdst(); Block Destination: Sets the destination pointer to the
block segment pointer.
This is a utility function called by other functions in
this module.
Note: Sets dstlo and dsthi to blklo and blkhi.
Note: This library expects the following functions to be defined
setdst(&s); Set destination string pointer

View File

@ -12,100 +12,121 @@
;Args: X,Y = Address
;Sets: BLKSLO, BLKSHI = Block Start Address
;Affects: Z, N
BLKBGN: STX BLKSLO ;Save Block Start Low Byte
STY BLKSHI ;Save Block Start High Byte
BLKBGN: STX BLKSLO ;Save Block Start LSB
STY BLKSHI ;Save Block Start MSB
RTS
;blkend(&b) - Set Block End Address (+1)
;Args: X,Y = Address
;Sets: BLKELO, BLKEHI = Block End Address
;Affects: Z, N
BLKEND: STX BLKELO ;Save Block End Low Byte
STY BLKEHI ;Save Block End High Byte
BLKEND: STX BLKELO ;Save Block End LSB
STY BLKEHI ;Save Block End MSB
RTS
;blkrst() - Reset Block Segment Pointer to Start Address
;Uses: BLKSLO, BLKSHI = Block Start Address
;Sets: BLKLO, BLKHI = Block Pointer
;Affects: Z, N
;Returns: X = Block Pointer Low Byte
; Y = Block Pointer High Byte
BLKRST: LDX BLKSLO ;Load X with Block Start Low Byte
LDY BLKSHI ;Load X with Block Start High Byte
;Set Block Address
BLKSXY: STX BLKLO ;Store X in Block Pointer Low Byte
STY BLKHI ;Store Y in Block Pointer High Byte
;Returns: X = Block Pointer LSB
; Y = Block Pointer MSB
BLKRST: LDX BLKSLO ;Load X with Block Start LSB
LDY BLKSHI ;Load Y with Block Start MSB
;and fall into BLKPTR
;blkptr() - Set Block Pointer Address
;Args: X,Y = Address LSB, MSN
;Sets: BLKLO, BLKHI = Block Pointer
;Affects: Z, N
;Returns: X = Block Pointer LSB
; Y = Block Pointer MSB
BLKPTR: STX BLKLO ;Store X in Block Pointer LSB
STY BLKHI ;Store Y in Block Pointer MSB
RTS ;Exit Routine
;blkcpe() - Compare Block Pointer to Block End
;Uses: BLKLO, BLKHI = Block Pointer
; BLKELO, BLKEHI = Block End Address
;Affects: X,N
;Returns: C=0,Z=0 if Pointer before End
; C=1,Z=1 if Pointer at End
; C=1,Z=0 if Pointer after End
BLKCPE: LDX BLKHI ;Get Block Pointer MSB
CPX BLKEHI ;Compare to Block End MSB
BCC BLKCPX ;If Pointer Not Less than
BNE BLKCPX ;or Equal to End
LDX BLKLO ; Get Block Pointer LSB
CPX BLKELO ; Compare to Block End LSB
BLKCPX: RTS
;blkset(c) - Set All Bytes in Block to Character c
;Args: c - Value to Set all Bytes to
;Uses: BLKSLO, BLKSHI = Block Start Address
; BLKELO, BLKEHI = Block End Address
;
;Uses: BLKSLO, BLKSHI - Block Start Address
; BLKELO, BLKEHI - Block End Address
;Sets: BLKLO, BLKHI = Start of Block
;Returns: A - Value of Argument n
BLKSET: JSR BLKRST ;Reset Block Pointer
LDY #0 ;Initialize Index
BLKSEL: LDX BLKHI ;Get Block Pointer High Byte
CPX BLKEHI ;Compare to Block End High Byte
BNE BLKSES ; If Equal
LDX BLKLO ; Get Block Pointer Low Byte
CPX BLKELO ; Compare to Block End Low Byte
BEQ BLKSEX ; If Equal Exit Routine
BLKSES: STA (BLKLO),Y ;Store Value at Block Pointer Address
INC BLKLO ;Increment Block Pointer Low Byte
BNE BLKSEL ;If Not End of Page, Loop
INC BLKHI ;Increment Block Pointer High Byte
JMP BLKSEL ;If Not End of Memory, Loop
BLKSEX: RTS ;Return
BLKSET: JSR BLKRST ;Reset Block Pointer
LDY #0 ;Initialize Index
BLKSEL: JSR BLKCPE ;Compare Pointer to Block End
BCS BLKSEX ;If Past End, Exit Routine
STA (BLKLO),Y ;Store Value at Block Pointer Address
INC BLKLO ;Increment Block Pointer LSB
BNE BLKSEL ;If Not End of Page, Loop
INC BLKHI ;Increment Block Pointer MSB
BNE BLKSEL ;If Not End of Memory, Loop
BLKSEX: JMP BLKRST ;Reset Block Pointer and Return
;blkput(n, &m) - Append n Bytes of m to Block
;Args: n = Number of Bytes to Append
; m = Array of Bytes to Append
;Uses: BLKELO, BLKEHI = Block End Address
;Uses: BLKELO, BLKEHI - Block End Address
;Sets: DSTLO, DSTHI = Pointer to Bytes in Block
; SRCHI, SRCLO = Pointer to m
; TEMP0 = Number of Bytes to Append
;Updates: BLKLO, BLKHI = Block Pointer
;Returns: A=$FF - Append Successful
; A=$00 - Block Overflow
BLKPUT: JSR SETSRC ;Save Source Pointer
JSR MEMSRA ;Save Number of Bytes to Append
BLKPUT: JSR MEMSRC ;Set Source Address & Number of Bytes
JSR BLKDST ;Set Destination to Block Pointer
JMP BLKNCP ;Move Block Pointer and Copy
;blkget(n, &m) - Read n Bytes of Block into Array m
;Args: n = Number of Bytes to Read
; m = Array to Read Bytes into
;blkget(n, &m) - Read n Bytes of Current Segment into Array m
;Args: A = Number of Bytes to Read
; Y,X = Address of Array
;Uses: BLKELO, BLKEHI = Block End Address
;Sets: DSTLO, DSTHI = Pointer to Bytes in Block
; SRCHI, SRCLO = Pointer to m
;Sets: DSTLO, DSTHI = Address of Array
; SRCHI, SRCLO = Current Pointer in Block
; TEMP0 = Number of Bytes to Append
;Updates: BLKLO, BLKHI = Block Pointer
;Updates: BLKLO, BLKHI = Next Segment in Block
;Returns: A=$FF - Append Successful
; A=$00 - Block Overflow
BLKGET: JSR MEMSRC ;Set Source Address & Number of Bytes
JSR BLKSRC ;Set Source Pointer to Block Pointer
BLKNCP: JSR BLKNXT ;Move Block Pointer
BEQ BLKRTS ;If Past End of Block, Return False
JMP BLKCPY ;Else Copy Bytes
BLKGET: JSR SETDST ;Set Destination Address
JSR MEMSRA ;Save Number of Bytes to Copy
JSR BLKSRC ;Set Source Pointer to Block Pointer
BLKNCP: JSR BLKNXT ;Move Block Pointer
BEQ BLKRTS ;If Past End of Block, Return False
BLKCPY: LDY #0 ;Copy Source To Destination
JSR MEMCPL ;
LDA #$FF ;Return TRUE
RTS
;blkmem(n, &m) - Search for n Bytes of m in Block
;Args: n = Segment Size to Search in Bytes
;Args: n = Number of Bytes to Compare
; m = Array of Bytes to Search For
;Sets: DSTLO, DSTHI = Pointer to Segment in Block
; SRCHI, SRCLO = Pointer to m
; TEMP0 = Number of Bytes to Append
; TEMP0 = Number of Bytes to Compare
;Returns: A=$FF - Bytes found
; A=$00 - Bytes not found
BLKMEM: JSR MEMSRC ;Initialize Source, Index, and Count
JSR BLKSRS ;Set Destination Pointer To Block Start
BLKMEL: LDY #0 ;Initialize Index
JSR MEMCML ;Compare Source to Destination
BEQ BLKTRU ;If Equal, Exit TRUE
JSR BLKDSN ;Move Destination Pointer
BNE BLKMEL ;If Not Past Block End, Loop
;Else
BLKFLS: LDA #$00 ; Return FALSE
BLKMEM: JSR MEMSRC ;Initialize Source, Index, and Count
JSR BLKDSS ;Set Destination Pointer To Block Start
LDX #DSTLO ;Set BLKNXX Pointer to SRCLO,SRCHI
BLKMEL: LDY #0 ;Initialize Index
JSR MEMCML ;Compare Source to Destination
BEQ BLKTRU ;If Equal, Exit TRUE
JSR BLKNXX ;Move Destination Pointer
BNE BLKMEL ;If Not Past Block End, Loop
BLKFLS: LDA #FALSE ; Return FALSE
RTS
;blkseg(n) - Set Block Segment Length
@ -113,73 +134,82 @@ BLKFLS: LDA #$00 ; Return FALSE
;Sets: TEMP0 = Segment Size
;Returns: A=$FF - Segment Length Successfully Set
; A=$00 - Error: Segment Length not Set
BLKSEG: STA BLKLEN ;Store Argument in Block Length
ORA #0 ;If Segment Length is Zero
BEQ BLKFLS ; Return False
;Else
BLKTRU: LDA #$FF ; Return TRUE
BLKSEG: STA BLKLEN ;Store Argument in Block Length
ORA #0 ;If Segment Length is Zero
BEQ BLKFLS ; Return False
BLKTRU: LDA #TRUE ;Return TRUE
BLKRTS: RTS
;blkdsn() - Move Destination Pointer to Next Segment
;BLKNXD() - Move Destination Pointer to Next Segment
;Uses: BLKLEN - Block Segment Length
;Updates: DSTLO, DSTHI = Block Pointer
;Affects: C,N,Z
;Returns: A=$FF - Destination Pointer Moved
; A=$00 - Error: Pointer Overflow or Length 0
BLKDSN: LDA BLKLEN ;Get Segment Length
BEQ BLKRTS ;If 0 Return False
BLKNXD: LDX #DSTLO ;Set X to Destination Pointer
JMP BLKNXX ;and Move to Next Segment
;blknxx() - Move Pointer to Next Segment
;Args: X = Zero Page Address of Pointer
;Uses: BLKLEN - Block Segment Length
;Updates: DSTLO, DSTHI = Block Pointer
;Affects: C,N,Z
;Returns: A=$FF - Destination Pointer Moved
; A=$00 - Error: Pointer Overflow or Length 0
BLKNXX: LDA BLKLEN ;Get Segment Length
BEQ BLKRTS ;If 0 Return False
CLC
ADC DSTLO ;Add to Destination Low Byte
STA DSTLO
LDA DSTHI ;Add Carry
ADC #0 ;to Destination High Byte
STA DSTHI ;If Destination High Byte
CMP BLKEHI ; < Block End High Byte
BCC BLKTRU ; Return True
LDA DSTLO ;Else
JMP BLKNXL ; Check Destination Low Byte
ADC 0,X ;Add to Pointer LSB
STA 0,X
LDA 1,X ;Add Carry
ADC #0 ;to Pointer MSB
STA 1,X ;If Destination MSB
CMP BLKEHI ; < Block End MSB
BCC BLKTRU ; Return True
LDA 0,X ;If Destination LSB
CMP BLKELO ; < Block End LSB
BCC BLKTRU ; Return True
BCS BLKFLS ;Return False
;blknxt(n) - Move Block Pointer to Next Segment
;blknxt(n) - Move Block Pointer to Next Segment
;Uses: BLKLEN - Block Segment Length
;Updates: BLKLO, BLKHI = Block Pointer
;Affects: C,N,Z
;Returns: A=$FF - Destination Pointer Moved
; A=$00 - Error: Pointer Overflow or Length 0
BLKNXT: LDA BLKLEN ;Get Segment Length
BEQ BLKRTS ;If 0 Return False
BLKNXT: LDA BLKLEN ;Get Segment Length
BEQ BLKRTS ;If 0 Return False
CLC
ADC BLKLO ;Add to Block Pointer Low Byte
ADC BLKLO ;Add to Block Pointer LSB
STA BLKLO
LDA BLKHI ;Add Carry
ADC #0 ;to Block Pointer High Byte
STA BLKHI ;If Block Pointer High Byte
CMP BLKEHI ; < Block End High Byte
BCC BLKTRU ; Exit True
LDA BLKLO ;Else If Destination Low Byte
BLKNXL: CMP BLKELO ; < Block End low Byte
BCC BLKTRU ; Return True
BCS BLKFLS ;Else Return False
LDA BLKHI ;Add Carry
ADC #0 ;to Block Pointer MSB
STA BLKHI ;If Block Pointer MSB
JSR BLKCPE ;Compare Pointer to End
BCC BLKTRU ; Return True
BCS BLKFLS ;Else Return False
;blkprv(n) - Move Block Pointer to Previous Segment
;Uses: BLKLEN - Block Segment Length
;Updates: BLKLO, BLKHI = Block Pointer
;Affects: C,N,Z
;Returns: A=$FF - Destination Pointer Moved
; A=$00 - Error: Pointer Overflow or Length 0
BLKPRV: LDA BLKLEN ;Get Segment Length
BEQ BLKRTS ;If 0 Return False
; A=$00 - Error: Pointer Underflow or Length 0
BLKPRV: LDA BLKLEN ;Get Segment Length
BEQ BLKRTS ;If 0 Return False
LDA BLKLO ;From Block Pointer LSB
SEC
SBC BLKLO ;Add to Block Pointer Low Byte
SBC BLKLEN ;Subtract Segment Length
STA BLKLO
LDA BLKHI ;Add Carry
SBC #0 ;to Block Pointer High Byte
STA BLKHI ;If Block Pointer High Byte
CMP BLKEHI ; >= Block Start High Byte
BCS BLKTRU ; Exit True
LDA BLKLO ;Else If Destination Low Byte
BLKPRL: CMP BLKELO ; >= Block End low Byte
BCS BLKTRU ; Return True
BCC BLKFLS ;Else Return False
LDA BLKHI ;Subtract Borrow
SBC #0 ;from Block Pointer MSB
STA BLKHI ;If Block Pointer MSB
CMP BLKEHI ; >= Block Start MSB
BCS BLKTRU ; Exit True
LDA BLKLO ;Else If Destination LSB
BLKPRL: CMP BLKELO ; >= Block End LSB
BCS BLKTRU ; Return True
BCC BLKFLS ;Else Return False
;blksrt(&m) - Sort Block
;Args: m = Array of at least n Bytes for Temporary Storage
@ -191,63 +221,66 @@ BLKPRL: CMP BLKELO ; >= Block End low Byte
; DSTLO, DSTHI = Pointer to Segment in Block
; SRCHI, SRCLO = Pointer to Segment in Block
;Affects: A,Y,C,N,Z
BLKSRT: LDA BLKLEN ;Get Segment Length
BEQ BLKRTS ;If 0 Return
STA TEMP0 ;Else Set Memory Swap Byte Count
JSR BLKRST ;Set Block Pointer to Block Start
BLKSRP: LDY #0 ;If First Byte of
LDA (BLKLO),Y ; Current Segment is Null
BEQ BLKRTS ; Return
JSR BLKSRC ;Copy Block Pointer to Source Pointer
JSR BLKDST ;Copy Block Pointer and Destination Pointer
BLKSRD: JSR BLKDSN ;Move Destination Pointer
BCS BLKSRC ;If Not Past Block End
LDY #0 ;
LDA (DSTLO),Y ;and Destination String Populated
BEQ BLKSRC ;
JSR STRCML ; Compare Destination String with Source String
BPL BLKSRD ; If Destination < Source
JSR SETSRD ; Set Source Pointer to Destination Pointer
JMP BLKSRD ; Check Next Destination Segment
BLKSRC: LDA SRCHI ;If Source Pointer
CMP BLKHI ; <> Block Pointer
BLKSRT: LDA BLKLEN ;Get Segment Length
BEQ BLKRTS ;If 0 Return
STA TEMP0 ;Else Set Memory Swap Byte Count
JSR BLKRST ;Set Block Pointer to Block Start
BLKSRP: LDY #0 ;If First Byte of
LDA (BLKLO),Y ; Current Segment is Null
BEQ BLKRTS ; Return
JSR BLKSRC ;Copy Block Pointer to Source Pointer
JSR BLKDST ;Copy Block Pointer and Destination Pointer
BLKSRD: JSR BLKNXD ;Move Destination Pointer
BCS BLKSRE ;If Not Past Block End
LDY #0 ;
LDA (DSTLO),Y ;and Destination String Populated
BEQ BLKSRE ;
JSR STRCML ; Compare Destination String with Source String
BPL BLKSRD ; If Destination < Source
JSR SETSRD ; Set Source Pointer to Destination Pointer
JMP BLKSRD ; Check Next Destination Segment
BLKSRE: LDA SRCHI ;If Source Pointer
CMP BLKHI ; <> Block Pointer
BNE BLKSRS
LDA SRCLO
CMP BLKLO
BEQ BLKSRN
BLKSRS: JSR BLKSWL ; Swap Source and Pointer
BLKSRN: JSR BLKNXT ;Move Block Pointer
BNE BLKSRP ;If Not Past End, Check Next Segment
RTS ;Return
BLKSRS: JSR BLKSWL ; Swap Source and Pointer
BLKSRN: JSR BLKNXT ;Move Block Pointer
BNE BLKSRP ;If Not Past End, Check Next Segment
RTS ;Return
;blkstr(n, &s) - Search for String s in Block and
; Copy Segment to Destination Array if Found
;Args: n = Segment Size to Search in Bytes
; s = String
;Sets: SRCLO,SRCHI = Pointer to Segment in String (if found)
; TEMP0 = Segment Size
;blkstr(&s) - Search for String s in Block and
; Copy Segment to Destination Array if Found
;Args: Y,X = Address of Search String
;Uses: DSTLO.DSTHI = Address of Destination Array
;Sets: SRCLO,SRCHI = Pointer to Segment in Block (if found)
; TEMP0 = Index within segment
; TEMP1,TEMP2 = Destination String Pointer
;Affects: Y,C
;Returns: A=$FF,N=1,Z=0 if Found
; A=$00,N=0,Z=1 if Not Found
BLKSTR: JSR MEMSRC ;Initialize Source, Index, and Count
JSR SAVDST ;Save Destination Pointer
JSR BLKSRS ;Set Destination Pointer To Block Start
BLKSTL: LDY #0 ;Initialize Index
JSR STRCML ;Compare Source to Destination
BEQ BLKSTS ;If Not Equal
JSR BLKDSN ; Move Destination Pointer
BNE BLKSTL ; If Not Past Block End, Loop
BLKSTF: JSR RESDST ; Else Restore Destination String and Return
LDA #$00 ; and Return FALSE
RTS ;Else
BLKSTS: JSR SETSRD ; Set Source Pointer to Destination Pointer
JSR RESDST ; Restore Destination String Pointer
BLKCPY: LDY #0 ; Initialize Index
JSR MEMCPL ; Copy Segment to Destination String
LDA #$FF ; Return TRUE
RTS
BLKSTR: JSR SETSRC ;Set Source Pointer to Search String
JSR SAVDST ;Save Destination Pointer
JSR GETSRC
LDA BLKLEN ;Get Segment Length
JSR MEMSRC ;Save Number of Bytes to Copy
JSR SETDSS ;Set Destination Pointer to Search String
LDX BLKSLO ;Set Source Pointer To Block Start
LDY BLKSHI
JSR SETSRC
LDX #SRCLO ;Set BLKNXX Pointer to SRCLO,SRCHI
BLKSTL: LDY #0 ;Initialize Index
JSR STRCML ;Compare Source to Destination
BEQ BLKSTS ;If Not Equal
JSR BLKNXX ; Move Source Pointer to Next Segment
BNE BLKSTL ; If Not Past Block End, Loop
JSR RESDST ; Else Restore Destination String and Return
LDA #$00 ; and Return FALSE
RTS ;Else
BLKSTS: JSR RESDST ; Restore Destination Pointer
JMP BLKCPY ; Copy Source to Destination
;blkswp(n, &m) - Swap n Bytes of Array with Block Segment
;Args: n = Number of bytes to swap
; m = Array to swap bytes from
@ -255,20 +288,10 @@ BLKCPY: LDY #0 ; Initialize Index
;Uses: BLKLO, BLKHI = Block Pointer
; DSTLO, DSTHI = Pointer to Temporary Storage Array
;Affects: A,Y,C,N,Z
BLKSWP: JSR MEMSRC ;Set Source Address and Index
BLKSWL: JSR BLKDST ;Set Destination Pointer to Block Pointer
LDY #0 ;Initialize Index
JMP MEMSWL ;Swap Bytes
;blkdst() - Set Destination Pointer to Block Pointer
;Uses: BLKLO,BLKHI = Block Segment Pointer
;Sets: DSTLO,DSTHI = Destination Array Pointer
;Affects: N,Z
;Returns: X = Block Pointer Low Byte
; Y = Block Pointer High Byte
BLKDST: LDX BLKLO
LDY BLKHI
JMP SETDST ;Set Destination and Return
BLKSWP: JSR MEMSRC ;Set Source Address and Index
BLKSWL: JSR BLKDST ;Set Destination Pointer to Block Pointer
LDY #0 ;Initialize Index
JMP MEMSWL ;Swap Bytes
;blksrc() - Set Source Pointer to Block Pointer
;Uses: BLKLO,BLKHI = Block Segment Pointer
@ -277,14 +300,48 @@ BLKDST: LDX BLKLO
;Returns: Y = 0
BLKSRC: LDX BLKLO
LDY BLKHI
JMP SETSRC ;Set Source and Return
JMP SETSRC ;Set Source and Return
;blksrs() - Set Destination Pointer to Block Start Address
;Uses: BLKSLO, BLKSHI = Block Start Address
;Sets: DSTLO, DSTHI = Block Pointer
;blkdst() - Set Destination Pointer to Block Pointer
;Uses: BLKLO,BLKHI = Block Segment Pointer
;Sets: DSTLO,DSTHI = Destination Array Pointer
;Affects: N,Z
;Returns: X = Block Pointer Low Byte
; Y = Block Pointer High Byte
BLKSRS: LDX BLKSLO ;Load Block Start Low Byte
LDY BLKSHI ;Load Block Start High Bytes
JMP SETDST ;Set Destination and Return
;Returns: X = Block Pointer LSB
; Y = Block Pointer MSB
BLKDST: LDX BLKLO
LDY BLKHI
JMP SETDST ;Set Destination and Return
;blkdst() - Set Destination Pointer to Block Start
;Uses: BLKSLO,BLKSHI = Block Start Address
;Sets: DSTLO,DSTHI = Destination Array Pointer
;Affects: N,Z
;Returns: X = Block Start LSB
; Y = Block Start MSB
BLKDSS: LDX BLKSLO
LDY BLKSHI
JMP SETDST ;Set Destination and Return
;Block Debug Routine
BLKDBG: LDA DSTHI
CMP #$43
BNE BLKDBX
LDA DSTLO
CMP #$57
BNE BLKDBX
NOP ;Break Point
BLKDBX: RTS
;Print Destination Address
BLKPDA LDA DSTHI ;Print Destination MSB
JSR PRBYTE
LDA DSTLO ;Print Destination LSB
JSR PRBYTE
JMP PUTSPC ;Print Space
;Print Destination Address
BLKPSA LDA SRCHI ;Print Source MSB
JSR PRBYTE
LDA SRCLO ;Print Source LSB
JSR PRBYTE
JMP PUTSPC ;Print Space

View File

@ -27,6 +27,20 @@ char blkget();
* $00 if not found */
char blkmem();
/* Move Block Pointer to Next Segment *
* Returns: A=$FF if successful *
* $00 if there was an error */
void blknxt();
/* Set Block Pointer Address *
* Args: &d - Address to Set Pointer to */
char blkptr();
/* Move Block Pointer to Previous Segment *
* Returns: A=$FF if successful *
* $00 if there was an error */
void blkprv();
/* Write Bytes to Block *
* Args: n - Number of bytes to write *
* &m - Array containing bytes to write *
@ -37,13 +51,18 @@ char blkput();
/* Set Block Pointer to Block Start */
void blkrst();
/* Set Block Segment Length *
* Args: n - Length of block segment *
* Returns: Fill character */
char blkseg();
/* Fill Block with Character *
* Args: c - Character to fill block with *
* Returns: Fill character */
char blkset();
/* Sort Segments in Block *
* Args: &m - Array containing bytes to swap */
/* Sort Segments in Block *
* Args: &m - Temporary storage array */
char blksrt();
/* Search Block for String *

View File

@ -1,46 +1,208 @@
/*******************************************
* TESTBLK - Test Array Handling Functions *
*******************************************/
//todo: Test blknxt() and blkprv()
#include <py65.h02>
#include <stdio.h02>
#include <stddef.h02>
#include <stdlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <string.h02>
#include <test.h02>
#include <memory.h02>
#include <block.h02>
char TRUE=$FF, FALSE=$00;
char c, i, n, r, z;
char savlo,savhi,tmplo,tmphi; //Address Pointer
char chkhi,chklo; //Address Check
char number[5];
char numbrs = "zero one two threefour five six seveneightnine ten";
char sorted = {8,5,4,9,1,7,6,3,2,0};
char name1 = "Dick", name2 = "Jane";
char block[255]; //Array to Use as Block
char temp[127];
char seglo[9],seghi[9];
char aa,xx,yy;
char seglen = 7;
char sgmt[6]; //Structure: [0-5]=Text, [6]=Binary
char seg1[6],seg2[6];
struct ssgmt {
char key[6];
char flag;
char value;
};
char pass = " Pass ";
char fail = " Fail ";
struct ssgmt sgmt;
struct ssgmt seg1;
struct ssgmt seg2;
struct ssgmt tseg;
main:
puts("blkbgn(&4321); ");
blkbgn(&$4321); //Set Block Start
setchk(&$4321); chkadr(blkshi,blkslo);
puts("blkend(&$4567); ");
blkend(&$4567); //Set Block End
setchk(&$4567); chkadr(blkehi,blkelo);
puts("blkseg(@sgmt); ");
blkseg(@sgmt);
printf(blklen,"blklen=%d:");
if (blklen == @sgmt) passln(); else failln();
puts("blkrst(); ");
blkrst();
setchk(&$4321); chkadr(blkhi,blklo);
puts("blknxt(); ");
blknxt();
setchk(&$432A); chkadr(blkhi,blklo);
puts("blkprv(); ");
blkprv();
setchk(&$4321); chkadr(blkhi,blklo);
puts("blkset('@'); ");
blkset('@'); r=chkptr(&$4321);
while (blkget(1,&sgmt)) {if (sgmt<>'@') r=#FALSE;} psflln(r);
newlin();//if (anykey()==#ESCKEY) goto exit;
setdst(&seg1.key); strcpy(&name1);seg1.flag=#TRUE; seg1.value = 1;
puts("seg1=");prtseg(&seg1);
setdst(&seg2.key); strcpy(&name2);seg2.flag=#FALSE;seg2.value = 2;
puts("seg2=");prtseg(&seg2);
setdst(&sgmt);memcpy(@seg2,&seg2);
puts("sgmt=");prtseg(&sgmt);
newlin();
puts("blkput(@seg1,&seg1); ");
blkrst(); blkput(@seg1,&seg1); r=chkptr(&$432A);
memdst(&$4321); r = chkmem(@seg1,&seg1) & r;
psflln(r);
puts(" _blk=");prtseg(&$4321);
newlin();
puts("blkswp(@sgmt,&sgmt); ");
blkrst(); blkswp(@sgmt,&sgmt); r = chkptr(&$4321);
memdst(&$4321); r = chkmem(@seg2,&seg2) & r;
memdst(&sgmt); r = chkmem(@seg1,&seg1) & r;
psflln(r);
puts(" _blk=");prtseg(&$4321);
puts(" sgmt=");prtseg(&sgmt);
anykey();
puts("blkput(@sgmt, &sgmt);\n"); blkset(0); blkrst(); r = #TRUE;
for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(i,&sgmt); savlo=blklo;savhi=blkhi;
blkput(@sgmt,&sgmt); seglo[i]=savlo; seghi[i]=savhi;
putadr(*,savhi,savlo); puts(" _blk="); prtseg(*,savhi,savlo);
setdst(*,savhi,savlo); if (memcmp(@sgmt,&sgmt)) r = #FALSE;
}
puts("blkput:"); psflln(r); newlin();
puts("blkget(@temp, &temp);\n"); blkrst(); r = #TRUE;
for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(i,&sgmt); memclr(@temp, &temp);
putadr(*,blkhi,blklo); r = blkget(@temp, &temp);
setdst(&temp); if (memcmp(@sgmt, &sgmt)) r = #FALSE;
puts(" temp="); prtseg(&temp);
}
puts("blkget:"); psflln(r); anykey();
puts("blkmem(@sgmt, &sgmt);\n"); r = #TRUE;
for (i=9; i:+; i--) {
printf(i,"%d: "); nsgmt(i,&sgmt);
blkmem(@sgmt,&sgmt);
if (dstlo<>seglo[i]) r = #FALSE;
if (dsthi<>seghi[i]) r = #FALSE;
putadr(*,dsthi,dstlo); puts(" _blk="); prtseg(*,dsthi,dstlo);
}
puts("blkmem:"); psflln(r); newlin();
puts("blkstr(@sgmt, &sgmnt);\n"); r = #TRUE;
for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(i,&sgmt); memclr(@temp, &temp);
setdst(&temp); blkstr(&sgmt.key);
if (srclo<>seglo[i]) r = #FALSE;
if (srchi<>seghi[i]) r = #FALSE;
putadr(*,srchi,srclo); puts(" temp="); prtseg(&temp);
if (memcmp(@sgmt, &sgmt)) r = #FALSE;
i++; if (i=9) i=0; //evens then odds
}
puts("blkstr:"); psflln(r); anykey();
puts("blksrt(&temp);\n"); r = #TRUE; blksrt(&temp);blkrst();
for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(sorted[i],&sgmt); memclr(@temp, &temp);
putadr(*,blkhi,blklo); r = blkget(@temp, &temp);
setdst(&temp); if (memcmp(@sgmt, &sgmt)) r = #FALSE;
puts(" temp="); prtseg(&temp);
}
puts("blksrt:"); psflln(r); newlin();
putln("Tests complete.");
goto exit;
char chkptr() {
setchk(); //pass through args
putadr(*,blkhi,blklo);
return cmpadr(*,blkhi,blklo);
}
void setchk() {
chklo=X; chkhi=Y;
}
void chkadr(tmphi,tmplo) {
putadr(*,tmphi,tmplo);
cmpadr(*,tmphi,tmplo);
psflln(tmplo & tmphi);
}
char cmpadr(aa,yy,xx) {
xx = (chklo == xx) ? #TRUE : #FALSE;
yy = (chkhi == yy) ? #TRUE : #FALSE;
return xx & yy;
}
void clrseg() {
setdst(); memset(0, @sgmt);
}
void prtseg(aa,yy,xx) {
setdst(&tseg); memcpy(@tseg,yy,xx);
setdst(&tseg.key); printf("key=\"%s\",");
puts("flag=");if (tseg.flag) puts("TRUE"); else puts("FALSE");
printf(tseg.value,",value=%d\n");
}
char chkmem() {
aa = memcmp(); //pass through args
aa = (aa==0) ? #TRUE : #FALSE;
return aa;
}
//Copy Textual Representation of n to temp
void numcpy(n) {
strdst(&temp);
strcut(mult(n,5), &numbrs); //Copy Representation
void numstr(n,yy,xx) {
strdst(&temp); strcut(mult(n,5),&numbrs); //Copy Representation
temp[5] = 0; //Cut off remainder of String
z = strchr(' ', &temp);
if (z:+) //Search for space in string
temp[z] = 0; //and terminate at that point
z=strchr(' ', &temp); if (z:+) temp[z]=0; //and terminate at space
setdst(*,yy,xx); strcpy(&temp);
}
//Build String Segment in Temp
void numtmp(n) {
numcpy(n); //Copy Textual Representation to temp[0:5]
temp[6] = i; //Set
void nsgmt(n,tmphi,tmplo) {
memclr(@tseg,&tseg);
numstr(n,&tseg.key);
tseg.flag = trufls(n);
tseg.value = n;
setdst(*,tmphi,tmplo); memcpy(@tseg,&tseg);
}
//Print Addresses
@ -59,105 +221,3 @@ void prbadr() {
prbyte(blkhi);prbyte(blklo);newlin();
}
main:
puts("blkbgn(&$4000);");
blkbgn(&$4000); //Set Block Start
if (blkshi == $40) putln(&pass); else putln(&fail);
puts("blkend(&$4400);");
blkend(&$4400); //Set Block End
if (blkehi == $44) putln(&pass); else putln(&fail);
puts("blkseg(seglen);");
blkseg(seglen);
if (blklen == seglen) putln(&pass); else putln(&fail);
puts("blkrst(); ");
blkrst();
if (blkhi == $40) putln(&pass); else putln(&fail);
puts("blkset('@'); ");
blkset('@');
r = $FF;
blkrst();
while (blkget(1,&sgmt)) {
if (sgmt <> '@') r = $00;
}
if (r) putln(&pass); else putln(&fail);
setdst(&seg1); strcpy(&name1);seg1[6] = 1;
setdst(&seg2); strcpy(&name2);seg2[6] = 2;
puts("blkswp(seglen, &seg2);");
blkrst();
blkput(seglen, &seg1);
blkrst();
setdst(&temp);
blkswp(seglen, &seg2);
r = $FF;
blkget(seglen, &sgmt);
if (strcmp(&name2)) r = $00;
if (sgmt[6] <> 2) r = $00;
setdst(&seg2);
if (strcmp(&name1)) r = $00;
if (seg2[6] <> 1) r = $00;
if (r) putln(&pass); else putln(&fail);
blkset(0);
puts("blkput(seglen, &temp);");
r = TRUE;
blkrst();
for (i=0; i<10; i++) {
numtmp(i);
savlo=blklo;savhi=blkhi;
blkput(seglen, &temp);
dstlo=savlo;dsthi=savhi;
if (memcmp(seglen,&temp)) r = FALSE;
}
if (blklo <> 70) r = TRUE;
if (r) putln(&pass); else putln(&fail);
puts("blkmem(seglen, &temp);");
r = $FF;
for (i=9; i:+; i--) {
numtmp(i);
r = blkmem(seglen, &temp);
if (mult(seglen,i) <> dstlo) r = 0;
}
if (r) putln(&pass); else putln(&fail);
puts("blkstr(seglen, &temp);");
r = $FF;
for (i=0; i<10; i++) {
numtmp(i);
setdst(&sgmt);
r = blkstr(seglen, &temp);
if (sgmt[6] <> i) r = 0;
}
if (r) putln(&pass); else putln(&fail);
blkrst();
puts("blkget(seglen, &sgmt);");
r = $FF;
for (i=0; i<10; i++) {
numtmp(i);
setdst(&sgmt);
r = blkget(seglen, &sgmt);
if (memcmp(seglen, &temp)) r = 0;
}
if (r) putln(&pass); else putln(&fail);
puts("blksrt(&temp);");
blksrt(&temp);
r = TRUE;
seg1[0] = 0;
blkrst();
while(blkget(seglen, &seg2)) {
if (!seg2[0]) break;
if (strcmp(&seg1)<>1) r = FALSE;
strdst(&seg1);strcpy(&seg2);
}
if (r) putln(&pass); else putln(&fail);
goto exit;