1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-22 12:30:41 +00:00

Code improvement

git-svn-id: svn://svn.cc65.org/cc65/trunk@3385 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2005-02-14 10:28:54 +00:00
parent 100fbfc0d1
commit 6c796774d8

View File

@ -6,9 +6,9 @@
; 2005-02-11, Greg King ; 2005-02-11, Greg King
.export _vfprintf .export _vfprintf
.import pushax, popax, push1, pushwysp, ldaxysp, ldaxidx, incsp6 .import push1, pushwysp, incsp6
.import _fwrite, __printf .import _fwrite, __printf
.importzp sp, ptr1, ptr2 .importzp sp, ptr1
.macpack generic .macpack generic
@ -29,72 +29,61 @@ ptr: .res 2 ; Points to output file
; ---------------------------------------------------------------------------- ; ----------------------------------------------------------------------------
; Callback routine used for the actual output. ; Callback routine used for the actual output.
; ;
; Since we know, that this routine is always called with "our" outdesc, we
; can ignore the passed pointer d, and access the data directly. While this
; is not very clean, it gives better and shorter code.
;
; static void out (struct outdesc* d, const char* buf, unsigned count) ; static void out (struct outdesc* d, const char* buf, unsigned count)
; /* Routine used for writing */ ; /* Routine used for writing */
; { ; {
; register size_t cnt; ; register size_t cnt;
;
; /* Write to the file */ ; /* Write to the file */
; if ((cnt = fwrite(buf, 1, count, (FILE *)d->ptr)) == 0) { ; if ((cnt = fwrite(buf, 1, count, ptr)) == 0) {
; d->ccount = -1; ; ccount = -1;
; } else { ; } else {
; d->ccount += cnt; ; ccount += cnt;
; } ; }
; } ; }
; About to call ; About to call
; ;
; fwrite (buf, 1, count, (FILE*) d->ptr); ; fwrite (buf, 1, count, ptr);
; ;
out: ldy #5 out: ldy #5
jsr pushwysp ; Push buf jsr pushwysp ; Push buf
jsr push1 ; Push #1 jsr push1 ; Push #1
ldy #7 ldy #7
jsr pushwysp ; Push count jsr pushwysp ; Push count
ldy #11 ; Current offset of D lda ptr
jsr ldaxysp ; Load D ldx ptr+1
ldy #5 ; Offset of ptr1+1 in struct outdesc
jsr ldaxidx ; Load
jsr _fwrite jsr _fwrite
sta ptr2 ; Save function result sta ptr1 ; Save function result
stx ptr2+1
; Get D and store it in ptr1
ldy #5
jsr ldaxysp
sta ptr1
stx ptr1+1 stx ptr1+1
; Load the offset of ccount in struct outdesc
ldy #$00
; Check the return value. ; Check the return value.
lda ptr2+1 ora ptr1+1
ora ptr2
bne @Ok bne @Ok
; We had an error. Store -1 into d->ccount ; We had an error. Store -1 into ccount
.ifp02 .ifp02
lda #<-1 lda #<-1
.else .else
dec a dec a
.endif .endif
sta (ptr1),y sta ccount
iny
bne @Done ; Branch always bne @Done ; Branch always
; Result was ok, count bytes written ; Result was ok, count bytes written
@Ok: lda (ptr1),y @Ok: lda ptr1
add ptr2 add ccount
sta (ptr1),y sta ccount
iny txa
lda (ptr1),y adc ccount+1
adc ptr2+1 @Done: sta ccount+1
@Done: sta (ptr1),y
jmp incsp6 ; Drop stackframe jmp incsp6 ; Drop stackframe