;
;VECTCLK PROGRAM is the code for the Doran Engineering Electronic Vector Clock.
;                It draws an analogue clock-face on the unit's CRT display using
;                the G02 interface originally built for the SCALE-7 micro-
;                processor system. The position of the clock's hands are 
;                determined by the program's internal time reference, which is
;                advanced by a 1 Hz external signal connected to the Z80 NMI
;                input.  The clock may also be stopped, and the minutes or hours
;                set, by manual controls.  The minute and hour setting functions
;                are connected to the Z80 INT input.  
;
;                Revision History:
;
;                1.0 -- Basic completed program, as described above. 12-hour
;                       analogue clock mode only.  (VECT00.MAC) 10/25/2001.
;
;                2.0 -- Added digital clock mode, and 24-hour capability for both 
;                       analogue and digital modes. (VECT01.MAC) 11/06/2001.
;
		.Z80			;program is Z80 assembly language
;
;I/O port addresses.
;
XMOVE		EQU	0E0H		;XMOVE port address
YMOVE		EQU	0E1H		;YMOVE port address
XSTORE		EQU	0E2H		;XSTORE port address
YDRAW		EQU	0E3H		;YDRAW port address
RESINT          EQU     00H             ;WRITE resets external interrupts
SWITCH          EQU     00H             ;READ loads manual control settings
;
;Program constants.
;
TICNUM          EQU     03		;number of times to draw hours tic marks
SECNUM          EQU     010             ;number of times to draw sec and min hands
HOUNUM          EQU     05              ;number of times to draw hour hand
;
;Program code begins here.  First, we initialize everything on power-up. 
;
		ASEG
		ORG	0000H		;starts at absolute address zero
START:		DI			;with interrupts disabled 	 
		LD      SP,087FFH       ;initialize stack to top of RAM
                LD      A,00            ;preset default seconds, minutes, hours
                LD      (SECONDS),A
                LD      (AMPM),A
                LD      A,010
                LD      (MINUTES),A
                LD      (HOURS),A
                LD      (HRS24),A
                LD      A,02H           ;set up SHORT and LONG time constants
                LD      (SCON),A
                LD      A,025H
                LD      (LCON),A
                IM      1               ;now, enable interrupts
                EI
                JP      MAIN            ;and then go execute the main program
;
;EXTERNAL INTERRUPT code starts here.  Ext ints, caused by operation of the SET
;HOUR or SET MIN controls, vector to absolute address 0038H.  This code will
;either advance the minutes or the hours, depending upon which button was
;depressed.
;
                ORG     0038H           ;ext int vector address
EXT_INT:        PUSH    AF              ;save the accumulator and flags
                CALL    SET             ;set the clock
                OUT     (RESINT),A      ;clear the external interrupt source
                POP     AF              ;recover the accumulator and flags
                IM      1               ;re-enable interrupts
                EI                       
                RETI                    ;and go back to drawing the clock
;
;NON-MASKABLE INTERRUPT code starts here.  NMIs, which arrive once each second
;from the external line-operated scaler, vector to absolute address 0066H. This
;code advances the clock by one second.
;
                ORG     0066H           ;NMI vector address
NM_INT:         DI                      ;disable maskable interrupts
		PUSH    AF              ;save the accumulator and flags
                CALL    TIMEKPR         ;advance the clock's time reference 
                POP     AF              ;recover
                IM      1               ;re-enable maskable interrupts
		EI 
                RETN                    ;and go back to drawing the clock
;
;MAIN PROGRAM begins here.  It reads the manual controls to determine the
;             correct mode of operation (ANALOGUE, DIGITAL, or CALIBRATE) and
;             then calls the appropriate subroutine.  Determination and
;             implementation of the two sub-modes, 12-hour and 24-hour, is
;             accomplished within the individual primary mode subroutines
;             themselves.  MAIN is a loop, which executes continuously.  
;
MAIN:         	IN	A,(SWITCH)	;read the manual controls
                BIT     3,A             ;CALIBRATE mode?
                JP      Z,GOCAL         ;then go do it
                BIT     2,A             ;otherwise, is it DIGITAL mode?
                JP      Z,GODIG         ;then go do it
;
GOANA:		LD      A,025		;program optimum LONG value for analogue
                LD      (LCON),A
                CALL    ANALOGUE        ;and do ANALOGUE mode
                JP      MAIN            ;again and again
;
GODIG:          LD      A,030H          ;program optimum LONG for digital
                LD      (LCON),A
	        CALL    DIGITAL         ;and do DIGITAL mode
                JP      MAIN            ;again and again
;
GOCAL:          LD      A,030H          ;program optimum LONG for calibrate
                LD      (LCON),A
                CALL    CALIBRATE       ;CALIBRATE mode
                JP      MAIN            ;again and again
;
;PROGRAM SUBROUTINES follow.
;
;ANALOGUE SUBROUTINE executes the analogue clock mode of operation. It draws
;                    a traditional clock face on the CRT display.  It calls the
;                    BEZEL, SECTIC, HOUTIC, NUM12, NUM24A, NUM24B, SECHAND,
;                    MINHAND, and HOUHAND subroutines.
;
ANALOGUE: 	IN	A,(SWITCH)	;read the manual controls
                BIT     1,A             ;24 hour mode?
                JP      Z,ANA24         ;if so, go execute 24-hour code
;
;the following code assumes 12-hour mode of operation.  
;
                CALL    NUM12           ;draw the numerals for a 12-hour clock
                JP      FACE            ;and then the rest of it
;
;the following code is for 24-hour mode of operation.  For times classified as
;"AM" in 12-hour mode, it displays numerals 0 through 11.  For "PM", it displays
;12 through 23.
;
ANA24:          LD      A,(AMPM)        ;get the AM/PM indicator
                CP      0FFH            ;"PM"?
                JP      Z,PMNUMS        ;if so, go draw the "PM" numerals
                CALL    NUM24A          ;if not, draw numerals for "AM"
                JP      FACE            ;and go draw the rest of it
PMNUMS:         CALL    NUM24P          ;numerals for "PM"
;
;the following code draws the rest of the clock face, such as the circular
;bezel, ledger lines, and hands. It is the same for both 12-hour and 24-hour
;operation.
;
FACE:           CALL    BEZEL           ;draw the bezel
		CALL    SECTIC          ;draw the seconds tic marks
                CALL    HOUTIC          ;draw the hours tic marks
                CALL    SECHAND         ;draw the second hand
                CALL    MINHAND         ;draw the minute hand
                CALL    HOUHAND         ;draw the hour hand
;
                RET                     ;and done
;
;NUM12 SUBROUTINE provides starting coordinates and calls individual numeral-
;                 drawing subroutines (ZERO through NINE) to draw the clock's
;                 numerals.  This subroutine is used for the 12-hour analogue
;                 clock mode, AM and PM.
;
NUM12:          LD      B,0114          ;draw a 1 at  (left digit of 12)
		LD      C,0214
		CALL    ONE
                LD      B,0129          ;draw a 2 at  (right digit of 12)
		LD      C,0214
                CALL    TWO
;
                LD      B,0173          ;draw 1 
		LD      C,0201
		CALL    ONE
;
                LD      B,0210          ;draw 2 
		LD      C,0165
		CALL    TWO
