VIDEO_MEM = $fc00 _plotSScreen = 0C9FAh ; graph mem ; Thanx to Robert Niedziela for his grayscale routines ;*============================================================================================* ;! Grayscale library ! ;*============================================================================================* ;******************************************************************* ;* GRAY SCALE LIBRARY FOR TI-86 VERSION 1.0 * ;* Written by Robert Niedziela * ;* 1998 * ;*-----------------------------------------------------------------* ;* This is the library of basic routines for gray scale graph mode * ;* Version for 4 levels of gray with double buffering * ;*-----------------------------------------------------------------* ;* There is variable UserCounter which is incremented every * ;* interrupt - use it if you need any counter. * ;******************************************************************* #define PAGE1_BPL1 $3C #define PAGE1_BPL2 $0A #define PAGE2_BPL1 $31 #define PAGE2_BPL2 $35 _user_int_ram EQU $d2fd ;Area where interrupt handler goes.. ;+--------------------------------------------------------------------------+ ;| Open gray scale graph mode | ;+--------------------------------------------------------------------------+ ;| Parameters: none | ;+--------------------------------------------------------------------------+ ;| Returns: nothing | ;+--------------------------------------------------------------------------+ ;| Registers destroyed: HL, DE, BC, A | ;+--------------------------------------------------------------------------+ ;| Comments: Iinitialize interrupt routine and init variables | ;+--------------------------------------------------------------------------+ OpenGray: ;store 6 bytes following _plotSScreen ld hl, _plotSScreen+1018 ld de, _plotSScreen ld bc, 6 ldir res 2,(iy+$23) ;turn user int off so it won't get called by ;accident before we're ready ld hl,IntRoutine ;copy prog to user int buffer ld de,_user_int_ram+1 ld bc,InterruptMemEnd-IntRoutine ;length of handler ldir ;hl is the source, de is the destination, ;and bc is the length ld a,(_user_int_ram+1) ;set up checksum byte ld hl,_user_int_ram+($28*1) ;load byte add a,(hl) ;add to total ld hl,_user_int_ram+($28*2) ;load byte add a,(hl) ;add to total ld hl,_user_int_ram+($28*3) ;load byte add a,(hl) ;add to total ld hl,_user_int_ram+($28*4) ;load byte add a,(hl) ;add to total ld hl,_user_int_ram+($28*5) ;load byte add a,(hl) ;add to total ld (_user_int_ram),a ;load checksum in its location xor a ;init variables ld (IntCounter), a ld (IntDisplayedPage), a ld (UserCounter), a ld de, IntData ;init page addrs ld hl, SourceIntData ld bc, 4 ldir set 2,(iy+$23) ;turn it on ret ;+--------------------------------------------------------------------------+ ;| Close gray scale graph mode | ;+--------------------------------------------------------------------------+ ;| Parameters: none | ;+--------------------------------------------------------------------------+ ;| Returns: nothing | ;+--------------------------------------------------------------------------+ ;| Registers destroyed: A, BC, DE, HL | ;+--------------------------------------------------------------------------+ ;| Comments: After closing gray scale graph mode it clears bitplanes on | ;| page 1 and sets LCD to display standard memory area ($FC00) | ;+--------------------------------------------------------------------------+ CloseGray: res 2, (iy+$23) ;disable the jump to $d2fd ld a, $3C out (0), a ;restore 6 bytes following _plotSScreen ld de, _plotSScreen+1018 ld hl, _plotSScreen ld bc, 6 ldir ;clear LCD and Plot memory call ClearPage1 ret ;+--------------------------------------------------------------------------+ ;| Clear given page | ;+--------------------------------------------------------------------------+ ;| Parameters: A-number of page to clear (0-page 1, other-page 2) | ;+--------------------------------------------------------------------------+ ;| Returns: nothing | ;+--------------------------------------------------------------------------+ ;| Registers destroyed: BC, DE, HL | ;+--------------------------------------------------------------------------+ ;| Comments: You can use ClearPage1 to clear page 1 or ClearPage2 to clear | ;| page2 instead of loading number to A and calling ClearPage | ;+--------------------------------------------------------------------------+ ;ClearPage: ; cp 0 ; jr nz, ClearPage2 ClearPage1: ; ld hl, (Pages) ; call Clear1024 ; ld hl, (Pages+2) ; call Clear1024 ; ret ClearPage2: ; ld hl, (Pages+4) ; call Clear1024 ; ld hl, (Pages+6) ; call Clear1024 ; ret Clear1024: ; ld d, h ; ld e, l ; inc de ; ld (hl), 0 ; ld bc, 1023 ; ldir ; ret ;+--------------------------------------------------------------------------+ ;| Wait for VBL interrupt | ;+--------------------------------------------------------------------------+ ;| Parameters: none | ;+--------------------------------------------------------------------------+ ;| Returns: nothing | ;+--------------------------------------------------------------------------+ ;| Registers destroyed: A | ;+--------------------------------------------------------------------------+ ;| Comments: This routine waits for VBL interrupt and exits. | ;| Call it to reduce flicking while changing pages. | ;+--------------------------------------------------------------------------+ WaitForVBL: ; push af WaitForVBLInternal: ; ld a,(IntCounter) ; or a ; jr nz, WaitForVBLInternal ; pop af ; ret ;+--------------------------------------------------------------------------+ ;| Set displayed page | ;+--------------------------------------------------------------------------+ ;| Parameters: A-page to display (0-page 1, 1-page 2) | ;+--------------------------------------------------------------------------+ ;| Returns: nothing | ;+--------------------------------------------------------------------------+ ;| Registers destroyed: A | ;+--------------------------------------------------------------------------+ ;| Comments: none | ;+--------------------------------------------------------------------------+ DisplayPage: ; call WaitForVBL ; ld (IntDisplayedPage), a ; ret ;+--------------------------------------------------------------------------+ ;| Flip pages (invisible becomes visible) | ;+--------------------------------------------------------------------------+ ;| Parameters: none | ;+--------------------------------------------------------------------------+ ;| Returns: nothing | ;+--------------------------------------------------------------------------+ ;| Registers destroyed: none | ;+--------------------------------------------------------------------------+ ;| Comments: none | ;+--------------------------------------------------------------------------+ FlipPages: ; push af ; ld a, (IntDisplayedPage) ; xor 1 ; call DisplayPage ; pop af ; ret ;--------------------------------------------------------------------- ;| This is the interrupt routine | ;--------------------------------------------------------------------- IntRoutine: in a,(3) bit 1,a ; check that it is a vbl interrupt jr z,EndIntRoutine ld hl, UserCounter inc (hl) ld hl, IntData ld a, (IntDisplayedPage) ;Check displayed page or a jr z, Int_DisplayedPage1 inc hl inc hl Int_DisplayedPage1: ld a,(IntCounter) cp 5 jr z,DisplayLast cp 3 jr c,DisplayBpl1 jr DisplayBpl2 DisplayBpl1: ;Dislpay 1st bitplane inc a ld (IntCounter),a ld a, (hl) out (0),a jr EndIntRoutine DisplayBpl2: ;Display 2nd bitplane inc a ld (IntCounter),a inc hl ld a, (hl) out (0),a jr EndIntRoutine DisplayLast: ;Display 1st bitplane again ld a, (hl) out (0), a xor a ld (IntCounter),a EndIntRoutine: ;------------------- My own interrupt code executed after the grayscale controller code -------------------- ld a, (game_mode) or a ret z ; return if game mode is not contest ld a, (time_run) or a ret z ; return if time decreasing is not activated ld hl, time200 dec (hl) ret nz ; execute the following code ONLY every 200 interrupts ld a, 200 ld (hl), a ; re-initialize time200 variable inc hl ; ld hl, time ld a, (hl) dec (hl) ; decrease time ld (time_previous), a or a ; same as cp 0 ret nz inc (hl) ; restore time (=0) inc a ; same as ld a, 1 ld (time's_up), a ret InterruptMemEnd: IntDisplayedPage equ _user_int_ram+InterruptMemEnd-IntRoutine+1 IntCounter equ _user_int_ram+InterruptMemEnd-IntRoutine+2 IntData equ _user_int_ram+InterruptMemEnd-IntRoutine+3 UserCounter equ _user_int_ram+InterruptMemEnd-IntRoutine+7 SourceIntData: .db PAGE1_BPL1, PAGE1_BPL2, PAGE2_BPL1, PAGE2_BPL2 ;addresses of ram area for each bitplane Pages: .dw VIDEO_MEM, _plotSScreen+6, $F100, $F500