1;;==========================================================================;;
2;; Joe Zbiciak's Singed Earth?                                              ;;
3;; Copyright 2003, Joe Zbiciak, intvnut AT gmail DOT com                    ;;
4;;==========================================================================;;
5
6;------------------------------------------------------------------------------
7; Include system information and macro libraries
8;------------------------------------------------------------------------------
9            INCLUDE "../library/gimini.asm"
10            INCLUDE "../macro/util.mac"
11            INCLUDE "../macro/stic.mac"
12            INCLUDE "../macro/gfx.mac"
13            INCLUDE "../macro/print.mac"
14
15            CFGVAR  "name" = "SDK-1600 Singed Earth? Tank Demo"
16            CFGVAR  "short_name" = "Singed Earth?"
17            CFGVAR  "author" = "Joe Zbiciak"
18            CFGVAR  "year" = 2003
19            CFGVAR  "license" = "GPLv2+"
20            CFGVAR  "description" = "Singed Earth is a play on Scorched Earth."
21            CFGVAR  "publisher" = "SDK-1600"
22
23;------------------------------------------------------------------------------
24; Global constants and configuration.
25;------------------------------------------------------------------------------
26TSKQM       EQU     $7              ; Task queue is 8 entries large
27
28;------------------------------------------------------------------------------
29; Allocate 8-bit variables in Scratch RAM
30;------------------------------------------------------------------------------
31SCRATCH     ORG     $100, $100, "-RWBN"
32
33ISRVEC      RMB     2               ; Always at $100 / $101
34
35            ; Task-oriented 8-bit variables
36TSKQHD      RMB     1               ; Task queue head
37TSKQTL      RMB     1               ; Task queue tail
38TSKDQ       RMB     2*(TSKQM+1)     ; Task data queue
39
40            ; Hand-controller 8-bit variables
41SH_TMP      RMB     1               ; Temp storage.
42SH_LR0      RMB     3               ;\
43SH_FL0      EQU     SH_LR0 + 1      ; |-- Three bytes for left controller
44SH_LV0      EQU     SH_LR0 + 2      ;/
45SH_LR1      RMB     3               ;\
46SH_FL1      EQU     SH_LR1 + 1      ; |-- Three bytes for right controller
47SH_LV1      EQU     SH_LR1 + 2      ;/
48
49            ; MOB data tables
50MOB_PIC     RMB     16              ; MOB picture table
51MOB_ATR     RMB     8               ; MOB attribute table
52MOB_XYP     RMB     32              ; MOB X/Y position table
53MOB_FLG     RMB     1               ; MOB update flags.
54
55            ; Tank status variables
56TNK0_VEL    RMB     1               ; Tank #0 desired velocity
57TNK1_VEL    RMB     1               ; Tank #1 desired velocity
58TNK0_MOV    RMB     1               ; Tank #0 movement (actual velocity)
59TNK1_MOV    RMB     1               ; Tank #1 movement (actual velocity)
60TNK0_AVL    RMB     1               ; Tank #0 angular velocity for turret
61TNK1_AVL    RMB     1               ; Tank #1 angular velocity for turret
62TNK0_ANG    RMB     1               ; Tank #0 turret angle (in 10 deg incrs.)
63TNK1_ANG    RMB     1               ; Tank #1 turret angle (in 10 deg incrs.)
64TNK0_POW    RMB     1               ; Tank #0 firing strength
65TNK1_POW    RMB     1               ; Tank #1 firing strength
66TNK0_FLP    RMB     1               ; Tank #0 flipped left/right
67TNK1_FLP    RMB     1               ; Tank #1 flipped left/right
68
69B0_TICK     RMB     1               ; Bullet 0 "no-hit timer" counter
70B1_TICK     RMB     1               ; Bullet 1 "no-hit timer" counter
71
72            ; Misc other stuff
73FR_BUSY     RMB     1               ; Per-frame updates busy flag.
74AVL_TICK    RMB     1               ; tick counter for angular velocity upd.
75DO_STATS    RMB     1               ; need to draw status line.
76
77_SCRATCH    EQU     $               ; end of scratch area
78
79
80
81;------------------------------------------------------------------------------
82; Allocate 16-bit variables in System RAM
83;------------------------------------------------------------------------------
84SYSTEM      ORG     $2F0, $2F0, "-RWBN"
85STACK       RMB     32              ; Reserve 32 words for the stack
86
87            ; Task-oriented 16-bit variables
88TSKQ        RMB     (TSKQM + 1)     ; Task queue
89
90            ; Hand-controller 16-bit variables
91SHDISP      RMB     1               ; ScanHand dispatch
92
93            ; STIC shadow
94MOB_DIS     RMB     1               ; MOB collision dispatch table ptr
95MOB_IGN     RMB     1               ; MOB collision ignore table ptr
96STICSH      RMB     32              ; Room for X, Y, and A regs only.
97
98            ; Tank status
99TNK0_PTS    RMB     1
100TNK1_PTS    RMB     1
101
102            ; Bullet details
103BUL0_XVL    RMB     1               ; bullet 0's X velocity (8.8)
104BUL0_YVL    RMB     1               ; bullet 0's Y velocity (8.8)
105BUL1_XVL    RMB     1               ; bullet 1's X velocity (8.8)
106BUL1_YVL    RMB     1               ; bullet 1's Y velocity (8.8)
107
108_SYSTEM     EQU     $               ; end of system area
109
110
111;------------------------------------------------------------------------------
112; Misc equates
113;------------------------------------------------------------------------------
114ISRRET      EQU     $1014           ; EXEC's ISR return pointer
115
116;------------------------------------------------------------------------------
117; EXEC-friendly ROM header.
118;------------------------------------------------------------------------------
119            ORG     $5000           ; Use default memory map
120ROMHDR:     BIDECLE ZERO            ; MOB picture base   (points to NULL list)
121            BIDECLE ZERO            ; Process table      (points to NULL list)
122            BIDECLE MAIN            ; Program start address
123            BIDECLE ZERO            ; Bkgnd picture base (points to NULL list)
124            BIDECLE ONES            ; GRAM pictures      (points to NULL list)
125            BIDECLE TITLE           ; Cartridge title/date
126            DECLE   $03C0           ; No ECS title, run code after title,
127                                    ; ... no clicks
128ZERO:       DECLE   $0000           ; Screen border control
129            DECLE   $0000           ; 0 = color stack, 1 = f/b mode
130ONES:       DECLE   C_BLU, C_BLU    ; Initial color stack 0 and 1: Blue
131            DECLE   C_BLU, C_BLU    ; Initial color stack 2 and 3: Blue
132            DECLE   C_BLU           ; Initial border color: Blue
133;------------------------------------------------------------------------------
134
135
136;; ======================================================================== ;;
137;;  TITLE  -- Display our modified title screen & copyright date.           ;;
138;; ======================================================================== ;;
139TITLE:      PROC
140            STRING  103, "Tank", 0
141            BEGIN
142
143            ; Put up our own title screen.
144            CALL    CLRSCR
145                                    ;     01234567890123456789
146            PRINT_CSTK  1,  2, White,      ">>> SDK-1600 <<<"
147            PRINT_CSTK  2,  6, White,          "Presents"
148            PRINT_CSTK  6,  4, Yellow,       "Singed Earth"
149            PRINT_CSTK 10,  3, White,       "Copyright 2003"
150
151            ; Done.
152            RETURN                  ; Return to EXEC for title screen display
153            ENDP
154
155;; ======================================================================== ;;
156;;  PROGRAM-SPECIFIC MACROS AND UTILITY FUNCTIONS.                          ;;
157;; ======================================================================== ;;
158            INCLUDE "util.asm"                  ; Utility functions, macros
159
160;; ======================================================================== ;;
161;;  DATA                                                                    ;;
162;; ======================================================================== ;;
163            INCLUDE "gfx_data.asm"              ; pictures
164            INCLUDE "atr_data.asm"              ; STIC attribute records
165            INCLUDE "mob_data.asm"              ; MOB collision dispatch tbls
166
167;; ======================================================================== ;;
168;;  PROGRAM MODULES                                                         ;;
169;; ======================================================================== ;;
170            INCLUDE "mob_ll.asm"                ; Low-level MOB routines
171            INCLUDE "objects.asm"               ; Tank/bullet code
172            INCLUDE "status.asm"                ; Status bar code
173
174;; ======================================================================== ;;
175;;  LIBRARY INCLUDES                                                        ;;
176;; ======================================================================== ;;
177            INCLUDE "../library/print.asm"      ; PRINT.xxx routines
178            INCLUDE "../library/prnum16.asm"    ; PRNUM16.x routines
179            INCLUDE "../library/fillmem.asm"    ; CLRSCR/FILLZERO/FILLMEM
180            INCLUDE "../library/memcpy.asm"     ; MEMCPY
181            INCLUDE "../library/memunpk.asm"    ; MEMCPY
182            INCLUDE "../task/scanhand.asm"      ; SCANHAND
183            INCLUDE "../task/taskq.asm"         ; RUNQ/QTASK
184
185;; ======================================================================== ;;
186;;  MAIN:  Here's our main program code.                                    ;;
187;; ======================================================================== ;;
188MAIN:       PROC
189            DIS
190            MVII    #STACK, R6      ; Set up our stack
191
192            MVII    #$25D,  R1      ;\
193            MVII    #$102,  R4      ; |-- Clear all of memory
194            CALL    FILLZERO        ;/
195
196            SETISR  INITISR,  R0    ;\    Do GRAM initialization in ISR.
197                                    ; |-- INITISR will the point to the
198                                    ;/    regular ISR when it's done.
199
200            ;; ------------------------------------------------------------ ;;
201            ;;  Set up our hand-controller dispatch.                        ;;
202            ;; ------------------------------------------------------------ ;;
203            MVII    #HAND,  R0      ;\__ Set up scanhand dispatch table
204            MVO     R0,     SHDISP  ;/
205
206            CALL    INIT_TANK
207            CALL    INIT_STAT
208
209            EIS
210
211            ;; ------------------------------------------------------------ ;;
212            ;;  Fall into the RUNQ.  We should never exit the RUNQ in this  ;;
213            ;;  demo, since we never call SCHEDEXIT.                        ;;
214            ;; ------------------------------------------------------------ ;;
215            CALL    RUNQ            ; Run until a SCHEDEXIT happens
216
217            ;; ------------------------------------------------------------ ;;
218            ;;  If a SCHEDEXIT *does* happen (say, due to a bug), crash     ;;
219            ;;  gracefully.                                                 ;;
220            ;; ------------------------------------------------------------ ;;
221            PRINT_CSTK 11, 0, Red, "SCHEDEXIT WAS CALLED"
222            DECR    PC              ; Can't get here normally
223
224            ENDP
225
226STUB        JR      R5
227
228;; ======================================================================== ;;
229;;  HAND    Dispatch table.                                                 ;;
230;; ======================================================================== ;;
231HAND        PROC
232            DECLE   HIT_KEYPAD
233            DECLE   HIT_ACTION
234            DECLE   HIT_DISC
235            ENDP
236
237;; ======================================================================== ;;
238;;  HIT_KEYPAD -- Someone hit a key on a keypad.                            ;;
239;; ======================================================================== ;;
240HIT_KEYPAD  PROC
241            SWAP    R2
242            MOVR    R2,         R1      ;\__ R1 gets tank #
243            ANDI    #1,         R1      ;/
244            ADDI    #TNK0_POW,  R1      ; point to tank firing strength
245            SWAP    R2
246            BPL     @@pressed
247            JR      R5
248
249@@pressed:  ANDI    #$FF,       R2      ;\__ [0] key means '10'
250            BEQ     @@force10           ;/
251            CMPI    #10,        R2      ;\__ [1]..[9] mean 1 through 9
252            BLE     @@ok                ;/
253@@force10:  MVII    #10,        R2      ;    [C], [E], and [0] are all 10
254
255@@ok:       MVO@    R2,         R1      ; Store firing strength for this tank
256
257            MVII    #1,         R1      ;\__ need to update status bar.
258            MVO     R1,         DO_STATS;/
259            JR      R5
260
261            ENDP
262
263;; ======================================================================== ;;
264;;  HIT_ACTION -- Someone hit a key on a keypad.                            ;;
265;; ======================================================================== ;;
266HIT_ACTION  PROC
267            SWAP    R2
268            MOVR    R2,         R1      ;\__ R1 gets tank #
269            ANDI    #1,         R1      ;/
270            MOVR    R1,         R0      ; save tank #
271            ADDI    #TNK0_AVL,  R1      ; point to turret angular velocity
272            SWAP    R2
273            BPL     @@pressed
274
275@@stop_tur  CLRR    R2
276@@upd_angv  MVO@    R2,         R1      ; store updated turret velocity
277@@leaveR5   JR      R5
278
279@@pressed   ANDI    #$FF,       R2
280            DECR    R2                  ; 1 is "top", 2 is "left", 3 is "right"
281            BNEQ    @@upd_angv          ; if it's 1 or 2, update angular vel.
282            MVO@    R2,         R1      ; otherwise force angular vel to 0
283
284@@fire:     B       FIRE_BULLET         ; Fire the bullet.  (Chained return)
285
286            ENDP
287
288;; ======================================================================== ;;
289;;  HIT_DISC   -- Someone hit a key on a keypad.                            ;;
290;; ======================================================================== ;;
291HIT_DISC    PROC
292
293            SWAP    R2
294            MOVR    R2,     R1
295            ANDI    #1,     R1      ; R1 gets Tank # (0 or 1)
296            ADDI    #TNK0_VEL,R1
297            SWAP    R2
298            BPL     @@pressed
299
300@@stop:     CLRR    R3
301@@store:    MVO@    R3,     R1
302            JR      R5
303
304@@pressed:  ADDI    #4,     R2      ; rotate disc.  SSE thru NNE go right
305            ANDI    #$F,    R2
306            BEQ     @@stop          ; position 0 is south.  Discard.
307            CMPI    #8,     R2
308            BEQ     @@stop          ; position 8 is north.  Discard.
309            BLT     @@go_right      ; less than 8 is right, greater is left.
310
311            ;; go left
312            MVII    #$FE,   R3      ; This velocity will be divided by 8
313            B       @@store
314
315@@go_right: ;; go right
316            MVII    #$02,   R3      ; This velocity will be divided by 8
317            B       @@store
318
319            ENDP
320
321
322;; ======================================================================== ;;
323;;  ISR -- Just keep the screen on, and copy the STIC shadow over.          ;;
324;; ======================================================================== ;;
325ISR         PROC
326            ;; ------------------------------------------------------------ ;;
327            ;;  Basics:  Update color stack and video enable.               ;;
328            ;; ------------------------------------------------------------ ;;
329            MVO     R0,     STIC.viden  ; Enable display
330            MVI     STIC.mode, R0       ; ...in color-stack mode
331
332            MVII    #C_CYN, R0          ;\__ sky is cyan
333            MVO     R0,     STIC.cs0    ;/
334            MVII    #C_BLU, R0          ;\__ status is blue
335            MVO     R0,     STIC.cs1    ;/
336            MVII    #C_GRY, R0          ;\__ border is grey
337            MVO     R0,     STIC.bord   ;/
338
339            CALL    MOB_ISR             ; Update MOBs
340
341
342            MVI     FR_BUSY,    R0      ;\    test per-frame busy flag.
343            XORI    #1,         R0      ; |__ never let it be 1 more than
344            MVO     R0,         FR_BUSY ; |   one frame at a time, though,
345            BEQ     ISRRET              ;/    in case task queue saturates.
346
347            CALL    MOB_COLDISP         ; do collision dispatches in ISR ctx.
348
349            MVII    #FR_TASK,   R0      ; \
350            MVII    #ISRRET,    R5      ;  |- Queue the per-frame work
351            JD      QTASK               ; /   and return via QTASK
352
353            ENDP
354
355;; ======================================================================== ;;
356;;  FR_TASK -- per frame work to do.                                        ;;
357;; ======================================================================== ;;
358FR_TASK     PROC
359            PSHR    R5
360            ;; ------------------------------------------------------------ ;;
361            ;;  Per-tick work to do.                                        ;;
362            ;;   -- Move tanks based on velocity.                           ;;
363            ;;   -- Update ballistics                                       ;;
364            ;;   -- Update STIC shadow                                      ;;
365            ;;   -- Scan for collision dispatches.                          ;;
366            ;; ------------------------------------------------------------ ;;
367
368            CALL    UPD_TANKS
369            CALL    UPD_BULLET
370            CALL    MOB_STICSH
371            CALL    UPD_STATUS
372
373            CLRR    R0
374            MVO     R0,         FR_BUSY ; let a new frame's work begin
375
376            PULR    PC                  ; done
377            ENDP
378
379
380;; ======================================================================== ;;
381;;  INITISR -- Copy our GRAM image over, and then do the plain ISR.         ;;
382;; ======================================================================== ;;
383INITISR     PROC
384            DIS     ; this could take a couple frames
385
386            ;; ------------------------------------------------------------ ;;
387            ;;  Force the MOBs to all be disabled, with no collision bits.  ;;
388            ;; ------------------------------------------------------------ ;;
389            MVII    #32,        R1      ;\
390            MVII    #0,         R4      ; |-- Clear MOB registers
391            CALL    FILLZERO            ;/
392
393            ;; ------------------------------------------------------------ ;;
394            ;;  Load our initial GRAM image.                                ;;
395            ;; ------------------------------------------------------------ ;;
396            CALL    MEMUNPK
397            DECLE   $3800, GFX_DATA.gram_img, GFX.gram_size
398
399            ;; ------------------------------------------------------------ ;;
400            ;;  Do the main ISR starting with the next frame.               ;;
401            ;; ------------------------------------------------------------ ;;
402            SETISR  ISR,        R0
403
404            JE      ISRRET              ; return and reenable interrupts.
405            ENDP
406
407
408
409;* ======================================================================== *;
410;*  This program is free software; you can redistribute it and/or modify    *;
411;*  it under the terms of the GNU General Public License as published by    *;
412;*  the Free Software Foundation; either version 2 of the License, or       *;
413;*  (at your option) any later version.                                     *;
414;*                                                                          *;
415;*  This program is distributed in the hope that it will be useful,         *;
416;*  but WITHOUT ANY WARRANTY; without even the implied warranty of          *;
417;*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *;
418;*  General Public License for more details.                                *;
419;*                                                                          *;
420;*  You should have received a copy of the GNU General Public License       *;
421;*  along with this program; if not, write to the Free Software             *;
422;*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               *;
423;* ======================================================================== *;
424;*                   Copyright (c) 2003, Joseph Zbiciak                     *;
425;* ======================================================================== *;
426