The previous post dealt with function arguments and private variables inside functions. Today we’re going to complete our study of functions by looking at how we can return values from them.
Let’s jump into it.Read more ›
It’s been a bit over two months since the previous post. In it we learnt how to define simple functions that don’t take or return any parameters. We also learnt that we need to declare a function if we’re calling it at a point in our program where it hasn’t been defined yet.
Today we’re resuming the course exactly where we left it. If you need a refresher then go ahead and re-read the previous chapter. As always, don’t hesitate to ask questions in the comments below if anything isn’t clear.
Let’s see a few more properties of functions in C:Read more ›
— Javi Lavandeira (@javilm) December 31, 2015
The plan was to go buy a floppy drive and a couple of cables and write a review immediately after the New Year vacation, but I focused on other things for a while.
It has taken a while, but here’s the review.Read more ›
We’ve covered a lot of ground already, but so far we haven’t seen anything about MSX-C that couldn’t be done with some effort with MSX-BASIC. That changes with the posts that follow.
Today we’re going to see one of the strengths of the C programming language: functions.
Let’s get to it.
Defining and using functions
When we write a program, as the source code becomes bigger and bigger it becomes much more complex and more difficult to maintain. Because of this, no matter what programming language we use, we normally divide a big program into smaller parts that perform a specific action. For example, in BASIC we used to write subroutines and call them with GOSUB.
In C we do this with functions.
Defining a function
Before we can use a function we have to indicate what code it is going to execute and what name we’re going to give to it. We call this the function definition.
The way we define a function changes slightly depending on whether it takes parameters or not, and whether it returns any data or not. Let’s start with the simplest cases and then look at more complex scenarios.
Function without parameters nor return value
The simplest case is a function that doesn’t take any parameters and that performs some action, but doesn’t return any data. It’s basically just a bunch of C statements grouped together and given a name. This is how we define such a function:Read more ›
(Update: Kai stole the ship graphics from here. See below)
(Update 2: I was wrong about Kai stealing the ship images. He has shown proof that he purchased these models back in November 4th. I apologize to Kai for asserting he had stolen these two images, when he did legally purchase them)
This post initially was a big rant complaining about Kai Magazine (Oscar Albero) and snout (Sander Zuidema) for what happened in this thread on msx.org:
- Kai claimed to have created most of the graphics for his game Life on Mars. Arkhan called him out on this and Kai, instead of admitting the criticism, started playing the victim and accusing Arkhan of attacking him.
- snout, acting as an admin in the MSX Resource Center, didn’t moderate the discussion properly. Instead, he insulted and banned Arkhan, and stopped all critical comments in the thread.
After my very angry post here and a heated discussion on Facebook, snout has apologized for his behaviour on this thread on the MSX Resource Center. Whether there’s a change in the MRC admins’ attitude is something that time will tell, but for now I accept the apology.
I’ve removed the rants in this post, as they’re not appropriate anymore. If the atmosphere
P.S.: From now on I’ll be in the #msxdev channel in irc.rizon.net.
In the last few posts we’ve learnt how to control what’s being printed on the screen. Soon we’ll move on to something else (functions!), but first we’re going to see how to handle graphical characters and how to print any character inside a double-quoted string.
The MSX graphic characters
MSX computers have a set of 32 special characters known as graphic characters. These only occupy one position on the screen and one byte in the video RAM, but in order to display them we have to print a 2-byte sequence.
We can type all of these characters by pressing the GRAPH key together with normal alphanumeric characters on the keyboard, but not all the characters generated with GRAPH are 2-byte codes: some are normal characters from the ASCII table (we’ll see these in the future).
Also, it’s important to remember that most of these graphic characters will be different from one MSX to another depending on the country of origin of the computer. For example, a Japanese MSX computer would display several commonly used kanji characters, while an European MSX would display several other useful symbols:Read more ›
In the last post we learned about control characters and the C escape sequences that represent some of them. Today we’re going to see a different kind of escape sequences: the ones that control the console.
You may remember that among the list of control characters we saw there were two that weren’t used to control the screen, but instead mark the beginning of either a graphic character or a terminal escape sequence. In this chapter we’re going to see how to use one of these (character code 27, or \33, or 0x1B):
Printing this character by itself does nothing. However, when it is followed by certain sequences of characters we can control several aspects of the text screen such as the position and shape of the cursor.Read more ›
8bitkick is a deck of 42 printed cards featuring photos of retro computers (and also a Raspberry Pi that got thrown into the mix because it’s cute). In order to create the product a Kickstarter campaign started with a funding goal of $750.
The campaign ended a few hours ago. The amount raised? $12,233. About 16 times the amount needed. Looks like there are a few of us (retro computer enthusiasts) out there.
Oh, I forgot to mention: one of the cards features the Ferrari of 8-bit computers: a red Sony HB-101:
You may have seen this photo somewhere before. :-)
All cards will be freely available for download after they’ve been produced.
Relevant link: http://www.8bitkick.cc
The MSX supports several control characters. Those are special characters that when printed on the screen don’t display any letter, number or symbol, but instead perform some special function such as clearing the screen or moving the cursor.
Let’s go take a look.Read more ›
At this point we already know a decent amount about programming in C and we can create some useful (although simple) programs. We’ve seen how to display text and numbers on the screen, but we haven’t paid much attention to the presentation yet. We’re going to take care of this in the next few chapters.
There are several statements in MSX BASIC such as CLS and LOCATE to help determine where and how things will be displayed on the screen. The C language doesn’t have functions to do the same thing, but we use control characters and escape sequences to achieve the same thing.
Let’s start.Read more ›