Metropoli BBS
VIEWER: bas2asm.bas MODE: TEXT (ASCII)
'DEBUG*DEBUG*DEBUG*DEBUG*DEBUG*DEBUG*DEBUG*DEBUG*DEBUG*THEBUG*THE-BUG*



'DECLARE SUB appendmenu ()

'DECLARE SUB editor (lengte%, mistake%)

'DECLARE SUB comments ()

'DECLARE SUB appending (path$, name$)

'DECLARE SUB inline (lines%, errorline%)

'comments                                    'read what is going on



ON ERROR GOTO errorhandling



CLS

edit:

call editor (lengte%, mistake%)                       'goto edit session

call inline (lengte%, mistakeline%)                   'well, do your thing

call appendmenu                                       'appending?

SUB editor (lines%, fout%)



'first get the code out of the inputdevices of BASIC



IF fout% = 0 THEN

PRINT "ASM /Debug Session for QBASIC 1.1    Rick Elbers  "

PRINT "______________________            _____________________________________"

COLOR 10, 0

PRINT "1) All the mnemonics acceptable for debug are allowed( like: rcl bx,1). "

PRINT "2) The end of your code is,like in debug, signified by an empty line    "

PRINT "   followed by <enter>. "

PRINT "3) A new entry in the existing line (when ttttttypinggg behaivorir      "

PRINT "   is bothering you) will be given when <esc> is pressed."

PRINT "4) Default key when given <Y/N> choice is (arbitrair)<Y>"

PRINT :

COLOR 7, 0

PRINT "You can put the assembly code below the line:"

PRINT "________________________________________________________________________"





OPEN "C:\codein.dbg" FOR OUTPUT AS #1



PRINT #1, "a"





END IF

fout% = 0

DO

	PRINT USING "###"; lines% + 1;

	PRINT "    ";

	LINE INPUT code$

	IF code$ = "" THEN EXIT loop

	lines% = lines% + 1

	cod$ = code$

	PRINT #1, cod$

LOOP

PRINT #1, "":

PRINT #1, "u  100  200"

PRINT #1, "q"

CLOSE #1, #2

CLOSE #1











'The second step i have learned from an earlier snippit:

'It succeeds in making a .txt file from the debug session

'our PC is going through .





SHELL "cd c:\"                             'Bill Gates does also have DEbug

SHELL "debug < codein.dbg >codedbg.txt"



END SUB



SUB inline (lines%, errorline%)

'Getting the codes in known format in the file "codehex.bas"



OPEN "c:\codedbg.txt" FOR INPUT AS #1

OPEN "codehex.bas" FOR OUTPUT AS #2



PRINT #2, "sub inline"

PRINT #2, CHR$(13)

PRINT #2, "'HIERONDER VOLGT DE CODE IN QBASIC"

PRINT #2, "'**************************************"

PRINT #2, CHR$(13)

PRINT #2, "asm$="; CHR$(34) + CHR$(34)

LINE INPUT #1, regel$'contains 'a' :wasting

LINE INPUT #1, regel$'contains nothing

'____________________________________________________________________________

'

'All that we use the a-session for is for error-checking..

'______________________________________________________________________

FOR i% = 0 TO 2 * lines% 'from 3 to .....

	IF (i% MOD 4) = 0 THEN kritisch1& = SEEK(1)    'saving offset asmcode

	IF (i% MOD 4) = 2 THEN kritisch& = SEEK(1)     'or offset error message

	LINE INPUT #1, regel$

	IF INSTR(regel$, CHR$(&H5E)) <> 0 THEN

		CLS

		PRINT "fatal error in line"; FIX(i% / 2):

		IF (i% MOD 4) = 0 THEN SEEK 1, kritisch&     'getting back errcode

		IF (i% MOD 4) = 2 THEN SEEK 1, kritisch1&

		LINE INPUT #1, regel$: PRINT "<"; MID$(regel$, 11); ">"

		errorline% = i% / 2: CLOSE #1, #2: ERROR 100

	END IF

NEXT i%

LINE INPUT #1, regel$ 'contains nothing

LINE INPUT #1, regel$ 'contains "u 100 200"

LINE INPUT #1, regel$ 'contains nothing



PRINT "Code is now being saved in the file 'codehex.bas'"

'Mark Kims tutorial for instance will

'give more insight in the used formats



