Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** This does something similar to the classic
- * "Hello World!" code that's a popular starting
- * point for learning programming. It also adds
- * a scrolly text at the bottom of the screen.
- * For the Sinclair ZX Spectrum using z88dk
- * MMXII Donkeysoft. */
- #include <stdio.h>
- #include <input.h>
- //#include <spectrum.h>
- // Here are our default colour attributes
- #define INK 7
- #define PAP 2
- #define FLA 0
- #define BRI 1
- #define INV 0
- #define BOR 5
- // This is used in the setup function, which drops into
- // machine code - see my blog for more information:
- #define COL 128*FLA+64*BRI+8*PAP+INK
- // Forward declarations of functions:
- static void main(void);
- static void setup(void);
- static void hello(void);
- static void magazine(void);
- static void scroll(void);
- // Global variables:
- static int c=0;
- static int i=0;
- static int j=0;
- // Here is an array which will set up the default colour
- // attributes for printing our message to the screen,
- // 255 is used as a 'terminator' to say "we've finished here"
- static int screensetup[]=
- {
- 1,32,16,48+INK,17,48+PAP,18,48+FLA,19,BRI,20,48+INV,12,255
- };
- static int scrollsetup[]=
- {
- 1,64,16,48+INK-1,22,0,5,255
- };
- static char text[]="................ This is an example of a simple scrolly text in C #"; // Hash used as terminator!
- static char buffer=' ';
- // This is the 'entry point' of our program:
- void main(void)
- {
- // This will call a routine to set the default
- // colour arrtibutes for the whole screen as
- // defined above:
- setup();
- // This does the same for outputting out character
- // see http://www.z88dk.org/wiki/doku.php?id=platform:zx
- // for more information under the heading "The standard
- // ZX Spectrum console driver" - hopefully, these numbers
- // will now make more sense!
- while(screensetup[i]!=255)
- {
- // The %c means 'print character code' or something similar
- printk("%c",screensetup[i]);
- // Increase i to read the next element of the array:
- i=i+1;
- }
- i=0;
- // Calls our functions, firstly hello:
- hello();
- // and now magazine:
- magazine();
- // This should set up our next lot of text as specified in the
- // look-up table aka array called scrollsetup:
- while(scrollsetup[i]!=255)
- {
- printk("%c",scrollsetup[i]);
- i=i+1;
- }
- // This simply waits for a key to be pressed:
- in_WaitForKey();
- // This invokes an infinite loop:
- while(1)
- {
- // Here is the time we'll wait in milliseconds:
- in_Wait(48);
- // This effectively moves the cursor or something:
- printf("\x16\x37\x20");
- printf(" ");
- // Here's our loop, as we're going to print out 64 characters
- // now instead of 32:
- for(c=0;c<62;c=c+1)
- {
- // Okay, we want to print all of the chatacters in the
- // scrolly text except for the hash as we're using that
- // as a terminator to say 'end of string':
- if(text[c]!="#")
- {
- printf("%c",text[c]);
- }
- }
- // This calls our scroll function:
- scroll();
- }
- }
- // This function sets up the default colours for our screen as
- // defined above:
- void setup(void)
- {
- #asm
- // Sets default ink and paper colour, then clears screen
- ld a,COL
- ld (23693),a
- call 3503
- // Sets border colour
- ld a,BOR
- call 8859
- #endasm
- }
- void hello(void)
- {
- // Here is where the magic happens, can you tell what it does?
- printf("Hello ");
- }
- void magazine(void)
- {
- // And what about this bad boy then?
- printf("Magazine!\n");
- }
- void scroll(void)
- {
- // Sets counter to zero
- c=0;
- // The buffer will preserve the first char otherwise the
- // scrolling won't wrap around
- buffer=text[c];
- // Loop will happen whilst the terminator hasn't been reached:
- while(text[c]!='#')
- {
- // Moves each character one element to the left:
- text[c]=text[c+1];
- // Increase our counter
- c=c+1;
- }
- // Puts the old first character from the start to the end so
- // it wraps around:
- text[c-1]=buffer;
- // Checks to see if the terminator has been over-written, if not
- // then it's restored:
- if(text[c]!='#')
- {
- text[c]='#';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement