Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM assembler version of lpeek and lpoke #33

Merged
merged 9 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(assembler
src/llvm/fileio.s
src/llvm/dirent.s)
src/llvm/dirent.s
src/llvm/memory_asm.s)

set(objects
src/conio.c
Expand Down Expand Up @@ -67,8 +68,7 @@ set(CLANG_WARNINGS
-Wpedantic # warn if non-standard C/C++ is used
-Wlanguage-extension-token
)
add_compile_options(-mcpu=mos65c02 -Os ${CLANG_WARNINGS})
target_compile_options(mega65libc PRIVATE -mcpu=mos65c02 -Os ${CLANG_WARNINGS})
target_compile_options(mega65libc PRIVATE -mcpu=mos65ce02 -Os ${CLANG_WARNINGS})

# install target
include(GNUInstallDirs)
Expand Down
22 changes: 8 additions & 14 deletions include/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,21 @@ void lcopy(long source_address, long destination_address, unsigned int count);
void lfill(long destination_address, unsigned char value, unsigned int count);
void lfill_skip(long destination_address, unsigned char value,
unsigned int count, unsigned char skip);
#if defined(__CC65__)
#define POKE(X, Y) (*(uint8_t*)(X)) = Y
#define POKE16(X, Y) (*(uint16_t*)(X)) = Y
#define POKE32(X, Y) (*(uint32_t*)(X)) = Y
#define PEEK(X) (*(uint8_t*)(X))
#define PEEK16(X) (*(uint16_t*)(X))
#define PEEK32(X) (*(uint32_t*)(X))
#elif defined(__clang__)

#ifdef __clang__
#define POKE(X, Y) (*(volatile uint8_t*)(X)) = Y
#define POKE16(X, Y) (*(volatile uint16_t*)(X)) = Y
#define POKE32(X, Y) (*(volatile uint32_t*)(X)) = Y
#define PEEK(X) (*(volatile uint8_t*)(X))
#define PEEK16(X) (*(volatile uint16_t*)(X))
#define PEEK32(X) (*(volatile uint32_t*)(X))
#else
#define POKE(X, Y)
#define POKE16(X, Y)
#define POKE32(X, Y)
#define PEEK(X)
#define PEEK16(X)
#define PEEK32(X)
#define POKE(X, Y) (*(uint8_t*)(X)) = Y
#define POKE16(X, Y) (*(uint16_t*)(X)) = Y
#define POKE32(X, Y) (*(uint32_t*)(X)) = Y
#define PEEK(X) (*(uint8_t*)(X))
#define PEEK16(X) (*(uint16_t*)(X))
#define PEEK32(X) (*(uint32_t*)(X))
#endif

#endif // __MEGA65_MEMORY_H
28 changes: 28 additions & 0 deletions src/llvm/memory_asm.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.global lpoke, lpeek
.section code, "a"
lpoke:
; copy 32-bit input address (a, x, rc2-rc3) to rc5-rc8
sta __rc5
stx __rc6
lda __rc2
sta __rc7
lda __rc3
sta __rc8
; 8-bit input value (rc4)
lda __rc4
ldz #0
nop
sta (__rc5), z
rts
lpeek:
; copy 32-bit input address (a, x, rc2-rc3) to rc4-rc7
sta __rc4
stx __rc5
lda __rc2
sta __rc6
lda __rc3
sta __rc7
ldz #0
nop
lda (__rc4), z
rts
13 changes: 6 additions & 7 deletions src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,20 @@ unsigned char lpeek_debounced(long address)
return db1;
}

#ifndef __CC65__
// cc65 has specialized assembler versions of lpeek and lpoke
void lpoke(long address, unsigned char value)
{
dma_poke(address, value);
}
// cc65 and llvm have specialized assembler versions of lpeek and lpoke
#if !defined(__clang__) && !defined(__CC65__)
unsigned char lpeek(long address)
{
return dma_peek(address);
}
void lpoke(long address, unsigned char value)
{
dma_poke(address, value);
}
#endif

void dma_poke(long address, unsigned char value)
{

dmalist.option_0b = 0x0b;
dmalist.option_80 = 0x80;
dmalist.source_mb = 0x00; // dma_byte lives in 1st MB
Expand Down