include "inc/cmdsys.plh"
include "inc/args.plh"
//
// ZIP Chip control
//
var arg, status, slots, clock, state, cache

byte _unlock[]
byte = $A9, $5A      // LDA #$5A
byte = $8D, $5A, $C0 // STA $C05A
byte = $8D, $5A, $C0 // STA $C05A
byte = $8D, $5A, $C0 // STA $C05A
byte = $8D, $5A, $C0 // STA $C05A
byte = $60           // RTS

def unlock#0
  (@_unlock)()#0 // Unlock regs (has to be machine code)
end
def lock#0
  ^$C05A = $A5 // Lock regs
end

arg = argNext(argFirst)
if ^arg
  when toupper(arg->[1])
    is 'S' // Slow to 1 MHz
      unlock
      ^$C05A = $00
      lock
      puts("Slow speed\n")
      break
    is 'F' // Enable acceleration
      unlock
      ^$C05B = $FF
      lock
      puts("Fast speed\n")
      break
  wend
fin
unlock
status = ^$C05B
slots  = ^$C05C
clock  = ^$C05D
state  = ^$C05E
cache  = ^$C05F
lock
^$C05F // AN3 off
puts("Status: $"); puth(status); putln
puts("Slots:  $"); puth(slots); putln
puts("Clock:  $"); puth(clock); putln
puts("State:  $"); puth(state); putln
puts("Cache:  $"); puth(cache); putln
done
