2018-09-17 00:30:25 +00:00
|
|
|
;py65mon program initialization code for c02 programs
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
;System Specific ASCII Key Mappings
|
2018-02-02 21:33:57 +00:00
|
|
|
DELKEY EQU $08 ;Delete/Backspace Key (Backspace)
|
2018-01-28 18:30:49 +00:00
|
|
|
ESCKEY EQU $1B ;Escape/Stop Key (Escape)
|
|
|
|
RTNKEY EQU $0D ;Return/Enter Key (Carriage Return)
|
|
|
|
|
|
|
|
;Zero Page Locations
|
|
|
|
SRCLO EQU $30 ;Source String Pointer (stdio.a02)
|
|
|
|
SRCHI EQU $31
|
|
|
|
DSTLO EQU $32 ;Destination String Pointer (string.a02)
|
|
|
|
DSTHI EQU $33
|
|
|
|
BLKLO EQU $34 ;Block Segment Pointer (block.a02)
|
|
|
|
BLKHI EQU $35
|
2018-07-25 23:00:46 +00:00
|
|
|
STKLO EQU $36 ;Stack Pointer (stack.a02)
|
|
|
|
STKHI EQU $37
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
RDSEED EQU $3E ;Pseudo-RANDOM Seed
|
|
|
|
RANDOM EQU $3F ;Pseudo-RANDOM Number Storage
|
2018-02-02 20:50:49 +00:00
|
|
|
|
2018-01-28 18:30:49 +00:00
|
|
|
TEMP0 EQU $40 ;Temporary Storage
|
|
|
|
TEMP1 EQU $41
|
|
|
|
TEMP2 EQU $42
|
2018-02-02 20:50:49 +00:00
|
|
|
TEMP3 EQU $43
|
|
|
|
|
2018-07-25 23:00:46 +00:00
|
|
|
BLKSLO EQU $46 ;Block Start Address
|
|
|
|
BLKSHI EQU $47
|
|
|
|
BLKELO EQU $48 ;Block End Address
|
|
|
|
BLKEHI EQU $49
|
|
|
|
BLKLEN EQU $4A ;Block Segment Length
|
|
|
|
|
|
|
|
STKSLO EQU $4C ;Stack Start Address
|
|
|
|
STKSHI EQU $4D
|
|
|
|
STKELO EQU $4E ;Stack End Address
|
|
|
|
STKEHI EQU $4F
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
;Memory Mapped I/O
|
2018-09-17 00:30:25 +00:00
|
|
|
PUTCON EQU $F001 ;Write Character to Console
|
|
|
|
GETCON EQU $F004 ;Read Character from Console
|
|
|
|
|
|
|
|
;Interrupt Vectors
|
|
|
|
NMILO EQU $FFFA ;Non-Maskable Interrupt
|
|
|
|
NMIHI EQU $FFFB
|
|
|
|
RSTLO EQU $FFFC ;Reset
|
|
|
|
RSTHI EQU $FFFD
|
|
|
|
IRQLO EQU $FFFE ;Maskable Interrupt
|
|
|
|
IRQHI EQU $FFFF
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
ORG $0200 ;START Directly Above Stack
|
|
|
|
|
|
|
|
START: JMP MAIN ;Execute Program
|
|
|
|
|
|
|
|
;Poll Character from Keyboard
|
2018-09-17 00:30:25 +00:00
|
|
|
POLKEY: INC RDSEED ;Cycle the RANDOM Seed (if not provided by system)
|
2018-02-02 21:33:57 +00:00
|
|
|
LDA GETCON ;Read Character from Console
|
2018-08-14 18:14:32 +00:00
|
|
|
CMP #$E0
|
2018-09-17 00:30:25 +00:00
|
|
|
BEQ POLKEX ;If Not E0 Extended Key
|
2018-08-14 18:14:32 +00:00
|
|
|
ORA #$00 ; Set Status Flags
|
|
|
|
RTS ; and Return
|
2018-09-17 00:30:25 +00:00
|
|
|
POLKEX: LDA GETCON ;Else Get Second Byte
|
2018-08-14 18:14:32 +00:00
|
|
|
ORA #$80 ; Set High Byte
|
|
|
|
RTS ; and Return
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
;Read Character from Console
|
|
|
|
GETKEY ;Same As RDKEY
|
|
|
|
|
|
|
|
;Wait for Character from Console
|
2018-09-17 00:30:25 +00:00
|
|
|
GETCHR: JSR POLKEY ;Read Character from Console
|
|
|
|
BEQ GETCHR ; Loop if None Received
|
2018-01-28 18:30:49 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
;Delete Previous Character
|
|
|
|
DELCHR: LDA #$08 ;Load Backspace into Accumulator
|
2018-09-17 00:30:25 +00:00
|
|
|
JSR PUTCHR ; and Print it
|
2018-01-28 18:30:49 +00:00
|
|
|
LDA #$20 ;Load Space into Accumulater
|
2018-09-17 00:30:25 +00:00
|
|
|
JSR PUTCHR ; and Print it
|
2018-01-28 18:30:49 +00:00
|
|
|
LDA #$08 ;Load Backspace into Accumulator
|
2018-09-17 00:30:25 +00:00
|
|
|
JMP PUTCHR ; and Print it
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
;Advance Character to Next line
|
|
|
|
NEWLIN: LDA #$0D ;Load C/R into Accumulator
|
2018-09-17 00:30:25 +00:00
|
|
|
JSR PUTCHR ; and Print it
|
2018-01-28 18:30:49 +00:00
|
|
|
LDA #$0A ;Load L/F into Accumulater
|
|
|
|
; and fall into PRCHR
|
|
|
|
|
|
|
|
;Print Character to Console
|
2018-09-17 00:30:25 +00:00
|
|
|
PUTCHR STA PUTCON ;Write Character to Console
|
2018-01-28 18:30:49 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
EXIT: BRK ;Return to Monitor
|
|
|
|
|
|
|
|
;Print Byte as Two-Digit Hex Number to Console
|
|
|
|
PRBYTE: PHA ;Save Accumulater
|
|
|
|
LSR ;Shift Hi Nybble to Low Nybble
|
|
|
|
LSR
|
|
|
|
LSR
|
|
|
|
LSR
|
|
|
|
JSR PRHEX ; and Print it
|
|
|
|
PLA ;Restore Accumulator
|
|
|
|
; and fall into PRHEX
|
|
|
|
|
|
|
|
;Print Low Nybble as Hex Digit to Console
|
|
|
|
PRHEX: AND #$0F ;Strip High Nybb
|
|
|
|
SED ;Set Decimal Flag for
|
|
|
|
CLC ; Addition Wizardry
|
|
|
|
ADC #$90 ;Convert to $90-$99,$00-$05
|
|
|
|
ADC #$40 ;Convert to $30-$39,$41-$46
|
|
|
|
CLD ;Clear Decimal Flag
|
2018-09-17 00:30:25 +00:00
|
|
|
JMP PUTCHR ;Print Hex Digit and Return
|
|
|
|
|
|
|
|
;Set Non-Maskable Interrupt Handler
|
|
|
|
SETNMI: STY NMIHI
|
|
|
|
STX NMILO
|
|
|
|
RTS
|
|
|
|
|
|
|
|
;Set Reset Handler
|
|
|
|
SETRST: STY RSTHI
|
|
|
|
STX RSTLO
|
|
|
|
RTS
|
|
|
|
|
|
|
|
;Set Maskable Interrupt Handler
|
|
|
|
SETIRQ: STY IRQHI
|
|
|
|
STX IRQLO
|
|
|
|
RTS
|