Difference between revisions of "Tagalong Todd Tutorial: Part 1 - Files"

From Intellivision Wiki
Jump to: navigation, search
(tag0.asm)
(tag1.asm)
 
Line 109: Line 109:
 
This is the full listing of the code for the example as it appears at the end of part 1.
 
This is the full listing of the code for the example as it appears at the end of part 1.
  
    ;;==========================================================================;;
+
<code><pre>
    ;; Joe Zbiciak's Tagalong Todd!                                            ;;
+
;;==========================================================================;;
    ;; Copyright 2002, Joe Zbiciak, intvnut AT gmail.com.                      ;;
+
;; Joe Zbiciak's Tagalong Todd!                                            ;;
    ;; http://spatula-city.org/~im14u2c/intv/                                  ;;
+
;; Copyright 2002, Joe Zbiciak, intvnut AT gmail.com.                      ;;
     ;;==========================================================================;;
+
;; http://spatula-city.org/~im14u2c/intv/                                  ;;
 +
;;==========================================================================;;
 +
 
 +
;* ======================================================================== *;
 +
;*  TO BUILD IN BIN+CFG FORMAT:                                            *;
 +
;*      as1600 -o tagalong.bin -l tagalong.lst tagalong.asm                *;
 +
;*                                                                          *;
 +
;*  TO BUILD IN ROM FORMAT:                                                *;
 +
;*      as1600 -o tagalong.rom -l tagalong.lst tagalong.asm                *;
 +
;* ======================================================================== *;
 +
 
 +
            ROMW    16              ; Use 16-bit ROM
 +
 
 +
;------------------------------------------------------------------------------
 +
; Include system information
 +
;------------------------------------------------------------------------------
 +
            INCLUDE "gimini.asm"
 +
 
 +
;------------------------------------------------------------------------------
 +
; Global constants and configuration.
 +
;------------------------------------------------------------------------------
 +
 
 +
TSKQM      EQU     $7              ; Task queue is 8 entries large
 +
MAXTSK      EQU    1              ; Only one task
 +
 
 +
;------------------------------------------------------------------------------
 +
; Allocate 8-bit variables in Scratch RAM
 +
;------------------------------------------------------------------------------
 +
SCRATCH    ORG    $100, $100, "-RWBN"
 +
 
 +
ISRVEC      RMB    2              ; Always at $100 / $101
 +
 
 +
            ; Task-oriented 8-bit variables
 +
TSKQHD      RMB    1              ; Task queue head
 +
TSKQTL      RMB    1              ; Task queue tail
 +
TSKDQ      RMB    2*(TSKQM+1)    ; Task data queue
 +
TSKACT      RMB    1              ; Number of active tasks
 +
 
 +
_SCRATCH    EQU    $              ; end of scratch area
 +
 
 +
 
 +
 
 +
;------------------------------------------------------------------------------
 +
; Allocate 16-bit variables in System RAM
 +
;------------------------------------------------------------------------------
 +
SYSTEM      ORG    $2F0, $2F0, "-RWBN"
 +
STACK      RMB    32              ; Reserve 32 words for the stack
 +
 
 +
            ; Task-oriented 16-bit variables
 +
TSKQ        RMB    (TSKQM + 1)    ; Task queue
 +
TSKTBL      RMB    (MAXTSK * 4)    ; Timer task table
 +
 
 +
            ; STIC shadow
 +
STICSH      RMB    24              ; Room for X, Y, and A regs only.
 +
 
 +
PLYR        PROC
 +
@@XP        RMB    1              ; X position
 +
@@YP        RMB    1              ; Y position
 +
            ENDP
 +
 
 +
MOB_BUSY    RMB    1
 +
_SYSTEM    EQU    $              ; end of system area
 +
 
 +
 
 +
;------------------------------------------------------------------------------
 +
; EXEC-friendly ROM header.
 +
;------------------------------------------------------------------------------
 +
            ORG    $5000          ; Use default memory map
 +
ROMHDR:    BIDECLE ZERO            ; MOB picture base  (points to NULL list)
 +
            BIDECLE ZERO            ; Process table      (points to NULL list)
 +
            BIDECLE MAIN            ; Program start address
 +
            BIDECLE ZERO            ; Bkgnd picture base (points to NULL list)
 +
            BIDECLE ONES            ; GRAM pictures      (points to NULL list)
 +
            BIDECLE TITLE          ; Cartridge title/date
 +
            DECLE  $03C0          ; No ECS title, run code after title,
 +
                                    ; ... no clicks
 +
ZERO:      DECLE  $0000          ; Screen border control
 +
            DECLE  $0000          ; 0 = color stack, 1 = f/b mode
 +
ONES:      DECLE  C_BLU, C_BLU    ; Initial color stack 0 and 1: Blue
 +
            DECLE  C_BLU, C_BLU    ; Initial color stack 2 and 3: Blue
 +
            DECLE  C_BLU          ; Initial border color: Blue
 +
;------------------------------------------------------------------------------
 +
 
 +
 
 +
;; ======================================================================== ;;
 +
;;  TITLE  -- Display our modified title screen & copyright date.          ;;
 +
;; ======================================================================== ;;
 +
