11-05-2011, 06:49 PM
just sharing a snippet i coded now - this is about handling 4 simultaneous players (just like those arcade games from early 90's) on one keyboard - the only issues is maybe some sprites ('printing' udgs for that) may disapear, and on emulators (due on keyboard hardware or driver limitation) more than few simultaneous keys (like 6, depending) are not recognized, but i think this doesn't happen on real hardware.
this code is relativelly similar to one in assembly i posted on Karoshi msx forum, with some help from there - the code below has some differences, like the lack of hardware sprites on zx-spectrum, being all in basic language (except asm defb), etc.
please share oppinions, feedback, suggestions, etc., about this!
- in my oppinion, games behaving like this (4 simultaneous players on one keyboard) are really rare on zx-spectrum, afaik
the keys used are 'wsad' for 1, 'tgfh' for 2, 'ikjl' for 3, and cursor keys for 4
this code is relativelly similar to one in assembly i posted on Karoshi msx forum, with some help from there - the code below has some differences, like the lack of hardware sprites on zx-spectrum, being all in basic language (except asm defb), etc.
please share oppinions, feedback, suggestions, etc., about this!

the keys used are 'wsad' for 1, 'tgfh' for 2, 'ikjl' for 3, and cursor keys for 4
Code:
poke uInteger 23675,@udg01
poke uInteger 23606,@typeface-256
dim sq1,sq2,sq3,sq4 as uinteger
dim x1,y1,x2,y2,x3,y3,x4,y4 as byte
x1=5:y1=3:x2=10:y2=4:x3=5:y3=11:x4=10:y4=12
border 0:bright 1:paper 7:ink 0:flash 0:cls
drawsprites()
inverse 0:ink 0:bright 1
lp01:
pause 1
sq1=((255-(in 64510)) band 2)/2 bor ((255-(in 65022)) band 2) bor ((255-(in 65022)) band 1)*4 bor ((255-(in 65022)) band 4)*2 :'- wsad
sq2=((255-(in 64510)) band 16)/16 bor ((255-(in 65022)) band 16)/8 bor ((255-(in 65022)) band 8)/2 bor ((255-(in 49150)) band 16)/2 :'- tgfh
sq3=((255-(in 57342)) band 4)/4 bor ((255-(in 49150)) band 4)/2 bor ((255-(in 49150)) band 8)/2 bor ((255-(in 49150)) band 2)*4 :'- ikjl
sq4=((255-(in 61438)) band 8)/8 bor ((255-(in 61438)) band 16)/8 bor ((255-(in 63486)) band 16)/4 bor ((255-(in 61438)) band 4)*2 :'-7658
if sq1<>0 then
inverse 0:ink 0:bright 1:print at y1,x1;" ":print at y1+1,x1;" "
if ((sq1 band 4) <>0) and x1>0 then:x1=x1-1:end if
if ((sq1 band 8) <>0) and x1<30 then:x1=x1+1:end if
if ((sq1 band 1)<>0) and y1>0 then:y1=y1-1:end if
if ((sq1 band 2) <>0) and y1<22 then:y1=y1+1:end if
drawsprites()
end if
if sq2<>0 then
inverse 0:ink 0:bright 1:print at y2,x2;" ":print at y2+1,x2;" "
if ((sq2 band 4) <>0) and x2>0 then:x2=x2-1:end if
if ((sq2 band 8) <>0) and x2<30 then:x2=x2+1:end if
if ((sq2 band 1)<>0) and y2>0 then:y2=y2-1:end if
if ((sq2 band 2) <>0) and y2<22 then:y2=y2+1:end if
drawsprites()
end if
if sq3<>0 then
inverse 0:ink 0:bright 1:print at y3,x3;" ":print at y3+1,x3;" "
if ((sq3 band 4) <>0) and x3>0 then:x3=x3-1:end if
if ((sq3 band 8) <>0) and x3<30 then:x3=x3+1:end if
if ((sq3 band 1)<>0) and y3>0 then:y3=y3-1:end if
if ((sq3 band 2) <>0) and y3<22 then:y3=y3+1:end if
drawsprites()
end if
if sq4<>0 then
inverse 0:ink 0:bright 1:print at y4,x4;" ":print at y4+1,x4;" "
if ((sq4 band 4) <>0) and x4>0 then:x4=x4-1:end if
if ((sq4 band 8) <>0) and x4<30 then:x4=x4+1:end if
if ((sq4 band 1)<>0) and y4>0 then:y4=y4-1:end if
if ((sq4 band 2) <>0) and y4<22 then:y4=y4+1:end if
drawsprites()
end if
inverse 0:ink 0:bright 1
print at 0,0;sq1;",";sq2;",";sq3;",";sq4;" "
goto lp01
sub drawsprites():
inverse 1:ink 1:bright 0:print at y1,x1;"\A\B":print at y1+1,x1;"\C\D"
inverse 1:ink 2:bright 0:print at y2,x2;"\E\F":print at y2+1,x2;"\G\H"
inverse 1:ink 3:bright 0:print at y3,x3;"\I\J":print at y3+1,x3;"\K\L"
inverse 1:ink 4:bright 0:print at y4,x4;"\M\N":print at y4+1,x4;"\O\P"
end sub
udg01:
'- sprites from http://upload.wikimedia.org/wikipedia/commons/e/e0/AdobeGaramondSp.svg
asm
defb 000h,000h,000h,000h,003h,001h,001h,001h
defb 000h,000h,000h,000h,0C0h,080h,080h,080h
defb 001h,001h,001h,003h,000h,000h,000h,000h
defb 080h,080h,080h,0C0h,000h,000h,000h,000h
defb 000h,000h,000h,000h,007h,009h,001h,001h
defb 000h,000h,000h,000h,080h,080h,080h,080h
defb 001h,002h,006h,00Fh,000h,000h,000h,000h
defb 000h,000h,020h,0E0h,000h,000h,000h,000h
defb 000h,000h,000h,000h,003h,004h,000h,000h
defb 000h,000h,000h,000h,080h,0C0h,0C0h,080h
defb 003h,001h,000h,000h,000h,000h,003h,006h
defb 080h,0C0h,0C0h,0C0h,0C0h,080h,000h,000h
defb 000h,000h,000h,000h,000h,000h,001h,003h
defb 000h,000h,000h,000h,040h,0C0h,0C0h,0C0h
defb 002h,004h,008h,01Fh,000h,000h,000h,000h
defb 0C0h,0C0h,0C0h,0F0h,0C0h,0C0h,0C0h,0C0h
end asm
typeface:
asm
defb 000h,000h,000h,000h,000h,000h,000h,000h
defb 018h,03ch,03ch,018h,018h,000h,018h,000h
defb 036h,036h,036h,000h,000h,000h,000h,000h
defb 036h,036h,07fh,036h,07fh,036h,036h,000h
defb 018h,03eh,060h,03ch,006h,07ch,018h,000h
defb 000h,063h,066h,00ch,018h,033h,063h,000h
defb 01ch,036h,01ch,03bh,06eh,066h,03bh,000h
defb 00ch,00ch,018h,000h,000h,000h,000h,000h
defb 00ch,018h,030h,030h,030h,018h,00ch,000h
defb 030h,018h,00ch,00ch,00ch,018h,030h,000h
defb 000h,066h,03ch,0ffh,03ch,066h,000h,000h
defb 000h,018h,018h,07eh,018h,018h,000h,000h
defb 000h,000h,000h,000h,018h,008h,010h,000h
defb 000h,000h,000h,07eh,000h,000h,000h,000h
defb 000h,000h,000h,000h,000h,018h,018h,000h
defb 003h,006h,00ch,018h,030h,060h,0c0h,000h
defb 01ch,026h,063h,063h,063h,032h,01ch,000h
defb 00ch,01ch,00ch,00ch,00ch,00ch,03fh,000h
defb 03eh,063h,007h,01eh,03ch,070h,07fh,000h
defb 03fh,006h,00ch,01eh,003h,063h,03eh,000h
defb 00eh,01eh,036h,066h,07fh,006h,006h,000h
defb 07eh,060h,07eh,003h,003h,063h,03eh,000h
defb 01ch,030h,060h,07eh,063h,063h,03eh,000h
defb 07fh,063h,006h,00ch,018h,018h,018h,000h
defb 03ch,062h,072h,03ch,04fh,043h,03eh,000h
defb 03eh,063h,063h,03fh,003h,006h,03ch,000h
defb 000h,000h,018h,018h,000h,018h,018h,000h
defb 000h,018h,018h,000h,038h,018h,030h,000h
defb 00ch,018h,030h,060h,030h,018h,00ch,000h
defb 000h,000h,07eh,000h,07eh,000h,000h,000h
defb 030h,018h,00ch,006h,00ch,018h,030h,000h
defb 07ch,0c6h,006h,01ch,030h,000h,030h,000h
defb 03eh,063h,06fh,06fh,06fh,060h,03ch,000h
defb 01ch,036h,063h,063h,07fh,063h,063h,000h
defb 07eh,063h,063h,07eh,063h,063h,07eh,000h
defb 01eh,033h,060h,060h,060h,033h,01eh,000h
defb 07ch,066h,063h,063h,063h,066h,07ch,000h
defb 03fh,030h,030h,03eh,030h,030h,03fh,000h
defb 07fh,060h,060h,07eh,060h,060h,060h,000h
defb 01fh,030h,060h,067h,063h,033h,01fh,000h
defb 063h,063h,063h,07fh,063h,063h,063h,000h
defb 03fh,00ch,00ch,00ch,00ch,00ch,03fh,000h
defb 003h,003h,003h,003h,003h,063h,03eh,000h
defb 063h,066h,06ch,078h,07ch,06eh,067h,000h
defb 030h,030h,030h,030h,030h,030h,03fh,000h
defb 063h,077h,07fh,07fh,06bh,063h,063h,000h
defb 063h,073h,07bh,07fh,06fh,067h,063h,000h
defb 03eh,063h,063h,063h,063h,063h,03eh,000h
defb 07eh,063h,063h,063h,07eh,060h,060h,000h
defb 03eh,063h,063h,063h,06fh,066h,03dh,000h
defb 07eh,063h,063h,067h,07ch,06eh,067h,000h
defb 03ch,066h,060h,03eh,003h,063h,03eh,000h
defb 03fh,00ch,00ch,00ch,00ch,00ch,00ch,000h
defb 063h,063h,063h,063h,063h,063h,03eh,000h
defb 063h,063h,063h,077h,03eh,01ch,008h,000h
defb 063h,063h,06bh,07fh,07fh,077h,063h,000h
defb 063h,077h,03eh,01ch,03eh,077h,063h,000h
defb 033h,033h,033h,01eh,00ch,00ch,00ch,000h
defb 07fh,007h,00eh,01ch,038h,070h,07fh,000h
defb 000h,000h,000h,03ch,03ch,000h,000h,000h
defb 000h,000h,000h,07fh,07fh,000h,000h,000h
defb 000h,000h,000h,000h,000h,018h,018h,000h
defb 018h,03ch,03ch,018h,018h,000h,018h,000h
defb 03ch,042h,09dh,0a1h,0a1h,09dh,042h,03ch
defb 030h,018h,00ch,000h,000h,000h,000h,000h
defb 01ch,036h,063h,063h,07fh,063h,063h,000h
defb 07eh,063h,063h,07eh,063h,063h,07eh,000h
defb 01eh,033h,060h,060h,060h,033h,01eh,000h
defb 07ch,066h,063h,063h,063h,066h,07ch,000h
defb 03fh,030h,030h,03eh,030h,030h,03fh,000h
defb 07fh,060h,060h,07eh,060h,060h,060h,000h
defb 01fh,030h,060h,067h,063h,033h,01fh,000h
defb 063h,063h,063h,07fh,063h,063h,063h,000h
defb 03fh,00ch,00ch,00ch,00ch,00ch,03fh,000h
defb 003h,003h,003h,003h,003h,063h,03eh,000h
defb 063h,066h,06ch,078h,07ch,06eh,067h,000h
defb 030h,030h,030h,030h,030h,030h,03fh,000h
defb 063h,077h,07fh,07fh,06bh,063h,063h,000h
defb 063h,073h,07bh,07fh,06fh,067h,063h,000h
defb 03eh,063h,063h,063h,063h,063h,03eh,000h
defb 07eh,063h,063h,063h,07eh,060h,060h,000h
defb 03eh,063h,063h,063h,06fh,066h,03dh,000h
defb 07eh,063h,063h,067h,07ch,06eh,067h,000h
defb 03ch,066h,060h,03eh,003h,063h,03eh,000h
defb 03fh,00ch,00ch,00ch,00ch,00ch,00ch,000h
defb 063h,063h,063h,063h,063h,063h,03eh,000h
defb 063h,063h,063h,077h,03eh,01ch,008h,000h
defb 063h,063h,06bh,07fh,07fh,077h,063h,000h
defb 063h,077h,03eh,01ch,03eh,077h,063h,000h
defb 033h,033h,033h,01eh,00ch,00ch,00ch,000h
defb 07fh,007h,00eh,01ch,038h,070h,07fh,000h
defb 000h,000h,000h,03ch,03ch,000h,000h,000h
defb 000h,000h,000h,07fh,07fh,000h,000h,000h
defb 000h,000h,000h,000h,000h,018h,018h,000h
defb 018h,03ch,03ch,018h,018h,000h,018h,000h
defb 03ch,042h,09dh,0a1h,0a1h,09dh,042h,03ch
end asm