handle HALT instruction

This commit is contained in:
Colby 2016-07-24 11:02:07 +10:00
parent faf994fb89
commit a10a2794d1
2 changed files with 12 additions and 17 deletions

View file

@ -74,30 +74,24 @@ module Waterfoul
def step
reset_tick
serve_interrupt if @ime
check_halt if @halt
if halted?
@m = 4
else
instruction_byte = fetch_instruction
perform_instruction instruction_byte
end
@timer.tick @m
end
def check_halt
@halt = false if @pre_halt_interrupt != $mmu.read_byte(0xFF0F)
end
def halted?
@halt == true
end
def halt_step
if @halt_cycles > 0
@halt_cycles -= 2
if @halt_cycles <= 0
@halt_cycles = 0
@halt = false
end
end
if @halt && Interrupt.pending_interupts != Interrupt::INTERRUPT_NONE && @halt_cycles == 0
@halt_cycles = HALT_CYCLES
end
@m = 2
end
# Execute the instruction and
def perform_instruction(instruction)
operation = OPCODE[instruction]

View file

@ -19,6 +19,7 @@ module Waterfoul
# Halt CPU & LCD display until button pressed.
# @flags - - - -
def halt
@pre_halt_interrupt = $mmu.read_byte(0xFF0F)
@halt = true
end