
; This is a walk through of a .DIS file
; Hopefully it will help you understand how to use the info provided,
; to get your .DIS files working.
; All the help text below starts with a ~

; Assembling this file will report an error for every help line
; that you have not ;~commented.


;FASM   fastkey .asm  made by Bitdog's DIS.com

	ORG 100h
	USE16
L0100:  ;Instructions		OPcode= ;p### HEX#s	Chars	;Label:4next

~the L0100: Label is needed by DDISS stripper to know where to start stripping.
~the end of line info starts with it's OP number = ;p### in decimal
~& that ;p is used by DDISS to end info removal & start white space removal.

~the $8EE8 is the hex values in byte form as they were assembled,
~2 digits ## per byte. Count them /2 shows the total instruction size.

~The first2 HEX numbers are the OP code, next2 are the EXTension code byte,
~& input numbers needed often follow. 386+ code deviates from that format.
~Some OP codes don't have EXT byte, but do have input values.

~Next is the 'chars' that made the instruction line.
~just like seen in the .com file.
~My editor shows the value in decimal of the character under the cursor,
~so the decimal, Hex, & char are all in the EOL INFO.

~The LABEL: at the end of the Line, is for the NEXT LINE DOWN
~so the DIS.com Label dropper can just change the two bytes before it to 13,10
~CRLF and it is dropped where it needs to be.
~The first DIS.com pass through the .com
~just makes a list of CALLed or JMP2 Labels,
~& they get dropped as they are made on the second pass.
~The Labels #### is the debth into the .com file + 100h offset for the PSP.
~So finding a Label is much easier.
~If the .DIS file is size altered & assembled, the values are wrong but the
~Labels still work as they were intended to work.

	MOV	GS,AX			;p142 $8EE8	''	;L0102:

 DB 101 ; GS:				;p101 $65	'e'	;L0103:
	MOV	AL,[$0449]		;p160 $A04904	'I'	;L0106:
~	MOV	AL,[GS:$0449] ;is how you write it, but
~GS: is a prefix to the instuction & it is shown just as the assembler
~assembled it.  You could code like this if you want.  It assembles just fine.
~There are many prefixes, REP is a prefix, DB 66h, 67h, SEGs CS: DS: ES: FS:
~just to name a few. Adaptability is a skill one must practice to perfect.

	CMP	AL,3			;p060 $3C03	'< '	;L0108:
	JNZ	L02C8 ;386+		;p015 $0F85BC01	''	;L010C:
~The ;386+ comment helps point out unusual code size or something.
~I haven't got them all marked correctly, but I got what I could.
~There was not any clear info available to learn from when I made this
~disassembler, so I checked all the info available, and rounded it down
~to what actually worked. So there is definately going to be some mistakes.
~the disassembler has a PROC for every instruction, & that is how I can
~alter each instruction to something that works, & change it if it doesn't.

	PUSH	47104			;p104 $6800B8	'h '	;L010F:
	POP	ES			;p007 $07	''	;L0110:
	JMP near L027C			;p233 $E96901	'i'	;L0113:

	NOP				;p144 $90	''	;L0114:
~a NOP is often a sign that the original code was ALIGN 2
~or more, for a PROC or data that needs a LABEL,
~& that LABEL: is just after the last NOP.
~the reason why it was not dropped, is that it wasn't CALLed or JMPed2

 DB "Press 2 keys,",13,10	;L0123:
 DB "alternating one after the other,",13,10	;L0145:
 DB "as fast as you can."	;L0158:
 DB " DEMO",13,10	;L015F:
 DB "The updated screen will show the change",13,10	;L0188:
 DB "that the port GetKEY IN AL,60h code is doing.",13,10	;L01B7:
 DB "Each Line is 160 GetKEYs."	;L01D0:
 DB "  Fast is 3 lines = 480",13,10	;L01E9:
 DB "GetKEY requests to the 8042 kbd chip.",13,10	;L0210:
 DB "Blinking= a released key."	;L0229:
 DB "  The keyboard is 10-31 khz",13,10	;L0246:
 DB "& quickly repeated GetKEY requests causes a delay.",13,10,36	;L027B:

~FINDTEXT.inc comes close looking like MESSAGE DATA like I write. Basic rules=
~Line length needs to fit on the screen, and lines end with .?! or CRLF.
~The LABEL: helps address locations that are accessed by the code,
~so you can alter & make a label where it's needed.

~Here is an ALIGN 2 PROC with a NOP and a dropped LABEL that was CALLed.
	NOP				;p144 $90	''
L027C:	MOV	DX,276			;p186 $BA1401	''	;L027F:
~276 is actually a LABEL, but DIS.com can't know that so it's a decimal.
~You can find the LABEL in the HEX dump info. Little ENDian = L0114:
~Labels are in WORD form so Little ENDian the bytes,
~means swap them to make a Label.


	MOV	AH,9			;p180 $B409	' '	;L0281:
	INT	$21			;p205 $CD21	'!'	;L0283:
	MOV	AH,8			;p180 $B408	' '	;L0285:
	INT	$21			;p205 $CD21	'!'	;L0287:
	PUSHF				;p156 $9C	''	;L0288:
	CLI	;disable INTs		;p250 $FA	''	;L0289:
~since DIS.com shows unfamiluar code written by others,
~important stuff may have a comment.
~If INTs get shut off, & not turned back on, you have problem code.
~in this case PUSHF saves the INT state & POPF restores it,
~but at least it's marked.

	IN	AL,$21			;p228 $E421	'!'	;L028B:
