Slang Frequently Asked [Programming] Questions SLJ last updated 06/29/06 This is a work in progress... sorry there's not much here yet. ++ Are there any licensing issues for programs written in Slang? ++ What's the deal with all the .e and .l and .s and ...? ++ Changing the program compilation address from $1000. ++ Mixing Slang and assembly. ++ Using external ML routines with Slang. ++ Commenting out large sections of code/debugging #IFDEFs? ++ Embedding sprite or other data. ++ Using bitmapped graphics. ++ Using interrupts. ++ What's the equivalent of backarrow in xlang? ++ Are there any licensing issues for programs written in Slang? Nope. (It's like using an assembler.) ++ What's the deal with all the .e and .l and .s and ...? Slang source code files end in .s. Slang object files end in .o. Slang linker files end in .l. As to the rest, when developing code I mark the current version with a letter. For example, slangdef.r.s is version "r" of the slangdef file. When I update it, I change that to .s.s, then to .t.s, and so on. ++ Changing the program compilation address from $1000 To change the address the program is compiled to, use the ORG command: org $c000 ;compile to $c000 int x(1) = 10 ;etc. ORG is an assembly pseudo-opcode, and needs to be indented. More on this below. For more information on ORG, see the Sirius assembler docs. ++ Mixing Slang and assembly. Slang contains the Sirius 65816 assembler, which is able to operate on Slang variables. For example: byte b ;Slang command inc b ;assembly command to increment b lda b sta $d021 ;set background to b lda #b ;set .AX to the address of b and so forth. Notice that the asm commands are indented. In 6502/816 asm, labels always start in the first column. If you put a command like inc b in the first column, the label "inc" will be created, and the statement "b" will be parsed and generate an error. This is especially irritating when doing something like RTS. But that's assembly for you. The rule is: Always Indent Assembly Commands. Check out slangdemo1 for an example of mixing asm and Slang, where asm is used for the DYCP, but Slang is used to set everything up and do the sprites and scroll. The Sirius assembler is quite powerful. Really. It's what I used to write Slang. You could write hugely complicated assembly programs, without ever using Slang commands. To get the most out of it, I highly recommend reading the Sirius docs, or at least the quick reference. ++ Using external ML routines with Slang. One way to use external routines is to use code like the above to copy variables over and JSR the routine. However, because Slang is built on top of assembly, and because Slang implements subroutines in a more 6502 kind of way, it is possible to write a little interface into the ML routine and let Slang do the work for you. When calling a 6502 ML routine, you generally need to copy some variables to some specific location, sometimes load up the registers with specific values, and call the routine. For example, when calling a bitmap routine to draw a line, you might have to store the x and y endpoints somewhere in zero page and call the routine. Slang implements subroutines the same way: variables are copied over, and the routine is called. What this means is that you can write a subroutine _interface_ to an ML routine, which tells Slang where to copy variables, what they should be converted to, etc. and where the routine is. So, for example, here is the interface to an ML line drawing routine, from the grlib.ext.s file: sub asm GrLine@$c01e(int x1@$02, int y1@$04, & int x2@$06, int y2@$08) The "asm" keyword after the sub tells Slang that this isn't the start of a subroutine, but is just an interface to an outside routine. The GrLine@$c01e routine creates a slang subroutine variable called GrLine, located at $c01e (the jump point in the grlib graphics library). The next four variables describe the variable types (signed 16-bit), their locations, and how many are needed. Slang can also load stuff to registers (A, X, Y, 16-bit AX, etc.). So with a single line of code, Slang will now do all the work of converting variables as needed, storing them in the right place, and calling the routine, as if the routine were written in Slang all along. Easy! ++ Commenting out large sections of code/debugging #IFDEFs? The assembler pseudo-op "DO 0" turns assembly off. A corresponding FIN turns it back on. So, something like int b b=1 do 0 b=10 ... fin will ignore the lines between the "do 0" and the "fin". This is a handy way to comment out big sections of code at once. Note that "do" and "fin" are indented, since they are assembly ops. More generally, do evaluates the following expression, and if it evaluates to zero assembly is turned off. Therefore, you can use code like DEBUG EQU 1 ;set to 0 to turn off debug code do DEBUG debugging code... fin to selectively enable compilation of sections of code. There is one obnoxious caveat to using do: do can be followed by "ELSE" for conditional assembly. When commenting out an if-then-else type of thing using do, the compiler will get confused and spit out an error. In this case the else lines must be commented out manually. Like I said, obnoxious, hopefully will be fixed sometime. ++ Embedding sprite or other data. Data, such as sprite data, may be included in several ways. One simple method is to create an array and pre-define the values, like byte sprdat(63) = [$00 $aa $00 & 169 155 1 & %01001100 %01101110 %11000000 & ... ] Notice that hex, decimal, and binary may all be used. You can then create a virtual array (an @-var array) as a place to copy to, e.g. byte vicdat(63)@832 for x=0:63 vicdat(x)=sprdat(x) next which copies the array values from sprdat into memory starting at 832. Another way, more like assembly, is to create an @-array to "capture" a set of values defined using assembly: byte sprdat(63)@ASMDAT [slang code, etc.] ASMDAT dfb %01001100,%00011000,%00110010 dfb %01100110,%00110010,%01100100 and so forth. Again, by creating a virtual @-array it is possible to "capture" data and then access it as an array. Which, of course, leads to the final way. Let's say you've edited a bunch of data using some sprite editor. You can include this data as a binary file, using the "BIN" command, and use an @-array as above. Or you could load it into memory somewhere (say at $c000) and create a virtual array pointing to that address. And finally, of course, if you're really motivated, you can do it in plain old ASM. Check out the slang quickref for some of the built-in sprite commands for setting the sprite address, position, and so on. ++ Using bitmapped graphics. Slang has a library for doing bimapped graphics. This is my old BLARG/grlib library. To use it, a set of asm subroutine interfaces is used. The library includes routines for doing points, lines, and circles, allowing for a double-buffered display. For more info, read the grlib docs, or check out the grlib demo program. Yeah, not a very informative section. ++ Using interrupts. Slang has commands for handling both VIC and CIA interrupts. In both cases it assumes the kernal ROM is active, thus the routine is entered through the kernal irq handler (with registers pushed on the stack etc.) and exits through the kernal, instead of just RTI. Routines can also exit through the normal system irq which checks for keypresses, etc. The spritedemo and slangdemo1 programs both demonstrate the use of some of the built-in interrupt commands. As always, you can always drop into assembly directly if needed. ++ What's the equivalent of backarrow in xlang? The backarrow translates to _ underscore, for declaring subroutine return variables using xlang.