2018-01-28 18:30:49 +00:00
|
|
|
; Program initialization code for C02 programs
|
|
|
|
; Template for System Specific Code
|
|
|
|
|
|
|
|
;System Specific ASCII Key Mappings
|
|
|
|
DELKEY EQU $7F ;Delete/Backspace Key ($08=Backspace, $7F=Delete)
|
|
|
|
ESCKEY EQU $1B ;Escape/Stop Key ($03=Ctrl-C, $1B=Escape)
|
|
|
|
RTNKEY EQU $0D ;Return/Enter Key ($0D=Carriage Return)
|
|
|
|
NULKEY EQU $00 ;No Key was Pressed ($00=Null)
|
|
|
|
|
|
|
|
;Zero Page Locations
|
2019-03-23 00:28:43 +00:00
|
|
|
SRCLO EQU $00 ;Source String/Array Pointer
|
2018-01-28 18:30:49 +00:00
|
|
|
SRCHI EQU $01
|
2019-03-23 00:28:43 +00:00
|
|
|
DSTLO EQU $02 ;Destination String/Array Pointer
|
2018-01-28 18:30:49 +00:00
|
|
|
DSTHI EQU $03
|
2019-03-23 00:28:43 +00:00
|
|
|
BFRLO EQU $04 ;Work Buffer Pointer
|
|
|
|
BFRHI EQU $05
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
STKSAV EQU $0D ;Stack Pointer Storage
|
|
|
|
RDSEED EQU $0E ;Pseudo-RANDOM Seed
|
|
|
|
RANDOM EQU $0F ;Pseudo-RANDOM Number Storage
|
|
|
|
TEMP0 EQU $10 ;Temporary Storage
|
|
|
|
TEMP1 EQU $11
|
|
|
|
TEMP2 EQU $12
|
2018-07-25 23:00:46 +00:00
|
|
|
TEMP3 EQU $12
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
BLKSLO EQU $20 ;Block Start Address
|
|
|
|
BLKSHI EQU $21
|
|
|
|
BLKELO EQU $22 ;Block End Address
|
|
|
|
BLKEHI EQU $23
|
2018-07-25 23:00:46 +00:00
|
|
|
BLKLO EQU $24 ;Block Pointer
|
|
|
|
BLKHI EQU $25
|
|
|
|
|
|
|
|
STKSLO EQU $28 ;Stack Start Address
|
|
|
|
STKSHI EQU $29
|
|
|
|
STKELO EQU $2A ;Stack End Address
|
|
|
|
STKEHI EQU $2B
|
|
|
|
STKLO EQU $2C ;Stack Pointer
|
|
|
|
STKHI EQU $2D
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2019-11-15 05:05:53 +00:00
|
|
|
;Placeholders Labels for the Example Code Below
|
|
|
|
POLKEY EQU $FFFE ;ROM Read Key Routine
|
|
|
|
WSTART EQU $FFFF ;BASIC Warm Start Routine
|
|
|
|
|
2018-01-28 18:30:49 +00:00
|
|
|
ORG $0200 ;Program Start Address
|
|
|
|
|
|
|
|
START: NOP ;System specific initialization code
|
|
|
|
TXS ;If an RTS is used to return to the Operating System,
|
|
|
|
STX STKSAV ; the Stack Pointer should be preserved
|
|
|
|
JMP MAIN ;Execute Program
|
|
|
|
|
2018-11-07 05:11:09 +00:00
|
|
|
|
|
|
|
;Exit Program and Return to Operating System or Monitor
|
|
|
|
EXIT: BRK ;Usually BRK if returning to Monitor
|
|
|
|
LDX STKSAV ;If an RTS is used to return to the Operating System,
|
|
|
|
TXS ; the Stack Pointer should be restored to original state
|
|
|
|
RTS ; in case program exits in the middle of a Function
|
|
|
|
JMP WSTART ;Or it may just execute the BASIC Warm Start Routine
|
|
|
|
|
2018-01-28 18:30:49 +00:00
|
|
|
;Poll Character from Keyboard
|
|
|
|
PLKEY: INC RDSEED ;Cycle the Random Seed (if not provided by system)
|
|
|
|
NOP ;Code Read from Keyboad
|
|
|
|
RTS
|
|
|
|
|
|
|
|
;Read Character from Console
|
|
|
|
GETKEY; ;Usually Drops into RDKEY, but may need to call RDKEY
|
|
|
|
; then clean/convert returned value (e.g. Apple-1)
|
|
|
|
|
|
|
|
;Wait for Character from Console
|
2018-11-07 05:11:09 +00:00
|
|
|
GETCHR: JSR POLKEY ;Usually calls POLKEY
|
|
|
|
BEQ GETCHR ; until a non-zero is returned
|
2018-01-28 18:30:49 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
;Delete Previous Character
|
|
|
|
DELCHR: RTS ;Code to move Cursor to left and clear that position
|
|
|
|
;May work differently on systems that don't support this
|
|
|
|
|
|
|
|
;Advance Cursor to Next line
|
|
|
|
NEWLIN: RTS ;Code to move Cursor to beginning of next line
|
|
|
|
;May emit Carriage Return, Line Feed, or both
|
|
|
|
|
|
|
|
;Print Character to Screen
|
2018-11-07 05:11:09 +00:00
|
|
|
PUTCHR RTS ;Code to write ASCII character to Screen
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2019-11-15 05:05:53 +00:00
|
|
|
INCLUDE "../include/prbyte.a02" ;PRBYTE and PRHEX routines
|
|
|
|
|