01-20-2014, 06:35 AM
My emulator is a very poor implementation, use Mark's CHIP8 app available here: http://www.hpmuseum.org/forum/thread-475...l#pid39757
___________________________________________
Hi!
Here is a small tease of the emulator:
With the upcoming Primecomm version loading any chip8 ROM will be just like sending the rom directly with on-the-fly conversion
CHIP-8 is a very old simple language/virtual machine: http://en.wikipedia.org/wiki/CHIP-8
Only 4K memory, but great start point into emulation!
Here are some ROMs:
PONG2
SPACE INVADERS
TETRIS
Download all: [attachment=176]
NOTE: The keyboard is mapped to http://cl.ly/TTBD there are still few glitches in the emulation. Drawing speed can be optimized further.
___________________________________________
Hi!
Here is a small tease of the emulator:
With the upcoming Primecomm version loading any chip8 ROM will be just like sending the rom directly with on-the-fly conversion
CHIP-8 is a very old simple language/virtual machine: http://en.wikipedia.org/wiki/CHIP-8
Only 4K memory, but great start point into emulation!
Here are some ROMs:
PONG2
Code:
local b5:={#22h,#FCh,#6Bh,#0Ch,#6Ch,#3Fh,#6Dh,#0Ch,#A2h,#EAh,#DAh,#B6h,#DCh,#D6h,#6Eh,#00h,#22h,#D4h,#66h,#03h,#68h,#02h,#60h,#60h,#F0h,#15h,#F0h,#07h,#30h,#00h,#12h,#1Ah,#C7h,#17h,#77h,#08h,#69h,#FFh,#A2h,#F0h,#D6h,#71h,#A2h,#EAh,#DAh,#B6h,#DCh,#D6h,#60h,#01h,#E0h,#A1h,#7Bh,#FEh,#60h,#04h,#E0h,#A1h,#7Bh,#02h,#60h,#1Fh,#8Bh,#02h,#DAh,#B6h,#60h,#0Ch,#E0h,#A1h,#7Dh,#FEh,#60h,#0Dh,#E0h,#A1h,#7Dh,#02h,#60h,#1Fh,#8Dh,#02h,#DCh,#D6h,#A2h,#F0h,#D6h,#71h,#86h,#84h,#87h,#94h,#60h,#3Fh,#86h,#02h,#61h,#1Fh,#87h,#12h,#46h,#00h,#12h,#78h,#46h,#3Fh,#12h,#82h,#47h,#1Fh,#69h,#FFh,#47h,#00h,#69h,#01h,#D6h,#71h,#12h,#2Ah,#68h,#02h,#63h,#01h,#80h,#70h,#80h,#B5h,#12h,#8Ah,#68h,#FEh,#63h,#0Ah,#80h,#70h,#80h,#D5h,#3Fh,#01h,#12h,#A2h,#61h,#02h,#80h,#15h,#3Fh,#01h,#12h,#BAh,#80h,#15h,#3Fh,#01h,#12h,#C8h,#80h,#15h,#3Fh,#01h,#12h,#C2h,#60h,#20h,#F0h,#18h,#22h,#D4h,#8Eh,#34h,#22h,#D4h,#66h,#3Eh,#33h,#01h,#66h,#03h,#68h,#FEh,#33h,#01h,#68h,#02h,#12h,#16h,#79h,#FFh,#49h,#FEh,#69h,#FFh,#12h,#C8h,#79h,#01h,#49h,#02h,#69h,#01h,#60h,#04h,#F0h,#18h,#76h,#01h,#46h,#40h,#76h,#FEh,#12h,#6Ch,#A2h,#F2h,#FEh,#33h,#F2h,#65h,#F1h,#29h,#64h,#14h,#65h,#02h,#D4h,#55h,#74h,#15h,#F2h,#29h,#D4h,#55h,#00h,#EEh,#80h,#80h,#80h,#80h,#80h,#80h,#80h,#00h,#00h,#00h,#00h,#00h,#C0h,#C0h,#C0h,#00h,#FFh,#00h,#6Bh,#20h,#6Ch,#00h,#A2h,#F6h,#DBh,#C4h,#7Ch,#04h,#3Ch,#20h,#13h,#02h,#6Ah,#00h,#6Bh,#00h,#6Ch,#1Fh,#A2h,#FAh,#DAh,#B1h,#DAh,#C1h,#7Ah,#08h,#3Ah,#40h,#13h,#12h,#A2h,#F6h,#6Ah,#00h,#6Bh,#20h,#DBh,#A1h,#00h,#EEh};local j9:={#F0h,#90h,#90h,#90h,#F0h,#20h,#60h,#20h,#20h,#70h,#F0h,#10h,#F0h,#80h,#F0h,#F0h,#10h,#F0h,#10h,#F0h,#90h,#90h,#F0h,#10h,#10h,#F0h,#80h,#F0h,#10h,#F0h,#F0h,#80h,#F0h,#90h,#F0h,#F0h,#10h,#20h,#40h,#40h,#F0h,#90h,#F0h,#90h,#F0h,#F0h,#90h,#F0h,#10h,#F0h,#F0h,#90h,#F0h,#90h,#90h,#E0h,#90h,#E0h,#90h,#E0h,#F0h,#80h,#80h,#80h,#F0h,#E0h,#90h,#90h,#90h,#E0h,#F0h,#80h,#F0h,#80h,#F0h,#F0h,#80h,#F0h,#80h,#80h};local b8;local b2;local m9,sp;local b3;local pc,l9,k9,e9,d9;local c9;local c9Width:=64;local updateScreen;clearScreen()BEGIN updateScreen:=1;c9:=MAKELIST(0,X,1,2048);END;init()BEGIN DIMGROB_P(G1,5,5,{#0:64h,#0:64h,#0:64h,#0:64h,#0:64h,#0:64h,#0:64h});DIMGROB_P(G2,5,5,{#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF:64h});clearScreen();m9:=MAKELIST(#0h,X,1,16);sp:=1;b2:=MAKELIST(#0h,X,1,16);b3:=MAKELIST(0,X,1,16);pc:=#200h;l9:=0;k9:=0;b8:=SUB(CONCAT(j9,MAKELIST(#0h,X,1,432),b5,MAKELIST(#0h,X,1,3583)),1,4096);END;errorOpcode()BEGIN msgbox("Fatal error: UNKNOWN OPCODE ("+e9+")");END;cpuCycle()BEGIN e9:=BITXOR(b8(pc+2),BITSL(b8(pc+1),8));d9:=BITAND(e9,#F000h);local q9;CASE IF d9==#0000h THEN CASE IF e9==#00E0 THEN clearScreen();pc:=pc+2;END;IF e9==#00EE THEN sp:=sp-1;pc:=m9(sp);pc:=pc+2;END;DEFAULT errorOpcode();END;END;IF d9==#1000h THEN pc:=BITAND(e9,#0FFFh);END;IF d9==#2000h THEN m9(sp):=pc;sp:=sp+1;pc:=BITAND(e9,#0FFFh);END;IF d9==#3000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==BITAND(e9,#00FF),4,2)END;IF d9==#4000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==BITAND(e9,#00FF),2,4)END;IF d9==#5000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==b2(BITSR(BITAND(e9,#00F0h),4)+1),4,2)END;IF d9==#6000h THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=BITAND(e9,#00FFh);pc:=pc+2;END;IF d9==#7000h THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=(b2(q9)+BITAND(e9,#00FFh))MOD 256;pc:=pc+2;END;IF d9==#8000h THEN d9:=BITAND(e9,#000Fh);CASE IF d9==#0000 THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=b2(BITSR(BITAND(e9,#00F0h),4)+1);pc:=pc+2;END;IF d9==#0001 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=BITOR(b2(q9),b2(BITSR(BITAND(e9,#00F0h),4)+1));pc:=pc+2;END;IF d9==#0002 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=BITAND(b2(q9),b2(BITSR(BITAND(e9,#00F0h),4)+1));pc:=pc+2;END;IF d9==#0003 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=BITXOR(b2(q9),b2(BITSR(BITAND(e9,#00F0h),4)+1));pc:=pc+2;END;IF d9==#0004 THEN b2(16):=b2(BITSR(BITAND(e9,#00F0h),4)+1)>(#FFh-b2(BITSR(BITAND(e9,#0F00h),8)+1));q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=(b2(q9)+b2(BITSR(BITAND(e9,#00F0h),4)+1))MOD 256;pc:=pc+2;END;IF d9==#0005 THEN b2(16):=b2(BITSR(BITAND(e9,#00F0h),4)+1)>b2(BITSR(BITAND(e9,#0F00h),8)+1);q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=b2(q9)-b2(BITSR(BITAND(e9,#00F0h),4)+1);pc:=pc+2;END;IF d9==#0006 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(16):=BITAND(b2(q9),#1h);b2(q9):=BITSR(b2(q9),1);pc:=pc+2;END;IF d9==#0007 THEN b2(16):=b2(BITSR(BITAND(e9,#0F00h),8)+1)<=b2(BITSR(BITAND(e9,#00F0h),4)+1);q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=(b2(BITSR(BITAND(e9,#00F0h),4)+1)-b2(q9))MOD 256;pc:=pc+2;END;IF d9==#000E THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(16):=BITSR(b2(q9),7);b2(q9):=BITSL(b2(q9),1);pc:=pc+2;END;DEFAULT errorOpcode();END;END;IF d9==#9000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==b2(BITSR(BITAND(e9,#00F0),4)+1),2,4);END;IF d9==#A000h THEN k9:=BITAND(e9,#0FFFh);pc:=pc+2;END;IF d9==#B000h THEN pc:=BITAND(e9,#0FFFh)+b2(1);END;IF d9==#C000h THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=BITAND(RANDINT(#FFh),BITAND(e9,#00FFh));pc:=pc+2;END;IF d9==#D000h THEN local c9X,c9Y,b9,n9,f9,g9,q9;c9X:=b2(BITSR(BITAND(e9,#0F00h),8)+1);c9Y:=b2(BITSR(BITAND(e9,#00F0h),4)+1);b9:=BITAND(e9,#000F);b2(16):=0;FOR f9 FROM 0 TO b9-1 DO n9:=b8(k9+f9+1);FOR g9 FROM 0 TO 7 DO IF BITAND(n9,BITSR(#80h,g9))<>0 THEN q9:=c9X+g9+((c9Y+f9)*c9Width)+1;IF c9(q9)THEN b2(16):=1;END;c9(q9):=NOT c9(q9);END;END;END;updateScreen:=1;pc:=pc+2;END;IF d9==#E000h THEN q9:=b3((b2((BITSR(BITAND(e9,#0F00h),8)+1))+1));d9:=BITAND(e9,#00FFh);CASE IF d9==#009Eh THEN pc:=pc+IFTE(q9<>0,4,2);END;IF d9==#00A1h THEN pc:=pc+IFTE(q9==0,4,2);END;DEFAULT errorOpcode();END;END;IF d9==#F000h THEN d9:=BITAND(e9,#00FFh);CASE IF d9==#0007h THEN b2(BITSR(BITAND(e9,#0F00),8)+1):=l9;pc:=pc+2;END;IF d9==#000Ah THEN local b6:=0;FOR q9 FROM 1 TO 16 DO IF b3(q9)THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=q9-1;b6:=1;BREAK;END;END;IF b6==0 THEN RETURN;END;pc:=pc+2;END;IF d9==#0015h THEN l9:=b2(BITSR(BITAND(e9,#0F00h),8)+1);pc:=pc+2;END;IF d9==#0018h THEN pc:=pc+2;END;IF d9==#001Eh THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(16):=k9+b2(q9)> #0FFFh;k9:=k9+b2(q9);pc:=pc+2;END;IF d9==#0029h THEN k9:=b2(BITSR(BITAND(e9,#0F00h),8)+1)*5;pc:=pc+2;END;IF d9==#0033h THEN q9:=b2(BITSR(BITAND(e9,#0F00h),8)+1);b8(k9+1):=IP(q9/100);b8(k9+2):=IP((q9/10)MOD 10);b8(k9+3):=IP((q9 MOD 100)MOD 10);pc:=pc+2;END;IF d9==#0055h THEN FOR q9 FROM 0 TO BITSR(BITAND(e9,#0F00h),8)DO b8(k9+q9+1):=b2(q9+1);END;k9:=k9+BITSR(BITAND(e9,#0F00),8)+1;pc:=pc+2;END;IF d9==#0065h THEN FOR q9 FROM 0 TO BITSR(BITAND(e9,#0F00h),8)DO b2(q9+1):=b8(k9+q9+1);END;k9:=k9+BITSR(BITAND(e9,#0F00),8)+1;pc:=pc+2;END;DEFAULT errorOpcode();END;END;DEFAULT errorOpcode();END;IF l9>0 THEN l9:=l9-1;END;END;loop()BEGIN cpuCycle();IF(updateScreen)THEN local o9,p9,i9,p95;FOR p9 FROM 1 TO 32 DO i9:=(p9-1)*c9Width;p95:=((p9-1)*5)+40;FOR o9 FROM 1 TO 64 DO BLIT_P((o9-1)*5,p95,IFTE(c9(o9+i9),G1,G2));END;END;updateScreen:=0;END;END;EXPORT pong2()BEGIN RECT(#000000);IF(SIZE(b5)>4096-512)THEN MSGBOX("ROM is too big for the RAM, it might not run properly");END;init();REPEAT loop();b3(1):=ISKEYDOWN(32);b3(2):=ISKEYDOWN(33);b3(3):=ISKEYDOWN(34);b3(4):=ISKEYDOWN(37);b3(5):=ISKEYDOWN(38);b3(6):=ISKEYDOWN(39);b3(7):=ISKEYDOWN(42);b3(8):=ISKEYDOWN(43);b3(9):=ISKEYDOWN(44);b3(10):=ISKEYDOWN(48);b3(11):=ISKEYDOWN(47);b3(12):=ISKEYDOWN(49);b3(13):=ISKEYDOWN(35);b3(14):=ISKEYDOWN(40);b3(15):=ISKEYDOWN(45);b3(16):=ISKEYDOWN(50);UNTIL 0;END;
SPACE INVADERS
Code:
local b5:={#12h,#25h,#53h,#50h,#41h,#43h,#45h,#20h,#49h,#4Eh,#56h,#41h,#44h,#45h,#52h,#53h,#20h,#30h,#2Eh,#39h,#31h,#20h,#42h,#79h,#20h,#44h,#61h,#76h,#69h,#64h,#20h,#57h,#49h,#4Eh,#54h,#45h,#52h,#60h,#00h,#61h,#00h,#62h,#08h,#A3h,#DDh,#D0h,#18h,#71h,#08h,#F2h,#1Eh,#31h,#20h,#12h,#2Dh,#70h,#08h,#61h,#00h,#30h,#40h,#12h,#2Dh,#69h,#05h,#6Ch,#15h,#6Eh,#00h,#23h,#91h,#60h,#0Ah,#F0h,#15h,#F0h,#07h,#30h,#00h,#12h,#4Bh,#23h,#91h,#7Eh,#01h,#12h,#45h,#66h,#00h,#68h,#1Ch,#69h,#00h,#6Ah,#04h,#6Bh,#0Ah,#6Ch,#04h,#6Dh,#3Ch,#6Eh,#0Fh,#00h,#E0h,#23h,#75h,#23h,#51h,#FDh,#15h,#60h,#04h,#E0h,#9Eh,#12h,#7Dh,#23h,#75h,#38h,#00h,#78h,#FFh,#23h,#75h,#60h,#06h,#E0h,#9Eh,#12h,#8Bh,#23h,#75h,#38h,#39h,#78h,#01h,#23h,#75h,#36h,#00h,#12h,#9Fh,#60h,#05h,#E0h,#9Eh,#12h,#E9h,#66h,#01h,#65h,#1Bh,#84h,#80h,#A3h,#D9h,#D4h,#51h,#A3h,#D9h,#D4h,#51h,#75h,#FFh,#35h,#FFh,#12h,#ADh,#66h,#00h,#12h,#E9h,#D4h,#51h,#3Fh,#01h,#12h,#E9h,#D4h,#51h,#66h,#00h,#83h,#40h,#73h,#03h,#83h,#B5h,#62h,#F8h,#83h,#22h,#62h,#08h,#33h,#00h,#12h,#C9h,#23h,#7Dh,#82h,#06h,#43h,#08h,#12h,#D3h,#33h,#10h,#12h,#D5h,#23h,#7Dh,#82h,#06h,#33h,#18h,#12h,#DDh,#23h,#7Dh,#82h,#06h,#43h,#20h,#12h,#E7h,#33h,#28h,#12h,#E9h,#23h,#7Dh,#3Eh,#00h,#13h,#07h,#79h,#06h,#49h,#18h,#69h,#00h,#6Ah,#04h,#6Bh,#0Ah,#6Ch,#04h,#7Dh,#F4h,#6Eh,#0Fh,#00h,#E0h,#23h,#51h,#23h,#75h,#FDh,#15h,#12h,#6Fh,#F7h,#07h,#37h,#00h,#12h,#6Fh,#FDh,#15h,#23h,#51h,#8Bh,#A4h,#3Bh,#12h,#13h,#1Bh,#7Ch,#02h,#6Ah,#FCh,#3Bh,#02h,#13h,#23h,#7Ch,#02h,#6Ah,#04h,#23h,#51h,#3Ch,#18h,#12h,#6Fh,#00h,#E0h,#A4h,#DDh,#60h,#14h,#61h,#08h,#62h,#0Fh,#D0h,#1Fh,#70h,#08h,#F2h,#1Eh,#30h,#2Ch,#13h,#33h,#60h,#FFh,#F0h,#15h,#F0h,#07h,#30h,#00h,#13h,#41h,#F0h,#0Ah,#00h,#E0h,#A7h,#06h,#FEh,#65h,#12h,#25h,#A3h,#C1h,#F9h,#1Eh,#61h,#08h,#23h,#69h,#81h,#06h,#23h,#69h,#81h,#06h,#23h,#69h,#81h,#06h,#23h,#69h,#7Bh,#D0h,#00h,#EEh,#80h,#E0h,#80h,#12h,#30h,#00h,#DBh,#C6h,#7Bh,#0Ch,#00h,#EEh,#A3h,#D9h,#60h,#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#00h,#FFh,#00h,#00h,#FFh,#00h,#EFh,#20h,#28h,#E8h,#E8h,#2Fh,#2Fh,#00h,#00h,#F9h,#85h,#C5h,#C5h,#C5h,#C5h,#F9h,#00h,#00h,#FFh,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#FFh,#00h,#00h,#FFh,#00h,#BEh,#00h,#20h,#30h,#20h,#BEh,#BEh,#00h,#00h,#F7h,#04h,#E7h,#85h,#85h,#84h,#F4h,#00h,#00h,#FFh,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#FFh,#00h,#00h,#FFh,#00h,#00h,#7Fh,#00h,#3Fh,#00h,#7Fh,#00h,#00h,#00h,#EFh,#28h,#EFh,#00h,#E0h,#60h,#6Fh,#00h,#00h,#FFh,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#FFh,#00h,#00h,#FFh,#00h,#00h,#FEh,#00h,#FCh,#00h,#FEh,#00h,#00h,#00h,#C0h,#00h,#C0h,#C0h,#C0h,#C0h,#C0h,#00h,#00h,#FCh,#04h,#04h,#04h,#04h,#04h,#04h,#04h,#04h,#FCh,#10h,#10h,#FFh,#F9h,#81h,#B9h,#8Bh,#9Ah,#9Ah,#FAh,#00h,#FAh,#8Ah,#9Ah,#9Ah,#9Bh,#99h,#F8h,#E6h,#25h,#25h,#F4h,#34h,#34h,#34h,#00h,#17h,#14h,#34h,#37h,#36h,#26h,#C7h,#DFh,#50h,#50h,#5Ch,#D8h,#D8h,#DFh,#00h,#DFh,#11h,#1Fh,#12h,#1Bh,#19h,#D9h,#7Ch,#44h,#FEh,#86h,#86h,#86h,#FCh,#84h,#FEh,#82h,#82h,#FEh,#FEh,#80h,#C0h,#C0h,#C0h,#FEh,#FCh,#82h,#C2h,#C2h,#C2h,#FCh,#FEh,#80h,#F8h,#C0h,#C0h,#FEh,#FEh,#80h,#F0h,#C0h,#C0h,#C0h,#FEh,#80h,#BEh,#86h,#86h,#FEh,#86h,#86h,#FEh,#86h,#86h,#86h,#10h,#10h,#10h,#10h,#10h,#10h,#18h,#18h,#18h,#48h,#48h,#78h,#9Ch,#90h,#B0h,#C0h,#B0h,#9Ch,#80h,#80h,#C0h,#C0h,#C0h,#FEh,#EEh,#92h,#92h,#86h,#86h,#86h,#FEh,#82h,#86h,#86h,#86h,#86h,#7Ch,#82h,#86h,#86h,#86h,#7Ch,#FEh,#82h,#FEh,#C0h,#C0h,#C0h,#7Ch,#82h,#C2h,#CAh,#C4h,#7Ah,#FEh,#86h,#FEh,#90h,#9Ch,#84h,#FEh,#C0h,#FEh,#02h,#02h,#FEh,#FEh,#10h,#30h,#30h,#30h,#30h,#82h,#82h,#C2h,#C2h,#C2h,#FEh,#82h,#82h,#82h,#EEh,#38h,#10h,#86h,#86h,#96h,#92h,#92h,#EEh,#82h,#44h,#38h,#38h,#44h,#82h,#82h,#82h,#FEh,#30h,#30h,#30h,#FEh,#02h,#1Eh,#F0h,#80h,#FEh,#00h,#00h,#00h,#00h,#06h,#06h,#00h,#00h,#00h,#60h,#60h,#C0h,#00h,#00h,#00h,#00h,#00h,#00h,#18h,#18h,#18h,#18h,#00h,#18h,#7Ch,#C6h,#0Ch,#18h,#00h,#18h,#00h,#00h,#FEh,#FEh,#00h,#00h,#FEh,#82h,#86h,#86h,#86h,#FEh,#08h,#08h,#08h,#18h,#18h,#18h,#FEh,#02h,#FEh,#C0h,#C0h,#FEh,#FEh,#02h,#1Eh,#06h,#06h,#FEh,#84h,#C4h,#C4h,#FEh,#04h,#04h,#FEh,#80h,#FEh,#06h,#06h,#FEh,#C0h,#C0h,#C0h,#FEh,#82h,#FEh,#FEh,#02h,#02h,#06h,#06h,#06h,#7Ch,#44h,#FEh,#86h,#86h,#FEh,#FEh,#82h,#FEh,#06h,#06h,#06h,#44h,#FEh,#44h,#44h,#FEh,#44h,#A8h,#A8h,#A8h,#A8h,#A8h,#A8h,#A8h,#6Ch,#5Ah,#00h,#0Ch,#18h,#A8h,#30h,#4Eh,#7Eh,#00h,#12h,#18h,#66h,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,#3Ch,#A8h,#AEh,#A8h,#A8h,#A8h,#A8h,#A8h,#A8h,#A8h,#FFh,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h};local j9:={#F0h,#90h,#90h,#90h,#F0h,#20h,#60h,#20h,#20h,#70h,#F0h,#10h,#F0h,#80h,#F0h,#F0h,#10h,#F0h,#10h,#F0h,#90h,#90h,#F0h,#10h,#10h,#F0h,#80h,#F0h,#10h,#F0h,#F0h,#80h,#F0h,#90h,#F0h,#F0h,#10h,#20h,#40h,#40h,#F0h,#90h,#F0h,#90h,#F0h,#F0h,#90h,#F0h,#10h,#F0h,#F0h,#90h,#F0h,#90h,#90h,#E0h,#90h,#E0h,#90h,#E0h,#F0h,#80h,#80h,#80h,#F0h,#E0h,#90h,#90h,#90h,#E0h,#F0h,#80h,#F0h,#80h,#F0h,#F0h,#80h,#F0h,#80h,#80h};local b8;local b2;local m9,sp;local b3;local pc,l9,k9,e9,d9;local c9;local c9Width:=64;local updateScreen;clearScreen()BEGIN updateScreen:=1;c9:=MAKELIST(0,X,1,2048);END;init()BEGIN DIMGROB_P(G1,5,5,{#0:64h,#0:64h,#0:64h,#0:64h,#0:64h,#0:64h,#0:64h});DIMGROB_P(G2,5,5,{#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF:64h});clearScreen();m9:=MAKELIST(#0h,X,1,16);sp:=1;b2:=MAKELIST(#0h,X,1,16);b3:=MAKELIST(0,X,1,16);pc:=#200h;l9:=0;k9:=0;b8:=SUB(CONCAT(j9,MAKELIST(#0h,X,1,432),b5,MAKELIST(#0h,X,1,3583)),1,4096);END;errorOpcode()BEGIN msgbox("Fatal error: UNKNOWN OPCODE ("+e9+")");END;cpuCycle()BEGIN e9:=BITXOR(b8(pc+2),BITSL(b8(pc+1),8));d9:=BITAND(e9,#F000h);local q9;CASE IF d9==#0000h THEN CASE IF e9==#00E0 THEN clearScreen();pc:=pc+2;END;IF e9==#00EE THEN sp:=sp-1;pc:=m9(sp);pc:=pc+2;END;DEFAULT errorOpcode();END;END;IF d9==#1000h THEN pc:=BITAND(e9,#0FFFh);END;IF d9==#2000h THEN m9(sp):=pc;sp:=sp+1;pc:=BITAND(e9,#0FFFh);END;IF d9==#3000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==BITAND(e9,#00FF),4,2)END;IF d9==#4000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==BITAND(e9,#00FF),2,4)END;IF d9==#5000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==b2(BITSR(BITAND(e9,#00F0h),4)+1),4,2)END;IF d9==#6000h THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=BITAND(e9,#00FFh);pc:=pc+2;END;IF d9==#7000h THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=(b2(q9)+BITAND(e9,#00FFh))MOD 256;pc:=pc+2;END;IF d9==#8000h THEN d9:=BITAND(e9,#000Fh);CASE IF d9==#0000 THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=b2(BITSR(BITAND(e9,#00F0h),4)+1);pc:=pc+2;END;IF d9==#0001 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=BITOR(b2(q9),b2(BITSR(BITAND(e9,#00F0h),4)+1));pc:=pc+2;END;IF d9==#0002 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=BITAND(b2(q9),b2(BITSR(BITAND(e9,#00F0h),4)+1));pc:=pc+2;END;IF d9==#0003 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=BITXOR(b2(q9),b2(BITSR(BITAND(e9,#00F0h),4)+1));pc:=pc+2;END;IF d9==#0004 THEN b2(16):=b2(BITSR(BITAND(e9,#00F0h),4)+1)>(#FFh-b2(BITSR(BITAND(e9,#0F00h),8)+1));q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=(b2(q9)+b2(BITSR(BITAND(e9,#00F0h),4)+1))MOD 256;pc:=pc+2;END;IF d9==#0005 THEN b2(16):=b2(BITSR(BITAND(e9,#00F0h),4)+1)>b2(BITSR(BITAND(e9,#0F00h),8)+1);q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=b2(q9)-b2(BITSR(BITAND(e9,#00F0h),4)+1);pc:=pc+2;END;IF d9==#0006 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(16):=BITAND(b2(q9),#1h);b2(q9):=BITSR(b2(q9),1);pc:=pc+2;END;IF d9==#0007 THEN b2(16):=b2(BITSR(BITAND(e9,#0F00h),8)+1)<=b2(BITSR(BITAND(e9,#00F0h),4)+1);q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=(b2(BITSR(BITAND(e9,#00F0h),4)+1)-b2(q9))MOD 256;pc:=pc+2;END;IF d9==#000E THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(16):=BITSR(b2(q9),7);b2(q9):=BITSL(b2(q9),1);pc:=pc+2;END;DEFAULT errorOpcode();END;END;IF d9==#9000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==b2(BITSR(BITAND(e9,#00F0),4)+1),2,4);END;IF d9==#A000h THEN k9:=BITAND(e9,#0FFFh);pc:=pc+2;END;IF d9==#B000h THEN pc:=BITAND(e9,#0FFFh)+b2(1);END;IF d9==#C000h THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=BITAND(RANDINT(#FFh),BITAND(e9,#00FFh));pc:=pc+2;END;IF d9==#D000h THEN local c9X,c9Y,b9,n9,f9,g9,q9;c9X:=b2(BITSR(BITAND(e9,#0F00h),8)+1);c9Y:=b2(BITSR(BITAND(e9,#00F0h),4)+1);b9:=BITAND(e9,#000F);b2(16):=0;FOR f9 FROM 0 TO b9-1 DO n9:=b8(k9+f9+1);FOR g9 FROM 0 TO 7 DO IF BITAND(n9,BITSR(#80h,g9))<>0 THEN q9:=c9X+g9+((c9Y+f9)*c9Width)+1;IF c9(q9)THEN b2(16):=1;END;c9(q9):=NOT c9(q9);END;END;END;updateScreen:=1;pc:=pc+2;END;IF d9==#E000h THEN q9:=b3((b2((BITSR(BITAND(e9,#0F00h),8)+1))+1));d9:=BITAND(e9,#00FFh);CASE IF d9==#009Eh THEN pc:=pc+IFTE(q9<>0,4,2);END;IF d9==#00A1h THEN pc:=pc+IFTE(q9==0,4,2);END;DEFAULT errorOpcode();END;END;IF d9==#F000h THEN d9:=BITAND(e9,#00FFh);CASE IF d9==#0007h THEN b2(BITSR(BITAND(e9,#0F00),8)+1):=l9;pc:=pc+2;END;IF d9==#000Ah THEN local b6:=0;FOR q9 FROM 1 TO 16 DO IF b3(q9)THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=q9-1;b6:=1;BREAK;END;END;IF b6==0 THEN RETURN;END;pc:=pc+2;END;IF d9==#0015h THEN l9:=b2(BITSR(BITAND(e9,#0F00h),8)+1);pc:=pc+2;END;IF d9==#0018h THEN pc:=pc+2;END;IF d9==#001Eh THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(16):=k9+b2(q9)> #0FFFh;k9:=k9+b2(q9);pc:=pc+2;END;IF d9==#0029h THEN k9:=b2(BITSR(BITAND(e9,#0F00h),8)+1)*5;pc:=pc+2;END;IF d9==#0033h THEN q9:=b2(BITSR(BITAND(e9,#0F00h),8)+1);b8(k9+1):=IP(q9/100);b8(k9+2):=IP((q9/10)MOD 10);b8(k9+3):=IP((q9 MOD 100)MOD 10);pc:=pc+2;END;IF d9==#0055h THEN FOR q9 FROM 0 TO BITSR(BITAND(e9,#0F00h),8)DO b8(k9+q9+1):=b2(q9+1);END;k9:=k9+BITSR(BITAND(e9,#0F00),8)+1;pc:=pc+2;END;IF d9==#0065h THEN FOR q9 FROM 0 TO BITSR(BITAND(e9,#0F00h),8)DO b2(q9+1):=b8(k9+q9+1);END;k9:=k9+BITSR(BITAND(e9,#0F00),8)+1;pc:=pc+2;END;DEFAULT errorOpcode();END;END;DEFAULT errorOpcode();END;IF l9>0 THEN l9:=l9-1;END;END;loop()BEGIN cpuCycle();IF(updateScreen)THEN local o9,p9,i9,p95;FOR p9 FROM 1 TO 32 DO i9:=(p9-1)*c9Width;p95:=((p9-1)*5)+40;FOR o9 FROM 1 TO 64 DO BLIT_P((o9-1)*5,p95,IFTE(c9(o9+i9),G1,G2));END;END;updateScreen:=0;END;END;EXPORT invaders()BEGIN RECT(#000000);IF(SIZE(b5)>4096-512)THEN MSGBOX("ROM is too big for the RAM, it might not run properly");END;init();REPEAT loop();b3(1):=ISKEYDOWN(32);b3(2):=ISKEYDOWN(33);b3(3):=ISKEYDOWN(34);b3(4):=ISKEYDOWN(37);b3(5):=ISKEYDOWN(38);b3(6):=ISKEYDOWN(39);b3(7):=ISKEYDOWN(42);b3(8):=ISKEYDOWN(43);b3(9):=ISKEYDOWN(44);b3(10):=ISKEYDOWN(48);b3(11):=ISKEYDOWN(47);b3(12):=ISKEYDOWN(49);b3(13):=ISKEYDOWN(35);b3(14):=ISKEYDOWN(40);b3(15):=ISKEYDOWN(45);b3(16):=ISKEYDOWN(50);UNTIL 0;END;
TETRIS
Code:
local b5:={#A2h,#B4h,#23h,#E6h,#22h,#B6h,#70h,#01h,#D0h,#11h,#30h,#25h,#12h,#06h,#71h,#FFh,#D0h,#11h,#60h,#1Ah,#D0h,#11h,#60h,#25h,#31h,#00h,#12h,#0Eh,#C4h,#70h,#44h,#70h,#12h,#1Ch,#C3h,#03h,#60h,#1Eh,#61h,#03h,#22h,#5Ch,#F5h,#15h,#D0h,#14h,#3Fh,#01h,#12h,#3Ch,#D0h,#14h,#71h,#FFh,#D0h,#14h,#23h,#40h,#12h,#1Ch,#E7h,#A1h,#22h,#72h,#E8h,#A1h,#22h,#84h,#E9h,#A1h,#22h,#96h,#E2h,#9Eh,#12h,#50h,#66h,#00h,#F6h,#15h,#F6h,#07h,#36h,#00h,#12h,#3Ch,#D0h,#14h,#71h,#01h,#12h,#2Ah,#A2h,#C4h,#F4h,#1Eh,#66h,#00h,#43h,#01h,#66h,#04h,#43h,#02h,#66h,#08h,#43h,#03h,#66h,#0Ch,#F6h,#1Eh,#00h,#EEh,#D0h,#14h,#70h,#FFh,#23h,#34h,#3Fh,#01h,#00h,#EEh,#D0h,#14h,#70h,#01h,#23h,#34h,#00h,#EEh,#D0h,#14h,#70h,#01h,#23h,#34h,#3Fh,#01h,#00h,#EEh,#D0h,#14h,#70h,#FFh,#23h,#34h,#00h,#EEh,#D0h,#14h,#73h,#01h,#43h,#04h,#63h,#00h,#22h,#5Ch,#23h,#34h,#3Fh,#01h,#00h,#EEh,#D0h,#14h,#73h,#FFh,#43h,#FFh,#63h,#03h,#22h,#5Ch,#23h,#34h,#00h,#EEh,#80h,#00h,#67h,#05h,#68h,#06h,#69h,#04h,#61h,#1Fh,#65h,#10h,#62h,#07h,#00h,#EEh,#40h,#E0h,#00h,#00h,#40h,#C0h,#40h,#00h,#00h,#E0h,#40h,#00h,#40h,#60h,#40h,#00h,#40h,#40h,#60h,#00h,#20h,#E0h,#00h,#00h,#C0h,#40h,#40h,#00h,#00h,#E0h,#80h,#00h,#40h,#40h,#C0h,#00h,#00h,#E0h,#20h,#00h,#60h,#40h,#40h,#00h,#80h,#E0h,#00h,#00h,#40h,#C0h,#80h,#00h,#C0h,#60h,#00h,#00h,#40h,#C0h,#80h,#00h,#C0h,#60h,#00h,#00h,#80h,#C0h,#40h,#00h,#00h,#60h,#C0h,#00h,#80h,#C0h,#40h,#00h,#00h,#60h,#C0h,#00h,#C0h,#C0h,#00h,#00h,#C0h,#C0h,#00h,#00h,#C0h,#C0h,#00h,#00h,#C0h,#C0h,#00h,#00h,#40h,#40h,#40h,#40h,#00h,#F0h,#00h,#00h,#40h,#40h,#40h,#40h,#00h,#F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#F0h,#90h,#F0h,#F0h,#10h,#20h,#40h,#40h,#F0h,#90h,#F0h,#90h,#F0h,#F0h,#90h,#F0h,#10h,#F0h,#F0h,#90h,#F0h,#90h,#90h,#E0h,#90h,#E0h,#90h,#E0h,#F0h,#80h,#80h,#80h,#F0h,#E0h,#90h,#90h,#90h,#E0h,#F0h,#80h,#F0h,#80h,#F0h,#F0h,#80h,#F0h,#80h,#80h};local b8;local b2;local m9,sp;local b3;local pc,l9,k9,e9,d9;local c9;local c9Width:=64;local updateScreen;clearScreen()BEGIN updateScreen:=1;c9:=MAKELIST(0,X,1,2048);END;init()BEGIN DIMGROB_P(G1,5,5,{#0:64h,#0:64h,#0:64h,#0:64h,#0:64h,#0:64h,#0:64h});DIMGROB_P(G2,5,5,{#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF:64h});clearScreen();m9:=MAKELIST(#0h,X,1,16);sp:=1;b2:=MAKELIST(#0h,X,1,16);b3:=MAKELIST(0,X,1,16);pc:=#200h;l9:=0;k9:=0;b8:=SUB(CONCAT(j9,MAKELIST(#0h,X,1,432),b5,MAKELIST(#0h,X,1,3583)),1,4096);END;errorOpcode()BEGIN msgbox("Fatal error: UNKNOWN OPCODE ("+e9+")");END;cpuCycle()BEGIN e9:=BITXOR(b8(pc+2),BITSL(b8(pc+1),8));d9:=BITAND(e9,#F000h);local q9;CASE IF d9==#0000h THEN CASE IF e9==#00E0 THEN clearScreen();pc:=pc+2;END;IF e9==#00EE THEN sp:=sp-1;pc:=m9(sp);pc:=pc+2;END;DEFAULT errorOpcode();END;END;IF d9==#1000h THEN pc:=BITAND(e9,#0FFFh);END;IF d9==#2000h THEN m9(sp):=pc;sp:=sp+1;pc:=BITAND(e9,#0FFFh);END;IF d9==#3000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==BITAND(e9,#00FF),4,2)END;IF d9==#4000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==BITAND(e9,#00FF),2,4)END;IF d9==#5000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==b2(BITSR(BITAND(e9,#00F0h),4)+1),4,2)END;IF d9==#6000h THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=BITAND(e9,#00FFh);pc:=pc+2;END;IF d9==#7000h THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=(b2(q9)+BITAND(e9,#00FFh))MOD 256;pc:=pc+2;END;IF d9==#8000h THEN d9:=BITAND(e9,#000Fh);CASE IF d9==#0000 THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=b2(BITSR(BITAND(e9,#00F0h),4)+1);pc:=pc+2;END;IF d9==#0001 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=BITOR(b2(q9),b2(BITSR(BITAND(e9,#00F0h),4)+1));pc:=pc+2;END;IF d9==#0002 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=BITAND(b2(q9),b2(BITSR(BITAND(e9,#00F0h),4)+1));pc:=pc+2;END;IF d9==#0003 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=BITXOR(b2(q9),b2(BITSR(BITAND(e9,#00F0h),4)+1));pc:=pc+2;END;IF d9==#0004 THEN b2(16):=b2(BITSR(BITAND(e9,#00F0h),4)+1)>(#FFh-b2(BITSR(BITAND(e9,#0F00h),8)+1));q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=(b2(q9)+b2(BITSR(BITAND(e9,#00F0h),4)+1))MOD 256;pc:=pc+2;END;IF d9==#0005 THEN b2(16):=b2(BITSR(BITAND(e9,#00F0h),4)+1)>b2(BITSR(BITAND(e9,#0F00h),8)+1);q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=b2(q9)-b2(BITSR(BITAND(e9,#00F0h),4)+1);pc:=pc+2;END;IF d9==#0006 THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(16):=BITAND(b2(q9),#1h);b2(q9):=BITSR(b2(q9),1);pc:=pc+2;END;IF d9==#0007 THEN b2(16):=b2(BITSR(BITAND(e9,#0F00h),8)+1)<=b2(BITSR(BITAND(e9,#00F0h),4)+1);q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(q9):=(b2(BITSR(BITAND(e9,#00F0h),4)+1)-b2(q9))MOD 256;pc:=pc+2;END;IF d9==#000E THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(16):=BITSR(b2(q9),7);b2(q9):=BITSL(b2(q9),1);pc:=pc+2;END;DEFAULT errorOpcode();END;END;IF d9==#9000h THEN pc:=pc+IFTE(b2(BITSR(BITAND(e9,#0F00h),8)+1)==b2(BITSR(BITAND(e9,#00F0),4)+1),2,4);END;IF d9==#A000h THEN k9:=BITAND(e9,#0FFFh);pc:=pc+2;END;IF d9==#B000h THEN pc:=BITAND(e9,#0FFFh)+b2(1);END;IF d9==#C000h THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=BITAND(RANDINT(#FFh),BITAND(e9,#00FFh));pc:=pc+2;END;IF d9==#D000h THEN local c9X,c9Y,b9,n9,f9,g9,q9;c9X:=b2(BITSR(BITAND(e9,#0F00h),8)+1);c9Y:=b2(BITSR(BITAND(e9,#00F0h),4)+1);b9:=BITAND(e9,#000F);b2(16):=0;FOR f9 FROM 0 TO b9-1 DO n9:=b8(k9+f9+1);FOR g9 FROM 0 TO 7 DO IF BITAND(n9,BITSR(#80h,g9))<>0 THEN q9:=c9X+g9+((c9Y+f9)*c9Width)+1;IF c9(q9)THEN b2(16):=1;END;c9(q9):=NOT c9(q9);END;END;END;updateScreen:=1;pc:=pc+2;END;IF d9==#E000h THEN q9:=b3((b2((BITSR(BITAND(e9,#0F00h),8)+1))+1));d9:=BITAND(e9,#00FFh);CASE IF d9==#009Eh THEN pc:=pc+IFTE(q9<>0,4,2);END;IF d9==#00A1h THEN pc:=pc+IFTE(q9==0,4,2);END;DEFAULT errorOpcode();END;END;IF d9==#F000h THEN d9:=BITAND(e9,#00FFh);CASE IF d9==#0007h THEN b2(BITSR(BITAND(e9,#0F00),8)+1):=l9;pc:=pc+2;END;IF d9==#000Ah THEN local b6:=0;FOR q9 FROM 1 TO 16 DO IF b3(q9)THEN b2(BITSR(BITAND(e9,#0F00h),8)+1):=q9-1;b6:=1;BREAK;END;END;IF b6==0 THEN RETURN;END;pc:=pc+2;END;IF d9==#0015h THEN l9:=b2(BITSR(BITAND(e9,#0F00h),8)+1);pc:=pc+2;END;IF d9==#0018h THEN pc:=pc+2;END;IF d9==#001Eh THEN q9:=BITSR(BITAND(e9,#0F00h),8)+1;b2(16):=k9+b2(q9)> #0FFFh;k9:=k9+b2(q9);pc:=pc+2;END;IF d9==#0029h THEN k9:=b2(BITSR(BITAND(e9,#0F00h),8)+1)*5;pc:=pc+2;END;IF d9==#0033h THEN q9:=b2(BITSR(BITAND(e9,#0F00h),8)+1);b8(k9+1):=IP(q9/100);b8(k9+2):=IP((q9/10)MOD 10);b8(k9+3):=IP((q9 MOD 100)MOD 10);pc:=pc+2;END;IF d9==#0055h THEN FOR q9 FROM 0 TO BITSR(BITAND(e9,#0F00h),8)DO b8(k9+q9+1):=b2(q9+1);END;k9:=k9+BITSR(BITAND(e9,#0F00),8)+1;pc:=pc+2;END;IF d9==#0065h THEN FOR q9 FROM 0 TO BITSR(BITAND(e9,#0F00h),8)DO b2(q9+1):=b8(k9+q9+1);END;k9:=k9+BITSR(BITAND(e9,#0F00),8)+1;pc:=pc+2;END;DEFAULT errorOpcode();END;END;DEFAULT errorOpcode();END;IF l9>0 THEN l9:=l9-1;END;END;loop()BEGIN cpuCycle();IF(updateScreen)THEN local o9,p9,i9,p95;FOR p9 FROM 1 TO 32 DO i9:=(p9-1)*c9Width;p95:=((p9-1)*5)+40;FOR o9 FROM 1 TO 64 DO BLIT_P((o9-1)*5,p95,IFTE(c9(o9+i9),G1,G2));END;END;updateScreen:=0;END;END;EXPORT tetris()BEGIN RECT(#000000);IF(SIZE(b5)>4096-512)THEN MSGBOX("ROM is too big for the RAM, it might not run properly");END;init();REPEAT loop();b3(1):=ISKEYDOWN(32);b3(2):=ISKEYDOWN(33);b3(3):=ISKEYDOWN(34);b3(4):=ISKEYDOWN(37);b3(5):=ISKEYDOWN(38);b3(6):=ISKEYDOWN(39);b3(7):=ISKEYDOWN(42);b3(8):=ISKEYDOWN(43);b3(9):=ISKEYDOWN(44);b3(10):=ISKEYDOWN(48);b3(11):=ISKEYDOWN(47);b3(12):=ISKEYDOWN(49);b3(13):=ISKEYDOWN(35);b3(14):=ISKEYDOWN(40);b3(15):=ISKEYDOWN(45);b3(16):=ISKEYDOWN(50);UNTIL 0;END;
Download all: [attachment=176]
NOTE: The keyboard is mapped to http://cl.ly/TTBD there are still few glitches in the emulation. Drawing speed can be optimized further.