An Introduction to Slang ------------------------ Slang is a C64 programming language. It has lots of commands useful for C64 programming, and generates ML code that is compact and efficient. It is meant for programmers of all levels, from those just starting out to those with years of assembly. And it runs on SuperCPU-equipped Commodore 64s, along with PCs for those without a SuperCPU. Slang is designed for writing C64 programs: games, utilities, bitmaps, sprites, irqs, the works. It is a good tool for prototyping, as it allows you to get ideas up and running fast. Because it includes a full assembler, you could even do a demo -- using Slang commands to set up tables, say, and assembly for the time-critical portions. Slang is meant to be used. In this article I'll give an overview of Slang, covering both features and technical aspects, for programmers of all levels. I'll also talk a little about the history and development of Slang. For the latest Slang updates, please visit the homepage at http://www.ffd2.com/fridge/slang. Development and History ----------------------- Slang was developed using a SuperCPU and CMD HD-equipped 128D, using the Sirius assembler. There are around 1000 blocks of source code, assembled into a single 38k program. It took about a year of steady coding to get to the first beta versions, and it is still in development (to be honest, I had no idea it would take so much time and effort). The idea of Slang was to write a programming language that had the kinds of features that a C64 programmer would find useful, and that would write 6502 code the way a C64 programmer would. To illustrate this, consider the well-known problems with writing a C64 game. Anyone who's written a C64 game knows that you spend 5% of the time on the glamorous code for displaying graphics and 95% of the time on all the unglamorous game logic and bookkeeping. You can write it all in ML, for speed, but coding up all the game logic can be tough and tends to bog a lot of projects down. You can use BASIC, but run into the usual problems of slowness and sharing memory. More recently you might use Uz's cool CC65 cross-compiler, but C is a "foreign language" to the C64: it is designed for a different type of task on a different type of computer architecture, and is relatively difficult to learn. And you have to use a PC. (Don't get me wrong; I think CC65 is really neat and important, I just think C is less than ideal for many C64 tasks.) Slang attempts to address these issues. Because Slang is designed for writing C64 programs, the commands have a familiar 'feel' to C= programmers, and are the types of commands a C64 program needs. Because the commands compile more naturally to 6502 code the programs can be fast and (crucially) can easily interface to existing C64 programs, for example programming libraries. And finally, it turns out that Slang includes an assembler, so it is possible for experienced coders to mix and match Slang and assembly as desired. The webpage contains several example programs, inlcuding a joystick-controlled sprite moving over a smoothly scrolling message, and a program using an external bitmap graphics library. Both of these are very easy and natural to do in Slang. And the name, "Slang"? Well, it can stand for "SCPU-Language" or "Sirius-Language" or even "Steve-Language", but it also refers to one special aspect of Slang. It turns out that with Slang you can create new language commands, and even design a completely different language. You can then use those commands to create new commands, and so forth. The dictionary defines slang as "2 : an informal nonstandard vocabulary composed typically of coinages, arbitrarily changed words, and extravagant, forced, or facetious figures of speech" and that fits just fine. Language Features ----------------- Slang has the usual high-level language features: floats, strings, arrays, loops, if-then-else, subroutines, and so on. But it also has a lot of features that make it specifically useful for C64 programming, beyond commands for handling things like sprites and irqs (which Slang also has, see e.g. the spritedemo program on the webpage). For example, you can specify the location of variables: byte border@$d020 ;locate "border" at 53280 border=1 ;set the screen border to white Here's another example: byte screen(25,40)@$0400 screen(12,20) = 0 ;place an '@' in the center of the screen This example creates an array of bytes and locates it at the default screen address, so now the entire text screen may be addressed as an array. This trick is useful for many situations. As another example, consider subroutines. Subroutines in Slang may contain both input and output variables. Slang subroutines are done the same way normal asm subroutines are done, which I'll explain later, and moreover the addresses of all these variables may be specified (even as CPU registers). This means that external machine language routines become immediately accessible as normal Slang subroutines. For example, years ago I wrote a program called GRLIB which contains routines for bitmapped graphics: lines, circles, and so on. To call these routines from Slang, all I had to do was write a "subroutine interface"; here is the interface for the circle routine: sub asm GrCircle@$c021(int x1@$02, int y1@$04, ubyte radius@$10) So with one line of code it is possible to instantly access a bitmapped circle drawing routine that was written almost ten years ago, and use it as a plain Slang command: GrCircle(140,80,25) ;draw a circle This immediately opens Slang up to a large number of existing code libraries, including GUI libraries (Mr. Mouse), graphics (grlib, lib3d/obj3d), and pretty much anything that's been made available over the years. A third example is one mentioned earlier: the ability to mix assembly with Slang. Slang is built on top of the Sirius assembler -- the assembler used to write Slang -- and contains all of its features. You can LDA and STA Slang variables, insert code in the middle of if-then statements, use 65816 code, and do whatever is needed to get the job done. Technical Features ------------------ At a more technical level, most languages are designed for a different type of computer architecture or environment -- CPUs with lots of registers and stack space, multitasking environments, relocatable code, large operating systems, etc. The C64 has a much simpler CPU, fixed registers and memory addresses, a very trivial OS, and generally runs one program at a time. This is the environment Slang is designed for. So, Slang writes code the way a C64 programmer would. For example, arrays are implemented using lookup tables. Subroutines pass variables directly, instead of on the stack. Variables can be placed at specific places in memory. Assembly is part of the language. The goal is not to write programs that can run on any platform or environment -- the goal is to write C64 programs, the way a C64 programmer would. There's one final feature to mention: Slang is a "reconfigurable" compiler. It is possible to add new commands, or to change commands or command syntax. It is possible to create completely different languages. You could even create a language specific to another 6502 computer -- VIC-20 or Apple II, say. It is furthermore possible to use these new commands to write even newer commands, and build up very complex languages. The result is a very flexible and adaptable system with control over the environment. The result isn't very portable, but it isn't meant to be, since that's hardly the purpose of 8-bit computer programming. So if you're at all interested in designing a language for another computer, you might also take a look at Slang. Summary ------- In summary, then, Slang is a C64 programming language: a language for writing C64 programs, that tries to write code like a C64 programmer would. It is accessible to programmers just starting out, with a natural feel and plenty of C64-specific commands, and is a powerful tool for advanced programmers, giving almost total control to the programmer. It is suitable for most C64 programming tasks, and can be adapted to other 6502-based computers (PET, VIC-20, Atari, Apple-II, etc.). I and others are always available to answer questions, so feel free to visit the homepage (http://www.ffd2.com/fridge/slang/) and have a look around. There are example programs, tutorials, and there's a user forum where you can always find help. And feel free to contact me with any other questions or comments!