the real 0 tstate zero point off the interrupt

edited July 2018 in Hardware
Hi,
I am looking for some precision info about the exact starting point of an IM2 interrupt
https://www.worldofspectrum.org/faq/reference/z80reference.htm#Interrupts
On the 48K Spectrum, the ULA holds the /INT pin low for precisely 32 T-states. This pin is sampled during the last M-cycle of every instruction apart from repeated IX and IY prefixes (DD and FD). If the pin goes high again before it is sampled, no interrupt will occur. The /INT pin must be held low for at least 23 T-states, as some IX and IY instructions take 23 T-states. If the interrupt routine starts EI/NOP, this can cause a double interrupt, as the /INT pin will be sampled 19 (for IM 2)+4+4=27 T-states after being first sampled, when it may still be low.

Should i read the part "sampled 19 (for IM 2)" as the interrupt itselves takes 19state ?
then the entry in this init takes 62+19 tstate which will influence the tstate off the 'out' command:
;tt=0  starts with 19t prehandeling delay (were to put it???)
im_main push	af		;11t save reg $XyXy = 0x8585 =ad33924
	push	bc		;11t
	push	de		;11t
	push	hl		;11t
	ld	a,2		; 7t set colour
	out	(254),a		;11t set border a

tm_intrupt_init equ 19

tm_main_1       equ tm_intrupt_init +11 +11 +11 +11 +7 +11  ;..62t +19t
tmu_main_1      equ tm_main_1 / 8
tmumn1          equ tm_main_1 - ( tmu_main_1 * 8 )
;@t=xxxxx 62/8=	y.75  >> + 0ut


BTW, ODD ports are NOT contended ? then pageswitching and AY registers are UNcontended in use...
; use of OUT lsb %xxxxxxx0 is always contended
; contended = Screen delay only
; fetching interrupt (initiate ITSELF at 0 tstate) takes 19t-state to accomplish at first(*),
;    48k/128k+2	Cycle  +2A/+3

;	6	14335	7       x/8=y.875 j.needle
;@16384 5	14336	6	x/8=y.00  64x224 null start !!
;	4	14337	5	x/8=y.125
;	3	14338	4	x/8=y.25
;      *2	14339	3
;      *1	14340	2	x/8=y.50
;      *0	14341	1	x/8=y.625  <<<
;      *0	14342	0	x/8=y.75   <<<
;	6	14343	7
;	5	14344	6	x/8=y.00
;	4	14345	5
;	3	14346	4
;	2	14347	3
;	1	14348	2
;	0	14349	1
;	0	14350	0	x/8=y.75
;	6	14351	7
;	5	14352	6	x/8=y.00
;	4	14353	5
;	3	14354	4
;	2	14355	3
;	1	14356	2
;	0	14357	1
;	0	14358	0	     x/8=y.75
;	6	14359	7
;	5	14360	6	     x/8=y.00
;	4	14361	5            x/8=y.125 j.needle
;	3	14362	4	     x/8=y.25
;	2	14363	3	     x/8=y.375
;	1@16384	14364	2	     x/8=y.5   63×228 halve start !!
;	0      *14365	1	     x/8=y.625
;	0      *14366	0_NO_delay   x/8=y.75
;	6      *14367	7	     x/8=y.875
;5<0+	5      *14368	6	  .0 >+6>6       <| check
;5<1+	4       14369	5         .1 >+5>6        | apparent
;5<2+	3       14370	4	  .2 >+4>6        | number
;5<3+	2       14371	3	  .3 >+3>6        | cycle
;6<5+	1       14372	2	  .5 >+2>7        | in 
;6<6+	0       14373	1	  .6 >+1>7        | Cycle
;6<7	0       14374	0_NOdelay .7 >+0>7        | +2A/+3
;14<	6       14375	7	  .8 >+7>15 >>6  >| ONLY

Post edited by Crisis on
my old website http://home.hccnet.nl/c.born/ has changed to http://www.cborn.nl/zxfiles/ so just click it and select a file

