Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

<lilo> Fairlight: udp is the light margarine of tcp/ip transport protocols :) -- Seen on #Linux


programming / comp.lang.asm.x86 / Re: pong 256 bytes

Subject: Re: pong 256 bytes
From: Kerr-Mudd,John
Newsgroups: alt.lang.asm, comp.lang.asm.x86
Organization: dis
Date: Mon, 9 Sep 2019 09:59 UTC
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: notsay...@nospicedham.invalid.org (Kerr-Mudd,John)
Newsgroups: alt.lang.asm,comp.lang.asm.x86
Subject: Re: pong 256 bytes
Date: Mon, 9 Sep 2019 09:59:22 -0000 (UTC)
Organization: dis
Lines: 271
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <XnsAAC56FD57254admin127001@144.76.35.198>
References: <XnsAAACA2EB9767Dadmin127001@144.76.35.198> <5d55acc7$0$31410$426a74cc@news.free.fr> <XnsAAACCF2D3678admin127001@144.76.35.198> <5d570a2e$0$3376$426a74cc@news.free.fr> <XnsAAADDDEF89029admin127001@144.76.35.198> <5d5724b6$0$6468$426a34cc@news.free.fr> <XnsAAAE628A5F2B4admin127001@144.76.35.198> <XnsAABDC809FE765admin127001@144.76.35.198> <5d6c3b18$0$15185$426a74cc@news.free.fr> <XnsAABE62AA7444Eadmin127001@144.76.35.198> <5d6cfa9a$0$21584$426a74cc@news.free.fr> <XnsAABEA7F809BB1admin127001@144.76.35.198> <5d6d4faf$0$15196$426a34cc@news.free.fr> <XnsAABEC212AE02Eadmin127001@144.76.35.198> <XnsAABF60BC267B7admin127001@144.76.35.198> <c1.2b8.46N5HB$06q@NOVOSAD3.EMBARQ.COM> <XnsAABF86B7DECE0admin127001@144.76.35.198> <c1.2b8.46NhKb$06r@NOVOSAD3.EMBARQ.COM> <XnsAAC0D436BAB79admin127001@144.76.35.198> <XnsAAC1B5B549C5Cadmin127001@144.76.35.198> <XnsAAC2887FF86B3admin127001@144.76.35.198> <c1.2b8.46RD7g$06s@NOVOSAD3.EMBARQ.COM>
Injection-Info: h2725194.stratoserver.net; posting-host="8b3e28c6c86ec14f2dadd20ea01a94e2";
logging-data="21963"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194TEYNU+KPfXGRPXbYGmo2PtApVqhHt5g="
User-Agent: Xnews/2006.08.24
Cancel-Lock: sha1:NHkYChMGwfrtCQbnHQ/H62wUA9Q=
View all headers
Pong in <256 for 8086, MCGA.
Alt=Dn,Ctl=Up, any key to exit
Score shown on top line, currently game resets after 6 losses.

Hex:

aB013CD10B800A0500731FF31C949F3AABA5F0052BD0100BEA000B864FF00E03C
0274043CC67502F6DC01EE89C389F7B60EE897005B81FEE600720D502C0538D8
587405720243434BBF3D01E84D0074B453723297B402CD16A804740142A80874
014AB401CD16752C52BADA03ECA80875F8ECA80874FB5B9731FFFDE81D00FC59
748289DA519C89C389F7B600E83C009D738BEB83B80300CD1058C3B10238CB72
06B1BD38CB720288CB39FE750D38D8722E8D4F0A38C87327F7DDB60AB10AE80A
00E2FBB600E8030080EB0C575052B84001B700F7E34301C75A268835585FC357
5081F73D01268A059840AB3C06B90F0091F3AB585F9CE8C1FF9DC3


Source Code nasm: comments welcome:
(I hope I've killed all the spare tabs; apologies for any format
messiness)

; SMALLPONG v2.1j5f
org 0x100;; MJ 251!  works!
;;
;;dots show score on top line; held as colour; prt white dots as score
; from Brad Smith's pong21 255; 6/29/2008
;http://rainwarrior.ca/dragon/pong256.html
cpu 8086
%define  SCREEN_WIDTH        320
%define  SCREEN_HEIGHT       200
%define  SCREEN_X_MID        SCREEN_WIDTH / 2
%define  SCREEN_Y_MID        SCREEN_HEIGHT / 2
%define  SCREEN_SIZE         SCREEN_WIDTH * SCREEN_HEIGHT

