/[projet1]/users/chema/skooldaze/eric.s
Defence Force logotype

Contents of /users/chema/skooldaze/eric.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 699 - (show annotations)
Tue Oct 25 18:08:48 2011 UTC (8 years, 5 months ago) by Chema
File size: 29067 byte(s)
Modified staircases to please Dbug :) Also solved the bug when sitting on the stairs and other minor changes. No mem left :(
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; -----------------------------------
3 ;; Skool Daze
4 ;; The Oric Version
5 ;; -----------------------------------
6 ;; (c) Chema 2011
7 ;; enguita@gmail.com
8 ;; -----------------------------------
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
11 ; Routines to deal with Eric
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
14 #include "params.h"
15
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ; Set the Eric main action timer
18 ; to the appropriate value
19 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20 set_Eric_timer
21 .(
22 ldy #7
23 lda #%00010000
24 and KeyBank,y
25 ;bne quick
26 beq quick
27 lda #NORMAL_ERIC_TIMER
28 .byt $2c
29 quick
30 lda #FAST_ERIC_TIMER
31 sta Eric_timer
32 sta Eric_mid_timer
33 rts
34 .)
35
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ; Get Eric's Y coordinate (adjusted
38 ; if he is jumping) in reg A
39 ; This is used by s_check_Eric_loc
40 ; and TODO others.
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42 get_Eric_Ycoord
43 .(
44 sty savy+1
45 ldy pos_row
46 lda Eric_flags
47 and #ERIC_JUMPING
48 beq noadjust
49 cpy #4
50 bcs nottop
51 ldy #3
52 bne noadjust
53 nottop
54 cpy #11
55 bcs notbottom
56 ldy #10
57 bne noadjust
58 notbottom
59 ldy #17
60 noadjust
61 tya
62 savy
63 ldy #0
64 rts
65 .)
66
67
68 to_front_Eric
69 .(
70 ldx #0
71 jmp to_front
72 .)
73
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75 ; Move Eric left
76 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77
78 left_Eric
79 .(
80 ; Check if Eric can move
81 lda Eric_flags
82 beq doit
83 retme
84 rts
85 doit
86 ; Is Eric facing left?
87 lda flags ;,x
88 and #IS_FACING_RIGHT
89 beq facingleft
90 ; Turn him
91 +turnEric
92 lda #MIDS_ERIC_TIMER
93 sta Eric_timer
94 jmp change_direction
95 facingleft
96
97 ; Assume we can move and put the correct
98 ; value in Eric's timer
99 jsr set_Eric_timer
100
101 ; Check if Eric is on a staircase
102 ldx #0
103 jsr is_on_staircase
104 beq notstaircasel
105 ; Is he at the right of the school?
106 lda pos_col ;,x
107 cmp #WALLMIDDLEFLOOR
108 bcs left
109 jmp up_a_stair
110 left
111 jmp down_a_stair
112 +notstaircasel
113 ; Perfect, we can perform a step if
114 ; there is no obstacle
115 ; Is he at the left end of the school?
116 ldy pos_col ;,x
117 cpy #FIRST_VIS_COL-1
118 beq retme
119
120 ; Is he on the bottom floor
121 lda pos_row ;,x
122 cmp #17
123 beq proceed
124 ; Is he on the top floor
125 cmp #3
126 bne middle
127 cpy #WALLTOPFLOOR+1
128 bne proceed
129 rts
130 middle
131 cpy #WALLMIDDLEFLOOR+1
132 bne otherwall
133 rts
134 otherwall
135 cpy #WALLMIDDLEFLOOR2+1
136 bne proceed
137 rts
138 proceed
139 jmp step_character
140 .)
141
142
143 right_Eric
144 .(
145 ; Check if Eric can move
146 lda Eric_flags
147 beq doit
148 retme
149 rts
150 doit
151 ; Is Eric facing left?
152 lda flags ;,x
153 and #IS_FACING_RIGHT
154 bne facingright
155 ; Turn him
156 jmp turnEric
157 facingright
158
159 ; Assume we can move and put the correct
160 ; value in Eric's timer
161 jsr set_Eric_timer
162
163 ; Check if Eric is on a staircase
164 ldx #0
165 jsr is_on_staircase
166 beq notstaircaser
167 ; Is he at the right of the school?
168 lda pos_col ;,x
169 cmp #WALLMIDDLEFLOOR
170 bcs left
171 jmp down_a_stair
172 left
173 jmp up_a_stair
174 +notstaircaser
175
176 ; Perfect, we can perform a step if
177 ; there is no obstacle
178 ; Is he at the right end of the school?
179 ldy pos_col ;,x
180 cpy #SKOOL_COLS-3
181 beq retme
182
183 ; Is he on the bottom floor
184 lda pos_row ;,x
185 cmp #17
186 beq proceed
187 ; Is he on the top floor
188 cmp #3
189 bne middle
190 cpy #WALLTOPFLOOR-3
191 bne proceed
192 rts
193 middle
194 cpy #WALLMIDDLEFLOOR-3
195 bne otherwall
196 rts
197 otherwall
198 cpy #WALLMIDDLEFLOOR2-3
199 bne proceed
200 rts
201 proceed
202 jmp step_character
203 .)
204
205
206
207 up_Eric
208 .(
209 ; Check if Eric can move
210 lda Eric_flags
211 beq doit
212 retme
213 rts
214 doit
215 ; Assume we can move and put the correct
216 ; value in Eric's timer
217 jsr set_Eric_timer
218
219 ; Check if Eric is on a staircase
220 lda pos_row; ,x
221 cmp #3
222 beq notstaircase
223 cmp #10
224 beq middlebottom
225 cmp #17
226 beq middlebottom
227 ; Eric is on a staircase, must he turn round first or go up a step?
228 ; First check if he is on a staircase at the left or at the right of the school
229 lda pos_col ;,x
230 cmp #WALLMIDDLEFLOOR
231 bcc left
232 ; He is at a right staircase
233 ; Is Eric facing left?
234 lda flags ;,x
235 and #IS_FACING_RIGHT
236 bne doit2 ;facingright
237 ; If so turn him round
238 jmp change_direction
239 /*facingright
240 ; Move him up a stair
241 jmp up_a_stair*/
242 left
243 ; His is at a left staircase
244 ; Is Eric facing left?
245 lda flags ;,x
246 and #IS_FACING_RIGHT
247 bne facingright2
248 ; Move him up a stair
249 jmp up_a_stair
250 facingright2
251 ; If so turn him round
252 jmp change_direction
253 +notstaircase
254 ; He is not in a staircase
255 /*
256 lda tab_chars
257 beq donothing
258 jsr to_front_Eric
259 donothing
260 */
261 lda flags
262 and #IS_FACING_RIGHT
263 bne notstaircaser
264 jmp notstaircasel
265
266 middlebottom
267 ; He is at the middle or bottom floors
268 lda pos_col
269 cmp #STAIRLBOTTOM
270 bne notleftstaircase
271 ; At the bottom of the left staircase
272 lda flags
273 and #IS_FACING_RIGHT
274 bne notstaircase
275 ; Facing left
276 beq doit2
277 notleftstaircase
278 cmp #STAIRRBOTTOM
279 bne notstaircase
280 lda flags
281 and #IS_FACING_RIGHT
282 beq notstaircase
283 ; Facing right
284 doit2
285 jsr to_back
286 jmp up_a_stair
287 .)
288
289
290 down_Eric
291 .(
292 ; Check if Eric can move
293 lda Eric_flags
294 beq doit
295 retme
296 rts
297 doit
298 ; Assume we can move and put the correct
299 ; value in Eric's timer
300 jsr set_Eric_timer
301
302 ; Check if Eric is on a staircase
303 lda pos_row; ,x
304 cmp #3
305 beq middletop
306 cmp #10
307 beq middletop
308 cmp #17
309 beq notstaircase
310 ; Eric is on a staircase, must he turn round first or go down a step?
311 ; First check if he is on a staircase at the left or at the right of the school
312 lda pos_col ;,x
313 cmp #WALLMIDDLEFLOOR
314 bcc left
315 ; He is at a right staircase
316 ; Is Eric facing left?
317 lda flags ;,x
318 and #IS_FACING_RIGHT
319 bne facingright
320 ; Move him down a stair
321 jmp doit22
322 facingright
323 ; If so turn him round
324 jmp change_direction
325 left
326 ; His is at a left staircase
327 ; Is Eric facing left?
328 lda flags ;,x
329 and #IS_FACING_RIGHT
330 bne facingright2
331 ; If so turn him round
332 jmp change_direction
333 facingright2
334 jmp doit22
335 middletop
336 ; He is at the middle or top floors
337 lda pos_col
338 cmp #STAIRLTOP
339 bne notleftstaircase
340 ; At the top of the left staircase
341 lda flags
342 and #IS_FACING_RIGHT
343 beq notstaircase
344 bne doit2
345 ; Facing left
346 notleftstaircase
347 cmp #STAIRRTOP
348 bne notstaircase
349 lda flags
350 and #IS_FACING_RIGHT
351 beq doit2
352 jmp notstaircase
353 doit2
354 jsr to_back
355 doit22
356 jmp down_a_stair
357 .)
358
359
360 sit_Eric
361 .(
362 ; Flip Eric flag...
363 lda Eric_flags
364 eor #(ERIC_SITTINGLYING)
365 sta Eric_flags
366 bmi dosit
367 ; Eric must stand up
368 jsr is_on_staircase
369 beq notstairs2
370 .(
371 jsr update_SRB_sp
372 lda pos_col
373 cmp #64
374 ; Carry is set if Eric is on the right side of the school
375 bcs incx
376 inc pos_col
377 bne contit
378 incx
379 dec pos_col
380 contit
381 .)
382 notstairs2
383 jmp s_stand_up
384 dosit
385 ; Eric is going to sit down... even on the floor
386
387 ldx #0
388 jsr is_on_staircase
389 beq notstairs
390
391 ; Eric is on a staircase...
392 ; sit him down...
393 lda pos_col
394 cmp #64
395 ; Carry is set if Eric is on the right side of the school
396 lda flags
397 and #IS_FACING_RIGHT
398 ; Zero is clear if eric is facing right
399 bcs rightside
400 ; Eric is at the left side, must he turn around?
401 bne noturn
402 turn
403 jsr change_direction
404 noturn
405 .(
406 jsr update_SRB_sp
407 lda pos_col
408 cmp #64
409 ; Carry is set if Eric is on the right side of the school
410 bcs incx
411 dec pos_col
412 bne contit
413 incx
414 inc pos_col
415 contit
416 .)
417 lda #4
418 jmp update_animstate
419 rightside
420 ; Eric is at the right side, turn if Z is clear
421 bne turn
422 beq noturn
423
424 notstairs
425 ; Eric is not at a staircase... so sit down
426 ; but not on the bottom floor!
427 lda pos_row
428 cmp #17
429 beq notyet
430
431 sty tmp7
432 jsr s_check_chair ; Returns Z=1 if there is a chair and C=1 if the
433 ; character needs to turn round
434 bne notyet
435 ldy tmp7
436 jmp s_knock_and_sit
437 notyet
438 ldy tmp3
439 ; Then sit on the floor
440 lda #5
441 jmp update_animstate
442 .)
443
444
445
446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
447 ; Deal with ERIC when he's being spoken to
448 ; by a little boy
449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
450
451 listen_Eric
452 .(
453 ; Is the little boy still delivering the message?
454 lda special_playtime
455 ora #%10000000
456 bne cont
457 retme
458 rts
459 cont
460 ; Check the keyboard
461 jsr ReadKeyNoBounce
462 beq retme
463
464 ; Was 'U' pressed?
465 cmp #"U"
466 bne retme
467
468 jsr SndPic
469 ; Signal it
470 lda Eric_flags
471 and #(ERIC_SPOKEN^$ff)
472 sta Eric_flags
473 rts
474 .)
475
476
477 jump_Eric
478 .(
479 lda Eric_flags
480 bpl cont
481 cannot
482 ; Eric is lying down or sitting
483 rts
484 cont
485
486 ldx #0
487 jsr is_on_staircase
488 bne cannot ; Eric cannot jump when on a staircase
489
490 jsr update_SRB_sp
491 dec pos_row
492
493 lda #10
494 sta tmp+1
495 lda #ERIC_JUMPING
496 sta tmp
497 lda #16
498 sta tmp0
499 jmp realize_Eric_action
500 .)
501
502 jump_Eric2
503 .(
504 ; Decrement action timer
505 dec Eric_timer
506 bne cont
507 jmp endpunch ; Re-use this entry point
508 cont
509
510 ; Usual checks for reprimands, shields, etc.
511 ; Time to get reprimands?
512 lda Eric_timer
513 entrypoint1
514 cmp #12
515 bne noreprimand
516 lda #NO_JUMPING
517 jmp punish_Eric
518 noreprimand
519 ; Time to check if Eric touched a shield
520 cmp #13
521 bne noshieldcheck
522 jmp shield_check_jump
523 noshieldcheck
524 ; Time to make the jumping sound?
525 cmp #14
526 bne nojumpsfx
527 ; jmp jump_sfx
528 rts
529 nojumpsfx
530 ; Time to move Eric's arm?
531 cmp #9
532 bne nomovearm
533 ;lda #9
534 jmp setEric_state
535 nomovearm
536 ; Time to bring Eric back down to the floor?
537 cmp #3
538 bne nofall
539 ldx #CHAR_ERIC
540 jsr update_SRB_sp
541 inc pos_row
542 jmp update_SRB_sp
543 nofall
544 cmp #6
545 bcc retme ; Nothing to do
546
547 ; At this point A=6 (which means it's time
548 ; to check whether ERIC has jumped onto a boy,
549 ; or ERIC is already standing on a boy), or A
550 ; is one of {7, 8, 10, 11, 15}, or A<128
551 ; (which means ERIC has jumped while standing
552 ; on a boy).
553
554 bne nocheckboy
555
556 ; Check if Eric jumped onto a knocked-down boy
557
558 ldy #CHAR_BOY11
559 loop
560 jsr check_boy
561 bcs found
562 dey
563 bne loop
564 ; No boy found
565 retme
566 rts
567 found
568 ; Eric is standing on a kid!
569 ; Read the keyboard
570 ; Set the timer to value 7, so we keep visiting
571 ; this code while Eric is standing on the boy
572 lda #7
573 sta Eric_timer
574 jsr ReadKeyNoBounce
575 beq retme
576
577 cmp #"J"
578 bne nopressJ
579 ; Set the timer to 144 to indicate that we
580 ; jumped while standing on a boy
581 lda #144
582 sta Eric_timer
583 ; Return to the main loop, but with the
584 ; carry flag reset, so the keypress is
585 ; processed there
586 /* lda #0
587 sta oldKey
588 pla
589 pla
590 clc
591 rts*/
592
593 ldx #CHAR_ERIC
594 jsr update_SRB_sp
595 dec pos_row
596 jsr update_SRB_sp
597 nopressJ
598 ; Another key of interest was pressed
599 ; maybe trying to turn Eric round
600 cmp #4 ; KEY_RIGHT
601 bne noright
602 lda Eric_flags
603 and #IS_FACING_RIGHT
604 beq retme
605 changedir
606 ldx #CHAR_ERIC
607 jmp change_direction
608 noright
609 cmp #2 ; KEY_LEFT
610 bne retme
611
612 lda Eric_flags
613 and #IS_FACING_RIGHT
614 beq retme
615 bne changedir
616
617 nocheckboy
618 ; At this point A is one of {7, 8, 10, 11, 15}
619 ; (which means there is nothing to do),
620 ; or A=128-143 (which means ERIC has jumped
621 ; while standing on a boy).
622 cmp #134
623 beq retme
624 sec
625 sbc #128
626 bcc retme ; Return unless Eric jumped while over a boy
627
628 ; So ERIC has jumped while standing on a boy.
629 ; Now either A=0, meaning it's time to set the
630 ; jumping action timer at 32758 back to 7, so
631 ; we can deal with ERIC while he's standing on
632 ; a boy; or A=1-15 (but not 6, because that
633 ; would lead us into the code at 62819 to
634 ; perform a redundant check on whether ERIC
635 ; is standing on a boy), meaning we need to run
636 ; the usual checks while ERIC is in mid-air.
637 beq found
638 jmp entrypoint1
639 .)
640
641
642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
643 ; Check whether ERIC is standing on a boy who's
644 ; been knocked out. Reg Y is the boy's id
645 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
646 check_boy
647 .(
648 ; Set limits (pos_x+-1)
649 ldx pos_col
650 dex
651 stx tmp0
652 inx
653 inx
654 stx tmp0+1
655
656 ; Check if the boy is at the same y-coordinate
657 ldx pos_row
658 inx
659 txa
660 cmp pos_row,y
661 bne notthis
662
663 ; Get the boy's animatory state
664 lda anim_state,y
665 cmp #6
666 bne notthis
667
668 ; Check the boy's x-coordinate
669 lda pos_col,y
670 cmp tmp0
671 bcc notthis
672 cmp tmp0+1
673 bcs notthis
674 sec
675 rts
676 notthis
677 clc
678 rts
679 .)
680
681 write_Eric
682 .(
683 ; Is Eric sitting or lying down?
684 lda Eric_flags
685 bpl cont
686 ; Eric is lying down or sitting
687 retme
688 rts
689 cont
690 ; Is he on a staircase?
691 ldx #0
692 jsr is_on_staircase
693 bne retme
694
695 ; Is he on the bottom floor (no blackboards there)
696 ; A holds the y position
697 cmp #17
698 beq retme
699
700 ; Check if on top floor
701 cmp #3
702 beq topfloor
703
704 ; Check if left or right to the white room wall
705 lda pos_col
706 cmp #WALLMIDDLEFLOOR
707 bcc left
708 ; He is at the right
709 cmp #COL_EXAM_BOARD-2
710 bcc retme
711 cmp #COL_EXAM_BOARD-2+6
712 bcc posok
713 rts
714 left
715 ; He ia at the left
716 cmp #COL_WHITE_BOARD-2
717 bcc retme
718 cmp #COL_WHITE_BOARD-2+6
719 bcc posok
720 rts
721 topfloor
722 lda pos_col
723 ; He is on the top floor
724 cmp #COL_READING_BOARD-2
725 bcc retme
726 cmp #COL_READING_BOARD-2+6
727 bcc posok
728 rts
729 posok
730 ; Set appropriate bit on Eric's flags
731 lda Eric_flags
732 ora #ERIC_WRITTING
733 sta Eric_flags
734
735 ; Get the blackboard identifier
736 ; Reg x=0 has been set way before
737 ldx #0
738 jsr get_blackboard
739 ldy #4
740 lda (tmp3),y ; Who wrote there last?
741 bpl notclean
742 ; Blackboard is clean, prepare
743 ; everything to grab what Eric writes
744 lda #0
745 .byt $2c
746 notclean
747 lda #$ff
748 ldy #11
749 sta (tmp3),y
750
751 ; Note Eric wrote here
752 ldy #4
753 lda #CHAR_ERIC
754 sta (tmp3),y
755
756 ; Set tile=0 and col=1
757 ldy #2
758 lda #1
759 sta (tmp3),y
760 iny
761 lda #0
762 sta (tmp3),y
763
764 jmp risearm
765
766 ; Entry point from the main loop whenever we
767 ; deal with Eric when he is writting on a blackboard
768
769 +Eric_writting
770 jsr ReadKeyNoBounce
771 bne cont2
772 retme2
773 rts
774 cont2
775 pha
776 jsr SndStep
777 pla
778 ; Check if it is RETURN ($0d)
779 cmp #$0d
780 bne writechar
781
782 ; Eric finished writting
783 lda Eric_flags
784 and #(ERIC_WRITTING^$ff)
785 sta Eric_flags
786 lda #0
787 jsr setEric_state
788
789 writechar
790 sta tmp+1
791 ; Check if it is a character
792 cmp #32
793 bcc retme2
794 /*
795 beq uppercase
796
797 ; Is it uppercase or not?
798 ldy #7
799 lda #%00010000
800 and KeyBank,y
801 sta tmp
802 ldy #4
803 lda #%00010000
804 and KeyBank,y
805 ora tmp
806 bne uppercase
807
808 ; Lowercase it
809 lda tmp+1
810 cmp #"A"
811 bcc uppercase
812 cmp #"Z"+1
813 bcs uppercase
814 ora #32
815 sta tmp+1
816 uppercase
817 */
818 ldx #0
819 jsr get_blackboard
820
821 ; Note what Eric writes down
822 ldy #11
823 lda (tmp3),y
824 sta tmp
825 bmi dowrite
826 cmp #4
827 beq dowrite
828 ; Save the written char
829 ; on the buffer
830 clc
831 adc #7
832 tay
833 lda tmp+1
834 cmp #32 ; If it is an space, ignore
835 beq dowrite
836 sta (tmp3),y
837 inc tmp
838 lda tmp
839 ldy #11
840 sta (tmp3),y
841 dowrite
842 lda tmp+1
843 jsr write_char_board_ex
844 risearm
845 /* lda #9
846 cmp anim_state
847 beq flop
848 .byt $2c
849 flop
850 lda #10
851 jmp setEric_state
852 */
853 lda #9
854 jmp setEric_state
855 .)
856
857 fire_Eric
858 .(
859 ; Is Eric's catpult pellet already fired?
860 ldy #CHAR_EPELLET
861 lda pos_col,y
862 bmi notfired
863 ; It is already flying, so return
864 rts
865 notfired
866 ; Prepare the flag number to set
867 lda #ERIC_FIRING
868 sta tmp
869 ; And the animatory state
870 lda #11
871 sta tmp+1
872 ; And the action timer
873 lda #24
874 sta tmp0
875
876 ; This entry point is used when Eric is hitting, writting or firing
877 +realize_Eric_action
878 lda Eric_flags
879 bpl cont
880 ; Eric is lying down or sitting
881 rts
882 cont
883 ; Set the appropriate flag
884 lda tmp
885 sta Eric_flags
886
887 ; Set the action timer
888 lda tmp0
889 sta Eric_timer
890
891 ; Save Eric's animatory state into byte 102 (dest_x variable)
892 lda anim_state
893 sta dest_x
894
895 ; Now set the animatory state
896 lda tmp+1
897 jmp setEric_state
898 .)
899
900
901 fire_Eric2
902 .(
903 ; Check if Eric has finished firing the catpult?
904 dec Eric_timer
905 bne cont
906 jmp endpunch ; Re-use this entry point
907 cont
908 lda Eric_timer
909 ; Is it 18? then next step of fire
910 cmp #18
911 bne nonext
912 ; First stage
913 lda #12
914 jmp setEric_state
915 nonext
916 ; Stat lowering the catpult?
917 cmp #6
918 bne nolower
919 lda #11
920 jmp setEric_state
921 nolower
922 ; Time to launch the pellet?
923 cmp #12
924 beq launch
925 rts
926 launch
927 ; This code is to let the player decide *when* to launch
928 ; the pellet, when he releases the F key.
929 lda KeyBank+1
930 and #%00001000
931 beq doit
932 inc Eric_timer
933 rts
934 doit
935 ; Launch the pellet, reprimands, etc.
936 lda #NO_CATAPULTS
937 jsr punish_Eric
938
939 jsr SndFire
940
941 ; this entry point is used when Boy Wander fires his catapult too
942 ; the ID of the pellet (Boy Wander's or Eric's) is passed on reg Y
943 ; and the ID of the character in reg X
944 ldy #CHAR_EPELLET
945 ldx #0
946
947 +launch_pellet
948 cpx #0
949 bne noteric
950 jsr flash_border
951 noteric
952 lda pos_col,x
953 sta pos_col,y
954 lda pos_row,x
955 sta pos_row,y
956
957 lda #<s_usc_pelleth
958 sta uni_subcom_low,y
959 lda #>s_usc_pelleth
960 sta uni_subcom_high,y
961
962 ; Initialize distance to travel
963 lda #18
964 sta var7,y
965
966 ; Initialize animatory state
967 lda flags,x
968 eor flags,y
969 and #IS_FACING_RIGHT
970 beq s1
971 stx savx+1
972 tya
973 tax
974 jsr change_direction
975 savx
976 ldx #1
977 s1
978 rts
979 .)
980
981
982 hit_Eric
983 .(
984 lda #7
985 sta tmp+1
986 lda #ERIC_HITTING
987 sta tmp
988 lda #18-8
989 sta tmp0
990 jmp realize_Eric_action
991 .)
992
993 hit_Eric2
994 .(
995 ; Check if Eric has finished the punch
996 dec Eric_timer
997 beq endpunch
998
999 lda Eric_timer
1000 ; Is it 12? then next step of punch
1001 cmp #12-4
1002 bne nonext
1003 ; First stage
1004 lda #8
1005
1006 ; Entry point from other routines...
1007 ; such as firing with the catpult.
1008 +setEric_state
1009 stx savx+1
1010 ldx #CHAR_ERIC
1011 jsr update_animstate
1012 savx
1013 ldx #0
1014 rts
1015 nonext
1016 ; is it time to see if anybody was hit?
1017 cmp #11-4
1018 beq completed
1019 rts
1020 completed
1021 stx savx2+1
1022
1023 ; Check if anyone was hit
1024 ldx #CHAR_ERIC
1025 jsr check_hit
1026 bmi nobody
1027 #ifndef OTHERS_DOSND
1028 jsr SndHit
1029 #endif
1030
1031 savx2
1032 ldx #0
1033
1034 #ifndef EINSTEIN_LIES
1035 ; Check if we hit Einstein
1036 cpy #CHAR_EINSTEIN
1037 bne notEinstein
1038 inc Einstein_was_hit
1039 bne nobody ; Always jumps
1040 notEinstein
1041 #endif
1042 ; We can check here if it was
1043 ; angelface and increase in 30
1044 ; the score
1045 cpy #CHAR_ANGELFACE
1046 bne nobody
1047 lda #3
1048 jsr add_score
1049 nobody
1050 ; Make a sound effect
1051 ; Check for reprimands
1052
1053 lda #NO_HITTING
1054 jmp punish_Eric
1055 +endpunch
1056 ; This should go to a subroutine?
1057 lda #0
1058 sta tmp
1059 lda #1 ; Can't be zero, or it will be decremented to $ff!
1060 sta tmp0
1061 lda dest_x ; Old animatory state
1062 sta tmp+1
1063
1064 jmp realize_Eric_action
1065 .)
1066
1067 knock_Eric
1068 .(
1069 lda Eric_knockout
1070 beq justknocked
1071
1072 ; Time to decrement timer
1073 dec Eric_knockout
1074 beq cangetup
1075 ; Jump to make a sound if Eric
1076 ; has jut been knocked down
1077 ; then return
1078 rts
1079 cangetup
1080 ; Reset bit 4, wo we don't keep
1081 ; visiting this routine, but also
1082 ; keep bit 7 (Eric is lying).
1083 ; It is better to do it this way, than with
1084 ; an and and an or.
1085 lda #128
1086 sta Eric_flags
1087 rts
1088 justknocked
1089 ; Eric has jut been kocked. Initialize everything
1090
1091 jsr SndKnocked
1092 ; First the counter
1093 lda #40
1094 sta Eric_knockout
1095 ; Then the status flags (set bits 7 and 4)
1096 lda #144
1097 sta Eric_flags
1098
1099 ; Get anim state to differentiate between
1100 ; beking knocked down from a chair or by a
1101 ; punch/pellet
1102 lda anim_state
1103 cmp #4
1104 beq sat
1105 lda #6
1106 .byt $2c
1107 sat
1108 lda #5
1109 jmp setEric_state
1110 .)
1111
1112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1113 ; Make any nearby teacher give ERIC lines if
1114 ; necessary.
1115 ; Used by the routine deal_with_Eric.
1116 ; Checks whether ERIC is somewhere he
1117 ; shouldn't be, or sitting or standing
1118 ; when or where he shouldn't be, or lying down,
1119 ; and makes any nearby teacher give lines
1120 ; accordingly.
1121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1122 teacher_gives_lines
1123 .(
1124 ; Check (and decrement) the lines-giving
1125 ; delay counter, and proceed only if it was
1126 ; <75 (the counter starts off at 0 for a new
1127 ; game, and is set to 150 by this routine
1128 ; after ERIC has been given lines)
1129
1130
1131 ; This has changed, as giving lines has been defered
1132 ; to the main loop. Also the routine is simplified.
1133
1134 lda lines_delay
1135 beq proceed
1136 dec lines_delay
1137 ; This is only if other teacher may give
1138 ; lines. For now we will comment this out
1139 ;cmp #75
1140 ;bcc proceed
1141 rts
1142 proceed
1143 /*
1144 ; It is time to give lines, go for it...
1145 ; Let's start checking if he is jumping
1146 ; as it may give trouble with Y coordinate
1147 ldy pos_row
1148
1149 lda Eric_flags
1150 and #ERIC_JUMPING
1151 beq notjumping
1152 iny
1153 notjumping
1154 ; Now we have in Y the Y coordinate
1155 ; (row) adjusted.
1156
1157 ; Get pointer to region table, and check
1158 ; if Eric is on a staircase at the same time.
1159 tya
1160 ldy #0
1161 cmp #3
1162 beq cont
1163 ; Not on the top floor
1164 iny
1165 cmp #10
1166 beq cont
1167 ; Not on the middle floor
1168 iny
1169 cmp #17
1170 beq cont
1171 ; Eric is on a staircase
1172 ; Put 7 in tmp for later
1173 lda #7
1174 sta tmp
1175
1176 ; Check if he is not sitting
1177 lda Eric_flags
1178 and #ERIC_SITTINGLYING
1179 beq check_validity
1180
1181 ; He is sitting, make any nearby teacher
1182 ; punish him
1183 lda #SIT_STAIRS
1184 jmp do_punishment ; Branches always
1185
1186 cont
1187 ; Prepare pointer to region table
1188 lda tab_regionslo,y
1189 sta tmp0
1190 lda tab_regionshi,y
1191 sta tmp0+1
1192 lda tab_ridslo,y
1193 sta tmp1
1194 lda tab_ridshi,y
1195 sta tmp1+1
1196
1197 ; Check col
1198 lda pos_col
1199 ldy #0
1200 loop
1201 cmp (tmp0),y
1202 iny
1203 bcs loop
1204 ; Point at the correct entry
1205 dey
1206 ; Get the region ID
1207 lda (tmp1),y
1208 sta tmp
1209 */
1210 ;;; ***** THIS VERSION MAY BE SMALLER ******
1211
1212 /*
1213 ; It is time to give lines, go for it...
1214 ; Let's start checking if he is jumping
1215 ; as it may give trouble with Y coordinate
1216 lda Eric_flags
1217 and #ERIC_JUMPING
1218 sta smc_jumpflag+1
1219 beq notjumping
1220 inc pos_row
1221 */
1222
1223
1224 ; If jumping, punishment would be 'YOU ARE NOT A KANGAROO'
1225 lda Eric_flags
1226 and #ERIC_JUMPING
1227 beq notjumping
1228 rts
1229 notjumping
1230 ; Now we have in Y the Y coordinate
1231 ; (row) adjusted.
1232 ; Is Eric on a staircase?
1233 ldx #CHAR_ERIC
1234 jsr is_on_staircase
1235 beq not_on_stairs
1236 ; Put the region ID for later
1237 lda #7
1238 sta tmp
1239 ; Check if he is not sitting
1240 lda Eric_flags
1241 and #ERIC_SITTINGLYING
1242 beq check_validity
1243
1244 ; He is sitting, make any nearby teacher
1245 ; punish him
1246 lda #SIT_STAIRS
1247 jmp do_punishment ; Branches always
1248
1249 not_on_stairs
1250 ; Prepare pointer to region table
1251 jsr s_check_Eric_loc
1252 lda (tmp1),y
1253 sta tmp
1254
1255 /*
1256 ; Put the Y coordinate back as it was
1257 smc_jumpflag
1258 lda #0
1259 beq notjumping2
1260 dec pos_row
1261 notjumping2
1262 */
1263
1264 check_validity
1265 ; At this point we have in tmp an ID of the
1266 ; region Eric is at (7 includes he is on a staircase).
1267 lda tmp
1268 bne notprivate
1269
1270 ; The room is private.
1271 lda #ROOM_PRIVATE
1272 jmp do_punishment
1273 notprivate
1274 ; See if Einstein had a chance to grass on Eric for
1275 ; being absent, or dinner has started, or this is
1276 ; PLAYTIME or REVISION LIBRARY
1277 lda lesson_status
1278 bpl nochanceyet
1279
1280 check_location
1281 ; Compare region and lesson IDs
1282 lda lesson_descriptor
1283 and #%111
1284 cmp tmp
1285 beq iswhereshould
1286 lda #GO_CLASS
1287 jmp do_punishment
1288 iswhereshould
1289 ; Pick again the lesson status flags
1290 lda lesson_status
1291 ; Set carry if Eric's lesson started with Eric
1292 ; being present
1293 asl
1294 asl
1295 strange_entry
1296 lda anim_state
1297 bcc notstarted
1298 ; Is Eric sitting in a chair?
1299 cmp #4
1300 bne notsitting
1301 ; He is, nothing to be done
1302 retme
1303 rts
1304 notsitting
1305 ; Aha!, punish him
1306 lda #FIND_SEAT
1307 jmp do_punishment
1308 notstarted
1309 ;lda anim_state
1310 cmp #5
1311 bcc retme
1312 cmp #7
1313 bcs retme
1314 ; He is on the floor
1315 lda #OFF_FLOOR
1316 jmp do_punishment
1317 nochanceyet
1318 ; Bit 7 of lesson_status is reset, which means
1319 ; EINSTEIN has not yet had a chance to grass
1320 ; on ERIC for being absent at the start of the
1321 ; lesson, or dinner has not started yet, or
1322 ; this is PLAYTIME or REVISION LIBRARY.
1323
1324 ; Is Eric in a room?
1325 lda #4
1326 cmp tmp
1327 bcc strange_entry
1328
1329 ; Have a look at the lesson_clock
1330 lda #CLASS_START
1331 cmp lesson_clock+1
1332 bcc strange_entry
1333 bcs check_location
1334
1335 do_punishment
1336 ; Time for a teacher to punish Eric.
1337 ; A holds the message ID
1338 sta smc_sav_msg+1
1339
1340 /*
1341 ; Is it too soon for the same teacher to dish Eric?
1342 lda #0
1343 sta flag_kludge+1
1344 lda lines_delay
1345 beq notsoon
1346
1347 ; We need to patch so this teacher does not see
1348 ; Eric.
1349 ; Get the teacher who last gave lines to Eric
1350 +smc_teachpun
1351 ldy #0
1352 lda pos_col,y
1353 sta smc_savcol+1
1354 lda #255
1355 sta pos_col,y
1356 inc flag_kludge
1357
1358 ; Is a teacher in range?
1359 stx savx+1
1360 ldx #0
1361 jsr can_be_seen
1362 savx
1363 ldx #0
1364 bcc finish_this
1365
1366 ; Okay, time to give lines (at last!)
1367 notsoon
1368 ; Re-initialize the delay counter
1369 ldy #150
1370 sty lines_delay
1371 ; Get the reason code back
1372 smc_sav_msg
1373 lda #0
1374 jsr punish_Eric
1375
1376 finish_this
1377 ; Put the teacher's coordinate back, if necessary
1378 flag_kludge
1379 lda #0
1380 beq noadjust
1381 smc_savcol
1382 lda #0
1383 ldy smc_teachpun+1
1384 sta pos_col,y
1385 noadjust
1386 rts
1387 */
1388 ; Get the teacher who is to give lines to
1389 ; Eric and adjust message if he is his teacher
1390 ; for this period (so he must be chasing him
1391 ; for being absent).
1392
1393 ; Is the current punish message the GET TO WHERE
1394 ; YOU SHOULD BE? (GO_CLASS)
1395
1396 cmp #GO_CLASS
1397 bne finishthis
1398
1399 ; Get the teacher who may give lines in reg A
1400 jsr can_be_seen
1401 bcs proceed2
1402
1403 ; No one saw Eric
1404 rts
1405
1406 proceed2
1407 sta tmp
1408
1409 ; Get Eric's current teacher
1410 lda lesson_descriptor
1411 lsr
1412 lsr
1413 lsr
1414 lsr
1415 tay
1416 lda table_teacher_codes,y
1417 cmp tmp
1418 bne finishthis
1419
1420 ; Okay it is his teacher, so the message may
1421 ; change according to the lesson flags
1422
1423 lda #COME_ME
1424 sta smc_sav_msg+1
1425
1426 lda lesson_status
1427 and #%100000
1428 bne notfirsttime
1429
1430 lda lesson_status
1431 ora #%100000
1432 sta lesson_status
1433 jmp finishthis
1434 notfirsttime
1435 lda lesson_status
1436 and #%10000
1437 bne notsecond
1438
1439 lda lesson_status
1440 ora #%10000
1441 sta lesson_status
1442 lda #HURRY_UP
1443 sta smc_sav_msg+1
1444 jmp finishthis
1445 notsecond
1446 lda #MY_PATIENCE
1447 sta smc_sav_msg+1
1448
1449 finishthis
1450 /*
1451 ; Re-initialize the delay counter
1452 ldy #150
1453 sty lines_delay
1454 ; Get the reason code back
1455 smc_sav_msg
1456 lda #0
1457 jmp punish_Eric
1458 */
1459
1460 ; Defer any punisment so it is issued
1461 ; after the screen has been updated.
1462 ; Else it will seem as given too early.
1463
1464 inc need_to_punish_Eric+1
1465 rts
1466 .)
1467
1468 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1469 ; Deal with ERIC
1470 ; Called from the main loop.
1471 ; Deals with ERIC when any of bits 0-4 at ERIC's status flags are set.
1472 ; Returns with the carry flag set if and only if ERIC was dealt with,
1473 ; indicating that there is no need to check keypresses in the main loop.
1474 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1475
1476 deal_with_Eric
1477 .(
1478 ;Make any nearby teachers give ERIC lines if he's
1479 ;not where he should be, or standing or sitting
1480 ;when or where he shouldn't be
1481
1482 jsr teacher_gives_lines
1483
1484 ;Check ERIC's status flags and return with
1485 ;the carry flag reset unless ERIC has been
1486 ;knocked over, or he is firing, hitting,
1487 ;jumping, or being spoken to
1488
1489 lda Eric_flags
1490 and #%00011111
1491 bne takecare
1492 clc
1493 rts
1494
1495 takecare
1496
1497 /*
1498 ;Is ERIC being spoken to by a little boy?
1499 lda Eric_flags
1500 and #ERIC_SPOKEN
1501 beq notspoken
1502
1503 sec
1504 rts
1505 notspoken
1506 ;Has ERIC been knocked over?
1507 lda Eric_flags
1508 and #ERIC_DOWN
1509 beq noknock
1510 jsr knock_Eric
1511 sec
1512 rts
1513 noknock
1514 ;Is ERIC firing a catapult?
1515 lda Eric_flags
1516 and #ERIC_FIRING
1517 beq nofire
1518 jsr fire_Eric2
1519 sec
1520 rts
1521 nofire
1522 ;Is ERIC hitting?
1523 lda Eric_flags
1524 and #ERIC_HITTING
1525 beq nohit
1526 jsr hit_Eric2
1527 sec
1528 rts
1529 nohit
1530 ;ERIC is jumping; deal with him accordingly
1531 jsr jump_Eric2
1532 sec
1533 rts
1534 */
1535 ldy #4
1536 loop
1537 lda Eric_flags
1538 and tab_dE_flags,y
1539 beq notthis
1540 ; Flag found
1541 lda tab_dE_routl,y
1542 sta smc_routine+1
1543 lda tab_dE_routh,y
1544 sta smc_routine+2
1545 smc_routine
1546 jsr $1234
1547 sec
1548 rts
1549 notthis
1550 dey
1551 bpl loop
1552 .)
1553
1554
1555 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1556 ;; Checks if a teacher must give Eric
1557 ;; lines. The reason is passed in reg A.
1558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1559 punish_Eric
1560 .(
1561 ; Save the reprimand message identifier
1562 sta sava+1
1563
1564 ; Can Eric be seen by a teacher?
1565 stx savx+1
1566 ldx #CHAR_ERIC
1567 jsr can_be_seen
1568 bcs punish_him
1569 savx
1570 ldx #0
1571 rts
1572 punish_him
1573 ; Time for lines and reprimands
1574 ; Save the teacher code (this is a kludge)
1575 ;sta smc_teachpun+1
1576 ldy #CHAR_ERIC
1577 tax
1578 ; Get back the reprimad message identifier
1579 sava
1580 lda #0
1581 jsr give_lines
1582
1583 ; Re-initialize the delay counter
1584 ldy #LINES_DELAY_VAL
1585 sty lines_delay
1586
1587 ldx savx+1
1588 rts
1589 .)
1590
1591 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1592 ; Check if jumping Eric has touched
1593 ; a shield or the safe.
1594 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1595 shield_check_jump
1596 .(
1597 lda pos_row
1598 sta op1
1599 lda pos_col
1600 sta op1+1
1601
1602 ; Check if Eric is looking right
1603 lda flags
1604 and #IS_FACING_RIGHT
1605 beq skip
1606 inc op1+1
1607 inc op1+1
1608 skip
1609 dec op1
1610 jsr check_shield_hit2
1611 dec op1+1
1612 jmp check_shield_hit2
1613 .)
1614
1615
1616
1617 audio_onof
1618 .(
1619 lda audio_off
1620 eor #$ff
1621 sta audio_off
1622 jmp SndPic
1623 .)
1624
1625
1626
1627 change_colors
1628 .(
1629 stx savx+1
1630 ldx cur_comb
1631 inx
1632 cpx #3
1633 bne skip
1634 ldx #0
1635 skip
1636 stx cur_comb
1637 jsr SndPic
1638 +change_colors_ex
1639 lda color_combination1,x
1640 sta smc_paper_1+1
1641 lda color_combination2,x
1642 sta smc_paper_2+1
1643 jsr set_ink2
1644 savx
1645 ldx #0
1646 rts
1647 .)
1648

  ViewVC Help
Powered by ViewVC 1.1.26