• Tetris was: Re: Pong 256

    From Kerr-Mudd,John@21:1/5 to John" on Fri Feb 26 11:34:19 2021
    On Thu, 15 Aug 2019 14:58:16 GMT, "Kerr-Mudd,John" <notsaying@nospicedham.invalid.org> wrote:

    A pong (the 1st computer video game?) in <255 bytes;

    I'll give the hexcode 1st to see if there's any takers. Needs DOS.

    [snip]
    In a similar vein: Tetris in 256 bytes

    I took John David Chapman's 1999 code & reduced it by 30 bytes
    Here's the text from his source:

    ;----------------------------------------------------------------------------- ;
    ; [] TET - 256 byte Tetris [][][]
    ; [][] []
    ; [] by []
    ; [] [] []
    ; [][][] [][] James David Chapman [][] [][] []
    ; [][][][] [] [] [] [][] [] ;----------------------------------------------------------------------------- ;
    ; Here is a 256 byte version of of the all time classic game Tetris...
    ;
    ; To play, use the left and right SHIFT keys to move the current block, and
    ; the ALT key to rotate it. Press CONTROL to exit.
    ;
    ; I have not had the amount of time that I would have liked to write this ;program, so am sure that there is some optimization still left to be done. If ;you find a saving somewhere along the line, do let me know.
    ;
    ; Another idea for a 256 compo? - 256 scramble. Could be fun.
    ;
    ; James David Chapman 1999. ;----------------------------------------------------------------------------- ;Features:
    ; Cool looking blocks Almost as good as graphics mode ones.
    ; Random shape Taken from the timer.
    ; Random colours Also taken from timer.
    ; Rotatable shape I hated writing this bit, as expected. ; Block stop check Stops blocks when they hit another one ; Solidity Prevent sideways crashing into blocks. ; Dual loop timing Allows for multiple input per advance. ; End of game effect More of a useful side effect really!
    ; Full lines removed A quickly cobbled together routine.
    ; Frame Sets a maximum 10 block width for game. ; End program key Better than using Control-C etc.
    ;No space for:
    ; Scoring +2 for a line, +4 if the bottom line.. ; Beeps a simple beep on line removal...
    ; Speedup should increase in speed over time...
    ; Graphics mode I had a lovely graphics version, and
    ; Nice enlarge effect a cool block effect which was too big. ;----------------------------------------------------------------------------- [[code]] ;-----------------------------------------------------------------------------
    ;(c) JDC 1999.
    ;jchap@globalnet.co.uk
    ;http://www.users.globalnet.co.uk/~jchap/ ;-----------------------------------------------------------------------------



    I've used the saved space to tick off the beep on line removal [8] & a simple score [22]
    (1 point per line cleared)


    Here's my hexdump:

    B80100CD106800B807531FE44089C383E30774F7B401C1E0032E8A9FF701C1E3 04BFC4FF83C750BD040091914D74F560BED20789F7B90A00B20826AD20E2ABE2 F9ADB8BA09AB741083C7502EFE06FF0160B402B207CD216183EF6883EE68ABAD 73D32EA0FF01D40A0D3030BF1800268825AFAA6189FE53A01704D0E87301AFD0 E873024F4FD0E87302CD20D0E87312B110BA1111C1C304D1D27302D1CBE2F589 D3B00899E8240074045B89F7525ABADA03E817007403E952FFB104ECA80874FB ECA80875FBE2F491682B0160B91000F6C103750383C748D1C3731A08D2741326 0A755081FF8007720208C6ABE2E184C661C3260A35AFEBF4E2C66C4EF066E800


    WK: used DOS int 21 for the beep, int 20 for exit

    His Home page has gone, so I haven't been able to contact him.

    --
    Bah, and indeed, Humbug.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From wolfgang kern@21:1/5 to All on Sat Feb 27 16:15:08 2021
    On 26.02.2021 12:34, Kerr-Mudd,John wrote:
    < Here's my hexdump:

    and here is what I see :) (thick glasses wont help)

    0100 B80100 |CD10 mode01 rare supported today
    0105 6800B8 |07 es = screen
    0109 53 |1F ds = bx bx=0 ?
    010b E440 |89C3 in[40] bx=ax
    010f 83E307 |74f7 AND ax,07 JZ 114+f7=010b
    0114 B401 ah=1
    0116 C1E003 SHL ax,3
    0119 2E8A9FF701 bl=cs:01f7+bx
    011e C1E304 SHL bx,4
    0121 BFC4FF di=ffc4

    0124 83C750 ADD di,50
    0127 BD0400 bp=0400
    012a 91
    012b 91 swap ax,cx
    012c 4D DEC bp
    012d 74F5 JZ 0124
    012f 60 pusha
    0130 BED207 |89F7 si=07d2 di=si

    0135 B90A00 |B208 cx=07d2 dl=08

    013a 26AD es:LODSW
    013c 20E2 AND dl,ah
    013e AB |E2 F9 STOSW LOOP 141+f9=013a

    0141 AD |B8BA09 ?LODSW? ax= 09ba ;║ blue/blink/high
    0145 AB |7410 STOSW JZ 0158
    0148 83C750 ADD di,50
    014b 2EFE06FF01 INC byte[cs:01ff]
    0150 60 PUSHA
    0151 B402 |B207 |CD21 INT21_02/07
    0157 61 POPA

    0158 83EF68 |83EE68 SUB si,68 SUB di 68
    015e AB |AD STOSW LODSW
    0160 73D3 JNC 162+d3= 0135
    0162 2EA0FF01|D40A al=[cs:-1ff] AAM
    0168 0D3030 |BF1800 OR ax,3030 di=1800
    016e 268825 [es:di]=ah
    0171 AF |AA SCASW STOSB
    0173 61 |89FE |53 POPA si=di inc bx
    0177 A01704 |D0E8 al=[0417] SHR al,1
    017c 7301 |AF JNC 017f
    017f D0E8 |7302 SHR al,1 JNC 0175
    0183 4F4F di-2
    0185 D0E8 |7302 SHR al,1 JNC 017b
    0189 CD20 ;end
    018b D0E8 |7312 SHR al,1 JNC 18f+12=01a1
    018f B110 |BA1111 cl=10 dx=1111

    0194 C1C304 ROL bx,4
    0197 D1D2 |7302 RLC dx,1 JNC 019f
    019b D1CB |E2F5 ROR bx,1 LOOP f5+19f=0194

    019f 89D3 bx=dx
    01a1 B008 |99 al=8 cwd
    01a4 E82400 |7404 CALL 01cB
    01a9 5B |89F7 POP bx di=si
    01ac 52 POP dx
    01ad 5A |BADA03 PUSH dx dx=03da
    01b1 E81700 |7403 CALL 01cd JZ 01b9
    01b6 E942ff JMP 1b9+ff42= 00fb ???

    01b9 b104 cl=4

    01bb EC |A808 |75FB in ax,dx TEST al,08 JNZ 01bb

    01c0 EC |A808 |75FB
    01c5 E2F4 LOOP 01bb
    01c7 91 |682B01 SWAP ax cx PUSH 0128
    01cb 60 B91000 PUSHA cx=0010

    01cf F6C103 7503 TEST cl,3 JNZ 01d7
    01d4 83C748 ADD di,48
    01d7 D1C3 |731A ROL bx,1 JNC 1db+1a=01f5
    01db 08D2 |7413 OR dl,dl JZ 1df+13=01f2
    01df 260A7550 OR dh,[es:di+50]
    01e3 81FF8007 |7202 CMP di,0780 JC 01eb
    01e9 08C6 OR dh,al
    01eb AB STOSW
    91ec E2E1 LOOP 1ee+e1=01cf
    01ee 84C6 61 C3 TEST dh,al POPA RET

    01f2 260A35 OR dh,[es:fdi]
    01f5 AF EBF4 SCASW JMP 1f8+f4= 01ec
    01f8 E2C6 LOOP 1fa+c6= 01c0
    01fa 6C 4E INSB DEC si
    01fc F066E800 LOCK BIG CALL ??? crash!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kerr-Mudd,John@21:1/5 to nowhere@nospicedham.never.at on Sat Feb 27 20:52:04 2021
    On Sat, 27 Feb 2021 15:15:08 GMT, wolfgang kern
    <nowhere@nospicedham.never.at> wrote:

    On 26.02.2021 12:34, Kerr-Mudd,John wrote:
    < Here's my hexdump:

    and here is what I see :) (thick glasses wont help)

    in the following I've added labels above; and comment below sections


    0100 B80100 |CD10 mode01 rare supported today
    wide screen 40*25 for text tetris

    0105 6800B8 |07 es = screen
    0109 53 |1F ds = bx bx=0 ?
    yup ; allows access to keystate at 0000:0x417

    010b E440 |89C3 in[40] bx=ax
    010f 83E307 |74f7 AND ax,07 JZ 114+f7=010b
    0114 B401 ah=1
    0116 C1E003 SHL ax,3
    0119 2E8A9FF701 bl=cs:01f7+bx
    load shape from table

    011e C1E304 SHL bx,4
    random shape, colour (with hilight bit on)

    0121 BFC4FF di=ffc4
    start posn


    0124 83C750 ADD di,50
    0127 BD0400 bp=0400
    nope; bp=0004
    012a 91 swap ax,cx


    mainloop:
    012b 91 swap ax,cx
    restore ax
    012c 4D DEC bp
    012d 74F5 JZ 0124
    do 4 times

    012f 60 pusha
    0130 BED207 |89F7 si=07d2 di=si

    0135 B90A00 |B208 cx=07d2 dl=08
    no! cx=0A; line lth ; dl=8=hilite attribute bit set

    013a 26AD es:LODSW
    013c 20E2 AND dl,ah
    test if full line (all 10 attributes high)
    013e AB |E2 F9 STOSW LOOP 141+f9=013a

    0141 AD |B8BA09 ?LODSW? ax= 09ba ;║ blue/blink/high
    bright blue double vertical lines at edge
    0145 AB |7410 STOSW JZ 0158
    flag still valid from last AND

    0148 83C750 ADD di,50
    drop line
    014b 2EFE06FF01 INC byte[cs:01ff]
    up score

    0150 60 PUSHA
    0151 B402 |B207 |CD21 INT21_02/07
    0157 61 POPA
    beep

    0158 83EF68 |83EE68 SUB si,68 SUB di 68
    015e AB |AD STOSW LODSW
    0160 73D3 JNC 162+d3= 0135
    ; have printed screen

    0162 2EA0FF01|D40A al=[cs:-1ff] AAM
    0168 0D3030 |BF1800 OR ax,3030 di=1800
    016e 268825 [es:di]=ah
    0171 AF |AA SCASW STOSB
    print score

    0173 61 |89FE |53 POPA si=di inc bx
    0177 A01704 |D0E8 al=[0417] SHR al,1
    querykeys

    017c 7301 |AF JNC 017f scasw
    017f D0E8 |7302 SHR al,1 JNC 0175
    0183 4F4F di-2
    left-2, right+2

    0185 D0E8 |7302 SHR al,1 JNC 017b
    0189 CD20 ;end
    018b D0E8 |7312 SHR al,1 JNC 18f+12=01a1
    018f B110 |BA1111 cl=10 dx=1111

    0194 C1C304 ROL bx,4
    0197 D1D2 |7302 RLC dx,1 JNC 019f
    019b D1CB |E2F5 ROR bx,1 LOOP f5+19f=0194

    019f 89D3 bx=dx
    rotate shape

    01a1 B008 |99 al=8 cwd
    01a4 E82400 |7404 CALL 01cB
    01a9 5B |89F7 POP bx di=si
    01ac 52 POP dx
    01ad 5A |BADA03 PUSH dx dx=03da
    01b1 E81700 |7403 CALL 01cd JZ 01b9
    01b6 E942ff JMP 1b9+ff42= 00fb ???
    ; 10b; jnz newblock

    sadly the jmp back is too far for a short jnz


    01b9 b104 cl=4
    delay count

    01bb EC |A808 |75FB in ax,dx TEST al,08 JNZ 01bb

    01c0 EC |A808 |75FB
    01c5 E2F4 LOOP 01bb
    01c7 91 |682B01 SWAP ax cx PUSH 0128
    save ax, ret to mainloop later

    test/putrtn:
    01cb 60 B91000 PUSHA cx=0010

    01cf F6C103 7503 TEST cl,3 JNZ 01d7
    01d4 83C748 ADD di,48
    01d7 D1C3 |731A ROL bx,1 JNC 1db+1a=01f5
    01db 08D2 |7413 OR dl,dl JZ 1df+13=01f2
    01df 260A7550 OR dh,[es:di+50]
    test next line clear

    01e3 81FF8007 |7202 CMP di,0780 JC 01eb
    01e9 08C6 OR dh,al
    01eb AB STOSW
    91ec E2E1 LOOP 1ee+e1=01cf
    01ee 84C6 61 C3 TEST dh,al POPA RET

    01f2 260A35 OR dh,[es:di]
    test overwrite posn is clear

    01f5 AF EBF4 SCASW JMP 1f8+f4= 01ec

    data:
    01f8 E2C6 LOOP 1fa+c6= 01c0
    01fa 6C 4E INSB DEC si
    01fc F066E800 LOCK BIG CALL ??? crash!
    these last bytes are the tetris shape data!
    (final byte is for the score)

    --
    Bah, and indeed, Humbug.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From wolfgang kern@21:1/5 to All on Sun Feb 28 15:07:28 2021
    On 26.02.2021 12:34, Kerr-Mudd,John wrote:

    as you can see, I cannot trust my eyes anymore, every point starts
    shifting and blurring, so I better give up on anal-ice hex-dumps.
    But it was really funny for many years. Thanks!
    __
    wolfgang

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)