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 > KickAss coding question
2015-01-03 20:31
xIII

Registered: Nov 2008
Posts: 210
KickAss coding question

If I use a for loop and load a value from a table which is stored to a label inside the for loop the value is always the first value of the table ?

just an example:
.for (var i=0; i<38; i++) {

lda valuefromtable+i
sta store+1

store:
lda #$00
sta $d020
}
rts

valuefromtable: .byte 0,1,2,3,4,5,6,7,8,9,10

Question: how can this be solved ? or what am I doing wrong ?
2015-01-03 20:36
Cruzer

Registered: Dec 2001
Posts: 1048
This should work. Maybe the issue is that there's only 11 elements in the table, but 38 loop iterations.
2015-01-03 20:46
xIII

Registered: Nov 2008
Posts: 210
@CRUZER: it's just an example ofcourse :) but even if you add more values to the table it doesn't work :(

This is what I get (in vice monitor):

.C:6000 AD A3 61 LDA $61A3
.C:6003 8D 07 60 STA $6007
.C:6006 A9 00 LDA #$00
.C:6008 8D 20 D0 STA $D020
.C:600b AD A4 61 LDA $61A4
.C:600e 8D 12 60 STA $6012
.C:6011 A9 00 LDA #$00
.C:6013 8D 20 D0 STA $D020
.C:6016 AD A5 61 LDA $61A5
.C:6019 8D 1D 60 STA $601D
.C:601c A9 00 LDA #$00
.C:601e 8D 20 D0 STA $D020
.C:6021 AD A6 61 LDA $61A6
.C:6024 8D 28 60 STA $6028
.C:6027 A9 00 LDA #$00
.C:6029 8D 20 D0 STA $D020
.C:602c AD A7 61 LDA $61A7
.C:602f 8D 33 60 STA $6033
.C:6032 A9 00 LDA #$00
.C:6034 8D 20 D0 STA $D020
.C:6037 AD A8 61 LDA $61A8
.C:603a 8D 3E 60 STA $603E
.C:603d A9 00 LDA #$00
.C:603f 8D 20 D0 STA $D020
...
2015-01-03 21:27
Burglar

Registered: Dec 2004
Posts: 1101
the result you got is correct. what are you trying to achieve?
2015-01-03 21:51
Nith

Registered: Jan 2013
Posts: 15
For me it doesn' t make much sense to mix the self modification of the code with it's actual execution.. You could just leave out the sta store+1 and the lda #$00 and you will get the same result with less code
2015-01-03 22:29
Dr.Science

Registered: Oct 2011
Posts: 41
I think xIII wants to get directly something like this as result:

LDA #$00
STA $d020
LDA #$01
STA $d020
LDA #$02
STA $d020
LDA #$03
STA $d020
etc. etc.
2015-01-03 22:43
Knut Clausen

Registered: Apr 2013
Posts: 18
My guess is that you need to have another look at how the kickassembler preprocessing works. Once you do that, your output will make sense.

I'm not sure what you want to accomplish, but here are two possible solutions.
1: Load numbers by memory reference:

.for (var i=0; i<11; i++) {
lda valuefromtable+i
sta $d020
}
rts
valuefromtable: .byte 0,1,2,3,4,5,6,7,8,9,10

2: Load numbers by actual value:

.var colorsList = List()
.eval colorsList.add(0,1,2,3,4,5,6,7,8,9,10 )
.for (var i=0; i<colorsList.size(); i++) {
lda # colorsList.get(i)
sta $d020
}
rts
2015-01-03 22:50
Oswald

Registered: Apr 2002
Posts: 5094
or how the big boys do it:

lda #<speed
sta fc
lda #>speed
sta fd

lda #$00
sta i

loop

ldx i
lda table,x
sta mod+1

ldy #$00
copy
lda sample,y
sta (fc),y
iny
cpy #end-start
bne copy

tya
clc
adc fc
sta fc
bcc *+4
inc fd

inc y
lda y
cmp #38
bne loop

ldy #$00
lda #$60
sta (fc),y
rts

sample
start
mod lda #$00
sta $d020
end

table .byte 0,1,2,3,4,5,6,7
2015-01-03 22:51
Cruzer

Registered: Dec 2001
Posts: 1048
xIII: The result you get in the Vice monitor seems correct. My guess is now that the code hasn't been executed yet, and the values from the table therefore haven't been copied to the lda's.
2015-01-03 22:55
Oswald

Registered: Apr 2002
Posts: 5094
the first problem that we dont even know whats the problem...

I think kickass is to be used by experienced programmers (such as myself), if you cant write the code generator in native assembly its not for you.

inc i instead of inc y btw.
2015-01-04 10:17
Ash Checksum
Account closed

Registered: Nov 2013
Posts: 6
Word. I think also cars should be only used by people who can build an engine.
 
... 5 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 - 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
Alakran_64
Guests online: 96
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Diskmag Editors
1 Magic  (9.8)
2 hedning  (9.6)
3 Jazzcat  (9.5)
4 Elwix  (9.1)
5 Remix  (9.1)

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