TGB1718 Posted November 25, 2020 Share Posted November 25, 2020 I'm just testing some inline .ASM code in cc65 but getting strange results using "-1" is this a "feature" of cc65 ? I tried with local and global variables, same result. this returns 0 signed char v; __asm__ ("lda #-1"); __asm__ ("sta %v",v); return(v); This returns 25 signed char v; __asm__ ("lda #25"); __asm__ ("sta %v",v); return(v); This returns 255 which is -1 signed char v; signed char w=-1; __asm__ ("lda %v",w); __asm__ ("sta %v",v); return(v); So does this return 255 signed char v; __asm__ ("lda #255"); __asm__ ("sta %v",v); return(v); Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted November 25, 2020 Share Posted November 25, 2020 maybe try: _asm__("lda #%b", -1); probably something I've not tried with more recent sources as in early CA65 days the assembler wouldn't accept negative numbers, but when doing disassemblies with IDA Pro I had to manually run through and change "LDA/X/Y #-" to positive values before exporting as source. 1 Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted November 25, 2020 Author Share Posted November 25, 2020 10 minutes ago, Wrathchild said: maybe try: _asm__("lda #%b", -1); Yes, that fixed it, strange that it doesn't accept it in the previous format, it is a rather long winded way to put in-line assembler. thanks very much ? Some C compilers I've use in the past, mainly on my ST, all you had to do was #asm ... your assembler code ... #endasm Quote Link to comment Share on other sites More sharing options...
ivop Posted November 25, 2020 Share Posted November 25, 2020 (edited) If I'm not mistaken, you can do something like: __asm__(" lda #$12 sta $02c4 )"; Or use \n and/or \t and perhaps \ for line continuation? Edited November 25, 2020 by ivop Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted November 25, 2020 Share Posted November 25, 2020 (edited) Having single __asm__ statements maybe as a result of the argument passing. https://www.cc65.org/doc/cc65-9.html If you need a lot of asm then that can easily be broken out, built with ca65 instead (or cl65) and linked. Edited November 25, 2020 by Wrathchild Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted November 25, 2020 Author Share Posted November 25, 2020 (edited) Thanks again, I'll have a look at it, not used ca65 as I generally use MAC/65 will read up on creating routines and linking them in, I would guess the code needs to be relocatable ? Edited November 25, 2020 by TGB1718 spelling Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted November 25, 2020 Share Posted November 25, 2020 er no, you can still put code/data in any desired target segment and let the linker take care of things... certainly the aim with using this approach is to learn to not worry/think about where things reside (except where necessary, e.g. screen / sprite memory) Quote Link to comment Share on other sites More sharing options...
baktra Posted November 25, 2020 Share Posted November 25, 2020 (edited) To verify the behavior, one can always check the resulting .s file with the generated assembler. Edited November 25, 2020 by baktra Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted November 26, 2020 Author Share Posted November 26, 2020 @Wrathchild sorry to be a pain, but do you know of and examples of how to firstly use ca65 to produce runnable code, I converted some code from MAC/65 and managed to run it through ca65, but what next, I've looked at the help files, but struggling a bit. Also how would you merge this with a C program to use with cc65. There's tons of information in the manuals, but a total lack of examples Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted November 26, 2020 Share Posted November 26, 2020 Sounds like you might be over thinking it. break a function out to a separate C file and then compile it using cc65 (not cl65) so that you just produce the .s file from it. You can then examine that to get a feel of how to structure the .s file, but ultimate it really boils down to the '.export' directive to expose the things you want to access. The .s file itself can be built to an object file using ca65 which can then be used with the linker. But you can also use cl65 and pass multiple input files, mixing .c and .s and it will take care the rest. If needed, break down what you are trying into a smaller example and PM me if you get stuck. Quote Link to comment Share on other sites More sharing options...
baktra Posted November 27, 2020 Share Posted November 27, 2020 There is a thread that holds links to some real world examples. Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted November 27, 2020 Author Share Posted November 27, 2020 @Wrathchild thanks, that's what I was thinking, but didn't know that cc65 was the way forward, I'll make something simple and see how it all fits together, thanks again. @baktra thanks for the link, will read it later Quote Link to comment Share on other sites More sharing options...
dmsc Posted November 27, 2020 Share Posted November 27, 2020 Hi! 17 hours ago, TGB1718 said: sorry to be a pain, but do you know of and examples of how to firstly use ca65 to produce runnable code, I converted some code from MAC/65 and managed to run it through ca65, but what next, I've looked at the help files, but struggling a bit. Perhaps a minimal assembly example could help. Try this into a file named "minimal.s": ; Export the start of program code .export start ; Include Atari equates .include "atari.inc" ; Out code .code start: ldx #0 loop: stx COLBK stx WSYNC inx ldy CH iny beq loop rts Then, you assemble with: cl65 -tatari -Catari-asm-xex.cfg minimal.s -o minimal.xex That is all it takes. Have Fun! 1 Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted November 27, 2020 Author Share Posted November 27, 2020 @dmsc thank you so much, those few lines pointed me at more of the config files which answered loads of questions 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.