;this code is based on the doors expression viewer ;copywrite 2000 Samuel Stearley sstear70@calvin.edu include "doorsos.h" include "userlib.h" xdef _ti89 xdef _ti92plus xdef _main _main: move.l a7,a6 ;SAVE THE STACK POINTER move.l 200,a3 ;get the jump table pointer move.l 1060(a3),a5 ;get pointer to top estack move.l (a5),a4 ;get topestack ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ move.l 3852(a3),a0 ;argument counter call move.l a4,-(a7) ;input to argument counter call jsr (a0) ;count number of arguments subq.b #1,d0 ;was there only one argument? bcs no_arguments ;carry set if d0=0 bne too_many_arguments ;branch if zero or if more than 1 argument move.l a4,a2 ;get the esi into a2 bra proceed_as_normal ;proceed no_arguments: ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ move.w #1,-(a7) ;want the first answer ; jsr doorsos::HS_getAns ;Returns an esi in a0 move.l 2308(a3),a4 jsr (a4) tst.w d0 ;check for an error beq window_was_not_made ;test for an error ; move.l a0,a2 ;The HS_getAns call also returns an Esi ; in A0 to the Answer but technically it ; only returns a handle in d0. So for ; stability the code is not going to rely ; on what is possibly a fluke. ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- move.w d0,-(a7) ; jsr doorsos::HToESI move.l 2332(a3),a4 jsr (a4) ;make the call move.l a0,a2 ;save the esi ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ proceed_as_normal: move.w #$300,-(a7) ;THESE ARE THE WINDOWS FLAGS pea rect(Pc) ;THE BORDERS OF THE WINDOW push.l #window ;storage for stuff from open call ; jsr doorsos::WinOpen ;MAKE THE CALL move.l 120(a3),a4 ;It is smaller to do make the call this way jsr (a4) tst.b d0 ;CHECKS IF THE CALL WAS SUCCESSFUL beq window_was_not_made ;ZERO IF AN ERROR ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ clr.w -(a7) ;INPUT move.l a2,-(a7) ;THIS IS THE ESI ; jsr doorsos::Parse2DExpr ;THIS WILL CONSTRUCT THE IMAGE move.l 296(a3),a4 jsr (a4) move.l a0,a2 ;SAVE THE RESULT ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ pea top_half(pc) ;THESE ARE THE INPUTS. pea bottom_half(pc) ;VALUES ARE STORED TO THE PLACES THEY pea width(pc) ;POINT TO, d0 IS THE SAME AS TOP_HALF push.l a2 ;PUSH THE RESULT OF THE PARSE2D CALL ; jsr doorsos::Parms2D ;GET THE DIMENSIONS move.l 308(a3),a4 jsr (a4) moveq #0,d5 ;initial X is zero move.w d0,d6 ;Get the Y of the thing to be displayed move.w d6,d4 ;this copy will not be altered ;a0 will point to the height of top_half after the Parm2D call and d0 contains the ;top_half value. ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ ;EVERYTHING BEFORE THIS POINT WAS JUST SET UP. THE FOLLOWING CODE IS THE MAIN LOOP THAT ;TAKES KEYPRESSES AND SCROLLS THE ANSWER AND CLEARS THE SCREEN BETWEEN THE SCROLLING. ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ REDRAW_THE_SCREEN: push.l #window ;window that needs to be cleared ; jsr doorsos::WinClr ;CLEAR IT move.l 48(a3),a4 jsr (a4) ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ move.w d6,-(a7) ;push the y move.w d5,-(a7) ;push the x push.l #window ;the window to draw to push.l a2 ;THIS IS THE RESULT OF THE PARSE2D CALL ; jsr doorsos::Print2DExpr ;display it move.l 304(a3),a4 jsr (a4) ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ lea 16(a7),a7 ;in a loop so stack needs to be reset ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ get_another_key_press: jsr userlib::idle_loop ;idle cmp.w #264,d0 ;exit key, but it might not be the same on a beq quit ;92+ cmp.w #KEY_RIGHT,d0 ;These are all ram calls the kernel will beq scroll_right ;fill them in at execute time with what cmp.w #KEY_LEFT,d0 ;they should be beq scroll_left cmp.w #KEY_DOWN,d0 beq scroll_down cmp.w #KEY_UP,d0 beq scroll_up bra get_another_key_press ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ scroll_right: move.w d5,d1 ;copy of x add.w width,d1 ;add the width to the x cmp.w #LCD_WIDTH,d1 ;if the width and the x combine to be less than bcs get_another_key_press ;the screen width then it stops it from being add.w #-40,d5 ;scrolled anymore. Remember that the x may be bra REDRAW_THE_SCREEN ;negative. scroll_left: tst.w d5 ;keeps it within bounds the initial x was zero beq get_another_key_press ;so if x is currently zero then it can not be add.w #40,d5 ;scrolled left. bra REDRAW_THE_SCREEN scroll_up: cmp.w d4,d6 ;check if the current y is the same as the beq get_another_key_press ;initial y, this is similar to the limitations add.w #28,d6 ;of the scroll left, except that the initial y bra REDRAW_THE_SCREEN ;can vary and so must be stored in a register. scroll_down: move.w d6,d0 ;add the y to the bottom half and if the result add.w bottom_half,d0 ;is greater than the height of the screen then cmp.w #LCD_HEIGHT-7,d0 ;the variable can not be scrolled. Remember bcs get_another_key_press ;that y may be negative. add.w #-28,d6 bra REDRAW_THE_SCREEN quit: push.l #window ;the window to close ; jsr doorsos::WinClose ;CLOSE IT move.l 44(a3),a4 jsr (a4) window_was_not_made: too_many_arguments: move.l a6,a7 ;RESET THE STACK move.l a4,(a5) ;reset the expression stack rts ;RETURN ;---------------------------------------------------------------------------------------- ;---------------------------------------------------------------------------------------- ; DATA ;---------------------------------------------------------------------------------------- ;---------------------------------------------------------------------------------------- rect dc.w 0,0,LCD_WIDTH,LCD_HEIGHT-8 ;SUBTRACT EIGHT SO THAT IT DOES NOT OVER ;LAP THE STATUS BAR width dc.w 0 bottom_half dc.w 0 top_half dc.w 0 BSS ; uninitialized data window ds.l 60 end