2 ; Graphics driver for the lores 64x56x2 mode on the NES
4 ; Stefan Haubenthal, 2009-03-10
5 ; Based on Maciej Witkowiak's line routine.
8 .include "zeropage.inc"
10 .include "tgi-kernel.inc"
11 .include "tgi-error.inc"
14 .import _clrscr, setcursor, putchar
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table and constants.
24 ; First part of the header is a structure that has a magic and defines the
25 ; capabilities of the driver
27 .byte $74, $67, $69 ; "tgi"
28 .byte TGI_API_VERSION ; TGI API version number
29 .addr $0000 ; Library reference
30 xres: .word charsperline*2 ; Max X resolution
31 yres: .word 56 ; Max Y resolution
32 .byte 2 ; Number of drawing colors
33 .byte 1 ; Number of screens available
34 .byte 2 ; System font X size
35 .byte 2 ; System font Y size
36 .word $0100 ; Aspect ratio
37 .byte 0 ; TGI driver flags
39 ; Next comes the jump table. Currently all entries must be valid and may point
40 ; to an RTS for test versions (function not implemented).
61 .addr 0 ; IRQ entry is unused
63 ; ------------------------------------------------------------------------
66 ; Variables mapped to the zero page segment variables. Some of these are
67 ; used for passing parameters to the driver.
81 ; Line routine stuff (must be on zpage)
84 ERR = regsave ; (2) LINE
85 NX = regsave+2 ; (2) LINE
87 ; Absolute variables used in the code
91 MEM: .res charsperline*2*56/4
93 ERROR: .res 1 ; Error code
94 COLOR: .res 1 ; Current color
95 PALETTE: .res 2 ; The current palette
108 ; Constants and tables
112 DEFPALETTE: .byte $0, $1
113 OFFSET: .byte 8, 4, 2, 1
114 ; 00 00 00 00 01 01 01 01
115 ; 00 01 10 11 00 01 10 11
116 CODE: .byte 32, 29, 26, 25, 28, 24+128, 31+128, 30+128
117 ; 10 10 10 10 11 11 11 11
118 ; 00 01 10 11 00 01 10 11
119 .byte 30, 31, 24, 28+128, 25+128, 26+128, 29+128, 32+128
123 ; ------------------------------------------------------------------------
124 ; INSTALL routine. Is called after the driver is loaded into memory. May
125 ; initialize anything that has to be done just once. Is probably empty
128 ; Must set an error code: NO
140 ; ------------------------------------------------------------------------
141 ; UNINSTALL routine. Is called before the driver is removed from memory. May
142 ; clean up anything done by INSTALL but is probably empty most of the time.
144 ; Must set an error code: NO
150 ; ------------------------------------------------------------------------
151 ; INIT: Changes an already installed device from text mode to graphics
153 ; Note that INIT/DONE may be called multiple times while the driver
154 ; is loaded, while INSTALL is only called once, so any code that is needed
155 ; to initializes variables and so on must go here. Setting palette and
156 ; clearing the screen is not needed because this is called by the graphics
158 ; The graphics kernel will never call INIT when a graphics mode is already
159 ; active, so there is no need to protect against that.
161 ; Must set an error code: YES
166 ; Done, reset the error code
172 ; ------------------------------------------------------------------------
173 ; DONE: Will be called to switch the graphics device back into text mode.
174 ; The graphics kernel will never call DONE when no graphics mode is active,
175 ; so there is no need to protect against that.
177 ; Must set an error code: NO
183 ; ------------------------------------------------------------------------
184 ; GETERROR: Return the error code in A and clear it.
192 ; ------------------------------------------------------------------------
193 ; CONTROL: Platform/driver specific entry point.
195 ; Must set an error code: YES
199 lda #TGI_ERR_INV_FUNC
203 ; ------------------------------------------------------------------------
204 ; CLEAR: Clears the screen.
206 ; Must set an error code: NO
225 ; ------------------------------------------------------------------------
226 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
227 ; to be in a valid range (0..maxcolor-1).
229 ; Must set an error code: NO (will only be called if color ok)
236 ; ------------------------------------------------------------------------
237 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
238 ; The page number is already checked to be valid by the graphics kernel.
240 ; Must set an error code: NO (will only be called if page ok)
245 ; ------------------------------------------------------------------------
246 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
247 ; The page number is already checked to be valid by the graphics kernel.
249 ; Must set an error code: NO (will only be called if page ok)
255 ; ------------------------------------------------------------------------
256 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
257 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
260 ; Must set an error code: YES
265 @wait: lda PPU_STATUS
291 ; ------------------------------------------------------------------------
292 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
293 ; set the palette should return the default palette here, so there's no
294 ; way for this function to fail.
296 ; Must set an error code: NO
304 ; ------------------------------------------------------------------------
305 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
306 ; drivers should return something reasonable here, even drivers that don't
307 ; support palettes, otherwise the caller has no way to determine the colors
308 ; of the (not changeable) palette.
310 ; Must set an error code: NO (all drivers must have a default palette)
318 ; ------------------------------------------------------------------------
319 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
320 ; color. The coordinates passed to this function are never outside the
321 ; visible screen area, so there is no need for clipping inside this function.
323 ; Must set an error code: NO
363 ; ------------------------------------------------------------------------
364 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
365 ; coordinates passed to this function are never outside the visible screen
366 ; area, so there is no need for clipping inside this function.
379 ; ------------------------------------------------------------------------
380 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
381 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
382 ; Contrary to most other functions, the graphics kernel will sort and clip
383 ; the coordinates before calling the driver, so on entry the following
384 ; conditions are valid:
387 ; (X1 >= 0) && (X1 < XRES)
388 ; (X2 >= 0) && (X2 < XRES)
389 ; (Y1 >= 0) && (Y1 < YRES)
390 ; (Y2 >= 0) && (Y2 < YRES)
392 ; Must set an error code: NO
412 ; ------------------------------------------------------------------------
413 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
414 ; direction is passend in X/Y, the text direction is passed in A.
416 ; Must set an error code: NO
422 ; ------------------------------------------------------------------------
423 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
424 ; current text style. The text to output is given as a zero terminated
425 ; string with address in ptr3.
427 ; Must set an error code: NO
447 ; ------------------------------------------------------------------------
448 ; Calculate all variables to plot the pixel at X1/Y1. If the point is out
449 ; of range, a carry is returned and INRANGE is set to a value !0 zero. If
450 ; the coordinates are valid, INRANGE is zero and the carry clear.
493 ; ------------------------------------------------------------------------
495 .include "../../tgi/tgidrv_line.inc"