📄 absasm21.bas
字号:
PRINT #2, midline$
PRINT #2, newline$
errorcounter% = errorcounter% + 1
linecounter% = linecounter% - 1
END IF
linecounter% = linecounter% + 1
LOOP UNTIL newline$ = "-u 100, 100"
CLOSE #2
CLOSE #1
IF errorcounter% > 0 THEN
KILL tempfile1$
KILL tempfile2$
KILL tempfile3$
PRINT
PRINT "Error(s) in source code detected. Look in "; errorfile$; " for information."
END
END IF
asmlength$ = MID$(oldline$, INSTR(oldline$, ":") + 1, 4)
PRINT "Source code byte length detected."
OPEN tempfile3$ FOR INPUT AS #1
OPEN tempfile4$ FOR OUTPUT AS #2
SEEK #1, SEEK(1) + 5
PRINT #2, "a"
DO
LINE INPUT #1, sourceline$
SEEK #1, SEEK(1) + 2
sourceline$ = RIGHT$(sourceline$, LEN(sourceline$) - 10)
IF LEN(sourceline$) > 0 THEN PRINT #2, sourceline$
LOOP UNTIL sourceline$ = ""
CLOSE #1
PRINT #2, ""
PRINT #2, "u 100, "; asmlength$
PRINT #2, "q"
CLOSE #2
' -------------------------------------------------------------------------- '
' Run DEBUG again to create a full output file: '
' -------------------------------------------------------------------------- '
SHELL rundebug$ + "<" + tempfile4$ + ">" + tempfile3$
' -------------------------------------------------------------------------- '
' Scan through DEBUG output file to get the byte offsets for the lines with '
' labels in the sourcefile: '
' -------------------------------------------------------------------------- '
OPEN tempfile3$ FOR INPUT AS #1
DO
LINE INPUT #1, readline$
LOOP UNTIL INSTR(readline$, "-u 100,")
SEEK #1, SEEK(1) + 2
labelcounter% = 1
linecounter% = 1
DO
LINE INPUT #1, readline$
IF label(labelcounter%).labelnum = linecounter% THEN
label(labelcounter%).labelpos = MID$(readline$, 6, 4)
labelcounter% = labelcounter% + 1
END IF
linecounter% = linecounter% + 1
LOOP UNTIL readline$ = "-q"
CLOSE #1
' -------------------------------------------------------------------------- '
' Update tempfile with the correct byte offset numbers for lines with labels '
' in the sourcefile: '
' -------------------------------------------------------------------------- '
OPEN tempfile2$ FOR INPUT AS #1
OPEN tempfile3$ FOR OUTPUT AS #2
PRINT #2, "a"
DO
LINE INPUT #1, sourceline$
FOR labelscan% = 1 TO numlabels%
IF INSTR(sourceline$, LTRIM$(RTRIM$(label(labelscan%).labelname))) THEN
sourceline$ = LEFT$(sourceline$, INSTR(sourceline$, LTRIM$(RTRIM$(label(labelscan%).labelname))) - 1) + label(labelscan%).labelpos
END IF
NEXT labelscan%
PRINT #2, sourceline$
LOOP UNTIL EOF(1)
CLOSE #1
PRINT #2, ""
PRINT #2, "u 100, "; asmlength$
PRINT #2, "q"
CLOSE #2
PRINT "Label conversion completed."
' -------------------------------------------------------------------------- '
' Make a final pass through DEBUG to create final output file: '
' -------------------------------------------------------------------------- '
SHELL rundebug$ + "<" + tempfile3$ + ">" + tempfile3$
PRINT "DEBUG output file successfully created."
' -------------------------------------------------------------------------- '
' Calculate the longest possible BASIC string declaration line: '
' -------------------------------------------------------------------------- '
linecounter% = 1
longestline% = 0
maxsourcelength% = 0
maxcodelength% = 0
OPEN tempfile3$ FOR INPUT AS #1
DO
LINE INPUT #1, readline$
LOOP UNTIL INSTR(readline$, "-u 100,")
SEEK #1, SEEK(1) + 2
DO
LINE INPUT #1, readline$
linelength% = LEN(RTRIM$(MID$(readline$, 11, 14)))
IF linelength% >= longestline% THEN
codelength% = 0
FOR findcodelength% = 1 TO linelength% STEP 2
IF MID$(RTRIM$(MID$(readline$, 11, 14)), findcodelength%, 1) = "0" THEN
codelength% = codelength% + 1
ELSE
codelength% = codelength% + 2
END IF
NEXT findcodelength%
IF maxsourcelength% < codelength% THEN maxsourcelength% = codelength%
longestline% = linelength%
END IF
linecounter% = linecounter + 1
LOOP UNTIL readline$ = "-q"
maxcodelength% = LEN(codestring$) + 3 + LEN(codestring$) + (longestline% \ 2) * 11 + maxsourcelength%
CLOSE #1
' -------------------------------------------------------------------------- '
' Transform the source code to BASIC string declaration lines: '
' -------------------------------------------------------------------------- '
FOR modifylabels% = 1 TO numlabels%
MID$(label(modifylabels%).labelname, 2, 16) = LCASE$(RIGHT$(label(modifylabels%).labelname, 15))
NEXT modifylabels%
OPEN tempfile3$ FOR INPUT AS #1
OPEN tempfile1$ FOR INPUT AS #2
IF writemethod% = 1 THEN
OPEN destfilename$ FOR APPEND AS #3
ELSE
OPEN destfilename$ FOR OUTPUT AS #3
END IF
DO
LINE INPUT #1, readline$
LOOP UNTIL INSTR(readline$, "-u 100,")
SEEK #1, SEEK(1) + 2
PRINT #3, "' ------ Created with Absolute Assembly 2.1 by Petter Holmberg, -97. ------- '"
PRINT #3, ""
PRINT #3, codestring$ + " = " + CHR$(34) + CHR$(34)
linecounter% = 1
labelcounter% = 1
DO
LINE INPUT #1, readline$
readline$ = RTRIM$(readline$)
IF NOT EOF(2) THEN LINE INPUT #2, sourceline$ ELSE sourceline$ = ""
IF readline$ <> "-q" THEN
sourcedata$ = RTRIM$(MID$(readline$, 11, 14))
basicline$ = codestring$ + " = " + codestring$
FOR makebasicline% = 1 TO LEN(sourcedata$) STEP 2
IF MID$(RTRIM$(MID$(readline$, 11, 14)), makebasicline%, 1) = "0" THEN
basicline$ = basicline$ + " + CHR$(&H" + MID$(sourcedata$, makebasicline% + 1, 1) + ")"
ELSE
basicline$ = basicline$ + " + CHR$(&H" + MID$(sourcedata$, makebasicline%, 2) + ")"
END IF
NEXT makebasicline%
IF LEN(basicline$) < maxcodelength% THEN basicline$ = basicline$ + SPACE$(maxcodelength% - LEN(basicline$))
basicline$ = basicline$ + " ' "
IF label(labelcounter%).labelnum = linecounter% THEN
basicline$ = basicline$ + RTRIM$(label(labelcounter%).labelname) + ": "
labelcounter% = labelcounter% + 1
END IF
asmline$ = (RIGHT$(readline$, (LEN(readline$) - 24)))
IF INSTR(asmline$, CHR$(9)) THEN MID$(asmline$, INSTR(asmline$, CHR$(9))) = " "
asmline$ = RTRIM$(asmline$)
basicline$ = basicline$ + asmline$
FOR labelscan% = 1 TO numlabels%
IF INSTR(sourceline$, UCASE$(RTRIM$(label(labelscan%).labelname))) AND INSTR(sourceline$, ":") = 0 THEN
basicline$ = LEFT$(basicline$, LEN(basicline$) - 4)
basicline$ = basicline$ + RTRIM$(label(labelscan%).labelname)
END IF
NEXT labelscan%
PRINT #3, basicline$
END IF
linecounter% = linecounter% + 1
LOOP UNTIL readline$ = "-q"
IF callabs% = 1 THEN
PRINT #3, ""
PRINT #3, "offset% = SADD("; codestring$; ")"
PRINT #3, "DEF SEG = VARSEG("; codestring$; ")"
PRINT #3, "CALL ABSOLUTE(offset%)"
PRINT #3, "DEF SEG"
END IF
PRINT #3, ""
PRINT #3, "' ------ Created with Absolute Assembly 2.1 by Petter Holmberg, -97. ------- '"
CLOSE #3
CLOSE #2
CLOSE #1
PRINT "Source code successfully moved to BASIC destination file."
KILL tempfile1$
KILL tempfile2$
KILL tempfile3$
KILL tempfile4$
PRINT
PRINT "Time of conversion:"; TIMER - conversiontime!; "seconds."
PRINT
PRINT "Convert another file? (y/n) : ";
DO
kbd$ = INKEY$
IF LCASE$(kbd$) = "n" THEN
PRINT LCASE$(kbd$)
END
END IF
IF LCASE$(kbd$) = "y" THEN
PRINT LCASE$(kbd$)
GOTO Start
END IF
LOOP
END
' -------------------------------------------------------------------------- '
' Error handler: '
' -------------------------------------------------------------------------- '
ErrorHandler:
CLEAR
PRINT
PRINT "Whoops! An error occured during program execution."
PRINT "Check the spelling of your filenames and check the sourcefile for illegal lines."
PRINT
PRINT "Press any key to end program..."
DO: LOOP WHILE INKEY$ = ""
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -