2003-12-09 20:46:38 +00:00
|
|
|
;
|
2008-03-16 09:37:22 +00:00
|
|
|
; Graphics driver for the 40x48x16 mode on the Apple II
|
2003-12-09 20:46:38 +00:00
|
|
|
;
|
|
|
|
; Stefan Haubenthal <polluks@sdf.lonestar.org>
|
2008-03-16 09:37:22 +00:00
|
|
|
; Oliver Schmidt <ol.sc@web.de>
|
2003-12-09 20:46:38 +00:00
|
|
|
; Based on Maciej Witkowiak's line and circle routine
|
|
|
|
;
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
|
|
|
|
.include "tgi-kernel.inc"
|
|
|
|
.include "tgi-mode.inc"
|
|
|
|
.include "tgi-error.inc"
|
|
|
|
.include "apple2.inc"
|
|
|
|
|
|
|
|
.macpack generic
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Zero page stuff
|
|
|
|
|
|
|
|
H2 := $2C
|
2004-06-03 15:05:41 +00:00
|
|
|
|
|
|
|
; ROM entry points
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
TEXT := $F399
|
|
|
|
PLOT := $F800
|
|
|
|
HLINE := $F819
|
|
|
|
CLRSCR := $F832
|
|
|
|
SETCOL := $F864
|
|
|
|
SCRN := $F871
|
|
|
|
SETGR := $FB40
|
|
|
|
HOME := $FC58
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
; Variables mapped to the zero page segment variables. Some of these are
|
|
|
|
; used for passing parameters to the driver.
|
|
|
|
|
|
|
|
X1 := ptr1
|
|
|
|
Y1 := ptr2
|
|
|
|
X2 := ptr3
|
|
|
|
Y2 := ptr4
|
|
|
|
RADIUS := tmp1
|
|
|
|
|
|
|
|
ADDR := tmp1
|
|
|
|
TEMP := tmp3
|
|
|
|
TEMP2 := tmp4
|
|
|
|
TEMP3 := sreg
|
|
|
|
TEMP4 := sreg+1
|
|
|
|
|
|
|
|
; Line routine stuff (must be on zpage)
|
|
|
|
|
|
|
|
PB := ptr3 ; (2) LINE
|
|
|
|
UB := ptr4 ; (2) LINE
|
|
|
|
ERR := regsave ; (2) LINE
|
|
|
|
NX := regsave+2 ; (2) LINE
|
|
|
|
|
|
|
|
; Circle routine stuff (must be on zpage)
|
|
|
|
|
|
|
|
XX := ptr3 ; (2) CIRCLE
|
|
|
|
YY := ptr4 ; (2) CIRCLE
|
|
|
|
MaxO := sreg ; (overwritten by TEMP3+TEMP4, but restored from OG/OU anyway)
|
|
|
|
XS := regsave ; (2) CIRCLE
|
|
|
|
YS := regsave+2 ; (2) CIRCLE
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
.segment "JUMPTABLE"
|
|
|
|
|
|
|
|
; Header. Includes jump table and constants.
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; First part of the header is a structure that has a magic and defines the
|
|
|
|
; capabilities of the driver
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
.byte $74, $67, $69 ; "tgi"
|
|
|
|
.byte TGI_API_VERSION ; TGI API version number
|
|
|
|
xres: .word 40 ; X resolution
|
|
|
|
yres: .word 48 ; Y resolution
|
|
|
|
.byte 16 ; Number of drawing colors
|
|
|
|
.byte 1 ; Number of screens available
|
|
|
|
.byte 8 ; System font X size
|
|
|
|
.byte 8 ; System font Y size
|
|
|
|
.res 4, $00 ; Reserved for future extensions
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; Next comes the jump table. Currently all entries must be valid and may point
|
|
|
|
; to an RTS for test versions (function not implemented).
|
|
|
|
|
2004-11-07 11:33:08 +00:00
|
|
|
.addr INSTALL
|
|
|
|
.addr UNINSTALL
|
|
|
|
.addr INIT
|
|
|
|
.addr DONE
|
|
|
|
.addr GETERROR
|
|
|
|
.addr CONTROL
|
|
|
|
.addr CLEAR
|
|
|
|
.addr SETVIEWPAGE
|
|
|
|
.addr SETDRAWPAGE
|
|
|
|
.addr SETCOLOR
|
|
|
|
.addr SETPALETTE
|
|
|
|
.addr GETPALETTE
|
|
|
|
.addr GETDEFPALETTE
|
|
|
|
.addr SETPIXEL
|
|
|
|
.addr GETPIXEL
|
|
|
|
.addr LINE
|
|
|
|
.addr BAR
|
|
|
|
.addr CIRCLE
|
|
|
|
.addr TEXTSTYLE
|
|
|
|
.addr OUTTEXT
|
2008-03-16 09:37:22 +00:00
|
|
|
.addr 0 ; IRQ entry is unused
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
.bss
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; Absolute variables used in the code
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
ERROR: .res 1 ; Error code
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Line routine stuff (combined with circle routine stuff to save space)
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
OGora:
|
2008-03-16 09:37:22 +00:00
|
|
|
COUNT: .res 2
|
2003-12-09 20:46:38 +00:00
|
|
|
OUkos:
|
2008-03-16 09:37:22 +00:00
|
|
|
NY: .res 2
|
2003-12-09 20:46:38 +00:00
|
|
|
Y3:
|
2008-03-16 09:37:22 +00:00
|
|
|
DX: .res 1
|
|
|
|
DY: .res 1
|
|
|
|
AX: .res 1
|
|
|
|
AY: .res 1
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
.rodata
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Constants and tables
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
|
|
|
|
.byte $08, $09, $0A, $0B, $0C, $0D, $0E, $0F
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; ------------------------------------------------------------------------
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
.code
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; INIT: Changes an already installed device from text mode to graphics mode.
|
2003-12-09 20:46:38 +00:00
|
|
|
; Note that INIT/DONE may be called multiple times while the driver
|
|
|
|
; is loaded, while INSTALL is only called once, so any code that is needed
|
|
|
|
; to initializes variables and so on must go here. Setting palette and
|
|
|
|
; clearing the screen is not needed because this is called by the graphics
|
|
|
|
; kernel later.
|
|
|
|
; The graphics kernel will never call INIT when a graphics mode is already
|
|
|
|
; active, so there is no need to protect against that.
|
|
|
|
; Must set an error code: YES
|
|
|
|
INIT:
|
2008-03-16 09:37:22 +00:00
|
|
|
; Switch into graphics mode
|
|
|
|
bit $C082 ; Switch in ROM
|
2003-12-09 20:46:38 +00:00
|
|
|
jsr SETGR
|
2008-03-16 09:37:22 +00:00
|
|
|
bit MIXCLR
|
|
|
|
bit $C080 ; Switch in LC bank 2 for R/O
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Done, reset the error code
|
2003-12-09 20:46:38 +00:00
|
|
|
lda #TGI_ERR_OK
|
|
|
|
sta ERROR
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; Fall through
|
|
|
|
|
|
|
|
; INSTALL routine. Is called after the driver is loaded into memory. May
|
|
|
|
; initialize anything that has to be done just once. Is probably empty
|
|
|
|
; most of the time.
|
|
|
|
; Must set an error code: NO
|
|
|
|
INSTALL:
|
|
|
|
; Fall through
|
|
|
|
|
|
|
|
; UNINSTALL routine. Is called before the driver is removed from memory. May
|
|
|
|
; clean up anything done by INSTALL but is probably empty most of the time.
|
|
|
|
; Must set an error code: NO
|
|
|
|
UNINSTALL:
|
|
|
|
; Fall through
|
|
|
|
|
|
|
|
; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
|
|
|
|
; The page number is already checked to be valid by the graphics kernel.
|
|
|
|
; Must set an error code: NO (will only be called if page ok)
|
|
|
|
SETVIEWPAGE:
|
|
|
|
; Fall through
|
|
|
|
|
|
|
|
; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
|
|
|
|
; The page number is already checked to be valid by the graphics kernel.
|
|
|
|
; Must set an error code: NO (will only be called if page ok)
|
|
|
|
SETDRAWPAGE:
|
|
|
|
; Fall through
|
|
|
|
|
|
|
|
; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
|
|
|
|
; direction is passend in X/Y, the text direction is passed in A.
|
|
|
|
; Must set an error code: NO
|
|
|
|
TEXTSTYLE:
|
|
|
|
; Fall through
|
|
|
|
|
|
|
|
; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
|
|
|
|
; current text style. The text to output is given as a zero terminated
|
|
|
|
; string with address in ptr3.
|
|
|
|
; Must set an error code: NO
|
|
|
|
OUTTEXT:
|
2003-12-09 20:46:38 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; DONE: Will be called to switch the graphics device back into text mode.
|
|
|
|
; The graphics kernel will never call DONE when no graphics mode is active,
|
|
|
|
; so there is no need to protect against that.
|
|
|
|
; Must set an error code: NO
|
2008-03-16 09:37:22 +00:00
|
|
|
DONE:
|
|
|
|
bit $C082 ; Switch in ROM
|
|
|
|
jsr TEXT
|
|
|
|
jsr HOME
|
|
|
|
bit $C080 ; Switch in LC bank 2 for R/O
|
|
|
|
rts
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; GETERROR: Return the error code in A and clear it.
|
|
|
|
GETERROR:
|
|
|
|
lda ERROR
|
2008-03-16 09:37:22 +00:00
|
|
|
ldx #TGI_ERR_OK
|
2003-12-09 20:46:38 +00:00
|
|
|
stx ERROR
|
|
|
|
rts
|
|
|
|
|
|
|
|
; CLEAR: Clears the screen.
|
|
|
|
; Must set an error code: NO
|
2008-03-16 09:37:22 +00:00
|
|
|
CLEAR:
|
|
|
|
bit $C082 ; Switch in ROM
|
|
|
|
jsr CLRSCR
|
|
|
|
bit $C080 ; Switch in LC bank 2 for R/O
|
2003-12-09 20:46:38 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; SETCOLOR: Set the drawing color (in A). The new color is already checked
|
|
|
|
; to be in a valid range (0..maxcolor-1).
|
|
|
|
; Must set an error code: NO (will only be called if color ok)
|
2008-03-16 09:37:22 +00:00
|
|
|
SETCOLOR:
|
|
|
|
bit $C082 ; Switch in ROM
|
|
|
|
jsr SETCOL
|
|
|
|
bit $C080 ; Switch in LC bank 2 for R/O
|
|
|
|
rts
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; CONTROL: Platform/driver specific entry point.
|
|
|
|
; Must set an error code: YES
|
|
|
|
CONTROL:
|
|
|
|
; Fall through
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; SETPALETTE: Set the palette (not available with all drivers/hardware).
|
|
|
|
; A pointer to the palette is passed in ptr1. Must set an error if palettes
|
|
|
|
; are not supported
|
|
|
|
; Must set an error code: YES
|
|
|
|
SETPALETTE:
|
|
|
|
lda #TGI_ERR_INV_FUNC
|
|
|
|
sta ERROR
|
|
|
|
rts
|
|
|
|
|
|
|
|
; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
|
|
|
|
; set the palette should return the default palette here, so there's no
|
|
|
|
; way for this function to fail.
|
|
|
|
; Must set an error code: NO
|
|
|
|
GETPALETTE:
|
2008-03-16 09:37:22 +00:00
|
|
|
; Fall through
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; GETDEFPALETTE: Return the default palette for the driver in A/X. All
|
|
|
|
; drivers should return something reasonable here, even drivers that don't
|
|
|
|
; support palettes, otherwise the caller has no way to determine the colors
|
|
|
|
; of the (not changeable) palette.
|
|
|
|
; Must set an error code: NO (all drivers must have a default palette)
|
|
|
|
GETDEFPALETTE:
|
|
|
|
lda #<DEFPALETTE
|
|
|
|
ldx #>DEFPALETTE
|
|
|
|
rts
|
|
|
|
|
|
|
|
; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
|
|
|
|
; color. The coordinates passed to this function are never outside the
|
|
|
|
; visible screen area, so there is no need for clipping inside this function.
|
|
|
|
; Must set an error code: NO
|
2008-03-16 09:37:22 +00:00
|
|
|
SETPIXEL:
|
|
|
|
bit $C082 ; Switch in ROM
|
|
|
|
ldy X1
|
|
|
|
lda Y1
|
|
|
|
jsr PLOT
|
|
|
|
bit $C080 ; Switch in LC bank 2 for R/O
|
|
|
|
rts
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
SETPIXELCLIP:
|
|
|
|
lda Y1+1
|
2008-03-16 09:37:22 +00:00
|
|
|
bmi :+ ; y < 0
|
2003-12-09 20:46:38 +00:00
|
|
|
lda X1+1
|
2008-03-16 09:37:22 +00:00
|
|
|
bmi :+ ; x < 0
|
2003-12-09 20:46:38 +00:00
|
|
|
lda X1
|
|
|
|
ldx X1+1
|
|
|
|
sta ADDR
|
|
|
|
stx ADDR+1
|
|
|
|
ldx #ADDR
|
|
|
|
lda xres
|
|
|
|
ldy xres+1
|
|
|
|
jsr icmp ; ( x < xres ) ...
|
2008-03-16 09:37:22 +00:00
|
|
|
bcs :+
|
2003-12-09 20:46:38 +00:00
|
|
|
lda Y1
|
|
|
|
ldx Y1+1
|
|
|
|
sta ADDR
|
|
|
|
stx ADDR+1
|
|
|
|
ldx #ADDR
|
|
|
|
lda yres
|
|
|
|
ldy yres+1
|
|
|
|
jsr icmp ; ... && ( y < yres )
|
|
|
|
bcc SETPIXEL
|
2008-03-16 09:37:22 +00:00
|
|
|
: rts
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; GETPIXEL: Read the color value of a pixel and return it in A/X. The
|
|
|
|
; coordinates passed to this function are never outside the visible screen
|
|
|
|
; area, so there is no need for clipping inside this function.
|
|
|
|
GETPIXEL:
|
2008-03-16 09:37:22 +00:00
|
|
|
bit $C082 ; Switch in ROM
|
|
|
|
ldy X1
|
|
|
|
lda Y1
|
2003-12-09 20:46:38 +00:00
|
|
|
jsr SCRN
|
2004-03-11 21:54:22 +00:00
|
|
|
ldx #$00
|
2008-03-16 09:37:22 +00:00
|
|
|
bit $C080 ; Switch in LC bank 2 for R/O
|
2003-12-09 20:46:38 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
|
|
|
|
; X2/Y2 = ptr3/ptr4 using the current drawing color.
|
|
|
|
; Must set an error code: NO
|
|
|
|
LINE:
|
2008-03-16 09:37:22 +00:00
|
|
|
; nx = abs (x2 - x1)
|
2003-12-09 20:46:38 +00:00
|
|
|
lda X2
|
|
|
|
sub X1
|
|
|
|
sta NX
|
|
|
|
lda X2+1
|
|
|
|
sbc X1+1
|
|
|
|
tay
|
|
|
|
lda NX
|
|
|
|
jsr abs
|
|
|
|
sta NX
|
|
|
|
sty NX+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; ny = abs (y2 - y1)
|
2003-12-09 20:46:38 +00:00
|
|
|
lda Y2
|
|
|
|
sub Y1
|
|
|
|
sta NY
|
|
|
|
lda Y2+1
|
|
|
|
sbc Y1+1
|
|
|
|
tay
|
|
|
|
lda NY
|
|
|
|
jsr abs
|
|
|
|
sta NY
|
|
|
|
sty NY+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; if (x2 >= x1)
|
2003-12-09 20:46:38 +00:00
|
|
|
ldx #X2
|
|
|
|
lda X1
|
|
|
|
ldy X1+1
|
|
|
|
jsr icmp
|
2008-03-16 09:37:22 +00:00
|
|
|
bcc :+
|
|
|
|
|
|
|
|
; dx = 1
|
2004-03-11 21:54:22 +00:00
|
|
|
lda #$01
|
2008-03-16 09:37:22 +00:00
|
|
|
bne :++
|
|
|
|
|
2003-12-09 20:46:38 +00:00
|
|
|
; else
|
2008-03-16 09:37:22 +00:00
|
|
|
; dx = -1
|
|
|
|
: lda #$FF
|
|
|
|
: sta DX
|
|
|
|
|
|
|
|
; if (y2 >= y1)
|
2003-12-09 20:46:38 +00:00
|
|
|
ldx #Y2
|
|
|
|
lda Y1
|
|
|
|
ldy Y1+1
|
|
|
|
jsr icmp
|
2008-03-16 09:37:22 +00:00
|
|
|
bcc :+
|
|
|
|
|
|
|
|
; dy = 1
|
2004-03-11 21:54:22 +00:00
|
|
|
lda #$01
|
2008-03-16 09:37:22 +00:00
|
|
|
bne :++
|
|
|
|
|
2003-12-09 20:46:38 +00:00
|
|
|
; else
|
2008-03-16 09:37:22 +00:00
|
|
|
; dy = -1
|
|
|
|
: lda #$FF
|
|
|
|
: sta DY
|
|
|
|
|
|
|
|
; err = ax = ay = 0
|
2004-03-11 21:54:22 +00:00
|
|
|
lda #$00
|
2003-12-09 20:46:38 +00:00
|
|
|
sta ERR
|
|
|
|
sta ERR+1
|
2008-03-16 09:37:22 +00:00
|
|
|
sta AX
|
2003-12-09 20:46:38 +00:00
|
|
|
sta AY
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; if (nx < ny) {
|
2003-12-09 20:46:38 +00:00
|
|
|
ldx #NX
|
|
|
|
lda NY
|
|
|
|
ldy NY+1
|
|
|
|
jsr icmp
|
2008-03-16 09:37:22 +00:00
|
|
|
bcs :+
|
|
|
|
|
|
|
|
; nx <-> ny
|
2003-12-09 20:46:38 +00:00
|
|
|
lda NX
|
|
|
|
ldx NY
|
|
|
|
sta NY
|
|
|
|
stx NX
|
|
|
|
lda NX+1
|
|
|
|
ldx NY+1
|
|
|
|
sta NY+1
|
|
|
|
stx NX+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; ax = dx
|
2003-12-09 20:46:38 +00:00
|
|
|
lda DX
|
2008-03-16 09:37:22 +00:00
|
|
|
sta AX
|
|
|
|
|
|
|
|
; ay = dy
|
|
|
|
lda DY
|
2003-12-09 20:46:38 +00:00
|
|
|
sta AY
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; dx = dy = 0 }
|
2004-03-11 21:54:22 +00:00
|
|
|
lda #$00
|
2003-12-09 20:46:38 +00:00
|
|
|
sta DX
|
|
|
|
sta DY
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; ny = - ny
|
|
|
|
: lda NY
|
2003-12-09 20:46:38 +00:00
|
|
|
ldy NY+1
|
|
|
|
jsr neg
|
|
|
|
sta NY
|
|
|
|
sty NY+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; for (count = nx; count > 0; --count) {
|
2003-12-09 20:46:38 +00:00
|
|
|
lda NX
|
|
|
|
ldx NX+1
|
|
|
|
sta COUNT
|
|
|
|
stx COUNT+1
|
2008-03-16 09:37:22 +00:00
|
|
|
for: lda COUNT ; count > 0
|
2003-12-09 20:46:38 +00:00
|
|
|
ora COUNT+1
|
2008-03-16 09:37:22 +00:00
|
|
|
bne :+
|
2003-12-09 20:46:38 +00:00
|
|
|
rts
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; setpixel (X1, Y1)
|
|
|
|
: jsr SETPIXELCLIP
|
|
|
|
|
2003-12-09 20:46:38 +00:00
|
|
|
; pb = err + ny
|
|
|
|
lda ERR
|
|
|
|
add NY
|
|
|
|
sta PB
|
|
|
|
lda ERR+1
|
|
|
|
adc NY+1
|
|
|
|
sta PB+1
|
|
|
|
tax
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2003-12-09 20:46:38 +00:00
|
|
|
; ub = pb + nx
|
|
|
|
lda PB
|
|
|
|
add NX
|
|
|
|
sta UB
|
|
|
|
txa
|
|
|
|
adc NX+1
|
|
|
|
sta UB+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2003-12-09 20:46:38 +00:00
|
|
|
; x1 = x1 + dx
|
2004-03-11 21:54:22 +00:00
|
|
|
ldx #$00
|
2003-12-09 20:46:38 +00:00
|
|
|
lda DX
|
2008-03-16 09:37:22 +00:00
|
|
|
bpl :+
|
2003-12-09 20:46:38 +00:00
|
|
|
dex
|
2008-03-16 09:37:22 +00:00
|
|
|
: add X1
|
2003-12-09 20:46:38 +00:00
|
|
|
sta X1
|
|
|
|
txa
|
|
|
|
adc X1+1
|
|
|
|
sta X1+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; y1 = y1 + ay
|
2004-03-11 21:54:22 +00:00
|
|
|
ldx #$00
|
2003-12-09 20:46:38 +00:00
|
|
|
lda AY
|
2008-03-16 09:37:22 +00:00
|
|
|
bpl :+
|
2003-12-09 20:46:38 +00:00
|
|
|
dex
|
2008-03-16 09:37:22 +00:00
|
|
|
: add Y1
|
2003-12-09 20:46:38 +00:00
|
|
|
sta Y1
|
|
|
|
txa
|
|
|
|
adc Y1+1
|
|
|
|
sta Y1+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; if (abs (pb) < abs (ub)) {
|
2003-12-09 20:46:38 +00:00
|
|
|
lda PB
|
|
|
|
ldy PB+1
|
|
|
|
jsr abs
|
|
|
|
sta TEMP3
|
|
|
|
sty TEMP4
|
|
|
|
lda UB
|
|
|
|
ldy UB+1
|
|
|
|
jsr abs
|
|
|
|
ldx #TEMP3
|
|
|
|
jsr icmp
|
2008-03-16 09:37:22 +00:00
|
|
|
bpl :+
|
|
|
|
|
|
|
|
; err = pb }
|
2003-12-09 20:46:38 +00:00
|
|
|
lda PB
|
|
|
|
ldx PB+1
|
2008-03-16 09:37:22 +00:00
|
|
|
jmp next
|
|
|
|
|
|
|
|
; else { x1 = x1 + ax
|
|
|
|
: ldx #$00
|
|
|
|
lda AX
|
|
|
|
bpl :+
|
2003-12-09 20:46:38 +00:00
|
|
|
dex
|
2008-03-16 09:37:22 +00:00
|
|
|
: add X1
|
2003-12-09 20:46:38 +00:00
|
|
|
sta X1
|
|
|
|
txa
|
|
|
|
adc X1+1
|
|
|
|
sta X1+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; y1 = y1 + dy
|
2004-03-11 21:54:22 +00:00
|
|
|
ldx #$00
|
2003-12-09 20:46:38 +00:00
|
|
|
lda DY
|
2008-03-16 09:37:22 +00:00
|
|
|
bpl :+
|
2003-12-09 20:46:38 +00:00
|
|
|
dex
|
2008-03-16 09:37:22 +00:00
|
|
|
: add Y1
|
2003-12-09 20:46:38 +00:00
|
|
|
sta Y1
|
|
|
|
txa
|
|
|
|
adc Y1+1
|
|
|
|
sta Y1+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2003-12-09 20:46:38 +00:00
|
|
|
; err = ub }
|
|
|
|
lda UB
|
|
|
|
ldx UB+1
|
2008-03-16 09:37:22 +00:00
|
|
|
next: sta ERR
|
2003-12-09 20:46:38 +00:00
|
|
|
stx ERR+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2003-12-09 20:46:38 +00:00
|
|
|
; } (--count)
|
|
|
|
lda COUNT
|
2008-03-16 09:37:22 +00:00
|
|
|
sub #$01
|
2003-12-09 20:46:38 +00:00
|
|
|
sta COUNT
|
2008-03-16 09:37:22 +00:00
|
|
|
bcc :+
|
|
|
|
jmp for
|
|
|
|
: dec COUNT+1
|
|
|
|
jmp for
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
|
|
|
|
; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
|
|
|
|
; Contrary to most other functions, the graphics kernel will sort and clip
|
|
|
|
; the coordinates before calling the driver, so on entry the following
|
|
|
|
; conditions are valid:
|
|
|
|
; X1 <= X2
|
|
|
|
; Y1 <= Y2
|
|
|
|
; (X1 >= 0) && (X1 < XRES)
|
|
|
|
; (X2 >= 0) && (X2 < XRES)
|
|
|
|
; (Y1 >= 0) && (Y1 < YRES)
|
|
|
|
; (Y2 >= 0) && (Y2 < YRES)
|
|
|
|
; Must set an error code: NO
|
|
|
|
BAR:
|
2008-03-16 09:37:22 +00:00
|
|
|
bit $C082 ; Switch in ROM
|
2003-12-09 20:46:38 +00:00
|
|
|
inc Y2
|
|
|
|
ldx X2
|
|
|
|
stx H2
|
2008-03-16 09:37:22 +00:00
|
|
|
: ldy X1
|
2003-12-09 20:46:38 +00:00
|
|
|
lda Y1
|
|
|
|
jsr HLINE
|
|
|
|
inc Y1
|
|
|
|
lda Y2
|
|
|
|
cmp Y1
|
2008-03-16 09:37:22 +00:00
|
|
|
bne :-
|
|
|
|
bit $C080 ; Switch in LC bank 2 for R/O
|
2003-12-09 20:46:38 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the
|
|
|
|
; radius in tmp1 and the current drawing color.
|
|
|
|
; Must set an error code: NO
|
|
|
|
CIRCLE:
|
|
|
|
lda RADIUS
|
2008-03-16 09:37:22 +00:00
|
|
|
bne :+
|
2003-12-09 20:46:38 +00:00
|
|
|
jmp SETPIXELCLIP ; Plot as a point
|
2008-03-16 09:37:22 +00:00
|
|
|
: sta XX
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; x = r
|
2004-03-11 21:54:22 +00:00
|
|
|
lda #$00
|
2003-12-09 20:46:38 +00:00
|
|
|
sta XX+1
|
|
|
|
sta YY
|
|
|
|
sta YY+1
|
|
|
|
sta MaxO
|
|
|
|
sta MaxO+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; y = 0, mo = 0
|
2003-12-09 20:46:38 +00:00
|
|
|
lda X1
|
|
|
|
ldx X1+1
|
|
|
|
sta XS
|
|
|
|
stx XS+1
|
|
|
|
lda Y1
|
|
|
|
ldx Y1+1
|
|
|
|
sta YS
|
|
|
|
stx YS+1 ; XS/YS to remember the center
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; while (y < x) {
|
|
|
|
while: ldx #YY
|
2003-12-09 20:46:38 +00:00
|
|
|
lda XX
|
|
|
|
ldy XX+1
|
|
|
|
jsr icmp
|
2008-03-16 09:37:22 +00:00
|
|
|
bcc :+
|
2003-12-09 20:46:38 +00:00
|
|
|
rts
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; Plot points in 8 slices...
|
|
|
|
: lda XS
|
2003-12-09 20:46:38 +00:00
|
|
|
add XX
|
|
|
|
sta X1
|
|
|
|
lda XS+1
|
|
|
|
adc XX+1
|
2008-03-16 09:37:22 +00:00
|
|
|
sta X1+1 ; x1 = xs + x
|
2003-12-09 20:46:38 +00:00
|
|
|
lda YS
|
|
|
|
add YY
|
|
|
|
sta Y1
|
|
|
|
pha
|
|
|
|
lda YS+1
|
|
|
|
adc YY+1
|
2008-03-16 09:37:22 +00:00
|
|
|
sta Y1+1 ; (stack) = ys + y, y1 = (stack)
|
2003-12-09 20:46:38 +00:00
|
|
|
pha
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr SETPIXELCLIP ; plot (xs + x, ys + y)
|
2003-12-09 20:46:38 +00:00
|
|
|
lda YS
|
|
|
|
sub YY
|
|
|
|
sta Y1
|
|
|
|
sta Y3
|
|
|
|
lda YS+1
|
|
|
|
sbc YY+1
|
2008-03-16 09:37:22 +00:00
|
|
|
sta Y1+1 ; y3 = y1 = ys - y
|
2003-12-09 20:46:38 +00:00
|
|
|
sta Y3+1
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr SETPIXELCLIP ; plot (xs + x, ys - y)
|
2003-12-09 20:46:38 +00:00
|
|
|
pla
|
|
|
|
sta Y1+1
|
|
|
|
pla
|
2008-03-16 09:37:22 +00:00
|
|
|
sta Y1 ; y1 = ys + y
|
2003-12-09 20:46:38 +00:00
|
|
|
lda XS
|
|
|
|
sub XX
|
|
|
|
sta X1
|
|
|
|
lda XS+1
|
|
|
|
sbc XX+1
|
|
|
|
sta X1+1
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr SETPIXELCLIP ; plot (xs - x, ys + y)
|
2003-12-09 20:46:38 +00:00
|
|
|
lda Y3
|
|
|
|
sta Y1
|
|
|
|
lda Y3+1
|
|
|
|
sta Y1+1
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr SETPIXELCLIP ; plot (xs - x, ys - y)
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
lda XS
|
|
|
|
add YY
|
|
|
|
sta X1
|
|
|
|
lda XS+1
|
|
|
|
adc YY+1
|
2008-03-16 09:37:22 +00:00
|
|
|
sta X1+1 ; x1 = xs + y
|
2003-12-09 20:46:38 +00:00
|
|
|
lda YS
|
|
|
|
add XX
|
|
|
|
sta Y1
|
|
|
|
pha
|
|
|
|
lda YS+1
|
|
|
|
adc XX+1
|
2008-03-16 09:37:22 +00:00
|
|
|
sta Y1+1 ; (stack) = ys + x, y1 = (stack)
|
2003-12-09 20:46:38 +00:00
|
|
|
pha
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr SETPIXELCLIP ; plot (xs + y, ys + x)
|
2003-12-09 20:46:38 +00:00
|
|
|
lda YS
|
|
|
|
sub XX
|
|
|
|
sta Y1
|
|
|
|
sta Y3
|
|
|
|
lda YS+1
|
|
|
|
sbc XX+1
|
2008-03-16 09:37:22 +00:00
|
|
|
sta Y1+1 ; y3 = y1 = ys - x
|
2003-12-09 20:46:38 +00:00
|
|
|
sta Y3+1
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr SETPIXELCLIP ; plot (xs + y, ys - x)
|
2003-12-09 20:46:38 +00:00
|
|
|
pla
|
|
|
|
sta Y1+1
|
|
|
|
pla
|
2008-03-16 09:37:22 +00:00
|
|
|
sta Y1 ; y1 = ys + x(stack)
|
2003-12-09 20:46:38 +00:00
|
|
|
lda XS
|
|
|
|
sub YY
|
|
|
|
sta X1
|
|
|
|
lda XS+1
|
|
|
|
sbc YY+1
|
|
|
|
sta X1+1
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr SETPIXELCLIP ; plot (xs - y, ys + x)
|
2003-12-09 20:46:38 +00:00
|
|
|
lda Y3
|
|
|
|
sta Y1
|
|
|
|
lda Y3+1
|
|
|
|
sta Y1+1
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr SETPIXELCLIP ; plot (xs - y, ys - x)
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; og = mo + y + y + 1
|
2003-12-09 20:46:38 +00:00
|
|
|
lda MaxO
|
|
|
|
ldx MaxO+1
|
|
|
|
add YY
|
|
|
|
tay
|
|
|
|
txa
|
|
|
|
adc YY+1
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
add YY
|
|
|
|
tay
|
|
|
|
txa
|
|
|
|
adc YY+1
|
|
|
|
tax
|
|
|
|
tya
|
2004-03-11 21:54:22 +00:00
|
|
|
add #$01
|
2008-03-16 09:37:22 +00:00
|
|
|
bcc :+
|
2003-12-09 20:46:38 +00:00
|
|
|
inx
|
2008-03-16 09:37:22 +00:00
|
|
|
: sta OGora
|
2003-12-09 20:46:38 +00:00
|
|
|
stx OGora+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; ou = og - x - x + 1
|
2003-12-09 20:46:38 +00:00
|
|
|
sub XX
|
|
|
|
tay
|
|
|
|
txa
|
|
|
|
sbc XX+1
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
sub XX
|
|
|
|
tay
|
|
|
|
txa
|
|
|
|
sbc XX+1
|
|
|
|
tax
|
|
|
|
tya
|
2004-03-11 21:54:22 +00:00
|
|
|
add #$01
|
2008-03-16 09:37:22 +00:00
|
|
|
bcc :+
|
2003-12-09 20:46:38 +00:00
|
|
|
inx
|
2008-03-16 09:37:22 +00:00
|
|
|
: sta OUkos
|
2003-12-09 20:46:38 +00:00
|
|
|
stx OUkos+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; ++y
|
2003-12-09 20:46:38 +00:00
|
|
|
inc YY
|
2008-03-16 09:37:22 +00:00
|
|
|
bne :+
|
2003-12-09 20:46:38 +00:00
|
|
|
inc YY+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; if (abs (ou) < abs (og)) {
|
|
|
|
: lda OUkos
|
2003-12-09 20:46:38 +00:00
|
|
|
ldy OUkos+1
|
|
|
|
jsr abs
|
|
|
|
sta TEMP3
|
|
|
|
sty TEMP4
|
|
|
|
lda OGora
|
|
|
|
ldy OGora+1
|
|
|
|
jsr abs
|
|
|
|
ldx #TEMP3
|
|
|
|
jsr icmp
|
2008-03-16 09:37:22 +00:00
|
|
|
bpl :++
|
|
|
|
|
|
|
|
; --x
|
2003-12-09 20:46:38 +00:00
|
|
|
lda XX
|
2004-03-11 21:54:22 +00:00
|
|
|
sub #$01
|
2003-12-09 20:46:38 +00:00
|
|
|
sta XX
|
2008-03-16 09:37:22 +00:00
|
|
|
bcs :+
|
2003-12-09 20:46:38 +00:00
|
|
|
dec XX+1
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; mo = ou }
|
|
|
|
: lda OUkos
|
2003-12-09 20:46:38 +00:00
|
|
|
ldx OUkos+1
|
2008-03-16 09:37:22 +00:00
|
|
|
jmp :++
|
|
|
|
|
|
|
|
; else mo = og
|
|
|
|
: lda OGora
|
2003-12-09 20:46:38 +00:00
|
|
|
ldx OGora+1
|
2008-03-16 09:37:22 +00:00
|
|
|
: sta MaxO
|
2003-12-09 20:46:38 +00:00
|
|
|
stx MaxO+1
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; }
|
|
|
|
jmp while
|
2003-12-09 20:46:38 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Copies of some runtime routines
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
abs:
|
2008-03-16 09:37:22 +00:00
|
|
|
; A/Y := abs (A/Y)
|
2004-03-11 21:54:22 +00:00
|
|
|
cpy #$00
|
2008-03-16 09:37:22 +00:00
|
|
|
bpl :+
|
|
|
|
|
|
|
|
; A/Y := neg (A/Y)
|
2003-12-09 20:46:38 +00:00
|
|
|
neg: clc
|
2004-03-11 21:54:22 +00:00
|
|
|
eor #$FF
|
|
|
|
adc #$01
|
2003-12-09 20:46:38 +00:00
|
|
|
pha
|
|
|
|
tya
|
2004-03-11 21:54:22 +00:00
|
|
|
eor #$FF
|
|
|
|
adc #$00
|
2003-12-09 20:46:38 +00:00
|
|
|
tay
|
|
|
|
pla
|
2008-03-16 09:37:22 +00:00
|
|
|
: rts
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
icmp:
|
2008-03-16 09:37:22 +00:00
|
|
|
; Compare A/Y to zp,X
|
2003-12-09 20:46:38 +00:00
|
|
|
sta TEMP ; TEMP/TEMP2 - arg2
|
|
|
|
sty TEMP2
|
2004-03-11 21:54:22 +00:00
|
|
|
lda $00,x
|
2003-12-09 20:46:38 +00:00
|
|
|
pha
|
2004-03-11 21:54:22 +00:00
|
|
|
lda $01,x
|
2003-12-09 20:46:38 +00:00
|
|
|
tay
|
|
|
|
pla
|
|
|
|
tax
|
2008-03-16 09:37:22 +00:00
|
|
|
tya ; X/A - arg1 (a = high)
|
2003-12-09 20:46:38 +00:00
|
|
|
|
|
|
|
sub TEMP2
|
2008-03-16 09:37:22 +00:00
|
|
|
bne :++
|
2003-12-09 20:46:38 +00:00
|
|
|
cpx TEMP
|
2008-03-16 09:37:22 +00:00
|
|
|
beq :+
|
2004-03-11 21:54:22 +00:00
|
|
|
adc #$FF
|
2003-12-09 20:46:38 +00:00
|
|
|
ora #$01
|
2008-03-16 09:37:22 +00:00
|
|
|
: rts
|
|
|
|
: bvc :+
|
2004-03-11 21:54:22 +00:00
|
|
|
eor #$FF
|
2003-12-09 20:46:38 +00:00
|
|
|
ora #$01
|
2008-03-16 09:37:22 +00:00
|
|
|
: rts
|