%define  PADDLE_LEFT_X       0
%define  paddle_left_y       dx  ; dl ; dh=prtclr
%define  PADDLE_RIGHT_X      SCREEN_WIDTH  - 3 ; (was -1) make visible on
my scrn
;%define  paddle_right_y     ; now on stack
%define  PADDLE_TOP          2 ; allow top line for score
%define  PADDLE_MID          SCREEN_Y_MID - (PADDLE_SIZE/2)
%define  PADDLE_BOTTOM       (SCREEN_HEIGHT-1) - PADDLE_SIZE

%define  ball_x              si
%define  ball_y              ax ; actually al ; ah is dircn
%define  ball_dx             bp ;word [BALL_DX]
%define  ball_dy             ah ; -1 at start
;; %define temp1             cx
%define  BALL_MID_X          SCREEN_X_MID
%define  BALL_MID_Y          SCREEN_Y_MID
%define  BALL_TOP            PADDLE_TOP
%define  BALL_BOTTOM         SCREEN_HEIGHT-2 ;; (PADDLE_BOTTOM +
PADDLE_SIZE) - 1

%define  PADDLE_SIZE         10
%define  AI_THRESHOLD        SCREEN_WIDTH - 90
%define  LOSE_LIMIT          6

Black    equ 0
Blue     equ 1
Green    equ 2
Red      equ 4
Yellow   Equ Bright+Green+Red
White    equ 7
Bright   equ 8
PADDLE_COLOUR equ Bright+Green
SCORE_COLOUR  equ Bright+White
BALL_COLOUR   equ Yellow
start:
         mov al,0x13         ; set VGA 320x200 [9]
         int 0x10
new_game:
         mov ax,0xA000
        push ax
        pop es               ; es:di pts to screen
         xor di,di           ; cls
         xor cx,cx
         dec cx              ;FA00 + a bit
         rep stosb           ;need al=0! also resets scores to 0
         mov paddle_left_y,PADDLE_MID
;         mov paddle_right_y,paddle_left_y
        push  paddle_left_y  ;paddle_right_y on stack
         mov ball_dx,1

game_loop:

;set_new_ball:  ; top of loop
         mov ball_x,BALL_MID_X
         mov ax,BALL_MID_Y+0x100*-1 ; ah<=-1
no_new:

;move_ball:      add movement to ball_x,ball_y
         add al,ball_dy      ; move ball vert
         cmp al,BALL_TOP     ; chk bounce vertical
         je invert_dy
         cmp al,BALL_BOTTOM
         jne ball_not_bottom
       invert_dy:
         neg ball_dy
         ball_not_bottom:
         add ball_x,ball_dx  ; move ball hztl

;prt_ball:
         mov bx,ball_y
         mov di,ball_x
         mov dh,BALL_COLOUR
         call put_pixel      ; plot at (X,Y) di,bx : color dl

;right_paddle_AI:
;        mov bx,paddle_right_y
        pop bx ;paddle_right_y
         cmp ball_x,AI_THRESHOLD
         jc no_move
       push ax
         sub al,(PADDLE_SIZE / 2)
         cmp al,bl ; ball_y v paddle_right_y
       pop ax
         jz no_move
         jc mv_up
         inc bx
         inc bx
        mv_up:
         dec bx
        end_ai:
        no_move:

;draw_right_paddle: ; reqs ballx/y
;        mov paddle_right_y,bx
         mov di,PADDLE_RIGHT_X
         call do_paddle      ; paddle at (X,Y) di,bx
         jz new_game
        push bx              ; store paddle_right_y
         jc new_ball

         ;; ry on stack, bx=ly
;left_paddle_move: inkey to al, dx up/dn
         xchg ax,di          ; save ball_y
         mov ah,2            ; get keyshift status
         int 0x16
         test al,4 ;Ctrl
         jz not_dn
         inc paddle_left_y   ; move paddle down
    not_dn:
         test al,8 ;Alt
         jz not_up
         dec paddle_left_y   ; move paddle up
    not_up:
;         cmp al,3  ; both shifts to exit - also txt mode
;         jne game_loop
 ;        cbw
         mov ah,1            ; any key to exit
         int 0x16
         jnz Quit
