1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-24 15:31:17 +00:00

Documented module xmemory and created template include files

This commit is contained in:
Curtis F Kaylor 2020-10-23 18:13:59 -04:00
parent 7ed5a51ae2
commit 3b570f248c
3 changed files with 377 additions and 0 deletions

119
doc/xmemory.txt Normal file
View File

@ -0,0 +1,119 @@
Template Functions for C02 Programs
This module provides functions to read from and write to extended
memory.
Extended memory is RAM that is not directly addressable by the 6502.
Read and write operations use a 24-bit logical address, which is
comprised of an 8-bit bank and 16-bit offset and automatically updated
after each operation.
At the beginning of the program use the directives
#include <stddef.h02>
#include <xmemory.h02>
The following functions are defined:
b,d = xgetad(); Returns the current logical extended bank b
and offset d.
Note: the physical address stored in XMBANK
and XMADDR is converted to a logical bank and
offset, which are returned.
xsetad(b,d); Sets the current logical extended bank to b
and offset to d.
This extended address is used for all read and
write functions except for the page operations.
Note: the logical address is converted to a
physical address stored in XMBANK and XMADDR.
c = xgetc(); Reads a byte from the current extended address,
increments the address, and returns the byte
as c.
xputc(c); Writes byte c to the current extended address,
then increments the address.
w = xgeti(); Reads a word starting at the current extended
address, adds 2 to the address, and returns the
word as w.
xputi(w); Writes word w at the current extended address,
then adds 2 to the address.
c,w = xgetl(); Reads a long starting at the current extended
address, adds 3 to the address, and returns the
high byte of the long in c and the low word in w.
xputl(c,w); Writes the long consisting of the byte c and
word w at the current extended address, then
adds 3 to the address.
xread(n,r); Reads n bytes starting at the current extended
address into array r, then adds n to the address.
xwrite(n,r); Writes n bytes of array r starting at the current
extended address, then adds n to the address.
xswap(n,r); Swaps n bytes of array r with n bytes starting at
the current extended address, then adds n to the
address.
xload(w); Reads word w bytes into local memory starting at
the address specified by a call to setdst() from
extended memory starting at the current extended
address, then adds w to the address.
xsave(w); Writes word w bytes from local memory starting at
the address specified by a call to setsrc() into
extended memory starting at the current extended
address, then adds w to the address.
xchng(w); Swaps word w bytes in local memory starting at
the address specified by a call to setdst() with
extended memory starting at the current extended
address, then adds w to the address.
xsetpg(b,p) Sets the current extended address to bank b and
offset p * 256. This ensures that the address is
on a page boundary for subsequent page read and
write operations.
Note: The page operation are the fastest of the
block read and write functions since the code
can use indirect addressing.
xrpage(n,p); Copies n 256 byte pages starting at the current
extended bank and page to local memory starting
at address p * 256, then updates the extended
address accordingly.
xwpage(n,p); Copies n 256 bytes from local memory starting
at address p * 256 to extended memory starting at
current bank and page, then updates the extended
address accordingly.
xspage(n,p); Swaps n 256 bytes from local memory starting at
address p * 256 with extended memory starting at
current bank and page, then updates the extended
address accordingly.
Note: This library expects the following functions to be defined:
ext(); External function description
along with the zero page variables
zpage0,zpage1: Zero page variable pair
the external variables
exvar0,exvar1: External variable pair
and the constants
#CNSTNAME Constant description

153
include/xmemory.a02 Normal file
View File

