📄 tskprf.asm
字号:
mov bx,handle
mov ax,ss
mov ds,ax
mov ah,40h
int 21h
vfprintfend:
add sp,FILE_BUFSIZE
ret
tsk_vfprintf endp
;
;
; void tsk_sprintf (char far *dest, char far *format, ...)
;
; Formatted output to string.
;
CGlobalfunc tsk_sprintf,<uses ds si di, dest: far ptr, fmt: far ptr, varg: word>
;
mov ax,ss
mov es,ax
lds bx,dest
mov dx,ds
lds si,fmt
lea di,varg
mov cx,offset @stringchar
call @disprintf
mov es,word ptr(dest) + 2
mov byte ptr es:[bx],0
sub bx,word ptr(dest)
mov ax,bx
ret
tsk_sprintf endp
;
;
; void tsk_vsprintf (char far *dest, char far *format, void far *arglist)
;
; Formatted output to string.
;
Globalfunc tsk_vsprintf,<uses ds si di, dest: far ptr, fmt: far ptr, varg: far ptr>
;
lds bx,dest
mov dx,ds
lds si,fmt
les di,varg
mov cx,offset @stringchar
call @disprintf
mov es,word ptr(dest) + 2
mov byte ptr es:[bx],0
sub bx,word ptr(dest)
mov ax,bx
ret
tsk_vsprintf endp
;
;
; void tsk_rprintf (char far *format, ...)
;
; Formatted output to regen buffer (second display).
;
CGlobalfunc tsk_rprintf,<uses ds si di, fmt: far ptr, varg: word>
;
IFDEF LOAD_DS
mov ds,cs:ctdataseg
ENDIF
mov cx,sc_proc
mov ax,ss
mov es,ax
lds si,fmt
lea di,varg
call @disprintf
ret
tsk_rprintf endp
;
;
; void tsk_vrprintf (char far *format, void far *arglist)
;
; Formatted output to regen buffer (second display).
;
Globalfunc tsk_vrprintf,<uses ds si di, fmt: far ptr, varg: far ptr>
;
IFDEF LOAD_DS
mov ds,cs:ctdataseg
ENDIF
mov cx,sc_proc
lds si,fmt
les di,varg
call @disprintf
ret
tsk_vrprintf endp
;
;
;
; void tsk_cprintf (char far *format, ...)
;
; Formatted output to comm port
;
CGlobalfunc tsk_cprintf,<uses ds si di, fmt: far ptr, varg: word>
;
IFDEF LOAD_DS
mov ds,cs:ctdataseg
ENDIF
mov cx,offset @comchar
mov ax,ss
mov es,ax
lds si,fmt
lea di,varg
call @disprintf
ret
tsk_cprintf endp
;
;
; void tsk_vcprintf (char far *format, void far *arglist)
;
; Formatted output to comm port
;
Globalfunc tsk_vcprintf,<uses ds si di, fmt: far ptr, varg: far ptr>
;
IFDEF LOAD_DS
mov ds,cs:ctdataseg
ENDIF
mov cx,offset @comchar
lds si,fmt
les di,varg
call @disprintf
ret
tsk_vcprintf endp
;
;
; void tsk_putc (char c)
;
; Output character to console.
;
Globalfunc tsk_putc,<chr: word>
mov ax,chr
call @dischar
ret
tsk_putc endp
;
;
; void tsk_puts (char far *s)
;
; Output string to console.
;
Globalfunc tsk_puts,<uses ds si, dstr: far ptr>
;
lds si,dstr
putslp:
lodsb
or al,al
jz putsend
call @dischar
jmp putslp
;
putsend:
mov al,0dh
call @dischar
mov al,0ah
call @dischar
ret
tsk_puts endp
;
;
; void tsk_rputc (char c)
;
; Output character to regen buffer (second display).
;
Globalfunc tsk_rputc,<chr: word>
;
mov ax,chr
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
call sc_proc
pop ds
ELSE
call sc_proc
ENDIF
ret
tsk_rputc endp
;
;
; void tsk_rputs (char far *s)
;
; Output string to regen buffer.
;
Globalfunc tsk_rputs,<uses si, dstr: far ptr>
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
les si,dstr
rputslp:
lods es:prflags
or al,al
jz rputsend
call sc_proc
jmp rputslp
;
rputsend:
mov al,0dh
call sc_proc
mov al,0ah
call sc_proc
IFDEF LOAD_DS
pop ds
ENDIF
ret
tsk_rputs endp
;
;
; void tsk_cputc (char c)
;
; Output character to comm port.
;
Globalfunc tsk_cputc,<chr: word>
mov ax,chr
call @comchar
ret
tsk_cputc endp
;
;
; void tsk_cputs (char far *s)
;
; Output string to comm port.
;
Globalfunc tsk_cputs,<uses ds si, dstr: far ptr>
;
lds si,dstr
cputslp:
lodsb
or al,al
jz cputsend
call @comchar
jmp cputslp
;
cputsend:
mov al,0dh
call @comchar
mov al,0ah
call @comchar
ret
tsk_cputs endp
;
;
; void tsk_setpos (int row, int col)
;
; Set cursor position for regen output.
; First position on screen is (0, 0).
;
Globalfunc tsk_setpos,<row: word, col: word>
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
mov ax,row
mul sc_cols
add ax,col
add ax,col
mov tsk_regen_o,ax
call @setcsr
IFDEF LOAD_DS
pop ds
ENDIF
ret
tsk_setpos endp
;
;
; void tsk_set_regen (int segment, int port, int rows, int cols)
;
; Set regen buffer address and size, and display controller port.
; This routine can be used to force regen output to the
; primary screen for single-screen systems, and to modify
; the output parameters (number of rows and columns).
;
Globalfunc tsk_set_regen,<reg: word, port: word, rows: word, cols: word>
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
mov ax,reg
mov tsk_regen_s,ax
mov ax,port
mov tsk_disport,ax
mov tsk_regen_o,0
mov ax,cols
add ax,ax
mov sc_cols,ax
mul rows
mov sc_end,ax
mov sc_proc,offset @disregen
IFDEF LOAD_DS
pop ds
ENDIF
ret
tsk_set_regen endp
;
;
; int tsk_set_dualdis (void)
;
; Determine regen buffer address on second monitor.
; This routine first checks the current video mode. If it's
; mode 7, the regen buffer is set to B800 (the colour screen).
; For all other modes, the regen buffer is B000 (mono).
; Then a check is done to make sure that the secondary card
; exists. If it does, the regen output is initialized. Otherwise,
; any output through the regen routines will be discarded.
;
; Returns 0 if there is no secondary monitor, else the
; regen buffer address.
;
; No attempt is made to initialize the secondary monitor,
; the monitor must be in alpha mode.
;
Globalfunc tsk_set_dualdis
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
mov ah,0fh
push bp
int 10h ; get video mode
pop bp
mov bx,0b800h ; colour regen buffer
mov dx,3d4h ; CGA 6845 I/O addr
cmp al,7 ; only mode 7 has regen at B000
je ddis_checks
mov bx,0b000h ; mono regen buffer
mov dx,3b4h ; mono 6845 I/O addr
;
ddis_checks:
mov tsk_regen_s,bx
mov tsk_regen_o,0
mov tsk_disport,dx
mov sc_cols,80 * 2
mov sc_end,25 * 80 * 2
mov al,0fh
out dx,al
inc dx
in al,dx
mov ah,al
mov al,56h
out dx,al
mov cx,100h
ddis_wait:
loop ddis_wait
in al,dx
xchg ah,al
out dx,al
cmp ah,56h
je ddis_ok
mov sc_proc,offset @nodis
xor ax,ax
mov tsk_regen_s,ax
jmp short ddis_end
;
ddis_ok:
mov sc_proc,offset @disregen
mov ax,bx
;
ddis_end:
IFDEF LOAD_DS
pop ds
ENDIF
ret
;
tsk_set_dualdis endp
;
;
; int tsk_set_currdis (void)
;
; Determine regen buffer address on current monitor.
; This routine checks the current video mode. If it's
; mode 7, the regen buffer is set to B000 (the mono screen).
; For all other modes, the regen buffer is B800 (colour).
;
; Returns the regen buffer address.
;
; No attempt is made to initialize the monitor, or to check for
; special modes with different regen address. The monitor must
; be in alpha mode.
;
Globalfunc tsk_set_currdis
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
mov ah,0fh
push bp
int 10h ; get video mode
pop bp
mov bx,0b800h ; colour regen buffer
cmp al,7 ; only mode 7 has regen at B000
jne curdis_ready
mov bx,0b000h ; mono regen buffer
;
curdis_ready:
mov tsk_regen_s,bx
mov tsk_regen_o,0
mov ax,SEG biosdata
mov es,ax
assume es:biosdata
mov ax,bios_chipad
mov tsk_disport,ax
mov ax,bios_cols
add ax,ax
mov sc_cols,ax
mov dl,bios_rows
xor dh,dh
mul dx
mov sc_end,ax
mov sc_proc,offset @disregen
mov ax,bx
IFDEF LOAD_DS
pop ds
ENDIF
ret
;
tsk_set_currdis endp
;
;
; void tsk_set_colour (int rows, int cols)
;
; Set regen buffer address to colour monitor.
;
Globalfunc tsk_set_colour,<rows: word, cols: word>
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
mov tsk_regen_s,0b800h ; colour regen buffer
mov tsk_regen_o,0
mov tsk_disport,3d4h ; CGA 6845 I/O addr
mov ax,cols
add ax,ax
mov sc_cols,ax
mul rows
mov sc_end,ax
mov sc_proc,offset @disregen
IFDEF LOAD_DS
pop ds
ENDIF
ret
;
tsk_set_colour endp
;
;
; void tsk_set_mono (int rows, int cols)
;
; Set regen buffer address to monochrome monitor.
;
Globalfunc tsk_set_mono,<rows: word, cols: word>
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
mov tsk_regen_s,0b000h ; mono regen buffer
mov tsk_regen_o,0
mov tsk_disport,3b4h ; mono 6845 I/O addr
mov ax,cols
add ax,ax
mov sc_cols,ax
mul rows
mov sc_end,ax
mov sc_proc,offset @disregen
IFDEF LOAD_DS
pop ds
ENDIF
ret
;
tsk_set_mono endp
;
;
; void tsk_set_attr (int attr)
;
; Set regen display attributes
;
Globalfunc tsk_set_attr,<attr: word>
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
mov ax,attr
mov tsk_attrib,al
IFDEF LOAD_DS
pop ds
ENDIF
ret
;
tsk_set_attr endp
;
;
; void tsk_set_clreol (int clr)
;
; Set special handling of CR. If "clr" is nonzero, CR will clear
; to end of line before returning to the home position.
;
Globalfunc tsk_set_clreol,<clr: word>
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
mov ax,clr
mov sc_clreol,al
IFDEF LOAD_DS
pop ds
ENDIF
ret
;
tsk_set_clreol endp
;
;
Globalfunc tsk_cprint_init,<port: word, baud: word>
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
;
mov ax,port
cmp ax,4
ja compok
mov bx,ax
or bx,bx
jz comp1
dec bx
add bx,bx
comp1:
mov ax,40h
mov es,ax
mov ax,es:[bx]
or ax,ax
jnz compok
mov ax,3f8h
compok:
mov tsk_comport,ax
mov dx,ax
mov bx,48
mov ax,baud
cmp ax,24
jbe baudok
mov bx,12
cmp ax,96
jbe baudok
mov bx,6
cmp ax,192
jbe baudok
mov bx,3
cmp ax,384
jbe baudok
mov bx,1
baudok:
add dx,3 ; line control
cli
mov al,83h ; no par, 1 stop 8 data
out dx,al
sub dx,3 ; data
jmp $+2
mov al,bl
out dx,al
jmp $+2
xor al,al
inc dx
out dx,al
jmp $+2
add dx,2 ; line control
mov al,03h ; no par, 1 stop 8 data
out dx,al
jmp $+2
inc dx ; modem control
mov al,03h ; DTR, RTS
out dx,al
jmp $+2
sub dx,3 ; int enable
xor al,al ; no ints
out dx,al
sti
;
IFDEF LOAD_DS
pop ds
ENDIF
ret
;
tsk_cprint_init endp
;
;
Globalfunc tsk_cprint_getc
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
;
push dx
mov dx,tsk_comport
mov ax,dx
or ax,ax
jz cgc_end
call @poll_com
mov ax,tsk_comcnt
or ax,ax
jz cgc_end
push bx
mov bx,tsk_comoptr
mov al,tsk_combuf[bx]
inc bx
and bx,0fh
mov tsk_comoptr,bx
pop bx
dec tsk_comcnt
mov ah,1
or ax,ax
;
cgc_end:
pop dx
IFDEF LOAD_DS
pop ds
ENDIF
ret
;
tsk_cprint_getc endp
;
;
Globalfunc tsk_cprint_waitc
;
IFDEF LOAD_DS
push ds
mov ds,cs:ctdataseg
ENDIF
;
push dx
mov dx,tsk_comport
mov ax,dx
or ax,ax
jz cwc_end
;
cwc_loop:
call @poll_com
cmp tsk_comcnt,0
je cwc_loop
push bx
mov bx,tsk_comoptr
mov al,tsk_combuf[bx]
inc bx
and bx,0fh
mov tsk_comoptr,bx
pop bx
dec tsk_comcnt
mov ah,1
;
cwc_end:
pop dx
IFDEF LOAD_DS
pop ds
ENDIF
ret
;
tsk_cprint_waitc endp
;
.tsk_ecode
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -