Skip to content

Commit

Permalink
improve dumpvars output for zeropage variables
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Feb 3, 2025
1 parent 06ca68a commit a940dc7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
48 changes: 25 additions & 23 deletions codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -272,42 +272,44 @@ class AsmGen6502Internal (

private fun dumpVariables() {
println("---- VARIABLES DUMP ----")
if(allocator.zeropageVars.isNotEmpty()) {
println("ZeroPage:")
val allvars = allocator.zeropageVars.map { (name, alloc) -> Triple(name, alloc.address, alloc.dt) } + symbolTable.allMemMappedVariables.map { Triple(it.name, it.address, it.dt) }
allvars
.filter { it.second in 0u..255u }
.distinct()
.sortedWith( compareBy( {it.second}, {it.first} ))
.forEach {
println(" $${it.second.toString(16).padStart(2, '0')}\t${it.third}\t${it.first}")
}
}
if(symbolTable.allVariables.isNotEmpty()) {
println("Static variables (not in ZeroPage):")
symbolTable.allVariables
.filterNot { allocator.isZpVar(it.scopedName) }
.sortedBy { it.scopedName }.forEach {
println(" ${it.dt}\t${it.scopedName}\t")
}
}
if(allocator.globalFloatConsts.isNotEmpty()) {
println("Floats:")
allocator.globalFloatConsts.forEach { (value, name) ->
println(" $name = $value")
}
}
if(symbolTable.allMemorySlabs.isNotEmpty()) {
println("Memory slabs:")
symbolTable.allMemorySlabs.sortedBy { it.name }.forEach { slab ->
println(" ${slab.name} ${slab.size} align ${slab.align}")
}
}
if(symbolTable.allMemMappedVariables.isNotEmpty()) {
println("Memory mapped:")
symbolTable.allMemMappedVariables
.sortedWith( compareBy( {it.address}, {it.scopedName} ))
.forEach { mvar ->
println(" ${'$'}${mvar.address.toString(16).padStart(4, '0')}\t${mvar.dt}\t${mvar.scopedName}")
}
}
if(allocator.zeropageVars.isNotEmpty()) {
println("ZeroPage:")
allocator.zeropageVars
.asSequence()
.sortedWith( compareBy( {it.value.address}, {it.key} ))
.forEach { (name, alloc) ->
println(" ${'$'}${alloc.address.toString(16).padStart(2, '0')}\t${alloc.dt}\t$name")
println(" $${mvar.address.toString(16).padStart(4, '0')}\t${mvar.dt}\t${mvar.scopedName}")
}
}
if(symbolTable.allVariables.isNotEmpty()) {
println("Static variables (not in ZeroPage):")
symbolTable.allVariables
.filterNot { allocator.isZpVar(it.scopedName) }
.sortedBy { it.scopedName }.forEach {
println(" ${it.dt}\t${it.scopedName}\t")
}
if(symbolTable.allMemorySlabs.isNotEmpty()) {
println("Memory slabs:")
symbolTable.allMemorySlabs.sortedBy { it.name }.forEach { slab ->
println(" ${slab.name} ${slab.size} align ${slab.align}")
}
}
println("---- VARIABLES DUMP END ----")
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/res/prog8lib/cx16/psg.p8
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ psg {
sub pulse_width(ubyte voice_num, ubyte pw) {
; -- Modifies the pulse width of this voice (when waveform=PULSE)
; voice_num = 0-15, pw = 0-63 where 0=narrow, 63=50%cycle so square wave.
; When Waveform is TRIANGLE or SAWTOOTH, it sets the XOR mode parameter instead.
; (see the Vera reference manual for the exact description of this)
cx16.vpoke_mask(1, $f9c3 + voice_num * 4, %11000000, pw)
}

Expand Down
3 changes: 3 additions & 0 deletions examples/cx16/fileselector/fselector.p8
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
; Returns the name of the selected file. If it is a directory instead, the name will start and end with a slash '/'.
; Works in PETSCII mode and in ISO mode as well (no case folding in ISO mode!)

; ZERO PAGE LOCATIONS USED: R0-R4 ($02-$0b), $7a-$7f (can be checked with -dumpvars)


; TODO joystick control? mouse control?
; TODO keyboard typing; jump to the first entry that starts with that character? (but 'q' for quit stops working then, plus scrolling with pageup/down is already pretty fast)

Expand Down

0 comments on commit a940dc7

Please sign in to comment.