@ -0,0 +1,153 @@
;Extended Memory Assembly Language Routines Non-Functional Template
;Requires locations XMBANK and XMADDR (header.a02)
SUBROUTINE XMEMORY
;Extended Memory Constants\
XLBANK EQU $00 ;Maximum Logical Bank - 0 = Not Implemented
;Extended Memory Physical Address Registers - Defined in header.a02
;XMBANK Bank These contain the physical bank and address of extended memory,
;XMADDR Address which are usually different than the logical bank and address.
;Bank Selected Memory
;This interface is used by nearly every 6502 based 8-bit computer
;The extended memory is exposed as a 1K, 8K, or 16K section of the
;6502's address space. An I/O register is used to to map equally
;sized banks of the extended memory into this section of RAM.
;XMBANK is the bank number and XMADDR is the offset in the bank.
;Bank Physical Address Max Ext
;Size XMBANK XMADDR Logical Address RAM
; 1K BBBBBBBB 000000AA AAAAAAAA 000000BB BBBBBBAA AAAAAAAA 256K
; 8K BBBBBBBB 00000AAA AAAAAAAA 00000BBB BBBBBAAA AAAAAAAA 512K
; 16K BBBBBBBB 0000AAAA AAAAAAAA 0000BBBB BBBBAAAA AAAAAAAA 1024K
;Ultimem for the VIC-20 uses a two-byte bank number and 8K banks
;giving a 27-bit wide address, but this module is limited to 24 bits.
; Physical Address Max Ext
; XMBANK XMADDR Logical Address RAM
;000BBBBB BBBBBBBB 00000AAA AAAAAAAA BBBBBBBB BBBBBAAA AAAAAAAA 16MB
;Page Selected Memory
;The interface is used by GeoRAM for the Commodore 64 and 128
;The extended memory is exposed as a single page (256 bytes) of the
;6502's address space. I/O registers are used to select a bank of
;up to 64K of extended memory and to map a page of that bank to
;the page of RAM. GeoRAM uses 16K banks.
;XMBANK is the bank number, the high byte of XMADDR is the page of
;the bank, and the low byte of XMADDR is the offset in the page.
;Bank XMBANK XMADDR Max Ext
;Size Bank Page Offset Logical Address RAM
; 16K BBBBBBBB 0000PPPP AAAAAAAA 0000BBBB BBBBPPPP AAAAAAAA 1MB
; 64K BBBBBBBB PPPPPPPP AAAAAAAA BBBBBBBB PPPPPPPP AAAAAAAA 16MB
;DMA Controller`
;This interface is used by the Commodore REUs and the run6502 emulator.
;The expansion device suspends operation of the 6502 and directly
;reads and writes to the system RAM. I/O registers are used to select
;an operation (read, write, or swap), a 24-bit extended memory address,
;a 16-bit system RAM address, and 16-bit byte count.
;XMBANK and XMADDR contain the 24-bit extended memory address which is
;identical to the logical address, for up to 16MB of extended memory.
;xgetad() - Get Logical Extended Memory Address
; For run6502, this is the same as the Physical Address
;Returns: A = Logical Bank ($00-$0F)
; YX = Logical Address ($0000-$FFFF)
XGETAD: LDA #$FF ;Return $FF,$FFFFF which would
TAY ;indicate 16MB of extended memory,
TAX ;which is rare on 8-bit machines
RTS
;xsetad() - Set Logical Extended Memory Address
; For run6502, this is the same as the Physical Address
;Args: A = Logical Bank ($00-$0F)
; YX = Logical Address ($0000-$FFFF)
;Returns: A=$00 - Success or $FF - Failure
XSETAD: LDA #$FF ;Return Failure
;xputc() - Write Byte to Extended Memory
;Args: A = Byte
;Affects: A,X
XPUTC: RTS
;xgetc() - Read Byte from Extended Memory
;Returns: A = Byte
XGETC: LDA #0 ;Return 0
RTS
;xputi() - Write Word to Extended Memory
;Args: YX = Word
XPUTI: RTS
;xgeti() - Read Word from Extended Memory
;Returns: YX = Word
XGETI: LDY #0 ;Return Zero
LDX #0
RTS
;xgetl() - Read Long from Extended Memory
;Args: AYX = Long
XGETL: LDA #0 ;Return Zero
;xputl() - Write Long to Extended Memory
;Args: AYX = Long
XPUTL: RTS
;xread(n,dest) - Read Bytes from Extended Memory
;Args: A = Number of Bytes to Read (0=256)
; YX = Destination Address
;Returns: AYX = New Extended Memory Address
XREAD: ;Return $FF,$FFF
;xwrite(n,source) - Write Bytes to Extended Memory
;Args: A = Number of Bytes to Write (0=256)
; YX = Source Address
;Returns: AYX = New Extended Memory Address
XWRITE: ;Return $FF,$FFF
;xswap(n,dest) - Swap Bytes with Extended Memory
;Args: A = Number of Bytes to Exchange
; YX = System Memory Address
;Returns: AYX = New Extended Memory Address
XSWAP: ;Return $FF,$FFF
;xload(addr) - Load from Extended Memory
;Args: YX = Local Memory End Address
;Uses: GETDST - Local Memory Start Address
;Returns: AYX = New Extended Memory Address
XLOAD: ;Return $FF,$FFF
;xsave(size) - Save from Extended Memory
;Args: YX = Local Memory End Address
;Requires: SRCPTR = Local Memory Start Address
;Returns: AYX = New Extended Memory Address
XSAVE: ;Return $FF,$FFF
;xchng(size) - Exchange with Extended Memory
;Args: YX = Local Memory End Address
;Requires: DSTPTR = Local Memory Start Address
;Returns: AYX = New Extended Memory Address
XCHNG: ;Return $FF,$FFF
;xrpage(count, page) - Read Extended Memory Pages
;Args: A = Number of Pages
; Y = Local Memory Starting Page
;Returns: AYX = New Extended Memory Address
XRPAGE: ;Return $FF,$FFF
;xwpage(count, page) - Write Extended Memory Pages
;Args: A = Number of Pages
; Y = Local Memory Starting Page
;Returns: AYX = New Extended Memory Address
XWPAGE: ;Return $FF,$FFF
;xspage(count, page) - Swap Extended Memory Pages
;Args: A = Number of Pages
; Y = Local Memory Starting Page
;Returns: AYX = New Extended Memory Address
XSPAGE: LDA #$FF ;Return $FF,$FFF
TAY
TAX
RTS
ENDSUBROUTINE

105
include/xmemory.h02 Normal file
View File

@ -0,0 +1,105 @@
/****************************************
* xmemory.h02 - Extended Memory Access *
* Non-Functional Template Module *
****************************************/
#define XLBANK $0F //Maximum Logical Bank
/* Exhange with with Extended Memory *
* Setup: xsetad(xbank, xaddr) *
* setdst(maddr) *
* Args: int n - number of bytes *
* Returns: char bank - Extended Bank *
* int addr - Extended Address */
void xshng();
/* Get Logical Extended Memory Address *
* Returns: char xbank - Logical Bank *
* int xaddr - Logical Address *
char xgetad();
/* Read Byte from Extended Memory *
* Returns: char b: Byte Read */
char xgetc();
/* Read Word from Extended Memory *
* Returns: int i: Word Read */
int xgeti();
/* Read Long from Extended Memory *
* Returns: long l: Long Read */
char xgetl();
/* Load from Extended Memory *
* Setup: xsetad(xbank, xaddr) *
* setdst(maddr) *
* Args: int n - number of bytes *
* Returns: char bank - Extended Bank *
* int addr - Extended Address */
void xload();
/* Write Byte to Extended Memory *
* Args: char b: Byte to Write */
void xputc();
/* Write Word to Extended Memory *
* Args: int i: Word to Write */
void xputi();
/* Write Long to Extended Memory *
* Args: long l: Long to Write */
void xputl();
/* Read Bytes from Extended Memory *
* Args: char n - Number of Bytes *
* int maddr - Destination Address *
* Returns: char bank - Extended Bank *
* int addr - Extended Address */
void xread();
/* Read Extended Memory Pages *
* Args: char n - Number of Pages *
char p - Local Start Page */
void xrpage();
/* Save to Extended Memory *
* Setup: setsrc(maddr) *
* Args: int n - number of bytes *
* Returns: char bank - Extended Bank *
* int addr - Extended Address */
void xsave();
/* Set Extended Memory Address *
* Args: char xbank - Extended Bank *
* int xaddr - Extended Address */
void xsetad();
/* Set Extended Memory Page *
* Args: char xbank - Extended Bank *
* int xpage - Extended Page */
void xsetpg();
/* Swap Extended Memory Pages *
* Args: char n - Number of Pages *
char p - Local Start Page */
void xspage();
/* Swap Bytes with Extended Memory *
* Args: char n - Number of Bytes *
* int maddr - Destination Address *
* Returns: char bank - Extended Bank *
* int addr - Extended Address */
void xswap();
/* Write Extended Memory Page *
* Args: char xbank - Extended Bank *
* char xpage - Extended Page *
* char mpage - Memory Page */
void xwpage();
/* Write Bytes to Extended Memory *
* Args: char n - Number of Bytes *
* int maddr - Source Address *
* Returns: char bank - Extended Bank *
* int addr - Extended Address */
void xwrite();