~Since IN OUT & INT instructions always work with HEX numbers,
~DIS.com writes HEX for them.

~Bit wise instructions OR AND TEST use binary values, & 2 = it's decimal value.
	OR	AL,00000010b ; 2	;p012 $0C02	''	;L028D:
	OUT	$21,AL			;p230 $E621	'!'	;L028F:
	POPF				;p157 $9D	''
L0290:
 DB 129,255,161,15 ; CMP DI,4001 ;sizeDIF ;p129 $81FFA10F '' ;L0294:
~if FASM assembles an instruction to a different value than other assemblers
~this .DIS would never reassemble to be the same bytes as the .COM file it
~was made from, and getting an exact duplicate is NECESSARY to know you have
~it right. The Decimal Dump, DDump insures that any assembler producing any
~values, get reassembled to be the same.
~After FCC.COM proves that they are the same, make a back up & you can comment
~out the DDump & just use the INSTRUCTION. (by dropping it to the next line)
~There is usually a comment describing why it was DDumped.

	JB	L0298			;p114 $7202	'r'	;L0296:
	XOR	DI,DI			;p049 $31FF	'1'
L0298:	IN	AL,$60	; GetKEY	;p228 $E460	'`'	;L029A:
~I went out of my way to  GetKEY commented, it's important 4 code reading.
~DIS.com outFiles don't have real comments and getting an overview of the
~codes goals & techniques is important. So the stupid comments help me4 that.
~You could Edit DIS.com + find the comments you don't like, change them to
~spaces, so DIS.com remains the SAME SIZE, and you wouldn't see them again.
	CMP	AL,129			;p060 $3C81	'<'	;L029C:
	JZ	L02A1			;p116 $7403	't '	;L029E:
	STOSB				;p170 $AA	''	;L029F:
	JMP short L0290			;p235 $EBEF	''
L02A1:	MOV	AL,32			;p176 $B020	' '	;L02A3:
	CLI	;disable INTs		;p250 $FA	''	;L02A4:
	OUT	$20,AL			;p230 $E620	' '	;L02A6:
	STI	; enable INTs		;p251 $FB	''	;L02A7:
 DB 101 ; GS:				;p101 $65	'e'	;L02A8:
	MOV	AX,[$0480]		;p161 $A18004	''	;L02AB:
	CLI	;disable INTs		;p250 $FA	''	;L02AC:
 DB 101 ; GS:				;p101 $65	'e'	;L02AD:
	MOV	[$041A],AX		;p163 $A31A04	' '	;L02B0:
 DB 101 ; GS:				;p101 $65	'e'	;L02B1:
	MOV	[$041C],AX		;p163 $A31C04	''	;L02B4:
	STI	; enable INTs		;p251 $FB	''	;L02B5:
	PUSHF				;p156 $9C	''	;L02B6:
	CLI	;disable INTs		;p250 $FA	''	;L02B7:
	IN	AL,$21			;p228 $E421	'!'	;L02B9:
	AND	AL,11111101b ; 253	;p036 $24FD	'$'	;L02BB:
	OUT	$21,AL			;p230 $E621	'!'	;L02BD:
	POPF				;p157 $9D	''	;L02BE:
	MOV	AX,1824			;p184 $B82007	' '	;L02C1:
	XOR	DI,DI			;p049 $31FF	'1'	;L02C3:
	MOV	CX,2000			;p185 $B9D007	''	;L02C6:
	REPZ				;p243 $F3	''	;L02C7:
	STOSW				;p171 $AB	''
L02C8:	MOV	AX,19456		;p184 $B8004C	' L'	;L02CB:
	INT	$21			;p205 $CD21	'!'	;L02CD:
~DIS.com can't see anything except the line it's working on, so it
~doesn't know an INT follows MOV AX,??
~I usually end up changing 19456 to
~	MOV	AX,4C00h	;for readablity

EOF

~The char = 26 stops Fasm from processing any data after it, which is great.

~Not shown here is
~ times ### DB 0
~ which is often off by one, but it's better that 999 lines of DB 0
~ If a FCV of .DIS files shows Label adr changes after a TIMES instruction
~ it's off by one?  If FCC.com says there is a difference,
~ it's probably a TIMES oops again....

~AND, DIS.com does one line and THEN checks to see if it's done.
~ so the LAST line of a .DIS file often has, what ever bytes followed it in
~ memory added to complete the instruction that was probably just data.
~ It's all just numbers to the computer,
~ and DIS.com can't tell the difference either.
~ So edit it out.  I just load the original .COM file and view the end.
~ Then view the assembled .DIS file to see the offenders.
~ FCV.com will show it also.
~ Edit the .DIS until FCC.com says it's identical,
~ by making a Decimal Dump out of the last line and adjust the Last Label ####
~ and you got it.
~ Then you can butcher the back up all you want, like I do.

~NOTE, alter DIS.com defaults in an editor to get UPPER case or lower case
~ instructions, followed by a TAB or a SPACE
~ Every body has their own writing style, and if I want my .DIS file to match
~ the .asm that was included, I can get something to match in FCV.com
~ by altering the defaults in a few different coppies of DIS.com
~ with different names.

~Maybe the next version of DIS.com can have a whole bunch of complicated
~ input commands that no one can remember and
~ won't allow the program to run unless you get it right :)

;By Bitdog.

