; Canzona RAMless monitor ; Copyright 1998-2000 by Canzona Technologies ; Commands: ; daaaa,cccc = display cccc bytes at DS:aaaa ; edd = echo byte value dd ; faaaa,cccc,dddd = fill cccc bytes at DS:aaaa with word dddd ; iaaaa,cc,dd = write byte "dd" "cccc" times to DS:aaaa, increment "dd" ; mdd,aaaa = write byte dd to address aaaa, increment aaaa ; opppp,dddd = output word dddd to port pppp ; raaaa = read from DS:aaaa until next RX, don't output anything ; saaaa = DS segment ; waaaa,dddd = write word dd to DS:aaaa until next RX ; Registers: ; DI = first parameter ; SI = second parameter ; ES = third parameter ; DS = current data segment ; AX, BX, CX, DX are scratch registers ; macros preserve everything but AX unless specified otherwise ideal model small p186 include "cond.inc" ;Conditional structure macros dataseg databuf: IFDEF UseDOS db 0ffffh dup (?) ;Free memory for testing ENDIF segment _MONITOR para "CODE" assume cs:_MONITOR, ds:nothing, es:nothing, ss:nothing public _Debugger IFDEF UseDOS IoWidth = 1 ;Width of I/O data bus in bytes SerPort = 02f8h ;Serial port base address ELSE IoWidth = 2 ;Width of I/O data bus in bytes SerPort = 0 ;Serial port base address ENDIF lf = 10 cr = 13 ;------------------------ ; Write AL to serial port ; AL unchanged ;------------------------ macro SerTx mov ah,al UntilBeg mov dx,5*IoWidth ;;Serial port TX status in al,dx and al,20h ;;Ready to TX if set UntilEnd nz mov al,ah mov dx,SerPort ;;Serial port base address out dx,al endm ;------------------------------------------------------- ; Return serial port RX status in carry (set = RX ready) ;------------------------------------------------------- macro SerStat mov dx,5*IoWidth ;;Serial port RX status in al,dx and al,1 ;;RX data ready if set add al,-1 ;;Set carry if data ready endm ;------------- ; Wait for RX ; return in AL ;------------- macro SerIn UntilBeg SerStat UntilEnd c mov dx,SerPort ;Serial port base address in al,dx endm ;------------------------------------------------------- ; Wait for RX, echo, convert to upper case, return in AL ;------------------------------------------------------- macro SerRx SerIn SerTx ;;Send it back cmp al,'a' IfBeg ae cmp al,'z' IfBeg be sub al,'a'-'A' IfEnd IfEnd endm ;-------------------------------------- ; Display message in cs:bx until 0 byte ;-------------------------------------- macro msg_bx WhileBeg mov al,[cs:bx] and al,al WhileDo nz SerTx inc bx WhileEnd endm ;----------- ; Display cr ;----------- macro crlf mov al,cr SerTx mov al,lf SerTx endm ;----------------------------------- ; Display AL bits 0-3 as a hex digit ;----------------------------------- macro al_hex and al,0fh add al,'0' cmp al,'9' ifbeg a add al,'A'-('9'+1) ifend SerTx endm ;----------------------------- ; Display data as 2 hex digits ;----------------------------- macro data_2hex dat mov al,dat shr al,4 al_hex ;;Upper bits first mov al,dat al_hex ;;Lower bits endm ;----------------------------- ; Display data as 4 hex digits ;----------------------------- macro data_4hex dat mov ax,dat mov al,ah shr al,4 al_hex ;;Upper bits of upper byte mov ax,dat mov al,ah al_hex ;;Lower bits of upper byte mov ax,dat shr al,4 al_hex ;;Upper bits of lower byte mov ax,dat al_hex ;;Lower bits of lower byte endm ;------------------------------ ; Display address as hex digits ;------------------------------ macro adr_hex data_4hex ds mov al,':' SerTx data_4hex di mov al,' ' SerTx mov al,'=' SerTx mov al,' ' SerTx endm jumps ;Automatic absolute jumps ;--------------------------------------------------- ; Read hex value from serial port, return in BX ; Read until ',' or CR ; return exit character in AL, hex digit count in CL ;--------------------------------------------------- macro read_hex xor bx,bx ;;Clear value xor cl,cl WhileBeg SerRx cmp al,cr IfBeg ne cmp al,',' IfEnd WhileDo ne shl bx,4 sub al,'0' cmp al,9 IfBeg a sub al,'A'-('9'+1) IfEnd or bl,al inc cl WhileEnd endm ;--------------------------------------------- ; Read command and parameters from serial port ; Parameters read to DI, SI, ES ; Command returned in AL ; BX, CX are altered ;--------------------------------------------- macro read_cmd SerRx mov ch,al ;;Command read_hex ;;Address parameter or cl,cl IfBeg ne ;;Parameter received if nz mov di,bx cmp al,cr ifbeg ne ;;More parameters if ne read_hex ;;Byte count parameter mov si,bx cmp al,cr ifbeg ne ;;More parameters if ne read_hex mov es,bx ifend ifend IfEnd mov al,lf SerTx mov al,ch endm ;--------------------- ; Write byte to memory ;--------------------- proc MemByte mov ax,di mov [si],al inc si jmp CmdLoop endp ;--------------- ; Display memory ;--------------- proc disp mov cx,si add cx,15 ;;Round up shr cx,4 ;;Line count loopbeg z SerStat ifbeg nc ;;Quit if something received adr_hex mov bx,16 ;;Column count untilbeg data_2hex [di] mov al,' ' SerTx inc di dec bx untilend z crlf ifend loopend SerStat ifbeg c SerIn ;;Clear terminating keypress ifend jmp CmdLoop endp ;------------ ; Fill memory ;------------ proc fill mov ax,es mov cx,si loopbeg z mov [di],ax inc di inc di loopend jmp CmdLoop endp ;------------------ ; Incrementing fill ;------------------ proc increment mov bx,es mov bh,bl untilbeg mov cx,si loopbeg z mov [di],bl inc di loopend inc bl cmp bl,bh untilend e jmp CmdLoop endp ;------------------- ; Output to I/O port ;------------------- proc output mov dx,di mov ax,si IFDEF UseDOS out dx,al ELSE out dx,ax ENDIF jmp CmdLoop endp ;------------ ; Read memory ;------------ proc read untilbeg mov ax,[di] SerStat untilend c SerIn ;;Clear terminating keypress jmp CmdLoop endp ;------------- ; Write memory ;------------- proc write mov cx,si ;;Data to write untilbeg mov [di],cx SerStat untilend c SerIn ;;Clear terminating keypress jmp CmdLoop endp Hello db "RAMless monitor 2/18/97", cr, lf, 0 helptext: db "daaaa,cccc = display cccc bytes at DS:aaaa", cr, lf db "edd = echo byte dd", cr, lf db "faaaa,cccc,dddd = fill cccc bytes at DS:aaaa with word dddd", cr, lf db 'iaaaa,cccc,dd = write "dd" "cccc" times to DS:aaaa, increment "dd"', cr, lf db "mdd,aaaa = write byte dd to address aaaa, increment aaaa", cr, lf db "opppp,dddd = output dddd to port pppp", cr, lf db "raaaa = read from DS:aaaa until next RX, don't output anything", cr, lf db "saaaa = set DS segment to aaaa", cr, lf db "waaaa,dddd = write word dddd to DS:aaaa until next RX", cr, lf db 0 proc _Debugger far xor ax,ax mov di,ax ;Default address mov es,ax ;Default data inc ax mov si,ax ;Default byte count mov ax,seg databuf mov ds,ax ;Default data segment mov dx,SerPort ;Serial port base address add dx,IoWidth*(1-0) ;Interrupt enable register xor al,al out dx,al add dx,IoWidth*(3-1) ;Line control register mov al,10000011b ;8N1, divisor latch out dx,al add dx,IoWidth*(0-3) ;Divisor LSB mov al,12 ;9600 baud out dx,al add dx,IoWidth*(1-0) mov al,0 out dx,al add dx,IoWidth*(3-1) in al,dx and al,NOT 80h out dx,al ;Clear divisor latch add dx,IoWidth*(4-3) ;Modem control register mov al,00000011b ;RTS, DTR out dx,al mov bx,offset Hello msg_bx CmdLoop: mov al,'>' SerTx read_cmd cmp al,'D' ;Display ifbeg e jmp disp ifend cmp al,'E' ;Echo ifbeg e mov ax,di SerTx jmp CmdLoop ifend cmp al,'F' ;Fill ifbeg e jmp fill ifend cmp al,'H' ;Help ifbeg ne cmp al,'?' ifend ifbeg e mov bx,offset helptext msg_bx ifend cmp al,'I' ;Incrementin data fill ifbeg e jmp increment ifend cmp al,'M' ;Byte write ifbeg e jmp MemByte ifend cmp al,'O' ;Output ifbeg e jmp output ifend cmp al,'R' ;Read ifbeg e jmp read ifend cmp al,'S' ;Segment ifbeg e mov ds,di jmp CmdLoop ifend cmp al,'W' ;Write ifbeg e jmp write ifend jmp CmdLoop endp ends CheckNest end _Debugger