You can make a "POKE" macro, but there is no C safe way to specify the kind of 1:1 access you're expecting from it. It may work in all of your cases, but it's generally subject to a lot of compile whims. For safety's sake I'd suggest turning that into an assembly function to isolate it. Maybe something like:
Code: Select all
// C
extern void poke(void* addr, char value);
extern char peek(void* addr);
; assembly
.segment "DATA"
poke_finish:
sta a:$FFFF ; address to be overwritten
rts
peek_finish:
lda a:$FFFF
rts
.segment "CODE"
.export _poke
.export _peek
.import popax
_poke: ; A = value, C-stack = addr
pha ; value
jsr popax ; addr to X:A
sta poke_finish+1
stx poke_finish+2
pla
jmp poke_finish
_peek: ; X:A = addr
sta peek_finish+1
stx peek_finish+2
ldx #0 ; cc65 functions with 8-bit return must leave 0 in X
jmp peek_finish