mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-24 15:31:17 +00:00
Imported x16.h02 and x16.a02 from master
This commit is contained in:
parent
cf56e15c01
commit
b83b345ca4
96
include/x16.a02
Normal file
96
include/x16.a02
Normal file
@ -0,0 +1,96 @@
|
||||
; c02 Program Initialization Code for Commander X16
|
||||
; Compatible with x16emu Release 34
|
||||
|
||||
;PETSCII Key Mappings
|
||||
DELKEY EQU $14 ;Delete/Backspace Key (Delete)
|
||||
ESCKEY EQU $03 ;Escape/Stop Key (RUN/STOP)
|
||||
RTNKEY EQU $0D ;Return/Enter Key (RETURN)
|
||||
|
||||
;Zero Page System Variables - x16emu Release 34 Memory Map
|
||||
;UNUSED $00-$01 ;Available to User
|
||||
; $02-$52 ;Used by Basic graphics commands
|
||||
XMBANK EQU $53 ;Extended Memory Bank
|
||||
XADRLO EQU $54 ;Ext Memory Address LSB
|
||||
XADRHI EQU $55 ;Ext Memory Address MSB
|
||||
SRCPTR EQU $56 ;Source Pointer
|
||||
SRCLO EQU $57 ;Source Pointer LSB
|
||||
SRCHI EQU $58 ;Source Pointer MSB
|
||||
DSTPTR EQU $59 ;Destination Pointer
|
||||
DSTLO EQU $5A ;Destination Pointer LSB
|
||||
DSTHI EQU $5B ;Destination Pointer MSB
|
||||
BLKLO EQU $5C ;Block Pointer LSB
|
||||
BLKHI EQU $5D ;Block Pointer MSB
|
||||
STKLO EQU $5E ;Stack Pointer LSB
|
||||
STKHI EQU $5F ;Stack Pointer MSB
|
||||
BFRLO EQU $60 ;Buffer Pointer LSB
|
||||
BFRHI EQU $61 ;Buffer Pointer MSB
|
||||
RANDOM EQU $62 ;Random Number Storage
|
||||
RDSEED EQU $63 ;Random Seed
|
||||
TEMP0 EQU $64 ;Temporary Variable
|
||||
TEMP1 EQU $65 ;Temporary Variable
|
||||
TEMP2 EQU $66 ;Temporary Variable
|
||||
TEMP3 EQU $67 ;Temporary Variable
|
||||
; $68-7F ;Available to User
|
||||
; $80-$83 ;Used by Kernal and DOS
|
||||
; $A4-$A8 ;Reserved for KERNAL/DOS/BASIC
|
||||
; $A9-$FF ;Used by BASIC
|
||||
|
||||
;Other Variables - Top of Extended System RAM Area
|
||||
BLKSLO EQU $07F4 ;Block Start LSB
|
||||
BLKSHI EQU $07F5 ;Block Start MSB
|
||||
BLKELO EQU $07F6 ;Block End LSB
|
||||
BLKEHI EQU $07F7 ;Block End MSB
|
||||
BLKLEN EQU $07F8 ;Block Length
|
||||
|
||||
STKSAV EQU $07FA ;Machine Stack Storage
|
||||
|
||||
STKSLO EQU $07FC ;Stack Start LSB
|
||||
STKSHI EQU $07FD ;Stack Start MSB
|
||||
STKELO EQU $07FE ;Stack End LSB
|
||||
STKEHI EQU $07FF ;Stack End MSB
|
||||
|
||||
;Machine Language Basic Stub - Same as Commodore 64
|
||||
ORG $0801 ;Start of Basic Program
|
||||
BASIC: DC $0C, $08 ;Pointer to Next Line
|
||||
DC $00, $00 ;Line Number (0)
|
||||
DC $9E ;SYS
|
||||
DC $20 ;' '
|
||||
DC $32, $30, $36 ,$32 ;"2062"
|
||||
DC $00 ;End of Line Marker
|
||||
DC $00, $00 ;End of Basic Program
|
||||
|
||||
START: TSX ;Get Stack Pointer
|
||||
STX STKSAV ;and Save for Exit
|
||||
SEC ;Set Screen Mode
|
||||
LDA #0 ;to 40x30 Text
|
||||
JSR $FF5F ;using SCRMOD
|
||||
JMP MAIN ;Execute Program
|
||||
|
||||
EXIT: LDX STKSAV ;Retrieve Saved Stack Pointer
|
||||
TXS ;and Restore It
|
||||
RTS ;Return to BASIC
|
||||
|
||||
;Poll Keyboard for Character
|
||||
POLKEY EQU $FFE4 ;Aliased to Kernal GETIN Routine
|
||||
|
||||
;Get Character from Keyboard
|
||||
GETKEY EQU POLKEY ;Aliased to POLKEY Routine
|
||||
|
||||
;Wait for Character from Keyboard
|
||||
GETCHR: JSR GETKEY ;Poll Keyboard
|
||||
BEQ GETCHR ;If No Key, Loop
|
||||
RTS
|
||||
|
||||
;Print Character to Console
|
||||
PUTCHR EQU $FFD2 ;Aliased to CHROUT Routine
|
||||
|
||||
;Delete Previous Character
|
||||
DELCHR: LDA #DELKEY ;Load Delete Character
|
||||
JMP PUTCHR ;Print and Return
|
||||
|
||||
;Advance Character to Next line
|
||||
NEWLIN: LDA #RTNKEY ;Load Return Character
|
||||
JMP PUTCHR ;Print and Return
|
||||
|
||||
INCLUDE "../include/prbyte.a02" ;PRBYTE and PRHEX routine
|
||||
INCLUDE "../include/putstr.a02" ;PUTSTR routine
|
45
include/x16.h02
Normal file
45
include/x16.h02
Normal file
@ -0,0 +1,45 @@
|
||||
/* C02 System Header file for Commander X16 */
|
||||
|
||||
/* Platform Specific Settings */
|
||||
#pragma zeropage $68 //Unused Zero Page - $68-$7F
|
||||
|
||||
/* Platform Specific Constants */
|
||||
#define DELKEY $14 //Delete/Backspace Key (DEL)
|
||||
#define ESCKEY $03 //Escape/Break Key (STOP)
|
||||
#define RTNKEY $0D //Return/Enter Key (RETURN)
|
||||
|
||||
/* Standard Library Pointers */
|
||||
zeropage char srclo,srchi; //Source Pointer for Library Functions
|
||||
zeropage char dstlo,dsthi; //String Pointer for Library Functions
|
||||
zeropage int srcptr,dstptr; //Source, Destination Pointers
|
||||
zeropage char bfrlo,bfrhi; //Buffer Pointer for Library Functions
|
||||
zeropage char blklo,blkhi; //Block Segment Pointer
|
||||
zeropage char stklo,stkhi; //Stack Pointer
|
||||
zeropage char xadrlo,xadrhi; //Physical Address LSB, MSB
|
||||
|
||||
/* Standard Library Variables */
|
||||
char blkslo,blkshi; //Block Start Address
|
||||
char blkelo,blkehi; //Block End Address
|
||||
char blklen; //Block Segment Length
|
||||
char stkslo,stkshi; //Stack Start Address
|
||||
char stkelo,stkehi; //Stsck End Address
|
||||
char random,rdseed; //Pseudo-Random Number Generation
|
||||
char temp0,temp1,temp2,temp3; //Temporary Storage
|
||||
char xmbank; //Physical Bank
|
||||
|
||||
/* System Subroutines */
|
||||
void delchr(); //Delete previous character
|
||||
char getkey(); //Read ASCII character from Keyboard
|
||||
char getpos(); //Get Cursor Position
|
||||
char getsiz(); //Get Screen Size
|
||||
void newlin(); //Advance cursor to beginning of next line
|
||||
char polkey(); //Poll Keyboard for character
|
||||
char putchr(); //Print ASCII character to Keyboard
|
||||
void prbyte(); //Print Accumulator as Hexadadecimal number
|
||||
void prhex(); //Print Low Nybble of Accumulator as Hex Digit
|
||||
char getchr(); //Wait for character from Keyboard
|
||||
void setpos(); //Set Cursor Position
|
||||
|
||||
//System Labels
|
||||
start: //Start of Code
|
||||
exit: //Return to Operating System
|
33
include/x16/joystk.a02
Normal file
33
include/x16/joystk.a02
Normal file
@ -0,0 +1,33 @@
|
||||
;Joystick Constants and Functions
|
||||
;Non-Functional Skeleton for Systems with No Joystick Support
|
||||
|
||||
JYSTKS EQU 2 ;Number of Joysticks
|
||||
|
||||
JYDATA EQU $02BC ;Joystick 0 Data
|
||||
|
||||
GETJOY EQU $FF06 ;Kernal GETJOY Routine
|
||||
|
||||
;Joystick Bit Masks
|
||||
JOYUP EQU $08 ;Up
|
||||
JOYDN EQU $04 ;Down
|
||||
JOYLF EQU $02 ;Left
|
||||
JOYRT EQU $01 ;Right
|
||||
JOYB0 EQU $80 ;Button
|
||||
|
||||
;Read Joystick
|
||||
JOYSTK: CMP #JYSTKS ;If Invalid Joystick Number
|
||||
BCS JOYSTE ; Return ERROR
|
||||
STA TEMP0 ;Save Joystick Number
|
||||
JSR $FF06 ;Call Kernal GETJOY Routine
|
||||
LDA TEMP0 ;Retrieve Joystick Number
|
||||
ASL ;Multiply it by 3
|
||||
ADC TEMP0 ;(Assumes Number<128)
|
||||
TAX ;and Copy to X-Register
|
||||
LDA $02BE,X ;If Controller Not Present
|
||||
BNE JOYSTE ; Return ERROR
|
||||
LDA $02BC,X ;Read Controller Status
|
||||
;EOR #$FF ;Invert Bits
|
||||
AND #$CF ;and Mask off Select/Start
|
||||
RTS
|
||||
JOYSTE: LDA #255 ;Return Error Code
|
||||
RTS
|
24
include/x16/joystk.h02
Normal file
24
include/x16/joystk.h02
Normal file
@ -0,0 +1,24 @@
|
||||
/* Joystick Functions for *
|
||||
* Commander X-16 Computer */
|
||||
|
||||
#define JYSTKS 2 //Number of Joysticks
|
||||
|
||||
#define JOYUP $08 //Up
|
||||
#define JOYDN $04 //Down
|
||||
#define JOYLF $02 //Left
|
||||
#define JOYRT $01 //Right
|
||||
#define JOYB0 $80 //Button
|
||||
|
||||
char jydata[]; //Joystick Data
|
||||
|
||||
/* Poll Joysticks` *
|
||||
* Sets: j = Joystick Number *
|
||||
* Returns: $FF = Error *
|
||||
* No Joysticks */
|
||||
void getjoy();
|
||||
|
||||
/* Read Joystick State *
|
||||
* Args: j = Joystick Number *
|
||||
* Returns: $FF = Error *
|
||||
* No Joysticks */
|
||||
char joystk();
|
360
include/x16/xmemory.a02
Normal file
360
include/x16/xmemory.a02
Normal file
@ -0,0 +1,360 @@
|
||||
; Commander X16 Extended Memory Assembly Langyage Routines for C02
|
||||
|
||||
;Extended Memory Constants
|
||||
XLBANK EQU $0F ;Maximum Logical Bank
|
||||
|
||||
;Extended Memory Address - Defined in x16.a02
|
||||
; Physical Address Logical Address
|
||||
;XMBANK Bank ($00-$FF) Bits 20-13
|
||||
;XADRLO Address LSB ($00-$FF) Bits 7- 0
|
||||
;XADRHI Address MSB ($A0-$BF) Bits 12- 8
|
||||
|
||||
;VIA Registers
|
||||
XSBANK EQU $9F61 ;RAM Bank Select
|
||||
|
||||
;xgetla() - Get Logical Extended Memory Address
|
||||
;Destroys: TEMP0
|
||||
;Returns: A = Logical Bank ($0-$F$)
|
||||
; $FF if Physical Address Invalid
|
||||
; Y,X = Logical Address ($0000-$FFFF)
|
||||
; Carry Set if Physical Address is Invalid
|
||||
XGETLA: JSR XGETPN
|
||||
|
||||
;xclcla(bank,page,byte) - Convert Physical to Logical Address
|
||||
;Args: A = Physical Bank ($00,$FF)
|
||||
; Y,X = Physical Address ($A000-$BFFF)
|
||||
;Destroys: TEMP0
|
||||
;Returns: A = Logical Bank ($00-$0F)
|
||||
; Y,X = Logical Address ($0000-$000F)
|
||||
; Carry Set if Physical Address is Invalid
|
||||
XCLCLA: STA TEMP0 ;Save Physical Bank
|
||||
TYA ;Get Physical MSB
|
||||
AND #$E0 ;Isolate Bits 5-7
|
||||
CMP #$A0 ;If Not in Banked RAM Area
|
||||
BNE XRCSET ; Return Carry Set
|
||||
TYA ;Get Physical MSB
|
||||
ASL ;Rotate Bits 8-12 to 11-15
|
||||
ASL
|
||||
ASL
|
||||
LSR TEMP0 ;Rotate Physical Bank
|
||||
ROR ;into Logical Bits 13-20
|
||||
LSR TEMP0
|
||||
ROR
|
||||
LSR TEMP0
|
||||
ROR
|
||||
TAY ;Copy MSB into Y
|
||||
LDA TEMP0 ;Load Bank into A
|
||||
CLC ;Return Carry Clear
|
||||
RTS
|
||||
|
||||
XRCSET: SEC ;Return Carry Set
|
||||
RTS
|
||||
|
||||
;xclcpa(bank,page,byte) - Convert Logical to Physical Address
|
||||
;Args: A = Logical Bank ($00-$0F)
|
||||
; Y,X = Logical Address ($0000-$000F)
|
||||
;Destroys: TEMP0
|
||||
;Returns: A = Physical Bank ($00,$FF)
|
||||
; Y,X = Physical Address ($A000-$BFFF)
|
||||
; Carry Set if Logical Address is Invalid
|
||||
XCLCPA: CMP #$10 ;If Bank >= 16
|
||||
BCS XLPADX ; Return Carry Set
|
||||
STA TEMP0 ;Store Logical Bank,LSB,MSB in TEMP0,TEMP1,TEMP2
|
||||
TYA ;Get Logical Address MSB
|
||||
ASL ;Rotate Logical Bits 13-20 into Physical Bank
|
||||
ROL TEMP0
|
||||
ASL
|
||||
ROL TEMP0
|
||||
ASL
|
||||
ROL TEMP0
|
||||
LSR ;Shift Bits 8-12 back into Position
|
||||
LSR
|
||||
LSR
|
||||
ORA #$A0 ;Convert to Physical MSB
|
||||
TAY ;and Copy Back to Y
|
||||
LDA TEMP0 ;Load Physical Bank into Accumulator
|
||||
XLPADX: RTS
|
||||
|
||||
;xsetla(bank,page,byte) - Set Logical Extended Memory Address
|
||||
;Args: A = Logical Bank ($0-$F$)
|
||||
; Y,X = Logical Address ($0000-$FFFF)
|
||||
;Destroys: TEMP0
|
||||
;Returns: A = Physical Bank ($00-$FF)
|
||||
; Y,X = Physical Address ($A000-$BFFF)
|
||||
XSETLA: JSR XCLCPA ;Convert Logical Address to Physical Address
|
||||
BCC XSETPN ;If Valid, Store and Return
|
||||
RTS ;Else Return Carry Set
|
||||
|
||||
;xsetpa(bank,page,byte) - Set Physical Extended Memory Address
|
||||
;Args: A = Physical Bank ($00-$FF)
|
||||
; Y,X = Physical Address ($A000-$BFFF)
|
||||
;Destroys: TEMP0
|
||||
;Returns: A = Physical Bank ($FF if Address Invalid)
|
||||
; Y,X = Physical Address
|
||||
; Carry Set if Logical Address is Invalid
|
||||
XSETPA: JSR XVALPA ;Validate Physical Address
|
||||
BCS XSETPX ;If Invalid, Return Carry Set
|
||||
|
||||
;XSETPn(bank,page,byte) - Set Physical Address without Error Checking
|
||||
;Args: A,Y,X = Physical Extended Address
|
||||
XSETPN: STA XMBANK ;Store Physical Bank
|
||||
STY XADRHI ;Store Physical MSB
|
||||
STX XADRLO ;Store Physical LSB
|
||||
XSETPX: RTS
|
||||
|
||||
;XGETPA() - Get Physical Extended Memory Address
|
||||
;Returns: A = Physical Bank ($FF if Address Invalid)
|
||||
; Y,X = Physical Address
|
||||
XGETPA: LDA XADRHI ;Load Physical MSB
|
||||
AND #$E0 ;Isolate Bits 5-7
|
||||
CMP #$A0 ;If Not in Banked RAM Area
|
||||
BNE XRCSET ; Return Carry Set
|
||||
|
||||
;xgetpn() - Get Physical Address without Error Checking
|
||||
;Returns: A,Y,X = Physical Extended Address
|
||||
XGETPN: LDA XMBANK ;Load Physical Bank
|
||||
LDY XADRHI ;Load Physical MSB
|
||||
LDX XADRLO ;Load Physical LSB
|
||||
RTS
|
||||
|
||||
;xvalpa(bank,page,byte) - Validate Physical Extended Address
|
||||
;Args: A = Physical Bank ($00-$FF)
|
||||
; Y,X = Physical Address ($A000-$BFFF)
|
||||
;Returns: Carry Set if Logical Address is Invalid
|
||||
XVALPA: CPY #$A0 ;If MSB<$A0
|
||||
BCC XRCSET ; Return Carry Set
|
||||
CPY #$C0 ;Return Carry Set if MSB>=$C0
|
||||
RTS
|
||||
|
||||
;xselrb() - Select Extended RAM Bank
|
||||
;Sets: XSBANK to XMBANK
|
||||
;Returns: Y = 0
|
||||
XSELRB: LDY XMBANK ;Get Physical Bank
|
||||
STY XSBANK ;and Select RAM Bank
|
||||
LDY #0
|
||||
RTS
|
||||
|
||||
;xgetl() - Read Long from Extended Memory
|
||||
;Updates: XMBANK, XADRHI, XADRLO - Physical Address
|
||||
;Returns: A,Y,X = Bytes Read
|
||||
; Carry Set if Address Rolled Over
|
||||
XGETL: JSR XGETI ;Read X,Y from Extended Memory
|
||||
BRA XGETC ;Read A from Extended Memory
|
||||
|
||||
;xgeti() - Read Word from Extended Memory
|
||||
;Updates: XMBANK, XADRHI, XADRLO - Physical Address
|
||||
;Affects: A
|
||||
;Returns: Y,X = Word Read
|
||||
; Carry Set if Address Rolled Over
|
||||
XGETI: JSR XGETC ;Read LSB from Extended Memory
|
||||
TAX ;and Return in X
|
||||
JSR XGETC ;Read MSB from Extended Memory
|
||||
TAY ;and Return in Y
|
||||
RTS
|
||||
|
||||
;xgetc() - Read Byte from Extended Memory
|
||||
;Updates: XMBANK, XADRHI, XADRLO - Physical Address
|
||||
;Affects: Y
|
||||
;Returns: A = Byte Read
|
||||
; Carry Set if Address Rolled Over
|
||||
XGETC: JSR XSELRB ;Select Extended RAM Bank
|
||||
LDA (XADRLO),Y ;Load Character at Extended Address
|
||||
TAY ;Save Character
|
||||
JSR XINCPA ;Increment Physical Address
|
||||
TYA ;Restore Character
|
||||
RTS
|
||||
|
||||
;xload(size) - Load from Extended Memory
|
||||
;Args: Y,X = Number of Bytes to Load
|
||||
;Requires: DSTLO,DSTHI = Local Memory Start Address
|
||||
; XMBANK,XADRHI,XADRLO = Extended Memory Address
|
||||
;Destroys: TEMP0
|
||||
;Affects: A,X,Y
|
||||
XLOAD: STY TEMP0 ;and Store in TEMP0
|
||||
JSR XSELRB ;Select Extended RAM Bank
|
||||
XLOADL: JSR XREADL ;Read Count LSB Bytes
|
||||
LDA TEMP0 ;Load MSB
|
||||
BEQ XLOADX ;If Not Zero
|
||||
DEC TEMP0 ; Decrement MSB
|
||||
BRA XLOADL ; and Read Another 256 Bytes
|
||||
XLOADX: RTS
|
||||
|
||||
;xread(n,&dest) - Read Bytes from Extended Memory
|
||||
;Args: A = Number of Bytes to Read
|
||||
; Y,X = Address of Array to Read Into
|
||||
;Sets: DSTLO,DSTHI
|
||||
;Updates: XMBANK, XADRHI, XADRLO - Physical Address
|
||||
;Affects: A,X,Y
|
||||
XREAD: JSR SETDST ;Set Destination to String
|
||||
TAX ;Copy Byte Count to X
|
||||
JSR XSELRB ;Select Extended RAM Bank
|
||||
XREADL: LDA (XADRLO) ;Get Character at Extended Address
|
||||
STA (DSTLO) ;Write to Array
|
||||
INC DSTLO ;Increment Destination Address
|
||||
BNE XREADS
|
||||
INC DSTHI
|
||||
XREADS: JSR XINCPA ;Increment Physical Address
|
||||
DEX ;Increment Counter
|
||||
BNE XREADL ;and Loop if Not Zero
|
||||
RTS
|
||||
|
||||
;xsave(size) - Save from Extended Memory
|
||||
;Args: Y,X = Number of Bytes to Save
|
||||
;Requires: SRCLO,SRCHI = Local Memory Start Address
|
||||
; XMBANK,XADRHI,XADRLO = Extended Memory Address
|
||||
;Destroys: TEMP0
|
||||
;Affects: A,X,Y
|
||||
XSAVE: STY TEMP0 ;and Store in TEMP0
|
||||
JSR XSELRB ;Select Extended RAM Bank
|
||||
XSAVEL: JSR XWRITL ;Write Count LSB Bytes
|
||||
LDA TEMP0 ;Load MSB
|
||||
BEQ XSAVEX ;If Not Zero
|
||||
DEC TEMP0 ; Decrement MSB
|
||||
BRA XSAVEL ; and Write Another 256 Bytes
|
||||
XSAVEX: RTS
|
||||
|
||||
;xwrite(n,&source) - Write Bytes to Extended Memory
|
||||
;Args: A = Number of Bytes to Write
|
||||
; Y,X = Address of Array to Write From
|
||||
;Sets: SRCLO,SRCHI
|
||||
;Updates: XMBANK, XADRHI, XADRLO - Physical Address
|
||||
;Affects: A,X,Y
|
||||
XWRITE: JSR SETSRC ;Set Destination to String
|
||||
TAX ;Copy Byte Count to X
|
||||
JSR XSELRB ;Select Extended RAM Bank
|
||||
XWRITL: LDA (SRCLO)
|
||||
STA (XADRLO) ;Get Character at Extended Address
|
||||
INC SRCLO ;Increment Destination Address
|
||||
BNE XWRITS
|
||||
INC SRCHI
|
||||
XWRITS: JSR XINCPA ;Increment Physical Address
|
||||
DEX ;Increment Counter
|
||||
BNE XWRITL ;and Loop if Not Zero
|
||||
RTS
|
||||
|
||||
;xswap(size) - Swap with Extended Memory
|
||||
;Args: Y,X = Number of Bytes to Swap
|
||||
;Requires: DSTLO,DSTHI = Local Memory Start Address
|
||||
; XMBANK,XADRHI,XADRLO = Extended Memory Address
|
||||
;Destroys: TEMP0
|
||||
;Affects: A,X,Y
|
||||
XSWAP: STY TEMP0 ;and Store in TEMP0
|
||||
JSR XSELRB ;Select Extended RAM Bank
|
||||
XSWAPL: JSR XCHNGL ;Write Count LSB Bytes
|
||||
LDA TEMP0 ;Load MSB
|
||||
BEQ XSWAPX ;If Not Zero
|
||||
DEC TEMP0 ; Decrement MSB
|
||||
BRA XSWAPL ; and Write Another 256 Bytes
|
||||
XSWAPX: RTS
|
||||
|
||||
;xchng(n,&dest) - Exhange with Bytes in Extended Memory
|
||||
;Args: A = Number of Bytes to Read
|
||||
; Y,X = Address of Array to Read Into
|
||||
;Sets: DSTLO,DSTHI
|
||||
;Updates: XMBANK, XADRHI, XADRLO - Physical Address
|
||||
;Affects: A,X,Y
|
||||
XCHNG: JSR SETDST ;Set Destination to String
|
||||
TAX ;Copy Byte Count to X
|
||||
JSR XSELRB ;Select Extended RAM Bank
|
||||
XCHNGL: LDA (XADRLO) ;Get Character at Extended Address
|
||||
TAY ;and Save It
|
||||
LDA (DSTLO) ;Get Character from Array
|
||||
STA (XADRLO) ;and Store at Extended Address
|
||||
TYA ;Retrieve Original Character
|
||||
STA (DSTLO) ;and Store in Array
|
||||
INC DSTLO ;Increment Destination Address
|
||||
BNE XCHNGS
|
||||
INC DSTHI
|
||||
XCHNGS: JSR XINCPA ;Increment Physical Address
|
||||
DEX ;Increment Counter
|
||||
BNE XCHNGL ;and Loop if Not Zero
|
||||
RTS
|
||||
|
||||
;xputl(nsb,msb,lsb) - Write Long to Extended Memory
|
||||
;Args: A,Y,X = Long to Write
|
||||
;Updates: XMBANK, XADRHI, XADRLO - Physical Address
|
||||
;Affects: Y
|
||||
;Returns: Carry Set if Address Rolled Over
|
||||
XPUTL: PHA ;Save NSB
|
||||
JSR XPUTI ;Write LSB, MSB to Extended Memory
|
||||
PLA ;Retrieve NSB
|
||||
BRA XPUTCN ;and Write to Extended Memory
|
||||
|
||||
;xputi(i) - Write Word to Extended Memory
|
||||
;Args: Y,X = Word to Write
|
||||
;Updates: XMBANK, XADRHI, XADRLO - Physical Address
|
||||
;Affects: A,Y
|
||||
;Returns: Carry Set if Address Rolled Over
|
||||
XPUTI: PHY ;Save MSB
|
||||
TXA ;Get LSB
|
||||
JSR XPUTC ;and Write to Extended Memory
|
||||
PLA ;Retrieve MSB
|
||||
BRA XPUTCN ;and Write to Extended Memory
|
||||
|
||||
;xputc(c) - Write Byte to Extended Memory
|
||||
;Args: A = Integer to Write
|
||||
;Updates: XMBANK, XADRHI, XADRLO - Physical Address
|
||||
;Affects: A,Y
|
||||
;Returns: Carry Set if Address Rolled Over
|
||||
XPUTC: JSR XSELRB ;Select Extended RAM Bank
|
||||
XPUTCN: STA (XADRLO) ;Store Character at Extended Address
|
||||
|
||||
;xincpa() - Increment Physical Extended Address
|
||||
;Updates: XMBANK, XADRHI, XADRLO - Physical Address
|
||||
;Affects: A
|
||||
;Returns: Carry Set if Address Rolled Over
|
||||
XINCPA: CLC ;Preset Carry to Clear
|
||||
INC XADRLO ;Increment Physical LSB
|
||||
BNE XINCPX ;If Zero
|
||||
INC XADRHI ; Increment Physical MSB
|
||||
LDA XADRHI ; Load Physical MSB
|
||||
CMP #$C0 ; If More than Maximum
|
||||
BCC XINCPX
|
||||
LDA #$A0 ; Set MSB to Minimum
|
||||
STA XADRHI
|
||||
INC XMBANK ; Increment Bank
|
||||
LDA XMBANK ; and Write to Bank Select
|
||||
STA XSBANK
|
||||
BNE XINCPX ; If Not Zero
|
||||
CLC ; Return Carry Clear
|
||||
XINCPX: RTS
|
||||
|
||||
;xrdpg(xbank, xpage, mpage) - Read Extended Memory Page
|
||||
XRDPG: STX DSTHI ;Set Destination MSB to Memory Page
|
||||
LDX #0 ;Set Extended Memory LSB to 0
|
||||
STX DSTLO ;Set Destination LSB to 0
|
||||
JSR XCLCPA ;Convert Logical to Physical Address
|
||||
BCS XRDPGX ;If Invalid, Return Carry Set
|
||||
JSR SETSRC ;Set Source Address, Y to 0
|
||||
XRDPGM: STA XSBANK ;Select Extended RAM Bank
|
||||
XRDPGL: LDA (SRCLO),Y ;Read Byte from Extended Memory
|
||||
STA (DSTLO),Y ;and Write to Local Memory
|
||||
INY ;Increment Counter
|
||||
BNE XRDPGL ;and Loop if Not 0
|
||||
XRDPGX: RTS
|
||||
|
||||
;xwrtpg(xbank, xpage, mpage) - Write Extended Memory Page
|
||||
XWRTPG: JSR XSRCPA ;Set Source Address and Physical Address
|
||||
BEQ XRDPGM ;and Copy Bytes
|
||||
|
||||
XSRCPA: STX SRCHI ;Set Destination MSB to Memory Page
|
||||
LDX #0 ;Set Extended Memory LSB to 0
|
||||
STX SRCLO ;Set Destination LSB to 0
|
||||
JSR XCLCPA ;Convert Logical to Physical Address
|
||||
BCS XRDPGX ;If Invalid, Return Carry Set
|
||||
JSR SETDST ;Set Destination to Extended Address
|
||||
LDY #0 ;Set Counter to 0
|
||||
BEQ XRDPGM ;and Copy Bytes
|
||||
|
||||
;xswppg(xbank, xpage, mpage) - Swap with Extended Memory Page
|
||||
XSWPPG: JSR XSRCPA ;Set Source Address and Physical Address
|
||||
STA XSBANK ;Select Extended RAM Bank
|
||||
XSWPPL: LDA (DSTLO),Y ;Read From Local Memory
|
||||
TAX ;and Save Contents
|
||||
LDA (SRCLO),Y ;Read Byte from Extended Memory
|
||||
STA (DSTLO),Y ;and Write to Local Memory
|
||||
TXA ;Retrieve Byte Read from Local Memory
|
||||
LDA (SRCLO),Y ;and Write to Extended Memory
|
||||
INY ;Increment Counter
|
||||
BNE XSWPPL ;and Loop if Not 0
|
||||
RTS
|
115
include/x16/xmemory.h02
Normal file
115
include/x16/xmemory.h02
Normal file
@ -0,0 +1,115 @@
|
||||
/****************************************
|
||||
* xmemory.h02 - Extended Memory Access *
|
||||
* for Commander X16 *
|
||||
****************************************/
|
||||
|
||||
#define XLBANK $0F //Maximum Logical Bank
|
||||
|
||||
/* Read Byte to Extended Memory *
|
||||
* Returns: char b: Byte Read *
|
||||
* Sets Carry if Address Rolled Over */
|
||||
char xgetc();
|
||||
|
||||
/* Read Word to Extended Memory *
|
||||
* Returns: int i: Word Read *
|
||||
* Sets Carry if Address Rolled Over */
|
||||
int xgeti();
|
||||
|
||||
/* Read Word, Byte to Extended Memory *
|
||||
* Args: char b: Byte Read *
|
||||
* int i: Word Read *
|
||||
* Sets Carry if Address Rolled Over */
|
||||
char xgetl();
|
||||
|
||||
/* Get Logical Extended Address *
|
||||
* Returns: char lbank - Logical Bank *
|
||||
* int laddr - Logical Address *
|
||||
* Sets Carry if Physical Address Invalid */
|
||||
char xgetla();
|
||||
|
||||
/* Get Physical Extended Address *
|
||||
* Returns: char pbank - Physical Bank *
|
||||
* char ppage - Physical Page *
|
||||
* char pbyte - Physical Byte *
|
||||
* Sets Carry if Physical Address Invalid */
|
||||
char xgetpa();
|
||||
|
||||
/* Convert Physical to Logical Address *
|
||||
* Args: char pbank - Physical Bank *
|
||||
* char ppage - Physical Page *
|
||||
* char pbyte - Physical Byte *
|
||||
* Returns: char lbank - Logical Bank *
|
||||
* int laddr - Logical Address *
|
||||
* Sets Carry if Physical Address Invalid */
|
||||
char xclcla();
|
||||
|
||||
/* Increment Physical Address *
|
||||
* Sets Carry if Address Rolled Over */
|
||||
void xincpa();
|
||||
|
||||
/* Convert Logical to Physical Address *
|
||||
* Args: char lbank - Logical Bank *
|
||||
* int laddr - Logical Address *
|
||||
* Returns: char pbank - Physical Bank *
|
||||
* char ppage - Physical Page *
|
||||
* char pbyte - Physical Byte *
|
||||
* Sets Carry if Logical Address Invalid */
|
||||
char xclcpa();
|
||||
|
||||
/* Write Byte to Extended Memory *
|
||||
* Args: char b: Byte to Write *
|
||||
* Sets Carry if Address Rolled Over */
|
||||
void xputc();
|
||||
|
||||
/* Write Word to Extended Memory *
|
||||
* Args: int i: Word to Write *
|
||||
* Sets Carry if Address Rolled Over */
|
||||
void xputi();
|
||||
|
||||
/* Write Word, Byte to Extended Memory *
|
||||
* Args: char b: Byte to Write *
|
||||
* int i: Word to Write *
|
||||
* Sets Carry if Address Rolled Over */
|
||||
void xputl();
|
||||
|
||||
/* Read Extended Memory Page *
|
||||
* Args: char lbank - Logical Bank *
|
||||
* char lpage - Logical Page *
|
||||
* char mpage - Memory Page *
|
||||
* Sets Carry if Logical Bank Invalid */
|
||||
void xrdpg();
|
||||
|
||||
/* Set Logical Extended Address *
|
||||
* Args: char lbank - Logical Bank *
|
||||
* int laddr - Logical Address *
|
||||
* Sets Carry if Logical Address Invalid */
|
||||
void xsetla();
|
||||
|
||||
/* Set Physical Extended Address *
|
||||
* without Error Checking *
|
||||
* Args: char pbank - Physical Bank *
|
||||
* char ppage - Physical Page *
|
||||
* char pbyte - Physical Byte */
|
||||
void xsetpn();
|
||||
|
||||
/* Set Physical Extended Address *
|
||||
* with Error Checking *
|
||||
* Args: char pbank - Physical Bank *
|
||||
* char ppage - Physical Page *
|
||||
* char pbyte - Physical Byte *
|
||||
* Sets Carry if Physical Address Invalid */
|
||||
void xsetpa();
|
||||
|
||||
/* Validate Physical Extended Address *
|
||||
* Args: char pbank - Physical Bank *
|
||||
* char ppage - Physical Page *
|
||||
* char pbyte - Physical Byte *
|
||||
* Sets Carry if Physical Address Invalid */
|
||||
void xvalpa();
|
||||
|
||||
/* Write Extended Memory Page *
|
||||
* Args: char lbank - Logical Bank *
|
||||
* char lpage - Logical Page *
|
||||
* char mpage - Memory Page *
|
||||
* Sets Carry if Logical Bank Invalid */
|
||||
void xwrtpg();
|
Loading…
Reference in New Issue
Block a user