TITLE:      PROC
 +
            STRING  102, "Tagalong Todd", 0
 +
            BEGIN
 +
         
 +
            ; Patch the title string to say '=JRMZ=' instead of Mattel.
 +
            CALL    PRINT.FLS      ; Write string (ptr in R5)
 +
            DECLE  C_WHT, $23D    ; White, Point to 'Mattel' in top-left
 +
            STRING  '=JRMZ='        ; Guess who?  :-)
 +
            STRING  ' Productions'
 +
            BYTE    0
 +
         
 +
            CALL    PRINT.FLS      ; Write string (ptr in R1)
 +
            DECLE  C_WHT, $2D0    ; White, Point to 'Mattel' in lower-right
 +
            STRING  '2002 =JRMZ='  ; Guess who?  :-)
 +
            BYTE    0
 +
         
 +
            ; Done.
 +
            RETURN                  ; Return to EXEC for title screen display
 +
            ENDP
 +
 
 +
 
 +
;; ======================================================================== ;;
 +
;;  MAIN:  Here's our main program code.                                    ;;
 +
;; ======================================================================== ;;
 +
MAIN:      PROC
 +
            DIS
 +
            MVII    #STACK, R6      ; Set up our stack
 +
 
 +
            MVII    #$25E,  R1      ;\
 +
            MVII    #$102,  R4      ; |-- Clear all of RAM memory
 +
            CALL    FILLZERO        ;/
 +
 
 +
            MVII    #INITISR, R0    ;\    Do GRAM initialization in ISR.
 +
            MVO    R0,    ISRVEC  ; |__ INITISR will the point to the
 +
            SWAP    R0              ; |  regular ISR when it's done.
 +
            MVO    R0,    ISRVEC+1;/   
 +
         
 +
            ;; ------------------------------------------------------------ ;;
 +
            ;;  Put the character on the screen                            ;;
 +
            ;; ------------------------------------------------------------ ;;
 +
            MVII    #$1000, R0
 +
            MVO    R0,    PLYR.XP
 +
            MVO    R0,    PLYR.YP
 +
 
 +
            EIS
 +
 
 +
            ;; ------------------------------------------------------------ ;;
 +
            ;;  Fall into the RUNQ.  We should never exit the RUNQ in this  ;;
 +
            ;;  demo, since we never call SCHEDEXIT.                        ;;
 +
            ;; ------------------------------------------------------------ ;;
 +
            CALL    RUNQ            ; Run until a SCHEDEXIT happens
 +
 
 +
            ;; ------------------------------------------------------------ ;;
 +
            ;;  If a SCHEDEXIT *does* happen (say, due to a bug), crash    ;;
 +
            ;;  gracefully.                                                ;;
 +
            ;; ------------------------------------------------------------ ;;
 +
            CALL    PRINT.FLS
 +
            DECLE  C_RED, $200 + 11*20
 +
                    ;01234567890123456789
 +
            STRING  "SCHEDEXIT WAS CALLED",0
 +
 
 +
            DECR    PC              ; Can't get here
 +
         
 +
            ENDP
 +
 
 +
;; ======================================================================== ;;
 +
;;  MOB_UPDATE -- This updates the player's position                        ;;
 +
;; ======================================================================== ;;
 +
MOB_UPDATE  PROC
 +
            PSHR    R5
 +
 
 +
            ;; ------------------------------------------------------------ ;;
 +
            ;;  Merge our position with our MOB registers.                  ;;
 +
            ;; ------------------------------------------------------------ ;;
 +
            MVII    #@@mobr,    R4      ; MOB information template
 +
            MVII    #STICSH,    R5
 +
 
 +
            MVI    PLYR.XP,    R0      ;\
 +
            SWAP    R0                  ; |
 +
            ANDI    #$00FF,    R0      ; |- Player X position
 +
            XOR@    R4,        R0      ; |
 +
            MVO@    R0,        R5      ;/
 +
         
 +
            ADDI    #7,        R5      ;  Move pointer to Y coordinate section of the STICSH
 +
           
 +
            MVI    PLYR.YP,    R0      ;\
 +
            SWAP    R0                  ; |
 +
            ANDI    #$007F,    R0      ; |- Player Y position
 +
            XOR@    R4,        R0      ; |
 +
            MVO@    R0,        R5      ;/
 +
 
 +
            ADDI    #7,        R5      ; Move pointer to A register section of the STICSH
 +
 
 +
            MVI@    R4,        R0      ; \_ Player's A register
 +
            MVO@    R0,        R5      ; /
 +
 
 +
            CLRR    R0
 +
            MVO    R0,        MOB_BUSY
 +
 
 +
            PULR    PC
 +
 
 +
            ;; ------------------------------------------------------------ ;;
 +
            ;;  Bits to copy into MOB registers.                            ;;
 +
            ;; ------------------------------------------------------------ ;;
 +
@@mobr      DECLE  STIC.mobx_visb      ; make player visible
 +
            DECLE  STIC.moby_yres      ; make player 8x16 MOB
 +
            DECLE  STIC.moba_fg1 + STIC.moba_gram + 0*8    ; Player is blue
 +
            ENDP
 
      
 
      
    ;* ======================================================================== *;
+
 
    ;* TO BUILD IN BIN+CFG FORMAT:                                            *;
+
;; ======================================================================== ;;
    ;*      as1600 -o tagalong.bin -l tagalong.lst tagalong.asm                *;
+
;; ISR -- Just keep the screen on, and copy the STIC shadow over.         ;;
    ;*                                                                          *;
+
;; ======================================================================== ;;
    ;*  TO BUILD IN ROM FORMAT:                                                *;
+
ISR        PROC
    ;*      as1600 -o tagalong.rom -l tagalong.lst tagalong.asm                *;
+
 
    ;* ======================================================================== *;
+
            ;; ------------------------------------------------------------ ;;
   