;
                LD      B,0224          ;draw 3 
                LD      C,0118
                CALL    THREE 
;
		LD      B,0210          ;draw 4
		LD      C,070
		CALL    FOUR
;        
		LD      B,0172          ;draw 5
		LD      C,034  
                CALL    FIVE
;
                LD      B,0122          ;draw 6 
                LD      C,021
                CALL    SIX
;
		LD	B,074		;draw 7
		LD      C,034
		CALL    SEVEN
;
		LD      B,036           ;draw 8
		LD      C,070
		CALL    EIGHT
;
                LD      B,021           ;draw 9 
                LD      C,0118   
                CALL    NINE
;
		LD      B,032           ;draw a 1 at  (left digit of 10)
		LD      C,0165
                CALL    ONE
                LD      B,047           ;draw a 0 at (right digit of 10)
                LD      C,0165
                CALL    ZERO
;
                LD      B,069           ;draw a 1 at  (left digit of 11)
                LD      C,0201
                CALL    ONE
		LD      B,082           ;draw a 1 at  (right digit of 11)
		LD      C,0201
                CALL    ONE
;
		RET
;
;NUM24A SUBROUTINE provides starting coordinates and calls individual numeral-
;                  drawing subroutines (ZERO through NINE) to draw the clock's
;                  numerals.  This subroutine is used for the "AM" portion of
;                  the 24-hour analogue clock mode (0000 through 1200 hours).
;
NUM24A:         LD      B,0122          ;draw 0 
		LD      C,0214
		CALL    ZERO
;
                LD      B,0173          ;draw 1 
		LD      C,0201
		CALL    ONE
;
                LD      B,0210          ;draw 2 
		LD      C,0165
		CALL    TWO
;
                LD      B,0224          ;draw 3 
                LD      C,0118
                CALL    THREE 
;
		LD      B,0210          ;draw 4
		LD      C,070
		CALL    FOUR
;        
		LD      B,0172          ;draw 5
		LD      C,034  
                CALL    FIVE
;
                LD      B,0122          ;draw 6 
                LD      C,021
                CALL    SIX
;
		LD	B,074		;draw 7
		LD      C,034
		CALL    SEVEN
;
		LD      B,036           ;draw 8
		LD      C,070
		CALL    EIGHT
;
                LD      B,021           ;draw 9 
                LD      C,0118   
                CALL    NINE
;
		LD      B,032           ;draw a 1 at  (left digit of 10)
		LD      C,0165
                CALL    ONE
                LD      B,047           ;draw a 0 at (right digit of 10)
                LD      C,0165
                CALL    ZERO
;
                LD      B,069           ;draw a 1 at  (left digit of 11)
                LD      C,0201
                CALL    ONE
		LD      B,082           ;draw a 1 at  (right digit of 11)
		LD      C,0201
                CALL    ONE
;
		RET
;
;NUM24P SUBROUTINE provides starting coordinates and calls individual numeral-
;                  drawing subroutines (ZERO through NINE) to draw the clock's
;                  numerals.  This subroutine is used for the "PM" portion of
;                  the 24-hour analogue clock mode (1200 through 2400 hours).
;
NUM24P:         LD      B,0114          ;draw a 1 at (left digit of 12)
		LD      C,0214
		CALL    ONE
                LD      B,0129          ;draw a 2 at (right digit of 12)
		LD      C,0214
                CALL    TWO
;
                LD      B,0158		;draw a 1 at (left digit of 13)
                LD      C,0201
                CALL    ONE
                LD      B,0173          ;draw a 3 at (right digit of 13) 
		LD      C,0201
		CALL    THREE
;
                LD      B,0195          ;draw a 1 at (left digit of 14)
                LD      C,0165
                CALL    ONE
                LD      B,0210          ;draw a 4 at (right digit of 14) 
		LD      C,0165
		CALL    FOUR
;
                LD      B,0209          ;draw a 1 at (left digit of 15)
                LD      C,0118
                CALL    ONE
                LD      B,0224          ;draw a 5 at (right digit of 15) 
		LD      C,0118
		CALL    FIVE
;
                LD      B,0195          ;draw a 1 at (left digit of 16)
                LD      C,070
                CALL    ONE
                LD      B,0210          ;draw a 6 at (right digit of 16) 
		LD      C,070
		CALL    SIX
;
                LD      B,0157          ;draw a 1 at (left digit of 17)
                LD      C,034
                CALL    ONE
                LD      B,0172          ;draw a 7 at (right digit of 17) 
		LD      C,034
		CALL    SEVEN
;
                LD      B,0114          ;draw a 1 at (left digit of 18)
                LD      C,021
                CALL    ONE
                LD      B,0129          ;draw an 8 at (right digit of 18) 
		LD      C,021
		CALL    EIGHT
;
                LD      B,074           ;draw a 1 at (left digit of 19)
                LD      C,034
                CALL    ONE
                LD      B,089           ;draw a 9 at (right digit of 19) 
		LD      C,034
		CALL    NINE
;
                LD      B,036           ;draw a 2 at (left digit of 20)
                LD      C,070
                CALL    TWO
                LD      B,051           ;draw a 0 at (right digit of 20) 
		LD      C,070
		CALL    ZERO
;
                LD      B,021           ;draw a 2 at (left digit of 21)
                LD      C,0118
                CALL    TWO
                LD      B,036           ;draw a 1 at (right digit of 21) 
		LD      C,0118
		CALL    ONE
;
                LD      B,032           ;draw a 2 at (left digit of 22)
                LD      C,0165
                CALL    TWO
                LD      B,047           ;draw a 2 at (right digit of 22) 
		LD      C,0165
		CALL    TWO
;
                LD      B,069           ;draw a 2 at (left digit of 23)
                LD      C,0201
                CALL    TWO
                LD      B,084           ;draw a 3 at (right digit of 23) 
		LD      C,0201
		CALL    THREE
;
		RET
;
;BEZEL SUBROUTINE draws the clock's bezel, a circle of radius 127 counts.  It
;                 calls the SHORT and LONG subroutines, and accesses the
;                 coordinate table CIRC0.
;               
BEZEL:		LD	A,114		;set origin to (move pen to) 114,253 
		OUT     (XMOVE),A
                LD      A,253
		OUT	(YMOVE),A
		CALL	SHORT		;delay 10 us to alLow DACs to stabilize
;
BEGIN0:         LD      B,60            ;get number of vectors to draw
                LD      HL,CIRC0        ;point to start of vector table
;
DRAW0:          LD      A,(HL)          ;load x-coord of destination 
                OUT     (XSTORE),A
                INC     HL
                LD      A,(HL)          ;load y-coord and draw the vector
                OUT     (YDRAW),A
                INC     HL
                CALL    LONG            ;wait for vector to draw
;
                DEC     B               ;draw next vector
                JP      NZ,DRAW0
;
                RET
;
;SECTIC SUBROUTINE draws the clock's seconds tic marks.  It calls the SHORT and
;                  LONG subroutines and accesses coordinate tables CIRC0 and CIRC1.                  CIRC1.
;
SECTIC:         LD      D,60            ;get number of vectors to draw
                LD      HL,CIRC0        ;point to start of coordinate tables
                LD      BC,CIRC1
