Inlined call vicSelectGfxBank::$0 = call toDd00(vicSelectGfxBank::gfx)

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) = *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) & $7f
  asm { lda#0  }
  main::port4Value#0 = *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B)
  *SCREEN = main::port4Value#0
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  call main
  to:__start::@1
__start::@1: scope:[__start]  from __start
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  return 
  to:@return

SYMBOL TABLE SSA
__constant struct MOS6526_CIA * const CIA2 = (struct MOS6526_CIA *)$dd00
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
__constant char * const SCREEN = (char *)$400
void __start()
void main()
char main::port4Value
char main::port4Value#0

Adding number conversion cast (unumber) $7f in *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) = *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) & $7f
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (struct MOS6526_CIA *) 56576
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast $7f
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $7f
Successful SSA optimization PassNFinalizeNumberTypeConversions
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
CALL GRAPH

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) = *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) & $7f
  asm { lda#0  }
  [2] main::port4Value#0 = *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B)
  [3] *SCREEN = main::port4Value#0
  to:main::@return
main::@return: scope:[main]  from main
  [4] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::port4Value
char main::port4Value#0 // 4.0

Initial phi equivalence classes
Added variable main::port4Value#0 to live range equivalence class [ main::port4Value#0 ]
Complete equivalence classes
[ main::port4Value#0 ]
Allocated zp[1]:2 [ main::port4Value#0 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) = *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) & $7f [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement asm { lda#0  } always clobbers reg byte a 
Potential registers zp[1]:2 [ main::port4Value#0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 4: zp[1]:2 [ main::port4Value#0 ] 
Uplift Scope [MOS6526_CIA] 
Uplift Scope [MOS6569_VICII] 
Uplift Scope [MOS6581_SID] 
Uplift Scope [] 

Uplifting [main] best 29 combination reg byte a [ main::port4Value#0 ] 
Uplifting [MOS6526_CIA] best 29 combination 
Uplifting [MOS6569_VICII] best 29 combination 
Uplifting [MOS6581_SID] best 29 combination 
Uplifting [] best 29 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests problem writing/reading joystick encountered by Danny Spijksma
// https://www.protovision.games/hardw/build4player.php?language=en&fbclid=IwAR1MJLgQjOU0zVa0ax2aNeGa-xVbE9IGY9zC6b6eInTV4HQzoUAoCPoXu14
  // Upstart
  // Commodore 64 PRG executable file
.file [name="danny-joystick-problem.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .const OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
  /// The CIA#2: Serial bus, RS-232, VIC memory bank
  .label CIA2 = $dd00
  .label SCREEN = $400
.segment Code
  // main
main: {
    // [0] *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) = *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) & $7f -- _deref_pbuc1=_deref_pbuc1_band_vbuc2 
    lda #$7f
    and CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B
    sta CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B
    // asm { lda#0  }
    lda #0
    // [2] main::port4Value#0 = *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) -- vbuaa=_deref_pbuc1 
    lda CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B
    // [3] *SCREEN = main::port4Value#0 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    jmp __breturn
    // main::@return
  __breturn:
    // [4] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant struct MOS6526_CIA * const CIA2 = (struct MOS6526_CIA *) 56576
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
__constant char * const SCREEN = (char *) 1024
void main()
char main::port4Value
char main::port4Value#0 // reg byte a 4.0

reg byte a [ main::port4Value#0 ]


FINAL ASSEMBLER
Score: 26

  // File Comments
// Tests problem writing/reading joystick encountered by Danny Spijksma
// https://www.protovision.games/hardw/build4player.php?language=en&fbclid=IwAR1MJLgQjOU0zVa0ax2aNeGa-xVbE9IGY9zC6b6eInTV4HQzoUAoCPoXu14
  // Upstart
  // Commodore 64 PRG executable file
.file [name="danny-joystick-problem.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .const OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
  /// The CIA#2: Serial bus, RS-232, VIC memory bank
  .label CIA2 = $dd00
  .label SCREEN = $400
.segment Code
  // main
main: {
    // (CIA2->PORT_B) &= 0x7f
    // [0] *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) = *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) & $7f -- _deref_pbuc1=_deref_pbuc1_band_vbuc2 
    lda #$7f
    and CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B
    sta CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B
    // asm
    // asm { lda#0  }
    lda #0
    // char port4Value = CIA2->PORT_B
    // [2] main::port4Value#0 = *((char *)CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B) -- vbuaa=_deref_pbuc1 
    lda CIA2+OFFSET_STRUCT_MOS6526_CIA_PORT_B
    // *SCREEN = port4Value
    // [3] *SCREEN = main::port4Value#0 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // main::@return
    // }
    // [4] return 
    rts
}
  // File Data

