1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-03-20 03:31:27 +00:00

More work on for/next

This commit is contained in:
David Schmenk 2018-03-04 13:15:02 -08:00
parent 2b2e464c9b
commit 5b41fd07c4
7 changed files with 132 additions and 130 deletions

View File

@ -162,38 +162,37 @@ export def fight(player, enemy)
if toupper(conio:getkey()) == 'R'
conio:echo(ECHO_OFF)
return 1
fin
//
// Turn player in random direction
//
player->angle = conio:rnd() & 7
//
// Calculate attack (with a little random variation)
//
p_atck = player->skill + player->energy / 10 - enemy->power / 25 + (conio:rnd() & 7)
e_atck = enemy->power - player->skill / 5 - player->energy / 20 + (conio:rnd() & 7)
if enemy->life > p_atck
enemy->life = enemy->life - p_atck
else
win
enemy->life = 0
p_atck = player->skill + enemy->power / 3
if p_atck > 100 // Limit skill
p_atck = 100
fin
player->skill = p_atck
//
// Turn player in random direction
// Unlink dead enemy from entities list
//
player->angle = conio:rnd() & 7
//
// Calculate attack (with a little random variation)
//
p_atck = player->skill + player->energy / 10 - enemy->power / 25 + (conio:rnd() & 7)
e_atck = enemy->power - player->skill / 5 - player->energy / 20 + (conio:rnd() & 7)
if enemy->life > p_atck
enemy->life = enemy->life - p_atck
else
win
enemy->life = 0
p_atck = player->skill + enemy->power / 3
if p_atck > 100 // Limit skill
p_atck = 100
fin
player->skill = p_atck
//
// Unlink dead enemy from entities list
//
if enemy == entities
entities = enemy=>next_other
fin
if enemy=>next_other
enemy=>next_other=>prev_other = enemy=>prev_other
fin
if enemy=>prev_other
enemy=>prev_other=>next_other = enemy=>next_other
fin
if enemy == entities
entities = enemy=>next_other
fin
if enemy=>next_other
enemy=>next_other=>prev_other = enemy=>prev_other
fin
if enemy=>prev_other
enemy=>prev_other=>next_other = enemy=>next_other
fin
if player->health > e_atck
player->health = player->health - e_atck

View File

