A83: Interrupt help.


[Prev][Next][Index][Thread]

A83: Interrupt help.




Ok, can someone check this code.  Its an interrupt program.  I'm still
trying to write that trig program, even though Joe wrote a version.  Mine
doesn't work though!! =)...can someone help me.

Thanks.

James.


.NOLIST
#define equ .equ
#define EQU .equ
#define end .end
#include "ti83asm.inc"
#include "tokens.inc"
.LIST

.org 9327h

     im 1                     ; make sure it isn't running in im 2

     ld hl,trig		      ; Display "ZTrigMode!"
     call _puts
     call _newline
     ld hl,Dekker             ; display "By Dekker"
     call _puts               ;
     call _newline            ;

     ld a,(state)             ; check if it is running
     or a                     ;
     jr nz,disable_interrupt  ;

enable_interrupt:		; Enable the interrupts.

     ld hl,On                 ; dipslay "On."
     call _puts               ;
     call _newline            ;

     ld a,1                   ; set state to enabled
     call store_state         ;

     ld hl,$8300              ; set up interrupt vector
     ld de,$8301              ;
     ld (hl),$84              ;
     ld bc,$0100              ;
     ldir                     ;

     ld hl,interrupt_start    ; copy interrupt
     ld de,$8484              ;
     ld bc,interrupt_end-interrupt_start+1  ;
     ldir                     ;

     ld a,$83                 ; point i to interrupt vector
     ld i,a                   ;
     im 2                     ;
     ret                      ;


disable_interrupt:		; Disable them.

     ld hl,Off                ; display "Off."
     call _puts               ;
     call _newline            ;

     xor a                    ; set state to disabled
     ld (state),a             ;

store_state:

     push af                  ; write back state
     call _zerooop1           ;
     ld de,op1                ;
     ld hl,prog               ;
     ld bc,7                  ;
     ldir                     ;
     call _chkfindsym         ;
     inc de                   ;
     inc de                   ;
     ld hl,state-$9327        ;
     add hl,de                ;
     pop af                   ;
     ld (hl),a                ;
     ret                      ;

interrupt_start:

     di
     ex af,af'
     exx

     ld a,($800A)             ; turn off calc if apd
     cp $11                   ;
     jr c,interrupt_off       ;

     ld      hl,degsprite+$8484-interrupt_start
     bit     trigdeg,(iy+trigflags)
     jr      nz,startdraw
     ld      hl, radsprite+$8484-interrupt_start
startdraw:
     ld	a,20h+11
     out (lcdinstport),a
     call delay-$8484+interrupt_start 
     ld b,4
     ld  a,80h+60
     out (lcddataport),a
draw:
     call delay+$8484-interrupt_start
     ld   a,(hl)
     out  (lcddataport),a
     inc hl
     djnz draw
     
exit_interrupt:

     exx                      ;
     ex af,af'                ;
     jp $0038                 ; normal interrupt handler

interrupt_off:

     ld a,$74                 ; reset apd counter
     ld ($800A),a             ;

     ld a,$08                 ; turn off lcd
     out (3),a                ;
     ld a,$01                 ; mask on key interrupts
     out (3),a                ;
     pop hl                   ; return to when the int occured
     exx                      ;
     ex af,af'                ;
     ei                       ; enable interrupts
     halt                     ; wait for an interrupt
     jp $0038                 ;

interrupt_end:

delay:	push	hl	; short delay to give the LCD time to update
	inc	hl
	dec	hl
	pop	hl
	ret

trig:		.db "ZTrigMode!",0
Dekker:		.db "by Dekker.",0
On:		.db "Status: On.",0
Off:		.db "Status: Off.",0
degreestext:	.db "Degrees",0
radianstext:	.db "Radians",0
prog:           .db 05h,"ZTRIG",0         ; program name for write back
state:          .db $00                  ; interrupt state

degsprite:
	.db	%11111111
	.db	%10000001
	.db	%10000001
	.db	%11111111

radsprite:
	.db	%11111100
	.db	%10000100
	.db	%11111000
	.db	%10000100



.end
END