ZX81 Assembly Listing for runml.asm


ZX81 assembly listing for **RUN ML***SLR/2022**

**RUN ML***SLR/2022** (runml.asm)

A machine language version of a person running with a moving sky.


ASSEMBLY PROGRAM LISTING

;
; Run ML
; v1.00 Steven Reid (c) 2022
;
; A simple little running animation and moving sky.
;
; 2/16/2022 - Initial build.
;

; +++
;
; Header and startup
;

        ; start up stuff
        org 16514               ; stored in REM at top (ZX81)
        jr start                ; needed for z80asm

; title and copyright (will show on listing)
copy:
        db $17,$17,$37,$3a,$33,$00,$32,$31,$17,$17
        db $17,$38,$31,$37,$18,$1e,$1c,$1e,$1e,$17
        db $17,$76  ; **RUN ML***SLR/2022**

start:
        call slow               ; SLOW is required.

; end header and startup
;
; ---


; +++
;
; Main Loop
;

mainloop:

        ; print static elements
        call cls

        ld bc,$0302             ; head
        call printat
        ld a,$80
        rst $10

        ld bc,$0700             ; floor
        call printat
        ld b,32
        ld a,3
floorlp:
        rst $10
        djnz floorlp

animate:

        ; deal with runner
        ld hl,runner
        ld (runframe),hl
        ld b,4
runloop:
        push bc
        call printrunner

        call printsky

        ld hl,100
        call newpause

        pop bc
        djnz runloop

        jp animate

; End of loop!
;

; +++
;
; Routines
;

printrunner:
        ld b,4                  ; load position
        ld c,1
        call printrow
        call printrow
        call printrow
        ret

printrow:
        push bc
        call printat            ; print location
        ld hl,(runframe)        ; load run location
        ld b,3                  ; print row
printrowlp:
        ld a,(hl)
        rst $10
        inc hl
        djnz printrowlp

        ld (runframe),hl        ; save next row
        pop bc
        inc b                   ; move down a row
        ret

printsky:
        ld hl,skytop
        call shiftsky
        ld hl,skybottom
        call shiftsky

        ld bc,$0000
        call printat
        ld hl,skytop
        call printskyrow

        ld bc,$0100
        call printat
        ld hl,skybottom
        call printskyrow

        ret

printskyrow:
        ld b,32
printskylp:
        ld a,(hl)
        rst $10
        inc hl
        djnz printskylp
        ret

shiftsky:
        ld a,(hl)       ; grab first character
        ld de,hl
        inc hl
        ld bc,39
        ldir            ; shift line to the left
        ld (de),a       ; replace last char with first
        ret
;
; Print string at HL
; stops when reaches $FF
;
print:
        ld a,(hl)               ; load character
        inc hl                  ; increment memory
        cp $ff                  ; last character?
        ret z                   ; yep, return
        rst $10                 ; nope, print it!
        jr print                ; loop

;
; Delay
;
; set bc to speed
; press space to 

pframe: dw $0000
newpause:
        ld (pframe),hl

        call kscan              ; get key press
        inc l
        jr z,lppause            ; not yet loop
        dec l
        ld b,h
        ld c,l
        call findchar           ; yep, grab character pressed
        ld a,(hl)

        push af
        call wait
        pop af

        and a                   ; pressed space (break)
        jp z,stop               ; stop!
        ret                     ; or return!

        ; loop!
lppause:
        ld hl,(pframe)
        dec hl
        ld a,h
        or l
        jr nz,newpause          ; not zero, keep going!

        ret                     ; pause is done!

wait:   call kscan              ; Wait for human to take finger off of key.
        inc l
        jr nz,wait
        ret

; +++
;
; Data and Defines
;

; ZX81 system vars
d_file:         equ $400c
d_fcc:          equ 16398
frames:         equ 16436

; ZX81 ROM functions
kscan:          equ $02bb
findchar:       equ $07bd
stop:           equ $0cdc
slow:           equ $0f2b
fast:           equ $02e7
save:           equ $02f9
printat:        equ $08f5
pause:          equ $0f35
cls:            equ $0a2a

; end defines
; ---

; +++
; Data
;

;
; vars
;

runframe:       dw 0

;
; runner
;

runner:
        db $87, $82, $04, $01, $05, $00, $06, $02, $04
        db $87, $82, $00, $02, $05, $01, $87, $84, $00
        db $87, $82, $00, $00, $07, $00, $00, $07, $00
        db $87, $82, $00, $02, $05, $01, $87, $84, $00
;
; sky
;

skytop:
        db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
        db $83, $00, $00, $87, $07, $04, $00, $00, $00, $00
        db $00, $02, $04, $02, $00, $87, $01, $00, $00, $00
        db $00, $00, $00, $00, $00, $00, $00, $87, $07, $04
skybottom:
        db $00, $00, $00, $00, $00, $00, $00, $00, $83, $81
        db $82, $01, $03, $03, $03, $00, $00, $00, $00, $00
        db $00, $04, $09, $08, $08, $09, $87, $00, $00, $00
        db $00, $00, $00, $00, $00, $00, $03, $03, $03, $00

; end data
; ---