+
            ;;  Basics:  Update color stack and video enable.              ;;
                ROMW    16              ; Use 16-bit ROM
+
            ;; ------------------------------------------------------------ ;;
   
+
            MVO    R0,    STIC.viden  ; Enable display
    ;------------------------------------------------------------------------------
+
            MVI    STIC.mode, R0      ; ...in color-stack mode
    ; Include system information
+
 
    ;------------------------------------------------------------------------------
+
            MVII    #C_GRY, R0          ;\
                INCLUDE "gimini.asm"
+
            MVO    R0,    STIC.cs0    ; |__ Set display to grey
   
+
            MVO    R0,    STIC.cs2    ; |
    ;------------------------------------------------------------------------------
+
            MVO    R0,    STIC.bord  ;/
    ; Global constants and configuration.
+
 
    ;------------------------------------------------------------------------------
+
            ;; ------------------------------------------------------------ ;;
      
+
            ;;  Update STIC shadow and queue updates for MOB velocities.   ;;
     TSKQM      EQU     $7              ; Task queue is 8 entries large
+
            ;; ------------------------------------------------------------ ;;
    MAXTSK      EQU    1              ; Only one task
+
            MVI     MOB_BUSY, R0
   
+
            TSTR    R0
    ;------------------------------------------------------------------------------
+
            BNEQ    @@no_mobs
    ; Allocate 8-bit variables in Scratch RAM
+
            MVO     PC,     MOB_BUSY
    ;------------------------------------------------------------------------------
+
 
     SCRATCH    ORG    $100, $100, "-RWBN"
+
 
      
+
            CALL    MEMCPY              ;\__ Copy over the STIC shadow.
     ISRVEC     RMB    2              ; Always at $100 / $101
+
            DECLE  $0000, STICSH, 24  ;/
      
+
 
                ; Task-oriented 8-bit variables
+
            MVII    #MOB_UPDATE, R0
    TSKQHD      RMB     1               ; Task queue head
+
            JSRD    R5,  QTASK
    TSKQTL      RMB    1              ; Task queue tail
+
@@no_mobs: 
    TSKDQ      RMB    2*(TSKQM+1)    ; Task data queue
+
 
    TSKACT      RMB    1              ; Number of active tasks
+
            CALL    DOTIMER            ; Update timer-based tasks.
   
+
            B      $1014              ; return from interrupt.
    _SCRATCH    EQU    $              ; end of scratch area
+
            ENDP
   
+
 
   
+
;; ======================================================================== ;;
   
+
;;  INITISR -- Copy our GRAM image over, and then do the plain ISR.        ;;
    ;------------------------------------------------------------------------------
+
;; ======================================================================== ;;
    ; Allocate 16-bit variables in System RAM
+
INITISR     PROC
    ;------------------------------------------------------------------------------
+
            PSHR    R5
     SYSTEM      ORG    $2F0, $2F0, "-RWBN"
+
 
    STACK      RMB    32              ; Reserve 32 words for the stack
+
            CALL    MEMCPY
   
+
            DECLE  $3800, GRAMIMG, GRAMIMG.end - GRAMIMG
                ; Task-oriented 16-bit variables
+
 
    TSKQ        RMB    (TSKQM + 1)    ; Task queue
+
            MVII    #ISR,  R0
    TSKTBL      RMB    (MAXTSK * 4)    ; Timer task table
+
            MVO     R0,     ISRVEC
   
+
            SWAP    R0
                ; STIC shadow
+
            MVO     R0,     ISRVEC + 1
    STICSH      RMB    24              ; Room for X, Y, and A regs only.
+
 
   
+
            PULR    PC
    PLYR        PROC
+
            ENDP
    @@XP        RMB    1              ; X position
+
 
    @@YP        RMB    1              ; Y position
+
;; ======================================================================== ;;
                ENDP
+
;;  GRAMIMG -- Arrow pictures and other graphics to load into GRAM.        ;;
   
+
;; ======================================================================== ;;
    MOB_BUSY    RMB    1
+
GRAMIMG     PROC
    _SYSTEM    EQU    $              ; end of system area
+
 
   
+
@@person:  ; Crappy person graphic.
   
+
            DECLE  %00010000
    ;------------------------------------------------------------------------------
+
            DECLE  %00111000
    ; EXEC-friendly ROM header.
+
            DECLE  %00111000
    ;------------------------------------------------------------------------------
+
            DECLE  %00010000
                ORG    $5000          ; Use default memory map
+
            DECLE  %00010000
    ROMHDR:    BIDECLE ZERO            ; MOB picture base  (points to NULL list)
+
            DECLE  %01111100
                BIDECLE ZERO            ; Process table      (points to NULL list)
+
            DECLE  %10111010
                BIDECLE MAIN            ; Program start address
+
            DECLE  %10111010
                BIDECLE ZERO            ; Bkgnd picture base (points to NULL list)
+
            DECLE  %10111010
                BIDECLE ONES            ; GRAM pictures      (points to NULL list)
+
            DECLE  %10111010
                BIDECLE TITLE          ; Cartridge title/date
+
            DECLE  %00111000
                DECLE  $03C0          ; No ECS title, run code after title,
+
            DECLE  %00101000
                                        ; ... no clicks
+
            DECLE  %00101000
    ZERO:      DECLE  $0000          ; Screen border control
+
            DECLE  %00101000
                DECLE  $0000          ; 0 = color stack, 1 = f/b mode
+
            DECLE  %00101000
    ONES:      DECLE  C_BLU, C_BLU    ; Initial color stack 0 and 1: Blue
