Ti Constructor
 
Loading...
Searching...
No Matches
graphics.c File Reference

some useful graphics functions More...

Macros

Drawing settings
#define G_SCREEN_BUFFER   plotSScreen
 the temp ram where you draw to
 
#define G_COL_START   0x20
 
#define G_START_ROW   0x80
 
#define G_ROW_END   0xBF
 
#define G_MAX_ROW   12
 
#define G_BLOB_END   768
 
#define G_CLEAR_BUFFER_CO   48
 
#define buff   ( (char*)G_SCREEN_BUFFER )
 Use this like a variable for interacting with the screen buffer.
 
#define _LCD_BUSY_QUICK   0x000B
 function to call from ASM to wait required amount of time between screen calls
 
#define XMAX   96
 Width of screen in pixels.
 
#define YMAX   64
 Height of screen in pixels.
 

Functions

void clearBuffer ()
 clears screen buffer as defined by G_SCREEN_BUFFER If you wish to redefine the screen size you muse set multiple #defines before you include this file. You can find an example of this in examples/2048/main.c
 
void swap ()
 fast enough way to display SCREEN_BUFFER on lcd See the scoreboard in examples/2048/main.c for redefining the location of the screen
 
void line (char x, char y, char x2, char y2) __naked __z88dk_sdccdecl __z88dk_callee
 Draw a line between any 2 valid points.
 
void vertical_line (char x, char start, char height, char not_used) __naked
 Quick verticle line drawing routine.
 
void vertical_dotted_line (char x, char start, char height, char not_used) __naked
 Quick dotted verticle line drawing routine.
 
void ___GetPixel () __naked
 ASM Routine to get the memory location of a pixel based
 
void setPix (char x, char y) __naked __z88dk_callee __z88dk_sdccdecl
 Set a pixel on the screen.
 
void __drawCircleSegment (char xc, char yc, char x, char y)
 Do not call me.
 
void circle (char xc, char yc, char r)
 Circle drawing routine.
 

Detailed Description

some useful graphics functions

Optional #defines

Functions enables

  • G_SCREEN_BUFFER - allows you to redefine the location of the screen buffer. This is not recommended as the default is plotSScreen
  • G_COL_START - allows you to redefine where the screen starts drawing. Not recommended
  • G_START_ROW - allows you to redefine where the screen starts drawing. Not recommended
  • G_ROW_END - allows you to redefine where the screen stops drawing. Not recommended
  • G_MAX_ROW - allows you to redefine where the screen stops drawing. Not recommended
  • G_BLOB_END - allows you to redefine how large the screen buffer is. Could be cause errors if you redefine without changing G_CLEAR_BUFFER_CO
  • G_CLEAR_BUFFER_CO - allows you to redefine the math behind clearBuffer(). By default is set to 48 beacuse 48*8=384 times, @ 2 bytes a PUSH = 768 bytes
    • XMAX - Max x value. Not recommended. Requires changing a lot of defines
    • YMAX - Max y value. Not recommended. Requires changing a lot of defines

Function Documentation

◆ ___GetPixel()

void ___GetPixel ( )

ASM Routine to get the memory location of a pixel based

Parameters
[A]The x coord
[L]The y coord
Returns
HL = memory location & A = bitmask

Only call this from assembly Taken from https://taricorp.gitlab.io/83pa28d/lesson/week4/day24/index.html

◆ circle()

void circle ( char xc,
char yc,
char r )

Circle drawing routine.

Parameters
[xc]X coord of center of the circle
[yc]Y coord of center of the circle
[r]Radius of the circle

This code is quite slow as it is entirly written in c and uses the already quite slow setPix()

taken from https://www.geeksforgeeks.org/bresenhams-circle-drawing-algorithm/ and modified

◆ clearBuffer()

void clearBuffer ( )

clears screen buffer as defined by G_SCREEN_BUFFER If you wish to redefine the screen size you muse set multiple #defines before you include this file. You can find an example of this in examples/2048/main.c

Taken from https://taricorp.gitlab.io/83pa28d/lesson/day10.html

◆ line()

void line ( char x,
char y,
char x2,
char y2 )

Draw a line between any 2 valid points.

Parameters
[x]First x coord (between 0-XMAX)
[x]First y coord (between 0-YMAX)
[x2]Secound x coord (between 0-XMAX)
[y2]Secound y coord (between 0-YMAX)

Draws a line onto G_SCREEN_BUFFER between (x, y) and (x2, y2)

taken from https://wikiti.brandonw.net/index.php?title=Z80_Routines:Graphic:LineDraw and adapted for sdcc, should be quite fast

◆ setPix()

void setPix ( char x,
char y )

Set a pixel on the screen.

Parameters
[x]the x value to draw at (0-XMAX)
[y]the y value to draw at (0-YMAX)

This is a routine that works, but is overall not the most efficient way to draw on the screen.

◆ vertical_dotted_line()

void vertical_dotted_line ( char x,
char start,
char height,
char not_used )

Quick dotted verticle line drawing routine.

Parameters
[x]the x value to draw at (0-XMAX)
[start]the y value to start at (0-YMAX-1)
[height]How long the line should be (1-YMAX)
[not_used]Can be anything, this value is just discarded. Odd number byte params require more instructions than Even number params

Quickly draws a dotted verticle line onto G_SCREEN_BUFFER

◆ vertical_line()

void vertical_line ( char x,
char start,
char height,
char not_used )

Quick verticle line drawing routine.

Parameters
[x]the x value to draw at (0-XMAX)
[start]the y value to start at (0-YMAX-1)
[height]How long the line should be (1-YMAX)
[not_used]Can be anything, this value is just discarded. Odd number byte params require more instructions than Even number params

Quickly draws a verticle line onto G_SCREEN_BUFFER