COM 'Copyright 1984, 2014 Lamar Owen, GPLv2 or later license.'
TITLE '<Conways game of LIFE for TRS-DOS 6.1 on TRS-80 Model 4>'
SUBTTL '<PROGRAM Header>'
; Source reformatted from Series-I Editor-Assembler to what should be MRAS-compatible.
; Original Model III version hand-assembled; this is a reconstruction and thus is
; not well-commented.
; Engine is by Ray Chason.
;
; Original Model III code used direct access to video RAM; this version would be better
; if it built the screen in the buffer at 3000H as well as in the video memory....
; but hindsight is 20/20..... and using @VDCTL function 6 would have been useful.
;
; Keys: space: puts a space at the cursor and moves cursor right
; X: puts an X at the cursor and moves cursor right
; Up (0BH): moves cursor up
; Down (0AH): moves cursor down (yep, a linefeed)
; Left (08H): moves cursor left
; Right (09H): moves cursor right
; SHIFT-CLEAR (1FH): clears screen
; ENTER (0DH): starts LIFE
; BREAK (80H): exits.
;
; Version: 1.01, released September 4, 2014, via vintage-computer.com forums.
; SVC MACRO is not actually used in the below code, but is here to show RST 28H calling
; convention in this version (I may rebuild it later to use it....)
;
; SVC EUQates are for reference; please see 'Model 4/4P Technical Reference Manual' or
; 'The Programmer's Guide to LDOS/TRSDOS 6' for a list of SVC's and their arguments.
;
; EQUate for CRSAVE (0BC8H) constant used below is an undocumented for TRSDOS 6.1
; memory location for 'character currently under cursor' in the *DO display driver
; (See 'The Source' or Frank Durda IV's LS-DOS 6.3.1 source code for DODVR/ASM. EQUate in
; LS-DOS source is for CRSAVE. Frank Durda's site: nemesis.lonestar.org)
; Equivalent LS-DOS 6.3.1 location is 0B97H.
;
; MACROS
;
SVC MACRO #NUM ;Macro to invoke a SVC
LD A,#NUM
RST 28H
ENDM
; Character under the cursor
CRSAVE EQU 0B97H ;TRS-DOS 6.1 location was 0BC8H. Used internally in *DO
;
;
; SVC (SuperVisor Call) EQUates.
@DSP EQU 2
@KEY EQU 1
@KBD EQU 8
@EXIT EQU 16H
@VDCTL EQU 0FH
;
; Calls to @VDCTL use register B for a function.
; The model III version of this code used direct access to the video RAM instead
; of the buffer.
;
SUBTTL '<Main-line Code>'
ORG 4000H
OFSTBL DEFB 0FFH
DEFB 0FFH
DEFB 0
DEFB 0FFH
DEFB 1
DEFB 0FFH
DEFB 0FFH
DEFB 0
DEFB 1
DEFB 0
DEFB 0FFH
DEFB 1
DEFB 0
DEFB 1
DEFB 1
DEFB 1
CLEAR LD C,1CH
LD A,2
RST 28H
LD C,1FH
LD A,2
RST 28H
LD HL,0
PRCRSR LD B,3 ;@VDCTL function 'move cursor to position HL'
LD A,0FH
PUSH HL
RST 28H
POP HL
LD C,0EH
LD A,2
RST 28H
LD A,1
RST 28H
CP ' '
JR Z,PRCELL
CP 'X'
JR Z,PRCELL
CP 0BH
JR Z,UP
CP 0AH
JR Z,DOWN
CP 08H
JR Z,LEFT
CP 09H
JR Z,RIGHT
CP 1FH
JR Z,CLEAR
CP 0DH
JR Z,STEP
CP 80H
JR NZ,PRCRSR
LD A,16H
RST 28H
;
; CRSAVE is 0B97H for LS-DOS 6.3.1, 0BC8H for TRS-DOS 6.1
;
PRCELL LD (CRSAVE),A ;Put either space or X under cursor 'behind *DO's back'
RIGHT INC L
LD A,L
CP 80
JR C,PRCRSR
LD L,0
JR PRCRSR
;
LEFT DEC L
LD A,L
CP 80
JR C,PRCRSR
LD L,79
JR PRCRSR
;
UP DEC H
LD A,H
CP 24
JR C,PRCRSR
LD H,23
JR PRCRSR
;
DOWN INC H
LD A,H
CP 24
JR C,PRCRSR
LD H,0
JR PRCRSR
;
STEP PUSH HL
LD C,0FH
LD A,2
RST 28H
STEP2 LD IX,377FH
LD H,23
ROW LD L,79
CELL LD DE,OFSTBL
LD BC,0800H
NBRCHK PUSH HL
LD A,(DE)
ADD A,L
CP 80
JR NZ,NORGT
LD A,0
NORGT CP 0FFH
JR NZ,NOLEFT
LD A,79
NOLEFT LD L,A
INC DE
LD A,(DE)
ADD A,H
CP 24
JR NZ,NODOWN
LD A,0
NODOWN CP 0FFH
JR NZ,NOUP
LD A,23
NOUP LD H,A
PUSH BC
PUSH DE
LD B,1 ;@VDCTL function 1: return character at HL (H is row, L is column)
LD A,0FH
PUSH HL
RST 28H
POP HL
POP DE
POP BC
CP 'X'
JR NZ,NONBR
INC C
NONBR POP HL
INC DE
DJNZ NBRCHK
PUSH BC
LD B,1 ;@VDCTL function 1: get char at HL
LD A,0FH
PUSH HL
RST 28H
POP HL
POP BC
CP 'X'
JR NZ,DEDCEL
SET 0,C
DEDCEL LD A,C
CP 3
JR Z,LVCELL
LD A,' '
JR SETCEL
LVCELL LD A,'X'
SETCEL LD (IX+0),A
DEC IX
DEC L
LD A,L
CP 80
JR C,CELL
DEC H
LD A,H
CP 24
JR C,ROW
LD A,8 ;@KBD Check for keypress, return to editor if so.
RST 28H
POP HL
CP 0
JP NZ,PRCRSR
PUSH HL
LD HL,3000H
LD B,5 ;@VDCTL function 5: blow 1920 bytes starting at HL into video.
LD A,0FH ; (Basically a glorified LDIR, but has to map VIDEORAM in and out).
RST 28H
JP STEP2
END CLEAR