2000-05-28 13:40:48 +00:00
|
|
|
;
|
2004-11-30 18:47:25 +00:00
|
|
|
; Ullrich von Bassewitz, 1998-12-09, 2004-11-30
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; void __fastcall__ _swap (void* p, void* q, size_t size);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export __swap
|
2018-05-20 13:30:18 +00:00
|
|
|
.import popax, popptr1
|
2013-05-09 11:56:54 +00:00
|
|
|
.importzp ptr1, ptr2, ptr3
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
__swap: eor #$FF
|
|
|
|
sta ptr3
|
2004-11-30 18:47:25 +00:00
|
|
|
txa
|
|
|
|
eor #$FF
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr3+1 ; Save -(size+1) into ptr3
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr popax ; Get q
|
|
|
|
sta ptr2
|
|
|
|
stx ptr2+1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1 ; Get p
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Prepare for swap
|
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
; ldy #$00 is guaranteed by popptr1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-11-30 18:47:25 +00:00
|
|
|
; Swap loop
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-11-30 18:47:25 +00:00
|
|
|
@L1: inc ptr3 ; Bump counter low byte
|
|
|
|
beq @L3 ; Branch on overflow
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
@L2: lda (ptr1),y
|
|
|
|
tax
|
|
|
|
lda (ptr2),y
|
|
|
|
sta (ptr1),y
|
|
|
|
txa
|
|
|
|
sta (ptr2),y
|
|
|
|
iny
|
|
|
|
bne @L1
|
2004-11-30 18:47:25 +00:00
|
|
|
inc ptr1+1
|
|
|
|
inc ptr2+1
|
|
|
|
bne @L1 ; Branch always (hopefully)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-11-30 18:47:25 +00:00
|
|
|
; Bump the high counter byte
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-11-30 18:47:25 +00:00
|
|
|
@L3: inc ptr3+1
|
|
|
|
bne @L2
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Done
|
|
|
|
|
2004-11-30 18:47:25 +00:00
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|