\ 1802cycle

needs 1802regs
needs 1802memory
needs 1802exceptions

decimal

\ This gets called once per machine
\ cycle. This provides a hook that 
\ we can sychronize virtual 1861 on.
variable (cycle)
' noop (cycle) !
: cycle  ( -- )   (cycle) @ execute ;
inline

variable not-idle
0 not-idle !

: not-idle?  ( -- flag )  not-idle @ ;
inline

: idle-cpu  ( -- )   0 not-idle ! ;

: reset-idle  ( -- )    -1 not-idle ! ; 

: fetch-byte  ( -- byte )
\    P @      R @        \ get prog ctr
\    byte@               \ fetch the byte
\   1   P @    R +!  ;  \ incr prog ctr

    P @  R                      ( adr )
    dup   @ byte@     ( adr byte )
    1                                ( adr byte 1 )
    rot +! ;  inline

\ : do-dma-in  ( -- ) 
\    cycle  ;

\ (dma-out) is a vector that may 
\ later be filled in by the 1861 
\ display code.
variable (dma-out)
' drop (dma-out) !

: do-dma-out  ( -- )
    0 R @  byte@
    (dma-out) @ execute
    1  0 R +!
    cycle ;
inline

: do-interrupt  ( -- )
    X @  4 lshift   P @ or    T !
    2 X !   1 P ! 
    0 IE !
    ack-interrupt
    cycle ;