FOR i% = 1 TO lines%   'from 1 to...(u code:no empty lines in between)

	PRINT "Processing "; i%; "lines of asmcode"

	LINE INPUT #1, regel$

	zoek$ = RTRIM$(MID$(regel$, 11, 10))

	posit% = LEN(zoek$)

		PRINT #2, "asm$=asm$";

		DO WHILE posit% > j% * 2

			PRINT #2, "+chr$(&H" + MID$(regel$, 11 + 2 * j%, 2) + ")";

			j% = j% + 1

		LOOP                            'the tabs for the textfile

		IF j% < 2 THEN PRINT #2, SPC(11);

		IF j% < 3 THEN PRINT #2, SPC(11);

		IF j% < 4 THEN PRINT #2, SPC(11);

		IF j% < 5 THEN PRINT #2, SPC(11);

		IF j% < 6 THEN PRINT #2, SPC(2);

		PRINT #2, "'" + MID$(regel$, 25):

		j% = 0

NEXT i%

CLOSE #1



PRINT #2, CHR$(13)

PRINT #2, "'____________________________"

PRINT #2, " Codeoff%=sadd(asm$)"

PRINT #2, " def seg= varseg(asm$)"

PRINT #2, " call absolute(Codeoff%)"

PRINT #2, "'____________________________"

PRINT #2, CHR$(13)

PRINT #2, " end sub"



CLOSE #2



END SUB







SUB appendmenu

'Last and final step was not so easy as it seems:

'I just wanted to give everyone the choice of not only

'appending the code to a file( which was easy) but also

'to right off start that file( which was not so easy).

'I just hope that it was worth it because you now can go

'on with your main job(QB i presume...) right away.

'But remember that it succeeds by tricking QBASIC.

CLS

PRINT "Do you want to append your code right away to a file?"

COLOR 10, 0

PRINT "                      <Y/N>"

PRINT "______________________________________________________"

PRINT :

COLOR 7, 0

PRINT "                        ";

LINE INPUT answer$:

PRINT :

IF LCASE$(LEFT$(answer$, 1)) <> "n" THEN              'yes appending



	PRINT "Please enter the filename(with a .bas extension)"

	COLOR 10, 0

	PRINT "It does not matter if it is an already existing"

	PRINT "            file or a new one."

	PRINT :

	COLOR 7, 0

	PRINT "           C:\dos\";

	LINE INPUT answer$:

	CLS

	PRINT

	PRINT "The thing that matters is: do you already have a   "

	PRINT "sub-inline in the file ? When this is not the first"

	PRINT "asm sub in the file or not the first attempt for   "

	PRINT "appending you can be pretty sure sub inline        "

	PRINT "already exists. So you have to rename the coming   "

	PRINT "-to-append-sub."

	COLOR 10, 0

	PRINT "___________________________________________________"

	PRINT "To be sure,does u want the upcoming asmsub to be "

	PRINT "named otherwise ?   <Y/N>"

	PRINT "___________________________________________________"

	PRINT :

	LINE INPUT ren$

	IF LCASE$(LEFT$(ren$, 1)) <> "n" THEN                   'rename sub

		PRINT "name of asmsub:";

		LINE INPUT nme$

	END IF

		CLS



	path$ = "c:\dos\" + answer$                              'the append

	call appending (path$, nme$)                                'thing



	PRINT "The file should be were it ought to be now..........."

	PRINT "That being in sub "; newname$; " in the file C:\dos\"; answer$;

	PRINT "_____________________________________________________"

	PRINT :

	PRINT "     Do you want to start the QBASIC environment"

	PRINT "            with *"; answer$; "* now ?"

	COLOR 10, 0

	PRINT :

	PRINT "                       <Y/N>"

	PRINT "_____________________________________________________"

	PRINT :

	PRINT "                    ";

	LINE INPUT answer1$







	IF LCASE$(LEFT$(answer1$, 1)) <> "n" THEN               'start

		OPEN "c:\dos\gogoasm.bat" FOR OUTPUT AS #1

		a$ = "c:\dos\gogoasm.bat"

		PRINT #1, "start Qbasic ";

		PRINT #1, "C:\dos\";

		PRINT #1, answer$

		CLOSE #1

		SHELL a$                                              'no start

	ELSE

		CLS

		COLOR 10, 0

		PRINT "______________________________________________________"

		PRINT "The asmcode is saved in the file c:\dos\"; answer$

		PRINT "in the sub "; newname$; " for use on a later occasion."

		PRINT "______________________________________________________"

		COLOR 7, 0

		KILL "codehex.bas"   'there is a better one now sub- bed in

	END IF