+
            DECLE  %01101100
                DECLE  C_BLU, C_BLU    ; Initial color stack 2 and 3: Blue
+
@@end:     
                DECLE  C_BLU          ; Initial border color: Blue
+
            ENDP
    ;------------------------------------------------------------------------------
+
 
   
+
;; ======================================================================== ;;
   
+
;;  LIBRARY INCLUDES                                                        ;;
    ;; ======================================================================== ;;
+
;; ======================================================================== ;;
    ;TITLE -- Display our modified title screen & copyright date.           ;;
+
            INCLUDE "print.asm"      ; PRINT.xxx routines
    ;; ======================================================================== ;;
+
            INCLUDE "fillmem.asm"    ; CLRSCR/FILLZERO/FILLMEM
    TITLE:      PROC
+
            INCLUDE "memcpy.asm"      ; MEMCPY
                STRING  102, "Tagalong Todd", 0
+
            INCLUDE "timer.asm"          ; Timer-based task stuff
                BEGIN
+
            INCLUDE "taskq.asm"          ; RUNQ/QTASK
             
+
 
                ; Patch the title string to say '=JRMZ=' instead of Mattel.
+
 
                CALL    PRINT.FLS      ; Write string (ptr in R5)
+
;* ======================================================================== *;
                DECLE  C_WHT, $23D    ; White, Point to 'Mattel' in top-left
+
;*  This program is free software; you can redistribute it and/or modify    *;
                STRING  '=JRMZ='        ; Guess who?  :-)
+
;*  it under the terms of the GNU General Public License as published by    *;
                STRING  ' Productions'
+
;*  the Free Software Foundation; either version 2 of the License, or      *;
                BYTE    0
+
;*  (at your option) any later version.                                    *;
             
+
;*                                                                          *;
                CALL    PRINT.FLS      ; Write string (ptr in R1)
+
;*  This program is distributed in the hope that it will be useful,        *;
                DECLE  C_WHT, $2D0    ; White, Point to 'Mattel' in lower-right
+
;*  but WITHOUT ANY WARRANTY; without even the implied warranty of          *;
                STRING  '2002 =JRMZ='  ; Guess who?  :-)
+
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      *;
                BYTE    0
+
;*  General Public License for more details.                               *;
             
+
;*                                                                          *;
                ; Done.
+
;*  You should have received a copy of the GNU General Public License      *;
                RETURN                  ; Return to EXEC for title screen display
+
;*  along with this program; if not, write to the Free Software            *;
                ENDP
+
;*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              *;
   
+
;* ======================================================================== *;
   
+
;*                  Copyright (c) 2002, Joseph Zbiciak                    *;
    ;; ======================================================================== ;;
+
;* ======================================================================== *;
    ;;  MAIN:  Here's our main program code.                                    ;;