;         jz game_loop
;delay_: ;  wait for vsync [15]
       push paddle_left_y
   vsync_active:
         mov dx,0x03DA       ; checking retrace
         in al,dx
         test al,8
         jnz vsync_active
   vsync_retrace:
         in al,dx
         test al,8
         jz vsync_retrace
       pop bx                ; mov bx,paddle_left_y

;         mov ax,ball_y
         xchg ax,di          ; restore ball_y
;draw_left_paddle:  ; ball_x, ball_y, di=PADDLE_X, bx=paddle_y
        ; bx=paddle_y already
         xor di,di           ; di=PADDLE_LEFT_X
         std                 ; for score drawing
         call do_paddle      ; paddle at (X,Y) di,bx
         cld
        pop cx               ; drop PR_Y if restarting
         jz new_game
         mov paddle_left_y,bx
        push cx

new_ball: ; must clr old ball 1st!
        pushf
;clear_ball:
         mov bx,ball_y
         mov di,ball_x
 ;        cwd ; dl=0  ? not always
         mov dh,Black        ; clear ball
         call put_pixel      ; plot at (X,Y) di,bx : color dl
        popf
         jnc no_new          ; cy means new ball
        ; jc set_new_ball
         jmp game_loop

Quit:
         mov ax,0x0003       ; back to txt mode
         int 0x10
        pop ax               ; tidy stack (or just int 0x20 also 2)
Exit:    ret

;------------------------------------------------------------
do_paddle: ; si=ball_x, al=ball_y, di=PADDLE_X, bx=paddle_y
;clamp_paddle: ; [14]   clamps bx to [PADDLE_TOP,PADDLE_BOTTOM]
         mov cl,PADDLE_TOP
         cmp bl,cl
         jc doclamp
         mov cl,PADDLE_BOTTOM
         cmp bl,cl
         jc noclamp
     doclamp:
         mov bl,cl
     noclamp:
;collide_paddle: ;  si=ball_x, al=ball_y, di=PADDLE_X, bx=paddle_y
         cmp ball_x,di
         jnz no_collide      ; no x match
         cmp al,bl           ; ball v bat top
         jc bat_miss         ; ball above bat
         lea cx,[bx+PADDLE_SIZE]  ;; cx as temp;bh to ch? is 0!
         cmp al,cl
         jnc bat_miss        ; ball below bat
        ; jc bat_bounce
;bat_bounce:
         neg ball_dx         ; hit bat, bounce
no_collide:

draw_paddle: ; (position: (X,Y) di,bx colour: dh)
         mov dh,PADDLE_COLOUR
         mov cl,PADDLE_SIZE  ; ch=0?
draw_paddle_loop:
         call put_pixel
         loop draw_paddle_loop
         mov dh,Black
         call put_pixel      ; bot then fallthru for top
         sub bl,PADDLE_SIZE+2 ; bx precorrected in putrtn
put_pixel: ; plot pixel at (X,Y) di,bx colour dh
       push di
       push ax
       push dx
         mov ax,SCREEN_WIDTH ; so req 16 bit mul
         mov bh,0 ; dont x dircn!
         mul bx              ; hits ax,dx
         inc bx              ; down a row
         add di,ax           ; chg di ; nz ret!
       pop dx
         mov byte [es:di],dh ; cos of std/cld
       pop ax
       pop di
         retn                ; nz nc

bat_miss:
;put_score:  ; put score to opp corner!
      push di
       push ax
         xor di,PADDLE_RIGHT_X ; other corner
         mov al,byte [es:di]   ; prev score
         cbw                   ; short line!
         inc ax                ; new colour dot
         stosw                 ; save score
         cmp al,LOSE_LIMIT     ; zr or cy flags rtnd
         mov cx,0x100*0x0+SCORE_COLOUR   ; space blob
         xchg cx,ax
         rep stosw             ; NB cld/std
       pop ax
      pop di
       pushf
        call draw_paddle
       popf                    ; only way to keep flgs
        retn                   ; zr or cy still


--
Bah, and indeed, Humbug.



SubjectRepliesAuthor
o Re: pong 256 bytes

By: Kerr-Mudd,John on Mon, 9 Sep 2019

0Kerr-Mudd,John
rocksolid light 0.7.2
clearneti2ptor