2018-08-14 18:14:32 +00:00
|
|
|
;Apple 1 program initialization code for c02 programs
|
|
|
|
|
2020-04-27 16:20:37 +00:00
|
|
|
SUBROUTINE _APPLE2
|
|
|
|
|
2018-08-14 18:14:32 +00:00
|
|
|
;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)
|
2020-10-11 18:45:01 +00:00
|
|
|
DSTPTR EQU $06 ;Destination Pointer [Unused]
|
|
|
|
DSTLO EQU $06
|
2018-08-14 18:14:32 +00:00
|
|
|
DSTHI EQU $07
|
2020-10-11 18:45:01 +00:00
|
|
|
BLKLO EQU $08 ;Block Segment Pointer [Unused]
|
2018-08-14 18:14:32 +00:00
|
|
|
BLKHI EQU $09
|
2020-10-11 18:45:01 +00:00
|
|
|
SYSBFP EQU $1D ;Stack Pointer [Unused]
|
|
|
|
; $1E ;Unused
|
|
|
|
STKLO EQU $2E ;Stack Pointer [Tape Read Work Area]
|
|
|
|
STKHI EQU $2F
|
2018-08-14 18:14:32 +00:00
|
|
|
RANDOM EQU $1F ;Random Number
|
2020-10-11 18:45:01 +00:00
|
|
|
.INVFLG EQU $32 ;*Inverse Flag: $3F=Blinking, $7F=Inverse, $FF=Normal
|
|
|
|
SRCPTR EQU $71 ;Source Pointer [Temporary Register]
|
|
|
|
SRCLO EQU $71
|
2018-08-14 18:14:32 +00:00
|
|
|
SRCHI EQU $72
|
|
|
|
RDSEED EQU $E3 ;Random Seed
|
2020-10-11 18:45:01 +00:00
|
|
|
BLKSLO EQU $EB ;Block Start Address [Unused]
|
|
|
|
BLKSHI EQU $EC
|
|
|
|
BLKELO EQU $ED ;Block End Address [Unused]
|
2018-08-14 18:14:32 +00:00
|
|
|
BLKEHI EQU $EE
|
2020-10-11 18:45:01 +00:00
|
|
|
BLKLEN EQU $EF ;Block Segment Length [Unused]
|
|
|
|
BFRLO EQU $FA ;Work Buffer Pointer [Unused]
|
2019-03-23 00:14:00 +00:00
|
|
|
BFRHI EQU $FB
|
2020-10-11 18:45:01 +00:00
|
|
|
TEMP0 EQU $FC ;Temporary Variables [Unused]
|
2018-08-14 18:14:32 +00:00
|
|
|
TEMP1 EQU $FD
|
|
|
|
TEMP2 EQU $FE
|
|
|
|
TEMP3 EQU $FF
|
|
|
|
|
2020-10-11 18:45:01 +00:00
|
|
|
;System Variables
|
|
|
|
SYSBFL EQU 255 ;System Buffer Size [88 Bytes]
|
|
|
|
SYSBFR EQU $0300 ;System Buffer [Keyboard Buffer]
|
|
|
|
|
|
|
|
|
2018-08-14 18:14:32 +00:00
|
|
|
;I/O Locations
|
2020-04-27 16:20:37 +00:00
|
|
|
.KBD EQU $C000 ;Keyboard Data
|
|
|
|
.AKD EQU $C010 ;Keyboard Strobe Register
|
2018-08-14 18:14:32 +00:00
|
|
|
|
|
|
|
;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
|
|
|
|
|
2018-09-12 13:54:54 +00:00
|
|
|
;Poll Keyboard for Raw Character
|
|
|
|
POLKEY: INC RDSEED ;Cycle Random Seed
|
2018-08-14 18:14:32 +00:00
|
|
|
LDA #0 ;Clear Accumulator
|
2020-04-27 16:20:37 +00:00
|
|
|
BIT .KBD ;Check Keyboard Strobe Bit
|
2018-09-12 13:54:54 +00:00
|
|
|
BPL POLKER ;If Key Pressed
|
2020-04-27 16:20:37 +00:00
|
|
|
LDA .KBD ; Load Key Value
|
|
|
|
STA .AKD ; Clear Strobe
|
2018-09-12 13:54:54 +00:00
|
|
|
POLKER: RTS
|
2018-08-14 18:14:32 +00:00
|
|
|
|
2018-09-12 13:54:54 +00:00
|
|
|
;Get ASCII Character from Keyboard
|
|
|
|
GETKEY: JSR POLKEY ;Poll Keyboard
|
2018-08-14 18:14:32 +00:00
|
|
|
AND #$7F ;Strip High Bit
|
|
|
|
RTS
|
|
|
|
|
2018-09-12 13:54:54 +00:00
|
|
|
;Wait for ASCII Character from Keyboard
|
|
|
|
GETCHR: JSR GETKEY ;Get Modified Key Code
|
|
|
|
BEQ GETCHR ;Loop if No Key
|
2018-08-14 18:14:32 +00:00
|
|
|
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
|
2018-09-12 13:54:54 +00:00
|
|
|
PUTCHR: ORA #$80 ;Set High Bit
|
2018-08-14 18:14:32 +00:00
|
|
|
CMP #$E0 ;
|
|
|
|
BCC PRCHRX ;If Lower Case
|
|
|
|
AND #$1F ; Convert to Inverse
|
2020-04-27 16:20:37 +00:00
|
|
|
PRCHRX: JMP $FDF0 ;Execute Monitor Routine COUT1
|
2018-08-14 18:14:32 +00:00
|
|
|
|
|
|
|
;Advance Character to Next line
|
|
|
|
NEWLIN EQU $FD8E ;Monitor Routine CROUT
|
2020-04-27 16:20:37 +00:00
|
|
|
|
|
|
|
INCLUDE "../include/putstr.a02" ;PUTSTR routine
|