2018-02-14 00:55:25 +00:00
|
|
|
;Apple 1 program initialization code for c02 programs
|
|
|
|
|
2020-04-27 16:20:37 +00:00
|
|
|
SUBROUTINE _APPLE1
|
|
|
|
|
2018-02-14 00:55:25 +00:00
|
|
|
;System Specific ASCII Key Mappings
|
|
|
|
DELKEY EQU $5F ;Delete/Backspace Key (Left Arrow/Underscore)
|
|
|
|
ESCKEY EQU $1B ;Escape/Stop Key (Escape)
|
|
|
|
RTNKEY EQU $0D ;Return/Enter Key (Carriage Return)
|
|
|
|
|
|
|
|
;Locations used by Monitor
|
2020-04-27 16:20:37 +00:00
|
|
|
.XAML EQU $24 ;Examine Index
|
|
|
|
.XAMH EQU $25 ;
|
|
|
|
.STL EQU $26 ;Store Index
|
|
|
|
.STH EQU $27 ;
|
|
|
|
.HEXL EQU $28 ;Hex Data
|
|
|
|
.HEXH EQU $29 ;
|
|
|
|
.YSAVE EQU $2A ;Y Register Storage
|
|
|
|
.MODE EQU $2B ;Mode: Store, Examine, Block Examine
|
2020-10-11 18:45:01 +00:00
|
|
|
.IN EQU $200 ;Input Buffer
|
2018-02-14 00:55:25 +00:00
|
|
|
|
|
|
|
;Standard Library Variables
|
2020-10-19 19:42:10 +00:00
|
|
|
SRCPTR EQU $30 ;Source String Pointer
|
|
|
|
DSTPTR EQU $32 ;Destination Pointer
|
|
|
|
BLKPTR EQU $34 ;Block Segment Pointer
|
|
|
|
STKPTR EQU $36 ;Stack Pointer
|
|
|
|
BLKBGN EQU $38 ;Block Start Address
|
|
|
|
BLKEND EQU $3A ;Block End Address
|
|
|
|
STKBGN EQU $3C ;Stack Start Address
|
|
|
|
STKEND EQU $3E ;Stack End Address
|
|
|
|
BLKLEN EQU $40 ;Block Segment Length
|
|
|
|
SYSBFP EQU $41 ;Position in System Buffer
|
|
|
|
RDSEED EQU $42 ;Pseudo-RANDOM Seed
|
|
|
|
RANDOM EQU $43 ;Pseudo-RANDOM Number Storage
|
|
|
|
TEMP0 EQU $44 ;Temporary Storage
|
|
|
|
TEMP1 EQU $45
|
|
|
|
TEMP2 EQU $46
|
|
|
|
TEMP3 EQU $47
|
|
|
|
TMPPTR EQU $48 ;Temporary Pointer
|
|
|
|
USRPTR EQU $4A ;User Pointer
|
|
|
|
; $4C-$4F ;Unused
|
|
|
|
; $50-$FF ;Free Zero Page for Applications
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-11 18:45:01 +00:00
|
|
|
|
|
|
|
SYSBFL EQU 128 ;System Buffer Size (128 Bytes)
|
|
|
|
SYSBFR EQU .IN ;System Buffer (Input Buffer
|
|
|
|
|
2018-02-14 00:55:25 +00:00
|
|
|
;PIA 6820 Registers
|
2020-04-27 16:20:37 +00:00
|
|
|
.KBD EQU $D010 ;Keyboard Data
|
|
|
|
.KBDCR EQU $D011 ;Keyboard Control Register
|
|
|
|
.DSP EQU $D012 ;Display Data
|
|
|
|
.DSPCR EQU $D013 ;Display Control Register
|
2018-02-14 00:55:25 +00:00
|
|
|
|
|
|
|
EXIT EQU $FF00 ;Monitor Entry Point
|
2020-04-27 16:20:37 +00:00
|
|
|
.ECHO EQU $FFEF ;Subroutine - Print Character in Accumulator
|
2020-10-19 19:42:10 +00:00
|
|
|
PRBYTE EQU $FFDC ;Subroutine - Print Accumulator as Hexadecimal Number
|
2018-02-14 00:55:25 +00:00
|
|
|
PRHEX EQU $FFE5 ;Subroutine - Print Low Nybble of Accumulator as Hex Digit
|
|
|
|
|
|
|
|
ORG $0300 ;Start one page above Monitor input buffer
|
|
|
|
|
|
|
|
START: LDX #$FF ;Reset stack - the monitor doesn't do this
|
|
|
|
TXS ; (probably because of lack of space)
|
2018-08-19 22:24:02 +00:00
|
|
|
JSR NEWLIN ;Move cursor to next line before executing program
|
2018-02-14 00:55:25 +00:00
|
|
|
JMP MAIN ;Execute Program
|
|
|
|
|
|
|
|
|
|
|
|
;Subroutine Poll Keyboard
|
|
|
|
PLKEY: INC RDSEED ;Cycle Keypress Counter
|
2020-04-27 16:20:37 +00:00
|
|
|
LDA #0 ;Set Return Value to 0
|
|
|
|
BIT .KBDCR ;Check the Keyboard Control Register
|
|
|
|
BPL .PLKEYX ;If No Key Pressed, Return 0
|
|
|
|
LDA .KBD ;Else Read Key and Return
|
|
|
|
.PLKEYX RTS
|
|
|
|
|
|
|
|
GETKEY: JSR PLKEY ;Read Keyboard
|
|
|
|
AND #$7F ;Strip High Bit
|
|
|
|
RTS
|
|
|
|
|
|
|
|
BIT .GETKEM ;If Character is in
|
|
|
|
BEQ .GETKEX ; Alpha Block ($40-$74)
|
|
|
|
AND #$5F ; Strip Bit 5
|
|
|
|
.GETKEX RTS
|
|
|
|
.GETKEM DC $40 ;Character Block Bit Mask
|
2018-02-14 00:55:25 +00:00
|
|
|
|
2020-04-27 16:20:37 +00:00
|
|
|
GETCHR: JSR GETKEY ;Get Keypress
|
|
|
|
BEQ GETCHR ;Loop if No Key Pressed
|
2018-02-14 00:55:25 +00:00
|
|
|
RTS
|
|
|
|
|
2020-04-27 16:20:37 +00:00
|
|
|
PUTCHR EQU .ECHO ;Alias to Monitor Routine
|
2018-02-14 00:55:25 +00:00
|
|
|
|
|
|
|
;Delete Previous Character
|
|
|
|
DELCHR: LDA #DELKEY ;Load Underscore Character
|
2018-09-12 13:54:54 +00:00
|
|
|
JMP PUTCHR ; and Print it
|
2018-02-14 00:55:25 +00:00
|
|
|
|
|
|
|
;Advance Character to Next line
|
|
|
|
NEWLIN: LDA #$0D ;Load C/R into Accumulator
|
2018-09-12 13:54:54 +00:00
|
|
|
JMP PUTCHR ; and Print it
|
2020-04-27 16:20:37 +00:00
|
|
|
|
2020-10-19 19:42:10 +00:00
|
|
|
INCLUDE "putstr.a02" ;PUTSTR routine
|
2020-10-11 18:45:01 +00:00
|
|
|
|
|
|
|
ENDSUBROUTINE
|