+
</pre></code>
    ;; ======================================================================== ;;
 
    MAIN:      PROC
 
                DIS
 
                MVII    #STACK, R6      ; Set up our stack
 
   
 
                MVII    #$25E,  R1      ;\
 
                MVII    #$102,  R4      ; |-- Clear all of RAM memory
 
                CALL    FILLZERO        ;/
 
   
 
                MVII    #INITISR, R0    ;\    Do GRAM initialization in ISR.
 
                MVO    R0,    ISRVEC  ; |__ INITISR will the point to the
 
                SWAP    R0              ; |  regular ISR when it's done.
 
                MVO    R0,    ISRVEC+1;/   
 
             
 
                ;; ------------------------------------------------------------ ;;
 
                ;;  Put the character on the screen                            ;;
 
                ;; ------------------------------------------------------------ ;;
 
                MVII    #$1000, R0
 
                MVO    R0,    PLYR.XP
 
                MVO    R0,    PLYR.YP
 
   
 
                EIS
 
   
 
                ;; ------------------------------------------------------------ ;;
 
                ;;  Fall into the RUNQ.  We should never exit the RUNQ in this  ;;
 
                ;;  demo, since we never call SCHEDEXIT.                        ;;
 
                ;; ------------------------------------------------------------ ;;
 
                CALL    RUNQ            ; Run until a SCHEDEXIT happens
 
   
 
                ;; ------------------------------------------------------------ ;;
 
                ;;  If a SCHEDEXIT *does* happen (say, due to a bug), crash    ;;
 
                ;;  gracefully.                                                ;;
 
                ;; ------------------------------------------------------------ ;;
 
                CALL    PRINT.FLS
 
                DECLE  C_RED, $200 + 11*20
 
                        ;01234567890123456789
 
                STRING  "SCHEDEXIT WAS CALLED",0
 
   
 
                DECR    PC              ; Can't get here
 
             
 
                ENDP
 
   
 
    ;; ======================================================================== ;;
 
    ;;  MOB_UPDATE -- This updates the player's position                        ;;
 
    ;; ======================================================================== ;;
 
    MOB_UPDATE  PROC
 
                PSHR    R5
 
   
 
                ;; ------------------------------------------------------------ ;;
 
                ;;  Merge our position with our MOB registers.                  ;;
 
                ;; ------------------------------------------------------------ ;;
 
                MVII    #@@mobr,    R4      ; MOB information template
 
                MVII    #STICSH,    R5
 
   
 
                MVI    PLYR.XP,    R0      ;\
 
                SWAP    R0                  ; |
 
                ANDI    #$00FF,    R0      ; |- Player X position
 
                XOR@    R4,        R0      ; |
 
                MVO@    R0,        R5      ;/
 
             
 
                ADDI    #7,        R5      ;  Move pointer to Y coordinate section of the STICSH
 
               
 
                MVI    PLYR.YP,    R0      ;\
 
                SWAP    R0                  ; |
 
                ANDI    #$007F,    R0      ; |- Player Y position
 
                XOR@    R4,        R0      ; |
 
                MVO@    R0,        R5      ;/
 
   
 
                ADDI    #7,        R5      ; Move pointer to A register section of the STICSH
 
   
 
                MVI@    R4,        R0      ; \_ Player's A register
 
                MVO@    R0,        R5      ; /
 
   
 
                CLRR    R0
 
                MVO    R0,        MOB_BUSY
 
   
 
                PULR    PC
 
   
 
                ;; ------------------------------------------------------------ ;;
 
                ;;  Bits to copy into MOB registers.                            ;;
 
                ;; ------------------------------------------------------------ ;;
 
    @@mobr      DECLE  STIC.mobx_visb      ; make player visible
 
                DECLE  STIC.moby_yres      ; make player 8x16 MOB
 
                DECLE  STIC.moba_fg1 + STIC.moba_gram + 0*8    ; Player is blue
 
                ENDP
 
       
 
   
 
    ;; ======================================================================== ;;
 
    ;;  ISR -- Just keep the screen on, and copy the STIC shadow over.          ;;
 
    ;; ======================================================================== ;;
 
    ISR        PROC
 
   
 
                ;; ------------------------------------------------------------ ;;
 
                ;;  Basics:  Update color stack and video enable.              ;;
 
                ;; ------------------------------------------------------------ ;;
 
                MVO    R0,    STIC.viden  ; Enable display
 
                MVI    STIC.mode, R0      ; ...in color-stack mode
 
   
 
                MVII    #C_GRY, R0          ;\
 
                MVO    R0,    STIC.cs0    ; |__ Set display to grey
 
                MVO    R0,    STIC.cs2    ; |
 
                MVO    R0,    STIC.bord  ;/
 
   
 
                ;; ------------------------------------------------------------ ;;
 
                ;;  Update STIC shadow and queue updates for MOB velocities.    ;;
 
                ;; ------------------------------------------------------------ ;;
 
                MVI    MOB_BUSY, R0
 
                TSTR    R0
 
                BNEQ    @@no_mobs
 
                MVO    PC,    MOB_BUSY
 
   
 
   
 
                CALL    MEMCPY              ;\__ Copy over the STIC shadow.
 
                DECLE  $0000, STICSH, 24  ;/
 
   
 
                MVII    #MOB_UPDATE, R0
 
                JSRD    R5,  QTASK
 
    @@no_mobs: 
 
   
 
                CALL    DOTIMER            ; Update timer-based tasks.
 
                B      $1014              ; return from interrupt.
 
                ENDP
 
   
 
    ;; ======================================================================== ;;
 
    ;;  INITISR -- Copy our GRAM image over, and then do the plain ISR.        ;;
 
    ;; ======================================================================== ;;
 
    INITISR    PROC
 
                PSHR    R5
 
   
 
                CALL    MEMCPY
 
                DECLE  $3800, GRAMIMG, GRAMIMG.end - GRAMIMG
 
   
 
                MVII    #ISR,  R0
 
                MVO    R0,    ISRVEC
 
                SWAP    R0
 
                MVO    R0,    ISRVEC + 1
 
   
 
                PULR    PC
 
                ENDP
 
   
 
    ;; ======================================================================== ;;
 
    ;;  GRAMIMG -- Arrow pictures and other graphics to load into GRAM.        ;;
 
    ;; ======================================================================== ;;
 
    GRAMIMG    PROC
 
   
 
    @@person:  ; Crappy person graphic.
 
                DECLE  %00010000
 
                DECLE  %00111000
 
                DECLE  %00111000
 
                DECLE  %00010000
 
                DECLE  %00010000
 
                DECLE  %01111100
 
                DECLE  %10111010
 
                DECLE  %10111010
 
                DECLE  %10111010
 
                DECLE  %10111010
 
                DECLE  %00111000
 
                DECLE  %00101000
 
                DECLE  %00101000
 
                DECLE  %00101000
 
                DECLE  %00101000
 
                DECLE  %01101100
 
    @@end:     
 
                ENDP
 
   
 
    ;; ======================================================================== ;;
 
    ;;  LIBRARY INCLUDES                                                        ;;
 
    ;; ======================================================================== ;;
 
                INCLUDE "print.asm"      ; PRINT.xxx routines
 
                INCLUDE "fillmem.asm"    ; CLRSCR/FILLZERO/FILLMEM
 
                INCLUDE "memcpy.asm"      ; MEMCPY
 
                INCLUDE "timer.asm"          ; Timer-based task stuff
 
                INCLUDE "taskq.asm"          ; RUNQ/QTASK
 
   
 
   
 
    ;* ======================================================================== *;
 
    ;*  This program is free software; you can redistribute it and/or modify    *;
 
    ;*  it under the terms of the GNU General Public License as published by    *;
 
    ;*  the Free Software Foundation; either version 2 of the License, or      *;
 
    ;*  (at your option) any later version.                                    *;
 
    ;*                                                                          *;
 
    ;*  This program is distributed in the hope that it will be useful,        *;
 
    ;*  but WITHOUT ANY WARRANTY; without even the implied warranty of          *;
 
    ;*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *;
 
    ;*  General Public License for more details.                                *;
 
    ;*                                                                          *;
 
    ;*  You should have received a copy of the GNU General Public License      *;
 
    ;*  along with this program; if not, write to the Free Software            *;
 
    ;*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              *;
 
    ;* ======================================================================== *;
 
    ;*                  Copyright (c) 2002, Joseph Zbiciak                    *;
 
    ;* ======================================================================== *;
 

