From 88bd0605bbd69a5c753f00e6d45d5026784699e9 Mon Sep 17 00:00:00 2001 From: Curtis F Kaylor Date: Mon, 5 Oct 2020 12:14:37 -0400 Subject: [PATCH] Removed shiftl, shiftr, and swap functions from stdlib --- doc/func-idx.txt | 58 ++++++++++++++++++++++++++--------------- doc/library.txt | 48 ++++++++++++++++++++++++++-------- doc/stdlib.txt | 26 ++----------------- include/stdlib.a02 | 65 +++------------------------------------------- include/stdlib.h02 | 12 --------- test/slibtest.c02 | 50 +++-------------------------------- 6 files changed, 82 insertions(+), 177 deletions(-) diff --git a/doc/func-idx.txt b/doc/func-idx.txt index f37a01b..c7b9f60 100644 --- a/doc/func-idx.txt +++ b/doc/func-idx.txt @@ -1,5 +1,8 @@ Function Library Name Description abs stdlib Absolute Value Return absolute value of byte. +adddst stddef Add Destination Add value to Destination Pointer. +addsrc stddef Add Source Add value to Source Pointer. +addzpw stddef Add Zero Page Word Add value to word in zero page anykey stdiox Any Key Display "Any Key" prompt and wait for keypress. atoc stdlib ASCII to Character Convert numeric string to byte. blkbgn block Block Begin Set beginning of block address. @@ -15,30 +18,33 @@ blkstr block Block String Search block for segment beginning with blkswp block Block Swap Swap bytes of array with the current segment. blksrt block Block Sort Sort segments in block by initial string. button paddle Button Read paddle button controller status. +chdir direct Change Directory Change to specified directory +chdrv direct Change Drive Change to specified drive ctoa stdlib Character to ASCII Convert byte to numeric string. div stdlib Divide Divide two bytes. +drvnam direct Drive Name Return name of specified drive failed test Failed Write " Fail" to screen. failln test Failed Line Write " Fail" plus newline to screen. -fclall file File Close All Close all files. -fclose file File Close Close file. -feof file File End of File Check for end of file condition. -ferror file File Error Get file error information. -fgetc file File Get Character Read character from file. -fgets file File Get String Read string from file. -fopen file File Open Open file. +fclose fileio File Close Close file. +feof fileio File End of File Check for end of file condition. +ferror fileio File Error Get file error information. +fflush fileio File Flush Flush output buffer to file. +fgetc fileio File Get Character Read character from file. +fgets fileio File Get String Read string from file. +fopen fileio File Open Open file. florps test Fail or Pass Write " Fail" or " Pass" to screen. flpsln test Fail or Pass Line Write " Fail" or " Pass" plus newline to screen. -fputc file File Put Character Write character to file. -fputs file File Put String Write string to file. -fread file File Read Read bytes from file. -fschk file File System Check Check for valid file pointer -fsdst file File Set Destination Set destination array for fread. -fsinit file File System Init Initialize file system. -fsptr file File System Pointer Get unused file pointer. -fssrc file File Set Source Set source array for fwrite. -fstat file File System Status Get file pointer status. -fwrite file File Write Write bytes to file. +fputc fileio File Put Character Write character to file. +fputln fileio File Put Line Write line to file. +fputs fileio File Put String Write string to file. +fread fileio File Read Read bytes from file. +fsaddr fileio File Set Address Set address for fread, fwrite, fsave, or fload. +fsinit fileio File System Init Initialize file system. +fsname fileio File Set Name Set filename for fopen, fsave, or fload. +fwrite fileio File Write Write bytes to file. getc stdio Get Character Read character from keyboard. +getcwd direct Get CWD Return current working directory +getdrv direct Get Drive Return current drive identifier getdst stddef Get Destination Get address in Destination Pointer. getprc stdiox Get Prompt Character Display prompt and wait for keypress. gets stdio Get String Read string from keyboard. @@ -71,11 +77,14 @@ mflush memio Memory Flush Flush memory file. mgetc memio Memory Get Character Read single character from memory file. mgets memio Memory Get String Read string from memory file. min stdlib Minimum Return lesser of two byte. +mkdir direct Make Directory Create specified directory mopen memio Memory Open Open memory file. mputc memio Memory Put Character Write single character to memory file. mputln memio Memory Put String Write string followed by newline to memory file. mputs memio Memory Put String Write string to memory file. mult stdlib Multiply Multiply two bytes. +opndir dirent Open Directory Open directory for reading +pack bitlib Pack nybbles Pack two nybbles into a single byte. paddle paddle Paddle Read paddle controller position. passed test Passed Write " Pass" to screen. passln test Passed Line Print " Pass" plus newline to screen. @@ -106,10 +115,16 @@ putsub stdio Put Substring Write substring to screen. putwrd stdiox Put Word Write address to screen as hexadecimal number. rand stdlib Random Generate pseudorandom number. rands stdlib Random Seed Seed random number generator. -ressrc stddef Restore Destination Restore Destination Pointer from TEMP variables. +rddir dirent Read Directory Read Directory Entry +rdhdr dirent Read Header Read Directory Header +rmdir direct Remove Directory Remove specified directory +resdst stddef Restore Destination Restore Destination Pointer from TEMP variables. resreg stddef Restore Registers Restore A, X, and Y registers from TEMP variables. resrxy stddef Restore Reg. X and Y Restore X, and Y registers from TEMP variables. ressrc stddef Restore Source Restore Source Pointer from TEMP variables. +rotl bitlib Rotate Left Rotate byte left specified number of bits. +rotr bitlib Rotate Right Rotate byte right specified number of bits. +savdst stddef Save Destination Save Destination Pointer in TEMP variables. savreg stddef Save Registers Save A, X, and Y registers in TEMP variables. savrxy stddef Save Reg. X and Y Save X, and Y registers in TEMP variables. savsrc stddef Save Source Save Source Pointer in TEMP variables. @@ -117,8 +132,8 @@ setdss stddef Set Dest. Source Set Destination Pointer to Source Pointe setdst stddef Set Destination Set Destination Pointer to address. setsrc stddef Set Source Set Source Pointer to address. setsrd stddef Set Source Dest. Set Source Pointer to Destination Pointer. -shiftl stdlib Shift Left Shift byte left specified number of bits. -shiftr stdlib Shift Right Shift byte right specified number of bits. +shiftl bitlib Shift Left Shift byte left specified number of bits. +shiftr bitlib Shift Right Shift byte right specified number of bits. stkbgn stack Stack Begin Set start of stack address. stkdup stack Stack Duplicate Duplicate top entry of stack. stkend stack Stack End Set end of stack address. @@ -144,7 +159,8 @@ strpbk stringx String Pointer Break Find first character in destination foun strrch string String Reverse Char Search for character from end of string. strspn stringx String Span Return length of span in destination found in string. strstr string String String Search for string in destination string. -swap stdlib Swap nybbles Swaps the upper and lower nybbles in a byte. +swap bitlib Swap nybbles Swaps left and right nybbles in byte. tolowr ctype To Lowercase Convert character to lowercase. touppr ctype To Uppercase Convert character to uppercase. trufls test True or False Convert value to #TRUE or #FALSE. +unpack bitlib Unpack nybbles Unpack byte into two nybbles. diff --git a/doc/library.txt b/doc/library.txt index 6303f33..6b1cc32 100644 --- a/doc/library.txt +++ b/doc/library.txt @@ -24,42 +24,57 @@ module. The available modules are as follows: stddef Standard Definitions - Contains commonly used constants, as well as base - functions common to nearly every other module. + Commonly used constants, as well as base functions + common to nearly every other module. stdlib Standard Library - Includes the most commonly used functions, including + The most commonly used functions, including eight bit mathematical operations and string/numeric conversions. + bitlib Bit Library + + Bit shift, rotate, and nybble manipulation functions + for 8-bit values. + + intlib Integer Library + + Mathematical, bit shifting and string/numeric + conversion functions for 16-bit values. + + ctype Characted Type + + Functions to detect character types and convert + between lower and upper case. + stdio Standard Input/Output - Contains functions for reading and writing characters + Functions for reading and writing characters and strings from the keyboard and to the screen. stdiox Standard Input/Output Extended - Contains functions for writing formatted data to the + Functions for writing formatted data to the screen, including decimal and hexadecimal numbers. string String functions - Contains functions for copying, searching, comparing, + Functions for copying, searching, comparing, and concatenating strings. stringx String Extended - Contains the more powerful, but less frequently used + The more powerful, but less frequently used string manipulation functions. memory Memory functions - Contains functions for copying, searching, and comparing + Functions for copying, searching, and comparing arrays. block Block functions - Contains functions for reading, writing, and searching + Functions for reading, writing, and searching for fixed length segments of data to an arbitrarily large section of memory. @@ -70,11 +85,22 @@ module. The available modules are as follows: memio Memory Input/Ouput - Provides functions to simulate reading and writing to + Functions to simulate reading and writing to a section of memory as though it were a file. fileio File Input/Ouput - Provides functions to access, read from, and write to + Functions to access, read from, and write to files on cassette and/or disk. + dirent Directory Entry + + Functions to read directories from disk, disk + like devices, and possibly tapes. + + direct Directory Access + + Functions to switch between, create and remove + directories, and to switch between devices. + + \ No newline at end of file diff --git a/doc/stdlib.txt b/doc/stdlib.txt index 62b863c..ad88b92 100644 --- a/doc/stdlib.txt +++ b/doc/stdlib.txt @@ -13,7 +13,7 @@ The following functions are defined: 0 - 127 are considered positive, while the unsigned values 128 - 255 are considered negative. - c = atoc(&s); Returns the numeric value of the string in array s. + c = atoc(s); Returns the numeric value of the string in array s. Does not skip leading white-space characters and stops when first non-digit character is encountered. @@ -21,7 +21,7 @@ The following functions are defined: Overflows are ignored, so numbers greater than 255 will be returned modulo 256. - ctoa(c, &s); Stores the ASCII representation of usigned byte c + ctoa(c, &s); Stores the ASCII representation of unsigned byte c as a null-terminated string in array s. The array must be dimensioned to at least 4 bytes. @@ -59,28 +59,6 @@ The following functions are defined: or getchr() function must called at least once before a rands(0) call. - c = shiftl(b, n); Returns byte b shifted n bits to the left, filling - with 0's from the right. - - If n is greater than 8, all bits will be shifted out, - and a value of 0 is treated as 256. - - c = shiftr(b, n); Returns byte b shifted n bits to the right, filling - with 0's from the left. - - If n is greater than 8, all bits will be shifted out, - and a value of 0 is treated as 256. - - Note: Using the shiftl() or shiftr() functions with - an asignment generates 9 to 12 bytes of code, whereas - the << and >> post-operators generate either 2 or 3 - bytes each. So for a constant number of shifts, the - post-operators will generate smaller code for less - than 5 shifts and will always be faster. - - c = swap(b); Returns the byte b with the high and low nybbles - swapped. - Note: This library expects the following function to be defined setsrc(&s); Set source string pointer and initialize index diff --git a/include/stdlib.a02 b/include/stdlib.a02 index 388ca1f..01b02b7 100644 --- a/include/stdlib.a02 +++ b/include/stdlib.a02 @@ -108,67 +108,6 @@ RANDS: ORA #$00 ;If Passed Value not 0 ADC #$01 ;Else Add 1 or 2 BNE .RANDX ; then Store and Return -;swap(byte) - Swap Low and High Nybbles in Byte -;Args: A = Byte to Swap -;Affects Y,N,Z,C -;Returns: A = Swapped Byte -SWAP: LDY #4 ;Set Count to 4 and Rotate Left - -;rotatl(byte,count) - Rotate byte by count Bits to the Left -;Args = Byte to Rotate -;Y = Number of Bits to Rotate -;Affects X,Y,N,Z,C -;Returns: A = Rotated Byte -ROTATL: INY ;Pre-Increment Counter -.ROTALL DEY ;Decrement Counter - BEQ .ROTATX ;If Not Zero - ASL ; Shift Left One Bit - ADC #0 ; Copy Carry into Bit 0 - BNE .ROTALL ; If Not Zero, Loop -.ROTATX RTS - -;rotatr(byte,count) - Shift byte by count Bits to the Right -;Args = Byte to Rotate -;Y = Number of Bits to Rotate -;Affects Y,N,Z,C -;Returns: A = Rotated Byte -ROTATR: INY ;Pre-Increment Counter -.ROTALR DEY ;Decrement Counter - BEQ .ROTATX ;If Not Zero - LSR ; Shift Right One Bit - BCC .ROTATS ; If Carry Set - ORA #$80 ; Copy Carry into Bit 7 -.ROTATS BNE .ROTALR ; If Not Zero, Loop - RTS - -SHFTL4: LDY #4; ;Set Count to 4 and Shift Left - -;shiftl(byte,count) - Shift byte by Count bits to the Left -;Args = Byte to Shift -;Y = Number of Bits to Rotate -;Affects Y,N,Z,C -;Returns: A = Shifted Byte -SHIFTL: INY ;Pre-Increment Counter -.SHIFLL DEY ;Decrement Counter - BEQ .SHIFTX ;If Not Zero - ASL ; Shift Byte to Left - BNE .SHIFLL ; and Loop if Not 0 -.SHIFTX RTS - -SHFTR4: LDY #4; ;Set Count to 4 and Shift Right - -;shiftr(byte,count) - Shift byte by Count bits to the Right -;Args = Byte to Shift -;Y = Number of Bits to Rotate -;Affects Y,N,Z,C -;Returns: A = Shifted Byte -SHIFTR: INY ;Pre-Increment Counter -.SHIFLR DEY ;Decrement Counter - BEQ .SHIFTX ;If Not Zero - LSR ; Shift Byte to Right - BNE .SHIFLR ; and Loop if Not 0 - RTS - ;atoc(&s) - ASCII string TO Character ;Args: Y,X = Address of String to Convert ;Uses: TEMP0, TEMP1 @@ -205,7 +144,7 @@ ATOC: JSR SETSRC ;Initialize Source String ; TEMP2 = Hundreds Digit ;Affects: C,N.Z ;Returns: A,Y = Length of String -CTOA: JSR SETDST ;Initialize Source String +CTOA: JSR SETDST ;Initialize Destination String LDY #0 ;Initialize Index into String JSR CUBCD ;Convert Accumulator to Unpacked BCD LDA TEMP2 ;Get MSB @@ -274,3 +213,5 @@ CVBCDT: LDA #0 ;Clear BCD Bytes BNE .CVBCDL ; Process Next Bit PLP ;Restore Status Register RTS + + ENDSUBROUTINE diff --git a/include/stdlib.h02 b/include/stdlib.h02 index 27f81eb..ce30c03 100644 --- a/include/stdlib.h02 +++ b/include/stdlib.h02 @@ -53,18 +53,6 @@ char mult(); * Returns: Random number between 1 and 255 */ char rand(); -/* Shift Byte Left * - * Args: b - Byte to Shift * - * n - Number of Bits to Shift * - * Returns: Shifted Byte */ -char shiftl(); - -/* Shift Byte Right * - * Args: b - Byte to Shift * - * n - Number of Bits to Shift * - * Returns: Shifted Byte */ -char shiftr(); - /* Seed Pseudo-Random Number Generator * * Args: n - Seed number */ void srand(); diff --git a/test/slibtest.c02 b/test/slibtest.c02 index e44d91d..ae23d28 100644 --- a/test/slibtest.c02 +++ b/test/slibtest.c02 @@ -1,6 +1,6 @@ -/************************************************** - * TESTSLIB - Test Library stdlib.h02 for py65mon * - **************************************************/ +/********************************* + * SLIBTEST - Test Module stdlib * + *********************************/ //Specify System Header using -H option #include @@ -119,50 +119,6 @@ char countr, rndnum, rndtbl[255]; tstros: //Test rotatl(), rotatr(), swap() char lbyte, rbyte, obyte, sbyte, tbyte, scount; - putstr("ROTATL(), SHIFTL()"); - obyte = 0; - do { - if (!obyte & $F) putchr('.'); - scount = 0; sbyte = obyte; tbyte = obyte; - do { - rbyte = rotatl(obyte, scount); if (rbyte <> tbyte) goto rtlerr; - lbyte = shiftl(obyte, scount); if (lbyte <> sbyte) goto shlerr; - sbyte<<; - temp0 = tbyte; tbyte<<; if (temp0:-) tbyte++; - scount++; if (scount == 8) scount = $F8; - } while (scount); - obyte ++; - } while (obyte); - prtok(); - - putstr("ROTATR(), SHIFTR()"); - obyte = 0; - do { - if (!obyte & $F) putchr('.'); - scount = 0; sbyte = obyte; tbyte = obyte; - do { - rbyte = rotatr(obyte, scount); if (rbyte <> tbyte) goto rtrerr; - lbyte = shiftr(obyte, scount); if (lbyte <> sbyte) goto shrerr; - sbyte>>; - temp0 = tbyte; tbyte>>; if (temp0 & 1) tbyte = tbyte | $80; - scount++; if (scount == 8) scount = $F8; - } while (scount); - obyte ++; - } while (obyte); - prtok(); - - putstr("SWAP()"); - lbyte=0; do { - rbyte = 0; do { - obyte = lbyte & $f0; obyte = rbyte & $0f + lbyte; - tbyte = lbyte & $0f; tbyte = rbyte & $f0 + lbyte; - sbyte = swap(obyte); - if (sbyte <> tbyte) goto swperr; - rbyte = rbyte + $11; - } while (rbyte & $0f); - } while (lbyte & $0f); - prtok(); - tstc2a: //Test ctoa(); char srcchr, dstchr, tststr[4];