;
DRAW1:          LD      A,(HL)          ;move pen to vector start coordinates
		OUT     (XMOVE),A
		INC     HL
		LD      A,(HL)
		OUT     (YMOVE),A
		INC     HL 
                CALL    SHORT           ;delay 10 us to allow DACs to stabilize
;	
		LD      A,(BC)          ;draw vector to endpoint coordinates
		OUT     (XSTORE),A
		INC     BC
                LD      A,(BC)
		OUT     (YDRAW),A
                INC     BC
		CALL    LONG            ;and wait for it to be completed
;
		DEC     D               ;next vector
		JP      NZ,DRAW1
;
		RET
;
;
;HOUTIC SUBROUTINE draws the clock's hours tic marks.  It essentially writes
;                  over every fifth seconds tic mark to make them bolder.  It
;                  calls the SHORT and LONG subroutines and accesses coordinate
;                  tables CIRC0 and CIRC1.
;
HOUTIC:         LD      E,HOUNUM        ;get number of times to draw tics
LOOP3:          LD      D,12            ;get number of vectors to draw each time
                LD      HL,CIRC0        ;point to start of coordinate tables
                LD      BC,CIRC1
;
DRAW2:          LD      A,(HL)          ;move pen to vector start coordinates
		OUT     (XMOVE),A
		INC     HL
		LD      A,(HL)
		OUT     (YMOVE),A
		INC     HL              ;point to next start
                INC     HL
                INC     HL
                INC     HL
                INC     HL          
         	INC     HL 
                INC     HL
                INC     HL
                INC     HL
                CALL    SHORT           ;delay 10 us to allow DACs to stabilize
;	
		LD      A,(BC)          ;draw vector to endpoint coordinates
		OUT     (XSTORE),A
		INC     BC
                LD      A,(BC)
		OUT     (YDRAW),A
                INC     BC		;point to next endpoint
                INC     BC
		INC     BC
		INC	BC
		INC     BC
                INC     BC
		INC     BC
		INC	BC
		INC	BC
		CALL    LONG            ;and wait for it to be completed
;
		DEC     D               ;next vector
		JP      NZ,DRAW2
;
		DEC     E              
                JP      NZ,LOOP3        ;draw tics the requisite number of times
		RET			;before returning
;
;SECHAND SUBROUTINE draws the clock's second hand.  It calls the SHORT and LONG
;                   subroutines and accesses coordinate table CIRC2.
;
SECHAND:	LD	A,(SECONDS)	;take the number of seconds (0 to 59)
                SLA     A		;multiply by two
		LD      C,A             ;put it in BC as an index
		LD      B,0
                LD      HL,CIRC2        ;get base address
                ADD     HL,BC           ;generate indexed address pointing to x
                LD      A,(HL)          ;get x
                LD      (X),A           ;save it
                INC     HL              ;point to y
		LD      A,(HL)          ;get y
		LD      (Y),A           ;save it
;
                LD      D,SECNUM        ;get number of times to draw hand
DRAW3:		LD      A,0127          ;move beam to center of dial
                OUT     (XMOVE),A
                OUT     (YMOVE),A
                CALL    SHORT           ;let DACs stabilize
                LD      A,(X)           ;draw the hand from center to x,y
		OUT     (XSTORE),A
                LD      A,(Y)
		OUT     (YDRAW),A
                CALL    LONG
                DEC     D             
                JP      NZ,DRAW3        ;draw the requisite number of times
		RET                     ;before returning
;
;MINHAND SUBROUTINE draws the clock's minute hand.  It calls the SHORT and LONG
;                   subroutines and accesses coordinate table CIRC2.
;
MINHAND:	LD	A,(MINUTES)	;take the number of minutes (0 to 59)
                SLA     A		;multiply by two
		LD      C,A             ;put it in BC as an index
		LD      B,0
                LD      HL,CIRC2        ;get base address
                ADD     HL,BC           ;generate indexed address pointing to x
                LD      A,(HL)          ;get x
                LD      (X),A           ;save it
                INC     HL              ;point to y
		LD      A,(HL)          ;get y
		LD      (Y),A           ;save it
;
                LD      D,SECNUM        ;get number of times to draw hand
DRAW4:		LD      A,0127          ;move beam to center of dial
                OUT     (XMOVE),A
                OUT     (YMOVE),A
                CALL    SHORT           ;let DACs stabilize
                LD      A,(X)           ;draw the hand from center to x,y
		OUT     (XSTORE),A
                LD      A,(Y)
		OUT     (YDRAW),A
                CALL    LONG
                DEC     D             
                JP      NZ,DRAW4        ;draw the requisite number of times
		RET                     ;before returning
;
;HOUHAND SUBROUTINE draws the clock's hour hand.  It calls the SHORT and LONG
;                   subroutines and accesses coordinate table CIRC3.
;
HOUHAND:	LD	A,(HOURS)	;take the number of hours (0 to 11)
                SLA     A		;multiply by two
		LD      C,A             ;put it in BC as an index
		LD      B,0
                LD      HL,CIRC3        ;get base address
                ADD     HL,BC           ;generate indexed address pointing to x
                LD      A,(HL)          ;get x
                LD      (X),A           ;save it
                INC     HL              ;point to y
		LD      A,(HL)          ;get y
		LD      (Y),A           ;save it
;
                LD      D,HOUNUM        ;get number of times to draw hand
DRAW5:		LD      A,0127          ;move beam to center of dial
                OUT     (XMOVE),A
                OUT     (YMOVE),A
                CALL    SHORT           ;let DACs stabilize
                LD      A,(X)           ;draw the hand from center to x,y
		OUT     (XSTORE),A
                LD      A,(Y)
		OUT     (YDRAW),A
                CALL    LONG
                DEC     D             
                JP      NZ,DRAW5        ;draw the requisite number of times
		RET                     ;before returning
;
;DIGITAL SUBROUTINE implements the digital clock function.  It calls the
;                   NUMBER, BIGAY, BIGPEE, BIGEM, and COLON subroutines to draw 
;                   the digits and AM/PM indicators on the display. 
;
DIGITAL: 	IN	A,(SWITCH)	;read the manual controls
                BIT     1,A             ;24 hour mode?
                JP      Z,DIG24         ;if so, go execute 24-hour code
;
;the following code assumes 12-hour operation.  It displays the hours, and then
;either AM or PM.
;
                LD      B,026           ;load BC with the coordinates for the
                LD      C,0134          ;most-significant hours digit
		LD      A,(HOURS)       ;get the hours
                CALL    BIN2BCD         ;convert it to BCD
                SRL     A               ;retain only the most-significant digit
                SRL     A
                SRL     A
                SRL     A
                CALL    NUMBER          ;put it on the display
                LD      B,075           ;load coords for least-significant digit
                LD      C,0134
                LD      A,(HOURS)       ;get the hours again
                CALL    BIN2BCD         ;convert it to BCD
                AND     0FH             ;retain only the least-significant digit
                CALL    NUMBER          ;put it on the display                
; 
                LD      A,(AMPM)        ;PM?
                CP      0FFH            
                JP      Z,PEEOUT        ;if so, go draw a P
AYOUT:          LD      B,0141          ;else it's AM.  Draw an A
                LD      C,052
                CALL    BIGAY
                JP      EMOUT           ;then draw the M
