home *** CD-ROM | disk | FTP | other *** search
- ;
- ; VLIB ROUTINES
- ;
-
-
- ;
- ; Common vlib routine to find terminal info in ENV
- ;
- vterm:
- ld hl,z3env+80h ; Pt to environment
- ld a,(hl) ; No terminal?
- cp ' '+1
- ret
-
-
- ;
- ; CLEAR SCREEN ON TERMINAL
- ;
- if [not clson]
- cls:
- push hl ; Save regs
- push de
- call vterm
- jr c,clserr
- ld de,14h ; Pt to cls delay
- add hl,de
- ld d,(hl) ; Get it
- inc hl ; Pt to cls string
- inc hl
- inc hl
- ld a,(hl) ; Get first char of string
- or a ; If no string, error
- jr z,clserr
- call vidout ; Output string with delay
- pop de ; Done
- pop hl
- xor a ; Return nz
- dec a
- ret
- clserr:
- pop de ; Done
- pop hl
- xor a ; Return z
- ret
-
- endif ; Not clson
-
- ;
- ; Erase to End of Line
- ; Return with A=0 and Zero Flag Set if not done
- ;
- ereol:
- push bc ; Save regs
- push de
- push hl
- call vterm
- jr c,err
- ld de,16h ; Pt to ereol delay
- add hl,de
- ld d,(hl) ; Get it
- inc hl ; Pt to cls string
- call vidskp ; Skip over it
- call vidskp ; Skip over cm string
- ld a,(hl) ; Get first char of ereol string
- or a ; If no string, error
- jr z,err
- call vidout ; Output string with delay
- jr noerr
-
- ;
- ; GOTO XY
- ; HL = Row/Col, with Home=1/1
- ; Return with A=0 and Zero Flag Set if not done
- ;
- gotoxy:
- push bc ; Save regs
- push de
- push hl
- call vterm
- jr c,err
- ld de,15h ; Pt to cm delay
- add hl,de
- ld a,(hl) ; Get it
- ld (cmdelay),a ; Save it
- inc hl ; Pt to cl string
- inc hl
- call vidskp ; Skip cl string
- ld a,(hl) ; Get first char of cm string
- or a ; If no string, error
- jr z,err
- ex de,hl ; De=address of cm string
- pop hl ; Get coordinates in hl
- push hl
- call gxy ; Output xy string with delay
- ld a,(cmdelay) ; Pause
- call videlay
- noerr:
- pop hl ; Done
- pop de
- pop bc
- xor a ; Return nz
- dec a
- ret
- err:
- pop hl ; Done
- pop de
- pop bc
- xor a ; Return z
- ret
-
- ;
- ; Position Cursor at Location Specified by Return Address
- ; Usage:
- ; call at
- ; db row,col ;location
- ;
- at:
- ex (sp),hl ; Pt to address
- push de ; Save de
- ld d,(hl) ; Get row
- inc hl
- ld e,(hl)
- inc hl ; Hl pts to return byte
- ex de,hl ; De pts to return byte, hl contains screen loc
- call gotoxy ; Position cursor
- ex de,hl ; Hl pts to return byte
- pop de ; Restore registers
- ex (sp),hl ; Restore stack ptr
- ret
-
- ;
- ; GOTOXY
- ; On input, H=Row and L=Column to Position To (1,1 is Home)
- ; On input, DE=address of CM string
- ;
- gxy:
- dec h ; Adjust to 0,0 for home
- dec l
- xor a ; Set row/column
- ld (rcorder),a ; Row before column
- ld (rcbase),a ; Add 0 to base
- ;
- ; Cycle thru string
- ;
- gxyloop:
- ld a,(de) ; Get next char
- inc de ; Pt to next
- or a ; Done?
- ret z
- cp '%' ; Command?
- jr z,gxycmd
- cp '\' ; Escape?
- jr z,gxyesc
- call conout ; Send char
- jr gxyloop
-
- ;
- ; Escape - output following byte literally
- ;
- gxyesc:
- ld a,(de) ; Get next char
- call conout ; Output literally
- inc de ; Pt to next
- jr gxyloop
- ;
- ; Interpret next character as a command character
- ;
- gxycmd:
- ld a,(de) ; Get command char
- inc de ; Pt to next
- cp 'd' ; %d
- jr z,gxyout1
- cp '2' ; %2
- jr z,gxyout2
- cp '3' ; %3
- jr z,gxyout3
- cp '.' ; %.
- jr z,gxyout4
- cp '+' ; %+v
- jr z,gxyout5
- cp '>' ; %>xy
- jr z,gxygt
- cp 'r' ; %r
- jr z,gxyrev
- cp 'i' ; %i
- jr z,gxyinc
- call conout ; Output char if nothing else
- jr gxyloop
- ;
- ; Set row/col home to 1,1 rather than 0,0
- ;
- gxyinc:
- ld a,1 ; Set rcbase to 1
- ld (rcbase),a
- jr gxyloop
- ;
- ; Reverse order of output to column then row (default is row then column)
- ;
- gxyrev:
- ld a,1 ; Set column and row order
- ld (rcorder),a
- jr gxyloop
- ;
- ; Command: >xy
- ; If value of row/col is greater than x, add y to it
- ;
- gxygt:
- call getval ; Get value
- ld c,a ; Save value
- ld a,(de) ; Get value to test
- inc de ; Pt to next
- cp c ; If carry, value>x
- jr nc,gxygt1
- ld a,(de) ; Get value to add
- add a,c
- call putval ; Put value back
- gxygt1:
- inc de ; Pt to next
- jp gxyloop ; Resume
- ;
- ; Command: +n
- ; Add n to next value and output
- ;
- gxyout5:
- ld a,(de) ; Get value to add
- inc de ; Pt to next
- ld b,a ; Save in b
- call getval ; Get value
- add a,b ; Add in b
- call conout ; Output value
- rcmark:
- ld a,(rcorder) ; Mark output
- or 80h
- ld (rcorder),a
- jp gxyloop
- ;
- ; Command: .
- ; Output next value
- ;
- gxyout4:
- call getval ; Get value
- call conout ; Output value
- jp rcmark
- ;
- ; Command: 3
- ; Output next value as 3 decimal digits
- ;
- gxyout3:
- call getval ; Get value
- ld b,100 ; Output 100's
- ld c,1 ; Leading zeroes
- call digout
- gxyot3:
- ld b,10 ; Output 10's
- ld c,1 ; Leading zeroes
- gxyot2:
- call digout
- add '0' ; Output 1's
- call conout
- jp rcmark
- ;
- ; Command: 2
- ; Output next value as 2 decimal digits
- ;
- gxyout2:
- call getval ; Get value
- jr gxyot3
- ;
- ; Command: d
- ; Output next value as n decimal digits with no leading zeroes
- ;
- gxyout1:
- call getval ; Get value
- ld b,100 ; Output 100's
- ld c,0 ; No leading zeroes
- call digout
- ld b,10 ; Output 10's
- ld c,0 ; No leading zeroes
- jr gxyot2
- ;
- ; Return next value in A
- ;
- getval:
- ld a,(rcorder) ; Get order flag
- or a ; Already output the first value?
- jp m,getval2
- and 1 ; Look at lsb
- jr z,getvalr ; If 0, row first
- getvalc:
- ld a,(rcbase) ; Get base offset
- add a,l ; Get column
- ret
- getvalr:
- ld a,(rcbase) ; Get base offset
- add a,h ; Get row
- ret
- getval2:
- and 1 ; Look at lsb
- jr z,getvalc
- jr getvalr
- ;
- ; Store A as next value
- ;
- putval:
- ld c,a ; Save value
- ld a,(rcorder) ; Get order flag
- or a ; Already output the first value?
- jp m,putval2
- and 1 ; Look at lsb
- jr z,putvalr ; If 0, row first
- putvalc:
- ld l,c ; Set column
- ret
- putvalr:
- ld h,c ; Set row
- ret
- putval2:
- and 1 ; Look at lsb
- jr z,putvalc
- jr putvalr
- ;
- ; Output A as decimal digit char
- ; B=Quantity to Subtract from A, C=0 if no leading zero
- ;
- digout:
- push de ; Save de
- ld d,'0' ; Char
- decot1:
- sub b ; Subtract
- jr c,decot2
- inc d ; Increment char
- jr decot1
- decot2:
- add a,b ; Add back in
- push af ; Save result
- ld a,d ; Get digit
- cp '0' ; Zero?
- jr nz,decot3
- ld a,c ; Get zero flag
- or a ; 0=no zero
- jr z,decot4
- decot3:
- ld a,d ; Get digit
- call conout ; Print it
- decot4:
- pop af ; Get a
- pop de ; Restore de
- ret
- ;
- ; GXY Buffers
- ;
- rcorder:
- ds 1 ; 0=row/col, else col/row
- rcbase:
- ds 1 ; 0=org is 0,0, else org is 1,1
- cmdelay:
- ds 1 ; Number of milliseconds to delay for cm
-
- ;
- ; Begin Standout Mode
- ; Return with A=0 and Zero Flag Set if not done
- ;
- stndout:
- push bc
- push de
- push hl ; Save regs
- call vterm
- jp c,err
- ld de,17h ; Pt to cls string
- add hl,de
- ld d,0 ; No delay
- stnd1: call vidskp ; Skip over cl string
- call vidskp ; Skip over cm string
- call vidskp ; Skip over ce string
- ld a,(hl) ; Get first char of so string
- or a ; If no string, error
- jp z,err
- call vidout ; Output string with delay
- jp noerr
-
- ;
- ; Terminate Standout Mode
- ; Return with A=0 and Zero Flag Set if not done
- ;
- stndend:
- push bc
- push de
- push hl ; Save regs
- call vterm
- jp c,err
- ld de,17h ; Pt to cls string
- add hl,de
- ld d,0 ; No delay
- call vidskp ; Skip over cl string
- jr stnd1
-
- ;
- ; Initialize Terminal
- ; Affect No Registers
- ;
- tinit:
- push hl ; Save regs
- push de
- push af
- call vterm
- jp c,tid
- ld de,17h ; Pt to cls string
- add hl,de
- ld d,0 ; No delay
- tinit1: call vidskp ; Skip over cl string
- call vidskp ; Skip over cm string
- call vidskp ; Skip over ce string
- call vidskp ; Skip over so string
- call vidskp ; Skip over se string
- ld a,(hl) ; Get first char of ti string
- or a ; If no string, error
- jp z,tid
- call vidout ; Output string with delay
- tid:
- pop af ; Done
- pop de
- pop hl
- ret
-
- ;
- ; De-Initialize Terminal
- ; Affect No Registers
- ;
- dinit:
- push hl ; Save regs
- push de
- push af
- call vterm
- jp c,tid
- ld de,17h ; Pt to cls string
- add hl,de
- ld d,0 ; No delay
- call vidskp ; Skip over cl string
- jr tinit1
-
-
- ;
- ; VIDOUT - Output video string pted to by HL
- ; Output also a delay contained in the D register
- ;
- vidout:
- ld a,(hl) ; Get next char
- or a ; Done if zero
- jr z,vid2
- inc hl ; Pt to next
- cp '\' ; Literal value?
- jr nz,vid1
- ld a,(hl) ; Get literal char
- inc hl ; Pt to after it
- vid1:
- call conout ; Output char
- jr vidout
- vid2:
- ld a,d ; Output delay and fall thru to videlay
-
- ;
- ; VIDELAY pauses for the number of milliseconds indicated by the A
- ; register. VIDELAY assumes a ZCPR3 environment and uses it to determine
- ; processor speed.
- ;
- videlay:
- push af ; Save regs
- push bc
- push de
- push hl
- ld c,a ; Save count in c
- or a ; No delay?
- jr z,done
- ld hl,z3env ; Pt to environment
- ld de,2bh ; Offset to processor speed
- add hl,de
- ld a,(hl) ; Get processor speed
- or a ; Zero?
- jr nz,vidl1
- ld a,4 ; Assume 4 mhz
- vidl1:
- ld b,a ; Processor speed in b
- vidl2:
- push bc ; Delay 1 ms
- call delay
- pop bc
- dec c ; Count down
- jr nz,vidl2
- done:
- pop hl ; Restore regs
- pop de
- pop bc
- pop af
-
- ret
- ;
- ; Delay 1 ms at Clock speed
- ;
- delay:
- call del1 ; Delay 1 ms at 1mhz
- dec b ; Count down clock speed
- jp nz,delay
- ret
- ;
- ; Delay 1 ms at 1MHz
- ;
- del1:
- ld c,20 ; 20 loops of 51 cycles each ~ 1000 cycles
- del1a:
- ex (sp),hl ; 18 cycles
- ex (sp),hl ; +18 = 36 cycles
- dec c ; + 5 = 41 cycles
- jr nz,del1a ; +10 = 51 cycles
- ret
-
- ;
- ; VIDSKP - Skip over video string pted to by HL; pt to byte after string
- ;
- vidskp:
- ld a,(hl) ; Get next char
- inc hl ; Pt to next
- or a ; Done if zero
- ret z
- cp '\' ; Literal value?
- jr nz,vidskp ; Continue if not
- inc hl ; Pt to after literal value
- jr vidskp
- if zero
- ret z
- cp '\' ; Literal value?
-