From afbcea2d821d1166ae347338ae52a64f3ee51e57 Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 29 Jun 2016 16:43:56 +0200 Subject: [PATCH] reduce stack usage --- cbios/msgbuf.180 | 61 ++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/cbios/msgbuf.180 b/cbios/msgbuf.180 index 7b70d54..1bce062 100644 --- a/cbios/msgbuf.180 +++ b/cbios/msgbuf.180 @@ -95,9 +95,8 @@ bg.wait: cp (ix+o.in_idx) ; jr z,bg.wait - push hl ; - push ix - pop hl + push ix ; + ex (sp),hl ; add a,l ld l,a jr nc,bg.nc @@ -130,37 +129,27 @@ bg.nc: ; TODO: result code msg.recv: - push de - -mr_wait_start: call msg.in cp 0AEh - jr nz,mr_wait_start - + jr nz,msg.recv call msg.in ; get message length ld c,a inc c jr mr_do - mr_next: - dec c - jr z,mr_exit ; while chars in input buffer + dec c ; while chars in input buffer + ret z call msg.in ; get next mr_do: - ld e,a - ld a,b - or a ; if room in output buffer - jr z,mr_skip - ld (hl),e ; store char - inc hl dec b -mr_skip: + jp p,mr_store + inc b + jr mr_next +mr_store: + ld (hl),a ; store char + inc hl jr mr_next ; -mr_exit: - pop de - ret - ;-------------------------------------------------------------- msgo.st: @@ -185,10 +174,9 @@ msg.out: push ix ld ix,(fifolst+itx) ; - push hl ; push bc push ix - pop hl + ex (sp),hl ; ld c,(ix+o.in_idx) ; ld b,0 add hl,bc @@ -205,8 +193,8 @@ bp.wait: ld a,b out (AVRINT5),a - pop bc pop hl + pop bc pop ix ret @@ -330,7 +318,7 @@ msg.sout: ld b,(hl) ; 6 inc hl ; 4 ex de,hl ; 3 -ms.ol: ; \ +ms.ol: ; push ix ;14 pop hl ; 9 ld c,(ix+o.in_idx) ;14 @@ -392,17 +380,19 @@ msnd_l: buf.put: push ix ;15 - push bc ;11 + ex (sp),hl ;16 ld a,(ix+o.in_idx) ;19 - ld c,a ;4 - ld b,0 ;7 - add ix,bc ;11 - pop bc ;10 - ld (ix),c ;7 - pop ix ;14 + add a,l ; 4 + ld l,a ; 4 + jr nc,bufp.1 ;12/7 + inc h ; 4 +bufp.1: + ld (hl),c ; 7 + pop hl ;10 + ld a,(ix+o.in_idx) ;19 inc a ;4 - and (ix+o.mask) ;19 =121 + and (ix+o.mask) ;19 =129 bufp.wait: cp (ix+o.out_idx) ;19 jr z,bufp.wait ;12/7 @@ -410,8 +400,7 @@ bufp.wait: out (AVRINT5),a ;11 ld a,c ;4 - ret ;10 =191 - + ret ;10 =199 ;---------------------------------------------------------------------- ; Send message MEMORY -- 2.39.2