;; ;; stack.inc, data stack macros ;; Copyright (C) 2001 James Cameron (quozl@us.netrek.org) ;; ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2 of the License, or ;; (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;; ;; ;; Data stack macros, to reduce memory use ;; FSR points to top element of stack ;; Stack grows downward in memory addresses (upward on paper) ;; Initial FSR high in register space ;; pop macro ; pop from stack incf fsr,f endm push macro ; push to stack decf fsr,f endm peekw macro ; copy top of stack to w movf indf,w endm pokew macro ; copy w to top of stack movwf indf endm popw macro ; pop to w from stack peekw pop ; note: affects STATUS,Z endm pushw macro ; push from w to stack push pokew endm dup macro ; duplicate stack using w peekw pushw endm exch macro ; exchange top of stack with w xorwf indf,f xorwf indf,w xorwf indf,f endm swap macro ; ( a b -- b a ) peekw ; ( a [b] ) w=b pop ; ( [a] b ) w=b exch ; ( [b] b ) w=a push ; ( b [b] ) w=a pokew ; ( b a ) endm over macro ; ( a b -- a b a ) pop peekw push pushw endm picks macro depth pushl depth call pick endm pops macro depth movlw depth addwf fsr,f endm popl macro ; pop literal (aka drop) from stack pop endm pushl macro m_literal ; push literal to stack movlw m_literal pushw endm popf macro m_to ; pop to file addresss (uses w) popw movwf m_to endm pushf macro m_from ; push from file address (uses w) movf m_from,w pushw endm pusha macro address pushl low(address) pushl high(address) endm popf16 macro m_to ; pop 16-bit value popf m_to+1 popf m_to endm pushf16 macro m_from ; push 16-bit value pushf m_from pushf m_from+1 endm pushl16 macro literal ; push literal to stack pushl low(literal) pushl high(literal) endm popl16 macro ; pop literal (aka 2drop) popl popl endm mov8 macro from,to movf from,w movwf to endm mov16 macro from,to ; move 16 bit value mov8 from+0,to+0 mov8 from+1,to+1 endm clr16 macro from clrf from+0 clrf from+1 endm mov24 macro from,to ; move 24 bit value mov16 from+0,to+0 mov8 from+2,to+2 endm clr24 macro count ; clear 24 bit value clrf count+0 clrf count+1 clrf count+2 endm mov32 macro from,to ; move 32 bit value mov16 from+0,to+0 mov16 from+2,to+2 endm inc32 macro count ; increment 32 bit value local exit incf count+0,f bnz exit incf count+1,f bnz exit incf count+2,f bnz exit incf count+3,f exit endm clr32 macro count ; clear 32 bit value clrf count+0 clrf count+1 clrf count+2 clrf count+3 endm