5 MODE7 10 REM 'BADFIX' Source code 20 memory_address=&70 :REM and &71 30 line_address=&72 :REM and &73 40 line_length=&74 50 : 60 FOR pass=0 TO 3 STEP 3 70 P%=&900 :REM Assembly address 80 [OPT pass 90 .start 100 LDA &18 \Read the value of PAGE from &18 110 STA memory_address+1 \Store it in memory_address 120 LDA#0 130 STA memory_address 140 TAY 150 LDA #&0D \Load accumulator with Carriage return (&0D) 160 STA(memory_address),Y \Write it as first byte of program 170 : 180 .outer 190 JSR update \Increment pointer 200 LDY #0 210 LDA (memory_address),Y \Get next program byte 220 CMP #&FF \Is it &FF (indicating end of program) 230 BNE over \If not branch to 'over' 240 LDA #7 \Must be end of program 250 JSR &FFEE \Sound beep 260 RTS \and finish 270 : 280 .over 290 LDA memory_address \Update line_address to point- 300 STA line_address \to start of new line 310 LDA memory_address+1 320 STA line_address+1 330 JSR update \Update pointer twice- 340 JSR update \to skip line number 350 LDA #3 \Store the value 3 in line_length register 360 STA line_length \(we are 3 bytes into the line) 370 : 380 .inner 390 INC line_length \Increment line_length value to point to next byte 400 BEQ force_end \Check to see if it exceeds maximum permitted- 410 \length of line (255 bytes) if so, branch to 'force_end' 420 JSR update \Update pointer 430 LDA (memory_address),Y \Get next byte 440 CMP #&0D \Is it a Carriage return? (&0D) 450 BEQ carriage_return \If so, branch to 'carriage_return' 460 CMP #&20 \Is it a control character (value less than &20) 470 BCS inner \If not, branch back to 'inner' 480 LDA #ASC("@") \Must be a control character 490 STA (memory_address),Y \overwrite it with '@' 500 JMP inner \Jump back to 'inner' 510 : 520 .carriage_return \Must be Carriage return 530 LDA line_length \Get line_length value 540 LDY #2 550 STA (line_address),Y \Write correct value into line length byte 560 JMP outer \Jump back to 'outer' 570 : 580 .update \Update memory_address 590 INC memory_address \Increment Lo byte 600 BNE past \If it has not reached zero, branch to 'past' 610 INC memory_address+1 \Lo byte has reached zero, increment Hi byte 620 : 630 .past 640 RTS \Return from sub-routine 650 : 660 .force_end \Force an end to the program 670 LDA #&0D \Load a Carriage return (&0D) 680 STA (memory_address),Y \Store it as last byte of line 690 JSR update \Update pointer 700 LDA #&FF \Load accumulator with &FF (end of program byte) 710 LDY #0 720 STA (memory_address),Y \Write it as last byte of program 730 LDY #2 740 STA (line_address),Y \Also write it as line length of last line 750 LDA #7 760 JSR &FFEE \Sound Beep 770 RTS \and finish 780 ] 790 NEXT 800 REM *SAVE BADFIX 0900 096F