Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This is a dual scrolly text programme which will display
- * a 'marquee', as they say these days, on the bottom and
- * top lines of BASIC screen area of a ZX81; In this example
- * the top line is inversed, and the bottom line is not.
- * This is a quicker method than shifting the characters
- * with wrap around and updating the display.
- * Written in Z88DK and tested on EightOne emulator.
- *
- * @author Shaun B
- * @date 2012-11-28
- * @version 2.0.3
- */
- #include <zx81.h>
- #include <stdio.h>
- #include <input.h>
- // This will flip the characters to 'inverse' mode:
- #define INVERSE(a) (0x80 | a)
- // This is used for the printat routine:
- #define SCRLOC(x,y) (x<<8 | y)
- // Definitions for ROM calls:
- #define PRINTAT 0x08f5
- #define PRINT 0x10
- // This will define out character sets, meaning that there's
- // no longer a need to convert the bytes on the fly, which
- // should therefore save some timing states:
- #define CLEAR 0x00
- // Here's some characters:
- #define TL 0x01
- #define TR 0x02
- #define TOP 0x03
- #define BL 0x04
- #define LEFT 0x05
- #define CHECKER 0x06
- #define CORNER 0x07
- #define CHESSB 0x08
- #define CHESSBOT 0x09
- #define CHESSTOP 0x0a
- #define QUOTE 0x0b
- #define POUND 0x0c
- #define DOLLAR 0x0d
- #define COLON 0x0e
- #define QM 0x0f
- #define OBRACKET 0x10
- #define CBRACKET 0x11
- #define GRT 0x12
- #define LST 0x13
- #define EQUALS 0x14
- #define PLUS 0x15
- #define DASH 0x16
- #define STAR 0x17
- #define SLASH 0x18
- #define SEMI 0x19
- #define COMMA 0x1a
- #define DOT 0x1b
- // Defines start of numbers:
- #define ZERO 0x1c
- #define ONE 0x1d
- #define TWO 0x1e
- #define THREE 0x1f
- #define FOUR 0x20
- #define FIVE 0x21
- #define SIX 0x22
- #define SEVEN 0x23
- #define EIGHT 0x24
- #define NINE 0x25
- // ZX81 alphabet:
- #define _A 0x26
- #define _B 0x27
- #define _C 0x28
- #define _D 0x29
- #define _E 0x2a
- #define _F 0x2b
- #define _G 0x2c
- #define _H 0x2d
- #define _I 0x2e
- #define _J 0x2f
- #define _K 0x30
- #define _L 0x31
- #define _M 0x32
- #define _N 0x33
- #define _O 0x34
- #define _P 0x35
- #define _Q 0x36
- #define _R 0x37
- #define _S 0x38
- #define _T 0x39
- #define _U 0x3a
- #define _V 0x3b
- #define _W 0x3c
- #define _X 0x3d
- #define _Y 0x3e
- #define _Z 0x3f
- // Function prototypes:
- // Here is our main entry:
- void main(void);
- // This will output our character to the screen:
- void print(short ch);
- // Here's our PRINT AT equivalent:
- void printat(short xy);
- // Things now move much quicker, so we need to slow
- // the scroll update down a bit:
- // In this example, it is unused, but it should cost
- // around 30-something timing states per unit sent to
- // the function at a guess because of how C uses the
- // stack - accepts numbers between 0 and 255
- void pause(char x);
- // Globals for x and y axis:
- // Reusable counters:
- static char i=0;
- static short c=0;
- static char x=0;
- static char y=0;
- // Used for reading the keyboard:
- static char key=0;
- // Scrolly:
- static char scrolly[478]=
- {
- _D,_O,_N,_K,_E,_Y,_S,_O,_F,_T,CLEAR,_M,_M,_X,_I,_I,CLEAR,
- _P,_R,_E,_S,_E,_N,_T,_S,CLEAR,_A,CLEAR,_L,_I,_T,_T,_L,_E,
- CLEAR,_R,_O,_U,_T,_I,_N,_E,CLEAR,_F,_O,_R,CLEAR,_T,_H,_E,
- CLEAR,_S,_I,_N,_C,_L,_A,_I,_R,CLEAR,_Z,_X,EIGHT,ONE,CLEAR,
- PLUS,CLEAR,ONE,SIX,_K,COMMA,CLEAR,_F,_A,_S,_T,CLEAR,
- _S,_C,_R,_O,_L,_L,_Y,CLEAR,_V,TWO,DOT,ZERO,DOT,THREE,COMMA,
- CLEAR,_W,_R,_I,_T,_T,_E,_N,CLEAR,_I,_N,CLEAR,_C,CLEAR,_A,_N,_D,
- CLEAR,_C,_O,_M,_P,_I,_L,_E,_D,CLEAR,_I,_N,CLEAR,_Z,EIGHT,EIGHT,
- _D,_K,CLEAR,DASH,CLEAR,_H,_T,_T,_P,COLON,SLASH,SLASH,_W,_W,_W,
- DOT,_Z,EIGHT,EIGHT,_D,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LEAR,_A,_N,_D,_Y,CLEAR,_R,_E,_A,COMMA,
- CLEAR,_S,_I,_M,_O,_N,CLEAR,_U,_L,_L,_Y,_A,_T,_T,CLEAR,_A,_N,_D,
- CLEAR,_E,_V,_E,_R,_Y,_O,_N,_E,CLEAR,_O,_N,CLEAR,_T,_H,_E,CLEAR,
- _R,_W,_A,_P,CLEAR,_F,_O,_R,_U,_M,_S,DOT,CLEAR,_B,_Y,_E,_Z,DOT
- };
- // Main function:
- void main()
- {
- // This is quite a nice way of waiting for a keyboard input
- // before dropping out of the programme and returning (in
- // this case) to BASIC.
- while(!(key=in_Inkey()))
- {
- // y should already be initialised to zero from start-up
- // see the global-scope variables above:
- if(y==0)
- {
- c=y;
- y=32;
- }
- // Prints at location 0,0 (top row):
- printat(SCRLOC(0,0));
- // If we're not past the first 32 characters of the scrolly
- // yet, we want to print out spaces and then start the
- // message so that it magically appears onto the screen:
- if(c<32)
- {
- // This will print the number of blanks needed (inversed):
- for(i=32; i>c; i--)
- {
- print(INVERSE(CLEAR));
- }
- x=i;
- // The remainder in x will then output the first characters
- // of the scrolly text message:
- for(i=0; i<x; i++)
- {
- print(INVERSE(scrolly[i]));
- }
- // Puts cursor at location 0,21 (bottom row) and we'll do the
- // same as above, but not inverse:
- printat(SCRLOC(0,21));
- for(i=32; i>c; i--)
- {
- print(CLEAR);
- }
- x=i;
- for(i=0; i<x; i++)
- {
- print(scrolly[i]);
- }
- // To slow down the text, use:
- // pause(12);
- // for instance. You'll also have to put a similar
- // pause below so that the the characters don't scroll
- // onto the screen slower than they do usually.
- }
- // Okay, so now we just want the characters in the scrolly text
- // to be displayed, but we have a 32-char off-set because of the
- // way that the logic works, as our counter will be 32 ahead
- // of where we need to be:
- else
- {
- // Because this is an else condition, we set printat(0,0)
- // above:
- for(i=0; i<y; i++)
- {
- print(INVERSE(scrolly[c+i-32]));
- }
- // Puts cursor at location 0,21 (bottom row):
- printat(SCRLOC(0,21));
- for(i=0; i<y; i++)
- {
- print(scrolly[c+i-32]);
- }
- }
- // This will print out up to 32 spaces after the scrolly text
- // so there's a total of 64 spaces between the beginning and
- // the end of the text:
- if(y<32)
- {
- // We need to set the cursor to y across and then the line
- // in which we'll output the characters:
- printat(SCRLOC(y,0));
- // Counts up to y:
- for(i=y; i<32; i++)
- {
- print(INVERSE(CLEAR));
- }
- // Same as above, but this time at the bottom of the screen
- // without inverse:
- printat(SCRLOC(y,21));
- for(i=y; i<32; i++)
- {
- print(CLEAR);
- }
- }
- // This will count to the end of the scrolly text: if we're at
- // the end, y will decrease to say how many spaces will be
- // padded out at the end:
- if(c>=478 && y>0)
- {
- y--;
- }
- // Increase our counter:
- c++;
- // Loops back around while there's been no key-press.
- }
- }
- // This will print out a char, which is pushed onto the stack:
- void print(short ch)
- {
- #asm
- EXX
- LD HL,$0002
- ADD HL,SP
- LD A,(HL)
- RST PRINT
- EXX
- #endasm
- }
- void printat(short xy)
- {
- #asm
- EXX
- LD HL,$0002
- ADD HL,SP
- LD B,(HL)
- INC L
- LD C,(HL)
- CALL PRINTAT
- EXX
- #endasm
- }
- void pause(char x)
- {
- while(x)
- {
- #asm
- NOP
- #endasm
- x--;
- }
- }
- // Compile with:
- // zcc +zx81 -startup=2 -create-app -DTEXT -o FS Scroller.c
- // (C) 2012 Donkeysoft
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement