Skip to content

Instantly share code, notes, and snippets.

@fastjack
Created March 27, 2023 17:17
Show Gist options
  • Save fastjack/e88f238dc3fac8bff13ebfa8e29b2d07 to your computer and use it in GitHub Desktop.
Save fastjack/e88f238dc3fac8bff13ebfa8e29b2d07 to your computer and use it in GitHub Desktop.
Code examples from Section 9 of Digital Research's Programmer’s Utilies Guide
; macro library for pedestrian pushbuttons
;
cwinp equ 00h ;input port for crosswalk
;
push? macro iftrue
;; "push?" jumps to label "iftrue" when any one
;; of the crosswalk switches is depressed. The
;; value has been latched, and reading the port
;; clears the latched values
in cwinp ;;read the crosswalk switches
ani (1 shl cwcnt) - 1 ;;build mask
jnz iftrue ;;any switches set?
;; continue on false condition
endm
; macro library for basic intersection
;
; input/output ports for light and clock
light equ 00h ;traffic light control
clock equ 03h ;24 hour clock (0,1,...23)
;
; constants for traffic light control
nsbits equ 4 ;north south bits
ewbits equ 0 ;east west bits
;
off equ 0 ;turn light off
red equ 1 ;value for red light
yellow equ 2 ;value for yellow light
green equ 3 ;value for green light
;
setlite macro dir,color
;; set light "dir" (ns,ew) to "color" (off,red,yellow,green)
mvi a,color shl dir&bits ;;color readied
out light ;;sent in proper bit position
endm
;
timer macro seconds
;; construct inline time-out loop
local t1,t2,t3 ;;loop entries
mvi d,4*seconds ;;basic loop control
t1: mvi b,250 ;;250msec *4 = 1 sec
t2: mvi c,182 ;;182*5.5usec = 1msec
t3: dcr c ;;1 cy = .5 usec
jnz t3 ;;+10 cy = 5.5 usec
dcr b ;;count 250,249...
jnz t2 ;;loop on b register
dcr d ;;basic loop control
jnz t1 ;;loop on d register
;; arrive here with approximately "seconds" secs timeout
endm
;
clock? macro low,high,iftrue
;; jump to "iftrue" if clock is between low and high
local iffalse ;;alternate to true case
in clock ;;read rea-time clock
if not nul high ;;check high clock
cpi high ;;equal or greater?
jnc iffalse ;;skip to label if so
endif
cpi low ;;less than low value?
jnc iftrue ;;skipt to label if not
iffalse:
endm
;
retry macro golabel
;; continue execution at "golabel"
jmp golabel
endm
; intersection: bumpenram blvd / lullabyte ln.
cwcnt equ 4 ;set to 4 crosswalk switches
lull0 equ 0 ;name for treadle zero
lull1 equ 1 ;name for treadle one
maclib inter ;basic intersection
maclib treadles ;include treadles
maclib buttons ;include pushbuttons
cycle: ;enter here on each major cycle of the light
clock? 2,5,night ;special flashing?
;not between 2 and 5 am
setlite ns,red ;red light on lullabye
setlite ew,green ;green on bumpenram
sample: ;sample the buttons and treadles
push? switch ;anyone there?
tread? lull0,switch ;treadle 0?
tread? lull1,switch ;treadle 1?
clock? 2,,night ;past 2am?
retry sample ;try again if not
switch:
;someone is waiting, change lights
setlite ew,yellow ;slow 'em down
timer 3 ;wait 3 seconds
setlite ew,red ;stop 'em
setlite ns,green ;let 'em go
timer 23 ;for awhile
done?: ;is all the traffic through on lullabye
tread? lull0,notdone ;treadle 0?
tread? lull1,notdone ;treadle 1?
;neither treadle is set, cycle
retry cycle ;for another loop
notdone:
timer 5 ;wait 5 seconds
retry done? ;try again
night: ;this is nighttime, flash lights
setlite ew,off ;turn off
setlite ns,off ;turn off
timer 1 ;wait with off
setlite ew,yellow ;turn to yellow
setlite ns,red ;turn to red
timer 1 ;leave on for 1 sec
retry cycle ;go around again
; macro library for street treadles
;
trinp equ 01h ;treadle input port
trout equ 01h ;treadle output port
;
tread? macro tr,iftrue
;; "tread?" is invoked to check if
;; treadle given by tr has been sensed.
;; if so, the latch is cleared and control
;; transfers to the label "iftrue"
local iffalse ;;in case not set
;;
in trinp ;;read treadle switches
ani l shl tr ;;mask proper bit
jz iffalse ;;skip reset if 0
mvi a,1 shl tr ;;to reset the bit
out trout ;;clear it
jmp iftrue ;;go to true label
iffalse:
endm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment