kickc/src/test/ref/test-keyboard-space.log

750 lines
35 KiB
Plaintext

Inlined call vicSelectGfxBank::$0 = call toDd00(vicSelectGfxBank::gfx)
Inlined call call __init
Eliminating unused variable with no statement keyboard_matrix_read::$0
Eliminating unused variable with no statement keyboard_key_pressed::$0
Eliminating unused variable with no statement keyboard_key_pressed::$1
CONTROL FLOW GRAPH SSA
void keyboard_init()
keyboard_init: scope:[keyboard_init] from main
*((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff
*((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0
to:keyboard_init::@return
keyboard_init::@return: scope:[keyboard_init] from keyboard_init
return
to:@return
char keyboard_matrix_read(char rowid)
keyboard_matrix_read: scope:[keyboard_matrix_read] from keyboard_key_pressed
keyboard_matrix_read::rowid#1 = phi( keyboard_key_pressed/keyboard_matrix_read::rowid#0 )
*((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A) = keyboard_matrix_row_bitmask[keyboard_matrix_read::rowid#1]
keyboard_matrix_read::row_pressed_bits#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B)
keyboard_matrix_read::return#0 = keyboard_matrix_read::row_pressed_bits#0
to:keyboard_matrix_read::@return
keyboard_matrix_read::@return: scope:[keyboard_matrix_read] from keyboard_matrix_read
keyboard_matrix_read::return#3 = phi( keyboard_matrix_read/keyboard_matrix_read::return#0 )
keyboard_matrix_read::return#1 = keyboard_matrix_read::return#3
return
to:@return
char keyboard_key_pressed(char key)
keyboard_key_pressed: scope:[keyboard_key_pressed] from main::@3
keyboard_key_pressed::key#1 = phi( main::@3/keyboard_key_pressed::key#0 )
keyboard_key_pressed::colidx#0 = keyboard_key_pressed::key#1 & 7
keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#1 >> 3
keyboard_matrix_read::rowid#0 = keyboard_key_pressed::rowidx#0
call keyboard_matrix_read
keyboard_matrix_read::return#2 = keyboard_matrix_read::return#1
to:keyboard_key_pressed::@1
keyboard_key_pressed::@1: scope:[keyboard_key_pressed] from keyboard_key_pressed
keyboard_key_pressed::colidx#1 = phi( keyboard_key_pressed/keyboard_key_pressed::colidx#0 )
keyboard_matrix_read::return#4 = phi( keyboard_key_pressed/keyboard_matrix_read::return#2 )
keyboard_key_pressed::$2 = keyboard_matrix_read::return#4
keyboard_key_pressed::$3 = keyboard_key_pressed::$2 & keyboard_matrix_col_bitmask[keyboard_key_pressed::colidx#1]
keyboard_key_pressed::return#0 = keyboard_key_pressed::$3
to:keyboard_key_pressed::@return
keyboard_key_pressed::@return: scope:[keyboard_key_pressed] from keyboard_key_pressed::@1
keyboard_key_pressed::return#3 = phi( keyboard_key_pressed::@1/keyboard_key_pressed::return#0 )
keyboard_key_pressed::return#1 = keyboard_key_pressed::return#3
return
to:@return
void main()
main: scope:[main] from __start::@1
call keyboard_init
to:main::@6
main::@6: scope:[main] from main
to:main::@1
main::@1: scope:[main] from main::@4 main::@5 main::@6
if(true) goto main::@2
to:main::@return
main::@2: scope:[main] from main::@1 main::@2
main::$1 = *RASTER != $ff
if(main::$1) goto main::@2
to:main::@3
main::@3: scope:[main] from main::@2
keyboard_key_pressed::key#0 = KEY_SPACE
call keyboard_key_pressed
keyboard_key_pressed::return#2 = keyboard_key_pressed::return#1
to:main::@7
main::@7: scope:[main] from main::@3
keyboard_key_pressed::return#4 = phi( main::@3/keyboard_key_pressed::return#2 )
main::$2 = keyboard_key_pressed::return#4
main::$3 = main::$2 != 0
if(main::$3) goto main::@5
to:main::@4
main::@5: scope:[main] from main::@7
*BG_COLOR = GREEN
to:main::@1
main::@4: scope:[main] from main::@7
*BG_COLOR = BLUE
to:main::@1
main::@return: scope:[main] from main::@1
return
to:@return
void __start()
__start: scope:[__start] from
to:__start::__init1
__start::__init1: scope:[__start] from __start
to:__start::@1
__start::@1: scope:[__start] from __start::__init1
call main
to:__start::@2
__start::@2: scope:[__start] from __start::@1
to:__start::@return
__start::@return: scope:[__start] from __start::@2
return
to:@return
SYMBOL TABLE SSA
__constant char * const BG_COLOR = (char *)$d021
__constant const char BLUE = 6
__constant struct MOS6526_CIA * const CIA1 = (struct MOS6526_CIA *)$dc00
__constant const char GREEN = 5
__constant const char KEY_SPACE = $3c
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_A = 0
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR = 2
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR = 3
__constant char * const RASTER = (char *)$d012
void __start()
void keyboard_init()
char keyboard_key_pressed(char key)
char keyboard_key_pressed::$2
char keyboard_key_pressed::$3
char keyboard_key_pressed::colidx
char keyboard_key_pressed::colidx#0
char keyboard_key_pressed::colidx#1
char keyboard_key_pressed::key
char keyboard_key_pressed::key#0
char keyboard_key_pressed::key#1
char keyboard_key_pressed::return
char keyboard_key_pressed::return#0
char keyboard_key_pressed::return#1
char keyboard_key_pressed::return#2
char keyboard_key_pressed::return#3
char keyboard_key_pressed::return#4
char keyboard_key_pressed::rowidx
char keyboard_key_pressed::rowidx#0
__constant char keyboard_matrix_col_bitmask[8] = { 1, 2, 4, 8, $10, $20, $40, $80 }
char keyboard_matrix_read(char rowid)
char keyboard_matrix_read::return
char keyboard_matrix_read::return#0
char keyboard_matrix_read::return#1
char keyboard_matrix_read::return#2
char keyboard_matrix_read::return#3
char keyboard_matrix_read::return#4
char keyboard_matrix_read::row_pressed_bits
char keyboard_matrix_read::row_pressed_bits#0
char keyboard_matrix_read::rowid
char keyboard_matrix_read::rowid#0
char keyboard_matrix_read::rowid#1
__constant char keyboard_matrix_row_bitmask[8] = { $fe, $fd, $fb, $f7, $ef, $df, $bf, $7f }
void main()
bool main::$1
char main::$2
bool main::$3
Adding number conversion cast (unumber) $ff in *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff
Adding number conversion cast (unumber) 0 in *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0
Adding number conversion cast (unumber) 7 in keyboard_key_pressed::colidx#0 = keyboard_key_pressed::key#1 & 7
Adding number conversion cast (unumber) 3 in keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#1 >> 3
Adding number conversion cast (unumber) $ff in main::$1 = *RASTER != $ff
Adding number conversion cast (unumber) 0 in main::$3 = main::$2 != 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = (unumber)$ff
Inlining cast *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = (unumber)0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 53266
Simplifying constant pointer cast (char *) 53281
Simplifying constant pointer cast (struct MOS6526_CIA *) 56320
Simplifying constant integer cast $ff
Simplifying constant integer cast 0
Simplifying constant integer cast 7
Simplifying constant integer cast 3
Simplifying constant integer cast $ff
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $ff
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 7
Finalized unsigned number type (char) 3
Finalized unsigned number type (char) $ff
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias keyboard_matrix_read::return#0 = keyboard_matrix_read::row_pressed_bits#0 keyboard_matrix_read::return#3 keyboard_matrix_read::return#1
Alias keyboard_matrix_read::return#2 = keyboard_matrix_read::return#4
Alias keyboard_key_pressed::colidx#0 = keyboard_key_pressed::colidx#1
Alias keyboard_key_pressed::return#0 = keyboard_key_pressed::$3 keyboard_key_pressed::return#3 keyboard_key_pressed::return#1
Alias keyboard_key_pressed::return#2 = keyboard_key_pressed::return#4
Successful SSA optimization Pass2AliasElimination
Identical Phi Values keyboard_matrix_read::rowid#1 keyboard_matrix_read::rowid#0
Identical Phi Values keyboard_key_pressed::key#1 keyboard_key_pressed::key#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition main::$1 [19] if(*RASTER!=$ff) goto main::@2
Simple Condition main::$3 [25] if(main::$2!=0) goto main::@5
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant keyboard_key_pressed::key#0 = KEY_SPACE
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [17] if(true) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Simplifying expression containing zero (char *)CIA1 in [4] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A) = keyboard_matrix_row_bitmask[keyboard_matrix_read::rowid#0]
Successful SSA optimization PassNSimplifyExpressionWithZero
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Eliminating unused constant OFFSET_STRUCT_MOS6526_CIA_PORT_A
Successful SSA optimization PassNEliminateUnusedVars
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::__init1
Removing unused procedure block __start::@1
Removing unused procedure block __start::@2
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Constant right-side identified [6] keyboard_key_pressed::colidx#0 = keyboard_key_pressed::key#0 & 7
Constant right-side identified [7] keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#0 >> 3
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant keyboard_key_pressed::colidx#0 = keyboard_key_pressed::key#0&7
Constant keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#0>>3
Successful SSA optimization Pass2ConstantIdentification
Constant keyboard_matrix_read::rowid#0 = keyboard_key_pressed::rowidx#0
Successful SSA optimization Pass2ConstantIdentification
Constant inlined keyboard_key_pressed::key#0 = KEY_SPACE
Constant inlined keyboard_matrix_read::rowid#0 = keyboard_key_pressed::rowidx#0
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(keyboard_matrix_row_bitmask+keyboard_key_pressed::rowidx#0)
Consolidated array index constant in *(keyboard_matrix_col_bitmask+keyboard_key_pressed::colidx#0)
Successful SSA optimization Pass2ConstantAdditionElimination
Finalized unsigned number type (char) 8
Finalized unsigned number type (char) 8
Successful SSA optimization PassNFinalizeNumberTypeConversions
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@6
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@3
Adding NOP phi() at start of keyboard_key_pressed
CALL GRAPH
Calls in [main] to keyboard_init:1 keyboard_key_pressed:6
Calls in [keyboard_key_pressed] to keyboard_matrix_read:16
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block label main::@6
Culled Empty Block label main::@1
Renumbering block main::@2 to main::@1
Renumbering block main::@3 to main::@2
Renumbering block main::@4 to main::@3
Renumbering block main::@5 to main::@4
Renumbering block main::@7 to main::@5
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@2
Adding NOP phi() at start of keyboard_key_pressed
FINAL CONTROL FLOW GRAPH
void main()
main: scope:[main] from
[0] phi()
[1] call keyboard_init
to:main::@1
main::@1: scope:[main] from main main::@1 main::@3 main::@4
[2] if(*RASTER!=$ff) goto main::@1
to:main::@2
main::@2: scope:[main] from main::@1
[3] phi()
[4] call keyboard_key_pressed
[5] keyboard_key_pressed::return#2 = keyboard_key_pressed::return#0
to:main::@5
main::@5: scope:[main] from main::@2
[6] main::$2 = keyboard_key_pressed::return#2
[7] if(main::$2!=0) goto main::@4
to:main::@3
main::@3: scope:[main] from main::@5
[8] *BG_COLOR = BLUE
to:main::@1
main::@4: scope:[main] from main::@5
[9] *BG_COLOR = GREEN
to:main::@1
void keyboard_init()
keyboard_init: scope:[keyboard_init] from main
[10] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff
[11] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0
to:keyboard_init::@return
keyboard_init::@return: scope:[keyboard_init] from keyboard_init
[12] return
to:@return
char keyboard_key_pressed(char key)
keyboard_key_pressed: scope:[keyboard_key_pressed] from main::@2
[13] phi()
[14] call keyboard_matrix_read
[15] keyboard_matrix_read::return#2 = keyboard_matrix_read::return#0
to:keyboard_key_pressed::@1
keyboard_key_pressed::@1: scope:[keyboard_key_pressed] from keyboard_key_pressed
[16] keyboard_key_pressed::$2 = keyboard_matrix_read::return#2
[17] keyboard_key_pressed::return#0 = keyboard_key_pressed::$2 & *(keyboard_matrix_col_bitmask+keyboard_key_pressed::colidx#0)
to:keyboard_key_pressed::@return
keyboard_key_pressed::@return: scope:[keyboard_key_pressed] from keyboard_key_pressed::@1
[18] return
to:@return
char keyboard_matrix_read(char rowid)
keyboard_matrix_read: scope:[keyboard_matrix_read] from keyboard_key_pressed
[19] *((char *)CIA1) = *(keyboard_matrix_row_bitmask+keyboard_key_pressed::rowidx#0)
[20] keyboard_matrix_read::return#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B)
to:keyboard_matrix_read::@return
keyboard_matrix_read::@return: scope:[keyboard_matrix_read] from keyboard_matrix_read
[21] return
to:@return
VARIABLE REGISTER WEIGHTS
void keyboard_init()
char keyboard_key_pressed(char key)
char keyboard_key_pressed::$2 // 202.0
char keyboard_key_pressed::colidx
char keyboard_key_pressed::key
char keyboard_key_pressed::return
char keyboard_key_pressed::return#0 // 37.33333333333333
char keyboard_key_pressed::return#2 // 22.0
char keyboard_key_pressed::rowidx
char keyboard_matrix_read(char rowid)
char keyboard_matrix_read::return
char keyboard_matrix_read::return#0 // 367.33333333333337
char keyboard_matrix_read::return#2 // 202.0
char keyboard_matrix_read::row_pressed_bits
char keyboard_matrix_read::rowid
void main()
char main::$2 // 22.0
Initial phi equivalence classes
Added variable keyboard_key_pressed::return#2 to live range equivalence class [ keyboard_key_pressed::return#2 ]
Added variable main::$2 to live range equivalence class [ main::$2 ]
Added variable keyboard_matrix_read::return#2 to live range equivalence class [ keyboard_matrix_read::return#2 ]
Added variable keyboard_key_pressed::$2 to live range equivalence class [ keyboard_key_pressed::$2 ]
Added variable keyboard_key_pressed::return#0 to live range equivalence class [ keyboard_key_pressed::return#0 ]
Added variable keyboard_matrix_read::return#0 to live range equivalence class [ keyboard_matrix_read::return#0 ]
Complete equivalence classes
[ keyboard_key_pressed::return#2 ]
[ main::$2 ]
[ keyboard_matrix_read::return#2 ]
[ keyboard_key_pressed::$2 ]
[ keyboard_key_pressed::return#0 ]
[ keyboard_matrix_read::return#0 ]
Allocated zp[1]:2 [ keyboard_matrix_read::return#0 ]
Allocated zp[1]:3 [ keyboard_matrix_read::return#2 ]
Allocated zp[1]:4 [ keyboard_key_pressed::$2 ]
Allocated zp[1]:5 [ keyboard_key_pressed::return#0 ]
Allocated zp[1]:6 [ keyboard_key_pressed::return#2 ]
Allocated zp[1]:7 [ main::$2 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] if(*RASTER!=$ff) goto main::@1 [ ] ( [ ] { } ) always clobbers reg byte a
Statement [8] *BG_COLOR = BLUE [ ] ( [ ] { } ) always clobbers reg byte a
Statement [9] *BG_COLOR = GREEN [ ] ( [ ] { } ) always clobbers reg byte a
Statement [10] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff [ ] ( keyboard_init:1 [ ] { } ) always clobbers reg byte a
Statement [11] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0 [ ] ( keyboard_init:1 [ ] { } ) always clobbers reg byte a
Statement [19] *((char *)CIA1) = *(keyboard_matrix_row_bitmask+keyboard_key_pressed::rowidx#0) [ ] ( keyboard_key_pressed:4::keyboard_matrix_read:14 [ ] { { keyboard_key_pressed::return#0 = keyboard_key_pressed::return#2 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#2 } } ) always clobbers reg byte a
Statement [20] keyboard_matrix_read::return#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B) [ keyboard_matrix_read::return#0 ] ( keyboard_key_pressed:4::keyboard_matrix_read:14 [ keyboard_matrix_read::return#0 ] { { keyboard_key_pressed::return#0 = keyboard_key_pressed::return#2 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#2 } } ) always clobbers reg byte a
Potential registers zp[1]:6 [ keyboard_key_pressed::return#2 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:7 [ main::$2 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:3 [ keyboard_matrix_read::return#2 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:4 [ keyboard_key_pressed::$2 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:5 [ keyboard_key_pressed::return#0 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:2 [ keyboard_matrix_read::return#0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [keyboard_matrix_read] 367.33: zp[1]:2 [ keyboard_matrix_read::return#0 ] 202: zp[1]:3 [ keyboard_matrix_read::return#2 ]
Uplift Scope [keyboard_key_pressed] 202: zp[1]:4 [ keyboard_key_pressed::$2 ] 37.33: zp[1]:5 [ keyboard_key_pressed::return#0 ] 22: zp[1]:6 [ keyboard_key_pressed::return#2 ]
Uplift Scope [main] 22: zp[1]:7 [ main::$2 ]
Uplift Scope [keyboard_init]
Uplift Scope [MOS6526_CIA]
Uplift Scope [MOS6569_VICII]
Uplift Scope [MOS6581_SID]
Uplift Scope []
Uplifting [keyboard_matrix_read] best 1385 combination reg byte a [ keyboard_matrix_read::return#0 ] reg byte a [ keyboard_matrix_read::return#2 ]
Uplifting [keyboard_key_pressed] best 1286 combination reg byte a [ keyboard_key_pressed::$2 ] reg byte a [ keyboard_key_pressed::return#0 ] reg byte a [ keyboard_key_pressed::return#2 ]
Uplifting [main] best 1246 combination reg byte a [ main::$2 ]
Uplifting [keyboard_init] best 1246 combination
Uplifting [MOS6526_CIA] best 1246 combination
Uplifting [MOS6569_VICII] best 1246 combination
Uplifting [MOS6581_SID] best 1246 combination
Uplifting [] best 1246 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test keyboard input - test the space bar
/// @file
/// Simple Keyboard Input Library
///
/// C64 Keyboard Matrix Reference - from http://codebase64.org/doku.php?id=base:reading_the_keyboard
/// Keyboard Codes are %00rrrccc, where rrr is the row ID (0-7) and ccc is the column ID (0-7)
/// +----+----------------------+-------------------------------------------------------------------------------------------------------+
/// | | Write | Read $dc01 (C64 screen code in parenthesis): |
/// |row:| $dc00: row bits +------------+------------+------------+------------+------------+------------+------------+------------+
/// | | | BIT 7 | BIT 6 | BIT 5 | BIT 4 | BIT 3 | BIT 2 | BIT 1 | BIT 0 |
/// +----+----------------------+------------+------------+------------+------------+------------+------------+------------+------------+
/// |0. | #%11111110 (254/$fe) | DOWN ($ )| F5 ($ )| F3 ($ )| F1 ($ )| F7 ($ )| RIGHT ($ )| RETURN($ )|DELETE ($ )|
/// |1. | #%11111101 (253/$fd) |LEFT-SH($ )| e ($05)| s ($13)| z ($1a)| 4 ($34)| a ($01)| w ($17)| 3 ($33)|
/// |2. | #%11111011 (251/$fb) | x ($18)| t ($14)| f ($06)| c ($03)| 6 ($36)| d ($04)| r ($12)| 5 ($35)|
/// |3. | #%11110111 (247/$f7) | v ($16)| u ($15)| h ($08)| b ($02)| 8 ($38)| g ($07)| y ($19)| 7 ($37)|
/// |4. | #%11101111 (239/$ef) | n ($0e)| o ($0f)| k ($0b)| m ($0d)| 0 ($30)| j ($0a)| i ($09)| 9 ($39)|
/// |5. | #%11011111 (223/$df) | , ($2c)| @ ($00)| : ($3a)| . ($2e)| - ($2d)| l ($0c)| p ($10)| + ($2b)|
/// |6. | #%10111111 (191/$bf) | / ($2f)| ^ ($1e)| = ($3d)|RGHT-SH($ )| HOME ($ )| ; ($3b)| * ($2a)| £ ($1c)|
/// |7. | #%01111111 (127/$7f) | STOP ($ )| q ($11)|COMMODR($ )| SPACE ($20)| 2 ($32)|CONTROL($ )| <- ($1f)| 1 ($31)|
/// +----+----------------------+------------+------------+------------+------------+------------+------------+------------+------------+
// Upstart
// Commodore 64 PRG executable file
.file [name="test-keyboard-space.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 KEY_SPACE = $3c
.const GREEN = 5
.const BLUE = 6
.const OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR = 2
.const OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR = 3
.const OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
/// $D012 RASTER Raster counter
.label RASTER = $d012
/// $D021 Background Color 0
.label BG_COLOR = $d021
/// The CIA#1: keyboard matrix, joystick #1/#2
.label CIA1 = $dc00
.segment Code
// main
main: {
// [1] call keyboard_init
jsr keyboard_init
jmp __b1
// main::@1
__b1:
// [2] if(*RASTER!=$ff) goto main::@1 -- _deref_pbuc1_neq_vbuc2_then_la1
lda #$ff
cmp RASTER
bne __b1
// [3] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
__b2_from___b1:
jmp __b2
// main::@2
__b2:
// [4] call keyboard_key_pressed
// [13] phi from main::@2 to keyboard_key_pressed [phi:main::@2->keyboard_key_pressed]
keyboard_key_pressed_from___b2:
jsr keyboard_key_pressed
// [5] keyboard_key_pressed::return#2 = keyboard_key_pressed::return#0
jmp __b5
// main::@5
__b5:
// [6] main::$2 = keyboard_key_pressed::return#2
// [7] if(main::$2!=0) goto main::@4 -- vbuaa_neq_0_then_la1
cmp #0
bne __b4
jmp __b3
// main::@3
__b3:
// [8] *BG_COLOR = BLUE -- _deref_pbuc1=vbuc2
lda #BLUE
sta BG_COLOR
jmp __b1
// main::@4
__b4:
// [9] *BG_COLOR = GREEN -- _deref_pbuc1=vbuc2
lda #GREEN
sta BG_COLOR
jmp __b1
}
// keyboard_init
// Initialize keyboard reading by setting CIA#1 Data Direction Registers
keyboard_init: {
// [10] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff -- _deref_pbuc1=vbuc2
// Keyboard Matrix Columns Write Mode
lda #$ff
sta CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR
// [11] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0 -- _deref_pbuc1=vbuc2
// Keyboard Matrix Columns Read Mode
lda #0
sta CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR
jmp __breturn
// keyboard_init::@return
__breturn:
// [12] return
rts
}
// keyboard_key_pressed
// Determines whether a specific key is currently pressed by accessing the matrix directly
// The key is a keyboard code defined from the keyboard matrix by %00rrrccc, where rrr is the row ID (0-7) and ccc is the column ID (0-7)
// All keys exist as as KEY_XXX constants.
// Returns zero if the key is not pressed and a non-zero value if the key is currently pressed
// __register(A) char keyboard_key_pressed(char key)
keyboard_key_pressed: {
.const colidx = KEY_SPACE&7
.label rowidx = KEY_SPACE>>3
// [14] call keyboard_matrix_read
jsr keyboard_matrix_read
// [15] keyboard_matrix_read::return#2 = keyboard_matrix_read::return#0
jmp __b1
// keyboard_key_pressed::@1
__b1:
// [16] keyboard_key_pressed::$2 = keyboard_matrix_read::return#2
// [17] keyboard_key_pressed::return#0 = keyboard_key_pressed::$2 & *(keyboard_matrix_col_bitmask+keyboard_key_pressed::colidx#0) -- vbuaa=vbuaa_band__deref_pbuc1
and keyboard_matrix_col_bitmask+colidx
jmp __breturn
// keyboard_key_pressed::@return
__breturn:
// [18] return
rts
}
// keyboard_matrix_read
// Read a single row of the keyboard matrix
// The row ID (0-7) of the keyboard matrix row to read. See the C64 key matrix for row IDs.
// Returns the keys pressed on the row as bits according to the C64 key matrix.
// Notice: If the C64 normal interrupt is still running it will occasionally interrupt right between the read & write
// leading to erroneous readings. You must disable the normal interrupt or sei/cli around calls to the keyboard matrix reader.
// __register(A) char keyboard_matrix_read(char rowid)
keyboard_matrix_read: {
// [19] *((char *)CIA1) = *(keyboard_matrix_row_bitmask+keyboard_key_pressed::rowidx#0) -- _deref_pbuc1=_deref_pbuc2
lda keyboard_matrix_row_bitmask+keyboard_key_pressed.rowidx
sta CIA1
// [20] keyboard_matrix_read::return#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B) -- vbuaa=_bnot__deref_pbuc1
lda CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B
eor #$ff
jmp __breturn
// keyboard_matrix_read::@return
__breturn:
// [21] return
rts
}
// File Data
.segment Data
// Keyboard row bitmask as expected by CIA#1 Port A when reading a specific keyboard matrix row (rows are numbered 0-7)
keyboard_matrix_row_bitmask: .byte $fe, $fd, $fb, $f7, $ef, $df, $bf, $7f
// Keyboard matrix column bitmasks for a specific keybooard matrix column when reading the keyboard. (columns are numbered 0-7)
keyboard_matrix_col_bitmask: .byte 1, 2, 4, 8, $10, $20, $40, $80
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b5
Removing instruction jmp __b3
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b2_from___b1:
Removing instruction keyboard_key_pressed_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b2:
Removing instruction __b5:
Removing instruction __b3:
Removing instruction __breturn:
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
__constant char * const BG_COLOR = (char *) 53281
__constant const char BLUE = 6
__constant struct MOS6526_CIA * const CIA1 = (struct MOS6526_CIA *) 56320
__constant const char GREEN = 5
__constant const char KEY_SPACE = $3c
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR = 2
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR = 3
__constant char * const RASTER = (char *) 53266
void keyboard_init()
char keyboard_key_pressed(char key)
char keyboard_key_pressed::$2 // reg byte a 202.0
char keyboard_key_pressed::colidx
__constant char keyboard_key_pressed::colidx#0 = KEY_SPACE&7 // colidx
char keyboard_key_pressed::key
char keyboard_key_pressed::return
char keyboard_key_pressed::return#0 // reg byte a 37.33333333333333
char keyboard_key_pressed::return#2 // reg byte a 22.0
char keyboard_key_pressed::rowidx
__constant char keyboard_key_pressed::rowidx#0 = KEY_SPACE>>3 // rowidx
__constant char keyboard_matrix_col_bitmask[8] = { 1, 2, 4, 8, $10, $20, $40, $80 }
char keyboard_matrix_read(char rowid)
char keyboard_matrix_read::return
char keyboard_matrix_read::return#0 // reg byte a 367.33333333333337
char keyboard_matrix_read::return#2 // reg byte a 202.0
char keyboard_matrix_read::row_pressed_bits
char keyboard_matrix_read::rowid
__constant char keyboard_matrix_row_bitmask[8] = { $fe, $fd, $fb, $f7, $ef, $df, $bf, $7f }
void main()
char main::$2 // reg byte a 22.0
reg byte a [ keyboard_key_pressed::return#2 ]
reg byte a [ main::$2 ]
reg byte a [ keyboard_matrix_read::return#2 ]
reg byte a [ keyboard_key_pressed::$2 ]
reg byte a [ keyboard_key_pressed::return#0 ]
reg byte a [ keyboard_matrix_read::return#0 ]
FINAL ASSEMBLER
Score: 1141
// File Comments
// Test keyboard input - test the space bar
/// @file
/// Simple Keyboard Input Library
///
/// C64 Keyboard Matrix Reference - from http://codebase64.org/doku.php?id=base:reading_the_keyboard
/// Keyboard Codes are %00rrrccc, where rrr is the row ID (0-7) and ccc is the column ID (0-7)
/// +----+----------------------+-------------------------------------------------------------------------------------------------------+
/// | | Write | Read $dc01 (C64 screen code in parenthesis): |
/// |row:| $dc00: row bits +------------+------------+------------+------------+------------+------------+------------+------------+
/// | | | BIT 7 | BIT 6 | BIT 5 | BIT 4 | BIT 3 | BIT 2 | BIT 1 | BIT 0 |
/// +----+----------------------+------------+------------+------------+------------+------------+------------+------------+------------+
/// |0. | #%11111110 (254/$fe) | DOWN ($ )| F5 ($ )| F3 ($ )| F1 ($ )| F7 ($ )| RIGHT ($ )| RETURN($ )|DELETE ($ )|
/// |1. | #%11111101 (253/$fd) |LEFT-SH($ )| e ($05)| s ($13)| z ($1a)| 4 ($34)| a ($01)| w ($17)| 3 ($33)|
/// |2. | #%11111011 (251/$fb) | x ($18)| t ($14)| f ($06)| c ($03)| 6 ($36)| d ($04)| r ($12)| 5 ($35)|
/// |3. | #%11110111 (247/$f7) | v ($16)| u ($15)| h ($08)| b ($02)| 8 ($38)| g ($07)| y ($19)| 7 ($37)|
/// |4. | #%11101111 (239/$ef) | n ($0e)| o ($0f)| k ($0b)| m ($0d)| 0 ($30)| j ($0a)| i ($09)| 9 ($39)|
/// |5. | #%11011111 (223/$df) | , ($2c)| @ ($00)| : ($3a)| . ($2e)| - ($2d)| l ($0c)| p ($10)| + ($2b)|
/// |6. | #%10111111 (191/$bf) | / ($2f)| ^ ($1e)| = ($3d)|RGHT-SH($ )| HOME ($ )| ; ($3b)| * ($2a)| £ ($1c)|
/// |7. | #%01111111 (127/$7f) | STOP ($ )| q ($11)|COMMODR($ )| SPACE ($20)| 2 ($32)|CONTROL($ )| <- ($1f)| 1 ($31)|
/// +----+----------------------+------------+------------+------------+------------+------------+------------+------------+------------+
// Upstart
// Commodore 64 PRG executable file
.file [name="test-keyboard-space.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 KEY_SPACE = $3c
.const GREEN = 5
.const BLUE = 6
.const OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR = 2
.const OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR = 3
.const OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
/// $D012 RASTER Raster counter
.label RASTER = $d012
/// $D021 Background Color 0
.label BG_COLOR = $d021
/// The CIA#1: keyboard matrix, joystick #1/#2
.label CIA1 = $dc00
.segment Code
// main
main: {
// keyboard_init()
// [1] call keyboard_init
jsr keyboard_init
// main::@1
__b1:
// while (*RASTER!=$ff)
// [2] if(*RASTER!=$ff) goto main::@1 -- _deref_pbuc1_neq_vbuc2_then_la1
lda #$ff
cmp RASTER
bne __b1
// [3] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
// main::@2
// keyboard_key_pressed(KEY_SPACE)
// [4] call keyboard_key_pressed
// [13] phi from main::@2 to keyboard_key_pressed [phi:main::@2->keyboard_key_pressed]
jsr keyboard_key_pressed
// keyboard_key_pressed(KEY_SPACE)
// [5] keyboard_key_pressed::return#2 = keyboard_key_pressed::return#0
// main::@5
// [6] main::$2 = keyboard_key_pressed::return#2
// if(keyboard_key_pressed(KEY_SPACE)!=0)
// [7] if(main::$2!=0) goto main::@4 -- vbuaa_neq_0_then_la1
cmp #0
bne __b4
// main::@3
// *BG_COLOR = BLUE
// [8] *BG_COLOR = BLUE -- _deref_pbuc1=vbuc2
lda #BLUE
sta BG_COLOR
jmp __b1
// main::@4
__b4:
// *BG_COLOR = GREEN
// [9] *BG_COLOR = GREEN -- _deref_pbuc1=vbuc2
lda #GREEN
sta BG_COLOR
jmp __b1
}
// keyboard_init
// Initialize keyboard reading by setting CIA#1 Data Direction Registers
keyboard_init: {
// CIA1->PORT_A_DDR = 0xff
// [10] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff -- _deref_pbuc1=vbuc2
// Keyboard Matrix Columns Write Mode
lda #$ff
sta CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR
// CIA1->PORT_B_DDR = 0x00
// [11] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0 -- _deref_pbuc1=vbuc2
// Keyboard Matrix Columns Read Mode
lda #0
sta CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR
// keyboard_init::@return
// }
// [12] return
rts
}
// keyboard_key_pressed
// Determines whether a specific key is currently pressed by accessing the matrix directly
// The key is a keyboard code defined from the keyboard matrix by %00rrrccc, where rrr is the row ID (0-7) and ccc is the column ID (0-7)
// All keys exist as as KEY_XXX constants.
// Returns zero if the key is not pressed and a non-zero value if the key is currently pressed
// __register(A) char keyboard_key_pressed(char key)
keyboard_key_pressed: {
.const colidx = KEY_SPACE&7
.label rowidx = KEY_SPACE>>3
// keyboard_matrix_read(rowidx)
// [14] call keyboard_matrix_read
jsr keyboard_matrix_read
// [15] keyboard_matrix_read::return#2 = keyboard_matrix_read::return#0
// keyboard_key_pressed::@1
// [16] keyboard_key_pressed::$2 = keyboard_matrix_read::return#2
// keyboard_matrix_read(rowidx) & keyboard_matrix_col_bitmask[colidx]
// [17] keyboard_key_pressed::return#0 = keyboard_key_pressed::$2 & *(keyboard_matrix_col_bitmask+keyboard_key_pressed::colidx#0) -- vbuaa=vbuaa_band__deref_pbuc1
and keyboard_matrix_col_bitmask+colidx
// keyboard_key_pressed::@return
// }
// [18] return
rts
}
// keyboard_matrix_read
// Read a single row of the keyboard matrix
// The row ID (0-7) of the keyboard matrix row to read. See the C64 key matrix for row IDs.
// Returns the keys pressed on the row as bits according to the C64 key matrix.
// Notice: If the C64 normal interrupt is still running it will occasionally interrupt right between the read & write
// leading to erroneous readings. You must disable the normal interrupt or sei/cli around calls to the keyboard matrix reader.
// __register(A) char keyboard_matrix_read(char rowid)
keyboard_matrix_read: {
// CIA1->PORT_A = keyboard_matrix_row_bitmask[rowid]
// [19] *((char *)CIA1) = *(keyboard_matrix_row_bitmask+keyboard_key_pressed::rowidx#0) -- _deref_pbuc1=_deref_pbuc2
lda keyboard_matrix_row_bitmask+keyboard_key_pressed.rowidx
sta CIA1
// char row_pressed_bits = ~CIA1->PORT_B
// [20] keyboard_matrix_read::return#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B) -- vbuaa=_bnot__deref_pbuc1
lda CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B
eor #$ff
// keyboard_matrix_read::@return
// }
// [21] return
rts
}
// File Data
.segment Data
// Keyboard row bitmask as expected by CIA#1 Port A when reading a specific keyboard matrix row (rows are numbered 0-7)
keyboard_matrix_row_bitmask: .byte $fe, $fd, $fb, $f7, $ef, $df, $bf, $7f
// Keyboard matrix column bitmasks for a specific keybooard matrix column when reading the keyboard. (columns are numbered 0-7)
keyboard_matrix_col_bitmask: .byte 1, 2, 4, 8, $10, $20, $40, $80