Automatic Proofreader by Charles Brannon for the Commodore 64 Compute Gazette October 1983
Methodology
Text entered has it's PETSCII values summed. The LSB of the sum is printed in reverse print in the upper left corner. The checksum is only a summation so order of text, rotations and other inline swaps don't modify the checksum. The tool is launched by intercepting the CHRIN kernel call by modifying the vector at 0x0324-0x0325 to be instead a location within this program, which itself calls CHRIN, but also collects the keystrokes in the process to calculate the checksum, with special cases for SPACE and RETURN.
Code
Line number | BASIC command | Comment |
---|---|---|
100 | FOR I=828 TO 932: | I is counting through tape buffer |
READ A: | Example | |
POKE I,A: | Example | |
NEXT: | Example | |
PRINT"{CLR}{RVS}sys 828{OFF} to activate.{2 down}" | Instruction text | |
110 | POKE178,165: | Page Zero. Move begin of TAPE BUFFER to 0x03A5 from 0x033C. This substantially shortens the tape buffer. |
print"sys 828{home}": | Prepare text for user. 0d828 = 0x033C | |
end | Release back to user from BASIC program mode | |
120 | DATA169,75,141,36,3,169,3,141 | A9 4B 8D 24 03 A9 03 8D |
130 | DATA37,3,169,0,133,255,96,32 | 25 03 A9 00 85 FF 60 20 |
140 | DATA87,241,133,252,134,253,132,254 | 57 F1 85 FC 86 FD 84 FE |
150 | DATA8,201,13,240,17,201,32,240 | 08 C9 0D F0 11 C9 20 F0 |
160 | DATA5,24,101,255,133,255,165,252 | 05 18 65 FF 85 FF A5 FC |
170 | DATA166,253,164,254,40,96,169,13 | A6 FD A4 FE 28 60 A9 0D |
180 | DATA32,210,255,165,214,141,165,3 | 20 D2 FF A5 D6 8D A5 03 |
190 | DATA206,165,3,169,0,133,216,169 | CE A5 03 A9 00 85 D8 A9 |
200 | DATA19,32,210,255,169,18,32,210 | 13 20 D2 FF A9 12 20 D2 |
210 | DATA255,169,58,32,210,255,166,255 | FF A9 3A 20 D2 FF A6 FF |
220 | DATA169,0,32,205,189,169,0,133 | A9 00 20 CD BD A9 00 85 |
230 | DATA255,169,32,32,210,255,32,210 | FF A9 20 20 D2 FF 20 D2 |
240 | DATA255,173,165,3,133,214,76,98,3 | FF AD A5 03 85 D6 4C 62 03 |
Assembly
- Move the vector to CHRIN into this program and then terminate
033C : LDA Immediate 4B ; LSB of new vector for CHRIN (A9 4B)
033E : STA Absolute 0x0324 ; LSB of CHRIN(8D 24 03)
0341 : LDA Immediate 03 ; MSB of new vector for CHRIN (A9 03)
0343 : STA Absolute 0x0325 ; MSB of CHRIN (8D 25 03)
- Clear checksum register
0346 : LDA Immediate 00 ; Clear A (A9 00)
0348 : STA Zeropage FF ; Clear 0x00FF (85 FF)
- Terminate
034A : RTS ; 60
- This is now resident code that is executed as part of CHRIN
- Launch CHRIN
034B : JSR F157 ; Kernel routine CHRIN (20 57 F1)
- Undocumented register dump for X, Y
034E : STA Zeropage FC ; MLZP Memory 2 (85 FC)
0350 : STX Zeropage FD ; MLZP Memory 3 (86 FD)
0352 : STY Zeropage FE ; MLZP Memory 4 (84 FE)
0354 : PHP ; 08
0355 : CMP Immediate 0D ; Is this a CR? (C9 0D)
0357 : BEQ 11 ; If so, go to 0x036A (F0 11)
0359 : CMP Immediate 20 ; Is this an ASCII space? (C9 20)
035B : BEQ 05 ; If so, go to 0x0362 (F0 05)
035D : CLC ; 18
035E : ADC Zeropage FF ;65 FF
0360 : STA Zeropage FF ;85 FF
- Is Space
0362 : LDA Zeropage FC ;A5 FC
0364 : LDX Zeropage FD ;A6 FD
0366 : LDY Zeropage FE ;A4 FE
0368 : PLP ; 28
0369 : RTS ; 60
- It is CR
036A : LDA Immediate 0D ; PETSCII Carriage return to next line A9 0D
036C : JSR FFD2 ; CHROUT New Line (20 D2 FF)
- capture current line number. We're about to print and will want to return to this location
036F : LDA Zeropage D6 ; A5 D6
0371 : STA Absolute 03A5 ; 8D A5 03
0374 : DEC Absolute 03A5 ; CE A5 03
- Line number stored in 0x03A5. Get ready to print to screen
0377 : LDA Immediate 00 ; (A9 00)
0379 : STA Zeropage D8 ; Inserts = 0 (85 D8)
037B : LDA Immediate 13 ; HOME character (A9 13)
037D : JSR FFD2 ; CHROUT - Set cursor to pos 0,0 (20 D2 FF)
0380 : LDA Immediate 12 ; Reverse character code (A9 12)
0382 : JSR FFD2 ; CHROUT - Set text to reverse mode (20 D2 FF)
0385 : LDA Immediate 3A ; ASCII":" (A9 3A)
0387 : JSR FFD2 ; Print the ":" (20 D2 FF)
038A : LDX Zeropage FF ; Read Checksum from FF (A6 FF)
038C : LDA Immediate 00 ; Force output to be 8 bit number (A9 00)
038E : JSR BDCD ; LINPRT - Print AAXX to screen (20 CD BD)
0391 : LDA Immediate 00 ; Clear A (A9 00)
0393 : STA Zeropage FF ; Clear Checksum to zero (85 FF)
0395 : LDA Immediate 20 ; ASCII Space (A9 20)
0397 : JSR FFD2 ; CHROUT - Draw two spaces (20 D2 FF)
039A : JSR FFD2 ; CHROUT (20 D2 FF)
039D : LDA Absolute 03A5 ; AD A5 03
03A0 : STA Zeropage D6 ; Current physical line number 0-24 (85 D6)
03A2 : JMP Absolute 0362; 4C 62 03
03A5 : xx ; Line number, used by program