Jump to content
IGNORED

mads .proc self modifying code?


ivop

Recommended Posts

This happens to work:

    org $2800
  
.proc setcolors (.byte c0,c1,c2,c3,c4) .var
c0=*+1
    mva #$00 $02c4
c1=*+1
    mva #$00 $02c5
c2=*+1
    mva #$00 $02c6
c3=*+1
    mva #$00 $02c7
c4=*+1
    mva #$00 $02c8
    rts
.endp

.proc setcolor0 (.byte c0) .var
c0=*+1
    mva #$00 $02c4
    rts
.end

main
    setcolors #$11, #$22, #$33, #$44, #$55
    setcolor0 #$66
    jmp *

    run main

Disassembly after run:

2800: A9 11     LDA #$11
2802: 8D C4 02  STA $02C4   ;COLOR0
2805: A9 22     LDA #$22
2807: 8D C5 02  STA $02C5   ;COLOR1
280A: A9 33     LDA #$33
280C: 8D C6 02  STA $02C6   ;COLOR2
280F: A9 44     LDA #$44
2811: 8D C7 02  STA $02C7   ;COLOR3
2814: A9 55     LDA #$55
2816: 8D C8 02  STA $02C8   ;COLOR4
2819: 60        RTS
281A: A9 66     LDA #$66
281C: 8D C4 02  STA $02C4   ;COLOR0
281F: 60        RTS
2820: A9 11     LDA #$11
2822: 8D 01 28  STA $2801
2825: A9 22     LDA #$22
2827: 8D 06 28  STA $2806
282A: A9 33     LDA #$33
282C: 8D 0B 28  STA $280B
282F: A9 44     LDA #$44
2831: 8D 10 28  STA $2810
2834: A9 55     LDA #$55
2836: 8D 15 28  STA $2815
2839: 20 00 28  JSR $2800
283C: A9 66     LDA #$66
283E: 8D 1B 28  STA $281B
2841: 20 1A 28  JSR $281A
2844: 4C 44 28  JMP $2844

Not very useful functions per sé, but a proof of concept that it could be (ab)used :)

 

@tebe is this intended behaviour?

 

  • Like 2
Link to comment
Share on other sites

12 minutes ago, Wrathchild said:

I see it as highlighting the inflection.

'e' in 'per' is more an 'uh', so sounds like purr' but in the 'se' its more like the 'ey' in 'hey', sounding like 'say'.

You are right pointing out that "e" in "per" is short, whereas in "se" it is long. But still it does not really need emphasizing in script.

 

PS. I now feel guilty for derailing the topic. And yet I cannot blame anyone else, than myself, for that. I probably should report myself to the administration and get banned :D

 

  • Like 2
Link to comment
Share on other sites

10 hours ago, ivop said:

    org $2800
  
.proc setcolors (.byte c0,c1,c2,c3,c4) .var
c0=*+1
    mva #$00 $02c4
c1=*+1
    mva #$00 $02c5
c2=*+1
    mva #$00 $02c6
c3=*+1
    mva #$00 $02c7
c4=*+1
    mva #$00 $02c8
    rts
.endp

.proc setcolor0 (.byte c0) .var
c0=*+1
    mva #$00 $02c4
    rts
.end

main
    setcolors #$11, #$22, #$33, #$44, #$55
    setcolor0 #$66
    jmp *

    run main

 

simpler


.proc setcolors (.byte c0+1,c1+1,c2+1,c3+1,c4+1) .var

c0 mva #$00 $02c4
c1 mva #$00 $02c5
c2 mva #$00 $02c6
c3 mva #$00 $02c7
c4 mva #$00 $02c8
  rts
.endp

.proc setcolor0 (.byte c0+1) .var

c0 mva #$00 $02c4
   rts
.end

main
    setcolors #$11, #$22, #$33, #$44, #$55
    setcolor0 #$66
    jmp *

    run main

Edited by tebe
  • Like 1
  • Thanks 2
Link to comment
Share on other sites

"per se" is latin.

 

per se

"by himself, herself, or itself," 1570s, Latin, literally "by itself;" from per (see per) + se (see se-). The Latin phrase translates Greek kath auto (Aristotle).

 

It is not spelled with an accent grave (`). English phonetic could be "purr say", as mentioned above. Modern usage usually means "on it's own" or "by itself", or sometimes "literally".

Edited by danwinslow
  • Like 1
Link to comment
Share on other sites

18 hours ago, Wrathchild said:

I see it as highlighting the inflection.

'e' in 'per' is more an 'uh', so sounds like purr' but in the 'se' its more like the 'ey' in 'hey', sounding like 'say'.

That's exactly what the Dutch website says:

Quote

Persé is de ‘vernederlandste’ vorm van per se. Het accent op de slot-e is een uitspraakaanwijzing (lang niet iedereen kent Latijn).

Persé is the "Dutchified" form of per se. The accent on the closing-e is a pronunciation clue (not everybody knows Latin).

 

Anyway, I wrote per sé, which is wrong either way :) The accent is not a grave accent BTW, but an acute accent (accent aigu).

 

Edited by ivop
Link to comment
Share on other sites

54 minutes ago, ivop said:

Anyway, I wrote per sé, which is wrong either way :) The accent is not a grave accent BTW, but an acute accent (accent aigu).

A touch! I do declare!

Yep, you're correct.

Ironically, 'flout' is more or less from dutch:

mid 16th century: perhaps from Dutch fluiten ‘whistle, play the flute, hiss (in derision).

 

The general idea is that 'I play my flute at you in derision'. 

 

  • Like 1
Link to comment
Share on other sites

11 hours ago, tebe said:

simpler


.proc setcolors (.byte c0+1,c1+1,c2+1,c3+1,c4+1) .var

c0 mva #$00 $02c4
c1 mva #$00 $02c5
c2 mva #$00 $02c6
c3 mva #$00 $02c7
c4 mva #$00 $02c8
  rts
.endp

.proc setcolor0 (.byte c0+1) .var

c0 mva #$00 $02c4
   rts
.end

main
    setcolors #$11, #$22, #$33, #$44, #$55
    setcolor0 #$66
    jmp *

    run main

I see what you mean. So it is intended behaviour. Very nice!

 

Using c0+1 in the declaration is interesting, but if you need to reference that value multiple times in your procedure, you need to use c0+1 again instead of just c0, so I guess it's just a matter of taste and what is more convenient to the programmer :)

 

This setcolors() is better done as a macro anyway, but it was just an example to show self modifying code with procedures. Larger procedures, not suitable for macros, could really benefit from this.

 

Now can .reg and .var be mixed? Might be interesting, too.

 

Link to comment
Share on other sites

54 minutes ago, danwinslow said:

Ironically, 'flout' is more or less from dutch:

mid 16th century: perhaps from Dutch fluiten ‘whistle, play the flute, hiss (in derision).

Fascinating. All the Anglo-Dutch wars influenced both languages a lot. It has been said that cultures and languages influence each other most during times of war. Sad, but true.

Edited by ivop
Link to comment
Share on other sites

59 minutes ago, tebe said:

no

okthnx

 

 

edit: it's very cool that the variables stay local to the .proc scope. Using .reg might be useful in a rare case, but .var it is, if its needs extend beyond a macro.

Edited by ivop
Link to comment
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...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...