EasyManua.ls Logo

Mega 65 - Page 95

Mega 65
101 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
MEGA65 Welcome Guide
14.2.2 Newer graphics commands
CUT, GCOPY, PASTE act on a rectangle of a graphics screen as a clipboard. GCOPY copies a rectangle of pixels to a
buffer; CUT copies the rectangle then fills with the color of the pen. PASTE paints the previously copied rectangle onto
the screen at a given location. An example from the manual:
10 SCREEN 320,200,2
20 BOX 60,60,300,180,1
30 PEN 2
40 CUT 140,80,40,40
50 PASTE 10,10,40,40
60 GETKEY A$
70 SCREEN CLOSE
DOT draws a single pixel on a graphics screen.
10 SCREEN 320,200,5
20 DOT 100, 80, 7
30 GETKEY A$
40 SCREEN CLOSE
CHARDEF changes the image for a single character based on its arguments. This makes it easy to produce custom fonts
or character graphics in a BASIC program.
To replace the letter A with a happy face:
CHARDEF 1,$3C,$7E,$DB,$FF,$BD,$C3,$7E,$3C
To restore the PETSCII font: FONT C
VSYNC <n> waits until screen drawing reaches raster line n. This is useful for games and graphical demos that need
code to run once per frame for smooth animation or effects. This was once only possible with machine language
programs, but MEGA65 in 40 MHz mode runs BASIC quickly enough for high speed games.
10 BORDER 0: VSYNC 150: BORDER 1: VSYNC 180: GOTO 10
14.2.3 Newer memory commands
MEM reserves 8K segments of memory in banks 4 and 5 for use by the program, such that the graphics library does not
use them.
To reserve $40000-$41FFF for program use: MEM 1,0
SETBIT and CLRBIT set and clear a given bit at a given byte memory location. Bit numbers are 0-7 from least significant
to most significant.
Given address $03FFF containing the bit pattern 00110111 ($37), to set bit 6 so it becomes 0110111 ($77):
SETBIT $03FFF, 6
WPOKE and WPEEK() write and read, respectively, a 16-bit (“word”) value at two consecutive locations in memory, least
significant byte first.
To store the word $FABC across byte addresses $0C000 (the least significant byte $BC) and $0C001 (the most
significant byte $FA): BANK 0 : WPOKE $C000,$FABC
To read the 16-bit value stored at $0C000-$0C001: V = WPEEK($C000)
14.2. New BASIC commands 91

Table of Contents