ROM Computer Magazine Archive ROM MAGAZINE ISSUE 5 — APRIL/MAY 1984 / PAGE 52

MACTODAT
By Bob Cockroft

    Have you ever wanted to make a machine language subroutine for a Basic program using an assembler, but did not want to waste time rewriting the Operand (Op) codes in data statements? Your problems are over! This is a program which automaticlly rewrites the machine code you have created with an assembler into data statements. By doing this the code can be loaded with the BASIC,and integrated into your program. Before any data lines are created, the program will ask a few simple questions about the machine code and how you want it presented. You will need to know where your machine code starts and ends,at what line number your data statements are to start, and how much you wish the lines incremented by. By using untokenized files(LIST,ENTER) it is possible to add data statements to programs. First, save the MACTODAT program listed below, using the LIST statement, thus creating a untokenized file. Then do the same to the program to which you wish to add data statements.Then, clear the memory of any BASIC program with the NEW statement. LOAD in the machine code you want converted. Now reLOAD in the MACTODAT program with the ENTER command(tokenized files) and RUN it. Be careful not to have your machine code in memory locations used by the BASIC program. The computer will now ask you if you wish to erase the MACTODAT program so that it does not interfere with the program you wish to add the data statements to. After the MACTODAT program has finished, ENTER the program to which you want to add the DATA statements. If you have done all these steps correctly, you will have successfully merged your program with the newly created DATA statements.
    The MACTODAT program creates the DATA statements by PRINTing them on the screen. What makes this program interesting is its use of the memory location 842. While the DATA statements are being drawn, memory location 842 contains a 12, the value of "write to the screen" mode. However, after a screen of DATA statements has been created, the cursor is placed at the top of the screen, and a value of 13 is POKEd into the memory location in order to put the computer into the "return key mode". What you will see is the cursor at the top left corner of the screen, then moving down as if the RETURN key were repetitively pressed. Theoretically this is what is happening. By poking 13 into location 842 Dec., one tricks the computer into thinking the RETURN key is pressed. As the cursor passes each line of data, the line is added to your program as if you had manually typed a line in and RETURNed the cursor yourself.
    It is important to note that at the bottom of a screen of data is a line that reads:

POKE 842,12:GOTO

    This line tells the computer to return to "write mode". In other words the cursor is prevented from moving any farther down the screen and allows the computer to function in its normal way. The second part of this line tells the computer where to go to next.
    Although this program did not take me very long to make, I have found it helpful in making machine code programs for ROM,and hopefully, it will be equally helpful to you.

1 GRAPHICS 0:? :? " RETURNS DATA LINES FROM MACHINE CODE":?
2 ? "Print START and END address of machine code":INPUT A1,A2:GRAPHICS 0:POKE 842,12:POSITION 2,2
3 DIM AN$(10)
4 ? "print beginning DATA line number(must be greater than 180)":INPUT LOW
5 ? "line numbers incremented by what?":INPUT INCR
6 ? "do you want to ERASE the orginal PROGRAM?":INPUT AN$
7 GRAPHICS 0
25 FOR LINE=LOW TO 32000 STEP INCR
30 POSITION PEEK(82),3*COUNT+3:I=0:COUNT=COUNT+1:PRINT LINE;"DATA";
82 I=I+1
88 IF I=24 THEN ? PEEK(A1);:A1=A1+1:GOTO 120
90 PRINT PEEK(A1);",";:A1=A1+1
92 IF A1=A2 THEN ? PEEK(A1);:? :? :?"POKE 842,12:GOTO 160":GOTO 155
95 GOTO 82
120 ? :IF COUNT=6 THEN ?:? "POKE 842,12:GOTO 160":GOTO 155
150 NEXT LINE
155 POSITION PEEK(82),0
159 GOTO 180
160 IF A1>=A2 THEN 162
161 COUNT=0:I=0:GRAPHICS 0:GOTO 150
162 IF AN$="N" THEN END
163 GRAPHICS 0:POSITION PEEK(82),8
164 ? "2":? "25":? "30":? "82":?"88":? "90":? "159":? "92":? "95":? "120":? "150":? "155"
165 ? "160":? "162":? "163":? "164":? "165":? "180":? "161":? "POKE 84 2,12:GOTO 175"
170 GOTO 176
175 GRAPHICS 0:POSITION PEEK(82),8:? "1":? "3":? "4":? "5":? "6":? "7":? "176":? "175":? "170":? "POKE 842,12:LIST"
176 POSITION PEEK(82),0:POKE 842,13
180 POKE 842,13