; Based on Maciej Witkowiak's line routine.
;
- .include "zeropage.inc"
+ .include "zeropage.inc"
- .include "tgi-kernel.inc"
- .include "tgi-error.inc"
- .include "nes.inc"
- .include "get_tv.inc"
- .import _clrscr, setcursor, putchar
- .import paldata
+ .include "tgi-kernel.inc"
+ .include "tgi-error.inc"
+ .include "nes.inc"
+ .include "get_tv.inc"
+ .import _clrscr, setcursor, putchar
+ .import paldata
- .macpack generic
+ .macpack generic
; ------------------------------------------------------------------------
; Header. Includes jump table and constants.
-.segment "JUMPTABLE"
+.segment "JUMPTABLE"
; First part of the header is a structure that has a magic and defines the
; capabilities of the driver
- .byte $74, $67, $69 ; "tgi"
- .byte TGI_API_VERSION ; TGI API version number
-xres: .word charsperline*2 ; Max X resolution
-yres: .word 56 ; Max Y resolution
- .byte 2 ; Number of drawing colors
- .byte 1 ; Number of screens available
- .byte 2 ; System font X size
- .byte 2 ; System font Y size
- .word $100 ; Aspect ratio
- .byte 0 ; TGI driver flags
+ .byte $74, $67, $69 ; "tgi"
+ .byte TGI_API_VERSION ; TGI API version number
+xres: .word charsperline*2 ; Max X resolution
+yres: .word 56 ; Max Y resolution
+ .byte 2 ; Number of drawing colors
+ .byte 1 ; Number of screens available
+ .byte 2 ; System font X size
+ .byte 2 ; System font Y size
+ .word $100 ; Aspect ratio
+ .byte 0 ; TGI driver flags
; Next comes the jump table. Currently all entries must be valid and may point
; to an RTS for test versions (function not implemented).
- .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 TEXTSTYLE
- .addr OUTTEXT
- .addr 0 ; IRQ entry is unused
+ .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 TEXTSTYLE
+ .addr OUTTEXT
+ .addr 0 ; IRQ entry is unused
; ------------------------------------------------------------------------
; Data.
; 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
+X1 = ptr1
+Y1 = ptr2
+X2 = ptr3
+Y2 = ptr4
+RADIUS = tmp1
-ADDR = tmp1
-TEMP = tmp3
-TEMP2 = tmp4
-TEMP3 = sreg
-TEMP4 = sreg+1
+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
+PB = ptr3 ; (2) LINE
+UB = ptr4 ; (2) LINE
+ERR = regsave ; (2) LINE
+NX = regsave+2 ; (2) LINE
; Absolute variables used in the code
.bss
-MEM: .res charsperline*2*56/4
+MEM: .res charsperline*2*56/4
MEMEND:
-ERROR: .res 1 ; Error code
-COLOR: .res 1 ; Current color
-PALETTE: .res 2 ; The current palette
+ERROR: .res 1 ; Error code
+COLOR: .res 1 ; Current color
+PALETTE: .res 2 ; The current palette
; Line routine stuff
OGora:
-COUNT: .res 2
+COUNT: .res 2
OUkos:
-NY: .res 2
+NY: .res 2
Y3:
-DX: .res 1
-DY: .res 1
-AY: .res 1
+DX: .res 1
+DY: .res 1
+AY: .res 1
; Constants and tables
.rodata
-DEFPALETTE: .byte $0, $1
-OFFSET: .byte 8, 4, 2, 1
-; 00 00 00 00 01 01 01 01
-; 00 01 10 11 00 01 10 11
-CODE: .byte 32, 29, 26, 25, 28, 24+128, 31+128, 30+128
-; 10 10 10 10 11 11 11 11
-; 00 01 10 11 00 01 10 11
- .byte 30, 31, 24, 28+128, 25+128, 26+128, 29+128, 32+128
+DEFPALETTE: .byte $0, $1
+OFFSET: .byte 8, 4, 2, 1
+; 00 00 00 00 01 01 01 01
+; 00 01 10 11 00 01 10 11
+CODE: .byte 32, 29, 26, 25, 28, 24+128, 31+128, 30+128
+; 10 10 10 10 11 11 11 11
+; 00 01 10 11 00 01 10 11
+ .byte 30, 31, 24, 28+128, 25+128, 26+128, 29+128, 32+128
.code
;
INSTALL:
- jsr _get_tv
- cmp #TV::NTSC
- beq ntsc
+ jsr _get_tv
+ cmp #TV::NTSC
+ beq ntsc
; TODO ROM!
- inc yres
- inc yres
-ntsc:; rts
+ inc yres
+ inc yres
+ntsc:; rts
; ------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory. May
;
UNINSTALL:
- rts
+ rts
; ------------------------------------------------------------------------
; INIT: Changes an already installed device from text mode to graphics
; Done, reset the error code
- lda #TGI_ERR_OK
- sta ERROR
-; rts
+ lda #TGI_ERR_OK
+ sta ERROR
+; rts
; ------------------------------------------------------------------------
; DONE: Will be called to switch the graphics device back into text mode.
;
DONE:
- rts
+ rts
; ------------------------------------------------------------------------
; GETERROR: Return the error code in A and clear it.
GETERROR:
- lda ERROR
- ldx #TGI_ERR_OK
- stx ERROR
- rts
+ lda ERROR
+ ldx #TGI_ERR_OK
+ stx ERROR
+ rts
; ------------------------------------------------------------------------
; CONTROL: Platform/driver specific entry point.
;
CONTROL:
- lda #TGI_ERR_INV_FUNC
- sta ERROR
- rts
+ lda #TGI_ERR_INV_FUNC
+ sta ERROR
+ rts
; ------------------------------------------------------------------------
; CLEAR: Clears the screen.
;
CLEAR:
- ldx #<MEM
- stx TEMP
- ldx #>MEM
- stx TEMP+1
- lda #0
- tay
-@L1: sta (TEMP),y
- iny
- bne @L1
- inc TEMP+1
- inx
- cpx #>MEMEND
- bne @L1
- jmp _clrscr
+ ldx #<MEM
+ stx TEMP
+ ldx #>MEM
+ stx TEMP+1
+ lda #0
+ tay
+@L1: sta (TEMP),y
+ iny
+ bne @L1
+ inc TEMP+1
+ inx
+ cpx #>MEMEND
+ bne @L1
+ jmp _clrscr
; ------------------------------------------------------------------------
; SETCOLOR: Set the drawing color (in A). The new color is already checked
;
SETCOLOR:
- sta COLOR
-; rts
+ sta COLOR
+; rts
; ------------------------------------------------------------------------
; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
;
SETDRAWPAGE:
- rts
+ rts
; ------------------------------------------------------------------------
; SETPALETTE: Set the palette (not available with all drivers/hardware).
SETPALETTE:
; Wait for v-blank
-@wait: lda PPU_STATUS
- bpl @wait
-
- lda #$3F
- sta PPU_VRAM_ADDR2
- lda #$00
- sta PPU_VRAM_ADDR2
-
- ldy #0
- lda (ptr1),y
- sta PALETTE
- tax
- lda paldata,x
-; sta PPU_VRAM_IO
-
- iny
- lda (ptr1),y
- sta PALETTE+1
- tax
- lda paldata,x
- sta PPU_VRAM_IO
-
- lda #TGI_ERR_OK
- sta ERROR
- rts
+@wait: lda PPU_STATUS
+ bpl @wait
+
+ lda #$3F
+ sta PPU_VRAM_ADDR2
+ lda #$00
+ sta PPU_VRAM_ADDR2
+
+ ldy #0
+ lda (ptr1),y
+ sta PALETTE
+ tax
+ lda paldata,x
+; sta PPU_VRAM_IO
+
+ iny
+ lda (ptr1),y
+ sta PALETTE+1
+ tax
+ lda paldata,x
+ sta PPU_VRAM_IO
+
+ lda #TGI_ERR_OK
+ sta ERROR
+ rts
; ------------------------------------------------------------------------
; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
;
GETPALETTE:
- lda #<PALETTE
- ldx #>PALETTE
- rts
+ lda #<PALETTE
+ ldx #>PALETTE
+ rts
; ------------------------------------------------------------------------
; GETDEFPALETTE: Return the default palette for the driver in A/X. All
;
GETDEFPALETTE:
- lda #<DEFPALETTE
- ldx #>DEFPALETTE
- rts
+ lda #<DEFPALETTE
+ ldx #>DEFPALETTE
+ rts
; ------------------------------------------------------------------------
; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
;
SETPIXEL:
- ldx Y1 ; y+2<yres
- inx
- inx
- cpx yres
- bcc @L2
- ldx X1 ; x+2<xres
- inx
- inx
- cpx xres
- bcc @L2
- rts
-@L2: lda X1
- lsr
- tay
- lda Y1
- lsr
- tax
- clc
- jsr setcursor
- jsr CALC
- ldx COLOR
- bne @set2
- eor #%00001111
-@set2: sta TEMP3
-
- lda (TEMP),y
- ldx COLOR
- bne @set
- and TEMP3
- .byte $2c
-@set: ora TEMP3
- sta (TEMP),y
- tax
- lda CODE,x
-@normal:jmp putchar
+ ldx Y1 ; y+2<yres
+ inx
+ inx
+ cpx yres
+ bcc @L2
+ ldx X1 ; x+2<xres
+ inx
+ inx
+ cpx xres
+ bcc @L2
+ rts
+@L2: lda X1
+ lsr
+ tay
+ lda Y1
+ lsr
+ tax
+ clc
+ jsr setcursor
+ jsr CALC
+ ldx COLOR
+ bne @set2
+ eor #%00001111
+@set2: sta TEMP3
+
+ lda (TEMP),y
+ ldx COLOR
+ bne @set
+ and TEMP3
+ .byte $2c
+@set: ora TEMP3
+ sta (TEMP),y
+ tax
+ lda CODE,x
+@normal:jmp putchar
; ------------------------------------------------------------------------
; GETPIXEL: Read the color value of a pixel and return it in A/X. The
GETPIXEL:
- jsr CALC
- sta TEMP3
- lda (TEMP),y
- and TEMP3
- beq @L1
- lda #1
-@L1: ldx #0
- rts
+ jsr CALC
+ sta TEMP3
+ lda (TEMP),y
+ and TEMP3
+ beq @L1
+ lda #1
+@L1: ldx #0
+ rts
; ------------------------------------------------------------------------
; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
; 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)
+; 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:
- inc Y2
-@L1: lda X1
- pha
-@L2: jsr SETPIXEL
- inc X1
- lda X2
- cmp X1
- bne @L2
- pla
- sta X1
- inc Y1
- lda Y2
- cmp Y1
- bne @L1
- rts
+ inc Y2
+@L1: lda X1
+ pha
+@L2: jsr SETPIXEL
+ inc X1
+ lda X2
+ cmp X1
+ bne @L2
+ pla
+ sta X1
+ inc Y1
+ lda Y2
+ cmp Y1
+ bne @L1
+ rts
; ------------------------------------------------------------------------
; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
;
TEXTSTYLE:
- rts
+ rts
; ------------------------------------------------------------------------
; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
;
OUTTEXT:
- lda ptr1
- lsr
- tay
- lda ptr2
- lsr
- tax
- clc
- jsr setcursor
- ldy #0
-@L1: lda (ptr3),y
- jsr putchar
- iny
- cmp #$0
- bne @L1
- rts
+ lda ptr1
+ lsr
+ tay
+ lda ptr2
+ lsr
+ tax
+ clc
+ jsr setcursor
+ ldy #0
+@L1: lda (ptr3),y
+ jsr putchar
+ iny
+ cmp #$0
+ bne @L1
+ rts
; ------------------------------------------------------------------------
; Calculate all variables to plot the pixel at X1/Y1. If the point is out
; of range, a carry is returned and INRANGE is set to a value !0 zero. If
; the coordinates are valid, INRANGE is zero and the carry clear.
-CALC: lda xres
- sta TEMP
- lda #0
- sta TEMP+1
- ldy Y1
-@L1: lda TEMP
- add xres
- lsr
- sta TEMP
- lda TEMP+1
- adc #0
- lsr
- sta TEMP+1
- dey
- bne @L1
- lda TEMP
- add X1
- lsr
- sta TEMP
- lda TEMP+1
- adc #0
- lsr
- sta TEMP+1
- lda TEMP
- add #<MEM
- sta TEMP
- lda TEMP+1
- adc #>MEM
- sta TEMP+1
-
- lda X1
- and #%00000001
- sta TEMP3
- lda Y1
- asl
- and #%00000010
- ora TEMP3
- tax
- lda OFFSET,x
- rts
+CALC: lda xres
+ sta TEMP
+ lda #0
+ sta TEMP+1
+ ldy Y1
+@L1: lda TEMP
+ add xres
+ lsr
+ sta TEMP
+ lda TEMP+1
+ adc #0
+ lsr
+ sta TEMP+1
+ dey
+ bne @L1
+ lda TEMP
+ add X1
+ lsr
+ sta TEMP
+ lda TEMP+1
+ adc #0
+ lsr
+ sta TEMP+1
+ lda TEMP
+ add #<MEM
+ sta TEMP
+ lda TEMP+1
+ adc #>MEM
+ sta TEMP+1
+
+ lda X1
+ and #%00000001
+ sta TEMP3
+ lda Y1
+ asl
+ and #%00000010
+ ora TEMP3
+ tax
+ lda OFFSET,x
+ rts
; ------------------------------------------------------------------------
-.include "../../tgi/tgidrv_line.inc"
+.include "../../tgi/tgidrv_line.inc"