*********************************************************************** * CML Demo Program 28 May 1997 Michael Burke * VT100/ANSI Escape Code Demonstration * * This program demonstrates how to use the various VT100/ANSI escape * code sequences. * *********************************************************************** *********************************************************************** * Initialization routine - jumps straight to the * beginning of code, with the data inbetween * Input: None * Output: All * Modifies: Just about everything *********************************************************************** ORG $C000 JMP START *********************************************************************** * Data Segment - EQU's, constants and variables here * Input: None * Output: None *********************************************************************** * Equates ("Magic Numbers" and BUFFALO routines) OUTCRLF EQU $FFC4 ; prints a LF and a CR INPUT EQU $FFAC ; Input without polling OUTA EQU $FFB8 ; Output ASCII character in ACCA UPCASE EQU $FFA0 ; Lower -> upper case conversion OUTPUT EQU $FFAF ; outputs a single character -> SCI * Put a stack in our program (mostly for BUFFALO/interrupt calls) * (Note: This stack is probably WAY too large for our needs, as * nested calls which fill the stack are mostly absent. However, * since our data immediately follows the stack, an overflow could * be very messy...) STACK RMB $100 ; 256 byte stack INITSP EQU *-1 ; Stack pointer initializer * VT100/ANSI Escape codes (Generic) * These escape codes do not have specific {NUM} or position * variables inside them; those are included in the next section * (program specific). * [NOTE: Most of these codes are not used in this demonstration; * they are included to avoid duplication of effort.] RESET FCB $1B ; Resets all terminal settings to default FCB $63 FCB $04 ELINEW FCB $1B ; Enables wrapping text to the next line FCB $5B ; if text is no longer than the display FCB $37 ; area. FCB $68 FCB $04 DLINEW FCB $1B ; Disables wrapping text; text will be FCB $5B ; clipped if longer than display area. FCB $37 FCB $6C FCB $04 CURHOME FCB $1B ; Moves the cursor to the home position FCB $5B FCB $48 FCB $04 CURUP FCB $1B ; Moves the cursor up one row. FCB $5B FCB $41 FCB $04 CURDOWN FCB $1B ; Moves the cursor down one row. FCB $5B FCB $42 FCB $04 CURLEFT FCB $1B ; Moves the cursor left one column. FCB $5B FCB $44 FCB $04 CURIGHT FCB $1B ; Moves the cursor right one column. FCB $5B FCB $43 FCB $04 CURSAVE FCB $1B ; Saves the current cursor position. FCB $5B FCB $73 FCB $04 CURREST FCB $1B ; Restores the previously saved position. FCB $5B FCB $75 FCB $04 CLREOL FCB $1B ; Erases from the current cursor position FCB $5B ; to the end of the row. FCB $4B FCB $04 CLRSOL FCB $1B ; Erases from the current cursor position FCB $5B ; to the beginning of the row. FCB $31 FCB $4B FCB $04 CLRLINE FCB $1B ; Erases the row the cursor is in. FCB $5B FCB $32 FCB $4B FCB $04 CLRDOWN FCB $1B ; Erases from the current cursor position FCB $5B ; to the bottom of the screen. FCB $4A FCB $04 CLRUP FCB $1B ; Erases from the current cursor position FCB $5B ; to the top of the screen. FCB $31 FCB $4A FCB $04 CLRALL FCB $1B ; Erases the entire screen and places the FCB $5B ; cursor in the home position. FCB $32 FCB $4A FCB $04 SCROLLA FCB $1B ; Set the whole screen as 'scrollable'. FCB $5B FCB $72 FCB $04 SCROLLD FCB $1B ; Scroll one line down. FCB $44 FCB $04 SCROLLU FCB $1B ; Scroll one line up. FCB $4D FCB $04 * VT100/ANSI Escape codes (Program specific) * (These codes contain code specific to this program) WHITE FCB $1B ; Make the cursor white FCB $5B FCB $33 FCB $37 FCB $6D FCB $04 RED FCB $1B ; Make the cursor red FCB $5B FCB $33 FCB $31 FCB $6D FCB $04 GREEN FCB $1B ; Make the cursor green FCB $5B FCB $33 FCB $32 FCB $6D FCB $04 RSTCUR FCB $1B ; Resets the cursor attributes FCB $5B FCB $30 FCB $6D FCB $04 BLNKCUR FCB $1B ; Blink the cursor FCB $5B FCB $35 FCB $6D FCB $04 BRTCUR FCB $1B ; Bright cursor FCB $5B FCB $31 FCB $6D FCB $04 CURCNTR FCB $1B ; Center the cursor on the screen FCB $5B FCB $31 FCB $32 FCB $3B FCB $34 FCB $30 FCB $48 FCB $04 PAKCNTR FCB $1B ; Center the words "Press any key to continue" FCB $5B ; at the bottom of the screen FCB $32 FCB $33 FCB $3B FCB $32 FCB $37 FCB $48 FCB $04 * Program text; predefined text for the demo HEADR1 FCC `CML Demonstration: VT100/ANSI Escape Sequences v1.0 6 June 1997` FCB $04 HEADR2 FCC `=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=` FCB $04 INST1 FCC ` To move the cursor, use the I J K L keys as shown below. moves the` FCB $04 INST2 FCC ` cursor up, moves the cursor left, moves the cursor right, and ` FCB $04 INST3 FCC ` moves the cursor down.` FCB $04 INST4 FCC ` ^` FCB $04 INST5 FCC ` Press to make the cursor WHITE. |` FCB $04 INST6 FCC ` Press to make the cursor RED. ` FCB $04 INST7 FCC ` Press to make the cursor GREEN. <- ->` FCB $04 INST8 FCC ` ` FCB $04 INST9 FCC ` Press to HOME the cursor (in the center). |` FCB $04 INSTA FCC ` Press to CLEAR the screen. V` FCB $04 INSTB FCC ` Press <[> to pick up the "pen", and` FCB $04 INSTC FCC ` Press <]> to put the "pen" down.` FCB $04 INSTD FCC ` Press to QUIT this demonstration.` FCB $04 PAKTC FCC `Press any key to continue...` FCB $04 END1 FCC ` Written : 6 June 1997.` FCB $04 * Save the state of the cursor CURSTA FCB $00 ; Cursor state: $00 if up, $01 if down *********************************************************************** * START Start of the program * Input: None * Output: VT100/ANSI Demo * Modifies: Just about everything *********************************************************************** START LDS #INITSP ; Initializes the stack LDAD #$00 ; If you dont put initial values into the LDX #$0000 ; registers, you can get unexpected results LDY #$0000 ; if you try to push them onto the stack. CLI ; Enable interrupts globally JSR RSCREEN ; Clear the screen JSR PRNTHDR ; Print the header JSR OUTCRLF JSR PRNTINS ; Print instructions JSR PRNTKEY ; Press any key to continue JSR RSCREEN JSR CENTER ; Center the cursor LOOP JSR GETKEY ; Gets key (returns in B) JSR DRAW ; Use the keypress (returns 00 in B if quit) TSTB BNE LOOP ; End if 00, otherwise LOOP JSR RSCREEN JSR PRNTHDR JSR OUTCRLF JSR ENDSCRN ; Print an ending screen SWI ; Return control to the simulator or BUFFALO *********************************************************************** * RSCREEN Reset the screen * Input: None * Output: Clears the screen, and returns to the home position * Modifies: Nothing *********************************************************************** RSCREEN PSHA ; Push registers so they are returned as they PSHX ; were received. LDX #CURHOME JSR STRGOUT LDX #CLRALL JSR STRGOUT ; Clear the screen PULX ; Restore the original register values PULA RTS ; Go home. *********************************************************************** * PRNTHDR Prints the two line program title bar * Input: None * Output: 2 Lines of text, starting wherever the cursor is. * Modifies: Nothing *********************************************************************** PRNTHDR PSHA ; Push registers so they are returned as they PSHX ; were received. LDX #GREEN JSR STRGOUT LDX #HEADR1 JSR STRGOUT ; Print the header JSR OUTCRLF LDX #HEADR2 JSR STRGOUT JSR OUTCRLF LDX #WHITE JSR STRGOUT PULX ; Restore the original register values PULA RTS ; Go home. *********************************************************************** * ENDSCRN Output the quit screen * Input: None * Output: Some text * Modifies: Nothing *********************************************************************** ENDSCRN PSHA ; Push registers so they are returned as they PSHX ; were received. LDX #END1 JSR STRGOUT ; Print the header JSR OUTCRLF JSR OUTCRLF PULX ; Restore the original register values PULA RTS ; Go home. *********************************************************************** * DELAY Delays A/10'ths of a second * Input: Register A * Output: Register A/10 seconds of delay * Modifies: Nothing *********************************************************************** DELAY PSHA ; Push registers so they are returned as they PSHB ; were received. PSHX PSHY DELLP1 CMPA #$00 BEQ DELDNE DECA LDY #$0000 DELLP2 IDIV INY CPY #$0A00 BHS DELLP1 BRA DELLP2 DELDNE PULY ; Restore the original register values. PULX PULB PULA RTS ; Go home. *********************************************************************** * PRNTHDR Prints the instructions * Input: None * Output: Text * Modifies: Nothing *********************************************************************** PRNTINS PSHA ; Push registers so they are returned as they PSHX ; were received. LDX #INST1 JSR STRGOUT ; Print the instructions (long...) JSR OUTCRLF LDX #INST2 JSR STRGOUT JSR OUTCRLF LDX #INST3 JSR STRGOUT JSR OUTCRLF LDX #INST4 JSR STRGOUT JSR OUTCRLF LDX #INST5 JSR STRGOUT JSR OUTCRLF LDX #INST6 JSR STRGOUT JSR OUTCRLF LDX #INST7 JSR STRGOUT JSR OUTCRLF LDX #INST8 JSR STRGOUT JSR OUTCRLF LDX #INST9 JSR STRGOUT JSR OUTCRLF LDX #INSTA JSR STRGOUT JSR OUTCRLF LDX #INSTB JSR STRGOUT JSR OUTCRLF LDX #INSTC JSR STRGOUT JSR OUTCRLF LDX #INSTD JSR STRGOUT JSR OUTCRLF PULX ; Restore the original register values PULA RTS ; Go home. *********************************************************************** * PRNTKEY "Press any key to continue..." * Input: None * Output: One ine of text starting at (23,27) * Modifies: Nothing *********************************************************************** PRNTKEY PSHA ; Push registers so they are returned as they PSHX ; were received. LDX #RED ; Red text JSR STRGOUT LDX #BLNKCUR ; Blinking JSR STRGOUT LDX #BRTCUR JSR STRGOUT LDX #PAKCNTR ; Place the cursor where we need it (23,27) JSR STRGOUT LDX #PAKTC ; Text JSR STRGOUT PKLOOP JSR INPUT ; Wait for a keypress TSTA BEQ PKLOOP LDX #RSTCUR ; Reset cursor attributes JSR STRGOUT LDX #WHITE JSR STRGOUT PULX ; Restore the original register values PULA RTS ; Go home. *********************************************************************** * CENTER Centers the cursor * Input: None * Output: Centered cursor * Modifies: Nothing *********************************************************************** CENTER PSHA ; Push registers so they are returned as they PSHX ; were received. LDX #CURCNTR JSR STRGOUT PULX ; Restore the original register values PULA RTS ; Go home. *********************************************************************** * GETKEY Gets a keypress * Input: None * Output: The ASCII value of the key in REG B * Modifies: Reg B *********************************************************************** GETKEY PSHA ; Store unmodified registers GETLOOP JSR INPUT TSTA BEQ GETLOOP TAB PULA ; Restore original values. RTS ; Go home. *********************************************************************** * DRAW Draws according to Reg B * Input: Reg B * Output: Draws something on the screen * Modifies: Reg B *********************************************************************** DRAW PSHA ; Store unmodified registers PSHX TBA JSR UPCASE TAB CMPB #$49 ; Is it up? BEQ DUP CMPB #$4A ; Is it left? BEQ DLEFT CMPB #$4C ; Is it right? BEQ DRIGHT CMPB #$4B ; Is it down? BEQ DDOWN CMPB #$57 ; White? BEQ DWHITE CMPB #$52 ; Red? BEQ DRED CMPB #$47 ; Green? BEQ DGREEN CMPB #$48 ; Home? BEQ DHOME CMPB #$43 ; Clear screen? BEQ DCLR CMPB #$5B ; Pick up the pen? BNE D1 LDAA #$00 STAA CURSTA BRA DRET D1 CMPB #$5D ; Put the pen down? BNE D2 LDAA #$01 STAA CURSTA BRA DRET D2 CMPB #$51 ; Quit? BEQ DQUIT BRA DERROR DRET LDAA CURSTA ; Is the pen up or down? CMPA #$00 BEQ DRET2 ; If CURSTA=00, up so therefore don't draw. LDX #CURSAVE JSR STRGOUT LDAA #$23 ; # Pound sign JSR OUTA LDX #CURREST JSR STRGOUT DRET2 PULX ; Return here when done above PULA ; Restore values in pushed registers. RTS ; Go home. *********************************************************************** * DUP Draw UP * Input: None * Output: One charater drawn up * Modifies: REG X *********************************************************************** DUP LDX #CURUP JSR STRGOUT BRA DRET *********************************************************************** * DDOWN Draw DOWN * Input: None * Output: One charater drawn down * Modifies: REG X *********************************************************************** DDOWN LDX #CURDOWN JSR STRGOUT BRA DRET *********************************************************************** * DLEFT Draw LEFT * Input: None * Output: One charater drawn left * Modifies: REG X *********************************************************************** DLEFT LDX #CURLEFT JSR STRGOUT BRA DRET *********************************************************************** * DRIGHT Draw RIGHT * Input: None * Output: One charater drawn right * Modifies: REG X *********************************************************************** DRIGHT LDX #CURIGHT JSR STRGOUT BRA DRET *********************************************************************** * DWHITE Change color to white * Input: None * Output: One character drawn white * Modifies: REG X *********************************************************************** DWHITE LDX #WHITE JSR STRGOUT BRA DRET *********************************************************************** * DRED Change color to red * Input: None * Output: One charater drawn red * Modifies: REG X *********************************************************************** DRED LDX #RED JSR STRGOUT BRA DRET *********************************************************************** * DGREEN Change color to green * Input: None * Output: One charater drawn green * Modifies: REG X *********************************************************************** DGREEN LDX #GREEN JSR STRGOUT BRA DRET *********************************************************************** * DHOME Home the cursor * Input: None * Output: One charater drawn in the center * Modifies: REG X *********************************************************************** DHOME LDX #CURCNTR JSR STRGOUT BRA DRET *********************************************************************** * DCLR Clear the screen * Input: None * Output: One charater drawn * Modifies: REG X *********************************************************************** DCLR LDX #CURSAVE JSR STRGOUT LDX #CLRALL JSR STRGOUT LDX #CURREST JSR STRGOUT BRA DRET *********************************************************************** * DQUIT Quit drawing * Input: None * Output: Quit drawing * Modifies: ACCB *********************************************************************** DQUIT LDAB #$00 ; Load ACCB with the 'quit' sequence BRA DRET2 *********************************************************************** * DERROR An error * Input: None * Output: Beep * Modifies: ACCA *********************************************************************** DERROR LDAA #$07 ; A beep JSR OUTA BRA DRET2 *********************************************************************** * STRGOUT String output - outputs a string with no leading * or trailing CRLF's... similar to the BUFFALO OUTSTRG * (This one does not wait on CTRL-W however) * Input: Register X points to the text location - terminate * with a $04 * Output: Text * Modifies: Nothing *********************************************************************** STRGOUT PSHA STRGOT1 LDAA 0,X CMPA #$04 BEQ STRGOT3 JSR OUTPUT INX BRA STRGOT1 STRGOT3 PULA RTS