Close

New Print Function

A project log for Merlin

68000 Retro Super Computer

Matthew PearceMatthew Pearce 07/12/2021 at 09:200 Comments

The EVE chip has a number of built in fonts. You can access them directly using the "cmd_text" command. I've added a new basic command in addition to the PRINT command - "GDPRINT"

You can specify the font (#16-31), cursor position and colour, plus a string to be displayed on the screen rather than the console.

5 CLS $FFFFFF: CLR                                                              
10 SIZE 16                                                                      
20 CURSOR 60,60                                                                 
30 GDPRINT"HELLO WORLD!"                                                        
35 GDSWAP                                                                       
40 PRINT"DONE"                                                                  
                                                                                

This produces black text in the top left of a white screen.

This was quite a fiddly change to make. The EVE text command needs a lot of parameters both strings and numbers - so I broke it down into multiple basic commands. Size & Cursor just add the data to the stack and GDPRINT sends everything to EVE. EhBasic interprets the line and gives you a pointer to the string and the length of the string. Passing them to 'C' means I need to cast the string pointer as a uintptr_t and then copy it to an initialised buffer.

LAB_GDPRINT

	MOVEM.L  A0-A2/D0-D7,-(A7)    * Save working registers

	BSR		LAB_EVEX			* evaluate expression
	BSR		LAB_GBYT			* scan memory
	BNE		LAB_SNER			* if not [EOL] or [EOS] do syntax error and
						* warm start

	MOVE.l	(a4)+,gfxText(a3)			* string address from descriptor stack
	MOVE.w	(a4)+,gfxTextLen(a3)			* string length from descriptor stack

	pea gfxTextLen(a3)
	pea gfxText(a3)
	pea lineColor(a3)
	pea lineSize(a3)
	pea y1(a3)
	pea x1(a3)
	jsr gd_text
	add #24,sp

	MOVEM.L  (A7)+,A0-A2/D0-D7    * Restore working registers

	rts
void gd_text(uint32_t *x, uint32_t *y, uint32_t *font, uint32_t *color, uint32_t *text, uint32_t *len)
{

    char string[256] = {0};
    uint8_t lenb = (uint8_t)((*len >> 16) & 0xff);
    uintptr_t ptr = (uintptr_t)*text;
    volatile char *buf = (char *)ptr;

    for (int i = 0; i < lenb; i++)
    {
        string[i] = *buf++;
    }

    GD.VertexFormat(0);
    GD.ColorRGB(*color);

    if (*font == 0 || *font < 16 || *font > 31)
        *font = 18;

    GD.cmd_text(*x, *y, *font, 0, string);
}

Next I'll need to add in a new command to set the text colour. I'll also reuse the 'MODE" command to switch between resolutions I think.

Discussions