Hi Guys,
I wonder if anyone can see a problem with the code which prevents it from running correctly on the msx 64K version.
So I've removed the MSX's rom and placed my own one in with code as below.
The VDP is generating the 50hz interrupt signals ok, however for some reason the IORQ is activating about 240 times within each 50hz cycle. I dont expect this to happen as the iorq should only activate to acknowlege the 50hz interrupt at most, also the iorq will activate when writing to the output port, which should be just once per second.
All i can think of is that the program is making an invalid jump somewhere but i cannot find any problem. I've tried this on Zemu and it seems to work ok.
I've included the code below along with a snapshot of the binary.
0000: (runtime initialising, pre main) F3,0EA8,3EA0,ED79,31F0FF,ED56,0E99,3E20,ED79,0E99,3E81,ED79,CD0001 F3 [ 4] 22 DI ;disable interrupts (will be re-enabled in main program) 23 ;; set paging registers to allow rom at low 32K memory and ram at high 32K 24 ;set register 0xA8 to value (10100000) 0xA0 0E A8 [ 7] 25 ld c, #0xA8 3E A0 [ 7] 26 ld a, #0xA0 ED 79 [12] 27 out (c),a 28 29 ;; Stack at the top of memory. 31 F0 FF [10] 30 ld sp,#0xFFF0 31 32 33 ;; set z80 to receive and process maskable interrupts /INT interrupt mode 1 ED 56 [ 8] 34 IM 1 35 36 ;; set vdp to generate 50hz IM1_interrupts 37 38 ;;out 0x99,#32 ;;set bit 5 0E 99 [ 7] 39 ld c, #0x99 3E 20 [ 7] 40 ld a, #32 ED 79 [12] 41 out (c),a 42 43 44 ;;out 0x99,#129 ;;store in register 1&128 (control reg) 0E 99 [ 7] 45 ld c, #0x99 3E 81 [ 7] 46 ld a, #129 ED 79 [12] 47 out (c),a 48 49 50 51 52 CD 00 01 [17] 53 call _main at 0x0100 -------------------------------------------------------------------------------------------- 0038: F3,CD1301,FB,ED4D 11 .org 0x38 F3 [ 4] 12 DI ;disable further interrupts for now CD 13 01 [17] 13 call _IM1_InterruptHandler at location 0x0113 FB [ 4] 14 EI ;re-enable interrupts ED 4D [14] 15 reti ; return from this handler to where program left off. -------------------------------------------------------------------------------------------- 0100: (main program) FD210080,FD360032,FD210180,FD360000,FB,18FE,FD210080,FD7E00,210080,C6FF,77 54 _main:: 55 ;test.c:7: counter =50; FD 21r00r80 [14] 56 ld iy, #_counter FD 36 00 32 [19] 57 ld 0 (iy), #0x32 58 ;test.c:8: pattern =0; FD 21r01r80 [14] 59 ld iy, #_pattern FD 36 00 00 [19] 60 ld 0 (iy), #0x00 61 ;test.c:11: __endasm; FB [ 4] 62 EI 63 ;test.c:12: while(1==1){} 64 00102$: 65 ;test.c:14: }//end of main 18 FE [12] 66 jr 00102$ Function IM1_InterruptHandler -------------------------------------------------------------------------------------------- 71 _IM1_InterruptHandler:: 72 ;test.c:32: counter=counter-1; FD 21r00r80 [14] 73 ld iy, #_counter FD 7E 00 [19] 74 ld a, 0 (iy) 21r00r80 [10] 75 ld hl, #_counter C6 FF [ 7] 76 add a, #0xff 77 [ 7] 77 ld (hl), a 0120: interrupt handler (continued) FD7E00,B7,2019,FD210180,FD3400,FD7E00,FD210080,FD360032,3A0180,0E00,ED79,DB99,C9 78 ;test.c:33: if(counter==0){ FD 7E 00 [19] 79 ld a, 0 (iy) B7 [ 4] 80 or a, a 20 19 [12] 81 jr NZ,END_OF_THIS 82 ;test.c:34: pattern+=1; FD 21r01r80 [14] 83 ld iy, #_pattern FD 34 00 [23] 84 inc 0 (iy) FD 7E 00 [19] 85 ld a, 0 (iy) 86 ;test.c:35: counter=50; FD 21r00r80 [14] 87 ld iy, #_counter FD 36 00 32 [19] 88 ld 0 (iy), #0x32 89 ;test.c:42: __endasm; 3Ar01r80 [13] 90 ld a,(#_pattern); 0E 00 [ 7] 91 ld c, #0x00 ED 79 [12] 92 out (c),a END_OF_THIS: 94 ;test.c:47: __endasm; DB 99 [11] 95 in a, (#0x99) ;read from status port to clear VDP interrupt 96 ;test.c:48: } C9 [10] 97 ret ;return from handler, should goto interrupt vector which called this, then it will end isr and return to main.
binary hex view:
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000000 F3 0E A8 3E A0 ED 79 31 F0 FF ED 56 0E 99 3E 20 ó.¨> íy1ðÿíV.™> 00000010 ED 79 0E 99 3E 81 ED 79 CD 00 01 FF FF FF FF FF íy.™>.íyÍ..ÿÿÿÿÿ 00000020 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000030 FF FF FF FF FF FF FF FF F3 CD 13 01 FB ED 4D FF ÿÿÿÿÿÿÿÿóÍ..ûíMÿ 00000040 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000050 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000060 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000070 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000080 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000090 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000000A0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000000B0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000000C0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000000D0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000000E0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 000000F0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 00000100 FD 21 00 80 FD 36 00 32 FD 21 01 80 FD 36 00 00 ý!.€ý6.2ý!.€ý6.. 00000110 FB 18 FE FD 21 00 80 FD 7E 00 21 00 80 C6 FF 77 û.þý!.€ý~.!.€Æÿw 00000120 FD 7E 00 B7 20 19 FD 21 01 80 FD 34 00 FD 7E 00 ý~.· .ý!.€ý4.ý~. 00000130 FD 21 00 80 FD 36 00 32 3A 01 80 0E 00 ED 79 DB ý!.€ý6.2:.€..íyÛ 00000140 99 C9
So the program should just count 50 cycles then increment the value being sent to the output port 0 once every second.
Any thoughts?
Regards
Ed