; Double buffer IRQ stuff
DRAWPAGE: .res 1
SWAPREQUEST: .res 1
-VBLHOOK: .res 3
text_bitmap: .res 8*(1+20+1)+1
; 8 rows with (one offset-byte plus 20 character bytes plus one fill-byte) plus one 0-offset-byte
stz BGINDEX
stz DRAWPAGE
stz SWAPREQUEST
- lda #$60 ; rts op-code
- sta VBLHOOK
rts
;
INIT:
+; Enable interrupts for VBL
+ lda #$80
+ tsb VTIMCTLA
+; Set up collision buffer to $A058
+ lda #$58
+ sta COLLBASL
+ lda #$A0
+ sta COLLBASH
+; Put collision index before sprite data
+ lda #$FE
+ sta COLLOFFL
+ lda #$FF
+ sta COLLOFFH
; Done, reset the error code
lda #TGI_ERR_OK
sta ERROR
; To update displays you can call tgi_ioctl(4, 1) it will wait for the
; next VBL interrupt and swap draw and view buffers.
;
-; Set an address for a subroutine you want to call at every VBL
-; tgi_ioctl(5, hook)
+; Activate or deactivate collision detection by calling tgi_ioctl(5, 0/1).
CONTROL:
pha ; Almost all control routines succeed
lda #TGI_ERR_OK
sta ERROR
pla
+
cmp #5
- bne ControlSwapRequest
-
- lda ptr1 ; Set IRQ routine to be called at VBL
- sta VBLHOOK+1
- lda ptr1+1
- sta VBLHOOK+2
- lda #$43 ; jmp op-code
- sta VBLHOOK
+ bne ControlSwap
+ lda ptr1
+ bne @L0
+ lda __sprsys
+ ora #$20
+ bra @L1
+@L0: lda __sprsys
+ and #$df
+@L1: sta __sprsys
+ sta SPRSYS
rts
-ControlSwapRequest:
+ControlSwap:
cmp #4
bne ControlFramerate
cmp #3
bne ControlTextBG
+ lda ptr1
cmp #75 ; Set framerate
beq rate75
cmp #60
SETVIEWPAGE:
cmp #1
beq @L1 ; page == maxpages-1
- ldy #<$de20 ; page 0
- ldx #>$de20
+ ldy #<$e018 ; page 0
+ ldx #>$e018
bra @L2
@L1:
- ldy #<$be40 ; page 1
- ldx #>$be40
+ ldy #<$c038 ; page 1
+ ldx #>$c038
@L2:
sty VIEWPAGEL ; Save viewpage for getpixel
stx VIEWPAGEH
;
SETDRAWPAGE:
- cmp #1
+ cmp #1
beq @L1 ; page == maxpages-1
- lda #<$de20 ; page 0
- ldx #>$de20
+ lda #<$e018 ; page 0
+ ldx #>$e018
bra @L2
@L1:
- lda #<$be40 ; page 1
- ldx #>$be40
+ lda #<$c038 ; page 1
+ ldx #>$c038
@L2:
sta DRAWPAGEL
stx DRAWPAGEH
; IRQ: VBL interrupt handler
;
-TIMER0_INTERRUPT = $01
-TIMER1_INTERRUPT = $02
-TIMER2_INTERRUPT = $04
-TIMER3_INTERRUPT = $08
-TIMER4_INTERRUPT = $10
-TIMER5_INTERRUPT = $20
-TIMER6_INTERRUPT = $40
-TIMER7_INTERRUPT = $80
-
-HBL_INTERRUPT = TIMER0_INTERRUPT
-VBL_INTERRUPT = TIMER2_INTERRUPT
-SERIAL_INTERRUPT = TIMER4_INTERRUPT
-
IRQ:
- lda INTSET ; Poll all pending interrupts
- and #VBL_INTERRUPT
- bne IRQVBL
- clc ; Not a VBL interrupt - exit
- rts
-IRQVBL:
- lda SWAPREQUEST
- beq @L0
- lda DRAWPAGE
- jsr SETVIEWPAGE
- lda DRAWPAGE
- eor #1
- sta DRAWPAGE
- jsr SETDRAWPAGE
- stz SWAPREQUEST
+ lda INTSET ; Poll all pending interrupts
+ and #VBL_INTERRUPT
+ beq IRQEND ; Exit if not a VBL interrupt
+
+ lda SWAPREQUEST
+ beq @L0
+ lda DRAWPAGE
+ jsr SETVIEWPAGE
+ lda DRAWPAGE
+ eor #1
+ sta DRAWPAGE
+ jsr SETDRAWPAGE
+ stz SWAPREQUEST
@L0:
- jsr VBLHOOK
- clc
- rts
+IRQEND:
+ clc
+ rts
; ------------------------------------------------------------------------
; SETCOLOR: Set the drawing color (in A). The new color is already checked
; The Font
; 96 characters from ASCII 32 to 127
; 8 pixels wide, 8 pixels high
-; bit value 0 = foreground, bit value 1 = background / transparent
+; bit value 0 = foreground, bit value 1 = background / transparent
font:
; VERSAIL
.byte $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ;32