PEEOUT:         LD      B,0141          ;If PM, draw the P first
                LD      C,052
                CALL    BIGPEE
EMOUT:          LD      B,0190          ;and then the M
                LD      C,052
                CALL    BIGEM
                JP      MINSEC          ;then, go display minutes and seconds
;
;the following code displays the hours for 24-hour operation. 
;
DIG24:          LD      B,026           ;load BC with the coordinates for the
                LD      C,0134          ;most-significant hours digit
		LD      A,(HRS24)       ;get the hours
		CALL    BIN2BCD         ;convert it to BCD
                SRL     A               ;retain only the most-significant digit
                SRL     A
                SRL     A
                SRL     A
                CALL    NUMBER          ;put it on the display
                LD      B,075           ;load coords for least-significant digit
                LD      C,0134
                LD      A,(HRS24)       ;get the hours again
		CALL    BIN2BCD         ;convert it to BCD
                AND     0FH             ;retain only the least-significant digit
                CALL    NUMBER          ;put it on the display                
;  
;the following code displays the minutes and seconds.  It is the same for both
;12-hour and 24-hour operation.
;
MINSEC:  	LD      B,0141          ;load BC with the coordinates for the
                LD      C,0134          ;most-significant minutes digit
		LD      A,(MINUTES)     ;get the minutes
		CALL    BIN2BCD         ;convert it to BCD
                SRL     A               ;retain only the most-significant digit
                SRL     A
                SRL     A
                SRL     A
                CALL    NUMBER          ;put it on the display
	        LD      B,0190          ;load coords for least-significant digit
                LD      C,0134
                LD      A,(MINUTES)     ;get the minutes again
		CALL    BIN2BCD         ;convert it to BCD
                AND     0FH             ;retain only the least-significant digit
                CALL    NUMBER          ;put it on the display 
;
                LD      B,0121          ;load BC with the coordinates for the
                LD      C,0134          ;colon (:) between hours and minutes
                CALL    COLON           ;and draw the colon               
;
                LD      B,026           ;load BC with the coordinates for the
                LD      C,052           ;most-significant seconds digit
		LD      A,(SECONDS)     ;get the seconds
		CALL    BIN2BCD         ;convert it to BCD
                SRL     A               ;retain only the most-significant digit
                SRL     A
                SRL     A
                SRL     A
                CALL    NUMBER          ;put it on the display
                LD      B,075           ;load coords for least-significant digit
                LD      C,052
                LD      A,(SECONDS)     ;get the seconds again
		CALL    BIN2BCD         ;convert it to BCD
                AND     0FH             ;retain only the least-significant digit
                CALL    NUMBER          ;put it on the display                
;
                RET                     ;and done
;
;NUMBER SUBROUTINE accepts a BCD digit in the least-significant nybble of the
;                  Accumulator.  It then places the corresponding numeral at
;                  the coordinates stored in BC.  It calls individual numeral-
;                  drawing subroutines (BIGZERO through BIGNINE).
;
NUMBER:         CP      00		;is BCD digit zero?
                JP      Z,DRWZERO       ;if so, go draw zero
                CP      01              ;if not zero, is it one?
                JP      Z,DRWONE        ;if so, go draw one
                CP      02              ;and so on
		JP      Z,DRWTWO
		CP      03
		JP      Z,DRWTHREE
                CP      04
		JP      Z,DRWFOUR
                CP      05
                JP      Z,DRWFIVE
                CP      06
                JP      Z,DRWSIX
                CP      07
                JP      Z,DRWSEVEN
                CP      08  
                JP      Z,DRWEIGHT
                CP      09
                JP      Z,DRWNINE
                RET                     ;if value is not 0-9, ignore it
DRWZERO:        CALL    BIGZERO         ;if zero, draw numeral 0 at (BC)
                RET                     ;and done
DRWONE:         CALL    BIGONE          ;if one, draw numeral 1 at (BC)
                RET			;done
DRWTWO:         CALL    BIGTWO		;and so on
                RET
DRWTHREE:       CALL    BIGTHREE
		RET
DRWFOUR:        CALL    BIGFOUR
                RET
DRWFIVE:        CALL    BIGFIVE
		RET
DRWSIX:		CALL    BIGSIX
		RET
DRWSEVEN:	CALL    BIGSEVEN
		RET
DRWEIGHT:	CALL    BIGEIGHT
		RET
DRWNINE:	CALL    BIGNINE
		RET
;
;BIN2BCD SUBROUTINE accepts a 6-bit binary value, right-justified in the
;                   Accumulator, and returns the two-digit BCD value in the
;                   Accumulator.  The  two most significant bits of the
;                   input byte are set to zero, so any binary value greater
;                   than 63 will be returned as BCD 63.  The subroutine 
;                   accesses memory locations X and Y.
;
BIN2BCD:        PUSH    BC		;save any BC contents so we can use C
                LD      C,06            ;set loop constant
                SLA     A		;left-justify the input
                SLA     A 
                LD      (X),A           ;and store it away
                LD      A,00            ;clear the output to zero
                LD      (Y),A
;
CONVLOOP:       LD      A,(Y)           ;get the output value
                SRL     A               ;now, isolate its MS nybble
                SRL     A
                SRL     A
                SRL     A                    
                SUB     05              ;is it greater than or equal to 5?
                JP      P,ADD3MS        ;if so, go add 3 to it
                JP      CHEKLS          ;if not, do nothing to it!
ADD3MS:         LD      A,(Y)           ;get output 
                ADD     A,030H          ;add three to the MS nybble
                LD      (Y),A           ;and store it back 
;
CHEKLS:         LD      A,(Y)           ;get the output value
                AND     0FH             ;isolate its LS nybble
                SUB     05              ;is it greater than or equal to 5?
                JP      P,ADD3LS        ;if so, go add 3 to it
                JP      SHIFT           ;if not, go shift the input into output
ADD3LS:         LD      A,(Y)           ;get output
                ADD     A,03H           ;add three to the LS nybble
                LD      (Y),A           ;and store it back
;
SHIFT:          LD      A,(Y)           ;get the output
                SLA     A               ;shift it left one bit, putting 0 in LSB
                LD      (Y),A           ;store it back
                LD      A,(X)           ;get the input
                SLA     A               ;shift it left one bit, putting MSB into CF
                LD      (X),A           ;and store it back
                LD      A,(Y)           ;get the shifted output
                ADC     A,00H           ;put CF into its LSB
                LD      (Y),A           ;then store it back
;
                DEC     C               ;decrement the shift count
                JP      Z,BCDDONE       ;zero?  we're done
                JP      CONVLOOP        ;otherwise, keep looping
;          
BCDDONE: 	LD      A,(Y)           ;get the completed BCD output
                POP     BC              ;recover old BC contents
                RET                     ;and that's it
;
;CALIBRATE SUBROUTINE draws a test pattern--a simple square, with diagonals.
;                     It calls the SHORT and LONG subroutines.
;
CALIBRATE:	LD      A,037           ;set the origin at (move beam to) 37,37
		OUT	(XMOVE),A
		OUT	(YMOVE),A
		CALL    SHORT           ;delay 10 us to allow DACs to stabilize
