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

Fix bug in HuCC poke() function where the address can be corrupted #43

Merged
merged 1 commit into from
Sep 8, 2024
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
16 changes: 11 additions & 5 deletions include/hucc/hucc-baselib.asm
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,30 @@ _peekw.1 .macro
; ***************************************************************************
; ***************************************************************************
;
; void __fastcall __macro __xsafe poke( unsigned int addr<__ptr>, unsigned char with<acc> );
; void __fastcall __macro __xsafe poke( unsigned int addr<__poke>, unsigned char with<acc> );
;
; N.B. Because the <acc> value can be a complex C calculation, it isn't safe
; to use __ptr as the destination, which can be overwritten in C macros.

_poke.2 .macro
sta [__ptr]
sta [__poke]
.endm



; ***************************************************************************
; ***************************************************************************
;
; void __fastcall __macro __xsafe pokew( unsigned int addr<__ptr>, unsigned int with<acc> );
; void __fastcall __macro __xsafe pokew( unsigned int addr<__poke>, unsigned int with<acc> );
;
; N.B. Because the <acc> value can be a complex C calculation, it isn't safe
; to use __ptr as the destination, which can be overwritten in C macros.

_pokew.2 .macro
sta [__ptr]
sta [__poke]
tya
ldy #1
sta [__ptr], y
sta [__poke], y
.endm


Expand Down
4 changes: 2 additions & 2 deletions include/hucc/hucc-baselib.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ extern unsigned char __fastcall __xsafe __macro ac_exists( void );

extern unsigned int __fastcall __xsafe __macro peek( unsigned int addr<__ptr> );
extern unsigned int __fastcall __xsafe __macro peekw( unsigned int addr<__ptr> );
extern void __fastcall __xsafe __macro poke( unsigned int addr<__ptr>, unsigned char with<acc> );
extern void __fastcall __xsafe __macro pokew( unsigned int addr<__ptr>, unsigned int with<acc> );
extern void __fastcall __xsafe __macro poke( unsigned int addr<__poke>, unsigned char with<acc> );
extern void __fastcall __xsafe __macro pokew( unsigned int addr<__poke>, unsigned int with<acc> );

extern unsigned int __fastcall __xsafe __farpeekw( void __far *addr<__fbank:__fptr> );

Expand Down
1 change: 1 addition & 0 deletions include/hucc/hucc.asm
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ __fbank .ds 1
__sp .ds 1
__stack .ds HUCC_STACK_SZ
__ptr .ds 2
__poke .ds 2

; Data pointer used by SDCC for indirect indexed memory access

Expand Down