1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-18 21:07:28 +00:00
C02/include/apple2.a02
2018-02-14 23:42:10 -05:00

106 lines
3.4 KiB
Plaintext

;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)
;Zero Page Variables (*=System Variable)
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
INVFLG EQU $32 ;*Inverse Flag: $3F=Blinking, $7F=Inverse, $FF=Normal
RDSEED EQU $4E ;O/S Random Number Low Byte
; 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
;Page 3 Vectors
WARMST EQU $3D0 ;Jump vector to DOS warm start
COLDST EQU $3D3 ;Jump vector to DOS cold start
;I/O Locations
KBD EQU $C000 ;Keyboard Data
AKD EQU $C010 ;Keyboard Strobe Register
;Monitor Routines
PRBLNK EQU $F94C ;Print 3 blanks
PRBLNX EQU $F94C ;Print X blanks
PRBLAX EQU $F94C ;Print character in A followed by X-1 blanks
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
COUT EQU $FDED ;Print Character to Current Output Device
COUT1 EQU $FDF0 ;Print Character to Screen
BELL EQU $FF3A ;Ring Bell through COUT
MONZ EQU $FF69 ;Enter monitor (<Control-C>, <Return> leaves the monitor)
ECHO EQU COUT1 ;Print Character
EXIT EQU WARMST ;Return to Monitor
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
GETKEY EQU KEYIN ;Alias to Monitor Routine
;Print Character to Screen
PRCHR: ORA #$80 ;Set High Bit
CMP #$E0 ;
BCC PRCHRX ;If Lower Case
AND #$DF ; Convert to Upper Case
PRCHRX: JMP ECHO ;Alias to Monitor Routine
;Delete Previous Character
DELCHR: LDX #2 ;Two Characters Total
LDA #$88 ;Load Backspace Character
JSR PRBLAX ;Print Accumulator and X-1 Blanks
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