wargames: more complete version

This commit is contained in:
Vince Weaver 2021-09-15 08:23:22 -04:00
parent 5c4451b507
commit ae23580743
4 changed files with 443 additions and 81 deletions

View File

@ -12,15 +12,15 @@ all: wargames.dsk
wargames.dsk: HELLO WARGAMES
cp $(EMPTY_DISK) wargames.dsk
$(DOS33) -y wargames.dsk SAVE A HELLO
$(DOS33) -y wargames.dsk BSAVE -a 0x1000 WARGAMES
$(DOS33) -y wargames.dsk BSAVE -a 0xc00 WARGAMES
###
WARGAMES: wargames.o
ld65 -o WARGAMES wargames.o -C ../../linker_scripts/apple2_1000.inc
ld65 -o WARGAMES wargames.o -C ../../linker_scripts/apple2_c00.inc
wargames.o: wargames.s ssi263.inc ssi263_detect.s ssi263_simple_speech.s \
map.lzsa
map.lzsa coords.inc
ca65 -o wargames.o wargames.s -l wargames.lst
###
@ -33,6 +33,19 @@ map.hgr: map.png
###
coords.inc: make_coords coords.txt
./make_coords < coords.txt > coords.inc
###
make_coords: make_coords.o
$(CC) -o make_coords make_coords.o $(LFLAGS) -lm
make_coords.o: make_coords.c
$(CC) $(CFLAGS) -c make_coords.c
###
HELLO: hello.bas
$(TOKENIZE) < hello.bas > HELLO
@ -40,6 +53,5 @@ HELLO: hello.bas
####
clean:
rm -f *~ *.o *.lst HELLO WARGAMES
rm -f *~ *.o *.lst HELLO WARGAMES make_coords

View File