Latest revision as of 13:30, 18 November 2011

tag0.asm

This is the code for the very beginning of the tutorial - it just displays a title screen and then a blank screen.

;;==========================================================================;;
;; Joe Zbiciak's Tagalong Todd!                                             ;;
;; Copyright 2002, Joe Zbiciak, intvnut AT gmail.com.                       ;;
;; http://spatula-city.org/~im14u2c/intv/                                   ;;
;;==========================================================================;;

;* ======================================================================== *;
;*  TO BUILD IN BIN+CFG FORMAT:                                             *;
;*      as1600 -o tagalong.bin -l tagalong.lst tagalong.asm                 *;
;*                                                                          *;
;*  TO BUILD IN ROM FORMAT:                                                 *;
;*      as1600 -o tagalong.rom -l tagalong.lst tagalong.asm                 *;
;* ======================================================================== *;

            ROMW    16              ; Use 16-bit ROM

;------------------------------------------------------------------------------
; Include system information
;------------------------------------------------------------------------------
            INCLUDE "gimini.asm"

;------------------------------------------------------------------------------
; EXEC-friendly ROM header.
;------------------------------------------------------------------------------
            ORG     $5000           ; Use default memory map
ROMHDR:     BIDECLE ZERO            ; MOB picture base   (points to NULL list)
            BIDECLE ZERO            ; Process table      (points to NULL list)
            BIDECLE MAIN            ; Program start address
            BIDECLE ZERO            ; Bkgnd picture base (points to NULL list)
            BIDECLE ONES            ; GRAM pictures      (points to NULL list)
            BIDECLE TITLE           ; Cartridge title/date
            DECLE   $03C0           ; No ECS title, run code after title,
                                    ; ... no clicks
ZERO:       DECLE   $0000           ; Screen border control
            DECLE   $0000           ; 0 = color stack, 1 = f/b mode
ONES:       DECLE   C_BLU, C_BLU    ; Initial color stack 0 and 1: Blue
            DECLE   C_BLU, C_BLU    ; Initial color stack 2 and 3: Blue
            DECLE   C_BLU           ; Initial border color: Blue
;------------------------------------------------------------------------------


;; ======================================================================== ;;
;;  TITLE  -- Display our modified title screen & copyright date.           ;;
;; ======================================================================== ;;
TITLE:      PROC
            STRING  102, "Tagalong Todd", 0
            BEGIN
          
            ; Patch the title string to say '=JRMZ=' instead of Mattel.
            CALL    PRINT.FLS       ; Write string (ptr in R5)
            DECLE   C_WHT, $23D     ; White, Point to 'Mattel' in top-left
            STRING  '=JRMZ='        ; Guess who?  :-)
            STRING  ' Productions' 
            BYTE    0
          
            CALL    PRINT.FLS       ; Write string (ptr in R1)
            DECLE   C_WHT, $2D0     ; White, Point to 'Mattel' in lower-right
            STRING  '2002 =JRMZ='   ; Guess who?  :-)
            BYTE    0
          
            ; Done.
            RETURN                  ; Return to EXEC for title screen display
            ENDP


;; ======================================================================== ;;
;;  MAIN:  Here's our main program code.                                    ;;
;; ======================================================================== ;;
MAIN:       PROC
            BEGIN

            CALL    CLRSCR          ; Clear the screen

            RETURN                  ; Return to the EXEC and sit doing nothing.
            ENDP

;; ======================================================================== ;;
;;  LIBRARY INCLUDES                                                        ;;
;; ======================================================================== ;;
            INCLUDE "print.asm"       ; PRINT.xxx routines
            INCLUDE "fillmem.asm"     ; CLRSCR/FILLZERO/FILLMEM

;* ======================================================================== *;
;*  This program is free software; you can redistribute it and/or modify    *;
;*  it under the terms of the GNU General Public License as published by    *;
;*  the Free Software Foundation; either version 2 of the License, or       *;
;*  (at your option) any later version.                                     *;
;*                                                                          *;
;*  This program is distributed in the hope that it will be useful,         *;
;*  but WITHOUT ANY WARRANTY; without even the implied warranty of          *;
;*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *;
;*  General Public License for more details.                                *;
;*                                                                          *;
;*  You should have received a copy of the GNU General Public License       *;
;*  along with this program; if not, write to the Free Software             *;
;*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               *;
;* ======================================================================== *;
;*                   Copyright (c) 2002, Joseph Zbiciak                     *;
;* ======================================================================== *;

tag1.asm

This is the full listing of the code for the example as it appears at the end of part 1.

;;==========================================================================;;
;; Joe Zbiciak's Tagalong Todd!                                             ;;
;; Copyright 2002, Joe Zbiciak, intvnut AT gmail.com.                       ;;
;; http://spatula-city.org/~im14u2c/intv/                                   ;;
;;==========================================================================;;

;* ======================================================================== *;
;*  TO BUILD IN BIN+CFG FORMAT:                                             *;
;*      as1600 -o tagalong.bin -l tagalong.lst tagalong.asm                 *;
;*                                                                          *;
;*  TO BUILD IN ROM FORMAT:                                                 *;
;*      as1600 -o tagalong.rom -l tagalong.lst tagalong.asm                 *;
;* ======================================================================== *;

            ROMW    16              ; Use 16-bit ROM

