Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Want to understand this way of looping through a table
2023-10-13 21:16
Flashback

Registered: Dec 2009
Posts: 4
Want to understand this way of looping through a table

Hi,

I would like some explanation about this way of looping a colour table:

colourcycle.asm

Basically it's this section I can't wrap my head around:
...
txa     ; select next colour index
adc #01
and #07 ; loop colour index
tax
...
colours  .byte 09, 08, 05, 13, 01, 13, 05, 08 ; colour table


As far as I understand, the start color is saved in a ZP address (startcol) which will is changed each frame. This is done by txa/ adc #$01 I guess. (BTW, why is there no clc before adc here?) But why do we need the and #$07?

Regards
 
... 27 posts hidden. Click here to view all posts....
 
2023-10-24 11:59
TheRyk

Registered: Mar 2009
Posts: 2071
@Rastah Bar yeah... and more often than not - after spending hours or evenings of cleaning up the mess that once went through as good code for your past self, you just regret not having started from scratch again (which might have even saved time and a bunch of bugs resulting only from messing around with old messy code) :)
2023-10-24 13:13
Rastah Bar

Registered: Oct 2012
Posts: 336
Recoding part of it can definitely help. Instead of looking at the screen and trying to figure it out, recoding may tell you quicker what you were doing and perhaps show some bugs, too.
2023-10-25 10:18
Krill

Registered: Apr 2002
Posts: 2844
Quoting Oswald
this label: is horrible :P
Indeed.

The point of a colon after a label definition is to tell it apart from references to that label.

So you can easily search for that label while conveniently not having to skip over all the references to that label.

Having to add the colon to all references as well is pointless, could just as well have everything without colons, like the OG Turbo Assembler did. =)
2023-10-25 10:47
Oswald

Registered: Apr 2002
Posts: 5017
Quote: Quoting Oswald
this label: is horrible :P
Indeed.

The point of a colon after a label definition is to tell it apart from references to that label.

So you can easily search for that label while conveniently not having to skip over all the references to that label.

Having to add the colon to all references as well is pointless, could just as well have everything without colons, like the OG Turbo Assembler did. =)


ah I didnt know this! finally colon makes sense, but one clever text editor could just show the label without any preceeding characters, I prefer turbo asm way till death :)
2023-10-25 10:51
Krill

Registered: Apr 2002
Posts: 2844
Quoting Oswald
ah I didnt know this! finally colon makes sense, but one clever text editor could just show the label without any preceeding characters, I prefer turbo asm way till death :)
You'll quickly end up with an IDE again, and i love me my not-too-smart text editors (like KATE aka KEdit). :)
2023-10-25 12:15
Rastah Bar

Registered: Oct 2012
Posts: 336
Quote: Quoting Oswald
this label: is horrible :P
Indeed.

The point of a colon after a label definition is to tell it apart from references to that label.

So you can easily search for that label while conveniently not having to skip over all the references to that label.

Having to add the colon to all references as well is pointless, could just as well have everything without colons, like the OG Turbo Assembler did. =)


If you want to make clear the difference between labels and memory addresses, how do yo do that? For example, labels all in lowercase letters and memory addresses start with a capital?
2023-10-25 12:33
chatGPZ

Registered: Dec 2001
Posts: 11116
but labels are memory addresses?

*runs*
2023-10-25 12:35
Krill

Registered: Apr 2002
Posts: 2844
Quoting Rastah Bar
If you want to make clear the difference between labels and memory addresses, how do yo do that? For example, labels all in lowercase letters and memory addresses start with a capital?
Yes, by convention, if need be. It's nothing that needs to be enforced by the toolchain.

My personal convention is all-lower-case for regular labels and allcaps for labels with literally assigned addresses (either by asm source or via linker script). The latter are constants, after all.
2023-10-25 14:06
Rastah Bar

Registered: Oct 2012
Posts: 336
@chatGPZ: yes, that's true, but I find code a bit easier to read when I see immediately what everything is. But maybe it does not matter in this case.

@Krill: thanks, I will try out some naming conventions.
2023-10-25 22:25
Frostbyte

Registered: Aug 2003
Posts: 167
This discussion should really be under its own topic (maybe moderators can move it?), but anyway, my 2 eurocents. I've tried a few naming conventions in KickAssembler, and pretty much settled with the following.

Address pointers (i.e. labels), variables and constants are all lowercase, words separated by underscore. E.g.
      jsr reticulate_splines
      ......

  reticulate_splines:
      lda #next_spline_to_reticulate


Zero page labels are wrapped under "zp" namespace:
  .namespace zp {
      .label current_player_state = $02
      .label spline_tbl_ptr       = $03
  }

      .......
      lda #0
      sta zp.current_player_state

I use namespaces (even recursive ones) for other special addresses too, e.g. sid and vic and other fixed addresses. This allows me to use dot notation, which imho is very readable, e.g.
      lda freq_table_lo, y
      sta sid.ch1.freqlo

For macros I use PascalCasing:
      MoveCursorTo(15, 13)

...and that's about it. Very simple, really. Namespaces are a godsend, I can easily assign the same context to a bunch of labels or values, and while using them, dot notation separates them clearly from the usual labels or variable names. I don't know how many other dialects have namespaces or a similar concept, unfortunately. Some dialects probably allow adding dots to label names, making naming nearly as neat as using namespaces.

Earlier I tried using all uppercase for ZP variables, constants etc., but ditched it later as it made the code messier to read.
Previous - 1 | 2 | 3 | 4 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Dymo/G★P
bOOZElEE
Sentinel/Excess/TREX
Grue/Extend
Acidchild/Padua
Flavioweb/🇮🇹HF..
Guests online: 134
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Wafer Demo  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Musicians
1 Vincenzo  (9.8)
2 Rob Hubbard  (9.7)
3 Stinsen  (9.7)
4 Jeroen Tel  (9.6)
5 Linus  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.233 sec.