;Apple 1 program initialization code for c02 programs SUBROUTINE _APPLE2 ;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) DSTPTR EQU $06 ;Destination Pointer [Unused] BLKPTR EQU $08 ;Block Segment Pointer [Unused] SYSBFP EQU $1D ;Stack Pointer [Unused] ; $1E ;Unused STKLO EQU $2E ;Stack Pointer [Tape Read Work Area] STKHI EQU $2F RANDOM EQU $1F ;Random Number .INVFLG EQU $32 ;*Inverse Flag: $3F=Blinking, $7F=Inverse, $FF=Normal SRCPTR EQU $71 ;Source Pointer [Temporary Register] RDSEED EQU $E3 ;Random Seed BLKBGN EQU $EB ;Block Start Address [Unused] BLKEND EQU $ED ;Block End Address [Unused] BLKLEN EQU $EF ;Block Segment Length [Unused] BFRLO EQU $FA ;Work Buffer Pointer [Unused] BFRHI EQU $FB TEMP0 EQU $FC ;Temporary Variables [Unused] TEMP1 EQU $FD TEMP2 EQU $FE TEMP3 EQU $FF ;System Variables SYSBFL EQU 255 ;System Buffer Size [88 Bytes] SYSBFR EQU $0300 ;System Buffer [Keyboard Buffer] ;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 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 ;Poll Keyboard for Raw Character POLKEY: INC RDSEED ;Cycle Random Seed LDA #0 ;Clear Accumulator BIT .KBD ;Check Keyboard Strobe Bit BPL POLKER ;If Key Pressed LDA .KBD ; Load Key Value STA .AKD ; Clear Strobe POLKER: RTS ;Get ASCII Character from Keyboard GETKEY: JSR POLKEY ;Poll Keyboard AND #$7F ;Strip High Bit RTS ;Wait for ASCII Character from Keyboard GETCHR: JSR GETKEY ;Get Modified Key Code BEQ GETCHR ;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 PUTCHR: ORA #$80 ;Set High Bit CMP #$E0 ; BCC PRCHRX ;If Lower Case AND #$1F ; Convert to Inverse PRCHRX: JMP $FDF0 ;Execute Monitor Routine COUT1 ;Advance Character to Next line NEWLIN EQU $FD8E ;Monitor Routine CROUT INCLUDE "../include/putstr.a02" ;PUTSTR routine