;------------------------------------------------------------------------------
; Include system information
;------------------------------------------------------------------------------
            INCLUDE "gimini.asm"

;------------------------------------------------------------------------------
; Global constants and configuration.
;------------------------------------------------------------------------------

TSKQM       EQU     $7              ; Task queue is 8 entries large
MAXTSK      EQU     1               ; Only one task

;------------------------------------------------------------------------------
; Allocate 8-bit variables in Scratch RAM
;------------------------------------------------------------------------------
SCRATCH     ORG     $100, $100, "-RWBN"

ISRVEC      RMB     2               ; Always at $100 / $101

            ; Task-oriented 8-bit variables
TSKQHD      RMB     1               ; Task queue head
TSKQTL      RMB     1               ; Task queue tail
TSKDQ       RMB     2*(TSKQM+1)     ; Task data queue
TSKACT      RMB     1               ; Number of active tasks

_SCRATCH    EQU     $               ; end of scratch area



;------------------------------------------------------------------------------
; Allocate 16-bit variables in System RAM 
;------------------------------------------------------------------------------
SYSTEM      ORG     $2F0, $2F0, "-RWBN"
STACK       RMB     32              ; Reserve 32 words for the stack

            ; Task-oriented 16-bit variables
TSKQ        RMB     (TSKQM + 1)     ; Task queue
TSKTBL      RMB     (MAXTSK * 4)    ; Timer task table

            ; STIC shadow
STICSH      RMB     24              ; Room for X, Y, and A regs only.

PLYR        PROC
@@XP        RMB     1               ; X position
@@YP        RMB     1               ; Y position
            ENDP

MOB_BUSY    RMB     1
_SYSTEM     EQU     $               ; end of system area


;------------------------------------------------------------------------------
; EXEC-friendly ROM header.
;------------------------------------------------------------------------------
            ORG     $5000           ; Use default memory map
ROMHDR:     BIDECLE ZERO            ; MOB picture base   (points to NULL list)
            BIDECLE ZERO            ; Process table      (points to NULL list)
            BIDECLE MAIN            ; Program start address
            BIDECLE ZERO            ; Bkgnd picture base (points to NULL list)
            BIDECLE ONES            ; GRAM pictures      (points to NULL list)
            BIDECLE TITLE           ; Cartridge title/date
            DECLE   $03C0           ; No ECS title, run code after title,
                                    ; ... no clicks
ZERO:       DECLE   $0000           ; Screen border control
            DECLE   $0000           ; 0 = color stack, 1 = f/b mode
ONES:       DECLE   C_BLU, C_BLU    ; Initial color stack 0 and 1: Blue
            DECLE   C_BLU, C_BLU    ; Initial color stack 2 and 3: Blue
            DECLE   C_BLU           ; Initial border color: Blue
;------------------------------------------------------------------------------


;; ======================================================================== ;;
;;  TITLE  -- Display our modified title screen & copyright date.           ;;
;; ======================================================================== ;;
TITLE:      PROC
            STRING  102, "Tagalong Todd", 0
            BEGIN
          
            ; Patch the title string to say '=JRMZ=' instead of Mattel.
            CALL    PRINT.FLS       ; Write string (ptr in R5)
            DECLE   C_WHT, $23D     ; White, Point to 'Mattel' in top-left
            STRING  '=JRMZ='        ; Guess who?  :-)
            STRING  ' Productions' 
            BYTE    0
          
            CALL    PRINT.FLS       ; Write string (ptr in R1)
            DECLE   C_WHT, $2D0     ; White, Point to 'Mattel' in lower-right
            STRING  '2002 =JRMZ='   ; Guess who?  :-)
            BYTE    0
          
            ; Done.
            RETURN                  ; Return to EXEC for title screen display
            ENDP


;; ======================================================================== ;;
;;  MAIN:  Here's our main program code.                                    ;;
;; ======================================================================== ;;
MAIN:       PROC
            DIS
            MVII    #STACK, R6      ; Set up our stack

            MVII    #$25E,  R1      ;\
            MVII    #$102,  R4      ; |-- Clear all of RAM memory
            CALL    FILLZERO        ;/

            MVII    #INITISR, R0    ;\    Do GRAM initialization in ISR.
            MVO     R0,     ISRVEC  ; |__ INITISR will the point to the 
            SWAP    R0              ; |   regular ISR when it's done.
            MVO     R0,     ISRVEC+1;/    
          
            ;; ------------------------------------------------------------ ;;
            ;;  Put the character on the screen                             ;;
            ;; ------------------------------------------------------------ ;;
            MVII    #$1000, R0
            MVO     R0,     PLYR.XP
            MVO     R0,     PLYR.YP

            EIS

            ;; ------------------------------------------------------------ ;;
            ;;  Fall into the RUNQ.  We should never exit the RUNQ in this  ;;
            ;;  demo, since we never call SCHEDEXIT.                        ;;
            ;; ------------------------------------------------------------ ;;
            CALL    RUNQ            ; Run until a SCHEDEXIT happens

            ;; ------------------------------------------------------------ ;;
            ;;  If a SCHEDEXIT *does* happen (say, due to a bug), crash     ;;
            ;;  gracefully.                                                 ;;
            ;; ------------------------------------------------------------ ;;
            CALL    PRINT.FLS
            DECLE   C_RED, $200 + 11*20
                    ;01234567890123456789
            STRING  "SCHEDEXIT WAS CALLED",0

            DECR    PC              ; Can't get here
          
            ENDP

