Z80エミュレーターを搭載した作品群
Revisión | fec9c66e3bf425bc974f8e1360ed91dfae6490e3 (tree) |
---|---|
Tiempo | 2019-04-07 12:43:08 |
Autor | Katsumi <kmorimatsu@sour...> |
Commiter | Katsumi |
CP/KM ver 0.6
@@ -9,7 +9,7 @@ | ||
9 | 9 | --> |
10 | 10 | <head> |
11 | 11 | <meta charset="UTF-8" /> |
12 | - <title>CP/KM web v0.5</title> | |
12 | + <title>CP/KM web v0.6</title> | |
13 | 13 | <link rel="stylesheet" type="text/css" href="./style.css" /> |
14 | 14 | <!-- HTML5 functions --> |
15 | 15 | <script type="text/javascript" src="./get.js"></script> |
@@ -142,9 +142,10 @@ display.writeChar=function(ascii){ | ||
142 | 142 | this.cursor=parseInt(this.cursor/80)*80+80; |
143 | 143 | break; |
144 | 144 | case 0x0b: // ^K |
145 | - for(var i=this.cursor;i<parseInt(this.cursor/80)*80+80;i++){ | |
145 | + /*for(var i=this.cursor;i<parseInt(this.cursor/80)*80+80;i++){ | |
146 | 146 | this.write(i,0x20); |
147 | - } | |
147 | + }*/ | |
148 | + if (80<=this.cursor) this.cursor-=80; | |
148 | 149 | break; |
149 | 150 | case 0x0d: // ^M (CR) |
150 | 151 | this.cursor=parseInt(this.cursor/80)*80+80; |
@@ -160,6 +161,15 @@ display.writeChar=function(ascii){ | ||
160 | 161 | case 0x1a: // ^Z |
161 | 162 | this.cls(); |
162 | 163 | break; |
164 | + case 0x1c: // ^\ | |
165 | + this.cursor++; | |
166 | + break; | |
167 | + case 0x1d: // ^] | |
168 | + if (0<this.cursor) this.cursor--; | |
169 | + break; | |
170 | + case 0x1e: // ^^ | |
171 | + this.cursor=0; | |
172 | + break; | |
163 | 173 | default: |
164 | 174 | this.write(this.cursor,ascii); |
165 | 175 | this.cursor++; |
@@ -1,8 +1,9 @@ | ||
1 | -/********************************* | |
2 | -* CP/KM web written by Katsumi * | |
3 | -* This script is released * | |
4 | -* under the LGPL v2.1. * | |
5 | -*********************************/ | |
1 | +/********************************** | |
2 | +* Z80 emulator written by Katsumi * | |
3 | +* ver 0.80 * | |
4 | +* This script is released * | |
5 | +* under the LGPL v2.1. * | |
6 | +**********************************/ | |
6 | 7 | |
7 | 8 | /* |
8 | 9 | Public methods: |
@@ -10,7 +11,7 @@ | ||
10 | 11 | z80.setSpeed(clk); |
11 | 12 | z80.getMicroSec(); |
12 | 13 | z80.exec(msec); |
13 | - z80.interrupt(); | |
14 | + z80.interrupt(code); | |
14 | 15 | z80.nmr(); |
15 | 16 | |
16 | 17 | Required outside methods: |
@@ -24,6 +25,7 @@ | ||
24 | 25 | z80=new Object(); |
25 | 26 | z80.breakPoint=-1; |
26 | 27 | z80.step=0; |
28 | +z80.m1=false; | |
27 | 29 | z80.reset=function(){ |
28 | 30 | // 8 bit registers |
29 | 31 | this.z80IM=0; |
@@ -72,11 +74,13 @@ z80.reset=function(){ | ||
72 | 74 | this.irq=0; |
73 | 75 | this.nrq=0; |
74 | 76 | }; |
75 | -z80.interrupt=function(){ | |
77 | +z80.intCode=0xff; | |
78 | +z80.interrupt=function(code){ | |
76 | 79 | if (!this.flagIFF1) return; |
77 | 80 | this.loadIFF1(0); |
78 | 81 | this.loadIFF2(0); |
79 | 82 | this.irq=1; |
83 | + this.intCode=code; | |
80 | 84 | }; |
81 | 85 | z80.nmr=function(){ |
82 | 86 | this.loadIFF1(0); |
@@ -94,11 +98,22 @@ z80.doInt=function(){ | ||
94 | 98 | this.loadPC(0x0066); |
95 | 99 | } else { |
96 | 100 | // Mascable interrupt |
97 | - if (this.regIM!=1) { | |
98 | - alert("Mode "+this.regIM+" interrupt is not supported."); | |
99 | - return; | |
101 | + switch (this.regIM) { | |
102 | + case 0: | |
103 | + this.codeVector[this.intCode](); | |
104 | + return; | |
105 | + case 2: | |
106 | + var addr=(this.regI<<8)|this.intCode; | |
107 | + this.loadSP(this.regSP-2); | |
108 | + memory.write(this.regSP,this.regPC&0xFF); | |
109 | + memory.write(this.regSP+1,this.regPC>>8); | |
110 | + this.loadPC(memory.read(addr)|(memory.read(addr+1)<<8)); | |
111 | + return; | |
112 | + case 1: | |
113 | + default: | |
114 | + this.codeFF(); | |
115 | + return; | |
100 | 116 | } |
101 | - this.codeFF(); | |
102 | 117 | } |
103 | 118 | }; |
104 | 119 | z80.speed=2000; // Default: 2 MHz |
@@ -113,25 +128,32 @@ z80.events=function(){ | ||
113 | 128 | // The events function will be called every msec. |
114 | 129 | // Override this function if required to use. |
115 | 130 | } |
131 | + | |
116 | 132 | z80.clk=0; |
117 | -z80.setT4= function(){ this.clk+=4; } | |
118 | -z80.setT5= function(){ this.clk+=5; } | |
119 | -z80.setT6= function(){ this.clk+=6; } | |
120 | -z80.setT7= function(){ this.clk+=7; } | |
121 | -z80.setT8= function(){ this.clk+=8; } | |
122 | -z80.setT9= function(){ this.clk+=9; } | |
123 | -z80.setT10=function(){ this.clk+=10; } | |
124 | -z80.setT11=function(){ this.clk+=11; } | |
125 | -z80.setT12=function(){ this.clk+=12; } | |
126 | -z80.setT13=function(){ this.clk+=13; } | |
127 | -z80.setT14=function(){ this.clk+=14; } | |
128 | -z80.setT15=function(){ this.clk+=15; } | |
129 | -z80.setT16=function(){ this.clk+=16; } | |
130 | -z80.setT17=function(){ this.clk+=17; } | |
131 | -z80.setT19=function(){ this.clk+=19; } | |
132 | -z80.setT20=function(){ this.clk+=20; } | |
133 | -z80.setT21=function(){ this.clk+=21; } | |
134 | -z80.setT23=function(){ this.clk+=23; } | |
133 | +z80.setT4= function(){ this.clk+=4; } | |
134 | +z80.setT4_5= function(){ this.clk+=4; } | |
135 | +z80.setT4_7= function(){ this.clk+=4; } | |
136 | +z80.setT5= function(){ this.clk+=5; } | |
137 | +z80.setT6= function(){ this.clk+=6; } | |
138 | +z80.setT6_5= function(){ this.clk+=6; } | |
139 | +z80.setT7= function(){ this.clk+=7; } | |
140 | +z80.setT8= function(){ this.clk+=8; } | |
141 | +z80.setT9= function(){ this.clk+=9; } | |
142 | +z80.setT10= function(){ this.clk+=10; } | |
143 | +z80.setT10_11=function(){ this.clk+=10; } | |
144 | +z80.setT11= function(){ this.clk+=11; } | |
145 | +z80.setT11_10=function(){ this.clk+=11; } | |
146 | +z80.setT12= function(){ this.clk+=12; } | |
147 | +z80.setT13= function(){ this.clk+=13; } | |
148 | +z80.setT14= function(){ this.clk+=14; } | |
149 | +z80.setT15= function(){ this.clk+=15; } | |
150 | +z80.setT16= function(){ this.clk+=16; } | |
151 | +z80.setT17= function(){ this.clk+=17; } | |
152 | +z80.setT19= function(){ this.clk+=19; } | |
153 | +z80.setT19_18=function(){ this.clk+=19; } | |
154 | +z80.setT20= function(){ this.clk+=20; } | |
155 | +z80.setT21= function(){ this.clk+=21; } | |
156 | +z80.setT23= function(){ this.clk+=23; } | |
135 | 157 | |
136 | 158 | z80.loadA=function(x){ |
137 | 159 | this.regA=x&0xff; |
@@ -179,7 +201,7 @@ z80.loadI=function(x){ | ||
179 | 201 | this.regI=x&0xff; |
180 | 202 | }; |
181 | 203 | z80.loadR=function(x){ |
182 | - this.regR=x&0xff; | |
204 | + this.regR=x&0x7f; | |
183 | 205 | }; |
184 | 206 | z80.loadIXh=function(x){ |
185 | 207 | this.regIXh=x&0xff; |
@@ -303,19 +325,19 @@ z80.code02=function(){ | ||
303 | 325 | z80.code03=function(){ |
304 | 326 | //INC BC |
305 | 327 | //Note that 16-bit increment routine does not change flags. |
306 | - this.setT6(); | |
328 | + this.setT6_5(); | |
307 | 329 | this.loadBC(this.regBC+1); |
308 | 330 | }; |
309 | 331 | z80.code04=function(){ |
310 | 332 | //INC B |
311 | - this.setT4(); | |
333 | + this.setT4_5(); | |
312 | 334 | var i8=this.regB+1; |
313 | 335 | this.loadB(i8); |
314 | 336 | this.flag8inc(i8); |
315 | 337 | }; |
316 | 338 | z80.code05=function(){ |
317 | 339 | //DEC B |
318 | - this.setT4(); | |
340 | + this.setT4_5(); | |
319 | 341 | var i8=this.regB-1; |
320 | 342 | this.loadB(i8); |
321 | 343 | this.flag8dec(i8); |
@@ -355,7 +377,7 @@ z80.code08=function(){ | ||
355 | 377 | }; |
356 | 378 | z80.code09=function(){ |
357 | 379 | //ADD HL,BC |
358 | - this.setT11(); | |
380 | + this.setT11_10(); | |
359 | 381 | this.z80ADD16(this.regBC); |
360 | 382 | }; |
361 | 383 | z80.code0A=function(){ |
@@ -365,19 +387,19 @@ z80.code0A=function(){ | ||
365 | 387 | }; |
366 | 388 | z80.code0B=function(){ |
367 | 389 | //DEC BC |
368 | - this.setT6(); | |
390 | + this.setT6_5(); | |
369 | 391 | this.loadBC(this.regBC-1); |
370 | 392 | }; |
371 | 393 | z80.code0C=function(){ |
372 | 394 | //INC C |
373 | - this.setT4(); | |
395 | + this.setT4_5(); | |
374 | 396 | var i8=this.regC+1; |
375 | 397 | this.loadC(i8); |
376 | 398 | this.flag8inc(i8); |
377 | 399 | }; |
378 | 400 | z80.code0D=function(){ |
379 | 401 | //DEC C |
380 | - this.setT4(); | |
402 | + this.setT4_5(); | |
381 | 403 | var i8=this.regC-1; |
382 | 404 | this.loadC(i8); |
383 | 405 | this.flag8dec(i8); |
@@ -434,19 +456,19 @@ z80.code12=function(){ | ||
434 | 456 | }; |
435 | 457 | z80.code13=function(){ |
436 | 458 | //INC DE |
437 | - this.setT6(); | |
459 | + this.setT6_5(); | |
438 | 460 | this.loadDE(this.regDE+1); |
439 | 461 | }; |
440 | 462 | z80.code14=function(){ |
441 | 463 | //INC D |
442 | - this.setT4(); | |
464 | + this.setT4_5(); | |
443 | 465 | var i8=this.regD+1; |
444 | 466 | this.loadD(i8); |
445 | 467 | this.flag8inc(i8); |
446 | 468 | }; |
447 | 469 | z80.code15=function(){ |
448 | 470 | //DEC D |
449 | - this.setT4(); | |
471 | + this.setT4_5(); | |
450 | 472 | var i8=this.regD-1; |
451 | 473 | this.loadD(i8); |
452 | 474 | this.flag8dec(i8); |
@@ -482,7 +504,7 @@ z80.code18=function(){ | ||
482 | 504 | }; |
483 | 505 | z80.code19=function(){ |
484 | 506 | //ADD HL,DE |
485 | - this.setT11(); | |
507 | + this.setT11_10(); | |
486 | 508 | this.z80ADD16(this.regDE); |
487 | 509 | }; |
488 | 510 | z80.code1A=function(){ |
@@ -492,19 +514,19 @@ z80.code1A=function(){ | ||
492 | 514 | }; |
493 | 515 | z80.code1B=function(){ |
494 | 516 | //DEC DE |
495 | - this.setT6(); | |
517 | + this.setT6_5(); | |
496 | 518 | this.loadDE(this.regDE-1); |
497 | 519 | }; |
498 | 520 | z80.code1C=function(){ |
499 | 521 | //INC E |
500 | - this.setT4(); | |
522 | + this.setT4_5(); | |
501 | 523 | var i8=this.regE+1; |
502 | 524 | this.loadE(i8); |
503 | 525 | this.flag8inc(i8); |
504 | 526 | }; |
505 | 527 | z80.code1D=function(){ |
506 | 528 | //DEC E |
507 | - this.setT4(); | |
529 | + this.setT4_5(); | |
508 | 530 | var i8=this.regE-1; |
509 | 531 | this.loadE(i8); |
510 | 532 | this.flag8dec(i8); |
@@ -560,19 +582,19 @@ z80.code22=function(){ | ||
560 | 582 | }; |
561 | 583 | z80.code23=function(){ |
562 | 584 | //INC HL |
563 | - this.setT6(); | |
585 | + this.setT6_5(); | |
564 | 586 | this.loadHL(this.regHL+1); |
565 | 587 | }; |
566 | 588 | z80.code24=function(){ |
567 | 589 | //INC H |
568 | - this.setT4(); | |
590 | + this.setT4_5(); | |
569 | 591 | var i8=this.regH+1; |
570 | 592 | this.loadH(i8); |
571 | 593 | this.flag8inc(i8); |
572 | 594 | }; |
573 | 595 | z80.code25=function(){ |
574 | 596 | //DEC H |
575 | - this.setT4(); | |
597 | + this.setT4_5(); | |
576 | 598 | var i8=this.regH-1; |
577 | 599 | this.loadH(i8); |
578 | 600 | this.flag8dec(i8); |
@@ -736,7 +758,7 @@ z80.code28=function(){ | ||
736 | 758 | }; |
737 | 759 | z80.code29=function(){ |
738 | 760 | //ADD HL,HL |
739 | - this.setT11(); | |
761 | + this.setT11_10(); | |
740 | 762 | this.z80ADD16(this.regHL); |
741 | 763 | }; |
742 | 764 | z80.code2A=function(){ |
@@ -750,19 +772,19 @@ z80.code2A=function(){ | ||
750 | 772 | }; |
751 | 773 | z80.code2B=function(){ |
752 | 774 | //DEC HL |
753 | - this.setT6(); | |
775 | + this.setT6_5(); | |
754 | 776 | this.loadHL(this.regHL-1); |
755 | 777 | }; |
756 | 778 | z80.code2C=function(){ |
757 | 779 | //INC L |
758 | - this.setT4(); | |
780 | + this.setT4_5(); | |
759 | 781 | var i8=this.regL+1; |
760 | 782 | this.loadL(i8); |
761 | 783 | this.flag8inc(i8); |
762 | 784 | }; |
763 | 785 | z80.code2D=function(){ |
764 | 786 | //DEC L |
765 | - this.setT4(); | |
787 | + this.setT4_5(); | |
766 | 788 | var i8=this.regL-1; |
767 | 789 | this.loadL(i8); |
768 | 790 | this.flag8dec(i8); |
@@ -815,19 +837,19 @@ z80.code32=function(){ | ||
815 | 837 | }; |
816 | 838 | z80.code33=function(){ |
817 | 839 | //INC SP |
818 | - this.setT6(); | |
840 | + this.setT6_5(); | |
819 | 841 | this.loadSP(this.regSP+1); |
820 | 842 | }; |
821 | 843 | z80.code34=function(){ |
822 | 844 | //INC (HL) |
823 | - this.setT11(); | |
845 | + this.setT11_10(); | |
824 | 846 | var i8=memory.read(this.regHL)+1; |
825 | 847 | memory.write(this.regHL,i8); |
826 | 848 | this.flag8inc(i8); |
827 | 849 | }; |
828 | 850 | z80.code35=function(){ |
829 | 851 | //DEC (HL) |
830 | - this.setT11(); | |
852 | + this.setT11_10(); | |
831 | 853 | var i8=memory.read(this.regHL)-1; |
832 | 854 | memory.write(this.regHL,i8); |
833 | 855 | this.flag8dec(i8); |
@@ -864,7 +886,7 @@ z80.code38=function(){ | ||
864 | 886 | }; |
865 | 887 | z80.code39=function(){ |
866 | 888 | //ADD HL,SP |
867 | - this.setT11(); | |
889 | + this.setT11_10(); | |
868 | 890 | this.z80ADD16(this.regSP); |
869 | 891 | }; |
870 | 892 | z80.code3A=function(){ |
@@ -877,19 +899,19 @@ z80.code3A=function(){ | ||
877 | 899 | }; |
878 | 900 | z80.code3B=function(){ |
879 | 901 | //DEC SP |
880 | - this.setT6(); | |
902 | + this.setT6_5(); | |
881 | 903 | this.loadSP(this.regSP-1); |
882 | 904 | }; |
883 | 905 | z80.code3C=function(){ |
884 | 906 | //INC A |
885 | - this.setT4(); | |
907 | + this.setT4_5(); | |
886 | 908 | var i8=this.regA+1; |
887 | 909 | this.loadA(i8); |
888 | 910 | this.flag8inc(i8); |
889 | 911 | }; |
890 | 912 | z80.code3D=function(){ |
891 | 913 | //DEC A |
892 | - this.setT4(); | |
914 | + this.setT4_5(); | |
893 | 915 | var i8=this.regA-1; |
894 | 916 | this.loadA(i8); |
895 | 917 | this.flag8dec(i8); |
@@ -921,32 +943,32 @@ C is set if CY was 0 before operation; reset otherwise | ||
921 | 943 | }; |
922 | 944 | z80.code40=function(){ |
923 | 945 | //LD B,B |
924 | - this.setT4(); | |
946 | + this.setT4_5(); | |
925 | 947 | this.loadB(this.regB); |
926 | 948 | }; |
927 | 949 | z80.code41=function(){ |
928 | 950 | //LD B,C |
929 | - this.setT4(); | |
951 | + this.setT4_5(); | |
930 | 952 | this.loadB(this.regC); |
931 | 953 | }; |
932 | 954 | z80.code42=function(){ |
933 | 955 | //LD B,D |
934 | - this.setT4(); | |
956 | + this.setT4_5(); | |
935 | 957 | this.loadB(this.regD); |
936 | 958 | }; |
937 | 959 | z80.code43=function(){ |
938 | 960 | //LD B,E |
939 | - this.setT4(); | |
961 | + this.setT4_5(); | |
940 | 962 | this.loadB(this.regE); |
941 | 963 | }; |
942 | 964 | z80.code44=function(){ |
943 | 965 | //LD B,H |
944 | - this.setT4(); | |
966 | + this.setT4_5(); | |
945 | 967 | this.loadB(this.regH); |
946 | 968 | }; |
947 | 969 | z80.code45=function(){ |
948 | 970 | //LD B,L |
949 | - this.setT4(); | |
971 | + this.setT4_5(); | |
950 | 972 | this.loadB(this.regL); |
951 | 973 | }; |
952 | 974 | z80.code46=function(){ |
@@ -956,37 +978,37 @@ z80.code46=function(){ | ||
956 | 978 | }; |
957 | 979 | z80.code47=function(){ |
958 | 980 | //LD B,A |
959 | - this.setT4(); | |
981 | + this.setT4_5(); | |
960 | 982 | this.loadB(this.regA); |
961 | 983 | }; |
962 | 984 | z80.code48=function(){ |
963 | 985 | //LD C,B |
964 | - this.setT4(); | |
986 | + this.setT4_5(); | |
965 | 987 | this.loadC(this.regB); |
966 | 988 | }; |
967 | 989 | z80.code49=function(){ |
968 | 990 | //LD C,C |
969 | - this.setT4(); | |
991 | + this.setT4_5(); | |
970 | 992 | this.loadC(this.regC); |
971 | 993 | }; |
972 | 994 | z80.code4A=function(){ |
973 | 995 | //LD C,D |
974 | - this.setT4(); | |
996 | + this.setT4_5(); | |
975 | 997 | this.loadC(this.regD); |
976 | 998 | }; |
977 | 999 | z80.code4B=function(){ |
978 | 1000 | //LD C,E |
979 | - this.setT4(); | |
1001 | + this.setT4_5(); | |
980 | 1002 | this.loadC(this.regE); |
981 | 1003 | }; |
982 | 1004 | z80.code4C=function(){ |
983 | 1005 | //LD C,H |
984 | - this.setT4(); | |
1006 | + this.setT4_5(); | |
985 | 1007 | this.loadC(this.regH); |
986 | 1008 | }; |
987 | 1009 | z80.code4D=function(){ |
988 | 1010 | //LD C,L |
989 | - this.setT4(); | |
1011 | + this.setT4_5(); | |
990 | 1012 | this.loadC(this.regL); |
991 | 1013 | }; |
992 | 1014 | z80.code4E=function(){ |
@@ -996,37 +1018,37 @@ z80.code4E=function(){ | ||
996 | 1018 | }; |
997 | 1019 | z80.code4F=function(){ |
998 | 1020 | //LD C,A |
999 | - this.setT4(); | |
1021 | + this.setT4_5(); | |
1000 | 1022 | this.loadC(this.regA); |
1001 | 1023 | }; |
1002 | 1024 | z80.code50=function(){ |
1003 | 1025 | //LD D,B |
1004 | - this.setT4(); | |
1026 | + this.setT4_5(); | |
1005 | 1027 | this.loadD(this.regB); |
1006 | 1028 | }; |
1007 | 1029 | z80.code51=function(){ |
1008 | 1030 | //LD D,C |
1009 | - this.setT4(); | |
1031 | + this.setT4_5(); | |
1010 | 1032 | this.loadD(this.regC); |
1011 | 1033 | }; |
1012 | 1034 | z80.code52=function(){ |
1013 | 1035 | //LD D,D |
1014 | - this.setT4(); | |
1036 | + this.setT4_5(); | |
1015 | 1037 | this.loadD(this.regD); |
1016 | 1038 | }; |
1017 | 1039 | z80.code53=function(){ |
1018 | 1040 | //LD D,E |
1019 | - this.setT4(); | |
1041 | + this.setT4_5(); | |
1020 | 1042 | this.loadD(this.regE); |
1021 | 1043 | }; |
1022 | 1044 | z80.code54=function(){ |
1023 | 1045 | //LD D,H |
1024 | - this.setT4(); | |
1046 | + this.setT4_5(); | |
1025 | 1047 | this.loadD(this.regH); |
1026 | 1048 | }; |
1027 | 1049 | z80.code55=function(){ |
1028 | 1050 | //LD D,L |
1029 | - this.setT4(); | |
1051 | + this.setT4_5(); | |
1030 | 1052 | this.loadD(this.regL); |
1031 | 1053 | }; |
1032 | 1054 | z80.code56=function(){ |
@@ -1036,37 +1058,37 @@ z80.code56=function(){ | ||
1036 | 1058 | }; |
1037 | 1059 | z80.code57=function(){ |
1038 | 1060 | //LD D,A |
1039 | - this.setT4(); | |
1061 | + this.setT4_5(); | |
1040 | 1062 | this.loadD(this.regA); |
1041 | 1063 | }; |
1042 | 1064 | z80.code58=function(){ |
1043 | 1065 | //LD E,B |
1044 | - this.setT4(); | |
1066 | + this.setT4_5(); | |
1045 | 1067 | this.loadE(this.regB); |
1046 | 1068 | }; |
1047 | 1069 | z80.code59=function(){ |
1048 | 1070 | //LD E,C |
1049 | - this.setT4(); | |
1071 | + this.setT4_5(); | |
1050 | 1072 | this.loadE(this.regC); |
1051 | 1073 | }; |
1052 | 1074 | z80.code5A=function(){ |
1053 | 1075 | //LD E,D |
1054 | - this.setT4(); | |
1076 | + this.setT4_5(); | |
1055 | 1077 | this.loadE(this.regD); |
1056 | 1078 | }; |
1057 | 1079 | z80.code5B=function(){ |
1058 | 1080 | //LD E,E |
1059 | - this.setT4(); | |
1081 | + this.setT4_5(); | |
1060 | 1082 | this.loadE(this.regE); |
1061 | 1083 | }; |
1062 | 1084 | z80.code5C=function(){ |
1063 | 1085 | //LD E,H |
1064 | - this.setT4(); | |
1086 | + this.setT4_5(); | |
1065 | 1087 | this.loadE(this.regH); |
1066 | 1088 | }; |
1067 | 1089 | z80.code5D=function(){ |
1068 | 1090 | //LD E,L |
1069 | - this.setT4(); | |
1091 | + this.setT4_5(); | |
1070 | 1092 | this.loadE(this.regL); |
1071 | 1093 | }; |
1072 | 1094 | z80.code5E=function(){ |
@@ -1076,37 +1098,37 @@ z80.code5E=function(){ | ||
1076 | 1098 | }; |
1077 | 1099 | z80.code5F=function(){ |
1078 | 1100 | //LD E,A |
1079 | - this.setT4(); | |
1101 | + this.setT4_5(); | |
1080 | 1102 | this.loadE(this.regA); |
1081 | 1103 | }; |
1082 | 1104 | z80.code60=function(){ |
1083 | 1105 | //LD H,B |
1084 | - this.setT4(); | |
1106 | + this.setT4_5(); | |
1085 | 1107 | this.loadH(this.regB); |
1086 | 1108 | }; |
1087 | 1109 | z80.code61=function(){ |
1088 | 1110 | //LD H,C |
1089 | - this.setT4(); | |
1111 | + this.setT4_5(); | |
1090 | 1112 | this.loadH(this.regC); |
1091 | 1113 | }; |
1092 | 1114 | z80.code62=function(){ |
1093 | 1115 | //LD H,D |
1094 | - this.setT4(); | |
1116 | + this.setT4_5(); | |
1095 | 1117 | this.loadH(this.regD); |
1096 | 1118 | }; |
1097 | 1119 | z80.code63=function(){ |
1098 | 1120 | //LD H,E |
1099 | - this.setT4(); | |
1121 | + this.setT4_5(); | |
1100 | 1122 | this.loadH(this.regE); |
1101 | 1123 | }; |
1102 | 1124 | z80.code64=function(){ |
1103 | 1125 | //LD H,H |
1104 | - this.setT4(); | |
1126 | + this.setT4_5(); | |
1105 | 1127 | this.loadH(this.regH); |
1106 | 1128 | }; |
1107 | 1129 | z80.code65=function(){ |
1108 | 1130 | //LD H,L |
1109 | - this.setT4(); | |
1131 | + this.setT4_5(); | |
1110 | 1132 | this.loadH(this.regL); |
1111 | 1133 | }; |
1112 | 1134 | z80.code66=function(){ |
@@ -1116,37 +1138,37 @@ z80.code66=function(){ | ||
1116 | 1138 | }; |
1117 | 1139 | z80.code67=function(){ |
1118 | 1140 | //LD H,A |
1119 | - this.setT4(); | |
1141 | + this.setT4_5(); | |
1120 | 1142 | this.loadH(this.regA); |
1121 | 1143 | }; |
1122 | 1144 | z80.code68=function(){ |
1123 | 1145 | //LD L,B |
1124 | - this.setT4(); | |
1146 | + this.setT4_5(); | |
1125 | 1147 | this.loadL(this.regB); |
1126 | 1148 | }; |
1127 | 1149 | z80.code69=function(){ |
1128 | 1150 | //LD L,C |
1129 | - this.setT4(); | |
1151 | + this.setT4_5(); | |
1130 | 1152 | this.loadL(this.regC); |
1131 | 1153 | }; |
1132 | 1154 | z80.code6A=function(){ |
1133 | 1155 | //LD L,D |
1134 | - this.setT4(); | |
1156 | + this.setT4_5(); | |
1135 | 1157 | this.loadL(this.regD); |
1136 | 1158 | }; |
1137 | 1159 | z80.code6B=function(){ |
1138 | 1160 | //LD L,E |
1139 | - this.setT4(); | |
1161 | + this.setT4_5(); | |
1140 | 1162 | this.loadL(this.regE); |
1141 | 1163 | }; |
1142 | 1164 | z80.code6C=function(){ |
1143 | 1165 | //LD L,H |
1144 | - this.setT4(); | |
1166 | + this.setT4_5(); | |
1145 | 1167 | this.loadL(this.regH); |
1146 | 1168 | }; |
1147 | 1169 | z80.code6D=function(){ |
1148 | 1170 | //LD L,L |
1149 | - this.setT4(); | |
1171 | + this.setT4_5(); | |
1150 | 1172 | this.loadL(this.regL); |
1151 | 1173 | }; |
1152 | 1174 | z80.code6E=function(){ |
@@ -1156,7 +1178,7 @@ z80.code6E=function(){ | ||
1156 | 1178 | }; |
1157 | 1179 | z80.code6F=function(){ |
1158 | 1180 | //LD L,A |
1159 | - this.setT4(); | |
1181 | + this.setT4_5(); | |
1160 | 1182 | this.loadL(this.regA); |
1161 | 1183 | }; |
1162 | 1184 | z80.code70=function(){ |
@@ -1191,7 +1213,7 @@ z80.code75=function(){ | ||
1191 | 1213 | }; |
1192 | 1214 | z80.code76=function(){ |
1193 | 1215 | //HALT |
1194 | - this.setT4(); | |
1216 | + this.setT4_7(); | |
1195 | 1217 | this.loadPC(this.regPC-1); |
1196 | 1218 | }; |
1197 | 1219 | z80.code77=function(){ |
@@ -1201,32 +1223,32 @@ z80.code77=function(){ | ||
1201 | 1223 | }; |
1202 | 1224 | z80.code78=function(){ |
1203 | 1225 | //LD A,B |
1204 | - this.setT4(); | |
1226 | + this.setT4_5(); | |
1205 | 1227 | this.loadA(this.regB); |
1206 | 1228 | }; |
1207 | 1229 | z80.code79=function(){ |
1208 | 1230 | //LD A,C |
1209 | - this.setT4(); | |
1231 | + this.setT4_5(); | |
1210 | 1232 | this.loadA(this.regC); |
1211 | 1233 | }; |
1212 | 1234 | z80.code7A=function(){ |
1213 | 1235 | //LD A,D |
1214 | - this.setT4(); | |
1236 | + this.setT4_5(); | |
1215 | 1237 | this.loadA(this.regD); |
1216 | 1238 | }; |
1217 | 1239 | z80.code7B=function(){ |
1218 | 1240 | //LD A,E |
1219 | - this.setT4(); | |
1241 | + this.setT4_5(); | |
1220 | 1242 | this.loadA(this.regE); |
1221 | 1243 | }; |
1222 | 1244 | z80.code7C=function(){ |
1223 | 1245 | //LD A,H |
1224 | - this.setT4(); | |
1246 | + this.setT4_5(); | |
1225 | 1247 | this.loadA(this.regH); |
1226 | 1248 | }; |
1227 | 1249 | z80.code7D=function(){ |
1228 | 1250 | //LD A,L |
1229 | - this.setT4(); | |
1251 | + this.setT4_5(); | |
1230 | 1252 | this.loadA(this.regL); |
1231 | 1253 | }; |
1232 | 1254 | z80.code7E=function(){ |
@@ -1236,7 +1258,7 @@ z80.code7E=function(){ | ||
1236 | 1258 | }; |
1237 | 1259 | z80.code7F=function(){ |
1238 | 1260 | //LD A,A |
1239 | - this.setT4(); | |
1261 | + this.setT4_5(); | |
1240 | 1262 | this.loadA(this.regA); |
1241 | 1263 | }; |
1242 | 1264 | z80.code80=function(){ |
@@ -1598,7 +1620,7 @@ z80.codeC4=function(){ | ||
1598 | 1620 | var i8=this.getCode(); |
1599 | 1621 | var i16=this.getCode(); |
1600 | 1622 | if (this.flagZ){ |
1601 | - this.setT10(); | |
1623 | + this.setT10_11(); | |
1602 | 1624 | } else { |
1603 | 1625 | this.setT17(); |
1604 | 1626 | this.loadSP(this.regSP-2); |
@@ -1667,7 +1689,7 @@ z80.codeCC=function(){ | ||
1667 | 1689 | memory.write(this.regSP+1,this.regPC>>8); |
1668 | 1690 | this.loadPC((i16<<8)|i8); |
1669 | 1691 | } else { |
1670 | - this.setT10(); | |
1692 | + this.setT10_11(); | |
1671 | 1693 | } |
1672 | 1694 | }; |
1673 | 1695 | z80.codeCD=function(){ |
@@ -1722,7 +1744,7 @@ z80.codeD2=function(){ | ||
1722 | 1744 | }; |
1723 | 1745 | z80.codeD3=function(){ |
1724 | 1746 | //OUT (n),A |
1725 | - this.setT11(); | |
1747 | + this.setT11_10(); | |
1726 | 1748 | io.write(this.getCode(),this.regA,this.regA); |
1727 | 1749 | }; |
1728 | 1750 | z80.codeD4=function(){ |
@@ -1730,7 +1752,7 @@ z80.codeD4=function(){ | ||
1730 | 1752 | var i8=this.getCode(); |
1731 | 1753 | var i16=this.getCode(); |
1732 | 1754 | if (this.flagC){ |
1733 | - this.setT10(); | |
1755 | + this.setT10_11(); | |
1734 | 1756 | } else { |
1735 | 1757 | this.setT17(); |
1736 | 1758 | this.loadSP(this.regSP-2); |
@@ -1794,7 +1816,7 @@ z80.codeDA=function(){ | ||
1794 | 1816 | }; |
1795 | 1817 | z80.codeDB=function(){ |
1796 | 1818 | //IN A,n |
1797 | - this.setT11(); | |
1819 | + this.setT11_10(); | |
1798 | 1820 | this.loadA(io.read(this.getCode(), this.regA)); |
1799 | 1821 | }; |
1800 | 1822 | z80.codeDC=function(){ |
@@ -1808,7 +1830,7 @@ z80.codeDC=function(){ | ||
1808 | 1830 | memory.write(this.regSP+1,this.regPC>>8); |
1809 | 1831 | this.loadPC((i16<<8)|i8); |
1810 | 1832 | } else { |
1811 | - this.setT10(); | |
1833 | + this.setT10_11(); | |
1812 | 1834 | } |
1813 | 1835 | }; |
1814 | 1836 | z80.codeDE=function(){ |
@@ -1853,7 +1875,7 @@ z80.codeE2=function(){ | ||
1853 | 1875 | }; |
1854 | 1876 | z80.codeE3=function(){ |
1855 | 1877 | //EX (SP),HL |
1856 | - this.setT19(); | |
1878 | + this.setT19_18(); | |
1857 | 1879 | var i16=memory.read(this.regSP+1)<<8; |
1858 | 1880 | i16|=memory.read(this.regSP); |
1859 | 1881 | memory.write(this.regSP,this.regL); |
@@ -1865,7 +1887,7 @@ z80.codeE4=function(){ | ||
1865 | 1887 | var i8=this.getCode(); |
1866 | 1888 | var i16=this.getCode(); |
1867 | 1889 | if (this.flagP){ |
1868 | - this.setT10(); | |
1890 | + this.setT10_11(); | |
1869 | 1891 | } else { |
1870 | 1892 | this.setT17(); |
1871 | 1893 | this.loadSP(this.regSP-2); |
@@ -1909,7 +1931,7 @@ z80.codeE8=function(){ | ||
1909 | 1931 | }; |
1910 | 1932 | z80.codeE9=function(){ |
1911 | 1933 | //JP (HL) |
1912 | - this.setT4(); | |
1934 | + this.setT4_5(); | |
1913 | 1935 | this.loadPC(this.regHL); |
1914 | 1936 | }; |
1915 | 1937 | z80.codeEA=function(){ |
@@ -1937,7 +1959,7 @@ z80.codeEC=function(){ | ||
1937 | 1959 | memory.write(this.regSP+1,this.regPC>>8); |
1938 | 1960 | this.loadPC((i16<<8)|i8); |
1939 | 1961 | } else { |
1940 | - this.setT10(); | |
1962 | + this.setT10_11(); | |
1941 | 1963 | } |
1942 | 1964 | }; |
1943 | 1965 | z80.codeEE=function(){ |
@@ -1992,7 +2014,7 @@ z80.codeF4=function(){ | ||
1992 | 2014 | var i8=this.getCode(); |
1993 | 2015 | var i16=this.getCode(); |
1994 | 2016 | if (this.flagS){ |
1995 | - this.setT10(); | |
2017 | + this.setT10_11(); | |
1996 | 2018 | } else { |
1997 | 2019 | this.setT17(); |
1998 | 2020 | this.loadSP(this.regSP-2); |
@@ -2036,7 +2058,7 @@ z80.codeF8=function(){ | ||
2036 | 2058 | }; |
2037 | 2059 | z80.codeF9=function(){ |
2038 | 2060 | //LD SP,HL |
2039 | - this.setT6(); | |
2061 | + this.setT6_5(); | |
2040 | 2062 | this.loadSP(this.regHL); |
2041 | 2063 | }; |
2042 | 2064 | z80.codeFA=function(){ |
@@ -2063,7 +2085,7 @@ z80.codeFC=function(){ | ||
2063 | 2085 | memory.write(this.regSP+1,this.regPC>>8); |
2064 | 2086 | this.loadPC((i16<<8)|i8); |
2065 | 2087 | } else { |
2066 | - this.setT10(); | |
2088 | + this.setT10_11(); | |
2067 | 2089 | } |
2068 | 2090 | }; |
2069 | 2091 | z80.codeFE=function(){ |
@@ -5001,7 +5023,7 @@ for (i=16;i<256;i++) { | ||
5001 | 5023 | eval("z80.codeFDCBVector["+i+"]=function(i16){ z80.codeFDCB"+i.toString(16).toUpperCase()+"(i16); };"); |
5002 | 5024 | } |
5003 | 5025 | z80.exec=function(msec){ |
5004 | - var i; | |
5026 | + var i,code; | |
5005 | 5027 | for (i=msec;0<i;i--) { |
5006 | 5028 | while (this.clk<this.speed || this.step) { |
5007 | 5029 | if (this.regPC==this.breakPoint) { |
@@ -5009,43 +5031,56 @@ z80.exec=function(msec){ | ||
5009 | 5031 | this.step=1; |
5010 | 5032 | return; |
5011 | 5033 | } |
5012 | - this.codeVector[this.getCode()](); | |
5034 | + this.m1=true; | |
5035 | + code=this.getCode(); | |
5036 | + this.m1=false; | |
5037 | + this.codeVector[code](); | |
5013 | 5038 | if (this.irq) this.doInt(); |
5014 | 5039 | if (this.step) return; |
5040 | + // Increment R register here | |
5041 | + this.loadR(this.regR+1); | |
5015 | 5042 | } |
5016 | 5043 | this.clk-=this.speed; |
5017 | 5044 | this.events(); |
5018 | 5045 | } |
5019 | 5046 | }; |
5020 | 5047 | z80.codeCB=function(){ |
5048 | + // Increment R register here | |
5049 | + this.loadR(this.regR+1); | |
5021 | 5050 | try { |
5022 | 5051 | this.codeCBVector[this.getCode()](); |
5023 | 5052 | } catch(e) { |
5024 | - alert(e); | |
5053 | + console.log(e); | |
5025 | 5054 | this.codeVOID(); |
5026 | 5055 | } |
5027 | 5056 | }; |
5028 | 5057 | z80.codeDD=function(){ |
5058 | + // Increment R register here | |
5059 | + this.loadR(this.regR+1); | |
5029 | 5060 | try { |
5030 | 5061 | this.codeDDVector[this.getCode()](); |
5031 | 5062 | } catch(e) { |
5032 | - alert(e); | |
5063 | + console.log(e); | |
5033 | 5064 | this.codeVOID(); |
5034 | 5065 | } |
5035 | 5066 | }; |
5036 | 5067 | z80.codeED=function(){ |
5068 | + // Increment R register here | |
5069 | + this.loadR(this.regR+1); | |
5037 | 5070 | try { |
5038 | 5071 | this.codeEDVector[this.getCode()](); |
5039 | 5072 | } catch(e) { |
5040 | - alert(e); | |
5073 | + console.log(e); | |
5041 | 5074 | this.codeVOID(); |
5042 | 5075 | } |
5043 | 5076 | }; |
5044 | 5077 | z80.codeFD=function(){ |
5078 | + // Increment R register here | |
5079 | + this.loadR(this.regR+1); | |
5045 | 5080 | try { |
5046 | 5081 | this.codeFDVector[this.getCode()](); |
5047 | 5082 | } catch(e) { |
5048 | - alert(e); | |
5083 | + console.log(e); | |
5049 | 5084 | this.codeVOID(); |
5050 | 5085 | } |
5051 | 5086 | }; |
@@ -5054,7 +5089,7 @@ z80.codeDDCB=function(){ | ||
5054 | 5089 | try { |
5055 | 5090 | this.codeDDCBVector[this.getCode()](i16); |
5056 | 5091 | } catch(e) { |
5057 | - alert(e); | |
5092 | + console.log(e); | |
5058 | 5093 | this.codeVOID(); |
5059 | 5094 | } |
5060 | 5095 | }; |
@@ -5063,7 +5098,7 @@ z80.codeFDCB=function(){ | ||
5063 | 5098 | try { |
5064 | 5099 | this.codeFDCBVector[this.getCode()](i16); |
5065 | 5100 | } catch(e) { |
5066 | - alert(e); | |
5101 | + console.log(e); | |
5067 | 5102 | this.codeVOID(); |
5068 | 5103 | } |
5069 | 5104 | }; |
@@ -1,8 +1,9 @@ | ||
1 | -/********************************* | |
2 | -* CP/KM web written by Katsumi * | |
3 | -* This script is released * | |
4 | -* under the LGPL v2.1. * | |
5 | -*********************************/ | |
1 | +/********************************** | |
2 | +* Z80 emulator written by Katsumi * | |
3 | +* ver 0.80 * | |
4 | +* This script is released * | |
5 | +* under the LGPL v2.1. * | |
6 | +**********************************/ | |
6 | 7 | |
7 | 8 | /* |
8 | 9 | Additional methods used for emulating Z80 CPU |