ELSE

	CLS                                                     'no appending

	COLOR 10, 0

	PRINT "_____________________________________________________"

	PRINT "The asmcode is saved in the file c:\codehex.bas"

	PRINT "            for use on a later occasion."

	PRINT "_____________________________________________________"

	COLOR 7, 0

END IF     'we are done whatsoever!

KILL "codein.dbg"      'there is a better one saved!!

KILL "codedbg.txt"     'be it codehex.bas or sub enz....





END SUB

SUB appending (path$, nme$)



OPEN path$ FOR APPEND AS #1

OPEN "codehex.bas" FOR INPUT AS #2

	PRINT "Appending the asmcode"



IF nme$ <> "" THEN

	LINE INPUT #2, regel$: regel$ = "sub " + nme$: PRINT #1, regel$

ELSE

	nme$ = "inline"

END IF



DO UNTIL EOF(2)

	PRINT ".";

	LINE INPUT #2, regel$

	PRINT #1, regel$

LOOP



CLOSE #1, #2

PRINT : PRINT :

COLOR 10, 0

CLS

PRINT "..........The end of asmcodegeneration..............."

PRINT "....................................................."

PRINT "_____________________________________________________"



END SUB





SUB comments

'Okay,here is something. I have already seen at least two great tutorials

'on Debug. I remember also seeing something in the ASM snippits, but

'up till now i have not seen very much in the meaning of *tools* for using

'it. 1 exception being a snippit describing textfile creation from

'debugsessions .Of course i do understand why not so much effort is invested

'here. Debug has only limited possibilities....



'Still i think it is great for beginners like me. I only hated the constant

'going back and forth between debug and QBASIC, and the distraction from

'the difficult enough asm task. Well that is why i made this Asm_to_QBsub

'file. You can just type in asm on input, and you get back a file/sub/

'totally ready to use! So now we can concentrate on ASM itself.



'I have made a long day with creating this, but it is far from complete.

'When you go through this program( as **everyone** must be capable off)

'you will see further possibilities: I wont be surprised if someone writes

'a program which just rewrites your plain asmcode inside one of your

'programs to acceptable basic using debug, but i wont make it. I want to

'adress further asm topics...(but okay, maybe i might compile this one and

'then it is already almost the same)



'As already said: it works but everyone can pretty much optimize it to

'to his or her own needs. You might plan a-sessions apart from

'u-sessions. Making 1)extracting the code from u- easier

'                   2)allowing some sort of modification

'                     with earlier errorcode. It should even

'                     be easy to implement functions keys.

'3)Also a lot of speeding up is possible :you can use dos/ bios functions

'  for the file i/o making it much better.

'rick.elbers@tip.nl

'_________________________________________________________________________

'IMPORTANT: THIS FILE USES FILES WITH THE FOLLOWING NAMES:

'C:\CODEIN.DBG        C:\CODEDBG.TXT      C:\CODEHEX.BAS

'C:\DOS\GOGOASM.BAT

'_________________________________________________________________________







'boven inline sub komt dit te staan

'So here's the third step: the addition i made was

'that the textfile is transformed again into the known

'codehex.bas form. Everyone who has followed Mark Kims

'tutorial should be very familiar with the structures

'and even the names used.





END SUB



END



errorhandling:                                 'as in :real life

mistake% = ERR

IF ERR = 53 THEN RESUME NEXT

IF ERR = 100 THEN                              'asmcode error





PRINT "____________________"

b = CSRLIN: PRINT "Try again(any key)":

PRINT "_____THE END________"

LOCATE b, 19: INPUT ; jk$

CLS

OPEN "codein.dbg " FOR OUTPUT AS #1

OPEN "codedbg.txt " FOR INPUT AS #2

	LINE INPUT #2, regel$   'contains "a"

	LINE INPUT #2, regel$   'contains nothing

	PRINT #1, "a"

	IF mistakeline% <> 1 THEN                        'not in first line



	FOR k% = 1 TO 2 * (mistakeline% - 1)

		LINE INPUT #2, regel$                           'get nice code form codedbg.txt

		IF k% MOD 2 = 1 THEN

			PRINT USING "###"; 1 + ((k% - 1) / 2);

			PRINT "    ";

			PRINT MID$(regel$, 11):

			PRINT #1, MID$(regel$, 11)                    'print it in codein.dbg

		END IF

	NEXT k%

	CLOSE #2: KILL "codedbg.txt"                      'Its useless for know



	END IF                                            'first line error

	lengte% = mistakeline% - 1: mistakeline% = 0



	RESUME edit:       'well let us do it again

END IF









[ RETURN TO DIRECTORY ]