2019-11-15 18:27:55 +00:00
|
|
|
; c02 Program Initialization Code for Commodore 64
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2018-09-17 00:30:25 +00:00
|
|
|
;PETSCII Key Mappings
|
2019-11-15 18:27:55 +00:00
|
|
|
DELKEY EQU $14 ;Delete/Backspace Key (Delete)
|
|
|
|
ESCKEY EQU $03 ;Escape/Stop Key (RUN/STOP)
|
|
|
|
RTNKEY EQU $0D ;Return/Enter Key (RETURN)
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2018-09-17 00:30:25 +00:00
|
|
|
;Zero Page Variables
|
2020-10-19 19:42:10 +00:00
|
|
|
XMBANK EQU $0A ;Extended Memory Bank [Load/Verify Flag]
|
|
|
|
XMADDR EQU $0B ;Extended Memory Address [Array Index/Flags]
|
|
|
|
; $16 ;[Temporary String Stack Pointer]
|
|
|
|
SRCPTR EQU $17 ;Source Pointer [Temporary String Space Pointer]
|
|
|
|
DSTPTR EQU $19 ;Destination Pointer [Temporary String Stack]
|
|
|
|
; $21 ;[Temporary String Stack]
|
|
|
|
BLKPTR EQU $22 ;Block Pointer [Temporary Pointers]
|
|
|
|
STKPTR EQU $24 ;Stack Pointer [Temporary Pointers]
|
|
|
|
; $26-$29 ;[Floating Point Work Area]
|
|
|
|
USRPTR EQU $35 ;[Temporary String Pointer]
|
|
|
|
TEMP0 EQU $61 ;Temporary Variable [Floating Point Accumulator]
|
|
|
|
TEMP1 EQU $63 ;Temporary Variable [Floating Point Accumulator]
|
|
|
|
TEMP2 EQU $65 ;Temporary Variable [Floating Point Accumulator]
|
|
|
|
TEMP3 EQU $67 ;Temporary Variable [Floating Point Accumulator]
|
|
|
|
TMPPTR EQU $69 ;Temporary Pointer [Floating Point Argument]
|
|
|
|
; $6A-$70 ;[Floating Point Argument]
|
2021-09-04 21:03:07 +00:00
|
|
|
.STKEY EQU $91 ;Stop Key flag
|
2019-11-15 18:27:55 +00:00
|
|
|
RDSEED EQU $A2 ;Random Seed [Software Jiffy Clock (Low Byte)]
|
2020-10-19 19:42:10 +00:00
|
|
|
; $FB-$FE ;Unused Zero Page for Applications
|
2018-09-17 00:30:25 +00:00
|
|
|
|
|
|
|
;System Variables
|
2020-10-19 19:42:10 +00:00
|
|
|
SYSBFL EQU 88 ;System Buffer Size (88 Bytes)
|
2020-10-11 18:45:01 +00:00
|
|
|
SYSBFR EQU $0200 ;System Buffer [Keyboard Buffer]
|
|
|
|
SYSBFP EQU $0313 ;Position in System Buffer [Free Byte]
|
2018-09-17 00:30:25 +00:00
|
|
|
|
2020-10-16 02:58:12 +00:00
|
|
|
BLKBGN EQU $0334 ;Block Start [Unused Byte]
|
|
|
|
BLKEND EQU $0336 ;Block Start [Unused Byte]
|
2018-09-17 00:30:25 +00:00
|
|
|
BLKLEN EQU $0338 ;Block Length [Unused Byte]
|
|
|
|
|
|
|
|
RANDOM EQU $0339 ;Random Number Storage [Unused Byte]
|
2021-09-04 21:03:07 +00:00
|
|
|
.STKSAV EQU $033A ;Machine Stack Storage [Unused Byte]
|
2020-10-19 19:42:10 +00:00
|
|
|
; $033B ;Free Byte for User Programs
|
2018-09-17 00:30:25 +00:00
|
|
|
TBFFR EQU $033C ;Cassette I/O Buffer
|
|
|
|
|
2020-10-19 19:42:10 +00:00
|
|
|
STKBGN EQU $03FC ;Stack Start [Unused Byte]
|
|
|
|
STKEND EQU $03FE ;Stack End [Unused Byte]
|
2018-09-17 00:30:25 +00:00
|
|
|
|
|
|
|
;Video RAM and ROM
|
|
|
|
VICSCN EQU $0400 ;Video Screen Memory Area (Unexpanded)
|
|
|
|
CHRROM EQU $D000 ;Character Generator ROM
|
|
|
|
VICCLR EQU $D800 ;Color RAM (Unexpanded)
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2019-03-29 23:06:12 +00:00
|
|
|
;ROM Routines
|
|
|
|
FSFLFA EQU $F314 ;Find Logical File A
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
;Machine Language Basic Stub
|
2018-09-17 00:30:25 +00:00
|
|
|
ORG $0801 ;Start of Basic Program
|
2019-11-15 18:27:55 +00:00
|
|
|
BASIC: DC $0C, $08 ;Pointer to Next Line
|
2018-09-17 00:30:25 +00:00
|
|
|
DC $00, $00 ;Line Number (0)
|
|
|
|
DC $9E ;SYS
|
|
|
|
DC $20 ;' '
|
|
|
|
DC $32, $30, $36 ,$32 ;"2062"
|
2018-01-28 18:30:49 +00:00
|
|
|
DC $00 ;End of Line Marker
|
|
|
|
DC $00, $00 ;End of Basic Program
|
|
|
|
|
2018-09-17 00:30:25 +00:00
|
|
|
START: TSX ;Get Stack Pointer
|
2021-09-04 21:03:07 +00:00
|
|
|
STX .STKSAV ;and Save for Exit
|
2018-09-17 00:30:25 +00:00
|
|
|
JMP MAIN ;Execute Program
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2021-09-04 21:03:07 +00:00
|
|
|
EXIT: LDA #0 ;Clear Stop Key Flag
|
|
|
|
STA .STKEY
|
|
|
|
LDX .STKSAV ;Retrieve Saved Stack Pointer
|
2018-09-17 00:30:25 +00:00
|
|
|
TXS ;and Restore It
|
2020-10-19 19:42:10 +00:00
|
|
|
RTS
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2018-09-17 00:30:25 +00:00
|
|
|
;Poll Keyboard for Character
|
|
|
|
POLKEY EQU $FFE4 ;Aliased to Kernal GETIN Routine
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2018-09-17 00:30:25 +00:00
|
|
|
;Get Character from Keyboard
|
|
|
|
GETKEY EQU POLKEY ;Get Key From Keybord
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2018-09-17 00:30:25 +00:00
|
|
|
;Wait for Character from Keyboard
|
|
|
|
GETCHR: JSR GETKEY ;Poll Keyboard
|
|
|
|
BEQ GETCHR ;If No Key, Loop
|
2018-01-28 18:30:49 +00:00
|
|
|
RTS
|
|
|
|
|
2018-09-17 00:30:25 +00:00
|
|
|
;Print Character to Console
|
|
|
|
;uses direct call to SCRNOUT instead of CHROUT
|
|
|
|
PUTCHR EQU $E716 ;Aliased to SRCNOUT Routine
|
|
|
|
|
2018-01-28 18:30:49 +00:00
|
|
|
;Delete Previous Character
|
2018-09-17 00:30:25 +00:00
|
|
|
DELCHR: LDA #DELKEY ;Load Delete Character
|
|
|
|
JMP PUTCHR ;Print and Return
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
;Advance Character to Next line
|
2018-09-17 00:30:25 +00:00
|
|
|
NEWLIN: LDX #0 ;Store 0
|
|
|
|
STX $D3 ;in Cursor Column and
|
|
|
|
JMP $E87C ;Execute NXTLINE Routine
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2019-11-15 18:27:55 +00:00
|
|
|
;Print Zero Delimited String to Screen
|
|
|
|
PUTSTR: TXA ;Copy LSB to Accumulator
|
|
|
|
JMP $AB1E ;Execute STROUT
|
|
|
|
|
2020-10-16 02:58:12 +00:00
|
|
|
INCLUDE "prbyte.a02" ;PRBYTE and PRHEX routine
|
|
|
|
|