wallaby Posted September 14, 2016 Share Posted September 14, 2016 This is basic ASM question. What I'm trying to do is use assembly (instead of a macro) to change the player sprites and colors to anything. change_player_color STA player0color STY player0color+1 LDA #16 STA player0height RETURN If I call the function this way: temp1 = change_player_color(flash_lo, flash_hi) This changes the color, but not the right way. It looks like it's just getting random data and all the lines are different colors. I'd like to simplify this so I only need to pass the label of the data object. Like: temp1 = change_player_color(flash_color) Another thing, is how can I manipulate something already in a register? Can I use other registers in an expression? LDA x + y? Can I manipulate the current register on the same line? LDA a + 1? I have this working with macros, but do macros duplicate your code for every permutation? Quote Link to comment Share on other sites More sharing options...
wallaby Posted September 14, 2016 Author Share Posted September 14, 2016 Hmm. Maybe macros don't behave like I thought they did. I thought they sort of allowed you to programmatically duplicate code. But when I call the same macro twice, it looks like it acts more like a function. In that case, it shouldn't duplicate and using a macro is easier. Unless my interpretation is wrong. Quote Link to comment Share on other sites More sharing options...
bogax Posted September 14, 2016 Share Posted September 14, 2016 This is basic ASM question. What I'm trying to do is use assembly (instead of a macro) to change the player sprites and colors to anything. change_player_color STA player0color STY player0color+1 LDA #16 STA player0height RETURN If I call the function this way: temp1 = change_player_color(flash_lo, flash_hi) This changes the color, but not the right way. It looks like it's just getting random data and all the lines are different colors. I'd like to simplify this so I only need to pass the label of the data object. Like: temp1 = change_player_color(flash_color) Another thing, is how can I manipulate something already in a register? Can I use other registers in an expression? LDA x + y? Can I manipulate the current register on the same line? LDA a + 1? I have this working with macros, but do macros duplicate your code for every permutation? macros do duplicate code they're kinda like inlined functions "temp =" is bB and there's not much facility built into bB for getting stuff from asm to bB (you just do it in asm) a bB function can supply a value for an assignment but it has a bunch of overhead you probably don't need for one thing it's a subroutine for another it always (in effect) passes at least two parameters whether you want them or not if your player data object is in RAM and therefore uses 1 byte addresses then you're asm might be something like this macro {1} asm lda {1} sta player0color lda #16 sta player0height end end you'd pass the macro a number which is the address of the color data (a single byte) in bB that would be either a numeric constant or a variable name the variable name is an alias for the number which is the address of a location in memory it gets interpreted as an address in the asm because I didn't tell it otherwise if you passed "a" as a parameter that would be equivalent to lda $d6 $d6 is the location of variable a if the asm were lda {1}+1 that would be address $d7 dasm would do the math it's a constant expression and that would be variable b (they're in order in memory) if the asm were lda #{1} and you passed (variable name) "a" as a parameter then player0color would get set to $d6 the bB equvalent of that (my) macro would be macro player0color = {1} playerheight = 16 end I don't think that helps you much though (I don't think any of that is what you want) could you give a little more information (maybe a little more explicit) Quote Link to comment Share on other sites More sharing options...
wallaby Posted September 15, 2016 Author Share Posted September 15, 2016 What I'm trying to come up with is an efficient way to change player sprites and colors in bB. I didn't want to use a macro because of the duplication of code. The overhead of a function isn't too much of a problem since I won't call it every frame, only occasionally. I understand the assembly to set a sprite color or pixel data in DPC+. The problem is I don't know how to pass my address as an argument to the function. Or how to pass a label as an argument. (Since they're 16-bit.) Quote Link to comment Share on other sites More sharing options...
wallaby Posted September 15, 2016 Author Share Posted September 15, 2016 could you give a little more information (maybe a little more explicit) Here is my macro currently. This works. But does it duplicate the code for every label I pass to it? If I pass "monster" or "monster2" or "monster3" is this code getting duplicated for each one? macro _change_sprite_color_player0 ;1 datalabel (myskele) asm LDX #<{1} STX player0color LDA #((>{1}) & $0f) | (((>{1}) / 2) & $70) STA player0color+1 end end Quote Link to comment Share on other sites More sharing options...
bogax Posted September 15, 2016 Share Posted September 15, 2016 I don't see anything there that needs asm you can't stx in bB but you don't need to what is the nature of the label/parameter? Quote Link to comment Share on other sites More sharing options...
wallaby Posted September 15, 2016 Author Share Posted September 15, 2016 what is the nature of the label/parameter? It's either a list of colors or sprite data. (Using DPC+ kernel) Imagine a situation where you want to re-use sprite data. If you use bB, you might set player0 to a sprite using the syntax "player0: %000000, etc" What if you want to then use that same sprite for player1? If you use the same syntax "player1: %00000, etc" you just duplicated the data. The more sprites you want to use, more this situation spirals out of control. So, you can set the sprite using the data format. Then you can reference that data for your players and it's only defined once. data skele %00111000 %01111100 %01111100 %01111100 %01101000 %01101000 %00010100 %00010100 %01111110 %01111110 %10111101 %10111101 %00111000 %00111000 %01000100 %01000100 end I don't know of any way to set this data to a player object in bB. player0: skele? player1: skele? But I know how it is set in ASM by examining the file generated by bB. So I have to either bypass bB using inline ASM or extend bB to use some new syntax. Modifying bB is much, much harder because the application is larger and I don't have a development environment set up for C. That leaves one option - inline asm. Quote Link to comment Share on other sites More sharing options...
bogax Posted September 15, 2016 Share Posted September 15, 2016 (edited) you can do that without asm as far as I know there are only two uses of labels in bB either as targets for goto's and such or as the name of a table in a data statement if it's a goto target bB appends a "." to get access in bB define constants for the labels data table xx, xx, etc end const tablelo = <table const tablehi = >table ;the label target const targetlo = <.target const targethi = >.target [ I haven't got time to search now but if you can find some of my previous posts there should be examples (somewhere ) edit: I found some old files and attached them here because I thought they were probably from the (no longer working) link there maybe a mistake because they appear to come from here Edited September 15, 2016 by bogax Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.