2020-04-27 15:50:22 +00:00
|
|
|
;run6502 program initialization code for c02 programs
|
|
|
|
|
|
|
|
;System Specific ASCII Key Mappings
|
|
|
|
DELKEY EQU $08 ;Delete/Backspace Key (Backspace)
|
2020-10-19 19:42:10 +00:00
|
|
|
ESCKEY EQU $1B ;Escape/Stop Key (Escape)
|
2020-10-16 02:58:12 +00:00
|
|
|
RTNKEY EQU $0D ;Return/Enter Key (Carriage Return)
|
2020-04-27 15:50:22 +00:00
|
|
|
|
2022-04-04 23:47:16 +00:00
|
|
|
;Zero Page Variables
|
|
|
|
; $00-$06 ;Reserved
|
|
|
|
|
|
|
|
XMBANK EQU $07 ;Extended Memory Bank
|
|
|
|
XMADDR EQU $08 ;Extended Memory Address
|
|
|
|
|
|
|
|
SRCPTR EQU $10 ;Source Pointer
|
|
|
|
DSTPTR EQU $12 ;Destination Pointer
|
|
|
|
|
|
|
|
TEMP0 EQU $14 ;Temporary Storage
|
|
|
|
TEMP1 EQU $15
|
|
|
|
TEMP2 EQU $16
|
|
|
|
TEMP3 EQU $17
|
|
|
|
TMPPTR EQU $18 ;Temporary Pointer
|
|
|
|
|
|
|
|
LSTPTR EQU $1A ;List Pointer
|
|
|
|
USRPTR EQU $1C ;User Pointer
|
|
|
|
; $1E ;Reserved
|
|
|
|
|
|
|
|
BLKLEN EQU $1F ;Block Segment Length
|
|
|
|
BLKPTR EQU $20 ;Block Segment Pointer
|
|
|
|
BLKBGN EQU $22 ;Block Start Address
|
|
|
|
BLKEND EQU $24 ;Block End Address
|
|
|
|
|
|
|
|
STKPTR EQU $26 ;Stack Pointer
|
|
|
|
STKBGN EQU $28 ;Stack Start Addres
|
|
|
|
STKEND EQU $2A ;Stack End Address
|
|
|
|
|
|
|
|
RDSEED EQU $2C ;Pseudo-RANDOM Seed
|
|
|
|
RANDOM EQU $2D ;Pseudo-RANDOM Number Storage
|
|
|
|
|
|
|
|
SYSBFP EQU $2E ;Position in System Buffer
|
|
|
|
.STKSAV EQU $2F ;Stack Pointer Storage
|
|
|
|
|
|
|
|
INTACC EQU $30 ;Integer Accumulator
|
|
|
|
INTOVR EQU $32 ;Integer Overflow
|
|
|
|
INTARG EQU $34 ;Integer Argument
|
|
|
|
|
|
|
|
; $34-$3F ;Reserved
|
|
|
|
; $40-$FF ;Free Zero Page for Applications
|
2020-10-11 18:45:01 +00:00
|
|
|
|
|
|
|
SYSBFL EQU 128 ;System Buffer Size (Max String Size)
|
|
|
|
SYSBFR EQU $0200 ;System Buffer
|
2020-10-19 19:42:10 +00:00
|
|
|
; $0281-$03FF ;Unused
|
2020-10-11 18:45:01 +00:00
|
|
|
|
2022-04-04 23:47:16 +00:00
|
|
|
;Emulated BIOS System Calls
|
|
|
|
.GETCH EQU $FFE0 ;-K Read Keyboard
|
|
|
|
.PUTCH EQU $FFE3 ;-C Write to Screen
|
|
|
|
FSCMD EQU $FFE6 ;-F filecmd() - File I/O Command Processor
|
|
|
|
SYSCMD EQU $FFE9 ;-S syscmd() - System Command Processor
|
|
|
|
XMCMD EQU $FFEC ;-E Extended Memory
|
|
|
|
.STDIO EQU $FFEF ;-M Memory Mapped stdio
|
|
|
|
EXIT EQU $FFF0 ;-X Exit Emulator
|
|
|
|
|
|
|
|
; $0000 ;-N NMI Vector
|
2020-04-27 15:50:22 +00:00
|
|
|
|
2022-04-04 23:47:16 +00:00
|
|
|
ARGV EQU $0300 ;Command Line Arguments Bu
|
|
|
|
|
2020-10-11 18:45:01 +00:00
|
|
|
ORG $0400 ;START at RAM midpoint
|
2020-04-27 15:50:22 +00:00
|
|
|
|
|
|
|
START: JMP MAIN ;Execute Program
|
|
|
|
|
|
|
|
;Read Character from Console
|
2022-04-04 23:47:16 +00:00
|
|
|
GETKEY EQU .GETCH ;Emulator _GETCH Routine
|
2020-04-27 15:50:22 +00:00
|
|
|
|
|
|
|
;Poll Character from Keyboard
|
|
|
|
POLKEY: BRK ;Exit Emulator
|
|
|
|
|
|
|
|
|
|
|
|
;Wait for Character from Console
|
2020-10-16 02:58:12 +00:00
|
|
|
GETCHR: JSR GETKEY ;Get Key from Console
|
|
|
|
BEQ GETCHR ;If None Pressed, Loop
|
|
|
|
RTS
|
|
|
|
|
|
|
|
;Read Character from stdin
|
2022-04-04 23:47:16 +00:00
|
|
|
RDCHAR: LDA .STDIO ;Read Character from STDIN
|
2020-04-27 15:50:22 +00:00
|
|
|
CMP #$FF ;If EOF
|
2020-10-16 02:58:12 +00:00
|
|
|
BNE RDCHAX
|
|
|
|
LDA #0 ; Set to ASCII NUL
|
|
|
|
RDCHAX ORA #0 ;Set Flags
|
2020-04-27 15:50:22 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
;Delete Previous Character
|
|
|
|
DELCHR: LDA #$08 ;Load Backspace into Accumulator
|
|
|
|
JSR PUTCHR ; and Print it
|
2020-10-16 02:58:12 +00:00
|
|
|
LDA #$20 ;Load Space into Accumulator
|
2020-04-27 15:50:22 +00:00
|
|
|
JSR PUTCHR ; and Print it
|
|
|
|
LDA #$08 ;Load Backspace into Accumulator
|
|
|
|
JMP PUTCHR ; and Print it
|
|
|
|
|
|
|
|
;Advance Character to Next line
|
2020-10-16 02:58:12 +00:00
|
|
|
NEWLIN: LDA #$0D ;Load Carriage Return into Accumulator
|
|
|
|
JSR PUTCHR ; and Print it
|
|
|
|
LDA #$0A ;Load Line Feed into Accumulator
|
2020-04-27 15:50:22 +00:00
|
|
|
JMP PUTCHR ; and Print it
|
|
|
|
|
|
|
|
;Print Character to Console
|
2022-04-04 23:47:16 +00:00
|
|
|
PUTCHR EQU .PUTCH ;Emulator CHROUT Routine
|
2020-04-27 15:50:22 +00:00
|
|
|
|
2020-10-16 02:58:12 +00:00
|
|
|
;Write Character to stdout
|
2022-04-04 23:47:16 +00:00
|
|
|
PRCHAR: STA .STDIO ;Read Character from STDIN
|
2020-10-16 02:58:12 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
INCLUDE "prbyte.a02" ;PRBYTE and PRHEX routines
|
|
|
|
INCLUDE "putstr.a02" ;PUTSTR routine
|
|
|
|
|