@ -798,37 +798,37 @@ void emit_brne(int tag)
void emit_brgt(int tag)
{
emit_pending_seq();
printf("\t%s\t$88\t\t\t; BRGT\t_B%03d\n", DB, tag);
printf("\t%s\t$80\t\t\t; BRGT\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_brlt(int tag)
{
emit_pending_seq();
printf("\t%s\t$8A\t\t\t; BRLT\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_addbrle(int tag)
{
emit_pending_seq();
printf("\t%s\t$80\t\t\t; BRLE\t_B%03d\n", DB, tag);
printf("\t%s\t$82\t\t\t; BRLT\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_incbrle(int tag)
{
emit_pending_seq();
printf("\t%s\t$82\t\t\t; INCBRLE\t_B%03d\n", DB, tag);
printf("\t%s\t$84\t\t\t; INCBRLE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_subbrge(int tag)
void emit_addbrle(int tag)
{
emit_pending_seq();
printf("\t%s\t$84\t\t\t; BRGE\t_B%03d\n", DB, tag);
printf("\t%s\t$86\t\t\t; BRLE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_decbrge(int tag)
{
emit_pending_seq();
printf("\t%s\t$86\t\t\t; DECBRGE\t_B%03d\n", DB, tag);
printf("\t%s\t$88\t\t\t; DECBRGE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_subbrge(int tag)
{
emit_pending_seq();
printf("\t%s\t$8A\t\t\t; BRGE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_call(int tag, int type)
@ -1277,6 +1277,7 @@ int crunch_seq(t_opseq **seq, int pass)
op->code = SUBI_CODE;
freeops = 1;
}
break;
case BINARY_CODE(AND_TOKEN):
if (op->val >= 0 && op->val <= 255)
{

View File

@ -405,9 +405,10 @@ def idmatch(nameptr, len, idptr, idcnt)
while idcnt
if len == idptr->idname
for i = 1 to len
if nameptr->[i - 1] <> idptr->idname.[i]; break; fin
next
i = 1; while i <= len and nameptr->[i - 1] == idptr->idname.[i]; i++; loop
//for i = 1 to len
// if nameptr->[i - 1] <> idptr->idname.[i]; break; fin
//next
if i > len; return idptr; fin
fin
idptr = idptr + idptr->idname + t_id

View File

@ -36,11 +36,12 @@ def keymatch
loop
chrptr = tknptr - 1
while keywrds[keypos] == tknlen
for i = 1 to tknlen
if ^(chrptr + i) <> keywrds[keypos + i]
break
fin
next
i = 1; while i <= tknlen and ^(chrptr + i) == keywrds[keypos + i]; i++; loop
//for i = 1 to tknlen
// if ^(chrptr + i) <> keywrds[keypos + i]
// break
// fin
//next
if i > tknlen
return keywrds[keypos + keywrds[keypos] + 1]
fin

View File

@ -640,8 +640,8 @@ def parse_stmnt
if token <> FIN_TKN; exit_err(ERR_MISS|ERR_CLOSE|ERR_STATE); fin
break
is WHILE_TKN
prev_for = infor
infor = FALSE
prev_for = infor
infor = FALSE
tag_while = new_tag(RELATIVE_FIXUP)
tag_wend = new_tag(RELATIVE_FIXUP)
tag_prevcnt = cont_tag
@ -665,11 +665,11 @@ def parse_stmnt
emit_tag(tag_wend)
break_tag = tag_prevbrk
cont_tag = tag_prevcnt
infor = prev_for
infor = prev_for
break
is REPEAT_TKN
prev_for = infor
infor = FALSE
prev_for = infor
infor = FALSE
tag_repeat = new_tag(RELATIVE_FIXUP)
tag_prevbrk = break_tag
break_tag = new_tag(RELATIVE_FIXUP)
@ -693,11 +693,11 @@ def parse_stmnt
emit_seq(seq)
emit_tag(break_tag)
break_tag = tag_prevbrk
infor = prev_for
infor = prev_for
break
is FOR_TKN
prev_for = infor
infor = TRUE
prev_for = infor
infor = TRUE
stack_loop = stack_loop + 2
tag_for = new_tag(RELATIVE_FIXUP)
tag_prevcnt = cont_tag
@ -773,15 +773,14 @@ def parse_stmnt
emit_decbrge(tag_for)
fin
fin
emit_tag(break_tag)
break_tag = tag_prevbrk
stack_loop = stack_loop - 2
infor = prev_for
break_tag = tag_prevbrk
stack_loop = stack_loop - 2
infor = prev_for
break
is CASE_TKN
prev_for = infor
infor = FALSE
prev_for = infor
infor = FALSE
stack_loop++
tag_prevbrk = break_tag
break_tag = new_tag(RELATIVE_FIXUP)

View File

@ -203,7 +203,8 @@ OPTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08
!WORD BRNCH,BRNE,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
!WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
!WORD ADDBRLE,INCBRLE,SUBBRGE,DECBRGE,BRGT,BRLT ; 80 82 84 86 88 8A 8C 8E
!WORD BRGT,BRLT,INCBRLE,ADDBRLE,DECBRGE,SUBBRGE ; 80 82 84 86 88 8A 8C 8E
;*
;*
;* ENTER INTO BYTECODE INTERPRETER
;*
@ -413,7 +414,7 @@ OPXTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08
!WORD BRNCH,BRNE,CALLX,ICALX,ENTER,LEAVEX,RETX,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD LBX,LWX,LLBX,LLWX,LABX,LAWX,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
!WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
!WORD ADDBRLE,INCBRLE,SUBBRGE,DECBRGE,BRGT,BRLT ; 80 82 84 86 88 8A 8C 8E
!WORD BRGT,BRLT,INCBRLE,ADDBRLE,DECBRGE,SUBBRGE ; 80 82 84 86 88 8A 8C 8E
;*
;* ADD TOS TO TOS-1
;*
@ -710,6 +711,17 @@ LOR LDA ESTKL,X
STA ESTKH+1,X
+ JMP DROP
;*
;* LOGICAL NOT
;*
LNOT LDA ESTKL,X
ORA ESTKH,X
BEQ +
LDA #$FF
+ EOR #$FF
STA ESTKL,X
STA ESTKH,X
JMP NEXTOP
;*
;* DUPLICATE TOS
;*
DUP DEX
@ -719,17 +731,6 @@ DUP DEX
STA ESTKH,X
JMP NEXTOP
;*
;* LOGICAL NOT
;*
LNOT LDA ESTKL,X
ORA ESTKH,X
BEQ +
LDA #$00
+ EOR #$FF
STA ESTKL,X
STA ESTKH,X
JMP NEXTOP
;*
;* CONSTANT
;*
ZERO
@ -1385,13 +1386,12 @@ BRLT LDA ESTKL,X
BNE BRNCH ; BMI BRNCH
+ BMI NOBRNCH
BPL -
DECBRGE LDA ESTKL,X
SEC
SBC #$01
STA ESTKL,X
BCS +
DECBRGE DEC ESTKL,X
LDA ESTKL,X
CMP #$FF
BNE +
DEC ESTKH,X
_BRGE LDA ESTKL,X ; BRGE
_BRGE LDA ESTKL,X
+ CMP ESTKL+1,X
LDA ESTKH,X
SBC ESTKH+1,X
@ -1403,7 +1403,7 @@ _BRGE LDA ESTKL,X ; BRGE
INCBRLE INC ESTKL,X
BNE _BRLE
INC ESTKH,X
_BRLE LDA ESTKL+1,X ; BRLE
_BRLE LDA ESTKL+1,X
CMP ESTKL,X
LDA ESTKH+1,X
SBC ESTKH,X

View File

@ -526,6 +526,7 @@ OPTBL: DW ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0
DW LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
DW SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
DW ADDBRLE,INCBRLE,SUBBRGE,DECBRGE,BRGT,BRLT ; 80 82 84 86 88 8A 8C 8E
DW BRGT,BRLT,INCBRLE,ADDBRLE,DECBRGE,SUBBRGE ; 80 82 84 86 88 8A 8C 8E
*/
void interp(code *ip)
{
@ -884,7 +885,47 @@ void interp(code *ip)
/*
* 0x80-0x8F
*/
case 0x80: // ADDBRLE : TOS = TOS + TOS-1
case 0x80: // BRGT : TOS-1 > TOS ? IP += (IP)
val = POP;
if (TOS < val)
{
POP;
ip += WORD_PTR(ip);
}
else
{
PUSH(val);
ip += 2;
}
break;
case 0x82: // BRLT : TOS-1 < TOS ? IP += (IP)
val = POP;
if (TOS > val)
{
POP;
ip += WORD_PTR(ip);
}
else
{
PUSH(val);
ip += 2;
}
break;
case 0x84: // INCBRLE : TOS = TOS + 1
val = POP;
val++;
if (TOS >= val)
{
PUSH(val);
ip += WORD_PTR(ip);
}
else
{
POP;
ip += 2;
}
break;
case 0x86: // ADDBRLE : TOS = TOS + TOS-1
val = POP;
ea = POP;
val = ea + val;
@ -899,36 +940,7 @@ void interp(code *ip)
ip += 2;
}
break;
case 0x82: // INCBRLE : TOS = TOS + 1
val = POP;
val++;
if (TOS >= val)
{
PUSH(val);
ip += WORD_PTR(ip);
}
else
{
POP;
ip += 2;
}
break;
case 0x84: // SUBBRGE : TOS = TOS-1 - TOS
val = POP;
ea = POP;
val = ea - val;
if (TOS <= val)
{
PUSH(val);
ip += WORD_PTR(ip);
}
else
{
POP;
ip += 2;
}
break;
case 0x86: // DECBRGE : TOS = TOS - 1
case 0x88: // DECBRGE : TOS = TOS - 1
val = POP;
val--;
if (TOS <= val)
@ -942,29 +954,18 @@ void interp(code *ip)
ip += 2;
}
break;
case 0x88: // BRGT : TOS-1 > TOS ? IP += (IP)
case 0x8A: // SUBBRGE : TOS = TOS-1 - TOS
val = POP;
if (TOS < val)
ea = POP;
val = ea - val;
if (TOS <= val)
{
POP;
PUSH(val);
ip += WORD_PTR(ip);
}
else
{
PUSH(val);
ip += 2;
}
break;
case 0x8A: // BRLT : TOS-1 < TOS ? IP += (IP)
val = POP;
if (TOS > val)
{
POP;
ip += WORD_PTR(ip);
}
else
{
PUSH(val);
ip += 2;
}
break;