Resolved forward reference irq to __interrupt(rom_sys_c64) void irq()

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  asm { sei  }
  *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR
  *VICII_CONTROL1 = *VICII_CONTROL1 | $80
  *RASTER = 0
  *IRQ_ENABLE = IRQ_RASTER
  *KERNEL_IRQ = &irq
  asm { cli  }
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return

__interrupt(rom_sys_c64) void irq()
irq: scope:[irq]  from
  *BG_COLOR = WHITE
  *BG_COLOR = BLACK
  *IRQ_STATUS = IRQ_RASTER
  to:irq::@return
irq::@return: scope:[irq]  from irq
  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 char * const BG_COLOR = (char *)$d020
__constant const char BLACK = 0
__constant char * const CIA1_INTERRUPT = (char *)$dc0d
__constant const char CIA_INTERRUPT_CLEAR = $7f
__constant char * const IRQ_ENABLE = (char *)$d01a
__constant const char IRQ_RASTER = 1
__constant char * const IRQ_STATUS = (char *)$d019
__constant void (** const KERNEL_IRQ)() = (void (**)())$314
__constant char * const RASTER = (char *)$d012
__constant char * const VICII_CONTROL1 = (char *)$d011
__constant const char WHITE = 1
void __start()
__interrupt(rom_sys_c64) void irq()
void main()

Adding number conversion cast (unumber) $80 in *VICII_CONTROL1 = *VICII_CONTROL1 | $80
Adding number conversion cast (unumber) 0 in *RASTER = 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *RASTER = (unumber)0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (void (**)()) 788
Simplifying constant pointer cast (char *) 53266
Simplifying constant pointer cast (char *) 53265
Simplifying constant pointer cast (char *) 53273
Simplifying constant pointer cast (char *) 53274
Simplifying constant pointer cast (char *) 53280
Simplifying constant pointer cast (char *) 56333
Simplifying constant integer cast $80
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $80
Finalized unsigned number type (char) 0
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

__interrupt(rom_sys_c64) void irq()
irq: scope:[irq]  from
  [0] *BG_COLOR = WHITE
  [1] *BG_COLOR = BLACK
  [2] *IRQ_STATUS = IRQ_RASTER
  to:irq::@return
irq::@return: scope:[irq]  from irq
  [3] return 
  to:@return

void main()
main: scope:[main]  from
  asm { sei  }
  [5] *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR
  [6] *VICII_CONTROL1 = *VICII_CONTROL1 | $80
  [7] *RASTER = 0
  [8] *IRQ_ENABLE = IRQ_RASTER
  [9] *KERNEL_IRQ = &irq
  asm { cli  }
  to:main::@return
main::@return: scope:[main]  from main
  [11] return 
  to:@return


VARIABLE REGISTER WEIGHTS
__interrupt(rom_sys_c64) void irq()
void main()

