Link

Print Following Null-Terminated String

This is used within INIT until SUBS is loaded and the equivalent there can be used.

The return address at the top of the stack is effectively (one before) the start of the string.

Let’s load that into $FE/$FF.

416C  68            PLA
416D  85 FE         STA $FE
416F  68            PLA
4170  85 FF         STA $FF

We will increment $FE/$FF as we move through the string but we’ll use ($FE), Y with Y set to #$00 to retrieve the characters.

4172  A0 00         LDY #$00

Increment the low byte ($FE) and carry to high byte ($FF) if needed.

4174  E6 FE         INC $FE
4176  D0 02         BNE $417A

4178  E6 FF         INC $FF

Load the character to print into A.

417A  B1 FE         LDA ($FE),Y

If A is zero, we’re done.

417C  F0 08         BEQ $4186

Otherwise, set the high bit (not sure why) and call the ROM routine to print the character in A.

417E  09 80         ORA #$80
4180  20 ED FD      JSR $FDED

Jump back to increment $FE/$FF for the next character.

4183  4C 74 41      JMP $4174

If we’ve hit the null, we’ve now got out return address, so put that on the stack.

4186  A5 FF         LDA $FF
4188  48            PHA
4189  A5 FE         LDA $FE
418B  48            PHA

and return.

418C  60            RTS

External Sub-Routines Used

$FDED — print the character in the accumulator

Zero Page Locations Used

Note these are effectively local variables. They are set within the sub-routine and nothing external refers to them.

$FE — low byte of address within string to print

$FF — high byte of address within string to print

What Calls This

  • Three places in INIT ($4003, $4024, $4092)