@ -0,0 +1,217 @@
#include <stdio.h>
#include <math.h>
static int debug=0;
static void make_coord_line(int frame,int x,int y,int destx,int desty) {
int status, xh,xl, yh,yl;
double theta,dx,dy;
int dxi,dyi,dxh,dxl,dyh,dyl;
int closestx,closesty,distance,closest;
// status frame x/x y/y dx/dx dy/dy destx desty/radius
status=0;
xl=0; xh=x;
yl=0; yh=y;
if ((destx-x)!=0) {
theta=atan2((desty-y),(destx-x));
dx=cos(theta);
dy=sin(theta);
}
else {
if (debug) printf("; VERTICAL\n");
theta=0;
dx=0;
dy=1;
}
dxi=dx*256;
dyi=dy*256;
dxh=(dxi>>8)&0xff;
dxl=dxi&0xff;
dyh=(dyi>>8)&0xff;
dyl=dyi&0xff;
if (debug) {
printf("; theta=%lf dx=%lf dy=%lf\n",theta,dx,dy);
printf("; dxh=%d dxl=%d\n",dxh,dxl);
printf("; dyh=%d dyl=%d\n",dyh,dyl);
}
{ int i,blahx,blahy;
blahx=xh*256;
blahy=yh*256;
closest=1000000;
closestx=0;
closesty=0;
for (i=0;i<200;i++) {
distance=sqrt((blahx/256-destx)*(blahx/256-destx)+
(blahy/256-desty)*(blahy/256-desty));
if (distance<closest) {
closestx=blahx/256;
closesty=blahy/256;
closest=distance;
}
blahx+=dxi;
blahy+=dyi;
}
if (debug) printf("; Found closest at %d %d\n",closestx,closesty);
}
printf(".byte $%02X, %d, %d,$%02X, %d,$%02X, "
"$%02x,$%02X, $%02x,$%02X, %d,%d\n",
status,frame,xh,xl,yh,yl,
dxh&0xff,dxl&0xff,
dyh&0xff,dyl&0xff,
closestx,closesty);
}
double func(double x,
double x1,double x2,
double ystart,double height) {
double center_x,width;
double top;
center_x=(x1+x2)/2;
width=fabs(x1-x2);
top=ystart-height;
return top+(ystart-top)*(x-center_x)*(x-center_x)/((width/2)*(width/2));
}
static void make_coord_parab(int frame,int x,int y,int destx,int height) {
int status;
// int closestx,closesty,distance,closest;
int i;
double last,last2,diff=0;
double urgh=-3.5, zurgh=0.1,current;
int u,z;
int direction;
if (x>destx) direction=-1;
else direction=1;
last=0,last2=0;
if (debug) printf("; x=%d destx=%d y=%d height=%d\n",
x,destx,y,height);
if (debug) printf("; center_x=%d width=%d top=%d\n",
(x+destx)/2,
(x-destx),
y-height);
for(i=x;i!=destx;i+=direction) {
current=func(i,x,destx,y,height);
if (debug) printf("; %d %lf -- %lf %lf\n",i,current,
current-last,last2-(current-last));
diff=(current-last)-last2;
last2=current-last;
last=current;
}
urgh=func(x+direction,x,destx,y,height)-func(x,x,destx,y,height);
zurgh=diff;
u=urgh*256; z=zurgh*256;
if (debug) printf("; $%02X $%02X, $%02X $%02X\n",(u>>8)&0xff,u&0xff,
(z>>8)&0xff,z&0xff);
#if 0
{ int i,blahx,blahy;
blahx=xh*256;
blahy=yh*256;
closest=1000000;
closestx=0;
closesty=0;
for (i=0;i<200;i++) {
distance=sqrt((blahx/256-destx)*(blahx/256-destx)+
(blahy/256-desty)*(blahy/256-desty));
if (distance<closest) {
closestx=blahx/256;
closesty=blahy/256;
closest=distance;
}
blahx+=dxi;
blahy+=dyi;
}
printf("; Found closest at %d %d\n",closestx,closesty);
}
#endif
status=0;
printf(".byte $%02X, %d, %d,$%02X, %d,$%02X, "
"$%02x,$%02X, $%02x,$%02X, %d,%d\n",
status,frame,
x,direction&0xff,y,0x00,
(u>>8)&0xff,u&0xff,
(z>>8)&0xff,z&0xff,
destx,255);
}
int main(int argc, char **argv) {
char string[BUFSIZ];
char *ptr;
int x,y;
int type, frame;
int destx, desty;
while(1) {
ptr=fgets(string,BUFSIZ,stdin);
if (ptr==NULL) break;
if (string[0]=='#') continue;
sscanf(string,"%d %d %d %d %d %d",
&type,&frame,&x,&y,&destx,&desty);
if (type==0) {
make_coord_line(frame,x,y,destx,desty);
}
else if (type==1) {
make_coord_parab(frame,x,y,destx,desty);
}
else {
fprintf(stderr,"Error, unknown type %d\n",type);
}
}
printf(".byte $FE\n");
return 0;
}
// 10,10 100,100 slope=90/90=1
//
//
//
//
//
//

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -5,6 +5,9 @@
.include "hardware.inc"
FRAME_ADD = $40
EXPLOSION_RADIUS= 10
VGI_CCOLOR = P0
VGI_CX = P1
VGI_CY = P2
@ -18,12 +21,15 @@ BASH = $28
HGR_COLOR = $E4
DRAW_PAGE = $FA
OUTL = $FB
OUTH = $FC
MISSILE_LOW = $FD
MISSILE_HIGH = $FE
FRAME = $FF
FRAMEL = $F8
FRAMEH = $F9
CURRENT_MISSILE = $FA
DRAW_PAGE = $FB
OUTL = $FC
OUTH = $FD
MISSILE_LOW = $FE
MISSILE_HIGH = $FF
STATUS_WAITING = $00
STATUS_MOVING = $01
@ -42,7 +48,12 @@ MISSILE_DY_H = 8
MISSILE_DY_L = 9
MISSILE_DEST_X = 10
MISSILE_DEST_Y = 11
MISSILE_RADIUS = 12
MISSILE_RADIUS = 11
MISSILE_P_DY_H = 6
MISSILE_P_DY_L = 7
MISSILE_P_DDY_H = 8
MISSILE_P_DDY_L = 9
.include "ssi263.inc"
@ -55,6 +66,8 @@ wargames:
;===========================
;===========================
; jmp exchange ; debug
jsr HOME
lda #<header
@ -90,7 +103,7 @@ wargames:
; exchange
;===========================
;===========================
exchange:
jsr HGR
lda #<map_lzsa
@ -104,18 +117,30 @@ wargames:
lda #0
sta FRAME
missile_loop:
sta FRAMEL
sta FRAMEH
jsr move_and_print
outer_missile_loop:
lda #<missiles
sta MISSILE_LOW
lda #>missiles
sta MISSILE_HIGH
ldy #0
inner_missile_loop:
ldy #MISSILE_STATUS
lda (MISSILE_LOW),Y
cmp #$FE ; means all done
bne more_missiles
jmp really_done_missile
more_missiles:
; see if totally done
lda (MISSILE_LOW),Y
bpl keep_going
jmp done_missile_loop
keep_going:
@ -128,7 +153,7 @@ keep_going:
ldy #MISSILE_START_FRAME
lda (MISSILE_LOW),Y
cmp FRAME
cmp FRAMEH
beq missile_activate
jmp done_missile_loop ; not ready
@ -155,55 +180,16 @@ missile_draw:
jsr HPLOT0 ; plot at (Y,X), (A)
missile_move:
; add X
clc
ldy #MISSILE_DX_L
lda (MISSILE_LOW),Y
ldy #MISSILE_X_FRAC
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
ldy #MISSILE_DX_H
lda (MISSILE_LOW),Y
ldy #MISSILE_X
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
; add Y
clc
ldy #MISSILE_DY_L
lda (MISSILE_LOW),Y
ldy #MISSILE_Y_FRAC
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
ldy #MISSILE_DY_H
lda (MISSILE_LOW),Y
ldy #MISSILE_Y
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
; see if at end
ldy #MISSILE_Y
lda (MISSILE_LOW),Y
ldy #MISSILE_DEST_Y
cmp (MISSILE_LOW),Y
bne not_match
ldy #MISSILE_X
lda (MISSILE_LOW),Y
ldy #MISSILE_DEST_X
cmp (MISSILE_LOW),Y
bne not_match
cmp #$FF
beq a_parab
is_match:
lda #STATUS_EXPLODING
ldy #MISSILE_STATUS
sta (MISSILE_LOW),Y
not_match:
jsr missile_move_line
jmp done_missile_loop
a_parab:
jsr missile_move_parab
jmp done_missile_loop
missile_explode:
@ -219,7 +205,7 @@ missile_explode:
sta VGI_CR
cmp #12
cmp #EXPLOSION_RADIUS
bcc not_done_explosion
lda #STATUS_DONE
@ -241,23 +227,44 @@ not_done_explosion:
done_missile_loop:
clc
lda MISSILE_LOW
adc #12
sta MISSILE_LOW
lda #0
adc MISSILE_HIGH
sta MISSILE_HIGH
jmp inner_missile_loop
really_done_missile:
lda #50
jsr WAIT
inc FRAME
beq done_missiles
clc
lda FRAMEL
adc #FRAME_ADD
sta FRAMEL
lda FRAMEH
adc #0
sta FRAMEH
jmp missile_loop
cmp #$90
bcs done_missiles
jmp outer_missile_loop
done_missiles:
;============================
; print WINNER: NONE
jsr HOME
jsr move_and_print
jsr wait_1s
jsr wait_1s
;=========================================
@ -271,6 +278,7 @@ done_missiles:
jsr move_and_print
jsr wait_1s
jsr wait_1s
jsr normal_text
@ -538,6 +546,10 @@ header:
.byte 0,3,"NATO / WARSAW PACT",0
.byte 27,3,"NONE",0
.byte 0,4,"FAR EAST STRATEGY",0
far_east:
.byte 11,21,"FAR EAST STRATEGY",0
winner:
.byte 14,21,"WINNER: NONE",0
@ -553,20 +565,6 @@ ending:
; .byte "HOW ABOUT A NICE GAME OF CHESS",0
missiles:
.byte $00 ; status
.byte $10 ; start frame
.byte 10,$10 ; x-location
.byte 50,$10 ; y-location
.byte $01,$00 ; deltax
.byte $00,$00 ; deltay
.byte 100,50 ; destination
.byte $00 ; radius
.byte $00,$00,$00 ; padding
;===================
; next step
;===================
@ -595,3 +593,138 @@ wait_1s_loop:
bne wait_1s_loop
rts
;============================
; missile move line
;============================
missile_move_line:
; add X
clc
ldy #MISSILE_DX_L
lda (MISSILE_LOW),Y
ldy #MISSILE_X_FRAC
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
ldy #MISSILE_DX_H
lda (MISSILE_LOW),Y
ldy #MISSILE_X
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
; add Y
clc
ldy #MISSILE_DY_L
lda (MISSILE_LOW),Y
ldy #MISSILE_Y_FRAC
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
ldy #MISSILE_DY_H
lda (MISSILE_LOW),Y
ldy #MISSILE_Y
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
; see if at end
ldy #MISSILE_Y
lda (MISSILE_LOW),Y
ldy #MISSILE_DEST_Y
cmp (MISSILE_LOW),Y
bne not_match
ldy #MISSILE_X
lda (MISSILE_LOW),Y
ldy #MISSILE_DEST_X
cmp (MISSILE_LOW),Y
bne not_match
is_match:
lda #STATUS_EXPLODING
ldy #MISSILE_STATUS
sta (MISSILE_LOW),Y
lda #0
ldy #MISSILE_RADIUS
sta (MISSILE_LOW),Y
not_match:
rts
;============================
; missile move parabola
;============================
missile_move_parab:
; add X
clc
ldy #MISSILE_X_FRAC
lda (MISSILE_LOW),Y
ldy #MISSILE_X
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
; add Y
clc
ldy #MISSILE_P_DY_L
lda (MISSILE_LOW),Y
ldy #MISSILE_Y_FRAC
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
ldy #MISSILE_P_DY_H
lda (MISSILE_LOW),Y
ldy #MISSILE_Y
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
; add dY
clc
ldy #MISSILE_P_DDY_L
lda (MISSILE_LOW),Y
ldy #MISSILE_P_DY_L
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
ldy #MISSILE_P_DDY_H
lda (MISSILE_LOW),Y
ldy #MISSILE_P_DY_H
adc (MISSILE_LOW),Y
sta (MISSILE_LOW),Y
; see if at end
ldy #MISSILE_X
lda (MISSILE_LOW),Y
ldy #MISSILE_DEST_X
cmp (MISSILE_LOW),Y
bne not_parab_match
is_parab_match:
lda #STATUS_EXPLODING
ldy #MISSILE_STATUS
sta (MISSILE_LOW),Y
lda #0
ldy #MISSILE_RADIUS
sta (MISSILE_LOW),Y
not_parab_match:
rts
; status frame x/x y/y dx/dx dy/dy destx desty/radius
missiles:
parabolas:
;.byte $00, 4, 164,$00, 75,$00, $FC,$8C, $00,$16, 80,255
.include "coords.inc"
; status grame x/x y/y dy/dy ddy/ddy destx/desty