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
21 ; ------------------------------------------------------------------------
22 ; Header. Includes jump table and constants.
24 module_header _nes_64_56_2_tgi
26 ; First part of the header is a structure that has a magic and defines the
27 ; capabilities of the driver
29 .byte $74, $67, $69 ; "tgi"
30 .byte TGI_API_VERSION ; TGI API version number
31 .addr $0000 ; Library reference
32 xres: .word charsperline*2 ; Max X resolution
33 yres: .word 56 ; Max Y resolution
34 .byte 2 ; Number of drawing colors
35 .byte 1 ; Number of screens available
36 .byte 2 ; System font X size
37 .byte 2 ; System font Y size
38 .word $0100 ; Aspect ratio
39 .byte 0 ; TGI driver flags
41 ; Next comes the jump table. Currently all entries must be valid and may point
42 ; to an RTS for test versions (function not implemented).
63 .addr 0 ; IRQ entry is unused
65 ; ------------------------------------------------------------------------
68 ; Variables mapped to the zero page segment variables. Some of these are
69 ; used for passing parameters to the driver.
83 ; Line routine stuff (must be on zpage)
86 ERR = regsave ; (2) LINE
87 NX = regsave+2 ; (2) LINE
89 ; Absolute variables used in the code
93 MEM: .res charsperline*2*56/4
95 ERROR: .res 1 ; Error code
96 COLOR: .res 1 ; Current color
97 PALETTE: .res 2 ; The current palette
110 ; Constants and tables
114 DEFPALETTE: .byte $0, $1
115 OFFSET: .byte 8, 4, 2, 1
116 ; 00 00 00 00 01 01 01 01
117 ; 00 01 10 11 00 01 10 11
118 CODE: .byte 32, 29, 26, 25, 28, 24+128, 31+128, 30+128
119 ; 10 10 10 10 11 11 11 11
120 ; 00 01 10 11 00 01 10 11
121 .byte 30, 31, 24, 28+128, 25+128, 26+128, 29+128, 32+128
125 ; ------------------------------------------------------------------------
126 ; INSTALL routine. Is called after the driver is loaded into memory. May
127 ; initialize anything that has to be done just once. Is probably empty
130 ; Must set an error code: NO
142 ; ------------------------------------------------------------------------
143 ; UNINSTALL routine. Is called before the driver is removed from memory. May
144 ; clean up anything done by INSTALL but is probably empty most of the time.
146 ; Must set an error code: NO
152 ; ------------------------------------------------------------------------
153 ; INIT: Changes an already installed device from text mode to graphics
155 ; Note that INIT/DONE may be called multiple times while the driver
156 ; is loaded, while INSTALL is only called once, so any code that is needed
157 ; to initializes variables and so on must go here. Setting palette and
158 ; clearing the screen is not needed because this is called by the graphics
160 ; The graphics kernel will never call INIT when a graphics mode is already
161 ; active, so there is no need to protect against that.
163 ; Must set an error code: YES
168 ; Done, reset the error code
174 ; ------------------------------------------------------------------------
175 ; DONE: Will be called to switch the graphics device back into text mode.
176 ; The graphics kernel will never call DONE when no graphics mode is active,
177 ; so there is no need to protect against that.
179 ; Must set an error code: NO
185 ; ------------------------------------------------------------------------
186 ; GETERROR: Return the error code in A and clear it.
194 ; ------------------------------------------------------------------------
195 ; CONTROL: Platform/driver specific entry point.
197 ; Must set an error code: YES
201 lda #TGI_ERR_INV_FUNC
205 ; ------------------------------------------------------------------------
206 ; CLEAR: Clears the screen.
208 ; Must set an error code: NO
227 ; ------------------------------------------------------------------------
228 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
229 ; to be in a valid range (0..maxcolor-1).
231 ; Must set an error code: NO (will only be called if color ok)
238 ; ------------------------------------------------------------------------
239 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
240 ; The page number is already checked to be valid by the graphics kernel.
242 ; Must set an error code: NO (will only be called if page ok)
247 ; ------------------------------------------------------------------------
248 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
249 ; The page number is already checked to be valid by the graphics kernel.
251 ; Must set an error code: NO (will only be called if page ok)
257 ; ------------------------------------------------------------------------
258 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
259 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
262 ; Must set an error code: YES
267 @wait: lda PPU_STATUS
293 ; ------------------------------------------------------------------------
294 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
295 ; set the palette should return the default palette here, so there's no
296 ; way for this function to fail.
298 ; Must set an error code: NO
306 ; ------------------------------------------------------------------------
307 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
308 ; drivers should return something reasonable here, even drivers that don't
309 ; support palettes, otherwise the caller has no way to determine the colors
310 ; of the (not changeable) palette.
312 ; Must set an error code: NO (all drivers must have a default palette)
320 ; ------------------------------------------------------------------------
321 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
322 ; color. The coordinates passed to this function are never outside the
323 ; visible screen area, so there is no need for clipping inside this function.
325 ; Must set an error code: NO
365 ; ------------------------------------------------------------------------
366 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
367 ; coordinates passed to this function are never outside the visible screen
368 ; area, so there is no need for clipping inside this function.
381 ; ------------------------------------------------------------------------
382 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
383 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
384 ; Contrary to most other functions, the graphics kernel will sort and clip
385 ; the coordinates before calling the driver, so on entry the following
386 ; conditions are valid:
389 ; (X1 >= 0) && (X1 < XRES)
390 ; (X2 >= 0) && (X2 < XRES)
391 ; (Y1 >= 0) && (Y1 < YRES)
392 ; (Y2 >= 0) && (Y2 < YRES)
394 ; Must set an error code: NO
414 ; ------------------------------------------------------------------------
415 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
416 ; direction is passend in X/Y, the text direction is passed in A.
418 ; Must set an error code: NO
424 ; ------------------------------------------------------------------------
425 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
426 ; current text style. The text to output is given as a zero terminated
427 ; string with address in ptr3.
429 ; Must set an error code: NO
449 ; ------------------------------------------------------------------------
450 ; Calculate all variables to plot the pixel at X1/Y1. If the point is out
451 ; of range, a carry is returned and INRANGE is set to a value !0 zero. If
452 ; the coordinates are valid, INRANGE is zero and the carry clear.
495 ; ------------------------------------------------------------------------
497 .include "../../tgi/tgidrv_line.inc"