Lua 5.3 didn't need an x86 emulator. But now, it has one regardless.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

timer.lua 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. local function get_timer_ticks()
  2. return RAM:r32(0x46c)
  3. end
  4. local function set_timer_ticks(v)
  5. return RAM:w32(0x46c, v)
  6. end
  7. local timer_last_midnight = 0
  8. local timer_midnight = 24*60*60*20
  9. cpu_register_interrupt_handler(0x08, function(ax,ah,al)
  10. set_timer_ticks(get_timer_ticks()+1)
  11. cpu_emit_interrupt(0x1C,false)
  12. return true
  13. end)
  14. cpu_register_interrupt_handler(0x1C, function(ax,ah,al)
  15. -- dummy - override by user
  16. return true
  17. end)
  18. cpu_register_interrupt_handler(0x1A, function(ax,ah,al)
  19. if (ah == 0x00) then
  20. local midnight = 0
  21. local timer_ticks = get_timer_ticks()
  22. while (timer_ticks - timer_midnight) >= timer_last_midnight do
  23. midnight = 1
  24. timer_last_midnight = timer_last_midnight + timer_midnight
  25. end
  26. CPU["regs"][1] = (CPU["regs"][1] & 0xFF00) | midnight
  27. CPU["regs"][2] = (timer_ticks >> 16) & 0xFFFF
  28. CPU["regs"][3] = (timer_ticks & 0xFFFF)
  29. emu_debug(0, "time: get clock time\n")
  30. return true
  31. elseif (ah == 0x01) then
  32. local timer_ticks = CPU["regs"][3] | (CPU["regs"][2] << 16)
  33. set_timer_ticks(timer_ticks)
  34. -- reset midnight flag
  35. timer_last_midnight = 0
  36. while (timer_ticks - timer_midnight) >= timer_last_midnight do
  37. timer_last_midnight = timer_last_midnight + timer_midnight
  38. end
  39. emu_debug(0, "time: set clock time\n")
  40. return true
  41. elseif (ah == 0x03) or (ah == 0x05) then
  42. -- TODO
  43. emu_debug(0, "time: set RTC (dummy)\n")
  44. return true
  45. elseif (ah == 0x02) or (ah == 0x04) then
  46. -- TODO
  47. cpu_clear_flag(0) -- clear carry
  48. CPU["regs"][2] = 0x0000
  49. CPU["regs"][3] = 0x0000
  50. emu_debug(0, "time: get RTC (dummy)\n")
  51. return true
  52. else
  53. cpu_set_flag(0)
  54. end
  55. end)
  56. set_timer_ticks(0)