2018-02-14 00:55:25 +00:00
|
|
|
;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)
|
|
|
|
|
2018-02-15 04:42:10 +00:00
|
|
|
;Zero Page Variables (*=System Variable)
|
2018-02-14 00:55:25 +00:00
|
|
|
DSTLO EQU $06 ;Destination String Pointer (string.a02)
|
|
|
|
DSTHI EQU $07
|
|
|
|
BLKLO EQU $08 ;Block Segment Pointer (block.a02)
|
|
|
|
BLKHI EQU $09
|
|
|
|
PTRLO EQU $1D ;System Pointer (pointer.a02)
|
|
|
|
PTRHI EQU $1E
|
|
|
|
RANDOM EQU $1F ;Random Number
|
2018-02-15 04:42:10 +00:00
|
|
|
INVFLG EQU $32 ;*Inverse Flag: $3F=Blinking, $7F=Inverse, $FF=Normal
|
|
|
|
RDSEED EQU $4E ;O/S Random Number Low Byte
|
2018-02-14 00:55:25 +00:00
|
|
|
; EQU $4F ;O/S Random Number High Byte
|
|
|
|
SRCLO EQU $71 ;Source String Pointer (stdio.a02)
|
|
|
|
SRCHI EQU $72
|
|
|
|
; $E3 ;Unused
|
|
|
|
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
|
|
|
|
|
2018-02-15 04:42:10 +00:00
|
|
|
;Page 3 Vectors
|
|
|
|
WARMST EQU $3D0 ;Jump vector to DOS warm start
|
|
|
|
COLDST EQU $3D3 ;Jump vector to DOS cold start
|
|
|
|
|
2018-02-14 00:55:25 +00:00
|
|
|
;I/O Locations
|
|
|
|
KBD EQU $C000 ;Keyboard Data
|
|
|
|
AKD EQU $C010 ;Keyboard Strobe Register
|
|
|
|
|
2018-03-03 19:35:12 +00:00
|
|
|
;BASIC Routines
|
|
|
|
SHWCUR EQU $CC4C ;Display Cursor
|
|
|
|
UPDATE EQU $CC70 ;Flash Cursor
|
|
|
|
STORY EQU $C3B3 ;Store Accumulator at Current Screen Position
|
|
|
|
|
2018-02-14 00:55:25 +00:00
|
|
|
;Monitor Routines
|
2018-02-15 04:42:10 +00:00
|
|
|
PRBLNK EQU $F94C ;Print 3 blanks
|
|
|
|
PRBLNX EQU $F94C ;Print X blanks
|
|
|
|
PRBLAX EQU $F94C ;Print character in A followed by X-1 blanks
|
2018-02-14 00:55:25 +00:00
|
|
|
RDKEY EQU $FD0C ;Waits for keypress and return in A
|
|
|
|
KEYIN EQU $FD1B ;Waits for keypress and cycle random-number generator
|
|
|
|
RDCHAR EQU $FD35 ;Read keyboard (processing escapes)
|
|
|
|
GETLIN EQU $FD6A ;Get Line from Keyboard into Input Buffer
|
|
|
|
CROUT EQU $FD8E ;Performs a carriage return
|
|
|
|
PRBYTE EQU $FDDA ;Print Accumulator as Hexadecimal Number
|
|
|
|
PRHEX EQU $FDE3 ;Print Low Nybble of Accumulator as Hex Digit
|
2018-02-15 04:42:10 +00:00
|
|
|
COUT EQU $FDED ;Print Character to Current Output Device
|
|
|
|
COUT1 EQU $FDF0 ;Print Character to Screen
|
2018-02-14 00:55:25 +00:00
|
|
|
BELL EQU $FF3A ;Ring Bell through COUT
|
|
|
|
MONZ EQU $FF69 ;Enter monitor (<Control-C>, <Return> leaves the monitor)
|
|
|
|
|
2018-02-15 04:42:10 +00:00
|
|
|
ECHO EQU COUT1 ;Print Character
|
|
|
|
EXIT EQU WARMST ;Return to Monitor
|
2018-02-14 00:55:25 +00:00
|
|
|
|
|
|
|
ORG $0C00 ;Safe Area for Machine Language
|
|
|
|
|
|
|
|
START: JMP MAIN ;Execute Program
|
|
|
|
|
|
|
|
;Subroutine Poll Keyboard
|
|
|
|
PLKEY: 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
|
2018-03-03 19:35:12 +00:00
|
|
|
GETKEY JSR PLKEY ;Poll Keyboard
|
|
|
|
BEQ GETKEY ;Loop if No Key
|
|
|
|
AND #$7F ;Strip High Bit
|
|
|
|
RTS
|
2018-02-17 18:52:13 +00:00
|
|
|
|
2018-02-15 04:42:10 +00:00
|
|
|
;Print Character to Screen
|
|
|
|
PRCHR: ORA #$80 ;Set High Bit
|
|
|
|
CMP #$E0 ;
|
|
|
|
BCC PRCHRX ;If Lower Case
|
2018-03-03 19:35:12 +00:00
|
|
|
AND #$1F ; Convert to Inverse
|
2018-02-15 04:42:10 +00:00
|
|
|
PRCHRX: JMP ECHO ;Alias to Monitor Routine
|
2018-02-14 00:55:25 +00:00
|
|
|
|
|
|
|
;Delete Previous Character
|
|
|
|
DELCHR: LDX #2 ;Two Characters Total
|
|
|
|
LDA #$88 ;Load Backspace Character
|
2018-02-15 04:42:10 +00:00
|
|
|
JSR PRBLAX ;Print Accumulator and X-1 Blanks
|
2018-02-14 00:55:25 +00:00
|
|
|
LDA #$88 ;Load Backspace Character
|
|
|
|
JMP PRCHR ;and Print it
|
|
|
|
|
|
|
|
;Advance Character to Next line
|
|
|
|
NEWLIN EQU CROUT ;Alias to Monitor Routine
|
|
|
|
|
|
|
|
;Initialize Destination String Pointer and Index
|
|
|
|
SETDST: STX DSTLO ;Save Destination String Pointer
|
|
|
|
STY DSTHI
|
|
|
|
RTS
|
|
|
|
|
|
|
|
;Initialize Source String Pointer and Index
|
|
|
|
SETSRC: STX SRCLO ;Save Source String Pointer
|
|
|
|
STY SRCHI
|
|
|
|
LDY #$00 ;Initialize Index Into String
|
|
|
|
RTS
|
|
|
|
|
|
|
|
;Retrieve Source String Pointer
|
|
|
|
GETSRC: LDX SRCLO
|
|
|
|
LDY SRCHI
|
|
|
|
RTS
|