Comments

  • On the +2A/+3, ports are non-contended. On the 128K/48K, port contention will depend on the high byte of the address (just like with RAM access) and whether the lowest bit is set: http://www.worldofspectrum.org/faq/reference/48kreference.htm#IOContention

    Note that on the 128K (but not on the +2A/+3), contention will also be affected by which bank (contended or non-contended) is paged in at $c000–$ffff.

    Additionally, avoid setting the I register to point to contended memory, including paged-in banks, or you’ll trigger the ULA snow effect on the 48K/128K. Interrupt access will also be slowed down.
    Every man should plant a tree, build a house, and write a ZX Spectrum game.

    Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
    and zasm Z80 Assembler syntax highlighter.
    Member of the team that discovered, analyzed, and detailed the floating bus behavior on the ZX Spectrum +2A/+3.

    A few Spectrum game fixes.
  • edited July 2018
    On the +2A/+3, ports are non-contended. On the 128K/48K, port contention will depend on the high byte of the address (just like with RAM access) and whether the lowest bit is set: http://www.worldofspectrum.org/faq/reference/48kreference.htm#IOContention

    ok, i have to be (much) more precise:
    in UNconteded RAM the even adreses are Contended.
    in Contended RAm alll adresses are contended...
    new abrivation off the rule:
    in EVEN ram EVEN ports are contended
    In ODD ram ALL ports are contended


    Do you know if the 19t for IM2 is correct?
    Post edited by Crisis on
    my old website http://home.hccnet.nl/c.born/ has changed to http://www.cborn.nl/zxfiles/ so just click it and select a file
  • orgmain	org	$8585		; 0x8585 =ad33924
    free1	equ	orgmain-frcode1
    
    ;tt=0  starts with 19t prehandeling delay (were to put it???)
    tm_intrupt_init equ 19
    im_main         push af         ;11t save reg $XyXy = 0x8585 =ad33924
                    push bc         ;11t
                    push de         ;11t
                    push hl         ;11t
                    ld a,2          ; 7t set colour
                    out (254),a     ;11t set border a
    ; 254 = 'even port'
    tm_main_1       equ tm_intrupt_init +11 +11 +11 +11 +7 +11  ;..62t +19t
    tmu_main_1      equ tm_main_1 / 8
    tm_out1          equ tm_main_1 - ( tmu_main_1 * 8 )
    tm_out_1         equ 8-2-tm_out1   ; on 'tm_out1=7' result is -1
    ;@t=xxxxx/8 >> 81/8= y.125  >> + 5t
    

    the OUT instruction seems to have to wait for 5t-ula-state before execution in this case

    my old website http://home.hccnet.nl/c.born/ has changed to http://www.cborn.nl/zxfiles/ so just click it and select a file
  • hi
    out (254),a ;11t set border a
    its 4+3+4 tstate
    the value off A_reg is used as HIGH byte meaning it will be checked on bit 7 by the ULA (simply said)
    So if i SET bit 7 for A_reg anyway ULA wont delay that part off the out instruction.
    bit 7,6 and 5 are not used by ZX ROM as instruction and probably can be ignored....usualy...
    High byte   |         | 
        in 40 - 7F? | Low bit | Contention pattern  
        ------------+---------+-------------------
             No     |  Reset  | N:1, C:3
             No     |   Set   | N:4
            Yes     |  Reset  | C:1, C:3
            Yes     |   Set   | C:1, C:1, C:1, C:1
    

    and its definitly 19 tstate to INIT an IM2, so now i can use it
    In IM 2, it takes 19 cycles to get to the interrupt routine:

    M1: 7 T states: acknowledge interrupt and decrement SP
    M2: 3 T states: write high byte and decrement SP
    M3: 3 T states: write low byte
    M4: 3 T states: read low byte from the interrupt vector
    M5: 3 T states: read high byte and jump to interrupt routine
    my old website http://home.hccnet.nl/c.born/ has changed to http://www.cborn.nl/zxfiles/ so just click it and select a file
  • ;https://www.worldofspectrum.org/faq/reference/z80reference.htm#Interrupts
    ;In IM 2, it takes 19 cycles to get to the interrupt routine:
    ;    M1: 7 T states: acknowledge interrupt and decrement SP
    ;    M2: 3 T states: write high byte and decrement SP
    ;    M3: 3 T states: write low byte
    ;    M4: 3 T states: read low byte from the interrupt vector
    ;    M5: 3 T states: read high byte and jump to interrupt routine
    
    orgmain	org	$8585		; 0x8585 =ad33924
    
    ;tt=0  starts with 19t prehandeling delay
    tm_intrupt_init equ 19
    
    ;t=    1   ; start interrupt
    ;t..
    ;t=   19
    
    im_main
                    push af         ;11t(5,3,3) save reg $XyXy = 0x8585 =ad33924
    ;t=   20        5t
    ;t=   21
    ;t=   22
    ;t=   23
    ;t=   24        ended
    
    ;t=   25        3t
    ;t=   26
    ;t=   27        ended
    
    ;t=   28        3t
    ;t=   29
    ;t=   30        ended
                    push bc         ;11t(5,3,3)
    ;t=   31        5t
    ;t=   36        3t 
    ;t=   39        3t
    ;t=   41        ended
                    push de         ;11t(5,3,3)
    ;t=   42
    ;..
    ;t=   52
                    push hl         ;11t(5,3,3)
    ;t=   53
    ;..
    ;t=   63
                    ld a,2+128      ; 7t(4,3)  a=%10000010  254=%11111110  set colour, bit 7,6 and 5 are 'ignored cq not used' by ZX
    ;t=   64        4t
    ;t=   68        3t
    ;t=   70        ended
    
                    out (254),a     ;11t(4,3,4)  #254 = 'even port' , set border a
    ;t=   71        4t
    ;t=   75        3t
    ;t=   78        4t   78/8= y.75  > 0 ut + 3 ut ???
    ;..
    ;  IO  High byte |         |
    ;       %10000010 11111110
    ;    in 40 - 7F? | Low bit | Contention pattern  N=normal, C=extra wait tstate
    ;    ------------+---------+-------------------
    ;>>>>     No     |  Reset  | N:1, C:3   <<<<<<<
    ;         No     |   Set   | N:4
    ;        Yes     |  Reset  | C:1, C:3
    ;        Yes     |   Set   | C:1, C:1, C:1, C:1
    ;..
    ;t=   81
    ; DOES setting a BORDER COLOUR with ODD value ( 1,3,5,7 ) is faster then an EVEN value (0,2,4,6) ????
    
    
    tm_main_1       equ tm_intrupt_init +11 +11 +11 +11 +7 +11  ;..62t +19t
    tmu_main_1      equ tm_main_1 / 8
    tm_out1          equ tm_main_1 - ( tmu_main_1 * 8 )
    tm_out_1         equ 8-2-tm_out1   ; on 'tm_out1=7' result is -1
    ;@t=xxxxx/8 >> 81/8= y.125  >> + 5t
    

    is t=78 the tstate from which I should calc the ULAtime (ut) ?
    78/8= y.75 > 0 tstate to wait acording the 'waitlist' on FAQ
    BUT the command explanation says there is a 3state wait
    should i include BOTH wait periodes?
    meaning that if IO in fluences part is at a different moment, FIRST the ula has to get ready (1 to 7 t wait) and THEN the other wait period is included,
    in this case with t=78, BOTH will be 0 ut + 3 ut is 3t wait extra
    my old website http://home.hccnet.nl/c.born/ has changed to http://www.cborn.nl/zxfiles/ so just click it and select a file
  • Hi,
    i still am a bit confused about this timing of IM2
    with fuse 1.5.7 the time differs between 19 and 22 which is 3 tstates, not much but still of very big influence with correct timings. I try to make my 16k bordetron better for which i made an exact 14335 tstate moment to start with a border-rainbow side, as usual.
    But this 3t make a differnce in timing and influence the border effect. I disconnect the +d which is standard attachet with my settings. so its a 'empty' zx 16k. what could influnce this timing?
    If its fuse then does it have to do with th big interrupt of the motherboard that does do the emulation?
    is there a change that a real 16k has the same effect? its ONLY 19t or 22t but not inbetween
    .
    my old website http://home.hccnet.nl/c.born/ has changed to http://www.cborn.nl/zxfiles/ so just click it and select a file
  • The interrupt doesn't necessarily happen on a fixed t state. It depends on what instruction was executing at the point the interrupt occurred.
  • edited May 30
    AndyC wrote: »
    The interrupt doesn't necessarily happen on a fixed t state. It depends on what instruction was executing at the point the interrupt occurred.

    Yes exactly the point
    If i start a bare emulated zx 16k in fuse and go to the debugger it automaticly WILL halt at the interrupt
    In IM1 mode thats adres 56 , starting with 0x0038 PUSH AF
    If you click 'continue' and 'break' several times you will see the Tstate counter differ every time you do that. It will change bewteen 15 and 22 tstate , perhaps even a broader difference.
    In IM2 you can aviod the OS sytems calls by NOT jumping to adres 56 after the inteerupt.
    That will give a pretty stable interrupt, also on a 16K model.
    Now what i see happening is that with in IM2 that interrupt start moment will be exact the SAME every interrupt loop is made, YET
    it will have a different time per instance i re-start fuse cq the whole emulator

    while writing if this idea:
    at start zx spectrum WILL be in IM1 and use adres 56 by which the interrupt start time will change VERY interrupt.
    My routine, avoiding 56, will start with any timeing between the lowest and the highest possible time needed
    ONCE it avoids 56 it will STAY on the sequence that was valid ONT THE MOMENT of invoking the IM2 interrupt.
    exacpt that on fuse thats ONLY 19 or 22 tatste and NVER inbetween. but that easily could be a emulator timing extra on top of the zx timing

    at borlin1 equ $-1
    i have to choose between ld A,0 7t
    or LD BC,00 of 10t
    what a long block, its a 99% re-write of BORDERTRON for lower memory cq contended memory:
    ; pasmo -d -1 -v --tap --name md16nir131 md16nir131.asm md16nir131.tap md16nir131.symbol
    ; quick compile in kate:
    ; pasmo -d --tap --name %n %f %n.tap %n.symbol
    ; pasmo -d %f %n.bin %n.symbol
    ; -----------------------------;--------------------------------
    
    ; based on "The BorderTron 3000" Chris Cowley chrrris@gmail.com
    ; Please use this code freely.
    ; used by Chris Born for 16kb ZX Spectrum timings in
    ; Full Contended Cycle periodes
    ; which are also known as "machine cycles"
    
    ;On first issues 16k zx spectrum, all RAM executed opcodes are fully contended, delayed.
    ;ROM is not but all other are since they reach between 0x4000 and 0x7fff.
    ;This gives a slower execution, which needs a different way off counting for eg borderlines and black/white&bright pictures
    ;In fact in 16k memory you will have to count in M-cycle off 8 tstate each.
    
    ;halt= wait for first entry tv-raster and set cycle to zero
    ;cycle=14335 tstate from halt/start of screen V and H sync= 16/48k zx screen
    ;l3b=last 3 bits
    ;compl=complement of l3b
    ;dec=decimal
    ;delay=by ULA implemented delay is Contended Delay
    ;ogev=omgekeerd evenredig=Inversely proportional
    ;c= almost constante 
    ;n=complemented 3 bit cycle number
    ;t=tstate
    ;1 t duration equals 1 n duration
    ;Z80 cycle count of 8 goes up while ULA delay count of 6 goes down 
    
    ;cycle   binary               l3b    compl  delay ogev delay-to-3bitcount 
    ;14335 = 11 0111 1111 1111  111(7) = 000(0)  6t   0n-6t=-6 > 8n-6t= 2 ,8is4bit 1000 so borrow '1'
    ;14336 = 11 1000 0000 0000  000(0) = 111(7)  5t   7n-5t= 2
    ;14337 = 11 1000 0000 0001  001(1) = 110(6)  4t   6n-4t= 2
    ;14338 = 11 1000 0000 0010  010(2) = 101(5)  3t   5n-3t= 2
    ;14339 = 11 1000 0000 0011  011(3) = 100(4)  2t   4n-2t= 2
    ;14340 = 11 1000 0000 0100  100(4) = 011(3)  1t   3n-1t= 2
    ;14341 = 11 1000 0000 0101  101(5) = 010(2)  0t   2n-0t= 2
    ;14342 = 11 1000 0000 0110  110(6) = 001(1)  0t   1n-0t= 1   almost constante = c= 2
    ;=== next ula cycle
    ;14343 = 11 1000 0000 0111  111 = 000 0-2= 6
    ;14344 = 11 1000 0000 1000
    ;14345 = 11 1000 0000 1001 >3bit> 001 >complement> 110 >n-c=t> 6n-2= 4t delay
    
    ;as formula(?)
    ;set Z80-cycle number, fetch LSB 3 bits, complement them, substract 2 and that gives the delay,
    ; >>  except for n=0(first make it 4bit by ADD 8) and n=1(delay=0 anyway)
    
    ; 1 scanline takes 224 tstate on 16k and 48k zx
    ; 224/8=28 exact, so every display scanline starts an 8fold time periode later
    ; and thus every display scanline starts with a delay of 6t by ULA
    ;14335+  0=14335  11011111111111 > 111 = 000 0-2= 6
    ;14335+224=14559  11100011011111
    ;14559+224=14783  11100110111111
    ;14783+224=15007  11101010011111  
    
    ; moments of ULA Delay are:
    ; using RAM from $4000 up to $7FFF
    ; using a port with even number/ last bit=0
    
    ;    High byte   |         | 
    ;    in 40 - 7F? | Low bit | Contention pattern  
    ;    ------------+---------+-------------------
    ;         No     |  Reset  | N:1, C:3
    ;         No     |   Set   | N:4
    ;        Yes     |  Reset  | C:1, C:3
    ;        Yes     |   Set   | C:1, C:1, C:1, C:1
    ;
    ;The 'Contention pattern' column should be interpreted from left to right. An
    ; "N:n" entry means that no delay is applied at this cycle, and the Z80 continues
    ; uninterrupted for 'n' T states. A "C:n" entry means that the ULA halts the Z80
    ; the delay is exactly the same as would occur for a contended memory access at
    ; this cycle (eg 6 T states at cycle 14335, 5 at 14336, etc on the 48K machine).
    ; After this delay, the Z80 then continues for 'n' cycles.
    
    
    setchan          equ 0x1601           ; ROM openchannel routine
    attr             equ 22528            ; start screen attribute field
    
                      org   26000
    
    Start:            exx
                      push hl
    ;                  exx  ; not needed
                      call  SetupIntHandler
    
                      ; Setup registers for our chosen border colours
                      ; C is used by the display loop so is out of bounds
    
                     ;ld    bc,0x02         is over written at first
                     ;ld     c,$fe
    BorderLoop:
                      halt                ;  0t wait for start of frame, cycle=0t,actualy last code of the frame, before waiting at interrupt
    ; In IM 2, it takes 19 cycles to get to the interrupt routine, which is 14t by it self, ei=4 ret=10.
    t1 equ 0+19+4    ;tcycle=33  ; according FUSE-1.5.7 it can be 33 or 36 tstate now!
    A_tc1 equ 33
    
    ; time counter
    A_halt            ld a,128            ;  7t        background colour
                      out (254),a         ; 11t[4,3,4] contended
                      ld hl,23672         ; 10t 
                      inc (hl)            ; 11t        1/50 sec =256*1/50 sec
                      jr nz,nsec          ; 12t 7+11+10+11+12=51
    t2a  equ 7 +11 +10 +11 +12
                                          ; -5t
                      inc hl              ;  6t
                      inc (hl)            ; 11t
                      jr nz,nmin          ; 12t -5+6+11+12=24
    t2b  equ 6 +11 +12 -5
    t2zx  equ  -5  +6 +11 +12   ; BUGGED RESULT !!!!!!!!!!!!!!!!
                                          ; -5t
                      inc hl              ;  6t
                      inc (hl)            ; 11t if 255 aswel, 2 day's are done!
                      jr tdone            ; 12t -5+6+11+12=24
    t2c  equ 6 +11 +12 -5
    
    nsec              jr $+2  ;12t
                      jr $+2  ;12t=24
    t2b2  equ 12+12
    nmin              jr $+2  ;12t
                      jr $+2  ;12t=24
    t2c2  equ 12+12
    t2 equ t2a + t2b + t2c
    A_tc2  equ A_tc1 + t2
    
    tdone             ld bc,0x260e        ; 10t  b=38, c=14
    t3 equ 10
    A_tc3 equ A_tc2 +t3
    
    a13               ld a,0              ;  7t delay !!
                      nop                 ;  4t delay !!
                      ld a,c              ;  4t a=14
    noa               dec a               ;  4t
                      jp nz ,noa          ; 10t
                      djnz a13            ; 13t 7+4+4+14*(4+10)+13 = 224 per loop
                                          ; -5t
    ; 38*(7+4+4+14*(4+10)+13) -5= 8507
    t4 equ 38*(7+4+4+14*(4+10)+13) -5
    A_tc4 equ A_tc3 +t4
    
                      ld b,19             ; 7t
    here              djnz here           ; 7+19*13-5 =249
    t5 equ 7+19*13-5
    A_tc5 equ A_tc4+t5
    
                      ld bc,$82FE         ; 10t(4,3,3)  b=red  c=prt254
                      ld hl,$8581         ; 10t   h=light blue l= darkblue
                      ld de,$8682         ; 10t   d=yellow     e=red   BRIGHT red E6,DOES IT WORK ??? how to influence that BORDER??
                      ld a,128            ;  7t   a=black
    t6 equ 10+10+10+7
    A_tc6 equ A_tc5 +t6
    ;tm=8901+10+10+10+7=8938    ;39 scanline+ 202 tstate ; !! 40x224=8960 !!!
                      ; Top Row 0
    REPT 18
    	          out (c),l           ; 12t(4,4,4)  ; blue line
    ENDM
    	          nop
    	          nop                 ; 4t   = (18*12)+4+4=216+8=224
    
                      ; Top Row 1
                      out   (c),a         ; black HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b  ; red
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h  ; lightblue
                      out   (c),h
                      out   (c),h
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 2
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 3
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 4
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 5
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),e
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 6
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),e
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),d  ;yellow  ;yellow
                      out   (c),h
                      out   (c),d  ;yellow  ;yellow
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 7
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),d  ;yellow
                      out   (c),h
                      out   (c),d  ;yellow
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 8
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),a
                      out   (c),h
                      out   (c),a
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 9
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 10
                      out   (c),d  ;yellow   HIDDEN - Background
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),d  ;yellow
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 11
                      out   (c),d  ;yellow  HIDDEN - Background
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),d  ;yellow
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 12
                      out   (c),d  ;yellow  HIDDEN - Background
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),d  ;yellow
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 13
                      out   (c),d  ;yellow  HIDDEN - Background
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),d  ;yellow
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 14
                      out   (c),d  ;yellow  HIDDEN - Background
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),d  ;yellow
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 15
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 16
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 17
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 18
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 19
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 20
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),a
                      out   (c),h
                      out   (c),a
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 21
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),h  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 22
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Top Row 23
    REPT 17
    	          out (c),l    ; blue
    ENDM
                      out (c),a    ; black    
    	          nop
    	          nop          ;  4 t = (18*12)+4+4=216+8=224 
    t7 equ 24 * 224
    A_tc7 equ A_tc6 + t7
    
    ;Fully Contended Area?
    
    ;tc=8938 + 24*224 = 8938 + 5376 = 14314     !!!!!14335=screen!!!!! 14335-14314=21
    ; tc is 14314 according FUSE 1.5.7, i am 3t state ahead, yet earlier it was 3 state extra (19 or 22 interrupt_start_time !!)
    A_time            exx                 ;  4t move colorscheme aside
                      ld hl,$c700         ; 10t [4,3,3]   h=lines+8  l=color-0    4+10+7=21
    borlin1 equ $-1
                      ;ld bc,0             ; 10t [4,3,3]   delay !!!!!
                       ld a,0              ; 7t
    
    t8 equ 4+10+10
    A_tc8 equ A_tc7 + t8
    
    ;ttt===14335 ???exact ????? CONTENDED from now!
                                          ; manual coping Tstate from FUSE 1.5.7
    lab               nop                 ; 10t  (6+4) C is Sure
                      nop                 ; 13t (5,3,3)or (2+5+6)
                      nop                 ;  4t =(14362)
                      nop                 ;  7t (2+4+1)??
                      nop                 ;  8t 
                      nop                 ;  8t
                      nop                 ;  8t
                      nop                 ;  8t =14401
                      nop                 ;  8t =14417
                      ld    a,h           ;  8t            10+13+4+7+8+8+8+8+8+8 =82
    ;224-82=142
                      and   %00000111     ; 15t =14440  switch off bit 6, beeper ticks/ear/mic
                      or    %10000000     ; 16t
                      out   (254),a       ; 16t =14472  +ula colour, around border   15+16+16 +82=
    ;224-129  ; Not contended for a while
                      nop                 ;  4t
                      nop                 ;  4t
                      nop                 ;  4t
                      nop                 ;  4t
                      nop                 ;  4t
                      nop                 ;  4t 4+4+4+4  +137=153
    
                      dec   a             ;  4t =14476  decrease colour ahead of counter h
                      and   %00000111     ;  7t  switch off bit 6, beeper ticks/ear/mic
                      or    %10000000     ;  7t
                      out   (254),a       ; 11t +ula black
                      ld a,l              ;  4t =14505
                      out   (254),a       ; 11t +ula black   4+7+7+11+4+11  +153=197
    ;224-197=27
    
                      dec h               ;  4t
                      ld a,7              ;  7t =14527 last line+8
    borlin2 equ $
                      cp h                ;  4t  compare a high or low Areg
                      jr nz,lab           ; 12t  (*192)      4+7+4+12 +197 =224
    
    ;192*224=43,008 tstate
    
    noncontended      exx                 ; 4t  fetch color scheme again
    
                      ; Bottom Row 00
    
                      nop
                      nop
                      nop
                      nop
                      nop
    
                      out   (c),b
                      out   (c),l
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop                  
    
                      ; Bottom Row 01
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),l
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop                  
    
    ; Bottom Rows 0-9
    REPT 3
    REPT 18
    	out (c),a
    ENDM
    	nop
    	nop
    ENDM
    
    
                      ; Bottom Row 10
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 11
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 12
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 13
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),d  ;yellow  ;yellow
                      out   (c),d  ;yellow  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 14
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),d  ;yellow  ;yellow
                      out   (c),d  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 15
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),d  ;yellow
                      out   (c),d  ;yellow
                      out   (c),d  ;yellow
                      out   (c),d  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 16
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),d  ;yellow
                      out   (c),e
                      out   (c),e
                      out   (c),d  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 17
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),d  ;yellow
                      out   (c),d  ;yellow
                      out   (c),e
                      out   (c),e
                      out   (c),d  ;yellow
                      out   (c),d  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 18
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),d  ;yellow
                      out   (c),d  ;yellow
                      out   (c),e
                      out   (c),e
                      out   (c),e
                      out   (c),e
                      out   (c),d  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 19
                      out   (c),a
                      out   (c),a
                      out   (c),b
                      out   (c),d  ;yellow
                      out   (c),d  ;yellow
                      out   (c),e
                      out   (c),h
                      out   (c),h
                      out   (c),e
                      out   (c),d  ;yellow
                      out   (c),d  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 20
                      out   (c),a
                      out   (c),b
                      out   (c),b
                      out   (c),d  ;yellow
                      out   (c),e
                      out   (c),e
                      out   (c),h
                      out   (c),h
                      out   (c),e
                      out   (c),d  ;yellow
                      out   (c),d  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 21
                      out   (c),a
                      out   (c),b
                      out   (c),d  ;yellow
                      out   (c),e
                      out   (c),e
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),h
                      out   (c),e
                      out   (c),d  ;yellow
                      out   (c),d  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 22
                      out   (c),b
                      out   (c),b
                      out   (c),d  ;yellow
                      out   (c),e
                      out   (c),e
                      out   (c),h
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),e
                      out   (c),e
                      out   (c),d  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    
                      ; Bottom Row 23
                      out   (c),b
                      out   (c),b
                      out   (c),d  ;yellow
                      out   (c),e
                      out   (c),h
                      out   (c),h
                      out   (c),a
                      out   (c),a
                      out   (c),h
                      out   (c),e
                      out   (c),e
                      out   (c),d  ;yellow
                      out   (c),b
                      out   (c),b
                      out   (c),b
                      out   (c),a
                      out   (c),a  ; HIDDEN - Background
                      out   (c),a  ; HIDDEN - Background
                      nop
                      nop
    jr notdone
    exx
    ld hl,borlin1
    ld a,(hl)
    and 255-7
    ld b,a
    ld a,(hl)
    and 7
    inc a
    and 7
    or b
    ld (hl),a
    ld hl,borlin2
    ld a,(hl)
    and 255-7
    ld b,a
    ld a,(hl)
    and 7
    inc a
    and 7
    or b
    ld (hl),a
    exx
    
    notdone           xor   a
                      in    a,($FE)   ; port $00fe
                      and   $1F       ; check ANY key touch with bin 11111
                      cp    $1F
                      jp    z,BorderLoop  ; keep looping without system !
    
    ;big key check here
                      ld b,0xfe     ; 7t
                      ld hl,keys    ;10t
    ky                in a,(254)    ;11t contended
                      ld (hl),a     ; 7t
                      inc hl        ; 6t
                      rlc b         ; 8t
                      jp c,ky       ;10t
                                    ; 7+10+8*(11+7+6+8+10)= 353
    
    ReturnToBASIC:    di
                      ld    a,$3F
                      ld    i,a
                      im    1
                      ei
                      pop hl
                      exx
                      ret
    
    numstr            defm 0,22,1,0,16,7,17,0,"0123456789abcde><edcba9876543210",21,0,255
    SetupIntHandler:  di
    screen            call	0x0d6b			; clear bitmap
                      ld hl,16384
                      ld de,16385
                      ld a,%00001111
                      ld bc,1024
                      push bc
                      ld (hl),a
                      ldir
                      rrca
                      rrca
                      rrca
                      rrca
                      ld (hl),a
                      pop bc
                      ldir
    
                      ld a,%01010101
                      ld b,15
    
    spix              push bc
                      ld (hl),a
                      ld bc,256
                      ldir
                      rrca
                      pop bc
                      djnz spix
                      ld (hl),a
                      ld bc,255
                      ldir
                      push hl
                      ld hl,numstr
                      call fetchan
                      pop hl
                      inc hl
    
    ;colourwrap                   ; replace for sm_attr routine
                      ld hl,attr
    phl               push hl
                      ld bc,32
                      ld d,3
    moink             ld e,8
    numbr             ld a,7         ; bright 0, paper 0, ink 7
    ink0              ld (hl),a
                      add hl,bc
                      dec a         
                      dec e
                      jr nz,ink0
                      dec d
                      jr nz,moink
    
                      pop hl
                      inc hl
    
                      ld a,l         ; l raises and so does paper
                      and %00001110  ; STEP 2, carry reset
                      rlca           ; %00011100
                      rlca           ; %00111000
                      ld b,a
    
                      ld a,(numbr+1)
                      and %11000111  ; exclude PAPER
                      or b           ; write PAPER
                      xor 64         ; bright on/off
                      ld (numbr+1),a
    
                      ld a,31
                      cp l        ; on l=32 Carry set
                      jr nc,phl   ;
    
                      ; Put an EI and RET at $7f7f
                      ld    a,i
                      cp    $7e
                      jr    z,imset    ; assume all set and return
                      ld    hl,$7f7f
                      ld    (hl),$FB
                      inc   hl
                      ld    (hl),$C9
    
                      ; Put interrupt vector table at $7E00
                      ld    hl,$7E00
                      ld    (hl),$7F
                      ld    de,$7E01
                      ld    bc,$0100
                      ldir
    kend              ld    a,$7e  
                      ld    i,a
                      im    2
    imset             ei
    dummy             ret           ; set 'dummy' for empty CALLs without changing length of code
    
    
    ; FIRST value/char is CHANNEL-INFO and used to set the correct channel, 0,2,4
    ; HL must be set to the string before calling this routine
    fetchan           ld a,(hl)
                      push hl
                      call setchan
                      pop hl
    ; if ploop is used as entry notice first value will be skipped so set HL=HL-1 instead before calling, or call ploop1
    ploop:            inc hl           
    ploop1            ld a,(hl)
                      cp 0xFF
                      ret z
                      rst 16          ; takes very long, must be DIY
                      jr ploop
    
    keys              defs 8,0        ; 8 key storage
    
    ;small 1/6 screen ATTR , actualy counting 0 to 127 in another following order
    smattr            defb      7, 71, 15, 79, 23, 87, 31, 95, 39,103, 47,111, 55,119, 63,127
                      defb      6, 70, 14, 78, 22, 86, 30, 94, 38,102, 46,110, 54,118, 62,126
                      defb      5, 69, 13, 77, 21, 85, 29, 93, 37,101, 45,109, 53,117, 61,125
                      defb      4, 68, 12, 76, 20, 84, 28, 92, 36,100, 44,108, 52,116, 60,124
                      defb      3, 67, 11, 75, 19, 83, 27, 91, 35, 99, 43,107, 51,115, 59,123
                      defb      2, 66, 10, 74, 18, 82, 26, 90, 34, 98, 42,106, 50,114, 58,122
                      defb      1, 65,  9, 73, 17, 81, 25, 89, 33, 97, 41,105, 49,113, 57,121
                      defb      0, 64,  8, 72, 16, 80, 24, 88, 32, 96, 40,104, 48,112, 56,120
    
    the               end 26000
    
    
    Post edited by Crisis on
    my old website http://home.hccnet.nl/c.born/ has changed to http://www.cborn.nl/zxfiles/ so just click it and select a file
  • I'm not sure what you are trying to get at. On a real machine the precise moment an interrupt will occur will vary by a few t-states depending on what instructions are running at the time. There is no way of guaranteeing that the interrupt response will occur on a specific display cycle, that's exactly why people use various floating bus and/or contention based tricks to re-sync with the display.
  • "the precise moment an interrupt will occur will vary by a few t-states depending on what instructions are running at the time"
    ok, i get it, try to stick it in my brain.
    its the moment of the interrupt ITSELF. ok. the interrupt HAS to wait until the instruction BE-ing executed AT interupt time is FINISHED and thus will postpone the interrupt itself. That means the LAST instruction right before the interrupt sets the timing MOMENT of the next interrupt. so its NOT a ULA thing now. ok then.
    Maybe a trick might be to do a HALT first and then immediate a IM2 and then jump to a HALT again.
    But thats not a real sync yet.
    my old website http://home.hccnet.nl/c.born/ has changed to http://www.cborn.nl/zxfiles/ so just click it and select a file
Sign In or Register to comment.