;; ======================================================================== ;;
;;  MOB_UPDATE -- This updates the player's position                        ;;
;; ======================================================================== ;;
MOB_UPDATE  PROC
            PSHR    R5

            ;; ------------------------------------------------------------ ;;
            ;;  Merge our position with our MOB registers.                  ;;
            ;; ------------------------------------------------------------ ;;
            MVII    #@@mobr,    R4      ; MOB information template
            MVII    #STICSH,    R5

            MVI     PLYR.XP,    R0      ;\
            SWAP    R0                  ; |
            ANDI    #$00FF,     R0      ; |- Player X position
            XOR@    R4,         R0      ; |
            MVO@    R0,         R5      ;/
          
            ADDI    #7,         R5      ;  Move pointer to Y coordinate section of the STICSH
            
            MVI     PLYR.YP,    R0      ;\
            SWAP    R0                  ; |
            ANDI    #$007F,     R0      ; |- Player Y position
            XOR@    R4,         R0      ; |
            MVO@    R0,         R5      ;/

            ADDI    #7,         R5      ; Move pointer to A register section of the STICSH

            MVI@    R4,         R0      ; \_ Player's A register
            MVO@    R0,         R5      ; /

            CLRR    R0
            MVO     R0,         MOB_BUSY

            PULR    PC

            ;; ------------------------------------------------------------ ;;
            ;;  Bits to copy into MOB registers.                            ;;
            ;; ------------------------------------------------------------ ;;
@@mobr      DECLE   STIC.mobx_visb      ; make player visible
            DECLE   STIC.moby_yres      ; make player 8x16 MOB
            DECLE   STIC.moba_fg1 + STIC.moba_gram + 0*8    ; Player is blue
            ENDP
    

;; ======================================================================== ;;
;;  ISR -- Just keep the screen on, and copy the STIC shadow over.          ;;
;; ======================================================================== ;;
ISR         PROC

            ;; ------------------------------------------------------------ ;;
            ;;  Basics:  Update color stack and video enable.               ;;
            ;; ------------------------------------------------------------ ;;
            MVO     R0,     STIC.viden  ; Enable display
            MVI     STIC.mode, R0       ; ...in color-stack mode

            MVII    #C_GRY, R0          ;\
            MVO     R0,     STIC.cs0    ; |__ Set display to grey
            MVO     R0,     STIC.cs2    ; |
            MVO     R0,     STIC.bord   ;/

            ;; ------------------------------------------------------------ ;;
            ;;  Update STIC shadow and queue updates for MOB velocities.    ;;
            ;; ------------------------------------------------------------ ;;
            MVI     MOB_BUSY, R0
            TSTR    R0
            BNEQ    @@no_mobs
            MVO     PC,     MOB_BUSY


            CALL    MEMCPY              ;\__ Copy over the STIC shadow.
            DECLE   $0000, STICSH, 24   ;/

            MVII    #MOB_UPDATE, R0
            JSRD    R5,   QTASK
@@no_mobs:  

            CALL    DOTIMER             ; Update timer-based tasks.
            B       $1014               ; return from interrupt.
            ENDP

;; ======================================================================== ;;
;;  INITISR -- Copy our GRAM image over, and then do the plain ISR.         ;;
;; ======================================================================== ;;
INITISR     PROC
            PSHR    R5

            CALL    MEMCPY
            DECLE   $3800, GRAMIMG, GRAMIMG.end - GRAMIMG

            MVII    #ISR,   R0
            MVO     R0,     ISRVEC
            SWAP    R0
            MVO     R0,     ISRVEC + 1

            PULR    PC
            ENDP

;; ======================================================================== ;;
;;  GRAMIMG -- Arrow pictures and other graphics to load into GRAM.         ;;
;; ======================================================================== ;;
GRAMIMG     PROC

@@person:   ; Crappy person graphic.
            DECLE   %00010000
            DECLE   %00111000
            DECLE   %00111000
            DECLE   %00010000
            DECLE   %00010000
            DECLE   %01111100
            DECLE   %10111010
            DECLE   %10111010
            DECLE   %10111010
            DECLE   %10111010
            DECLE   %00111000
            DECLE   %00101000
            DECLE   %00101000
            DECLE   %00101000
            DECLE   %00101000
            DECLE   %01101100
@@end:      
            ENDP

;; ======================================================================== ;;
;;  LIBRARY INCLUDES                                                        ;;
;; ======================================================================== ;;
            INCLUDE "print.asm"       ; PRINT.xxx routines
            INCLUDE "fillmem.asm"     ; CLRSCR/FILLZERO/FILLMEM
            INCLUDE "memcpy.asm"      ; MEMCPY
            INCLUDE "timer.asm"          ; Timer-based task stuff
            INCLUDE "taskq.asm"          ; RUNQ/QTASK


;* ======================================================================== *;
;*  This program is free software; you can redistribute it and/or modify    *;
;*  it under the terms of the GNU General Public License as published by    *;
;*  the Free Software Foundation; either version 2 of the License, or       *;
;*  (at your option) any later version.                                     *;
;*                                                                          *;
;*  This program is distributed in the hope that it will be useful,         *;
;*  but WITHOUT ANY WARRANTY; without even the implied warranty of          *;
;*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *;
;*  General Public License for more details.                                *;
;*                                                                          *;
;*  You should have received a copy of the GNU General Public License       *;
;*  along with this program; if not, write to the Free Software             *;
;*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               *;
;* ======================================================================== *;
;*                   Copyright (c) 2002, Joseph Zbiciak                     *;
;* ======================================================================== *;