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 xres: .word charsperline*2 ; Max X resolution
30 yres: .word 56 ; Max Y resolution
31 .byte 2 ; Number of drawing colors
32 .byte 1 ; Number of screens available
33 .byte 2 ; System font X size
34 .byte 2 ; System font Y size
35 .word $100 ; Aspect ratio
36 .byte 0 ; TGI driver flags
38 ; Next comes the jump table. Currently all entries must be valid and may point
39 ; to an RTS for test versions (function not implemented).
60 .addr 0 ; IRQ entry is unused
62 ; ------------------------------------------------------------------------
65 ; Variables mapped to the zero page segment variables. Some of these are
66 ; used for passing parameters to the driver.
80 ; Line routine stuff (must be on zpage)
83 ERR = regsave ; (2) LINE
84 NX = regsave+2 ; (2) LINE
86 ; Absolute variables used in the code
90 MEM: .res charsperline*2*56/4
92 ERROR: .res 1 ; Error code
93 COLOR: .res 1 ; Current color
94 PALETTE: .res 2 ; The current palette
107 ; Constants and tables
111 DEFPALETTE: .byte $0, $1
112 OFFSET: .byte 8, 4, 2, 1
113 ; 00 00 00 00 01 01 01 01
114 ; 00 01 10 11 00 01 10 11
115 CODE: .byte 32, 29, 26, 25, 28, 24+128, 31+128, 30+128
116 ; 10 10 10 10 11 11 11 11
117 ; 00 01 10 11 00 01 10 11
118 .byte 30, 31, 24, 28+128, 25+128, 26+128, 29+128, 32+128
122 ; ------------------------------------------------------------------------
123 ; INSTALL routine. Is called after the driver is loaded into memory. May
124 ; initialize anything that has to be done just once. Is probably empty
127 ; Must set an error code: NO
139 ; ------------------------------------------------------------------------
140 ; UNINSTALL routine. Is called before the driver is removed from memory. May
141 ; clean up anything done by INSTALL but is probably empty most of the time.
143 ; Must set an error code: NO
149 ; ------------------------------------------------------------------------
150 ; INIT: Changes an already installed device from text mode to graphics
152 ; Note that INIT/DONE may be called multiple times while the driver
153 ; is loaded, while INSTALL is only called once, so any code that is needed
154 ; to initializes variables and so on must go here. Setting palette and
155 ; clearing the screen is not needed because this is called by the graphics
157 ; The graphics kernel will never call INIT when a graphics mode is already
158 ; active, so there is no need to protect against that.
160 ; Must set an error code: YES
165 ; Done, reset the error code
171 ; ------------------------------------------------------------------------
172 ; DONE: Will be called to switch the graphics device back into text mode.
173 ; The graphics kernel will never call DONE when no graphics mode is active,
174 ; so there is no need to protect against that.
176 ; Must set an error code: NO
182 ; ------------------------------------------------------------------------
183 ; GETERROR: Return the error code in A and clear it.
191 ; ------------------------------------------------------------------------
192 ; CONTROL: Platform/driver specific entry point.
194 ; Must set an error code: YES
198 lda #TGI_ERR_INV_FUNC
202 ; ------------------------------------------------------------------------
203 ; CLEAR: Clears the screen.
205 ; Must set an error code: NO
224 ; ------------------------------------------------------------------------
225 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
226 ; to be in a valid range (0..maxcolor-1).
228 ; Must set an error code: NO (will only be called if color ok)
235 ; ------------------------------------------------------------------------
236 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
237 ; The page number is already checked to be valid by the graphics kernel.
239 ; Must set an error code: NO (will only be called if page ok)
244 ; ------------------------------------------------------------------------
245 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
246 ; The page number is already checked to be valid by the graphics kernel.
248 ; Must set an error code: NO (will only be called if page ok)
254 ; ------------------------------------------------------------------------
255 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
256 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
259 ; Must set an error code: YES
264 @wait: lda PPU_STATUS
290 ; ------------------------------------------------------------------------
291 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
292 ; set the palette should return the default palette here, so there's no
293 ; way for this function to fail.
295 ; Must set an error code: NO
303 ; ------------------------------------------------------------------------
304 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
305 ; drivers should return something reasonable here, even drivers that don't
306 ; support palettes, otherwise the caller has no way to determine the colors
307 ; of the (not changeable) palette.
309 ; Must set an error code: NO (all drivers must have a default palette)
317 ; ------------------------------------------------------------------------
318 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
319 ; color. The coordinates passed to this function are never outside the
320 ; visible screen area, so there is no need for clipping inside this function.
322 ; Must set an error code: NO
362 ; ------------------------------------------------------------------------
363 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
364 ; coordinates passed to this function are never outside the visible screen
365 ; area, so there is no need for clipping inside this function.
378 ; ------------------------------------------------------------------------
379 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
380 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
381 ; Contrary to most other functions, the graphics kernel will sort and clip
382 ; the coordinates before calling the driver, so on entry the following
383 ; conditions are valid:
386 ; (X1 >= 0) && (X1 < XRES)
387 ; (X2 >= 0) && (X2 < XRES)
388 ; (Y1 >= 0) && (Y1 < YRES)
389 ; (Y2 >= 0) && (Y2 < YRES)
391 ; Must set an error code: NO
411 ; ------------------------------------------------------------------------
412 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
413 ; direction is passend in X/Y, the text direction is passed in A.
415 ; Must set an error code: NO
421 ; ------------------------------------------------------------------------
422 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
423 ; current text style. The text to output is given as a zero terminated
424 ; string with address in ptr3.
426 ; Must set an error code: NO
446 ; ------------------------------------------------------------------------
447 ; Calculate all variables to plot the pixel at X1/Y1. If the point is out
448 ; of range, a carry is returned and INRANGE is set to a value !0 zero. If
449 ; the coordinates are valid, INRANGE is zero and the carry clear.
492 ; ------------------------------------------------------------------------
494 .include "../tgi/tgidrv_line.inc"