text stringlengths 0 99.6k |
|---|
Line 16 is the beginning of the main loop of this module. It gets |
a byte from the disk drive. |
Line 17 and 18 handle the line feeds contained in the ASCII file. |
If these are left in the converted file then the printout will be |
double spaced. A "CMP" op-code can give 3 possible results which |
are: |
(1) BCC - less-than (the carry is clear) |
(2) BEQ - equal to (the zero flag is set) |
(3) BCS - equal-to or greater-than (the carry-flag is set). |
Lines 19 through 22 will trap all the codes in the $41 to $5a |
range. In line 20, the branch will occur if the value is |
LESS-THAN a $41. In line 22 the branch will occur if the value is |
MACHINE CODE PROGRAMMING EXAMPLE page 2 |
GREATER-THAN a hex $5a. The comparison is actually made to a hex |
$5b because the carry is set if the values are equal. |
Line 23 sets the high bit of the orginal value and line 24 will |
always branch because no value can be zero with the high bit set. |
Line 25 through 28 traps the values in the range of $61 to $7a. |
Lines 29 through 30 convert the values by subtracting a hex $20 |
from the orginal value. When the SBC opcode is used, it must be |
preceded with the SEC opcode unless the status of the carry flag |
is already known. |
Lines 30 through 34 handle storing the converted value to the |
buffer. The Y Register is set to zero in line 10 and it has not |
been changed to this point. The value is actually stored at the |
address pointed to at aux ($8b) PLUS the value of the Y register. |
So the first time through the loop, aux contains the address $2000 |
in standard lo-byte - hi-byte format ($00 $20) and Y is 0, so the |
first byte is stored at $2000. The second time around the loop, |
the value is stored at $2001 because y is now 1. Y will be |
incremented up to 255 ($FF) and at that point the value will be |
stored at $20FF. When Y is incremented the new value will be 0 |
and this sets the zero flag tested by the BNE op-code, and since |
it is "NOT EQUAL TO ZERO" then this branch will not occur and then |
aux+1 is incremented. Aux will now contain a pointer to the |
address $2100. This is how the converted values are stored in the |
buffer and this process will continue as long as the main loop |
continues. |
Lines 35 to 38 check for the EOF and terminate the loop when it is |
detected. The EOF is indicated by the sixth bit of the status |
byte being set. When you AND the status byte with $40 (binary |
0100 0000) the only two possible results are 0 and $40. Our |
branch here occurs if the result is zero (in other words, the |
sixth bit was NOT set). |
Lines 38 and 39 put the eof marker in the buffer. |
Line 40 restores the input and output devices to normal (input |
keyboard - output screen). |
Line 41 will return us to BASIC. The file has now been read from |
the disk, converting it to PETASCII, and storing it to the |
temporary buffer. |
Line 42 is the beginning of the ML code for use when BASIC SYS's |
back to write the converted file to disk. Line 42 through 45 |
initialize the zero page pointer to point to the address of $2000 |
(beginning of the temporary buffer). |
Line 46 and 47 set up the disk file 8 as the output channel. |
Line 48 initialized the Y Register to the value of zero. |
Line 49 is the beginning of the main loop for the write module. |
It gets a byte from the temporary buffer. |
MACHINE CODE PROGRAMMING EXAMPLE page 3 |
Line 50 tests for the EOF marker and branches if detected. |
Line 51 outputs the byte to the output channel (disk drive in this |
case). |
Lines 52 to 55 take care of managing the Y Register and the zero |
page pointer. This works the same as in lines 32 through 34. |
Line 56 restores the normal input and output channels and line 57 |
returns to BASIC. We only get here by detecting the EOF marker |
back in line 50. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.