-; Since Buf and Count are already in place, we will just push the last
-; two parameters. The fwrite function will remove Buf and Count on exit.
-
- jsr push1
- ldy #7 ; Offset of D+1 on stack
- lda (sp),y
- sta ptr1+1
- dey ; Offset of D on stack (6)
- lda (sp),y
- sta ptr1
- dey ; Offset of ptr+1 in struct outdesc (5)
- lda (ptr1),y
- tax
- dey
- lda (ptr1),y
- jsr pushax ; Push D->ptr
- jsr _fwrite
- sta ptr2 ; Save function result
- stx ptr2+1
-
-; Pop the last parameter from stack and store it in ptr1. This means that
-; the stack is clean now.
-
- jsr popax
- sta ptr1
- stx ptr1+1
-
-; Load the offset of ccount in struct outdesc
-
- ldy #$00
-
-; Check the return code. Checking the hig byte against $FF is ok here.
-
- lda ptr2+1
- cmp #$FF
- bne @Ok
-
-; We had an error. Store -1 into d->ccount
-
- sta (ptr1),y
- iny
- sta (ptr1),y
- rts
+out: ldy #5
+ jsr pushwysp ; Push buf
+ jsr push1 ; Push #1
+ ldy #7
+ jsr pushwysp ; Push count
+ lda ptr
+ ldx ptr+1
+ jsr _fwrite
+ sta ptr1 ; Save function result
+ stx ptr1+1
+
+; Check the return value.
+
+ ora ptr1+1
+ bne @Ok
+
+; We had an error. Store -1 into ccount
+
+.ifp02
+ lda #<-1
+.else
+ dec a
+.endif
+ sta ccount
+ bne @Done ; Branch always