Initial phi equivalence classes
Complete equivalence classes
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *BG_COLOR = WHITE [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [1] *BG_COLOR = BLACK [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [2] *IRQ_STATUS = IRQ_RASTER [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [5] *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [6] *VICII_CONTROL1 = *VICII_CONTROL1 | $80 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [7] *RASTER = 0 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [8] *IRQ_ENABLE = IRQ_RASTER [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [9] *KERNEL_IRQ = &irq [ ] (  [ ] { }  ) always clobbers reg byte a 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 
Uplift Scope [irq] 
Uplift Scope [] 

Uplifting [main] best 104 combination 
Uplifting [irq] best 104 combination 
Uplifting [] best 104 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// A minimal working raster IRQ
  // Upstart
  // Commodore 64 PRG executable file
.file [name="irq-kernel.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 IRQ_RASTER = 1
  .const WHITE = 1
  .const BLACK = 0
  .const CIA_INTERRUPT_CLEAR = $7f
  .label KERNEL_IRQ = $314
  .label RASTER = $d012
  .label VICII_CONTROL1 = $d011
  .label IRQ_STATUS = $d019
  .label IRQ_ENABLE = $d01a
  .label BG_COLOR = $d020
  .label CIA1_INTERRUPT = $dc0d
.segment Code
  // irq
// Interrupt Routine
irq: {
    // interrupt(isr_rom_sys_c64_entry) -- isr_rom_sys_c64_entry 
    // [0] *BG_COLOR = WHITE -- _deref_pbuc1=vbuc2 
    lda #WHITE
    sta BG_COLOR
    // [1] *BG_COLOR = BLACK -- _deref_pbuc1=vbuc2 
    lda #BLACK
    sta BG_COLOR
    // [2] *IRQ_STATUS = IRQ_RASTER -- _deref_pbuc1=vbuc2 
    // Acknowledge the IRQ
    lda #IRQ_RASTER
    sta IRQ_STATUS
    jmp __breturn
    // irq::@return
  __breturn:
    // [3] return 
    // interrupt(isr_rom_sys_c64_exit) -- isr_rom_sys_c64_exit 
    jmp $ea31
}
  // main
main: {
    // asm { sei  }
    sei
    // [5] *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR -- _deref_pbuc1=vbuc2 
    // Disable CIA 1 Timer IRQ
    lda #CIA_INTERRUPT_CLEAR
    sta CIA1_INTERRUPT
    // [6] *VICII_CONTROL1 = *VICII_CONTROL1 | $80 -- _deref_pbuc1=_deref_pbuc1_bor_vbuc2 
    // Set raster line to $100
    lda #$80
    ora VICII_CONTROL1
    sta VICII_CONTROL1
    // [7] *RASTER = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta RASTER
    // [8] *IRQ_ENABLE = IRQ_RASTER -- _deref_pbuc1=vbuc2 
    // Enable Raster Interrupt
    lda #IRQ_RASTER
    sta IRQ_ENABLE
    // [9] *KERNEL_IRQ = &irq -- _deref_qprc1=pprc2 
    // Set the IRQ routine
    lda #<irq
    sta KERNEL_IRQ
    lda #>irq
    sta KERNEL_IRQ+1
    // asm { cli  }
    cli
    jmp __breturn
    // main::@return
  __breturn:
    // [11] return 
    rts
}
  // File Data

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

FINAL SYMBOL TABLE
__constant char * const BG_COLOR = (char *) 53280
__constant const char BLACK = 0
__constant char * const CIA1_INTERRUPT = (char *) 56333
__constant const char CIA_INTERRUPT_CLEAR = $7f
__constant char * const IRQ_ENABLE = (char *) 53274
__constant const char IRQ_RASTER = 1
__constant char * const IRQ_STATUS = (char *) 53273
__constant void (** const KERNEL_IRQ)() = (void (**)()) 788
__constant char * const RASTER = (char *) 53266
__constant char * const VICII_CONTROL1 = (char *) 53265
__constant const char WHITE = 1
__interrupt(rom_sys_c64) void irq()
void main()



FINAL ASSEMBLER
Score: 98

  // File Comments
// A minimal working raster IRQ
  // Upstart
  // Commodore 64 PRG executable file
.file [name="irq-kernel.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 IRQ_RASTER = 1
  .const WHITE = 1
  .const BLACK = 0
  .const CIA_INTERRUPT_CLEAR = $7f
  .label KERNEL_IRQ = $314
  .label RASTER = $d012
  .label VICII_CONTROL1 = $d011
  .label IRQ_STATUS = $d019
  .label IRQ_ENABLE = $d01a
  .label BG_COLOR = $d020
  .label CIA1_INTERRUPT = $dc0d
.segment Code
  // irq
// Interrupt Routine
irq: {
    // interrupt(isr_rom_sys_c64_entry) -- isr_rom_sys_c64_entry 
    // *BG_COLOR = WHITE
    // [0] *BG_COLOR = WHITE -- _deref_pbuc1=vbuc2 
    lda #WHITE
    sta BG_COLOR
    // *BG_COLOR = BLACK
    // [1] *BG_COLOR = BLACK -- _deref_pbuc1=vbuc2 
    lda #BLACK
    sta BG_COLOR
    // *IRQ_STATUS = IRQ_RASTER
    // [2] *IRQ_STATUS = IRQ_RASTER -- _deref_pbuc1=vbuc2 
    // Acknowledge the IRQ
    lda #IRQ_RASTER
    sta IRQ_STATUS
    // irq::@return
    // }
    // [3] return 
    // interrupt(isr_rom_sys_c64_exit) -- isr_rom_sys_c64_exit 
    jmp $ea31
}
  // main
main: {
    // asm
    // asm { sei  }
    sei
    // *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR
    // [5] *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR -- _deref_pbuc1=vbuc2 
    // Disable CIA 1 Timer IRQ
    lda #CIA_INTERRUPT_CLEAR
    sta CIA1_INTERRUPT
    // *VICII_CONTROL1 |=$80
    // [6] *VICII_CONTROL1 = *VICII_CONTROL1 | $80 -- _deref_pbuc1=_deref_pbuc1_bor_vbuc2 
    // Set raster line to $100
    lda #$80
    ora VICII_CONTROL1
    sta VICII_CONTROL1
    // *RASTER = $00
    // [7] *RASTER = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta RASTER
    // *IRQ_ENABLE = IRQ_RASTER
    // [8] *IRQ_ENABLE = IRQ_RASTER -- _deref_pbuc1=vbuc2 
    // Enable Raster Interrupt
    lda #IRQ_RASTER
    sta IRQ_ENABLE
    // *KERNEL_IRQ = &irq
    // [9] *KERNEL_IRQ = &irq -- _deref_qprc1=pprc2 
    // Set the IRQ routine
    lda #<irq
    sta KERNEL_IRQ
    lda #>irq
    sta KERNEL_IRQ+1
    // asm
    // asm { cli  }
    cli
    // main::@return
    // }
    // [11] return 
    rts
}
  // File Data

