1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-02 19:42:23 +00:00
cc65/libsrc/atmos/cpeeks.s
Greg King ae7a38f3de Added peek functions to the conio library.
The functions return the character, or its attributes, that is at the current screen location of conio's cursor.  The values can be used directly by the output functions to reproduce that screen character.
2021-12-11 18:47:33 -05:00

55 lines
1.2 KiB
ArmAsm

;
; 2017-06-20, Greg King
;
; void cpeeks (char* s, unsigned length);
;
.export _cpeeks
.import setscrptr, popax
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
.macpack generic
_cpeeks:
eor #<$FFFF ; counting a word upward is faster
sta ptr3 ; so, we use -(length + 1)
txa
eor #>$FFFF
sta ptr3+1
jsr setscrptr ; Set ptr2 and .Y to the cursor's address
sty tmp2
jsr popax
sta tmp1 ; (will be a .Y index)
stx ptr1+1
ldx #<$0000
stx ptr1
bze L3 ; branch always
L4: ldy tmp2
lda (ptr2),y ; Get char
iny
bnz L2
inc ptr2+1
L2: sty tmp2
and #<~$80 ; Remove reverse bit
ldy tmp1
sta (ptr1),y
iny
bnz L1
inc ptr1+1
L1: sty tmp1
L3: inc ptr3 ; count length
bnz L4
inc ptr3+1
bnz L4
txa ; terminate the string
ldy tmp1
sta (ptr1),y
rts