;
		LD      A,0217		;draw a vector from 37,37 to 217,37
                OUT     (XSTORE),A
		LD      A,037
		OUT     (YDRAW),A
                CALL    LONG		;delay 110 us while vector is drawn
;
		LD      A,0217		;draw a vector from 217,37 to 217,217
                OUT     (XSTORE),A
		LD      A,0217
		OUT     (YDRAW),A
                CALL    LONG		;delay 110 us while vector is drawn
;
		LD      A,037		;draw a vector from 217,217 to 37,217
                OUT     (XSTORE),A
		LD      A,0217
		OUT     (YDRAW),A
                CALL    LONG		;delay 110 us while vector is drawn
;
		LD      A,037		;draw a vector from 37,217 to 37,37
                OUT     (XSTORE),A
		LD      A,037
		OUT     (YDRAW),A
                CALL    LONG		;delay 110 us while vector is drawn
;
DIAGS:		LD      A,0217		;draw a vector from 37,37 to 217,217
                OUT     (XSTORE),A
		LD      A,0217
		OUT     (YDRAW),A
                CALL    LONG		;delay 110 us while vector is drawn
;
		LD      A,0217          ;move beam to 217,37
		OUT	(XMOVE),A
                LD      A,037
		OUT	(YMOVE),A
		CALL    SHORT           ;delay 10 us to allow DACs to stabilize
;
		LD      A,037		;draw a vector from 217,37 to 37,217
                OUT     (XSTORE),A
		LD      A,0217
		OUT     (YDRAW),A
                CALL    LONG		;delay 110 us while vector is drawn
;
                RET                     ;and done
;
;TIMEKPR SUBROUTINE executes the actual timekeeping function.  It advances the
;                   clock by one second if the RUN/STOP switch is in the RUN 
;                   position.  If the switch is in the STOP position, it
;                   returns without advancing the clock.
;
TIMEKPR:        IN      A,(SWITCH)      ;read the manual controls
                BIT     0,A             ;RUN set?
                JP      NZ,ADVANCE      ;if so, go advance clock
                RET                     ;if not, quit without action
;
;the following code counts seconds.  It counts from 0 to 59 and then rolls over
;to 0 again, carrying over to the minutes count when rolling over.
;
ADVANCE:        LD      A,(SECONDS)     ;get the seconds
                CP      059             ;is it 59?
                JP      Z,ROLLSEC       ;if so, go roll over
                INC     A               ;but if not, just advance it by one
                LD      (SECONDS),A
                RET			;and we're done
ROLLSEC:        LD      A,00            ;roll it to 0
                LD      (SECONDS),A
;
;the following code counts minutes.  It counts from 0 to 59 and then rolls over
;to 0, carrying to the hours.
;
                LD      A,(MINUTES)     ;now get the minutes
                CP      059             ;59?
		JP      Z,ROLLMIN       ;if so, roll over
		INC     A               ;if not, advance by one
		LD      (MINUTES),A
                RET			;and done
ROLLMIN:   	LD      A,00            ;roll to zero              
                LD      (MINUTES),A
;
;the following code counts hours.  There are two independent counts, one for
;use by the 12-hour mode of operation, and one for use by the 24-hour mode.
;The 12-hour code counts from 0 to 11 and rolls over to 0, toggling the AM/PM
;indicator.  The 24-hour code counts from 0 to 23 and rolls over to 0.
;
		LD      A,(HOURS)       ;finally, get the hours
                CP      011             ;is it 11?
                JP      Z,ROLLHOU       ;if so, go roll over
                INC     A               ;else advance it by one
                LD      (HOURS),A
		JP      MODE24   	;then do the same for 24-hour mode value
ROLLHOU:   	LD      A,00            ;if it was 11, roll it to zero
                LD      (HOURS),A
;
                LD      A,(AMPM)        ;and then toggle AMPM
                CPL
		LD      (AMPM),A
;
MODE24:         LD      A,(HRS24)       ;now get the 24-hour hours value
                CP      023             ;is it 23?
                JP      Z,ROLL24        ;if so, go roll over
                INC     A               ;else advance it by one
                LD      (HRS24),A
                RET
ROLL24:         LD      A,00            ;if it was 23, roll it to zero
                LD      (HRS24),A      
                RET                     ;then, all done
;
;SET SUBROUTINE advances the hour or minute hand as requested by the manual
;               controls.  There is no carry from minutes to hours as in the
;               TIMEKPR subroutine.
;
SET:            IN      A,(SWITCH)      ;read the manual controls
                BIT     4,A             ;SET_HOUR button pressed?
                JP      NZ,SETHOU       ;if so, go advance hours
;
SETMIN:         LD      A,(MINUTES)     ;otherwise, get the minutes
                CP      059             ;is it 59?
                JP      Z,ROLLM         ;if so, go roll over
                INC     A               ;but if not, just advance it by one
                LD      (MINUTES),A
                RET			;and we're done
ROLLM:          LD      A,00            ;if it was 59, roll it to 0
                LD      (MINUTES),A
                RET                     ;and we're done
;
SETHOU:	        LD      A,(HOURS)       ;get the hours
                CP      011             ;is it 11?
                JP      Z,ROLLH         ;if so, go roll over
                INC     A               ;else advance it by one
                LD      (HOURS),A
		JP      SET24           ;go do the same for the 24-hour hours value
ROLLH:   	LD      A,00            ;if it was 11, roll it to zero
                LD      (HOURS),A
;
                LD      A,(AMPM)        ;and then toggle AMPM
                CPL
		LD      (AMPM),A
;
SET24:          LD      A,(HRS24)       ;now get the 24-hour hours value
                CP      023             ;is it 23?
                JP      Z,R24           ;if so, go roll over
                INC     A               ;else advance it by one
                LD      (HRS24),A	;and done
                RET
R24:            LD      A,00            ;if it was 23, roll it to zero
                LD      (HRS24),A      
                RET                     ;then, all done
;
;SHORT SUBROUTINE generates a shorter delay for beam ("pen") moves.
;
SHORT:		LD 	A,(SCON)	;get time constant  
LOOP1:		DEC     A               ;decrement it until zero
		JP      NZ,LOOP1
		RET
;
;LONG SUBROUTINE generates a longer delay for actual vector drawing operation.
;
LONG:		LD 	A,(LCON)	;get time constant 
LOOP2:		DEC     A               ;decrement it until zero
		JP      NZ,LOOP2
		RET
;
;ZERO SUBROUTINE draws the 7-segment numeral 0 at the coordinates stored in BC.
;
ZERO:		LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from origin to relative 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,9 to 0,18
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;  		
		LD      A,B             ;draw stroke from 0,18 to 9,18
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B		;draw stroke from 9,18 to 9,9
                ADD     A,09
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,09
		OUT     (YDRAW),A
		CALL    LONG
;
		LD      A,B		;draw stroke from 9,9 to 9,0
                ADD     A,09
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,0
		OUT     (YDRAW),A
		CALL    LONG
;
		LD      A,B		;draw stroke from 9,0 to 0,0
                ADD     A,0
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,0
		OUT     (YDRAW),A
		CALL    LONG
;
	        RET                      ;done
