📄 pcrom.htm
字号:
; ROMLIB.ASM - Large/Small model rom-code interface code for C Compilers
;***********************************************************************
; (c) B Brown, School of Electronics
; Central Institute of Technology,
; Private Bag, Heretaunga
; New Zealand
;
; designed to be compatible with TURBOC and MICROSOFT C Ver 3.00
;
; Include macros to handle saving and restoring of registers
; and the offset from BP for the 1st parameter.
INCLUDE romlib.mac
timer EQU 40h
port_b EQU 61h
NAME ROMLIB
page ,132
CGROUP GROUP CODE
DGROUP GROUP STACK
ASSUME CS:CGROUP, DS:DGROUP, SS:DGROUP
STACK SEGMENT STACK 'STACK'
DW 1024 DUP(0) ; make room for stack
STACK ENDS
CODE SEGMENT PUBLIC 'CODE'
PUBLIC _ipl_load, _basic_rom
PUBLIC _ser_init, _serial_in, _serial_out, _serial_status
PUBLIC _prn_out, _prn_status, _prn_init
PUBLIC _kbhit, _kbgetch, _kbstatus
PUBLIC _segread
PUBLIC _inportb, _outportb, _int86
PUBLIC _pokeb, _peekb
PUBLIC _biosequip, _bioskey, _biosmemory, _biosprint
PUBLIC _getvect, _setvect
PUBLIC _setvmode, _setvcurs, _setvcpos, _getvcpos
PUBLIC _setvpage, _scrollvup, _scrollvdn
PUBLIC _getvattrchar, _setvattrchar, _setvchar
PUBLIC _setvpall, _setvdot, _getvdot
PUBLIC _setvstring
PUBLIC _getvmode
PUBLIC _savevscrn, _getvscrn, _printstr
PUBLIC _beep
PUBLIC _enable, _disable
;***********************************************************************
; void ipl_load( void ) BOOT from disk
;***********************************************************************
PTY _ipl_load
save
int 19h
restore ; these will never be executed
ret ; if unsuccessful, will invoke int18h
_ipl_load ENDP
;***********************************************************************
; void basic_rom( void ) Jump to basic rom space F600:0000 on motherboard
;***********************************************************************
PTY _basic_rom
save
int 18h
restore ; these will never be executed
ret ;
_basic_rom ENDP
;***********************************************************************
; void ser_init( unsigned char parameters, int comport )
; Initialise the serial port
;
;***********************************************************************
PTY _ser_init
save
push dx
mov ah,00h ; Function: Initialise serial card
mov al,byte ptr [bp+base]
mov dx,[bp+base+2]
and dx,1 ; ensure only com1 or com2
int 14h
pop dx
restore
ret
_ser_init ENDP
;***********************************************************************
; int serial_in( int comport ) Read a character from the serial port
;***********************************************************************
PTY _serial_in
save
push dx
mov ah,02h ; Function: Auxiliary Input
mov dx,[bp+base]
and dx,1
int 14h
mov ah,00h ; character returned in AL
pop dx
restore
ret
_serial_in ENDP
;***********************************************************************
; void serial_out( char byte, int comport ) Output a character to serial port
;***********************************************************************
PTY _serial_out
save
push dx
mov al, byte ptr [bp+base] ; get character to send
mov dx, [bp+base+2]
and dx,1
mov ah, 01h ; Function: Auxiliary Output
int 14h
pop dx
restore ; bit 7 of ah=1 if error
ret
_serial_out ENDP
;***********************************************************************
; int serial_status( int comport ) Return serial port status
; AH = LCstatus, AL=MCstatus
;***********************************************************************
PTY _serial_status
save
push dx
mov dx, [bp+base]
and dx,1
mov ah, 03h ; Function: Get status
int 14h
pop dx
restore
ret
_serial_status ENDP
;***********************************************************************
; void prn_out( char byte, int printer )
; Output a character to the prn device
;***********************************************************************
PTY _prn_out
save
push dx
mov al, byte ptr [bp+base] ; byte
mov dx, [bp+base+2]
and dx, 3
mov ah, 0h ; Function: Printer Output
int 17h
pop dx
restore ; on return, if AH=1 then
ret ; char could not be sent
_prn_out ENDP
;***********************************************************************
; int prn_status( int printer )
; Return prn device status in AH
; 0x80 = busy
; 0x40 = acknowledge
; 0x20 = out of paper
; 0x10 = selected, on line
; 0x08 = I/O error
; 0x01 = time out
;***********************************************************************
PTY _prn_status
save
push dx
mov dx, [bp+base]
and dx, 3
mov ah, 2h ; Function: Printer Status
int 17h
pop dx
restore
ret
_prn_status ENDP
;***********************************************************************
; int prn_init( int printer ) Initialise printer port
;***********************************************************************
PTY _prn_init
save
push dx
mov dx, [bp+base]
and dx, 3
mov ah, 1h ; Function: Printer Init
int 17h ; AH = printer status
pop dx
restore
ret
_prn_init ENDP
;***********************************************************************
; int kbhit( void ) Test if character avialable at keyboard for input
; returns 0 if input not ready, non-zero otherwise
;***********************************************************************
PTY _kbhit
save
mov ah, 01h ; Function: Direct Console I/O
int 16h
jnz short kbh0 ; is character ready?
xor ax, ax ; no, then return zero
kbh0: restore
ret
_kbhit ENDP
;***********************************************************************
; int kbgetch( void ) Read a character from keyboard
;***********************************************************************
PTY _kbgetch
save
mov ah, 00h ; Function: Console Input Without Echo
int 16h
restore ; char in AL, scan code in AH
ret ; al=0 indicates function key etc
_kbgetch ENDP
;***********************************************************************
; int kbstatus( void ) Read keyboard shift status
; 0x80 = ins ON
; 0x40 = caps toggled
; 0x20 = num lock toggled
; 0x10 = scroll lock toggled
; 0x08 = alt key depressed
; 0x04 = ctrl key depressed
; 0x02 = left shift key depressed
; 0x01 = right shift key depressed
;***********************************************************************
PTY _kbstatus
save
mov ah, 02h ; Function: Keyboard status byte
int 16h
mov ah, 00h
restore ; status in AL
ret
_kbstatus ENDP
;***********************************************************************
; void segread( struct SREGS &sregs )
; Read segment register values into structure
;***********************************************************************
PTY _segread
save
push ds
push si
ifdef LARGE
mov ax,[bp+base+2] ; get segment for sregs
mov ds,ax
endif
mov si, [bp+base] ; get pointer to sregs
mov ax, es
mov [si], ax
mov ax, cs
mov [si+2],ax
mov ax, ss
mov [si+4],ax
mov ax, ds
mov [si+6],ax
pop si
pop ds
restore
ret
_segread ENDP
;***********************************************************************
; int inportb( int port ) read a byte value from a specified port
;***********************************************************************
PTY _inportb
save
push dx
mov dx,[bp+base] ; get port value
xor ax,ax
in al, dx ; read byte
mov ah,00h
pop dx
restore
ret
_inportb ENDP
;***********************************************************************
; void outportb( int port, char byte )
; output a character to the specified port
;***********************************************************************
PTY _outportb
save
push dx
mov dx,[bp+base] ; get port value
mov al,[bp+base+2] ; get character
out dx, al ; output it
pop dx
restore
ret
_outportb ENDP
;***********************************************************************
; void int86( int intnum, struct REGS &inregs, struct REGS &outregs )
; generate a software interrupt of PTY intnum
; use the registers defined in &inregs for input and &outregs for output
;***********************************************************************
PTY _int86
save
push ax
push bx
push cx
push dx
push si
push di
push ds
ifdef LARGE
mov ax,[bp+base+4] ; get segment for inregs
mov ds,ax
endif
mov si,[bp+base+2] ; get invalues for registers
mov ax,[si]
mov bx,[si+2]
mov cx,[si+4]
mov dx,[si+6]
mov di,[si+10]
mov si,[si+8]
cmp word ptr [bp+base], 0005h ; int 5h Print screen
je short din05
cmp word ptr [bp+base], 0010h ; Video I/O
je short din10
cmp word ptr [bp+base], 0011h ; Equipment check
je short din11
cmp word ptr [bp+base], 0012h ; Memory check
je short din12
cmp word ptr [bp+base], 0013h ; Diskette I/O
je short din13
cmp word ptr [bp+base], 0014h ; RS232 I/O
je short din14
cmp word ptr [bp+base], 0016h ; Keyboard
je short din16
cmp word ptr [bp+base], 0017h ; Printer
je short din17
cmp word ptr [bp+base], 001Ah ; Time of day
je short din1a
mov ax, -1 ; Invalid intnum
jmp short derr
din05: int 05h
jmp short dout
din10: int 10h
jmp short dout
din11: int 11h
jmp short dout
din12: int 12h
jmp short dout
din13: int 13h
jmp short dout
din14: int 14h
jmp short dout
din16: int 16h
jmp short dout
din17: int 17h
jmp short dout
din1a: int 1ah
dout:
ifdef LARGE
mov ax,[bp+base+8] ; get segment for outregs
mov ds,ax
mov si,[bp+base+6] ; get offset for outregs
else
mov si,[bp+base+4] ; save registers in output ®s
endif
mov [si],ax
mov [si+2],bx
mov [si+4],cx
mov [si+6],dx
mov [si+8],si
mov [si+10],di
jnc short int860
mov word ptr [si+12],0001h
jmp short derr
int860: mov word ptr [si+12],0000h
derr: pop ds
pop di
pop si
pop dx
pop cx
pop bx
pop ax
restore ; if invalid intnum, just return!
ret
_int86 ENDP
;***********************************************************************
; void pokeb( int segment, int offset, char value );
; write abyte into a memory location at segment:offset
;***********************************************************************
PTY _pokeb
save
push ds
push si
mov ax, [bp+base] ; get segment address into ds
mov ds, ax
mov si, [bp+base+2] ; get offset into si
mov al, [bp+base+4] ; get character
mov byte ptr [si], al ; store value at ds:si
pop si
pop ds
restore
ret
_pokeb ENDP
;***********************************************************************
; char peekb( int segment, int offset );
; return the byte stored at segment:offset
;***********************************************************************
PTY _peekb
save
push ds
push si
mov ax, [bp+base] ; get segment value into ds
mov ds, ax
mov si,[bp+base+2] ; offset into si
xor ax, ax ; clear ax
mov al, byte ptr [si]
pop si
pop ds
restore
ret
_peekb ENDP
;***********************************************************************
; int biosequip( void ); Equipment determination check
;***********************************************************************
PTY _biosequip
save
int 11h
restore
ret
_biosequip ENDP
;***********************************************************************
; int bioskey( int cmd );
; cmd=0, if ((bioskey() & 0x0f) == 0)
; /* bioskey has returned scan code */
; cmd=1, return values, 0 = no key avialable
; non-zero = key, and is buffered ready for next
; call using bioskey( 0 )
; cmd=2, returns current key status for Ins, Numlock etc
; 0x80 = Ins 0x40 = Caps 0x20 = Num Lock 0x10 = Scroll Lock
; 0x08 = Alt 0x04 = Ctrl 0x20 = LeftShift 0x01 = Right Shift
;***********************************************************************
PTY _bioskey
save
mov al, 0
mov ah, [bp+base]
int 16h
restore
ret
_bioskey ENDP
;***********************************************************************
; int biosmemory( void ); Return the number of 1k memory
; blocks avialable
;***********************************************************************
PTY _biosmemory
restore
int 12h
restore
ret
_biosmemory ENDP
;***********************************************************************
; int biosprint( int cmd, int byte, int port );
; return value is current printer status
; lpt1 = port value 0
; lpt2 = port value 1
; cmd=0, Print character byte to printer designed by port
; cmd=1, Initialize printer port
; cmd=2, Read printer status
; 0x01 = Device time out 0x08 = I/O error
; 0x10 = Selected 0x20 = Out of paper
; 0x40 = Acknowledge 0x80 = Not Busy
;***********************************************************************
PTY _biosprint
save
push dx
mov ah, byte ptr [bp+base] ; port number
mov al, byte ptr [bp+base+2] ; byte value
mov dx, [bp+base+4] ; command
int 17h
pop dx
restore
ret
_biosprint ENDP
;***********************************************************************
; long int getvect( int intnumber ); Get interrupt vector
; return address in DX:AX
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -