Skip to content

Commit

Permalink
Merge pull request #43 from jbrandwood/master
Browse files Browse the repository at this point in the history
Fix bug in HuCC poke() function where the address can be corrupted
  • Loading branch information
jbrandwood authored Sep 8, 2024
2 parents d21acfc + ebb5609 commit 5d9885d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
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

0 comments on commit 5d9885d

Please sign in to comment.