;
;ONE SUBROUTINE draws the 7-segment numeral 1 at the coordinates stored in BC.
; 
ONE:		LD      A,B             ;move to relative 6,0
                ADD     A,06
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,0
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 6,0 to 6,9
		ADD     A,06
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 6,9 to 6,18
		ADD     A,06
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		RET                     ;done
;
;TWO SUBROUTINE draws the 7-segment numeral 2 at the coordinates stored in BC.
; 
TWO:		LD      A,B             ;move to relative 9,0
                ADD     A,09
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,0
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 9,0 to 0,0
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,0 to 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,9 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,9 to 9,18
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,18 to 0,18
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		RET                     ;done
;
;THREE SUBROUTINE draws the 7-segment numeral 3 at the coordinates stored in BC.
; 
THREE:		LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
; 	
		LD      A,B             ;draw stroke from 0,0 to 9,0
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,0 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,9 to 9,18
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,18 to 0,18
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;move to 0,9
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,09
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,9 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
                RET                     ;done
;
;FOUR SUBROUTINE draws the 7-segment numeral 4 at the coordinates stored in BC.
; 
FOUR:		LD      A,B             ;move to relative 0,18
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,018
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,18 to 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,9 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;move to 9,18
                ADD     A,09
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,018
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 9,18 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,9 to 9,0
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		RET			;done
;
;FIVE SUBROUTINE draws the 7-segment numeral 5 at the coordinates stored in BC.
; 
FIVE:		LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,0 to 9,0
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,0 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,9 to 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,9 to 0,18
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,18 to 9,18
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		RET			;done
;
;SIX SUBROUTINE draws the 7-segment numeral 6 at the coordinates stored in BC.
; 
SIX:		LD      A,B             ;move to relative 0,9
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,09
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,9 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,9 to 9,0
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,0 to 0,0
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,0 to 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,9 to 0,18
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,18 to 9,18
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		RET			;done
;
;SEVEN SUBROUTINE draws the 7-segment numeral 7 at the coordinates stored in BC.
; 
SEVEN:		LD      A,B             ;move to relative 0,18
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,018
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,18 to 9,18
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,18 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,9 to 9,0
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		RET                     ;done
;
;EIGHT SUBROUTINE draws the 7-segment numeral 8 at the coordinates stored in BC.
; 
EIGHT:		LD      A,B             ;move to relative 0,9
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,09
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,9 to 0,18
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,18 to 9,18
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,18 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,9 to 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,9 to 0,0
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,0 to 9,0 
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,0 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		RET			;done
;
;NINE SUBROUTINE draws the 7-segment numeral 9 at the coordinates stored in BC.
;
NINE:		LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,0 to 9,0
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,0 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,9 to 9,18
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,18 to 0,18
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,18 to 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,9 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		RET			;done
;
;BIGZERO SUBROUTINE draws the formed numeral 0 at the coordinates stored in BC.
;
BIGZERO:	LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from origin to relative 33,66
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;move to 33,55
                ADD     A,033
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,055
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B		;draw from 33,55 to 33,11
                ADD     A,033
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,011
		OUT     (YDRAW),A
		CALL    LONG
;
		LD      A,B		;draw from 33,11 to 22,0
                ADD     A,022
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,0
		OUT     (YDRAW),A
		CALL    LONG
;
                LD      A,B		;draw from 22,0 to 11,0
                ADD     A,011
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,0
		OUT     (YDRAW),A
		CALL    LONG
;
		LD      A,B		;draw from 11,0 to 0,11
                ADD     A,0
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,011
		OUT     (YDRAW),A
		CALL    LONG
;
		LD      A,B		;draw from 0,11 to 0,55
                ADD     A,0
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,055
		OUT     (YDRAW),A
		CALL    LONG
;
	        LD      A,B             ;draw from 0,55 to 11,66
                ADD     A,011
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,066
		OUT     (YDRAW),A
		CALL    LONG
;
 		LD      A,B             ;draw from 11,66 to 22,66
                ADD     A,022
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,066
		OUT     (YDRAW),A
		CALL    LONG
;
		LD      A,B             ;draw from 22,66 to 33,55
                ADD     A,033
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,055
		OUT     (YDRAW),A
		CALL    LONG
;
		RET
;
;BIGONE SUBROUTINE draws the formed numeral 1 at the coordinates stored in BC.
; 
BIGONE:		LD      A,B             ;move to relative 11,0
                ADD     A,011
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,0
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 11,0 to 33,0
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;  	
		LD      A,B             ;move to 22,0
                ADD     A,022
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,0
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 22,0 to 22,66
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,66 to 11,55
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		RET
;
;BIGTWO SUBROUTINE draws the formed numeral 2 at the coordinates stored in BC.
; 
BIGTWO:		LD      A,B             ;move to relative 33,0
                ADD     A,033
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,0
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 33,0 to 0,0
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,0 to 0,22
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,022
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,22 to 11,33
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,33 to 22,33
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,33 to 33,44
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,044
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,44 to 33,55
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,55 to 22,66
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,66 to 11,66
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,66 to 0,55
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		RET
;
;BIGTHREE SUBROUTINE draws the formed numeral 3 at the coordinates stored in BC.
; 
BIGTHREE:	LD      A,B             ;move to relative 0,11
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,011
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,11 to 11,0
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,0 to 22,0
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,0 to 33,11
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,011
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,11 to 33,22
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,022
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,22 to 22,33
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,33 to 11,33
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;move back to 22,33
                ADD     A,022
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,033
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 22,33 to 33,44
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,044
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,44 to 33,55
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,55 to 22,66
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,66, to 11,66
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,66 to 0,55
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
                RET
;
;BIGFOUR SUBROUTINE draws the formed numeral 4 at the coordinates stored in BC.
; 
BIGFOUR:	LD      A,B             ;move to relative 22,0
                ADD     A,022
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,0
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 22,0 to 22,66
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;move to relative 0,66
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,066
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,66 to 0,33
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,33 to 33,33
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		RET
;
;BIGFIVE SUBROUTINE draws the formed numeral 5 at the coordinates stored in BC.
; 
BIGFIVE:	LD      A,B             ;move to relative 0,11
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,011
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,11 to 11,0
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,0 to 22,0
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,0 to 33,11
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,011
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,11 to 33,22
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,022
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,22 to 22,33
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,33 to 11,33
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,33 to 0,44
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,044
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,44 to 0,66
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,66 to 33,66
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		RET
;
;BIGSIX SUBROUTINE draws the formed numeral 6 at the coordinates stored in BC.
; 
BIGSIX:		LD      A,B             ;move to relative 0,22
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,022
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,22 to 11,33
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,33 to 22,33
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,33 to 33,22
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,022
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,22 to 33,11
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,011
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,11 to 22,0
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,0 to 11,0
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,0 to 0,11
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,011
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,11 to 0,55
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,55 to 11,66
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,66 to 22,66
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,66 to 33,55
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		RET
;
;BIGSEVEN SUBROUTINE draws the formed numeral 7 at the coordinates stored in BC.
; 
BIGSEVEN:	LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,0 to 33,66
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,66 to 0,66
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,66 to 0,55
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
                LD      A,B             ;move to  11,33
                ADD     A,011
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,033
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 11,33 to 22,33
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		RET
;
;BIGEIGHT SUBROUTINE draws the formed numeral 8 at the coordinates stored in BC.
; 
BIGEIGHT:	LD      A,B             ;move to relative 22,33
                ADD     A,022
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,033
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 22,33 to 33,44
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,044
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,44 to 33,55
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,55 to 22,66
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,66 to 11,66
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,66 to 0,55
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,55 to 0,44
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,044
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,44 to 11,33
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,33 to 22,33
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,33 to 33,22
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,022
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,22 to 33,11
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,011
                OUT     (YDRAW),A
                CALL    LONG
