Paper Model now Steps. Stepping algorithm optimized. 11 bytes saved.

A project log for Mystery 6502 program for the Kim Uno #1kBChallenge

The #1kBChallenge inspired me to dust off the Kim-Uno and write an Enigma Z30 simulator. This is a very rare numbers only Enigma Machine.

Arduino EnigmaArduino Enigma 12/18/2016 at 04:010 Comments

I was looking for a way to make the Excel Paper Model for the Z30 calculate the stepping points so it would be a complete model of the machine. The example shown below is for a rotor with a Ring Setting of 4, the 1 mark on the ring is set to the 4 position on the rotor. When this rotor is showing a 2, it is at its stepping point. The 9 is aligned with the 2 and at position 0 of the Entry Rotor.

This made me realize that I can ask what is the Ring Setting value at position 0 and if it is a 9, then step the next rotor to the right.

This is the old algorithm, it uses an interesting logic to determine the stepping point.

0623 STEPRT 
0623        LDX #$00        A2 00
0625        LDY #$03        A0 03
0627 STEPSC 
0627        LDA *LRRING,X   B5 54
0629        CLC             18
062A        ADC #$08        69 08
062C        CMP #$0A        C9 0A
062E        BCC STEPS1      90 02
0630        SBC #$0A        E9 0A
0632 STEPS1 
0632        CMP *LROTOR,X   D5 58
0634        BNE STEPS2      D0 05
0636        LDA #$01        A9 01
0638        JMP STEPDN      4C 3D 06
063B STEPS2 
063B        LDA #$00        A9 00
063D        STA *TMP02,X    95 5F
063F        INX             E8
0640        DEY             88
0641        BNE STEPSC      D0 E4
0643        STY *TMP01      84 5E

This is the new algorithm. It calls the ENRING routine with A=0 and Values of X of 1,2 and 3 to see if the three rotors on the right are at the stepping position, indicated by the value of 9.

To get the shorter algorithm to align with 0643, the beginning of the unchanged part, 11 NOP are used.

0623 STEPRT 
0623        LDX #$01        A2 01
0625        LDY #$03        A0 03

0627 STEPSC 
0627        LDA #$00        A9 00
0629        JSR ENRING      20 67 06
062C        CMP #$09        C9 09
062E        BEQ STEPDN      F0 02
0630        LDA #$00        A9 00
0632 STEPDN 
0632        STA *TMP01,X    95 5E
0634        INX             E8
0635        DEY             88
0636        BNE STEPSC      D0 EF

0638        NOP             EA
0639        NOP             EA
063A        NOP             EA
063B        NOP             EA
063C        NOP             EA
063D        NOP             EA
063E        NOP             EA
063F        NOP             EA
0640        NOP             EA
0641        NOP             EA
0642        NOP             EA

0643        STY *TMP01      84 5E

In the next release of the program, those 11 NOP will be eliminated.