eris2010

Documentation: http://frombelow.net/projects/eris2010/
Clone: git clone https://git.frombelow.net/eris2010.git
Log | Files | Refs | README | LICENSE

ds.inc (1506B)


      1 ;;; -*- asm -*-
      2 
      3 ;;; Copyright 2021 Gerd Beuster (gerd@frombelow.net). This is free
      4 ;;; software under the GNU GPL v3 license or any later version. See
      5 ;;; COPYING in the root directory for details.
      6 
      7 ;;; Macros for accessing the data stack
      8 ;;; and managing local variables and
      9 ;;; call parameters. Check ds.asm for
     10 ;;; documentation.
     11 
     12 .namespace ds
     13 	
     14 INIT_STACK:	.macro
     15 	#mem.STORE_WORD \1, ds.ptr
     16 	.endm
     17 	
     18 PUSH:	.macro			; Reserve bytes on stack (no actual push operation)
     19 	#mem.ADD_WORD ds.ptr, \1
     20 	.endm
     21 
     22 PULL:	.macro			; Remove bytes from stack (no return value)
     23 	#mem.SUB_WORD ds.ptr, \1
     24 	.endm
     25 
     26 PUSH_WORD:	.macro		; Push a word on the stack
     27 	lda #<\1
     28 	sta (ds.ptr)
     29 	lda #>\1
     30 	ldy #$01
     31 	sta (ds.ptr),y
     32 	#ds.PUSH $02
     33 	.endm
     34 
     35 LOCAL:	.macro
     36 	ldy #\1
     37 	\2 (ds.frame_ptr),y
     38 	.endm
     39 lda_LOCAL:	.macro
     40 	#ds.LOCAL \1, lda
     41 	.endm
     42 sta_LOCAL:	.macro
     43 	#ds.LOCAL \1, sta
     44 	.endm
     45 adc_LOCAL:	.macro
     46 	#ds.LOCAL \1, adc
     47 	.endm
     48 PARAM:	.macro
     49 	ldy #\1
     50 	\2 (ds.ptr),y
     51 	.endm
     52 sta_PARAM:	.macro
     53 	#ds.PARAM \1+2, sta
     54 	.endm
     55 lda_PARAM:	.macro
     56 	#ds.PARAM \1+2, lda
     57 	.endm
     58 
     59 CALL:	.macro subroutine, param=[], param_lda=""
     60 	.block
     61 	.if len(\param) != 0
     62 	  .for CALL_param := 0, CALL_param < len(\param), CALL_param += $1
     63 	    \param_lda \param[CALL_param]
     64 	    #ds.sta_PARAM CALL_param
     65 	  .next
     66 	.endif
     67 	jsr \subroutine
     68 	.bend
     69 	.endm
     70 
     71 ;; Push sequence of bytes to stack. Parameters: From, Length
     72 PUSH_RANGE:	.macro
     73 	ldy #$00
     74 loop_PUSH_RANGE:	
     75 	lda \1,y
     76 	sta (ds_pointer),y
     77 	iny
     78 	cpy \2
     79 	bne loop_PUSH_RANGE
     80 	#PUSH \2
     81 	.endm
     82 
     83 .endn