;
        	LD      A,B             ;draw stroke from 33,11 to 22,0
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,0 to 11,0
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,0 to 0,11
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,011
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,11 to 0,22
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,022
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,22 to 11,33
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		RET
;
;BIGNINE SUBROUTINE draws the formed numeral 9 at the coordinates stored in BC.
;
BIGNINE:	LD      A,B             ;move to relative 33,44
                ADD     A,033
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,044
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 33,44 to 33,55
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,55 to 22,66
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,66 to 11,66
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,66 to 0,55
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,55 to 0,44
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,044
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,44 to 11,33
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,33 to 22,33
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,33 to 33,44
		ADD     A,033
		OUT     (XSTORE),A
                LD      A,C
                ADD     A,044
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,44 to 33,11
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,011
                OUT     (YDRAW),A
                CALL    LONG
;
        	LD      A,B             ;draw stroke from 33,11 to 22,0
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,0 to 11,0
		ADD     A,011
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 11,0 to 0,11
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,011
                OUT     (YDRAW),A
                CALL    LONG
;
		RET
;
;AY SUBROUTINE draws the small formed character A at the coordinates stored in BC.
;
AY:		LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from origin to relative 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,9 to 4,18
		ADD     A,04
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;  		
		LD      A,B             ;draw stroke from 4,18 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B		;draw stroke from 9,9 to 9,0
                ADD     A,09
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,00
		OUT     (YDRAW),A
		CALL    LONG
;
		LD      A,B             ;move to relative 0,9
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,09
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,9 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;  	
	        RET
;
;PEE SUBROUTINE draws the small formed character P at the coordinates stored in BC.
; 
PEE:		LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from origin to 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,9 to 0,18
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,18 to 6,18
		ADD     A,06
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 6,18 to 9,15
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,015
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,15 to 9,12
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,012
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,12 to 6,9
		ADD     A,06
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 6,9 to 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
                RET
;
;EM SUBROUTINE draws the small formed character M at the coordinates stored in BC.
; 
EM:		LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from origin to 0,9
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,9 to 0,18
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,18 to 4,9
		ADD     A,04
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 4,9 to 9,18
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,018
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,18 to 9,9
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,09
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 9,9 to 9,0
		ADD     A,09
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
                RET
;
;BIGAY SUBROUTINE draws the large formed character A at the coordinates stored
;                 in BC.
;
BIGAY:		LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from origin to relative 0,33
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,33 to 16,66
		ADD     A,016
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;  		
		LD      A,B             ;draw stroke from 16,66 to 33,33
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B		;draw stroke from 33,33 to 33,0
                ADD     A,033
		OUT     (XSTORE),A
		LD      A,C
		ADD     A,00
		OUT     (YDRAW),A
		CALL    LONG
;
		LD      A,B             ;move to relative 0,33
                ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,033
                OUT     (YMOVE),A
		CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,33 to 33,33
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;  	
	        RET
;
;BIGPEE SUBROUTINE draws the large formed character P at the coordinates stored
;                  in BC.
; 
BIGPEE:		LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from origin to 0,66
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,66 to 22,66
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,66 to 33,55
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,055
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,55 to 33,44
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,044
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,44 to 22,33
		ADD     A,022
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 22,33 to 0,33
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
                RET
;
;BIGEM SUBROUTINE draws the large formed character M at the coordinates stored
;                 in BC.
; 
BIGEM:		LD      A,B             ;move to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from origin to 0,66
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 0,66 to 16,33
		ADD     A,016
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,033
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 16,33 to 33,66
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,066
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 33,66 to 33,0
		ADD     A,033
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,00
                OUT     (YDRAW),A
                CALL    LONG
;
                RET
;
;COLON SUBROUTINE draws a colon (:) at the coordinates stored in BC.  It is 
;                 used by the DIGITAL mode of operation, and it calls the
;                 SHORT and LONG subroutines.
;
COLON:		LD      A,B             ;move beam to origin
		OUT     (XMOVE),A
		LD      A,C
		OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from origin to relative 7,0
		ADD     A,07
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 7,0 to 7,7
		ADD     A,07
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,07
                OUT     (YDRAW),A
                CALL    LONG
; 
		LD      A,B             ;draw stroke from 7,7 to 0,7
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,07
                OUT     (YDRAW),A
                CALL    LONG
; 
		LD      A,B             ;draw stroke from 0,7 to 0,0
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,0
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;move beam to 0,31
		ADD     A,0
                OUT     (XMOVE),A
                LD      A,C
                ADD     A,031
                OUT     (YMOVE),A
                CALL    SHORT
;
		LD      A,B             ;draw stroke from 0,31 to 7,31
		ADD     A,07
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,031
                OUT     (YDRAW),A
                CALL    LONG
;
		LD      A,B             ;draw stroke from 7,31 to 7,38
		ADD     A,07
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,038
                OUT     (YDRAW),A
                CALL    LONG
; 
		LD      A,B             ;draw stroke from 7,38 to 0,38
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,038
                OUT     (YDRAW),A
                CALL    LONG
; 
		LD      A,B             ;draw stroke from 0,38 to 0,31
		ADD     A,0
                OUT     (XSTORE),A
                LD      A,C
                ADD     A,031
                OUT     (YDRAW),A
                CALL    LONG 
;
                RET                     ;and done
;
;COORDINATE DATA TABLES for the analogue clock's circles and hand endpoints
;follow.
;
CIRC0:          DB      0127          	;60 vectors for the outside circle
                DB      0254
;
                DB      0140
                DB      0253
;
                DB      0153
                DB      0251
;
                DB      0166      
                DB      0248       
;
                DB      0179
                DB      0243       
;
                DB      0191
                DB      0237       
;
                DB      0202
                DB      0230       
;
                DB      0212
                DB      0221       
;
                DB      0221
                DB      0212       
;
                DB      0230
                DB      0202       
;
                DB      0237
                DB      0190       
;
                DB      0243
                DB      0179       
;
                DB      0248
                DB      0166       
;
                DB      0251
                DB      0153       
;
                DB      0253
                DB      0140       
;
                DB      0254
                DB      0127       
;
                DB      0253
                DB      0114       
;
                DB      0251
                DB      0101       
;
                DB      0248
                DB      088       
;
                DB      0243
                DB      075       
;
                DB      0237
                DB      063       
;
                DB      0230
                DB      052       
;
                DB      0221
                DB      042       
;
                DB      0212
                DB      033     
;
                DB      0202
                DB      024       
;
                DB      0190
                DB      017       
;
                DB      0179
                DB      011       
;
                DB      0166
                DB      06       
;
                DB      0153
                DB      03       
;
                DB      0140
                DB      01       
;
                DB      0127
                DB      0       
;
                DB      0114
                DB      01       
;
                DB      0101
                DB      03       
