diff --git a/include/apple2.a02 b/include/apple2.a02 new file mode 100644 index 0000000..1de4778 --- /dev/null +++ b/include/apple2.a02 @@ -0,0 +1,81 @@ +;Apple 1 program initialization code for c02 programs + +;System Specific ASCII Key Mappings +DELKEY EQU $08 ;Delete/Backspace Key (Left Arrow) +ESCKEY EQU $1B ;Escape/Stop Key (Escape) +RTNKEY EQU $0D ;Return/Enter Key (Return) + +;Zero Page Variables (*=System Variable) +DSTLO EQU $06 ;Destination Pointer +DSTHI EQU $07 +BLKLO EQU $08 ;Block Segment Pointer (block.a02) +BLKHI EQU $09 +STKLO EQU $1D ;Stack Pointer (stack.a02) +STKHI EQU $1E +RANDOM EQU $1F ;Random Number +INVFLG EQU $32 ;*Inverse Flag: $3F=Blinking, $7F=Inverse, $FF=Normal +SRCLO EQU $71 ;Source Pointer +SRCHI EQU $72 +RDSEED EQU $E3 ;Random Seed +BLKSLO EQU $EB ;Block Start Address +BLKSHI EQU $ED +BLKELO EQU $ED ;Block End Address +BLKEHI EQU $EE +BLKLEN EQU $EF ;Block Segment Length +TEMP0 EQU $FC ;Temporary Storage +TEMP1 EQU $FD +TEMP2 EQU $FE +TEMP3 EQU $FF + +;I/O Locations +KBD EQU $C000 ;Keyboard Data +AKD EQU $C010 ;Keyboard Strobe Register + +;Monitor Routines +PRBYTE EQU $FDDA ;Print Accumulator as Hexadecimal Number +PRHEX EQU $FDE3 ;Print Low Nybble of Accumulator as Hex Digit + +ECHO EQU $FDF0 ;Print Character - Routine Monitor COUT1 +EXIT EQU $03D0 ;Return to Monitor - Jump Vector to DOS warm start + + ORG $0C00 ;Safe Area for Machine Language + +START: JSR NEWLIN ;Start On New Line + JMP MAIN ;Execute Program + +;Subroutine Poll Keyboard +PLKEY: INC RDSEED ;Cycle Random Seed + LDA #0 ;Clear Accumulator + BIT KBD ;Check Keyboard Strobe Bit + BPL PLKEYR ;If Key Pressed + LDA KBD ; Load Key Value + STA AKD ; Clear Strobe +PLKEYR: RTS + +;Read Keyboard +GETKEY JSR PLKEY ;Poll Keyboard + AND #$7F ;Strip High Bit + RTS + +;Wait for Keypress +RDKEY: JSR GETKEY ;Get Modified Key Code + BEQ RDKEY ;Loop if No Key + RTS + +;Delete Previous Character +DELCHR: LDX #2 ;Two Characters Total + LDA #$88 ;Load Backspace Character + JSR $F94C ;Monitor Routine PRBLAX + LDA #DELKEY ;Load Backspace Character + ;and Fall into PRCHR + +;Print Character to Screen +PRCHR: ORA #$80 ;Set High Bit + CMP #$E0 ; + BCC PRCHRX ;If Lower Case + AND #$1F ; Convert to Inverse +PRCHRX: JMP ECHO ;Alias to Monitor Routine + +;Advance Character to Next line +NEWLIN EQU $FD8E ;Monitor Routine CROUT + diff --git a/include/apple2.h02 b/include/apple2.h02 new file mode 100644 index 0000000..706706c --- /dev/null +++ b/include/apple2.h02 @@ -0,0 +1,39 @@ +/* Apple ][ Header File */ + +//Platform Specific Constants +#define DELKEY $08 //Delete/Backspace Key +#define ESCKEY $1B //Escape/Stop Key +#define RTNKEY $0D //Return/Enter Key + +/* Standard Library Variables */ +char srclo,srchi; //Source String Pointer for Library Functions +char dstlo,dsthi; //Destination String Pointer for Library Functions +char blklo,blkhi; //Block Segment Pointer +char stklo,stkhi; //System Pointer + +char blkslo, blkshi; //Block Start Address +char blkelo, blkehi; //Block End Address +char blklen; //Block Segment Length + +char temp0, temp1, temp2, temp3; //Temporary Variables + +//System Variables +char invflg; //Video Invert Mask + +//Keyboard I/O +char kbd; //Keyboard Data Register +char abd; //Keyboard Strobe Register + +//Monitor Subroutines +void echo(); //Print Character in Accumulator +void prbyte(); //Print Accumulator as Hexadadecimal number +void prhex(); //Print Low Nybble of Accumulator as Hex Digit + +//System Subroutines +char plkey(); //Poll Console for character +char rdkey(); //Wait for character from Console +char getkey(); //Read ASCII character from Console +void newlin(); //Advance cursor to beginning of next line +void prchr(); //Print ASCII character to Console +void setdst(); //Set Destination Pointer +void setsrc(); //Set Source Pointer diff --git a/include/header.h02 b/include/header.h02 index 4c1e3dc..81ad9cc 100644 --- a/include/header.h02 +++ b/include/header.h02 @@ -13,6 +13,8 @@ /* Zero Page Variables used as Pointers */ char strlo,strhi; //String pointer for String and I/O functions char dstlo,dsthi; //Secondary string pointer for String functions +char blklo,blkhi; //Block Segment Pointer +char stklo,stkhi; //Stack Pointer /* Ephemeral Library Variables * * Available for use in program code, but may * @@ -23,14 +25,19 @@ char temp0,temp1,temp2,temp3; //Temporary variables /* Static Library Variables * * Must be preserved between function calls * * May be Zero Page, but not required */ -char random; //Last Result of Pseudo-Random Number Generator -char rdseed; //System Seed for Pseudo-Random Number Generator +char blkslo, blkshi; //Block Start Address +char blkelo, blkehi; //Block End Address +char blklen; //Block Segment Length +char stkslo, stkshi; //Stack Start Address +char stkelo, stkehi; //Stsck End Address +char random; //Last Result of Pseudo-Random Number Generator +char rdseed; //System Seed for Pseudo-Random Number Generator //System Subroutines -char plkey(); //Poll Console for character -char rdkey(); //Wait for character from Console -char getkey(); //Read ASCII character from Console -void newlin(); //Advance cursor to beginning of next line -void prchr(); //Print ASCII character to Console -void prbyte(); //Print Accumulator as Hexadadecimal number -void prhex(); //Print Low Nybble of Accumulator as Hex Digit +char plkey(); //Poll Console for character +char rdkey(); //Wait for character from Console +char getkey(); //Read ASCII character from Console +void newlin(); //Advance cursor to beginning of next line +void prchr(); //Print ASCII character to Console +void prbyte(); //Print Accumulator as Hexadadecimal number +void prhex(); //Print Low Nybble of Accumulator as Hex Digit diff --git a/include/py65.a02 b/include/py65.a02 index f0aa3ae..19036d6 100644 --- a/include/py65.a02 +++ b/include/py65.a02 @@ -45,7 +45,13 @@ START: JMP MAIN ;Execute Program ;Poll Character from Keyboard PLKEY: INC RDSEED ;Cycle the RANDOM Seed (if not provided by system) LDA GETCON ;Read Character from Console - RTS + CMP #$E0 + BEQ PLKEYX ;If Not E0 Extended Key + ORA #$00 ; Set Status Flags + RTS ; and Return +PLKEYX: LDA GETCON ;Else Get Second Byte + ORA #$80 ; Set High Byte + RTS ; and Return ;Read Character from Console GETKEY ;Same As RDKEY diff --git a/include/py65.h02 b/include/py65.h02 index 398cddf..cc3681d 100644 --- a/include/py65.h02 +++ b/include/py65.h02 @@ -6,30 +6,31 @@ #define RTNKEY $0D //Return/Enter Key #define NULKEY $00 //No Key was Pressed -//System Pointer Variables -char srclo,srchi; //Source String Pointer for Library Functions -char dstlo,dsthi; //Destination String Pointer for Library Functions -char blklo,blkhi; //Block Segment Pointer -char stklo,stkhi; //Stack Pointer +//Library Pointer Variables +char srclo,srchi; //Source String Pointer for Library Functions +char dstlo,dsthi; //Destination String Pointer for Library Functions +char blklo,blkhi; //Block Segment Pointer +char stklo,stkhi; //Stack Pointer -//System Variables -char blkslo, blkshi; //Block Start Address -char blkelo, blkehi; //Block End Address -char blklen; //Block Segment Length -char stkslo, stkshi; //Stack Start Address -char stkelo, stkehi; //Stsck End Address -char temp0, temp1; //Temporary Variables -char temp2, temp3; +//Library Variables +char blkslo, blkshi; //Block Start Address +char blkelo, blkehi; //Block End Address +char blklen; //Block Segment Length +char stkslo, stkshi; //Stack Start Address +char stkelo, stkehi; //Stsck End Address +char random, rdseed; //Pseudo-Random Number Generation +char temp0, temp1, temp2, temp3; //Temporary Storage //Memory Mapped I/O -char putcon; //Write Character to Console -char getcomn; //Read Character from Console +char putcon; //Write Character to Console +char getcomn; //Read Character from Console //System Subroutines -char plkey(); //Poll Console for character -char rdkey(); //Wait for character from Console -char getkey(); //Read ASCII character from Console -void newlin(); //Advance cursor to beginning of next line -void prchr(); //Print ASCII character to Console -void prbyte(); //Print Accumulator as Hexadadecimal number -void prhex(); //Print Low Nybble of Accumulator as Hex Digit +char plkey(); //Poll Console for character +char rdkey(); //Wait for character from Console +char getkey(); //Read ASCII character from Console +void newlin(); //Advance cursor to beginning of next line +void delchr(); //Delete previous character +void prchr(); //Print ASCII character to Console +void prbyte(); //Print Accumulator as Hexadadecimal number +void prhex(); //Print Low Nybble of Accumulator as Hex Digit diff --git a/include/py65min.a02 b/include/py65min.a02 index 0b2e12d..0c58838 100644 --- a/include/py65min.a02 +++ b/include/py65min.a02 @@ -1,25 +1,41 @@ ; py65mon program initialization code for c02 programs ;System Specific ASCII Key Mappings -DELKEY EQU $7F ;Delete/Backspace Key (Delete) +DELKEY EQU $08 ;Delete/Backspace Key (Delete) ESCKEY EQU $1B ;Escape/Stop Key (Escape) RTNKEY EQU $0D ;Return/Enter Key (Carriage Return) ;Memory Mapped I/O -PUTC EQU $F001 ;Write Character to Console -GETC EQU $F004 ;Read Character from Console +PUTCON EQU $F001 ;Write Character to Console +GETCON EQU $F004 ;Read Character from Console ORG $0200 ;Start Directly Above Stack START: JMP MAIN ;Execute Program -;Wait for Character from Console -RDKEY: LDA GETC ;Read Character from Console - BEQ RDKEY ; Loop if None Received +;Delete Previous Character +DELCHR: JSR DELCHB ;Print Backspace + LDA #$20 ;Load Space into Accumulater + JSR PRCHR ; and Print it +DELCHB: LDA #$08 ;Load Backspace into Accumulator + BNE PRCHR ; and Print it + + ;Advance Character to Next line +NEWLIN: LDA #$0D ;Load C/R into Accumulator + JSR PRCHR ; and Print it + LDA #$0A ;Load L/F into Accumulater + ; and fall into PRCHR +;Print Character to Console +PRCHR: STA PUTCON ;Write Character to Console RTS -;Print Character to Console -PRCHR: STA PUTC ;Write Character to Console +;Poll Keyboard for Keypress +PLKEY: LDA GETCON ;Read Character from Console + RTS + +;Wait for Character from Console +RDKEY: JSR PLKEY ;Read Character from Console + BEQ RDKEY ; Loop if None Received RTS EXIT: BRK ;Return to Monitor diff --git a/include/py65min.h02 b/include/py65min.h02 index cb66dda..f5f314e 100644 --- a/include/py65min.h02 +++ b/include/py65min.h02 @@ -1,12 +1,18 @@ /* py65mon Header File */ +#define DELKEY $08 //Delete/Backspace Key +#define ESCKEY $1B //Escape/Stop Key +#define RTNKEY $0D //Return/Enter Key + //Memory Mapped I/O char putc; //Write Character to Console char getc; //Read Character from Console //System Subroutines -char plkey(); //Poll Console for character -char rdkey(); //Wait for character from Console -char getkey(); //Read ASCII character from Console -void prchr(); //Print ASCII character to Console +void newlin(); //Advance cursor to beginning of next line +void delchr(); //Delete previous character +char plkey(); //Poll Console for character +char rdkey(); //Wait for character from Console +char getkey(); //Read ASCII character from Console +void prchr(); //Print ASCII character to Console diff --git a/include/py65win.a02 b/include/py65win.a02 new file mode 100644 index 0000000..358444e --- /dev/null +++ b/include/py65win.a02 @@ -0,0 +1,99 @@ +; py65mon program initialization code for c02 programs + +;System Specific ASCII Key Mappings +DELKEY EQU $08 ;Delete/Backspace Key (Backspace) +ESCKEY EQU $1B ;Escape/Stop Key (Escape) +RTNKEY EQU $0D ;Return/Enter Key (Carriage Return) + +;Zero Page Locations +SRCLO EQU $30 ;Source String Pointer (stdio.a02) +SRCHI EQU $31 +DSTLO EQU $32 ;Destination String Pointer (string.a02) +DSTHI EQU $33 +BLKLO EQU $34 ;Block Segment Pointer (block.a02) +BLKHI EQU $35 +STKLO EQU $36 ;Stack Pointer (stack.a02) +STKHI EQU $37 + +RDSEED EQU $3E ;Pseudo-RANDOM Seed +RANDOM EQU $3F ;Pseudo-RANDOM Number Storage + +TEMP0 EQU $40 ;Temporary Storage +TEMP1 EQU $41 +TEMP2 EQU $42 +TEMP3 EQU $43 + +BLKSLO EQU $46 ;Block Start Address +BLKSHI EQU $47 +BLKELO EQU $48 ;Block End Address +BLKEHI EQU $49 +BLKLEN EQU $4A ;Block Segment Length + +STKSLO EQU $4C ;Stack Start Address +STKSHI EQU $4D +STKELO EQU $4E ;Stack End Address +STKEHI EQU $4F + +;Memory Mapped I/O +PUTCON EQU $F001 ;Write Character to Console +GETCON EQU $F004 ;Read Character from Console + + ORG $0200 ;START Directly Above Stack + +START: JMP MAIN ;Execute Program + +;Poll Character from Keyboard +PLKEY: INC RDSEED ;Cycle the RANDOM Seed (if not provided by system) + LDA GETCON ;Read Character from Console + CMP $E0 + BNE PLKEYX ;If E0 Extended Key + LDA GETCON ; Get Second Byte + ORA $80 ; and Set High Byte +PLKEYX: RTS + +;Read Character from Console +GETKEY ;Same As RDKEY + +;Wait for Character from Console +RDKEY: JSR PLKEY ;Read Character from Console + BEQ RDKEY ; Loop if None Received + RTS + +;Delete Previous Character +DELCHR: LDA #$08 ;Load Backspace into Accumulator + JSR PRCHR ; and Print it + LDA #$20 ;Load Space into Accumulater + JSR PRCHR ; and Print it + LDA #$08 ;Load Backspace into Accumulator + JMP PRCHR ; and Print it + +;Advance Character to Next line +NEWLIN: LDA #$0D ;Load C/R into Accumulator + JSR PRCHR ; and Print it + LDA #$0A ;Load L/F into Accumulater + ; and fall into PRCHR + +;Print Character to Console +PRCHR: STA PUTCON ;Write Character to Console + RTS + +EXIT: BRK ;Return to Monitor + +;Print Byte as Two-Digit Hex Number to Console +PRBYTE: PHA ;Save Accumulater + LSR ;Shift Hi Nybble to Low Nybble + LSR + LSR + LSR + JSR PRHEX ; and Print it + PLA ;Restore Accumulator + ; and fall into PRHEX + +;Print Low Nybble as Hex Digit to Console +PRHEX: AND #$0F ;Strip High Nybb + SED ;Set Decimal Flag for + CLC ; Addition Wizardry + ADC #$90 ;Convert to $90-$99,$00-$05 + ADC #$40 ;Convert to $30-$39,$41-$46 + CLD ;Clear Decimal Flag + JMP PRCHR ;Print Hex Digit and Return diff --git a/include/stddef.h02 b/include/stddef.h02 index ade546c..5bc4f6f 100644 --- a/include/stddef.h02 +++ b/include/stddef.h02 @@ -3,8 +3,8 @@ * functions used in libraries. */ /* Constant Definitions */ -#define #TRUE $FF -#define #FALSE $00 +#define TRUE $FF +#define FALSE $00 /* Get Destination Pointer * * Returns: Y,X=Destination address */ diff --git a/include/stdio.a02 b/include/stdio.a02 index a79d3cf..1cb032d 100644 --- a/include/stdio.a02 +++ b/include/stdio.a02 @@ -8,7 +8,7 @@ ;Uses: System Dependent ;Affects: System Dependent ;Returns: A = Character Code of Key -GETC EQU GETKEY ;Alias to external GETKEY routine +GETC EQU RDKEY ;Alias to external RDKEY routine ;void putc(c) - PUT Character to screen ;Args: Character code to display diff --git a/include/stdiox.a02 b/include/stdiox.a02 index 1bdd706..52148d2 100644 --- a/include/stdiox.a02 +++ b/include/stdiox.a02 @@ -1,6 +1,6 @@ ; C02 library stdiox.h02 assembly language subroutines -ANYKEP: DC "Press any key to continue...",0 +ANYKEP: DC "PRESS ANY KEY...",0 ; ;char anykey() - wait for character with ANY KEY prompt @@ -138,10 +138,14 @@ PRINTD: CMP #'D ;'Else If "d" or "D" JSR PUTDEC ; Print as Decimal JMP PRINTY ; and Continue Printing Screen PRINTH: CMP #'H ;'Else If "h" or "H" - BNE PRINTS + BNE PRINTN LDA TEMP3 ; Load Byte to Format JSR PUTHEX ; Print as Hexadecimal JMP PRINTY ; and Continue Printing Screen +PRINTN: CMP #'N ;'Else If "n" or "N" + BNE PRINTS + JSR NEWLIN ; Execute Newline Function + JMP PRINTY ; and Continue Printing Screen PRINTS: CMP #'S ;'Else If "s" or "S" BNE PRINTW STY TEMP0 ; Save Index @@ -158,8 +162,7 @@ PRINTW: CMP #'W ;'Else If "w" or "W" PRINTB: LDA TEMP3 ;Else JMP PRINTC ; Print Raw Byte and Continue - ;and fall into putsub -;char putdst() + ;char putdst() PUTDST: LDY #0 ;Initialize character offset PUTDSL: LDA (DSTLO),Y ;Read next character in string BEQ PUTDSX ;If Not 0 diff --git a/include/stdlib.a02 b/include/stdlib.a02 index 54e5ff7..96b4f3d 100644 --- a/include/stdlib.a02 +++ b/include/stdlib.a02 @@ -1,4 +1,4 @@ -f; C02 library stdlib.h02 assembly language subroutines +; C02 library stdlib.h02 assembly language subroutines ; Requires ; external zero page locations SRCLO and srchi ; and external locations RANDOM, RDSEED, TEMP0, TEMP1, and TEMP2. @@ -121,18 +121,6 @@ SHIFTR: LSR ;Shift Byte to Right BNE SHIFTR ; and Loop if Not 0 RTS -;SWAP Nybbles in Byte -;Args: A = Byte containing Nybbles to Swap -;Affects: C,N,Z -;Returns: A = Byte with Nybbles Swapped -SWAP: ASL ;Code by - ADC #$80 ;David Galloway - ROL ;posted on - ASL ;6502.org by - ADC #$80 ;Garth Wilson - ROL ;Oct 27, 2017 - RTS - ;atoc(&s) - ASCII string TO Character ;Args: Y,X = Address of String to Convert ;Uses: TEMP0, TEMP1 diff --git a/include/stdlib.h02 b/include/stdlib.h02 index 82f6d76..27f81eb 100644 --- a/include/stdlib.h02 +++ b/include/stdlib.h02 @@ -65,11 +65,6 @@ char shiftl(); * Returns: Shifted Byte */ char shiftr(); -/* Swap Nybbles in Byte * - * Args: b - Byte to Swap * - * Returns: Swapped Byte */ -char swap(); - /* Seed Pseudo-Random Number Generator * * Args: n - Seed number */ void srand(); diff --git a/include/string.a02 b/include/string.a02 index 105c6af..207c643 100644 --- a/include/string.a02 +++ b/include/string.a02 @@ -94,7 +94,7 @@ STRCAX: STY TEMP0 ;Subtract Destination String Length ;Args: X,Y = Pointer to source string ;Sets: SRCLO,SRCHI = Pointer to source string ;Affects: N,Z -;Returns: A,Y = Number of characters copies +;Returns: A,Y = Number of characters copied STRCPY: JSR SETSRC ;Initialize Source String STRCPL: LDA (SRCLO),Y ;Get Character from Source String STA (DSTLO),Y ;Copy to Destination String diff --git a/include/test.a02 b/include/test.a02 index 9602c78..6949f6f 100644 --- a/include/test.a02 +++ b/include/test.a02 @@ -5,8 +5,8 @@ ; and external constants #TRUE and #FALSE ;Predefined Strings -PASS DC " Pass",0 -FAIL DC " Fail",0 +PASS DC " PASS",0 +FAIL DC " FAIL",0 ;putadr(&addr) - PUT ADdRess to screen ;Args: Y = Address MSB @@ -20,7 +20,7 @@ PUTADR: JSR SAVRXY ;Save Address LDX #