HP Forums
CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime (/thread-475.html)



CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - eried - 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-post-39757.html#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 Smile

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});DIMGRO​B_P(G2,5,5,{#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7​FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF:64h});clea​rScreen();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,MAKELI​ST(#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,#0​0F0h),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(q​9)+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(b​2(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):=(b​2(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(q​9),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));p​c:=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;I​F 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;D​EFAULT 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);b​3(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):=I​SKEYDOWN(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,#1Ch,#D8h,#04h,#00h,#EEh,#23h,​#51h,#8Eh,#23h,#23h,#51h,#60h,#05h,#F0h,#18h,#F0h,#15h,#F0h,#07h,#30h,#00h,#13h,​#89h,#00h,#EEh,#6Ah,#00h,#8Dh,#E0h,#6Bh,#04h,#E9h,#A1h,#12h,#57h,#A6h,#0Ch,#FDh,​#1Eh,#F0h,#65h,#30h,#FFh,#13h,#AFh,#6Ah,#00h,#6Bh,#04h,#6Dh,#01h,#6Eh,#01h,#13h,​#97h,#A5h,#0Ah,#F0h,#1Eh,#DBh,#C6h,#7Bh,#08h,#7Dh,#01h,#7Ah,#01h,#3Ah,#07h,#13h,​#97h,#00h,#EEh,#3Ch,#7Eh,#FFh,#FFh,#99h,#99h,#7Eh,#FFh,#FFh,#24h,#24h,#E7h,#7Eh,​#FFh,#3Ch,#3Ch,#7Eh,#DBh,#81h,#42h,#3Ch,#7Eh,#FFh,#DBh,#10h,#38h,#7Ch,#FEh,#00h,​#00h,#7Fh,#00h,#3Fh,#00h,#7Fh,#00h,#00h,#00h,#01h,#01h,#01h,#03h,#03h,#03h,#03h,​#00h,#00h,#3Fh,#20h,#20h,#20h,#20h,#20h,#20h,#20h,#20h,#3Fh,#08h,#08h,#FFh,#00h,​#00h,#FEh,#00h,#FCh,#00h,#FEh,#00h,#00h,#00h,#7Eh,#42h,#42h,#62h,#62h,#62h,#62h,​#00h,#00h,#FFh,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#FFh,#00h,#00h,#FFh,#00h,​#7Dh,#00h,#41h,#7Dh,#05h,#7Dh,#7Dh,#00h,#00h,#C2h,#C2h,#C6h,#44h,#6Ch,#28h,#38h,​#00h,#00h,#FFh,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#FFh,#00h,#00h,#FFh,#00h,​#F7h,#10h,#14h,#F7h,#F7h,#04h,#04h,#00h,#00h,#7Ch,#44h,#FEh,#C2h,#C2h,#C2h,#C2h,​#00h,#00h,#FFh,#00h,#00h,#00h,#00h,#00h,#00h,#00h,#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,#6Ch,#A8h,#5Ah,#66h,#54h,#24h,#66h,#00h,#48h,#48h,#18h,#12h,#A8h,#06h,​#90h,#A8h,#12h,#00h,#7Eh,#30h,#12h,#A8h,#84h,#30h,#4Eh,#72h,#18h,#66h,#A8h,#A8h,​#A8h,#A8h,#A8h,#A8h,#90h,#54h,#78h,#A8h,#48h,#78h,#6Ch,#72h,#A8h,#12h,#18h,#6Ch,​#72h,#66h,#54h,#90h,#A8h,#72h,#2Ah,#18h,#A8h,#30h,#4Eh,#7Eh,#00h,#12h,#18h,#66h,​#6Ch,#A8h,#72h,#54h,#A8h,#5Ah,#66h,#18h,#7Eh,#18h,#4Eh,#72h,#A8h,#72h,#2Ah,#18h,​#30h,#66h,#A8h,#30h,#4Eh,#7Eh,#00h,#6Ch,#30h,#54h,#4Eh,#9Ch,#A8h,#A8h,#A8h,#A8h,​#A8h,#A8h,#A8h,#48h,#54h,#7Eh,#18h,#A8h,#90h,#54h,#78h,#66h,#A8h,#6Ch,#2Ah,#30h,​#5Ah,#A8h,#84h,#30h,#72h,#2Ah,#A8h,#D8h,#A8h,#00h,#4Eh,#12h,#A8h,#E4h,#A2h,#A8h,​#00h,#4Eh,#12h,#A8h,#6Ch,#2Ah,#54h,#54h,#72h,#A8h,#84h,#30h,#72h,#2Ah,#A8h,#DEh,​#9Ch,#A8h,#72h,#2Ah,#18h,#A8h,#0Ch,#54h,#48h,#5Ah,#78h,#72h,#18h,#66h,#A8h,#66h,​#18h,#5Ah,#54h,#66h,#72h,#6Ch,#A8h,#72h,#2Ah,#00h,#72h,#A8h,#72h,#2Ah,#18h,#A8h,​#30h,#4Eh,#7Eh,#00h,#12h,#18h,#66h,#6Ch,#A8h,#00h,#66h,#18h,#A8h,#30h,#4Eh,#0Ch,​#66h,#18h,#00h,#6Ch,#30h,#4Eh,#24h,#A8h,#72h,#2Ah,#18h,#30h,#66h,#A8h,#1Eh,#54h,​#66h,#0Ch,#18h,#9Ch,#A8h,#24h,#54h,#54h,#12h,#A8h,#42h,#78h,#0Ch,#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});DIMGRO​B_P(G2,5,5,{#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7​FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF:64h});clea​rScreen();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,MAKELI​ST(#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,#0​0F0h),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(q​9)+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(b​2(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):=(b​2(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(q​9),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));p​c:=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;I​F 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;D​EFAULT 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);b​3(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):=I​SKEYDOWN(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,#F0h,#00h,#00h,#D0h,#14h,#66h,#35h,#76h,#FFh,#36h,#00h,#13h,#38h,​#00h,#EEh,#A2h,#B4h,#8Ch,#10h,#3Ch,#1Eh,#7Ch,#01h,#3Ch,#1Eh,#7Ch,#01h,#3Ch,#1Eh,​#7Ch,#01h,#23h,#5Eh,#4Bh,#0Ah,#23h,#72h,#91h,#C0h,#00h,#EEh,#71h,#01h,#13h,#50h,​#60h,#1Bh,#6Bh,#00h,#D0h,#11h,#3Fh,#00h,#7Bh,#01h,#D0h,#11h,#70h,#01h,#30h,#25h,​#13h,#62h,#00h,#EEh,#60h,#1Bh,#D0h,#11h,#70h,#01h,#30h,#25h,#13h,#74h,#8Eh,#10h,​#8Dh,#E0h,#7Eh,#FFh,#60h,#1Bh,#6Bh,#00h,#D0h,#E1h,#3Fh,#00h,#13h,#90h,#D0h,#E1h,​#13h,#94h,#D0h,#D1h,#7Bh,#01h,#70h,#01h,#30h,#25h,#13h,#86h,#4Bh,#00h,#13h,#A6h,​#7Dh,#FFh,#7Eh,#FFh,#3Dh,#01h,#13h,#82h,#23h,#C0h,#3Fh,#01h,#23h,#C0h,#7Ah,#01h,​#23h,#C0h,#80h,#A0h,#6Dh,#07h,#80h,#D2h,#40h,#04h,#75h,#FEh,#45h,#02h,#65h,#04h,​#00h,#EEh,#A7h,#00h,#F2h,#55h,#A8h,#04h,#FAh,#33h,#F2h,#65h,#F0h,#29h,#6Dh,#32h,​#6Eh,#00h,#DDh,#E5h,#7Dh,#05h,#F1h,#29h,#DDh,#E5h,#7Dh,#05h,#F2h,#29h,#DDh,#E5h,​#A7h,#00h,#F2h,#65h,#A2h,#B4h,#00h,#EEh,#6Ah,#00h,#60h,#19h,#00h,#EEh,#37h,#23h}​;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});DIMGRO​B_P(G2,5,5,{#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7​FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF:64h});clea​rScreen();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,MAKELI​ST(#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,#0​0F0h),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(q​9)+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(b​2(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):=(b​2(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(q​9),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));p​c:=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;I​F 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;D​EFAULT 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);b​3(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):=I​SKEYDOWN(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.


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - Han - 01-20-2014 03:16 PM

Very cool -- there was a chip interpreter for the HP48 as well. I wonder if those would "port" easily to the HP Prime.


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - Adriweb - 01-21-2014 01:23 AM

Ah, pretty cool what we can do with our calcs today...
It reminds me of the TI-Nspire Chip-8 emulator by Jim Bauwens Smile

It's done in Lua, though :




Source is here : https://github.com/jimbauwens/chip-8


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - eried - 01-21-2014 07:06 AM

(01-21-2014 01:23 AM)Adriweb Wrote:  Ah, pretty cool what we can do with our calcs today...
It reminds me of the TI-Nspire Chip-8 emulator by Jim Bauwens Smile

Source is here : https://github.com/jimbauwens/chip-8

Very cool! I have to work yet to reach that speed! hehe Smile

I attached the very same program as SPACE INVADERS, works pretty much identical but keyboard detection is still messed.

UPDATE: Speed is pretty much TOO fast right now Big Grin





RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - Kevin Ouellet - 01-22-2014 03:29 AM

This seems very promising. However, both Tetris and Pong2 gives me Syntax error in both the emulator and calculator D:


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - eried - 01-22-2014 09:56 AM

(01-22-2014 03:29 AM)Kevin Ouellet Wrote:  This seems very promising. However, both Tetris and Pong2 gives me Syntax error in both the emulator and calculator D:

Can you download the zip and paste the txt to the calculator? I tried in this moment and this works. The emulator in the current code is not ultra optimized as the video one, I am still looking how to balance the flickering/speed with the key detection Big Grin


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - cyrille de brébisson - 01-23-2014 08:05 AM

Hello,

Very nice! good work!!!


Cyrille


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - Kevin Ouellet - 01-25-2014 05:33 AM

(01-22-2014 09:56 AM)eried Wrote:  
(01-22-2014 03:29 AM)Kevin Ouellet Wrote:  This seems very promising. However, both Tetris and Pong2 gives me Syntax error in both the emulator and calculator D:

Can you download the zip and paste the txt to the calculator? I tried in this moment and this works. The emulator in the current code is not ultra optimized as the video one, I am still looking how to balance the flickering/speed with the key detection Big Grin

Hi, I just tried this and this now works. Thanks Smile


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - eried - 01-25-2014 02:44 PM

(01-25-2014 05:33 AM)Kevin Ouellet Wrote:  Hi, I just tried this and this now works. Thanks Smile

I have to balance the speed and keydetection. I was thinking on replace the screen list by G1 and use pixel functions directly, then with blit enlarge the area.

What do you think based on your tests? What should be the fastest way to write to clear and write to a temporal "memory" that will be drawn later? (in this moment there are 2 sprites (5x5) created with dimgrob used as pixels)


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - Kevin Ouellet - 01-25-2014 09:49 PM

I sadly don't know yet, but if each pixel on the screen are made of 5x5 squares, you should definitively draw them in a smaller GROB as 1x1 pixels then when you need to update the LCD, you BLIT it at larger resolution. I notice that when I make advanced programs in 160x120 resolution then stretch the result afterward, it's much faster than drawing everything directly at 320x240.


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - Mark Power - 06-03-2015 07:47 PM

I've put together a Chip-8 App using file handling from the Gallery (PNG Viewer) App and an alternative emulator I put together. I've included Pong, Space Invaders and Tetris ROMs as samples. You can find more at http://chip8.com/?page=109.

This is only the first version so some tuning is needed.

To copy additional Chip8 ROMs to your calculator, open the HP Connectivity Kit and load Chip8 ROMS into the "Files" Folder inside Chip8 App.
Then, open the Chip8 App from Connectivity Kit and Press Save Button.

*Press [VIEW] to access the Menu.
*To Open a File, select Open and then select the file.
*To Delete a File, select Delete and then select the file, or just select Delete ALL.

Keyboard mapping (calculator to Chip8)
789/ 123C
456* 456D
123- 789E
0. + A0BF

Bugs:
*Screen size needs fixing, but when I turn BLIT scaling on in display_sprite the calculator hangs. See lines 375 onwards.
*Timing is wrong, just fast enough on the calculator to play, but way too fast on the emulator.

Thanks to:
*Andrés Vélez (mandresve) manuel.velez@uptc.edu.co for the App framework
*Vik2015 for chip8.c which is the basis of the emulator


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - eried - 06-04-2015 11:35 AM

(06-03-2015 07:47 PM)Mark Power Wrote:  I've put together a Chip-8 App using file handling from the Gallery (PNG Viewer) App and an alternative emulator I put together. I've included Pong, Space Invaders and Tetris ROMs as samples. You can find more at http://chip8.com/?page=109.

This is only the first version so some tuning is needed.

To copy additional Chip8 ROMs to your calculator, open the HP Connectivity Kit and load Chip8 ROMS into the "Files" Folder inside Chip8 App.
Then, open the Chip8 App from Connectivity Kit and Press Save Button.

*Press [VIEW] to access the Menu.
*To Open a File, select Open and then select the file.
*To Delete a File, select Delete and then select the file, or just select Delete ALL.

Keyboard mapping (calculator to Chip8)
789/ 123C
456* 456D
123- 789E
0. + A0BF

Bugs:
*Screen size needs fixing, but when I turn BLIT scaling on in display_sprite the calculator hangs. See lines 375 onwards.
*Timing is wrong, just fast enough on the calculator to play, but way too fast on the emulator.

Thanks to:
*Andrés Vélez (mandresve) manuel.velez@uptc.edu.co for the App framework
*Vik2015 for chip8.c which is the basis of the emulator

Really cool!


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - Mark Power - 06-13-2015 10:27 AM

I've fixed the display scaling problem so that the whole of the HP Prime screen is used and tidied up a few things. You now don't see the icon.png file in the list of ROMS to play.

I've included Breakout, Pong2, Space Invaders and Tetris in the zip file for you to play as samples.

Speed is the next thing to improve and then I'll add SChip functions so you can play the more advanced games.

Anyone feeling adventurous can press the D (Define) key during a game and drop into the Prime debugger.


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - Mark Power - 07-26-2015 08:43 PM

I've added emulation of SCHIP instructions which means you can now play H.Piper!

The latest version of Chip8 along with ROMS for H.Piper!, Breakout, Lunar Lander, Pong2, Space Invaders, Tetris and Car is available to download here on the HPCC web site.

[Image: HPiper.png]

Fixes:
* Compatible with firmware 2015 6 17 (8151)
* This is my first attempt at implementing SCHIP instructions, so you may find other games don't work as expected - the original documentation is a little vague, so it is a bit of a case of trial and error. The car driving game is included in the ROMS, but looks a bit wonky at present.


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - eried - 07-27-2015 04:49 AM

Tested and it works perfect! great work!


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - jusu - 04-07-2016 11:39 AM

Hi all

I'm very new to the Prime, hence my possible stupid question:

How do I install the CHIP-8 app onto my Prime?
What do I need to copy when (a step by step advice would be great)?

Many thanks in advance for helping me out here.

Thanks
jusu


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - Han - 04-07-2016 03:33 PM

1. Download the zip file from this post: http://www.hpmuseum.org/forum/thread-475-post-39757.html#pid39757

2. Unzip the contents into your My Documents\HP Connectivity Kit\Content folder.

3. Start the connectivity kit.

4. Plug in your calculator.

5. In the conn. kit (bottom left pane) you should see the CHIP8.hpappdir file; drag it onto your calculator (also on the left pane in the conn. kit). This will download the app onto your calculator.

6. Press the [Apps] key on your calculator and select the CHIP8 app.


RE: CHIP-8 virtual machine emulator - Load chip8 ROMs in the prime - rprosperi - 04-07-2016 07:01 PM

Moderators:

Han's post is clear and very useful for new Prime users. Suggest a generic version of this be added to the top of this Sub-Forum, to avoid a continuing series of threads with this same question and answer.