;
                DB      088
                DB      06       
;
                DB      075
                DB      011       
;
                DB      063
                DB      017       
;
                DB      052
                DB      024       
;
                DB      042
                DB      033        
;
                DB      033
                DB      042       
;
                DB      024
                DB      052       
;
                DB      017
                DB      064       
;
                DB      011
                DB      075       
;
                DB      06
                DB      088       
;
                DB      03
                DB      0101       
;
                DB      01
                DB      0114       
;
                DB      0
                DB      0127       
;
                DB      01
                DB      0140       
;
                DB      03
                DB      0153       
;
                DB      06
                DB      0166       
;
                DB      011
                DB      0179       
;
                DB      017
                DB      0191       
;
                DB      024
                DB      0202       
;
                DB      033
                DB      0212       
;
                DB      042
                DB      0221       
;
                DB      052
                DB      0230       
;
                DB      064
                DB      0237       
;
                DB      075
                DB      0243       
;
                DB      088
                DB      0248       
;
                DB      0101
                DB      0251       
;
                DB      0114
                DB      0253       
;
CIRC1:          DB      0127            ;60 coordinates for seconds tic mark endpoints
                DB      0243
;
                DB      0139
                DB      0242
;
                DB      0151      
                DB      0240       
;
                DB      0163
                DB      0237       
;
                DB      0174
                DB      0233       
;
                DB      0185
                DB      0227       
;
                DB      0195
                DB      0221       
;
                DB      0205
                DB      0213       
;
                DB      0213
		DB      0205
;
                DB      0221
                DB      0195       
;
                DB      0227
                DB      0185       
;
                DB      0233
                DB      0174       
;
                DB      0237
                DB      0163       
;
                DB      0240
                DB      0151       
;
                DB      0242
                DB      0139       
;
                DB      0243
                DB      0127       
;
                DB      0242
                DB      0115       
;
                DB      0240
                DB      0103       
;
                DB      0237
                DB      091       
;
                DB      0233
                DB      080       
;
                DB      0227
                DB      069       
;
                DB      0221
                DB      059       
;
                DB      0213
                DB      049       
;
                DB      0205
                DB      041     
;
                DB      0195
                DB      033       
;
                DB      0185
                DB      027       
;
                DB      0174
                DB      021       
;
                DB      0163
                DB      017       
;
                DB      0151
                DB      014       
;
                DB      0139
                DB      012       
;
                DB      0127
                DB      011       
;
                DB      0115
                DB      012       
;
                DB      0103
                DB      014       
;
                DB      091
                DB      017       
;
                DB      080
                DB      021       
;
                DB      069
                DB      027       
;
                DB      059
                DB      033       
;
                DB      049
                DB      041        
;
                DB      041
                DB      049       
;
                DB      033
                DB      059       
;
                DB      027
                DB      069       
;
                DB      021
                DB      080       
;
                DB      017
                DB      091       
;
                DB      014
                DB      0103       
;
                DB      012
                DB      0115       
;
                DB      011
                DB      0127       
;
                DB      012
                DB      0139
;
                DB      014
                DB      0151       
;
                DB      017
                DB      0163       
;
                DB      021
                DB      0174       
;
                DB      027
                DB      0185       
;
                DB      033
                DB      0195       
;
                DB      041
                DB      0205       
;
                DB      049
                DB      0213       
;
                DB      059
                DB      0221       
;
                DB      069
                DB      0227       
;
                DB      080
                DB      0233       
;
                DB      091
                DB      0237       
;
                DB      0103
                DB      0240       
;
                DB      0115
                DB      0242      
;
CIRC2:          DB      0127            ;60 coordinates for sec/min hand endpoints
                DB      0232
;
                DB      0139
                DB      0231
;
                DB      0149      
                DB      0230       
;
                DB      0159
                DB      0227       
;
                DB      0170
                DB      0223       
;
                DB      0180
                DB      0218       
;
                DB      0189
                DB      0212       
;
                DB      0197
                DB      0205       
;
                DB      0205
		DB      0197
;
                DB      0212
                DB      0189       
;
                DB      0218
                DB      0179       
;
                DB      0223
                DB      0170       
;
                DB      0227
                DB      0159       
;
                DB      0230
                DB      0149       
;
                DB      0231
                DB      0138       
;
                DB      0232
                DB      0127       
;
                DB      0231
                DB      0116       
;
                DB      0230
                DB      0105       
;
                DB      0227
                DB      095       
;
                DB      0223
                DB      084       
;
                DB      0218
                DB      074       
;
                DB      0212
                DB      065       
;
                DB      0205
                DB      057       
;
                DB      0197
                DB      049     
;
                DB      0189
                DB      042       
;
                DB      0179
                DB      036       
;
                DB      0170
                DB      031       
;
                DB      0159
                DB      027       
;
                DB      0149
                DB      024       
;
                DB      0138
                DB      023       
;
                DB      0127
                DB      022       
;
                DB      0116
                DB      023       
;
                DB      0105
                DB      024       
;
                DB      095
                DB      027       
;
                DB      084
                DB      031       
;
                DB      074
                DB      036       
;
                DB      065
                DB      042       
;
                DB      057
                DB      049        
;
                DB      049
                DB      057       
;
                DB      042
                DB      065       
;
                DB      036
                DB      075       
;
                DB      031
                DB      084       
;
                DB      027
                DB      095       
;
                DB      024
                DB      0105       
;
                DB      023
                DB      0116       
;
                DB      022
                DB      0127       
;
                DB      023
                DB      0138
;
                DB      024
                DB      0149       
;
                DB      027
                DB      0159       
;
                DB      031
                DB      0170       
;
                DB      036
                DB      0180       
;
                DB      042
                DB      0189       
;
                DB      049
                DB      0197       
;
                DB      057
                DB      0205       
;
                DB      065
                DB      0212       
;
                DB      075
                DB      0218       
;
                DB      084
                DB      0223       
;
                DB      095
                DB      0227       
;
                DB      0105
                DB      0230       
;
                DB      0116
                DB      0231      
;
CIRC3:          DB      0127		;12 coordinates for hour hand endpoints
		DB      0201
;
		DB      0164
		DB      0191
;
		DB	0191
		DB	0164
;
		DB      0201
		DB	0127
;
		DB	0191
		DB	090
;
		DB	0164
		DB	063
;
		DB	0127
		DB	053
;
		DB	090
		DB	063
;
		DB	063
		DB	090
;
		DB	053
		DB	0127
;
		DB	063
		DB	0164
;
		DB	090
		DB	0191
;
                HALT                    ;end of program code
;
;SCRATCH PAD MEMORY storage for program variables.
;
                ORG     08000H          ;put it in RAM!
SCON:           DS      01              ;time constant for SHORT subroutine
LCON:           DS      01              ;time constant for LONG subroutine
X:		DS      01              ;scratch x coordinate
Y:		DS      01		;scratch y coordinate
SECONDS:        DS      01              ;seconds (0 to 59)
MINUTES:	DS      01              ;minutes (0 to 59)
HOURS:		DS      01		;hours (0 [12] to 11)
HRS24:          DS      01              ;hours (0 to 23)
AMPM:		DS      01              ;AM/PM indicator (00 [AM] or FF [PM])
;
		END
