Jump to content
Sign in to follow this  
tane

mads: labels inside local procedure

Recommended Posts

This compiles and works, but...

  org $609
general.launcher


address1 = $1234

  lda #<:address1
  sta $4000
  lda #>:address1
  sta $4001


jump
  jmp jump

  run general.launcher

 

... not the following. The only difference is  ".local"  and  ".endl".  How can be created a local procedure with non-global labels inside?

  org $609
general.launcher

.local
address1 = $1234

  lda #<:address1
  sta $4000
  lda #>:address1
  sta $4001
.endl

jump
  jmp jump

  run general.launcher

 

Share this post


Link to post
Share on other sites
Posted (edited)
	org $600

A=1

run
	lda #A			;global A=1
	ldx #EXAMPLE.A		;local A=2

	rts

.local EXAMPLE
A=2
	lda #A			;local A=2
	ldx #:A			;global A=1

.endl

run	run

 

Edited by shanti77

Share this post


Link to post
Share on other sites

Thanks all. The idea was to convert the macro CopyMemory (NRV, 2009) to a function in order to save space if multiple times is applied.

 

As Macro:

;--------------------------------------------------------------------------------
; CopyMemory [source address] [dest address] [bytes]
;--------------------------------------------------------------------------------

; warning, using some page zero memory

	.macro CopyMemory

copyMemPtr1	= 254
copyMemPtr2	= 252
copyMemCounter	= 250

	   .if :0 <> 3
	      .error "CopyMemory error"

	   .else
	      ldy #0

	      lda #<:1
	      sta copyMemPtr1
	      lda #>:1
	      sta copyMemPtr1+1

	      lda #<:2
	      sta copyMemPtr2
	      lda #>:2
	      sta copyMemPtr2+1

	      .if :3 < 256
copyMemLoop1
	         lda (copyMemPtr1),y
	         sta (copyMemPtr2),y
	         iny
	         cpy #:3
	         bne copyMemLoop1

	      .else
	         lda #<:3
	         sta copyMemCounter
	         lda #>:3
	         sta copyMemCounter+1

copyMemLoop2
	         lda (copyMemPtr1),y
	         sta (copyMemPtr2),y
	         iny
	         bne copyMemB1
	         inc copyMemPtr1+1
	         inc copyMemPtr2+1
copyMemB1
	         lda copyMemCounter
	         bne copyMemB2
	         dec copyMemCounter+1
copyMemB2
	         dec copyMemCounter

	         lda copyMemCounter
	         ora copyMemCounter+1
	         bne copyMemLoop2
	      .endif
	   .endif

	.endm

 

As 2 functions:

function.main
.local
///////////////////////////// Copy memory procedure - begin
  /////////////// TO EDIT VARIABLES TO THE RIGHT OF EQUAL:
address.current.begin = $1234
address.current.fin   = $5678
address.destiny.begin = $4321
  ;[$address.current.begin - $address.current.fin] copy to [$address.destiny.begin - $address.destiny.fin]
  /////////////// 

  ;Copy addresses to memory - begin:
value.data.1 = address.current.begin
value.data.2 = address.destiny.begin
value.data.3 = address.current.fin-address.current.begin+1

  lda #<value.data.1       ; ":" removed inside a local procedure (lda #<:value.data.1)
  sta copyMemPtr1
  lda #>value.data.1
  sta copyMemPtr1+1

  lda #<value.data.2
  sta copyMemPtr2
  lda #>value.data.2
  sta copyMemPtr2+1

  lda #<value.data.3
  sta copyMemCounter
  lda #>value.data.3
  sta copyMemCounter+1
  ;Copy addresses to memory - end
  jsr function.copy.memory
///////////////////////////// Copy memory procedure - end
.endl
  rts


function.copy.memory
;Variables:
copyMemPtr1     = 254
copyMemPtr2     = 252
copyMemCounter  = 250
;Original macro:
  ldy #0
copyMemLoop2
  lda (copyMemPtr1),y
  sta (copyMemPtr2),y
  iny
  bne copyMemB1
  inc copyMemPtr1+1
  inc copyMemPtr2+1
copyMemB1
  lda copyMemCounter
  bne copyMemB2
  dec copyMemCounter+1
copyMemB2
  dec copyMemCounter
  lda copyMemCounter
  ora copyMemCounter+1
  bne copyMemLoop2
  
  ;Clean temp bytes of macro CopyMemory
  lda #$00
  sta $fa
  sta $fb
  sta $fc
  sta $fd
  sta $fe
  sta $ff
  rts
  

 

  • Like 1

Share this post


Link to post
Share on other sites
11 minutes ago, tane said:

Thanks all. The idea was to convert the macro CopyMemory (NRV, 2009) to a function in order to save space if multiple times is applied.

I see what you want to do, but you lost the speed optimization for 256 bytes or less copies. You could also put the setting of the source, destination and length, and the jsr in a macro. That macro could decide whether to call your current copy routine, or the <=256 copy routine.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...